From 9e02b7f3b3f6d5db71a974ca6a4d574e3cc171f9 Mon Sep 17 00:00:00 2001 From: Erin Catto Date: Sat, 6 Jun 2026 10:06:05 -0700 Subject: [PATCH] New sample renderer and UI (#10) No changes to simulation --- .gitignore | 3 +- CMakeLists.txt | 21 +- data/fonts/Roboto-Medium.ttf | Bin 168644 -> 0 bytes extern/glad/include/KHR/khrplatform.h | 311 - extern/glad/include/glad/glad.h | 4133 --- extern/glad/src/glad.c | 2121 -- extern/sokol/LICENSE | 22 + extern/sokol/README.md | 62 + extern/sokol/sokol_app.h | 14500 +++++++++ extern/sokol/sokol_gfx.h | 26841 ++++++++++++++++ extern/sokol/sokol_glue.h | 207 + extern/sokol/sokol_imgui.h | 3171 ++ extern/sokol/sokol_log.h | 334 + extern/stb/stb_image.h | 7987 ----- include/box3d/base.h | 3 + include/box3d/collision.h | 3 +- include/box3d/types.h | 21 + samples/CMakeLists.txt | 308 +- samples/camera.cpp | 332 - samples/camera.h | 85 - samples/font.cpp | 276 - samples/font.h | 51 - samples/geo_buffer.cpp | 150 - samples/geo_buffer.h | 17 - samples/gfx/CMakeLists.txt | 63 + samples/gfx/arena.c | 62 + samples/gfx/arena.h | 37 + samples/gfx/debug_adapter.c | 916 + samples/gfx/debug_adapter.h | 45 + samples/gfx/debug_shapes.c | 839 + samples/gfx/debug_shapes.h | 50 + samples/gfx/draw.c | 370 + samples/gfx/draw.h | 117 + samples/gfx/draw_overlay.h | 37 + samples/gfx/edges.c | 349 + samples/gfx/edges.h | 71 + samples/gfx/geometry_registry.c | 770 + samples/gfx/geometry_registry.h | 243 + samples/gfx/gtao.c | 890 + samples/gfx/gtao.h | 164 + samples/gfx/highlight_mask.c | 413 + samples/gfx/highlight_mask.h | 74 + samples/gfx/highlight_outline.c | 155 + samples/gfx/highlight_outline.h | 57 + samples/gfx/highlight_target.c | 90 + samples/gfx/highlight_target.h | 44 + samples/gfx/ibl.c | 667 + samples/gfx/ibl.h | 75 + samples/gfx/keycodes.h | 55 + samples/gfx/overlay.c | 403 + samples/gfx/overlay.h | 75 + samples/gfx/picking.h | 67 + samples/gfx/projection.h | 56 + samples/gfx/qsort.h | 190 + samples/gfx/renderer.c | 3087 ++ samples/gfx/renderer.h | 179 + samples/gfx/scene_target.c | 220 + samples/gfx/scene_target.h | 69 + samples/gfx/shadow.c | 350 + samples/gfx/shadow.h | 102 + samples/gfx/sky.c | 109 + samples/gfx/sky.h | 49 + samples/gfx/sokol_impl.c | 10 + samples/gfx/text.c | 115 + samples/gfx/text.h | 84 + samples/gfx/tone_map.c | 137 + samples/gfx/tone_map.h | 56 + samples/gfx/utility.h | 228 + samples/host/camera.cpp | 449 + samples/host/camera.h | 198 + samples/host/gui.cpp | 402 + samples/host/gui.h | 56 + samples/host/imgui_impl.cpp | 17 + samples/host/sokol_app_impl.c | 29 + samples/imconfig.h | 156 - samples/main.cpp | 644 +- samples/renderer.cpp | 746 - samples/renderer.h | 43 - samples/sample.cpp | 1577 +- samples/sample.h | 118 +- samples/sample_benchmark.cpp | 319 +- samples/sample_bodies.cpp | 213 +- samples/sample_character.cpp | 168 +- samples/sample_collision.cpp | 401 +- samples/sample_compound.cpp | 44 +- samples/sample_continuous.cpp | 126 +- samples/sample_determinism.cpp | 6 +- samples/sample_events.cpp | 79 +- samples/sample_geometry.cpp | 105 +- samples/sample_issues.cpp | 54 +- samples/sample_joint.cpp | 482 +- samples/sample_manifold.cpp | 137 +- samples/sample_mesh.cpp | 158 +- samples/sample_ragdoll.cpp | 46 +- samples/sample_robustness.cpp | 96 +- samples/sample_shapes.cpp | 289 +- samples/sample_stacking.cpp | 283 +- samples/sample_tree.cpp | 40 +- samples/scene.cpp | 2146 -- samples/scene.h | 147 - samples/shader.cpp | 465 - samples/shader.h | 39 - samples/shaders/.gitkeep | 0 samples/shaders/CLAUDE.md | 286 + samples/shaders/CMakeLists.txt | 140 + samples/shaders/common/pbr.glsl | 238 + samples/shaders/common/preetham.glsl | 146 + samples/shaders/common/xe_gtao_common.glsl | 192 + samples/shaders/generated/brdf_lut.glsl.h | 1093 + samples/shaders/generated/capsule.glsl.h | 5707 ++++ samples/shaders/generated/cube.glsl.h | 4408 +++ .../generated/depth_only_capsule.glsl.h | 1620 + .../shaders/generated/depth_only_cube.glsl.h | 626 + .../shaders/generated/depth_only_geom.glsl.h | 693 + .../generated/depth_only_sphere.glsl.h | 939 + samples/shaders/generated/edge.glsl.h | 1384 + samples/shaders/generated/geom.glsl.h | 4748 +++ samples/shaders/generated/gtao_denoise.glsl.h | 1872 ++ .../shaders/generated/gtao_main_pass.glsl.h | 3911 +++ .../generated/gtao_prefilter_depth.glsl.h | 1827 ++ .../generated/highlight_outline.glsl.h | 1321 + samples/shaders/generated/mask_capsule.glsl.h | 1613 + samples/shaders/generated/mask_hull.glsl.h | 640 + samples/shaders/generated/mask_sphere.glsl.h | 894 + samples/shaders/generated/overlay_line.glsl.h | 1691 + .../shaders/generated/overlay_point.glsl.h | 1203 + samples/shaders/generated/prefilter.glsl.h | 1090 + .../generated/shadow_caster_capsule.glsl.h | 607 + .../generated/shadow_caster_cube.glsl.h | 544 + .../generated/shadow_caster_geom.glsl.h | 557 + .../generated/shadow_caster_sphere.glsl.h | 546 + samples/shaders/generated/sky.glsl.h | 2111 ++ samples/shaders/generated/sky_to_cube.glsl.h | 2067 ++ samples/shaders/generated/sphere.glsl.h | 4913 +++ samples/shaders/generated/tonemap.glsl.h | 1000 + samples/shaders/ibl/brdf_lut.glsl | 144 + samples/shaders/ibl/prefilter.glsl | 128 + samples/shaders/ibl/sky.glsl | 103 + samples/shaders/ibl/sky_to_cube.glsl | 70 + samples/shaders/overlays/line.glsl | 275 + samples/shaders/overlays/point.glsl | 176 + samples/shaders/post/depth_only_capsule.glsl | 180 + samples/shaders/post/depth_only_cube.glsl | 70 + samples/shaders/post/depth_only_geom.glsl | 84 + samples/shaders/post/depth_only_sphere.glsl | 100 + samples/shaders/post/gtao_denoise.glsl | 260 + samples/shaders/post/gtao_main_pass.glsl | 412 + .../shaders/post/gtao_prefilter_depth.glsl | 248 + samples/shaders/post/highlight_outline.glsl | 132 + samples/shaders/post/mask_capsule.glsl | 164 + samples/shaders/post/mask_hull.glsl | 78 + samples/shaders/post/mask_sphere.glsl | 103 + samples/shaders/post/tonemap.glsl | 138 + samples/shaders/shapes/capsule.glsl | 487 + samples/shaders/shapes/cube.glsl | 391 + samples/shaders/shapes/edge.glsl | 202 + samples/shaders/shapes/geom.glsl | 327 + .../shaders/shapes/shadow_caster_capsule.glsl | 86 + .../shaders/shapes/shadow_caster_cube.glsl | 78 + .../shaders/shapes/shadow_caster_geom.glsl | 79 + .../shaders/shapes/shadow_caster_sphere.glsl | 71 + samples/shaders/shapes/sphere.glsl | 416 + samples/ssao_buffer.cpp | 163 - samples/ssao_buffer.h | 21 - samples/stb_image_write.h | 1724 - samples/stb_truetype.h | 5079 --- samples/utility.h | 118 - shaders/common.glsl | 80 - shaders/deferred_lighting_fs.glsl | 253 - shaders/depth_copy_fs.glsl | 10 - shaders/empty.fs | 5 - shaders/forward.fs | 10 - shaders/forward.vs | 17 - shaders/geometry_fs.glsl | 20 - shaders/geometry_vs.glsl | 46 - shaders/mesh.fs | 20 - shaders/mesh.vs | 48 - shaders/mesh_edge.vs | 20 - shaders/mesh_forward.fs | 34 - shaders/mesh_forward.vs | 47 - shaders/mesh_shadow.vs | 14 - shaders/quad_vs.glsl | 11 - shaders/shadow_map.vs | 10 - shaders/ssao_blur_fs.glsl | 47 - shaders/ssao_fs.glsl | 67 - shared/benchmarks.c | 28 +- shared/benchmarks.h | 5 + shared/human.c | 9 + shared/human.h | 2 + shared/overflow_color.c | 2 +- shared/overflow_color.h | 1 + src/CMakeLists.txt | 1 - src/dynamic_tree.c | 2 +- src/hull.c | 13 +- src/physics_world.c | 116 +- src/timer.c | 27 + 196 files changed, 117099 insertions(+), 30076 deletions(-) delete mode 100644 data/fonts/Roboto-Medium.ttf delete mode 100644 extern/glad/include/KHR/khrplatform.h delete mode 100644 extern/glad/include/glad/glad.h delete mode 100644 extern/glad/src/glad.c create mode 100644 extern/sokol/LICENSE create mode 100644 extern/sokol/README.md create mode 100644 extern/sokol/sokol_app.h create mode 100644 extern/sokol/sokol_gfx.h create mode 100644 extern/sokol/sokol_glue.h create mode 100644 extern/sokol/sokol_imgui.h create mode 100644 extern/sokol/sokol_log.h delete mode 100644 extern/stb/stb_image.h delete mode 100644 samples/camera.cpp delete mode 100644 samples/camera.h delete mode 100644 samples/font.cpp delete mode 100644 samples/font.h delete mode 100644 samples/geo_buffer.cpp delete mode 100644 samples/geo_buffer.h create mode 100644 samples/gfx/CMakeLists.txt create mode 100644 samples/gfx/arena.c create mode 100644 samples/gfx/arena.h create mode 100644 samples/gfx/debug_adapter.c create mode 100644 samples/gfx/debug_adapter.h create mode 100644 samples/gfx/debug_shapes.c create mode 100644 samples/gfx/debug_shapes.h create mode 100644 samples/gfx/draw.c create mode 100644 samples/gfx/draw.h create mode 100644 samples/gfx/draw_overlay.h create mode 100644 samples/gfx/edges.c create mode 100644 samples/gfx/edges.h create mode 100644 samples/gfx/geometry_registry.c create mode 100644 samples/gfx/geometry_registry.h create mode 100644 samples/gfx/gtao.c create mode 100644 samples/gfx/gtao.h create mode 100644 samples/gfx/highlight_mask.c create mode 100644 samples/gfx/highlight_mask.h create mode 100644 samples/gfx/highlight_outline.c create mode 100644 samples/gfx/highlight_outline.h create mode 100644 samples/gfx/highlight_target.c create mode 100644 samples/gfx/highlight_target.h create mode 100644 samples/gfx/ibl.c create mode 100644 samples/gfx/ibl.h create mode 100644 samples/gfx/keycodes.h create mode 100644 samples/gfx/overlay.c create mode 100644 samples/gfx/overlay.h create mode 100644 samples/gfx/picking.h create mode 100644 samples/gfx/projection.h create mode 100644 samples/gfx/qsort.h create mode 100644 samples/gfx/renderer.c create mode 100644 samples/gfx/renderer.h create mode 100644 samples/gfx/scene_target.c create mode 100644 samples/gfx/scene_target.h create mode 100644 samples/gfx/shadow.c create mode 100644 samples/gfx/shadow.h create mode 100644 samples/gfx/sky.c create mode 100644 samples/gfx/sky.h create mode 100644 samples/gfx/sokol_impl.c create mode 100644 samples/gfx/text.c create mode 100644 samples/gfx/text.h create mode 100644 samples/gfx/tone_map.c create mode 100644 samples/gfx/tone_map.h create mode 100644 samples/gfx/utility.h create mode 100644 samples/host/camera.cpp create mode 100644 samples/host/camera.h create mode 100644 samples/host/gui.cpp create mode 100644 samples/host/gui.h create mode 100644 samples/host/imgui_impl.cpp create mode 100644 samples/host/sokol_app_impl.c delete mode 100644 samples/imconfig.h delete mode 100644 samples/renderer.cpp delete mode 100644 samples/renderer.h delete mode 100644 samples/scene.cpp delete mode 100644 samples/scene.h delete mode 100644 samples/shader.cpp delete mode 100644 samples/shader.h create mode 100644 samples/shaders/.gitkeep create mode 100644 samples/shaders/CLAUDE.md create mode 100644 samples/shaders/CMakeLists.txt create mode 100644 samples/shaders/common/pbr.glsl create mode 100644 samples/shaders/common/preetham.glsl create mode 100644 samples/shaders/common/xe_gtao_common.glsl create mode 100644 samples/shaders/generated/brdf_lut.glsl.h create mode 100644 samples/shaders/generated/capsule.glsl.h create mode 100644 samples/shaders/generated/cube.glsl.h create mode 100644 samples/shaders/generated/depth_only_capsule.glsl.h create mode 100644 samples/shaders/generated/depth_only_cube.glsl.h create mode 100644 samples/shaders/generated/depth_only_geom.glsl.h create mode 100644 samples/shaders/generated/depth_only_sphere.glsl.h create mode 100644 samples/shaders/generated/edge.glsl.h create mode 100644 samples/shaders/generated/geom.glsl.h create mode 100644 samples/shaders/generated/gtao_denoise.glsl.h create mode 100644 samples/shaders/generated/gtao_main_pass.glsl.h create mode 100644 samples/shaders/generated/gtao_prefilter_depth.glsl.h create mode 100644 samples/shaders/generated/highlight_outline.glsl.h create mode 100644 samples/shaders/generated/mask_capsule.glsl.h create mode 100644 samples/shaders/generated/mask_hull.glsl.h create mode 100644 samples/shaders/generated/mask_sphere.glsl.h create mode 100644 samples/shaders/generated/overlay_line.glsl.h create mode 100644 samples/shaders/generated/overlay_point.glsl.h create mode 100644 samples/shaders/generated/prefilter.glsl.h create mode 100644 samples/shaders/generated/shadow_caster_capsule.glsl.h create mode 100644 samples/shaders/generated/shadow_caster_cube.glsl.h create mode 100644 samples/shaders/generated/shadow_caster_geom.glsl.h create mode 100644 samples/shaders/generated/shadow_caster_sphere.glsl.h create mode 100644 samples/shaders/generated/sky.glsl.h create mode 100644 samples/shaders/generated/sky_to_cube.glsl.h create mode 100644 samples/shaders/generated/sphere.glsl.h create mode 100644 samples/shaders/generated/tonemap.glsl.h create mode 100644 samples/shaders/ibl/brdf_lut.glsl create mode 100644 samples/shaders/ibl/prefilter.glsl create mode 100644 samples/shaders/ibl/sky.glsl create mode 100644 samples/shaders/ibl/sky_to_cube.glsl create mode 100644 samples/shaders/overlays/line.glsl create mode 100644 samples/shaders/overlays/point.glsl create mode 100644 samples/shaders/post/depth_only_capsule.glsl create mode 100644 samples/shaders/post/depth_only_cube.glsl create mode 100644 samples/shaders/post/depth_only_geom.glsl create mode 100644 samples/shaders/post/depth_only_sphere.glsl create mode 100644 samples/shaders/post/gtao_denoise.glsl create mode 100644 samples/shaders/post/gtao_main_pass.glsl create mode 100644 samples/shaders/post/gtao_prefilter_depth.glsl create mode 100644 samples/shaders/post/highlight_outline.glsl create mode 100644 samples/shaders/post/mask_capsule.glsl create mode 100644 samples/shaders/post/mask_hull.glsl create mode 100644 samples/shaders/post/mask_sphere.glsl create mode 100644 samples/shaders/post/tonemap.glsl create mode 100644 samples/shaders/shapes/capsule.glsl create mode 100644 samples/shaders/shapes/cube.glsl create mode 100644 samples/shaders/shapes/edge.glsl create mode 100644 samples/shaders/shapes/geom.glsl create mode 100644 samples/shaders/shapes/shadow_caster_capsule.glsl create mode 100644 samples/shaders/shapes/shadow_caster_cube.glsl create mode 100644 samples/shaders/shapes/shadow_caster_geom.glsl create mode 100644 samples/shaders/shapes/shadow_caster_sphere.glsl create mode 100644 samples/shaders/shapes/sphere.glsl delete mode 100644 samples/ssao_buffer.cpp delete mode 100644 samples/ssao_buffer.h delete mode 100644 samples/stb_image_write.h delete mode 100644 samples/stb_truetype.h delete mode 100644 samples/utility.h delete mode 100644 shaders/common.glsl delete mode 100644 shaders/deferred_lighting_fs.glsl delete mode 100644 shaders/depth_copy_fs.glsl delete mode 100644 shaders/empty.fs delete mode 100644 shaders/forward.fs delete mode 100644 shaders/forward.vs delete mode 100644 shaders/geometry_fs.glsl delete mode 100644 shaders/geometry_vs.glsl delete mode 100644 shaders/mesh.fs delete mode 100644 shaders/mesh.vs delete mode 100644 shaders/mesh_edge.vs delete mode 100644 shaders/mesh_forward.fs delete mode 100644 shaders/mesh_forward.vs delete mode 100644 shaders/mesh_shadow.vs delete mode 100644 shaders/quad_vs.glsl delete mode 100644 shaders/shadow_map.vs delete mode 100644 shaders/ssao_blur_fs.glsl delete mode 100644 shaders/ssao_fs.glsl diff --git a/.gitignore b/.gitignore index 344933e..c82e5f3 100644 --- a/.gitignore +++ b/.gitignore @@ -10,5 +10,4 @@ CMakeUserPresets.json .idea/ .claude/ .tmp/ -AGENTS.md -GEMINI.md +.fetchcontent-cache/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 9fa66f2..f7441a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,4 @@ cmake_minimum_required(VERSION 3.22) -include(FetchContent) include(CMakeDependentOption) project(box3d @@ -9,6 +8,13 @@ project(box3d LANGUAGES C CXX ) +# sokol's Metal backend is Objective-C; samples/host/sokol_app_impl.c and +# samples/gfx/sokol_impl.c compile as OBJC on Apple. Enable the language here +# so those source properties are honored. +if(APPLE) + enable_language(OBJC) +endif() + # stuff to help debug cmake # message(STATUS "cmake tool chain: ${CMAKE_TOOLCHAIN_FILE}") # message(STATUS "cmake source dir: ${CMAKE_SOURCE_DIR}") @@ -91,6 +97,15 @@ set(CMAKE_VERBOSE_MAKEFILE ON) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") +# Collect FetchContent downloads outside the build dir so a clean rebuild reuses them. +# Must precede the first include(FetchContent) +if(NOT FETCHCONTENT_BASE_DIR) + set(FETCHCONTENT_BASE_DIR "${CMAKE_SOURCE_DIR}/.fetchcontent-cache" + CACHE PATH "Shared FetchContent populate cache") +endif() + +include(FetchContent) + add_subdirectory(src) # This hides samples, test, and doxygen from apps that use box3d via FetchContent @@ -102,6 +117,10 @@ if(PROJECT_IS_TOP_LEVEL) option(BOX3D_VALIDATE "Enable heavy validation" ON) option(BOX3D_UNIT_TESTS "Build the Box3D unit tests" ON) + # Enable this for shader development using sokol-shdc. + # This can be a large download, so this is disabled by default. + option(BOX3D_BUILD_SHADERS "Recompile shaders with sokol-shdc" OFF) + if(BOX3D_UNIT_TESTS OR BOX3D_SAMPLES OR BOX3D_BENCHMARKS) # Emscripten pthread support diff --git a/data/fonts/Roboto-Medium.ttf b/data/fonts/Roboto-Medium.ttf deleted file mode 100644 index e89b0b79a2910f0ac309a1845a9f733bcb568792..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 168644 zcmbS!2YeJ&7w_De+1>Q)rfm`eX(XX1BqRX@q)G1}MS8EHhZ=hCy(kDsF9MqpklsN+ zgn)pGe255GXi5~3?B2Zpy|a^@LB8+3-&3-?vt{Pqb5B42b4MV8AOzt-7GmnxeXriW z+K#D$7`j0a#2)oqG;jUS;KnlrF*Ul`k8%$S zqEroM>DDu=`_S{xT4o8N*FHfoPwhEsWK6{^%>eXYnHR*Euuj^mR3vPO=1@nzG$@%cSL2&p`1NYCz1FAUx;kO#8`!KXx4 z_c22)HKafs_rv#N26xZuU1McdD~xY5=6hx6kP#ybvxHt4&q((9(BZv@Mv9wC3!?Q; zjH$I?!e@e1%H$9v!7O+SenOxyMDerQY(Z5VepZK&#~#i6(VIW|=Lrtsz4i_U!WB^x0&BE^z) z5-XK*RTIx<&}Z~8@p~XjloHY9GC5vvHd$N~#L)#dag3{r*k!iZMG%EWg)hh^K7N0p znqm$JWFt3Q9pr7}^usv)FwR`Fzr&|&``B-b{n-KEbdcnfiX*Yl4tu~kyWw<4F_U6Kw6I7$Cm*jy zWGgOU)eboMF%wSyNPH5>$Y0z~WYaI6oGVD43Cekn;(QVD=$q&8P0sbwed>!>gzztiieB99X%J~%!-mj9(mX~Fmljpu)O42~DC-fObG$tx{ZB!YZKLj0y+=NxeaJ`aNR{wo|u@P77~`0 znjxhPa@PCx((Vm=j=vbzz1yIHL|ED@@tMAO4xpnJ;`crpon`5fmu65(a_1d&)^k)NkcmwFGwxF8L zbXJIh1XdJ2QYxgTF^W~NI;?r@u>`2ZG?jsIih(}GG{ylv3Ws*pn1f zial9NF>X?V)z56f;p`|PJeWO&*&^`dC}zzq?%^IKx;WRH-qze?&%2y_nP3`~Qs5yA z$w*JLTI{h&=9rSE)J$Sw3?_xxGcz+lRnV^O;EnIs$#bm#vQz(_B%=D)6K~N+t=7^O z)J5)(A4pF}kC__LcSv-NwzccGA#-}~7&&ldy^eV593>r z(P164dry>hwwcr%Xqhm!GznM%ciW|*c z1*>3HEVdxbUU10C4u7b&;7UP3nRc@%S*$^JOQI-F&iQ?2%7VRKWY zC-rMD97r3|hi&OKnvgTAHfcyc#(7KOye)CwAa>s15beAHOl5|Mq9rLK$d+yulaeyS zf`aT~%WDW9r(_&&% zX(V)NfDoh3RK}9aTv+lV971xq!yC`u$>F$KLZ(SdlM?KvV2dOrktXzNCaDnkSs*E$ zK`&icvQJqmU2eZ4o3y7JM||3zz8pYe=&ya)Rq6^$`H{Yo0Vy_l z3>FBUl)?0q#cWnr0O|)fy+`Ql9#S>=S z9Ch<(*7MbL8phZhD;0_{mKKI7mNI3F#u$h(25Mu}w5vh_*(~5!Dba)sQ`QsGS$P+) z9D&wci)VZeV$Ch(IaESR5%x2v)i}?)SkSb$O##+9M2?Ru>9)p9bHmJ|NHCo&-^J_!=}!jxk#!{h7amDVpzwa2m5}1rpNAbr5)qW{&Med zw=rXekH`T>R>E4e2mks&XEaim!C*kR0%10Tc+2V(_09%!l?n5*6fZNAUB#b&i%lUk zo(X>vNh7f~i?nI~{(RRwi#W2twU|r@5-n%wQBrrg^sTd<*ewS1o&tJT#W;!!SxRJy zXq-zO3<14~MsI%{_%n$B9rgTXA^vP^mgL+>4;>YgC6c}CZ_N$Sy=x0$?<&P3neK&d z35J@Iz$QVVAp)qIlol2SUq`h|mOag-0N2q{y(i`UTqyi-f&SzBI3TCj&vF zD=@Q8btx9XJuA$Fy~+*sOoPp;nCB1#4~;jQEk*MXU_^viDGnZ7NLXryHBstb;_{#N z>;tEMpanN>(?3Wy>GGt-jOf|lPMmD|{GxRG!g%`oH+Sh%Qk$4slSxEzHTRW4e*KO7^bB-% zKetY_3$a33VYK31t~{fbx788J?24nLTQ`Pc@k2G5aUNxCS=u|4eY-RyuQVBESbr(9 zG(J)SOLI1Wg^KnN42zMQ;5h{Spd^YU4DPVzz)0NfV>I-!I(u4GAT{?>PkS4`k<=30WDR20=3Qa4G+l0nW4j_)yf8N% zlSS3&fH9jw5iEz246&K>i1eN~`d&WCK1D|6gN92;FX_2-3%q2(nRy(V=a3K->S$oG z=E|N!oR9e>_>-PHH%eXDpX7JRweTVv&17MVbnh*r;dWgeO#&NBy7-%GrPR&2LCpE- zIh}us&VP>4R4e>bT8$MA7vhC(ig(Eb#-CWxDEEpQ;@UVcbsSbSH_GF5Fn>x&R%F4- zerYw@JwGeYIE3;KF%7Ju=0%6byUm@&Vzx+{`;FMXOYJj}r8t|^93-QLJjj*es_=Wubwum(b82x)=6gux0%weQt*sE)66z{ik>`6uPNSs z^GNj7HlNo_tbVmWrOP{Z@%6h)ro8-z^i`aaf1{Qe-Aa^CO&&5|G{2@leAJ}L?-w@_ z^P)1fU09` ztZ%9fooa#gt*1Um zN%WO#E!p}tX-#({v(!S27CRvkCM<_mXW66xAq9S3M`t{^DZ;nB|L{I71M07sWMA5sG67H5SBM7!EJ!!my`Uz zi8!d=s44WHzvyoyV)V>k==E2lW{jWu(&RXQw%3MoF}XQk-4U12Dx>=UWI8;s#~>c@ z^?^-!3>hpg)K(;&H(^LH75Uf3R0;F1b#4UXI_4ONN$HgsI|=sqM8-(WurjWaABWK! z|LmcEFP4@P+h>1}#BgWOvV~i6#T}bgtPCNyf29RmNXo_8S4h>J^!4+P=l${Plqaud zA|Wbr`dfORfCYe5aoEu#>U9JndM~9 zDN=Ux7JBvE)-7M$6tA2$IXLp*OpITL;EqFXu`+TQsqg`d79xZ z@&|p*+#f`CO|NEULoN!5$y_h}(BKQQsF43jKf88{N1P3$TvrpZtvHv~ykv4*rh}OV zW@D&`F?d7kaGmm2xp=!MI4}lXEXqWJd7|vH()X?dF6m=eH?fh}-?fTet~stY0NnCB zxTS>9Uh$1)SrGN2zEEVo+Qf^v#rJt&Q zV#{P!NdCP!{YCklKKf81)kv{?Qlj{)GW4IFxzZQ8r(4k*VyR<&2W%zjSB8^DWW?|H ziRG`SL!Z!s_N4epH@!^Ze9fA^Wz7sxr6#=|vNBceZRSB1l!`8u$OAY=Jjf}Mx#3P% zw#y~XbBeQEV@(d%MkJ&`y-j#nk84YiHhxkq{N)GQ<@mYM$a<#}U&XJ=7e0|5;ANnY zqL_I8UH!4aGv+ZThNowDtY?~y1wvX{GF|+|Nega0c;y_C)d%BpO4nXK`f6nMtkHVP z_zA7m3m7QQfVwpr|qp;$O|GNErtteCOI z<(f}+l2q4EVl^yU_FjsR#`XSgLS5sXEK|YwIuWxrA+Gc+z?%cmOH@k51jf2)WQn-K zIoNdxGNPWxJOHl(gu!nin_&Sof#sLeOfx^wssjoUm?-b-jhFyaw5Ue|EaNOV@^K&e zjPqd=_7)jG1jC&V#xuD?Hj_=HzB7Wh+D}_YU~LOF%bi}gAos+n1?%MQu1Pco!&FCX zvg4(<&_p5bJP&gg3~2?!a%h~x$Er!6BAU4WW8qJXsR&yE0`|1KT%#F#7RcTOe`6r| zvOhE|EP<&6WZMeqZlK6qx}hPE_g4vLun0x8f<@59j7*~#gDs|7HIon{BMVrGrC?wZ zSPCZHRAM=O`dKc0yo#(M!K4=nUP)Y^Z{K`KJhFBBeo?takL}(~YF=w~lhoV2i=Mb? zdI2}P@Nt{p>1!gqblZg+pq3A6Yt0p(5FX?BSRH=uQFC%=Y@-EViZ9{1=M9w%bEYc< zfM-E4Zg%DP1a5B=lVZsdmstK!5>0=0(XUC$tc8mw(u-no*H0z~y>{!_my^bfS|DOv z-3nz>B&Zn*-?o9`rTVt0qQtnzWys(ZF&n~>2#*zDUSN#p5CaMkEp|%+^Vu{b%Sj3= z>mg~xv{A1&(@WLsIoxE;-N(pE4{qOdNIbM{2grJrUh8mX`CtA<(!Qj$@VED$(3c*{ z-UVd?1iR2lF@^KIHtG#l_Y4f`LDL9Ipva9~pdq&idh_ZV>@_M%;1RoFR!mUb?hOfr zKgN>^NwMNC`p6{;P7<_WBB@XRaGfUd@DHhbKylaRJi^EtIX9`O!&SF3%z?&x*5&P+LhoWJWN*w<#%4Kf^ z!<7=@KBrfLyJM&cX#ujPdZh)k=!Sk@km!f2pUrkInvpYSIcamH8~ye9I{NoA*X9qW z&mg0_^&3!Y!bQh}p;spkpE96pi-EnTY#Vyuo9ruda%K<2?2s6h9as^IkgQJ2;BRP4 zz+4G~qro%GjKr{>4qCN<){v*cjfs*UTxK+z0Gb`cS*=2K1#9qyjbtNfU7e8BW4nfBxlqiHNhhJmPf=oR!F>{TgY=Ud zylx>U6?_M+dswcA(Ur!U{)*B0YF5`UEQ3Fyk)5k~3z*o#tuA2#rZGWo z;TD$}-8m$cl%x&FY5E=g0$J_bL zg5jhZFY6f@VLlJ%ke@Jl)Q942LeUAAWyT*Ef%Mo=GF9>^I4l0)3X!8PUD_BYLm~{cd^^=CdWTtAE#bf326k_4F4VN)7$(O*5;K=>T6;gH=Df5-Q zm8OZ`xJu(}QeiE&7??+tx(1qP=?Rlk(ZrHJtDOU-6(>&MR~6-JBKQlx0v(aZ4@3&z zA+a>lzCbBjf+wU32d|?ZmkF8kNR@L@%vI~ zm#e{~m}#?ScaE+%_VAqDhw8WK-MVInHSJIArr}H5+4k0Z=W>^}^;$Cub0;kAsC9gTN)9xh2ftRZ}+wSxk6M zlE;W;UJFB~lhhYm4$UA}rXFEqZ;i40g36(Y7-uSBJU`Mh=M-hwY1wOlD8dBMb4Q%#S3UbNxIb01qJ7>RAdU$cqQM@Ieg= zWP*uTGvYzE&{$RiVp&89L3%6zFk*+F>5mic&->3GuIj!YkKWdQTCMLk_Zn{_SG|UZ zkoXrRHWn_Vk0|XibM34N-3LnR=T8V4Hv#;_ioUnZp{N7BuUJCEiuj4okb$R|OmJQB z=5!(0@JaQaI|FWE*l(nIkhxzUR&zY39D3`_2X( z_xh~cKIb?_{Z_QC><8*cK-0}s;t~=W!^W{9o=#nA!{Jh?9dHjK$USPV&Y03NNjz(1 zOp7RiHukO(s(uJPrmH|ODK->5RnE$E$Mt|dumoWG8%);f>DfaAe7~oE|2X=mcSa1| zJa&Hny~qD}F=N!S`tL0pGeb;plJZls3Vy!%vS*8>Gp0>ym`y6Y+;n6jxikJavod3$ z++RUrtU?{d$L$eXRY~E7S({~1kx}m&G2`arVIvrTjI%e{&NTo^4H}AY+?MrqY9ywNl|r@A6!h7;*LKo- zy1dCVE_mnglQKXRV^&5J2!s4ZXFu9 zBE<_QMmv9(tFn1p|CT>( z^xLO-yj5UOAin~@fPXjdhGh145tgl1ThpN@}rHVTNqKG zP*VY3qDUeQ(Hvh5s4hh?@oa7&XIYPR9sZfhH$00%JZ%BZJ0?hCuTFIUh7xtm#}TCb%9- z%}<|RFMf0OBen{a>1uI_xjM4jnMx4PZVT`p`GRws9gdlr1s3%oOw2WT0wpEL#FA{7 zYDp=*Qha)9dODybc2?)M01F>x7rWE-mQ$ys{f?B~=H2*5SN9~{ZvLp;zp?Lb>io*D zzx}aer=M=Vu8dLa!K%EEj1JEw{Rw!`nVLk`_dg{RP zMl+VwNvhLE3Ud5Vc}{GIW#*7NR z3VmfCQ=$+fbXAJQ#&IgJW#DxkjcvIoLuVS;R`TJ!0H{%^oj^9;S`(72gxjE&Iegbp zLgN_`AQoAJiHOiUNNqq-^CFTZBus4HVT}2Kd~WH5&o5v8{KC3J@&n7Lj*qO!iu7wS z`>Uwmev2c~ccN~Rn7AMBMSZ)rTQllV>$zk)K7`zh!&M{L9kUpT839M z{08IXm8X;dPhq?$;Op~hh`~x&9f5gDnEG*$p`?W+w})6_kt<-x-6Ytqq)HhvMfTW^ z?5)dEQ#?oter}ai*7C_3uh(SdFMsv#(xI<6$rRf9^YlyY`>j z@5L7^X6#(}(9~T11NpR4;7hS|88$Td4AE|0&@>1FItOA|Sg#n5bTH^xqUR7B@34i z>@jblbIjo5caCRe9lLuxYv81b(-+TKd+x%PWs8@L$X>o=)%r`P)-G5gjvsR+d(@R@ zm$S2ZCB_%4Q3<*r3`lB$N1*Cz7?SUvz|NOpiWCds;?7#iAZ1Wgx(+S`Lf*PVe{`O) zrE#E&2hh5*c6o4{($i3vKOBcl}0@yQSBh^fIYLFTbKY zh)rrPc6Vj0p1TTl(DJM1t`;w`b(jr(mc{j%1zJkO`Ev^jeqsfavJf`-2h0=y#oF0p7tB0z^mykTwd#`KN52!l z{3Ta(eBYTdfM>ej8OKCzg;9S{Qdu{x2E zu?%6U5}jF@5iZ(_UK#e7=9aZIEKwSZa?9sA$|oyg8iy&1s1E>5hx&kbdESrZoxD%* zwtC|Ye{bfg=UP1oMkb(k&!G~j!gb3dhwtT?5ipSno`~dHX144xV=F1XYcst^ zKc)A!?IbbVE|Cwu_=0YwgXq?a7sv-#sRiO^66;QjL{@RB;;&{E{XMAH5Ku3KF}Re# zfcKDT)kY!7!H$uF=5PBXJ3^4-)X~W5!yI$vvXykM8SH0`vX-+}vo^7IvJSH5Sm#^4 zJ1d8+XtaPO)&oh=G864N325jpgJh&3UCInI6f}#NPy|tHAZGBl*v-~7XVkRqyZel+ z)o}OT*>gUMq#H`LDK?-0=>^O>tm2VZs^TgMXu~(cs_I;;aqBk(!(vrTalbR4RKHy|v|-c;r^~e8%KY&w+1n zC)2#P8l<$1mSt*N$|r)N0m*?01U~*;LnVjoZ+q&deGa_1+;^pEXFgG&1dk9*9tg z%wm4tLZ<5{2J^7BY2<1t?lt+X1Fuh#_KNes>)xo8zM}|kbdFn1a4(xJg4&L1@^B$9 zMR*QzUZ$%MUslQp=0u1yhlG(?13p?kC~M8f1JmDoZ$N{FrnBqrtXXqs9UW6Yy;74V z{TkrK~rD|#mnt8Gh=4xk>d0S zfwvgunYtnhtQMl6lb`VtbFFnB`tf&BN@E{#>Z5^_<=NftG*~E5j1?6inu`z1s8qG~ z;T^LUtsT%~J{cjdnLtc^>y$~aoiXym$s-2#X*Uex%oG=kJ21|YK(LqKnn~wLYx2VD z85pNR>`dY0Kup6A)FdrPHzEyF7PE3N2x!)g(_8I2LViPsSyzI9NW;{M@w2c3ZVAs% zFqyQ}H>SeuFk^zEwyvaj;@5I|MvatOhqp{!v}x9g+(ol?9e%IcyVYlQlC!$U!@umA zGq(Tew9*R)Oq?_zCgIb$RxpWl+gYu@%B%K zE=ePy^zj+9K(FEVOOgGHMywhnbXWY{ovCa!`2uRbzag!{;WJv+uZaEFZ;F%;NTy5v zD8BwGtby2AR*EN7m|{+XY9Q0a4g5y~o}u6L8CJhYYM17 z5Fv}!A{U`W0)%wMJCNn?it4aM>2WiHBWC8=85MsE1MMh;V|U=2t9+28YQs!Y!*}JU zYb>?v*KZLcWfWW5f7G1hGUek<^Vqc}L+(V=9%PxS0vEyNsPZ!pX$(|g{48^*Br`dZ zffM6x7S@|79=b?|1mlcVQI7{{{`f z|HH-MghM3c=5e)`p5xIW&7)6{jFU${UUz(N=N8R6lFrSWb(XttICFYygY{?5ZZh>4 zJg9q%?t`=XF#FmW_Vq(0XkNCG*t`k?}ENMQV`+zQ;d$rEZyLfQRrp^sUq!UkuKrDO-;VyK3zC5_ zTC9N+S&mrA(#|}X{HS`m#u+!yjrR(!nKD@B$#l#=j_B#SIfd5T5mZW08-7XfB4K@&Bx z6YvgcN~+Pb%gH;W+H!i9KhSez5c(-=ucXKM13kWy)S@R?)X~526H}b&8Ej_^@Iw6* ztBM!m+=0N|k?7`;w?Y(^NGng3#`7m^>cO_lK(w!~u}8AbNhbA)p70MW!ja1W%w#44 ziNg9>?3rnnuwYY&omDzSi>Xo)focYbISwG^eVeCu+_B`$N)n=+ThwmbvX6 zc-DlBxI7h!jU+Pbk3UHeeU|?sKmX-~CG*Dt-2BV43tv2^fLhZ88aegubdI;34SdQP zpf<`0ot1dq{w!R-YGq+V$+pPk1ekcO7Tu*$9)DYVHF^xIl~k_H@;Qxn9ZHHg6P3`mPQ{M1XSZm7v1!Zhe>1LYQ24|=U2Xx6t0Ytt z@)WUp4K^^)A3-f1E4x?0fK}5nW$u8@&&2T_e#y!rKX@4MaIBuGG6)iQu~@QFS>P@4 zm6P{HS5B_X06LWm*;CibL)g=a%2z8R#+Y9j;k-U)1-MSU?sP_yF@#dGC!@t0=hHo3 z2By#59LQp24erJRJ$r^74c=~G4@35Ng1#`qK|V-pJaWyib!(>M!n0pbbZy^p#0%HC zABIf3aO0V)q4(;Ua|Tv#Snry1b=BGB&-NSBSt{Fel9imz3i+gI8^_vppVsf#w?pmV zrH5wB5~=I)oO$c2#%--!^WZyWuZdmj)oL#OJa{eQG1<{ zz$oRWd<1MlgvMhZU)ZPKJ_73RrFK-P_xtIJ0? zIxPWfBqy?z85=1W8;|ksl`^0Xit32rGRFbN@F$k!i{MIFm-}{vTOF}^Y{_(t&iy2| zFiaZ*T*I7Vrlf;ay=-=?S7|_1{l0IhvPw4zXgC%{g{)s!=TIt{Es{s70hpYo@T(x3`|(`$e#ST?x684aZ7Ytz=l9;^c7 z2!$+Um1BiPO0?QHk8Ba`xy++AxrhY4Bew!CL!!Jn*6Q1;u1)+V;2-A0DbSOm9gDq>6{(n@oI zH7n{yT20Ld8i@I63*j>i#7k7Y)fpQ^&rt5xR+cYwQBlFHw(po>i_FPpphOp$VRrO; zZTJv(@sl|Wn4H>P@O;RN7w;nlP>yydhv=8&Q`$zZN?QVJ5zV(;YcfGtM&PrOAB(7v*0!Bcr0Lkzb8mnXCUX*51id=G{`mz6YOh~Kq z5nvo%+6Y+4$gcm<^5yw6XXZ;|)0d{ZBE-eXOOwUB?AnWIW0N=M&VGuS=f%_^7`(cF zyR@2K(U3!<p1Pd{|vAUh(JEYb7YaogPx5hzv8Dp3ZvP&YCuOkoqlKu!^kY2B;p(_rUaGz(w#;(#e0sS;u~IWb1oX14_M<)4BhW z#^C;yJ8xZg729{(cHYk+em7=lU*|o@frvWo6H9r-=ypVwD;1(fmZ*6}x^0tz4LKn- zp43z~C$T1QjsSxbrvwQsH{l3M){md1FLiiuHaoow0wt&mKUjc&fEW616 zumK#$jI$l8EajaaZyURf{=HmWLVUN6-zIfpz2K}bykJ7le#1L{vX>|!%ZUF@QuR|3 zv@!(k;TLGlD1W(fz}2Jl(y43EBpupPe@ZFT@M-85t_m%;t``5vTX)f@S@_*ZSzh$-t7=kCUuj% z_Q09YL%xR#utBRRv~+jhhGBKOD1zF3Yj-b*!ER}nQA}!1*z_;N#T)F0$UtX<;rqv+ zw<4B#vKExMficC_HVAf+P|J*kYbze4cjz%G&-BCPZL2C(jCI_`#%BXJ(uX@%9uIOQ z9}YpDx8a<7zgG%AAJ~A-qn{5vL(lBJar;>GA;jyX@BwWsehpfc5JoB?x;+AT7^u;T zYc@?&@PKW43HLom;(QMB+OilZ(%aW~aFV zs@aKH8JXi1_1-N{=W0r$$Y=!mv%CWm{JCMCvJcCP>!Mwp#pv0pIftU&UT{Bh-PrR3 zUDH@CPm8aWB^-*{dkZ%*fZ(NVgDdZZZ0ZQw0)x zri47FCdfRKi@2)!ga^xioSUAqt$p8j#qmF{_=!GwQ3NXf#5HF{@POenKTDXft~i4h zS0IFAi?dDS_>r#De9XJzH$;>pBTD0+@xd@}#pq5FL zmnmC(omcf}&DoaPO`1TeS%1Vb?pdZ7G$5y!Kz9-cICwidO6f9szDTNt5cFS-IjA z30x#U_FcQypK!lyIIdQSUk$rWyRW8}&i4h9Xtqm*AoIP4;3)ImrZdw*QO^Rl=laq- z`s+&i_=>5|8Xx*A3HN4I0+KIV%1@?BcZKx1G>WXQKz;Gnl12O3XrWO_7l?b?a88#b&BshuMKKxU!q##<<% zNbbEZyg)K9BXotw{O-<~DRn2-#XnPr^!ljt)~g5386z(c)68XXmJnnjK{X}Ngi!+A z6pSF%howQ(4ZUGQ{5^+^3AC~@V01i_2uv4g+j;VYZrvwLvemATT)IEV8{BdKAm(R}lfReRnf^jf1^f8``oWj&K%iH&SF)GHh^2@ zDiyp2ul%42@6l~2Uqk({5MHB2sQG`bk}`9Q&={@=Qlp$Z*hnp4VGCzrbRc5~-FUIz zGy3w};$QC`G8NM6qyoK;)tgEOkSB%5!C`jnZU=?!;6S#Tfr4a}Vx$zQrqn{}CRsW& zYY%(s%@bbgf@0dCoipL8FdVGWg1&lS1v4cj*!1EY=O162wMvNVbbTSAwQxYnkS)FS{4kJ ztddrVMof;9EsMi*Ejkn6PuzhX6dABPnOtHlp{|yehP75&cI;}_Kz_8;6cyiKe82Y9 zn)#qaEIR$<2ZfbTU195-$@;kwco$7rT~fZD2bi=cn;8qjU1!?XA>)fOUtUmxEikp@ z(VN(LF7C`;IZZB{2aTxiI&AiU(%_A1_%m0OT3Y)9f;|9oO@#CE zujIbD7RF|0^kgXk(7-@LFcp!0n7`Oui*CpF`T_-a*t{37{2)Qq1SEBe6fWlW?`2@l z4p&#XxgJTzvTZwX3P?=^vRfPQlHHvFnwg!C z8^|}$r_YxtW`27GHa8NR0GR%ee6hysvE+U69$n2gySpTzyNSn%reMU(67*@DFjnzW z{X*DcFf$%COsye3QDl)tFILmf!GeYF>n08b;BQ}wSd-!Y1QC1R>2gV|5T_4}q0@}n zL6$T7-x~-?n`ljPk_=_r2s!Ap4EpYPz?2*DX1dwLG5yX_>^zUs`XZhRx5 z=ftGjNC?~(1BwQLqGoN+3myh*^ek#KWt7(HJc=MO+X{j*^eli9tLZB2aYFwhh4gp1 zZUJuEz)%yC0M#y6;HzbUo@=JA7pItZer^5ri;uvX;|5IVY4!MYO!XTYY~ir*(yoN( zLDFewjb7qQmrpzCLucPhm!ziWrP3T-4E{5PUD?H9G9#27C&p;Q1NkNw-e7JU^-AFD<-2q_PLUGl@1bttQ0TvLq%@ zlHnpy_t9_2gm53jjWlN8(L90lQ9K5nkb%Ys75j$G#q8jrG__rVLA3cEj~3wD#UDnF zCm%0fxMtF5YWa5Hn1#f&c?&Tw9zE~|wO)-O)}OO3-Tv;YUXSVH5?8H8(qy=@C0gY}#7ib{^Iq7s~^&dt#2X9!!gn3GRb<3Ym)-9Ev5pNUZZ z#Ofvbm^%1P1+nQv4y1VH?}qGj-(?$tBgZ`Glu6*_htv)R~_ioZa6ym`05o zHNRfHxg#dYRh_TL%lk@f+DMAO@+UqdW7Ra*iFLaHLth9;kSMIAqvZjx1R+3t_fwM8 zu8Jfp7J~Ks{M+hi^HY-4#;K%aLr12$BrgymQq!w_OwzE|DZFw-W_+hpHZ$-bDzUiz z3ah;G{YtRRtaBt)?0@w|&-P=dzPPq!+>4y=NRwfmyG?2T@vu4L`i^gK!*uprrR$oM za>u5A^`teeY}zs6)KHrB!KjJ-oDW;g8Jx9*9Aa9ZcEvs>RpFap|0!<w7KQ zG+_C(AQv0(uviV^f<8nHlB9_NPYURwe7dNBydxGC{7%zJp6tu$*amr)%H|k=3(I1c z^DwoRjS5-3n`5|s)N*57f|&royVa-j1HyRf9Dt6}9&4Z!FU>R1VQ-|8)H}1-Lpjw# z>|u}ycfti*cB70PtOYztapt@mpEn%Vd{zHu9~`}RR~+}_iu?50!8u~bexv4$9X)GF z*4R1nZ%ej>6+4q&y;A4e&FOEKqt?8f1^-vtQW$3{HODn!T*ffeJK*-tMXcW6Q+x0oeVTZR+)84`kZz0cq4^O$_o^Tz_WgJO?E!wQQ zsr%cRr=djo!yWd;gCoJfNlI)9me|=R$A<6*V34F}vvN<*MjDEBT17vN_jz>d-=kgk zSJzJzz8Ke`%kXafzqodNLZ2Q}Ur^_lH|Z;q+G$cu$*~PqZrQ)2TJxswR%^UlTJ~PiNcREpGJ5QFt?u}{=Q zMS4b361yRhm1M@IOP6T3w)Ltv{!jPj<62GVEDr8>wow(5aL0Alc6#FYr_@mS0)JG{=MSrX0BPy#qcKgSWkywHH50n7^xsEH><2tX4A z>QB0@9$8gKuaO{lIv4`RZ@6y=_QO(@k%^_tkuZ|Wz53~g*QS?`?!Pp-s*)Syh7B1< zZqRb$?~NA4;kf0@0aA;U{}sEkH^ITz@hMln{PN24GI`f7T>|ZQ6#gl8=b1J4PNxPs zb7&<5MeoOBK>7x7vNp9wnX--A!X{UBzO0_XyS{NR5S%-#@R{7mRDfuql_F`mMpbWX z-T+tP+>>W22fh8e;p3*U{VO%lk9aF*kEecMw1rG3}Px~Qah$~YLyxmw54_GncUUZZM z)r}Yl4KQv*S(rNFGSC@iu+Vy!RPid$JN>*2C^x0J`YuWcdPHPNZ}Z8SSSFYJZfg!IWj*^>+Z5k)8@7tH=9JwnNQbEArV93TZ-dbOiQouE_F4TG-}i0 z!8t_y>B9-~?UHR9A3RTg>M^@^LU`q@21nlMRi#Dg`0{mQ(m!9mWG zz@mmiZxIm78{Q-G6M7HMSeL>&U>gopp4>KGklZOaX6MDW_X_Tv`fNZxk*wGvYeLTO zKBMJk^h^3Y@CAK{-D{=qUyxYm&FtNu9Xxkx1LO5pbguL(#vF%zV2kk>K-FP}vGN)Q z!w&QO1!HMFyGO-y<%@kJj2KBcB%W?E8NM*w6O~)QEZFTlBSWlw_UVJHZo{T6Cl$I? zB$Jv?)BS(*| z{S3JW+=Bv{dfbCXuwthq#J@$>g7c|1$|4Si8?PVbe_>iSP*thHosE%rlh+fvx@;Pn za9a$bPfT==v|AeMa=i0S7`ivBh;2?`B$MHZdtoF&0=9AeZ=Dz#JVNhhv-Q_9;x;Qw zizZ5GVKysvFh!6;hJP|_i8T0+5!Ctfm)8h7EJjh+uN!_Q#UIi8^iO)~{TnkbXkD7%Cx6W)+gsQa+4dFcG)+odolc{zcv$1g@Y(=355IXDz9P4p+kSZ%F zu=a0&GLf#ftB6=EE^aIpAB>QVRdhpfzbYsFY2t|04Vs7_Enko$pnZ4Cj6W9K{PLGhogRI8YXJ~Yzdk+o<;TlOJ-T<{>MxHyC!xQ% zF3{_D?~)2)nJ4c|%tE<+1ee-Kd zpG+OxBkLNf0_V1DJKDI6Yv+W4a#p1}V!IIE?AtD4x_zn`_ zd^fhj!lN(<0dzA%4~g$yFFUSVz1oTXrD{df@0|4e*qUX1N>*#scS1SILSFUi7J1tA zo@=1%nP?SPy=OXAtQV_8rh%sbUV~0a6oxBaYP}y>&l2tx`L{r8cDhLAL2z{{Pw}$x z)k66K&DYo?E(}mLgNLa^TY0NQNhT=qVWCCrWvi44n@zCqI1_nrpSt%0UYOfV&b)N= zS*K3Vj$OzYVveQfJ~*Y%xU&$5G%(k<33UA1tbb&f1XnZqhhXlB?(5=?@$A% zjuHQXTT8I6Y#3ZQ9#jCYBJHE@RUc1QiIbhA?Am9O=ui2sd#=e&r<8+PFI}F4J8%tj zT_61AjIaI{$GK+WE*D-jeCE(0)0q9Lh>Y$9%r#VKuR3~K^FLp`w=N|tt5NW*9E^ke zO1|MnKt~4ig@c&I$e|c7i&`}qTS{%y77;&UaZdPX{!AyGD|d%@tts~8AMyMBR*(#k^x--| zwZ0T*g4&U^5ADr35&N-O)^JXos1jG}>EsJ(z_=O84MpQ-GG|!)BDff~_+ZY8^^N`3 zaVJdPjmfa{xGiR|cAqweD`y2|R#Jn=sQ`1iaFcTy<{_T zjh+`ry5_S#$s+D>Z4kThzYfm7F|US&PvuGQHcAU~lmy+~NewGe1ZxFt^>@oG<;&8J zIgV1v;kfBDK?^*+S1$IVJVABoa!!XaFN*}V(e_^Nw8d+O}4sRt|=}Tt8vQy1^JNP7mSl&t@ssfh{I)F zF41sdLpjysU>L~HJP94-6W7M24c5ox?=+ekK9)DF3&vChapHf#-GM@*fA4Rn&0phQ zMF>>=H7fXU*ZJC)}QwMJ>-ytp{MA)>v#{tX2iEt6O-o5~l9u z#u8w8N`iWjU`Tbbln-+MdZV3S#a(9L?enr2woyR!3q^EGJT?$xICI|2iZ&Z`^RY%Y zE@LVJQ`!@@odkdQA^l@}WPbP#`efB=60|cspZ>M|*wIfz^TW3vIkL-?xQag8wUhp_ zk{mz2iUjP~MS?y&PlsGTwC}1E;CylYv(K-C;!Ei#remPEFGFFt+oTK}V6YmR@-`R> zv&T>Xi(yj@g(Kvbf@`XwD2Q_1B-r7DcfCBrwQLNj^e-MaC^C)jlmNp0RTNWnDKwSE zkbgj(iq$+>6O#PQxzRxj=%2(%Ca&7EnX#Byz4W7B$Q7D0Z&Vp^8%BV;C|D#uTiD2d zjextJ8kZSFPUHMH>*8$cFhb1Z;D2N#IqD>bod2wFPo3LIT##LxZnW&i%Ru4%qRjve zl>YCR*LBMcQnPa9eNy8TYFVhX9_cqfVF3w_>djkFSnd=5n1hZ7j4SW6d z;EOZijLA=3Uuu?HVqT}2-QAh(6ca8CQA8dMF|ZK?438QL)nGRa{UQc$t*8(xc<~In zfUO@qsT_uT&?QE()}9#vD(7)5lgMf|3Dx~@$tRu8f|}|)q-mP}!ESS-_dztT$rnCI zb0t9aK?0aAQ>ky5fyRKSeQM*>lO7sa=T#cVS>*YX1-dc5IXchCfCWID_6LvCrW)cj zgA=bMXcX^YmXyhX@<0X0dnon^+n48kk3FS$*JQhf3El|I^j;G3wtDL=n0dVvNpszl zlt6D*V8>L{;0*C53q8%2_zd)$;BHz>S0X2pMEZrSTDEqV*+oUsD|f^E6+zB$lJMd) zVqHcS(LWup=#4P)-MX0%zPbGEgZb;85wGp^!dK(3(l53X(=U*M4d^_wV77K(AEqcl zYHuujL2XY9!>kPs7FUgLCKb@nukN1sGC=3YVPXRuzQ zf8CGGVqrk4ZS>W;fCEnFXXcMc;BMt@H)UH*qK>(6KUCMSizI!^Tkp&UJeAxP62*{s z*wX{4B<2KKp;lBr4DQls+VpF#;z-Aaa)EM>O34TeQyX3iZA3vTyTa0nt69F3KK& zp0j&p*#OwcL|zn49%c*vW!Q_F%PS>{<1W9Xe?9zxK6~|YZp*W^XK!7-zSxpwqh?MY zH+IGhiPGo4`Ta)kl2SydN4k*JX;JTH^q$x}K4$Zh6=&9OS-WSiWBw+18|WmJt0JEj zfOUux#^bJM>~1Ygry&ue(`*LBgSH+@7{`?I`)BW~8P+0hoTK98m1yMjmL_m}UrDSh@-*abYGlM+O z`@a9rAI)svz31F>PcJ|H*1PAhjB8&a$nJOeD1UnPV$RoUoee8nPmBzm*K_S=_BnUW zo4;?$43*^GT&PlQ0hcwO((p@rm027FlQ~E%OlXm9d4-4aS!F`rB76n*J)R#`PYEmq zLnAA&+*DAjrz@~Hmd5uRV$1yHPPn^~%?}L@(i71e-Cn~2EW92YE(|qV1|0WfuQ}wI zgPJ;u$`95&bhrAOp{*S{4?2pT9D89i+nl$+oyQvUqp~V*zsSD<3EM|AwXU zJ*@oWbl14QS$V#f4MpDf2fQu)$%(RqcV#>2&zw)&C8t&fA}z=riD(}|v>9<7H(8-3+EhYCM+k`A0MoOc&hbi-AnF`Xi6f>Lqax^t zH1sVLRU)clRNW|*2AEPxlJJ+mXr)SZfa2Kh0O%V9{P{O^JN?kav5CZei#~{*}85Vp>(`7l}Iz!Y>wl!h zm;R#ABEYbbQ%qS<8L<7s4}5LEiHeW|ui87|MhmiA(|s`}kL)U}$|HkxBi}vMeX*bQ6fXg+M_CKV~dL@G9eh!P&*z3{6Ax)g>)jvL5rjNIF(u-_gEkKJ&mgA2(WG zUzUC#!MB00oUR>%+I66eZvs8P+!s!f<-Tv@d9&#TVJw)NZojC3F5c7SV(+^cs>l!& zdxd42Xx*BR{9l(zmbj@cmiK3()M75)!=)@S_&Gy7R#I|-5eF)r|BVsv;lUT0q=QpM z4GWn(LPnsKWiEfm#owpEbKZPq@(D=O&OFsd6L6?|YXbB-N7ZVeY2x;+eP7TYtbHFn zOl&!y7Ovuzou<8n?DV>Yg`GLi#kRRt1^<}$6@tMFlt~bSZq^9D)fYQ^U9Agizoo^$ zWD$Y_sRk_>%t0$6jQ$M72EwiRR3KNNOs|j>R)3;$9jR$Q{q7n%qW?e_8yb4~43f7F zOz0mb7uIRlt_XO|_P+6Z;@BGxEKJ)t_GWz+6eoa(I;5W$+_K56ql~;2*$?2i{iQZu)x?79|NQg+$=(-9-`=11nE7M%C43V6i1u0j8O>Lk7bPEx?q6Ar@c|fS1YPcTEgeEA1&3DorX}>Gq|eHYlYj2}>)9LQ|~} zE?FfCG&ACZrcf+8k?0w|A;BS{GcU|1-K(w__nJKFNRox2FS9NaZjC>mew7uPe0Am2 zv!iZJcx`ZIVW_B`ie@T{ho%hNKZJjk7qKC4LE53$dry38;f^`Wf%%ol38)1agF*8P zv=9+vc7_o3yhLdd+}!|NDBy-+>!llpR(qs0p#=CqF1wC0-2>D>m#iw2mk3A1T*3@P z!qPW{CDw!u?;Xt*FSIJKdfl0eLe@E-m0*4sj1gU5aaYKBh~ZBb{k>r6By_==fANVi zrc1rV>w(t3qgh>4PY-(tT=tqc+o7=DgLNMsl6uG<@;W#TAPoj9Uh(Rp#UxR9jNT|F zB}{WDVrm4=yD18<>tfMLbda8Wsd&xzYY%VU&dVP-{Lbl52cQ6y+ zDHHi)F%|KXZO!WV$Jd=Ih9hp?>|%w~y>~DnF^_9GD3w1Z-xqTd)xEoS>>$k#l?BRE zP-ZDIYT`7nI*1H|3>sTagA)Os-E8N|Z_G$NvJ`-shL&kHv_RQPccbPrfYzV@d`) z2eNo3)9}`x52n7pdg%^+4^&8&?s`yRD9+t9%~wBnz6IV`i`+Ay6dP{jrFmK#1!MYtVV;E1$l-<%BHEiHCnM*c1D2vM=1H_=#?9TXbN66}F!}3$PYL z4(MFe0f?dW$a^qyK!wg~oH&bJZ`fil03Ikjx~OAT^?TG)-@^5YW=)6CiRh;(145|5 zFz3Bs!xlltgAQ*rG?e#U2FTFv<#qRa3?A51ew%GDU}Zn@XfPFk*rRo`&N!ccfTz&; z42KuW=+Qw%XoyN$&Zps4v%+&M1jLp=7k|2h`-}de;V+y`RXE}Rm|582Fd`>9oN!4{ z>4&i(AHq0;i}?-HWYWcpU961y;a}$Qr0R#e-g!spyX%FWUWlfbzf9k?=wJp%6!5%E z1tjv)l|M3@fZA;?{-KL&y4v;pG==R!8BAJ`f7ebK5!4~WZtATg&Vk`e6;j4{AnHtv z2Zp&P7GfM1^adn;mSu8MfpyW61iLcp#V8BZlXP*%e&Xp@w?>Y=bJ68a>oYW+v5^D% zjY2pm|C>MFfB(T{l|9dUeb&s0s`5N<{OswIRfV|KnEbo8`+(%7>o;iIqB)B78?XF_ z^@se2^^3M6FRUMvbD`j4{kHq;%8@gvgD-r1+10sOr@@bUrL^h^a&33w>at}&X3P8C z9nwdPNH4gB#+!c~8d#J)T%6JIT8Mr|p$8})sVKOP;T<-1S}W!+VvP`lrtE!9)}N)i zc2R?l(0~XvS&k$EF#kG|#(@OclEGjc$#{7y|LLEcTept$V*B>FSXutl{hoscbOrM{ zr+l$*@7JnYXE#gapSyeVS%bQF8H#KxL=W@t+dsFRLX2XiR@79V8ADZ=2Hgk(HXaxO z8bL&5@wT$$29nCgfQXP?pp}u>Sj{I!WYnVJ#tY{VK2h*tlRuntIT5%q$xba?d>9m{ zM=2y@1h_Y&F42>5r)xZ`KPsSs`l1HSVHW^c+|hin}V78)d^j|{!pA{@VS1|Mj7JwYwix- z3}!v{r+gB#{MX%!mI>jDmR}SjkP#t}Y+)h}S`?F73K)g4`(DqKEDpwgn@j3>KAUm4ANz@HNDkbmi&-E+u4Z0BvZ`ybxx z$-syR7KUay_!Ej~4zmv&NVf1EWB^nJ-h!a3Ow;iu7G&VfGEwcNd`#flun@!p!)Ve% zgpakLVA~w@M3ml6p>_0SB{m4`3cMm=Lf{zDaT4263fsYku!;i1%QAmX2fo+wAJFo# zKkKwpPE%SwYj5D3?dF(BnD;Sz3b-~wD+veIgCMnMnBX$7F5ogA{9oac0(4t|`XO1& zf3)O4AO*@#FeOZDVZ}V4CDO=G4`|Vt-%Oy;wR z5O{oeu2w>S2YOOlGl;3Y9;Nn3`l9?y3P?0K2XUsv*! zXUw0^MHcO{J3K)tr+)t(U&=bj0YBgEsC1Oau=jPd+h5F zC1M!mVKQowsYbFJMX4ooktw1@>2HEQZHd80A)Q|wM-i!h$({oZ@~OJ~ZHTI>e7<^% z&oOr1mN$LnI7Rlk!>h2=cLurFBlJF1p6j0E-F#p7Ub)xU48BsS&2|w^;4N}Yz`pA^ zDW&72)C)K<_T3V;_&?*MkQXN=T6hsB`kVfRlO!};0~wGa^PfmVev>8fk07?*=l6&} zP92pWvOeRgm;~& zeW6E&A@e5yzUI=>P)*e<*OA!`D-_pokF{Vi)V%TqUO$s5rUk2%uatpKR@5!f?3AEN zfRY8M0_aAL52biwykVFa*bo<|z&8V3(H8daE=lh9wjA`4KlM4V7rFE?u^hfU3DBo1)Aj zYHJ7!Vcr=J43N-2R4C~PC0biHge6mLT9_l+?tnHKCHE^);+Le2Q!2~ho#XksM@SAX z!WO5GmjBtamVGN{JYNj~hLup>R5*9*8v!R9ba!*%EMZ~TG6irqQ=J1gRzHR<%^xpStTo;*X= zF!x|_bY^BW8^=m@K_>Q;=&|Y1d>;Sa{>9_y)PB*AFSa@3j!o?w{r5${m6E>zRD1w% z#Y#OiMbFNI05`NEiv!0{#7V*fv;ZOPUkJ%UQw3;dCPhvZjCm9Q=?#cT?U9qHy^G_j8UEdmfj{u?OAQ}UhQt?8a$om%#HSk}PT}qxp)3$1*3kf|w8Wl$r0e8ZcQ8U+BGl2$QR!YdKSkR-8 zICu42nv_}F`efr=XX6BCvs`C0l6cKO(+zE++3<5MTLah_4yoY?SM4WI?>haf-Jfp6UclwWpY{ z`(F`X=g?Jl>BCd~2AtHsR<9mz*|XED?fbBMtWSr=oqM)C64PnXiAo_u<^%Jm#_*~F z^J?>3pFR2P_R5vlPch~5+u5&YJkEH1%&_z4hm8?;+3k7JZF~jN+m+yR4Wwh|K>rxJ!Q)D>EK<$ zi)zafFfTU29BYQzkh~TLYH7HrN*k|uH4d_n4AcNG8s zqx)BN9VP+89!Kadz!YbtSLXrEy7goZi&_Z z$F;(7fVG+nbg|Zm7uSl$Z$dSKW4NGANm!zM+4aHKlYe+4l$J3OK1lp{MzymMH_I!8k5SY@jZc^D+2X_D|i83Y21*c`D4&c-I yL< z$8t{=)q?-{;r<)^T5}eAp8wR6MSrsA7Z%%wUuP%w%-F?Guw}bv>}ErD&)SU^2*Y&D>M{J=@#;lnm`8%k4darC6WC!zIWf($0k*&l-T0+-hIc9N$QozFW@=ct5P}9onpMv-FCd^Bm5`h zjY+sepRJszx;hUT(z!}zKW9{e6Qy|Q6$8$mc_Xw zwhlf6bZZI2iBaN%5*3zg3yH;vNwTrz*f1M&*y3ZAcqKWAg#|ej-o6mJRMaVqi(IM* zYs|&sh3yM?tI65CWr1%sJuCkrvt~{C<-D6RKir&Er0(vkd8X}0M+{`;RY?L&@34}r zK66L`>Wuu;bn?BTfY@k}s~FCTPtD_*>MyqM@u@%cPf2U@UGyns{tKTX(IP(Ojg|Em zv9gITiIrI-v#@6j)@=mN$X8;Cm=zImG;hSLFx4+u^wR$!Tt=A||5LckW^;2rTxPTF z*0j78MzBnu$oV~tw4#X6BNthZ{+TRZVKW#&7&$RosOS+4!ZBxGkgZ@1?7;^nTs&Yh zP`-kMiGW;#>dEoRY^7VS{D_r#eagrMlXpEWxgwLFV^ve?j2k7Fa^J*6&M!|)oIh|) zGJ7?t)r6%oS3_rrm_!D;cvXe$2?G6&(ZZrdgbwq{X!09vv?WPWY=@y52az6`@a z^9>+dKr1S4C>6^jHIYSU_4cx09TL&NGcgQ|q!<}>)PVrXB%lhbsa72|Z1j-sV=&L| zy5I1RPv3Yra}o`-YgT>OsP1LuVvp8N88E3P=Gxh=jGD#2=g;i#9;LB%QBwz|b%V^J ze7G8p0G!jBrs)9!G>h48$gzK=53^{@TB4A9qFTepo$8h~mwMlqT5Pjae19gC`kuCN zkW}W5-3E@l@h12wOet+(sGjdsdh$>gyZca2N@lh3jT`uBbrUFvdcXO5dcS#!V}*a+ zARe!?kvhH=hYGC!oMcmd-Sc%%L?-`P`2lW#5cIMvB(ggt%qti8we*1U zy7pdZO`!yficXBIG-+G3wh+>*sOAZ6EI|@taY{2@u_a?Hvd`{uU4GiIteuO>b8hix zKc=2sT54abOEcGs5GD9gC|~bm!xH19E8s^Cxr6_ zwY%HheQPo+0f&FjyvOp$J9pfxaDP4L@?flW8P32yz<{bHeXW*rY}qDbd13<%SB8fRUs z(0K6j75e=EcI0tzIwC8&%rA6?=-mbFTBlK;KdhEpH%Ve*0ztOBddC!rwb6cxlE zn^_D~eCqyONb&Wy9|Zjy^t?pS^E}Y=WkJu6JoJp5GQfr&5RTb+e-UY+j(q`vfp7~w z3#iG1XQ5{%i-rhDC3~A8!ZDfwz-x5zXDpqb8>=!z)&HQfj5z4Ho@ye=9%dj z2nK}&2ElwOh`Ul=tfaZ$#B@xwcI+tk$$lOrV<;vTjrD^M+bI93h&05seq%et`i%$w zVf|vNq@Hf8=h^-rmp7KZFSqAgMIDPgk!9y#{*{QaA~6EbbV(<}^rrQWAsY4iez zUs%w&Ka>AzKLqTCqtjH&Nb;M8f$)`jgXh0K^!@eI^)eoLHGlq7zhlcv?Jc)FZPr>|)2Qo_F%|l*?OTzr zR2>~%LiGuTp#@XmEn1}*EN9TUR|^ncHceJVf+dtm_^8dL2N36`WF!Rc&7EC9Hx#Nv zW7&iPu?$^bbOY1}x9Pr0^q_~9BSy!Q<`WX&2o-YyYGRl?lpuSE?b~Y~tp4aQzqC`C zc4Nul%pbIB<$u2a@k!U=Uc=nW1`T*OwOi*tAOSR+s{hBbLqyBkH6(l9T!-W z3x6UYdW=6i&99sfmLuj|Zn2#CUf#ER|2yyw^+N^oIcR-lr7F@2O--mu^aU+7+N1SZ zLcOBBps~XR7=kbpGLKlVtQMzl0HVmOE`XZiGp0=@M3ps-AOfObgretQ#e$C*h@w`c z#S+nTmz?{F$#LYrAVV`GSYRm(jRu&Z)!aPZ|cU zSsq$IS-~~ydAK76)8hFu;F|G*YxdHgm%kHSvoe3j{t@2qFLjVmF(i(y@RAt>W#OVm z42BqsNn>+D&?Cjmny^FMkH%YwoKI10gM{`i%2EEdJTuQ3eEa#AkWD$ye?nsoy~PQ* zOdLOEqYN#7sjYW4mKcSR@JyD4nel?!k?Cw+fFfF-!bd9R<)Xh}h){ts-vPI*#A7-8 z2cz^#nV6mJZtX3;0=AX`i_~o-PP(CEOYI}D*cVuQ4^>%l5=}0G?xl1QSeya<P#~x9q=PW1o|R84peWF;*Xn zKG}9r>!1r7i}TbXXuRf~Khxv0{-`N4^%8c%6XntHqD)Ie=)zdB^4Qh1+SY?d*+VvK zYu&miGAn9Zv^Xd?i?!#@J!M!S{=i;TRGZBK4sQX66cMzUB7$NK2HK4CD(KX(pwTNq zq-J1(jETijB|a4lMyj5yBiLkf+*>qeXMVDqWv-zvH|~?=Z{On8*hTcXarXdU3C+KQ zUXeM-5R5@@v(Q+P%>d48@D;IdFRn%_tq;g8onY}|0y(H(MCuxthS`Y3QL$vq*l1L# zsJ9M-H#UqWl~T`ja8@+I#UT=0Lb=Mn;=49%|8VJQ=Chgku(EmRwVJi3+N=Fu z>SfL_)|pkT7k+8i!3z6W$t{d;y;%5aX;ONm zJ}Esiz#9{^sMZF)wUUwuB$PzyY{`oysdTpF=#nU%EmJZ9H`?-&NC$aPG9UM|0!{KA zC_sXejslas(ZckvgHVdJGR_$E`=|b3VN~@4i6XK;J$Q)2+&cNYOZ?YhW!Ai%L&`A6 z;UE8Uzfx$^#2smK8eQQd*+rl9^HYMKe_6fMiB)e_J%xHs&il{XIDcBd;qsbdQ>HD! zDOiCj&ikOVP|W%W@tgvhg$`*TM1!%p|K@@uCmbp%z!^00?SSM6z%)aG4qgJ2-a<-_ zsg49^*kkrk?vE5g=4xc1jL}qY`ncU=nZ~N~vUixo|9pgDpEBRapU7j~%R!v)$-Uf* z%J6TWau@&lBpc19psoPc5dU3$6%P zHa|aMuCFl^9elJhJaM`X57L8&AwbQ{KaJ<3;A^`jq|rnDd1V27Y@}tj#!N1)dOxWUQX1hx-DmVANikd)|xH8|sHeoc)K@i{deT^$q3r7%KL^ zTefKcsaQ7jc^5l`3F0WV%0O|tUX=cP?guAm94Wg^W$K2%^f!PI2M>_GON+%Wkw=sg zB;q7tX~7dZS3D2@s-v2CKRSETuG%h%=a=(Ldn56Fm*;za!LHKO=exGj;Hm$0=Bee_ z(Mckz4r9oyZ0+7yw;j z8!N9*ezxWCCH&y<6Z|BsaPJW4BCVd~>BFCy=$_LW@RvX@>q5dmYBJaiIJ^;WtE!}_ zVmh5xqL9uo5+)oC}5@l4GI;8Q6TB--)$7-eD@p5O2+4%y~1z( zzWC?Ny!k^WuXtn}9<;ya(4{$Qy(2t! zkVT4lrMbgLC`=?YELl`qp#DMxqK=m27iR<|LshL7RW^o}3a1mAYt>Ay85fVrIcn+@ zYb;()zsG+TE6;1)XM|0TD)qQboUFP&<5~QhX)BgZaew{AGer)0UR+)@t=0E!`h3>( zQl4^Nwl5n0`WsXs*eCzCeLAX-Xo}Q4Ekf@aiJzyQ6GWWC`C(KaS-7cD8GhlD>xJZf&1a9BK4rqvrgrq6z$CIsa^vSI zDMRItb{@Ul{iE4Cp3YT2`heMfVjYH@_gC_IApnBzu7kB`Q+HRP{~G+J ztWl%HDhTg6d=+L34W4w9-j0zsqH4LU#S5SnFRQ!jf)GB22O|pXCKRc-j?kbGFXY&6 zKyIgjAaT*ZZeKMAy2<-&;4@~=|J%muB@Rjl+>eV_l;tT`7H!vjGScM!pRu;p;#MD!71Yk`u$!o=YnmOf|iz4?5%|0&Lts>x3&K zOkr}n9;u4j=w9V;rr!B<^A?|Xf0a*uav|T&f-n5y{KS5@o4kDbnw|4z)c)+DGIn;0 z=||MrYqI5S{CumbduZ=k@IzuAYFV7lLLxRLVG5X_P|NliHCFIRQ&|;UW&exqgM2V$ zO&|{s>lgb506hDa2!|AOxSGk)`i`w-U#y(T@ABUjR^nWMz z$* z7#rn1e#}?Y$PqlIU3q~VF%yY^#3^i9OknHr?<)L>nvm06)mg`SxzLpsiizp zGth-82n9=ewpmTVKyjkbmqm5(e&I#?eX_AtxhX^ZODfCSG#E8qRU7?Xvb-!$zrG~< zw0hHho&U|hUL>Dae6O*R^0numb{u$M`{C~fpBcRU`J59+Xpb5qTdW86C<>72_MLu` zET+9kk}@FkmV{W_ijzOW#5G{eW|_DEBpulyD*AM5G}mz* z*64wTj`p~*&?nrJCZ$6wW|RRMfM5u!0j18}RYfVz+oQb9>5@A(>oZVM8{Q?3KITj& zUlha+ap;ZwRd&Q(x#M7Y+sgf4^gh-PyX3>>0Jh%n%pQjCItrbOBu{?|FMBYgm7$4H zgx6$!k~(5`6BPHvk8J4Zj09Qg=Bej*i!52w#>j{F@Vgu2^(<`fwFM34y}RjD&gN;e z6(#9$d=Qgo{vNWCh3{ql`&p^Y-9K(}`_p{s;2nAH_%}bx>eg-X=c8y(y5!$gZo@B9 zT56^RnX1l3M8ntyL#sFASF;rovlkG>wlq_S#rkUCctbs+@iTh%nrHcBi1g^tR1UgZ zN>;!6@HYQBKu75a{V!^G77pt z51fGrwBpE zafymTrvbIAH$VS8Z+_=gi1WkWL7bENa-6!JHOarJUH}IQqg9$__!@?VkQd%i%S%^@ zP>^MnA^&leK(DH>h5WFxnD6b_w9fz{*Gdsg{p%!O7$ls#e|8=y&l$gJb4F(JXAg-? zvBsI8(|pirIrtjl#LQRy3|dADd-vO13>6bfNy`}+Ocbt-i$SO`6&G{-M6)Y2?^6qi z70D<-xT(vTRw9P_tpMRd0#I926}`BVYQzdNAc|T*c@i9hX?P!6+)V%It$F+MmU8zN zC|k!^(FwCy0`mo7xVL7k*u@eL9^15)ts9g%v(K!fL+|9cyH?xQ|I`md4^8a;`nUn# zpB*DSF|BQIT)>tWo*22a3ZfUDnASEsb}CL1o*22aGD+AyY3gYC8{4u%(VEX z-SpL~=Jw9T8d_lu8Db5gI@tq3}XQa*kF?d zSym0h*bBJbVGlDV4 zRG~*i5ZTzqdOd5V5Sm(>*1e3S(;wE(7vL|IZ8<3)$RPl7+-(Sk1+rakqWpj}8>T5m z$rX_L(@YH|S$g{$ph{ z106`k;AKD#GX;?J=WXc3?0G(3f1X}f=7CO_)Pvn+Bjx+p!3a$$OnNWh|WO)sJHy-mSGP#}R!$$=F71>B?&jAvog5DcZ8FnK6+ZhqjA75Xbm!kz_d+O>Og-u|77*0yW6deI(ti5+tn z?cTj$?k+ZQntW!OGo^mRR_!v{vNN7L&)c`50A zd7^lLDbOM!2CDEYNC+U&fskV$I8GcTfg*UoB3rLu$|>8l0r977dnV84=eRGsvbVeY zD+LP`oj%nJ%!XZTC=*3@+nvq@|1;sun z_))4O-K?SfF?)WyV|+#V{VnRowYFz$&2Nu~_U)EtXASsi8wlf4mHA!HpZ6WzGkN9Y z74Mw?{mRFEht3-E&Wg#q!1EUk4pUw_rupfUB2mv$hH6CMf}|_XJg!vF zPF&V9JJNzQ!N3ihsUTSFD>6M0a0k|q?1k*E-dRe)7COo3H9d^QuYo;Ka2`_)XbC_X zvI|f$RW_G+HX3-qUmA}(DpCIyL&!w>3`ham8~hcBoe2>H>?Prk^7W{pM^dy6*knmi zn&NE}zr#N_NMmo_*Z7wQTy=fU$F6qqv_JYTmzN~Cw^ppEoZ7N>3opk0pg-JYcX&!~cIXrXi)R3%uXA;&C!HX-f|)OmBd z;7c>hSBP6P$w{JM6g^rZgF=WOL?&dJyajN?QQwG?2`D!+*Tw=(mI=<$a3)i<5qfYK z1@M8X>VfE-Z%;f{9V4APwdKD}D*5RA=4WilC3pDi505?X`^KYRx4>uq-Yd1lP;hzB z-ouI;sRY>{Fb98%8UpDbJ8_8B`S*P40XK0{O-L(;)KyK#tzA%_1J4uP#l!1d1rzJ; zX%(s`5)>7LbifsxjVrbp*UI8r%|n3}+si_9-UK)wS>(zh*-_5%7YMnvY(A09cHSe!-~?vK8i<@xU9u==kEIHWpMXCn9Noc+&!AQb(*?u zS*%PiZ;B2TzWZo6OHE7~J`zi=Q-HIuVB1B-H3(W`!a@I_GC>JJ;O+sY55n*?`M#-a z8N?Dm!~#&^;}#hv(UFqkVNEm~Mt4v+z|}*dlwqj*+PZF3-;$GNYseO8J^GI{BYrTMHxna|7ad2i_qsPlBT#FV7sI9)N| z>9@7QI!`Yw=oeQ=CtM9~E_Tr1Pe%F?#YJNZ0y4UK)-Xtl42X=3tQy%cvVCM~hd1GFI=GBQpE+M$KnOScu|2D!=MJ!v1WQ&d;(( zyfCXal`3JBGFw_~VZIAyZiy?qW!hYJvRsSb>dL%sGN`Q_P+l0EtT-xRLQQp;7G2oO zp`fOk99AR_q51-ZV1zAkg)`pdu?Gf%J&JOcZ^83g5s^brTpauwT_DhU0p&;WR7o9` z90lKfa+LD@l|=vZ)z^kzJ;%Pn1Z;)5$IK3O|B40;)xP7dn#w-)Y3o4;-`^kTzE(u; z@K*0O2RDeB2*_0GAY|EUt%S)VXDOpHT-RDqpwL2t5~y4-EP*E4_O`$WA&nF}C`J&^ zV5WtHT!+)nRG~y79A~SDDDj7AM`bDw859Cb9{|w{2M~u~Dg>1IKu1z?68-`cLy|)r z^hZ;`lhh9K8h&3JzT_(Y<=wzPbmPhI{uR&OjhvgVXSy!zdbTU8`)!Z2Jr?#j+ui+K z&U?}pdzgX~<1c(?82)7PomtY94Z$K9orUXp@ev}%Iu^83Gl!u?EA&t)2o)LVuLDx0 zB-QAoV$_#HDR-SIs*BA`ca5FpQkZ(pr3@?2-{AL-eSGRc1@|!d%?hqFS%+9K8&eU! z44J6TmWX|#{sK3Og`zhE-m$ zVrd4?xqbWgh2aBcM6dkZMWmwBohvkZw>s zz$sDoFKGq1CIjB21ZT1-9Ax@TERn5WUxKbn`T^4Bn^|Yz}CbY!n~HHNYRERC1<^zFTJ~Y z){J*{HL6*o@vFlcvhaQL7wp~6f7`taCS=QYuhehrex50x$y8&DsBaFdrWY!%UXiz^}f-_7uM0D9jvUdWHhi`vZAq z4jEn(&0bjKB@j&%uox#K9K^Oc=Lb{}{_p*_A%RO$oVsE9h`IyL0TD0~_M@@||gImraqIwEk>x z`34O!oSkZ=94BqZVS)N1`V=qi^vvxco)5N(E7Uq%4Gkp@+Z|`wd*gvH8KBWwqKB{Gc#$W=82Ozyh`< z@NHBCqDI6hzrn~m0znajbbwjSM;~Jeq5;z;^cemuvc15g(YFCM8P%CFsIP!1F$hDN zqD9&zGQXAIGU{iHUO02^+|fL6(d$c5`0UFUv+;b1T$0ab)7-zXBfKd)+!t$K1DUfD zQ6QQkHpnzZEY!oxEPg;QFN@I2q9RZqB7AL8-<5dO9m;uDP+_nCNDI;51gj~u;7yc? z07n?jDAj6uIQMKIxkn zTeX}iZ!dPOsLwwhHASf~h2LeR$C9nnJ^!)og6%C#_&c5dy*v-MtEJ~~H#p=N1v;4& zVBMFh)$p0l`H$^GYzL4vRYoc$ucpti9iGn|E%=NPAQzwMiO=-1?Z9WEq{8wl@fp-< ziQmx*K4YXwiO+PyXNudl;xo}wS$UcGOrqyAV+uYaBpHqh+%~e*AJLjuZI1;H?xO|i z9Z;aqMq*z)S!;%ws!4i04jv|1zX$cvYN(p!In?5;$O7dOG*mq-j+g~{pC{_MgxDd9 z-xVtuTnDi!*V;F+_^CM=i%ZoTwH!^Z;-}nPeG~DSM^oq0?7Gm!syglDt)!14D)Dwa zJqcxw+gZ#%MXs@8C%3=1-kE!5z_Qs_vjwiXN#+ zQF0?T>3be_>boyl8mp+zMb$&2Qxp;E126J5oaEx@R8(6UuQ}?}#jiOX!b--qy5~e2 zUV8Dfh9yR(Hgv?$1kDjD+MPlfES8`J>kq5}J-jz7zJP$7RfH%=CRC#Om)z{KNbwU# zJTj;lMfk!TLLMQ?gz66R`Rd-@j%nH@JNsSRrtA+^6pv}#>RdMVBY!_{E$=|Tkr1hYCVQ%%iDrcH zY{{}ih{F=OKp?}CtYh2_&L0fblGvjNVT~Y)0p%V36L{XB9fEF6DGhki zoCrno07@c^8JN3hYlJ(Iv?u09m3Y#e<40c5irBFrXbv^QXiJhquyrU#a9}ggmhC0a z4yrn*amO|rn{}8oXz=t7&DN!KZalwg)ftUDr>tw%Vg8`OvpY1~*rsFSIaQTq)oaOR z+eK!6KP<9MjNG{11w4*vBObRai^n(@E2SCA12r37Ya9rK)XaW1=oa8~4snIF^S4x* z6IxJ$Q;5hd3Ooz)j;6pQleG!Qt@6PA^Nf+boh&Mo_mczWjT&%-e>siqVFQ1uzwO+$ z^Y`oTKYtCpzn&DVELDd~X;LIO@ZyG2?e&QN?a$xr-i}vi;MMEm)v}gXe|B%j?#1A^ z-Nl)e;@#!tZ`n7z0x!?LCF%B#w3~fub3hX-hVy-pB2ZFs)q%APkf+P_)!I1!4ylGF z`3U`)!jweRLS7rbBEe(v0B@qy0tzgsghVRTr9WxYCRTsbCV4vLyRbvpqo(<3tOv7$ zccEvFh=q$VuP4T7x1XBPQaQ&uz14Qy)PX6z4`H2^VHp+2>57wD0dEeemD~ikVs^9| zhUdfJ;d)*3)jeD=4UDW^!G?^}Cm58mYD+1jCA~@5_@qpNb)mk>RDePv1a^k0bd_qO z$WW>;L+3D3QsA8ki~{6G-hZDBJGr3!s+8D8>7xf;zAUG?T*|xyt)?IBRkrxKs{Q&k zIgmF67Ai$%B()OY2!*ax%v4b(!fnR-EzwdhgQflO=BXgkW)@6EDYEPYgE3|7g3hry z;Ef@=OI@rV=d!vDP1b7xnJ3%$j@5Su#SKu)ovJ|Co7H&>Y_HdxP1A3?2ycm~d|*WV15yB5DvuFrkJl0bsB!h(srC3ywT=LNPgme4+xa_|XYR zrz5@ugkxYvC!hj~%9}!ZOl8;!UxJ!qq-k1^DO*|O@ft7+fDI&hiJf5d##fNSYxcpx z+XNzbA+UmG?O^*zD>cbm;`yQ*oi%uZGfgl;Ii%xFIG{>Q^}?}gp4f?|H65`P2j!%5 z&|m4tC~8ta*%LK6@Fen+=V^ev|H159)%Y?%*&5NL8OX(NBc0WnwQYwJqchUx*staW zU=8u0p#iceGcz8v#w)Fj2bPmx39nS5-ESRW5q1A|b;A?}Qkug}SKtxQN;RxRr?(+A zchj?Rl^Wt%t(v$&56-L_rWfmqj|l!A?2+!|`64U3VHwOdNJQc)!z4SB8opgyeh)|7`ib92YvvrQV1 zI&k=tP6zKD?Af;R_xsNML|Ff50g%4yUAf(XZvBULZdzyP;K^;9^=?(aR{aKDr*wVe z!_*!9UhCbmZlfkO%5~emLv*A#cv&)fdb}#NgxByj zsfW}Dy<7&P+uA5;f;0trEVD3gX_2&yoz()CuON&;r;a* z#I?P+b`{s2;@VGK2Z(E$xQ-OpG2%K=T&Ifbba9;{t_#F<354(~x@)W%cE1@E0&Q9o zrJ|NG8J9^jahXvY7r$n&&`QyQM>xu8_tB{j9zUV_Xro11ONMhaDv{e4GFjK{M~jak zj$QC9DTcA8hd4ClbJ2nvvW3+2DhXLNOs~EY;2fUo1Y7{Her{HS0^8j=DAzeO*9l;O ztJ+F{6Y@O?D65wnnL|F&Z4>b>P_9d+?Yl7*? zNdZovYjS{dZmu&UzzL*H3ve#Xbs*p?C=AH1t7Gdm_SG@RNq1PbH|Ig^0Q2L1gTC{)FM@xgSKYqID57 zysEg3HQiT|XAT@ZL(UvBXomdir~T7ASFe%Fm$z!vuvM$Z4O=RQdJXN^ZDj8uh8%x+`Z7$+ppmMr@bfCsnDoaw^K9aTY1B zn|3a~23$rVBwFNMn^(N?_U4r8Qr+X zc_0!RqXChj3}_X7MXpH21npu)YOq9?z7<)zIdH8hB`Oky`BxOBQP2@g{yHEnE3Ux% zBDTe0h;P80Oj*^mLyCY^a7XZ)H|4c1v*XJx@3-N=2OIk@FBdDQ%m)+Mxp| zw>Hp`t1boQ*3p=QItJ-`DG1nr+(f{Z2^*3^;Y%zZK6$WWCD+aKaS+@?m9?tv`E%u5 z4yYy-xc*jM4=+I^EUpq_4lT{{DeS?qIK0L$dE>kYo|yWHVG^FmMX_UKqMhzp0-%Vg znNkL@9JC~N=!aMkQBr^utB^}X7c({Dl%OkL1rC2_@7X_cav!s{tX58o5yeOK?LKm- zy8g_jO(QR9`)@q`sRc`B?N#@#S1MN-KW|+3p2JCpP6ISw0$-(&alL7#kc=fa229Dn$X=-gw-gn@nPm6hwt9nZQdUidKU>ftwAH5oRr_sIA# z;xARP^Y;LWA3Cdb)r$HD;CD#J@b&DAAa?^IVITn_l==zRB1+@T#;+am4!bCaW8~IB zpimbWBAX1}op^Xkq5>UC$Mx%7?jQW*3Qyc$vAV(R)0`(yHptK132Z$a{7kA3?0$-K z87IA?MGAkpPL0AGH`Zdh*PN@jdaSzTn(-8)h8R!?2jfEhzJD}7El1ucE z8q|=q8AAv4@7{5U>%pN5w+Hn5F7Ny)*Q4|v1BTq1ChzRpta;lObygn8+L$sg_LZ+U zee%iX#+|yg*a2KL#{PT@T!fS4Gxg^YjMcz}SMr%6jhYd`;vPW{|*a4ODrv-jDujiZ{sHmK*$D~I3hxPD+yv}$6~8W2>D;35tG zGZ!(|>MRh0rgh04UIJ-oBWal9;-}gviE^nyL&kHf0c#?RxHx6;5URcEOIlZct4BnU;mt+5y*;AXZNJ&g&Rh!B{9JeseKIDtqC zfI>pbEt@1y&1)x*aKEW+IeBuaQZGm3{oCNfs)=9pLDrx6MGO0}{Ji(%O3ZU6^#Cfy zo|Ixm(aWg!Lq3odlBdW)ZU-O1-jVOoj)veDTHzN8Nu6Hu3qtoW05pD~0CZv$`p;>0 z@vE3wOo39(7sWF|U<5@$W+)gmh-Jh-WF^u5dp^0h2+^6yLM@`|(pEz?T%IhVo1opRGJp&gCVO5`b?d&i(-0EEfF$d_{(@ z{^b@a<1N5eN{ST6B6=M*l&64#WBbA>)}q9FsSevT(+i8K5f@{qQ3XztFhk3teoe@+ zQRE@~qO;TA*_gpTX;9x$W0(JU{K;pFZe>1VQoqrxdgGKf{b%=jN zO>Nm*`+DyhdmPSj86FEstqoiifsbQ=W)t3IVsHK)87emBU#KIb8Y+TTR2BjiU0zM- z)F6~ev>{4oDlG+2o-AXOl`}*-JrXEdZgI`U&R+TR1}nz%c#X>=MhqQ&neF6V)ukWp zy4#b-7LteeZPy_cD{hltRULtS2!`g{Lh}(dc zlEefHA1$TzqyXZk(7nW*Ad_vcjuayO^Pxez_ZD8_mC{6|2Jb|bqEIOu;)YCC!WqpRSJNK4A7KDs;fG3zJh11yUzC!b zU$ia9FBXNR$b@dG|FA{d7tF*UHiL-?p5vuFT7_X0U}8L-70sdF_=y|Qrx}Y00xJ!| zEn1UxVC`7_hY@_s4*pKWL#*jTrSt`waCgt_Tz4W-6 zNkiBj@==+S6FKOlJBu#*ULT$EbM z-ht7+(|w`bU-NxHZ|h4>mGrHI`(^`0tdFD<^*~5ehq!c_bzyR8th$s3vIn&4&N$C4 zaGpz|yHs&ghXc!cy+@*`B6_I9;bL}U;5eIA@e=x*N+ejDV#PY_QFO=yki4!>jgCbB zuh7V3q=H7NEyC9D%TM@K7W(MhXA$>{O&-C2*}}>-d&=&v3SZ2sFyBVZmsQF>J`gi( z8h&)B_F2#LRz(gG_@S6GKuq;DB0HV&FrCP-v; zV;YmWA_5uNCSL%hM)>3+N0cyvK}|&|Q^MjF2rEMl0G!mQP@|eHUR1KhK`HgZ#=@RM?gciv7D|C%<=fZQr)5O=UCKEp1G8cA-_%9IJ+Y@yDf4`wh#S z4EZIrSLH2GOgMV~NhS-^VoZ3MuT)rA!#<*`s>o`|&47SFD>!dvBlHMw*)BnZ$0!tr zK7?#o$VKG0z&#);4X8c`{)`YfHIV-dOD8EFj(+gDug>Q4XUBNHA1sr{5BVcjSmjSn z^Jk37%UHhqqg7#5SAPHf%KE;mS0r$oL{CWRF~bDGStW!gp?VD}d`jN5c?oB}z?yzLtIR_t0WN zKe3zOIOkfob&tk@_399mi54kM)*QNj%t4|6<{=Wgba*UQzc4IFa47x+vDk(Ksmd4y zy;Q0y4RNDM3L9&Nl_EFh^a@y>riqAziKHmoe^Wh_TD%9_#*$yEfUs-X6aJeDVz!iO zX%15tgO}p6fPE2=4iT!*kqHXHOmRP+4`d?8C7=IPEJ$4ntL(MbZGlblnRLM(QYK9y zsh_5bdTwkxg+FjLJk=JCZb%@rz|b6iB5VLxowS564cV2 zDbH$2_p;$uWPUk1XIA@TRSpT>5s}@a@2N#78lq3YZYZ#1WtseJUNIJ>_J8Dl?o#e~ zXcpZ|0Qs-@jlxn}O)5ghgZ>*9?ZY?+7T2n70^_Wjvnm0?5{qT@GIkytjvy-WKZ!ghf;m+|ozaioppGQNp#jhn_`}g~2%u zZBO$L5IyVtDO{!b`UsaKrm)yWE|AGPO4MvJjPR|L6;p!DU1}nx3JD;({(-5;wm{W} zez1WtO3Oc4Fu!x(^(PGke&BLHRarPDS4XUv#fqsR{(qm(eda%Mg#Xjr&;Kbh$^8*` zhsYH|p3j}>=l%u`5hkEh03EUmEF4qh4jIsRIc8{KQL&G~RG_|MqWlA4Hl)Xx(*Q-Q zZ-msKnxOXt>3ngrBCK^JK`7DFN4eOLY0q3YpUbW>(_HMw@RQqF0{{Hxs{N(-Z!9bn z<0vEy&-il3@o;%Rtq}>j>Kw?bXiTzkn5y@L+tgU25uFj#W{7FRs#%u-2gkzU_cZs@ z3KTIC>Z^!eL3)XTJ_(j0wbWIgf`Srd?o%?Kym!)w)k_zxo-m$Qbsm}haO3Z+!hr4v zdBWMU=bRNc@7eiYxvVqMXLB~N_|TR2=J1>MBbHukB|HW(s9@;`Tt}c|Y3PexgA6!~ zdPxC?x0m9}n)7HrvM{NUjtS?le?gW7QND?mbXEwlB&007xk)0E0$z3`=V$V5%3i)@ z(b6k_{&{!Ygz>M>oa=&vBj=C!OQ%0Qex&oz^t3qlZQ2F04PV7BltP8PVu};I)F#yY z3yH!St7)i(=+A~EX!#+e?uJ0|Z9w-f;&Nbg$n+5MYKI&PA;p(oT#k!{%R|*NM;b~g zl;#Ks(Y;65n6y`FSTv=MD-gvZq>!vO4&?uQe~;hGytnZirUttTPfLFu%4YBxewni; zWfWm^j$LMzSfM66^A}w?Ic6xon6vur{)nrItV%}+_ACstY>KApvJ8CJn5%6$Ck8hX zduP}}I45S8C{j-&z zk%#d2iWcg&XJri*m)fpyh*J07m1pjTf2F-XVKAG%`zu*F$2a~z^4>eJs$%OK-m_0j zLP9DDJrE!P1OtQ+Kzf%J1f^q;rUaE{C<;;(P^2iu0z&92H5?HY3kcW{1RGeeT*Y2c zj)FkWKHqPx*)wOKfcHN4eV^~2@4F@B?6b1=%$hZ8R-dz0sOXsKEB@8I#=8APthHoZ zzZ*u{o*!RD%rqHN?yz4-DF^LF-BKK(8Acp(5oK`N4P+#++H1hzG4>l|@EEkv^aH<5 z@)yvL5Pd`&Ojtd*oRF*@<1AqJq{CH*KPe^{cN~ZCDb+I~eUfw^rvyc~sSMXc=zvBX z!2t2dSb}{o=_SUBVBp-M_s56cx6&;a?ET-FPUc#1*1El5+k{;wq;U{@+9nbE5qbYs zpxa9vS=zkpYX9;zNaSI1`ozdWaGtt23!+kZgG5D?=SOT+y9V01P3JH9;%9f@uDk3_ z`fKL#cdW<7;2C4>JvzlIcHe?EEQcEqROc7E!Vac+#L;|JZGpkmq3zTPN~ln=CM%Yp zD4CnLSPKL2h?<^&RV?tr(q^tBHV?V$^7~Vut3=5@y*MLd?K3jsz3PlCfezx(VR5}0 zADNVE9@(}RM0EI>h*lL4GfeQ-!s4Q_G{WfUknZvapD#WB=ii@L>8@7R)3;5YFy_4L zov&Pnt*4LDKu6w~KMXzjX|!3^E)VVPc*F*V`IC7?DaV@|JrTRq5i z=X`jw4p0OI%P3-`d2LMIu%w$O)=CB~Yx>N&-8b?$8bM z_uMO9D{U71MciQRGE-dMQfnvVZ)If8rem}fjAFlVa9@OfGa{@QL2VT$;8l(gRH_4< zKi0+PNi3p|vDlUcvDkda@!OtVvHN4ODVN3;$C{Ji3U+E+$g}ZB#j_VHS;*WI_UYE* zPzVaZ@Lw4l`Kur>ywv(Y3`N0b^$Rx!ZoD9>TL;C>c=VBV4gDY8$XZx6#8>qH;ECWy z%(?@7K;Prk$ubuEGaZ?)5p&Z?o!}&gMT#VNYBTH4*Ngw>!vnz9dCIn1~ z9>iyoIKmI7zuliuE0g}XYAQQLB8yGHdopK3rPd%$3Nb_dz>%MrlgdJdOxtGW*AvDK z850N``uNW~hmF6}vQ7`%)pkap+>xnweYIlMo34&s^1HNJ@$6HN4q2F0`;j5V&o#^* zQoMXXw=J#`w`~o&@5HJ{lYYiI{Zb2#@H$4Q#L8%oSZKf7#qQ2%kF5kFJvR~Sl#}SX zClCn!7C^KQHb9eRml+up7Ih;d5Nd+ z+n!zC{a)fJZ?V^$SGfxt-7TvW3r;kvr_h+SZH5~I8x+)0$G zjS-WjltA9}MAB2QLMd&AkVsVNFLbUr*al7=XV?jAP1}}^UY~vRx^D_to8n^!Y+ck+ zWR2(^i{KK7_qJ91tA%^ij=9UN`_8?y@Y5eI=mN;2QwV;=+~4yJrw+7SoApNB|Zsgr;s$Q*N{ zdt}^>dt@TKX%QxqS{i?xtTT;^FjU!4q(p=)yjjNma@?tb`E!2yT?EEYpF1xgwr0Nn z9@_J*oqBsFN+%@`d&~2@JNSL}ylLGd&TIABi1Qh)9av~=Uc+F8Xy@~f&ptZ;yyY+5 z77zsiF&x{5&OUkmF{QnfOA~K&@RzgK8|N6kG=kFlly#hYRBjy29uk}+)W6S3Xnt!v zh<)i%`C=!%)#)1pOSKB#9*Z*qr>{KE*iMx@Az}#n2q+V=kMXfyLW#d+%(@7#CU%8X zNs+(`9ZMg-o+_+|ZZP}){MkjT$(W*vBQDyy=V9oZ)~a#+@<*CTYe!uUWQ^w-j5pJa zqPiTok(zK_4#^&+MdbTkQj5TnC@msFl~JTbW+zuJ!@uEhzLwDudDKuBq+X~8?XF8& zAghCV$h(k3Mv9>Ip&BtbsugUYMr;EujIeF>A00y+-Bo`0tgn+yp@DUQE9(!^#r+dT6t6fe8jqcD@KfuD-;16JJ@Dy1=tomR zzvCv6HLwV38h*c9_6)$LQ1wv}+xMzwAalMJX>n0xtUfTeN8ak$j60KfZ>)6=&2u_rw)8_@J%QUpE9+zJeSbu>={UD)}jF3q8?I%Pw+ z-uCeQePMl_{PMYTFQ_!%O!(SDwt`jhM-g8(3TYze-*6|{J8r1oD|Z|OhU!2N zvE$Tn<4=s{^ti+Cbq3%a^L;;&JLV?T?oIgoAcr8~lVX z-(7plxX(Yw{Yo+Y-`n^iLW3_`om?5+2Z`Iu8E%b2*1Cld07II3edq`=Ay`7k2K6Nti;fJo8!S_#!@2tw=yR9O4*upg) z&|s}y-a9agO6Z9eW&1yD=@_BJs-uUwM^TMGXyY=CTSZZWnYL-9R-_Tb;I}=y()Op3 zT9HwS!b3k@qd>XF^TGF7x82%u5_A1iMsDA+nPKrpRKI?w% zw^vVW3tmN|HHTTFgTEqTdlj9Q&LnG>dj@EbU@Y`QBjc4I%N8dD>rBdwjL;AwXrL5% zq$F|%X&h)kTSadgwY%hIa-QEPvgCA4_+TA0z&sH<#SD2NS>ZC5i<)npSZy6tN|)K! znxJMS)h?O~xZlEDQjl-#aoiKdCa{`Fgs|piRyrc98{`f*61kHtIt8>PcR&Fd{p2UG z9S3`s8pQ_e4tN@&s3kb^W@2G_aIX?fLEdJ}s-nI-Sd8t8>x`Qt8EcZ*X}xD1Y_qW| zEd3o{d;zubaB!FS=$&^+jl^7_J$icMxAMjUf3zdk9I=BV6eP7>c2ddFcuKFueVi5KeVoW=uWj4kTo~olXJcQC--qWQk6M#Z;!()YYk7<} z`=f2`()R8|Sbz~u0JX3YP74TfM{t~67v)ssmKwC$nkO_0ikBzmcnS}vd{NrT+T_|` zZ8yE=Sl1^nap@)U`-HXqH29s|j+&MTk;YcKqN7r~{RuMqnvm@j*0k3XD99?+es$R< zY5r-sITffGAe8@}{Wl&xZU%1bzp?v3sQ;-kN8gHjZ@(zCipPzO4V;Uv2s1!RsUDzO zSxY2hStDGSdL`WnoB@vV7Ds#ond@|+B?8uvndAk48+}S({_J1R28zfr2l3cH^W=Nh zT5${c<-Q_MQ%vZ0-1xl_b>_8jYepQ$FiPMvs%G!Yh!xYjuZFyo6dgPrxdg&jJ zAnuY@dLT*U&!3##{<_!K&t4a0_FM@f{8aAqmxfJ=U3TVP>s#x>O6$ZmN&9LxaQ(J< zQR@7aEO&l)&%ylu?cH)}>BIWq|M}f=X^6&nYdP<&36W(%}Qy3Sm5@lngN zes;C>J-cQ8l!oowz5V!{wK2gxE8H8c(--eveenTNRYa|PbX9}IeHqu3CT(0ob0Lq@ zFRmZJFO`hj{Yn26rO`V-GBBg=m8&E#l0(xBT+bG-Zx~TuL&ldUE(F{YM^B#o$4qR%)z*QO{SQ5T;KlXV_Zi%;YSMH!3J9$E>Th>;rNB_kIWF9f2o`qQW2Gi z3C^aO{+hKp=OnhK7)EQ3uFaG&0+MidXY>up$-OcqMo=q`xh`>!H909$=EXEkdUU;O z?GpltF^5kDZtRD|7<1pU4ynsK=N>v#{`TeNyD!Un_qP*!2j6<{bdu0r;72WSuSJgR zCV!0Mo}~z(tOZ|&?0}kq?tdA$QZ^x@Mh4wx6aD}uSqyJ0?7j#yzf8YL#Dj=G z!kOgft-k^%@E`H>d*^?B%Q{bKSbyI#x#;GLPdxF&-d@j}EkCgK9P{)N?ptr_KbrPR z9_mz|L7i%CW3IotqpJj4pQ=7pb$vmHQ?jXMpk%k=o<7EK1Tpu{MytYghHDr|wA&lr zG{}Kx7Zncf+K#75wK*||dcQlK>icPA@i+8k6>GSnBn$1JV{f>>S(`@f_idiLbmM}R zyO%E5wy$%mwyoz674P3t3le4IjOk;i=G0qKc<-!- zz!E@BQK^p361ngQ$wMk@EfbQ z=Uggioex^?#26~0`Y_JXE0?V+H4tU?L$Epvjp3+J)rS?s0N z%AAaO)#^i=(7q8(#V^+Olr~-OTeNY}oE_$io=HU=J9NxN&E2DquBbBq?rBflKeF%4 z=AG(-hP^QU7hM_fkyS@_N{ZYW$lOuBN>=97Jk&Wvs+(i?I~s1Lgy&HLMt8K7giI`3 z1d4)M(&VVz8NpAp$s-TObsbl<;OY6xxBdRbqYXR6&&q`p=!t?6otNA_^@*oeH-7&I zYe4O^+K+T;hD+!L^Xw*-_Gz4nyA#8srcL0S6KuIiHlZkqEVd>s*;fncK3PrF z>5!5tzV9&j-UVCle`tew`m5xn(?|BM)uCxl`&Ob^i-j|%ZQAnKb*DZN%lmF`+PPc% z-YxPv5vM$CE^sw;b{8zGxw;w#N1AKQ1zSl2ebn8}+<-=ibh=hSh8YFZ(e@dAIepQ( zRY-{mJqeC4*fH7d;^RS_Y@;n2s1z9E4c{%{7n0 zL3XbL@$z?nt(<#j@1D1h&A(yX$fk8_H)>S7PE+s7gJ1L>HM&>#kt2H4Y23I@R!$CP z1uek!98R@z#toAHBMx&d{mOZ{mZ40^4U$hBd5k!roQ^h9VAvhX2DGcdiZOeZzUFEb zd|sRve_KaTWpUU#N3@Euy1T2OKVm)X#*W51e^jT=#J7mrG~(>SmiA7`gldtgn)tBN zMwcCBQp@&|x=70oH$+F^hXU8gXZFXZ+R2BzbHn>E1QnSAijk)@YbePaE!w@K09QKfI*)I&@RHmcqDfl2eXFSmYbclV%yQ;S|Ga;>{* zZ0e|I3X*DNcXx?ZO9pNkv3mOEK~1_%y`k~ig47L1QZ9d++^tcEUN^TJ7j2r)_84<( z@1*Wy#`L27*B?Dg3qaunWUfu{SK-Vxs@9LF3Rje639UY82}s^qy)%tyN=NdS<9~QF zh6zNWi8Dt|o^|*WQRB~ex}5mbq2Sl(jeBw3_HA3TH^2Bg&1p51*mEB0^<5n@rJ_7_ zDkhY;ZEj%|O!fLxt`_!EsWeGHuGJ+jNsFkOurJ~ylP)rs8X6@UX39&5Q(&^lYi#S( zqtoK*w!ndBTR_S%_dnO>IBjw>au-(2f`v37XOGVzY@NUmTWo<^95u7KrDrv}cFQGJM53}t@nI-_iVI+6;UUhS)=5ttpfmzF++ z#*59YShEIh%b5^-7_AMTG)D!y2BR^eIiPGV?p}++$E#jTQ0mPZx`&D82r~%JLeePl~lxV(>XdpCr&n-^CWO zuzX-D`b4a9*tO29jGMOD>Wnt*quV)%$4X1RW+l-)xY?X#y=ATnjsZbtnR9}P!*$Y!a@A&861Gr|+99x_Yg*-HR7qE^fWidI)*x7sb$yVt5p2qHUI&$MSaoKwFruJ(+Tg`5r^SgkL zsJ5M|BYoiIu8!TUSSLcnFk_Q8de!nWe+(C$!Bt+!f!PG~G0C9dx%6Ikvd)*b2N}8XYCNP!$CB zWK?*V78aVNZByOD$c{+K-rF`MKcyfA)SZuj@@hrACPUU0||o`DC+oJvcLR$40Fk2#nil!?n{WojMfS_unLF+4le!};Li z@TL2*eeeaKR4@i0F-+PVPpvFs95iNFvtHEtu(r#9qQ@+ z)HT$5pJOy`AaLUy>i$=Z0`3%{2pz2m4JW4QVqXIwP?U!f0U!RzfPr_Zv1`x@)GVVzoA72ldEn@4HU!lJ7ye_b}SZ#?t?Kv>urO zMO11R-8LparXXf~4Az|Y5H?L5C8V^C%a1FF8y|;F1HTl~eiO3EQb`HV2G4h=IX=SX zt4yvPq6;-eS=yzzNdDTdV>eGsy{2Uas&7GOP2ilWt)Ny4XRXZH@tnr zs*opSy*!5dIen-Tbp2BemQJO>R&$su7zHJ>L8&u01yCwzUh6q*dAL}R*ZPD1I~gOX z@lP@aF5W~iW8#%EhIXn$#*E(k%xq7I5;5-{kSqI+}QiMb@qIrJTBg=N}=+miluP>vz zwO!_0Tim;o@RW?e<*iLyw9KhA#Z0T*Yyd4eurLwdC{{E zxH6pYWc`S6rP%LmhIdL_wVb$^a}+K;eiL~T7=I=CK6c*_E?D0iB5Bkgbr38-1!FTQb&BQN%_Vq1DNnlrjQ$m@}~thlQgM2n*&l5GydL zSqJC8aS4!#Bme(_rC$E_c@et3D* z>U8UKGyUa)Nq*7oy~dx2{Jp<_gG(2`{W0ek>&r&9MU?~C)nsd>u`N-7dV9!RH5?DB zvx{OLruu)SMJGXvHr>b@Mb9ai|7NY#;?=iAd%vs1I&k#x&eMPY@u{a|w{_^P=0~ml zewX{qhJN3%%|O#Pw#l<%Q1WJ-1KpbdFWlMWZyo~ z`|ZZ>h+YStw_bcB>5Ry*KKr50@;~N_=uhRyT^<^F3ZnYxJR_s}IA7^D6zwulBWLa> zK882Xq4$%+rAAl}Cc$Icoo8%zsNpU<_*~DV#~wVp+4`tsn`f<0x0+9hy5csG^|ZhQ zwtg|@x$!$cG2b|1y)xp!iofEX7roxO_JrvB((~4?chU0|ta7&6W9V2@13HE<9>YY= zx)oZ5~*ijI)NM<#=)>26Ru zTwLzbV(j2s?+HvlHSfqz1MakTo7WeMeQig!>o$1W@X0S1KL6z4V%+9V6HEV)f(YT{tTTnnJk8;etCVKj-Pp(#kgm%{XGT^Y zpDjosL5zQGaGz_cwPxFA4_oI--h8*knjM=CZ+*TSV*E?3*_AJpYz*9g>)wGcEPHg> zJ=in3)?s8TE#k;cKgn!-MyPeWswLx`0a*g9r=iOs8+ZnVED*w>2~h$N-ItrFyBvPB zckj92K(D#wQgD>mns)Gz^}4ujh3jHzGjn!*&~J>j4n4gV;Y=RxuVnWbLAz+$1j?** zGLGLTxY7tt5~pnR__+Ha5?LIA9)TNn=vS>o<%D+N#)Y1}NuVP6AvF~d3Ry7NRWG=z z;pq9tf1UT&<}=TAzyFn`+m=l0H>Qdxa;3d*ZEa$j)`c^V2j&*}M?Sk^!G_%HF#3+5 zW&-blOx6`?*nIravOD-4EePy&Bzq5SO%j5817@3G6W1}f_tL8#TrkSo(+Tr}_p}iU zd4@aewH0)Qg%<754Y3@EpM&M_i`1Stgx)Sr-YD8OIX}4|8Kx6-r_>WLhPbtc!&ZV& zspj}tnS>B4F}Q5Z)?t#bqHvlQN~|wRcJ=Jit^30TU7OFTpI-mATRLYy(4cw)Ps!+e z?iroivQ>_V?=h}xlR8y;-QKkcj(=ecwN{CI<2m>iaMuu$SEVPP4H3K({w6KsBk@tLlxXf$Mcgpi+T*^_y$<#DwT=G%bQuRjcNB^b;)YLRHC7{N z=i;tUr_Zob3Wd*SAZ}7IB7hEA6Va>81O0~G%(74&ZFl%W%)HcOXVmA%$6u*5Y3q9z z?)h}VA0p)uE8t&yfA-AxO8P!9>y8BrAAIZ8!6NC~Cw`rcG}-g-erx&tt@dV%AE#~K zyl3~ag(bM7sKn|amKevNdE?G_JBQrf$#5?ML~pl-P!fhA z8elKaWr$uE45epl*{JmAF*u)UyVn9wkH0k@bvQAek-*c4@#NRg5K1U8L@weA1KsO@ zV>D7pofjH@5~;x;bL7fP?b4Y)Eq zhk*+X$&?PRuM)3ev{+fpvHt$uzTjPw3>K=dgOq-7QV8fzsD2Kf_8k#9Z7a z<2BIk3g2J0hVti3`i!TW-jBfwMLdx=iaU6}3)8Y7j2c za2TZinDh!@c39l7C3Z)J&rZzAx#7V~;X^YSF%(L|k=k8T-neVDds&aNZPuvh7J zyLs5Fbf*I}WX?t)caF+(iI7z)%Z03br|f~g@5qLOJftcV+$_kAv667%SPgYMK%RS^ z^-W-HV6I3%SA1^Hxz*PBCsxg$_n2w6v3|4;FA=eCid4~Ni4}P2g*V^Y*WkHhukQiP zTViE@f*v2Ku_-l^Hv`cZD#*V%x?Dd6Km5~d5bWeC@zlF?%Khsh%zp;>s|#Wu@tFS@ zf3loE{OlyF;H}fLO1b+r3FsT`FGWc+R?;6M4V^2kwg}nF{c7RsK}-bNTT)_{OsJ(b zc6SN9dEk!3_XA`7M}H4IbkC|zU7xsnp_%xnb$rR)UL*Ma4C|zIDQe40^Q^oDFVnfy z2je#o>8pm0F=-Bal0$cD&`J-F5VbCD%;Hax%~~SsiokLZusJBZ%%JNBC9|=0$qQ+A z7<{+)jQj2*cYSA_yZc{{ANtdK#y4%~^m+4kj?EuaGD=)yRa$#_!I?b;Q=au#*-^r0 z;xD*&%7DdF6?B$;+34n4ir(2d=WOSwA?x%PqO%UGc-`ba^Oxg)u3`^GSjWjcZuDPC ztd#{(j4&-n&GYCk9&i4HV{^9`20lo<{iS=~xht^vo)ulXEStI5%q$Krnrha&WE4HP zD7adzIXFk0n)w=?YWY@wcN!>N1%0jO`_tt;koKuYgNztHhpE(DSg29xn!r?h6TjC@ z$vLD&J4|PPLK3I!q{=TVMjU%3u=r{_O%Z#BdB_o`4QH!`xjb3tT<&u&=K^U2kzQx}!4DLybq zd~(lgn0rrf*-e;xJS1>uzniTaj7Cd|h`IB0u^pZBqMOrNI2RC(?!Eg<_8JP1K zGQ2(K{`}~7qQo&v1n{XuRDDBx#HK~p#5tN zcX#4QcNIjsE6MxJD$y}4r84u8S_l?q>H{y4S`}qu`@L~o)?beQVdrL;;4}$`?hZL8 zwQ-6prqNcm?^dL1RGYawjel#-?%M;Ol)ru7YiDErcx1-1PMw!eTW%(<4KBRPGCZG7 zoM-*~OIGp0X;#`a)}r$wv=?yCtG+NZE;m83`A1 z!)1`=$>r>#Vh}PZ57k zeuH*OKX6Mq%!4BJv;0v~|Ami0ohcC!Wu@}^t3wn_-U?~VNI1{?IGq5>Hr{ejTtYFSqEvC36dRzWUR-Ig=mj*lER- z*=A-?TmwmvaL%%>ty$9c(G?j}ME3copPwh*oAn&Dp&?jczvnre#1)>UT%KW}vu?Ug zq#C4R6I2g0$Z1MatpUfe@KbdpW~Nl8x>|Dt6qw-1ZGx(jA&EkYX)-DRD-dh+5MK?Mca)2p!NH z!}2DU|A9oo-ODh=e7UIhNz60vxI`UlXU+^KSccFaP*SOn zSv+jgg?>*mR}`Ydp^9!__3cb^r4ZnvdwTs0-0WG=sT`1`b84!I42JMUWC>M7wt+uM z%>j+{Dxjers=e@Ua!uSq;CbBY9BWoC4aQh=@3TsAZ|~IL`Euf5X*-dcA}s6R0l01v zIeyLh^CFrQV}DVk=Y7nL>iQ9nmY!RL6P4$dSxE7dPDC-KX^fkZ;^l9+vDD#ABdge9 zNn^|4ZYt?NL;Ym3-6tt)N?_%w;Q3Qe1_Dovn>=MC+HarOy7P$m#+78PD7dLF@`$P8 z44IQ@ygZ=|)-(tDkClv?GJQ(KJYwjzrW< z#8Z`oQC6~mujja+yZT81pngp+u{YQ2l)nC zxGJkY+?Sj94^o7ws~L@6LC0XtCc-*3LooH-zr!YqhwPo_Pmno&@RfOO&QrlG-tbD| z;tB_LYP(RW;zBV~TQnH;kEb8$^rM)b#kAK8o5unthP zsUp6K8%HhqW0Ij4ff4DdC;aAr=_RrAHF3?R&DQbP+kU(8osZrB?bhL= z*B`gu*lI4a+5~^^^6Mq5@Ba^GC_*1%4O3wiRWzm`dz+3w12=5(ie0JfF@s?T>2${I z3bb1EqhdUJ5-K7AFT8H3WTvE7lI5{sJpoHe`7lVFOqN>*SIsA5??@w5?V%iV;`dYc ziou@1EjKUg7C3Y$@V)y@E4a`q3br=)O&B(}^s@WStxK0;?=-|5N|+COJKUSfHdlKe zCk@99AdnqHg!xwzPb^Cw1xHU-nBVrcW{%>T+#J`7$1i{Ifz`%+pVjiXE2;E1SJGBd z_vlgUV|eO*2>oKt^R$O`S>!hyUB4r4MP+XnkrAn|aNU-<0TpAx^RyGl50!C(5-41b zyFW?#AUNZsCEy|Mt7c=cxaJU-=OKhZ(Q~@OyGA0*BbtENv48)^A2)7W|C)ZitRLQg z-|zRdw=VA4ywwWWcc6;Yt(*4U`&;qpfM($ z=C-bSb}KaeMlnzn;*=+x38&dPsG)XCC{(OxiJL`LJRf7Va{uf(jOSU9fj(opcsq0% z&sTs4d-_`Ac|A!p;|I}N(TqZyp-C$Hu-9f`6t1y2!{4L$k?2&|V20 zdI!*V`)K46_u5ci7+T|wvZ40_dY+F)E};uUBf=xs(B)2Z5{0C>C(TFP(S%3787t4+ zfzV(Dd%R=N{k1yta*mvxXc^`=K3r+MHU0s*NPH58W&?ttYeqm5FH78OjZeeS8h5P- zXd11A-fW!4Xl<{v#+?xXO_g6e!LLGmxc0TNv zlRVzmJYL!XTE^(4h;sH=2BSLsvey9i&T@9f4(vXgc5K0tp?l3gKoOTZ)dmqT z!p7(|*7mv*-?dIy&v^~IIbU4y?uHStM>TBWG`hE#&r?0l#-~eKN-D^C-K^)e(fHbE zdIfy;>5@Dr{0s?CQpxxs^gXDVZ?$s$ zdS2Jig`wVnwpUO?hh@-oSc!i#Z}jC+Z@!6o)KmPqs!i2=?9A4@2K@j*Yk-tuH8ZVa z{S$PNxJj-7PN!-S7-qxQSc^oed^<8})d(4eF%pc|DD0pyvYtzPmv)*X``Br$?Rd{% ztWr0cV7w|?s@ZF8L+M7mzdbtvO>)a?Oz7seIEH9n;YNPOSf z_GP7WTOVqy1>5L-U*lw9i5{N~1;(v~#1bI9Tm;(BX`r=)bei7o=BG1%(s zx(vT(Lv*3o>Q8IYl3$;IgRqR4rLosT0bf03Br`dc4O1Q8ROb({EwgdgrS!VyQ) zrR8v)z_Endt}myBVHjw)1cRFul!TFZdTKmtjn{z38BKR;SP~=c zb;5|fj+_G`O?Pgz(JA4wF6Z~a|*J@gsvoNZ5E6^(g=xKnhwVx%edI3#9T55i3AkriGKjhjy) z*zhZ?zV4ooRaK1p{fUm+t_T^$t9aGjtfZH}vJ^*^vz=9ml;h)YCYPXy0#{VTI5scp zaU&z-R7hNAPv+Uh#jfvzTg{iohqvE?;BwdQU{ABZxzK8NMDMow1)h?l7Lqa%kFxII zcvLOp8siy%VuOYxvyi)8+m=~;r-q8vD0$0bSvd^+W+J;g5v+BHVSn99oUvIqdrx}Z z?7E0m?XP>hF8Ty5t&3PyLEZ86=xp5({@GnE?3W=YLd~#n^4F4B&>SfuxLXGoi9`x- z$O;*YPfC=btUPWkgt}VSrRyh#DbnY-b=fO}TCK~inflaN>-AChB#PrvlU^vy(F7XP zH%=s_ZtyF%^d zLP)#ceI%u*MKrWPoZDJTvG?9-+4V(iEtc{105qgjJH0Ekewk&zTVigkF|RlNxC&-9 z4#w=E{U$N5pL`|ex)GR3{>d?K5SzmCPmfuRLt>`=Mwn^8Wrp{g9<{Pl3WEXoZpn`U z+~@+lPkdu70^Q}zpHW!Mrr5Rjl0<_>ThAUBBn-NJv;j;5o0eaP*M_w)qNVaju!iir z8PKr8nDS|27-2-|j%{m(p2a44*p~wsY58vswGeHTWYJy)pL~C)7|=63X8}!?g3s6- zsuQ|I7}43lmTRG71jABQVw@0a5|*mkmtflyp%(#to98KwaYCp%ZnCw{C9U-<=q~|1 z+D8&r;$9yr49{QVR-=6f&^LI#)VSA&`d`KVu%V4KYoI9hlt|n-B{u!$#i|%qU-7W# zBRuVe)xy(L7ZdEXT3Is4BEP*5gpR=*G}5-b_eX9yRRmYfUJ+z%mm$GH~NL z;r1E5&2s#_A$H6*AKCxc%5_7wyVgwEn@_83OMA+6Gsp2Pk?BUO9I6}oLQ#+<8i_Zx zUsqV2JQaDC**5pBu|DUqWV@TOz5x?}xw4`47M|0YmdV}%H1`1ZBBNe-EZWCt+i=E0 zP<({%5sbW#4P9A0qQ=79M0M1*eTb9CixD| z7urmAwAW=r;60(??x3O-CpIctu}6rbVA@G`Azu90(%g2u_cAJmX$6hap!8>Tf|7B5vDZZV9wRXlFA_$a?WkRK!jhcQn638ig?vf^Gxpzf0hx<+>R~l^9bviv2S4u= zx`5~1aTA;a9=qj1YZ<`@&pP4pypi<)!7~NIBQG|#XbLD#rKCW3yv5i;a{kKS*)Uj2 z@h{8>H0RZuYOMtJsNh9&lBYeMLmlGPdy7ZY(CXxb$E+SgqjJDo?aj?$cw@S8TAl>p zvJzfx;0Fg48;^(StM|IHP@=G6S*V}ZZxzQpq|r$aaRZE|1!LKaxPq&c{TWH(8C6S}+As`Cs8pW;h7 zQj!P~-+JRrc)psS)Y~Oyk_d#EB*I)!+vX_klTy$UH$|T$?v0|0j6PwksX9i*IK8AZ zNt_#vGw=%|Mg^}~7)s(I=^}A$;n;>PT{J}z>7lDqu>!#AzScw1MPl7ze2kGwtbpRQ zcmaLjLH8@r6Vj3OQq^%sEvJpr5|LkpuO(Bi6z-#25ltK1-0f|5w8OAMUs6YA2?c$* z(PSbD#>&_hHH=(j93ggzu%-KzdH1%?SH7WUA;bEtbj8D>HoQPh9zWB%-k?0`8@j2p zi2d1hthC9pRidfu4cL)W;T^hwjQVus##eTXUOUHV^qdl-Mjw$V&*wM!x;&0KAjKA~ zM&a^6nv5gA7cL@BI;dG@BGS)8bAj6n|G2&m8%E1K<6bX$F0gHPn}9Zh7Tq%9-ggg~ zuLQfiJIfV)`3V zFJk%MhDTC_)}eYN+Ky0K48)%60G|Xm+t5|Qv()=cK}*~z7>mTcK@^I%5xbIDS?zen z&AuavdxN09C1v-pf|j^RYD?V3#%hck@&;+-%2O*xOLQZQIQ^hpL_mbjLnIIIbpQnX z?O3%U^Ci(iy;Dn7<@fFe?frgUIjS-7me>%c&lT6QVZ;4youaln**2{luM?#t1NVp7!!t8^-4P0 zFQL`ALto&{&3d+frYTG@S1sG0xEN z8;w$E;bq~mE9veHO^GKYJZChht?hO-{P&*EMh zwfKhk8CefS;c>9-Oyf}TM(ihZh=%qWMag;`Y)=xbiZ?z3*nwV**~Yv!ME!ehPSTiF zyb=1OIg&RG+t$+l!Y!5cL5q0p{XlRyo8}S5k{;-k)Dypr@X`xmPROHH&5m90h{t`F$B+9 zj<3*I7oM}mSNn8HL&=f1Vm{S*KBw&YJQto1pDQ#UrRkN0E`rZYkCx9Yf>yFzLetC$ zH)eK|hSiwW`Npt3ZaI!ZMBnsUY3OjQ(1W#V#^e5g$6X{EhDX9DEsaFwILLjCXt}-f zCyb!}wybUGT^%WZ+%_!foU6i^H8k%cc%P%;Tc-|O6bGDql{jETCbROS^Nat7aXHSy9a(z08AMs9Yn4xBI~iNFsX ziLNAx_~aUi*-MUfa&<@Ag$#pr9i`V*b6D6%0DPWOjciiaqM@0ep*>82u1uX+uNre9)+Al|e-Lx2l1j1Dk}6273L1R$Ttu|I8k7xTeQ+TcM zXZU?uSSiot6brQB_x;PJS(5dHz5cAxiLdyLMKPLYT0>JF<0+PKK|*4NfMvQTSgRBc z_rvlz#cst)*Fxo$RIA5Y6LFgZ19sk|U>Au2=QZgW^1Ln*^TKn{XNH>j6s-TPJPttf zIHu|Kzm+K>u@uAiuVh*v4w_I?Fo^u&m7@ z;(+xki=%iDkHq1TtQ`!6EeW1O9rl#7g~4-R3&SYxs^6|xNXhitR#ztuc;H$X6z7rJ z2tTHfGIL%G;>=8C)UXVDq7+*+U02FKvZf_=xTdle1OtTo@jPzIG>PxA}uop(1 zEP5x?F~d$h_>lO_QT`d+Vas|2+D z9`B=_R!!PR*6$P}=I4kJV}I?m>htpe-c#)D2rP(M^7DqMvk8TsLY{ULZ+in#m=yW^ zUks0*o|gQ)^(grqULU~w@!mi9`92%|7k<7V^r!i$cNOp-VruOQ)d>BJnhfSE9fw4Q zAo~5l8EI!D^W5M;_tM<3_7qpy$e%OyXJn_~d(0Bwvj>Pjw^847Jkv`NaeTj#X35`U zmJ*-+J>s46v$v4HhX!kZPti9oMbq$^<3@-(cqt|&zjuGg-#6vYz{(zcFM0g&J$v5x z`_}v!qjdkspIg!A(0-iY|4nB7f9uJkZtv51wO?YY?-ZaA$^PW*5~Vi}hxa*_VK5r# zO*^rlR3t-5<$JAL++K!x&4#HZVUT^GtgvUW!nb%E*eeV^jQ^S51o@*lbv8y5<=p@X z#NNTxyQ&2g2e8Z`Z)kP$cT*$gENNpd0ma5~rxyGMigF|l5gsqa`S5ueD&y1ndz^Fl zoQhrfDSsY}5elP?b-jDEyF1=f=udW3|L7NzkYl}r-hPE*%~luu&S?3@6;nu0a@_gq zPnJ(n0~b;KpN!uhGSBmRHx-7)V>j8dO7EtW)9eQaRhaUg{hIQHw+9roCPd}aCAB2YnZ~@@pfPhq zhFooUyOgFP*RrXNk+>!<6tLG@`9`r@ybZlg0Q0WIV>Uo#vg8R>eL*|AC)bu>Z{S`3 zp(=)Z{pWF=%Wj4*5_7{j9&BNg|CsehtUkx_&=ocdokbEI_o3-v5iK}hj)tg%->eo5 zd&yrux*C~HxV*qoa8Cuoj`jim42Grq%pz-Wn`YLgs&h2mL<62$GM_Xh)lJ=as0E|y zKjvDzz*=|PnH)pOU_I< ze($6?g#~@ajh^$=guSPV-hFV!1LLr&Wu)1EElrR~;yT092$>|nw;D3N5q&nLw8YvV zpNO&}r*?C#Gw`$p=*>y1ysE5lk6t&GxY{*z?KSloF$Hmozo z#(ct`rKG2^#qrw^3&q&hi)!Jw@##x%Qztv1uaN7M=c3MqvT~g$k;32a)o*vodBAhE znHQWzqbn=-%gA|y^TSzcb!K?Z!Q{`^^XK`PZIb5`P#Whm&Bk~PyUDiucs3-R)NIPi zKz9Ix9%xNioU_6Vo_&a3wXbEPaQgCwwSfEu=nU)V??HKRk|SR{ptRfXbV%Pvf6>7)u04sy1x6B@jSJ68gUeo_T_bqxsw?c-j{4867MTtJ@h_AA*n`d zh=fL5TjOSEqKbkpi@ON@RP~c0_c6wuSZYgj!EMb}bWPY@1g`P-*Ov;+>{ys_2cP{7`*e zrJ|hIaCvd}h#mp2A!V%Dy&l2Oqg{WR?HJArxCT;H=&;d$gpL&`Zbsff_^+3S z&bi(~gg=w+WrptPp^nku#NEi@o9xKpD-N|q4xcGtCLQC?37A*FOP)jM$$0m6_w}N@;$nTyC8~;L>c!%& z=s5xS$`ao7ZRl$S&uQee|H9cI`BsmpQIOu8$p$(Pb4$&4jMXE0D0CUlhok2n%nNkB z-fHQd+rmnb)D<5yBD6HwV$^Lt;h2*sFQb8N(266XcM02TWy@R zig@0gpO>{^YFGt;quzk%BJ!F4iJAM-V(o@A}`W(gHmsZjx3K_kXHimo;GU``9&Q|F*(ZW*IP-&0#8X z9)Y_Ls47=g?w(q}R?nW<|5mlg4d^pp-TN8%aUf$ZG!BY*#gA+akYor~Fb{$@@wYo4 zBU{5G<U|-uZUvmR8Co`q(A^CwU70C~U zVix$p2~YUL@YjcabBFn$*nG&w-?S%!%CkCz z9d*6UvG?s?xqGebZo;6w@aW6a-M3?_ir_MSh(?!~R|Eb!v0Dhq~ z@`S*TMN&xXq@p5!=I?#T=b-QT{mIDvvnj3hh%le%_tW3gx=hyVqID%*lZ-C;zqtSK zRmAMRm)MPOP)lxO=NvfV;jGiRHjt@z16KV9o?S>{AEdEs+SNT>(pW;XCBv&OEtv_h zF51&+h)ALG;Yxjt@)o7`Fd>QammLt&9wN?{SPG5z!kn+qiEva}VkG$?G5-5{SBbrq z#=Zp?cI$nmu_GrjNzRF|pXVGy!tOJ+80&B<*c8+HP8c3%j{7&}&woh@<6<_ApCc?p z;Yz1VG9>;2=-ywkhvA~6@U42+vi?K+Dh$0EQh%T?#>h0jgF=;MG<4&vWiB}=+Ne=! zjj+b)l6vwj(5XFdd-mh+EQ~(OSnTd<|J_~T-JmtY^wYQxlGmTO%SGA|)%uZaw;qeo zWp;StY+Yt`gf6qg-Hvq`c^13`YRj`=o5v$s5l6ryqINXPfA2iNbmlQ_b1#KA7BI*J zQ+_nU)7@uxFG03ep0QulG}5G=s4VK;<)i@6{RkAhd!L9UnT1tTd= z@>XJR+53coc4BX8kDb<>^D99c@D6vl0nhQ;D><#-qHOKK7C3_Q`|u9%9r{tw-wDT^uhe}pObpD;zW z(X?&N-FU7#CfwPmDB5}&=OJG?rYMrVpd)y=59;b#DY`p(po*lsoafgXXPv_dv@CJrw>3SY<}%;68h;DqJ6Bemq3|Piz}?7bRe-$*%MyvbMSCqvGT`{~B}N~6HSDPpUalL-5{bQK2Q5o9cF@K?PndIjw43TNzj5a$;!@%uB^UG@l+M6> z#j*tNAX(C0$`Wvw`WyW&Ro4WI$4vAQ&%wt?Jm;Dwc@9}4Zkt!|_af-M7ch%$m{Fhr z_{jmY0=HB=#k>wY#M7>69NC^`t#wo|((|Fb2gX<{Jk`0v2Kpnxd#Xu2&syeg&3glS zBJYhgAq#Jl`X-%_fTwYKszNH*9!#z8h4U7v_X_P2VBwwgxZEX>kSeo)Fy6vvC1V7C zpTt>NR)a(~qOBXy8UHzRH{k?#_to6Z@`5xFM3-vI_0Hn{QzWA$_U6WCI4N!H+AcwN z6?-?JN)sa{X)UogAE0^LiQSH%NNUhIDY3Ue2P%C|YHC2QvG)RveK_;B#NML6=539= zs@An6b~+~|_LdmCJ|~^n9h7P9CEk|UTMp2??Zj^H9A0@oCxP9da}wRNutv-QSFEUt z#M}L8U3a*_9qMoNyHpHmAl6_jR~J9dTu=mmV2*;;YoO#E(dZ@i`8;7m z55${n4%4_*##UL}okY{C;8qzbWpQ^hppRaGTSZJIZj!um+}k{<$P=+gqQ{+U?@o!E zcwLTrn|n2Qz3jLZ9VPC18uw;!eNzRkaVve2adQ_T!i`g6h_1%c6jA+z24Y8V^2dk7w<{7L2t!1Ib9kz4^wIohU$^u!Za;BOgbkmL%7H7)T_c7eo0IurL4 z1dPf+kQOxQOoRvXuEaVMAk-S=TRYu;us!#DF|y#Dm}hpt8#@|LgzkXH&!1ftJyX-G zQo~#P#+pP!Yn8Jq)4aj##gwRJt#X~<8K0*a!(aLxKVJg)->ef@b8i`^RZ01v7 zJUJnTBI3zNBn~$#@tg7~lngYE#eH3}^D^S(DUNJobZ>RsHiew9S`~1WHATaHxN()c zGUvF^8JOCzXPI|=CF-yHZHD#p+298U4g|mYO4OUZbkPiV*TZ)nnRoPW)7^FJ{{6u> zt)z!0-#Od-|JrOs2);ey1tSi(^h zmz(ugK+|_~mi70!jT_CktokBKyk}*L_qK}thc9EphQ5JC(+RUrq5HDwl@YU#U`<5| z24kT{bSW?CQa+-|kRSFeaWAgdb2}K*$KAqlQwc8mOX3Uo!i1tW;ncHN)D)toIbeI~ z(W9jwee{snE}B`fW)16vIU)G4yY1FD-`pB7M+LhEqcQrOSi9>XTOvoV;(k2(vZO3C z`UD>56{Am3qYv-BlK(t<+&f337w5;H`~LfLhYyd11Fx!8ES6f|iBGI7_e)z>uihH` zmso2h2A>1E7xxgS}0EsfAJ5(I$*))Rm)B^wb_dJu20V zisKnz4W=}!MEJ1V8y=-UrkqS=J;6it*jq*9Q2thqYxwEFyBn;RE(doP-=tg(QbYu@2G;c9Gj5xeFYW5%?jzePmb-HvlM5sSiS(wQspXBoL@ zith&kmlwU(>H9hOz9oOI#GfC;=N_Ktp^;Qhq3`Klux5zE;@&y_JS=nxxjXc^8pA_Z zv%gQ_?+fwyckbtR4Tw(~>MOFN9kTRm+8U7T?nJo=J#3h^m=`Q~#NU<1Nd6vYZ<$V_ zr_k9A+Sj1G(dyKfon0tG{wy%sR)@~{Q~Acy&sY=hXP+Ko+EYc2vW9uv5F5kuN>_7( z265yyX003kHq2?eTfokcWH+8kh=-n z@?Grb@37TD@b5D`viuo-1;gjV7IiT^IEkO{;k`!vaUAfd1L`LGMp6-<85}gs|FIQCzIbc-CD~UGj~Sgx2@;rv;(iqhr}+0*GlC$&BRJJ z<2;sprd*L2hqzfJ%nIvEXO}Hd_VleNWQy=m@0kb z_-)@E;5pkd(`anZ>!eNfwchFMyMs)md3ipO^RiYUmP@MyKIG?h**C~^VEDfBxqC6g zOaIfCfal#{HbXS5pV~coH^6t6E4dqVbAQMdeN&qzlVEjA>87gZIfv160XT28Vbkr`J(*`|zSPwb7{^0ox=Dvp3 zV@^vC&kx!CcUCz2_27Ammh`Xqhz`7~%x3P>paWtm@OU7b+V-cBY^~-a+r1^vY%}7> z95sMls^l+DCfBE)UjZ{1FtA)J{!MdtKqP@ztMM8E3-jbzo?|L_mGa&BFZuZZe%=T? z@GZk%XRqmZ{JbXc9A)?+_VeESybox*h~eAV_+R7aeS!Y~!{2N_A4$)xs_?sv@|?oH z&cPP;iHW2{g0|6EYj}=P=?dP!cy@-SPzSjX&S}>lo|*Ct9E3IZ^akf*0S|&nGkda?~JB_f*I8&toK>V}#%O0eB|y^ABwJ41Vt>JYT}k z12+5@^jwY;6>nY|Cq7RBTnvB49+01@1{dE$65(@uj6Xo1sUpXQr|L$pIK!XkVZ2lM zGpv}1@8JcIpFK-%{ApYVLj(DT2Z4{B9iqnI8z>uq}8#$%BA49+S@CA-scO17ZtOH=SJ zTz|K&y5bB8Dv(n-xXkB-|KIS>WBh*1S-wAlpNQY?;eNSfZo%#2yl>YV!?)IFRboFj~qAj0pq|ef;O0!^YqF()PgWl0dm5Q}6m}#i}=59lPXrX|>|nryd=$ zFst?>L+01+n(_;vtmH7FJsOE zY)^VjHbEEQ8|QsvbR%T>u+eLq;^dgYtz7tjj;BH3aPUvMXe@9Tk-{-_5t@6kl_<`Z z*2Nt2t&YSm;Lza_b)#%6s%f#Fstj*66ZoV2N#*Gd~`3J?5F*X^JaNxQm&YgJ97g1 z#;FQkl{?Oof?#Y(F`)xPz!j=uz0k-!y?6)y!8>eT=y%U>a0%Dy!yf|sZC<8oiQ~iB4cWk@tn;5wuVOJR%{aO zSfA*Jo+r-SicP}J^R;`SV7@qy@!m~1BUo-)gIR9!Nkh+(7a9dRu$=;bFUvtx06l=pi5%~f-nV_-e9!v!``+>W6qOX!IO_4}F3}6312J7=9*Oy&Tuixf z<(?^bxZK~dZDU8qz8w2^T)(*D@<#c=<=-yKx zJYOlV(u7LSRytBSw(<>?msUPkWk8h|t5&Jnvg)a7(bcwBZ&1B?_5SHm=^5!G(zm2v zs&Pk+#WlXHS*~V-nj>mHQuB1pA2Q60su|5P*46UX>Qw7M?WEeX>a?r#VrF9I{h4R7 zhC|$bS~sii#Jaoc`Ra|V_hbF}^`F0{>NWRYbFRUF2HP9@8a8kEWWx^{UcT0KZIf$n zx^~I6FI^kTZkjzk`-$uqvkztm8r5mkzR}=D>l!`X=y;=G<7thzH2$GUT9X@_yq!}k zXK_=r>Exzca;xU9&OP6(U9&ySzRtTYZ+o8Ad|>mvE#g}AZLzFHsAb=l&tBKyx*6A< zYjsnr*IT!0?Qi35)4t8BHW%8CZ2L{Ss_n+K+tEI~{Y~v3ZU141Y8|F_INh;c$90`* zbh@Y0na+JWPwjlHOUo|%x&*p*>bj`w$!?9h6?A*(`qb-tUccn}qump`kLmt)kCYzs zdxUxp>iI#h4!vIJU9b0&-beE5=P%3;^qJo0@(tZ?c&x9h@5H`m`t|Sk)s16sioR)0 z|JeRh`@cNEHDLUJQv;tE)NjzS!Mz4=9DHF&gCX69%owt4$kRh-4E<@CXIPD44-Wg+ z%{SaU=jN>iqM%p7pn}l_6ANY*d@ww7`2WM)d&fsr?En9B%BE0~fQU#lfCZIir5Gs+ zC?Zl-swiEGM4F0#pn!l%QPc=hMWjjypdcloh5#WUgance$%bS%B%9q$L#5<=pK~^W zpm@EX`}qCw+mqLsQ|HXQ`^=m(dGF2GH!r-I{Z^;9mcCUyr0Wpt&{0Dt4V^hOdRXOQ z_Y7+^Y|5~s!~KSTF#OLE{YPvYv3ErD$OlJ$JaXa4Wh2**j2KmW)bvpoM&*q9<8A%z zpts+AJ7#pR(MQL$7!x+;#@Nwglg2$WZsR+acly4w`JEf%Cyk#u{`2vB|HE>4{K@g> z#;1?}J+yXcNa(=O4?{l<{VMd>yOwuHzWdp`-@g0PyC)_roAAqogbCRb{+!rh;?YT? zCS94VPChZE#gy>(M!t9Y{VwmX{h;~>+o#?&b<>A_ACCQS?uV;C{O!ZUX&t7Gnzm-z z?rHhcXHGvnqvMR(GrpR!c1G%qoR4aL)cm7oK3err$;`#G>dsp9aleoI&8|9o%Iuig zMRP*tteN}Z+}GzG__Wcd<325#*Ja++dB^7~^BSsqj zzxVTApRfD;_!pJGc>0T;Uu;=edEs*l_bj@9(cDGhi|mX0FaBcj`6ZQ>ys~8fmw{hS z{4(LIZeJZ*+I#7`rCDD;^YxeCRQ=|QZ(_b}`0dzlw|#p#?9s4cVLyaj`_A{fKHr^O zHgH+^vZCdam#2Q;;rn$fo?6ji#aAmbRyJE1x-w%`=T+-h*IT`PO{+EWYhPHqckPWI z2K})2hn#iqtczdg`0<$^r>}3eK5YHy4K-b=>sX zrZbxxZ(g=JdduBgLbuG`61HX2mIGVjw>Y+3+uD6=#MaWE2mHMM=bUZrw}oxX2yYiY zB0M=ffBU%Y2@zUEjfe*#T19k;=pQjIVrIlw5gQ}6N9>6>7!ebZ7-8M<{ElyS9NyVz z=X*QP?|N<555M^TGVYi3UkCg;^jG`t2D=ySPT$ja&#~WXu>}9NWUsn+*xsM^RoT~Q zUz>eB_YK|m;l73YmhD@=Z~wl;eR=z}{k8W$w*STbZ|48lL4j#C0Ap1Z;q+ew1$QF?=L=K9a7`Y&FZRC!~6Oq=)!YD1O zPSoR39i#e3y&LsO)Uv4UQHP=~M0pMlIA|QIcBs*zHivo~8hL2Op~Z*R9NKZ{@S&7L zd56`*wGKBw-1+dXBd;78eq_p#FOK|hz09}7Qr^w^nWX~&AAeWI&J*N=WG zx^wh^=n2uEL@$fp9vu^Hi!M5DIbQ8}z2nV~w?E$N_^{(29$#{N#qo{DcO5@?{Os|p zdX&siN4*vG>F_ift3yGj?R` zjM%SZH^&}|O^J1$)=uAj`q9%Nr~8~9bNb`cVW-1SN1skRT^u(s?wz>Vam(Yj#O;qe z8+SQg#E*}k6Tdt@B0eVmTzp>qjWadQJbLEoGcTVRdS?8YIcJufS$`(tOw5^cXPjql zB-BWFD4}&ir-auMMkUNhSdg$h;irWC2{8%j37)gQXKSBrdUny-^=J2;J$p7cQAxZf zv0-Af#5ReY6MH4TkvKYWPU07dUnj0e{4sHB;;zK~iANJ-6VD~4C1xk)CzhP6dhUU9 zEzfm1H{jgZb92uvJonAHmFLzcRZDs}seMwfq+v-@k`^ZYm|P>dZt|1KA;}$+2P98O zo|^n|@`B_qlQ$-BPu`P!FgYgqO!9?fTk_@Pg5*EX2c55VKKT6P^V84IIsg6n9q0F+ zKYTv*{H60(F9cn9=tA2IuU;5?VfKaZFYLGwb0O`*^%TF9+9?fFTBmePc|B!l%G8u4 zDH~EEQ=(JiQXDBpYUR{>QX8ces1TQV*x5rWU4NwW`*8 zt<9}3Si4(CSZ7$jvHom5YPDJm(<-GkOlyPcx(Q*1 zS5_vioO`$bLV2LH76ATeG9H&t|7* z=VkwH*X)7zI`)U`&F$aVZ#Y66(;TTe&*aR_Id{3m<@uMFTwZbcr_0+e|9Uy{a`ff6 z%gLA1FFP*(nOixxVQ%Z(p1E)5&dU8RcYAJ3t}XY^ylQz5=XJ>Imp44`-Mr~}^YgyW zTa&jlFDma;-o-pm-gT#+vxYO+*~Hn(+0ogggKgn(F%4wZOI3waK;5mEcNoWx8@*g>HX$HTS*l2JVO5kGWgBJGi^J zlRaHLn>{-`k)AW2Oi!-oN`YDsP*A(z!GgyN+7`T2@LIu;f_Dn07R)X9vS1~#qKp{T zM%A|%$324sLrTQGelmg-M?BS<$@HAk%X#(w8|VB7`pIbBpTN@mX`hQ>-Yv3_tp>oi zn~T&iFL;0H0U-VK>h?#1FXspc_b@a*nAJ;>ouDY84;~XMB)gBQl z*S`%mfS#Z`coNJ4lR+mi3Jg;36CW!M(M+!<+UZlp68#Y|Q_B(|zKz8IOK(x#QbjDa zv=$>QZNyT2E*Q@K1TosOO)OQP6F=zhil&yz9PcBR`trYiEI)&}Twl*j-_%PvmndG+ zQ@O6Cm~Lq*s`J%G3rmoASkDl?`WexK9)#IiUr~d!iZ(_(rF}0nb*XraJp1dj#5BDH z<)00@ir#7xUwX_Jy?E{iYGpB9Rg7JFQ_{-fbDt|*J5hX~FXUQz-)Ew`8c*6lbX7MB zKYfCDPb(2MErp_i?j!EgvPBirUg|c{N>#L23Vi}WzDP#-25s@+8c%U5DC*Ua$UDTevB5d+jJ z;xo%U(Nm2#vMdWkUwtL_trOFE3-3L~J9p_JqMv3LOSNz@L9L789d`8OpA&1NPvgTgPRAi@>2-X*i zv6k&(Iq3@)w|L32Np!Rf5M$uwYx*(qjUK=?^F$w=_LN>*yd}%7uMrc~O=6=yTGZ6< zf(J$Ld!Cr7w}j`5K~v=PO)(SNb+p8Y?mkP!2z`f`qJL=EeBKpLSV~1hOFuEnZ=PuC zw@57a86Y0xxnElR#9|*Galh|c@=X$5EE|x|jmTsr(b{J)borBO=8J{C%SD*)pCZhs zwy5RvC-w0ai!D9G7~ei(wf;Nhoh}CGi^L+WznG(65fAxH5%u+&q8ogetG@$3mWc*F z8tJ#}a}0TFWI0P6&$2&44E9+l=K46r3=1>&`HbhfQ6NP0^qGzBg^Gvtca2o``}mv@ z^?kCqXTIT*`S^B07P=!(BaIAnGt5U3bJ5MZ(4vy>b7G6n(_)2BK6J5*kNqDPKTwB7 zdNB6E15Kui!O*a~rM3u?G%w%x?L?j(#ia7QIX?pV9jF^(9Q++o#_JE^^N&JYrHAio zH=jqKTOGnQ2;`$fhQ;C>C-XnSTTiBb2_0Hlx-^bujsCdwF71^?i!InwL!9+0$ z`!d_-e)xFUI7$EhV*P#cZp^jy(1C3{6FKsEio9#{j2U97&-;`CJ3v>IZpR!6kg{KVt>Akkj`P7G8}ih0^qvB0vP zHyMwM{=Pqnm(&SjtopX-Lmo}BHBT{~_cnHHuumv*xm$$!eMLPQv;8@I`yBgLf-QVf zG}hNrpEr<^>7ubEON3&dUiNE-?E8yxmKx$4=-ChYNVy!~vld&jL=3TfBi8E|D9a~e zr5+)k@#`esP@5Xtu)o7iUs6qkNPnVN5%;SD_=-D>Iu(dc$WK#!gQ%tN6HR>^d10w0 zn)>`I-(7%yEkr-Rr>LLTj?N_Qs@KEz)#JJKL~Fe+_M#rNt|wZ6w%|GN4d}=7I-oxm z{S9%qk1zH5Q21kSM(WRq`>AJJeIT|XO1zBSmT7lAO-#WqOwsnRKY;X{xF1_TN59Da zdgyqRRNgm2w9?iIfAcz-r@WU`3**`6x#nJEVTI^n=_7jRS;*=Vo;Oo;_w9qtd0kAg ze9L|^*S*VjKkP;uQ5zY5j%%lwWje`uWZp7}{m(@Q?7E;{=?OdHUbA$>E;dHbkX3YbIW~C~{FdeGjy;-! zpYc~M_?0!xpCYcW&?}3ndS&Bf(#aB%hVq<5*>mprZ0yt+%UUp(=Vg#);ydbyZ}pGG zJNoM)P(L7^(#K%4nu+ISUdj$J&?k&C?8Juz8R68uH5d(=fDvFQcnXXM{eX;tE=gZ# zq7Ly^9pjoxYStr94AGwuZJ_rw{aN@b^Zp8~L4KBUY!%zYB*Y^UvQ8;u+@&XTd#oj~km#$7V@Dueo*aU6g9 z1L;W+c{ApcaaTpic&h@;cuU4q{{$Il$@)})THDwu;|$VY!RDLsm5i|}g4jyNSLKkg zm4vL5eBR$uSudU^W6L|H#GA-z?4&vG>#7V@qQZCH+mKc+IEajR7W$CMCx<-6%rVjDB#?_=kZuGkq^_7YO4_N4 zkT$#`q>ZomEb=z(PkB03jIQ{c@@*ZPejBj!Ja-A$4E9r&yTLT+2TXq;ZB+%B<&$On zYdNJ~DTnkI6(Q+Tj*4}tuxIlWm~C7eXg{~vds9&(y`QL8E-_W zn~YE8dD%uY^#eYYx67o={E!%an4TxPb+kwR2@|tp4{%b1hE6&sKxDcs*v z(p}c`Zz=5?vkgMK#%z1grYp#?R&QWa4rlBDAB6hjGZ)dfbPwX>I zUrifjC%(VjCzksqFORB1>lcx01$%NutzDW~Mzfmup2z7ccn6>HF1{mBPcPkK+7|TB z?EjJSBKv`4TINs7ePelA<{RI?sZZt4mby-#kg3aFUpL{VZ!7a%W~@U0kl9C5mX_;q zxev0ODy?hU{kp~@mfA*3wUyCYKVf{Ozh9c8yNq?_Ibu+0?@b$O+IQl4VtX0q-?ZB@ z{+BkntgT@B9=1(CA=?7jZ~VXhER#*RYXLH?C>GE-H}$HKHdnx9O-k^DGMbn<@LY11KUpHqnFWwcMpa}9#^C!>A%*yxW$qGL+mz(=~8GB@T%%#G`H;+lt^Db~#(h7=8 zx%6I8ey4_{RivF1u(C_M7eaMOIQcV)=G~NQQ#NJo{{EAvym!fhtMH(F|8LiNS;ezt z)lHhPmO2KJ%z~LK6p1_KwQ#zOVCGdfd1A5{nL=lz49jAx8v9;OlNs_?sj{RzdHDO9 zb(C_?zQ4(kTZHq0M=Vk$Djd9R`>)lIl>Vn{&Eq%uN;%~sb;Hy`Dj+w_a(QWC?#P=c zsLYh2-u`T}PO{>XCXkH6QdCn{I3n|v%r47J+7QTKas#=!`3P>68tJtdUd@7HXu5>7 zHZ@pdBT021zP#YSp3D?JViH@bs48ZN)nbd-%9lyUM4YfQ+hQr7+Er5?P##iRD7}@z z%1C8~@{zJg`BGVJ+#Qd^^iYkRa9 z?X;G_SJe;b&Gk-tcYTOHUjIO!tFO{G>f80-^wWB>ZqrLFiY3T$SAC^^yZUqL7t}AR z|L1+(g8hRl2UiQeJGg#u!{CR4TLeE5+$K0AxMT37;E#gW1#b%861+Y5x8VH^EDi2z zP_se91`jr9*5D1^5%Osm*syxT+70VBe6-<<4c}}y{DBiL^~&LEI+J|d;JqvPleG?} z)@!Ks&mu}hi+JW?^9Vx;QmQl0Z)4>#rH}F^|Ciib>($COYJF9$RaWa`)cQQN#^jaN zdN#FQsC}jVpl#QF(@tn-s5SptTyLRw)_dqf^-z7PK2Kk*Z_*=}s~}E4uV?C4;B2+} zqJG=@GwZLeUs%7GT8rRH!9l@y1>X}K9Q**aemuDK&07Buygqm{wcZoF@3vYGD64g~ z3bh_atrcpmQ0wc|8txlcj4b86aY#939K>Ztg5SU|U?+$Go4^+S|Dvy9DgC1~PjN|N zl@2fMs5H89{zmeRm>WB9Y`F2$jkPyc+*m-4rTi~@emCf0HZEQ-y?%}UHuAhqUe|vD zYruD43FqZo=nt^X7*2L(_S)>;*)y^n+0(M8+a@roJYERfSlbxe+qSnZZM5~fw8qxM z*1*PljTwa?Kf|7pov|`wNyeg#+38C&KFH{nzUktY^p)u=(!WXnD*e;+G3kBMd#2{! z^=qZyefFw{m1tAmW#Ml9ve=|X=KOq*la@p3L4}_(Ntsb$_qI)CtlZ^_#jH1YPbpCd z6vM2tZ(Z#Lh5$yZ)MelRI1Mtr*WSKn1oaL-^$^#C|K+ECq|Q`lsUNGKsIwVK`%qn^ zE>@SQU#efJOU1|H6ZLEL8}(Z?O#M#G7IV~P>T>mab%nZ8T_xsQddRhj$kj zs|9MITBH`MCF&LRcdI`*`x>|cw zYoayPnrW4^%36RHh-Pln=JEyMr`kNmnYW7wZLzjQ`%>&c&z6dv+Sl4QVwd)<_=R5Z zU$yVFWn#CsoOw@v)4tbMXe+f<+G_03TI~mMMEg-&FOJendJJ7ZE@H$9aZ;SpeiE_b zw3el96$#qU;;gm}tF>K=5Q+R>!z68|maXj)$=WaCy!NZMTU?+gCPkzQD;mB-q-lG# zecFEQfEKAmX$Qqck**!m4vSoo$2|^l%7g2tbHHlRc!QB>*#fr0m?vSkn#prZN4&Cuct3i#w(%9EahYUbNw^rTYZYc7aZZDN!M`y z9(}hf%EErT6=P0#$9nu1=fQ6@4Of~32X}hAW4Q8W({Qy(xbjGYrr}zX;LhRN1D$*I zZPYJ#LGXeu!xjX04j%Q^uyFkWGv&na1^t=_hl}2Q-)7yXZ-emm{p#G@9Nw>Ao2KEq z%!WI-dO<%j7+sbDsd=dRji%w2CS8NWwFi6j?b$bcX2&|=?K}3X)1X0cr|_sAeZ!+V z)@jhMU(;}(n`NY|)8DS;Ev;{paGyt-hWmMQ=-oHGeVuU8Z@~hYU+=z+8idbWu%ONY zYEZr(b^HEqMf~+Z`-%skK&Rcx%pPP#(x^cld7x2)Mhz%ozm84A{hM^{-M14(Y(Nn! zH3@IhscCrSCgDv zRQ#&6YIc9^YHa?hzS92jMt93C?Zs!BHK-xC^qa>lEgIifGe92m8QQa5(>ij?xBZi4 z_xcTZsm;Up%47bY411+bBe_-Sy&*3@-9T{R@3AUV-t78xJ$bBZll$w|s3Nxl zo^Sc+ebw0#5kUdI6xPe5h?zB%i4oy))uVKrh`?ZO8y_rp<(6Bn?hEGP!E&`ouHxj%kgIm`y5AAjP2vbPzeeesyo<7&IcZvps-@r3 zAJITm*4v00`WGUIHg64|T8ytni6F)_tNYS=@ws@@*9D5-WTeOFj}Z9TvTa4wX3u+E z6#=x`z1v!a<9dZ{i+B)k;Jt=##)%ER+rFYb_S3uVPd_Hp#GB8mENUp#%eJfVeZYfd z+f~ItW_a;l6CnEFFTLAA+)2ab`IAP9~SPxc)Wsu8Eu*&og8Rn(_Q6L`!D-FE0=8fmFz?>0ffI_?)*XMKJjW z^V|uf!^nM{`J6Ev8!tw%u2{2Xx9#12W+>N>gG!@J3h@pCWqivlqqj7&wv%|CEceTt z8_KiZF{v<&r%YyBK7E2&mQid;+J%zCP;!)ex8Ku*BX^=j3zIXGxU&uaPo=qd&s>_3 z&#kh%c6++EDCYWH>|_N3fAjb z6#i%7R^)R#i-Jb&WgW?)h=VMOILx9DN5~lSB#R=W2-fkuQK5*lEDCXg)JhwRBC=T& z+838u=ZR~qZ?Gt|HWZ;KG@V%E>si-SYO}7Z)MXv4G-Q3h@&IpR;Op7Ov$K9$d7AYz z%t56n9h8o&Ur=6T-Bn>?SA2L+)_s(|tntpQhbTi>4^xJ*9;J+8J(?(1;XmQL!#Y$6 zW&Im10ZrMf92BaOpx8N*tK_mSQi@oYC?%|~Gls129SUWZT@kE(RbSTrjDaX>HMJV+ zntYq1sI}=CRMf`s0iU5#a%uV@D6Qn zZw_)TOX0)&crr%?8CJ;GBJLOPQCwxe5?9~NH$eA@TH;=Et;0-L^^oWX#Y3VoGf+H& zUv7d1HAAbUm3$m4^`v-8JdLet#kbsTuvj7DSu{Y}w^>O1Z1Fjf`4VDp;%H{l*vVH; zzldMOZW%9&1Z38Xc}21~FD`haT#+VYT9JVaXNpTA3n{iE#W~_K@#Yi6mo1gn$YBTN zd8L!m1^Ihf=}Uz8t+GN{tNaLuKP0lR&>kVipR0bV&Qs^B3)Iil&($x~g%#T;x7sG^ zFY0dfH+mNis8Q-6^@w^*J+7WmPpPNXcr`&yRFi0Zr>Iu-qMD&*(jLjCEpnMwNIor) z0$Ls=v^TEO)+nWgE_)+=G(TDuRcKWN(c-9~)zoTfwY9oheJxmPsNJtUpgp8LO#7p$ zHrLzQpcmsavqiti+vboh4%yz&zSY8HOG8_3wlTJ9KbN-|v>nLqF6|fDQlRJKx7%9> zv<%K_=d@()0y6B;3h6(ts^3Kf{;@t6$@IR5tBOh;rb;Q7Qlu36#)s4jspVVh_h#E3 z?fgROcWBl&(Qib%DJ<37y(!ZU&DyQ4qE|_1=WKtV{gsdw&!%*!QT4^P5$&QvQmQTt zI1+HWU0A!Ywwdjs+NA`>x3>m89kPIRk9JWVngxCHY^}CE$g@YaTGeabRqL*+HNJ0e zt+BRU*gf;^omxArc0}#nwGY(WUGG4>Kk7HDzdQK3hE*D6wwv-miw9FeT09&gpC7W= zEX|Zhsy`aVo~y~GrlHN$X2Y7l6q4248nU28L<{TVzqE_ui>Vnc_qAToE~-`MR*9`j zTlZ}(LKP0GaVuu=LnV_&&cG@|gg_rH7 zJewkGO8qk1CO%uM?3(H!i{)KNNm(xK)`rw?=L~7lHiG&hQ|;j}bjpG2(udzHR`m#JE`int$jlnEU!~&M4#5>>MJ65nX#~Qd7l~Ih=;7!^|3(4v^%e04 z@#HmeoyfKn$2N+{#v;Zjm6S^29i^&LRg9+>qqYcD8Y&INM0zb+h)L3qi1+X$EyYy4 zNo(;T9_1M^4WH6cOec=%BR--h;x#c7-_lpiqR-(Cz8ILT%wcTwQ)RyRR5`Dl=l#6zqL47PliEpqr@o-RD3(c2 zCBDa3O&2TiS4+hz^*eR7*rl#je-!)a6Wb;Zsyo$vA{u{mK*ZydqQn{e(jk$6Z#p8* z;-BI~qV!4PB3{WVY;H~mS4j#)bF5|Us zh+NfB4SI$kocKcyAc;TmSOMZHUMomk!*f*^*YQ}v;s##p0a1$AdWc}`VeMi1keX|) z6kU5>dqD}%x@p~&yR<%9AEl-?Tzgx&M;oV&SL$l-Gxzp=__)uMV0x=pC=Y6@wbjbg z+B$8W(vk>lz0ykCq-|1KYj`%LjqD9mLhx*Rl(zV@{Yobyvm?rj+A%F!d4=BnQ%Vo| z_s=SQ@NMUm*YI!2%Io+ztI}6X*Rqs>^l{mhA+p~}8H(TYD8uQ4x~7cKN;N|XrFThJ zCh#?N6=jMZqz5VQ>(%vI$_M<1=g!JZ{$Krz%0}h{d0pA057q}OyXi%rtn8sD>pdk> z_CqOAG73}<>9h2YmBaLO%~p=mzcp7mrhlt1SEBV5`U>R~qYbN-SbeR&R*BQs>l>7K zdf_)IXZ0=m&q|^mu7@kh^vXvl=k=ZXZ^{LIpT1AY&?EIo#ik$9k13h@as9aB&`;=O`{cSI<@4dVyY`c=Qszg!hdri&n-FkpPm6 zBT8$~$vC0~fFMvE95jyT?}13JsfEtfAbOLt#MV^qr6=G!Q4@|os5KIrbe`&anvc*a`Ns zzn^o*Nn^lC&Lxm<68PQ7Q#4T3Xs^^Ft!?Be^+_9o*7P7eN7{+>P13i(7%;cgr7Qpo z!6J}nL@D`3l==kt$Y`(51hc@$;1e(#%mK@ci|TUlJy-!&f>mHOSYza=Yrzj-9rzJ! z23x>Z@H5y3!i`*YJBR=~z)mAa-35Lj|6j>xH|ZYI-$?h8?&qFJa1a~@M?o}z4(dq| z3*x{Ta2A{c$spTkq5esF4csvD(Dxc>dku8GhIY4+tK9?c1$96@a35%785i|n(gvgrNgI*gPx=7qgQO3UHYR#^ZM(c9~b}zfx+M{ zFx1G^hl7#eZ7>Fm1LMKF)M+A^4BkWMzM~Atqy9bjtp@A3W+N#wr$=)BFxMRgCygjQ z0puD{wB}kF>7tF1C7xlv?q`iO>_TydP%r^Z0`D2=`drdT(nCg;egqt27NV0PKu-XJ3)BX6L46Rx_fA8=FmRCjyAhQI zVZ(!nzG~2GRvr78gMG}wKIUK_bFhs$^nmd#66tqfFE|d+8*E+nfqq~B7zEw|--C@{Gxb)*6(dQRV}yzJ(8~$EoY2b&y`0d?39X#a z$_cHU(8>v|oY2Y%t(?%x39X#a$_cHU(8>v|oY2JyU7XOx30<7f#R*-U(8UQ|oY2Jy zU7XOx30<7f#R*-U(8UQ|oY2JyU7XOx30?RfdVps`7bmoELJKFfa6$_wv~WTTC$w-v z3n#Q-UM+w&LJKFfa6$_wv~WTTC$w-v3n#R2LJKFfa6$_wv~bdY)7!|z<7L9>T6mgF zJWVE^CKFGSiKod_{{+{-4I>lloQYM=#QJ7pF*C82nOLVxtWze|DHH3IiFL}vI%Q&= zGO(E}%X;6x9cv@U#@-M=#E&;KbK1ond~MhSkrNSSRE!tFxkQ!o$AHwy8W zMfl4id{q(trU*Y$gbyjghZJe4{GV7WNC$cB7a2wPgd%)G5k8>^8(M@7Ey9KtVIPaI zk43b39%B6{cmg~HJ^^2WFt7t0K}XM08b5Fkr~~SO`#=NG0gR?poj_;sBIp9`=fC1?*734h8H`zzzlMP{0la>`=fC1?*734h8H`zzzlMP{0la>`=fC z1?*734h8H`zzzlMP{0la>`=fC1?*734h8H`zzzlMP{0la>`=fC1?*734h8H`zzzlM zP{0la>`=fC1?*734h8H`zzzlMP{0la>`=fC1?*734h8JQrw`x{LyQEx$XO!JEF#V< zaRk{vy>-Dp9h1C1oa~$i|8o`vTjUY!{N2u>S|!SMhh6kw65KMf8$I z@FHl0}4)MRbxyWRgWxl7;s=i}yN<_d1K`I!lz0MH@ZH=!_0` zrlzsfFqRs|ifHtysu7D`cSf%}qt~6$>(10LmKw%V!&qtZ%Y%y8fjtoQ?~IKgcCC%OI<@j|STC{7!x!pZd>PymWRF(?7Q zbNwHrSHU$o~uW?ag2p$A1Nf zx$Y?PISr4Og2zii+C50S2Wj^p?H;7tgLJ!*ZY$DlMY=smw+HEVBi$aP+lo{>(Um|X zIv0udAkiKq`ZN;lMxq@^tOx1zAeC06(t}ibkU|eq=RxW`NSz0-nu1qN!KO5RkpeeTU_}b7 zNP!jZd*Hkq&U@gz2aa3exRw4)-b^6EuL8#%aNGgM9dO(M#~pCl0hb+c*kN+^IB5*{ z-EhE32V8W(MF(7Tz(ogKbihT2GFMbl7J!9d5pO%JF&uEv0S6s$&;bV>aLNIv9B|43 zryOv~0jC^r$^oYwaLNIv9B|43ryOv~0jC^r!vXajP~QRN9Z=Z;g&k1X0d*Zv*8z1M zP}c!P9Z=K(MIBJo0Yx29)B!~uP}BiM9Z=K(MIBJo0Yx29$^n%eP{~1rc>-C^r%iN) z|EyR_>#Yru`8ecU;Ybwg6GVvzxUP!Xi(Rpu^b*Iq(k|#t4zj(}pDPA|ifyL->>n`} z^M*;~o9(9)+*jU)s%7NTdt4bh|5ID43K4b{+EP_$OI4vQRYf@~swzp~JT2u5#Hy*3 zIE|7M`6_uvq~c^dpR}0sC2apeOF9TtGxF8yqN-Yh?b>WVMyv4&BNE>Iy=_MS2|gef zACQX=$i)ZHS0pN{yTJe0Zo|gss@K2`+1Dc~)7KM8Ur!``J(1c|;Azkjv;wVZ4?hn& zf=-|_cmcdDs?rY>Nk32|{Xmgg503Q&y+Ci!9}EBk!5}aWyaUFAiAISw2}}l4!29$L z%p$*!foxOKhoP;fT$@N``w}aM4CZJt9Fy(L1X64#?aeB*H>=Rztb%OjFos_l`Si9q zi`cH%?yN$;h-`ZXk=Edir<$M^_;1>xUAd!yG#bPV$9n9DND#qAL9|k@`ha8^~q5faArWgdUDRNw3oKkXn#Q zbOb%c8^8t73*|}V3f?Fj(;ftk!6V=VxWc_Uh~Zk^mZEj_25=GaJqbDj_PMK&y9&9h zkh==GtB|`2xvP+op8iI$dFLQfS`B!gVl#)@MsdYl@CwCvg<`CDF*z2IV-Y#ZwplTj zyV%S*fiwl=fg(`;q#8ysmbnaoKkdJW!e|bW*B1UgR z#1=wHWUNj^PYK=lN;{>qiv-Rm0iGl-Qga*L*3R`VuDN2wU|Y^8{zf)EM2YxEyAo_% zBDR;canoazfZaJloL>xm-1HtLC@&D%bpcQSdbyP$+&2_$ABOcEYYf9i#o$X%;7d>7 zOHbfSPvA>WsIncflh(^FS}6g<^Fg3GknMp+9FuJV*>=1&TG<7Ff^mU2yIo*BydF zG3=kf2hu9iWcwh6G}SnP-#dZdJ3((%BGj~-ZH6M!5|gTK+6=|;(5>GE_iNC?xtp{m z={=;iNbe;Ik!^%`*_Q2uiKMcvFq!l{+8ZBmUbY(|**?Tv4u?5@g!Cx%od74I;6xOh zSOF)Z;e-cHY$i@mAWlypMo%F2W+adEiAD+BSOGUYB8}~f*l3%0vz)YV<*6|6>#j7Ld%UxS1oLvEDH^bGLLD3ApT8&tGRGA7jEXl$!y}@1h}~w zPHu*ao8jOJIG9a5ngAC!6O$$oeC>pE8%7o+>C>pad1=GDXE7mZ|b4sXm8HF3SI{T!64I? zN!^Tvqd9PM72G@qC%41N?Qn8CoZJp4x5LQ|a54@~#=*%rI2i{gT;=~RfqQ_|&$=87H8#N24RCb>TwQ7EBe&A!9g3Gv%$Foa4sFr+2EWFjvYYv zF2gAsoU*|w8=SJ4mUEnu0S9dAPFfSYKq1>a7f#sVgbhv{fD;Gc!~ra&8>-u|jBcoY z0E*k7xDCtbMt^Kj+=g{@V;S90+6JX&w)cp$h`x(cOdr; zIAllebKp`Ea_@jsNpLC&P9?!9J96(p?j5{g`v5JhhoJnU;0f>)Xk}!;y$q~cy7+|s zuRs`x;MyIeJ4q8b&$tF}odm(f4Bk+z!P|*JWfm?&$o~#o$o`*32Jg`a(f^sl`zArk zJ*4+?tPUx0q;el<09tdb18FBx89ls6DkF%ONV}2t;NG5~FZwYAof&3aR7S8rntR5w z{|?q{Jo}-H*Dw~Mb_Op3IIMoev6)~N_!xWw80S$L=TYZ!elb`Az68{je%2hgov!}E z`Q6|*u#aO0KomFx;sN8YY9dGie}JptIf+a_kR|U1i3R%5b+T2n5pd)iyHp z`Wz1i4Z;23K|l|t{s?FSnt>MJaquK~iF;oLuYew)7w7|C1APJS70~aSL%(kh{k}O! zSUM7xj)bKnVHu`nok}{F{qM+c71!(rksLb&jvyCLi8}bcR_JpZVoPuQ=|Or5%A%YC z^uM?)$|*ws3y_XtGq!Bawu~t|k;-U9#*#ze@-X0yKH#`f0;fDsya0+9K=A@7?t$VS zsO*8d9&}K~i5~Q?2+9_iG2#XGb2(l}O8kd@6{Ax{=u{CpRYXla)YL;wJ=C;-8hWTz z0ktZoR>firdJ|Y?SnA(M2G75(pLS3M0g27R;eM&$icUWuqI?a%H0%Irxh#bRz)W2vi1< z4&lCGU;<^dJyD2t*G8(StzrAP_wWL=OU?q8)h;MBW3D_rSkcH5qx^ zk>5b5YDabhp{$)R`vRaW(Kqcz?)6$Xj$PnbCi}Uhg@860avO-;1~St^fPNQkxx2wV zK*nOccY^E&BD;aeZXmK7i0lR;yMf4VAhH{X>;@vcfyizkvKt78WE3tVa2b6|YnQE0 zB_GC3kj20mxJdyA*B8k}|;n*tVFa~b%eIeUPz#Es@k-Z~uA{H*3gZeR0ew7&| zcOrcOiZUu=M#e*E3o!-b;Xj(QkzAOrf;dSr?a@3mE-1DTJ zNPCddUPs%q(Xwo6nT3{RE1~p#Fd{;&E>WvX)anwo%A!_sghr0eWT9!<)GUjdT}Boz zp=sIFPL9rGp=H@_8oeiYz66=+gKu6g8|N3MC$qzIZ6 zL6ahAQUpDu)yabnMbJT7mLlq0M4gMMa~^dr;t6@Y-Px1KsTb%22Ga67Na_T#f6v9f zhwTDDlqQNn3An(77uZYo47?rkZxiYH}ScL z*j%=_+x>Yu5Sb}vb!8(;-ol3Ayl1?R9n-Z)|318&> zbu6Vftz0>tQa*+v$4|<~OUlPcYSE)m7Y+EQagtQdrGadsHQq*3O3;*Qpf-36tYKW^ zuVW^gjc9cX*b06I+rWOV`ya+j)IYiR8n{7k0Gdi~Y#zO_c^Vo^Z)_gDv3c~q=F$6_ zNAGJMy{~y%f52O1+CadYW%R!0(fgW5?`xhW$5_^p*CrsxR*sR%@fA6?BF9n6$51Mc zpH!j8K#rjVk=7&qx3QD1T-ObB2R#9N&|d|wgNoxSgV~p3D{{TR(K=%F9LV@#9 zjHyI1LUs;IbR3JDEPkiAK?AyxtjM=$NsUQteN-%x=4N0E^Jvsj->04kZ*9-?^ z*be3RY{mfQfKS0ZFdzJXJvKn}r_!IqJEtC%2vCKKymRVNSA#Y5Ppt(%fOX(UaHltc z%Et|U<(@qNZ9pockjg0aAUF(;f@lDpRNfh6Y$%Gcp(w_NqSUkC97qNg-zxh5-xxv^ z5}sK$hLFiSrye9d3Q5mI(xb}85u&tP;|Nt5N2tm;LRIaOsRdDGV+m1=bwz1%Ea6X% zUjqj3P%1zL@(rp0Qu!9u?PCg2`h7@r1JDRO03HGlgGWJA&>TDl=*Q$8QmIil0TNgU(!aBRq zRTsMILPuTbsPtO0JrTfDE}^5+OI^Y{?dEBh&{r2v3qVI*=%@5fzoDbjGhO1z7kF|2 zy6Qq#UFfLvOqVD{0D9s=Ph9AU3q5h6CobgQh5Wmae;4xaLjGOIzYFO!Vm$de1p>B4flu$(UB#f6NxkP#O$;zB;8ce{kubird6Ja)lj z7d&>sV;4Mj!DAOZc3~M^@X-YyUGPwP!%OhZ1+oL=kCV(ZCgBCRA~m^!GPX zi8ioU(7lbp7rWH@B`{R@D#M9J#u*=}JJH%*NOL2wUTOj0jbNe;q#YC?6*WLjPz&(h zDp5uhQAQL|MiixS5otsbX+()eW#d8~N>fZ}X#Wur$;ghlkP^Wk-iE8qlV!9fqqCmu zzagc8H`*$W72O&ik|XY8t_1E%5dPdXnmdl&cE?|?HtUv5 z-S9GC4)_$z1M`h!>XuC1lBruVBV;e|M(m5A3+M`Z8=>e|n0Vc&B?jOFm$LmG*b9z> z81TChhCYSi`$EyDF!U)5T?#{g!qA^E^e0R?Xw*V?!qA;CbSDhm2}5_n@G+r8IiW;3 zp+q^ML^+}8QyBUbhCYR%Phsd&82S{3K82xAVdzsB`V@vfg`rPj=u;T_6ox+uRj+{? zMyO^nYH7Z}A5;ca!Ac_xn;uHk5{ll1Var3&y)bkyOpE2bozw{mfMJB8e_`lf7&bZ- z9Sp-phoXaF=wKK+7^Xi1o(1hd2k<=T1iErvH_#pQ1kjMkC6ve|6#WcCKf}<^Fzjq7 zIvR$4hGADj(a|t;G)zALt?yE>6v{aw)Fj$0=aHOZ@CR?L27&5WkQzkyFJmd*C!I<3 zI*aX((XV)L5!e9Z1iFmNWp3HzRzPlf1Hw4ctgxLxtHC}nV|8(Z=i)@U&Gu0*{pl)eSDJ;!$tm571m zcLV{{SAI+I5@W5e8Rtb`Quz(RI4C`hUZGjWYHD_nnnh8wc(IT3k&M(uarYrOa~KXB zqYp3I_>Ed#rj{qEWeT;7R=$A4sm4jTcoHtg(wor8*v1pw&@NppgXX)DjXhA*D=){9 zk-Ol+QRr|28pKn#S#V)Eb(=%oM!?53>Q<->VSH{FW9MU;D}9`CTuEXqFB=*4<4$js z;g1dk<44+%4kaB9#vwx*HFfd)T<-B;SG{i%?dHBrDD2^$0`B1(LF9usija}TNPaaU zczP8n-2iB@n-ZQdcEY`6?%P92FLQ4MQk1~`$GLwsC6-d1MLwr^_9^l@3FY0;!$C>y z&?5)_58zCav74iX94+8z5p}qL@5yKO^)B5168bFrI)@OK45N(nOWpjYVIKdhwJ&kc ztkPtGor4F_NLFzPm~0=b?}86uGDnaK4A$aQ1ndODQ*2+ECsaw*95EaW;2xt2DKf7Qx2%2K(1^O%uEN&ohv6lFhSvvH1cn?Fh`(B7Lr!)DCoNQpfD*PoGR z#2dwE8$Yf%ZMcnjL?`kmXEPDhM;P7-%A|Nt5f_fAYTa9~3P6 z85?eunEP%XFF*g^r$+d{U+blZAtO}thtA8nO7Hml=dzSjwc>3RYj^8-`Eza^`S&d^ z<-OP4$`!e&NWa2=&j)H2-RUZ%@?U@6JH1b=_}stT7X|<83!j z8g_chg+bq&JY+cVX8-li;J;ECKa^i?&>L@@XMMpKZ5%ZCE(=>$jqf2g8}tjn_p072 zc@oksX<^(8+@_q5Dm%CO&eSb`#@|yT7tdt=cw^>oKjSC#`6r_VrJ85-HTK}21$H~g z*k-jt_>Tg9c4@l~IpL*-r zcfRt!If_j|(^$*54+Zotw_IhE{%`W|UV{`k%$!U+hZG zcJxj$Nd=Fv)7X3GC)2JJ)a|nIv(!xEN7@43Uv<+jCfw;R<3#Cu<@qto=&cx370Zax zeYmGGiy}Q8?H-wvMr8ajadH#dEdG3p*_LCS_+sW>W+3XqJVbH^qI%}sL-ozMhj=fY zrI8rO{EPRSvkpCE&N|eX`G$6qlbmCyDKiWmWF8_plVWq;VL3+|Kbhrm-eE~$4g@Rj zuskU;Xxp@8wp1t2WNe!6fPZIc&pbodX)lxtLp&$vP3C_P%bA8cn==i)V9qr3q9W%Q z>T1q0^olvhP)~D?pdH)j_bVa_fz(wtrBZF6>^vF7YT6lKmFbl99Z=!iLU&{1>dpkvH#m(AQma{i#>=KMi1 z=KMh?%=v>(n)3&pGUpG9HRlgXG3O6THRlhqn)3&xnezu-H0KXWXZE`qB7+(5Y6=^( z;MEeD%!F54Tw*r7x+04i@#>3gbB-b2FVr3p4mqz7vsg2)5c3c*uaGdzd4*JSULj4B z^9uQy^9ofq=M}1A&MQ>ioL8u!Ij>M7b6%nQ&3T0$Fy|F|Q2uWKrLj4q(BtNeLQgTH z&?)5^b1tFh%(;X*nsW(tGUpQNY|bV0k~x=94|6V|p3Eh5P3isr+B@?&Es8Ub*YUi= zTrk7Hz%X3HrHIN69^e5ADlniRpeRJ-@Zu8C>_*r1i0DVxc;O0|>|!)B2jhAJA|eWM zE8e26f)Fo^2O&gIV82iG^m`y=vnKy#yFdNBPghk}S5-gtbag%T{+@s$^s|5>G&Z0J zO$aDLmjo1{O9P6~)PN#1C!h$;4Jbkj*i654w;d3RML}p~nKE(BlD7=*fU6 z^i)6;dL|$WEeeQ2ivyz2vVbV`d_WX>As`B^2#7)}1ESEXfGD&kAPTJwh(hZEqR?vr zQRsD90iw_wAPTJqX-Khz{ySg^eHgHWJ_=YuTLPBQ)_^7SaljJV7O;evgRnD0|7;Ta zXOqxBTZR7FivHP-zIp_EGcdo7ynKCG;=QIO$*AnL$)s zv3jfuIe|1MvNs2Ts28Y{z1fREB07n0%#+#c)93q9g8uAv=>2DaP^tYtJM@2{{|`k+ z3}g48key2!#UU#Wx*!K#a3NoHquF!N3S%g}qLI}JdcmR>9>;$21iJ&D@=40}6uS$W zA}44H37Vo#&=h4sM--tUKBV5;*~`!qpFmYplm<-!<`8?Gpeb6SDfXL|Xo~|_TvT7Q z4EmyF&=(GUQNqk?6Whczx24#abI=_fN!iJEGOcZA^hhasq?;+S-EDVJih6)smKStN zUeGCdXp_^3JssS#hCz>5^vH!=HJX)jMRp9hWeo#vSra>p{{*%Q=w(gpZD^TRLCdrX zTBc3VGIh~1TTENK)owK{&^0@lZTZrE$y_b}SA$nnvlc<`vBjcvXFdReR1Ya*Ig0nALmEEy2TZ7FeCn!Y_48;hzI3t$|zSmXVL* zr8RKN-Ew$EO>5v*xE1hGf&aH!A@7BX_ za2wz^x{dI!;8h{vUIlk8+iiB6DW_`5+@K}%f|e`^TCyZ)$&#QYOYlmtla#yME~t7Y z5O6}jGm902v)#9L4i-T5GEK&X|7_@4=pjC5& zR?Q7sH8*J0+@Mu+gI3KATD2)!wKe~SYvbGCMXN1{UiqMpwlnqp5uO#ais%O4-m{Wc zaoylMpoI(3!kw{wckx|J8{ZX;To5!e|L{X27pO)ic7mT^TKI|nGSgP|G9lo-k$#q+ zWgNJsx0nRDrniAGdOIj$s;PfP_?`Yv(+rf;yNJEp-_0Fo``Osj@AvnUa*m$^uGm~Z zmzvJ=^SJ5(R$><6U*R|K^Zk4ys^xKn0(u-Z0zD4C#@CSBqxe*4?Vs>Zm|R6iCC{f> zz1a?oRHO);)J5EPv0qG@C4LF%m-z_$cR6=_!6Pkx1&CDjz)pRUJHCW(g)G0)uQb`b zEnem>tNm&`Dz5QsOk=R<)^hiCejNx_>pjxqH~0;vls5`?Jg`^aFirKn0tKTEy4i20 z{O|EE#T@@WYYUq2j`;|>)o-OnAG4y=`E7n1ciir`Q#Nqy$ny*Tg=vlth8@4+!4{7N70+p);z5g~$kYKZwt;CU4Oz*MBgL#~Z6}TRmt>AKW^HRb zDUlNR7OZV`(o$NQEGd&R_*T*izBOxIowSiQ@NHT1>hQ_a4*m$%zB)Nlj)ZT|8dxVs z$x-kfSPSdqXgM1G7}mr(IaZE^@5tI%hc};2@SRyB>!gcxf$u6^;k!vU`0mmjzK8UH z?v=*>kyGGLl~dvSNFVsV z(ii?TISu}FIUT;A^n)KD18A#(GLTjpB!l3~r5t{+42B;fL*UPrv*FK?bKr-{Q21fO z8%oZVbK!@}aQG220)C{7ga>O7$|wPU(~J_J(?HbAmn&Jbkt5SV*2|X}{C_k@W`eMn zFIVwD(i|N_u-f<IhZX_IpLRKMzP{>ttWDc=&SwHM# zo-po~2jl_j^`H24ws;DfPZ_{0#DCu-@`!0B3uFN@P$3n>f?o)&ks5M%R30TyPz<4< z7~h zStYCBUzV3mQ^h_s^<}NBWtGS}Sx0W`LH8=qv5WpQ7L>079lMwoI(9K_bnF5T4kF>; zAd&_gM7{(pHT+ZBtZr(4x0LsC>7l+;eiWu(CayL#`fZa;qvv`kT30S3m`03N@>6pd zAst_HltXv@O>MwLGj0LXoFL`~7%$~Oi=nmiGpVFMnTyMPxC~sfL=hLhLl2kuN8wr2 zU0Wx$X*+~KbMdxWb@|8HAk zz8l(-sEBU^W;__vM@RZ~8WwMLNs&3fQ4+2(Tpw-C;-rWDjZ)}!diVG`O`d+I!(N_@ z(A1e_Nk(NbF34U)Ga~-ZC;GJGP3KcmdrJ1>c$KAi&qZ_Tp3hfH`X1@5sNY7{slJN$ z1o}$%9QG`(iw~92^dr)Fsuwbk^fW2CPL(gkwMnrDadBT$U7$TUKGKshT1Go(9@-=0 zBbPcH>S#ooeCnp!ydZgK&Z*X{%kxj|hmxLbWGdQqK1=t;wO7R9nq#~jDlCpm{YI&x za~%1FJ(B$rqlc&?l_DD5Wn|_omKZGd9)BCMmtCs7!4e^|x#^c%;#zJhha$ z_F{LBk;C{)IWwvo{!)ratF5jQnoUdArQ`)@3+%s?H};0Yj7*7`Emg;JM{>pEkcxo6zC$bObf?La>W^kagjo6n|d>{rv2?wT=q+%&Uy#*EHgtbum5Sk6h6{IcNDf)@)uDJ(1;RCrP0%)(m>=M_FxxVwJC`V;FfEUH&Dsp$Hm$BJI(O1(Op z+1I^hul>|rX+L$b)~;a&uB+?9Y+QT$iT%CZZnxQwnZMg&Ke8V( zr}u$2H{Jc*4aM)$4rcoPV860o<8k&| zyAvNwyYRrY+y2>pXZP5>_Io@r?X&x7U@QBb!xs}yv0WD4n6mN3lo4}>-@j^>-`P>Mt_t4rN5a0j(&M=kd1f^epNQfYkYgYA#ciC@-|+C z-<8esp1dy~@D=)@d?Z`&EBvu+lkM_*`9wao2ly`ioUhUy@}>MizLKxy8@^6=;vs4m z->18ANiBF$&XPaN9@#5DxKi0C-@ANQl*miyTloLIGR^%5^vaa#`5%}a?#iFi$K7~0 z!*|v`?mO9SQ7>1?)t(+nFCHY`iF&+zK%f6cCAhZd?^St?dpusZO_1B2NbDhde!8YO zq!wt52Dths_xl_FFFpTn?)N|L_3zTZwUtE_G9$n?({ydJwCHvyOLzj zZj{!yckqrvYd)vNPoch}Vw%m?# z*WyPx&7-rMk2UAF?jiTE`<;8lEpQdC5}Qua!*j~JvwIqw&Jyf5%dpj~z%H{Y_;p{8 zt>snsntQ{&<=(-{@;;v4KXO~~{``si46n~$;_>+#Y%063rR>3Ovd+5=-2v5#zXS!{!Rb3f0r5jubG4YBeUq)QjfXu>zH-DNp4AGC-_$~ z@9iu`3>{2gp4xPtla7yd3}Ja%+PC!!!}6?C;s2BtJ~%D>qExusnij4e`)c#?ucU={ zP7B|Z7G9DHm$SksslqIzP;KpzjCPXxhB9WkvG_{7*o|`+1gHHaV1R0(t2)Xp*w{Rmu*a##nsf&-jTX0e@p zmKkl0%gpyyO@-}1^SuRHf$e~Nu^MQ;4?q`kXdd_RTj}1`oWh+n{NUXFP1DGk8slz< zR!DznwR;a*CBK2HkK1gm8MEn{->0EukHM=a&=BK34>3DJj9RH{I4FVNqT!;pYOG$2 zM57tBw(eUEcYh4&v3QvpxgT2L?u1q`!YyP}+=AJG4%p*+GEeUbt#o(mRaiAh@Awx4 zWgP^qcK1T7unoj5x&*EgImjiSMy8qDujdG|w&+s$8hJ3Jtu4LR@7PM88{(H~JcpLP zUIg277|mFuwC!oK<2=AO<@e zS7)@6$_VQ)LhNRZ#lE6XdL|V42xZij4VBm-wA7h$qLNUFwM$Dj4_bk>OIu5yX_aV5 zB!3IwBKgz0$MRPl>aJ%8=c{$9#A>Da{uWw+)k;g%3tA<=hDP~@mI-pF?HTS6`gKxj zj8DgT^Zq;yXIGSI&JnanWcZKweG*;$7!ODYH9n>!R zJSwq@Y5A!oKNz*l0u(z2p|{Ly+IxMP#tF-Z>VCb8+Qu98#fRDV^-8PIC? zKD0{y1G+FhrJP4drCbE9kx|eJxe!_{W1v+TDbFXQQpQ4SLMmk{v_>w2R>&35YMBhhT8Iw*9h}N~eOAmI#rxxER^TOA z5!4<1)|2%<;7YN^2QOfZf*LUjD#tD|gt3pV=(_+trDL8B<_7j-%uVdaGX9yxx+3+W z+=&s;9q6$+<^gblHnI2Mp0)2NBqYo+Xsf1;dFVbe8M_vY)a;p+so|Xnb%E>g#Lz=U#_J8cb>;uwL zb|5yNT9*+nb}4DFE5ogT(~^i)*;Y>PG}7D$m#m#tU(c2nOAnhG!qj(kDjj~5+40|; zY=dU3n>j|kBPT<03F+uM5#ngoA!#u!Sf$gC)jj>)neHriiM!NY<}PFL@0nw}Iq5!IZjT#Yt`%dtHm)scQYlJ#3MZRi;Pri`JH?&q`nbOCG - * by Khronos client API header files that use its types and defines. - * - * The types in khrplatform.h should only be used to define API-specific types. - * - * Types defined in khrplatform.h: - * khronos_int8_t signed 8 bit - * khronos_uint8_t unsigned 8 bit - * khronos_int16_t signed 16 bit - * khronos_uint16_t unsigned 16 bit - * khronos_int32_t signed 32 bit - * khronos_uint32_t unsigned 32 bit - * khronos_int64_t signed 64 bit - * khronos_uint64_t unsigned 64 bit - * khronos_intptr_t signed same number of bits as a pointer - * khronos_uintptr_t unsigned same number of bits as a pointer - * khronos_ssize_t signed size - * khronos_usize_t unsigned size - * khronos_float_t signed 32 bit floating point - * khronos_time_ns_t unsigned 64 bit time in nanoseconds - * khronos_utime_nanoseconds_t unsigned time interval or absolute time in - * nanoseconds - * khronos_stime_nanoseconds_t signed time interval in nanoseconds - * khronos_boolean_enum_t enumerated boolean type. This should - * only be used as a base type when a client API's boolean type is - * an enum. Client APIs which use an integer or other type for - * booleans cannot use this as the base type for their boolean. - * - * Tokens defined in khrplatform.h: - * - * KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values. - * - * KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0. - * KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0. - * - * Calling convention macros defined in this file: - * KHRONOS_APICALL - * KHRONOS_APIENTRY - * KHRONOS_APIATTRIBUTES - * - * These may be used in function prototypes as: - * - * KHRONOS_APICALL void KHRONOS_APIENTRY funcname( - * int arg1, - * int arg2) KHRONOS_APIATTRIBUTES; - */ - -#if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC) -# define KHRONOS_STATIC 1 -#endif - -/*------------------------------------------------------------------------- - * Definition of KHRONOS_APICALL - *------------------------------------------------------------------------- - * This precedes the return type of the function in the function prototype. - */ -#if defined(KHRONOS_STATIC) - /* If the preprocessor constant KHRONOS_STATIC is defined, make the - * header compatible with static linking. */ -# define KHRONOS_APICALL -#elif defined(_WIN32) -# define KHRONOS_APICALL __declspec(dllimport) -#elif defined (__SYMBIAN32__) -# define KHRONOS_APICALL IMPORT_C -#elif defined(__ANDROID__) -# define KHRONOS_APICALL __attribute__((visibility("default"))) -#else -# define KHRONOS_APICALL -#endif - -/*------------------------------------------------------------------------- - * Definition of KHRONOS_APIENTRY - *------------------------------------------------------------------------- - * This follows the return type of the function and precedes the function - * name in the function prototype. - */ -#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__) - /* Win32 but not WinCE */ -# define KHRONOS_APIENTRY __stdcall -#else -# define KHRONOS_APIENTRY -#endif - -/*------------------------------------------------------------------------- - * Definition of KHRONOS_APIATTRIBUTES - *------------------------------------------------------------------------- - * This follows the closing parenthesis of the function prototype arguments. - */ -#if defined (__ARMCC_2__) -#define KHRONOS_APIATTRIBUTES __softfp -#else -#define KHRONOS_APIATTRIBUTES -#endif - -/*------------------------------------------------------------------------- - * basic type definitions - *-----------------------------------------------------------------------*/ -#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__) - - -/* - * Using - */ -#include -typedef int32_t khronos_int32_t; -typedef uint32_t khronos_uint32_t; -typedef int64_t khronos_int64_t; -typedef uint64_t khronos_uint64_t; -#define KHRONOS_SUPPORT_INT64 1 -#define KHRONOS_SUPPORT_FLOAT 1 -/* - * To support platform where unsigned long cannot be used interchangeably with - * inptr_t (e.g. CHERI-extended ISAs), we can use the stdint.h intptr_t. - * Ideally, we could just use (u)intptr_t everywhere, but this could result in - * ABI breakage if khronos_uintptr_t is changed from unsigned long to - * unsigned long long or similar (this results in different C++ name mangling). - * To avoid changes for existing platforms, we restrict usage of intptr_t to - * platforms where the size of a pointer is larger than the size of long. - */ -#if defined(__SIZEOF_LONG__) && defined(__SIZEOF_POINTER__) -#if __SIZEOF_POINTER__ > __SIZEOF_LONG__ -#define KHRONOS_USE_INTPTR_T -#endif -#endif - -#elif defined(__VMS ) || defined(__sgi) - -/* - * Using - */ -#include -typedef int32_t khronos_int32_t; -typedef uint32_t khronos_uint32_t; -typedef int64_t khronos_int64_t; -typedef uint64_t khronos_uint64_t; -#define KHRONOS_SUPPORT_INT64 1 -#define KHRONOS_SUPPORT_FLOAT 1 - -#elif defined(_WIN32) && !defined(__SCITECH_SNAP__) - -/* - * Win32 - */ -typedef __int32 khronos_int32_t; -typedef unsigned __int32 khronos_uint32_t; -typedef __int64 khronos_int64_t; -typedef unsigned __int64 khronos_uint64_t; -#define KHRONOS_SUPPORT_INT64 1 -#define KHRONOS_SUPPORT_FLOAT 1 - -#elif defined(__sun__) || defined(__digital__) - -/* - * Sun or Digital - */ -typedef int khronos_int32_t; -typedef unsigned int khronos_uint32_t; -#if defined(__arch64__) || defined(_LP64) -typedef long int khronos_int64_t; -typedef unsigned long int khronos_uint64_t; -#else -typedef long long int khronos_int64_t; -typedef unsigned long long int khronos_uint64_t; -#endif /* __arch64__ */ -#define KHRONOS_SUPPORT_INT64 1 -#define KHRONOS_SUPPORT_FLOAT 1 - -#elif 0 - -/* - * Hypothetical platform with no float or int64 support - */ -typedef int khronos_int32_t; -typedef unsigned int khronos_uint32_t; -#define KHRONOS_SUPPORT_INT64 0 -#define KHRONOS_SUPPORT_FLOAT 0 - -#else - -/* - * Generic fallback - */ -#include -typedef int32_t khronos_int32_t; -typedef uint32_t khronos_uint32_t; -typedef int64_t khronos_int64_t; -typedef uint64_t khronos_uint64_t; -#define KHRONOS_SUPPORT_INT64 1 -#define KHRONOS_SUPPORT_FLOAT 1 - -#endif - - -/* - * Types that are (so far) the same on all platforms - */ -typedef signed char khronos_int8_t; -typedef unsigned char khronos_uint8_t; -typedef signed short int khronos_int16_t; -typedef unsigned short int khronos_uint16_t; - -/* - * Types that differ between LLP64 and LP64 architectures - in LLP64, - * pointers are 64 bits, but 'long' is still 32 bits. Win64 appears - * to be the only LLP64 architecture in current use. - */ -#ifdef KHRONOS_USE_INTPTR_T -typedef intptr_t khronos_intptr_t; -typedef uintptr_t khronos_uintptr_t; -#elif defined(_WIN64) -typedef signed long long int khronos_intptr_t; -typedef unsigned long long int khronos_uintptr_t; -#else -typedef signed long int khronos_intptr_t; -typedef unsigned long int khronos_uintptr_t; -#endif - -#if defined(_WIN64) -typedef signed long long int khronos_ssize_t; -typedef unsigned long long int khronos_usize_t; -#else -typedef signed long int khronos_ssize_t; -typedef unsigned long int khronos_usize_t; -#endif - -#if KHRONOS_SUPPORT_FLOAT -/* - * Float type - */ -typedef float khronos_float_t; -#endif - -#if KHRONOS_SUPPORT_INT64 -/* Time types - * - * These types can be used to represent a time interval in nanoseconds or - * an absolute Unadjusted System Time. Unadjusted System Time is the number - * of nanoseconds since some arbitrary system event (e.g. since the last - * time the system booted). The Unadjusted System Time is an unsigned - * 64 bit value that wraps back to 0 every 584 years. Time intervals - * may be either signed or unsigned. - */ -typedef khronos_uint64_t khronos_utime_nanoseconds_t; -typedef khronos_int64_t khronos_stime_nanoseconds_t; -#endif - -/* - * Dummy value used to pad enum types to 32 bits. - */ -#ifndef KHRONOS_MAX_ENUM -#define KHRONOS_MAX_ENUM 0x7FFFFFFF -#endif - -/* - * Enumerated boolean type - * - * Values other than zero should be considered to be true. Therefore - * comparisons should not be made against KHRONOS_TRUE. - */ -typedef enum { - KHRONOS_FALSE = 0, - KHRONOS_TRUE = 1, - KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM -} khronos_boolean_enum_t; - -#endif /* __khrplatform_h_ */ diff --git a/extern/glad/include/glad/glad.h b/extern/glad/include/glad/glad.h deleted file mode 100644 index e43afbd..0000000 --- a/extern/glad/include/glad/glad.h +++ /dev/null @@ -1,4133 +0,0 @@ -/* - - OpenGL loader generated by glad 0.1.36 on Sat Apr 12 17:00:07 2025. - - Language/Generator: C/C++ - Specification: gl - APIs: gl=4.1 - Profile: compatibility - Extensions: - - Loader: True - Local files: False - Omit khrplatform: False - Reproducible: False - - Commandline: - --profile="compatibility" --api="gl=4.1" --generator="c" --spec="gl" --extensions="" - Online: - https://glad.dav1d.de/#profile=compatibility&language=c&specification=gl&loader=on&api=gl%3D4.1 -*/ - - -#ifndef __glad_h_ -#define __glad_h_ - -#ifdef __gl_h_ -#error OpenGL header already included, remove this include, glad already provides it -#endif -#define __gl_h_ - -#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) -#define APIENTRY __stdcall -#endif - -#ifndef APIENTRY -#define APIENTRY -#endif -#ifndef APIENTRYP -#define APIENTRYP APIENTRY * -#endif - -#ifndef GLAPIENTRY -#define GLAPIENTRY APIENTRY -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -struct gladGLversionStruct { - int major; - int minor; -}; - -typedef void* (* GLADloadproc)(const char *name); - -#ifndef GLAPI -# if defined(GLAD_GLAPI_EXPORT) -# if defined(_WIN32) || defined(__CYGWIN__) -# if defined(GLAD_GLAPI_EXPORT_BUILD) -# if defined(__GNUC__) -# define GLAPI __attribute__ ((dllexport)) extern -# else -# define GLAPI __declspec(dllexport) extern -# endif -# else -# if defined(__GNUC__) -# define GLAPI __attribute__ ((dllimport)) extern -# else -# define GLAPI __declspec(dllimport) extern -# endif -# endif -# elif defined(__GNUC__) && defined(GLAD_GLAPI_EXPORT_BUILD) -# define GLAPI __attribute__ ((visibility ("default"))) extern -# else -# define GLAPI extern -# endif -# else -# define GLAPI extern -# endif -#endif - -GLAPI struct gladGLversionStruct GLVersion; - -GLAPI int gladLoadGL(void); - -GLAPI int gladLoadGLLoader(GLADloadproc); - -#include -typedef unsigned int GLenum; -typedef unsigned char GLboolean; -typedef unsigned int GLbitfield; -typedef void GLvoid; -typedef khronos_int8_t GLbyte; -typedef khronos_uint8_t GLubyte; -typedef khronos_int16_t GLshort; -typedef khronos_uint16_t GLushort; -typedef int GLint; -typedef unsigned int GLuint; -typedef khronos_int32_t GLclampx; -typedef int GLsizei; -typedef khronos_float_t GLfloat; -typedef khronos_float_t GLclampf; -typedef double GLdouble; -typedef double GLclampd; -typedef void *GLeglClientBufferEXT; -typedef void *GLeglImageOES; -typedef char GLchar; -typedef char GLcharARB; -#ifdef __APPLE__ -typedef void *GLhandleARB; -#else -typedef unsigned int GLhandleARB; -#endif -typedef khronos_uint16_t GLhalf; -typedef khronos_uint16_t GLhalfARB; -typedef khronos_int32_t GLfixed; -typedef khronos_intptr_t GLintptr; -typedef khronos_intptr_t GLintptrARB; -typedef khronos_ssize_t GLsizeiptr; -typedef khronos_ssize_t GLsizeiptrARB; -typedef khronos_int64_t GLint64; -typedef khronos_int64_t GLint64EXT; -typedef khronos_uint64_t GLuint64; -typedef khronos_uint64_t GLuint64EXT; -typedef struct __GLsync *GLsync; -struct _cl_context; -struct _cl_event; -typedef void (APIENTRY *GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam); -typedef void (APIENTRY *GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam); -typedef void (APIENTRY *GLDEBUGPROCKHR)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam); -typedef void (APIENTRY *GLDEBUGPROCAMD)(GLuint id,GLenum category,GLenum severity,GLsizei length,const GLchar *message,void *userParam); -typedef unsigned short GLhalfNV; -typedef GLintptr GLvdpauSurfaceNV; -typedef void (APIENTRY *GLVULKANPROCNV)(void); -#define GL_DEPTH_BUFFER_BIT 0x00000100 -#define GL_STENCIL_BUFFER_BIT 0x00000400 -#define GL_COLOR_BUFFER_BIT 0x00004000 -#define GL_FALSE 0 -#define GL_TRUE 1 -#define GL_POINTS 0x0000 -#define GL_LINES 0x0001 -#define GL_LINE_LOOP 0x0002 -#define GL_LINE_STRIP 0x0003 -#define GL_TRIANGLES 0x0004 -#define GL_TRIANGLE_STRIP 0x0005 -#define GL_TRIANGLE_FAN 0x0006 -#define GL_QUADS 0x0007 -#define GL_NEVER 0x0200 -#define GL_LESS 0x0201 -#define GL_EQUAL 0x0202 -#define GL_LEQUAL 0x0203 -#define GL_GREATER 0x0204 -#define GL_NOTEQUAL 0x0205 -#define GL_GEQUAL 0x0206 -#define GL_ALWAYS 0x0207 -#define GL_ZERO 0 -#define GL_ONE 1 -#define GL_SRC_COLOR 0x0300 -#define GL_ONE_MINUS_SRC_COLOR 0x0301 -#define GL_SRC_ALPHA 0x0302 -#define GL_ONE_MINUS_SRC_ALPHA 0x0303 -#define GL_DST_ALPHA 0x0304 -#define GL_ONE_MINUS_DST_ALPHA 0x0305 -#define GL_DST_COLOR 0x0306 -#define GL_ONE_MINUS_DST_COLOR 0x0307 -#define GL_SRC_ALPHA_SATURATE 0x0308 -#define GL_NONE 0 -#define GL_FRONT_LEFT 0x0400 -#define GL_FRONT_RIGHT 0x0401 -#define GL_BACK_LEFT 0x0402 -#define GL_BACK_RIGHT 0x0403 -#define GL_FRONT 0x0404 -#define GL_BACK 0x0405 -#define GL_LEFT 0x0406 -#define GL_RIGHT 0x0407 -#define GL_FRONT_AND_BACK 0x0408 -#define GL_NO_ERROR 0 -#define GL_INVALID_ENUM 0x0500 -#define GL_INVALID_VALUE 0x0501 -#define GL_INVALID_OPERATION 0x0502 -#define GL_OUT_OF_MEMORY 0x0505 -#define GL_CW 0x0900 -#define GL_CCW 0x0901 -#define GL_POINT_SIZE 0x0B11 -#define GL_POINT_SIZE_RANGE 0x0B12 -#define GL_POINT_SIZE_GRANULARITY 0x0B13 -#define GL_LINE_SMOOTH 0x0B20 -#define GL_LINE_WIDTH 0x0B21 -#define GL_LINE_WIDTH_RANGE 0x0B22 -#define GL_LINE_WIDTH_GRANULARITY 0x0B23 -#define GL_POLYGON_MODE 0x0B40 -#define GL_POLYGON_SMOOTH 0x0B41 -#define GL_CULL_FACE 0x0B44 -#define GL_CULL_FACE_MODE 0x0B45 -#define GL_FRONT_FACE 0x0B46 -#define GL_DEPTH_RANGE 0x0B70 -#define GL_DEPTH_TEST 0x0B71 -#define GL_DEPTH_WRITEMASK 0x0B72 -#define GL_DEPTH_CLEAR_VALUE 0x0B73 -#define GL_DEPTH_FUNC 0x0B74 -#define GL_STENCIL_TEST 0x0B90 -#define GL_STENCIL_CLEAR_VALUE 0x0B91 -#define GL_STENCIL_FUNC 0x0B92 -#define GL_STENCIL_VALUE_MASK 0x0B93 -#define GL_STENCIL_FAIL 0x0B94 -#define GL_STENCIL_PASS_DEPTH_FAIL 0x0B95 -#define GL_STENCIL_PASS_DEPTH_PASS 0x0B96 -#define GL_STENCIL_REF 0x0B97 -#define GL_STENCIL_WRITEMASK 0x0B98 -#define GL_VIEWPORT 0x0BA2 -#define GL_DITHER 0x0BD0 -#define GL_BLEND_DST 0x0BE0 -#define GL_BLEND_SRC 0x0BE1 -#define GL_BLEND 0x0BE2 -#define GL_LOGIC_OP_MODE 0x0BF0 -#define GL_DRAW_BUFFER 0x0C01 -#define GL_READ_BUFFER 0x0C02 -#define GL_SCISSOR_BOX 0x0C10 -#define GL_SCISSOR_TEST 0x0C11 -#define GL_COLOR_CLEAR_VALUE 0x0C22 -#define GL_COLOR_WRITEMASK 0x0C23 -#define GL_DOUBLEBUFFER 0x0C32 -#define GL_STEREO 0x0C33 -#define GL_LINE_SMOOTH_HINT 0x0C52 -#define GL_POLYGON_SMOOTH_HINT 0x0C53 -#define GL_UNPACK_SWAP_BYTES 0x0CF0 -#define GL_UNPACK_LSB_FIRST 0x0CF1 -#define GL_UNPACK_ROW_LENGTH 0x0CF2 -#define GL_UNPACK_SKIP_ROWS 0x0CF3 -#define GL_UNPACK_SKIP_PIXELS 0x0CF4 -#define GL_UNPACK_ALIGNMENT 0x0CF5 -#define GL_PACK_SWAP_BYTES 0x0D00 -#define GL_PACK_LSB_FIRST 0x0D01 -#define GL_PACK_ROW_LENGTH 0x0D02 -#define GL_PACK_SKIP_ROWS 0x0D03 -#define GL_PACK_SKIP_PIXELS 0x0D04 -#define GL_PACK_ALIGNMENT 0x0D05 -#define GL_MAX_TEXTURE_SIZE 0x0D33 -#define GL_MAX_VIEWPORT_DIMS 0x0D3A -#define GL_SUBPIXEL_BITS 0x0D50 -#define GL_TEXTURE_1D 0x0DE0 -#define GL_TEXTURE_2D 0x0DE1 -#define GL_TEXTURE_WIDTH 0x1000 -#define GL_TEXTURE_HEIGHT 0x1001 -#define GL_TEXTURE_BORDER_COLOR 0x1004 -#define GL_DONT_CARE 0x1100 -#define GL_FASTEST 0x1101 -#define GL_NICEST 0x1102 -#define GL_BYTE 0x1400 -#define GL_UNSIGNED_BYTE 0x1401 -#define GL_SHORT 0x1402 -#define GL_UNSIGNED_SHORT 0x1403 -#define GL_INT 0x1404 -#define GL_UNSIGNED_INT 0x1405 -#define GL_FLOAT 0x1406 -#define GL_STACK_OVERFLOW 0x0503 -#define GL_STACK_UNDERFLOW 0x0504 -#define GL_CLEAR 0x1500 -#define GL_AND 0x1501 -#define GL_AND_REVERSE 0x1502 -#define GL_COPY 0x1503 -#define GL_AND_INVERTED 0x1504 -#define GL_NOOP 0x1505 -#define GL_XOR 0x1506 -#define GL_OR 0x1507 -#define GL_NOR 0x1508 -#define GL_EQUIV 0x1509 -#define GL_INVERT 0x150A -#define GL_OR_REVERSE 0x150B -#define GL_COPY_INVERTED 0x150C -#define GL_OR_INVERTED 0x150D -#define GL_NAND 0x150E -#define GL_SET 0x150F -#define GL_TEXTURE 0x1702 -#define GL_COLOR 0x1800 -#define GL_DEPTH 0x1801 -#define GL_STENCIL 0x1802 -#define GL_STENCIL_INDEX 0x1901 -#define GL_DEPTH_COMPONENT 0x1902 -#define GL_RED 0x1903 -#define GL_GREEN 0x1904 -#define GL_BLUE 0x1905 -#define GL_ALPHA 0x1906 -#define GL_RGB 0x1907 -#define GL_RGBA 0x1908 -#define GL_POINT 0x1B00 -#define GL_LINE 0x1B01 -#define GL_FILL 0x1B02 -#define GL_KEEP 0x1E00 -#define GL_REPLACE 0x1E01 -#define GL_INCR 0x1E02 -#define GL_DECR 0x1E03 -#define GL_VENDOR 0x1F00 -#define GL_RENDERER 0x1F01 -#define GL_VERSION 0x1F02 -#define GL_EXTENSIONS 0x1F03 -#define GL_NEAREST 0x2600 -#define GL_LINEAR 0x2601 -#define GL_NEAREST_MIPMAP_NEAREST 0x2700 -#define GL_LINEAR_MIPMAP_NEAREST 0x2701 -#define GL_NEAREST_MIPMAP_LINEAR 0x2702 -#define GL_LINEAR_MIPMAP_LINEAR 0x2703 -#define GL_TEXTURE_MAG_FILTER 0x2800 -#define GL_TEXTURE_MIN_FILTER 0x2801 -#define GL_TEXTURE_WRAP_S 0x2802 -#define GL_TEXTURE_WRAP_T 0x2803 -#define GL_REPEAT 0x2901 -#define GL_CURRENT_BIT 0x00000001 -#define GL_POINT_BIT 0x00000002 -#define GL_LINE_BIT 0x00000004 -#define GL_POLYGON_BIT 0x00000008 -#define GL_POLYGON_STIPPLE_BIT 0x00000010 -#define GL_PIXEL_MODE_BIT 0x00000020 -#define GL_LIGHTING_BIT 0x00000040 -#define GL_FOG_BIT 0x00000080 -#define GL_ACCUM_BUFFER_BIT 0x00000200 -#define GL_VIEWPORT_BIT 0x00000800 -#define GL_TRANSFORM_BIT 0x00001000 -#define GL_ENABLE_BIT 0x00002000 -#define GL_HINT_BIT 0x00008000 -#define GL_EVAL_BIT 0x00010000 -#define GL_LIST_BIT 0x00020000 -#define GL_TEXTURE_BIT 0x00040000 -#define GL_SCISSOR_BIT 0x00080000 -#define GL_ALL_ATTRIB_BITS 0xFFFFFFFF -#define GL_QUAD_STRIP 0x0008 -#define GL_POLYGON 0x0009 -#define GL_ACCUM 0x0100 -#define GL_LOAD 0x0101 -#define GL_RETURN 0x0102 -#define GL_MULT 0x0103 -#define GL_ADD 0x0104 -#define GL_AUX0 0x0409 -#define GL_AUX1 0x040A -#define GL_AUX2 0x040B -#define GL_AUX3 0x040C -#define GL_2D 0x0600 -#define GL_3D 0x0601 -#define GL_3D_COLOR 0x0602 -#define GL_3D_COLOR_TEXTURE 0x0603 -#define GL_4D_COLOR_TEXTURE 0x0604 -#define GL_PASS_THROUGH_TOKEN 0x0700 -#define GL_POINT_TOKEN 0x0701 -#define GL_LINE_TOKEN 0x0702 -#define GL_POLYGON_TOKEN 0x0703 -#define GL_BITMAP_TOKEN 0x0704 -#define GL_DRAW_PIXEL_TOKEN 0x0705 -#define GL_COPY_PIXEL_TOKEN 0x0706 -#define GL_LINE_RESET_TOKEN 0x0707 -#define GL_EXP 0x0800 -#define GL_EXP2 0x0801 -#define GL_COEFF 0x0A00 -#define GL_ORDER 0x0A01 -#define GL_DOMAIN 0x0A02 -#define GL_PIXEL_MAP_I_TO_I 0x0C70 -#define GL_PIXEL_MAP_S_TO_S 0x0C71 -#define GL_PIXEL_MAP_I_TO_R 0x0C72 -#define GL_PIXEL_MAP_I_TO_G 0x0C73 -#define GL_PIXEL_MAP_I_TO_B 0x0C74 -#define GL_PIXEL_MAP_I_TO_A 0x0C75 -#define GL_PIXEL_MAP_R_TO_R 0x0C76 -#define GL_PIXEL_MAP_G_TO_G 0x0C77 -#define GL_PIXEL_MAP_B_TO_B 0x0C78 -#define GL_PIXEL_MAP_A_TO_A 0x0C79 -#define GL_CURRENT_COLOR 0x0B00 -#define GL_CURRENT_INDEX 0x0B01 -#define GL_CURRENT_NORMAL 0x0B02 -#define GL_CURRENT_TEXTURE_COORDS 0x0B03 -#define GL_CURRENT_RASTER_COLOR 0x0B04 -#define GL_CURRENT_RASTER_INDEX 0x0B05 -#define GL_CURRENT_RASTER_TEXTURE_COORDS 0x0B06 -#define GL_CURRENT_RASTER_POSITION 0x0B07 -#define GL_CURRENT_RASTER_POSITION_VALID 0x0B08 -#define GL_CURRENT_RASTER_DISTANCE 0x0B09 -#define GL_POINT_SMOOTH 0x0B10 -#define GL_LINE_STIPPLE 0x0B24 -#define GL_LINE_STIPPLE_PATTERN 0x0B25 -#define GL_LINE_STIPPLE_REPEAT 0x0B26 -#define GL_LIST_MODE 0x0B30 -#define GL_MAX_LIST_NESTING 0x0B31 -#define GL_LIST_BASE 0x0B32 -#define GL_LIST_INDEX 0x0B33 -#define GL_POLYGON_STIPPLE 0x0B42 -#define GL_EDGE_FLAG 0x0B43 -#define GL_LIGHTING 0x0B50 -#define GL_LIGHT_MODEL_LOCAL_VIEWER 0x0B51 -#define GL_LIGHT_MODEL_TWO_SIDE 0x0B52 -#define GL_LIGHT_MODEL_AMBIENT 0x0B53 -#define GL_SHADE_MODEL 0x0B54 -#define GL_COLOR_MATERIAL_FACE 0x0B55 -#define GL_COLOR_MATERIAL_PARAMETER 0x0B56 -#define GL_COLOR_MATERIAL 0x0B57 -#define GL_FOG 0x0B60 -#define GL_FOG_INDEX 0x0B61 -#define GL_FOG_DENSITY 0x0B62 -#define GL_FOG_START 0x0B63 -#define GL_FOG_END 0x0B64 -#define GL_FOG_MODE 0x0B65 -#define GL_FOG_COLOR 0x0B66 -#define GL_ACCUM_CLEAR_VALUE 0x0B80 -#define GL_MATRIX_MODE 0x0BA0 -#define GL_NORMALIZE 0x0BA1 -#define GL_MODELVIEW_STACK_DEPTH 0x0BA3 -#define GL_PROJECTION_STACK_DEPTH 0x0BA4 -#define GL_TEXTURE_STACK_DEPTH 0x0BA5 -#define GL_MODELVIEW_MATRIX 0x0BA6 -#define GL_PROJECTION_MATRIX 0x0BA7 -#define GL_TEXTURE_MATRIX 0x0BA8 -#define GL_ATTRIB_STACK_DEPTH 0x0BB0 -#define GL_ALPHA_TEST 0x0BC0 -#define GL_ALPHA_TEST_FUNC 0x0BC1 -#define GL_ALPHA_TEST_REF 0x0BC2 -#define GL_LOGIC_OP 0x0BF1 -#define GL_AUX_BUFFERS 0x0C00 -#define GL_INDEX_CLEAR_VALUE 0x0C20 -#define GL_INDEX_WRITEMASK 0x0C21 -#define GL_INDEX_MODE 0x0C30 -#define GL_RGBA_MODE 0x0C31 -#define GL_RENDER_MODE 0x0C40 -#define GL_PERSPECTIVE_CORRECTION_HINT 0x0C50 -#define GL_POINT_SMOOTH_HINT 0x0C51 -#define GL_FOG_HINT 0x0C54 -#define GL_TEXTURE_GEN_S 0x0C60 -#define GL_TEXTURE_GEN_T 0x0C61 -#define GL_TEXTURE_GEN_R 0x0C62 -#define GL_TEXTURE_GEN_Q 0x0C63 -#define GL_PIXEL_MAP_I_TO_I_SIZE 0x0CB0 -#define GL_PIXEL_MAP_S_TO_S_SIZE 0x0CB1 -#define GL_PIXEL_MAP_I_TO_R_SIZE 0x0CB2 -#define GL_PIXEL_MAP_I_TO_G_SIZE 0x0CB3 -#define GL_PIXEL_MAP_I_TO_B_SIZE 0x0CB4 -#define GL_PIXEL_MAP_I_TO_A_SIZE 0x0CB5 -#define GL_PIXEL_MAP_R_TO_R_SIZE 0x0CB6 -#define GL_PIXEL_MAP_G_TO_G_SIZE 0x0CB7 -#define GL_PIXEL_MAP_B_TO_B_SIZE 0x0CB8 -#define GL_PIXEL_MAP_A_TO_A_SIZE 0x0CB9 -#define GL_MAP_COLOR 0x0D10 -#define GL_MAP_STENCIL 0x0D11 -#define GL_INDEX_SHIFT 0x0D12 -#define GL_INDEX_OFFSET 0x0D13 -#define GL_RED_SCALE 0x0D14 -#define GL_RED_BIAS 0x0D15 -#define GL_ZOOM_X 0x0D16 -#define GL_ZOOM_Y 0x0D17 -#define GL_GREEN_SCALE 0x0D18 -#define GL_GREEN_BIAS 0x0D19 -#define GL_BLUE_SCALE 0x0D1A -#define GL_BLUE_BIAS 0x0D1B -#define GL_ALPHA_SCALE 0x0D1C -#define GL_ALPHA_BIAS 0x0D1D -#define GL_DEPTH_SCALE 0x0D1E -#define GL_DEPTH_BIAS 0x0D1F -#define GL_MAX_EVAL_ORDER 0x0D30 -#define GL_MAX_LIGHTS 0x0D31 -#define GL_MAX_CLIP_PLANES 0x0D32 -#define GL_MAX_PIXEL_MAP_TABLE 0x0D34 -#define GL_MAX_ATTRIB_STACK_DEPTH 0x0D35 -#define GL_MAX_MODELVIEW_STACK_DEPTH 0x0D36 -#define GL_MAX_NAME_STACK_DEPTH 0x0D37 -#define GL_MAX_PROJECTION_STACK_DEPTH 0x0D38 -#define GL_MAX_TEXTURE_STACK_DEPTH 0x0D39 -#define GL_INDEX_BITS 0x0D51 -#define GL_RED_BITS 0x0D52 -#define GL_GREEN_BITS 0x0D53 -#define GL_BLUE_BITS 0x0D54 -#define GL_ALPHA_BITS 0x0D55 -#define GL_DEPTH_BITS 0x0D56 -#define GL_STENCIL_BITS 0x0D57 -#define GL_ACCUM_RED_BITS 0x0D58 -#define GL_ACCUM_GREEN_BITS 0x0D59 -#define GL_ACCUM_BLUE_BITS 0x0D5A -#define GL_ACCUM_ALPHA_BITS 0x0D5B -#define GL_NAME_STACK_DEPTH 0x0D70 -#define GL_AUTO_NORMAL 0x0D80 -#define GL_MAP1_COLOR_4 0x0D90 -#define GL_MAP1_INDEX 0x0D91 -#define GL_MAP1_NORMAL 0x0D92 -#define GL_MAP1_TEXTURE_COORD_1 0x0D93 -#define GL_MAP1_TEXTURE_COORD_2 0x0D94 -#define GL_MAP1_TEXTURE_COORD_3 0x0D95 -#define GL_MAP1_TEXTURE_COORD_4 0x0D96 -#define GL_MAP1_VERTEX_3 0x0D97 -#define GL_MAP1_VERTEX_4 0x0D98 -#define GL_MAP2_COLOR_4 0x0DB0 -#define GL_MAP2_INDEX 0x0DB1 -#define GL_MAP2_NORMAL 0x0DB2 -#define GL_MAP2_TEXTURE_COORD_1 0x0DB3 -#define GL_MAP2_TEXTURE_COORD_2 0x0DB4 -#define GL_MAP2_TEXTURE_COORD_3 0x0DB5 -#define GL_MAP2_TEXTURE_COORD_4 0x0DB6 -#define GL_MAP2_VERTEX_3 0x0DB7 -#define GL_MAP2_VERTEX_4 0x0DB8 -#define GL_MAP1_GRID_DOMAIN 0x0DD0 -#define GL_MAP1_GRID_SEGMENTS 0x0DD1 -#define GL_MAP2_GRID_DOMAIN 0x0DD2 -#define GL_MAP2_GRID_SEGMENTS 0x0DD3 -#define GL_TEXTURE_COMPONENTS 0x1003 -#define GL_TEXTURE_BORDER 0x1005 -#define GL_AMBIENT 0x1200 -#define GL_DIFFUSE 0x1201 -#define GL_SPECULAR 0x1202 -#define GL_POSITION 0x1203 -#define GL_SPOT_DIRECTION 0x1204 -#define GL_SPOT_EXPONENT 0x1205 -#define GL_SPOT_CUTOFF 0x1206 -#define GL_CONSTANT_ATTENUATION 0x1207 -#define GL_LINEAR_ATTENUATION 0x1208 -#define GL_QUADRATIC_ATTENUATION 0x1209 -#define GL_COMPILE 0x1300 -#define GL_COMPILE_AND_EXECUTE 0x1301 -#define GL_2_BYTES 0x1407 -#define GL_3_BYTES 0x1408 -#define GL_4_BYTES 0x1409 -#define GL_EMISSION 0x1600 -#define GL_SHININESS 0x1601 -#define GL_AMBIENT_AND_DIFFUSE 0x1602 -#define GL_COLOR_INDEXES 0x1603 -#define GL_MODELVIEW 0x1700 -#define GL_PROJECTION 0x1701 -#define GL_COLOR_INDEX 0x1900 -#define GL_LUMINANCE 0x1909 -#define GL_LUMINANCE_ALPHA 0x190A -#define GL_BITMAP 0x1A00 -#define GL_RENDER 0x1C00 -#define GL_FEEDBACK 0x1C01 -#define GL_SELECT 0x1C02 -#define GL_FLAT 0x1D00 -#define GL_SMOOTH 0x1D01 -#define GL_S 0x2000 -#define GL_T 0x2001 -#define GL_R 0x2002 -#define GL_Q 0x2003 -#define GL_MODULATE 0x2100 -#define GL_DECAL 0x2101 -#define GL_TEXTURE_ENV_MODE 0x2200 -#define GL_TEXTURE_ENV_COLOR 0x2201 -#define GL_TEXTURE_ENV 0x2300 -#define GL_EYE_LINEAR 0x2400 -#define GL_OBJECT_LINEAR 0x2401 -#define GL_SPHERE_MAP 0x2402 -#define GL_TEXTURE_GEN_MODE 0x2500 -#define GL_OBJECT_PLANE 0x2501 -#define GL_EYE_PLANE 0x2502 -#define GL_CLAMP 0x2900 -#define GL_CLIP_PLANE0 0x3000 -#define GL_CLIP_PLANE1 0x3001 -#define GL_CLIP_PLANE2 0x3002 -#define GL_CLIP_PLANE3 0x3003 -#define GL_CLIP_PLANE4 0x3004 -#define GL_CLIP_PLANE5 0x3005 -#define GL_LIGHT0 0x4000 -#define GL_LIGHT1 0x4001 -#define GL_LIGHT2 0x4002 -#define GL_LIGHT3 0x4003 -#define GL_LIGHT4 0x4004 -#define GL_LIGHT5 0x4005 -#define GL_LIGHT6 0x4006 -#define GL_LIGHT7 0x4007 -#define GL_COLOR_LOGIC_OP 0x0BF2 -#define GL_POLYGON_OFFSET_UNITS 0x2A00 -#define GL_POLYGON_OFFSET_POINT 0x2A01 -#define GL_POLYGON_OFFSET_LINE 0x2A02 -#define GL_POLYGON_OFFSET_FILL 0x8037 -#define GL_POLYGON_OFFSET_FACTOR 0x8038 -#define GL_TEXTURE_BINDING_1D 0x8068 -#define GL_TEXTURE_BINDING_2D 0x8069 -#define GL_TEXTURE_INTERNAL_FORMAT 0x1003 -#define GL_TEXTURE_RED_SIZE 0x805C -#define GL_TEXTURE_GREEN_SIZE 0x805D -#define GL_TEXTURE_BLUE_SIZE 0x805E -#define GL_TEXTURE_ALPHA_SIZE 0x805F -#define GL_DOUBLE 0x140A -#define GL_PROXY_TEXTURE_1D 0x8063 -#define GL_PROXY_TEXTURE_2D 0x8064 -#define GL_R3_G3_B2 0x2A10 -#define GL_RGB4 0x804F -#define GL_RGB5 0x8050 -#define GL_RGB8 0x8051 -#define GL_RGB10 0x8052 -#define GL_RGB12 0x8053 -#define GL_RGB16 0x8054 -#define GL_RGBA2 0x8055 -#define GL_RGBA4 0x8056 -#define GL_RGB5_A1 0x8057 -#define GL_RGBA8 0x8058 -#define GL_RGB10_A2 0x8059 -#define GL_RGBA12 0x805A -#define GL_RGBA16 0x805B -#define GL_CLIENT_PIXEL_STORE_BIT 0x00000001 -#define GL_CLIENT_VERTEX_ARRAY_BIT 0x00000002 -#define GL_CLIENT_ALL_ATTRIB_BITS 0xFFFFFFFF -#define GL_VERTEX_ARRAY_POINTER 0x808E -#define GL_NORMAL_ARRAY_POINTER 0x808F -#define GL_COLOR_ARRAY_POINTER 0x8090 -#define GL_INDEX_ARRAY_POINTER 0x8091 -#define GL_TEXTURE_COORD_ARRAY_POINTER 0x8092 -#define GL_EDGE_FLAG_ARRAY_POINTER 0x8093 -#define GL_FEEDBACK_BUFFER_POINTER 0x0DF0 -#define GL_SELECTION_BUFFER_POINTER 0x0DF3 -#define GL_CLIENT_ATTRIB_STACK_DEPTH 0x0BB1 -#define GL_INDEX_LOGIC_OP 0x0BF1 -#define GL_MAX_CLIENT_ATTRIB_STACK_DEPTH 0x0D3B -#define GL_FEEDBACK_BUFFER_SIZE 0x0DF1 -#define GL_FEEDBACK_BUFFER_TYPE 0x0DF2 -#define GL_SELECTION_BUFFER_SIZE 0x0DF4 -#define GL_VERTEX_ARRAY 0x8074 -#define GL_NORMAL_ARRAY 0x8075 -#define GL_COLOR_ARRAY 0x8076 -#define GL_INDEX_ARRAY 0x8077 -#define GL_TEXTURE_COORD_ARRAY 0x8078 -#define GL_EDGE_FLAG_ARRAY 0x8079 -#define GL_VERTEX_ARRAY_SIZE 0x807A -#define GL_VERTEX_ARRAY_TYPE 0x807B -#define GL_VERTEX_ARRAY_STRIDE 0x807C -#define GL_NORMAL_ARRAY_TYPE 0x807E -#define GL_NORMAL_ARRAY_STRIDE 0x807F -#define GL_COLOR_ARRAY_SIZE 0x8081 -#define GL_COLOR_ARRAY_TYPE 0x8082 -#define GL_COLOR_ARRAY_STRIDE 0x8083 -#define GL_INDEX_ARRAY_TYPE 0x8085 -#define GL_INDEX_ARRAY_STRIDE 0x8086 -#define GL_TEXTURE_COORD_ARRAY_SIZE 0x8088 -#define GL_TEXTURE_COORD_ARRAY_TYPE 0x8089 -#define GL_TEXTURE_COORD_ARRAY_STRIDE 0x808A -#define GL_EDGE_FLAG_ARRAY_STRIDE 0x808C -#define GL_TEXTURE_LUMINANCE_SIZE 0x8060 -#define GL_TEXTURE_INTENSITY_SIZE 0x8061 -#define GL_TEXTURE_PRIORITY 0x8066 -#define GL_TEXTURE_RESIDENT 0x8067 -#define GL_ALPHA4 0x803B -#define GL_ALPHA8 0x803C -#define GL_ALPHA12 0x803D -#define GL_ALPHA16 0x803E -#define GL_LUMINANCE4 0x803F -#define GL_LUMINANCE8 0x8040 -#define GL_LUMINANCE12 0x8041 -#define GL_LUMINANCE16 0x8042 -#define GL_LUMINANCE4_ALPHA4 0x8043 -#define GL_LUMINANCE6_ALPHA2 0x8044 -#define GL_LUMINANCE8_ALPHA8 0x8045 -#define GL_LUMINANCE12_ALPHA4 0x8046 -#define GL_LUMINANCE12_ALPHA12 0x8047 -#define GL_LUMINANCE16_ALPHA16 0x8048 -#define GL_INTENSITY 0x8049 -#define GL_INTENSITY4 0x804A -#define GL_INTENSITY8 0x804B -#define GL_INTENSITY12 0x804C -#define GL_INTENSITY16 0x804D -#define GL_V2F 0x2A20 -#define GL_V3F 0x2A21 -#define GL_C4UB_V2F 0x2A22 -#define GL_C4UB_V3F 0x2A23 -#define GL_C3F_V3F 0x2A24 -#define GL_N3F_V3F 0x2A25 -#define GL_C4F_N3F_V3F 0x2A26 -#define GL_T2F_V3F 0x2A27 -#define GL_T4F_V4F 0x2A28 -#define GL_T2F_C4UB_V3F 0x2A29 -#define GL_T2F_C3F_V3F 0x2A2A -#define GL_T2F_N3F_V3F 0x2A2B -#define GL_T2F_C4F_N3F_V3F 0x2A2C -#define GL_T4F_C4F_N3F_V4F 0x2A2D -#define GL_UNSIGNED_BYTE_3_3_2 0x8032 -#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033 -#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034 -#define GL_UNSIGNED_INT_8_8_8_8 0x8035 -#define GL_UNSIGNED_INT_10_10_10_2 0x8036 -#define GL_TEXTURE_BINDING_3D 0x806A -#define GL_PACK_SKIP_IMAGES 0x806B -#define GL_PACK_IMAGE_HEIGHT 0x806C -#define GL_UNPACK_SKIP_IMAGES 0x806D -#define GL_UNPACK_IMAGE_HEIGHT 0x806E -#define GL_TEXTURE_3D 0x806F -#define GL_PROXY_TEXTURE_3D 0x8070 -#define GL_TEXTURE_DEPTH 0x8071 -#define GL_TEXTURE_WRAP_R 0x8072 -#define GL_MAX_3D_TEXTURE_SIZE 0x8073 -#define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362 -#define GL_UNSIGNED_SHORT_5_6_5 0x8363 -#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364 -#define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365 -#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366 -#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 -#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368 -#define GL_BGR 0x80E0 -#define GL_BGRA 0x80E1 -#define GL_MAX_ELEMENTS_VERTICES 0x80E8 -#define GL_MAX_ELEMENTS_INDICES 0x80E9 -#define GL_CLAMP_TO_EDGE 0x812F -#define GL_TEXTURE_MIN_LOD 0x813A -#define GL_TEXTURE_MAX_LOD 0x813B -#define GL_TEXTURE_BASE_LEVEL 0x813C -#define GL_TEXTURE_MAX_LEVEL 0x813D -#define GL_SMOOTH_POINT_SIZE_RANGE 0x0B12 -#define GL_SMOOTH_POINT_SIZE_GRANULARITY 0x0B13 -#define GL_SMOOTH_LINE_WIDTH_RANGE 0x0B22 -#define GL_SMOOTH_LINE_WIDTH_GRANULARITY 0x0B23 -#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E -#define GL_RESCALE_NORMAL 0x803A -#define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8 -#define GL_SINGLE_COLOR 0x81F9 -#define GL_SEPARATE_SPECULAR_COLOR 0x81FA -#define GL_ALIASED_POINT_SIZE_RANGE 0x846D -#define GL_TEXTURE0 0x84C0 -#define GL_TEXTURE1 0x84C1 -#define GL_TEXTURE2 0x84C2 -#define GL_TEXTURE3 0x84C3 -#define GL_TEXTURE4 0x84C4 -#define GL_TEXTURE5 0x84C5 -#define GL_TEXTURE6 0x84C6 -#define GL_TEXTURE7 0x84C7 -#define GL_TEXTURE8 0x84C8 -#define GL_TEXTURE9 0x84C9 -#define GL_TEXTURE10 0x84CA -#define GL_TEXTURE11 0x84CB -#define GL_TEXTURE12 0x84CC -#define GL_TEXTURE13 0x84CD -#define GL_TEXTURE14 0x84CE -#define GL_TEXTURE15 0x84CF -#define GL_TEXTURE16 0x84D0 -#define GL_TEXTURE17 0x84D1 -#define GL_TEXTURE18 0x84D2 -#define GL_TEXTURE19 0x84D3 -#define GL_TEXTURE20 0x84D4 -#define GL_TEXTURE21 0x84D5 -#define GL_TEXTURE22 0x84D6 -#define GL_TEXTURE23 0x84D7 -#define GL_TEXTURE24 0x84D8 -#define GL_TEXTURE25 0x84D9 -#define GL_TEXTURE26 0x84DA -#define GL_TEXTURE27 0x84DB -#define GL_TEXTURE28 0x84DC -#define GL_TEXTURE29 0x84DD -#define GL_TEXTURE30 0x84DE -#define GL_TEXTURE31 0x84DF -#define GL_ACTIVE_TEXTURE 0x84E0 -#define GL_MULTISAMPLE 0x809D -#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E -#define GL_SAMPLE_ALPHA_TO_ONE 0x809F -#define GL_SAMPLE_COVERAGE 0x80A0 -#define GL_SAMPLE_BUFFERS 0x80A8 -#define GL_SAMPLES 0x80A9 -#define GL_SAMPLE_COVERAGE_VALUE 0x80AA -#define GL_SAMPLE_COVERAGE_INVERT 0x80AB -#define GL_TEXTURE_CUBE_MAP 0x8513 -#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514 -#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515 -#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516 -#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517 -#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518 -#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519 -#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A -#define GL_PROXY_TEXTURE_CUBE_MAP 0x851B -#define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C -#define GL_COMPRESSED_RGB 0x84ED -#define GL_COMPRESSED_RGBA 0x84EE -#define GL_TEXTURE_COMPRESSION_HINT 0x84EF -#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE 0x86A0 -#define GL_TEXTURE_COMPRESSED 0x86A1 -#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2 -#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3 -#define GL_CLAMP_TO_BORDER 0x812D -#define GL_CLIENT_ACTIVE_TEXTURE 0x84E1 -#define GL_MAX_TEXTURE_UNITS 0x84E2 -#define GL_TRANSPOSE_MODELVIEW_MATRIX 0x84E3 -#define GL_TRANSPOSE_PROJECTION_MATRIX 0x84E4 -#define GL_TRANSPOSE_TEXTURE_MATRIX 0x84E5 -#define GL_TRANSPOSE_COLOR_MATRIX 0x84E6 -#define GL_MULTISAMPLE_BIT 0x20000000 -#define GL_NORMAL_MAP 0x8511 -#define GL_REFLECTION_MAP 0x8512 -#define GL_COMPRESSED_ALPHA 0x84E9 -#define GL_COMPRESSED_LUMINANCE 0x84EA -#define GL_COMPRESSED_LUMINANCE_ALPHA 0x84EB -#define GL_COMPRESSED_INTENSITY 0x84EC -#define GL_COMBINE 0x8570 -#define GL_COMBINE_RGB 0x8571 -#define GL_COMBINE_ALPHA 0x8572 -#define GL_SOURCE0_RGB 0x8580 -#define GL_SOURCE1_RGB 0x8581 -#define GL_SOURCE2_RGB 0x8582 -#define GL_SOURCE0_ALPHA 0x8588 -#define GL_SOURCE1_ALPHA 0x8589 -#define GL_SOURCE2_ALPHA 0x858A -#define GL_OPERAND0_RGB 0x8590 -#define GL_OPERAND1_RGB 0x8591 -#define GL_OPERAND2_RGB 0x8592 -#define GL_OPERAND0_ALPHA 0x8598 -#define GL_OPERAND1_ALPHA 0x8599 -#define GL_OPERAND2_ALPHA 0x859A -#define GL_RGB_SCALE 0x8573 -#define GL_ADD_SIGNED 0x8574 -#define GL_INTERPOLATE 0x8575 -#define GL_SUBTRACT 0x84E7 -#define GL_CONSTANT 0x8576 -#define GL_PRIMARY_COLOR 0x8577 -#define GL_PREVIOUS 0x8578 -#define GL_DOT3_RGB 0x86AE -#define GL_DOT3_RGBA 0x86AF -#define GL_BLEND_DST_RGB 0x80C8 -#define GL_BLEND_SRC_RGB 0x80C9 -#define GL_BLEND_DST_ALPHA 0x80CA -#define GL_BLEND_SRC_ALPHA 0x80CB -#define GL_POINT_FADE_THRESHOLD_SIZE 0x8128 -#define GL_DEPTH_COMPONENT16 0x81A5 -#define GL_DEPTH_COMPONENT24 0x81A6 -#define GL_DEPTH_COMPONENT32 0x81A7 -#define GL_MIRRORED_REPEAT 0x8370 -#define GL_MAX_TEXTURE_LOD_BIAS 0x84FD -#define GL_TEXTURE_LOD_BIAS 0x8501 -#define GL_INCR_WRAP 0x8507 -#define GL_DECR_WRAP 0x8508 -#define GL_TEXTURE_DEPTH_SIZE 0x884A -#define GL_TEXTURE_COMPARE_MODE 0x884C -#define GL_TEXTURE_COMPARE_FUNC 0x884D -#define GL_POINT_SIZE_MIN 0x8126 -#define GL_POINT_SIZE_MAX 0x8127 -#define GL_POINT_DISTANCE_ATTENUATION 0x8129 -#define GL_GENERATE_MIPMAP 0x8191 -#define GL_GENERATE_MIPMAP_HINT 0x8192 -#define GL_FOG_COORDINATE_SOURCE 0x8450 -#define GL_FOG_COORDINATE 0x8451 -#define GL_FRAGMENT_DEPTH 0x8452 -#define GL_CURRENT_FOG_COORDINATE 0x8453 -#define GL_FOG_COORDINATE_ARRAY_TYPE 0x8454 -#define GL_FOG_COORDINATE_ARRAY_STRIDE 0x8455 -#define GL_FOG_COORDINATE_ARRAY_POINTER 0x8456 -#define GL_FOG_COORDINATE_ARRAY 0x8457 -#define GL_COLOR_SUM 0x8458 -#define GL_CURRENT_SECONDARY_COLOR 0x8459 -#define GL_SECONDARY_COLOR_ARRAY_SIZE 0x845A -#define GL_SECONDARY_COLOR_ARRAY_TYPE 0x845B -#define GL_SECONDARY_COLOR_ARRAY_STRIDE 0x845C -#define GL_SECONDARY_COLOR_ARRAY_POINTER 0x845D -#define GL_SECONDARY_COLOR_ARRAY 0x845E -#define GL_TEXTURE_FILTER_CONTROL 0x8500 -#define GL_DEPTH_TEXTURE_MODE 0x884B -#define GL_COMPARE_R_TO_TEXTURE 0x884E -#define GL_BLEND_COLOR 0x8005 -#define GL_BLEND_EQUATION 0x8009 -#define GL_CONSTANT_COLOR 0x8001 -#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002 -#define GL_CONSTANT_ALPHA 0x8003 -#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004 -#define GL_FUNC_ADD 0x8006 -#define GL_FUNC_REVERSE_SUBTRACT 0x800B -#define GL_FUNC_SUBTRACT 0x800A -#define GL_MIN 0x8007 -#define GL_MAX 0x8008 -#define GL_BUFFER_SIZE 0x8764 -#define GL_BUFFER_USAGE 0x8765 -#define GL_QUERY_COUNTER_BITS 0x8864 -#define GL_CURRENT_QUERY 0x8865 -#define GL_QUERY_RESULT 0x8866 -#define GL_QUERY_RESULT_AVAILABLE 0x8867 -#define GL_ARRAY_BUFFER 0x8892 -#define GL_ELEMENT_ARRAY_BUFFER 0x8893 -#define GL_ARRAY_BUFFER_BINDING 0x8894 -#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895 -#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING 0x889F -#define GL_READ_ONLY 0x88B8 -#define GL_WRITE_ONLY 0x88B9 -#define GL_READ_WRITE 0x88BA -#define GL_BUFFER_ACCESS 0x88BB -#define GL_BUFFER_MAPPED 0x88BC -#define GL_BUFFER_MAP_POINTER 0x88BD -#define GL_STREAM_DRAW 0x88E0 -#define GL_STREAM_READ 0x88E1 -#define GL_STREAM_COPY 0x88E2 -#define GL_STATIC_DRAW 0x88E4 -#define GL_STATIC_READ 0x88E5 -#define GL_STATIC_COPY 0x88E6 -#define GL_DYNAMIC_DRAW 0x88E8 -#define GL_DYNAMIC_READ 0x88E9 -#define GL_DYNAMIC_COPY 0x88EA -#define GL_SAMPLES_PASSED 0x8914 -#define GL_SRC1_ALPHA 0x8589 -#define GL_VERTEX_ARRAY_BUFFER_BINDING 0x8896 -#define GL_NORMAL_ARRAY_BUFFER_BINDING 0x8897 -#define GL_COLOR_ARRAY_BUFFER_BINDING 0x8898 -#define GL_INDEX_ARRAY_BUFFER_BINDING 0x8899 -#define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING 0x889A -#define GL_EDGE_FLAG_ARRAY_BUFFER_BINDING 0x889B -#define GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING 0x889C -#define GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING 0x889D -#define GL_WEIGHT_ARRAY_BUFFER_BINDING 0x889E -#define GL_FOG_COORD_SRC 0x8450 -#define GL_FOG_COORD 0x8451 -#define GL_CURRENT_FOG_COORD 0x8453 -#define GL_FOG_COORD_ARRAY_TYPE 0x8454 -#define GL_FOG_COORD_ARRAY_STRIDE 0x8455 -#define GL_FOG_COORD_ARRAY_POINTER 0x8456 -#define GL_FOG_COORD_ARRAY 0x8457 -#define GL_FOG_COORD_ARRAY_BUFFER_BINDING 0x889D -#define GL_SRC0_RGB 0x8580 -#define GL_SRC1_RGB 0x8581 -#define GL_SRC2_RGB 0x8582 -#define GL_SRC0_ALPHA 0x8588 -#define GL_SRC2_ALPHA 0x858A -#define GL_BLEND_EQUATION_RGB 0x8009 -#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622 -#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623 -#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624 -#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625 -#define GL_CURRENT_VERTEX_ATTRIB 0x8626 -#define GL_VERTEX_PROGRAM_POINT_SIZE 0x8642 -#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645 -#define GL_STENCIL_BACK_FUNC 0x8800 -#define GL_STENCIL_BACK_FAIL 0x8801 -#define GL_STENCIL_BACK_PASS_DEPTH_FAIL 0x8802 -#define GL_STENCIL_BACK_PASS_DEPTH_PASS 0x8803 -#define GL_MAX_DRAW_BUFFERS 0x8824 -#define GL_DRAW_BUFFER0 0x8825 -#define GL_DRAW_BUFFER1 0x8826 -#define GL_DRAW_BUFFER2 0x8827 -#define GL_DRAW_BUFFER3 0x8828 -#define GL_DRAW_BUFFER4 0x8829 -#define GL_DRAW_BUFFER5 0x882A -#define GL_DRAW_BUFFER6 0x882B -#define GL_DRAW_BUFFER7 0x882C -#define GL_DRAW_BUFFER8 0x882D -#define GL_DRAW_BUFFER9 0x882E -#define GL_DRAW_BUFFER10 0x882F -#define GL_DRAW_BUFFER11 0x8830 -#define GL_DRAW_BUFFER12 0x8831 -#define GL_DRAW_BUFFER13 0x8832 -#define GL_DRAW_BUFFER14 0x8833 -#define GL_DRAW_BUFFER15 0x8834 -#define GL_BLEND_EQUATION_ALPHA 0x883D -#define GL_MAX_VERTEX_ATTRIBS 0x8869 -#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A -#define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872 -#define GL_FRAGMENT_SHADER 0x8B30 -#define GL_VERTEX_SHADER 0x8B31 -#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS 0x8B49 -#define GL_MAX_VERTEX_UNIFORM_COMPONENTS 0x8B4A -#define GL_MAX_VARYING_FLOATS 0x8B4B -#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 0x8B4C -#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D -#define GL_SHADER_TYPE 0x8B4F -#define GL_FLOAT_VEC2 0x8B50 -#define GL_FLOAT_VEC3 0x8B51 -#define GL_FLOAT_VEC4 0x8B52 -#define GL_INT_VEC2 0x8B53 -#define GL_INT_VEC3 0x8B54 -#define GL_INT_VEC4 0x8B55 -#define GL_BOOL 0x8B56 -#define GL_BOOL_VEC2 0x8B57 -#define GL_BOOL_VEC3 0x8B58 -#define GL_BOOL_VEC4 0x8B59 -#define GL_FLOAT_MAT2 0x8B5A -#define GL_FLOAT_MAT3 0x8B5B -#define GL_FLOAT_MAT4 0x8B5C -#define GL_SAMPLER_1D 0x8B5D -#define GL_SAMPLER_2D 0x8B5E -#define GL_SAMPLER_3D 0x8B5F -#define GL_SAMPLER_CUBE 0x8B60 -#define GL_SAMPLER_1D_SHADOW 0x8B61 -#define GL_SAMPLER_2D_SHADOW 0x8B62 -#define GL_DELETE_STATUS 0x8B80 -#define GL_COMPILE_STATUS 0x8B81 -#define GL_LINK_STATUS 0x8B82 -#define GL_VALIDATE_STATUS 0x8B83 -#define GL_INFO_LOG_LENGTH 0x8B84 -#define GL_ATTACHED_SHADERS 0x8B85 -#define GL_ACTIVE_UNIFORMS 0x8B86 -#define GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87 -#define GL_SHADER_SOURCE_LENGTH 0x8B88 -#define GL_ACTIVE_ATTRIBUTES 0x8B89 -#define GL_ACTIVE_ATTRIBUTE_MAX_LENGTH 0x8B8A -#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT 0x8B8B -#define GL_SHADING_LANGUAGE_VERSION 0x8B8C -#define GL_CURRENT_PROGRAM 0x8B8D -#define GL_POINT_SPRITE_COORD_ORIGIN 0x8CA0 -#define GL_LOWER_LEFT 0x8CA1 -#define GL_UPPER_LEFT 0x8CA2 -#define GL_STENCIL_BACK_REF 0x8CA3 -#define GL_STENCIL_BACK_VALUE_MASK 0x8CA4 -#define GL_STENCIL_BACK_WRITEMASK 0x8CA5 -#define GL_VERTEX_PROGRAM_TWO_SIDE 0x8643 -#define GL_POINT_SPRITE 0x8861 -#define GL_COORD_REPLACE 0x8862 -#define GL_MAX_TEXTURE_COORDS 0x8871 -#define GL_PIXEL_PACK_BUFFER 0x88EB -#define GL_PIXEL_UNPACK_BUFFER 0x88EC -#define GL_PIXEL_PACK_BUFFER_BINDING 0x88ED -#define GL_PIXEL_UNPACK_BUFFER_BINDING 0x88EF -#define GL_FLOAT_MAT2x3 0x8B65 -#define GL_FLOAT_MAT2x4 0x8B66 -#define GL_FLOAT_MAT3x2 0x8B67 -#define GL_FLOAT_MAT3x4 0x8B68 -#define GL_FLOAT_MAT4x2 0x8B69 -#define GL_FLOAT_MAT4x3 0x8B6A -#define GL_SRGB 0x8C40 -#define GL_SRGB8 0x8C41 -#define GL_SRGB_ALPHA 0x8C42 -#define GL_SRGB8_ALPHA8 0x8C43 -#define GL_COMPRESSED_SRGB 0x8C48 -#define GL_COMPRESSED_SRGB_ALPHA 0x8C49 -#define GL_CURRENT_RASTER_SECONDARY_COLOR 0x845F -#define GL_SLUMINANCE_ALPHA 0x8C44 -#define GL_SLUMINANCE8_ALPHA8 0x8C45 -#define GL_SLUMINANCE 0x8C46 -#define GL_SLUMINANCE8 0x8C47 -#define GL_COMPRESSED_SLUMINANCE 0x8C4A -#define GL_COMPRESSED_SLUMINANCE_ALPHA 0x8C4B -#define GL_COMPARE_REF_TO_TEXTURE 0x884E -#define GL_CLIP_DISTANCE0 0x3000 -#define GL_CLIP_DISTANCE1 0x3001 -#define GL_CLIP_DISTANCE2 0x3002 -#define GL_CLIP_DISTANCE3 0x3003 -#define GL_CLIP_DISTANCE4 0x3004 -#define GL_CLIP_DISTANCE5 0x3005 -#define GL_CLIP_DISTANCE6 0x3006 -#define GL_CLIP_DISTANCE7 0x3007 -#define GL_MAX_CLIP_DISTANCES 0x0D32 -#define GL_MAJOR_VERSION 0x821B -#define GL_MINOR_VERSION 0x821C -#define GL_NUM_EXTENSIONS 0x821D -#define GL_CONTEXT_FLAGS 0x821E -#define GL_COMPRESSED_RED 0x8225 -#define GL_COMPRESSED_RG 0x8226 -#define GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT 0x00000001 -#define GL_RGBA32F 0x8814 -#define GL_RGB32F 0x8815 -#define GL_RGBA16F 0x881A -#define GL_RGB16F 0x881B -#define GL_VERTEX_ATTRIB_ARRAY_INTEGER 0x88FD -#define GL_MAX_ARRAY_TEXTURE_LAYERS 0x88FF -#define GL_MIN_PROGRAM_TEXEL_OFFSET 0x8904 -#define GL_MAX_PROGRAM_TEXEL_OFFSET 0x8905 -#define GL_CLAMP_READ_COLOR 0x891C -#define GL_FIXED_ONLY 0x891D -#define GL_MAX_VARYING_COMPONENTS 0x8B4B -#define GL_TEXTURE_1D_ARRAY 0x8C18 -#define GL_PROXY_TEXTURE_1D_ARRAY 0x8C19 -#define GL_TEXTURE_2D_ARRAY 0x8C1A -#define GL_PROXY_TEXTURE_2D_ARRAY 0x8C1B -#define GL_TEXTURE_BINDING_1D_ARRAY 0x8C1C -#define GL_TEXTURE_BINDING_2D_ARRAY 0x8C1D -#define GL_R11F_G11F_B10F 0x8C3A -#define GL_UNSIGNED_INT_10F_11F_11F_REV 0x8C3B -#define GL_RGB9_E5 0x8C3D -#define GL_UNSIGNED_INT_5_9_9_9_REV 0x8C3E -#define GL_TEXTURE_SHARED_SIZE 0x8C3F -#define GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH 0x8C76 -#define GL_TRANSFORM_FEEDBACK_BUFFER_MODE 0x8C7F -#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS 0x8C80 -#define GL_TRANSFORM_FEEDBACK_VARYINGS 0x8C83 -#define GL_TRANSFORM_FEEDBACK_BUFFER_START 0x8C84 -#define GL_TRANSFORM_FEEDBACK_BUFFER_SIZE 0x8C85 -#define GL_PRIMITIVES_GENERATED 0x8C87 -#define GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN 0x8C88 -#define GL_RASTERIZER_DISCARD 0x8C89 -#define GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS 0x8C8A -#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS 0x8C8B -#define GL_INTERLEAVED_ATTRIBS 0x8C8C -#define GL_SEPARATE_ATTRIBS 0x8C8D -#define GL_TRANSFORM_FEEDBACK_BUFFER 0x8C8E -#define GL_TRANSFORM_FEEDBACK_BUFFER_BINDING 0x8C8F -#define GL_RGBA32UI 0x8D70 -#define GL_RGB32UI 0x8D71 -#define GL_RGBA16UI 0x8D76 -#define GL_RGB16UI 0x8D77 -#define GL_RGBA8UI 0x8D7C -#define GL_RGB8UI 0x8D7D -#define GL_RGBA32I 0x8D82 -#define GL_RGB32I 0x8D83 -#define GL_RGBA16I 0x8D88 -#define GL_RGB16I 0x8D89 -#define GL_RGBA8I 0x8D8E -#define GL_RGB8I 0x8D8F -#define GL_RED_INTEGER 0x8D94 -#define GL_GREEN_INTEGER 0x8D95 -#define GL_BLUE_INTEGER 0x8D96 -#define GL_RGB_INTEGER 0x8D98 -#define GL_RGBA_INTEGER 0x8D99 -#define GL_BGR_INTEGER 0x8D9A -#define GL_BGRA_INTEGER 0x8D9B -#define GL_SAMPLER_1D_ARRAY 0x8DC0 -#define GL_SAMPLER_2D_ARRAY 0x8DC1 -#define GL_SAMPLER_1D_ARRAY_SHADOW 0x8DC3 -#define GL_SAMPLER_2D_ARRAY_SHADOW 0x8DC4 -#define GL_SAMPLER_CUBE_SHADOW 0x8DC5 -#define GL_UNSIGNED_INT_VEC2 0x8DC6 -#define GL_UNSIGNED_INT_VEC3 0x8DC7 -#define GL_UNSIGNED_INT_VEC4 0x8DC8 -#define GL_INT_SAMPLER_1D 0x8DC9 -#define GL_INT_SAMPLER_2D 0x8DCA -#define GL_INT_SAMPLER_3D 0x8DCB -#define GL_INT_SAMPLER_CUBE 0x8DCC -#define GL_INT_SAMPLER_1D_ARRAY 0x8DCE -#define GL_INT_SAMPLER_2D_ARRAY 0x8DCF -#define GL_UNSIGNED_INT_SAMPLER_1D 0x8DD1 -#define GL_UNSIGNED_INT_SAMPLER_2D 0x8DD2 -#define GL_UNSIGNED_INT_SAMPLER_3D 0x8DD3 -#define GL_UNSIGNED_INT_SAMPLER_CUBE 0x8DD4 -#define GL_UNSIGNED_INT_SAMPLER_1D_ARRAY 0x8DD6 -#define GL_UNSIGNED_INT_SAMPLER_2D_ARRAY 0x8DD7 -#define GL_QUERY_WAIT 0x8E13 -#define GL_QUERY_NO_WAIT 0x8E14 -#define GL_QUERY_BY_REGION_WAIT 0x8E15 -#define GL_QUERY_BY_REGION_NO_WAIT 0x8E16 -#define GL_BUFFER_ACCESS_FLAGS 0x911F -#define GL_BUFFER_MAP_LENGTH 0x9120 -#define GL_BUFFER_MAP_OFFSET 0x9121 -#define GL_DEPTH_COMPONENT32F 0x8CAC -#define GL_DEPTH32F_STENCIL8 0x8CAD -#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV 0x8DAD -#define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506 -#define GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING 0x8210 -#define GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE 0x8211 -#define GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE 0x8212 -#define GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE 0x8213 -#define GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE 0x8214 -#define GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE 0x8215 -#define GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE 0x8216 -#define GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE 0x8217 -#define GL_FRAMEBUFFER_DEFAULT 0x8218 -#define GL_FRAMEBUFFER_UNDEFINED 0x8219 -#define GL_DEPTH_STENCIL_ATTACHMENT 0x821A -#define GL_MAX_RENDERBUFFER_SIZE 0x84E8 -#define GL_DEPTH_STENCIL 0x84F9 -#define GL_UNSIGNED_INT_24_8 0x84FA -#define GL_DEPTH24_STENCIL8 0x88F0 -#define GL_TEXTURE_STENCIL_SIZE 0x88F1 -#define GL_TEXTURE_RED_TYPE 0x8C10 -#define GL_TEXTURE_GREEN_TYPE 0x8C11 -#define GL_TEXTURE_BLUE_TYPE 0x8C12 -#define GL_TEXTURE_ALPHA_TYPE 0x8C13 -#define GL_TEXTURE_DEPTH_TYPE 0x8C16 -#define GL_UNSIGNED_NORMALIZED 0x8C17 -#define GL_FRAMEBUFFER_BINDING 0x8CA6 -#define GL_DRAW_FRAMEBUFFER_BINDING 0x8CA6 -#define GL_RENDERBUFFER_BINDING 0x8CA7 -#define GL_READ_FRAMEBUFFER 0x8CA8 -#define GL_DRAW_FRAMEBUFFER 0x8CA9 -#define GL_READ_FRAMEBUFFER_BINDING 0x8CAA -#define GL_RENDERBUFFER_SAMPLES 0x8CAB -#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE 0x8CD0 -#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME 0x8CD1 -#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL 0x8CD2 -#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE 0x8CD3 -#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER 0x8CD4 -#define GL_FRAMEBUFFER_COMPLETE 0x8CD5 -#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6 -#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7 -#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER 0x8CDB -#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER 0x8CDC -#define GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD -#define GL_MAX_COLOR_ATTACHMENTS 0x8CDF -#define GL_COLOR_ATTACHMENT0 0x8CE0 -#define GL_COLOR_ATTACHMENT1 0x8CE1 -#define GL_COLOR_ATTACHMENT2 0x8CE2 -#define GL_COLOR_ATTACHMENT3 0x8CE3 -#define GL_COLOR_ATTACHMENT4 0x8CE4 -#define GL_COLOR_ATTACHMENT5 0x8CE5 -#define GL_COLOR_ATTACHMENT6 0x8CE6 -#define GL_COLOR_ATTACHMENT7 0x8CE7 -#define GL_COLOR_ATTACHMENT8 0x8CE8 -#define GL_COLOR_ATTACHMENT9 0x8CE9 -#define GL_COLOR_ATTACHMENT10 0x8CEA -#define GL_COLOR_ATTACHMENT11 0x8CEB -#define GL_COLOR_ATTACHMENT12 0x8CEC -#define GL_COLOR_ATTACHMENT13 0x8CED -#define GL_COLOR_ATTACHMENT14 0x8CEE -#define GL_COLOR_ATTACHMENT15 0x8CEF -#define GL_COLOR_ATTACHMENT16 0x8CF0 -#define GL_COLOR_ATTACHMENT17 0x8CF1 -#define GL_COLOR_ATTACHMENT18 0x8CF2 -#define GL_COLOR_ATTACHMENT19 0x8CF3 -#define GL_COLOR_ATTACHMENT20 0x8CF4 -#define GL_COLOR_ATTACHMENT21 0x8CF5 -#define GL_COLOR_ATTACHMENT22 0x8CF6 -#define GL_COLOR_ATTACHMENT23 0x8CF7 -#define GL_COLOR_ATTACHMENT24 0x8CF8 -#define GL_COLOR_ATTACHMENT25 0x8CF9 -#define GL_COLOR_ATTACHMENT26 0x8CFA -#define GL_COLOR_ATTACHMENT27 0x8CFB -#define GL_COLOR_ATTACHMENT28 0x8CFC -#define GL_COLOR_ATTACHMENT29 0x8CFD -#define GL_COLOR_ATTACHMENT30 0x8CFE -#define GL_COLOR_ATTACHMENT31 0x8CFF -#define GL_DEPTH_ATTACHMENT 0x8D00 -#define GL_STENCIL_ATTACHMENT 0x8D20 -#define GL_FRAMEBUFFER 0x8D40 -#define GL_RENDERBUFFER 0x8D41 -#define GL_RENDERBUFFER_WIDTH 0x8D42 -#define GL_RENDERBUFFER_HEIGHT 0x8D43 -#define GL_RENDERBUFFER_INTERNAL_FORMAT 0x8D44 -#define GL_STENCIL_INDEX1 0x8D46 -#define GL_STENCIL_INDEX4 0x8D47 -#define GL_STENCIL_INDEX8 0x8D48 -#define GL_STENCIL_INDEX16 0x8D49 -#define GL_RENDERBUFFER_RED_SIZE 0x8D50 -#define GL_RENDERBUFFER_GREEN_SIZE 0x8D51 -#define GL_RENDERBUFFER_BLUE_SIZE 0x8D52 -#define GL_RENDERBUFFER_ALPHA_SIZE 0x8D53 -#define GL_RENDERBUFFER_DEPTH_SIZE 0x8D54 -#define GL_RENDERBUFFER_STENCIL_SIZE 0x8D55 -#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE 0x8D56 -#define GL_MAX_SAMPLES 0x8D57 -#define GL_INDEX 0x8222 -#define GL_TEXTURE_LUMINANCE_TYPE 0x8C14 -#define GL_TEXTURE_INTENSITY_TYPE 0x8C15 -#define GL_FRAMEBUFFER_SRGB 0x8DB9 -#define GL_HALF_FLOAT 0x140B -#define GL_MAP_READ_BIT 0x0001 -#define GL_MAP_WRITE_BIT 0x0002 -#define GL_MAP_INVALIDATE_RANGE_BIT 0x0004 -#define GL_MAP_INVALIDATE_BUFFER_BIT 0x0008 -#define GL_MAP_FLUSH_EXPLICIT_BIT 0x0010 -#define GL_MAP_UNSYNCHRONIZED_BIT 0x0020 -#define GL_COMPRESSED_RED_RGTC1 0x8DBB -#define GL_COMPRESSED_SIGNED_RED_RGTC1 0x8DBC -#define GL_COMPRESSED_RG_RGTC2 0x8DBD -#define GL_COMPRESSED_SIGNED_RG_RGTC2 0x8DBE -#define GL_RG 0x8227 -#define GL_RG_INTEGER 0x8228 -#define GL_R8 0x8229 -#define GL_R16 0x822A -#define GL_RG8 0x822B -#define GL_RG16 0x822C -#define GL_R16F 0x822D -#define GL_R32F 0x822E -#define GL_RG16F 0x822F -#define GL_RG32F 0x8230 -#define GL_R8I 0x8231 -#define GL_R8UI 0x8232 -#define GL_R16I 0x8233 -#define GL_R16UI 0x8234 -#define GL_R32I 0x8235 -#define GL_R32UI 0x8236 -#define GL_RG8I 0x8237 -#define GL_RG8UI 0x8238 -#define GL_RG16I 0x8239 -#define GL_RG16UI 0x823A -#define GL_RG32I 0x823B -#define GL_RG32UI 0x823C -#define GL_VERTEX_ARRAY_BINDING 0x85B5 -#define GL_CLAMP_VERTEX_COLOR 0x891A -#define GL_CLAMP_FRAGMENT_COLOR 0x891B -#define GL_ALPHA_INTEGER 0x8D97 -#define GL_SAMPLER_2D_RECT 0x8B63 -#define GL_SAMPLER_2D_RECT_SHADOW 0x8B64 -#define GL_SAMPLER_BUFFER 0x8DC2 -#define GL_INT_SAMPLER_2D_RECT 0x8DCD -#define GL_INT_SAMPLER_BUFFER 0x8DD0 -#define GL_UNSIGNED_INT_SAMPLER_2D_RECT 0x8DD5 -#define GL_UNSIGNED_INT_SAMPLER_BUFFER 0x8DD8 -#define GL_TEXTURE_BUFFER 0x8C2A -#define GL_MAX_TEXTURE_BUFFER_SIZE 0x8C2B -#define GL_TEXTURE_BINDING_BUFFER 0x8C2C -#define GL_TEXTURE_BUFFER_DATA_STORE_BINDING 0x8C2D -#define GL_TEXTURE_RECTANGLE 0x84F5 -#define GL_TEXTURE_BINDING_RECTANGLE 0x84F6 -#define GL_PROXY_TEXTURE_RECTANGLE 0x84F7 -#define GL_MAX_RECTANGLE_TEXTURE_SIZE 0x84F8 -#define GL_R8_SNORM 0x8F94 -#define GL_RG8_SNORM 0x8F95 -#define GL_RGB8_SNORM 0x8F96 -#define GL_RGBA8_SNORM 0x8F97 -#define GL_R16_SNORM 0x8F98 -#define GL_RG16_SNORM 0x8F99 -#define GL_RGB16_SNORM 0x8F9A -#define GL_RGBA16_SNORM 0x8F9B -#define GL_SIGNED_NORMALIZED 0x8F9C -#define GL_PRIMITIVE_RESTART 0x8F9D -#define GL_PRIMITIVE_RESTART_INDEX 0x8F9E -#define GL_COPY_READ_BUFFER 0x8F36 -#define GL_COPY_WRITE_BUFFER 0x8F37 -#define GL_UNIFORM_BUFFER 0x8A11 -#define GL_UNIFORM_BUFFER_BINDING 0x8A28 -#define GL_UNIFORM_BUFFER_START 0x8A29 -#define GL_UNIFORM_BUFFER_SIZE 0x8A2A -#define GL_MAX_VERTEX_UNIFORM_BLOCKS 0x8A2B -#define GL_MAX_GEOMETRY_UNIFORM_BLOCKS 0x8A2C -#define GL_MAX_FRAGMENT_UNIFORM_BLOCKS 0x8A2D -#define GL_MAX_COMBINED_UNIFORM_BLOCKS 0x8A2E -#define GL_MAX_UNIFORM_BUFFER_BINDINGS 0x8A2F -#define GL_MAX_UNIFORM_BLOCK_SIZE 0x8A30 -#define GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS 0x8A31 -#define GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS 0x8A32 -#define GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS 0x8A33 -#define GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT 0x8A34 -#define GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH 0x8A35 -#define GL_ACTIVE_UNIFORM_BLOCKS 0x8A36 -#define GL_UNIFORM_TYPE 0x8A37 -#define GL_UNIFORM_SIZE 0x8A38 -#define GL_UNIFORM_NAME_LENGTH 0x8A39 -#define GL_UNIFORM_BLOCK_INDEX 0x8A3A -#define GL_UNIFORM_OFFSET 0x8A3B -#define GL_UNIFORM_ARRAY_STRIDE 0x8A3C -#define GL_UNIFORM_MATRIX_STRIDE 0x8A3D -#define GL_UNIFORM_IS_ROW_MAJOR 0x8A3E -#define GL_UNIFORM_BLOCK_BINDING 0x8A3F -#define GL_UNIFORM_BLOCK_DATA_SIZE 0x8A40 -#define GL_UNIFORM_BLOCK_NAME_LENGTH 0x8A41 -#define GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS 0x8A42 -#define GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES 0x8A43 -#define GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER 0x8A44 -#define GL_UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER 0x8A45 -#define GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER 0x8A46 -#define GL_INVALID_INDEX 0xFFFFFFFF -#define GL_CONTEXT_CORE_PROFILE_BIT 0x00000001 -#define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002 -#define GL_LINES_ADJACENCY 0x000A -#define GL_LINE_STRIP_ADJACENCY 0x000B -#define GL_TRIANGLES_ADJACENCY 0x000C -#define GL_TRIANGLE_STRIP_ADJACENCY 0x000D -#define GL_PROGRAM_POINT_SIZE 0x8642 -#define GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS 0x8C29 -#define GL_FRAMEBUFFER_ATTACHMENT_LAYERED 0x8DA7 -#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS 0x8DA8 -#define GL_GEOMETRY_SHADER 0x8DD9 -#define GL_GEOMETRY_VERTICES_OUT 0x8916 -#define GL_GEOMETRY_INPUT_TYPE 0x8917 -#define GL_GEOMETRY_OUTPUT_TYPE 0x8918 -#define GL_MAX_GEOMETRY_UNIFORM_COMPONENTS 0x8DDF -#define GL_MAX_GEOMETRY_OUTPUT_VERTICES 0x8DE0 -#define GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS 0x8DE1 -#define GL_MAX_VERTEX_OUTPUT_COMPONENTS 0x9122 -#define GL_MAX_GEOMETRY_INPUT_COMPONENTS 0x9123 -#define GL_MAX_GEOMETRY_OUTPUT_COMPONENTS 0x9124 -#define GL_MAX_FRAGMENT_INPUT_COMPONENTS 0x9125 -#define GL_CONTEXT_PROFILE_MASK 0x9126 -#define GL_DEPTH_CLAMP 0x864F -#define GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION 0x8E4C -#define GL_FIRST_VERTEX_CONVENTION 0x8E4D -#define GL_LAST_VERTEX_CONVENTION 0x8E4E -#define GL_PROVOKING_VERTEX 0x8E4F -#define GL_TEXTURE_CUBE_MAP_SEAMLESS 0x884F -#define GL_MAX_SERVER_WAIT_TIMEOUT 0x9111 -#define GL_OBJECT_TYPE 0x9112 -#define GL_SYNC_CONDITION 0x9113 -#define GL_SYNC_STATUS 0x9114 -#define GL_SYNC_FLAGS 0x9115 -#define GL_SYNC_FENCE 0x9116 -#define GL_SYNC_GPU_COMMANDS_COMPLETE 0x9117 -#define GL_UNSIGNALED 0x9118 -#define GL_SIGNALED 0x9119 -#define GL_ALREADY_SIGNALED 0x911A -#define GL_TIMEOUT_EXPIRED 0x911B -#define GL_CONDITION_SATISFIED 0x911C -#define GL_WAIT_FAILED 0x911D -#define GL_TIMEOUT_IGNORED 0xFFFFFFFFFFFFFFFF -#define GL_SYNC_FLUSH_COMMANDS_BIT 0x00000001 -#define GL_SAMPLE_POSITION 0x8E50 -#define GL_SAMPLE_MASK 0x8E51 -#define GL_SAMPLE_MASK_VALUE 0x8E52 -#define GL_MAX_SAMPLE_MASK_WORDS 0x8E59 -#define GL_TEXTURE_2D_MULTISAMPLE 0x9100 -#define GL_PROXY_TEXTURE_2D_MULTISAMPLE 0x9101 -#define GL_TEXTURE_2D_MULTISAMPLE_ARRAY 0x9102 -#define GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY 0x9103 -#define GL_TEXTURE_BINDING_2D_MULTISAMPLE 0x9104 -#define GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY 0x9105 -#define GL_TEXTURE_SAMPLES 0x9106 -#define GL_TEXTURE_FIXED_SAMPLE_LOCATIONS 0x9107 -#define GL_SAMPLER_2D_MULTISAMPLE 0x9108 -#define GL_INT_SAMPLER_2D_MULTISAMPLE 0x9109 -#define GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE 0x910A -#define GL_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910B -#define GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910C -#define GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910D -#define GL_MAX_COLOR_TEXTURE_SAMPLES 0x910E -#define GL_MAX_DEPTH_TEXTURE_SAMPLES 0x910F -#define GL_MAX_INTEGER_SAMPLES 0x9110 -#define GL_VERTEX_ATTRIB_ARRAY_DIVISOR 0x88FE -#define GL_SRC1_COLOR 0x88F9 -#define GL_ONE_MINUS_SRC1_COLOR 0x88FA -#define GL_ONE_MINUS_SRC1_ALPHA 0x88FB -#define GL_MAX_DUAL_SOURCE_DRAW_BUFFERS 0x88FC -#define GL_ANY_SAMPLES_PASSED 0x8C2F -#define GL_SAMPLER_BINDING 0x8919 -#define GL_RGB10_A2UI 0x906F -#define GL_TEXTURE_SWIZZLE_R 0x8E42 -#define GL_TEXTURE_SWIZZLE_G 0x8E43 -#define GL_TEXTURE_SWIZZLE_B 0x8E44 -#define GL_TEXTURE_SWIZZLE_A 0x8E45 -#define GL_TEXTURE_SWIZZLE_RGBA 0x8E46 -#define GL_TIME_ELAPSED 0x88BF -#define GL_TIMESTAMP 0x8E28 -#define GL_INT_2_10_10_10_REV 0x8D9F -#define GL_SAMPLE_SHADING 0x8C36 -#define GL_MIN_SAMPLE_SHADING_VALUE 0x8C37 -#define GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET 0x8E5E -#define GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET 0x8E5F -#define GL_TEXTURE_CUBE_MAP_ARRAY 0x9009 -#define GL_TEXTURE_BINDING_CUBE_MAP_ARRAY 0x900A -#define GL_PROXY_TEXTURE_CUBE_MAP_ARRAY 0x900B -#define GL_SAMPLER_CUBE_MAP_ARRAY 0x900C -#define GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW 0x900D -#define GL_INT_SAMPLER_CUBE_MAP_ARRAY 0x900E -#define GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY 0x900F -#define GL_DRAW_INDIRECT_BUFFER 0x8F3F -#define GL_DRAW_INDIRECT_BUFFER_BINDING 0x8F43 -#define GL_GEOMETRY_SHADER_INVOCATIONS 0x887F -#define GL_MAX_GEOMETRY_SHADER_INVOCATIONS 0x8E5A -#define GL_MIN_FRAGMENT_INTERPOLATION_OFFSET 0x8E5B -#define GL_MAX_FRAGMENT_INTERPOLATION_OFFSET 0x8E5C -#define GL_FRAGMENT_INTERPOLATION_OFFSET_BITS 0x8E5D -#define GL_MAX_VERTEX_STREAMS 0x8E71 -#define GL_DOUBLE_VEC2 0x8FFC -#define GL_DOUBLE_VEC3 0x8FFD -#define GL_DOUBLE_VEC4 0x8FFE -#define GL_DOUBLE_MAT2 0x8F46 -#define GL_DOUBLE_MAT3 0x8F47 -#define GL_DOUBLE_MAT4 0x8F48 -#define GL_DOUBLE_MAT2x3 0x8F49 -#define GL_DOUBLE_MAT2x4 0x8F4A -#define GL_DOUBLE_MAT3x2 0x8F4B -#define GL_DOUBLE_MAT3x4 0x8F4C -#define GL_DOUBLE_MAT4x2 0x8F4D -#define GL_DOUBLE_MAT4x3 0x8F4E -#define GL_ACTIVE_SUBROUTINES 0x8DE5 -#define GL_ACTIVE_SUBROUTINE_UNIFORMS 0x8DE6 -#define GL_ACTIVE_SUBROUTINE_UNIFORM_LOCATIONS 0x8E47 -#define GL_ACTIVE_SUBROUTINE_MAX_LENGTH 0x8E48 -#define GL_ACTIVE_SUBROUTINE_UNIFORM_MAX_LENGTH 0x8E49 -#define GL_MAX_SUBROUTINES 0x8DE7 -#define GL_MAX_SUBROUTINE_UNIFORM_LOCATIONS 0x8DE8 -#define GL_NUM_COMPATIBLE_SUBROUTINES 0x8E4A -#define GL_COMPATIBLE_SUBROUTINES 0x8E4B -#define GL_PATCHES 0x000E -#define GL_PATCH_VERTICES 0x8E72 -#define GL_PATCH_DEFAULT_INNER_LEVEL 0x8E73 -#define GL_PATCH_DEFAULT_OUTER_LEVEL 0x8E74 -#define GL_TESS_CONTROL_OUTPUT_VERTICES 0x8E75 -#define GL_TESS_GEN_MODE 0x8E76 -#define GL_TESS_GEN_SPACING 0x8E77 -#define GL_TESS_GEN_VERTEX_ORDER 0x8E78 -#define GL_TESS_GEN_POINT_MODE 0x8E79 -#define GL_ISOLINES 0x8E7A -#define GL_FRACTIONAL_ODD 0x8E7B -#define GL_FRACTIONAL_EVEN 0x8E7C -#define GL_MAX_PATCH_VERTICES 0x8E7D -#define GL_MAX_TESS_GEN_LEVEL 0x8E7E -#define GL_MAX_TESS_CONTROL_UNIFORM_COMPONENTS 0x8E7F -#define GL_MAX_TESS_EVALUATION_UNIFORM_COMPONENTS 0x8E80 -#define GL_MAX_TESS_CONTROL_TEXTURE_IMAGE_UNITS 0x8E81 -#define GL_MAX_TESS_EVALUATION_TEXTURE_IMAGE_UNITS 0x8E82 -#define GL_MAX_TESS_CONTROL_OUTPUT_COMPONENTS 0x8E83 -#define GL_MAX_TESS_PATCH_COMPONENTS 0x8E84 -#define GL_MAX_TESS_CONTROL_TOTAL_OUTPUT_COMPONENTS 0x8E85 -#define GL_MAX_TESS_EVALUATION_OUTPUT_COMPONENTS 0x8E86 -#define GL_MAX_TESS_CONTROL_UNIFORM_BLOCKS 0x8E89 -#define GL_MAX_TESS_EVALUATION_UNIFORM_BLOCKS 0x8E8A -#define GL_MAX_TESS_CONTROL_INPUT_COMPONENTS 0x886C -#define GL_MAX_TESS_EVALUATION_INPUT_COMPONENTS 0x886D -#define GL_MAX_COMBINED_TESS_CONTROL_UNIFORM_COMPONENTS 0x8E1E -#define GL_MAX_COMBINED_TESS_EVALUATION_UNIFORM_COMPONENTS 0x8E1F -#define GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_CONTROL_SHADER 0x84F0 -#define GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_EVALUATION_SHADER 0x84F1 -#define GL_TESS_EVALUATION_SHADER 0x8E87 -#define GL_TESS_CONTROL_SHADER 0x8E88 -#define GL_TRANSFORM_FEEDBACK 0x8E22 -#define GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED 0x8E23 -#define GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE 0x8E24 -#define GL_TRANSFORM_FEEDBACK_BINDING 0x8E25 -#define GL_MAX_TRANSFORM_FEEDBACK_BUFFERS 0x8E70 -#define GL_FIXED 0x140C -#define GL_IMPLEMENTATION_COLOR_READ_TYPE 0x8B9A -#define GL_IMPLEMENTATION_COLOR_READ_FORMAT 0x8B9B -#define GL_LOW_FLOAT 0x8DF0 -#define GL_MEDIUM_FLOAT 0x8DF1 -#define GL_HIGH_FLOAT 0x8DF2 -#define GL_LOW_INT 0x8DF3 -#define GL_MEDIUM_INT 0x8DF4 -#define GL_HIGH_INT 0x8DF5 -#define GL_SHADER_COMPILER 0x8DFA -#define GL_SHADER_BINARY_FORMATS 0x8DF8 -#define GL_NUM_SHADER_BINARY_FORMATS 0x8DF9 -#define GL_MAX_VERTEX_UNIFORM_VECTORS 0x8DFB -#define GL_MAX_VARYING_VECTORS 0x8DFC -#define GL_MAX_FRAGMENT_UNIFORM_VECTORS 0x8DFD -#define GL_RGB565 0x8D62 -#define GL_PROGRAM_BINARY_RETRIEVABLE_HINT 0x8257 -#define GL_PROGRAM_BINARY_LENGTH 0x8741 -#define GL_NUM_PROGRAM_BINARY_FORMATS 0x87FE -#define GL_PROGRAM_BINARY_FORMATS 0x87FF -#define GL_VERTEX_SHADER_BIT 0x00000001 -#define GL_FRAGMENT_SHADER_BIT 0x00000002 -#define GL_GEOMETRY_SHADER_BIT 0x00000004 -#define GL_TESS_CONTROL_SHADER_BIT 0x00000008 -#define GL_TESS_EVALUATION_SHADER_BIT 0x00000010 -#define GL_ALL_SHADER_BITS 0xFFFFFFFF -#define GL_PROGRAM_SEPARABLE 0x8258 -#define GL_ACTIVE_PROGRAM 0x8259 -#define GL_PROGRAM_PIPELINE_BINDING 0x825A -#define GL_MAX_VIEWPORTS 0x825B -#define GL_VIEWPORT_SUBPIXEL_BITS 0x825C -#define GL_VIEWPORT_BOUNDS_RANGE 0x825D -#define GL_LAYER_PROVOKING_VERTEX 0x825E -#define GL_VIEWPORT_INDEX_PROVOKING_VERTEX 0x825F -#define GL_UNDEFINED_VERTEX 0x8260 -#ifndef GL_VERSION_1_0 -#define GL_VERSION_1_0 1 -GLAPI int GLAD_GL_VERSION_1_0; -typedef void (APIENTRYP PFNGLCULLFACEPROC)(GLenum mode); -GLAPI PFNGLCULLFACEPROC glad_glCullFace; -#define glCullFace glad_glCullFace -typedef void (APIENTRYP PFNGLFRONTFACEPROC)(GLenum mode); -GLAPI PFNGLFRONTFACEPROC glad_glFrontFace; -#define glFrontFace glad_glFrontFace -typedef void (APIENTRYP PFNGLHINTPROC)(GLenum target, GLenum mode); -GLAPI PFNGLHINTPROC glad_glHint; -#define glHint glad_glHint -typedef void (APIENTRYP PFNGLLINEWIDTHPROC)(GLfloat width); -GLAPI PFNGLLINEWIDTHPROC glad_glLineWidth; -#define glLineWidth glad_glLineWidth -typedef void (APIENTRYP PFNGLPOINTSIZEPROC)(GLfloat size); -GLAPI PFNGLPOINTSIZEPROC glad_glPointSize; -#define glPointSize glad_glPointSize -typedef void (APIENTRYP PFNGLPOLYGONMODEPROC)(GLenum face, GLenum mode); -GLAPI PFNGLPOLYGONMODEPROC glad_glPolygonMode; -#define glPolygonMode glad_glPolygonMode -typedef void (APIENTRYP PFNGLSCISSORPROC)(GLint x, GLint y, GLsizei width, GLsizei height); -GLAPI PFNGLSCISSORPROC glad_glScissor; -#define glScissor glad_glScissor -typedef void (APIENTRYP PFNGLTEXPARAMETERFPROC)(GLenum target, GLenum pname, GLfloat param); -GLAPI PFNGLTEXPARAMETERFPROC glad_glTexParameterf; -#define glTexParameterf glad_glTexParameterf -typedef void (APIENTRYP PFNGLTEXPARAMETERFVPROC)(GLenum target, GLenum pname, const GLfloat *params); -GLAPI PFNGLTEXPARAMETERFVPROC glad_glTexParameterfv; -#define glTexParameterfv glad_glTexParameterfv -typedef void (APIENTRYP PFNGLTEXPARAMETERIPROC)(GLenum target, GLenum pname, GLint param); -GLAPI PFNGLTEXPARAMETERIPROC glad_glTexParameteri; -#define glTexParameteri glad_glTexParameteri -typedef void (APIENTRYP PFNGLTEXPARAMETERIVPROC)(GLenum target, GLenum pname, const GLint *params); -GLAPI PFNGLTEXPARAMETERIVPROC glad_glTexParameteriv; -#define glTexParameteriv glad_glTexParameteriv -typedef void (APIENTRYP PFNGLTEXIMAGE1DPROC)(GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const void *pixels); -GLAPI PFNGLTEXIMAGE1DPROC glad_glTexImage1D; -#define glTexImage1D glad_glTexImage1D -typedef void (APIENTRYP PFNGLTEXIMAGE2DPROC)(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels); -GLAPI PFNGLTEXIMAGE2DPROC glad_glTexImage2D; -#define glTexImage2D glad_glTexImage2D -typedef void (APIENTRYP PFNGLDRAWBUFFERPROC)(GLenum buf); -GLAPI PFNGLDRAWBUFFERPROC glad_glDrawBuffer; -#define glDrawBuffer glad_glDrawBuffer -typedef void (APIENTRYP PFNGLCLEARPROC)(GLbitfield mask); -GLAPI PFNGLCLEARPROC glad_glClear; -#define glClear glad_glClear -typedef void (APIENTRYP PFNGLCLEARCOLORPROC)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); -GLAPI PFNGLCLEARCOLORPROC glad_glClearColor; -#define glClearColor glad_glClearColor -typedef void (APIENTRYP PFNGLCLEARSTENCILPROC)(GLint s); -GLAPI PFNGLCLEARSTENCILPROC glad_glClearStencil; -#define glClearStencil glad_glClearStencil -typedef void (APIENTRYP PFNGLCLEARDEPTHPROC)(GLdouble depth); -GLAPI PFNGLCLEARDEPTHPROC glad_glClearDepth; -#define glClearDepth glad_glClearDepth -typedef void (APIENTRYP PFNGLSTENCILMASKPROC)(GLuint mask); -GLAPI PFNGLSTENCILMASKPROC glad_glStencilMask; -#define glStencilMask glad_glStencilMask -typedef void (APIENTRYP PFNGLCOLORMASKPROC)(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); -GLAPI PFNGLCOLORMASKPROC glad_glColorMask; -#define glColorMask glad_glColorMask -typedef void (APIENTRYP PFNGLDEPTHMASKPROC)(GLboolean flag); -GLAPI PFNGLDEPTHMASKPROC glad_glDepthMask; -#define glDepthMask glad_glDepthMask -typedef void (APIENTRYP PFNGLDISABLEPROC)(GLenum cap); -GLAPI PFNGLDISABLEPROC glad_glDisable; -#define glDisable glad_glDisable -typedef void (APIENTRYP PFNGLENABLEPROC)(GLenum cap); -GLAPI PFNGLENABLEPROC glad_glEnable; -#define glEnable glad_glEnable -typedef void (APIENTRYP PFNGLFINISHPROC)(void); -GLAPI PFNGLFINISHPROC glad_glFinish; -#define glFinish glad_glFinish -typedef void (APIENTRYP PFNGLFLUSHPROC)(void); -GLAPI PFNGLFLUSHPROC glad_glFlush; -#define glFlush glad_glFlush -typedef void (APIENTRYP PFNGLBLENDFUNCPROC)(GLenum sfactor, GLenum dfactor); -GLAPI PFNGLBLENDFUNCPROC glad_glBlendFunc; -#define glBlendFunc glad_glBlendFunc -typedef void (APIENTRYP PFNGLLOGICOPPROC)(GLenum opcode); -GLAPI PFNGLLOGICOPPROC glad_glLogicOp; -#define glLogicOp glad_glLogicOp -typedef void (APIENTRYP PFNGLSTENCILFUNCPROC)(GLenum func, GLint ref, GLuint mask); -GLAPI PFNGLSTENCILFUNCPROC glad_glStencilFunc; -#define glStencilFunc glad_glStencilFunc -typedef void (APIENTRYP PFNGLSTENCILOPPROC)(GLenum fail, GLenum zfail, GLenum zpass); -GLAPI PFNGLSTENCILOPPROC glad_glStencilOp; -#define glStencilOp glad_glStencilOp -typedef void (APIENTRYP PFNGLDEPTHFUNCPROC)(GLenum func); -GLAPI PFNGLDEPTHFUNCPROC glad_glDepthFunc; -#define glDepthFunc glad_glDepthFunc -typedef void (APIENTRYP PFNGLPIXELSTOREFPROC)(GLenum pname, GLfloat param); -GLAPI PFNGLPIXELSTOREFPROC glad_glPixelStoref; -#define glPixelStoref glad_glPixelStoref -typedef void (APIENTRYP PFNGLPIXELSTOREIPROC)(GLenum pname, GLint param); -GLAPI PFNGLPIXELSTOREIPROC glad_glPixelStorei; -#define glPixelStorei glad_glPixelStorei -typedef void (APIENTRYP PFNGLREADBUFFERPROC)(GLenum src); -GLAPI PFNGLREADBUFFERPROC glad_glReadBuffer; -#define glReadBuffer glad_glReadBuffer -typedef void (APIENTRYP PFNGLREADPIXELSPROC)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels); -GLAPI PFNGLREADPIXELSPROC glad_glReadPixels; -#define glReadPixels glad_glReadPixels -typedef void (APIENTRYP PFNGLGETBOOLEANVPROC)(GLenum pname, GLboolean *data); -GLAPI PFNGLGETBOOLEANVPROC glad_glGetBooleanv; -#define glGetBooleanv glad_glGetBooleanv -typedef void (APIENTRYP PFNGLGETDOUBLEVPROC)(GLenum pname, GLdouble *data); -GLAPI PFNGLGETDOUBLEVPROC glad_glGetDoublev; -#define glGetDoublev glad_glGetDoublev -typedef GLenum (APIENTRYP PFNGLGETERRORPROC)(void); -GLAPI PFNGLGETERRORPROC glad_glGetError; -#define glGetError glad_glGetError -typedef void (APIENTRYP PFNGLGETFLOATVPROC)(GLenum pname, GLfloat *data); -GLAPI PFNGLGETFLOATVPROC glad_glGetFloatv; -#define glGetFloatv glad_glGetFloatv -typedef void (APIENTRYP PFNGLGETINTEGERVPROC)(GLenum pname, GLint *data); -GLAPI PFNGLGETINTEGERVPROC glad_glGetIntegerv; -#define glGetIntegerv glad_glGetIntegerv -typedef const GLubyte * (APIENTRYP PFNGLGETSTRINGPROC)(GLenum name); -GLAPI PFNGLGETSTRINGPROC glad_glGetString; -#define glGetString glad_glGetString -typedef void (APIENTRYP PFNGLGETTEXIMAGEPROC)(GLenum target, GLint level, GLenum format, GLenum type, void *pixels); -GLAPI PFNGLGETTEXIMAGEPROC glad_glGetTexImage; -#define glGetTexImage glad_glGetTexImage -typedef void (APIENTRYP PFNGLGETTEXPARAMETERFVPROC)(GLenum target, GLenum pname, GLfloat *params); -GLAPI PFNGLGETTEXPARAMETERFVPROC glad_glGetTexParameterfv; -#define glGetTexParameterfv glad_glGetTexParameterfv -typedef void (APIENTRYP PFNGLGETTEXPARAMETERIVPROC)(GLenum target, GLenum pname, GLint *params); -GLAPI PFNGLGETTEXPARAMETERIVPROC glad_glGetTexParameteriv; -#define glGetTexParameteriv glad_glGetTexParameteriv -typedef void (APIENTRYP PFNGLGETTEXLEVELPARAMETERFVPROC)(GLenum target, GLint level, GLenum pname, GLfloat *params); -GLAPI PFNGLGETTEXLEVELPARAMETERFVPROC glad_glGetTexLevelParameterfv; -#define glGetTexLevelParameterfv glad_glGetTexLevelParameterfv -typedef void (APIENTRYP PFNGLGETTEXLEVELPARAMETERIVPROC)(GLenum target, GLint level, GLenum pname, GLint *params); -GLAPI PFNGLGETTEXLEVELPARAMETERIVPROC glad_glGetTexLevelParameteriv; -#define glGetTexLevelParameteriv glad_glGetTexLevelParameteriv -typedef GLboolean (APIENTRYP PFNGLISENABLEDPROC)(GLenum cap); -GLAPI PFNGLISENABLEDPROC glad_glIsEnabled; -#define glIsEnabled glad_glIsEnabled -typedef void (APIENTRYP PFNGLDEPTHRANGEPROC)(GLdouble n, GLdouble f); -GLAPI PFNGLDEPTHRANGEPROC glad_glDepthRange; -#define glDepthRange glad_glDepthRange -typedef void (APIENTRYP PFNGLVIEWPORTPROC)(GLint x, GLint y, GLsizei width, GLsizei height); -GLAPI PFNGLVIEWPORTPROC glad_glViewport; -#define glViewport glad_glViewport -typedef void (APIENTRYP PFNGLNEWLISTPROC)(GLuint list, GLenum mode); -GLAPI PFNGLNEWLISTPROC glad_glNewList; -#define glNewList glad_glNewList -typedef void (APIENTRYP PFNGLENDLISTPROC)(void); -GLAPI PFNGLENDLISTPROC glad_glEndList; -#define glEndList glad_glEndList -typedef void (APIENTRYP PFNGLCALLLISTPROC)(GLuint list); -GLAPI PFNGLCALLLISTPROC glad_glCallList; -#define glCallList glad_glCallList -typedef void (APIENTRYP PFNGLCALLLISTSPROC)(GLsizei n, GLenum type, const void *lists); -GLAPI PFNGLCALLLISTSPROC glad_glCallLists; -#define glCallLists glad_glCallLists -typedef void (APIENTRYP PFNGLDELETELISTSPROC)(GLuint list, GLsizei range); -GLAPI PFNGLDELETELISTSPROC glad_glDeleteLists; -#define glDeleteLists glad_glDeleteLists -typedef GLuint (APIENTRYP PFNGLGENLISTSPROC)(GLsizei range); -GLAPI PFNGLGENLISTSPROC glad_glGenLists; -#define glGenLists glad_glGenLists -typedef void (APIENTRYP PFNGLLISTBASEPROC)(GLuint base); -GLAPI PFNGLLISTBASEPROC glad_glListBase; -#define glListBase glad_glListBase -typedef void (APIENTRYP PFNGLBEGINPROC)(GLenum mode); -GLAPI PFNGLBEGINPROC glad_glBegin; -#define glBegin glad_glBegin -typedef void (APIENTRYP PFNGLBITMAPPROC)(GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, const GLubyte *bitmap); -GLAPI PFNGLBITMAPPROC glad_glBitmap; -#define glBitmap glad_glBitmap -typedef void (APIENTRYP PFNGLCOLOR3BPROC)(GLbyte red, GLbyte green, GLbyte blue); -GLAPI PFNGLCOLOR3BPROC glad_glColor3b; -#define glColor3b glad_glColor3b -typedef void (APIENTRYP PFNGLCOLOR3BVPROC)(const GLbyte *v); -GLAPI PFNGLCOLOR3BVPROC glad_glColor3bv; -#define glColor3bv glad_glColor3bv -typedef void (APIENTRYP PFNGLCOLOR3DPROC)(GLdouble red, GLdouble green, GLdouble blue); -GLAPI PFNGLCOLOR3DPROC glad_glColor3d; -#define glColor3d glad_glColor3d -typedef void (APIENTRYP PFNGLCOLOR3DVPROC)(const GLdouble *v); -GLAPI PFNGLCOLOR3DVPROC glad_glColor3dv; -#define glColor3dv glad_glColor3dv -typedef void (APIENTRYP PFNGLCOLOR3FPROC)(GLfloat red, GLfloat green, GLfloat blue); -GLAPI PFNGLCOLOR3FPROC glad_glColor3f; -#define glColor3f glad_glColor3f -typedef void (APIENTRYP PFNGLCOLOR3FVPROC)(const GLfloat *v); -GLAPI PFNGLCOLOR3FVPROC glad_glColor3fv; -#define glColor3fv glad_glColor3fv -typedef void (APIENTRYP PFNGLCOLOR3IPROC)(GLint red, GLint green, GLint blue); -GLAPI PFNGLCOLOR3IPROC glad_glColor3i; -#define glColor3i glad_glColor3i -typedef void (APIENTRYP PFNGLCOLOR3IVPROC)(const GLint *v); -GLAPI PFNGLCOLOR3IVPROC glad_glColor3iv; -#define glColor3iv glad_glColor3iv -typedef void (APIENTRYP PFNGLCOLOR3SPROC)(GLshort red, GLshort green, GLshort blue); -GLAPI PFNGLCOLOR3SPROC glad_glColor3s; -#define glColor3s glad_glColor3s -typedef void (APIENTRYP PFNGLCOLOR3SVPROC)(const GLshort *v); -GLAPI PFNGLCOLOR3SVPROC glad_glColor3sv; -#define glColor3sv glad_glColor3sv -typedef void (APIENTRYP PFNGLCOLOR3UBPROC)(GLubyte red, GLubyte green, GLubyte blue); -GLAPI PFNGLCOLOR3UBPROC glad_glColor3ub; -#define glColor3ub glad_glColor3ub -typedef void (APIENTRYP PFNGLCOLOR3UBVPROC)(const GLubyte *v); -GLAPI PFNGLCOLOR3UBVPROC glad_glColor3ubv; -#define glColor3ubv glad_glColor3ubv -typedef void (APIENTRYP PFNGLCOLOR3UIPROC)(GLuint red, GLuint green, GLuint blue); -GLAPI PFNGLCOLOR3UIPROC glad_glColor3ui; -#define glColor3ui glad_glColor3ui -typedef void (APIENTRYP PFNGLCOLOR3UIVPROC)(const GLuint *v); -GLAPI PFNGLCOLOR3UIVPROC glad_glColor3uiv; -#define glColor3uiv glad_glColor3uiv -typedef void (APIENTRYP PFNGLCOLOR3USPROC)(GLushort red, GLushort green, GLushort blue); -GLAPI PFNGLCOLOR3USPROC glad_glColor3us; -#define glColor3us glad_glColor3us -typedef void (APIENTRYP PFNGLCOLOR3USVPROC)(const GLushort *v); -GLAPI PFNGLCOLOR3USVPROC glad_glColor3usv; -#define glColor3usv glad_glColor3usv -typedef void (APIENTRYP PFNGLCOLOR4BPROC)(GLbyte red, GLbyte green, GLbyte blue, GLbyte alpha); -GLAPI PFNGLCOLOR4BPROC glad_glColor4b; -#define glColor4b glad_glColor4b -typedef void (APIENTRYP PFNGLCOLOR4BVPROC)(const GLbyte *v); -GLAPI PFNGLCOLOR4BVPROC glad_glColor4bv; -#define glColor4bv glad_glColor4bv -typedef void (APIENTRYP PFNGLCOLOR4DPROC)(GLdouble red, GLdouble green, GLdouble blue, GLdouble alpha); -GLAPI PFNGLCOLOR4DPROC glad_glColor4d; -#define glColor4d glad_glColor4d -typedef void (APIENTRYP PFNGLCOLOR4DVPROC)(const GLdouble *v); -GLAPI PFNGLCOLOR4DVPROC glad_glColor4dv; -#define glColor4dv glad_glColor4dv -typedef void (APIENTRYP PFNGLCOLOR4FPROC)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); -GLAPI PFNGLCOLOR4FPROC glad_glColor4f; -#define glColor4f glad_glColor4f -typedef void (APIENTRYP PFNGLCOLOR4FVPROC)(const GLfloat *v); -GLAPI PFNGLCOLOR4FVPROC glad_glColor4fv; -#define glColor4fv glad_glColor4fv -typedef void (APIENTRYP PFNGLCOLOR4IPROC)(GLint red, GLint green, GLint blue, GLint alpha); -GLAPI PFNGLCOLOR4IPROC glad_glColor4i; -#define glColor4i glad_glColor4i -typedef void (APIENTRYP PFNGLCOLOR4IVPROC)(const GLint *v); -GLAPI PFNGLCOLOR4IVPROC glad_glColor4iv; -#define glColor4iv glad_glColor4iv -typedef void (APIENTRYP PFNGLCOLOR4SPROC)(GLshort red, GLshort green, GLshort blue, GLshort alpha); -GLAPI PFNGLCOLOR4SPROC glad_glColor4s; -#define glColor4s glad_glColor4s -typedef void (APIENTRYP PFNGLCOLOR4SVPROC)(const GLshort *v); -GLAPI PFNGLCOLOR4SVPROC glad_glColor4sv; -#define glColor4sv glad_glColor4sv -typedef void (APIENTRYP PFNGLCOLOR4UBPROC)(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha); -GLAPI PFNGLCOLOR4UBPROC glad_glColor4ub; -#define glColor4ub glad_glColor4ub -typedef void (APIENTRYP PFNGLCOLOR4UBVPROC)(const GLubyte *v); -GLAPI PFNGLCOLOR4UBVPROC glad_glColor4ubv; -#define glColor4ubv glad_glColor4ubv -typedef void (APIENTRYP PFNGLCOLOR4UIPROC)(GLuint red, GLuint green, GLuint blue, GLuint alpha); -GLAPI PFNGLCOLOR4UIPROC glad_glColor4ui; -#define glColor4ui glad_glColor4ui -typedef void (APIENTRYP PFNGLCOLOR4UIVPROC)(const GLuint *v); -GLAPI PFNGLCOLOR4UIVPROC glad_glColor4uiv; -#define glColor4uiv glad_glColor4uiv -typedef void (APIENTRYP PFNGLCOLOR4USPROC)(GLushort red, GLushort green, GLushort blue, GLushort alpha); -GLAPI PFNGLCOLOR4USPROC glad_glColor4us; -#define glColor4us glad_glColor4us -typedef void (APIENTRYP PFNGLCOLOR4USVPROC)(const GLushort *v); -GLAPI PFNGLCOLOR4USVPROC glad_glColor4usv; -#define glColor4usv glad_glColor4usv -typedef void (APIENTRYP PFNGLEDGEFLAGPROC)(GLboolean flag); -GLAPI PFNGLEDGEFLAGPROC glad_glEdgeFlag; -#define glEdgeFlag glad_glEdgeFlag -typedef void (APIENTRYP PFNGLEDGEFLAGVPROC)(const GLboolean *flag); -GLAPI PFNGLEDGEFLAGVPROC glad_glEdgeFlagv; -#define glEdgeFlagv glad_glEdgeFlagv -typedef void (APIENTRYP PFNGLENDPROC)(void); -GLAPI PFNGLENDPROC glad_glEnd; -#define glEnd glad_glEnd -typedef void (APIENTRYP PFNGLINDEXDPROC)(GLdouble c); -GLAPI PFNGLINDEXDPROC glad_glIndexd; -#define glIndexd glad_glIndexd -typedef void (APIENTRYP PFNGLINDEXDVPROC)(const GLdouble *c); -GLAPI PFNGLINDEXDVPROC glad_glIndexdv; -#define glIndexdv glad_glIndexdv -typedef void (APIENTRYP PFNGLINDEXFPROC)(GLfloat c); -GLAPI PFNGLINDEXFPROC glad_glIndexf; -#define glIndexf glad_glIndexf -typedef void (APIENTRYP PFNGLINDEXFVPROC)(const GLfloat *c); -GLAPI PFNGLINDEXFVPROC glad_glIndexfv; -#define glIndexfv glad_glIndexfv -typedef void (APIENTRYP PFNGLINDEXIPROC)(GLint c); -GLAPI PFNGLINDEXIPROC glad_glIndexi; -#define glIndexi glad_glIndexi -typedef void (APIENTRYP PFNGLINDEXIVPROC)(const GLint *c); -GLAPI PFNGLINDEXIVPROC glad_glIndexiv; -#define glIndexiv glad_glIndexiv -typedef void (APIENTRYP PFNGLINDEXSPROC)(GLshort c); -GLAPI PFNGLINDEXSPROC glad_glIndexs; -#define glIndexs glad_glIndexs -typedef void (APIENTRYP PFNGLINDEXSVPROC)(const GLshort *c); -GLAPI PFNGLINDEXSVPROC glad_glIndexsv; -#define glIndexsv glad_glIndexsv -typedef void (APIENTRYP PFNGLNORMAL3BPROC)(GLbyte nx, GLbyte ny, GLbyte nz); -GLAPI PFNGLNORMAL3BPROC glad_glNormal3b; -#define glNormal3b glad_glNormal3b -typedef void (APIENTRYP PFNGLNORMAL3BVPROC)(const GLbyte *v); -GLAPI PFNGLNORMAL3BVPROC glad_glNormal3bv; -#define glNormal3bv glad_glNormal3bv -typedef void (APIENTRYP PFNGLNORMAL3DPROC)(GLdouble nx, GLdouble ny, GLdouble nz); -GLAPI PFNGLNORMAL3DPROC glad_glNormal3d; -#define glNormal3d glad_glNormal3d -typedef void (APIENTRYP PFNGLNORMAL3DVPROC)(const GLdouble *v); -GLAPI PFNGLNORMAL3DVPROC glad_glNormal3dv; -#define glNormal3dv glad_glNormal3dv -typedef void (APIENTRYP PFNGLNORMAL3FPROC)(GLfloat nx, GLfloat ny, GLfloat nz); -GLAPI PFNGLNORMAL3FPROC glad_glNormal3f; -#define glNormal3f glad_glNormal3f -typedef void (APIENTRYP PFNGLNORMAL3FVPROC)(const GLfloat *v); -GLAPI PFNGLNORMAL3FVPROC glad_glNormal3fv; -#define glNormal3fv glad_glNormal3fv -typedef void (APIENTRYP PFNGLNORMAL3IPROC)(GLint nx, GLint ny, GLint nz); -GLAPI PFNGLNORMAL3IPROC glad_glNormal3i; -#define glNormal3i glad_glNormal3i -typedef void (APIENTRYP PFNGLNORMAL3IVPROC)(const GLint *v); -GLAPI PFNGLNORMAL3IVPROC glad_glNormal3iv; -#define glNormal3iv glad_glNormal3iv -typedef void (APIENTRYP PFNGLNORMAL3SPROC)(GLshort nx, GLshort ny, GLshort nz); -GLAPI PFNGLNORMAL3SPROC glad_glNormal3s; -#define glNormal3s glad_glNormal3s -typedef void (APIENTRYP PFNGLNORMAL3SVPROC)(const GLshort *v); -GLAPI PFNGLNORMAL3SVPROC glad_glNormal3sv; -#define glNormal3sv glad_glNormal3sv -typedef void (APIENTRYP PFNGLRASTERPOS2DPROC)(GLdouble x, GLdouble y); -GLAPI PFNGLRASTERPOS2DPROC glad_glRasterPos2d; -#define glRasterPos2d glad_glRasterPos2d -typedef void (APIENTRYP PFNGLRASTERPOS2DVPROC)(const GLdouble *v); -GLAPI PFNGLRASTERPOS2DVPROC glad_glRasterPos2dv; -#define glRasterPos2dv glad_glRasterPos2dv -typedef void (APIENTRYP PFNGLRASTERPOS2FPROC)(GLfloat x, GLfloat y); -GLAPI PFNGLRASTERPOS2FPROC glad_glRasterPos2f; -#define glRasterPos2f glad_glRasterPos2f -typedef void (APIENTRYP PFNGLRASTERPOS2FVPROC)(const GLfloat *v); -GLAPI PFNGLRASTERPOS2FVPROC glad_glRasterPos2fv; -#define glRasterPos2fv glad_glRasterPos2fv -typedef void (APIENTRYP PFNGLRASTERPOS2IPROC)(GLint x, GLint y); -GLAPI PFNGLRASTERPOS2IPROC glad_glRasterPos2i; -#define glRasterPos2i glad_glRasterPos2i -typedef void (APIENTRYP PFNGLRASTERPOS2IVPROC)(const GLint *v); -GLAPI PFNGLRASTERPOS2IVPROC glad_glRasterPos2iv; -#define glRasterPos2iv glad_glRasterPos2iv -typedef void (APIENTRYP PFNGLRASTERPOS2SPROC)(GLshort x, GLshort y); -GLAPI PFNGLRASTERPOS2SPROC glad_glRasterPos2s; -#define glRasterPos2s glad_glRasterPos2s -typedef void (APIENTRYP PFNGLRASTERPOS2SVPROC)(const GLshort *v); -GLAPI PFNGLRASTERPOS2SVPROC glad_glRasterPos2sv; -#define glRasterPos2sv glad_glRasterPos2sv -typedef void (APIENTRYP PFNGLRASTERPOS3DPROC)(GLdouble x, GLdouble y, GLdouble z); -GLAPI PFNGLRASTERPOS3DPROC glad_glRasterPos3d; -#define glRasterPos3d glad_glRasterPos3d -typedef void (APIENTRYP PFNGLRASTERPOS3DVPROC)(const GLdouble *v); -GLAPI PFNGLRASTERPOS3DVPROC glad_glRasterPos3dv; -#define glRasterPos3dv glad_glRasterPos3dv -typedef void (APIENTRYP PFNGLRASTERPOS3FPROC)(GLfloat x, GLfloat y, GLfloat z); -GLAPI PFNGLRASTERPOS3FPROC glad_glRasterPos3f; -#define glRasterPos3f glad_glRasterPos3f -typedef void (APIENTRYP PFNGLRASTERPOS3FVPROC)(const GLfloat *v); -GLAPI PFNGLRASTERPOS3FVPROC glad_glRasterPos3fv; -#define glRasterPos3fv glad_glRasterPos3fv -typedef void (APIENTRYP PFNGLRASTERPOS3IPROC)(GLint x, GLint y, GLint z); -GLAPI PFNGLRASTERPOS3IPROC glad_glRasterPos3i; -#define glRasterPos3i glad_glRasterPos3i -typedef void (APIENTRYP PFNGLRASTERPOS3IVPROC)(const GLint *v); -GLAPI PFNGLRASTERPOS3IVPROC glad_glRasterPos3iv; -#define glRasterPos3iv glad_glRasterPos3iv -typedef void (APIENTRYP PFNGLRASTERPOS3SPROC)(GLshort x, GLshort y, GLshort z); -GLAPI PFNGLRASTERPOS3SPROC glad_glRasterPos3s; -#define glRasterPos3s glad_glRasterPos3s -typedef void (APIENTRYP PFNGLRASTERPOS3SVPROC)(const GLshort *v); -GLAPI PFNGLRASTERPOS3SVPROC glad_glRasterPos3sv; -#define glRasterPos3sv glad_glRasterPos3sv -typedef void (APIENTRYP PFNGLRASTERPOS4DPROC)(GLdouble x, GLdouble y, GLdouble z, GLdouble w); -GLAPI PFNGLRASTERPOS4DPROC glad_glRasterPos4d; -#define glRasterPos4d glad_glRasterPos4d -typedef void (APIENTRYP PFNGLRASTERPOS4DVPROC)(const GLdouble *v); -GLAPI PFNGLRASTERPOS4DVPROC glad_glRasterPos4dv; -#define glRasterPos4dv glad_glRasterPos4dv -typedef void (APIENTRYP PFNGLRASTERPOS4FPROC)(GLfloat x, GLfloat y, GLfloat z, GLfloat w); -GLAPI PFNGLRASTERPOS4FPROC glad_glRasterPos4f; -#define glRasterPos4f glad_glRasterPos4f -typedef void (APIENTRYP PFNGLRASTERPOS4FVPROC)(const GLfloat *v); -GLAPI PFNGLRASTERPOS4FVPROC glad_glRasterPos4fv; -#define glRasterPos4fv glad_glRasterPos4fv -typedef void (APIENTRYP PFNGLRASTERPOS4IPROC)(GLint x, GLint y, GLint z, GLint w); -GLAPI PFNGLRASTERPOS4IPROC glad_glRasterPos4i; -#define glRasterPos4i glad_glRasterPos4i -typedef void (APIENTRYP PFNGLRASTERPOS4IVPROC)(const GLint *v); -GLAPI PFNGLRASTERPOS4IVPROC glad_glRasterPos4iv; -#define glRasterPos4iv glad_glRasterPos4iv -typedef void (APIENTRYP PFNGLRASTERPOS4SPROC)(GLshort x, GLshort y, GLshort z, GLshort w); -GLAPI PFNGLRASTERPOS4SPROC glad_glRasterPos4s; -#define glRasterPos4s glad_glRasterPos4s -typedef void (APIENTRYP PFNGLRASTERPOS4SVPROC)(const GLshort *v); -GLAPI PFNGLRASTERPOS4SVPROC glad_glRasterPos4sv; -#define glRasterPos4sv glad_glRasterPos4sv -typedef void (APIENTRYP PFNGLRECTDPROC)(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2); -GLAPI PFNGLRECTDPROC glad_glRectd; -#define glRectd glad_glRectd -typedef void (APIENTRYP PFNGLRECTDVPROC)(const GLdouble *v1, const GLdouble *v2); -GLAPI PFNGLRECTDVPROC glad_glRectdv; -#define glRectdv glad_glRectdv -typedef void (APIENTRYP PFNGLRECTFPROC)(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2); -GLAPI PFNGLRECTFPROC glad_glRectf; -#define glRectf glad_glRectf -typedef void (APIENTRYP PFNGLRECTFVPROC)(const GLfloat *v1, const GLfloat *v2); -GLAPI PFNGLRECTFVPROC glad_glRectfv; -#define glRectfv glad_glRectfv -typedef void (APIENTRYP PFNGLRECTIPROC)(GLint x1, GLint y1, GLint x2, GLint y2); -GLAPI PFNGLRECTIPROC glad_glRecti; -#define glRecti glad_glRecti -typedef void (APIENTRYP PFNGLRECTIVPROC)(const GLint *v1, const GLint *v2); -GLAPI PFNGLRECTIVPROC glad_glRectiv; -#define glRectiv glad_glRectiv -typedef void (APIENTRYP PFNGLRECTSPROC)(GLshort x1, GLshort y1, GLshort x2, GLshort y2); -GLAPI PFNGLRECTSPROC glad_glRects; -#define glRects glad_glRects -typedef void (APIENTRYP PFNGLRECTSVPROC)(const GLshort *v1, const GLshort *v2); -GLAPI PFNGLRECTSVPROC glad_glRectsv; -#define glRectsv glad_glRectsv -typedef void (APIENTRYP PFNGLTEXCOORD1DPROC)(GLdouble s); -GLAPI PFNGLTEXCOORD1DPROC glad_glTexCoord1d; -#define glTexCoord1d glad_glTexCoord1d -typedef void (APIENTRYP PFNGLTEXCOORD1DVPROC)(const GLdouble *v); -GLAPI PFNGLTEXCOORD1DVPROC glad_glTexCoord1dv; -#define glTexCoord1dv glad_glTexCoord1dv -typedef void (APIENTRYP PFNGLTEXCOORD1FPROC)(GLfloat s); -GLAPI PFNGLTEXCOORD1FPROC glad_glTexCoord1f; -#define glTexCoord1f glad_glTexCoord1f -typedef void (APIENTRYP PFNGLTEXCOORD1FVPROC)(const GLfloat *v); -GLAPI PFNGLTEXCOORD1FVPROC glad_glTexCoord1fv; -#define glTexCoord1fv glad_glTexCoord1fv -typedef void (APIENTRYP PFNGLTEXCOORD1IPROC)(GLint s); -GLAPI PFNGLTEXCOORD1IPROC glad_glTexCoord1i; -#define glTexCoord1i glad_glTexCoord1i -typedef void (APIENTRYP PFNGLTEXCOORD1IVPROC)(const GLint *v); -GLAPI PFNGLTEXCOORD1IVPROC glad_glTexCoord1iv; -#define glTexCoord1iv glad_glTexCoord1iv -typedef void (APIENTRYP PFNGLTEXCOORD1SPROC)(GLshort s); -GLAPI PFNGLTEXCOORD1SPROC glad_glTexCoord1s; -#define glTexCoord1s glad_glTexCoord1s -typedef void (APIENTRYP PFNGLTEXCOORD1SVPROC)(const GLshort *v); -GLAPI PFNGLTEXCOORD1SVPROC glad_glTexCoord1sv; -#define glTexCoord1sv glad_glTexCoord1sv -typedef void (APIENTRYP PFNGLTEXCOORD2DPROC)(GLdouble s, GLdouble t); -GLAPI PFNGLTEXCOORD2DPROC glad_glTexCoord2d; -#define glTexCoord2d glad_glTexCoord2d -typedef void (APIENTRYP PFNGLTEXCOORD2DVPROC)(const GLdouble *v); -GLAPI PFNGLTEXCOORD2DVPROC glad_glTexCoord2dv; -#define glTexCoord2dv glad_glTexCoord2dv -typedef void (APIENTRYP PFNGLTEXCOORD2FPROC)(GLfloat s, GLfloat t); -GLAPI PFNGLTEXCOORD2FPROC glad_glTexCoord2f; -#define glTexCoord2f glad_glTexCoord2f -typedef void (APIENTRYP PFNGLTEXCOORD2FVPROC)(const GLfloat *v); -GLAPI PFNGLTEXCOORD2FVPROC glad_glTexCoord2fv; -#define glTexCoord2fv glad_glTexCoord2fv -typedef void (APIENTRYP PFNGLTEXCOORD2IPROC)(GLint s, GLint t); -GLAPI PFNGLTEXCOORD2IPROC glad_glTexCoord2i; -#define glTexCoord2i glad_glTexCoord2i -typedef void (APIENTRYP PFNGLTEXCOORD2IVPROC)(const GLint *v); -GLAPI PFNGLTEXCOORD2IVPROC glad_glTexCoord2iv; -#define glTexCoord2iv glad_glTexCoord2iv -typedef void (APIENTRYP PFNGLTEXCOORD2SPROC)(GLshort s, GLshort t); -GLAPI PFNGLTEXCOORD2SPROC glad_glTexCoord2s; -#define glTexCoord2s glad_glTexCoord2s -typedef void (APIENTRYP PFNGLTEXCOORD2SVPROC)(const GLshort *v); -GLAPI PFNGLTEXCOORD2SVPROC glad_glTexCoord2sv; -#define glTexCoord2sv glad_glTexCoord2sv -typedef void (APIENTRYP PFNGLTEXCOORD3DPROC)(GLdouble s, GLdouble t, GLdouble r); -GLAPI PFNGLTEXCOORD3DPROC glad_glTexCoord3d; -#define glTexCoord3d glad_glTexCoord3d -typedef void (APIENTRYP PFNGLTEXCOORD3DVPROC)(const GLdouble *v); -GLAPI PFNGLTEXCOORD3DVPROC glad_glTexCoord3dv; -#define glTexCoord3dv glad_glTexCoord3dv -typedef void (APIENTRYP PFNGLTEXCOORD3FPROC)(GLfloat s, GLfloat t, GLfloat r); -GLAPI PFNGLTEXCOORD3FPROC glad_glTexCoord3f; -#define glTexCoord3f glad_glTexCoord3f -typedef void (APIENTRYP PFNGLTEXCOORD3FVPROC)(const GLfloat *v); -GLAPI PFNGLTEXCOORD3FVPROC glad_glTexCoord3fv; -#define glTexCoord3fv glad_glTexCoord3fv -typedef void (APIENTRYP PFNGLTEXCOORD3IPROC)(GLint s, GLint t, GLint r); -GLAPI PFNGLTEXCOORD3IPROC glad_glTexCoord3i; -#define glTexCoord3i glad_glTexCoord3i -typedef void (APIENTRYP PFNGLTEXCOORD3IVPROC)(const GLint *v); -GLAPI PFNGLTEXCOORD3IVPROC glad_glTexCoord3iv; -#define glTexCoord3iv glad_glTexCoord3iv -typedef void (APIENTRYP PFNGLTEXCOORD3SPROC)(GLshort s, GLshort t, GLshort r); -GLAPI PFNGLTEXCOORD3SPROC glad_glTexCoord3s; -#define glTexCoord3s glad_glTexCoord3s -typedef void (APIENTRYP PFNGLTEXCOORD3SVPROC)(const GLshort *v); -GLAPI PFNGLTEXCOORD3SVPROC glad_glTexCoord3sv; -#define glTexCoord3sv glad_glTexCoord3sv -typedef void (APIENTRYP PFNGLTEXCOORD4DPROC)(GLdouble s, GLdouble t, GLdouble r, GLdouble q); -GLAPI PFNGLTEXCOORD4DPROC glad_glTexCoord4d; -#define glTexCoord4d glad_glTexCoord4d -typedef void (APIENTRYP PFNGLTEXCOORD4DVPROC)(const GLdouble *v); -GLAPI PFNGLTEXCOORD4DVPROC glad_glTexCoord4dv; -#define glTexCoord4dv glad_glTexCoord4dv -typedef void (APIENTRYP PFNGLTEXCOORD4FPROC)(GLfloat s, GLfloat t, GLfloat r, GLfloat q); -GLAPI PFNGLTEXCOORD4FPROC glad_glTexCoord4f; -#define glTexCoord4f glad_glTexCoord4f -typedef void (APIENTRYP PFNGLTEXCOORD4FVPROC)(const GLfloat *v); -GLAPI PFNGLTEXCOORD4FVPROC glad_glTexCoord4fv; -#define glTexCoord4fv glad_glTexCoord4fv -typedef void (APIENTRYP PFNGLTEXCOORD4IPROC)(GLint s, GLint t, GLint r, GLint q); -GLAPI PFNGLTEXCOORD4IPROC glad_glTexCoord4i; -#define glTexCoord4i glad_glTexCoord4i -typedef void (APIENTRYP PFNGLTEXCOORD4IVPROC)(const GLint *v); -GLAPI PFNGLTEXCOORD4IVPROC glad_glTexCoord4iv; -#define glTexCoord4iv glad_glTexCoord4iv -typedef void (APIENTRYP PFNGLTEXCOORD4SPROC)(GLshort s, GLshort t, GLshort r, GLshort q); -GLAPI PFNGLTEXCOORD4SPROC glad_glTexCoord4s; -#define glTexCoord4s glad_glTexCoord4s -typedef void (APIENTRYP PFNGLTEXCOORD4SVPROC)(const GLshort *v); -GLAPI PFNGLTEXCOORD4SVPROC glad_glTexCoord4sv; -#define glTexCoord4sv glad_glTexCoord4sv -typedef void (APIENTRYP PFNGLVERTEX2DPROC)(GLdouble x, GLdouble y); -GLAPI PFNGLVERTEX2DPROC glad_glVertex2d; -#define glVertex2d glad_glVertex2d -typedef void (APIENTRYP PFNGLVERTEX2DVPROC)(const GLdouble *v); -GLAPI PFNGLVERTEX2DVPROC glad_glVertex2dv; -#define glVertex2dv glad_glVertex2dv -typedef void (APIENTRYP PFNGLVERTEX2FPROC)(GLfloat x, GLfloat y); -GLAPI PFNGLVERTEX2FPROC glad_glVertex2f; -#define glVertex2f glad_glVertex2f -typedef void (APIENTRYP PFNGLVERTEX2FVPROC)(const GLfloat *v); -GLAPI PFNGLVERTEX2FVPROC glad_glVertex2fv; -#define glVertex2fv glad_glVertex2fv -typedef void (APIENTRYP PFNGLVERTEX2IPROC)(GLint x, GLint y); -GLAPI PFNGLVERTEX2IPROC glad_glVertex2i; -#define glVertex2i glad_glVertex2i -typedef void (APIENTRYP PFNGLVERTEX2IVPROC)(const GLint *v); -GLAPI PFNGLVERTEX2IVPROC glad_glVertex2iv; -#define glVertex2iv glad_glVertex2iv -typedef void (APIENTRYP PFNGLVERTEX2SPROC)(GLshort x, GLshort y); -GLAPI PFNGLVERTEX2SPROC glad_glVertex2s; -#define glVertex2s glad_glVertex2s -typedef void (APIENTRYP PFNGLVERTEX2SVPROC)(const GLshort *v); -GLAPI PFNGLVERTEX2SVPROC glad_glVertex2sv; -#define glVertex2sv glad_glVertex2sv -typedef void (APIENTRYP PFNGLVERTEX3DPROC)(GLdouble x, GLdouble y, GLdouble z); -GLAPI PFNGLVERTEX3DPROC glad_glVertex3d; -#define glVertex3d glad_glVertex3d -typedef void (APIENTRYP PFNGLVERTEX3DVPROC)(const GLdouble *v); -GLAPI PFNGLVERTEX3DVPROC glad_glVertex3dv; -#define glVertex3dv glad_glVertex3dv -typedef void (APIENTRYP PFNGLVERTEX3FPROC)(GLfloat x, GLfloat y, GLfloat z); -GLAPI PFNGLVERTEX3FPROC glad_glVertex3f; -#define glVertex3f glad_glVertex3f -typedef void (APIENTRYP PFNGLVERTEX3FVPROC)(const GLfloat *v); -GLAPI PFNGLVERTEX3FVPROC glad_glVertex3fv; -#define glVertex3fv glad_glVertex3fv -typedef void (APIENTRYP PFNGLVERTEX3IPROC)(GLint x, GLint y, GLint z); -GLAPI PFNGLVERTEX3IPROC glad_glVertex3i; -#define glVertex3i glad_glVertex3i -typedef void (APIENTRYP PFNGLVERTEX3IVPROC)(const GLint *v); -GLAPI PFNGLVERTEX3IVPROC glad_glVertex3iv; -#define glVertex3iv glad_glVertex3iv -typedef void (APIENTRYP PFNGLVERTEX3SPROC)(GLshort x, GLshort y, GLshort z); -GLAPI PFNGLVERTEX3SPROC glad_glVertex3s; -#define glVertex3s glad_glVertex3s -typedef void (APIENTRYP PFNGLVERTEX3SVPROC)(const GLshort *v); -GLAPI PFNGLVERTEX3SVPROC glad_glVertex3sv; -#define glVertex3sv glad_glVertex3sv -typedef void (APIENTRYP PFNGLVERTEX4DPROC)(GLdouble x, GLdouble y, GLdouble z, GLdouble w); -GLAPI PFNGLVERTEX4DPROC glad_glVertex4d; -#define glVertex4d glad_glVertex4d -typedef void (APIENTRYP PFNGLVERTEX4DVPROC)(const GLdouble *v); -GLAPI PFNGLVERTEX4DVPROC glad_glVertex4dv; -#define glVertex4dv glad_glVertex4dv -typedef void (APIENTRYP PFNGLVERTEX4FPROC)(GLfloat x, GLfloat y, GLfloat z, GLfloat w); -GLAPI PFNGLVERTEX4FPROC glad_glVertex4f; -#define glVertex4f glad_glVertex4f -typedef void (APIENTRYP PFNGLVERTEX4FVPROC)(const GLfloat *v); -GLAPI PFNGLVERTEX4FVPROC glad_glVertex4fv; -#define glVertex4fv glad_glVertex4fv -typedef void (APIENTRYP PFNGLVERTEX4IPROC)(GLint x, GLint y, GLint z, GLint w); -GLAPI PFNGLVERTEX4IPROC glad_glVertex4i; -#define glVertex4i glad_glVertex4i -typedef void (APIENTRYP PFNGLVERTEX4IVPROC)(const GLint *v); -GLAPI PFNGLVERTEX4IVPROC glad_glVertex4iv; -#define glVertex4iv glad_glVertex4iv -typedef void (APIENTRYP PFNGLVERTEX4SPROC)(GLshort x, GLshort y, GLshort z, GLshort w); -GLAPI PFNGLVERTEX4SPROC glad_glVertex4s; -#define glVertex4s glad_glVertex4s -typedef void (APIENTRYP PFNGLVERTEX4SVPROC)(const GLshort *v); -GLAPI PFNGLVERTEX4SVPROC glad_glVertex4sv; -#define glVertex4sv glad_glVertex4sv -typedef void (APIENTRYP PFNGLCLIPPLANEPROC)(GLenum plane, const GLdouble *equation); -GLAPI PFNGLCLIPPLANEPROC glad_glClipPlane; -#define glClipPlane glad_glClipPlane -typedef void (APIENTRYP PFNGLCOLORMATERIALPROC)(GLenum face, GLenum mode); -GLAPI PFNGLCOLORMATERIALPROC glad_glColorMaterial; -#define glColorMaterial glad_glColorMaterial -typedef void (APIENTRYP PFNGLFOGFPROC)(GLenum pname, GLfloat param); -GLAPI PFNGLFOGFPROC glad_glFogf; -#define glFogf glad_glFogf -typedef void (APIENTRYP PFNGLFOGFVPROC)(GLenum pname, const GLfloat *params); -GLAPI PFNGLFOGFVPROC glad_glFogfv; -#define glFogfv glad_glFogfv -typedef void (APIENTRYP PFNGLFOGIPROC)(GLenum pname, GLint param); -GLAPI PFNGLFOGIPROC glad_glFogi; -#define glFogi glad_glFogi -typedef void (APIENTRYP PFNGLFOGIVPROC)(GLenum pname, const GLint *params); -GLAPI PFNGLFOGIVPROC glad_glFogiv; -#define glFogiv glad_glFogiv -typedef void (APIENTRYP PFNGLLIGHTFPROC)(GLenum light, GLenum pname, GLfloat param); -GLAPI PFNGLLIGHTFPROC glad_glLightf; -#define glLightf glad_glLightf -typedef void (APIENTRYP PFNGLLIGHTFVPROC)(GLenum light, GLenum pname, const GLfloat *params); -GLAPI PFNGLLIGHTFVPROC glad_glLightfv; -#define glLightfv glad_glLightfv -typedef void (APIENTRYP PFNGLLIGHTIPROC)(GLenum light, GLenum pname, GLint param); -GLAPI PFNGLLIGHTIPROC glad_glLighti; -#define glLighti glad_glLighti -typedef void (APIENTRYP PFNGLLIGHTIVPROC)(GLenum light, GLenum pname, const GLint *params); -GLAPI PFNGLLIGHTIVPROC glad_glLightiv; -#define glLightiv glad_glLightiv -typedef void (APIENTRYP PFNGLLIGHTMODELFPROC)(GLenum pname, GLfloat param); -GLAPI PFNGLLIGHTMODELFPROC glad_glLightModelf; -#define glLightModelf glad_glLightModelf -typedef void (APIENTRYP PFNGLLIGHTMODELFVPROC)(GLenum pname, const GLfloat *params); -GLAPI PFNGLLIGHTMODELFVPROC glad_glLightModelfv; -#define glLightModelfv glad_glLightModelfv -typedef void (APIENTRYP PFNGLLIGHTMODELIPROC)(GLenum pname, GLint param); -GLAPI PFNGLLIGHTMODELIPROC glad_glLightModeli; -#define glLightModeli glad_glLightModeli -typedef void (APIENTRYP PFNGLLIGHTMODELIVPROC)(GLenum pname, const GLint *params); -GLAPI PFNGLLIGHTMODELIVPROC glad_glLightModeliv; -#define glLightModeliv glad_glLightModeliv -typedef void (APIENTRYP PFNGLLINESTIPPLEPROC)(GLint factor, GLushort pattern); -GLAPI PFNGLLINESTIPPLEPROC glad_glLineStipple; -#define glLineStipple glad_glLineStipple -typedef void (APIENTRYP PFNGLMATERIALFPROC)(GLenum face, GLenum pname, GLfloat param); -GLAPI PFNGLMATERIALFPROC glad_glMaterialf; -#define glMaterialf glad_glMaterialf -typedef void (APIENTRYP PFNGLMATERIALFVPROC)(GLenum face, GLenum pname, const GLfloat *params); -GLAPI PFNGLMATERIALFVPROC glad_glMaterialfv; -#define glMaterialfv glad_glMaterialfv -typedef void (APIENTRYP PFNGLMATERIALIPROC)(GLenum face, GLenum pname, GLint param); -GLAPI PFNGLMATERIALIPROC glad_glMateriali; -#define glMateriali glad_glMateriali -typedef void (APIENTRYP PFNGLMATERIALIVPROC)(GLenum face, GLenum pname, const GLint *params); -GLAPI PFNGLMATERIALIVPROC glad_glMaterialiv; -#define glMaterialiv glad_glMaterialiv -typedef void (APIENTRYP PFNGLPOLYGONSTIPPLEPROC)(const GLubyte *mask); -GLAPI PFNGLPOLYGONSTIPPLEPROC glad_glPolygonStipple; -#define glPolygonStipple glad_glPolygonStipple -typedef void (APIENTRYP PFNGLSHADEMODELPROC)(GLenum mode); -GLAPI PFNGLSHADEMODELPROC glad_glShadeModel; -#define glShadeModel glad_glShadeModel -typedef void (APIENTRYP PFNGLTEXENVFPROC)(GLenum target, GLenum pname, GLfloat param); -GLAPI PFNGLTEXENVFPROC glad_glTexEnvf; -#define glTexEnvf glad_glTexEnvf -typedef void (APIENTRYP PFNGLTEXENVFVPROC)(GLenum target, GLenum pname, const GLfloat *params); -GLAPI PFNGLTEXENVFVPROC glad_glTexEnvfv; -#define glTexEnvfv glad_glTexEnvfv -typedef void (APIENTRYP PFNGLTEXENVIPROC)(GLenum target, GLenum pname, GLint param); -GLAPI PFNGLTEXENVIPROC glad_glTexEnvi; -#define glTexEnvi glad_glTexEnvi -typedef void (APIENTRYP PFNGLTEXENVIVPROC)(GLenum target, GLenum pname, const GLint *params); -GLAPI PFNGLTEXENVIVPROC glad_glTexEnviv; -#define glTexEnviv glad_glTexEnviv -typedef void (APIENTRYP PFNGLTEXGENDPROC)(GLenum coord, GLenum pname, GLdouble param); -GLAPI PFNGLTEXGENDPROC glad_glTexGend; -#define glTexGend glad_glTexGend -typedef void (APIENTRYP PFNGLTEXGENDVPROC)(GLenum coord, GLenum pname, const GLdouble *params); -GLAPI PFNGLTEXGENDVPROC glad_glTexGendv; -#define glTexGendv glad_glTexGendv -typedef void (APIENTRYP PFNGLTEXGENFPROC)(GLenum coord, GLenum pname, GLfloat param); -GLAPI PFNGLTEXGENFPROC glad_glTexGenf; -#define glTexGenf glad_glTexGenf -typedef void (APIENTRYP PFNGLTEXGENFVPROC)(GLenum coord, GLenum pname, const GLfloat *params); -GLAPI PFNGLTEXGENFVPROC glad_glTexGenfv; -#define glTexGenfv glad_glTexGenfv -typedef void (APIENTRYP PFNGLTEXGENIPROC)(GLenum coord, GLenum pname, GLint param); -GLAPI PFNGLTEXGENIPROC glad_glTexGeni; -#define glTexGeni glad_glTexGeni -typedef void (APIENTRYP PFNGLTEXGENIVPROC)(GLenum coord, GLenum pname, const GLint *params); -GLAPI PFNGLTEXGENIVPROC glad_glTexGeniv; -#define glTexGeniv glad_glTexGeniv -typedef void (APIENTRYP PFNGLFEEDBACKBUFFERPROC)(GLsizei size, GLenum type, GLfloat *buffer); -GLAPI PFNGLFEEDBACKBUFFERPROC glad_glFeedbackBuffer; -#define glFeedbackBuffer glad_glFeedbackBuffer -typedef void (APIENTRYP PFNGLSELECTBUFFERPROC)(GLsizei size, GLuint *buffer); -GLAPI PFNGLSELECTBUFFERPROC glad_glSelectBuffer; -#define glSelectBuffer glad_glSelectBuffer -typedef GLint (APIENTRYP PFNGLRENDERMODEPROC)(GLenum mode); -GLAPI PFNGLRENDERMODEPROC glad_glRenderMode; -#define glRenderMode glad_glRenderMode -typedef void (APIENTRYP PFNGLINITNAMESPROC)(void); -GLAPI PFNGLINITNAMESPROC glad_glInitNames; -#define glInitNames glad_glInitNames -typedef void (APIENTRYP PFNGLLOADNAMEPROC)(GLuint name); -GLAPI PFNGLLOADNAMEPROC glad_glLoadName; -#define glLoadName glad_glLoadName -typedef void (APIENTRYP PFNGLPASSTHROUGHPROC)(GLfloat token); -GLAPI PFNGLPASSTHROUGHPROC glad_glPassThrough; -#define glPassThrough glad_glPassThrough -typedef void (APIENTRYP PFNGLPOPNAMEPROC)(void); -GLAPI PFNGLPOPNAMEPROC glad_glPopName; -#define glPopName glad_glPopName -typedef void (APIENTRYP PFNGLPUSHNAMEPROC)(GLuint name); -GLAPI PFNGLPUSHNAMEPROC glad_glPushName; -#define glPushName glad_glPushName -typedef void (APIENTRYP PFNGLCLEARACCUMPROC)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); -GLAPI PFNGLCLEARACCUMPROC glad_glClearAccum; -#define glClearAccum glad_glClearAccum -typedef void (APIENTRYP PFNGLCLEARINDEXPROC)(GLfloat c); -GLAPI PFNGLCLEARINDEXPROC glad_glClearIndex; -#define glClearIndex glad_glClearIndex -typedef void (APIENTRYP PFNGLINDEXMASKPROC)(GLuint mask); -GLAPI PFNGLINDEXMASKPROC glad_glIndexMask; -#define glIndexMask glad_glIndexMask -typedef void (APIENTRYP PFNGLACCUMPROC)(GLenum op, GLfloat value); -GLAPI PFNGLACCUMPROC glad_glAccum; -#define glAccum glad_glAccum -typedef void (APIENTRYP PFNGLPOPATTRIBPROC)(void); -GLAPI PFNGLPOPATTRIBPROC glad_glPopAttrib; -#define glPopAttrib glad_glPopAttrib -typedef void (APIENTRYP PFNGLPUSHATTRIBPROC)(GLbitfield mask); -GLAPI PFNGLPUSHATTRIBPROC glad_glPushAttrib; -#define glPushAttrib glad_glPushAttrib -typedef void (APIENTRYP PFNGLMAP1DPROC)(GLenum target, GLdouble u1, GLdouble u2, GLint stride, GLint order, const GLdouble *points); -GLAPI PFNGLMAP1DPROC glad_glMap1d; -#define glMap1d glad_glMap1d -typedef void (APIENTRYP PFNGLMAP1FPROC)(GLenum target, GLfloat u1, GLfloat u2, GLint stride, GLint order, const GLfloat *points); -GLAPI PFNGLMAP1FPROC glad_glMap1f; -#define glMap1f glad_glMap1f -typedef void (APIENTRYP PFNGLMAP2DPROC)(GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble *points); -GLAPI PFNGLMAP2DPROC glad_glMap2d; -#define glMap2d glad_glMap2d -typedef void (APIENTRYP PFNGLMAP2FPROC)(GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat *points); -GLAPI PFNGLMAP2FPROC glad_glMap2f; -#define glMap2f glad_glMap2f -typedef void (APIENTRYP PFNGLMAPGRID1DPROC)(GLint un, GLdouble u1, GLdouble u2); -GLAPI PFNGLMAPGRID1DPROC glad_glMapGrid1d; -#define glMapGrid1d glad_glMapGrid1d -typedef void (APIENTRYP PFNGLMAPGRID1FPROC)(GLint un, GLfloat u1, GLfloat u2); -GLAPI PFNGLMAPGRID1FPROC glad_glMapGrid1f; -#define glMapGrid1f glad_glMapGrid1f -typedef void (APIENTRYP PFNGLMAPGRID2DPROC)(GLint un, GLdouble u1, GLdouble u2, GLint vn, GLdouble v1, GLdouble v2); -GLAPI PFNGLMAPGRID2DPROC glad_glMapGrid2d; -#define glMapGrid2d glad_glMapGrid2d -typedef void (APIENTRYP PFNGLMAPGRID2FPROC)(GLint un, GLfloat u1, GLfloat u2, GLint vn, GLfloat v1, GLfloat v2); -GLAPI PFNGLMAPGRID2FPROC glad_glMapGrid2f; -#define glMapGrid2f glad_glMapGrid2f -typedef void (APIENTRYP PFNGLEVALCOORD1DPROC)(GLdouble u); -GLAPI PFNGLEVALCOORD1DPROC glad_glEvalCoord1d; -#define glEvalCoord1d glad_glEvalCoord1d -typedef void (APIENTRYP PFNGLEVALCOORD1DVPROC)(const GLdouble *u); -GLAPI PFNGLEVALCOORD1DVPROC glad_glEvalCoord1dv; -#define glEvalCoord1dv glad_glEvalCoord1dv -typedef void (APIENTRYP PFNGLEVALCOORD1FPROC)(GLfloat u); -GLAPI PFNGLEVALCOORD1FPROC glad_glEvalCoord1f; -#define glEvalCoord1f glad_glEvalCoord1f -typedef void (APIENTRYP PFNGLEVALCOORD1FVPROC)(const GLfloat *u); -GLAPI PFNGLEVALCOORD1FVPROC glad_glEvalCoord1fv; -#define glEvalCoord1fv glad_glEvalCoord1fv -typedef void (APIENTRYP PFNGLEVALCOORD2DPROC)(GLdouble u, GLdouble v); -GLAPI PFNGLEVALCOORD2DPROC glad_glEvalCoord2d; -#define glEvalCoord2d glad_glEvalCoord2d -typedef void (APIENTRYP PFNGLEVALCOORD2DVPROC)(const GLdouble *u); -GLAPI PFNGLEVALCOORD2DVPROC glad_glEvalCoord2dv; -#define glEvalCoord2dv glad_glEvalCoord2dv -typedef void (APIENTRYP PFNGLEVALCOORD2FPROC)(GLfloat u, GLfloat v); -GLAPI PFNGLEVALCOORD2FPROC glad_glEvalCoord2f; -#define glEvalCoord2f glad_glEvalCoord2f -typedef void (APIENTRYP PFNGLEVALCOORD2FVPROC)(const GLfloat *u); -GLAPI PFNGLEVALCOORD2FVPROC glad_glEvalCoord2fv; -#define glEvalCoord2fv glad_glEvalCoord2fv -typedef void (APIENTRYP PFNGLEVALMESH1PROC)(GLenum mode, GLint i1, GLint i2); -GLAPI PFNGLEVALMESH1PROC glad_glEvalMesh1; -#define glEvalMesh1 glad_glEvalMesh1 -typedef void (APIENTRYP PFNGLEVALPOINT1PROC)(GLint i); -GLAPI PFNGLEVALPOINT1PROC glad_glEvalPoint1; -#define glEvalPoint1 glad_glEvalPoint1 -typedef void (APIENTRYP PFNGLEVALMESH2PROC)(GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2); -GLAPI PFNGLEVALMESH2PROC glad_glEvalMesh2; -#define glEvalMesh2 glad_glEvalMesh2 -typedef void (APIENTRYP PFNGLEVALPOINT2PROC)(GLint i, GLint j); -GLAPI PFNGLEVALPOINT2PROC glad_glEvalPoint2; -#define glEvalPoint2 glad_glEvalPoint2 -typedef void (APIENTRYP PFNGLALPHAFUNCPROC)(GLenum func, GLfloat ref); -GLAPI PFNGLALPHAFUNCPROC glad_glAlphaFunc; -#define glAlphaFunc glad_glAlphaFunc -typedef void (APIENTRYP PFNGLPIXELZOOMPROC)(GLfloat xfactor, GLfloat yfactor); -GLAPI PFNGLPIXELZOOMPROC glad_glPixelZoom; -#define glPixelZoom glad_glPixelZoom -typedef void (APIENTRYP PFNGLPIXELTRANSFERFPROC)(GLenum pname, GLfloat param); -GLAPI PFNGLPIXELTRANSFERFPROC glad_glPixelTransferf; -#define glPixelTransferf glad_glPixelTransferf -typedef void (APIENTRYP PFNGLPIXELTRANSFERIPROC)(GLenum pname, GLint param); -GLAPI PFNGLPIXELTRANSFERIPROC glad_glPixelTransferi; -#define glPixelTransferi glad_glPixelTransferi -typedef void (APIENTRYP PFNGLPIXELMAPFVPROC)(GLenum map, GLsizei mapsize, const GLfloat *values); -GLAPI PFNGLPIXELMAPFVPROC glad_glPixelMapfv; -#define glPixelMapfv glad_glPixelMapfv -typedef void (APIENTRYP PFNGLPIXELMAPUIVPROC)(GLenum map, GLsizei mapsize, const GLuint *values); -GLAPI PFNGLPIXELMAPUIVPROC glad_glPixelMapuiv; -#define glPixelMapuiv glad_glPixelMapuiv -typedef void (APIENTRYP PFNGLPIXELMAPUSVPROC)(GLenum map, GLsizei mapsize, const GLushort *values); -GLAPI PFNGLPIXELMAPUSVPROC glad_glPixelMapusv; -#define glPixelMapusv glad_glPixelMapusv -typedef void (APIENTRYP PFNGLCOPYPIXELSPROC)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type); -GLAPI PFNGLCOPYPIXELSPROC glad_glCopyPixels; -#define glCopyPixels glad_glCopyPixels -typedef void (APIENTRYP PFNGLDRAWPIXELSPROC)(GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels); -GLAPI PFNGLDRAWPIXELSPROC glad_glDrawPixels; -#define glDrawPixels glad_glDrawPixels -typedef void (APIENTRYP PFNGLGETCLIPPLANEPROC)(GLenum plane, GLdouble *equation); -GLAPI PFNGLGETCLIPPLANEPROC glad_glGetClipPlane; -#define glGetClipPlane glad_glGetClipPlane -typedef void (APIENTRYP PFNGLGETLIGHTFVPROC)(GLenum light, GLenum pname, GLfloat *params); -GLAPI PFNGLGETLIGHTFVPROC glad_glGetLightfv; -#define glGetLightfv glad_glGetLightfv -typedef void (APIENTRYP PFNGLGETLIGHTIVPROC)(GLenum light, GLenum pname, GLint *params); -GLAPI PFNGLGETLIGHTIVPROC glad_glGetLightiv; -#define glGetLightiv glad_glGetLightiv -typedef void (APIENTRYP PFNGLGETMAPDVPROC)(GLenum target, GLenum query, GLdouble *v); -GLAPI PFNGLGETMAPDVPROC glad_glGetMapdv; -#define glGetMapdv glad_glGetMapdv -typedef void (APIENTRYP PFNGLGETMAPFVPROC)(GLenum target, GLenum query, GLfloat *v); -GLAPI PFNGLGETMAPFVPROC glad_glGetMapfv; -#define glGetMapfv glad_glGetMapfv -typedef void (APIENTRYP PFNGLGETMAPIVPROC)(GLenum target, GLenum query, GLint *v); -GLAPI PFNGLGETMAPIVPROC glad_glGetMapiv; -#define glGetMapiv glad_glGetMapiv -typedef void (APIENTRYP PFNGLGETMATERIALFVPROC)(GLenum face, GLenum pname, GLfloat *params); -GLAPI PFNGLGETMATERIALFVPROC glad_glGetMaterialfv; -#define glGetMaterialfv glad_glGetMaterialfv -typedef void (APIENTRYP PFNGLGETMATERIALIVPROC)(GLenum face, GLenum pname, GLint *params); -GLAPI PFNGLGETMATERIALIVPROC glad_glGetMaterialiv; -#define glGetMaterialiv glad_glGetMaterialiv -typedef void (APIENTRYP PFNGLGETPIXELMAPFVPROC)(GLenum map, GLfloat *values); -GLAPI PFNGLGETPIXELMAPFVPROC glad_glGetPixelMapfv; -#define glGetPixelMapfv glad_glGetPixelMapfv -typedef void (APIENTRYP PFNGLGETPIXELMAPUIVPROC)(GLenum map, GLuint *values); -GLAPI PFNGLGETPIXELMAPUIVPROC glad_glGetPixelMapuiv; -#define glGetPixelMapuiv glad_glGetPixelMapuiv -typedef void (APIENTRYP PFNGLGETPIXELMAPUSVPROC)(GLenum map, GLushort *values); -GLAPI PFNGLGETPIXELMAPUSVPROC glad_glGetPixelMapusv; -#define glGetPixelMapusv glad_glGetPixelMapusv -typedef void (APIENTRYP PFNGLGETPOLYGONSTIPPLEPROC)(GLubyte *mask); -GLAPI PFNGLGETPOLYGONSTIPPLEPROC glad_glGetPolygonStipple; -#define glGetPolygonStipple glad_glGetPolygonStipple -typedef void (APIENTRYP PFNGLGETTEXENVFVPROC)(GLenum target, GLenum pname, GLfloat *params); -GLAPI PFNGLGETTEXENVFVPROC glad_glGetTexEnvfv; -#define glGetTexEnvfv glad_glGetTexEnvfv -typedef void (APIENTRYP PFNGLGETTEXENVIVPROC)(GLenum target, GLenum pname, GLint *params); -GLAPI PFNGLGETTEXENVIVPROC glad_glGetTexEnviv; -#define glGetTexEnviv glad_glGetTexEnviv -typedef void (APIENTRYP PFNGLGETTEXGENDVPROC)(GLenum coord, GLenum pname, GLdouble *params); -GLAPI PFNGLGETTEXGENDVPROC glad_glGetTexGendv; -#define glGetTexGendv glad_glGetTexGendv -typedef void (APIENTRYP PFNGLGETTEXGENFVPROC)(GLenum coord, GLenum pname, GLfloat *params); -GLAPI PFNGLGETTEXGENFVPROC glad_glGetTexGenfv; -#define glGetTexGenfv glad_glGetTexGenfv -typedef void (APIENTRYP PFNGLGETTEXGENIVPROC)(GLenum coord, GLenum pname, GLint *params); -GLAPI PFNGLGETTEXGENIVPROC glad_glGetTexGeniv; -#define glGetTexGeniv glad_glGetTexGeniv -typedef GLboolean (APIENTRYP PFNGLISLISTPROC)(GLuint list); -GLAPI PFNGLISLISTPROC glad_glIsList; -#define glIsList glad_glIsList -typedef void (APIENTRYP PFNGLFRUSTUMPROC)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); -GLAPI PFNGLFRUSTUMPROC glad_glFrustum; -#define glFrustum glad_glFrustum -typedef void (APIENTRYP PFNGLLOADIDENTITYPROC)(void); -GLAPI PFNGLLOADIDENTITYPROC glad_glLoadIdentity; -#define glLoadIdentity glad_glLoadIdentity -typedef void (APIENTRYP PFNGLLOADMATRIXFPROC)(const GLfloat *m); -GLAPI PFNGLLOADMATRIXFPROC glad_glLoadMatrixf; -#define glLoadMatrixf glad_glLoadMatrixf -typedef void (APIENTRYP PFNGLLOADMATRIXDPROC)(const GLdouble *m); -GLAPI PFNGLLOADMATRIXDPROC glad_glLoadMatrixd; -#define glLoadMatrixd glad_glLoadMatrixd -typedef void (APIENTRYP PFNGLMATRIXMODEPROC)(GLenum mode); -GLAPI PFNGLMATRIXMODEPROC glad_glMatrixMode; -#define glMatrixMode glad_glMatrixMode -typedef void (APIENTRYP PFNGLMULTMATRIXFPROC)(const GLfloat *m); -GLAPI PFNGLMULTMATRIXFPROC glad_glMultMatrixf; -#define glMultMatrixf glad_glMultMatrixf -typedef void (APIENTRYP PFNGLMULTMATRIXDPROC)(const GLdouble *m); -GLAPI PFNGLMULTMATRIXDPROC glad_glMultMatrixd; -#define glMultMatrixd glad_glMultMatrixd -typedef void (APIENTRYP PFNGLORTHOPROC)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); -GLAPI PFNGLORTHOPROC glad_glOrtho; -#define glOrtho glad_glOrtho -typedef void (APIENTRYP PFNGLPOPMATRIXPROC)(void); -GLAPI PFNGLPOPMATRIXPROC glad_glPopMatrix; -#define glPopMatrix glad_glPopMatrix -typedef void (APIENTRYP PFNGLPUSHMATRIXPROC)(void); -GLAPI PFNGLPUSHMATRIXPROC glad_glPushMatrix; -#define glPushMatrix glad_glPushMatrix -typedef void (APIENTRYP PFNGLROTATEDPROC)(GLdouble angle, GLdouble x, GLdouble y, GLdouble z); -GLAPI PFNGLROTATEDPROC glad_glRotated; -#define glRotated glad_glRotated -typedef void (APIENTRYP PFNGLROTATEFPROC)(GLfloat angle, GLfloat x, GLfloat y, GLfloat z); -GLAPI PFNGLROTATEFPROC glad_glRotatef; -#define glRotatef glad_glRotatef -typedef void (APIENTRYP PFNGLSCALEDPROC)(GLdouble x, GLdouble y, GLdouble z); -GLAPI PFNGLSCALEDPROC glad_glScaled; -#define glScaled glad_glScaled -typedef void (APIENTRYP PFNGLSCALEFPROC)(GLfloat x, GLfloat y, GLfloat z); -GLAPI PFNGLSCALEFPROC glad_glScalef; -#define glScalef glad_glScalef -typedef void (APIENTRYP PFNGLTRANSLATEDPROC)(GLdouble x, GLdouble y, GLdouble z); -GLAPI PFNGLTRANSLATEDPROC glad_glTranslated; -#define glTranslated glad_glTranslated -typedef void (APIENTRYP PFNGLTRANSLATEFPROC)(GLfloat x, GLfloat y, GLfloat z); -GLAPI PFNGLTRANSLATEFPROC glad_glTranslatef; -#define glTranslatef glad_glTranslatef -#endif -#ifndef GL_VERSION_1_1 -#define GL_VERSION_1_1 1 -GLAPI int GLAD_GL_VERSION_1_1; -typedef void (APIENTRYP PFNGLDRAWARRAYSPROC)(GLenum mode, GLint first, GLsizei count); -GLAPI PFNGLDRAWARRAYSPROC glad_glDrawArrays; -#define glDrawArrays glad_glDrawArrays -typedef void (APIENTRYP PFNGLDRAWELEMENTSPROC)(GLenum mode, GLsizei count, GLenum type, const void *indices); -GLAPI PFNGLDRAWELEMENTSPROC glad_glDrawElements; -#define glDrawElements glad_glDrawElements -typedef void (APIENTRYP PFNGLGETPOINTERVPROC)(GLenum pname, void **params); -GLAPI PFNGLGETPOINTERVPROC glad_glGetPointerv; -#define glGetPointerv glad_glGetPointerv -typedef void (APIENTRYP PFNGLPOLYGONOFFSETPROC)(GLfloat factor, GLfloat units); -GLAPI PFNGLPOLYGONOFFSETPROC glad_glPolygonOffset; -#define glPolygonOffset glad_glPolygonOffset -typedef void (APIENTRYP PFNGLCOPYTEXIMAGE1DPROC)(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); -GLAPI PFNGLCOPYTEXIMAGE1DPROC glad_glCopyTexImage1D; -#define glCopyTexImage1D glad_glCopyTexImage1D -typedef void (APIENTRYP PFNGLCOPYTEXIMAGE2DPROC)(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); -GLAPI PFNGLCOPYTEXIMAGE2DPROC glad_glCopyTexImage2D; -#define glCopyTexImage2D glad_glCopyTexImage2D -typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE1DPROC)(GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); -GLAPI PFNGLCOPYTEXSUBIMAGE1DPROC glad_glCopyTexSubImage1D; -#define glCopyTexSubImage1D glad_glCopyTexSubImage1D -typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE2DPROC)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); -GLAPI PFNGLCOPYTEXSUBIMAGE2DPROC glad_glCopyTexSubImage2D; -#define glCopyTexSubImage2D glad_glCopyTexSubImage2D -typedef void (APIENTRYP PFNGLTEXSUBIMAGE1DPROC)(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const void *pixels); -GLAPI PFNGLTEXSUBIMAGE1DPROC glad_glTexSubImage1D; -#define glTexSubImage1D glad_glTexSubImage1D -typedef void (APIENTRYP PFNGLTEXSUBIMAGE2DPROC)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels); -GLAPI PFNGLTEXSUBIMAGE2DPROC glad_glTexSubImage2D; -#define glTexSubImage2D glad_glTexSubImage2D -typedef void (APIENTRYP PFNGLBINDTEXTUREPROC)(GLenum target, GLuint texture); -GLAPI PFNGLBINDTEXTUREPROC glad_glBindTexture; -#define glBindTexture glad_glBindTexture -typedef void (APIENTRYP PFNGLDELETETEXTURESPROC)(GLsizei n, const GLuint *textures); -GLAPI PFNGLDELETETEXTURESPROC glad_glDeleteTextures; -#define glDeleteTextures glad_glDeleteTextures -typedef void (APIENTRYP PFNGLGENTEXTURESPROC)(GLsizei n, GLuint *textures); -GLAPI PFNGLGENTEXTURESPROC glad_glGenTextures; -#define glGenTextures glad_glGenTextures -typedef GLboolean (APIENTRYP PFNGLISTEXTUREPROC)(GLuint texture); -GLAPI PFNGLISTEXTUREPROC glad_glIsTexture; -#define glIsTexture glad_glIsTexture -typedef void (APIENTRYP PFNGLARRAYELEMENTPROC)(GLint i); -GLAPI PFNGLARRAYELEMENTPROC glad_glArrayElement; -#define glArrayElement glad_glArrayElement -typedef void (APIENTRYP PFNGLCOLORPOINTERPROC)(GLint size, GLenum type, GLsizei stride, const void *pointer); -GLAPI PFNGLCOLORPOINTERPROC glad_glColorPointer; -#define glColorPointer glad_glColorPointer -typedef void (APIENTRYP PFNGLDISABLECLIENTSTATEPROC)(GLenum array); -GLAPI PFNGLDISABLECLIENTSTATEPROC glad_glDisableClientState; -#define glDisableClientState glad_glDisableClientState -typedef void (APIENTRYP PFNGLEDGEFLAGPOINTERPROC)(GLsizei stride, const void *pointer); -GLAPI PFNGLEDGEFLAGPOINTERPROC glad_glEdgeFlagPointer; -#define glEdgeFlagPointer glad_glEdgeFlagPointer -typedef void (APIENTRYP PFNGLENABLECLIENTSTATEPROC)(GLenum array); -GLAPI PFNGLENABLECLIENTSTATEPROC glad_glEnableClientState; -#define glEnableClientState glad_glEnableClientState -typedef void (APIENTRYP PFNGLINDEXPOINTERPROC)(GLenum type, GLsizei stride, const void *pointer); -GLAPI PFNGLINDEXPOINTERPROC glad_glIndexPointer; -#define glIndexPointer glad_glIndexPointer -typedef void (APIENTRYP PFNGLINTERLEAVEDARRAYSPROC)(GLenum format, GLsizei stride, const void *pointer); -GLAPI PFNGLINTERLEAVEDARRAYSPROC glad_glInterleavedArrays; -#define glInterleavedArrays glad_glInterleavedArrays -typedef void (APIENTRYP PFNGLNORMALPOINTERPROC)(GLenum type, GLsizei stride, const void *pointer); -GLAPI PFNGLNORMALPOINTERPROC glad_glNormalPointer; -#define glNormalPointer glad_glNormalPointer -typedef void (APIENTRYP PFNGLTEXCOORDPOINTERPROC)(GLint size, GLenum type, GLsizei stride, const void *pointer); -GLAPI PFNGLTEXCOORDPOINTERPROC glad_glTexCoordPointer; -#define glTexCoordPointer glad_glTexCoordPointer -typedef void (APIENTRYP PFNGLVERTEXPOINTERPROC)(GLint size, GLenum type, GLsizei stride, const void *pointer); -GLAPI PFNGLVERTEXPOINTERPROC glad_glVertexPointer; -#define glVertexPointer glad_glVertexPointer -typedef GLboolean (APIENTRYP PFNGLARETEXTURESRESIDENTPROC)(GLsizei n, const GLuint *textures, GLboolean *residences); -GLAPI PFNGLARETEXTURESRESIDENTPROC glad_glAreTexturesResident; -#define glAreTexturesResident glad_glAreTexturesResident -typedef void (APIENTRYP PFNGLPRIORITIZETEXTURESPROC)(GLsizei n, const GLuint *textures, const GLfloat *priorities); -GLAPI PFNGLPRIORITIZETEXTURESPROC glad_glPrioritizeTextures; -#define glPrioritizeTextures glad_glPrioritizeTextures -typedef void (APIENTRYP PFNGLINDEXUBPROC)(GLubyte c); -GLAPI PFNGLINDEXUBPROC glad_glIndexub; -#define glIndexub glad_glIndexub -typedef void (APIENTRYP PFNGLINDEXUBVPROC)(const GLubyte *c); -GLAPI PFNGLINDEXUBVPROC glad_glIndexubv; -#define glIndexubv glad_glIndexubv -typedef void (APIENTRYP PFNGLPOPCLIENTATTRIBPROC)(void); -GLAPI PFNGLPOPCLIENTATTRIBPROC glad_glPopClientAttrib; -#define glPopClientAttrib glad_glPopClientAttrib -typedef void (APIENTRYP PFNGLPUSHCLIENTATTRIBPROC)(GLbitfield mask); -GLAPI PFNGLPUSHCLIENTATTRIBPROC glad_glPushClientAttrib; -#define glPushClientAttrib glad_glPushClientAttrib -#endif -#ifndef GL_VERSION_1_2 -#define GL_VERSION_1_2 1 -GLAPI int GLAD_GL_VERSION_1_2; -typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSPROC)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices); -GLAPI PFNGLDRAWRANGEELEMENTSPROC glad_glDrawRangeElements; -#define glDrawRangeElements glad_glDrawRangeElements -typedef void (APIENTRYP PFNGLTEXIMAGE3DPROC)(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels); -GLAPI PFNGLTEXIMAGE3DPROC glad_glTexImage3D; -#define glTexImage3D glad_glTexImage3D -typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DPROC)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels); -GLAPI PFNGLTEXSUBIMAGE3DPROC glad_glTexSubImage3D; -#define glTexSubImage3D glad_glTexSubImage3D -typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DPROC)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); -GLAPI PFNGLCOPYTEXSUBIMAGE3DPROC glad_glCopyTexSubImage3D; -#define glCopyTexSubImage3D glad_glCopyTexSubImage3D -#endif -#ifndef GL_VERSION_1_3 -#define GL_VERSION_1_3 1 -GLAPI int GLAD_GL_VERSION_1_3; -typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC)(GLenum texture); -GLAPI PFNGLACTIVETEXTUREPROC glad_glActiveTexture; -#define glActiveTexture glad_glActiveTexture -typedef void (APIENTRYP PFNGLSAMPLECOVERAGEPROC)(GLfloat value, GLboolean invert); -GLAPI PFNGLSAMPLECOVERAGEPROC glad_glSampleCoverage; -#define glSampleCoverage glad_glSampleCoverage -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DPROC)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *data); -GLAPI PFNGLCOMPRESSEDTEXIMAGE3DPROC glad_glCompressedTexImage3D; -#define glCompressedTexImage3D glad_glCompressedTexImage3D -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DPROC)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data); -GLAPI PFNGLCOMPRESSEDTEXIMAGE2DPROC glad_glCompressedTexImage2D; -#define glCompressedTexImage2D glad_glCompressedTexImage2D -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DPROC)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const void *data); -GLAPI PFNGLCOMPRESSEDTEXIMAGE1DPROC glad_glCompressedTexImage1D; -#define glCompressedTexImage1D glad_glCompressedTexImage1D -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *data); -GLAPI PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC glad_glCompressedTexSubImage3D; -#define glCompressedTexSubImage3D glad_glCompressedTexSubImage3D -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data); -GLAPI PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC glad_glCompressedTexSubImage2D; -#define glCompressedTexSubImage2D glad_glCompressedTexSubImage2D -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC)(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *data); -GLAPI PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC glad_glCompressedTexSubImage1D; -#define glCompressedTexSubImage1D glad_glCompressedTexSubImage1D -typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEPROC)(GLenum target, GLint level, void *img); -GLAPI PFNGLGETCOMPRESSEDTEXIMAGEPROC glad_glGetCompressedTexImage; -#define glGetCompressedTexImage glad_glGetCompressedTexImage -typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREPROC)(GLenum texture); -GLAPI PFNGLCLIENTACTIVETEXTUREPROC glad_glClientActiveTexture; -#define glClientActiveTexture glad_glClientActiveTexture -typedef void (APIENTRYP PFNGLMULTITEXCOORD1DPROC)(GLenum target, GLdouble s); -GLAPI PFNGLMULTITEXCOORD1DPROC glad_glMultiTexCoord1d; -#define glMultiTexCoord1d glad_glMultiTexCoord1d -typedef void (APIENTRYP PFNGLMULTITEXCOORD1DVPROC)(GLenum target, const GLdouble *v); -GLAPI PFNGLMULTITEXCOORD1DVPROC glad_glMultiTexCoord1dv; -#define glMultiTexCoord1dv glad_glMultiTexCoord1dv -typedef void (APIENTRYP PFNGLMULTITEXCOORD1FPROC)(GLenum target, GLfloat s); -GLAPI PFNGLMULTITEXCOORD1FPROC glad_glMultiTexCoord1f; -#define glMultiTexCoord1f glad_glMultiTexCoord1f -typedef void (APIENTRYP PFNGLMULTITEXCOORD1FVPROC)(GLenum target, const GLfloat *v); -GLAPI PFNGLMULTITEXCOORD1FVPROC glad_glMultiTexCoord1fv; -#define glMultiTexCoord1fv glad_glMultiTexCoord1fv -typedef void (APIENTRYP PFNGLMULTITEXCOORD1IPROC)(GLenum target, GLint s); -GLAPI PFNGLMULTITEXCOORD1IPROC glad_glMultiTexCoord1i; -#define glMultiTexCoord1i glad_glMultiTexCoord1i -typedef void (APIENTRYP PFNGLMULTITEXCOORD1IVPROC)(GLenum target, const GLint *v); -GLAPI PFNGLMULTITEXCOORD1IVPROC glad_glMultiTexCoord1iv; -#define glMultiTexCoord1iv glad_glMultiTexCoord1iv -typedef void (APIENTRYP PFNGLMULTITEXCOORD1SPROC)(GLenum target, GLshort s); -GLAPI PFNGLMULTITEXCOORD1SPROC glad_glMultiTexCoord1s; -#define glMultiTexCoord1s glad_glMultiTexCoord1s -typedef void (APIENTRYP PFNGLMULTITEXCOORD1SVPROC)(GLenum target, const GLshort *v); -GLAPI PFNGLMULTITEXCOORD1SVPROC glad_glMultiTexCoord1sv; -#define glMultiTexCoord1sv glad_glMultiTexCoord1sv -typedef void (APIENTRYP PFNGLMULTITEXCOORD2DPROC)(GLenum target, GLdouble s, GLdouble t); -GLAPI PFNGLMULTITEXCOORD2DPROC glad_glMultiTexCoord2d; -#define glMultiTexCoord2d glad_glMultiTexCoord2d -typedef void (APIENTRYP PFNGLMULTITEXCOORD2DVPROC)(GLenum target, const GLdouble *v); -GLAPI PFNGLMULTITEXCOORD2DVPROC glad_glMultiTexCoord2dv; -#define glMultiTexCoord2dv glad_glMultiTexCoord2dv -typedef void (APIENTRYP PFNGLMULTITEXCOORD2FPROC)(GLenum target, GLfloat s, GLfloat t); -GLAPI PFNGLMULTITEXCOORD2FPROC glad_glMultiTexCoord2f; -#define glMultiTexCoord2f glad_glMultiTexCoord2f -typedef void (APIENTRYP PFNGLMULTITEXCOORD2FVPROC)(GLenum target, const GLfloat *v); -GLAPI PFNGLMULTITEXCOORD2FVPROC glad_glMultiTexCoord2fv; -#define glMultiTexCoord2fv glad_glMultiTexCoord2fv -typedef void (APIENTRYP PFNGLMULTITEXCOORD2IPROC)(GLenum target, GLint s, GLint t); -GLAPI PFNGLMULTITEXCOORD2IPROC glad_glMultiTexCoord2i; -#define glMultiTexCoord2i glad_glMultiTexCoord2i -typedef void (APIENTRYP PFNGLMULTITEXCOORD2IVPROC)(GLenum target, const GLint *v); -GLAPI PFNGLMULTITEXCOORD2IVPROC glad_glMultiTexCoord2iv; -#define glMultiTexCoord2iv glad_glMultiTexCoord2iv -typedef void (APIENTRYP PFNGLMULTITEXCOORD2SPROC)(GLenum target, GLshort s, GLshort t); -GLAPI PFNGLMULTITEXCOORD2SPROC glad_glMultiTexCoord2s; -#define glMultiTexCoord2s glad_glMultiTexCoord2s -typedef void (APIENTRYP PFNGLMULTITEXCOORD2SVPROC)(GLenum target, const GLshort *v); -GLAPI PFNGLMULTITEXCOORD2SVPROC glad_glMultiTexCoord2sv; -#define glMultiTexCoord2sv glad_glMultiTexCoord2sv -typedef void (APIENTRYP PFNGLMULTITEXCOORD3DPROC)(GLenum target, GLdouble s, GLdouble t, GLdouble r); -GLAPI PFNGLMULTITEXCOORD3DPROC glad_glMultiTexCoord3d; -#define glMultiTexCoord3d glad_glMultiTexCoord3d -typedef void (APIENTRYP PFNGLMULTITEXCOORD3DVPROC)(GLenum target, const GLdouble *v); -GLAPI PFNGLMULTITEXCOORD3DVPROC glad_glMultiTexCoord3dv; -#define glMultiTexCoord3dv glad_glMultiTexCoord3dv -typedef void (APIENTRYP PFNGLMULTITEXCOORD3FPROC)(GLenum target, GLfloat s, GLfloat t, GLfloat r); -GLAPI PFNGLMULTITEXCOORD3FPROC glad_glMultiTexCoord3f; -#define glMultiTexCoord3f glad_glMultiTexCoord3f -typedef void (APIENTRYP PFNGLMULTITEXCOORD3FVPROC)(GLenum target, const GLfloat *v); -GLAPI PFNGLMULTITEXCOORD3FVPROC glad_glMultiTexCoord3fv; -#define glMultiTexCoord3fv glad_glMultiTexCoord3fv -typedef void (APIENTRYP PFNGLMULTITEXCOORD3IPROC)(GLenum target, GLint s, GLint t, GLint r); -GLAPI PFNGLMULTITEXCOORD3IPROC glad_glMultiTexCoord3i; -#define glMultiTexCoord3i glad_glMultiTexCoord3i -typedef void (APIENTRYP PFNGLMULTITEXCOORD3IVPROC)(GLenum target, const GLint *v); -GLAPI PFNGLMULTITEXCOORD3IVPROC glad_glMultiTexCoord3iv; -#define glMultiTexCoord3iv glad_glMultiTexCoord3iv -typedef void (APIENTRYP PFNGLMULTITEXCOORD3SPROC)(GLenum target, GLshort s, GLshort t, GLshort r); -GLAPI PFNGLMULTITEXCOORD3SPROC glad_glMultiTexCoord3s; -#define glMultiTexCoord3s glad_glMultiTexCoord3s -typedef void (APIENTRYP PFNGLMULTITEXCOORD3SVPROC)(GLenum target, const GLshort *v); -GLAPI PFNGLMULTITEXCOORD3SVPROC glad_glMultiTexCoord3sv; -#define glMultiTexCoord3sv glad_glMultiTexCoord3sv -typedef void (APIENTRYP PFNGLMULTITEXCOORD4DPROC)(GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); -GLAPI PFNGLMULTITEXCOORD4DPROC glad_glMultiTexCoord4d; -#define glMultiTexCoord4d glad_glMultiTexCoord4d -typedef void (APIENTRYP PFNGLMULTITEXCOORD4DVPROC)(GLenum target, const GLdouble *v); -GLAPI PFNGLMULTITEXCOORD4DVPROC glad_glMultiTexCoord4dv; -#define glMultiTexCoord4dv glad_glMultiTexCoord4dv -typedef void (APIENTRYP PFNGLMULTITEXCOORD4FPROC)(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); -GLAPI PFNGLMULTITEXCOORD4FPROC glad_glMultiTexCoord4f; -#define glMultiTexCoord4f glad_glMultiTexCoord4f -typedef void (APIENTRYP PFNGLMULTITEXCOORD4FVPROC)(GLenum target, const GLfloat *v); -GLAPI PFNGLMULTITEXCOORD4FVPROC glad_glMultiTexCoord4fv; -#define glMultiTexCoord4fv glad_glMultiTexCoord4fv -typedef void (APIENTRYP PFNGLMULTITEXCOORD4IPROC)(GLenum target, GLint s, GLint t, GLint r, GLint q); -GLAPI PFNGLMULTITEXCOORD4IPROC glad_glMultiTexCoord4i; -#define glMultiTexCoord4i glad_glMultiTexCoord4i -typedef void (APIENTRYP PFNGLMULTITEXCOORD4IVPROC)(GLenum target, const GLint *v); -GLAPI PFNGLMULTITEXCOORD4IVPROC glad_glMultiTexCoord4iv; -#define glMultiTexCoord4iv glad_glMultiTexCoord4iv -typedef void (APIENTRYP PFNGLMULTITEXCOORD4SPROC)(GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); -GLAPI PFNGLMULTITEXCOORD4SPROC glad_glMultiTexCoord4s; -#define glMultiTexCoord4s glad_glMultiTexCoord4s -typedef void (APIENTRYP PFNGLMULTITEXCOORD4SVPROC)(GLenum target, const GLshort *v); -GLAPI PFNGLMULTITEXCOORD4SVPROC glad_glMultiTexCoord4sv; -#define glMultiTexCoord4sv glad_glMultiTexCoord4sv -typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXFPROC)(const GLfloat *m); -GLAPI PFNGLLOADTRANSPOSEMATRIXFPROC glad_glLoadTransposeMatrixf; -#define glLoadTransposeMatrixf glad_glLoadTransposeMatrixf -typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXDPROC)(const GLdouble *m); -GLAPI PFNGLLOADTRANSPOSEMATRIXDPROC glad_glLoadTransposeMatrixd; -#define glLoadTransposeMatrixd glad_glLoadTransposeMatrixd -typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXFPROC)(const GLfloat *m); -GLAPI PFNGLMULTTRANSPOSEMATRIXFPROC glad_glMultTransposeMatrixf; -#define glMultTransposeMatrixf glad_glMultTransposeMatrixf -typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXDPROC)(const GLdouble *m); -GLAPI PFNGLMULTTRANSPOSEMATRIXDPROC glad_glMultTransposeMatrixd; -#define glMultTransposeMatrixd glad_glMultTransposeMatrixd -#endif -#ifndef GL_VERSION_1_4 -#define GL_VERSION_1_4 1 -GLAPI int GLAD_GL_VERSION_1_4; -typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC)(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); -GLAPI PFNGLBLENDFUNCSEPARATEPROC glad_glBlendFuncSeparate; -#define glBlendFuncSeparate glad_glBlendFuncSeparate -typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSPROC)(GLenum mode, const GLint *first, const GLsizei *count, GLsizei drawcount); -GLAPI PFNGLMULTIDRAWARRAYSPROC glad_glMultiDrawArrays; -#define glMultiDrawArrays glad_glMultiDrawArrays -typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSPROC)(GLenum mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei drawcount); -GLAPI PFNGLMULTIDRAWELEMENTSPROC glad_glMultiDrawElements; -#define glMultiDrawElements glad_glMultiDrawElements -typedef void (APIENTRYP PFNGLPOINTPARAMETERFPROC)(GLenum pname, GLfloat param); -GLAPI PFNGLPOINTPARAMETERFPROC glad_glPointParameterf; -#define glPointParameterf glad_glPointParameterf -typedef void (APIENTRYP PFNGLPOINTPARAMETERFVPROC)(GLenum pname, const GLfloat *params); -GLAPI PFNGLPOINTPARAMETERFVPROC glad_glPointParameterfv; -#define glPointParameterfv glad_glPointParameterfv -typedef void (APIENTRYP PFNGLPOINTPARAMETERIPROC)(GLenum pname, GLint param); -GLAPI PFNGLPOINTPARAMETERIPROC glad_glPointParameteri; -#define glPointParameteri glad_glPointParameteri -typedef void (APIENTRYP PFNGLPOINTPARAMETERIVPROC)(GLenum pname, const GLint *params); -GLAPI PFNGLPOINTPARAMETERIVPROC glad_glPointParameteriv; -#define glPointParameteriv glad_glPointParameteriv -typedef void (APIENTRYP PFNGLFOGCOORDFPROC)(GLfloat coord); -GLAPI PFNGLFOGCOORDFPROC glad_glFogCoordf; -#define glFogCoordf glad_glFogCoordf -typedef void (APIENTRYP PFNGLFOGCOORDFVPROC)(const GLfloat *coord); -GLAPI PFNGLFOGCOORDFVPROC glad_glFogCoordfv; -#define glFogCoordfv glad_glFogCoordfv -typedef void (APIENTRYP PFNGLFOGCOORDDPROC)(GLdouble coord); -GLAPI PFNGLFOGCOORDDPROC glad_glFogCoordd; -#define glFogCoordd glad_glFogCoordd -typedef void (APIENTRYP PFNGLFOGCOORDDVPROC)(const GLdouble *coord); -GLAPI PFNGLFOGCOORDDVPROC glad_glFogCoorddv; -#define glFogCoorddv glad_glFogCoorddv -typedef void (APIENTRYP PFNGLFOGCOORDPOINTERPROC)(GLenum type, GLsizei stride, const void *pointer); -GLAPI PFNGLFOGCOORDPOINTERPROC glad_glFogCoordPointer; -#define glFogCoordPointer glad_glFogCoordPointer -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BPROC)(GLbyte red, GLbyte green, GLbyte blue); -GLAPI PFNGLSECONDARYCOLOR3BPROC glad_glSecondaryColor3b; -#define glSecondaryColor3b glad_glSecondaryColor3b -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BVPROC)(const GLbyte *v); -GLAPI PFNGLSECONDARYCOLOR3BVPROC glad_glSecondaryColor3bv; -#define glSecondaryColor3bv glad_glSecondaryColor3bv -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DPROC)(GLdouble red, GLdouble green, GLdouble blue); -GLAPI PFNGLSECONDARYCOLOR3DPROC glad_glSecondaryColor3d; -#define glSecondaryColor3d glad_glSecondaryColor3d -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DVPROC)(const GLdouble *v); -GLAPI PFNGLSECONDARYCOLOR3DVPROC glad_glSecondaryColor3dv; -#define glSecondaryColor3dv glad_glSecondaryColor3dv -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FPROC)(GLfloat red, GLfloat green, GLfloat blue); -GLAPI PFNGLSECONDARYCOLOR3FPROC glad_glSecondaryColor3f; -#define glSecondaryColor3f glad_glSecondaryColor3f -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FVPROC)(const GLfloat *v); -GLAPI PFNGLSECONDARYCOLOR3FVPROC glad_glSecondaryColor3fv; -#define glSecondaryColor3fv glad_glSecondaryColor3fv -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IPROC)(GLint red, GLint green, GLint blue); -GLAPI PFNGLSECONDARYCOLOR3IPROC glad_glSecondaryColor3i; -#define glSecondaryColor3i glad_glSecondaryColor3i -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IVPROC)(const GLint *v); -GLAPI PFNGLSECONDARYCOLOR3IVPROC glad_glSecondaryColor3iv; -#define glSecondaryColor3iv glad_glSecondaryColor3iv -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SPROC)(GLshort red, GLshort green, GLshort blue); -GLAPI PFNGLSECONDARYCOLOR3SPROC glad_glSecondaryColor3s; -#define glSecondaryColor3s glad_glSecondaryColor3s -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SVPROC)(const GLshort *v); -GLAPI PFNGLSECONDARYCOLOR3SVPROC glad_glSecondaryColor3sv; -#define glSecondaryColor3sv glad_glSecondaryColor3sv -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBPROC)(GLubyte red, GLubyte green, GLubyte blue); -GLAPI PFNGLSECONDARYCOLOR3UBPROC glad_glSecondaryColor3ub; -#define glSecondaryColor3ub glad_glSecondaryColor3ub -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBVPROC)(const GLubyte *v); -GLAPI PFNGLSECONDARYCOLOR3UBVPROC glad_glSecondaryColor3ubv; -#define glSecondaryColor3ubv glad_glSecondaryColor3ubv -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIPROC)(GLuint red, GLuint green, GLuint blue); -GLAPI PFNGLSECONDARYCOLOR3UIPROC glad_glSecondaryColor3ui; -#define glSecondaryColor3ui glad_glSecondaryColor3ui -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIVPROC)(const GLuint *v); -GLAPI PFNGLSECONDARYCOLOR3UIVPROC glad_glSecondaryColor3uiv; -#define glSecondaryColor3uiv glad_glSecondaryColor3uiv -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USPROC)(GLushort red, GLushort green, GLushort blue); -GLAPI PFNGLSECONDARYCOLOR3USPROC glad_glSecondaryColor3us; -#define glSecondaryColor3us glad_glSecondaryColor3us -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USVPROC)(const GLushort *v); -GLAPI PFNGLSECONDARYCOLOR3USVPROC glad_glSecondaryColor3usv; -#define glSecondaryColor3usv glad_glSecondaryColor3usv -typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTERPROC)(GLint size, GLenum type, GLsizei stride, const void *pointer); -GLAPI PFNGLSECONDARYCOLORPOINTERPROC glad_glSecondaryColorPointer; -#define glSecondaryColorPointer glad_glSecondaryColorPointer -typedef void (APIENTRYP PFNGLWINDOWPOS2DPROC)(GLdouble x, GLdouble y); -GLAPI PFNGLWINDOWPOS2DPROC glad_glWindowPos2d; -#define glWindowPos2d glad_glWindowPos2d -typedef void (APIENTRYP PFNGLWINDOWPOS2DVPROC)(const GLdouble *v); -GLAPI PFNGLWINDOWPOS2DVPROC glad_glWindowPos2dv; -#define glWindowPos2dv glad_glWindowPos2dv -typedef void (APIENTRYP PFNGLWINDOWPOS2FPROC)(GLfloat x, GLfloat y); -GLAPI PFNGLWINDOWPOS2FPROC glad_glWindowPos2f; -#define glWindowPos2f glad_glWindowPos2f -typedef void (APIENTRYP PFNGLWINDOWPOS2FVPROC)(const GLfloat *v); -GLAPI PFNGLWINDOWPOS2FVPROC glad_glWindowPos2fv; -#define glWindowPos2fv glad_glWindowPos2fv -typedef void (APIENTRYP PFNGLWINDOWPOS2IPROC)(GLint x, GLint y); -GLAPI PFNGLWINDOWPOS2IPROC glad_glWindowPos2i; -#define glWindowPos2i glad_glWindowPos2i -typedef void (APIENTRYP PFNGLWINDOWPOS2IVPROC)(const GLint *v); -GLAPI PFNGLWINDOWPOS2IVPROC glad_glWindowPos2iv; -#define glWindowPos2iv glad_glWindowPos2iv -typedef void (APIENTRYP PFNGLWINDOWPOS2SPROC)(GLshort x, GLshort y); -GLAPI PFNGLWINDOWPOS2SPROC glad_glWindowPos2s; -#define glWindowPos2s glad_glWindowPos2s -typedef void (APIENTRYP PFNGLWINDOWPOS2SVPROC)(const GLshort *v); -GLAPI PFNGLWINDOWPOS2SVPROC glad_glWindowPos2sv; -#define glWindowPos2sv glad_glWindowPos2sv -typedef void (APIENTRYP PFNGLWINDOWPOS3DPROC)(GLdouble x, GLdouble y, GLdouble z); -GLAPI PFNGLWINDOWPOS3DPROC glad_glWindowPos3d; -#define glWindowPos3d glad_glWindowPos3d -typedef void (APIENTRYP PFNGLWINDOWPOS3DVPROC)(const GLdouble *v); -GLAPI PFNGLWINDOWPOS3DVPROC glad_glWindowPos3dv; -#define glWindowPos3dv glad_glWindowPos3dv -typedef void (APIENTRYP PFNGLWINDOWPOS3FPROC)(GLfloat x, GLfloat y, GLfloat z); -GLAPI PFNGLWINDOWPOS3FPROC glad_glWindowPos3f; -#define glWindowPos3f glad_glWindowPos3f -typedef void (APIENTRYP PFNGLWINDOWPOS3FVPROC)(const GLfloat *v); -GLAPI PFNGLWINDOWPOS3FVPROC glad_glWindowPos3fv; -#define glWindowPos3fv glad_glWindowPos3fv -typedef void (APIENTRYP PFNGLWINDOWPOS3IPROC)(GLint x, GLint y, GLint z); -GLAPI PFNGLWINDOWPOS3IPROC glad_glWindowPos3i; -#define glWindowPos3i glad_glWindowPos3i -typedef void (APIENTRYP PFNGLWINDOWPOS3IVPROC)(const GLint *v); -GLAPI PFNGLWINDOWPOS3IVPROC glad_glWindowPos3iv; -#define glWindowPos3iv glad_glWindowPos3iv -typedef void (APIENTRYP PFNGLWINDOWPOS3SPROC)(GLshort x, GLshort y, GLshort z); -GLAPI PFNGLWINDOWPOS3SPROC glad_glWindowPos3s; -#define glWindowPos3s glad_glWindowPos3s -typedef void (APIENTRYP PFNGLWINDOWPOS3SVPROC)(const GLshort *v); -GLAPI PFNGLWINDOWPOS3SVPROC glad_glWindowPos3sv; -#define glWindowPos3sv glad_glWindowPos3sv -typedef void (APIENTRYP PFNGLBLENDCOLORPROC)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); -GLAPI PFNGLBLENDCOLORPROC glad_glBlendColor; -#define glBlendColor glad_glBlendColor -typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC)(GLenum mode); -GLAPI PFNGLBLENDEQUATIONPROC glad_glBlendEquation; -#define glBlendEquation glad_glBlendEquation -#endif -#ifndef GL_VERSION_1_5 -#define GL_VERSION_1_5 1 -GLAPI int GLAD_GL_VERSION_1_5; -typedef void (APIENTRYP PFNGLGENQUERIESPROC)(GLsizei n, GLuint *ids); -GLAPI PFNGLGENQUERIESPROC glad_glGenQueries; -#define glGenQueries glad_glGenQueries -typedef void (APIENTRYP PFNGLDELETEQUERIESPROC)(GLsizei n, const GLuint *ids); -GLAPI PFNGLDELETEQUERIESPROC glad_glDeleteQueries; -#define glDeleteQueries glad_glDeleteQueries -typedef GLboolean (APIENTRYP PFNGLISQUERYPROC)(GLuint id); -GLAPI PFNGLISQUERYPROC glad_glIsQuery; -#define glIsQuery glad_glIsQuery -typedef void (APIENTRYP PFNGLBEGINQUERYPROC)(GLenum target, GLuint id); -GLAPI PFNGLBEGINQUERYPROC glad_glBeginQuery; -#define glBeginQuery glad_glBeginQuery -typedef void (APIENTRYP PFNGLENDQUERYPROC)(GLenum target); -GLAPI PFNGLENDQUERYPROC glad_glEndQuery; -#define glEndQuery glad_glEndQuery -typedef void (APIENTRYP PFNGLGETQUERYIVPROC)(GLenum target, GLenum pname, GLint *params); -GLAPI PFNGLGETQUERYIVPROC glad_glGetQueryiv; -#define glGetQueryiv glad_glGetQueryiv -typedef void (APIENTRYP PFNGLGETQUERYOBJECTIVPROC)(GLuint id, GLenum pname, GLint *params); -GLAPI PFNGLGETQUERYOBJECTIVPROC glad_glGetQueryObjectiv; -#define glGetQueryObjectiv glad_glGetQueryObjectiv -typedef void (APIENTRYP PFNGLGETQUERYOBJECTUIVPROC)(GLuint id, GLenum pname, GLuint *params); -GLAPI PFNGLGETQUERYOBJECTUIVPROC glad_glGetQueryObjectuiv; -#define glGetQueryObjectuiv glad_glGetQueryObjectuiv -typedef void (APIENTRYP PFNGLBINDBUFFERPROC)(GLenum target, GLuint buffer); -GLAPI PFNGLBINDBUFFERPROC glad_glBindBuffer; -#define glBindBuffer glad_glBindBuffer -typedef void (APIENTRYP PFNGLDELETEBUFFERSPROC)(GLsizei n, const GLuint *buffers); -GLAPI PFNGLDELETEBUFFERSPROC glad_glDeleteBuffers; -#define glDeleteBuffers glad_glDeleteBuffers -typedef void (APIENTRYP PFNGLGENBUFFERSPROC)(GLsizei n, GLuint *buffers); -GLAPI PFNGLGENBUFFERSPROC glad_glGenBuffers; -#define glGenBuffers glad_glGenBuffers -typedef GLboolean (APIENTRYP PFNGLISBUFFERPROC)(GLuint buffer); -GLAPI PFNGLISBUFFERPROC glad_glIsBuffer; -#define glIsBuffer glad_glIsBuffer -typedef void (APIENTRYP PFNGLBUFFERDATAPROC)(GLenum target, GLsizeiptr size, const void *data, GLenum usage); -GLAPI PFNGLBUFFERDATAPROC glad_glBufferData; -#define glBufferData glad_glBufferData -typedef void (APIENTRYP PFNGLBUFFERSUBDATAPROC)(GLenum target, GLintptr offset, GLsizeiptr size, const void *data); -GLAPI PFNGLBUFFERSUBDATAPROC glad_glBufferSubData; -#define glBufferSubData glad_glBufferSubData -typedef void (APIENTRYP PFNGLGETBUFFERSUBDATAPROC)(GLenum target, GLintptr offset, GLsizeiptr size, void *data); -GLAPI PFNGLGETBUFFERSUBDATAPROC glad_glGetBufferSubData; -#define glGetBufferSubData glad_glGetBufferSubData -typedef void * (APIENTRYP PFNGLMAPBUFFERPROC)(GLenum target, GLenum access); -GLAPI PFNGLMAPBUFFERPROC glad_glMapBuffer; -#define glMapBuffer glad_glMapBuffer -typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERPROC)(GLenum target); -GLAPI PFNGLUNMAPBUFFERPROC glad_glUnmapBuffer; -#define glUnmapBuffer glad_glUnmapBuffer -typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERIVPROC)(GLenum target, GLenum pname, GLint *params); -GLAPI PFNGLGETBUFFERPARAMETERIVPROC glad_glGetBufferParameteriv; -#define glGetBufferParameteriv glad_glGetBufferParameteriv -typedef void (APIENTRYP PFNGLGETBUFFERPOINTERVPROC)(GLenum target, GLenum pname, void **params); -GLAPI PFNGLGETBUFFERPOINTERVPROC glad_glGetBufferPointerv; -#define glGetBufferPointerv glad_glGetBufferPointerv -#endif -#ifndef GL_VERSION_2_0 -#define GL_VERSION_2_0 1 -GLAPI int GLAD_GL_VERSION_2_0; -typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEPROC)(GLenum modeRGB, GLenum modeAlpha); -GLAPI PFNGLBLENDEQUATIONSEPARATEPROC glad_glBlendEquationSeparate; -#define glBlendEquationSeparate glad_glBlendEquationSeparate -typedef void (APIENTRYP PFNGLDRAWBUFFERSPROC)(GLsizei n, const GLenum *bufs); -GLAPI PFNGLDRAWBUFFERSPROC glad_glDrawBuffers; -#define glDrawBuffers glad_glDrawBuffers -typedef void (APIENTRYP PFNGLSTENCILOPSEPARATEPROC)(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); -GLAPI PFNGLSTENCILOPSEPARATEPROC glad_glStencilOpSeparate; -#define glStencilOpSeparate glad_glStencilOpSeparate -typedef void (APIENTRYP PFNGLSTENCILFUNCSEPARATEPROC)(GLenum face, GLenum func, GLint ref, GLuint mask); -GLAPI PFNGLSTENCILFUNCSEPARATEPROC glad_glStencilFuncSeparate; -#define glStencilFuncSeparate glad_glStencilFuncSeparate -typedef void (APIENTRYP PFNGLSTENCILMASKSEPARATEPROC)(GLenum face, GLuint mask); -GLAPI PFNGLSTENCILMASKSEPARATEPROC glad_glStencilMaskSeparate; -#define glStencilMaskSeparate glad_glStencilMaskSeparate -typedef void (APIENTRYP PFNGLATTACHSHADERPROC)(GLuint program, GLuint shader); -GLAPI PFNGLATTACHSHADERPROC glad_glAttachShader; -#define glAttachShader glad_glAttachShader -typedef void (APIENTRYP PFNGLBINDATTRIBLOCATIONPROC)(GLuint program, GLuint index, const GLchar *name); -GLAPI PFNGLBINDATTRIBLOCATIONPROC glad_glBindAttribLocation; -#define glBindAttribLocation glad_glBindAttribLocation -typedef void (APIENTRYP PFNGLCOMPILESHADERPROC)(GLuint shader); -GLAPI PFNGLCOMPILESHADERPROC glad_glCompileShader; -#define glCompileShader glad_glCompileShader -typedef GLuint (APIENTRYP PFNGLCREATEPROGRAMPROC)(void); -GLAPI PFNGLCREATEPROGRAMPROC glad_glCreateProgram; -#define glCreateProgram glad_glCreateProgram -typedef GLuint (APIENTRYP PFNGLCREATESHADERPROC)(GLenum type); -GLAPI PFNGLCREATESHADERPROC glad_glCreateShader; -#define glCreateShader glad_glCreateShader -typedef void (APIENTRYP PFNGLDELETEPROGRAMPROC)(GLuint program); -GLAPI PFNGLDELETEPROGRAMPROC glad_glDeleteProgram; -#define glDeleteProgram glad_glDeleteProgram -typedef void (APIENTRYP PFNGLDELETESHADERPROC)(GLuint shader); -GLAPI PFNGLDELETESHADERPROC glad_glDeleteShader; -#define glDeleteShader glad_glDeleteShader -typedef void (APIENTRYP PFNGLDETACHSHADERPROC)(GLuint program, GLuint shader); -GLAPI PFNGLDETACHSHADERPROC glad_glDetachShader; -#define glDetachShader glad_glDetachShader -typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYPROC)(GLuint index); -GLAPI PFNGLDISABLEVERTEXATTRIBARRAYPROC glad_glDisableVertexAttribArray; -#define glDisableVertexAttribArray glad_glDisableVertexAttribArray -typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYPROC)(GLuint index); -GLAPI PFNGLENABLEVERTEXATTRIBARRAYPROC glad_glEnableVertexAttribArray; -#define glEnableVertexAttribArray glad_glEnableVertexAttribArray -typedef void (APIENTRYP PFNGLGETACTIVEATTRIBPROC)(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); -GLAPI PFNGLGETACTIVEATTRIBPROC glad_glGetActiveAttrib; -#define glGetActiveAttrib glad_glGetActiveAttrib -typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMPROC)(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); -GLAPI PFNGLGETACTIVEUNIFORMPROC glad_glGetActiveUniform; -#define glGetActiveUniform glad_glGetActiveUniform -typedef void (APIENTRYP PFNGLGETATTACHEDSHADERSPROC)(GLuint program, GLsizei maxCount, GLsizei *count, GLuint *shaders); -GLAPI PFNGLGETATTACHEDSHADERSPROC glad_glGetAttachedShaders; -#define glGetAttachedShaders glad_glGetAttachedShaders -typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONPROC)(GLuint program, const GLchar *name); -GLAPI PFNGLGETATTRIBLOCATIONPROC glad_glGetAttribLocation; -#define glGetAttribLocation glad_glGetAttribLocation -typedef void (APIENTRYP PFNGLGETPROGRAMIVPROC)(GLuint program, GLenum pname, GLint *params); -GLAPI PFNGLGETPROGRAMIVPROC glad_glGetProgramiv; -#define glGetProgramiv glad_glGetProgramiv -typedef void (APIENTRYP PFNGLGETPROGRAMINFOLOGPROC)(GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog); -GLAPI PFNGLGETPROGRAMINFOLOGPROC glad_glGetProgramInfoLog; -#define glGetProgramInfoLog glad_glGetProgramInfoLog -typedef void (APIENTRYP PFNGLGETSHADERIVPROC)(GLuint shader, GLenum pname, GLint *params); -GLAPI PFNGLGETSHADERIVPROC glad_glGetShaderiv; -#define glGetShaderiv glad_glGetShaderiv -typedef void (APIENTRYP PFNGLGETSHADERINFOLOGPROC)(GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog); -GLAPI PFNGLGETSHADERINFOLOGPROC glad_glGetShaderInfoLog; -#define glGetShaderInfoLog glad_glGetShaderInfoLog -typedef void (APIENTRYP PFNGLGETSHADERSOURCEPROC)(GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source); -GLAPI PFNGLGETSHADERSOURCEPROC glad_glGetShaderSource; -#define glGetShaderSource glad_glGetShaderSource -typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONPROC)(GLuint program, const GLchar *name); -GLAPI PFNGLGETUNIFORMLOCATIONPROC glad_glGetUniformLocation; -#define glGetUniformLocation glad_glGetUniformLocation -typedef void (APIENTRYP PFNGLGETUNIFORMFVPROC)(GLuint program, GLint location, GLfloat *params); -GLAPI PFNGLGETUNIFORMFVPROC glad_glGetUniformfv; -#define glGetUniformfv glad_glGetUniformfv -typedef void (APIENTRYP PFNGLGETUNIFORMIVPROC)(GLuint program, GLint location, GLint *params); -GLAPI PFNGLGETUNIFORMIVPROC glad_glGetUniformiv; -#define glGetUniformiv glad_glGetUniformiv -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVPROC)(GLuint index, GLenum pname, GLdouble *params); -GLAPI PFNGLGETVERTEXATTRIBDVPROC glad_glGetVertexAttribdv; -#define glGetVertexAttribdv glad_glGetVertexAttribdv -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVPROC)(GLuint index, GLenum pname, GLfloat *params); -GLAPI PFNGLGETVERTEXATTRIBFVPROC glad_glGetVertexAttribfv; -#define glGetVertexAttribfv glad_glGetVertexAttribfv -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVPROC)(GLuint index, GLenum pname, GLint *params); -GLAPI PFNGLGETVERTEXATTRIBIVPROC glad_glGetVertexAttribiv; -#define glGetVertexAttribiv glad_glGetVertexAttribiv -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVPROC)(GLuint index, GLenum pname, void **pointer); -GLAPI PFNGLGETVERTEXATTRIBPOINTERVPROC glad_glGetVertexAttribPointerv; -#define glGetVertexAttribPointerv glad_glGetVertexAttribPointerv -typedef GLboolean (APIENTRYP PFNGLISPROGRAMPROC)(GLuint program); -GLAPI PFNGLISPROGRAMPROC glad_glIsProgram; -#define glIsProgram glad_glIsProgram -typedef GLboolean (APIENTRYP PFNGLISSHADERPROC)(GLuint shader); -GLAPI PFNGLISSHADERPROC glad_glIsShader; -#define glIsShader glad_glIsShader -typedef void (APIENTRYP PFNGLLINKPROGRAMPROC)(GLuint program); -GLAPI PFNGLLINKPROGRAMPROC glad_glLinkProgram; -#define glLinkProgram glad_glLinkProgram -typedef void (APIENTRYP PFNGLSHADERSOURCEPROC)(GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length); -GLAPI PFNGLSHADERSOURCEPROC glad_glShaderSource; -#define glShaderSource glad_glShaderSource -typedef void (APIENTRYP PFNGLUSEPROGRAMPROC)(GLuint program); -GLAPI PFNGLUSEPROGRAMPROC glad_glUseProgram; -#define glUseProgram glad_glUseProgram -typedef void (APIENTRYP PFNGLUNIFORM1FPROC)(GLint location, GLfloat v0); -GLAPI PFNGLUNIFORM1FPROC glad_glUniform1f; -#define glUniform1f glad_glUniform1f -typedef void (APIENTRYP PFNGLUNIFORM2FPROC)(GLint location, GLfloat v0, GLfloat v1); -GLAPI PFNGLUNIFORM2FPROC glad_glUniform2f; -#define glUniform2f glad_glUniform2f -typedef void (APIENTRYP PFNGLUNIFORM3FPROC)(GLint location, GLfloat v0, GLfloat v1, GLfloat v2); -GLAPI PFNGLUNIFORM3FPROC glad_glUniform3f; -#define glUniform3f glad_glUniform3f -typedef void (APIENTRYP PFNGLUNIFORM4FPROC)(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); -GLAPI PFNGLUNIFORM4FPROC glad_glUniform4f; -#define glUniform4f glad_glUniform4f -typedef void (APIENTRYP PFNGLUNIFORM1IPROC)(GLint location, GLint v0); -GLAPI PFNGLUNIFORM1IPROC glad_glUniform1i; -#define glUniform1i glad_glUniform1i -typedef void (APIENTRYP PFNGLUNIFORM2IPROC)(GLint location, GLint v0, GLint v1); -GLAPI PFNGLUNIFORM2IPROC glad_glUniform2i; -#define glUniform2i glad_glUniform2i -typedef void (APIENTRYP PFNGLUNIFORM3IPROC)(GLint location, GLint v0, GLint v1, GLint v2); -GLAPI PFNGLUNIFORM3IPROC glad_glUniform3i; -#define glUniform3i glad_glUniform3i -typedef void (APIENTRYP PFNGLUNIFORM4IPROC)(GLint location, GLint v0, GLint v1, GLint v2, GLint v3); -GLAPI PFNGLUNIFORM4IPROC glad_glUniform4i; -#define glUniform4i glad_glUniform4i -typedef void (APIENTRYP PFNGLUNIFORM1FVPROC)(GLint location, GLsizei count, const GLfloat *value); -GLAPI PFNGLUNIFORM1FVPROC glad_glUniform1fv; -#define glUniform1fv glad_glUniform1fv -typedef void (APIENTRYP PFNGLUNIFORM2FVPROC)(GLint location, GLsizei count, const GLfloat *value); -GLAPI PFNGLUNIFORM2FVPROC glad_glUniform2fv; -#define glUniform2fv glad_glUniform2fv -typedef void (APIENTRYP PFNGLUNIFORM3FVPROC)(GLint location, GLsizei count, const GLfloat *value); -GLAPI PFNGLUNIFORM3FVPROC glad_glUniform3fv; -#define glUniform3fv glad_glUniform3fv -typedef void (APIENTRYP PFNGLUNIFORM4FVPROC)(GLint location, GLsizei count, const GLfloat *value); -GLAPI PFNGLUNIFORM4FVPROC glad_glUniform4fv; -#define glUniform4fv glad_glUniform4fv -typedef void (APIENTRYP PFNGLUNIFORM1IVPROC)(GLint location, GLsizei count, const GLint *value); -GLAPI PFNGLUNIFORM1IVPROC glad_glUniform1iv; -#define glUniform1iv glad_glUniform1iv -typedef void (APIENTRYP PFNGLUNIFORM2IVPROC)(GLint location, GLsizei count, const GLint *value); -GLAPI PFNGLUNIFORM2IVPROC glad_glUniform2iv; -#define glUniform2iv glad_glUniform2iv -typedef void (APIENTRYP PFNGLUNIFORM3IVPROC)(GLint location, GLsizei count, const GLint *value); -GLAPI PFNGLUNIFORM3IVPROC glad_glUniform3iv; -#define glUniform3iv glad_glUniform3iv -typedef void (APIENTRYP PFNGLUNIFORM4IVPROC)(GLint location, GLsizei count, const GLint *value); -GLAPI PFNGLUNIFORM4IVPROC glad_glUniform4iv; -#define glUniform4iv glad_glUniform4iv -typedef void (APIENTRYP PFNGLUNIFORMMATRIX2FVPROC)(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI PFNGLUNIFORMMATRIX2FVPROC glad_glUniformMatrix2fv; -#define glUniformMatrix2fv glad_glUniformMatrix2fv -typedef void (APIENTRYP PFNGLUNIFORMMATRIX3FVPROC)(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI PFNGLUNIFORMMATRIX3FVPROC glad_glUniformMatrix3fv; -#define glUniformMatrix3fv glad_glUniformMatrix3fv -typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVPROC)(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI PFNGLUNIFORMMATRIX4FVPROC glad_glUniformMatrix4fv; -#define glUniformMatrix4fv glad_glUniformMatrix4fv -typedef void (APIENTRYP PFNGLVALIDATEPROGRAMPROC)(GLuint program); -GLAPI PFNGLVALIDATEPROGRAMPROC glad_glValidateProgram; -#define glValidateProgram glad_glValidateProgram -typedef void (APIENTRYP PFNGLVERTEXATTRIB1DPROC)(GLuint index, GLdouble x); -GLAPI PFNGLVERTEXATTRIB1DPROC glad_glVertexAttrib1d; -#define glVertexAttrib1d glad_glVertexAttrib1d -typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVPROC)(GLuint index, const GLdouble *v); -GLAPI PFNGLVERTEXATTRIB1DVPROC glad_glVertexAttrib1dv; -#define glVertexAttrib1dv glad_glVertexAttrib1dv -typedef void (APIENTRYP PFNGLVERTEXATTRIB1FPROC)(GLuint index, GLfloat x); -GLAPI PFNGLVERTEXATTRIB1FPROC glad_glVertexAttrib1f; -#define glVertexAttrib1f glad_glVertexAttrib1f -typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVPROC)(GLuint index, const GLfloat *v); -GLAPI PFNGLVERTEXATTRIB1FVPROC glad_glVertexAttrib1fv; -#define glVertexAttrib1fv glad_glVertexAttrib1fv -typedef void (APIENTRYP PFNGLVERTEXATTRIB1SPROC)(GLuint index, GLshort x); -GLAPI PFNGLVERTEXATTRIB1SPROC glad_glVertexAttrib1s; -#define glVertexAttrib1s glad_glVertexAttrib1s -typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVPROC)(GLuint index, const GLshort *v); -GLAPI PFNGLVERTEXATTRIB1SVPROC glad_glVertexAttrib1sv; -#define glVertexAttrib1sv glad_glVertexAttrib1sv -typedef void (APIENTRYP PFNGLVERTEXATTRIB2DPROC)(GLuint index, GLdouble x, GLdouble y); -GLAPI PFNGLVERTEXATTRIB2DPROC glad_glVertexAttrib2d; -#define glVertexAttrib2d glad_glVertexAttrib2d -typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVPROC)(GLuint index, const GLdouble *v); -GLAPI PFNGLVERTEXATTRIB2DVPROC glad_glVertexAttrib2dv; -#define glVertexAttrib2dv glad_glVertexAttrib2dv -typedef void (APIENTRYP PFNGLVERTEXATTRIB2FPROC)(GLuint index, GLfloat x, GLfloat y); -GLAPI PFNGLVERTEXATTRIB2FPROC glad_glVertexAttrib2f; -#define glVertexAttrib2f glad_glVertexAttrib2f -typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVPROC)(GLuint index, const GLfloat *v); -GLAPI PFNGLVERTEXATTRIB2FVPROC glad_glVertexAttrib2fv; -#define glVertexAttrib2fv glad_glVertexAttrib2fv -typedef void (APIENTRYP PFNGLVERTEXATTRIB2SPROC)(GLuint index, GLshort x, GLshort y); -GLAPI PFNGLVERTEXATTRIB2SPROC glad_glVertexAttrib2s; -#define glVertexAttrib2s glad_glVertexAttrib2s -typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVPROC)(GLuint index, const GLshort *v); -GLAPI PFNGLVERTEXATTRIB2SVPROC glad_glVertexAttrib2sv; -#define glVertexAttrib2sv glad_glVertexAttrib2sv -typedef void (APIENTRYP PFNGLVERTEXATTRIB3DPROC)(GLuint index, GLdouble x, GLdouble y, GLdouble z); -GLAPI PFNGLVERTEXATTRIB3DPROC glad_glVertexAttrib3d; -#define glVertexAttrib3d glad_glVertexAttrib3d -typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVPROC)(GLuint index, const GLdouble *v); -GLAPI PFNGLVERTEXATTRIB3DVPROC glad_glVertexAttrib3dv; -#define glVertexAttrib3dv glad_glVertexAttrib3dv -typedef void (APIENTRYP PFNGLVERTEXATTRIB3FPROC)(GLuint index, GLfloat x, GLfloat y, GLfloat z); -GLAPI PFNGLVERTEXATTRIB3FPROC glad_glVertexAttrib3f; -#define glVertexAttrib3f glad_glVertexAttrib3f -typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVPROC)(GLuint index, const GLfloat *v); -GLAPI PFNGLVERTEXATTRIB3FVPROC glad_glVertexAttrib3fv; -#define glVertexAttrib3fv glad_glVertexAttrib3fv -typedef void (APIENTRYP PFNGLVERTEXATTRIB3SPROC)(GLuint index, GLshort x, GLshort y, GLshort z); -GLAPI PFNGLVERTEXATTRIB3SPROC glad_glVertexAttrib3s; -#define glVertexAttrib3s glad_glVertexAttrib3s -typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVPROC)(GLuint index, const GLshort *v); -GLAPI PFNGLVERTEXATTRIB3SVPROC glad_glVertexAttrib3sv; -#define glVertexAttrib3sv glad_glVertexAttrib3sv -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NBVPROC)(GLuint index, const GLbyte *v); -GLAPI PFNGLVERTEXATTRIB4NBVPROC glad_glVertexAttrib4Nbv; -#define glVertexAttrib4Nbv glad_glVertexAttrib4Nbv -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NIVPROC)(GLuint index, const GLint *v); -GLAPI PFNGLVERTEXATTRIB4NIVPROC glad_glVertexAttrib4Niv; -#define glVertexAttrib4Niv glad_glVertexAttrib4Niv -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NSVPROC)(GLuint index, const GLshort *v); -GLAPI PFNGLVERTEXATTRIB4NSVPROC glad_glVertexAttrib4Nsv; -#define glVertexAttrib4Nsv glad_glVertexAttrib4Nsv -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBPROC)(GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); -GLAPI PFNGLVERTEXATTRIB4NUBPROC glad_glVertexAttrib4Nub; -#define glVertexAttrib4Nub glad_glVertexAttrib4Nub -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBVPROC)(GLuint index, const GLubyte *v); -GLAPI PFNGLVERTEXATTRIB4NUBVPROC glad_glVertexAttrib4Nubv; -#define glVertexAttrib4Nubv glad_glVertexAttrib4Nubv -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUIVPROC)(GLuint index, const GLuint *v); -GLAPI PFNGLVERTEXATTRIB4NUIVPROC glad_glVertexAttrib4Nuiv; -#define glVertexAttrib4Nuiv glad_glVertexAttrib4Nuiv -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUSVPROC)(GLuint index, const GLushort *v); -GLAPI PFNGLVERTEXATTRIB4NUSVPROC glad_glVertexAttrib4Nusv; -#define glVertexAttrib4Nusv glad_glVertexAttrib4Nusv -typedef void (APIENTRYP PFNGLVERTEXATTRIB4BVPROC)(GLuint index, const GLbyte *v); -GLAPI PFNGLVERTEXATTRIB4BVPROC glad_glVertexAttrib4bv; -#define glVertexAttrib4bv glad_glVertexAttrib4bv -typedef void (APIENTRYP PFNGLVERTEXATTRIB4DPROC)(GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -GLAPI PFNGLVERTEXATTRIB4DPROC glad_glVertexAttrib4d; -#define glVertexAttrib4d glad_glVertexAttrib4d -typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVPROC)(GLuint index, const GLdouble *v); -GLAPI PFNGLVERTEXATTRIB4DVPROC glad_glVertexAttrib4dv; -#define glVertexAttrib4dv glad_glVertexAttrib4dv -typedef void (APIENTRYP PFNGLVERTEXATTRIB4FPROC)(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -GLAPI PFNGLVERTEXATTRIB4FPROC glad_glVertexAttrib4f; -#define glVertexAttrib4f glad_glVertexAttrib4f -typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVPROC)(GLuint index, const GLfloat *v); -GLAPI PFNGLVERTEXATTRIB4FVPROC glad_glVertexAttrib4fv; -#define glVertexAttrib4fv glad_glVertexAttrib4fv -typedef void (APIENTRYP PFNGLVERTEXATTRIB4IVPROC)(GLuint index, const GLint *v); -GLAPI PFNGLVERTEXATTRIB4IVPROC glad_glVertexAttrib4iv; -#define glVertexAttrib4iv glad_glVertexAttrib4iv -typedef void (APIENTRYP PFNGLVERTEXATTRIB4SPROC)(GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); -GLAPI PFNGLVERTEXATTRIB4SPROC glad_glVertexAttrib4s; -#define glVertexAttrib4s glad_glVertexAttrib4s -typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVPROC)(GLuint index, const GLshort *v); -GLAPI PFNGLVERTEXATTRIB4SVPROC glad_glVertexAttrib4sv; -#define glVertexAttrib4sv glad_glVertexAttrib4sv -typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVPROC)(GLuint index, const GLubyte *v); -GLAPI PFNGLVERTEXATTRIB4UBVPROC glad_glVertexAttrib4ubv; -#define glVertexAttrib4ubv glad_glVertexAttrib4ubv -typedef void (APIENTRYP PFNGLVERTEXATTRIB4UIVPROC)(GLuint index, const GLuint *v); -GLAPI PFNGLVERTEXATTRIB4UIVPROC glad_glVertexAttrib4uiv; -#define glVertexAttrib4uiv glad_glVertexAttrib4uiv -typedef void (APIENTRYP PFNGLVERTEXATTRIB4USVPROC)(GLuint index, const GLushort *v); -GLAPI PFNGLVERTEXATTRIB4USVPROC glad_glVertexAttrib4usv; -#define glVertexAttrib4usv glad_glVertexAttrib4usv -typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERPROC)(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer); -GLAPI PFNGLVERTEXATTRIBPOINTERPROC glad_glVertexAttribPointer; -#define glVertexAttribPointer glad_glVertexAttribPointer -#endif -#ifndef GL_VERSION_2_1 -#define GL_VERSION_2_1 1 -GLAPI int GLAD_GL_VERSION_2_1; -typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X3FVPROC)(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI PFNGLUNIFORMMATRIX2X3FVPROC glad_glUniformMatrix2x3fv; -#define glUniformMatrix2x3fv glad_glUniformMatrix2x3fv -typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X2FVPROC)(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI PFNGLUNIFORMMATRIX3X2FVPROC glad_glUniformMatrix3x2fv; -#define glUniformMatrix3x2fv glad_glUniformMatrix3x2fv -typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X4FVPROC)(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI PFNGLUNIFORMMATRIX2X4FVPROC glad_glUniformMatrix2x4fv; -#define glUniformMatrix2x4fv glad_glUniformMatrix2x4fv -typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X2FVPROC)(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI PFNGLUNIFORMMATRIX4X2FVPROC glad_glUniformMatrix4x2fv; -#define glUniformMatrix4x2fv glad_glUniformMatrix4x2fv -typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X4FVPROC)(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI PFNGLUNIFORMMATRIX3X4FVPROC glad_glUniformMatrix3x4fv; -#define glUniformMatrix3x4fv glad_glUniformMatrix3x4fv -typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X3FVPROC)(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI PFNGLUNIFORMMATRIX4X3FVPROC glad_glUniformMatrix4x3fv; -#define glUniformMatrix4x3fv glad_glUniformMatrix4x3fv -#endif -#ifndef GL_VERSION_3_0 -#define GL_VERSION_3_0 1 -GLAPI int GLAD_GL_VERSION_3_0; -typedef void (APIENTRYP PFNGLCOLORMASKIPROC)(GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a); -GLAPI PFNGLCOLORMASKIPROC glad_glColorMaski; -#define glColorMaski glad_glColorMaski -typedef void (APIENTRYP PFNGLGETBOOLEANI_VPROC)(GLenum target, GLuint index, GLboolean *data); -GLAPI PFNGLGETBOOLEANI_VPROC glad_glGetBooleani_v; -#define glGetBooleani_v glad_glGetBooleani_v -typedef void (APIENTRYP PFNGLGETINTEGERI_VPROC)(GLenum target, GLuint index, GLint *data); -GLAPI PFNGLGETINTEGERI_VPROC glad_glGetIntegeri_v; -#define glGetIntegeri_v glad_glGetIntegeri_v -typedef void (APIENTRYP PFNGLENABLEIPROC)(GLenum target, GLuint index); -GLAPI PFNGLENABLEIPROC glad_glEnablei; -#define glEnablei glad_glEnablei -typedef void (APIENTRYP PFNGLDISABLEIPROC)(GLenum target, GLuint index); -GLAPI PFNGLDISABLEIPROC glad_glDisablei; -#define glDisablei glad_glDisablei -typedef GLboolean (APIENTRYP PFNGLISENABLEDIPROC)(GLenum target, GLuint index); -GLAPI PFNGLISENABLEDIPROC glad_glIsEnabledi; -#define glIsEnabledi glad_glIsEnabledi -typedef void (APIENTRYP PFNGLBEGINTRANSFORMFEEDBACKPROC)(GLenum primitiveMode); -GLAPI PFNGLBEGINTRANSFORMFEEDBACKPROC glad_glBeginTransformFeedback; -#define glBeginTransformFeedback glad_glBeginTransformFeedback -typedef void (APIENTRYP PFNGLENDTRANSFORMFEEDBACKPROC)(void); -GLAPI PFNGLENDTRANSFORMFEEDBACKPROC glad_glEndTransformFeedback; -#define glEndTransformFeedback glad_glEndTransformFeedback -typedef void (APIENTRYP PFNGLBINDBUFFERRANGEPROC)(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); -GLAPI PFNGLBINDBUFFERRANGEPROC glad_glBindBufferRange; -#define glBindBufferRange glad_glBindBufferRange -typedef void (APIENTRYP PFNGLBINDBUFFERBASEPROC)(GLenum target, GLuint index, GLuint buffer); -GLAPI PFNGLBINDBUFFERBASEPROC glad_glBindBufferBase; -#define glBindBufferBase glad_glBindBufferBase -typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKVARYINGSPROC)(GLuint program, GLsizei count, const GLchar *const*varyings, GLenum bufferMode); -GLAPI PFNGLTRANSFORMFEEDBACKVARYINGSPROC glad_glTransformFeedbackVaryings; -#define glTransformFeedbackVaryings glad_glTransformFeedbackVaryings -typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKVARYINGPROC)(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); -GLAPI PFNGLGETTRANSFORMFEEDBACKVARYINGPROC glad_glGetTransformFeedbackVarying; -#define glGetTransformFeedbackVarying glad_glGetTransformFeedbackVarying -typedef void (APIENTRYP PFNGLCLAMPCOLORPROC)(GLenum target, GLenum clamp); -GLAPI PFNGLCLAMPCOLORPROC glad_glClampColor; -#define glClampColor glad_glClampColor -typedef void (APIENTRYP PFNGLBEGINCONDITIONALRENDERPROC)(GLuint id, GLenum mode); -GLAPI PFNGLBEGINCONDITIONALRENDERPROC glad_glBeginConditionalRender; -#define glBeginConditionalRender glad_glBeginConditionalRender -typedef void (APIENTRYP PFNGLENDCONDITIONALRENDERPROC)(void); -GLAPI PFNGLENDCONDITIONALRENDERPROC glad_glEndConditionalRender; -#define glEndConditionalRender glad_glEndConditionalRender -typedef void (APIENTRYP PFNGLVERTEXATTRIBIPOINTERPROC)(GLuint index, GLint size, GLenum type, GLsizei stride, const void *pointer); -GLAPI PFNGLVERTEXATTRIBIPOINTERPROC glad_glVertexAttribIPointer; -#define glVertexAttribIPointer glad_glVertexAttribIPointer -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIIVPROC)(GLuint index, GLenum pname, GLint *params); -GLAPI PFNGLGETVERTEXATTRIBIIVPROC glad_glGetVertexAttribIiv; -#define glGetVertexAttribIiv glad_glGetVertexAttribIiv -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIUIVPROC)(GLuint index, GLenum pname, GLuint *params); -GLAPI PFNGLGETVERTEXATTRIBIUIVPROC glad_glGetVertexAttribIuiv; -#define glGetVertexAttribIuiv glad_glGetVertexAttribIuiv -typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IPROC)(GLuint index, GLint x); -GLAPI PFNGLVERTEXATTRIBI1IPROC glad_glVertexAttribI1i; -#define glVertexAttribI1i glad_glVertexAttribI1i -typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IPROC)(GLuint index, GLint x, GLint y); -GLAPI PFNGLVERTEXATTRIBI2IPROC glad_glVertexAttribI2i; -#define glVertexAttribI2i glad_glVertexAttribI2i -typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IPROC)(GLuint index, GLint x, GLint y, GLint z); -GLAPI PFNGLVERTEXATTRIBI3IPROC glad_glVertexAttribI3i; -#define glVertexAttribI3i glad_glVertexAttribI3i -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IPROC)(GLuint index, GLint x, GLint y, GLint z, GLint w); -GLAPI PFNGLVERTEXATTRIBI4IPROC glad_glVertexAttribI4i; -#define glVertexAttribI4i glad_glVertexAttribI4i -typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIPROC)(GLuint index, GLuint x); -GLAPI PFNGLVERTEXATTRIBI1UIPROC glad_glVertexAttribI1ui; -#define glVertexAttribI1ui glad_glVertexAttribI1ui -typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIPROC)(GLuint index, GLuint x, GLuint y); -GLAPI PFNGLVERTEXATTRIBI2UIPROC glad_glVertexAttribI2ui; -#define glVertexAttribI2ui glad_glVertexAttribI2ui -typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIPROC)(GLuint index, GLuint x, GLuint y, GLuint z); -GLAPI PFNGLVERTEXATTRIBI3UIPROC glad_glVertexAttribI3ui; -#define glVertexAttribI3ui glad_glVertexAttribI3ui -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIPROC)(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); -GLAPI PFNGLVERTEXATTRIBI4UIPROC glad_glVertexAttribI4ui; -#define glVertexAttribI4ui glad_glVertexAttribI4ui -typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IVPROC)(GLuint index, const GLint *v); -GLAPI PFNGLVERTEXATTRIBI1IVPROC glad_glVertexAttribI1iv; -#define glVertexAttribI1iv glad_glVertexAttribI1iv -typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IVPROC)(GLuint index, const GLint *v); -GLAPI PFNGLVERTEXATTRIBI2IVPROC glad_glVertexAttribI2iv; -#define glVertexAttribI2iv glad_glVertexAttribI2iv -typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IVPROC)(GLuint index, const GLint *v); -GLAPI PFNGLVERTEXATTRIBI3IVPROC glad_glVertexAttribI3iv; -#define glVertexAttribI3iv glad_glVertexAttribI3iv -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IVPROC)(GLuint index, const GLint *v); -GLAPI PFNGLVERTEXATTRIBI4IVPROC glad_glVertexAttribI4iv; -#define glVertexAttribI4iv glad_glVertexAttribI4iv -typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIVPROC)(GLuint index, const GLuint *v); -GLAPI PFNGLVERTEXATTRIBI1UIVPROC glad_glVertexAttribI1uiv; -#define glVertexAttribI1uiv glad_glVertexAttribI1uiv -typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIVPROC)(GLuint index, const GLuint *v); -GLAPI PFNGLVERTEXATTRIBI2UIVPROC glad_glVertexAttribI2uiv; -#define glVertexAttribI2uiv glad_glVertexAttribI2uiv -typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIVPROC)(GLuint index, const GLuint *v); -GLAPI PFNGLVERTEXATTRIBI3UIVPROC glad_glVertexAttribI3uiv; -#define glVertexAttribI3uiv glad_glVertexAttribI3uiv -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIVPROC)(GLuint index, const GLuint *v); -GLAPI PFNGLVERTEXATTRIBI4UIVPROC glad_glVertexAttribI4uiv; -#define glVertexAttribI4uiv glad_glVertexAttribI4uiv -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4BVPROC)(GLuint index, const GLbyte *v); -GLAPI PFNGLVERTEXATTRIBI4BVPROC glad_glVertexAttribI4bv; -#define glVertexAttribI4bv glad_glVertexAttribI4bv -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4SVPROC)(GLuint index, const GLshort *v); -GLAPI PFNGLVERTEXATTRIBI4SVPROC glad_glVertexAttribI4sv; -#define glVertexAttribI4sv glad_glVertexAttribI4sv -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UBVPROC)(GLuint index, const GLubyte *v); -GLAPI PFNGLVERTEXATTRIBI4UBVPROC glad_glVertexAttribI4ubv; -#define glVertexAttribI4ubv glad_glVertexAttribI4ubv -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4USVPROC)(GLuint index, const GLushort *v); -GLAPI PFNGLVERTEXATTRIBI4USVPROC glad_glVertexAttribI4usv; -#define glVertexAttribI4usv glad_glVertexAttribI4usv -typedef void (APIENTRYP PFNGLGETUNIFORMUIVPROC)(GLuint program, GLint location, GLuint *params); -GLAPI PFNGLGETUNIFORMUIVPROC glad_glGetUniformuiv; -#define glGetUniformuiv glad_glGetUniformuiv -typedef void (APIENTRYP PFNGLBINDFRAGDATALOCATIONPROC)(GLuint program, GLuint color, const GLchar *name); -GLAPI PFNGLBINDFRAGDATALOCATIONPROC glad_glBindFragDataLocation; -#define glBindFragDataLocation glad_glBindFragDataLocation -typedef GLint (APIENTRYP PFNGLGETFRAGDATALOCATIONPROC)(GLuint program, const GLchar *name); -GLAPI PFNGLGETFRAGDATALOCATIONPROC glad_glGetFragDataLocation; -#define glGetFragDataLocation glad_glGetFragDataLocation -typedef void (APIENTRYP PFNGLUNIFORM1UIPROC)(GLint location, GLuint v0); -GLAPI PFNGLUNIFORM1UIPROC glad_glUniform1ui; -#define glUniform1ui glad_glUniform1ui -typedef void (APIENTRYP PFNGLUNIFORM2UIPROC)(GLint location, GLuint v0, GLuint v1); -GLAPI PFNGLUNIFORM2UIPROC glad_glUniform2ui; -#define glUniform2ui glad_glUniform2ui -typedef void (APIENTRYP PFNGLUNIFORM3UIPROC)(GLint location, GLuint v0, GLuint v1, GLuint v2); -GLAPI PFNGLUNIFORM3UIPROC glad_glUniform3ui; -#define glUniform3ui glad_glUniform3ui -typedef void (APIENTRYP PFNGLUNIFORM4UIPROC)(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); -GLAPI PFNGLUNIFORM4UIPROC glad_glUniform4ui; -#define glUniform4ui glad_glUniform4ui -typedef void (APIENTRYP PFNGLUNIFORM1UIVPROC)(GLint location, GLsizei count, const GLuint *value); -GLAPI PFNGLUNIFORM1UIVPROC glad_glUniform1uiv; -#define glUniform1uiv glad_glUniform1uiv -typedef void (APIENTRYP PFNGLUNIFORM2UIVPROC)(GLint location, GLsizei count, const GLuint *value); -GLAPI PFNGLUNIFORM2UIVPROC glad_glUniform2uiv; -#define glUniform2uiv glad_glUniform2uiv -typedef void (APIENTRYP PFNGLUNIFORM3UIVPROC)(GLint location, GLsizei count, const GLuint *value); -GLAPI PFNGLUNIFORM3UIVPROC glad_glUniform3uiv; -#define glUniform3uiv glad_glUniform3uiv -typedef void (APIENTRYP PFNGLUNIFORM4UIVPROC)(GLint location, GLsizei count, const GLuint *value); -GLAPI PFNGLUNIFORM4UIVPROC glad_glUniform4uiv; -#define glUniform4uiv glad_glUniform4uiv -typedef void (APIENTRYP PFNGLTEXPARAMETERIIVPROC)(GLenum target, GLenum pname, const GLint *params); -GLAPI PFNGLTEXPARAMETERIIVPROC glad_glTexParameterIiv; -#define glTexParameterIiv glad_glTexParameterIiv -typedef void (APIENTRYP PFNGLTEXPARAMETERIUIVPROC)(GLenum target, GLenum pname, const GLuint *params); -GLAPI PFNGLTEXPARAMETERIUIVPROC glad_glTexParameterIuiv; -#define glTexParameterIuiv glad_glTexParameterIuiv -typedef void (APIENTRYP PFNGLGETTEXPARAMETERIIVPROC)(GLenum target, GLenum pname, GLint *params); -GLAPI PFNGLGETTEXPARAMETERIIVPROC glad_glGetTexParameterIiv; -#define glGetTexParameterIiv glad_glGetTexParameterIiv -typedef void (APIENTRYP PFNGLGETTEXPARAMETERIUIVPROC)(GLenum target, GLenum pname, GLuint *params); -GLAPI PFNGLGETTEXPARAMETERIUIVPROC glad_glGetTexParameterIuiv; -#define glGetTexParameterIuiv glad_glGetTexParameterIuiv -typedef void (APIENTRYP PFNGLCLEARBUFFERIVPROC)(GLenum buffer, GLint drawbuffer, const GLint *value); -GLAPI PFNGLCLEARBUFFERIVPROC glad_glClearBufferiv; -#define glClearBufferiv glad_glClearBufferiv -typedef void (APIENTRYP PFNGLCLEARBUFFERUIVPROC)(GLenum buffer, GLint drawbuffer, const GLuint *value); -GLAPI PFNGLCLEARBUFFERUIVPROC glad_glClearBufferuiv; -#define glClearBufferuiv glad_glClearBufferuiv -typedef void (APIENTRYP PFNGLCLEARBUFFERFVPROC)(GLenum buffer, GLint drawbuffer, const GLfloat *value); -GLAPI PFNGLCLEARBUFFERFVPROC glad_glClearBufferfv; -#define glClearBufferfv glad_glClearBufferfv -typedef void (APIENTRYP PFNGLCLEARBUFFERFIPROC)(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil); -GLAPI PFNGLCLEARBUFFERFIPROC glad_glClearBufferfi; -#define glClearBufferfi glad_glClearBufferfi -typedef const GLubyte * (APIENTRYP PFNGLGETSTRINGIPROC)(GLenum name, GLuint index); -GLAPI PFNGLGETSTRINGIPROC glad_glGetStringi; -#define glGetStringi glad_glGetStringi -typedef GLboolean (APIENTRYP PFNGLISRENDERBUFFERPROC)(GLuint renderbuffer); -GLAPI PFNGLISRENDERBUFFERPROC glad_glIsRenderbuffer; -#define glIsRenderbuffer glad_glIsRenderbuffer -typedef void (APIENTRYP PFNGLBINDRENDERBUFFERPROC)(GLenum target, GLuint renderbuffer); -GLAPI PFNGLBINDRENDERBUFFERPROC glad_glBindRenderbuffer; -#define glBindRenderbuffer glad_glBindRenderbuffer -typedef void (APIENTRYP PFNGLDELETERENDERBUFFERSPROC)(GLsizei n, const GLuint *renderbuffers); -GLAPI PFNGLDELETERENDERBUFFERSPROC glad_glDeleteRenderbuffers; -#define glDeleteRenderbuffers glad_glDeleteRenderbuffers -typedef void (APIENTRYP PFNGLGENRENDERBUFFERSPROC)(GLsizei n, GLuint *renderbuffers); -GLAPI PFNGLGENRENDERBUFFERSPROC glad_glGenRenderbuffers; -#define glGenRenderbuffers glad_glGenRenderbuffers -typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEPROC)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height); -GLAPI PFNGLRENDERBUFFERSTORAGEPROC glad_glRenderbufferStorage; -#define glRenderbufferStorage glad_glRenderbufferStorage -typedef void (APIENTRYP PFNGLGETRENDERBUFFERPARAMETERIVPROC)(GLenum target, GLenum pname, GLint *params); -GLAPI PFNGLGETRENDERBUFFERPARAMETERIVPROC glad_glGetRenderbufferParameteriv; -#define glGetRenderbufferParameteriv glad_glGetRenderbufferParameteriv -typedef GLboolean (APIENTRYP PFNGLISFRAMEBUFFERPROC)(GLuint framebuffer); -GLAPI PFNGLISFRAMEBUFFERPROC glad_glIsFramebuffer; -#define glIsFramebuffer glad_glIsFramebuffer -typedef void (APIENTRYP PFNGLBINDFRAMEBUFFERPROC)(GLenum target, GLuint framebuffer); -GLAPI PFNGLBINDFRAMEBUFFERPROC glad_glBindFramebuffer; -#define glBindFramebuffer glad_glBindFramebuffer -typedef void (APIENTRYP PFNGLDELETEFRAMEBUFFERSPROC)(GLsizei n, const GLuint *framebuffers); -GLAPI PFNGLDELETEFRAMEBUFFERSPROC glad_glDeleteFramebuffers; -#define glDeleteFramebuffers glad_glDeleteFramebuffers -typedef void (APIENTRYP PFNGLGENFRAMEBUFFERSPROC)(GLsizei n, GLuint *framebuffers); -GLAPI PFNGLGENFRAMEBUFFERSPROC glad_glGenFramebuffers; -#define glGenFramebuffers glad_glGenFramebuffers -typedef GLenum (APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSPROC)(GLenum target); -GLAPI PFNGLCHECKFRAMEBUFFERSTATUSPROC glad_glCheckFramebufferStatus; -#define glCheckFramebufferStatus glad_glCheckFramebufferStatus -typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE1DPROC)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); -GLAPI PFNGLFRAMEBUFFERTEXTURE1DPROC glad_glFramebufferTexture1D; -#define glFramebufferTexture1D glad_glFramebufferTexture1D -typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DPROC)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); -GLAPI PFNGLFRAMEBUFFERTEXTURE2DPROC glad_glFramebufferTexture2D; -#define glFramebufferTexture2D glad_glFramebufferTexture2D -typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE3DPROC)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); -GLAPI PFNGLFRAMEBUFFERTEXTURE3DPROC glad_glFramebufferTexture3D; -#define glFramebufferTexture3D glad_glFramebufferTexture3D -typedef void (APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFERPROC)(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); -GLAPI PFNGLFRAMEBUFFERRENDERBUFFERPROC glad_glFramebufferRenderbuffer; -#define glFramebufferRenderbuffer glad_glFramebufferRenderbuffer -typedef void (APIENTRYP PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC)(GLenum target, GLenum attachment, GLenum pname, GLint *params); -GLAPI PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC glad_glGetFramebufferAttachmentParameteriv; -#define glGetFramebufferAttachmentParameteriv glad_glGetFramebufferAttachmentParameteriv -typedef void (APIENTRYP PFNGLGENERATEMIPMAPPROC)(GLenum target); -GLAPI PFNGLGENERATEMIPMAPPROC glad_glGenerateMipmap; -#define glGenerateMipmap glad_glGenerateMipmap -typedef void (APIENTRYP PFNGLBLITFRAMEBUFFERPROC)(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); -GLAPI PFNGLBLITFRAMEBUFFERPROC glad_glBlitFramebuffer; -#define glBlitFramebuffer glad_glBlitFramebuffer -typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC)(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); -GLAPI PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC glad_glRenderbufferStorageMultisample; -#define glRenderbufferStorageMultisample glad_glRenderbufferStorageMultisample -typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURELAYERPROC)(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); -GLAPI PFNGLFRAMEBUFFERTEXTURELAYERPROC glad_glFramebufferTextureLayer; -#define glFramebufferTextureLayer glad_glFramebufferTextureLayer -typedef void * (APIENTRYP PFNGLMAPBUFFERRANGEPROC)(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); -GLAPI PFNGLMAPBUFFERRANGEPROC glad_glMapBufferRange; -#define glMapBufferRange glad_glMapBufferRange -typedef void (APIENTRYP PFNGLFLUSHMAPPEDBUFFERRANGEPROC)(GLenum target, GLintptr offset, GLsizeiptr length); -GLAPI PFNGLFLUSHMAPPEDBUFFERRANGEPROC glad_glFlushMappedBufferRange; -#define glFlushMappedBufferRange glad_glFlushMappedBufferRange -typedef void (APIENTRYP PFNGLBINDVERTEXARRAYPROC)(GLuint array); -GLAPI PFNGLBINDVERTEXARRAYPROC glad_glBindVertexArray; -#define glBindVertexArray glad_glBindVertexArray -typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSPROC)(GLsizei n, const GLuint *arrays); -GLAPI PFNGLDELETEVERTEXARRAYSPROC glad_glDeleteVertexArrays; -#define glDeleteVertexArrays glad_glDeleteVertexArrays -typedef void (APIENTRYP PFNGLGENVERTEXARRAYSPROC)(GLsizei n, GLuint *arrays); -GLAPI PFNGLGENVERTEXARRAYSPROC glad_glGenVertexArrays; -#define glGenVertexArrays glad_glGenVertexArrays -typedef GLboolean (APIENTRYP PFNGLISVERTEXARRAYPROC)(GLuint array); -GLAPI PFNGLISVERTEXARRAYPROC glad_glIsVertexArray; -#define glIsVertexArray glad_glIsVertexArray -#endif -#ifndef GL_VERSION_3_1 -#define GL_VERSION_3_1 1 -GLAPI int GLAD_GL_VERSION_3_1; -typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDPROC)(GLenum mode, GLint first, GLsizei count, GLsizei instancecount); -GLAPI PFNGLDRAWARRAYSINSTANCEDPROC glad_glDrawArraysInstanced; -#define glDrawArraysInstanced glad_glDrawArraysInstanced -typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDPROC)(GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount); -GLAPI PFNGLDRAWELEMENTSINSTANCEDPROC glad_glDrawElementsInstanced; -#define glDrawElementsInstanced glad_glDrawElementsInstanced -typedef void (APIENTRYP PFNGLTEXBUFFERPROC)(GLenum target, GLenum internalformat, GLuint buffer); -GLAPI PFNGLTEXBUFFERPROC glad_glTexBuffer; -#define glTexBuffer glad_glTexBuffer -typedef void (APIENTRYP PFNGLPRIMITIVERESTARTINDEXPROC)(GLuint index); -GLAPI PFNGLPRIMITIVERESTARTINDEXPROC glad_glPrimitiveRestartIndex; -#define glPrimitiveRestartIndex glad_glPrimitiveRestartIndex -typedef void (APIENTRYP PFNGLCOPYBUFFERSUBDATAPROC)(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); -GLAPI PFNGLCOPYBUFFERSUBDATAPROC glad_glCopyBufferSubData; -#define glCopyBufferSubData glad_glCopyBufferSubData -typedef void (APIENTRYP PFNGLGETUNIFORMINDICESPROC)(GLuint program, GLsizei uniformCount, const GLchar *const*uniformNames, GLuint *uniformIndices); -GLAPI PFNGLGETUNIFORMINDICESPROC glad_glGetUniformIndices; -#define glGetUniformIndices glad_glGetUniformIndices -typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMSIVPROC)(GLuint program, GLsizei uniformCount, const GLuint *uniformIndices, GLenum pname, GLint *params); -GLAPI PFNGLGETACTIVEUNIFORMSIVPROC glad_glGetActiveUniformsiv; -#define glGetActiveUniformsiv glad_glGetActiveUniformsiv -typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMNAMEPROC)(GLuint program, GLuint uniformIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformName); -GLAPI PFNGLGETACTIVEUNIFORMNAMEPROC glad_glGetActiveUniformName; -#define glGetActiveUniformName glad_glGetActiveUniformName -typedef GLuint (APIENTRYP PFNGLGETUNIFORMBLOCKINDEXPROC)(GLuint program, const GLchar *uniformBlockName); -GLAPI PFNGLGETUNIFORMBLOCKINDEXPROC glad_glGetUniformBlockIndex; -#define glGetUniformBlockIndex glad_glGetUniformBlockIndex -typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMBLOCKIVPROC)(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint *params); -GLAPI PFNGLGETACTIVEUNIFORMBLOCKIVPROC glad_glGetActiveUniformBlockiv; -#define glGetActiveUniformBlockiv glad_glGetActiveUniformBlockiv -typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC)(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName); -GLAPI PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC glad_glGetActiveUniformBlockName; -#define glGetActiveUniformBlockName glad_glGetActiveUniformBlockName -typedef void (APIENTRYP PFNGLUNIFORMBLOCKBINDINGPROC)(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding); -GLAPI PFNGLUNIFORMBLOCKBINDINGPROC glad_glUniformBlockBinding; -#define glUniformBlockBinding glad_glUniformBlockBinding -#endif -#ifndef GL_VERSION_3_2 -#define GL_VERSION_3_2 1 -GLAPI int GLAD_GL_VERSION_3_2; -typedef void (APIENTRYP PFNGLDRAWELEMENTSBASEVERTEXPROC)(GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex); -GLAPI PFNGLDRAWELEMENTSBASEVERTEXPROC glad_glDrawElementsBaseVertex; -#define glDrawElementsBaseVertex glad_glDrawElementsBaseVertex -typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSBASEVERTEXPROC)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices, GLint basevertex); -GLAPI PFNGLDRAWRANGEELEMENTSBASEVERTEXPROC glad_glDrawRangeElementsBaseVertex; -#define glDrawRangeElementsBaseVertex glad_glDrawRangeElementsBaseVertex -typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC)(GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex); -GLAPI PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC glad_glDrawElementsInstancedBaseVertex; -#define glDrawElementsInstancedBaseVertex glad_glDrawElementsInstancedBaseVertex -typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSBASEVERTEXPROC)(GLenum mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei drawcount, const GLint *basevertex); -GLAPI PFNGLMULTIDRAWELEMENTSBASEVERTEXPROC glad_glMultiDrawElementsBaseVertex; -#define glMultiDrawElementsBaseVertex glad_glMultiDrawElementsBaseVertex -typedef void (APIENTRYP PFNGLPROVOKINGVERTEXPROC)(GLenum mode); -GLAPI PFNGLPROVOKINGVERTEXPROC glad_glProvokingVertex; -#define glProvokingVertex glad_glProvokingVertex -typedef GLsync (APIENTRYP PFNGLFENCESYNCPROC)(GLenum condition, GLbitfield flags); -GLAPI PFNGLFENCESYNCPROC glad_glFenceSync; -#define glFenceSync glad_glFenceSync -typedef GLboolean (APIENTRYP PFNGLISSYNCPROC)(GLsync sync); -GLAPI PFNGLISSYNCPROC glad_glIsSync; -#define glIsSync glad_glIsSync -typedef void (APIENTRYP PFNGLDELETESYNCPROC)(GLsync sync); -GLAPI PFNGLDELETESYNCPROC glad_glDeleteSync; -#define glDeleteSync glad_glDeleteSync -typedef GLenum (APIENTRYP PFNGLCLIENTWAITSYNCPROC)(GLsync sync, GLbitfield flags, GLuint64 timeout); -GLAPI PFNGLCLIENTWAITSYNCPROC glad_glClientWaitSync; -#define glClientWaitSync glad_glClientWaitSync -typedef void (APIENTRYP PFNGLWAITSYNCPROC)(GLsync sync, GLbitfield flags, GLuint64 timeout); -GLAPI PFNGLWAITSYNCPROC glad_glWaitSync; -#define glWaitSync glad_glWaitSync -typedef void (APIENTRYP PFNGLGETINTEGER64VPROC)(GLenum pname, GLint64 *data); -GLAPI PFNGLGETINTEGER64VPROC glad_glGetInteger64v; -#define glGetInteger64v glad_glGetInteger64v -typedef void (APIENTRYP PFNGLGETSYNCIVPROC)(GLsync sync, GLenum pname, GLsizei count, GLsizei *length, GLint *values); -GLAPI PFNGLGETSYNCIVPROC glad_glGetSynciv; -#define glGetSynciv glad_glGetSynciv -typedef void (APIENTRYP PFNGLGETINTEGER64I_VPROC)(GLenum target, GLuint index, GLint64 *data); -GLAPI PFNGLGETINTEGER64I_VPROC glad_glGetInteger64i_v; -#define glGetInteger64i_v glad_glGetInteger64i_v -typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERI64VPROC)(GLenum target, GLenum pname, GLint64 *params); -GLAPI PFNGLGETBUFFERPARAMETERI64VPROC glad_glGetBufferParameteri64v; -#define glGetBufferParameteri64v glad_glGetBufferParameteri64v -typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREPROC)(GLenum target, GLenum attachment, GLuint texture, GLint level); -GLAPI PFNGLFRAMEBUFFERTEXTUREPROC glad_glFramebufferTexture; -#define glFramebufferTexture glad_glFramebufferTexture -typedef void (APIENTRYP PFNGLTEXIMAGE2DMULTISAMPLEPROC)(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); -GLAPI PFNGLTEXIMAGE2DMULTISAMPLEPROC glad_glTexImage2DMultisample; -#define glTexImage2DMultisample glad_glTexImage2DMultisample -typedef void (APIENTRYP PFNGLTEXIMAGE3DMULTISAMPLEPROC)(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); -GLAPI PFNGLTEXIMAGE3DMULTISAMPLEPROC glad_glTexImage3DMultisample; -#define glTexImage3DMultisample glad_glTexImage3DMultisample -typedef void (APIENTRYP PFNGLGETMULTISAMPLEFVPROC)(GLenum pname, GLuint index, GLfloat *val); -GLAPI PFNGLGETMULTISAMPLEFVPROC glad_glGetMultisamplefv; -#define glGetMultisamplefv glad_glGetMultisamplefv -typedef void (APIENTRYP PFNGLSAMPLEMASKIPROC)(GLuint maskNumber, GLbitfield mask); -GLAPI PFNGLSAMPLEMASKIPROC glad_glSampleMaski; -#define glSampleMaski glad_glSampleMaski -#endif -#ifndef GL_VERSION_3_3 -#define GL_VERSION_3_3 1 -GLAPI int GLAD_GL_VERSION_3_3; -typedef void (APIENTRYP PFNGLBINDFRAGDATALOCATIONINDEXEDPROC)(GLuint program, GLuint colorNumber, GLuint index, const GLchar *name); -GLAPI PFNGLBINDFRAGDATALOCATIONINDEXEDPROC glad_glBindFragDataLocationIndexed; -#define glBindFragDataLocationIndexed glad_glBindFragDataLocationIndexed -typedef GLint (APIENTRYP PFNGLGETFRAGDATAINDEXPROC)(GLuint program, const GLchar *name); -GLAPI PFNGLGETFRAGDATAINDEXPROC glad_glGetFragDataIndex; -#define glGetFragDataIndex glad_glGetFragDataIndex -typedef void (APIENTRYP PFNGLGENSAMPLERSPROC)(GLsizei count, GLuint *samplers); -GLAPI PFNGLGENSAMPLERSPROC glad_glGenSamplers; -#define glGenSamplers glad_glGenSamplers -typedef void (APIENTRYP PFNGLDELETESAMPLERSPROC)(GLsizei count, const GLuint *samplers); -GLAPI PFNGLDELETESAMPLERSPROC glad_glDeleteSamplers; -#define glDeleteSamplers glad_glDeleteSamplers -typedef GLboolean (APIENTRYP PFNGLISSAMPLERPROC)(GLuint sampler); -GLAPI PFNGLISSAMPLERPROC glad_glIsSampler; -#define glIsSampler glad_glIsSampler -typedef void (APIENTRYP PFNGLBINDSAMPLERPROC)(GLuint unit, GLuint sampler); -GLAPI PFNGLBINDSAMPLERPROC glad_glBindSampler; -#define glBindSampler glad_glBindSampler -typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIPROC)(GLuint sampler, GLenum pname, GLint param); -GLAPI PFNGLSAMPLERPARAMETERIPROC glad_glSamplerParameteri; -#define glSamplerParameteri glad_glSamplerParameteri -typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIVPROC)(GLuint sampler, GLenum pname, const GLint *param); -GLAPI PFNGLSAMPLERPARAMETERIVPROC glad_glSamplerParameteriv; -#define glSamplerParameteriv glad_glSamplerParameteriv -typedef void (APIENTRYP PFNGLSAMPLERPARAMETERFPROC)(GLuint sampler, GLenum pname, GLfloat param); -GLAPI PFNGLSAMPLERPARAMETERFPROC glad_glSamplerParameterf; -#define glSamplerParameterf glad_glSamplerParameterf -typedef void (APIENTRYP PFNGLSAMPLERPARAMETERFVPROC)(GLuint sampler, GLenum pname, const GLfloat *param); -GLAPI PFNGLSAMPLERPARAMETERFVPROC glad_glSamplerParameterfv; -#define glSamplerParameterfv glad_glSamplerParameterfv -typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIIVPROC)(GLuint sampler, GLenum pname, const GLint *param); -GLAPI PFNGLSAMPLERPARAMETERIIVPROC glad_glSamplerParameterIiv; -#define glSamplerParameterIiv glad_glSamplerParameterIiv -typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIUIVPROC)(GLuint sampler, GLenum pname, const GLuint *param); -GLAPI PFNGLSAMPLERPARAMETERIUIVPROC glad_glSamplerParameterIuiv; -#define glSamplerParameterIuiv glad_glSamplerParameterIuiv -typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIVPROC)(GLuint sampler, GLenum pname, GLint *params); -GLAPI PFNGLGETSAMPLERPARAMETERIVPROC glad_glGetSamplerParameteriv; -#define glGetSamplerParameteriv glad_glGetSamplerParameteriv -typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIIVPROC)(GLuint sampler, GLenum pname, GLint *params); -GLAPI PFNGLGETSAMPLERPARAMETERIIVPROC glad_glGetSamplerParameterIiv; -#define glGetSamplerParameterIiv glad_glGetSamplerParameterIiv -typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERFVPROC)(GLuint sampler, GLenum pname, GLfloat *params); -GLAPI PFNGLGETSAMPLERPARAMETERFVPROC glad_glGetSamplerParameterfv; -#define glGetSamplerParameterfv glad_glGetSamplerParameterfv -typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIUIVPROC)(GLuint sampler, GLenum pname, GLuint *params); -GLAPI PFNGLGETSAMPLERPARAMETERIUIVPROC glad_glGetSamplerParameterIuiv; -#define glGetSamplerParameterIuiv glad_glGetSamplerParameterIuiv -typedef void (APIENTRYP PFNGLQUERYCOUNTERPROC)(GLuint id, GLenum target); -GLAPI PFNGLQUERYCOUNTERPROC glad_glQueryCounter; -#define glQueryCounter glad_glQueryCounter -typedef void (APIENTRYP PFNGLGETQUERYOBJECTI64VPROC)(GLuint id, GLenum pname, GLint64 *params); -GLAPI PFNGLGETQUERYOBJECTI64VPROC glad_glGetQueryObjecti64v; -#define glGetQueryObjecti64v glad_glGetQueryObjecti64v -typedef void (APIENTRYP PFNGLGETQUERYOBJECTUI64VPROC)(GLuint id, GLenum pname, GLuint64 *params); -GLAPI PFNGLGETQUERYOBJECTUI64VPROC glad_glGetQueryObjectui64v; -#define glGetQueryObjectui64v glad_glGetQueryObjectui64v -typedef void (APIENTRYP PFNGLVERTEXATTRIBDIVISORPROC)(GLuint index, GLuint divisor); -GLAPI PFNGLVERTEXATTRIBDIVISORPROC glad_glVertexAttribDivisor; -#define glVertexAttribDivisor glad_glVertexAttribDivisor -typedef void (APIENTRYP PFNGLVERTEXATTRIBP1UIPROC)(GLuint index, GLenum type, GLboolean normalized, GLuint value); -GLAPI PFNGLVERTEXATTRIBP1UIPROC glad_glVertexAttribP1ui; -#define glVertexAttribP1ui glad_glVertexAttribP1ui -typedef void (APIENTRYP PFNGLVERTEXATTRIBP1UIVPROC)(GLuint index, GLenum type, GLboolean normalized, const GLuint *value); -GLAPI PFNGLVERTEXATTRIBP1UIVPROC glad_glVertexAttribP1uiv; -#define glVertexAttribP1uiv glad_glVertexAttribP1uiv -typedef void (APIENTRYP PFNGLVERTEXATTRIBP2UIPROC)(GLuint index, GLenum type, GLboolean normalized, GLuint value); -GLAPI PFNGLVERTEXATTRIBP2UIPROC glad_glVertexAttribP2ui; -#define glVertexAttribP2ui glad_glVertexAttribP2ui -typedef void (APIENTRYP PFNGLVERTEXATTRIBP2UIVPROC)(GLuint index, GLenum type, GLboolean normalized, const GLuint *value); -GLAPI PFNGLVERTEXATTRIBP2UIVPROC glad_glVertexAttribP2uiv; -#define glVertexAttribP2uiv glad_glVertexAttribP2uiv -typedef void (APIENTRYP PFNGLVERTEXATTRIBP3UIPROC)(GLuint index, GLenum type, GLboolean normalized, GLuint value); -GLAPI PFNGLVERTEXATTRIBP3UIPROC glad_glVertexAttribP3ui; -#define glVertexAttribP3ui glad_glVertexAttribP3ui -typedef void (APIENTRYP PFNGLVERTEXATTRIBP3UIVPROC)(GLuint index, GLenum type, GLboolean normalized, const GLuint *value); -GLAPI PFNGLVERTEXATTRIBP3UIVPROC glad_glVertexAttribP3uiv; -#define glVertexAttribP3uiv glad_glVertexAttribP3uiv -typedef void (APIENTRYP PFNGLVERTEXATTRIBP4UIPROC)(GLuint index, GLenum type, GLboolean normalized, GLuint value); -GLAPI PFNGLVERTEXATTRIBP4UIPROC glad_glVertexAttribP4ui; -#define glVertexAttribP4ui glad_glVertexAttribP4ui -typedef void (APIENTRYP PFNGLVERTEXATTRIBP4UIVPROC)(GLuint index, GLenum type, GLboolean normalized, const GLuint *value); -GLAPI PFNGLVERTEXATTRIBP4UIVPROC glad_glVertexAttribP4uiv; -#define glVertexAttribP4uiv glad_glVertexAttribP4uiv -typedef void (APIENTRYP PFNGLVERTEXP2UIPROC)(GLenum type, GLuint value); -GLAPI PFNGLVERTEXP2UIPROC glad_glVertexP2ui; -#define glVertexP2ui glad_glVertexP2ui -typedef void (APIENTRYP PFNGLVERTEXP2UIVPROC)(GLenum type, const GLuint *value); -GLAPI PFNGLVERTEXP2UIVPROC glad_glVertexP2uiv; -#define glVertexP2uiv glad_glVertexP2uiv -typedef void (APIENTRYP PFNGLVERTEXP3UIPROC)(GLenum type, GLuint value); -GLAPI PFNGLVERTEXP3UIPROC glad_glVertexP3ui; -#define glVertexP3ui glad_glVertexP3ui -typedef void (APIENTRYP PFNGLVERTEXP3UIVPROC)(GLenum type, const GLuint *value); -GLAPI PFNGLVERTEXP3UIVPROC glad_glVertexP3uiv; -#define glVertexP3uiv glad_glVertexP3uiv -typedef void (APIENTRYP PFNGLVERTEXP4UIPROC)(GLenum type, GLuint value); -GLAPI PFNGLVERTEXP4UIPROC glad_glVertexP4ui; -#define glVertexP4ui glad_glVertexP4ui -typedef void (APIENTRYP PFNGLVERTEXP4UIVPROC)(GLenum type, const GLuint *value); -GLAPI PFNGLVERTEXP4UIVPROC glad_glVertexP4uiv; -#define glVertexP4uiv glad_glVertexP4uiv -typedef void (APIENTRYP PFNGLTEXCOORDP1UIPROC)(GLenum type, GLuint coords); -GLAPI PFNGLTEXCOORDP1UIPROC glad_glTexCoordP1ui; -#define glTexCoordP1ui glad_glTexCoordP1ui -typedef void (APIENTRYP PFNGLTEXCOORDP1UIVPROC)(GLenum type, const GLuint *coords); -GLAPI PFNGLTEXCOORDP1UIVPROC glad_glTexCoordP1uiv; -#define glTexCoordP1uiv glad_glTexCoordP1uiv -typedef void (APIENTRYP PFNGLTEXCOORDP2UIPROC)(GLenum type, GLuint coords); -GLAPI PFNGLTEXCOORDP2UIPROC glad_glTexCoordP2ui; -#define glTexCoordP2ui glad_glTexCoordP2ui -typedef void (APIENTRYP PFNGLTEXCOORDP2UIVPROC)(GLenum type, const GLuint *coords); -GLAPI PFNGLTEXCOORDP2UIVPROC glad_glTexCoordP2uiv; -#define glTexCoordP2uiv glad_glTexCoordP2uiv -typedef void (APIENTRYP PFNGLTEXCOORDP3UIPROC)(GLenum type, GLuint coords); -GLAPI PFNGLTEXCOORDP3UIPROC glad_glTexCoordP3ui; -#define glTexCoordP3ui glad_glTexCoordP3ui -typedef void (APIENTRYP PFNGLTEXCOORDP3UIVPROC)(GLenum type, const GLuint *coords); -GLAPI PFNGLTEXCOORDP3UIVPROC glad_glTexCoordP3uiv; -#define glTexCoordP3uiv glad_glTexCoordP3uiv -typedef void (APIENTRYP PFNGLTEXCOORDP4UIPROC)(GLenum type, GLuint coords); -GLAPI PFNGLTEXCOORDP4UIPROC glad_glTexCoordP4ui; -#define glTexCoordP4ui glad_glTexCoordP4ui -typedef void (APIENTRYP PFNGLTEXCOORDP4UIVPROC)(GLenum type, const GLuint *coords); -GLAPI PFNGLTEXCOORDP4UIVPROC glad_glTexCoordP4uiv; -#define glTexCoordP4uiv glad_glTexCoordP4uiv -typedef void (APIENTRYP PFNGLMULTITEXCOORDP1UIPROC)(GLenum texture, GLenum type, GLuint coords); -GLAPI PFNGLMULTITEXCOORDP1UIPROC glad_glMultiTexCoordP1ui; -#define glMultiTexCoordP1ui glad_glMultiTexCoordP1ui -typedef void (APIENTRYP PFNGLMULTITEXCOORDP1UIVPROC)(GLenum texture, GLenum type, const GLuint *coords); -GLAPI PFNGLMULTITEXCOORDP1UIVPROC glad_glMultiTexCoordP1uiv; -#define glMultiTexCoordP1uiv glad_glMultiTexCoordP1uiv -typedef void (APIENTRYP PFNGLMULTITEXCOORDP2UIPROC)(GLenum texture, GLenum type, GLuint coords); -GLAPI PFNGLMULTITEXCOORDP2UIPROC glad_glMultiTexCoordP2ui; -#define glMultiTexCoordP2ui glad_glMultiTexCoordP2ui -typedef void (APIENTRYP PFNGLMULTITEXCOORDP2UIVPROC)(GLenum texture, GLenum type, const GLuint *coords); -GLAPI PFNGLMULTITEXCOORDP2UIVPROC glad_glMultiTexCoordP2uiv; -#define glMultiTexCoordP2uiv glad_glMultiTexCoordP2uiv -typedef void (APIENTRYP PFNGLMULTITEXCOORDP3UIPROC)(GLenum texture, GLenum type, GLuint coords); -GLAPI PFNGLMULTITEXCOORDP3UIPROC glad_glMultiTexCoordP3ui; -#define glMultiTexCoordP3ui glad_glMultiTexCoordP3ui -typedef void (APIENTRYP PFNGLMULTITEXCOORDP3UIVPROC)(GLenum texture, GLenum type, const GLuint *coords); -GLAPI PFNGLMULTITEXCOORDP3UIVPROC glad_glMultiTexCoordP3uiv; -#define glMultiTexCoordP3uiv glad_glMultiTexCoordP3uiv -typedef void (APIENTRYP PFNGLMULTITEXCOORDP4UIPROC)(GLenum texture, GLenum type, GLuint coords); -GLAPI PFNGLMULTITEXCOORDP4UIPROC glad_glMultiTexCoordP4ui; -#define glMultiTexCoordP4ui glad_glMultiTexCoordP4ui -typedef void (APIENTRYP PFNGLMULTITEXCOORDP4UIVPROC)(GLenum texture, GLenum type, const GLuint *coords); -GLAPI PFNGLMULTITEXCOORDP4UIVPROC glad_glMultiTexCoordP4uiv; -#define glMultiTexCoordP4uiv glad_glMultiTexCoordP4uiv -typedef void (APIENTRYP PFNGLNORMALP3UIPROC)(GLenum type, GLuint coords); -GLAPI PFNGLNORMALP3UIPROC glad_glNormalP3ui; -#define glNormalP3ui glad_glNormalP3ui -typedef void (APIENTRYP PFNGLNORMALP3UIVPROC)(GLenum type, const GLuint *coords); -GLAPI PFNGLNORMALP3UIVPROC glad_glNormalP3uiv; -#define glNormalP3uiv glad_glNormalP3uiv -typedef void (APIENTRYP PFNGLCOLORP3UIPROC)(GLenum type, GLuint color); -GLAPI PFNGLCOLORP3UIPROC glad_glColorP3ui; -#define glColorP3ui glad_glColorP3ui -typedef void (APIENTRYP PFNGLCOLORP3UIVPROC)(GLenum type, const GLuint *color); -GLAPI PFNGLCOLORP3UIVPROC glad_glColorP3uiv; -#define glColorP3uiv glad_glColorP3uiv -typedef void (APIENTRYP PFNGLCOLORP4UIPROC)(GLenum type, GLuint color); -GLAPI PFNGLCOLORP4UIPROC glad_glColorP4ui; -#define glColorP4ui glad_glColorP4ui -typedef void (APIENTRYP PFNGLCOLORP4UIVPROC)(GLenum type, const GLuint *color); -GLAPI PFNGLCOLORP4UIVPROC glad_glColorP4uiv; -#define glColorP4uiv glad_glColorP4uiv -typedef void (APIENTRYP PFNGLSECONDARYCOLORP3UIPROC)(GLenum type, GLuint color); -GLAPI PFNGLSECONDARYCOLORP3UIPROC glad_glSecondaryColorP3ui; -#define glSecondaryColorP3ui glad_glSecondaryColorP3ui -typedef void (APIENTRYP PFNGLSECONDARYCOLORP3UIVPROC)(GLenum type, const GLuint *color); -GLAPI PFNGLSECONDARYCOLORP3UIVPROC glad_glSecondaryColorP3uiv; -#define glSecondaryColorP3uiv glad_glSecondaryColorP3uiv -#endif -#ifndef GL_VERSION_4_0 -#define GL_VERSION_4_0 1 -GLAPI int GLAD_GL_VERSION_4_0; -typedef void (APIENTRYP PFNGLMINSAMPLESHADINGPROC)(GLfloat value); -GLAPI PFNGLMINSAMPLESHADINGPROC glad_glMinSampleShading; -#define glMinSampleShading glad_glMinSampleShading -typedef void (APIENTRYP PFNGLBLENDEQUATIONIPROC)(GLuint buf, GLenum mode); -GLAPI PFNGLBLENDEQUATIONIPROC glad_glBlendEquationi; -#define glBlendEquationi glad_glBlendEquationi -typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEIPROC)(GLuint buf, GLenum modeRGB, GLenum modeAlpha); -GLAPI PFNGLBLENDEQUATIONSEPARATEIPROC glad_glBlendEquationSeparatei; -#define glBlendEquationSeparatei glad_glBlendEquationSeparatei -typedef void (APIENTRYP PFNGLBLENDFUNCIPROC)(GLuint buf, GLenum src, GLenum dst); -GLAPI PFNGLBLENDFUNCIPROC glad_glBlendFunci; -#define glBlendFunci glad_glBlendFunci -typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEIPROC)(GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); -GLAPI PFNGLBLENDFUNCSEPARATEIPROC glad_glBlendFuncSeparatei; -#define glBlendFuncSeparatei glad_glBlendFuncSeparatei -typedef void (APIENTRYP PFNGLDRAWARRAYSINDIRECTPROC)(GLenum mode, const void *indirect); -GLAPI PFNGLDRAWARRAYSINDIRECTPROC glad_glDrawArraysIndirect; -#define glDrawArraysIndirect glad_glDrawArraysIndirect -typedef void (APIENTRYP PFNGLDRAWELEMENTSINDIRECTPROC)(GLenum mode, GLenum type, const void *indirect); -GLAPI PFNGLDRAWELEMENTSINDIRECTPROC glad_glDrawElementsIndirect; -#define glDrawElementsIndirect glad_glDrawElementsIndirect -typedef void (APIENTRYP PFNGLUNIFORM1DPROC)(GLint location, GLdouble x); -GLAPI PFNGLUNIFORM1DPROC glad_glUniform1d; -#define glUniform1d glad_glUniform1d -typedef void (APIENTRYP PFNGLUNIFORM2DPROC)(GLint location, GLdouble x, GLdouble y); -GLAPI PFNGLUNIFORM2DPROC glad_glUniform2d; -#define glUniform2d glad_glUniform2d -typedef void (APIENTRYP PFNGLUNIFORM3DPROC)(GLint location, GLdouble x, GLdouble y, GLdouble z); -GLAPI PFNGLUNIFORM3DPROC glad_glUniform3d; -#define glUniform3d glad_glUniform3d -typedef void (APIENTRYP PFNGLUNIFORM4DPROC)(GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -GLAPI PFNGLUNIFORM4DPROC glad_glUniform4d; -#define glUniform4d glad_glUniform4d -typedef void (APIENTRYP PFNGLUNIFORM1DVPROC)(GLint location, GLsizei count, const GLdouble *value); -GLAPI PFNGLUNIFORM1DVPROC glad_glUniform1dv; -#define glUniform1dv glad_glUniform1dv -typedef void (APIENTRYP PFNGLUNIFORM2DVPROC)(GLint location, GLsizei count, const GLdouble *value); -GLAPI PFNGLUNIFORM2DVPROC glad_glUniform2dv; -#define glUniform2dv glad_glUniform2dv -typedef void (APIENTRYP PFNGLUNIFORM3DVPROC)(GLint location, GLsizei count, const GLdouble *value); -GLAPI PFNGLUNIFORM3DVPROC glad_glUniform3dv; -#define glUniform3dv glad_glUniform3dv -typedef void (APIENTRYP PFNGLUNIFORM4DVPROC)(GLint location, GLsizei count, const GLdouble *value); -GLAPI PFNGLUNIFORM4DVPROC glad_glUniform4dv; -#define glUniform4dv glad_glUniform4dv -typedef void (APIENTRYP PFNGLUNIFORMMATRIX2DVPROC)(GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI PFNGLUNIFORMMATRIX2DVPROC glad_glUniformMatrix2dv; -#define glUniformMatrix2dv glad_glUniformMatrix2dv -typedef void (APIENTRYP PFNGLUNIFORMMATRIX3DVPROC)(GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI PFNGLUNIFORMMATRIX3DVPROC glad_glUniformMatrix3dv; -#define glUniformMatrix3dv glad_glUniformMatrix3dv -typedef void (APIENTRYP PFNGLUNIFORMMATRIX4DVPROC)(GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI PFNGLUNIFORMMATRIX4DVPROC glad_glUniformMatrix4dv; -#define glUniformMatrix4dv glad_glUniformMatrix4dv -typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X3DVPROC)(GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI PFNGLUNIFORMMATRIX2X3DVPROC glad_glUniformMatrix2x3dv; -#define glUniformMatrix2x3dv glad_glUniformMatrix2x3dv -typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X4DVPROC)(GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI PFNGLUNIFORMMATRIX2X4DVPROC glad_glUniformMatrix2x4dv; -#define glUniformMatrix2x4dv glad_glUniformMatrix2x4dv -typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X2DVPROC)(GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI PFNGLUNIFORMMATRIX3X2DVPROC glad_glUniformMatrix3x2dv; -#define glUniformMatrix3x2dv glad_glUniformMatrix3x2dv -typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X4DVPROC)(GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI PFNGLUNIFORMMATRIX3X4DVPROC glad_glUniformMatrix3x4dv; -#define glUniformMatrix3x4dv glad_glUniformMatrix3x4dv -typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X2DVPROC)(GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI PFNGLUNIFORMMATRIX4X2DVPROC glad_glUniformMatrix4x2dv; -#define glUniformMatrix4x2dv glad_glUniformMatrix4x2dv -typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X3DVPROC)(GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI PFNGLUNIFORMMATRIX4X3DVPROC glad_glUniformMatrix4x3dv; -#define glUniformMatrix4x3dv glad_glUniformMatrix4x3dv -typedef void (APIENTRYP PFNGLGETUNIFORMDVPROC)(GLuint program, GLint location, GLdouble *params); -GLAPI PFNGLGETUNIFORMDVPROC glad_glGetUniformdv; -#define glGetUniformdv glad_glGetUniformdv -typedef GLint (APIENTRYP PFNGLGETSUBROUTINEUNIFORMLOCATIONPROC)(GLuint program, GLenum shadertype, const GLchar *name); -GLAPI PFNGLGETSUBROUTINEUNIFORMLOCATIONPROC glad_glGetSubroutineUniformLocation; -#define glGetSubroutineUniformLocation glad_glGetSubroutineUniformLocation -typedef GLuint (APIENTRYP PFNGLGETSUBROUTINEINDEXPROC)(GLuint program, GLenum shadertype, const GLchar *name); -GLAPI PFNGLGETSUBROUTINEINDEXPROC glad_glGetSubroutineIndex; -#define glGetSubroutineIndex glad_glGetSubroutineIndex -typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINEUNIFORMIVPROC)(GLuint program, GLenum shadertype, GLuint index, GLenum pname, GLint *values); -GLAPI PFNGLGETACTIVESUBROUTINEUNIFORMIVPROC glad_glGetActiveSubroutineUniformiv; -#define glGetActiveSubroutineUniformiv glad_glGetActiveSubroutineUniformiv -typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINEUNIFORMNAMEPROC)(GLuint program, GLenum shadertype, GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name); -GLAPI PFNGLGETACTIVESUBROUTINEUNIFORMNAMEPROC glad_glGetActiveSubroutineUniformName; -#define glGetActiveSubroutineUniformName glad_glGetActiveSubroutineUniformName -typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINENAMEPROC)(GLuint program, GLenum shadertype, GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name); -GLAPI PFNGLGETACTIVESUBROUTINENAMEPROC glad_glGetActiveSubroutineName; -#define glGetActiveSubroutineName glad_glGetActiveSubroutineName -typedef void (APIENTRYP PFNGLUNIFORMSUBROUTINESUIVPROC)(GLenum shadertype, GLsizei count, const GLuint *indices); -GLAPI PFNGLUNIFORMSUBROUTINESUIVPROC glad_glUniformSubroutinesuiv; -#define glUniformSubroutinesuiv glad_glUniformSubroutinesuiv -typedef void (APIENTRYP PFNGLGETUNIFORMSUBROUTINEUIVPROC)(GLenum shadertype, GLint location, GLuint *params); -GLAPI PFNGLGETUNIFORMSUBROUTINEUIVPROC glad_glGetUniformSubroutineuiv; -#define glGetUniformSubroutineuiv glad_glGetUniformSubroutineuiv -typedef void (APIENTRYP PFNGLGETPROGRAMSTAGEIVPROC)(GLuint program, GLenum shadertype, GLenum pname, GLint *values); -GLAPI PFNGLGETPROGRAMSTAGEIVPROC glad_glGetProgramStageiv; -#define glGetProgramStageiv glad_glGetProgramStageiv -typedef void (APIENTRYP PFNGLPATCHPARAMETERIPROC)(GLenum pname, GLint value); -GLAPI PFNGLPATCHPARAMETERIPROC glad_glPatchParameteri; -#define glPatchParameteri glad_glPatchParameteri -typedef void (APIENTRYP PFNGLPATCHPARAMETERFVPROC)(GLenum pname, const GLfloat *values); -GLAPI PFNGLPATCHPARAMETERFVPROC glad_glPatchParameterfv; -#define glPatchParameterfv glad_glPatchParameterfv -typedef void (APIENTRYP PFNGLBINDTRANSFORMFEEDBACKPROC)(GLenum target, GLuint id); -GLAPI PFNGLBINDTRANSFORMFEEDBACKPROC glad_glBindTransformFeedback; -#define glBindTransformFeedback glad_glBindTransformFeedback -typedef void (APIENTRYP PFNGLDELETETRANSFORMFEEDBACKSPROC)(GLsizei n, const GLuint *ids); -GLAPI PFNGLDELETETRANSFORMFEEDBACKSPROC glad_glDeleteTransformFeedbacks; -#define glDeleteTransformFeedbacks glad_glDeleteTransformFeedbacks -typedef void (APIENTRYP PFNGLGENTRANSFORMFEEDBACKSPROC)(GLsizei n, GLuint *ids); -GLAPI PFNGLGENTRANSFORMFEEDBACKSPROC glad_glGenTransformFeedbacks; -#define glGenTransformFeedbacks glad_glGenTransformFeedbacks -typedef GLboolean (APIENTRYP PFNGLISTRANSFORMFEEDBACKPROC)(GLuint id); -GLAPI PFNGLISTRANSFORMFEEDBACKPROC glad_glIsTransformFeedback; -#define glIsTransformFeedback glad_glIsTransformFeedback -typedef void (APIENTRYP PFNGLPAUSETRANSFORMFEEDBACKPROC)(void); -GLAPI PFNGLPAUSETRANSFORMFEEDBACKPROC glad_glPauseTransformFeedback; -#define glPauseTransformFeedback glad_glPauseTransformFeedback -typedef void (APIENTRYP PFNGLRESUMETRANSFORMFEEDBACKPROC)(void); -GLAPI PFNGLRESUMETRANSFORMFEEDBACKPROC glad_glResumeTransformFeedback; -#define glResumeTransformFeedback glad_glResumeTransformFeedback -typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKPROC)(GLenum mode, GLuint id); -GLAPI PFNGLDRAWTRANSFORMFEEDBACKPROC glad_glDrawTransformFeedback; -#define glDrawTransformFeedback glad_glDrawTransformFeedback -typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKSTREAMPROC)(GLenum mode, GLuint id, GLuint stream); -GLAPI PFNGLDRAWTRANSFORMFEEDBACKSTREAMPROC glad_glDrawTransformFeedbackStream; -#define glDrawTransformFeedbackStream glad_glDrawTransformFeedbackStream -typedef void (APIENTRYP PFNGLBEGINQUERYINDEXEDPROC)(GLenum target, GLuint index, GLuint id); -GLAPI PFNGLBEGINQUERYINDEXEDPROC glad_glBeginQueryIndexed; -#define glBeginQueryIndexed glad_glBeginQueryIndexed -typedef void (APIENTRYP PFNGLENDQUERYINDEXEDPROC)(GLenum target, GLuint index); -GLAPI PFNGLENDQUERYINDEXEDPROC glad_glEndQueryIndexed; -#define glEndQueryIndexed glad_glEndQueryIndexed -typedef void (APIENTRYP PFNGLGETQUERYINDEXEDIVPROC)(GLenum target, GLuint index, GLenum pname, GLint *params); -GLAPI PFNGLGETQUERYINDEXEDIVPROC glad_glGetQueryIndexediv; -#define glGetQueryIndexediv glad_glGetQueryIndexediv -#endif -#ifndef GL_VERSION_4_1 -#define GL_VERSION_4_1 1 -GLAPI int GLAD_GL_VERSION_4_1; -typedef void (APIENTRYP PFNGLRELEASESHADERCOMPILERPROC)(void); -GLAPI PFNGLRELEASESHADERCOMPILERPROC glad_glReleaseShaderCompiler; -#define glReleaseShaderCompiler glad_glReleaseShaderCompiler -typedef void (APIENTRYP PFNGLSHADERBINARYPROC)(GLsizei count, const GLuint *shaders, GLenum binaryFormat, const void *binary, GLsizei length); -GLAPI PFNGLSHADERBINARYPROC glad_glShaderBinary; -#define glShaderBinary glad_glShaderBinary -typedef void (APIENTRYP PFNGLGETSHADERPRECISIONFORMATPROC)(GLenum shadertype, GLenum precisiontype, GLint *range, GLint *precision); -GLAPI PFNGLGETSHADERPRECISIONFORMATPROC glad_glGetShaderPrecisionFormat; -#define glGetShaderPrecisionFormat glad_glGetShaderPrecisionFormat -typedef void (APIENTRYP PFNGLDEPTHRANGEFPROC)(GLfloat n, GLfloat f); -GLAPI PFNGLDEPTHRANGEFPROC glad_glDepthRangef; -#define glDepthRangef glad_glDepthRangef -typedef void (APIENTRYP PFNGLCLEARDEPTHFPROC)(GLfloat d); -GLAPI PFNGLCLEARDEPTHFPROC glad_glClearDepthf; -#define glClearDepthf glad_glClearDepthf -typedef void (APIENTRYP PFNGLGETPROGRAMBINARYPROC)(GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, void *binary); -GLAPI PFNGLGETPROGRAMBINARYPROC glad_glGetProgramBinary; -#define glGetProgramBinary glad_glGetProgramBinary -typedef void (APIENTRYP PFNGLPROGRAMBINARYPROC)(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length); -GLAPI PFNGLPROGRAMBINARYPROC glad_glProgramBinary; -#define glProgramBinary glad_glProgramBinary -typedef void (APIENTRYP PFNGLPROGRAMPARAMETERIPROC)(GLuint program, GLenum pname, GLint value); -GLAPI PFNGLPROGRAMPARAMETERIPROC glad_glProgramParameteri; -#define glProgramParameteri glad_glProgramParameteri -typedef void (APIENTRYP PFNGLUSEPROGRAMSTAGESPROC)(GLuint pipeline, GLbitfield stages, GLuint program); -GLAPI PFNGLUSEPROGRAMSTAGESPROC glad_glUseProgramStages; -#define glUseProgramStages glad_glUseProgramStages -typedef void (APIENTRYP PFNGLACTIVESHADERPROGRAMPROC)(GLuint pipeline, GLuint program); -GLAPI PFNGLACTIVESHADERPROGRAMPROC glad_glActiveShaderProgram; -#define glActiveShaderProgram glad_glActiveShaderProgram -typedef GLuint (APIENTRYP PFNGLCREATESHADERPROGRAMVPROC)(GLenum type, GLsizei count, const GLchar *const*strings); -GLAPI PFNGLCREATESHADERPROGRAMVPROC glad_glCreateShaderProgramv; -#define glCreateShaderProgramv glad_glCreateShaderProgramv -typedef void (APIENTRYP PFNGLBINDPROGRAMPIPELINEPROC)(GLuint pipeline); -GLAPI PFNGLBINDPROGRAMPIPELINEPROC glad_glBindProgramPipeline; -#define glBindProgramPipeline glad_glBindProgramPipeline -typedef void (APIENTRYP PFNGLDELETEPROGRAMPIPELINESPROC)(GLsizei n, const GLuint *pipelines); -GLAPI PFNGLDELETEPROGRAMPIPELINESPROC glad_glDeleteProgramPipelines; -#define glDeleteProgramPipelines glad_glDeleteProgramPipelines -typedef void (APIENTRYP PFNGLGENPROGRAMPIPELINESPROC)(GLsizei n, GLuint *pipelines); -GLAPI PFNGLGENPROGRAMPIPELINESPROC glad_glGenProgramPipelines; -#define glGenProgramPipelines glad_glGenProgramPipelines -typedef GLboolean (APIENTRYP PFNGLISPROGRAMPIPELINEPROC)(GLuint pipeline); -GLAPI PFNGLISPROGRAMPIPELINEPROC glad_glIsProgramPipeline; -#define glIsProgramPipeline glad_glIsProgramPipeline -typedef void (APIENTRYP PFNGLGETPROGRAMPIPELINEIVPROC)(GLuint pipeline, GLenum pname, GLint *params); -GLAPI PFNGLGETPROGRAMPIPELINEIVPROC glad_glGetProgramPipelineiv; -#define glGetProgramPipelineiv glad_glGetProgramPipelineiv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IPROC)(GLuint program, GLint location, GLint v0); -GLAPI PFNGLPROGRAMUNIFORM1IPROC glad_glProgramUniform1i; -#define glProgramUniform1i glad_glProgramUniform1i -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IVPROC)(GLuint program, GLint location, GLsizei count, const GLint *value); -GLAPI PFNGLPROGRAMUNIFORM1IVPROC glad_glProgramUniform1iv; -#define glProgramUniform1iv glad_glProgramUniform1iv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FPROC)(GLuint program, GLint location, GLfloat v0); -GLAPI PFNGLPROGRAMUNIFORM1FPROC glad_glProgramUniform1f; -#define glProgramUniform1f glad_glProgramUniform1f -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FVPROC)(GLuint program, GLint location, GLsizei count, const GLfloat *value); -GLAPI PFNGLPROGRAMUNIFORM1FVPROC glad_glProgramUniform1fv; -#define glProgramUniform1fv glad_glProgramUniform1fv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DPROC)(GLuint program, GLint location, GLdouble v0); -GLAPI PFNGLPROGRAMUNIFORM1DPROC glad_glProgramUniform1d; -#define glProgramUniform1d glad_glProgramUniform1d -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DVPROC)(GLuint program, GLint location, GLsizei count, const GLdouble *value); -GLAPI PFNGLPROGRAMUNIFORM1DVPROC glad_glProgramUniform1dv; -#define glProgramUniform1dv glad_glProgramUniform1dv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIPROC)(GLuint program, GLint location, GLuint v0); -GLAPI PFNGLPROGRAMUNIFORM1UIPROC glad_glProgramUniform1ui; -#define glProgramUniform1ui glad_glProgramUniform1ui -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIVPROC)(GLuint program, GLint location, GLsizei count, const GLuint *value); -GLAPI PFNGLPROGRAMUNIFORM1UIVPROC glad_glProgramUniform1uiv; -#define glProgramUniform1uiv glad_glProgramUniform1uiv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IPROC)(GLuint program, GLint location, GLint v0, GLint v1); -GLAPI PFNGLPROGRAMUNIFORM2IPROC glad_glProgramUniform2i; -#define glProgramUniform2i glad_glProgramUniform2i -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IVPROC)(GLuint program, GLint location, GLsizei count, const GLint *value); -GLAPI PFNGLPROGRAMUNIFORM2IVPROC glad_glProgramUniform2iv; -#define glProgramUniform2iv glad_glProgramUniform2iv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FPROC)(GLuint program, GLint location, GLfloat v0, GLfloat v1); -GLAPI PFNGLPROGRAMUNIFORM2FPROC glad_glProgramUniform2f; -#define glProgramUniform2f glad_glProgramUniform2f -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FVPROC)(GLuint program, GLint location, GLsizei count, const GLfloat *value); -GLAPI PFNGLPROGRAMUNIFORM2FVPROC glad_glProgramUniform2fv; -#define glProgramUniform2fv glad_glProgramUniform2fv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DPROC)(GLuint program, GLint location, GLdouble v0, GLdouble v1); -GLAPI PFNGLPROGRAMUNIFORM2DPROC glad_glProgramUniform2d; -#define glProgramUniform2d glad_glProgramUniform2d -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DVPROC)(GLuint program, GLint location, GLsizei count, const GLdouble *value); -GLAPI PFNGLPROGRAMUNIFORM2DVPROC glad_glProgramUniform2dv; -#define glProgramUniform2dv glad_glProgramUniform2dv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIPROC)(GLuint program, GLint location, GLuint v0, GLuint v1); -GLAPI PFNGLPROGRAMUNIFORM2UIPROC glad_glProgramUniform2ui; -#define glProgramUniform2ui glad_glProgramUniform2ui -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIVPROC)(GLuint program, GLint location, GLsizei count, const GLuint *value); -GLAPI PFNGLPROGRAMUNIFORM2UIVPROC glad_glProgramUniform2uiv; -#define glProgramUniform2uiv glad_glProgramUniform2uiv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IPROC)(GLuint program, GLint location, GLint v0, GLint v1, GLint v2); -GLAPI PFNGLPROGRAMUNIFORM3IPROC glad_glProgramUniform3i; -#define glProgramUniform3i glad_glProgramUniform3i -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IVPROC)(GLuint program, GLint location, GLsizei count, const GLint *value); -GLAPI PFNGLPROGRAMUNIFORM3IVPROC glad_glProgramUniform3iv; -#define glProgramUniform3iv glad_glProgramUniform3iv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FPROC)(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2); -GLAPI PFNGLPROGRAMUNIFORM3FPROC glad_glProgramUniform3f; -#define glProgramUniform3f glad_glProgramUniform3f -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FVPROC)(GLuint program, GLint location, GLsizei count, const GLfloat *value); -GLAPI PFNGLPROGRAMUNIFORM3FVPROC glad_glProgramUniform3fv; -#define glProgramUniform3fv glad_glProgramUniform3fv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DPROC)(GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2); -GLAPI PFNGLPROGRAMUNIFORM3DPROC glad_glProgramUniform3d; -#define glProgramUniform3d glad_glProgramUniform3d -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DVPROC)(GLuint program, GLint location, GLsizei count, const GLdouble *value); -GLAPI PFNGLPROGRAMUNIFORM3DVPROC glad_glProgramUniform3dv; -#define glProgramUniform3dv glad_glProgramUniform3dv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIPROC)(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2); -GLAPI PFNGLPROGRAMUNIFORM3UIPROC glad_glProgramUniform3ui; -#define glProgramUniform3ui glad_glProgramUniform3ui -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIVPROC)(GLuint program, GLint location, GLsizei count, const GLuint *value); -GLAPI PFNGLPROGRAMUNIFORM3UIVPROC glad_glProgramUniform3uiv; -#define glProgramUniform3uiv glad_glProgramUniform3uiv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IPROC)(GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3); -GLAPI PFNGLPROGRAMUNIFORM4IPROC glad_glProgramUniform4i; -#define glProgramUniform4i glad_glProgramUniform4i -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IVPROC)(GLuint program, GLint location, GLsizei count, const GLint *value); -GLAPI PFNGLPROGRAMUNIFORM4IVPROC glad_glProgramUniform4iv; -#define glProgramUniform4iv glad_glProgramUniform4iv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FPROC)(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); -GLAPI PFNGLPROGRAMUNIFORM4FPROC glad_glProgramUniform4f; -#define glProgramUniform4f glad_glProgramUniform4f -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FVPROC)(GLuint program, GLint location, GLsizei count, const GLfloat *value); -GLAPI PFNGLPROGRAMUNIFORM4FVPROC glad_glProgramUniform4fv; -#define glProgramUniform4fv glad_glProgramUniform4fv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DPROC)(GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3); -GLAPI PFNGLPROGRAMUNIFORM4DPROC glad_glProgramUniform4d; -#define glProgramUniform4d glad_glProgramUniform4d -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DVPROC)(GLuint program, GLint location, GLsizei count, const GLdouble *value); -GLAPI PFNGLPROGRAMUNIFORM4DVPROC glad_glProgramUniform4dv; -#define glProgramUniform4dv glad_glProgramUniform4dv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIPROC)(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); -GLAPI PFNGLPROGRAMUNIFORM4UIPROC glad_glProgramUniform4ui; -#define glProgramUniform4ui glad_glProgramUniform4ui -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIVPROC)(GLuint program, GLint location, GLsizei count, const GLuint *value); -GLAPI PFNGLPROGRAMUNIFORM4UIVPROC glad_glProgramUniform4uiv; -#define glProgramUniform4uiv glad_glProgramUniform4uiv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2FVPROC)(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI PFNGLPROGRAMUNIFORMMATRIX2FVPROC glad_glProgramUniformMatrix2fv; -#define glProgramUniformMatrix2fv glad_glProgramUniformMatrix2fv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3FVPROC)(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI PFNGLPROGRAMUNIFORMMATRIX3FVPROC glad_glProgramUniformMatrix3fv; -#define glProgramUniformMatrix3fv glad_glProgramUniformMatrix3fv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4FVPROC)(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI PFNGLPROGRAMUNIFORMMATRIX4FVPROC glad_glProgramUniformMatrix4fv; -#define glProgramUniformMatrix4fv glad_glProgramUniformMatrix4fv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2DVPROC)(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI PFNGLPROGRAMUNIFORMMATRIX2DVPROC glad_glProgramUniformMatrix2dv; -#define glProgramUniformMatrix2dv glad_glProgramUniformMatrix2dv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3DVPROC)(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI PFNGLPROGRAMUNIFORMMATRIX3DVPROC glad_glProgramUniformMatrix3dv; -#define glProgramUniformMatrix3dv glad_glProgramUniformMatrix3dv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4DVPROC)(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI PFNGLPROGRAMUNIFORMMATRIX4DVPROC glad_glProgramUniformMatrix4dv; -#define glProgramUniformMatrix4dv glad_glProgramUniformMatrix4dv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3FVPROC)(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI PFNGLPROGRAMUNIFORMMATRIX2X3FVPROC glad_glProgramUniformMatrix2x3fv; -#define glProgramUniformMatrix2x3fv glad_glProgramUniformMatrix2x3fv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2FVPROC)(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI PFNGLPROGRAMUNIFORMMATRIX3X2FVPROC glad_glProgramUniformMatrix3x2fv; -#define glProgramUniformMatrix3x2fv glad_glProgramUniformMatrix3x2fv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4FVPROC)(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI PFNGLPROGRAMUNIFORMMATRIX2X4FVPROC glad_glProgramUniformMatrix2x4fv; -#define glProgramUniformMatrix2x4fv glad_glProgramUniformMatrix2x4fv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2FVPROC)(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI PFNGLPROGRAMUNIFORMMATRIX4X2FVPROC glad_glProgramUniformMatrix4x2fv; -#define glProgramUniformMatrix4x2fv glad_glProgramUniformMatrix4x2fv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4FVPROC)(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI PFNGLPROGRAMUNIFORMMATRIX3X4FVPROC glad_glProgramUniformMatrix3x4fv; -#define glProgramUniformMatrix3x4fv glad_glProgramUniformMatrix3x4fv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3FVPROC)(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI PFNGLPROGRAMUNIFORMMATRIX4X3FVPROC glad_glProgramUniformMatrix4x3fv; -#define glProgramUniformMatrix4x3fv glad_glProgramUniformMatrix4x3fv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3DVPROC)(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI PFNGLPROGRAMUNIFORMMATRIX2X3DVPROC glad_glProgramUniformMatrix2x3dv; -#define glProgramUniformMatrix2x3dv glad_glProgramUniformMatrix2x3dv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2DVPROC)(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI PFNGLPROGRAMUNIFORMMATRIX3X2DVPROC glad_glProgramUniformMatrix3x2dv; -#define glProgramUniformMatrix3x2dv glad_glProgramUniformMatrix3x2dv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4DVPROC)(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI PFNGLPROGRAMUNIFORMMATRIX2X4DVPROC glad_glProgramUniformMatrix2x4dv; -#define glProgramUniformMatrix2x4dv glad_glProgramUniformMatrix2x4dv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2DVPROC)(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI PFNGLPROGRAMUNIFORMMATRIX4X2DVPROC glad_glProgramUniformMatrix4x2dv; -#define glProgramUniformMatrix4x2dv glad_glProgramUniformMatrix4x2dv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4DVPROC)(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI PFNGLPROGRAMUNIFORMMATRIX3X4DVPROC glad_glProgramUniformMatrix3x4dv; -#define glProgramUniformMatrix3x4dv glad_glProgramUniformMatrix3x4dv -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3DVPROC)(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI PFNGLPROGRAMUNIFORMMATRIX4X3DVPROC glad_glProgramUniformMatrix4x3dv; -#define glProgramUniformMatrix4x3dv glad_glProgramUniformMatrix4x3dv -typedef void (APIENTRYP PFNGLVALIDATEPROGRAMPIPELINEPROC)(GLuint pipeline); -GLAPI PFNGLVALIDATEPROGRAMPIPELINEPROC glad_glValidateProgramPipeline; -#define glValidateProgramPipeline glad_glValidateProgramPipeline -typedef void (APIENTRYP PFNGLGETPROGRAMPIPELINEINFOLOGPROC)(GLuint pipeline, GLsizei bufSize, GLsizei *length, GLchar *infoLog); -GLAPI PFNGLGETPROGRAMPIPELINEINFOLOGPROC glad_glGetProgramPipelineInfoLog; -#define glGetProgramPipelineInfoLog glad_glGetProgramPipelineInfoLog -typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DPROC)(GLuint index, GLdouble x); -GLAPI PFNGLVERTEXATTRIBL1DPROC glad_glVertexAttribL1d; -#define glVertexAttribL1d glad_glVertexAttribL1d -typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DPROC)(GLuint index, GLdouble x, GLdouble y); -GLAPI PFNGLVERTEXATTRIBL2DPROC glad_glVertexAttribL2d; -#define glVertexAttribL2d glad_glVertexAttribL2d -typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DPROC)(GLuint index, GLdouble x, GLdouble y, GLdouble z); -GLAPI PFNGLVERTEXATTRIBL3DPROC glad_glVertexAttribL3d; -#define glVertexAttribL3d glad_glVertexAttribL3d -typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DPROC)(GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -GLAPI PFNGLVERTEXATTRIBL4DPROC glad_glVertexAttribL4d; -#define glVertexAttribL4d glad_glVertexAttribL4d -typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DVPROC)(GLuint index, const GLdouble *v); -GLAPI PFNGLVERTEXATTRIBL1DVPROC glad_glVertexAttribL1dv; -#define glVertexAttribL1dv glad_glVertexAttribL1dv -typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DVPROC)(GLuint index, const GLdouble *v); -GLAPI PFNGLVERTEXATTRIBL2DVPROC glad_glVertexAttribL2dv; -#define glVertexAttribL2dv glad_glVertexAttribL2dv -typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DVPROC)(GLuint index, const GLdouble *v); -GLAPI PFNGLVERTEXATTRIBL3DVPROC glad_glVertexAttribL3dv; -#define glVertexAttribL3dv glad_glVertexAttribL3dv -typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DVPROC)(GLuint index, const GLdouble *v); -GLAPI PFNGLVERTEXATTRIBL4DVPROC glad_glVertexAttribL4dv; -#define glVertexAttribL4dv glad_glVertexAttribL4dv -typedef void (APIENTRYP PFNGLVERTEXATTRIBLPOINTERPROC)(GLuint index, GLint size, GLenum type, GLsizei stride, const void *pointer); -GLAPI PFNGLVERTEXATTRIBLPOINTERPROC glad_glVertexAttribLPointer; -#define glVertexAttribLPointer glad_glVertexAttribLPointer -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLDVPROC)(GLuint index, GLenum pname, GLdouble *params); -GLAPI PFNGLGETVERTEXATTRIBLDVPROC glad_glGetVertexAttribLdv; -#define glGetVertexAttribLdv glad_glGetVertexAttribLdv -typedef void (APIENTRYP PFNGLVIEWPORTARRAYVPROC)(GLuint first, GLsizei count, const GLfloat *v); -GLAPI PFNGLVIEWPORTARRAYVPROC glad_glViewportArrayv; -#define glViewportArrayv glad_glViewportArrayv -typedef void (APIENTRYP PFNGLVIEWPORTINDEXEDFPROC)(GLuint index, GLfloat x, GLfloat y, GLfloat w, GLfloat h); -GLAPI PFNGLVIEWPORTINDEXEDFPROC glad_glViewportIndexedf; -#define glViewportIndexedf glad_glViewportIndexedf -typedef void (APIENTRYP PFNGLVIEWPORTINDEXEDFVPROC)(GLuint index, const GLfloat *v); -GLAPI PFNGLVIEWPORTINDEXEDFVPROC glad_glViewportIndexedfv; -#define glViewportIndexedfv glad_glViewportIndexedfv -typedef void (APIENTRYP PFNGLSCISSORARRAYVPROC)(GLuint first, GLsizei count, const GLint *v); -GLAPI PFNGLSCISSORARRAYVPROC glad_glScissorArrayv; -#define glScissorArrayv glad_glScissorArrayv -typedef void (APIENTRYP PFNGLSCISSORINDEXEDPROC)(GLuint index, GLint left, GLint bottom, GLsizei width, GLsizei height); -GLAPI PFNGLSCISSORINDEXEDPROC glad_glScissorIndexed; -#define glScissorIndexed glad_glScissorIndexed -typedef void (APIENTRYP PFNGLSCISSORINDEXEDVPROC)(GLuint index, const GLint *v); -GLAPI PFNGLSCISSORINDEXEDVPROC glad_glScissorIndexedv; -#define glScissorIndexedv glad_glScissorIndexedv -typedef void (APIENTRYP PFNGLDEPTHRANGEARRAYVPROC)(GLuint first, GLsizei count, const GLdouble *v); -GLAPI PFNGLDEPTHRANGEARRAYVPROC glad_glDepthRangeArrayv; -#define glDepthRangeArrayv glad_glDepthRangeArrayv -typedef void (APIENTRYP PFNGLDEPTHRANGEINDEXEDPROC)(GLuint index, GLdouble n, GLdouble f); -GLAPI PFNGLDEPTHRANGEINDEXEDPROC glad_glDepthRangeIndexed; -#define glDepthRangeIndexed glad_glDepthRangeIndexed -typedef void (APIENTRYP PFNGLGETFLOATI_VPROC)(GLenum target, GLuint index, GLfloat *data); -GLAPI PFNGLGETFLOATI_VPROC glad_glGetFloati_v; -#define glGetFloati_v glad_glGetFloati_v -typedef void (APIENTRYP PFNGLGETDOUBLEI_VPROC)(GLenum target, GLuint index, GLdouble *data); -GLAPI PFNGLGETDOUBLEI_VPROC glad_glGetDoublei_v; -#define glGetDoublei_v glad_glGetDoublei_v -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/extern/glad/src/glad.c b/extern/glad/src/glad.c deleted file mode 100644 index aeb93ce..0000000 --- a/extern/glad/src/glad.c +++ /dev/null @@ -1,2121 +0,0 @@ -/* - - OpenGL loader generated by glad 0.1.36 on Sat Apr 12 17:00:07 2025. - - Language/Generator: C/C++ - Specification: gl - APIs: gl=4.1 - Profile: compatibility - Extensions: - - Loader: True - Local files: False - Omit khrplatform: False - Reproducible: False - - Commandline: - --profile="compatibility" --api="gl=4.1" --generator="c" --spec="gl" --extensions="" - Online: - https://glad.dav1d.de/#profile=compatibility&language=c&specification=gl&loader=on&api=gl%3D4.1 -*/ - -#include -#include -#include -#include - -static void* get_proc(const char *namez); - -#if defined(_WIN32) || defined(__CYGWIN__) -#ifndef _WINDOWS_ -#undef APIENTRY -#endif -#include -static HMODULE libGL; - -typedef void* (APIENTRYP PFNWGLGETPROCADDRESSPROC_PRIVATE)(const char*); -static PFNWGLGETPROCADDRESSPROC_PRIVATE gladGetProcAddressPtr; - -#ifdef _MSC_VER -#ifdef __has_include - #if __has_include() - #define HAVE_WINAPIFAMILY 1 - #endif -#elif _MSC_VER >= 1700 && !_USING_V110_SDK71_ - #define HAVE_WINAPIFAMILY 1 -#endif -#endif - -#ifdef HAVE_WINAPIFAMILY - #include - #if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) - #define IS_UWP 1 - #endif -#endif - -static -int open_gl(void) { -#ifndef IS_UWP - libGL = LoadLibraryW(L"opengl32.dll"); - if(libGL != NULL) { - void (* tmp)(void); - tmp = (void(*)(void)) GetProcAddress(libGL, "wglGetProcAddress"); - gladGetProcAddressPtr = (PFNWGLGETPROCADDRESSPROC_PRIVATE) tmp; - return gladGetProcAddressPtr != NULL; - } -#endif - - return 0; -} - -static -void close_gl(void) { - if(libGL != NULL) { - FreeLibrary((HMODULE) libGL); - libGL = NULL; - } -} -#else -#include -static void* libGL; - -#if !defined(__APPLE__) && !defined(__HAIKU__) -typedef void* (APIENTRYP PFNGLXGETPROCADDRESSPROC_PRIVATE)(const char*); -static PFNGLXGETPROCADDRESSPROC_PRIVATE gladGetProcAddressPtr; -#endif - -static -int open_gl(void) { -#ifdef __APPLE__ - static const char *NAMES[] = { - "../Frameworks/OpenGL.framework/OpenGL", - "/Library/Frameworks/OpenGL.framework/OpenGL", - "/System/Library/Frameworks/OpenGL.framework/OpenGL", - "/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL" - }; -#else - static const char *NAMES[] = {"libGL.so.1", "libGL.so"}; -#endif - - unsigned int index = 0; - for(index = 0; index < (sizeof(NAMES) / sizeof(NAMES[0])); index++) { - libGL = dlopen(NAMES[index], RTLD_NOW | RTLD_GLOBAL); - - if(libGL != NULL) { -#if defined(__APPLE__) || defined(__HAIKU__) - return 1; -#else - gladGetProcAddressPtr = (PFNGLXGETPROCADDRESSPROC_PRIVATE)dlsym(libGL, - "glXGetProcAddressARB"); - return gladGetProcAddressPtr != NULL; -#endif - } - } - - return 0; -} - -static -void close_gl(void) { - if(libGL != NULL) { - dlclose(libGL); - libGL = NULL; - } -} -#endif - -static -void* get_proc(const char *namez) { - void* result = NULL; - if(libGL == NULL) return NULL; - -#if !defined(__APPLE__) && !defined(__HAIKU__) - if(gladGetProcAddressPtr != NULL) { - result = gladGetProcAddressPtr(namez); - } -#endif - if(result == NULL) { -#if defined(_WIN32) || defined(__CYGWIN__) - result = (void*)GetProcAddress((HMODULE) libGL, namez); -#else - result = dlsym(libGL, namez); -#endif - } - - return result; -} - -int gladLoadGL(void) { - int status = 0; - - if(open_gl()) { - status = gladLoadGLLoader(&get_proc); - close_gl(); - } - - return status; -} - -struct gladGLversionStruct GLVersion = { 0, 0 }; - -#if defined(GL_ES_VERSION_3_0) || defined(GL_VERSION_3_0) -#define _GLAD_IS_SOME_NEW_VERSION 1 -#endif - -static int max_loaded_major; -static int max_loaded_minor; - -static const char *exts = NULL; -static int num_exts_i = 0; -static char **exts_i = NULL; - -static int get_exts(void) { -#ifdef _GLAD_IS_SOME_NEW_VERSION - if(max_loaded_major < 3) { -#endif - exts = (const char *)glGetString(GL_EXTENSIONS); -#ifdef _GLAD_IS_SOME_NEW_VERSION - } else { - int index; - - num_exts_i = 0; - glGetIntegerv(GL_NUM_EXTENSIONS, &num_exts_i); - if (num_exts_i > 0) { - exts_i = (char **)malloc((size_t)num_exts_i * (sizeof *exts_i)); - } - - if (exts_i == NULL) { - return 0; - } - - for(index = 0; index < num_exts_i; index++) { - const char *gl_str_tmp = (const char*)glGetStringi(GL_EXTENSIONS, index); - size_t len = strlen(gl_str_tmp); - - char *local_str = (char*)malloc((len+1) * sizeof(char)); - if(local_str != NULL) { - memcpy(local_str, gl_str_tmp, (len+1) * sizeof(char)); - } - exts_i[index] = local_str; - } - } -#endif - return 1; -} - -static void free_exts(void) { - if (exts_i != NULL) { - int index; - for(index = 0; index < num_exts_i; index++) { - free((char *)exts_i[index]); - } - free((void *)exts_i); - exts_i = NULL; - } -} - -static int has_ext(const char *ext) { -#ifdef _GLAD_IS_SOME_NEW_VERSION - if(max_loaded_major < 3) { -#endif - const char *extensions; - const char *loc; - const char *terminator; - extensions = exts; - if(extensions == NULL || ext == NULL) { - return 0; - } - - while(1) { - loc = strstr(extensions, ext); - if(loc == NULL) { - return 0; - } - - terminator = loc + strlen(ext); - if((loc == extensions || *(loc - 1) == ' ') && - (*terminator == ' ' || *terminator == '\0')) { - return 1; - } - extensions = terminator; - } -#ifdef _GLAD_IS_SOME_NEW_VERSION - } else { - int index; - if(exts_i == NULL) return 0; - for(index = 0; index < num_exts_i; index++) { - const char *e = exts_i[index]; - - if(exts_i[index] != NULL && strcmp(e, ext) == 0) { - return 1; - } - } - } -#endif - - return 0; -} -int GLAD_GL_VERSION_1_0 = 0; -int GLAD_GL_VERSION_1_1 = 0; -int GLAD_GL_VERSION_1_2 = 0; -int GLAD_GL_VERSION_1_3 = 0; -int GLAD_GL_VERSION_1_4 = 0; -int GLAD_GL_VERSION_1_5 = 0; -int GLAD_GL_VERSION_2_0 = 0; -int GLAD_GL_VERSION_2_1 = 0; -int GLAD_GL_VERSION_3_0 = 0; -int GLAD_GL_VERSION_3_1 = 0; -int GLAD_GL_VERSION_3_2 = 0; -int GLAD_GL_VERSION_3_3 = 0; -int GLAD_GL_VERSION_4_0 = 0; -int GLAD_GL_VERSION_4_1 = 0; -PFNGLACCUMPROC glad_glAccum = NULL; -PFNGLACTIVESHADERPROGRAMPROC glad_glActiveShaderProgram = NULL; -PFNGLACTIVETEXTUREPROC glad_glActiveTexture = NULL; -PFNGLALPHAFUNCPROC glad_glAlphaFunc = NULL; -PFNGLARETEXTURESRESIDENTPROC glad_glAreTexturesResident = NULL; -PFNGLARRAYELEMENTPROC glad_glArrayElement = NULL; -PFNGLATTACHSHADERPROC glad_glAttachShader = NULL; -PFNGLBEGINPROC glad_glBegin = NULL; -PFNGLBEGINCONDITIONALRENDERPROC glad_glBeginConditionalRender = NULL; -PFNGLBEGINQUERYPROC glad_glBeginQuery = NULL; -PFNGLBEGINQUERYINDEXEDPROC glad_glBeginQueryIndexed = NULL; -PFNGLBEGINTRANSFORMFEEDBACKPROC glad_glBeginTransformFeedback = NULL; -PFNGLBINDATTRIBLOCATIONPROC glad_glBindAttribLocation = NULL; -PFNGLBINDBUFFERPROC glad_glBindBuffer = NULL; -PFNGLBINDBUFFERBASEPROC glad_glBindBufferBase = NULL; -PFNGLBINDBUFFERRANGEPROC glad_glBindBufferRange = NULL; -PFNGLBINDFRAGDATALOCATIONPROC glad_glBindFragDataLocation = NULL; -PFNGLBINDFRAGDATALOCATIONINDEXEDPROC glad_glBindFragDataLocationIndexed = NULL; -PFNGLBINDFRAMEBUFFERPROC glad_glBindFramebuffer = NULL; -PFNGLBINDPROGRAMPIPELINEPROC glad_glBindProgramPipeline = NULL; -PFNGLBINDRENDERBUFFERPROC glad_glBindRenderbuffer = NULL; -PFNGLBINDSAMPLERPROC glad_glBindSampler = NULL; -PFNGLBINDTEXTUREPROC glad_glBindTexture = NULL; -PFNGLBINDTRANSFORMFEEDBACKPROC glad_glBindTransformFeedback = NULL; -PFNGLBINDVERTEXARRAYPROC glad_glBindVertexArray = NULL; -PFNGLBITMAPPROC glad_glBitmap = NULL; -PFNGLBLENDCOLORPROC glad_glBlendColor = NULL; -PFNGLBLENDEQUATIONPROC glad_glBlendEquation = NULL; -PFNGLBLENDEQUATIONSEPARATEPROC glad_glBlendEquationSeparate = NULL; -PFNGLBLENDEQUATIONSEPARATEIPROC glad_glBlendEquationSeparatei = NULL; -PFNGLBLENDEQUATIONIPROC glad_glBlendEquationi = NULL; -PFNGLBLENDFUNCPROC glad_glBlendFunc = NULL; -PFNGLBLENDFUNCSEPARATEPROC glad_glBlendFuncSeparate = NULL; -PFNGLBLENDFUNCSEPARATEIPROC glad_glBlendFuncSeparatei = NULL; -PFNGLBLENDFUNCIPROC glad_glBlendFunci = NULL; -PFNGLBLITFRAMEBUFFERPROC glad_glBlitFramebuffer = NULL; -PFNGLBUFFERDATAPROC glad_glBufferData = NULL; -PFNGLBUFFERSUBDATAPROC glad_glBufferSubData = NULL; -PFNGLCALLLISTPROC glad_glCallList = NULL; -PFNGLCALLLISTSPROC glad_glCallLists = NULL; -PFNGLCHECKFRAMEBUFFERSTATUSPROC glad_glCheckFramebufferStatus = NULL; -PFNGLCLAMPCOLORPROC glad_glClampColor = NULL; -PFNGLCLEARPROC glad_glClear = NULL; -PFNGLCLEARACCUMPROC glad_glClearAccum = NULL; -PFNGLCLEARBUFFERFIPROC glad_glClearBufferfi = NULL; -PFNGLCLEARBUFFERFVPROC glad_glClearBufferfv = NULL; -PFNGLCLEARBUFFERIVPROC glad_glClearBufferiv = NULL; -PFNGLCLEARBUFFERUIVPROC glad_glClearBufferuiv = NULL; -PFNGLCLEARCOLORPROC glad_glClearColor = NULL; -PFNGLCLEARDEPTHPROC glad_glClearDepth = NULL; -PFNGLCLEARDEPTHFPROC glad_glClearDepthf = NULL; -PFNGLCLEARINDEXPROC glad_glClearIndex = NULL; -PFNGLCLEARSTENCILPROC glad_glClearStencil = NULL; -PFNGLCLIENTACTIVETEXTUREPROC glad_glClientActiveTexture = NULL; -PFNGLCLIENTWAITSYNCPROC glad_glClientWaitSync = NULL; -PFNGLCLIPPLANEPROC glad_glClipPlane = NULL; -PFNGLCOLOR3BPROC glad_glColor3b = NULL; -PFNGLCOLOR3BVPROC glad_glColor3bv = NULL; -PFNGLCOLOR3DPROC glad_glColor3d = NULL; -PFNGLCOLOR3DVPROC glad_glColor3dv = NULL; -PFNGLCOLOR3FPROC glad_glColor3f = NULL; -PFNGLCOLOR3FVPROC glad_glColor3fv = NULL; -PFNGLCOLOR3IPROC glad_glColor3i = NULL; -PFNGLCOLOR3IVPROC glad_glColor3iv = NULL; -PFNGLCOLOR3SPROC glad_glColor3s = NULL; -PFNGLCOLOR3SVPROC glad_glColor3sv = NULL; -PFNGLCOLOR3UBPROC glad_glColor3ub = NULL; -PFNGLCOLOR3UBVPROC glad_glColor3ubv = NULL; -PFNGLCOLOR3UIPROC glad_glColor3ui = NULL; -PFNGLCOLOR3UIVPROC glad_glColor3uiv = NULL; -PFNGLCOLOR3USPROC glad_glColor3us = NULL; -PFNGLCOLOR3USVPROC glad_glColor3usv = NULL; -PFNGLCOLOR4BPROC glad_glColor4b = NULL; -PFNGLCOLOR4BVPROC glad_glColor4bv = NULL; -PFNGLCOLOR4DPROC glad_glColor4d = NULL; -PFNGLCOLOR4DVPROC glad_glColor4dv = NULL; -PFNGLCOLOR4FPROC glad_glColor4f = NULL; -PFNGLCOLOR4FVPROC glad_glColor4fv = NULL; -PFNGLCOLOR4IPROC glad_glColor4i = NULL; -PFNGLCOLOR4IVPROC glad_glColor4iv = NULL; -PFNGLCOLOR4SPROC glad_glColor4s = NULL; -PFNGLCOLOR4SVPROC glad_glColor4sv = NULL; -PFNGLCOLOR4UBPROC glad_glColor4ub = NULL; -PFNGLCOLOR4UBVPROC glad_glColor4ubv = NULL; -PFNGLCOLOR4UIPROC glad_glColor4ui = NULL; -PFNGLCOLOR4UIVPROC glad_glColor4uiv = NULL; -PFNGLCOLOR4USPROC glad_glColor4us = NULL; -PFNGLCOLOR4USVPROC glad_glColor4usv = NULL; -PFNGLCOLORMASKPROC glad_glColorMask = NULL; -PFNGLCOLORMASKIPROC glad_glColorMaski = NULL; -PFNGLCOLORMATERIALPROC glad_glColorMaterial = NULL; -PFNGLCOLORP3UIPROC glad_glColorP3ui = NULL; -PFNGLCOLORP3UIVPROC glad_glColorP3uiv = NULL; -PFNGLCOLORP4UIPROC glad_glColorP4ui = NULL; -PFNGLCOLORP4UIVPROC glad_glColorP4uiv = NULL; -PFNGLCOLORPOINTERPROC glad_glColorPointer = NULL; -PFNGLCOMPILESHADERPROC glad_glCompileShader = NULL; -PFNGLCOMPRESSEDTEXIMAGE1DPROC glad_glCompressedTexImage1D = NULL; -PFNGLCOMPRESSEDTEXIMAGE2DPROC glad_glCompressedTexImage2D = NULL; -PFNGLCOMPRESSEDTEXIMAGE3DPROC glad_glCompressedTexImage3D = NULL; -PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC glad_glCompressedTexSubImage1D = NULL; -PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC glad_glCompressedTexSubImage2D = NULL; -PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC glad_glCompressedTexSubImage3D = NULL; -PFNGLCOPYBUFFERSUBDATAPROC glad_glCopyBufferSubData = NULL; -PFNGLCOPYPIXELSPROC glad_glCopyPixels = NULL; -PFNGLCOPYTEXIMAGE1DPROC glad_glCopyTexImage1D = NULL; -PFNGLCOPYTEXIMAGE2DPROC glad_glCopyTexImage2D = NULL; -PFNGLCOPYTEXSUBIMAGE1DPROC glad_glCopyTexSubImage1D = NULL; -PFNGLCOPYTEXSUBIMAGE2DPROC glad_glCopyTexSubImage2D = NULL; -PFNGLCOPYTEXSUBIMAGE3DPROC glad_glCopyTexSubImage3D = NULL; -PFNGLCREATEPROGRAMPROC glad_glCreateProgram = NULL; -PFNGLCREATESHADERPROC glad_glCreateShader = NULL; -PFNGLCREATESHADERPROGRAMVPROC glad_glCreateShaderProgramv = NULL; -PFNGLCULLFACEPROC glad_glCullFace = NULL; -PFNGLDELETEBUFFERSPROC glad_glDeleteBuffers = NULL; -PFNGLDELETEFRAMEBUFFERSPROC glad_glDeleteFramebuffers = NULL; -PFNGLDELETELISTSPROC glad_glDeleteLists = NULL; -PFNGLDELETEPROGRAMPROC glad_glDeleteProgram = NULL; -PFNGLDELETEPROGRAMPIPELINESPROC glad_glDeleteProgramPipelines = NULL; -PFNGLDELETEQUERIESPROC glad_glDeleteQueries = NULL; -PFNGLDELETERENDERBUFFERSPROC glad_glDeleteRenderbuffers = NULL; -PFNGLDELETESAMPLERSPROC glad_glDeleteSamplers = NULL; -PFNGLDELETESHADERPROC glad_glDeleteShader = NULL; -PFNGLDELETESYNCPROC glad_glDeleteSync = NULL; -PFNGLDELETETEXTURESPROC glad_glDeleteTextures = NULL; -PFNGLDELETETRANSFORMFEEDBACKSPROC glad_glDeleteTransformFeedbacks = NULL; -PFNGLDELETEVERTEXARRAYSPROC glad_glDeleteVertexArrays = NULL; -PFNGLDEPTHFUNCPROC glad_glDepthFunc = NULL; -PFNGLDEPTHMASKPROC glad_glDepthMask = NULL; -PFNGLDEPTHRANGEPROC glad_glDepthRange = NULL; -PFNGLDEPTHRANGEARRAYVPROC glad_glDepthRangeArrayv = NULL; -PFNGLDEPTHRANGEINDEXEDPROC glad_glDepthRangeIndexed = NULL; -PFNGLDEPTHRANGEFPROC glad_glDepthRangef = NULL; -PFNGLDETACHSHADERPROC glad_glDetachShader = NULL; -PFNGLDISABLEPROC glad_glDisable = NULL; -PFNGLDISABLECLIENTSTATEPROC glad_glDisableClientState = NULL; -PFNGLDISABLEVERTEXATTRIBARRAYPROC glad_glDisableVertexAttribArray = NULL; -PFNGLDISABLEIPROC glad_glDisablei = NULL; -PFNGLDRAWARRAYSPROC glad_glDrawArrays = NULL; -PFNGLDRAWARRAYSINDIRECTPROC glad_glDrawArraysIndirect = NULL; -PFNGLDRAWARRAYSINSTANCEDPROC glad_glDrawArraysInstanced = NULL; -PFNGLDRAWBUFFERPROC glad_glDrawBuffer = NULL; -PFNGLDRAWBUFFERSPROC glad_glDrawBuffers = NULL; -PFNGLDRAWELEMENTSPROC glad_glDrawElements = NULL; -PFNGLDRAWELEMENTSBASEVERTEXPROC glad_glDrawElementsBaseVertex = NULL; -PFNGLDRAWELEMENTSINDIRECTPROC glad_glDrawElementsIndirect = NULL; -PFNGLDRAWELEMENTSINSTANCEDPROC glad_glDrawElementsInstanced = NULL; -PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC glad_glDrawElementsInstancedBaseVertex = NULL; -PFNGLDRAWPIXELSPROC glad_glDrawPixels = NULL; -PFNGLDRAWRANGEELEMENTSPROC glad_glDrawRangeElements = NULL; -PFNGLDRAWRANGEELEMENTSBASEVERTEXPROC glad_glDrawRangeElementsBaseVertex = NULL; -PFNGLDRAWTRANSFORMFEEDBACKPROC glad_glDrawTransformFeedback = NULL; -PFNGLDRAWTRANSFORMFEEDBACKSTREAMPROC glad_glDrawTransformFeedbackStream = NULL; -PFNGLEDGEFLAGPROC glad_glEdgeFlag = NULL; -PFNGLEDGEFLAGPOINTERPROC glad_glEdgeFlagPointer = NULL; -PFNGLEDGEFLAGVPROC glad_glEdgeFlagv = NULL; -PFNGLENABLEPROC glad_glEnable = NULL; -PFNGLENABLECLIENTSTATEPROC glad_glEnableClientState = NULL; -PFNGLENABLEVERTEXATTRIBARRAYPROC glad_glEnableVertexAttribArray = NULL; -PFNGLENABLEIPROC glad_glEnablei = NULL; -PFNGLENDPROC glad_glEnd = NULL; -PFNGLENDCONDITIONALRENDERPROC glad_glEndConditionalRender = NULL; -PFNGLENDLISTPROC glad_glEndList = NULL; -PFNGLENDQUERYPROC glad_glEndQuery = NULL; -PFNGLENDQUERYINDEXEDPROC glad_glEndQueryIndexed = NULL; -PFNGLENDTRANSFORMFEEDBACKPROC glad_glEndTransformFeedback = NULL; -PFNGLEVALCOORD1DPROC glad_glEvalCoord1d = NULL; -PFNGLEVALCOORD1DVPROC glad_glEvalCoord1dv = NULL; -PFNGLEVALCOORD1FPROC glad_glEvalCoord1f = NULL; -PFNGLEVALCOORD1FVPROC glad_glEvalCoord1fv = NULL; -PFNGLEVALCOORD2DPROC glad_glEvalCoord2d = NULL; -PFNGLEVALCOORD2DVPROC glad_glEvalCoord2dv = NULL; -PFNGLEVALCOORD2FPROC glad_glEvalCoord2f = NULL; -PFNGLEVALCOORD2FVPROC glad_glEvalCoord2fv = NULL; -PFNGLEVALMESH1PROC glad_glEvalMesh1 = NULL; -PFNGLEVALMESH2PROC glad_glEvalMesh2 = NULL; -PFNGLEVALPOINT1PROC glad_glEvalPoint1 = NULL; -PFNGLEVALPOINT2PROC glad_glEvalPoint2 = NULL; -PFNGLFEEDBACKBUFFERPROC glad_glFeedbackBuffer = NULL; -PFNGLFENCESYNCPROC glad_glFenceSync = NULL; -PFNGLFINISHPROC glad_glFinish = NULL; -PFNGLFLUSHPROC glad_glFlush = NULL; -PFNGLFLUSHMAPPEDBUFFERRANGEPROC glad_glFlushMappedBufferRange = NULL; -PFNGLFOGCOORDPOINTERPROC glad_glFogCoordPointer = NULL; -PFNGLFOGCOORDDPROC glad_glFogCoordd = NULL; -PFNGLFOGCOORDDVPROC glad_glFogCoorddv = NULL; -PFNGLFOGCOORDFPROC glad_glFogCoordf = NULL; -PFNGLFOGCOORDFVPROC glad_glFogCoordfv = NULL; -PFNGLFOGFPROC glad_glFogf = NULL; -PFNGLFOGFVPROC glad_glFogfv = NULL; -PFNGLFOGIPROC glad_glFogi = NULL; -PFNGLFOGIVPROC glad_glFogiv = NULL; -PFNGLFRAMEBUFFERRENDERBUFFERPROC glad_glFramebufferRenderbuffer = NULL; -PFNGLFRAMEBUFFERTEXTUREPROC glad_glFramebufferTexture = NULL; -PFNGLFRAMEBUFFERTEXTURE1DPROC glad_glFramebufferTexture1D = NULL; -PFNGLFRAMEBUFFERTEXTURE2DPROC glad_glFramebufferTexture2D = NULL; -PFNGLFRAMEBUFFERTEXTURE3DPROC glad_glFramebufferTexture3D = NULL; -PFNGLFRAMEBUFFERTEXTURELAYERPROC glad_glFramebufferTextureLayer = NULL; -PFNGLFRONTFACEPROC glad_glFrontFace = NULL; -PFNGLFRUSTUMPROC glad_glFrustum = NULL; -PFNGLGENBUFFERSPROC glad_glGenBuffers = NULL; -PFNGLGENFRAMEBUFFERSPROC glad_glGenFramebuffers = NULL; -PFNGLGENLISTSPROC glad_glGenLists = NULL; -PFNGLGENPROGRAMPIPELINESPROC glad_glGenProgramPipelines = NULL; -PFNGLGENQUERIESPROC glad_glGenQueries = NULL; -PFNGLGENRENDERBUFFERSPROC glad_glGenRenderbuffers = NULL; -PFNGLGENSAMPLERSPROC glad_glGenSamplers = NULL; -PFNGLGENTEXTURESPROC glad_glGenTextures = NULL; -PFNGLGENTRANSFORMFEEDBACKSPROC glad_glGenTransformFeedbacks = NULL; -PFNGLGENVERTEXARRAYSPROC glad_glGenVertexArrays = NULL; -PFNGLGENERATEMIPMAPPROC glad_glGenerateMipmap = NULL; -PFNGLGETACTIVEATTRIBPROC glad_glGetActiveAttrib = NULL; -PFNGLGETACTIVESUBROUTINENAMEPROC glad_glGetActiveSubroutineName = NULL; -PFNGLGETACTIVESUBROUTINEUNIFORMNAMEPROC glad_glGetActiveSubroutineUniformName = NULL; -PFNGLGETACTIVESUBROUTINEUNIFORMIVPROC glad_glGetActiveSubroutineUniformiv = NULL; -PFNGLGETACTIVEUNIFORMPROC glad_glGetActiveUniform = NULL; -PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC glad_glGetActiveUniformBlockName = NULL; -PFNGLGETACTIVEUNIFORMBLOCKIVPROC glad_glGetActiveUniformBlockiv = NULL; -PFNGLGETACTIVEUNIFORMNAMEPROC glad_glGetActiveUniformName = NULL; -PFNGLGETACTIVEUNIFORMSIVPROC glad_glGetActiveUniformsiv = NULL; -PFNGLGETATTACHEDSHADERSPROC glad_glGetAttachedShaders = NULL; -PFNGLGETATTRIBLOCATIONPROC glad_glGetAttribLocation = NULL; -PFNGLGETBOOLEANI_VPROC glad_glGetBooleani_v = NULL; -PFNGLGETBOOLEANVPROC glad_glGetBooleanv = NULL; -PFNGLGETBUFFERPARAMETERI64VPROC glad_glGetBufferParameteri64v = NULL; -PFNGLGETBUFFERPARAMETERIVPROC glad_glGetBufferParameteriv = NULL; -PFNGLGETBUFFERPOINTERVPROC glad_glGetBufferPointerv = NULL; -PFNGLGETBUFFERSUBDATAPROC glad_glGetBufferSubData = NULL; -PFNGLGETCLIPPLANEPROC glad_glGetClipPlane = NULL; -PFNGLGETCOMPRESSEDTEXIMAGEPROC glad_glGetCompressedTexImage = NULL; -PFNGLGETDOUBLEI_VPROC glad_glGetDoublei_v = NULL; -PFNGLGETDOUBLEVPROC glad_glGetDoublev = NULL; -PFNGLGETERRORPROC glad_glGetError = NULL; -PFNGLGETFLOATI_VPROC glad_glGetFloati_v = NULL; -PFNGLGETFLOATVPROC glad_glGetFloatv = NULL; -PFNGLGETFRAGDATAINDEXPROC glad_glGetFragDataIndex = NULL; -PFNGLGETFRAGDATALOCATIONPROC glad_glGetFragDataLocation = NULL; -PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC glad_glGetFramebufferAttachmentParameteriv = NULL; -PFNGLGETINTEGER64I_VPROC glad_glGetInteger64i_v = NULL; -PFNGLGETINTEGER64VPROC glad_glGetInteger64v = NULL; -PFNGLGETINTEGERI_VPROC glad_glGetIntegeri_v = NULL; -PFNGLGETINTEGERVPROC glad_glGetIntegerv = NULL; -PFNGLGETLIGHTFVPROC glad_glGetLightfv = NULL; -PFNGLGETLIGHTIVPROC glad_glGetLightiv = NULL; -PFNGLGETMAPDVPROC glad_glGetMapdv = NULL; -PFNGLGETMAPFVPROC glad_glGetMapfv = NULL; -PFNGLGETMAPIVPROC glad_glGetMapiv = NULL; -PFNGLGETMATERIALFVPROC glad_glGetMaterialfv = NULL; -PFNGLGETMATERIALIVPROC glad_glGetMaterialiv = NULL; -PFNGLGETMULTISAMPLEFVPROC glad_glGetMultisamplefv = NULL; -PFNGLGETPIXELMAPFVPROC glad_glGetPixelMapfv = NULL; -PFNGLGETPIXELMAPUIVPROC glad_glGetPixelMapuiv = NULL; -PFNGLGETPIXELMAPUSVPROC glad_glGetPixelMapusv = NULL; -PFNGLGETPOINTERVPROC glad_glGetPointerv = NULL; -PFNGLGETPOLYGONSTIPPLEPROC glad_glGetPolygonStipple = NULL; -PFNGLGETPROGRAMBINARYPROC glad_glGetProgramBinary = NULL; -PFNGLGETPROGRAMINFOLOGPROC glad_glGetProgramInfoLog = NULL; -PFNGLGETPROGRAMPIPELINEINFOLOGPROC glad_glGetProgramPipelineInfoLog = NULL; -PFNGLGETPROGRAMPIPELINEIVPROC glad_glGetProgramPipelineiv = NULL; -PFNGLGETPROGRAMSTAGEIVPROC glad_glGetProgramStageiv = NULL; -PFNGLGETPROGRAMIVPROC glad_glGetProgramiv = NULL; -PFNGLGETQUERYINDEXEDIVPROC glad_glGetQueryIndexediv = NULL; -PFNGLGETQUERYOBJECTI64VPROC glad_glGetQueryObjecti64v = NULL; -PFNGLGETQUERYOBJECTIVPROC glad_glGetQueryObjectiv = NULL; -PFNGLGETQUERYOBJECTUI64VPROC glad_glGetQueryObjectui64v = NULL; -PFNGLGETQUERYOBJECTUIVPROC glad_glGetQueryObjectuiv = NULL; -PFNGLGETQUERYIVPROC glad_glGetQueryiv = NULL; -PFNGLGETRENDERBUFFERPARAMETERIVPROC glad_glGetRenderbufferParameteriv = NULL; -PFNGLGETSAMPLERPARAMETERIIVPROC glad_glGetSamplerParameterIiv = NULL; -PFNGLGETSAMPLERPARAMETERIUIVPROC glad_glGetSamplerParameterIuiv = NULL; -PFNGLGETSAMPLERPARAMETERFVPROC glad_glGetSamplerParameterfv = NULL; -PFNGLGETSAMPLERPARAMETERIVPROC glad_glGetSamplerParameteriv = NULL; -PFNGLGETSHADERINFOLOGPROC glad_glGetShaderInfoLog = NULL; -PFNGLGETSHADERPRECISIONFORMATPROC glad_glGetShaderPrecisionFormat = NULL; -PFNGLGETSHADERSOURCEPROC glad_glGetShaderSource = NULL; -PFNGLGETSHADERIVPROC glad_glGetShaderiv = NULL; -PFNGLGETSTRINGPROC glad_glGetString = NULL; -PFNGLGETSTRINGIPROC glad_glGetStringi = NULL; -PFNGLGETSUBROUTINEINDEXPROC glad_glGetSubroutineIndex = NULL; -PFNGLGETSUBROUTINEUNIFORMLOCATIONPROC glad_glGetSubroutineUniformLocation = NULL; -PFNGLGETSYNCIVPROC glad_glGetSynciv = NULL; -PFNGLGETTEXENVFVPROC glad_glGetTexEnvfv = NULL; -PFNGLGETTEXENVIVPROC glad_glGetTexEnviv = NULL; -PFNGLGETTEXGENDVPROC glad_glGetTexGendv = NULL; -PFNGLGETTEXGENFVPROC glad_glGetTexGenfv = NULL; -PFNGLGETTEXGENIVPROC glad_glGetTexGeniv = NULL; -PFNGLGETTEXIMAGEPROC glad_glGetTexImage = NULL; -PFNGLGETTEXLEVELPARAMETERFVPROC glad_glGetTexLevelParameterfv = NULL; -PFNGLGETTEXLEVELPARAMETERIVPROC glad_glGetTexLevelParameteriv = NULL; -PFNGLGETTEXPARAMETERIIVPROC glad_glGetTexParameterIiv = NULL; -PFNGLGETTEXPARAMETERIUIVPROC glad_glGetTexParameterIuiv = NULL; -PFNGLGETTEXPARAMETERFVPROC glad_glGetTexParameterfv = NULL; -PFNGLGETTEXPARAMETERIVPROC glad_glGetTexParameteriv = NULL; -PFNGLGETTRANSFORMFEEDBACKVARYINGPROC glad_glGetTransformFeedbackVarying = NULL; -PFNGLGETUNIFORMBLOCKINDEXPROC glad_glGetUniformBlockIndex = NULL; -PFNGLGETUNIFORMINDICESPROC glad_glGetUniformIndices = NULL; -PFNGLGETUNIFORMLOCATIONPROC glad_glGetUniformLocation = NULL; -PFNGLGETUNIFORMSUBROUTINEUIVPROC glad_glGetUniformSubroutineuiv = NULL; -PFNGLGETUNIFORMDVPROC glad_glGetUniformdv = NULL; -PFNGLGETUNIFORMFVPROC glad_glGetUniformfv = NULL; -PFNGLGETUNIFORMIVPROC glad_glGetUniformiv = NULL; -PFNGLGETUNIFORMUIVPROC glad_glGetUniformuiv = NULL; -PFNGLGETVERTEXATTRIBIIVPROC glad_glGetVertexAttribIiv = NULL; -PFNGLGETVERTEXATTRIBIUIVPROC glad_glGetVertexAttribIuiv = NULL; -PFNGLGETVERTEXATTRIBLDVPROC glad_glGetVertexAttribLdv = NULL; -PFNGLGETVERTEXATTRIBPOINTERVPROC glad_glGetVertexAttribPointerv = NULL; -PFNGLGETVERTEXATTRIBDVPROC glad_glGetVertexAttribdv = NULL; -PFNGLGETVERTEXATTRIBFVPROC glad_glGetVertexAttribfv = NULL; -PFNGLGETVERTEXATTRIBIVPROC glad_glGetVertexAttribiv = NULL; -PFNGLHINTPROC glad_glHint = NULL; -PFNGLINDEXMASKPROC glad_glIndexMask = NULL; -PFNGLINDEXPOINTERPROC glad_glIndexPointer = NULL; -PFNGLINDEXDPROC glad_glIndexd = NULL; -PFNGLINDEXDVPROC glad_glIndexdv = NULL; -PFNGLINDEXFPROC glad_glIndexf = NULL; -PFNGLINDEXFVPROC glad_glIndexfv = NULL; -PFNGLINDEXIPROC glad_glIndexi = NULL; -PFNGLINDEXIVPROC glad_glIndexiv = NULL; -PFNGLINDEXSPROC glad_glIndexs = NULL; -PFNGLINDEXSVPROC glad_glIndexsv = NULL; -PFNGLINDEXUBPROC glad_glIndexub = NULL; -PFNGLINDEXUBVPROC glad_glIndexubv = NULL; -PFNGLINITNAMESPROC glad_glInitNames = NULL; -PFNGLINTERLEAVEDARRAYSPROC glad_glInterleavedArrays = NULL; -PFNGLISBUFFERPROC glad_glIsBuffer = NULL; -PFNGLISENABLEDPROC glad_glIsEnabled = NULL; -PFNGLISENABLEDIPROC glad_glIsEnabledi = NULL; -PFNGLISFRAMEBUFFERPROC glad_glIsFramebuffer = NULL; -PFNGLISLISTPROC glad_glIsList = NULL; -PFNGLISPROGRAMPROC glad_glIsProgram = NULL; -PFNGLISPROGRAMPIPELINEPROC glad_glIsProgramPipeline = NULL; -PFNGLISQUERYPROC glad_glIsQuery = NULL; -PFNGLISRENDERBUFFERPROC glad_glIsRenderbuffer = NULL; -PFNGLISSAMPLERPROC glad_glIsSampler = NULL; -PFNGLISSHADERPROC glad_glIsShader = NULL; -PFNGLISSYNCPROC glad_glIsSync = NULL; -PFNGLISTEXTUREPROC glad_glIsTexture = NULL; -PFNGLISTRANSFORMFEEDBACKPROC glad_glIsTransformFeedback = NULL; -PFNGLISVERTEXARRAYPROC glad_glIsVertexArray = NULL; -PFNGLLIGHTMODELFPROC glad_glLightModelf = NULL; -PFNGLLIGHTMODELFVPROC glad_glLightModelfv = NULL; -PFNGLLIGHTMODELIPROC glad_glLightModeli = NULL; -PFNGLLIGHTMODELIVPROC glad_glLightModeliv = NULL; -PFNGLLIGHTFPROC glad_glLightf = NULL; -PFNGLLIGHTFVPROC glad_glLightfv = NULL; -PFNGLLIGHTIPROC glad_glLighti = NULL; -PFNGLLIGHTIVPROC glad_glLightiv = NULL; -PFNGLLINESTIPPLEPROC glad_glLineStipple = NULL; -PFNGLLINEWIDTHPROC glad_glLineWidth = NULL; -PFNGLLINKPROGRAMPROC glad_glLinkProgram = NULL; -PFNGLLISTBASEPROC glad_glListBase = NULL; -PFNGLLOADIDENTITYPROC glad_glLoadIdentity = NULL; -PFNGLLOADMATRIXDPROC glad_glLoadMatrixd = NULL; -PFNGLLOADMATRIXFPROC glad_glLoadMatrixf = NULL; -PFNGLLOADNAMEPROC glad_glLoadName = NULL; -PFNGLLOADTRANSPOSEMATRIXDPROC glad_glLoadTransposeMatrixd = NULL; -PFNGLLOADTRANSPOSEMATRIXFPROC glad_glLoadTransposeMatrixf = NULL; -PFNGLLOGICOPPROC glad_glLogicOp = NULL; -PFNGLMAP1DPROC glad_glMap1d = NULL; -PFNGLMAP1FPROC glad_glMap1f = NULL; -PFNGLMAP2DPROC glad_glMap2d = NULL; -PFNGLMAP2FPROC glad_glMap2f = NULL; -PFNGLMAPBUFFERPROC glad_glMapBuffer = NULL; -PFNGLMAPBUFFERRANGEPROC glad_glMapBufferRange = NULL; -PFNGLMAPGRID1DPROC glad_glMapGrid1d = NULL; -PFNGLMAPGRID1FPROC glad_glMapGrid1f = NULL; -PFNGLMAPGRID2DPROC glad_glMapGrid2d = NULL; -PFNGLMAPGRID2FPROC glad_glMapGrid2f = NULL; -PFNGLMATERIALFPROC glad_glMaterialf = NULL; -PFNGLMATERIALFVPROC glad_glMaterialfv = NULL; -PFNGLMATERIALIPROC glad_glMateriali = NULL; -PFNGLMATERIALIVPROC glad_glMaterialiv = NULL; -PFNGLMATRIXMODEPROC glad_glMatrixMode = NULL; -PFNGLMINSAMPLESHADINGPROC glad_glMinSampleShading = NULL; -PFNGLMULTMATRIXDPROC glad_glMultMatrixd = NULL; -PFNGLMULTMATRIXFPROC glad_glMultMatrixf = NULL; -PFNGLMULTTRANSPOSEMATRIXDPROC glad_glMultTransposeMatrixd = NULL; -PFNGLMULTTRANSPOSEMATRIXFPROC glad_glMultTransposeMatrixf = NULL; -PFNGLMULTIDRAWARRAYSPROC glad_glMultiDrawArrays = NULL; -PFNGLMULTIDRAWELEMENTSPROC glad_glMultiDrawElements = NULL; -PFNGLMULTIDRAWELEMENTSBASEVERTEXPROC glad_glMultiDrawElementsBaseVertex = NULL; -PFNGLMULTITEXCOORD1DPROC glad_glMultiTexCoord1d = NULL; -PFNGLMULTITEXCOORD1DVPROC glad_glMultiTexCoord1dv = NULL; -PFNGLMULTITEXCOORD1FPROC glad_glMultiTexCoord1f = NULL; -PFNGLMULTITEXCOORD1FVPROC glad_glMultiTexCoord1fv = NULL; -PFNGLMULTITEXCOORD1IPROC glad_glMultiTexCoord1i = NULL; -PFNGLMULTITEXCOORD1IVPROC glad_glMultiTexCoord1iv = NULL; -PFNGLMULTITEXCOORD1SPROC glad_glMultiTexCoord1s = NULL; -PFNGLMULTITEXCOORD1SVPROC glad_glMultiTexCoord1sv = NULL; -PFNGLMULTITEXCOORD2DPROC glad_glMultiTexCoord2d = NULL; -PFNGLMULTITEXCOORD2DVPROC glad_glMultiTexCoord2dv = NULL; -PFNGLMULTITEXCOORD2FPROC glad_glMultiTexCoord2f = NULL; -PFNGLMULTITEXCOORD2FVPROC glad_glMultiTexCoord2fv = NULL; -PFNGLMULTITEXCOORD2IPROC glad_glMultiTexCoord2i = NULL; -PFNGLMULTITEXCOORD2IVPROC glad_glMultiTexCoord2iv = NULL; -PFNGLMULTITEXCOORD2SPROC glad_glMultiTexCoord2s = NULL; -PFNGLMULTITEXCOORD2SVPROC glad_glMultiTexCoord2sv = NULL; -PFNGLMULTITEXCOORD3DPROC glad_glMultiTexCoord3d = NULL; -PFNGLMULTITEXCOORD3DVPROC glad_glMultiTexCoord3dv = NULL; -PFNGLMULTITEXCOORD3FPROC glad_glMultiTexCoord3f = NULL; -PFNGLMULTITEXCOORD3FVPROC glad_glMultiTexCoord3fv = NULL; -PFNGLMULTITEXCOORD3IPROC glad_glMultiTexCoord3i = NULL; -PFNGLMULTITEXCOORD3IVPROC glad_glMultiTexCoord3iv = NULL; -PFNGLMULTITEXCOORD3SPROC glad_glMultiTexCoord3s = NULL; -PFNGLMULTITEXCOORD3SVPROC glad_glMultiTexCoord3sv = NULL; -PFNGLMULTITEXCOORD4DPROC glad_glMultiTexCoord4d = NULL; -PFNGLMULTITEXCOORD4DVPROC glad_glMultiTexCoord4dv = NULL; -PFNGLMULTITEXCOORD4FPROC glad_glMultiTexCoord4f = NULL; -PFNGLMULTITEXCOORD4FVPROC glad_glMultiTexCoord4fv = NULL; -PFNGLMULTITEXCOORD4IPROC glad_glMultiTexCoord4i = NULL; -PFNGLMULTITEXCOORD4IVPROC glad_glMultiTexCoord4iv = NULL; -PFNGLMULTITEXCOORD4SPROC glad_glMultiTexCoord4s = NULL; -PFNGLMULTITEXCOORD4SVPROC glad_glMultiTexCoord4sv = NULL; -PFNGLMULTITEXCOORDP1UIPROC glad_glMultiTexCoordP1ui = NULL; -PFNGLMULTITEXCOORDP1UIVPROC glad_glMultiTexCoordP1uiv = NULL; -PFNGLMULTITEXCOORDP2UIPROC glad_glMultiTexCoordP2ui = NULL; -PFNGLMULTITEXCOORDP2UIVPROC glad_glMultiTexCoordP2uiv = NULL; -PFNGLMULTITEXCOORDP3UIPROC glad_glMultiTexCoordP3ui = NULL; -PFNGLMULTITEXCOORDP3UIVPROC glad_glMultiTexCoordP3uiv = NULL; -PFNGLMULTITEXCOORDP4UIPROC glad_glMultiTexCoordP4ui = NULL; -PFNGLMULTITEXCOORDP4UIVPROC glad_glMultiTexCoordP4uiv = NULL; -PFNGLNEWLISTPROC glad_glNewList = NULL; -PFNGLNORMAL3BPROC glad_glNormal3b = NULL; -PFNGLNORMAL3BVPROC glad_glNormal3bv = NULL; -PFNGLNORMAL3DPROC glad_glNormal3d = NULL; -PFNGLNORMAL3DVPROC glad_glNormal3dv = NULL; -PFNGLNORMAL3FPROC glad_glNormal3f = NULL; -PFNGLNORMAL3FVPROC glad_glNormal3fv = NULL; -PFNGLNORMAL3IPROC glad_glNormal3i = NULL; -PFNGLNORMAL3IVPROC glad_glNormal3iv = NULL; -PFNGLNORMAL3SPROC glad_glNormal3s = NULL; -PFNGLNORMAL3SVPROC glad_glNormal3sv = NULL; -PFNGLNORMALP3UIPROC glad_glNormalP3ui = NULL; -PFNGLNORMALP3UIVPROC glad_glNormalP3uiv = NULL; -PFNGLNORMALPOINTERPROC glad_glNormalPointer = NULL; -PFNGLORTHOPROC glad_glOrtho = NULL; -PFNGLPASSTHROUGHPROC glad_glPassThrough = NULL; -PFNGLPATCHPARAMETERFVPROC glad_glPatchParameterfv = NULL; -PFNGLPATCHPARAMETERIPROC glad_glPatchParameteri = NULL; -PFNGLPAUSETRANSFORMFEEDBACKPROC glad_glPauseTransformFeedback = NULL; -PFNGLPIXELMAPFVPROC glad_glPixelMapfv = NULL; -PFNGLPIXELMAPUIVPROC glad_glPixelMapuiv = NULL; -PFNGLPIXELMAPUSVPROC glad_glPixelMapusv = NULL; -PFNGLPIXELSTOREFPROC glad_glPixelStoref = NULL; -PFNGLPIXELSTOREIPROC glad_glPixelStorei = NULL; -PFNGLPIXELTRANSFERFPROC glad_glPixelTransferf = NULL; -PFNGLPIXELTRANSFERIPROC glad_glPixelTransferi = NULL; -PFNGLPIXELZOOMPROC glad_glPixelZoom = NULL; -PFNGLPOINTPARAMETERFPROC glad_glPointParameterf = NULL; -PFNGLPOINTPARAMETERFVPROC glad_glPointParameterfv = NULL; -PFNGLPOINTPARAMETERIPROC glad_glPointParameteri = NULL; -PFNGLPOINTPARAMETERIVPROC glad_glPointParameteriv = NULL; -PFNGLPOINTSIZEPROC glad_glPointSize = NULL; -PFNGLPOLYGONMODEPROC glad_glPolygonMode = NULL; -PFNGLPOLYGONOFFSETPROC glad_glPolygonOffset = NULL; -PFNGLPOLYGONSTIPPLEPROC glad_glPolygonStipple = NULL; -PFNGLPOPATTRIBPROC glad_glPopAttrib = NULL; -PFNGLPOPCLIENTATTRIBPROC glad_glPopClientAttrib = NULL; -PFNGLPOPMATRIXPROC glad_glPopMatrix = NULL; -PFNGLPOPNAMEPROC glad_glPopName = NULL; -PFNGLPRIMITIVERESTARTINDEXPROC glad_glPrimitiveRestartIndex = NULL; -PFNGLPRIORITIZETEXTURESPROC glad_glPrioritizeTextures = NULL; -PFNGLPROGRAMBINARYPROC glad_glProgramBinary = NULL; -PFNGLPROGRAMPARAMETERIPROC glad_glProgramParameteri = NULL; -PFNGLPROGRAMUNIFORM1DPROC glad_glProgramUniform1d = NULL; -PFNGLPROGRAMUNIFORM1DVPROC glad_glProgramUniform1dv = NULL; -PFNGLPROGRAMUNIFORM1FPROC glad_glProgramUniform1f = NULL; -PFNGLPROGRAMUNIFORM1FVPROC glad_glProgramUniform1fv = NULL; -PFNGLPROGRAMUNIFORM1IPROC glad_glProgramUniform1i = NULL; -PFNGLPROGRAMUNIFORM1IVPROC glad_glProgramUniform1iv = NULL; -PFNGLPROGRAMUNIFORM1UIPROC glad_glProgramUniform1ui = NULL; -PFNGLPROGRAMUNIFORM1UIVPROC glad_glProgramUniform1uiv = NULL; -PFNGLPROGRAMUNIFORM2DPROC glad_glProgramUniform2d = NULL; -PFNGLPROGRAMUNIFORM2DVPROC glad_glProgramUniform2dv = NULL; -PFNGLPROGRAMUNIFORM2FPROC glad_glProgramUniform2f = NULL; -PFNGLPROGRAMUNIFORM2FVPROC glad_glProgramUniform2fv = NULL; -PFNGLPROGRAMUNIFORM2IPROC glad_glProgramUniform2i = NULL; -PFNGLPROGRAMUNIFORM2IVPROC glad_glProgramUniform2iv = NULL; -PFNGLPROGRAMUNIFORM2UIPROC glad_glProgramUniform2ui = NULL; -PFNGLPROGRAMUNIFORM2UIVPROC glad_glProgramUniform2uiv = NULL; -PFNGLPROGRAMUNIFORM3DPROC glad_glProgramUniform3d = NULL; -PFNGLPROGRAMUNIFORM3DVPROC glad_glProgramUniform3dv = NULL; -PFNGLPROGRAMUNIFORM3FPROC glad_glProgramUniform3f = NULL; -PFNGLPROGRAMUNIFORM3FVPROC glad_glProgramUniform3fv = NULL; -PFNGLPROGRAMUNIFORM3IPROC glad_glProgramUniform3i = NULL; -PFNGLPROGRAMUNIFORM3IVPROC glad_glProgramUniform3iv = NULL; -PFNGLPROGRAMUNIFORM3UIPROC glad_glProgramUniform3ui = NULL; -PFNGLPROGRAMUNIFORM3UIVPROC glad_glProgramUniform3uiv = NULL; -PFNGLPROGRAMUNIFORM4DPROC glad_glProgramUniform4d = NULL; -PFNGLPROGRAMUNIFORM4DVPROC glad_glProgramUniform4dv = NULL; -PFNGLPROGRAMUNIFORM4FPROC glad_glProgramUniform4f = NULL; -PFNGLPROGRAMUNIFORM4FVPROC glad_glProgramUniform4fv = NULL; -PFNGLPROGRAMUNIFORM4IPROC glad_glProgramUniform4i = NULL; -PFNGLPROGRAMUNIFORM4IVPROC glad_glProgramUniform4iv = NULL; -PFNGLPROGRAMUNIFORM4UIPROC glad_glProgramUniform4ui = NULL; -PFNGLPROGRAMUNIFORM4UIVPROC glad_glProgramUniform4uiv = NULL; -PFNGLPROGRAMUNIFORMMATRIX2DVPROC glad_glProgramUniformMatrix2dv = NULL; -PFNGLPROGRAMUNIFORMMATRIX2FVPROC glad_glProgramUniformMatrix2fv = NULL; -PFNGLPROGRAMUNIFORMMATRIX2X3DVPROC glad_glProgramUniformMatrix2x3dv = NULL; -PFNGLPROGRAMUNIFORMMATRIX2X3FVPROC glad_glProgramUniformMatrix2x3fv = NULL; -PFNGLPROGRAMUNIFORMMATRIX2X4DVPROC glad_glProgramUniformMatrix2x4dv = NULL; -PFNGLPROGRAMUNIFORMMATRIX2X4FVPROC glad_glProgramUniformMatrix2x4fv = NULL; -PFNGLPROGRAMUNIFORMMATRIX3DVPROC glad_glProgramUniformMatrix3dv = NULL; -PFNGLPROGRAMUNIFORMMATRIX3FVPROC glad_glProgramUniformMatrix3fv = NULL; -PFNGLPROGRAMUNIFORMMATRIX3X2DVPROC glad_glProgramUniformMatrix3x2dv = NULL; -PFNGLPROGRAMUNIFORMMATRIX3X2FVPROC glad_glProgramUniformMatrix3x2fv = NULL; -PFNGLPROGRAMUNIFORMMATRIX3X4DVPROC glad_glProgramUniformMatrix3x4dv = NULL; -PFNGLPROGRAMUNIFORMMATRIX3X4FVPROC glad_glProgramUniformMatrix3x4fv = NULL; -PFNGLPROGRAMUNIFORMMATRIX4DVPROC glad_glProgramUniformMatrix4dv = NULL; -PFNGLPROGRAMUNIFORMMATRIX4FVPROC glad_glProgramUniformMatrix4fv = NULL; -PFNGLPROGRAMUNIFORMMATRIX4X2DVPROC glad_glProgramUniformMatrix4x2dv = NULL; -PFNGLPROGRAMUNIFORMMATRIX4X2FVPROC glad_glProgramUniformMatrix4x2fv = NULL; -PFNGLPROGRAMUNIFORMMATRIX4X3DVPROC glad_glProgramUniformMatrix4x3dv = NULL; -PFNGLPROGRAMUNIFORMMATRIX4X3FVPROC glad_glProgramUniformMatrix4x3fv = NULL; -PFNGLPROVOKINGVERTEXPROC glad_glProvokingVertex = NULL; -PFNGLPUSHATTRIBPROC glad_glPushAttrib = NULL; -PFNGLPUSHCLIENTATTRIBPROC glad_glPushClientAttrib = NULL; -PFNGLPUSHMATRIXPROC glad_glPushMatrix = NULL; -PFNGLPUSHNAMEPROC glad_glPushName = NULL; -PFNGLQUERYCOUNTERPROC glad_glQueryCounter = NULL; -PFNGLRASTERPOS2DPROC glad_glRasterPos2d = NULL; -PFNGLRASTERPOS2DVPROC glad_glRasterPos2dv = NULL; -PFNGLRASTERPOS2FPROC glad_glRasterPos2f = NULL; -PFNGLRASTERPOS2FVPROC glad_glRasterPos2fv = NULL; -PFNGLRASTERPOS2IPROC glad_glRasterPos2i = NULL; -PFNGLRASTERPOS2IVPROC glad_glRasterPos2iv = NULL; -PFNGLRASTERPOS2SPROC glad_glRasterPos2s = NULL; -PFNGLRASTERPOS2SVPROC glad_glRasterPos2sv = NULL; -PFNGLRASTERPOS3DPROC glad_glRasterPos3d = NULL; -PFNGLRASTERPOS3DVPROC glad_glRasterPos3dv = NULL; -PFNGLRASTERPOS3FPROC glad_glRasterPos3f = NULL; -PFNGLRASTERPOS3FVPROC glad_glRasterPos3fv = NULL; -PFNGLRASTERPOS3IPROC glad_glRasterPos3i = NULL; -PFNGLRASTERPOS3IVPROC glad_glRasterPos3iv = NULL; -PFNGLRASTERPOS3SPROC glad_glRasterPos3s = NULL; -PFNGLRASTERPOS3SVPROC glad_glRasterPos3sv = NULL; -PFNGLRASTERPOS4DPROC glad_glRasterPos4d = NULL; -PFNGLRASTERPOS4DVPROC glad_glRasterPos4dv = NULL; -PFNGLRASTERPOS4FPROC glad_glRasterPos4f = NULL; -PFNGLRASTERPOS4FVPROC glad_glRasterPos4fv = NULL; -PFNGLRASTERPOS4IPROC glad_glRasterPos4i = NULL; -PFNGLRASTERPOS4IVPROC glad_glRasterPos4iv = NULL; -PFNGLRASTERPOS4SPROC glad_glRasterPos4s = NULL; -PFNGLRASTERPOS4SVPROC glad_glRasterPos4sv = NULL; -PFNGLREADBUFFERPROC glad_glReadBuffer = NULL; -PFNGLREADPIXELSPROC glad_glReadPixels = NULL; -PFNGLRECTDPROC glad_glRectd = NULL; -PFNGLRECTDVPROC glad_glRectdv = NULL; -PFNGLRECTFPROC glad_glRectf = NULL; -PFNGLRECTFVPROC glad_glRectfv = NULL; -PFNGLRECTIPROC glad_glRecti = NULL; -PFNGLRECTIVPROC glad_glRectiv = NULL; -PFNGLRECTSPROC glad_glRects = NULL; -PFNGLRECTSVPROC glad_glRectsv = NULL; -PFNGLRELEASESHADERCOMPILERPROC glad_glReleaseShaderCompiler = NULL; -PFNGLRENDERMODEPROC glad_glRenderMode = NULL; -PFNGLRENDERBUFFERSTORAGEPROC glad_glRenderbufferStorage = NULL; -PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC glad_glRenderbufferStorageMultisample = NULL; -PFNGLRESUMETRANSFORMFEEDBACKPROC glad_glResumeTransformFeedback = NULL; -PFNGLROTATEDPROC glad_glRotated = NULL; -PFNGLROTATEFPROC glad_glRotatef = NULL; -PFNGLSAMPLECOVERAGEPROC glad_glSampleCoverage = NULL; -PFNGLSAMPLEMASKIPROC glad_glSampleMaski = NULL; -PFNGLSAMPLERPARAMETERIIVPROC glad_glSamplerParameterIiv = NULL; -PFNGLSAMPLERPARAMETERIUIVPROC glad_glSamplerParameterIuiv = NULL; -PFNGLSAMPLERPARAMETERFPROC glad_glSamplerParameterf = NULL; -PFNGLSAMPLERPARAMETERFVPROC glad_glSamplerParameterfv = NULL; -PFNGLSAMPLERPARAMETERIPROC glad_glSamplerParameteri = NULL; -PFNGLSAMPLERPARAMETERIVPROC glad_glSamplerParameteriv = NULL; -PFNGLSCALEDPROC glad_glScaled = NULL; -PFNGLSCALEFPROC glad_glScalef = NULL; -PFNGLSCISSORPROC glad_glScissor = NULL; -PFNGLSCISSORARRAYVPROC glad_glScissorArrayv = NULL; -PFNGLSCISSORINDEXEDPROC glad_glScissorIndexed = NULL; -PFNGLSCISSORINDEXEDVPROC glad_glScissorIndexedv = NULL; -PFNGLSECONDARYCOLOR3BPROC glad_glSecondaryColor3b = NULL; -PFNGLSECONDARYCOLOR3BVPROC glad_glSecondaryColor3bv = NULL; -PFNGLSECONDARYCOLOR3DPROC glad_glSecondaryColor3d = NULL; -PFNGLSECONDARYCOLOR3DVPROC glad_glSecondaryColor3dv = NULL; -PFNGLSECONDARYCOLOR3FPROC glad_glSecondaryColor3f = NULL; -PFNGLSECONDARYCOLOR3FVPROC glad_glSecondaryColor3fv = NULL; -PFNGLSECONDARYCOLOR3IPROC glad_glSecondaryColor3i = NULL; -PFNGLSECONDARYCOLOR3IVPROC glad_glSecondaryColor3iv = NULL; -PFNGLSECONDARYCOLOR3SPROC glad_glSecondaryColor3s = NULL; -PFNGLSECONDARYCOLOR3SVPROC glad_glSecondaryColor3sv = NULL; -PFNGLSECONDARYCOLOR3UBPROC glad_glSecondaryColor3ub = NULL; -PFNGLSECONDARYCOLOR3UBVPROC glad_glSecondaryColor3ubv = NULL; -PFNGLSECONDARYCOLOR3UIPROC glad_glSecondaryColor3ui = NULL; -PFNGLSECONDARYCOLOR3UIVPROC glad_glSecondaryColor3uiv = NULL; -PFNGLSECONDARYCOLOR3USPROC glad_glSecondaryColor3us = NULL; -PFNGLSECONDARYCOLOR3USVPROC glad_glSecondaryColor3usv = NULL; -PFNGLSECONDARYCOLORP3UIPROC glad_glSecondaryColorP3ui = NULL; -PFNGLSECONDARYCOLORP3UIVPROC glad_glSecondaryColorP3uiv = NULL; -PFNGLSECONDARYCOLORPOINTERPROC glad_glSecondaryColorPointer = NULL; -PFNGLSELECTBUFFERPROC glad_glSelectBuffer = NULL; -PFNGLSHADEMODELPROC glad_glShadeModel = NULL; -PFNGLSHADERBINARYPROC glad_glShaderBinary = NULL; -PFNGLSHADERSOURCEPROC glad_glShaderSource = NULL; -PFNGLSTENCILFUNCPROC glad_glStencilFunc = NULL; -PFNGLSTENCILFUNCSEPARATEPROC glad_glStencilFuncSeparate = NULL; -PFNGLSTENCILMASKPROC glad_glStencilMask = NULL; -PFNGLSTENCILMASKSEPARATEPROC glad_glStencilMaskSeparate = NULL; -PFNGLSTENCILOPPROC glad_glStencilOp = NULL; -PFNGLSTENCILOPSEPARATEPROC glad_glStencilOpSeparate = NULL; -PFNGLTEXBUFFERPROC glad_glTexBuffer = NULL; -PFNGLTEXCOORD1DPROC glad_glTexCoord1d = NULL; -PFNGLTEXCOORD1DVPROC glad_glTexCoord1dv = NULL; -PFNGLTEXCOORD1FPROC glad_glTexCoord1f = NULL; -PFNGLTEXCOORD1FVPROC glad_glTexCoord1fv = NULL; -PFNGLTEXCOORD1IPROC glad_glTexCoord1i = NULL; -PFNGLTEXCOORD1IVPROC glad_glTexCoord1iv = NULL; -PFNGLTEXCOORD1SPROC glad_glTexCoord1s = NULL; -PFNGLTEXCOORD1SVPROC glad_glTexCoord1sv = NULL; -PFNGLTEXCOORD2DPROC glad_glTexCoord2d = NULL; -PFNGLTEXCOORD2DVPROC glad_glTexCoord2dv = NULL; -PFNGLTEXCOORD2FPROC glad_glTexCoord2f = NULL; -PFNGLTEXCOORD2FVPROC glad_glTexCoord2fv = NULL; -PFNGLTEXCOORD2IPROC glad_glTexCoord2i = NULL; -PFNGLTEXCOORD2IVPROC glad_glTexCoord2iv = NULL; -PFNGLTEXCOORD2SPROC glad_glTexCoord2s = NULL; -PFNGLTEXCOORD2SVPROC glad_glTexCoord2sv = NULL; -PFNGLTEXCOORD3DPROC glad_glTexCoord3d = NULL; -PFNGLTEXCOORD3DVPROC glad_glTexCoord3dv = NULL; -PFNGLTEXCOORD3FPROC glad_glTexCoord3f = NULL; -PFNGLTEXCOORD3FVPROC glad_glTexCoord3fv = NULL; -PFNGLTEXCOORD3IPROC glad_glTexCoord3i = NULL; -PFNGLTEXCOORD3IVPROC glad_glTexCoord3iv = NULL; -PFNGLTEXCOORD3SPROC glad_glTexCoord3s = NULL; -PFNGLTEXCOORD3SVPROC glad_glTexCoord3sv = NULL; -PFNGLTEXCOORD4DPROC glad_glTexCoord4d = NULL; -PFNGLTEXCOORD4DVPROC glad_glTexCoord4dv = NULL; -PFNGLTEXCOORD4FPROC glad_glTexCoord4f = NULL; -PFNGLTEXCOORD4FVPROC glad_glTexCoord4fv = NULL; -PFNGLTEXCOORD4IPROC glad_glTexCoord4i = NULL; -PFNGLTEXCOORD4IVPROC glad_glTexCoord4iv = NULL; -PFNGLTEXCOORD4SPROC glad_glTexCoord4s = NULL; -PFNGLTEXCOORD4SVPROC glad_glTexCoord4sv = NULL; -PFNGLTEXCOORDP1UIPROC glad_glTexCoordP1ui = NULL; -PFNGLTEXCOORDP1UIVPROC glad_glTexCoordP1uiv = NULL; -PFNGLTEXCOORDP2UIPROC glad_glTexCoordP2ui = NULL; -PFNGLTEXCOORDP2UIVPROC glad_glTexCoordP2uiv = NULL; -PFNGLTEXCOORDP3UIPROC glad_glTexCoordP3ui = NULL; -PFNGLTEXCOORDP3UIVPROC glad_glTexCoordP3uiv = NULL; -PFNGLTEXCOORDP4UIPROC glad_glTexCoordP4ui = NULL; -PFNGLTEXCOORDP4UIVPROC glad_glTexCoordP4uiv = NULL; -PFNGLTEXCOORDPOINTERPROC glad_glTexCoordPointer = NULL; -PFNGLTEXENVFPROC glad_glTexEnvf = NULL; -PFNGLTEXENVFVPROC glad_glTexEnvfv = NULL; -PFNGLTEXENVIPROC glad_glTexEnvi = NULL; -PFNGLTEXENVIVPROC glad_glTexEnviv = NULL; -PFNGLTEXGENDPROC glad_glTexGend = NULL; -PFNGLTEXGENDVPROC glad_glTexGendv = NULL; -PFNGLTEXGENFPROC glad_glTexGenf = NULL; -PFNGLTEXGENFVPROC glad_glTexGenfv = NULL; -PFNGLTEXGENIPROC glad_glTexGeni = NULL; -PFNGLTEXGENIVPROC glad_glTexGeniv = NULL; -PFNGLTEXIMAGE1DPROC glad_glTexImage1D = NULL; -PFNGLTEXIMAGE2DPROC glad_glTexImage2D = NULL; -PFNGLTEXIMAGE2DMULTISAMPLEPROC glad_glTexImage2DMultisample = NULL; -PFNGLTEXIMAGE3DPROC glad_glTexImage3D = NULL; -PFNGLTEXIMAGE3DMULTISAMPLEPROC glad_glTexImage3DMultisample = NULL; -PFNGLTEXPARAMETERIIVPROC glad_glTexParameterIiv = NULL; -PFNGLTEXPARAMETERIUIVPROC glad_glTexParameterIuiv = NULL; -PFNGLTEXPARAMETERFPROC glad_glTexParameterf = NULL; -PFNGLTEXPARAMETERFVPROC glad_glTexParameterfv = NULL; -PFNGLTEXPARAMETERIPROC glad_glTexParameteri = NULL; -PFNGLTEXPARAMETERIVPROC glad_glTexParameteriv = NULL; -PFNGLTEXSUBIMAGE1DPROC glad_glTexSubImage1D = NULL; -PFNGLTEXSUBIMAGE2DPROC glad_glTexSubImage2D = NULL; -PFNGLTEXSUBIMAGE3DPROC glad_glTexSubImage3D = NULL; -PFNGLTRANSFORMFEEDBACKVARYINGSPROC glad_glTransformFeedbackVaryings = NULL; -PFNGLTRANSLATEDPROC glad_glTranslated = NULL; -PFNGLTRANSLATEFPROC glad_glTranslatef = NULL; -PFNGLUNIFORM1DPROC glad_glUniform1d = NULL; -PFNGLUNIFORM1DVPROC glad_glUniform1dv = NULL; -PFNGLUNIFORM1FPROC glad_glUniform1f = NULL; -PFNGLUNIFORM1FVPROC glad_glUniform1fv = NULL; -PFNGLUNIFORM1IPROC glad_glUniform1i = NULL; -PFNGLUNIFORM1IVPROC glad_glUniform1iv = NULL; -PFNGLUNIFORM1UIPROC glad_glUniform1ui = NULL; -PFNGLUNIFORM1UIVPROC glad_glUniform1uiv = NULL; -PFNGLUNIFORM2DPROC glad_glUniform2d = NULL; -PFNGLUNIFORM2DVPROC glad_glUniform2dv = NULL; -PFNGLUNIFORM2FPROC glad_glUniform2f = NULL; -PFNGLUNIFORM2FVPROC glad_glUniform2fv = NULL; -PFNGLUNIFORM2IPROC glad_glUniform2i = NULL; -PFNGLUNIFORM2IVPROC glad_glUniform2iv = NULL; -PFNGLUNIFORM2UIPROC glad_glUniform2ui = NULL; -PFNGLUNIFORM2UIVPROC glad_glUniform2uiv = NULL; -PFNGLUNIFORM3DPROC glad_glUniform3d = NULL; -PFNGLUNIFORM3DVPROC glad_glUniform3dv = NULL; -PFNGLUNIFORM3FPROC glad_glUniform3f = NULL; -PFNGLUNIFORM3FVPROC glad_glUniform3fv = NULL; -PFNGLUNIFORM3IPROC glad_glUniform3i = NULL; -PFNGLUNIFORM3IVPROC glad_glUniform3iv = NULL; -PFNGLUNIFORM3UIPROC glad_glUniform3ui = NULL; -PFNGLUNIFORM3UIVPROC glad_glUniform3uiv = NULL; -PFNGLUNIFORM4DPROC glad_glUniform4d = NULL; -PFNGLUNIFORM4DVPROC glad_glUniform4dv = NULL; -PFNGLUNIFORM4FPROC glad_glUniform4f = NULL; -PFNGLUNIFORM4FVPROC glad_glUniform4fv = NULL; -PFNGLUNIFORM4IPROC glad_glUniform4i = NULL; -PFNGLUNIFORM4IVPROC glad_glUniform4iv = NULL; -PFNGLUNIFORM4UIPROC glad_glUniform4ui = NULL; -PFNGLUNIFORM4UIVPROC glad_glUniform4uiv = NULL; -PFNGLUNIFORMBLOCKBINDINGPROC glad_glUniformBlockBinding = NULL; -PFNGLUNIFORMMATRIX2DVPROC glad_glUniformMatrix2dv = NULL; -PFNGLUNIFORMMATRIX2FVPROC glad_glUniformMatrix2fv = NULL; -PFNGLUNIFORMMATRIX2X3DVPROC glad_glUniformMatrix2x3dv = NULL; -PFNGLUNIFORMMATRIX2X3FVPROC glad_glUniformMatrix2x3fv = NULL; -PFNGLUNIFORMMATRIX2X4DVPROC glad_glUniformMatrix2x4dv = NULL; -PFNGLUNIFORMMATRIX2X4FVPROC glad_glUniformMatrix2x4fv = NULL; -PFNGLUNIFORMMATRIX3DVPROC glad_glUniformMatrix3dv = NULL; -PFNGLUNIFORMMATRIX3FVPROC glad_glUniformMatrix3fv = NULL; -PFNGLUNIFORMMATRIX3X2DVPROC glad_glUniformMatrix3x2dv = NULL; -PFNGLUNIFORMMATRIX3X2FVPROC glad_glUniformMatrix3x2fv = NULL; -PFNGLUNIFORMMATRIX3X4DVPROC glad_glUniformMatrix3x4dv = NULL; -PFNGLUNIFORMMATRIX3X4FVPROC glad_glUniformMatrix3x4fv = NULL; -PFNGLUNIFORMMATRIX4DVPROC glad_glUniformMatrix4dv = NULL; -PFNGLUNIFORMMATRIX4FVPROC glad_glUniformMatrix4fv = NULL; -PFNGLUNIFORMMATRIX4X2DVPROC glad_glUniformMatrix4x2dv = NULL; -PFNGLUNIFORMMATRIX4X2FVPROC glad_glUniformMatrix4x2fv = NULL; -PFNGLUNIFORMMATRIX4X3DVPROC glad_glUniformMatrix4x3dv = NULL; -PFNGLUNIFORMMATRIX4X3FVPROC glad_glUniformMatrix4x3fv = NULL; -PFNGLUNIFORMSUBROUTINESUIVPROC glad_glUniformSubroutinesuiv = NULL; -PFNGLUNMAPBUFFERPROC glad_glUnmapBuffer = NULL; -PFNGLUSEPROGRAMPROC glad_glUseProgram = NULL; -PFNGLUSEPROGRAMSTAGESPROC glad_glUseProgramStages = NULL; -PFNGLVALIDATEPROGRAMPROC glad_glValidateProgram = NULL; -PFNGLVALIDATEPROGRAMPIPELINEPROC glad_glValidateProgramPipeline = NULL; -PFNGLVERTEX2DPROC glad_glVertex2d = NULL; -PFNGLVERTEX2DVPROC glad_glVertex2dv = NULL; -PFNGLVERTEX2FPROC glad_glVertex2f = NULL; -PFNGLVERTEX2FVPROC glad_glVertex2fv = NULL; -PFNGLVERTEX2IPROC glad_glVertex2i = NULL; -PFNGLVERTEX2IVPROC glad_glVertex2iv = NULL; -PFNGLVERTEX2SPROC glad_glVertex2s = NULL; -PFNGLVERTEX2SVPROC glad_glVertex2sv = NULL; -PFNGLVERTEX3DPROC glad_glVertex3d = NULL; -PFNGLVERTEX3DVPROC glad_glVertex3dv = NULL; -PFNGLVERTEX3FPROC glad_glVertex3f = NULL; -PFNGLVERTEX3FVPROC glad_glVertex3fv = NULL; -PFNGLVERTEX3IPROC glad_glVertex3i = NULL; -PFNGLVERTEX3IVPROC glad_glVertex3iv = NULL; -PFNGLVERTEX3SPROC glad_glVertex3s = NULL; -PFNGLVERTEX3SVPROC glad_glVertex3sv = NULL; -PFNGLVERTEX4DPROC glad_glVertex4d = NULL; -PFNGLVERTEX4DVPROC glad_glVertex4dv = NULL; -PFNGLVERTEX4FPROC glad_glVertex4f = NULL; -PFNGLVERTEX4FVPROC glad_glVertex4fv = NULL; -PFNGLVERTEX4IPROC glad_glVertex4i = NULL; -PFNGLVERTEX4IVPROC glad_glVertex4iv = NULL; -PFNGLVERTEX4SPROC glad_glVertex4s = NULL; -PFNGLVERTEX4SVPROC glad_glVertex4sv = NULL; -PFNGLVERTEXATTRIB1DPROC glad_glVertexAttrib1d = NULL; -PFNGLVERTEXATTRIB1DVPROC glad_glVertexAttrib1dv = NULL; -PFNGLVERTEXATTRIB1FPROC glad_glVertexAttrib1f = NULL; -PFNGLVERTEXATTRIB1FVPROC glad_glVertexAttrib1fv = NULL; -PFNGLVERTEXATTRIB1SPROC glad_glVertexAttrib1s = NULL; -PFNGLVERTEXATTRIB1SVPROC glad_glVertexAttrib1sv = NULL; -PFNGLVERTEXATTRIB2DPROC glad_glVertexAttrib2d = NULL; -PFNGLVERTEXATTRIB2DVPROC glad_glVertexAttrib2dv = NULL; -PFNGLVERTEXATTRIB2FPROC glad_glVertexAttrib2f = NULL; -PFNGLVERTEXATTRIB2FVPROC glad_glVertexAttrib2fv = NULL; -PFNGLVERTEXATTRIB2SPROC glad_glVertexAttrib2s = NULL; -PFNGLVERTEXATTRIB2SVPROC glad_glVertexAttrib2sv = NULL; -PFNGLVERTEXATTRIB3DPROC glad_glVertexAttrib3d = NULL; -PFNGLVERTEXATTRIB3DVPROC glad_glVertexAttrib3dv = NULL; -PFNGLVERTEXATTRIB3FPROC glad_glVertexAttrib3f = NULL; -PFNGLVERTEXATTRIB3FVPROC glad_glVertexAttrib3fv = NULL; -PFNGLVERTEXATTRIB3SPROC glad_glVertexAttrib3s = NULL; -PFNGLVERTEXATTRIB3SVPROC glad_glVertexAttrib3sv = NULL; -PFNGLVERTEXATTRIB4NBVPROC glad_glVertexAttrib4Nbv = NULL; -PFNGLVERTEXATTRIB4NIVPROC glad_glVertexAttrib4Niv = NULL; -PFNGLVERTEXATTRIB4NSVPROC glad_glVertexAttrib4Nsv = NULL; -PFNGLVERTEXATTRIB4NUBPROC glad_glVertexAttrib4Nub = NULL; -PFNGLVERTEXATTRIB4NUBVPROC glad_glVertexAttrib4Nubv = NULL; -PFNGLVERTEXATTRIB4NUIVPROC glad_glVertexAttrib4Nuiv = NULL; -PFNGLVERTEXATTRIB4NUSVPROC glad_glVertexAttrib4Nusv = NULL; -PFNGLVERTEXATTRIB4BVPROC glad_glVertexAttrib4bv = NULL; -PFNGLVERTEXATTRIB4DPROC glad_glVertexAttrib4d = NULL; -PFNGLVERTEXATTRIB4DVPROC glad_glVertexAttrib4dv = NULL; -PFNGLVERTEXATTRIB4FPROC glad_glVertexAttrib4f = NULL; -PFNGLVERTEXATTRIB4FVPROC glad_glVertexAttrib4fv = NULL; -PFNGLVERTEXATTRIB4IVPROC glad_glVertexAttrib4iv = NULL; -PFNGLVERTEXATTRIB4SPROC glad_glVertexAttrib4s = NULL; -PFNGLVERTEXATTRIB4SVPROC glad_glVertexAttrib4sv = NULL; -PFNGLVERTEXATTRIB4UBVPROC glad_glVertexAttrib4ubv = NULL; -PFNGLVERTEXATTRIB4UIVPROC glad_glVertexAttrib4uiv = NULL; -PFNGLVERTEXATTRIB4USVPROC glad_glVertexAttrib4usv = NULL; -PFNGLVERTEXATTRIBDIVISORPROC glad_glVertexAttribDivisor = NULL; -PFNGLVERTEXATTRIBI1IPROC glad_glVertexAttribI1i = NULL; -PFNGLVERTEXATTRIBI1IVPROC glad_glVertexAttribI1iv = NULL; -PFNGLVERTEXATTRIBI1UIPROC glad_glVertexAttribI1ui = NULL; -PFNGLVERTEXATTRIBI1UIVPROC glad_glVertexAttribI1uiv = NULL; -PFNGLVERTEXATTRIBI2IPROC glad_glVertexAttribI2i = NULL; -PFNGLVERTEXATTRIBI2IVPROC glad_glVertexAttribI2iv = NULL; -PFNGLVERTEXATTRIBI2UIPROC glad_glVertexAttribI2ui = NULL; -PFNGLVERTEXATTRIBI2UIVPROC glad_glVertexAttribI2uiv = NULL; -PFNGLVERTEXATTRIBI3IPROC glad_glVertexAttribI3i = NULL; -PFNGLVERTEXATTRIBI3IVPROC glad_glVertexAttribI3iv = NULL; -PFNGLVERTEXATTRIBI3UIPROC glad_glVertexAttribI3ui = NULL; -PFNGLVERTEXATTRIBI3UIVPROC glad_glVertexAttribI3uiv = NULL; -PFNGLVERTEXATTRIBI4BVPROC glad_glVertexAttribI4bv = NULL; -PFNGLVERTEXATTRIBI4IPROC glad_glVertexAttribI4i = NULL; -PFNGLVERTEXATTRIBI4IVPROC glad_glVertexAttribI4iv = NULL; -PFNGLVERTEXATTRIBI4SVPROC glad_glVertexAttribI4sv = NULL; -PFNGLVERTEXATTRIBI4UBVPROC glad_glVertexAttribI4ubv = NULL; -PFNGLVERTEXATTRIBI4UIPROC glad_glVertexAttribI4ui = NULL; -PFNGLVERTEXATTRIBI4UIVPROC glad_glVertexAttribI4uiv = NULL; -PFNGLVERTEXATTRIBI4USVPROC glad_glVertexAttribI4usv = NULL; -PFNGLVERTEXATTRIBIPOINTERPROC glad_glVertexAttribIPointer = NULL; -PFNGLVERTEXATTRIBL1DPROC glad_glVertexAttribL1d = NULL; -PFNGLVERTEXATTRIBL1DVPROC glad_glVertexAttribL1dv = NULL; -PFNGLVERTEXATTRIBL2DPROC glad_glVertexAttribL2d = NULL; -PFNGLVERTEXATTRIBL2DVPROC glad_glVertexAttribL2dv = NULL; -PFNGLVERTEXATTRIBL3DPROC glad_glVertexAttribL3d = NULL; -PFNGLVERTEXATTRIBL3DVPROC glad_glVertexAttribL3dv = NULL; -PFNGLVERTEXATTRIBL4DPROC glad_glVertexAttribL4d = NULL; -PFNGLVERTEXATTRIBL4DVPROC glad_glVertexAttribL4dv = NULL; -PFNGLVERTEXATTRIBLPOINTERPROC glad_glVertexAttribLPointer = NULL; -PFNGLVERTEXATTRIBP1UIPROC glad_glVertexAttribP1ui = NULL; -PFNGLVERTEXATTRIBP1UIVPROC glad_glVertexAttribP1uiv = NULL; -PFNGLVERTEXATTRIBP2UIPROC glad_glVertexAttribP2ui = NULL; -PFNGLVERTEXATTRIBP2UIVPROC glad_glVertexAttribP2uiv = NULL; -PFNGLVERTEXATTRIBP3UIPROC glad_glVertexAttribP3ui = NULL; -PFNGLVERTEXATTRIBP3UIVPROC glad_glVertexAttribP3uiv = NULL; -PFNGLVERTEXATTRIBP4UIPROC glad_glVertexAttribP4ui = NULL; -PFNGLVERTEXATTRIBP4UIVPROC glad_glVertexAttribP4uiv = NULL; -PFNGLVERTEXATTRIBPOINTERPROC glad_glVertexAttribPointer = NULL; -PFNGLVERTEXP2UIPROC glad_glVertexP2ui = NULL; -PFNGLVERTEXP2UIVPROC glad_glVertexP2uiv = NULL; -PFNGLVERTEXP3UIPROC glad_glVertexP3ui = NULL; -PFNGLVERTEXP3UIVPROC glad_glVertexP3uiv = NULL; -PFNGLVERTEXP4UIPROC glad_glVertexP4ui = NULL; -PFNGLVERTEXP4UIVPROC glad_glVertexP4uiv = NULL; -PFNGLVERTEXPOINTERPROC glad_glVertexPointer = NULL; -PFNGLVIEWPORTPROC glad_glViewport = NULL; -PFNGLVIEWPORTARRAYVPROC glad_glViewportArrayv = NULL; -PFNGLVIEWPORTINDEXEDFPROC glad_glViewportIndexedf = NULL; -PFNGLVIEWPORTINDEXEDFVPROC glad_glViewportIndexedfv = NULL; -PFNGLWAITSYNCPROC glad_glWaitSync = NULL; -PFNGLWINDOWPOS2DPROC glad_glWindowPos2d = NULL; -PFNGLWINDOWPOS2DVPROC glad_glWindowPos2dv = NULL; -PFNGLWINDOWPOS2FPROC glad_glWindowPos2f = NULL; -PFNGLWINDOWPOS2FVPROC glad_glWindowPos2fv = NULL; -PFNGLWINDOWPOS2IPROC glad_glWindowPos2i = NULL; -PFNGLWINDOWPOS2IVPROC glad_glWindowPos2iv = NULL; -PFNGLWINDOWPOS2SPROC glad_glWindowPos2s = NULL; -PFNGLWINDOWPOS2SVPROC glad_glWindowPos2sv = NULL; -PFNGLWINDOWPOS3DPROC glad_glWindowPos3d = NULL; -PFNGLWINDOWPOS3DVPROC glad_glWindowPos3dv = NULL; -PFNGLWINDOWPOS3FPROC glad_glWindowPos3f = NULL; -PFNGLWINDOWPOS3FVPROC glad_glWindowPos3fv = NULL; -PFNGLWINDOWPOS3IPROC glad_glWindowPos3i = NULL; -PFNGLWINDOWPOS3IVPROC glad_glWindowPos3iv = NULL; -PFNGLWINDOWPOS3SPROC glad_glWindowPos3s = NULL; -PFNGLWINDOWPOS3SVPROC glad_glWindowPos3sv = NULL; -static void load_GL_VERSION_1_0(GLADloadproc load) { - if(!GLAD_GL_VERSION_1_0) return; - glad_glCullFace = (PFNGLCULLFACEPROC)load("glCullFace"); - glad_glFrontFace = (PFNGLFRONTFACEPROC)load("glFrontFace"); - glad_glHint = (PFNGLHINTPROC)load("glHint"); - glad_glLineWidth = (PFNGLLINEWIDTHPROC)load("glLineWidth"); - glad_glPointSize = (PFNGLPOINTSIZEPROC)load("glPointSize"); - glad_glPolygonMode = (PFNGLPOLYGONMODEPROC)load("glPolygonMode"); - glad_glScissor = (PFNGLSCISSORPROC)load("glScissor"); - glad_glTexParameterf = (PFNGLTEXPARAMETERFPROC)load("glTexParameterf"); - glad_glTexParameterfv = (PFNGLTEXPARAMETERFVPROC)load("glTexParameterfv"); - glad_glTexParameteri = (PFNGLTEXPARAMETERIPROC)load("glTexParameteri"); - glad_glTexParameteriv = (PFNGLTEXPARAMETERIVPROC)load("glTexParameteriv"); - glad_glTexImage1D = (PFNGLTEXIMAGE1DPROC)load("glTexImage1D"); - glad_glTexImage2D = (PFNGLTEXIMAGE2DPROC)load("glTexImage2D"); - glad_glDrawBuffer = (PFNGLDRAWBUFFERPROC)load("glDrawBuffer"); - glad_glClear = (PFNGLCLEARPROC)load("glClear"); - glad_glClearColor = (PFNGLCLEARCOLORPROC)load("glClearColor"); - glad_glClearStencil = (PFNGLCLEARSTENCILPROC)load("glClearStencil"); - glad_glClearDepth = (PFNGLCLEARDEPTHPROC)load("glClearDepth"); - glad_glStencilMask = (PFNGLSTENCILMASKPROC)load("glStencilMask"); - glad_glColorMask = (PFNGLCOLORMASKPROC)load("glColorMask"); - glad_glDepthMask = (PFNGLDEPTHMASKPROC)load("glDepthMask"); - glad_glDisable = (PFNGLDISABLEPROC)load("glDisable"); - glad_glEnable = (PFNGLENABLEPROC)load("glEnable"); - glad_glFinish = (PFNGLFINISHPROC)load("glFinish"); - glad_glFlush = (PFNGLFLUSHPROC)load("glFlush"); - glad_glBlendFunc = (PFNGLBLENDFUNCPROC)load("glBlendFunc"); - glad_glLogicOp = (PFNGLLOGICOPPROC)load("glLogicOp"); - glad_glStencilFunc = (PFNGLSTENCILFUNCPROC)load("glStencilFunc"); - glad_glStencilOp = (PFNGLSTENCILOPPROC)load("glStencilOp"); - glad_glDepthFunc = (PFNGLDEPTHFUNCPROC)load("glDepthFunc"); - glad_glPixelStoref = (PFNGLPIXELSTOREFPROC)load("glPixelStoref"); - glad_glPixelStorei = (PFNGLPIXELSTOREIPROC)load("glPixelStorei"); - glad_glReadBuffer = (PFNGLREADBUFFERPROC)load("glReadBuffer"); - glad_glReadPixels = (PFNGLREADPIXELSPROC)load("glReadPixels"); - glad_glGetBooleanv = (PFNGLGETBOOLEANVPROC)load("glGetBooleanv"); - glad_glGetDoublev = (PFNGLGETDOUBLEVPROC)load("glGetDoublev"); - glad_glGetError = (PFNGLGETERRORPROC)load("glGetError"); - glad_glGetFloatv = (PFNGLGETFLOATVPROC)load("glGetFloatv"); - glad_glGetIntegerv = (PFNGLGETINTEGERVPROC)load("glGetIntegerv"); - glad_glGetString = (PFNGLGETSTRINGPROC)load("glGetString"); - glad_glGetTexImage = (PFNGLGETTEXIMAGEPROC)load("glGetTexImage"); - glad_glGetTexParameterfv = (PFNGLGETTEXPARAMETERFVPROC)load("glGetTexParameterfv"); - glad_glGetTexParameteriv = (PFNGLGETTEXPARAMETERIVPROC)load("glGetTexParameteriv"); - glad_glGetTexLevelParameterfv = (PFNGLGETTEXLEVELPARAMETERFVPROC)load("glGetTexLevelParameterfv"); - glad_glGetTexLevelParameteriv = (PFNGLGETTEXLEVELPARAMETERIVPROC)load("glGetTexLevelParameteriv"); - glad_glIsEnabled = (PFNGLISENABLEDPROC)load("glIsEnabled"); - glad_glDepthRange = (PFNGLDEPTHRANGEPROC)load("glDepthRange"); - glad_glViewport = (PFNGLVIEWPORTPROC)load("glViewport"); - glad_glNewList = (PFNGLNEWLISTPROC)load("glNewList"); - glad_glEndList = (PFNGLENDLISTPROC)load("glEndList"); - glad_glCallList = (PFNGLCALLLISTPROC)load("glCallList"); - glad_glCallLists = (PFNGLCALLLISTSPROC)load("glCallLists"); - glad_glDeleteLists = (PFNGLDELETELISTSPROC)load("glDeleteLists"); - glad_glGenLists = (PFNGLGENLISTSPROC)load("glGenLists"); - glad_glListBase = (PFNGLLISTBASEPROC)load("glListBase"); - glad_glBegin = (PFNGLBEGINPROC)load("glBegin"); - glad_glBitmap = (PFNGLBITMAPPROC)load("glBitmap"); - glad_glColor3b = (PFNGLCOLOR3BPROC)load("glColor3b"); - glad_glColor3bv = (PFNGLCOLOR3BVPROC)load("glColor3bv"); - glad_glColor3d = (PFNGLCOLOR3DPROC)load("glColor3d"); - glad_glColor3dv = (PFNGLCOLOR3DVPROC)load("glColor3dv"); - glad_glColor3f = (PFNGLCOLOR3FPROC)load("glColor3f"); - glad_glColor3fv = (PFNGLCOLOR3FVPROC)load("glColor3fv"); - glad_glColor3i = (PFNGLCOLOR3IPROC)load("glColor3i"); - glad_glColor3iv = (PFNGLCOLOR3IVPROC)load("glColor3iv"); - glad_glColor3s = (PFNGLCOLOR3SPROC)load("glColor3s"); - glad_glColor3sv = (PFNGLCOLOR3SVPROC)load("glColor3sv"); - glad_glColor3ub = (PFNGLCOLOR3UBPROC)load("glColor3ub"); - glad_glColor3ubv = (PFNGLCOLOR3UBVPROC)load("glColor3ubv"); - glad_glColor3ui = (PFNGLCOLOR3UIPROC)load("glColor3ui"); - glad_glColor3uiv = (PFNGLCOLOR3UIVPROC)load("glColor3uiv"); - glad_glColor3us = (PFNGLCOLOR3USPROC)load("glColor3us"); - glad_glColor3usv = (PFNGLCOLOR3USVPROC)load("glColor3usv"); - glad_glColor4b = (PFNGLCOLOR4BPROC)load("glColor4b"); - glad_glColor4bv = (PFNGLCOLOR4BVPROC)load("glColor4bv"); - glad_glColor4d = (PFNGLCOLOR4DPROC)load("glColor4d"); - glad_glColor4dv = (PFNGLCOLOR4DVPROC)load("glColor4dv"); - glad_glColor4f = (PFNGLCOLOR4FPROC)load("glColor4f"); - glad_glColor4fv = (PFNGLCOLOR4FVPROC)load("glColor4fv"); - glad_glColor4i = (PFNGLCOLOR4IPROC)load("glColor4i"); - glad_glColor4iv = (PFNGLCOLOR4IVPROC)load("glColor4iv"); - glad_glColor4s = (PFNGLCOLOR4SPROC)load("glColor4s"); - glad_glColor4sv = (PFNGLCOLOR4SVPROC)load("glColor4sv"); - glad_glColor4ub = (PFNGLCOLOR4UBPROC)load("glColor4ub"); - glad_glColor4ubv = (PFNGLCOLOR4UBVPROC)load("glColor4ubv"); - glad_glColor4ui = (PFNGLCOLOR4UIPROC)load("glColor4ui"); - glad_glColor4uiv = (PFNGLCOLOR4UIVPROC)load("glColor4uiv"); - glad_glColor4us = (PFNGLCOLOR4USPROC)load("glColor4us"); - glad_glColor4usv = (PFNGLCOLOR4USVPROC)load("glColor4usv"); - glad_glEdgeFlag = (PFNGLEDGEFLAGPROC)load("glEdgeFlag"); - glad_glEdgeFlagv = (PFNGLEDGEFLAGVPROC)load("glEdgeFlagv"); - glad_glEnd = (PFNGLENDPROC)load("glEnd"); - glad_glIndexd = (PFNGLINDEXDPROC)load("glIndexd"); - glad_glIndexdv = (PFNGLINDEXDVPROC)load("glIndexdv"); - glad_glIndexf = (PFNGLINDEXFPROC)load("glIndexf"); - glad_glIndexfv = (PFNGLINDEXFVPROC)load("glIndexfv"); - glad_glIndexi = (PFNGLINDEXIPROC)load("glIndexi"); - glad_glIndexiv = (PFNGLINDEXIVPROC)load("glIndexiv"); - glad_glIndexs = (PFNGLINDEXSPROC)load("glIndexs"); - glad_glIndexsv = (PFNGLINDEXSVPROC)load("glIndexsv"); - glad_glNormal3b = (PFNGLNORMAL3BPROC)load("glNormal3b"); - glad_glNormal3bv = (PFNGLNORMAL3BVPROC)load("glNormal3bv"); - glad_glNormal3d = (PFNGLNORMAL3DPROC)load("glNormal3d"); - glad_glNormal3dv = (PFNGLNORMAL3DVPROC)load("glNormal3dv"); - glad_glNormal3f = (PFNGLNORMAL3FPROC)load("glNormal3f"); - glad_glNormal3fv = (PFNGLNORMAL3FVPROC)load("glNormal3fv"); - glad_glNormal3i = (PFNGLNORMAL3IPROC)load("glNormal3i"); - glad_glNormal3iv = (PFNGLNORMAL3IVPROC)load("glNormal3iv"); - glad_glNormal3s = (PFNGLNORMAL3SPROC)load("glNormal3s"); - glad_glNormal3sv = (PFNGLNORMAL3SVPROC)load("glNormal3sv"); - glad_glRasterPos2d = (PFNGLRASTERPOS2DPROC)load("glRasterPos2d"); - glad_glRasterPos2dv = (PFNGLRASTERPOS2DVPROC)load("glRasterPos2dv"); - glad_glRasterPos2f = (PFNGLRASTERPOS2FPROC)load("glRasterPos2f"); - glad_glRasterPos2fv = (PFNGLRASTERPOS2FVPROC)load("glRasterPos2fv"); - glad_glRasterPos2i = (PFNGLRASTERPOS2IPROC)load("glRasterPos2i"); - glad_glRasterPos2iv = (PFNGLRASTERPOS2IVPROC)load("glRasterPos2iv"); - glad_glRasterPos2s = (PFNGLRASTERPOS2SPROC)load("glRasterPos2s"); - glad_glRasterPos2sv = (PFNGLRASTERPOS2SVPROC)load("glRasterPos2sv"); - glad_glRasterPos3d = (PFNGLRASTERPOS3DPROC)load("glRasterPos3d"); - glad_glRasterPos3dv = (PFNGLRASTERPOS3DVPROC)load("glRasterPos3dv"); - glad_glRasterPos3f = (PFNGLRASTERPOS3FPROC)load("glRasterPos3f"); - glad_glRasterPos3fv = (PFNGLRASTERPOS3FVPROC)load("glRasterPos3fv"); - glad_glRasterPos3i = (PFNGLRASTERPOS3IPROC)load("glRasterPos3i"); - glad_glRasterPos3iv = (PFNGLRASTERPOS3IVPROC)load("glRasterPos3iv"); - glad_glRasterPos3s = (PFNGLRASTERPOS3SPROC)load("glRasterPos3s"); - glad_glRasterPos3sv = (PFNGLRASTERPOS3SVPROC)load("glRasterPos3sv"); - glad_glRasterPos4d = (PFNGLRASTERPOS4DPROC)load("glRasterPos4d"); - glad_glRasterPos4dv = (PFNGLRASTERPOS4DVPROC)load("glRasterPos4dv"); - glad_glRasterPos4f = (PFNGLRASTERPOS4FPROC)load("glRasterPos4f"); - glad_glRasterPos4fv = (PFNGLRASTERPOS4FVPROC)load("glRasterPos4fv"); - glad_glRasterPos4i = (PFNGLRASTERPOS4IPROC)load("glRasterPos4i"); - glad_glRasterPos4iv = (PFNGLRASTERPOS4IVPROC)load("glRasterPos4iv"); - glad_glRasterPos4s = (PFNGLRASTERPOS4SPROC)load("glRasterPos4s"); - glad_glRasterPos4sv = (PFNGLRASTERPOS4SVPROC)load("glRasterPos4sv"); - glad_glRectd = (PFNGLRECTDPROC)load("glRectd"); - glad_glRectdv = (PFNGLRECTDVPROC)load("glRectdv"); - glad_glRectf = (PFNGLRECTFPROC)load("glRectf"); - glad_glRectfv = (PFNGLRECTFVPROC)load("glRectfv"); - glad_glRecti = (PFNGLRECTIPROC)load("glRecti"); - glad_glRectiv = (PFNGLRECTIVPROC)load("glRectiv"); - glad_glRects = (PFNGLRECTSPROC)load("glRects"); - glad_glRectsv = (PFNGLRECTSVPROC)load("glRectsv"); - glad_glTexCoord1d = (PFNGLTEXCOORD1DPROC)load("glTexCoord1d"); - glad_glTexCoord1dv = (PFNGLTEXCOORD1DVPROC)load("glTexCoord1dv"); - glad_glTexCoord1f = (PFNGLTEXCOORD1FPROC)load("glTexCoord1f"); - glad_glTexCoord1fv = (PFNGLTEXCOORD1FVPROC)load("glTexCoord1fv"); - glad_glTexCoord1i = (PFNGLTEXCOORD1IPROC)load("glTexCoord1i"); - glad_glTexCoord1iv = (PFNGLTEXCOORD1IVPROC)load("glTexCoord1iv"); - glad_glTexCoord1s = (PFNGLTEXCOORD1SPROC)load("glTexCoord1s"); - glad_glTexCoord1sv = (PFNGLTEXCOORD1SVPROC)load("glTexCoord1sv"); - glad_glTexCoord2d = (PFNGLTEXCOORD2DPROC)load("glTexCoord2d"); - glad_glTexCoord2dv = (PFNGLTEXCOORD2DVPROC)load("glTexCoord2dv"); - glad_glTexCoord2f = (PFNGLTEXCOORD2FPROC)load("glTexCoord2f"); - glad_glTexCoord2fv = (PFNGLTEXCOORD2FVPROC)load("glTexCoord2fv"); - glad_glTexCoord2i = (PFNGLTEXCOORD2IPROC)load("glTexCoord2i"); - glad_glTexCoord2iv = (PFNGLTEXCOORD2IVPROC)load("glTexCoord2iv"); - glad_glTexCoord2s = (PFNGLTEXCOORD2SPROC)load("glTexCoord2s"); - glad_glTexCoord2sv = (PFNGLTEXCOORD2SVPROC)load("glTexCoord2sv"); - glad_glTexCoord3d = (PFNGLTEXCOORD3DPROC)load("glTexCoord3d"); - glad_glTexCoord3dv = (PFNGLTEXCOORD3DVPROC)load("glTexCoord3dv"); - glad_glTexCoord3f = (PFNGLTEXCOORD3FPROC)load("glTexCoord3f"); - glad_glTexCoord3fv = (PFNGLTEXCOORD3FVPROC)load("glTexCoord3fv"); - glad_glTexCoord3i = (PFNGLTEXCOORD3IPROC)load("glTexCoord3i"); - glad_glTexCoord3iv = (PFNGLTEXCOORD3IVPROC)load("glTexCoord3iv"); - glad_glTexCoord3s = (PFNGLTEXCOORD3SPROC)load("glTexCoord3s"); - glad_glTexCoord3sv = (PFNGLTEXCOORD3SVPROC)load("glTexCoord3sv"); - glad_glTexCoord4d = (PFNGLTEXCOORD4DPROC)load("glTexCoord4d"); - glad_glTexCoord4dv = (PFNGLTEXCOORD4DVPROC)load("glTexCoord4dv"); - glad_glTexCoord4f = (PFNGLTEXCOORD4FPROC)load("glTexCoord4f"); - glad_glTexCoord4fv = (PFNGLTEXCOORD4FVPROC)load("glTexCoord4fv"); - glad_glTexCoord4i = (PFNGLTEXCOORD4IPROC)load("glTexCoord4i"); - glad_glTexCoord4iv = (PFNGLTEXCOORD4IVPROC)load("glTexCoord4iv"); - glad_glTexCoord4s = (PFNGLTEXCOORD4SPROC)load("glTexCoord4s"); - glad_glTexCoord4sv = (PFNGLTEXCOORD4SVPROC)load("glTexCoord4sv"); - glad_glVertex2d = (PFNGLVERTEX2DPROC)load("glVertex2d"); - glad_glVertex2dv = (PFNGLVERTEX2DVPROC)load("glVertex2dv"); - glad_glVertex2f = (PFNGLVERTEX2FPROC)load("glVertex2f"); - glad_glVertex2fv = (PFNGLVERTEX2FVPROC)load("glVertex2fv"); - glad_glVertex2i = (PFNGLVERTEX2IPROC)load("glVertex2i"); - glad_glVertex2iv = (PFNGLVERTEX2IVPROC)load("glVertex2iv"); - glad_glVertex2s = (PFNGLVERTEX2SPROC)load("glVertex2s"); - glad_glVertex2sv = (PFNGLVERTEX2SVPROC)load("glVertex2sv"); - glad_glVertex3d = (PFNGLVERTEX3DPROC)load("glVertex3d"); - glad_glVertex3dv = (PFNGLVERTEX3DVPROC)load("glVertex3dv"); - glad_glVertex3f = (PFNGLVERTEX3FPROC)load("glVertex3f"); - glad_glVertex3fv = (PFNGLVERTEX3FVPROC)load("glVertex3fv"); - glad_glVertex3i = (PFNGLVERTEX3IPROC)load("glVertex3i"); - glad_glVertex3iv = (PFNGLVERTEX3IVPROC)load("glVertex3iv"); - glad_glVertex3s = (PFNGLVERTEX3SPROC)load("glVertex3s"); - glad_glVertex3sv = (PFNGLVERTEX3SVPROC)load("glVertex3sv"); - glad_glVertex4d = (PFNGLVERTEX4DPROC)load("glVertex4d"); - glad_glVertex4dv = (PFNGLVERTEX4DVPROC)load("glVertex4dv"); - glad_glVertex4f = (PFNGLVERTEX4FPROC)load("glVertex4f"); - glad_glVertex4fv = (PFNGLVERTEX4FVPROC)load("glVertex4fv"); - glad_glVertex4i = (PFNGLVERTEX4IPROC)load("glVertex4i"); - glad_glVertex4iv = (PFNGLVERTEX4IVPROC)load("glVertex4iv"); - glad_glVertex4s = (PFNGLVERTEX4SPROC)load("glVertex4s"); - glad_glVertex4sv = (PFNGLVERTEX4SVPROC)load("glVertex4sv"); - glad_glClipPlane = (PFNGLCLIPPLANEPROC)load("glClipPlane"); - glad_glColorMaterial = (PFNGLCOLORMATERIALPROC)load("glColorMaterial"); - glad_glFogf = (PFNGLFOGFPROC)load("glFogf"); - glad_glFogfv = (PFNGLFOGFVPROC)load("glFogfv"); - glad_glFogi = (PFNGLFOGIPROC)load("glFogi"); - glad_glFogiv = (PFNGLFOGIVPROC)load("glFogiv"); - glad_glLightf = (PFNGLLIGHTFPROC)load("glLightf"); - glad_glLightfv = (PFNGLLIGHTFVPROC)load("glLightfv"); - glad_glLighti = (PFNGLLIGHTIPROC)load("glLighti"); - glad_glLightiv = (PFNGLLIGHTIVPROC)load("glLightiv"); - glad_glLightModelf = (PFNGLLIGHTMODELFPROC)load("glLightModelf"); - glad_glLightModelfv = (PFNGLLIGHTMODELFVPROC)load("glLightModelfv"); - glad_glLightModeli = (PFNGLLIGHTMODELIPROC)load("glLightModeli"); - glad_glLightModeliv = (PFNGLLIGHTMODELIVPROC)load("glLightModeliv"); - glad_glLineStipple = (PFNGLLINESTIPPLEPROC)load("glLineStipple"); - glad_glMaterialf = (PFNGLMATERIALFPROC)load("glMaterialf"); - glad_glMaterialfv = (PFNGLMATERIALFVPROC)load("glMaterialfv"); - glad_glMateriali = (PFNGLMATERIALIPROC)load("glMateriali"); - glad_glMaterialiv = (PFNGLMATERIALIVPROC)load("glMaterialiv"); - glad_glPolygonStipple = (PFNGLPOLYGONSTIPPLEPROC)load("glPolygonStipple"); - glad_glShadeModel = (PFNGLSHADEMODELPROC)load("glShadeModel"); - glad_glTexEnvf = (PFNGLTEXENVFPROC)load("glTexEnvf"); - glad_glTexEnvfv = (PFNGLTEXENVFVPROC)load("glTexEnvfv"); - glad_glTexEnvi = (PFNGLTEXENVIPROC)load("glTexEnvi"); - glad_glTexEnviv = (PFNGLTEXENVIVPROC)load("glTexEnviv"); - glad_glTexGend = (PFNGLTEXGENDPROC)load("glTexGend"); - glad_glTexGendv = (PFNGLTEXGENDVPROC)load("glTexGendv"); - glad_glTexGenf = (PFNGLTEXGENFPROC)load("glTexGenf"); - glad_glTexGenfv = (PFNGLTEXGENFVPROC)load("glTexGenfv"); - glad_glTexGeni = (PFNGLTEXGENIPROC)load("glTexGeni"); - glad_glTexGeniv = (PFNGLTEXGENIVPROC)load("glTexGeniv"); - glad_glFeedbackBuffer = (PFNGLFEEDBACKBUFFERPROC)load("glFeedbackBuffer"); - glad_glSelectBuffer = (PFNGLSELECTBUFFERPROC)load("glSelectBuffer"); - glad_glRenderMode = (PFNGLRENDERMODEPROC)load("glRenderMode"); - glad_glInitNames = (PFNGLINITNAMESPROC)load("glInitNames"); - glad_glLoadName = (PFNGLLOADNAMEPROC)load("glLoadName"); - glad_glPassThrough = (PFNGLPASSTHROUGHPROC)load("glPassThrough"); - glad_glPopName = (PFNGLPOPNAMEPROC)load("glPopName"); - glad_glPushName = (PFNGLPUSHNAMEPROC)load("glPushName"); - glad_glClearAccum = (PFNGLCLEARACCUMPROC)load("glClearAccum"); - glad_glClearIndex = (PFNGLCLEARINDEXPROC)load("glClearIndex"); - glad_glIndexMask = (PFNGLINDEXMASKPROC)load("glIndexMask"); - glad_glAccum = (PFNGLACCUMPROC)load("glAccum"); - glad_glPopAttrib = (PFNGLPOPATTRIBPROC)load("glPopAttrib"); - glad_glPushAttrib = (PFNGLPUSHATTRIBPROC)load("glPushAttrib"); - glad_glMap1d = (PFNGLMAP1DPROC)load("glMap1d"); - glad_glMap1f = (PFNGLMAP1FPROC)load("glMap1f"); - glad_glMap2d = (PFNGLMAP2DPROC)load("glMap2d"); - glad_glMap2f = (PFNGLMAP2FPROC)load("glMap2f"); - glad_glMapGrid1d = (PFNGLMAPGRID1DPROC)load("glMapGrid1d"); - glad_glMapGrid1f = (PFNGLMAPGRID1FPROC)load("glMapGrid1f"); - glad_glMapGrid2d = (PFNGLMAPGRID2DPROC)load("glMapGrid2d"); - glad_glMapGrid2f = (PFNGLMAPGRID2FPROC)load("glMapGrid2f"); - glad_glEvalCoord1d = (PFNGLEVALCOORD1DPROC)load("glEvalCoord1d"); - glad_glEvalCoord1dv = (PFNGLEVALCOORD1DVPROC)load("glEvalCoord1dv"); - glad_glEvalCoord1f = (PFNGLEVALCOORD1FPROC)load("glEvalCoord1f"); - glad_glEvalCoord1fv = (PFNGLEVALCOORD1FVPROC)load("glEvalCoord1fv"); - glad_glEvalCoord2d = (PFNGLEVALCOORD2DPROC)load("glEvalCoord2d"); - glad_glEvalCoord2dv = (PFNGLEVALCOORD2DVPROC)load("glEvalCoord2dv"); - glad_glEvalCoord2f = (PFNGLEVALCOORD2FPROC)load("glEvalCoord2f"); - glad_glEvalCoord2fv = (PFNGLEVALCOORD2FVPROC)load("glEvalCoord2fv"); - glad_glEvalMesh1 = (PFNGLEVALMESH1PROC)load("glEvalMesh1"); - glad_glEvalPoint1 = (PFNGLEVALPOINT1PROC)load("glEvalPoint1"); - glad_glEvalMesh2 = (PFNGLEVALMESH2PROC)load("glEvalMesh2"); - glad_glEvalPoint2 = (PFNGLEVALPOINT2PROC)load("glEvalPoint2"); - glad_glAlphaFunc = (PFNGLALPHAFUNCPROC)load("glAlphaFunc"); - glad_glPixelZoom = (PFNGLPIXELZOOMPROC)load("glPixelZoom"); - glad_glPixelTransferf = (PFNGLPIXELTRANSFERFPROC)load("glPixelTransferf"); - glad_glPixelTransferi = (PFNGLPIXELTRANSFERIPROC)load("glPixelTransferi"); - glad_glPixelMapfv = (PFNGLPIXELMAPFVPROC)load("glPixelMapfv"); - glad_glPixelMapuiv = (PFNGLPIXELMAPUIVPROC)load("glPixelMapuiv"); - glad_glPixelMapusv = (PFNGLPIXELMAPUSVPROC)load("glPixelMapusv"); - glad_glCopyPixels = (PFNGLCOPYPIXELSPROC)load("glCopyPixels"); - glad_glDrawPixels = (PFNGLDRAWPIXELSPROC)load("glDrawPixels"); - glad_glGetClipPlane = (PFNGLGETCLIPPLANEPROC)load("glGetClipPlane"); - glad_glGetLightfv = (PFNGLGETLIGHTFVPROC)load("glGetLightfv"); - glad_glGetLightiv = (PFNGLGETLIGHTIVPROC)load("glGetLightiv"); - glad_glGetMapdv = (PFNGLGETMAPDVPROC)load("glGetMapdv"); - glad_glGetMapfv = (PFNGLGETMAPFVPROC)load("glGetMapfv"); - glad_glGetMapiv = (PFNGLGETMAPIVPROC)load("glGetMapiv"); - glad_glGetMaterialfv = (PFNGLGETMATERIALFVPROC)load("glGetMaterialfv"); - glad_glGetMaterialiv = (PFNGLGETMATERIALIVPROC)load("glGetMaterialiv"); - glad_glGetPixelMapfv = (PFNGLGETPIXELMAPFVPROC)load("glGetPixelMapfv"); - glad_glGetPixelMapuiv = (PFNGLGETPIXELMAPUIVPROC)load("glGetPixelMapuiv"); - glad_glGetPixelMapusv = (PFNGLGETPIXELMAPUSVPROC)load("glGetPixelMapusv"); - glad_glGetPolygonStipple = (PFNGLGETPOLYGONSTIPPLEPROC)load("glGetPolygonStipple"); - glad_glGetTexEnvfv = (PFNGLGETTEXENVFVPROC)load("glGetTexEnvfv"); - glad_glGetTexEnviv = (PFNGLGETTEXENVIVPROC)load("glGetTexEnviv"); - glad_glGetTexGendv = (PFNGLGETTEXGENDVPROC)load("glGetTexGendv"); - glad_glGetTexGenfv = (PFNGLGETTEXGENFVPROC)load("glGetTexGenfv"); - glad_glGetTexGeniv = (PFNGLGETTEXGENIVPROC)load("glGetTexGeniv"); - glad_glIsList = (PFNGLISLISTPROC)load("glIsList"); - glad_glFrustum = (PFNGLFRUSTUMPROC)load("glFrustum"); - glad_glLoadIdentity = (PFNGLLOADIDENTITYPROC)load("glLoadIdentity"); - glad_glLoadMatrixf = (PFNGLLOADMATRIXFPROC)load("glLoadMatrixf"); - glad_glLoadMatrixd = (PFNGLLOADMATRIXDPROC)load("glLoadMatrixd"); - glad_glMatrixMode = (PFNGLMATRIXMODEPROC)load("glMatrixMode"); - glad_glMultMatrixf = (PFNGLMULTMATRIXFPROC)load("glMultMatrixf"); - glad_glMultMatrixd = (PFNGLMULTMATRIXDPROC)load("glMultMatrixd"); - glad_glOrtho = (PFNGLORTHOPROC)load("glOrtho"); - glad_glPopMatrix = (PFNGLPOPMATRIXPROC)load("glPopMatrix"); - glad_glPushMatrix = (PFNGLPUSHMATRIXPROC)load("glPushMatrix"); - glad_glRotated = (PFNGLROTATEDPROC)load("glRotated"); - glad_glRotatef = (PFNGLROTATEFPROC)load("glRotatef"); - glad_glScaled = (PFNGLSCALEDPROC)load("glScaled"); - glad_glScalef = (PFNGLSCALEFPROC)load("glScalef"); - glad_glTranslated = (PFNGLTRANSLATEDPROC)load("glTranslated"); - glad_glTranslatef = (PFNGLTRANSLATEFPROC)load("glTranslatef"); -} -static void load_GL_VERSION_1_1(GLADloadproc load) { - if(!GLAD_GL_VERSION_1_1) return; - glad_glDrawArrays = (PFNGLDRAWARRAYSPROC)load("glDrawArrays"); - glad_glDrawElements = (PFNGLDRAWELEMENTSPROC)load("glDrawElements"); - glad_glGetPointerv = (PFNGLGETPOINTERVPROC)load("glGetPointerv"); - glad_glPolygonOffset = (PFNGLPOLYGONOFFSETPROC)load("glPolygonOffset"); - glad_glCopyTexImage1D = (PFNGLCOPYTEXIMAGE1DPROC)load("glCopyTexImage1D"); - glad_glCopyTexImage2D = (PFNGLCOPYTEXIMAGE2DPROC)load("glCopyTexImage2D"); - glad_glCopyTexSubImage1D = (PFNGLCOPYTEXSUBIMAGE1DPROC)load("glCopyTexSubImage1D"); - glad_glCopyTexSubImage2D = (PFNGLCOPYTEXSUBIMAGE2DPROC)load("glCopyTexSubImage2D"); - glad_glTexSubImage1D = (PFNGLTEXSUBIMAGE1DPROC)load("glTexSubImage1D"); - glad_glTexSubImage2D = (PFNGLTEXSUBIMAGE2DPROC)load("glTexSubImage2D"); - glad_glBindTexture = (PFNGLBINDTEXTUREPROC)load("glBindTexture"); - glad_glDeleteTextures = (PFNGLDELETETEXTURESPROC)load("glDeleteTextures"); - glad_glGenTextures = (PFNGLGENTEXTURESPROC)load("glGenTextures"); - glad_glIsTexture = (PFNGLISTEXTUREPROC)load("glIsTexture"); - glad_glArrayElement = (PFNGLARRAYELEMENTPROC)load("glArrayElement"); - glad_glColorPointer = (PFNGLCOLORPOINTERPROC)load("glColorPointer"); - glad_glDisableClientState = (PFNGLDISABLECLIENTSTATEPROC)load("glDisableClientState"); - glad_glEdgeFlagPointer = (PFNGLEDGEFLAGPOINTERPROC)load("glEdgeFlagPointer"); - glad_glEnableClientState = (PFNGLENABLECLIENTSTATEPROC)load("glEnableClientState"); - glad_glIndexPointer = (PFNGLINDEXPOINTERPROC)load("glIndexPointer"); - glad_glInterleavedArrays = (PFNGLINTERLEAVEDARRAYSPROC)load("glInterleavedArrays"); - glad_glNormalPointer = (PFNGLNORMALPOINTERPROC)load("glNormalPointer"); - glad_glTexCoordPointer = (PFNGLTEXCOORDPOINTERPROC)load("glTexCoordPointer"); - glad_glVertexPointer = (PFNGLVERTEXPOINTERPROC)load("glVertexPointer"); - glad_glAreTexturesResident = (PFNGLARETEXTURESRESIDENTPROC)load("glAreTexturesResident"); - glad_glPrioritizeTextures = (PFNGLPRIORITIZETEXTURESPROC)load("glPrioritizeTextures"); - glad_glIndexub = (PFNGLINDEXUBPROC)load("glIndexub"); - glad_glIndexubv = (PFNGLINDEXUBVPROC)load("glIndexubv"); - glad_glPopClientAttrib = (PFNGLPOPCLIENTATTRIBPROC)load("glPopClientAttrib"); - glad_glPushClientAttrib = (PFNGLPUSHCLIENTATTRIBPROC)load("glPushClientAttrib"); -} -static void load_GL_VERSION_1_2(GLADloadproc load) { - if(!GLAD_GL_VERSION_1_2) return; - glad_glDrawRangeElements = (PFNGLDRAWRANGEELEMENTSPROC)load("glDrawRangeElements"); - glad_glTexImage3D = (PFNGLTEXIMAGE3DPROC)load("glTexImage3D"); - glad_glTexSubImage3D = (PFNGLTEXSUBIMAGE3DPROC)load("glTexSubImage3D"); - glad_glCopyTexSubImage3D = (PFNGLCOPYTEXSUBIMAGE3DPROC)load("glCopyTexSubImage3D"); -} -static void load_GL_VERSION_1_3(GLADloadproc load) { - if(!GLAD_GL_VERSION_1_3) return; - glad_glActiveTexture = (PFNGLACTIVETEXTUREPROC)load("glActiveTexture"); - glad_glSampleCoverage = (PFNGLSAMPLECOVERAGEPROC)load("glSampleCoverage"); - glad_glCompressedTexImage3D = (PFNGLCOMPRESSEDTEXIMAGE3DPROC)load("glCompressedTexImage3D"); - glad_glCompressedTexImage2D = (PFNGLCOMPRESSEDTEXIMAGE2DPROC)load("glCompressedTexImage2D"); - glad_glCompressedTexImage1D = (PFNGLCOMPRESSEDTEXIMAGE1DPROC)load("glCompressedTexImage1D"); - glad_glCompressedTexSubImage3D = (PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC)load("glCompressedTexSubImage3D"); - glad_glCompressedTexSubImage2D = (PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC)load("glCompressedTexSubImage2D"); - glad_glCompressedTexSubImage1D = (PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC)load("glCompressedTexSubImage1D"); - glad_glGetCompressedTexImage = (PFNGLGETCOMPRESSEDTEXIMAGEPROC)load("glGetCompressedTexImage"); - glad_glClientActiveTexture = (PFNGLCLIENTACTIVETEXTUREPROC)load("glClientActiveTexture"); - glad_glMultiTexCoord1d = (PFNGLMULTITEXCOORD1DPROC)load("glMultiTexCoord1d"); - glad_glMultiTexCoord1dv = (PFNGLMULTITEXCOORD1DVPROC)load("glMultiTexCoord1dv"); - glad_glMultiTexCoord1f = (PFNGLMULTITEXCOORD1FPROC)load("glMultiTexCoord1f"); - glad_glMultiTexCoord1fv = (PFNGLMULTITEXCOORD1FVPROC)load("glMultiTexCoord1fv"); - glad_glMultiTexCoord1i = (PFNGLMULTITEXCOORD1IPROC)load("glMultiTexCoord1i"); - glad_glMultiTexCoord1iv = (PFNGLMULTITEXCOORD1IVPROC)load("glMultiTexCoord1iv"); - glad_glMultiTexCoord1s = (PFNGLMULTITEXCOORD1SPROC)load("glMultiTexCoord1s"); - glad_glMultiTexCoord1sv = (PFNGLMULTITEXCOORD1SVPROC)load("glMultiTexCoord1sv"); - glad_glMultiTexCoord2d = (PFNGLMULTITEXCOORD2DPROC)load("glMultiTexCoord2d"); - glad_glMultiTexCoord2dv = (PFNGLMULTITEXCOORD2DVPROC)load("glMultiTexCoord2dv"); - glad_glMultiTexCoord2f = (PFNGLMULTITEXCOORD2FPROC)load("glMultiTexCoord2f"); - glad_glMultiTexCoord2fv = (PFNGLMULTITEXCOORD2FVPROC)load("glMultiTexCoord2fv"); - glad_glMultiTexCoord2i = (PFNGLMULTITEXCOORD2IPROC)load("glMultiTexCoord2i"); - glad_glMultiTexCoord2iv = (PFNGLMULTITEXCOORD2IVPROC)load("glMultiTexCoord2iv"); - glad_glMultiTexCoord2s = (PFNGLMULTITEXCOORD2SPROC)load("glMultiTexCoord2s"); - glad_glMultiTexCoord2sv = (PFNGLMULTITEXCOORD2SVPROC)load("glMultiTexCoord2sv"); - glad_glMultiTexCoord3d = (PFNGLMULTITEXCOORD3DPROC)load("glMultiTexCoord3d"); - glad_glMultiTexCoord3dv = (PFNGLMULTITEXCOORD3DVPROC)load("glMultiTexCoord3dv"); - glad_glMultiTexCoord3f = (PFNGLMULTITEXCOORD3FPROC)load("glMultiTexCoord3f"); - glad_glMultiTexCoord3fv = (PFNGLMULTITEXCOORD3FVPROC)load("glMultiTexCoord3fv"); - glad_glMultiTexCoord3i = (PFNGLMULTITEXCOORD3IPROC)load("glMultiTexCoord3i"); - glad_glMultiTexCoord3iv = (PFNGLMULTITEXCOORD3IVPROC)load("glMultiTexCoord3iv"); - glad_glMultiTexCoord3s = (PFNGLMULTITEXCOORD3SPROC)load("glMultiTexCoord3s"); - glad_glMultiTexCoord3sv = (PFNGLMULTITEXCOORD3SVPROC)load("glMultiTexCoord3sv"); - glad_glMultiTexCoord4d = (PFNGLMULTITEXCOORD4DPROC)load("glMultiTexCoord4d"); - glad_glMultiTexCoord4dv = (PFNGLMULTITEXCOORD4DVPROC)load("glMultiTexCoord4dv"); - glad_glMultiTexCoord4f = (PFNGLMULTITEXCOORD4FPROC)load("glMultiTexCoord4f"); - glad_glMultiTexCoord4fv = (PFNGLMULTITEXCOORD4FVPROC)load("glMultiTexCoord4fv"); - glad_glMultiTexCoord4i = (PFNGLMULTITEXCOORD4IPROC)load("glMultiTexCoord4i"); - glad_glMultiTexCoord4iv = (PFNGLMULTITEXCOORD4IVPROC)load("glMultiTexCoord4iv"); - glad_glMultiTexCoord4s = (PFNGLMULTITEXCOORD4SPROC)load("glMultiTexCoord4s"); - glad_glMultiTexCoord4sv = (PFNGLMULTITEXCOORD4SVPROC)load("glMultiTexCoord4sv"); - glad_glLoadTransposeMatrixf = (PFNGLLOADTRANSPOSEMATRIXFPROC)load("glLoadTransposeMatrixf"); - glad_glLoadTransposeMatrixd = (PFNGLLOADTRANSPOSEMATRIXDPROC)load("glLoadTransposeMatrixd"); - glad_glMultTransposeMatrixf = (PFNGLMULTTRANSPOSEMATRIXFPROC)load("glMultTransposeMatrixf"); - glad_glMultTransposeMatrixd = (PFNGLMULTTRANSPOSEMATRIXDPROC)load("glMultTransposeMatrixd"); -} -static void load_GL_VERSION_1_4(GLADloadproc load) { - if(!GLAD_GL_VERSION_1_4) return; - glad_glBlendFuncSeparate = (PFNGLBLENDFUNCSEPARATEPROC)load("glBlendFuncSeparate"); - glad_glMultiDrawArrays = (PFNGLMULTIDRAWARRAYSPROC)load("glMultiDrawArrays"); - glad_glMultiDrawElements = (PFNGLMULTIDRAWELEMENTSPROC)load("glMultiDrawElements"); - glad_glPointParameterf = (PFNGLPOINTPARAMETERFPROC)load("glPointParameterf"); - glad_glPointParameterfv = (PFNGLPOINTPARAMETERFVPROC)load("glPointParameterfv"); - glad_glPointParameteri = (PFNGLPOINTPARAMETERIPROC)load("glPointParameteri"); - glad_glPointParameteriv = (PFNGLPOINTPARAMETERIVPROC)load("glPointParameteriv"); - glad_glFogCoordf = (PFNGLFOGCOORDFPROC)load("glFogCoordf"); - glad_glFogCoordfv = (PFNGLFOGCOORDFVPROC)load("glFogCoordfv"); - glad_glFogCoordd = (PFNGLFOGCOORDDPROC)load("glFogCoordd"); - glad_glFogCoorddv = (PFNGLFOGCOORDDVPROC)load("glFogCoorddv"); - glad_glFogCoordPointer = (PFNGLFOGCOORDPOINTERPROC)load("glFogCoordPointer"); - glad_glSecondaryColor3b = (PFNGLSECONDARYCOLOR3BPROC)load("glSecondaryColor3b"); - glad_glSecondaryColor3bv = (PFNGLSECONDARYCOLOR3BVPROC)load("glSecondaryColor3bv"); - glad_glSecondaryColor3d = (PFNGLSECONDARYCOLOR3DPROC)load("glSecondaryColor3d"); - glad_glSecondaryColor3dv = (PFNGLSECONDARYCOLOR3DVPROC)load("glSecondaryColor3dv"); - glad_glSecondaryColor3f = (PFNGLSECONDARYCOLOR3FPROC)load("glSecondaryColor3f"); - glad_glSecondaryColor3fv = (PFNGLSECONDARYCOLOR3FVPROC)load("glSecondaryColor3fv"); - glad_glSecondaryColor3i = (PFNGLSECONDARYCOLOR3IPROC)load("glSecondaryColor3i"); - glad_glSecondaryColor3iv = (PFNGLSECONDARYCOLOR3IVPROC)load("glSecondaryColor3iv"); - glad_glSecondaryColor3s = (PFNGLSECONDARYCOLOR3SPROC)load("glSecondaryColor3s"); - glad_glSecondaryColor3sv = (PFNGLSECONDARYCOLOR3SVPROC)load("glSecondaryColor3sv"); - glad_glSecondaryColor3ub = (PFNGLSECONDARYCOLOR3UBPROC)load("glSecondaryColor3ub"); - glad_glSecondaryColor3ubv = (PFNGLSECONDARYCOLOR3UBVPROC)load("glSecondaryColor3ubv"); - glad_glSecondaryColor3ui = (PFNGLSECONDARYCOLOR3UIPROC)load("glSecondaryColor3ui"); - glad_glSecondaryColor3uiv = (PFNGLSECONDARYCOLOR3UIVPROC)load("glSecondaryColor3uiv"); - glad_glSecondaryColor3us = (PFNGLSECONDARYCOLOR3USPROC)load("glSecondaryColor3us"); - glad_glSecondaryColor3usv = (PFNGLSECONDARYCOLOR3USVPROC)load("glSecondaryColor3usv"); - glad_glSecondaryColorPointer = (PFNGLSECONDARYCOLORPOINTERPROC)load("glSecondaryColorPointer"); - glad_glWindowPos2d = (PFNGLWINDOWPOS2DPROC)load("glWindowPos2d"); - glad_glWindowPos2dv = (PFNGLWINDOWPOS2DVPROC)load("glWindowPos2dv"); - glad_glWindowPos2f = (PFNGLWINDOWPOS2FPROC)load("glWindowPos2f"); - glad_glWindowPos2fv = (PFNGLWINDOWPOS2FVPROC)load("glWindowPos2fv"); - glad_glWindowPos2i = (PFNGLWINDOWPOS2IPROC)load("glWindowPos2i"); - glad_glWindowPos2iv = (PFNGLWINDOWPOS2IVPROC)load("glWindowPos2iv"); - glad_glWindowPos2s = (PFNGLWINDOWPOS2SPROC)load("glWindowPos2s"); - glad_glWindowPos2sv = (PFNGLWINDOWPOS2SVPROC)load("glWindowPos2sv"); - glad_glWindowPos3d = (PFNGLWINDOWPOS3DPROC)load("glWindowPos3d"); - glad_glWindowPos3dv = (PFNGLWINDOWPOS3DVPROC)load("glWindowPos3dv"); - glad_glWindowPos3f = (PFNGLWINDOWPOS3FPROC)load("glWindowPos3f"); - glad_glWindowPos3fv = (PFNGLWINDOWPOS3FVPROC)load("glWindowPos3fv"); - glad_glWindowPos3i = (PFNGLWINDOWPOS3IPROC)load("glWindowPos3i"); - glad_glWindowPos3iv = (PFNGLWINDOWPOS3IVPROC)load("glWindowPos3iv"); - glad_glWindowPos3s = (PFNGLWINDOWPOS3SPROC)load("glWindowPos3s"); - glad_glWindowPos3sv = (PFNGLWINDOWPOS3SVPROC)load("glWindowPos3sv"); - glad_glBlendColor = (PFNGLBLENDCOLORPROC)load("glBlendColor"); - glad_glBlendEquation = (PFNGLBLENDEQUATIONPROC)load("glBlendEquation"); -} -static void load_GL_VERSION_1_5(GLADloadproc load) { - if(!GLAD_GL_VERSION_1_5) return; - glad_glGenQueries = (PFNGLGENQUERIESPROC)load("glGenQueries"); - glad_glDeleteQueries = (PFNGLDELETEQUERIESPROC)load("glDeleteQueries"); - glad_glIsQuery = (PFNGLISQUERYPROC)load("glIsQuery"); - glad_glBeginQuery = (PFNGLBEGINQUERYPROC)load("glBeginQuery"); - glad_glEndQuery = (PFNGLENDQUERYPROC)load("glEndQuery"); - glad_glGetQueryiv = (PFNGLGETQUERYIVPROC)load("glGetQueryiv"); - glad_glGetQueryObjectiv = (PFNGLGETQUERYOBJECTIVPROC)load("glGetQueryObjectiv"); - glad_glGetQueryObjectuiv = (PFNGLGETQUERYOBJECTUIVPROC)load("glGetQueryObjectuiv"); - glad_glBindBuffer = (PFNGLBINDBUFFERPROC)load("glBindBuffer"); - glad_glDeleteBuffers = (PFNGLDELETEBUFFERSPROC)load("glDeleteBuffers"); - glad_glGenBuffers = (PFNGLGENBUFFERSPROC)load("glGenBuffers"); - glad_glIsBuffer = (PFNGLISBUFFERPROC)load("glIsBuffer"); - glad_glBufferData = (PFNGLBUFFERDATAPROC)load("glBufferData"); - glad_glBufferSubData = (PFNGLBUFFERSUBDATAPROC)load("glBufferSubData"); - glad_glGetBufferSubData = (PFNGLGETBUFFERSUBDATAPROC)load("glGetBufferSubData"); - glad_glMapBuffer = (PFNGLMAPBUFFERPROC)load("glMapBuffer"); - glad_glUnmapBuffer = (PFNGLUNMAPBUFFERPROC)load("glUnmapBuffer"); - glad_glGetBufferParameteriv = (PFNGLGETBUFFERPARAMETERIVPROC)load("glGetBufferParameteriv"); - glad_glGetBufferPointerv = (PFNGLGETBUFFERPOINTERVPROC)load("glGetBufferPointerv"); -} -static void load_GL_VERSION_2_0(GLADloadproc load) { - if(!GLAD_GL_VERSION_2_0) return; - glad_glBlendEquationSeparate = (PFNGLBLENDEQUATIONSEPARATEPROC)load("glBlendEquationSeparate"); - glad_glDrawBuffers = (PFNGLDRAWBUFFERSPROC)load("glDrawBuffers"); - glad_glStencilOpSeparate = (PFNGLSTENCILOPSEPARATEPROC)load("glStencilOpSeparate"); - glad_glStencilFuncSeparate = (PFNGLSTENCILFUNCSEPARATEPROC)load("glStencilFuncSeparate"); - glad_glStencilMaskSeparate = (PFNGLSTENCILMASKSEPARATEPROC)load("glStencilMaskSeparate"); - glad_glAttachShader = (PFNGLATTACHSHADERPROC)load("glAttachShader"); - glad_glBindAttribLocation = (PFNGLBINDATTRIBLOCATIONPROC)load("glBindAttribLocation"); - glad_glCompileShader = (PFNGLCOMPILESHADERPROC)load("glCompileShader"); - glad_glCreateProgram = (PFNGLCREATEPROGRAMPROC)load("glCreateProgram"); - glad_glCreateShader = (PFNGLCREATESHADERPROC)load("glCreateShader"); - glad_glDeleteProgram = (PFNGLDELETEPROGRAMPROC)load("glDeleteProgram"); - glad_glDeleteShader = (PFNGLDELETESHADERPROC)load("glDeleteShader"); - glad_glDetachShader = (PFNGLDETACHSHADERPROC)load("glDetachShader"); - glad_glDisableVertexAttribArray = (PFNGLDISABLEVERTEXATTRIBARRAYPROC)load("glDisableVertexAttribArray"); - glad_glEnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYPROC)load("glEnableVertexAttribArray"); - glad_glGetActiveAttrib = (PFNGLGETACTIVEATTRIBPROC)load("glGetActiveAttrib"); - glad_glGetActiveUniform = (PFNGLGETACTIVEUNIFORMPROC)load("glGetActiveUniform"); - glad_glGetAttachedShaders = (PFNGLGETATTACHEDSHADERSPROC)load("glGetAttachedShaders"); - glad_glGetAttribLocation = (PFNGLGETATTRIBLOCATIONPROC)load("glGetAttribLocation"); - glad_glGetProgramiv = (PFNGLGETPROGRAMIVPROC)load("glGetProgramiv"); - glad_glGetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC)load("glGetProgramInfoLog"); - glad_glGetShaderiv = (PFNGLGETSHADERIVPROC)load("glGetShaderiv"); - glad_glGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC)load("glGetShaderInfoLog"); - glad_glGetShaderSource = (PFNGLGETSHADERSOURCEPROC)load("glGetShaderSource"); - glad_glGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC)load("glGetUniformLocation"); - glad_glGetUniformfv = (PFNGLGETUNIFORMFVPROC)load("glGetUniformfv"); - glad_glGetUniformiv = (PFNGLGETUNIFORMIVPROC)load("glGetUniformiv"); - glad_glGetVertexAttribdv = (PFNGLGETVERTEXATTRIBDVPROC)load("glGetVertexAttribdv"); - glad_glGetVertexAttribfv = (PFNGLGETVERTEXATTRIBFVPROC)load("glGetVertexAttribfv"); - glad_glGetVertexAttribiv = (PFNGLGETVERTEXATTRIBIVPROC)load("glGetVertexAttribiv"); - glad_glGetVertexAttribPointerv = (PFNGLGETVERTEXATTRIBPOINTERVPROC)load("glGetVertexAttribPointerv"); - glad_glIsProgram = (PFNGLISPROGRAMPROC)load("glIsProgram"); - glad_glIsShader = (PFNGLISSHADERPROC)load("glIsShader"); - glad_glLinkProgram = (PFNGLLINKPROGRAMPROC)load("glLinkProgram"); - glad_glShaderSource = (PFNGLSHADERSOURCEPROC)load("glShaderSource"); - glad_glUseProgram = (PFNGLUSEPROGRAMPROC)load("glUseProgram"); - glad_glUniform1f = (PFNGLUNIFORM1FPROC)load("glUniform1f"); - glad_glUniform2f = (PFNGLUNIFORM2FPROC)load("glUniform2f"); - glad_glUniform3f = (PFNGLUNIFORM3FPROC)load("glUniform3f"); - glad_glUniform4f = (PFNGLUNIFORM4FPROC)load("glUniform4f"); - glad_glUniform1i = (PFNGLUNIFORM1IPROC)load("glUniform1i"); - glad_glUniform2i = (PFNGLUNIFORM2IPROC)load("glUniform2i"); - glad_glUniform3i = (PFNGLUNIFORM3IPROC)load("glUniform3i"); - glad_glUniform4i = (PFNGLUNIFORM4IPROC)load("glUniform4i"); - glad_glUniform1fv = (PFNGLUNIFORM1FVPROC)load("glUniform1fv"); - glad_glUniform2fv = (PFNGLUNIFORM2FVPROC)load("glUniform2fv"); - glad_glUniform3fv = (PFNGLUNIFORM3FVPROC)load("glUniform3fv"); - glad_glUniform4fv = (PFNGLUNIFORM4FVPROC)load("glUniform4fv"); - glad_glUniform1iv = (PFNGLUNIFORM1IVPROC)load("glUniform1iv"); - glad_glUniform2iv = (PFNGLUNIFORM2IVPROC)load("glUniform2iv"); - glad_glUniform3iv = (PFNGLUNIFORM3IVPROC)load("glUniform3iv"); - glad_glUniform4iv = (PFNGLUNIFORM4IVPROC)load("glUniform4iv"); - glad_glUniformMatrix2fv = (PFNGLUNIFORMMATRIX2FVPROC)load("glUniformMatrix2fv"); - glad_glUniformMatrix3fv = (PFNGLUNIFORMMATRIX3FVPROC)load("glUniformMatrix3fv"); - glad_glUniformMatrix4fv = (PFNGLUNIFORMMATRIX4FVPROC)load("glUniformMatrix4fv"); - glad_glValidateProgram = (PFNGLVALIDATEPROGRAMPROC)load("glValidateProgram"); - glad_glVertexAttrib1d = (PFNGLVERTEXATTRIB1DPROC)load("glVertexAttrib1d"); - glad_glVertexAttrib1dv = (PFNGLVERTEXATTRIB1DVPROC)load("glVertexAttrib1dv"); - glad_glVertexAttrib1f = (PFNGLVERTEXATTRIB1FPROC)load("glVertexAttrib1f"); - glad_glVertexAttrib1fv = (PFNGLVERTEXATTRIB1FVPROC)load("glVertexAttrib1fv"); - glad_glVertexAttrib1s = (PFNGLVERTEXATTRIB1SPROC)load("glVertexAttrib1s"); - glad_glVertexAttrib1sv = (PFNGLVERTEXATTRIB1SVPROC)load("glVertexAttrib1sv"); - glad_glVertexAttrib2d = (PFNGLVERTEXATTRIB2DPROC)load("glVertexAttrib2d"); - glad_glVertexAttrib2dv = (PFNGLVERTEXATTRIB2DVPROC)load("glVertexAttrib2dv"); - glad_glVertexAttrib2f = (PFNGLVERTEXATTRIB2FPROC)load("glVertexAttrib2f"); - glad_glVertexAttrib2fv = (PFNGLVERTEXATTRIB2FVPROC)load("glVertexAttrib2fv"); - glad_glVertexAttrib2s = (PFNGLVERTEXATTRIB2SPROC)load("glVertexAttrib2s"); - glad_glVertexAttrib2sv = (PFNGLVERTEXATTRIB2SVPROC)load("glVertexAttrib2sv"); - glad_glVertexAttrib3d = (PFNGLVERTEXATTRIB3DPROC)load("glVertexAttrib3d"); - glad_glVertexAttrib3dv = (PFNGLVERTEXATTRIB3DVPROC)load("glVertexAttrib3dv"); - glad_glVertexAttrib3f = (PFNGLVERTEXATTRIB3FPROC)load("glVertexAttrib3f"); - glad_glVertexAttrib3fv = (PFNGLVERTEXATTRIB3FVPROC)load("glVertexAttrib3fv"); - glad_glVertexAttrib3s = (PFNGLVERTEXATTRIB3SPROC)load("glVertexAttrib3s"); - glad_glVertexAttrib3sv = (PFNGLVERTEXATTRIB3SVPROC)load("glVertexAttrib3sv"); - glad_glVertexAttrib4Nbv = (PFNGLVERTEXATTRIB4NBVPROC)load("glVertexAttrib4Nbv"); - glad_glVertexAttrib4Niv = (PFNGLVERTEXATTRIB4NIVPROC)load("glVertexAttrib4Niv"); - glad_glVertexAttrib4Nsv = (PFNGLVERTEXATTRIB4NSVPROC)load("glVertexAttrib4Nsv"); - glad_glVertexAttrib4Nub = (PFNGLVERTEXATTRIB4NUBPROC)load("glVertexAttrib4Nub"); - glad_glVertexAttrib4Nubv = (PFNGLVERTEXATTRIB4NUBVPROC)load("glVertexAttrib4Nubv"); - glad_glVertexAttrib4Nuiv = (PFNGLVERTEXATTRIB4NUIVPROC)load("glVertexAttrib4Nuiv"); - glad_glVertexAttrib4Nusv = (PFNGLVERTEXATTRIB4NUSVPROC)load("glVertexAttrib4Nusv"); - glad_glVertexAttrib4bv = (PFNGLVERTEXATTRIB4BVPROC)load("glVertexAttrib4bv"); - glad_glVertexAttrib4d = (PFNGLVERTEXATTRIB4DPROC)load("glVertexAttrib4d"); - glad_glVertexAttrib4dv = (PFNGLVERTEXATTRIB4DVPROC)load("glVertexAttrib4dv"); - glad_glVertexAttrib4f = (PFNGLVERTEXATTRIB4FPROC)load("glVertexAttrib4f"); - glad_glVertexAttrib4fv = (PFNGLVERTEXATTRIB4FVPROC)load("glVertexAttrib4fv"); - glad_glVertexAttrib4iv = (PFNGLVERTEXATTRIB4IVPROC)load("glVertexAttrib4iv"); - glad_glVertexAttrib4s = (PFNGLVERTEXATTRIB4SPROC)load("glVertexAttrib4s"); - glad_glVertexAttrib4sv = (PFNGLVERTEXATTRIB4SVPROC)load("glVertexAttrib4sv"); - glad_glVertexAttrib4ubv = (PFNGLVERTEXATTRIB4UBVPROC)load("glVertexAttrib4ubv"); - glad_glVertexAttrib4uiv = (PFNGLVERTEXATTRIB4UIVPROC)load("glVertexAttrib4uiv"); - glad_glVertexAttrib4usv = (PFNGLVERTEXATTRIB4USVPROC)load("glVertexAttrib4usv"); - glad_glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC)load("glVertexAttribPointer"); -} -static void load_GL_VERSION_2_1(GLADloadproc load) { - if(!GLAD_GL_VERSION_2_1) return; - glad_glUniformMatrix2x3fv = (PFNGLUNIFORMMATRIX2X3FVPROC)load("glUniformMatrix2x3fv"); - glad_glUniformMatrix3x2fv = (PFNGLUNIFORMMATRIX3X2FVPROC)load("glUniformMatrix3x2fv"); - glad_glUniformMatrix2x4fv = (PFNGLUNIFORMMATRIX2X4FVPROC)load("glUniformMatrix2x4fv"); - glad_glUniformMatrix4x2fv = (PFNGLUNIFORMMATRIX4X2FVPROC)load("glUniformMatrix4x2fv"); - glad_glUniformMatrix3x4fv = (PFNGLUNIFORMMATRIX3X4FVPROC)load("glUniformMatrix3x4fv"); - glad_glUniformMatrix4x3fv = (PFNGLUNIFORMMATRIX4X3FVPROC)load("glUniformMatrix4x3fv"); -} -static void load_GL_VERSION_3_0(GLADloadproc load) { - if(!GLAD_GL_VERSION_3_0) return; - glad_glColorMaski = (PFNGLCOLORMASKIPROC)load("glColorMaski"); - glad_glGetBooleani_v = (PFNGLGETBOOLEANI_VPROC)load("glGetBooleani_v"); - glad_glGetIntegeri_v = (PFNGLGETINTEGERI_VPROC)load("glGetIntegeri_v"); - glad_glEnablei = (PFNGLENABLEIPROC)load("glEnablei"); - glad_glDisablei = (PFNGLDISABLEIPROC)load("glDisablei"); - glad_glIsEnabledi = (PFNGLISENABLEDIPROC)load("glIsEnabledi"); - glad_glBeginTransformFeedback = (PFNGLBEGINTRANSFORMFEEDBACKPROC)load("glBeginTransformFeedback"); - glad_glEndTransformFeedback = (PFNGLENDTRANSFORMFEEDBACKPROC)load("glEndTransformFeedback"); - glad_glBindBufferRange = (PFNGLBINDBUFFERRANGEPROC)load("glBindBufferRange"); - glad_glBindBufferBase = (PFNGLBINDBUFFERBASEPROC)load("glBindBufferBase"); - glad_glTransformFeedbackVaryings = (PFNGLTRANSFORMFEEDBACKVARYINGSPROC)load("glTransformFeedbackVaryings"); - glad_glGetTransformFeedbackVarying = (PFNGLGETTRANSFORMFEEDBACKVARYINGPROC)load("glGetTransformFeedbackVarying"); - glad_glClampColor = (PFNGLCLAMPCOLORPROC)load("glClampColor"); - glad_glBeginConditionalRender = (PFNGLBEGINCONDITIONALRENDERPROC)load("glBeginConditionalRender"); - glad_glEndConditionalRender = (PFNGLENDCONDITIONALRENDERPROC)load("glEndConditionalRender"); - glad_glVertexAttribIPointer = (PFNGLVERTEXATTRIBIPOINTERPROC)load("glVertexAttribIPointer"); - glad_glGetVertexAttribIiv = (PFNGLGETVERTEXATTRIBIIVPROC)load("glGetVertexAttribIiv"); - glad_glGetVertexAttribIuiv = (PFNGLGETVERTEXATTRIBIUIVPROC)load("glGetVertexAttribIuiv"); - glad_glVertexAttribI1i = (PFNGLVERTEXATTRIBI1IPROC)load("glVertexAttribI1i"); - glad_glVertexAttribI2i = (PFNGLVERTEXATTRIBI2IPROC)load("glVertexAttribI2i"); - glad_glVertexAttribI3i = (PFNGLVERTEXATTRIBI3IPROC)load("glVertexAttribI3i"); - glad_glVertexAttribI4i = (PFNGLVERTEXATTRIBI4IPROC)load("glVertexAttribI4i"); - glad_glVertexAttribI1ui = (PFNGLVERTEXATTRIBI1UIPROC)load("glVertexAttribI1ui"); - glad_glVertexAttribI2ui = (PFNGLVERTEXATTRIBI2UIPROC)load("glVertexAttribI2ui"); - glad_glVertexAttribI3ui = (PFNGLVERTEXATTRIBI3UIPROC)load("glVertexAttribI3ui"); - glad_glVertexAttribI4ui = (PFNGLVERTEXATTRIBI4UIPROC)load("glVertexAttribI4ui"); - glad_glVertexAttribI1iv = (PFNGLVERTEXATTRIBI1IVPROC)load("glVertexAttribI1iv"); - glad_glVertexAttribI2iv = (PFNGLVERTEXATTRIBI2IVPROC)load("glVertexAttribI2iv"); - glad_glVertexAttribI3iv = (PFNGLVERTEXATTRIBI3IVPROC)load("glVertexAttribI3iv"); - glad_glVertexAttribI4iv = (PFNGLVERTEXATTRIBI4IVPROC)load("glVertexAttribI4iv"); - glad_glVertexAttribI1uiv = (PFNGLVERTEXATTRIBI1UIVPROC)load("glVertexAttribI1uiv"); - glad_glVertexAttribI2uiv = (PFNGLVERTEXATTRIBI2UIVPROC)load("glVertexAttribI2uiv"); - glad_glVertexAttribI3uiv = (PFNGLVERTEXATTRIBI3UIVPROC)load("glVertexAttribI3uiv"); - glad_glVertexAttribI4uiv = (PFNGLVERTEXATTRIBI4UIVPROC)load("glVertexAttribI4uiv"); - glad_glVertexAttribI4bv = (PFNGLVERTEXATTRIBI4BVPROC)load("glVertexAttribI4bv"); - glad_glVertexAttribI4sv = (PFNGLVERTEXATTRIBI4SVPROC)load("glVertexAttribI4sv"); - glad_glVertexAttribI4ubv = (PFNGLVERTEXATTRIBI4UBVPROC)load("glVertexAttribI4ubv"); - glad_glVertexAttribI4usv = (PFNGLVERTEXATTRIBI4USVPROC)load("glVertexAttribI4usv"); - glad_glGetUniformuiv = (PFNGLGETUNIFORMUIVPROC)load("glGetUniformuiv"); - glad_glBindFragDataLocation = (PFNGLBINDFRAGDATALOCATIONPROC)load("glBindFragDataLocation"); - glad_glGetFragDataLocation = (PFNGLGETFRAGDATALOCATIONPROC)load("glGetFragDataLocation"); - glad_glUniform1ui = (PFNGLUNIFORM1UIPROC)load("glUniform1ui"); - glad_glUniform2ui = (PFNGLUNIFORM2UIPROC)load("glUniform2ui"); - glad_glUniform3ui = (PFNGLUNIFORM3UIPROC)load("glUniform3ui"); - glad_glUniform4ui = (PFNGLUNIFORM4UIPROC)load("glUniform4ui"); - glad_glUniform1uiv = (PFNGLUNIFORM1UIVPROC)load("glUniform1uiv"); - glad_glUniform2uiv = (PFNGLUNIFORM2UIVPROC)load("glUniform2uiv"); - glad_glUniform3uiv = (PFNGLUNIFORM3UIVPROC)load("glUniform3uiv"); - glad_glUniform4uiv = (PFNGLUNIFORM4UIVPROC)load("glUniform4uiv"); - glad_glTexParameterIiv = (PFNGLTEXPARAMETERIIVPROC)load("glTexParameterIiv"); - glad_glTexParameterIuiv = (PFNGLTEXPARAMETERIUIVPROC)load("glTexParameterIuiv"); - glad_glGetTexParameterIiv = (PFNGLGETTEXPARAMETERIIVPROC)load("glGetTexParameterIiv"); - glad_glGetTexParameterIuiv = (PFNGLGETTEXPARAMETERIUIVPROC)load("glGetTexParameterIuiv"); - glad_glClearBufferiv = (PFNGLCLEARBUFFERIVPROC)load("glClearBufferiv"); - glad_glClearBufferuiv = (PFNGLCLEARBUFFERUIVPROC)load("glClearBufferuiv"); - glad_glClearBufferfv = (PFNGLCLEARBUFFERFVPROC)load("glClearBufferfv"); - glad_glClearBufferfi = (PFNGLCLEARBUFFERFIPROC)load("glClearBufferfi"); - glad_glGetStringi = (PFNGLGETSTRINGIPROC)load("glGetStringi"); - glad_glIsRenderbuffer = (PFNGLISRENDERBUFFERPROC)load("glIsRenderbuffer"); - glad_glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC)load("glBindRenderbuffer"); - glad_glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC)load("glDeleteRenderbuffers"); - glad_glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC)load("glGenRenderbuffers"); - glad_glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC)load("glRenderbufferStorage"); - glad_glGetRenderbufferParameteriv = (PFNGLGETRENDERBUFFERPARAMETERIVPROC)load("glGetRenderbufferParameteriv"); - glad_glIsFramebuffer = (PFNGLISFRAMEBUFFERPROC)load("glIsFramebuffer"); - glad_glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)load("glBindFramebuffer"); - glad_glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC)load("glDeleteFramebuffers"); - glad_glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)load("glGenFramebuffers"); - glad_glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC)load("glCheckFramebufferStatus"); - glad_glFramebufferTexture1D = (PFNGLFRAMEBUFFERTEXTURE1DPROC)load("glFramebufferTexture1D"); - glad_glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)load("glFramebufferTexture2D"); - glad_glFramebufferTexture3D = (PFNGLFRAMEBUFFERTEXTURE3DPROC)load("glFramebufferTexture3D"); - glad_glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC)load("glFramebufferRenderbuffer"); - glad_glGetFramebufferAttachmentParameteriv = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC)load("glGetFramebufferAttachmentParameteriv"); - glad_glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC)load("glGenerateMipmap"); - glad_glBlitFramebuffer = (PFNGLBLITFRAMEBUFFERPROC)load("glBlitFramebuffer"); - glad_glRenderbufferStorageMultisample = (PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC)load("glRenderbufferStorageMultisample"); - glad_glFramebufferTextureLayer = (PFNGLFRAMEBUFFERTEXTURELAYERPROC)load("glFramebufferTextureLayer"); - glad_glMapBufferRange = (PFNGLMAPBUFFERRANGEPROC)load("glMapBufferRange"); - glad_glFlushMappedBufferRange = (PFNGLFLUSHMAPPEDBUFFERRANGEPROC)load("glFlushMappedBufferRange"); - glad_glBindVertexArray = (PFNGLBINDVERTEXARRAYPROC)load("glBindVertexArray"); - glad_glDeleteVertexArrays = (PFNGLDELETEVERTEXARRAYSPROC)load("glDeleteVertexArrays"); - glad_glGenVertexArrays = (PFNGLGENVERTEXARRAYSPROC)load("glGenVertexArrays"); - glad_glIsVertexArray = (PFNGLISVERTEXARRAYPROC)load("glIsVertexArray"); -} -static void load_GL_VERSION_3_1(GLADloadproc load) { - if(!GLAD_GL_VERSION_3_1) return; - glad_glDrawArraysInstanced = (PFNGLDRAWARRAYSINSTANCEDPROC)load("glDrawArraysInstanced"); - glad_glDrawElementsInstanced = (PFNGLDRAWELEMENTSINSTANCEDPROC)load("glDrawElementsInstanced"); - glad_glTexBuffer = (PFNGLTEXBUFFERPROC)load("glTexBuffer"); - glad_glPrimitiveRestartIndex = (PFNGLPRIMITIVERESTARTINDEXPROC)load("glPrimitiveRestartIndex"); - glad_glCopyBufferSubData = (PFNGLCOPYBUFFERSUBDATAPROC)load("glCopyBufferSubData"); - glad_glGetUniformIndices = (PFNGLGETUNIFORMINDICESPROC)load("glGetUniformIndices"); - glad_glGetActiveUniformsiv = (PFNGLGETACTIVEUNIFORMSIVPROC)load("glGetActiveUniformsiv"); - glad_glGetActiveUniformName = (PFNGLGETACTIVEUNIFORMNAMEPROC)load("glGetActiveUniformName"); - glad_glGetUniformBlockIndex = (PFNGLGETUNIFORMBLOCKINDEXPROC)load("glGetUniformBlockIndex"); - glad_glGetActiveUniformBlockiv = (PFNGLGETACTIVEUNIFORMBLOCKIVPROC)load("glGetActiveUniformBlockiv"); - glad_glGetActiveUniformBlockName = (PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC)load("glGetActiveUniformBlockName"); - glad_glUniformBlockBinding = (PFNGLUNIFORMBLOCKBINDINGPROC)load("glUniformBlockBinding"); - glad_glBindBufferRange = (PFNGLBINDBUFFERRANGEPROC)load("glBindBufferRange"); - glad_glBindBufferBase = (PFNGLBINDBUFFERBASEPROC)load("glBindBufferBase"); - glad_glGetIntegeri_v = (PFNGLGETINTEGERI_VPROC)load("glGetIntegeri_v"); -} -static void load_GL_VERSION_3_2(GLADloadproc load) { - if(!GLAD_GL_VERSION_3_2) return; - glad_glDrawElementsBaseVertex = (PFNGLDRAWELEMENTSBASEVERTEXPROC)load("glDrawElementsBaseVertex"); - glad_glDrawRangeElementsBaseVertex = (PFNGLDRAWRANGEELEMENTSBASEVERTEXPROC)load("glDrawRangeElementsBaseVertex"); - glad_glDrawElementsInstancedBaseVertex = (PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC)load("glDrawElementsInstancedBaseVertex"); - glad_glMultiDrawElementsBaseVertex = (PFNGLMULTIDRAWELEMENTSBASEVERTEXPROC)load("glMultiDrawElementsBaseVertex"); - glad_glProvokingVertex = (PFNGLPROVOKINGVERTEXPROC)load("glProvokingVertex"); - glad_glFenceSync = (PFNGLFENCESYNCPROC)load("glFenceSync"); - glad_glIsSync = (PFNGLISSYNCPROC)load("glIsSync"); - glad_glDeleteSync = (PFNGLDELETESYNCPROC)load("glDeleteSync"); - glad_glClientWaitSync = (PFNGLCLIENTWAITSYNCPROC)load("glClientWaitSync"); - glad_glWaitSync = (PFNGLWAITSYNCPROC)load("glWaitSync"); - glad_glGetInteger64v = (PFNGLGETINTEGER64VPROC)load("glGetInteger64v"); - glad_glGetSynciv = (PFNGLGETSYNCIVPROC)load("glGetSynciv"); - glad_glGetInteger64i_v = (PFNGLGETINTEGER64I_VPROC)load("glGetInteger64i_v"); - glad_glGetBufferParameteri64v = (PFNGLGETBUFFERPARAMETERI64VPROC)load("glGetBufferParameteri64v"); - glad_glFramebufferTexture = (PFNGLFRAMEBUFFERTEXTUREPROC)load("glFramebufferTexture"); - glad_glTexImage2DMultisample = (PFNGLTEXIMAGE2DMULTISAMPLEPROC)load("glTexImage2DMultisample"); - glad_glTexImage3DMultisample = (PFNGLTEXIMAGE3DMULTISAMPLEPROC)load("glTexImage3DMultisample"); - glad_glGetMultisamplefv = (PFNGLGETMULTISAMPLEFVPROC)load("glGetMultisamplefv"); - glad_glSampleMaski = (PFNGLSAMPLEMASKIPROC)load("glSampleMaski"); -} -static void load_GL_VERSION_3_3(GLADloadproc load) { - if(!GLAD_GL_VERSION_3_3) return; - glad_glBindFragDataLocationIndexed = (PFNGLBINDFRAGDATALOCATIONINDEXEDPROC)load("glBindFragDataLocationIndexed"); - glad_glGetFragDataIndex = (PFNGLGETFRAGDATAINDEXPROC)load("glGetFragDataIndex"); - glad_glGenSamplers = (PFNGLGENSAMPLERSPROC)load("glGenSamplers"); - glad_glDeleteSamplers = (PFNGLDELETESAMPLERSPROC)load("glDeleteSamplers"); - glad_glIsSampler = (PFNGLISSAMPLERPROC)load("glIsSampler"); - glad_glBindSampler = (PFNGLBINDSAMPLERPROC)load("glBindSampler"); - glad_glSamplerParameteri = (PFNGLSAMPLERPARAMETERIPROC)load("glSamplerParameteri"); - glad_glSamplerParameteriv = (PFNGLSAMPLERPARAMETERIVPROC)load("glSamplerParameteriv"); - glad_glSamplerParameterf = (PFNGLSAMPLERPARAMETERFPROC)load("glSamplerParameterf"); - glad_glSamplerParameterfv = (PFNGLSAMPLERPARAMETERFVPROC)load("glSamplerParameterfv"); - glad_glSamplerParameterIiv = (PFNGLSAMPLERPARAMETERIIVPROC)load("glSamplerParameterIiv"); - glad_glSamplerParameterIuiv = (PFNGLSAMPLERPARAMETERIUIVPROC)load("glSamplerParameterIuiv"); - glad_glGetSamplerParameteriv = (PFNGLGETSAMPLERPARAMETERIVPROC)load("glGetSamplerParameteriv"); - glad_glGetSamplerParameterIiv = (PFNGLGETSAMPLERPARAMETERIIVPROC)load("glGetSamplerParameterIiv"); - glad_glGetSamplerParameterfv = (PFNGLGETSAMPLERPARAMETERFVPROC)load("glGetSamplerParameterfv"); - glad_glGetSamplerParameterIuiv = (PFNGLGETSAMPLERPARAMETERIUIVPROC)load("glGetSamplerParameterIuiv"); - glad_glQueryCounter = (PFNGLQUERYCOUNTERPROC)load("glQueryCounter"); - glad_glGetQueryObjecti64v = (PFNGLGETQUERYOBJECTI64VPROC)load("glGetQueryObjecti64v"); - glad_glGetQueryObjectui64v = (PFNGLGETQUERYOBJECTUI64VPROC)load("glGetQueryObjectui64v"); - glad_glVertexAttribDivisor = (PFNGLVERTEXATTRIBDIVISORPROC)load("glVertexAttribDivisor"); - glad_glVertexAttribP1ui = (PFNGLVERTEXATTRIBP1UIPROC)load("glVertexAttribP1ui"); - glad_glVertexAttribP1uiv = (PFNGLVERTEXATTRIBP1UIVPROC)load("glVertexAttribP1uiv"); - glad_glVertexAttribP2ui = (PFNGLVERTEXATTRIBP2UIPROC)load("glVertexAttribP2ui"); - glad_glVertexAttribP2uiv = (PFNGLVERTEXATTRIBP2UIVPROC)load("glVertexAttribP2uiv"); - glad_glVertexAttribP3ui = (PFNGLVERTEXATTRIBP3UIPROC)load("glVertexAttribP3ui"); - glad_glVertexAttribP3uiv = (PFNGLVERTEXATTRIBP3UIVPROC)load("glVertexAttribP3uiv"); - glad_glVertexAttribP4ui = (PFNGLVERTEXATTRIBP4UIPROC)load("glVertexAttribP4ui"); - glad_glVertexAttribP4uiv = (PFNGLVERTEXATTRIBP4UIVPROC)load("glVertexAttribP4uiv"); - glad_glVertexP2ui = (PFNGLVERTEXP2UIPROC)load("glVertexP2ui"); - glad_glVertexP2uiv = (PFNGLVERTEXP2UIVPROC)load("glVertexP2uiv"); - glad_glVertexP3ui = (PFNGLVERTEXP3UIPROC)load("glVertexP3ui"); - glad_glVertexP3uiv = (PFNGLVERTEXP3UIVPROC)load("glVertexP3uiv"); - glad_glVertexP4ui = (PFNGLVERTEXP4UIPROC)load("glVertexP4ui"); - glad_glVertexP4uiv = (PFNGLVERTEXP4UIVPROC)load("glVertexP4uiv"); - glad_glTexCoordP1ui = (PFNGLTEXCOORDP1UIPROC)load("glTexCoordP1ui"); - glad_glTexCoordP1uiv = (PFNGLTEXCOORDP1UIVPROC)load("glTexCoordP1uiv"); - glad_glTexCoordP2ui = (PFNGLTEXCOORDP2UIPROC)load("glTexCoordP2ui"); - glad_glTexCoordP2uiv = (PFNGLTEXCOORDP2UIVPROC)load("glTexCoordP2uiv"); - glad_glTexCoordP3ui = (PFNGLTEXCOORDP3UIPROC)load("glTexCoordP3ui"); - glad_glTexCoordP3uiv = (PFNGLTEXCOORDP3UIVPROC)load("glTexCoordP3uiv"); - glad_glTexCoordP4ui = (PFNGLTEXCOORDP4UIPROC)load("glTexCoordP4ui"); - glad_glTexCoordP4uiv = (PFNGLTEXCOORDP4UIVPROC)load("glTexCoordP4uiv"); - glad_glMultiTexCoordP1ui = (PFNGLMULTITEXCOORDP1UIPROC)load("glMultiTexCoordP1ui"); - glad_glMultiTexCoordP1uiv = (PFNGLMULTITEXCOORDP1UIVPROC)load("glMultiTexCoordP1uiv"); - glad_glMultiTexCoordP2ui = (PFNGLMULTITEXCOORDP2UIPROC)load("glMultiTexCoordP2ui"); - glad_glMultiTexCoordP2uiv = (PFNGLMULTITEXCOORDP2UIVPROC)load("glMultiTexCoordP2uiv"); - glad_glMultiTexCoordP3ui = (PFNGLMULTITEXCOORDP3UIPROC)load("glMultiTexCoordP3ui"); - glad_glMultiTexCoordP3uiv = (PFNGLMULTITEXCOORDP3UIVPROC)load("glMultiTexCoordP3uiv"); - glad_glMultiTexCoordP4ui = (PFNGLMULTITEXCOORDP4UIPROC)load("glMultiTexCoordP4ui"); - glad_glMultiTexCoordP4uiv = (PFNGLMULTITEXCOORDP4UIVPROC)load("glMultiTexCoordP4uiv"); - glad_glNormalP3ui = (PFNGLNORMALP3UIPROC)load("glNormalP3ui"); - glad_glNormalP3uiv = (PFNGLNORMALP3UIVPROC)load("glNormalP3uiv"); - glad_glColorP3ui = (PFNGLCOLORP3UIPROC)load("glColorP3ui"); - glad_glColorP3uiv = (PFNGLCOLORP3UIVPROC)load("glColorP3uiv"); - glad_glColorP4ui = (PFNGLCOLORP4UIPROC)load("glColorP4ui"); - glad_glColorP4uiv = (PFNGLCOLORP4UIVPROC)load("glColorP4uiv"); - glad_glSecondaryColorP3ui = (PFNGLSECONDARYCOLORP3UIPROC)load("glSecondaryColorP3ui"); - glad_glSecondaryColorP3uiv = (PFNGLSECONDARYCOLORP3UIVPROC)load("glSecondaryColorP3uiv"); -} -static void load_GL_VERSION_4_0(GLADloadproc load) { - if(!GLAD_GL_VERSION_4_0) return; - glad_glMinSampleShading = (PFNGLMINSAMPLESHADINGPROC)load("glMinSampleShading"); - glad_glBlendEquationi = (PFNGLBLENDEQUATIONIPROC)load("glBlendEquationi"); - glad_glBlendEquationSeparatei = (PFNGLBLENDEQUATIONSEPARATEIPROC)load("glBlendEquationSeparatei"); - glad_glBlendFunci = (PFNGLBLENDFUNCIPROC)load("glBlendFunci"); - glad_glBlendFuncSeparatei = (PFNGLBLENDFUNCSEPARATEIPROC)load("glBlendFuncSeparatei"); - glad_glDrawArraysIndirect = (PFNGLDRAWARRAYSINDIRECTPROC)load("glDrawArraysIndirect"); - glad_glDrawElementsIndirect = (PFNGLDRAWELEMENTSINDIRECTPROC)load("glDrawElementsIndirect"); - glad_glUniform1d = (PFNGLUNIFORM1DPROC)load("glUniform1d"); - glad_glUniform2d = (PFNGLUNIFORM2DPROC)load("glUniform2d"); - glad_glUniform3d = (PFNGLUNIFORM3DPROC)load("glUniform3d"); - glad_glUniform4d = (PFNGLUNIFORM4DPROC)load("glUniform4d"); - glad_glUniform1dv = (PFNGLUNIFORM1DVPROC)load("glUniform1dv"); - glad_glUniform2dv = (PFNGLUNIFORM2DVPROC)load("glUniform2dv"); - glad_glUniform3dv = (PFNGLUNIFORM3DVPROC)load("glUniform3dv"); - glad_glUniform4dv = (PFNGLUNIFORM4DVPROC)load("glUniform4dv"); - glad_glUniformMatrix2dv = (PFNGLUNIFORMMATRIX2DVPROC)load("glUniformMatrix2dv"); - glad_glUniformMatrix3dv = (PFNGLUNIFORMMATRIX3DVPROC)load("glUniformMatrix3dv"); - glad_glUniformMatrix4dv = (PFNGLUNIFORMMATRIX4DVPROC)load("glUniformMatrix4dv"); - glad_glUniformMatrix2x3dv = (PFNGLUNIFORMMATRIX2X3DVPROC)load("glUniformMatrix2x3dv"); - glad_glUniformMatrix2x4dv = (PFNGLUNIFORMMATRIX2X4DVPROC)load("glUniformMatrix2x4dv"); - glad_glUniformMatrix3x2dv = (PFNGLUNIFORMMATRIX3X2DVPROC)load("glUniformMatrix3x2dv"); - glad_glUniformMatrix3x4dv = (PFNGLUNIFORMMATRIX3X4DVPROC)load("glUniformMatrix3x4dv"); - glad_glUniformMatrix4x2dv = (PFNGLUNIFORMMATRIX4X2DVPROC)load("glUniformMatrix4x2dv"); - glad_glUniformMatrix4x3dv = (PFNGLUNIFORMMATRIX4X3DVPROC)load("glUniformMatrix4x3dv"); - glad_glGetUniformdv = (PFNGLGETUNIFORMDVPROC)load("glGetUniformdv"); - glad_glGetSubroutineUniformLocation = (PFNGLGETSUBROUTINEUNIFORMLOCATIONPROC)load("glGetSubroutineUniformLocation"); - glad_glGetSubroutineIndex = (PFNGLGETSUBROUTINEINDEXPROC)load("glGetSubroutineIndex"); - glad_glGetActiveSubroutineUniformiv = (PFNGLGETACTIVESUBROUTINEUNIFORMIVPROC)load("glGetActiveSubroutineUniformiv"); - glad_glGetActiveSubroutineUniformName = (PFNGLGETACTIVESUBROUTINEUNIFORMNAMEPROC)load("glGetActiveSubroutineUniformName"); - glad_glGetActiveSubroutineName = (PFNGLGETACTIVESUBROUTINENAMEPROC)load("glGetActiveSubroutineName"); - glad_glUniformSubroutinesuiv = (PFNGLUNIFORMSUBROUTINESUIVPROC)load("glUniformSubroutinesuiv"); - glad_glGetUniformSubroutineuiv = (PFNGLGETUNIFORMSUBROUTINEUIVPROC)load("glGetUniformSubroutineuiv"); - glad_glGetProgramStageiv = (PFNGLGETPROGRAMSTAGEIVPROC)load("glGetProgramStageiv"); - glad_glPatchParameteri = (PFNGLPATCHPARAMETERIPROC)load("glPatchParameteri"); - glad_glPatchParameterfv = (PFNGLPATCHPARAMETERFVPROC)load("glPatchParameterfv"); - glad_glBindTransformFeedback = (PFNGLBINDTRANSFORMFEEDBACKPROC)load("glBindTransformFeedback"); - glad_glDeleteTransformFeedbacks = (PFNGLDELETETRANSFORMFEEDBACKSPROC)load("glDeleteTransformFeedbacks"); - glad_glGenTransformFeedbacks = (PFNGLGENTRANSFORMFEEDBACKSPROC)load("glGenTransformFeedbacks"); - glad_glIsTransformFeedback = (PFNGLISTRANSFORMFEEDBACKPROC)load("glIsTransformFeedback"); - glad_glPauseTransformFeedback = (PFNGLPAUSETRANSFORMFEEDBACKPROC)load("glPauseTransformFeedback"); - glad_glResumeTransformFeedback = (PFNGLRESUMETRANSFORMFEEDBACKPROC)load("glResumeTransformFeedback"); - glad_glDrawTransformFeedback = (PFNGLDRAWTRANSFORMFEEDBACKPROC)load("glDrawTransformFeedback"); - glad_glDrawTransformFeedbackStream = (PFNGLDRAWTRANSFORMFEEDBACKSTREAMPROC)load("glDrawTransformFeedbackStream"); - glad_glBeginQueryIndexed = (PFNGLBEGINQUERYINDEXEDPROC)load("glBeginQueryIndexed"); - glad_glEndQueryIndexed = (PFNGLENDQUERYINDEXEDPROC)load("glEndQueryIndexed"); - glad_glGetQueryIndexediv = (PFNGLGETQUERYINDEXEDIVPROC)load("glGetQueryIndexediv"); -} -static void load_GL_VERSION_4_1(GLADloadproc load) { - if(!GLAD_GL_VERSION_4_1) return; - glad_glReleaseShaderCompiler = (PFNGLRELEASESHADERCOMPILERPROC)load("glReleaseShaderCompiler"); - glad_glShaderBinary = (PFNGLSHADERBINARYPROC)load("glShaderBinary"); - glad_glGetShaderPrecisionFormat = (PFNGLGETSHADERPRECISIONFORMATPROC)load("glGetShaderPrecisionFormat"); - glad_glDepthRangef = (PFNGLDEPTHRANGEFPROC)load("glDepthRangef"); - glad_glClearDepthf = (PFNGLCLEARDEPTHFPROC)load("glClearDepthf"); - glad_glGetProgramBinary = (PFNGLGETPROGRAMBINARYPROC)load("glGetProgramBinary"); - glad_glProgramBinary = (PFNGLPROGRAMBINARYPROC)load("glProgramBinary"); - glad_glProgramParameteri = (PFNGLPROGRAMPARAMETERIPROC)load("glProgramParameteri"); - glad_glUseProgramStages = (PFNGLUSEPROGRAMSTAGESPROC)load("glUseProgramStages"); - glad_glActiveShaderProgram = (PFNGLACTIVESHADERPROGRAMPROC)load("glActiveShaderProgram"); - glad_glCreateShaderProgramv = (PFNGLCREATESHADERPROGRAMVPROC)load("glCreateShaderProgramv"); - glad_glBindProgramPipeline = (PFNGLBINDPROGRAMPIPELINEPROC)load("glBindProgramPipeline"); - glad_glDeleteProgramPipelines = (PFNGLDELETEPROGRAMPIPELINESPROC)load("glDeleteProgramPipelines"); - glad_glGenProgramPipelines = (PFNGLGENPROGRAMPIPELINESPROC)load("glGenProgramPipelines"); - glad_glIsProgramPipeline = (PFNGLISPROGRAMPIPELINEPROC)load("glIsProgramPipeline"); - glad_glGetProgramPipelineiv = (PFNGLGETPROGRAMPIPELINEIVPROC)load("glGetProgramPipelineiv"); - glad_glProgramParameteri = (PFNGLPROGRAMPARAMETERIPROC)load("glProgramParameteri"); - glad_glProgramUniform1i = (PFNGLPROGRAMUNIFORM1IPROC)load("glProgramUniform1i"); - glad_glProgramUniform1iv = (PFNGLPROGRAMUNIFORM1IVPROC)load("glProgramUniform1iv"); - glad_glProgramUniform1f = (PFNGLPROGRAMUNIFORM1FPROC)load("glProgramUniform1f"); - glad_glProgramUniform1fv = (PFNGLPROGRAMUNIFORM1FVPROC)load("glProgramUniform1fv"); - glad_glProgramUniform1d = (PFNGLPROGRAMUNIFORM1DPROC)load("glProgramUniform1d"); - glad_glProgramUniform1dv = (PFNGLPROGRAMUNIFORM1DVPROC)load("glProgramUniform1dv"); - glad_glProgramUniform1ui = (PFNGLPROGRAMUNIFORM1UIPROC)load("glProgramUniform1ui"); - glad_glProgramUniform1uiv = (PFNGLPROGRAMUNIFORM1UIVPROC)load("glProgramUniform1uiv"); - glad_glProgramUniform2i = (PFNGLPROGRAMUNIFORM2IPROC)load("glProgramUniform2i"); - glad_glProgramUniform2iv = (PFNGLPROGRAMUNIFORM2IVPROC)load("glProgramUniform2iv"); - glad_glProgramUniform2f = (PFNGLPROGRAMUNIFORM2FPROC)load("glProgramUniform2f"); - glad_glProgramUniform2fv = (PFNGLPROGRAMUNIFORM2FVPROC)load("glProgramUniform2fv"); - glad_glProgramUniform2d = (PFNGLPROGRAMUNIFORM2DPROC)load("glProgramUniform2d"); - glad_glProgramUniform2dv = (PFNGLPROGRAMUNIFORM2DVPROC)load("glProgramUniform2dv"); - glad_glProgramUniform2ui = (PFNGLPROGRAMUNIFORM2UIPROC)load("glProgramUniform2ui"); - glad_glProgramUniform2uiv = (PFNGLPROGRAMUNIFORM2UIVPROC)load("glProgramUniform2uiv"); - glad_glProgramUniform3i = (PFNGLPROGRAMUNIFORM3IPROC)load("glProgramUniform3i"); - glad_glProgramUniform3iv = (PFNGLPROGRAMUNIFORM3IVPROC)load("glProgramUniform3iv"); - glad_glProgramUniform3f = (PFNGLPROGRAMUNIFORM3FPROC)load("glProgramUniform3f"); - glad_glProgramUniform3fv = (PFNGLPROGRAMUNIFORM3FVPROC)load("glProgramUniform3fv"); - glad_glProgramUniform3d = (PFNGLPROGRAMUNIFORM3DPROC)load("glProgramUniform3d"); - glad_glProgramUniform3dv = (PFNGLPROGRAMUNIFORM3DVPROC)load("glProgramUniform3dv"); - glad_glProgramUniform3ui = (PFNGLPROGRAMUNIFORM3UIPROC)load("glProgramUniform3ui"); - glad_glProgramUniform3uiv = (PFNGLPROGRAMUNIFORM3UIVPROC)load("glProgramUniform3uiv"); - glad_glProgramUniform4i = (PFNGLPROGRAMUNIFORM4IPROC)load("glProgramUniform4i"); - glad_glProgramUniform4iv = (PFNGLPROGRAMUNIFORM4IVPROC)load("glProgramUniform4iv"); - glad_glProgramUniform4f = (PFNGLPROGRAMUNIFORM4FPROC)load("glProgramUniform4f"); - glad_glProgramUniform4fv = (PFNGLPROGRAMUNIFORM4FVPROC)load("glProgramUniform4fv"); - glad_glProgramUniform4d = (PFNGLPROGRAMUNIFORM4DPROC)load("glProgramUniform4d"); - glad_glProgramUniform4dv = (PFNGLPROGRAMUNIFORM4DVPROC)load("glProgramUniform4dv"); - glad_glProgramUniform4ui = (PFNGLPROGRAMUNIFORM4UIPROC)load("glProgramUniform4ui"); - glad_glProgramUniform4uiv = (PFNGLPROGRAMUNIFORM4UIVPROC)load("glProgramUniform4uiv"); - glad_glProgramUniformMatrix2fv = (PFNGLPROGRAMUNIFORMMATRIX2FVPROC)load("glProgramUniformMatrix2fv"); - glad_glProgramUniformMatrix3fv = (PFNGLPROGRAMUNIFORMMATRIX3FVPROC)load("glProgramUniformMatrix3fv"); - glad_glProgramUniformMatrix4fv = (PFNGLPROGRAMUNIFORMMATRIX4FVPROC)load("glProgramUniformMatrix4fv"); - glad_glProgramUniformMatrix2dv = (PFNGLPROGRAMUNIFORMMATRIX2DVPROC)load("glProgramUniformMatrix2dv"); - glad_glProgramUniformMatrix3dv = (PFNGLPROGRAMUNIFORMMATRIX3DVPROC)load("glProgramUniformMatrix3dv"); - glad_glProgramUniformMatrix4dv = (PFNGLPROGRAMUNIFORMMATRIX4DVPROC)load("glProgramUniformMatrix4dv"); - glad_glProgramUniformMatrix2x3fv = (PFNGLPROGRAMUNIFORMMATRIX2X3FVPROC)load("glProgramUniformMatrix2x3fv"); - glad_glProgramUniformMatrix3x2fv = (PFNGLPROGRAMUNIFORMMATRIX3X2FVPROC)load("glProgramUniformMatrix3x2fv"); - glad_glProgramUniformMatrix2x4fv = (PFNGLPROGRAMUNIFORMMATRIX2X4FVPROC)load("glProgramUniformMatrix2x4fv"); - glad_glProgramUniformMatrix4x2fv = (PFNGLPROGRAMUNIFORMMATRIX4X2FVPROC)load("glProgramUniformMatrix4x2fv"); - glad_glProgramUniformMatrix3x4fv = (PFNGLPROGRAMUNIFORMMATRIX3X4FVPROC)load("glProgramUniformMatrix3x4fv"); - glad_glProgramUniformMatrix4x3fv = (PFNGLPROGRAMUNIFORMMATRIX4X3FVPROC)load("glProgramUniformMatrix4x3fv"); - glad_glProgramUniformMatrix2x3dv = (PFNGLPROGRAMUNIFORMMATRIX2X3DVPROC)load("glProgramUniformMatrix2x3dv"); - glad_glProgramUniformMatrix3x2dv = (PFNGLPROGRAMUNIFORMMATRIX3X2DVPROC)load("glProgramUniformMatrix3x2dv"); - glad_glProgramUniformMatrix2x4dv = (PFNGLPROGRAMUNIFORMMATRIX2X4DVPROC)load("glProgramUniformMatrix2x4dv"); - glad_glProgramUniformMatrix4x2dv = (PFNGLPROGRAMUNIFORMMATRIX4X2DVPROC)load("glProgramUniformMatrix4x2dv"); - glad_glProgramUniformMatrix3x4dv = (PFNGLPROGRAMUNIFORMMATRIX3X4DVPROC)load("glProgramUniformMatrix3x4dv"); - glad_glProgramUniformMatrix4x3dv = (PFNGLPROGRAMUNIFORMMATRIX4X3DVPROC)load("glProgramUniformMatrix4x3dv"); - glad_glValidateProgramPipeline = (PFNGLVALIDATEPROGRAMPIPELINEPROC)load("glValidateProgramPipeline"); - glad_glGetProgramPipelineInfoLog = (PFNGLGETPROGRAMPIPELINEINFOLOGPROC)load("glGetProgramPipelineInfoLog"); - glad_glVertexAttribL1d = (PFNGLVERTEXATTRIBL1DPROC)load("glVertexAttribL1d"); - glad_glVertexAttribL2d = (PFNGLVERTEXATTRIBL2DPROC)load("glVertexAttribL2d"); - glad_glVertexAttribL3d = (PFNGLVERTEXATTRIBL3DPROC)load("glVertexAttribL3d"); - glad_glVertexAttribL4d = (PFNGLVERTEXATTRIBL4DPROC)load("glVertexAttribL4d"); - glad_glVertexAttribL1dv = (PFNGLVERTEXATTRIBL1DVPROC)load("glVertexAttribL1dv"); - glad_glVertexAttribL2dv = (PFNGLVERTEXATTRIBL2DVPROC)load("glVertexAttribL2dv"); - glad_glVertexAttribL3dv = (PFNGLVERTEXATTRIBL3DVPROC)load("glVertexAttribL3dv"); - glad_glVertexAttribL4dv = (PFNGLVERTEXATTRIBL4DVPROC)load("glVertexAttribL4dv"); - glad_glVertexAttribLPointer = (PFNGLVERTEXATTRIBLPOINTERPROC)load("glVertexAttribLPointer"); - glad_glGetVertexAttribLdv = (PFNGLGETVERTEXATTRIBLDVPROC)load("glGetVertexAttribLdv"); - glad_glViewportArrayv = (PFNGLVIEWPORTARRAYVPROC)load("glViewportArrayv"); - glad_glViewportIndexedf = (PFNGLVIEWPORTINDEXEDFPROC)load("glViewportIndexedf"); - glad_glViewportIndexedfv = (PFNGLVIEWPORTINDEXEDFVPROC)load("glViewportIndexedfv"); - glad_glScissorArrayv = (PFNGLSCISSORARRAYVPROC)load("glScissorArrayv"); - glad_glScissorIndexed = (PFNGLSCISSORINDEXEDPROC)load("glScissorIndexed"); - glad_glScissorIndexedv = (PFNGLSCISSORINDEXEDVPROC)load("glScissorIndexedv"); - glad_glDepthRangeArrayv = (PFNGLDEPTHRANGEARRAYVPROC)load("glDepthRangeArrayv"); - glad_glDepthRangeIndexed = (PFNGLDEPTHRANGEINDEXEDPROC)load("glDepthRangeIndexed"); - glad_glGetFloati_v = (PFNGLGETFLOATI_VPROC)load("glGetFloati_v"); - glad_glGetDoublei_v = (PFNGLGETDOUBLEI_VPROC)load("glGetDoublei_v"); -} -static int find_extensionsGL(void) { - if (!get_exts()) return 0; - (void)&has_ext; - free_exts(); - return 1; -} - -static void find_coreGL(void) { - - /* Thank you @elmindreda - * https://github.com/elmindreda/greg/blob/master/templates/greg.c.in#L176 - * https://github.com/glfw/glfw/blob/master/src/context.c#L36 - */ - int i, major, minor; - - const char* version; - const char* prefixes[] = { - "OpenGL ES-CM ", - "OpenGL ES-CL ", - "OpenGL ES ", - NULL - }; - - version = (const char*) glGetString(GL_VERSION); - if (!version) return; - - for (i = 0; prefixes[i]; i++) { - const size_t length = strlen(prefixes[i]); - if (strncmp(version, prefixes[i], length) == 0) { - version += length; - break; - } - } - -/* PR #18 */ -#ifdef _MSC_VER - sscanf_s(version, "%d.%d", &major, &minor); -#else - sscanf(version, "%d.%d", &major, &minor); -#endif - - GLVersion.major = major; GLVersion.minor = minor; - max_loaded_major = major; max_loaded_minor = minor; - GLAD_GL_VERSION_1_0 = (major == 1 && minor >= 0) || major > 1; - GLAD_GL_VERSION_1_1 = (major == 1 && minor >= 1) || major > 1; - GLAD_GL_VERSION_1_2 = (major == 1 && minor >= 2) || major > 1; - GLAD_GL_VERSION_1_3 = (major == 1 && minor >= 3) || major > 1; - GLAD_GL_VERSION_1_4 = (major == 1 && minor >= 4) || major > 1; - GLAD_GL_VERSION_1_5 = (major == 1 && minor >= 5) || major > 1; - GLAD_GL_VERSION_2_0 = (major == 2 && minor >= 0) || major > 2; - GLAD_GL_VERSION_2_1 = (major == 2 && minor >= 1) || major > 2; - GLAD_GL_VERSION_3_0 = (major == 3 && minor >= 0) || major > 3; - GLAD_GL_VERSION_3_1 = (major == 3 && minor >= 1) || major > 3; - GLAD_GL_VERSION_3_2 = (major == 3 && minor >= 2) || major > 3; - GLAD_GL_VERSION_3_3 = (major == 3 && minor >= 3) || major > 3; - GLAD_GL_VERSION_4_0 = (major == 4 && minor >= 0) || major > 4; - GLAD_GL_VERSION_4_1 = (major == 4 && minor >= 1) || major > 4; - if (GLVersion.major > 4 || (GLVersion.major >= 4 && GLVersion.minor >= 1)) { - max_loaded_major = 4; - max_loaded_minor = 1; - } -} - -int gladLoadGLLoader(GLADloadproc load) { - GLVersion.major = 0; GLVersion.minor = 0; - glGetString = (PFNGLGETSTRINGPROC)load("glGetString"); - if(glGetString == NULL) return 0; - if(glGetString(GL_VERSION) == NULL) return 0; - find_coreGL(); - load_GL_VERSION_1_0(load); - load_GL_VERSION_1_1(load); - load_GL_VERSION_1_2(load); - load_GL_VERSION_1_3(load); - load_GL_VERSION_1_4(load); - load_GL_VERSION_1_5(load); - load_GL_VERSION_2_0(load); - load_GL_VERSION_2_1(load); - load_GL_VERSION_3_0(load); - load_GL_VERSION_3_1(load); - load_GL_VERSION_3_2(load); - load_GL_VERSION_3_3(load); - load_GL_VERSION_4_0(load); - load_GL_VERSION_4_1(load); - - if (!find_extensionsGL()) return 0; - return GLVersion.major != 0 || GLVersion.minor != 0; -} - diff --git a/extern/sokol/LICENSE b/extern/sokol/LICENSE new file mode 100644 index 0000000..efdc02e --- /dev/null +++ b/extern/sokol/LICENSE @@ -0,0 +1,22 @@ +zlib/libpng license + +Copyright (c) 2018 Andre Weissflog + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the +use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software in a + product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not + be misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. diff --git a/extern/sokol/README.md b/extern/sokol/README.md new file mode 100644 index 0000000..395bc33 --- /dev/null +++ b/extern/sokol/README.md @@ -0,0 +1,62 @@ +# Vendored sokol headers + +Upstream: +Pinned commit: `b210caee10d6834081cb46c617c3ff715a92be26` +License: zlib (see `LICENSE`) + +These are the only sokol headers render3d actually `#include`s: + +| File | Upstream path | Used for | +| ----------------- | ------------------------- | ----------------------------------------- | +| `sokol_gfx.h` | `sokol_gfx.h` | Graphics backend (D3D11 / Metal / GL 4.3) | +| `sokol_app.h` | `sokol_app.h` | Windowing and input | +| `sokol_glue.h` | `sokol_glue.h` | Bridges sokol_app and sokol_gfx | +| `sokol_log.h` | `sokol_log.h` | Default logger callback | +| `sokol_imgui.h` | `util/sokol_imgui.h` | Dear ImGui renderer/event handler | + +## Local patches + +`sokol_gfx.h` carries a local patch (search the file for `Local patch:`) wiring +`sg_push_debug_group` / `sg_pop_debug_group` on the D3D11 backend to +`ID3DUserDefinedAnnotation::BeginEvent` / `EndEvent`. Upstream sokol_gfx +silently no-ops these on every backend except Metal, so D3D11 captures in +RenderDoc / PIX / Nsight had no hierarchical event regions. The patch: + +- includes ``, +- adds `ID3DUserDefinedAnnotation* annotation` to `_sg_d3d11_backend_t`, +- QueryInterfaces it in `_sg_d3d11_setup_backend`, releases in + `_sg_d3d11_discard_backend`, +- implements `_sg_d3d11_push_debug_group` / `_sg_d3d11_pop_debug_group` + (UTF-8 -> UTF-16 conversion, stack buffer, 256 char cap), +- routes the public `_sg_push_debug_group` / `_sg_pop_debug_group` + dispatcher to them under `SOKOL_D3D11`. + +`sokol_app.h` carries a local patch (search the file for `Local patch:`) in +`_sapp_win32_create_window` that changes how `desc.width` / `desc.height` +are interpreted on Win32 when `desc.high_dpi == true`. Upstream always +multiplies the requested size by the monitor's `window_scale`, treating +`desc.width` as 100%-DPI logical pixels — so callers that want a specific +framebuffer size on a high-DPI display have to pre-divide by the DPI scale +themselves. The patch makes the high-DPI path interpret `desc.width` / +`desc.height` as physical/framebuffer pixels directly; the `high_dpi=false` +branch keeps upstream behavior so DPI-unaware apps are unaffected. + +When bumping either header, re-apply the patch and rebuild. Each patch is +small enough to re-do by hand each time; if either grows, consider +upstreaming. + +## Bumping + +1. Pull the new headers from upstream at the desired commit: + + ``` + git clone --depth 1 https://github.com/floooh/sokol /tmp/sokol-src + (cd /tmp/sokol-src && git fetch --depth 1 origin && git checkout ) + cp /tmp/sokol-src/sokol_{gfx,app,glue,log}.h extern/sokol/ + cp /tmp/sokol-src/util/sokol_imgui.h extern/sokol/ + cp /tmp/sokol-src/LICENSE extern/sokol/ + ``` + +2. Update the pinned commit at the top of this file. +3. Rebuild + run the smoke test on all three OSes. +4. Commit as `deps: bump sokol to ()`. diff --git a/extern/sokol/sokol_app.h b/extern/sokol/sokol_app.h new file mode 100644 index 0000000..37dcc38 --- /dev/null +++ b/extern/sokol/sokol_app.h @@ -0,0 +1,14500 @@ +#if defined(SOKOL_IMPL) && !defined(SOKOL_APP_IMPL) +#define SOKOL_APP_IMPL +#endif +#ifndef SOKOL_APP_INCLUDED +/* + sokol_app.h -- cross-platform application wrapper + + Project URL: https://github.com/floooh/sokol + + Do this: + #define SOKOL_IMPL or + #define SOKOL_APP_IMPL + before you include this file in *one* C or C++ file to create the + implementation. + + In the same place define one of the following to select the 3D-API + which should be initialized by sokol_app.h (this must also match + the backend selected for sokol_gfx.h if both are used in the same + project): + + #define SOKOL_GLCORE + #define SOKOL_GLES3 + #define SOKOL_D3D11 + #define SOKOL_METAL + #define SOKOL_WGPU + #define SOKOL_VULKAN + #define SOKOL_NOAPI + + Optionally provide the following defines with your own implementations: + + SOKOL_ASSERT(c) - your own assert macro (default: assert(c)) + SOKOL_UNREACHABLE() - a guard macro for unreachable code (default: assert(false)) + SOKOL_WIN32_FORCE_MAIN - define this on Win32 to add a main() entry point + SOKOL_WIN32_FORCE_WINMAIN - define this on Win32 to add a WinMain() entry point (enabled by default unless + SOKOL_WIN32_FORCE_MAIN or SOKOL_NO_ENTRY is defined) + SOKOL_NO_ENTRY - define this if sokol_app.h shouldn't "hijack" the main() function + SOKOL_APP_API_DECL - public function declaration prefix (default: extern) + SOKOL_API_DECL - same as SOKOL_APP_API_DECL + SOKOL_API_IMPL - public function implementation prefix (default: -) + + Optionally define the following to force debug checks and validations + even in release mode: + + SOKOL_DEBUG - by default this is defined if NDEBUG is not defined + + If sokol_app.h is compiled as a DLL, define the following before + including the declaration or implementation: + + SOKOL_DLL + + On Windows, SOKOL_DLL will define SOKOL_APP_API_DECL as __declspec(dllexport) + or __declspec(dllimport) as needed. + + if SOKOL_WIN32_FORCE_MAIN and SOKOL_WIN32_FORCE_WINMAIN are both defined, + it is up to the developer to define the desired subsystem. + + On Linux, SOKOL_GLCORE can use either GLX or EGL. + GLX is default, set SOKOL_FORCE_EGL to override. + + For example code, see https://github.com/floooh/sokol-samples/tree/master/sapp + + Portions of the Windows and Linux GL initialization, event-, icon- etc... code + have been taken from GLFW (http://www.glfw.org/). + + iOS onscreen keyboard support 'inspired' by libgdx. + + Link with the following system libraries: + + - on macOS: + - all backends: AppKit, QuartzCore + - with SOKOL_METAL: Metal + - with SOKOL_GLCORE: OpenGL + - with SOKOL_WGPU: a WebGPU implementation library (tested with webgpu_dawn) + - on iOS: + - all backends: Foundation, UIKit, QuartzCore + - with SOKOL_METAL: Metal + - with SOKOL_GLES3: OpenGLES, GLKit + - on Linux: + - all backends: X11, Xi, Xcursor, dl, pthread, m + - with SOKOL_GLCORE: GL + - with SOKOL_GLES3: GLESv2 + - with SOKOL_WGPU: a WebGPU implementation library (tested with webgpu_dawn) + - with SOKOL_VULKAN: vulkan + - with EGL: EGL + - on Android: GLESv3, EGL, log, android + - on Windows: + - with MSVC or Clang: library dependencies are defined via `#pragma comment` + - with SOKOL_WGPU: a WebGPU implementation library (tested with webgpu_dawn) + - with SOKOL_VULKAN: + - install the Vulkan SDK + - set a header search path to $VULKAN_SDK/Include + - set a library search path to $VULKAN_SDK/Lib + - link with vulkan-1.lib + - with MINGW/MSYS2 gcc: + - compile with '-mwin32' so that _WIN32 is defined + - link with the following libs: -lkernel32 -luser32 -lshell32 + - additionally with the GL backend: -lgdi32 + - additionally with the D3D11 backend: -ld3d11 -ldxgi + + On Linux, you also need to use the -pthread compiler and linker option, otherwise weird + things will happen, see here for details: https://github.com/floooh/sokol/issues/376 + + For Linux+Vulkan install the following packages (or equivalents): + - libvulkan-dev + - vulkan-validationlayers + - vulkan-tools + + On macOS and iOS, the implementation must be compiled as Objective-C. + + On Emscripten: + - for WebGL2: add the linker option `-s USE_WEBGL2=1` + - for WebGPU: compile and link with `--use-port=emdawnwebgpu` + (for more exotic situations read: https://dawn.googlesource.com/dawn/+/refs/heads/main/src/emdawnwebgpu/pkg/README.md) + + FEATURE OVERVIEW + ================ + sokol_app.h provides a minimalistic cross-platform API which + implements the 'application-wrapper' parts of a 3D application: + + - a common application entry function + - creates a window and 3D-API context/device with a swapchain + surface, depth-stencil-buffer surface and optionally MSAA surface + - makes the rendered frame visible + - provides keyboard-, mouse- and low-level touch-events + - platforms: MacOS, iOS, HTML5, Win32, Linux/RaspberryPi, Android + - 3D-APIs: Metal, D3D11, GL4.1, GL4.3, GLES3, WebGL2, WebGPU, NOAPI + + FEATURE/PLATFORM MATRIX + ======================= + | Windows | macOS | Linux | iOS | Android | HTML5 + --------------------+---------+-------+-------+-------+---------+-------- + gl 4.x | YES | YES | YES | --- | --- | --- + gles3/webgl2 | --- | --- | YES(2)| YES | YES | YES + metal | --- | YES | --- | YES | --- | --- + d3d11 | YES | --- | --- | --- | --- | --- + webgpu | YES(4) | YES(4)| YES(4)| NO | NO | YES + noapi | YES | TODO | TODO | --- | TODO | --- + KEY_DOWN | YES | YES | YES | SOME | TODO | YES + KEY_UP | YES | YES | YES | SOME | TODO | YES + CHAR | YES | YES | YES | YES | TODO | YES + MOUSE_DOWN | YES | YES | YES | --- | --- | YES + MOUSE_UP | YES | YES | YES | --- | --- | YES + MOUSE_SCROLL | YES | YES | YES | --- | --- | YES + MOUSE_MOVE | YES | YES | YES | --- | --- | YES + MOUSE_ENTER | YES | YES | YES | --- | --- | YES + MOUSE_LEAVE | YES | YES | YES | --- | --- | YES + TOUCHES_BEGAN | --- | --- | --- | YES | YES | YES + TOUCHES_MOVED | --- | --- | --- | YES | YES | YES + TOUCHES_ENDED | --- | --- | --- | YES | YES | YES + TOUCHES_CANCELLED | --- | --- | --- | YES | YES | YES + RESIZED | YES | YES | YES | YES | YES | YES + ICONIFIED | YES | YES | YES | --- | --- | --- + RESTORED | YES | YES | YES | --- | --- | --- + FOCUSED | YES | YES | YES | --- | --- | YES + UNFOCUSED | YES | YES | YES | --- | --- | YES + SUSPENDED | --- | --- | --- | YES | YES | TODO + RESUMED | --- | --- | --- | YES | YES | TODO + QUIT_REQUESTED | YES | YES | YES | --- | --- | YES + IME | TODO | TODO? | TODO | ??? | TODO | ??? + key repeat flag | YES | YES | YES | --- | --- | YES + windowed | YES | YES | YES | --- | --- | YES + fullscreen | YES | YES | YES | YES | YES | YES(3) + mouse hide | YES | YES | YES | --- | --- | YES + mouse lock | YES | YES | YES | --- | --- | YES + set cursor type | YES | YES | YES | --- | --- | YES + screen keyboard | --- | --- | --- | YES | TODO | YES + swap interval | YES | YES | YES | YES | TODO | YES + high-dpi | YES | YES | TODO | YES | YES | YES + clipboard | YES | YES | YES | --- | --- | YES + MSAA | YES | YES | YES | YES | YES | YES + drag'n'drop | YES | YES | YES | --- | --- | YES + window icon | YES | YES(1)| YES | --- | --- | YES + + (1) macOS has no regular window icons, instead the dock icon is changed + (2) supported with EGL only (not GLX) + (3) fullscreen in the browser not supported on iphones + (4) WebGPU on native desktop platforms should be considered experimental + and mainly useful for debugging and benchmarking + + STEP BY STEP + ============ + --- Add a sokol_main() function to your code which returns a sapp_desc structure + with initialization parameters and callback function pointers. This + function is called very early, usually at the start of the + platform's entry function (e.g. main or WinMain). You should do as + little as possible here, since the rest of your code might be called + from another thread (this depends on the platform): + + sapp_desc sokol_main(int argc, char* argv[]) { + return (sapp_desc) { + .width = 640, + .height = 480, + .init_cb = my_init_func, + .frame_cb = my_frame_func, + .cleanup_cb = my_cleanup_func, + .event_cb = my_event_func, + ... + }; + } + + To get any logging output in case of errors you need to provide a log + callback. The easiest way is via sokol_log.h: + + #include "sokol_log.h" + + sapp_desc sokol_main(int argc, char* argv[]) { + return (sapp_desc) { + ... + .logger.func = slog_func, + }; + } + + There are many more setup parameters, but these are the most important. + For a complete list search for the sapp_desc structure declaration + below. + + DO NOT call any sokol-app function from inside sokol_main(), since + sokol-app will not be initialized at this point. + + The .width and .height parameters are the preferred size of the 3D + rendering canvas. The actual size may differ from this depending on + platform and other circumstances. Also the canvas size may change at + any time (for instance when the user resizes the application window, + or rotates the mobile device). You can just keep .width and .height + zero-initialized to open a default-sized window (what "default-size" + exactly means is platform-specific, but usually it's a size that covers + most of, but not all, of the display). + + All provided function callbacks will be called from the same thread, + but this may be different from the thread where sokol_main() was called. + + .init_cb (void (*)(void)) + This function is called once after the application window, + 3D rendering context and swap chain have been created. The + function takes no arguments and has no return value. + .frame_cb (void (*)(void)) + This is the per-frame callback, which is usually called 60 + times per second. This is where your application would update + most of its state and perform all rendering. + .cleanup_cb (void (*)(void)) + The cleanup callback is called once right before the application + quits. + .event_cb (void (*)(const sapp_event* event)) + The event callback is mainly for input handling, but is also + used to communicate other types of events to the application. Keep the + event_cb struct member zero-initialized if your application doesn't require + event handling. + + As you can see, those 'standard callbacks' don't have a user_data + argument, so any data that needs to be preserved between callbacks + must live in global variables. If keeping state in global variables + is not an option, there's an alternative set of callbacks with + an additional user_data pointer argument: + + .user_data (void*) + The user-data argument for the callbacks below + .init_userdata_cb (void (*)(void* user_data)) + .frame_userdata_cb (void (*)(void* user_data)) + .cleanup_userdata_cb (void (*)(void* user_data)) + .event_userdata_cb (void(*)(const sapp_event* event, void* user_data)) + + The function sapp_userdata() can be used to query the user_data + pointer provided in the sapp_desc struct. + + You can also call sapp_query_desc() to get a copy of the + original sapp_desc structure. + + NOTE that there's also an alternative compile mode where sokol_app.h + doesn't "hijack" the main() function. Search below for SOKOL_NO_ENTRY. + + --- Implement the initialization callback function (init_cb), this is called + once after the rendering surface, 3D API and swap chain have been + initialized by sokol_app. All sokol-app functions can be called + from inside the initialization callback, the most useful functions + at this point are: + + int sapp_width(void) + int sapp_height(void) + Returns the current width and height of the default framebuffer in pixels, + this may change from one frame to the next, and it may be different + from the initial size provided in the sapp_desc struct. + + float sapp_widthf(void) + float sapp_heightf(void) + These are alternatives to sapp_width() and sapp_height() which return + the default framebuffer size as float values instead of integer. This + may help to prevent casting back and forth between int and float + in more strongly typed languages than C and C++. + + double sapp_frame_duration(void) + Returns a smoothed frame duration. + + double sapp_frame_duration_unfiltered(void) + Returns the unfiltered frame duration with varying degree of + jitter (depending on platform and backend). + + int sapp_color_format(void) + int sapp_depth_format(void) + The color and depth-stencil pixelformats of the default framebuffer, + as integer values which are compatible with sokol-gfx's + sg_pixel_format enum (so that they can be plugged directly in places + where sg_pixel_format is expected). Possible values are: + + 23 == SG_PIXELFORMAT_RGBA8 + 28 == SG_PIXELFORMAT_BGRA8 + 42 == SG_PIXELFORMAT_DEPTH + 43 == SG_PIXELFORMAT_DEPTH_STENCIL + + int sapp_sample_count(void) + Return the MSAA sample count of the default framebuffer. + + const void* sapp_metal_get_device(void) + const void* sapp_metal_get_current_drawable(void) + const void* sapp_metal_get_depth_stencil_texture(void) + const void* sapp_metal_get_msaa_color_texture(void) + If the Metal backend has been selected, these functions return pointers + to various Metal API objects required for rendering, otherwise + they return a null pointer. These void pointers are actually + Objective-C ids converted with a (ARC) __bridge cast so that + the ids can be tunneled through C code. Also note that the returned + pointers may change from one frame to the next, only the Metal device + object is guaranteed to stay the same. + + const void* sapp_macos_get_window(void) + On macOS, get the NSWindow object pointer, otherwise a null pointer. + Before being used as Objective-C object, the void* must be converted + back with a (ARC) __bridge cast. + + const void* sapp_ios_get_window(void) + On iOS, get the UIWindow object pointer, otherwise a null pointer. + Before being used as Objective-C object, the void* must be converted + back with a (ARC) __bridge cast. + + const void* sapp_d3d11_get_device(void) + const void* sapp_d3d11_get_device_context(void) + const void* sapp_d3d11_get_render_view(void) + const void* sapp_d3d11_get_resolve_view(void); + const void* sapp_d3d11_get_depth_stencil_view(void) + Similar to the sapp_metal_* functions, the sapp_d3d11_* functions + return pointers to D3D11 API objects required for rendering, + only if the D3D11 backend has been selected. Otherwise they + return a null pointer. Note that the returned pointers to the + render-target-view and depth-stencil-view may change from one + frame to the next! + + const void* sapp_win32_get_hwnd(void) + On Windows, get the window's HWND, otherwise a null pointer. The + HWND has been cast to a void pointer in order to be tunneled + through code which doesn't include Windows.h. + + const void* sapp_x11_get_window(void) + On Linux, get the X11 Window, otherwise a null pointer. The + Window has been cast to a void pointer in order to be tunneled + through code which doesn't include X11/Xlib.h. + + const void* sapp_x11_get_display(void) + On Linux, get the X11 Display, otherwise a null pointer. The + Display has been cast to a void pointer in order to be tunneled + through code which doesn't include X11/Xlib.h. + + const void* sapp_wgpu_get_device(void) + const void* sapp_wgpu_get_render_view(void) + const void* sapp_wgpu_get_resolve_view(void) + const void* sapp_wgpu_get_depth_stencil_view(void) + These are the WebGPU-specific functions to get the WebGPU + objects and values required for rendering. If sokol_app.h + is not compiled with SOKOL_WGPU, these functions return null. + + uint32_t sapp_gl_get_framebuffer(void) + This returns the 'default framebuffer' of the GL context. + Typically this will be zero. + + int sapp_gl_get_major_version(void) + int sapp_gl_get_minor_version(void) + bool sapp_gl_is_gles(void) + Returns the major and minor version of the GL context and + whether the GL context is a GLES context + + const void* sapp_android_get_native_activity(void); + On Android, get the native activity ANativeActivity pointer, otherwise + a null pointer. + + --- Implement the frame-callback function, this function will be called + on the same thread as the init callback, but might be on a different + thread than the sokol_main() function. Note that the size of + the rendering framebuffer might have changed since the frame callback + was called last. Call the functions sapp_width() and sapp_height() + each frame to get the current size. + + --- Optionally implement the event-callback to handle input events. + sokol-app provides the following type of input events: + - a 'virtual key' was pressed down or released + - a single text character was entered (provided as UTF-32 encoded + UNICODE code point) + - a mouse button was pressed down or released (left, right, middle) + - mouse-wheel or 2D scrolling events + - the mouse was moved + - the mouse has entered or left the application window boundaries + - low-level, portable multi-touch events (began, moved, ended, cancelled) + - the application window was resized, iconified or restored + - the application was suspended or restored (on mobile platforms) + - the user or application code has asked to quit the application + - a string was pasted to the system clipboard + - one or more files have been dropped onto the application window + + To explicitly 'consume' an event and prevent that the event is + forwarded for further handling to the operating system, call + sapp_consume_event() from inside the event handler (NOTE that + this behaviour is currently only implemented for some HTML5 + events, support for other platforms and event types will + be added as needed, please open a GitHub ticket and/or provide + a PR if needed). + + NOTE: Do *not* call any 3D API rendering functions in the event + callback function, since the 3D API context may not be active when the + event callback is called (it may work on some platforms and 3D APIs, + but not others, and the exact behaviour may change between + sokol-app versions). + + --- Implement the cleanup-callback function, this is called once + after the user quits the application (see the section + "APPLICATION QUIT" for detailed information on quitting + behaviour, and how to intercept a pending quit - for instance to show a + "Really Quit?" dialog box). Note that the cleanup-callback isn't + guaranteed to be called on the web and mobile platforms. + + MOUSE CURSOR TYPE AND VISIBILITY + ================================ + You can show and hide the mouse cursor with + + void sapp_show_mouse(bool show) + + And to get the current shown status: + + bool sapp_mouse_shown(void) + + NOTE that hiding the mouse cursor is different and independent from + the MOUSE/POINTER LOCK feature which will also hide the mouse pointer when + active (MOUSE LOCK is described below). + + To change the mouse cursor to one of several predefined types, call + the function: + + void sapp_set_mouse_cursor(sapp_mouse_cursor cursor) + + Setting the default mouse cursor SAPP_MOUSECURSOR_DEFAULT will restore + the standard look. + + To get the currently active mouse cursor type, call: + + sapp_mouse_cursor sapp_get_mouse_cursor(void) + + MOUSE LOCK (AKA POINTER LOCK, AKA MOUSE CAPTURE) + ================================================ + In normal mouse mode, no mouse movement events are reported when the + mouse leaves the windows client area or hits the screen border (whether + it's one or the other depends on the platform), and the mouse move events + (SAPP_EVENTTYPE_MOUSE_MOVE) contain absolute mouse positions in + framebuffer pixels in the sapp_event items mouse_x and mouse_y, and + relative movement in framebuffer pixels in the sapp_event items mouse_dx + and mouse_dy. + + To get continuous mouse movement (also when the mouse leaves the window + client area or hits the screen border), activate mouse-lock mode + by calling: + + sapp_lock_mouse(true) + + When mouse lock is activated, the mouse pointer is hidden, the + reported absolute mouse position (sapp_event.mouse_x/y) appears + frozen, and the relative mouse movement in sapp_event.mouse_dx/dy + no longer has a direct relation to framebuffer pixels but instead + uses "raw mouse input" (what "raw mouse input" exactly means also + differs by platform). + + To deactivate mouse lock and return to normal mouse mode, call + + sapp_lock_mouse(false) + + And finally, to check if mouse lock is currently active, call + + if (sapp_mouse_locked()) { ... } + + Note that mouse-lock state may not change immediately after sapp_lock_mouse(true/false) + is called, instead on some platforms the actual state switch may be delayed + to the end of the current frame or even to a later frame. + + The mouse may also be unlocked automatically without calling sapp_lock_mouse(false), + most notably when the application window becomes inactive. + + On the web platform there are further restrictions to be aware of, caused + by the limitations of the HTML5 Pointer Lock API: + + - sapp_lock_mouse(true) can be called at any time, but it will + only take effect in a 'short-lived input event handler of a specific + type', meaning when one of the following events happens: + - SAPP_EVENTTYPE_MOUSE_DOWN + - SAPP_EVENTTYPE_MOUSE_UP + - SAPP_EVENTTYPE_MOUSE_SCROLL + - SAPP_EVENTTYPE_KEY_UP + - SAPP_EVENTTYPE_KEY_DOWN + - The mouse lock/unlock action on the web platform is asynchronous, + this means that sapp_mouse_locked() won't immediately return + the new status after calling sapp_lock_mouse(), instead the + reported status will only change when the pointer lock has actually + been activated or deactivated in the browser. + - On the web, mouse lock can be deactivated by the user at any time + by pressing the Esc key. When this happens, sokol_app.h behaves + the same as if sapp_lock_mouse(false) is called. + + For things like camera manipulation it's most straightforward to lock + and unlock the mouse right from the sokol_app.h event handler, for + instance the following code enters and leaves mouse lock when the + left mouse button is pressed and released, and then uses the relative + movement information to manipulate a camera (taken from the + cgltf-sapp.c sample in the sokol-samples repository + at https://github.com/floooh/sokol-samples): + + static void input(const sapp_event* ev) { + switch (ev->type) { + case SAPP_EVENTTYPE_MOUSE_DOWN: + if (ev->mouse_button == SAPP_MOUSEBUTTON_LEFT) { + sapp_lock_mouse(true); + } + break; + + case SAPP_EVENTTYPE_MOUSE_UP: + if (ev->mouse_button == SAPP_MOUSEBUTTON_LEFT) { + sapp_lock_mouse(false); + } + break; + + case SAPP_EVENTTYPE_MOUSE_MOVE: + if (sapp_mouse_locked()) { + cam_orbit(&state.camera, ev->mouse_dx * 0.25f, ev->mouse_dy * 0.25f); + } + break; + + default: + break; + } + } + + For a 'first person shooter mouse' the following code inside the sokol-app event handler + is recommended somewhere in your frame callback: + + if (!sapp_mouse_locked()) { + sapp_lock_mouse(true); + } + + CLIPBOARD SUPPORT + ================= + Applications can send and receive UTF-8 encoded text data from and to the + system clipboard. By default, clipboard support is disabled and + must be enabled at startup via the following sapp_desc struct + members: + + sapp_desc.enable_clipboard - set to true to enable clipboard support + sapp_desc.clipboard_size - size of the internal clipboard buffer in bytes + + Enabling the clipboard will dynamically allocate a clipboard buffer + for UTF-8 encoded text data of the requested size in bytes, the default + size is 8 KBytes. Strings that don't fit into the clipboard buffer + (including the terminating zero) will be silently clipped, so it's + important that you provide a big enough clipboard size for your + use case. + + To send data to the clipboard, call sapp_set_clipboard_string() with + a pointer to an UTF-8 encoded, null-terminated C-string. + + NOTE that on the HTML5 platform, sapp_set_clipboard_string() must be + called from inside a 'short-lived event handler', and there are a few + other HTML5-specific caveats to workaround. You'll basically have to + tinker until it works in all browsers :/ (maybe the situation will + improve when all browsers agree on and implement the new + HTML5 navigator.clipboard API). + + To get data from the clipboard, check for the SAPP_EVENTTYPE_CLIPBOARD_PASTED + event in your event handler function, and then call sapp_get_clipboard_string() + to obtain the pasted UTF-8 encoded text. + + NOTE that behaviour of sapp_get_clipboard_string() is slightly different + depending on platform: + + - on the HTML5 platform, the internal clipboard buffer will only be updated + right before the SAPP_EVENTTYPE_CLIPBOARD_PASTED event is sent, + and sapp_get_clipboard_string() will simply return the current content + of the clipboard buffer + - on 'native' platforms, the call to sapp_get_clipboard_string() will + update the internal clipboard buffer with the most recent data + from the system clipboard + + Portable code should check for the SAPP_EVENTTYPE_CLIPBOARD_PASTED event, + and then call sapp_get_clipboard_string() right in the event handler. + + The SAPP_EVENTTYPE_CLIPBOARD_PASTED event will be generated by sokol-app + as follows: + + - on macOS: when the Cmd+V key is pressed down + - on HTML5: when the browser sends a 'paste' event to the global 'window' object + - on all other platforms: when the Ctrl+V key is pressed down + + DRAG AND DROP SUPPORT + ===================== + PLEASE NOTE: the drag'n'drop feature works differently on WASM/HTML5 + and on the native desktop platforms (Win32, Linux and macOS) because + of security-related restrictions in the HTML5 drag'n'drop API. The + WASM/HTML5 specifics are described at the end of this documentation + section: + + Like clipboard support, drag'n'drop support must be explicitly enabled + at startup in the sapp_desc struct. + + sapp_desc sokol_main(void) { + return (sapp_desc) { + .enable_dragndrop = true, // default is false + ... + }; + } + + You can also adjust the maximum number of files that are accepted + in a drop operation, and the maximum path length in bytes if needed: + + sapp_desc sokol_main(void) { + return (sapp_desc) { + .enable_dragndrop = true, // default is false + .max_dropped_files = 8, // default is 1 + .max_dropped_file_path_length = 8192, // in bytes, default is 2048 + ... + }; + } + + When drag'n'drop is enabled, the event callback will be invoked with an + event of type SAPP_EVENTTYPE_FILES_DROPPED whenever the user drops files on + the application window. + + After the SAPP_EVENTTYPE_FILES_DROPPED is received, you can query the + number of dropped files, and their absolute paths by calling separate + functions: + + void on_event(const sapp_event* ev) { + if (ev->type == SAPP_EVENTTYPE_FILES_DROPPED) { + + // the mouse position where the drop happened + float x = ev->mouse_x; + float y = ev->mouse_y; + + // get the number of files and their paths like this: + const int num_dropped_files = sapp_get_num_dropped_files(); + for (int i = 0; i < num_dropped_files; i++) { + const char* path = sapp_get_dropped_file_path(i); + ... + } + } + } + + The returned file paths are UTF-8 encoded strings. + + You can call sapp_get_num_dropped_files() and sapp_get_dropped_file_path() + anywhere, also outside the event handler callback, but be aware that the + file path strings will be overwritten with the next drop operation. + + In any case, sapp_get_dropped_file_path() will never return a null pointer, + instead an empty string "" will be returned if the drag'n'drop feature + hasn't been enabled, the last drop-operation failed, or the file path index + is out of range. + + Drag'n'drop caveats: + + - if more files are dropped in a single drop-action + than sapp_desc.max_dropped_files, the additional + files will be silently ignored + - if any of the file paths is longer than + sapp_desc.max_dropped_file_path_length (in number of bytes, after UTF-8 + encoding) the entire drop operation will be silently ignored (this + needs some sort of error feedback in the future) + - no mouse positions are reported while the drag is in + process, this may change in the future + + Drag'n'drop on HTML5/WASM: + + The HTML5 drag'n'drop API doesn't return file paths, but instead + black-box 'file objects' which must be used to load the content + of dropped files. This is the reason why sokol_app.h adds two + HTML5-specific functions to the drag'n'drop API: + + uint32_t sapp_html5_get_dropped_file_size(int index) + Returns the size in bytes of a dropped file. + + void sapp_html5_fetch_dropped_file(const sapp_html5_fetch_request* request) + Asynchronously loads the content of a dropped file into a + provided memory buffer (which must be big enough to hold + the file content) + + To start loading the first dropped file after an SAPP_EVENTTYPE_FILES_DROPPED + event is received: + + sapp_html5_fetch_dropped_file(&(sapp_html5_fetch_request){ + .dropped_file_index = 0, + .callback = fetch_cb + .buffer = { + .ptr = buf, + .size = sizeof(buf) + }, + .user_data = ... + }); + + Make sure that the memory pointed to by 'buf' stays valid until the + callback function is called! + + As result of the asynchronous loading operation (no matter if succeeded or + failed) the 'fetch_cb' function will be called: + + void fetch_cb(const sapp_html5_fetch_response* response) { + // IMPORTANT: check if the loading operation actually succeeded: + if (response->succeeded) { + // the size of the loaded file: + const size_t num_bytes = response->data.size; + // and the pointer to the data (same as 'buf' in the fetch-call): + const void* ptr = response->data.ptr; + } else { + // on error check the error code: + switch (response->error_code) { + case SAPP_HTML5_FETCH_ERROR_BUFFER_TOO_SMALL: + ... + break; + case SAPP_HTML5_FETCH_ERROR_OTHER: + ... + break; + } + } + } + + Check the droptest-sapp example for a real-world example which works + both on native platforms and the web: + + https://github.com/floooh/sokol-samples/blob/master/sapp/droptest-sapp.c + + HIGH-DPI RENDERING + ================== + You can set the sapp_desc.high_dpi flag during initialization to request + a full-resolution framebuffer on HighDPI displays. The default behaviour + is sapp_desc.high_dpi=false, this means that the application will + render to a lower-resolution framebuffer on HighDPI displays and the + rendered content will be upscaled by the window system composer. + + In a HighDPI scenario, you still request the same window size during + sokol_main(), but the framebuffer sizes returned by sapp_width() + and sapp_height() will be scaled up according to the DPI scaling + ratio. + + Note that on some platforms the DPI scaling factor may change at any + time (for instance when a window is moved from a high-dpi display + to a low-dpi display). + + To query the current DPI scaling factor, call the function: + + float sapp_dpi_scale(void); + + For instance on a Retina Mac, returning the following sapp_desc + struct from sokol_main(): + + sapp_desc sokol_main(void) { + return (sapp_desc) { + .width = 640, + .height = 480, + .high_dpi = true, + ... + }; + } + + ...the functions the functions sapp_width(), sapp_height() + and sapp_dpi_scale() will return the following values: + + sapp_width: 1280 + sapp_height: 960 + sapp_dpi_scale: 2.0 + + If the high_dpi flag is false, or you're not running on a Retina display, + the values would be: + + sapp_width: 640 + sapp_height: 480 + sapp_dpi_scale: 1.0 + + If the window is moved from the Retina display to a low-dpi external display, + the values would change as follows: + + sapp_width: 1280 => 640 + sapp_height: 960 => 480 + sapp_dpi_scale: 2.0 => 1.0 + + Currently there is no event associated with a DPI change, but an + SAPP_EVENTTYPE_RESIZED will be sent as a side effect of the + framebuffer size changing. + + Per-monitor DPI is currently supported on macOS and Windows. + + APPLICATION QUIT + ================ + Without special quit handling, a sokol_app.h application will quit + 'gracefully' when the user clicks the window close-button unless a + platform's application model prevents this (e.g. on web or mobile). + 'Graceful exit' means that the application-provided cleanup callback will + be called before the application quits. + + On native desktop platforms sokol_app.h provides more control over the + application-quit-process. It's possible to initiate a 'programmatic quit' + from the application code, and a quit initiated by the application user can + be intercepted (for instance to show a custom dialog box). + + This 'programmatic quit protocol' is implemented through 3 functions + and 1 event: + + - sapp_quit(): This function simply quits the application without + giving the user a chance to intervene. Usually this might + be called when the user clicks the 'Ok' button in a 'Really Quit?' + dialog box + - sapp_request_quit(): Calling sapp_request_quit() will send the + event SAPP_EVENTTYPE_QUIT_REQUESTED to the applications event handler + callback, giving the user code a chance to intervene and cancel the + pending quit process (for instance to show a 'Really Quit?' dialog + box). If the event handler callback does nothing, the application + will be quit as usual. To prevent this, call the function + sapp_cancel_quit() from inside the event handler. + - sapp_cancel_quit(): Cancels a pending quit request, either initiated + by the user clicking the window close button, or programmatically + by calling sapp_request_quit(). The only place where calling this + function makes sense is from inside the event handler callback when + the SAPP_EVENTTYPE_QUIT_REQUESTED event has been received. + - SAPP_EVENTTYPE_QUIT_REQUESTED: this event is sent when the user + clicks the window's close button or application code calls the + sapp_request_quit() function. The event handler callback code can handle + this event by calling sapp_cancel_quit() to cancel the quit. + If the event is ignored, the application will quit as usual. + + On the web platform, the quit behaviour differs from native platforms, + because of web-specific restrictions: + + A `programmatic quit` initiated by calling sapp_quit() or + sapp_request_quit() will work as described above: the cleanup callback is + called, platform-specific cleanup is performed (on the web + this means that JS event handlers are unregistered), and then + the request-animation-loop will be exited. However that's all. The + web page itself will continue to exist (e.g. it's not possible to + programmatically close the browser tab). + + On the web it's also not possible to run custom code when the user + closes a browser tab, so it's not possible to prevent this with a + fancy custom dialog box. + + Instead the standard "Leave Site?" dialog box can be activated (or + deactivated) with the following function: + + sapp_html5_ask_leave_site(bool ask); + + The initial state of the associated internal flag can be provided + at startup via sapp_desc.html5.ask_leave_site. + + This feature should only be used sparingly in critical situations - for + instance when the user would loose data - since popping up modal dialog + boxes is considered quite rude in the web world. Note that there's no way + to customize the content of this dialog box or run any code as a result + of the user's decision. Also note that the user must have interacted with + the site before the dialog box will appear. These are all security measures + to prevent fishing. + + The Dear ImGui HighDPI sample contains example code of how to + implement a 'Really Quit?' dialog box with Dear ImGui (native desktop + platforms only), and for showing the hardwired "Leave Site?" dialog box + when running on the web platform: + + https://floooh.github.io/sokol-html5/wasm/imgui-highdpi-sapp.html + + FULLSCREEN + ========== + If the sapp_desc.fullscreen flag is true, sokol-app will try to create + a fullscreen window on platforms with a 'proper' window system + (mobile devices will always use fullscreen). The implementation details + depend on the target platform, in general sokol-app will use a + 'soft approach' which doesn't interfere too much with the platform's + window system (for instance borderless fullscreen window instead of + a 'real' fullscreen mode). Such details might change over time + as sokol-app is adapted for different needs. + + The most important effect of fullscreen mode to keep in mind is that + the requested canvas width and height will be ignored for the initial + window size, calling sapp_width() and sapp_height() will instead return + the resolution of the fullscreen canvas (however the provided size + might still be used for the non-fullscreen window, in case the user can + switch back from fullscreen- to windowed-mode). + + To toggle fullscreen mode programmatically, call sapp_toggle_fullscreen(). + + To check if the application window is currently in fullscreen mode, + call sapp_is_fullscreen(). + + On the web, sapp_desc.fullscreen will have no effect, and the application + will always start in non-fullscreen mode. Call sapp_toggle_fullscreen() + from within or 'near' an input event to switch to fullscreen programatically. + Note that on the web, the fullscreen state may change back to windowed at + any time (either because the browser had rejected switching into fullscreen, + or the user leaves fullscreen via Esc), this means that the result + of sapp_is_fullscreen() may change also without calling sapp_toggle_fullscreen()! + + + WINDOW ICON SUPPORT + =================== + Some sokol_app.h backends allow to change the window icon programmatically: + + - on Win32: the small icon in the window's title bar, and the + bigger icon in the task bar + - on Linux: highly dependent on the used window manager, but usually + the window's title bar icon and/or the task bar icon + - on HTML5: the favicon shown in the page's browser tab + - on macOS: the application icon shown in the dock, but only + for currently running applications + + NOTE that it is not possible to set the actual application icon which is + displayed by the operating system on the desktop or 'home screen'. Those + icons must be provided 'traditionally' through operating-system-specific + resources which are associated with the application (sokol_app.h might + later support setting the window icon from platform specific resource data + though). + + There are two ways to set the window icon: + + - at application start in the sokol_main() function by initializing + the sapp_desc.icon nested struct + - or later by calling the function sapp_set_icon() + + As a convenient shortcut, sokol_app.h comes with a builtin default-icon + (a rainbow-colored 'S', which at least looks a bit better than the Windows + default icon for applications), which can be activated like this: + + At startup in sokol_main(): + + sapp_desc sokol_main(...) { + return (sapp_desc){ + ... + icon.sokol_default = true + }; + } + + Or later by calling: + + sapp_set_icon(&(sapp_icon_desc){ .sokol_default = true }); + + NOTE that a completely zero-initialized sapp_icon_desc struct will not + update the window icon in any way. This is an 'escape hatch' so that you + can handle the window icon update yourself (or if you do this already, + sokol_app.h won't get in your way, in this case just leave the + sapp_desc.icon struct zero-initialized). + + Providing your own icon images works exactly like in GLFW (down to the + data format): + + You provide one or more 'candidate images' in different sizes, and the + sokol_app.h platform backends pick the best match for the specific backend + and icon type. + + For each candidate image, you need to provide: + + - the width in pixels + - the height in pixels + - and the actual pixel data in RGBA8 pixel format (e.g. 0xFFCC8844 + on a little-endian CPU means: alpha=0xFF, blue=0xCC, green=0x88, red=0x44) + + For instance, if you have 3 candidate images (small, medium, big) of + sizes 16x16, 32x32 and 64x64 the corresponding sapp_icon_desc struct is setup + like this: + + // the actual pixel data (RGBA8, origin top-left) + const uint32_t small[16][16] = { ... }; + const uint32_t medium[32][32] = { ... }; + const uint32_t big[64][64] = { ... }; + + const sapp_icon_desc icon_desc = { + .images = { + { .width = 16, .height = 16, .pixels = SAPP_RANGE(small) }, + { .width = 32, .height = 32, .pixels = SAPP_RANGE(medium) }, + // ...or without the SAPP_RANGE helper macro: + { .width = 64, .height = 64, .pixels = { .ptr=big, .size=sizeof(big) } } + } + }; + + An sapp_icon_desc struct initialized like this can then either be applied + at application start in sokol_main: + + sapp_desc sokol_main(...) { + return (sapp_desc){ + ... + icon = icon_desc + }; + } + + ...or later by calling sapp_set_icon(): + + sapp_set_icon(&icon_desc); + + Some window icon caveats: + + - once the window icon has been updated, there's no way to go back to + the platform's default icon, this is because some platforms (Linux + and HTML5) don't switch the icon visual back to the default even if + the custom icon is deleted or removed + - on HTML5, if the sokol_app.h icon doesn't show up in the browser + tab, check that there's no traditional favicon 'link' element + is defined in the page's index.html, sokol_app.h will only + append a new favicon link element, but not delete any manually + defined favicon in the page + + For an example and test of the window icon feature, check out the + 'icon-sapp' sample on the sokol-samples git repository. + + ONSCREEN KEYBOARD + ================= + On some platforms which don't provide a physical keyboard, sokol-app + can display the platform's integrated onscreen keyboard for text + input. To request that the onscreen keyboard is shown, call + + sapp_show_keyboard(true); + + Likewise, to hide the keyboard call: + + sapp_show_keyboard(false); + + Note that onscreen keyboard functionality is no longer supported + on the browser platform (the previous hacks and workarounds to make browser + keyboards work for on web applications that don't use HTML UIs + never really worked across browsers). + + INPUT EVENT BUBBLING ON THE WEB PLATFORM + ======================================== + By default, input event bubbling on the web platform is configured in + a way that makes the most sense for 'full-canvas' apps that cover the + entire browser client window area: + + - mouse, touch and wheel events do not bubble up, this prevents various + ugly side events, like: + - HTML text overlays being selected on double- or triple-click into + the canvas + - 'scroll bumping' even when the canvas covers the entire client area + - key_up/down events for 'character keys' *do* bubble up (otherwise + the browser will not generate UNICODE character events) + - all other key events *do not* bubble up by default (this prevents side effects + like F1 opening help, or F7 starting 'caret browsing') + - character events do not bubble up (although I haven't noticed any side effects + otherwise) + + Event bubbling can be enabled for input event categories during initialization + in the sapp_desc struct: + + sapp_desc sokol_main(int argc, char* argv[]) { + return (sapp_desc){ + //... + .html5 = { + .bubble_mouse_events = true, + .bubble_touch_events = true, + .bubble_wheel_events = true, + .bubble_key_events = true, + .bubble_char_events = true, + } + }; + } + + This basically opens the floodgates and lets *all* input events bubble up to the browser. + + To prevent individual events from bubbling, call sapp_consume_event() from within + the sokol_app.h event callback when that specific event is reported. + + + SETTING THE CANVAS OBJECT ON THE WEB PLATFORM + ============================================= + On the web, sokol_app.h and the Emscripten SDK functions need to find + the WebGL/WebGPU canvas intended for rendering and attaching event + handlers. This can happen in four ways: + + 1. do nothing and just set the id of the canvas object to 'canvas' (preferred) + 2. via a CSS Selector string (preferred) + 3. by setting the `Module.canvas` property to the canvas object + 4. by adding the canvas object to the global variable `specialHTMLTargets[]` + (this is a special variable used by the Emscripten runtime to lookup + event target objects for which document.querySelector() cannot be used) + + The easiest way is to just name your canvas object 'canvas': + + + + This works because the default css selector string used by sokol_app.h + is '#canvas'. + + If you name your canvas differently, you need to communicate that name to + sokol_app.h via `sapp_desc.html5.canvas_selector` as a regular css selector + string that's compatible with `document.querySelector()`. E.g. if your canvas + object looks like this: + + + + The `sapp_desc.html5.canvas_selector` string must be set to '#bla': + + .html5.canvas_selector = "#bla" + + If the canvas object cannot be looked up via `document.querySelector()` you + need to use one of the alternative methods, both involve the special + Emscripten runtime `Module` object which is usually setup in the index.html + like this before the WASM blob is loaded and instantiated: + + + + The first option is to set the `Module.canvas` property to your canvas object: + + + + When sokol_app.h initializes, it will check the global Module object whether + a `Module.canvas` property exists and is an object. This method will add + a new entry to the `specialHTMLTargets[]` object + + The other option is to add the canvas under a name chosen by you to the + special `specialHTMLTargets[]` map, which is used by the Emscripten runtime + to lookup 'event target objects' which are not visible to `document.querySelector()`. + Note that `specialHTMLTargets[]` must be updated after the Emscripten runtime + has started but before the WASM code is running. A good place for this is + the special `Module.preRun` array in index.html: + + + + In that case, pass the same string to sokol_app.h which is used as key + in the specialHTMLTargets[] map: + + .html5.canvas_selector = "my_canvas" + + If sokol_app.h can't find your canvas for some reason check for warning + messages on the browser console. + + + OPTIONAL: DON'T HIJACK main() (#define SOKOL_NO_ENTRY) + ====================================================== + NOTE: SOKOL_NO_ENTRY and sapp_run() is currently not supported on Android. + + In its default configuration, sokol_app.h "hijacks" the platform's + standard main() function. This was done because different platforms + have different entry point conventions which are not compatible with + C's main() (for instance WinMain on Windows has completely different + arguments). However, this "main hijacking" posed a problem for + usage scenarios like integrating sokol_app.h with other languages than + C or C++, so an alternative SOKOL_NO_ENTRY mode has been added + in which the user code provides the platform's main function: + + - define SOKOL_NO_ENTRY before including the sokol_app.h implementation + - do *not* provide a sokol_main() function + - instead provide the standard main() function of the platform + - from the main function, call the function ```sapp_run()``` which + takes a pointer to an ```sapp_desc``` structure. + - from here on```sapp_run()``` takes over control and calls the provided + init-, frame-, event- and cleanup-callbacks just like in the default model. + + sapp_run() behaves differently across platforms: + + - on some platforms, sapp_run() will return when the application quits + - on other platforms, sapp_run() will never return, even when the + application quits (the operating system is free to simply terminate + the application at any time) + - on Emscripten specifically, sapp_run() will return immediately while + the frame callback keeps being called + + This different behaviour of sapp_run() essentially means that there shouldn't + be any code *after* sapp_run(), because that may either never be called, or in + case of Emscripten will be called at an unexpected time (at application start). + + An application also should not depend on the cleanup-callback being called + when cross-platform compatibility is required. + + Since sapp_run() returns immediately on Emscripten you shouldn't activate + the 'EXIT_RUNTIME' linker option (this is disabled by default when compiling + for the browser target), since the C/C++ exit runtime would be called immediately at + application start, causing any global objects to be destroyed and global + variables to be zeroed. + + WINDOWS CONSOLE OUTPUT + ====================== + On Windows, regular windowed applications don't show any stdout/stderr text + output, which can be a bit of a hassle for printf() debugging or generally + logging text to the console. Also, console output by default uses a local + codepage setting and thus international UTF-8 encoded text is printed + as garbage. + + To help with these issues, sokol_app.h can be configured at startup + via the following Windows-specific sapp_desc flags: + + sapp_desc.win32.console_utf8 (default: false) + When set to true, the output console codepage will be switched + to UTF-8 (and restored to the original codepage on exit) + + sapp_desc.win32.console_attach (default: false) + When set to true, stdout and stderr will be attached to the + console of the parent process (if the parent process actually + has a console). This means that if the application was started + in a command line window, stdout and stderr output will be printed + to the terminal, just like a regular command line program. But if + the application is started via double-click, it will behave like + a regular UI application, and stdout/stderr will not be visible. + + sapp_desc.win32.console_create (default: false) + When set to true, a new console window will be created and + stdout/stderr will be redirected to that console window. It + doesn't matter if the application is started from the command + line or via double-click. + + NOTE: setting both win32.console_attach and win32.console_create + to true also makes sense and has the effect that output + will appear in the existing terminal when started from the cmdline, and + otherwise (when started via double-click) will open a console window. + + MEMORY ALLOCATION OVERRIDE + ========================== + You can override the memory allocation functions at initialization time + like this: + + void* my_alloc(size_t size, void* user_data) { + return malloc(size); + } + + void my_free(void* ptr, void* user_data) { + free(ptr); + } + + sapp_desc sokol_main(int argc, char* argv[]) { + return (sapp_desc){ + // ... + .allocator = { + .alloc_fn = my_alloc, + .free_fn = my_free, + .user_data = ..., + } + }; + } + + If no overrides are provided, malloc and free will be used. + + This only affects memory allocation calls done by sokol_app.h + itself though, not any allocations in OS libraries. + + + ERROR REPORTING AND LOGGING + =========================== + To get any logging information at all you need to provide a logging callback in the setup call + the easiest way is to use sokol_log.h: + + #include "sokol_log.h" + + sapp_desc sokol_main(int argc, char* argv[]) { + return (sapp_desc) { + ... + .logger.func = slog_func, + }; + } + + To override logging with your own callback, first write a logging function like this: + + void my_log(const char* tag, // e.g. 'sapp' + uint32_t log_level, // 0=panic, 1=error, 2=warn, 3=info + uint32_t log_item_id, // SAPP_LOGITEM_* + const char* message_or_null, // a message string, may be nullptr in release mode + uint32_t line_nr, // line number in sokol_app.h + const char* filename_or_null, // source filename, may be nullptr in release mode + void* user_data) + { + ... + } + + ...and then setup sokol-app like this: + + sapp_desc sokol_main(int argc, char* argv[]) { + return (sapp_desc) { + ... + .logger = { + .func = my_log, + .user_data = my_user_data, + } + }; + } + + The provided logging function must be reentrant (e.g. be callable from + different threads). + + If you don't want to provide your own custom logger it is highly recommended to use + the standard logger in sokol_log.h instead, otherwise you won't see any warnings or + errors. + + TEMP NOTE DUMP + ============== + - sapp_desc needs a bool whether to initialize depth-stencil surface + - the Android implementation calls cleanup_cb() and destroys the egl context in onDestroy + at the latest but should do it earlier, in onStop, as an app is "killable" after onStop + on Android Honeycomb and later (it can't be done at the moment as the app may be started + again after onStop and the sokol lifecycle does not yet handle context teardown/bringup) + + + LICENSE + ======= + zlib/libpng license + + Copyright (c) 2018 Andre Weissflog + + This software is provided 'as-is', without any express or implied warranty. + In no event will the authors be held liable for any damages arising from the + use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software in a + product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not + be misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*/ +#define SOKOL_APP_INCLUDED (1) +#include // size_t +#include +#include + +#if defined(SOKOL_API_DECL) && !defined(SOKOL_APP_API_DECL) +#define SOKOL_APP_API_DECL SOKOL_API_DECL +#endif +#ifndef SOKOL_APP_API_DECL +#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_APP_IMPL) +#define SOKOL_APP_API_DECL __declspec(dllexport) +#elif defined(_WIN32) && defined(SOKOL_DLL) +#define SOKOL_APP_API_DECL __declspec(dllimport) +#else +#define SOKOL_APP_API_DECL extern +#endif +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* misc constants */ +enum { + SAPP_MAX_TOUCHPOINTS = 8, + SAPP_MAX_MOUSEBUTTONS = 3, + SAPP_MAX_KEYCODES = 512, + SAPP_MAX_ICONIMAGES = 8, +}; + +/* + sapp_event_type + + The type of event that's passed to the event handler callback + in the sapp_event.type field. These are not just "traditional" + input events, but also notify the application about state changes + or other user-invoked actions. +*/ +typedef enum sapp_event_type { + SAPP_EVENTTYPE_INVALID, + SAPP_EVENTTYPE_KEY_DOWN, + SAPP_EVENTTYPE_KEY_UP, + SAPP_EVENTTYPE_CHAR, + SAPP_EVENTTYPE_MOUSE_DOWN, + SAPP_EVENTTYPE_MOUSE_UP, + SAPP_EVENTTYPE_MOUSE_SCROLL, + SAPP_EVENTTYPE_MOUSE_MOVE, + SAPP_EVENTTYPE_MOUSE_ENTER, + SAPP_EVENTTYPE_MOUSE_LEAVE, + SAPP_EVENTTYPE_TOUCHES_BEGAN, + SAPP_EVENTTYPE_TOUCHES_MOVED, + SAPP_EVENTTYPE_TOUCHES_ENDED, + SAPP_EVENTTYPE_TOUCHES_CANCELLED, + SAPP_EVENTTYPE_RESIZED, + SAPP_EVENTTYPE_ICONIFIED, + SAPP_EVENTTYPE_RESTORED, + SAPP_EVENTTYPE_FOCUSED, + SAPP_EVENTTYPE_UNFOCUSED, + SAPP_EVENTTYPE_SUSPENDED, + SAPP_EVENTTYPE_RESUMED, + SAPP_EVENTTYPE_QUIT_REQUESTED, + SAPP_EVENTTYPE_CLIPBOARD_PASTED, + SAPP_EVENTTYPE_FILES_DROPPED, + _SAPP_EVENTTYPE_NUM, + _SAPP_EVENTTYPE_FORCE_U32 = 0x7FFFFFFF +} sapp_event_type; + +/* + sapp_keycode + + The 'virtual keycode' of a KEY_DOWN or KEY_UP event in the + struct field sapp_event.key_code. + + Note that the keycode values are identical with GLFW. +*/ +typedef enum sapp_keycode { + SAPP_KEYCODE_INVALID = 0, + SAPP_KEYCODE_SPACE = 32, + SAPP_KEYCODE_APOSTROPHE = 39, /* ' */ + SAPP_KEYCODE_COMMA = 44, /* , */ + SAPP_KEYCODE_MINUS = 45, /* - */ + SAPP_KEYCODE_PERIOD = 46, /* . */ + SAPP_KEYCODE_SLASH = 47, /* / */ + SAPP_KEYCODE_0 = 48, + SAPP_KEYCODE_1 = 49, + SAPP_KEYCODE_2 = 50, + SAPP_KEYCODE_3 = 51, + SAPP_KEYCODE_4 = 52, + SAPP_KEYCODE_5 = 53, + SAPP_KEYCODE_6 = 54, + SAPP_KEYCODE_7 = 55, + SAPP_KEYCODE_8 = 56, + SAPP_KEYCODE_9 = 57, + SAPP_KEYCODE_SEMICOLON = 59, /* ; */ + SAPP_KEYCODE_EQUAL = 61, /* = */ + SAPP_KEYCODE_A = 65, + SAPP_KEYCODE_B = 66, + SAPP_KEYCODE_C = 67, + SAPP_KEYCODE_D = 68, + SAPP_KEYCODE_E = 69, + SAPP_KEYCODE_F = 70, + SAPP_KEYCODE_G = 71, + SAPP_KEYCODE_H = 72, + SAPP_KEYCODE_I = 73, + SAPP_KEYCODE_J = 74, + SAPP_KEYCODE_K = 75, + SAPP_KEYCODE_L = 76, + SAPP_KEYCODE_M = 77, + SAPP_KEYCODE_N = 78, + SAPP_KEYCODE_O = 79, + SAPP_KEYCODE_P = 80, + SAPP_KEYCODE_Q = 81, + SAPP_KEYCODE_R = 82, + SAPP_KEYCODE_S = 83, + SAPP_KEYCODE_T = 84, + SAPP_KEYCODE_U = 85, + SAPP_KEYCODE_V = 86, + SAPP_KEYCODE_W = 87, + SAPP_KEYCODE_X = 88, + SAPP_KEYCODE_Y = 89, + SAPP_KEYCODE_Z = 90, + SAPP_KEYCODE_LEFT_BRACKET = 91, /* [ */ + SAPP_KEYCODE_BACKSLASH = 92, /* \ */ + SAPP_KEYCODE_RIGHT_BRACKET = 93, /* ] */ + SAPP_KEYCODE_GRAVE_ACCENT = 96, /* ` */ + SAPP_KEYCODE_WORLD_1 = 161, /* non-US #1 */ + SAPP_KEYCODE_WORLD_2 = 162, /* non-US #2 */ + SAPP_KEYCODE_ESCAPE = 256, + SAPP_KEYCODE_ENTER = 257, + SAPP_KEYCODE_TAB = 258, + SAPP_KEYCODE_BACKSPACE = 259, + SAPP_KEYCODE_INSERT = 260, + SAPP_KEYCODE_DELETE = 261, + SAPP_KEYCODE_RIGHT = 262, + SAPP_KEYCODE_LEFT = 263, + SAPP_KEYCODE_DOWN = 264, + SAPP_KEYCODE_UP = 265, + SAPP_KEYCODE_PAGE_UP = 266, + SAPP_KEYCODE_PAGE_DOWN = 267, + SAPP_KEYCODE_HOME = 268, + SAPP_KEYCODE_END = 269, + SAPP_KEYCODE_CAPS_LOCK = 280, + SAPP_KEYCODE_SCROLL_LOCK = 281, + SAPP_KEYCODE_NUM_LOCK = 282, + SAPP_KEYCODE_PRINT_SCREEN = 283, + SAPP_KEYCODE_PAUSE = 284, + SAPP_KEYCODE_F1 = 290, + SAPP_KEYCODE_F2 = 291, + SAPP_KEYCODE_F3 = 292, + SAPP_KEYCODE_F4 = 293, + SAPP_KEYCODE_F5 = 294, + SAPP_KEYCODE_F6 = 295, + SAPP_KEYCODE_F7 = 296, + SAPP_KEYCODE_F8 = 297, + SAPP_KEYCODE_F9 = 298, + SAPP_KEYCODE_F10 = 299, + SAPP_KEYCODE_F11 = 300, + SAPP_KEYCODE_F12 = 301, + SAPP_KEYCODE_F13 = 302, + SAPP_KEYCODE_F14 = 303, + SAPP_KEYCODE_F15 = 304, + SAPP_KEYCODE_F16 = 305, + SAPP_KEYCODE_F17 = 306, + SAPP_KEYCODE_F18 = 307, + SAPP_KEYCODE_F19 = 308, + SAPP_KEYCODE_F20 = 309, + SAPP_KEYCODE_F21 = 310, + SAPP_KEYCODE_F22 = 311, + SAPP_KEYCODE_F23 = 312, + SAPP_KEYCODE_F24 = 313, + SAPP_KEYCODE_F25 = 314, + SAPP_KEYCODE_KP_0 = 320, + SAPP_KEYCODE_KP_1 = 321, + SAPP_KEYCODE_KP_2 = 322, + SAPP_KEYCODE_KP_3 = 323, + SAPP_KEYCODE_KP_4 = 324, + SAPP_KEYCODE_KP_5 = 325, + SAPP_KEYCODE_KP_6 = 326, + SAPP_KEYCODE_KP_7 = 327, + SAPP_KEYCODE_KP_8 = 328, + SAPP_KEYCODE_KP_9 = 329, + SAPP_KEYCODE_KP_DECIMAL = 330, + SAPP_KEYCODE_KP_DIVIDE = 331, + SAPP_KEYCODE_KP_MULTIPLY = 332, + SAPP_KEYCODE_KP_SUBTRACT = 333, + SAPP_KEYCODE_KP_ADD = 334, + SAPP_KEYCODE_KP_ENTER = 335, + SAPP_KEYCODE_KP_EQUAL = 336, + SAPP_KEYCODE_LEFT_SHIFT = 340, + SAPP_KEYCODE_LEFT_CONTROL = 341, + SAPP_KEYCODE_LEFT_ALT = 342, + SAPP_KEYCODE_LEFT_SUPER = 343, + SAPP_KEYCODE_RIGHT_SHIFT = 344, + SAPP_KEYCODE_RIGHT_CONTROL = 345, + SAPP_KEYCODE_RIGHT_ALT = 346, + SAPP_KEYCODE_RIGHT_SUPER = 347, + SAPP_KEYCODE_MENU = 348, +} sapp_keycode; + +/* + Android specific 'tool type' enum for touch events. This lets the + application check what type of input device was used for + touch events. + + NOTE: the values must remain in sync with the corresponding + Android SDK type, so don't change those. + + See https://developer.android.com/reference/android/view/MotionEvent#TOOL_TYPE_UNKNOWN +*/ +typedef enum sapp_android_tooltype { + SAPP_ANDROIDTOOLTYPE_UNKNOWN = 0, // TOOL_TYPE_UNKNOWN + SAPP_ANDROIDTOOLTYPE_FINGER = 1, // TOOL_TYPE_FINGER + SAPP_ANDROIDTOOLTYPE_STYLUS = 2, // TOOL_TYPE_STYLUS + SAPP_ANDROIDTOOLTYPE_MOUSE = 3, // TOOL_TYPE_MOUSE +} sapp_android_tooltype; + +/* + sapp_touchpoint + + Describes a single touchpoint in a multitouch event (TOUCHES_BEGAN, + TOUCHES_MOVED, TOUCHES_ENDED). + + Touch points are stored in the nested array sapp_event.touches[], + and the number of touches is stored in sapp_event.num_touches. +*/ +typedef struct sapp_touchpoint { + uintptr_t identifier; + float pos_x; + float pos_y; + sapp_android_tooltype android_tooltype; // only valid on Android + bool changed; +} sapp_touchpoint; + +/* + sapp_mousebutton + + The currently pressed mouse button in the events MOUSE_DOWN + and MOUSE_UP, stored in the struct field sapp_event.mouse_button. +*/ +typedef enum sapp_mousebutton { + SAPP_MOUSEBUTTON_LEFT = 0x0, + SAPP_MOUSEBUTTON_RIGHT = 0x1, + SAPP_MOUSEBUTTON_MIDDLE = 0x2, + SAPP_MOUSEBUTTON_INVALID = 0x100, +} sapp_mousebutton; + +/* + These are currently pressed modifier keys (and mouse buttons) which are + passed in the event struct field sapp_event.modifiers. +*/ +enum { + SAPP_MODIFIER_SHIFT = 0x1, // left or right shift key + SAPP_MODIFIER_CTRL = 0x2, // left or right control key + SAPP_MODIFIER_ALT = 0x4, // left or right alt key + SAPP_MODIFIER_SUPER = 0x8, // left or right 'super' key + SAPP_MODIFIER_LMB = 0x100, // left mouse button + SAPP_MODIFIER_RMB = 0x200, // right mouse button + SAPP_MODIFIER_MMB = 0x400, // middle mouse button +}; + +/* + sapp_event + + This is an all-in-one event struct passed to the event handler + user callback function. Note that it depends on the event + type what struct fields actually contain useful values, so you + should first check the event type before reading other struct + fields. +*/ +typedef struct sapp_event { + uint64_t frame_count; // current frame counter, always valid, useful for checking if two events were issued in the same frame + sapp_event_type type; // the event type, always valid + sapp_keycode key_code; // the virtual key code, only valid in KEY_UP, KEY_DOWN + uint32_t char_code; // the UTF-32 character code, only valid in CHAR events + bool key_repeat; // true if this is a key-repeat event, valid in KEY_UP, KEY_DOWN and CHAR + uint32_t modifiers; // current modifier keys, valid in all key-, char- and mouse-events + sapp_mousebutton mouse_button; // mouse button that was pressed or released, valid in MOUSE_DOWN, MOUSE_UP + float mouse_x; // current horizontal mouse position in pixels, always valid except during mouse lock + float mouse_y; // current vertical mouse position in pixels, always valid except during mouse lock + float mouse_dx; // relative horizontal mouse movement since last frame, always valid + float mouse_dy; // relative vertical mouse movement since last frame, always valid + float scroll_x; // horizontal mouse wheel scroll distance, valid in MOUSE_SCROLL events + float scroll_y; // vertical mouse wheel scroll distance, valid in MOUSE_SCROLL events + int num_touches; // number of valid items in the touches[] array + sapp_touchpoint touches[SAPP_MAX_TOUCHPOINTS]; // current touch points, valid in TOUCHES_BEGIN, TOUCHES_MOVED, TOUCHES_ENDED + int window_width; // current window- and framebuffer sizes in pixels, always valid + int window_height; + int framebuffer_width; // = window_width * dpi_scale + int framebuffer_height; // = window_height * dpi_scale +} sapp_event; + +/* + sg_range + + A general pointer/size-pair struct and constructor macros for passing binary blobs + into sokol_app.h. +*/ +typedef struct sapp_range { + const void* ptr; + size_t size; +} sapp_range; +// disabling this for every includer isn't great, but the warnings are also quite pointless +#if defined(_MSC_VER) +#pragma warning(disable:4221) /* /W4 only: nonstandard extension used: 'x': cannot be initialized using address of automatic variable 'y' */ +#pragma warning(disable:4204) /* VS2015: nonstandard extension used: non-constant aggregate initializer */ +#endif +#if defined(__cplusplus) +#define SAPP_RANGE(x) sapp_range{ &x, sizeof(x) } +#else +#define SAPP_RANGE(x) (sapp_range){ &x, sizeof(x) } +#endif + +/* + sapp_image_desc + + This is used to describe image data to sokol_app.h (window icons and cursor images). + + The pixel format is RGBA8. + + cursor_hotspot_x and _y are used only for cursors, to define which pixel + of the image should be aligned with the mouse position. +*/ +typedef struct sapp_image_desc { + int width; + int height; + int cursor_hotspot_x; + int cursor_hotspot_y; + sapp_range pixels; +} sapp_image_desc; + +/* + sapp_icon_desc + + An icon description structure for use in sapp_desc.icon and + sapp_set_icon(). + + When setting a custom image, the application can provide a number of + candidates differing in size, and sokol_app.h will pick the image(s) + closest to the size expected by the platform's window system. + + To set sokol-app's default icon, set .sokol_default to true. + + Otherwise provide candidate images of different sizes in the + images[] array. + + If both the sokol_default flag is set to true, any image candidates + will be ignored and the sokol_app.h default icon will be set. +*/ +typedef struct sapp_icon_desc { + bool sokol_default; + sapp_image_desc images[SAPP_MAX_ICONIMAGES]; +} sapp_icon_desc; + +/* + sapp_allocator + + Used in sapp_desc to provide custom memory-alloc and -free functions + to sokol_app.h. If memory management should be overridden, both the + alloc_fn and free_fn function must be provided (e.g. it's not valid to + override one function but not the other). +*/ +typedef struct sapp_allocator { + void* (*alloc_fn)(size_t size, void* user_data); + void (*free_fn)(void* ptr, void* user_data); + void* user_data; +} sapp_allocator; + +/* + sapp_log_item + + Log items are defined via X-Macros and expanded to an enum + 'sapp_log_item', and in debug mode to corresponding + human readable error messages. +*/ +#define _SAPP_LOG_ITEMS \ + _SAPP_LOGITEM_XMACRO(OK, "Ok") \ + _SAPP_LOGITEM_XMACRO(MALLOC_FAILED, "memory allocation failed") \ + _SAPP_LOGITEM_XMACRO(MACOS_INVALID_NSOPENGL_PROFILE, "macos: invalid NSOpenGLProfile (valid choices are 1.0 and 4.1)") \ + _SAPP_LOGITEM_XMACRO(METAL_CREATE_SWAPCHAIN_DEPTH_TEXTURE_FAILED, "metal: failed to create swapchain depth-buffer texture") \ + _SAPP_LOGITEM_XMACRO(METAL_CREATE_SWAPCHAIN_MSAA_TEXTURE_FAILED, "metal: failed to create swapchain msaa texture") \ + _SAPP_LOGITEM_XMACRO(WIN32_LOAD_OPENGL32_DLL_FAILED, "failed loading opengl32.dll") \ + _SAPP_LOGITEM_XMACRO(WIN32_CREATE_HELPER_WINDOW_FAILED, "failed to create helper window") \ + _SAPP_LOGITEM_XMACRO(WIN32_HELPER_WINDOW_GETDC_FAILED, "failed to get helper window DC") \ + _SAPP_LOGITEM_XMACRO(WIN32_DUMMY_CONTEXT_SET_PIXELFORMAT_FAILED, "failed to set pixel format for dummy GL context") \ + _SAPP_LOGITEM_XMACRO(WIN32_CREATE_DUMMY_CONTEXT_FAILED, "failed to create dummy GL context") \ + _SAPP_LOGITEM_XMACRO(WIN32_DUMMY_CONTEXT_MAKE_CURRENT_FAILED, "failed to make dummy GL context current") \ + _SAPP_LOGITEM_XMACRO(WIN32_GET_PIXELFORMAT_ATTRIB_FAILED, "failed to get WGL pixel format attribute") \ + _SAPP_LOGITEM_XMACRO(WIN32_WGL_FIND_PIXELFORMAT_FAILED, "failed to find matching WGL pixel format") \ + _SAPP_LOGITEM_XMACRO(WIN32_WGL_DESCRIBE_PIXELFORMAT_FAILED, "failed to get pixel format descriptor") \ + _SAPP_LOGITEM_XMACRO(WIN32_WGL_SET_PIXELFORMAT_FAILED, "failed to set selected pixel format") \ + _SAPP_LOGITEM_XMACRO(WIN32_WGL_ARB_CREATE_CONTEXT_REQUIRED, "ARB_create_context required") \ + _SAPP_LOGITEM_XMACRO(WIN32_WGL_ARB_CREATE_CONTEXT_PROFILE_REQUIRED, "ARB_create_context_profile required") \ + _SAPP_LOGITEM_XMACRO(WIN32_WGL_OPENGL_VERSION_NOT_SUPPORTED, "requested OpenGL version not supported by GL driver (ERROR_INVALID_VERSION_ARB)") \ + _SAPP_LOGITEM_XMACRO(WIN32_WGL_OPENGL_PROFILE_NOT_SUPPORTED, "requested OpenGL profile not support by GL driver (ERROR_INVALID_PROFILE_ARB)") \ + _SAPP_LOGITEM_XMACRO(WIN32_WGL_INCOMPATIBLE_DEVICE_CONTEXT, "CreateContextAttribsARB failed with ERROR_INCOMPATIBLE_DEVICE_CONTEXTS_ARB") \ + _SAPP_LOGITEM_XMACRO(WIN32_WGL_CREATE_CONTEXT_ATTRIBS_FAILED_OTHER, "CreateContextAttribsARB failed for other reason") \ + _SAPP_LOGITEM_XMACRO(WIN32_D3D11_CREATE_DEVICE_AND_SWAPCHAIN_WITH_DEBUG_FAILED, "D3D11CreateDeviceAndSwapChain() with D3D11_CREATE_DEVICE_DEBUG failed, retrying without debug flag.") \ + _SAPP_LOGITEM_XMACRO(WIN32_D3D11_GET_IDXGIFACTORY_FAILED, "could not obtain IDXGIFactory object") \ + _SAPP_LOGITEM_XMACRO(WIN32_D3D11_GET_IDXGIADAPTER_FAILED, "could not obtain IDXGIAdapter object") \ + _SAPP_LOGITEM_XMACRO(WIN32_D3D11_QUERY_INTERFACE_IDXGIDEVICE1_FAILED, "could not obtain IDXGIDevice1 interface") \ + _SAPP_LOGITEM_XMACRO(WIN32_REGISTER_RAW_INPUT_DEVICES_FAILED_MOUSE_LOCK, "RegisterRawInputDevices() failed (on mouse lock)") \ + _SAPP_LOGITEM_XMACRO(WIN32_REGISTER_RAW_INPUT_DEVICES_FAILED_MOUSE_UNLOCK, "RegisterRawInputDevices() failed (on mouse unlock)") \ + _SAPP_LOGITEM_XMACRO(WIN32_GET_RAW_INPUT_DATA_FAILED, "GetRawInputData() failed") \ + _SAPP_LOGITEM_XMACRO(WIN32_DESTROYICON_FOR_CURSOR_FAILED, "DestroyIcon() for a cursor image failed") \ + _SAPP_LOGITEM_XMACRO(LINUX_GLX_LOAD_LIBGL_FAILED, "failed to load libGL") \ + _SAPP_LOGITEM_XMACRO(LINUX_GLX_LOAD_ENTRY_POINTS_FAILED, "failed to load GLX entry points") \ + _SAPP_LOGITEM_XMACRO(LINUX_GLX_EXTENSION_NOT_FOUND, "GLX extension not found") \ + _SAPP_LOGITEM_XMACRO(LINUX_GLX_QUERY_VERSION_FAILED, "failed to query GLX version") \ + _SAPP_LOGITEM_XMACRO(LINUX_GLX_VERSION_TOO_LOW, "GLX version too low (need at least 1.3)") \ + _SAPP_LOGITEM_XMACRO(LINUX_GLX_NO_GLXFBCONFIGS, "glXGetFBConfigs() returned no configs") \ + _SAPP_LOGITEM_XMACRO(LINUX_GLX_NO_SUITABLE_GLXFBCONFIG, "failed to find a suitable GLXFBConfig") \ + _SAPP_LOGITEM_XMACRO(LINUX_GLX_GET_VISUAL_FROM_FBCONFIG_FAILED, "glXGetVisualFromFBConfig failed") \ + _SAPP_LOGITEM_XMACRO(LINUX_GLX_REQUIRED_EXTENSIONS_MISSING, "GLX extensions ARB_create_context and ARB_create_context_profile missing") \ + _SAPP_LOGITEM_XMACRO(LINUX_GLX_CREATE_CONTEXT_FAILED, "Failed to create GL context via glXCreateContextAttribsARB") \ + _SAPP_LOGITEM_XMACRO(LINUX_GLX_CREATE_WINDOW_FAILED, "glXCreateWindow() failed") \ + _SAPP_LOGITEM_XMACRO(LINUX_X11_CREATE_WINDOW_FAILED, "XCreateWindow() failed") \ + _SAPP_LOGITEM_XMACRO(LINUX_EGL_BIND_OPENGL_API_FAILED, "eglBindAPI(EGL_OPENGL_API) failed") \ + _SAPP_LOGITEM_XMACRO(LINUX_EGL_BIND_OPENGL_ES_API_FAILED, "eglBindAPI(EGL_OPENGL_ES_API) failed") \ + _SAPP_LOGITEM_XMACRO(LINUX_EGL_GET_DISPLAY_FAILED, "eglGetDisplay() failed") \ + _SAPP_LOGITEM_XMACRO(LINUX_EGL_INITIALIZE_FAILED, "eglInitialize() failed") \ + _SAPP_LOGITEM_XMACRO(LINUX_EGL_NO_CONFIGS, "eglChooseConfig() returned no configs") \ + _SAPP_LOGITEM_XMACRO(LINUX_EGL_NO_NATIVE_VISUAL, "eglGetConfigAttrib() for EGL_NATIVE_VISUAL_ID failed") \ + _SAPP_LOGITEM_XMACRO(LINUX_EGL_GET_VISUAL_INFO_FAILED, "XGetVisualInfo() failed") \ + _SAPP_LOGITEM_XMACRO(LINUX_EGL_CREATE_WINDOW_SURFACE_FAILED, "eglCreateWindowSurface() failed") \ + _SAPP_LOGITEM_XMACRO(LINUX_EGL_CREATE_CONTEXT_FAILED, "eglCreateContext() failed") \ + _SAPP_LOGITEM_XMACRO(LINUX_EGL_MAKE_CURRENT_FAILED, "eglMakeCurrent() failed") \ + _SAPP_LOGITEM_XMACRO(LINUX_X11_OPEN_DISPLAY_FAILED, "XOpenDisplay() failed") \ + _SAPP_LOGITEM_XMACRO(LINUX_X11_QUERY_SYSTEM_DPI_FAILED, "failed to query system dpi value, assuming default 96.0") \ + _SAPP_LOGITEM_XMACRO(LINUX_X11_DROPPED_FILE_URI_WRONG_SCHEME, "dropped file URL doesn't start with 'file://'") \ + _SAPP_LOGITEM_XMACRO(LINUX_X11_FAILED_TO_BECOME_OWNER_OF_CLIPBOARD, "X11: Failed to become owner of clipboard selection") \ + _SAPP_LOGITEM_XMACRO(ANDROID_UNSUPPORTED_INPUT_EVENT_INPUT_CB, "unsupported input event encountered in _sapp_android_input_cb()") \ + _SAPP_LOGITEM_XMACRO(ANDROID_UNSUPPORTED_INPUT_EVENT_MAIN_CB, "unsupported input event encountered in _sapp_android_main_cb()") \ + _SAPP_LOGITEM_XMACRO(ANDROID_READ_MSG_FAILED, "failed to read message in _sapp_android_main_cb()") \ + _SAPP_LOGITEM_XMACRO(ANDROID_WRITE_MSG_FAILED, "failed to write message in _sapp_android_msg") \ + _SAPP_LOGITEM_XMACRO(ANDROID_MSG_CREATE, "MSG_CREATE") \ + _SAPP_LOGITEM_XMACRO(ANDROID_MSG_RESUME, "MSG_RESUME") \ + _SAPP_LOGITEM_XMACRO(ANDROID_MSG_PAUSE, "MSG_PAUSE") \ + _SAPP_LOGITEM_XMACRO(ANDROID_MSG_FOCUS, "MSG_FOCUS") \ + _SAPP_LOGITEM_XMACRO(ANDROID_MSG_NO_FOCUS, "MSG_NO_FOCUS") \ + _SAPP_LOGITEM_XMACRO(ANDROID_MSG_SET_NATIVE_WINDOW, "MSG_SET_NATIVE_WINDOW") \ + _SAPP_LOGITEM_XMACRO(ANDROID_MSG_SET_INPUT_QUEUE, "MSG_SET_INPUT_QUEUE") \ + _SAPP_LOGITEM_XMACRO(ANDROID_MSG_DESTROY, "MSG_DESTROY") \ + _SAPP_LOGITEM_XMACRO(ANDROID_UNKNOWN_MSG, "unknown msg type received") \ + _SAPP_LOGITEM_XMACRO(ANDROID_LOOP_THREAD_STARTED, "loop thread started") \ + _SAPP_LOGITEM_XMACRO(ANDROID_LOOP_THREAD_DONE, "loop thread done") \ + _SAPP_LOGITEM_XMACRO(ANDROID_NATIVE_ACTIVITY_ONSTART, "NativeActivity onStart()") \ + _SAPP_LOGITEM_XMACRO(ANDROID_NATIVE_ACTIVITY_ONRESUME, "NativeActivity onResume") \ + _SAPP_LOGITEM_XMACRO(ANDROID_NATIVE_ACTIVITY_ONSAVEINSTANCESTATE, "NativeActivity onSaveInstanceState") \ + _SAPP_LOGITEM_XMACRO(ANDROID_NATIVE_ACTIVITY_ONWINDOWFOCUSCHANGED, "NativeActivity onWindowFocusChanged") \ + _SAPP_LOGITEM_XMACRO(ANDROID_NATIVE_ACTIVITY_ONPAUSE, "NativeActivity onPause") \ + _SAPP_LOGITEM_XMACRO(ANDROID_NATIVE_ACTIVITY_ONSTOP, "NativeActivity onStop()") \ + _SAPP_LOGITEM_XMACRO(ANDROID_NATIVE_ACTIVITY_ONNATIVEWINDOWCREATED, "NativeActivity onNativeWindowCreated") \ + _SAPP_LOGITEM_XMACRO(ANDROID_NATIVE_ACTIVITY_ONNATIVEWINDOWDESTROYED, "NativeActivity onNativeWindowDestroyed") \ + _SAPP_LOGITEM_XMACRO(ANDROID_NATIVE_ACTIVITY_ONINPUTQUEUECREATED, "NativeActivity onInputQueueCreated") \ + _SAPP_LOGITEM_XMACRO(ANDROID_NATIVE_ACTIVITY_ONINPUTQUEUEDESTROYED, "NativeActivity onInputQueueDestroyed") \ + _SAPP_LOGITEM_XMACRO(ANDROID_NATIVE_ACTIVITY_ONCONFIGURATIONCHANGED, "NativeActivity onConfigurationChanged") \ + _SAPP_LOGITEM_XMACRO(ANDROID_NATIVE_ACTIVITY_ONLOWMEMORY, "NativeActivity onLowMemory") \ + _SAPP_LOGITEM_XMACRO(ANDROID_NATIVE_ACTIVITY_ONDESTROY, "NativeActivity onDestroy") \ + _SAPP_LOGITEM_XMACRO(ANDROID_NATIVE_ACTIVITY_DONE, "NativeActivity done") \ + _SAPP_LOGITEM_XMACRO(ANDROID_NATIVE_ACTIVITY_ONCREATE, "NativeActivity onCreate") \ + _SAPP_LOGITEM_XMACRO(ANDROID_CREATE_THREAD_PIPE_FAILED, "failed to create thread pipe") \ + _SAPP_LOGITEM_XMACRO(ANDROID_NATIVE_ACTIVITY_CREATE_SUCCESS, "NativeActivity successfully created") \ + _SAPP_LOGITEM_XMACRO(ANDROID_CHOREOGRAPHER_ENABLED, "Choreographer frame loop enabled") \ + _SAPP_LOGITEM_XMACRO(ANDROID_CHOREOGRAPHER_UNAVAILABLE, "Choreographer unavailable, using poll loop") \ + _SAPP_LOGITEM_XMACRO(WGPU_DEVICE_LOST, "wgpu: device lost") \ + _SAPP_LOGITEM_XMACRO(WGPU_DEVICE_LOG, "wgpu: device log") \ + _SAPP_LOGITEM_XMACRO(WGPU_DEVICE_UNCAPTURED_ERROR, "wgpu: uncaptured error") \ + _SAPP_LOGITEM_XMACRO(WGPU_SWAPCHAIN_CREATE_SURFACE_FAILED, "wgpu: failed to create surface for swapchain") \ + _SAPP_LOGITEM_XMACRO(WGPU_SWAPCHAIN_SURFACE_GET_CAPABILITIES_FAILED, "wgpu: wgpuSurfaceGetCapabilities failed") \ + _SAPP_LOGITEM_XMACRO(WGPU_SWAPCHAIN_CREATE_DEPTH_STENCIL_TEXTURE_FAILED, "wgpu: failed to create depth-stencil texture for swapchain") \ + _SAPP_LOGITEM_XMACRO(WGPU_SWAPCHAIN_CREATE_DEPTH_STENCIL_VIEW_FAILED, "wgpu: failed to create view object for swapchain depth-stencil texture") \ + _SAPP_LOGITEM_XMACRO(WGPU_SWAPCHAIN_CREATE_MSAA_TEXTURE_FAILED, "wgpu: failed to create msaa texture for swapchain") \ + _SAPP_LOGITEM_XMACRO(WGPU_SWAPCHAIN_CREATE_MSAA_VIEW_FAILED, "wgpu: failed to create view object for swapchain msaa texture") \ + _SAPP_LOGITEM_XMACRO(WGPU_SWAPCHAIN_GETCURRENTTEXTURE_FAILED, "wgpu: wgpuSurfaceGetCurrentTexture() failed") \ + _SAPP_LOGITEM_XMACRO(WGPU_REQUEST_DEVICE_STATUS_ERROR, "wgpu: requesting device failed with status 'error'") \ + _SAPP_LOGITEM_XMACRO(WGPU_REQUEST_DEVICE_STATUS_UNKNOWN, "wgpu: requesting device failed with status 'unknown'") \ + _SAPP_LOGITEM_XMACRO(WGPU_REQUEST_ADAPTER_STATUS_UNAVAILABLE, "wgpu: requesting adapter failed with 'unavailable'") \ + _SAPP_LOGITEM_XMACRO(WGPU_REQUEST_ADAPTER_STATUS_ERROR, "wgpu: requesting adapter failed with status 'error'") \ + _SAPP_LOGITEM_XMACRO(WGPU_REQUEST_ADAPTER_STATUS_UNKNOWN, "wgpu: requesting adapter failed with status 'unknown'") \ + _SAPP_LOGITEM_XMACRO(WGPU_CREATE_INSTANCE_FAILED, "wgpu: failed to create instance") \ + _SAPP_LOGITEM_XMACRO(VULKAN_REQUIRED_INSTANCE_EXTENSION_FUNCTION_MISSING, "vulkan: could not lookup a required instance extension function pointer") \ + _SAPP_LOGITEM_XMACRO(VULKAN_ALLOC_DEVICE_MEMORY_NO_SUITABLE_MEMORY_TYPE, "vulkan: could not find suitable memory type") \ + _SAPP_LOGITEM_XMACRO(VULKAN_ALLOCATE_MEMORY_FAILED, "vulkan: vkAllocateMemory() failed!") \ + _SAPP_LOGITEM_XMACRO(VULKAN_CREATE_INSTANCE_FAILED, "vulkan: vkCreateInstance failed") \ + _SAPP_LOGITEM_XMACRO(VULKAN_ENUMERATE_PHYSICAL_DEVICES_FAILED, "vulkan: vkEnumeratePhysicalDevices failed") \ + _SAPP_LOGITEM_XMACRO(VULKAN_NO_PHYSICAL_DEVICES_FOUND, "vulkan: vkEnumeratePhysicalDevices return no devices") \ + _SAPP_LOGITEM_XMACRO(VULKAN_NO_SUITABLE_PHYSICAL_DEVICE_FOUND, "vulkan: no suitable physical device found") \ + _SAPP_LOGITEM_XMACRO(VULKAN_CREATE_DEVICE_FAILED_EXTENSION_NOT_PRESENT, "vulkan: vkCreateDevice failed (extension not present)") \ + _SAPP_LOGITEM_XMACRO(VULKAN_CREATE_DEVICE_FAILED_FEATURE_NOT_PRESENT, "vulkan: vkCreateDevice failed (feature not present)") \ + _SAPP_LOGITEM_XMACRO(VULKAN_CREATE_DEVICE_FAILED_INITIALIZATION_FAILED, "vulkan: vkCreateDevice failed (initialization failed)") \ + _SAPP_LOGITEM_XMACRO(VULKAN_CREATE_DEVICE_FAILED_OTHER, "vulkan: vkCreateDevice failed (other)") \ + _SAPP_LOGITEM_XMACRO(VULKAN_CREATE_SURFACE_FAILED, "vulkan: vkCreate*SurfaceKHR failed") \ + _SAPP_LOGITEM_XMACRO(VULKAN_CREATE_SWAPCHAIN_FAILED, "vulkan: vkCreateSwapchainKHR failed") \ + _SAPP_LOGITEM_XMACRO(VULKAN_SWAPCHAIN_CREATE_IMAGE_VIEW_FAILED, "vulkan: vkCreateImageView for swapchain image failed") \ + _SAPP_LOGITEM_XMACRO(VULKAN_SWAPCHAIN_CREATE_IMAGE_FAILED, "vulkan: vkCreateImage for depth-stencil image failed") \ + _SAPP_LOGITEM_XMACRO(VULKAN_SWAPCHAIN_ALLOC_IMAGE_DEVICE_MEMORY_FAILED, "vulkan: failed to allocate device memory for depth-stencil image") \ + _SAPP_LOGITEM_XMACRO(VULKAN_SWAPCHAIN_BIND_IMAGE_MEMORY_FAILED, "vulkan: vkBindImageMemory() for depth-stencil image failed") \ + _SAPP_LOGITEM_XMACRO(VULKAN_ACQUIRE_NEXT_IMAGE_FAILED, "vulkan: vkAcquireNextImageKHR failed") \ + _SAPP_LOGITEM_XMACRO(VULKAN_QUEUE_PRESENT_FAILED, "vulkan: vkQueuePresentKHR failed") \ + _SAPP_LOGITEM_XMACRO(IMAGE_DATA_SIZE_MISMATCH, "image data size mismatch (must be width*height*4 bytes)") \ + _SAPP_LOGITEM_XMACRO(DROPPED_FILE_PATH_TOO_LONG, "dropped file path too long (sapp_desc.max_dropped_filed_path_length)") \ + _SAPP_LOGITEM_XMACRO(CLIPBOARD_STRING_TOO_BIG, "clipboard string didn't fit into clipboard buffer") \ + +#define _SAPP_LOGITEM_XMACRO(item,msg) SAPP_LOGITEM_##item, +typedef enum sapp_log_item { + _SAPP_LOG_ITEMS +} sapp_log_item; +#undef _SAPP_LOGITEM_XMACRO + +/* + sapp_pixel_format + + Defines the pixel format for swapchain surfaces. + + NOTE: when using sokol_gfx.h do not assume that the underlying + values are compatible with sg_pixel_format! + +*/ +typedef enum sapp_pixel_format { + _SAPP_PIXELFORMAT_DEFAULT, + SAPP_PIXELFORMAT_NONE, + SAPP_PIXELFORMAT_RGBA8, + SAPP_PIXELFORMAT_SRGB8A8, + SAPP_PIXELFORMAT_BGRA8, + SAPP_PIXELFORMAT_SBGRA8, + SAPP_PIXELFORMAT_DEPTH, + SAPP_PIXELFORMAT_DEPTH_STENCIL, + _SAPP_PIXELFORMAT_FORCE_U32 = 0x7FFFFFFF +} sapp_pixel_format; + +/* + sapp_environment + + Used to provide runtime environment information to the + outside world (like default pixel formats and the backend + 3D API device pointer) via a call to sapp_get_environment(). + + NOTE: when using sokol_gfx.h, don't assume that sapp_environment + is binary compatible with sg_environment! Always use a translation + function like sglue_environment() to populate sg_environment + from sapp_environment! +*/ +typedef struct sapp_environment_defaults { + sapp_pixel_format color_format; + sapp_pixel_format depth_format; + int sample_count; +} sapp_environment_defaults; + +typedef struct sapp_metal_environment { + const void* device; +} sapp_metal_environment; + +typedef struct sapp_d3d11_environment { + const void* device; + const void* device_context; +} sapp_d3d11_environment; + +typedef struct sapp_wgpu_environment { + const void* device; +} sapp_wgpu_environment; + +typedef struct sapp_vulkan_environment { + const void* instance; + const void* physical_device; + const void* device; + const void* queue; + uint32_t queue_family_index; +} sapp_vulkan_environment; + +typedef struct sapp_environment { + sapp_environment_defaults defaults; + sapp_metal_environment metal; + sapp_d3d11_environment d3d11; + sapp_wgpu_environment wgpu; + sapp_vulkan_environment vulkan; +} sapp_environment; + +/* + sapp_swapchain + + Provides swapchain information for the current frame to the outside + world via a call to sapp_get_swapchain(). + + NOTE: sapp_get_swapchain() must be called exactly once per frame since + on some backends it will also acquire the next swapchain image. + + NOTE: when using sokol_gfx.h, don't assume that the sapp_swapchain struct + has the same memory layout as sg_swapchain! Use the sokol_log.h helper + function sglue_swapchain() to translate sapp_swapchain into a + sg_swapchain instead. +*/ +typedef struct sapp_metal_swapchain { + const void* current_drawable; // CAMetalDrawable (NOT MTLDrawable!!!) + const void* depth_stencil_texture; // MTLTexture + const void* msaa_color_texture; // MTLTexture +} sapp_metal_swapchain; + +typedef struct sapp_d3d11_swapchain { + const void* render_view; // ID3D11RenderTargetView + const void* resolve_view; // ID3D11RenderTargetView + const void* depth_stencil_view; // ID3D11DepthStencilView +} sapp_d3d11_swapchain; + +typedef struct sapp_wgpu_swapchain { + const void* render_view; // WGPUTextureView + const void* resolve_view; // WGPUTextureView + const void* depth_stencil_view; // WGPUTextureView +} sapp_wgpu_swapchain; + +typedef struct sapp_vulkan_swapchain { + const void* render_image; // vkImage + const void* render_view; // vkImageView + const void* resolve_image; // vkImage; + const void* resolve_view; // vkImageView + const void* depth_stencil_image; // vkImage + const void* depth_stencil_view; // vkImageView + const void* render_finished_semaphore; // vkSemaphore + const void* present_complete_semaphore; // vkSemaphore +} sapp_vulkan_swapchain; + +typedef struct sapp_gl_swapchain { + uint32_t framebuffer; // GL framebuffer object +} sapp_gl_swapchain; + +typedef struct sapp_swapchain { + int width; + int height; + int sample_count; + sapp_pixel_format color_format; + sapp_pixel_format depth_format; + sapp_metal_swapchain metal; + sapp_d3d11_swapchain d3d11; + sapp_wgpu_swapchain wgpu; + sapp_vulkan_swapchain vulkan; + sapp_gl_swapchain gl; +} sapp_swapchain; + +/* + sapp_logger + + Used in sapp_desc to provide a logging function. Please be aware that + without logging function, sokol-app will be completely silent, e.g. it will + not report errors or warnings. For maximum error verbosity, compile in + debug mode (e.g. NDEBUG *not* defined) and install a logger (for instance + the standard logging function from sokol_log.h). +*/ +typedef struct sapp_logger { + void (*func)( + const char* tag, // always "sapp" + uint32_t log_level, // 0=panic, 1=error, 2=warning, 3=info + uint32_t log_item_id, // SAPP_LOGITEM_* + const char* message_or_null, // a message string, may be nullptr in release mode + uint32_t line_nr, // line number in sokol_app.h + const char* filename_or_null, // source filename, may be nullptr in release mode + void* user_data); + void* user_data; +} sapp_logger; + +/* + sokol-app initialization options, used as return value of sokol_main() + or sapp_run() argument. +*/ +typedef struct sapp_gl_desc { + int major_version; // override GL/GLES major and minor version (defaults: GL4.1 (macOS) or GL4.3, GLES3.1 (Android) or GLES3.0 + int minor_version; +} sapp_gl_desc; + +typedef struct sapp_win32_desc { + bool console_utf8; // if true, set the output console codepage to UTF-8 + bool console_create; // if true, attach stdout/stderr to a new console window + bool console_attach; // if true, attach stdout/stderr to parent process +} sapp_win32_desc; + +typedef struct sapp_html5_desc { + const char* canvas_selector; // css selector of the HTML5 canvas element, default is "#canvas" + bool canvas_resize; // if true, the HTML5 canvas size is set to sapp_desc.width/height, otherwise canvas size is tracked + bool preserve_drawing_buffer; // HTML5 only: whether to preserve default framebuffer content between frames + bool premultiplied_alpha; // HTML5 only: whether the rendered pixels use premultiplied alpha convention + bool ask_leave_site; // initial state of the internal html5_ask_leave_site flag (see sapp_html5_ask_leave_site()) + bool update_document_title; // if true, update the HTML document.title with sapp_desc.window_title + bool bubble_mouse_events; // if true, mouse events will bubble up to the web page + bool bubble_touch_events; // same for touch events + bool bubble_wheel_events; // same for wheel events + bool bubble_key_events; // if true, bubble up *all* key events to browser, not just key events that represent characters + bool bubble_char_events; // if true, bubble up character events to browser + bool use_emsc_set_main_loop; // if true, use emscripten_set_main_loop() instead of emscripten_request_animation_frame_loop() + bool emsc_set_main_loop_simulate_infinite_loop; // this will be passed as the simulate_infinite_loop arg to emscripten_set_main_loop() +} sapp_html5_desc; + +typedef struct sapp_ios_desc { + bool keyboard_resizes_canvas; // if true, showing the iOS keyboard shrinks the canvas +} sapp_ios_desc; + +typedef struct sapp_desc { + void (*init_cb)(void); // these are the user-provided callbacks without user data + void (*frame_cb)(void); + void (*cleanup_cb)(void); + void (*event_cb)(const sapp_event*); + + void* user_data; // these are the user-provided callbacks with user data + void (*init_userdata_cb)(void*); + void (*frame_userdata_cb)(void*); + void (*cleanup_userdata_cb)(void*); + void (*event_userdata_cb)(const sapp_event*, void*); + + int width; // the preferred width of the window / canvas + int height; // the preferred height of the window / canvas + int sample_count; // MSAA sample count + int swap_interval; // the preferred swap interval (ignored on some platforms) + bool high_dpi; // whether the rendering canvas is full-resolution on HighDPI displays + bool fullscreen; // whether the window should be created in fullscreen mode + bool alpha; // whether the framebuffer should have an alpha channel (ignored on some platforms) + const char* window_title; // the window title as UTF-8 encoded string + bool enable_clipboard; // enable clipboard access, default is false + int clipboard_size; // max size of clipboard content in bytes + bool enable_dragndrop; // enable file dropping (drag'n'drop), default is false + int max_dropped_files; // max number of dropped files to process (default: 1) + int max_dropped_file_path_length; // max length in bytes of a dropped UTF-8 file path (default: 2048) + sapp_icon_desc icon; // the initial window icon to set + sapp_allocator allocator; // optional memory allocation overrides (default: malloc/free) + sapp_logger logger; // logging callback override (default: NO LOGGING!) + + // backend-specific options + sapp_gl_desc gl; + sapp_win32_desc win32; + sapp_html5_desc html5; + sapp_ios_desc ios; +} sapp_desc; + +/* HTML5 specific: request and response structs for + asynchronously loading dropped-file content. +*/ +typedef enum sapp_html5_fetch_error { + SAPP_HTML5_FETCH_ERROR_NO_ERROR, + SAPP_HTML5_FETCH_ERROR_BUFFER_TOO_SMALL, + SAPP_HTML5_FETCH_ERROR_OTHER, +} sapp_html5_fetch_error; + +typedef struct sapp_html5_fetch_response { + bool succeeded; // true if the loading operation has succeeded + sapp_html5_fetch_error error_code; + int file_index; // index of the dropped file (0..sapp_get_num_dropped_filed()-1) + sapp_range data; // pointer and size of the fetched data (data.ptr == buffer.ptr, data.size <= buffer.size) + sapp_range buffer; // the user-provided buffer ptr/size pair (buffer.ptr == data.ptr, buffer.size >= data.size) + void* user_data; // user-provided user data pointer +} sapp_html5_fetch_response; + +typedef struct sapp_html5_fetch_request { + int dropped_file_index; // 0..sapp_get_num_dropped_files()-1 + void (*callback)(const sapp_html5_fetch_response*); // response callback function pointer (required) + sapp_range buffer; // ptr/size of a memory buffer to load the data into + void* user_data; // optional userdata pointer +} sapp_html5_fetch_request; + +/* + sapp_mouse_cursor + + Predefined cursor image definitions, set with sapp_set_mouse_cursor(sapp_mouse_cursor cursor) +*/ +typedef enum sapp_mouse_cursor { + SAPP_MOUSECURSOR_DEFAULT = 0, // equivalent with system default cursor + SAPP_MOUSECURSOR_ARROW, + SAPP_MOUSECURSOR_IBEAM, + SAPP_MOUSECURSOR_CROSSHAIR, + SAPP_MOUSECURSOR_POINTING_HAND, + SAPP_MOUSECURSOR_RESIZE_EW, + SAPP_MOUSECURSOR_RESIZE_NS, + SAPP_MOUSECURSOR_RESIZE_NWSE, + SAPP_MOUSECURSOR_RESIZE_NESW, + SAPP_MOUSECURSOR_RESIZE_ALL, + SAPP_MOUSECURSOR_NOT_ALLOWED, + SAPP_MOUSECURSOR_CUSTOM_0, + SAPP_MOUSECURSOR_CUSTOM_1, + SAPP_MOUSECURSOR_CUSTOM_2, + SAPP_MOUSECURSOR_CUSTOM_3, + SAPP_MOUSECURSOR_CUSTOM_4, + SAPP_MOUSECURSOR_CUSTOM_5, + SAPP_MOUSECURSOR_CUSTOM_6, + SAPP_MOUSECURSOR_CUSTOM_7, + SAPP_MOUSECURSOR_CUSTOM_8, + SAPP_MOUSECURSOR_CUSTOM_9, + SAPP_MOUSECURSOR_CUSTOM_10, + SAPP_MOUSECURSOR_CUSTOM_11, + SAPP_MOUSECURSOR_CUSTOM_12, + SAPP_MOUSECURSOR_CUSTOM_13, + SAPP_MOUSECURSOR_CUSTOM_14, + SAPP_MOUSECURSOR_CUSTOM_15, + _SAPP_MOUSECURSOR_NUM, +} sapp_mouse_cursor; + +/* user-provided functions */ +extern sapp_desc sokol_main(int argc, char* argv[]); + +/* returns true after sokol-app has been initialized */ +SOKOL_APP_API_DECL bool sapp_isvalid(void); +/* returns the current framebuffer width in pixels */ +SOKOL_APP_API_DECL int sapp_width(void); +/* same as sapp_width(), but returns float */ +SOKOL_APP_API_DECL float sapp_widthf(void); +/* returns the current framebuffer height in pixels */ +SOKOL_APP_API_DECL int sapp_height(void); +/* same as sapp_height(), but returns float */ +SOKOL_APP_API_DECL float sapp_heightf(void); +/* get default framebuffer color pixel format */ +SOKOL_APP_API_DECL sapp_pixel_format sapp_color_format(void); +/* get default framebuffer depth pixel format */ +SOKOL_APP_API_DECL sapp_pixel_format sapp_depth_format(void); +/* get default framebuffer sample count */ +SOKOL_APP_API_DECL int sapp_sample_count(void); +/* returns true when high_dpi was requested and actually running in a high-dpi scenario */ +SOKOL_APP_API_DECL bool sapp_high_dpi(void); +/* returns the dpi scaling factor (window pixels to framebuffer pixels) */ +SOKOL_APP_API_DECL float sapp_dpi_scale(void); +/* show or hide the mobile device onscreen keyboard */ +SOKOL_APP_API_DECL void sapp_show_keyboard(bool show); +/* return true if the mobile device onscreen keyboard is currently shown */ +SOKOL_APP_API_DECL bool sapp_keyboard_shown(void); +/* query fullscreen mode */ +SOKOL_APP_API_DECL bool sapp_is_fullscreen(void); +/* toggle fullscreen mode */ +SOKOL_APP_API_DECL void sapp_toggle_fullscreen(void); +/* show or hide the mouse cursor */ +SOKOL_APP_API_DECL void sapp_show_mouse(bool show); +/* show or hide the mouse cursor */ +SOKOL_APP_API_DECL bool sapp_mouse_shown(void); +/* enable/disable mouse-pointer-lock mode */ +SOKOL_APP_API_DECL void sapp_lock_mouse(bool lock); +/* return true if in mouse-pointer-lock mode (this may toggle a few frames later) */ +SOKOL_APP_API_DECL bool sapp_mouse_locked(void); +/* set mouse cursor type */ +SOKOL_APP_API_DECL void sapp_set_mouse_cursor(sapp_mouse_cursor cursor); +/* get current mouse cursor type */ +SOKOL_APP_API_DECL sapp_mouse_cursor sapp_get_mouse_cursor(void); +/* associate a custom mouse cursor image to a sapp_mouse_cursor enum entry */ +SOKOL_APP_API_DECL sapp_mouse_cursor sapp_bind_mouse_cursor_image(sapp_mouse_cursor cursor, const sapp_image_desc* desc); +/* restore the sapp_mouse_cursor enum entry to it's default system appearance */ +SOKOL_APP_API_DECL void sapp_unbind_mouse_cursor_image(sapp_mouse_cursor cursor); +/* return the userdata pointer optionally provided in sapp_desc */ +SOKOL_APP_API_DECL void* sapp_userdata(void); +/* return a copy of the sapp_desc structure */ +SOKOL_APP_API_DECL sapp_desc sapp_query_desc(void); +/* initiate a "soft quit" (sends SAPP_EVENTTYPE_QUIT_REQUESTED) */ +SOKOL_APP_API_DECL void sapp_request_quit(void); +/* cancel a pending quit (when SAPP_EVENTTYPE_QUIT_REQUESTED has been received) */ +SOKOL_APP_API_DECL void sapp_cancel_quit(void); +/* initiate a "hard quit" (quit application without sending SAPP_EVENTTYPE_QUIT_REQUESTED) */ +SOKOL_APP_API_DECL void sapp_quit(void); +/* call from inside event callback to consume the current event (don't forward to platform) */ +SOKOL_APP_API_DECL void sapp_consume_event(void); +/* get the current frame counter (for comparison with sapp_event.frame_count) */ +SOKOL_APP_API_DECL uint64_t sapp_frame_count(void); +/* get an averaged/smoothed frame duration in seconds */ +SOKOL_APP_API_DECL double sapp_frame_duration(void); +/* get 'raw' unfiltered frame duration in seconds */ +SOKOL_APP_API_DECL double sapp_frame_duration_unfiltered(void); +/* write string into clipboard */ +SOKOL_APP_API_DECL void sapp_set_clipboard_string(const char* str); +/* read string from clipboard (usually during SAPP_EVENTTYPE_CLIPBOARD_PASTED) */ +SOKOL_APP_API_DECL const char* sapp_get_clipboard_string(void); +/* set the window title (only on desktop platforms) */ +SOKOL_APP_API_DECL void sapp_set_window_title(const char* str); +/* set the window icon (only on Windows and Linux) */ +SOKOL_APP_API_DECL void sapp_set_icon(const sapp_icon_desc* icon_desc); +/* gets the total number of dropped files (after an SAPP_EVENTTYPE_FILES_DROPPED event) */ +SOKOL_APP_API_DECL int sapp_get_num_dropped_files(void); +/* gets the dropped file paths */ +SOKOL_APP_API_DECL const char* sapp_get_dropped_file_path(int index); + +/* special run-function for SOKOL_NO_ENTRY (in standard mode this is an empty stub) */ +SOKOL_APP_API_DECL void sapp_run(const sapp_desc* desc); + +/* get runtime environment information */ +SOKOL_APP_API_DECL sapp_environment sapp_get_environment(void); +/* get current frame's swapchain information (call once per frame!) */ +SOKOL_APP_API_DECL sapp_swapchain sapp_get_swapchain(void); + +/* EGL: get EGLDisplay object */ +SOKOL_APP_API_DECL const void* sapp_egl_get_display(void); +/* EGL: get EGLContext object */ +SOKOL_APP_API_DECL const void* sapp_egl_get_context(void); + +/* HTML5: enable or disable the hardwired "Leave Site?" dialog box */ +SOKOL_APP_API_DECL void sapp_html5_ask_leave_site(bool ask); +/* HTML5: get byte size of a dropped file */ +SOKOL_APP_API_DECL uint32_t sapp_html5_get_dropped_file_size(int index); +/* HTML5: asynchronously load the content of a dropped file */ +SOKOL_APP_API_DECL void sapp_html5_fetch_dropped_file(const sapp_html5_fetch_request* request); + +/* macOS: get bridged pointer to macOS NSWindow */ +SOKOL_APP_API_DECL const void* sapp_macos_get_window(void); +/* iOS: get bridged pointer to iOS UIWindow */ +SOKOL_APP_API_DECL const void* sapp_ios_get_window(void); + +/* D3D11: get pointer to IDXGISwapChain object */ +SOKOL_APP_API_DECL const void* sapp_d3d11_get_swap_chain(void); + +/* Win32: get the HWND window handle */ +SOKOL_APP_API_DECL const void* sapp_win32_get_hwnd(void); + +/* GL: get major version */ +SOKOL_APP_API_DECL int sapp_gl_get_major_version(void); +/* GL: get minor version */ +SOKOL_APP_API_DECL int sapp_gl_get_minor_version(void); +/* GL: return true if the context is GLES */ +SOKOL_APP_API_DECL bool sapp_gl_is_gles(void); + +/* X11: get Window */ +SOKOL_APP_API_DECL const void* sapp_x11_get_window(void); +/* X11: get Display */ +SOKOL_APP_API_DECL const void* sapp_x11_get_display(void); + +/* Android: get native activity handle */ +SOKOL_APP_API_DECL const void* sapp_android_get_native_activity(void); + +#ifdef __cplusplus +} /* extern "C" */ + +/* reference-based equivalents for C++ */ +inline void sapp_run(const sapp_desc& desc) { return sapp_run(&desc); } + +#endif + +#endif // SOKOL_APP_INCLUDED + +// ██ ███ ███ ██████ ██ ███████ ███ ███ ███████ ███ ██ ████████ █████ ████████ ██ ██████ ███ ██ +// ██ ████ ████ ██ ██ ██ ██ ████ ████ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ +// ██ ██ ████ ██ ██████ ██ █████ ██ ████ ██ █████ ██ ██ ██ ██ ███████ ██ ██ ██ ██ ██ ██ ██ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ██ ██ ██ ██ ███████ ███████ ██ ██ ███████ ██ ████ ██ ██ ██ ██ ██ ██████ ██ ████ +// +// >>implementation +#ifdef SOKOL_APP_IMPL +#define SOKOL_APP_IMPL_INCLUDED (1) + +#if defined(SOKOL_MALLOC) || defined(SOKOL_CALLOC) || defined(SOKOL_FREE) +#error "SOKOL_MALLOC/CALLOC/FREE macros are no longer supported, please use sapp_desc.allocator to override memory allocation functions" +#endif + +#include // malloc, free +#include // memset, strncmp +#include // size_t +#include // roundf + +// helper macros +#define _sapp_def(val, def) (((val) == 0) ? (def) : (val)) +#define _sapp_absf(a) (((a)<0.0f)?-(a):(a)) + +#ifdef __cplusplus +#define _SAPP_STRUCT(TYPE, NAME) TYPE NAME = {} +#else +#define _SAPP_STRUCT(TYPE, NAME) TYPE NAME = {0} +#endif + +#define _SAPP_MAX_TITLE_LENGTH (128) +#define _SAPP_FALLBACK_DEFAULT_WINDOW_WIDTH (640) +#define _SAPP_FALLBACK_DEFAULT_WINDOW_HEIGHT (480) + +// check if the config defines are alright +#if defined(__APPLE__) + // see https://clang.llvm.org/docs/LanguageExtensions.html#automatic-reference-counting + #if !defined(__cplusplus) + #if __has_feature(objc_arc) && !__has_feature(objc_arc_fields) + #error "sokol_app.h requires __has_feature(objc_arc_field) if ARC is enabled (use a more recent compiler version)" + #endif + #endif + #define _SAPP_APPLE (1) + #include + #if defined(TARGET_OS_IPHONE) && !TARGET_OS_IPHONE + // MacOS + #define _SAPP_MACOS (1) + #if !defined(SOKOL_METAL) && !defined(SOKOL_GLCORE) && !defined(SOKOL_WGPU) + #error("sokol_app.h: unknown 3D API selected for MacOS, must be SOKOL_METAL, SOKOL_GLCORE or SOKOL_WGPU") + #endif + #else + // iOS or iOS Simulator + #define _SAPP_IOS (1) + #if !defined(SOKOL_METAL) && !defined(SOKOL_GLES3) + #error("sokol_app.h: unknown 3D API selected for iOS, must be SOKOL_METAL or SOKOL_GLES3") + #endif + #if TARGET_OS_TV + #define _SAPP_TVOS (1) + #endif + #endif +#elif defined(__EMSCRIPTEN__) + // Emscripten + #define _SAPP_EMSCRIPTEN (1) + #if !defined(SOKOL_GLES3) && !defined(SOKOL_WGPU) + #error("sokol_app.h: unknown 3D API selected for emscripten, must be SOKOL_GLES3 or SOKOL_WGPU") + #endif +#elif defined(_WIN32) + // Windows (D3D11 or GL) + #define _SAPP_WIN32 (1) + #if !defined(SOKOL_D3D11) && !defined(SOKOL_GLCORE) && !defined(SOKOL_WGPU) && !defined(SOKOL_VULKAN) && !defined(SOKOL_NOAPI) + #error("sokol_app.h: unknown 3D API selected for Win32, must be SOKOL_D3D11, SOKOL_GLCORE, SOKOL_WGPU, SOKOL_VULKAN or SOKOL_NOAPI") + #endif + #if defined(SOKOL_VULKAN) + #define VK_USE_PLATFORM_WIN32_KHR + #include + #endif +#elif defined(__ANDROID__) + // Android + #define _SAPP_ANDROID (1) + #if !defined(SOKOL_GLES3) + #error("sokol_app.h: unknown 3D API selected for Android, must be SOKOL_GLES3") + #endif + #if defined(SOKOL_NO_ENTRY) + #error("sokol_app.h: SOKOL_NO_ENTRY is not supported on Android") + #endif +#elif defined(__linux__) || defined(__unix__) + // Linux + #define _SAPP_LINUX (1) + #if !defined(SOKOL_GLCORE) && !defined(SOKOL_GLES3) && !defined(SOKOL_WGPU) && !defined(SOKOL_VULKAN) + #error("sokol_app.h: unknown 3D API selected for Linux, must be SOKOL_GLCORE, SOKOL_GLES3, SOKOL_WGPU or SOKOL_VULKAN") + #endif + #if defined(SOKOL_GLCORE) + #if defined(SOKOL_FORCE_EGL) + #define _SAPP_EGL (1) + #else + #define _SAPP_GLX (1) + #endif + #define GL_GLEXT_PROTOTYPES + #include + #elif defined(SOKOL_GLES3) + #define _SAPP_EGL (1) + #include + #include + #elif defined(SOKOL_VULKAN) + #define VK_USE_PLATFORM_XLIB_KHR + #include + #endif +#else +#error "sokol_app.h: Unknown platform" +#endif + +#if defined(SOKOL_GLCORE) || defined(SOKOL_GLES3) + #define _SAPP_ANY_GL (1) +#endif + +#ifndef SOKOL_API_IMPL + #define SOKOL_API_IMPL +#endif +#ifndef SOKOL_DEBUG + #ifndef NDEBUG + #define SOKOL_DEBUG + #endif +#endif +#ifndef SOKOL_ASSERT + #include + #define SOKOL_ASSERT(c) assert(c) +#endif +#ifndef SOKOL_UNREACHABLE + #define SOKOL_UNREACHABLE SOKOL_ASSERT(false) +#endif + +#ifndef _SOKOL_PRIVATE + #if defined(__GNUC__) || defined(__clang__) + #define _SOKOL_PRIVATE __attribute__((unused)) static + #else + #define _SOKOL_PRIVATE static + #endif +#endif +#ifndef _SOKOL_UNUSED + #define _SOKOL_UNUSED(x) (void)(x) +#endif + +#if defined(SOKOL_WGPU) + #include + #if !defined(__EMSCRIPTEN__) + #define _SAPP_WGPU_HAS_WAIT (1) + #endif +#endif + +#if defined(_SAPP_APPLE) + #ifndef GL_SILENCE_DEPRECATION + #define GL_SILENCE_DEPRECATION + #endif + #if defined(_SAPP_MACOS) + #import + #if defined(SOKOL_METAL) + #import + #import + #import + #elif defined(SOKOL_WGPU) + #import + #import + #elif defined(_SAPP_ANY_GL) + #include + #endif + #elif defined(_SAPP_IOS) + #import + #if defined(SOKOL_METAL) + #import + #import + #import + #elif defined(_SAPP_ANY_GL) + #import + #include + #endif + #endif + #include + #include +#elif defined(_SAPP_EMSCRIPTEN) + #if defined(SOKOL_GLES3) + #include + #endif + #include + #include +#elif defined(_SAPP_WIN32) + #ifdef _MSC_VER + #pragma warning(push) + #pragma warning(disable:4201) /* nonstandard extension used: nameless struct/union */ + #pragma warning(disable:4204) /* nonstandard extension used: non-constant aggregate initializer */ + #pragma warning(disable:4054) /* 'type cast': from function pointer */ + #pragma warning(disable:4055) /* 'type cast': from data pointer */ + #pragma warning(disable:4505) /* unreferenced local function has been removed */ + #pragma warning(disable:4115) /* /W4: 'ID3D11ModuleInstance': named type definition in parentheses (in d3d11.h) */ + #endif + #ifndef WIN32_LEAN_AND_MEAN + #define WIN32_LEAN_AND_MEAN + #endif + #ifndef NOMINMAX + #define NOMINMAX + #endif + #include + #include + #include + + #if defined(__GNUC__) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wunknown-pragmas" + #endif + + #if !defined(SOKOL_NO_ENTRY) // if SOKOL_NO_ENTRY is defined, it's the application's responsibility to use the right subsystem + + #if defined(SOKOL_WIN32_FORCE_MAIN) && defined(SOKOL_WIN32_FORCE_WINMAIN) + // If both are defined, it's the application's responsibility to use the right subsystem + #elif defined(SOKOL_WIN32_FORCE_MAIN) + #pragma comment (linker, "/subsystem:console") + #else + #pragma comment (linker, "/subsystem:windows") + #endif + #endif + #include /* freopen_s() */ + #include /* wcslen() */ + + #pragma comment (lib, "kernel32") + #pragma comment (lib, "user32") + #pragma comment (lib, "shell32") /* CommandLineToArgvW, DragQueryFileW, DragFinished */ + #pragma comment (lib, "gdi32") + #if defined(SOKOL_D3D11) + #pragma comment (lib, "dxgi") + #pragma comment (lib, "d3d11") + #endif + + #if defined(__GNUC__) + #pragma GCC diagnostic pop + #endif + + #if defined(SOKOL_D3D11) + #ifndef D3D11_NO_HELPERS + #define D3D11_NO_HELPERS + #endif + #include + #include + // DXGI_SWAP_EFFECT_FLIP_DISCARD is only defined in newer Windows SDKs, so don't depend on it + #define _SAPP_DXGI_SWAP_EFFECT_FLIP_DISCARD (4) + #endif + #ifndef WM_MOUSEHWHEEL /* see https://github.com/floooh/sokol/issues/138 */ + #define WM_MOUSEHWHEEL (0x020E) + #endif + #ifndef WM_DPICHANGED + #define WM_DPICHANGED (0x02E0) + #endif +#elif defined(_SAPP_ANDROID) + #include + #include + #include + #include + #include + #if __ANDROID_API__ >= 29 + #include + #endif + #include + #include +#elif defined(_SAPP_LINUX) + #define GL_GLEXT_PROTOTYPES + #include + #include + #include + #include + #include + #include + #include + #include + #include /* XC_* font cursors */ + #include /* CARD32 */ + #if defined(_SAPP_EGL) + #include + #endif + #include /* dlopen, dlsym, dlclose */ + #include /* LONG_MAX */ + #include /* only used a linker-guard, search for _sapp_linux_run() and see first comment */ + #include + #include +#endif + +#if defined(_SAPP_APPLE) + // this is ARC compatible + #if defined(__cplusplus) + #define _SAPP_CLEAR_ARC_STRUCT(type, item) { item = type(); } + #else + #define _SAPP_CLEAR_ARC_STRUCT(type, item) { item = (type) { 0 }; } + #endif +#else + #define _SAPP_CLEAR_ARC_STRUCT(type, item) { _sapp_clear(&item, sizeof(item)); } +#endif + + +// ███████ ██████ █████ ███ ███ ███████ ████████ ██ ███ ███ ██ ███ ██ ██████ +// ██ ██ ██ ██ ██ ████ ████ ██ ██ ██ ████ ████ ██ ████ ██ ██ +// █████ ██████ ███████ ██ ████ ██ █████ ██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ███ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ██ ██ ██ ██ ██ ██ ██ ███████ ██ ██ ██ ██ ██ ██ ████ ██████ +// +// >>frame timing +typedef struct { + #if defined(_SAPP_APPLE) + struct { + mach_timebase_info_data_t timebase; + uint64_t start; + } mach; + #elif defined(_SAPP_EMSCRIPTEN) + int _dummy; + #elif defined(_SAPP_WIN32) + struct { + LARGE_INTEGER freq; + LARGE_INTEGER start; + } win; + #else // Linux, Android, ... + #ifdef CLOCK_MONOTONIC + #define _SAPP_CLOCK_MONOTONIC CLOCK_MONOTONIC + #else + // on some embedded platforms, CLOCK_MONOTONIC isn't defined + #define _SAPP_CLOCK_MONOTONIC (1) + #endif + struct { + uint64_t start; + } posix; + #endif +} _sapp_timestamp_t; + +_SOKOL_PRIVATE int64_t _sapp_int64_muldiv(int64_t value, int64_t numer, int64_t denom) { + int64_t q = value / denom; + int64_t r = value % denom; + return q * numer + r * numer / denom; +} + +_SOKOL_PRIVATE void _sapp_timestamp_init(_sapp_timestamp_t* ts) { + #if defined(_SAPP_APPLE) + mach_timebase_info(&ts->mach.timebase); + ts->mach.start = mach_absolute_time(); + #elif defined(_SAPP_EMSCRIPTEN) + (void)ts; + #elif defined(_SAPP_WIN32) + QueryPerformanceFrequency(&ts->win.freq); + QueryPerformanceCounter(&ts->win.start); + #else + struct timespec tspec; + clock_gettime(_SAPP_CLOCK_MONOTONIC, &tspec); + ts->posix.start = (uint64_t)tspec.tv_sec*1000000000 + (uint64_t)tspec.tv_nsec; + #endif +} + +_SOKOL_PRIVATE double _sapp_timestamp_now(_sapp_timestamp_t* ts) { + #if defined(_SAPP_APPLE) + const uint64_t traw = mach_absolute_time() - ts->mach.start; + const uint64_t now = (uint64_t) _sapp_int64_muldiv((int64_t)traw, (int64_t)ts->mach.timebase.numer, (int64_t)ts->mach.timebase.denom); + return (double)now / 1000000000.0; + #elif defined(_SAPP_EMSCRIPTEN) + (void)ts; + SOKOL_ASSERT(false); + return 0.0; + #elif defined(_SAPP_WIN32) + LARGE_INTEGER qpc; + QueryPerformanceCounter(&qpc); + const uint64_t now = (uint64_t)_sapp_int64_muldiv(qpc.QuadPart - ts->win.start.QuadPart, 1000000000, ts->win.freq.QuadPart); + return (double)now / 1000000000.0; + #else + struct timespec tspec; + clock_gettime(_SAPP_CLOCK_MONOTONIC, &tspec); + const uint64_t now = ((uint64_t)tspec.tv_sec*1000000000 + (uint64_t)tspec.tv_nsec) - ts->posix.start; + return (double)now / 1000000000.0; + #endif +} + +typedef struct { + _sapp_timestamp_t timestamp; + double dt_min; // config: min clamp value for unfiltered time delta (seconds) + double dt_max; // config: max clamp value for unfiltered time delta (seconds) + double dt_threshold; // config: threshold time delta for 'resetting' filtering (default: 0.004s, 4ms) + double alpha; // config: smoothing constant, lower values smoother, higher values faster response + double last; // last absolute time in seconds + double dt; // unfiltered frame delta in seconds, clamped to dt_min/dt_max + double ema; // intermediate ema-filter result + double smooth_dt; // smoothed frame delta in seconds +} _sapp_timing_t; + +_SOKOL_PRIVATE void _sapp_timing_init(_sapp_timing_t* t) { + _sapp_timestamp_init(&t->timestamp); + t->dt_min = 0.000001; // 1 us + t->dt_max = 0.1; // 100 ms + t->dt_threshold = 0.004; // 4ms + t->alpha = 0.025; + t->dt = 1.0 / 60.0; // a 'likely' non-null value + t->ema = t->dt; + t->smooth_dt = t->dt; +} + +_SOKOL_PRIVATE double _sapp_timing_clamp(_sapp_timing_t* t, double dt) { + SOKOL_ASSERT((t->dt_min > 0.0) && (t->dt_max > 0.0) && (t->dt_max >= t->dt_min)); + if (dt < t->dt_min) { + return t->dt_min; + } else if (dt > t->dt_max) { + return t->dt_max; + } else { + return dt; + } +} + +_SOKOL_PRIVATE void _sapp_timing_delta(_sapp_timing_t* t, double dt) { + // first clamp raw dt against min/max (min avoid division by zero, max + // may avoids glitches and 'death-spirals' during debugging + dt = _sapp_timing_clamp(t, dt); + t->dt = dt; + const double error = fabs(dt - t->smooth_dt); + if (error > t->dt_threshold) { + // 'reset' filter when new delta is outside threshold + t->ema = dt; + t->smooth_dt = dt; + } else { + // simple ema-filter with fixed alpha + t->ema = t->ema + t->alpha * (dt - t->ema); + t->smooth_dt = _sapp_timing_clamp(t, t->ema); + } +} + +_SOKOL_PRIVATE void _sapp_timing_update(_sapp_timing_t* t, double external_now) { + double now; + if (external_now == 0.0) { + now = _sapp_timestamp_now(&t->timestamp); + } else { + now = external_now; + } + if (t->last > 0.0) { + double dt = now - t->last; + _sapp_timing_delta(t, dt); + } + t->last = now; + +} + +_SOKOL_PRIVATE double _sapp_timing_get(_sapp_timing_t* t) { + return t->smooth_dt; +} + +// ███████ ████████ ██████ ██ ██ ██████ ████████ ███████ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ███████ ██ ██████ ██ ██ ██ ██ ███████ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ███████ ██ ██ ██ ██████ ██████ ██ ███████ +// +// >> structs +#if defined(SOKOL_WGPU) +typedef struct { + WGPUInstance instance; + WGPUAdapter adapter; + WGPUDevice device; + WGPUSurface surface; + WGPUTextureFormat render_format; + WGPUTexture msaa_tex; + WGPUTextureView msaa_view; + WGPUTexture depth_stencil_tex; + WGPUTextureView depth_stencil_view; + WGPUTextureView swapchain_view; + bool init_done; +} _sapp_wgpu_t; +#endif + +#if defined(SOKOL_VULKAN) +#define _SAPP_VK_MAX_SWAPCHAIN_IMAGES (8) + +typedef struct { + VkImage img; + VkDeviceMemory mem; + VkImageView view; +} _sapp_vk_swapchain_surface_t; + +typedef struct { + VkInstance instance; + VkSurfaceKHR surface; + VkSurfaceFormatKHR surface_format; + VkPhysicalDevice physical_device; + uint32_t queue_family_index; + VkDevice device; + VkQueue queue; + VkSwapchainKHR swapchain; + bool swapchain_acquired; + uint32_t num_swapchain_images; + uint32_t cur_swapchain_image_index; + VkImage swapchain_images[_SAPP_VK_MAX_SWAPCHAIN_IMAGES]; + VkImageView swapchain_views[_SAPP_VK_MAX_SWAPCHAIN_IMAGES]; + _sapp_vk_swapchain_surface_t msaa; + _sapp_vk_swapchain_surface_t depth; + uint32_t sync_slot; + struct { + VkSemaphore render_finished_sem; + VkSemaphore present_complete_sem; + } sync[_SAPP_VK_MAX_SWAPCHAIN_IMAGES]; + struct { + PFN_vkSetDebugUtilsObjectNameEXT set_debug_utils_object_name_ext; + } ext; +} _sapp_vk_t; +#endif + +#if defined(_SAPP_MACOS) +@interface _sapp_macos_app_delegate : NSObject +@end +@interface _sapp_macos_window : NSWindow +@end +@interface _sapp_macos_window_delegate : NSObject +@end +#if defined(SOKOL_METAL) || defined(SOKOL_WGPU) + @interface _sapp_macos_view : NSView + - (void)displayLinkFired:(id)sender; + - (void)fallbackTimerFired:(NSTimer*)timer; + @end +#elif defined(SOKOL_GLCORE) + @interface _sapp_macos_view : NSOpenGLView + - (void)timerFired:(id)sender; + @end +#endif // SOKOL_GLCORE + +typedef struct { + uint32_t flags_changed_store; + uint8_t mouse_buttons; + NSWindow* window; + NSTrackingArea* tracking_area; + id keyup_monitor; + _sapp_macos_app_delegate* app_dlg; + _sapp_macos_window_delegate* win_dlg; + _sapp_macos_view* view; + NSCursor* standard_cursors[_SAPP_MOUSECURSOR_NUM]; + NSCursor* custom_cursors[_SAPP_MOUSECURSOR_NUM]; + #if defined(SOKOL_METAL) + struct { + id device; + CAMetalLayer* layer; + CADisplayLink* display_link; + NSTimer* fallback_timer; + id depth_tex; + id msaa_tex; + // NOTE: CADisplayLink.timestamp seems to be very stable, so we'll use + // this instead of the generic measured+filtered frame timing code + struct { + CFTimeInterval timestamp; + CFTimeInterval frame_duration_sec; + } timing; + } mtl; + #endif + #if defined(SOKOL_WGPU) + struct { + CAMetalLayer* mtl_layer; + CADisplayLink* display_link; + } wgpu; + #endif +} _sapp_macos_t; + +#endif // _SAPP_MACOS + +#if defined(_SAPP_IOS) + +@interface _sapp_scene_delegate : NSObject; +@end +@interface _sapp_textfield_dlg : NSObject +- (void)keyboardWasShown:(NSNotification*)notif; +- (void)keyboardWillBeHidden:(NSNotification*)notif; +- (void)keyboardDidChangeFrame:(NSNotification*)notif; +@end +#if defined(SOKOL_METAL) + @interface _sapp_ios_view : UIView + - (void)displayLinkFired:(id)sender; + @end +#else + @interface _sapp_ios_view : GLKView + @end +#endif + +typedef struct { + UIWindow* window; + _sapp_ios_view* view; + UITextField* textfield; + _sapp_textfield_dlg* textfield_dlg; + #if defined(SOKOL_METAL) + UIViewController* view_ctrl; + #else + GLKViewController* view_ctrl; + #endif + #if defined(SOKOL_METAL) + struct { + id device; + CAMetalLayer* layer; + CADisplayLink* display_link; + id depth_tex; + id msaa_tex; + struct { + CFTimeInterval timestamp; + CFTimeInterval frame_duration_sec; + } timing; + } mtl; + #else + EAGLContext* eagl_ctx; + #endif + bool suspended; +} _sapp_ios_t; + +#endif // _SAPP_IOS + +#if defined(_SAPP_EMSCRIPTEN) + +typedef struct { + bool mouse_lock_requested; + uint16_t mouse_buttons; +} _sapp_emsc_t; +#endif // _SAPP_EMSCRIPTEN + +#if defined(SOKOL_D3D11) && defined(_SAPP_WIN32) +typedef struct { + ID3D11Device* device; + ID3D11DeviceContext* device_context; + ID3D11Texture2D* rt; + ID3D11RenderTargetView* rtv; + ID3D11Texture2D* msaa_rt; + ID3D11RenderTargetView* msaa_rtv; + ID3D11Texture2D* ds; + ID3D11DepthStencilView* dsv; + DXGI_SWAP_CHAIN_DESC swap_chain_desc; + IDXGISwapChain* swap_chain; + IDXGIDevice1* dxgi_device; +} _sapp_d3d11_t; +#endif + +#if defined(_SAPP_WIN32) + +#ifndef DPI_ENUMS_DECLARED +typedef enum PROCESS_DPI_AWARENESS +{ + PROCESS_DPI_UNAWARE = 0, + PROCESS_SYSTEM_DPI_AWARE = 1, + PROCESS_PER_MONITOR_DPI_AWARE = 2 +} PROCESS_DPI_AWARENESS; +typedef enum MONITOR_DPI_TYPE { + MDT_EFFECTIVE_DPI = 0, + MDT_ANGULAR_DPI = 1, + MDT_RAW_DPI = 2, + MDT_DEFAULT = MDT_EFFECTIVE_DPI +} MONITOR_DPI_TYPE; +#endif // DPI_ENUMS_DECLARED + +typedef struct { + bool aware; + float content_scale; + float window_scale; + float mouse_scale; +} _sapp_win32_dpi_t; + +typedef struct { + HWND hwnd; + HMONITOR hmonitor; + HDC dc; + HICON big_icon; + HICON small_icon; + HCURSOR standard_cursors[_SAPP_MOUSECURSOR_NUM]; + HCURSOR custom_cursors[_SAPP_MOUSECURSOR_NUM]; + UINT orig_codepage; + WCHAR surrogate; + RECT stored_window_rect; // used to restore window pos/size when toggling fullscreen => windowed + bool is_win10_or_greater; + bool in_create_window; + bool iconified; + _sapp_win32_dpi_t dpi; + struct { + struct { + LONG pos_x, pos_y; + bool pos_valid; + } lock; + struct { + LONG pos_x, pos_y; + bool pos_valid; + } raw_input; + bool requested_lock; + bool tracked; + uint8_t capture_mask; + } mouse; + struct { + size_t size; + void* ptr; + } raw_input_data; +} _sapp_win32_t; + +#if defined(SOKOL_GLCORE) +#define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000 +#define WGL_SUPPORT_OPENGL_ARB 0x2010 +#define WGL_DRAW_TO_WINDOW_ARB 0x2001 +#define WGL_PIXEL_TYPE_ARB 0x2013 +#define WGL_TYPE_RGBA_ARB 0x202b +#define WGL_ACCELERATION_ARB 0x2003 +#define WGL_NO_ACCELERATION_ARB 0x2025 +#define WGL_RED_BITS_ARB 0x2015 +#define WGL_GREEN_BITS_ARB 0x2017 +#define WGL_BLUE_BITS_ARB 0x2019 +#define WGL_ALPHA_BITS_ARB 0x201b +#define WGL_DEPTH_BITS_ARB 0x2022 +#define WGL_STENCIL_BITS_ARB 0x2023 +#define WGL_DOUBLE_BUFFER_ARB 0x2011 +#define WGL_SAMPLES_ARB 0x2042 +#define WGL_CONTEXT_DEBUG_BIT_ARB 0x00000001 +#define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002 +#define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126 +#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 +#define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091 +#define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092 +#define WGL_CONTEXT_FLAGS_ARB 0x2094 +#define ERROR_INVALID_VERSION_ARB 0x2095 +#define ERROR_INVALID_PROFILE_ARB 0x2096 +#define ERROR_INCOMPATIBLE_DEVICE_CONTEXTS_ARB 0x2054 +typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC)(int); +typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC)(HDC,int,int,UINT,const int*,int*); +typedef const char* (WINAPI * PFNWGLGETEXTENSIONSSTRINGEXTPROC)(void); +typedef const char* (WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC)(HDC); +typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC)(HDC,HGLRC,const int*); +typedef HGLRC (WINAPI * PFN_wglCreateContext)(HDC); +typedef BOOL (WINAPI * PFN_wglDeleteContext)(HGLRC); +typedef PROC (WINAPI * PFN_wglGetProcAddress)(LPCSTR); +typedef HDC (WINAPI * PFN_wglGetCurrentDC)(void); +typedef BOOL (WINAPI * PFN_wglMakeCurrent)(HDC,HGLRC); + +typedef struct { + HINSTANCE opengl32; + HGLRC gl_ctx; + PFN_wglCreateContext CreateContext; + PFN_wglDeleteContext DeleteContext; + PFN_wglGetProcAddress GetProcAddress; + PFN_wglGetCurrentDC GetCurrentDC; + PFN_wglMakeCurrent MakeCurrent; + PFNWGLSWAPINTERVALEXTPROC SwapIntervalEXT; + PFNWGLGETPIXELFORMATATTRIBIVARBPROC GetPixelFormatAttribivARB; + PFNWGLGETEXTENSIONSSTRINGEXTPROC GetExtensionsStringEXT; + PFNWGLGETEXTENSIONSSTRINGARBPROC GetExtensionsStringARB; + PFNWGLCREATECONTEXTATTRIBSARBPROC CreateContextAttribsARB; + // special case glGetIntegerv + void (WINAPI *GetIntegerv)(uint32_t pname, int32_t* data); + bool ext_swap_control; + bool arb_multisample; + bool arb_pixel_format; + bool arb_create_context; + bool arb_create_context_profile; + HWND msg_hwnd; + HDC msg_dc; +} _sapp_wgl_t; +#endif // SOKOL_GLCORE + +#endif // _SAPP_WIN32 + +#if defined(_SAPP_ANDROID) +typedef enum { + _SOKOL_ANDROID_MSG_CREATE, + _SOKOL_ANDROID_MSG_RESUME, + _SOKOL_ANDROID_MSG_PAUSE, + _SOKOL_ANDROID_MSG_FOCUS, + _SOKOL_ANDROID_MSG_NO_FOCUS, + _SOKOL_ANDROID_MSG_SET_NATIVE_WINDOW, + _SOKOL_ANDROID_MSG_SET_INPUT_QUEUE, + _SOKOL_ANDROID_MSG_DESTROY, +} _sapp_android_msg_t; + +typedef struct { + pthread_t thread; + pthread_mutex_t mutex; + pthread_cond_t cond; + int read_from_main_fd; + int write_from_main_fd; +} _sapp_android_pt_t; + +typedef struct { + ANativeWindow* window; + AInputQueue* input; +} _sapp_android_resources_t; + +typedef struct { + ANativeActivity* activity; + _sapp_android_pt_t pt; + _sapp_android_resources_t pending; + _sapp_android_resources_t current; + ALooper* looper; + bool is_thread_started; + bool is_thread_stopping; + bool is_thread_stopped; + bool has_created; + bool has_resumed; + bool has_focus; + EGLConfig config; + EGLDisplay display; + EGLContext context; + EGLSurface surface; + #if __ANDROID_API__ >= 29 + AChoreographer* choreographer; + bool frame_callback_in_flight; + #endif +} _sapp_android_t; + +#endif // _SAPP_ANDROID + +#if defined(_SAPP_LINUX) + +#define _SAPP_X11_XDND_VERSION (5) +#define _SAPP_X11_MAX_X11_KEYCODES (256) + +#define GLX_VENDOR 1 +#define GLX_RGBA_BIT 0x00000001 +#define GLX_WINDOW_BIT 0x00000001 +#define GLX_DRAWABLE_TYPE 0x8010 +#define GLX_RENDER_TYPE 0x8011 +#define GLX_DOUBLEBUFFER 5 +#define GLX_RED_SIZE 8 +#define GLX_GREEN_SIZE 9 +#define GLX_BLUE_SIZE 10 +#define GLX_ALPHA_SIZE 11 +#define GLX_DEPTH_SIZE 12 +#define GLX_STENCIL_SIZE 13 +#define GLX_SAMPLES 0x186a1 +#define GLX_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 +#define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126 +#define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002 +#define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091 +#define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092 +#define GLX_CONTEXT_FLAGS_ARB 0x2094 + +typedef XID GLXWindow; +typedef XID GLXDrawable; +typedef struct __GLXFBConfig* GLXFBConfig; +typedef struct __GLXcontext* GLXContext; +typedef void (*__GLXextproc)(void); + +typedef int (*PFNGLXGETFBCONFIGATTRIBPROC)(Display*,GLXFBConfig,int,int*); +typedef const char* (*PFNGLXGETCLIENTSTRINGPROC)(Display*,int); +typedef Bool (*PFNGLXQUERYEXTENSIONPROC)(Display*,int*,int*); +typedef Bool (*PFNGLXQUERYVERSIONPROC)(Display*,int*,int*); +typedef void (*PFNGLXDESTROYCONTEXTPROC)(Display*,GLXContext); +typedef Bool (*PFNGLXMAKECURRENTPROC)(Display*,GLXDrawable,GLXContext); +typedef void (*PFNGLXSWAPBUFFERSPROC)(Display*,GLXDrawable); +typedef const char* (*PFNGLXQUERYEXTENSIONSSTRINGPROC)(Display*,int); +typedef GLXFBConfig* (*PFNGLXGETFBCONFIGSPROC)(Display*,int,int*); +typedef __GLXextproc (* PFNGLXGETPROCADDRESSPROC)(const char *procName); +typedef void (*PFNGLXSWAPINTERVALEXTPROC)(Display*,GLXDrawable,int); +typedef XVisualInfo* (*PFNGLXGETVISUALFROMFBCONFIGPROC)(Display*,GLXFBConfig); +typedef GLXWindow (*PFNGLXCREATEWINDOWPROC)(Display*,GLXFBConfig,Window,const int*); +typedef void (*PFNGLXDESTROYWINDOWPROC)(Display*,GLXWindow); + +typedef int (*PFNGLXSWAPINTERVALMESAPROC)(int); +typedef GLXContext (*PFNGLXCREATECONTEXTATTRIBSARBPROC)(Display*,GLXFBConfig,GLXContext,Bool,const int*); + +typedef struct { + bool available; + int major_opcode; + int event_base; + int error_base; + int major; + int minor; +} _sapp_xi_t; + +typedef struct { + int version; + Window source; + Atom format; + Atom XdndAware; + Atom XdndEnter; + Atom XdndPosition; + Atom XdndStatus; + Atom XdndActionCopy; + Atom XdndDrop; + Atom XdndFinished; + Atom XdndSelection; + Atom XdndTypeList; + Atom text_uri_list; +} _sapp_xdnd_t; + +typedef struct { + uint8_t mouse_buttons; + Display* display; + int screen; + Window root; + Colormap colormap; + Window window; + Cursor hidden_cursor; + Cursor standard_cursors[_SAPP_MOUSECURSOR_NUM]; + Cursor custom_cursors[_SAPP_MOUSECURSOR_NUM]; + int window_state; + float dpi; + unsigned char error_code; + Atom UTF8_STRING; + Atom CLIPBOARD; + Atom TARGETS; + Atom WM_PROTOCOLS; + Atom WM_DELETE_WINDOW; + Atom WM_STATE; + Atom NET_WM_NAME; + Atom NET_WM_ICON_NAME; + Atom NET_WM_ICON; + Atom NET_WM_STATE; + Atom NET_WM_STATE_FULLSCREEN; + _sapp_xi_t xi; + _sapp_xdnd_t xdnd; + // XLib manual says keycodes are in the range [8, 255] inclusive. + // https://tronche.com/gui/x/xlib/input/keyboard-encoding.html + bool key_repeat[_SAPP_X11_MAX_X11_KEYCODES]; +} _sapp_x11_t; + +#if defined(_SAPP_GLX) + +typedef struct { + void* libgl; + int major; + int minor; + int event_base; + int error_base; + GLXContext ctx; + GLXWindow window; + + // GLX 1.3 functions + PFNGLXGETFBCONFIGSPROC GetFBConfigs; + PFNGLXGETFBCONFIGATTRIBPROC GetFBConfigAttrib; + PFNGLXGETCLIENTSTRINGPROC GetClientString; + PFNGLXQUERYEXTENSIONPROC QueryExtension; + PFNGLXQUERYVERSIONPROC QueryVersion; + PFNGLXDESTROYCONTEXTPROC DestroyContext; + PFNGLXMAKECURRENTPROC MakeCurrent; + PFNGLXSWAPBUFFERSPROC SwapBuffers; + PFNGLXQUERYEXTENSIONSSTRINGPROC QueryExtensionsString; + PFNGLXGETVISUALFROMFBCONFIGPROC GetVisualFromFBConfig; + PFNGLXCREATEWINDOWPROC CreateWindow; + PFNGLXDESTROYWINDOWPROC DestroyWindow; + + // GLX 1.4 and extension functions + PFNGLXGETPROCADDRESSPROC GetProcAddress; + PFNGLXGETPROCADDRESSPROC GetProcAddressARB; + PFNGLXSWAPINTERVALEXTPROC SwapIntervalEXT; + PFNGLXSWAPINTERVALMESAPROC SwapIntervalMESA; + PFNGLXCREATECONTEXTATTRIBSARBPROC CreateContextAttribsARB; + + // special case glGetIntegerv + void (*GetIntegerv)(uint32_t pname, int32_t* data); + + // extension availability + bool EXT_swap_control; + bool MESA_swap_control; + bool ARB_multisample; + bool ARB_create_context; + bool ARB_create_context_profile; +} _sapp_glx_t; +#endif // _SAPP_GLX + +#if defined(_SAPP_EGL) +typedef struct { + EGLDisplay display; + EGLContext context; + EGLSurface surface; +} _sapp_egl_t; +#endif // _SAPP_EGL +#endif // _SAPP_LINUX + +#if defined(_SAPP_ANY_GL) +typedef struct { + uint32_t framebuffer; +} _sapp_gl_t; +#endif + +typedef struct { + bool enabled; + int buf_size; + char* buffer; +} _sapp_clipboard_t; + +typedef struct { + bool enabled; + int max_files; + int max_path_length; + int num_files; + int buf_size; + char* buffer; +} _sapp_drop_t; + +typedef struct { + float x, y; + float dx, dy; + bool shown; + bool locked; + bool pos_valid; + sapp_mouse_cursor current_cursor; +} _sapp_mouse_t; + +typedef struct { + sapp_desc desc; + bool valid; + bool fullscreen; + bool first_frame; + bool init_called; + bool cleanup_called; + bool quit_requested; + bool quit_ordered; + bool event_consumed; + bool html5_ask_leave_site; + bool onscreen_keyboard_shown; + int window_width; + int window_height; + int framebuffer_width; + int framebuffer_height; + int sample_count; + int swap_interval; + float dpi_scale; + uint64_t frame_count; + sapp_event event; + _sapp_mouse_t mouse; + _sapp_clipboard_t clipboard; + _sapp_drop_t drop; + sapp_icon_desc default_icon_desc; + uint32_t* default_icon_pixels; + _sapp_timing_t timing; + #if defined(SOKOL_WGPU) + _sapp_wgpu_t wgpu; + #endif + #if defined(SOKOL_VULKAN) + _sapp_vk_t vk; + #endif + #if defined(_SAPP_MACOS) + _sapp_macos_t macos; + #elif defined(_SAPP_IOS) + _sapp_ios_t ios; + #elif defined(_SAPP_EMSCRIPTEN) + _sapp_emsc_t emsc; + #elif defined(_SAPP_WIN32) + _sapp_win32_t win32; + #if defined(SOKOL_D3D11) + _sapp_d3d11_t d3d11; + #elif defined(SOKOL_GLCORE) + _sapp_wgl_t wgl; + #endif + #elif defined(_SAPP_ANDROID) + _sapp_android_t android; + #elif defined(_SAPP_LINUX) + _sapp_x11_t x11; + #if defined(_SAPP_GLX) + _sapp_glx_t glx; + #elif defined(_SAPP_EGL) + _sapp_egl_t egl; + #endif + #endif + #if defined(_SAPP_ANY_GL) + _sapp_gl_t gl; + #endif + char html5_canvas_selector[_SAPP_MAX_TITLE_LENGTH]; + char window_title[_SAPP_MAX_TITLE_LENGTH]; // UTF-8 + wchar_t window_title_wide[_SAPP_MAX_TITLE_LENGTH]; // UTF-32 or UCS-2 */ + sapp_keycode keycodes[SAPP_MAX_KEYCODES]; + bool custom_cursor_bound[_SAPP_MOUSECURSOR_NUM]; // true if a custom mouse cursor is bound on that slot +} _sapp_t; +static _sapp_t _sapp; + +// ██ ██████ ██████ ██████ ██ ███ ██ ██████ +// ██ ██ ██ ██ ██ ██ ████ ██ ██ +// ██ ██ ██ ██ ███ ██ ███ ██ ██ ██ ██ ██ ███ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ███████ ██████ ██████ ██████ ██ ██ ████ ██████ +// +// >>logging +#if defined(SOKOL_DEBUG) +#define _SAPP_LOGITEM_XMACRO(item,msg) #item ": " msg, +static const char* _sapp_log_messages[] = { + _SAPP_LOG_ITEMS +}; +#undef _SAPP_LOGITEM_XMACRO +#endif // SOKOL_DEBUG + +#define _SAPP_PANIC(code) _sapp_log(SAPP_LOGITEM_ ##code, 0, 0, __LINE__) +#define _SAPP_ERROR(code) _sapp_log(SAPP_LOGITEM_ ##code, 1, 0, __LINE__) +#define _SAPP_WARN(code) _sapp_log(SAPP_LOGITEM_ ##code, 2, 0, __LINE__) +#define _SAPP_INFO(code) _sapp_log(SAPP_LOGITEM_ ##code, 3, 0, __LINE__) +#define _SAPP_PANIC_MSG(code, msg) _sapp_log(SAPP_LOGITEM_ ##code, 0, msg, __LINE__) +#define _SAPP_ERROR_MSG(code, msg) _sapp_log(SAPP_LOGITEM_ ##code, 1, msg, __LINE__) +#define _SAPP_WARN_MSG(code, msg) _sapp_log(SAPP_LOGITEM_ ##code, 2, msg, __LINE__) +#define _SAPP_INFO_MSG(code, msg) _sapp_log(SAPP_LOGITEM_ ##code, 3, msg, __LINE__) + +static void _sapp_log(sapp_log_item log_item, uint32_t log_level, const char* msg, uint32_t line_nr) { + if (_sapp.desc.logger.func) { + const char* filename = 0; + #if defined(SOKOL_DEBUG) + filename = __FILE__; + if (0 == msg) { + msg = _sapp_log_messages[log_item]; + } + #endif + _sapp.desc.logger.func("sapp", log_level, (uint32_t)log_item, msg, line_nr, filename, _sapp.desc.logger.user_data); + } else { + // for log level PANIC it would be 'undefined behaviour' to continue + if (log_level == 0) { + abort(); + } + } +} + +// ███ ███ ███████ ███ ███ ██████ ██████ ██ ██ +// ████ ████ ██ ████ ████ ██ ██ ██ ██ ██ ██ +// ██ ████ ██ █████ ██ ████ ██ ██ ██ ██████ ████ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ██ ██ ███████ ██ ██ ██████ ██ ██ ██ +// +// >>memory +_SOKOL_PRIVATE void _sapp_clear(void* ptr, size_t size) { + SOKOL_ASSERT(ptr && (size > 0)); + memset(ptr, 0, size); +} + +_SOKOL_PRIVATE void* _sapp_malloc(size_t size) { + SOKOL_ASSERT(size > 0); + void* ptr; + if (_sapp.desc.allocator.alloc_fn) { + ptr = _sapp.desc.allocator.alloc_fn(size, _sapp.desc.allocator.user_data); + } else { + ptr = malloc(size); + } + if (0 == ptr) { + _SAPP_PANIC(MALLOC_FAILED); + } + return ptr; +} + +_SOKOL_PRIVATE void* _sapp_malloc_clear(size_t size) { + void* ptr = _sapp_malloc(size); + _sapp_clear(ptr, size); + return ptr; +} + +_SOKOL_PRIVATE void _sapp_free(void* ptr) { + if (_sapp.desc.allocator.free_fn) { + _sapp.desc.allocator.free_fn(ptr, _sapp.desc.allocator.user_data); + } else { + free(ptr); + } +} + +// ██ ██ ███████ ██ ██████ ███████ ██████ ███████ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ███████ █████ ██ ██████ █████ ██████ ███████ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ██ ██ ███████ ███████ ██ ███████ ██ ██ ███████ +// +// >>helpers + +// round float to int and at least 1 +_SOKOL_PRIVATE int _sapp_roundf_gzero(float f) { + int val = (int)roundf(f); + if (val <= 0) { + val = 1; + } + return val; +} + +_SOKOL_PRIVATE void _sapp_call_init(void) { + if (_sapp.desc.init_cb) { + _sapp.desc.init_cb(); + } else if (_sapp.desc.init_userdata_cb) { + _sapp.desc.init_userdata_cb(_sapp.desc.user_data); + } + _sapp.init_called = true; +} + +_SOKOL_PRIVATE void _sapp_call_frame(void) { + if (_sapp.init_called && !_sapp.cleanup_called) { + if (_sapp.desc.frame_cb) { + _sapp.desc.frame_cb(); + } else if (_sapp.desc.frame_userdata_cb) { + _sapp.desc.frame_userdata_cb(_sapp.desc.user_data); + } + } +} + +_SOKOL_PRIVATE void _sapp_call_cleanup(void) { + if (!_sapp.cleanup_called) { + if (_sapp.desc.cleanup_cb) { + _sapp.desc.cleanup_cb(); + } else if (_sapp.desc.cleanup_userdata_cb) { + _sapp.desc.cleanup_userdata_cb(_sapp.desc.user_data); + } + _sapp.cleanup_called = true; + } +} + +_SOKOL_PRIVATE bool _sapp_call_event(const sapp_event* e) { + if (!_sapp.cleanup_called) { + if (_sapp.desc.event_cb) { + _sapp.desc.event_cb(e); + } else if (_sapp.desc.event_userdata_cb) { + _sapp.desc.event_userdata_cb(e, _sapp.desc.user_data); + } + } + if (_sapp.event_consumed) { + _sapp.event_consumed = false; + return true; + } else { + return false; + } +} + +_SOKOL_PRIVATE char* _sapp_dropped_file_path_ptr(int index) { + SOKOL_ASSERT(_sapp.drop.buffer); + SOKOL_ASSERT((index >= 0) && (index <= _sapp.drop.max_files)); + int offset = index * _sapp.drop.max_path_length; + SOKOL_ASSERT(offset < _sapp.drop.buf_size); + return &_sapp.drop.buffer[offset]; +} + +/* Copy a string (either zero-terminated or with explicit length) + into a fixed size buffer with guaranteed zero-termination. + + Return false if the string didn't fit into the buffer and had to be clamped. + + FIXME: Currently UTF-8 strings might become invalid if the string + is clamped, because the last zero-byte might be written into + the middle of a multi-byte sequence. +*/ +_SOKOL_PRIVATE bool _sapp_strcpy_range(const char* src, size_t src_len, char* dst, size_t dst_buf_len) { + SOKOL_ASSERT(src && dst && (dst_buf_len > 0)); + if (0 == src_len) { + src_len = dst_buf_len; + } + char* const end = &(dst[dst_buf_len-1]); + char c = 0; + for (size_t i = 0; i < dst_buf_len; i++) { + c = *src; + if (i >= src_len) { + c = 0; + } + if (c != 0) { + src++; + } + *dst++ = c; + } + // truncated? + if (c != 0) { + *end = 0; + return false; + } else { + return true; + } +} + +_SOKOL_PRIVATE bool _sapp_strcpy(const char* src, char* dst, size_t dst_buf_len) { + return _sapp_strcpy_range(src, 0, dst, dst_buf_len); +} + +_SOKOL_PRIVATE sapp_desc _sapp_desc_defaults(const sapp_desc* desc) { + SOKOL_ASSERT((desc->allocator.alloc_fn && desc->allocator.free_fn) || (!desc->allocator.alloc_fn && !desc->allocator.free_fn)); + sapp_desc res = *desc; + res.sample_count = _sapp_def(res.sample_count, 1); + res.swap_interval = _sapp_def(res.swap_interval, 1); + if (0 == res.gl.major_version) { + #if defined(SOKOL_GLCORE) + res.gl.major_version = 4; + #if defined(_SAPP_APPLE) + res.gl.minor_version = 1; + #else + res.gl.minor_version = 3; + #endif + #elif defined(SOKOL_GLES3) + res.gl.major_version = 3; + #if defined(_SAPP_ANDROID) || defined(_SAPP_LINUX) + res.gl.minor_version = 1; + #else + res.gl.minor_version = 0; + #endif + #endif + } + res.html5.canvas_selector = _sapp_def(res.html5.canvas_selector, "#canvas"); + res.clipboard_size = _sapp_def(res.clipboard_size, 8192); + res.max_dropped_files = _sapp_def(res.max_dropped_files, 1); + res.max_dropped_file_path_length = _sapp_def(res.max_dropped_file_path_length, 2048); + res.window_title = _sapp_def(res.window_title, "sokol"); + return res; +} + +_SOKOL_PRIVATE void _sapp_init_state(const sapp_desc* desc) { + SOKOL_ASSERT(desc); + SOKOL_ASSERT(desc->width >= 0); + SOKOL_ASSERT(desc->height >= 0); + SOKOL_ASSERT(desc->sample_count >= 0); + SOKOL_ASSERT(desc->swap_interval >= 0); + SOKOL_ASSERT(desc->clipboard_size >= 0); + SOKOL_ASSERT(desc->max_dropped_files >= 0); + SOKOL_ASSERT(desc->max_dropped_file_path_length >= 0); + _SAPP_CLEAR_ARC_STRUCT(_sapp_t, _sapp); + _sapp.desc = _sapp_desc_defaults(desc); + _sapp.first_frame = true; + // NOTE: _sapp.desc.width/height may be 0! Platform backends need to deal with this + _sapp.window_width = _sapp.desc.width; + _sapp.window_height = _sapp.desc.height; + _sapp.framebuffer_width = _sapp.window_width; + _sapp.framebuffer_height = _sapp.window_height; + _sapp.sample_count = _sapp.desc.sample_count; + _sapp.swap_interval = _sapp.desc.swap_interval; + _sapp_strcpy(_sapp.desc.html5.canvas_selector, _sapp.html5_canvas_selector, sizeof(_sapp.html5_canvas_selector)); + _sapp.desc.html5.canvas_selector = _sapp.html5_canvas_selector; + _sapp.html5_ask_leave_site = _sapp.desc.html5.ask_leave_site; + _sapp.clipboard.enabled = _sapp.desc.enable_clipboard; + if (_sapp.clipboard.enabled) { + _sapp.clipboard.buf_size = _sapp.desc.clipboard_size; + _sapp.clipboard.buffer = (char*) _sapp_malloc_clear((size_t)_sapp.clipboard.buf_size); + } + _sapp.drop.enabled = _sapp.desc.enable_dragndrop; + if (_sapp.drop.enabled) { + _sapp.drop.max_files = _sapp.desc.max_dropped_files; + _sapp.drop.max_path_length = _sapp.desc.max_dropped_file_path_length; + _sapp.drop.buf_size = _sapp.drop.max_files * _sapp.drop.max_path_length; + _sapp.drop.buffer = (char*) _sapp_malloc_clear((size_t)_sapp.drop.buf_size); + } + _sapp_strcpy(_sapp.desc.window_title, _sapp.window_title, sizeof(_sapp.window_title)); + _sapp.desc.window_title = _sapp.window_title; + _sapp.dpi_scale = 1.0f; + _sapp.fullscreen = _sapp.desc.fullscreen; + _sapp.mouse.shown = true; + _sapp_timing_init(&_sapp.timing); +} + +_SOKOL_PRIVATE void _sapp_discard_state(void) { + if (_sapp.clipboard.enabled) { + SOKOL_ASSERT(_sapp.clipboard.buffer); + _sapp_free((void*)_sapp.clipboard.buffer); + } + if (_sapp.drop.enabled) { + SOKOL_ASSERT(_sapp.drop.buffer); + _sapp_free((void*)_sapp.drop.buffer); + } + if (_sapp.default_icon_pixels) { + _sapp_free((void*)_sapp.default_icon_pixels); + } + for (int i = 0; i < _SAPP_MOUSECURSOR_NUM; i++) { + sapp_unbind_mouse_cursor_image((sapp_mouse_cursor) i); + } + _SAPP_CLEAR_ARC_STRUCT(_sapp_t, _sapp); +} + +_SOKOL_PRIVATE void _sapp_init_event(sapp_event_type type) { + _sapp_clear(&_sapp.event, sizeof(_sapp.event)); + _sapp.event.type = type; + _sapp.event.frame_count = _sapp.frame_count; + _sapp.event.mouse_button = SAPP_MOUSEBUTTON_INVALID; + _sapp.event.window_width = _sapp.window_width; + _sapp.event.window_height = _sapp.window_height; + _sapp.event.framebuffer_width = _sapp.framebuffer_width; + _sapp.event.framebuffer_height = _sapp.framebuffer_height; + _sapp.event.mouse_x = _sapp.mouse.x; + _sapp.event.mouse_y = _sapp.mouse.y; + _sapp.event.mouse_dx = _sapp.mouse.dx; + _sapp.event.mouse_dy = _sapp.mouse.dy; +} + +_SOKOL_PRIVATE bool _sapp_events_enabled(void) { + /* only send events when an event callback is set, and the init function was called */ + return (_sapp.desc.event_cb || _sapp.desc.event_userdata_cb) && _sapp.init_called; +} + +_SOKOL_PRIVATE sapp_keycode _sapp_translate_key(int scan_code) { + if ((scan_code >= 0) && (scan_code < SAPP_MAX_KEYCODES)) { + return _sapp.keycodes[scan_code]; + } else { + return SAPP_KEYCODE_INVALID; + } +} + +_SOKOL_PRIVATE void _sapp_clear_drop_buffer(void) { + if (_sapp.drop.enabled) { + SOKOL_ASSERT(_sapp.drop.buffer); + _sapp_clear(_sapp.drop.buffer, (size_t)_sapp.drop.buf_size); + } +} + +_SOKOL_PRIVATE void _sapp_frame(void) { + if (_sapp.first_frame) { + _sapp.first_frame = false; + _sapp_call_init(); + } + _sapp_call_frame(); + _sapp.frame_count++; +} + +_SOKOL_PRIVATE bool _sapp_image_validate(const sapp_image_desc* desc) { + SOKOL_ASSERT(desc->width > 0); + SOKOL_ASSERT(desc->height > 0); + SOKOL_ASSERT(desc->pixels.ptr != 0); + SOKOL_ASSERT(desc->pixels.size > 0); + const size_t wh_size = (size_t)(desc->width * desc->height) * sizeof(uint32_t); + if (wh_size != desc->pixels.size) { + _SAPP_ERROR(IMAGE_DATA_SIZE_MISMATCH); + return false; + } + return true; +} + +_SOKOL_PRIVATE int _sapp_image_bestmatch(const sapp_image_desc image_descs[], int num_images, int width, int height) { + int least_diff = 0x7FFFFFFF; + int least_index = 0; + for (int i = 0; i < num_images; i++) { + int diff = (image_descs[i].width * image_descs[i].height) - (width * height); + if (diff < 0) { + diff = -diff; + } + if (diff < least_diff) { + least_diff = diff; + least_index = i; + } + } + return least_index; +} + +_SOKOL_PRIVATE int _sapp_icon_num_images(const sapp_icon_desc* desc) { + int index = 0; + for (; index < SAPP_MAX_ICONIMAGES; index++) { + if (0 == desc->images[index].pixels.ptr) { + break; + } + } + return index; +} + +_SOKOL_PRIVATE bool _sapp_validate_icon_desc(const sapp_icon_desc* desc, int num_images) { + SOKOL_ASSERT(num_images <= SAPP_MAX_ICONIMAGES); + for (int i = 0; i < num_images; i++) { + const sapp_image_desc* img_desc = &desc->images[i]; + if (!_sapp_image_validate(img_desc)) { + return false; + } + } + return true; +} + +_SOKOL_PRIVATE void _sapp_setup_default_icon(void) { + SOKOL_ASSERT(0 == _sapp.default_icon_pixels); + + const int num_icons = 3; + const int icon_sizes[3] = { 16, 32, 64 }; // must be multiple of 8! + + // allocate a pixel buffer for all icon pixels + int all_num_pixels = 0; + for (int i = 0; i < num_icons; i++) { + all_num_pixels += icon_sizes[i] * icon_sizes[i]; + } + _sapp.default_icon_pixels = (uint32_t*) _sapp_malloc_clear((size_t)all_num_pixels * sizeof(uint32_t)); + + // initialize default_icon_desc struct + uint32_t* dst = _sapp.default_icon_pixels; + const uint32_t* dst_end = dst + all_num_pixels; + (void)dst_end; // silence unused warning in release mode + for (int i = 0; i < num_icons; i++) { + const int dim = (int) icon_sizes[i]; + const int num_pixels = dim * dim; + sapp_image_desc* img_desc = &_sapp.default_icon_desc.images[i]; + img_desc->width = dim; + img_desc->height = dim; + img_desc->pixels.ptr = dst; + img_desc->pixels.size = (size_t)num_pixels * sizeof(uint32_t); + dst += num_pixels; + } + SOKOL_ASSERT(dst == dst_end); + + // Amstrad CPC font 'S' + const uint8_t tile[8] = { + 0x3C, + 0x66, + 0x60, + 0x3C, + 0x06, + 0x66, + 0x3C, + 0x00, + }; + // rainbow colors + const uint32_t colors[8] = { + 0xFF4370FF, + 0xFF26A7FF, + 0xFF58EEFF, + 0xFF57E1D4, + 0xFF65CC9C, + 0xFF6ABB66, + 0xFFF5A542, + 0xFFC2577E, + }; + dst = _sapp.default_icon_pixels; + const uint32_t blank = 0x00FFFFFF; + const uint32_t shadow = 0xFF000000; + for (int i = 0; i < num_icons; i++) { + const int dim = icon_sizes[i]; + SOKOL_ASSERT((dim % 8) == 0); + const int scale = dim / 8; + for (int ty = 0, y = 0; ty < 8; ty++) { + const uint32_t color = colors[ty]; + for (int sy = 0; sy < scale; sy++, y++) { + uint8_t bits = tile[ty]; + for (int tx = 0, x = 0; tx < 8; tx++, bits<<=1) { + uint32_t pixel = (0 == (bits & 0x80)) ? blank : color; + for (int sx = 0; sx < scale; sx++, x++) { + SOKOL_ASSERT(dst < dst_end); + *dst++ = pixel; + } + } + } + } + } + SOKOL_ASSERT(dst == dst_end); + + // right shadow + dst = _sapp.default_icon_pixels; + for (int i = 0; i < num_icons; i++) { + const int dim = icon_sizes[i]; + for (int y = 0; y < dim; y++) { + uint32_t prev_color = blank; + for (int x = 0; x < dim; x++) { + const int dst_index = y * dim + x; + const uint32_t cur_color = dst[dst_index]; + if ((cur_color == blank) && (prev_color != blank)) { + dst[dst_index] = shadow; + } + prev_color = cur_color; + } + } + dst += dim * dim; + } + SOKOL_ASSERT(dst == dst_end); + + // bottom shadow + dst = _sapp.default_icon_pixels; + for (int i = 0; i < num_icons; i++) { + const int dim = icon_sizes[i]; + for (int x = 0; x < dim; x++) { + uint32_t prev_color = blank; + for (int y = 0; y < dim; y++) { + const int dst_index = y * dim + x; + const uint32_t cur_color = dst[dst_index]; + if ((cur_color == blank) && (prev_color != blank)) { + dst[dst_index] = shadow; + } + prev_color = cur_color; + } + } + dst += dim * dim; + } + SOKOL_ASSERT(dst == dst_end); +} + +// ██ ██ ██████ ██████ ██ ██ +// ██ ██ ██ ██ ██ ██ ██ +// ██ █ ██ ██ ███ ██████ ██ ██ +// ██ ███ ██ ██ ██ ██ ██ ██ +// ███ ███ ██████ ██ ██████ +// +// >>wgpu +#if defined(SOKOL_WGPU) + +_SOKOL_PRIVATE WGPUStringView _sapp_wgpu_stringview(const char* str) { + WGPUStringView res; + if (str) { + res.data = str; + res.length = strlen(str); + } else { + res.data = 0; + res.length = 0; + } + return res; +} + +_SOKOL_PRIVATE WGPUCallbackMode _sapp_wgpu_callbackmode(void) { + #if defined(_SAPP_WGPU_HAS_WAIT) + return WGPUCallbackMode_WaitAnyOnly; + #else + return WGPUCallbackMode_AllowProcessEvents; + #endif +} + +_SOKOL_PRIVATE void _sapp_wgpu_await(WGPUFuture future) { + #if defined(_SAPP_WGPU_HAS_WAIT) + SOKOL_ASSERT(_sapp.wgpu.instance); + _SAPP_STRUCT(WGPUFutureWaitInfo, wait_info); + wait_info.future = future; + WGPUWaitStatus res = wgpuInstanceWaitAny(_sapp.wgpu.instance, 1, &wait_info, UINT64_MAX); + SOKOL_ASSERT(res == WGPUWaitStatus_Success); _SOKOL_UNUSED(res); + #else + // this code path should never be called + _SOKOL_UNUSED(future); + SOKOL_ASSERT(false); + #endif +} + +_SOKOL_PRIVATE WGPUTextureFormat _sapp_wgpu_pick_render_format(size_t count, const WGPUTextureFormat* formats) { + // NOTE: only accept non-SRGB formats until sokol_app.h gets proper SRGB support + SOKOL_ASSERT((count > 0) && formats); + for (size_t i = 0; i < count; i++) { + const WGPUTextureFormat fmt = formats[i]; + switch (fmt) { + case WGPUTextureFormat_RGBA8Unorm: + case WGPUTextureFormat_BGRA8Unorm: + return fmt; + default: break; + } + } + // FIXME: fallback might still return an SRGB format + return formats[0]; +} + +_SOKOL_PRIVATE void _sapp_wgpu_create_swapchain(bool called_from_resize) { + SOKOL_ASSERT(_sapp.wgpu.instance); + SOKOL_ASSERT(_sapp.wgpu.device); + SOKOL_ASSERT(0 == _sapp.wgpu.msaa_tex); + SOKOL_ASSERT(0 == _sapp.wgpu.msaa_view); + SOKOL_ASSERT(0 == _sapp.wgpu.depth_stencil_tex); + SOKOL_ASSERT(0 == _sapp.wgpu.depth_stencil_view); + + if (!called_from_resize) { + SOKOL_ASSERT(0 == _sapp.wgpu.surface); + _SAPP_STRUCT(WGPUSurfaceDescriptor, surf_desc); + #if defined (_SAPP_EMSCRIPTEN) + _SAPP_STRUCT(WGPUEmscriptenSurfaceSourceCanvasHTMLSelector, html_canvas_desc); + html_canvas_desc.chain.sType = WGPUSType_EmscriptenSurfaceSourceCanvasHTMLSelector; + html_canvas_desc.selector = _sapp_wgpu_stringview(_sapp.html5_canvas_selector); + surf_desc.nextInChain = &html_canvas_desc.chain; + #elif defined(_SAPP_MACOS) + _SAPP_STRUCT(WGPUSurfaceSourceMetalLayer, from_metal_layer); + from_metal_layer.chain.sType = WGPUSType_SurfaceSourceMetalLayer; + from_metal_layer.layer = _sapp.macos.view.layer; + surf_desc.nextInChain = &from_metal_layer.chain; + #elif defined(_SAPP_WIN32) + _SAPP_STRUCT(WGPUSurfaceSourceWindowsHWND, from_hwnd); + from_hwnd.chain.sType = WGPUSType_SurfaceSourceWindowsHWND; + from_hwnd.hinstance = GetModuleHandleW(NULL); + from_hwnd.hwnd = _sapp.win32.hwnd; + surf_desc.nextInChain = &from_hwnd.chain; + #elif defined(_SAPP_LINUX) + _SAPP_STRUCT(WGPUSurfaceSourceXlibWindow, from_xlib); + from_xlib.chain.sType = WGPUSType_SurfaceSourceXlibWindow; + from_xlib.display = _sapp.x11.display; + from_xlib.window = _sapp.x11.window; + surf_desc.nextInChain = &from_xlib.chain; + #else + #error "sokol_app.h: unsupported WebGPU platform" + #endif + _sapp.wgpu.surface = wgpuInstanceCreateSurface(_sapp.wgpu.instance, &surf_desc); + if (0 == _sapp.wgpu.surface) { + _SAPP_PANIC(WGPU_SWAPCHAIN_CREATE_SURFACE_FAILED); + } + _SAPP_STRUCT(WGPUSurfaceCapabilities, surf_caps); + WGPUStatus caps_status = wgpuSurfaceGetCapabilities(_sapp.wgpu.surface, _sapp.wgpu.adapter, &surf_caps); + if (caps_status != WGPUStatus_Success) { + _SAPP_PANIC(WGPU_SWAPCHAIN_SURFACE_GET_CAPABILITIES_FAILED); + } + _sapp.wgpu.render_format = _sapp_wgpu_pick_render_format(surf_caps.formatCount, surf_caps.formats); + } + + SOKOL_ASSERT(_sapp.wgpu.surface); + _SAPP_STRUCT(WGPUSurfaceConfiguration, surf_conf); + surf_conf.device = _sapp.wgpu.device; + surf_conf.format = _sapp.wgpu.render_format; + surf_conf.usage = WGPUTextureUsage_RenderAttachment; + surf_conf.width = (uint32_t)_sapp.framebuffer_width; + surf_conf.height = (uint32_t)_sapp.framebuffer_height; + surf_conf.alphaMode = WGPUCompositeAlphaMode_Opaque; + #if defined(_SAPP_EMSCRIPTEN) + // FIXME: make this further configurable? + if (_sapp.desc.html5.premultiplied_alpha) { + surf_conf.alphaMode = WGPUCompositeAlphaMode_Premultiplied; + } + #endif + surf_conf.presentMode = WGPUPresentMode_Fifo; + wgpuSurfaceConfigure(_sapp.wgpu.surface, &surf_conf); + + _SAPP_STRUCT(WGPUTextureDescriptor, ds_desc); + ds_desc.usage = WGPUTextureUsage_RenderAttachment; + ds_desc.dimension = WGPUTextureDimension_2D; + ds_desc.size.width = (uint32_t)_sapp.framebuffer_width; + ds_desc.size.height = (uint32_t)_sapp.framebuffer_height; + ds_desc.size.depthOrArrayLayers = 1; + ds_desc.format = WGPUTextureFormat_Depth32FloatStencil8; + ds_desc.mipLevelCount = 1; + ds_desc.sampleCount = (uint32_t)_sapp.sample_count; + _sapp.wgpu.depth_stencil_tex = wgpuDeviceCreateTexture(_sapp.wgpu.device, &ds_desc); + if (0 == _sapp.wgpu.depth_stencil_tex) { + _SAPP_PANIC(WGPU_SWAPCHAIN_CREATE_DEPTH_STENCIL_TEXTURE_FAILED); + } + _sapp.wgpu.depth_stencil_view = wgpuTextureCreateView(_sapp.wgpu.depth_stencil_tex, 0); + if (0 == _sapp.wgpu.depth_stencil_view) { + _SAPP_PANIC(WGPU_SWAPCHAIN_CREATE_DEPTH_STENCIL_VIEW_FAILED); + } + + if (_sapp.sample_count > 1) { + _SAPP_STRUCT(WGPUTextureDescriptor, msaa_desc); + msaa_desc.usage = WGPUTextureUsage_RenderAttachment; + msaa_desc.dimension = WGPUTextureDimension_2D; + msaa_desc.size.width = (uint32_t)_sapp.framebuffer_width; + msaa_desc.size.height = (uint32_t)_sapp.framebuffer_height; + msaa_desc.size.depthOrArrayLayers = 1; + msaa_desc.format = _sapp.wgpu.render_format; + msaa_desc.mipLevelCount = 1; + msaa_desc.sampleCount = (uint32_t)_sapp.sample_count; + _sapp.wgpu.msaa_tex = wgpuDeviceCreateTexture(_sapp.wgpu.device, &msaa_desc); + if (0 == _sapp.wgpu.msaa_tex) { + _SAPP_PANIC(WGPU_SWAPCHAIN_CREATE_MSAA_TEXTURE_FAILED); + } + _sapp.wgpu.msaa_view = wgpuTextureCreateView(_sapp.wgpu.msaa_tex, 0); + if (0 == _sapp.wgpu.msaa_view) { + _SAPP_PANIC(WGPU_SWAPCHAIN_CREATE_MSAA_VIEW_FAILED); + } + } +} + +_SOKOL_PRIVATE void _sapp_wgpu_discard_swapchain(bool called_from_resize) { + if (_sapp.wgpu.msaa_view) { + wgpuTextureViewRelease(_sapp.wgpu.msaa_view); + _sapp.wgpu.msaa_view = 0; + } + if (_sapp.wgpu.msaa_tex) { + wgpuTextureRelease(_sapp.wgpu.msaa_tex); + _sapp.wgpu.msaa_tex = 0; + } + if (_sapp.wgpu.depth_stencil_view) { + wgpuTextureViewRelease(_sapp.wgpu.depth_stencil_view); + _sapp.wgpu.depth_stencil_view = 0; + } + if (_sapp.wgpu.depth_stencil_tex) { + wgpuTextureRelease(_sapp.wgpu.depth_stencil_tex); + _sapp.wgpu.depth_stencil_tex = 0; + } + if (!called_from_resize) { + if (_sapp.wgpu.surface) { + wgpuSurfaceRelease(_sapp.wgpu.surface); + _sapp.wgpu.surface = 0; + } + } +} + +_SOKOL_PRIVATE void _sapp_wgpu_swapchain_next(void) { + SOKOL_ASSERT(0 == _sapp.wgpu.swapchain_view); + _SAPP_STRUCT(WGPUSurfaceTexture, surf_tex); + wgpuSurfaceGetCurrentTexture(_sapp.wgpu.surface, &surf_tex); + switch (surf_tex.status) { + case WGPUSurfaceGetCurrentTextureStatus_SuccessOptimal: + case WGPUSurfaceGetCurrentTextureStatus_SuccessSuboptimal: + // all ok + break; + case WGPUSurfaceGetCurrentTextureStatus_Timeout: + case WGPUSurfaceGetCurrentTextureStatus_Outdated: + case WGPUSurfaceGetCurrentTextureStatus_Lost: + if (surf_tex.texture) { + wgpuTextureRelease(surf_tex.texture); + } + _sapp_wgpu_discard_swapchain(false); + _sapp_wgpu_create_swapchain(false); + // FIXME: currently this will assert in the caller + return; + case WGPUSurfaceGetCurrentTextureStatus_Error: + default: + _SAPP_PANIC(WGPU_SWAPCHAIN_GETCURRENTTEXTURE_FAILED); + break; + } + _sapp.wgpu.swapchain_view = wgpuTextureCreateView(surf_tex.texture, 0); + SOKOL_ASSERT(_sapp.wgpu.swapchain_view); +} + +_SOKOL_PRIVATE void _sapp_wgpu_swapchain_size_changed(void) { + if (_sapp.wgpu.surface) { + _sapp_wgpu_discard_swapchain(true); + _sapp_wgpu_create_swapchain(true); + } +} + +_SOKOL_PRIVATE void _sapp_wgpu_device_lost_cb(const WGPUDevice* dev, WGPUDeviceLostReason reason, WGPUStringView msg, void* ud1, void* ud2) { + _SOKOL_UNUSED(dev); _SOKOL_UNUSED(reason); _SOKOL_UNUSED(ud1); _SOKOL_UNUSED(ud2); + // NOTE: on wgpuInstanceRelease(), the device lost callback is always called with + // WGPUDeviceLostReason_CallbackCancelled (even though no device should exist at that point) + if (reason != WGPUDeviceLostReason_CallbackCancelled) { + SOKOL_ASSERT(msg.data && (msg.length > 0)); + char buf[1024]; + _sapp_strcpy_range(msg.data, msg.length, buf, sizeof(buf)); + _SAPP_ERROR_MSG(WGPU_DEVICE_LOST, buf); + } +} + +// NOTE: emdawnwebgpu doesn't seem to have a device logging callback +#if !defined(_SAPP_EMSCRIPTEN) +_SOKOL_PRIVATE void _sapp_wgpu_device_logging_cb(WGPULoggingType log_type, WGPUStringView msg, void* ud1, void* ud2) { + _SOKOL_UNUSED(log_type); _SOKOL_UNUSED(ud1); _SOKOL_UNUSED(ud2); + SOKOL_ASSERT(msg.data && (msg.length > 0)); + char buf[1024]; + _sapp_strcpy_range(msg.data, msg.length, buf, sizeof(buf)); + switch (log_type) { + case WGPULoggingType_Warning: + _SAPP_WARN_MSG(WGPU_DEVICE_LOG, buf); + break; + case WGPULoggingType_Error: + _SAPP_ERROR_MSG(WGPU_DEVICE_LOG, buf); + break; + default: + _SAPP_INFO_MSG(WGPU_DEVICE_LOG, buf); + break; + } +} +#endif + +_SOKOL_PRIVATE void _sapp_wgpu_uncaptured_error_cb(const WGPUDevice* dev, WGPUErrorType err_type, WGPUStringView msg, void* ud1, void* ud2) { + _SOKOL_UNUSED(dev); _SOKOL_UNUSED(ud1); _SOKOL_UNUSED(ud2); + if (err_type != WGPUErrorType_NoError) { + SOKOL_ASSERT(msg.data && (msg.length > 0)); + char buf[1024]; + _sapp_strcpy_range(msg.data, msg.length, buf, sizeof(buf)); + _SAPP_ERROR_MSG(WGPU_DEVICE_UNCAPTURED_ERROR, buf); + } +} + +_SOKOL_PRIVATE void _sapp_wgpu_request_device_cb(WGPURequestDeviceStatus status, WGPUDevice device, WGPUStringView msg, void* userdata1, void* userdata2) { + _SOKOL_UNUSED(msg); + _SOKOL_UNUSED(userdata1); + _SOKOL_UNUSED(userdata2); + SOKOL_ASSERT(!_sapp.wgpu.init_done); + if (status != WGPURequestDeviceStatus_Success) { + if (status == WGPURequestDeviceStatus_Error) { + _SAPP_PANIC(WGPU_REQUEST_DEVICE_STATUS_ERROR); + } else { + _SAPP_PANIC(WGPU_REQUEST_DEVICE_STATUS_UNKNOWN); + } + } + SOKOL_ASSERT(device); + _sapp.wgpu.device = device; + #if !defined(_SAPP_EMSCRIPTEN) + _SAPP_STRUCT(WGPULoggingCallbackInfo, cb_info); + cb_info.callback = _sapp_wgpu_device_logging_cb; + wgpuDeviceSetLoggingCallback(_sapp.wgpu.device, cb_info); + #endif + _sapp_wgpu_create_swapchain(false); + _sapp.wgpu.init_done = true; +} + +_SOKOL_PRIVATE void _sapp_wgpu_create_device_and_swapchain(void) { + SOKOL_ASSERT(_sapp.wgpu.adapter); + size_t cur_feature_index = 1; + #define _SAPP_WGPU_MAX_REQUESTED_FEATURES (16) + WGPUFeatureName requiredFeatures[_SAPP_WGPU_MAX_REQUESTED_FEATURES] = { + WGPUFeatureName_Depth32FloatStencil8, + }; + // check for optional features we're interested in + if (wgpuAdapterHasFeature(_sapp.wgpu.adapter, WGPUFeatureName_TextureCompressionBC)) { + SOKOL_ASSERT(cur_feature_index < _SAPP_WGPU_MAX_REQUESTED_FEATURES); + requiredFeatures[cur_feature_index++] = WGPUFeatureName_TextureCompressionBC; + } + if (wgpuAdapterHasFeature(_sapp.wgpu.adapter, WGPUFeatureName_TextureCompressionETC2)) { + SOKOL_ASSERT(cur_feature_index < _SAPP_WGPU_MAX_REQUESTED_FEATURES); + requiredFeatures[cur_feature_index++] = WGPUFeatureName_TextureCompressionETC2; + } + if (wgpuAdapterHasFeature(_sapp.wgpu.adapter, WGPUFeatureName_TextureCompressionASTC)) { + SOKOL_ASSERT(cur_feature_index < _SAPP_WGPU_MAX_REQUESTED_FEATURES); + requiredFeatures[cur_feature_index++] = WGPUFeatureName_TextureCompressionASTC; + } + if (wgpuAdapterHasFeature(_sapp.wgpu.adapter, WGPUFeatureName_DualSourceBlending)) { + SOKOL_ASSERT(cur_feature_index < _SAPP_WGPU_MAX_REQUESTED_FEATURES); + requiredFeatures[cur_feature_index++] = WGPUFeatureName_DualSourceBlending; + } + if (wgpuAdapterHasFeature(_sapp.wgpu.adapter, WGPUFeatureName_ShaderF16)) { + SOKOL_ASSERT(cur_feature_index < _SAPP_WGPU_MAX_REQUESTED_FEATURES); + requiredFeatures[cur_feature_index++] = WGPUFeatureName_ShaderF16; + } + if (wgpuAdapterHasFeature(_sapp.wgpu.adapter, WGPUFeatureName_Float32Filterable)) { + SOKOL_ASSERT(cur_feature_index < _SAPP_WGPU_MAX_REQUESTED_FEATURES); + requiredFeatures[cur_feature_index++] = WGPUFeatureName_Float32Filterable; + } + if (wgpuAdapterHasFeature(_sapp.wgpu.adapter, WGPUFeatureName_Float32Blendable)) { + SOKOL_ASSERT(cur_feature_index < _SAPP_WGPU_MAX_REQUESTED_FEATURES); + requiredFeatures[cur_feature_index++] = WGPUFeatureName_Float32Blendable; + } + if (wgpuAdapterHasFeature(_sapp.wgpu.adapter, WGPUFeatureName_TextureFormatsTier2)) { + SOKOL_ASSERT(cur_feature_index < _SAPP_WGPU_MAX_REQUESTED_FEATURES); + requiredFeatures[cur_feature_index++] = WGPUFeatureName_TextureFormatsTier2; + } + #undef _SAPP_WGPU_MAX_REQUESTED_FEATURES + + WGPULimits adapterLimits = WGPU_LIMITS_INIT; + wgpuAdapterGetLimits(_sapp.wgpu.adapter, &adapterLimits); + + WGPULimits requiredLimits = WGPU_LIMITS_INIT; + requiredLimits.maxColorAttachments = adapterLimits.maxColorAttachments; + requiredLimits.maxSampledTexturesPerShaderStage = adapterLimits.maxSampledTexturesPerShaderStage; + requiredLimits.maxStorageBuffersPerShaderStage = adapterLimits.maxStorageBuffersPerShaderStage; + requiredLimits.maxStorageTexturesPerShaderStage = adapterLimits.maxStorageTexturesPerShaderStage; + + _SAPP_STRUCT(WGPURequestDeviceCallbackInfo, cb_info); + cb_info.mode = _sapp_wgpu_callbackmode(); + cb_info.callback = _sapp_wgpu_request_device_cb; + + _SAPP_STRUCT(WGPUDeviceDescriptor, dev_desc); + dev_desc.requiredFeatureCount = cur_feature_index; + dev_desc.requiredFeatures = requiredFeatures; + dev_desc.requiredLimits = &requiredLimits; + dev_desc.deviceLostCallbackInfo.mode = WGPUCallbackMode_AllowProcessEvents; + dev_desc.deviceLostCallbackInfo.callback = _sapp_wgpu_device_lost_cb; + dev_desc.uncapturedErrorCallbackInfo.callback = _sapp_wgpu_uncaptured_error_cb; + WGPUFuture future = wgpuAdapterRequestDevice(_sapp.wgpu.adapter, &dev_desc, cb_info); + #if defined(_SAPP_WGPU_HAS_WAIT) + _sapp_wgpu_await(future); + #else + _SOKOL_UNUSED(future); + #endif +} + +_SOKOL_PRIVATE void _sapp_wgpu_request_adapter_cb(WGPURequestAdapterStatus status, WGPUAdapter adapter, WGPUStringView msg, void* userdata1, void* userdata2) { + _SOKOL_UNUSED(msg); + _SOKOL_UNUSED(userdata1); + _SOKOL_UNUSED(userdata2); + if (status != WGPURequestAdapterStatus_Success) { + switch (status) { + case WGPURequestAdapterStatus_Unavailable: _SAPP_PANIC(WGPU_REQUEST_ADAPTER_STATUS_UNAVAILABLE); break; + case WGPURequestAdapterStatus_Error: _SAPP_PANIC(WGPU_REQUEST_ADAPTER_STATUS_ERROR); break; + default: _SAPP_PANIC(WGPU_REQUEST_ADAPTER_STATUS_UNKNOWN); break; + } + } + SOKOL_ASSERT(adapter); + _sapp.wgpu.adapter = adapter; + #if !defined(_SAPP_WGPU_HAS_WAIT) + // chain device creation + _sapp_wgpu_create_device_and_swapchain(); + #endif +} + +_SOKOL_PRIVATE void _sapp_wgpu_create_adapter(void) { + SOKOL_ASSERT(_sapp.wgpu.instance); + // FIXME: power preference? + _SAPP_STRUCT(WGPURequestAdapterCallbackInfo, cb_info); + cb_info.mode = _sapp_wgpu_callbackmode(); + cb_info.callback = _sapp_wgpu_request_adapter_cb; + WGPUFuture future = wgpuInstanceRequestAdapter(_sapp.wgpu.instance, 0, cb_info); + #if defined(_SAPP_WGPU_HAS_WAIT) + _sapp_wgpu_await(future); + #else + _SOKOL_UNUSED(future); + #endif +} + +_SOKOL_PRIVATE void _sapp_wgpu_init(void) { + SOKOL_ASSERT(0 == _sapp.wgpu.instance); + SOKOL_ASSERT(!_sapp.wgpu.init_done); + + _SAPP_STRUCT(WGPUInstanceDescriptor, desc); + #if defined(_SAPP_WGPU_HAS_WAIT) + WGPUInstanceFeatureName inst_features[1] = { + WGPUInstanceFeatureName_TimedWaitAny, + }; + desc.requiredFeatureCount = 1; + desc.requiredFeatures = inst_features; + #endif + _sapp.wgpu.instance = wgpuCreateInstance(&desc); + if (0 == _sapp.wgpu.instance) { + _SAPP_PANIC(WGPU_CREATE_INSTANCE_FAILED); + } + // NOTE: on Emscripten, device and swapchain creation are chained in the callacks + _sapp_wgpu_create_adapter(); + #if defined(_SAPP_WGPU_HAS_WAIT) + _sapp_wgpu_create_device_and_swapchain(); + SOKOL_ASSERT(_sapp.wgpu.init_done); + #endif +} + +_SOKOL_PRIVATE void _sapp_wgpu_discard(void) { + _sapp_wgpu_discard_swapchain(false); + if (_sapp.wgpu.device) { + wgpuDeviceRelease(_sapp.wgpu.device); + _sapp.wgpu.device = 0; + } + if (_sapp.wgpu.adapter) { + wgpuAdapterRelease(_sapp.wgpu.adapter); + _sapp.wgpu.adapter = 0; + } + if (_sapp.wgpu.instance) { + wgpuInstanceRelease(_sapp.wgpu.instance); + _sapp.wgpu.instance = 0; + } +} + +_SOKOL_PRIVATE void _sapp_wgpu_frame(void) { + wgpuInstanceProcessEvents(_sapp.wgpu.instance); + if (_sapp.wgpu.init_done) { + _sapp_frame(); + if (_sapp.wgpu.swapchain_view) { + wgpuTextureViewRelease(_sapp.wgpu.swapchain_view); + _sapp.wgpu.swapchain_view = 0; + } + #if !defined(_SAPP_EMSCRIPTEN) + wgpuSurfacePresent(_sapp.wgpu.surface); + #endif + } +} +#endif // SOKOL_WGPU + +// ██ ██ ██ ██ ██ ██ ██ █████ ███ ██ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ +// ██ ██ ██ ██ ██ █████ ███████ ██ ██ ██ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ████ ██████ ███████ ██ ██ ██ ██ ██ ████ +// +// >>vulkan +// >>vk +#if defined(SOKOL_VULKAN) + +#if defined(__cplusplus) +#define _SAPP_VK_ZERO_COUNT_AND_ARRAY(num, type, count_name, array_name) uint32_t count_name = 0; type array_name[num] = {} +#define _SAPP_VK_MAX_COUNT_AND_ARRAY(num, type, count_name, array_name) uint32_t count_name = num; type array_name[num] = {} +#else +#define _SAPP_VK_ZERO_COUNT_AND_ARRAY(num, type, count_name, array_name) uint32_t count_name = 0; type array_name[num] = {0} +#define _SAPP_VK_MAX_COUNT_AND_ARRAY(num, type, count_name, array_name) uint32_t count_name = num; type array_name[num] = {0} +#endif + +_SOKOL_PRIVATE void _sapp_vk_load_instance_ext_funcs(void) { + SOKOL_ASSERT(_sapp.vk.instance); + #if defined(SOKOL_DEBUG) + _sapp.vk.ext.set_debug_utils_object_name_ext = (PFN_vkSetDebugUtilsObjectNameEXT)vkGetInstanceProcAddr(_sapp.vk.instance, "vkSetDebugUtilsObjectNameEXT"); + if (0 == _sapp.vk.ext.set_debug_utils_object_name_ext) { + _SAPP_PANIC(VULKAN_REQUIRED_INSTANCE_EXTENSION_FUNCTION_MISSING); + } + #endif +} + +_SOKOL_PRIVATE void _sapp_vk_set_object_label(VkObjectType obj_type, uint64_t obj_handle, const char* label) { + #if defined(SOKOL_DEBUG) + SOKOL_ASSERT(_sapp.vk.device); + SOKOL_ASSERT(_sapp.vk.ext.set_debug_utils_object_name_ext); + SOKOL_ASSERT(obj_handle); + if (label) { + _SAPP_STRUCT(VkDebugUtilsObjectNameInfoEXT, name_info); + name_info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT; + name_info.objectType = obj_type; + name_info.objectHandle = obj_handle, + name_info.pObjectName = label; + VkResult res = _sapp.vk.ext.set_debug_utils_object_name_ext(_sapp.vk.device, &name_info); + SOKOL_ASSERT(res == VK_SUCCESS); + } + #else + _SOKOL_UNUSED(obj_type); + _SOKOL_UNUSED(obj_handle); + _SOKOL_UNUSED(label); + #endif +} + +_SOKOL_PRIVATE int _sapp_vk_mem_find_memory_type_index(uint32_t type_filter, VkMemoryPropertyFlags props) { + SOKOL_ASSERT(_sapp.vk.physical_device); + _SAPP_STRUCT(VkPhysicalDeviceMemoryProperties, mem_props); + vkGetPhysicalDeviceMemoryProperties(_sapp.vk.physical_device, &mem_props); + for (uint32_t i = 0; i < mem_props.memoryTypeCount; i++) { + if ((type_filter & (1 << i)) && ((mem_props.memoryTypes[i].propertyFlags & props) == props)) { + return (int)i; + } + } + return -1; +} + +_SOKOL_PRIVATE void _sapp_vk_create_instance(void) { + SOKOL_ASSERT(0 == _sapp.vk.instance); + + _SAPP_STRUCT(VkApplicationInfo, app_info); + app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; + app_info.pApplicationName = "sokol-app"; // FIXME: override via sapp_desc? + app_info.applicationVersion = VK_MAKE_VERSION(1, 0, 0); + app_info.pEngineName = "sokol"; + app_info.engineVersion = VK_MAKE_VERSION(1, 0, 0); + app_info.apiVersion = VK_API_VERSION_1_3; + + _SAPP_VK_ZERO_COUNT_AND_ARRAY(32, const char*, layer_count, layer_names); + #if defined(SOKOL_DEBUG) + layer_names[layer_count++] = "VK_LAYER_KHRONOS_validation"; + SOKOL_ASSERT(layer_count <= 32); + #endif + + _SAPP_VK_ZERO_COUNT_AND_ARRAY(32, const char*, ext_count, ext_names); + ext_names[ext_count++] = VK_KHR_SURFACE_EXTENSION_NAME; + #if defined(SOKOL_DEBUG) + ext_names[ext_count++] = VK_EXT_DEBUG_UTILS_EXTENSION_NAME; + #endif + #if defined(VK_USE_PLATFORM_XLIB_KHR) + ext_names[ext_count++] = VK_KHR_XLIB_SURFACE_EXTENSION_NAME; + #elif defined(VK_USE_PLATFORM_WIN32_KHR) + ext_names[ext_count++] = VK_KHR_WIN32_SURFACE_EXTENSION_NAME; + #endif + SOKOL_ASSERT(ext_count <= 32); + + _SAPP_STRUCT(VkInstanceCreateInfo, create_info); + create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; + create_info.flags = 0; + create_info.pApplicationInfo = &app_info; + create_info.enabledLayerCount = layer_count; + create_info.ppEnabledLayerNames = layer_names; + create_info.enabledExtensionCount = ext_count; + create_info.ppEnabledExtensionNames = ext_names; + VkResult res = vkCreateInstance(&create_info, 0, &_sapp.vk.instance); + if (res != VK_SUCCESS) { + _SAPP_PANIC(VULKAN_CREATE_INSTANCE_FAILED); + } + SOKOL_ASSERT(_sapp.vk.instance); +} + +_SOKOL_PRIVATE void _sapp_vk_destroy_instance(void) { + SOKOL_ASSERT(_sapp.vk.instance); + vkDestroyInstance(_sapp.vk.instance, 0); + _sapp.vk.instance = 0; +} + +_SOKOL_PRIVATE uint32_t _sapp_vk_required_device_extensions(const char** out_names, uint32_t max_count) { + SOKOL_ASSERT(out_names && (max_count > 0)); + uint32_t count = 0; + out_names[count++] = VK_KHR_SWAPCHAIN_EXTENSION_NAME; + out_names[count++] = VK_EXT_DESCRIPTOR_BUFFER_EXTENSION_NAME; + SOKOL_ASSERT(count <= max_count); _SOKOL_UNUSED(max_count); + return count; +} + +_SOKOL_PRIVATE bool _sapp_vk_check_device_extensions(VkPhysicalDevice pdev, const char** required_exts, uint32_t num_required_exts) { + SOKOL_ASSERT(pdev && required_exts && num_required_exts > 0); + uint32_t ext_count = 0; + VkResult res = vkEnumerateDeviceExtensionProperties(pdev, 0, &ext_count, 0); + SOKOL_ASSERT(res == VK_SUCCESS); _SOKOL_UNUSED(res); + if (ext_count == 0) { + return false; + } + VkExtensionProperties* ext_props = (VkExtensionProperties*) _sapp_malloc(sizeof(VkExtensionProperties) * ext_count); + SOKOL_ASSERT(ext_props); + res = vkEnumerateDeviceExtensionProperties(pdev, 0, &ext_count, ext_props); + bool all_supported = true; + for (uint32_t req_ext_idx = 0; req_ext_idx < num_required_exts; req_ext_idx++) { + const char* req_ext_name = required_exts[req_ext_idx]; + bool required_ext_supported = false; + for (uint32_t ext_idx = 0; ext_idx < ext_count; ext_idx++) { + const VkExtensionProperties* ext_prop = &ext_props[ext_idx]; + if (0 == strcmp(req_ext_name, ext_prop->extensionName)) { + required_ext_supported = true; + break; + } + } + if (!required_ext_supported) { + all_supported = false; + } + } + _sapp_free(ext_props); + return all_supported; +} + +_SOKOL_PRIVATE void _sapp_vk_pick_physical_device(void) { + SOKOL_ASSERT(_sapp.vk.instance); + SOKOL_ASSERT(_sapp.vk.surface); + SOKOL_ASSERT(0 == _sapp.vk.physical_device); + VkResult res = VK_SUCCESS; + + _SAPP_VK_MAX_COUNT_AND_ARRAY(8, VkPhysicalDevice, physical_device_count, physical_devices); + res = vkEnumeratePhysicalDevices(_sapp.vk.instance, &physical_device_count, physical_devices); + if ((res != VK_SUCCESS) && (res != VK_INCOMPLETE)) { + _SAPP_PANIC(VULKAN_ENUMERATE_PHYSICAL_DEVICES_FAILED); + } + if (physical_device_count == 0) { + _SAPP_PANIC(VULKAN_NO_PHYSICAL_DEVICES_FOUND); + } + _SAPP_VK_ZERO_COUNT_AND_ARRAY(32, const char*, ext_count, ext_names); + ext_count = _sapp_vk_required_device_extensions(ext_names, 32); + + VkPhysicalDevice picked_pdev = 0; + for (uint32_t pdev_idx = 0; pdev_idx < physical_device_count; pdev_idx++) { + const VkPhysicalDevice pdev = physical_devices[pdev_idx]; + _SAPP_STRUCT(VkPhysicalDeviceProperties, dev_props); + vkGetPhysicalDeviceProperties(pdev, &dev_props); + if (dev_props.apiVersion < VK_API_VERSION_1_3) { + continue; + } + if (!_sapp_vk_check_device_extensions(pdev, ext_names, ext_count)) { + continue; + } + // FIXME: handle theoretical case where graphics and present aren't supported by the same queue family index + _SAPP_VK_MAX_COUNT_AND_ARRAY(8, VkQueueFamilyProperties, queue_family_props_count, queue_family_props); + vkGetPhysicalDeviceQueueFamilyProperties(pdev, &queue_family_props_count, queue_family_props); + bool has_required_queues = false; + const VkQueueFlags required_flags = VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT; + for (uint32_t qfp_idx = 0; qfp_idx < queue_family_props_count; qfp_idx++) { + const VkQueueFlags queue_flags = queue_family_props[qfp_idx].queueFlags; + if ((queue_flags & required_flags) == required_flags) { + _sapp.vk.queue_family_index = qfp_idx; + has_required_queues = true; + break; + } + } + if (!has_required_queues) { + continue; + } + + VkBool32 presentation_supported = false; + res = vkGetPhysicalDeviceSurfaceSupportKHR(pdev, _sapp.vk.queue_family_index, _sapp.vk.surface, &presentation_supported); + SOKOL_ASSERT(VK_SUCCESS == res); + if (!presentation_supported) { + continue; + } + + // if we arrive here, found a suitable device + picked_pdev = pdev; + break; + } + if (0 == picked_pdev) { + _SAPP_PANIC(VULKAN_NO_SUITABLE_PHYSICAL_DEVICE_FOUND); + } + _sapp.vk.physical_device = picked_pdev; + SOKOL_ASSERT(_sapp.vk.physical_device); +} + +_SOKOL_PRIVATE void _sapp_vk_create_device(void) { + SOKOL_ASSERT(_sapp.vk.physical_device); + SOKOL_ASSERT(0 == _sapp.vk.device); + + const float queue_priority = 0.0f; + _SAPP_STRUCT(VkDeviceQueueCreateInfo, queue_create_info); + queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; + queue_create_info.queueFamilyIndex = _sapp.vk.queue_family_index; + queue_create_info.queueCount = 1; + queue_create_info.pQueuePriorities = &queue_priority; + + _SAPP_VK_ZERO_COUNT_AND_ARRAY(32, const char*, ext_count, ext_names); + ext_count = _sapp_vk_required_device_extensions(ext_names, 32); + + _SAPP_STRUCT(VkPhysicalDeviceFeatures2, supports); + supports.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2; + vkGetPhysicalDeviceFeatures2(_sapp.vk.physical_device, &supports); + + _SAPP_STRUCT(VkPhysicalDeviceDescriptorBufferFeaturesEXT, descriptor_buffer_features); + descriptor_buffer_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_BUFFER_FEATURES_EXT; + descriptor_buffer_features.descriptorBuffer = VK_TRUE; + + _SAPP_STRUCT(VkPhysicalDeviceExtendedDynamicStateFeaturesEXT, xds_features); + xds_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT; + xds_features.pNext = &descriptor_buffer_features; + xds_features.extendedDynamicState = VK_TRUE; + + _SAPP_STRUCT(VkPhysicalDeviceVulkan12Features, vk12_features); + vk12_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES; + vk12_features.pNext = &xds_features; + vk12_features.bufferDeviceAddress = VK_TRUE; + + _SAPP_STRUCT(VkPhysicalDeviceVulkan13Features, vk13_features); + vk13_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES; + vk13_features.pNext = &vk12_features; + vk13_features.dynamicRendering = VK_TRUE; + vk13_features.synchronization2 = VK_TRUE; + + _SAPP_STRUCT(VkPhysicalDeviceFeatures2, required); + required.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2; + required.pNext = &vk13_features; + required.features.samplerAnisotropy = VK_TRUE; + required.features.dualSrcBlend = VK_TRUE; + if (supports.features.textureCompressionBC) { + required.features.textureCompressionBC = VK_TRUE; + } + if (supports.features.textureCompressionETC2) { + required.features.textureCompressionETC2 = VK_TRUE; + } + if (supports.features.textureCompressionASTC_LDR) { + required.features.textureCompressionASTC_LDR = VK_TRUE; + } + _SAPP_STRUCT(VkDeviceCreateInfo, dev_create_info); + dev_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; + dev_create_info.pNext = &required; + dev_create_info.queueCreateInfoCount = 1; + dev_create_info.pQueueCreateInfos = &queue_create_info; + dev_create_info.enabledExtensionCount = ext_count; + dev_create_info.ppEnabledExtensionNames = ext_names; + + VkResult res = vkCreateDevice(_sapp.vk.physical_device, &dev_create_info, 0, &_sapp.vk.device); + if (res != VK_SUCCESS) { + switch (res) { + case VK_ERROR_EXTENSION_NOT_PRESENT: + _SAPP_PANIC(VULKAN_CREATE_DEVICE_FAILED_EXTENSION_NOT_PRESENT); + break; + case VK_ERROR_FEATURE_NOT_PRESENT: + _SAPP_PANIC(VULKAN_CREATE_DEVICE_FAILED_FEATURE_NOT_PRESENT); + break; + case VK_ERROR_INITIALIZATION_FAILED: + _SAPP_PANIC(VULKAN_CREATE_DEVICE_FAILED_INITIALIZATION_FAILED); + break; + default: + _SAPP_PANIC(VULKAN_CREATE_DEVICE_FAILED_OTHER); + break; + } + } + SOKOL_ASSERT(_sapp.vk.device); + + SOKOL_ASSERT(0 == _sapp.vk.queue); + vkGetDeviceQueue(_sapp.vk.device, _sapp.vk.queue_family_index, 0, &_sapp.vk.queue); + SOKOL_ASSERT(_sapp.vk.queue); +} + +_SOKOL_PRIVATE void _sapp_vk_destroy_device(void) { + SOKOL_ASSERT(_sapp.vk.device); + vkDestroyDevice(_sapp.vk.device, 0); + _sapp.vk.device = 0; + _sapp.vk.queue = 0; +} + +_SOKOL_PRIVATE void _sapp_vk_create_surface(void) { + SOKOL_ASSERT(_sapp.vk.instance); + SOKOL_ASSERT(0 == _sapp.vk.surface); + VkResult res = VK_SUCCESS; + + #if defined(_SAPP_LINUX) + _SAPP_STRUCT(VkXlibSurfaceCreateInfoKHR, xlib_info); + xlib_info.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR; + xlib_info.dpy = _sapp.x11.display; + xlib_info.window = _sapp.x11.window; + res = vkCreateXlibSurfaceKHR(_sapp.vk.instance, &xlib_info, 0, &_sapp.vk.surface); + #elif defined(_SAPP_WIN32) + _SAPP_STRUCT(VkWin32SurfaceCreateInfoKHR, win32_info); + win32_info.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR; + win32_info.hinstance = GetModuleHandleW(NULL); + win32_info.hwnd = _sapp.win32.hwnd; + res = vkCreateWin32SurfaceKHR(_sapp.vk.instance, &win32_info, 0, &_sapp.vk.surface); + #else + #error "sokol_app.h: unsupported Vulkan platform" + #endif + if (res != VK_SUCCESS) { + _SAPP_PANIC(VULKAN_CREATE_SURFACE_FAILED); + } + SOKOL_ASSERT(_sapp.vk.surface); +} + +_SOKOL_PRIVATE void _sapp_vk_destroy_surface(void) { + SOKOL_ASSERT(_sapp.vk.instance); + SOKOL_ASSERT(_sapp.vk.surface); + vkDestroySurfaceKHR(_sapp.vk.instance, _sapp.vk.surface, 0); + _sapp.vk.surface = 0; +} + +_SOKOL_PRIVATE VkSurfaceFormatKHR _sapp_vk_pick_surface_format(void) { + SOKOL_ASSERT(_sapp.vk.instance); + SOKOL_ASSERT(_sapp.vk.surface); + _SAPP_VK_MAX_COUNT_AND_ARRAY(64, VkSurfaceFormatKHR, fmt_count, formats); + VkResult res = vkGetPhysicalDeviceSurfaceFormatsKHR(_sapp.vk.physical_device, _sapp.vk.surface, &fmt_count, formats); + SOKOL_ASSERT((res == VK_SUCCESS) || (res == VK_INCOMPLETE)); _SOKOL_UNUSED(res); + SOKOL_ASSERT(fmt_count > 0); + // FIXME: only accept non-SRGB formats until sokol_app.h gets proper SRGB support + for (uint32_t i = 0; i < fmt_count; i++) { + switch (formats[i].format) { + case VK_FORMAT_B8G8R8A8_UNORM: + case VK_FORMAT_R8G8B8A8_UNORM: + return formats[i]; + default: break; + } + } + // FIXME: fallback might still return an SRGB format + return formats[0]; +} + +_SOKOL_PRIVATE void _sapp_vk_create_sync_objects(void) { + SOKOL_ASSERT(_sapp.vk.device); + _SAPP_STRUCT(VkSemaphoreCreateInfo, create_info); + create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; + VkResult res; + _SOKOL_UNUSED(res); + for (uint32_t i = 0; i < _sapp.vk.num_swapchain_images; i++) { + SOKOL_ASSERT(0 == _sapp.vk.sync[i].present_complete_sem); + SOKOL_ASSERT(0 == _sapp.vk.sync[i].render_finished_sem); + res = vkCreateSemaphore(_sapp.vk.device, &create_info, 0, &_sapp.vk.sync[i].present_complete_sem); + SOKOL_ASSERT((res == VK_SUCCESS) && (_sapp.vk.sync[i].present_complete_sem)); + _sapp_vk_set_object_label(VK_OBJECT_TYPE_SEMAPHORE, (uint64_t)_sapp.vk.sync[i].present_complete_sem, "present_complete_sem"); + res = vkCreateSemaphore(_sapp.vk.device, &create_info, 0, &_sapp.vk.sync[i].render_finished_sem); + SOKOL_ASSERT((res == VK_SUCCESS) && (_sapp.vk.sync[i].render_finished_sem)); + _sapp_vk_set_object_label(VK_OBJECT_TYPE_SEMAPHORE, (uint64_t)_sapp.vk.sync[i].render_finished_sem, "render_finished_sem"); + } +} + +_SOKOL_PRIVATE void _sapp_vk_destroy_sync_objects(void) { + SOKOL_ASSERT(_sapp.vk.device); + for (uint32_t i = 0; i < _sapp.vk.num_swapchain_images; i++) { + SOKOL_ASSERT(_sapp.vk.sync[i].present_complete_sem); + SOKOL_ASSERT(_sapp.vk.sync[i].render_finished_sem); + vkDestroySemaphore(_sapp.vk.device, _sapp.vk.sync[i].present_complete_sem, 0); + vkDestroySemaphore(_sapp.vk.device, _sapp.vk.sync[i].render_finished_sem, 0); + _sapp.vk.sync[i].present_complete_sem = 0; + _sapp.vk.sync[i].render_finished_sem = 0; + } +} + +_SOKOL_PRIVATE VkDeviceMemory _sapp_vk_mem_alloc_image_memory(const VkMemoryRequirements* mem_reqs) { + SOKOL_ASSERT(_sapp.vk.device); + SOKOL_ASSERT(mem_reqs); + int mem_type_index = _sapp_vk_mem_find_memory_type_index(mem_reqs->memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); + if (-1 == mem_type_index) { + _SAPP_ERROR(VULKAN_ALLOC_DEVICE_MEMORY_NO_SUITABLE_MEMORY_TYPE); + return 0; + } + _SAPP_STRUCT(VkMemoryAllocateInfo, alloc_info); + alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + alloc_info.allocationSize = mem_reqs->size; + alloc_info.memoryTypeIndex = (uint32_t) mem_type_index; + VkDeviceMemory vk_dev_mem = 0; + VkResult res = vkAllocateMemory(_sapp.vk.device, &alloc_info, 0, &vk_dev_mem); + if (res != VK_SUCCESS) { + _SAPP_ERROR(VULKAN_ALLOCATE_MEMORY_FAILED); + return 0; + } + SOKOL_ASSERT(vk_dev_mem); + return vk_dev_mem; +} + +_SOKOL_PRIVATE void _sapp_vk_mem_free_image_memory(VkDeviceMemory vk_dev_mem) { + SOKOL_ASSERT(_sapp.vk.device); + SOKOL_ASSERT(vk_dev_mem); + vkFreeMemory(_sapp.vk.device, vk_dev_mem, 0); +} + +_SOKOL_PRIVATE void _sapp_vk_swapchain_destroy_surface(_sapp_vk_swapchain_surface_t* surf) { + SOKOL_ASSERT(surf); + SOKOL_ASSERT(surf->img); + SOKOL_ASSERT(surf->mem); + SOKOL_ASSERT(surf->view); + vkDestroyImageView(_sapp.vk.device, surf->view, 0); + surf->view = 0; + _sapp_vk_mem_free_image_memory(surf->mem); + surf->mem = 0; + vkDestroyImage(_sapp.vk.device, surf->img, 0); + surf->img = 0; +} + +_SOKOL_PRIVATE void _sapp_vk_swapchain_create_surface( + _sapp_vk_swapchain_surface_t* surf, + bool recreate, + VkFormat format, + uint32_t width, + uint32_t height, + VkSampleCountFlagBits sample_count_flags, + VkImageUsageFlags usage, + VkImageAspectFlags aspect_mask, + const char* image_debug_label, + const char* view_debug_label) +{ + SOKOL_ASSERT(_sapp.vk.physical_device); + SOKOL_ASSERT(_sapp.vk.device); + SOKOL_ASSERT(surf); + if (recreate) { + _sapp_vk_swapchain_destroy_surface(surf); + } + SOKOL_ASSERT(0 == surf->img); + SOKOL_ASSERT(0 == surf->mem); + SOKOL_ASSERT(0 == surf->view); + VkResult res; + + _SAPP_STRUCT(VkImageCreateInfo, img_create_info); + img_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + img_create_info.imageType = VK_IMAGE_TYPE_2D; + img_create_info.format = format; + img_create_info.extent.width = width; + img_create_info.extent.height = height; + img_create_info.extent.depth = 1; + img_create_info.mipLevels = 1; + img_create_info.arrayLayers = 1; + img_create_info.samples = sample_count_flags; + img_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; + img_create_info.usage = usage; + img_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + img_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + res = vkCreateImage(_sapp.vk.device, &img_create_info, 0, &surf->img); + if (res != VK_SUCCESS) { + _SAPP_PANIC(VULKAN_SWAPCHAIN_CREATE_IMAGE_FAILED); + } + SOKOL_ASSERT(surf->img); + _sapp_vk_set_object_label(VK_OBJECT_TYPE_IMAGE, (uint64_t)surf->img, image_debug_label); + + _SAPP_STRUCT(VkMemoryRequirements, mem_reqs); + vkGetImageMemoryRequirements(_sapp.vk.device, surf->img, &mem_reqs); + surf->mem = _sapp_vk_mem_alloc_image_memory(&mem_reqs); + if (0 == surf->mem) { + _SAPP_PANIC(VULKAN_SWAPCHAIN_ALLOC_IMAGE_DEVICE_MEMORY_FAILED); + } + res = vkBindImageMemory(_sapp.vk.device, surf->img, surf->mem, 0); + if (res != VK_SUCCESS) { + _SAPP_PANIC(VULKAN_SWAPCHAIN_BIND_IMAGE_MEMORY_FAILED); + } + SOKOL_ASSERT(surf->mem); + + _SAPP_STRUCT(VkImageViewCreateInfo, view_create_info); + view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + view_create_info.image = surf->img; + view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + view_create_info.format = format; + view_create_info.subresourceRange.aspectMask = aspect_mask; + view_create_info.subresourceRange.levelCount = 1; + view_create_info.subresourceRange.layerCount = 1; + res = vkCreateImageView(_sapp.vk.device, &view_create_info, 0, &surf->view); + if (res != VK_SUCCESS) { + _SAPP_PANIC(VULKAN_SWAPCHAIN_CREATE_IMAGE_VIEW_FAILED); + } + SOKOL_ASSERT(surf->view); + _sapp_vk_set_object_label(VK_OBJECT_TYPE_IMAGE_VIEW, (uint64_t)surf->view, view_debug_label); +} + +_SOKOL_PRIVATE uint32_t _sapp_vk_swapchain_min_image_count(const VkSurfaceCapabilitiesKHR* surf_caps) { + // FIXME: figure out why at least 3 swapchain images are required to appease the validation layer + // (on the Linux Intel driver, present-mode-fifo has a surf_caps.minImageCount == 3, while + // on Windows surf_caps.minImageCount == 2, and using this directly causes validation layer + // errors about the present-complete semaphore (to reproduce simply change the '= 3' below to '= 2') + SOKOL_ASSERT(surf_caps); + const uint32_t required_image_count = 3; + uint32_t min_image_count = surf_caps->minImageCount; + if (min_image_count < required_image_count) { + min_image_count = required_image_count; + } + return min_image_count; +} + +_SOKOL_PRIVATE void _sapp_vk_create_swapchain_image_view(uint32_t image_index) { + SOKOL_ASSERT(_sapp.vk.device); + SOKOL_ASSERT(image_index < _sapp.vk.num_swapchain_images); + SOKOL_ASSERT(_sapp.vk.swapchain_images[image_index]); + SOKOL_ASSERT(0 == _sapp.vk.swapchain_views[image_index]); + + _SAPP_STRUCT(VkImageViewCreateInfo, view_create_info); + view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + view_create_info.format = _sapp.vk.surface_format.format; + view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + view_create_info.subresourceRange.levelCount = 1; + view_create_info.subresourceRange.layerCount = 1; + view_create_info.image = _sapp.vk.swapchain_images[image_index]; + VkResult res = vkCreateImageView(_sapp.vk.device, &view_create_info, 0, &_sapp.vk.swapchain_views[image_index]); + if (res != VK_SUCCESS) { + _SAPP_PANIC(VULKAN_SWAPCHAIN_CREATE_IMAGE_VIEW_FAILED); + } + SOKOL_ASSERT(_sapp.vk.swapchain_views[image_index]); + _sapp_vk_set_object_label(VK_OBJECT_TYPE_IMAGE_VIEW, (uint64_t)_sapp.vk.swapchain_views[image_index], "swapchain_view"); +} + +_SOKOL_PRIVATE void _sapp_vk_destroy_swapchain_image_view(uint32_t image_index) { + SOKOL_ASSERT(_sapp.vk.device); + SOKOL_ASSERT(image_index < _sapp.vk.num_swapchain_images); + SOKOL_ASSERT(_sapp.vk.swapchain_views[image_index]); + vkDestroyImageView(_sapp.vk.device, _sapp.vk.swapchain_views[image_index], 0); + _sapp.vk.swapchain_views[image_index] = 0; +} + +_SOKOL_PRIVATE void _sapp_vk_create_swapchain(bool recreate) { + SOKOL_ASSERT(_sapp.vk.physical_device); + SOKOL_ASSERT(_sapp.vk.surface); + SOKOL_ASSERT(_sapp.vk.device); + if (!recreate) { + SOKOL_ASSERT(0 == _sapp.vk.swapchain); + SOKOL_ASSERT(0 == _sapp.vk.num_swapchain_images); + SOKOL_ASSERT(0 == _sapp.vk.swapchain_images[0]); + SOKOL_ASSERT(0 == _sapp.vk.swapchain_views[0]); + } else { + SOKOL_ASSERT(_sapp.vk.swapchain); + SOKOL_ASSERT(_sapp.vk.num_swapchain_images > 0); + SOKOL_ASSERT(_sapp.vk.swapchain_images[0]); + SOKOL_ASSERT(_sapp.vk.swapchain_views[0]); + } + + VkSwapchainKHR old_swapchain = _sapp.vk.swapchain; + + _SAPP_STRUCT(VkSurfaceCapabilitiesKHR, surf_caps); + VkResult res = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(_sapp.vk.physical_device, _sapp.vk.surface, &surf_caps); + SOKOL_ASSERT(res == VK_SUCCESS); + const uint32_t fb_width = surf_caps.currentExtent.width; + const uint32_t fb_height = surf_caps.currentExtent.height; + + _sapp.vk.surface_format = _sapp_vk_pick_surface_format(); + const VkPresentModeKHR present_mode = VK_PRESENT_MODE_FIFO_KHR; + + _SAPP_STRUCT(VkSwapchainCreateInfoKHR, create_info); + create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; + create_info.flags = 0; + create_info.surface = _sapp.vk.surface; + create_info.minImageCount = _sapp_vk_swapchain_min_image_count(&surf_caps); + create_info.imageFormat = _sapp.vk.surface_format.format; + create_info.imageColorSpace = _sapp.vk.surface_format.colorSpace; + create_info.imageExtent.width = fb_width; + create_info.imageExtent.height = fb_height; + create_info.imageArrayLayers = 1; + create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; + create_info.preTransform = surf_caps.currentTransform; + create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; + create_info.presentMode = present_mode; + create_info.clipped = true; + create_info.oldSwapchain = old_swapchain; + res = vkCreateSwapchainKHR(_sapp.vk.device, &create_info, 0, &_sapp.vk.swapchain); + if (res != VK_SUCCESS) { + _SAPP_PANIC(VULKAN_CREATE_SWAPCHAIN_FAILED); + } + SOKOL_ASSERT(_sapp.vk.swapchain); + + if (old_swapchain) { + // NOTE: destroying the depth- and msaa-surfaces happens + // down in the respective _sapp_vk_swapchain_create_surface() calls! + for (uint32_t i = 0; i < _sapp.vk.num_swapchain_images; i++) { + _sapp_vk_destroy_swapchain_image_view(i); + } + vkDestroySwapchainKHR(_sapp.vk.device, old_swapchain, 0); + } + + _sapp.vk.num_swapchain_images = _SAPP_VK_MAX_SWAPCHAIN_IMAGES; + res = vkGetSwapchainImagesKHR(_sapp.vk.device, + _sapp.vk.swapchain, + &_sapp.vk.num_swapchain_images, + _sapp.vk.swapchain_images); + SOKOL_ASSERT(res == VK_SUCCESS); + SOKOL_ASSERT(_sapp.vk.num_swapchain_images >= surf_caps.minImageCount); + + for (uint32_t i = 0; i < _sapp.vk.num_swapchain_images; i++) { + _sapp_vk_create_swapchain_image_view(i); + } + + // create depth-stencil buffer + _sapp_vk_swapchain_create_surface(&_sapp.vk.depth, + recreate, + VK_FORMAT_D32_SFLOAT_S8_UINT, + fb_width, + fb_height, + (VkSampleCountFlagBits)_sapp.sample_count, + VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, + VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, + "swapchain_depthstencil_image", + "swapchain_depthstencil_view"); + + // optionally create MSAA surface + if (_sapp.sample_count > 1) { + _sapp_vk_swapchain_create_surface(&_sapp.vk.msaa, + recreate, + _sapp.vk.surface_format.format, + fb_width, + fb_height, + (VkSampleCountFlagBits)_sapp.sample_count, + VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, + VK_IMAGE_ASPECT_COLOR_BIT, + "swapchain_msaa_image", + "swapchain_msaa_view"); + } + + // this is the only place in the Vulkan code path which updates + // _sapp.framebuffer_width/height + _sapp.framebuffer_width = (int)fb_width; + _sapp.framebuffer_height = (int)fb_height; +} + +_SOKOL_PRIVATE void _sapp_vk_destroy_swapchain(void) { + SOKOL_ASSERT(_sapp.vk.device); + SOKOL_ASSERT(_sapp.vk.swapchain); + SOKOL_ASSERT(_sapp.vk.num_swapchain_images > 0); + if (_sapp.vk.msaa.img) { + _sapp_vk_swapchain_destroy_surface(&_sapp.vk.msaa); + } + _sapp_vk_swapchain_destroy_surface(&_sapp.vk.depth); + for (uint32_t i = 0; i < _sapp.vk.num_swapchain_images; i++) { + _sapp_vk_destroy_swapchain_image_view(i); + _sapp.vk.swapchain_images[i] = 0; + } + vkDestroySwapchainKHR(_sapp.vk.device, _sapp.vk.swapchain, 0); + _sapp.vk.swapchain = 0; + _sapp.vk.num_swapchain_images = 0; +} + +#if defined(_SAPP_LINUX) +_SOKOL_PRIVATE void _sapp_x11_app_event(sapp_event_type type); +#endif +#if defined(_SAPP_WIN32) +_SOKOL_PRIVATE void _sapp_win32_app_event(sapp_event_type type); +#endif + +_SOKOL_PRIVATE void _sapp_vk_recreate_swapchain(void) { + SOKOL_ASSERT(_sapp.vk.device); + vkDeviceWaitIdle(_sapp.vk.device); + int fb_width = _sapp.framebuffer_width; + int fb_height = _sapp.framebuffer_height; + _sapp_vk_create_swapchain(true); + if ((fb_width != _sapp.framebuffer_width) || (fb_height != _sapp.framebuffer_height)) { + if (!_sapp.first_frame) { + #if defined(_SAPP_LINUX) + _sapp_x11_app_event(SAPP_EVENTTYPE_RESIZED); + #endif + #if defined(_SAPP_WIN32) + _sapp_win32_app_event(SAPP_EVENTTYPE_RESIZED); + #endif + } + } +} + +_SOKOL_PRIVATE void _sapp_vk_init(void) { + _sapp_vk_create_instance(); + _sapp_vk_load_instance_ext_funcs(); + _sapp_vk_create_surface(); + _sapp_vk_pick_physical_device(); + _sapp_vk_create_device(); + _sapp_vk_create_swapchain(false); + _sapp_vk_create_sync_objects(); +} + +_SOKOL_PRIVATE void _sapp_vk_discard(void) { + SOKOL_ASSERT(_sapp.vk.device); + vkDeviceWaitIdle(_sapp.vk.device); + _sapp_vk_destroy_sync_objects(); + _sapp_vk_destroy_swapchain(); + _sapp_vk_destroy_device(); + _sapp_vk_destroy_surface(); + _sapp_vk_destroy_instance(); +} + +_SOKOL_PRIVATE void _sapp_vk_swapchain_next(void) { + SOKOL_ASSERT(_sapp.vk.device); + SOKOL_ASSERT(_sapp.vk.swapchain); + _sapp.vk.swapchain_acquired = true; + VkResult res = vkAcquireNextImageKHR( + _sapp.vk.device, + _sapp.vk.swapchain, + UINT64_MAX, // timeout + _sapp.vk.sync[_sapp.vk.sync_slot].present_complete_sem, // semaphore to signal + 0, // fence to signal + &_sapp.vk.cur_swapchain_image_index); + if ((res != VK_NOT_READY) && (res != VK_SUBOPTIMAL_KHR) && (res != VK_SUCCESS) && (res != VK_TIMEOUT)) { + _SAPP_WARN(VULKAN_ACQUIRE_NEXT_IMAGE_FAILED); + } +} + +_SOKOL_PRIVATE void _sapp_vk_present(void) { + SOKOL_ASSERT(_sapp.vk.queue); + if (_sapp.vk.swapchain_acquired) { + _sapp.vk.swapchain_acquired = false; + _SAPP_STRUCT(VkPresentInfoKHR, present_info); + present_info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; + present_info.waitSemaphoreCount = 1; + // NOTE: using the current swapchain image index here instead of `sync_slot` is *NOT* a bug! The render_finished_semaphore *must* + // be associated with the current swapchain image in case the swapchain implementation doesn't return swapchain images in order + present_info.pWaitSemaphores = &_sapp.vk.sync[_sapp.vk.cur_swapchain_image_index].render_finished_sem; + present_info.swapchainCount = 1; + present_info.pSwapchains = &_sapp.vk.swapchain; + present_info.pImageIndices = &_sapp.vk.cur_swapchain_image_index; + VkResult res = vkQueuePresentKHR(_sapp.vk.queue, &present_info); + if ((res == VK_ERROR_OUT_OF_DATE_KHR) || (res == VK_SUBOPTIMAL_KHR)) { + _sapp_vk_recreate_swapchain(); + } else if (res != VK_SUCCESS) { + _SAPP_WARN(VULKAN_QUEUE_PRESENT_FAILED); + } + } +} + +_SOKOL_PRIVATE void _sapp_vk_frame(void) { + _sapp_frame(); + _sapp_vk_present(); + _sapp.vk.sync_slot = (_sapp.vk.sync_slot + 1) % _sapp.vk.num_swapchain_images; +} + +#endif // SOKOL_VULKAN + +// █████ ██████ ██████ ██ ███████ +// ██ ██ ██ ██ ██ ██ ██ ██ +// ███████ ██████ ██████ ██ █████ +// ██ ██ ██ ██ ██ ██ +// ██ ██ ██ ██ ███████ ███████ +// +// >>apple +#if defined(_SAPP_APPLE) + +#if __has_feature(objc_arc) +#define _SAPP_OBJC_RELEASE(obj) { obj = nil; } +#else +#define _SAPP_OBJC_RELEASE(obj) { [obj release]; obj = nil; } +#endif + +// ███ ███ █████ ██████ ██████ ███████ +// ████ ████ ██ ██ ██ ██ ██ ██ +// ██ ████ ██ ███████ ██ ██ ██ ███████ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ██ ██ ██ ██ ██████ ██████ ███████ +// +// >>macos +#if defined(_SAPP_MACOS) + +#define _SAPP_MACOS_MTL_OBSCURED_FRAME_DURATION_IN_SECONDS (0.0166667) + +_SOKOL_PRIVATE NSInteger _sapp_macos_max_fps(void) { + return [NSScreen.mainScreen maximumFramesPerSecond]; +} + +#if defined(SOKOL_METAL) +_SOKOL_PRIVATE id _sapp_macos_mtl_create_texture(int width, int height, MTLPixelFormat fmt, int sample_count, const char* label) { + MTLTextureDescriptor* mtl_desc = [[MTLTextureDescriptor alloc] init]; + if (sample_count > 1) { + mtl_desc.textureType = MTLTextureType2DMultisample; + } else { + mtl_desc.textureType = MTLTextureType2D; + } + mtl_desc.pixelFormat = fmt; + mtl_desc.width = (NSUInteger)width; + mtl_desc.height = (NSUInteger)height; + mtl_desc.depth = 1; + mtl_desc.mipmapLevelCount = 1; + mtl_desc.arrayLength = 1; + mtl_desc.sampleCount = (NSUInteger)sample_count; + mtl_desc.usage = MTLTextureUsageRenderTarget; + mtl_desc.resourceOptions = MTLResourceStorageModePrivate; + id mtl_tex = [_sapp.macos.mtl.device newTextureWithDescriptor:mtl_desc]; + _SAPP_OBJC_RELEASE(mtl_desc); + #if defined(SOKOL_DEBUG) + if (mtl_tex) { + mtl_tex.label = [NSString stringWithUTF8String:label]; + } + #else + _SOKOL_UNUSED(label); + #endif + return mtl_tex; +} + +_SOKOL_PRIVATE void _sapp_macos_mtl_swapchain_create(int width, int height) { + _sapp.macos.mtl.depth_tex =_sapp_macos_mtl_create_texture(width, height, MTLPixelFormatDepth32Float_Stencil8, _sapp.sample_count, "swapchain_depth_tex"); + if (nil == _sapp.macos.mtl.depth_tex) { + _SAPP_PANIC(METAL_CREATE_SWAPCHAIN_DEPTH_TEXTURE_FAILED); + } + if (_sapp.sample_count > 1) { + _sapp.macos.mtl.msaa_tex = _sapp_macos_mtl_create_texture(width, height, MTLPixelFormatBGRA8Unorm, _sapp.sample_count, "swapchain_msaa_tex"); + if (nil == _sapp.macos.mtl.msaa_tex) { + _SAPP_PANIC(METAL_CREATE_SWAPCHAIN_MSAA_TEXTURE_FAILED); + } + } +} + +_SOKOL_PRIVATE void _sapp_macos_mtl_swapchain_destroy(void) { + if (_sapp.macos.mtl.depth_tex) { + _SAPP_OBJC_RELEASE(_sapp.macos.mtl.depth_tex); + } + if (_sapp.macos.mtl.msaa_tex) { + _SAPP_OBJC_RELEASE(_sapp.macos.mtl.msaa_tex); + } +} + +_SOKOL_PRIVATE void _sapp_macos_mtl_swapchain_resize(int width, int height) { + _sapp_macos_mtl_swapchain_destroy(); + _sapp_macos_mtl_swapchain_create(width, height); +} + +_SOKOL_PRIVATE id _sapp_macos_mtl_swapchain_next(void) { + id drawable = [_sapp.macos.mtl.layer nextDrawable]; + SOKOL_ASSERT(drawable != nil); + return drawable; +} + +_SOKOL_PRIVATE bool _sapp_macos_mtl_display_link_active(void) { + return (nil != _sapp.macos.mtl.display_link) && (!_sapp.macos.mtl.display_link.paused); +} + +_SOKOL_PRIVATE void _sapp_macos_mtl_timing_init(void) { + _sapp.macos.mtl.timing.timestamp = 0.0; + _sapp.macos.mtl.timing.frame_duration_sec = 1.0 / _sapp_macos_max_fps(); +} + +_SOKOL_PRIVATE void _sapp_macos_mtl_timing_update(void) { + // NOTE: if display link is not active, frame duration will be provided + // by the regular platform-agnostic timing code + if (_sapp_macos_mtl_display_link_active()) { + CFTimeInterval cur_timestamp = _sapp.macos.mtl.display_link.timestamp; + // skip first frame (frame_duration had been initialized to display refresh rate) + if (_sapp.macos.mtl.timing.timestamp > 0.0) { + const double dt = cur_timestamp - _sapp.macos.mtl.timing.timestamp; + _sapp.macos.mtl.timing.frame_duration_sec = _sapp_timing_clamp(&_sapp.timing, dt); + } else { + SOKOL_ASSERT(_sapp.macos.mtl.timing.frame_duration_sec > 0.0); + } + _sapp.macos.mtl.timing.timestamp = cur_timestamp; + } +} + +_SOKOL_PRIVATE double _sapp_macos_mtl_timing_frame_duration(void) { + if (_sapp_macos_mtl_display_link_active()) { + SOKOL_ASSERT(_sapp.macos.mtl.timing.frame_duration_sec > 0.0); + return _sapp.macos.mtl.timing.frame_duration_sec; + } else { + return _sapp_timing_get(&_sapp.timing); + } +} + +_SOKOL_PRIVATE void _sapp_macos_mtl_start_display_link(void) { + if (nil != _sapp.macos.mtl.display_link) { + _sapp.macos.mtl.display_link.paused = false; + return; + } + // NOTE: CADisplayLink is only available since macOS 14.0 + SOKOL_ASSERT(nil == _sapp.macos.mtl.display_link); + SOKOL_ASSERT(nil == _sapp.macos.mtl.fallback_timer); + SOKOL_ASSERT(nil != _sapp.macos.view); + NSInteger max_fps = _sapp_macos_max_fps(); + _sapp.macos.mtl.display_link = [_sapp.macos.view displayLinkWithTarget:_sapp.macos.view selector:@selector(displayLinkFired:)]; + const float preferred_fps = max_fps / _sapp.swap_interval; + const CAFrameRateRange frame_rate_range = { preferred_fps, preferred_fps, preferred_fps }; + _sapp.macos.mtl.display_link.preferredFrameRateRange = frame_rate_range; + [_sapp.macos.mtl.display_link addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes]; +} + +_SOKOL_PRIVATE void _sapp_macos_mtl_stop_display_link(void) { + if (nil != _sapp.macos.mtl.display_link) { + _sapp.macos.mtl.display_link.paused = true; + } +} + +_SOKOL_PRIVATE void _sapp_macos_mtl_start_fallback_timer(void) { + SOKOL_ASSERT(nil == _sapp.macos.mtl.fallback_timer); + _sapp.macos.mtl.fallback_timer = [NSTimer + timerWithTimeInterval: _SAPP_MACOS_MTL_OBSCURED_FRAME_DURATION_IN_SECONDS + target: _sapp.macos.view + selector: @selector(fallbackTimerFired:) + userInfo: nil + repeats: YES]; + [[NSRunLoop currentRunLoop] addTimer:_sapp.macos.mtl.fallback_timer forMode:NSRunLoopCommonModes]; +} + +_SOKOL_PRIVATE void _sapp_macos_mtl_stop_fallback_timer(void) { + if (nil != _sapp.macos.mtl.fallback_timer) { + [_sapp.macos.mtl.fallback_timer invalidate]; + _sapp.macos.mtl.fallback_timer = nil; + } +} + +_SOKOL_PRIVATE void _sapp_macos_mtl_transition_to_occluded(void) { + if (_sapp_macos_mtl_display_link_active()) { + _sapp_macos_mtl_stop_display_link(); + _sapp_macos_mtl_start_fallback_timer(); + } +} + +_SOKOL_PRIVATE void _sapp_macos_mtl_transition_to_visible(void) { + if (!_sapp_macos_mtl_display_link_active()) { + _sapp_macos_mtl_stop_fallback_timer(); + _sapp_macos_mtl_start_display_link(); + } +} + +_SOKOL_PRIVATE void _sapp_macos_mtl_init(void) { + _sapp.macos.mtl.device = MTLCreateSystemDefaultDevice(); + _sapp.macos.mtl.layer = [CAMetalLayer layer]; + _sapp.macos.mtl.layer.device = _sapp.macos.mtl.device; + _sapp.macos.mtl.layer.magnificationFilter = kCAFilterNearest; + _sapp.macos.mtl.layer.opaque = true; + _sapp.macos.mtl.layer.pixelFormat = MTLPixelFormatBGRA8Unorm; + _sapp.macos.mtl.layer.framebufferOnly = true; + //NOTE: default is 3: _sapp.macos.mtl.layer.maximumDrawableCount = 2; + // FIXME: _sapp.macos.mtl.layer.colorspace = ...; + _sapp.macos.view = [[_sapp_macos_view alloc] init]; + [_sapp.macos.view updateTrackingAreas]; + _sapp.macos.view.wantsLayer = YES; + _sapp.macos.view.layer = _sapp.macos.mtl.layer; + _sapp_macos_mtl_start_display_link(); + _sapp_macos_mtl_timing_init(); +} + +_SOKOL_PRIVATE void _sapp_macos_mtl_discard_state(void) { + _sapp_macos_mtl_stop_display_link(); + _sapp_macos_mtl_stop_fallback_timer(); + _sapp_macos_mtl_swapchain_destroy(); + _SAPP_OBJC_RELEASE(_sapp.macos.mtl.layer); + _SAPP_OBJC_RELEASE(_sapp.macos.mtl.device); +} + +_SOKOL_PRIVATE bool _sapp_macos_mtl_update_framebuffer_dimensions(NSRect view_bounds) { + _sapp.framebuffer_width = _sapp_roundf_gzero(view_bounds.size.width * _sapp.dpi_scale); + _sapp.framebuffer_height = _sapp_roundf_gzero(view_bounds.size.height * _sapp.dpi_scale); + const CGSize cur_fb_size = _sapp.macos.mtl.layer.drawableSize; + int cur_fb_width = _sapp_roundf_gzero(cur_fb_size.width); + int cur_fb_height = _sapp_roundf_gzero(cur_fb_size.height); + bool dim_changed = (_sapp.framebuffer_width != cur_fb_width) || (_sapp.framebuffer_height != cur_fb_height); + if (dim_changed) { + const CGSize drawable_size = { (CGFloat) _sapp.framebuffer_width, (CGFloat) _sapp.framebuffer_height }; + _sapp.macos.mtl.layer.drawableSize = drawable_size; + _sapp_macos_mtl_swapchain_resize(_sapp.framebuffer_width, _sapp.framebuffer_height); + } + return dim_changed; +} +#endif + +#if defined(SOKOL_WGPU) +_SOKOL_PRIVATE void _sapp_macos_wgpu_init(void) { + NSInteger max_fps = _sapp_macos_max_fps(); + _sapp.macos.wgpu.mtl_layer = [CAMetalLayer layer]; + _sapp.macos.wgpu.mtl_layer.magnificationFilter = kCAFilterNearest; + _sapp.macos.wgpu.mtl_layer.opaque = true; + // NOTE: might experiment with this, valid values are 2 or 3 (default: 3), I don't see any difference tbh + // _sapp.macos.wgpu.mtl_layer.maximumDrawableCount = 2; + _sapp.macos.view = [[_sapp_macos_view alloc] init]; + [_sapp.macos.view updateTrackingAreas]; + _sapp.macos.view.wantsLayer = YES; + _sapp.macos.view.layer = _sapp.macos.wgpu.mtl_layer; + _sapp.macos.wgpu.display_link = [_sapp.macos.view displayLinkWithTarget:_sapp.macos.view selector:@selector(displayLinkFired:)]; + float preferred_fps = max_fps / _sapp.swap_interval; + CAFrameRateRange frame_rate_range = { preferred_fps, preferred_fps, preferred_fps }; + _sapp.macos.wgpu.display_link.preferredFrameRateRange = frame_rate_range; + [_sapp.macos.wgpu.display_link addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes]; + _sapp_wgpu_init(); +} + +_SOKOL_PRIVATE void _sapp_macos_wgpu_discard_state(void) { + _SAPP_OBJC_RELEASE(_sapp.macos.wgpu.display_link); + _SAPP_OBJC_RELEASE(_sapp.macos.wgpu.mtl_layer); + _sapp_wgpu_discard(); +} + +_SOKOL_PRIVATE bool _sapp_macos_wgpu_update_framebuffer_dimensions(NSRect view_bounds) { + _sapp.framebuffer_width = _sapp_roundf_gzero(view_bounds.size.width * _sapp.dpi_scale); + _sapp.framebuffer_height = _sapp_roundf_gzero(view_bounds.size.height * _sapp.dpi_scale); + const CGSize cur_fb_size = _sapp.macos.wgpu.mtl_layer.drawableSize; + int cur_fb_width = _sapp_roundf_gzero(cur_fb_size.width); + int cur_fb_height = _sapp_roundf_gzero(cur_fb_size.height); + bool dim_changed = (_sapp.framebuffer_width != cur_fb_width) || (_sapp.framebuffer_height != cur_fb_height); + if (dim_changed) { + const CGSize drawable_size = { (CGFloat) _sapp.framebuffer_width, (CGFloat) _sapp.framebuffer_height }; + _sapp.macos.wgpu.mtl_layer.drawableSize = drawable_size; + _sapp_wgpu_swapchain_size_changed(); + } + return dim_changed; +} +#endif + +#if defined(SOKOL_GLCORE) +_SOKOL_PRIVATE void _sapp_macos_gl_init(NSRect window_rect) { + NSOpenGLPixelFormatAttribute attrs[32]; + int i = 0; + attrs[i++] = NSOpenGLPFAAccelerated; + attrs[i++] = NSOpenGLPFADoubleBuffer; + attrs[i++] = NSOpenGLPFAOpenGLProfile; + const int glVersion = _sapp.desc.gl.major_version * 10 + _sapp.desc.gl.minor_version; + switch(glVersion) { + case 10: attrs[i++] = NSOpenGLProfileVersionLegacy; break; + case 32: attrs[i++] = NSOpenGLProfileVersion3_2Core; break; + case 41: attrs[i++] = NSOpenGLProfileVersion4_1Core; break; + default: + _SAPP_PANIC(MACOS_INVALID_NSOPENGL_PROFILE); + } + attrs[i++] = NSOpenGLPFAColorSize; attrs[i++] = 24; + attrs[i++] = NSOpenGLPFAAlphaSize; attrs[i++] = 8; + attrs[i++] = NSOpenGLPFADepthSize; attrs[i++] = 24; + attrs[i++] = NSOpenGLPFAStencilSize; attrs[i++] = 8; + if (_sapp.sample_count > 1) { + attrs[i++] = NSOpenGLPFAMultisample; + attrs[i++] = NSOpenGLPFASampleBuffers; attrs[i++] = 1; + attrs[i++] = NSOpenGLPFASamples; attrs[i++] = (NSOpenGLPixelFormatAttribute)_sapp.sample_count; + } else { + attrs[i++] = NSOpenGLPFASampleBuffers; attrs[i++] = 0; + } + attrs[i++] = 0; + NSOpenGLPixelFormat* glpixelformat_obj = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs]; + SOKOL_ASSERT(glpixelformat_obj != nil); + + _sapp.macos.view = [[_sapp_macos_view alloc] + initWithFrame:window_rect + pixelFormat:glpixelformat_obj]; + _SAPP_OBJC_RELEASE(glpixelformat_obj); + [_sapp.macos.view updateTrackingAreas]; + if (_sapp.desc.high_dpi) { + [_sapp.macos.view setWantsBestResolutionOpenGLSurface:YES]; + } else { + [_sapp.macos.view setWantsBestResolutionOpenGLSurface:NO]; + } + + NSTimer* timer_obj = [NSTimer timerWithTimeInterval:0.001 + target:_sapp.macos.view + selector:@selector(timerFired:) + userInfo:nil + repeats:YES]; + [[NSRunLoop currentRunLoop] addTimer:timer_obj forMode:NSDefaultRunLoopMode]; + timer_obj = nil; +} + +_SOKOL_PRIVATE void _sapp_macos_gl_discard_state(void) { + // nothing to do here +} + +_SOKOL_PRIVATE bool _sapp_macos_gl_update_framebuffer_dimensions(NSRect view_bounds) { + const int cur_fb_width = _sapp_roundf_gzero(view_bounds.size.width * _sapp.dpi_scale); + const int cur_fb_height = _sapp_roundf_gzero(view_bounds.size.height * _sapp.dpi_scale); + const bool dim_changed = (_sapp.framebuffer_width != cur_fb_width) || (_sapp.framebuffer_height != cur_fb_height); + _sapp.framebuffer_width = cur_fb_width; + _sapp.framebuffer_height = cur_fb_height; + return dim_changed; +} +#endif + +_SOKOL_PRIVATE void _sapp_macos_init_keytable(void) { + _sapp.keycodes[0x1D] = SAPP_KEYCODE_0; + _sapp.keycodes[0x12] = SAPP_KEYCODE_1; + _sapp.keycodes[0x13] = SAPP_KEYCODE_2; + _sapp.keycodes[0x14] = SAPP_KEYCODE_3; + _sapp.keycodes[0x15] = SAPP_KEYCODE_4; + _sapp.keycodes[0x17] = SAPP_KEYCODE_5; + _sapp.keycodes[0x16] = SAPP_KEYCODE_6; + _sapp.keycodes[0x1A] = SAPP_KEYCODE_7; + _sapp.keycodes[0x1C] = SAPP_KEYCODE_8; + _sapp.keycodes[0x19] = SAPP_KEYCODE_9; + _sapp.keycodes[0x00] = SAPP_KEYCODE_A; + _sapp.keycodes[0x0B] = SAPP_KEYCODE_B; + _sapp.keycodes[0x08] = SAPP_KEYCODE_C; + _sapp.keycodes[0x02] = SAPP_KEYCODE_D; + _sapp.keycodes[0x0E] = SAPP_KEYCODE_E; + _sapp.keycodes[0x03] = SAPP_KEYCODE_F; + _sapp.keycodes[0x05] = SAPP_KEYCODE_G; + _sapp.keycodes[0x04] = SAPP_KEYCODE_H; + _sapp.keycodes[0x22] = SAPP_KEYCODE_I; + _sapp.keycodes[0x26] = SAPP_KEYCODE_J; + _sapp.keycodes[0x28] = SAPP_KEYCODE_K; + _sapp.keycodes[0x25] = SAPP_KEYCODE_L; + _sapp.keycodes[0x2E] = SAPP_KEYCODE_M; + _sapp.keycodes[0x2D] = SAPP_KEYCODE_N; + _sapp.keycodes[0x1F] = SAPP_KEYCODE_O; + _sapp.keycodes[0x23] = SAPP_KEYCODE_P; + _sapp.keycodes[0x0C] = SAPP_KEYCODE_Q; + _sapp.keycodes[0x0F] = SAPP_KEYCODE_R; + _sapp.keycodes[0x01] = SAPP_KEYCODE_S; + _sapp.keycodes[0x11] = SAPP_KEYCODE_T; + _sapp.keycodes[0x20] = SAPP_KEYCODE_U; + _sapp.keycodes[0x09] = SAPP_KEYCODE_V; + _sapp.keycodes[0x0D] = SAPP_KEYCODE_W; + _sapp.keycodes[0x07] = SAPP_KEYCODE_X; + _sapp.keycodes[0x10] = SAPP_KEYCODE_Y; + _sapp.keycodes[0x06] = SAPP_KEYCODE_Z; + _sapp.keycodes[0x27] = SAPP_KEYCODE_APOSTROPHE; + _sapp.keycodes[0x2A] = SAPP_KEYCODE_BACKSLASH; + _sapp.keycodes[0x2B] = SAPP_KEYCODE_COMMA; + _sapp.keycodes[0x18] = SAPP_KEYCODE_EQUAL; + _sapp.keycodes[0x32] = SAPP_KEYCODE_GRAVE_ACCENT; + _sapp.keycodes[0x21] = SAPP_KEYCODE_LEFT_BRACKET; + _sapp.keycodes[0x1B] = SAPP_KEYCODE_MINUS; + _sapp.keycodes[0x2F] = SAPP_KEYCODE_PERIOD; + _sapp.keycodes[0x1E] = SAPP_KEYCODE_RIGHT_BRACKET; + _sapp.keycodes[0x29] = SAPP_KEYCODE_SEMICOLON; + _sapp.keycodes[0x2C] = SAPP_KEYCODE_SLASH; + _sapp.keycodes[0x0A] = SAPP_KEYCODE_WORLD_1; + _sapp.keycodes[0x33] = SAPP_KEYCODE_BACKSPACE; + _sapp.keycodes[0x39] = SAPP_KEYCODE_CAPS_LOCK; + _sapp.keycodes[0x75] = SAPP_KEYCODE_DELETE; + _sapp.keycodes[0x7D] = SAPP_KEYCODE_DOWN; + _sapp.keycodes[0x77] = SAPP_KEYCODE_END; + _sapp.keycodes[0x24] = SAPP_KEYCODE_ENTER; + _sapp.keycodes[0x35] = SAPP_KEYCODE_ESCAPE; + _sapp.keycodes[0x7A] = SAPP_KEYCODE_F1; + _sapp.keycodes[0x78] = SAPP_KEYCODE_F2; + _sapp.keycodes[0x63] = SAPP_KEYCODE_F3; + _sapp.keycodes[0x76] = SAPP_KEYCODE_F4; + _sapp.keycodes[0x60] = SAPP_KEYCODE_F5; + _sapp.keycodes[0x61] = SAPP_KEYCODE_F6; + _sapp.keycodes[0x62] = SAPP_KEYCODE_F7; + _sapp.keycodes[0x64] = SAPP_KEYCODE_F8; + _sapp.keycodes[0x65] = SAPP_KEYCODE_F9; + _sapp.keycodes[0x6D] = SAPP_KEYCODE_F10; + _sapp.keycodes[0x67] = SAPP_KEYCODE_F11; + _sapp.keycodes[0x6F] = SAPP_KEYCODE_F12; + _sapp.keycodes[0x69] = SAPP_KEYCODE_F13; + _sapp.keycodes[0x6B] = SAPP_KEYCODE_F14; + _sapp.keycodes[0x71] = SAPP_KEYCODE_F15; + _sapp.keycodes[0x6A] = SAPP_KEYCODE_F16; + _sapp.keycodes[0x40] = SAPP_KEYCODE_F17; + _sapp.keycodes[0x4F] = SAPP_KEYCODE_F18; + _sapp.keycodes[0x50] = SAPP_KEYCODE_F19; + _sapp.keycodes[0x5A] = SAPP_KEYCODE_F20; + _sapp.keycodes[0x73] = SAPP_KEYCODE_HOME; + _sapp.keycodes[0x72] = SAPP_KEYCODE_INSERT; + _sapp.keycodes[0x7B] = SAPP_KEYCODE_LEFT; + _sapp.keycodes[0x3A] = SAPP_KEYCODE_LEFT_ALT; + _sapp.keycodes[0x3B] = SAPP_KEYCODE_LEFT_CONTROL; + _sapp.keycodes[0x38] = SAPP_KEYCODE_LEFT_SHIFT; + _sapp.keycodes[0x37] = SAPP_KEYCODE_LEFT_SUPER; + _sapp.keycodes[0x6E] = SAPP_KEYCODE_MENU; + _sapp.keycodes[0x47] = SAPP_KEYCODE_NUM_LOCK; + _sapp.keycodes[0x79] = SAPP_KEYCODE_PAGE_DOWN; + _sapp.keycodes[0x74] = SAPP_KEYCODE_PAGE_UP; + _sapp.keycodes[0x7C] = SAPP_KEYCODE_RIGHT; + _sapp.keycodes[0x3D] = SAPP_KEYCODE_RIGHT_ALT; + _sapp.keycodes[0x3E] = SAPP_KEYCODE_RIGHT_CONTROL; + _sapp.keycodes[0x3C] = SAPP_KEYCODE_RIGHT_SHIFT; + _sapp.keycodes[0x36] = SAPP_KEYCODE_RIGHT_SUPER; + _sapp.keycodes[0x31] = SAPP_KEYCODE_SPACE; + _sapp.keycodes[0x30] = SAPP_KEYCODE_TAB; + _sapp.keycodes[0x7E] = SAPP_KEYCODE_UP; + _sapp.keycodes[0x52] = SAPP_KEYCODE_KP_0; + _sapp.keycodes[0x53] = SAPP_KEYCODE_KP_1; + _sapp.keycodes[0x54] = SAPP_KEYCODE_KP_2; + _sapp.keycodes[0x55] = SAPP_KEYCODE_KP_3; + _sapp.keycodes[0x56] = SAPP_KEYCODE_KP_4; + _sapp.keycodes[0x57] = SAPP_KEYCODE_KP_5; + _sapp.keycodes[0x58] = SAPP_KEYCODE_KP_6; + _sapp.keycodes[0x59] = SAPP_KEYCODE_KP_7; + _sapp.keycodes[0x5B] = SAPP_KEYCODE_KP_8; + _sapp.keycodes[0x5C] = SAPP_KEYCODE_KP_9; + _sapp.keycodes[0x45] = SAPP_KEYCODE_KP_ADD; + _sapp.keycodes[0x41] = SAPP_KEYCODE_KP_DECIMAL; + _sapp.keycodes[0x4B] = SAPP_KEYCODE_KP_DIVIDE; + _sapp.keycodes[0x4C] = SAPP_KEYCODE_KP_ENTER; + _sapp.keycodes[0x51] = SAPP_KEYCODE_KP_EQUAL; + _sapp.keycodes[0x43] = SAPP_KEYCODE_KP_MULTIPLY; + _sapp.keycodes[0x4E] = SAPP_KEYCODE_KP_SUBTRACT; +} + +_SOKOL_PRIVATE void _sapp_macos_discard_state(void) { + // NOTE: it's safe to call [release] on a nil object + if (_sapp.macos.keyup_monitor != nil) { + [NSEvent removeMonitor:_sapp.macos.keyup_monitor]; + // NOTE: removeMonitor also releases the object + _sapp.macos.keyup_monitor = nil; + } + _SAPP_OBJC_RELEASE(_sapp.macos.tracking_area); + _SAPP_OBJC_RELEASE(_sapp.macos.app_dlg); + _SAPP_OBJC_RELEASE(_sapp.macos.win_dlg); + _SAPP_OBJC_RELEASE(_sapp.macos.view); + #if defined(SOKOL_METAL) + _sapp_macos_mtl_discard_state(); + #elif defined(SOKOL_GLCORE) + _sapp_macos_gl_discard_state(); + #elif defined(SOKOL_WGPU) + _sapp_macos_wgpu_discard_state(); + #endif + _SAPP_OBJC_RELEASE(_sapp.macos.window); +} + +// undocumented methods for creating cursors (see GLFW 3.4 and imgui_impl_osx.mm) +@interface NSCursor() ++ (id)_windowResizeNorthWestSouthEastCursor; ++ (id)_windowResizeNorthEastSouthWestCursor; ++ (id)_windowResizeNorthSouthCursor; ++ (id)_windowResizeEastWestCursor; +@end + +_SOKOL_PRIVATE void _sapp_macos_init_cursors(void) { + for (size_t i = 0; i < _SAPP_MOUSECURSOR_NUM; i++) { + _sapp.macos.standard_cursors[i] = nil; + _sapp.macos.custom_cursors[i] = nil; + } + _sapp.macos.standard_cursors[SAPP_MOUSECURSOR_ARROW] = [NSCursor arrowCursor]; + _sapp.macos.standard_cursors[SAPP_MOUSECURSOR_IBEAM] = [NSCursor IBeamCursor]; + _sapp.macos.standard_cursors[SAPP_MOUSECURSOR_CROSSHAIR] = [NSCursor crosshairCursor]; + _sapp.macos.standard_cursors[SAPP_MOUSECURSOR_POINTING_HAND] = [NSCursor pointingHandCursor]; + _sapp.macos.standard_cursors[SAPP_MOUSECURSOR_RESIZE_EW] = [NSCursor respondsToSelector:@selector(_windowResizeEastWestCursor)] ? [NSCursor _windowResizeEastWestCursor] : [NSCursor resizeLeftRightCursor]; + _sapp.macos.standard_cursors[SAPP_MOUSECURSOR_RESIZE_NS] = [NSCursor respondsToSelector:@selector(_windowResizeNorthSouthCursor)] ? [NSCursor _windowResizeNorthSouthCursor] : [NSCursor resizeUpDownCursor]; + _sapp.macos.standard_cursors[SAPP_MOUSECURSOR_RESIZE_NWSE] = [NSCursor respondsToSelector:@selector(_windowResizeNorthWestSouthEastCursor)] ? [NSCursor _windowResizeNorthWestSouthEastCursor] : [NSCursor closedHandCursor]; + _sapp.macos.standard_cursors[SAPP_MOUSECURSOR_RESIZE_NESW] = [NSCursor respondsToSelector:@selector(_windowResizeNorthEastSouthWestCursor)] ? [NSCursor _windowResizeNorthEastSouthWestCursor] : [NSCursor closedHandCursor]; + _sapp.macos.standard_cursors[SAPP_MOUSECURSOR_RESIZE_ALL] = [NSCursor closedHandCursor]; + _sapp.macos.standard_cursors[SAPP_MOUSECURSOR_NOT_ALLOWED] = [NSCursor operationNotAllowedCursor]; +} + +_SOKOL_PRIVATE void _sapp_macos_run(const sapp_desc* desc) { + _sapp_init_state(desc); + _sapp_macos_init_keytable(); + [NSApplication sharedApplication]; + + // set the application dock icon as early as possible, otherwise + // the dummy icon will be visible for a short time + sapp_set_icon(&_sapp.desc.icon); + _sapp.macos.app_dlg = [[_sapp_macos_app_delegate alloc] init]; + NSApp.delegate = _sapp.macos.app_dlg; + + // workaround for "no key-up sent while Cmd is pressed" taken from GLFW: + NSEvent* (^keyup_monitor)(NSEvent*) = ^NSEvent* (NSEvent* event) { + if ([event modifierFlags] & NSEventModifierFlagCommand) { + [[NSApp keyWindow] sendEvent:event]; + } + return event; + }; + _sapp.macos.keyup_monitor = [NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskKeyUp handler:keyup_monitor]; + + [NSApp run]; + // NOTE: [NSApp run] never returns, instead cleanup code + // must be put into applicationWillTerminate +} + +/* MacOS entry function */ +#if !defined(SOKOL_NO_ENTRY) +int main(int argc, char* argv[]) { + sapp_desc desc = sokol_main(argc, argv); + _sapp_macos_run(&desc); + return 0; +} +#endif /* SOKOL_NO_ENTRY */ + +_SOKOL_PRIVATE uint32_t _sapp_macos_mods(NSEvent* ev) { + const NSEventModifierFlags f = (ev == nil) ? NSEvent.modifierFlags : ev.modifierFlags; + const NSUInteger b = NSEvent.pressedMouseButtons; + uint32_t m = 0; + if (f & NSEventModifierFlagShift) { + m |= SAPP_MODIFIER_SHIFT; + } + if (f & NSEventModifierFlagControl) { + m |= SAPP_MODIFIER_CTRL; + } + if (f & NSEventModifierFlagOption) { + m |= SAPP_MODIFIER_ALT; + } + if (f & NSEventModifierFlagCommand) { + m |= SAPP_MODIFIER_SUPER; + } + if (0 != (b & (1<<0))) { + m |= SAPP_MODIFIER_LMB; + } + if (0 != (b & (1<<1))) { + m |= SAPP_MODIFIER_RMB; + } + if (0 != (b & (1<<2))) { + m |= SAPP_MODIFIER_MMB; + } + return m; +} + +_SOKOL_PRIVATE void _sapp_macos_mouse_event(sapp_event_type type, sapp_mousebutton btn, uint32_t mod) { + if (_sapp_events_enabled()) { + _sapp_init_event(type); + _sapp.event.mouse_button = btn; + _sapp.event.modifiers = mod; + _sapp_call_event(&_sapp.event); + } +} + +_SOKOL_PRIVATE void _sapp_macos_key_event(sapp_event_type type, sapp_keycode key, bool repeat, uint32_t mod) { + if (_sapp_events_enabled()) { + _sapp_init_event(type); + _sapp.event.key_code = key; + _sapp.event.key_repeat = repeat; + _sapp.event.modifiers = mod; + _sapp_call_event(&_sapp.event); + } +} + +_SOKOL_PRIVATE void _sapp_macos_app_event(sapp_event_type type) { + if (_sapp_events_enabled()) { + _sapp_init_event(type); + _sapp_call_event(&_sapp.event); + } +} + +// called in applicationDidFinishedLaunching when no window size was provided +_SOKOL_PRIVATE void _sapp_macos_init_default_dimensions(void) { + if (_sapp.desc.high_dpi) { + _sapp.dpi_scale = NSScreen.mainScreen.backingScaleFactor; + } else { + _sapp.dpi_scale = 1.0f; + } + NSRect screen_rect = NSScreen.mainScreen.frame; + // use 4/5 of screen size as default size + const float default_widthf = (screen_rect.size.width * 4.0f) / 5.0f; + const float default_heightf = (screen_rect.size.height * 4.0f) / 5.0f; + if (_sapp.window_width == 0) { + _sapp.window_width = _sapp_roundf_gzero(default_widthf); + } + if (_sapp.window_height == 0) { + _sapp.window_height = _sapp_roundf_gzero(default_heightf); + } + _sapp.framebuffer_width = _sapp_roundf_gzero(default_widthf * _sapp.dpi_scale); + _sapp.framebuffer_height = _sapp_roundf_gzero(default_heightf * _sapp.dpi_scale); +} + +/* NOTE: unlike the iOS version of this function, the macOS version + can dynamically update the DPI scaling factor when a window is moved + between HighDPI / LowDPI screens. +*/ +_SOKOL_PRIVATE void _sapp_macos_update_dimensions(void) { + if (_sapp.desc.high_dpi) { + _sapp.dpi_scale = [_sapp.macos.window screen].backingScaleFactor; + } else { + _sapp.dpi_scale = 1.0f; + } + // NOTE: needed because we set layerContentsPlacement to a non-scaling value in windowWillStartLiveResize. + _sapp.macos.view.layer.contentsScale = _sapp.dpi_scale; + const NSRect bounds = [_sapp.macos.view bounds]; + _sapp.window_width = _sapp_roundf_gzero(bounds.size.width); + _sapp.window_height = _sapp_roundf_gzero(bounds.size.height); + #if defined(SOKOL_METAL) + bool dim_changed = _sapp_macos_mtl_update_framebuffer_dimensions(bounds); + #elif defined(SOKOL_GLCORE) + bool dim_changed = _sapp_macos_gl_update_framebuffer_dimensions(bounds); + #elif defined(SOKOL_WGPU) + bool dim_changed = _sapp_macos_wgpu_update_framebuffer_dimensions(bounds); + #endif + if (dim_changed && !_sapp.first_frame) { + _sapp_macos_app_event(SAPP_EVENTTYPE_RESIZED); + } +} + +_SOKOL_PRIVATE void _sapp_macos_toggle_fullscreen(void) { + /* NOTE: the _sapp.fullscreen flag is also notified by the + windowDidEnterFullscreen / windowDidExitFullscreen + event handlers + */ + _sapp.fullscreen = !_sapp.fullscreen; + [_sapp.macos.window toggleFullScreen:nil]; +} + +_SOKOL_PRIVATE void _sapp_macos_set_clipboard_string(const char* str) { + @autoreleasepool { + NSPasteboard* pasteboard = [NSPasteboard generalPasteboard]; + [pasteboard declareTypes:@[NSPasteboardTypeString] owner:nil]; + [pasteboard setString:@(str) forType:NSPasteboardTypeString]; + } +} + +_SOKOL_PRIVATE const char* _sapp_macos_get_clipboard_string(void) { + SOKOL_ASSERT(_sapp.clipboard.buffer); + @autoreleasepool { + _sapp.clipboard.buffer[0] = 0; + NSPasteboard* pasteboard = [NSPasteboard generalPasteboard]; + if (![[pasteboard types] containsObject:NSPasteboardTypeString]) { + return _sapp.clipboard.buffer; + } + NSString* str = [pasteboard stringForType:NSPasteboardTypeString]; + if (!str) { + return _sapp.clipboard.buffer; + } + _sapp_strcpy([str UTF8String], _sapp.clipboard.buffer, (size_t)_sapp.clipboard.buf_size); + } + return _sapp.clipboard.buffer; +} + +_SOKOL_PRIVATE void _sapp_macos_update_window_title(void) { + [_sapp.macos.window setTitle: [NSString stringWithUTF8String:_sapp.window_title]]; +} + +_SOKOL_PRIVATE void _sapp_macos_mouse_update_from_nspoint(NSPoint mouse_pos, bool clear_dxdy) { + if (!_sapp.mouse.locked) { + float new_x = mouse_pos.x * _sapp.dpi_scale; + float new_y = _sapp.framebuffer_height - (mouse_pos.y * _sapp.dpi_scale) - 1; + if (clear_dxdy) { + _sapp.mouse.dx = 0.0f; + _sapp.mouse.dy = 0.0f; + } else if (_sapp.mouse.pos_valid) { + // don't update dx/dy in the very first update + _sapp.mouse.dx = new_x - _sapp.mouse.x; + _sapp.mouse.dy = new_y - _sapp.mouse.y; + } + _sapp.mouse.x = new_x; + _sapp.mouse.y = new_y; + _sapp.mouse.pos_valid = true; + } +} + +_SOKOL_PRIVATE void _sapp_macos_mouse_update_from_nsevent(NSEvent* event, bool clear_dxdy) { + _sapp_macos_mouse_update_from_nspoint(event.locationInWindow, clear_dxdy); +} + +_SOKOL_PRIVATE void _sapp_macos_show_mouse(bool visible) { + /* NOTE: this function is only called when the mouse visibility actually changes */ + if (visible) { + CGDisplayShowCursor(kCGDirectMainDisplay); + } else { + CGDisplayHideCursor(kCGDirectMainDisplay); + } +} + +_SOKOL_PRIVATE void _sapp_macos_lock_mouse(bool lock) { + if (lock == _sapp.mouse.locked) { + return; + } + _sapp.mouse.dx = 0.0f; + _sapp.mouse.dy = 0.0f; + _sapp.mouse.locked = lock; + /* + NOTE that this code doesn't warp the mouse cursor to the window + center as everybody else does it. This lead to a spike in the + *second* mouse-moved event after the warp happened. The + mouse centering doesn't seem to be required (mouse-moved events + are reported correctly even when the cursor is at an edge of the screen). + + NOTE also that the hide/show of the mouse cursor should properly + stack with calls to sapp_show_mouse() + */ + if (_sapp.mouse.locked) { + CGAssociateMouseAndMouseCursorPosition(NO); + [NSCursor hide]; + } else { + [NSCursor unhide]; + CGAssociateMouseAndMouseCursorPosition(YES); + } +} + +_SOKOL_PRIVATE void _sapp_macos_update_cursor(sapp_mouse_cursor cursor, bool shown) { + // show/hide cursor only if visibility status has changed (required because show/hide stacks) + if (shown != _sapp.mouse.shown) { + if (shown) { + [NSCursor unhide]; + } else { + [NSCursor hide]; + } + } + + // update cursor + SOKOL_ASSERT((cursor >= 0) && (cursor < _SAPP_MOUSECURSOR_NUM)); + NSCursor* ns_cursor = 0; + if (_sapp.custom_cursor_bound[cursor]) { + SOKOL_ASSERT(_sapp.macos.custom_cursors[cursor]); + ns_cursor = _sapp.macos.custom_cursors[cursor]; + } else if (_sapp.macos.standard_cursors[cursor]) { + ns_cursor = _sapp.macos.standard_cursors[cursor]; + } else { + ns_cursor = [NSCursor arrowCursor]; + } + [ns_cursor set]; +} + +_SOKOL_PRIVATE bool _sapp_macos_make_custom_mouse_cursor(sapp_mouse_cursor cursor, const sapp_image_desc* desc) { + SOKOL_ASSERT((cursor >= 0) && (cursor < _SAPP_MOUSECURSOR_NUM)); + SOKOL_ASSERT(_sapp.macos.custom_cursors[cursor] == nil); + + // NOTE: see glfw for reference https://github.com/glfw/glfw/blob/ac10768495837eb98da27d01fe706073d6d251c2/src/cocoa_window.m#L1712 + NSBitmapImageRep* rep = [[NSBitmapImageRep alloc] + initWithBitmapDataPlanes:NULL + pixelsWide:desc->width + pixelsHigh:desc->height + bitsPerSample:8 + samplesPerPixel:4 + hasAlpha:YES + isPlanar:NO + colorSpaceName:NSCalibratedRGBColorSpace + bitmapFormat:NSBitmapFormatAlphaNonpremultiplied + bytesPerRow:desc->width * 4 + bitsPerPixel:32]; + if (rep != nil) { + memcpy([rep bitmapData], desc->pixels.ptr, (size_t) (desc->width * desc->height * 4)); + + NSImage* native = [[NSImage alloc] initWithSize:NSMakeSize(desc->width, desc->height)]; + SOKOL_ASSERT(native); + [native addRepresentation:rep]; + + _sapp.macos.custom_cursors[cursor] = [[NSCursor alloc] + initWithImage:native + hotSpot:NSMakePoint(desc->cursor_hotspot_x, desc->cursor_hotspot_y)]; + SOKOL_ASSERT(_sapp.macos.custom_cursors[cursor] != nil); + + _SAPP_OBJC_RELEASE(native); + _SAPP_OBJC_RELEASE(rep); + return true; + } + return false; +} + +_SOKOL_PRIVATE void _sapp_macos_destroy_custom_mouse_cursor(sapp_mouse_cursor cursor) { + SOKOL_ASSERT((cursor >= 0) && (cursor < _SAPP_MOUSECURSOR_NUM)); + SOKOL_ASSERT(_sapp.macos.custom_cursors[cursor] != nil); + _SAPP_OBJC_RELEASE(_sapp.macos.custom_cursors[cursor]); +} + +_SOKOL_PRIVATE void _sapp_macos_set_icon(const sapp_icon_desc* icon_desc, int num_images) { + NSDockTile* dock_tile = NSApp.dockTile; + const int wanted_width = (int) dock_tile.size.width; + const int wanted_height = (int) dock_tile.size.height; + const int img_index = _sapp_image_bestmatch(icon_desc->images, num_images, wanted_width, wanted_height); + const sapp_image_desc* img_desc = &icon_desc->images[img_index]; + + CGColorSpaceRef cg_color_space = CGColorSpaceCreateDeviceRGB(); + CFDataRef cf_data = CFDataCreate(kCFAllocatorDefault, (const UInt8*)img_desc->pixels.ptr, (CFIndex)img_desc->pixels.size); + CGDataProviderRef cg_data_provider = CGDataProviderCreateWithCFData(cf_data); + CGImageRef cg_img = CGImageCreate( + (size_t)img_desc->width, // width + (size_t)img_desc->height, // height + 8, // bitsPerComponent + 32, // bitsPerPixel + (size_t)img_desc->width * 4,// bytesPerRow + cg_color_space, // space + kCGImageAlphaLast | kCGImageByteOrderDefault, // bitmapInfo + cg_data_provider, // provider + NULL, // decode + false, // shouldInterpolate + kCGRenderingIntentDefault); + CFRelease(cf_data); + CGDataProviderRelease(cg_data_provider); + CGColorSpaceRelease(cg_color_space); + + NSImage* ns_image = [[NSImage alloc] initWithCGImage:cg_img size:dock_tile.size]; + dock_tile.contentView = [NSImageView imageViewWithImage:ns_image]; + [dock_tile display]; + _SAPP_OBJC_RELEASE(ns_image); + CGImageRelease(cg_img); +} + +_SOKOL_PRIVATE void _sapp_macos_frame(void) { + _sapp_timing_update(&_sapp.timing, 0.0); + #if defined(SOKOL_METAL) + _sapp_macos_mtl_timing_update(); + #endif + #if defined(_SAPP_ANY_GL) + glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint*)&_sapp.gl.framebuffer); + #endif + @autoreleasepool { + #if defined(SOKOL_WGPU) + _sapp_wgpu_frame(); + #else + _sapp_frame(); + #endif + } + #if defined(_SAPP_ANY_GL) + [[_sapp.macos.view openGLContext] flushBuffer]; + #endif + if (_sapp.quit_requested || _sapp.quit_ordered) { + [_sapp.macos.window performClose:nil]; + } +} + +@implementation _sapp_macos_app_delegate +- (void)applicationDidFinishLaunching:(NSNotification*)aNotification { + _SOKOL_UNUSED(aNotification); + // NOTE: keep activationPolicy in front of window creation (see https://github.com/floooh/sokol/issues/1500) + NSApp.activationPolicy = NSApplicationActivationPolicyRegular; + _sapp_macos_init_cursors(); + if ((_sapp.window_width == 0) || (_sapp.window_height == 0)) { + _sapp_macos_init_default_dimensions(); + } + const NSUInteger style = + NSWindowStyleMaskTitled | + NSWindowStyleMaskClosable | + NSWindowStyleMaskMiniaturizable | + NSWindowStyleMaskResizable; + NSRect window_rect = NSMakeRect(0, 0, _sapp.window_width, _sapp.window_height); + _sapp.macos.window = [[_sapp_macos_window alloc] + initWithContentRect:window_rect + styleMask:style + backing:NSBackingStoreBuffered + defer:NO]; + _sapp.macos.window.releasedWhenClosed = NO; // this is necessary for proper cleanup in applicationWillTerminate + _sapp.macos.window.title = [NSString stringWithUTF8String:_sapp.window_title]; + _sapp.macos.window.acceptsMouseMovedEvents = YES; + _sapp.macos.window.restorable = YES; + + _sapp.macos.win_dlg = [[_sapp_macos_window_delegate alloc] init]; + _sapp.macos.window.delegate = _sapp.macos.win_dlg; + #if defined(SOKOL_METAL) + _sapp_macos_mtl_init(); + #elif defined(SOKOL_GLCORE) + _sapp_macos_gl_init(window_rect); + #elif defined(SOKOL_WGPU) + _sapp_macos_wgpu_init(); + #endif + _sapp.macos.window.contentView = _sapp.macos.view; + [_sapp.macos.window makeFirstResponder:_sapp.macos.view]; + [_sapp.macos.window center]; + _sapp.valid = true; + if (_sapp.fullscreen) { + /* ^^^ on GL, this already toggles a rendered frame, so set the valid flag before */ + [_sapp.macos.window toggleFullScreen:self]; + } + [NSApp activateIgnoringOtherApps:YES]; + [_sapp.macos.window makeKeyAndOrderFront:nil]; + _sapp_macos_update_dimensions(); + [NSEvent setMouseCoalescingEnabled:NO]; + + // workaround for window not being focused during a long init callback + // for details see: https://github.com/floooh/sokol/pull/982 + // also see: https://gitlab.gnome.org/GNOME/gtk/-/issues/2342 + NSEvent *focusevent = [NSEvent otherEventWithType:NSEventTypeAppKitDefined + location:NSZeroPoint + modifierFlags:0x40 + timestamp:0 + windowNumber:0 + context:nil + subtype:NSEventSubtypeApplicationActivated + data1:0 + data2:0]; + [NSApp postEvent:focusevent atStart:YES]; +} + +- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)sender { + _SOKOL_UNUSED(sender); + return YES; +} + +- (void)applicationWillTerminate:(NSNotification*)notification { + _SOKOL_UNUSED(notification); + _sapp_call_cleanup(); + _sapp_macos_discard_state(); + _sapp_discard_state(); +} +@end + +@implementation _sapp_macos_window_delegate +- (BOOL)windowShouldClose:(id)sender { + _SOKOL_UNUSED(sender); + // only give user-code a chance to intervene when sapp_quit() wasn't already called + if (!_sapp.quit_ordered) { + // if window should be closed and event handling is enabled, give user code + // a chance to intervene via sapp_cancel_quit() + _sapp.quit_requested = true; + _sapp_macos_app_event(SAPP_EVENTTYPE_QUIT_REQUESTED); + /* user code hasn't intervened, quit the app */ + if (_sapp.quit_requested) { + _sapp.quit_ordered = true; + } + } + if (_sapp.quit_ordered) { + return YES; + } else { + return NO; + } +} + +- (void)windowWillStartLiveResize:(NSNotification *)notification { + #if defined(SOKOL_METAL) || defined(SOKOL_WGPU) + // Work around the MTKView/CAMetalLayer resizing glitch by "anchoring" the layer to the window corner opposite + // to the currently manipulated corner (or edge). This prevents the content stretching back and + // forth during resizing. This is a workaround for this issue: https://github.com/floooh/sokol/issues/700 + // Can be removed if/when migrating to CAMetalLayer: https://github.com/floooh/sokol/issues/727 + bool resizing_from_left = _sapp.mouse.x < _sapp.window_width/2; + bool resizing_from_top = _sapp.mouse.y < _sapp.window_height/2; + NSViewLayerContentsPlacement placement; + if (resizing_from_left) { + placement = resizing_from_top ? NSViewLayerContentsPlacementBottomRight : NSViewLayerContentsPlacementTopRight; + } else { + placement = resizing_from_top ? NSViewLayerContentsPlacementBottomLeft : NSViewLayerContentsPlacementTopLeft; + } + _sapp.macos.view.layerContentsPlacement = placement; + #endif +} + +- (void)windowDidResize:(NSNotification*)notification { + _SOKOL_UNUSED(notification); + _sapp_macos_update_dimensions(); +} + +- (void)windowDidChangeScreen:(NSNotification*)notification { + _SOKOL_UNUSED(notification); + _sapp_macos_update_dimensions(); +} + +- (void)windowDidMiniaturize:(NSNotification*)notification { + _SOKOL_UNUSED(notification); + #if defined(SOKOL_METAL) + _sapp_macos_mtl_transition_to_occluded(); + #endif + _sapp_macos_app_event(SAPP_EVENTTYPE_ICONIFIED); +} + +- (void)windowDidDeminiaturize:(NSNotification*)notification { + _SOKOL_UNUSED(notification); + #if defined(SOKOL_METAL) + _sapp_macos_mtl_transition_to_visible(); + #endif + _sapp_macos_app_event(SAPP_EVENTTYPE_RESTORED); +} + +- (void)windowDidChangeOcclusionState:(NSNotification*)notification { + #if defined(SOKOL_METAL) + if (_sapp.macos.window.occlusionState & NSWindowOcclusionStateVisible) { + _sapp_macos_mtl_transition_to_visible(); + } else { + _sapp_macos_mtl_transition_to_occluded(); + } + #endif +} + +- (void)windowDidBecomeKey:(NSNotification*)notification { + _SOKOL_UNUSED(notification); + _sapp_macos_app_event(SAPP_EVENTTYPE_FOCUSED); +} + +- (void)windowDidResignKey:(NSNotification*)notification { + _SOKOL_UNUSED(notification); + _sapp_macos_app_event(SAPP_EVENTTYPE_UNFOCUSED); +} + +- (void)windowDidEnterFullScreen:(NSNotification*)notification { + _SOKOL_UNUSED(notification); + _sapp.fullscreen = true; +} + +- (void)windowDidExitFullScreen:(NSNotification*)notification { + _SOKOL_UNUSED(notification); + _sapp.fullscreen = false; +} +@end + +@implementation _sapp_macos_window +- (instancetype)initWithContentRect:(NSRect)contentRect + styleMask:(NSWindowStyleMask)style + backing:(NSBackingStoreType)backingStoreType + defer:(BOOL)flag { + if (self = [super initWithContentRect:contentRect styleMask:style backing:backingStoreType defer:flag]) { + #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101300 + [self registerForDraggedTypes:[NSArray arrayWithObject:NSPasteboardTypeFileURL]]; + #endif + } + return self; +} + +- (NSDragOperation)draggingEntered:(id)sender { + return NSDragOperationCopy; +} + +- (NSDragOperation)draggingUpdated:(id)sender { + return NSDragOperationCopy; +} + +- (BOOL)performDragOperation:(id)sender { + #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101300 + NSPasteboard *pboard = [sender draggingPasteboard]; + if ([pboard.types containsObject:NSPasteboardTypeFileURL]) { + _sapp_clear_drop_buffer(); + _sapp.drop.num_files = ((int)pboard.pasteboardItems.count > _sapp.drop.max_files) ? _sapp.drop.max_files : (int)pboard.pasteboardItems.count; + bool drop_failed = false; + for (int i = 0; i < _sapp.drop.num_files; i++) { + NSURL *fileUrl = [NSURL fileURLWithPath:[pboard.pasteboardItems[(NSUInteger)i] stringForType:NSPasteboardTypeFileURL]]; + if (!_sapp_strcpy(fileUrl.standardizedURL.path.UTF8String, _sapp_dropped_file_path_ptr(i), (size_t)_sapp.drop.max_path_length)) { + _SAPP_ERROR(DROPPED_FILE_PATH_TOO_LONG); + drop_failed = true; + break; + } + } + if (!drop_failed) { + if (_sapp_events_enabled()) { + _sapp_macos_mouse_update_from_nspoint(sender.draggingLocation, true); + _sapp_init_event(SAPP_EVENTTYPE_FILES_DROPPED); + _sapp.event.modifiers = _sapp_macos_mods(nil); + _sapp_call_event(&_sapp.event); + } + } else { + _sapp_clear_drop_buffer(); + _sapp.drop.num_files = 0; + } + return YES; + } + #endif + return NO; +} +@end + +@implementation _sapp_macos_view +#if defined(SOKOL_GLCORE) +- (void)timerFired:(id)sender { + _SOKOL_UNUSED(sender); + [self setNeedsDisplay:YES]; +} +- (void)prepareOpenGL { + [super prepareOpenGL]; + GLint swapInt = 1; + NSOpenGLContext* ctx = [_sapp.macos.view openGLContext]; + [ctx setValues:&swapInt forParameter:NSOpenGLContextParameterSwapInterval]; + [ctx makeCurrentContext]; +} +- (void)drawRect:(NSRect)rect { + _SOKOL_UNUSED(rect); + _sapp_macos_frame(); +} +#elif defined(SOKOL_METAL) || defined(SOKOL_WGPU) +- (void)displayLinkFired:(id)sender { + _SOKOL_UNUSED(sender); + _sapp_macos_frame(); +} +- (void)fallbackTimerFired:(NSTimer*)timer { + _SOKOL_UNUSED(timer); + _sapp_macos_frame(); +} +#endif + +- (BOOL)isOpaque { + return YES; +} +- (BOOL)canBecomeKeyView { + return YES; +} +- (BOOL)acceptsFirstResponder { + return YES; +} +- (void)updateTrackingAreas { + if (_sapp.macos.tracking_area != nil) { + [self removeTrackingArea:_sapp.macos.tracking_area]; + _SAPP_OBJC_RELEASE(_sapp.macos.tracking_area); + } + const NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited | + NSTrackingActiveInKeyWindow | + NSTrackingEnabledDuringMouseDrag | + NSTrackingCursorUpdate | + NSTrackingInVisibleRect | + NSTrackingAssumeInside; + _sapp.macos.tracking_area = [[NSTrackingArea alloc] initWithRect:[self bounds] options:options owner:self userInfo:nil]; + [self addTrackingArea:_sapp.macos.tracking_area]; + [super updateTrackingAreas]; +} + +// helper function to make GL context active +static void _sapp_gl_make_current(void) { + #if defined(SOKOL_GLCORE) + [[_sapp.macos.view openGLContext] makeCurrentContext]; + #endif +} + +- (void)mouseEntered:(NSEvent*)event { + _sapp_gl_make_current(); + _sapp_macos_mouse_update_from_nsevent(event, true); + /* don't send mouse enter/leave while dragging (so that it behaves the same as + on Windows while SetCapture is active + */ + if (0 == _sapp.macos.mouse_buttons) { + _sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_ENTER, SAPP_MOUSEBUTTON_INVALID, _sapp_macos_mods(event)); + } +} +- (void)mouseExited:(NSEvent*)event { + _sapp_gl_make_current(); + _sapp_macos_mouse_update_from_nsevent(event, true); + if (0 == _sapp.macos.mouse_buttons) { + _sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_LEAVE, SAPP_MOUSEBUTTON_INVALID, _sapp_macos_mods(event)); + } +} +- (void)mouseDown:(NSEvent*)event { + _sapp_gl_make_current(); + _sapp_macos_mouse_update_from_nsevent(event, false); + _sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_DOWN, SAPP_MOUSEBUTTON_LEFT, _sapp_macos_mods(event)); + _sapp.macos.mouse_buttons |= (1< 0.0f) || (_sapp_absf(dy) > 0.0f)) { + _sapp_init_event(SAPP_EVENTTYPE_MOUSE_SCROLL); + _sapp.event.modifiers = _sapp_macos_mods(event); + _sapp.event.scroll_x = dx; + _sapp.event.scroll_y = dy; + _sapp_call_event(&_sapp.event); + } + } +} +- (void)keyDown:(NSEvent*)event { + if (_sapp_events_enabled()) { + _sapp_gl_make_current(); + const uint32_t mods = _sapp_macos_mods(event); + const sapp_keycode key_code = _sapp_translate_key(event.keyCode); + _sapp_macos_key_event(SAPP_EVENTTYPE_KEY_DOWN, key_code, event.isARepeat, mods); + const NSString* chars = event.characters; + const NSUInteger len = chars.length; + if (len > 0) { + _sapp_init_event(SAPP_EVENTTYPE_CHAR); + _sapp.event.modifiers = mods; + for (NSUInteger i = 0; i < len; i++) { + const unichar codepoint = [chars characterAtIndex:i]; + if ((codepoint & 0xFF00) == 0xF700) { + continue; + } + _sapp.event.char_code = codepoint; + _sapp.event.key_repeat = event.isARepeat; + _sapp_call_event(&_sapp.event); + } + } + /* if this is a Cmd+V (paste), also send a CLIPBOARD_PASTE event */ + if (_sapp.clipboard.enabled && (mods == SAPP_MODIFIER_SUPER) && (key_code == SAPP_KEYCODE_V)) { + _sapp_init_event(SAPP_EVENTTYPE_CLIPBOARD_PASTED); + _sapp_call_event(&_sapp.event); + } + } +} + +- (BOOL)performKeyEquivalent:(NSEvent*)event { + // fixes Ctrl-Tab keydown not triggering a keyDown event + // + // NOTE: it seems that Ctrl-F1 cannot be intercepted the same way, but since + // this enabled critical accessibility features that's probably a good thing. + switch (_sapp_translate_key(event.keyCode)) { + case SAPP_KEYCODE_TAB: + [_sapp.macos.view keyDown:event]; + return YES; + default: + return NO; + } +} + +- (void)keyUp:(NSEvent*)event { + _sapp_gl_make_current(); + _sapp_macos_key_event(SAPP_EVENTTYPE_KEY_UP, + _sapp_translate_key(event.keyCode), + event.isARepeat, + _sapp_macos_mods(event)); +} + +- (void)flagsChanged:(NSEvent*)event { + const uint32_t old_f = _sapp.macos.flags_changed_store; + const uint32_t new_f = (uint32_t)event.modifierFlags; + _sapp.macos.flags_changed_store = new_f; + sapp_keycode key_code = SAPP_KEYCODE_INVALID; + bool down = false; + if ((new_f ^ old_f) & NSEventModifierFlagShift) { + key_code = SAPP_KEYCODE_LEFT_SHIFT; + down = 0 != (new_f & NSEventModifierFlagShift); + } + if ((new_f ^ old_f) & NSEventModifierFlagControl) { + key_code = SAPP_KEYCODE_LEFT_CONTROL; + down = 0 != (new_f & NSEventModifierFlagControl); + } + if ((new_f ^ old_f) & NSEventModifierFlagOption) { + key_code = SAPP_KEYCODE_LEFT_ALT; + down = 0 != (new_f & NSEventModifierFlagOption); + } + if ((new_f ^ old_f) & NSEventModifierFlagCommand) { + key_code = SAPP_KEYCODE_LEFT_SUPER; + down = 0 != (new_f & NSEventModifierFlagCommand); + } + if (key_code != SAPP_KEYCODE_INVALID) { + _sapp_macos_key_event(down ? SAPP_EVENTTYPE_KEY_DOWN : SAPP_EVENTTYPE_KEY_UP, + key_code, + false, + _sapp_macos_mods(event)); + } +} +- (void)cursorUpdate:(NSEvent *)event { + _sapp_macos_update_cursor(_sapp.mouse.current_cursor, _sapp.mouse.shown); +} +@end + +#endif // macOS + +// ██ ██████ ███████ +// ██ ██ ██ ██ +// ██ ██ ██ ███████ +// ██ ██ ██ ██ +// ██ ██████ ███████ +// +// >>ios +#if defined(_SAPP_IOS) + +_SOKOL_PRIVATE NSInteger _sapp_ios_max_fps(void) { + return _sapp.ios.window.windowScene.screen.maximumFramesPerSecond; +} + +#if defined(SOKOL_METAL) + +_SOKOL_PRIVATE id _sapp_ios_mtl_create_texture(int width, int height, MTLPixelFormat fmt, int sample_count, const char* label) { + MTLTextureDescriptor* mtl_desc = [[MTLTextureDescriptor alloc] init]; + if (sample_count > 1) { + mtl_desc.textureType = MTLTextureType2DMultisample; + } else { + mtl_desc.textureType = MTLTextureType2D; + } + mtl_desc.pixelFormat = fmt; + mtl_desc.width = (NSUInteger)width; + mtl_desc.height = (NSUInteger)height; + mtl_desc.depth = 1; + mtl_desc.mipmapLevelCount = 1; + mtl_desc.arrayLength = 1; + mtl_desc.sampleCount = (NSUInteger)sample_count; + mtl_desc.usage = MTLTextureUsageRenderTarget; + mtl_desc.resourceOptions = MTLResourceStorageModePrivate; + id mtl_tex = [_sapp.ios.mtl.device newTextureWithDescriptor:mtl_desc]; + _SAPP_OBJC_RELEASE(mtl_desc); + #if defined(SOKOL_DEBUG) + if (mtl_tex) { + mtl_tex.label = [NSString stringWithUTF8String:label]; + } + #else + _SOKOL_UNUSED(label); + #endif + return mtl_tex; +} + +_SOKOL_PRIVATE void _sapp_ios_mtl_swapchain_create(int width, int height) { + _sapp.ios.mtl.depth_tex =_sapp_ios_mtl_create_texture(width, height, MTLPixelFormatDepth32Float_Stencil8, _sapp.sample_count, "swapchain_depth_tex"); + if (nil == _sapp.ios.mtl.depth_tex) { + _SAPP_PANIC(METAL_CREATE_SWAPCHAIN_DEPTH_TEXTURE_FAILED); + } + if (_sapp.sample_count > 1) { + _sapp.ios.mtl.msaa_tex = _sapp_ios_mtl_create_texture(width, height, MTLPixelFormatBGRA8Unorm, _sapp.sample_count, "swapchain_msaa_tex"); + if (nil == _sapp.ios.mtl.msaa_tex) { + _SAPP_PANIC(METAL_CREATE_SWAPCHAIN_MSAA_TEXTURE_FAILED); + } + } +} + +_SOKOL_PRIVATE void _sapp_ios_mtl_swapchain_destroy(void) { + if (_sapp.ios.mtl.depth_tex) { + _SAPP_OBJC_RELEASE(_sapp.ios.mtl.depth_tex); + } + if (_sapp.ios.mtl.msaa_tex) { + _SAPP_OBJC_RELEASE(_sapp.ios.mtl.msaa_tex); + } +} + +_SOKOL_PRIVATE void _sapp_ios_mtl_swapchain_resize(int width, int height) { + _sapp_ios_mtl_swapchain_destroy(); + _sapp_ios_mtl_swapchain_create(width, height); +} + +_SOKOL_PRIVATE id _sapp_ios_mtl_swapchain_next(void) { + id drawable = [_sapp.ios.mtl.layer nextDrawable]; + SOKOL_ASSERT(drawable != nil); + return drawable; +} + +_SOKOL_PRIVATE void _sapp_ios_mtl_timing_init(void) { + _sapp.ios.mtl.timing.timestamp = 0.0; + _sapp.ios.mtl.timing.frame_duration_sec = 1.0 / _sapp_ios_max_fps(); +} + +_SOKOL_PRIVATE void _sapp_ios_mtl_timing_update(void) { + const CFTimeInterval cur_timestamp = _sapp.ios.mtl.display_link.timestamp; + // skip first frame (frame_duration had been initialized to display refresh rate) + if (_sapp.ios.mtl.timing.timestamp > 0.0) { + const double dt = cur_timestamp - _sapp.ios.mtl.timing.timestamp; + _sapp.ios.mtl.timing.frame_duration_sec = _sapp_timing_clamp(&_sapp.timing, dt); + } else { + SOKOL_ASSERT(_sapp.ios.mtl.timing.frame_duration_sec > 0.0); + } + _sapp.ios.mtl.timing.timestamp = cur_timestamp; +} + +_SOKOL_PRIVATE double _sapp_ios_mtl_timing_frame_duration(void) { + SOKOL_ASSERT(_sapp.ios.mtl.timing.frame_duration_sec > 0.0); + return _sapp.ios.mtl.timing.frame_duration_sec; +} + +_SOKOL_PRIVATE void _sapp_ios_mtl_start_display_link(void) { + SOKOL_ASSERT(nil == _sapp.ios.mtl.display_link); + SOKOL_ASSERT(nil != _sapp.ios.view); + _sapp.ios.mtl.display_link = [CADisplayLink displayLinkWithTarget:_sapp.ios.view selector:@selector(displayLinkFired:)]; + const float preferred_fps = _sapp_ios_max_fps() / _sapp.swap_interval; + const CAFrameRateRange frame_rate_range = { preferred_fps, preferred_fps, preferred_fps }; + _sapp.ios.mtl.display_link.preferredFrameRateRange = frame_rate_range; + [_sapp.ios.mtl.display_link addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes]; +} + +_SOKOL_PRIVATE void _sapp_ios_mtl_stop_display_link(void) { + if (nil != _sapp.ios.mtl.display_link) { + [_sapp.ios.mtl.display_link invalidate]; + // NOTE: the run-loop held the only string reference to the display link + _sapp.ios.mtl.display_link = nil; + } +} + +_SOKOL_PRIVATE void _sapp_ios_mtl_init(UIWindowScene* windowScene) { + _sapp.ios.mtl.device = MTLCreateSystemDefaultDevice(); + + _sapp.ios.view = [[_sapp_ios_view alloc] initWithFrame:windowScene.screen.bounds]; + _sapp.ios.view.userInteractionEnabled = YES; + #if !defined(_SAPP_TVOS) + _sapp.ios.view.multipleTouchEnabled = YES; + #endif + + _sapp.ios.mtl.layer = [CAMetalLayer layer]; + _sapp.ios.mtl.layer.device = _sapp.ios.mtl.device; + _sapp.ios.mtl.layer.opaque = true; + _sapp.ios.mtl.layer.framebufferOnly = true; + _sapp.ios.mtl.layer.pixelFormat = MTLPixelFormatBGRA8Unorm; + _sapp.ios.mtl.layer.frame = _sapp.ios.view.layer.frame; + + [_sapp.ios.view.layer addSublayer:_sapp.ios.mtl.layer]; + + _sapp.ios.view_ctrl = [[UIViewController alloc] init]; + _sapp.ios.view_ctrl.modalPresentationStyle = UIModalPresentationFullScreen; + _sapp.ios.view_ctrl.view = _sapp.ios.view; + _sapp.ios.window.rootViewController = _sapp.ios.view_ctrl; + + _sapp_ios_mtl_start_display_link(); + _sapp_ios_mtl_timing_init(); +} + +_SOKOL_PRIVATE void _sapp_ios_mtl_discard_state(void) { + _sapp_ios_mtl_stop_display_link(); + _sapp_ios_mtl_swapchain_destroy(); + _SAPP_OBJC_RELEASE(_sapp.ios.mtl.layer); + _SAPP_OBJC_RELEASE(_sapp.ios.view_ctrl); + _SAPP_OBJC_RELEASE(_sapp.ios.mtl.device); +} + +_SOKOL_PRIVATE bool _sapp_ios_mtl_update_framebuffer_dimensions(CGRect screen_rect) { + // get current screen size and if it changed, update the MTKView drawable size + _sapp.framebuffer_width = _sapp_roundf_gzero(screen_rect.size.width * _sapp.dpi_scale); + _sapp.framebuffer_height = _sapp_roundf_gzero(screen_rect.size.height * _sapp.dpi_scale); + const CGSize cur_size = _sapp.ios.mtl.layer.drawableSize; + const int cur_width = _sapp_roundf_gzero(cur_size.width); + const int cur_height = _sapp_roundf_gzero(cur_size.height); + const bool dim_changed = (_sapp.framebuffer_width != cur_width) || (_sapp.framebuffer_height != cur_height); + if (dim_changed) { + const CGSize drawable_size = { (CGFloat) _sapp.framebuffer_width, (CGFloat) _sapp.framebuffer_height }; + _sapp.ios.mtl.layer.drawableSize = drawable_size; + _sapp.ios.mtl.layer.frame = screen_rect; + _sapp_ios_mtl_swapchain_resize(_sapp.framebuffer_width, _sapp.framebuffer_height); + } + return dim_changed; +} +#endif + +#if defined(SOKOL_GLES3) +_SOKOL_PRIVATE void _sapp_ios_gles3_init(UIWindowScene* windowScene) { + const CGRect screen_rect = windowScene.screen.bounds; + _sapp.ios.eagl_ctx = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]; + _sapp.ios.view = [[_sapp_ios_view alloc] initWithFrame:screen_rect]; + _sapp.ios.view.drawableColorFormat = GLKViewDrawableColorFormatRGBA8888; + _sapp.ios.view.drawableDepthFormat = GLKViewDrawableDepthFormat24; + _sapp.ios.view.drawableStencilFormat = GLKViewDrawableStencilFormatNone; + GLKViewDrawableMultisample msaa = _sapp.sample_count > 1 ? GLKViewDrawableMultisample4X : GLKViewDrawableMultisampleNone; + _sapp.ios.view.drawableMultisample = msaa; + _sapp.ios.view.context = _sapp.ios.eagl_ctx; + _sapp.ios.view.enableSetNeedsDisplay = NO; + _sapp.ios.view.userInteractionEnabled = YES; + _sapp.ios.view.multipleTouchEnabled = YES; + // on GLKView, contentScaleFactor appears to work just fine! + if (_sapp.desc.high_dpi) { + _sapp.ios.view.contentScaleFactor = _sapp.dpi_scale; + } else { + _sapp.ios.view.contentScaleFactor = 1.0; + } + _sapp.ios.view_ctrl = [[GLKViewController alloc] init]; + _sapp.ios.view_ctrl.view = _sapp.ios.view; + _sapp.ios.view_ctrl.preferredFramesPerSecond = _sapp_ios_max_fps() / _sapp.swap_interval; + _sapp.ios.window.rootViewController = _sapp.ios.view_ctrl; +} + +_SOKOL_PRIVATE void _sapp_ios_gles3_discard_state(void) { + _SAPP_OBJC_RELEASE(_sapp.ios.view_ctrl); + _SAPP_OBJC_RELEASE(_sapp.ios.eagl_ctx); +} + +_SOKOL_PRIVATE bool _sapp_ios_gles3_update_framebuffer_dimensions(CGRect screen_rect) { + _sapp.framebuffer_width = _sapp_roundf_gzero(screen_rect.size.width * _sapp.dpi_scale); + _sapp.framebuffer_height = _sapp_roundf_gzero(screen_rect.size.height * _sapp.dpi_scale); + int cur_fb_width = _sapp_roundf_gzero(_sapp.ios.view.drawableWidth); + int cur_fb_height = _sapp_roundf_gzero(_sapp.ios.view.drawableHeight); + return (_sapp.framebuffer_width != cur_fb_width) || (_sapp.framebuffer_height != cur_fb_height); +} +#endif + +_SOKOL_PRIVATE void _sapp_ios_discard_state(void) { + // NOTE: it's safe to call [release] on a nil object + _SAPP_OBJC_RELEASE(_sapp.ios.textfield_dlg); + _SAPP_OBJC_RELEASE(_sapp.ios.textfield); + #if defined(SOKOL_METAL) + _sapp_ios_mtl_discard_state(); + #else + _sapp_ios_gles3_discard_state(); + #endif + _SAPP_OBJC_RELEASE(_sapp.ios.view); + _SAPP_OBJC_RELEASE(_sapp.ios.window); +} + +_SOKOL_PRIVATE void _sapp_ios_run(const sapp_desc* desc) { + _sapp_init_state(desc); + static int argc = 1; + static char* argv[] = { (char*)"sokol_app" }; + UIApplicationMain(argc, argv, nil, NSStringFromClass([_sapp_scene_delegate class])); +} + +/* iOS entry function */ +#if !defined(SOKOL_NO_ENTRY) +int main(int argc, char* argv[]) { + sapp_desc desc = sokol_main(argc, argv); + _sapp_ios_run(&desc); + return 0; +} +#endif /* SOKOL_NO_ENTRY */ + +_SOKOL_PRIVATE void _sapp_ios_app_event(sapp_event_type type) { + if (_sapp_events_enabled()) { + _sapp_init_event(type); + _sapp_call_event(&_sapp.event); + } +} + +_SOKOL_PRIVATE void _sapp_tvos_press_event(sapp_event_type type, NSSet* presses) { + if (_sapp_events_enabled()) { + for (UIPress *press in presses) { + sapp_keycode key = SAPP_KEYCODE_INVALID; + switch (press.type) { + case UIPressTypeUpArrow: key = SAPP_KEYCODE_UP; break; + case UIPressTypeDownArrow: key = SAPP_KEYCODE_DOWN; break; + case UIPressTypeLeftArrow: key = SAPP_KEYCODE_LEFT; break; + case UIPressTypeRightArrow: key = SAPP_KEYCODE_RIGHT; break; + case UIPressTypeSelect: key = SAPP_KEYCODE_ENTER; break; + case UIPressTypeMenu: key = SAPP_KEYCODE_MENU; break; + case UIPressTypePlayPause: key = SAPP_KEYCODE_PAUSE; break; + default: break; + } + if (key != SAPP_KEYCODE_INVALID) { + _sapp_init_event(type); + _sapp.event.key_code = key; + _sapp.event.key_repeat = false; + _sapp.event.modifiers = 0; + _sapp_call_event(&_sapp.event); + } + } + } +} + +_SOKOL_PRIVATE void _sapp_ios_touch_event(sapp_event_type type, NSSet* touches, UIEvent* event) { + if (_sapp_events_enabled()) { + _sapp_init_event(type); + NSEnumerator* enumerator = event.allTouches.objectEnumerator; + UITouch* ios_touch; + while ((ios_touch = [enumerator nextObject])) { + if ((_sapp.event.num_touches + 1) < SAPP_MAX_TOUCHPOINTS) { + CGPoint ios_pos = [ios_touch locationInView:_sapp.ios.view]; + sapp_touchpoint* cur_point = &_sapp.event.touches[_sapp.event.num_touches++]; + cur_point->identifier = (uintptr_t) ios_touch; + cur_point->pos_x = ios_pos.x * _sapp.dpi_scale; + cur_point->pos_y = ios_pos.y * _sapp.dpi_scale; + cur_point->changed = [touches containsObject:ios_touch]; + } + } + if (_sapp.event.num_touches > 0) { + _sapp_call_event(&_sapp.event); + } + } +} + +_SOKOL_PRIVATE void _sapp_ios_update_dimensions(void) { + CGRect screen_rect = _sapp.ios.window.windowScene.screen.bounds; + _sapp.window_width = _sapp_roundf_gzero(screen_rect.size.width); + _sapp.window_height = _sapp_roundf_gzero(screen_rect.size.height); + #if defined(SOKOL_METAL) + bool dim_changed = _sapp_ios_mtl_update_framebuffer_dimensions(screen_rect); + #else + bool dim_changed = _sapp_ios_gles3_update_framebuffer_dimensions(screen_rect); + #endif + if (dim_changed && !_sapp.first_frame) { + _sapp_ios_app_event(SAPP_EVENTTYPE_RESIZED); + } +} + +_SOKOL_PRIVATE void _sapp_ios_frame(void) { + _sapp_timing_update(&_sapp.timing, 0.0); + #if defined(SOKOL_METAL) + _sapp_ios_mtl_timing_update(); + #endif + #if defined(_SAPP_ANY_GL) + glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint*)&_sapp.gl.framebuffer); + #endif + @autoreleasepool { + _sapp_ios_update_dimensions(); + _sapp_frame(); + } +} + +_SOKOL_PRIVATE void _sapp_ios_show_keyboard(bool shown) { + /* if not happened yet, create an invisible text field */ + if (nil == _sapp.ios.textfield) { + _sapp.ios.textfield_dlg = [[_sapp_textfield_dlg alloc] init]; + _sapp.ios.textfield = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, 100, 50)]; + _sapp.ios.textfield.keyboardType = UIKeyboardTypeDefault; + _sapp.ios.textfield.returnKeyType = UIReturnKeyDefault; + _sapp.ios.textfield.autocapitalizationType = UITextAutocapitalizationTypeNone; + _sapp.ios.textfield.autocorrectionType = UITextAutocorrectionTypeNo; + _sapp.ios.textfield.spellCheckingType = UITextSpellCheckingTypeNo; + _sapp.ios.textfield.hidden = YES; + _sapp.ios.textfield.text = @"x"; + _sapp.ios.textfield.delegate = _sapp.ios.textfield_dlg; + [_sapp.ios.view_ctrl.view addSubview:_sapp.ios.textfield]; + +#if !defined(_SAPP_TVOS) + [[NSNotificationCenter defaultCenter] addObserver:_sapp.ios.textfield_dlg + selector:@selector(keyboardWasShown:) + name:UIKeyboardDidShowNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:_sapp.ios.textfield_dlg + selector:@selector(keyboardWillBeHidden:) + name:UIKeyboardWillHideNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:_sapp.ios.textfield_dlg + selector:@selector(keyboardDidChangeFrame:) + name:UIKeyboardDidChangeFrameNotification object:nil]; +#endif + } + if (shown) { + // setting the text field as first responder brings up the onscreen keyboard + [_sapp.ios.textfield becomeFirstResponder]; + } else { + [_sapp.ios.textfield resignFirstResponder]; + } +} + +@implementation _sapp_scene_delegate +- (UISceneConfiguration*) application:(UIApplication*)application + configurationForConnectingSceneSession:(UISceneSession*)connectingSceneSession + options:(UISceneConnectionOptions*)options +{ + UISceneConfiguration* config = [[UISceneConfiguration alloc] initWithName:@"SokolSceneConfiguration" sessionRole:connectingSceneSession.role]; + config.delegateClass = [_sapp_scene_delegate class]; + return config; +} + +- (void)scene:(UIScene*)scene willConnectToSession:(UISceneSession*)session options:(UISceneConnectionOptions*)connectionOptions { + UIWindowScene* windowScene = (UIWindowScene*)scene; + CGRect screen_rect = windowScene.screen.bounds; + _sapp.ios.window = [[UIWindow alloc] initWithWindowScene:windowScene]; + _sapp.window_width = _sapp_roundf_gzero(screen_rect.size.width); + _sapp.window_height = _sapp_roundf_gzero(screen_rect.size.height); + if (_sapp.desc.high_dpi) { + _sapp.dpi_scale = (float) windowScene.screen.nativeScale; + } else { + _sapp.dpi_scale = 1.0f; + } + _sapp.framebuffer_width = _sapp_roundf_gzero(_sapp.window_width * _sapp.dpi_scale); + _sapp.framebuffer_height = _sapp_roundf_gzero(_sapp.window_height * _sapp.dpi_scale); + #if defined(SOKOL_METAL) + _sapp_ios_mtl_init(windowScene); + #else + _sapp_ios_gles3_init(windowScene); + #endif + [_sapp.ios.window makeKeyAndVisible]; + _sapp.valid = true; +} + +- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { + return YES; +} + +- (void)sceneWillResignActive:(UIScene*)scene { + if (!_sapp.ios.suspended) { + _sapp.ios.suspended = true; + #if defined(SOKOL_METAL) + if (nil != _sapp.ios.mtl.display_link) { + _sapp.ios.mtl.display_link.paused = YES; + } + #endif + _sapp_ios_app_event(SAPP_EVENTTYPE_SUSPENDED); + } +} + +- (void)sceneDidBecomeActive:(UIScene*)scene { + if (_sapp.ios.suspended) { + _sapp.ios.suspended = false; + #if defined(SOKOL_METAL) + if (nil != _sapp.ios.mtl.display_link) { + _sapp.ios.mtl.display_link.paused = NO; + } + #endif + _sapp_ios_app_event(SAPP_EVENTTYPE_RESUMED); + } +} + +/* NOTE: this method will rarely ever be called, iOS application + which are terminated by the user are usually killed via signal 9 + by the operating system. +*/ +- (void)applicationWillTerminate:(UIApplication *)application { + _SOKOL_UNUSED(application); + _sapp_call_cleanup(); + _sapp_ios_discard_state(); + _sapp_discard_state(); +} +@end + +@implementation _sapp_textfield_dlg +- (void)keyboardWasShown:(NSNotification*)notif { + _sapp.onscreen_keyboard_shown = true; + /* query the keyboard's size, and modify the content view's size */ +#if !defined(_SAPP_TVOS) + if (_sapp.desc.ios.keyboard_resizes_canvas) { + NSDictionary* info = notif.userInfo; + CGFloat kbd_h = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height; + CGRect view_frame = _sapp.ios.window.windowScene.screen.bounds; + view_frame.size.height -= kbd_h; + _sapp.ios.view.frame = view_frame; + } +#endif +} +- (void)keyboardWillBeHidden:(NSNotification*)notif { + _sapp.onscreen_keyboard_shown = false; + if (_sapp.desc.ios.keyboard_resizes_canvas) { + _sapp.ios.view.frame = _sapp.ios.window.windowScene.screen.bounds; + } +} +- (void)keyboardDidChangeFrame:(NSNotification*)notif { + /* this is for the case when the screen rotation changes while the keyboard is open */ +#if !defined(_SAPP_TVOS) + if (_sapp.onscreen_keyboard_shown && _sapp.desc.ios.keyboard_resizes_canvas) { + NSDictionary* info = notif.userInfo; + CGFloat kbd_h = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height; + CGRect view_frame = _sapp.ios.window.windowScene.screen.bounds; + view_frame.size.height -= kbd_h; + _sapp.ios.view.frame = view_frame; + } +#endif +} +- (BOOL)textField:(UITextField*)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString*)string { + if (_sapp_events_enabled()) { + const NSUInteger len = string.length; + if (len > 0) { + for (NSUInteger i = 0; i < len; i++) { + unichar c = [string characterAtIndex:i]; + if (c >= 32) { + /* ignore surrogates for now */ + if ((c < 0xD800) || (c > 0xDFFF)) { + _sapp_init_event(SAPP_EVENTTYPE_CHAR); + _sapp.event.char_code = c; + _sapp_call_event(&_sapp.event); + } + } + if (c <= 32) { + sapp_keycode k = SAPP_KEYCODE_INVALID; + switch (c) { + case 10: k = SAPP_KEYCODE_ENTER; break; + case 32: k = SAPP_KEYCODE_SPACE; break; + default: break; + } + if (k != SAPP_KEYCODE_INVALID) { + _sapp_init_event(SAPP_EVENTTYPE_KEY_DOWN); + _sapp.event.key_code = k; + _sapp_call_event(&_sapp.event); + _sapp_init_event(SAPP_EVENTTYPE_KEY_UP); + _sapp.event.key_code = k; + _sapp_call_event(&_sapp.event); + } + } + } + } else { + // this was a backspace + _sapp_init_event(SAPP_EVENTTYPE_KEY_DOWN); + _sapp.event.key_code = SAPP_KEYCODE_BACKSPACE; + _sapp_call_event(&_sapp.event); + _sapp_init_event(SAPP_EVENTTYPE_KEY_UP); + _sapp.event.key_code = SAPP_KEYCODE_BACKSPACE; + _sapp_call_event(&_sapp.event); + } + } + return NO; +} +@end + +@implementation _sapp_ios_view +#if defined(SOKOL_METAL) +- (void)displayLinkFired:(id)sender { + _SOKOL_UNUSED(sender); + _sapp_ios_frame(); +} +#else +- (void)drawRect:(CGRect)rect { + _SOKOL_UNUSED(rect); + _sapp_ios_frame(); +} +#endif + +- (BOOL)isOpaque { + return YES; +} +- (void)pressesBegan:(NSSet *)presses withEvent:(UIPressesEvent *)event { + _sapp_tvos_press_event(SAPP_EVENTTYPE_KEY_DOWN, presses); +} +- (void)pressesChanged:(NSSet *)presses withEvent:(UIPressesEvent *)event { +} +- (void)pressesEnded:(NSSet *)presses withEvent:(UIPressesEvent *)event { + _sapp_tvos_press_event(SAPP_EVENTTYPE_KEY_UP, presses); +} +- (void)pressesCancelled:(NSSet *)presses withEvent:(UIPressesEvent *)event { + _sapp_tvos_press_event(SAPP_EVENTTYPE_KEY_UP, presses); +} +- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent*)event { + _sapp_ios_touch_event(SAPP_EVENTTYPE_TOUCHES_BEGAN, touches, event); +} +- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent*)event { + _sapp_ios_touch_event(SAPP_EVENTTYPE_TOUCHES_MOVED, touches, event); +} +- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent*)event { + _sapp_ios_touch_event(SAPP_EVENTTYPE_TOUCHES_ENDED, touches, event); +} +- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent*)event { + _sapp_ios_touch_event(SAPP_EVENTTYPE_TOUCHES_CANCELLED, touches, event); +} +@end +#endif /* TARGET_OS_IPHONE */ + +#endif /* _SAPP_APPLE */ + +// ███████ ███ ███ ███████ ██████ ██████ ██ ██████ ████████ ███████ ███ ██ +// ██ ████ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ +// █████ ██ ████ ██ ███████ ██ ██████ ██ ██████ ██ █████ ██ ██ ██ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ███████ ██ ██ ███████ ██████ ██ ██ ██ ██ ██ ███████ ██ ████ +// +// >>emscripten +#if defined(_SAPP_EMSCRIPTEN) + +#if defined(EM_JS_DEPS) +EM_JS_DEPS(sokol_app, "$withStackSave,$stringToUTF8OnStack,$findCanvasEventTarget") +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void (*_sapp_html5_fetch_callback) (const sapp_html5_fetch_response*); + +EMSCRIPTEN_KEEPALIVE void _sapp_emsc_onpaste(const char* str) { + if (_sapp.clipboard.enabled) { + _sapp_strcpy(str, _sapp.clipboard.buffer, (size_t)_sapp.clipboard.buf_size); + if (_sapp_events_enabled()) { + _sapp_init_event(SAPP_EVENTTYPE_CLIPBOARD_PASTED); + _sapp_call_event(&_sapp.event); + } + } +} + +/* https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload */ +EMSCRIPTEN_KEEPALIVE int _sapp_html5_get_ask_leave_site(void) { + return _sapp.html5_ask_leave_site ? 1 : 0; +} + +EMSCRIPTEN_KEEPALIVE void _sapp_emsc_begin_drop(int num) { + if (!_sapp.drop.enabled) { + return; + } + if (num < 0) { + num = 0; + } + if (num > _sapp.drop.max_files) { + num = _sapp.drop.max_files; + } + _sapp.drop.num_files = num; + _sapp_clear_drop_buffer(); +} + +EMSCRIPTEN_KEEPALIVE void _sapp_emsc_drop(int i, const char* name) { + /* NOTE: name is only the filename part, not a path */ + if (!_sapp.drop.enabled) { + return; + } + if (0 == name) { + return; + } + SOKOL_ASSERT(_sapp.drop.num_files <= _sapp.drop.max_files); + if ((i < 0) || (i >= _sapp.drop.num_files)) { + return; + } + if (!_sapp_strcpy(name, _sapp_dropped_file_path_ptr(i), (size_t)_sapp.drop.max_path_length)) { + _SAPP_ERROR(DROPPED_FILE_PATH_TOO_LONG); + _sapp.drop.num_files = 0; + } +} + +EMSCRIPTEN_KEEPALIVE void _sapp_emsc_end_drop(int x, int y, int mods) { + if (!_sapp.drop.enabled) { + return; + } + if (0 == _sapp.drop.num_files) { + /* there was an error copying the filenames */ + _sapp_clear_drop_buffer(); + return; + + } + if (_sapp_events_enabled()) { + _sapp.mouse.x = (float)x * _sapp.dpi_scale; + _sapp.mouse.y = (float)y * _sapp.dpi_scale; + _sapp.mouse.dx = 0.0f; + _sapp.mouse.dy = 0.0f; + _sapp_init_event(SAPP_EVENTTYPE_FILES_DROPPED); + // see sapp_js_add_dragndrop_listeners for mods constants + if (mods & 1) { _sapp.event.modifiers |= SAPP_MODIFIER_SHIFT; } + if (mods & 2) { _sapp.event.modifiers |= SAPP_MODIFIER_CTRL; } + if (mods & 4) { _sapp.event.modifiers |= SAPP_MODIFIER_ALT; } + if (mods & 8) { _sapp.event.modifiers |= SAPP_MODIFIER_SUPER; } + _sapp_call_event(&_sapp.event); + } +} + +EMSCRIPTEN_KEEPALIVE void _sapp_emsc_invoke_fetch_cb(int index, int success, int error_code, _sapp_html5_fetch_callback callback, uint32_t fetched_size, void* buf_ptr, uint32_t buf_size, void* user_data) { + _SAPP_STRUCT(sapp_html5_fetch_response, response); + response.succeeded = (0 != success); + response.error_code = (sapp_html5_fetch_error) error_code; + response.file_index = index; + response.data.ptr = buf_ptr; + response.data.size = fetched_size; + response.buffer.ptr = buf_ptr; + response.buffer.size = buf_size; + response.user_data = user_data; + callback(&response); +} + +// will be called after the request/exitFullscreen promise rejects +// to restore the _sapp.fullscreen flag to the actual fullscreen state +EMSCRIPTEN_KEEPALIVE void _sapp_emsc_set_fullscreen_flag(int f) { + _sapp.fullscreen = (bool)f; +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +EM_JS(void, sapp_js_add_beforeunload_listener, (void), { + Module.sokol_beforeunload = (event) => { + if (__sapp_html5_get_ask_leave_site() != 0) { + event.preventDefault(); + event.returnValue = ' '; + } + }; + window.addEventListener('beforeunload', Module.sokol_beforeunload); +}) + +EM_JS(void, sapp_js_remove_beforeunload_listener, (void), { + window.removeEventListener('beforeunload', Module.sokol_beforeunload); +}) + +EM_JS(void, sapp_js_add_clipboard_listener, (void), { + Module.sokol_paste = (event) => { + const pasted_str = event.clipboardData.getData('text'); + withStackSave(() => { + const cstr = stringToUTF8OnStack(pasted_str); + __sapp_emsc_onpaste(cstr); + }); + }; + window.addEventListener('paste', Module.sokol_paste); +}) + +EM_JS(void, sapp_js_remove_clipboard_listener, (void), { + window.removeEventListener('paste', Module.sokol_paste); +}) + +EM_JS(void, sapp_js_write_clipboard, (const char* c_str), { + const str = UTF8ToString(c_str); + const ta = document.createElement('textarea'); + ta.setAttribute('autocomplete', 'off'); + ta.setAttribute('autocorrect', 'off'); + ta.setAttribute('autocapitalize', 'off'); + ta.setAttribute('spellcheck', 'false'); + ta.style.left = -100 + 'px'; + ta.style.top = -100 + 'px'; + ta.style.height = 1; + ta.style.width = 1; + ta.value = str; + document.body.appendChild(ta); + ta.select(); + document.execCommand('copy'); + document.body.removeChild(ta); +}) + +_SOKOL_PRIVATE void _sapp_emsc_set_clipboard_string(const char* str) { + sapp_js_write_clipboard(str); +} + +EM_JS(void, sapp_js_add_dragndrop_listeners, (void), { + Module.sokol_drop_files = []; + Module.sokol_dragenter = (event) => { + event.stopPropagation(); + event.preventDefault(); + }; + Module.sokol_dragleave = (event) => { + event.stopPropagation(); + event.preventDefault(); + }; + Module.sokol_dragover = (event) => { + event.stopPropagation(); + event.preventDefault(); + }; + Module.sokol_drop = (event) => { + event.stopPropagation(); + event.preventDefault(); + const files = event.dataTransfer.files; + Module.sokol_dropped_files = files; + __sapp_emsc_begin_drop(files.length); + for (let i = 0; i < files.length; i++) { + withStackSave(() => { + const cstr = stringToUTF8OnStack(files[i].name); + __sapp_emsc_drop(i, cstr); + }); + } + let mods = 0; + if (event.shiftKey) { mods |= 1; } + if (event.ctrlKey) { mods |= 2; } + if (event.altKey) { mods |= 4; } + if (event.metaKey) { mods |= 8; } + // FIXME? see computation of targetX/targetY in emscripten via getClientBoundingRect + __sapp_emsc_end_drop(event.clientX, event.clientY, mods); + }; + \x2F\x2A\x2A @suppress {missingProperties} \x2A\x2F + const canvas = Module.sapp_emsc_target; + canvas.addEventListener('dragenter', Module.sokol_dragenter, false); + canvas.addEventListener('dragleave', Module.sokol_dragleave, false); + canvas.addEventListener('dragover', Module.sokol_dragover, false); + canvas.addEventListener('drop', Module.sokol_drop, false); +}) + +EM_JS(uint32_t, sapp_js_dropped_file_size, (int index), { + \x2F\x2A\x2A @suppress {missingProperties} \x2A\x2F + const files = Module.sokol_dropped_files; + if ((index < 0) || (index >= files.length)) { + return 0; + } else { + return files[index].size; + } +}) + +EM_JS(void, sapp_js_fetch_dropped_file, (int index, _sapp_html5_fetch_callback callback, void* buf_ptr, uint32_t buf_size, void* user_data), { + const reader = new FileReader(); + reader.onload = (loadEvent) => { + const content = loadEvent.target.result; + if (content.byteLength > buf_size) { + // SAPP_HTML5_FETCH_ERROR_BUFFER_TOO_SMALL + __sapp_emsc_invoke_fetch_cb(index, 0, 1, callback, 0, buf_ptr, buf_size, user_data); + } else { + HEAPU8.set(new Uint8Array(content), buf_ptr); + __sapp_emsc_invoke_fetch_cb(index, 1, 0, callback, content.byteLength, buf_ptr, buf_size, user_data); + } + }; + reader.onerror = () => { + // SAPP_HTML5_FETCH_ERROR_OTHER + __sapp_emsc_invoke_fetch_cb(index, 0, 2, callback, 0, buf_ptr, buf_size, user_data); + }; + \x2F\x2A\x2A @suppress {missingProperties} \x2A\x2F + const files = Module.sokol_dropped_files; + reader.readAsArrayBuffer(files[index]); +}) + +EM_JS(void, sapp_js_remove_dragndrop_listeners, (void), { + \x2F\x2A\x2A @suppress {missingProperties} \x2A\x2F + const canvas = Module.sapp_emsc_target; + canvas.removeEventListener('dragenter', Module.sokol_dragenter); + canvas.removeEventListener('dragleave', Module.sokol_dragleave); + canvas.removeEventListener('dragover', Module.sokol_dragover); + canvas.removeEventListener('drop', Module.sokol_drop); +}) + +EM_JS(void, sapp_js_init, (const char* c_str_target_selector, const char* c_str_document_title), { + if (c_str_document_title !== 0) { + document.title = UTF8ToString(c_str_document_title); + } + const target_selector_str = UTF8ToString(c_str_target_selector); + if (Module['canvas'] !== undefined) { + if (typeof Module['canvas'] === 'object') { + specialHTMLTargets[target_selector_str] = Module['canvas']; + } else { + console.warn("sokol_app.h: Module['canvas'] is set but is not an object"); + } + } + Module.sapp_emsc_target = findCanvasEventTarget(target_selector_str); + if (!Module.sapp_emsc_target) { + console.warn("sokol_app.h: can't find html5_canvas_selector ", target_selector_str); + } + if (!Module.sapp_emsc_target.requestPointerLock) { + console.warn("sokol_app.h: target doesn't support requestPointerLock: ", target_selector_str); + } +}) + +_SOKOL_PRIVATE EM_BOOL _sapp_emsc_pointerlockchange_cb(int emsc_type, const EmscriptenPointerlockChangeEvent* emsc_event, void* user_data) { + _SOKOL_UNUSED(emsc_type); + _SOKOL_UNUSED(user_data); + _sapp.mouse.locked = emsc_event->isActive; + return EM_TRUE; +} + +_SOKOL_PRIVATE EM_BOOL _sapp_emsc_pointerlockerror_cb(int emsc_type, const void* reserved, void* user_data) { + _SOKOL_UNUSED(emsc_type); + _SOKOL_UNUSED(reserved); + _SOKOL_UNUSED(user_data); + _sapp.mouse.locked = false; + _sapp.emsc.mouse_lock_requested = false; + return true; +} + +EM_JS(void, sapp_js_request_pointerlock, (void), { + if (Module.sapp_emsc_target) { + if (Module.sapp_emsc_target.requestPointerLock) { + Module.sapp_emsc_target.requestPointerLock(); + } + } +}) + +EM_JS(void, sapp_js_exit_pointerlock, (void), { + if (document.exitPointerLock) { + document.exitPointerLock(); + } +}) + +_SOKOL_PRIVATE void _sapp_emsc_lock_mouse(bool lock) { + if (lock) { + /* request mouse-lock during event handler invocation (see _sapp_emsc_update_mouse_lock_state) */ + _sapp.emsc.mouse_lock_requested = true; + } else { + /* NOTE: the _sapp.mouse_locked state will be set in the pointerlockchange callback */ + _sapp.emsc.mouse_lock_requested = false; + sapp_js_exit_pointerlock(); + } +} + +/* called from inside event handlers to check if mouse lock had been requested, + and if yes, actually enter mouse lock. +*/ +_SOKOL_PRIVATE void _sapp_emsc_update_mouse_lock_state(void) { + if (_sapp.emsc.mouse_lock_requested) { + _sapp.emsc.mouse_lock_requested = false; + sapp_js_request_pointerlock(); + } +} + +// set mouse cursor type +EM_JS(void, sapp_js_set_cursor, (int cursor_type, int shown, int use_custom_cursor_image), { + if (Module.sapp_emsc_target) { + let cursor; + if (shown === 0) { + cursor = "none"; + } else if (use_custom_cursor_image != 0) { + cursor = Module.__sapp_custom_cursors[cursor_type].css_property; + } else switch (cursor_type) { + case 0: cursor = "auto"; break; // SAPP_MOUSECURSOR_DEFAULT + case 1: cursor = "default"; break; // SAPP_MOUSECURSOR_ARROW + case 2: cursor = "text"; break; // SAPP_MOUSECURSOR_IBEAM + case 3: cursor = "crosshair"; break; // SAPP_MOUSECURSOR_CROSSHAIR + case 4: cursor = "pointer"; break; // SAPP_MOUSECURSOR_POINTING_HAND + case 5: cursor = "ew-resize"; break; // SAPP_MOUSECURSOR_RESIZE_EW + case 6: cursor = "ns-resize"; break; // SAPP_MOUSECURSOR_RESIZE_NS + case 7: cursor = "nwse-resize"; break; // SAPP_MOUSECURSOR_RESIZE_NWSE + case 8: cursor = "nesw-resize"; break; // SAPP_MOUSECURSOR_RESIZE_NESW + case 9: cursor = "all-scroll"; break; // SAPP_MOUSECURSOR_RESIZE_ALL + case 10: cursor = "not-allowed"; break; // SAPP_MOUSECURSOR_NOT_ALLOWED + default: cursor = "auto"; break; + } + Module.sapp_emsc_target.style.cursor = cursor; + } +}) + +_SOKOL_PRIVATE void _sapp_emsc_update_cursor(sapp_mouse_cursor cursor, bool shown) { + SOKOL_ASSERT((cursor >= 0) && (cursor < _SAPP_MOUSECURSOR_NUM)); + bool custom_cursor = _sapp.custom_cursor_bound[cursor]; + sapp_js_set_cursor((int)cursor, shown ? 1 : 0, custom_cursor ? 1 : 0); +} + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdollar-in-identifier-extension" +EM_JS(void, sapp_js_make_custom_mouse_cursor, (int cursor_slot_idx, int width, int height, const void* pixels_ptr, int hotspot_x, int hotspot_y), { + // encode the cursor pixels into a BMP which then is encoded into an 'object url' + const bmp_hdr_size = 14; + const dib_hdr_size = 124; // common values are 56, I saw 124 for the rgba32-1.bmp file of the test suite included in firefox, and 108 from wikipedia example 2 (transparent) + const pixels_size = width * height * 4; + const bmp_size = bmp_hdr_size + dib_hdr_size + pixels_size; + const bmp = new Uint8Array(bmp_size); + let index = 0; + const w8 = (val) => { + bmp[index++] = val & 255; + }; + const w16 = (val) => { + bmp[index++] = val & 255; + bmp[index++] = (val >> 8) & 255; + }; + const w32 = (val) => { + bmp[index++] = val & 255; + bmp[index++] = (val >> 8) & 255; + bmp[index++] = (val >> 16) & 255; + bmp[index++] = (val >> 24) & 255; + }; + + // bmp file header + w8(66); // 'B' + w8(77); // 'M' + w32(bmp_size); + w32(0); // reserved + w32(bmp_hdr_size + dib_hdr_size); // offset to pixel data + assert(index == bmp_hdr_size); + + // DIB header + w32(dib_hdr_size); // header size + w32(width); + w32(height); + w16(1); // planes + w16(32); // bits per pixel + w32(3); // compression method. 3 = BI_BITFIELDS + w32(pixels_size); // image size + w32(2835); // pixel per metre horizontal + w32(2835); // pixel per metre vertical + w32(0); // colors number + w32(0); // important colors + w32(0x000000ff); // red channel bit mask (big endian) + w32(0x0000ff00); // green channel bit mask (big endian) + w32(0x00ff0000); // blue channel bit mask (big endian) + w32(0xff000000); // alpha channel bit mask (big endian) + w8(66); w8(71); w8(82); w8(115); // color space type: 'sRGB' + index += 64; // color space stuff, unused for 'Win ' or 'sRGB' + assert(index == bmp_hdr_size + dib_hdr_size); + const row_pitch = width * 4; + for (let y = 0; y < height; y++) { + const src_idx = pixels_ptr + y * row_pitch; + const dst_idx = index + (height - y - 1) * row_pitch; + const row_data = HEAPU8.slice(src_idx, src_idx + row_pitch); + bmp.set(row_data, dst_idx); + } + const blob = new Blob([bmp.buffer], { type: 'image/bmp' }); + const url = URL.createObjectURL(blob); + + const cursor_slot = { + css_property: `url('${url}') ${hotspot_x} ${hotspot_y}, auto`, + blob_url: url // so we can release it later + }; + + // Store a reference to the js cursor object in a global table, indexed by its sapp_mouse_cursor + if (!Module.__sapp_custom_cursors) { + Module.__sapp_custom_cursors = Array().fill(null); + } + Module.__sapp_custom_cursors[cursor_slot_idx] = cursor_slot; +}) + +#pragma GCC diagnostic pop +EM_JS(void, sapp_js_destroy_custom_mouse_cursor, (int cursor_slot_idx), { + if (Module.__sapp_custom_cursors) { + const cursor = Module.__sapp_custom_cursors[cursor_slot_idx]; + URL.revokeObjectURL(cursor.blob_url); // release the url, which should allow the blob to be garbage collected. + Module.__sapp_custom_cursors[cursor_slot_idx] = null; // clear this array entry + } +}) + +_SOKOL_PRIVATE bool _sapp_emsc_make_custom_mouse_cursor(sapp_mouse_cursor cursor, const sapp_image_desc* desc) { + sapp_js_make_custom_mouse_cursor((int)cursor, desc->width, desc->height, desc->pixels.ptr, desc->cursor_hotspot_x, desc->cursor_hotspot_y); + return true; +} + +_SOKOL_PRIVATE void _sapp_emsc_destroy_custom_mouse_cursor(sapp_mouse_cursor cursor) { + sapp_js_destroy_custom_mouse_cursor((int) cursor); +} + +// NOTE: this callback is needed to react to the user actively leaving fullscreen mode via Esc +_SOKOL_PRIVATE EM_BOOL _sapp_emsc_fullscreenchange_cb(int emsc_type, const EmscriptenFullscreenChangeEvent* emsc_event, void* user_data) { + _SOKOL_UNUSED(emsc_type); + _SOKOL_UNUSED(user_data); + _sapp.fullscreen = emsc_event->isFullscreen; + return true; +} + +EM_JS(void, sapp_js_toggle_fullscreen, (void), { + const canvas = Module.sapp_emsc_target; + if (canvas) { + // NOTE: Safari had the prefix until 2023, Firefox until 2018 + const fullscreenElement = document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement; + let p = undefined; + if (!fullscreenElement) { + if (canvas.requestFullscreen) { + p = canvas.requestFullscreen(); + } else if (canvas.webkitRequestFullscreen) { + p = canvas.webkitRequestFullscreen(); + } else if (canvas.mozRequestFullScreen) { + p = canvas.mozRequestFullScreen(); + } + if (p) { + p.catch((err) => { + console.warn('sapp_js_toggle_fullscreen(): failed to enter fullscreen mode with', err); + __sapp_emsc_set_fullscreen_flag(0); + }); + } else { + console.warn('sapp_js_toogle_fullscreen(): browser has no [webkit|moz]requestFullscreen function'); + __sapp_emsc_set_fullscreen_flag(0); + } + } else { + if (document.exitFullscreen) { + p = document.exitFullscreen(); + } else if (document.webkitExitFullscreen) { + p = document.webkitExitFullscreen(); + } else if (document.mozCancelFullScreen) { + p = document.mozCancelFullScreen(); + } + if (p) { + p.catch((err) => { + console.warn('sapp_js_toggle_fullscreen(): failed to exit fullscreen mode with', err); + __sapp_emsc_set_fullscreen_flag(1); + }); + } else { + console.warn('sapp_js_toggle_fullscreen(): browser has no [wekbit|moz]exitFullscreen'); + // NOTE: don't need to explicitly set the fullscreen flag here + } + } + } +}) + +_SOKOL_PRIVATE void _sapp_emsc_toggle_fullscreen(void) { + // toggle the fullscreen flag preliminary, this may be undone + // when requesting/exiting fullscreen mode actually fails + _sapp.fullscreen = !_sapp.fullscreen; + sapp_js_toggle_fullscreen(); +} + +/* JS helper functions to update browser tab favicon */ +EM_JS(void, sapp_js_clear_favicon, (void), { + const link = document.getElementById('sokol-app-favicon'); + if (link) { + document.head.removeChild(link); + } +}) + +EM_JS(void, sapp_js_set_favicon, (int w, int h, const uint8_t* pixels), { + const canvas = document.createElement('canvas'); + canvas.width = w; + canvas.height = h; + const ctx = canvas.getContext('2d'); + const img_data = ctx.createImageData(w, h); + img_data.data.set(HEAPU8.subarray(pixels, pixels + w*h*4)); + ctx.putImageData(img_data, 0, 0); + const new_link = document.createElement('link'); + new_link.id = 'sokol-app-favicon'; + new_link.rel = 'shortcut icon'; + new_link.href = canvas.toDataURL(); + document.head.appendChild(new_link); +}) + +_SOKOL_PRIVATE void _sapp_emsc_set_icon(const sapp_icon_desc* icon_desc, int num_images) { + SOKOL_ASSERT((num_images > 0) && (num_images <= SAPP_MAX_ICONIMAGES)); + sapp_js_clear_favicon(); + // find the best matching image candidate for 16x16 pixels + int img_index = _sapp_image_bestmatch(icon_desc->images, num_images, 16, 16); + const sapp_image_desc* img_desc = &icon_desc->images[img_index]; + sapp_js_set_favicon(img_desc->width, img_desc->height, (const uint8_t*) img_desc->pixels.ptr); +} + +_SOKOL_PRIVATE uint32_t _sapp_emsc_mouse_button_mods(uint16_t buttons) { + uint32_t m = 0; + if (0 != (buttons & (1<<0))) { m |= SAPP_MODIFIER_LMB; } + if (0 != (buttons & (1<<1))) { m |= SAPP_MODIFIER_RMB; } // not a bug + if (0 != (buttons & (1<<2))) { m |= SAPP_MODIFIER_MMB; } // not a bug + return m; +} + +_SOKOL_PRIVATE uint32_t _sapp_emsc_mouse_event_mods(const EmscriptenMouseEvent* ev) { + uint32_t m = 0; + if (ev->ctrlKey) { m |= SAPP_MODIFIER_CTRL; } + if (ev->shiftKey) { m |= SAPP_MODIFIER_SHIFT; } + if (ev->altKey) { m |= SAPP_MODIFIER_ALT; } + if (ev->metaKey) { m |= SAPP_MODIFIER_SUPER; } + m |= _sapp_emsc_mouse_button_mods(_sapp.emsc.mouse_buttons); + return m; +} + +_SOKOL_PRIVATE uint32_t _sapp_emsc_key_event_mods(const EmscriptenKeyboardEvent* ev) { + uint32_t m = 0; + if (ev->ctrlKey) { m |= SAPP_MODIFIER_CTRL; } + if (ev->shiftKey) { m |= SAPP_MODIFIER_SHIFT; } + if (ev->altKey) { m |= SAPP_MODIFIER_ALT; } + if (ev->metaKey) { m |= SAPP_MODIFIER_SUPER; } + m |= _sapp_emsc_mouse_button_mods(_sapp.emsc.mouse_buttons); + return m; +} + +_SOKOL_PRIVATE uint32_t _sapp_emsc_touch_event_mods(const EmscriptenTouchEvent* ev) { + uint32_t m = 0; + if (ev->ctrlKey) { m |= SAPP_MODIFIER_CTRL; } + if (ev->shiftKey) { m |= SAPP_MODIFIER_SHIFT; } + if (ev->altKey) { m |= SAPP_MODIFIER_ALT; } + if (ev->metaKey) { m |= SAPP_MODIFIER_SUPER; } + m |= _sapp_emsc_mouse_button_mods(_sapp.emsc.mouse_buttons); + return m; +} + +_SOKOL_PRIVATE EM_BOOL _sapp_emsc_size_changed(int event_type, const EmscriptenUiEvent* ui_event, void* user_data) { + _SOKOL_UNUSED(event_type); + _SOKOL_UNUSED(user_data); + double w, h; + emscripten_get_element_css_size(_sapp.html5_canvas_selector, &w, &h); + /* The above method might report zero when toggling HTML5 fullscreen, + in that case use the window's inner width reported by the + emscripten event. This works ok when toggling *into* fullscreen + but doesn't properly restore the previous canvas size when switching + back from fullscreen. + + In general, due to the HTML5's fullscreen API's flaky nature it is + recommended to use 'soft fullscreen' (stretching the WebGL canvas + over the browser windows client rect) with a CSS definition like this: + + position: absolute; + top: 0px; + left: 0px; + margin: 0px; + border: 0; + width: 100%; + height: 100%; + overflow: hidden; + display: block; + */ + if (w < 1.0) { + w = ui_event->windowInnerWidth; + } else { + _sapp.window_width = _sapp_roundf_gzero(w); + } + if (h < 1.0) { + h = ui_event->windowInnerHeight; + } else { + _sapp.window_height = _sapp_roundf_gzero(h); + } + if (_sapp.desc.high_dpi) { + _sapp.dpi_scale = emscripten_get_device_pixel_ratio(); + } + _sapp.framebuffer_width = _sapp_roundf_gzero(w * _sapp.dpi_scale); + _sapp.framebuffer_height = _sapp_roundf_gzero(h * _sapp.dpi_scale); + emscripten_set_canvas_element_size(_sapp.html5_canvas_selector, _sapp.framebuffer_width, _sapp.framebuffer_height); + #if defined(SOKOL_WGPU) + // on WebGPU: recreate size-dependent rendering surfaces + _sapp_wgpu_swapchain_size_changed(); + #endif + if (_sapp_events_enabled()) { + _sapp_init_event(SAPP_EVENTTYPE_RESIZED); + _sapp_call_event(&_sapp.event); + } + return true; +} + +_SOKOL_PRIVATE EM_BOOL _sapp_emsc_mouse_cb(int emsc_type, const EmscriptenMouseEvent* emsc_event, void* user_data) { + _SOKOL_UNUSED(user_data); + bool consume_event = !_sapp.desc.html5.bubble_mouse_events; + _sapp.emsc.mouse_buttons = emsc_event->buttons; + if (_sapp.mouse.locked) { + _sapp.mouse.dx = (float) emsc_event->movementX; + _sapp.mouse.dy = (float) emsc_event->movementY; + } else { + float new_x = emsc_event->targetX * _sapp.dpi_scale; + float new_y = emsc_event->targetY * _sapp.dpi_scale; + if (_sapp.mouse.pos_valid) { + _sapp.mouse.dx = new_x - _sapp.mouse.x; + _sapp.mouse.dy = new_y - _sapp.mouse.y; + } + _sapp.mouse.x = new_x; + _sapp.mouse.y = new_y; + _sapp.mouse.pos_valid = true; + } + if (_sapp_events_enabled() && (emsc_event->button >= 0) && (emsc_event->button < SAPP_MAX_MOUSEBUTTONS)) { + sapp_event_type type; + bool is_button_event = false; + bool clear_dxdy = false; + switch (emsc_type) { + case EMSCRIPTEN_EVENT_MOUSEDOWN: + type = SAPP_EVENTTYPE_MOUSE_DOWN; + is_button_event = true; + break; + case EMSCRIPTEN_EVENT_MOUSEUP: + type = SAPP_EVENTTYPE_MOUSE_UP; + is_button_event = true; + break; + case EMSCRIPTEN_EVENT_MOUSEMOVE: + type = SAPP_EVENTTYPE_MOUSE_MOVE; + break; + case EMSCRIPTEN_EVENT_MOUSEENTER: + type = SAPP_EVENTTYPE_MOUSE_ENTER; + clear_dxdy = true; + break; + case EMSCRIPTEN_EVENT_MOUSELEAVE: + type = SAPP_EVENTTYPE_MOUSE_LEAVE; + clear_dxdy = true; + break; + default: + type = SAPP_EVENTTYPE_INVALID; + break; + } + if (clear_dxdy) { + _sapp.mouse.dx = 0.0f; + _sapp.mouse.dy = 0.0f; + } + if (type != SAPP_EVENTTYPE_INVALID) { + _sapp_init_event(type); + _sapp.event.modifiers = _sapp_emsc_mouse_event_mods(emsc_event); + if (is_button_event) { + switch (emsc_event->button) { + case 0: _sapp.event.mouse_button = SAPP_MOUSEBUTTON_LEFT; break; + case 1: _sapp.event.mouse_button = SAPP_MOUSEBUTTON_MIDDLE; break; + case 2: _sapp.event.mouse_button = SAPP_MOUSEBUTTON_RIGHT; break; + default: _sapp.event.mouse_button = (sapp_mousebutton)emsc_event->button; break; + } + } else { + _sapp.event.mouse_button = SAPP_MOUSEBUTTON_INVALID; + } + consume_event |= _sapp_call_event(&_sapp.event); + } + // mouse lock can only be activated in mouse button events (not in move, enter or leave) + if (is_button_event) { + _sapp_emsc_update_mouse_lock_state(); + } + } + return consume_event; +} + +_SOKOL_PRIVATE EM_BOOL _sapp_emsc_wheel_cb(int emsc_type, const EmscriptenWheelEvent* emsc_event, void* user_data) { + _SOKOL_UNUSED(emsc_type); + _SOKOL_UNUSED(user_data); + bool consume_event = !_sapp.desc.html5.bubble_wheel_events; + _sapp.emsc.mouse_buttons = emsc_event->mouse.buttons; + if (_sapp_events_enabled()) { + _sapp_init_event(SAPP_EVENTTYPE_MOUSE_SCROLL); + _sapp.event.modifiers = _sapp_emsc_mouse_event_mods(&emsc_event->mouse); + /* see https://github.com/floooh/sokol/issues/339 */ + float scale; + switch (emsc_event->deltaMode) { + case DOM_DELTA_PIXEL: scale = -0.01f; break; + case DOM_DELTA_LINE: scale = -1.33f; break; + case DOM_DELTA_PAGE: scale = -10.0f; break; // FIXME: this is a guess + default: scale = -0.1f; break; // shouldn't happen + } + _sapp.event.scroll_x = scale * (float)emsc_event->deltaX; + _sapp.event.scroll_y = scale * (float)emsc_event->deltaY; + consume_event |= _sapp_call_event(&_sapp.event); + } + _sapp_emsc_update_mouse_lock_state(); + return consume_event; +} + +static struct { + const char* str; + sapp_keycode code; +} _sapp_emsc_keymap[] = { + { "Backspace", SAPP_KEYCODE_BACKSPACE }, + { "Tab", SAPP_KEYCODE_TAB }, + { "Enter", SAPP_KEYCODE_ENTER }, + { "ShiftLeft", SAPP_KEYCODE_LEFT_SHIFT }, + { "ShiftRight", SAPP_KEYCODE_RIGHT_SHIFT }, + { "ControlLeft", SAPP_KEYCODE_LEFT_CONTROL }, + { "ControlRight", SAPP_KEYCODE_RIGHT_CONTROL }, + { "AltLeft", SAPP_KEYCODE_LEFT_ALT }, + { "AltRight", SAPP_KEYCODE_RIGHT_ALT }, + { "Pause", SAPP_KEYCODE_PAUSE }, + { "CapsLock", SAPP_KEYCODE_CAPS_LOCK }, + { "Escape", SAPP_KEYCODE_ESCAPE }, + { "Space", SAPP_KEYCODE_SPACE }, + { "PageUp", SAPP_KEYCODE_PAGE_UP }, + { "PageDown", SAPP_KEYCODE_PAGE_DOWN }, + { "End", SAPP_KEYCODE_END }, + { "Home", SAPP_KEYCODE_HOME }, + { "ArrowLeft", SAPP_KEYCODE_LEFT }, + { "ArrowUp", SAPP_KEYCODE_UP }, + { "ArrowRight", SAPP_KEYCODE_RIGHT }, + { "ArrowDown", SAPP_KEYCODE_DOWN }, + { "PrintScreen", SAPP_KEYCODE_PRINT_SCREEN }, + { "Insert", SAPP_KEYCODE_INSERT }, + { "Delete", SAPP_KEYCODE_DELETE }, + { "Digit0", SAPP_KEYCODE_0 }, + { "Digit1", SAPP_KEYCODE_1 }, + { "Digit2", SAPP_KEYCODE_2 }, + { "Digit3", SAPP_KEYCODE_3 }, + { "Digit4", SAPP_KEYCODE_4 }, + { "Digit5", SAPP_KEYCODE_5 }, + { "Digit6", SAPP_KEYCODE_6 }, + { "Digit7", SAPP_KEYCODE_7 }, + { "Digit8", SAPP_KEYCODE_8 }, + { "Digit9", SAPP_KEYCODE_9 }, + { "KeyA", SAPP_KEYCODE_A }, + { "KeyB", SAPP_KEYCODE_B }, + { "KeyC", SAPP_KEYCODE_C }, + { "KeyD", SAPP_KEYCODE_D }, + { "KeyE", SAPP_KEYCODE_E }, + { "KeyF", SAPP_KEYCODE_F }, + { "KeyG", SAPP_KEYCODE_G }, + { "KeyH", SAPP_KEYCODE_H }, + { "KeyI", SAPP_KEYCODE_I }, + { "KeyJ", SAPP_KEYCODE_J }, + { "KeyK", SAPP_KEYCODE_K }, + { "KeyL", SAPP_KEYCODE_L }, + { "KeyM", SAPP_KEYCODE_M }, + { "KeyN", SAPP_KEYCODE_N }, + { "KeyO", SAPP_KEYCODE_O }, + { "KeyP", SAPP_KEYCODE_P }, + { "KeyQ", SAPP_KEYCODE_Q }, + { "KeyR", SAPP_KEYCODE_R }, + { "KeyS", SAPP_KEYCODE_S }, + { "KeyT", SAPP_KEYCODE_T }, + { "KeyU", SAPP_KEYCODE_U }, + { "KeyV", SAPP_KEYCODE_V }, + { "KeyW", SAPP_KEYCODE_W }, + { "KeyX", SAPP_KEYCODE_X }, + { "KeyY", SAPP_KEYCODE_Y }, + { "KeyZ", SAPP_KEYCODE_Z }, + { "MetaLeft", SAPP_KEYCODE_LEFT_SUPER }, + { "MetaRight", SAPP_KEYCODE_RIGHT_SUPER }, + { "Numpad0", SAPP_KEYCODE_KP_0 }, + { "Numpad1", SAPP_KEYCODE_KP_1 }, + { "Numpad2", SAPP_KEYCODE_KP_2 }, + { "Numpad3", SAPP_KEYCODE_KP_3 }, + { "Numpad4", SAPP_KEYCODE_KP_4 }, + { "Numpad5", SAPP_KEYCODE_KP_5 }, + { "Numpad6", SAPP_KEYCODE_KP_6 }, + { "Numpad7", SAPP_KEYCODE_KP_7 }, + { "Numpad8", SAPP_KEYCODE_KP_8 }, + { "Numpad9", SAPP_KEYCODE_KP_9 }, + { "NumpadMultiply", SAPP_KEYCODE_KP_MULTIPLY }, + { "NumpadAdd", SAPP_KEYCODE_KP_ADD }, + { "NumpadSubtract", SAPP_KEYCODE_KP_SUBTRACT }, + { "NumpadDecimal", SAPP_KEYCODE_KP_DECIMAL }, + { "NumpadDivide", SAPP_KEYCODE_KP_DIVIDE }, + { "F1", SAPP_KEYCODE_F1 }, + { "F2", SAPP_KEYCODE_F2 }, + { "F3", SAPP_KEYCODE_F3 }, + { "F4", SAPP_KEYCODE_F4 }, + { "F5", SAPP_KEYCODE_F5 }, + { "F6", SAPP_KEYCODE_F6 }, + { "F7", SAPP_KEYCODE_F7 }, + { "F8", SAPP_KEYCODE_F8 }, + { "F9", SAPP_KEYCODE_F9 }, + { "F10", SAPP_KEYCODE_F10 }, + { "F11", SAPP_KEYCODE_F11 }, + { "F12", SAPP_KEYCODE_F12 }, + { "NumLock", SAPP_KEYCODE_NUM_LOCK }, + { "ScrollLock", SAPP_KEYCODE_SCROLL_LOCK }, + { "Semicolon", SAPP_KEYCODE_SEMICOLON }, + { "Equal", SAPP_KEYCODE_EQUAL }, + { "Comma", SAPP_KEYCODE_COMMA }, + { "Minus", SAPP_KEYCODE_MINUS }, + { "Period", SAPP_KEYCODE_PERIOD }, + { "Slash", SAPP_KEYCODE_SLASH }, + { "Backquote", SAPP_KEYCODE_GRAVE_ACCENT }, + { "BracketLeft", SAPP_KEYCODE_LEFT_BRACKET }, + { "Backslash", SAPP_KEYCODE_BACKSLASH }, + { "BracketRight", SAPP_KEYCODE_RIGHT_BRACKET }, + { "Quote", SAPP_KEYCODE_GRAVE_ACCENT }, // FIXME: ??? + { 0, SAPP_KEYCODE_INVALID }, +}; + +_SOKOL_PRIVATE sapp_keycode _sapp_emsc_translate_key(const char* str) { + int i = 0; + const char* keystr; + while (( keystr = _sapp_emsc_keymap[i].str )) { + if (0 == strcmp(str, keystr)) { + return _sapp_emsc_keymap[i].code; + } + i += 1; + } + return SAPP_KEYCODE_INVALID; +} + +// returns true if the key code is a 'character key', this is used to decide +// if a key event needs to bubble up to create a char event +_SOKOL_PRIVATE bool _sapp_emsc_is_char_key(sapp_keycode key_code) { + return key_code < SAPP_KEYCODE_WORLD_1; +} + +_SOKOL_PRIVATE EM_BOOL _sapp_emsc_key_cb(int emsc_type, const EmscriptenKeyboardEvent* emsc_event, void* user_data) { + _SOKOL_UNUSED(user_data); + bool consume_event = false; + if (_sapp_events_enabled()) { + sapp_event_type type; + switch (emsc_type) { + case EMSCRIPTEN_EVENT_KEYDOWN: + type = SAPP_EVENTTYPE_KEY_DOWN; + break; + case EMSCRIPTEN_EVENT_KEYUP: + type = SAPP_EVENTTYPE_KEY_UP; + break; + case EMSCRIPTEN_EVENT_KEYPRESS: + type = SAPP_EVENTTYPE_CHAR; + break; + default: + type = SAPP_EVENTTYPE_INVALID; + break; + } + if (type != SAPP_EVENTTYPE_INVALID) { + bool send_keyup_followup = false; + _sapp_init_event(type); + _sapp.event.key_repeat = emsc_event->repeat; + _sapp.event.modifiers = _sapp_emsc_key_event_mods(emsc_event); + if (type == SAPP_EVENTTYPE_CHAR) { + // NOTE: charCode doesn't appear to be supported on Android Chrome + _sapp.event.char_code = emsc_event->charCode; + consume_event |= !_sapp.desc.html5.bubble_char_events; + } else { + if (0 != emsc_event->code[0]) { + // This code path is for desktop browsers which send untranslated 'physical' key code strings + // (which is what we actually want for key events) + _sapp.event.key_code = _sapp_emsc_translate_key(emsc_event->code); + } else { + // This code path is for mobile browsers which only send localized key code + // strings. Note that the translation will only work for a small subset + // of localization-agnostic keys (like Enter, arrow keys, etc...), but + // regular alpha-numeric keys will all result in an SAPP_KEYCODE_INVALID) + _sapp.event.key_code = _sapp_emsc_translate_key(emsc_event->key); + } + + // Special hack for macOS: if the Super key is pressed, macOS doesn't + // send keyUp events. As a workaround, to prevent keys from + // "sticking", we'll send a keyup event following a keydown + // when the SUPER key is pressed + if ((type == SAPP_EVENTTYPE_KEY_DOWN) && + (_sapp.event.key_code != SAPP_KEYCODE_LEFT_SUPER) && + (_sapp.event.key_code != SAPP_KEYCODE_RIGHT_SUPER) && + (_sapp.event.modifiers & SAPP_MODIFIER_SUPER)) + { + send_keyup_followup = true; + } + + // 'character key events' will always need to bubble up, otherwise the browser + // wouldn't be able to generate character events. + if (!_sapp_emsc_is_char_key(_sapp.event.key_code)) { + consume_event |= !_sapp.desc.html5.bubble_key_events; + } + } + consume_event |= _sapp_call_event(&_sapp.event); + if (send_keyup_followup) { + _sapp.event.type = SAPP_EVENTTYPE_KEY_UP; + consume_event |= _sapp_call_event(&_sapp.event); + } + } + } + _sapp_emsc_update_mouse_lock_state(); + return consume_event; +} + +_SOKOL_PRIVATE EM_BOOL _sapp_emsc_touch_cb(int emsc_type, const EmscriptenTouchEvent* emsc_event, void* user_data) { + _SOKOL_UNUSED(user_data); + bool consume_event = !_sapp.desc.html5.bubble_touch_events; + if (_sapp_events_enabled()) { + sapp_event_type type; + switch (emsc_type) { + case EMSCRIPTEN_EVENT_TOUCHSTART: + type = SAPP_EVENTTYPE_TOUCHES_BEGAN; + break; + case EMSCRIPTEN_EVENT_TOUCHMOVE: + type = SAPP_EVENTTYPE_TOUCHES_MOVED; + break; + case EMSCRIPTEN_EVENT_TOUCHEND: + type = SAPP_EVENTTYPE_TOUCHES_ENDED; + break; + case EMSCRIPTEN_EVENT_TOUCHCANCEL: + type = SAPP_EVENTTYPE_TOUCHES_CANCELLED; + break; + default: + type = SAPP_EVENTTYPE_INVALID; + break; + } + if (type != SAPP_EVENTTYPE_INVALID) { + _sapp_init_event(type); + _sapp.event.modifiers = _sapp_emsc_touch_event_mods(emsc_event); + _sapp.event.num_touches = emsc_event->numTouches; + if (_sapp.event.num_touches > SAPP_MAX_TOUCHPOINTS) { + _sapp.event.num_touches = SAPP_MAX_TOUCHPOINTS; + } + for (int i = 0; i < _sapp.event.num_touches; i++) { + const EmscriptenTouchPoint* src = &emsc_event->touches[i]; + sapp_touchpoint* dst = &_sapp.event.touches[i]; + dst->identifier = (uintptr_t)src->identifier; + dst->pos_x = src->targetX * _sapp.dpi_scale; + dst->pos_y = src->targetY * _sapp.dpi_scale; + dst->changed = src->isChanged; + } + consume_event |= _sapp_call_event(&_sapp.event); + } + } + return consume_event; +} + +_SOKOL_PRIVATE EM_BOOL _sapp_emsc_focus_cb(int emsc_type, const EmscriptenFocusEvent* emsc_event, void* user_data) { + _SOKOL_UNUSED(emsc_type); + _SOKOL_UNUSED(emsc_event); + _SOKOL_UNUSED(user_data); + if (_sapp_events_enabled()) { + _sapp_init_event(SAPP_EVENTTYPE_FOCUSED); + _sapp_call_event(&_sapp.event); + } + return true; +} + +_SOKOL_PRIVATE EM_BOOL _sapp_emsc_blur_cb(int emsc_type, const EmscriptenFocusEvent* emsc_event, void* user_data) { + _SOKOL_UNUSED(emsc_type); + _SOKOL_UNUSED(emsc_event); + _SOKOL_UNUSED(user_data); + if (_sapp_events_enabled()) { + _sapp_init_event(SAPP_EVENTTYPE_UNFOCUSED); + _sapp_call_event(&_sapp.event); + } + return true; +} + +#if defined(SOKOL_GLES3) +_SOKOL_PRIVATE EM_BOOL _sapp_emsc_webgl_context_cb(int emsc_type, const void* reserved, void* user_data) { + _SOKOL_UNUSED(reserved); + _SOKOL_UNUSED(user_data); + sapp_event_type type; + switch (emsc_type) { + case EMSCRIPTEN_EVENT_WEBGLCONTEXTLOST: type = SAPP_EVENTTYPE_SUSPENDED; break; + case EMSCRIPTEN_EVENT_WEBGLCONTEXTRESTORED: type = SAPP_EVENTTYPE_RESUMED; break; + default: type = SAPP_EVENTTYPE_INVALID; break; + } + if (_sapp_events_enabled() && (SAPP_EVENTTYPE_INVALID != type)) { + _sapp_init_event(type); + _sapp_call_event(&_sapp.event); + } + return true; +} + +_SOKOL_PRIVATE void _sapp_emsc_webgl_init(void) { + EmscriptenWebGLContextAttributes attrs; + emscripten_webgl_init_context_attributes(&attrs); + attrs.alpha = _sapp.desc.alpha; + attrs.depth = true; + attrs.stencil = true; + attrs.antialias = _sapp.sample_count > 1; + attrs.premultipliedAlpha = _sapp.desc.html5.premultiplied_alpha; + attrs.preserveDrawingBuffer = _sapp.desc.html5.preserve_drawing_buffer; + attrs.enableExtensionsByDefault = true; + attrs.majorVersion = 2; + EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_create_context(_sapp.html5_canvas_selector, &attrs); + // FIXME: error message? + emscripten_webgl_make_context_current(ctx); + glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint*)&_sapp.gl.framebuffer); +} +#endif + +_SOKOL_PRIVATE void _sapp_emsc_register_eventhandlers(void) { + // NOTE: HTML canvas doesn't receive input focus, this is why key event handlers are added + // to the window object (this could be worked around by adding a "tab index" to the + // canvas) + emscripten_set_mousedown_callback(_sapp.html5_canvas_selector, 0, true, _sapp_emsc_mouse_cb); + emscripten_set_mouseup_callback(_sapp.html5_canvas_selector, 0, true, _sapp_emsc_mouse_cb); + emscripten_set_mousemove_callback(_sapp.html5_canvas_selector, 0, true, _sapp_emsc_mouse_cb); + emscripten_set_mouseenter_callback(_sapp.html5_canvas_selector, 0, true, _sapp_emsc_mouse_cb); + emscripten_set_mouseleave_callback(_sapp.html5_canvas_selector, 0, true, _sapp_emsc_mouse_cb); + emscripten_set_wheel_callback(_sapp.html5_canvas_selector, 0, true, _sapp_emsc_wheel_cb); + emscripten_set_keydown_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, 0, true, _sapp_emsc_key_cb); + emscripten_set_keyup_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, 0, true, _sapp_emsc_key_cb); + emscripten_set_keypress_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, 0, true, _sapp_emsc_key_cb); + emscripten_set_touchstart_callback(_sapp.html5_canvas_selector, 0, true, _sapp_emsc_touch_cb); + emscripten_set_touchmove_callback(_sapp.html5_canvas_selector, 0, true, _sapp_emsc_touch_cb); + emscripten_set_touchend_callback(_sapp.html5_canvas_selector, 0, true, _sapp_emsc_touch_cb); + emscripten_set_touchcancel_callback(_sapp.html5_canvas_selector, 0, true, _sapp_emsc_touch_cb); + emscripten_set_pointerlockchange_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, 0, true, _sapp_emsc_pointerlockchange_cb); + emscripten_set_pointerlockerror_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, 0, true, _sapp_emsc_pointerlockerror_cb); + emscripten_set_focus_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, 0, true, _sapp_emsc_focus_cb); + emscripten_set_blur_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, 0, true, _sapp_emsc_blur_cb); + emscripten_set_fullscreenchange_callback(_sapp.html5_canvas_selector, 0, true, _sapp_emsc_fullscreenchange_cb); + sapp_js_add_beforeunload_listener(); + if (_sapp.clipboard.enabled) { + sapp_js_add_clipboard_listener(); + } + if (_sapp.drop.enabled) { + sapp_js_add_dragndrop_listeners(); + } + #if defined(SOKOL_GLES3) + emscripten_set_webglcontextlost_callback(_sapp.html5_canvas_selector, 0, true, _sapp_emsc_webgl_context_cb); + emscripten_set_webglcontextrestored_callback(_sapp.html5_canvas_selector, 0, true, _sapp_emsc_webgl_context_cb); + #endif +} + +_SOKOL_PRIVATE void _sapp_emsc_unregister_eventhandlers(void) { + emscripten_set_mousedown_callback(_sapp.html5_canvas_selector, 0, true, 0); + emscripten_set_mouseup_callback(_sapp.html5_canvas_selector, 0, true, 0); + emscripten_set_mousemove_callback(_sapp.html5_canvas_selector, 0, true, 0); + emscripten_set_mouseenter_callback(_sapp.html5_canvas_selector, 0, true, 0); + emscripten_set_mouseleave_callback(_sapp.html5_canvas_selector, 0, true, 0); + emscripten_set_wheel_callback(_sapp.html5_canvas_selector, 0, true, 0); + emscripten_set_keydown_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, 0, true, 0); + emscripten_set_keyup_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, 0, true, 0); + emscripten_set_keypress_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, 0, true, 0); + emscripten_set_touchstart_callback(_sapp.html5_canvas_selector, 0, true, 0); + emscripten_set_touchmove_callback(_sapp.html5_canvas_selector, 0, true, 0); + emscripten_set_touchend_callback(_sapp.html5_canvas_selector, 0, true, 0); + emscripten_set_touchcancel_callback(_sapp.html5_canvas_selector, 0, true, 0); + emscripten_set_pointerlockchange_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, 0, true, 0); + emscripten_set_pointerlockerror_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, 0, true, 0); + emscripten_set_focus_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, 0, true, 0); + emscripten_set_blur_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, 0, true, 0); + emscripten_set_fullscreenchange_callback(_sapp.html5_canvas_selector, 0, true, 0); + if (!_sapp.desc.html5.canvas_resize) { + emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, 0, true, 0); + } + sapp_js_remove_beforeunload_listener(); + if (_sapp.clipboard.enabled) { + sapp_js_remove_clipboard_listener(); + } + if (_sapp.drop.enabled) { + sapp_js_remove_dragndrop_listeners(); + } + #if defined(SOKOL_GLES3) + emscripten_set_webglcontextlost_callback(_sapp.html5_canvas_selector, 0, true, 0); + emscripten_set_webglcontextrestored_callback(_sapp.html5_canvas_selector, 0, true, 0); + #endif +} + +_SOKOL_PRIVATE EM_BOOL _sapp_emsc_frame_animation_loop(double time, void* userData) { + _SOKOL_UNUSED(userData); + _sapp_timing_update(&_sapp.timing, time / 1000.0); + + #if defined(SOKOL_WGPU) + _sapp_wgpu_frame(); + #else + _sapp_frame(); + #endif + + // quit-handling + if (_sapp.quit_requested) { + _sapp_init_event(SAPP_EVENTTYPE_QUIT_REQUESTED); + _sapp_call_event(&_sapp.event); + if (_sapp.quit_requested) { + _sapp.quit_ordered = true; + } + } + if (_sapp.quit_ordered) { + _sapp_emsc_unregister_eventhandlers(); + #if defined(SOKOL_WGPU) + _sapp_wgpu_discard(); + #endif + _sapp_call_cleanup(); + _sapp_discard_state(); + return EM_FALSE; + } + return EM_TRUE; +} + +_SOKOL_PRIVATE void _sapp_emsc_frame_main_loop(void) { + const double time = emscripten_performance_now(); + if (!_sapp_emsc_frame_animation_loop(time, 0)) { + emscripten_cancel_main_loop(); + } +} + +_SOKOL_PRIVATE void _sapp_emsc_run(const sapp_desc* desc) { + _sapp_init_state(desc); + _sapp.fullscreen = false; // override user provided fullscreen state: can't start in fullscreen on the web! + const char* document_title = desc->html5.update_document_title ? _sapp.window_title : 0; + sapp_js_init(_sapp.html5_canvas_selector, document_title); + double w, h; + if (_sapp.desc.html5.canvas_resize) { + w = (double) _sapp_def(_sapp.desc.width, _SAPP_FALLBACK_DEFAULT_WINDOW_WIDTH); + h = (double) _sapp_def(_sapp.desc.height, _SAPP_FALLBACK_DEFAULT_WINDOW_HEIGHT); + } else { + emscripten_get_element_css_size(_sapp.html5_canvas_selector, &w, &h); + emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, 0, false, _sapp_emsc_size_changed); + } + if (_sapp.desc.high_dpi) { + _sapp.dpi_scale = emscripten_get_device_pixel_ratio(); + } + _sapp.window_width = _sapp_roundf_gzero(w); + _sapp.window_height = _sapp_roundf_gzero(h); + _sapp.framebuffer_width = _sapp_roundf_gzero(w * _sapp.dpi_scale); + _sapp.framebuffer_height = _sapp_roundf_gzero(h * _sapp.dpi_scale); + emscripten_set_canvas_element_size(_sapp.html5_canvas_selector, _sapp.framebuffer_width, _sapp.framebuffer_height); + #if defined(SOKOL_GLES3) + _sapp_emsc_webgl_init(); + #elif defined(SOKOL_WGPU) + _sapp_wgpu_init(); + #endif + _sapp.valid = true; + _sapp_emsc_register_eventhandlers(); + sapp_set_icon(&desc->icon); + + // start the frame loop + if (_sapp.desc.html5.use_emsc_set_main_loop) { + emscripten_set_main_loop(_sapp_emsc_frame_main_loop, 0, _sapp.desc.html5.emsc_set_main_loop_simulate_infinite_loop); + } else { + emscripten_request_animation_frame_loop(_sapp_emsc_frame_animation_loop, 0); + } + // NOT A BUG: do not call _sapp_discard_state() here, instead this is + // called in _sapp_emsc_frame() when the application is ordered to quit +} + +#if !defined(SOKOL_NO_ENTRY) +int main(int argc, char* argv[]) { + sapp_desc desc = sokol_main(argc, argv); + _sapp_emsc_run(&desc); + return 0; +} +#endif /* SOKOL_NO_ENTRY */ +#endif /* _SAPP_EMSCRIPTEN */ + +// ██████ ██ ██ ██ ███████ ██ ██████ ███████ ██████ ███████ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ██ ███ ██ ███████ █████ ██ ██████ █████ ██████ ███████ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ██████ ███████ ██ ██ ███████ ███████ ██ ███████ ██ ██ ███████ +// +// >>gl helpers +#if defined(SOKOL_GLCORE) +typedef struct { + int red_bits; + int green_bits; + int blue_bits; + int alpha_bits; + int depth_bits; + int stencil_bits; + int samples; + bool doublebuffer; + uintptr_t handle; +} _sapp_gl_fbconfig; + +_SOKOL_PRIVATE void _sapp_gl_init_fbconfig(_sapp_gl_fbconfig* fbconfig) { + _sapp_clear(fbconfig, sizeof(_sapp_gl_fbconfig)); + /* -1 means "don't care" */ + fbconfig->red_bits = -1; + fbconfig->green_bits = -1; + fbconfig->blue_bits = -1; + fbconfig->alpha_bits = -1; + fbconfig->depth_bits = -1; + fbconfig->stencil_bits = -1; + fbconfig->samples = -1; +} + +typedef struct { + int least_missing; + int least_color_diff; + int least_extra_diff; + bool best_match; +} _sapp_gl_fbselect; + +_SOKOL_PRIVATE void _sapp_gl_init_fbselect(_sapp_gl_fbselect* fbselect) { + _sapp_clear(fbselect, sizeof(_sapp_gl_fbselect)); + fbselect->least_missing = 1000000; + fbselect->least_color_diff = 10000000; + fbselect->least_extra_diff = 10000000; + fbselect->best_match = false; +} + +// NOTE: this is used only in the WGL code path +_SOKOL_PRIVATE bool _sapp_gl_select_fbconfig(_sapp_gl_fbselect* fbselect, const _sapp_gl_fbconfig* desired, const _sapp_gl_fbconfig* current) { + int missing = 0; + if (desired->doublebuffer != current->doublebuffer) { + return false; + } + + if ((desired->alpha_bits > 0) && (current->alpha_bits == 0)) { + missing++; + } + if ((desired->depth_bits > 0) && (current->depth_bits == 0)) { + missing++; + } + if ((desired->stencil_bits > 0) && (current->stencil_bits == 0)) { + missing++; + } + if ((desired->samples > 0) && (current->samples == 0)) { + /* Technically, several multisampling buffers could be + involved, but that's a lower level implementation detail and + not important to us here, so we count them as one + */ + missing++; + } + + /* These polynomials make many small channel size differences matter + less than one large channel size difference + Calculate color channel size difference value + */ + int color_diff = 0; + if (desired->red_bits != -1) { + color_diff += (desired->red_bits - current->red_bits) * (desired->red_bits - current->red_bits); + } + if (desired->green_bits != -1) { + color_diff += (desired->green_bits - current->green_bits) * (desired->green_bits - current->green_bits); + } + if (desired->blue_bits != -1) { + color_diff += (desired->blue_bits - current->blue_bits) * (desired->blue_bits - current->blue_bits); + } + + /* Calculate non-color channel size difference value */ + int extra_diff = 0; + if (desired->alpha_bits != -1) { + extra_diff += (desired->alpha_bits - current->alpha_bits) * (desired->alpha_bits - current->alpha_bits); + } + if (desired->depth_bits != -1) { + extra_diff += (desired->depth_bits - current->depth_bits) * (desired->depth_bits - current->depth_bits); + } + if (desired->stencil_bits != -1) { + extra_diff += (desired->stencil_bits - current->stencil_bits) * (desired->stencil_bits - current->stencil_bits); + } + if (desired->samples != -1) { + extra_diff += (desired->samples - current->samples) * (desired->samples - current->samples); + } + + /* Figure out if the current one is better than the best one found so far + Least number of missing buffers is the most important heuristic, + then color buffer size match and lastly size match for other buffers + */ + bool new_closest = false; + if (missing < fbselect->least_missing) { + new_closest = true; + } else if (missing == fbselect->least_missing) { + if ((color_diff < fbselect->least_color_diff) || + ((color_diff == fbselect->least_color_diff) && (extra_diff < fbselect->least_extra_diff))) + { + new_closest = true; + } + } + if (new_closest) { + fbselect->least_missing = missing; + fbselect->least_color_diff = color_diff; + fbselect->least_extra_diff = extra_diff; + fbselect->best_match = (missing | color_diff | extra_diff) == 0; + } + return new_closest; +} + +// NOTE: this is used only in the GLX code path +_SOKOL_PRIVATE const _sapp_gl_fbconfig* _sapp_gl_choose_fbconfig(const _sapp_gl_fbconfig* desired, const _sapp_gl_fbconfig* alternatives, int count) { + int missing, least_missing = 1000000; + int color_diff, least_color_diff = 10000000; + int extra_diff, least_extra_diff = 10000000; + const _sapp_gl_fbconfig* current; + const _sapp_gl_fbconfig* closest = 0; + for (int i = 0; i < count; i++) { + current = alternatives + i; + if (desired->doublebuffer != current->doublebuffer) { + continue; + } + missing = 0; + if (desired->alpha_bits > 0 && current->alpha_bits == 0) { + missing++; + } + if (desired->depth_bits > 0 && current->depth_bits == 0) { + missing++; + } + if (desired->stencil_bits > 0 && current->stencil_bits == 0) { + missing++; + } + if (desired->samples > 0 && current->samples == 0) { + /* Technically, several multisampling buffers could be + involved, but that's a lower level implementation detail and + not important to us here, so we count them as one + */ + missing++; + } + + /* These polynomials make many small channel size differences matter + less than one large channel size difference + Calculate color channel size difference value + */ + color_diff = 0; + if (desired->red_bits != -1) { + color_diff += (desired->red_bits - current->red_bits) * (desired->red_bits - current->red_bits); + } + if (desired->green_bits != -1) { + color_diff += (desired->green_bits - current->green_bits) * (desired->green_bits - current->green_bits); + } + if (desired->blue_bits != -1) { + color_diff += (desired->blue_bits - current->blue_bits) * (desired->blue_bits - current->blue_bits); + } + + /* Calculate non-color channel size difference value */ + extra_diff = 0; + if (desired->alpha_bits != -1) { + extra_diff += (desired->alpha_bits - current->alpha_bits) * (desired->alpha_bits - current->alpha_bits); + } + if (desired->depth_bits != -1) { + extra_diff += (desired->depth_bits - current->depth_bits) * (desired->depth_bits - current->depth_bits); + } + if (desired->stencil_bits != -1) { + extra_diff += (desired->stencil_bits - current->stencil_bits) * (desired->stencil_bits - current->stencil_bits); + } + if (desired->samples != -1) { + extra_diff += (desired->samples - current->samples) * (desired->samples - current->samples); + } + + /* Figure out if the current one is better than the best one found so far + Least number of missing buffers is the most important heuristic, + then color buffer size match and lastly size match for other buffers + */ + if (missing < least_missing) { + closest = current; + } else if (missing == least_missing) { + if ((color_diff < least_color_diff) || + (color_diff == least_color_diff && extra_diff < least_extra_diff)) + { + closest = current; + } + } + if (current == closest) { + least_missing = missing; + least_color_diff = color_diff; + least_extra_diff = extra_diff; + } + } + return closest; +} +#endif + +// ██ ██ ██ ███ ██ ██████ ██████ ██ ██ ███████ +// ██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ +// ██ █ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ █ ██ ███████ +// ██ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ███ ██ ██ +// ███ ███ ██ ██ ████ ██████ ██████ ███ ███ ███████ +// +// >>windows +#if defined(_SAPP_WIN32) +_SOKOL_PRIVATE bool _sapp_win32_utf8_to_wide(const char* src, wchar_t* dst, int dst_num_bytes) { + SOKOL_ASSERT(src && dst && (dst_num_bytes > 1)); + _sapp_clear(dst, (size_t)dst_num_bytes); + const int dst_chars = dst_num_bytes / (int)sizeof(wchar_t); + const int dst_needed = MultiByteToWideChar(CP_UTF8, 0, src, -1, 0, 0); + if ((dst_needed > 0) && (dst_needed < dst_chars)) { + MultiByteToWideChar(CP_UTF8, 0, src, -1, dst, dst_chars); + return true; + } else { + // input string doesn't fit into destination buffer + return false; + } +} + +_SOKOL_PRIVATE void _sapp_win32_app_event(sapp_event_type type) { + if (_sapp_events_enabled()) { + _sapp_init_event(type); + _sapp_call_event(&_sapp.event); + } +} + +_SOKOL_PRIVATE void _sapp_win32_init_keytable(void) { + /* same as GLFW */ + _sapp.keycodes[0x00B] = SAPP_KEYCODE_0; + _sapp.keycodes[0x002] = SAPP_KEYCODE_1; + _sapp.keycodes[0x003] = SAPP_KEYCODE_2; + _sapp.keycodes[0x004] = SAPP_KEYCODE_3; + _sapp.keycodes[0x005] = SAPP_KEYCODE_4; + _sapp.keycodes[0x006] = SAPP_KEYCODE_5; + _sapp.keycodes[0x007] = SAPP_KEYCODE_6; + _sapp.keycodes[0x008] = SAPP_KEYCODE_7; + _sapp.keycodes[0x009] = SAPP_KEYCODE_8; + _sapp.keycodes[0x00A] = SAPP_KEYCODE_9; + _sapp.keycodes[0x01E] = SAPP_KEYCODE_A; + _sapp.keycodes[0x030] = SAPP_KEYCODE_B; + _sapp.keycodes[0x02E] = SAPP_KEYCODE_C; + _sapp.keycodes[0x020] = SAPP_KEYCODE_D; + _sapp.keycodes[0x012] = SAPP_KEYCODE_E; + _sapp.keycodes[0x021] = SAPP_KEYCODE_F; + _sapp.keycodes[0x022] = SAPP_KEYCODE_G; + _sapp.keycodes[0x023] = SAPP_KEYCODE_H; + _sapp.keycodes[0x017] = SAPP_KEYCODE_I; + _sapp.keycodes[0x024] = SAPP_KEYCODE_J; + _sapp.keycodes[0x025] = SAPP_KEYCODE_K; + _sapp.keycodes[0x026] = SAPP_KEYCODE_L; + _sapp.keycodes[0x032] = SAPP_KEYCODE_M; + _sapp.keycodes[0x031] = SAPP_KEYCODE_N; + _sapp.keycodes[0x018] = SAPP_KEYCODE_O; + _sapp.keycodes[0x019] = SAPP_KEYCODE_P; + _sapp.keycodes[0x010] = SAPP_KEYCODE_Q; + _sapp.keycodes[0x013] = SAPP_KEYCODE_R; + _sapp.keycodes[0x01F] = SAPP_KEYCODE_S; + _sapp.keycodes[0x014] = SAPP_KEYCODE_T; + _sapp.keycodes[0x016] = SAPP_KEYCODE_U; + _sapp.keycodes[0x02F] = SAPP_KEYCODE_V; + _sapp.keycodes[0x011] = SAPP_KEYCODE_W; + _sapp.keycodes[0x02D] = SAPP_KEYCODE_X; + _sapp.keycodes[0x015] = SAPP_KEYCODE_Y; + _sapp.keycodes[0x02C] = SAPP_KEYCODE_Z; + _sapp.keycodes[0x028] = SAPP_KEYCODE_APOSTROPHE; + _sapp.keycodes[0x02B] = SAPP_KEYCODE_BACKSLASH; + _sapp.keycodes[0x033] = SAPP_KEYCODE_COMMA; + _sapp.keycodes[0x00D] = SAPP_KEYCODE_EQUAL; + _sapp.keycodes[0x029] = SAPP_KEYCODE_GRAVE_ACCENT; + _sapp.keycodes[0x01A] = SAPP_KEYCODE_LEFT_BRACKET; + _sapp.keycodes[0x00C] = SAPP_KEYCODE_MINUS; + _sapp.keycodes[0x034] = SAPP_KEYCODE_PERIOD; + _sapp.keycodes[0x01B] = SAPP_KEYCODE_RIGHT_BRACKET; + _sapp.keycodes[0x027] = SAPP_KEYCODE_SEMICOLON; + _sapp.keycodes[0x035] = SAPP_KEYCODE_SLASH; + _sapp.keycodes[0x056] = SAPP_KEYCODE_WORLD_2; + _sapp.keycodes[0x00E] = SAPP_KEYCODE_BACKSPACE; + _sapp.keycodes[0x153] = SAPP_KEYCODE_DELETE; + _sapp.keycodes[0x14F] = SAPP_KEYCODE_END; + _sapp.keycodes[0x01C] = SAPP_KEYCODE_ENTER; + _sapp.keycodes[0x001] = SAPP_KEYCODE_ESCAPE; + _sapp.keycodes[0x147] = SAPP_KEYCODE_HOME; + _sapp.keycodes[0x152] = SAPP_KEYCODE_INSERT; + _sapp.keycodes[0x15D] = SAPP_KEYCODE_MENU; + _sapp.keycodes[0x151] = SAPP_KEYCODE_PAGE_DOWN; + _sapp.keycodes[0x149] = SAPP_KEYCODE_PAGE_UP; + _sapp.keycodes[0x045] = SAPP_KEYCODE_PAUSE; + _sapp.keycodes[0x146] = SAPP_KEYCODE_PAUSE; + _sapp.keycodes[0x039] = SAPP_KEYCODE_SPACE; + _sapp.keycodes[0x00F] = SAPP_KEYCODE_TAB; + _sapp.keycodes[0x03A] = SAPP_KEYCODE_CAPS_LOCK; + _sapp.keycodes[0x145] = SAPP_KEYCODE_NUM_LOCK; + _sapp.keycodes[0x046] = SAPP_KEYCODE_SCROLL_LOCK; + _sapp.keycodes[0x03B] = SAPP_KEYCODE_F1; + _sapp.keycodes[0x03C] = SAPP_KEYCODE_F2; + _sapp.keycodes[0x03D] = SAPP_KEYCODE_F3; + _sapp.keycodes[0x03E] = SAPP_KEYCODE_F4; + _sapp.keycodes[0x03F] = SAPP_KEYCODE_F5; + _sapp.keycodes[0x040] = SAPP_KEYCODE_F6; + _sapp.keycodes[0x041] = SAPP_KEYCODE_F7; + _sapp.keycodes[0x042] = SAPP_KEYCODE_F8; + _sapp.keycodes[0x043] = SAPP_KEYCODE_F9; + _sapp.keycodes[0x044] = SAPP_KEYCODE_F10; + _sapp.keycodes[0x057] = SAPP_KEYCODE_F11; + _sapp.keycodes[0x058] = SAPP_KEYCODE_F12; + _sapp.keycodes[0x064] = SAPP_KEYCODE_F13; + _sapp.keycodes[0x065] = SAPP_KEYCODE_F14; + _sapp.keycodes[0x066] = SAPP_KEYCODE_F15; + _sapp.keycodes[0x067] = SAPP_KEYCODE_F16; + _sapp.keycodes[0x068] = SAPP_KEYCODE_F17; + _sapp.keycodes[0x069] = SAPP_KEYCODE_F18; + _sapp.keycodes[0x06A] = SAPP_KEYCODE_F19; + _sapp.keycodes[0x06B] = SAPP_KEYCODE_F20; + _sapp.keycodes[0x06C] = SAPP_KEYCODE_F21; + _sapp.keycodes[0x06D] = SAPP_KEYCODE_F22; + _sapp.keycodes[0x06E] = SAPP_KEYCODE_F23; + _sapp.keycodes[0x076] = SAPP_KEYCODE_F24; + _sapp.keycodes[0x038] = SAPP_KEYCODE_LEFT_ALT; + _sapp.keycodes[0x01D] = SAPP_KEYCODE_LEFT_CONTROL; + _sapp.keycodes[0x02A] = SAPP_KEYCODE_LEFT_SHIFT; + _sapp.keycodes[0x15B] = SAPP_KEYCODE_LEFT_SUPER; + _sapp.keycodes[0x137] = SAPP_KEYCODE_PRINT_SCREEN; + _sapp.keycodes[0x138] = SAPP_KEYCODE_RIGHT_ALT; + _sapp.keycodes[0x11D] = SAPP_KEYCODE_RIGHT_CONTROL; + _sapp.keycodes[0x036] = SAPP_KEYCODE_RIGHT_SHIFT; + _sapp.keycodes[0x136] = SAPP_KEYCODE_RIGHT_SHIFT; + _sapp.keycodes[0x15C] = SAPP_KEYCODE_RIGHT_SUPER; + _sapp.keycodes[0x150] = SAPP_KEYCODE_DOWN; + _sapp.keycodes[0x14B] = SAPP_KEYCODE_LEFT; + _sapp.keycodes[0x14D] = SAPP_KEYCODE_RIGHT; + _sapp.keycodes[0x148] = SAPP_KEYCODE_UP; + _sapp.keycodes[0x052] = SAPP_KEYCODE_KP_0; + _sapp.keycodes[0x04F] = SAPP_KEYCODE_KP_1; + _sapp.keycodes[0x050] = SAPP_KEYCODE_KP_2; + _sapp.keycodes[0x051] = SAPP_KEYCODE_KP_3; + _sapp.keycodes[0x04B] = SAPP_KEYCODE_KP_4; + _sapp.keycodes[0x04C] = SAPP_KEYCODE_KP_5; + _sapp.keycodes[0x04D] = SAPP_KEYCODE_KP_6; + _sapp.keycodes[0x047] = SAPP_KEYCODE_KP_7; + _sapp.keycodes[0x048] = SAPP_KEYCODE_KP_8; + _sapp.keycodes[0x049] = SAPP_KEYCODE_KP_9; + _sapp.keycodes[0x04E] = SAPP_KEYCODE_KP_ADD; + _sapp.keycodes[0x053] = SAPP_KEYCODE_KP_DECIMAL; + _sapp.keycodes[0x135] = SAPP_KEYCODE_KP_DIVIDE; + _sapp.keycodes[0x11C] = SAPP_KEYCODE_KP_ENTER; + _sapp.keycodes[0x037] = SAPP_KEYCODE_KP_MULTIPLY; + _sapp.keycodes[0x04A] = SAPP_KEYCODE_KP_SUBTRACT; +} +#endif // _SAPP_WIN32 + +#if defined(_SAPP_WIN32) + +#if defined(SOKOL_D3D11) + +#if defined(__cplusplus) +#define _sapp_d3d11_Release(self) (self)->Release() +#define _sapp_win32_refiid(iid) iid +#else +#define _sapp_d3d11_Release(self) (self)->lpVtbl->Release(self) +#define _sapp_win32_refiid(iid) &iid +#endif + +#define _SAPP_SAFE_RELEASE(obj) if (obj) { _sapp_d3d11_Release(obj); obj=0; } + + +static const IID _sapp_IID_ID3D11Texture2D = { 0x6f15aaf2,0xd208,0x4e89, {0x9a,0xb4,0x48,0x95,0x35,0xd3,0x4f,0x9c} }; +static const IID _sapp_IID_IDXGIDevice1 = { 0x77db970f,0x6276,0x48ba, {0xba,0x28,0x07,0x01,0x43,0xb4,0x39,0x2c} }; +static const IID _sapp_IID_IDXGIFactory = { 0x7b7166ec,0x21c7,0x44ae, {0xb2,0x1a,0xc9,0xae,0x32,0x1a,0xe3,0x69} }; + +static inline HRESULT _sapp_dxgi_GetBuffer(IDXGISwapChain* self, UINT Buffer, REFIID riid, void** ppSurface) { + #if defined(__cplusplus) + return self->GetBuffer(Buffer, riid, ppSurface); + #else + return self->lpVtbl->GetBuffer(self, Buffer, riid, ppSurface); + #endif +} + +static inline HRESULT _sapp_d3d11_QueryInterface(ID3D11Device* self, REFIID riid, void** ppvObject) { + #if defined(__cplusplus) + return self->QueryInterface(riid, ppvObject); + #else + return self->lpVtbl->QueryInterface(self, riid, ppvObject); + #endif +} + +static inline HRESULT _sapp_d3d11_CreateRenderTargetView(ID3D11Device* self, ID3D11Resource *pResource, const D3D11_RENDER_TARGET_VIEW_DESC* pDesc, ID3D11RenderTargetView** ppRTView) { + #if defined(__cplusplus) + return self->CreateRenderTargetView(pResource, pDesc, ppRTView); + #else + return self->lpVtbl->CreateRenderTargetView(self, pResource, pDesc, ppRTView); + #endif +} + +static inline HRESULT _sapp_d3d11_CreateTexture2D(ID3D11Device* self, const D3D11_TEXTURE2D_DESC* pDesc, const D3D11_SUBRESOURCE_DATA* pInitialData, ID3D11Texture2D** ppTexture2D) { + #if defined(__cplusplus) + return self->CreateTexture2D(pDesc, pInitialData, ppTexture2D); + #else + return self->lpVtbl->CreateTexture2D(self, pDesc, pInitialData, ppTexture2D); + #endif +} + +static inline HRESULT _sapp_d3d11_CreateDepthStencilView(ID3D11Device* self, ID3D11Resource* pResource, const D3D11_DEPTH_STENCIL_VIEW_DESC* pDesc, ID3D11DepthStencilView** ppDepthStencilView) { + #if defined(__cplusplus) + return self->CreateDepthStencilView(pResource, pDesc, ppDepthStencilView); + #else + return self->lpVtbl->CreateDepthStencilView(self, pResource, pDesc, ppDepthStencilView); + #endif +} + +static inline HRESULT _sapp_dxgi_ResizeBuffers(IDXGISwapChain* self, UINT BufferCount, UINT Width, UINT Height, DXGI_FORMAT NewFormat, UINT SwapChainFlags) { + #if defined(__cplusplus) + return self->ResizeBuffers(BufferCount, Width, Height, NewFormat, SwapChainFlags); + #else + return self->lpVtbl->ResizeBuffers(self, BufferCount, Width, Height, NewFormat, SwapChainFlags); + #endif +} + +static inline HRESULT _sapp_dxgi_Present(IDXGISwapChain* self, UINT SyncInterval, UINT Flags) { + #if defined(__cplusplus) + return self->Present(SyncInterval, Flags); + #else + return self->lpVtbl->Present(self, SyncInterval, Flags); + #endif +} + +static inline HRESULT _sapp_dxgi_GetFrameStatistics(IDXGISwapChain* self, DXGI_FRAME_STATISTICS* pStats) { + #if defined(__cplusplus) + return self->GetFrameStatistics(pStats); + #else + return self->lpVtbl->GetFrameStatistics(self, pStats); + #endif +} + +static inline HRESULT _sapp_dxgi_SetMaximumFrameLatency(IDXGIDevice1* self, UINT MaxLatency) { + #if defined(__cplusplus) + return self->SetMaximumFrameLatency(MaxLatency); + #else + return self->lpVtbl->SetMaximumFrameLatency(self, MaxLatency); + #endif +} + +static inline HRESULT _sapp_dxgi_GetAdapter(IDXGIDevice1* self, IDXGIAdapter** pAdapter) { + #if defined(__cplusplus) + return self->GetAdapter(pAdapter); + #else + return self->lpVtbl->GetAdapter(self, pAdapter); + #endif +} + +static inline HRESULT _sapp_dxgi_GetParent(IDXGIObject* self, REFIID riid, void** ppParent) { + #if defined(__cplusplus) + return self->GetParent(riid, ppParent); + #else + return self->lpVtbl->GetParent(self, riid, ppParent); + #endif +} + +static inline HRESULT _sapp_dxgi_MakeWindowAssociation(IDXGIFactory* self, HWND WindowHandle, UINT Flags) { + #if defined(__cplusplus) + return self->MakeWindowAssociation(WindowHandle, Flags); + #else + return self->lpVtbl->MakeWindowAssociation(self, WindowHandle, Flags); + #endif +} + +_SOKOL_PRIVATE void _sapp_d3d11_create_device_and_swapchain(void) { + DXGI_SWAP_CHAIN_DESC* sc_desc = &_sapp.d3d11.swap_chain_desc; + sc_desc->BufferDesc.Width = (UINT)_sapp.framebuffer_width; + sc_desc->BufferDesc.Height = (UINT)_sapp.framebuffer_height; + sc_desc->BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; + sc_desc->BufferDesc.RefreshRate.Numerator = 60; + sc_desc->BufferDesc.RefreshRate.Denominator = 1; + sc_desc->OutputWindow = _sapp.win32.hwnd; + sc_desc->Windowed = true; + if (_sapp.win32.is_win10_or_greater) { + sc_desc->BufferCount = 2; + sc_desc->SwapEffect = (DXGI_SWAP_EFFECT) _SAPP_DXGI_SWAP_EFFECT_FLIP_DISCARD; + } else { + sc_desc->BufferCount = 1; + sc_desc->SwapEffect = DXGI_SWAP_EFFECT_DISCARD; + } + sc_desc->SampleDesc.Count = 1; + sc_desc->SampleDesc.Quality = 0; + sc_desc->BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; + UINT create_flags = D3D11_CREATE_DEVICE_SINGLETHREADED | D3D11_CREATE_DEVICE_BGRA_SUPPORT; + #if defined(SOKOL_DEBUG) + create_flags |= D3D11_CREATE_DEVICE_DEBUG; + #endif + D3D_FEATURE_LEVEL requested_feature_levels[] = { D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0 }; + D3D_FEATURE_LEVEL result_feature_level; + HRESULT hr = D3D11CreateDeviceAndSwapChain( + NULL, /* pAdapter (use default) */ + D3D_DRIVER_TYPE_HARDWARE, /* DriverType */ + NULL, /* Software */ + create_flags, /* Flags */ + requested_feature_levels, /* pFeatureLevels */ + 2, /* FeatureLevels */ + D3D11_SDK_VERSION, /* SDKVersion */ + sc_desc, /* pSwapChainDesc */ + &_sapp.d3d11.swap_chain, /* ppSwapChain */ + &_sapp.d3d11.device, /* ppDevice */ + &result_feature_level, /* pFeatureLevel */ + &_sapp.d3d11.device_context); /* ppImmediateContext */ + _SOKOL_UNUSED(hr); + #if defined(SOKOL_DEBUG) + if (!SUCCEEDED(hr)) { + // if initialization with D3D11_CREATE_DEVICE_DEBUG fails, this could be because the + // 'D3D11 debug layer' stopped working, indicated by the error message: + // === + // D3D11CreateDevice: Flags (0x2) were specified which require the D3D11 SDK Layers for Windows 10, but they are not present on the system. + // These flags must be removed, or the Windows 10 SDK must be installed. + // Flags include: D3D11_CREATE_DEVICE_DEBUG + // === + // + // ...just retry with the DEBUG flag switched off + _SAPP_ERROR(WIN32_D3D11_CREATE_DEVICE_AND_SWAPCHAIN_WITH_DEBUG_FAILED); + create_flags &= ~(UINT)D3D11_CREATE_DEVICE_DEBUG; + hr = D3D11CreateDeviceAndSwapChain( + NULL, /* pAdapter (use default) */ + D3D_DRIVER_TYPE_HARDWARE, /* DriverType */ + NULL, /* Software */ + create_flags, /* Flags */ + requested_feature_levels, /* pFeatureLevels */ + 2, /* FeatureLevels */ + D3D11_SDK_VERSION, /* SDKVersion */ + sc_desc, /* pSwapChainDesc */ + &_sapp.d3d11.swap_chain, /* ppSwapChain */ + &_sapp.d3d11.device, /* ppDevice */ + &result_feature_level, /* pFeatureLevel */ + &_sapp.d3d11.device_context); /* ppImmediateContext */ + } + #endif + SOKOL_ASSERT(SUCCEEDED(hr) && _sapp.d3d11.swap_chain && _sapp.d3d11.device && _sapp.d3d11.device_context); + + // minimize frame latency, disable Alt-Enter + hr = _sapp_d3d11_QueryInterface(_sapp.d3d11.device, _sapp_win32_refiid(_sapp_IID_IDXGIDevice1), (void**)&_sapp.d3d11.dxgi_device); + if (SUCCEEDED(hr) && _sapp.d3d11.dxgi_device) { + _sapp_dxgi_SetMaximumFrameLatency(_sapp.d3d11.dxgi_device, 1); + IDXGIAdapter* dxgi_adapter = 0; + hr = _sapp_dxgi_GetAdapter(_sapp.d3d11.dxgi_device, &dxgi_adapter); + if (SUCCEEDED(hr) && dxgi_adapter) { + IDXGIFactory* dxgi_factory = 0; + hr = _sapp_dxgi_GetParent((IDXGIObject*)dxgi_adapter, _sapp_win32_refiid(_sapp_IID_IDXGIFactory), (void**)&dxgi_factory); + if (SUCCEEDED(hr)) { + _sapp_dxgi_MakeWindowAssociation(dxgi_factory, _sapp.win32.hwnd, DXGI_MWA_NO_ALT_ENTER|DXGI_MWA_NO_PRINT_SCREEN); + _SAPP_SAFE_RELEASE(dxgi_factory); + } else { + _SAPP_ERROR(WIN32_D3D11_GET_IDXGIFACTORY_FAILED); + } + _SAPP_SAFE_RELEASE(dxgi_adapter); + } else { + _SAPP_ERROR(WIN32_D3D11_GET_IDXGIADAPTER_FAILED); + } + } else { + _SAPP_PANIC(WIN32_D3D11_QUERY_INTERFACE_IDXGIDEVICE1_FAILED); + } +} + +_SOKOL_PRIVATE void _sapp_d3d11_destroy_device_and_swapchain(void) { + _SAPP_SAFE_RELEASE(_sapp.d3d11.swap_chain); + _SAPP_SAFE_RELEASE(_sapp.d3d11.dxgi_device); + _SAPP_SAFE_RELEASE(_sapp.d3d11.device_context); + _SAPP_SAFE_RELEASE(_sapp.d3d11.device); +} + +_SOKOL_PRIVATE void _sapp_d3d11_create_default_render_target(void) { + SOKOL_ASSERT(0 == _sapp.d3d11.rt); + SOKOL_ASSERT(0 == _sapp.d3d11.rtv); + SOKOL_ASSERT(0 == _sapp.d3d11.msaa_rt); + SOKOL_ASSERT(0 == _sapp.d3d11.msaa_rtv); + SOKOL_ASSERT(0 == _sapp.d3d11.ds); + SOKOL_ASSERT(0 == _sapp.d3d11.dsv); + + HRESULT hr; _SOKOL_UNUSED(hr); + + /* view for the swapchain-created framebuffer */ + hr = _sapp_dxgi_GetBuffer(_sapp.d3d11.swap_chain, 0, _sapp_win32_refiid(_sapp_IID_ID3D11Texture2D), (void**)&_sapp.d3d11.rt); + SOKOL_ASSERT(SUCCEEDED(hr) && _sapp.d3d11.rt); + hr = _sapp_d3d11_CreateRenderTargetView(_sapp.d3d11.device, (ID3D11Resource*)_sapp.d3d11.rt, NULL, &_sapp.d3d11.rtv); + SOKOL_ASSERT(SUCCEEDED(hr) && _sapp.d3d11.rtv); + + /* common desc for MSAA and depth-stencil texture */ + _SAPP_STRUCT(D3D11_TEXTURE2D_DESC, tex_desc); + tex_desc.Width = (UINT)_sapp.framebuffer_width; + tex_desc.Height = (UINT)_sapp.framebuffer_height; + tex_desc.MipLevels = 1; + tex_desc.ArraySize = 1; + tex_desc.Usage = D3D11_USAGE_DEFAULT; + tex_desc.BindFlags = D3D11_BIND_RENDER_TARGET; + tex_desc.SampleDesc.Count = (UINT) _sapp.sample_count; + tex_desc.SampleDesc.Quality = (UINT) (_sapp.sample_count > 1 ? D3D11_STANDARD_MULTISAMPLE_PATTERN : 0); + + /* create MSAA texture and view if antialiasing requested */ + if (_sapp.sample_count > 1) { + tex_desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; + hr = _sapp_d3d11_CreateTexture2D(_sapp.d3d11.device, &tex_desc, NULL, &_sapp.d3d11.msaa_rt); + SOKOL_ASSERT(SUCCEEDED(hr) && _sapp.d3d11.msaa_rt); + hr = _sapp_d3d11_CreateRenderTargetView(_sapp.d3d11.device, (ID3D11Resource*)_sapp.d3d11.msaa_rt, NULL, &_sapp.d3d11.msaa_rtv); + SOKOL_ASSERT(SUCCEEDED(hr) && _sapp.d3d11.msaa_rtv); + } + + /* texture and view for the depth-stencil-surface */ + tex_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; + tex_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL; + hr = _sapp_d3d11_CreateTexture2D(_sapp.d3d11.device, &tex_desc, NULL, &_sapp.d3d11.ds); + SOKOL_ASSERT(SUCCEEDED(hr) && _sapp.d3d11.ds); + hr = _sapp_d3d11_CreateDepthStencilView(_sapp.d3d11.device, (ID3D11Resource*)_sapp.d3d11.ds, NULL, &_sapp.d3d11.dsv); + SOKOL_ASSERT(SUCCEEDED(hr) && _sapp.d3d11.dsv); +} + +_SOKOL_PRIVATE void _sapp_d3d11_destroy_default_render_target(void) { + _SAPP_SAFE_RELEASE(_sapp.d3d11.rt); + _SAPP_SAFE_RELEASE(_sapp.d3d11.rtv); + _SAPP_SAFE_RELEASE(_sapp.d3d11.msaa_rt); + _SAPP_SAFE_RELEASE(_sapp.d3d11.msaa_rtv); + _SAPP_SAFE_RELEASE(_sapp.d3d11.ds); + _SAPP_SAFE_RELEASE(_sapp.d3d11.dsv); +} + +_SOKOL_PRIVATE void _sapp_d3d11_resize_default_render_target(void) { + if (_sapp.d3d11.swap_chain) { + _sapp_d3d11_destroy_default_render_target(); + _sapp_dxgi_ResizeBuffers(_sapp.d3d11.swap_chain, _sapp.d3d11.swap_chain_desc.BufferCount, (UINT)_sapp.framebuffer_width, (UINT)_sapp.framebuffer_height, DXGI_FORMAT_B8G8R8A8_UNORM, 0); + _sapp_d3d11_create_default_render_target(); + } +} + +_SOKOL_PRIVATE void _sapp_d3d11_present(bool do_not_wait) { + UINT flags = 0; + if (_sapp.win32.is_win10_or_greater && do_not_wait) { + /* this hack/workaround somewhat improves window-movement and -sizing + responsiveness when rendering is controlled via WM_TIMER during window + move and resize on NVIDIA cards on Win10 with recent drivers. + */ + flags = DXGI_PRESENT_DO_NOT_WAIT; + } + _sapp_dxgi_Present(_sapp.d3d11.swap_chain, (UINT)_sapp.swap_interval, flags); +} + +#endif /* SOKOL_D3D11 */ + +#if defined(SOKOL_GLCORE) +_SOKOL_PRIVATE void _sapp_wgl_init(void) { + _sapp.wgl.opengl32 = LoadLibraryA("opengl32.dll"); + if (!_sapp.wgl.opengl32) { + _SAPP_PANIC(WIN32_LOAD_OPENGL32_DLL_FAILED); + } + SOKOL_ASSERT(_sapp.wgl.opengl32); + _sapp.wgl.CreateContext = (PFN_wglCreateContext)(void*) GetProcAddress(_sapp.wgl.opengl32, "wglCreateContext"); + SOKOL_ASSERT(_sapp.wgl.CreateContext); + _sapp.wgl.DeleteContext = (PFN_wglDeleteContext)(void*) GetProcAddress(_sapp.wgl.opengl32, "wglDeleteContext"); + SOKOL_ASSERT(_sapp.wgl.DeleteContext); + _sapp.wgl.GetProcAddress = (PFN_wglGetProcAddress)(void*) GetProcAddress(_sapp.wgl.opengl32, "wglGetProcAddress"); + SOKOL_ASSERT(_sapp.wgl.GetProcAddress); + _sapp.wgl.GetCurrentDC = (PFN_wglGetCurrentDC)(void*) GetProcAddress(_sapp.wgl.opengl32, "wglGetCurrentDC"); + SOKOL_ASSERT(_sapp.wgl.GetCurrentDC); + _sapp.wgl.MakeCurrent = (PFN_wglMakeCurrent)(void*) GetProcAddress(_sapp.wgl.opengl32, "wglMakeCurrent"); + SOKOL_ASSERT(_sapp.wgl.MakeCurrent); + _sapp.wgl.GetIntegerv = (void(WINAPI*)(uint32_t, int32_t*)) GetProcAddress(_sapp.wgl.opengl32, "glGetIntegerv"); + SOKOL_ASSERT(_sapp.wgl.GetIntegerv); + + _sapp.wgl.msg_hwnd = CreateWindowExW(WS_EX_OVERLAPPEDWINDOW, + L"SOKOLAPP", + L"sokol-app message window", + WS_CLIPSIBLINGS|WS_CLIPCHILDREN, + 0, 0, 1, 1, + NULL, NULL, + GetModuleHandleW(NULL), + NULL); + if (!_sapp.wgl.msg_hwnd) { + _SAPP_PANIC(WIN32_CREATE_HELPER_WINDOW_FAILED); + } + SOKOL_ASSERT(_sapp.wgl.msg_hwnd); + ShowWindow(_sapp.wgl.msg_hwnd, SW_HIDE); + MSG msg; + while (PeekMessageW(&msg, _sapp.wgl.msg_hwnd, 0, 0, PM_REMOVE)) { + TranslateMessage(&msg); + DispatchMessageW(&msg); + } + _sapp.wgl.msg_dc = GetDC(_sapp.wgl.msg_hwnd); + if (!_sapp.wgl.msg_dc) { + _SAPP_PANIC(WIN32_HELPER_WINDOW_GETDC_FAILED); + } +} + +_SOKOL_PRIVATE void _sapp_wgl_shutdown(void) { + SOKOL_ASSERT(_sapp.wgl.opengl32 && _sapp.wgl.msg_hwnd); + DestroyWindow(_sapp.wgl.msg_hwnd); _sapp.wgl.msg_hwnd = 0; + FreeLibrary(_sapp.wgl.opengl32); _sapp.wgl.opengl32 = 0; +} + +_SOKOL_PRIVATE bool _sapp_wgl_has_ext(const char* ext, const char* extensions) { + SOKOL_ASSERT(ext && extensions); + const char* start = extensions; + while (true) { + const char* where = strstr(start, ext); + if (!where) { + return false; + } + const char* terminator = where + strlen(ext); + if ((where == start) || (*(where - 1) == ' ')) { + if (*terminator == ' ' || *terminator == '\0') { + break; + } + } + start = terminator; + } + return true; +} + +_SOKOL_PRIVATE bool _sapp_wgl_ext_supported(const char* ext) { + SOKOL_ASSERT(ext); + if (_sapp.wgl.GetExtensionsStringEXT) { + const char* extensions = _sapp.wgl.GetExtensionsStringEXT(); + if (extensions) { + if (_sapp_wgl_has_ext(ext, extensions)) { + return true; + } + } + } + if (_sapp.wgl.GetExtensionsStringARB) { + const char* extensions = _sapp.wgl.GetExtensionsStringARB(_sapp.wgl.GetCurrentDC()); + if (extensions) { + if (_sapp_wgl_has_ext(ext, extensions)) { + return true; + } + } + } + return false; +} + +_SOKOL_PRIVATE void _sapp_wgl_load_extensions(void) { + SOKOL_ASSERT(_sapp.wgl.msg_dc); + _SAPP_STRUCT(PIXELFORMATDESCRIPTOR, pfd); + pfd.nSize = sizeof(pfd); + pfd.nVersion = 1; + pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; + pfd.iPixelType = PFD_TYPE_RGBA; + pfd.cColorBits = 24; + if (!SetPixelFormat(_sapp.wgl.msg_dc, ChoosePixelFormat(_sapp.wgl.msg_dc, &pfd), &pfd)) { + _SAPP_PANIC(WIN32_DUMMY_CONTEXT_SET_PIXELFORMAT_FAILED); + } + HGLRC rc = _sapp.wgl.CreateContext(_sapp.wgl.msg_dc); + if (!rc) { + _SAPP_PANIC(WIN32_CREATE_DUMMY_CONTEXT_FAILED); + } + if (!_sapp.wgl.MakeCurrent(_sapp.wgl.msg_dc, rc)) { + _SAPP_PANIC(WIN32_DUMMY_CONTEXT_MAKE_CURRENT_FAILED); + } + _sapp.wgl.GetExtensionsStringEXT = (PFNWGLGETEXTENSIONSSTRINGEXTPROC)(void*) _sapp.wgl.GetProcAddress("wglGetExtensionsStringEXT"); + _sapp.wgl.GetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)(void*) _sapp.wgl.GetProcAddress("wglGetExtensionsStringARB"); + _sapp.wgl.CreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)(void*) _sapp.wgl.GetProcAddress("wglCreateContextAttribsARB"); + _sapp.wgl.SwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)(void*) _sapp.wgl.GetProcAddress("wglSwapIntervalEXT"); + _sapp.wgl.GetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)(void*) _sapp.wgl.GetProcAddress("wglGetPixelFormatAttribivARB"); + _sapp.wgl.arb_multisample = _sapp_wgl_ext_supported("WGL_ARB_multisample"); + _sapp.wgl.arb_create_context = _sapp_wgl_ext_supported("WGL_ARB_create_context"); + _sapp.wgl.arb_create_context_profile = _sapp_wgl_ext_supported("WGL_ARB_create_context_profile"); + _sapp.wgl.ext_swap_control = _sapp_wgl_ext_supported("WGL_EXT_swap_control"); + _sapp.wgl.arb_pixel_format = _sapp_wgl_ext_supported("WGL_ARB_pixel_format"); + _sapp.wgl.MakeCurrent(_sapp.wgl.msg_dc, 0); + _sapp.wgl.DeleteContext(rc); +} + +_SOKOL_PRIVATE int _sapp_wgl_attrib(int pixel_format, int attrib) { + SOKOL_ASSERT(_sapp.wgl.arb_pixel_format); + int value = 0; + if (!_sapp.wgl.GetPixelFormatAttribivARB(_sapp.win32.dc, pixel_format, 0, 1, &attrib, &value)) { + _SAPP_PANIC(WIN32_GET_PIXELFORMAT_ATTRIB_FAILED); + } + return value; +} + +_SOKOL_PRIVATE void _sapp_wgl_attribiv(int pixel_format, int num_attribs, const int* attribs, int* results) { + SOKOL_ASSERT(_sapp.wgl.arb_pixel_format); + if (!_sapp.wgl.GetPixelFormatAttribivARB(_sapp.win32.dc, pixel_format, 0, num_attribs, attribs, results)) { + _SAPP_PANIC(WIN32_GET_PIXELFORMAT_ATTRIB_FAILED); + } +} + +_SOKOL_PRIVATE int _sapp_wgl_find_pixel_format(void) { + SOKOL_ASSERT(_sapp.win32.dc); + SOKOL_ASSERT(_sapp.wgl.arb_pixel_format); + + #define _sapp_wgl_num_query_tags (12) + const int query_tags[_sapp_wgl_num_query_tags] = { + WGL_SUPPORT_OPENGL_ARB, + WGL_DRAW_TO_WINDOW_ARB, + WGL_PIXEL_TYPE_ARB, + WGL_ACCELERATION_ARB, + WGL_DOUBLE_BUFFER_ARB, + WGL_RED_BITS_ARB, + WGL_GREEN_BITS_ARB, + WGL_BLUE_BITS_ARB, + WGL_ALPHA_BITS_ARB, + WGL_DEPTH_BITS_ARB, + WGL_STENCIL_BITS_ARB, + WGL_SAMPLES_ARB, + }; + const int result_support_opengl_index = 0; + const int result_draw_to_window_index = 1; + const int result_pixel_type_index = 2; + const int result_acceleration_index = 3; + const int result_double_buffer_index = 4; + const int result_red_bits_index = 5; + const int result_green_bits_index = 6; + const int result_blue_bits_index = 7; + const int result_alpha_bits_index = 8; + const int result_depth_bits_index = 9; + const int result_stencil_bits_index = 10; + const int result_samples_index = 11; + + int query_results[_sapp_wgl_num_query_tags] = {0}; + // Drop the last item if multisample extension is not supported. + // If in future querying with multiple extensions, will have to shuffle index values to have active extensions on the end. + int query_count = _sapp_wgl_num_query_tags; + if (!_sapp.wgl.arb_multisample) { + query_count = _sapp_wgl_num_query_tags - 1; + } + + int native_count = _sapp_wgl_attrib(1, WGL_NUMBER_PIXEL_FORMATS_ARB); + + _sapp_gl_fbconfig desired; + _sapp_gl_init_fbconfig(&desired); + desired.red_bits = 8; + desired.green_bits = 8; + desired.blue_bits = 8; + desired.alpha_bits = 8; + desired.depth_bits = 24; + desired.stencil_bits = 8; + desired.doublebuffer = true; + desired.samples = (_sapp.sample_count > 1) ? _sapp.sample_count : 0; + + int pixel_format = 0; + + _sapp_gl_fbselect fbselect; + _sapp_gl_init_fbselect(&fbselect); + for (int i = 0; i < native_count; i++) { + const int n = i + 1; + _sapp_wgl_attribiv(n, query_count, query_tags, query_results); + + if (query_results[result_support_opengl_index] == 0 + || query_results[result_draw_to_window_index] == 0 + || query_results[result_pixel_type_index] != WGL_TYPE_RGBA_ARB + || query_results[result_acceleration_index] == WGL_NO_ACCELERATION_ARB) + { + continue; + } + + _SAPP_STRUCT(_sapp_gl_fbconfig, u); + u.red_bits = query_results[result_red_bits_index]; + u.green_bits = query_results[result_green_bits_index]; + u.blue_bits = query_results[result_blue_bits_index]; + u.alpha_bits = query_results[result_alpha_bits_index]; + u.depth_bits = query_results[result_depth_bits_index]; + u.stencil_bits = query_results[result_stencil_bits_index]; + u.doublebuffer = 0 != query_results[result_double_buffer_index]; + u.samples = query_results[result_samples_index]; // NOTE: If arb_multisample is not supported - just takes the default 0 + + // Test if this pixel format is better than the previous one + if (_sapp_gl_select_fbconfig(&fbselect, &desired, &u)) { + pixel_format = (uintptr_t)n; + + // Early exit if matching as good as possible + if (fbselect.best_match) { + break; + } + } + } + + return pixel_format; +} + +_SOKOL_PRIVATE void _sapp_wgl_create_context(void) { + int pixel_format = _sapp_wgl_find_pixel_format(); + if (0 == pixel_format) { + _SAPP_PANIC(WIN32_WGL_FIND_PIXELFORMAT_FAILED); + } + PIXELFORMATDESCRIPTOR pfd; + if (!DescribePixelFormat(_sapp.win32.dc, pixel_format, sizeof(pfd), &pfd)) { + _SAPP_PANIC(WIN32_WGL_DESCRIBE_PIXELFORMAT_FAILED); + } + if (!SetPixelFormat(_sapp.win32.dc, pixel_format, &pfd)) { + _SAPP_PANIC(WIN32_WGL_SET_PIXELFORMAT_FAILED); + } + if (!_sapp.wgl.arb_create_context) { + _SAPP_PANIC(WIN32_WGL_ARB_CREATE_CONTEXT_REQUIRED); + } + if (!_sapp.wgl.arb_create_context_profile) { + _SAPP_PANIC(WIN32_WGL_ARB_CREATE_CONTEXT_PROFILE_REQUIRED); + } + const int attrs[] = { + WGL_CONTEXT_MAJOR_VERSION_ARB, _sapp.desc.gl.major_version, + WGL_CONTEXT_MINOR_VERSION_ARB, _sapp.desc.gl.minor_version, +#if defined(SOKOL_DEBUG) + WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB | WGL_CONTEXT_DEBUG_BIT_ARB, +#else + WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, +#endif + WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, + 0, 0 + }; + _sapp.wgl.gl_ctx = _sapp.wgl.CreateContextAttribsARB(_sapp.win32.dc, 0, attrs); + if (!_sapp.wgl.gl_ctx) { + const DWORD err = GetLastError(); + if (err == (0xc0070000 | ERROR_INVALID_VERSION_ARB)) { + _SAPP_PANIC(WIN32_WGL_OPENGL_VERSION_NOT_SUPPORTED); + } else if (err == (0xc0070000 | ERROR_INVALID_PROFILE_ARB)) { + _SAPP_PANIC(WIN32_WGL_OPENGL_PROFILE_NOT_SUPPORTED); + } else if (err == (0xc0070000 | ERROR_INCOMPATIBLE_DEVICE_CONTEXTS_ARB)) { + _SAPP_PANIC(WIN32_WGL_INCOMPATIBLE_DEVICE_CONTEXT); + } else { + _SAPP_PANIC(WIN32_WGL_CREATE_CONTEXT_ATTRIBS_FAILED_OTHER); + } + } + _sapp.wgl.MakeCurrent(_sapp.win32.dc, _sapp.wgl.gl_ctx); + if (_sapp.wgl.ext_swap_control) { + /* FIXME: DwmIsCompositionEnabled() (see GLFW) */ + _sapp.wgl.SwapIntervalEXT(_sapp.swap_interval); + } + const uint32_t gl_framebuffer_binding = 0x8CA6; + _sapp.wgl.GetIntegerv(gl_framebuffer_binding, (int32_t*)&_sapp.gl.framebuffer); +} + +_SOKOL_PRIVATE void _sapp_wgl_destroy_context(void) { + SOKOL_ASSERT(_sapp.wgl.gl_ctx); + _sapp.wgl.DeleteContext(_sapp.wgl.gl_ctx); + _sapp.wgl.gl_ctx = 0; +} + +_SOKOL_PRIVATE void _sapp_wgl_swap_buffers(void) { + SOKOL_ASSERT(_sapp.win32.dc); + /* FIXME: DwmIsCompositionEnabled? (see GLFW) */ + SwapBuffers(_sapp.win32.dc); +} +#endif /* SOKOL_GLCORE */ + +_SOKOL_PRIVATE bool _sapp_win32_wide_to_utf8(const wchar_t* src, char* dst, int dst_num_bytes) { + SOKOL_ASSERT(src && dst && (dst_num_bytes > 1)); + _sapp_clear(dst, (size_t)dst_num_bytes); + const int bytes_needed = WideCharToMultiByte(CP_UTF8, 0, src, -1, NULL, 0, NULL, NULL); + if (bytes_needed <= dst_num_bytes) { + WideCharToMultiByte(CP_UTF8, 0, src, -1, dst, dst_num_bytes, NULL, NULL); + return true; + } else { + return false; + } +} + +/* updates current window and framebuffer size from the window's client rect, returns true if size has changed */ +_SOKOL_PRIVATE bool _sapp_win32_update_dimensions(void) { + RECT rect; + if (GetClientRect(_sapp.win32.hwnd, &rect)) { + float window_width = (float)(rect.right - rect.left) / _sapp.win32.dpi.window_scale; + float window_height = (float)(rect.bottom - rect.top) / _sapp.win32.dpi.window_scale; + if ((window_width == 0.0f) && (window_height == 0.0f)) { + // both width and height being zero means the window is minimized, in that + // case pretend that the size didn't change (this is consistent with other + // window systems) - also see: https://github.com/floooh/sokol/issues/1465 + return false; + } + _sapp.window_width = _sapp_roundf_gzero(window_width); + _sapp.window_height = _sapp_roundf_gzero(window_height); + // NOTE: on Vulkan, updating the framebuffer dimensions and firing the resize-event + // is handled entirely by the swapchain management code + #if !defined(SOKOL_VULKAN) + int fb_width = _sapp_roundf_gzero(window_width * _sapp.win32.dpi.content_scale); + int fb_height = _sapp_roundf_gzero(window_height * _sapp.win32.dpi.content_scale); + if ((fb_width != _sapp.framebuffer_width) || (fb_height != _sapp.framebuffer_height)) { + _sapp.framebuffer_width = fb_width; + _sapp.framebuffer_height = fb_height; + return true; + } + #endif + } else { + _sapp.window_width = _sapp.window_height = 1; + #if !defined(SOKOL_VULKAN) + _sapp.framebuffer_width = _sapp.framebuffer_height = 1; + #endif + } + return false; +} + +_SOKOL_PRIVATE void _sapp_win32_set_fullscreen(bool fullscreen, UINT swp_flags) { + HMONITOR monitor = MonitorFromWindow(_sapp.win32.hwnd, MONITOR_DEFAULTTONEAREST); + _SAPP_STRUCT(MONITORINFO, minfo); + minfo.cbSize = sizeof(MONITORINFO); + GetMonitorInfo(monitor, &minfo); + const RECT mr = minfo.rcMonitor; + const int monitor_w = mr.right - mr.left; + const int monitor_h = mr.bottom - mr.top; + + const DWORD win_ex_style = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; + DWORD win_style; + RECT rect = { 0, 0, 0, 0 }; + + _sapp.fullscreen = fullscreen; + if (!_sapp.fullscreen) { + win_style = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SIZEBOX; + rect = _sapp.win32.stored_window_rect; + } else { + GetWindowRect(_sapp.win32.hwnd, &_sapp.win32.stored_window_rect); + win_style = WS_POPUP | WS_SYSMENU | WS_VISIBLE; + rect.left = mr.left; + rect.top = mr.top; + rect.right = rect.left + monitor_w; + rect.bottom = rect.top + monitor_h; + AdjustWindowRectEx(&rect, win_style, FALSE, win_ex_style); + } + const int win_w = rect.right - rect.left; + const int win_h = rect.bottom - rect.top; + const int win_x = rect.left; + const int win_y = rect.top; + SetWindowLongPtr(_sapp.win32.hwnd, GWL_STYLE, win_style); + SetWindowPos(_sapp.win32.hwnd, HWND_TOP, win_x, win_y, win_w, win_h, swp_flags | SWP_FRAMECHANGED); +} + +_SOKOL_PRIVATE void _sapp_win32_toggle_fullscreen(void) { + _sapp_win32_set_fullscreen(!_sapp.fullscreen, SWP_SHOWWINDOW); +} + +_SOKOL_PRIVATE void _sapp_win32_init_cursor(sapp_mouse_cursor cursor) { + SOKOL_ASSERT((cursor >= 0) && (cursor < _SAPP_MOUSECURSOR_NUM)); + // NOTE: the OCR_* constants are only defined if OEMRESOURCE is defined + // before windows.h is included, but we can't guarantee that because + // the sokol_app.h implementation may be included with other implementations + // in the same compilation unit + int id = 0; + switch (cursor) { + case SAPP_MOUSECURSOR_ARROW: id = 32512; break; // OCR_NORMAL + case SAPP_MOUSECURSOR_IBEAM: id = 32513; break; // OCR_IBEAM + case SAPP_MOUSECURSOR_CROSSHAIR: id = 32515; break; // OCR_CROSS + case SAPP_MOUSECURSOR_POINTING_HAND: id = 32649; break; // OCR_HAND + case SAPP_MOUSECURSOR_RESIZE_EW: id = 32644; break; // OCR_SIZEWE + case SAPP_MOUSECURSOR_RESIZE_NS: id = 32645; break; // OCR_SIZENS + case SAPP_MOUSECURSOR_RESIZE_NWSE: id = 32642; break; // OCR_SIZENWSE + case SAPP_MOUSECURSOR_RESIZE_NESW: id = 32643; break; // OCR_SIZENESW + case SAPP_MOUSECURSOR_RESIZE_ALL: id = 32646; break; // OCR_SIZEALL + case SAPP_MOUSECURSOR_NOT_ALLOWED: id = 32648; break; // OCR_NO + default: break; + } + if (id != 0) { + _sapp.win32.standard_cursors[cursor] = (HCURSOR)LoadImageW(NULL, MAKEINTRESOURCEW(id), IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE|LR_SHARED); + } + // fallback: default cursor + if (0 == _sapp.win32.standard_cursors[cursor]) { + // 32512 => IDC_ARROW + _sapp.win32.standard_cursors[cursor] = LoadCursorW(NULL, MAKEINTRESOURCEW(32512)); + } + SOKOL_ASSERT(0 != _sapp.win32.standard_cursors[cursor]); +} + +_SOKOL_PRIVATE void _sapp_win32_init_cursors(void) { + for (int i = 0; i < _SAPP_MOUSECURSOR_NUM; i++) { + _sapp_win32_init_cursor((sapp_mouse_cursor)i); + } +} + +_SOKOL_PRIVATE bool _sapp_win32_cursor_in_content_area(void) { + POINT pos; + if (!GetCursorPos(&pos)) { + return false; + } + if (WindowFromPoint(pos) != _sapp.win32.hwnd) { + return false; + } + RECT area; + GetClientRect(_sapp.win32.hwnd, &area); + ClientToScreen(_sapp.win32.hwnd, (POINT*)&area.left); + ClientToScreen(_sapp.win32.hwnd, (POINT*)&area.right); + return PtInRect(&area, pos) == TRUE; +} + +_SOKOL_PRIVATE void _sapp_win32_update_cursor(sapp_mouse_cursor cursor, bool shown, bool skip_area_test) { + SOKOL_ASSERT((cursor >= 0) && (cursor < _SAPP_MOUSECURSOR_NUM)); + + // NOTE: when called from WM_SETCURSOR, the area test would be redundant + if (!skip_area_test) { + if (!_sapp_win32_cursor_in_content_area()) { + return; + } + } + HCURSOR cursor_handle = NULL; + if (shown) { + if (_sapp.custom_cursor_bound[cursor]) { + SOKOL_ASSERT(_sapp.win32.custom_cursors[cursor]); + cursor_handle = _sapp.win32.custom_cursors[cursor]; + SOKOL_ASSERT(0 != cursor_handle); + } else { + cursor_handle = _sapp.win32.standard_cursors[cursor]; + SOKOL_ASSERT(0 != cursor_handle); + } + } + SetCursor(cursor_handle); +} + +_SOKOL_PRIVATE void _sapp_win32_capture_mouse(uint8_t btn_mask) { + if (0 == _sapp.win32.mouse.capture_mask) { + SetCapture(_sapp.win32.hwnd); + } + _sapp.win32.mouse.capture_mask |= btn_mask; +} + +_SOKOL_PRIVATE void _sapp_win32_release_mouse(uint8_t btn_mask) { + if (0 != _sapp.win32.mouse.capture_mask) { + _sapp.win32.mouse.capture_mask &= ~btn_mask; + if (0 == _sapp.win32.mouse.capture_mask) { + ReleaseCapture(); + } + } +} + +_SOKOL_PRIVATE bool _sapp_win32_is_foreground_window(void) { + return _sapp.win32.hwnd == GetForegroundWindow(); +} + +_SOKOL_PRIVATE void _sapp_win32_lock_mouse(bool lock) { + _sapp.win32.mouse.requested_lock = lock; +} + +_SOKOL_PRIVATE void _sapp_win32_free_raw_input_data(void) { + if (_sapp.win32.raw_input_data.ptr) { + _sapp_free(_sapp.win32.raw_input_data.ptr); + _sapp.win32.raw_input_data.ptr = 0; + _sapp.win32.raw_input_data.size = 0; + } +} + +_SOKOL_PRIVATE void _sapp_win32_alloc_raw_input_data(size_t size) { + SOKOL_ASSERT(!_sapp.win32.raw_input_data.ptr); + SOKOL_ASSERT(size > 0); + _sapp.win32.raw_input_data.ptr = _sapp_malloc(size); + _sapp.win32.raw_input_data.size = size; + SOKOL_ASSERT(_sapp.win32.raw_input_data.ptr); +} + +_SOKOL_PRIVATE void* _sapp_win32_ensure_raw_input_data(size_t required_size) { + if (required_size > _sapp.win32.raw_input_data.size) { + _sapp_win32_free_raw_input_data(); + _sapp_win32_alloc_raw_input_data(required_size); + } + // we expect that malloc() returns at least 8-byte aligned memory + SOKOL_ASSERT((((uintptr_t)_sapp.win32.raw_input_data.ptr) & 7) == 0); + return _sapp.win32.raw_input_data.ptr; +} + +_SOKOL_PRIVATE void _sapp_win32_do_lock_mouse(void) { + _sapp.mouse.locked = true; + + // hide mouse cursor (NOTE: this maintains a hidden counter, but since + // only mouse-lock uses ShowCursor this doesn't matter) + ShowCursor(FALSE); + + // reset dx/dy and release any active mouse capture + _sapp.mouse.dx = 0.0f; + _sapp.mouse.dy = 0.0f; + _sapp_win32_release_mouse(0xFF); + + // store current mouse position so that it can be restored when unlocked + POINT pos; + if (GetCursorPos(&pos)) { + _sapp.win32.mouse.lock.pos_valid = true; + _sapp.win32.mouse.lock.pos_x = pos.x; + _sapp.win32.mouse.lock.pos_y = pos.y; + } else { + _sapp.win32.mouse.lock.pos_valid = false; + } + + // while mouse is locked, restrict cursor movement to the client + // rectangle so that we don't loose any mouse movement events + RECT client_rect; + GetClientRect(_sapp.win32.hwnd, &client_rect); + POINT mid_point; + mid_point.x = (client_rect.right - client_rect.left) / 2; + mid_point.y = (client_rect.bottom - client_rect.top) / 2; + ClientToScreen(_sapp.win32.hwnd, &mid_point); + RECT clip_rect; + clip_rect.left = clip_rect.right = mid_point.x; + clip_rect.top = clip_rect.bottom = mid_point.y; + ClipCursor(&clip_rect); + + // enable raw input for mouse, starts sending WM_INPUT messages to WinProc (see GLFW) + const RAWINPUTDEVICE rid = { + 0x01, // usUsagePage: HID_USAGE_PAGE_GENERIC + 0x02, // usUsage: HID_USAGE_GENERIC_MOUSE + 0, // dwFlags + _sapp.win32.hwnd // hwndTarget + }; + if (!RegisterRawInputDevices(&rid, 1, sizeof(rid))) { + _SAPP_ERROR(WIN32_REGISTER_RAW_INPUT_DEVICES_FAILED_MOUSE_LOCK); + } + // in case the raw mouse device only supports absolute position reporting, + // we need to skip the dx/dy compution for the first WM_INPUT event + _sapp.win32.mouse.raw_input.pos_valid = false; +} + +_SOKOL_PRIVATE void _sapp_win32_do_unlock_mouse(void) { + _sapp.mouse.locked = false; + + // make mouse cursor visible + ShowCursor(TRUE); + + // reset dx/dy and release any active mouse capture + _sapp.mouse.dx = 0.0f; + _sapp.mouse.dy = 0.0f; + _sapp_win32_release_mouse(0xFF); + + // disable raw input for mouse + const RAWINPUTDEVICE rid = { 0x01, 0x02, RIDEV_REMOVE, NULL }; + if (!RegisterRawInputDevices(&rid, 1, sizeof(rid))) { + _SAPP_ERROR(WIN32_REGISTER_RAW_INPUT_DEVICES_FAILED_MOUSE_UNLOCK); + } + + // unrestrict mouse movement + ClipCursor(NULL); + + // restore the 'pre-locked' mouse position + if (_sapp.win32.mouse.lock.pos_valid) { + SetCursorPos(_sapp.win32.mouse.lock.pos_x, _sapp.win32.mouse.lock.pos_y); + _sapp.win32.mouse.lock.pos_valid = false; + } +} + +_SOKOL_PRIVATE void _sapp_win32_update_mouse_lock(void) { + // mouse lock can only be active when we're the active window + if (!_sapp_win32_is_foreground_window()) { + // unlock mouse if currently locked + if (_sapp.mouse.locked) { + _sapp_win32_do_unlock_mouse(); + } + return; + } + + // nothing to do if requested lock state matches current lock state + const bool lock = _sapp.win32.mouse.requested_lock; + if (lock == _sapp.mouse.locked) { + return; + } + + // otherwise change into desired state + if (lock) { + _sapp_win32_do_lock_mouse(); + } else { + _sapp_win32_do_unlock_mouse(); + } +} + +_SOKOL_PRIVATE bool _sapp_win32_update_monitor(void) { + const HMONITOR cur_monitor = MonitorFromWindow(_sapp.win32.hwnd, MONITOR_DEFAULTTONULL); + if (cur_monitor != _sapp.win32.hmonitor) { + _sapp.win32.hmonitor = cur_monitor; + return true; + } else { + return false; + } +} + +_SOKOL_PRIVATE uint32_t _sapp_win32_mods(void) { + uint32_t mods = 0; + if (GetKeyState(VK_SHIFT) & (1<<15)) { + mods |= SAPP_MODIFIER_SHIFT; + } + if (GetKeyState(VK_CONTROL) & (1<<15)) { + mods |= SAPP_MODIFIER_CTRL; + } + if (GetKeyState(VK_MENU) & (1<<15)) { + mods |= SAPP_MODIFIER_ALT; + } + if ((GetKeyState(VK_LWIN) | GetKeyState(VK_RWIN)) & (1<<15)) { + mods |= SAPP_MODIFIER_SUPER; + } + const bool swapped = (TRUE == GetSystemMetrics(SM_SWAPBUTTON)); + if (GetAsyncKeyState(VK_LBUTTON)) { + mods |= swapped ? SAPP_MODIFIER_RMB : SAPP_MODIFIER_LMB; + } + if (GetAsyncKeyState(VK_RBUTTON)) { + mods |= swapped ? SAPP_MODIFIER_LMB : SAPP_MODIFIER_RMB; + } + if (GetAsyncKeyState(VK_MBUTTON)) { + mods |= SAPP_MODIFIER_MMB; + } + return mods; +} + +_SOKOL_PRIVATE void _sapp_win32_mouse_update(LPARAM lParam) { + if (!_sapp.mouse.locked) { + const float new_x = (float)GET_X_LPARAM(lParam) * _sapp.win32.dpi.mouse_scale; + const float new_y = (float)GET_Y_LPARAM(lParam) * _sapp.win32.dpi.mouse_scale; + if (_sapp.mouse.pos_valid) { + // don't update dx/dy in the very first event + _sapp.mouse.dx = new_x - _sapp.mouse.x; + _sapp.mouse.dy = new_y - _sapp.mouse.y; + } + _sapp.mouse.x = new_x; + _sapp.mouse.y = new_y; + _sapp.mouse.pos_valid = true; + } +} + +_SOKOL_PRIVATE void _sapp_win32_mouse_event(sapp_event_type type, sapp_mousebutton btn) { + if (_sapp_events_enabled()) { + _sapp_init_event(type); + _sapp.event.modifiers = _sapp_win32_mods(); + _sapp.event.mouse_button = btn; + _sapp_call_event(&_sapp.event); + } +} + +_SOKOL_PRIVATE void _sapp_win32_scroll_event(float x, float y) { + if (_sapp_events_enabled()) { + _sapp_init_event(SAPP_EVENTTYPE_MOUSE_SCROLL); + _sapp.event.modifiers = _sapp_win32_mods(); + _sapp.event.scroll_x = x; + _sapp.event.scroll_y = y; + _sapp_call_event(&_sapp.event); + } +} + +_SOKOL_PRIVATE void _sapp_win32_key_event(sapp_event_type type, int vk, bool repeat) { + if (_sapp_events_enabled() && (vk < SAPP_MAX_KEYCODES)) { + _sapp_init_event(type); + _sapp.event.modifiers = _sapp_win32_mods(); + _sapp.event.key_code = _sapp.keycodes[vk]; + _sapp.event.key_repeat = repeat; + _sapp_call_event(&_sapp.event); + /* check if a CLIPBOARD_PASTED event must be sent too */ + if (_sapp.clipboard.enabled && + (type == SAPP_EVENTTYPE_KEY_DOWN) && + (_sapp.event.modifiers == SAPP_MODIFIER_CTRL) && + (_sapp.event.key_code == SAPP_KEYCODE_V)) + { + _sapp_init_event(SAPP_EVENTTYPE_CLIPBOARD_PASTED); + _sapp_call_event(&_sapp.event); + } + } +} + +_SOKOL_PRIVATE void _sapp_win32_char_event(uint32_t c, bool repeat) { + if (_sapp_events_enabled() && (c >= 32)) { + if (c >= 0xD800 && c <= 0xDBFF) { + _sapp.win32.surrogate = (WCHAR)c - 0xD800; + } else { + if (c > 0xDC00 && c <= 0xDFFF) { + c = (uint32_t)(_sapp.win32.surrogate) << 10 | (c - 0xDC00); + c += 0x10000; + _sapp.win32.surrogate = 0; + } + _sapp_init_event(SAPP_EVENTTYPE_CHAR); + _sapp.event.modifiers = _sapp_win32_mods(); + _sapp.event.char_code = c; + _sapp.event.key_repeat = repeat; + _sapp_call_event(&_sapp.event); + } + } +} + +_SOKOL_PRIVATE void _sapp_win32_dpi_changed(HWND hWnd, LPRECT proposed_win_rect) { + if (!_sapp.win32.dpi.aware) { + return; + } + HINSTANCE user32 = LoadLibraryA("user32.dll"); + if (!user32) { + return; + } + typedef UINT(WINAPI * GETDPIFORWINDOW_T)(HWND hwnd); + GETDPIFORWINDOW_T fn_getdpiforwindow = (GETDPIFORWINDOW_T)(void*)GetProcAddress(user32, "GetDpiForWindow"); + if (fn_getdpiforwindow) { + UINT dpix = fn_getdpiforwindow(_sapp.win32.hwnd); + _sapp.win32.dpi.window_scale = (float)dpix / 96.0f; + if (_sapp.desc.high_dpi) { + _sapp.win32.dpi.content_scale = _sapp.win32.dpi.window_scale; + _sapp.win32.dpi.mouse_scale = 1.0f; + } else { + _sapp.win32.dpi.content_scale = 1.0f; + _sapp.win32.dpi.mouse_scale = 1.0f / _sapp.win32.dpi.window_scale; + } + _sapp.dpi_scale = _sapp.win32.dpi.content_scale; + SetWindowPos(hWnd, 0, + proposed_win_rect->left, + proposed_win_rect->top, + proposed_win_rect->right - proposed_win_rect->left, + proposed_win_rect->bottom - proposed_win_rect->top, + SWP_NOZORDER | SWP_NOACTIVATE); + } + FreeLibrary(user32); +} + +_SOKOL_PRIVATE void _sapp_win32_files_dropped(HDROP hdrop) { + if (!_sapp.drop.enabled) { + return; + } + _sapp_clear_drop_buffer(); + bool drop_failed = false; + const int count = (int) DragQueryFileW(hdrop, 0xffffffff, NULL, 0); + _sapp.drop.num_files = (count > _sapp.drop.max_files) ? _sapp.drop.max_files : count; + for (UINT i = 0; i < (UINT)_sapp.drop.num_files; i++) { + const UINT num_chars = DragQueryFileW(hdrop, i, NULL, 0) + 1; + WCHAR* buffer = (WCHAR*) _sapp_malloc_clear(num_chars * sizeof(WCHAR)); + DragQueryFileW(hdrop, i, buffer, num_chars); + if (!_sapp_win32_wide_to_utf8(buffer, _sapp_dropped_file_path_ptr((int)i), _sapp.drop.max_path_length)) { + _SAPP_ERROR(DROPPED_FILE_PATH_TOO_LONG); + drop_failed = true; + } + _sapp_free(buffer); + } + DragFinish(hdrop); + if (!drop_failed) { + if (_sapp_events_enabled()) { + _sapp_init_event(SAPP_EVENTTYPE_FILES_DROPPED); + _sapp.event.modifiers = _sapp_win32_mods(); + _sapp_call_event(&_sapp.event); + } + } else { + _sapp_clear_drop_buffer(); + _sapp.drop.num_files = 0; + } +} + +_SOKOL_PRIVATE void _sapp_win32_frame(bool from_winproc) { + #if defined(SOKOL_WGPU) + _sapp_wgpu_frame(); + #elif defined(SOKOL_VULKAN) + _sapp_vk_frame(); + #else + _sapp_frame(); + #endif + #if defined(SOKOL_D3D11) + bool do_not_wait = from_winproc; + _sapp_d3d11_present(do_not_wait); + #endif + #if defined(SOKOL_GLCORE) + _sapp_wgl_swap_buffers(); + #endif + if (!from_winproc) { + if (IsIconic(_sapp.win32.hwnd)) { + Sleep((DWORD)(16 * _sapp.swap_interval)); + } + } +} + +_SOKOL_PRIVATE LRESULT CALLBACK _sapp_win32_wndproc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { + if (!_sapp.win32.in_create_window) { + switch (uMsg) { + case WM_CLOSE: + /* only give user a chance to intervene when sapp_quit() wasn't already called */ + if (!_sapp.quit_ordered) { + /* if window should be closed and event handling is enabled, give user code + a change to intervene via sapp_cancel_quit() + */ + _sapp.quit_requested = true; + _sapp_win32_app_event(SAPP_EVENTTYPE_QUIT_REQUESTED); + /* if user code hasn't intervened, quit the app */ + if (_sapp.quit_requested) { + _sapp.quit_ordered = true; + } + } + if (_sapp.quit_ordered) { + PostQuitMessage(0); + } + return 0; + case WM_SYSCOMMAND: + switch (wParam & 0xFFF0) { + case SC_SCREENSAVE: + case SC_MONITORPOWER: + if (_sapp.fullscreen) { + /* disable screen saver and blanking in fullscreen mode */ + return 0; + } + break; + case SC_KEYMENU: + /* user trying to access menu via ALT */ + return 0; + } + break; + case WM_ERASEBKGND: + return 1; + case WM_SIZE: + { + const bool iconified = wParam == SIZE_MINIMIZED; + if (iconified != _sapp.win32.iconified) { + _sapp.win32.iconified = iconified; + if (iconified) { + _sapp_win32_app_event(SAPP_EVENTTYPE_ICONIFIED); + } else { + _sapp_win32_app_event(SAPP_EVENTTYPE_RESTORED); + } + } + } + break; + case WM_SETFOCUS: + _sapp_win32_app_event(SAPP_EVENTTYPE_FOCUSED); + break; + case WM_KILLFOCUS: + _sapp_win32_app_event(SAPP_EVENTTYPE_UNFOCUSED); + break; + case WM_SETCURSOR: + if (LOWORD(lParam) == HTCLIENT) { + _sapp_win32_update_cursor(_sapp.mouse.current_cursor, _sapp.mouse.shown, true); + return TRUE; + } + break; + case WM_DPICHANGED: + { + /* Update window's DPI and size if its moved to another monitor with a different DPI + Only sent if DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 is used. + */ + _sapp_win32_dpi_changed(hWnd, (LPRECT)lParam); + break; + } + case WM_LBUTTONDOWN: + _sapp_win32_mouse_update(lParam); + _sapp_win32_mouse_event(SAPP_EVENTTYPE_MOUSE_DOWN, SAPP_MOUSEBUTTON_LEFT); + _sapp_win32_capture_mouse(1<data.mouse.usFlags & MOUSE_MOVE_ABSOLUTE) { + /* mouse only reports absolute position + NOTE: This code is untested and will most likely behave wrong in Remote Desktop sessions. + (such remote desktop sessions are setting the MOUSE_MOVE_ABSOLUTE flag). + See: https://github.com/floooh/sokol/issues/806 and + https://github.com/microsoft/DirectXTK/commit/ef56b63f3739381e451f7a5a5bd2c9779d2a7555) + */ + LONG new_x = raw_mouse_data->data.mouse.lLastX; + LONG new_y = raw_mouse_data->data.mouse.lLastY; + if (_sapp.win32.mouse.raw_input.pos_valid) { + _sapp.mouse.dx = (float) (new_x - _sapp.win32.mouse.raw_input.pos_x); + _sapp.mouse.dy = (float) (new_y - _sapp.win32.mouse.raw_input.pos_y); + } + _sapp.win32.mouse.raw_input.pos_x = new_x; + _sapp.win32.mouse.raw_input.pos_y = new_y; + _sapp.win32.mouse.raw_input.pos_valid = true; + } else { + /* mouse reports movement delta (this seems to be the common case) */ + _sapp.mouse.dx = (float) raw_mouse_data->data.mouse.lLastX; + _sapp.mouse.dy = (float) raw_mouse_data->data.mouse.lLastY; + } + _sapp_win32_mouse_event(SAPP_EVENTTYPE_MOUSE_MOVE, SAPP_MOUSEBUTTON_INVALID); + } + break; + + case WM_MOUSELEAVE: + if (!_sapp.mouse.locked) { + _sapp.mouse.dx = 0.0f; + _sapp.mouse.dy = 0.0f; + _sapp.win32.mouse.tracked = false; + _sapp_win32_mouse_event(SAPP_EVENTTYPE_MOUSE_LEAVE, SAPP_MOUSEBUTTON_INVALID); + } + break; + case WM_MOUSEWHEEL: + _sapp_win32_scroll_event(0.0f, (float)GET_WHEEL_DELTA_WPARAM(wParam) / (float)WHEEL_DELTA); + break; + case WM_MOUSEHWHEEL: + _sapp_win32_scroll_event(-(float)GET_WHEEL_DELTA_WPARAM(wParam) / (float)WHEEL_DELTA, 0.0f); + break; + case WM_CHAR: + _sapp_win32_char_event((uint32_t)wParam, !!(lParam&0x40000000)); + break; + case WM_KEYDOWN: + case WM_SYSKEYDOWN: + _sapp_win32_key_event(SAPP_EVENTTYPE_KEY_DOWN, (int)(HIWORD(lParam)&0x1FF), !!(lParam&0x40000000)); + break; + case WM_KEYUP: + case WM_SYSKEYUP: + _sapp_win32_key_event(SAPP_EVENTTYPE_KEY_UP, (int)(HIWORD(lParam)&0x1FF), false); + break; + case WM_ENTERSIZEMOVE: + SetTimer(_sapp.win32.hwnd, 1, USER_TIMER_MINIMUM, NULL); + break; + case WM_EXITSIZEMOVE: + KillTimer(_sapp.win32.hwnd, 1); + break; + case WM_TIMER: + _sapp_timing_update(&_sapp.timing, 0.0); + _sapp_win32_frame(true); + /* + * NOTE: resizing each frame explodes memory usage + * + if (_sapp_win32_update_dimensions()) { + #if defined(SOKOL_D3D11) + _sapp_d3d11_resize_default_render_target(); + #elif defined(SOKOL_WGPU) + _sapp_wgpu_swapchain_size_changed(); + #endif + _sapp_win32_app_event(SAPP_EVENTTYPE_RESIZED); + } + */ + break; + case WM_NCLBUTTONDOWN: + /* workaround for half-second pause when starting to move window + see: https://gamedev.net/forums/topic/672094-keeping-things-moving-during-win32-moveresize-events/5254386/ + */ + if (SendMessage(_sapp.win32.hwnd, WM_NCHITTEST, wParam, lParam) == HTCAPTION) { + POINT point = { 0, 0 }; + if (GetCursorPos(&point)) { + ScreenToClient(_sapp.win32.hwnd, &point); + PostMessage(_sapp.win32.hwnd, WM_MOUSEMOVE, 0, ((uint32_t)point.x)|(((uint32_t)point.y) << 16)); + } + } + break; + case WM_DROPFILES: + _sapp_win32_files_dropped((HDROP)wParam); + break; + + default: + break; + } + } + return DefWindowProcW(hWnd, uMsg, wParam, lParam); +} + +_SOKOL_PRIVATE void _sapp_win32_create_window(void) { + _SAPP_STRUCT(WNDCLASSW, wndclassw); + wndclassw.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; + wndclassw.lpfnWndProc = (WNDPROC) _sapp_win32_wndproc; + wndclassw.hInstance = GetModuleHandleW(NULL); + wndclassw.hCursor = LoadCursor(NULL, IDC_ARROW); + wndclassw.hIcon = LoadIcon(NULL, IDI_WINLOGO); + wndclassw.lpszClassName = L"SOKOLAPP"; + RegisterClassW(&wndclassw); + + /* NOTE: regardless whether fullscreen is requested or not, a regular + windowed-mode window will always be created first (however in hidden + mode, so that no windowed-mode window pops up before the fullscreen window) + */ + const DWORD win_ex_style = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; + RECT rect = { 0, 0, 0, 0 }; + DWORD win_style = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SIZEBOX; + // Local patch: when high_dpi is requested, treat desc.width/desc.height as + // physical/framebuffer pixels rather than 100%-DPI logical pixels. + if (_sapp.desc.high_dpi) { + rect.right = _sapp.window_width; + rect.bottom = _sapp.window_height; + } else { + rect.right = (int) ((float)_sapp.window_width * _sapp.win32.dpi.window_scale); + rect.bottom = (int) ((float)_sapp.window_height * _sapp.win32.dpi.window_scale); + } + const bool use_default_width = 0 == _sapp.window_width; + const bool use_default_height = 0 == _sapp.window_height; + AdjustWindowRectEx(&rect, win_style, FALSE, win_ex_style); + const int win_width = rect.right - rect.left; + const int win_height = rect.bottom - rect.top; + _sapp.win32.in_create_window = true; + _sapp.win32.surrogate = 0; + _sapp.win32.hwnd = CreateWindowExW( + win_ex_style, // dwExStyle + L"SOKOLAPP", // lpClassName + _sapp.window_title_wide, // lpWindowName + win_style, // dwStyle + CW_USEDEFAULT, // X + SW_HIDE, // Y (NOTE: CW_USEDEFAULT is not used for position here, but internally calls ShowWindow! + use_default_width ? CW_USEDEFAULT : win_width, // nWidth + use_default_height ? CW_USEDEFAULT : win_height, // nHeight (NOTE: if width is CW_USEDEFAULT, height is actually ignored) + NULL, // hWndParent + NULL, // hMenu + GetModuleHandle(NULL), // hInstance + NULL); // lParam + _sapp.win32.in_create_window = false; + _sapp.win32.dc = GetDC(_sapp.win32.hwnd); + _sapp.win32.hmonitor = MonitorFromWindow(_sapp.win32.hwnd, MONITOR_DEFAULTTONULL); + SOKOL_ASSERT(_sapp.win32.dc); + + /* this will get the actual windowed-mode window size, if fullscreen + is requested, the set_fullscreen function will then capture the + current window rectangle, which then might be used later to + restore the window position when switching back to windowed + */ + _sapp_win32_update_dimensions(); + if (_sapp.fullscreen) { + _sapp_win32_set_fullscreen(_sapp.fullscreen, SWP_HIDEWINDOW); + _sapp_win32_update_dimensions(); + } + ShowWindow(_sapp.win32.hwnd, SW_SHOW); + DragAcceptFiles(_sapp.win32.hwnd, 1); +} + +_SOKOL_PRIVATE void _sapp_win32_destroy_window(void) { + DestroyWindow(_sapp.win32.hwnd); _sapp.win32.hwnd = 0; + UnregisterClassW(L"SOKOLAPP", GetModuleHandleW(NULL)); +} + +_SOKOL_PRIVATE void _sapp_win32_destroy_icons(void) { + if (_sapp.win32.big_icon) { + DestroyIcon(_sapp.win32.big_icon); + _sapp.win32.big_icon = 0; + } + if (_sapp.win32.small_icon) { + DestroyIcon(_sapp.win32.small_icon); + _sapp.win32.small_icon = 0; + } +} + +_SOKOL_PRIVATE void _sapp_win32_init_console(void) { + if (_sapp.desc.win32.console_create || _sapp.desc.win32.console_attach) { + BOOL con_valid = FALSE; + if (_sapp.desc.win32.console_attach) { + con_valid = AttachConsole(ATTACH_PARENT_PROCESS); + } + if (!con_valid && _sapp.desc.win32.console_create) { + con_valid = AllocConsole(); + } + if (con_valid) { + FILE* res_fp = 0; + errno_t err; + err = freopen_s(&res_fp, "CON", "w", stdout); + (void)err; + err = freopen_s(&res_fp, "CON", "w", stderr); + (void)err; + } + } + if (_sapp.desc.win32.console_utf8) { + _sapp.win32.orig_codepage = GetConsoleOutputCP(); + SetConsoleOutputCP(CP_UTF8); + } +} + +_SOKOL_PRIVATE void _sapp_win32_restore_console(void) { + if (_sapp.desc.win32.console_utf8) { + SetConsoleOutputCP(_sapp.win32.orig_codepage); + } +} + +_SOKOL_PRIVATE void _sapp_win32_init_dpi(void) { + + DECLARE_HANDLE(DPI_AWARENESS_CONTEXT_T); + typedef BOOL(WINAPI * SETPROCESSDPIAWARE_T)(void); + typedef bool (WINAPI * SETPROCESSDPIAWARENESSCONTEXT_T)(DPI_AWARENESS_CONTEXT_T); // since Windows 10, version 1703 + typedef HRESULT(WINAPI * SETPROCESSDPIAWARENESS_T)(PROCESS_DPI_AWARENESS); + typedef HRESULT(WINAPI * GETDPIFORMONITOR_T)(HMONITOR, MONITOR_DPI_TYPE, UINT*, UINT*); + + SETPROCESSDPIAWARE_T fn_setprocessdpiaware = 0; + SETPROCESSDPIAWARENESS_T fn_setprocessdpiawareness = 0; + GETDPIFORMONITOR_T fn_getdpiformonitor = 0; + SETPROCESSDPIAWARENESSCONTEXT_T fn_setprocessdpiawarenesscontext =0; + + HINSTANCE user32 = LoadLibraryA("user32.dll"); + if (user32) { + fn_setprocessdpiaware = (SETPROCESSDPIAWARE_T)(void*) GetProcAddress(user32, "SetProcessDPIAware"); + fn_setprocessdpiawarenesscontext = (SETPROCESSDPIAWARENESSCONTEXT_T)(void*) GetProcAddress(user32, "SetProcessDpiAwarenessContext"); + } + HINSTANCE shcore = LoadLibraryA("shcore.dll"); + if (shcore) { + fn_setprocessdpiawareness = (SETPROCESSDPIAWARENESS_T)(void*) GetProcAddress(shcore, "SetProcessDpiAwareness"); + fn_getdpiformonitor = (GETDPIFORMONITOR_T)(void*) GetProcAddress(shcore, "GetDpiForMonitor"); + } + /* + NOTE on SetProcessDpiAware() vs SetProcessDpiAwareness() vs SetProcessDpiAwarenessContext(): + + These are different attempts to get DPI handling on Windows right, from oldest + to newest. SetProcessDpiAwarenessContext() is required for the new + DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 method. + */ + bool init_dpi_awareness = true; + #if !defined(SOKOL_D3D11) + // special case for GL and Vulkan: if no high-dpi is requested, need to set the + // process to dpi-unaware, so that Windows takes care of upscaling + if (!_sapp.desc.high_dpi) { + _sapp.win32.dpi.aware = false; + fn_setprocessdpiawareness(PROCESS_DPI_UNAWARE); + init_dpi_awareness = false; + } + #endif + if (init_dpi_awareness) { + if (fn_setprocessdpiawareness) { + // first try the Win10 Creator Update per-monitor-dpi awareness, if that fails, fall back to system-dpi-awareness + // NOTE: if DPI awareness had already been set otherwise (e.g. via manifest.xml) both calls will fail + _sapp.win32.dpi.aware = true; + DPI_AWARENESS_CONTEXT_T per_monitor_aware_v2 = (DPI_AWARENESS_CONTEXT_T)-4; + if (!(fn_setprocessdpiawarenesscontext && fn_setprocessdpiawarenesscontext(per_monitor_aware_v2))) { + // fallback to system-dpi-aware + fn_setprocessdpiawareness(PROCESS_SYSTEM_DPI_AWARE); + } + } else if (fn_setprocessdpiaware) { + // fallback for Windows 7 + _sapp.win32.dpi.aware = true; + fn_setprocessdpiaware(); + } + } + // get dpi scale factor for main monitor + if (fn_getdpiformonitor && _sapp.win32.dpi.aware) { + POINT pt = { 1, 1 }; + HMONITOR hm = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST); + UINT dpix, dpiy; + HRESULT hr = fn_getdpiformonitor(hm, MDT_EFFECTIVE_DPI, &dpix, &dpiy); + _SOKOL_UNUSED(hr); + SOKOL_ASSERT(SUCCEEDED(hr)); + // clamp window scale to an integer factor + _sapp.win32.dpi.window_scale = (float)dpix / 96.0f; + } else { + _sapp.win32.dpi.window_scale = 1.0f; + } + if (_sapp.desc.high_dpi) { + _sapp.win32.dpi.content_scale = _sapp.win32.dpi.window_scale; + _sapp.win32.dpi.mouse_scale = 1.0f; + } else { + _sapp.win32.dpi.content_scale = 1.0f; + _sapp.win32.dpi.mouse_scale = 1.0f / _sapp.win32.dpi.window_scale; + } + _sapp.dpi_scale = _sapp.win32.dpi.content_scale; + if (user32) { + FreeLibrary(user32); + } + if (shcore) { + FreeLibrary(shcore); + } +} + +_SOKOL_PRIVATE bool _sapp_win32_set_clipboard_string(const char* str) { + SOKOL_ASSERT(str); + SOKOL_ASSERT(_sapp.win32.hwnd); + SOKOL_ASSERT(_sapp.clipboard.enabled && (_sapp.clipboard.buf_size > 0)); + + if (!OpenClipboard(_sapp.win32.hwnd)) { + return false; + } + + HANDLE object = 0; + wchar_t* wchar_buf = 0; + + const SIZE_T wchar_buf_size = (SIZE_T)_sapp.clipboard.buf_size * sizeof(wchar_t); + object = GlobalAlloc(GMEM_MOVEABLE, wchar_buf_size); + if (NULL == object) { + goto error; + } + wchar_buf = (wchar_t*) GlobalLock(object); + if (NULL == wchar_buf) { + goto error; + } + if (!_sapp_win32_utf8_to_wide(str, wchar_buf, (int)wchar_buf_size)) { + goto error; + } + GlobalUnlock(object); + wchar_buf = 0; + EmptyClipboard(); + // NOTE: when successful, SetClipboardData() takes ownership of memory object! + if (NULL == SetClipboardData(CF_UNICODETEXT, object)) { + goto error; + } + CloseClipboard(); + return true; + +error: + if (wchar_buf) { + GlobalUnlock(object); + } + if (object) { + GlobalFree(object); + } + CloseClipboard(); + return false; +} + +_SOKOL_PRIVATE const char* _sapp_win32_get_clipboard_string(void) { + SOKOL_ASSERT(_sapp.clipboard.enabled && _sapp.clipboard.buffer); + SOKOL_ASSERT(_sapp.win32.hwnd); + if (!OpenClipboard(_sapp.win32.hwnd)) { + /* silently ignore any errors and just return the current + content of the local clipboard buffer + */ + return _sapp.clipboard.buffer; + } + HANDLE object = GetClipboardData(CF_UNICODETEXT); + if (!object) { + CloseClipboard(); + return _sapp.clipboard.buffer; + } + const wchar_t* wchar_buf = (const wchar_t*) GlobalLock(object); + if (!wchar_buf) { + CloseClipboard(); + return _sapp.clipboard.buffer; + } + if (!_sapp_win32_wide_to_utf8(wchar_buf, _sapp.clipboard.buffer, _sapp.clipboard.buf_size)) { + _SAPP_ERROR(CLIPBOARD_STRING_TOO_BIG); + } + GlobalUnlock(object); + CloseClipboard(); + return _sapp.clipboard.buffer; +} + +_SOKOL_PRIVATE void _sapp_win32_update_window_title(void) { + _sapp_win32_utf8_to_wide(_sapp.window_title, _sapp.window_title_wide, sizeof(_sapp.window_title_wide)); + SetWindowTextW(_sapp.win32.hwnd, _sapp.window_title_wide); +} + +_SOKOL_PRIVATE HICON _sapp_win32_create_icon_from_image(const sapp_image_desc* desc, bool is_cursor) { + _SAPP_STRUCT(BITMAPV5HEADER, bi); + bi.bV5Size = sizeof(bi); + bi.bV5Width = desc->width; + bi.bV5Height = -desc->height; // NOTE the '-' here to indicate that origin is top-left + bi.bV5Planes = 1; + bi.bV5BitCount = 32; + bi.bV5Compression = BI_BITFIELDS; + bi.bV5RedMask = 0x00FF0000; + bi.bV5GreenMask = 0x0000FF00; + bi.bV5BlueMask = 0x000000FF; + bi.bV5AlphaMask = 0xFF000000; + + uint8_t* target = 0; + const uint8_t* source = (const uint8_t*)desc->pixels.ptr; + + HDC dc = GetDC(NULL); + HBITMAP color = CreateDIBSection(dc, (BITMAPINFO*)&bi, DIB_RGB_COLORS, (void**)&target, NULL, (DWORD)0); + ReleaseDC(NULL, dc); + if (0 == color) { + return NULL; + } + SOKOL_ASSERT(target); + + HBITMAP mask = CreateBitmap(desc->width, desc->height, 1, 1, NULL); + if (0 == mask) { + DeleteObject(color); + return NULL; + } + + for (int i = 0; i < (desc->width*desc->height); i++) { + target[0] = source[2]; + target[1] = source[1]; + target[2] = source[0]; + target[3] = source[3]; + target += 4; + source += 4; + } + + _SAPP_STRUCT(ICONINFO, icon_info); + icon_info.fIcon = !is_cursor; + icon_info.xHotspot = (DWORD) (is_cursor ? desc->cursor_hotspot_x : 0); + icon_info.yHotspot = (DWORD) (is_cursor ? desc->cursor_hotspot_y : 0); + icon_info.hbmMask = mask; + icon_info.hbmColor = color; + HICON icon_handle = CreateIconIndirect(&icon_info); + DeleteObject(color); + DeleteObject(mask); + + return icon_handle; +} + +_SOKOL_PRIVATE void _sapp_win32_set_icon(const sapp_icon_desc* icon_desc, int num_images) { + SOKOL_ASSERT((num_images > 0) && (num_images <= SAPP_MAX_ICONIMAGES)); + + int big_img_index = _sapp_image_bestmatch(icon_desc->images, num_images, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON)); + int sml_img_index = _sapp_image_bestmatch(icon_desc->images, num_images, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON)); + HICON big_icon = _sapp_win32_create_icon_from_image(&icon_desc->images[big_img_index], false); + HICON sml_icon = _sapp_win32_create_icon_from_image(&icon_desc->images[sml_img_index], false); + + // if icon creation or lookup has failed for some reason, leave the currently set icon untouched + if (0 != big_icon) { + SendMessage(_sapp.win32.hwnd, WM_SETICON, ICON_BIG, (LPARAM) big_icon); + if (0 != _sapp.win32.big_icon) { + DestroyIcon(_sapp.win32.big_icon); + } + _sapp.win32.big_icon = big_icon; + } + if (0 != sml_icon) { + SendMessage(_sapp.win32.hwnd, WM_SETICON, ICON_SMALL, (LPARAM) sml_icon); + if (0 != _sapp.win32.small_icon) { + DestroyIcon(_sapp.win32.small_icon); + } + _sapp.win32.small_icon = sml_icon; + } +} + +/* don't laugh, but this seems to be the easiest and most robust + way to check if we're running on Win10 + + From: https://github.com/videolan/vlc/blob/232fb13b0d6110c4d1b683cde24cf9a7f2c5c2ea/modules/video_output/win32/d3d11_swapchain.c#L263 +*/ +_SOKOL_PRIVATE bool _sapp_win32_is_win10_or_greater(void) { + HMODULE h = GetModuleHandleW(L"kernel32.dll"); + if (NULL != h) { + return (NULL != GetProcAddress(h, "GetSystemCpuSetInformation")); + } else { + return false; + } +} + +_SOKOL_PRIVATE void _sapp_win32_run(const sapp_desc* desc) { + _sapp_init_state(desc); + _sapp_win32_init_console(); + _sapp.win32.is_win10_or_greater = _sapp_win32_is_win10_or_greater(); + _sapp_win32_init_keytable(); + _sapp_win32_utf8_to_wide(_sapp.window_title, _sapp.window_title_wide, sizeof(_sapp.window_title_wide)); + _sapp_win32_init_dpi(); + _sapp_win32_init_cursors(); + _sapp_win32_create_window(); + sapp_set_icon(&desc->icon); + #if defined(SOKOL_D3D11) + _sapp_d3d11_create_device_and_swapchain(); + _sapp_d3d11_create_default_render_target(); + #elif defined(SOKOL_GLCORE) + _sapp_wgl_init(); + _sapp_wgl_load_extensions(); + _sapp_wgl_create_context(); + #elif defined(SOKOL_WGPU) + _sapp_wgpu_init(); + #elif defined(SOKOL_VULKAN) + _sapp_vk_init(); + #endif + _sapp.valid = true; + + bool done = false; + while (!(done || _sapp.quit_ordered)) { + _sapp_timing_update(&_sapp.timing, 0.0); + MSG msg; + while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) { + if (WM_QUIT == msg.message) { + done = true; + continue; + } else { + TranslateMessage(&msg); + DispatchMessageW(&msg); + } + } + _sapp_win32_frame(false); + // check for window resized, this cannot happen in WM_SIZE as it explodes memory usage + // NOTE: when Vulkan is active, _sapp_win32_update_dimensions() will never return true, + // instead the resize-event is fixed by the swapchain management code + if (_sapp_win32_update_dimensions()) { + #if defined(SOKOL_D3D11) + _sapp_d3d11_resize_default_render_target(); + #elif defined(SOKOL_WGPU) + _sapp_wgpu_swapchain_size_changed(); + #endif + _sapp_win32_app_event(SAPP_EVENTTYPE_RESIZED); + } + if (_sapp.quit_requested) { + PostMessage(_sapp.win32.hwnd, WM_CLOSE, 0, 0); + } + // update mouse-lock state + _sapp_win32_update_mouse_lock(); + } + _sapp_call_cleanup(); + + #if defined(SOKOL_D3D11) + _sapp_d3d11_destroy_default_render_target(); + _sapp_d3d11_destroy_device_and_swapchain(); + #elif defined(SOKOL_GLCORE) + _sapp_wgl_destroy_context(); + _sapp_wgl_shutdown(); + #elif defined(SOKOL_WGPU) + _sapp_wgpu_discard(); + #elif defined(SOKOL_VULKAN) + _sapp_vk_discard(); + #endif + _sapp_win32_destroy_window(); + _sapp_win32_destroy_icons(); + _sapp_win32_restore_console(); + _sapp_win32_free_raw_input_data(); + _sapp_discard_state(); +} + +_SOKOL_PRIVATE char** _sapp_win32_command_line_to_utf8_argv(LPWSTR w_command_line, int* o_argc) { + int argc = 0; + char** argv = 0; + char* args; + + LPWSTR* w_argv = CommandLineToArgvW(w_command_line, &argc); + if (w_argv == NULL) { + // FIXME: chicken egg problem, can't report errors before sokol_main() is called! + } else { + size_t size = wcslen(w_command_line) * 4; + argv = (char**) _sapp_malloc_clear(((size_t)argc + 1) * sizeof(char*) + size); + SOKOL_ASSERT(argv); + args = (char*) &argv[argc + 1]; + int n; + for (int i = 0; i < argc; ++i) { + n = WideCharToMultiByte(CP_UTF8, 0, w_argv[i], -1, args, (int)size, NULL, NULL); + if (n == 0) { + // FIXME: chicken egg problem, can't report errors before sokol_main() is called! + break; + } + argv[i] = args; + size -= (size_t)n; + args += n; + } + LocalFree(w_argv); + } + *o_argc = argc; + return argv; +} + +_SOKOL_PRIVATE bool _sapp_win32_make_custom_mouse_cursor(sapp_mouse_cursor cursor, const sapp_image_desc* desc) { + SOKOL_ASSERT((cursor >= 0) && (cursor < _SAPP_MOUSECURSOR_NUM)); + SOKOL_ASSERT(0 == _sapp.win32.custom_cursors[cursor]); + const HCURSOR win32_cursor = _sapp_win32_create_icon_from_image(desc, true); + _sapp.win32.custom_cursors[cursor] = win32_cursor; + return win32_cursor != 0; +} + +_SOKOL_PRIVATE void _sapp_win32_destroy_custom_mouse_cursor(sapp_mouse_cursor cursor) { + SOKOL_ASSERT((cursor >= 0) && (cursor < _SAPP_MOUSECURSOR_NUM)); + HCURSOR win32_cursor = _sapp.win32.custom_cursors[cursor]; + SOKOL_ASSERT(win32_cursor); + _sapp.win32.custom_cursors[cursor] = 0; + // NOTE: DestroyIcon() may return zero (failure) if the cursor is currently in + // use. Normally that shouldn't happen since when attempting to unbind the + // current cursor it will be hidden first, but since there might be other edge + // cases we just log a warning but don't fail hard + BOOL res = DestroyIcon(win32_cursor); + if (!res) { + _SAPP_WARN(WIN32_DESTROYICON_FOR_CURSOR_FAILED); + } +} + +#if !defined(SOKOL_NO_ENTRY) +#if defined(SOKOL_WIN32_FORCE_MAIN) +int main(int argc, char* argv[]) { + sapp_desc desc = sokol_main(argc, argv); + _sapp_win32_run(&desc); + return 0; +} +#endif /* SOKOL_WIN32_FORCE_MAIN */ +#if defined(SOKOL_WIN32_FORCE_WINMAIN) || !defined(SOKOL_WIN32_FORCE_MAIN) +int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow) { + _SOKOL_UNUSED(hInstance); + _SOKOL_UNUSED(hPrevInstance); + _SOKOL_UNUSED(lpCmdLine); + _SOKOL_UNUSED(nCmdShow); + int argc_utf8 = 0; + char** argv_utf8 = _sapp_win32_command_line_to_utf8_argv(GetCommandLineW(), &argc_utf8); + sapp_desc desc = sokol_main(argc_utf8, argv_utf8); + _sapp_win32_run(&desc); + _sapp_free(argv_utf8); + return 0; +} +#endif /* SOKOL_WIN32_FORCE_WINMAIN */ +#endif /* SOKOL_NO_ENTRY */ + +#ifdef _MSC_VER + #pragma warning(pop) +#endif + +#endif /* _SAPP_WIN32 */ + +// █████ ███ ██ ██████ ██████ ██████ ██ ██████ +// ██ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ███████ ██ ██ ██ ██ ██ ██████ ██ ██ ██ ██ ██ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ██ ██ ██ ████ ██████ ██ ██ ██████ ██ ██████ +// +// >>android +#if defined(_SAPP_ANDROID) + +/* android loop thread */ +_SOKOL_PRIVATE bool _sapp_android_init_egl(void) { + SOKOL_ASSERT(_sapp.android.display == EGL_NO_DISPLAY); + SOKOL_ASSERT(_sapp.android.context == EGL_NO_CONTEXT); + + EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); + if (display == EGL_NO_DISPLAY) { + return false; + } + if (eglInitialize(display, NULL, NULL) == EGL_FALSE) { + return false; + } + EGLint alpha_size = _sapp.desc.alpha ? 8 : 0; + const EGLint cfg_attributes[] = { + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT, + EGL_RED_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_BLUE_SIZE, 8, + EGL_ALPHA_SIZE, alpha_size, + EGL_DEPTH_SIZE, 16, + EGL_STENCIL_SIZE, 0, + EGL_NONE, + }; + EGLConfig available_cfgs[32]; + EGLint cfg_count; + eglChooseConfig(display, cfg_attributes, available_cfgs, 32, &cfg_count); + SOKOL_ASSERT(cfg_count > 0); + SOKOL_ASSERT(cfg_count <= 32); + + /* find config with 8-bit rgb buffer if available, ndk sample does not trust egl spec */ + EGLConfig config; + bool exact_cfg_found = false; + for (int i = 0; i < cfg_count; ++i) { + EGLConfig c = available_cfgs[i]; + EGLint r, g, b, a, d; + if (eglGetConfigAttrib(display, c, EGL_RED_SIZE, &r) == EGL_TRUE && + eglGetConfigAttrib(display, c, EGL_GREEN_SIZE, &g) == EGL_TRUE && + eglGetConfigAttrib(display, c, EGL_BLUE_SIZE, &b) == EGL_TRUE && + eglGetConfigAttrib(display, c, EGL_ALPHA_SIZE, &a) == EGL_TRUE && + eglGetConfigAttrib(display, c, EGL_DEPTH_SIZE, &d) == EGL_TRUE && + r == 8 && g == 8 && b == 8 && (alpha_size == 0 || a == alpha_size) && d == 16) { + exact_cfg_found = true; + config = c; + break; + } + } + if (!exact_cfg_found) { + config = available_cfgs[0]; + } + + EGLint ctx_attributes[] = { + EGL_CONTEXT_MAJOR_VERSION, _sapp.desc.gl.major_version, + EGL_CONTEXT_MINOR_VERSION, _sapp.desc.gl.minor_version, + EGL_NONE, + }; + EGLContext context = eglCreateContext(display, config, EGL_NO_CONTEXT, ctx_attributes); + if (context == EGL_NO_CONTEXT) { + return false; + } + + _sapp.android.config = config; + _sapp.android.display = display; + _sapp.android.context = context; + return true; +} + +_SOKOL_PRIVATE void _sapp_android_cleanup_egl(void) { + if (_sapp.android.display != EGL_NO_DISPLAY) { + eglMakeCurrent(_sapp.android.display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + if (_sapp.android.surface != EGL_NO_SURFACE) { + eglDestroySurface(_sapp.android.display, _sapp.android.surface); + _sapp.android.surface = EGL_NO_SURFACE; + } + if (_sapp.android.context != EGL_NO_CONTEXT) { + eglDestroyContext(_sapp.android.display, _sapp.android.context); + _sapp.android.context = EGL_NO_CONTEXT; + } + eglTerminate(_sapp.android.display); + _sapp.android.display = EGL_NO_DISPLAY; + } +} + +_SOKOL_PRIVATE bool _sapp_android_init_egl_surface(ANativeWindow* window) { + SOKOL_ASSERT(_sapp.android.display != EGL_NO_DISPLAY); + SOKOL_ASSERT(_sapp.android.context != EGL_NO_CONTEXT); + SOKOL_ASSERT(_sapp.android.surface == EGL_NO_SURFACE); + SOKOL_ASSERT(window); + + /* TODO: set window flags */ + /* ANativeActivity_setWindowFlags(activity, AWINDOW_FLAG_KEEP_SCREEN_ON, 0); */ + + /* create egl surface and make it current */ + EGLSurface surface = eglCreateWindowSurface(_sapp.android.display, _sapp.android.config, window, NULL); + if (surface == EGL_NO_SURFACE) { + return false; + } + if (eglMakeCurrent(_sapp.android.display, surface, surface, _sapp.android.context) == EGL_FALSE) { + return false; + } + _sapp.android.surface = surface; + glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint*)&_sapp.gl.framebuffer); + return true; +} + +_SOKOL_PRIVATE void _sapp_android_cleanup_egl_surface(void) { + if (_sapp.android.display == EGL_NO_DISPLAY) { + return; + } + eglMakeCurrent(_sapp.android.display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + if (_sapp.android.surface != EGL_NO_SURFACE) { + eglDestroySurface(_sapp.android.display, _sapp.android.surface); + _sapp.android.surface = EGL_NO_SURFACE; + } +} + +_SOKOL_PRIVATE void _sapp_android_app_event(sapp_event_type type) { + if (_sapp_events_enabled()) { + _sapp_init_event(type); + _sapp_call_event(&_sapp.event); + } +} + +_SOKOL_PRIVATE void _sapp_android_update_dimensions(ANativeWindow* window, bool force_update) { + SOKOL_ASSERT(_sapp.android.display != EGL_NO_DISPLAY); + SOKOL_ASSERT(_sapp.android.context != EGL_NO_CONTEXT); + SOKOL_ASSERT(_sapp.android.surface != EGL_NO_SURFACE); + SOKOL_ASSERT(window); + + const int32_t win_w = ANativeWindow_getWidth(window); + const int32_t win_h = ANativeWindow_getHeight(window); + SOKOL_ASSERT(win_w >= 0 && win_h >= 0); + const bool win_changed = (win_w != _sapp.window_width) || (win_h != _sapp.window_height); + _sapp.window_width = win_w; + _sapp.window_height = win_h; + if (win_changed || force_update) { + if (!_sapp.desc.high_dpi) { + const int32_t buf_w = win_w / 2; + const int32_t buf_h = win_h / 2; + EGLint format; + EGLBoolean egl_result = eglGetConfigAttrib(_sapp.android.display, _sapp.android.config, EGL_NATIVE_VISUAL_ID, &format); + SOKOL_ASSERT(egl_result == EGL_TRUE); _SOKOL_UNUSED(egl_result); + /* NOTE: calling ANativeWindow_setBuffersGeometry() with the same dimensions + as the ANativeWindow size results in weird display artefacts, that's + why it's only called when the buffer geometry is different from + the window size + */ + int32_t result = ANativeWindow_setBuffersGeometry(window, buf_w, buf_h, format); + SOKOL_ASSERT(result == 0); _SOKOL_UNUSED(result); + } + } + + /* query surface size */ + EGLint fb_w, fb_h; + EGLBoolean egl_result_w = eglQuerySurface(_sapp.android.display, _sapp.android.surface, EGL_WIDTH, &fb_w); + EGLBoolean egl_result_h = eglQuerySurface(_sapp.android.display, _sapp.android.surface, EGL_HEIGHT, &fb_h); + SOKOL_ASSERT(egl_result_w == EGL_TRUE); _SOKOL_UNUSED(egl_result_w); + SOKOL_ASSERT(egl_result_h == EGL_TRUE); _SOKOL_UNUSED(egl_result_h); + const bool fb_changed = (fb_w != _sapp.framebuffer_width) || (fb_h != _sapp.framebuffer_height); + _sapp.framebuffer_width = fb_w; + _sapp.framebuffer_height = fb_h; + _sapp.dpi_scale = (float)_sapp.framebuffer_width / (float)_sapp.window_width; + if (win_changed || fb_changed || force_update) { + if (!_sapp.first_frame) { + _sapp_android_app_event(SAPP_EVENTTYPE_RESIZED); + } + } +} + +_SOKOL_PRIVATE void _sapp_android_cleanup(void) { + if (_sapp.android.surface != EGL_NO_SURFACE) { + /* egl context is bound, cleanup gracefully */ + if (_sapp.init_called && !_sapp.cleanup_called) { + _sapp_call_cleanup(); + } + } + /* always try to cleanup by destroying egl context */ + _sapp_android_cleanup_egl(); +} + +_SOKOL_PRIVATE void _sapp_android_shutdown(void) { + /* try to cleanup while we still have a surface and can call cleanup_cb() */ + _sapp_android_cleanup(); + /* request exit */ + ANativeActivity_finish(_sapp.android.activity); +} + +_SOKOL_PRIVATE void _sapp_android_frame(double external_now) { + SOKOL_ASSERT(_sapp.android.display != EGL_NO_DISPLAY); + SOKOL_ASSERT(_sapp.android.context != EGL_NO_CONTEXT); + SOKOL_ASSERT(_sapp.android.surface != EGL_NO_SURFACE); + _sapp_timing_update(&_sapp.timing, external_now); + _sapp_android_update_dimensions(_sapp.android.current.window, false); + _sapp_frame(); + eglSwapBuffers(_sapp.android.display, _sapp.android.surface); +} + +_SOKOL_PRIVATE bool _sapp_android_touch_event(const AInputEvent* e) { + if (AInputEvent_getType(e) != AINPUT_EVENT_TYPE_MOTION) { + return false; + } + if (!_sapp_events_enabled()) { + return false; + } + int32_t action_idx = AMotionEvent_getAction(e); + int32_t action = action_idx & AMOTION_EVENT_ACTION_MASK; + sapp_event_type type = SAPP_EVENTTYPE_INVALID; + switch (action) { + case AMOTION_EVENT_ACTION_DOWN: + case AMOTION_EVENT_ACTION_POINTER_DOWN: + type = SAPP_EVENTTYPE_TOUCHES_BEGAN; + break; + case AMOTION_EVENT_ACTION_MOVE: + type = SAPP_EVENTTYPE_TOUCHES_MOVED; + break; + case AMOTION_EVENT_ACTION_UP: + case AMOTION_EVENT_ACTION_POINTER_UP: + type = SAPP_EVENTTYPE_TOUCHES_ENDED; + break; + case AMOTION_EVENT_ACTION_CANCEL: + type = SAPP_EVENTTYPE_TOUCHES_CANCELLED; + break; + default: + break; + } + if (type == SAPP_EVENTTYPE_INVALID) { + return false; + } + int32_t index = action_idx >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; + _sapp_init_event(type); + _sapp.event.num_touches = (int)AMotionEvent_getPointerCount(e); + if (_sapp.event.num_touches > SAPP_MAX_TOUCHPOINTS) { + _sapp.event.num_touches = SAPP_MAX_TOUCHPOINTS; + } + for (int32_t i = 0; i < _sapp.event.num_touches; i++) { + sapp_touchpoint* dst = &_sapp.event.touches[i]; + dst->identifier = (uintptr_t)AMotionEvent_getPointerId(e, (size_t)i); + dst->pos_x = (AMotionEvent_getX(e, (size_t)i) / _sapp.window_width) * _sapp.framebuffer_width; + dst->pos_y = (AMotionEvent_getY(e, (size_t)i) / _sapp.window_height) * _sapp.framebuffer_height; + dst->android_tooltype = (sapp_android_tooltype) AMotionEvent_getToolType(e, (size_t)i); + if (action == AMOTION_EVENT_ACTION_POINTER_DOWN || + action == AMOTION_EVENT_ACTION_POINTER_UP) { + dst->changed = (i == index); + } else { + dst->changed = true; + } + } + _sapp_call_event(&_sapp.event); + return true; +} + +_SOKOL_PRIVATE bool _sapp_android_key_event(const AInputEvent* e) { + if (AInputEvent_getType(e) != AINPUT_EVENT_TYPE_KEY) { + return false; + } + if (AKeyEvent_getKeyCode(e) == AKEYCODE_BACK) { + /* FIXME: this should be hooked into a "really quit?" mechanism + so the app can ask the user for confirmation, this is currently + generally missing in sokol_app.h + */ + _sapp_android_shutdown(); + return true; + } + return false; +} + +_SOKOL_PRIVATE int _sapp_android_input_cb(int fd, int events, void* data) { + _SOKOL_UNUSED(fd); + _SOKOL_UNUSED(data); + if ((events & ALOOPER_EVENT_INPUT) == 0) { + _SAPP_ERROR(ANDROID_UNSUPPORTED_INPUT_EVENT_INPUT_CB); + return 1; + } + SOKOL_ASSERT(_sapp.android.current.input); + AInputEvent* event = NULL; + while (AInputQueue_getEvent(_sapp.android.current.input, &event) >= 0) { + if (AInputQueue_preDispatchEvent(_sapp.android.current.input, event) != 0) { + continue; + } + int32_t handled = 0; + if (_sapp_android_touch_event(event) || _sapp_android_key_event(event)) { + handled = 1; + } + AInputQueue_finishEvent(_sapp.android.current.input, event, handled); + } + return 1; +} + +_SOKOL_PRIVATE int _sapp_android_main_cb(int fd, int events, void* data) { + _SOKOL_UNUSED(data); + if ((events & ALOOPER_EVENT_INPUT) == 0) { + _SAPP_ERROR(ANDROID_UNSUPPORTED_INPUT_EVENT_MAIN_CB); + return 1; + } + + _sapp_android_msg_t msg; + if (read(fd, &msg, sizeof(msg)) != sizeof(msg)) { + _SAPP_ERROR(ANDROID_READ_MSG_FAILED); + return 1; + } + + pthread_mutex_lock(&_sapp.android.pt.mutex); + switch (msg) { + case _SOKOL_ANDROID_MSG_CREATE: + { + _SAPP_INFO(ANDROID_MSG_CREATE); + SOKOL_ASSERT(!_sapp.valid); + bool result = _sapp_android_init_egl(); + SOKOL_ASSERT(result); _SOKOL_UNUSED(result); + _sapp.valid = true; + _sapp.android.has_created = true; + } + break; + case _SOKOL_ANDROID_MSG_RESUME: + _SAPP_INFO(ANDROID_MSG_RESUME); + _sapp.android.has_resumed = true; + _sapp_android_app_event(SAPP_EVENTTYPE_RESUMED); + break; + case _SOKOL_ANDROID_MSG_PAUSE: + _SAPP_INFO(ANDROID_MSG_PAUSE); + _sapp.android.has_resumed = false; + _sapp_android_app_event(SAPP_EVENTTYPE_SUSPENDED); + break; + case _SOKOL_ANDROID_MSG_FOCUS: + _SAPP_INFO(ANDROID_MSG_FOCUS); + _sapp.android.has_focus = true; + break; + case _SOKOL_ANDROID_MSG_NO_FOCUS: + _SAPP_INFO(ANDROID_MSG_NO_FOCUS); + _sapp.android.has_focus = false; + break; + case _SOKOL_ANDROID_MSG_SET_NATIVE_WINDOW: + _SAPP_INFO(ANDROID_MSG_SET_NATIVE_WINDOW); + if (_sapp.android.current.window != _sapp.android.pending.window) { + if (_sapp.android.current.window != NULL) { + _sapp_android_cleanup_egl_surface(); + } + if (_sapp.android.pending.window != NULL) { + if (_sapp_android_init_egl_surface(_sapp.android.pending.window)) { + _sapp_android_update_dimensions(_sapp.android.pending.window, true); + } else { + _sapp_android_shutdown(); + } + } + } + _sapp.android.current.window = _sapp.android.pending.window; + break; + case _SOKOL_ANDROID_MSG_SET_INPUT_QUEUE: + _SAPP_INFO(ANDROID_MSG_SET_INPUT_QUEUE); + if (_sapp.android.current.input != _sapp.android.pending.input) { + if (_sapp.android.current.input != NULL) { + AInputQueue_detachLooper(_sapp.android.current.input); + } + if (_sapp.android.pending.input != NULL) { + AInputQueue_attachLooper( + _sapp.android.pending.input, + _sapp.android.looper, + ALOOPER_POLL_CALLBACK, + _sapp_android_input_cb, + NULL); /* data */ + } + } + _sapp.android.current.input = _sapp.android.pending.input; + break; + case _SOKOL_ANDROID_MSG_DESTROY: + _SAPP_INFO(ANDROID_MSG_DESTROY); + _sapp_android_cleanup(); + _sapp.valid = false; + _sapp.android.is_thread_stopping = true; + break; + default: + _SAPP_WARN(ANDROID_UNKNOWN_MSG); + break; + } + pthread_cond_broadcast(&_sapp.android.pt.cond); /* signal "received" */ + pthread_mutex_unlock(&_sapp.android.pt.mutex); + return 1; +} + +_SOKOL_PRIVATE bool _sapp_android_should_update(void) { + bool is_in_front = _sapp.android.has_resumed && _sapp.android.has_focus; + bool has_surface = _sapp.android.surface != EGL_NO_SURFACE; + return is_in_front && has_surface; +} + +#if __ANDROID_API__ >= 29 +_SOKOL_PRIVATE void _sapp_android_frame_callback(int64_t frame_time_nanos, void* data) { + _SOKOL_UNUSED(data); + _sapp.android.frame_callback_in_flight = false; + if (_sapp.android.is_thread_stopping) { + return; + } + if (_sapp_android_should_update()) { + // Post the next frame callback. We do this here rather than later so the runnable can be + // queued early in the looper. + AChoreographer_postFrameCallback64(_sapp.android.choreographer, _sapp_android_frame_callback, NULL); + _sapp.android.frame_callback_in_flight = true; + _sapp_android_frame((double)frame_time_nanos / 1.0e9); + } +} +#endif + +_SOKOL_PRIVATE void _sapp_android_show_keyboard(bool shown) { + SOKOL_ASSERT(_sapp.valid); + /* This seems to be broken in the NDK, but there is (a very cumbersome) workaround... */ + if (shown) { + ANativeActivity_showSoftInput(_sapp.android.activity, ANATIVEACTIVITY_SHOW_SOFT_INPUT_FORCED); + } else { + ANativeActivity_hideSoftInput(_sapp.android.activity, ANATIVEACTIVITY_HIDE_SOFT_INPUT_NOT_ALWAYS); + } +} + +_SOKOL_PRIVATE void* _sapp_android_loop(void* arg) { + _SOKOL_UNUSED(arg); + _SAPP_INFO(ANDROID_LOOP_THREAD_STARTED); + + _sapp.android.looper = ALooper_prepare(0 /* or ALOOPER_PREPARE_ALLOW_NON_CALLBACKS*/); + ALooper_addFd(_sapp.android.looper, + _sapp.android.pt.read_from_main_fd, + ALOOPER_POLL_CALLBACK, + ALOOPER_EVENT_INPUT, + _sapp_android_main_cb, + NULL); /* data */ + + #if __ANDROID_API__ >= 29 + _sapp.android.choreographer = AChoreographer_getInstance(); + if (_sapp.android.choreographer != NULL) { + _SAPP_INFO(ANDROID_CHOREOGRAPHER_ENABLED); + } else { + _SAPP_INFO(ANDROID_CHOREOGRAPHER_UNAVAILABLE); + } + #else + _SAPP_INFO(ANDROID_CHOREOGRAPHER_UNAVAILABLE); + #endif + + /* signal start to main thread */ + pthread_mutex_lock(&_sapp.android.pt.mutex); + _sapp.android.is_thread_started = true; + pthread_cond_broadcast(&_sapp.android.pt.cond); + pthread_mutex_unlock(&_sapp.android.pt.mutex); + + /* main loop */ + while (!_sapp.android.is_thread_stopping) { + #if __ANDROID_API__ >= 29 + if (_sapp.android.choreographer != NULL) { + // Posts _sapp_android_frame_callback with the choreographer to start our frame + // loop (for example, on first run or when resuming). When we have a choreographer, + // we'll get frame callbacks via _sapp_android_frame_callback. + if (!_sapp.android.frame_callback_in_flight && _sapp_android_should_update()) { + AChoreographer_postFrameCallback64(_sapp.android.choreographer, _sapp_android_frame_callback, NULL); + _sapp.android.frame_callback_in_flight = true; + } + // Blocks until the next event. We don't need a while loop here because we're + // already being driven by the outer while loop. + ALooper_pollOnce(-1, NULL, NULL, NULL); + continue; + } + #endif + // sokol frame -- fallback if not updating frames from choreographer callbacks + if (_sapp_android_should_update()) { + _sapp_android_frame(0.0); + } + + /* process all events (or stop early if app is requested to quit) */ + bool process_events = true; + while (process_events && !_sapp.android.is_thread_stopping) { + bool block_until_event = !_sapp.android.is_thread_stopping && !_sapp_android_should_update(); + process_events = ALooper_pollOnce(block_until_event ? -1 : 0, NULL, NULL, NULL) == ALOOPER_POLL_CALLBACK; + } + } + + /* cleanup thread */ + if (_sapp.android.current.input != NULL) { + AInputQueue_detachLooper(_sapp.android.current.input); + } + + /* the following causes heap corruption on exit, why?? + ALooper_removeFd(_sapp.android.looper, _sapp.android.pt.read_from_main_fd); + ALooper_release(_sapp.android.looper);*/ + + /* signal "destroyed" */ + pthread_mutex_lock(&_sapp.android.pt.mutex); + _sapp.android.is_thread_stopped = true; + pthread_cond_broadcast(&_sapp.android.pt.cond); + pthread_mutex_unlock(&_sapp.android.pt.mutex); + + _SAPP_INFO(ANDROID_LOOP_THREAD_DONE); + return NULL; +} + +/* android main/ui thread */ +_SOKOL_PRIVATE void _sapp_android_msg(_sapp_android_msg_t msg) { + if (write(_sapp.android.pt.write_from_main_fd, &msg, sizeof(msg)) != sizeof(msg)) { + _SAPP_ERROR(ANDROID_WRITE_MSG_FAILED); + } +} + +_SOKOL_PRIVATE void _sapp_android_on_start(ANativeActivity* activity) { + _SOKOL_UNUSED(activity); + _SAPP_INFO(ANDROID_NATIVE_ACTIVITY_ONSTART); +} + +_SOKOL_PRIVATE void _sapp_android_on_resume(ANativeActivity* activity) { + _SOKOL_UNUSED(activity); + _SAPP_INFO(ANDROID_NATIVE_ACTIVITY_ONRESUME); + _sapp_android_msg(_SOKOL_ANDROID_MSG_RESUME); +} + +_SOKOL_PRIVATE void* _sapp_android_on_save_instance_state(ANativeActivity* activity, size_t* out_size) { + _SOKOL_UNUSED(activity); + _SAPP_INFO(ANDROID_NATIVE_ACTIVITY_ONSAVEINSTANCESTATE); + *out_size = 0; + return NULL; +} + +_SOKOL_PRIVATE void _sapp_android_on_window_focus_changed(ANativeActivity* activity, int has_focus) { + _SOKOL_UNUSED(activity); + _SAPP_INFO(ANDROID_NATIVE_ACTIVITY_ONWINDOWFOCUSCHANGED); + if (has_focus) { + _sapp_android_msg(_SOKOL_ANDROID_MSG_FOCUS); + } else { + _sapp_android_msg(_SOKOL_ANDROID_MSG_NO_FOCUS); + } +} + +_SOKOL_PRIVATE void _sapp_android_on_pause(ANativeActivity* activity) { + _SOKOL_UNUSED(activity); + _SAPP_INFO(ANDROID_NATIVE_ACTIVITY_ONPAUSE); + _sapp_android_msg(_SOKOL_ANDROID_MSG_PAUSE); +} + +_SOKOL_PRIVATE void _sapp_android_on_stop(ANativeActivity* activity) { + _SOKOL_UNUSED(activity); + _SAPP_INFO(ANDROID_NATIVE_ACTIVITY_ONSTOP); +} + +_SOKOL_PRIVATE void _sapp_android_msg_set_native_window(ANativeWindow* window) { + pthread_mutex_lock(&_sapp.android.pt.mutex); + _sapp.android.pending.window = window; + _sapp_android_msg(_SOKOL_ANDROID_MSG_SET_NATIVE_WINDOW); + while (_sapp.android.current.window != window) { + pthread_cond_wait(&_sapp.android.pt.cond, &_sapp.android.pt.mutex); + } + pthread_mutex_unlock(&_sapp.android.pt.mutex); +} + +_SOKOL_PRIVATE void _sapp_android_on_native_window_created(ANativeActivity* activity, ANativeWindow* window) { + _SOKOL_UNUSED(activity); + _SAPP_INFO(ANDROID_NATIVE_ACTIVITY_ONNATIVEWINDOWCREATED); + _sapp_android_msg_set_native_window(window); +} + +_SOKOL_PRIVATE void _sapp_android_on_native_window_destroyed(ANativeActivity* activity, ANativeWindow* window) { + _SOKOL_UNUSED(activity); + _SOKOL_UNUSED(window); + _SAPP_INFO(ANDROID_NATIVE_ACTIVITY_ONNATIVEWINDOWDESTROYED); + _sapp_android_msg_set_native_window(NULL); +} + +_SOKOL_PRIVATE void _sapp_android_msg_set_input_queue(AInputQueue* input) { + pthread_mutex_lock(&_sapp.android.pt.mutex); + _sapp.android.pending.input = input; + _sapp_android_msg(_SOKOL_ANDROID_MSG_SET_INPUT_QUEUE); + while (_sapp.android.current.input != input) { + pthread_cond_wait(&_sapp.android.pt.cond, &_sapp.android.pt.mutex); + } + pthread_mutex_unlock(&_sapp.android.pt.mutex); +} + +_SOKOL_PRIVATE void _sapp_android_on_input_queue_created(ANativeActivity* activity, AInputQueue* queue) { + _SOKOL_UNUSED(activity); + _SAPP_INFO(ANDROID_NATIVE_ACTIVITY_ONINPUTQUEUECREATED); + _sapp_android_msg_set_input_queue(queue); +} + +_SOKOL_PRIVATE void _sapp_android_on_input_queue_destroyed(ANativeActivity* activity, AInputQueue* queue) { + _SOKOL_UNUSED(activity); + _SOKOL_UNUSED(queue); + _SAPP_INFO(ANDROID_NATIVE_ACTIVITY_ONINPUTQUEUEDESTROYED); + _sapp_android_msg_set_input_queue(NULL); +} + +_SOKOL_PRIVATE void _sapp_android_on_config_changed(ANativeActivity* activity) { + _SOKOL_UNUSED(activity); + _SAPP_INFO(ANDROID_NATIVE_ACTIVITY_ONCONFIGURATIONCHANGED); + /* see android:configChanges in manifest */ +} + +_SOKOL_PRIVATE void _sapp_android_on_low_memory(ANativeActivity* activity) { + _SOKOL_UNUSED(activity); + _SAPP_INFO(ANDROID_NATIVE_ACTIVITY_ONLOWMEMORY); +} + +_SOKOL_PRIVATE void _sapp_android_on_destroy(ANativeActivity* activity) { + /* + * For some reason even an empty app using nativeactivity.h will crash (WIN DEATH) + * on my device (Moto X 2nd gen) when the app is removed from the task view + * (TaskStackView: onTaskViewDismissed). + * + * However, if ANativeActivity_finish() is explicitly called from for example + * _sapp_android_on_stop(), the crash disappears. Is this a bug in NativeActivity? + */ + _SOKOL_UNUSED(activity); + _SAPP_INFO(ANDROID_NATIVE_ACTIVITY_ONDESTROY); + + /* send destroy msg */ + pthread_mutex_lock(&_sapp.android.pt.mutex); + _sapp_android_msg(_SOKOL_ANDROID_MSG_DESTROY); + while (!_sapp.android.is_thread_stopped) { + pthread_cond_wait(&_sapp.android.pt.cond, &_sapp.android.pt.mutex); + } + pthread_mutex_unlock(&_sapp.android.pt.mutex); + + /* clean up main thread */ + pthread_cond_destroy(&_sapp.android.pt.cond); + pthread_mutex_destroy(&_sapp.android.pt.mutex); + + close(_sapp.android.pt.read_from_main_fd); + close(_sapp.android.pt.write_from_main_fd); + + _SAPP_INFO(ANDROID_NATIVE_ACTIVITY_DONE); + + /* this is a bit naughty, but causes a clean restart of the app (static globals are reset) */ + exit(0); +} + +JNIEXPORT +void ANativeActivity_onCreate(ANativeActivity* activity, void* saved_state, size_t saved_state_size) { + _SOKOL_UNUSED(saved_state); + _SOKOL_UNUSED(saved_state_size); + _SAPP_INFO(ANDROID_NATIVE_ACTIVITY_ONCREATE); + + // the NativeActity pointer needs to be available inside sokol_main() + // (see https://github.com/floooh/sokol/issues/708), however _sapp_init_state() + // will clear the global _sapp_t struct, so we need to initialize the native + // activity pointer twice, once before sokol_main() and once after _sapp_init_state() + _sapp_clear(&_sapp, sizeof(_sapp)); + _sapp.android.activity = activity; + sapp_desc desc = sokol_main(0, NULL); + _sapp_init_state(&desc); + _sapp.android.activity = activity; + + int pipe_fd[2]; + if (pipe(pipe_fd) != 0) { + _SAPP_ERROR(ANDROID_CREATE_THREAD_PIPE_FAILED); + return; + } + _sapp.android.pt.read_from_main_fd = pipe_fd[0]; + _sapp.android.pt.write_from_main_fd = pipe_fd[1]; + + pthread_mutex_init(&_sapp.android.pt.mutex, NULL); + pthread_cond_init(&_sapp.android.pt.cond, NULL); + + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + pthread_create(&_sapp.android.pt.thread, &attr, _sapp_android_loop, 0); + pthread_attr_destroy(&attr); + + /* wait until main loop has started */ + pthread_mutex_lock(&_sapp.android.pt.mutex); + while (!_sapp.android.is_thread_started) { + pthread_cond_wait(&_sapp.android.pt.cond, &_sapp.android.pt.mutex); + } + pthread_mutex_unlock(&_sapp.android.pt.mutex); + + /* send create msg */ + pthread_mutex_lock(&_sapp.android.pt.mutex); + _sapp_android_msg(_SOKOL_ANDROID_MSG_CREATE); + while (!_sapp.android.has_created) { + pthread_cond_wait(&_sapp.android.pt.cond, &_sapp.android.pt.mutex); + } + pthread_mutex_unlock(&_sapp.android.pt.mutex); + + /* register for callbacks */ + activity->callbacks->onStart = _sapp_android_on_start; + activity->callbacks->onResume = _sapp_android_on_resume; + activity->callbacks->onSaveInstanceState = _sapp_android_on_save_instance_state; + activity->callbacks->onWindowFocusChanged = _sapp_android_on_window_focus_changed; + activity->callbacks->onPause = _sapp_android_on_pause; + activity->callbacks->onStop = _sapp_android_on_stop; + activity->callbacks->onDestroy = _sapp_android_on_destroy; + activity->callbacks->onNativeWindowCreated = _sapp_android_on_native_window_created; + /* activity->callbacks->onNativeWindowResized = _sapp_android_on_native_window_resized; */ + /* activity->callbacks->onNativeWindowRedrawNeeded = _sapp_android_on_native_window_redraw_needed; */ + activity->callbacks->onNativeWindowDestroyed = _sapp_android_on_native_window_destroyed; + activity->callbacks->onInputQueueCreated = _sapp_android_on_input_queue_created; + activity->callbacks->onInputQueueDestroyed = _sapp_android_on_input_queue_destroyed; + /* activity->callbacks->onContentRectChanged = _sapp_android_on_content_rect_changed; */ + /* activity->callbacks->onConfigurationChanged = _sapp_android_on_config_changed; */ + activity->callbacks->onLowMemory = _sapp_android_on_low_memory; + + _SAPP_INFO(ANDROID_NATIVE_ACTIVITY_CREATE_SUCCESS); + + /* NOT A BUG: do NOT call sapp_discard_state() */ +} + +#endif /* _SAPP_ANDROID */ + +// ██ ██ ███ ██ ██ ██ ██ ██ +// ██ ██ ████ ██ ██ ██ ██ ██ +// ██ ██ ██ ██ ██ ██ ██ ███ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ███████ ██ ██ ████ ██████ ██ ██ +// +// >>linux +#if defined(_SAPP_LINUX) + +/* see GLFW's xkb_unicode.c */ +static const struct _sapp_x11_codepair { + uint16_t keysym; + uint16_t ucs; +} _sapp_x11_keysymtab[] = { + { 0x01a1, 0x0104 }, + { 0x01a2, 0x02d8 }, + { 0x01a3, 0x0141 }, + { 0x01a5, 0x013d }, + { 0x01a6, 0x015a }, + { 0x01a9, 0x0160 }, + { 0x01aa, 0x015e }, + { 0x01ab, 0x0164 }, + { 0x01ac, 0x0179 }, + { 0x01ae, 0x017d }, + { 0x01af, 0x017b }, + { 0x01b1, 0x0105 }, + { 0x01b2, 0x02db }, + { 0x01b3, 0x0142 }, + { 0x01b5, 0x013e }, + { 0x01b6, 0x015b }, + { 0x01b7, 0x02c7 }, + { 0x01b9, 0x0161 }, + { 0x01ba, 0x015f }, + { 0x01bb, 0x0165 }, + { 0x01bc, 0x017a }, + { 0x01bd, 0x02dd }, + { 0x01be, 0x017e }, + { 0x01bf, 0x017c }, + { 0x01c0, 0x0154 }, + { 0x01c3, 0x0102 }, + { 0x01c5, 0x0139 }, + { 0x01c6, 0x0106 }, + { 0x01c8, 0x010c }, + { 0x01ca, 0x0118 }, + { 0x01cc, 0x011a }, + { 0x01cf, 0x010e }, + { 0x01d0, 0x0110 }, + { 0x01d1, 0x0143 }, + { 0x01d2, 0x0147 }, + { 0x01d5, 0x0150 }, + { 0x01d8, 0x0158 }, + { 0x01d9, 0x016e }, + { 0x01db, 0x0170 }, + { 0x01de, 0x0162 }, + { 0x01e0, 0x0155 }, + { 0x01e3, 0x0103 }, + { 0x01e5, 0x013a }, + { 0x01e6, 0x0107 }, + { 0x01e8, 0x010d }, + { 0x01ea, 0x0119 }, + { 0x01ec, 0x011b }, + { 0x01ef, 0x010f }, + { 0x01f0, 0x0111 }, + { 0x01f1, 0x0144 }, + { 0x01f2, 0x0148 }, + { 0x01f5, 0x0151 }, + { 0x01f8, 0x0159 }, + { 0x01f9, 0x016f }, + { 0x01fb, 0x0171 }, + { 0x01fe, 0x0163 }, + { 0x01ff, 0x02d9 }, + { 0x02a1, 0x0126 }, + { 0x02a6, 0x0124 }, + { 0x02a9, 0x0130 }, + { 0x02ab, 0x011e }, + { 0x02ac, 0x0134 }, + { 0x02b1, 0x0127 }, + { 0x02b6, 0x0125 }, + { 0x02b9, 0x0131 }, + { 0x02bb, 0x011f }, + { 0x02bc, 0x0135 }, + { 0x02c5, 0x010a }, + { 0x02c6, 0x0108 }, + { 0x02d5, 0x0120 }, + { 0x02d8, 0x011c }, + { 0x02dd, 0x016c }, + { 0x02de, 0x015c }, + { 0x02e5, 0x010b }, + { 0x02e6, 0x0109 }, + { 0x02f5, 0x0121 }, + { 0x02f8, 0x011d }, + { 0x02fd, 0x016d }, + { 0x02fe, 0x015d }, + { 0x03a2, 0x0138 }, + { 0x03a3, 0x0156 }, + { 0x03a5, 0x0128 }, + { 0x03a6, 0x013b }, + { 0x03aa, 0x0112 }, + { 0x03ab, 0x0122 }, + { 0x03ac, 0x0166 }, + { 0x03b3, 0x0157 }, + { 0x03b5, 0x0129 }, + { 0x03b6, 0x013c }, + { 0x03ba, 0x0113 }, + { 0x03bb, 0x0123 }, + { 0x03bc, 0x0167 }, + { 0x03bd, 0x014a }, + { 0x03bf, 0x014b }, + { 0x03c0, 0x0100 }, + { 0x03c7, 0x012e }, + { 0x03cc, 0x0116 }, + { 0x03cf, 0x012a }, + { 0x03d1, 0x0145 }, + { 0x03d2, 0x014c }, + { 0x03d3, 0x0136 }, + { 0x03d9, 0x0172 }, + { 0x03dd, 0x0168 }, + { 0x03de, 0x016a }, + { 0x03e0, 0x0101 }, + { 0x03e7, 0x012f }, + { 0x03ec, 0x0117 }, + { 0x03ef, 0x012b }, + { 0x03f1, 0x0146 }, + { 0x03f2, 0x014d }, + { 0x03f3, 0x0137 }, + { 0x03f9, 0x0173 }, + { 0x03fd, 0x0169 }, + { 0x03fe, 0x016b }, + { 0x047e, 0x203e }, + { 0x04a1, 0x3002 }, + { 0x04a2, 0x300c }, + { 0x04a3, 0x300d }, + { 0x04a4, 0x3001 }, + { 0x04a5, 0x30fb }, + { 0x04a6, 0x30f2 }, + { 0x04a7, 0x30a1 }, + { 0x04a8, 0x30a3 }, + { 0x04a9, 0x30a5 }, + { 0x04aa, 0x30a7 }, + { 0x04ab, 0x30a9 }, + { 0x04ac, 0x30e3 }, + { 0x04ad, 0x30e5 }, + { 0x04ae, 0x30e7 }, + { 0x04af, 0x30c3 }, + { 0x04b0, 0x30fc }, + { 0x04b1, 0x30a2 }, + { 0x04b2, 0x30a4 }, + { 0x04b3, 0x30a6 }, + { 0x04b4, 0x30a8 }, + { 0x04b5, 0x30aa }, + { 0x04b6, 0x30ab }, + { 0x04b7, 0x30ad }, + { 0x04b8, 0x30af }, + { 0x04b9, 0x30b1 }, + { 0x04ba, 0x30b3 }, + { 0x04bb, 0x30b5 }, + { 0x04bc, 0x30b7 }, + { 0x04bd, 0x30b9 }, + { 0x04be, 0x30bb }, + { 0x04bf, 0x30bd }, + { 0x04c0, 0x30bf }, + { 0x04c1, 0x30c1 }, + { 0x04c2, 0x30c4 }, + { 0x04c3, 0x30c6 }, + { 0x04c4, 0x30c8 }, + { 0x04c5, 0x30ca }, + { 0x04c6, 0x30cb }, + { 0x04c7, 0x30cc }, + { 0x04c8, 0x30cd }, + { 0x04c9, 0x30ce }, + { 0x04ca, 0x30cf }, + { 0x04cb, 0x30d2 }, + { 0x04cc, 0x30d5 }, + { 0x04cd, 0x30d8 }, + { 0x04ce, 0x30db }, + { 0x04cf, 0x30de }, + { 0x04d0, 0x30df }, + { 0x04d1, 0x30e0 }, + { 0x04d2, 0x30e1 }, + { 0x04d3, 0x30e2 }, + { 0x04d4, 0x30e4 }, + { 0x04d5, 0x30e6 }, + { 0x04d6, 0x30e8 }, + { 0x04d7, 0x30e9 }, + { 0x04d8, 0x30ea }, + { 0x04d9, 0x30eb }, + { 0x04da, 0x30ec }, + { 0x04db, 0x30ed }, + { 0x04dc, 0x30ef }, + { 0x04dd, 0x30f3 }, + { 0x04de, 0x309b }, + { 0x04df, 0x309c }, + { 0x05ac, 0x060c }, + { 0x05bb, 0x061b }, + { 0x05bf, 0x061f }, + { 0x05c1, 0x0621 }, + { 0x05c2, 0x0622 }, + { 0x05c3, 0x0623 }, + { 0x05c4, 0x0624 }, + { 0x05c5, 0x0625 }, + { 0x05c6, 0x0626 }, + { 0x05c7, 0x0627 }, + { 0x05c8, 0x0628 }, + { 0x05c9, 0x0629 }, + { 0x05ca, 0x062a }, + { 0x05cb, 0x062b }, + { 0x05cc, 0x062c }, + { 0x05cd, 0x062d }, + { 0x05ce, 0x062e }, + { 0x05cf, 0x062f }, + { 0x05d0, 0x0630 }, + { 0x05d1, 0x0631 }, + { 0x05d2, 0x0632 }, + { 0x05d3, 0x0633 }, + { 0x05d4, 0x0634 }, + { 0x05d5, 0x0635 }, + { 0x05d6, 0x0636 }, + { 0x05d7, 0x0637 }, + { 0x05d8, 0x0638 }, + { 0x05d9, 0x0639 }, + { 0x05da, 0x063a }, + { 0x05e0, 0x0640 }, + { 0x05e1, 0x0641 }, + { 0x05e2, 0x0642 }, + { 0x05e3, 0x0643 }, + { 0x05e4, 0x0644 }, + { 0x05e5, 0x0645 }, + { 0x05e6, 0x0646 }, + { 0x05e7, 0x0647 }, + { 0x05e8, 0x0648 }, + { 0x05e9, 0x0649 }, + { 0x05ea, 0x064a }, + { 0x05eb, 0x064b }, + { 0x05ec, 0x064c }, + { 0x05ed, 0x064d }, + { 0x05ee, 0x064e }, + { 0x05ef, 0x064f }, + { 0x05f0, 0x0650 }, + { 0x05f1, 0x0651 }, + { 0x05f2, 0x0652 }, + { 0x06a1, 0x0452 }, + { 0x06a2, 0x0453 }, + { 0x06a3, 0x0451 }, + { 0x06a4, 0x0454 }, + { 0x06a5, 0x0455 }, + { 0x06a6, 0x0456 }, + { 0x06a7, 0x0457 }, + { 0x06a8, 0x0458 }, + { 0x06a9, 0x0459 }, + { 0x06aa, 0x045a }, + { 0x06ab, 0x045b }, + { 0x06ac, 0x045c }, + { 0x06ae, 0x045e }, + { 0x06af, 0x045f }, + { 0x06b0, 0x2116 }, + { 0x06b1, 0x0402 }, + { 0x06b2, 0x0403 }, + { 0x06b3, 0x0401 }, + { 0x06b4, 0x0404 }, + { 0x06b5, 0x0405 }, + { 0x06b6, 0x0406 }, + { 0x06b7, 0x0407 }, + { 0x06b8, 0x0408 }, + { 0x06b9, 0x0409 }, + { 0x06ba, 0x040a }, + { 0x06bb, 0x040b }, + { 0x06bc, 0x040c }, + { 0x06be, 0x040e }, + { 0x06bf, 0x040f }, + { 0x06c0, 0x044e }, + { 0x06c1, 0x0430 }, + { 0x06c2, 0x0431 }, + { 0x06c3, 0x0446 }, + { 0x06c4, 0x0434 }, + { 0x06c5, 0x0435 }, + { 0x06c6, 0x0444 }, + { 0x06c7, 0x0433 }, + { 0x06c8, 0x0445 }, + { 0x06c9, 0x0438 }, + { 0x06ca, 0x0439 }, + { 0x06cb, 0x043a }, + { 0x06cc, 0x043b }, + { 0x06cd, 0x043c }, + { 0x06ce, 0x043d }, + { 0x06cf, 0x043e }, + { 0x06d0, 0x043f }, + { 0x06d1, 0x044f }, + { 0x06d2, 0x0440 }, + { 0x06d3, 0x0441 }, + { 0x06d4, 0x0442 }, + { 0x06d5, 0x0443 }, + { 0x06d6, 0x0436 }, + { 0x06d7, 0x0432 }, + { 0x06d8, 0x044c }, + { 0x06d9, 0x044b }, + { 0x06da, 0x0437 }, + { 0x06db, 0x0448 }, + { 0x06dc, 0x044d }, + { 0x06dd, 0x0449 }, + { 0x06de, 0x0447 }, + { 0x06df, 0x044a }, + { 0x06e0, 0x042e }, + { 0x06e1, 0x0410 }, + { 0x06e2, 0x0411 }, + { 0x06e3, 0x0426 }, + { 0x06e4, 0x0414 }, + { 0x06e5, 0x0415 }, + { 0x06e6, 0x0424 }, + { 0x06e7, 0x0413 }, + { 0x06e8, 0x0425 }, + { 0x06e9, 0x0418 }, + { 0x06ea, 0x0419 }, + { 0x06eb, 0x041a }, + { 0x06ec, 0x041b }, + { 0x06ed, 0x041c }, + { 0x06ee, 0x041d }, + { 0x06ef, 0x041e }, + { 0x06f0, 0x041f }, + { 0x06f1, 0x042f }, + { 0x06f2, 0x0420 }, + { 0x06f3, 0x0421 }, + { 0x06f4, 0x0422 }, + { 0x06f5, 0x0423 }, + { 0x06f6, 0x0416 }, + { 0x06f7, 0x0412 }, + { 0x06f8, 0x042c }, + { 0x06f9, 0x042b }, + { 0x06fa, 0x0417 }, + { 0x06fb, 0x0428 }, + { 0x06fc, 0x042d }, + { 0x06fd, 0x0429 }, + { 0x06fe, 0x0427 }, + { 0x06ff, 0x042a }, + { 0x07a1, 0x0386 }, + { 0x07a2, 0x0388 }, + { 0x07a3, 0x0389 }, + { 0x07a4, 0x038a }, + { 0x07a5, 0x03aa }, + { 0x07a7, 0x038c }, + { 0x07a8, 0x038e }, + { 0x07a9, 0x03ab }, + { 0x07ab, 0x038f }, + { 0x07ae, 0x0385 }, + { 0x07af, 0x2015 }, + { 0x07b1, 0x03ac }, + { 0x07b2, 0x03ad }, + { 0x07b3, 0x03ae }, + { 0x07b4, 0x03af }, + { 0x07b5, 0x03ca }, + { 0x07b6, 0x0390 }, + { 0x07b7, 0x03cc }, + { 0x07b8, 0x03cd }, + { 0x07b9, 0x03cb }, + { 0x07ba, 0x03b0 }, + { 0x07bb, 0x03ce }, + { 0x07c1, 0x0391 }, + { 0x07c2, 0x0392 }, + { 0x07c3, 0x0393 }, + { 0x07c4, 0x0394 }, + { 0x07c5, 0x0395 }, + { 0x07c6, 0x0396 }, + { 0x07c7, 0x0397 }, + { 0x07c8, 0x0398 }, + { 0x07c9, 0x0399 }, + { 0x07ca, 0x039a }, + { 0x07cb, 0x039b }, + { 0x07cc, 0x039c }, + { 0x07cd, 0x039d }, + { 0x07ce, 0x039e }, + { 0x07cf, 0x039f }, + { 0x07d0, 0x03a0 }, + { 0x07d1, 0x03a1 }, + { 0x07d2, 0x03a3 }, + { 0x07d4, 0x03a4 }, + { 0x07d5, 0x03a5 }, + { 0x07d6, 0x03a6 }, + { 0x07d7, 0x03a7 }, + { 0x07d8, 0x03a8 }, + { 0x07d9, 0x03a9 }, + { 0x07e1, 0x03b1 }, + { 0x07e2, 0x03b2 }, + { 0x07e3, 0x03b3 }, + { 0x07e4, 0x03b4 }, + { 0x07e5, 0x03b5 }, + { 0x07e6, 0x03b6 }, + { 0x07e7, 0x03b7 }, + { 0x07e8, 0x03b8 }, + { 0x07e9, 0x03b9 }, + { 0x07ea, 0x03ba }, + { 0x07eb, 0x03bb }, + { 0x07ec, 0x03bc }, + { 0x07ed, 0x03bd }, + { 0x07ee, 0x03be }, + { 0x07ef, 0x03bf }, + { 0x07f0, 0x03c0 }, + { 0x07f1, 0x03c1 }, + { 0x07f2, 0x03c3 }, + { 0x07f3, 0x03c2 }, + { 0x07f4, 0x03c4 }, + { 0x07f5, 0x03c5 }, + { 0x07f6, 0x03c6 }, + { 0x07f7, 0x03c7 }, + { 0x07f8, 0x03c8 }, + { 0x07f9, 0x03c9 }, + { 0x08a1, 0x23b7 }, + { 0x08a2, 0x250c }, + { 0x08a3, 0x2500 }, + { 0x08a4, 0x2320 }, + { 0x08a5, 0x2321 }, + { 0x08a6, 0x2502 }, + { 0x08a7, 0x23a1 }, + { 0x08a8, 0x23a3 }, + { 0x08a9, 0x23a4 }, + { 0x08aa, 0x23a6 }, + { 0x08ab, 0x239b }, + { 0x08ac, 0x239d }, + { 0x08ad, 0x239e }, + { 0x08ae, 0x23a0 }, + { 0x08af, 0x23a8 }, + { 0x08b0, 0x23ac }, + { 0x08bc, 0x2264 }, + { 0x08bd, 0x2260 }, + { 0x08be, 0x2265 }, + { 0x08bf, 0x222b }, + { 0x08c0, 0x2234 }, + { 0x08c1, 0x221d }, + { 0x08c2, 0x221e }, + { 0x08c5, 0x2207 }, + { 0x08c8, 0x223c }, + { 0x08c9, 0x2243 }, + { 0x08cd, 0x21d4 }, + { 0x08ce, 0x21d2 }, + { 0x08cf, 0x2261 }, + { 0x08d6, 0x221a }, + { 0x08da, 0x2282 }, + { 0x08db, 0x2283 }, + { 0x08dc, 0x2229 }, + { 0x08dd, 0x222a }, + { 0x08de, 0x2227 }, + { 0x08df, 0x2228 }, + { 0x08ef, 0x2202 }, + { 0x08f6, 0x0192 }, + { 0x08fb, 0x2190 }, + { 0x08fc, 0x2191 }, + { 0x08fd, 0x2192 }, + { 0x08fe, 0x2193 }, + { 0x09e0, 0x25c6 }, + { 0x09e1, 0x2592 }, + { 0x09e2, 0x2409 }, + { 0x09e3, 0x240c }, + { 0x09e4, 0x240d }, + { 0x09e5, 0x240a }, + { 0x09e8, 0x2424 }, + { 0x09e9, 0x240b }, + { 0x09ea, 0x2518 }, + { 0x09eb, 0x2510 }, + { 0x09ec, 0x250c }, + { 0x09ed, 0x2514 }, + { 0x09ee, 0x253c }, + { 0x09ef, 0x23ba }, + { 0x09f0, 0x23bb }, + { 0x09f1, 0x2500 }, + { 0x09f2, 0x23bc }, + { 0x09f3, 0x23bd }, + { 0x09f4, 0x251c }, + { 0x09f5, 0x2524 }, + { 0x09f6, 0x2534 }, + { 0x09f7, 0x252c }, + { 0x09f8, 0x2502 }, + { 0x0aa1, 0x2003 }, + { 0x0aa2, 0x2002 }, + { 0x0aa3, 0x2004 }, + { 0x0aa4, 0x2005 }, + { 0x0aa5, 0x2007 }, + { 0x0aa6, 0x2008 }, + { 0x0aa7, 0x2009 }, + { 0x0aa8, 0x200a }, + { 0x0aa9, 0x2014 }, + { 0x0aaa, 0x2013 }, + { 0x0aae, 0x2026 }, + { 0x0aaf, 0x2025 }, + { 0x0ab0, 0x2153 }, + { 0x0ab1, 0x2154 }, + { 0x0ab2, 0x2155 }, + { 0x0ab3, 0x2156 }, + { 0x0ab4, 0x2157 }, + { 0x0ab5, 0x2158 }, + { 0x0ab6, 0x2159 }, + { 0x0ab7, 0x215a }, + { 0x0ab8, 0x2105 }, + { 0x0abb, 0x2012 }, + { 0x0abc, 0x2329 }, + { 0x0abe, 0x232a }, + { 0x0ac3, 0x215b }, + { 0x0ac4, 0x215c }, + { 0x0ac5, 0x215d }, + { 0x0ac6, 0x215e }, + { 0x0ac9, 0x2122 }, + { 0x0aca, 0x2613 }, + { 0x0acc, 0x25c1 }, + { 0x0acd, 0x25b7 }, + { 0x0ace, 0x25cb }, + { 0x0acf, 0x25af }, + { 0x0ad0, 0x2018 }, + { 0x0ad1, 0x2019 }, + { 0x0ad2, 0x201c }, + { 0x0ad3, 0x201d }, + { 0x0ad4, 0x211e }, + { 0x0ad6, 0x2032 }, + { 0x0ad7, 0x2033 }, + { 0x0ad9, 0x271d }, + { 0x0adb, 0x25ac }, + { 0x0adc, 0x25c0 }, + { 0x0add, 0x25b6 }, + { 0x0ade, 0x25cf }, + { 0x0adf, 0x25ae }, + { 0x0ae0, 0x25e6 }, + { 0x0ae1, 0x25ab }, + { 0x0ae2, 0x25ad }, + { 0x0ae3, 0x25b3 }, + { 0x0ae4, 0x25bd }, + { 0x0ae5, 0x2606 }, + { 0x0ae6, 0x2022 }, + { 0x0ae7, 0x25aa }, + { 0x0ae8, 0x25b2 }, + { 0x0ae9, 0x25bc }, + { 0x0aea, 0x261c }, + { 0x0aeb, 0x261e }, + { 0x0aec, 0x2663 }, + { 0x0aed, 0x2666 }, + { 0x0aee, 0x2665 }, + { 0x0af0, 0x2720 }, + { 0x0af1, 0x2020 }, + { 0x0af2, 0x2021 }, + { 0x0af3, 0x2713 }, + { 0x0af4, 0x2717 }, + { 0x0af5, 0x266f }, + { 0x0af6, 0x266d }, + { 0x0af7, 0x2642 }, + { 0x0af8, 0x2640 }, + { 0x0af9, 0x260e }, + { 0x0afa, 0x2315 }, + { 0x0afb, 0x2117 }, + { 0x0afc, 0x2038 }, + { 0x0afd, 0x201a }, + { 0x0afe, 0x201e }, + { 0x0ba3, 0x003c }, + { 0x0ba6, 0x003e }, + { 0x0ba8, 0x2228 }, + { 0x0ba9, 0x2227 }, + { 0x0bc0, 0x00af }, + { 0x0bc2, 0x22a5 }, + { 0x0bc3, 0x2229 }, + { 0x0bc4, 0x230a }, + { 0x0bc6, 0x005f }, + { 0x0bca, 0x2218 }, + { 0x0bcc, 0x2395 }, + { 0x0bce, 0x22a4 }, + { 0x0bcf, 0x25cb }, + { 0x0bd3, 0x2308 }, + { 0x0bd6, 0x222a }, + { 0x0bd8, 0x2283 }, + { 0x0bda, 0x2282 }, + { 0x0bdc, 0x22a2 }, + { 0x0bfc, 0x22a3 }, + { 0x0cdf, 0x2017 }, + { 0x0ce0, 0x05d0 }, + { 0x0ce1, 0x05d1 }, + { 0x0ce2, 0x05d2 }, + { 0x0ce3, 0x05d3 }, + { 0x0ce4, 0x05d4 }, + { 0x0ce5, 0x05d5 }, + { 0x0ce6, 0x05d6 }, + { 0x0ce7, 0x05d7 }, + { 0x0ce8, 0x05d8 }, + { 0x0ce9, 0x05d9 }, + { 0x0cea, 0x05da }, + { 0x0ceb, 0x05db }, + { 0x0cec, 0x05dc }, + { 0x0ced, 0x05dd }, + { 0x0cee, 0x05de }, + { 0x0cef, 0x05df }, + { 0x0cf0, 0x05e0 }, + { 0x0cf1, 0x05e1 }, + { 0x0cf2, 0x05e2 }, + { 0x0cf3, 0x05e3 }, + { 0x0cf4, 0x05e4 }, + { 0x0cf5, 0x05e5 }, + { 0x0cf6, 0x05e6 }, + { 0x0cf7, 0x05e7 }, + { 0x0cf8, 0x05e8 }, + { 0x0cf9, 0x05e9 }, + { 0x0cfa, 0x05ea }, + { 0x0da1, 0x0e01 }, + { 0x0da2, 0x0e02 }, + { 0x0da3, 0x0e03 }, + { 0x0da4, 0x0e04 }, + { 0x0da5, 0x0e05 }, + { 0x0da6, 0x0e06 }, + { 0x0da7, 0x0e07 }, + { 0x0da8, 0x0e08 }, + { 0x0da9, 0x0e09 }, + { 0x0daa, 0x0e0a }, + { 0x0dab, 0x0e0b }, + { 0x0dac, 0x0e0c }, + { 0x0dad, 0x0e0d }, + { 0x0dae, 0x0e0e }, + { 0x0daf, 0x0e0f }, + { 0x0db0, 0x0e10 }, + { 0x0db1, 0x0e11 }, + { 0x0db2, 0x0e12 }, + { 0x0db3, 0x0e13 }, + { 0x0db4, 0x0e14 }, + { 0x0db5, 0x0e15 }, + { 0x0db6, 0x0e16 }, + { 0x0db7, 0x0e17 }, + { 0x0db8, 0x0e18 }, + { 0x0db9, 0x0e19 }, + { 0x0dba, 0x0e1a }, + { 0x0dbb, 0x0e1b }, + { 0x0dbc, 0x0e1c }, + { 0x0dbd, 0x0e1d }, + { 0x0dbe, 0x0e1e }, + { 0x0dbf, 0x0e1f }, + { 0x0dc0, 0x0e20 }, + { 0x0dc1, 0x0e21 }, + { 0x0dc2, 0x0e22 }, + { 0x0dc3, 0x0e23 }, + { 0x0dc4, 0x0e24 }, + { 0x0dc5, 0x0e25 }, + { 0x0dc6, 0x0e26 }, + { 0x0dc7, 0x0e27 }, + { 0x0dc8, 0x0e28 }, + { 0x0dc9, 0x0e29 }, + { 0x0dca, 0x0e2a }, + { 0x0dcb, 0x0e2b }, + { 0x0dcc, 0x0e2c }, + { 0x0dcd, 0x0e2d }, + { 0x0dce, 0x0e2e }, + { 0x0dcf, 0x0e2f }, + { 0x0dd0, 0x0e30 }, + { 0x0dd1, 0x0e31 }, + { 0x0dd2, 0x0e32 }, + { 0x0dd3, 0x0e33 }, + { 0x0dd4, 0x0e34 }, + { 0x0dd5, 0x0e35 }, + { 0x0dd6, 0x0e36 }, + { 0x0dd7, 0x0e37 }, + { 0x0dd8, 0x0e38 }, + { 0x0dd9, 0x0e39 }, + { 0x0dda, 0x0e3a }, + { 0x0ddf, 0x0e3f }, + { 0x0de0, 0x0e40 }, + { 0x0de1, 0x0e41 }, + { 0x0de2, 0x0e42 }, + { 0x0de3, 0x0e43 }, + { 0x0de4, 0x0e44 }, + { 0x0de5, 0x0e45 }, + { 0x0de6, 0x0e46 }, + { 0x0de7, 0x0e47 }, + { 0x0de8, 0x0e48 }, + { 0x0de9, 0x0e49 }, + { 0x0dea, 0x0e4a }, + { 0x0deb, 0x0e4b }, + { 0x0dec, 0x0e4c }, + { 0x0ded, 0x0e4d }, + { 0x0df0, 0x0e50 }, + { 0x0df1, 0x0e51 }, + { 0x0df2, 0x0e52 }, + { 0x0df3, 0x0e53 }, + { 0x0df4, 0x0e54 }, + { 0x0df5, 0x0e55 }, + { 0x0df6, 0x0e56 }, + { 0x0df7, 0x0e57 }, + { 0x0df8, 0x0e58 }, + { 0x0df9, 0x0e59 }, + { 0x0ea1, 0x3131 }, + { 0x0ea2, 0x3132 }, + { 0x0ea3, 0x3133 }, + { 0x0ea4, 0x3134 }, + { 0x0ea5, 0x3135 }, + { 0x0ea6, 0x3136 }, + { 0x0ea7, 0x3137 }, + { 0x0ea8, 0x3138 }, + { 0x0ea9, 0x3139 }, + { 0x0eaa, 0x313a }, + { 0x0eab, 0x313b }, + { 0x0eac, 0x313c }, + { 0x0ead, 0x313d }, + { 0x0eae, 0x313e }, + { 0x0eaf, 0x313f }, + { 0x0eb0, 0x3140 }, + { 0x0eb1, 0x3141 }, + { 0x0eb2, 0x3142 }, + { 0x0eb3, 0x3143 }, + { 0x0eb4, 0x3144 }, + { 0x0eb5, 0x3145 }, + { 0x0eb6, 0x3146 }, + { 0x0eb7, 0x3147 }, + { 0x0eb8, 0x3148 }, + { 0x0eb9, 0x3149 }, + { 0x0eba, 0x314a }, + { 0x0ebb, 0x314b }, + { 0x0ebc, 0x314c }, + { 0x0ebd, 0x314d }, + { 0x0ebe, 0x314e }, + { 0x0ebf, 0x314f }, + { 0x0ec0, 0x3150 }, + { 0x0ec1, 0x3151 }, + { 0x0ec2, 0x3152 }, + { 0x0ec3, 0x3153 }, + { 0x0ec4, 0x3154 }, + { 0x0ec5, 0x3155 }, + { 0x0ec6, 0x3156 }, + { 0x0ec7, 0x3157 }, + { 0x0ec8, 0x3158 }, + { 0x0ec9, 0x3159 }, + { 0x0eca, 0x315a }, + { 0x0ecb, 0x315b }, + { 0x0ecc, 0x315c }, + { 0x0ecd, 0x315d }, + { 0x0ece, 0x315e }, + { 0x0ecf, 0x315f }, + { 0x0ed0, 0x3160 }, + { 0x0ed1, 0x3161 }, + { 0x0ed2, 0x3162 }, + { 0x0ed3, 0x3163 }, + { 0x0ed4, 0x11a8 }, + { 0x0ed5, 0x11a9 }, + { 0x0ed6, 0x11aa }, + { 0x0ed7, 0x11ab }, + { 0x0ed8, 0x11ac }, + { 0x0ed9, 0x11ad }, + { 0x0eda, 0x11ae }, + { 0x0edb, 0x11af }, + { 0x0edc, 0x11b0 }, + { 0x0edd, 0x11b1 }, + { 0x0ede, 0x11b2 }, + { 0x0edf, 0x11b3 }, + { 0x0ee0, 0x11b4 }, + { 0x0ee1, 0x11b5 }, + { 0x0ee2, 0x11b6 }, + { 0x0ee3, 0x11b7 }, + { 0x0ee4, 0x11b8 }, + { 0x0ee5, 0x11b9 }, + { 0x0ee6, 0x11ba }, + { 0x0ee7, 0x11bb }, + { 0x0ee8, 0x11bc }, + { 0x0ee9, 0x11bd }, + { 0x0eea, 0x11be }, + { 0x0eeb, 0x11bf }, + { 0x0eec, 0x11c0 }, + { 0x0eed, 0x11c1 }, + { 0x0eee, 0x11c2 }, + { 0x0eef, 0x316d }, + { 0x0ef0, 0x3171 }, + { 0x0ef1, 0x3178 }, + { 0x0ef2, 0x317f }, + { 0x0ef3, 0x3181 }, + { 0x0ef4, 0x3184 }, + { 0x0ef5, 0x3186 }, + { 0x0ef6, 0x318d }, + { 0x0ef7, 0x318e }, + { 0x0ef8, 0x11eb }, + { 0x0ef9, 0x11f0 }, + { 0x0efa, 0x11f9 }, + { 0x0eff, 0x20a9 }, + { 0x13a4, 0x20ac }, + { 0x13bc, 0x0152 }, + { 0x13bd, 0x0153 }, + { 0x13be, 0x0178 }, + { 0x20ac, 0x20ac }, + { 0xfe50, '`' }, + { 0xfe51, 0x00b4 }, + { 0xfe52, '^' }, + { 0xfe53, '~' }, + { 0xfe54, 0x00af }, + { 0xfe55, 0x02d8 }, + { 0xfe56, 0x02d9 }, + { 0xfe57, 0x00a8 }, + { 0xfe58, 0x02da }, + { 0xfe59, 0x02dd }, + { 0xfe5a, 0x02c7 }, + { 0xfe5b, 0x00b8 }, + { 0xfe5c, 0x02db }, + { 0xfe5d, 0x037a }, + { 0xfe5e, 0x309b }, + { 0xfe5f, 0x309c }, + { 0xfe63, '/' }, + { 0xfe64, 0x02bc }, + { 0xfe65, 0x02bd }, + { 0xfe66, 0x02f5 }, + { 0xfe67, 0x02f3 }, + { 0xfe68, 0x02cd }, + { 0xfe69, 0xa788 }, + { 0xfe6a, 0x02f7 }, + { 0xfe6e, ',' }, + { 0xfe6f, 0x00a4 }, + { 0xfe80, 'a' }, /* XK_dead_a */ + { 0xfe81, 'A' }, /* XK_dead_A */ + { 0xfe82, 'e' }, /* XK_dead_e */ + { 0xfe83, 'E' }, /* XK_dead_E */ + { 0xfe84, 'i' }, /* XK_dead_i */ + { 0xfe85, 'I' }, /* XK_dead_I */ + { 0xfe86, 'o' }, /* XK_dead_o */ + { 0xfe87, 'O' }, /* XK_dead_O */ + { 0xfe88, 'u' }, /* XK_dead_u */ + { 0xfe89, 'U' }, /* XK_dead_U */ + { 0xfe8a, 0x0259 }, + { 0xfe8b, 0x018f }, + { 0xfe8c, 0x00b5 }, + { 0xfe90, '_' }, + { 0xfe91, 0x02c8 }, + { 0xfe92, 0x02cc }, + { 0xff80 /*XKB_KEY_KP_Space*/, ' ' }, + { 0xff95 /*XKB_KEY_KP_7*/, 0x0037 }, + { 0xff96 /*XKB_KEY_KP_4*/, 0x0034 }, + { 0xff97 /*XKB_KEY_KP_8*/, 0x0038 }, + { 0xff98 /*XKB_KEY_KP_6*/, 0x0036 }, + { 0xff99 /*XKB_KEY_KP_2*/, 0x0032 }, + { 0xff9a /*XKB_KEY_KP_9*/, 0x0039 }, + { 0xff9b /*XKB_KEY_KP_3*/, 0x0033 }, + { 0xff9c /*XKB_KEY_KP_1*/, 0x0031 }, + { 0xff9d /*XKB_KEY_KP_5*/, 0x0035 }, + { 0xff9e /*XKB_KEY_KP_0*/, 0x0030 }, + { 0xffaa /*XKB_KEY_KP_Multiply*/, '*' }, + { 0xffab /*XKB_KEY_KP_Add*/, '+' }, + { 0xffac /*XKB_KEY_KP_Separator*/, ',' }, + { 0xffad /*XKB_KEY_KP_Subtract*/, '-' }, + { 0xffae /*XKB_KEY_KP_Decimal*/, '.' }, + { 0xffaf /*XKB_KEY_KP_Divide*/, '/' }, + { 0xffb0 /*XKB_KEY_KP_0*/, 0x0030 }, + { 0xffb1 /*XKB_KEY_KP_1*/, 0x0031 }, + { 0xffb2 /*XKB_KEY_KP_2*/, 0x0032 }, + { 0xffb3 /*XKB_KEY_KP_3*/, 0x0033 }, + { 0xffb4 /*XKB_KEY_KP_4*/, 0x0034 }, + { 0xffb5 /*XKB_KEY_KP_5*/, 0x0035 }, + { 0xffb6 /*XKB_KEY_KP_6*/, 0x0036 }, + { 0xffb7 /*XKB_KEY_KP_7*/, 0x0037 }, + { 0xffb8 /*XKB_KEY_KP_8*/, 0x0038 }, + { 0xffb9 /*XKB_KEY_KP_9*/, 0x0039 }, + { 0xffbd /*XKB_KEY_KP_Equal*/, '=' } +}; + +_SOKOL_PRIVATE int _sapp_x11_error_handler(Display* display, XErrorEvent* event) { + _SOKOL_UNUSED(display); + _sapp.x11.error_code = event->error_code; + return 0; +} + +_SOKOL_PRIVATE void _sapp_x11_grab_error_handler(void) { + _sapp.x11.error_code = Success; + XSetErrorHandler(_sapp_x11_error_handler); +} + +_SOKOL_PRIVATE void _sapp_x11_release_error_handler(void) { + XSync(_sapp.x11.display, False); + XSetErrorHandler(NULL); +} + +_SOKOL_PRIVATE void _sapp_x11_init_extensions(void) { + _sapp.x11.UTF8_STRING = XInternAtom(_sapp.x11.display, "UTF8_STRING", False); + _sapp.x11.WM_PROTOCOLS = XInternAtom(_sapp.x11.display, "WM_PROTOCOLS", False); + _sapp.x11.WM_DELETE_WINDOW = XInternAtom(_sapp.x11.display, "WM_DELETE_WINDOW", False); + _sapp.x11.WM_STATE = XInternAtom(_sapp.x11.display, "WM_STATE", False); + _sapp.x11.NET_WM_NAME = XInternAtom(_sapp.x11.display, "_NET_WM_NAME", False); + _sapp.x11.NET_WM_ICON_NAME = XInternAtom(_sapp.x11.display, "_NET_WM_ICON_NAME", False); + _sapp.x11.NET_WM_ICON = XInternAtom(_sapp.x11.display, "_NET_WM_ICON", False); + _sapp.x11.NET_WM_STATE = XInternAtom(_sapp.x11.display, "_NET_WM_STATE", False); + _sapp.x11.NET_WM_STATE_FULLSCREEN = XInternAtom(_sapp.x11.display, "_NET_WM_STATE_FULLSCREEN", False); + _sapp.x11.CLIPBOARD = XInternAtom(_sapp.x11.display, "CLIPBOARD", False); + _sapp.x11.TARGETS = XInternAtom(_sapp.x11.display, "TARGETS", False); + if (_sapp.drop.enabled) { + _sapp.x11.xdnd.XdndAware = XInternAtom(_sapp.x11.display, "XdndAware", False); + _sapp.x11.xdnd.XdndEnter = XInternAtom(_sapp.x11.display, "XdndEnter", False); + _sapp.x11.xdnd.XdndPosition = XInternAtom(_sapp.x11.display, "XdndPosition", False); + _sapp.x11.xdnd.XdndStatus = XInternAtom(_sapp.x11.display, "XdndStatus", False); + _sapp.x11.xdnd.XdndActionCopy = XInternAtom(_sapp.x11.display, "XdndActionCopy", False); + _sapp.x11.xdnd.XdndDrop = XInternAtom(_sapp.x11.display, "XdndDrop", False); + _sapp.x11.xdnd.XdndFinished = XInternAtom(_sapp.x11.display, "XdndFinished", False); + _sapp.x11.xdnd.XdndSelection = XInternAtom(_sapp.x11.display, "XdndSelection", False); + _sapp.x11.xdnd.XdndTypeList = XInternAtom(_sapp.x11.display, "XdndTypeList", False); + _sapp.x11.xdnd.text_uri_list = XInternAtom(_sapp.x11.display, "text/uri-list", False); + } + + /* check Xi extension for raw mouse input */ + if (XQueryExtension(_sapp.x11.display, "XInputExtension", &_sapp.x11.xi.major_opcode, &_sapp.x11.xi.event_base, &_sapp.x11.xi.error_base)) { + _sapp.x11.xi.major = 2; + _sapp.x11.xi.minor = 0; + if (XIQueryVersion(_sapp.x11.display, &_sapp.x11.xi.major, &_sapp.x11.xi.minor) == Success) { + _sapp.x11.xi.available = true; + } + } +} + +// translate the X11 KeySyms for a key to sokol-app key code +// NOTE: this is only used as a fallback, in case the XBK method fails +// it is layout-dependent and will fail partially on most non-US layouts. +// +_SOKOL_PRIVATE sapp_keycode _sapp_x11_translate_keysyms(const KeySym* keysyms, int width) { + if (width > 1) { + switch (keysyms[1]) { + case XK_KP_0: return SAPP_KEYCODE_KP_0; + case XK_KP_1: return SAPP_KEYCODE_KP_1; + case XK_KP_2: return SAPP_KEYCODE_KP_2; + case XK_KP_3: return SAPP_KEYCODE_KP_3; + case XK_KP_4: return SAPP_KEYCODE_KP_4; + case XK_KP_5: return SAPP_KEYCODE_KP_5; + case XK_KP_6: return SAPP_KEYCODE_KP_6; + case XK_KP_7: return SAPP_KEYCODE_KP_7; + case XK_KP_8: return SAPP_KEYCODE_KP_8; + case XK_KP_9: return SAPP_KEYCODE_KP_9; + case XK_KP_Separator: + case XK_KP_Decimal: return SAPP_KEYCODE_KP_DECIMAL; + case XK_KP_Equal: return SAPP_KEYCODE_KP_EQUAL; + case XK_KP_Enter: return SAPP_KEYCODE_KP_ENTER; + default: break; + } + } + + switch (keysyms[0]) { + case XK_Escape: return SAPP_KEYCODE_ESCAPE; + case XK_Tab: return SAPP_KEYCODE_TAB; + case XK_Shift_L: return SAPP_KEYCODE_LEFT_SHIFT; + case XK_Shift_R: return SAPP_KEYCODE_RIGHT_SHIFT; + case XK_Control_L: return SAPP_KEYCODE_LEFT_CONTROL; + case XK_Control_R: return SAPP_KEYCODE_RIGHT_CONTROL; + case XK_Meta_L: + case XK_Alt_L: return SAPP_KEYCODE_LEFT_ALT; + case XK_Mode_switch: // Mapped to Alt_R on many keyboards + case XK_ISO_Level3_Shift: // AltGr on at least some machines + case XK_Meta_R: + case XK_Alt_R: return SAPP_KEYCODE_RIGHT_ALT; + case XK_Super_L: return SAPP_KEYCODE_LEFT_SUPER; + case XK_Super_R: return SAPP_KEYCODE_RIGHT_SUPER; + case XK_Menu: return SAPP_KEYCODE_MENU; + case XK_Num_Lock: return SAPP_KEYCODE_NUM_LOCK; + case XK_Caps_Lock: return SAPP_KEYCODE_CAPS_LOCK; + case XK_Print: return SAPP_KEYCODE_PRINT_SCREEN; + case XK_Scroll_Lock: return SAPP_KEYCODE_SCROLL_LOCK; + case XK_Pause: return SAPP_KEYCODE_PAUSE; + case XK_Delete: return SAPP_KEYCODE_DELETE; + case XK_BackSpace: return SAPP_KEYCODE_BACKSPACE; + case XK_Return: return SAPP_KEYCODE_ENTER; + case XK_Home: return SAPP_KEYCODE_HOME; + case XK_End: return SAPP_KEYCODE_END; + case XK_Page_Up: return SAPP_KEYCODE_PAGE_UP; + case XK_Page_Down: return SAPP_KEYCODE_PAGE_DOWN; + case XK_Insert: return SAPP_KEYCODE_INSERT; + case XK_Left: return SAPP_KEYCODE_LEFT; + case XK_Right: return SAPP_KEYCODE_RIGHT; + case XK_Down: return SAPP_KEYCODE_DOWN; + case XK_Up: return SAPP_KEYCODE_UP; + case XK_F1: return SAPP_KEYCODE_F1; + case XK_F2: return SAPP_KEYCODE_F2; + case XK_F3: return SAPP_KEYCODE_F3; + case XK_F4: return SAPP_KEYCODE_F4; + case XK_F5: return SAPP_KEYCODE_F5; + case XK_F6: return SAPP_KEYCODE_F6; + case XK_F7: return SAPP_KEYCODE_F7; + case XK_F8: return SAPP_KEYCODE_F8; + case XK_F9: return SAPP_KEYCODE_F9; + case XK_F10: return SAPP_KEYCODE_F10; + case XK_F11: return SAPP_KEYCODE_F11; + case XK_F12: return SAPP_KEYCODE_F12; + case XK_F13: return SAPP_KEYCODE_F13; + case XK_F14: return SAPP_KEYCODE_F14; + case XK_F15: return SAPP_KEYCODE_F15; + case XK_F16: return SAPP_KEYCODE_F16; + case XK_F17: return SAPP_KEYCODE_F17; + case XK_F18: return SAPP_KEYCODE_F18; + case XK_F19: return SAPP_KEYCODE_F19; + case XK_F20: return SAPP_KEYCODE_F20; + case XK_F21: return SAPP_KEYCODE_F21; + case XK_F22: return SAPP_KEYCODE_F22; + case XK_F23: return SAPP_KEYCODE_F23; + case XK_F24: return SAPP_KEYCODE_F24; + case XK_F25: return SAPP_KEYCODE_F25; + + // numeric keypad + case XK_KP_Divide: return SAPP_KEYCODE_KP_DIVIDE; + case XK_KP_Multiply: return SAPP_KEYCODE_KP_MULTIPLY; + case XK_KP_Subtract: return SAPP_KEYCODE_KP_SUBTRACT; + case XK_KP_Add: return SAPP_KEYCODE_KP_ADD; + + // these should have been detected in secondary keysym test above! + case XK_KP_Insert: return SAPP_KEYCODE_KP_0; + case XK_KP_End: return SAPP_KEYCODE_KP_1; + case XK_KP_Down: return SAPP_KEYCODE_KP_2; + case XK_KP_Page_Down: return SAPP_KEYCODE_KP_3; + case XK_KP_Left: return SAPP_KEYCODE_KP_4; + case XK_KP_Right: return SAPP_KEYCODE_KP_6; + case XK_KP_Home: return SAPP_KEYCODE_KP_7; + case XK_KP_Up: return SAPP_KEYCODE_KP_8; + case XK_KP_Page_Up: return SAPP_KEYCODE_KP_9; + case XK_KP_Delete: return SAPP_KEYCODE_KP_DECIMAL; + case XK_KP_Equal: return SAPP_KEYCODE_KP_EQUAL; + case XK_KP_Enter: return SAPP_KEYCODE_KP_ENTER; + + // last resort: Check for printable keys (should not happen if the XKB + // extension is available). This will give a layout dependent mapping + // (which is wrong, and we may miss some keys, especially on non-US + // keyboards), but it's better than nothing... + case XK_a: return SAPP_KEYCODE_A; + case XK_b: return SAPP_KEYCODE_B; + case XK_c: return SAPP_KEYCODE_C; + case XK_d: return SAPP_KEYCODE_D; + case XK_e: return SAPP_KEYCODE_E; + case XK_f: return SAPP_KEYCODE_F; + case XK_g: return SAPP_KEYCODE_G; + case XK_h: return SAPP_KEYCODE_H; + case XK_i: return SAPP_KEYCODE_I; + case XK_j: return SAPP_KEYCODE_J; + case XK_k: return SAPP_KEYCODE_K; + case XK_l: return SAPP_KEYCODE_L; + case XK_m: return SAPP_KEYCODE_M; + case XK_n: return SAPP_KEYCODE_N; + case XK_o: return SAPP_KEYCODE_O; + case XK_p: return SAPP_KEYCODE_P; + case XK_q: return SAPP_KEYCODE_Q; + case XK_r: return SAPP_KEYCODE_R; + case XK_s: return SAPP_KEYCODE_S; + case XK_t: return SAPP_KEYCODE_T; + case XK_u: return SAPP_KEYCODE_U; + case XK_v: return SAPP_KEYCODE_V; + case XK_w: return SAPP_KEYCODE_W; + case XK_x: return SAPP_KEYCODE_X; + case XK_y: return SAPP_KEYCODE_Y; + case XK_z: return SAPP_KEYCODE_Z; + case XK_1: return SAPP_KEYCODE_1; + case XK_2: return SAPP_KEYCODE_2; + case XK_3: return SAPP_KEYCODE_3; + case XK_4: return SAPP_KEYCODE_4; + case XK_5: return SAPP_KEYCODE_5; + case XK_6: return SAPP_KEYCODE_6; + case XK_7: return SAPP_KEYCODE_7; + case XK_8: return SAPP_KEYCODE_8; + case XK_9: return SAPP_KEYCODE_9; + case XK_0: return SAPP_KEYCODE_0; + case XK_space: return SAPP_KEYCODE_SPACE; + case XK_minus: return SAPP_KEYCODE_MINUS; + case XK_equal: return SAPP_KEYCODE_EQUAL; + case XK_bracketleft: return SAPP_KEYCODE_LEFT_BRACKET; + case XK_bracketright: return SAPP_KEYCODE_RIGHT_BRACKET; + case XK_backslash: return SAPP_KEYCODE_BACKSLASH; + case XK_semicolon: return SAPP_KEYCODE_SEMICOLON; + case XK_apostrophe: return SAPP_KEYCODE_APOSTROPHE; + case XK_grave: return SAPP_KEYCODE_GRAVE_ACCENT; + case XK_comma: return SAPP_KEYCODE_COMMA; + case XK_period: return SAPP_KEYCODE_PERIOD; + case XK_slash: return SAPP_KEYCODE_SLASH; + case XK_less: return SAPP_KEYCODE_WORLD_1; // At least in some layouts... + default: break; + } + + // no matching translation was found + return SAPP_KEYCODE_INVALID; +} + + +// setup dynamic keycode/scancode mapping tables, this is required +// for getting layout-independent keycodes on X11. +// +// see GLFW x11_init.c/createKeyTables() +_SOKOL_PRIVATE void _sapp_x11_init_keytable(void) { + for (int i = 0; i < SAPP_MAX_KEYCODES; i++) { + _sapp.keycodes[i] = SAPP_KEYCODE_INVALID; + } + // use XKB to determine physical key locations independently of the current keyboard layout + XkbDescPtr desc = XkbGetMap(_sapp.x11.display, 0, XkbUseCoreKbd); + SOKOL_ASSERT(desc); + XkbGetNames(_sapp.x11.display, XkbKeyNamesMask | XkbKeyAliasesMask, desc); + + const int scancode_min = desc->min_key_code; + const int scancode_max = desc->max_key_code; + + const struct { sapp_keycode key; const char* name; } keymap[] = { + { SAPP_KEYCODE_GRAVE_ACCENT, "TLDE" }, + { SAPP_KEYCODE_1, "AE01" }, + { SAPP_KEYCODE_2, "AE02" }, + { SAPP_KEYCODE_3, "AE03" }, + { SAPP_KEYCODE_4, "AE04" }, + { SAPP_KEYCODE_5, "AE05" }, + { SAPP_KEYCODE_6, "AE06" }, + { SAPP_KEYCODE_7, "AE07" }, + { SAPP_KEYCODE_8, "AE08" }, + { SAPP_KEYCODE_9, "AE09" }, + { SAPP_KEYCODE_0, "AE10" }, + { SAPP_KEYCODE_MINUS, "AE11" }, + { SAPP_KEYCODE_EQUAL, "AE12" }, + { SAPP_KEYCODE_Q, "AD01" }, + { SAPP_KEYCODE_W, "AD02" }, + { SAPP_KEYCODE_E, "AD03" }, + { SAPP_KEYCODE_R, "AD04" }, + { SAPP_KEYCODE_T, "AD05" }, + { SAPP_KEYCODE_Y, "AD06" }, + { SAPP_KEYCODE_U, "AD07" }, + { SAPP_KEYCODE_I, "AD08" }, + { SAPP_KEYCODE_O, "AD09" }, + { SAPP_KEYCODE_P, "AD10" }, + { SAPP_KEYCODE_LEFT_BRACKET, "AD11" }, + { SAPP_KEYCODE_RIGHT_BRACKET, "AD12" }, + { SAPP_KEYCODE_A, "AC01" }, + { SAPP_KEYCODE_S, "AC02" }, + { SAPP_KEYCODE_D, "AC03" }, + { SAPP_KEYCODE_F, "AC04" }, + { SAPP_KEYCODE_G, "AC05" }, + { SAPP_KEYCODE_H, "AC06" }, + { SAPP_KEYCODE_J, "AC07" }, + { SAPP_KEYCODE_K, "AC08" }, + { SAPP_KEYCODE_L, "AC09" }, + { SAPP_KEYCODE_SEMICOLON, "AC10" }, + { SAPP_KEYCODE_APOSTROPHE, "AC11" }, + { SAPP_KEYCODE_Z, "AB01" }, + { SAPP_KEYCODE_X, "AB02" }, + { SAPP_KEYCODE_C, "AB03" }, + { SAPP_KEYCODE_V, "AB04" }, + { SAPP_KEYCODE_B, "AB05" }, + { SAPP_KEYCODE_N, "AB06" }, + { SAPP_KEYCODE_M, "AB07" }, + { SAPP_KEYCODE_COMMA, "AB08" }, + { SAPP_KEYCODE_PERIOD, "AB09" }, + { SAPP_KEYCODE_SLASH, "AB10" }, + { SAPP_KEYCODE_BACKSLASH, "BKSL" }, + { SAPP_KEYCODE_WORLD_1, "LSGT" }, + { SAPP_KEYCODE_SPACE, "SPCE" }, + { SAPP_KEYCODE_ESCAPE, "ESC" }, + { SAPP_KEYCODE_ENTER, "RTRN" }, + { SAPP_KEYCODE_TAB, "TAB" }, + { SAPP_KEYCODE_BACKSPACE, "BKSP" }, + { SAPP_KEYCODE_INSERT, "INS" }, + { SAPP_KEYCODE_DELETE, "DELE" }, + { SAPP_KEYCODE_RIGHT, "RGHT" }, + { SAPP_KEYCODE_LEFT, "LEFT" }, + { SAPP_KEYCODE_DOWN, "DOWN" }, + { SAPP_KEYCODE_UP, "UP" }, + { SAPP_KEYCODE_PAGE_UP, "PGUP" }, + { SAPP_KEYCODE_PAGE_DOWN, "PGDN" }, + { SAPP_KEYCODE_HOME, "HOME" }, + { SAPP_KEYCODE_END, "END" }, + { SAPP_KEYCODE_CAPS_LOCK, "CAPS" }, + { SAPP_KEYCODE_SCROLL_LOCK, "SCLK" }, + { SAPP_KEYCODE_NUM_LOCK, "NMLK" }, + { SAPP_KEYCODE_PRINT_SCREEN, "PRSC" }, + { SAPP_KEYCODE_PAUSE, "PAUS" }, + { SAPP_KEYCODE_F1, "FK01" }, + { SAPP_KEYCODE_F2, "FK02" }, + { SAPP_KEYCODE_F3, "FK03" }, + { SAPP_KEYCODE_F4, "FK04" }, + { SAPP_KEYCODE_F5, "FK05" }, + { SAPP_KEYCODE_F6, "FK06" }, + { SAPP_KEYCODE_F7, "FK07" }, + { SAPP_KEYCODE_F8, "FK08" }, + { SAPP_KEYCODE_F9, "FK09" }, + { SAPP_KEYCODE_F10, "FK10" }, + { SAPP_KEYCODE_F11, "FK11" }, + { SAPP_KEYCODE_F12, "FK12" }, + { SAPP_KEYCODE_F13, "FK13" }, + { SAPP_KEYCODE_F14, "FK14" }, + { SAPP_KEYCODE_F15, "FK15" }, + { SAPP_KEYCODE_F16, "FK16" }, + { SAPP_KEYCODE_F17, "FK17" }, + { SAPP_KEYCODE_F18, "FK18" }, + { SAPP_KEYCODE_F19, "FK19" }, + { SAPP_KEYCODE_F20, "FK20" }, + { SAPP_KEYCODE_F21, "FK21" }, + { SAPP_KEYCODE_F22, "FK22" }, + { SAPP_KEYCODE_F23, "FK23" }, + { SAPP_KEYCODE_F24, "FK24" }, + { SAPP_KEYCODE_F25, "FK25" }, + { SAPP_KEYCODE_KP_0, "KP0" }, + { SAPP_KEYCODE_KP_1, "KP1" }, + { SAPP_KEYCODE_KP_2, "KP2" }, + { SAPP_KEYCODE_KP_3, "KP3" }, + { SAPP_KEYCODE_KP_4, "KP4" }, + { SAPP_KEYCODE_KP_5, "KP5" }, + { SAPP_KEYCODE_KP_6, "KP6" }, + { SAPP_KEYCODE_KP_7, "KP7" }, + { SAPP_KEYCODE_KP_8, "KP8" }, + { SAPP_KEYCODE_KP_9, "KP9" }, + { SAPP_KEYCODE_KP_DECIMAL, "KPDL" }, + { SAPP_KEYCODE_KP_DIVIDE, "KPDV" }, + { SAPP_KEYCODE_KP_MULTIPLY, "KPMU" }, + { SAPP_KEYCODE_KP_SUBTRACT, "KPSU" }, + { SAPP_KEYCODE_KP_ADD, "KPAD" }, + { SAPP_KEYCODE_KP_ENTER, "KPEN" }, + { SAPP_KEYCODE_KP_EQUAL, "KPEQ" }, + { SAPP_KEYCODE_LEFT_SHIFT, "LFSH" }, + { SAPP_KEYCODE_LEFT_CONTROL, "LCTL" }, + { SAPP_KEYCODE_LEFT_ALT, "LALT" }, + { SAPP_KEYCODE_LEFT_SUPER, "LWIN" }, + { SAPP_KEYCODE_RIGHT_SHIFT, "RTSH" }, + { SAPP_KEYCODE_RIGHT_CONTROL, "RCTL" }, + { SAPP_KEYCODE_RIGHT_ALT, "RALT" }, + { SAPP_KEYCODE_RIGHT_ALT, "LVL3" }, + { SAPP_KEYCODE_RIGHT_ALT, "MDSW" }, + { SAPP_KEYCODE_RIGHT_SUPER, "RWIN" }, + { SAPP_KEYCODE_MENU, "MENU" } + }; + const int num_keymap_items = (int)(sizeof(keymap) / sizeof(keymap[0])); + + // find X11 keycode to sokol-app key code mapping + for (int scancode = scancode_min; scancode <= scancode_max; scancode++) { + sapp_keycode key = SAPP_KEYCODE_INVALID; + for (int i = 0; i < num_keymap_items; i++) { + if (strncmp(desc->names->keys[scancode].name, keymap[i].name, XkbKeyNameLength) == 0) { + key = keymap[i].key; + break; + } + } + + // fall back to key aliases in case the key name did not match + for (int i = 0; i < desc->names->num_key_aliases; i++) { + if (key != SAPP_KEYCODE_INVALID) { + break; + } + if (strncmp(desc->names->key_aliases[i].real, desc->names->keys[scancode].name, XkbKeyNameLength) != 0) { + continue; + } + for (int j = 0; j < num_keymap_items; j++) { + if (strncmp(desc->names->key_aliases[i].alias, keymap[j].name, XkbKeyNameLength) == 0) { + key = keymap[j].key; + break; + } + } + } + _sapp.keycodes[scancode] = key; + } + XkbFreeNames(desc, XkbKeyNamesMask, True); + XkbFreeKeyboard(desc, 0, True); + + int width = 0; + KeySym* keysyms = XGetKeyboardMapping(_sapp.x11.display, scancode_min, scancode_max - scancode_min + 1, &width); + for (int scancode = scancode_min; scancode <= scancode_max; scancode++) { + // translate untranslated key codes using the traditional X11 KeySym lookups + if (_sapp.keycodes[scancode] == SAPP_KEYCODE_INVALID) { + const size_t base = (size_t)((scancode - scancode_min) * width); + _sapp.keycodes[scancode] = _sapp_x11_translate_keysyms(&keysyms[base], width); + } + } + XFree(keysyms); +} + +_SOKOL_PRIVATE void _sapp_x11_query_system_dpi(void) { + /* from GLFW: + + NOTE: Default to the display-wide DPI as we don't currently have a policy + for which monitor a window is considered to be on + + _sapp.x11.dpi = DisplayWidth(_sapp.x11.display, _sapp.x11.screen) * + 25.4f / DisplayWidthMM(_sapp.x11.display, _sapp.x11.screen); + + NOTE: Basing the scale on Xft.dpi where available should provide the most + consistent user experience (matches Qt, Gtk, etc), although not + always the most accurate one + */ + bool dpi_ok = false; + char* rms = XResourceManagerString(_sapp.x11.display); + if (rms) { + XrmDatabase db = XrmGetStringDatabase(rms); + if (db) { + XrmValue value; + char* type = NULL; + if (XrmGetResource(db, "Xft.dpi", "Xft.Dpi", &type, &value)) { + if (type && strcmp(type, "String") == 0) { + _sapp.x11.dpi = atof(value.addr); + dpi_ok = true; + } + } + XrmDestroyDatabase(db); + } + } + // fallback if querying DPI had failed: assume the standard DPI 96.0f + if (!dpi_ok) { + _sapp.x11.dpi = 96.0f; + _SAPP_WARN(LINUX_X11_QUERY_SYSTEM_DPI_FAILED); + } +} + +#if defined(_SAPP_GLX) + +_SOKOL_PRIVATE bool _sapp_glx_has_ext(const char* ext, const char* extensions) { + SOKOL_ASSERT(ext); + const char* start = extensions; + while (true) { + const char* where = strstr(start, ext); + if (!where) { + return false; + } + const char* terminator = where + strlen(ext); + if ((where == start) || (*(where - 1) == ' ')) { + if (*terminator == ' ' || *terminator == '\0') { + break; + } + } + start = terminator; + } + return true; +} + +_SOKOL_PRIVATE bool _sapp_glx_extsupported(const char* ext, const char* extensions) { + if (extensions) { + return _sapp_glx_has_ext(ext, extensions); + } else { + return false; + } +} + +_SOKOL_PRIVATE void* _sapp_glx_getprocaddr(const char* procname) +{ + if (_sapp.glx.GetProcAddress) { + return (void*) _sapp.glx.GetProcAddress(procname); + } else if (_sapp.glx.GetProcAddressARB) { + return (void*) _sapp.glx.GetProcAddressARB(procname); + } else { + return dlsym(_sapp.glx.libgl, procname); + } +} + +_SOKOL_PRIVATE void _sapp_glx_init(void) { + const char* sonames[] = { "libGL.so.1", "libGL.so", 0 }; + for (int i = 0; sonames[i]; i++) { + _sapp.glx.libgl = dlopen(sonames[i], RTLD_LAZY|RTLD_GLOBAL); + if (_sapp.glx.libgl) { + break; + } + } + if (!_sapp.glx.libgl) { + _SAPP_PANIC(LINUX_GLX_LOAD_LIBGL_FAILED); + } + _sapp.glx.GetFBConfigs = (PFNGLXGETFBCONFIGSPROC) dlsym(_sapp.glx.libgl, "glXGetFBConfigs"); + _sapp.glx.GetFBConfigAttrib = (PFNGLXGETFBCONFIGATTRIBPROC) dlsym(_sapp.glx.libgl, "glXGetFBConfigAttrib"); + _sapp.glx.GetClientString = (PFNGLXGETCLIENTSTRINGPROC) dlsym(_sapp.glx.libgl, "glXGetClientString"); + _sapp.glx.QueryExtension = (PFNGLXQUERYEXTENSIONPROC) dlsym(_sapp.glx.libgl, "glXQueryExtension"); + _sapp.glx.QueryVersion = (PFNGLXQUERYVERSIONPROC) dlsym(_sapp.glx.libgl, "glXQueryVersion"); + _sapp.glx.DestroyContext = (PFNGLXDESTROYCONTEXTPROC) dlsym(_sapp.glx.libgl, "glXDestroyContext"); + _sapp.glx.MakeCurrent = (PFNGLXMAKECURRENTPROC) dlsym(_sapp.glx.libgl, "glXMakeCurrent"); + _sapp.glx.SwapBuffers = (PFNGLXSWAPBUFFERSPROC) dlsym(_sapp.glx.libgl, "glXSwapBuffers"); + _sapp.glx.QueryExtensionsString = (PFNGLXQUERYEXTENSIONSSTRINGPROC) dlsym(_sapp.glx.libgl, "glXQueryExtensionsString"); + _sapp.glx.CreateWindow = (PFNGLXCREATEWINDOWPROC) dlsym(_sapp.glx.libgl, "glXCreateWindow"); + _sapp.glx.DestroyWindow = (PFNGLXDESTROYWINDOWPROC) dlsym(_sapp.glx.libgl, "glXDestroyWindow"); + _sapp.glx.GetProcAddress = (PFNGLXGETPROCADDRESSPROC) dlsym(_sapp.glx.libgl, "glXGetProcAddress"); + _sapp.glx.GetProcAddressARB = (PFNGLXGETPROCADDRESSPROC) dlsym(_sapp.glx.libgl, "glXGetProcAddressARB"); + _sapp.glx.GetVisualFromFBConfig = (PFNGLXGETVISUALFROMFBCONFIGPROC) dlsym(_sapp.glx.libgl, "glXGetVisualFromFBConfig"); + if (!_sapp.glx.GetFBConfigs || + !_sapp.glx.GetFBConfigAttrib || + !_sapp.glx.GetClientString || + !_sapp.glx.QueryExtension || + !_sapp.glx.QueryVersion || + !_sapp.glx.DestroyContext || + !_sapp.glx.MakeCurrent || + !_sapp.glx.SwapBuffers || + !_sapp.glx.QueryExtensionsString || + !_sapp.glx.CreateWindow || + !_sapp.glx.DestroyWindow || + !_sapp.glx.GetProcAddress || + !_sapp.glx.GetProcAddressARB || + !_sapp.glx.GetVisualFromFBConfig) + { + _SAPP_PANIC(LINUX_GLX_LOAD_ENTRY_POINTS_FAILED); + } + + if (!_sapp.glx.QueryExtension(_sapp.x11.display, &_sapp.glx.error_base, &_sapp.glx.event_base)) { + _SAPP_PANIC(LINUX_GLX_EXTENSION_NOT_FOUND); + } + if (!_sapp.glx.QueryVersion(_sapp.x11.display, &_sapp.glx.major, &_sapp.glx.minor)) { + _SAPP_PANIC(LINUX_GLX_QUERY_VERSION_FAILED); + } + if (_sapp.glx.major == 1 && _sapp.glx.minor < 3) { + _SAPP_PANIC(LINUX_GLX_VERSION_TOO_LOW); + } + const char* exts = _sapp.glx.QueryExtensionsString(_sapp.x11.display, _sapp.x11.screen); + if (_sapp_glx_extsupported("GLX_EXT_swap_control", exts)) { + _sapp.glx.SwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC) _sapp_glx_getprocaddr("glXSwapIntervalEXT"); + _sapp.glx.EXT_swap_control = 0 != _sapp.glx.SwapIntervalEXT; + } + if (_sapp_glx_extsupported("GLX_MESA_swap_control", exts)) { + _sapp.glx.SwapIntervalMESA = (PFNGLXSWAPINTERVALMESAPROC) _sapp_glx_getprocaddr("glXSwapIntervalMESA"); + _sapp.glx.MESA_swap_control = 0 != _sapp.glx.SwapIntervalMESA; + } + _sapp.glx.ARB_multisample = _sapp_glx_extsupported("GLX_ARB_multisample", exts); + if (_sapp_glx_extsupported("GLX_ARB_create_context", exts)) { + _sapp.glx.CreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC) _sapp_glx_getprocaddr("glXCreateContextAttribsARB"); + _sapp.glx.ARB_create_context = 0 != _sapp.glx.CreateContextAttribsARB; + } + _sapp.glx.ARB_create_context_profile = _sapp_glx_extsupported("GLX_ARB_create_context_profile", exts); +} + +_SOKOL_PRIVATE int _sapp_glx_attrib(GLXFBConfig fbconfig, int attrib) { + int value; + _sapp.glx.GetFBConfigAttrib(_sapp.x11.display, fbconfig, attrib, &value); + return value; +} + +_SOKOL_PRIVATE GLXFBConfig _sapp_glx_choosefbconfig(void) { + GLXFBConfig* native_configs; + _sapp_gl_fbconfig* usable_configs; + const _sapp_gl_fbconfig* closest; + int i, native_count, usable_count; + const char* vendor; + bool trust_window_bit = true; + + /* HACK: This is a (hopefully temporary) workaround for Chromium + (VirtualBox GL) not setting the window bit on any GLXFBConfigs + */ + vendor = _sapp.glx.GetClientString(_sapp.x11.display, GLX_VENDOR); + if (vendor && strcmp(vendor, "Chromium") == 0) { + trust_window_bit = false; + } + + native_configs = _sapp.glx.GetFBConfigs(_sapp.x11.display, _sapp.x11.screen, &native_count); + if (!native_configs || !native_count) { + _SAPP_PANIC(LINUX_GLX_NO_GLXFBCONFIGS); + } + + usable_configs = (_sapp_gl_fbconfig*) _sapp_malloc_clear((size_t)native_count * sizeof(_sapp_gl_fbconfig)); + usable_count = 0; + for (i = 0; i < native_count; i++) { + const GLXFBConfig n = native_configs[i]; + _sapp_gl_fbconfig* u = usable_configs + usable_count; + _sapp_gl_init_fbconfig(u); + + /* Only consider RGBA GLXFBConfigs */ + if (0 == (_sapp_glx_attrib(n, GLX_RENDER_TYPE) & GLX_RGBA_BIT)) { + continue; + } + /* Only consider window GLXFBConfigs */ + if (0 == (_sapp_glx_attrib(n, GLX_DRAWABLE_TYPE) & GLX_WINDOW_BIT)) { + if (trust_window_bit) { + continue; + } + } + u->red_bits = _sapp_glx_attrib(n, GLX_RED_SIZE); + u->green_bits = _sapp_glx_attrib(n, GLX_GREEN_SIZE); + u->blue_bits = _sapp_glx_attrib(n, GLX_BLUE_SIZE); + u->alpha_bits = _sapp_glx_attrib(n, GLX_ALPHA_SIZE); + u->depth_bits = _sapp_glx_attrib(n, GLX_DEPTH_SIZE); + u->stencil_bits = _sapp_glx_attrib(n, GLX_STENCIL_SIZE); + if (_sapp_glx_attrib(n, GLX_DOUBLEBUFFER)) { + u->doublebuffer = true; + } + if (_sapp.glx.ARB_multisample) { + u->samples = _sapp_glx_attrib(n, GLX_SAMPLES); + } + u->handle = (uintptr_t) n; + usable_count++; + } + _sapp_gl_fbconfig desired; + _sapp_gl_init_fbconfig(&desired); + desired.red_bits = 8; + desired.green_bits = 8; + desired.blue_bits = 8; + desired.alpha_bits = 8; + desired.depth_bits = 24; + desired.stencil_bits = 8; + desired.doublebuffer = true; + desired.samples = _sapp.sample_count > 1 ? _sapp.sample_count : 0; + closest = _sapp_gl_choose_fbconfig(&desired, usable_configs, usable_count); + GLXFBConfig result = 0; + if (closest) { + result = (GLXFBConfig) closest->handle; + } + XFree(native_configs); + _sapp_free(usable_configs); + return result; +} + +_SOKOL_PRIVATE void _sapp_glx_choose_visual(Visual** visual, int* depth) { + GLXFBConfig native = _sapp_glx_choosefbconfig(); + if (0 == native) { + _SAPP_PANIC(LINUX_GLX_NO_SUITABLE_GLXFBCONFIG); + } + XVisualInfo* result = _sapp.glx.GetVisualFromFBConfig(_sapp.x11.display, native); + if (!result) { + _SAPP_PANIC(LINUX_GLX_GET_VISUAL_FROM_FBCONFIG_FAILED); + } + *visual = result->visual; + *depth = result->depth; + XFree(result); +} + +_SOKOL_PRIVATE void _sapp_glx_make_current(void) { + _sapp.glx.MakeCurrent(_sapp.x11.display, _sapp.glx.window, _sapp.glx.ctx); + glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint*)&_sapp.gl.framebuffer); +} + +_SOKOL_PRIVATE void _sapp_glx_create_context(void) { + GLXFBConfig native = _sapp_glx_choosefbconfig(); + if (0 == native){ + _SAPP_PANIC(LINUX_GLX_NO_SUITABLE_GLXFBCONFIG); + } + if (!(_sapp.glx.ARB_create_context && _sapp.glx.ARB_create_context_profile)) { + _SAPP_PANIC(LINUX_GLX_REQUIRED_EXTENSIONS_MISSING); + } + _sapp_x11_grab_error_handler(); + const int attribs[] = { + GLX_CONTEXT_MAJOR_VERSION_ARB, _sapp.desc.gl.major_version, + GLX_CONTEXT_MINOR_VERSION_ARB, _sapp.desc.gl.minor_version, + GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB, + GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, + 0, 0 + }; + _sapp.glx.ctx = _sapp.glx.CreateContextAttribsARB(_sapp.x11.display, native, NULL, True, attribs); + if (!_sapp.glx.ctx) { + _SAPP_PANIC(LINUX_GLX_CREATE_CONTEXT_FAILED); + } + _sapp_x11_release_error_handler(); + _sapp.glx.window = _sapp.glx.CreateWindow(_sapp.x11.display, native, _sapp.x11.window, NULL); + if (!_sapp.glx.window) { + _SAPP_PANIC(LINUX_GLX_CREATE_WINDOW_FAILED); + } + _sapp_glx_make_current(); +} + +_SOKOL_PRIVATE void _sapp_glx_destroy_context(void) { + if (_sapp.glx.window) { + _sapp.glx.DestroyWindow(_sapp.x11.display, _sapp.glx.window); + _sapp.glx.window = 0; + } + if (_sapp.glx.ctx) { + _sapp.glx.DestroyContext(_sapp.x11.display, _sapp.glx.ctx); + _sapp.glx.ctx = 0; + } +} + +_SOKOL_PRIVATE void _sapp_glx_swap_buffers(void) { + _sapp.glx.SwapBuffers(_sapp.x11.display, _sapp.glx.window); +} + +_SOKOL_PRIVATE void _sapp_glx_swapinterval(int interval) { + if (_sapp.glx.EXT_swap_control) { + _sapp.glx.SwapIntervalEXT(_sapp.x11.display, _sapp.glx.window, interval); + } else if (_sapp.glx.MESA_swap_control) { + _sapp.glx.SwapIntervalMESA(interval); + } +} + +#endif // _SAPP_GLX + +_SOKOL_PRIVATE void _sapp_x11_send_event(Atom type, int a, int b, int c, int d, int e) { + _SAPP_STRUCT(XEvent, event); + event.type = ClientMessage; + event.xclient.window = _sapp.x11.window; + event.xclient.format = 32; + event.xclient.message_type = type; + event.xclient.data.l[0] = a; + event.xclient.data.l[1] = b; + event.xclient.data.l[2] = c; + event.xclient.data.l[3] = d; + event.xclient.data.l[4] = e; + + XSendEvent(_sapp.x11.display, _sapp.x11.root, + False, + SubstructureNotifyMask | SubstructureRedirectMask, + &event); +} + +_SOKOL_PRIVATE bool _sapp_x11_wait_for_event(int event_type, double timeout_sec, XEvent* out_event) { + _sapp_timestamp_t ts; + _sapp_timestamp_init(&ts); + while (!XCheckTypedWindowEvent(_sapp.x11.display, _sapp.x11.window, event_type, out_event)) { + struct pollfd fd = { ConnectionNumber(_sapp.x11.display), POLLIN, 0 }; + poll(&fd, 1, timeout_sec * 1000); + if (_sapp_timestamp_now(&ts) > timeout_sec) { + return false; + } + } + return true; +} + +_SOKOL_PRIVATE void _sapp_x11_app_event(sapp_event_type type) { + if (_sapp_events_enabled()) { + _sapp_init_event(type); + _sapp_call_event(&_sapp.event); + } +} + +_SOKOL_PRIVATE void _sapp_x11_update_dimensions(int x11_window_width, int x11_window_height) { + // NOTE: do *NOT* use _sapp.dpi_scale for the window scale + const float window_scale = _sapp.x11.dpi / 96.0f; + _sapp.window_width = _sapp_roundf_gzero(x11_window_width / window_scale); + _sapp.window_height = _sapp_roundf_gzero(x11_window_height / window_scale); + // NOTE: on Vulkan, updating the framebuffer dimensions is entirely handled + // by the swapchain management code + #if !defined(SOKOL_VULKAN) + int cur_fb_width = _sapp.framebuffer_width; + int cur_fb_height = _sapp.framebuffer_height; + _sapp.framebuffer_width = _sapp_roundf_gzero(_sapp.window_width * _sapp.dpi_scale); + _sapp.framebuffer_height = _sapp_roundf_gzero(_sapp.window_height * _sapp.dpi_scale); + bool dim_changed = (_sapp.framebuffer_width != cur_fb_width) || (_sapp.framebuffer_height != cur_fb_height); + if (dim_changed) { + #if defined(SOKOL_WGPU) + _sapp_wgpu_swapchain_size_changed(); + #endif + if (!_sapp.first_frame) { + _sapp_x11_app_event(SAPP_EVENTTYPE_RESIZED); + } + } + #endif +} + +_SOKOL_PRIVATE void _sapp_x11_update_dimensions_from_window_size(void) { + XWindowAttributes attribs; + XGetWindowAttributes(_sapp.x11.display, _sapp.x11.window, &attribs); + _sapp_x11_update_dimensions(attribs.width, attribs.height); +} + +_SOKOL_PRIVATE void _sapp_x11_set_fullscreen(bool enable) { + /* NOTE: this function must be called after XMapWindow (which happens in _sapp_x11_show_window()) */ + if (_sapp.x11.NET_WM_STATE && _sapp.x11.NET_WM_STATE_FULLSCREEN) { + if (enable) { + const int _NET_WM_STATE_ADD = 1; + _sapp_x11_send_event(_sapp.x11.NET_WM_STATE, + _NET_WM_STATE_ADD, + _sapp.x11.NET_WM_STATE_FULLSCREEN, + 0, 1, 0); + } else { + const int _NET_WM_STATE_REMOVE = 0; + _sapp_x11_send_event(_sapp.x11.NET_WM_STATE, + _NET_WM_STATE_REMOVE, + _sapp.x11.NET_WM_STATE_FULLSCREEN, + 0, 1, 0); + } + } + XFlush(_sapp.x11.display); +} + +_SOKOL_PRIVATE void _sapp_x11_create_hidden_cursor(void) { + SOKOL_ASSERT(0 == _sapp.x11.hidden_cursor); + const int w = 16; + const int h = 16; + XcursorImage* img = XcursorImageCreate(w, h); + SOKOL_ASSERT(img && (img->width == 16) && (img->height == 16) && img->pixels); + img->xhot = 0; + img->yhot = 0; + const size_t num_bytes = (size_t)(w * h) * sizeof(XcursorPixel); + _sapp_clear(img->pixels, num_bytes); + _sapp.x11.hidden_cursor = XcursorImageLoadCursor(_sapp.x11.display, img); + XcursorImageDestroy(img); +} + + _SOKOL_PRIVATE void _sapp_x11_create_standard_cursor(sapp_mouse_cursor cursor, const char* name, const char* theme, int size, uint32_t fallback_native) { + SOKOL_ASSERT((cursor >= 0) && (cursor < _SAPP_MOUSECURSOR_NUM)); + SOKOL_ASSERT(_sapp.x11.display); + if (theme) { + XcursorImage* img = XcursorLibraryLoadImage(name, theme, size); + if (img) { + _sapp.x11.standard_cursors[cursor] = XcursorImageLoadCursor(_sapp.x11.display, img); + XcursorImageDestroy(img); + } + } + if (0 == _sapp.x11.standard_cursors[cursor]) { + _sapp.x11.standard_cursors[cursor] = XCreateFontCursor(_sapp.x11.display, fallback_native); + } +} + +_SOKOL_PRIVATE void _sapp_x11_create_standard_cursors(void) { + SOKOL_ASSERT(_sapp.x11.display); + const char* cursor_theme = XcursorGetTheme(_sapp.x11.display); + const int size = XcursorGetDefaultSize(_sapp.x11.display); + _sapp_x11_create_standard_cursor(SAPP_MOUSECURSOR_ARROW, "default", cursor_theme, size, XC_left_ptr); + _sapp_x11_create_standard_cursor(SAPP_MOUSECURSOR_IBEAM, "text", cursor_theme, size, XC_xterm); + _sapp_x11_create_standard_cursor(SAPP_MOUSECURSOR_CROSSHAIR, "crosshair", cursor_theme, size, XC_crosshair); + _sapp_x11_create_standard_cursor(SAPP_MOUSECURSOR_POINTING_HAND, "pointer", cursor_theme, size, XC_hand2); + _sapp_x11_create_standard_cursor(SAPP_MOUSECURSOR_RESIZE_EW, "ew-resize", cursor_theme, size, XC_sb_h_double_arrow); + _sapp_x11_create_standard_cursor(SAPP_MOUSECURSOR_RESIZE_NS, "ns-resize", cursor_theme, size, XC_sb_v_double_arrow); + _sapp_x11_create_standard_cursor(SAPP_MOUSECURSOR_RESIZE_NWSE, "nwse-resize", cursor_theme, size, 0); + _sapp_x11_create_standard_cursor(SAPP_MOUSECURSOR_RESIZE_NESW, "nesw-resize", cursor_theme, size, 0); + _sapp_x11_create_standard_cursor(SAPP_MOUSECURSOR_RESIZE_ALL, "all-scroll", cursor_theme, size, XC_fleur); + _sapp_x11_create_standard_cursor(SAPP_MOUSECURSOR_NOT_ALLOWED, "not-allowed", cursor_theme, size, 0); + _sapp_x11_create_hidden_cursor(); +} + +_SOKOL_PRIVATE void _sapp_x11_destroy_standard_cursors(void) { + SOKOL_ASSERT(_sapp.x11.display); + if (_sapp.x11.hidden_cursor) { + XFreeCursor(_sapp.x11.display, _sapp.x11.hidden_cursor); + _sapp.x11.hidden_cursor = 0; + } + for (int i = 0; i < _SAPP_MOUSECURSOR_NUM; i++) { + if (_sapp.x11.standard_cursors[i]) { + XFreeCursor(_sapp.x11.display, _sapp.x11.standard_cursors[i]); + _sapp.x11.standard_cursors[i] = 0; + } + } +} + +_SOKOL_PRIVATE bool _sapp_x11_make_custom_mouse_cursor(sapp_mouse_cursor cursor, const sapp_image_desc* desc) { + SOKOL_ASSERT((cursor >= 0) && (cursor < _SAPP_MOUSECURSOR_NUM)); + SOKOL_ASSERT(0 == _sapp.x11.custom_cursors[cursor]); + XcursorImage* img = XcursorImageCreate(desc->width, desc->height); + SOKOL_ASSERT(img && ((int) img->width == desc->width) && ((int) img->height == desc->height) && img->pixels); + img->xhot = (XcursorDim) desc->cursor_hotspot_x; + img->yhot = (XcursorDim) desc->cursor_hotspot_y; + const size_t dest_num_bytes = (size_t)(img->width * img->height) * sizeof(XcursorPixel); + SOKOL_ASSERT(dest_num_bytes == desc->pixels.size); + // Copy RGBA -> BGRA + for (size_t i = 0; i < dest_num_bytes; i += 4) { + ((uint8_t*) img->pixels)[i+0] = ((uint8_t*) desc->pixels.ptr)[i+2]; + ((uint8_t*) img->pixels)[i+1] = ((uint8_t*) desc->pixels.ptr)[i+1]; + ((uint8_t*) img->pixels)[i+2] = ((uint8_t*) desc->pixels.ptr)[i+0]; + ((uint8_t*) img->pixels)[i+3] = ((uint8_t*) desc->pixels.ptr)[i+3]; + } + _sapp.x11.custom_cursors[cursor] = XcursorImageLoadCursor(_sapp.x11.display, img); + XcursorImageDestroy(img); + return 0 != _sapp.x11.custom_cursors[cursor]; +} + +_SOKOL_PRIVATE void _sapp_x11_destroy_custom_mouse_cursor(sapp_mouse_cursor cursor) { + SOKOL_ASSERT((cursor >= 0) && (cursor < _SAPP_MOUSECURSOR_NUM)); + Cursor xcursor = _sapp.x11.custom_cursors[cursor]; + _sapp.x11.custom_cursors[cursor] = 0; + SOKOL_ASSERT(xcursor); + XFreeCursor(_sapp.x11.display, xcursor); +} + +_SOKOL_PRIVATE void _sapp_x11_toggle_fullscreen(void) { + _sapp.fullscreen = !_sapp.fullscreen; + _sapp_x11_set_fullscreen(_sapp.fullscreen); + _sapp_x11_update_dimensions_from_window_size(); +} + +_SOKOL_PRIVATE void _sapp_x11_update_cursor(sapp_mouse_cursor cursor, bool shown) { + SOKOL_ASSERT((cursor >= 0) && (cursor < _SAPP_MOUSECURSOR_NUM)); + if (shown) { + if (_sapp.custom_cursor_bound[cursor]) { + Cursor xcursor = _sapp.x11.custom_cursors[cursor]; + SOKOL_ASSERT(0 != xcursor); + XDefineCursor(_sapp.x11.display, _sapp.x11.window, xcursor); + } else if (_sapp.x11.standard_cursors[cursor]) { + XDefineCursor(_sapp.x11.display, _sapp.x11.window, _sapp.x11.standard_cursors[cursor]); + } else { + XUndefineCursor(_sapp.x11.display, _sapp.x11.window); + } + } else { + XDefineCursor(_sapp.x11.display, _sapp.x11.window, _sapp.x11.hidden_cursor); + } + XFlush(_sapp.x11.display); +} + +_SOKOL_PRIVATE void _sapp_x11_lock_mouse(bool lock) { + if (lock == _sapp.mouse.locked) { + return; + } + _sapp.mouse.dx = 0.0f; + _sapp.mouse.dy = 0.0f; + _sapp.mouse.locked = lock; + if (_sapp.mouse.locked) { + if (_sapp.x11.xi.available) { + XIEventMask em; + unsigned char mask[XIMaskLen(XI_RawMotion)] = { 0 }; // XIMaskLen is a macro + em.deviceid = XIAllMasterDevices; + em.mask_len = sizeof(mask); + em.mask = mask; + XISetMask(mask, XI_RawMotion); + XISelectEvents(_sapp.x11.display, _sapp.x11.root, &em, 1); + } + XGrabPointer(_sapp.x11.display, // display + _sapp.x11.window, // grab_window + True, // owner_events + ButtonPressMask | ButtonReleaseMask | PointerMotionMask, // event_mask + GrabModeAsync, // pointer_mode + GrabModeAsync, // keyboard_mode + _sapp.x11.window, // confine_to + _sapp.x11.hidden_cursor, // cursor + CurrentTime); // time + } else { + if (_sapp.x11.xi.available) { + XIEventMask em; + unsigned char mask[] = { 0 }; + em.deviceid = XIAllMasterDevices; + em.mask_len = sizeof(mask); + em.mask = mask; + XISelectEvents(_sapp.x11.display, _sapp.x11.root, &em, 1); + } + XWarpPointer(_sapp.x11.display, None, _sapp.x11.window, 0, 0, 0, 0, (int) _sapp.mouse.x, _sapp.mouse.y); + XUngrabPointer(_sapp.x11.display, CurrentTime); + } + XFlush(_sapp.x11.display); +} + +_SOKOL_PRIVATE void _sapp_x11_set_clipboard_string(const char* str) { + SOKOL_ASSERT(_sapp.clipboard.enabled && _sapp.clipboard.buffer); + if (strlen(str) >= (size_t)_sapp.clipboard.buf_size) { + _SAPP_ERROR(CLIPBOARD_STRING_TOO_BIG); + } + XSetSelectionOwner(_sapp.x11.display, _sapp.x11.CLIPBOARD, _sapp.x11.window, CurrentTime); + if (XGetSelectionOwner(_sapp.x11.display, _sapp.x11.CLIPBOARD) != _sapp.x11.window) { + _SAPP_ERROR(LINUX_X11_FAILED_TO_BECOME_OWNER_OF_CLIPBOARD); + } +} + +_SOKOL_PRIVATE const char* _sapp_x11_get_clipboard_string(void) { + SOKOL_ASSERT(_sapp.clipboard.enabled && _sapp.clipboard.buffer); + Atom none = XInternAtom(_sapp.x11.display, "SAPP_SELECTION", False); + Atom incremental = XInternAtom(_sapp.x11.display, "INCR", False); + if (XGetSelectionOwner(_sapp.x11.display, _sapp.x11.CLIPBOARD) == _sapp.x11.window) { + // Instead of doing a large number of X round-trips just to put this + // string into a window property and then read it back, just return it + return _sapp.clipboard.buffer; + } + XConvertSelection(_sapp.x11.display, + _sapp.x11.CLIPBOARD, + _sapp.x11.UTF8_STRING, + none, + _sapp.x11.window, + CurrentTime); + XEvent event; + if (!_sapp_x11_wait_for_event(SelectionNotify, 0.1, &event)) { + return NULL; + } + if (event.xselection.property == None) { + return NULL; + } + char* data = NULL; + Atom actualType; + int actualFormat; + unsigned long itemCount, bytesAfter; + const bool ret = XGetWindowProperty(_sapp.x11.display, + event.xselection.requestor, + event.xselection.property, + 0, + LONG_MAX, + True, + _sapp.x11.UTF8_STRING, + &actualType, + &actualFormat, + &itemCount, + &bytesAfter, + (unsigned char**) &data); + if (ret != Success || data == NULL) { + if (data != NULL) { + XFree(data); + } + return NULL; + } + if ((actualType == incremental) || (itemCount >= (size_t)_sapp.clipboard.buf_size)) { + _SAPP_ERROR(CLIPBOARD_STRING_TOO_BIG); + XFree(data); + return NULL; + } + _sapp_strcpy(data, _sapp.clipboard.buffer, (size_t)_sapp.clipboard.buf_size); + XFree(data); + return _sapp.clipboard.buffer; +} + +_SOKOL_PRIVATE void _sapp_x11_update_window_title(void) { + Xutf8SetWMProperties(_sapp.x11.display, + _sapp.x11.window, + _sapp.window_title, _sapp.window_title, + NULL, 0, NULL, NULL, NULL); + XChangeProperty(_sapp.x11.display, _sapp.x11.window, + _sapp.x11.NET_WM_NAME, _sapp.x11.UTF8_STRING, 8, + PropModeReplace, + (unsigned char*)_sapp.window_title, + strlen(_sapp.window_title)); + XChangeProperty(_sapp.x11.display, _sapp.x11.window, + _sapp.x11.NET_WM_ICON_NAME, _sapp.x11.UTF8_STRING, 8, + PropModeReplace, + (unsigned char*)_sapp.window_title, + strlen(_sapp.window_title)); + XFlush(_sapp.x11.display); +} + +_SOKOL_PRIVATE void _sapp_x11_set_icon(const sapp_icon_desc* icon_desc, int num_images) { + SOKOL_ASSERT((num_images > 0) && (num_images <= SAPP_MAX_ICONIMAGES)); + int long_count = 0; + for (int i = 0; i < num_images; i++) { + const sapp_image_desc* img_desc = &icon_desc->images[i]; + long_count += 2 + (img_desc->width * img_desc->height); + } + long* icon_data = (long*) _sapp_malloc_clear((size_t)long_count * sizeof(long)); + SOKOL_ASSERT(icon_data); + long* dst = icon_data; + for (int img_index = 0; img_index < num_images; img_index++) { + const sapp_image_desc* img_desc = &icon_desc->images[img_index]; + const uint8_t* src = (const uint8_t*) img_desc->pixels.ptr; + *dst++ = img_desc->width; + *dst++ = img_desc->height; + const int num_pixels = img_desc->width * img_desc->height; + for (int pixel_index = 0; pixel_index < num_pixels; pixel_index++) { + *dst++ = ((long)(src[pixel_index * 4 + 0]) << 16) | + ((long)(src[pixel_index * 4 + 1]) << 8) | + ((long)(src[pixel_index * 4 + 2]) << 0) | + ((long)(src[pixel_index * 4 + 3]) << 24); + } + } + XChangeProperty(_sapp.x11.display, _sapp.x11.window, + _sapp.x11.NET_WM_ICON, + XA_CARDINAL, 32, + PropModeReplace, + (unsigned char*)icon_data, + long_count); + _sapp_free(icon_data); + XFlush(_sapp.x11.display); +} + +_SOKOL_PRIVATE void _sapp_x11_create_window(Visual* visual_or_null, int depth) { + Visual* visual = visual_or_null; + if (0 == visual_or_null) { + visual = DefaultVisual(_sapp.x11.display, _sapp.x11.screen); + depth = DefaultDepth(_sapp.x11.display, _sapp.x11.screen); + } + _sapp.x11.colormap = XCreateColormap(_sapp.x11.display, _sapp.x11.root, visual, AllocNone); + _SAPP_STRUCT(XSetWindowAttributes, wa); + const uint32_t wamask = CWBorderPixel | CWColormap | CWEventMask; + wa.colormap = _sapp.x11.colormap; + wa.border_pixel = 0; + wa.event_mask = StructureNotifyMask | KeyPressMask | KeyReleaseMask | + PointerMotionMask | ButtonPressMask | ButtonReleaseMask | + ExposureMask | FocusChangeMask | VisibilityChangeMask | + EnterWindowMask | LeaveWindowMask | PropertyChangeMask; + + int display_width = DisplayWidth(_sapp.x11.display, _sapp.x11.screen); + int display_height = DisplayHeight(_sapp.x11.display, _sapp.x11.screen); + // NOTE: do *NOT* use _sapp.dpi_scale for the size multiplicator! + const float window_scale = _sapp.x11.dpi / 96.0f; + int x11_window_width = _sapp_roundf_gzero(_sapp.window_width * window_scale); + int x11_window_height = _sapp_roundf_gzero(_sapp.window_height * window_scale); + if (0 == _sapp.window_width) { + x11_window_width = (display_width * 4) / 5; + } + if (0 == _sapp.window_height) { + x11_window_height = (display_height * 4) / 5; + } + _sapp_x11_grab_error_handler(); + _sapp.x11.window = XCreateWindow(_sapp.x11.display, + _sapp.x11.root, + 0, 0, + (uint32_t)x11_window_width, + (uint32_t)x11_window_height, + 0, /* border width */ + depth, /* color depth */ + InputOutput, + visual, + wamask, + &wa); + _sapp_x11_release_error_handler(); + if (!_sapp.x11.window) { + _SAPP_PANIC(LINUX_X11_CREATE_WINDOW_FAILED); + } + Atom protocols[] = { + _sapp.x11.WM_DELETE_WINDOW + }; + XSetWMProtocols(_sapp.x11.display, _sapp.x11.window, protocols, 1); + + // NOTE: PPosition and PSize are obsolete and ignored + XSizeHints* hints = XAllocSizeHints(); + hints->flags = PWinGravity; + hints->win_gravity = CenterGravity; + XSetWMNormalHints(_sapp.x11.display, _sapp.x11.window, hints); + XFree(hints); + + // announce support for drag'n'drop + if (_sapp.drop.enabled) { + const Atom version = _SAPP_X11_XDND_VERSION; + XChangeProperty(_sapp.x11.display, _sapp.x11.window, _sapp.x11.xdnd.XdndAware, XA_ATOM, 32, PropModeReplace, (unsigned char*) &version, 1); + } + _sapp_x11_update_window_title(); + _sapp_x11_update_dimensions_from_window_size(); +} + +_SOKOL_PRIVATE void _sapp_x11_destroy_window(void) { + if (_sapp.x11.window) { + XUnmapWindow(_sapp.x11.display, _sapp.x11.window); + XDestroyWindow(_sapp.x11.display, _sapp.x11.window); + _sapp.x11.window = 0; + } + if (_sapp.x11.colormap) { + XFreeColormap(_sapp.x11.display, _sapp.x11.colormap); + _sapp.x11.colormap = 0; + } + XFlush(_sapp.x11.display); +} + +_SOKOL_PRIVATE bool _sapp_x11_window_visible(void) { + XWindowAttributes wa; + XGetWindowAttributes(_sapp.x11.display, _sapp.x11.window, &wa); + return wa.map_state == IsViewable; +} + +_SOKOL_PRIVATE void _sapp_x11_show_window(void) { + if (!_sapp_x11_window_visible()) { + XMapWindow(_sapp.x11.display, _sapp.x11.window); + XEvent dummy; + _sapp_x11_wait_for_event(VisibilityNotify, 0.1, &dummy); + XRaiseWindow(_sapp.x11.display, _sapp.x11.window); + XFlush(_sapp.x11.display); + } +} + +_SOKOL_PRIVATE void _sapp_x11_hide_window(void) { + XUnmapWindow(_sapp.x11.display, _sapp.x11.window); + XFlush(_sapp.x11.display); +} + +_SOKOL_PRIVATE unsigned long _sapp_x11_get_window_property(Window window, Atom property, Atom type, unsigned char** value) { + Atom actualType; + int actualFormat; + unsigned long itemCount, bytesAfter; + XGetWindowProperty(_sapp.x11.display, + window, + property, + 0, + LONG_MAX, + False, + type, + &actualType, + &actualFormat, + &itemCount, + &bytesAfter, + value); + return itemCount; +} + +_SOKOL_PRIVATE int _sapp_x11_get_window_state(void) { + int result = WithdrawnState; + struct { + CARD32 state; + Window icon; + } *state = NULL; + + if (_sapp_x11_get_window_property(_sapp.x11.window, _sapp.x11.WM_STATE, _sapp.x11.WM_STATE, (unsigned char**)&state) >= 2) { + result = (int)state->state; + } + if (state) { + XFree(state); + } + return result; +} + +_SOKOL_PRIVATE uint32_t _sapp_x11_key_modifier_bit(sapp_keycode key) { + switch (key) { + case SAPP_KEYCODE_LEFT_SHIFT: + case SAPP_KEYCODE_RIGHT_SHIFT: + return SAPP_MODIFIER_SHIFT; + case SAPP_KEYCODE_LEFT_CONTROL: + case SAPP_KEYCODE_RIGHT_CONTROL: + return SAPP_MODIFIER_CTRL; + case SAPP_KEYCODE_LEFT_ALT: + case SAPP_KEYCODE_RIGHT_ALT: + return SAPP_MODIFIER_ALT; + case SAPP_KEYCODE_LEFT_SUPER: + case SAPP_KEYCODE_RIGHT_SUPER: + return SAPP_MODIFIER_SUPER; + default: + return 0; + } +} + +_SOKOL_PRIVATE uint32_t _sapp_x11_button_modifier_bit(sapp_mousebutton btn) { + switch (btn) { + case SAPP_MOUSEBUTTON_LEFT: return SAPP_MODIFIER_LMB; + case SAPP_MOUSEBUTTON_RIGHT: return SAPP_MODIFIER_RMB; + case SAPP_MOUSEBUTTON_MIDDLE: return SAPP_MODIFIER_MMB; + default: return 0; + } +} + +_SOKOL_PRIVATE uint32_t _sapp_x11_mods(uint32_t x11_mods) { + uint32_t mods = 0; + if (x11_mods & ShiftMask) { + mods |= SAPP_MODIFIER_SHIFT; + } + if (x11_mods & ControlMask) { + mods |= SAPP_MODIFIER_CTRL; + } + if (x11_mods & Mod1Mask) { + mods |= SAPP_MODIFIER_ALT; + } + if (x11_mods & Mod4Mask) { + mods |= SAPP_MODIFIER_SUPER; + } + if (x11_mods & Button1Mask) { + mods |= SAPP_MODIFIER_LMB; + } + if (x11_mods & Button2Mask) { + mods |= SAPP_MODIFIER_MMB; + } + if (x11_mods & Button3Mask) { + mods |= SAPP_MODIFIER_RMB; + } + return mods; +} + +_SOKOL_PRIVATE sapp_mousebutton _sapp_x11_translate_button(const XEvent* event) { + switch (event->xbutton.button) { + case Button1: return SAPP_MOUSEBUTTON_LEFT; + case Button2: return SAPP_MOUSEBUTTON_MIDDLE; + case Button3: return SAPP_MOUSEBUTTON_RIGHT; + default: return SAPP_MOUSEBUTTON_INVALID; + } +} + +_SOKOL_PRIVATE void _sapp_x11_mouse_update(int x, int y, bool clear_dxdy) { + if (!_sapp.mouse.locked) { + const float new_x = (float)x; + const float new_y = (float)y; + if (clear_dxdy) { + _sapp.mouse.dx = 0.0f; + _sapp.mouse.dy = 0.0f; + } else if (_sapp.mouse.pos_valid) { + _sapp.mouse.dx = new_x - _sapp.mouse.x; + _sapp.mouse.dy = new_y - _sapp.mouse.y; + } + _sapp.mouse.x = new_x; + _sapp.mouse.y = new_y; + _sapp.mouse.pos_valid = true; + } +} + +_SOKOL_PRIVATE void _sapp_x11_mouse_event(sapp_event_type type, sapp_mousebutton btn, uint32_t mods) { + if (_sapp_events_enabled()) { + _sapp_init_event(type); + _sapp.event.mouse_button = btn; + _sapp.event.modifiers = mods; + _sapp_call_event(&_sapp.event); + } +} + +_SOKOL_PRIVATE void _sapp_x11_scroll_event(float x, float y, uint32_t mods) { + if (_sapp_events_enabled()) { + _sapp_init_event(SAPP_EVENTTYPE_MOUSE_SCROLL); + _sapp.event.modifiers = mods; + _sapp.event.scroll_x = x; + _sapp.event.scroll_y = y; + _sapp_call_event(&_sapp.event); + } +} + +_SOKOL_PRIVATE void _sapp_x11_key_event(sapp_event_type type, sapp_keycode key, bool repeat, uint32_t mods) { + if (_sapp_events_enabled()) { + _sapp_init_event(type); + _sapp.event.key_code = key; + _sapp.event.key_repeat = repeat; + _sapp.event.modifiers = mods; + _sapp_call_event(&_sapp.event); + /* check if a CLIPBOARD_PASTED event must be sent too */ + if (_sapp.clipboard.enabled && + (type == SAPP_EVENTTYPE_KEY_DOWN) && + (_sapp.event.modifiers == SAPP_MODIFIER_CTRL) && + (_sapp.event.key_code == SAPP_KEYCODE_V)) + { + _sapp_init_event(SAPP_EVENTTYPE_CLIPBOARD_PASTED); + _sapp_call_event(&_sapp.event); + } + } +} + +_SOKOL_PRIVATE void _sapp_x11_char_event(uint32_t chr, bool repeat, uint32_t mods) { + if (_sapp_events_enabled()) { + _sapp_init_event(SAPP_EVENTTYPE_CHAR); + _sapp.event.char_code = chr; + _sapp.event.key_repeat = repeat; + _sapp.event.modifiers = mods; + _sapp_call_event(&_sapp.event); + } +} + +_SOKOL_PRIVATE sapp_keycode _sapp_x11_translate_key(int scancode) { + if ((scancode >= 0) && (scancode < _SAPP_X11_MAX_X11_KEYCODES)) { + return _sapp.keycodes[scancode]; + } else { + return SAPP_KEYCODE_INVALID; + } +} + +_SOKOL_PRIVATE int32_t _sapp_x11_keysym_to_unicode(KeySym keysym) { + int min = 0; + int max = sizeof(_sapp_x11_keysymtab) / sizeof(struct _sapp_x11_codepair) - 1; + int mid; + + /* First check for Latin-1 characters (1:1 mapping) */ + if ((keysym >= 0x0020 && keysym <= 0x007e) || + (keysym >= 0x00a0 && keysym <= 0x00ff)) + { + return keysym; + } + + /* Also check for directly encoded 24-bit UCS characters */ + if ((keysym & 0xff000000) == 0x01000000) { + return keysym & 0x00ffffff; + } + + /* Binary search in table */ + while (max >= min) { + mid = (min + max) / 2; + if (_sapp_x11_keysymtab[mid].keysym < keysym) { + min = mid + 1; + } else if (_sapp_x11_keysymtab[mid].keysym > keysym) { + max = mid - 1; + } else { + return _sapp_x11_keysymtab[mid].ucs; + } + } + + /* No matching Unicode value found */ + return -1; +} + +_SOKOL_PRIVATE bool _sapp_x11_keypress_repeat(int keycode) { + bool repeat = false; + if ((keycode >= 0) && (keycode < _SAPP_X11_MAX_X11_KEYCODES)) { + repeat = _sapp.x11.key_repeat[keycode]; + _sapp.x11.key_repeat[keycode] = true; + } + return repeat; +} + +_SOKOL_PRIVATE void _sapp_x11_keyrelease_repeat(int keycode) { + if ((keycode >= 0) && (keycode < _SAPP_X11_MAX_X11_KEYCODES)) { + _sapp.x11.key_repeat[keycode] = false; + } +} + +_SOKOL_PRIVATE bool _sapp_x11_parse_dropped_files_list(const char* src) { + SOKOL_ASSERT(src); + SOKOL_ASSERT(_sapp.drop.buffer); + + _sapp_clear_drop_buffer(); + _sapp.drop.num_files = 0; + + /* + src is (potentially percent-encoded) string made of one or multiple paths + separated by \r\n, each path starting with 'file://' + */ + bool err = false; + int src_count = 0; + char src_chr = 0; + char* dst_ptr = _sapp.drop.buffer; + const char* dst_end_ptr = dst_ptr + (_sapp.drop.max_path_length - 1); // room for terminating 0 + while (0 != (src_chr = *src++)) { + src_count++; + char dst_chr = 0; + /* check leading 'file://' */ + if (src_count <= 7) { + if (((src_count == 1) && (src_chr != 'f')) || + ((src_count == 2) && (src_chr != 'i')) || + ((src_count == 3) && (src_chr != 'l')) || + ((src_count == 4) && (src_chr != 'e')) || + ((src_count == 5) && (src_chr != ':')) || + ((src_count == 6) && (src_chr != '/')) || + ((src_count == 7) && (src_chr != '/'))) + { + _SAPP_ERROR(LINUX_X11_DROPPED_FILE_URI_WRONG_SCHEME); + err = true; + break; + } + } else if (src_chr == '\r') { + // skip + } else if (src_chr == '\n') { + src_count = 0; + _sapp.drop.num_files++; + // too many files is not an error + if (_sapp.drop.num_files >= _sapp.drop.max_files) { + break; + } + dst_ptr = _sapp.drop.buffer + _sapp.drop.num_files * _sapp.drop.max_path_length; + dst_end_ptr = dst_ptr + (_sapp.drop.max_path_length - 1); + } else if ((src_chr == '%') && src[0] && src[1]) { + // a percent-encoded byte (most likely UTF-8 multibyte sequence) + const char digits[3] = { src[0], src[1], 0 }; + src += 2; + dst_chr = (char) strtol(digits, 0, 16); + } else { + dst_chr = src_chr; + } + if (dst_chr) { + // dst_end_ptr already has adjustment for terminating zero + if (dst_ptr < dst_end_ptr) { + *dst_ptr++ = dst_chr; + } else { + _SAPP_ERROR(DROPPED_FILE_PATH_TOO_LONG); + err = true; + break; + } + } + } + if (err) { + _sapp_clear_drop_buffer(); + _sapp.drop.num_files = 0; + return false; + } else { + return true; + } +} + +_SOKOL_PRIVATE void _sapp_x11_on_genericevent(XEvent* event) { + if (_sapp.mouse.locked && _sapp.x11.xi.available) { + if (event->xcookie.extension == _sapp.x11.xi.major_opcode) { + if (XGetEventData(_sapp.x11.display, &event->xcookie)) { + if (event->xcookie.evtype == XI_RawMotion) { + XIRawEvent* re = (XIRawEvent*) event->xcookie.data; + if (re->valuators.mask_len) { + const double* values = re->raw_values; + if (XIMaskIsSet(re->valuators.mask, 0)) { + _sapp.mouse.dx = (float) *values; + values++; + } + if (XIMaskIsSet(re->valuators.mask, 1)) { + _sapp.mouse.dy = (float) *values; + } + _sapp_x11_mouse_event(SAPP_EVENTTYPE_MOUSE_MOVE, SAPP_MOUSEBUTTON_INVALID, _sapp_x11_mods(event->xmotion.state)); + } + } + XFreeEventData(_sapp.x11.display, &event->xcookie); + } + } + } +} + +_SOKOL_PRIVATE void _sapp_x11_on_focusin(XEvent* event) { + // NOTE: ignoring NotifyGrab and NotifyUngrab is same behaviour as GLFW + if ((event->xfocus.mode != NotifyGrab) && (event->xfocus.mode != NotifyUngrab)) { + _sapp_x11_app_event(SAPP_EVENTTYPE_FOCUSED); + } +} + +_SOKOL_PRIVATE void _sapp_x11_on_focusout(XEvent* event) { + // if focus is lost for any reason, and we're in mouse locked mode, disable mouse lock + if (_sapp.mouse.locked) { + _sapp_x11_lock_mouse(false); + } + // NOTE: ignoring NotifyGrab and NotifyUngrab is same behaviour as GLFW + if ((event->xfocus.mode != NotifyGrab) && (event->xfocus.mode != NotifyUngrab)) { + _sapp_x11_app_event(SAPP_EVENTTYPE_UNFOCUSED); + } +} + +_SOKOL_PRIVATE void _sapp_x11_on_keypress(XEvent* event) { + int keycode = (int)event->xkey.keycode; + + const sapp_keycode key = _sapp_x11_translate_key(keycode); + const bool repeat = _sapp_x11_keypress_repeat(keycode); + uint32_t mods = _sapp_x11_mods(event->xkey.state); + // X11 doesn't set modifier bit on key down, so emulate that + mods |= _sapp_x11_key_modifier_bit(key); + if (key != SAPP_KEYCODE_INVALID) { + _sapp_x11_key_event(SAPP_EVENTTYPE_KEY_DOWN, key, repeat, mods); + } + KeySym keysym; + XLookupString(&event->xkey, NULL, 0, &keysym, NULL); + int32_t chr = _sapp_x11_keysym_to_unicode(keysym); + if (chr > 0) { + _sapp_x11_char_event((uint32_t)chr, repeat, mods); + } +} + +_SOKOL_PRIVATE void _sapp_x11_on_keyrelease(XEvent* event) { + int keycode = (int)event->xkey.keycode; + const sapp_keycode key = _sapp_x11_translate_key(keycode); + _sapp_x11_keyrelease_repeat(keycode); + if (key != SAPP_KEYCODE_INVALID) { + uint32_t mods = _sapp_x11_mods(event->xkey.state); + // X11 doesn't clear modifier bit on key up, so emulate that + mods &= ~_sapp_x11_key_modifier_bit(key); + _sapp_x11_key_event(SAPP_EVENTTYPE_KEY_UP, key, false, mods); + } +} + +_SOKOL_PRIVATE void _sapp_x11_on_buttonpress(XEvent* event) { + _sapp_x11_mouse_update(event->xbutton.x, event->xbutton.y, false); + const sapp_mousebutton btn = _sapp_x11_translate_button(event); + uint32_t mods = _sapp_x11_mods(event->xbutton.state); + // X11 doesn't set modifier bit on button down, so emulate that + mods |= _sapp_x11_button_modifier_bit(btn); + if (btn != SAPP_MOUSEBUTTON_INVALID) { + _sapp_x11_mouse_event(SAPP_EVENTTYPE_MOUSE_DOWN, btn, mods); + _sapp.x11.mouse_buttons |= (1 << btn); + } else { + // might be a scroll event + switch (event->xbutton.button) { + case 4: _sapp_x11_scroll_event(0.0f, 1.0f, mods); break; + case 5: _sapp_x11_scroll_event(0.0f, -1.0f, mods); break; + case 6: _sapp_x11_scroll_event(1.0f, 0.0f, mods); break; + case 7: _sapp_x11_scroll_event(-1.0f, 0.0f, mods); break; + } + } +} + +_SOKOL_PRIVATE void _sapp_x11_on_buttonrelease(XEvent* event) { + _sapp_x11_mouse_update(event->xbutton.x, event->xbutton.y, false); + const sapp_mousebutton btn = _sapp_x11_translate_button(event); + if (btn != SAPP_MOUSEBUTTON_INVALID) { + uint32_t mods = _sapp_x11_mods(event->xbutton.state); + // X11 doesn't clear modifier bit on button up, so emulate that + mods &= ~_sapp_x11_button_modifier_bit(btn); + _sapp_x11_mouse_event(SAPP_EVENTTYPE_MOUSE_UP, btn, mods); + _sapp.x11.mouse_buttons &= ~(1 << btn); + } +} + +_SOKOL_PRIVATE void _sapp_x11_on_enternotify(XEvent* event) { + // don't send enter/leave events while mouse button held down + if (0 == _sapp.x11.mouse_buttons) { + _sapp_x11_mouse_update(event->xcrossing.x, event->xcrossing.y, true); + _sapp_x11_mouse_event(SAPP_EVENTTYPE_MOUSE_ENTER, SAPP_MOUSEBUTTON_INVALID, _sapp_x11_mods(event->xcrossing.state)); + } +} + +_SOKOL_PRIVATE void _sapp_x11_on_leavenotify(XEvent* event) { + if (0 == _sapp.x11.mouse_buttons) { + _sapp_x11_mouse_update(event->xcrossing.x, event->xcrossing.y, true); + _sapp_x11_mouse_event(SAPP_EVENTTYPE_MOUSE_LEAVE, SAPP_MOUSEBUTTON_INVALID, _sapp_x11_mods(event->xcrossing.state)); + } +} + +_SOKOL_PRIVATE void _sapp_x11_on_motionnotify(XEvent* event) { + if (!_sapp.mouse.locked) { + _sapp_x11_mouse_update(event->xmotion.x, event->xmotion.y, false); + _sapp_x11_mouse_event(SAPP_EVENTTYPE_MOUSE_MOVE, SAPP_MOUSEBUTTON_INVALID, _sapp_x11_mods(event->xmotion.state)); + } +} + +_SOKOL_PRIVATE void _sapp_x11_on_propertynotify(XEvent* event) { + if (event->xproperty.state == PropertyNewValue) { + if (event->xproperty.atom == _sapp.x11.WM_STATE) { + const int state = _sapp_x11_get_window_state(); + if (state != _sapp.x11.window_state) { + _sapp.x11.window_state = state; + if (state == IconicState) { + _sapp_x11_app_event(SAPP_EVENTTYPE_ICONIFIED); + } else if (state == NormalState) { + _sapp_x11_app_event(SAPP_EVENTTYPE_RESTORED); + } + } + } + } +} + +_SOKOL_PRIVATE void _sapp_x11_on_selectionnotify(XEvent* event) { + if (event->xselection.property == _sapp.x11.xdnd.XdndSelection) { + char* data = 0; + uint32_t result = _sapp_x11_get_window_property(event->xselection.requestor, + event->xselection.property, + event->xselection.target, + (unsigned char**) &data); + if (_sapp.drop.enabled && result) { + if (_sapp_x11_parse_dropped_files_list(data)) { + _sapp.mouse.dx = 0.0f; + _sapp.mouse.dy = 0.0f; + if (_sapp_events_enabled()) { + // FIXME: Figure out how to get modifier key state here. + // The XSelection event has no 'state' item, and + // XQueryKeymap() always returns a zeroed array. + _sapp_init_event(SAPP_EVENTTYPE_FILES_DROPPED); + _sapp_call_event(&_sapp.event); + } + } + } + if (_sapp.x11.xdnd.version >= 2) { + _SAPP_STRUCT(XEvent, reply); + reply.type = ClientMessage; + reply.xclient.window = _sapp.x11.xdnd.source; + reply.xclient.message_type = _sapp.x11.xdnd.XdndFinished; + reply.xclient.format = 32; + reply.xclient.data.l[0] = (long)_sapp.x11.window; + reply.xclient.data.l[1] = result; + reply.xclient.data.l[2] = (long)_sapp.x11.xdnd.XdndActionCopy; + XSendEvent(_sapp.x11.display, _sapp.x11.xdnd.source, False, NoEventMask, &reply); + XFlush(_sapp.x11.display); + } + if (data) { + XFree(data); + } + } +} + +_SOKOL_PRIVATE void _sapp_x11_on_clientmessage(XEvent* event) { + if (XFilterEvent(event, None)) { + return; + } + if (event->xclient.message_type == _sapp.x11.WM_PROTOCOLS) { + const Atom protocol = (Atom)event->xclient.data.l[0]; + if (protocol == _sapp.x11.WM_DELETE_WINDOW) { + _sapp.quit_requested = true; + } + } else if (event->xclient.message_type == _sapp.x11.xdnd.XdndEnter) { + const bool is_list = 0 != (event->xclient.data.l[1] & 1); + _sapp.x11.xdnd.source = (Window)event->xclient.data.l[0]; + _sapp.x11.xdnd.version = event->xclient.data.l[1] >> 24; + _sapp.x11.xdnd.format = None; + if (_sapp.x11.xdnd.version > _SAPP_X11_XDND_VERSION) { + return; + } + uint32_t count = 0; + Atom* formats = 0; + if (is_list) { + count = _sapp_x11_get_window_property(_sapp.x11.xdnd.source, _sapp.x11.xdnd.XdndTypeList, XA_ATOM, (unsigned char**)&formats); + } else { + count = 3; + formats = (Atom*) event->xclient.data.l + 2; + } + for (uint32_t i = 0; i < count; i++) { + if (formats[i] == _sapp.x11.xdnd.text_uri_list) { + _sapp.x11.xdnd.format = _sapp.x11.xdnd.text_uri_list; + break; + } + } + if (is_list && formats) { + XFree(formats); + } + } else if (event->xclient.message_type == _sapp.x11.xdnd.XdndDrop) { + if (_sapp.x11.xdnd.version > _SAPP_X11_XDND_VERSION) { + return; + } + Time time = CurrentTime; + if (_sapp.x11.xdnd.format) { + if (_sapp.x11.xdnd.version >= 1) { + time = (Time)event->xclient.data.l[2]; + } + XConvertSelection(_sapp.x11.display, + _sapp.x11.xdnd.XdndSelection, + _sapp.x11.xdnd.format, + _sapp.x11.xdnd.XdndSelection, + _sapp.x11.window, + time); + } else if (_sapp.x11.xdnd.version >= 2) { + _SAPP_STRUCT(XEvent, reply); + reply.type = ClientMessage; + reply.xclient.window = _sapp.x11.xdnd.source; + reply.xclient.message_type = _sapp.x11.xdnd.XdndFinished; + reply.xclient.format = 32; + reply.xclient.data.l[0] = (long)_sapp.x11.window; + reply.xclient.data.l[1] = 0; // drag was rejected + reply.xclient.data.l[2] = None; + XSendEvent(_sapp.x11.display, _sapp.x11.xdnd.source, False, NoEventMask, &reply); + XFlush(_sapp.x11.display); + } + } else if (event->xclient.message_type == _sapp.x11.xdnd.XdndPosition) { + // drag operation has moved over the window + // FIXME: we could track the mouse position here, but + // this isn't implemented on other platforms either so far + if (_sapp.x11.xdnd.version > _SAPP_X11_XDND_VERSION) { + return; + } + _SAPP_STRUCT(XEvent, reply); + reply.type = ClientMessage; + reply.xclient.window = _sapp.x11.xdnd.source; + reply.xclient.message_type = _sapp.x11.xdnd.XdndStatus; + reply.xclient.format = 32; + reply.xclient.data.l[0] = (long)_sapp.x11.window; + if (_sapp.x11.xdnd.format) { + /* reply that we are ready to copy the dragged data */ + reply.xclient.data.l[1] = 1; // accept with no rectangle + if (_sapp.x11.xdnd.version >= 2) { + reply.xclient.data.l[4] = (long)_sapp.x11.xdnd.XdndActionCopy; + } + } + XSendEvent(_sapp.x11.display, _sapp.x11.xdnd.source, False, NoEventMask, &reply); + XFlush(_sapp.x11.display); + } +} + +_SOKOL_PRIVATE void _sapp_x11_on_selectionrequest(XEvent* event) { + XSelectionRequestEvent* req = &event->xselectionrequest; + if (req->selection != _sapp.x11.CLIPBOARD) { + return; + } + if (!_sapp.clipboard.enabled) { + return; + } + SOKOL_ASSERT(_sapp.clipboard.buffer); + _SAPP_STRUCT(XSelectionEvent, reply); + reply.type = SelectionNotify; + reply.display = req->display; + reply.requestor = req->requestor; + reply.selection = req->selection; + reply.target = req->target; + reply.property = req->property; + reply.time = req->time; + if (req->target == _sapp.x11.UTF8_STRING) { + XChangeProperty(_sapp.x11.display, + req->requestor, + req->property, + _sapp.x11.UTF8_STRING, + 8, + PropModeReplace, + (unsigned char*) _sapp.clipboard.buffer, + strlen(_sapp.clipboard.buffer)); + } else if (req->target == _sapp.x11.TARGETS) { + XChangeProperty(_sapp.x11.display, + req->requestor, + req->property, + XA_ATOM, + 32, + PropModeReplace, + (unsigned char*) &_sapp.x11.UTF8_STRING, + 1); + } else { + reply.property = None; + } + XSendEvent(_sapp.x11.display, req->requestor, False, 0, (XEvent*) &reply); +} + +_SOKOL_PRIVATE void _sapp_x11_process_event(XEvent* event) { + switch (event->type) { + case GenericEvent: + _sapp_x11_on_genericevent(event); + break; + case FocusIn: + _sapp_x11_on_focusin(event); + break; + case FocusOut: + _sapp_x11_on_focusout(event); + break; + case KeyPress: + _sapp_x11_on_keypress(event); + break; + case KeyRelease: + _sapp_x11_on_keyrelease(event); + break; + case ButtonPress: + _sapp_x11_on_buttonpress(event); + break; + case ButtonRelease: + _sapp_x11_on_buttonrelease(event); + break; + case EnterNotify: + _sapp_x11_on_enternotify(event); + break; + case LeaveNotify: + _sapp_x11_on_leavenotify(event); + break; + case MotionNotify: + _sapp_x11_on_motionnotify(event); + break; + case PropertyNotify: + _sapp_x11_on_propertynotify(event); + break; + case SelectionNotify: + _sapp_x11_on_selectionnotify(event); + break; + case SelectionRequest: + _sapp_x11_on_selectionrequest(event); + break; + case DestroyNotify: + // not a bug + break; + case ClientMessage: + _sapp_x11_on_clientmessage(event); + break; + } +} + +#if defined(_SAPP_EGL) + +_SOKOL_PRIVATE void _sapp_egl_init(void) { + #if defined(SOKOL_GLCORE) + if (!eglBindAPI(EGL_OPENGL_API)) { + _SAPP_PANIC(LINUX_EGL_BIND_OPENGL_API_FAILED); + } + #else + if (!eglBindAPI(EGL_OPENGL_ES_API)) { + _SAPP_PANIC(LINUX_EGL_BIND_OPENGL_ES_API_FAILED); + } + #endif + + _sapp.egl.display = eglGetDisplay((EGLNativeDisplayType)_sapp.x11.display); + if (EGL_NO_DISPLAY == _sapp.egl.display) { + _SAPP_PANIC(LINUX_EGL_GET_DISPLAY_FAILED); + } + + EGLint major, minor; + if (!eglInitialize(_sapp.egl.display, &major, &minor)) { + _SAPP_PANIC(LINUX_EGL_INITIALIZE_FAILED); + } + + EGLint sample_count = _sapp.desc.sample_count > 1 ? _sapp.desc.sample_count : 0; + EGLint alpha_size = _sapp.desc.alpha ? 8 : 0; + const EGLint config_attrs[] = { + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, + #if defined(SOKOL_GLCORE) + EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, + #elif defined(SOKOL_GLES3) + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT, + #endif + EGL_RED_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_BLUE_SIZE, 8, + EGL_ALPHA_SIZE, alpha_size, + EGL_DEPTH_SIZE, 24, + EGL_STENCIL_SIZE, 8, + EGL_SAMPLE_BUFFERS, _sapp.desc.sample_count > 1 ? 1 : 0, + EGL_SAMPLES, sample_count, + EGL_NONE, + }; + + EGLConfig egl_configs[32]; + EGLint config_count; + if (!eglChooseConfig(_sapp.egl.display, config_attrs, egl_configs, 32, &config_count) || config_count == 0) { + _SAPP_PANIC(LINUX_EGL_NO_CONFIGS); + } + + EGLConfig config = egl_configs[0]; + for (int i = 0; i < config_count; ++i) { + EGLConfig c = egl_configs[i]; + EGLint r, g, b, a, d, s, n; + if (eglGetConfigAttrib(_sapp.egl.display, c, EGL_RED_SIZE, &r) && + eglGetConfigAttrib(_sapp.egl.display, c, EGL_GREEN_SIZE, &g) && + eglGetConfigAttrib(_sapp.egl.display, c, EGL_BLUE_SIZE, &b) && + eglGetConfigAttrib(_sapp.egl.display, c, EGL_ALPHA_SIZE, &a) && + eglGetConfigAttrib(_sapp.egl.display, c, EGL_DEPTH_SIZE, &d) && + eglGetConfigAttrib(_sapp.egl.display, c, EGL_STENCIL_SIZE, &s) && + eglGetConfigAttrib(_sapp.egl.display, c, EGL_SAMPLES, &n) && + (r == 8) && (g == 8) && (b == 8) && (a == alpha_size) && (d == 24) && (s == 8) && (n == sample_count)) { + config = c; + break; + } + } + + EGLint visual_id; + if (!eglGetConfigAttrib(_sapp.egl.display, config, EGL_NATIVE_VISUAL_ID, &visual_id)) { + _SAPP_PANIC(LINUX_EGL_NO_NATIVE_VISUAL); + } + + _SAPP_STRUCT(XVisualInfo, visual_info_template); + visual_info_template.visualid = (VisualID)visual_id; + + int num_visuals; + XVisualInfo* visual_info = XGetVisualInfo(_sapp.x11.display, VisualIDMask, &visual_info_template, &num_visuals); + if (!visual_info) { + _SAPP_PANIC(LINUX_EGL_GET_VISUAL_INFO_FAILED); + } + + _sapp_x11_create_window(visual_info->visual, visual_info->depth); + XFree(visual_info); + + _sapp.egl.surface = eglCreateWindowSurface(_sapp.egl.display, config, (EGLNativeWindowType)_sapp.x11.window, NULL); + if (EGL_NO_SURFACE == _sapp.egl.surface) { + _SAPP_PANIC(LINUX_EGL_CREATE_WINDOW_SURFACE_FAILED); + } + + EGLint ctx_attrs[] = { + EGL_CONTEXT_MAJOR_VERSION, _sapp.desc.gl.major_version, + EGL_CONTEXT_MINOR_VERSION, _sapp.desc.gl.minor_version, + #if defined(SOKOL_GLCORE) + EGL_CONTEXT_OPENGL_PROFILE_MASK, EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT, + #endif + EGL_NONE, + }; + + _sapp.egl.context = eglCreateContext(_sapp.egl.display, config, EGL_NO_CONTEXT, ctx_attrs); + if (EGL_NO_CONTEXT == _sapp.egl.context) { + _SAPP_PANIC(LINUX_EGL_CREATE_CONTEXT_FAILED); + } + + if (!eglMakeCurrent(_sapp.egl.display, _sapp.egl.surface, _sapp.egl.surface, _sapp.egl.context)) { + _SAPP_PANIC(LINUX_EGL_MAKE_CURRENT_FAILED); + } + glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint*)&_sapp.gl.framebuffer); + + eglSwapInterval(_sapp.egl.display, _sapp.swap_interval); +} + +_SOKOL_PRIVATE void _sapp_egl_destroy(void) { + if (_sapp.egl.display != EGL_NO_DISPLAY) { + eglMakeCurrent(_sapp.egl.display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + + if (_sapp.egl.context != EGL_NO_CONTEXT) { + eglDestroyContext(_sapp.egl.display, _sapp.egl.context); + _sapp.egl.context = EGL_NO_CONTEXT; + } + + if (_sapp.egl.surface != EGL_NO_SURFACE) { + eglDestroySurface(_sapp.egl.display, _sapp.egl.surface); + _sapp.egl.surface = EGL_NO_SURFACE; + } + + eglTerminate(_sapp.egl.display); + _sapp.egl.display = EGL_NO_DISPLAY; + } +} + +#endif // _SAPP_EGL + +_SOKOL_PRIVATE void _sapp_linux_frame(void) { + _sapp_x11_update_dimensions_from_window_size(); + #if defined(SOKOL_WGPU) + _sapp_wgpu_frame(); + #elif defined(SOKOL_VULKAN) + _sapp_vk_frame(); + #else + _sapp_frame(); + #if defined(_SAPP_GLX) + _sapp_glx_swap_buffers(); + #elif defined(_SAPP_EGL) + eglSwapBuffers(_sapp.egl.display, _sapp.egl.surface); + #endif + #endif +} + +_SOKOL_PRIVATE void _sapp_linux_run(const sapp_desc* desc) { + /* The following lines are here to trigger a linker error instead of an + obscure runtime error if the user has forgotten to add -pthread to + the compiler or linker options. They have no other purpose. + */ + pthread_attr_t pthread_attr; + pthread_attr_init(&pthread_attr); + pthread_attr_destroy(&pthread_attr); + + _sapp_init_state(desc); + _sapp.x11.window_state = NormalState; + + XInitThreads(); + XrmInitialize(); + _sapp.x11.display = XOpenDisplay(NULL); + if (!_sapp.x11.display) { + _SAPP_PANIC(LINUX_X11_OPEN_DISPLAY_FAILED); + } + _sapp.x11.screen = DefaultScreen(_sapp.x11.display); + _sapp.x11.root = DefaultRootWindow(_sapp.x11.display); + _sapp_x11_query_system_dpi(); + // NOTE: on Linux system-window-size to frame-buffer-size mapping is always 1:1 + _sapp.dpi_scale = _sapp.x11.dpi / 96.0f; + _sapp_x11_init_extensions(); + _sapp_x11_create_standard_cursors(); + XkbSetDetectableAutoRepeat(_sapp.x11.display, true, NULL); + _sapp_x11_init_keytable(); + #if defined(_SAPP_GLX) + _sapp_glx_init(); + Visual* visual = 0; + int depth = 0; + _sapp_glx_choose_visual(&visual, &depth); + _sapp_x11_create_window(visual, depth); + _sapp_glx_create_context(); + _sapp_glx_swapinterval(_sapp.swap_interval); + #elif defined(_SAPP_EGL) + _sapp_egl_init(); + #elif defined(SOKOL_WGPU) + _sapp_x11_create_window(0, 0); + _sapp_wgpu_init(); + #elif defined(SOKOL_VULKAN) + _sapp_x11_create_window(0, 0); + _sapp_vk_init(); + #endif + sapp_set_icon(&desc->icon); + _sapp.valid = true; + _sapp_x11_show_window(); + if (_sapp.fullscreen) { + _sapp_x11_set_fullscreen(true); + } + + XFlush(_sapp.x11.display); + while (!_sapp.quit_ordered) { + _sapp_timing_update(&_sapp.timing, 0.0); + int count = XPending(_sapp.x11.display); + while (count--) { + XEvent event; + XNextEvent(_sapp.x11.display, &event); + _sapp_x11_process_event(&event); + } + _sapp_linux_frame(); + XFlush(_sapp.x11.display); + // handle quit-requested, either from window or from sapp_request_quit() + if (_sapp.quit_requested && !_sapp.quit_ordered) { + // give user code a chance to intervene + _sapp_x11_app_event(SAPP_EVENTTYPE_QUIT_REQUESTED); + /* if user code hasn't intervened, quit the app */ + if (_sapp.quit_requested) { + _sapp.quit_ordered = true; + } + } + } + _sapp_call_cleanup(); + #if defined(_SAPP_GLX) + _sapp_glx_destroy_context(); + #elif defined(_SAPP_EGL) + _sapp_egl_destroy(); + #elif defined(SOKOL_WGPU) + _sapp_wgpu_discard(); + #elif defined(SOKOL_VULKAN) + _sapp_vk_discard(); + #endif + _sapp_x11_destroy_window(); + _sapp_x11_destroy_standard_cursors(); + XCloseDisplay(_sapp.x11.display); + _sapp_discard_state(); +} + +#if !defined(SOKOL_NO_ENTRY) +int main(int argc, char* argv[]) { + sapp_desc desc = sokol_main(argc, argv); + _sapp_linux_run(&desc); + return 0; +} +#endif /* SOKOL_NO_ENTRY */ +#endif /* _SAPP_LINUX */ + +// ██████ ██ ██ ██████ ██ ██ ██████ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ██████ ██ ██ ██████ ██ ██ ██ +// ██ ██ ██ ██ ██ ██ ██ ██ +// ██ ██████ ██████ ███████ ██ ██████ +// +// >>public +#if defined(SOKOL_NO_ENTRY) +SOKOL_API_IMPL void sapp_run(const sapp_desc* desc) { + SOKOL_ASSERT(desc); + #if defined(_SAPP_MACOS) + _sapp_macos_run(desc); + #elif defined(_SAPP_IOS) + _sapp_ios_run(desc); + #elif defined(_SAPP_EMSCRIPTEN) + _sapp_emsc_run(desc); + #elif defined(_SAPP_WIN32) + _sapp_win32_run(desc); + #elif defined(_SAPP_LINUX) + _sapp_linux_run(desc); + #else + #error "sapp_run() not supported on this platform" + #endif +} + +/* this is just a stub so the linker doesn't complain */ +sapp_desc sokol_main(int argc, char* argv[]) { + _SOKOL_UNUSED(argc); + _SOKOL_UNUSED(argv); + _SAPP_STRUCT(sapp_desc, desc); + return desc; +} +#else +/* likewise, in normal mode, sapp_run() is just an empty stub */ +SOKOL_API_IMPL void sapp_run(const sapp_desc* desc) { + _SOKOL_UNUSED(desc); +} +#endif + +SOKOL_API_IMPL bool sapp_isvalid(void) { + return _sapp.valid; +} + +SOKOL_API_IMPL void* sapp_userdata(void) { + return _sapp.desc.user_data; +} + +SOKOL_API_IMPL sapp_desc sapp_query_desc(void) { + return _sapp.desc; +} + +SOKOL_API_IMPL uint64_t sapp_frame_count(void) { + return _sapp.frame_count; +} + +SOKOL_API_IMPL double sapp_frame_duration(void) { + #if defined(_SAPP_MACOS) && defined(SOKOL_METAL) + return _sapp_macos_mtl_timing_frame_duration(); + #elif defined(_SAPP_IOS) && defined(SOKOL_METAL) + return _sapp_ios_mtl_timing_frame_duration(); + #else + return _sapp_timing_get(&_sapp.timing); + #endif +} + +SOKOL_API_IMPL double sapp_frame_duration_unfiltered(void) { + return _sapp.timing.dt; +} + +SOKOL_API_IMPL int sapp_width(void) { + return (_sapp.framebuffer_width > 0) ? _sapp.framebuffer_width : 1; +} + +SOKOL_API_IMPL float sapp_widthf(void) { + return (float)sapp_width(); +} + +SOKOL_API_IMPL int sapp_height(void) { + return (_sapp.framebuffer_height > 0) ? _sapp.framebuffer_height : 1; +} + +SOKOL_API_IMPL float sapp_heightf(void) { + return (float)sapp_height(); +} + +SOKOL_API_IMPL sapp_pixel_format sapp_color_format(void) { + #if defined(SOKOL_WGPU) + switch (_sapp.wgpu.render_format) { + case WGPUTextureFormat_RGBA8Unorm: + return SAPP_PIXELFORMAT_RGBA8; + case WGPUTextureFormat_BGRA8Unorm: + return SAPP_PIXELFORMAT_BGRA8; + default: + SOKOL_UNREACHABLE; + return SAPP_PIXELFORMAT_NONE; + } + #elif defined(SOKOL_VULKAN) + switch (_sapp.vk.surface_format.format) { + case VK_FORMAT_R8G8B8A8_UNORM: + return SAPP_PIXELFORMAT_RGBA8; + case VK_FORMAT_B8G8R8A8_UNORM: + return SAPP_PIXELFORMAT_BGRA8; + default: + // FIXME! + SOKOL_UNREACHABLE; + return SAPP_PIXELFORMAT_NONE; + } + #elif defined(SOKOL_METAL) || defined(SOKOL_D3D11) + return SAPP_PIXELFORMAT_BGRA8; + #else + return SAPP_PIXELFORMAT_RGBA8; + #endif +} + +SOKOL_API_IMPL sapp_pixel_format sapp_depth_format(void) { + return SAPP_PIXELFORMAT_DEPTH_STENCIL; +} + +SOKOL_API_IMPL int sapp_sample_count(void) { + return _sapp.sample_count; +} + +SOKOL_API_IMPL bool sapp_high_dpi(void) { + return _sapp.desc.high_dpi && (_sapp.dpi_scale >= 1.5f); +} + +SOKOL_API_IMPL float sapp_dpi_scale(void) { + return _sapp.dpi_scale; +} + +SOKOL_API_IMPL const void* sapp_egl_get_display(void) { + SOKOL_ASSERT(_sapp.valid); + #if defined(_SAPP_ANDROID) + return _sapp.android.display; + #elif defined(_SAPP_LINUX) && defined(_SAPP_EGL) + return _sapp.egl.display; + #else + return 0; + #endif +} + +SOKOL_API_IMPL const void* sapp_egl_get_context(void) { + SOKOL_ASSERT(_sapp.valid); + #if defined(_SAPP_ANDROID) + return _sapp.android.context; + #elif defined(_SAPP_LINUX) && defined(_SAPP_EGL) + return _sapp.egl.context; + #else + return 0; + #endif +} + +SOKOL_API_IMPL void sapp_show_keyboard(bool show) { + #if defined(_SAPP_IOS) + _sapp_ios_show_keyboard(show); + #elif defined(_SAPP_ANDROID) + _sapp_android_show_keyboard(show); + #else + _SOKOL_UNUSED(show); + #endif +} + +SOKOL_API_IMPL bool sapp_keyboard_shown(void) { + return _sapp.onscreen_keyboard_shown; +} + +SOKOL_API_IMPL bool sapp_is_fullscreen(void) { + return _sapp.fullscreen; +} + +SOKOL_API_IMPL void sapp_toggle_fullscreen(void) { + #if defined(_SAPP_MACOS) + _sapp_macos_toggle_fullscreen(); + #elif defined(_SAPP_WIN32) + _sapp_win32_toggle_fullscreen(); + #elif defined(_SAPP_LINUX) + _sapp_x11_toggle_fullscreen(); + #elif defined(_SAPP_EMSCRIPTEN) + _sapp_emsc_toggle_fullscreen(); + #endif +} + +_SOKOL_PRIVATE void _sapp_update_cursor(sapp_mouse_cursor cursor, bool shown) { + #if defined(_SAPP_MACOS) + _sapp_macos_update_cursor(cursor, shown); + #elif defined(_SAPP_WIN32) + _sapp_win32_update_cursor(cursor, shown, false); + #elif defined(_SAPP_LINUX) + _sapp_x11_update_cursor(cursor, shown); + #elif defined(_SAPP_EMSCRIPTEN) + _sapp_emsc_update_cursor(cursor, shown); + #endif + _sapp.mouse.current_cursor = cursor; + _sapp.mouse.shown = shown; +} + +/* NOTE that sapp_show_mouse() does not "stack" like the Win32 or macOS API functions! */ +SOKOL_API_IMPL void sapp_show_mouse(bool show) { + if (_sapp.mouse.shown != show) { + _sapp_update_cursor(_sapp.mouse.current_cursor, show); + } +} + +SOKOL_API_IMPL bool sapp_mouse_shown(void) { + return _sapp.mouse.shown; +} + +SOKOL_API_IMPL void sapp_lock_mouse(bool lock) { + #if defined(_SAPP_MACOS) + _sapp_macos_lock_mouse(lock); + #elif defined(_SAPP_EMSCRIPTEN) + _sapp_emsc_lock_mouse(lock); + #elif defined(_SAPP_WIN32) + _sapp_win32_lock_mouse(lock); + #elif defined(_SAPP_LINUX) + _sapp_x11_lock_mouse(lock); + #else + _sapp.mouse.locked = lock; + #endif +} + +SOKOL_API_IMPL bool sapp_mouse_locked(void) { + return _sapp.mouse.locked; +} + +SOKOL_API_IMPL void sapp_set_mouse_cursor(sapp_mouse_cursor cursor) { + SOKOL_ASSERT((cursor >= 0) && (cursor < _SAPP_MOUSECURSOR_NUM)); + if (_sapp.mouse.current_cursor != cursor) { + _sapp_update_cursor(cursor, _sapp.mouse.shown); + } +} + +SOKOL_API_IMPL sapp_mouse_cursor sapp_get_mouse_cursor(void) { + return _sapp.mouse.current_cursor; +} + +SOKOL_API_IMPL sapp_mouse_cursor sapp_bind_mouse_cursor_image(sapp_mouse_cursor cursor, const sapp_image_desc* desc) { + SOKOL_ASSERT((cursor >= 0) && (cursor < _SAPP_MOUSECURSOR_NUM)); + // NOTE: It seems that for some reason, the hotspot doesn't work if it is one less + // than the dimension of the cursor image (or more), on windows. So for a cursor + // that is 32 by 32 px, a hotspot of x = 30 works, but not x = 31. + // The cursor simply dissapears in such cases. Asserting for all platforms to make + // the behaviour consistent. + SOKOL_ASSERT(desc->cursor_hotspot_x < desc->width - 1 && desc->cursor_hotspot_y < desc->height - 1); + SOKOL_ASSERT(desc->width * desc->height * 4 == (int) desc->pixels.size); + + sapp_unbind_mouse_cursor_image(cursor); + + bool res = false; + #if defined(_SAPP_MACOS) + res = _sapp_macos_make_custom_mouse_cursor(cursor, desc); + #elif defined(_SAPP_EMSCRIPTEN) + res = _sapp_emsc_make_custom_mouse_cursor(cursor, desc); + #elif defined(_SAPP_WIN32) + res = _sapp_win32_make_custom_mouse_cursor(cursor, desc); + #elif defined(_SAPP_LINUX) + res = _sapp_x11_make_custom_mouse_cursor(cursor, desc); + #else + _SOKOL_UNUSED(desc); + #endif + _sapp.custom_cursor_bound[(int)cursor] = res; + + // Update the displayed cursor in case the current cursor is the one we just bound. + if (_sapp.mouse.current_cursor == cursor) { + _sapp_update_cursor(cursor, _sapp.mouse.shown); + } + return cursor; // returning the passed-in cursor puerly for convenience, in case you want to asign the value to a variable. +} + +SOKOL_API_IMPL void sapp_unbind_mouse_cursor_image(sapp_mouse_cursor cursor) { + SOKOL_ASSERT((cursor >= 0) && (cursor < _SAPP_MOUSECURSOR_NUM)); + if (_sapp.custom_cursor_bound[(int)cursor]) { + // if this is the active cursor, first restore it to its default image, + // this must be done before attempting to destroy any cursor image + // resources which at least on win32 would fail if the cursor is still in use + _sapp.custom_cursor_bound[(int)cursor] = false; + if (_sapp.mouse.current_cursor == cursor) { + _sapp_update_cursor(cursor, _sapp.mouse.shown); + } + #if defined(_SAPP_MACOS) + _sapp_macos_destroy_custom_mouse_cursor(cursor); + #elif defined(_SAPP_EMSCRIPTEN) + _sapp_emsc_destroy_custom_mouse_cursor(cursor); + #elif defined(_SAPP_WIN32) + _sapp_win32_destroy_custom_mouse_cursor(cursor); + #elif defined(_SAPP_LINUX) + _sapp_x11_destroy_custom_mouse_cursor(cursor); + #endif + } +} + +SOKOL_API_IMPL void sapp_request_quit(void) { + _sapp.quit_requested = true; +} + +SOKOL_API_IMPL void sapp_cancel_quit(void) { + _sapp.quit_requested = false; +} + +SOKOL_API_IMPL void sapp_quit(void) { + _sapp.quit_ordered = true; +} + +SOKOL_API_IMPL void sapp_consume_event(void) { + _sapp.event_consumed = true; +} + +/* NOTE: on HTML5, sapp_set_clipboard_string() must be called from within event handler! */ +SOKOL_API_IMPL void sapp_set_clipboard_string(const char* str) { + if (!_sapp.clipboard.enabled) { + return; + } + SOKOL_ASSERT(str); + #if defined(_SAPP_MACOS) + _sapp_macos_set_clipboard_string(str); + #elif defined(_SAPP_EMSCRIPTEN) + _sapp_emsc_set_clipboard_string(str); + #elif defined(_SAPP_WIN32) + _sapp_win32_set_clipboard_string(str); + #elif defined(_SAPP_LINUX) + _sapp_x11_set_clipboard_string(str); + #else + /* not implemented */ + #endif + _sapp_strcpy(str, _sapp.clipboard.buffer, (size_t)_sapp.clipboard.buf_size); +} + +SOKOL_API_IMPL const char* sapp_get_clipboard_string(void) { + if (!_sapp.clipboard.enabled) { + return ""; + } + #if defined(_SAPP_MACOS) + return _sapp_macos_get_clipboard_string(); + #elif defined(_SAPP_EMSCRIPTEN) + return _sapp.clipboard.buffer; + #elif defined(_SAPP_WIN32) + return _sapp_win32_get_clipboard_string(); + #elif defined(_SAPP_LINUX) + return _sapp_x11_get_clipboard_string(); + #else + /* not implemented */ + return _sapp.clipboard.buffer; + #endif +} + +SOKOL_API_IMPL void sapp_set_window_title(const char* title) { + SOKOL_ASSERT(title); + _sapp_strcpy(title, _sapp.window_title, sizeof(_sapp.window_title)); + #if defined(_SAPP_MACOS) + _sapp_macos_update_window_title(); + #elif defined(_SAPP_WIN32) + _sapp_win32_update_window_title(); + #elif defined(_SAPP_LINUX) + _sapp_x11_update_window_title(); + #endif +} + +SOKOL_API_IMPL void sapp_set_icon(const sapp_icon_desc* desc) { + SOKOL_ASSERT(desc); + if (desc->sokol_default) { + if (0 == _sapp.default_icon_pixels) { + _sapp_setup_default_icon(); + } + SOKOL_ASSERT(0 != _sapp.default_icon_pixels); + desc = &_sapp.default_icon_desc; + } + const int num_images = _sapp_icon_num_images(desc); + if (num_images == 0) { + return; + } + SOKOL_ASSERT((num_images > 0) && (num_images <= SAPP_MAX_ICONIMAGES)); + if (!_sapp_validate_icon_desc(desc, num_images)) { + return; + } + #if defined(_SAPP_MACOS) + _sapp_macos_set_icon(desc, num_images); + #elif defined(_SAPP_WIN32) + _sapp_win32_set_icon(desc, num_images); + #elif defined(_SAPP_LINUX) + _sapp_x11_set_icon(desc, num_images); + #elif defined(_SAPP_EMSCRIPTEN) + _sapp_emsc_set_icon(desc, num_images); + #endif +} + +SOKOL_API_IMPL int sapp_get_num_dropped_files(void) { + if (!_sapp.drop.enabled) { + return 0; + } + return _sapp.drop.num_files; +} + +SOKOL_API_IMPL const char* sapp_get_dropped_file_path(int index) { + SOKOL_ASSERT((index >= 0) && (index < _sapp.drop.num_files)); + if (!_sapp.drop.enabled) { + return ""; + } + SOKOL_ASSERT(_sapp.drop.buffer); + if ((index < 0) || (index >= _sapp.drop.max_files)) { + return ""; + } + return (const char*) _sapp_dropped_file_path_ptr(index); +} + +SOKOL_API_IMPL uint32_t sapp_html5_get_dropped_file_size(int index) { + SOKOL_ASSERT((index >= 0) && (index < _sapp.drop.num_files)); + #if defined(_SAPP_EMSCRIPTEN) + if (!_sapp.drop.enabled) { + return 0; + } + return sapp_js_dropped_file_size(index); + #else + (void)index; + return 0; + #endif +} + +SOKOL_API_IMPL void sapp_html5_fetch_dropped_file(const sapp_html5_fetch_request* request) { + SOKOL_ASSERT(_sapp.drop.enabled); + SOKOL_ASSERT(request); + SOKOL_ASSERT(request->callback); + SOKOL_ASSERT(request->buffer.ptr); + SOKOL_ASSERT(request->buffer.size > 0); + #if defined(_SAPP_EMSCRIPTEN) + const int index = request->dropped_file_index; + sapp_html5_fetch_error error_code = SAPP_HTML5_FETCH_ERROR_NO_ERROR; + if ((index < 0) || (index >= _sapp.drop.num_files)) { + error_code = SAPP_HTML5_FETCH_ERROR_OTHER; + } + if (sapp_html5_get_dropped_file_size(index) > request->buffer.size) { + error_code = SAPP_HTML5_FETCH_ERROR_BUFFER_TOO_SMALL; + } + if (SAPP_HTML5_FETCH_ERROR_NO_ERROR != error_code) { + _sapp_emsc_invoke_fetch_cb(index, + false, // success + (int)error_code, + request->callback, + 0, // fetched_size + (void*)request->buffer.ptr, + request->buffer.size, + request->user_data); + } else { + sapp_js_fetch_dropped_file(index, + request->callback, + (void*)request->buffer.ptr, + request->buffer.size, + request->user_data); + } + #else + (void)request; + #endif +} + +SOKOL_API_IMPL sapp_environment sapp_get_environment(void) { + SOKOL_ASSERT(_sapp.valid); + _SAPP_STRUCT(sapp_environment, res); + res.defaults.color_format = sapp_color_format(); + res.defaults.depth_format = sapp_depth_format(); + res.defaults.sample_count = sapp_sample_count(); + #if defined(SOKOL_METAL) + #if defined(_SAPP_MACOS) + res.metal.device = (__bridge const void*) _sapp.macos.mtl.device; + #else + res.metal.device = (__bridge const void*) _sapp.ios.mtl.device; + #endif + #endif + #if defined(SOKOL_D3D11) + res.d3d11.device = (const void*) _sapp.d3d11.device; + res.d3d11.device_context = (const void*) _sapp.d3d11.device_context; + #endif + #if defined(SOKOL_WGPU) + res.wgpu.device = (const void*) _sapp.wgpu.device; + #endif + #if defined(SOKOL_VULKAN) + res.vulkan.instance = (const void*) _sapp.vk.instance; + res.vulkan.physical_device = (const void*) _sapp.vk.physical_device; + res.vulkan.device = (const void*) _sapp.vk.device; + res.vulkan.queue = (const void*) _sapp.vk.queue; + res.vulkan.queue_family_index = _sapp.vk.queue_family_index; + #endif + return res; +} + +SOKOL_API_IMPL sapp_swapchain sapp_get_swapchain(void) { + SOKOL_ASSERT(_sapp.valid); + _SAPP_STRUCT(sapp_swapchain, res); + #if defined(SOKOL_METAL) + #if defined(_SAPP_MACOS) + res.metal.current_drawable = (__bridge const void*) _sapp_macos_mtl_swapchain_next(); + res.metal.depth_stencil_texture = (__bridge const void*) _sapp.macos.mtl.depth_tex; + res.metal.msaa_color_texture = (__bridge const void*) _sapp.macos.mtl.msaa_tex; + #else + res.metal.current_drawable = (__bridge const void*) _sapp_ios_mtl_swapchain_next(); + res.metal.depth_stencil_texture = (__bridge const void*) _sapp.ios.mtl.depth_tex; + res.metal.msaa_color_texture = (__bridge const void*) _sapp.ios.mtl.msaa_tex; + #endif + #endif + #if defined(SOKOL_D3D11) + SOKOL_ASSERT(_sapp.d3d11.rtv); + if (_sapp.sample_count > 1) { + SOKOL_ASSERT(_sapp.d3d11.msaa_rtv); + res.d3d11.render_view = (const void*) _sapp.d3d11.msaa_rtv; + res.d3d11.resolve_view = (const void*) _sapp.d3d11.rtv; + } else { + res.d3d11.render_view = (const void*) _sapp.d3d11.rtv; + } + res.d3d11.depth_stencil_view = (const void*) _sapp.d3d11.dsv; + #endif + #if defined(SOKOL_WGPU) + SOKOL_ASSERT(0 == _sapp.wgpu.swapchain_view); + _sapp_wgpu_swapchain_next(); + // FIXME: swapchain_view being null must be allowed and should skip the frame + SOKOL_ASSERT(_sapp.wgpu.swapchain_view); + if (_sapp.sample_count > 1) { + SOKOL_ASSERT(_sapp.wgpu.msaa_view); + res.wgpu.render_view = (const void*) _sapp.wgpu.msaa_view; + res.wgpu.resolve_view = (const void*) _sapp.wgpu.swapchain_view; + } else { + res.wgpu.render_view = (const void*) _sapp.wgpu.swapchain_view; + } + res.wgpu.depth_stencil_view = (const void*) _sapp.wgpu.depth_stencil_view; + #endif + #if defined(SOKOL_VULKAN) + _sapp_vk_swapchain_next(); + // FIXME: swapchain_view being null must be allowed and should skip the frame + uint32_t img_idx = _sapp.vk.cur_swapchain_image_index; + if (_sapp.sample_count > 1) { + SOKOL_ASSERT(_sapp.vk.msaa.img && _sapp.vk.msaa.view); + res.vulkan.render_image = (const void*) _sapp.vk.msaa.img; + res.vulkan.render_view = (const void*) _sapp.vk.msaa.view; + res.vulkan.resolve_image = (const void*) _sapp.vk.swapchain_images[img_idx]; + res.vulkan.resolve_view = (const void*) _sapp.vk.swapchain_views[img_idx]; + } else { + res.vulkan.render_image = (const void*) _sapp.vk.swapchain_images[img_idx]; + res.vulkan.render_view = (const void*) _sapp.vk.swapchain_views[img_idx]; + } + res.vulkan.depth_stencil_image = (const void*) _sapp.vk.depth.img; + res.vulkan.depth_stencil_view = (const void*) _sapp.vk.depth.view; + // NOTE: using the current swapchain image index here is *NOT* a bug! The render_finished_semaphore *must* + // be associated with its swapchain image in case the swapchain implementation doesn't return swapchain images in order + res.vulkan.render_finished_semaphore = _sapp.vk.sync[img_idx].render_finished_sem; + res.vulkan.present_complete_semaphore = _sapp.vk.sync[_sapp.vk.sync_slot].present_complete_sem; + #endif + #if defined(_SAPP_ANY_GL) + res.gl.framebuffer = _sapp.gl.framebuffer; + #endif + res.width = sapp_width(); + res.height = sapp_height(); + res.color_format = sapp_color_format(); + res.depth_format = sapp_depth_format(); + res.sample_count = sapp_sample_count(); + return res; +} + +SOKOL_API_IMPL const void* sapp_macos_get_window(void) { + #if defined(_SAPP_MACOS) + const void* obj = (__bridge const void*) _sapp.macos.window; + SOKOL_ASSERT(obj); + return obj; + #else + return 0; + #endif +} + +SOKOL_API_IMPL const void* sapp_ios_get_window(void) { + #if defined(_SAPP_IOS) + const void* obj = (__bridge const void*) _sapp.ios.window; + SOKOL_ASSERT(obj); + return obj; + #else + return 0; + #endif +} + +SOKOL_API_IMPL const void* sapp_d3d11_get_swap_chain(void) { + SOKOL_ASSERT(_sapp.valid); +#if defined(SOKOL_D3D11) + return _sapp.d3d11.swap_chain; +#else + return 0; +#endif +} + +SOKOL_API_IMPL const void* sapp_win32_get_hwnd(void) { + SOKOL_ASSERT(_sapp.valid); + #if defined(_SAPP_WIN32) + return _sapp.win32.hwnd; + #else + return 0; + #endif +} + +SOKOL_API_IMPL int sapp_gl_get_major_version(void) { + SOKOL_ASSERT(_sapp.valid); + #if defined(_SAPP_ANY_GL) + return _sapp.desc.gl.major_version; + #else + return 0; + #endif +} + +SOKOL_API_IMPL int sapp_gl_get_minor_version(void) { + SOKOL_ASSERT(_sapp.valid); + #if defined(_SAPP_ANY_GL) + return _sapp.desc.gl.minor_version; + #else + return 0; + #endif +} + +SOKOL_API_IMPL bool sapp_gl_is_gles(void) { + #if defined(SOKOL_GLES3) + return true; + #else + return false; + #endif +} + +SOKOL_API_IMPL const void* sapp_x11_get_window(void) { + #if defined(_SAPP_LINUX) + return (void*)_sapp.x11.window; + #else + return 0; + #endif +} + +SOKOL_API_IMPL const void* sapp_x11_get_display(void) { + #if defined(_SAPP_LINUX) + return (void*)_sapp.x11.display; + #else + return 0; + #endif +} + +SOKOL_API_IMPL const void* sapp_android_get_native_activity(void) { + // NOTE: _sapp.valid is not asserted here because sapp_android_get_native_activity() + // needs to be callable from within sokol_main() (see: https://github.com/floooh/sokol/issues/708) + #if defined(_SAPP_ANDROID) + return (void*)_sapp.android.activity; + #else + return 0; + #endif +} + +SOKOL_API_IMPL void sapp_html5_ask_leave_site(bool ask) { + _sapp.html5_ask_leave_site = ask; +} + +#endif /* SOKOL_APP_IMPL */ diff --git a/extern/sokol/sokol_gfx.h b/extern/sokol/sokol_gfx.h new file mode 100644 index 0000000..72ad505 --- /dev/null +++ b/extern/sokol/sokol_gfx.h @@ -0,0 +1,26841 @@ +#if defined(SOKOL_IMPL) && !defined(SOKOL_GFX_IMPL) +#define SOKOL_GFX_IMPL +#endif +#ifndef SOKOL_GFX_INCLUDED +/* + sokol_gfx.h -- simple 3D API wrapper + + Project URL: https://github.com/floooh/sokol + + Example code: https://github.com/floooh/sokol-samples + + Do this: + #define SOKOL_IMPL or + #define SOKOL_GFX_IMPL + before you include this file in *one* C or C++ file to create the + implementation. + + In the same place define one of the following to select the rendering + backend: + #define SOKOL_GLCORE + #define SOKOL_GLES3 + #define SOKOL_D3D11 + #define SOKOL_METAL + #define SOKOL_WGPU + #define SOKOL_VULKAN + #define SOKOL_DUMMY_BACKEND + + I.e. for the desktop GL it should look like this: + + #include ... + #include ... + #define SOKOL_IMPL + #define SOKOL_GLCORE + #include "sokol_gfx.h" + + The dummy backend replaces the platform-specific backend code with empty + stub functions. This is useful for writing tests that need to run on the + command line. + + Optionally provide the following defines with your own implementations: + + SOKOL_ASSERT(c) - your own assert macro (default: assert(c)) + SOKOL_UNREACHABLE() - a guard macro for unreachable code (default: assert(false)) + SOKOL_GFX_API_DECL - public function declaration prefix (default: extern) + SOKOL_API_DECL - same as SOKOL_GFX_API_DECL + SOKOL_API_IMPL - public function implementation prefix (default: -) + SOKOL_TRACE_HOOKS - enable trace hook callbacks (search below for TRACE HOOKS) + SOKOL_EXTERNAL_GL_LOADER - indicates that you're using your own GL loader, in this case + sokol_gfx.h will not include any platform GL headers and disable + the integrated Win32 GL loader + + If sokol_gfx.h is compiled as a DLL, define the following before + including the declaration or implementation: + + SOKOL_DLL + + On Windows, SOKOL_DLL will define SOKOL_GFX_API_DECL as __declspec(dllexport) + or __declspec(dllimport) as needed. + + Optionally define the following to force debug checks and validations + even in release mode: + + SOKOL_DEBUG - by default this is defined if NDEBUG is not defined + + Link with the following system libraries (note that sokol_app.h has + additional linker requirements): + + - on macOS/iOS with Metal: Metal + - on macOS with GL: OpenGL + - on iOS with GL: OpenGLES + - on Linux with EGL: GL or GLESv2 + - on Linux with GLX: GL + - on Linux with Vulkan: vulkan + - on Android: GLESv3, log, android + - on Windows: + - with Vulkan: link with vulkan-1 (this is explicit in case you want to + use your own Vulkan loader library) + - with D3D11: + - on MSVC or Clang: no action needed, libs are defined in-source via pragma-comment-lib + - on MINGW/MSYS2 gcc: compile with '-mwin32' so that _WIN32 is defined and link with -ld3d11 + - with GL: no linking needed since sokol_gfx.h comes with its own GL loader on Windows + + On macOS and iOS, the implementation must be compiled as Objective-C. + + For Linux+Vulkan install the following packages (or equivalents): + - libvulkan-dev + - vulkan-validationlayers + - vulkan-tools + + For Windows+Vulkan install the Vulkan SDK and in your build system: + - add a header search path to $ENV{VULKAN_SDK}/Include + - add a link search path to $ENV{VULKAN_SDK}/Env + + On Emscripten: + - for WebGL2: add the linker option `-s USE_WEBGL2=1` + - for WebGPU: compile and link with `--use-port=emdawnwebgpu` + (for more exotic situations, read: https://dawn.googlesource.com/dawn/+/refs/heads/main/src/emdawnwebgpu/pkg/README.md) + + sokol_gfx DOES NOT: + =================== + - create a window, swapchain or the 3D-API context/device, you must do this + before sokol_gfx is initialized, and pass any required information + (like 3D device pointers) to the sokol_gfx initialization call + + - present the rendered frame, how this is done exactly usually depends + on how the window and 3D-API context/device was created + + - provide a unified shader language, instead 3D-API-specific shader + source-code or shader-bytecode must be provided (for the "official" + offline shader cross-compiler / code-generator, see here: + https://github.com/floooh/sokol-tools/blob/master/docs/sokol-shdc.md) + + + STEP BY STEP + ============ + --- to initialize sokol_gfx, after creating a window and a 3D-API + context/device, call: + + sg_setup(const sg_desc*) + + Depending on the selected 3D backend, sokol-gfx requires some + information about its runtime environment, like a GPU device pointer, + default swapchain pixel formats and so on. If you are using sokol_app.h + for the window system glue, you can use a helper function provided in + the sokol_glue.h header: + + #include "sokol_gfx.h" + #include "sokol_app.h" + #include "sokol_glue.h" + //... + sg_setup(&(sg_desc){ + .environment = sglue_environment(), + }); + + To get any logging output for errors and from the validation layer, you + need to provide a logging callback. Easiest way is through sokol_log.h: + + #include "sokol_log.h" + //... + sg_setup(&(sg_desc){ + //... + .logger.func = slog_func, + }); + + --- create resource objects (buffers, images, views, samplers, shaders + and pipeline objects) + + sg_buffer sg_make_buffer(const sg_buffer_desc*) + sg_image sg_make_image(const sg_image_desc*) + sg_view sg_make_view(const sg_view_desc*) + sg_sampler sg_make_sampler(const sg_sampler_desc*) + sg_shader sg_make_shader(const sg_shader_desc*) + sg_pipeline sg_make_pipeline(const sg_pipeline_desc*) + + --- start a render- or compute-pass: + + sg_begin_pass(const sg_pass* pass); + + Typically, render passes render into an externally provided swapchain which + presents the rendering result on the display. Such a 'swapchain pass' + is started like this: + + sg_begin_pass(&(sg_pass){ .action = { ... }, .swapchain = sglue_swapchain() }) + + ...where .action is an sg_pass_action struct containing actions to be performed + at the start and end of a render pass (such as clearing the render surfaces to + a specific color), and .swapchain is an sg_swapchain struct with all the required + information to render into the swapchain's surfaces. + + To start an 'offscreen render pass' into sokol-gfx image objects, populate + the sg_pass.attachments nested struct with attachment view objects + (1..4 color-attachment-views for to render into, a depth-stencil-attachment-view + to provide the depth-stencil-buffer, and optionally 1..4 resolve-attachment-views + for an MSAA-resolve operation: + + sg_begin_pass(&(sg_pass){ + .action = { ... }, + .attachments = { + .colors[0] = color_attachment_view, + .resolves[0] = optional_resolve_attachment_view, + .depth_stencil = depth_stencil_attachment_view, + }, + }); + + To start a compute-pass, just set the .compute item to true: + + sg_begin_pass(&(sg_pass){ .compute = true }); + + --- set the pipeline state for the next draw call with: + + sg_apply_pipeline(sg_pipeline pip) + + --- fill an sg_bindings struct with the resource bindings for the next + draw- or dispatch-call (0..N vertex buffers, 0 or 1 index buffer, 0..N views, + 0..N samplers), and call + + sg_apply_bindings(const sg_bindings* bindings) + + ...to update the resource bindings. Note that in a compute pass, no vertex- + or index-buffer bindings can be used, and in render passes, no storage-image bindings + are allowed. Those restrictions will be checked by the sokol-gfx validation layer. + + --- optionally update shader uniform data with: + + sg_apply_uniforms(int ub_slot, const sg_range* data) + + Read the section 'UNIFORM DATA LAYOUT' to learn about the expected memory layout + of the uniform data passed into sg_apply_uniforms(). + + --- kick off a draw call with: + + sg_draw(int base_element, int num_elements, int num_instances) + + The sg_draw() function unifies all the different ways to render primitives + in a single call (indexed vs non-indexed rendering, and instanced vs non-instanced + rendering). In case of indexed rendering, base_element and num_element specify + indices in the currently bound index buffer. In case of non-indexed rendering + base_element and num_elements specify vertices in the currently bound + vertex-buffer(s). To perform instanced rendering, the rendering pipeline + must be setup for instancing (see sg_pipeline_desc below), a separate vertex buffer + containing per-instance data must be bound, and the num_instances parameter + must be > 1. + + Alternatively, call: + + sg_draw_ex(...) + + to provide a base-vertex and/or base-instance which allows to render + from different sections of a vertex buffer without rebinding the + vertex buffer with a different offset. Note that the `sg_draw_ex()` + only has limited portability on OpenGL, check the sg_limits struct + members .draw_base_vertex and .draw_base_instance for runtime support, + those are generally true on non-GL-backends, and on GL the feature + flags are set according to the GL version: + + - on GL base_instance != 0 is only supported since GL 4.2 + - on GLES3.x, base_instance != 0 is not supported + - on GLES3.x, base_vertex is only supported since GLES3.2 + (e.g. not supported on WebGL2) + + --- ...or kick of a dispatch call to invoke a compute shader workload: + + sg_dispatch(int num_groups_x, int num_groups_y, int num_groups_z) + + The dispatch args define the number of 'compute workgroups' processed + by the currently applied compute shader. + + --- finish the current pass with: + + sg_end_pass() + + --- when done with the current frame, call + + sg_commit() + + --- at the end of your program, shutdown sokol_gfx with: + + sg_shutdown() + + --- if you need to destroy resources before sg_shutdown(), call: + + sg_destroy_buffer(sg_buffer buf) + sg_destroy_image(sg_image img) + sg_destroy_sampler(sg_sampler smp) + sg_destroy_shader(sg_shader shd) + sg_destroy_pipeline(sg_pipeline pip) + sg_destroy_view(sg_view view) + + --- to set a new viewport rectangle, call: + + sg_apply_viewport(int x, int y, int width, int height, bool origin_top_left) + + ...or if you want to specify the viewport rectangle with float values: + + sg_apply_viewportf(float x, float y, float width, float height, bool origin_top_left) + + --- to set a new scissor rect, call: + + sg_apply_scissor_rect(int x, int y, int width, int height, bool origin_top_left) + + ...or with float values: + + sg_apply_scissor_rectf(float x, float y, float width, float height, bool origin_top_left) + + Both sg_apply_viewport() and sg_apply_scissor_rect() must be called + inside a rendering pass (e.g. not in a compute pass, or outside a pass) + + Note that sg_begin_pass() will reset both the viewport and scissor + rectangles to cover the entire framebuffer. + + --- to update (overwrite) the content of buffer and image resources, call: + + sg_update_buffer(sg_buffer buf, const sg_range* data) + sg_update_image(sg_image img, const sg_image_data* data) + + Buffers and images to be updated must have been created with + sg_buffer_desc.usage.dynamic_update or .stream_update. + + Only one update per frame is allowed for buffer and image resources when + using the sg_update_*() functions. The rationale is to have a simple + protection from the CPU scribbling over data the GPU is currently + using, or the CPU having to wait for the GPU + + Buffer and image updates can be partial, as long as a rendering + operation only references the valid (updated) data in the + buffer or image. + + --- to append a chunk of data to a buffer resource, call: + + int sg_append_buffer(sg_buffer buf, const sg_range* data) + + The difference to sg_update_buffer() is that sg_append_buffer() + can be called multiple times per frame to append new data to the + buffer piece by piece, optionally interleaved with draw calls referencing + the previously written data. + + sg_append_buffer() returns a byte offset to the start of the + written data, this offset can be assigned to + sg_bindings.vertex_buffer_offsets[n] or + sg_bindings.index_buffer_offset + + Code example: + + for (...) { + const void* data = ...; + const int num_bytes = ...; + int offset = sg_append_buffer(buf, &(sg_range) { .ptr=data, .size=num_bytes }); + bindings.vertex_buffer_offsets[0] = offset; + sg_apply_pipeline(pip); + sg_apply_bindings(&bindings); + sg_apply_uniforms(...); + sg_draw(...); + } + + A buffer to be used with sg_append_buffer() must have been created + with sg_buffer_desc.usage.dynamic_update or .stream_update. + + If the application appends more data to the buffer then fits into + the buffer, the buffer will go into the "overflow" state for the + rest of the frame. + + Any draw calls attempting to render an overflown buffer will be + silently dropped (in debug mode this will also result in a + validation error). + + You can also check manually if a buffer is in overflow-state by calling + + bool sg_query_buffer_overflow(sg_buffer buf) + + You can manually check to see if an overflow would occur before adding + any data to a buffer by calling + + bool sg_query_buffer_will_overflow(sg_buffer buf, size_t size) + + NOTE: Due to restrictions in underlying 3D-APIs, appended chunks of + data will be 4-byte aligned in the destination buffer. This means + that there will be gaps in index buffers containing 16-bit indices + when the number of indices in a call to sg_append_buffer() is + odd. This isn't a problem when each call to sg_append_buffer() + is associated with one draw call, but will be problematic when + a single indexed draw call spans several appended chunks of indices. + + --- to check at runtime for optional features, limits and pixelformat support, + call: + + sg_features sg_query_features() + sg_limits sg_query_limits() + sg_pixelformat_info sg_query_pixelformat(sg_pixel_format fmt) + + --- if you need to call into the underlying 3D-API directly, you must call: + + sg_reset_state_cache() + + ...before calling sokol_gfx functions again + + --- you can inspect the original sg_desc structure handed to sg_setup() + by calling sg_query_desc(). This will return an sg_desc struct with + the default values patched in instead of any zero-initialized values + + --- you can get a desc struct matching the creation attributes of a + specific resource object via: + + sg_buffer_desc sg_query_buffer_desc(sg_buffer buf) + sg_image_desc sg_query_image_desc(sg_image img) + sg_sampler_desc sg_query_sampler_desc(sg_sampler smp) + sg_shader_desc sq_query_shader_desc(sg_shader shd) + sg_pipeline_desc sg_query_pipeline_desc(sg_pipeline pip) + sg_view_desc sg_query_view_desc(sg_view view) + + ...but NOTE that the returned desc structs may be incomplete, only + creation attributes that are kept around internally after resource + creation will be filled in, and in some cases (like shaders) that's + very little. Any missing attributes will be set to zero. The returned + desc structs might still be useful as partial blueprint for creating + similar resources if filled up with the missing attributes. + + Calling the query-desc functions on an invalid resource will return + completely zeroed structs (it makes sense to check the resource state + with sg_query_*_state() first) + + --- you can query the default resource creation parameters through the functions + + sg_buffer_desc sg_query_buffer_defaults(const sg_buffer_desc* desc) + sg_image_desc sg_query_image_defaults(const sg_image_desc* desc) + sg_sampler_desc sg_query_sampler_defaults(const sg_sampler_desc* desc) + sg_shader_desc sg_query_shader_defaults(const sg_shader_desc* desc) + sg_pipeline_desc sg_query_pipeline_defaults(const sg_pipeline_desc* desc) + sg_view_desc sg_query_view_defaults(const sg_view_desc* desc) + + These functions take a pointer to a desc structure which may contain + zero-initialized items for default values. These zero-init values + will be replaced with their concrete values in the returned desc + struct. + + --- you can inspect various internal resource runtime values via: + + sg_buffer_info sg_query_buffer_info(sg_buffer buf) + sg_image_info sg_query_image_info(sg_image img) + sg_sampler_info sg_query_sampler_info(sg_sampler smp) + sg_shader_info sg_query_shader_info(sg_shader shd) + sg_pipeline_info sg_query_pipeline_info(sg_pipeline pip) + sg_view_info sg_query_view_info(sg_view view) + + ...please note that the returned info-structs are tied quite closely + to sokol_gfx.h internals, and may change more often than other + public API functions and structs. + + -- you can query the type/flavour and parent resource of a view: + + sg_view_type sg_query_view_type(sg_view view) + sg_image sg_query_view_image(sg_view view) + sg_buffer sg_query_view_buffer(sg_view view) + + --- you can query stats and control stats collection via: + + sg_query_stats() + sg_enable_stats() + sg_disable_stats() + sg_stats_enabled() + + --- you can ask at runtime what backend sokol_gfx.h has been compiled for: + + sg_backend sg_query_backend(void) + + --- call the following helper functions to compute the number of + bytes in a texture row or surface for a specific pixel format. + These functions might be helpful when preparing image data for consumption + by sg_make_image() or sg_update_image(): + + int sg_query_row_pitch(sg_pixel_format fmt, int width, int int row_align_bytes); + int sg_query_surface_pitch(sg_pixel_format fmt, int width, int height, int row_align_bytes); + + Width and height are generally in number pixels, but note that 'row' has different meaning + for uncompressed vs compressed pixel formats: for uncompressed formats, a row is identical + with a single line if pixels, while in compressed formats, one row is a line of *compression blocks*. + + This is why calling sg_query_surface_pitch() for a compressed pixel format and height + N, N+1, N+2, ... may return the same result. + + The row_align_bytes parameter is for added flexibility. For image data that goes into + the sg_make_image() or sg_update_image() this should generally be 1, because these + functions take tightly packed image data as input no matter what alignment restrictions + exist in the backend 3D APIs. + + ON INITIALIZATION: + ================== + When calling sg_setup(), a pointer to an sg_desc struct must be provided + which contains initialization options. These options provide two types + of information to sokol-gfx: + + (1) upper bounds and limits needed to allocate various internal + data structures: + - the max number of resources of each type that can + be alive at the same time, this is used for allocating + internal pools + - the max overall size of uniform data that can be + updated per frame, including a worst-case alignment + per uniform update (this worst-case alignment is 256 bytes) + - the max size of all dynamic resource updates (sg_update_buffer, + sg_append_buffer and sg_update_image) per frame + - the max number of compute-dispatch calls in a compute pass + Not all of those limit values are used by all backends, but it is + good practice to provide them none-the-less. + + (2) 3D backend "environment information" in a nested sg_environment struct: + - pointers to backend-specific context- or device-objects (for instance + the D3D11, WebGPU or Metal device objects) + - defaults for external swapchain pixel formats and sample counts, + these will be used as default values in image and pipeline objects, + and the sg_swapchain struct passed into sg_begin_pass() + Usually you provide a complete sg_environment struct through + a helper function, as an example look at the sglue_environment() + function in the sokol_glue.h header. + + See the documentation block of the sg_desc struct below for more information. + + + ON RENDER PASSES + ================ + Relevant samples: + - https://floooh.github.io/sokol-html5/offscreen-sapp.html + - https://floooh.github.io/sokol-html5/offscreen-msaa-sapp.html + - https://floooh.github.io/sokol-html5/mrt-sapp.html + - https://floooh.github.io/sokol-html5/mrt-pixelformats-sapp.html + + A render pass groups rendering commands into a set of render target images + (called 'render pass attachments'). Render target images can be used in subsequent + passes as textures (it is invalid to use the same image both as render target + and as texture in the same pass). + + The following sokol-gfx functions must only be called inside a render-pass: + + sg_apply_viewport[f] + sg_apply_scissor_rect[f] + sg_draw + + The following function may be called inside a render- or compute-pass, but + not outside a pass: + + sg_apply_pipeline + sg_apply_bindings + sg_apply_uniforms + + A frame must have at least one 'swapchain render pass' which renders into an + externally provided swapchain provided as an sg_swapchain struct to the + sg_begin_pass() function. If you use sokol_gfx.h together with sokol_app.h, + just call the sglue_swapchain() helper function in sokol_glue.h to + provide the swapchain information. Otherwise the following information + must be provided: + + - the color pixel-format of the swapchain's render surface + - an optional depth/stencil pixel format if the swapchain + has a depth/stencil buffer + - an optional sample-count for MSAA rendering + - NOTE: the above three values can be zero-initialized, in that + case the defaults from the sg_environment struct will be used that + had been passed to the sg_setup() function. + - a number of backend specific objects: + - GL/GLES3: just a GL framebuffer handle + - D3D11: + - an ID3D11RenderTargetView for the rendering surface + - if MSAA is used, an ID3D11RenderTargetView as + MSAA resolve-target + - an optional ID3D11DepthStencilView for the + depth/stencil buffer + - WebGPU + - a WGPUTextureView object for the rendering surface + - if MSAA is used, a WGPUTextureView object as MSAA resolve target + - an optional WGPUTextureView for the + - Metal (NOTE that the roles of provided surfaces is slightly + different in Metal than in D3D11 or WebGPU, notably, the + CAMetalDrawable is either rendered to directly, or serves + as MSAA resolve target): + - a CAMetalDrawable object which is either rendered + into directly, or in case of MSAA rendering, serves + as MSAA-resolve-target + - if MSAA is used, an multisampled MTLTexture where + rendering goes into + - an optional MTLTexture for the depth/stencil buffer + + A sg_swapchain struct provided to sg_begin_pass() can indicate that the + swapchain is in an 'invalid state' via the boolean `sg_swapchain.invalid`. + When this flag is set, all other sg_swapchain members must be zeroed. + An invalid swapchain will cause all rendering operations in that pass + to be silently skipped. + + It's recommended that you create a helper function which returns an + initialized sg_swapchain struct by value. This can then be directly plugged + into the sg_begin_pass function like this: + + sg_begin_pass(&(sg_pass){ .swapchain = sglue_swapchain() }); + + As an example for such a helper function check out the function sglue_swapchain() + in the sokol_glue.h header. + + For offscreen render passes, the render target images used in a render pass + must be provided as sg_view objects specialized for the specific pass-attachment + types: + + - color-attachment-views for color-rendering + - depth-stencil-attachment-views for the depth-stencil-buffer surface + - resolve-attachment-views for MSAA-resolve operations + + For a simple offscreen scenario with one color-, one depth-stencil-render + target and without multisampling, setting up the required image- + and view-objects looks like this: + + First create two render target images, one with a color pixel format, + and one with the depth- or depth-stencil pixel format. Both images + must have the same dimensions. Also not the usage flags: + + const sg_image color_img = sg_make_image(&(sg_image_desc){ + .usage.color_attachment = true, + .width = 256, + .height = 256, + .pixel_format = SG_PIXELFORMAT_RGBA8, + .sample_count = 1, + }); + const sg_image depth_img = sg_make_image(&(sg_image_desc){ + .usage.depth_stencil_attachment = true, + .width = 256, + .height = 256, + .pixel_format = SG_PIXELFORMAT_DEPTH, + .sample_count = 1, + }); + + NOTE: when creating render target images, have in mind that some default values + are aligned with the default environment attributes in the sg_environment struct + that was passed into the sg_setup() call: + + - the default value for sg_image_desc.pixel_format is taken from + sg_environment.defaults.color_format + - the default value for sg_image_desc.sample_count is taken from + sg_environment.defaults.sample_count + - the default value for sg_image_desc.num_mipmaps is always 1 + + Next, create two view objects, one color-attachment-view and one + depth-stencil-attachment view: + + const sg_view color_att_view = sg_make_view(&(sg_view_desc){ + .color_attachment.image = color_img, + }); + const sg_view depth_att_view = sg_make_view(&(sg_view_desc){ + .depth_stencil_attachment.image = depth_img, + }); + + You'll typically also want to create a texture-view on the color image + to sample the color attachment image as texture in a later pass: + + const sg_view tex_view = sg_make_view(&(sg_view_desc){ + .texture.image = color_img, + }); + + The attachment-view objects are then passed into the sg_begin_pass function in + place of the nested swapchain struct: + + sg_begin_pass(&(sg_pass){ + .attachments = { + .colors[0] = color_att_view, + .depth_stencil = depth_att_view, + }, + }); + + ...in a later pass when you want to sample the color attachment image as + texture, use the texture view in the sg_apply_bindings() call: + + sg_apply_bindings(&(sg_bindings){ + .vertex_buffers[0] = ..., + .index_buffer = ..., + .views[VIEW_tex] = tex_view, + .samplers[SMP_smp] = smp, + }); + + Swapchain and offscreen passes form dependency trees with a swapchain + pass at the root, offscreen passes as nodes, and attachment images as + dependencies between passes. + + sg_pass_action structs are used to define actions that should happen at the + start and end of render passes (such as clearing pass attachments to a + specific color or depth-value, or performing an MSAA resolve operation at + the end of a pass). + + A typical sg_pass_action object which clears the color attachment to black + might look like this: + + const sg_pass_action = { + .colors[0] = { + .load_action = SG_LOADACTION_CLEAR, + .clear_value = { 0.0f, 0.0f, 0.0f, 1.0f } + } + }; + + This omits the defaults for the color attachment store action, and + the depth-stencil-attachments actions. The same pass action with the + defaults explicitly filled in would look like this: + + const sg_pass_action pass_action = { + .colors[0] = { + .load_action = SG_LOADACTION_CLEAR, + .store_action = SG_STOREACTION_STORE, + .clear_value = { 0.0f, 0.0f, 0.0f, 1.0f } + }, + .depth = = { + .load_action = SG_LOADACTION_CLEAR, + .store_action = SG_STOREACTION_DONTCARE, + .clear_value = 1.0f, + }, + .stencil = { + .load_action = SG_LOADACTION_CLEAR, + .store_action = SG_STOREACTION_DONTCARE, + .clear_value = 0 + } + }; + + With the sg_pass object and sg_pass_action struct in place everything + is ready now for the actual render pass: + + Using such this prepared sg_pass_action in a swapchain pass looks like + this: + + sg_begin_pass(&(sg_pass){ + .action = pass_action, + .swapchain = sglue_swapchain() + }); + ... + sg_end_pass(); + + ...of alternatively in one offscreen pass: + + sg_begin_pass(&(sg_pass){ + .action = pass_action, + .attachments = { + .colors[0] = color_att_view, + .depth_stencil = ds_att_view, + }, + }); + ... + sg_end_pass(); + + Offscreen rendering can also go into a mipmap, or a slice/face of + a cube-, array- or 3d-image (which some restrictions, for instance + it's not possible to create a 3D image with a depth/stencil pixel format, + these exceptions are generally caught by the sokol-gfx validation layer). + + The mipmap/slice selection is baked into the attachment-view objects, for + instance to create a color-attachment-view for rendering into mip-level + 2 and slice 3 of an array texture: + + const sg_view color_att_view = sg_make_view(&(sg_view_desc){ + .color_attachment = { + .image = color_img, + .mip_level = 2, + .slice = 3, + }, + }); + + If MSAA offscreen rendering is desired, the multi-sample rendering result + must be 'resolved' into a separate 'resolve image', before that image can + be used as texture. + + Setting up MSAA offscreen 3D rendering requires three image objects + (one color-attachment image with a sample count > 1), a resolve-attachment + image with a sample count of 1, and a depth-stencil-attachment image + with the same sample count as the color-attachment image: + + const sg_image color_img = sg_make_image(&(sg_image_desc){ + .usage.color_attachment = true, + .width = 256, + .height = 256, + .pixel_format = SG_PIXELFORMAT_RGBA8, + .sample_count = 4, + }); + const sg_image resolve_img = sg_make_image(&(sg_image_desc){ + .usage.resolve_attachment = true, + .width = 256, + .height = 256, + .pixel_format = SG_PIXELFORMAT_RGBA8, + .sample_count = 1, + }); + const sg_image depth_img = sg_make_image(&(sg_image_desc){ + .usage.depth_stencil_attachment = true, + .width = 256, + .height = 256, + .pixel_format = SG_PIXELFORMAT_DEPTH, + .sample_count = 4, + }); + + Next you'll need the corresponding attachment-view objects: + + const sg_view color_att_view = sg_make_view(&(sg_view_desc){ + .color_attachment.image = color_img, + }); + const sg_view resolve_att_view = sg_make_view(&(sg_view_desc){ + .resolve_attachment.image = resolve_img, + }); + const sg_view depth_att_view = sg_make_view(&(sg_view_desc){ + .depth_stencil_attachment.image = depth_img, + }); + + To sample the rendered image as a texture in a later pass you'll also + need a texture-view on the resolve-attachment-image (not the color-attachment-image!): + + const sg_view tex_view = sg_make_view(&(sg_view_desc){ + .texture.image = resolve_img, + }); + + Next start the render pass with all attachment-views, as soon as a + resolve-attachment-view is provided, an MSAA resolve operation will happen + at the end of the pass. Also note that the content of the MSAA color-attachment-image + doesn't need to be preserved, since it's only needed until the MSAA-resolve + at the end of the pass, so the .store_action should be set to "don't care": + + sg_begin_pass(&(sg_pass){ + .attachments = { + .colors[0] = color_att_view, + .resolves[0] = resolve_att_view, + .depth_stencil = depth_att_view, + }, + .action = { + .colors[0] = { + .load_action = SG_LOADACTION_CLEAR, + .store_action = SG_STOREACTION_DONTCARE, + .clear_value = { 0.0f, 0.0f, 0.0f, 1.0f }, + } + }, + }); + + ...in a later pass, use the texture-view that had been created on the + resolve-image to use the rendering result as texture: + + sg_apply_bindings(&(sg_bindings){ + .vertex_buffers[0] = ..., + .index_buffer = ..., + .views[VIEW_tex] = tex_view, + .samplers[SMP_smp] = smp, + }); + + ON COMPUTE PASSES + ================= + Compute passes are used to update the content of storage buffers and + storage images by running compute shader code on + the GPU. Updating storage resources with a compute shader will almost always + be more efficient than computing the same data on the CPU and then uploading + it via `sg_update_buffer()` or `sg_update_image()`. + + NOTE: compute passes are only supported on the following platforms and + backends: + + - macOS and iOS with Metal + - Windows with D3D11 and OpenGL + - Linux with OpenGL or GLES3.1+ + - Web with WebGPU + - Android with GLES3.1+ + + ...this means compute shaders can't be used on the following platform/backend + combos (the same restrictions apply to using storage buffers without compute + shaders): + + - macOS with GL + - iOS with GLES3 + - Web with WebGL2 + + A compute pass is started with: + + sg_begin_pass(&(sg_pass){ .compute = true }); + + ...and finished with a regular: + + sg_end_pass(); + + Typically the following functions will be called inside a compute pass: + + sg_apply_pipeline() + sg_apply_bindings() + sg_apply_uniforms() + sg_dispatch() + + The following functions are disallowed inside a compute pass + and will cause validation layer errors: + + sg_apply_viewport[f]() + sg_apply_scissor_rect[f]() + sg_draw() + + Only special 'compute shaders' and 'compute pipelines' can be used in + compute passes. A compute shader only has a compute-function instead + of a vertex- and fragment-function pair, and it doesn't accept vertex- + and index-buffers as bindings, only storage-buffer-views (readable + and writable), storage-image-views (read/write or writeonly) and + texture-views (read-only). + + A compute pipeline is created by providing a compute shader object, + setting the .compute creation parameter to true and not defining any + 'render state': + + sg_pipeline pip = sg_make_pipeline(&(sg_pipeline_desc){ + .compute = true, + .shader = compute_shader, + }); + + The sg_apply_bindings and sg_apply_uniforms calls are the same as in + render passes, with the exception that no vertex- and index-buffers + can be bound in the sg_apply_bindings call. + + Finally to kick off a compute workload, call sg_dispatch with the + number of workgroups in the x, y and z-dimension: + + sg_dispatch(int num_groups_x, int num_groups_y, int num_groups_z) + + Also see the following compute-shader samples: + + - https://floooh.github.io/sokol-webgpu/instancing-compute-sapp.html + - https://floooh.github.io/sokol-webgpu/computeboids-sapp.html + - https://floooh.github.io/sokol-webgpu/imageblur-sapp.html + + + ON SHADER CREATION + ================== + sokol-gfx doesn't come with an integrated shader cross-compiler, instead + backend-specific shader sources or binary blobs need to be provided when + creating a shader object, along with reflection information about the + shader resource binding interface needed to bind sokol-gfx resources to the + proper shader inputs. + + The easiest way to provide all this shader creation data is to use the + sokol-shdc shader compiler tool to compile shaders from a common + GLSL syntax into backend-specific sources or binary blobs, along with + shader interface information and uniform blocks and storage buffer array items + mapped to C structs. + + To create a shader using a C header which has been code-generated by sokol-shdc: + + // include the C header code-generated by sokol-shdc: + #include "myshader.glsl.h" + ... + + // create shader using a code-generated helper function from the C header: + sg_shader shd = sg_make_shader(myshader_shader_desc(sg_query_backend())); + + The samples in the 'sapp' subdirectory of the sokol-samples project + also use the sokol-shdc approach: + + https://github.com/floooh/sokol-samples/tree/master/sapp + + If you're planning to use sokol-shdc, you can stop reading here, instead + continue with the sokol-shdc documentation: + + https://github.com/floooh/sokol-tools/blob/master/docs/sokol-shdc.md + + To create shaders with backend-specific shader code or binary blobs, + the sg_make_shader() function requires the following information: + + - Shader code or shader binary blobs for the vertex- and fragment-, or the + compute-shader-stage: + - for the desktop GL backend, source code can be provided in '#version 410' or + '#version 430', version 430 is required when using storage buffers and + compute shaders, but note that this is not available on macOS + - for the GLES3 backend, source code must be provided in '#version 300 es' or + '#version 310 es' syntax (version 310 is required for storage buffer and + compute shader support, but note that this is not supported on WebGL2) + - for the D3D11 backend, shaders can be provided as source or binary + blobs, the source code should be in HLSL4.0 (for compatibility with old + low-end GPUs) or preferably in HLSL5.0 syntax, note that when + shader source code is provided for the D3D11 backend, sokol-gfx will + dynamically load 'd3dcompiler_47.dll' + - for the Metal backends, shaders can be provided as source or binary blobs, the + MSL version should be in 'metal-1.1' (other versions may work but are not tested) + - for the WebGPU backend, shaders must be provided as WGSL source code + - optionally the following shader-code related attributes can be provided: + - an entry function name (only on D3D11 or Metal, but not OpenGL) + - on D3D11 only, a compilation target (default is "vs_4_0" and "ps_4_0") + + - Information about the input vertex attributes used by the vertex shader, + most of that backend-specific: + - An optional 'base type' (float, signed-/unsigned-int) for each vertex + attribute. When provided, this is used by the validation layer to check + that the CPU-side input vertex format is compatible with the input + vertex declaration of the vertex shader. + - Metal: no location information needed since vertex attributes are always bound + by their attribute location defined in the shader via '[[attribute(N)]]' + - WebGPU: no location information needed since vertex attributes are always + bound by their attribute location defined in the shader via `@location(N)` + - GLSL: vertex attribute names can be optionally provided, in that case their + location will be looked up by name, otherwise, the vertex attribute location + can be defined with 'layout(location = N)' + - D3D11: a 'semantic name' and 'semantic index' must be provided for each vertex + attribute, e.g. if the vertex attribute is defined as 'TEXCOORD1' in the shader, + the semantic name would be 'TEXCOORD', and the semantic index would be '1' + + NOTE that vertex attributes currently must not have gaps. This requirement + may be relaxed in the future. + + - Specifically for Metal compute shaders, the 'number of threads per threadgroup' + must be provided. Normally this is extracted by sokol-shdc from the GLSL + shader source code. For instance the following statement in the input + GLSL: + + layout(local_size_x=64, local_size_y=1, local_size_z=1) in; + + ...will be communicated to the sokol-gfx Metal backend in the + code-generated sg_shader_desc struct: + + (sg_shader_desc){ + .mtl_threads_per_threadgroup = { .x = 64, .y = 1, .z = 1 }, + } + + - Information about each uniform block binding used in the shader: + - the shader stage of the uniform block (vertex, fragment or compute) + - the size of the uniform block in number of bytes + - a memory layout hint (currently 'native' or 'std140') where 'native' defines a + backend-specific memory layout which shouldn't be used for cross-platform code. + Only std140 guarantees a backend-agnostic memory layout. + - a backend-specific bind slot: + - D3D11/HLSL: the buffer register N (`register(bN)`) where N is 0..7 + - Metal/MSL: the buffer bind slot N (`[[buffer(N)]]`) where N is 0..7 + - WebGPU: the binding N in `@group(0) @binding(N)` where N is 0..15 + - For GLSL only: a description of the internal uniform block layout, which maps + member types and their offsets on the CPU side to uniform variable names + in the GLSL shader + - please also NOTE the documentation sections about UNIFORM DATA LAYOUT + and CROSS-BACKEND COMMON UNIFORM DATA LAYOUT below! + + - A description of each resource binding (texture-, storage-buffer- + and storage-image-bindings) which directly map to the sg_bindings.view[] + array slots. + + Each resource binding slot comes in three flavours: + + 1. Texture bindings with the following properties: + - the shader stage of the texture (vertex, fragment or compute) + - the expected image type: + - SG_IMAGETYPE_2D + - SG_IMAGETYPE_CUBE + - SG_IMAGETYPE_3D + - SG_IMAGETYPE_ARRAY + - the expected 'image sample type': + - SG_IMAGESAMPLETYPE_FLOAT + - SG_IMAGESAMPLETYPE_DEPTH + - SG_IMAGESAMPLETYPE_SINT + - SG_IMAGESAMPLETYPE_UINT + - SG_IMAGESAMPLETYPE_UNFILTERABLE_FLOAT + - a flag whether the texture is expected to be multisampled + - a backend-specific bind slot: + - D3D11/HLSL: the texture register N (`register(tN)`) where N is 0..31 + (in HLSL, readonly storage buffers and texture share the same bind space) + - Metal/MSL: the texture bind slot N (`[[texture(N)]]`) where N is 0..31 + (the bind slot must not collide with storage image bindings on the same stage) + - WebGPU/WGSL: the binding N in `@group(0) @binding(N)` where N is 0..127 + + 2. Storage buffer bindings with the following properties: + - the shader stage of the storage buffer + - a boolean 'readonly' flag, this is used for validation and hazard + tracking in some 3D backends. Note that in render passes, only + readonly storage buffer bindings are allowed. In compute passes, any + read/write storage buffer binding is assumed to be written to by the + compute shader. + - a backend-specific bind slot: + - D3D11/HLSL: + - for readonly storage buffer bindings: the texture register N + (`register(tN)`) where N is 0..31 (in HLSL, readonly storage + buffers and textures share the same bind space for + 'shader resource views') + - for read/write storage buffer buffer bindings: the UAV register N + (`register(uN)`) where N is 0..31 (in HLSL, readwrite storage + buffers use their own bind space for 'unordered access views') + - Metal/MSL: the buffer bind slot N (`[[buffer(N)]]`) where N is 8..23 + - WebGPU/WGSL: the binding N in `@group(0) @binding(N)` where N is 0..127 + - GL/GLSL: the buffer binding N in `layout(binding=N)` + where N is 0..sg_limits.max_storage_buffer_bindings_per_stage + - note that storage buffer bindings are not supported on all backends + and platforms + + 3. Storage image bindings with the following properties: + - the shader stage (*must* be compute) + - the expected image type: + - SG_IMAGETYPE_2D + - SG_IMAGETYPE_CUBE + - SG_IMAGETYPE_3D + - SG_IMAGETYPE_ARRAY + - the 'access pixel format', this is currently limited to: + - SG_PIXELFORMAT_RGBA8 + - SG_PIXELFORMAT_RGBA8SN/UI/SI + - SG_PIXELFORMAT_RGBA16UI/SI/F + - SG_PIXELFORMAT_R32UIUI/SI/F + - SG_PIXELFORMAT_RG32UI/SI/F + - SG_PIXELFORMAT_RGBA32UI/SI/F + - the access type (readwrite or writeonly) + - a backend-specific bind slot: + - D3D11/HLSL: the UAV register N (`register(uN)` where N is 0..31, the + bind slot must not collide with UAV storage buffer bindings + - Metal/MSL: the texture bind slot N (`[[texture(N)]])` where N is 0..31, + the bind slot must not collide with other texture bindings on the same + stage + - WebGPU/WGSL: the binding N in `@group(1) @binding(N)` where N is 0..127 + - GL/GLSL: the buffer binding N in `layout(binding=N)` + where N is 0.._sg.max_storage_image_bindings_per_stage + - note that storage image bindings are not supported on all backends and platforms + + - A description of each sampler used in the shader: + - the shader stage of the sampler (vertex, fragment or compute) + - the expected sampler type: + - SG_SAMPLERTYPE_FILTERING, + - SG_SAMPLERTYPE_NONFILTERING, + - SG_SAMPLERTYPE_COMPARISON, + - a backend-specific bind slot: + - D3D11/HLSL: the sampler register N (`register(sN)`) where N is 0..SG_MAX_SAMPLER_BINDINGS + - Metal/MSL: the sampler bind slot N (`[[sampler(N)]]`) where N is 0..SG_MAX_SAMPLER_BINDINGS + - WebGPU/WGSL: the binding N in `@group(0) @binding(N)` where N is 0..127 + + - An array of 'texture-sampler-pairs' used by the shader to sample textures, + for D3D11, Metal and WebGPU this is used for validation purposes to check + whether the texture and sampler are compatible with each other (especially + WebGPU is very picky about combining the correct + texture-sample-type with the correct sampler-type). For GLSL an + additional 'combined-image-sampler name' must be provided because 'OpenGL + style GLSL' cannot handle separate texture and sampler objects, but still + groups them into a traditional GLSL 'sampler object'. + + Compatibility rules for image-sample-type vs sampler-type are as follows: + + - SG_IMAGESAMPLETYPE_FLOAT => (SG_SAMPLERTYPE_FILTERING or SG_SAMPLERTYPE_NONFILTERING) + - SG_IMAGESAMPLETYPE_UNFILTERABLE_FLOAT => SG_SAMPLERTYPE_NONFILTERING + - SG_IMAGESAMPLETYPE_SINT => SG_SAMPLERTYPE_NONFILTERING + - SG_IMAGESAMPLETYPE_UINT => SG_SAMPLERTYPE_NONFILTERING + - SG_IMAGESAMPLETYPE_DEPTH => SG_SAMPLERTYPE_COMPARISON + + Backend-specific bindslot ranges (not relevant when using sokol-shdc): + + - D3D11/HLSL: + - separate bindslot space per shader stage + - uniform block bindings (as cbuffer): `register(b0..b7)` + - texture- and readonly storage buffer bindings: `register(t0..t31)` + - read/write storage buffer and storage image bindings: `register(u0..u31)` + - samplers: `register(s0..s11)` + - Metal/MSL: + - separate bindslot space per shader stage + - uniform blocks: `[[buffer(0..7)]]` + - storage buffers: `[[buffer(8..23)]]` + - textures and storage image bindings: `[[texture(0..31)]]` + - samplers: `[[sampler(0..11)]]` + - WebGPU/WGSL: + - common bindslot space across shader stages + - uniform blocks: `@group(0) @binding(0..15)` + - textures, storage-images, storage-buffers and sampler: `@group(1) @binding(0..127)` + - GL/GLSL: + - uniforms and image-samplers are bound by name + - storage buffer bindings: `layout(std430, binding=0..sg_limits.max_storage_buffer_bindings_per_stage` (common + bindslot space across shader stages) + - storage image bindings: `layout(binding=0..sg_limits.max_storage_image_bindings_per_stage, [access_format])` + + For example code of how to create backend-specific shader objects, + please refer to the following samples: + + - for D3D11: https://github.com/floooh/sokol-samples/tree/master/d3d11 + - for Metal: https://github.com/floooh/sokol-samples/tree/master/metal + - for OpenGL: https://github.com/floooh/sokol-samples/tree/master/glfw + - for GLES3: https://github.com/floooh/sokol-samples/tree/master/html5 + - for WebGPU: https://github.com/floooh/sokol-samples/tree/master/wgpu + + + ON SG_IMAGESAMPLETYPE_UNFILTERABLE_FLOAT AND SG_SAMPLERTYPE_NONFILTERING + ======================================================================== + The WebGPU backend introduces the concept of 'unfilterable-float' textures, + which can only be combined with 'nonfiltering' samplers (this is a restriction + specific to WebGPU, but since the same sokol-gfx code should work across + all backend, the sokol-gfx validation layer also enforces this restriction + - the alternative would be undefined behaviour in some backend APIs on + some devices). + + The background is that some mobile devices (most notably iOS devices) can + not perform linear filtering when sampling textures with certain pixel + formats, most notable the 32F formats: + + - SG_PIXELFORMAT_R32F + - SG_PIXELFORMAT_RG32F + - SG_PIXELFORMAT_RGBA32F + + The information of whether a shader is going to be used with such an + unfilterable-float texture must already be provided in the sg_shader_desc + struct when creating the shader (see the above section "ON SHADER CREATION"). + + If you are using the sokol-shdc shader compiler, the information whether a + texture/sampler binding expects an 'unfilterable-float/nonfiltering' + texture/sampler combination cannot be inferred from the shader source + alone, you'll need to provide this hint via annotation-tags. For instance + here is an example from the ozz-skin-sapp.c sample shader which samples an + RGBA32F texture with skinning matrices in the vertex shader: + + ```glsl + @image_sample_type joint_tex unfilterable_float + uniform texture2D joint_tex; + @sampler_type smp nonfiltering + uniform sampler smp; + ``` + + This will result in SG_IMAGESAMPLETYPE_UNFILTERABLE_FLOAT and + SG_SAMPLERTYPE_NONFILTERING being written to the code-generated + sg_shader_desc struct. + + + ON VERTEX FORMATS + ================= + Sokol-gfx implements the same strict mapping rules from CPU-side + vertex component formats to GPU-side vertex input data types: + + - float and packed normalized CPU-side formats must be used as + floating point base type in the vertex shader + - packed signed-integer CPU-side formats must be used as signed + integer base type in the vertex shader + - packed unsigned-integer CPU-side formats must be used as unsigned + integer base type in the vertex shader + + These mapping rules are enforced by the sokol-gfx validation layer, + but only when sufficient reflection information is provided in + `sg_shader_desc.attrs[].base_type`. This is the case when sokol-shdc + is used, otherwise the default base_type will be SG_SHADERATTRBASETYPE_UNDEFINED + which causes the sokol-gfx validation check to be skipped (of course you + can also provide the per-attribute base type information manually when + not using sokol-shdc). + + The detailed mapping rules from SG_VERTEXFORMAT_* to GLSL data types + are as follows: + + - FLOAT[*] => float, vec* + - BYTE4N => vec* (scaled to -1.0 .. +1.0) + - UBYTE4N => vec* (scaled to 0.0 .. +1.0) + - SHORT[*]N => vec* (scaled to -1.0 .. +1.0) + - USHORT[*]N => vec* (scaled to 0.0 .. +1.0) + - INT[*] => int, ivec* + - UINT[*] => uint, uvec* + - BYTE4 => int* + - UBYTE4 => uint* + - SHORT[*] => int* + - USHORT[*] => uint* + + NOTE that sokol-gfx only provides vertex formats with sizes of a multiple + of 4 (e.g. BYTE4N but not BYTE2N). This is because vertex components must + be 4-byte aligned anyway. + + + UNIFORM DATA LAYOUT: + ==================== + NOTE: if you use the sokol-shdc shader compiler tool, you don't need to worry + about the following details. + + The data that's passed into the sg_apply_uniforms() function must adhere to + specific layout rules so that the GPU shader finds the uniform block + items at the right offset. + + For the D3D11 and Metal backends, sokol-gfx only cares about the size of uniform + blocks, but not about the internal layout. The data will just be copied into + a uniform/constant buffer in a single operation and it's up you to arrange the + CPU-side layout so that it matches the GPU side layout. This also means that with + the D3D11 and Metal backends you are not limited to a 'cross-platform' subset + of uniform variable types. + + If you ever only use one of the D3D11, Metal *or* WebGPU backend, you can stop reading here. + + For the GL backends, the internal layout of uniform blocks matters though, + and you are limited to a small number of uniform variable types. This is + because sokol-gfx must be able to locate the uniform block members in order + to upload them to the GPU with glUniformXXX() calls. + + To describe the uniform block layout to sokol-gfx, the following information + must be passed to the sg_make_shader() call in the sg_shader_desc struct: + + - a hint about the used packing rule (either SG_UNIFORMLAYOUT_NATIVE or + SG_UNIFORMLAYOUT_STD140) + - a list of the uniform block members types in the correct order they + appear on the CPU side + + For example if the GLSL shader has the following uniform declarations: + + uniform mat4 mvp; + uniform vec2 offset0; + uniform vec2 offset1; + uniform vec2 offset2; + + ...and on the CPU side, there's a similar C struct: + + typedef struct { + float mvp[16]; + float offset0[2]; + float offset1[2]; + float offset2[2]; + } params_t; + + ...the uniform block description in the sg_shader_desc must look like this: + + sg_shader_desc desc = { + .vs.uniform_blocks[0] = { + .size = sizeof(params_t), + .layout = SG_UNIFORMLAYOUT_NATIVE, // this is the default and can be omitted + .uniforms = { + // order must be the same as in 'params_t': + [0] = { .name = "mvp", .type = SG_UNIFORMTYPE_MAT4 }, + [1] = { .name = "offset0", .type = SG_UNIFORMTYPE_VEC2 }, + [2] = { .name = "offset1", .type = SG_UNIFORMTYPE_VEC2 }, + [3] = { .name = "offset2", .type = SG_UNIFORMTYPE_VEC2 }, + } + } + }; + + With this information sokol-gfx can now compute the correct offsets of the data items + within the uniform block struct. + + The SG_UNIFORMLAYOUT_NATIVE packing rule works fine if only the GL backends are used, + but for proper D3D11/Metal/GL a subset of the std140 layout must be used which is + described in the next section: + + + CROSS-BACKEND COMMON UNIFORM DATA LAYOUT + ======================================== + For cross-platform / cross-3D-backend code it is important that the same uniform block + layout on the CPU side can be used for all sokol-gfx backends. To achieve this, + a common subset of the std140 layout must be used: + + - The uniform block layout hint in sg_shader_desc must be explicitly set to + SG_UNIFORMLAYOUT_STD140. + - Only the following GLSL uniform types can be used (with their associated sokol-gfx enums): + - float => SG_UNIFORMTYPE_FLOAT + - vec2 => SG_UNIFORMTYPE_FLOAT2 + - vec3 => SG_UNIFORMTYPE_FLOAT3 + - vec4 => SG_UNIFORMTYPE_FLOAT4 + - int => SG_UNIFORMTYPE_INT + - ivec2 => SG_UNIFORMTYPE_INT2 + - ivec3 => SG_UNIFORMTYPE_INT3 + - ivec4 => SG_UNIFORMTYPE_INT4 + - mat4 => SG_UNIFORMTYPE_MAT4 + - Alignment for those types must be as follows (in bytes): + - float => 4 + - vec2 => 8 + - vec3 => 16 + - vec4 => 16 + - int => 4 + - ivec2 => 8 + - ivec3 => 16 + - ivec4 => 16 + - mat4 => 16 + - Arrays are only allowed for the following types: vec4, int4, mat4. + + Note that the HLSL cbuffer layout rules are slightly different from the + std140 layout rules, this means that the cbuffer declarations in HLSL code + must be tweaked so that the layout is compatible with std140. + + The by far easiest way to tackle the common uniform block layout problem is + to use the sokol-shdc shader cross-compiler tool! + + + ON STORAGE BUFFERS + ================== + The two main purpose of storage buffers are: + + - to be populated by compute shaders with dynamically generated data + - for providing random-access data to all shader stages + + Storage buffers can be used to pass large amounts of random access structured + data from the CPU side to the shaders. They are similar to data textures, but are + more convenient to use both on the CPU and shader side since they can be accessed + in shaders as as a 1-dimensional array of struct items. + + Storage buffers are *NOT* supported on the following platform/backend combos: + + - macOS+GL (because storage buffers require GL 4.3, while macOS only goes up to GL 4.1) + - platforms which only support a GLES3.0 context (WebGL2 and iOS) + + To use storage buffers, the following steps are required: + + - write a shader which uses storage buffers (vertex- and fragment-shaders + can only read from storage buffers, while compute-shaders can both read + and write storage buffers) + - create one or more storage buffers via sg_make_buffer() with the + `.usage.storage_buffer = true` + - when creating a shader via sg_make_shader(), populate the sg_shader_desc + struct with binding info (when using sokol-shdc, this step will be taken care + of automatically) + - which storage buffer bind slots on the vertex-, fragment- or compute-stage + are occupied + - whether the storage buffer on that bind slot is readonly (readonly + bindings are required for vertex- and fragment-shaders, and in compute + shaders the readonly flag is used to control hazard tracking in some + 3D backends) + + - when calling sg_apply_bindings(), apply the matching bind slots with the previously + created storage buffers + - ...and that's it. + + For more details, see the following backend-agnostic sokol samples: + + - simple vertex pulling from a storage buffer: + - C code: https://github.com/floooh/sokol-samples/blob/master/sapp/vertexpull-sapp.c + - shader: https://github.com/floooh/sokol-samples/blob/master/sapp/vertexpull-sapp.glsl + - instanced rendering via storage buffers (vertex- and instance-pulling): + - C code: https://github.com/floooh/sokol-samples/blob/master/sapp/instancing-pull-sapp.c + - shader: https://github.com/floooh/sokol-samples/blob/master/sapp/instancing-pull-sapp.glsl + - storage buffers both on the vertex- and fragment-stage: + - C code: https://github.com/floooh/sokol-samples/blob/master/sapp/sbuftex-sapp.c + - shader: https://github.com/floooh/sokol-samples/blob/master/sapp/sbuftex-sapp.glsl + - the Ozz animation sample rewritten to pull all rendering data from storage buffers: + - C code: https://github.com/floooh/sokol-samples/blob/master/sapp/ozz-storagebuffer-sapp.cc + - shader: https://github.com/floooh/sokol-samples/blob/master/sapp/ozz-storagebuffer-sapp.glsl + - the instancing sample modified to use compute shaders: + - C code: https://github.com/floooh/sokol-samples/blob/master/sapp/instancing-compute-sapp.c + - shader: https://github.com/floooh/sokol-samples/blob/master/sapp/instancing-compute-sapp.glsl + - the Compute Boids sample ported to sokol-gfx: + - C code: https://github.com/floooh/sokol-samples/blob/master/sapp/computeboids-sapp.c + - shader: https://github.com/floooh/sokol-samples/blob/master/sapp/computeboids-sapp.glsl + + ...also see the following backend-specific vertex pulling samples (those also don't use sokol-shdc): + + - D3D11: https://github.com/floooh/sokol-samples/blob/master/d3d11/vertexpulling-d3d11.c + - desktop GL: https://github.com/floooh/sokol-samples/blob/master/glfw/vertexpulling-glfw.c + - Metal: https://github.com/floooh/sokol-samples/blob/master/metal/vertexpulling-metal.c + - WebGPU: https://github.com/floooh/sokol-samples/blob/master/wgpu/vertexpulling-wgpu.c + + ...and the backend specific compute shader samples: + + - D3D11: https://github.com/floooh/sokol-samples/blob/master/d3d11/instancing-compute-d3d11.c + - desktop GL: https://github.com/floooh/sokol-samples/blob/master/glfw/instancing-compute-glfw.c + - Metal: https://github.com/floooh/sokol-samples/blob/master/metal/instancing-compute-metal.c + - WebGPU: https://github.com/floooh/sokol-samples/blob/master/wgpu/instancing-compute-wgpu.c + + Storage buffer shader authoring caveats when using sokol-shdc: + + - declare a read-only storage buffer interface block with `layout(binding=N) readonly buffer [name] { ... }` + (where 'N' is the index in `sg_bindings.storage_buffers[N]`) + - ...or a read/write storage buffer interface block with `layout(binding=N) buffer [name] { ... }` + - declare a struct which describes a single array item in the storage buffer interface block + - only put a single flexible array member into the storage buffer interface block + + E.g. a complete example in 'sokol-shdc GLSL': + + ```glsl + @vs + // declare a struct: + struct sb_vertex { + vec3 pos; + vec4 color; + } + // declare a buffer interface block with a single flexible struct array: + layout(binding=0) readonly buffer vertices { + sb_vertex vtx[]; + } + // in the shader function, access the storage buffer like this: + void main() { + vec3 pos = vtx[gl_VertexIndex].pos; + ... + } + @end + ``` + + In a compute shader you can read and write the same item in the same + storage buffer (but you'll have to be careful for random access since + many threads of the same compute function run in parallel): + + @cs + struct sb_item { + vec3 pos; + vec3 vel; + } + layout(binding=0) buffer items_ssbo { + sb_item items[]; + } + layout(local_size_x=64, local_size_y=1, local_size_z=1) in; + void main() { + uint index = gl_GlobalInvocationID.x; + vec3 pos = items[index].pos; + ... + items[index].pos = pos; + } + @end + + Backend-specific storage-buffer caveats (not relevant when using sokol-shdc): + + D3D11: + - storage buffers are created as 'raw' Byte Address Buffers + (https://learn.microsoft.com/en-us/windows/win32/direct3d11/overviews-direct3d-11-resources-intro#raw-views-of-buffers) + - in HLSL, use a ByteAddressBuffer for readonly access of the buffer content: + (https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/sm5-object-byteaddressbuffer) + - ...or RWByteAddressBuffer for read/write access: + (https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/sm5-object-rwbyteaddressbuffer) + - readonly-storage buffers and textures are both bound as 'shader-resource-view' and + share the same bind slots (declared as `register(tN)` in HLSL), where N must be in the range 0..23) + - read/write storage buffers and storage images are bound as 'unordered-access-view' + (declared as `register(uN)` in HLSL where N is in the range 0..11) + + Metal: + - in Metal there is no internal difference between vertex-, uniform- and + storage-buffers, all are bound to the same 'buffer bind slots' with the + following reserved ranges: + - vertex shader stage: + - uniform buffers: slots 0..7 + - storage buffers: slots 8..15 + - vertex buffers: slots 15..23 + - fragment shader stage: + - uniform buffers: slots 0..7 + - storage buffers: slots 8..15 + - this means in MSL, storage buffer bindings start at [[buffer(8)]] both in + the vertex and fragment stage + + GL: + - the GL backend doesn't use name-lookup to find storage buffer bindings, this + means you must annotate buffers with `layout(std430, binding=N)` in GLSL + - ...where N is 0..sg_limits.max_storage_buffer_bindings_per_stage. + + WebGPU: + - in WGSL, textures, samplers and storage buffers all use a shared + bindspace across all shader stages on bindgroup 1: + + `@group(1) @binding(0..127) + + ON STORAGE IMAGES: + ================== + To write pixel data to texture objects in compute shaders, first an image + object must be created with `storage_image usage`: + + sg_image storage_image = sg_make_image(&(sg_image_desc){ + .usage.storage_image = true, + }, + .width = ..., + .height = ..., + .pixel_format = ..., + }); + + Next a storage-image-view object is required which also allows to pick + a specific mip-level or slice for the compute-shader to access: + + sg_view simg_view = sg_make_view(&(sg_view_desc){ + .storage_image = { + .image = storage_image, + .mip_level = ..., + .slice = ... + }, + }); + + Finally 'bind' the storage-image-view via a regular sg_apply_bindings() call + inside a compute pass: + + sg_begin_pass(&(sg_pass){ .compute = true }); + sg_apply_pipeline(...); + sg_apply_bindings(&(sg_bindings){ + .views[VIEW_simg] = simg_view, + }); + sg_dispatch(...); + sg_end_pass(); + + Currently, storage images can only be used with `readwrite` or `writeonly` access in + shaders. For readonly access use a regular texture binding instead. + + For an example of using storage images in compute shaders see imageblur-sapp: + + - C code: https://github.com/floooh/sokol-samples/blob/master/sapp/imageblur-sapp.c + - shader: https://github.com/floooh/sokol-samples/blob/master/sapp/imageblur-sapp.glsl + + TRACE HOOKS: + ============ + sokol_gfx.h optionally allows to install "trace hook" callbacks for + each public API functions. When a public API function is called, and + a trace hook callback has been installed for this function, the + callback will be invoked with the parameters and result of the function. + This is useful for things like debugging- and profiling-tools, or + keeping track of resource creation and destruction. + + To use the trace hook feature: + + --- Define SOKOL_TRACE_HOOKS before including the implementation. + + --- Setup an sg_trace_hooks structure with your callback function + pointers (keep all function pointers you're not interested + in zero-initialized), optionally set the user_data member + in the sg_trace_hooks struct. + + --- Install the trace hooks by calling sg_install_trace_hooks(), + the return value of this function is another sg_trace_hooks + struct which contains the previously set of trace hooks. + You should keep this struct around, and call those previous + functions pointers from your own trace callbacks for proper + chaining. + + As an example of how trace hooks are used, have a look at the + imgui/sokol_gfx_imgui.h header which implements a realtime + debugging UI for sokol_gfx.h on top of Dear ImGui. + + + MEMORY ALLOCATION OVERRIDE + ========================== + You can override the memory allocation functions at initialization time + like this: + + void* my_alloc(size_t size, void* user_data) { + return malloc(size); + } + + void my_free(void* ptr, void* user_data) { + free(ptr); + } + + ... + sg_setup(&(sg_desc){ + // ... + .allocator = { + .alloc_fn = my_alloc, + .free_fn = my_free, + .user_data = ..., + } + }); + ... + + If no overrides are provided, malloc and free will be used. + + This only affects memory allocation calls done by sokol_gfx.h + itself though, not any allocations in OS libraries. + + + ERROR REPORTING AND LOGGING + =========================== + To get any logging information at all you need to provide a logging callback in the setup call + the easiest way is to use sokol_log.h: + + #include "sokol_log.h" + + sg_setup(&(sg_desc){ .logger.func = slog_func }); + + To override logging with your own callback, first write a logging function like this: + + void my_log(const char* tag, // e.g. 'sg' + uint32_t log_level, // 0=panic, 1=error, 2=warn, 3=info + uint32_t log_item_id, // SG_LOGITEM_* + const char* message_or_null, // a message string, may be nullptr in release mode + uint32_t line_nr, // line number in sokol_gfx.h + const char* filename_or_null, // source filename, may be nullptr in release mode + void* user_data) + { + ... + } + + ...and then setup sokol-gfx like this: + + sg_setup(&(sg_desc){ + .logger = { + .func = my_log, + .user_data = my_user_data, + } + }); + + The provided logging function must be reentrant (e.g. be callable from + different threads). + + If you don't want to provide your own custom logger it is highly recommended to use + the standard logger in sokol_log.h instead, otherwise you won't see any warnings or + errors. + + + COMMIT LISTENERS + ================ + It's possible to hook callback functions into sokol-gfx which are called from + inside sg_commit() in unspecified order. This is mainly useful for libraries + that build on top of sokol_gfx.h to be notified about the end/start of a frame. + + To add a commit listener, call: + + static void my_commit_listener(void* user_data) { + ... + } + + bool success = sg_add_commit_listener((sg_commit_listener){ + .func = my_commit_listener, + .user_data = ..., + }); + + The function returns false if the internal array of commit listeners is full, + or the same commit listener had already been added. + + If the function returns true, my_commit_listener() will be called each frame + from inside sg_commit(). + + By default, 1024 distinct commit listeners can be added, but this number + can be tweaked in the sg_setup() call: + + sg_setup(&(sg_desc){ + .max_commit_listeners = 2048, + }); + + An sg_commit_listener item is equal to another if both the function + pointer and user_data field are equal. + + To remove a commit listener: + + bool success = sg_remove_commit_listener((sg_commit_listener){ + .func = my_commit_listener, + .user_data = ..., + }); + + ...where the .func and .user_data field are equal to a previous + sg_add_commit_listener() call. The function returns true if the commit + listener item was found and removed, and false otherwise. + + + RESOURCE CREATION AND DESTRUCTION IN DETAIL + =========================================== + The 'vanilla' way to create resource objects is with the 'make functions': + + sg_buffer sg_make_buffer(const sg_buffer_desc* desc) + sg_image sg_make_image(const sg_image_desc* desc) + sg_sampler sg_make_sampler(const sg_sampler_desc* desc) + sg_shader sg_make_shader(const sg_shader_desc* desc) + sg_pipeline sg_make_pipeline(const sg_pipeline_desc* desc) + sg_view sg_make_view(const sg_view_desc* desc) + + This will result in one of three cases: + + 1. The returned handle is invalid. This happens when there are no more + free slots in the resource pool for this resource type. An invalid + handle is associated with the INVALID resource state, for instance: + + sg_buffer buf = sg_make_buffer(...) + if (sg_query_buffer_state(buf) == SG_RESOURCESTATE_INVALID) { + // buffer pool is exhausted + } + + 2. The returned handle is valid, but creating the underlying resource + has failed for some reason. This results in a resource object in the + FAILED state. The reason *why* resource creation has failed differ + by resource type. Look for log messages with more details. A failed + resource state can be checked with: + + sg_buffer buf = sg_make_buffer(...) + if (sg_query_buffer_state(buf) == SG_RESOURCESTATE_FAILED) { + // creating the resource has failed + } + + 3. And finally, if everything goes right, the returned resource is + in resource state VALID and ready to use. This can be checked + with: + + sg_buffer buf = sg_make_buffer(...) + if (sg_query_buffer_state(buf) == SG_RESOURCESTATE_VALID) { + // creating the resource has succeeded + } + + When calling the 'make functions', the created resource goes through a number + of states: + + - INITIAL: the resource slot associated with the new resource is currently + free (technically, there is no resource yet, just an empty pool slot) + - ALLOC: a handle for the new resource has been allocated, this just means + a pool slot has been reserved. + - VALID or FAILED: in VALID state any 3D API backend resource objects have + been successfully created, otherwise if anything went wrong, the resource + will be in FAILED state. + + Sometimes it makes sense to first grab a handle, but initialize the + underlying resource at a later time. For instance when loading data + asynchronously from a slow data source, you may know what buffers and + textures are needed at an early stage of the loading process, but actually + loading the buffer or texture content can only be completed at a later time. + + For such situations, sokol-gfx resource objects can be created in two steps. + You can allocate a handle upfront with one of the 'alloc functions': + + sg_buffer sg_alloc_buffer(void) + sg_image sg_alloc_image(void) + sg_sampler sg_alloc_sampler(void) + sg_shader sg_alloc_shader(void) + sg_pipeline sg_alloc_pipeline(void) + sg_view sg_alloc_view(void) + + This will return a handle with the underlying resource object in the + ALLOC state: + + sg_image img = sg_alloc_image(); + if (sg_query_image_state(img) == SG_RESOURCESTATE_ALLOC) { + // allocating an image handle has succeeded, otherwise + // the image pool is full + } + + Such an 'incomplete' handle can be used in most sokol-gfx rendering functions + without doing any harm, sokol-gfx will simply skip any rendering operation + that involve resources which are not in VALID state. + + At a later time (for instance once the texture has completed loading + asynchronously), the resource creation can be completed by calling one of + the 'init functions', those functions take an existing resource handle and + 'desc struct': + + void sg_init_buffer(sg_buffer buf, const sg_buffer_desc* desc) + void sg_init_image(sg_image img, const sg_image_desc* desc) + void sg_init_sampler(sg_sampler smp, const sg_sampler_desc* desc) + void sg_init_shader(sg_shader shd, const sg_shader_desc* desc) + void sg_init_pipeline(sg_pipeline pip, const sg_pipeline_desc* desc) + void sg_init_view(sg_view view, const sg_view_desc* desc) + + The init functions expect a resource in ALLOC state, and after the function + returns, the resource will be either in VALID or FAILED state. Calling + an 'alloc function' followed by the matching 'init function' is fully + equivalent with calling the 'make function' alone. + + Destruction can also happen as a two-step process. The 'uninit functions' + will put a resource object from the VALID or FAILED state back into the + ALLOC state: + + void sg_uninit_buffer(sg_buffer buf) + void sg_uninit_image(sg_image img) + void sg_uninit_sampler(sg_sampler smp) + void sg_uninit_shader(sg_shader shd) + void sg_uninit_pipeline(sg_pipeline pip) + void sg_uninit_view(sg_view view) + + Calling the 'uninit functions' with a resource that is not in the VALID or + FAILED state is a no-op. + + To finally free the pool slot for recycling call the 'dealloc functions': + + void sg_dealloc_buffer(sg_buffer buf) + void sg_dealloc_image(sg_image img) + void sg_dealloc_sampler(sg_sampler smp) + void sg_dealloc_shader(sg_shader shd) + void sg_dealloc_pipeline(sg_pipeline pip) + void sg_dealloc_view(sg_view view) + + Calling the 'dealloc functions' on a resource that's not in ALLOC state is + a no-op, but will generate a warning log message. + + Calling an 'uninit function' and 'dealloc function' in sequence is equivalent + with calling the associated 'destroy function': + + void sg_destroy_buffer(sg_buffer buf) + void sg_destroy_image(sg_image img) + void sg_destroy_sampler(sg_sampler smp) + void sg_destroy_shader(sg_shader shd) + void sg_destroy_pipeline(sg_pipeline pip) + void sg_destroy_view(sg_view view) + + The 'destroy functions' can be called on resources in any state and generally + do the right thing (for instance if the resource is in ALLOC state, the destroy + function will be equivalent to the 'dealloc function' and skip the 'uninit part'). + + And finally to close the circle, the 'fail functions' can be called to manually + put a resource in ALLOC state into the FAILED state: + + sg_fail_buffer(sg_buffer buf) + sg_fail_image(sg_image img) + sg_fail_sampler(sg_sampler smp) + sg_fail_shader(sg_shader shd) + sg_fail_pipeline(sg_pipeline pip) + sg_fail_view(sg_view view) + + This is recommended if anything went wrong outside of sokol-gfx during asynchronous + resource setup (for instance a file loading operation failed). In this case, + the 'fail function' should be called instead of the 'init function'. + + Calling a 'fail function' on a resource that's not in ALLOC state is a no-op, + but will generate a warning log message. + + NOTE: that two-step resource creation usually only makes sense for buffers, + images and views, but not for samplers, shaders or pipelines. Most notably, trying + to create a pipeline object with a shader that's not in VALID state will + trigger a validation layer error, or if the validation layer is disabled, + result in a pipeline object in FAILED state. + + + WEBGPU CAVEATS + ============== + For a general overview and design notes of the WebGPU backend see: + + https://floooh.github.io/2023/10/16/sokol-webgpu.html + + In general, don't expect an automatic speedup when switching from the WebGL2 + backend to the WebGPU backend. Some WebGPU functions currently actually + have a higher CPU overhead than similar WebGL2 functions, leading to the + paradoxical situation that some WebGPU code may be slower than similar WebGL2 + code. + + - when writing WGSL shader code by hand, a specific bind-slot convention + must be used: + + All uniform block structs must use `@group(0)` and bindings in the + range 0..15 + + @group(0) @binding(0..15) + + All textures, samplers, storage-buffers and storage-images must use `@group(1)` + and bindings must be in the range 0..127: + + @group(1) @binding(0..127) + + Note that the number of texture, sampler, storage-buffer storage-image bindings + is still limited despite the large bind range: + + - up to 16 textures and sampler across all shader stages + - up to 8 storage buffers across all shader stages + - up to 4 storage images on the compute shader stage + + If you use sokol-shdc to generate WGSL shader code, you don't need to worry + about the above binding conventions since sokol-shdc will allocate + the WGSL bindslots). + + - The sokol-gfx WebGPU backend uses the sg_desc.uniform_buffer_size item + to allocate a single per-frame uniform buffer which must be big enough + to hold all data written by sg_apply_uniforms() during a single frame, + including a worst-case 256-byte alignment (e.g. each sg_apply_uniform + call will cost at least 256 bytes of uniform buffer size). The default size + is 4 MB, which is enough for 16384 sg_apply_uniform() calls per + frame (assuming the uniform data 'payload' is less than 256 bytes + per call). These rules are the same as for the Metal backend, so if + you are already using the Metal backend you'll be fine. + + - sg_apply_bindings(): the sokol-gfx WebGPU backend implements a bindgroup + cache to prevent excessive creation and destruction of BindGroup objects + when calling sg_apply_bindings(). The number of slots in the bindgroups + cache is defined in sg_desc.wgpu.bindgroups_cache_size when calling + sg_setup. The cache size must be a power-of-2 number, with the default being + 1024. The bindgroups cache behaviour can be observed by calling the new + function sg_query_stats(), where the following struct items are + of interest: + + .wgpu.num_bindgroup_cache_hits + .wgpu.num_bindgroup_cache_misses + .wgpu.num_bindgroup_cache_collisions + .wgpu_num_bindgroup_cache_invalidates + .wgpu.num_bindgroup_cache_vs_hash_key_mismatch + + The value to pay attention to is `.wgpu.num_bindgroup_cache_collisions`, + if this number is consistently higher than a few percent of the + .wgpu.num_set_bindgroup value, it might be a good idea to bump the + bindgroups cache size to the next power-of-2. + + - sg_apply_viewport(): WebGPU currently has a unique restriction that viewport + rectangles must be contained entirely within the framebuffer. As a shitty + workaround sokol_gfx.h will clip incoming viewport rectangles against + the framebuffer, but this will distort the clipspace-to-screenspace mapping. + There's no proper way to handle this inside sokol_gfx.h, this must be fixed + in a future WebGPU update (see: https://github.com/gpuweb/gpuweb/issues/373 + and https://github.com/gpuweb/gpuweb/pull/5025) + + - The sokol shader compiler generally adds `diagnostic(off, derivative_uniformity);` + into the WGSL output. Currently only the Chrome WebGPU implementation seems + to recognize this. + + - Likewise, the following sokol-gfx pixel formats are not supported in WebGPU: + R16, R16SN, RG16, RG16SN, RGBA16, RGBA16SN. + Unlike unsupported vertex formats, unsupported pixel formats can be queried + in cross-backend code via sg_query_pixelformat() though. + + - The Emscripten WebGPU shim currently doesn't support the Closure minification + post-link-step (e.g. currently the emcc argument '--closure 1' or '--closure 2' + will generate broken Javascript code. + + - sokol-gfx requires the WebGPU device feature `depth32float-stencil8` to be enabled + (this should be widely supported) + + - sokol-gfx expects that the WebGPU device feature `float32-filterable` to *not* be + enabled (since this would exclude all iOS devices) + + + LICENSE + ======= + zlib/libpng license + + Copyright (c) 2018 Andre Weissflog + + This software is provided 'as-is', without any express or implied warranty. + In no event will the authors be held liable for any damages arising from the + use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software in a + product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not + be misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*/ +#define SOKOL_GFX_INCLUDED (1) +#include // size_t +#include +#include + +#if defined(SOKOL_API_DECL) && !defined(SOKOL_GFX_API_DECL) +#define SOKOL_GFX_API_DECL SOKOL_API_DECL +#endif +#ifndef SOKOL_GFX_API_DECL +#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_GFX_IMPL) +#define SOKOL_GFX_API_DECL __declspec(dllexport) +#elif defined(_WIN32) && defined(SOKOL_DLL) +#define SOKOL_GFX_API_DECL __declspec(dllimport) +#else +#define SOKOL_GFX_API_DECL extern +#endif +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* + Resource id typedefs: + + sg_buffer: vertex- and index-buffers + sg_image: images used as textures and render-pass attachments + sg_sampler sampler objects describing how a texture is sampled in a shader + sg_shader: vertex- and fragment-shaders and shader interface information + sg_pipeline: associated shader and vertex-layouts, and render states + sg_view: a resource view object used for bindings and render-pass attachments + + Instead of pointers, resource creation functions return a 32-bit + handle which uniquely identifies the resource object. + + The 32-bit resource id is split into a 16-bit pool index in the lower bits, + and a 16-bit 'generation counter' in the upper bits. The index allows fast + pool lookups, and combined with the generation-counter it allows to detect + 'dangling accesses' (trying to use an object which no longer exists, and + its pool slot has been reused for a new object) + + The resource ids are wrapped into a strongly-typed struct so that + trying to pass an incompatible resource id is a compile error. +*/ +typedef struct sg_buffer { uint32_t id; } sg_buffer; +typedef struct sg_image { uint32_t id; } sg_image; +typedef struct sg_sampler { uint32_t id; } sg_sampler; +typedef struct sg_shader { uint32_t id; } sg_shader; +typedef struct sg_pipeline { uint32_t id; } sg_pipeline; +typedef struct sg_view { uint32_t id; } sg_view; + +/* + sg_range is a pointer-size-pair struct used to pass memory blobs into + sokol-gfx. When initialized from a value type (array or struct), you can + use the SG_RANGE() macro to build an sg_range struct. For functions which + take either a sg_range pointer, or a (C++) sg_range reference, use the + SG_RANGE_REF macro as a solution which compiles both in C and C++. +*/ +typedef struct sg_range { + const void* ptr; + size_t size; +} sg_range; + +// disabling this for every includer isn't great, but the warnings are also quite pointless +#if defined(_MSC_VER) +#pragma warning(disable:4221) // /W4 only: nonstandard extension used: 'x': cannot be initialized using address of automatic variable 'y' +#pragma warning(disable:4204) // VS2015: nonstandard extension used: non-constant aggregate initializer +#endif +#if defined(__cplusplus) +#define SG_RANGE(x) sg_range{ &x, sizeof(x) } +#define SG_RANGE_REF(x) sg_range{ &x, sizeof(x) } +#else +#define SG_RANGE(x) (sg_range){ &x, sizeof(x) } +#define SG_RANGE_REF(x) &(sg_range){ &x, sizeof(x) } +#endif + +// various compile-time constants in the public API +enum { + SG_INVALID_ID = 0, + SG_NUM_INFLIGHT_FRAMES = 2, + SG_MAX_COLOR_ATTACHMENTS = 8, + SG_MAX_UNIFORMBLOCK_MEMBERS = 16, + SG_MAX_VERTEX_ATTRIBUTES = 16, + SG_MAX_MIPMAPS = 16, + SG_MAX_VERTEXBUFFER_BINDSLOTS = 8, + SG_MAX_UNIFORMBLOCK_BINDSLOTS = 8, + SG_MAX_VIEW_BINDSLOTS = 32, + SG_MAX_SAMPLER_BINDSLOTS = 12, + SG_MAX_TEXTURE_SAMPLER_PAIRS = 32, // same as SG_MAX_VIEW_BINDSLOTS + SG_MAX_PORTABLE_COLOR_ATTACHMENTS = 4, + SG_MAX_PORTABLE_TEXTURE_BINDINGS_PER_STAGE = 16, + SG_MAX_PORTABLE_STORAGEBUFFER_BINDINGS_PER_STAGE = 8, // assuming sg_features.compute = true + SG_MAX_PORTABLE_STORAGEIMAGE_BINDINGS_PER_STAGE = 4, // assuming sg_features.compute = true +}; + +/* + sg_color + + An RGBA color value. +*/ +typedef struct sg_color { float r, g, b, a; } sg_color; + +/* + sg_backend + + The active 3D-API backend, use the function sg_query_backend() + to get the currently active backend. +*/ +typedef enum sg_backend { + SG_BACKEND_GLCORE, + SG_BACKEND_GLES3, + SG_BACKEND_D3D11, + SG_BACKEND_METAL_IOS, + SG_BACKEND_METAL_MACOS, + SG_BACKEND_METAL_SIMULATOR, + SG_BACKEND_WGPU, + SG_BACKEND_VULKAN, + SG_BACKEND_DUMMY, +} sg_backend; + +/* + sg_pixel_format + + sokol_gfx.h basically uses the same pixel formats as WebGPU, since these + are supported on most newer GPUs. + + A pixelformat name consist of three parts: + + - components (R, RG, RGB or RGBA) + - bit width per component (8, 16 or 32) + - component data type: + - unsigned normalized (no postfix) + - signed normalized (SN postfix) + - unsigned integer (UI postfix) + - signed integer (SI postfix) + - float (F postfix) + + Not all pixel formats can be used for everything, call sg_query_pixelformat() + to inspect the capabilities of a given pixelformat. The function returns + an sg_pixelformat_info struct with the following members: + + - sample: the pixelformat can be sampled as texture at least with + nearest filtering + - filter: the pixelformat can be sampled as texture with linear + filtering + - render: the pixelformat can be used as render-pass attachment + - blend: blending is supported when used as render-pass attachment + - msaa: multisample-antialiasing is supported when used + as render-pass attachment + - depth: the pixelformat can be used for depth-stencil attachments + - compressed: this is a block-compressed format + - bytes_per_pixel: the numbers of bytes in a pixel (0 for compressed formats) + + The default pixel format for texture images is SG_PIXELFORMAT_RGBA8. + + The default pixel format for render target images is platform-dependent + and taken from the sg_environment struct passed into sg_setup(). Typically + the default formats are: + + - for the Metal, D3D11 and WebGPU backends: SG_PIXELFORMAT_BGRA8 + - for GL backends: SG_PIXELFORMAT_RGBA8 +*/ +typedef enum sg_pixel_format { + _SG_PIXELFORMAT_DEFAULT, // value 0 reserved for default-init + SG_PIXELFORMAT_NONE, + + SG_PIXELFORMAT_R8, + SG_PIXELFORMAT_R8SN, + SG_PIXELFORMAT_R8UI, + SG_PIXELFORMAT_R8SI, + + SG_PIXELFORMAT_R16, + SG_PIXELFORMAT_R16SN, + SG_PIXELFORMAT_R16UI, + SG_PIXELFORMAT_R16SI, + SG_PIXELFORMAT_R16F, + SG_PIXELFORMAT_RG8, + SG_PIXELFORMAT_RG8SN, + SG_PIXELFORMAT_RG8UI, + SG_PIXELFORMAT_RG8SI, + + SG_PIXELFORMAT_R32UI, + SG_PIXELFORMAT_R32SI, + SG_PIXELFORMAT_R32F, + SG_PIXELFORMAT_RG16, + SG_PIXELFORMAT_RG16SN, + SG_PIXELFORMAT_RG16UI, + SG_PIXELFORMAT_RG16SI, + SG_PIXELFORMAT_RG16F, + SG_PIXELFORMAT_RGBA8, + SG_PIXELFORMAT_SRGB8A8, + SG_PIXELFORMAT_RGBA8SN, + SG_PIXELFORMAT_RGBA8UI, + SG_PIXELFORMAT_RGBA8SI, + SG_PIXELFORMAT_BGRA8, + SG_PIXELFORMAT_RGB10A2, + SG_PIXELFORMAT_RG11B10F, + SG_PIXELFORMAT_RGB9E5, + + SG_PIXELFORMAT_RG32UI, + SG_PIXELFORMAT_RG32SI, + SG_PIXELFORMAT_RG32F, + SG_PIXELFORMAT_RGBA16, + SG_PIXELFORMAT_RGBA16SN, + SG_PIXELFORMAT_RGBA16UI, + SG_PIXELFORMAT_RGBA16SI, + SG_PIXELFORMAT_RGBA16F, + + SG_PIXELFORMAT_RGBA32UI, + SG_PIXELFORMAT_RGBA32SI, + SG_PIXELFORMAT_RGBA32F, + + SG_PIXELFORMAT_DEPTH, + SG_PIXELFORMAT_DEPTH_STENCIL, + + // NOTE: don't put any new compressed format in front of here + SG_PIXELFORMAT_BC1_RGBA, + SG_PIXELFORMAT_BC2_RGBA, + SG_PIXELFORMAT_BC3_RGBA, + SG_PIXELFORMAT_BC3_SRGBA, + SG_PIXELFORMAT_BC4_R, + SG_PIXELFORMAT_BC4_RSN, + SG_PIXELFORMAT_BC5_RG, + SG_PIXELFORMAT_BC5_RGSN, + SG_PIXELFORMAT_BC6H_RGBF, + SG_PIXELFORMAT_BC6H_RGBUF, + SG_PIXELFORMAT_BC7_RGBA, + SG_PIXELFORMAT_BC7_SRGBA, + SG_PIXELFORMAT_ETC2_RGB8, + SG_PIXELFORMAT_ETC2_SRGB8, + SG_PIXELFORMAT_ETC2_RGB8A1, + SG_PIXELFORMAT_ETC2_RGBA8, + SG_PIXELFORMAT_ETC2_SRGB8A8, + SG_PIXELFORMAT_EAC_R11, + SG_PIXELFORMAT_EAC_R11SN, + SG_PIXELFORMAT_EAC_RG11, + SG_PIXELFORMAT_EAC_RG11SN, + + SG_PIXELFORMAT_ASTC_4x4_RGBA, + SG_PIXELFORMAT_ASTC_4x4_SRGBA, + + _SG_PIXELFORMAT_NUM, + _SG_PIXELFORMAT_FORCE_U32 = 0x7FFFFFFF +} sg_pixel_format; + +/* + Runtime information about a pixel format, returned by sg_query_pixelformat(). +*/ +typedef struct sg_pixelformat_info { + bool sample; // pixel format can be sampled in shaders at least with nearest filtering + bool filter; // pixel format can be sampled with linear filtering + bool render; // pixel format can be used as render-pass attachment + bool blend; // pixel format supports alpha-blending when used as render-pass attachment + bool msaa; // pixel format supports MSAA when used as render-pass attachment + bool depth; // pixel format is a depth format + bool compressed; // true if this is a hardware-compressed format + bool read; // true if format supports compute shader read access + bool write; // true if format supports compute shader write access + int bytes_per_pixel; // NOTE: this is 0 for compressed formats, use sg_query_row_pitch() / sg_query_surface_pitch() as alternative +} sg_pixelformat_info; + +/* + Runtime information about available optional features, returned by sg_query_features() +*/ +typedef struct sg_features { + bool origin_top_left; // framebuffer- and texture-origin is in top left corner + bool image_clamp_to_border; // border color and clamp-to-border uv-wrap mode is supported + bool mrt_independent_blend_state; // multiple-render-target rendering can use per-render-target blend state + bool mrt_independent_write_mask; // multiple-render-target rendering can use per-render-target color write masks + bool compute; // storage buffers and compute shaders are supported + bool msaa_texture_bindings; // if true, multisampled images can be bound as textures + bool separate_buffer_types; // cannot use the same buffer for vertex and indices (only WebGL2) + bool draw_base_vertex; // draw with (base vertex > 0) && (base_instance == 0) supported + bool draw_base_instance; // draw with (base instance > 0) supported + bool dual_source_blending; // dual-source-blending supported + bool vertexformat_int10_n2; // SG_VERTEXFORMAT_INT10_N2 is supported + bool gl_texture_views; // supports 'proper' texture views (GL 4.3+) +} sg_features; + +/* + Runtime information about resource limits, returned by sg_query_limit() +*/ +typedef struct sg_limits { + int max_image_size_2d; // max width/height of SG_IMAGETYPE_2D images + int max_image_size_cube; // max width/height of SG_IMAGETYPE_CUBE images + int max_image_size_3d; // max width/height/depth of SG_IMAGETYPE_3D images + int max_image_size_array; // max width/height of SG_IMAGETYPE_ARRAY images + int max_image_array_layers; // max number of layers in SG_IMAGETYPE_ARRAY images + int max_vertex_attrs; // max number of vertex attributes, clamped to SG_MAX_VERTEX_ATTRIBUTES + int max_color_attachments; // max number of render pass color attachments, clamped to SG_MAX_COLOR_ATTACHMENTS + int max_texture_bindings_per_stage; // max number of texture bindings per shader stage, clamped to SG_MAX_VIEW_BINDSLOTS + int max_storage_buffer_bindings_per_stage; // max number of storage buffer bindings per shader stage, clamped to SG_MAX_VIEW_BINDSLOTS + int max_storage_image_bindings_per_stage; // max number of storage image bindings per shader stage, clamped to SG_MAX_VIEW_BINDSLOTS + int gl_max_vertex_uniform_components; // GL_MAX_VERTEX_UNIFORM_COMPONENTS (only on GL backends) + int gl_max_combined_texture_image_units; // GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS (only on GL backends) + int d3d11_max_unordered_access_views; // 8 on feature level 11.0, otherwise 32 (clamped to SG_MAX_VIEW_BINDSLOTS) + int vk_min_uniform_buffer_offset_alignment; +} sg_limits; + +/* + sg_resource_state + + The current state of a resource in its resource pool. + Resources start in the INITIAL state, which means the + pool slot is unoccupied and can be allocated. When a resource is + created, first an id is allocated, and the resource pool slot + is set to state ALLOC. After allocation, the resource is + initialized, which may result in the VALID or FAILED state. The + reason why allocation and initialization are separate is because + some resource types (e.g. buffers and images) might be asynchronously + initialized by the user application. If a resource which is not + in the VALID state is attempted to be used for rendering, rendering + operations will silently be dropped. + + The special INVALID state is returned in sg_query_xxx_state() if no + resource object exists for the provided resource id. +*/ +typedef enum sg_resource_state { + SG_RESOURCESTATE_INITIAL, + SG_RESOURCESTATE_ALLOC, + SG_RESOURCESTATE_VALID, + SG_RESOURCESTATE_FAILED, + SG_RESOURCESTATE_INVALID, + _SG_RESOURCESTATE_FORCE_U32 = 0x7FFFFFFF +} sg_resource_state; + +/* + sg_index_type + + Indicates whether indexed rendering (fetching vertex-indices from an + index buffer) is used, and if yes, the index data type (16- or 32-bits). + + This is used in the sg_pipeline_desc.index_type member when creating a + pipeline object. + + The default index type is SG_INDEXTYPE_NONE. +*/ +typedef enum sg_index_type { + _SG_INDEXTYPE_DEFAULT, // value 0 reserved for default-init + SG_INDEXTYPE_NONE, + SG_INDEXTYPE_UINT16, + SG_INDEXTYPE_UINT32, + _SG_INDEXTYPE_NUM, + _SG_INDEXTYPE_FORCE_U32 = 0x7FFFFFFF +} sg_index_type; + +/* + sg_image_type + + Indicates the basic type of an image object (2D-texture, cubemap, + 3D-texture or 2D-array-texture). Used in the sg_image_desc.type member when + creating an image, and in sg_shader_image_desc to describe a sampled texture + in the shader (both must match and will be checked in the validation layer + when calling sg_apply_bindings). + + The default image type when creating an image is SG_IMAGETYPE_2D. +*/ +typedef enum sg_image_type { + _SG_IMAGETYPE_DEFAULT, // value 0 reserved for default-init + SG_IMAGETYPE_2D, + SG_IMAGETYPE_CUBE, + SG_IMAGETYPE_3D, + SG_IMAGETYPE_ARRAY, + _SG_IMAGETYPE_NUM, + _SG_IMAGETYPE_FORCE_U32 = 0x7FFFFFFF +} sg_image_type; + +/* + sg_image_sample_type + + The basic data type of a texture sample as expected by a shader. + Must be provided in sg_shader_image and used by the validation + layer in sg_apply_bindings() to check if the provided image object + is compatible with what the shader expects. Apart from the sokol-gfx + validation layer, WebGPU is the only backend API which actually requires + matching texture and sampler type to be provided upfront for validation + (other 3D APIs treat texture/sampler type mismatches as undefined behaviour). + + NOTE that the following texture pixel formats require the use + of SG_IMAGESAMPLETYPE_UNFILTERABLE_FLOAT, combined with a sampler + of type SG_SAMPLERTYPE_NONFILTERING: + + - SG_PIXELFORMAT_R32F + - SG_PIXELFORMAT_RG32F + - SG_PIXELFORMAT_RGBA32F + + (when using sokol-shdc, also check out the meta tags `@image_sample_type` + and `@sampler_type`) +*/ +typedef enum sg_image_sample_type { + _SG_IMAGESAMPLETYPE_DEFAULT, // value 0 reserved for default-init + SG_IMAGESAMPLETYPE_FLOAT, + SG_IMAGESAMPLETYPE_DEPTH, + SG_IMAGESAMPLETYPE_SINT, + SG_IMAGESAMPLETYPE_UINT, + SG_IMAGESAMPLETYPE_UNFILTERABLE_FLOAT, + _SG_IMAGESAMPLETYPE_NUM, + _SG_IMAGESAMPLETYPE_FORCE_U32 = 0x7FFFFFFF +} sg_image_sample_type; + +/* + sg_sampler_type + + The basic type of a texture sampler (sampling vs comparison) as + defined in a shader. Must be provided in sg_shader_sampler_desc. + + sg_image_sample_type and sg_sampler_type for a texture/sampler + pair must be compatible with each other, specifically only + the following pairs are allowed: + + - SG_IMAGESAMPLETYPE_FLOAT => (SG_SAMPLERTYPE_FILTERING or SG_SAMPLERTYPE_NONFILTERING) + - SG_IMAGESAMPLETYPE_UNFILTERABLE_FLOAT => SG_SAMPLERTYPE_NONFILTERING + - SG_IMAGESAMPLETYPE_SINT => SG_SAMPLERTYPE_NONFILTERING + - SG_IMAGESAMPLETYPE_UINT => SG_SAMPLERTYPE_NONFILTERING + - SG_IMAGESAMPLETYPE_DEPTH => SG_SAMPLERTYPE_COMPARISON +*/ +typedef enum sg_sampler_type { + _SG_SAMPLERTYPE_DEFAULT, + SG_SAMPLERTYPE_FILTERING, + SG_SAMPLERTYPE_NONFILTERING, + SG_SAMPLERTYPE_COMPARISON, + _SG_SAMPLERTYPE_NUM, + _SG_SAMPLERTYPE_FORCE_U32, +} sg_sampler_type; + +/* + sg_primitive_type + + This is the common subset of 3D primitive types supported across all 3D + APIs. This is used in the sg_pipeline_desc.primitive_type member when + creating a pipeline object. + + The default primitive type is SG_PRIMITIVETYPE_TRIANGLES. +*/ +typedef enum sg_primitive_type { + _SG_PRIMITIVETYPE_DEFAULT, // value 0 reserved for default-init + SG_PRIMITIVETYPE_POINTS, + SG_PRIMITIVETYPE_LINES, + SG_PRIMITIVETYPE_LINE_STRIP, + SG_PRIMITIVETYPE_TRIANGLES, + SG_PRIMITIVETYPE_TRIANGLE_STRIP, + _SG_PRIMITIVETYPE_NUM, + _SG_PRIMITIVETYPE_FORCE_U32 = 0x7FFFFFFF +} sg_primitive_type; + +/* + sg_filter + + The filtering mode when sampling a texture image. This is + used in the sg_sampler_desc.min_filter, sg_sampler_desc.mag_filter + and sg_sampler_desc.mipmap_filter members when creating a sampler object. + + For the default is SG_FILTER_NEAREST. +*/ +typedef enum sg_filter { + _SG_FILTER_DEFAULT, // value 0 reserved for default-init + SG_FILTER_NEAREST, + SG_FILTER_LINEAR, + _SG_FILTER_NUM, + _SG_FILTER_FORCE_U32 = 0x7FFFFFFF +} sg_filter; + +/* + sg_wrap + + The texture coordinates wrapping mode when sampling a texture + image. This is used in the sg_image_desc.wrap_u, .wrap_v + and .wrap_w members when creating an image. + + The default wrap mode is SG_WRAP_REPEAT. + + NOTE: SG_WRAP_CLAMP_TO_BORDER is not supported on all backends + and platforms. To check for support, call sg_query_features() + and check the "clamp_to_border" boolean in the returned + sg_features struct. + + Platforms which don't support SG_WRAP_CLAMP_TO_BORDER will silently fall back + to SG_WRAP_CLAMP_TO_EDGE without a validation error. +*/ +typedef enum sg_wrap { + _SG_WRAP_DEFAULT, // value 0 reserved for default-init + SG_WRAP_REPEAT, + SG_WRAP_CLAMP_TO_EDGE, + SG_WRAP_CLAMP_TO_BORDER, + SG_WRAP_MIRRORED_REPEAT, + _SG_WRAP_NUM, + _SG_WRAP_FORCE_U32 = 0x7FFFFFFF +} sg_wrap; + +/* + sg_border_color + + The border color to use when sampling a texture, and the UV wrap + mode is SG_WRAP_CLAMP_TO_BORDER. + + The default border color is SG_BORDERCOLOR_OPAQUE_BLACK +*/ +typedef enum sg_border_color { + _SG_BORDERCOLOR_DEFAULT, // value 0 reserved for default-init + SG_BORDERCOLOR_TRANSPARENT_BLACK, + SG_BORDERCOLOR_OPAQUE_BLACK, + SG_BORDERCOLOR_OPAQUE_WHITE, + _SG_BORDERCOLOR_NUM, + _SG_BORDERCOLOR_FORCE_U32 = 0x7FFFFFFF +} sg_border_color; + +/* + sg_vertex_format + + The data type of a vertex component. This is used to describe + the layout of input vertex data when creating a pipeline object. + + NOTE that specific mapping rules exist from the CPU-side vertex + formats to the vertex attribute base type in the vertex shader code + (see doc header section 'ON VERTEX FORMATS'). +*/ +typedef enum sg_vertex_format { + SG_VERTEXFORMAT_INVALID, + SG_VERTEXFORMAT_FLOAT, + SG_VERTEXFORMAT_FLOAT2, + SG_VERTEXFORMAT_FLOAT3, + SG_VERTEXFORMAT_FLOAT4, + SG_VERTEXFORMAT_INT, + SG_VERTEXFORMAT_INT2, + SG_VERTEXFORMAT_INT3, + SG_VERTEXFORMAT_INT4, + SG_VERTEXFORMAT_UINT, + SG_VERTEXFORMAT_UINT2, + SG_VERTEXFORMAT_UINT3, + SG_VERTEXFORMAT_UINT4, + SG_VERTEXFORMAT_BYTE4, + SG_VERTEXFORMAT_BYTE4N, + SG_VERTEXFORMAT_UBYTE4, + SG_VERTEXFORMAT_UBYTE4N, + SG_VERTEXFORMAT_SHORT2, + SG_VERTEXFORMAT_SHORT2N, + SG_VERTEXFORMAT_USHORT2, + SG_VERTEXFORMAT_USHORT2N, + SG_VERTEXFORMAT_SHORT4, + SG_VERTEXFORMAT_SHORT4N, + SG_VERTEXFORMAT_USHORT4, + SG_VERTEXFORMAT_USHORT4N, + SG_VERTEXFORMAT_INT10_N2, + SG_VERTEXFORMAT_UINT10_N2, + SG_VERTEXFORMAT_HALF2, + SG_VERTEXFORMAT_HALF4, + _SG_VERTEXFORMAT_NUM, + _SG_VERTEXFORMAT_FORCE_U32 = 0x7FFFFFFF +} sg_vertex_format; + +/* + sg_vertex_step + + Defines whether the input pointer of a vertex input stream is advanced + 'per vertex' or 'per instance'. The default step-func is + SG_VERTEXSTEP_PER_VERTEX. SG_VERTEXSTEP_PER_INSTANCE is used with + instanced-rendering. + + The vertex-step is part of the vertex-layout definition + when creating pipeline objects. +*/ +typedef enum sg_vertex_step { + _SG_VERTEXSTEP_DEFAULT, // value 0 reserved for default-init + SG_VERTEXSTEP_PER_VERTEX, + SG_VERTEXSTEP_PER_INSTANCE, + _SG_VERTEXSTEP_NUM, + _SG_VERTEXSTEP_FORCE_U32 = 0x7FFFFFFF +} sg_vertex_step; + +/* + sg_uniform_type + + The data type of a uniform block member. This is used to + describe the internal layout of uniform blocks when creating + a shader object. This is only required for the GL backend, all + other backends will ignore the interior layout of uniform blocks. +*/ +typedef enum sg_uniform_type { + SG_UNIFORMTYPE_INVALID, + SG_UNIFORMTYPE_FLOAT, + SG_UNIFORMTYPE_FLOAT2, + SG_UNIFORMTYPE_FLOAT3, + SG_UNIFORMTYPE_FLOAT4, + SG_UNIFORMTYPE_INT, + SG_UNIFORMTYPE_INT2, + SG_UNIFORMTYPE_INT3, + SG_UNIFORMTYPE_INT4, + SG_UNIFORMTYPE_MAT4, + _SG_UNIFORMTYPE_NUM, + _SG_UNIFORMTYPE_FORCE_U32 = 0x7FFFFFFF +} sg_uniform_type; + +/* + sg_uniform_layout + + A hint for the interior memory layout of uniform blocks. This is + only relevant for the GL backend where the internal layout + of uniform blocks must be known to sokol-gfx. For all other backends the + internal memory layout of uniform blocks doesn't matter, sokol-gfx + will just pass uniform data as an opaque memory blob to the + 3D backend. + + SG_UNIFORMLAYOUT_NATIVE (default) + Native layout means that a 'backend-native' memory layout + is used. For the GL backend this means that uniforms + are packed tightly in memory (e.g. there are no padding + bytes). + + SG_UNIFORMLAYOUT_STD140 + The memory layout is a subset of std140. Arrays are only + allowed for the FLOAT4, INT4 and MAT4. Alignment is as + is as follows: + + FLOAT, INT: 4 byte alignment + FLOAT2, INT2: 8 byte alignment + FLOAT3, INT3: 16 byte alignment(!) + FLOAT4, INT4: 16 byte alignment + MAT4: 16 byte alignment + FLOAT4[], INT4[]: 16 byte alignment + + The overall size of the uniform block must be a multiple + of 16. + + For more information search for 'UNIFORM DATA LAYOUT' in the documentation block + at the start of the header. +*/ +typedef enum sg_uniform_layout { + _SG_UNIFORMLAYOUT_DEFAULT, // value 0 reserved for default-init + SG_UNIFORMLAYOUT_NATIVE, // default: layout depends on currently active backend + SG_UNIFORMLAYOUT_STD140, // std140: memory layout according to std140 + _SG_UNIFORMLAYOUT_NUM, + _SG_UNIFORMLAYOUT_FORCE_U32 = 0x7FFFFFFF +} sg_uniform_layout; + +/* + sg_cull_mode + + The face-culling mode, this is used in the + sg_pipeline_desc.cull_mode member when creating a + pipeline object. + + The default cull mode is SG_CULLMODE_NONE +*/ +typedef enum sg_cull_mode { + _SG_CULLMODE_DEFAULT, // value 0 reserved for default-init + SG_CULLMODE_NONE, + SG_CULLMODE_FRONT, + SG_CULLMODE_BACK, + _SG_CULLMODE_NUM, + _SG_CULLMODE_FORCE_U32 = 0x7FFFFFFF +} sg_cull_mode; + +/* + sg_face_winding + + The vertex-winding rule that determines a front-facing primitive. This + is used in the member sg_pipeline_desc.face_winding + when creating a pipeline object. + + The default winding is SG_FACEWINDING_CW (clockwise) +*/ +typedef enum sg_face_winding { + _SG_FACEWINDING_DEFAULT, // value 0 reserved for default-init + SG_FACEWINDING_CCW, + SG_FACEWINDING_CW, + _SG_FACEWINDING_NUM, + _SG_FACEWINDING_FORCE_U32 = 0x7FFFFFFF +} sg_face_winding; + +/* + sg_compare_func + + The compare-function for configuring depth- and stencil-ref tests + in pipeline objects, and for texture samplers which perform a comparison + instead of regular sampling operation. + + Used in the following structs: + + sg_pipeline_desc + .depth + .compare + .stencil + .front.compare + .back.compare + + sg_sampler_desc + .compare + + The default compare func for depth- and stencil-tests is + SG_COMPAREFUNC_ALWAYS. + + The default compare func for samplers is SG_COMPAREFUNC_NEVER. +*/ +typedef enum sg_compare_func { + _SG_COMPAREFUNC_DEFAULT, // value 0 reserved for default-init + SG_COMPAREFUNC_NEVER, + SG_COMPAREFUNC_LESS, + SG_COMPAREFUNC_EQUAL, + SG_COMPAREFUNC_LESS_EQUAL, + SG_COMPAREFUNC_GREATER, + SG_COMPAREFUNC_NOT_EQUAL, + SG_COMPAREFUNC_GREATER_EQUAL, + SG_COMPAREFUNC_ALWAYS, + _SG_COMPAREFUNC_NUM, + _SG_COMPAREFUNC_FORCE_U32 = 0x7FFFFFFF +} sg_compare_func; + +/* + sg_stencil_op + + The operation performed on a currently stored stencil-value when a + comparison test passes or fails. This is used when creating a pipeline + object in the following sg_pipeline_desc struct items: + + sg_pipeline_desc + .stencil + .front + .fail_op + .depth_fail_op + .pass_op + .back + .fail_op + .depth_fail_op + .pass_op + + The default value is SG_STENCILOP_KEEP. +*/ +typedef enum sg_stencil_op { + _SG_STENCILOP_DEFAULT, // value 0 reserved for default-init + SG_STENCILOP_KEEP, + SG_STENCILOP_ZERO, + SG_STENCILOP_REPLACE, + SG_STENCILOP_INCR_CLAMP, + SG_STENCILOP_DECR_CLAMP, + SG_STENCILOP_INVERT, + SG_STENCILOP_INCR_WRAP, + SG_STENCILOP_DECR_WRAP, + _SG_STENCILOP_NUM, + _SG_STENCILOP_FORCE_U32 = 0x7FFFFFFF +} sg_stencil_op; + +/* + sg_blend_factor + + The source and destination factors in blending operations. + This is used in the following members when creating a pipeline object: + + sg_pipeline_desc + .colors[i] + .blend + .src_factor_rgb + .dst_factor_rgb + .src_factor_alpha + .dst_factor_alpha + + The default value is SG_BLENDFACTOR_ONE for source + factors, and for the destination SG_BLENDFACTOR_ZERO if the associated + blend-op is ADD, SUBTRACT or REVERSE_SUBTRACT or SG_BLENDFACTOR_ONE + if the associated blend-op is MIN or MAX. +*/ +typedef enum sg_blend_factor { + _SG_BLENDFACTOR_DEFAULT, // value 0 reserved for default-init + SG_BLENDFACTOR_ZERO, + SG_BLENDFACTOR_ONE, + SG_BLENDFACTOR_SRC_COLOR, + SG_BLENDFACTOR_ONE_MINUS_SRC_COLOR, + SG_BLENDFACTOR_SRC_ALPHA, + SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, + SG_BLENDFACTOR_DST_COLOR, + SG_BLENDFACTOR_ONE_MINUS_DST_COLOR, + SG_BLENDFACTOR_DST_ALPHA, + SG_BLENDFACTOR_ONE_MINUS_DST_ALPHA, + SG_BLENDFACTOR_SRC_ALPHA_SATURATED, + SG_BLENDFACTOR_BLEND_COLOR, + SG_BLENDFACTOR_ONE_MINUS_BLEND_COLOR, + SG_BLENDFACTOR_BLEND_ALPHA, + SG_BLENDFACTOR_ONE_MINUS_BLEND_ALPHA, + SG_BLENDFACTOR_SRC1_COLOR, + SG_BLENDFACTOR_ONE_MINUS_SRC1_COLOR, + SG_BLENDFACTOR_SRC1_ALPHA, + SG_BLENDFACTOR_ONE_MINUS_SRC1_ALPHA, + _SG_BLENDFACTOR_NUM, + _SG_BLENDFACTOR_FORCE_U32 = 0x7FFFFFFF +} sg_blend_factor; + +/* + sg_blend_op + + Describes how the source and destination values are combined in the + fragment blending operation. It is used in the following struct items + when creating a pipeline object: + + sg_pipeline_desc + .colors[i] + .blend + .op_rgb + .op_alpha + + The default value is SG_BLENDOP_ADD. +*/ +typedef enum sg_blend_op { + _SG_BLENDOP_DEFAULT, // value 0 reserved for default-init + SG_BLENDOP_ADD, + SG_BLENDOP_SUBTRACT, + SG_BLENDOP_REVERSE_SUBTRACT, + SG_BLENDOP_MIN, + SG_BLENDOP_MAX, + _SG_BLENDOP_NUM, + _SG_BLENDOP_FORCE_U32 = 0x7FFFFFFF +} sg_blend_op; + +/* + sg_color_mask + + Selects the active color channels when writing a fragment color to the + framebuffer. This is used in the members + sg_pipeline_desc.colors[i].write_mask when creating a pipeline object. + + The default colormask is SG_COLORMASK_RGBA (write all colors channels) + + NOTE: since the color mask value 0 is reserved for the default value + (SG_COLORMASK_RGBA), use SG_COLORMASK_NONE if all color channels + should be disabled. +*/ +typedef enum sg_color_mask { + _SG_COLORMASK_DEFAULT = 0, // value 0 reserved for default-init + SG_COLORMASK_NONE = 0x10, // special value for 'all channels disabled + SG_COLORMASK_R = 0x1, + SG_COLORMASK_G = 0x2, + SG_COLORMASK_RG = 0x3, + SG_COLORMASK_B = 0x4, + SG_COLORMASK_RB = 0x5, + SG_COLORMASK_GB = 0x6, + SG_COLORMASK_RGB = 0x7, + SG_COLORMASK_A = 0x8, + SG_COLORMASK_RA = 0x9, + SG_COLORMASK_GA = 0xA, + SG_COLORMASK_RGA = 0xB, + SG_COLORMASK_BA = 0xC, + SG_COLORMASK_RBA = 0xD, + SG_COLORMASK_GBA = 0xE, + SG_COLORMASK_RGBA = 0xF, + _SG_COLORMASK_FORCE_U32 = 0x7FFFFFFF +} sg_color_mask; + +/* + sg_load_action + + Defines the load action that should be performed at the start of a render pass: + + SG_LOADACTION_CLEAR: clear the render target + SG_LOADACTION_LOAD: load the previous content of the render target + SG_LOADACTION_DONTCARE: leave the render target in an undefined state + + This is used in the sg_pass_action structure. + + The default load action for all pass attachments is SG_LOADACTION_CLEAR, + with the values rgba = { 0.5f, 0.5f, 0.5f, 1.0f }, depth=1.0f and stencil=0. + + If you want to override the default behaviour, it is important to not + only set the clear color, but the 'action' field as well (as long as this + is _SG_LOADACTION_DEFAULT, the value fields will be ignored). +*/ +typedef enum sg_load_action { + _SG_LOADACTION_DEFAULT, + SG_LOADACTION_CLEAR, + SG_LOADACTION_LOAD, + SG_LOADACTION_DONTCARE, + _SG_LOADACTION_FORCE_U32 = 0x7FFFFFFF +} sg_load_action; + +/* + sg_store_action + + Defines the store action that should be performed at the end of a render pass: + + SG_STOREACTION_STORE: store the rendered content to the color attachment image + SG_STOREACTION_DONTCARE: allows the GPU to discard the rendered content +*/ +typedef enum sg_store_action { + _SG_STOREACTION_DEFAULT, + SG_STOREACTION_STORE, + SG_STOREACTION_DONTCARE, + _SG_STOREACTION_FORCE_U32 = 0x7FFFFFFF +} sg_store_action; + + +/* + sg_pass_action + + The sg_pass_action struct defines the actions to be performed + at the start and end of a render pass. + + - at the start of the pass: whether the render attachments should be cleared, + loaded with their previous content, or start in an undefined state + - for clear operations: the clear value (color, depth, or stencil values) + - at the end of the pass: whether the rendering result should be + stored back into the render attachment or discarded +*/ +typedef struct sg_color_attachment_action { + sg_load_action load_action; // default: SG_LOADACTION_CLEAR + sg_store_action store_action; // default: SG_STOREACTION_STORE + sg_color clear_value; // default: { 0.5f, 0.5f, 0.5f, 1.0f } +} sg_color_attachment_action; + +typedef struct sg_depth_attachment_action { + sg_load_action load_action; // default: SG_LOADACTION_CLEAR + sg_store_action store_action; // default: SG_STOREACTION_DONTCARE + float clear_value; // default: 1.0 +} sg_depth_attachment_action; + +typedef struct sg_stencil_attachment_action { + sg_load_action load_action; // default: SG_LOADACTION_CLEAR + sg_store_action store_action; // default: SG_STOREACTION_DONTCARE + uint8_t clear_value; // default: 0 +} sg_stencil_attachment_action; + +typedef struct sg_pass_action { + sg_color_attachment_action colors[SG_MAX_COLOR_ATTACHMENTS]; + sg_depth_attachment_action depth; + sg_stencil_attachment_action stencil; +} sg_pass_action; + +/* + sg_swapchain + + Used in sg_begin_pass() to provide details about an external swapchain + (pixel formats, sample count and backend-API specific render surface objects). + + The following information must be provided: + + - the width and height of the swapchain surfaces in number of pixels, + - the pixel format of the render- and optional msaa-resolve-surface + - the pixel format of the optional depth- or depth-stencil-surface + - the MSAA sample count for the render and depth-stencil surface + + If the pixel formats and MSAA sample counts are left zero-initialized, + their defaults are taken from the sg_environment struct provided in the + sg_setup() call. + + The width and height *must* be > 0. + + The boolean `sg_swapchain.invalid` is used to communicate an invalid + swapchain state to sokol-gfx (for instance the swapchain code outside of + sokol-gfx not being able to create swapchain surfaces). When the .invalid + boolean is set to true, all other sg_swapchain struct items must be zeroed + (checked in the validation layer), and all rendering in this swapchain-pass + will be silently skipped. + + For valid swapchains, the following backend API specific objects must be passed in + as 'type erased' void pointers: + + GL: + - on all GL backends, a GL framebuffer object must be provided. This + can be zero for the default framebuffer. + + D3D11: + - an ID3D11RenderTargetView for the rendering surface, without + MSAA rendering this surface will also be displayed + - an optional ID3D11DepthStencilView for the depth- or depth/stencil + buffer surface + - when MSAA rendering is used, another ID3D11RenderTargetView + which serves as MSAA resolve target and will be displayed + + WebGPU (same as D3D11, except different types) + - a WGPUTextureView for the rendering surface, without + MSAA rendering this surface will also be displayed + - an optional WGPUTextureView for the depth- or depth/stencil + buffer surface + - when MSAA rendering is used, another WGPUTextureView + which serves as MSAA resolve target and will be displayed + + Metal (NOTE that the roles of provided surfaces is slightly different + than on D3D11 or WebGPU in case of MSAA vs non-MSAA rendering): + + - A current CAMetalDrawable (NOT an MTLDrawable!) which will be presented. + This will either be rendered to directly (if no MSAA is used), or serve + as MSAA-resolve target. + - an optional MTLTexture for the depth- or depth-stencil buffer + - an optional multisampled MTLTexture which serves as intermediate + rendering surface which will then be resolved into the + CAMetalDrawable. + + NOTE that for Metal you must use an ObjC __bridge cast to + properly tunnel the ObjC object id through a C void*, e.g.: + + swapchain.metal.current_drawable = (__bridge const void*) [mtkView currentDrawable]; + + On all other backends you shouldn't need to mess with the reference count. + + It's a good practice to write a helper function which returns an initialized + sg_swapchain struct, which can then be plugged directly into + sg_pass.swapchain. Look at the function sglue_swapchain() in the sokol_glue.h + as an example. +*/ +typedef struct sg_metal_swapchain { + const void* current_drawable; // CAMetalDrawable (NOT MTLDrawable!!!) + const void* depth_stencil_texture; // MTLTexture + const void* msaa_color_texture; // MTLTexture +} sg_metal_swapchain; + +typedef struct sg_d3d11_swapchain { + const void* render_view; // ID3D11RenderTargetView + const void* resolve_view; // ID3D11RenderTargetView + const void* depth_stencil_view; // ID3D11DepthStencilView +} sg_d3d11_swapchain; + +typedef struct sg_wgpu_swapchain { + const void* render_view; // WGPUTextureView + const void* resolve_view; // WGPUTextureView + const void* depth_stencil_view; // WGPUTextureView +} sg_wgpu_swapchain; + +typedef struct sg_vulkan_swapchain { + const void* render_image; // vkImage + const void* render_view; // vkImageView + const void* resolve_image; // vkImage + const void* resolve_view; // vkImageView + const void* depth_stencil_image; // vkImage + const void* depth_stencil_view; // vkImageView + const void* render_finished_semaphore; // vkSemaphore + const void* present_complete_semaphore; // vkSemaphore +} sg_vulkan_swapchain; + +typedef struct sg_gl_swapchain { + uint32_t framebuffer; // GL framebuffer object +} sg_gl_swapchain; + +typedef struct sg_swapchain { + bool invalid; + int width; + int height; + int sample_count; + sg_pixel_format color_format; + sg_pixel_format depth_format; + sg_metal_swapchain metal; + sg_d3d11_swapchain d3d11; + sg_wgpu_swapchain wgpu; + sg_vulkan_swapchain vulkan; + sg_gl_swapchain gl; +} sg_swapchain; + +/* + sg_attachments + + Used in sg_pass to provide render pass attachment views. Each + type of pass attachment has it corresponding view type: + + sg_attachments.colors[]: + populate with color-attachment views, e.g.: + + sg_make_view(&(sg_view_desc){ + .color_attachment = { ... }, + }); + + sg_attachments.resolves[]: + populate with resolve-attachment views, e.g.: + + sg_make_view(&(sg_view_desc){ + .resolve_attachment = { ... }, + }); + + sg_attachments.depth_stencil: + populate with depth-stencil-attachment views, e.g.: + + sg_make_view(&(sg_view_desc){ + .depth_stencil_attachment = { ... }, + }); +*/ +typedef struct sg_attachments { + sg_view colors[SG_MAX_COLOR_ATTACHMENTS]; + sg_view resolves[SG_MAX_COLOR_ATTACHMENTS]; + sg_view depth_stencil; +} sg_attachments; + +/* + sg_pass + + The sg_pass structure is passed as argument into the sg_begin_pass() + function. + + For a swapchain render pass, provide an sg_pass_action and sg_swapchain + struct (for instance via the sglue_swapchain() helper function from + sokol_glue.h): + + sg_begin_pass(&(sg_pass){ + .action = { ... }, + .swapchain = sglue_swapchain(), + }); + + For an offscreen render pass, provide an sg_pass_action struct with + attachment view objects: + + sg_begin_pass(&(sg_pass){ + .action = { ... }, + .attachments = { + .colors = { ... }, + .resolves = { ... }, + .depth_stencil = ..., + }, + }); + + You can also omit the .action object to get default pass action behaviour + (clear to color=grey, depth=1 and stencil=0). + + For a compute pass, just set the sg_pass.compute boolean to true: + + sg_begin_pass(&(sg_pass){ .compute = true }); +*/ +typedef struct sg_pass { + uint32_t _start_canary; + bool compute; + sg_pass_action action; + sg_attachments attachments; + sg_swapchain swapchain; + const char* label; + uint32_t _end_canary; +} sg_pass; + +/* + sg_bindings + + The sg_bindings structure defines the resource bindings for + the next draw call. + + To update the resource bindings, call sg_apply_bindings() with + a pointer to a populated sg_bindings struct. Note that + sg_apply_bindings() must be called after sg_apply_pipeline() + and that bindings are not preserved across sg_apply_pipeline() + calls, even when the new pipeline uses the same 'bindings layout'. + + A resource binding struct contains: + + - 1..N vertex buffers + - 1..N vertex buffer offsets + - 0..1 index buffer + - 0..1 index buffer offset + - 0..N resource views (texture-, storage-image, storage-buffer-views) + - 0..N samplers + + Where 'N' is defined in the following constants: + + - SG_MAX_VERTEXBUFFER_BINDSLOTS + - SG_MAX_VIEW_BINDSLOTS + - SG_MAX_SAMPLER_BINDSLOTS + + Note that inside compute passes vertex- and index-buffer-bindings are + disallowed. + + When using sokol-shdc for shader authoring, the `layout(binding=N)` + for texture-, storage-image- and storage-buffer-bindings directly + maps to the views-array index, for instance the following vertex- + and fragment-shader interface for sokol-shdc: + + @vs vs + layout(binding=0) uniform vs_params { ... }; + layout(binding=0) readonly buffer ssbo { ... }; + layout(binding=1) uniform texture2D vs_tex; + layout(binding=0) uniform sampler vs_smp; + ... + @end + + @fs fs + layout(binding=1) uniform fs_params { ... }; + layout(binding=2) uniform texture2D fs_tex; + layout(binding=1) uniform sampler fs_smp; + ... + @end + + ...would map to the following sg_bindings struct: + + const sg_bindings bnd = { + .vertex_buffers[0] = ..., + .views[0] = ssbo_view, + .views[1] = vs_tex_view, + .views[2] = fs_tex_view, + .samplers[0] = vs_smp, + .samplers[1] = fs_smp, + }; + + ...alternatively you can use code-generated slot indices: + + const sg_bindings bnd = { + .vertex_buffers[0] = ..., + .views[VIEW_ssbo] = ssbo_view, + .views[VIEW_vs_tex] = vs_tex_view, + .views[VIEW_fs_tex] = fs_tex_view, + .samplers[SMP_vs_smp] = vs_smp, + .samplers[SMP_fs_smp] = fs_smp, + }; + + Resource bindslots for a specific shader/pipeline may have gaps, and an + sg_bindings struct may have populated bind slots which are not used by a + specific shader. This allows to use the same sg_bindings struct across + different shader variants. + + When not using sokol-shdc, the bindslot indices in the sg_bindings + struct need to match the per-binding reflection info slot indices + in the sg_shader_desc struct (for details about that see the + sg_shader_desc struct documentation). + + The optional buffer offsets can be used to put different unrelated + chunks of vertex- and/or index-data into the same buffer objects. +*/ +typedef struct sg_bindings { + uint32_t _start_canary; + sg_buffer vertex_buffers[SG_MAX_VERTEXBUFFER_BINDSLOTS]; + int vertex_buffer_offsets[SG_MAX_VERTEXBUFFER_BINDSLOTS]; + sg_buffer index_buffer; + int index_buffer_offset; + sg_view views[SG_MAX_VIEW_BINDSLOTS]; + sg_sampler samplers[SG_MAX_SAMPLER_BINDSLOTS]; + uint32_t _end_canary; +} sg_bindings; + +/* + sg_buffer_usage + + Describes how a buffer object is going to be used: + + .vertex_buffer (default: true) + the buffer will be bound as vertex buffer via sg_bindings.vertex_buffers[] + .index_buffer (default: false) + the buffer will be bound as index buffer via sg_bindings.index_buffer + .storage_buffer (default: false) + the buffer will be bound as storage buffer via storage-buffer-view + in sg_bindings.views[] + .immutable (default: true) + the buffer content will never be updated from the CPU side (but + may be written to by a compute shader) + .dynamic_update (default: false) + the buffer content will be infrequently updated from the CPU side + .stream_upate (default: false) + the buffer content will be updated each frame from the CPU side +*/ +typedef struct sg_buffer_usage { + bool vertex_buffer; + bool index_buffer; + bool storage_buffer; + bool immutable; + bool dynamic_update; + bool stream_update; +} sg_buffer_usage; + +/* + sg_buffer_desc + + Creation parameters for sg_buffer objects, used in the sg_make_buffer() call. + + The default configuration is: + + .size: 0 (*must* be >0 for buffers without data) + .usage { .vertex_buffer = true, .immutable = true } + .data.ptr 0 (*must* be valid for immutable buffers without storage buffer usage) + .data.size 0 (*must* be > 0 for immutable buffers without storage buffer usage) + .label 0 (optional string label) + + For immutable buffers which are initialized with initial data, + keep the .size item zero-initialized, and set the size together with the + pointer to the initial data in the .data item. + + For immutable or mutable buffers without initial data, keep the .data item + zero-initialized, and set the buffer size in the .size item instead. + + You can also set both size values, but currently both size values must + be identical (this may change in the future when the dynamic resource + management may become more flexible). + + NOTE: Immutable buffers without storage-buffer-usage *must* be created + with initial content, this restriction doesn't apply to storage buffer usage, + because storage buffers may also get their initial content by running + a compute shader on them. + + NOTE: Buffers without initial data will have undefined content, e.g. + do *not* expect the buffer to be zero-initialized! + + ADVANCED TOPIC: Injecting native 3D-API buffers: + + The following struct members allow to inject your own GL, Metal + or D3D11 buffers into sokol_gfx: + + .gl_buffers[SG_NUM_INFLIGHT_FRAMES] + .mtl_buffers[SG_NUM_INFLIGHT_FRAMES] + .d3d11_buffer + + You must still provide all other struct items except the .data item, and + these must match the creation parameters of the native buffers you provide. + For sg_buffer_desc.usage.immutable buffers, only provide a single native + 3D-API buffer, otherwise you need to provide SG_NUM_INFLIGHT_FRAMES buffers + (only for GL and Metal, not D3D11). Providing multiple buffers for GL and + Metal is necessary because sokol_gfx will rotate through them when calling + sg_update_buffer() to prevent lock-stalls. + + Note that it is expected that immutable injected buffer have already been + initialized with content, and the .content member must be 0! + + Also you need to call sg_reset_state_cache() after calling native 3D-API + functions, and before calling any sokol_gfx function. +*/ +typedef struct sg_buffer_desc { + uint32_t _start_canary; + size_t size; + sg_buffer_usage usage; + sg_range data; + const char* label; + // optionally inject backend-specific resources + uint32_t gl_buffers[SG_NUM_INFLIGHT_FRAMES]; + const void* mtl_buffers[SG_NUM_INFLIGHT_FRAMES]; + const void* d3d11_buffer; + const void* wgpu_buffer; + uint32_t _end_canary; +} sg_buffer_desc; + +/* + sg_image_usage + + Describes the intended usage of an image object: + + .storage_image (default: false) + the image can be used as parent resource of a storage-image-view, + which allows compute shaders to write to the image in a compute + pass (for read-only access in compute shaders bind the image + via a texture view instead + .color_attachment (default: false) + the image can be used as parent resource of a color-attachment-view, + which is then passed into sg_begin_pass via sg_pass.attachments.colors[] + so that fragment shaders can render into the image + .resolve_attachment (default: false) + the image can be used as parent resource of a resolve-attachment-view, + which is then passed into sg_begin_pass via sg_pass.attachments.resolves[] + as target for an MSAA-resolve operation in sg_end_pass() + .depth_stencil_attachment (default: false) + the image can be used as parent resource of a depth-stencil-attachmnet-view + which is then passes into sg_begin_pass via sg_pass.attachments.depth_stencil + as depth-stencil-buffer + .immutable (default: true) + the image content cannot be updated from the CPU side + (but may be updated by the GPU in a render- or compute-pass) + .dynamic_update (default: false) + the image content is updated infrequently by the CPU + .stream_update (default: false) + the image content is updated each frame by the CPU via + + Note that creating a texture view from the image to be used for + texture-sampling in vertex-, fragment- or compute-shaders + is always implicitly allowed. +*/ +typedef struct sg_image_usage { + bool storage_image; + bool color_attachment; + bool resolve_attachment; + bool depth_stencil_attachment; + bool immutable; + bool dynamic_update; + bool stream_update; +} sg_image_usage; + +/* + sg_view_type + + Allows to query the type of a view object via the function sg_query_view_type() +*/ +typedef enum sg_view_type { + SG_VIEWTYPE_INVALID, + SG_VIEWTYPE_STORAGEBUFFER, + SG_VIEWTYPE_STORAGEIMAGE, + SG_VIEWTYPE_TEXTURE, + SG_VIEWTYPE_COLORATTACHMENT, + SG_VIEWTYPE_RESOLVEATTACHMENT, + SG_VIEWTYPE_DEPTHSTENCILATTACHMENT, + _SG_VIEWTYPE_FORCE_U32 = 0x7FFFFFFF +} sg_view_type; + +/* + sg_image_data + + Defines the content of an image through an array of sg_range structs, each + range pointing to the pixel data for one mip-level. For array-, cubemap- and + 3D-images each mip-level contains all slice-surfaces for that mip-level in a + single tightly packed memory block. + + The size of a single surface in a mip-level for a regular 2D texture + can be computed via: + + sg_query_surface_pitch(pixel_format, mip_width, mip_height, 1); + + For array- and 3d-images the size of a single miplevel is: + + num_slices * sg_query_surface_pitch(pixel_format, mip_width, mip_height, 1); + + For cubemap-images the size of a single mip-level is: + + 6 * sg_query_surface_pitch(pixel_format, mip_width, mip_height, 1); + + The order of cubemap-faces is in a mip-level data chunk is: + + [0] => +X + [1] => -X + [2] => +Y + [3] => -Y + [4] => +Z + [5] => -Z +*/ +typedef struct sg_image_data { + sg_range mip_levels[SG_MAX_MIPMAPS]; +} sg_image_data; + +/* + sg_image_desc + + Creation parameters for sg_image objects, used in the sg_make_image() call. + + The default configuration is: + + .type SG_IMAGETYPE_2D + .usage .immutable = true + .width 0 (must be set to >0) + .height 0 (must be set to >0) + .num_slices 1 (3D textures: depth; array textures: number of layers) + .num_mipmaps 1 + .pixel_format SG_PIXELFORMAT_RGBA8 for textures, or sg_desc.environment.defaults.color_format for render targets + .sample_count 1 for textures, or sg_desc.environment.defaults.sample_count for render targets + .data an sg_image_data struct to define the initial content + .label 0 (optional string label for trace hooks) + + Q: Why is the default sample_count for render targets identical with the + "default sample count" from sg_desc.environment.defaults.sample_count? + + A: So that it matches the default sample count in pipeline objects. Even + though it is a bit strange/confusing that offscreen render targets by default + get the same sample count as 'default swapchains', but it's better that + an offscreen render target created with default parameters matches + a pipeline object created with default parameters. + + NOTE: + + Regular images used as texture binding with usage.immutable must be fully + initialized by providing a valid .data member which points to initialization + data. + + Images with usage.*_attachment or usage.storage_image must + *not* be created with initial content. Be aware that the initial + content of pass attachment and storage images is undefined + (not guaranteed to be zeroed). + + ADVANCED TOPIC: Injecting native 3D-API textures: + + The following struct members allow to inject your own GL, Metal or D3D11 + textures into sokol_gfx: + + .gl_textures[SG_NUM_INFLIGHT_FRAMES] + .mtl_textures[SG_NUM_INFLIGHT_FRAMES] + .d3d11_texture + .wgpu_texture + + For GL, you can also specify the texture target or leave it empty to use + the default texture target for the image type (GL_TEXTURE_2D for + SG_IMAGETYPE_2D etc) + + The same rules apply as for injecting native buffers (see sg_buffer_desc + documentation for more details). +*/ +typedef struct sg_image_desc { + uint32_t _start_canary; + sg_image_type type; + sg_image_usage usage; + int width; + int height; + int num_slices; + int num_mipmaps; + sg_pixel_format pixel_format; + int sample_count; + sg_image_data data; + const char* label; + // optionally inject backend-specific resources + uint32_t gl_textures[SG_NUM_INFLIGHT_FRAMES]; + uint32_t gl_texture_target; + const void* mtl_textures[SG_NUM_INFLIGHT_FRAMES]; + const void* d3d11_texture; + const void* wgpu_texture; + uint32_t _end_canary; +} sg_image_desc; + +/* + sg_sampler_desc + + Creation parameters for sg_sampler objects, used in the sg_make_sampler() call + + .min_filter: SG_FILTER_NEAREST + .mag_filter: SG_FILTER_NEAREST + .mipmap_filter SG_FILTER_NEAREST + .wrap_u: SG_WRAP_REPEAT + .wrap_v: SG_WRAP_REPEAT + .wrap_w: SG_WRAP_REPEAT (only SG_IMAGETYPE_3D) + .min_lod 0.0f + .max_lod FLT_MAX + .border_color SG_BORDERCOLOR_OPAQUE_BLACK + .compare SG_COMPAREFUNC_NEVER + .max_anisotropy 1 (must be 1..16) +*/ +typedef struct sg_sampler_desc { + uint32_t _start_canary; + sg_filter min_filter; + sg_filter mag_filter; + sg_filter mipmap_filter; + sg_wrap wrap_u; + sg_wrap wrap_v; + sg_wrap wrap_w; + float min_lod; + float max_lod; + sg_border_color border_color; + sg_compare_func compare; + uint32_t max_anisotropy; + const char* label; + // optionally inject backend-specific resources + uint32_t gl_sampler; + const void* mtl_sampler; + const void* d3d11_sampler; + const void* wgpu_sampler; + uint32_t _end_canary; +} sg_sampler_desc; + +/* + sg_shader_desc + + Used as parameter of sg_make_shader() to create a shader object which + communicates shader source or bytecode and shader interface + reflection information to sokol-gfx. + + If you use sokol-shdc you can ignore the following information since + the sg_shader_desc struct will be code-generated. + + Otherwise you need to provide the following information to the + sg_make_shader() call: + + - a vertex- and fragment-shader function: + - the shader source or bytecode + - an optional entry point name + - for D3D11: an optional compile target when source code is provided + (the defaults are "vs_4_0" and "ps_4_0") + + - ...or alternatively, a compute function: + - the shader source or bytecode + - an optional entry point name + - for D3D11: an optional compile target when source code is provided + (the default is "cs_5_0") + + - vertex attributes required by some backends (not for compute shaders): + - the vertex attribute base type (undefined, float, signed int, unsigned int), + this information is only used in the validation layer to check that the + pipeline object vertex formats are compatible with the input vertex attribute + type used in the vertex shader. NOTE that the default base type + 'undefined' skips the validation layer check. + - for the GL backend: optional vertex attribute names used for name lookup + - for the D3D11 backend: semantic names and indices + + - only for compute shaders on the Metal backend: + - the workgroup size aka 'threads per thread-group' + + In other 3D APIs this is declared in the shader code: + - GLSL: `layout(local_size_x=x, local_size_y=y, local_size_y=z) in;` + - HLSL: `[numthreads(x, y, z)]` + - WGSL: `@workgroup_size(x, y, z)` + ...but in Metal the workgroup size is declared on the CPU side + + - reflection information for each uniform block binding used by the shader: + - the shader stage the uniform block appears in (SG_SHADERSTAGE_*) + - the size in bytes of the uniform block + - backend-specific bindslots: + - HLSL: the constant buffer register `register(b0..7)` + - MSL: the buffer attribute `[[buffer(0..7)]]` + - WGSL: the binding in `@group(0) @binding(0..15)` + - GLSL only: a description of the uniform block interior + - the memory layout standard (SG_UNIFORMLAYOUT_*) + - for each member in the uniform block: + - the member type (SG_UNIFORM_*) + - if the member is an array, the array count + - the member name + + - reflection information for each texture-, storage-buffer and + storage-image bindings by the shader, each with an associated + view type: + - texture bindings => texture views + - storage-buffer bindings => storage-buffer views + - storage-image bindings => storage-image views + + - texture bindings must provide the following information: + - the shader stage the texture binding appears in (SG_SHADERSTAGE_*) + - the image type (SG_IMAGETYPE_*) + - the image-sample type (SG_IMAGESAMPLETYPE_*) + - whether the texture is multisampled + - backend specific bindslots: + - HLSL: the texture register `register(t0..31)` + - MSL: the texture attribute `[[texture(0..31)]]` + - WGSL: the binding in `@group(1) @binding(0..127)` + + - storage-buffer bindings must provide the following information: + - the shader stage the storage buffer appears in (SG_SHADERSTAGE_*) + - whether the storage buffer is readonly + - backend specific bindslots: + - HLSL: + - for storage buffer bindings: `register(t0..31)` + - for read/write storage buffer bindings: `register(u0..31)` + - MSL: the buffer attribute `[[buffer(8..23)]]` + - WGSL: the binding in `@group(1) @binding(0..127)` + - GL: the binding in `layout(binding=0..sg_limits.max_storage_buffer_bindings_per_stage)` + + - storage-image bindings must provide the following information: + - the shader stage (*must* be SG_SHADERSTAGE_COMPUTE) + - whether the storage image is writeonly or readwrite (for readonly + access use a regular texture binding instead) + - the image type expected by the shader (SG_IMAGETYPE_*) + - the access pixel format expected by the shader (SG_PIXELFORMAT_*), + note that only a subset of pixel formats is allowed for storage image + bindings + - backend specific bindslots: + - HLSL: the UAV register `register(u0..31)` + - MSL: the texture attribute `[[texture(0..31)]]` + - WGSL: the binding in `@group(1) @binding(0..127)` + - GLSL: the binding in `layout(binding=0..sg_imits.max_storage_buffer_bindings_per_stage, [access_format])` + + - reflection information for each sampler used by the shader: + - the shader stage the sampler appears in (SG_SHADERSTAGE_*) + - the sampler type (SG_SAMPLERTYPE_*) + - backend specific bindslots: + - HLSL: the sampler register `register(s0..11)` + - MSL: the sampler attribute `[[sampler(0..11)]]` + - WGSL: the binding in `@group(0) @binding(0..127)` + + - reflection information for each texture-sampler pair used by + the shader: + - the shader stage (SG_SHADERSTAGE_*) + - the texture's array index in the sg_shader_desc.views[] array + - the sampler's array index in the sg_shader_desc.samplers[] array + - GLSL only: the name of the combined image-sampler object + + The number and order of items in the sg_shader_desc.attrs[] + array corresponds to the items in sg_pipeline_desc.layout.attrs. + + - sg_shader_desc.attrs[N] => sg_pipeline_desc.layout.attrs[N] + + NOTE that vertex attribute indices currently cannot have gaps. + + The items index in the sg_shader_desc.uniform_blocks[] array corresponds + to the ub_slot arg in sg_apply_uniforms(): + + - sg_shader_desc.uniform_blocks[N] => sg_apply_uniforms(N, ...) + + The items in the sg_shader_desc.views[] array directly map to + the views in the sg_bindings.views[] array! + + For all GL backends, shader source-code must be provided. For D3D11 and Metal, + either shader source-code or byte-code can be provided. + + NOTE that the uniform-block, view and sampler arrays may have gaps. This + allows to use the same sg_bindings struct for different but related + shader variations. + + For D3D11, if source code is provided, the d3dcompiler_47.dll will be loaded + on demand. If this fails, shader creation will fail. When compiling HLSL + source code, you can provide an optional target string via + sg_shader_stage_desc.d3d11_target, the default target is "vs_4_0" for the + vertex shader stage and "ps_4_0" for the pixel shader stage. + You may optionally provide the file path to enable the default #include handler + behavior when compiling source code. +*/ +typedef enum sg_shader_stage { + SG_SHADERSTAGE_NONE, + SG_SHADERSTAGE_VERTEX, + SG_SHADERSTAGE_FRAGMENT, + SG_SHADERSTAGE_COMPUTE, + _SG_SHADERSTAGE_FORCE_U32 = 0x7FFFFFFF, +} sg_shader_stage; + +typedef struct sg_shader_function { + const char* source; + sg_range bytecode; + const char* entry; + const char* d3d11_target; // default: "vs_4_0" or "ps_4_0" + const char* d3d11_filepath; +} sg_shader_function; + +typedef enum sg_shader_attr_base_type { + SG_SHADERATTRBASETYPE_UNDEFINED, + SG_SHADERATTRBASETYPE_FLOAT, + SG_SHADERATTRBASETYPE_SINT, + SG_SHADERATTRBASETYPE_UINT, + _SG_SHADERATTRBASETYPE_FORCE_U32 = 0x7FFFFFFF, +} sg_shader_attr_base_type; + +typedef struct sg_shader_vertex_attr { + sg_shader_attr_base_type base_type; // default: UNDEFINED (disables validation) + const char* glsl_name; // [optional] GLSL attribute name + const char* hlsl_sem_name; // HLSL semantic name + uint8_t hlsl_sem_index; // HLSL semantic index +} sg_shader_vertex_attr; + +typedef struct sg_glsl_shader_uniform { + sg_uniform_type type; + uint16_t array_count; // 0 or 1 for scalars, >1 for arrays + const char* glsl_name; // glsl name binding is required on GL 4.1 and WebGL2 +} sg_glsl_shader_uniform; + +typedef struct sg_shader_uniform_block { + sg_shader_stage stage; + uint32_t size; + uint8_t hlsl_register_b_n; // HLSL register(bn) + uint8_t msl_buffer_n; // MSL [[buffer(n)]] + uint8_t wgsl_group0_binding_n; // WGSL @group(0) @binding(n) + uint8_t spirv_set0_binding_n; // Vulkan GLSL layout(set=0, binding=n) + sg_uniform_layout layout; + sg_glsl_shader_uniform glsl_uniforms[SG_MAX_UNIFORMBLOCK_MEMBERS]; +} sg_shader_uniform_block; + +typedef struct sg_shader_texture_view { + sg_shader_stage stage; + sg_image_type image_type; + sg_image_sample_type sample_type; + bool multisampled; + uint8_t hlsl_register_t_n; // HLSL register(tn) bind slot + uint8_t msl_texture_n; // MSL [[texture(n)]] bind slot + uint8_t wgsl_group1_binding_n; // WGSL @group(1) @binding(n) bind slot + uint8_t spirv_set1_binding_n; // Vulkan GLSL layout(set=1, binding=0) +} sg_shader_texture_view; + +typedef struct sg_shader_storage_buffer_view { + sg_shader_stage stage; + bool readonly; + uint8_t hlsl_register_t_n; // HLSL register(tn) bind slot (for readonly access) + uint8_t hlsl_register_u_n; // HLSL register(un) bind slot (for read/write access) + uint8_t msl_buffer_n; // MSL [[buffer(n)]] bind slot + uint8_t wgsl_group1_binding_n; // WGSL @group(1) @binding(n) bind slot + uint8_t spirv_set1_binding_n; // Vulkan GLSL layout(set=1, binding=0) + uint8_t glsl_binding_n; // GLSL layout(binding=n) +} sg_shader_storage_buffer_view; + +typedef struct sg_shader_storage_image_view { + sg_shader_stage stage; + sg_image_type image_type; + sg_pixel_format access_format; // shader-access pixel format + bool writeonly; // false means read/write access + uint8_t hlsl_register_u_n; // HLSL register(un) bind slot + uint8_t msl_texture_n; // MSL [[texture(n)]] bind slot + uint8_t wgsl_group1_binding_n; // WGSL @group(2) @binding(n) bind slot + uint8_t spirv_set1_binding_n; // Vulkan GLSL layout(set=1, binding=0) + uint8_t glsl_binding_n; // GLSL layout(binding=n) +} sg_shader_storage_image_view; + +typedef struct sg_shader_view { + sg_shader_texture_view texture; + sg_shader_storage_buffer_view storage_buffer; + sg_shader_storage_image_view storage_image; +} sg_shader_view; + +typedef struct sg_shader_sampler { + sg_shader_stage stage; + sg_sampler_type sampler_type; + uint8_t hlsl_register_s_n; // HLSL register(sn) bind slot + uint8_t msl_sampler_n; // MSL [[sampler(n)]] bind slot + uint8_t wgsl_group1_binding_n; // WGSL @group(1) @binding(n) bind slot + uint8_t spirv_set1_binding_n; // Vulkan GLSL layout(set=1, binding=0) +} sg_shader_sampler; + +typedef struct sg_shader_texture_sampler_pair { + sg_shader_stage stage; + uint8_t view_slot; // must be SG_VIEWTYPE_TEXTURE + uint8_t sampler_slot; + const char* glsl_name; // glsl name binding required because of GL 4.1 and WebGL2 +} sg_shader_texture_sampler_pair; + +typedef struct sg_mtl_shader_threads_per_threadgroup { + int x, y, z; +} sg_mtl_shader_threads_per_threadgroup; + +typedef struct sg_shader_desc { + uint32_t _start_canary; + sg_shader_function vertex_func; + sg_shader_function fragment_func; + sg_shader_function compute_func; + sg_shader_vertex_attr attrs[SG_MAX_VERTEX_ATTRIBUTES]; + sg_shader_uniform_block uniform_blocks[SG_MAX_UNIFORMBLOCK_BINDSLOTS]; + sg_shader_view views[SG_MAX_VIEW_BINDSLOTS]; + sg_shader_sampler samplers[SG_MAX_SAMPLER_BINDSLOTS]; + sg_shader_texture_sampler_pair texture_sampler_pairs[SG_MAX_TEXTURE_SAMPLER_PAIRS]; + sg_mtl_shader_threads_per_threadgroup mtl_threads_per_threadgroup; + const char* label; + uint32_t _end_canary; +} sg_shader_desc; + +/* + sg_pipeline_desc + + The sg_pipeline_desc struct defines all creation parameters for an + sg_pipeline object, used as argument to the sg_make_pipeline() function: + + Pipeline objects come in two flavours: + + - render pipelines for use in render passes + - compute pipelines for use in compute passes + + A compute pipeline only requires a compute shader object but no + 'render state', while a render pipeline requires a vertex/fragment shader + object and additional render state declarations: + + - the vertex layout for all input vertex buffers + - a shader object + - the 3D primitive type (points, lines, triangles, ...) + - the index type (none, 16- or 32-bit) + - all the fixed-function-pipeline state (depth-, stencil-, blend-state, etc...) + + If the vertex data has no gaps between vertex components, you can omit + the .layout.buffers[].stride and layout.attrs[].offset items (leave them + default-initialized to 0), sokol-gfx will then compute the offsets and + strides from the vertex component formats (.layout.attrs[].format). + Please note that ALL vertex attribute offsets must be 0 in order for the + automatic offset computation to kick in. + + Note that if you use vertex-pulling from storage buffers instead of + fixed-function vertex input you can simply omit the entire nested .layout + struct. + + The default configuration is as follows: + + .compute: false (must be set to true for a compute pipeline) + .shader: 0 (must be initialized with a valid sg_shader id!) + .layout: + .buffers[]: vertex buffer layouts + .stride: 0 (if no stride is given it will be computed) + .step_func SG_VERTEXSTEP_PER_VERTEX + .step_rate 1 + .attrs[]: vertex attribute declarations + .buffer_index 0 the vertex buffer bind slot + .offset 0 (offsets can be omitted if the vertex layout has no gaps) + .format SG_VERTEXFORMAT_INVALID (must be initialized!) + .depth: + .pixel_format: sg_desc.context.depth_format + .compare: SG_COMPAREFUNC_ALWAYS + .write_enabled: false + .bias: 0.0f + .bias_slope_scale: 0.0f + .bias_clamp: 0.0f + .stencil: + .enabled: false + .front/back: + .compare: SG_COMPAREFUNC_ALWAYS + .fail_op: SG_STENCILOP_KEEP + .depth_fail_op: SG_STENCILOP_KEEP + .pass_op: SG_STENCILOP_KEEP + .read_mask: 0 + .write_mask: 0 + .ref: 0 + .color_count 1 + .colors[0..color_count] + .pixel_format sg_desc.context.color_format + .write_mask: SG_COLORMASK_RGBA + .blend: + .enabled: false + .src_factor_rgb: SG_BLENDFACTOR_ONE + .dst_factor_rgb: SG_BLENDFACTOR_ZERO + .op_rgb: SG_BLENDOP_ADD + .src_factor_alpha: SG_BLENDFACTOR_ONE + .dst_factor_alpha: SG_BLENDFACTOR_ZERO + .op_alpha: SG_BLENDOP_ADD + .primitive_type: SG_PRIMITIVETYPE_TRIANGLES + .index_type: SG_INDEXTYPE_NONE + .cull_mode: SG_CULLMODE_NONE + .face_winding: SG_FACEWINDING_CW + .sample_count: sg_desc.context.sample_count + .blend_color: (sg_color) { 0.0f, 0.0f, 0.0f, 0.0f } + .alpha_to_coverage_enabled: false + .label 0 (optional string label for trace hooks) +*/ +typedef struct sg_vertex_buffer_layout_state { + int stride; + sg_vertex_step step_func; + int step_rate; +} sg_vertex_buffer_layout_state; + +typedef struct sg_vertex_attr_state { + int buffer_index; + int offset; + sg_vertex_format format; +} sg_vertex_attr_state; + +typedef struct sg_vertex_layout_state { + sg_vertex_buffer_layout_state buffers[SG_MAX_VERTEXBUFFER_BINDSLOTS]; + sg_vertex_attr_state attrs[SG_MAX_VERTEX_ATTRIBUTES]; +} sg_vertex_layout_state; + +typedef struct sg_stencil_face_state { + sg_compare_func compare; + sg_stencil_op fail_op; + sg_stencil_op depth_fail_op; + sg_stencil_op pass_op; +} sg_stencil_face_state; + +typedef struct sg_stencil_state { + bool enabled; + sg_stencil_face_state front; + sg_stencil_face_state back; + uint8_t read_mask; + uint8_t write_mask; + uint8_t ref; +} sg_stencil_state; + +typedef struct sg_depth_state { + sg_pixel_format pixel_format; + sg_compare_func compare; + bool write_enabled; + float bias; + float bias_slope_scale; + float bias_clamp; +} sg_depth_state; + +typedef struct sg_blend_state { + bool enabled; + sg_blend_factor src_factor_rgb; + sg_blend_factor dst_factor_rgb; + sg_blend_op op_rgb; + sg_blend_factor src_factor_alpha; + sg_blend_factor dst_factor_alpha; + sg_blend_op op_alpha; +} sg_blend_state; + +typedef struct sg_color_target_state { + sg_pixel_format pixel_format; + sg_color_mask write_mask; + sg_blend_state blend; +} sg_color_target_state; + +typedef struct sg_pipeline_desc { + uint32_t _start_canary; + bool compute; + sg_shader shader; + sg_vertex_layout_state layout; + sg_depth_state depth; + sg_stencil_state stencil; + int color_count; + sg_color_target_state colors[SG_MAX_COLOR_ATTACHMENTS]; + sg_primitive_type primitive_type; + sg_index_type index_type; + sg_cull_mode cull_mode; + sg_face_winding face_winding; + int sample_count; + sg_color blend_color; + bool alpha_to_coverage_enabled; + const char* label; + uint32_t _end_canary; +} sg_pipeline_desc; + +/* + sg_view_desc + + Creation params for sg_view objects, passed into sg_make_view() calls. + + View objects are passed into sg_apply_bindings() (for texture-, storage-buffer- + and storage-image views), and sg_begin_pass() (for color-, resolve- + and depth-stencil-attachment views). + + The view type is determined by initializing one of the sub-structs of + sg_view_desc: + + .texture a texture-view object will be created + .image the sg_image parent resource + .mip_levels optional mip-level range, keep zero-initialized for the + entire mipmap chain + .base the first mip level + .count number of mip levels, keeping this zero-initialized means + 'all remaining mip levels' + .slices optional slice range, keep zero-initialized to include + all slices + .base the first slice + .count number of slices, keeping this zero-initializied means 'all remaining slices' + + .storage_buffer a storage-buffer-view object will be created + .buffer the sg_buffer parent resource, must have been created + with `sg_buffer_desc.usage.storage_buffer = true` + .offset optional 256-byte aligned byte-offset into the buffer + + .storage_image a storage-image-view object will be created + .image the sg_image parent resource, must have been created + with `sg_image_desc.usage.storage_image = true` + .mip_level selects the mip-level for the compute shader to write + .slice selects the slice for the compute shader to write + + .color_attachment a color-attachment-view object will be created + .image the sg_image parent resource, must have been created + with `sg_image_desc.usage.color_attachment = true` + .mip_level selects the mip-level to render into + .slice selects the slice to render into + + .resolve_attachment a resolve-attachment-view object will be created + .image the sg_image parent resource, must have been created + with `sg_image_desc.usage.resolve_attachment = true` + .mip_level selects the mip-level to msaa-resolve into + .slice selects the slice to msaa-resolve into + + .depth_stencil_attachment a depth-stencil-attachment-view object will be created + .image the sg_image parent resource, must have been created + with `sg_image_desc.usage.depth_stencil_attachment = true` + .mip_level selects the mip-level to render into + .slice selects the slice to render into +*/ +typedef struct sg_buffer_view_desc { + sg_buffer buffer; + int offset; +} sg_buffer_view_desc; + +typedef struct sg_image_view_desc { + sg_image image; + int mip_level; + int slice; // cube texture: face; array texture: layer; 3D texture: depth-slice +} sg_image_view_desc; + +typedef struct sg_texture_view_range { + int base; + int count; +} sg_texture_view_range; + +typedef struct sg_texture_view_desc { + sg_image image; + sg_texture_view_range mip_levels; + sg_texture_view_range slices; // cube texture: face; array texture: layer; 3D texture: depth-slice +} sg_texture_view_desc; + +typedef struct sg_view_desc { + uint32_t _start_canary; + sg_texture_view_desc texture; + sg_buffer_view_desc storage_buffer; + sg_image_view_desc storage_image; + sg_image_view_desc color_attachment; + sg_image_view_desc resolve_attachment; + sg_image_view_desc depth_stencil_attachment; + const char* label; + uint32_t _end_canary; +} sg_view_desc; + +/* + sg_trace_hooks + + Installable callback functions to keep track of the sokol-gfx calls, + this is useful for debugging, or keeping track of resource creation + and destruction. + + Trace hooks are installed with sg_install_trace_hooks(), this returns + another sg_trace_hooks struct with the previous set of + trace hook function pointers. These should be invoked by the + new trace hooks to form a proper call chain. +*/ +typedef struct sg_trace_hooks { + void* user_data; + void (*reset_state_cache)(void* user_data); + void (*make_buffer)(const sg_buffer_desc* desc, sg_buffer result, void* user_data); + void (*make_image)(const sg_image_desc* desc, sg_image result, void* user_data); + void (*make_sampler)(const sg_sampler_desc* desc, sg_sampler result, void* user_data); + void (*make_shader)(const sg_shader_desc* desc, sg_shader result, void* user_data); + void (*make_pipeline)(const sg_pipeline_desc* desc, sg_pipeline result, void* user_data); + void (*make_view)(const sg_view_desc* desc, sg_view result, void* user_data); + void (*destroy_buffer)(sg_buffer buf, void* user_data); + void (*destroy_image)(sg_image img, void* user_data); + void (*destroy_sampler)(sg_sampler smp, void* user_data); + void (*destroy_shader)(sg_shader shd, void* user_data); + void (*destroy_pipeline)(sg_pipeline pip, void* user_data); + void (*destroy_view)(sg_view view, void* user_data); + void (*update_buffer)(sg_buffer buf, const sg_range* data, void* user_data); + void (*update_image)(sg_image img, const sg_image_data* data, void* user_data); + void (*append_buffer)(sg_buffer buf, const sg_range* data, int result, void* user_data); + void (*begin_pass)(const sg_pass* pass, void* user_data); + void (*apply_viewport)(int x, int y, int width, int height, bool origin_top_left, void* user_data); + void (*apply_scissor_rect)(int x, int y, int width, int height, bool origin_top_left, void* user_data); + void (*apply_pipeline)(sg_pipeline pip, void* user_data); + void (*apply_bindings)(const sg_bindings* bindings, void* user_data); + void (*apply_uniforms)(int ub_index, const sg_range* data, void* user_data); + void (*draw)(int base_element, int num_elements, int num_instances, void* user_data); + void (*draw_ex)(int base_element, int num_elements, int num_instances, int base_vertex, int base_instance, void* user_data); + void (*dispatch)(int num_groups_x, int num_groups_y, int num_groups_z, void* user_data); + void (*end_pass)(void* user_data); + void (*commit)(void* user_data); + void (*alloc_buffer)(sg_buffer result, void* user_data); + void (*alloc_image)(sg_image result, void* user_data); + void (*alloc_sampler)(sg_sampler result, void* user_data); + void (*alloc_shader)(sg_shader result, void* user_data); + void (*alloc_pipeline)(sg_pipeline result, void* user_data); + void (*alloc_view)(sg_view result, void* user_data); + void (*dealloc_buffer)(sg_buffer buf_id, void* user_data); + void (*dealloc_image)(sg_image img_id, void* user_data); + void (*dealloc_sampler)(sg_sampler smp_id, void* user_data); + void (*dealloc_shader)(sg_shader shd_id, void* user_data); + void (*dealloc_pipeline)(sg_pipeline pip_id, void* user_data); + void (*dealloc_view)(sg_view view_id, void* user_data); + void (*init_buffer)(sg_buffer buf_id, const sg_buffer_desc* desc, void* user_data); + void (*init_image)(sg_image img_id, const sg_image_desc* desc, void* user_data); + void (*init_sampler)(sg_sampler smp_id, const sg_sampler_desc* desc, void* user_data); + void (*init_shader)(sg_shader shd_id, const sg_shader_desc* desc, void* user_data); + void (*init_pipeline)(sg_pipeline pip_id, const sg_pipeline_desc* desc, void* user_data); + void (*init_view)(sg_view view_id, const sg_view_desc* desc, void* user_data); + void (*uninit_buffer)(sg_buffer buf_id, void* user_data); + void (*uninit_image)(sg_image img_id, void* user_data); + void (*uninit_sampler)(sg_sampler smp_id, void* user_data); + void (*uninit_shader)(sg_shader shd_id, void* user_data); + void (*uninit_pipeline)(sg_pipeline pip_id, void* user_data); + void (*uninit_view)(sg_view view_id, void* user_data); + void (*fail_buffer)(sg_buffer buf_id, void* user_data); + void (*fail_image)(sg_image img_id, void* user_data); + void (*fail_sampler)(sg_sampler smp_id, void* user_data); + void (*fail_shader)(sg_shader shd_id, void* user_data); + void (*fail_pipeline)(sg_pipeline pip_id, void* user_data); + void (*fail_view)(sg_view view_id, void* user_data); + void (*push_debug_group)(const char* name, void* user_data); + void (*pop_debug_group)(void* user_data); +} sg_trace_hooks; + +/* + sg_buffer_info + sg_image_info + sg_sampler_info + sg_shader_info + sg_pipeline_info + sg_view_info + + These structs contain various internal resource attributes which + might be useful for debug-inspection. Please don't rely on the + actual content of those structs too much, as they are quite closely + tied to sokol_gfx.h internals and may change more frequently than + the other public API elements. + + The *_info structs are used as the return values of the following functions: + + sg_query_buffer_info() + sg_query_image_info() + sg_query_sampler_info() + sg_query_shader_info() + sg_query_pipeline_info() + sg_query_view_info() +*/ +typedef struct sg_slot_info { + sg_resource_state state; // the current state of this resource slot + uint32_t res_id; // type-neutral resource if (e.g. sg_buffer.id) + uint32_t uninit_count; +} sg_slot_info; + +typedef struct sg_buffer_info { + sg_slot_info slot; // resource pool slot info + uint32_t update_frame_index; // frame index of last sg_update_buffer() + uint32_t append_frame_index; // frame index of last sg_append_buffer() + int append_pos; // current position in buffer for sg_append_buffer() + bool append_overflow; // is buffer in overflow state (due to sg_append_buffer) + int num_slots; // number of renaming-slots for dynamically updated buffers + int active_slot; // currently active write-slot for dynamically updated buffers +} sg_buffer_info; + +typedef struct sg_image_info { + sg_slot_info slot; // resource pool slot info + uint32_t upd_frame_index; // frame index of last sg_update_image() + int num_slots; // number of renaming-slots for dynamically updated images + int active_slot; // currently active write-slot for dynamically updated images +} sg_image_info; + +typedef struct sg_sampler_info { + sg_slot_info slot; // resource pool slot info +} sg_sampler_info; + +typedef struct sg_shader_info { + sg_slot_info slot; // resource pool slot info +} sg_shader_info; + +typedef struct sg_pipeline_info { + sg_slot_info slot; // resource pool slot info +} sg_pipeline_info; + +typedef struct sg_view_info { + sg_slot_info slot; // resource pool slot info +} sg_view_info; + +/* + sg_stats + + Allows to track generic and backend-specific rendering stats, + obtained via sg_query_stats(). +*/ +typedef struct sg_frame_stats_gl { + uint32_t num_bind_buffer; + uint32_t num_active_texture; + uint32_t num_bind_texture; + uint32_t num_bind_sampler; + uint32_t num_bind_image_texture; + uint32_t num_use_program; + uint32_t num_render_state; + uint32_t num_vertex_attrib_pointer; + uint32_t num_vertex_attrib_divisor; + uint32_t num_enable_vertex_attrib_array; + uint32_t num_disable_vertex_attrib_array; + uint32_t num_uniform; + uint32_t num_memory_barriers; +} sg_frame_stats_gl; + +typedef struct sg_frame_stats_d3d11_pass { + uint32_t num_om_set_render_targets; + uint32_t num_clear_render_target_view; + uint32_t num_clear_depth_stencil_view; + uint32_t num_resolve_subresource; +} sg_frame_stats_d3d11_pass; + +typedef struct sg_frame_stats_d3d11_pipeline { + uint32_t num_rs_set_state; + uint32_t num_om_set_depth_stencil_state; + uint32_t num_om_set_blend_state; + uint32_t num_ia_set_primitive_topology; + uint32_t num_ia_set_input_layout; + uint32_t num_vs_set_shader; + uint32_t num_vs_set_constant_buffers; + uint32_t num_ps_set_shader; + uint32_t num_ps_set_constant_buffers; + uint32_t num_cs_set_shader; + uint32_t num_cs_set_constant_buffers; +} sg_frame_stats_d3d11_pipeline; + +typedef struct sg_frame_stats_d3d11_bindings { + uint32_t num_ia_set_vertex_buffers; + uint32_t num_ia_set_index_buffer; + uint32_t num_vs_set_shader_resources; + uint32_t num_vs_set_samplers; + uint32_t num_ps_set_shader_resources; + uint32_t num_ps_set_samplers; + uint32_t num_cs_set_shader_resources; + uint32_t num_cs_set_samplers; + uint32_t num_cs_set_unordered_access_views; +} sg_frame_stats_d3d11_bindings; + +typedef struct sg_frame_stats_d3d11_uniforms { + uint32_t num_update_subresource; +} sg_frame_stats_d3d11_uniforms; + +typedef struct sg_frame_stats_d3d11_draw { + uint32_t num_draw_indexed_instanced; + uint32_t num_draw_indexed; + uint32_t num_draw_instanced; + uint32_t num_draw; +} sg_frame_stats_d3d11_draw; + +typedef struct sg_frame_stats_d3d11 { + sg_frame_stats_d3d11_pass pass; + sg_frame_stats_d3d11_pipeline pipeline; + sg_frame_stats_d3d11_bindings bindings; + sg_frame_stats_d3d11_uniforms uniforms; + sg_frame_stats_d3d11_draw draw; + uint32_t num_map; + uint32_t num_unmap; +} sg_frame_stats_d3d11; + +typedef struct sg_frame_stats_metal_idpool { + uint32_t num_added; + uint32_t num_released; + uint32_t num_garbage_collected; +} sg_frame_stats_metal_idpool; + +typedef struct sg_frame_stats_metal_pipeline { + uint32_t num_set_blend_color; + uint32_t num_set_cull_mode; + uint32_t num_set_front_facing_winding; + uint32_t num_set_stencil_reference_value; + uint32_t num_set_depth_bias; + uint32_t num_set_render_pipeline_state; + uint32_t num_set_depth_stencil_state; +} sg_frame_stats_metal_pipeline; + +typedef struct sg_frame_stats_metal_bindings { + uint32_t num_set_vertex_buffer; + uint32_t num_set_vertex_buffer_offset; + uint32_t num_skip_redundant_vertex_buffer; + uint32_t num_set_vertex_texture; + uint32_t num_skip_redundant_vertex_texture; + uint32_t num_set_vertex_sampler_state; + uint32_t num_skip_redundant_vertex_sampler_state; + uint32_t num_set_fragment_buffer; + uint32_t num_set_fragment_buffer_offset; + uint32_t num_skip_redundant_fragment_buffer; + uint32_t num_set_fragment_texture; + uint32_t num_skip_redundant_fragment_texture; + uint32_t num_set_fragment_sampler_state; + uint32_t num_skip_redundant_fragment_sampler_state; + uint32_t num_set_compute_buffer; + uint32_t num_set_compute_buffer_offset; + uint32_t num_skip_redundant_compute_buffer; + uint32_t num_set_compute_texture; + uint32_t num_skip_redundant_compute_texture; + uint32_t num_set_compute_sampler_state; + uint32_t num_skip_redundant_compute_sampler_state; +} sg_frame_stats_metal_bindings; + +typedef struct sg_frame_stats_metal_uniforms { + uint32_t num_set_vertex_buffer_offset; + uint32_t num_set_fragment_buffer_offset; + uint32_t num_set_compute_buffer_offset; +} sg_frame_stats_metal_uniforms; + +typedef struct sg_frame_stats_metal { + sg_frame_stats_metal_idpool idpool; + sg_frame_stats_metal_pipeline pipeline; + sg_frame_stats_metal_bindings bindings; + sg_frame_stats_metal_uniforms uniforms; +} sg_frame_stats_metal; + +typedef struct sg_frame_stats_wgpu_uniforms { + uint32_t num_set_bindgroup; + uint32_t size_write_buffer; +} sg_frame_stats_wgpu_uniforms; + +typedef struct sg_frame_stats_wgpu_bindings { + uint32_t num_set_vertex_buffer; + uint32_t num_skip_redundant_vertex_buffer; + uint32_t num_set_index_buffer; + uint32_t num_skip_redundant_index_buffer; + uint32_t num_create_bindgroup; + uint32_t num_discard_bindgroup; + uint32_t num_set_bindgroup; + uint32_t num_skip_redundant_bindgroup; + uint32_t num_bindgroup_cache_hits; + uint32_t num_bindgroup_cache_misses; + uint32_t num_bindgroup_cache_collisions; + uint32_t num_bindgroup_cache_invalidates; + uint32_t num_bindgroup_cache_hash_vs_key_mismatch; +} sg_frame_stats_wgpu_bindings; + +typedef struct sg_frame_stats_wgpu { + sg_frame_stats_wgpu_uniforms uniforms; + sg_frame_stats_wgpu_bindings bindings; +} sg_frame_stats_wgpu; + +typedef struct sg_frame_stats_vk { + uint32_t num_cmd_pipeline_barrier; + uint32_t num_allocate_memory; + uint32_t num_free_memory; + uint32_t size_allocate_memory; + uint32_t num_delete_queue_added; + uint32_t num_delete_queue_collected; + uint32_t num_cmd_copy_buffer; + uint32_t num_cmd_copy_buffer_to_image; + uint32_t num_cmd_set_descriptor_buffer_offsets; + uint32_t size_descriptor_buffer_writes; +} sg_frame_stats_vk; + +typedef struct sg_frame_resource_stats { + uint32_t allocated; // number of allocated objects in current frame + uint32_t deallocated; // number of deallocated object in current frame + uint32_t inited; // number of initialized objects in current frame + uint32_t uninited; // number of deinitialized objects in current frame +} sg_frame_resource_stats; + +typedef struct sg_total_resource_stats { + uint32_t alive; // number of live objects in pool + uint32_t free; // number of free objects in pool + uint32_t allocated; // total number of object allocations + uint32_t deallocated; // total number of object deallocations + uint32_t inited; // total number of object initializations + uint32_t uninited; // total number of object deinitializations +} sg_total_resource_stats; + +typedef struct sg_total_stats { + sg_total_resource_stats buffers; + sg_total_resource_stats images; + sg_total_resource_stats samplers; + sg_total_resource_stats views; + sg_total_resource_stats shaders; + sg_total_resource_stats pipelines; +} sg_total_stats; + +typedef struct sg_frame_stats { + uint32_t frame_index; // current frame counter, starts at 0 + + uint32_t num_passes; + uint32_t num_apply_viewport; + uint32_t num_apply_scissor_rect; + uint32_t num_apply_pipeline; + uint32_t num_apply_bindings; + uint32_t num_apply_uniforms; + uint32_t num_draw; + uint32_t num_draw_ex; + uint32_t num_dispatch; + uint32_t num_update_buffer; + uint32_t num_append_buffer; + uint32_t num_update_image; + + uint32_t size_apply_uniforms; + uint32_t size_update_buffer; + uint32_t size_append_buffer; + uint32_t size_update_image; + + sg_frame_resource_stats buffers; + sg_frame_resource_stats images; + sg_frame_resource_stats samplers; + sg_frame_resource_stats views; + sg_frame_resource_stats shaders; + sg_frame_resource_stats pipelines; + + sg_frame_stats_gl gl; + sg_frame_stats_d3d11 d3d11; + sg_frame_stats_metal metal; + sg_frame_stats_wgpu wgpu; + sg_frame_stats_vk vk; +} sg_frame_stats; + +typedef struct sg_stats { + sg_frame_stats prev_frame; + sg_frame_stats cur_frame; + sg_total_stats total; +} sg_stats; + +/* + sg_log_item + + An enum with a unique item for each log message, warning, error + and validation layer message. Note that these messages are only + visible when a logger function is installed in the sg_setup() call. +*/ +#define _SG_LOG_ITEMS \ + _SG_LOGITEM_XMACRO(OK, "Ok") \ + _SG_LOGITEM_XMACRO(MALLOC_FAILED, "memory allocation failed") \ + _SG_LOGITEM_XMACRO(GL_TEXTURE_FORMAT_NOT_SUPPORTED, "pixel format not supported for texture (gl)") \ + _SG_LOGITEM_XMACRO(GL_3D_TEXTURES_NOT_SUPPORTED, "3d textures not supported (gl)") \ + _SG_LOGITEM_XMACRO(GL_ARRAY_TEXTURES_NOT_SUPPORTED, "array textures not supported (gl)") \ + _SG_LOGITEM_XMACRO(GL_STORAGEBUFFER_GLSL_BINDING_OUT_OF_RANGE, "GLSL storage buffer bindslot is out of range (sg_limits.max_storage_buffer_bindings_per_stage) (gl)") \ + _SG_LOGITEM_XMACRO(GL_STORAGEIMAGE_GLSL_BINDING_OUT_OF_RANGE, "GLSL storage image bindslot is out of range (sg.limits.max_storage_image_bindings_per_stage) (gl)") \ + _SG_LOGITEM_XMACRO(GL_SHADER_COMPILATION_FAILED, "shader compilation failed (gl)") \ + _SG_LOGITEM_XMACRO(GL_SHADER_LINKING_FAILED, "shader linking failed (gl)") \ + _SG_LOGITEM_XMACRO(GL_VERTEX_ATTRIBUTE_NOT_FOUND_IN_SHADER, "vertex attribute not found in shader; NOTE: may be caused by GL driver's GLSL compiler removing unused globals") \ + _SG_LOGITEM_XMACRO(GL_UNIFORMBLOCK_NAME_NOT_FOUND_IN_SHADER, "uniform block name not found in shader; NOTE: may be caused by GL driver's GLSL compiler removing unused globals") \ + _SG_LOGITEM_XMACRO(GL_IMAGE_SAMPLER_NAME_NOT_FOUND_IN_SHADER, "image-sampler name not found in shader; NOTE: may be caused by GL driver's GLSL compiler removing unused globals") \ + _SG_LOGITEM_XMACRO(GL_FRAMEBUFFER_STATUS_UNDEFINED, "framebuffer completeness check failed with GL_FRAMEBUFFER_UNDEFINED (gl)") \ + _SG_LOGITEM_XMACRO(GL_FRAMEBUFFER_STATUS_INCOMPLETE_ATTACHMENT, "framebuffer completeness check failed with GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT (gl)") \ + _SG_LOGITEM_XMACRO(GL_FRAMEBUFFER_STATUS_INCOMPLETE_MISSING_ATTACHMENT, "framebuffer completeness check failed with GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT (gl)") \ + _SG_LOGITEM_XMACRO(GL_FRAMEBUFFER_STATUS_UNSUPPORTED, "framebuffer completeness check failed with GL_FRAMEBUFFER_UNSUPPORTED (gl)") \ + _SG_LOGITEM_XMACRO(GL_FRAMEBUFFER_STATUS_INCOMPLETE_MULTISAMPLE, "framebuffer completeness check failed with GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE (gl)") \ + _SG_LOGITEM_XMACRO(GL_FRAMEBUFFER_STATUS_UNKNOWN, "framebuffer completeness check failed (unknown reason) (gl)") \ + _SG_LOGITEM_XMACRO(D3D11_FEATURE_LEVEL_0_DETECTED, "D3D11 Feature Level 0 device detected, this restricts the number of UAV slots to 8! (d3d11)") \ + _SG_LOGITEM_XMACRO(D3D11_CREATE_BUFFER_FAILED, "CreateBuffer() failed (d3d11)") \ + _SG_LOGITEM_XMACRO(D3D11_CREATE_BUFFER_SRV_FAILED, "CreateShaderResourceView() failed for storage buffer (d3d11)") \ + _SG_LOGITEM_XMACRO(D3D11_CREATE_BUFFER_UAV_FAILED, "CreateUnorderedAccessView() failed for storage buffer (d3d11)") \ + _SG_LOGITEM_XMACRO(D3D11_CREATE_DEPTH_TEXTURE_UNSUPPORTED_PIXEL_FORMAT, "pixel format not supported for depth-stencil texture (d3d11)") \ + _SG_LOGITEM_XMACRO(D3D11_CREATE_DEPTH_TEXTURE_FAILED, "CreateTexture2D() failed for depth-stencil texture (d3d11)") \ + _SG_LOGITEM_XMACRO(D3D11_CREATE_2D_TEXTURE_UNSUPPORTED_PIXEL_FORMAT, "pixel format not supported for 2d-, cube- or array-texture (d3d11)") \ + _SG_LOGITEM_XMACRO(D3D11_CREATE_2D_TEXTURE_FAILED, "CreateTexture2D() failed for 2d-, cube- or array-texture (d3d11)") \ + _SG_LOGITEM_XMACRO(D3D11_CREATE_2D_SRV_FAILED, "CreateShaderResourceView() failed for 2d-, cube- or array-texture (d3d11)") \ + _SG_LOGITEM_XMACRO(D3D11_CREATE_3D_TEXTURE_UNSUPPORTED_PIXEL_FORMAT, "pixel format not supported for 3D texture (d3d11)") \ + _SG_LOGITEM_XMACRO(D3D11_CREATE_3D_TEXTURE_FAILED, "CreateTexture3D() failed (d3d11)") \ + _SG_LOGITEM_XMACRO(D3D11_CREATE_3D_SRV_FAILED, "CreateShaderResourceView() failed for 3d texture (d3d11)") \ + _SG_LOGITEM_XMACRO(D3D11_CREATE_MSAA_TEXTURE_FAILED, "CreateTexture2D() failed for MSAA render target texture (d3d11)") \ + _SG_LOGITEM_XMACRO(D3D11_CREATE_SAMPLER_STATE_FAILED, "CreateSamplerState() failed (d3d11)") \ + _SG_LOGITEM_XMACRO(D3D11_UNIFORMBLOCK_HLSL_REGISTER_B_OUT_OF_RANGE, "sg_shader_desc.uniform_blocks[].hlsl_register_b_n is out of range (must be 0..7)") \ + _SG_LOGITEM_XMACRO(D3D11_STORAGEBUFFER_HLSL_REGISTER_T_OUT_OF_RANGE, "sg_shader_desc.views[].storage_buffer.hlsl_register_t_n is out of range (must be 0..31)") \ + _SG_LOGITEM_XMACRO(D3D11_STORAGEBUFFER_HLSL_REGISTER_U_OUT_OF_RANGE, "sg_shader_desc.views[].storage_buffer.hlsl_register_u_n is out of range (must be 0..31)") \ + _SG_LOGITEM_XMACRO(D3D11_IMAGE_HLSL_REGISTER_T_OUT_OF_RANGE, "sg_shader_desc.views[].texture.hlsl_register_t_n is out of range (must be 0..31)") \ + _SG_LOGITEM_XMACRO(D3D11_STORAGEIMAGE_HLSL_REGISTER_U_OUT_OF_RANGE, "sg_shader_desc.views[].storage_image.hlsl_register_u_n is out of range (must be 0..31)") \ + _SG_LOGITEM_XMACRO(D3D11_SAMPLER_HLSL_REGISTER_S_OUT_OF_RANGE, "sampler 'hlsl_register_s_n' is out of rang (must be 0..11)") \ + _SG_LOGITEM_XMACRO(D3D11_LOAD_D3DCOMPILER_47_DLL_FAILED, "loading d3dcompiler_47.dll failed (d3d11)") \ + _SG_LOGITEM_XMACRO(D3D11_SHADER_COMPILATION_FAILED, "shader compilation failed (d3d11)") \ + _SG_LOGITEM_XMACRO(D3D11_SHADER_COMPILATION_OUTPUT, "") \ + _SG_LOGITEM_XMACRO(D3D11_CREATE_CONSTANT_BUFFER_FAILED, "CreateBuffer() failed for uniform constant buffer (d3d11)") \ + _SG_LOGITEM_XMACRO(D3D11_CREATE_INPUT_LAYOUT_FAILED, "CreateInputLayout() failed (d3d11)") \ + _SG_LOGITEM_XMACRO(D3D11_CREATE_RASTERIZER_STATE_FAILED, "CreateRasterizerState() failed (d3d11)") \ + _SG_LOGITEM_XMACRO(D3D11_CREATE_DEPTH_STENCIL_STATE_FAILED, "CreateDepthStencilState() failed (d3d11)") \ + _SG_LOGITEM_XMACRO(D3D11_CREATE_BLEND_STATE_FAILED, "CreateBlendState() failed (d3d11)") \ + _SG_LOGITEM_XMACRO(D3D11_CREATE_RTV_FAILED, "CreateRenderTargetView() failed (d3d11)") \ + _SG_LOGITEM_XMACRO(D3D11_CREATE_DSV_FAILED, "CreateDepthStencilView() failed (d3d11)") \ + _SG_LOGITEM_XMACRO(D3D11_CREATE_UAV_FAILED, "CreateUnorderedAccessView() failed (d3d11)") \ + _SG_LOGITEM_XMACRO(D3D11_MAP_FOR_UPDATE_BUFFER_FAILED, "Map() failed when updating buffer (d3d11)") \ + _SG_LOGITEM_XMACRO(D3D11_MAP_FOR_APPEND_BUFFER_FAILED, "Map() failed when appending to buffer (d3d11)") \ + _SG_LOGITEM_XMACRO(D3D11_MAP_FOR_UPDATE_IMAGE_FAILED, "Map() failed when updating image (d3d11)") \ + _SG_LOGITEM_XMACRO(METAL_CREATE_BUFFER_FAILED, "failed to create buffer object (metal)") \ + _SG_LOGITEM_XMACRO(METAL_TEXTURE_FORMAT_NOT_SUPPORTED, "pixel format not supported for texture (metal)") \ + _SG_LOGITEM_XMACRO(METAL_CREATE_TEXTURE_FAILED, "failed to create texture object (metal)") \ + _SG_LOGITEM_XMACRO(METAL_CREATE_SAMPLER_FAILED, "failed to create sampler object (metal)") \ + _SG_LOGITEM_XMACRO(METAL_SHADER_COMPILATION_FAILED, "shader compilation failed (metal)") \ + _SG_LOGITEM_XMACRO(METAL_SHADER_CREATION_FAILED, "shader creation failed (metal)") \ + _SG_LOGITEM_XMACRO(METAL_SHADER_COMPILATION_OUTPUT, "") \ + _SG_LOGITEM_XMACRO(METAL_SHADER_ENTRY_NOT_FOUND, "shader entry function not found (metal)") \ + _SG_LOGITEM_XMACRO(METAL_UNIFORMBLOCK_MSL_BUFFER_SLOT_OUT_OF_RANGE, "uniform block 'msl_buffer_n' is out of range (must be 0..7)") \ + _SG_LOGITEM_XMACRO(METAL_STORAGEBUFFER_MSL_BUFFER_SLOT_OUT_OF_RANGE, "storage buffer 'msl_buffer_n' is out of range (must be 8..23)") \ + _SG_LOGITEM_XMACRO(METAL_STORAGEIMAGE_MSL_TEXTURE_SLOT_OUT_OF_RANGE, "storage image 'msl_texture_n' is out of range (must be 0..31)") \ + _SG_LOGITEM_XMACRO(METAL_IMAGE_MSL_TEXTURE_SLOT_OUT_OF_RANGE, "image 'msl_texture_n' is out of range (must be 0..31)") \ + _SG_LOGITEM_XMACRO(METAL_SAMPLER_MSL_SAMPLER_SLOT_OUT_OF_RANGE, "sampler 'msl_sampler_n' is out of range (must be 0..11)") \ + _SG_LOGITEM_XMACRO(METAL_CREATE_CPS_FAILED, "failed to create compute pipeline state (metal)") \ + _SG_LOGITEM_XMACRO(METAL_CREATE_CPS_OUTPUT, "") \ + _SG_LOGITEM_XMACRO(METAL_CREATE_RPS_FAILED, "failed to create render pipeline state (metal)") \ + _SG_LOGITEM_XMACRO(METAL_CREATE_RPS_OUTPUT, "") \ + _SG_LOGITEM_XMACRO(METAL_CREATE_DSS_FAILED, "failed to create depth stencil state (metal)") \ + _SG_LOGITEM_XMACRO(WGPU_BINDGROUPS_POOL_EXHAUSTED, "bindgroups pool exhausted (increase sg_desc.bindgroups_cache_size) (wgpu)") \ + _SG_LOGITEM_XMACRO(WGPU_BINDGROUPSCACHE_SIZE_GREATER_ONE, "sg_desc.wgpu.bindgroups_cache_size must be > 1 (wgpu)") \ + _SG_LOGITEM_XMACRO(WGPU_BINDGROUPSCACHE_SIZE_POW2, "sg_desc.wgpu.bindgroups_cache_size must be a power of 2 (wgpu)") \ + _SG_LOGITEM_XMACRO(WGPU_CREATEBINDGROUP_FAILED, "wgpuDeviceCreateBindGroup failed") \ + _SG_LOGITEM_XMACRO(WGPU_CREATE_BUFFER_FAILED, "wgpuDeviceCreateBuffer() failed") \ + _SG_LOGITEM_XMACRO(WGPU_CREATE_TEXTURE_FAILED, "wgpuDeviceCreateTexture() failed") \ + _SG_LOGITEM_XMACRO(WGPU_CREATE_TEXTURE_VIEW_FAILED, "wgpuTextureCreateView() failed") \ + _SG_LOGITEM_XMACRO(WGPU_CREATE_SAMPLER_FAILED, "wgpuDeviceCreateSampler() failed") \ + _SG_LOGITEM_XMACRO(WGPU_CREATE_SHADER_MODULE_FAILED, "wgpuDeviceCreateShaderModule() failed") \ + _SG_LOGITEM_XMACRO(WGPU_SHADER_CREATE_BINDGROUP_LAYOUT_FAILED, "wgpuDeviceCreateBindGroupLayout() for shader stage failed") \ + _SG_LOGITEM_XMACRO(WGPU_UNIFORMBLOCK_WGSL_GROUP0_BINDING_OUT_OF_RANGE, "uniform block 'wgsl_group0_binding_n' is out of range (must be 0..15)") \ + _SG_LOGITEM_XMACRO(WGPU_TEXTURE_WGSL_GROUP1_BINDING_OUT_OF_RANGE, "texture 'wgsl_group1_binding_n' is out of range (must be 0..127)") \ + _SG_LOGITEM_XMACRO(WGPU_STORAGEBUFFER_WGSL_GROUP1_BINDING_OUT_OF_RANGE, "storage buffer 'wgsl_group1_binding_n' is out of range (must be 0..127)") \ + _SG_LOGITEM_XMACRO(WGPU_STORAGEIMAGE_WGSL_GROUP1_BINDING_OUT_OF_RANGE, "storage image 'wgsl_group1_binding_n' is out of range (must be 0..127)") \ + _SG_LOGITEM_XMACRO(WGPU_SAMPLER_WGSL_GROUP1_BINDING_OUT_OF_RANGE, "sampler 'wgsl_group1_binding_n' is out of range (must be 0..127)") \ + _SG_LOGITEM_XMACRO(WGPU_CREATE_PIPELINE_LAYOUT_FAILED, "wgpuDeviceCreatePipelineLayout() failed") \ + _SG_LOGITEM_XMACRO(WGPU_CREATE_RENDER_PIPELINE_FAILED, "wgpuDeviceCreateRenderPipeline() failed") \ + _SG_LOGITEM_XMACRO(WGPU_CREATE_COMPUTE_PIPELINE_FAILED, "wgpuDeviceCreateComputePipeline() failed") \ + _SG_LOGITEM_XMACRO(VULKAN_REQUIRED_EXTENSION_FUNCTION_MISSING, "vulkan: could not look up a required extension function pointer") \ + _SG_LOGITEM_XMACRO(VULKAN_ALLOC_DEVICE_MEMORY_NO_SUITABLE_MEMORY_TYPE, "vulkan: could not find suitable memory type") \ + _SG_LOGITEM_XMACRO(VULKAN_ALLOCATE_MEMORY_FAILED, "vulkan: vkAllocateMemory() failed!") \ + _SG_LOGITEM_XMACRO(VULKAN_ALLOC_BUFFER_DEVICE_MEMORY_FAILED, "vulkan: allocating buffer device memory failed") \ + _SG_LOGITEM_XMACRO(VULKAN_ALLOC_IMAGE_DEVICE_MEMORY_FAILED, "vulkan: allocating image device memory failed") \ + _SG_LOGITEM_XMACRO(VULKAN_DELETE_QUEUE_EXHAUSTED, "vulkan: internal delete queue exhausted (too many objects destroyed per frame)") \ + _SG_LOGITEM_XMACRO(VULKAN_STAGING_CREATE_BUFFER_FAILED, "vulkan: vkCreateBuffer() failed for staging buffer") \ + _SG_LOGITEM_XMACRO(VULKAN_STAGING_ALLOCATE_MEMORY_FAILED, "vulkan: allocating device memory for staging buffer failed") \ + _SG_LOGITEM_XMACRO(VULKAN_STAGING_BIND_BUFFER_MEMORY_FAILED, "vulkan: vkBindBufferMemory() failed for staging buffer") \ + _SG_LOGITEM_XMACRO(VULKAN_STAGING_STREAM_BUFFER_OVERFLOW, "vulkan: per-frame stream staging buffer has overflown (sg_desc.vulkan.stream_staging_buffer_size)") \ + _SG_LOGITEM_XMACRO(VULKAN_CREATE_SHARED_BUFFER_FAILED, "vulkan: vkCreateBuffer() failed for cpu/gpu-shared buffer") \ + _SG_LOGITEM_XMACRO(VULKAN_ALLOCATE_SHARED_BUFFER_MEMORY_FAILED, "vulkan: allocating device memory for cpu/gpu-shared buffer failed") \ + _SG_LOGITEM_XMACRO(VULKAN_BIND_SHARED_BUFFER_MEMORY_FAILED, "vulkan: vkBindBufferMemory() failed for cpu/gpu-shared buffer") \ + _SG_LOGITEM_XMACRO(VULKAN_MAP_SHARED_BUFFER_MEMORY_FAILED, "vulkan: vkMapMemory() failed on cpu/gpu-shared buffer") \ + _SG_LOGITEM_XMACRO(VULKAN_CREATE_BUFFER_FAILED, "vulkan: vkCreateBuffer() failed!") \ + _SG_LOGITEM_XMACRO(VULKAN_BIND_BUFFER_MEMORY_FAILED, "vulkan: vkBindBufferMemory() failed!") \ + _SG_LOGITEM_XMACRO(VULKAN_CREATE_IMAGE_FAILED, "vulkan: vkCreateImage() failed!") \ + _SG_LOGITEM_XMACRO(VULKAN_BIND_IMAGE_MEMORY_FAILED, "vulkan: vkBindImageMemory() failed!") \ + _SG_LOGITEM_XMACRO(VULKAN_CREATE_SHADER_MODULE_FAILED, "vukan: vkCreateShaderModule() failed!") \ + _SG_LOGITEM_XMACRO(VULKAN_UNIFORMBLOCK_SPIRV_SET0_BINDING_OUT_OF_RANGE, "vulkan: uniform block 'spirv_set0_binding_n' is out of range (must be 0..15)") \ + _SG_LOGITEM_XMACRO(VULKAN_TEXTURE_SPIRV_SET1_BINDING_OUT_OF_RANGE, "vulkan: texture 'spirv_set1_binding_n' is out of range (must be 0..127)") \ + _SG_LOGITEM_XMACRO(VULKAN_STORAGEBUFFER_SPIRV_SET1_BINDING_OUT_OF_RANGE, "vulkan: storage buffer 'spirv_set1_binding_n' is out of range (must be 0..127)") \ + _SG_LOGITEM_XMACRO(VULKAN_STORAGEIMAGE_SPIRV_SET1_BINDING_OUT_OF_RANGE, "vulkan: storage image 'spirv_set1_binding_n' is out of range (must be 0..127)") \ + _SG_LOGITEM_XMACRO(VULKAN_SAMPLER_SPIRV_SET1_BINDING_OUT_OF_RANGE, "vulkan: sampler 'spirv_set1_binding_n' is out of range (must be 0..127)") \ + _SG_LOGITEM_XMACRO(VULKAN_CREATE_DESCRIPTOR_SET_LAYOUT_FAILED, "vulkan: vkCreateDescriptorSetLayout() failed!") \ + _SG_LOGITEM_XMACRO(VULKAN_SHADER_UNIFORM_DESCRIPTOR_SET_SIZE_VS_CACHE_SIZE, "vulkan: shader uniform descriptor set is too big for the descriptor set cache (please write a Github issue)") \ + _SG_LOGITEM_XMACRO(VULKAN_CREATE_PIPELINE_LAYOUT_FAILED, "vulkan: vkCreatePipelineLayout() failed!") \ + _SG_LOGITEM_XMACRO(VULKAN_CREATE_GRAPHICS_PIPELINE_FAILED, "vulkan: vkCreateGraphicsPipelines() failed!") \ + _SG_LOGITEM_XMACRO(VULKAN_CREATE_COMPUTE_PIPELINE_FAILED, "vulkan: vkCreateComputePipelines() failed!") \ + _SG_LOGITEM_XMACRO(VULKAN_CREATE_IMAGE_VIEW_FAILED, "vulkan: vkCreateImageView() failed!") \ + _SG_LOGITEM_XMACRO(VULKAN_VIEW_MAX_DESCRIPTOR_SIZE, "vulkan: required view descriptor size is greater than _SG_VK_MAX_DESCRIPTOR_DATA_SIZE") \ + _SG_LOGITEM_XMACRO(VULKAN_CREATE_SAMPLER_FAILED, "vulkan: vkCreateSampler() failed!") \ + _SG_LOGITEM_XMACRO(VULKAN_SAMPLER_MAX_DESCRIPTOR_SIZE, "vulkan: required sampler descriptor size is greater than _SG_VK_MAX_DESCRIPTOR_DATA_SIZE") \ + _SG_LOGITEM_XMACRO(VULKAN_WAIT_FOR_FENCE_FAILED, "vulkan: vkWaitForFence() failed!") \ + _SG_LOGITEM_XMACRO(VULKAN_UNIFORM_BUFFER_OVERFLOW, "vulkan: uniform buffer has overflown (increase sg_desc.uniform_buffer_size)") \ + _SG_LOGITEM_XMACRO(VULKAN_DESCRIPTOR_BUFFER_OVERFLOW, "vulkan: desccriptor buffer has overflown (increase sg_desc.vulkan.descriptor_buffer_size)") \ + _SG_LOGITEM_XMACRO(IDENTICAL_COMMIT_LISTENER, "attempting to add identical commit listener") \ + _SG_LOGITEM_XMACRO(COMMIT_LISTENER_ARRAY_FULL, "commit listener array full") \ + _SG_LOGITEM_XMACRO(TRACE_HOOKS_NOT_ENABLED, "sg_install_trace_hooks() called, but SOKOL_TRACE_HOOKS is not defined") \ + _SG_LOGITEM_XMACRO(DEALLOC_BUFFER_INVALID_STATE, "sg_dealloc_buffer(): buffer must be in ALLOC state") \ + _SG_LOGITEM_XMACRO(DEALLOC_IMAGE_INVALID_STATE, "sg_dealloc_image(): image must be in alloc state") \ + _SG_LOGITEM_XMACRO(DEALLOC_SAMPLER_INVALID_STATE, "sg_dealloc_sampler(): sampler must be in alloc state") \ + _SG_LOGITEM_XMACRO(DEALLOC_SHADER_INVALID_STATE, "sg_dealloc_shader(): shader must be in ALLOC state") \ + _SG_LOGITEM_XMACRO(DEALLOC_PIPELINE_INVALID_STATE, "sg_dealloc_pipeline(): pipeline must be in ALLOC state") \ + _SG_LOGITEM_XMACRO(DEALLOC_VIEW_INVALID_STATE, "sg_dealloc_view(): view must be in ALLOC state") \ + _SG_LOGITEM_XMACRO(INIT_BUFFER_INVALID_STATE, "sg_init_buffer(): buffer must be in ALLOC state") \ + _SG_LOGITEM_XMACRO(INIT_IMAGE_INVALID_STATE, "sg_init_image(): image must be in ALLOC state") \ + _SG_LOGITEM_XMACRO(INIT_SAMPLER_INVALID_STATE, "sg_init_sampler(): sampler must be in ALLOC state") \ + _SG_LOGITEM_XMACRO(INIT_SHADER_INVALID_STATE, "sg_init_shader(): shader must be in ALLOC state") \ + _SG_LOGITEM_XMACRO(INIT_PIPELINE_INVALID_STATE, "sg_init_pipeline(): pipeline must be in ALLOC state") \ + _SG_LOGITEM_XMACRO(INIT_VIEW_INVALID_STATE, "sg_init_view(): view must be in ALLOC state") \ + _SG_LOGITEM_XMACRO(UNINIT_BUFFER_INVALID_STATE, "sg_uninit_buffer(): buffer must be in VALID, FAILED or ALLOC state") \ + _SG_LOGITEM_XMACRO(UNINIT_IMAGE_INVALID_STATE, "sg_uninit_image(): image must be in VALID, FAILED or ALLOC state") \ + _SG_LOGITEM_XMACRO(UNINIT_SAMPLER_INVALID_STATE, "sg_uninit_sampler(): sampler must be in VALID, FAILED or ALLOC state") \ + _SG_LOGITEM_XMACRO(UNINIT_SHADER_INVALID_STATE, "sg_uninit_shader(): shader must be in VALID, FAILED or ALLOC state") \ + _SG_LOGITEM_XMACRO(UNINIT_PIPELINE_INVALID_STATE, "sg_uninit_pipeline(): pipeline must be in VALID, FAILED or ALLOC state") \ + _SG_LOGITEM_XMACRO(UNINIT_VIEW_INVALID_STATE, "sg_uninit_view(): view must be in VALID, FAILED or ALLOC state") \ + _SG_LOGITEM_XMACRO(FAIL_BUFFER_INVALID_STATE, "sg_fail_buffer(): buffer must be in ALLOC state") \ + _SG_LOGITEM_XMACRO(FAIL_IMAGE_INVALID_STATE, "sg_fail_image(): image must be in ALLOC state") \ + _SG_LOGITEM_XMACRO(FAIL_SAMPLER_INVALID_STATE, "sg_fail_sampler(): sampler must be in ALLOC state") \ + _SG_LOGITEM_XMACRO(FAIL_SHADER_INVALID_STATE, "sg_fail_shader(): shader must be in ALLOC state") \ + _SG_LOGITEM_XMACRO(FAIL_PIPELINE_INVALID_STATE, "sg_fail_pipeline(): pipeline must be in ALLOC state") \ + _SG_LOGITEM_XMACRO(FAIL_VIEW_INVALID_STATE, "sg_fail_view(): view must be in ALLOC state") \ + _SG_LOGITEM_XMACRO(BUFFER_POOL_EXHAUSTED, "buffer pool exhausted") \ + _SG_LOGITEM_XMACRO(IMAGE_POOL_EXHAUSTED, "image pool exhausted") \ + _SG_LOGITEM_XMACRO(SAMPLER_POOL_EXHAUSTED, "sampler pool exhausted") \ + _SG_LOGITEM_XMACRO(SHADER_POOL_EXHAUSTED, "shader pool exhausted") \ + _SG_LOGITEM_XMACRO(PIPELINE_POOL_EXHAUSTED, "pipeline pool exhausted") \ + _SG_LOGITEM_XMACRO(VIEW_POOL_EXHAUSTED, "view pool exhausted") \ + _SG_LOGITEM_XMACRO(BEGINPASS_TOO_MANY_COLOR_ATTACHMENTS, "sg_begin_pass: too many color attachments (sg_limits.max_color_attachments)") \ + _SG_LOGITEM_XMACRO(BEGINPASS_TOO_MANY_RESOLVE_ATTACHMENTS, "sg_begin_pass: too many resolve attachments (sg_limits.max_color_attachments)") \ + _SG_LOGITEM_XMACRO(BEGINPASS_ATTACHMENTS_ALIVE, "sg_begin_pass: an attachment was provided that no longer exists") \ + _SG_LOGITEM_XMACRO(DRAW_WITHOUT_BINDINGS, "attempting to draw without resource bindings") \ + _SG_LOGITEM_XMACRO(SHADERDESC_TOO_MANY_VERTEXSTAGE_TEXTURES, "sg_shader_desc: too many texture bindings on vertex shader stage (sg_limits.max_texture_bindings_per_stage)") \ + _SG_LOGITEM_XMACRO(SHADERDESC_TOO_MANY_FRAGMENTSTAGE_TEXTURES, "sg_shader_desc: too many texture bindings on fragment shader stage (sg_limits.max_texture_bindings_per_stage)") \ + _SG_LOGITEM_XMACRO(SHADERDESC_TOO_MANY_COMPUTESTAGE_TEXTURES, "sg_shader_desc: too many texture bindings on compute shader stage (sg_limits.max_texture_bindings_per_stage)") \ + _SG_LOGITEM_XMACRO(SHADERDESC_TOO_MANY_VERTEXSTAGE_STORAGEBUFFERS, "sg_shader_desc: too many storage buffer bindings on vertex shader stage (sg_limits.max_storage_buffer_bindings_per_stage)") \ + _SG_LOGITEM_XMACRO(SHADERDESC_TOO_MANY_FRAGMENTSTAGE_STORAGEBUFFERS, "sg_shader_desc: too many storage buffer bindings on fragment shader stage (sg_limits.max_storage_buffer_bindings_per_stage)") \ + _SG_LOGITEM_XMACRO(SHADERDESC_TOO_MANY_COMPUTESTAGE_STORAGEBUFFERS, "sg_shader_desc: too many storage buffer bindings on compute shader stage (sg_limits.max_storage_buffer_bindings_per_stage)") \ + _SG_LOGITEM_XMACRO(SHADERDESC_TOO_MANY_VERTEXSTAGE_STORAGEIMAGES, "sg_shader_desc: too many storage image bindings on vertex shader stage (sg_limits.max_storage_image_bindings_per_stage)") \ + _SG_LOGITEM_XMACRO(SHADERDESC_TOO_MANY_FRAGMENTSTAGE_STORAGEIMAGES, "sg_shader_desc: too many storage image bindings on fragment shader stage (sg_limits.max_storage_image_bindings_per_stage)") \ + _SG_LOGITEM_XMACRO(SHADERDESC_TOO_MANY_COMPUTESTAGE_STORAGEIMAGES, "sg_shader_desc: too many storage image bindings on compute shader stage (sg_limits.max_storage_image_bindings_per_stage)") \ + _SG_LOGITEM_XMACRO(SHADERDESC_TOO_MANY_VERTEXSTAGE_TEXTURESAMPLERPAIRS, "sg_shader_desc: too many texture-sampler-pairs on vertex shader stage (sg_limits.max_texture_bindings_per_stage)") \ + _SG_LOGITEM_XMACRO(SHADERDESC_TOO_MANY_FRAGMENTSTAGE_TEXTURESAMPLERPAIRS, "sg_shader_desc: too many texture-sampler-pairs on fragment shader stage (sg_limits.max_texture_bindings_per_stage)") \ + _SG_LOGITEM_XMACRO(SHADERDESC_TOO_MANY_COMPUTESTAGE_TEXTURESAMPLERPAIRS, "sg_shader_desc: too many texture-sampler-pairs on compute shader stage (sg_limits.max_texture_bindings_per_stage)") \ + _SG_LOGITEM_XMACRO(VALIDATE_BUFFERDESC_CANARY, "sg_buffer_desc not initialized") \ + _SG_LOGITEM_XMACRO(VALIDATE_BUFFERDESC_IMMUTABLE_DYNAMIC_STREAM, "sg_buffer_desc.usage: only one of .immutable, .dynamic_update, .stream_update can be true") \ + _SG_LOGITEM_XMACRO(VALIDATE_BUFFERDESC_SEPARATE_BUFFER_TYPES, "sg_buffer_desc.usage: on WebGL2, only one of .vertex_buffer or .index_buffer can be true (check sg_features.separate_buffer_types)") \ + _SG_LOGITEM_XMACRO(VALIDATE_BUFFERDESC_EXPECT_NONZERO_SIZE, "sg_buffer_desc.size must be greater zero") \ + _SG_LOGITEM_XMACRO(VALIDATE_BUFFERDESC_EXPECT_MATCHING_DATA_SIZE, "sg_buffer_desc.size and .data.size must be equal") \ + _SG_LOGITEM_XMACRO(VALIDATE_BUFFERDESC_EXPECT_ZERO_DATA_SIZE, "sg_buffer_desc.data.size expected to be zero") \ + _SG_LOGITEM_XMACRO(VALIDATE_BUFFERDESC_EXPECT_NO_DATA, "sg_buffer_desc.data.ptr must be null for dynamic/stream buffers") \ + _SG_LOGITEM_XMACRO(VALIDATE_BUFFERDESC_EXPECT_DATA, "sg_buffer_desc: initial content data must be provided for immutable buffers without storage buffer usage") \ + _SG_LOGITEM_XMACRO(VALIDATE_BUFFERDESC_STORAGEBUFFER_SUPPORTED, "storage buffers not supported by the backend 3D API (requires OpenGL >= 4.3)") \ + _SG_LOGITEM_XMACRO(VALIDATE_BUFFERDESC_STORAGEBUFFER_SIZE_MULTIPLE_4, "size of storage buffers must be a multiple of 4") \ + _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDATA_NODATA, "sg_image_data: no data (.ptr and/or .size is zero)") \ + _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDATA_DATA_SIZE, "sg_image_data: data size doesn't match expected surface size") \ + _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDESC_CANARY, "sg_image_desc not initialized") \ + _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDESC_IMMUTABLE_DYNAMIC_STREAM, "sg_image_desc.usage: only one of .immutable, .dynamic_update, .stream_update can be true") \ + _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDESC_ATTACHMENT_COLOR_DEPTH_STENCIL, "sg_image_desc.usage: only one of .color_attachment and .depth_stencil_attachment can be true") \ + _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDESC_IMAGETYPE_2D_NUMSLICES, "sg_image_desc.num_slices must be exactly 1 for SG_IMAGETYPE_2D") \ + _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDESC_IMAGETYPE_CUBE_NUMSLICES, "sg_image_desc.num_slices must be exactly 6 for SG_IMAGETYPE_CUBE") \ + _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDESC_IMAGETYPE_ARRAY_NUMSLICES, "sg_image_desc.num_slices must be ((>= 1) && (<= sg_limits.max_image_array_layers)) for SG_IMAGETYPE_ARRAY") \ + _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDESC_IMAGETYPE_3D_NUMSLICES, "sg_image_desc.num_slices must be ((>= 1) && (<= sg_limits.max_image_size_3d)) for SG_IMAGETYPE_ARRAY") \ + _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDESC_NUMSLICES, "sg_image_desc.num_slices must be > 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDESC_WIDTH, "sg_image_desc.width must be > 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDESC_HEIGHT, "sg_image_desc.height must be > 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDESC_NONRT_PIXELFORMAT, "invalid pixel format for non-render-target image") \ + _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDESC_MSAA_BUT_NO_ATTACHMENT, "non-attachment images cannot be multisampled") \ + _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDESC_DEPTH_3D_IMAGE, "3D images cannot have a depth/stencil image format") \ + _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDESC_ATTACHMENT_EXPECT_IMMUTABLE, "attachment and storage images must be sg_image_usage.immutable") \ + _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDESC_ATTACHMENT_EXPECT_NO_DATA, "render/storage attachment images cannot be initialized with data") \ + _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDESC_ATTACHMENT_PIXELFORMAT, "invalid pixel format for render attachment image") \ + _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDESC_ATTACHMENT_RESOLVE_EXPECT_NO_MSAA, "resolve attachment images cannot be multisampled") \ + _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDESC_ATTACHMENT_NO_MSAA_SUPPORT, "multisampling not supported for this pixel format") \ + _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDESC_ATTACHMENT_MSAA_NUM_MIPMAPS, "multisample images must have num_mipmaps == 1") \ + _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDESC_ATTACHMENT_MSAA_3D_IMAGE, "3D images cannot have a sample_count > 1") \ + _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDESC_ATTACHMENT_MSAA_CUBE_IMAGE, "cube images cannot have sample_count > 1") \ + _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDESC_ATTACHMENT_MSAA_ARRAY_IMAGE, "array images cannot have sample_count > 1") \ + _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDESC_STORAGEIMAGE_PIXELFORMAT, "invalid pixel format for storage image") \ + _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDESC_STORAGEIMAGE_EXPECT_NO_MSAA, "storage images cannot be multisampled") \ + _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDESC_INJECTED_NO_DATA, "images with injected textures cannot be initialized with data") \ + _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDESC_DYNAMIC_NO_DATA, "dynamic/stream-update images cannot be initialized with data") \ + _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDESC_COMPRESSED_IMMUTABLE, "compressed images must be immutable") \ + _SG_LOGITEM_XMACRO(VALIDATE_SAMPLERDESC_CANARY, "sg_sampler_desc not initialized") \ + _SG_LOGITEM_XMACRO(VALIDATE_SAMPLERDESC_ANISTROPIC_REQUIRES_LINEAR_FILTERING, "sg_sampler_desc.max_anisotropy > 1 requires min/mag/mipmap_filter to be SG_FILTER_LINEAR") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_CANARY, "sg_shader_desc not initialized") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_VERTEX_SOURCE, "vertex shader source code expected") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_FRAGMENT_SOURCE, "fragment shader source code expected") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_COMPUTE_SOURCE, "compute shader source code expected") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_VERTEX_SOURCE_OR_BYTECODE, "vertex shader source or byte code expected") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_FRAGMENT_SOURCE_OR_BYTECODE, "fragment shader source or byte code expected") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_COMPUTE_SOURCE_OR_BYTECODE, "compute shader source or byte code expected") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_INVALID_SHADER_COMBO, "cannot combine compute shaders with vertex or fragment shaders") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_NO_BYTECODE_SIZE, "shader byte code length (in bytes) required") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_METAL_THREADS_PER_THREADGROUP_INITIALIZED, "sg_shader_desc.mtl_threads_per_threadgroup must be initialized for compute shaders (metal)") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_METAL_THREADS_PER_THREADGROUP_MULTIPLE_32, "sg_shader_desc.mtl_threads_per_threadgroup (x * y * z) must be a multiple of 32 (metal)") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_UNIFORMBLOCK_NO_CONT_MEMBERS, "sg_shader_desc.uniform_blocks[].glsl_uniforms[]: items must occupy continuous slots") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_UNIFORMBLOCK_SIZE_IS_ZERO, "sg_shader_desc.uniform_blocks[].size cannot be zero") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_UNIFORMBLOCK_METAL_BUFFER_SLOT_COLLISION, "sg_shader_desc.uniform_blocks[].msl_buffer_n must be unique across uniform blocks and storage buffers in same shader stage") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_UNIFORMBLOCK_HLSL_REGISTER_B_COLLISION, "sg_shader_desc.uniform_blocks[].hlsl_register_b_n must be unique across uniform blocks in same shader stage") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_UNIFORMBLOCK_WGSL_GROUP0_BINDING_COLLISION, "sg_shader_desc.uniform_blocks[].wgsl_group0_binding_n must be unique across all uniform blocks") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_UNIFORMBLOCK_SPIRV_SET0_BINDING_COLLISION, "sg_shader_desc.unifrom_blocks[].spirv_set0_binding_n must be unique across all uniform blocks") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_UNIFORMBLOCK_NO_MEMBERS, "sg_shader_desc.uniform_blocks[].glsl_uniforms[]: GL backend requires uniform block member declarations") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_UNIFORMBLOCK_UNIFORM_GLSL_NAME, "sg_shader_desc.uniform_blocks[].glsl_uniforms[].glsl_name missing") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_UNIFORMBLOCK_SIZE_MISMATCH, "sg_shader_desc.uniform_blocks[].glsl_uniforms[]: size of uniform block members doesn't match uniform block size") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_UNIFORMBLOCK_ARRAY_COUNT, "sg_shader_desc.uniform_blocks[].glsl_uniforms[].array_count must be >= 1") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_UNIFORMBLOCK_STD140_ARRAY_TYPE, "sg_shader_desc.uniform_blocks[].glsl_uniforms[].type: uniform arrays only allowed for FLOAT4, INT4, MAT4 in std140 layout") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_VIEW_STORAGEBUFFER_METAL_BUFFER_SLOT_COLLISION, "sg_shader_desc.views[].storage_buffer.storagemsl_buffer_n must be unique across uniform blocks and storage buffer in same shader stage") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_VIEW_STORAGEBUFFER_HLSL_REGISTER_T_COLLISION, "sg_shader_desc.views[].storage_buffer.hlsl_register_t_n must be unique across read-only storage buffers and images in same shader stage") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_VIEW_STORAGEBUFFER_HLSL_REGISTER_U_COLLISION, "sg_shader_desc.views[].storage_buffer.hlsl_register_u_n must be unique across read/write storage buffers and storage images in same shader stage") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_VIEW_STORAGEBUFFER_GLSL_BINDING_COLLISION, "sg_shader_desc.views[].storage_buffer.glsl_binding_n must be unique across shader stages") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_VIEW_STORAGEBUFFER_WGSL_GROUP1_BINDING_COLLISION, "sg_shader_desc.views[].storage_buffer.wgsl_group1_binding_n must be unique across all view and sampler bindings") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_VIEW_STORAGEBUFFER_SPIRV_SET1_BINDING_COLLISION, "sg_shader_desc.views[].storage_buffer.spirv_set1_binding_n must be unique across all view and sampler bindings") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_VIEW_STORAGEIMAGE_EXPECT_COMPUTE_STAGE, "sg_shader_desc.views[].storage_image: storage images are allowed on the compute stage") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_VIEW_STORAGEIMAGE_METAL_TEXTURE_SLOT_COLLISION, "sg_shader_desc.views[].storage_image.msl_texture_n must be unique across images and storage images in same shader stage") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_VIEW_STORAGEIMAGE_HLSL_REGISTER_U_COLLISION, "sg_shader_desc.views[].storage_image.hlsl_register_u_n must be unique across storage images and read/write storage buffers in same shader stage") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_VIEW_STORAGEIMAGE_GLSL_BINDING_COLLISION, "sg_shader_desc.views[].storage_image.glsl_binding_n must be unique across shader stages") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_VIEW_STORAGEIMAGE_WGSL_GROUP1_BINDING_COLLISION, "sg_shader_desc.views[].storage_image.wgsl_group1_binding_n must be unique across all view and sampler bindings") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_VIEW_STORAGEIMAGE_SPIRV_SET1_BINDING_COLLISION, "sg_shader_desc.views[].storage_image.spirv_set1_binding_n must be unique across all view and sampler bindings") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_VIEW_TEXTURE_METAL_TEXTURE_SLOT_COLLISION, "sg_shader_desc.views[].texture.msl_texture_n must be unique across textures and storage images in same shader stage") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_VIEW_TEXTURE_HLSL_REGISTER_T_COLLISION, "sg_shader_desc.views[].texture.hlsl_register_t_n must be unique across textures and storage buffers in same shader stage") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_VIEW_TEXTURE_WGSL_GROUP1_BINDING_COLLISION, "sg_shader_desc.views[].texture.wgsl_group1_binding_n must be unique across all view and sampler bindings") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_VIEW_TEXTURE_SPIRV_SET1_BINDING_COLLISION, "sg_shader_desc.views[].texture.spirv_set1_binding_n must be unique across all view and sampler bindings") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_SAMPLER_METAL_SAMPLER_SLOT_COLLISION, "sg_shader_desc.samplers[].msl_sampler_n must be unique in same shader stage") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_SAMPLER_HLSL_REGISTER_S_COLLISION, "sg_shader_desc.samplers[].hlsl_register_s_n must be unique in same shader stage") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_SAMPLER_WGSL_GROUP1_BINDING_COLLISION, "sg_shader_desc.samplers[].wgsl_group1_binding_n must be unique across all view and sampler bindings") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_SAMPLER_SPIRV_SET1_BINDING_COLLISION, "sg_shader_desc.samplers[].spirv_set1_binding_n must be unique across all view and sampler bindings") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_TEXTURE_SAMPLER_PAIR_VIEW_SLOT_OUT_OF_RANGE, "texture-sampler-pair view slot index is out of range (sg_shader_desc.texture_sampler_pairs[].view_slot)") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_TEXTURE_SAMPLER_PAIR_SAMPLER_SLOT_OUT_OF_RANGE, "texture-sampler-pair sampler slot index is out of range (sg_shader_desc.texture_sampler_pairs[].sampler_slot)") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_TEXTURE_SAMPLER_PAIR_TEXTURE_STAGE_MISMATCH, "texture-sampler-pair stage doesn't match referenced texture stage") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_TEXTURE_SAMPLER_PAIR_EXPECT_TEXTURE_VIEW, "texture-sampler-pair view must be a texture view (sg_shader_desc.texture_sampler_pairs[].view_slot => sg_shaders_desc.views[i].texture)") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_TEXTURE_SAMPLER_PAIR_SAMPLER_STAGE_MISMATCH, "texture-sampler-pair stage doesn't match referenced sampler stage") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_TEXTURE_SAMPLER_PAIR_GLSL_NAME, "texture-sampler-pair 'glsl_name' missing") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_NONFILTERING_SAMPLER_REQUIRED, "image sample type UNFILTERABLE_FLOAT, UINT, SINT can only be used with NONFILTERING sampler") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_COMPARISON_SAMPLER_REQUIRED, "image sample type DEPTH can only be used with COMPARISON sampler") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_TEXVIEW_NOT_REFERENCED_BY_TEXTURE_SAMPLER_PAIRS, "one or more texture views are not referenced by by texture-sampler-pairs (sg_shader_desc.texture_sampler_pairs[].view_slot)") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_SAMPLER_NOT_REFERENCED_BY_TEXTURE_SAMPLER_PAIRS, "one or more samplers are not referenced by texture-sampler-pairs (sg_shader_desc.texture_sampler_pairs[].sampler_slot)") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_ATTR_STRING_TOO_LONG, "vertex attribute name/semantic string too long (max len 16)") \ + _SG_LOGITEM_XMACRO(VALIDATE_PIPELINEDESC_CANARY, "sg_pipeline_desc not initialized") \ + _SG_LOGITEM_XMACRO(VALIDATE_PIPELINEDESC_SHADER, "sg_pipeline_desc.shader missing or invalid") \ + _SG_LOGITEM_XMACRO(VALIDATE_PIPELINEDESC_COMPUTE_SHADER_EXPECTED, "sg_pipeline_desc.shader must be a compute shader") \ + _SG_LOGITEM_XMACRO(VALIDATE_PIPELINEDESC_NO_COMPUTE_SHADER_EXPECTED, "sg_pipeline_desc.compute is false, but shader is a compute shader") \ + _SG_LOGITEM_XMACRO(VALIDATE_PIPELINEDESC_NO_CONT_ATTRS, "sg_pipeline_desc.layout.attrs is not continuous") \ + _SG_LOGITEM_XMACRO(VALIDATE_PIPELINEDESC_ATTR_BASETYPE_MISMATCH, "sg_pipeline_desc.layout.attrs[].format is incompatible with sg_shader_desc.attrs[].base_type") \ + _SG_LOGITEM_XMACRO(VALIDATE_PIPELINEDESC_ATTR_VERTEXFORMAT_INT10_N2_NOT_SUPPORTED, "sg_pipeline_desc.layout.attrs[].format: SG_VERTEXFORMAT_INT10_N2 not supported on this platform") \ + _SG_LOGITEM_XMACRO(VALIDATE_PIPELINEDESC_LAYOUT_STRIDE4, "sg_pipeline_desc.layout.buffers[].stride must be multiple of 4") \ + _SG_LOGITEM_XMACRO(VALIDATE_PIPELINEDESC_ATTR_SEMANTICS, "D3D11 missing vertex attribute semantics in shader") \ + _SG_LOGITEM_XMACRO(VALIDATE_PIPELINEDESC_SHADER_READONLY_STORAGEBUFFERS, "sg_pipeline_desc.shader: only readonly storage buffer bindings allowed in render pipelines") \ + _SG_LOGITEM_XMACRO(VALIDATE_PIPELINEDESC_BLENDOP_MINMAX_REQUIRES_BLENDFACTOR_ONE, "SG_BLENDOP_MIN/MAX requires all blend factors to be SG_BLENDFACTOR_ONE") \ + _SG_LOGITEM_XMACRO(VALIDATE_PIPELINEDESC_DUAL_SOURCE_BLENDING_NOT_SUPPORTED, "dual source blending not supported (sg_features.dual_source_blending)") \ + _SG_LOGITEM_XMACRO(VALIDATE_VIEWDESC_CANARY, "sg_view_desc not initialized") \ + _SG_LOGITEM_XMACRO(VALIDATE_VIEWDESC_UNIQUE_VIEWTYPE, "sg_view_desc: only one view type can be active") \ + _SG_LOGITEM_XMACRO(VALIDATE_VIEWDESC_ANY_VIEWTYPE, "sg_view_desc: exactly one view type must be active") \ + _SG_LOGITEM_XMACRO(VALIDATE_VIEWDESC_RESOURCE_ALIVE, "sg_view_desc: resource object is no longer alive (.buffer or .image)") \ + _SG_LOGITEM_XMACRO(VALIDATE_VIEWDESC_RESOURCE_FAILED, "sg_view_desc: resource object cannot be in FAILED state (.buffer or .image)") \ + _SG_LOGITEM_XMACRO(VALIDATE_VIEWDESC_STORAGEBUFFER_OFFSET_VS_BUFFER_SIZE, "sg_view_desc.storage_buffer.offset is >= buffer size") \ + _SG_LOGITEM_XMACRO(VALIDATE_VIEWDESC_STORAGEBUFFER_OFFSET_MULTIPLE_256, "sg_view_desc.storage_buffer.offset must be a multiple of 256") \ + _SG_LOGITEM_XMACRO(VALIDATE_VIEWDESC_STORAGEBUFFER_USAGE, "sg_view_desc.storage_buffer.buffer must have been created with sg_buffer_desc.usage.storage_buffer = true") \ + _SG_LOGITEM_XMACRO(VALIDATE_VIEWDESC_STORAGEIMAGE_USAGE, "sg_view_desc.storage_image.image must have been created with sg_image_desc.usage.storage_image = true") \ + _SG_LOGITEM_XMACRO(VALIDATE_VIEWDESC_COLORATTACHMENT_USAGE, "sg_view_desc.color_attachment.image must have been created with sg_image_desc.usage.color_attachment = true") \ + _SG_LOGITEM_XMACRO(VALIDATE_VIEWDESC_RESOLVEATTACHMENT_USAGE, "sg_view_desc.resolve_attachment.image must have been created with sg_image_desc.usage.resolve_attachment = true") \ + _SG_LOGITEM_XMACRO(VALIDATE_VIEWDESC_DEPTHSTENCILATTACHMENT_USAGE, "sg_view_desc.depth_stencil_attachment.image must have been created with sg_image_desc.usage.depth_stencil_attachment = true") \ + _SG_LOGITEM_XMACRO(VALIDATE_VIEWDESC_IMAGE_MIPLEVEL, "sg_view_desc: image/attachment view mip level is out of range (must be >=0 and =0 and <6)") \ + _SG_LOGITEM_XMACRO(VALIDATE_VIEWDESC_IMAGE_ARRAY_SLICE, "sg_view_desc: image/attachment view slice is out of range for 2D array image (must be >=0 and =0 and =0 and 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_EXPECT_WIDTH_NOTSET, "sg_begin_pass: expected pass.swapchain.width == 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_EXPECT_HEIGHT, "sg_begin_pass: expected pass.swapchain.height > 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_EXPECT_HEIGHT_NOTSET, "sg_begin_pass: expected pass.swapchain.height == 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_EXPECT_SAMPLECOUNT, "sg_begin_pass: expected pass.swapchain.sample_count > 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_EXPECT_SAMPLECOUNT_NOTSET, "sg_begin_pass: expected pass.swapchain.sample_count == 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_EXPECT_COLORFORMAT, "sg_begin_pass: expected pass.swapchain.color_format to be valid") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_EXPECT_COLORFORMAT_NOTSET, "sg_begin_pass: expected pass.swapchain.color_format to be unset") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_EXPECT_DEPTHFORMAT_NOTSET, "sg_begin_pass: expected pass.swapchain.depth_format to be unset") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_METAL_EXPECT_CURRENTDRAWABLE, "sg_begin_pass: expected pass.swapchain.metal.current_drawable != 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_METAL_EXPECT_CURRENTDRAWABLE_NOTSET, "sg_begin_pass: expected pass.swapchain.metal.current_drawable == 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_METAL_EXPECT_DEPTHSTENCILTEXTURE, "sg_begin_pass: expected pass.swapchain.metal.depth_stencil_texture != 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_METAL_EXPECT_DEPTHSTENCILTEXTURE_NOTSET, "sg_begin_pass: expected pass.swapchain.metal.depth_stencil_texture == 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_METAL_EXPECT_MSAACOLORTEXTURE, "sg_begin_pass: expected pass.swapchain.metal.msaa_color_texture != 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_METAL_EXPECT_MSAACOLORTEXTURE_NOTSET, "sg_begin_pass: expected pass.swapchain.metal.msaa_color_texture == 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_D3D11_EXPECT_RENDERVIEW, "sg_begin_pass: expected pass.swapchain.d3d11.render_view != 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_D3D11_EXPECT_RENDERVIEW_NOTSET, "sg_begin_pass: expected pass.swapchain.d3d11.render_view == 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_D3D11_EXPECT_RESOLVEVIEW, "sg_begin_pass: expected pass.swapchain.d3d11.resolve_view != 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_D3D11_EXPECT_RESOLVEVIEW_NOTSET, "sg_begin_pass: expected pass.swapchain.d3d11.resolve_view == 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_D3D11_EXPECT_DEPTHSTENCILVIEW, "sg_begin_pass: expected pass.swapchain.d3d11.depth_stencil_view != 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_D3D11_EXPECT_DEPTHSTENCILVIEW_NOTSET, "sg_begin_pass: expected pass.swapchain.d3d11.depth_stencil_view == 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_WGPU_EXPECT_RENDERVIEW, "sg_begin_pass: expected pass.swapchain.wgpu.render_view != 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_WGPU_EXPECT_RENDERVIEW_NOTSET, "sg_begin_pass: expected pass.swapchain.wgpu.render_view == 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_WGPU_EXPECT_RESOLVEVIEW, "sg_begin_pass: expected pass.swapchain.wgpu.resolve_view != 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_WGPU_EXPECT_RESOLVEVIEW_NOTSET, "sg_begin_pass: expected pass.swapchain.wgpu.resolve_view == 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_WGPU_EXPECT_DEPTHSTENCILVIEW, "sg_begin_pass: expected pass.swapchain.wgpu.depth_stencil_view != 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_WGPU_EXPECT_DEPTHSTENCILVIEW_NOTSET, "sg_begin_pass: expected pass.swapchain.wgpu.depth_stencil_view == 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_GL_EXPECT_FRAMEBUFFER_NOTSET, "sg_begin_pass: expected pass.swapchain.gl.framebuffer == 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_RENDERIMAGE, "sg_begin_pass: expected pass.swapchain.vk.render_image != 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_RENDERIMAGE_NOTSET, "sg_begin_pass: expected pass.swapchain.vk.render_image == 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_RENDERVIEW, "sg_begin_pass: expected pass.swapchain.vk.render_view != 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_RENDERVIEW_NOTSET, "sg_begin_pass: expected pass.swapchain.vk.render_view == 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_DEPTHSTENCILIMAGE, "sg_begin_pass: expected pass.swapchain.vk.depth_stencil_image != 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_DEPTHSTENCILIMAGE_NOTSET, "sg_begin_pass: expected pass.swapchain.vk.depth_stencil_image == 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_DEPTHSTENCILVIEW, "sg_begin_pass: expected pass.swapchain.vk.depth_stencil_view != 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_DEPTHSTENCILVIEW_NOTSET, "sg_begin_pass: expected pass.swapchain.vk.depth_stencil_view == 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_RESOLVEIMAGE, "sg_begin_pass: expected pass.swapchain.vk.resolve_image != 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_RESOLVEIMAGE_NOTSET, "sg_begin_pass: expected pass.swapchain.vk.resolve_image == 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_RESOLVEVIEW, "sg_begin_pass: expected pass.swapchain.vk.resolve_view != 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_RESOLVEVIEW_NOTSET, "sg_begin_pass: expected pass.swapchain.vk.resolve_view == 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_RENDERFINISHEDSEMAPHORE, "sg_begin_pass: expected pass.swapchain.vk.render_finished_semaphore != 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_RENDERFINISHEDSEMAPHORE_NOTSET, "sg_begin_pass: expected pass.swapchain.vk.render_finished_semaphore == 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_PRESENTCOMPLETESEMAPHORE, "sg_begin_pass: expected pass.swapchain.vk.present_complete_semaphore != 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_PRESENTCOMPLETESEMAPHORE_NOTSET, "sg_begin_pass: expected pass.swapchain.vk.present_complete_semaphore == 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_COLORATTACHMENTVIEWS_CONTINUOUS, "sg_begin_pass: color attachment view array must be continuous") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_COLORATTACHMENTVIEW_ALIVE, "sg_begin_pass: color attachment view no longer alive") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_COLORATTACHMENTVIEW_VALID, "sg_begin_pass: color attachment view not in valid state (SG_RESOURCESTATE_VALID)") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_COLORATTACHMENTVIEW_TYPE, "sg_begin_pass: color attachment view has wrong type (must be sg_view_desc.color_attachment)") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_COLORATTACHMENTVIEW_IMAGE_ALIVE, "sg_begin_pass: color attachment view's image object is uninitialized or no longer alive") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_COLORATTACHMENTVIEW_IMAGE_VALID, "sg_begin_pass: color attachment view's image is not in valid state (SG_RESOURCESTATE_VALID)") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_COLORATTACHMENTVIEW_SIZES, "sg_begin_pass: all color attachments must have the same width and height") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_COLORATTACHMENTVIEW_SAMPLECOUNT, "sg_begin_pass: when resolve attachments are provided, the color attachment sample count must be > 1") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_COLORATTACHMENTVIEW_SAMPLECOUNTS_EQUAL, "sg_begin_pass: all color attachments must have the same sample count") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_RESOLVEATTACHMENTVIEW_NO_COLORATTACHMENTVIEW, "sg_begin_pass: a resolve attachment view must have an associated color attachment view at the same index") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_RESOLVEATTACHMENTVIEW_ALIVE, "sg_begin_pass: resolve attachment view no longer alive") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_RESOLVEATTACHMENTVIEW_VALID, "sg_begin_pass: resolve attachment view not in valid state (SG_RESOURCESTATE_VALID)") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_RESOLVEATTACHMENTVIEW_TYPE, "sg_begin_pass: resolve attachment view has wrong type (must be sg_view_desc.resolve_attachment)") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_RESOLVEATTACHMENTVIEW_IMAGE_ALIVE, "sg_begin_pass: resolve attachment view's image object is uninitialized or no longer alive") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_RESOLVEATTACHMENTVIEW_IMAGE_VALID, "sg_begin_pass: resolve attachment view's image is not in valid state (SG_RESOURCESTATE_VALID)") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_RESOLVEATTACHMENTVIEW_SIZES, "sg_begin_pass: all attachments must have the same width and height") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_DEPTHSTENCILATTACHMENTVIEWS_CONTINUOUS, "sg_begin_pass: color attachment view array must be continuous") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_DEPTHSTENCILATTACHMENTVIEW_ALIVE, "sg_begin_pass: depth-stencil attachment view no longer alive") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_DEPTHSTENCILATTACHMENTVIEW_VALID, "sg_begin_pass: depth-stencil attachment view not in valid state (SG_RESOURCESTATE_VALID)") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_DEPTHSTENCILATTACHMENTVIEW_TYPE, "sg_begin_pass: depth-stencil attachment view has wrong type (must be sg_view_desc.depth_stencil_attachment)") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_DEPTHSTENCILATTACHMENTVIEW_IMAGE_ALIVE, "sg_begin_pass: depth-stencil attachment view's image object is uninitialized or no longer alive") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_DEPTHSTENCILATTACHMENTVIEW_IMAGE_VALID, "sg_begin_pass: depth-stencil attachment view's image is not in valid state (SG_RESOURCESTATE_VALID)") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_DEPTHSTENCILATTACHMENTVIEW_SIZES, "sg_begin_pass: attachments must have the same width and height") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_DEPTHSTENCILATTACHMENTVIEW_SAMPLECOUNT, "sg_begin_pass: all color attachments must have the same sample count") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_ATTACHMENTS_EXPECTED, "sg_begin_pass: offscreen render passes must have at least one color- or depth-stencil attachment") \ + _SG_LOGITEM_XMACRO(VALIDATE_AVP_RENDERPASS_EXPECTED, "sg_apply_viewport: must be called in a render pass") \ + _SG_LOGITEM_XMACRO(VALIDATE_ASR_RENDERPASS_EXPECTED, "sg_apply_scissor_rect: must be called in a render pass") \ + _SG_LOGITEM_XMACRO(VALIDATE_APIP_PIPELINE_VALID_ID, "sg_apply_pipeline: invalid pipeline id provided") \ + _SG_LOGITEM_XMACRO(VALIDATE_APIP_PIPELINE_EXISTS, "sg_apply_pipeline: pipeline object no longer alive") \ + _SG_LOGITEM_XMACRO(VALIDATE_APIP_PIPELINE_VALID, "sg_apply_pipeline: pipeline object not in valid state (SG_RESOURCESTATE_VALID)") \ + _SG_LOGITEM_XMACRO(VALIDATE_APIP_PASS_EXPECTED, "sg_apply_pipeline: must be called in a pass") \ + _SG_LOGITEM_XMACRO(VALIDATE_APIP_PIPELINE_SHADER_ALIVE, "sg_apply_pipeline: shader object associated with pipeline no longer alive") \ + _SG_LOGITEM_XMACRO(VALIDATE_APIP_PIPELINE_SHADER_VALID, "sg_apply_pipeline: shader object associated with pipeline not in valid state") \ + _SG_LOGITEM_XMACRO(VALIDATE_APIP_COMPUTEPASS_EXPECTED, "sg_apply_pipeline: trying to apply compute pipeline in render pass") \ + _SG_LOGITEM_XMACRO(VALIDATE_APIP_RENDERPASS_EXPECTED, "sg_apply_pipeline: trying to apply render pipeline in compute pass") \ + _SG_LOGITEM_XMACRO(VALIDATE_APIP_SWAPCHAIN_COLOR_COUNT, "sg_apply_pipeline: the pipeline .color_count must be 1 in swapchain render passes") \ + _SG_LOGITEM_XMACRO(VALIDATE_APIP_SWAPCHAIN_COLOR_FORMAT, "sg_apply_pipeline: the pipeline .colors[0].pixel_format doesn't match the sg_pass.swapchain.color_format") \ + _SG_LOGITEM_XMACRO(VALIDATE_APIP_SWAPCHAIN_DEPTH_FORMAT, "sg_apply_pipeline: the pipeline .depth.pixel_format doesn't match the sg_pass.swapchain.depth_format") \ + _SG_LOGITEM_XMACRO(VALIDATE_APIP_SWAPCHAIN_SAMPLE_COUNT, "sg_apply_pipeline: the pipeline .sample_count doesn't match the sg_pass.swapchain.sample_count") \ + _SG_LOGITEM_XMACRO(VALIDATE_APIP_ATTACHMENTS_ALIVE, "sg_apply_pipeline: at least one pass attachment view or base image object is no longer alive") \ + _SG_LOGITEM_XMACRO(VALIDATE_APIP_COLORATTACHMENTS_COUNT, "sg_apply_pipeline: the pipeline .color_count doesn't match the number of render pass color attachments") \ + _SG_LOGITEM_XMACRO(VALIDATE_APIP_COLORATTACHMENTS_VIEW_VALID, "sg_apply_pipeline: a pass color attachment view is not in valid state (SG_RESOURCESTATE_VALID)") \ + _SG_LOGITEM_XMACRO(VALIDATE_APIP_COLORATTACHMENTS_IMAGE_VALID, "sg_apply_pipeline: a pass color attachment view's image object is not in valid state (SG_RESOURCESTATE_VALID)") \ + _SG_LOGITEM_XMACRO(VALIDATE_APIP_COLORATTACHMENTS_FORMAT, "sg_apply_pipeline: a pipeline .colors[n].pixel_format doesn't match sg_pass.attachments.colors[n] image pixel format") \ + _SG_LOGITEM_XMACRO(VALIDATE_APIP_DEPTHSTENCILATTACHMENT_VIEW_VALID, "sg_apply_pipeline: the pass depth-stencil attachment view is not in valid state (SG_RESOURCESTATE_VALID)") \ + _SG_LOGITEM_XMACRO(VALIDATE_APIP_DEPTHSTENCILATTACHMENT_IMAGE_VALID, "sg_apply_pipeline: the pass depth-stencil attachment view's image object is not in valid state (SG_RESOURCESTATE_VALID)") \ + _SG_LOGITEM_XMACRO(VALIDATE_APIP_DEPTHSTENCILATTACHMENT_FORMAT, "sg_apply_pipeline: pipeline .depth.pixel_format doesn't match sg_pass.attachments.depth_stencil image pixel format") \ + _SG_LOGITEM_XMACRO(VALIDATE_APIP_ATTACHMENT_SAMPLE_COUNT, "sg_apply_pipeline: pipeline MSAA sample count doesn't match pass attachment sample count") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_PASS_EXPECTED, "sg_apply_bindings: must be called in a pass") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_EMPTY_BINDINGS, "sg_apply_bindings: the provided sg_bindings struct is empty") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_NO_PIPELINE, "sg_apply_bindings: must be called after sg_apply_pipeline") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_PIPELINE_ALIVE, "sg_apply_bindings: currently applied pipeline object no longer alive") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_PIPELINE_VALID, "sg_apply_bindings: currently applied pipeline object not in valid state") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_PIPELINE_SHADER_ALIVE, "sg_apply_bindings: shader associated with currently applied pipeline is no longer alive") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_PIPELINE_SHADER_VALID, "sg_apply_bindings: shader associated with currently applied pipeline is not in valid state") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_COMPUTE_EXPECTED_NO_VBUFS, "sg_apply_bindings: vertex buffer bindings not allowed in a compute pass") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_COMPUTE_EXPECTED_NO_IBUF, "sg_apply_bindings: index buffer binding not allowed in compute pass") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_EXPECTED_VBUF, "sg_apply_bindings: vertex buffer binding is missing or buffer handle is invalid") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_VBUF_ALIVE, "sg_apply_bindings: vertex buffer no longer alive") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_VBUF_USAGE, "sg_apply_bindings: buffer in vertex buffer bind slot must have usage.vertex_buffer") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_VBUF_OVERFLOW, "sg_apply_bindings: buffer in vertex buffer bind slot is overflown") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_EXPECTED_NO_IBUF, "sg_apply_bindings: pipeline object defines non-indexed rendering, but index buffer binding provided") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_EXPECTED_IBUF, "sg_apply_bindings: pipeline object defines indexed rendering, but no index buffer binding provided") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_IBUF_ALIVE, "sg_apply_bindings: index buffer no longer alive") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_IBUF_USAGE, "sg_apply_bindings: buffer in index buffer bind slot must have usage.index_buffer") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_IBUF_OVERFLOW, "sg_apply_bindings: buffer in index buffer slot is overflown") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_EXPECTED_VIEW_BINDING, "sg_apply_bindings: view binding is missing or the view handle is invalid") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_VIEW_ALIVE, "sg_apply_bindings: view no longer alive") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_EXPECT_TEXVIEW, "sg_apply_bindings: view type mismatch in bindslot (shader expects a texture view)") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_EXPECT_SBVIEW, "sg_apply_bindings: view type mismatch in bindslot (shader expects a storage buffer view)") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_EXPECT_SIMGVIEW, "sg_apply_bindings: view type mismatch in bindslot (shader expects a storage image view)") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_TEXVIEW_IMAGETYPE_MISMATCH, "sg_apply_bindings: image type of bound texture doesn't match shader desc") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_TEXVIEW_EXPECTED_MULTISAMPLED_IMAGE, "sg_apply_bindings: texture bindings expects image with sample_count > 1") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_TEXVIEW_EXPECTED_NON_MULTISAMPLED_IMAGE, "sg_apply_bindings: texture bindings expects image with sample_count == 1") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_TEXVIEW_EXPECTED_FILTERABLE_IMAGE, "sg_apply_bindings: filterable image expected") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_TEXVIEW_EXPECTED_DEPTH_IMAGE, "sg_apply_bindings: depth image expected") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_SBVIEW_READWRITE_IMMUTABLE, "sg_apply_bindings: storage buffers bound as read/write must have usage immutable") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_SIMGVIEW_COMPUTE_PASS_EXPECTED, "sg_apply_bindings: storage image bindings can only appear on compute passes") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_SIMGVIEW_IMAGETYPE_MISMATCH, "sg_apply_bindings: image type of bound storage image doesn't match shader desc") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_SIMGVIEW_ACCESSFORMAT, "sg_apply_bindings: pixel format of storage image view doesn't match access format in shader desc") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_EXPECTED_SAMPLER_BINDING, "sg_apply_bindings: sampler binding is missing or the sampler handle is invalid") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_UNEXPECTED_SAMPLER_COMPARE_NEVER, "sg_apply_bindings: shader expects SG_SAMPLERTYPE_COMPARISON but sampler has SG_COMPAREFUNC_NEVER") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_EXPECTED_SAMPLER_COMPARE_NEVER, "sg_apply_bindings: shader expects SG_SAMPLERTYPE_FILTERING or SG_SAMPLERTYPE_NONFILTERING but sampler doesn't have SG_COMPAREFUNC_NEVER") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_EXPECTED_NONFILTERING_SAMPLER, "sg_apply_bindings: shader expected SG_SAMPLERTYPE_NONFILTERING, but sampler has SG_FILTER_LINEAR filters") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_SAMPLER_ALIVE, "sg_apply_bindings: bound sampler no longer alive") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_SAMPLER_VALID, "sg_apply_bindings: bound sampler not in valid state") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_TEXTURE_BINDING_VS_DEPTHSTENCIL_ATTACHMENT, "sg_apply_bindings: cannot bind texture in the same pass it is used as depth-stencil attachment") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_TEXTURE_BINDING_VS_COLOR_ATTACHMENT, "sg_apply_bindings: cannot bind texture in the same pass it is used as color attachment") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_TEXTURE_BINDING_VS_RESOLVE_ATTACHMENT, "sg_apply_bindings: cannot bind texture in the same pass it is used as resolve attachment") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_TEXTURE_VS_STORAGEIMAGE_BINDING, "sg_apply_bindings: an image cannot be bound as a texture and storage image at the same time") \ + _SG_LOGITEM_XMACRO(VALIDATE_AU_PASS_EXPECTED, "sg_apply_uniforms: must be called in a pass") \ + _SG_LOGITEM_XMACRO(VALIDATE_AU_NO_PIPELINE, "sg_apply_uniforms: must be called after sg_apply_pipeline()") \ + _SG_LOGITEM_XMACRO(VALIDATE_AU_PIPELINE_ALIVE, "sg_apply_uniforms: currently applied pipeline object no longer alive") \ + _SG_LOGITEM_XMACRO(VALIDATE_AU_PIPELINE_VALID, "sg_apply_uniforms: currently applied pipeline object not in valid state") \ + _SG_LOGITEM_XMACRO(VALIDATE_AU_PIPELINE_SHADER_ALIVE, "sg_apply_uniforms: shader associated with currently applied pipeline is no longer alive") \ + _SG_LOGITEM_XMACRO(VALIDATE_AU_PIPELINE_SHADER_VALID, "sg_apply_uniforms: shader associated with currently applied pipeline is not in valid state") \ + _SG_LOGITEM_XMACRO(VALIDATE_AU_NO_UNIFORMBLOCK_AT_SLOT, "sg_apply_uniforms: no uniform block declaration at this shader stage UB slot") \ + _SG_LOGITEM_XMACRO(VALIDATE_AU_SIZE, "sg_apply_uniforms: data size doesn't match declared uniform block size") \ + _SG_LOGITEM_XMACRO(VALIDATE_DRAW_RENDERPASS_EXPECTED, "sg_draw: must be called in a render pass") \ + _SG_LOGITEM_XMACRO(VALIDATE_DRAW_BASEELEMENT_GE_ZERO, "sg_draw: base_element cannot be < 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_DRAW_NUMELEMENTS_GE_ZERO, "sg_draw: num_elements cannot be < 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_DRAW_NUMINSTANCES_GE_ZERO, "sg_draw: num_instances cannot be < 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_DRAW_EX_RENDERPASS_EXPECTED, "sg_draw: must be called in a render pass") \ + _SG_LOGITEM_XMACRO(VALIDATE_DRAW_EX_BASEELEMENT_GE_ZERO, "sg_draw_ex: base_element cannot be < 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_DRAW_EX_NUMELEMENTS_GE_ZERO, "sg_draw_ex: num_elements cannot be < 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_DRAW_EX_NUMINSTANCES_GE_ZERO, "sg_draw_ex: num_instances cannot be < 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_DRAW_EX_BASEINSTANCE_GE_ZERO, "sg_draw_ex: base_instance cannot be < 0") \ + _SG_LOGITEM_XMACRO(VALIDATE_DRAW_EX_BASEVERTEX_VS_INDEXED, "sg_draw_ex(): base_vertex must be == 0 for non-indexed rendering") \ + _SG_LOGITEM_XMACRO(VALIDATE_DRAW_EX_BASEINSTANCE_VS_INSTANCED, "sg_draw_ex(): base_instance must be == 0 for non-instanced rendering") \ + _SG_LOGITEM_XMACRO(VALIDATE_DRAW_EX_BASEVERTEX_NOT_SUPPORTED, "sg_draw_ex(): base_vertex != 0 not supported on this backend (sg_features.draw_base_vertex)") \ + _SG_LOGITEM_XMACRO(VALIDATE_DRAW_EX_BASEINSTANCE_NOT_SUPPORTED, "sg_draw_ex(): base_instance > 0 not supported on this backend (sg_features.draw_base_instance)") \ + _SG_LOGITEM_XMACRO(VALIDATE_DRAW_REQUIRED_BINDINGS_OR_UNIFORMS_MISSING, "sg_draw: call to sg_apply_bindings() and/or sg_apply_uniforms() missing after sg_apply_pipeline()") \ + _SG_LOGITEM_XMACRO(VALIDATE_DISPATCH_COMPUTEPASS_EXPECTED, "sg_dispatch: must be called in a compute pass") \ + _SG_LOGITEM_XMACRO(VALIDATE_DISPATCH_NUMGROUPSX, "sg_dispatch: num_groups_x must be >=0 and <65536") \ + _SG_LOGITEM_XMACRO(VALIDATE_DISPATCH_NUMGROUPSY, "sg_dispatch: num_groups_y must be >=0 and <65536") \ + _SG_LOGITEM_XMACRO(VALIDATE_DISPATCH_NUMGROUPSZ, "sg_dispatch: num_groups_z must be >=0 and <65536") \ + _SG_LOGITEM_XMACRO(VALIDATE_DISPATCH_REQUIRED_BINDINGS_OR_UNIFORMS_MISSING, "sg_dispatch: call to sg_apply_bindings() and/or sg_apply_uniforms() missing after sg_apply_pipeline()") \ + _SG_LOGITEM_XMACRO(VALIDATE_UPDATEBUF_USAGE, "sg_update_buffer: cannot update immutable buffer") \ + _SG_LOGITEM_XMACRO(VALIDATE_UPDATEBUF_SIZE, "sg_update_buffer: update size is bigger than buffer size") \ + _SG_LOGITEM_XMACRO(VALIDATE_UPDATEBUF_ONCE, "sg_update_buffer: only one update allowed per buffer and frame") \ + _SG_LOGITEM_XMACRO(VALIDATE_UPDATEBUF_APPEND, "sg_update_buffer: cannot call sg_update_buffer and sg_append_buffer in same frame") \ + _SG_LOGITEM_XMACRO(VALIDATE_APPENDBUF_USAGE, "sg_append_buffer: cannot append to immutable buffer") \ + _SG_LOGITEM_XMACRO(VALIDATE_APPENDBUF_SIZE, "sg_append_buffer: overall appended size is bigger than buffer size") \ + _SG_LOGITEM_XMACRO(VALIDATE_APPENDBUF_UPDATE, "sg_append_buffer: cannot call sg_append_buffer and sg_update_buffer in same frame") \ + _SG_LOGITEM_XMACRO(VALIDATE_UPDIMG_USAGE, "sg_update_image: cannot update immutable image") \ + _SG_LOGITEM_XMACRO(VALIDATE_UPDIMG_ONCE, "sg_update_image: only one update allowed per image and frame") \ + _SG_LOGITEM_XMACRO(VALIDATION_FAILED, "validation layer checks failed") \ + +#define _SG_LOGITEM_XMACRO(item,msg) SG_LOGITEM_##item, +typedef enum sg_log_item { + _SG_LOG_ITEMS +} sg_log_item; +#undef _SG_LOGITEM_XMACRO + +/* + sg_desc + + The sg_desc struct contains configuration values for sokol_gfx, + it is used as parameter to the sg_setup() call. + + The default configuration is: + + .buffer_pool_size 128 + .image_pool_size 128 + .sampler_pool_size 64 + .shader_pool_size 32 + .pipeline_pool_size 64 + .view_pool_size 256 + .uniform_buffer_size 4 MB (4*1024*1024) + .max_commit_listeners 1024 + .disable_validation false + .metal.force_managed_storage_mode false + .metal.use_command_buffer_with_retained_references false + .wgpu.disable_bindgroups_cache false + .wgpu.bindgroups_cache_size 1024 + .vulkan.copy_staging_buffer_size 4 MB + .vulkan.stream_staging_buffer_size 16 MB + .vulkan.descriptor_buffer_size 16 MB + + .allocator.alloc_fn 0 (in this case, malloc() will be called) + .allocator.free_fn 0 (in this case, free() will be called) + .allocator.user_data 0 + + .environment.defaults.color_format: default value depends on selected backend: + all GL backends: SG_PIXELFORMAT_RGBA8 + Metal and D3D11: SG_PIXELFORMAT_BGRA8 + WebGPU: *no default* (must be queried from WebGPU swapchain object) + .environment.defaults.depth_format: SG_PIXELFORMAT_DEPTH_STENCIL + .environment.defaults.sample_count: 1 + + Metal specific: + (NOTE: All Objective-C object references are transferred through + a bridged cast (__bridge const void*) to sokol_gfx, which will use an + unretained bridged cast (__bridge id) to retrieve the Objective-C + references back. Since the bridge cast is unretained, the caller + must hold a strong reference to the Objective-C object until sg_setup() + returns. + + .metal.force_managed_storage_mode + when enabled, Metal buffers and texture resources are created in managed storage + mode, otherwise sokol-gfx will decide whether to create buffers and + textures in managed or shared storage mode (this is mainly a debugging option) + .metal.use_command_buffer_with_retained_references + when true, the sokol-gfx Metal backend will use Metal command buffers which + bump the reference count of resource objects as long as they are inflight, + this is slower than the default command-buffer-with-unretained-references + method, this may be a workaround when confronted with lifetime validation + errors from the Metal validation layer until a proper fix has been implemented + .environment.metal.device + a pointer to the MTLDevice object + + D3D11 specific: + .environment.d3d11.device + a pointer to the ID3D11Device object, this must have been created + before sg_setup() is called + .environment.d3d11.device_context + a pointer to the ID3D11DeviceContext object + .d3d11.shader_debugging + set this to true to compile shaders which are provided as HLSL source + code with debug information and without optimization, this allows + shader debugging in tools like RenderDoc, to output source code + instead of byte code from sokol-shdc, omit the `--binary` cmdline + option + + WebGPU specific: + .wgpu.disable_bindgroups_cache + When this is true, the WebGPU backend will create and immediately + release a BindGroup object in the sg_apply_bindings() call, only + use this for debugging purposes. + .wgpu.bindgroups_cache_size + The size of the bindgroups cache for re-using BindGroup objects + between sg_apply_bindings() calls. The smaller the cache size, + the more likely are cache slot collisions which will cause + a BindGroups object to be destroyed and a new one created. + Use the information returned by sg_query_stats() to check + if this is a frequent occurrence, and increase the cache size as + needed (the default is 1024). + NOTE: wgpu_bindgroups_cache_size must be a power-of-2 number! + .environment.wgpu.device + a WGPUDevice handle + + Vulkan specific: + .vulkan.copy_staging_buffer_size + Size of the staging buffer in bytes for uploading the initial + content of buffers and images, and for updating + .usage.dynamic_update resources. The default is 4 MB, + bigger resource updates are split into multiple chunks + of the staging buffer size + .vulkan.stream_staging_buffer_size + Size of the staging buffer in bytes for updating .usage.stream_update + resources. The default is 16 MB. The size must be big enough + to accomodate all update into .usage.stream_update resources. + Any additional data will cause an error log message and + incomplete rendering. Note that the actually allocated size + will be twice as much because the stream-staging-buffer is + double-buffered. + .vulkan.descriptor_buffer_size + Size of the descriptor-upload buffer in bytes. The default + size is 16 bytes. The size must be big enough to accomodate + all unifrom-block, view- and sampler-bindings in a single + frame (assume a worst-case of 256 bytes per binding). Note + that the actually allocated size will be twice as much + because the descriptor-buffer is double-buffered. + + When using sokol_gfx.h and sokol_app.h together, consider using the + helper function sglue_environment() in the sokol_glue.h header to + initialize the sg_desc.environment nested struct. sglue_environment() returns + a completely initialized sg_environment struct with information + provided by sokol_app.h. +*/ +typedef struct sg_environment_defaults { + sg_pixel_format color_format; + sg_pixel_format depth_format; + int sample_count; +} sg_environment_defaults; + +typedef struct sg_metal_environment { + const void* device; +} sg_metal_environment; + +typedef struct sg_d3d11_environment { + const void* device; + const void* device_context; +} sg_d3d11_environment; + +typedef struct sg_wgpu_environment { + const void* device; +} sg_wgpu_environment; + +typedef struct sg_vulkan_environment { + const void* instance; + const void* physical_device; + const void* device; + const void* queue; + uint32_t queue_family_index; +} sg_vulkan_environment; + +typedef struct sg_environment { + sg_environment_defaults defaults; + sg_metal_environment metal; + sg_d3d11_environment d3d11; + sg_wgpu_environment wgpu; + sg_vulkan_environment vulkan; +} sg_environment; + +/* + sg_commit_listener + + Used with function sg_add_commit_listener() to add a callback + which will be called in sg_commit(). This is useful for libraries + building on top of sokol-gfx to be notified about when a frame + ends (instead of having to guess, or add a manual 'new-frame' + function. +*/ +typedef struct sg_commit_listener { + void (*func)(void* user_data); + void* user_data; +} sg_commit_listener; + +/* + sg_allocator + + Used in sg_desc to provide custom memory-alloc and -free functions + to sokol_gfx.h. If memory management should be overridden, both the + alloc_fn and free_fn function must be provided (e.g. it's not valid to + override one function but not the other). +*/ +typedef struct sg_allocator { + void* (*alloc_fn)(size_t size, void* user_data); + void (*free_fn)(void* ptr, void* user_data); + void* user_data; +} sg_allocator; + +/* + sg_logger + + Used in sg_desc to provide a logging function. Please be aware + that without logging function, sokol-gfx will be completely + silent, e.g. it will not report errors, warnings and + validation layer messages. For maximum error verbosity, + compile in debug mode (e.g. NDEBUG *not* defined) and provide a + compatible logger function in the sg_setup() call + (for instance the standard logging function from sokol_log.h). +*/ +typedef struct sg_logger { + void (*func)( + const char* tag, // always "sg" + uint32_t log_level, // 0=panic, 1=error, 2=warning, 3=info + uint32_t log_item_id, // SG_LOGITEM_* + const char* message_or_null, // a message string, may be nullptr in release mode + uint32_t line_nr, // line number in sokol_gfx.h + const char* filename_or_null, // source filename, may be nullptr in release mode + void* user_data); + void* user_data; +} sg_logger; + +typedef struct sg_d3d11_desc { + bool shader_debugging; // if true, HLSL shaders are compiled with D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION +} sg_d3d11_desc; + +typedef struct sg_metal_desc { + bool force_managed_storage_mode; // for debugging: use Metal managed storage mode for resources even with UMA + bool use_command_buffer_with_retained_references; // Metal: use a managed MTLCommandBuffer which ref-counts used resources +} sg_metal_desc; + +typedef struct sg_wgpu_desc { + bool disable_bindgroups_cache; // set to true to disable the WebGPU backend BindGroup cache + int bindgroups_cache_size; // number of slots in the WebGPU bindgroup cache (must be 2^N) +} sg_wgpu_desc; + +typedef struct sg_vulkan_desc { + int copy_staging_buffer_size; // size of staging buffer for immutable and dynamic resources (default: 4 MB) + int stream_staging_buffer_size; // size of per-frame staging buffer for updating streaming resources (default: 16 MB) + int descriptor_buffer_size; // size of per-frame descriptor buffer for updating resource bindings (default: 16 MB) +} sg_vulkan_desc; + +typedef struct sg_desc { + uint32_t _start_canary; + int buffer_pool_size; + int image_pool_size; + int sampler_pool_size; + int shader_pool_size; + int pipeline_pool_size; + int view_pool_size; + int uniform_buffer_size; // max size of all sg_apply_uniform() calls per frame, with worst-case 256 byte alignment + int max_commit_listeners; // max number of commit listener hook functions + bool disable_validation; // disable validation layer even in debug mode, useful for tests + bool enforce_portable_limits; // if true, enforce portable resource binding limits (SG_MAX_PORTABLE_*) + sg_d3d11_desc d3d11; // d3d11-specific setup parameters + sg_metal_desc metal; // metal-specific setup parameters + sg_wgpu_desc wgpu; // webgpu-specific setup parameters + sg_vulkan_desc vulkan; // vulkan-specific setup parameters + sg_allocator allocator; // optional memory allocation hooks + sg_logger logger; // optional log function override + sg_environment environment; // required externally provided runtime objects and defaults + uint32_t _end_canary; +} sg_desc; + +// setup and misc functions +SOKOL_GFX_API_DECL void sg_setup(const sg_desc* desc); +SOKOL_GFX_API_DECL void sg_shutdown(void); +SOKOL_GFX_API_DECL bool sg_isvalid(void); +SOKOL_GFX_API_DECL void sg_reset_state_cache(void); +SOKOL_GFX_API_DECL sg_trace_hooks sg_install_trace_hooks(const sg_trace_hooks* trace_hooks); +SOKOL_GFX_API_DECL void sg_push_debug_group(const char* name); +SOKOL_GFX_API_DECL void sg_pop_debug_group(void); +SOKOL_GFX_API_DECL bool sg_add_commit_listener(sg_commit_listener listener); +SOKOL_GFX_API_DECL bool sg_remove_commit_listener(sg_commit_listener listener); + +// resource creation, destruction and updating +SOKOL_GFX_API_DECL sg_buffer sg_make_buffer(const sg_buffer_desc* desc); +SOKOL_GFX_API_DECL sg_image sg_make_image(const sg_image_desc* desc); +SOKOL_GFX_API_DECL sg_sampler sg_make_sampler(const sg_sampler_desc* desc); +SOKOL_GFX_API_DECL sg_shader sg_make_shader(const sg_shader_desc* desc); +SOKOL_GFX_API_DECL sg_pipeline sg_make_pipeline(const sg_pipeline_desc* desc); +SOKOL_GFX_API_DECL sg_view sg_make_view(const sg_view_desc* desc); +SOKOL_GFX_API_DECL void sg_destroy_buffer(sg_buffer buf); +SOKOL_GFX_API_DECL void sg_destroy_image(sg_image img); +SOKOL_GFX_API_DECL void sg_destroy_sampler(sg_sampler smp); +SOKOL_GFX_API_DECL void sg_destroy_shader(sg_shader shd); +SOKOL_GFX_API_DECL void sg_destroy_pipeline(sg_pipeline pip); +SOKOL_GFX_API_DECL void sg_destroy_view(sg_view view); +SOKOL_GFX_API_DECL void sg_update_buffer(sg_buffer buf, const sg_range* data); +SOKOL_GFX_API_DECL void sg_update_image(sg_image img, const sg_image_data* data); +SOKOL_GFX_API_DECL int sg_append_buffer(sg_buffer buf, const sg_range* data); +SOKOL_GFX_API_DECL bool sg_query_buffer_overflow(sg_buffer buf); +SOKOL_GFX_API_DECL bool sg_query_buffer_will_overflow(sg_buffer buf, size_t size); + +// render and compute functions +SOKOL_GFX_API_DECL void sg_begin_pass(const sg_pass* pass); +SOKOL_GFX_API_DECL void sg_apply_viewport(int x, int y, int width, int height, bool origin_top_left); +SOKOL_GFX_API_DECL void sg_apply_viewportf(float x, float y, float width, float height, bool origin_top_left); +SOKOL_GFX_API_DECL void sg_apply_scissor_rect(int x, int y, int width, int height, bool origin_top_left); +SOKOL_GFX_API_DECL void sg_apply_scissor_rectf(float x, float y, float width, float height, bool origin_top_left); +SOKOL_GFX_API_DECL void sg_apply_pipeline(sg_pipeline pip); +SOKOL_GFX_API_DECL void sg_apply_bindings(const sg_bindings* bindings); +SOKOL_GFX_API_DECL void sg_apply_uniforms(int ub_slot, const sg_range* data); +SOKOL_GFX_API_DECL void sg_draw(int base_element, int num_elements, int num_instances); +SOKOL_GFX_API_DECL void sg_draw_ex(int base_element, int num_elements, int num_instances, int base_vertex, int base_instance); +SOKOL_GFX_API_DECL void sg_dispatch(int num_groups_x, int num_groups_y, int num_groups_z); +SOKOL_GFX_API_DECL void sg_end_pass(void); +SOKOL_GFX_API_DECL void sg_commit(void); + +// getting information +SOKOL_GFX_API_DECL sg_desc sg_query_desc(void); +SOKOL_GFX_API_DECL sg_backend sg_query_backend(void); +SOKOL_GFX_API_DECL sg_features sg_query_features(void); +SOKOL_GFX_API_DECL sg_limits sg_query_limits(void); +SOKOL_GFX_API_DECL sg_pixelformat_info sg_query_pixelformat(sg_pixel_format fmt); +SOKOL_GFX_API_DECL int sg_query_row_pitch(sg_pixel_format fmt, int width, int row_align_bytes); +SOKOL_GFX_API_DECL int sg_query_surface_pitch(sg_pixel_format fmt, int width, int height, int row_align_bytes); +// get current state of a resource (INITIAL, ALLOC, VALID, FAILED, INVALID) +SOKOL_GFX_API_DECL sg_resource_state sg_query_buffer_state(sg_buffer buf); +SOKOL_GFX_API_DECL sg_resource_state sg_query_image_state(sg_image img); +SOKOL_GFX_API_DECL sg_resource_state sg_query_sampler_state(sg_sampler smp); +SOKOL_GFX_API_DECL sg_resource_state sg_query_shader_state(sg_shader shd); +SOKOL_GFX_API_DECL sg_resource_state sg_query_pipeline_state(sg_pipeline pip); +SOKOL_GFX_API_DECL sg_resource_state sg_query_view_state(sg_view view); +// get runtime information about a resource +SOKOL_GFX_API_DECL sg_buffer_info sg_query_buffer_info(sg_buffer buf); +SOKOL_GFX_API_DECL sg_image_info sg_query_image_info(sg_image img); +SOKOL_GFX_API_DECL sg_sampler_info sg_query_sampler_info(sg_sampler smp); +SOKOL_GFX_API_DECL sg_shader_info sg_query_shader_info(sg_shader shd); +SOKOL_GFX_API_DECL sg_pipeline_info sg_query_pipeline_info(sg_pipeline pip); +SOKOL_GFX_API_DECL sg_view_info sg_query_view_info(sg_view view); +// get desc structs matching a specific resource (NOTE that not all creation attributes may be provided) +SOKOL_GFX_API_DECL sg_buffer_desc sg_query_buffer_desc(sg_buffer buf); +SOKOL_GFX_API_DECL sg_image_desc sg_query_image_desc(sg_image img); +SOKOL_GFX_API_DECL sg_sampler_desc sg_query_sampler_desc(sg_sampler smp); +SOKOL_GFX_API_DECL sg_shader_desc sg_query_shader_desc(sg_shader shd); +SOKOL_GFX_API_DECL sg_pipeline_desc sg_query_pipeline_desc(sg_pipeline pip); +SOKOL_GFX_API_DECL sg_view_desc sg_query_view_desc(sg_view view); +// get resource creation desc struct with their default values replaced +SOKOL_GFX_API_DECL sg_buffer_desc sg_query_buffer_defaults(const sg_buffer_desc* desc); +SOKOL_GFX_API_DECL sg_image_desc sg_query_image_defaults(const sg_image_desc* desc); +SOKOL_GFX_API_DECL sg_sampler_desc sg_query_sampler_defaults(const sg_sampler_desc* desc); +SOKOL_GFX_API_DECL sg_shader_desc sg_query_shader_defaults(const sg_shader_desc* desc); +SOKOL_GFX_API_DECL sg_pipeline_desc sg_query_pipeline_defaults(const sg_pipeline_desc* desc); +SOKOL_GFX_API_DECL sg_view_desc sg_query_view_defaults(const sg_view_desc* desc); +// assorted query functions +SOKOL_GFX_API_DECL size_t sg_query_buffer_size(sg_buffer buf); +SOKOL_GFX_API_DECL sg_buffer_usage sg_query_buffer_usage(sg_buffer buf); +SOKOL_GFX_API_DECL sg_image_type sg_query_image_type(sg_image img); +SOKOL_GFX_API_DECL int sg_query_image_width(sg_image img); +SOKOL_GFX_API_DECL int sg_query_image_height(sg_image img); +SOKOL_GFX_API_DECL int sg_query_image_num_slices(sg_image img); +SOKOL_GFX_API_DECL int sg_query_image_num_mipmaps(sg_image img); +SOKOL_GFX_API_DECL sg_pixel_format sg_query_image_pixelformat(sg_image img); +SOKOL_GFX_API_DECL sg_image_usage sg_query_image_usage(sg_image img); +SOKOL_GFX_API_DECL int sg_query_image_sample_count(sg_image img); +SOKOL_GFX_API_DECL sg_view_type sg_query_view_type(sg_view view); +SOKOL_GFX_API_DECL sg_image sg_query_view_image(sg_view view); +SOKOL_GFX_API_DECL sg_buffer sg_query_view_buffer(sg_view view); + +// separate resource allocation and initialization (for async setup) +SOKOL_GFX_API_DECL sg_buffer sg_alloc_buffer(void); +SOKOL_GFX_API_DECL sg_image sg_alloc_image(void); +SOKOL_GFX_API_DECL sg_sampler sg_alloc_sampler(void); +SOKOL_GFX_API_DECL sg_shader sg_alloc_shader(void); +SOKOL_GFX_API_DECL sg_pipeline sg_alloc_pipeline(void); +SOKOL_GFX_API_DECL sg_view sg_alloc_view(void); +SOKOL_GFX_API_DECL void sg_dealloc_buffer(sg_buffer buf); +SOKOL_GFX_API_DECL void sg_dealloc_image(sg_image img); +SOKOL_GFX_API_DECL void sg_dealloc_sampler(sg_sampler smp); +SOKOL_GFX_API_DECL void sg_dealloc_shader(sg_shader shd); +SOKOL_GFX_API_DECL void sg_dealloc_pipeline(sg_pipeline pip); +SOKOL_GFX_API_DECL void sg_dealloc_view(sg_view view); +SOKOL_GFX_API_DECL void sg_init_buffer(sg_buffer buf, const sg_buffer_desc* desc); +SOKOL_GFX_API_DECL void sg_init_image(sg_image img, const sg_image_desc* desc); +SOKOL_GFX_API_DECL void sg_init_sampler(sg_sampler smg, const sg_sampler_desc* desc); +SOKOL_GFX_API_DECL void sg_init_shader(sg_shader shd, const sg_shader_desc* desc); +SOKOL_GFX_API_DECL void sg_init_pipeline(sg_pipeline pip, const sg_pipeline_desc* desc); +SOKOL_GFX_API_DECL void sg_init_view(sg_view view, const sg_view_desc* desc); +SOKOL_GFX_API_DECL void sg_uninit_buffer(sg_buffer buf); +SOKOL_GFX_API_DECL void sg_uninit_image(sg_image img); +SOKOL_GFX_API_DECL void sg_uninit_sampler(sg_sampler smp); +SOKOL_GFX_API_DECL void sg_uninit_shader(sg_shader shd); +SOKOL_GFX_API_DECL void sg_uninit_pipeline(sg_pipeline pip); +SOKOL_GFX_API_DECL void sg_uninit_view(sg_view view); +SOKOL_GFX_API_DECL void sg_fail_buffer(sg_buffer buf); +SOKOL_GFX_API_DECL void sg_fail_image(sg_image img); +SOKOL_GFX_API_DECL void sg_fail_sampler(sg_sampler smp); +SOKOL_GFX_API_DECL void sg_fail_shader(sg_shader shd); +SOKOL_GFX_API_DECL void sg_fail_pipeline(sg_pipeline pip); +SOKOL_GFX_API_DECL void sg_fail_view(sg_view view); + +// frame and total stats +SOKOL_GFX_API_DECL void sg_enable_stats(void); +SOKOL_GFX_API_DECL void sg_disable_stats(void); +SOKOL_GFX_API_DECL bool sg_stats_enabled(void); +SOKOL_GFX_API_DECL sg_stats sg_query_stats(void); + +/* Backend-specific structs and functions, these may come in handy for mixing + sokol-gfx rendering with 'native backend' rendering functions. + + This group of functions will be expanded as needed. +*/ + +typedef struct sg_d3d11_buffer_info { + const void* buf; // ID3D11Buffer* +} sg_d3d11_buffer_info; + +typedef struct sg_d3d11_image_info { + const void* tex2d; // ID3D11Texture2D* + const void* tex3d; // ID3D11Texture3D* + const void* res; // ID3D11Resource* (either tex2d or tex3d) +} sg_d3d11_image_info; + +typedef struct sg_d3d11_sampler_info { + const void* smp; // ID3D11SamplerState* +} sg_d3d11_sampler_info; + +typedef struct sg_d3d11_shader_info { + const void* cbufs[SG_MAX_UNIFORMBLOCK_BINDSLOTS]; // ID3D11Buffer* (constant buffers by bind slot) + const void* vs; // ID3D11VertexShader* + const void* fs; // ID3D11PixelShader* +} sg_d3d11_shader_info; + +typedef struct sg_d3d11_pipeline_info { + const void* il; // ID3D11InputLayout* + const void* rs; // ID3D11RasterizerState* + const void* dss; // ID3D11DepthStencilState* + const void* bs; // ID3D11BlendState* +} sg_d3d11_pipeline_info; + +typedef struct sg_d3d11_view_info { + const void* srv; // ID3D11ShaderResourceView + const void* uav; // ID3D11UnorderedAccessView + const void* rtv; // ID3D11RenderTargetView + const void* dsv; // ID3D11DepthStencilView +} sg_d3d11_view_info; + +typedef struct sg_mtl_buffer_info { + const void* buf[SG_NUM_INFLIGHT_FRAMES]; // id + int active_slot; +} sg_mtl_buffer_info; + +typedef struct sg_mtl_image_info { + const void* tex[SG_NUM_INFLIGHT_FRAMES]; // id + int active_slot; +} sg_mtl_image_info; + +typedef struct sg_mtl_sampler_info { + const void* smp; // id +} sg_mtl_sampler_info; + +typedef struct sg_mtl_shader_info { + const void* vertex_lib; // id + const void* fragment_lib; // id + const void* vertex_func; // id + const void* fragment_func; // id +} sg_mtl_shader_info; + +typedef struct sg_mtl_pipeline_info { + const void* rps; // id + const void* dss; // id +} sg_mtl_pipeline_info; + +typedef struct sg_wgpu_buffer_info { + const void* buf; // WGPUBuffer +} sg_wgpu_buffer_info; + +typedef struct sg_wgpu_image_info { + const void* tex; // WGPUTexture +} sg_wgpu_image_info; + +typedef struct sg_wgpu_sampler_info { + const void* smp; // WGPUSampler +} sg_wgpu_sampler_info; + +typedef struct sg_wgpu_shader_info { + const void* vs_mod; // WGPUShaderModule + const void* fs_mod; // WGPUShaderModule + const void* bgl; // WGPUBindGroupLayout; +} sg_wgpu_shader_info; + +typedef struct sg_wgpu_pipeline_info { + const void* render_pipeline; // WGPURenderPipeline + const void* compute_pipeline; // WGPUComputePipeline +} sg_wgpu_pipeline_info; + +typedef struct sg_wgpu_view_info { + const void* view; // WGPUTextureView +} sg_wgpu_view_info; + +typedef struct sg_gl_buffer_info { + uint32_t buf[SG_NUM_INFLIGHT_FRAMES]; + int active_slot; +} sg_gl_buffer_info; + +typedef struct sg_gl_image_info { + uint32_t tex[SG_NUM_INFLIGHT_FRAMES]; + uint32_t tex_target; + int active_slot; +} sg_gl_image_info; + +typedef struct sg_gl_sampler_info { + uint32_t smp; +} sg_gl_sampler_info; + +typedef struct sg_gl_shader_info { + uint32_t prog; +} sg_gl_shader_info; + +typedef struct sg_gl_view_info { + uint32_t tex_view[SG_NUM_INFLIGHT_FRAMES]; + uint32_t msaa_render_buffer; + uint32_t msaa_resolve_frame_buffer; +} sg_gl_view_info; + +// D3D11: return ID3D11Device +SOKOL_GFX_API_DECL const void* sg_d3d11_device(void); +// D3D11: return ID3D11DeviceContext +SOKOL_GFX_API_DECL const void* sg_d3d11_device_context(void); +// D3D11: get internal buffer resource objects +SOKOL_GFX_API_DECL sg_d3d11_buffer_info sg_d3d11_query_buffer_info(sg_buffer buf); +// D3D11: get internal image resource objects +SOKOL_GFX_API_DECL sg_d3d11_image_info sg_d3d11_query_image_info(sg_image img); +// D3D11: get internal sampler resource objects +SOKOL_GFX_API_DECL sg_d3d11_sampler_info sg_d3d11_query_sampler_info(sg_sampler smp); +// D3D11: get internal shader resource objects +SOKOL_GFX_API_DECL sg_d3d11_shader_info sg_d3d11_query_shader_info(sg_shader shd); +// D3D11: get internal pipeline resource objects +SOKOL_GFX_API_DECL sg_d3d11_pipeline_info sg_d3d11_query_pipeline_info(sg_pipeline pip); +// D3D11: get internal view resource objects +SOKOL_GFX_API_DECL sg_d3d11_view_info sg_d3d11_query_view_info(sg_view view); + +// Metal: return __bridge-casted MTLDevice +SOKOL_GFX_API_DECL const void* sg_mtl_device(void); +// Metal: return __bridge-casted MTLRenderCommandEncoder when inside render pass (otherwise zero) +SOKOL_GFX_API_DECL const void* sg_mtl_render_command_encoder(void); +// Metal: return __bridge-casted MTLComputeCommandEncoder when inside compute pass (otherwise zero) +SOKOL_GFX_API_DECL const void* sg_mtl_compute_command_encoder(void); +// Metal: return __bridge-casted MTLCommandQueue +SOKOL_GFX_API_DECL const void* sg_mtl_command_queue(void); +// Metal: get internal __bridge-casted buffer resource objects +SOKOL_GFX_API_DECL sg_mtl_buffer_info sg_mtl_query_buffer_info(sg_buffer buf); +// Metal: get internal __bridge-casted image resource objects +SOKOL_GFX_API_DECL sg_mtl_image_info sg_mtl_query_image_info(sg_image img); +// Metal: get internal __bridge-casted sampler resource objects +SOKOL_GFX_API_DECL sg_mtl_sampler_info sg_mtl_query_sampler_info(sg_sampler smp); +// Metal: get internal __bridge-casted shader resource objects +SOKOL_GFX_API_DECL sg_mtl_shader_info sg_mtl_query_shader_info(sg_shader shd); +// Metal: get internal __bridge-casted pipeline resource objects +SOKOL_GFX_API_DECL sg_mtl_pipeline_info sg_mtl_query_pipeline_info(sg_pipeline pip); + +// WebGPU: return WGPUDevice object +SOKOL_GFX_API_DECL const void* sg_wgpu_device(void); +// WebGPU: return WGPUQueue object +SOKOL_GFX_API_DECL const void* sg_wgpu_queue(void); +// WebGPU: return this frame's WGPUCommandEncoder +SOKOL_GFX_API_DECL const void* sg_wgpu_command_encoder(void); +// WebGPU: return WGPURenderPassEncoder of current pass (returns 0 when outside pass or in a compute pass) +SOKOL_GFX_API_DECL const void* sg_wgpu_render_pass_encoder(void); +// WebGPU: return WGPUComputePassEncoder of current pass (returns 0 when outside pass or in a render pass) +SOKOL_GFX_API_DECL const void* sg_wgpu_compute_pass_encoder(void); +// WebGPU: get internal buffer resource objects +SOKOL_GFX_API_DECL sg_wgpu_buffer_info sg_wgpu_query_buffer_info(sg_buffer buf); +// WebGPU: get internal image resource objects +SOKOL_GFX_API_DECL sg_wgpu_image_info sg_wgpu_query_image_info(sg_image img); +// WebGPU: get internal sampler resource objects +SOKOL_GFX_API_DECL sg_wgpu_sampler_info sg_wgpu_query_sampler_info(sg_sampler smp); +// WebGPU: get internal shader resource objects +SOKOL_GFX_API_DECL sg_wgpu_shader_info sg_wgpu_query_shader_info(sg_shader shd); +// WebGPU: get internal pipeline resource objects +SOKOL_GFX_API_DECL sg_wgpu_pipeline_info sg_wgpu_query_pipeline_info(sg_pipeline pip); +// WebGPU: get internal view resource objects +SOKOL_GFX_API_DECL sg_wgpu_view_info sg_wgpu_query_view_info(sg_view view); + +// GL: get internal buffer resource objects +SOKOL_GFX_API_DECL sg_gl_buffer_info sg_gl_query_buffer_info(sg_buffer buf); +// GL: get internal image resource objects +SOKOL_GFX_API_DECL sg_gl_image_info sg_gl_query_image_info(sg_image img); +// GL: get internal sampler resource objects +SOKOL_GFX_API_DECL sg_gl_sampler_info sg_gl_query_sampler_info(sg_sampler smp); +// GL: get internal shader resource objects +SOKOL_GFX_API_DECL sg_gl_shader_info sg_gl_query_shader_info(sg_shader shd); +// GL: get internal view resource objects +SOKOL_GFX_API_DECL sg_gl_view_info sg_gl_query_view_info(sg_view view); + +#ifdef __cplusplus +} // extern "C" + +// reference-based equivalents for c++ +inline void sg_setup(const sg_desc& desc) { return sg_setup(&desc); } + +inline sg_buffer sg_make_buffer(const sg_buffer_desc& desc) { return sg_make_buffer(&desc); } +inline sg_image sg_make_image(const sg_image_desc& desc) { return sg_make_image(&desc); } +inline sg_sampler sg_make_sampler(const sg_sampler_desc& desc) { return sg_make_sampler(&desc); } +inline sg_shader sg_make_shader(const sg_shader_desc& desc) { return sg_make_shader(&desc); } +inline sg_pipeline sg_make_pipeline(const sg_pipeline_desc& desc) { return sg_make_pipeline(&desc); } +inline sg_view sg_make_view(const sg_view_desc& desc) { return sg_make_view(&desc); } +inline void sg_update_image(sg_image img, const sg_image_data& data) { return sg_update_image(img, &data); } + +inline void sg_begin_pass(const sg_pass& pass) { return sg_begin_pass(&pass); } +inline void sg_apply_bindings(const sg_bindings& bindings) { return sg_apply_bindings(&bindings); } +inline void sg_apply_uniforms(int ub_slot, const sg_range& data) { return sg_apply_uniforms(ub_slot, &data); } + +inline sg_buffer_desc sg_query_buffer_defaults(const sg_buffer_desc& desc) { return sg_query_buffer_defaults(&desc); } +inline sg_image_desc sg_query_image_defaults(const sg_image_desc& desc) { return sg_query_image_defaults(&desc); } +inline sg_sampler_desc sg_query_sampler_defaults(const sg_sampler_desc& desc) { return sg_query_sampler_defaults(&desc); } +inline sg_shader_desc sg_query_shader_defaults(const sg_shader_desc& desc) { return sg_query_shader_defaults(&desc); } +inline sg_pipeline_desc sg_query_pipeline_defaults(const sg_pipeline_desc& desc) { return sg_query_pipeline_defaults(&desc); } +inline sg_view_desc sg_query_view_defaults(const sg_view_desc& desc) { return sg_query_view_defaults(&desc); } + +inline void sg_init_buffer(sg_buffer buf, const sg_buffer_desc& desc) { return sg_init_buffer(buf, &desc); } +inline void sg_init_image(sg_image img, const sg_image_desc& desc) { return sg_init_image(img, &desc); } +inline void sg_init_sampler(sg_sampler smp, const sg_sampler_desc& desc) { return sg_init_sampler(smp, &desc); } +inline void sg_init_shader(sg_shader shd, const sg_shader_desc& desc) { return sg_init_shader(shd, &desc); } +inline void sg_init_pipeline(sg_pipeline pip, const sg_pipeline_desc& desc) { return sg_init_pipeline(pip, &desc); } +inline void sg_init_view(sg_view view, const sg_view_desc& desc) { return sg_init_view(view, &desc); } + +inline void sg_update_buffer(sg_buffer buf_id, const sg_range& data) { return sg_update_buffer(buf_id, &data); } +inline int sg_append_buffer(sg_buffer buf_id, const sg_range& data) { return sg_append_buffer(buf_id, &data); } +#endif +#endif // SOKOL_GFX_INCLUDED + +// ██ ███ ███ ██████ ██ ███████ ███ ███ ███████ ███ ██ ████████ █████ ████████ ██ ██████ ███ ██ +// ██ ████ ████ ██ ██ ██ ██ ████ ████ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ +// ██ ██ ████ ██ ██████ ██ █████ ██ ████ ██ █████ ██ ██ ██ ██ ███████ ██ ██ ██ ██ ██ ██ ██ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ██ ██ ██ ██ ███████ ███████ ██ ██ ███████ ██ ████ ██ ██ ██ ██ ██ ██████ ██ ████ +// +// >>implementation +#ifdef SOKOL_GFX_IMPL +#define SOKOL_GFX_IMPL_INCLUDED (1) + +#if !(defined(SOKOL_GLCORE)||defined(SOKOL_GLES3)||defined(SOKOL_D3D11)||defined(SOKOL_METAL)||defined(SOKOL_WGPU)||defined(SOKOL_VULKAN)||defined(SOKOL_DUMMY_BACKEND)) +#error "Please select a backend with SOKOL_GLCORE, SOKOL_GLES3, SOKOL_D3D11, SOKOL_METAL, SOKOL_WGPU, SOKOL_VULKAN or SOKOL_DUMMY_BACKEND" +#endif +#if defined(SOKOL_MALLOC) || defined(SOKOL_CALLOC) || defined(SOKOL_FREE) +#error "SOKOL_MALLOC/CALLOC/FREE macros are no longer supported, please use sg_desc.allocator to override memory allocation functions" +#endif + +#include // malloc, free, qsort +#include // memset +#include // FLT_MAX + +#ifndef SOKOL_API_IMPL + #define SOKOL_API_IMPL +#endif +#ifndef SOKOL_DEBUG + #ifndef NDEBUG + #define SOKOL_DEBUG + #endif +#endif +#ifndef SOKOL_ASSERT + #include + #define SOKOL_ASSERT(c) assert(c) +#endif +#ifndef SOKOL_UNREACHABLE + #define SOKOL_UNREACHABLE SOKOL_ASSERT(false) +#endif + +#ifndef _SOKOL_PRIVATE + #if defined(__GNUC__) || defined(__clang__) + #define _SOKOL_PRIVATE __attribute__((unused)) static + #else + #define _SOKOL_PRIVATE static + #endif +#endif + +#ifndef _SOKOL_UNUSED + #define _SOKOL_UNUSED(x) (void)(x) +#endif + +#if defined(SOKOL_TRACE_HOOKS) +#define _SG_TRACE_ARGS(fn, ...) if (_sg.hooks.fn) { _sg.hooks.fn(__VA_ARGS__, _sg.hooks.user_data); } +#define _SG_TRACE_NOARGS(fn) if (_sg.hooks.fn) { _sg.hooks.fn(_sg.hooks.user_data); } +#else +#define _SG_TRACE_ARGS(fn, ...) +#define _SG_TRACE_NOARGS(fn) +#endif + +#ifdef __cplusplus +#define _SG_STRUCT(TYPE, NAME) TYPE NAME = {} +#else +#define _SG_STRUCT(TYPE, NAME) TYPE NAME = {0} +#endif + +// default clear values +#ifndef SG_DEFAULT_CLEAR_RED +#define SG_DEFAULT_CLEAR_RED (0.5f) +#endif +#ifndef SG_DEFAULT_CLEAR_GREEN +#define SG_DEFAULT_CLEAR_GREEN (0.5f) +#endif +#ifndef SG_DEFAULT_CLEAR_BLUE +#define SG_DEFAULT_CLEAR_BLUE (0.5f) +#endif +#ifndef SG_DEFAULT_CLEAR_ALPHA +#define SG_DEFAULT_CLEAR_ALPHA (1.0f) +#endif +#ifndef SG_DEFAULT_CLEAR_DEPTH +#define SG_DEFAULT_CLEAR_DEPTH (1.0f) +#endif +#ifndef SG_DEFAULT_CLEAR_STENCIL +#define SG_DEFAULT_CLEAR_STENCIL (0) +#endif + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4115) // named type definition in parentheses +#pragma warning(disable:4505) // unreferenced local function has been removed +#pragma warning(disable:4201) // nonstandard extension used: nameless struct/union (needed by d3d11.h) +#pragma warning(disable:4054) // 'type cast': from function pointer +#pragma warning(disable:4055) // 'type cast': from data pointer +#endif + +#if defined(SOKOL_D3D11) + #if defined(__GNUC__) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wunknown-pragmas" + #endif + #ifndef D3D11_NO_HELPERS + #define D3D11_NO_HELPERS + #endif + #ifndef WIN32_LEAN_AND_MEAN + #define WIN32_LEAN_AND_MEAN + #endif + #ifndef NOMINMAX + #define NOMINMAX + #endif + #include + #include // ID3DUserDefinedAnnotation (debug-group markers) + #include + #pragma comment (lib, "kernel32") + #pragma comment (lib, "user32") + #pragma comment (lib, "dxgi") + #pragma comment (lib, "d3d11") + #if defined(__GNUC__) + #pragma GCC diagnostic pop + #endif +#elif defined(SOKOL_METAL) + // see https://clang.llvm.org/docs/LanguageExtensions.html#automatic-reference-counting + #if !defined(__cplusplus) + #if __has_feature(objc_arc) && !__has_feature(objc_arc_fields) + #error "sokol_gfx.h requires __has_feature(objc_arc_field) if ARC is enabled (use a more recent compiler version)" + #endif + #endif + #include + #include + #if defined(TARGET_OS_IPHONE) && !TARGET_OS_IPHONE + #define _SG_TARGET_MACOS (1) + #else + #define _SG_TARGET_IOS (1) + #if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR + #define _SG_TARGET_IOS_SIMULATOR (1) + #endif + #endif + #import + #import // needed for CAMetalDrawable +#elif defined(SOKOL_WGPU) + #include + #if defined(__EMSCRIPTEN__) + #include + #endif +#elif defined(SOKOL_VULKAN) + #include +#elif defined(SOKOL_GLCORE) || defined(SOKOL_GLES3) + #define _SOKOL_ANY_GL (1) + + // include platform specific GL headers (or on Win32: use an embedded GL loader) + #if !defined(SOKOL_EXTERNAL_GL_LOADER) + #if defined(_WIN32) + #if defined(SOKOL_GLCORE) + #define _SOKOL_USE_WIN32_GL_LOADER (1) + #ifndef WIN32_LEAN_AND_MEAN + #define WIN32_LEAN_AND_MEAN + #endif + #ifndef NOMINMAX + #define NOMINMAX + #endif + #include + #pragma comment (lib, "kernel32") // GetProcAddress() + #endif + #elif defined(__APPLE__) + #include + #ifndef GL_SILENCE_DEPRECATION + #define GL_SILENCE_DEPRECATION + #endif + #ifndef GLES_SILENCE_DEPRECATION + #define GLES_SILENCE_DEPRECATION + #endif + #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE + #if defined(TARGET_OS_MACCATALYST) && TARGET_OS_MACCATALYST + #include + #else + #include + #include + #endif + #else + #include + #endif + #elif defined(__EMSCRIPTEN__) + #if defined(SOKOL_GLES3) + #include + #endif + #elif defined(__ANDROID__) + #if __ANDROID_API__ >= 24 + #include + #else + #include + #endif + #elif defined(__linux__) || defined(__unix__) + #if defined(SOKOL_GLCORE) + #define GL_GLEXT_PROTOTYPES + #include + #else + #include + #include + #endif + #endif + #endif + + // broad GL feature availability defines (DON'T merge this into the above ifdef-block!) + #if defined(_WIN32) + #define _SOKOL_GL_HAS_COLORMASKI (1) + #if defined(GL_VERSION_4_3) || defined(_SOKOL_USE_WIN32_GL_LOADER) + #define _SOKOL_GL_HAS_COMPUTE (1) + #define _SOKOL_GL_HAS_TEXVIEWS (1) + #endif + #if defined(GL_VERSION_4_2) || defined(_SOKOL_USE_WIN32_GL_LOADER) + #define _SOKOL_GL_HAS_TEXSTORAGE (1) + #define _SOKOL_GL_HAS_BASEINSTANCE (1) + #endif + #if defined(GL_VERSION_3_3) || defined(_SOKOL_USE_WIN32_GL_LOADER) + #define _SOKOL_GL_HAS_DUALSOURCEBLENDING (1) + #endif + #if defined(GL_VERSION_3_2) || defined(_SOKOL_USE_WIN32_GL_LOADER) + #define _SOKOL_GL_HAS_BASEVERTEX (1) + #endif + #elif defined(__APPLE__) + #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE + #if defined(TARGET_OS_MACCATALYST) && TARGET_OS_MACCATALYST + #define _SOKOL_GL_HAS_COLORMASKI (1) + #define _SOKOL_GL_HAS_BASEVERTEX (1) + #define _SOKOL_GL_HAS_DUALSOURCEBLENDING (1) + #else + #define _SOKOL_GL_HAS_TEXSTORAGE (1) + #endif + #else + #define _SOKOL_GL_HAS_COLORMASKI (1) + #define _SOKOL_GL_HAS_BASEVERTEX (1) + #define _SOKOL_GL_HAS_DUALSOURCEBLENDING (1) + #endif + #elif defined(__EMSCRIPTEN__) + #define _SOKOL_GL_HAS_TEXSTORAGE (1) + #elif defined(__ANDROID__) + #define _SOKOL_GL_HAS_COMPUTE (1) + #define _SOKOL_GL_HAS_TEXSTORAGE (1) + #if defined(GL_ES_VERSION_3_2) + #define _SOKOL_GL_HAS_COLORMASKI (1) + #endif + #elif defined(__linux__) || defined(__unix__) + #define _SOKOL_GL_HAS_COLORMASKI (1) + #if defined(SOKOL_GLCORE) + #if defined(GL_VERSION_4_3) + #define _SOKOL_GL_HAS_COMPUTE (1) + #define _SOKOL_GL_HAS_TEXVIEWS (1) + #endif + #if defined(GL_VERSION_4_2) + #define _SOKOL_GL_HAS_TEXSTORAGE (1) + #define _SOKOL_GL_HAS_BASEINSTANCE (1) + #endif + #if defined(GL_VERSION_3_3) + #define _SOKOL_GL_HAS_DUALSOURCEBLENDING (1) + #endif + #if defined(GL_VERSION_3_2) + #define _SOKOL_GL_HAS_BASEVERTEX (1) + #endif + #else + #define _SOKOL_GL_HAS_COMPUTE (1) + #define _SOKOL_GL_HAS_TEXSTORAGE (1) + #define _SOKOL_GL_HAS_BASEVERTEX (1) + #endif + #endif + + // optional GL loader definitions (only on Win32) + #if defined(_SOKOL_USE_WIN32_GL_LOADER) + #define __gl_h_ 1 + #define __gl32_h_ 1 + #define __gl31_h_ 1 + #define __GL_H__ 1 + #define __glext_h_ 1 + #define __GLEXT_H_ 1 + #define __gltypes_h_ 1 + #define __glcorearb_h_ 1 + #define __gl_glcorearb_h_ 1 + #define GL_APIENTRY APIENTRY + + typedef unsigned int GLenum; + typedef unsigned int GLuint; + typedef int GLsizei; + typedef char GLchar; + typedef ptrdiff_t GLintptr; + typedef ptrdiff_t GLsizeiptr; + typedef double GLclampd; + typedef unsigned short GLushort; + typedef unsigned char GLubyte; + typedef unsigned char GLboolean; + typedef uint64_t GLuint64; + typedef double GLdouble; + typedef unsigned short GLhalf; + typedef float GLclampf; + typedef unsigned int GLbitfield; + typedef signed char GLbyte; + typedef short GLshort; + typedef void GLvoid; + typedef int64_t GLint64; + typedef float GLfloat; + typedef int GLint; + #define GL_INT_2_10_10_10_REV 0x8D9F + #define GL_R32F 0x822E + #define GL_PROGRAM_POINT_SIZE 0x8642 + #define GL_DEPTH_ATTACHMENT 0x8D00 + #define GL_DEPTH_STENCIL_ATTACHMENT 0x821A + #define GL_COLOR_ATTACHMENT0 0x8CE0 + #define GL_R16F 0x822D + #define GL_DRAW_FRAMEBUFFER 0x8CA9 + #define GL_FRAMEBUFFER_COMPLETE 0x8CD5 + #define GL_NUM_EXTENSIONS 0x821D + #define GL_INFO_LOG_LENGTH 0x8B84 + #define GL_VERTEX_SHADER 0x8B31 + #define GL_INCR 0x1E02 + #define GL_DYNAMIC_DRAW 0x88E8 + #define GL_STATIC_DRAW 0x88E4 + #define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519 + #define GL_TEXTURE_CUBE_MAP 0x8513 + #define GL_FUNC_SUBTRACT 0x800A + #define GL_FUNC_REVERSE_SUBTRACT 0x800B + #define GL_CONSTANT_COLOR 0x8001 + #define GL_DECR_WRAP 0x8508 + #define GL_R8 0x8229 + #define GL_LINEAR_MIPMAP_LINEAR 0x2703 + #define GL_ELEMENT_ARRAY_BUFFER 0x8893 + #define GL_SHORT 0x1402 + #define GL_DEPTH_TEST 0x0B71 + #define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518 + #define GL_LINK_STATUS 0x8B82 + #define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517 + #define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E + #define GL_RGBA16F 0x881A + #define GL_CONSTANT_ALPHA 0x8003 + #define GL_READ_FRAMEBUFFER 0x8CA8 + #define GL_TEXTURE0 0x84C0 + #define GL_TEXTURE_MIN_LOD 0x813A + #define GL_CLAMP_TO_EDGE 0x812F + #define GL_UNSIGNED_SHORT_5_6_5 0x8363 + #define GL_TEXTURE_WRAP_R 0x8072 + #define GL_UNSIGNED_SHORT_5_5_5_1 0x8034 + #define GL_NEAREST_MIPMAP_NEAREST 0x2700 + #define GL_UNSIGNED_SHORT_4_4_4_4 0x8033 + #define GL_SRC_ALPHA_SATURATE 0x0308 + #define GL_STREAM_DRAW 0x88E0 + #define GL_ONE 1 + #define GL_NEAREST_MIPMAP_LINEAR 0x2702 + #define GL_RGB10_A2 0x8059 + #define GL_RGBA8 0x8058 + #define GL_SRGB8_ALPHA8 0x8C43 + #define GL_RGBA4 0x8056 + #define GL_RGB8 0x8051 + #define GL_ARRAY_BUFFER 0x8892 + #define GL_STENCIL 0x1802 + #define GL_TEXTURE_2D 0x0DE1 + #define GL_DEPTH 0x1801 + #define GL_FRONT 0x0404 + #define GL_STENCIL_BUFFER_BIT 0x00000400 + #define GL_REPEAT 0x2901 + #define GL_RGBA 0x1908 + #define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515 + #define GL_DECR 0x1E03 + #define GL_FRAGMENT_SHADER 0x8B30 + #define GL_COMPUTE_SHADER 0x91B9 + #define GL_FLOAT 0x1406 + #define GL_TEXTURE_MAX_LOD 0x813B + #define GL_DEPTH_COMPONENT 0x1902 + #define GL_ONE_MINUS_DST_ALPHA 0x0305 + #define GL_COLOR 0x1800 + #define GL_TEXTURE_2D_ARRAY 0x8C1A + #define GL_TRIANGLES 0x0004 + #define GL_UNSIGNED_BYTE 0x1401 + #define GL_TEXTURE_MAG_FILTER 0x2800 + #define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004 + #define GL_NONE 0 + #define GL_SRC_COLOR 0x0300 + #define GL_SRC1_ALPHA 0x8589 + #define GL_SRC1_COLOR 0x88F9 + #define GL_ONE_MINUS_SRC1_ALPHA 0x88FB + #define GL_ONE_MINUS_SRC1_COLOR 0x88FA + #define GL_BYTE 0x1400 + #define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A + #define GL_LINE_STRIP 0x0003 + #define GL_TEXTURE_3D 0x806F + #define GL_CW 0x0900 + #define GL_LINEAR 0x2601 + #define GL_RENDERBUFFER 0x8D41 + #define GL_GEQUAL 0x0206 + #define GL_COLOR_BUFFER_BIT 0x00004000 + #define GL_RGBA32F 0x8814 + #define GL_BLEND 0x0BE2 + #define GL_ONE_MINUS_SRC_ALPHA 0x0303 + #define GL_ONE_MINUS_CONSTANT_COLOR 0x8002 + #define GL_TEXTURE_WRAP_T 0x2803 + #define GL_TEXTURE_WRAP_S 0x2802 + #define GL_TEXTURE_MIN_FILTER 0x2801 + #define GL_LINEAR_MIPMAP_NEAREST 0x2701 + #define GL_EXTENSIONS 0x1F03 + #define GL_NO_ERROR 0 + #define GL_REPLACE 0x1E01 + #define GL_KEEP 0x1E00 + #define GL_CCW 0x0901 + #define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516 + #define GL_RGB 0x1907 + #define GL_TRIANGLE_STRIP 0x0005 + #define GL_FALSE 0 + #define GL_ZERO 0 + #define GL_CULL_FACE 0x0B44 + #define GL_INVERT 0x150A + #define GL_INT 0x1404 + #define GL_UNSIGNED_INT 0x1405 + #define GL_UNSIGNED_SHORT 0x1403 + #define GL_NEAREST 0x2600 + #define GL_SCISSOR_TEST 0x0C11 + #define GL_LEQUAL 0x0203 + #define GL_STENCIL_TEST 0x0B90 + #define GL_DITHER 0x0BD0 + #define GL_DEPTH_COMPONENT32F 0x8CAC + #define GL_EQUAL 0x0202 + #define GL_FRAMEBUFFER 0x8D40 + #define GL_RGB5 0x8050 + #define GL_LINES 0x0001 + #define GL_DEPTH_BUFFER_BIT 0x00000100 + #define GL_SRC_ALPHA 0x0302 + #define GL_INCR_WRAP 0x8507 + #define GL_LESS 0x0201 + #define GL_MULTISAMPLE 0x809D + #define GL_FRAMEBUFFER_BINDING 0x8CA6 + #define GL_BACK 0x0405 + #define GL_ALWAYS 0x0207 + #define GL_FUNC_ADD 0x8006 + #define GL_ONE_MINUS_DST_COLOR 0x0307 + #define GL_NOTEQUAL 0x0205 + #define GL_DST_COLOR 0x0306 + #define GL_COMPILE_STATUS 0x8B81 + #define GL_RED 0x1903 + #define GL_DST_ALPHA 0x0304 + #define GL_RGB5_A1 0x8057 + #define GL_GREATER 0x0204 + #define GL_POLYGON_OFFSET_FILL 0x8037 + #define GL_TRUE 1 + #define GL_NEVER 0x0200 + #define GL_POINTS 0x0000 + #define GL_ONE_MINUS_SRC_COLOR 0x0301 + #define GL_MIRRORED_REPEAT 0x8370 + #define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D + #define GL_R11F_G11F_B10F 0x8C3A + #define GL_UNSIGNED_INT_10F_11F_11F_REV 0x8C3B + #define GL_RGB9_E5 0x8C3D + #define GL_UNSIGNED_INT_5_9_9_9_REV 0x8C3E + #define GL_RGBA32UI 0x8D70 + #define GL_RGB32UI 0x8D71 + #define GL_RGBA16UI 0x8D76 + #define GL_RGB16UI 0x8D77 + #define GL_RGBA8UI 0x8D7C + #define GL_RGB8UI 0x8D7D + #define GL_RGBA32I 0x8D82 + #define GL_RGB32I 0x8D83 + #define GL_RGBA16I 0x8D88 + #define GL_RGB16I 0x8D89 + #define GL_RGBA8I 0x8D8E + #define GL_RGB8I 0x8D8F + #define GL_RED_INTEGER 0x8D94 + #define GL_RG 0x8227 + #define GL_RG_INTEGER 0x8228 + #define GL_R8 0x8229 + #define GL_R16 0x822A + #define GL_RG8 0x822B + #define GL_RG16 0x822C + #define GL_R16F 0x822D + #define GL_R32F 0x822E + #define GL_RG16F 0x822F + #define GL_RG32F 0x8230 + #define GL_R8I 0x8231 + #define GL_R8UI 0x8232 + #define GL_R16I 0x8233 + #define GL_R16UI 0x8234 + #define GL_R32I 0x8235 + #define GL_R32UI 0x8236 + #define GL_RG8I 0x8237 + #define GL_RG8UI 0x8238 + #define GL_RG16I 0x8239 + #define GL_RG16UI 0x823A + #define GL_RG32I 0x823B + #define GL_RG32UI 0x823C + #define GL_RGBA_INTEGER 0x8D99 + #define GL_R8_SNORM 0x8F94 + #define GL_RG8_SNORM 0x8F95 + #define GL_RGB8_SNORM 0x8F96 + #define GL_RGBA8_SNORM 0x8F97 + #define GL_R16_SNORM 0x8F98 + #define GL_RG16_SNORM 0x8F99 + #define GL_RGB16_SNORM 0x8F9A + #define GL_RGBA16_SNORM 0x8F9B + #define GL_RGBA16 0x805B + #define GL_MAX_TEXTURE_SIZE 0x0D33 + #define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C + #define GL_MAX_3D_TEXTURE_SIZE 0x8073 + #define GL_MAX_ARRAY_TEXTURE_LAYERS 0x88FF + #define GL_MAX_VERTEX_ATTRIBS 0x8869 + #define GL_CLAMP_TO_BORDER 0x812D + #define GL_TEXTURE_BORDER_COLOR 0x1004 + #define GL_CURRENT_PROGRAM 0x8B8D + #define GL_MAX_VERTEX_UNIFORM_COMPONENTS 0x8B4A + #define GL_UNPACK_ALIGNMENT 0x0CF5 + #define GL_FRAMEBUFFER_SRGB 0x8DB9 + #define GL_TEXTURE_COMPARE_MODE 0x884C + #define GL_TEXTURE_COMPARE_FUNC 0x884D + #define GL_COMPARE_REF_TO_TEXTURE 0x884E + #define GL_TEXTURE_CUBE_MAP_SEAMLESS 0x884F + #define GL_TEXTURE_MAX_LEVEL 0x813D + #define GL_FRAMEBUFFER_UNDEFINED 0x8219 + #define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6 + #define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7 + #define GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD + #define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE 0x8D56 + #define GL_MAJOR_VERSION 0x821B + #define GL_MINOR_VERSION 0x821C + #define GL_TEXTURE_2D_MULTISAMPLE 0x9100 + #define GL_TEXTURE_2D_MULTISAMPLE_ARRAY 0x9102 + #define GL_SHADER_STORAGE_BARRIER_BIT 0x2000 + #define GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT 0x00000001 + #define GL_ELEMENT_ARRAY_BARRIER_BIT 0x00000002 + #define GL_TEXTURE_FETCH_BARRIER_BIT 0x00000008 + #define GL_SHADER_IMAGE_ACCESS_BARRIER_BIT 0x00000020 + #define GL_FRAMEBUFFER_BARRIER_BIT 0x00000400 + #define GL_MIN 0x8007 + #define GL_MAX 0x8008 + #define GL_WRITE_ONLY 0x88B9 + #define GL_READ_WRITE 0x88BA + #define GL_MAX_DRAW_BUFFERS 0x8824 + #define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872 + #define GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS 0x90DD + #define GL_MAX_IMAGE_UNITS 0x8F38 + #endif + + #ifndef GL_UNSIGNED_INT_2_10_10_10_REV + #define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368 + #endif + #ifndef GL_UNSIGNED_INT_24_8 + #define GL_UNSIGNED_INT_24_8 0x84FA + #endif + #ifndef GL_TEXTURE_MAX_ANISOTROPY_EXT + #define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE + #endif + #ifndef GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT + #define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF + #endif + #ifndef GL_COMPRESSED_RGBA_S3TC_DXT1_EXT + #define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1 + #endif + #ifndef GL_COMPRESSED_RGBA_S3TC_DXT3_EXT + #define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2 + #endif + #ifndef GL_COMPRESSED_RGBA_S3TC_DXT5_EXT + #define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3 + #endif + #ifndef GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT + #define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT 0x8C4F + #endif + #ifndef GL_COMPRESSED_RED_RGTC1 + #define GL_COMPRESSED_RED_RGTC1 0x8DBB + #endif + #ifndef GL_COMPRESSED_SIGNED_RED_RGTC1 + #define GL_COMPRESSED_SIGNED_RED_RGTC1 0x8DBC + #endif + #ifndef GL_COMPRESSED_RED_GREEN_RGTC2 + #define GL_COMPRESSED_RED_GREEN_RGTC2 0x8DBD + #endif + #ifndef GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2 + #define GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2 0x8DBE + #endif + #ifndef GL_COMPRESSED_RGBA_BPTC_UNORM_ARB + #define GL_COMPRESSED_RGBA_BPTC_UNORM_ARB 0x8E8C + #endif + #ifndef GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB + #define GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB 0x8E8D + #endif + #ifndef GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB + #define GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB 0x8E8E + #endif + #ifndef GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB + #define GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB 0x8E8F + #endif + #ifndef GL_COMPRESSED_RGB8_ETC2 + #define GL_COMPRESSED_RGB8_ETC2 0x9274 + #endif + #ifndef GL_COMPRESSED_SRGB8_ETC2 + #define GL_COMPRESSED_SRGB8_ETC2 0x9275 + #endif + #ifndef GL_COMPRESSED_RGBA8_ETC2_EAC + #define GL_COMPRESSED_RGBA8_ETC2_EAC 0x9278 + #endif + #ifndef GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC + #define GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC 0x9279 + #endif + #ifndef GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 + #define GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9276 + #endif + #ifndef GL_COMPRESSED_R11_EAC + #define GL_COMPRESSED_R11_EAC 0x9270 + #endif + #ifndef GL_COMPRESSED_SIGNED_R11_EAC + #define GL_COMPRESSED_SIGNED_R11_EAC 0x9271 + #endif + #ifndef GL_COMPRESSED_RG11_EAC + #define GL_COMPRESSED_RG11_EAC 0x9272 + #endif + #ifndef GL_COMPRESSED_SIGNED_RG11_EAC + #define GL_COMPRESSED_SIGNED_RG11_EAC 0x9273 + #endif + #ifndef GL_COMPRESSED_RGBA_ASTC_4x4_KHR + #define GL_COMPRESSED_RGBA_ASTC_4x4_KHR 0x93B0 + #endif + #ifndef GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR + #define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR 0x93D0 + #endif + #ifndef GL_DEPTH24_STENCIL8 + #define GL_DEPTH24_STENCIL8 0x88F0 + #endif + #ifndef GL_HALF_FLOAT + #define GL_HALF_FLOAT 0x140B + #endif + #ifndef GL_DEPTH_STENCIL + #define GL_DEPTH_STENCIL 0x84F9 + #endif + #ifndef GL_LUMINANCE + #define GL_LUMINANCE 0x1909 + #endif + #ifndef GL_COMPUTE_SHADER + #define GL_COMPUTE_SHADER 0x91B9 + #endif + #ifndef _SG_GL_CHECK_ERROR + #if defined(__EMSCRIPTEN__) + // generally turn off glGetError() on WASM, it's a too big performance hit + // and WebGL provides much better diagnostics anyway + #define _SG_GL_CHECK_ERROR() + #elif defined(SOKOL_DEBUG) + // make sure that glGetError() is only called in debug mode + #define _SG_GL_CHECK_ERROR() { SOKOL_ASSERT(glGetError() == GL_NO_ERROR); } + #else + #define _SG_GL_CHECK_ERROR() + #endif + #endif + // make some GL constants generally available to simplify compilation, + // use of those constants will be filtered by runtime flags + #ifndef GL_SHADER_STORAGE_BUFFER + #define GL_SHADER_STORAGE_BUFFER 0x90D2 + #endif +#endif + +#if defined(SOKOL_GLES3) + // on WebGL2, GL_FRAMEBUFFER_UNDEFINED technically doesn't exist (it is defined + // in the Emscripten headers, but may not exist in other WebGL2 shims) + // see: https://github.com/floooh/sokol/pull/933 + #ifndef GL_FRAMEBUFFER_UNDEFINED + #define GL_FRAMEBUFFER_UNDEFINED 0x8219 + #endif +#endif + +// ███████ ████████ ██████ ██ ██ ██████ ████████ ███████ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ███████ ██ ██████ ██ ██ ██ ██ ███████ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ███████ ██ ██ ██ ██████ ██████ ██ ███████ +// +// >>structs + +typedef struct { int x, y, w, h; } _sg_recti_t; +typedef struct { int width, height; } _sg_dimi_t; + +// resource pool slots +typedef struct { + uint32_t id; + uint32_t uninit_count; + sg_resource_state state; +} _sg_slot_t; + +// resource pool housekeeping struct +typedef struct { + int size; + int queue_top; + uint32_t* gen_ctrs; + int* free_queue; +} _sg_pool_t; + +// resource hazard tracking struct +typedef struct { + int num_slots; + int cur_slot; + uint32_t* slots; // tracked unique resource ids + uint32_t occupy_num_bytes; // size of occupy_bits array in bytes + uint8_t* occupy_bits; // one set bit for each unique resource (index = (id & 0xFFFF) >> 3) +} _sg_track_t; + +// resource func forward decls +struct _sg_buffer_s; +struct _sg_image_s; +struct _sg_sampler_s; +struct _sg_shader_s; +struct _sg_pipeline_s; +struct _sg_view_s; + +// a general resource slot reference useful for caches +typedef struct _sg_sref_s { + uint32_t id; + uint32_t uninit_count; +} _sg_sref_t; + +// safe (in debug mode) internal resource references +typedef struct _sg_buffer_ref_s { + struct _sg_buffer_s* ptr; + _sg_sref_t sref; +} _sg_buffer_ref_t; + +typedef struct _sg_image_ref_s { + struct _sg_image_s* ptr; + _sg_sref_t sref; +} _sg_image_ref_t; + +typedef struct _sg_sampler_ref_t { + struct _sg_sampler_s* ptr; + _sg_sref_t sref; +} _sg_sampler_ref_t; + +typedef struct _sg_shader_ref_s { + struct _sg_shader_s* ptr; + _sg_sref_t sref; +} _sg_shader_ref_t; + +typedef struct _sg_pipeline_ref_s { + struct _sg_pipeline_s* ptr; + _sg_sref_t sref; +} _sg_pipeline_ref_t; + +typedef struct _sg_view_ref_s { + struct _sg_view_s* ptr; + _sg_sref_t sref; +} _sg_view_ref_t; + +// constants +enum { + _SG_STRING_SIZE = 32, + _SG_SLOT_SHIFT = 16, + _SG_SLOT_MASK = (1<<_SG_SLOT_SHIFT)-1, + _SG_MAX_POOL_SIZE = (1<<_SG_SLOT_SHIFT), + _SG_DEFAULT_BUFFER_POOL_SIZE = 128, + _SG_DEFAULT_IMAGE_POOL_SIZE = 128, + _SG_DEFAULT_SAMPLER_POOL_SIZE = 64, + _SG_DEFAULT_SHADER_POOL_SIZE = 32, + _SG_DEFAULT_PIPELINE_POOL_SIZE = 64, + _SG_DEFAULT_VIEW_POOL_SIZE = 256, + _SG_DEFAULT_UB_SIZE = 4 * 1024 * 1024, + _SG_DEFAULT_MAX_COMMIT_LISTENERS = 1024, + _SG_DEFAULT_WGPU_BINDGROUP_CACHE_SIZE = 1024, + _SG_DEFAULT_VK_COPY_STAGING_SIZE = (4 * 1024 * 1024), + _SG_DEFAULT_VK_STREAM_STAGING_SIZE = (16 * 1024 * 1024), + _SG_DEFAULT_VK_DESCRIPTOR_BUFFER_SIZE = (16 * 1024 * 1024), + _SG_MAX_STORAGEBUFFER_BINDINGS_PER_STAGE = SG_MAX_VIEW_BINDSLOTS, + _SG_MAX_STORAGEIMAGE_BINDINGS_PER_STAGE = SG_MAX_VIEW_BINDSLOTS, + _SG_MAX_TEXTURE_BINDINGS_PER_STAGE = SG_MAX_VIEW_BINDSLOTS, + _SG_MAX_UNIFORMBLOCK_BINDINGS_PER_STAGE = 8, +}; + +// fixed-size string +typedef struct { + char buf[_SG_STRING_SIZE]; +} _sg_str_t; + +typedef struct { + int size; + int append_pos; + bool append_overflow; + uint32_t update_frame_index; + uint32_t append_frame_index; + int num_slots; + int active_slot; + sg_buffer_usage usage; +} _sg_buffer_common_t; + +typedef struct { + uint32_t upd_frame_index; + int num_slots; + int active_slot; + sg_image_type type; + int width; + int height; + int num_slices; + int num_mipmaps; + sg_image_usage usage; + sg_pixel_format pixel_format; + int sample_count; +} _sg_image_common_t; + +typedef struct { + sg_filter min_filter; + sg_filter mag_filter; + sg_filter mipmap_filter; + sg_wrap wrap_u; + sg_wrap wrap_v; + sg_wrap wrap_w; + float min_lod; + float max_lod; + sg_border_color border_color; + sg_compare_func compare; + uint32_t max_anisotropy; +} _sg_sampler_common_t; + +typedef struct { + sg_shader_attr_base_type base_type; +} _sg_shader_attr_t; + +typedef struct { + sg_shader_stage stage; + uint32_t size; +} _sg_shader_uniform_block_t; + +typedef struct { + sg_shader_stage stage; + sg_view_type view_type; + sg_image_type image_type; + sg_pixel_format access_format; + sg_image_sample_type sample_type; + bool sbuf_readonly; + bool simg_writeonly; + bool multisampled; +} _sg_shader_view_t; + +typedef struct { + sg_shader_stage stage; + sg_sampler_type sampler_type; +} _sg_shader_sampler_t; + +typedef struct { + sg_shader_stage stage; + uint8_t view_slot; + uint8_t sampler_slot; +} _sg_shader_texture_sampler_t; + +typedef struct { + uint32_t required_bindings_and_uniforms; + bool is_compute; + _sg_shader_attr_t attrs[SG_MAX_VERTEX_ATTRIBUTES]; + _sg_shader_uniform_block_t uniform_blocks[SG_MAX_UNIFORMBLOCK_BINDSLOTS]; + _sg_shader_view_t views[SG_MAX_VIEW_BINDSLOTS]; + _sg_shader_sampler_t samplers[SG_MAX_SAMPLER_BINDSLOTS]; + _sg_shader_texture_sampler_t texture_samplers[SG_MAX_TEXTURE_SAMPLER_PAIRS]; +} _sg_shader_common_t; + +typedef struct { + bool vertex_buffer_layout_active[SG_MAX_VERTEXBUFFER_BINDSLOTS]; + bool use_instanced_draw; + bool is_compute; + uint32_t required_bindings_and_uniforms; + _sg_shader_ref_t shader; + sg_vertex_layout_state layout; + sg_depth_state depth; + sg_stencil_state stencil; + int color_count; + sg_color_target_state colors[SG_MAX_COLOR_ATTACHMENTS]; + sg_primitive_type primitive_type; + sg_index_type index_type; + sg_cull_mode cull_mode; + sg_face_winding face_winding; + int sample_count; + sg_color blend_color; + bool alpha_to_coverage_enabled; +} _sg_pipeline_common_t; + +typedef struct { + _sg_buffer_ref_t ref; + int offset; +} _sg_buffer_view_common_t; + +typedef struct { + _sg_image_ref_t ref; + int mip_level; + int slice; + int mip_level_count; + int slice_count; +} _sg_image_view_common_t; + +typedef struct { + sg_view_type type; + _sg_buffer_view_common_t buf; + _sg_image_view_common_t img; +} _sg_view_common_t; + +#if defined(SOKOL_DUMMY_BACKEND) +typedef struct _sg_buffer_s { + _sg_slot_t slot; + _sg_buffer_common_t cmn; +} _sg_dummy_buffer_t; +typedef _sg_dummy_buffer_t _sg_buffer_t; + +typedef struct _sg_image_s { + _sg_slot_t slot; + _sg_image_common_t cmn; +} _sg_dummy_image_t; +typedef _sg_dummy_image_t _sg_image_t; + +typedef struct _sg_sampler_s { + _sg_slot_t slot; + _sg_sampler_common_t cmn; +} _sg_dummy_sampler_t; +typedef _sg_dummy_sampler_t _sg_sampler_t; + +typedef struct _sg_shader_s { + _sg_slot_t slot; + _sg_shader_common_t cmn; +} _sg_dummy_shader_t; +typedef _sg_dummy_shader_t _sg_shader_t; + +typedef struct _sg_pipeline_s { + _sg_slot_t slot; + _sg_pipeline_common_t cmn; +} _sg_dummy_pipeline_t; +typedef _sg_dummy_pipeline_t _sg_pipeline_t; + +typedef struct _sg_view_s { + _sg_slot_t slot; + _sg_view_common_t cmn; +} _sg_dummy_view_t; +typedef _sg_dummy_view_t _sg_view_t; + +#elif defined(_SOKOL_ANY_GL) + +typedef enum { + _SG_GL_GPUDIRTY_VERTEXBUFFER = (1<<0), + _SG_GL_GPUDIRTY_INDEXBUFFER = (1<<1), + _SG_GL_GPUDIRTY_STORAGEBUFFER = (1<<2), + _SG_GL_GPUDIRTY_TEXTURE = (1<<3), + _SG_GL_GPUDIRTY_STORAGEIMAGE = (1<<4), + _SG_GL_GPUDIRTY_ATTACHMENT = (1<<5), + _SG_GL_GPUDIRTY_BUFFER_ALL = _SG_GL_GPUDIRTY_VERTEXBUFFER | _SG_GL_GPUDIRTY_INDEXBUFFER | _SG_GL_GPUDIRTY_STORAGEBUFFER, + _SG_GL_GPUDIRTY_IMAGE_ALL = _SG_GL_GPUDIRTY_TEXTURE | _SG_GL_GPUDIRTY_STORAGEIMAGE | _SG_GL_GPUDIRTY_ATTACHMENT, +} _sg_gl_gpudirty_t; + +typedef struct _sg_buffer_s { + _sg_slot_t slot; + _sg_buffer_common_t cmn; + struct { + GLuint buf[SG_NUM_INFLIGHT_FRAMES]; + uint8_t gpu_dirty_flags; // combination of _sg_gl_gpudirty_t flags + bool injected; // if true, external buffers were injected with sg_buffer_desc.gl_buffers + } gl; +} _sg_gl_buffer_t; +typedef _sg_gl_buffer_t _sg_buffer_t; + +typedef struct _sg_image_s { + _sg_slot_t slot; + _sg_image_common_t cmn; + struct { + GLenum target; + GLuint tex[SG_NUM_INFLIGHT_FRAMES]; + uint8_t gpu_dirty_flags; // combination of _sg_gl_gpudirty_flags + bool injected; // if true, external textures were injected with sg_image_desc.gl_textures + } gl; +} _sg_gl_image_t; +typedef _sg_gl_image_t _sg_image_t; + +typedef struct _sg_sampler_s { + _sg_slot_t slot; + _sg_sampler_common_t cmn; + struct { + GLuint smp; + bool injected; // true if external sampler was injects in sg_sampler_desc.gl_sampler + } gl; +} _sg_gl_sampler_t; +typedef _sg_gl_sampler_t _sg_sampler_t; + +typedef struct { + GLint gl_loc; + sg_uniform_type type; + uint16_t count; + uint16_t offset; +} _sg_gl_uniform_t; + +typedef struct { + int num_uniforms; + _sg_gl_uniform_t uniforms[SG_MAX_UNIFORMBLOCK_MEMBERS]; +} _sg_gl_uniform_block_t; + +typedef struct { + _sg_str_t name; +} _sg_gl_shader_attr_t; + +typedef struct _sg_shader_s { + _sg_slot_t slot; + _sg_shader_common_t cmn; + struct { + GLuint prog; + _sg_gl_shader_attr_t attrs[SG_MAX_VERTEX_ATTRIBUTES]; + _sg_gl_uniform_block_t uniform_blocks[SG_MAX_UNIFORMBLOCK_BINDSLOTS]; + uint8_t sbuf_binding[SG_MAX_VIEW_BINDSLOTS]; + uint8_t simg_binding[SG_MAX_VIEW_BINDSLOTS]; + int8_t tex_slot[SG_MAX_TEXTURE_SAMPLER_PAIRS]; // GL texture unit index + } gl; +} _sg_gl_shader_t; +typedef _sg_gl_shader_t _sg_shader_t; + +typedef struct { + int8_t vb_index; // -1 if attr is not enabled + int8_t divisor; // -1 if not initialized + uint8_t stride; + uint8_t size; + uint8_t normalized; + int offset; + GLenum type; + sg_shader_attr_base_type base_type; +} _sg_gl_attr_t; + +typedef struct _sg_pipeline_s { + _sg_slot_t slot; + _sg_pipeline_common_t cmn; + struct { + _sg_gl_attr_t attrs[SG_MAX_VERTEX_ATTRIBUTES]; + sg_depth_state depth; + sg_stencil_state stencil; + sg_primitive_type primitive_type; + sg_blend_state blend; + sg_color_mask color_write_mask[SG_MAX_COLOR_ATTACHMENTS]; + sg_cull_mode cull_mode; + sg_face_winding face_winding; + int sample_count; + bool alpha_to_coverage_enabled; + } gl; +} _sg_gl_pipeline_t; +typedef _sg_gl_pipeline_t _sg_pipeline_t; + +typedef struct _sg_view_s { + _sg_slot_t slot; + _sg_view_common_t cmn; + struct { + GLuint tex_view[SG_NUM_INFLIGHT_FRAMES]; // only if sg_features.gl_texture_views + GLuint msaa_render_buffer; // only if !msaa_texture_bindings + GLuint msaa_resolve_frame_buffer; + } gl; +} _sg_gl_view_t; +typedef _sg_gl_view_t _sg_view_t; + +typedef struct { + _sg_gl_attr_t gl_attr; + GLuint gl_vbuf; +} _sg_gl_cache_attr_t; + +typedef struct { + GLenum target; + GLuint texture; + GLuint sampler; +} _sg_gl_cache_texture_sampler_bind_slot; + +#define _SG_GL_MAX_SBUF_BINDINGS (_SG_MAX_STORAGEBUFFER_BINDINGS_PER_STAGE) +#define _SG_GL_MAX_SIMG_BINDINGS (_SG_MAX_STORAGEIMAGE_BINDINGS_PER_STAGE) +#define _SG_GL_MAX_TEX_SMP_BINDINGS (SG_MAX_TEXTURE_SAMPLER_PAIRS) +typedef struct { + sg_depth_state depth; + sg_stencil_state stencil; + sg_blend_state blend; + sg_color_mask color_write_mask[SG_MAX_COLOR_ATTACHMENTS]; + sg_cull_mode cull_mode; + sg_face_winding face_winding; + bool polygon_offset_enabled; + int sample_count; + sg_color blend_color; + bool alpha_to_coverage_enabled; + _sg_gl_cache_attr_t attrs[SG_MAX_VERTEX_ATTRIBUTES]; + GLuint vertex_buffer; + GLuint index_buffer; + GLuint storage_buffer; // general bind point + GLuint storage_buffers[_SG_GL_MAX_SBUF_BINDINGS]; + int storage_buffer_offsets[_SG_GL_MAX_SBUF_BINDINGS]; + GLuint stored_vertex_buffer; + GLuint stored_index_buffer; + GLuint stored_storage_buffer; + GLuint prog; + _sg_gl_cache_texture_sampler_bind_slot texture_samplers[_SG_GL_MAX_TEX_SMP_BINDINGS]; + _sg_gl_cache_texture_sampler_bind_slot stored_texture_sampler; + int cur_ib_offset; + GLenum cur_primitive_type; + GLenum cur_index_type; + GLenum cur_active_texture; + _sg_sref_t cur_pip; +} _sg_gl_cache_t; + +typedef struct { + bool valid; + GLuint vao; // global mutated vertex-array-object + GLuint fb; // global mutated framebuffer + _sg_gl_cache_t cache; + bool ext_anisotropic; + GLint max_anisotropy; + sg_store_action color_store_actions[SG_MAX_COLOR_ATTACHMENTS]; + sg_store_action depth_store_action; + sg_store_action stencil_store_action; + #if _SOKOL_USE_WIN32_GL_LOADER + HINSTANCE opengl32_dll; + #endif +} _sg_gl_backend_t; + +#elif defined(SOKOL_D3D11) + +typedef struct _sg_buffer_s { + _sg_slot_t slot; + _sg_buffer_common_t cmn; + struct { + ID3D11Buffer* buf; + } d3d11; +} _sg_d3d11_buffer_t; +typedef _sg_d3d11_buffer_t _sg_buffer_t; + +typedef struct _sg_image_s { + _sg_slot_t slot; + _sg_image_common_t cmn; + struct { + DXGI_FORMAT format; + ID3D11Texture2D* tex2d; + ID3D11Texture3D* tex3d; + ID3D11Resource* res; // either tex2d or tex3d + } d3d11; +} _sg_d3d11_image_t; +typedef _sg_d3d11_image_t _sg_image_t; + +typedef struct _sg_sampler_s { + _sg_slot_t slot; + _sg_sampler_common_t cmn; + struct { + ID3D11SamplerState* smp; + } d3d11; +} _sg_d3d11_sampler_t; +typedef _sg_d3d11_sampler_t _sg_sampler_t; + +typedef struct { + _sg_str_t sem_name; + int sem_index; +} _sg_d3d11_shader_attr_t; + +#define _SG_D3D11_MAX_TEXTUREARRAY_LAYERS (2048) +#define _SG_D3D11_MAX_TEXTURE_SUBRESOURCES (SG_MAX_MIPMAPS * _SG_D3D11_MAX_TEXTUREARRAY_LAYERS) +#define _SG_D3D11_MAX_STAGE_UB_BINDINGS (_SG_MAX_UNIFORMBLOCK_BINDINGS_PER_STAGE) +#define _SG_D3D11_MAX_STAGE_SRV_BINDINGS (SG_MAX_VIEW_BINDSLOTS) +#define _SG_D3D11_MAX_STAGE_UAV_BINDINGS (SG_MAX_VIEW_BINDSLOTS) +#define _SG_D3D11_MAX_STAGE_SMP_BINDINGS (SG_MAX_SAMPLER_BINDSLOTS) + +typedef struct _sg_shader_s { + _sg_slot_t slot; + _sg_shader_common_t cmn; + struct { + _sg_d3d11_shader_attr_t attrs[SG_MAX_VERTEX_ATTRIBUTES]; + ID3D11VertexShader* vs; + ID3D11PixelShader* fs; + ID3D11ComputeShader* cs; + void* vs_blob; + size_t vs_blob_length; + uint8_t ub_register_b_n[SG_MAX_UNIFORMBLOCK_BINDSLOTS]; + uint8_t view_register_t_n[SG_MAX_VIEW_BINDSLOTS]; + uint8_t view_register_u_n[SG_MAX_VIEW_BINDSLOTS]; + uint8_t smp_register_s_n[SG_MAX_SAMPLER_BINDSLOTS]; + ID3D11Buffer* all_cbufs[SG_MAX_UNIFORMBLOCK_BINDSLOTS]; + ID3D11Buffer* vs_cbufs[_SG_D3D11_MAX_STAGE_UB_BINDINGS]; + ID3D11Buffer* fs_cbufs[_SG_D3D11_MAX_STAGE_UB_BINDINGS]; + ID3D11Buffer* cs_cbufs[_SG_D3D11_MAX_STAGE_UB_BINDINGS]; + } d3d11; +} _sg_d3d11_shader_t; +typedef _sg_d3d11_shader_t _sg_shader_t; + +typedef struct _sg_pipeline_s { + _sg_slot_t slot; + _sg_pipeline_common_t cmn; + struct { + UINT stencil_ref; + UINT vb_strides[SG_MAX_VERTEXBUFFER_BINDSLOTS]; + D3D_PRIMITIVE_TOPOLOGY topology; + DXGI_FORMAT index_format; + ID3D11InputLayout* il; + ID3D11RasterizerState* rs; + ID3D11DepthStencilState* dss; + ID3D11BlendState* bs; + } d3d11; +} _sg_d3d11_pipeline_t; +typedef _sg_d3d11_pipeline_t _sg_pipeline_t; + +typedef struct _sg_view_s { + _sg_slot_t slot; + _sg_view_common_t cmn; + struct { + ID3D11ShaderResourceView* srv; + ID3D11UnorderedAccessView* uav; + ID3D11RenderTargetView* rtv; + ID3D11DepthStencilView* dsv; + } d3d11; +} _sg_d3d11_view_t; +typedef _sg_d3d11_view_t _sg_view_t; + +typedef struct { + bool valid; + ID3D11Device* dev; + ID3D11DeviceContext* ctx; + ID3DUserDefinedAnnotation* annotation; // local patch: BeginEvent/EndEvent debug markers, NULL if QI failed + struct { + ID3D11RenderTargetView* render_view; + ID3D11RenderTargetView* resolve_view; + } cur_swapchain; + // on-demand loaded d3dcompiler_47.dll handles + HINSTANCE d3dcompiler_dll; + bool d3dcompiler_dll_load_failed; + pD3DCompile D3DCompile_func; + // static bindings arrays + struct { + ID3D11Buffer* vbs[SG_MAX_VERTEXBUFFER_BINDSLOTS]; + UINT vb_offsets[SG_MAX_VERTEXBUFFER_BINDSLOTS]; + ID3D11ShaderResourceView* vs_srvs[_SG_D3D11_MAX_STAGE_SRV_BINDINGS]; + ID3D11ShaderResourceView* fs_srvs[_SG_D3D11_MAX_STAGE_SRV_BINDINGS]; + ID3D11ShaderResourceView* cs_srvs[_SG_D3D11_MAX_STAGE_SRV_BINDINGS]; + ID3D11UnorderedAccessView* cs_uavs[_SG_D3D11_MAX_STAGE_UAV_BINDINGS]; + ID3D11SamplerState* vs_smps[_SG_D3D11_MAX_STAGE_SMP_BINDINGS]; + ID3D11SamplerState* fs_smps[_SG_D3D11_MAX_STAGE_SMP_BINDINGS]; + ID3D11SamplerState* cs_smps[_SG_D3D11_MAX_STAGE_SMP_BINDINGS]; + } bnd; + // global subresourcedata array for texture updates + D3D11_SUBRESOURCE_DATA subres_data[_SG_D3D11_MAX_TEXTURE_SUBRESOURCES]; +} _sg_d3d11_backend_t; + +#elif defined(SOKOL_METAL) + +#if defined(_SG_TARGET_MACOS) || defined(_SG_TARGET_IOS_SIMULATOR) +#define _SG_MTL_UB_ALIGN (256) +#else +#define _SG_MTL_UB_ALIGN (16) +#endif +#define _SG_MTL_INVALID_SLOT_INDEX (0) + +typedef struct { + uint32_t frame_index; // frame index at which it is safe to release this resource + int slot_index; +} _sg_mtl_release_item_t; + +typedef struct { + NSMutableArray* pool; + int num_slots; + int free_queue_top; + int* free_queue; + int release_queue_front; + int release_queue_back; + _sg_mtl_release_item_t* release_queue; +} _sg_mtl_idpool_t; + +typedef struct _sg_buffer_s { + _sg_slot_t slot; + _sg_buffer_common_t cmn; + struct { + int buf[SG_NUM_INFLIGHT_FRAMES]; // index into _sg_mtl_pool + } mtl; +} _sg_mtl_buffer_t; +typedef _sg_mtl_buffer_t _sg_buffer_t; + +typedef struct _sg_image_s { + _sg_slot_t slot; + _sg_image_common_t cmn; + struct { + int tex[SG_NUM_INFLIGHT_FRAMES]; + } mtl; +} _sg_mtl_image_t; +typedef _sg_mtl_image_t _sg_image_t; + +typedef struct _sg_sampler_s { + _sg_slot_t slot; + _sg_sampler_common_t cmn; + struct { + int sampler_state; + } mtl; +} _sg_mtl_sampler_t; +typedef _sg_mtl_sampler_t _sg_sampler_t; + +typedef struct { + int mtl_lib; + int mtl_func; +} _sg_mtl_shader_func_t; + +typedef struct _sg_shader_s { + _sg_slot_t slot; + _sg_shader_common_t cmn; + struct { + _sg_mtl_shader_func_t vertex_func; + _sg_mtl_shader_func_t fragment_func; + _sg_mtl_shader_func_t compute_func; + MTLSize threads_per_threadgroup; + uint8_t ub_buffer_n[SG_MAX_UNIFORMBLOCK_BINDSLOTS]; + uint8_t view_buffer_texture_n[SG_MAX_VIEW_BINDSLOTS]; + uint8_t smp_sampler_n[SG_MAX_SAMPLER_BINDSLOTS]; + } mtl; +} _sg_mtl_shader_t; +typedef _sg_mtl_shader_t _sg_shader_t; + +typedef struct _sg_pipeline_s { + _sg_slot_t slot; + _sg_pipeline_common_t cmn; + struct { + MTLPrimitiveType prim_type; + int index_size; + MTLIndexType index_type; + MTLCullMode cull_mode; + MTLWinding winding; + uint32_t stencil_ref; + MTLSize threads_per_threadgroup; + int cps; // MTLComputePipelineState + int rps; // MTLRenderPipelineState + int dss; // MTLDepthStencilState + } mtl; +} _sg_mtl_pipeline_t; +typedef _sg_mtl_pipeline_t _sg_pipeline_t; + +typedef struct _sg_view_s { + _sg_slot_t slot; + _sg_view_common_t cmn; + struct { + int tex_view[SG_NUM_INFLIGHT_FRAMES]; + } mtl; +} _sg_mtl_view_t; +typedef _sg_mtl_view_t _sg_view_t; + +// resource binding state cache +// +// NOTE: reserved buffer bindslot ranges: +// - 0..<=7: uniform buffer bindings +// - 8..<=22: storage buffer bindings +// - 23..<=30: vertex buffer bindings +// +#define _SG_MTL_MAX_STAGE_BUFFER_BINDINGS (31) // see: https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf +#define _SG_MTL_MAX_STAGE_UB_BINDINGS (_SG_MAX_UNIFORMBLOCK_BINDINGS_PER_STAGE) +#define _SG_MTL_MAX_STAGE_UB_SBUF_BINDINGS (_SG_MTL_MAX_STAGE_BUFFER_BINDINGS - SG_MAX_VERTEXBUFFER_BINDSLOTS) +#define _SG_MTL_MAX_STAGE_TEXTURE_BINDINGS (SG_MAX_VIEW_BINDSLOTS) +#define _SG_MTL_MAX_STAGE_SAMPLER_BINDINGS (SG_MAX_SAMPLER_BINDSLOTS) + +typedef struct { + _sg_sref_t sref; + int active_slot; + int offset; +} _sg_mtl_cache_buf_t; + +typedef struct { + _sg_sref_t sref; + int active_slot; +} _sg_mtl_cache_tex_t; + +typedef enum { + _SG_MTL_CACHE_CMP_EQUAL = 0, + _SG_MTL_CACHE_CMP_SREF = (1<<1), + _SG_MTL_CACHE_CMP_OFFSET = (1<<2), + _SG_MTL_CACHE_CMP_ACTIVESLOT = (1<<3), +} _sg_mtl_cache_cmp_result_t; + +typedef struct { + _sg_sref_t cur_pip; + _sg_buffer_ref_t cur_ibuf; + int cur_ibuf_offset; + _sg_mtl_cache_buf_t cur_vsbufs[_SG_MTL_MAX_STAGE_BUFFER_BINDINGS]; + _sg_mtl_cache_buf_t cur_fsbufs[_SG_MTL_MAX_STAGE_BUFFER_BINDINGS]; + _sg_mtl_cache_buf_t cur_csbufs[_SG_MTL_MAX_STAGE_BUFFER_BINDINGS]; + _sg_mtl_cache_tex_t cur_vstexs[_SG_MTL_MAX_STAGE_TEXTURE_BINDINGS]; + _sg_mtl_cache_tex_t cur_fstexs[_SG_MTL_MAX_STAGE_TEXTURE_BINDINGS]; + _sg_mtl_cache_tex_t cur_cstexs[_SG_MTL_MAX_STAGE_TEXTURE_BINDINGS]; + _sg_sref_t cur_vssmps[_SG_MTL_MAX_STAGE_SAMPLER_BINDINGS]; + _sg_sref_t cur_fssmps[_SG_MTL_MAX_STAGE_SAMPLER_BINDINGS]; + _sg_sref_t cur_cssmps[_SG_MTL_MAX_STAGE_SAMPLER_BINDINGS]; +} _sg_mtl_cache_t; + +typedef struct { + bool valid; + bool use_shared_storage_mode; + uint32_t cur_frame_rotate_index; + int ub_size; + int cur_ub_offset; + uint8_t* cur_ub_base_ptr; + _sg_mtl_cache_t cache; + _sg_mtl_idpool_t idpool; + dispatch_semaphore_t sem; + id device; + id cmd_queue; + id cmd_buffer; + id render_cmd_encoder; + id compute_cmd_encoder; + id cur_drawable; + id uniform_buffers[SG_NUM_INFLIGHT_FRAMES]; +} _sg_mtl_backend_t; + +#elif defined(SOKOL_WGPU) + +#define _SG_WGPU_ROWPITCH_ALIGN (256) +#define _SG_WGPU_MAX_UNIFORM_UPDATE_SIZE (1<<16) // also see WGPULimits.maxUniformBufferBindingSize +#define _SG_WGPU_MAX_BINDGROUPS (2) // 0: uniforms, 1: images, samplers, storage buffers, storage images +#define _SG_WGPU_UB_BINDGROUP_INDEX (0) +#define _SG_WGPU_VIEW_SMP_BINDGROUP_INDEX (1) +#define _SG_WGPU_MAX_UB_BINDGROUP_ENTRIES (SG_MAX_UNIFORMBLOCK_BINDSLOTS) +#define _SG_WGPU_MAX_UB_BINDGROUP_WGSL_SLOTS (2 * SG_MAX_UNIFORMBLOCK_BINDSLOTS) +#define _SG_WGPU_MAX_VIEW_SMP_BINDGROUP_ENTRIES (SG_MAX_VIEW_BINDSLOTS + SG_MAX_SAMPLER_BINDSLOTS) +#define _SG_WGPU_MAX_VIEW_SMP_BINDGROUP_WGSL_SLOTS (128) + +typedef struct _sg_buffer_s { + _sg_slot_t slot; + _sg_buffer_common_t cmn; + struct { + WGPUBuffer buf; + } wgpu; +} _sg_wgpu_buffer_t; +typedef _sg_wgpu_buffer_t _sg_buffer_t; + +typedef struct _sg_image_s { + _sg_slot_t slot; + _sg_image_common_t cmn; + struct { + WGPUTexture tex; + } wgpu; +} _sg_wgpu_image_t; +typedef _sg_wgpu_image_t _sg_image_t; + +typedef struct _sg_sampler_s { + _sg_slot_t slot; + _sg_sampler_common_t cmn; + struct { + WGPUSampler smp; + } wgpu; +} _sg_wgpu_sampler_t; +typedef _sg_wgpu_sampler_t _sg_sampler_t; + +typedef struct { + WGPUShaderModule module; + _sg_str_t entry; +} _sg_wgpu_shader_func_t; + +typedef struct _sg_shader_s { + _sg_slot_t slot; + _sg_shader_common_t cmn; + struct { + _sg_wgpu_shader_func_t vertex_func; + _sg_wgpu_shader_func_t fragment_func; + _sg_wgpu_shader_func_t compute_func; + WGPUBindGroupLayout bgl_ub; + WGPUBindGroup bg_ub; + WGPUBindGroupLayout bgl_view_smp; + // a mapping of sokol-gfx bind slots to setBindGroup dynamic-offset-array indices + uint8_t ub_num_dynoffsets; + uint8_t ub_dynoffsets[SG_MAX_UNIFORMBLOCK_BINDSLOTS]; + // indexed by sokol-gfx bind slot: + uint8_t ub_grp0_bnd_n[SG_MAX_UNIFORMBLOCK_BINDSLOTS]; + uint8_t view_grp1_bnd_n[SG_MAX_VIEW_BINDSLOTS]; + uint8_t smp_grp1_bnd_n[SG_MAX_SAMPLER_BINDSLOTS]; + } wgpu; +} _sg_wgpu_shader_t; +typedef _sg_wgpu_shader_t _sg_shader_t; + +typedef struct _sg_pipeline_s { + _sg_slot_t slot; + _sg_pipeline_common_t cmn; + struct { + WGPURenderPipeline rpip; + WGPUComputePipeline cpip; + WGPUColor blend_color; + } wgpu; +} _sg_wgpu_pipeline_t; +typedef _sg_wgpu_pipeline_t _sg_pipeline_t; + +typedef struct _sg_view_s { + _sg_slot_t slot; + _sg_view_common_t cmn; + struct { + WGPUTextureView view; + } wgpu; +} _sg_wgpu_view_t; +typedef _sg_wgpu_view_t _sg_view_t; + +// a pool of per-frame uniform buffers +typedef struct { + uint32_t num_bytes; + uint32_t offset; // current offset into buf + uint8_t* staging; // intermediate buffer for uniform data updates + WGPUBuffer buf; // the GPU-side uniform buffer + bool dirty; + uint32_t bind_offsets[SG_MAX_UNIFORMBLOCK_BINDSLOTS]; // NOTE: index is sokol-gfx ub slot index! +} _sg_wgpu_uniform_system_t; + +typedef struct { + uint32_t id; +} _sg_wgpu_bindgroup_handle_t; + +typedef enum { + _SG_WGPU_BINDGROUPSCACHEITEMTYPE_NONE = 0, + _SG_WGPU_BINDGROUPSCACHEITEMTYPE_VIEW = 1, + _SG_WGPU_BINDGROUPSCACHEITEMTYPE_SAMPLER = 2, + _SG_WGPU_BINDGROUPSCACHEITEMTYPE_PIPELINE = 3, +} _sg_wgpu_bindgroups_cache_item_type_t; + +#define _SG_WGPU_BINDGROUPSCACHEKEY_NUM_ITEMS (1 + _SG_WGPU_MAX_VIEW_SMP_BINDGROUP_ENTRIES) +typedef struct { + uint64_t hash; + // the format of cache key items is BBTCCCCCIIIIIIII + // where + // - BB: 8 bits WGPU binding + // - T: 2 bits _sg_wgpu_bindgroups_cache_item_type_t + // - CCCCC: 22 bits slot.uninit_count + // - IIIIIIII: 32 bits slot.id + // + // where the item type is a per-resource-type bit pattern + uint64_t items[_SG_WGPU_BINDGROUPSCACHEKEY_NUM_ITEMS]; +} _sg_wgpu_bindgroups_cache_key_t; + +typedef struct { + uint32_t num; // must be 2^n + uint32_t index_mask; // mask to turn hash into valid index + _sg_wgpu_bindgroup_handle_t* items; +} _sg_wgpu_bindgroups_cache_t; + +typedef struct { + _sg_slot_t slot; + WGPUBindGroup bindgroup; + _sg_wgpu_bindgroups_cache_key_t key; +} _sg_wgpu_bindgroup_t; + +typedef struct { + _sg_pool_t pool; + _sg_wgpu_bindgroup_t* bindgroups; +} _sg_wgpu_bindgroups_pool_t; + +typedef struct { + struct { + sg_buffer buffer; + uint64_t offset; + } vbs[SG_MAX_VERTEXBUFFER_BINDSLOTS]; + struct { + sg_buffer buffer; + uint64_t offset; + } ib; + _sg_wgpu_bindgroup_handle_t bg; +} _sg_wgpu_bindings_cache_t; + +// the WGPU backend state +typedef struct { + bool valid; + WGPUDevice dev; + WGPULimits limits; + WGPUQueue queue; + WGPUCommandEncoder cmd_enc; + WGPURenderPassEncoder rpass_enc; + WGPUComputePassEncoder cpass_enc; + _sg_wgpu_uniform_system_t uniform; + _sg_wgpu_bindings_cache_t bindings_cache; + _sg_wgpu_bindgroups_cache_t bindgroups_cache; + _sg_wgpu_bindgroups_pool_t bindgroups_pool; +} _sg_wgpu_backend_t; + +#elif defined(SOKOL_VULKAN) + +#define _SG_VK_MAX_UNIFORM_UPDATE_SIZE (1<<16) +#define _SG_VK_NUM_DESCRIPTORSETS (2) // 0: uniforms, 1: images, samplers, storage buffers, storage images +#define _SG_VK_UB_DESCRIPTORSET_INDEX (0) +#define _SG_VK_VIEW_SMP_DESCRIPTORSET_INDEX (1) +#define _SG_VK_MAX_UB_DESCRIPTORSET_ENTRIES (SG_MAX_UNIFORMBLOCK_BINDSLOTS) +#define _SG_VK_MAX_UB_DESCRIPTORSET_SLOTS (2 * SG_MAX_UNIFORMBLOCK_BINDSLOTS) +#define _SG_VK_MAX_VIEW_SMP_DESCRIPTORSET_ENTRIES (SG_MAX_VIEW_BINDSLOTS + SG_MAX_SAMPLER_BINDSLOTS) +#define _SG_VK_MAX_VIEW_SMP_DESCRIPTORSET_SLOTS (128) +#define _SG_VK_MAX_DESCRIPTOR_DATA_SIZE (256) // FIXME: llvmpipe needs 280 bytes, do we need to care about that? + +typedef enum { + _SG_VK_MEMTYPE_STORAGE_BUFFER, + _SG_VK_MEMTYPE_GENERIC_BUFFER, + _SG_VK_MEMTYPE_IMAGE, + _SG_VK_MEMTYPE_STAGING_COPY, + _SG_VK_MEMTYPE_STAGING_STREAM, + _SG_VK_MEMTYPE_UNIFORMS, + _SG_VK_MEMTYPE_DESCRIPTORS, +} _sg_vk_memtype_t; + +typedef void (*_sg_vk_delete_queue_destructor_t)(void* obj); + +typedef struct { + _sg_vk_delete_queue_destructor_t destructor; + void* obj; +} _sg_vk_delete_queue_item_t; + +typedef struct { + uint32_t index; + uint32_t num; + _sg_vk_delete_queue_item_t* items; +} _sg_vk_delete_queue_t; + +typedef enum { + _SG_VK_ACCESS_NONE = (0), // initial state for new resources + _SG_VK_ACCESS_STAGING = (1<<0), + _SG_VK_ACCESS_VERTEXBUFFER = (1<<1), + _SG_VK_ACCESS_INDEXBUFFER = (1<<2), + _SG_VK_ACCESS_STORAGEBUFFER_RO = (1<<3), + _SG_VK_ACCESS_STORAGEBUFFER_RW = (1<<4), + _SG_VK_ACCESS_TEXTURE = (1<<5), + _SG_VK_ACCESS_STORAGEIMAGE = (1<<6), + _SG_VK_ACCESS_COLOR_ATTACHMENT = (1<<7), + _SG_VK_ACCESS_RESOLVE_ATTACHMENT = (1<<8), + _SG_VK_ACCESS_DEPTH_ATTACHMENT = (1<<9), + _SG_VK_ACCESS_STENCIL_ATTACHMENT = (1<<10), + _SG_VK_ACCESS_DISCARD = (1<<11), // in combination with attachments + _SG_VK_ACCESS_PRESENT = (1<<12), +} _sg_vk_access_bits_t; +typedef int _sg_vk_access_t; + +typedef struct _sg_buffer_s { + _sg_slot_t slot; + _sg_buffer_common_t cmn; + struct { + VkBuffer buf; + VkDeviceMemory mem; + VkDeviceAddress dev_addr; // only valid for storage buffers + _sg_vk_access_t cur_access; + } vk; +} _sg_vk_buffer_t; +typedef _sg_vk_buffer_t _sg_buffer_t; + +typedef struct _sg_image_s { + _sg_slot_t slot; + _sg_image_common_t cmn; + struct { + VkImage img; + VkDeviceMemory mem; + _sg_vk_access_t cur_access; + } vk; +} _sg_vk_image_t; +typedef _sg_vk_image_t _sg_image_t; + +typedef struct _sg_sampler_s { + _sg_slot_t slot; + _sg_sampler_common_t cmn; + struct { + VkSampler smp; + size_t descriptor_size; + uint8_t descriptor_data[_SG_VK_MAX_DESCRIPTOR_DATA_SIZE]; + } vk; +} _sg_vk_sampler_t; +typedef _sg_vk_sampler_t _sg_sampler_t; + +typedef struct { + VkShaderModule module; + _sg_str_t entry; +} _sg_vk_shader_func_t; + +typedef struct _sg_shader_s { + _sg_slot_t slot; + _sg_shader_common_t cmn; + struct { + _sg_vk_shader_func_t vertex_func; + _sg_vk_shader_func_t fragment_func; + _sg_vk_shader_func_t compute_func; + VkDescriptorSetLayout ub_dsl; + VkDeviceSize ub_dset_size; + VkDescriptorSetLayout view_smp_dsl; + VkDeviceSize view_smp_dset_size; + VkPipelineLayout pip_layout; + // indexed by sokol-gfx bind-slot + uint8_t ub_set0_bnd_n[SG_MAX_UNIFORMBLOCK_BINDSLOTS]; + uint8_t view_set1_bnd_n[SG_MAX_VIEW_BINDSLOTS]; + uint8_t smp_set1_bnd_n[SG_MAX_SAMPLER_BINDSLOTS]; + // relative descriptor offsets to start of descriptor set in descriptor buffer + uint16_t ub_dset_offsets[SG_MAX_UNIFORMBLOCK_BINDSLOTS]; + uint16_t view_dset_offsets[SG_MAX_VIEW_BINDSLOTS]; + uint16_t smp_dset_offsets[SG_MAX_SAMPLER_BINDSLOTS]; + } vk; +} _sg_vk_shader_t; +typedef _sg_vk_shader_t _sg_shader_t; + +typedef struct _sg_pipeline_s { + _sg_slot_t slot; + _sg_pipeline_common_t cmn; + struct { + VkPipeline pip; + } vk; +} _sg_vk_pipeline_t; +typedef _sg_vk_pipeline_t _sg_pipeline_t; + +typedef struct _sg_view_s { + _sg_slot_t slot; + _sg_view_common_t cmn; + struct { + VkImageView img_view; + size_t descriptor_size; + uint8_t descriptor_data[_SG_VK_MAX_DESCRIPTOR_DATA_SIZE]; + } vk; +} _sg_vk_view_t; +typedef _sg_vk_view_t _sg_view_t; + +// a double-buffer cpu-write / gpu-read buffer +#define _SG_VK_SHARED_BUFFER_OVERFLOW_RESULT (0xFFFFFFFF) +typedef struct { + uint32_t size; // buffer size + uint32_t align; // required buffer offset alignemnt + uint32_t offset; // current offset into buffer + VkBuffer cur_buf; // currently mapped buffer + void* cur_mem_ptr; // current pointer into currently mapped buffer + VkDeviceAddress cur_dev_addr; // current buffer device address (only valid for some buffer types) + bool overflown; // true when in overflown state + struct { + VkBuffer buf; + VkDeviceMemory mem; + VkDeviceAddress dev_addr; // only valid for some buffer types! + void* mem_ptr; + } slots[SG_NUM_INFLIGHT_FRAMES]; +} _sg_vk_shared_buffer_t; + +typedef struct { + bool valid; + VkInstance instance; + VkPhysicalDevice phys_dev; + VkDevice dev; + VkQueue queue; + uint32_t queue_family_index; + sg_vulkan_swapchain swapchain; + VkSemaphore present_complete_sem; + VkSemaphore render_finished_sem; + + // extension function pointers + struct { + PFN_vkSetDebugUtilsObjectNameEXT set_debug_utils_object_name_ext; + PFN_vkGetDescriptorSetLayoutSizeEXT get_descriptor_set_layout_size; + PFN_vkGetDescriptorSetLayoutBindingOffsetEXT get_descriptor_set_layout_binding_offset; + PFN_vkGetDescriptorEXT get_descriptor; + PFN_vkCmdBindDescriptorBuffersEXT cmd_bind_descriptor_buffers; + PFN_vkCmdSetDescriptorBufferOffsetsEXT cmd_set_descriptor_buffer_offsets; + } ext; + + uint32_t frame_slot; + struct { + VkCommandPool cmd_pool; + VkCommandBuffer cmd_buf; + VkCommandBuffer stream_cmd_buf; + struct { + VkFence fence; + VkCommandBuffer command_buffer; + VkCommandBuffer stream_command_buffer; + _sg_vk_delete_queue_t delete_queue; + } slot[SG_NUM_INFLIGHT_FRAMES]; + } frame; + // staging system + struct { + // staging system for immutable and dynamic resources, generally causes a stall + struct { + VkCommandPool cmd_pool; + VkCommandBuffer cmd_buf; + uint32_t size; + VkBuffer buf; + VkDeviceMemory mem; + } copy; + // staging buffer for per-frame streaming updates + _sg_vk_shared_buffer_t stream; + } stage; + // uniform update system + struct { + bool dirty; + _sg_vk_shared_buffer_t dbuf; // descriptor buffer + VkDescriptorAddressInfoEXT addr_info[SG_MAX_UNIFORMBLOCK_BINDSLOTS]; + VkDescriptorGetInfoEXT get_info[SG_MAX_UNIFORMBLOCK_BINDSLOTS]; + size_t dset_cache_size; + uint8_t* dset_cache; + } uniforms; + // resource binding system (using descriptor buffers) + _sg_vk_shared_buffer_t bind; + // hazard tracking system for buffers and images + struct { + _sg_track_t buffers; + _sg_track_t images; + } track; + // device properties and features (initialized at startup) + VkPhysicalDeviceProperties2 dev_props; + VkPhysicalDeviceDescriptorBufferPropertiesEXT descriptor_buffer_props; + VkPhysicalDeviceFeatures2 dev_features; +} _sg_vk_backend_t; + +#endif // SOKOL_VULKAN + +// this *MUST* remain 0 +#define _SG_INVALID_SLOT_INDEX (0) + +typedef struct _sg_pools_s { + _sg_pool_t buffer_pool; + _sg_pool_t image_pool; + _sg_pool_t sampler_pool; + _sg_pool_t shader_pool; + _sg_pool_t pipeline_pool; + _sg_pool_t view_pool; + _sg_buffer_t* buffers; + _sg_image_t* images; + _sg_sampler_t* samplers; + _sg_shader_t* shaders; + _sg_pipeline_t* pipelines; + _sg_view_t* views; +} _sg_pools_t; + +typedef struct { + int num; // number of allocated commit listener items + int upper; // the current upper index (no valid items past this point) + sg_commit_listener* items; +} _sg_commit_listeners_t; + +// resolved pass attachments struct +typedef struct { + bool empty; + int num_color_views; + _sg_view_t* color_views[SG_MAX_COLOR_ATTACHMENTS]; + _sg_view_t* resolve_views[SG_MAX_COLOR_ATTACHMENTS]; + _sg_view_t* ds_view; +} _sg_attachments_ptrs_t; + +// resolved resource bindings struct +typedef struct { + _sg_pipeline_t* pip; + int vb_offsets[SG_MAX_VERTEXBUFFER_BINDSLOTS]; + int ib_offset; + _sg_buffer_t* vbs[SG_MAX_VERTEXBUFFER_BINDSLOTS]; + _sg_buffer_t* ib; + _sg_view_t* views[SG_MAX_VIEW_BINDSLOTS]; + _sg_sampler_t* smps[SG_MAX_SAMPLER_BINDSLOTS]; +} _sg_bindings_ptrs_t; + +typedef struct { + bool sample; + bool filter; + bool render; + bool blend; + bool msaa; + bool depth; + bool read; + bool write; +} _sg_pixelformat_info_t; + +typedef struct { + bool valid; + sg_desc desc; // original desc with default values patched in + uint32_t frame_index; + struct { + bool valid; + bool in_pass; + bool is_compute; + _sg_dimi_t dim; + sg_attachments atts; + sg_pass_action action; + struct { + bool invalid; + sg_pixel_format color_fmt; + sg_pixel_format depth_fmt; + int sample_count; + } swapchain; + } cur_pass; + _sg_pipeline_ref_t cur_pip; + bool next_draw_valid; + bool use_indexed_draw; + bool use_instanced_draw; + uint32_t required_bindings_and_uniforms; // used to check that bindings and uniforms are applied after applying pipeline + uint32_t applied_bindings_and_uniforms; // bits 0..7: uniform blocks, bit 8: bindings + #if defined(SOKOL_DEBUG) + sg_log_item validate_error; + #endif + _sg_pools_t pools; + sg_backend backend; + sg_features features; + sg_limits limits; + _sg_pixelformat_info_t formats[_SG_PIXELFORMAT_NUM]; + bool stats_enabled; + sg_stats stats; + #if defined(_SOKOL_ANY_GL) + _sg_gl_backend_t gl; + #elif defined(SOKOL_METAL) + _sg_mtl_backend_t mtl; + #elif defined(SOKOL_D3D11) + _sg_d3d11_backend_t d3d11; + #elif defined(SOKOL_WGPU) + _sg_wgpu_backend_t wgpu; + #elif defined(SOKOL_VULKAN) + _sg_vk_backend_t vk; + #endif + #if defined(SOKOL_TRACE_HOOKS) + sg_trace_hooks hooks; + #endif + _sg_commit_listeners_t commit_listeners; +} _sg_state_t; +static _sg_state_t _sg; + +// ██ ██████ ██████ ██████ ██ ███ ██ ██████ +// ██ ██ ██ ██ ██ ██ ████ ██ ██ +// ██ ██ ██ ██ ███ ██ ███ ██ ██ ██ ██ ██ ███ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ███████ ██████ ██████ ██████ ██ ██ ████ ██████ +// +// >>logging +#if defined(SOKOL_DEBUG) +#define _SG_LOGITEM_XMACRO(item,msg) #item ": " msg, +static const char* _sg_log_messages[] = { + _SG_LOG_ITEMS +}; +#undef _SG_LOGITEM_XMACRO +#endif // SOKOL_DEBUG + +#define _SG_PANIC(code) _sg_log(SG_LOGITEM_ ##code, 0, 0, __LINE__) +#define _SG_ERROR(code) _sg_log(SG_LOGITEM_ ##code, 1, 0, __LINE__) +#define _SG_WARN(code) _sg_log(SG_LOGITEM_ ##code, 2, 0, __LINE__) +#define _SG_INFO(code) _sg_log(SG_LOGITEM_ ##code, 3, 0, __LINE__) +#define _SG_LOGMSG(code,msg) _sg_log(SG_LOGITEM_ ##code, 3, msg, __LINE__) +#define _SG_VALIDATE(cond,code) if (!(cond)){ _sg.validate_error = SG_LOGITEM_ ##code; _sg_log(SG_LOGITEM_ ##code, 1, 0, __LINE__); } + +static void _sg_log(sg_log_item log_item, uint32_t log_level, const char* msg, uint32_t line_nr) { + if (_sg.desc.logger.func) { + const char* filename = 0; + #if defined(SOKOL_DEBUG) + filename = __FILE__; + if (0 == msg) { + msg = _sg_log_messages[log_item]; + } + #endif + _sg.desc.logger.func("sg", log_level, (uint32_t)log_item, msg, line_nr, filename, _sg.desc.logger.user_data); + } else { + // for log level PANIC it would be 'undefined behaviour' to continue + if (log_level == 0) { + abort(); + } + } +} + +// ███ ███ ███████ ███ ███ ██████ ██████ ██ ██ +// ████ ████ ██ ████ ████ ██ ██ ██ ██ ██ ██ +// ██ ████ ██ █████ ██ ████ ██ ██ ██ ██████ ████ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ██ ██ ███████ ██ ██ ██████ ██ ██ ██ +// +// >>memory + +_SOKOL_PRIVATE int _sg_roundup(int val, int round_to) { + return (val+(round_to-1)) & ~(round_to-1); +} + +_SOKOL_PRIVATE uint32_t _sg_roundup_u32(uint32_t val, uint32_t round_to) { + return (val+(round_to-1)) & ~(round_to-1); +} + +_SOKOL_PRIVATE uint64_t _sg_roundup_u64(uint64_t val, uint64_t round_to) { + return (val+(round_to-1)) & ~(round_to-1); +} + +_SOKOL_PRIVATE bool _sg_multiple_u64(uint64_t val, uint64_t of) { + return (val & (of-1)) == 0; +} + +// a helper macro to clear a struct with potentially ARC'ed ObjC references +#if defined(SOKOL_METAL) + #if defined(__cplusplus) + #define _SG_CLEAR_ARC_STRUCT(type, item) { item = type(); } + #else + #define _SG_CLEAR_ARC_STRUCT(type, item) { item = (type) { 0 }; } + #endif +#else + #define _SG_CLEAR_ARC_STRUCT(type, item) { _sg_clear(&item, sizeof(item)); } +#endif + +_SOKOL_PRIVATE void _sg_clear(void* ptr, size_t size) { + SOKOL_ASSERT(ptr && (size > 0)); + memset(ptr, 0, size); +} + +_SOKOL_PRIVATE void* _sg_malloc(size_t size) { + SOKOL_ASSERT(size > 0); + void* ptr; + if (_sg.desc.allocator.alloc_fn) { + ptr = _sg.desc.allocator.alloc_fn(size, _sg.desc.allocator.user_data); + } else { + ptr = malloc(size); + } + if (0 == ptr) { + _SG_PANIC(MALLOC_FAILED); + } + return ptr; +} + +_SOKOL_PRIVATE void* _sg_malloc_clear(size_t size) { + void* ptr = _sg_malloc(size); + _sg_clear(ptr, size); + return ptr; +} + +_SOKOL_PRIVATE void _sg_free(void* ptr) { + if (_sg.desc.allocator.free_fn) { + _sg.desc.allocator.free_fn(ptr, _sg.desc.allocator.user_data); + } else { + free(ptr); + } +} + +_SOKOL_PRIVATE bool _sg_strempty(const _sg_str_t* str) { + return 0 == str->buf[0]; +} + +_SOKOL_PRIVATE const char* _sg_strptr(const _sg_str_t* str) { + return &str->buf[0]; +} + +_SOKOL_PRIVATE void _sg_strcpy(_sg_str_t* dst, const char* src) { + SOKOL_ASSERT(dst); + if (src) { + #if defined(_MSC_VER) + strncpy_s(dst->buf, _SG_STRING_SIZE, src, (_SG_STRING_SIZE-1)); + #else + strncpy(dst->buf, src, _SG_STRING_SIZE); + #endif + dst->buf[_SG_STRING_SIZE-1] = 0; + } else { + _sg_clear(dst->buf, _SG_STRING_SIZE); + } +} + +// ██████ ██████ ██████ ██ +// ██ ██ ██ ██ ██ ██ ██ +// ██████ ██ ██ ██ ██ ██ +// ██ ██ ██ ██ ██ ██ +// ██ ██████ ██████ ███████ +// +// >>pool +_SOKOL_PRIVATE void _sg_pool_init(_sg_pool_t* pool, int num) { + SOKOL_ASSERT(pool && (num >= 1)); + // slot 0 is reserved for the 'invalid id', so bump the pool size by 1 + pool->size = num + 1; + pool->queue_top = 0; + // generation counters indexable by pool slot index, slot 0 is reserved + size_t gen_ctrs_size = sizeof(uint32_t) * (size_t)pool->size; + pool->gen_ctrs = (uint32_t*)_sg_malloc_clear(gen_ctrs_size); + // it's not a bug to only reserve 'num' here + pool->free_queue = (int*) _sg_malloc_clear(sizeof(int) * (size_t)num); + // never allocate the zero-th pool item since the invalid id is 0 + for (int i = pool->size-1; i >= 1; i--) { + pool->free_queue[pool->queue_top++] = i; + } +} + +_SOKOL_PRIVATE void _sg_pool_discard(_sg_pool_t* pool) { + SOKOL_ASSERT(pool); + SOKOL_ASSERT(pool->free_queue); + _sg_free(pool->free_queue); + pool->free_queue = 0; + SOKOL_ASSERT(pool->gen_ctrs); + _sg_free(pool->gen_ctrs); + pool->gen_ctrs = 0; + pool->size = 0; + pool->queue_top = 0; +} + +_SOKOL_PRIVATE int _sg_pool_alloc_index(_sg_pool_t* pool) { + SOKOL_ASSERT(pool); + SOKOL_ASSERT(pool->free_queue); + if (pool->queue_top > 0) { + int slot_index = pool->free_queue[--pool->queue_top]; + SOKOL_ASSERT((slot_index > 0) && (slot_index < pool->size)); + return slot_index; + } else { + // pool exhausted + return _SG_INVALID_SLOT_INDEX; + } +} + +_SOKOL_PRIVATE void _sg_pool_free_index(_sg_pool_t* pool, int slot_index) { + SOKOL_ASSERT((slot_index > _SG_INVALID_SLOT_INDEX) && (slot_index < pool->size)); + SOKOL_ASSERT(pool); + SOKOL_ASSERT(pool->free_queue); + SOKOL_ASSERT(pool->queue_top < pool->size); + #ifdef SOKOL_DEBUG + // debug check against double-free + for (int i = 0; i < pool->queue_top; i++) { + SOKOL_ASSERT(pool->free_queue[i] != slot_index); + } + #endif + pool->free_queue[pool->queue_top++] = slot_index; + SOKOL_ASSERT(pool->queue_top <= (pool->size-1)); +} + +_SOKOL_PRIVATE void _sg_slot_reset(_sg_slot_t* slot) { + SOKOL_ASSERT(slot); + _sg_clear(slot, sizeof(_sg_slot_t)); +} + +_SOKOL_PRIVATE void _sg_reset_buffer_to_alloc_state(_sg_buffer_t* buf) { + SOKOL_ASSERT(buf); + _sg_slot_t slot = buf->slot; + _sg_clear(buf, sizeof(*buf)); + buf->slot = slot; + buf->slot.uninit_count += 1; + buf->slot.state = SG_RESOURCESTATE_ALLOC; +} + +_SOKOL_PRIVATE void _sg_reset_image_to_alloc_state(_sg_image_t* img) { + SOKOL_ASSERT(img); + _sg_slot_t slot = img->slot; + _sg_clear(img, sizeof(*img)); + img->slot = slot; + img->slot.uninit_count += 1; + img->slot.state = SG_RESOURCESTATE_ALLOC; +} + +_SOKOL_PRIVATE void _sg_reset_sampler_to_alloc_state(_sg_sampler_t* smp) { + SOKOL_ASSERT(smp); + _sg_slot_t slot = smp->slot; + _sg_clear(smp, sizeof(*smp)); + smp->slot = slot; + smp->slot.uninit_count += 1; + smp->slot.state = SG_RESOURCESTATE_ALLOC; +} + +_SOKOL_PRIVATE void _sg_reset_shader_to_alloc_state(_sg_shader_t* shd) { + SOKOL_ASSERT(shd); + _sg_slot_t slot = shd->slot; + _sg_clear(shd, sizeof(*shd)); + shd->slot = slot; + shd->slot.uninit_count += 1; + shd->slot.state = SG_RESOURCESTATE_ALLOC; +} + +_SOKOL_PRIVATE void _sg_reset_pipeline_to_alloc_state(_sg_pipeline_t* pip) { + SOKOL_ASSERT(pip); + _sg_slot_t slot = pip->slot; + _sg_clear(pip, sizeof(*pip)); + pip->slot = slot; + pip->slot.uninit_count += 1; + pip->slot.state = SG_RESOURCESTATE_ALLOC; +} + +_SOKOL_PRIVATE void _sg_reset_view_to_alloc_state(_sg_view_t* view) { + SOKOL_ASSERT(view); + _sg_slot_t slot = view->slot; + _sg_clear(view, sizeof(*view)); + view->slot = slot; + view->slot.uninit_count += 1; + view->slot.state = SG_RESOURCESTATE_ALLOC; +} + +_SOKOL_PRIVATE void _sg_setup_pools(_sg_pools_t* p, const sg_desc* desc) { + SOKOL_ASSERT(p); + SOKOL_ASSERT(desc); + // note: the pools here will have an additional item, since slot 0 is reserved + SOKOL_ASSERT((desc->buffer_pool_size > 0) && (desc->buffer_pool_size < _SG_MAX_POOL_SIZE)); + _sg_pool_init(&p->buffer_pool, desc->buffer_pool_size); + size_t buffer_pool_byte_size = sizeof(_sg_buffer_t) * (size_t)p->buffer_pool.size; + p->buffers = (_sg_buffer_t*) _sg_malloc_clear(buffer_pool_byte_size); + + SOKOL_ASSERT((desc->image_pool_size > 0) && (desc->image_pool_size < _SG_MAX_POOL_SIZE)); + _sg_pool_init(&p->image_pool, desc->image_pool_size); + size_t image_pool_byte_size = sizeof(_sg_image_t) * (size_t)p->image_pool.size; + p->images = (_sg_image_t*) _sg_malloc_clear(image_pool_byte_size); + + SOKOL_ASSERT((desc->sampler_pool_size > 0) && (desc->sampler_pool_size < _SG_MAX_POOL_SIZE)); + _sg_pool_init(&p->sampler_pool, desc->sampler_pool_size); + size_t sampler_pool_byte_size = sizeof(_sg_sampler_t) * (size_t)p->sampler_pool.size; + p->samplers = (_sg_sampler_t*) _sg_malloc_clear(sampler_pool_byte_size); + + SOKOL_ASSERT((desc->shader_pool_size > 0) && (desc->shader_pool_size < _SG_MAX_POOL_SIZE)); + _sg_pool_init(&p->shader_pool, desc->shader_pool_size); + size_t shader_pool_byte_size = sizeof(_sg_shader_t) * (size_t)p->shader_pool.size; + p->shaders = (_sg_shader_t*) _sg_malloc_clear(shader_pool_byte_size); + + SOKOL_ASSERT((desc->pipeline_pool_size > 0) && (desc->pipeline_pool_size < _SG_MAX_POOL_SIZE)); + _sg_pool_init(&p->pipeline_pool, desc->pipeline_pool_size); + size_t pipeline_pool_byte_size = sizeof(_sg_pipeline_t) * (size_t)p->pipeline_pool.size; + p->pipelines = (_sg_pipeline_t*) _sg_malloc_clear(pipeline_pool_byte_size); + + SOKOL_ASSERT((desc->view_pool_size > 0) && (desc->view_pool_size < _SG_MAX_POOL_SIZE)); + _sg_pool_init(&p->view_pool, desc->view_pool_size); + size_t view_pool_byte_size = sizeof(_sg_view_t) * (size_t)p->view_pool.size; + p->views = (_sg_view_t*) _sg_malloc_clear(view_pool_byte_size); +} + +_SOKOL_PRIVATE void _sg_discard_pools(_sg_pools_t* p) { + SOKOL_ASSERT(p); + _sg_free(p->views); p->views = 0; + _sg_free(p->pipelines); p->pipelines = 0; + _sg_free(p->shaders); p->shaders = 0; + _sg_free(p->samplers); p->samplers = 0; + _sg_free(p->images); p->images = 0; + _sg_free(p->buffers); p->buffers = 0; + _sg_pool_discard(&p->view_pool); + _sg_pool_discard(&p->pipeline_pool); + _sg_pool_discard(&p->shader_pool); + _sg_pool_discard(&p->sampler_pool); + _sg_pool_discard(&p->image_pool); + _sg_pool_discard(&p->buffer_pool); +} + +/* allocate the slot at slot_index: + - bump the slot's generation counter + - create a resource id from the generation counter and slot index + - set the slot's id to this id + - set the slot's state to ALLOC + - return the resource id +*/ +_SOKOL_PRIVATE uint32_t _sg_slot_alloc(_sg_pool_t* pool, _sg_slot_t* slot, int slot_index) { + /* FIXME: add handling for an overflowing generation counter, + for now, just overflow (another option is to disable + the slot) + */ + SOKOL_ASSERT(pool && pool->gen_ctrs); + SOKOL_ASSERT((slot_index > _SG_INVALID_SLOT_INDEX) && (slot_index < pool->size)); + SOKOL_ASSERT(slot->id == SG_INVALID_ID); + SOKOL_ASSERT(slot->state == SG_RESOURCESTATE_INITIAL); + uint32_t ctr = ++pool->gen_ctrs[slot_index]; + slot->id = (ctr<<_SG_SLOT_SHIFT)|(slot_index & _SG_SLOT_MASK); + slot->state = SG_RESOURCESTATE_ALLOC; + return slot->id; +} + +// extract slot index from id +_SOKOL_PRIVATE int _sg_slot_index(uint32_t id) { + int slot_index = (int) (id & _SG_SLOT_MASK); + SOKOL_ASSERT(_SG_INVALID_SLOT_INDEX != slot_index); + return slot_index; +} + +// returns pointer to resource by id without matching id check +_SOKOL_PRIVATE _sg_buffer_t* _sg_buffer_at(uint32_t buf_id) { + SOKOL_ASSERT(SG_INVALID_ID != buf_id); + int slot_index = _sg_slot_index(buf_id); + SOKOL_ASSERT((slot_index > _SG_INVALID_SLOT_INDEX) && (slot_index < _sg.pools.buffer_pool.size)); + return &_sg.pools.buffers[slot_index]; +} + +_SOKOL_PRIVATE _sg_image_t* _sg_image_at(uint32_t img_id) { + SOKOL_ASSERT(SG_INVALID_ID != img_id); + int slot_index = _sg_slot_index(img_id); + SOKOL_ASSERT((slot_index > _SG_INVALID_SLOT_INDEX) && (slot_index < _sg.pools.image_pool.size)); + return &_sg.pools.images[slot_index]; +} + +_SOKOL_PRIVATE _sg_sampler_t* _sg_sampler_at(uint32_t smp_id) { + SOKOL_ASSERT(SG_INVALID_ID != smp_id); + int slot_index = _sg_slot_index(smp_id); + SOKOL_ASSERT((slot_index > _SG_INVALID_SLOT_INDEX) && (slot_index < _sg.pools.sampler_pool.size)); + return &_sg.pools.samplers[slot_index]; +} + +_SOKOL_PRIVATE _sg_shader_t* _sg_shader_at(uint32_t shd_id) { + SOKOL_ASSERT(SG_INVALID_ID != shd_id); + int slot_index = _sg_slot_index(shd_id); + SOKOL_ASSERT((slot_index > _SG_INVALID_SLOT_INDEX) && (slot_index < _sg.pools.shader_pool.size)); + return &_sg.pools.shaders[slot_index]; +} + +_SOKOL_PRIVATE _sg_pipeline_t* _sg_pipeline_at(uint32_t pip_id) { + SOKOL_ASSERT(SG_INVALID_ID != pip_id); + int slot_index = _sg_slot_index(pip_id); + SOKOL_ASSERT((slot_index > _SG_INVALID_SLOT_INDEX) && (slot_index < _sg.pools.pipeline_pool.size)); + return &_sg.pools.pipelines[slot_index]; +} + +_SOKOL_PRIVATE _sg_view_t* _sg_view_at(uint32_t view_id) { + SOKOL_ASSERT(SG_INVALID_ID != view_id); + int slot_index = _sg_slot_index(view_id); + SOKOL_ASSERT((slot_index > _SG_INVALID_SLOT_INDEX) && (slot_index < _sg.pools.view_pool.size)); + return &_sg.pools.views[slot_index]; +} + +// returns pointer to resource with matching id check, may return 0 +_SOKOL_PRIVATE _sg_buffer_t* _sg_lookup_buffer(uint32_t buf_id) { + if (SG_INVALID_ID != buf_id) { + _sg_buffer_t* buf = _sg_buffer_at(buf_id); + if (buf->slot.id == buf_id) { + return buf; + } + } + return 0; +} + +_SOKOL_PRIVATE _sg_image_t* _sg_lookup_image(uint32_t img_id) { + if (SG_INVALID_ID != img_id) { + _sg_image_t* img = _sg_image_at(img_id); + if (img->slot.id == img_id) { + return img; + } + } + return 0; +} + +_SOKOL_PRIVATE _sg_sampler_t* _sg_lookup_sampler(uint32_t smp_id) { + if (SG_INVALID_ID != smp_id) { + _sg_sampler_t* smp = _sg_sampler_at(smp_id); + if (smp->slot.id == smp_id) { + return smp; + } + } + return 0; +} + +_SOKOL_PRIVATE _sg_shader_t* _sg_lookup_shader(uint32_t shd_id) { + if (SG_INVALID_ID != shd_id) { + _sg_shader_t* shd = _sg_shader_at(shd_id); + if (shd->slot.id == shd_id) { + return shd; + } + } + return 0; +} + +_SOKOL_PRIVATE _sg_pipeline_t* _sg_lookup_pipeline(uint32_t pip_id) { + if (SG_INVALID_ID != pip_id) { + _sg_pipeline_t* pip = _sg_pipeline_at(pip_id); + if (pip->slot.id == pip_id) { + return pip; + } + } + return 0; +} + +_SOKOL_PRIVATE _sg_view_t* _sg_lookup_view(uint32_t view_id) { + if (SG_INVALID_ID != view_id) { + _sg_view_t* view = _sg_view_at(view_id); + if (view->slot.id == view_id) { + return view; + } + } + return 0; +} + +// ████████ ██████ █████ ██████ ██ ██ +// ██ ██ ██ ██ ██ ██ ██ ██ +// ██ ██████ ███████ ██ █████ +// ██ ██ ██ ██ ██ ██ ██ ██ +// ██ ██ ██ ██ ██ ██████ ██ ██ +// +// >>track +_SOKOL_PRIVATE void _sg_track_init(_sg_track_t* track, int num_slots) { + SOKOL_ASSERT(track && (num_slots > 0)); + _sg_clear(track, sizeof(_sg_track_t)); + track->num_slots = num_slots; + track->slots = (uint32_t*)_sg_malloc_clear((size_t)num_slots * sizeof(uint32_t)); + track->occupy_num_bytes = _sg_roundup_u32((uint32_t)num_slots, 8) >> 3; + track->occupy_bits = (uint8_t*)_sg_malloc_clear(track->occupy_num_bytes); +} + +_SOKOL_PRIVATE void _sg_track_discard(_sg_track_t* track) { + SOKOL_ASSERT(track); + if (track->slots) { + _sg_free(track->slots); + track->slots = 0; + } + if (track->occupy_bits) { + _sg_free(track->occupy_bits); + track->occupy_num_bytes = 0; + track->occupy_bits = 0; + } + track->num_slots = 0; + track->cur_slot = 0; +} + +_SOKOL_PRIVATE void _sg_track_reset(_sg_track_t* track) { + SOKOL_ASSERT(track && track->slots && track->occupy_bits); + track->cur_slot = 0; + _sg_clear(track->occupy_bits, track->occupy_num_bytes); +} + +_SOKOL_PRIVATE int _sg_track_occupy_index(int slot_index) { + const int occupy_index = slot_index >> 3; + return occupy_index; +} + +_SOKOL_PRIVATE uint8_t _sg_track_occupy_mask(int slot_index) { + return (uint8_t)(1 << (slot_index & 7)); +} + +_SOKOL_PRIVATE void _sg_track_add(_sg_track_t* track, uint32_t id) { + SOKOL_ASSERT(track && track->slots && track->occupy_bits); + SOKOL_ASSERT(id != SG_INVALID_ID); + const int slot_index = _sg_slot_index(id); + const int occupy_index = _sg_track_occupy_index(slot_index); + SOKOL_ASSERT((uint32_t)occupy_index < track->occupy_num_bytes); + const uint8_t occupy_mask = _sg_track_occupy_mask(slot_index); + // don't record the same resource twice + if (0 == (track->occupy_bits[occupy_index] & occupy_mask)) { + SOKOL_ASSERT(track->cur_slot < track->num_slots); + track->slots[track->cur_slot++] = id; + track->occupy_bits[occupy_index] |= occupy_mask; + } +} + +_SOKOL_PRIVATE void _sg_track_remove(_sg_track_t* track, uint32_t id) { + SOKOL_ASSERT(track && track->slots && track->occupy_bits); + SOKOL_ASSERT(id != SG_INVALID_ID); + const int slot_index = _sg_slot_index(id); + const int occupy_index = _sg_track_occupy_index(slot_index); + const uint8_t occupy_mask = _sg_track_occupy_mask(slot_index); + if (track->occupy_bits[occupy_index] & occupy_mask) { + track->occupy_bits[occupy_index] &= ~occupy_mask; + // remove tracked id from the slots array + for (int i = 0; i < track->cur_slot; i++) { + if (id == track->slots[i]) { + SOKOL_ASSERT(track->cur_slot > 0); + track->slots[i] = track->slots[--track->cur_slot]; + break; + } + } + } +} + +// ██████ ███████ ███████ ███████ +// ██ ██ ██ ██ ██ +// ██████ █████ █████ ███████ +// ██ ██ ██ ██ ██ +// ██ ██ ███████ ██ ███████ +// +// >>refs +_SOKOL_PRIVATE _sg_sref_t _sg_sref(const _sg_slot_t* slot) { + _SG_STRUCT(_sg_sref_t, sref); + if (slot) { + sref.id = slot->id; + sref.uninit_count = slot->uninit_count; + } + return sref; +} + +_SOKOL_PRIVATE bool _sg_sref_slot_eql(const _sg_sref_t* sref, const _sg_slot_t* slot) { + SOKOL_ASSERT(sref && slot); + return (sref->id == slot->id) && (sref->uninit_count == slot->uninit_count); +} + +_SOKOL_PRIVATE bool _sg_sref_sref_eql(const _sg_sref_t* sref0, const _sg_sref_t* sref1) { + SOKOL_ASSERT(sref0 && sref1); + return (sref0->id == sref1->id) && (sref0->uninit_count == sref1->uninit_count); +} + +_SOKOL_PRIVATE _sg_buffer_ref_t _sg_buffer_ref(_sg_buffer_t* buf_or_null) { + _SG_STRUCT(_sg_buffer_ref_t, ref); + if (buf_or_null) { + _sg_buffer_t* buf = buf_or_null; + SOKOL_ASSERT(buf->slot.id != SG_INVALID_ID); + ref.ptr = buf; + ref.sref = _sg_sref(&buf->slot); + } + return ref; +} + +_SOKOL_PRIVATE _sg_image_ref_t _sg_image_ref(_sg_image_t* img_or_null) { + _SG_STRUCT(_sg_image_ref_t, ref); + if (img_or_null) { + _sg_image_t* img = img_or_null; + SOKOL_ASSERT(img->slot.id != SG_INVALID_ID); + ref.ptr = img; + ref.sref = _sg_sref(&img->slot); + } + return ref; +} + +_SOKOL_PRIVATE _sg_sampler_ref_t _sg_sampler_ref(_sg_sampler_t* smp_or_null) { + _SG_STRUCT(_sg_sampler_ref_t, ref); + if (smp_or_null) { + _sg_sampler_t* smp = smp_or_null; + SOKOL_ASSERT(smp->slot.id != SG_INVALID_ID); + ref.ptr = smp; + ref.sref = _sg_sref(&smp->slot); + } + return ref; +} + +_SOKOL_PRIVATE _sg_shader_ref_t _sg_shader_ref(_sg_shader_t* shd_or_null) { + _SG_STRUCT(_sg_shader_ref_t, ref); + if (shd_or_null) { + _sg_shader_t* shd = shd_or_null; + SOKOL_ASSERT(shd->slot.id != SG_INVALID_ID); + ref.ptr = shd; + ref.sref = _sg_sref(&shd->slot); + } + return ref; +} + +_SOKOL_PRIVATE _sg_pipeline_ref_t _sg_pipeline_ref(_sg_pipeline_t* pip_or_null) { + _SG_STRUCT(_sg_pipeline_ref_t, ref); + if (pip_or_null) { + _sg_pipeline_t* pip = pip_or_null; + SOKOL_ASSERT(pip->slot.id != SG_INVALID_ID); + ref.ptr = pip; + ref.sref = _sg_sref(&pip->slot); + } + return ref; +} + +_SOKOL_PRIVATE _sg_view_ref_t _sg_view_ref(_sg_view_t* view_or_null) { + _SG_STRUCT(_sg_view_ref_t, ref); + if (view_or_null) { + _sg_view_t* view = view_or_null; + SOKOL_ASSERT(view->slot.id != SG_INVALID_ID); + ref.ptr = view; + ref.sref = _sg_sref(&view->slot); + } + return ref; +} + +#define _SG_IMPL_RES_EQL(NAME,REF,RES) _SOKOL_PRIVATE bool NAME(const REF* ref, const RES* res) { SOKOL_ASSERT(ref && res); return _sg_sref_slot_eql(&ref->sref, &res->slot); } +_SG_IMPL_RES_EQL(_sg_buffer_ref_eql, _sg_buffer_ref_t, _sg_buffer_t) +_SG_IMPL_RES_EQL(_sg_image_ref_eql, _sg_image_ref_t, _sg_image_t) +_SG_IMPL_RES_EQL(_sg_sampler_ref_eql, _sg_sampler_ref_t, _sg_sampler_t) +_SG_IMPL_RES_EQL(_sg_shader_ref_eql, _sg_shader_ref_t, _sg_shader_t) +_SG_IMPL_RES_EQL(_sg_pipeline_ref_eql, _sg_pipeline_ref_t, _sg_pipeline_t) +_SG_IMPL_RES_EQL(_sg_view_ref_eql, _sg_view_ref_t, _sg_view_t) + +#define _SG_IMPL_RES_NULL(NAME,REF) _SOKOL_PRIVATE bool NAME(const REF* ref) { SOKOL_ASSERT(ref); return SG_INVALID_ID == ref->sref.id; } +_SG_IMPL_RES_NULL(_sg_buffer_ref_null, _sg_buffer_ref_t) +_SG_IMPL_RES_NULL(_sg_image_ref_null, _sg_image_ref_t) +_SG_IMPL_RES_NULL(_sg_sampler_ref_null, _sg_sampler_ref_t) +_SG_IMPL_RES_NULL(_sg_shader_ref_null, _sg_shader_ref_t) +_SG_IMPL_RES_NULL(_sg_pipeline_ref_null, _sg_pipeline_ref_t) +_SG_IMPL_RES_NULL(_sg_view_ref_null, _sg_view_ref_t) + +#define _SG_IMPL_RES_ALIVE(NAME,REF) _SOKOL_PRIVATE bool NAME(const REF* ref) { SOKOL_ASSERT(ref); return ref->ptr && _sg_sref_slot_eql(&ref->sref, &ref->ptr->slot); } +_SG_IMPL_RES_ALIVE(_sg_buffer_ref_alive, _sg_buffer_ref_t) +_SG_IMPL_RES_ALIVE(_sg_image_ref_alive, _sg_image_ref_t) +_SG_IMPL_RES_ALIVE(_sg_sampler_ref_alive, _sg_sampler_ref_t) +_SG_IMPL_RES_ALIVE(_sg_shader_ref_alive, _sg_shader_ref_t) +_SG_IMPL_RES_ALIVE(_sg_pipeline_ref_alive, _sg_pipeline_ref_t) +_SG_IMPL_RES_ALIVE(_sg_view_ref_alive, _sg_view_ref_t) + +#define _SG_IMPL_RES_VALID(NAME,REF) _SOKOL_PRIVATE bool NAME(const REF* ref) { SOKOL_ASSERT(ref); return ref->ptr && _sg_sref_slot_eql(&ref->sref, &ref->ptr->slot) && (ref->ptr->slot.state == SG_RESOURCESTATE_VALID); } +_SG_IMPL_RES_VALID(_sg_buffer_ref_valid, _sg_buffer_ref_t) +_SG_IMPL_RES_VALID(_sg_image_ref_valid, _sg_image_ref_t) +_SG_IMPL_RES_VALID(_sg_sampler_ref_valid, _sg_sampler_ref_t) +_SG_IMPL_RES_VALID(_sg_shader_ref_valid, _sg_shader_ref_t) +_SG_IMPL_RES_VALID(_sg_pipeline_ref_valid, _sg_pipeline_ref_t) +_SG_IMPL_RES_VALID(_sg_view_ref_valid, _sg_view_ref_t) + +#define _SG_IMPL_RES_PTR(NAME,REF,RES) _SOKOL_PRIVATE RES* NAME(const REF* ref) { SOKOL_ASSERT(ref && ref->ptr && _sg_sref_slot_eql(&ref->sref, &ref->ptr->slot)); return ref->ptr; } +_SG_IMPL_RES_PTR(_sg_buffer_ref_ptr, _sg_buffer_ref_t, _sg_buffer_t) +_SG_IMPL_RES_PTR(_sg_image_ref_ptr, _sg_image_ref_t, _sg_image_t) +_SG_IMPL_RES_PTR(_sg_sampler_ref_ptr, _sg_sampler_ref_t, _sg_sampler_t) +_SG_IMPL_RES_PTR(_sg_shader_ref_ptr, _sg_shader_ref_t, _sg_shader_t) +_SG_IMPL_RES_PTR(_sg_pipeline_ref_ptr, _sg_pipeline_ref_t, _sg_pipeline_t) +_SG_IMPL_RES_PTR(_sg_view_ref_ptr, _sg_view_ref_t, _sg_view_t) + +#define _SG_IMPL_RES_PTR_OR_NULL(NAME,REF,RES) _SOKOL_PRIVATE RES* NAME(const REF* ref) { SOKOL_ASSERT(ref); if ((SG_INVALID_ID != ref->sref.id) && _sg_sref_slot_eql(&ref->sref, &ref->ptr->slot)) { return ref->ptr; } else { return 0; } } +_SG_IMPL_RES_PTR_OR_NULL(_sg_buffer_ref_ptr_or_null, _sg_buffer_ref_t, _sg_buffer_t) +_SG_IMPL_RES_PTR_OR_NULL(_sg_image_ref_ptr_or_null, _sg_image_ref_t, _sg_image_t) +_SG_IMPL_RES_PTR_OR_NULL(_sg_sampler_ref_ptr_or_null, _sg_sampler_ref_t, _sg_sampler_t) +_SG_IMPL_RES_PTR_OR_NULL(_sg_shader_ref_ptr_or_null, _sg_shader_ref_t, _sg_shader_t) +_SG_IMPL_RES_PTR_OR_NULL(_sg_pipeline_ref_ptr_or_null, _sg_pipeline_ref_t, _sg_pipeline_t) +_SG_IMPL_RES_PTR_OR_NULL(_sg_view_ref_ptr_or_null, _sg_view_ref_t, _sg_view_t) + +// ██ ██ ███████ ██ ██████ ███████ ██████ ███████ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ███████ █████ ██ ██████ █████ ██████ ███████ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ██ ██ ███████ ███████ ██ ███████ ██ ██ ███████ +// +// >>helpers + +// helper macros +#define _sg_def(val, def) (((val) == 0) ? (def) : (val)) +#define _sg_def_flt(val, def) (((val) == 0.0f) ? (def) : (val)) +#define _sg_min(a,b) (((a)<(b))?(a):(b)) +#define _sg_max(a,b) (((a)>(b))?(a):(b)) +#define _sg_clamp(v,v0,v1) (((v)<(v0))?(v0):(((v)>(v1))?(v1):(v))) +#define _sg_fequal(val,cmp,delta) ((((val)-(cmp))> -(delta))&&(((val)-(cmp))<(delta))) +#define _sg_ispow2(val) ((val&(val-1))==0) +#define _sg_stats_add(key,val) {if(_sg.stats_enabled){ _sg.stats.cur_frame.key+=val;}} +#define _sg_stats_inc(key) {if(_sg.stats_enabled){ _sg.stats.cur_frame.key++;}} +#define _sg_resource_stats_inc(key) {if(_sg.stats_enabled){ _sg.stats.cur_frame.key++; _sg.stats.total.key++;}} + +_SOKOL_PRIVATE void _sg_update_alive_free_resource_stats(sg_total_resource_stats* stats, const _sg_pool_t* pool) { + SOKOL_ASSERT(stats && pool); + stats->alive = (uint32_t) ((pool->size - 1) - pool->queue_top); + stats->free = (uint32_t) pool->queue_top; +} + +_SOKOL_PRIVATE void _sg_update_stats(void) { + _sg.stats.cur_frame.frame_index = _sg.frame_index; + _sg.stats.prev_frame = _sg.stats.cur_frame; + _sg_clear(&_sg.stats.cur_frame, sizeof(_sg.stats.cur_frame)); +} + +_SOKOL_PRIVATE uint32_t _sg_align_u32(uint32_t val, uint32_t align) { + SOKOL_ASSERT((align > 0) && ((align & (align - 1)) == 0)); + return (val + (align - 1)) & ~(align - 1); +} + +_SOKOL_PRIVATE _sg_recti_t _sg_clipi(int x, int y, int w, int h, int clip_width, int clip_height) { + x = _sg_min(_sg_max(0, x), clip_width-1); + y = _sg_min(_sg_max(0, y), clip_height-1); + if ((x + w) > clip_width) { + w = clip_width - x; + } + if ((y + h) > clip_height) { + h = clip_height - y; + } + w = _sg_max(w, 1); + h = _sg_max(h, 1); + const _sg_recti_t res = { x, y, w, h }; + return res; +} + +// return size of a mipmap level +_SOKOL_PRIVATE int _sg_miplevel_dim(int base_dim, int mip_level) { + return _sg_max(base_dim >> mip_level, 1); +} + +_SOKOL_PRIVATE bool _sg_image_view_alive(const _sg_view_t* view) { + return view && _sg_image_ref_alive(&view->cmn.img.ref); +} + +_SOKOL_PRIVATE _sg_dimi_t _sg_image_view_dim(const _sg_view_t* view) { + SOKOL_ASSERT(view); + const _sg_image_t* img = _sg_image_ref_ptr(&view->cmn.img.ref); + SOKOL_ASSERT((img->cmn.width > 0) && (img->cmn.height > 0)); + _SG_STRUCT(_sg_dimi_t, res); + res.width = _sg_miplevel_dim(img->cmn.width, view->cmn.img.mip_level); + res.height = _sg_miplevel_dim(img->cmn.height, view->cmn.img.mip_level); + return res; +} + +_SOKOL_PRIVATE bool _sg_attachments_empty(const sg_attachments* atts) { + SOKOL_ASSERT(atts); + for (size_t i = 0; i < SG_MAX_COLOR_ATTACHMENTS; i++) { + if (atts->colors[i].id != SG_INVALID_ID) { + return false; + } + if (atts->resolves[i].id != SG_INVALID_ID) { + return false; + } + } + if (atts->depth_stencil.id != SG_INVALID_ID) { + return false; + } + return true; +} + +_SOKOL_PRIVATE _sg_attachments_ptrs_t _sg_attachments_ptrs(const sg_attachments* atts) { + SOKOL_ASSERT(atts); + _SG_STRUCT(_sg_attachments_ptrs_t, res); + res.empty = true; + for (int i = 0; i < SG_MAX_COLOR_ATTACHMENTS; i++) { + if (atts->colors[i].id != SG_INVALID_ID) { + res.empty = false; + res.num_color_views += 1; + res.color_views[i] = _sg_lookup_view(atts->colors[i].id); + } + if (atts->resolves[i].id != SG_INVALID_ID) { + SOKOL_ASSERT(atts->colors[i].id != SG_INVALID_ID); + res.empty = false; + res.resolve_views[i] = _sg_lookup_view(atts->resolves[i].id); + } + } + if (atts->depth_stencil.id != SG_INVALID_ID) { + res.empty = false; + res.ds_view = _sg_lookup_view(atts->depth_stencil.id); + } + return res; +} + +_SOKOL_PRIVATE _sg_dimi_t _sg_attachments_dim(const _sg_attachments_ptrs_t* atts_ptrs) { + if (atts_ptrs->ds_view) { + return _sg_image_view_dim(atts_ptrs->ds_view); + } else { + SOKOL_ASSERT(atts_ptrs->color_views[0]); + return _sg_image_view_dim(atts_ptrs->color_views[0]); + } +} + +_SOKOL_PRIVATE bool _sg_attachments_alive(const _sg_attachments_ptrs_t* atts_ptrs) { + for (int i = 0; i < atts_ptrs->num_color_views; i++) { + if (!_sg_image_view_alive(atts_ptrs->color_views[i])) { + return false; + } + if (atts_ptrs->resolve_views[i] && !_sg_image_view_alive(atts_ptrs->resolve_views[i])) { + return false; + } + } + if (atts_ptrs->ds_view && !_sg_image_view_alive(atts_ptrs->ds_view)) { + return false; + } + return true; +} + +_SOKOL_PRIVATE bool _sg_is_dualsource_blendfactor(sg_blend_factor f) { + switch (f) { + case SG_BLENDFACTOR_SRC1_COLOR: + case SG_BLENDFACTOR_ONE_MINUS_SRC1_COLOR: + case SG_BLENDFACTOR_SRC1_ALPHA: + case SG_BLENDFACTOR_ONE_MINUS_SRC1_ALPHA: + return true; + default: + return false; + } +} + +_SOKOL_PRIVATE void _sg_buffer_common_init(_sg_buffer_common_t* cmn, const sg_buffer_desc* desc) { + cmn->size = (int)desc->size; + cmn->append_pos = 0; + cmn->append_overflow = false; + cmn->update_frame_index = 0; + cmn->append_frame_index = 0; + cmn->num_slots = desc->usage.immutable ? 1 : SG_NUM_INFLIGHT_FRAMES; + cmn->active_slot = 0; + cmn->usage = desc->usage; +} + +_SOKOL_PRIVATE void _sg_image_common_init(_sg_image_common_t* cmn, const sg_image_desc* desc) { + cmn->upd_frame_index = 0; + cmn->num_slots = desc->usage.immutable ? 1 : SG_NUM_INFLIGHT_FRAMES; + cmn->active_slot = 0; + cmn->type = desc->type; + cmn->width = desc->width; + cmn->height = desc->height; + cmn->num_slices = desc->num_slices; + cmn->num_mipmaps = desc->num_mipmaps; + cmn->usage = desc->usage; + cmn->pixel_format = desc->pixel_format; + cmn->sample_count = desc->sample_count; +} + +_SOKOL_PRIVATE void _sg_sampler_common_init(_sg_sampler_common_t* cmn, const sg_sampler_desc* desc) { + cmn->min_filter = desc->min_filter; + cmn->mag_filter = desc->mag_filter; + cmn->mipmap_filter = desc->mipmap_filter; + cmn->wrap_u = desc->wrap_u; + cmn->wrap_v = desc->wrap_v; + cmn->wrap_w = desc->wrap_w; + cmn->min_lod = desc->min_lod; + cmn->max_lod = desc->max_lod; + cmn->border_color = desc->border_color; + cmn->compare = desc->compare; + cmn->max_anisotropy = desc->max_anisotropy; +} + +_SOKOL_PRIVATE void _sg_shader_common_init(_sg_shader_common_t* cmn, const sg_shader_desc* desc) { + cmn->is_compute = desc->compute_func.source || desc->compute_func.bytecode.ptr; + for (size_t i = 0; i < SG_MAX_VERTEX_ATTRIBUTES; i++) { + cmn->attrs[i].base_type = desc->attrs[i].base_type; + } + for (size_t i = 0; i < SG_MAX_UNIFORMBLOCK_BINDSLOTS; i++) { + const sg_shader_uniform_block* src = &desc->uniform_blocks[i]; + _sg_shader_uniform_block_t* dst = &cmn->uniform_blocks[i]; + if (src->stage != SG_SHADERSTAGE_NONE) { + cmn->required_bindings_and_uniforms |= (1 << i); + dst->stage = src->stage; + dst->size = src->size; + } + } + const uint32_t required_bindings_flag = (1 << SG_MAX_UNIFORMBLOCK_BINDSLOTS); + for (size_t i = 0; i < SG_MAX_VIEW_BINDSLOTS; i++) { + _sg_shader_view_t* dst = &cmn->views[i]; + if (desc->views[i].texture.stage != SG_SHADERSTAGE_NONE) { + const sg_shader_texture_view* src = &desc->views[i].texture; + dst->stage = src->stage; + dst->view_type = SG_VIEWTYPE_TEXTURE; + dst->image_type = src->image_type; + dst->sample_type = src->sample_type; + dst->multisampled = src->multisampled; + } else if (desc->views[i].storage_buffer.stage != SG_SHADERSTAGE_NONE) { + const sg_shader_storage_buffer_view* src = &desc->views[i].storage_buffer; + cmn->required_bindings_and_uniforms |= required_bindings_flag; + dst->stage = src->stage; + dst->view_type = SG_VIEWTYPE_STORAGEBUFFER; + dst->sbuf_readonly = src->readonly; + } else if (desc->views[i].storage_image.stage != SG_SHADERSTAGE_NONE) { + const sg_shader_storage_image_view* src = &desc->views[i].storage_image; + cmn->required_bindings_and_uniforms |= required_bindings_flag; + dst->stage = src->stage; + dst->view_type = SG_VIEWTYPE_STORAGEIMAGE; + dst->image_type = src->image_type; + dst->access_format = src->access_format; + dst->simg_writeonly = src->writeonly; + } + } + for (size_t i = 0; i < SG_MAX_SAMPLER_BINDSLOTS; i++) { + const sg_shader_sampler* src = &desc->samplers[i]; + _sg_shader_sampler_t* dst = &cmn->samplers[i]; + if (src->stage != SG_SHADERSTAGE_NONE) { + cmn->required_bindings_and_uniforms |= required_bindings_flag; + dst->stage = src->stage; + dst->sampler_type = src->sampler_type; + } + } + for (size_t i = 0; i < SG_MAX_TEXTURE_SAMPLER_PAIRS; i++) { + const sg_shader_texture_sampler_pair* src = &desc->texture_sampler_pairs[i]; + _sg_shader_texture_sampler_t* dst = &cmn->texture_samplers[i]; + if (src->stage != SG_SHADERSTAGE_NONE) { + dst->stage = src->stage; + SOKOL_ASSERT((src->view_slot >= 0) && (src->view_slot < SG_MAX_VIEW_BINDSLOTS)); + SOKOL_ASSERT(cmn->views[src->view_slot].view_type == SG_VIEWTYPE_TEXTURE); + SOKOL_ASSERT(cmn->views[src->view_slot].stage == src->stage); + dst->view_slot = src->view_slot; + SOKOL_ASSERT((src->sampler_slot >= 0) && (src->sampler_slot < SG_MAX_SAMPLER_BINDSLOTS)); + SOKOL_ASSERT(desc->samplers[src->sampler_slot].stage == src->stage); + dst->sampler_slot = src->sampler_slot; + } + } +} + +_SOKOL_PRIVATE void _sg_pipeline_common_init(_sg_pipeline_common_t* cmn, const sg_pipeline_desc* desc, _sg_shader_t* shd) { + SOKOL_ASSERT((desc->color_count >= 0) && (desc->color_count <= SG_MAX_COLOR_ATTACHMENTS)); + + // FIXME: most of this isn't needed for compute pipelines + + const uint32_t required_bindings_flag = (1 << SG_MAX_UNIFORMBLOCK_BINDSLOTS); + for (size_t attr_idx = 0; attr_idx < SG_MAX_VERTEX_ATTRIBUTES; attr_idx++) { + const sg_vertex_attr_state* attr_state = &desc->layout.attrs[attr_idx]; + if (attr_state->format != SG_VERTEXFORMAT_INVALID) { + SOKOL_ASSERT((attr_state->buffer_index >= 0) && (attr_state->buffer_index < SG_MAX_VERTEXBUFFER_BINDSLOTS)); + cmn->vertex_buffer_layout_active[attr_state->buffer_index] = true; + cmn->required_bindings_and_uniforms |= required_bindings_flag; + } + } + cmn->use_instanced_draw = false; + for (size_t vbuf_idx = 0; vbuf_idx < SG_MAX_VERTEXBUFFER_BINDSLOTS; vbuf_idx++) { + const sg_vertex_buffer_layout_state* vbuf_state = &desc->layout.buffers[vbuf_idx]; + if (vbuf_state->step_func == SG_VERTEXSTEP_PER_INSTANCE) { + cmn->use_instanced_draw = true; + } + } + cmn->is_compute = desc->compute; + cmn->shader = _sg_shader_ref(shd); + cmn->layout = desc->layout; + cmn->depth = desc->depth; + cmn->stencil = desc->stencil; + cmn->color_count = desc->color_count; + for (int i = 0; i < desc->color_count; i++) { + cmn->colors[i] = desc->colors[i]; + } + cmn->primitive_type = desc->primitive_type; + cmn->index_type = desc->index_type; + if (cmn->index_type != SG_INDEXTYPE_NONE) { + cmn->required_bindings_and_uniforms |= required_bindings_flag; + } + cmn->cull_mode = desc->cull_mode; + cmn->face_winding = desc->face_winding; + cmn->sample_count = desc->sample_count; + cmn->blend_color = desc->blend_color; + cmn->alpha_to_coverage_enabled = desc->alpha_to_coverage_enabled; +} + +_SOKOL_PRIVATE void _sg_buffer_view_common_init(_sg_buffer_view_common_t* cmn, const sg_buffer_view_desc* desc, _sg_buffer_t* buf) { + SOKOL_ASSERT(SG_RESOURCESTATE_VALID == buf->slot.state); + cmn->ref = _sg_buffer_ref(buf); + cmn->offset = desc->offset; +} + +_SOKOL_PRIVATE void _sg_texture_view_common_init(_sg_image_view_common_t* cmn, const sg_texture_view_desc* desc, _sg_image_t* img) { + SOKOL_ASSERT(SG_RESOURCESTATE_VALID == img->slot.state); + cmn->ref = _sg_image_ref(img); + cmn->mip_level = desc->mip_levels.base; + cmn->mip_level_count = _sg_def(desc->mip_levels.count, img->cmn.num_mipmaps - cmn->mip_level); + cmn->slice = desc->slices.base; + switch (img->cmn.type) { + case SG_IMAGETYPE_2D: + cmn->slice_count = 1; + break; + case SG_IMAGETYPE_CUBE: + cmn->slice_count = 6; + break; + case SG_IMAGETYPE_3D: + cmn->slice_count = 1; + break; + case SG_IMAGETYPE_ARRAY: + cmn->slice_count = _sg_def(desc->slices.count, img->cmn.num_slices - cmn->slice); + break; + default: + SOKOL_UNREACHABLE; + } +} + +_SOKOL_PRIVATE void _sg_image_view_common_init(_sg_image_view_common_t* cmn, const sg_image_view_desc* desc, _sg_image_t* img) { + SOKOL_ASSERT(SG_RESOURCESTATE_VALID == img->slot.state); + cmn->ref = _sg_image_ref(img); + cmn->mip_level = desc->mip_level; + cmn->mip_level_count = 1; + cmn->slice = desc->slice; + cmn->slice_count = 1; +} + +_SOKOL_PRIVATE void _sg_view_common_init(_sg_view_common_t* cmn, const sg_view_desc* desc, _sg_buffer_t* buf, _sg_image_t* img) { + if (desc->texture.image.id != SG_INVALID_ID) { + SOKOL_ASSERT(img); + cmn->type = SG_VIEWTYPE_TEXTURE; + _sg_texture_view_common_init(&cmn->img, &desc->texture, img); + } else if (desc->storage_buffer.buffer.id != SG_INVALID_ID) { + SOKOL_ASSERT(buf); + cmn->type = SG_VIEWTYPE_STORAGEBUFFER; + _sg_buffer_view_common_init(&cmn->buf, &desc->storage_buffer, buf); + } else if (desc->storage_image.image.id != SG_INVALID_ID) { + SOKOL_ASSERT(img); + cmn->type = SG_VIEWTYPE_STORAGEIMAGE; + _sg_image_view_common_init(&cmn->img, &desc->storage_image, img); + } else if (desc->color_attachment.image.id != SG_INVALID_ID) { + SOKOL_ASSERT(img); + cmn->type = SG_VIEWTYPE_COLORATTACHMENT; + _sg_image_view_common_init(&cmn->img, &desc->color_attachment, img); + } else if (desc->resolve_attachment.image.id != SG_INVALID_ID) { + SOKOL_ASSERT(img); + cmn->type = SG_VIEWTYPE_RESOLVEATTACHMENT; + _sg_image_view_common_init(&cmn->img, &desc->resolve_attachment, img); + } else if (desc->depth_stencil_attachment.image.id != SG_INVALID_ID) { + SOKOL_ASSERT(img); + cmn->type = SG_VIEWTYPE_DEPTHSTENCILATTACHMENT; + _sg_image_view_common_init(&cmn->img, &desc->depth_stencil_attachment, img); + } else { + SOKOL_UNREACHABLE; + } +} + +_SOKOL_PRIVATE int _sg_vertexformat_bytesize(sg_vertex_format fmt) { + switch (fmt) { + case SG_VERTEXFORMAT_FLOAT: return 4; + case SG_VERTEXFORMAT_FLOAT2: return 8; + case SG_VERTEXFORMAT_FLOAT3: return 12; + case SG_VERTEXFORMAT_FLOAT4: return 16; + case SG_VERTEXFORMAT_INT: return 4; + case SG_VERTEXFORMAT_INT2: return 8; + case SG_VERTEXFORMAT_INT3: return 12; + case SG_VERTEXFORMAT_INT4: return 16; + case SG_VERTEXFORMAT_UINT: return 4; + case SG_VERTEXFORMAT_UINT2: return 8; + case SG_VERTEXFORMAT_UINT3: return 12; + case SG_VERTEXFORMAT_UINT4: return 16; + case SG_VERTEXFORMAT_BYTE4: return 4; + case SG_VERTEXFORMAT_BYTE4N: return 4; + case SG_VERTEXFORMAT_UBYTE4: return 4; + case SG_VERTEXFORMAT_UBYTE4N: return 4; + case SG_VERTEXFORMAT_SHORT2: return 4; + case SG_VERTEXFORMAT_SHORT2N: return 4; + case SG_VERTEXFORMAT_USHORT2: return 4; + case SG_VERTEXFORMAT_USHORT2N: return 4; + case SG_VERTEXFORMAT_SHORT4: return 8; + case SG_VERTEXFORMAT_SHORT4N: return 8; + case SG_VERTEXFORMAT_USHORT4: return 8; + case SG_VERTEXFORMAT_USHORT4N: return 8; + case SG_VERTEXFORMAT_INT10_N2: return 4; + case SG_VERTEXFORMAT_UINT10_N2: return 4; + case SG_VERTEXFORMAT_HALF2: return 4; + case SG_VERTEXFORMAT_HALF4: return 8; + case SG_VERTEXFORMAT_INVALID: return 0; + default: + SOKOL_UNREACHABLE; + return -1; + } +} + +_SOKOL_PRIVATE const char* _sg_vertexformat_to_string(sg_vertex_format fmt) { + switch (fmt) { + case SG_VERTEXFORMAT_FLOAT: return "FLOAT"; + case SG_VERTEXFORMAT_FLOAT2: return "FLOAT2"; + case SG_VERTEXFORMAT_FLOAT3: return "FLOAT3"; + case SG_VERTEXFORMAT_FLOAT4: return "FLOAT4"; + case SG_VERTEXFORMAT_INT: return "INT"; + case SG_VERTEXFORMAT_INT2: return "INT2"; + case SG_VERTEXFORMAT_INT3: return "INT3"; + case SG_VERTEXFORMAT_INT4: return "INT4"; + case SG_VERTEXFORMAT_UINT: return "UINT"; + case SG_VERTEXFORMAT_UINT2: return "UINT2"; + case SG_VERTEXFORMAT_UINT3: return "UINT3"; + case SG_VERTEXFORMAT_UINT4: return "UINT4"; + case SG_VERTEXFORMAT_BYTE4: return "BYTE4"; + case SG_VERTEXFORMAT_BYTE4N: return "BYTE4N"; + case SG_VERTEXFORMAT_UBYTE4: return "UBYTE4"; + case SG_VERTEXFORMAT_UBYTE4N: return "UBYTE4N"; + case SG_VERTEXFORMAT_SHORT2: return "SHORT2"; + case SG_VERTEXFORMAT_SHORT2N: return "SHORT2N"; + case SG_VERTEXFORMAT_USHORT2: return "USHORT2"; + case SG_VERTEXFORMAT_USHORT2N: return "USHORT2N"; + case SG_VERTEXFORMAT_SHORT4: return "SHORT4"; + case SG_VERTEXFORMAT_SHORT4N: return "SHORT4N"; + case SG_VERTEXFORMAT_USHORT4: return "USHORT4"; + case SG_VERTEXFORMAT_USHORT4N: return "USHORT4N"; + case SG_VERTEXFORMAT_INT10_N2: return "INT10_N2"; + case SG_VERTEXFORMAT_UINT10_N2: return "UINT10_N2"; + case SG_VERTEXFORMAT_HALF2: return "HALF2"; + case SG_VERTEXFORMAT_HALF4: return "HALF4"; + default: + SOKOL_UNREACHABLE; + return "INVALID"; + } +} + +_SOKOL_PRIVATE const char* _sg_shaderattrbasetype_to_string(sg_shader_attr_base_type b) { + switch (b) { + case SG_SHADERATTRBASETYPE_UNDEFINED: return "UNDEFINED"; + case SG_SHADERATTRBASETYPE_FLOAT: return "FLOAT"; + case SG_SHADERATTRBASETYPE_SINT: return "SINT"; + case SG_SHADERATTRBASETYPE_UINT: return "UINT"; + default: + SOKOL_UNREACHABLE; + return "INVALID"; + } +} + +_SOKOL_PRIVATE sg_shader_attr_base_type _sg_vertexformat_basetype(sg_vertex_format fmt) { + switch (fmt) { + case SG_VERTEXFORMAT_FLOAT: + case SG_VERTEXFORMAT_FLOAT2: + case SG_VERTEXFORMAT_FLOAT3: + case SG_VERTEXFORMAT_FLOAT4: + case SG_VERTEXFORMAT_HALF2: + case SG_VERTEXFORMAT_HALF4: + case SG_VERTEXFORMAT_BYTE4N: + case SG_VERTEXFORMAT_UBYTE4N: + case SG_VERTEXFORMAT_SHORT2N: + case SG_VERTEXFORMAT_USHORT2N: + case SG_VERTEXFORMAT_SHORT4N: + case SG_VERTEXFORMAT_USHORT4N: + case SG_VERTEXFORMAT_INT10_N2: + case SG_VERTEXFORMAT_UINT10_N2: + return SG_SHADERATTRBASETYPE_FLOAT; + case SG_VERTEXFORMAT_INT: + case SG_VERTEXFORMAT_INT2: + case SG_VERTEXFORMAT_INT3: + case SG_VERTEXFORMAT_INT4: + case SG_VERTEXFORMAT_BYTE4: + case SG_VERTEXFORMAT_SHORT2: + case SG_VERTEXFORMAT_SHORT4: + return SG_SHADERATTRBASETYPE_SINT; + case SG_VERTEXFORMAT_UINT: + case SG_VERTEXFORMAT_UINT2: + case SG_VERTEXFORMAT_UINT3: + case SG_VERTEXFORMAT_UINT4: + case SG_VERTEXFORMAT_UBYTE4: + case SG_VERTEXFORMAT_USHORT2: + case SG_VERTEXFORMAT_USHORT4: + return SG_SHADERATTRBASETYPE_UINT; + default: + SOKOL_UNREACHABLE; + return SG_SHADERATTRBASETYPE_UNDEFINED; + } +} + +_SOKOL_PRIVATE uint32_t _sg_uniform_alignment(sg_uniform_type type, int array_count, sg_uniform_layout ub_layout) { + if (ub_layout == SG_UNIFORMLAYOUT_NATIVE) { + return 1; + } else { + SOKOL_ASSERT(array_count > 0); + if (array_count == 1) { + switch (type) { + case SG_UNIFORMTYPE_FLOAT: + case SG_UNIFORMTYPE_INT: + return 4; + case SG_UNIFORMTYPE_FLOAT2: + case SG_UNIFORMTYPE_INT2: + return 8; + case SG_UNIFORMTYPE_FLOAT3: + case SG_UNIFORMTYPE_FLOAT4: + case SG_UNIFORMTYPE_INT3: + case SG_UNIFORMTYPE_INT4: + return 16; + case SG_UNIFORMTYPE_MAT4: + return 16; + default: + SOKOL_UNREACHABLE; + return 1; + } + } else { + return 16; + } + } +} + +_SOKOL_PRIVATE uint32_t _sg_uniform_size(sg_uniform_type type, int array_count, sg_uniform_layout ub_layout) { + SOKOL_ASSERT(array_count > 0); + if (array_count == 1) { + switch (type) { + case SG_UNIFORMTYPE_FLOAT: + case SG_UNIFORMTYPE_INT: + return 4; + case SG_UNIFORMTYPE_FLOAT2: + case SG_UNIFORMTYPE_INT2: + return 8; + case SG_UNIFORMTYPE_FLOAT3: + case SG_UNIFORMTYPE_INT3: + return 12; + case SG_UNIFORMTYPE_FLOAT4: + case SG_UNIFORMTYPE_INT4: + return 16; + case SG_UNIFORMTYPE_MAT4: + return 64; + default: + SOKOL_UNREACHABLE; + return 0; + } + } else { + if (ub_layout == SG_UNIFORMLAYOUT_NATIVE) { + switch (type) { + case SG_UNIFORMTYPE_FLOAT: + case SG_UNIFORMTYPE_INT: + return 4 * (uint32_t)array_count; + case SG_UNIFORMTYPE_FLOAT2: + case SG_UNIFORMTYPE_INT2: + return 8 * (uint32_t)array_count; + case SG_UNIFORMTYPE_FLOAT3: + case SG_UNIFORMTYPE_INT3: + return 12 * (uint32_t)array_count; + case SG_UNIFORMTYPE_FLOAT4: + case SG_UNIFORMTYPE_INT4: + return 16 * (uint32_t)array_count; + case SG_UNIFORMTYPE_MAT4: + return 64 * (uint32_t)array_count; + default: + SOKOL_UNREACHABLE; + return 0; + } + } else { + switch (type) { + case SG_UNIFORMTYPE_FLOAT: + case SG_UNIFORMTYPE_FLOAT2: + case SG_UNIFORMTYPE_FLOAT3: + case SG_UNIFORMTYPE_FLOAT4: + case SG_UNIFORMTYPE_INT: + case SG_UNIFORMTYPE_INT2: + case SG_UNIFORMTYPE_INT3: + case SG_UNIFORMTYPE_INT4: + return 16 * (uint32_t)array_count; + case SG_UNIFORMTYPE_MAT4: + return 64 * (uint32_t)array_count; + default: + SOKOL_UNREACHABLE; + return 0; + } + } + } +} + +_SOKOL_PRIVATE bool _sg_is_compressed_pixel_format(sg_pixel_format fmt) { + switch (fmt) { + case SG_PIXELFORMAT_BC1_RGBA: + case SG_PIXELFORMAT_BC2_RGBA: + case SG_PIXELFORMAT_BC3_RGBA: + case SG_PIXELFORMAT_BC3_SRGBA: + case SG_PIXELFORMAT_BC4_R: + case SG_PIXELFORMAT_BC4_RSN: + case SG_PIXELFORMAT_BC5_RG: + case SG_PIXELFORMAT_BC5_RGSN: + case SG_PIXELFORMAT_BC6H_RGBF: + case SG_PIXELFORMAT_BC6H_RGBUF: + case SG_PIXELFORMAT_BC7_RGBA: + case SG_PIXELFORMAT_BC7_SRGBA: + case SG_PIXELFORMAT_ETC2_RGB8: + case SG_PIXELFORMAT_ETC2_SRGB8: + case SG_PIXELFORMAT_ETC2_RGB8A1: + case SG_PIXELFORMAT_ETC2_RGBA8: + case SG_PIXELFORMAT_ETC2_SRGB8A8: + case SG_PIXELFORMAT_EAC_R11: + case SG_PIXELFORMAT_EAC_R11SN: + case SG_PIXELFORMAT_EAC_RG11: + case SG_PIXELFORMAT_EAC_RG11SN: + case SG_PIXELFORMAT_ASTC_4x4_RGBA: + case SG_PIXELFORMAT_ASTC_4x4_SRGBA: + return true; + default: + return false; + } +} + +_SOKOL_PRIVATE bool _sg_is_valid_attachment_color_format(sg_pixel_format fmt) { + const int fmt_index = (int) fmt; + SOKOL_ASSERT((fmt_index >= 0) && (fmt_index < _SG_PIXELFORMAT_NUM)); + return _sg.formats[fmt_index].render && !_sg.formats[fmt_index].depth; +} + +_SOKOL_PRIVATE bool _sg_is_valid_attachment_depth_format(sg_pixel_format fmt) { + const int fmt_index = (int) fmt; + SOKOL_ASSERT((fmt_index >= 0) && (fmt_index < _SG_PIXELFORMAT_NUM)); + return _sg.formats[fmt_index].render && _sg.formats[fmt_index].depth; +} + +_SOKOL_PRIVATE bool _sg_is_valid_storage_image_format(sg_pixel_format fmt) { + const int fmt_index = (int) fmt; + SOKOL_ASSERT((fmt_index >= 0) && (fmt_index < _SG_PIXELFORMAT_NUM)); + return _sg.formats[fmt_index].read || _sg.formats[fmt_index].write; +} + +_SOKOL_PRIVATE bool _sg_is_depth_or_depth_stencil_format(sg_pixel_format fmt) { + return (SG_PIXELFORMAT_DEPTH == fmt) || (SG_PIXELFORMAT_DEPTH_STENCIL == fmt); +} + +_SOKOL_PRIVATE bool _sg_is_depth_stencil_format(sg_pixel_format fmt) { + return (SG_PIXELFORMAT_DEPTH_STENCIL == fmt); +} + +_SOKOL_PRIVATE int _sg_pixelformat_bytesize(sg_pixel_format fmt) { + switch (fmt) { + case SG_PIXELFORMAT_R8: + case SG_PIXELFORMAT_R8SN: + case SG_PIXELFORMAT_R8UI: + case SG_PIXELFORMAT_R8SI: + return 1; + case SG_PIXELFORMAT_R16: + case SG_PIXELFORMAT_R16SN: + case SG_PIXELFORMAT_R16UI: + case SG_PIXELFORMAT_R16SI: + case SG_PIXELFORMAT_R16F: + case SG_PIXELFORMAT_RG8: + case SG_PIXELFORMAT_RG8SN: + case SG_PIXELFORMAT_RG8UI: + case SG_PIXELFORMAT_RG8SI: + return 2; + case SG_PIXELFORMAT_R32UI: + case SG_PIXELFORMAT_R32SI: + case SG_PIXELFORMAT_R32F: + case SG_PIXELFORMAT_RG16: + case SG_PIXELFORMAT_RG16SN: + case SG_PIXELFORMAT_RG16UI: + case SG_PIXELFORMAT_RG16SI: + case SG_PIXELFORMAT_RG16F: + case SG_PIXELFORMAT_RGBA8: + case SG_PIXELFORMAT_SRGB8A8: + case SG_PIXELFORMAT_RGBA8SN: + case SG_PIXELFORMAT_RGBA8UI: + case SG_PIXELFORMAT_RGBA8SI: + case SG_PIXELFORMAT_BGRA8: + case SG_PIXELFORMAT_RGB10A2: + case SG_PIXELFORMAT_RG11B10F: + case SG_PIXELFORMAT_RGB9E5: + return 4; + case SG_PIXELFORMAT_RG32UI: + case SG_PIXELFORMAT_RG32SI: + case SG_PIXELFORMAT_RG32F: + case SG_PIXELFORMAT_RGBA16: + case SG_PIXELFORMAT_RGBA16SN: + case SG_PIXELFORMAT_RGBA16UI: + case SG_PIXELFORMAT_RGBA16SI: + case SG_PIXELFORMAT_RGBA16F: + return 8; + case SG_PIXELFORMAT_RGBA32UI: + case SG_PIXELFORMAT_RGBA32SI: + case SG_PIXELFORMAT_RGBA32F: + return 16; + case SG_PIXELFORMAT_DEPTH: + case SG_PIXELFORMAT_DEPTH_STENCIL: + return 4; + default: + SOKOL_UNREACHABLE; + return 0; + } +} + +// return the texture block width/height of an image format +_SOKOL_PRIVATE int _sg_block_dim(sg_pixel_format fmt) { + if (_sg_is_compressed_pixel_format(fmt)) { + return 4; + } else { + return 1; + } +} + +// return texture block size in bytes +_SOKOL_PRIVATE int _sg_block_bytesize(sg_pixel_format fmt) { + switch (fmt) { + case SG_PIXELFORMAT_BC1_RGBA: + case SG_PIXELFORMAT_BC4_R: + case SG_PIXELFORMAT_BC4_RSN: + case SG_PIXELFORMAT_ETC2_RGB8: + case SG_PIXELFORMAT_ETC2_SRGB8: + case SG_PIXELFORMAT_ETC2_RGB8A1: + case SG_PIXELFORMAT_EAC_R11: + case SG_PIXELFORMAT_EAC_R11SN: + return 8; + case SG_PIXELFORMAT_BC2_RGBA: + case SG_PIXELFORMAT_BC3_RGBA: + case SG_PIXELFORMAT_BC3_SRGBA: + case SG_PIXELFORMAT_BC5_RG: + case SG_PIXELFORMAT_BC5_RGSN: + case SG_PIXELFORMAT_BC6H_RGBF: + case SG_PIXELFORMAT_BC6H_RGBUF: + case SG_PIXELFORMAT_BC7_RGBA: + case SG_PIXELFORMAT_BC7_SRGBA: + case SG_PIXELFORMAT_ETC2_RGBA8: + case SG_PIXELFORMAT_ETC2_SRGB8A8: + case SG_PIXELFORMAT_EAC_RG11: + case SG_PIXELFORMAT_EAC_RG11SN: + case SG_PIXELFORMAT_ASTC_4x4_RGBA: + case SG_PIXELFORMAT_ASTC_4x4_SRGBA: + return 16; + default: + return _sg_pixelformat_bytesize(fmt); + } +} + +/* return row pitch for an image + + see ComputePitch in https://github.com/microsoft/DirectXTex/blob/master/DirectXTex/DirectXTexUtil.cpp +*/ +_SOKOL_PRIVATE int _sg_row_pitch(sg_pixel_format fmt, int width, int row_align) { + const int block_dim = _sg_block_dim(fmt); + const int num_blocks_in_row = (width + (block_dim-1)) / block_dim; + const int block_num_bytes = _sg_block_bytesize(fmt); + int pitch = num_blocks_in_row * block_num_bytes; + pitch = (pitch < block_num_bytes) ? block_num_bytes : pitch; + pitch = _sg_roundup(pitch, row_align); + return pitch; +} + +// compute the number of rows in a surface depending on pixel format +_SOKOL_PRIVATE int _sg_num_rows(sg_pixel_format fmt, int height) { + const int block_dim = _sg_block_dim(fmt); + int num_rows = (height + (block_dim-1)) / block_dim; + if (num_rows < 1) { + num_rows = 1; + } + return num_rows; +} + +/* return pitch of a 2D subimage / texture slice + see ComputePitch in https://github.com/microsoft/DirectXTex/blob/master/DirectXTex/DirectXTexUtil.cpp +*/ +_SOKOL_PRIVATE int _sg_surface_pitch(sg_pixel_format fmt, int width, int height, int row_align) { + int num_rows = _sg_num_rows(fmt, height); + return num_rows * _sg_row_pitch(fmt, width, row_align); +} + +// capability table pixel format helper functions +_SOKOL_PRIVATE void _sg_pixelformat_all(_sg_pixelformat_info_t* pfi) { + pfi->sample = true; + pfi->filter = true; + pfi->blend = true; + pfi->render = true; + pfi->msaa = true; +} + +_SOKOL_PRIVATE void _sg_pixelformat_s(_sg_pixelformat_info_t* pfi) { + pfi->sample = true; +} + +_SOKOL_PRIVATE void _sg_pixelformat_sf(_sg_pixelformat_info_t* pfi) { + pfi->sample = true; + pfi->filter = true; +} + +_SOKOL_PRIVATE void _sg_pixelformat_sr(_sg_pixelformat_info_t* pfi) { + pfi->sample = true; + pfi->render = true; +} + +_SOKOL_PRIVATE void _sg_pixelformat_sfr(_sg_pixelformat_info_t* pfi) { + pfi->sample = true; + pfi->filter = true; + pfi->render = true; +} + +_SOKOL_PRIVATE void _sg_pixelformat_srmd(_sg_pixelformat_info_t* pfi) { + pfi->sample = true; + pfi->render = true; + pfi->msaa = true; + pfi->depth = true; +} + +_SOKOL_PRIVATE void _sg_pixelformat_srm(_sg_pixelformat_info_t* pfi) { + pfi->sample = true; + pfi->render = true; + pfi->msaa = true; +} + +_SOKOL_PRIVATE void _sg_pixelformat_sfrm(_sg_pixelformat_info_t* pfi) { + pfi->sample = true; + pfi->filter = true; + pfi->render = true; + pfi->msaa = true; +} +_SOKOL_PRIVATE void _sg_pixelformat_sbrm(_sg_pixelformat_info_t* pfi) { + pfi->sample = true; + pfi->blend = true; + pfi->render = true; + pfi->msaa = true; +} + +_SOKOL_PRIVATE void _sg_pixelformat_sbr(_sg_pixelformat_info_t* pfi) { + pfi->sample = true; + pfi->blend = true; + pfi->render = true; +} + +_SOKOL_PRIVATE void _sg_pixelformat_sfbr(_sg_pixelformat_info_t* pfi) { + pfi->sample = true; + pfi->filter = true; + pfi->blend = true; + pfi->render = true; +} + +_SOKOL_PRIVATE void _sg_pixelformat_compute_all(_sg_pixelformat_info_t* pfi) { + pfi->read = true; + pfi->write = true; +} + +_SOKOL_PRIVATE void _sg_pixelformat_compute_writeonly(_sg_pixelformat_info_t* pfi) { + pfi->read = false; + pfi->write = true; +} + +_SOKOL_PRIVATE sg_pass_action _sg_pass_action_defaults(const sg_pass_action* action) { + SOKOL_ASSERT(action); + sg_pass_action res = *action; + for (int i = 0; i < SG_MAX_COLOR_ATTACHMENTS; i++) { + if (res.colors[i].load_action == _SG_LOADACTION_DEFAULT) { + res.colors[i].load_action = SG_LOADACTION_CLEAR; + res.colors[i].clear_value.r = SG_DEFAULT_CLEAR_RED; + res.colors[i].clear_value.g = SG_DEFAULT_CLEAR_GREEN; + res.colors[i].clear_value.b = SG_DEFAULT_CLEAR_BLUE; + res.colors[i].clear_value.a = SG_DEFAULT_CLEAR_ALPHA; + } + if (res.colors[i].store_action == _SG_STOREACTION_DEFAULT) { + res.colors[i].store_action = SG_STOREACTION_STORE; + } + } + if (res.depth.load_action == _SG_LOADACTION_DEFAULT) { + res.depth.load_action = SG_LOADACTION_CLEAR; + res.depth.clear_value = SG_DEFAULT_CLEAR_DEPTH; + } + if (res.depth.store_action == _SG_STOREACTION_DEFAULT) { + res.depth.store_action = SG_STOREACTION_DONTCARE; + } + if (res.stencil.load_action == _SG_LOADACTION_DEFAULT) { + res.stencil.load_action = SG_LOADACTION_CLEAR; + res.stencil.clear_value = SG_DEFAULT_CLEAR_STENCIL; + } + if (res.stencil.store_action == _SG_STOREACTION_DEFAULT) { + res.stencil.store_action = SG_STOREACTION_DONTCARE; + } + return res; +} + +// ██████ ██ ██ ███ ███ ███ ███ ██ ██ ██████ █████ ██████ ██ ██ ███████ ███ ██ ██████ +// ██ ██ ██ ██ ████ ████ ████ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ +// ██ ██ ██ ██ ██ ████ ██ ██ ████ ██ ████ ██████ ███████ ██ █████ █████ ██ ██ ██ ██ ██ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ██████ ██████ ██ ██ ██ ██ ██ ██████ ██ ██ ██████ ██ ██ ███████ ██ ████ ██████ +// +// >>dummy backend +#if defined(SOKOL_DUMMY_BACKEND) + +_SOKOL_PRIVATE void _sg_dummy_setup_backend(const sg_desc* desc) { + SOKOL_ASSERT(desc); + _SOKOL_UNUSED(desc); + _sg.backend = SG_BACKEND_DUMMY; + for (int i = SG_PIXELFORMAT_R8; i < SG_PIXELFORMAT_BC1_RGBA; i++) { + _sg.formats[i].sample = true; + _sg.formats[i].filter = true; + _sg.formats[i].render = true; + _sg.formats[i].blend = true; + _sg.formats[i].msaa = true; + } + _sg.formats[SG_PIXELFORMAT_DEPTH].depth = true; + _sg.formats[SG_PIXELFORMAT_DEPTH_STENCIL].depth = true; + _sg.limits.max_image_size_2d = 1024; + _sg.limits.max_image_size_cube = 1024; + _sg.limits.max_image_size_3d = 1024; + _sg.limits.max_image_size_array = 1024; + _sg.limits.max_image_array_layers = 1024; + _sg.limits.max_vertex_attrs = 16; + _sg.limits.max_color_attachments = SG_MAX_PORTABLE_COLOR_ATTACHMENTS; + _sg.limits.max_texture_bindings_per_stage = SG_MAX_PORTABLE_TEXTURE_BINDINGS_PER_STAGE; + _sg.limits.max_storage_buffer_bindings_per_stage = SG_MAX_PORTABLE_STORAGEBUFFER_BINDINGS_PER_STAGE; + _sg.limits.max_storage_image_bindings_per_stage = SG_MAX_PORTABLE_STORAGEIMAGE_BINDINGS_PER_STAGE; +} + +_SOKOL_PRIVATE void _sg_dummy_discard_backend(void) { + // empty +} + +_SOKOL_PRIVATE void _sg_dummy_reset_state_cache(void) { + // empty +} + +_SOKOL_PRIVATE sg_resource_state _sg_dummy_create_buffer(_sg_buffer_t* buf, const sg_buffer_desc* desc) { + SOKOL_ASSERT(buf && desc); + _SOKOL_UNUSED(buf); + _SOKOL_UNUSED(desc); + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_dummy_discard_buffer(_sg_buffer_t* buf) { + SOKOL_ASSERT(buf); + _SOKOL_UNUSED(buf); +} + +_SOKOL_PRIVATE sg_resource_state _sg_dummy_create_image(_sg_image_t* img, const sg_image_desc* desc) { + SOKOL_ASSERT(img && desc); + _SOKOL_UNUSED(img); + _SOKOL_UNUSED(desc); + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_dummy_discard_image(_sg_image_t* img) { + SOKOL_ASSERT(img); + _SOKOL_UNUSED(img); +} + +_SOKOL_PRIVATE sg_resource_state _sg_dummy_create_sampler(_sg_sampler_t* smp, const sg_sampler_desc* desc) { + SOKOL_ASSERT(smp && desc); + _SOKOL_UNUSED(smp); + _SOKOL_UNUSED(desc); + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_dummy_discard_sampler(_sg_sampler_t* smp) { + SOKOL_ASSERT(smp); + _SOKOL_UNUSED(smp); +} + +_SOKOL_PRIVATE sg_resource_state _sg_dummy_create_shader(_sg_shader_t* shd, const sg_shader_desc* desc) { + SOKOL_ASSERT(shd && desc); + _SOKOL_UNUSED(shd); + _SOKOL_UNUSED(desc); + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_dummy_discard_shader(_sg_shader_t* shd) { + SOKOL_ASSERT(shd); + _SOKOL_UNUSED(shd); +} + +_SOKOL_PRIVATE sg_resource_state _sg_dummy_create_pipeline(_sg_pipeline_t* pip, const sg_pipeline_desc* desc) { + SOKOL_ASSERT(pip && desc); + _SOKOL_UNUSED(pip); + _SOKOL_UNUSED(desc); + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_dummy_discard_pipeline(_sg_pipeline_t* pip) { + SOKOL_ASSERT(pip); + _SOKOL_UNUSED(pip); +} + +_SOKOL_PRIVATE sg_resource_state _sg_dummy_create_view(_sg_view_t* view, const sg_view_desc* desc) { + SOKOL_ASSERT(view && desc); + _SOKOL_UNUSED(view); + _SOKOL_UNUSED(desc); + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_dummy_discard_view(_sg_view_t* view) { + SOKOL_ASSERT(view); + _SOKOL_UNUSED(view); +} + +_SOKOL_PRIVATE void _sg_dummy_begin_pass(const sg_pass* pass, const _sg_attachments_ptrs_t* atts) { + SOKOL_ASSERT(pass && atts); + _SOKOL_UNUSED(pass); + _SOKOL_UNUSED(atts); +} + +_SOKOL_PRIVATE void _sg_dummy_end_pass(const _sg_attachments_ptrs_t* atts) { + SOKOL_ASSERT(atts); + _SOKOL_UNUSED(atts); +} + +_SOKOL_PRIVATE void _sg_dummy_commit(void) { + // empty +} + +_SOKOL_PRIVATE void _sg_dummy_apply_viewport(int x, int y, int w, int h, bool origin_top_left) { + _SOKOL_UNUSED(x); + _SOKOL_UNUSED(y); + _SOKOL_UNUSED(w); + _SOKOL_UNUSED(h); + _SOKOL_UNUSED(origin_top_left); +} + +_SOKOL_PRIVATE void _sg_dummy_apply_scissor_rect(int x, int y, int w, int h, bool origin_top_left) { + _SOKOL_UNUSED(x); + _SOKOL_UNUSED(y); + _SOKOL_UNUSED(w); + _SOKOL_UNUSED(h); + _SOKOL_UNUSED(origin_top_left); +} + +_SOKOL_PRIVATE void _sg_dummy_apply_pipeline(_sg_pipeline_t* pip) { + SOKOL_ASSERT(pip); + _SOKOL_UNUSED(pip); +} + +_SOKOL_PRIVATE bool _sg_dummy_apply_bindings(_sg_bindings_ptrs_t* bnd) { + SOKOL_ASSERT(bnd); + SOKOL_ASSERT(bnd->pip); + _SOKOL_UNUSED(bnd); + return true; +} + +_SOKOL_PRIVATE void _sg_dummy_apply_uniforms(int ub_slot, const sg_range* data) { + _SOKOL_UNUSED(ub_slot); + _SOKOL_UNUSED(data); +} + +_SOKOL_PRIVATE void _sg_dummy_draw(int base_element, int num_elements, int num_instances, int base_vertex, int base_instance) { + _SOKOL_UNUSED(base_element); + _SOKOL_UNUSED(num_elements); + _SOKOL_UNUSED(num_instances); + _SOKOL_UNUSED(base_vertex); + _SOKOL_UNUSED(base_instance); +} + +_SOKOL_PRIVATE void _sg_dummy_dispatch(int num_groups_x, int num_groups_y, int num_groups_z) { + _SOKOL_UNUSED(num_groups_x); + _SOKOL_UNUSED(num_groups_y); + _SOKOL_UNUSED(num_groups_z); +} + +_SOKOL_PRIVATE void _sg_dummy_update_buffer(_sg_buffer_t* buf, const sg_range* data) { + SOKOL_ASSERT(buf && data && data->ptr && (data->size > 0)); + _SOKOL_UNUSED(data); + if (++buf->cmn.active_slot >= buf->cmn.num_slots) { + buf->cmn.active_slot = 0; + } +} + +_SOKOL_PRIVATE bool _sg_dummy_append_buffer(_sg_buffer_t* buf, const sg_range* data, bool new_frame) { + SOKOL_ASSERT(buf && data && data->ptr && (data->size > 0)); + _SOKOL_UNUSED(data); + if (new_frame) { + if (++buf->cmn.active_slot >= buf->cmn.num_slots) { + buf->cmn.active_slot = 0; + } + } + return true; +} + +_SOKOL_PRIVATE void _sg_dummy_update_image(_sg_image_t* img, const sg_image_data* data) { + SOKOL_ASSERT(img && data); + _SOKOL_UNUSED(data); + if (++img->cmn.active_slot >= img->cmn.num_slots) { + img->cmn.active_slot = 0; + } +} + +// ██████ ██████ ███████ ███ ██ ██████ ██ ██████ █████ ██████ ██ ██ ███████ ███ ██ ██████ +// ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ +// ██ ██ ██████ █████ ██ ██ ██ ██ ███ ██ ██████ ███████ ██ █████ █████ ██ ██ ██ ██ ██ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ██████ ██ ███████ ██ ████ ██████ ███████ ██████ ██ ██ ██████ ██ ██ ███████ ██ ████ ██████ +// +// >>opengl backend +#elif defined(_SOKOL_ANY_GL) + +// optional GL loader for win32 +#if defined(_SOKOL_USE_WIN32_GL_LOADER) + +#ifndef SG_GL_FUNCS_EXT +#define SG_GL_FUNCS_EXT +#endif + +// X Macro list of GL function names and signatures +#define _SG_GL_FUNCS \ + SG_GL_FUNCS_EXT \ + _SG_XMACRO(glBindVertexArray, void, (GLuint array)) \ + _SG_XMACRO(glFramebufferTextureLayer, void, (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)) \ + _SG_XMACRO(glGenFramebuffers, void, (GLsizei n, GLuint * framebuffers)) \ + _SG_XMACRO(glBindFramebuffer, void, (GLenum target, GLuint framebuffer)) \ + _SG_XMACRO(glBindRenderbuffer, void, (GLenum target, GLuint renderbuffer)) \ + _SG_XMACRO(glGetStringi, const GLubyte *, (GLenum name, GLuint index)) \ + _SG_XMACRO(glClearBufferfi, void, (GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)) \ + _SG_XMACRO(glClearBufferfv, void, (GLenum buffer, GLint drawbuffer, const GLfloat * value)) \ + _SG_XMACRO(glClearBufferuiv, void, (GLenum buffer, GLint drawbuffer, const GLuint * value)) \ + _SG_XMACRO(glClearBufferiv, void, (GLenum buffer, GLint drawbuffer, const GLint * value)) \ + _SG_XMACRO(glDeleteRenderbuffers, void, (GLsizei n, const GLuint * renderbuffers)) \ + _SG_XMACRO(glUniform1fv, void, (GLint location, GLsizei count, const GLfloat * value)) \ + _SG_XMACRO(glUniform2fv, void, (GLint location, GLsizei count, const GLfloat * value)) \ + _SG_XMACRO(glUniform3fv, void, (GLint location, GLsizei count, const GLfloat * value)) \ + _SG_XMACRO(glUniform4fv, void, (GLint location, GLsizei count, const GLfloat * value)) \ + _SG_XMACRO(glUniform1iv, void, (GLint location, GLsizei count, const GLint * value)) \ + _SG_XMACRO(glUniform2iv, void, (GLint location, GLsizei count, const GLint * value)) \ + _SG_XMACRO(glUniform3iv, void, (GLint location, GLsizei count, const GLint * value)) \ + _SG_XMACRO(glUniform4iv, void, (GLint location, GLsizei count, const GLint * value)) \ + _SG_XMACRO(glUniformMatrix4fv, void, (GLint location, GLsizei count, GLboolean transpose, const GLfloat * value)) \ + _SG_XMACRO(glUseProgram, void, (GLuint program)) \ + _SG_XMACRO(glShaderSource, void, (GLuint shader, GLsizei count, const GLchar *const* string, const GLint * length)) \ + _SG_XMACRO(glLinkProgram, void, (GLuint program)) \ + _SG_XMACRO(glGetUniformLocation, GLint, (GLuint program, const GLchar * name)) \ + _SG_XMACRO(glGetShaderiv, void, (GLuint shader, GLenum pname, GLint * params)) \ + _SG_XMACRO(glGetProgramInfoLog, void, (GLuint program, GLsizei bufSize, GLsizei * length, GLchar * infoLog)) \ + _SG_XMACRO(glGetAttribLocation, GLint, (GLuint program, const GLchar * name)) \ + _SG_XMACRO(glDisableVertexAttribArray, void, (GLuint index)) \ + _SG_XMACRO(glDeleteShader, void, (GLuint shader)) \ + _SG_XMACRO(glDeleteProgram, void, (GLuint program)) \ + _SG_XMACRO(glCompileShader, void, (GLuint shader)) \ + _SG_XMACRO(glStencilFuncSeparate, void, (GLenum face, GLenum func, GLint ref, GLuint mask)) \ + _SG_XMACRO(glStencilOpSeparate, void, (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass)) \ + _SG_XMACRO(glRenderbufferStorageMultisample, void, (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)) \ + _SG_XMACRO(glDrawBuffers, void, (GLsizei n, const GLenum * bufs)) \ + _SG_XMACRO(glVertexAttribDivisor, void, (GLuint index, GLuint divisor)) \ + _SG_XMACRO(glBufferSubData, void, (GLenum target, GLintptr offset, GLsizeiptr size, const void * data)) \ + _SG_XMACRO(glGenBuffers, void, (GLsizei n, GLuint * buffers)) \ + _SG_XMACRO(glCheckFramebufferStatus, GLenum, (GLenum target)) \ + _SG_XMACRO(glFramebufferRenderbuffer, void, (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)) \ + _SG_XMACRO(glCompressedTexImage2D, void, (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void * data)) \ + _SG_XMACRO(glCompressedTexImage3D, void, (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void * data)) \ + _SG_XMACRO(glActiveTexture, void, (GLenum texture)) \ + _SG_XMACRO(glTexSubImage3D, void, (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void * pixels)) \ + _SG_XMACRO(glRenderbufferStorage, void, (GLenum target, GLenum internalformat, GLsizei width, GLsizei height)) \ + _SG_XMACRO(glGenTextures, void, (GLsizei n, GLuint * textures)) \ + _SG_XMACRO(glPolygonOffset, void, (GLfloat factor, GLfloat units)) \ + _SG_XMACRO(glDrawElements, void, (GLenum mode, GLsizei count, GLenum type, const void * indices)) \ + _SG_XMACRO(glDeleteFramebuffers, void, (GLsizei n, const GLuint * framebuffers)) \ + _SG_XMACRO(glBlendEquationSeparate, void, (GLenum modeRGB, GLenum modeAlpha)) \ + _SG_XMACRO(glDeleteTextures, void, (GLsizei n, const GLuint * textures)) \ + _SG_XMACRO(glGetProgramiv, void, (GLuint program, GLenum pname, GLint * params)) \ + _SG_XMACRO(glBindTexture, void, (GLenum target, GLuint texture)) \ + _SG_XMACRO(glTexImage3D, void, (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void * pixels)) \ + _SG_XMACRO(glCreateShader, GLuint, (GLenum type)) \ + _SG_XMACRO(glTexSubImage2D, void, (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void * pixels)) \ + _SG_XMACRO(glFramebufferTexture2D, void, (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)) \ + _SG_XMACRO(glCreateProgram, GLuint, (void)) \ + _SG_XMACRO(glViewport, void, (GLint x, GLint y, GLsizei width, GLsizei height)) \ + _SG_XMACRO(glDeleteBuffers, void, (GLsizei n, const GLuint * buffers)) \ + _SG_XMACRO(glDrawArrays, void, (GLenum mode, GLint first, GLsizei count)) \ + _SG_XMACRO(glDrawElementsInstanced, void, (GLenum mode, GLsizei count, GLenum type, const void * indices, GLsizei instancecount)) \ + _SG_XMACRO(glVertexAttribPointer, void, (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void * pointer)) \ + _SG_XMACRO(glVertexAttribIPointer, void, (GLuint index, GLint size, GLenum type, GLsizei stride, const void * pointer)) \ + _SG_XMACRO(glUniform1i, void, (GLint location, GLint v0)) \ + _SG_XMACRO(glDisable, void, (GLenum cap)) \ + _SG_XMACRO(glColorMask, void, (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)) \ + _SG_XMACRO(glColorMaski, void, (GLuint buf, GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)) \ + _SG_XMACRO(glBindBuffer, void, (GLenum target, GLuint buffer)) \ + _SG_XMACRO(glDeleteVertexArrays, void, (GLsizei n, const GLuint * arrays)) \ + _SG_XMACRO(glDepthMask, void, (GLboolean flag)) \ + _SG_XMACRO(glDrawArraysInstanced, void, (GLenum mode, GLint first, GLsizei count, GLsizei instancecount)) \ + _SG_XMACRO(glScissor, void, (GLint x, GLint y, GLsizei width, GLsizei height)) \ + _SG_XMACRO(glGenRenderbuffers, void, (GLsizei n, GLuint * renderbuffers)) \ + _SG_XMACRO(glBufferData, void, (GLenum target, GLsizeiptr size, const void * data, GLenum usage)) \ + _SG_XMACRO(glBlendFuncSeparate, void, (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha)) \ + _SG_XMACRO(glTexParameteri, void, (GLenum target, GLenum pname, GLint param)) \ + _SG_XMACRO(glGetIntegerv, void, (GLenum pname, GLint * data)) \ + _SG_XMACRO(glEnable, void, (GLenum cap)) \ + _SG_XMACRO(glBlitFramebuffer, void, (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)) \ + _SG_XMACRO(glStencilMask, void, (GLuint mask)) \ + _SG_XMACRO(glAttachShader, void, (GLuint program, GLuint shader)) \ + _SG_XMACRO(glGetError, GLenum, (void)) \ + _SG_XMACRO(glBlendColor, void, (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)) \ + _SG_XMACRO(glTexParameterf, void, (GLenum target, GLenum pname, GLfloat param)) \ + _SG_XMACRO(glTexParameterfv, void, (GLenum target, GLenum pname, const GLfloat* params)) \ + _SG_XMACRO(glGetShaderInfoLog, void, (GLuint shader, GLsizei bufSize, GLsizei * length, GLchar * infoLog)) \ + _SG_XMACRO(glDepthFunc, void, (GLenum func)) \ + _SG_XMACRO(glStencilOp , void, (GLenum fail, GLenum zfail, GLenum zpass)) \ + _SG_XMACRO(glStencilFunc, void, (GLenum func, GLint ref, GLuint mask)) \ + _SG_XMACRO(glEnableVertexAttribArray, void, (GLuint index)) \ + _SG_XMACRO(glBlendFunc, void, (GLenum sfactor, GLenum dfactor)) \ + _SG_XMACRO(glReadBuffer, void, (GLenum src)) \ + _SG_XMACRO(glTexImage2D, void, (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void * pixels)) \ + _SG_XMACRO(glGenVertexArrays, void, (GLsizei n, GLuint * arrays)) \ + _SG_XMACRO(glFrontFace, void, (GLenum mode)) \ + _SG_XMACRO(glCullFace, void, (GLenum mode)) \ + _SG_XMACRO(glPixelStorei, void, (GLenum pname, GLint param)) \ + _SG_XMACRO(glBindSampler, void, (GLuint unit, GLuint sampler)) \ + _SG_XMACRO(glGenSamplers, void, (GLsizei n, GLuint* samplers)) \ + _SG_XMACRO(glSamplerParameteri, void, (GLuint sampler, GLenum pname, GLint param)) \ + _SG_XMACRO(glSamplerParameterf, void, (GLuint sampler, GLenum pname, GLfloat param)) \ + _SG_XMACRO(glSamplerParameterfv, void, (GLuint sampler, GLenum pname, const GLfloat* params)) \ + _SG_XMACRO(glDeleteSamplers, void, (GLsizei n, const GLuint* samplers)) \ + _SG_XMACRO(glBindBufferBase, void, (GLenum target, GLuint index, GLuint buffer)) \ + _SG_XMACRO(glBindBufferRange, void, (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)) \ + _SG_XMACRO(glTexImage2DMultisample, void, (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations)) \ + _SG_XMACRO(glTexImage3DMultisample, void, (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations)) \ + _SG_XMACRO(glDispatchCompute, void, (GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z)) \ + _SG_XMACRO(glMemoryBarrier, void, (GLbitfield barriers)) \ + _SG_XMACRO(glBindImageTexture, void, (GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format)) \ + _SG_XMACRO(glTexStorage2DMultisample, void, (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations)) \ + _SG_XMACRO(glTexStorage2D, void, (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)) \ + _SG_XMACRO(glTexStorage3DMultisample, void, (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations)) \ + _SG_XMACRO(glTexStorage3D, void, (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)) \ + _SG_XMACRO(glCompressedTexSubImage2D, void, (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data)) \ + _SG_XMACRO(glCompressedTexSubImage3D, void, (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *data)) \ + _SG_XMACRO(glTextureView, void, (GLuint texture, GLenum target, GLuint origtexture, GLenum internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers)) \ + _SG_XMACRO(glDrawElementsBaseVertex, void, (GLenum mode, GLsizei count, GLenum type, const void* indices, GLint basevertex)) \ + _SG_XMACRO(glDrawElementsInstancedBaseVertex, void, (GLenum mode, GLsizei count, GLenum type, const void* indices, GLsizei instancecount, GLint basevertex)) \ + _SG_XMACRO(glDrawElementsInstancedBaseVertexBaseInstance, void, (GLenum mode, GLsizei count, GLenum type, const void* indices, GLsizei instancecount, GLint basevertex, GLuint baseinstance)) \ + _SG_XMACRO(glDrawArraysInstancedBaseInstance, void, (GLenum mode, GLint first, GLsizei count, GLsizei instancecount, GLuint baseinstance)) + +// generate GL function pointer typedefs +#define _SG_XMACRO(name, ret, args) typedef ret (GL_APIENTRY* PFN_ ## name) args; +_SG_GL_FUNCS +#undef _SG_XMACRO + +// generate GL function pointers +#define _SG_XMACRO(name, ret, args) static PFN_ ## name name; +_SG_GL_FUNCS +#undef _SG_XMACRO + +// helper function to lookup GL functions in GL DLL +typedef PROC (WINAPI * _sg_wglGetProcAddress)(LPCSTR); +_SOKOL_PRIVATE void* _sg_gl_getprocaddr(const char* name, _sg_wglGetProcAddress wgl_getprocaddress) { + void* proc_addr = (void*) wgl_getprocaddress(name); + if (0 == proc_addr) { + proc_addr = (void*) GetProcAddress(_sg.gl.opengl32_dll, name); + } + SOKOL_ASSERT(proc_addr); + return proc_addr; +} + +// populate GL function pointers +_SOKOL_PRIVATE void _sg_gl_load_opengl(void) { + SOKOL_ASSERT(0 == _sg.gl.opengl32_dll); + _sg.gl.opengl32_dll = LoadLibraryA("opengl32.dll"); + SOKOL_ASSERT(_sg.gl.opengl32_dll); + _sg_wglGetProcAddress wgl_getprocaddress = (_sg_wglGetProcAddress) GetProcAddress(_sg.gl.opengl32_dll, "wglGetProcAddress"); + SOKOL_ASSERT(wgl_getprocaddress); + #define _SG_XMACRO(name, ret, args) name = (PFN_ ## name) _sg_gl_getprocaddr(#name, wgl_getprocaddress); + _SG_GL_FUNCS + #undef _SG_XMACRO +} + +_SOKOL_PRIVATE void _sg_gl_unload_opengl(void) { + SOKOL_ASSERT(_sg.gl.opengl32_dll); + FreeLibrary(_sg.gl.opengl32_dll); + _sg.gl.opengl32_dll = 0; +} +#endif // _SOKOL_USE_WIN32_GL_LOADER + +//-- type translation ---------------------------------------------------------- +_SOKOL_PRIVATE GLenum _sg_gl_buffer_target(const sg_buffer_usage* usg) { + // NOTE: the buffer target returned here is only used for the bind point + // to copy data into the buffer, expect for WebGL2, the bind point doesn't + // need to match the later usage of the buffer (but because of the WebGL2 + // restriction we cannot simply select a random bind point, because in WebGL2 + // a buffer cannot 'switch' bind points later. + if (usg->vertex_buffer) { + return GL_ARRAY_BUFFER; + } else if (usg->index_buffer) { + return GL_ELEMENT_ARRAY_BUFFER; + } else if (usg->storage_buffer) { + return GL_SHADER_STORAGE_BUFFER; + } else { + SOKOL_UNREACHABLE; return 0; + } +} + +_SOKOL_PRIVATE GLenum _sg_gl_texture_target(sg_image_type t, int sample_count) { + #if defined(SOKOL_GLCORE) + const bool msaa = sample_count > 1; + if (msaa) { + switch (t) { + case SG_IMAGETYPE_2D: return GL_TEXTURE_2D_MULTISAMPLE; + case SG_IMAGETYPE_ARRAY: return GL_TEXTURE_2D_MULTISAMPLE_ARRAY; + default: SOKOL_UNREACHABLE; return 0; + } + } else { + switch (t) { + case SG_IMAGETYPE_2D: return GL_TEXTURE_2D; + case SG_IMAGETYPE_CUBE: return GL_TEXTURE_CUBE_MAP; + case SG_IMAGETYPE_3D: return GL_TEXTURE_3D; + case SG_IMAGETYPE_ARRAY: return GL_TEXTURE_2D_ARRAY; + default: SOKOL_UNREACHABLE; return 0; + } + } + #else + SOKOL_ASSERT(sample_count == 1); _SOKOL_UNUSED(sample_count); + switch (t) { + case SG_IMAGETYPE_2D: return GL_TEXTURE_2D; + case SG_IMAGETYPE_CUBE: return GL_TEXTURE_CUBE_MAP; + case SG_IMAGETYPE_3D: return GL_TEXTURE_3D; + case SG_IMAGETYPE_ARRAY: return GL_TEXTURE_2D_ARRAY; + default: SOKOL_UNREACHABLE; return 0; + } + #endif +} + +_SOKOL_PRIVATE GLenum _sg_gl_buffer_usage(const sg_buffer_usage* usg) { + if (usg->immutable) { + return GL_STATIC_DRAW; + } else if (usg->dynamic_update) { + return GL_DYNAMIC_DRAW; + } else if (usg->stream_update) { + return GL_STREAM_DRAW; + } else { + SOKOL_UNREACHABLE; return 0; + } +} + +_SOKOL_PRIVATE GLenum _sg_gl_shader_stage(sg_shader_stage stage) { + switch (stage) { + case SG_SHADERSTAGE_VERTEX: return GL_VERTEX_SHADER; + case SG_SHADERSTAGE_FRAGMENT: return GL_FRAGMENT_SHADER; + case SG_SHADERSTAGE_COMPUTE: return GL_COMPUTE_SHADER; + default: SOKOL_UNREACHABLE; return 0; + } +} + +_SOKOL_PRIVATE GLint _sg_gl_vertexformat_size(sg_vertex_format fmt) { + switch (fmt) { + case SG_VERTEXFORMAT_FLOAT: return 1; + case SG_VERTEXFORMAT_FLOAT2: return 2; + case SG_VERTEXFORMAT_FLOAT3: return 3; + case SG_VERTEXFORMAT_FLOAT4: return 4; + case SG_VERTEXFORMAT_INT: return 1; + case SG_VERTEXFORMAT_INT2: return 2; + case SG_VERTEXFORMAT_INT3: return 3; + case SG_VERTEXFORMAT_INT4: return 4; + case SG_VERTEXFORMAT_UINT: return 1; + case SG_VERTEXFORMAT_UINT2: return 2; + case SG_VERTEXFORMAT_UINT3: return 3; + case SG_VERTEXFORMAT_UINT4: return 4; + case SG_VERTEXFORMAT_BYTE4: return 4; + case SG_VERTEXFORMAT_BYTE4N: return 4; + case SG_VERTEXFORMAT_UBYTE4: return 4; + case SG_VERTEXFORMAT_UBYTE4N: return 4; + case SG_VERTEXFORMAT_SHORT2: return 2; + case SG_VERTEXFORMAT_SHORT2N: return 2; + case SG_VERTEXFORMAT_USHORT2: return 2; + case SG_VERTEXFORMAT_USHORT2N: return 2; + case SG_VERTEXFORMAT_SHORT4: return 4; + case SG_VERTEXFORMAT_SHORT4N: return 4; + case SG_VERTEXFORMAT_USHORT4: return 4; + case SG_VERTEXFORMAT_USHORT4N: return 4; + case SG_VERTEXFORMAT_INT10_N2: return 4; + case SG_VERTEXFORMAT_UINT10_N2: return 4; + case SG_VERTEXFORMAT_HALF2: return 2; + case SG_VERTEXFORMAT_HALF4: return 4; + default: SOKOL_UNREACHABLE; return 0; + } +} + +_SOKOL_PRIVATE GLenum _sg_gl_vertexformat_type(sg_vertex_format fmt) { + switch (fmt) { + case SG_VERTEXFORMAT_FLOAT: + case SG_VERTEXFORMAT_FLOAT2: + case SG_VERTEXFORMAT_FLOAT3: + case SG_VERTEXFORMAT_FLOAT4: + return GL_FLOAT; + case SG_VERTEXFORMAT_INT: + case SG_VERTEXFORMAT_INT2: + case SG_VERTEXFORMAT_INT3: + case SG_VERTEXFORMAT_INT4: + return GL_INT; + case SG_VERTEXFORMAT_UINT: + case SG_VERTEXFORMAT_UINT2: + case SG_VERTEXFORMAT_UINT3: + case SG_VERTEXFORMAT_UINT4: + return GL_UNSIGNED_INT; + case SG_VERTEXFORMAT_BYTE4: + case SG_VERTEXFORMAT_BYTE4N: + return GL_BYTE; + case SG_VERTEXFORMAT_UBYTE4: + case SG_VERTEXFORMAT_UBYTE4N: + return GL_UNSIGNED_BYTE; + case SG_VERTEXFORMAT_SHORT2: + case SG_VERTEXFORMAT_SHORT2N: + case SG_VERTEXFORMAT_SHORT4: + case SG_VERTEXFORMAT_SHORT4N: + return GL_SHORT; + case SG_VERTEXFORMAT_USHORT2: + case SG_VERTEXFORMAT_USHORT2N: + case SG_VERTEXFORMAT_USHORT4: + case SG_VERTEXFORMAT_USHORT4N: + return GL_UNSIGNED_SHORT; + case SG_VERTEXFORMAT_INT10_N2: + return GL_INT_2_10_10_10_REV; + case SG_VERTEXFORMAT_UINT10_N2: + return GL_UNSIGNED_INT_2_10_10_10_REV; + case SG_VERTEXFORMAT_HALF2: + case SG_VERTEXFORMAT_HALF4: + return GL_HALF_FLOAT; + default: + SOKOL_UNREACHABLE; return 0; + } +} + +_SOKOL_PRIVATE GLboolean _sg_gl_vertexformat_normalized(sg_vertex_format fmt) { + switch (fmt) { + case SG_VERTEXFORMAT_BYTE4N: + case SG_VERTEXFORMAT_UBYTE4N: + case SG_VERTEXFORMAT_SHORT2N: + case SG_VERTEXFORMAT_USHORT2N: + case SG_VERTEXFORMAT_SHORT4N: + case SG_VERTEXFORMAT_USHORT4N: + case SG_VERTEXFORMAT_INT10_N2: + case SG_VERTEXFORMAT_UINT10_N2: + return GL_TRUE; + default: + return GL_FALSE; + } +} + +_SOKOL_PRIVATE GLenum _sg_gl_primitive_type(sg_primitive_type t) { + switch (t) { + case SG_PRIMITIVETYPE_POINTS: return GL_POINTS; + case SG_PRIMITIVETYPE_LINES: return GL_LINES; + case SG_PRIMITIVETYPE_LINE_STRIP: return GL_LINE_STRIP; + case SG_PRIMITIVETYPE_TRIANGLES: return GL_TRIANGLES; + case SG_PRIMITIVETYPE_TRIANGLE_STRIP: return GL_TRIANGLE_STRIP; + default: SOKOL_UNREACHABLE; return 0; + } +} + +_SOKOL_PRIVATE GLenum _sg_gl_index_type(sg_index_type t) { + switch (t) { + case SG_INDEXTYPE_NONE: return 0; + case SG_INDEXTYPE_UINT16: return GL_UNSIGNED_SHORT; + case SG_INDEXTYPE_UINT32: return GL_UNSIGNED_INT; + default: SOKOL_UNREACHABLE; return 0; + } +} + +_SOKOL_PRIVATE GLenum _sg_gl_compare_func(sg_compare_func cmp) { + switch (cmp) { + case SG_COMPAREFUNC_NEVER: return GL_NEVER; + case SG_COMPAREFUNC_LESS: return GL_LESS; + case SG_COMPAREFUNC_EQUAL: return GL_EQUAL; + case SG_COMPAREFUNC_LESS_EQUAL: return GL_LEQUAL; + case SG_COMPAREFUNC_GREATER: return GL_GREATER; + case SG_COMPAREFUNC_NOT_EQUAL: return GL_NOTEQUAL; + case SG_COMPAREFUNC_GREATER_EQUAL: return GL_GEQUAL; + case SG_COMPAREFUNC_ALWAYS: return GL_ALWAYS; + default: SOKOL_UNREACHABLE; return 0; + } +} + +_SOKOL_PRIVATE GLenum _sg_gl_stencil_op(sg_stencil_op op) { + switch (op) { + case SG_STENCILOP_KEEP: return GL_KEEP; + case SG_STENCILOP_ZERO: return GL_ZERO; + case SG_STENCILOP_REPLACE: return GL_REPLACE; + case SG_STENCILOP_INCR_CLAMP: return GL_INCR; + case SG_STENCILOP_DECR_CLAMP: return GL_DECR; + case SG_STENCILOP_INVERT: return GL_INVERT; + case SG_STENCILOP_INCR_WRAP: return GL_INCR_WRAP; + case SG_STENCILOP_DECR_WRAP: return GL_DECR_WRAP; + default: SOKOL_UNREACHABLE; return 0; + } +} + +_SOKOL_PRIVATE GLenum _sg_gl_blend_factor(sg_blend_factor f) { + switch (f) { + case SG_BLENDFACTOR_ZERO: return GL_ZERO; + case SG_BLENDFACTOR_ONE: return GL_ONE; + case SG_BLENDFACTOR_SRC_COLOR: return GL_SRC_COLOR; + case SG_BLENDFACTOR_ONE_MINUS_SRC_COLOR: return GL_ONE_MINUS_SRC_COLOR; + case SG_BLENDFACTOR_SRC_ALPHA: return GL_SRC_ALPHA; + case SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA: return GL_ONE_MINUS_SRC_ALPHA; + case SG_BLENDFACTOR_DST_COLOR: return GL_DST_COLOR; + case SG_BLENDFACTOR_ONE_MINUS_DST_COLOR: return GL_ONE_MINUS_DST_COLOR; + case SG_BLENDFACTOR_DST_ALPHA: return GL_DST_ALPHA; + case SG_BLENDFACTOR_ONE_MINUS_DST_ALPHA: return GL_ONE_MINUS_DST_ALPHA; + case SG_BLENDFACTOR_SRC_ALPHA_SATURATED: return GL_SRC_ALPHA_SATURATE; + case SG_BLENDFACTOR_BLEND_COLOR: return GL_CONSTANT_COLOR; + case SG_BLENDFACTOR_ONE_MINUS_BLEND_COLOR: return GL_ONE_MINUS_CONSTANT_COLOR; + case SG_BLENDFACTOR_BLEND_ALPHA: return GL_CONSTANT_ALPHA; + case SG_BLENDFACTOR_ONE_MINUS_BLEND_ALPHA: return GL_ONE_MINUS_CONSTANT_ALPHA; + #if defined(_SOKOL_GL_HAS_DUALSOURCEBLENDING) + case SG_BLENDFACTOR_SRC1_COLOR: return GL_SRC1_COLOR; + case SG_BLENDFACTOR_ONE_MINUS_SRC1_COLOR: return GL_ONE_MINUS_SRC1_COLOR; + case SG_BLENDFACTOR_SRC1_ALPHA: return GL_SRC1_ALPHA; + case SG_BLENDFACTOR_ONE_MINUS_SRC1_ALPHA: return GL_ONE_MINUS_SRC1_ALPHA; + #endif + default: SOKOL_UNREACHABLE; return 0; + } +} + +_SOKOL_PRIVATE GLenum _sg_gl_blend_op(sg_blend_op op) { + switch (op) { + case SG_BLENDOP_ADD: return GL_FUNC_ADD; + case SG_BLENDOP_SUBTRACT: return GL_FUNC_SUBTRACT; + case SG_BLENDOP_REVERSE_SUBTRACT: return GL_FUNC_REVERSE_SUBTRACT; + case SG_BLENDOP_MIN: return GL_MIN; + case SG_BLENDOP_MAX: return GL_MAX; + default: SOKOL_UNREACHABLE; return 0; + } +} + +_SOKOL_PRIVATE GLenum _sg_gl_min_filter(sg_filter min_f, sg_filter mipmap_f) { + if (min_f == SG_FILTER_NEAREST) { + switch (mipmap_f) { + case SG_FILTER_NEAREST: return GL_NEAREST_MIPMAP_NEAREST; + case SG_FILTER_LINEAR: return GL_NEAREST_MIPMAP_LINEAR; + default: SOKOL_UNREACHABLE; return (GLenum)0; + } + } else if (min_f == SG_FILTER_LINEAR) { + switch (mipmap_f) { + case SG_FILTER_NEAREST: return GL_LINEAR_MIPMAP_NEAREST; + case SG_FILTER_LINEAR: return GL_LINEAR_MIPMAP_LINEAR; + default: SOKOL_UNREACHABLE; return (GLenum)0; + } + } else { + SOKOL_UNREACHABLE; return (GLenum)0; + } +} + +_SOKOL_PRIVATE GLenum _sg_gl_mag_filter(sg_filter mag_f) { + if (mag_f == SG_FILTER_NEAREST) { + return GL_NEAREST; + } else { + return GL_LINEAR; + } +} + +_SOKOL_PRIVATE GLenum _sg_gl_wrap(sg_wrap w) { + switch (w) { + case SG_WRAP_CLAMP_TO_EDGE: return GL_CLAMP_TO_EDGE; + #if defined(SOKOL_GLCORE) + case SG_WRAP_CLAMP_TO_BORDER: return GL_CLAMP_TO_BORDER; + #else + case SG_WRAP_CLAMP_TO_BORDER: return GL_CLAMP_TO_EDGE; + #endif + case SG_WRAP_REPEAT: return GL_REPEAT; + case SG_WRAP_MIRRORED_REPEAT: return GL_MIRRORED_REPEAT; + default: SOKOL_UNREACHABLE; return 0; + } +} + +_SOKOL_PRIVATE GLenum _sg_gl_teximage_type(sg_pixel_format fmt) { + switch (fmt) { + case SG_PIXELFORMAT_R8: + case SG_PIXELFORMAT_R8UI: + case SG_PIXELFORMAT_RG8: + case SG_PIXELFORMAT_RG8UI: + case SG_PIXELFORMAT_RGBA8: + case SG_PIXELFORMAT_SRGB8A8: + case SG_PIXELFORMAT_RGBA8UI: + case SG_PIXELFORMAT_BGRA8: + return GL_UNSIGNED_BYTE; + case SG_PIXELFORMAT_R8SN: + case SG_PIXELFORMAT_R8SI: + case SG_PIXELFORMAT_RG8SN: + case SG_PIXELFORMAT_RG8SI: + case SG_PIXELFORMAT_RGBA8SN: + case SG_PIXELFORMAT_RGBA8SI: + return GL_BYTE; + case SG_PIXELFORMAT_R16: + case SG_PIXELFORMAT_R16UI: + case SG_PIXELFORMAT_RG16: + case SG_PIXELFORMAT_RG16UI: + case SG_PIXELFORMAT_RGBA16: + case SG_PIXELFORMAT_RGBA16UI: + return GL_UNSIGNED_SHORT; + case SG_PIXELFORMAT_R16SN: + case SG_PIXELFORMAT_R16SI: + case SG_PIXELFORMAT_RG16SN: + case SG_PIXELFORMAT_RG16SI: + case SG_PIXELFORMAT_RGBA16SN: + case SG_PIXELFORMAT_RGBA16SI: + return GL_SHORT; + case SG_PIXELFORMAT_R16F: + case SG_PIXELFORMAT_RG16F: + case SG_PIXELFORMAT_RGBA16F: + return GL_HALF_FLOAT; + case SG_PIXELFORMAT_R32UI: + case SG_PIXELFORMAT_RG32UI: + case SG_PIXELFORMAT_RGBA32UI: + return GL_UNSIGNED_INT; + case SG_PIXELFORMAT_R32SI: + case SG_PIXELFORMAT_RG32SI: + case SG_PIXELFORMAT_RGBA32SI: + return GL_INT; + case SG_PIXELFORMAT_R32F: + case SG_PIXELFORMAT_RG32F: + case SG_PIXELFORMAT_RGBA32F: + return GL_FLOAT; + case SG_PIXELFORMAT_RGB10A2: + return GL_UNSIGNED_INT_2_10_10_10_REV; + case SG_PIXELFORMAT_RG11B10F: + return GL_UNSIGNED_INT_10F_11F_11F_REV; + case SG_PIXELFORMAT_RGB9E5: + return GL_UNSIGNED_INT_5_9_9_9_REV; + case SG_PIXELFORMAT_DEPTH: + return GL_FLOAT; + case SG_PIXELFORMAT_DEPTH_STENCIL: + return GL_UNSIGNED_INT_24_8; + default: + SOKOL_UNREACHABLE; return 0; + } +} + +_SOKOL_PRIVATE GLenum _sg_gl_teximage_format(sg_pixel_format fmt) { + switch (fmt) { + case SG_PIXELFORMAT_R8: + case SG_PIXELFORMAT_R8SN: + case SG_PIXELFORMAT_R16: + case SG_PIXELFORMAT_R16SN: + case SG_PIXELFORMAT_R16F: + case SG_PIXELFORMAT_R32F: + return GL_RED; + case SG_PIXELFORMAT_R8UI: + case SG_PIXELFORMAT_R8SI: + case SG_PIXELFORMAT_R16UI: + case SG_PIXELFORMAT_R16SI: + case SG_PIXELFORMAT_R32UI: + case SG_PIXELFORMAT_R32SI: + return GL_RED_INTEGER; + case SG_PIXELFORMAT_RG8: + case SG_PIXELFORMAT_RG8SN: + case SG_PIXELFORMAT_RG16: + case SG_PIXELFORMAT_RG16SN: + case SG_PIXELFORMAT_RG16F: + case SG_PIXELFORMAT_RG32F: + return GL_RG; + case SG_PIXELFORMAT_RG8UI: + case SG_PIXELFORMAT_RG8SI: + case SG_PIXELFORMAT_RG16UI: + case SG_PIXELFORMAT_RG16SI: + case SG_PIXELFORMAT_RG32UI: + case SG_PIXELFORMAT_RG32SI: + return GL_RG_INTEGER; + case SG_PIXELFORMAT_RGBA8: + case SG_PIXELFORMAT_SRGB8A8: + case SG_PIXELFORMAT_RGBA8SN: + case SG_PIXELFORMAT_RGBA16: + case SG_PIXELFORMAT_RGBA16SN: + case SG_PIXELFORMAT_RGBA16F: + case SG_PIXELFORMAT_RGBA32F: + case SG_PIXELFORMAT_RGB10A2: + return GL_RGBA; + case SG_PIXELFORMAT_RGBA8UI: + case SG_PIXELFORMAT_RGBA8SI: + case SG_PIXELFORMAT_RGBA16UI: + case SG_PIXELFORMAT_RGBA16SI: + case SG_PIXELFORMAT_RGBA32UI: + case SG_PIXELFORMAT_RGBA32SI: + return GL_RGBA_INTEGER; + case SG_PIXELFORMAT_RG11B10F: + case SG_PIXELFORMAT_RGB9E5: + return GL_RGB; + case SG_PIXELFORMAT_DEPTH: + return GL_DEPTH_COMPONENT; + case SG_PIXELFORMAT_DEPTH_STENCIL: + return GL_DEPTH_STENCIL; + case SG_PIXELFORMAT_BC1_RGBA: + return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; + case SG_PIXELFORMAT_BC2_RGBA: + return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; + case SG_PIXELFORMAT_BC3_RGBA: + return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; + case SG_PIXELFORMAT_BC3_SRGBA: + return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT; + case SG_PIXELFORMAT_BC4_R: + return GL_COMPRESSED_RED_RGTC1; + case SG_PIXELFORMAT_BC4_RSN: + return GL_COMPRESSED_SIGNED_RED_RGTC1; + case SG_PIXELFORMAT_BC5_RG: + return GL_COMPRESSED_RED_GREEN_RGTC2; + case SG_PIXELFORMAT_BC5_RGSN: + return GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2; + case SG_PIXELFORMAT_BC6H_RGBF: + return GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB; + case SG_PIXELFORMAT_BC6H_RGBUF: + return GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB; + case SG_PIXELFORMAT_BC7_RGBA: + return GL_COMPRESSED_RGBA_BPTC_UNORM_ARB; + case SG_PIXELFORMAT_BC7_SRGBA: + return GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB; + case SG_PIXELFORMAT_ETC2_RGB8: + return GL_COMPRESSED_RGB8_ETC2; + case SG_PIXELFORMAT_ETC2_SRGB8: + return GL_COMPRESSED_SRGB8_ETC2; + case SG_PIXELFORMAT_ETC2_RGB8A1: + return GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2; + case SG_PIXELFORMAT_ETC2_RGBA8: + return GL_COMPRESSED_RGBA8_ETC2_EAC; + case SG_PIXELFORMAT_ETC2_SRGB8A8: + return GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC; + case SG_PIXELFORMAT_EAC_R11: + return GL_COMPRESSED_R11_EAC; + case SG_PIXELFORMAT_EAC_R11SN: + return GL_COMPRESSED_SIGNED_R11_EAC; + case SG_PIXELFORMAT_EAC_RG11: + return GL_COMPRESSED_RG11_EAC; + case SG_PIXELFORMAT_EAC_RG11SN: + return GL_COMPRESSED_SIGNED_RG11_EAC; + case SG_PIXELFORMAT_ASTC_4x4_RGBA: + return GL_COMPRESSED_RGBA_ASTC_4x4_KHR; + case SG_PIXELFORMAT_ASTC_4x4_SRGBA: + return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR; + default: + SOKOL_UNREACHABLE; return 0; + } +} + +_SOKOL_PRIVATE GLenum _sg_gl_teximage_internal_format(sg_pixel_format fmt) { + switch (fmt) { + case SG_PIXELFORMAT_R8: return GL_R8; + case SG_PIXELFORMAT_R8SN: return GL_R8_SNORM; + case SG_PIXELFORMAT_R8UI: return GL_R8UI; + case SG_PIXELFORMAT_R8SI: return GL_R8I; + #if !defined(SOKOL_GLES3) + case SG_PIXELFORMAT_R16: return GL_R16; + case SG_PIXELFORMAT_R16SN: return GL_R16_SNORM; + #endif + case SG_PIXELFORMAT_R16UI: return GL_R16UI; + case SG_PIXELFORMAT_R16SI: return GL_R16I; + case SG_PIXELFORMAT_R16F: return GL_R16F; + case SG_PIXELFORMAT_RG8: return GL_RG8; + case SG_PIXELFORMAT_RG8SN: return GL_RG8_SNORM; + case SG_PIXELFORMAT_RG8UI: return GL_RG8UI; + case SG_PIXELFORMAT_RG8SI: return GL_RG8I; + case SG_PIXELFORMAT_R32UI: return GL_R32UI; + case SG_PIXELFORMAT_R32SI: return GL_R32I; + case SG_PIXELFORMAT_R32F: return GL_R32F; + #if !defined(SOKOL_GLES3) + case SG_PIXELFORMAT_RG16: return GL_RG16; + case SG_PIXELFORMAT_RG16SN: return GL_RG16_SNORM; + #endif + case SG_PIXELFORMAT_RG16UI: return GL_RG16UI; + case SG_PIXELFORMAT_RG16SI: return GL_RG16I; + case SG_PIXELFORMAT_RG16F: return GL_RG16F; + case SG_PIXELFORMAT_RGBA8: return GL_RGBA8; + case SG_PIXELFORMAT_SRGB8A8: return GL_SRGB8_ALPHA8; + case SG_PIXELFORMAT_RGBA8SN: return GL_RGBA8_SNORM; + case SG_PIXELFORMAT_RGBA8UI: return GL_RGBA8UI; + case SG_PIXELFORMAT_RGBA8SI: return GL_RGBA8I; + case SG_PIXELFORMAT_RGB10A2: return GL_RGB10_A2; + case SG_PIXELFORMAT_RG11B10F: return GL_R11F_G11F_B10F; + case SG_PIXELFORMAT_RGB9E5: return GL_RGB9_E5; + case SG_PIXELFORMAT_RG32UI: return GL_RG32UI; + case SG_PIXELFORMAT_RG32SI: return GL_RG32I; + case SG_PIXELFORMAT_RG32F: return GL_RG32F; + #if !defined(SOKOL_GLES3) + case SG_PIXELFORMAT_RGBA16: return GL_RGBA16; + case SG_PIXELFORMAT_RGBA16SN: return GL_RGBA16_SNORM; + #endif + case SG_PIXELFORMAT_RGBA16UI: return GL_RGBA16UI; + case SG_PIXELFORMAT_RGBA16SI: return GL_RGBA16I; + case SG_PIXELFORMAT_RGBA16F: return GL_RGBA16F; + case SG_PIXELFORMAT_RGBA32UI: return GL_RGBA32UI; + case SG_PIXELFORMAT_RGBA32SI: return GL_RGBA32I; + case SG_PIXELFORMAT_RGBA32F: return GL_RGBA32F; + case SG_PIXELFORMAT_DEPTH: return GL_DEPTH_COMPONENT32F; + case SG_PIXELFORMAT_DEPTH_STENCIL: return GL_DEPTH24_STENCIL8; + case SG_PIXELFORMAT_BC1_RGBA: return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; + case SG_PIXELFORMAT_BC2_RGBA: return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; + case SG_PIXELFORMAT_BC3_RGBA: return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; + case SG_PIXELFORMAT_BC3_SRGBA: return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT; + case SG_PIXELFORMAT_BC4_R: return GL_COMPRESSED_RED_RGTC1; + case SG_PIXELFORMAT_BC4_RSN: return GL_COMPRESSED_SIGNED_RED_RGTC1; + case SG_PIXELFORMAT_BC5_RG: return GL_COMPRESSED_RED_GREEN_RGTC2; + case SG_PIXELFORMAT_BC5_RGSN: return GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2; + case SG_PIXELFORMAT_BC6H_RGBF: return GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB; + case SG_PIXELFORMAT_BC6H_RGBUF: return GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB; + case SG_PIXELFORMAT_BC7_RGBA: return GL_COMPRESSED_RGBA_BPTC_UNORM_ARB; + case SG_PIXELFORMAT_BC7_SRGBA: return GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB; + case SG_PIXELFORMAT_ETC2_RGB8: return GL_COMPRESSED_RGB8_ETC2; + case SG_PIXELFORMAT_ETC2_SRGB8: return GL_COMPRESSED_SRGB8_ETC2; + case SG_PIXELFORMAT_ETC2_RGB8A1: return GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2; + case SG_PIXELFORMAT_ETC2_RGBA8: return GL_COMPRESSED_RGBA8_ETC2_EAC; + case SG_PIXELFORMAT_ETC2_SRGB8A8: return GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC; + case SG_PIXELFORMAT_EAC_R11: return GL_COMPRESSED_R11_EAC; + case SG_PIXELFORMAT_EAC_R11SN: return GL_COMPRESSED_SIGNED_R11_EAC; + case SG_PIXELFORMAT_EAC_RG11: return GL_COMPRESSED_RG11_EAC; + case SG_PIXELFORMAT_EAC_RG11SN: return GL_COMPRESSED_SIGNED_RG11_EAC; + case SG_PIXELFORMAT_ASTC_4x4_RGBA: return GL_COMPRESSED_RGBA_ASTC_4x4_KHR; + case SG_PIXELFORMAT_ASTC_4x4_SRGBA: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR; + default: SOKOL_UNREACHABLE; return 0; + } +} + +_SOKOL_PRIVATE GLenum _sg_gl_cubeface_target(int face_index) { + switch (face_index) { + case 0: return GL_TEXTURE_CUBE_MAP_POSITIVE_X; + case 1: return GL_TEXTURE_CUBE_MAP_NEGATIVE_X; + case 2: return GL_TEXTURE_CUBE_MAP_POSITIVE_Y; + case 3: return GL_TEXTURE_CUBE_MAP_NEGATIVE_Y; + case 4: return GL_TEXTURE_CUBE_MAP_POSITIVE_Z; + case 5: return GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; + default: SOKOL_UNREACHABLE; return 0; + } +} + +// see: https://www.khronos.org/registry/OpenGL-Refpages/es3.0/html/glTexImage2D.xhtml +_SOKOL_PRIVATE void _sg_gl_init_pixelformats(bool has_bgra) { + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_R8]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_R8SN]); + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_R8UI]); + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_R8SI]); + #if !defined(SOKOL_GLES3) + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_R16]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_R16SN]); + #endif + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_R16UI]); + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_R16SI]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RG8]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_RG8SN]); + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_RG8UI]); + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_RG8SI]); + _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_R32UI]); + _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_R32SI]); + #if !defined(SOKOL_GLES3) + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RG16]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RG16SN]); + #endif + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_RG16UI]); + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_RG16SI]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RGBA8]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_SRGB8A8]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_RGBA8SN]); + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_RGBA8UI]); + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_RGBA8SI]); + if (has_bgra) { + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_BGRA8]); + } + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RGB10A2]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_RGB9E5]); + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_RG32UI]); + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_RG32SI]); + #if !defined(SOKOL_GLES3) + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RGBA16]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RGBA16SN]); + #endif + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_RGBA16UI]); + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_RGBA16SI]); + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_RGBA32UI]); + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_RGBA32SI]); + _sg_pixelformat_srmd(&_sg.formats[SG_PIXELFORMAT_DEPTH]); + _sg_pixelformat_srmd(&_sg.formats[SG_PIXELFORMAT_DEPTH_STENCIL]); +} + +// FIXME: OES_half_float_blend +_SOKOL_PRIVATE void _sg_gl_init_pixelformats_half_float(bool has_colorbuffer_half_float) { + if (has_colorbuffer_half_float) { + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_R16F]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RG16F]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RGBA16F]); + } else { + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_R16F]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_RG16F]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_RGBA16F]); + } +} + +_SOKOL_PRIVATE void _sg_gl_init_pixelformats_float(bool has_colorbuffer_float, bool has_texture_float_linear, bool has_float_blend) { + if (has_texture_float_linear) { + if (has_colorbuffer_float) { + if (has_float_blend) { + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_R32F]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RG32F]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RGBA32F]); + } else { + _sg_pixelformat_sfrm(&_sg.formats[SG_PIXELFORMAT_R32F]); + _sg_pixelformat_sfrm(&_sg.formats[SG_PIXELFORMAT_RG32F]); + _sg_pixelformat_sfrm(&_sg.formats[SG_PIXELFORMAT_RGBA32F]); + } + _sg_pixelformat_sfrm(&_sg.formats[SG_PIXELFORMAT_RG11B10F]); + } else { + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_R32F]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_RG32F]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_RGBA32F]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_RG11B10F]); + } + } else { + if (has_colorbuffer_float) { + _sg_pixelformat_sbrm(&_sg.formats[SG_PIXELFORMAT_R32F]); + _sg_pixelformat_sbrm(&_sg.formats[SG_PIXELFORMAT_RG32F]); + _sg_pixelformat_sbrm(&_sg.formats[SG_PIXELFORMAT_RGBA32F]); + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_RG11B10F]); + } else { + _sg_pixelformat_s(&_sg.formats[SG_PIXELFORMAT_R32F]); + _sg_pixelformat_s(&_sg.formats[SG_PIXELFORMAT_RG32F]); + _sg_pixelformat_s(&_sg.formats[SG_PIXELFORMAT_RGBA32F]); + _sg_pixelformat_s(&_sg.formats[SG_PIXELFORMAT_RG11B10F]); + } + } +} + +_SOKOL_PRIVATE void _sg_gl_init_pixelformats_s3tc(void) { + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC1_RGBA]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC2_RGBA]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC3_RGBA]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC3_SRGBA]); +} + +_SOKOL_PRIVATE void _sg_gl_init_pixelformats_rgtc(void) { + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC4_R]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC4_RSN]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC5_RG]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC5_RGSN]); +} + +_SOKOL_PRIVATE void _sg_gl_init_pixelformats_bptc(void) { + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC6H_RGBF]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC6H_RGBUF]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC7_RGBA]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC7_SRGBA]); +} + +_SOKOL_PRIVATE void _sg_gl_init_pixelformats_etc2(void) { + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RGB8]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_SRGB8]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RGB8A1]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RGBA8]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_SRGB8A8]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_R11]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_R11SN]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_RG11]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_RG11SN]); +} + +_SOKOL_PRIVATE void _sg_gl_init_pixelformats_astc(void) { + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ASTC_4x4_RGBA]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ASTC_4x4_SRGBA]); +} + +_SOKOL_PRIVATE void _sg_gl_init_limits(void) { + _SG_GL_CHECK_ERROR(); + + GLint gl_int; + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_int); + _SG_GL_CHECK_ERROR(); + + _sg.limits.max_image_size_2d = gl_int; + _sg.limits.max_image_size_array = gl_int; + + glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, &gl_int); + _SG_GL_CHECK_ERROR(); + _sg.limits.max_image_size_cube = gl_int; + + glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, &gl_int); + _SG_GL_CHECK_ERROR(); + _sg.limits.max_image_size_3d = gl_int; + + glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &gl_int); + _SG_GL_CHECK_ERROR(); + _sg.limits.max_image_array_layers = gl_int; + + glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &gl_int); + _SG_GL_CHECK_ERROR(); + _sg.limits.max_vertex_attrs = _sg_min(gl_int, SG_MAX_VERTEX_ATTRIBUTES); + + glGetIntegerv(GL_MAX_DRAW_BUFFERS, &gl_int); + _SG_GL_CHECK_ERROR(); + _sg.limits.max_color_attachments = _sg_min(gl_int, SG_MAX_COLOR_ATTACHMENTS); + + glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &gl_int); + _SG_GL_CHECK_ERROR(); + _sg.limits.max_texture_bindings_per_stage = _sg_min(gl_int, SG_MAX_VIEW_BINDSLOTS); + + #if defined(_SOKOL_GL_HAS_COMPUTE) + if (_sg.features.compute) { + glGetIntegerv(GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS, &gl_int); + _SG_GL_CHECK_ERROR(); + _sg.limits.max_storage_buffer_bindings_per_stage = _sg_min(gl_int, SG_MAX_VIEW_BINDSLOTS); + + glGetIntegerv(GL_MAX_IMAGE_UNITS, &gl_int); + _SG_GL_CHECK_ERROR(); + _sg.limits.max_storage_image_bindings_per_stage = _sg_min(gl_int, SG_MAX_VIEW_BINDSLOTS); + } + #endif + + glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS, &gl_int); + _SG_GL_CHECK_ERROR(); + _sg.limits.gl_max_vertex_uniform_components = gl_int; + + if (_sg.gl.ext_anisotropic) { + glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &gl_int); + _SG_GL_CHECK_ERROR(); + _sg.gl.max_anisotropy = gl_int; + } else { + _sg.gl.max_anisotropy = 1; + } + + glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &gl_int); + _SG_GL_CHECK_ERROR(); + _sg.limits.gl_max_combined_texture_image_units = gl_int; +} + +#if defined(SOKOL_GLCORE) +_SOKOL_PRIVATE void _sg_gl_init_caps_glcore(void) { + _sg.backend = SG_BACKEND_GLCORE; + + GLint major_version = 0; + GLint minor_version = 0; + glGetIntegerv(GL_MAJOR_VERSION, &major_version); + glGetIntegerv(GL_MINOR_VERSION, &minor_version); + const int version = major_version * 100 + minor_version * 10; + _sg.features.origin_top_left = false; + _sg.features.image_clamp_to_border = true; + _sg.features.mrt_independent_blend_state = false; + _sg.features.mrt_independent_write_mask = true; + _sg.features.compute = version >= 430; + _sg.features.gl_texture_views = version >= 430; + #if defined(__APPLE__) + _sg.features.msaa_texture_bindings = false; + #else + _sg.features.msaa_texture_bindings = true; + #endif + _sg.features.draw_base_vertex = version >= 320; + _sg.features.draw_base_instance = version >= 420; + _sg.features.dual_source_blending = version >= 330; + _sg.features.vertexformat_int10_n2 = true; + + // scan extensions + bool has_s3tc = false; // BC1..BC3 + bool has_rgtc = false; // BC4 and BC5 + bool has_bptc = false; // BC6H and BC7 + bool has_etc2 = false; + bool has_astc = false; + GLint num_ext = 0; + glGetIntegerv(GL_NUM_EXTENSIONS, &num_ext); + for (int i = 0; i < num_ext; i++) { + const char* ext = (const char*) glGetStringi(GL_EXTENSIONS, (GLuint)i); + if (ext) { + if (strstr(ext, "_texture_compression_s3tc")) { + has_s3tc = true; + } else if (strstr(ext, "_texture_compression_rgtc")) { + has_rgtc = true; + } else if (strstr(ext, "_texture_compression_bptc")) { + has_bptc = true; + } else if (strstr(ext, "_ES3_compatibility")) { + has_etc2 = true; + } else if (strstr(ext, "_texture_filter_anisotropic")) { + _sg.gl.ext_anisotropic = true; + } else if (strstr(ext, "_texture_compression_astc_ldr")) { + has_astc = true; + } + } + } + + // limits + _sg_gl_init_limits(); + + // pixel formats + const bool has_bgra = false; // not a bug + const bool has_colorbuffer_float = true; + const bool has_colorbuffer_half_float = true; + const bool has_texture_float_linear = true; // FIXME??? + const bool has_float_blend = true; + _sg_gl_init_pixelformats(has_bgra); + _sg_gl_init_pixelformats_float(has_colorbuffer_float, has_texture_float_linear, has_float_blend); + _sg_gl_init_pixelformats_half_float(has_colorbuffer_half_float); + if (has_s3tc) { + _sg_gl_init_pixelformats_s3tc(); + } + if (has_rgtc) { + _sg_gl_init_pixelformats_rgtc(); + } + if (has_bptc) { + _sg_gl_init_pixelformats_bptc(); + } + if (has_etc2) { + _sg_gl_init_pixelformats_etc2(); + } + if (has_astc) { + _sg_gl_init_pixelformats_astc(); + } + if (_sg.features.compute) { + // see: https://registry.khronos.org/OpenGL-Refpages/gl4/html/glBindImageTexture.xhtml + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA32F]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA16F]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG32F]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG16F]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG11B10F]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA32UI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA16UI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R32F]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R16F]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA8UI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG32UI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG16UI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG8UI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R32UI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R16UI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R8UI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA32SI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA16SI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA8SI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG32SI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG16SI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG8SI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R32SI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R16SI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R8SI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA16]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGB10A2]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA8]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG16]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG8]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R16]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R8]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA16SN]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA8SN]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG16SN]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG8SN]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R16SN]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R8SN]); + } +} +#endif + +#if defined(SOKOL_GLES3) +_SOKOL_PRIVATE void _sg_gl_init_caps_gles3(void) { + _sg.backend = SG_BACKEND_GLES3; + + GLint major_version = 0; + GLint minor_version = 0; + glGetIntegerv(GL_MAJOR_VERSION, &major_version); + glGetIntegerv(GL_MINOR_VERSION, &minor_version); + const int version = major_version * 100 + minor_version * 10; + _sg.features.origin_top_left = false; + _sg.features.image_clamp_to_border = false; + _sg.features.mrt_independent_blend_state = false; + #if defined(_SOKOL_GL_HAS_COLORMASKI) + _sg.features.mrt_independent_write_mask = version >= 320; + #else + _sg.features.mrt_independent_write_mask = false; + #endif + _sg.features.compute = version >= 310; + _sg.features.msaa_texture_bindings = false; + _sg.features.gl_texture_views = version >= 430; + #if defined(__EMSCRIPTEN__) + _sg.features.separate_buffer_types = true; + #else + _sg.features.separate_buffer_types = false; + #endif + _sg.features.draw_base_vertex = version >= 320; + _sg.features.draw_base_instance = false; + _sg.features.dual_source_blending = false; + _sg.features.vertexformat_int10_n2 = true; + + bool has_s3tc = false; // BC1..BC3 + bool has_rgtc = false; // BC4 and BC5 + bool has_bptc = false; // BC6H and BC7 + #if defined(__EMSCRIPTEN__) + bool has_etc2 = false; + #else + bool has_etc2 = true; + #endif + bool has_astc = false; + bool has_colorbuffer_float = false; + bool has_colorbuffer_half_float = false; + bool has_texture_float_linear = false; + bool has_float_blend = false; + GLint num_ext = 0; + glGetIntegerv(GL_NUM_EXTENSIONS, &num_ext); + for (int i = 0; i < num_ext; i++) { + const char* ext = (const char*) glGetStringi(GL_EXTENSIONS, (GLuint)i); + if (ext) { + if (strstr(ext, "_texture_compression_s3tc")) { + has_s3tc = true; + } else if (strstr(ext, "_compressed_texture_s3tc")) { + has_s3tc = true; + } else if (strstr(ext, "_texture_compression_rgtc")) { + has_rgtc = true; + } else if (strstr(ext, "_texture_compression_bptc")) { + has_bptc = true; + } else if (strstr(ext, "_compressed_texture_etc")) { + has_etc2 = true; + } else if (strstr(ext, "_compressed_texture_astc")) { + has_astc = true; + } else if (strstr(ext, "_color_buffer_float")) { + has_colorbuffer_float = true; + } else if (strstr(ext, "_color_buffer_half_float")) { + has_colorbuffer_half_float = true; + } else if (strstr(ext, "_texture_float_linear")) { + has_texture_float_linear = true; + } else if (strstr(ext, "_float_blend")) { + has_float_blend = true; + } else if (strstr(ext, "_texture_filter_anisotropic")) { + _sg.gl.ext_anisotropic = true; + } + } + } + + /* on WebGL2, color_buffer_float also includes 16-bit formats + see: https://developer.mozilla.org/en-US/docs/Web/API/EXT_color_buffer_float + */ + #if defined(__EMSCRIPTEN__) + if (!has_colorbuffer_half_float && has_colorbuffer_float) { + has_colorbuffer_half_float = has_colorbuffer_float; + } + #endif + + // limits + _sg_gl_init_limits(); + + // pixel formats + const bool has_bgra = false; // not a bug + _sg_gl_init_pixelformats(has_bgra); + _sg_gl_init_pixelformats_float(has_colorbuffer_float, has_texture_float_linear, has_float_blend); + _sg_gl_init_pixelformats_half_float(has_colorbuffer_half_float); + if (has_s3tc) { + _sg_gl_init_pixelformats_s3tc(); + } + if (has_rgtc) { + _sg_gl_init_pixelformats_rgtc(); + } + if (has_bptc) { + _sg_gl_init_pixelformats_bptc(); + } + if (has_etc2) { + _sg_gl_init_pixelformats_etc2(); + } + if (has_astc) { + _sg_gl_init_pixelformats_astc(); + } + if (_sg.features.compute) { + // see https://registry.khronos.org/OpenGL-Refpages/es3.1/html/glBindImageTexture.xhtml + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA32F]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA16F]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R32F]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA32UI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA16UI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA8UI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R32UI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA32SI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA16SI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA8SI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R32SI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA8]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA8SN]); + } +} +#endif + +//-- state cache implementation ------------------------------------------------ +_SOKOL_PRIVATE void _sg_gl_cache_clear_buffer_bindings(bool force) { + if (force || (_sg.gl.cache.vertex_buffer != 0)) { + glBindBuffer(GL_ARRAY_BUFFER, 0); + _sg.gl.cache.vertex_buffer = 0; + _sg_stats_inc(gl.num_bind_buffer); + } + if (force || (_sg.gl.cache.index_buffer != 0)) { + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + _sg.gl.cache.index_buffer = 0; + _sg_stats_inc(gl.num_bind_buffer); + } + if (force || (_sg.gl.cache.storage_buffer != 0)) { + if (_sg.features.compute) { + glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); + } + _sg.gl.cache.storage_buffer = 0; + _sg_stats_inc(gl.num_bind_buffer); + } + for (int i = 0; i < _SG_GL_MAX_SBUF_BINDINGS; i++) { + if (force || (_sg.gl.cache.storage_buffers[i] != 0)) { + if (_sg.features.compute && (i < _sg.limits.max_storage_buffer_bindings_per_stage)) { + glBindBufferBase(GL_SHADER_STORAGE_BUFFER, (GLuint)i, 0); + } + _sg.gl.cache.storage_buffers[i] = 0; + _sg_stats_inc(gl.num_bind_buffer); + } + } +} + +_SOKOL_PRIVATE void _sg_gl_cache_bind_buffer(GLenum target, GLuint buffer) { + SOKOL_ASSERT((GL_ARRAY_BUFFER == target) || (GL_ELEMENT_ARRAY_BUFFER == target) || (GL_SHADER_STORAGE_BUFFER == target)); + if (target == GL_ARRAY_BUFFER) { + if (_sg.gl.cache.vertex_buffer != buffer) { + _sg.gl.cache.vertex_buffer = buffer; + glBindBuffer(target, buffer); + _sg_stats_inc(gl.num_bind_buffer); + } + } else if (target == GL_ELEMENT_ARRAY_BUFFER) { + if (_sg.gl.cache.index_buffer != buffer) { + _sg.gl.cache.index_buffer = buffer; + glBindBuffer(target, buffer); + _sg_stats_inc(gl.num_bind_buffer); + } + } else if (target == GL_SHADER_STORAGE_BUFFER) { + if (_sg.gl.cache.storage_buffer != buffer) { + _sg.gl.cache.storage_buffer = buffer; + if (_sg.features.compute) { + glBindBuffer(target, buffer); + } + _sg_stats_inc(gl.num_bind_buffer); + } + } else { + SOKOL_UNREACHABLE; + } +} + +_SOKOL_PRIVATE void _sg_gl_cache_bind_storage_buffer(uint8_t glsl_binding_n, GLuint buffer, int offset, int buf_size) { + SOKOL_ASSERT(glsl_binding_n < _SG_GL_MAX_SBUF_BINDINGS); + SOKOL_ASSERT(offset < buf_size); + const bool buf_neql = _sg.gl.cache.storage_buffers[glsl_binding_n] != buffer; + const bool off_neql = _sg.gl.cache.storage_buffer_offsets[glsl_binding_n] != offset; + if (buf_neql || off_neql) { + _sg.gl.cache.storage_buffers[glsl_binding_n] = buffer; + _sg.gl.cache.storage_buffer_offsets[glsl_binding_n] = offset; + _sg.gl.cache.storage_buffer = buffer; // not a bug + if (_sg.features.compute) { + SOKOL_ASSERT(glsl_binding_n < _sg.limits.max_storage_buffer_bindings_per_stage); + glBindBufferRange(GL_SHADER_STORAGE_BUFFER, glsl_binding_n, buffer, offset, buf_size - offset); + } + _sg_stats_inc(gl.num_bind_buffer); + } +} + +_SOKOL_PRIVATE void _sg_gl_cache_store_buffer_binding(GLenum target) { + if (target == GL_ARRAY_BUFFER) { + _sg.gl.cache.stored_vertex_buffer = _sg.gl.cache.vertex_buffer; + } else if (target == GL_ELEMENT_ARRAY_BUFFER) { + _sg.gl.cache.stored_index_buffer = _sg.gl.cache.index_buffer; + } else if (target == GL_SHADER_STORAGE_BUFFER) { + _sg.gl.cache.stored_storage_buffer = _sg.gl.cache.storage_buffer; + } else { + SOKOL_UNREACHABLE; + } +} + +_SOKOL_PRIVATE void _sg_gl_cache_restore_buffer_binding(GLenum target) { + if (target == GL_ARRAY_BUFFER) { + if (_sg.gl.cache.stored_vertex_buffer != 0) { + // we only care about restoring valid ids + _sg_gl_cache_bind_buffer(target, _sg.gl.cache.stored_vertex_buffer); + _sg.gl.cache.stored_vertex_buffer = 0; + } + } else if (target == GL_ELEMENT_ARRAY_BUFFER) { + if (_sg.gl.cache.stored_index_buffer != 0) { + // we only care about restoring valid ids + _sg_gl_cache_bind_buffer(target, _sg.gl.cache.stored_index_buffer); + _sg.gl.cache.stored_index_buffer = 0; + } + } else if (target == GL_SHADER_STORAGE_BUFFER) { + if (_sg.gl.cache.stored_storage_buffer != 0) { + // we only care about restoring valid ids + _sg_gl_cache_bind_buffer(target, _sg.gl.cache.stored_storage_buffer); + _sg.gl.cache.stored_storage_buffer = 0; + } + } else { + SOKOL_UNREACHABLE; + } +} + +// called from _sg_gl_discard_buffer() +_SOKOL_PRIVATE void _sg_gl_cache_invalidate_buffer(GLuint buf) { + if (buf == _sg.gl.cache.vertex_buffer) { + _sg.gl.cache.vertex_buffer = 0; + glBindBuffer(GL_ARRAY_BUFFER, 0); + _sg_stats_inc(gl.num_bind_buffer); + } + if (buf == _sg.gl.cache.index_buffer) { + _sg.gl.cache.index_buffer = 0; + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + _sg_stats_inc(gl.num_bind_buffer); + } + if (buf == _sg.gl.cache.storage_buffer) { + _sg.gl.cache.storage_buffer = 0; + glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); + _sg_stats_inc(gl.num_bind_buffer); + } + for (int i = 0; i < _SG_GL_MAX_SBUF_BINDINGS; i++) { + if (buf == _sg.gl.cache.storage_buffers[i]) { + _sg.gl.cache.storage_buffers[i] = 0; + _sg.gl.cache.storage_buffer = 0; // not a bug! + if (_sg.features.compute && (i < _sg.limits.max_storage_buffer_bindings_per_stage)) { + glBindBufferBase(GL_SHADER_STORAGE_BUFFER, (GLuint)i, 0); + } + _sg_stats_inc(gl.num_bind_buffer); + } + } + if (buf == _sg.gl.cache.stored_vertex_buffer) { + _sg.gl.cache.stored_vertex_buffer = 0; + } + if (buf == _sg.gl.cache.stored_index_buffer) { + _sg.gl.cache.stored_index_buffer = 0; + } + if (buf == _sg.gl.cache.stored_storage_buffer) { + _sg.gl.cache.stored_storage_buffer = 0; + } + for (int i = 0; i < SG_MAX_VERTEX_ATTRIBUTES; i++) { + if (buf == _sg.gl.cache.attrs[i].gl_vbuf) { + _sg.gl.cache.attrs[i].gl_vbuf = 0; + } + } +} + +_SOKOL_PRIVATE void _sg_gl_cache_active_texture(GLenum texture) { + _SG_GL_CHECK_ERROR(); + if (_sg.gl.cache.cur_active_texture != texture) { + _sg.gl.cache.cur_active_texture = texture; + glActiveTexture(texture); + _sg_stats_inc(gl.num_active_texture); + } + _SG_GL_CHECK_ERROR(); +} + +_SOKOL_PRIVATE void _sg_gl_cache_clear_texture_sampler_bindings(bool force) { + _SG_GL_CHECK_ERROR(); + for (int i = 0; (i < _SG_GL_MAX_TEX_SMP_BINDINGS) && (i < _sg.limits.gl_max_combined_texture_image_units); i++) { + if (force || (_sg.gl.cache.texture_samplers[i].texture != 0)) { + GLenum gl_texture_unit = (GLenum) (GL_TEXTURE0 + i); + glActiveTexture(gl_texture_unit); + _sg_stats_inc(gl.num_active_texture); + glBindTexture(GL_TEXTURE_2D, 0); + glBindTexture(GL_TEXTURE_CUBE_MAP, 0); + glBindTexture(GL_TEXTURE_3D, 0); + glBindTexture(GL_TEXTURE_2D_ARRAY, 0); + _sg_stats_add(gl.num_bind_texture, 4); + glBindSampler((GLuint)i, 0); + _sg_stats_inc(gl.num_bind_sampler); + _sg.gl.cache.texture_samplers[i].target = 0; + _sg.gl.cache.texture_samplers[i].texture = 0; + _sg.gl.cache.texture_samplers[i].sampler = 0; + _sg.gl.cache.cur_active_texture = gl_texture_unit; + } + } + _SG_GL_CHECK_ERROR(); +} + +_SOKOL_PRIVATE void _sg_gl_cache_bind_texture_sampler(int8_t gl_tex_slot, GLenum target, GLuint texture, GLuint sampler) { + /* it's valid to call this function with target=0 and/or texture=0 + target=0 will unbind the previous binding, texture=0 will clear + the new binding + */ + SOKOL_ASSERT((gl_tex_slot >= 0) && (gl_tex_slot < _SG_GL_MAX_TEX_SMP_BINDINGS)); + if (gl_tex_slot >= _sg.limits.gl_max_combined_texture_image_units) { + return; + } + _SG_GL_CHECK_ERROR(); + _sg_gl_cache_texture_sampler_bind_slot* slot = &_sg.gl.cache.texture_samplers[gl_tex_slot]; + if ((slot->target != target) || (slot->texture != texture) || (slot->sampler != sampler)) { + _sg_gl_cache_active_texture((GLenum)(GL_TEXTURE0 + gl_tex_slot)); + // if the target has changed, clear the previous binding on that target + if ((target != slot->target) && (slot->target != 0)) { + glBindTexture(slot->target, 0); + _SG_GL_CHECK_ERROR(); + _sg_stats_inc(gl.num_bind_texture); + } + // apply new binding (can be 0 to unbind) + if (target != 0) { + glBindTexture(target, texture); + _SG_GL_CHECK_ERROR(); + _sg_stats_inc(gl.num_bind_texture); + } + // apply new sampler (can be 0 to unbind) + glBindSampler((GLuint)gl_tex_slot, sampler); + _SG_GL_CHECK_ERROR(); + _sg_stats_inc(gl.num_bind_sampler); + + slot->target = target; + slot->texture = texture; + slot->sampler = sampler; + } +} + +_SOKOL_PRIVATE void _sg_gl_cache_store_texture_sampler_binding(int8_t gl_tex_slot) { + SOKOL_ASSERT((gl_tex_slot >= 0) && (gl_tex_slot < _SG_GL_MAX_TEX_SMP_BINDINGS)); + _sg.gl.cache.stored_texture_sampler = _sg.gl.cache.texture_samplers[gl_tex_slot]; +} + +_SOKOL_PRIVATE void _sg_gl_cache_restore_texture_sampler_binding(int8_t gl_tex_slot) { + SOKOL_ASSERT((gl_tex_slot >= 0) && (gl_tex_slot < _SG_GL_MAX_TEX_SMP_BINDINGS)); + _sg_gl_cache_texture_sampler_bind_slot* slot = &_sg.gl.cache.stored_texture_sampler; + if (slot->texture != 0) { + // we only care about restoring valid ids + SOKOL_ASSERT(slot->target != 0); + _sg_gl_cache_bind_texture_sampler(gl_tex_slot, slot->target, slot->texture, slot->sampler); + slot->target = 0; + slot->texture = 0; + slot->sampler = 0; + } +} + +// called from _sg_gl_discard_texture() and _sg_gl_discard_sampler() +_SOKOL_PRIVATE void _sg_gl_cache_invalidate_texture_sampler(GLuint tex, GLuint smp) { + _SG_GL_CHECK_ERROR(); + for (size_t i = 0; i < _SG_GL_MAX_TEX_SMP_BINDINGS; i++) { + _sg_gl_cache_texture_sampler_bind_slot* slot = &_sg.gl.cache.texture_samplers[i]; + if ((0 != slot->target) && ((tex == slot->texture) || (smp == slot->sampler))) { + _sg_gl_cache_active_texture((GLenum)(GL_TEXTURE0 + i)); + glBindTexture(slot->target, 0); + _SG_GL_CHECK_ERROR(); + _sg_stats_inc(gl.num_bind_texture); + glBindSampler((GLuint)i, 0); + _SG_GL_CHECK_ERROR(); + _sg_stats_inc(gl.num_bind_sampler); + slot->target = 0; + slot->texture = 0; + slot->sampler = 0; + } + } + if ((tex == _sg.gl.cache.stored_texture_sampler.texture) || (smp == _sg.gl.cache.stored_texture_sampler.sampler)) { + _sg.gl.cache.stored_texture_sampler.target = 0; + _sg.gl.cache.stored_texture_sampler.texture = 0; + _sg.gl.cache.stored_texture_sampler.sampler = 0; + } +} + +// called from _sg_gl_discard_shader() +_SOKOL_PRIVATE void _sg_gl_cache_invalidate_program(GLuint prog) { + if (prog == _sg.gl.cache.prog) { + _sg.gl.cache.prog = 0; + glUseProgram(0); + _sg_stats_inc(gl.num_use_program); + } +} + +// called from _sg_gl_discard_pipeline() +_SOKOL_PRIVATE void _sg_gl_cache_invalidate_pipeline(_sg_pipeline_t* pip) { + if (_sg_sref_slot_eql(&_sg.gl.cache.cur_pip, &pip->slot)) { + _sg.gl.cache.cur_pip = _sg_sref(0); + } +} + +_SOKOL_PRIVATE void _sg_gl_reset_state_cache(void) { + _SG_GL_CHECK_ERROR(); + glBindVertexArray(_sg.gl.vao); + _SG_GL_CHECK_ERROR(); + _sg_clear(&_sg.gl.cache, sizeof(_sg.gl.cache)); + _sg_gl_cache_clear_buffer_bindings(true); + _SG_GL_CHECK_ERROR(); + _sg_gl_cache_clear_texture_sampler_bindings(true); + _SG_GL_CHECK_ERROR(); + for (int i = 0; i < _sg.limits.max_vertex_attrs; i++) { + _sg_gl_attr_t* attr = &_sg.gl.cache.attrs[i].gl_attr; + attr->vb_index = -1; + attr->divisor = -1; + glDisableVertexAttribArray((GLuint)i); + _SG_GL_CHECK_ERROR(); + _sg_stats_inc(gl.num_disable_vertex_attrib_array); + } + _sg.gl.cache.cur_primitive_type = GL_TRIANGLES; + + // shader program + glGetIntegerv(GL_CURRENT_PROGRAM, (GLint*)&_sg.gl.cache.prog); + _SG_GL_CHECK_ERROR(); + + // depth and stencil state + _sg.gl.cache.depth.compare = SG_COMPAREFUNC_ALWAYS; + _sg.gl.cache.stencil.front.compare = SG_COMPAREFUNC_ALWAYS; + _sg.gl.cache.stencil.front.fail_op = SG_STENCILOP_KEEP; + _sg.gl.cache.stencil.front.depth_fail_op = SG_STENCILOP_KEEP; + _sg.gl.cache.stencil.front.pass_op = SG_STENCILOP_KEEP; + _sg.gl.cache.stencil.back.compare = SG_COMPAREFUNC_ALWAYS; + _sg.gl.cache.stencil.back.fail_op = SG_STENCILOP_KEEP; + _sg.gl.cache.stencil.back.depth_fail_op = SG_STENCILOP_KEEP; + _sg.gl.cache.stencil.back.pass_op = SG_STENCILOP_KEEP; + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_ALWAYS); + glDepthMask(GL_FALSE); + glDisable(GL_STENCIL_TEST); + glStencilFunc(GL_ALWAYS, 0, 0); + glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); + glStencilMask(0); + _sg_stats_add(gl.num_render_state, 7); + + // blend state + _sg.gl.cache.blend.src_factor_rgb = SG_BLENDFACTOR_ONE; + _sg.gl.cache.blend.dst_factor_rgb = SG_BLENDFACTOR_ZERO; + _sg.gl.cache.blend.op_rgb = SG_BLENDOP_ADD; + _sg.gl.cache.blend.src_factor_alpha = SG_BLENDFACTOR_ONE; + _sg.gl.cache.blend.dst_factor_alpha = SG_BLENDFACTOR_ZERO; + _sg.gl.cache.blend.op_alpha = SG_BLENDOP_ADD; + glDisable(GL_BLEND); + glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ONE, GL_ZERO); + glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD); + glBlendColor(0.0f, 0.0f, 0.0f, 0.0f); + _sg_stats_add(gl.num_render_state, 4); + + // standalone state + for (int i = 0; i < SG_MAX_COLOR_ATTACHMENTS; i++) { + _sg.gl.cache.color_write_mask[i] = SG_COLORMASK_RGBA; + } + _sg.gl.cache.cull_mode = SG_CULLMODE_NONE; + _sg.gl.cache.face_winding = SG_FACEWINDING_CW; + _sg.gl.cache.sample_count = 1; + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + glPolygonOffset(0.0f, 0.0f); + glDisable(GL_POLYGON_OFFSET_FILL); + glDisable(GL_CULL_FACE); + glFrontFace(GL_CW); + glCullFace(GL_BACK); + glEnable(GL_SCISSOR_TEST); + glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); + glEnable(GL_DITHER); + glDisable(GL_POLYGON_OFFSET_FILL); + _sg_stats_add(gl.num_render_state, 10); + #if defined(SOKOL_GLCORE) + glEnable(GL_MULTISAMPLE); + glEnable(GL_PROGRAM_POINT_SIZE); + _sg_stats_add(gl.num_render_state, 2); + #endif +} + +_SOKOL_PRIVATE void _sg_gl_setup_backend(const sg_desc* desc) { + _SOKOL_UNUSED(desc); + + // assumes that _sg.gl is already zero-initialized + _sg.gl.valid = true; + + #if defined(_SOKOL_USE_WIN32_GL_LOADER) + _sg_gl_load_opengl(); + #endif + + // clear initial GL error state + #if defined(SOKOL_DEBUG) + while (glGetError() != GL_NO_ERROR); + #endif + #if defined(SOKOL_GLCORE) + _sg_gl_init_caps_glcore(); + #elif defined(SOKOL_GLES3) + _sg_gl_init_caps_gles3(); + #endif + + // create and bind global vertex array object which will be mutated as needed + glGenVertexArrays(1, &_sg.gl.vao); + glBindVertexArray(_sg.gl.vao); + _SG_GL_CHECK_ERROR(); + + // create global framebuffer object which will be mutated as needed + glGenFramebuffers(1, &_sg.gl.fb); + _SG_GL_CHECK_ERROR(); + + // incoming texture data is generally expected to be packed tightly + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + #if defined(SOKOL_GLCORE) + // enable seamless cubemap sampling (only desktop GL) + glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); + #endif + _sg_gl_reset_state_cache(); +} + +_SOKOL_PRIVATE void _sg_gl_discard_backend(void) { + SOKOL_ASSERT(_sg.gl.valid); + if (_sg.gl.fb) { + glDeleteFramebuffers(1, &_sg.gl.fb); + } + if (_sg.gl.vao) { + glDeleteVertexArrays(1, &_sg.gl.vao); + } + #if defined(_SOKOL_USE_WIN32_GL_LOADER) + _sg_gl_unload_opengl(); + #endif + _sg.gl.valid = false; +} + +//-- GL backend resource creation and destruction ------------------------------ +_SOKOL_PRIVATE sg_resource_state _sg_gl_create_buffer(_sg_buffer_t* buf, const sg_buffer_desc* desc) { + SOKOL_ASSERT(buf && desc); + _SG_GL_CHECK_ERROR(); + buf->gl.injected = (0 != desc->gl_buffers[0]); + const GLenum gl_target = _sg_gl_buffer_target(&buf->cmn.usage); + const GLenum gl_usage = _sg_gl_buffer_usage(&buf->cmn.usage); + for (int slot = 0; slot < buf->cmn.num_slots; slot++) { + GLuint gl_buf = 0; + if (buf->gl.injected) { + SOKOL_ASSERT(desc->gl_buffers[slot]); + gl_buf = desc->gl_buffers[slot]; + } else { + glGenBuffers(1, &gl_buf); + SOKOL_ASSERT(gl_buf); + _sg_gl_cache_store_buffer_binding(gl_target); + _sg_gl_cache_bind_buffer(gl_target, gl_buf); + glBufferData(gl_target, buf->cmn.size, 0, gl_usage); + if (desc->data.ptr) { + glBufferSubData(gl_target, 0, buf->cmn.size, desc->data.ptr); + } + _sg_gl_cache_restore_buffer_binding(gl_target); + } + buf->gl.buf[slot] = gl_buf; + } + _SG_GL_CHECK_ERROR(); + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_gl_discard_buffer(_sg_buffer_t* buf) { + SOKOL_ASSERT(buf); + _SG_GL_CHECK_ERROR(); + for (int slot = 0; slot < buf->cmn.num_slots; slot++) { + if (buf->gl.buf[slot]) { + _sg_gl_cache_invalidate_buffer(buf->gl.buf[slot]); + if (!buf->gl.injected) { + glDeleteBuffers(1, &buf->gl.buf[slot]); + } + } + } + _SG_GL_CHECK_ERROR(); +} + +_SOKOL_PRIVATE bool _sg_gl_supported_texture_format(sg_pixel_format fmt) { + const int fmt_index = (int) fmt; + SOKOL_ASSERT((fmt_index > SG_PIXELFORMAT_NONE) && (fmt_index < _SG_PIXELFORMAT_NUM)); + return _sg.formats[fmt_index].sample; +} + +_SOKOL_PRIVATE void _sg_gl_texstorage(const _sg_image_t* img) { + const GLenum tgt = img->gl.target; + const int num_mips = img->cmn.num_mipmaps; + #if defined(_SOKOL_GL_HAS_TEXSTORAGE) + const GLenum ifmt = _sg_gl_teximage_internal_format(img->cmn.pixel_format); + const bool msaa = img->cmn.sample_count > 1; + const int w = img->cmn.width; + const int h = img->cmn.height; + if ((SG_IMAGETYPE_2D == img->cmn.type) || (SG_IMAGETYPE_CUBE == img->cmn.type)) { + #if defined(SOKOL_GLCORE) + if (msaa) { + glTexStorage2DMultisample(tgt, img->cmn.sample_count, ifmt, w, h, GL_TRUE); + } else { + glTexStorage2D(tgt, num_mips, ifmt, w, h); + } + #else + SOKOL_ASSERT(!msaa); _SOKOL_UNUSED(msaa); + glTexStorage2D(tgt, num_mips, ifmt, w, h); + #endif + } else if ((SG_IMAGETYPE_3D == img->cmn.type) || (SG_IMAGETYPE_ARRAY == img->cmn.type)) { + const int depth = img->cmn.num_slices; + #if defined(SOKOL_GLCORE) + if (msaa) { + // NOTE: MSAA works only for array textures, not 3D textures + glTexStorage3DMultisample(tgt, img->cmn.sample_count, ifmt, w, h, depth, GL_TRUE); + } else { + glTexStorage3D(tgt, num_mips, ifmt, w, h, depth); + } + #else + SOKOL_ASSERT(!msaa); _SOKOL_UNUSED(msaa); + glTexStorage3D(tgt, num_mips, ifmt, w, h, depth); + #endif + } + #else + glTexParameteri(tgt, GL_TEXTURE_MAX_LEVEL, num_mips - 1); + #endif + _SG_GL_CHECK_ERROR(); +} + +_SOKOL_PRIVATE void _sg_gl_texsubimage(const _sg_image_t* img, GLenum tgt, int mip_index, int w, int h, int depth, const GLvoid* data_ptr, GLsizei data_size) { + SOKOL_ASSERT(data_ptr && (data_size > 0)); + SOKOL_ASSERT(img->cmn.sample_count == 1); + const bool compressed = _sg_is_compressed_pixel_format(img->cmn.pixel_format); + if ((SG_IMAGETYPE_2D == img->cmn.type) || (SG_IMAGETYPE_CUBE == img->cmn.type)) { + if (compressed) { + const GLenum ifmt = _sg_gl_teximage_internal_format(img->cmn.pixel_format); + glCompressedTexSubImage2D(tgt, mip_index, 0, 0, w, h, ifmt, data_size, data_ptr); + } else { + const GLenum type = _sg_gl_teximage_type(img->cmn.pixel_format); + const GLenum fmt = _sg_gl_teximage_format(img->cmn.pixel_format); + glTexSubImage2D(tgt, mip_index, 0, 0, w, h, fmt, type, data_ptr); + } + } else if ((SG_IMAGETYPE_3D == img->cmn.type) || (SG_IMAGETYPE_ARRAY == img->cmn.type)) { + if (compressed) { + const GLenum ifmt = _sg_gl_teximage_internal_format(img->cmn.pixel_format); + glCompressedTexSubImage3D(tgt, mip_index, 0, 0, 0, w, h, depth, ifmt, data_size, data_ptr); + } else { + const GLenum type = _sg_gl_teximage_type(img->cmn.pixel_format); + const GLenum fmt = _sg_gl_teximage_format(img->cmn.pixel_format); + glTexSubImage3D(tgt, mip_index, 0, 0, 0, w, h, depth, fmt, type, data_ptr); + } + } +} + +_SOKOL_PRIVATE void _sg_gl_teximage(const _sg_image_t* img, GLenum tgt, int mip_index, int w, int h, int depth, const GLvoid* data_ptr, GLsizei data_size) { + #if defined(_SOKOL_GL_HAS_TEXSTORAGE) + if (data_ptr == 0) { + return; + } + _sg_gl_texsubimage(img, tgt, mip_index, w, h, depth, data_ptr, data_size); + #else + const bool compressed = _sg_is_compressed_pixel_format(img->cmn.pixel_format); + const GLenum ifmt = _sg_gl_teximage_internal_format(img->cmn.pixel_format); + const bool msaa = img->cmn.sample_count > 1; + if ((SG_IMAGETYPE_2D == img->cmn.type) || (SG_IMAGETYPE_CUBE == img->cmn.type)) { + if (compressed) { + SOKOL_ASSERT(!msaa); _SOKOL_UNUSED(msaa); + glCompressedTexImage2D(tgt, mip_index, ifmt, w, h, 0, data_size, data_ptr); + } else { + const GLenum type = _sg_gl_teximage_type(img->cmn.pixel_format); + const GLenum fmt = _sg_gl_teximage_format(img->cmn.pixel_format); + #if defined(SOKOL_GLCORE) && !defined(__APPLE__) + if (msaa) { + glTexImage2DMultisample(tgt, img->cmn.sample_count, ifmt, w, h, GL_TRUE); + } else { + glTexImage2D(tgt, mip_index, (GLint)ifmt, w, h, 0, fmt, type, data_ptr); + } + #else + SOKOL_ASSERT(!msaa); _SOKOL_UNUSED(msaa); + glTexImage2D(tgt, mip_index, (GLint)ifmt, w, h, 0, fmt, type, data_ptr); + #endif + } + } else if ((SG_IMAGETYPE_3D == img->cmn.type) || (SG_IMAGETYPE_ARRAY == img->cmn.type)) { + if (compressed) { + SOKOL_ASSERT(!msaa); _SOKOL_UNUSED(msaa); + glCompressedTexImage3D(tgt, mip_index, ifmt, w, h, depth, 0, data_size, data_ptr); + } else { + const GLenum type = _sg_gl_teximage_type(img->cmn.pixel_format); + const GLenum fmt = _sg_gl_teximage_format(img->cmn.pixel_format); + #if defined(SOKOL_GLCORE) && !defined(__APPLE__) + if (msaa) { + // NOTE: MSAA works only for array textures, not 3D textures + glTexImage3DMultisample(tgt, img->cmn.sample_count, ifmt, w, h, depth, GL_TRUE); + } else { + glTexImage3D(tgt, mip_index, (GLint)ifmt, w, h, depth, 0, fmt, type, data_ptr); + } + #else + SOKOL_ASSERT(!msaa); _SOKOL_UNUSED(msaa); + glTexImage3D(tgt, mip_index, (GLint)ifmt, w, h, depth, 0, fmt, type, data_ptr); + #endif + } + } + #endif + _SG_GL_CHECK_ERROR(); +} + +_SOKOL_PRIVATE sg_resource_state _sg_gl_create_image(_sg_image_t* img, const sg_image_desc* desc) { + SOKOL_ASSERT(img && desc); + _SG_GL_CHECK_ERROR(); + img->gl.injected = (0 != desc->gl_textures[0]); + + // check if texture format is support + if (!_sg_gl_supported_texture_format(img->cmn.pixel_format)) { + _SG_ERROR(GL_TEXTURE_FORMAT_NOT_SUPPORTED); + return SG_RESOURCESTATE_FAILED; + } + + if (img->gl.injected) { + img->gl.target = _sg_gl_texture_target(img->cmn.type, img->cmn.sample_count); + // inject externally GL textures + for (int slot = 0; slot < img->cmn.num_slots; slot++) { + SOKOL_ASSERT(desc->gl_textures[slot]); + img->gl.tex[slot] = desc->gl_textures[slot]; + } + if (desc->gl_texture_target) { + img->gl.target = (GLenum)desc->gl_texture_target; + } + } else { + // on platforms that don't support MSAA texture bindings, no actual GL + // texture object is created, instead only attachment view object can be built + const bool msaa = img->cmn.sample_count > 1; + if (msaa && !_sg.features.msaa_texture_bindings) { + if (img->cmn.usage.color_attachment || img->cmn.usage.depth_stencil_attachment) { + return SG_RESOURCESTATE_VALID; + } else { + return SG_RESOURCESTATE_FAILED; + } + } + img->gl.target = _sg_gl_texture_target(img->cmn.type, img->cmn.sample_count); + for (int slot = 0; slot < img->cmn.num_slots; slot++) { + glGenTextures(1, &img->gl.tex[slot]); + SOKOL_ASSERT(img->gl.tex[slot]); + _sg_gl_cache_store_texture_sampler_binding(0); + _sg_gl_cache_bind_texture_sampler(0, img->gl.target, img->gl.tex[slot], 0); + _sg_gl_texstorage(img); + for (int mip_index = 0; mip_index < img->cmn.num_mipmaps; mip_index++) { + const GLvoid* data_ptr = desc->data.mip_levels[mip_index].ptr; + const GLsizei data_size = (GLsizei)desc->data.mip_levels[mip_index].size; + const int mip_width = _sg_miplevel_dim(img->cmn.width, mip_index); + const int mip_height = _sg_miplevel_dim(img->cmn.height, mip_index); + const int mip_depth = (SG_IMAGETYPE_3D == img->cmn.type) ? _sg_miplevel_dim(img->cmn.num_slices, mip_index) : img->cmn.num_slices; + if (SG_IMAGETYPE_CUBE == img->cmn.type) { + const int surf_pitch = _sg_surface_pitch(img->cmn.pixel_format, mip_width, mip_height, 1); + // NOTE: surf_ptr is allowed to be null here + const uint8_t* surf_ptr = (const uint8_t*) data_ptr; + for (int i = 0; i < 6; i++) { + const GLenum gl_img_target = _sg_gl_cubeface_target(i); + _sg_gl_teximage(img, gl_img_target, mip_index, mip_width, mip_height, mip_depth, surf_ptr, surf_pitch); + if (data_ptr) { + SOKOL_ASSERT((6 * surf_pitch) <= data_size); + surf_ptr += surf_pitch; + } + } + } else { + _sg_gl_teximage(img, img->gl.target, mip_index, mip_width, mip_height, mip_depth, data_ptr, data_size); + } + } + _sg_gl_cache_restore_texture_sampler_binding(0); + } + } + _SG_GL_CHECK_ERROR(); + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_gl_discard_image(_sg_image_t* img) { + SOKOL_ASSERT(img); + _SG_GL_CHECK_ERROR(); + for (int slot = 0; slot < img->cmn.num_slots; slot++) { + if (img->gl.tex[slot]) { + _sg_gl_cache_invalidate_texture_sampler(img->gl.tex[slot], 0); + if (!img->gl.injected) { + glDeleteTextures(1, &img->gl.tex[slot]); + } + } + } + _SG_GL_CHECK_ERROR(); +} + +_SOKOL_PRIVATE sg_resource_state _sg_gl_create_sampler(_sg_sampler_t* smp, const sg_sampler_desc* desc) { + SOKOL_ASSERT(smp && desc); + _SG_GL_CHECK_ERROR(); + smp->gl.injected = (0 != desc->gl_sampler); + if (smp->gl.injected) { + smp->gl.smp = (GLuint) desc->gl_sampler; + } else { + glGenSamplers(1, &smp->gl.smp); + SOKOL_ASSERT(smp->gl.smp); + + const GLenum gl_min_filter = _sg_gl_min_filter(smp->cmn.min_filter, smp->cmn.mipmap_filter); + const GLenum gl_mag_filter = _sg_gl_mag_filter(smp->cmn.mag_filter); + glSamplerParameteri(smp->gl.smp, GL_TEXTURE_MIN_FILTER, (GLint)gl_min_filter); + glSamplerParameteri(smp->gl.smp, GL_TEXTURE_MAG_FILTER, (GLint)gl_mag_filter); + // GL spec has strange defaults for mipmap min/max lod: -1000 to +1000 + const float min_lod = _sg_clamp(desc->min_lod, 0.0f, 1000.0f); + const float max_lod = _sg_clamp(desc->max_lod, 0.0f, 1000.0f); + glSamplerParameterf(smp->gl.smp, GL_TEXTURE_MIN_LOD, min_lod); + glSamplerParameterf(smp->gl.smp, GL_TEXTURE_MAX_LOD, max_lod); + glSamplerParameteri(smp->gl.smp, GL_TEXTURE_WRAP_S, (GLint)_sg_gl_wrap(smp->cmn.wrap_u)); + glSamplerParameteri(smp->gl.smp, GL_TEXTURE_WRAP_T, (GLint)_sg_gl_wrap(smp->cmn.wrap_v)); + glSamplerParameteri(smp->gl.smp, GL_TEXTURE_WRAP_R, (GLint)_sg_gl_wrap(smp->cmn.wrap_w)); + #if defined(SOKOL_GLCORE) + float border[4]; + switch (smp->cmn.border_color) { + case SG_BORDERCOLOR_TRANSPARENT_BLACK: + border[0] = 0.0f; border[1] = 0.0f; border[2] = 0.0f; border[3] = 0.0f; + break; + case SG_BORDERCOLOR_OPAQUE_WHITE: + border[0] = 1.0f; border[1] = 1.0f; border[2] = 1.0f; border[3] = 1.0f; + break; + default: + border[0] = 0.0f; border[1] = 0.0f; border[2] = 0.0f; border[3] = 1.0f; + break; + } + glSamplerParameterfv(smp->gl.smp, GL_TEXTURE_BORDER_COLOR, border); + #endif + if (smp->cmn.compare != SG_COMPAREFUNC_NEVER) { + glSamplerParameteri(smp->gl.smp, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); + glSamplerParameteri(smp->gl.smp, GL_TEXTURE_COMPARE_FUNC, (GLint)_sg_gl_compare_func(smp->cmn.compare)); + } else { + glSamplerParameteri(smp->gl.smp, GL_TEXTURE_COMPARE_MODE, GL_NONE); + } + if (_sg.gl.ext_anisotropic && (smp->cmn.max_anisotropy > 1)) { + GLint max_aniso = (GLint) smp->cmn.max_anisotropy; + if (max_aniso > _sg.gl.max_anisotropy) { + max_aniso = _sg.gl.max_anisotropy; + } + glSamplerParameteri(smp->gl.smp, GL_TEXTURE_MAX_ANISOTROPY_EXT, max_aniso); + } + } + _SG_GL_CHECK_ERROR(); + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_gl_discard_sampler(_sg_sampler_t* smp) { + SOKOL_ASSERT(smp); + _SG_GL_CHECK_ERROR(); + _sg_gl_cache_invalidate_texture_sampler(0, smp->gl.smp); + if (!smp->gl.injected) { + glDeleteSamplers(1, &smp->gl.smp); + } + _SG_GL_CHECK_ERROR(); +} + +_SOKOL_PRIVATE GLuint _sg_gl_compile_shader(sg_shader_stage stage, const char* src) { + SOKOL_ASSERT(src); + _SG_GL_CHECK_ERROR(); + GLuint gl_shd = glCreateShader(_sg_gl_shader_stage(stage)); + glShaderSource(gl_shd, 1, &src, 0); + glCompileShader(gl_shd); + GLint compile_status = 0; + glGetShaderiv(gl_shd, GL_COMPILE_STATUS, &compile_status); + if (!compile_status) { + // compilation failed, log error and delete shader + GLint log_len = 0; + glGetShaderiv(gl_shd, GL_INFO_LOG_LENGTH, &log_len); + if (log_len > 0) { + GLchar* log_buf = (GLchar*) _sg_malloc((size_t)log_len); + glGetShaderInfoLog(gl_shd, log_len, &log_len, log_buf); + _SG_ERROR(GL_SHADER_COMPILATION_FAILED); + _SG_LOGMSG(GL_SHADER_COMPILATION_FAILED, log_buf); + _sg_free(log_buf); + } + glDeleteShader(gl_shd); + gl_shd = 0; + } + _SG_GL_CHECK_ERROR(); + return gl_shd; +} + +// NOTE: this is an out-of-range check for GLSL bindslots that's also active in release mode +_SOKOL_PRIVATE bool _sg_gl_ensure_glsl_bindslot_ranges(const sg_shader_desc* desc) { + SOKOL_ASSERT(desc); _SOKOL_UNUSED(desc); + #if defined(_SOKOL_GL_HAS_COMPUTE) + SOKOL_ASSERT(_sg.limits.max_storage_buffer_bindings_per_stage <= _SG_GL_MAX_SBUF_BINDINGS); + SOKOL_ASSERT(_sg.limits.max_storage_image_bindings_per_stage <= _SG_GL_MAX_SIMG_BINDINGS); + for (size_t i = 0; i < SG_MAX_VIEW_BINDSLOTS; i++) { + const sg_shader_view* view = &desc->views[i]; + if (view->storage_buffer.stage != SG_SHADERSTAGE_NONE) { + if (view->storage_buffer.glsl_binding_n >= _sg.limits.max_storage_buffer_bindings_per_stage) { + _SG_ERROR(GL_STORAGEBUFFER_GLSL_BINDING_OUT_OF_RANGE); + return false; + } + } + if (view->storage_image.stage != SG_SHADERSTAGE_NONE) { + if (view->storage_image.glsl_binding_n >= _sg.limits.max_storage_image_bindings_per_stage) { + _SG_ERROR(GL_STORAGEIMAGE_GLSL_BINDING_OUT_OF_RANGE); + return false; + } + } + } + #endif + return true; +} + +_SOKOL_PRIVATE sg_resource_state _sg_gl_create_shader(_sg_shader_t* shd, const sg_shader_desc* desc) { + SOKOL_ASSERT(shd && desc); + SOKOL_ASSERT(!shd->gl.prog); + _SG_GL_CHECK_ERROR(); + + // perform a fatal range-check on GLSL bindslots that's also active + // in release mode to avoid potential out-of-bounds array accesses + if (!_sg_gl_ensure_glsl_bindslot_ranges(desc)) { + return SG_RESOURCESTATE_FAILED; + } + + // copy the optional vertex attribute names over + for (int i = 0; i < SG_MAX_VERTEX_ATTRIBUTES; i++) { + _sg_strcpy(&shd->gl.attrs[i].name, desc->attrs[i].glsl_name); + } + + const bool has_vs = desc->vertex_func.source; + const bool has_fs = desc->fragment_func.source; + const bool has_cs = desc->compute_func.source; + SOKOL_ASSERT((has_vs && has_fs) || has_cs); + GLuint gl_prog = glCreateProgram(); + if (has_vs && has_fs) { + GLuint gl_vs = _sg_gl_compile_shader(SG_SHADERSTAGE_VERTEX, desc->vertex_func.source); + GLuint gl_fs = _sg_gl_compile_shader(SG_SHADERSTAGE_FRAGMENT, desc->fragment_func.source); + if (!(gl_vs && gl_fs)) { + glDeleteProgram(gl_prog); + if (gl_vs) { glDeleteShader(gl_vs); } + if (gl_fs) { glDeleteShader(gl_fs); } + return SG_RESOURCESTATE_FAILED; + } + glAttachShader(gl_prog, gl_vs); + glAttachShader(gl_prog, gl_fs); + glLinkProgram(gl_prog); + glDeleteShader(gl_vs); + glDeleteShader(gl_fs); + _SG_GL_CHECK_ERROR(); + } else if (has_cs) { + GLuint gl_cs = _sg_gl_compile_shader(SG_SHADERSTAGE_COMPUTE, desc->compute_func.source); + if (!gl_cs) { + glDeleteProgram(gl_prog); + return SG_RESOURCESTATE_FAILED; + } + glAttachShader(gl_prog, gl_cs); + glLinkProgram(gl_prog); + glDeleteShader(gl_cs); + _SG_GL_CHECK_ERROR(); + } else { + SOKOL_UNREACHABLE; + } + GLint link_status; + glGetProgramiv(gl_prog, GL_LINK_STATUS, &link_status); + if (!link_status) { + GLint log_len = 0; + glGetProgramiv(gl_prog, GL_INFO_LOG_LENGTH, &log_len); + if (log_len > 0) { + GLchar* log_buf = (GLchar*) _sg_malloc((size_t)log_len); + glGetProgramInfoLog(gl_prog, log_len, &log_len, log_buf); + _SG_ERROR(GL_SHADER_LINKING_FAILED); + _SG_LOGMSG(GL_SHADER_LINKING_FAILED, log_buf); + _sg_free(log_buf); + } + glDeleteProgram(gl_prog); + return SG_RESOURCESTATE_FAILED; + } + shd->gl.prog = gl_prog; + + // resolve uniforms + _SG_GL_CHECK_ERROR(); + for (size_t ub_index = 0; ub_index < SG_MAX_UNIFORMBLOCK_BINDSLOTS; ub_index++) { + const sg_shader_uniform_block* ub_desc = &desc->uniform_blocks[ub_index]; + if (ub_desc->stage == SG_SHADERSTAGE_NONE) { + continue; + } + SOKOL_ASSERT(ub_desc->size > 0); + _sg_gl_uniform_block_t* ub = &shd->gl.uniform_blocks[ub_index]; + SOKOL_ASSERT(ub->num_uniforms == 0); + uint32_t cur_uniform_offset = 0; + for (int u_index = 0; u_index < SG_MAX_UNIFORMBLOCK_MEMBERS; u_index++) { + const sg_glsl_shader_uniform* u_desc = &ub_desc->glsl_uniforms[u_index]; + if (u_desc->type == SG_UNIFORMTYPE_INVALID) { + break; + } + const uint32_t u_align = _sg_uniform_alignment(u_desc->type, u_desc->array_count, ub_desc->layout); + const uint32_t u_size = _sg_uniform_size(u_desc->type, u_desc->array_count, ub_desc->layout); + cur_uniform_offset = _sg_align_u32(cur_uniform_offset, u_align); + _sg_gl_uniform_t* u = &ub->uniforms[u_index]; + u->type = u_desc->type; + u->count = (uint16_t) u_desc->array_count; + u->offset = (uint16_t) cur_uniform_offset; + SOKOL_ASSERT(u_desc->glsl_name); + u->gl_loc = glGetUniformLocation(gl_prog, u_desc->glsl_name); + if (u->gl_loc == -1) { + _SG_WARN(GL_UNIFORMBLOCK_NAME_NOT_FOUND_IN_SHADER); + _SG_LOGMSG(GL_UNIFORMBLOCK_NAME_NOT_FOUND_IN_SHADER, u_desc->glsl_name); + } + cur_uniform_offset += u_size; + ub->num_uniforms++; + } + if (ub_desc->layout == SG_UNIFORMLAYOUT_STD140) { + cur_uniform_offset = _sg_align_u32(cur_uniform_offset, 16); + } + SOKOL_ASSERT(ub_desc->size == (size_t)cur_uniform_offset); + _SOKOL_UNUSED(cur_uniform_offset); + } + + // copy resource bindslot mappings + for (size_t i = 0; i < SG_MAX_VIEW_BINDSLOTS; i++) { + const sg_shader_view* view = &desc->views[i]; + SOKOL_ASSERT(0 == shd->gl.sbuf_binding[i]); + SOKOL_ASSERT(0 == shd->gl.simg_binding[i]); + if (view->storage_buffer.stage != SG_SHADERSTAGE_NONE) { + shd->gl.sbuf_binding[i] = view->storage_buffer.glsl_binding_n; + } else if (view->storage_image.stage != SG_SHADERSTAGE_NONE) { + shd->gl.simg_binding[i] = view->storage_image.glsl_binding_n; + } + } + + // record image sampler location in shader program + _SG_GL_CHECK_ERROR(); + GLuint cur_prog = 0; + glGetIntegerv(GL_CURRENT_PROGRAM, (GLint*)&cur_prog); + glUseProgram(gl_prog); + GLint gl_tex_slot = 0; + for (size_t tex_smp_index = 0; tex_smp_index < SG_MAX_TEXTURE_SAMPLER_PAIRS; tex_smp_index++) { + const sg_shader_texture_sampler_pair* tex_smp_desc = &desc->texture_sampler_pairs[tex_smp_index]; + if (tex_smp_desc->stage == SG_SHADERSTAGE_NONE) { + continue; + } + SOKOL_ASSERT(tex_smp_desc->glsl_name); + GLint gl_loc = glGetUniformLocation(gl_prog, tex_smp_desc->glsl_name); + if (gl_loc != -1) { + glUniform1i(gl_loc, gl_tex_slot); + shd->gl.tex_slot[tex_smp_index] = (int8_t)gl_tex_slot++; + } else { + shd->gl.tex_slot[tex_smp_index] = -1; + _SG_WARN(GL_IMAGE_SAMPLER_NAME_NOT_FOUND_IN_SHADER); + _SG_LOGMSG(GL_IMAGE_SAMPLER_NAME_NOT_FOUND_IN_SHADER, tex_smp_desc->glsl_name); + } + } + + // it's legal to call glUseProgram with 0 + glUseProgram(cur_prog); + _SG_GL_CHECK_ERROR(); + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_gl_discard_shader(_sg_shader_t* shd) { + SOKOL_ASSERT(shd); + _SG_GL_CHECK_ERROR(); + if (shd->gl.prog) { + _sg_gl_cache_invalidate_program(shd->gl.prog); + glDeleteProgram(shd->gl.prog); + } + _SG_GL_CHECK_ERROR(); +} + +_SOKOL_PRIVATE sg_resource_state _sg_gl_create_pipeline(_sg_pipeline_t* pip, const sg_pipeline_desc* desc) { + SOKOL_ASSERT(pip && desc); + SOKOL_ASSERT(_sg.limits.max_vertex_attrs <= SG_MAX_VERTEX_ATTRIBUTES); + if (pip->cmn.is_compute) { + // shortcut for compute pipelines + return SG_RESOURCESTATE_VALID; + } + pip->gl.primitive_type = desc->primitive_type; + pip->gl.depth = desc->depth; + pip->gl.stencil = desc->stencil; + // FIXME: blend color and write mask per draw-buffer-attachment (requires GL4) + pip->gl.blend = desc->colors[0].blend; + for (int i = 0; i < SG_MAX_COLOR_ATTACHMENTS; i++) { + pip->gl.color_write_mask[i] = desc->colors[i].write_mask; + } + pip->gl.cull_mode = desc->cull_mode; + pip->gl.face_winding = desc->face_winding; + pip->gl.sample_count = desc->sample_count; + pip->gl.alpha_to_coverage_enabled = desc->alpha_to_coverage_enabled; + + // NOTE: GLSL compilers may remove unused vertex attributes so we can't rely + // on the 'prepopulated' vertex_buffer_layout_active[] state and need to + // fill this array from scratch with the actual info after GLSL compilation + for (int i = 0; i < SG_MAX_VERTEXBUFFER_BINDSLOTS; i++) { + pip->cmn.vertex_buffer_layout_active[i] = false; + } + + // resolve vertex attributes + const _sg_shader_t* shd = _sg_shader_ref_ptr(&pip->cmn.shader); + SOKOL_ASSERT(shd->gl.prog); + for (int attr_index = 0; attr_index < SG_MAX_VERTEX_ATTRIBUTES; attr_index++) { + pip->gl.attrs[attr_index].vb_index = -1; + } + for (int attr_index = 0; attr_index < _sg.limits.max_vertex_attrs; attr_index++) { + const sg_vertex_attr_state* a_state = &desc->layout.attrs[attr_index]; + if (a_state->format == SG_VERTEXFORMAT_INVALID) { + break; + } + SOKOL_ASSERT(a_state->buffer_index < SG_MAX_VERTEXBUFFER_BINDSLOTS); + const sg_vertex_buffer_layout_state* l_state = &desc->layout.buffers[a_state->buffer_index]; + const sg_vertex_step step_func = l_state->step_func; + const int step_rate = l_state->step_rate; + GLint attr_loc = attr_index; + if (!_sg_strempty(&shd->gl.attrs[attr_index].name)) { + attr_loc = glGetAttribLocation(shd->gl.prog, _sg_strptr(&shd->gl.attrs[attr_index].name)); + } + if (attr_loc != -1) { + SOKOL_ASSERT(attr_loc < (GLint)_sg.limits.max_vertex_attrs); + _sg_gl_attr_t* gl_attr = &pip->gl.attrs[attr_loc]; + SOKOL_ASSERT(gl_attr->vb_index == -1); + gl_attr->vb_index = (int8_t) a_state->buffer_index; + if (step_func == SG_VERTEXSTEP_PER_VERTEX) { + gl_attr->divisor = 0; + } else { + gl_attr->divisor = (int8_t) step_rate; + } + SOKOL_ASSERT(l_state->stride > 0); + gl_attr->stride = (uint8_t) l_state->stride; + gl_attr->offset = a_state->offset; + gl_attr->size = (uint8_t) _sg_gl_vertexformat_size(a_state->format); + gl_attr->type = _sg_gl_vertexformat_type(a_state->format); + gl_attr->normalized = _sg_gl_vertexformat_normalized(a_state->format); + gl_attr->base_type = _sg_vertexformat_basetype(a_state->format); + pip->cmn.vertex_buffer_layout_active[a_state->buffer_index] = true; + } else { + _SG_WARN(GL_VERTEX_ATTRIBUTE_NOT_FOUND_IN_SHADER); + _SG_LOGMSG(GL_VERTEX_ATTRIBUTE_NOT_FOUND_IN_SHADER, _sg_strptr(&shd->gl.attrs[attr_index].name)); + } + } + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_gl_discard_pipeline(_sg_pipeline_t* pip) { + SOKOL_ASSERT(pip); + _sg_gl_cache_invalidate_pipeline(pip); +} + +_SOKOL_PRIVATE void _sg_gl_fb_attach_texture(const _sg_view_t* view, GLenum gl_att_type) { + const _sg_image_t* img = _sg_image_ref_ptr(&view->cmn.img.ref); + const GLuint gl_tex = img->gl.tex[0]; + SOKOL_ASSERT(gl_tex); + const GLuint gl_target = img->gl.target; + SOKOL_ASSERT(gl_target); + const int mip_level = view->cmn.img.mip_level; + const int slice = view->cmn.img.slice; + switch (img->cmn.type) { + case SG_IMAGETYPE_2D: + glFramebufferTexture2D(GL_FRAMEBUFFER, gl_att_type, gl_target, gl_tex, mip_level); + break; + case SG_IMAGETYPE_CUBE: + glFramebufferTexture2D(GL_FRAMEBUFFER, gl_att_type, _sg_gl_cubeface_target(slice), gl_tex, mip_level); + break; + default: + glFramebufferTextureLayer(GL_FRAMEBUFFER, gl_att_type, gl_tex, mip_level, slice); + break; + } +} + +_SOKOL_PRIVATE GLenum _sg_gl_depth_stencil_attachment_type(const _sg_image_t* ds_img) { + if (_sg_is_depth_stencil_format(ds_img->cmn.pixel_format)) { + return GL_DEPTH_STENCIL_ATTACHMENT; + } else { + return GL_DEPTH_ATTACHMENT; + } +} + +_SOKOL_PRIVATE bool _sg_gl_check_framebuffer_status(void) { + const GLenum fb_status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + if (fb_status != GL_FRAMEBUFFER_COMPLETE) { + switch (fb_status) { + case GL_FRAMEBUFFER_UNDEFINED: + _SG_ERROR(GL_FRAMEBUFFER_STATUS_UNDEFINED); + break; + case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: + _SG_ERROR(GL_FRAMEBUFFER_STATUS_INCOMPLETE_ATTACHMENT); + break; + case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: + _SG_ERROR(GL_FRAMEBUFFER_STATUS_INCOMPLETE_MISSING_ATTACHMENT); + break; + case GL_FRAMEBUFFER_UNSUPPORTED: + _SG_ERROR(GL_FRAMEBUFFER_STATUS_UNSUPPORTED); + break; + case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: + _SG_ERROR(GL_FRAMEBUFFER_STATUS_INCOMPLETE_MULTISAMPLE); + break; + default: + _SG_ERROR(GL_FRAMEBUFFER_STATUS_UNKNOWN); + break; + } + return false; + } + return true; +} + +_SOKOL_PRIVATE sg_resource_state _sg_gl_create_view(_sg_view_t* view, const sg_view_desc* desc) { + SOKOL_ASSERT(view && desc); + _SOKOL_UNUSED(desc); + _SG_GL_CHECK_ERROR(); + if ((view->cmn.type == SG_VIEWTYPE_TEXTURE) && (_sg.features.gl_texture_views)) { + #if defined(_SOKOL_GL_HAS_TEXVIEWS) + if (_sg.features.gl_texture_views) { + const _sg_image_t* img = _sg_image_ref_ptr(&view->cmn.img.ref); + for (int slot = 0; slot < img->cmn.num_slots; slot++) { + SOKOL_ASSERT(img->gl.tex[slot] != 0); + const GLuint min_level = (GLuint)view->cmn.img.mip_level; + const GLuint num_levels = (GLuint)view->cmn.img.mip_level_count; + const GLuint min_layer = (GLuint)view->cmn.img.slice; + const GLuint num_layers = (GLuint)view->cmn.img.slice_count; + const GLenum ifmt = _sg_gl_teximage_internal_format(img->cmn.pixel_format); + glGenTextures(1, &view->gl.tex_view[slot]); + glTextureView(view->gl.tex_view[slot], img->gl.target, img->gl.tex[slot], ifmt, min_level, num_levels, min_layer, num_layers); + } + } + #endif + } else if ((view->cmn.type == SG_VIEWTYPE_COLORATTACHMENT) || (view->cmn.type == SG_VIEWTYPE_DEPTHSTENCILATTACHMENT)) { + // create MSAA render buffer if MSAA textures are not supported + const _sg_image_t* img = _sg_image_ref_ptr(&view->cmn.img.ref); + const bool msaa = img->cmn.sample_count > 1; + if (msaa && !_sg.features.msaa_texture_bindings) { + const GLenum gl_internal_format = _sg_gl_teximage_internal_format(img->cmn.pixel_format); + glGenRenderbuffers(1, &view->gl.msaa_render_buffer); + glBindRenderbuffer(GL_RENDERBUFFER, view->gl.msaa_render_buffer); + glRenderbufferStorageMultisample(GL_RENDERBUFFER, img->cmn.sample_count, gl_internal_format, img->cmn.width, img->cmn.height); + } + } else if (view->cmn.type == SG_VIEWTYPE_RESOLVEATTACHMENT) { + // store current framebuffer binding (restored at end of block) + GLuint gl_orig_fb; + glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint*)&gl_orig_fb); + + // create MSAA resolve framebuffer + glGenFramebuffers(1, &view->gl.msaa_resolve_frame_buffer); + glBindFramebuffer(GL_FRAMEBUFFER, view->gl.msaa_resolve_frame_buffer); + _sg_gl_fb_attach_texture(view, GL_COLOR_ATTACHMENT0); + if (!_sg_gl_check_framebuffer_status()) { + return SG_RESOURCESTATE_FAILED; + } + // setup color attachments for the framebuffer + static const GLenum gl_draw_buf = GL_COLOR_ATTACHMENT0; + glDrawBuffers(1, &gl_draw_buf); + // bind original framebuffer + glBindFramebuffer(GL_FRAMEBUFFER, gl_orig_fb); + } + _SG_GL_CHECK_ERROR(); + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_gl_discard_view(_sg_view_t* view) { + SOKOL_ASSERT(view); + _SG_GL_CHECK_ERROR(); + for (size_t slot = 0; slot < SG_NUM_INFLIGHT_FRAMES; slot++) { + if (0 != view->gl.tex_view[slot]) { + // NOTE: cache invalidation also works as expected without + // GL texture view support, in that case the view's texture object + // will simply remain bound until the sg_image object is discarded + _sg_gl_cache_invalidate_texture_sampler(view->gl.tex_view[slot], 0); + glDeleteTextures(1, &view->gl.tex_view[slot]); + } + } + if (view->gl.msaa_render_buffer) { + glDeleteRenderbuffers(1, &view->gl.msaa_render_buffer); + } + if (view->gl.msaa_resolve_frame_buffer) { + glDeleteFramebuffers(1, &view->gl.msaa_resolve_frame_buffer); + } + _SG_GL_CHECK_ERROR(); +} + +#if defined(_SOKOL_GL_HAS_COMPUTE) +_SOKOL_PRIVATE void _sg_gl_handle_memory_barriers(const _sg_shader_t* shd, const _sg_bindings_ptrs_t* bnd, const _sg_attachments_ptrs_t* atts) { + SOKOL_ASSERT((shd && bnd && atts == 0) || (atts && shd == 0 && bnd == 0)); + if (!_sg.features.compute) { + return; + } + GLbitfield gl_barrier_bits = 0; + + // if vertex-, index- or storage-buffer bindings have been written + // by a compute shader before, a barrier must be issued + if (bnd) { + for (size_t i = 0; i < SG_MAX_VERTEXBUFFER_BINDSLOTS; i++) { + _sg_buffer_t* buf = bnd->vbs[i]; + if (!buf) { + continue; + } + if (buf->gl.gpu_dirty_flags & _SG_GL_GPUDIRTY_VERTEXBUFFER) { + gl_barrier_bits |= GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT; + buf->gl.gpu_dirty_flags &= (uint8_t)~_SG_GL_GPUDIRTY_VERTEXBUFFER; + } + } + if (bnd->ib) { + _sg_buffer_t* buf = bnd->ib; + if (buf->gl.gpu_dirty_flags & _SG_GL_GPUDIRTY_INDEXBUFFER) { + gl_barrier_bits |= GL_ELEMENT_ARRAY_BARRIER_BIT; + buf->gl.gpu_dirty_flags &= (uint8_t)~_SG_GL_GPUDIRTY_INDEXBUFFER; + } + } + for (size_t i = 0; i < SG_MAX_VIEW_BINDSLOTS; i++) { + const _sg_view_t* view = bnd->views[i]; + if (!view) { + continue; + } + if (view->cmn.type == SG_VIEWTYPE_STORAGEBUFFER) { + _sg_buffer_t* buf = _sg_buffer_ref_ptr(&view->cmn.buf.ref); + if (buf->gl.gpu_dirty_flags & _SG_GL_GPUDIRTY_STORAGEBUFFER) { + gl_barrier_bits |= GL_SHADER_STORAGE_BARRIER_BIT; + buf->gl.gpu_dirty_flags &= (uint8_t)~_SG_GL_GPUDIRTY_STORAGEBUFFER; + } + } else if (view->cmn.type == SG_VIEWTYPE_TEXTURE) { + _sg_image_t* img = _sg_image_ref_ptr(&view->cmn.img.ref); + if (img->gl.gpu_dirty_flags & _SG_GL_GPUDIRTY_TEXTURE) { + gl_barrier_bits |= GL_TEXTURE_FETCH_BARRIER_BIT; + img->gl.gpu_dirty_flags &= (uint8_t)~_SG_GL_GPUDIRTY_TEXTURE; + } + } else if (view->cmn.type == SG_VIEWTYPE_STORAGEIMAGE) { + _sg_image_t* img = _sg_image_ref_ptr(&view->cmn.img.ref); + if (img->gl.gpu_dirty_flags &= _SG_GL_GPUDIRTY_STORAGEIMAGE) { + gl_barrier_bits |= GL_SHADER_IMAGE_ACCESS_BARRIER_BIT; + img->gl.gpu_dirty_flags &= (uint8_t)~_SG_GL_GPUDIRTY_STORAGEIMAGE; + } + } else { + SOKOL_UNREACHABLE; + } + } + } + if (atts) { + for (int i = 0; i < atts->num_color_views; i++) { + const _sg_view_t* view = atts->color_views[i]; + SOKOL_ASSERT(view); + _sg_image_t* img = _sg_image_ref_ptr(&view->cmn.img.ref); + if (img->gl.gpu_dirty_flags & _SG_GL_GPUDIRTY_ATTACHMENT) { + gl_barrier_bits |= GL_FRAMEBUFFER_BARRIER_BIT; + img->gl.gpu_dirty_flags &= (uint8_t)~_SG_GL_GPUDIRTY_ATTACHMENT; + } + } + } + if (0 != gl_barrier_bits) { + glMemoryBarrier(gl_barrier_bits); + _sg_stats_inc(gl.num_memory_barriers); + } + + // mark resources as dirty which will be written by compute shaders + // (don't merge this into the above loop, this would mess up the + // dirty flags if the same resource is bound multiple times) + if (bnd) { + for (size_t i = 0; i < SG_MAX_VIEW_BINDSLOTS; i++) { + const _sg_view_t* view = bnd->views[i]; + if (!view) { + continue; + } + if (view->cmn.type == SG_VIEWTYPE_STORAGEBUFFER) { + if (!shd->cmn.views[i].sbuf_readonly) { + _sg_buffer_t* buf = _sg_buffer_ref_ptr(&view->cmn.buf.ref); + buf->gl.gpu_dirty_flags = _SG_GL_GPUDIRTY_BUFFER_ALL; + } + } else if (view->cmn.type == SG_VIEWTYPE_STORAGEIMAGE) { + // NOTE: storage image bindings are always written, otherwise + // they would be texture bindings! + _sg_image_t* img = _sg_image_ref_ptr(&view->cmn.img.ref); + img->gl.gpu_dirty_flags = _SG_GL_GPUDIRTY_IMAGE_ALL; + } + } + } +} +#endif + +_SOKOL_PRIVATE void _sg_gl_begin_pass(const sg_pass* pass, const _sg_attachments_ptrs_t* atts) { + SOKOL_ASSERT(pass && atts); + _SG_GL_CHECK_ERROR(); + + // early out if this a compute pass + if (pass->compute) { + return; + } + + const sg_swapchain* swapchain = &pass->swapchain; + const sg_pass_action* action = &pass->action; + const bool is_swapchain_pass = atts->empty; + const bool is_offscreen_pass = !atts->empty; + + // bind the render pass framebuffer + // + // FIXME: Disabling SRGB conversion for the default framebuffer is + // a crude hack to make behaviour for sRGB render target textures + // identical with the Metal and D3D11 swapchains created by sokol-app. + // + // This will need a cleaner solution (e.g. allowing to configure + // sokol_app.h with an sRGB or RGB framebuffer. + if (is_offscreen_pass) { + + // offscreen pass, mutate the global offscreen framebuffer object + #if defined(SOKOL_GLCORE) + glEnable(GL_FRAMEBUFFER_SRGB); + #endif + glBindFramebuffer(GL_FRAMEBUFFER, _sg.gl.fb); + for (int i = 0; i < atts->num_color_views; i++) { + const _sg_view_t* view = atts->color_views[i]; + const GLenum gl_att_type = (GLenum)(GL_COLOR_ATTACHMENT0 + i); + if (view->gl.msaa_render_buffer) { + glFramebufferRenderbuffer(GL_FRAMEBUFFER, gl_att_type, GL_RENDERBUFFER, view->gl.msaa_render_buffer); + } else { + _sg_gl_fb_attach_texture(view, gl_att_type); + } + } + // explicitly detach unused color attachments + for (int i = atts->num_color_views; i < _sg.limits.max_color_attachments; i++) { + const GLenum gl_att_type = (GLenum)(GL_COLOR_ATTACHMENT0 + i); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, gl_att_type, GL_RENDERBUFFER, 0); + glFramebufferTexture2D(GL_FRAMEBUFFER, gl_att_type, GL_TEXTURE_2D, 0, 0); + } + if (atts->ds_view) { + // When switching between depth-only and depth-stencil attachments, + // explicitly detach BOTH attachment types first. Some GL drivers + // fail with GL_FRAMEBUFFER_UNSUPPORTED if both attachment types + // are bound to the same FBO. + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, 0); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, 0); + const _sg_view_t* view = atts->ds_view; + const _sg_image_t* img = _sg_image_ref_ptr(&view->cmn.img.ref); + const GLenum gl_att_type = _sg_gl_depth_stencil_attachment_type(img); + if (view->gl.msaa_render_buffer) { + glFramebufferRenderbuffer(GL_FRAMEBUFFER, gl_att_type, GL_RENDERBUFFER, view->gl.msaa_render_buffer); + } else { + _sg_gl_fb_attach_texture(view, gl_att_type); + } + } else { + // explicitly detach depth-stencil attachment if not used in this pass + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, 0); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, 0); + } + if (!_sg_gl_check_framebuffer_status()) { + _sg.cur_pass.valid = false; + return; + } + GLenum gl_draw_bufs[SG_MAX_COLOR_ATTACHMENTS]; + SOKOL_ASSERT(_sg.limits.max_color_attachments <= SG_MAX_COLOR_ATTACHMENTS); + for (int i = 0; i < _sg.limits.max_color_attachments; i++) { + if (i < atts->num_color_views) { + gl_draw_bufs[i] = (GLenum)(GL_COLOR_ATTACHMENT0 + i); + } else { + gl_draw_bufs[i] = GL_NONE; + } + } + glDrawBuffers(_sg.limits.max_color_attachments, gl_draw_bufs); + + #if defined(_SOKOL_GL_HAS_COMPUTE) + _sg_gl_handle_memory_barriers(0, 0, atts); + _SG_GL_CHECK_ERROR(); + #endif + + } else { + // swapchain pass + #if defined(SOKOL_GLCORE) + glDisable(GL_FRAMEBUFFER_SRGB); + #endif + // NOTE: on some platforms, the default framebuffer of a context + // is null, so we can't actually assert here that the + // framebuffer has been provided + glBindFramebuffer(GL_FRAMEBUFFER, swapchain->gl.framebuffer); + } + glViewport(0, 0, _sg.cur_pass.dim.width, _sg.cur_pass.dim.height); + glScissor(0, 0, _sg.cur_pass.dim.width, _sg.cur_pass.dim.height); + + // number of color attachments + const int num_color_atts = is_offscreen_pass ? atts->num_color_views : 1; + + // clear color and depth-stencil attachments if needed + bool clear_any_color = false; + for (int i = 0; i < num_color_atts; i++) { + if (SG_LOADACTION_CLEAR == action->colors[i].load_action) { + clear_any_color = true; + break; + } + } + const bool clear_depth = (action->depth.load_action == SG_LOADACTION_CLEAR); + const bool clear_stencil = (action->stencil.load_action == SG_LOADACTION_CLEAR); + + bool need_pip_cache_flush = false; + if (clear_any_color) { + bool need_color_mask_flush = false; + // NOTE: not a bug to iterate over all possible color attachments + for (int i = 0; i < SG_MAX_COLOR_ATTACHMENTS; i++) { + if (SG_COLORMASK_RGBA != _sg.gl.cache.color_write_mask[i]) { + need_pip_cache_flush = true; + need_color_mask_flush = true; + _sg.gl.cache.color_write_mask[i] = SG_COLORMASK_RGBA; + } + } + if (need_color_mask_flush) { + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + } + } + if (clear_depth) { + if (!_sg.gl.cache.depth.write_enabled) { + need_pip_cache_flush = true; + _sg.gl.cache.depth.write_enabled = true; + glDepthMask(GL_TRUE); + } + if (_sg.gl.cache.depth.compare != SG_COMPAREFUNC_ALWAYS) { + need_pip_cache_flush = true; + _sg.gl.cache.depth.compare = SG_COMPAREFUNC_ALWAYS; + glDepthFunc(GL_ALWAYS); + } + } + if (clear_stencil) { + if (_sg.gl.cache.stencil.write_mask != 0xFF) { + need_pip_cache_flush = true; + _sg.gl.cache.stencil.write_mask = 0xFF; + glStencilMask(0xFF); + } + } + if (need_pip_cache_flush) { + // we messed with the state cache directly, need to clear cached + // pipeline to force re-evaluation in next sg_apply_pipeline() + _sg.gl.cache.cur_pip = _sg_sref(0); + } + for (int i = 0; i < num_color_atts; i++) { + if (action->colors[i].load_action == SG_LOADACTION_CLEAR) { + glClearBufferfv(GL_COLOR, i, &action->colors[i].clear_value.r); + } + } + if (is_swapchain_pass || atts->ds_view) { + if (clear_depth && clear_stencil) { + glClearBufferfi(GL_DEPTH_STENCIL, 0, action->depth.clear_value, action->stencil.clear_value); + } else if (clear_depth) { + glClearBufferfv(GL_DEPTH, 0, &action->depth.clear_value); + } else if (clear_stencil) { + GLint val = (GLint) action->stencil.clear_value; + glClearBufferiv(GL_STENCIL, 0, &val); + } + } + // keep store actions for end-pass + for (int i = 0; i < SG_MAX_COLOR_ATTACHMENTS; i++) { + _sg.gl.color_store_actions[i] = action->colors[i].store_action; + } + _sg.gl.depth_store_action = action->depth.store_action; + _sg.gl.stencil_store_action = action->stencil.store_action; + + _SG_GL_CHECK_ERROR(); +} + +_SOKOL_PRIVATE void _sg_gl_end_render_pass(const _sg_attachments_ptrs_t* atts) { + SOKOL_ASSERT(atts); + if (!atts->empty) { + bool fb_read_bound = false; + bool fb_draw_bound = false; + const int num_color_atts = atts->num_color_views; + for (int i = 0; i < num_color_atts; i++) { + // perform MSAA resolve if needed + const _sg_view_t* rsv_view = atts->resolve_views[i]; + if (rsv_view && rsv_view->gl.msaa_resolve_frame_buffer) { + if (!fb_read_bound) { + glBindFramebuffer(GL_READ_FRAMEBUFFER, _sg.gl.fb); + fb_read_bound = true; + } + const _sg_image_t* rsv_img = _sg_image_ref_ptr(&rsv_view->cmn.img.ref); + const int w = rsv_img->cmn.width; + const int h = rsv_img->cmn.height; + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, rsv_view->gl.msaa_resolve_frame_buffer); + glReadBuffer((GLenum)(GL_COLOR_ATTACHMENT0 + i)); + glBlitFramebuffer(0, 0, w, h, 0, 0, w, h, GL_COLOR_BUFFER_BIT, GL_NEAREST); + fb_draw_bound = true; + } + } + + // invalidate framebuffers + _SOKOL_UNUSED(fb_draw_bound); + #if defined(SOKOL_GLES3) + // need to restore framebuffer binding before invalidate if the MSAA resolve had changed the binding + if (fb_draw_bound) { + glBindFramebuffer(GL_FRAMEBUFFER, _sg.gl.fb); + } + GLenum invalidate_atts[SG_MAX_COLOR_ATTACHMENTS + 2] = { 0 }; + int att_index = 0; + for (int i = 0; i < num_color_atts; i++) { + if (_sg.gl.color_store_actions[i] == SG_STOREACTION_DONTCARE) { + invalidate_atts[att_index++] = (GLenum)(GL_COLOR_ATTACHMENT0 + i); + } + } + if (!atts->ds_view) { + if (_sg.gl.depth_store_action == SG_STOREACTION_DONTCARE) { + invalidate_atts[att_index++] = GL_DEPTH_ATTACHMENT; + } + if (_sg.gl.stencil_store_action == SG_STOREACTION_DONTCARE) { + invalidate_atts[att_index++] = GL_STENCIL_ATTACHMENT; + } + } + if (att_index > 0) { + glInvalidateFramebuffer(GL_DRAW_FRAMEBUFFER, att_index, invalidate_atts); + } + #endif + } +} + +_SOKOL_PRIVATE void _sg_gl_end_pass(const _sg_attachments_ptrs_t* atts) { + _SG_GL_CHECK_ERROR(); + if (!_sg.cur_pass.is_compute) { + _sg_gl_end_render_pass(atts); + } + _SG_GL_CHECK_ERROR(); +} + +_SOKOL_PRIVATE void _sg_gl_apply_viewport(int x, int y, int w, int h, bool origin_top_left) { + y = origin_top_left ? (_sg.cur_pass.dim.height - (y+h)) : y; + glViewport(x, y, w, h); +} + +_SOKOL_PRIVATE void _sg_gl_apply_scissor_rect(int x, int y, int w, int h, bool origin_top_left) { + y = origin_top_left ? (_sg.cur_pass.dim.height - (y+h)) : y; + glScissor(x, y, w, h); +} + +_SOKOL_PRIVATE void _sg_gl_apply_render_pipeline_state(_sg_pipeline_t* pip) { + // update render pipeline state + _sg.gl.cache.cur_primitive_type = _sg_gl_primitive_type(pip->gl.primitive_type); + _sg.gl.cache.cur_index_type = _sg_gl_index_type(pip->cmn.index_type); + + // update depth state + { + const sg_depth_state* state_ds = &pip->gl.depth; + sg_depth_state* cache_ds = &_sg.gl.cache.depth; + if (state_ds->compare != cache_ds->compare) { + cache_ds->compare = state_ds->compare; + glDepthFunc(_sg_gl_compare_func(state_ds->compare)); + _sg_stats_inc(gl.num_render_state); + } + if (state_ds->write_enabled != cache_ds->write_enabled) { + cache_ds->write_enabled = state_ds->write_enabled; + glDepthMask(state_ds->write_enabled); + _sg_stats_inc(gl.num_render_state); + } + if (!_sg_fequal(state_ds->bias, cache_ds->bias, 0.000001f) || + !_sg_fequal(state_ds->bias_slope_scale, cache_ds->bias_slope_scale, 0.000001f)) + { + /* according to ANGLE's D3D11 backend: + D3D11 SlopeScaledDepthBias ==> GL polygonOffsetFactor + D3D11 DepthBias ==> GL polygonOffsetUnits + DepthBiasClamp has no meaning on GL + */ + cache_ds->bias = state_ds->bias; + cache_ds->bias_slope_scale = state_ds->bias_slope_scale; + glPolygonOffset(state_ds->bias_slope_scale, state_ds->bias); + _sg_stats_inc(gl.num_render_state); + bool po_enabled = true; + if (_sg_fequal(state_ds->bias, 0.0f, 0.000001f) && + _sg_fequal(state_ds->bias_slope_scale, 0.0f, 0.000001f)) + { + po_enabled = false; + } + if (po_enabled != _sg.gl.cache.polygon_offset_enabled) { + _sg.gl.cache.polygon_offset_enabled = po_enabled; + if (po_enabled) { + glEnable(GL_POLYGON_OFFSET_FILL); + } else { + glDisable(GL_POLYGON_OFFSET_FILL); + } + _sg_stats_inc(gl.num_render_state); + } + } + } + + // update stencil state + { + const sg_stencil_state* state_ss = &pip->gl.stencil; + sg_stencil_state* cache_ss = &_sg.gl.cache.stencil; + if (state_ss->enabled != cache_ss->enabled) { + cache_ss->enabled = state_ss->enabled; + if (state_ss->enabled) { + glEnable(GL_STENCIL_TEST); + } else { + glDisable(GL_STENCIL_TEST); + } + _sg_stats_inc(gl.num_render_state); + } + if (state_ss->write_mask != cache_ss->write_mask) { + cache_ss->write_mask = state_ss->write_mask; + glStencilMask(state_ss->write_mask); + _sg_stats_inc(gl.num_render_state); + } + for (int i = 0; i < 2; i++) { + const sg_stencil_face_state* state_sfs = (i==0)? &state_ss->front : &state_ss->back; + sg_stencil_face_state* cache_sfs = (i==0)? &cache_ss->front : &cache_ss->back; + GLenum gl_face = (i==0)? GL_FRONT : GL_BACK; + if ((state_sfs->compare != cache_sfs->compare) || + (state_ss->read_mask != cache_ss->read_mask) || + (state_ss->ref != cache_ss->ref)) + { + cache_sfs->compare = state_sfs->compare; + glStencilFuncSeparate(gl_face, + _sg_gl_compare_func(state_sfs->compare), + state_ss->ref, + state_ss->read_mask); + _sg_stats_inc(gl.num_render_state); + } + if ((state_sfs->fail_op != cache_sfs->fail_op) || + (state_sfs->depth_fail_op != cache_sfs->depth_fail_op) || + (state_sfs->pass_op != cache_sfs->pass_op)) + { + cache_sfs->fail_op = state_sfs->fail_op; + cache_sfs->depth_fail_op = state_sfs->depth_fail_op; + cache_sfs->pass_op = state_sfs->pass_op; + glStencilOpSeparate(gl_face, + _sg_gl_stencil_op(state_sfs->fail_op), + _sg_gl_stencil_op(state_sfs->depth_fail_op), + _sg_gl_stencil_op(state_sfs->pass_op)); + _sg_stats_inc(gl.num_render_state); + } + } + cache_ss->read_mask = state_ss->read_mask; + cache_ss->ref = state_ss->ref; + } + + if (pip->cmn.color_count > 0) { + // update blend state + // FIXME: separate blend state per color attachment + const sg_blend_state* state_bs = &pip->gl.blend; + sg_blend_state* cache_bs = &_sg.gl.cache.blend; + if (state_bs->enabled != cache_bs->enabled) { + cache_bs->enabled = state_bs->enabled; + if (state_bs->enabled) { + glEnable(GL_BLEND); + } else { + glDisable(GL_BLEND); + } + _sg_stats_inc(gl.num_render_state); + } + if ((state_bs->src_factor_rgb != cache_bs->src_factor_rgb) || + (state_bs->dst_factor_rgb != cache_bs->dst_factor_rgb) || + (state_bs->src_factor_alpha != cache_bs->src_factor_alpha) || + (state_bs->dst_factor_alpha != cache_bs->dst_factor_alpha)) + { + cache_bs->src_factor_rgb = state_bs->src_factor_rgb; + cache_bs->dst_factor_rgb = state_bs->dst_factor_rgb; + cache_bs->src_factor_alpha = state_bs->src_factor_alpha; + cache_bs->dst_factor_alpha = state_bs->dst_factor_alpha; + glBlendFuncSeparate(_sg_gl_blend_factor(state_bs->src_factor_rgb), + _sg_gl_blend_factor(state_bs->dst_factor_rgb), + _sg_gl_blend_factor(state_bs->src_factor_alpha), + _sg_gl_blend_factor(state_bs->dst_factor_alpha)); + _sg_stats_inc(gl.num_render_state); + } + if ((state_bs->op_rgb != cache_bs->op_rgb) || (state_bs->op_alpha != cache_bs->op_alpha)) { + cache_bs->op_rgb = state_bs->op_rgb; + cache_bs->op_alpha = state_bs->op_alpha; + glBlendEquationSeparate(_sg_gl_blend_op(state_bs->op_rgb), _sg_gl_blend_op(state_bs->op_alpha)); + _sg_stats_inc(gl.num_render_state); + } + + // standalone color target state + for (GLuint i = 0; i < (GLuint)pip->cmn.color_count; i++) { + if (pip->gl.color_write_mask[i] != _sg.gl.cache.color_write_mask[i]) { + const sg_color_mask cm = pip->gl.color_write_mask[i]; + _sg.gl.cache.color_write_mask[i] = cm; + if (_sg.features.mrt_independent_write_mask) { + #if defined(_SOKOL_GL_HAS_COLORMASKI) + glColorMaski(i, + (cm & SG_COLORMASK_R) != 0, + (cm & SG_COLORMASK_G) != 0, + (cm & SG_COLORMASK_B) != 0, + (cm & SG_COLORMASK_A) != 0); + #else + // can't happen + SOKOL_ASSERT(false); + #endif + } else if (0 == i) { + glColorMask((cm & SG_COLORMASK_R) != 0, + (cm & SG_COLORMASK_G) != 0, + (cm & SG_COLORMASK_B) != 0, + (cm & SG_COLORMASK_A) != 0); + } + _sg_stats_inc(gl.num_render_state); + } + } + + if (!_sg_fequal(pip->cmn.blend_color.r, _sg.gl.cache.blend_color.r, 0.0001f) || + !_sg_fequal(pip->cmn.blend_color.g, _sg.gl.cache.blend_color.g, 0.0001f) || + !_sg_fequal(pip->cmn.blend_color.b, _sg.gl.cache.blend_color.b, 0.0001f) || + !_sg_fequal(pip->cmn.blend_color.a, _sg.gl.cache.blend_color.a, 0.0001f)) + { + sg_color c = pip->cmn.blend_color; + _sg.gl.cache.blend_color = c; + glBlendColor(c.r, c.g, c.b, c.a); + _sg_stats_inc(gl.num_render_state); + } + } // pip->cmn.color_count > 0 + + if (pip->gl.cull_mode != _sg.gl.cache.cull_mode) { + _sg.gl.cache.cull_mode = pip->gl.cull_mode; + if (SG_CULLMODE_NONE == pip->gl.cull_mode) { + glDisable(GL_CULL_FACE); + _sg_stats_inc(gl.num_render_state); + } else { + glEnable(GL_CULL_FACE); + GLenum gl_mode = (SG_CULLMODE_FRONT == pip->gl.cull_mode) ? GL_FRONT : GL_BACK; + glCullFace(gl_mode); + _sg_stats_add(gl.num_render_state, 2); + } + } + if (pip->gl.face_winding != _sg.gl.cache.face_winding) { + _sg.gl.cache.face_winding = pip->gl.face_winding; + GLenum gl_winding = (SG_FACEWINDING_CW == pip->gl.face_winding) ? GL_CW : GL_CCW; + glFrontFace(gl_winding); + _sg_stats_inc(gl.num_render_state); + } + if (pip->gl.alpha_to_coverage_enabled != _sg.gl.cache.alpha_to_coverage_enabled) { + _sg.gl.cache.alpha_to_coverage_enabled = pip->gl.alpha_to_coverage_enabled; + if (pip->gl.alpha_to_coverage_enabled) { + glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE); + } else { + glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); + } + _sg_stats_inc(gl.num_render_state); + } + #ifdef SOKOL_GLCORE + if (pip->gl.sample_count != _sg.gl.cache.sample_count) { + _sg.gl.cache.sample_count = pip->gl.sample_count; + if (pip->gl.sample_count > 1) { + glEnable(GL_MULTISAMPLE); + } else { + glDisable(GL_MULTISAMPLE); + } + _sg_stats_inc(gl.num_render_state); + } + #endif +} + +_SOKOL_PRIVATE void _sg_gl_apply_pipeline(_sg_pipeline_t* pip) { + SOKOL_ASSERT(pip); + _SG_GL_CHECK_ERROR(); + if (!_sg_sref_slot_eql(&_sg.gl.cache.cur_pip, &pip->slot)) { + _sg.gl.cache.cur_pip = _sg_sref(&pip->slot); + + // bind shader program + const _sg_shader_t* shd = _sg_shader_ref_ptr(&pip->cmn.shader); + if (shd->gl.prog != _sg.gl.cache.prog) { + _sg.gl.cache.prog = shd->gl.prog; + glUseProgram(shd->gl.prog); + _sg_stats_inc(gl.num_use_program); + } + + if (!pip->cmn.is_compute) { + _sg_gl_apply_render_pipeline_state(pip); + } + } + _SG_GL_CHECK_ERROR(); +} + +_SOKOL_PRIVATE bool _sg_gl_apply_bindings(_sg_bindings_ptrs_t* bnd) { + SOKOL_ASSERT(bnd); + SOKOL_ASSERT(bnd->pip); + _SG_GL_CHECK_ERROR(); + const _sg_shader_t* shd = _sg_shader_ref_ptr(&bnd->pip->cmn.shader); + + // bind combined texture-samplers + _SG_GL_CHECK_ERROR(); + for (size_t tex_smp_index = 0; tex_smp_index < SG_MAX_TEXTURE_SAMPLER_PAIRS; tex_smp_index++) { + const _sg_shader_texture_sampler_t* tex_smp = &shd->cmn.texture_samplers[tex_smp_index]; + if (tex_smp->stage == SG_SHADERSTAGE_NONE) { + continue; + } + const int8_t gl_tex_slot = (GLint)shd->gl.tex_slot[tex_smp_index]; + if (gl_tex_slot != -1) { + SOKOL_ASSERT(tex_smp->view_slot < SG_MAX_VIEW_BINDSLOTS); + SOKOL_ASSERT(tex_smp->sampler_slot < SG_MAX_SAMPLER_BINDSLOTS); + const _sg_view_t* view = bnd->views[tex_smp->view_slot]; + const _sg_sampler_t* smp = bnd->smps[tex_smp->sampler_slot]; + SOKOL_ASSERT(view); + SOKOL_ASSERT(smp); + const _sg_image_t* img = _sg_image_ref_ptr(&view->cmn.img.ref); + const GLenum gl_tgt = img->gl.target; + const GLuint gl_smp = smp->gl.smp; + GLuint gl_tex; + if (_sg.features.gl_texture_views) { + gl_tex = view->gl.tex_view[img->cmn.active_slot]; + } else { + gl_tex = img->gl.tex[img->cmn.active_slot]; + } + _sg_gl_cache_bind_texture_sampler(gl_tex_slot, gl_tgt, gl_tex, gl_smp); + } + } + _SG_GL_CHECK_ERROR(); + + // bind storage buffer and images + for (size_t i = 0; i < SG_MAX_VIEW_BINDSLOTS; i++) { + if (shd->cmn.views[i].stage == SG_SHADERSTAGE_NONE) { + continue; + } + const _sg_view_t* view = bnd->views[i]; + if (view->cmn.type == SG_VIEWTYPE_STORAGEBUFFER) { + const _sg_buffer_t* sbuf = _sg_buffer_ref_ptr(&view->cmn.buf.ref); + const uint8_t gl_binding = shd->gl.sbuf_binding[i]; + GLuint gl_sbuf = sbuf->gl.buf[sbuf->cmn.active_slot]; + _sg_gl_cache_bind_storage_buffer(gl_binding, gl_sbuf, view->cmn.buf.offset, sbuf->cmn.size); + } else if (view->cmn.type == SG_VIEWTYPE_STORAGEIMAGE) { + #if defined(_SOKOL_GL_HAS_COMPUTE) + const _sg_image_t* img = _sg_image_ref_ptr(&view->cmn.img.ref); + const uint8_t gl_unit = shd->gl.simg_binding[i]; + SOKOL_ASSERT((int)gl_unit < _sg.limits.max_storage_image_bindings_per_stage); + GLuint gl_tex = img->gl.tex[img->cmn.active_slot]; + GLint level = (GLint)view->cmn.img.mip_level; + GLint layer = (GLint)view->cmn.img.slice; + GLboolean layered = shd->cmn.views[i].image_type != SG_IMAGETYPE_2D; + GLenum access = shd->cmn.views[i].simg_writeonly ? GL_WRITE_ONLY : GL_READ_WRITE; + GLenum format = _sg_gl_teximage_internal_format(shd->cmn.views[i].access_format); + // NOTE: we specifically don't go through the GL cache since storage images + // are not supported on WebGL2, and on native platforms call caching isn't + // worth the hassle + glBindImageTexture(gl_unit, gl_tex, level, layered, layer, access, format); + _sg_stats_inc(gl.num_bind_image_texture); + #endif + } + } + _SG_GL_CHECK_ERROR(); + + if (!bnd->pip->cmn.is_compute) { + // index buffer (can be 0) + const GLuint gl_ib = bnd->ib ? bnd->ib->gl.buf[bnd->ib->cmn.active_slot] : 0; + _sg_gl_cache_bind_buffer(GL_ELEMENT_ARRAY_BUFFER, gl_ib); + _sg.gl.cache.cur_ib_offset = bnd->ib_offset; + + // vertex attributes + for (GLuint attr_index = 0; attr_index < (GLuint)_sg.limits.max_vertex_attrs; attr_index++) { + _sg_gl_attr_t* attr = &bnd->pip->gl.attrs[attr_index]; + _sg_gl_cache_attr_t* cache_attr = &_sg.gl.cache.attrs[attr_index]; + bool cache_attr_dirty = false; + int vb_offset = 0; + GLuint gl_vb = 0; + if (attr->vb_index >= 0) { + // attribute is enabled + SOKOL_ASSERT(attr->vb_index < SG_MAX_VERTEXBUFFER_BINDSLOTS); + _sg_buffer_t* vb = bnd->vbs[attr->vb_index]; + SOKOL_ASSERT(vb); + gl_vb = vb->gl.buf[vb->cmn.active_slot]; + vb_offset = bnd->vb_offsets[attr->vb_index] + attr->offset; + if ((gl_vb != cache_attr->gl_vbuf) || + (attr->size != cache_attr->gl_attr.size) || + (attr->type != cache_attr->gl_attr.type) || + (attr->normalized != cache_attr->gl_attr.normalized) || + (attr->base_type != cache_attr->gl_attr.base_type) || + (attr->stride != cache_attr->gl_attr.stride) || + (vb_offset != cache_attr->gl_attr.offset) || + (cache_attr->gl_attr.divisor != attr->divisor)) + { + _sg_gl_cache_bind_buffer(GL_ARRAY_BUFFER, gl_vb); + if (attr->base_type == SG_SHADERATTRBASETYPE_FLOAT) { + glVertexAttribPointer(attr_index, attr->size, attr->type, attr->normalized, attr->stride, (const GLvoid*)(GLintptr)vb_offset); + } else { + glVertexAttribIPointer(attr_index, attr->size, attr->type, attr->stride, (const GLvoid*)(GLintptr)vb_offset); + } + _sg_stats_inc(gl.num_vertex_attrib_pointer); + glVertexAttribDivisor(attr_index, (GLuint)attr->divisor); + _sg_stats_inc(gl.num_vertex_attrib_divisor); + cache_attr_dirty = true; + } + if (cache_attr->gl_attr.vb_index == -1) { + glEnableVertexAttribArray(attr_index); + _sg_stats_inc(gl.num_enable_vertex_attrib_array); + cache_attr_dirty = true; + } + } else { + // attribute is disabled + if (cache_attr->gl_attr.vb_index != -1) { + glDisableVertexAttribArray(attr_index); + _sg_stats_inc(gl.num_disable_vertex_attrib_array); + cache_attr_dirty = true; + } + } + if (cache_attr_dirty) { + cache_attr->gl_attr = *attr; + cache_attr->gl_attr.offset = vb_offset; + cache_attr->gl_vbuf = gl_vb; + } + } + _SG_GL_CHECK_ERROR(); + } + + // take care of storage resource memory barriers (this needs to happen after the bindings are set) + #if defined(_SOKOL_GL_HAS_COMPUTE) + _sg_gl_handle_memory_barriers(shd, bnd, 0); + _SG_GL_CHECK_ERROR(); + #endif + + return true; +} + +_SOKOL_PRIVATE void _sg_gl_apply_uniforms(int ub_slot, const sg_range* data) { + SOKOL_ASSERT((ub_slot >= 0) && (ub_slot < SG_MAX_UNIFORMBLOCK_BINDSLOTS)); + const _sg_pipeline_t* pip = _sg_pipeline_ref_ptr(&_sg.cur_pip); + const _sg_shader_t* shd = _sg_shader_ref_ptr(&pip->cmn.shader); + SOKOL_ASSERT(SG_SHADERSTAGE_NONE != shd->cmn.uniform_blocks[ub_slot].stage); + SOKOL_ASSERT(data->size == shd->cmn.uniform_blocks[ub_slot].size); + const _sg_gl_uniform_block_t* gl_ub = &shd->gl.uniform_blocks[ub_slot]; + for (int u_index = 0; u_index < gl_ub->num_uniforms; u_index++) { + const _sg_gl_uniform_t* u = &gl_ub->uniforms[u_index]; + SOKOL_ASSERT(u->type != SG_UNIFORMTYPE_INVALID); + if (u->gl_loc == -1) { + continue; + } + _sg_stats_inc(gl.num_uniform); + GLfloat* fptr = (GLfloat*) (((uint8_t*)data->ptr) + u->offset); + GLint* iptr = (GLint*) (((uint8_t*)data->ptr) + u->offset); + switch (u->type) { + case SG_UNIFORMTYPE_INVALID: + break; + case SG_UNIFORMTYPE_FLOAT: + glUniform1fv(u->gl_loc, u->count, fptr); + break; + case SG_UNIFORMTYPE_FLOAT2: + glUniform2fv(u->gl_loc, u->count, fptr); + break; + case SG_UNIFORMTYPE_FLOAT3: + glUniform3fv(u->gl_loc, u->count, fptr); + break; + case SG_UNIFORMTYPE_FLOAT4: + glUniform4fv(u->gl_loc, u->count, fptr); + break; + case SG_UNIFORMTYPE_INT: + glUniform1iv(u->gl_loc, u->count, iptr); + break; + case SG_UNIFORMTYPE_INT2: + glUniform2iv(u->gl_loc, u->count, iptr); + break; + case SG_UNIFORMTYPE_INT3: + glUniform3iv(u->gl_loc, u->count, iptr); + break; + case SG_UNIFORMTYPE_INT4: + glUniform4iv(u->gl_loc, u->count, iptr); + break; + case SG_UNIFORMTYPE_MAT4: + glUniformMatrix4fv(u->gl_loc, u->count, GL_FALSE, fptr); + break; + default: + SOKOL_UNREACHABLE; + break; + } + } +} + +_SOKOL_PRIVATE void _sg_gl_draw(int base_element, int num_elements, int num_instances, int base_vertex, int base_instance) { + const GLenum p_type = _sg.gl.cache.cur_primitive_type; + const bool use_instanced_draw = (num_instances > 1) || _sg.use_instanced_draw; + if (_sg.use_indexed_draw) { + // indexed rendering + const GLenum i_type = _sg.gl.cache.cur_index_type; + const int i_size = (i_type == GL_UNSIGNED_SHORT) ? 2 : 4; + const int ib_offset = _sg.gl.cache.cur_ib_offset; + const GLvoid* indices = (const GLvoid*)(GLintptr)(base_element*i_size+ib_offset); + if (use_instanced_draw) { + if ((base_vertex == 0) && (base_instance == 0)) { + glDrawElementsInstanced(p_type, num_elements, i_type, indices, num_instances); + } else if ((base_vertex != 0) && (base_instance == 0) && _sg.features.draw_base_vertex) { + #if defined(_SOKOL_GL_HAS_BASEVERTEX) + glDrawElementsInstancedBaseVertex(p_type, num_elements, i_type, indices, num_instances, base_vertex); + #endif + } else if ((base_instance != 0) && _sg.features.draw_base_instance) { + #if defined(_SOKOL_GL_HAS_BASEINSTANCE) + glDrawElementsInstancedBaseVertexBaseInstance(p_type, num_elements, i_type, indices, num_instances, base_vertex, (GLuint)base_instance); + #endif + } + } else { + if (base_vertex == 0) { + glDrawElements(p_type, num_elements, i_type, indices); + } else if (_sg.features.draw_base_vertex) { + #if defined(_SOKOL_GL_HAS_BASEVERTEX) + glDrawElementsBaseVertex(p_type, num_elements, i_type, indices, base_vertex); + #endif + } + } + } else { + // non-indexed rendering + if (use_instanced_draw) { + if (base_instance == 0) { + glDrawArraysInstanced(p_type, base_element, num_elements, num_instances); + } else if (_sg.features.draw_base_instance) { + #if defined(_SOKOL_GL_HAS_BASEINSTANCE) + glDrawArraysInstancedBaseInstance(p_type, base_element, num_elements, num_instances, (GLuint)base_instance); + #endif + } + } else { + glDrawArrays(p_type, base_element, num_elements); + } + } +} + +_SOKOL_PRIVATE void _sg_gl_dispatch(int num_groups_x, int num_groups_y, int num_groups_z) { + #if defined(_SOKOL_GL_HAS_COMPUTE) + if (!_sg.features.compute) { + return; + } + glDispatchCompute((GLuint)num_groups_x, (GLuint)num_groups_y, (GLuint)num_groups_z); + #else + (void)num_groups_x; (void)num_groups_y; (void)num_groups_z; + #endif +} + +_SOKOL_PRIVATE void _sg_gl_commit(void) { + // "soft" clear bindings (only those that are actually bound) + _sg_gl_cache_clear_buffer_bindings(false); + _sg_gl_cache_clear_texture_sampler_bindings(false); +} + +_SOKOL_PRIVATE void _sg_gl_update_buffer(_sg_buffer_t* buf, const sg_range* data) { + SOKOL_ASSERT(buf && data && data->ptr && (data->size > 0)); + // only one update per buffer per frame allowed + if (++buf->cmn.active_slot >= buf->cmn.num_slots) { + buf->cmn.active_slot = 0; + } + GLenum gl_tgt = _sg_gl_buffer_target(&buf->cmn.usage); + SOKOL_ASSERT(buf->cmn.active_slot < SG_NUM_INFLIGHT_FRAMES); + GLuint gl_buf = buf->gl.buf[buf->cmn.active_slot]; + SOKOL_ASSERT(gl_buf); + _SG_GL_CHECK_ERROR(); + _sg_gl_cache_store_buffer_binding(gl_tgt); + _sg_gl_cache_bind_buffer(gl_tgt, gl_buf); + glBufferSubData(gl_tgt, 0, (GLsizeiptr)data->size, data->ptr); + _sg_gl_cache_restore_buffer_binding(gl_tgt); + _SG_GL_CHECK_ERROR(); +} + +_SOKOL_PRIVATE void _sg_gl_append_buffer(_sg_buffer_t* buf, const sg_range* data, bool new_frame) { + SOKOL_ASSERT(buf && data && data->ptr && (data->size > 0)); + if (new_frame) { + if (++buf->cmn.active_slot >= buf->cmn.num_slots) { + buf->cmn.active_slot = 0; + } + } + GLenum gl_tgt = _sg_gl_buffer_target(&buf->cmn.usage); + SOKOL_ASSERT(buf->cmn.active_slot < SG_NUM_INFLIGHT_FRAMES); + GLuint gl_buf = buf->gl.buf[buf->cmn.active_slot]; + SOKOL_ASSERT(gl_buf); + _SG_GL_CHECK_ERROR(); + _sg_gl_cache_store_buffer_binding(gl_tgt); + _sg_gl_cache_bind_buffer(gl_tgt, gl_buf); + glBufferSubData(gl_tgt, buf->cmn.append_pos, (GLsizeiptr)data->size, data->ptr); + _sg_gl_cache_restore_buffer_binding(gl_tgt); + _SG_GL_CHECK_ERROR(); +} + +_SOKOL_PRIVATE void _sg_gl_update_image(_sg_image_t* img, const sg_image_data* data) { + SOKOL_ASSERT(img && data); + // only one update per image per frame allowed + if (++img->cmn.active_slot >= img->cmn.num_slots) { + img->cmn.active_slot = 0; + } + SOKOL_ASSERT(img->cmn.active_slot < SG_NUM_INFLIGHT_FRAMES); + SOKOL_ASSERT(0 != img->gl.tex[img->cmn.active_slot]); + _sg_gl_cache_store_texture_sampler_binding(0); + _sg_gl_cache_bind_texture_sampler(0, img->gl.target, img->gl.tex[img->cmn.active_slot], 0); + const int num_mips = img->cmn.num_mipmaps; + for (int mip_index = 0; mip_index < num_mips; mip_index++) { + const GLvoid* data_ptr = data->mip_levels[mip_index].ptr; + const GLsizei data_size = (GLsizei)data->mip_levels[mip_index].size; + const int mip_width = _sg_miplevel_dim(img->cmn.width, mip_index); + const int mip_height = _sg_miplevel_dim(img->cmn.height, mip_index); + const int mip_depth = (SG_IMAGETYPE_3D == img->cmn.type) ? _sg_miplevel_dim(img->cmn.num_slices, mip_index) : img->cmn.num_slices; + if (SG_IMAGETYPE_CUBE == img->cmn.type) { + const int surf_pitch = _sg_surface_pitch(img->cmn.pixel_format, mip_width, mip_height, 1); + SOKOL_ASSERT((6 * surf_pitch) <= data_size); + const uint8_t* surf_ptr = (const uint8_t*) data_ptr; + for (int i = 0; i < 6; i++) { + const GLenum gl_img_target = _sg_gl_cubeface_target(i); + _sg_gl_texsubimage(img, gl_img_target, mip_index, mip_width, mip_height, mip_depth, surf_ptr, surf_pitch); + surf_ptr += surf_pitch; + } + } else { + _sg_gl_texsubimage(img, img->gl.target, mip_index, mip_width, mip_height, mip_depth, data_ptr, data_size); + } + } + _sg_gl_cache_restore_texture_sampler_binding(0); +} + +// ██████ ██████ ██████ ██ ██ ██████ █████ ██████ ██ ██ ███████ ███ ██ ██████ +// ██ ██ ██ ██ ██ ███ ███ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ +// ██ ██ █████ ██ ██ ██ ██ ██████ ███████ ██ █████ █████ ██ ██ ██ ██ ██ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ██████ ██████ ██████ ██ ██ ██████ ██ ██ ██████ ██ ██ ███████ ██ ████ ██████ +// +// >>d3d11 backend +#elif defined(SOKOL_D3D11) + +#if defined(__cplusplus) +#define _sg_d3d11_AddRef(self) (self)->AddRef() +#else +#define _sg_d3d11_AddRef(self) (self)->lpVtbl->AddRef(self) +#endif + +#if defined(__cplusplus) +#define _sg_d3d11_Release(self) (self)->Release() +#else +#define _sg_d3d11_Release(self) (self)->lpVtbl->Release(self) +#endif + +// NOTE: This needs to be a macro since we can't use the polymorphism in C. It's called on many kinds of resources. +// NOTE: Based on microsoft docs, it's fine to call this with pData=NULL if DataSize is also zero. +#if defined(__cplusplus) +#define _sg_d3d11_SetPrivateData(self, guid, DataSize, pData) (self)->SetPrivateData(guid, DataSize, pData) +#else +#define _sg_d3d11_SetPrivateData(self, guid, DataSize, pData) (self)->lpVtbl->SetPrivateData(self, guid, DataSize, pData) +#endif + +#if defined(__cplusplus) +#define _sg_win32_refguid(guid) guid +#else +#define _sg_win32_refguid(guid) &guid +#endif + +static const GUID _sg_d3d11_WKPDID_D3DDebugObjectName = { 0x429b8c22,0x9188,0x4b0c, {0x87,0x42,0xac,0xb0,0xbf,0x85,0xc2,0x00} }; + +#if defined(SOKOL_DEBUG) +#define _sg_d3d11_setlabel(self, label) _sg_d3d11_SetPrivateData(self, _sg_win32_refguid(_sg_d3d11_WKPDID_D3DDebugObjectName), label ? (UINT)strlen(label) : 0, label) +#else +#define _sg_d3d11_setlabel(self, label) +#endif + + +//-- D3D11 C/C++ wrappers ------------------------------------------------------ +static inline HRESULT _sg_d3d11_CheckFormatSupport(ID3D11Device* self, DXGI_FORMAT Format, UINT* pFormatSupport) { + #if defined(__cplusplus) + return self->CheckFormatSupport(Format, pFormatSupport); + #else + return self->lpVtbl->CheckFormatSupport(self, Format, pFormatSupport); + #endif +} + +static inline void _sg_d3d11_OMSetRenderTargets(ID3D11DeviceContext* self, UINT NumViews, ID3D11RenderTargetView* const* ppRenderTargetViews, ID3D11DepthStencilView *pDepthStencilView) { + #if defined(__cplusplus) + self->OMSetRenderTargets(NumViews, ppRenderTargetViews, pDepthStencilView); + #else + self->lpVtbl->OMSetRenderTargets(self, NumViews, ppRenderTargetViews, pDepthStencilView); + #endif +} + +static inline void _sg_d3d11_RSSetState(ID3D11DeviceContext* self, ID3D11RasterizerState* pRasterizerState) { + #if defined(__cplusplus) + self->RSSetState(pRasterizerState); + #else + self->lpVtbl->RSSetState(self, pRasterizerState); + #endif +} + +static inline void _sg_d3d11_OMSetDepthStencilState(ID3D11DeviceContext* self, ID3D11DepthStencilState* pDepthStencilState, UINT StencilRef) { + #if defined(__cplusplus) + self->OMSetDepthStencilState(pDepthStencilState, StencilRef); + #else + self->lpVtbl->OMSetDepthStencilState(self, pDepthStencilState, StencilRef); + #endif +} + +static inline void _sg_d3d11_OMSetBlendState(ID3D11DeviceContext* self, ID3D11BlendState* pBlendState, const FLOAT BlendFactor[4], UINT SampleMask) { + #if defined(__cplusplus) + self->OMSetBlendState(pBlendState, BlendFactor, SampleMask); + #else + self->lpVtbl->OMSetBlendState(self, pBlendState, BlendFactor, SampleMask); + #endif +} + +static inline void _sg_d3d11_IASetVertexBuffers(ID3D11DeviceContext* self, UINT StartSlot, UINT NumBuffers, ID3D11Buffer* const* ppVertexBuffers, const UINT* pStrides, const UINT* pOffsets) { + #if defined(__cplusplus) + self->IASetVertexBuffers(StartSlot, NumBuffers, ppVertexBuffers, pStrides, pOffsets); + #else + self->lpVtbl->IASetVertexBuffers(self, StartSlot, NumBuffers, ppVertexBuffers, pStrides, pOffsets); + #endif +} + +static inline void _sg_d3d11_IASetIndexBuffer(ID3D11DeviceContext* self, ID3D11Buffer* pIndexBuffer, DXGI_FORMAT Format, UINT Offset) { + #if defined(__cplusplus) + self->IASetIndexBuffer(pIndexBuffer, Format, Offset); + #else + self->lpVtbl->IASetIndexBuffer(self, pIndexBuffer, Format, Offset); + #endif +} + +static inline void _sg_d3d11_IASetInputLayout(ID3D11DeviceContext* self, ID3D11InputLayout* pInputLayout) { + #if defined(__cplusplus) + self->IASetInputLayout(pInputLayout); + #else + self->lpVtbl->IASetInputLayout(self, pInputLayout); + #endif +} + +static inline void _sg_d3d11_VSSetShader(ID3D11DeviceContext* self, ID3D11VertexShader* pVertexShader, ID3D11ClassInstance* const* ppClassInstances, UINT NumClassInstances) { + #if defined(__cplusplus) + self->VSSetShader(pVertexShader, ppClassInstances, NumClassInstances); + #else + self->lpVtbl->VSSetShader(self, pVertexShader, ppClassInstances, NumClassInstances); + #endif +} + +static inline void _sg_d3d11_PSSetShader(ID3D11DeviceContext* self, ID3D11PixelShader* pPixelShader, ID3D11ClassInstance* const* ppClassInstances, UINT NumClassInstances) { + #if defined(__cplusplus) + self->PSSetShader(pPixelShader, ppClassInstances, NumClassInstances); + #else + self->lpVtbl->PSSetShader(self, pPixelShader, ppClassInstances, NumClassInstances); + #endif +} + +static inline void _sg_d3d11_CSSetShader(ID3D11DeviceContext* self, ID3D11ComputeShader* pComputeShader, ID3D11ClassInstance* const* ppClassInstances, UINT NumClassInstances) { + #if defined(__cplusplus) + self->CSSetShader(pComputeShader, ppClassInstances, NumClassInstances); + #else + self->lpVtbl->CSSetShader(self, pComputeShader, ppClassInstances, NumClassInstances); + #endif +} + +static inline void _sg_d3d11_VSSetConstantBuffers(ID3D11DeviceContext* self, UINT StartSlot, UINT NumBuffers, ID3D11Buffer* const* ppConstantBuffers) { + #if defined(__cplusplus) + self->VSSetConstantBuffers(StartSlot, NumBuffers, ppConstantBuffers); + #else + self->lpVtbl->VSSetConstantBuffers(self, StartSlot, NumBuffers, ppConstantBuffers); + #endif +} + +static inline void _sg_d3d11_PSSetConstantBuffers(ID3D11DeviceContext* self, UINT StartSlot, UINT NumBuffers, ID3D11Buffer* const* ppConstantBuffers) { + #if defined(__cplusplus) + self->PSSetConstantBuffers(StartSlot, NumBuffers, ppConstantBuffers); + #else + self->lpVtbl->PSSetConstantBuffers(self, StartSlot, NumBuffers, ppConstantBuffers); + #endif +} + +static inline void _sg_d3d11_CSSetConstantBuffers(ID3D11DeviceContext* self, UINT StartSlot, UINT NumBuffers, ID3D11Buffer* const* ppConstantBuffers) { + #if defined(__cplusplus) + self->CSSetConstantBuffers(StartSlot, NumBuffers, ppConstantBuffers); + #else + self->lpVtbl->CSSetConstantBuffers(self, StartSlot, NumBuffers, ppConstantBuffers); + #endif +} + +static inline void _sg_d3d11_VSSetShaderResources(ID3D11DeviceContext* self, UINT StartSlot, UINT NumViews, ID3D11ShaderResourceView* const* ppShaderResourceViews) { + #if defined(__cplusplus) + self->VSSetShaderResources(StartSlot, NumViews, ppShaderResourceViews); + #else + self->lpVtbl->VSSetShaderResources(self, StartSlot, NumViews, ppShaderResourceViews); + #endif +} + +static inline void _sg_d3d11_PSSetShaderResources(ID3D11DeviceContext* self, UINT StartSlot, UINT NumViews, ID3D11ShaderResourceView* const* ppShaderResourceViews) { + #if defined(__cplusplus) + self->PSSetShaderResources(StartSlot, NumViews, ppShaderResourceViews); + #else + self->lpVtbl->PSSetShaderResources(self, StartSlot, NumViews, ppShaderResourceViews); + #endif +} + +static inline void _sg_d3d11_CSSetShaderResources(ID3D11DeviceContext* self, UINT StartSlot, UINT NumViews, ID3D11ShaderResourceView* const* ppShaderResourceViews) { + #if defined(__cplusplus) + self->CSSetShaderResources(StartSlot, NumViews, ppShaderResourceViews); + #else + self->lpVtbl->CSSetShaderResources(self, StartSlot, NumViews, ppShaderResourceViews); + #endif +} + +static inline void _sg_d3d11_VSSetSamplers(ID3D11DeviceContext* self, UINT StartSlot, UINT NumSamplers, ID3D11SamplerState* const* ppSamplers) { + #if defined(__cplusplus) + self->VSSetSamplers(StartSlot, NumSamplers, ppSamplers); + #else + self->lpVtbl->VSSetSamplers(self, StartSlot, NumSamplers, ppSamplers); + #endif +} + +static inline void _sg_d3d11_PSSetSamplers(ID3D11DeviceContext* self, UINT StartSlot, UINT NumSamplers, ID3D11SamplerState* const* ppSamplers) { + #if defined(__cplusplus) + self->PSSetSamplers(StartSlot, NumSamplers, ppSamplers); + #else + self->lpVtbl->PSSetSamplers(self, StartSlot, NumSamplers, ppSamplers); + #endif +} + +static inline void _sg_d3d11_CSSetSamplers(ID3D11DeviceContext* self, UINT StartSlot, UINT NumSamplers, ID3D11SamplerState* const* ppSamplers) { + #if defined(__cplusplus) + self->CSSetSamplers(StartSlot, NumSamplers, ppSamplers); + #else + self->lpVtbl->CSSetSamplers(self, StartSlot, NumSamplers, ppSamplers); + #endif +} + +static inline void _sg_d3d11_CSSetUnorderedAccessViews(ID3D11DeviceContext* self, UINT StartSlot, UINT NumUAVs, ID3D11UnorderedAccessView* const* ppUnorderedAccessViews, const UINT* pUAVInitialCounts) { + #if defined(__cplusplus) + self->CSSetUnorderedAccessViews(StartSlot, NumUAVs, ppUnorderedAccessViews, pUAVInitialCounts); + #else + self->lpVtbl->CSSetUnorderedAccessViews(self, StartSlot, NumUAVs, ppUnorderedAccessViews, pUAVInitialCounts); + #endif +} + +static inline HRESULT _sg_d3d11_CreateBuffer(ID3D11Device* self, const D3D11_BUFFER_DESC* pDesc, const D3D11_SUBRESOURCE_DATA* pInitialData, ID3D11Buffer** ppBuffer) { + #if defined(__cplusplus) + return self->CreateBuffer(pDesc, pInitialData, ppBuffer); + #else + return self->lpVtbl->CreateBuffer(self, pDesc, pInitialData, ppBuffer); + #endif +} + +static inline HRESULT _sg_d3d11_CreateTexture2D(ID3D11Device* self, const D3D11_TEXTURE2D_DESC* pDesc, const D3D11_SUBRESOURCE_DATA* pInitialData, ID3D11Texture2D** ppTexture2D) { + #if defined(__cplusplus) + return self->CreateTexture2D(pDesc, pInitialData, ppTexture2D); + #else + return self->lpVtbl->CreateTexture2D(self, pDesc, pInitialData, ppTexture2D); + #endif +} + +static inline HRESULT _sg_d3d11_CreateShaderResourceView(ID3D11Device* self, ID3D11Resource* pResource, const D3D11_SHADER_RESOURCE_VIEW_DESC* pDesc, ID3D11ShaderResourceView** ppSRView) { + #if defined(__cplusplus) + return self->CreateShaderResourceView(pResource, pDesc, ppSRView); + #else + return self->lpVtbl->CreateShaderResourceView(self, pResource, pDesc, ppSRView); + #endif +} + +static inline HRESULT _sg_d3d11_CreateUnorderedAccessView(ID3D11Device* self, ID3D11Resource* pResource, const D3D11_UNORDERED_ACCESS_VIEW_DESC* pDesc, ID3D11UnorderedAccessView** ppUAVView) { + #if defined(__cplusplus) + return self->CreateUnorderedAccessView(pResource, pDesc, ppUAVView); + #else + return self->lpVtbl->CreateUnorderedAccessView(self, pResource, pDesc, ppUAVView); + #endif +} + +static inline void _sg_d3d11_GetResource(ID3D11View* self, ID3D11Resource** ppResource) { + #if defined(__cplusplus) + self->GetResource(ppResource); + #else + self->lpVtbl->GetResource(self, ppResource); + #endif +} + +static inline HRESULT _sg_d3d11_CreateTexture3D(ID3D11Device* self, const D3D11_TEXTURE3D_DESC* pDesc, const D3D11_SUBRESOURCE_DATA* pInitialData, ID3D11Texture3D** ppTexture3D) { + #if defined(__cplusplus) + return self->CreateTexture3D(pDesc, pInitialData, ppTexture3D); + #else + return self->lpVtbl->CreateTexture3D(self, pDesc, pInitialData, ppTexture3D); + #endif +} + +static inline HRESULT _sg_d3d11_CreateSamplerState(ID3D11Device* self, const D3D11_SAMPLER_DESC* pSamplerDesc, ID3D11SamplerState** ppSamplerState) { + #if defined(__cplusplus) + return self->CreateSamplerState(pSamplerDesc, ppSamplerState); + #else + return self->lpVtbl->CreateSamplerState(self, pSamplerDesc, ppSamplerState); + #endif +} + +static inline LPVOID _sg_d3d11_GetBufferPointer(ID3D10Blob* self) { + #if defined(__cplusplus) + return self->GetBufferPointer(); + #else + return self->lpVtbl->GetBufferPointer(self); + #endif +} + +static inline SIZE_T _sg_d3d11_GetBufferSize(ID3D10Blob* self) { + #if defined(__cplusplus) + return self->GetBufferSize(); + #else + return self->lpVtbl->GetBufferSize(self); + #endif +} + +static inline HRESULT _sg_d3d11_CreateVertexShader(ID3D11Device* self, const void* pShaderBytecode, SIZE_T BytecodeLength, ID3D11ClassLinkage* pClassLinkage, ID3D11VertexShader** ppVertexShader) { + #if defined(__cplusplus) + return self->CreateVertexShader(pShaderBytecode, BytecodeLength, pClassLinkage, ppVertexShader); + #else + return self->lpVtbl->CreateVertexShader(self, pShaderBytecode, BytecodeLength, pClassLinkage, ppVertexShader); + #endif +} + +static inline HRESULT _sg_d3d11_CreatePixelShader(ID3D11Device* self, const void* pShaderBytecode, SIZE_T BytecodeLength, ID3D11ClassLinkage* pClassLinkage, ID3D11PixelShader** ppPixelShader) { + #if defined(__cplusplus) + return self->CreatePixelShader(pShaderBytecode, BytecodeLength, pClassLinkage, ppPixelShader); + #else + return self->lpVtbl->CreatePixelShader(self, pShaderBytecode, BytecodeLength, pClassLinkage, ppPixelShader); + #endif +} + +static inline HRESULT _sg_d3d11_CreateComputeShader(ID3D11Device* self, const void* pShaderBytecode, SIZE_T BytecodeLength, ID3D11ClassLinkage* pClassLinkage, ID3D11ComputeShader** ppComputeShader) { + #if defined(__cplusplus) + return self->CreateComputeShader(pShaderBytecode, BytecodeLength, pClassLinkage, ppComputeShader); + #else + return self->lpVtbl->CreateComputeShader(self, pShaderBytecode, BytecodeLength, pClassLinkage, ppComputeShader); + #endif +} + +static inline HRESULT _sg_d3d11_CreateInputLayout(ID3D11Device* self, const D3D11_INPUT_ELEMENT_DESC* pInputElementDescs, UINT NumElements, const void* pShaderBytecodeWithInputSignature, SIZE_T BytecodeLength, ID3D11InputLayout **ppInputLayout) { + #if defined(__cplusplus) + return self->CreateInputLayout(pInputElementDescs, NumElements, pShaderBytecodeWithInputSignature, BytecodeLength, ppInputLayout); + #else + return self->lpVtbl->CreateInputLayout(self, pInputElementDescs, NumElements, pShaderBytecodeWithInputSignature, BytecodeLength, ppInputLayout); + #endif +} + +static inline HRESULT _sg_d3d11_CreateRasterizerState(ID3D11Device* self, const D3D11_RASTERIZER_DESC* pRasterizerDesc, ID3D11RasterizerState** ppRasterizerState) { + #if defined(__cplusplus) + return self->CreateRasterizerState(pRasterizerDesc, ppRasterizerState); + #else + return self->lpVtbl->CreateRasterizerState(self, pRasterizerDesc, ppRasterizerState); + #endif +} + +static inline HRESULT _sg_d3d11_CreateDepthStencilState(ID3D11Device* self, const D3D11_DEPTH_STENCIL_DESC* pDepthStencilDesc, ID3D11DepthStencilState** ppDepthStencilState) { + #if defined(__cplusplus) + return self->CreateDepthStencilState(pDepthStencilDesc, ppDepthStencilState); + #else + return self->lpVtbl->CreateDepthStencilState(self, pDepthStencilDesc, ppDepthStencilState); + #endif +} + +static inline HRESULT _sg_d3d11_CreateBlendState(ID3D11Device* self, const D3D11_BLEND_DESC* pBlendStateDesc, ID3D11BlendState** ppBlendState) { + #if defined(__cplusplus) + return self->CreateBlendState(pBlendStateDesc, ppBlendState); + #else + return self->lpVtbl->CreateBlendState(self, pBlendStateDesc, ppBlendState); + #endif +} + +static inline HRESULT _sg_d3d11_CreateRenderTargetView(ID3D11Device* self, ID3D11Resource *pResource, const D3D11_RENDER_TARGET_VIEW_DESC* pDesc, ID3D11RenderTargetView** ppRTView) { + #if defined(__cplusplus) + return self->CreateRenderTargetView(pResource, pDesc, ppRTView); + #else + return self->lpVtbl->CreateRenderTargetView(self, pResource, pDesc, ppRTView); + #endif +} + +static inline HRESULT _sg_d3d11_CreateDepthStencilView(ID3D11Device* self, ID3D11Resource* pResource, const D3D11_DEPTH_STENCIL_VIEW_DESC* pDesc, ID3D11DepthStencilView** ppDepthStencilView) { + #if defined(__cplusplus) + return self->CreateDepthStencilView(pResource, pDesc, ppDepthStencilView); + #else + return self->lpVtbl->CreateDepthStencilView(self, pResource, pDesc, ppDepthStencilView); + #endif +} + +static inline void _sg_d3d11_RSSetViewports(ID3D11DeviceContext* self, UINT NumViewports, const D3D11_VIEWPORT* pViewports) { + #if defined(__cplusplus) + self->RSSetViewports(NumViewports, pViewports); + #else + self->lpVtbl->RSSetViewports(self, NumViewports, pViewports); + #endif +} + +static inline void _sg_d3d11_RSSetScissorRects(ID3D11DeviceContext* self, UINT NumRects, const D3D11_RECT* pRects) { + #if defined(__cplusplus) + self->RSSetScissorRects(NumRects, pRects); + #else + self->lpVtbl->RSSetScissorRects(self, NumRects, pRects); + #endif +} + +static inline void _sg_d3d11_ClearRenderTargetView(ID3D11DeviceContext* self, ID3D11RenderTargetView* pRenderTargetView, const FLOAT ColorRGBA[4]) { + #if defined(__cplusplus) + self->ClearRenderTargetView(pRenderTargetView, ColorRGBA); + #else + self->lpVtbl->ClearRenderTargetView(self, pRenderTargetView, ColorRGBA); + #endif +} + +static inline void _sg_d3d11_ClearDepthStencilView(ID3D11DeviceContext* self, ID3D11DepthStencilView* pDepthStencilView, UINT ClearFlags, FLOAT Depth, UINT8 Stencil) { + #if defined(__cplusplus) + self->ClearDepthStencilView(pDepthStencilView, ClearFlags, Depth, Stencil); + #else + self->lpVtbl->ClearDepthStencilView(self, pDepthStencilView, ClearFlags, Depth, Stencil); + #endif +} + +static inline void _sg_d3d11_ResolveSubresource(ID3D11DeviceContext* self, ID3D11Resource* pDstResource, UINT DstSubresource, ID3D11Resource* pSrcResource, UINT SrcSubresource, DXGI_FORMAT Format) { + #if defined(__cplusplus) + self->ResolveSubresource(pDstResource, DstSubresource, pSrcResource, SrcSubresource, Format); + #else + self->lpVtbl->ResolveSubresource(self, pDstResource, DstSubresource, pSrcResource, SrcSubresource, Format); + #endif +} + +static inline void _sg_d3d11_IASetPrimitiveTopology(ID3D11DeviceContext* self, D3D11_PRIMITIVE_TOPOLOGY Topology) { + #if defined(__cplusplus) + self->IASetPrimitiveTopology(Topology); + #else + self->lpVtbl->IASetPrimitiveTopology(self, Topology); + #endif +} + +static inline void _sg_d3d11_UpdateSubresource(ID3D11DeviceContext* self, ID3D11Resource* pDstResource, UINT DstSubresource, const D3D11_BOX* pDstBox, const void* pSrcData, UINT SrcRowPitch, UINT SrcDepthPitch) { + #if defined(__cplusplus) + self->UpdateSubresource(pDstResource, DstSubresource, pDstBox, pSrcData, SrcRowPitch, SrcDepthPitch); + #else + self->lpVtbl->UpdateSubresource(self, pDstResource, DstSubresource, pDstBox, pSrcData, SrcRowPitch, SrcDepthPitch); + #endif +} + +static inline void _sg_d3d11_DrawIndexed(ID3D11DeviceContext* self, UINT IndexCount, UINT StartIndexLocation, INT BaseVertexLocation) { + #if defined(__cplusplus) + self->DrawIndexed(IndexCount, StartIndexLocation, BaseVertexLocation); + #else + self->lpVtbl->DrawIndexed(self, IndexCount, StartIndexLocation, BaseVertexLocation); + #endif +} + +static inline void _sg_d3d11_DrawIndexedInstanced(ID3D11DeviceContext* self, UINT IndexCountPerInstance, UINT InstanceCount, UINT StartIndexLocation, INT BaseVertexLocation, UINT StartInstanceLocation) { + #if defined(__cplusplus) + self->DrawIndexedInstanced(IndexCountPerInstance, InstanceCount, StartIndexLocation, BaseVertexLocation, StartInstanceLocation); + #else + self->lpVtbl->DrawIndexedInstanced(self, IndexCountPerInstance, InstanceCount, StartIndexLocation, BaseVertexLocation, StartInstanceLocation); + #endif +} + +static inline void _sg_d3d11_Draw(ID3D11DeviceContext* self, UINT VertexCount, UINT StartVertexLocation) { + #if defined(__cplusplus) + self->Draw(VertexCount, StartVertexLocation); + #else + self->lpVtbl->Draw(self, VertexCount, StartVertexLocation); + #endif +} + +static inline void _sg_d3d11_DrawInstanced(ID3D11DeviceContext* self, UINT VertexCountPerInstance, UINT InstanceCount, UINT StartVertexLocation, UINT StartInstanceLocation) { + #if defined(__cplusplus) + self->DrawInstanced(VertexCountPerInstance, InstanceCount, StartVertexLocation, StartInstanceLocation); + #else + self->lpVtbl->DrawInstanced(self, VertexCountPerInstance, InstanceCount, StartVertexLocation, StartInstanceLocation); + #endif +} + +static inline void _sg_d3d11_Dispatch(ID3D11DeviceContext* self, UINT ThreadGroupCountX, UINT ThreadGroupCountY, UINT ThreadGroupCountZ) { + #if defined(__cplusplus) + self->Dispatch(ThreadGroupCountX, ThreadGroupCountY, ThreadGroupCountZ); + #else + self->lpVtbl->Dispatch(self, ThreadGroupCountX, ThreadGroupCountY, ThreadGroupCountZ); + #endif +} + +static inline HRESULT _sg_d3d11_Map(ID3D11DeviceContext* self, ID3D11Resource* pResource, UINT Subresource, D3D11_MAP MapType, UINT MapFlags, D3D11_MAPPED_SUBRESOURCE* pMappedResource) { + #if defined(__cplusplus) + return self->Map(pResource, Subresource, MapType, MapFlags, pMappedResource); + #else + return self->lpVtbl->Map(self, pResource, Subresource, MapType, MapFlags, pMappedResource); + #endif +} + +static inline void _sg_d3d11_Unmap(ID3D11DeviceContext* self, ID3D11Resource* pResource, UINT Subresource) { + #if defined(__cplusplus) + self->Unmap(pResource, Subresource); + #else + self->lpVtbl->Unmap(self, pResource, Subresource); + #endif +} + +static inline void _sg_d3d11_ClearState(ID3D11DeviceContext* self) { + #if defined(__cplusplus) + self->ClearState(); + #else + self->lpVtbl->ClearState(self); + #endif +} + +static inline D3D_FEATURE_LEVEL _sg_d3d11_GetFeatureLevel(ID3D11Device* self) { + #if defined(__cplusplus) + return self->GetFeatureLevel(); + #else + return self->lpVtbl->GetFeatureLevel(self); + #endif +} + +//-- enum translation functions ------------------------------------------------ +_SOKOL_PRIVATE D3D11_USAGE _sg_d3d11_image_usage(const sg_image_usage* usg) { + if (usg->immutable) { + if (usg->color_attachment || + usg->resolve_attachment || + usg->depth_stencil_attachment || + usg->storage_image) + { + return D3D11_USAGE_DEFAULT; + } else { + return D3D11_USAGE_IMMUTABLE; + } + } else { + return D3D11_USAGE_DYNAMIC; + } +} + +_SOKOL_PRIVATE UINT _sg_d3d11_image_bind_flags(const sg_image_usage* usg) { + UINT res = D3D11_BIND_SHADER_RESOURCE; + if (usg->color_attachment) { + res |= D3D11_BIND_RENDER_TARGET; + } + if (usg->depth_stencil_attachment) { + res |= D3D11_BIND_DEPTH_STENCIL; + } + if (usg->storage_image) { + res |= D3D11_BIND_UNORDERED_ACCESS; + } + return res; +} + +_SOKOL_PRIVATE UINT _sg_d3d11_image_cpu_access_flags(const sg_image_usage* usg) { + if (usg->color_attachment || + usg->resolve_attachment || + usg->depth_stencil_attachment || + usg->storage_image || + usg->immutable) + { + return 0; + } else { + return D3D11_CPU_ACCESS_WRITE; + } +} + +_SOKOL_PRIVATE D3D11_USAGE _sg_d3d11_buffer_usage(const sg_buffer_usage* usg) { + if (usg->immutable) { + return usg->storage_buffer ? D3D11_USAGE_DEFAULT : D3D11_USAGE_IMMUTABLE; + } else { + return D3D11_USAGE_DYNAMIC; + } +} + +_SOKOL_PRIVATE UINT _sg_d3d11_buffer_bind_flags(const sg_buffer_usage* usg) { + UINT res = 0; + if (usg->vertex_buffer) { + res |= D3D11_BIND_VERTEX_BUFFER; + } + if (usg->index_buffer) { + res |= D3D11_BIND_INDEX_BUFFER; + } + if (usg->storage_buffer) { + res |= D3D11_BIND_SHADER_RESOURCE; + if (usg->immutable) { + res |= D3D11_BIND_UNORDERED_ACCESS; + } + } + return res; +} + +_SOKOL_PRIVATE UINT _sg_d3d11_buffer_misc_flags(const sg_buffer_usage* usg) { + return usg->storage_buffer ? D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS : 0; +} + +_SOKOL_PRIVATE UINT _sg_d3d11_buffer_cpu_access_flags(const sg_buffer_usage* usg) { + return usg->immutable ? 0 : D3D11_CPU_ACCESS_WRITE; +} + +_SOKOL_PRIVATE DXGI_FORMAT _sg_d3d11_texture_pixel_format(sg_pixel_format fmt) { + switch (fmt) { + case SG_PIXELFORMAT_R8: return DXGI_FORMAT_R8_UNORM; + case SG_PIXELFORMAT_R8SN: return DXGI_FORMAT_R8_SNORM; + case SG_PIXELFORMAT_R8UI: return DXGI_FORMAT_R8_UINT; + case SG_PIXELFORMAT_R8SI: return DXGI_FORMAT_R8_SINT; + case SG_PIXELFORMAT_R16: return DXGI_FORMAT_R16_UNORM; + case SG_PIXELFORMAT_R16SN: return DXGI_FORMAT_R16_SNORM; + case SG_PIXELFORMAT_R16UI: return DXGI_FORMAT_R16_UINT; + case SG_PIXELFORMAT_R16SI: return DXGI_FORMAT_R16_SINT; + case SG_PIXELFORMAT_R16F: return DXGI_FORMAT_R16_FLOAT; + case SG_PIXELFORMAT_RG8: return DXGI_FORMAT_R8G8_UNORM; + case SG_PIXELFORMAT_RG8SN: return DXGI_FORMAT_R8G8_SNORM; + case SG_PIXELFORMAT_RG8UI: return DXGI_FORMAT_R8G8_UINT; + case SG_PIXELFORMAT_RG8SI: return DXGI_FORMAT_R8G8_SINT; + case SG_PIXELFORMAT_R32UI: return DXGI_FORMAT_R32_UINT; + case SG_PIXELFORMAT_R32SI: return DXGI_FORMAT_R32_SINT; + case SG_PIXELFORMAT_R32F: return DXGI_FORMAT_R32_FLOAT; + case SG_PIXELFORMAT_RG16: return DXGI_FORMAT_R16G16_UNORM; + case SG_PIXELFORMAT_RG16SN: return DXGI_FORMAT_R16G16_SNORM; + case SG_PIXELFORMAT_RG16UI: return DXGI_FORMAT_R16G16_UINT; + case SG_PIXELFORMAT_RG16SI: return DXGI_FORMAT_R16G16_SINT; + case SG_PIXELFORMAT_RG16F: return DXGI_FORMAT_R16G16_FLOAT; + case SG_PIXELFORMAT_RGBA8: return DXGI_FORMAT_R8G8B8A8_UNORM; + case SG_PIXELFORMAT_SRGB8A8: return DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; + case SG_PIXELFORMAT_RGBA8SN: return DXGI_FORMAT_R8G8B8A8_SNORM; + case SG_PIXELFORMAT_RGBA8UI: return DXGI_FORMAT_R8G8B8A8_UINT; + case SG_PIXELFORMAT_RGBA8SI: return DXGI_FORMAT_R8G8B8A8_SINT; + case SG_PIXELFORMAT_BGRA8: return DXGI_FORMAT_B8G8R8A8_UNORM; + case SG_PIXELFORMAT_RGB10A2: return DXGI_FORMAT_R10G10B10A2_UNORM; + case SG_PIXELFORMAT_RG11B10F: return DXGI_FORMAT_R11G11B10_FLOAT; + case SG_PIXELFORMAT_RGB9E5: return DXGI_FORMAT_R9G9B9E5_SHAREDEXP; + case SG_PIXELFORMAT_RG32UI: return DXGI_FORMAT_R32G32_UINT; + case SG_PIXELFORMAT_RG32SI: return DXGI_FORMAT_R32G32_SINT; + case SG_PIXELFORMAT_RG32F: return DXGI_FORMAT_R32G32_FLOAT; + case SG_PIXELFORMAT_RGBA16: return DXGI_FORMAT_R16G16B16A16_UNORM; + case SG_PIXELFORMAT_RGBA16SN: return DXGI_FORMAT_R16G16B16A16_SNORM; + case SG_PIXELFORMAT_RGBA16UI: return DXGI_FORMAT_R16G16B16A16_UINT; + case SG_PIXELFORMAT_RGBA16SI: return DXGI_FORMAT_R16G16B16A16_SINT; + case SG_PIXELFORMAT_RGBA16F: return DXGI_FORMAT_R16G16B16A16_FLOAT; + case SG_PIXELFORMAT_RGBA32UI: return DXGI_FORMAT_R32G32B32A32_UINT; + case SG_PIXELFORMAT_RGBA32SI: return DXGI_FORMAT_R32G32B32A32_SINT; + case SG_PIXELFORMAT_RGBA32F: return DXGI_FORMAT_R32G32B32A32_FLOAT; + case SG_PIXELFORMAT_DEPTH: return DXGI_FORMAT_R32_TYPELESS; + case SG_PIXELFORMAT_DEPTH_STENCIL: return DXGI_FORMAT_R24G8_TYPELESS; + case SG_PIXELFORMAT_BC1_RGBA: return DXGI_FORMAT_BC1_UNORM; + case SG_PIXELFORMAT_BC2_RGBA: return DXGI_FORMAT_BC2_UNORM; + case SG_PIXELFORMAT_BC3_RGBA: return DXGI_FORMAT_BC3_UNORM; + case SG_PIXELFORMAT_BC3_SRGBA: return DXGI_FORMAT_BC3_UNORM_SRGB; + case SG_PIXELFORMAT_BC4_R: return DXGI_FORMAT_BC4_UNORM; + case SG_PIXELFORMAT_BC4_RSN: return DXGI_FORMAT_BC4_SNORM; + case SG_PIXELFORMAT_BC5_RG: return DXGI_FORMAT_BC5_UNORM; + case SG_PIXELFORMAT_BC5_RGSN: return DXGI_FORMAT_BC5_SNORM; + case SG_PIXELFORMAT_BC6H_RGBF: return DXGI_FORMAT_BC6H_SF16; + case SG_PIXELFORMAT_BC6H_RGBUF: return DXGI_FORMAT_BC6H_UF16; + case SG_PIXELFORMAT_BC7_RGBA: return DXGI_FORMAT_BC7_UNORM; + case SG_PIXELFORMAT_BC7_SRGBA: return DXGI_FORMAT_BC7_UNORM_SRGB; + default: return DXGI_FORMAT_UNKNOWN; + }; +} + +_SOKOL_PRIVATE DXGI_FORMAT _sg_d3d11_srv_pixel_format(sg_pixel_format fmt) { + if (fmt == SG_PIXELFORMAT_DEPTH) { + return DXGI_FORMAT_R32_FLOAT; + } else if (fmt == SG_PIXELFORMAT_DEPTH_STENCIL) { + return DXGI_FORMAT_R24_UNORM_X8_TYPELESS; + } else { + return _sg_d3d11_texture_pixel_format(fmt); + } +} + +_SOKOL_PRIVATE DXGI_FORMAT _sg_d3d11_dsv_pixel_format(sg_pixel_format fmt) { + if (fmt == SG_PIXELFORMAT_DEPTH) { + return DXGI_FORMAT_D32_FLOAT; + } else if (fmt == SG_PIXELFORMAT_DEPTH_STENCIL) { + return DXGI_FORMAT_D24_UNORM_S8_UINT; + } else { + return _sg_d3d11_texture_pixel_format(fmt); + } +} + +_SOKOL_PRIVATE DXGI_FORMAT _sg_d3d11_rtv_uav_pixel_format(sg_pixel_format fmt) { + if (fmt == SG_PIXELFORMAT_DEPTH) { + return DXGI_FORMAT_R32_FLOAT; + } else if (fmt == SG_PIXELFORMAT_DEPTH_STENCIL) { + return DXGI_FORMAT_R24_UNORM_X8_TYPELESS; + } else { + return _sg_d3d11_texture_pixel_format(fmt); + } +} + +_SOKOL_PRIVATE D3D11_PRIMITIVE_TOPOLOGY _sg_d3d11_primitive_topology(sg_primitive_type prim_type) { + switch (prim_type) { + case SG_PRIMITIVETYPE_POINTS: return D3D11_PRIMITIVE_TOPOLOGY_POINTLIST; + case SG_PRIMITIVETYPE_LINES: return D3D11_PRIMITIVE_TOPOLOGY_LINELIST; + case SG_PRIMITIVETYPE_LINE_STRIP: return D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP; + case SG_PRIMITIVETYPE_TRIANGLES: return D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST; + case SG_PRIMITIVETYPE_TRIANGLE_STRIP: return D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP; + default: SOKOL_UNREACHABLE; return (D3D11_PRIMITIVE_TOPOLOGY) 0; + } +} + +_SOKOL_PRIVATE DXGI_FORMAT _sg_d3d11_index_format(sg_index_type index_type) { + switch (index_type) { + case SG_INDEXTYPE_NONE: return DXGI_FORMAT_UNKNOWN; + case SG_INDEXTYPE_UINT16: return DXGI_FORMAT_R16_UINT; + case SG_INDEXTYPE_UINT32: return DXGI_FORMAT_R32_UINT; + default: SOKOL_UNREACHABLE; return (DXGI_FORMAT) 0; + } +} + +_SOKOL_PRIVATE D3D11_FILTER _sg_d3d11_filter(sg_filter min_f, sg_filter mag_f, sg_filter mipmap_f, bool comparison, uint32_t max_anisotropy) { + uint32_t d3d11_filter = 0; + if (max_anisotropy > 1) { + // D3D11_FILTER_ANISOTROPIC = 0x55, + d3d11_filter |= 0x55; + } else { + // D3D11_FILTER_MIN_MAG_MIP_POINT = 0, + // D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR = 0x1, + // D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT = 0x4, + // D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR = 0x5, + // D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT = 0x10, + // D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR = 0x11, + // D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT = 0x14, + // D3D11_FILTER_MIN_MAG_MIP_LINEAR = 0x15, + if (mipmap_f == SG_FILTER_LINEAR) { + d3d11_filter |= 0x01; + } + if (mag_f == SG_FILTER_LINEAR) { + d3d11_filter |= 0x04; + } + if (min_f == SG_FILTER_LINEAR) { + d3d11_filter |= 0x10; + } + } + // D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT = 0x80, + // D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR = 0x81, + // D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT = 0x84, + // D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR = 0x85, + // D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT = 0x90, + // D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR = 0x91, + // D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT = 0x94, + // D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR = 0x95, + // D3D11_FILTER_COMPARISON_ANISOTROPIC = 0xd5, + if (comparison) { + d3d11_filter |= 0x80; + } + return (D3D11_FILTER)d3d11_filter; +} + +_SOKOL_PRIVATE D3D11_TEXTURE_ADDRESS_MODE _sg_d3d11_address_mode(sg_wrap m) { + switch (m) { + case SG_WRAP_REPEAT: return D3D11_TEXTURE_ADDRESS_WRAP; + case SG_WRAP_CLAMP_TO_EDGE: return D3D11_TEXTURE_ADDRESS_CLAMP; + case SG_WRAP_CLAMP_TO_BORDER: return D3D11_TEXTURE_ADDRESS_BORDER; + case SG_WRAP_MIRRORED_REPEAT: return D3D11_TEXTURE_ADDRESS_MIRROR; + default: SOKOL_UNREACHABLE; return (D3D11_TEXTURE_ADDRESS_MODE) 0; + } +} + +_SOKOL_PRIVATE DXGI_FORMAT _sg_d3d11_vertex_format(sg_vertex_format fmt) { + switch (fmt) { + case SG_VERTEXFORMAT_FLOAT: return DXGI_FORMAT_R32_FLOAT; + case SG_VERTEXFORMAT_FLOAT2: return DXGI_FORMAT_R32G32_FLOAT; + case SG_VERTEXFORMAT_FLOAT3: return DXGI_FORMAT_R32G32B32_FLOAT; + case SG_VERTEXFORMAT_FLOAT4: return DXGI_FORMAT_R32G32B32A32_FLOAT; + case SG_VERTEXFORMAT_INT: return DXGI_FORMAT_R32_SINT; + case SG_VERTEXFORMAT_INT2: return DXGI_FORMAT_R32G32_SINT; + case SG_VERTEXFORMAT_INT3: return DXGI_FORMAT_R32G32B32_SINT; + case SG_VERTEXFORMAT_INT4: return DXGI_FORMAT_R32G32B32A32_SINT; + case SG_VERTEXFORMAT_UINT: return DXGI_FORMAT_R32_UINT; + case SG_VERTEXFORMAT_UINT2: return DXGI_FORMAT_R32G32_UINT; + case SG_VERTEXFORMAT_UINT3: return DXGI_FORMAT_R32G32B32_UINT; + case SG_VERTEXFORMAT_UINT4: return DXGI_FORMAT_R32G32B32A32_UINT; + case SG_VERTEXFORMAT_BYTE4: return DXGI_FORMAT_R8G8B8A8_SINT; + case SG_VERTEXFORMAT_BYTE4N: return DXGI_FORMAT_R8G8B8A8_SNORM; + case SG_VERTEXFORMAT_UBYTE4: return DXGI_FORMAT_R8G8B8A8_UINT; + case SG_VERTEXFORMAT_UBYTE4N: return DXGI_FORMAT_R8G8B8A8_UNORM; + case SG_VERTEXFORMAT_SHORT2: return DXGI_FORMAT_R16G16_SINT; + case SG_VERTEXFORMAT_SHORT2N: return DXGI_FORMAT_R16G16_SNORM; + case SG_VERTEXFORMAT_USHORT2: return DXGI_FORMAT_R16G16_UINT; + case SG_VERTEXFORMAT_USHORT2N: return DXGI_FORMAT_R16G16_UNORM; + case SG_VERTEXFORMAT_SHORT4: return DXGI_FORMAT_R16G16B16A16_SINT; + case SG_VERTEXFORMAT_SHORT4N: return DXGI_FORMAT_R16G16B16A16_SNORM; + case SG_VERTEXFORMAT_USHORT4: return DXGI_FORMAT_R16G16B16A16_UINT; + case SG_VERTEXFORMAT_USHORT4N: return DXGI_FORMAT_R16G16B16A16_UNORM; + case SG_VERTEXFORMAT_UINT10_N2: return DXGI_FORMAT_R10G10B10A2_UNORM; + case SG_VERTEXFORMAT_HALF2: return DXGI_FORMAT_R16G16_FLOAT; + case SG_VERTEXFORMAT_HALF4: return DXGI_FORMAT_R16G16B16A16_FLOAT; + default: SOKOL_UNREACHABLE; return (DXGI_FORMAT) 0; + } +} + +_SOKOL_PRIVATE D3D11_INPUT_CLASSIFICATION _sg_d3d11_input_classification(sg_vertex_step step) { + switch (step) { + case SG_VERTEXSTEP_PER_VERTEX: return D3D11_INPUT_PER_VERTEX_DATA; + case SG_VERTEXSTEP_PER_INSTANCE: return D3D11_INPUT_PER_INSTANCE_DATA; + default: SOKOL_UNREACHABLE; return (D3D11_INPUT_CLASSIFICATION) 0; + } +} + +_SOKOL_PRIVATE D3D11_CULL_MODE _sg_d3d11_cull_mode(sg_cull_mode m) { + switch (m) { + case SG_CULLMODE_NONE: return D3D11_CULL_NONE; + case SG_CULLMODE_FRONT: return D3D11_CULL_FRONT; + case SG_CULLMODE_BACK: return D3D11_CULL_BACK; + default: SOKOL_UNREACHABLE; return (D3D11_CULL_MODE) 0; + } +} + +_SOKOL_PRIVATE D3D11_COMPARISON_FUNC _sg_d3d11_compare_func(sg_compare_func f) { + switch (f) { + case SG_COMPAREFUNC_NEVER: return D3D11_COMPARISON_NEVER; + case SG_COMPAREFUNC_LESS: return D3D11_COMPARISON_LESS; + case SG_COMPAREFUNC_EQUAL: return D3D11_COMPARISON_EQUAL; + case SG_COMPAREFUNC_LESS_EQUAL: return D3D11_COMPARISON_LESS_EQUAL; + case SG_COMPAREFUNC_GREATER: return D3D11_COMPARISON_GREATER; + case SG_COMPAREFUNC_NOT_EQUAL: return D3D11_COMPARISON_NOT_EQUAL; + case SG_COMPAREFUNC_GREATER_EQUAL: return D3D11_COMPARISON_GREATER_EQUAL; + case SG_COMPAREFUNC_ALWAYS: return D3D11_COMPARISON_ALWAYS; + default: SOKOL_UNREACHABLE; return (D3D11_COMPARISON_FUNC) 0; + } +} + +_SOKOL_PRIVATE D3D11_STENCIL_OP _sg_d3d11_stencil_op(sg_stencil_op op) { + switch (op) { + case SG_STENCILOP_KEEP: return D3D11_STENCIL_OP_KEEP; + case SG_STENCILOP_ZERO: return D3D11_STENCIL_OP_ZERO; + case SG_STENCILOP_REPLACE: return D3D11_STENCIL_OP_REPLACE; + case SG_STENCILOP_INCR_CLAMP: return D3D11_STENCIL_OP_INCR_SAT; + case SG_STENCILOP_DECR_CLAMP: return D3D11_STENCIL_OP_DECR_SAT; + case SG_STENCILOP_INVERT: return D3D11_STENCIL_OP_INVERT; + case SG_STENCILOP_INCR_WRAP: return D3D11_STENCIL_OP_INCR; + case SG_STENCILOP_DECR_WRAP: return D3D11_STENCIL_OP_DECR; + default: SOKOL_UNREACHABLE; return (D3D11_STENCIL_OP) 0; + } +} + +_SOKOL_PRIVATE D3D11_BLEND _sg_d3d11_blend_factor(sg_blend_factor f) { + switch (f) { + case SG_BLENDFACTOR_ZERO: return D3D11_BLEND_ZERO; + case SG_BLENDFACTOR_ONE: return D3D11_BLEND_ONE; + case SG_BLENDFACTOR_SRC_COLOR: return D3D11_BLEND_SRC_COLOR; + case SG_BLENDFACTOR_ONE_MINUS_SRC_COLOR: return D3D11_BLEND_INV_SRC_COLOR; + case SG_BLENDFACTOR_SRC_ALPHA: return D3D11_BLEND_SRC_ALPHA; + case SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA: return D3D11_BLEND_INV_SRC_ALPHA; + case SG_BLENDFACTOR_DST_COLOR: return D3D11_BLEND_DEST_COLOR; + case SG_BLENDFACTOR_ONE_MINUS_DST_COLOR: return D3D11_BLEND_INV_DEST_COLOR; + case SG_BLENDFACTOR_DST_ALPHA: return D3D11_BLEND_DEST_ALPHA; + case SG_BLENDFACTOR_ONE_MINUS_DST_ALPHA: return D3D11_BLEND_INV_DEST_ALPHA; + case SG_BLENDFACTOR_SRC_ALPHA_SATURATED: return D3D11_BLEND_SRC_ALPHA_SAT; + case SG_BLENDFACTOR_BLEND_COLOR: return D3D11_BLEND_BLEND_FACTOR; + case SG_BLENDFACTOR_ONE_MINUS_BLEND_COLOR: return D3D11_BLEND_INV_BLEND_FACTOR; + case SG_BLENDFACTOR_BLEND_ALPHA: return D3D11_BLEND_BLEND_FACTOR; + case SG_BLENDFACTOR_ONE_MINUS_BLEND_ALPHA: return D3D11_BLEND_INV_BLEND_FACTOR; + case SG_BLENDFACTOR_SRC1_COLOR: return D3D11_BLEND_SRC1_COLOR; + case SG_BLENDFACTOR_ONE_MINUS_SRC1_COLOR: return D3D11_BLEND_INV_SRC1_COLOR; + case SG_BLENDFACTOR_SRC1_ALPHA: return D3D11_BLEND_SRC1_ALPHA; + case SG_BLENDFACTOR_ONE_MINUS_SRC1_ALPHA: return D3D11_BLEND_INV_SRC1_ALPHA; + default: SOKOL_UNREACHABLE; return (D3D11_BLEND) 0; + } +} + +_SOKOL_PRIVATE D3D11_BLEND_OP _sg_d3d11_blend_op(sg_blend_op op) { + switch (op) { + case SG_BLENDOP_ADD: return D3D11_BLEND_OP_ADD; + case SG_BLENDOP_SUBTRACT: return D3D11_BLEND_OP_SUBTRACT; + case SG_BLENDOP_REVERSE_SUBTRACT: return D3D11_BLEND_OP_REV_SUBTRACT; + case SG_BLENDOP_MIN: return D3D11_BLEND_OP_MIN; + case SG_BLENDOP_MAX: return D3D11_BLEND_OP_MAX; + default: SOKOL_UNREACHABLE; return (D3D11_BLEND_OP) 0; + } +} + +_SOKOL_PRIVATE UINT8 _sg_d3d11_color_write_mask(sg_color_mask m) { + UINT8 res = 0; + if (m & SG_COLORMASK_R) { + res |= D3D11_COLOR_WRITE_ENABLE_RED; + } + if (m & SG_COLORMASK_G) { + res |= D3D11_COLOR_WRITE_ENABLE_GREEN; + } + if (m & SG_COLORMASK_B) { + res |= D3D11_COLOR_WRITE_ENABLE_BLUE; + } + if (m & SG_COLORMASK_A) { + res |= D3D11_COLOR_WRITE_ENABLE_ALPHA; + } + return res; +} + +_SOKOL_PRIVATE UINT _sg_d3d11_dxgi_fmt_caps(DXGI_FORMAT dxgi_fmt) { + UINT dxgi_fmt_caps = 0; + if (dxgi_fmt != DXGI_FORMAT_UNKNOWN) { + HRESULT hr = _sg_d3d11_CheckFormatSupport(_sg.d3d11.dev, dxgi_fmt, &dxgi_fmt_caps); + SOKOL_ASSERT(SUCCEEDED(hr) || (E_FAIL == hr)); + if (!SUCCEEDED(hr)) { + dxgi_fmt_caps = 0; + } + } + return dxgi_fmt_caps; +} + +// see: https://docs.microsoft.com/en-us/windows/win32/direct3d11/overviews-direct3d-11-resources-limits#resource-limits-for-feature-level-11-hardware +_SOKOL_PRIVATE void _sg_d3d11_init_caps(void) { + _sg.backend = SG_BACKEND_D3D11; + + _sg.features.origin_top_left = true; + _sg.features.image_clamp_to_border = true; + _sg.features.mrt_independent_blend_state = true; + _sg.features.mrt_independent_write_mask = true; + _sg.features.compute = true; + _sg.features.msaa_texture_bindings = true; + _sg.features.draw_base_vertex = true; + _sg.features.draw_base_instance = true; + _sg.features.dual_source_blending = true; + _sg.features.vertexformat_int10_n2 = false; + + _sg.limits.max_image_size_2d = 16 * 1024; + _sg.limits.max_image_size_cube = 16 * 1024; + _sg.limits.max_image_size_3d = 2 * 1024; + _sg.limits.max_image_size_array = 16 * 1024; + _sg.limits.max_image_array_layers = _SG_D3D11_MAX_TEXTUREARRAY_LAYERS; + _sg.limits.max_vertex_attrs = SG_MAX_VERTEX_ATTRIBUTES; + _sg.limits.max_color_attachments = _sg_min(8, SG_MAX_COLOR_ATTACHMENTS); + _sg.limits.max_texture_bindings_per_stage = _sg_min(128, SG_MAX_VIEW_BINDSLOTS); + _sg.limits.max_storage_buffer_bindings_per_stage = _sg_min(64, SG_MAX_VIEW_BINDSLOTS); + if (_sg_d3d11_GetFeatureLevel(_sg.d3d11.dev) >= D3D_FEATURE_LEVEL_11_1) { + _sg.limits.d3d11_max_unordered_access_views = _sg_min(64, SG_MAX_VIEW_BINDSLOTS); + } else { + _sg.limits.d3d11_max_unordered_access_views = _sg_min(8, SG_MAX_VIEW_BINDSLOTS); + } + _sg.limits.max_storage_image_bindings_per_stage = _sg.limits.d3d11_max_unordered_access_views; + + // see: https://docs.microsoft.com/en-us/windows/win32/api/d3d11/ne-d3d11-d3d11_format_support + for (int fmt = (SG_PIXELFORMAT_NONE+1); fmt < _SG_PIXELFORMAT_NUM; fmt++) { + const UINT srv_dxgi_fmt_caps = _sg_d3d11_dxgi_fmt_caps(_sg_d3d11_srv_pixel_format((sg_pixel_format)fmt)); + const UINT rtv_uav_dxgi_fmt_caps = _sg_d3d11_dxgi_fmt_caps(_sg_d3d11_rtv_uav_pixel_format((sg_pixel_format)fmt)); + const UINT dsv_dxgi_fmt_caps = _sg_d3d11_dxgi_fmt_caps(_sg_d3d11_dsv_pixel_format((sg_pixel_format)fmt)); + _sg_pixelformat_info_t* info = &_sg.formats[fmt]; + const bool render = 0 != (rtv_uav_dxgi_fmt_caps & D3D11_FORMAT_SUPPORT_RENDER_TARGET); + const bool depth = 0 != (dsv_dxgi_fmt_caps & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL); + info->sample = 0 != (srv_dxgi_fmt_caps & D3D11_FORMAT_SUPPORT_TEXTURE2D); + info->filter = 0 != (srv_dxgi_fmt_caps & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE); + info->render = render || depth; + if (depth) { + info->blend = 0 != (dsv_dxgi_fmt_caps & D3D11_FORMAT_SUPPORT_BLENDABLE); + info->msaa = 0 != (dsv_dxgi_fmt_caps & D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET); + } else { + info->blend = 0 != (rtv_uav_dxgi_fmt_caps & D3D11_FORMAT_SUPPORT_BLENDABLE); + info->msaa = 0 != (rtv_uav_dxgi_fmt_caps & D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET); + } + info->depth = depth; + info->read = info->write = 0 != (rtv_uav_dxgi_fmt_caps & D3D11_FORMAT_SUPPORT_TYPED_UNORDERED_ACCESS_VIEW); + } +} + +// Local patch: debug-marker IID, defined inline so we don't need to link dxguid.lib. +// Matches the GUID from d3d11_1.h. +static const IID _sg_d3d11_IID_ID3DUserDefinedAnnotation = { + 0xb2daad8b, 0x03d4, 0x4dbf, { 0x95, 0xeb, 0x32, 0xab, 0x4b, 0x63, 0xd0, 0xab } +}; + +_SOKOL_PRIVATE void _sg_d3d11_setup_backend(const sg_desc* desc) { + // assume _sg.d3d11 already is zero-initialized + SOKOL_ASSERT(desc); + SOKOL_ASSERT(desc->environment.d3d11.device); + SOKOL_ASSERT(desc->environment.d3d11.device_context); + _sg.d3d11.valid = true; + _sg.d3d11.dev = (ID3D11Device*) desc->environment.d3d11.device; + _sg.d3d11.ctx = (ID3D11DeviceContext*) desc->environment.d3d11.device_context; + // Local patch: grab the annotation interface for BeginEvent/EndEvent debug markers. + // Always available on D3D11.1+ runtimes; only emits to capture tools (RenderDoc/PIX/Nsight) + // when one is attached, so it's safe to leave wired in release builds. + ID3DUserDefinedAnnotation* ann = NULL; + HRESULT ann_hr = _sg.d3d11.ctx->lpVtbl->QueryInterface( + _sg.d3d11.ctx, &_sg_d3d11_IID_ID3DUserDefinedAnnotation, (void**)&ann); + _sg.d3d11.annotation = SUCCEEDED(ann_hr) ? ann : NULL; + _sg_d3d11_init_caps(); + if (_sg_d3d11_GetFeatureLevel(_sg.d3d11.dev) == D3D_FEATURE_LEVEL_11_0) { + _SG_WARN(D3D11_FEATURE_LEVEL_0_DETECTED); + } +} + +_SOKOL_PRIVATE void _sg_d3d11_discard_backend(void) { + SOKOL_ASSERT(_sg.d3d11.valid); + _sg.d3d11.valid = false; + if (_sg.d3d11.annotation) { + _sg.d3d11.annotation->lpVtbl->Release(_sg.d3d11.annotation); + _sg.d3d11.annotation = NULL; + } +} + +// Local patch: debug-marker push/pop. Lowered to ID3DUserDefinedAnnotation::BeginEvent/EndEvent, +// which RenderDoc / PIX / Nsight pick up as hierarchical event regions in the captured command list. +_SOKOL_PRIVATE void _sg_d3d11_push_debug_group(const char* name) { + if (!_sg.d3d11.annotation || !name) { + return; + } + WCHAR wname[256]; + int n = MultiByteToWideChar(CP_UTF8, 0, name, -1, wname, (int)(sizeof(wname) / sizeof(wname[0]))); + if (n <= 0) { + wname[0] = L'?'; + wname[1] = 0; + } + _sg.d3d11.annotation->lpVtbl->BeginEvent(_sg.d3d11.annotation, wname); +} + +_SOKOL_PRIVATE void _sg_d3d11_pop_debug_group(void) { + if (!_sg.d3d11.annotation) { + return; + } + _sg.d3d11.annotation->lpVtbl->EndEvent(_sg.d3d11.annotation); +} + +_SOKOL_PRIVATE void _sg_d3d11_clear_state(void) { + // clear all the device context state, so that resource refs don't keep stuck in the d3d device context + _sg_d3d11_ClearState(_sg.d3d11.ctx); +} + +_SOKOL_PRIVATE void _sg_d3d11_reset_state_cache(void) { + // there's currently no state cache in the D3D11 backend, so this is a no-op +} + +_SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_buffer(_sg_buffer_t* buf, const sg_buffer_desc* desc) { + SOKOL_ASSERT(buf && desc); + SOKOL_ASSERT(!buf->d3d11.buf); + const bool injected = (0 != desc->d3d11_buffer); + if (injected) { + buf->d3d11.buf = (ID3D11Buffer*) desc->d3d11_buffer; + _sg_d3d11_AddRef(buf->d3d11.buf); + } else { + _SG_STRUCT(D3D11_BUFFER_DESC, d3d11_buf_desc); + d3d11_buf_desc.ByteWidth = (UINT)buf->cmn.size; + d3d11_buf_desc.Usage = _sg_d3d11_buffer_usage(&buf->cmn.usage); + d3d11_buf_desc.BindFlags = _sg_d3d11_buffer_bind_flags(&buf->cmn.usage); + d3d11_buf_desc.CPUAccessFlags = _sg_d3d11_buffer_cpu_access_flags(&buf->cmn.usage); + d3d11_buf_desc.MiscFlags = _sg_d3d11_buffer_misc_flags(&buf->cmn.usage); + D3D11_SUBRESOURCE_DATA* init_data_ptr = 0; + _SG_STRUCT(D3D11_SUBRESOURCE_DATA, init_data); + if (desc->data.ptr) { + init_data.pSysMem = desc->data.ptr; + init_data_ptr = &init_data; + } + HRESULT hr = _sg_d3d11_CreateBuffer(_sg.d3d11.dev, &d3d11_buf_desc, init_data_ptr, &buf->d3d11.buf); + if (!(SUCCEEDED(hr) && buf->d3d11.buf)) { + _SG_ERROR(D3D11_CREATE_BUFFER_FAILED); + return SG_RESOURCESTATE_FAILED; + } + _sg_d3d11_setlabel(buf->d3d11.buf, desc->label); + } + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_d3d11_discard_buffer(_sg_buffer_t* buf) { + SOKOL_ASSERT(buf); + if (buf->d3d11.buf) { + _sg_d3d11_Release(buf->d3d11.buf); + } +} + +_SOKOL_PRIVATE void _sg_d3d11_fill_subres_data(const _sg_image_t* img, const sg_image_data* data) { + const int num_slices = (img->cmn.type == SG_IMAGETYPE_3D) ? 1 : img->cmn.num_slices; + int subres_index = 0; + for (int slice_index = 0; slice_index < num_slices; slice_index++) { + for (int mip_index = 0; mip_index < img->cmn.num_mipmaps; mip_index++, subres_index++) { + SOKOL_ASSERT(subres_index < _SG_D3D11_MAX_TEXTURE_SUBRESOURCES); + D3D11_SUBRESOURCE_DATA* subres_data = &_sg.d3d11.subres_data[subres_index]; + const int mip_width = _sg_miplevel_dim(img->cmn.width, mip_index); + const int mip_height = _sg_miplevel_dim(img->cmn.height, mip_index); + const sg_range* miplevel_data = &(data->mip_levels[mip_index]); + const size_t slice_size = miplevel_data->size / (size_t)num_slices; + const size_t slice_offset = slice_size * (size_t)slice_index; + const uint8_t* ptr = (const uint8_t*) miplevel_data->ptr; + subres_data->pSysMem = ptr + slice_offset; + subres_data->SysMemPitch = (UINT)_sg_row_pitch(img->cmn.pixel_format, mip_width, 1); + if (img->cmn.type == SG_IMAGETYPE_3D) { + subres_data->SysMemSlicePitch = (UINT)_sg_surface_pitch(img->cmn.pixel_format, mip_width, mip_height, 1); + } else { + subres_data->SysMemSlicePitch = 0; + } + } + } +} + +_SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_image(_sg_image_t* img, const sg_image_desc* desc) { + SOKOL_ASSERT(img && desc); + SOKOL_ASSERT((0 == img->d3d11.tex2d) && (0 == img->d3d11.tex3d) && (0 == img->d3d11.res)); + HRESULT hr; + + const bool injected = (0 != desc->d3d11_texture); + const bool msaa = (img->cmn.sample_count > 1); + SOKOL_ASSERT(!(msaa && (img->cmn.type == SG_IMAGETYPE_CUBE))); + img->d3d11.format = _sg_d3d11_texture_pixel_format(img->cmn.pixel_format); + if (img->d3d11.format == DXGI_FORMAT_UNKNOWN) { + _SG_ERROR(D3D11_CREATE_2D_TEXTURE_UNSUPPORTED_PIXEL_FORMAT); + return SG_RESOURCESTATE_FAILED; + } + + // prepare initial content pointers + D3D11_SUBRESOURCE_DATA* init_data = 0; + if (!injected && desc->data.mip_levels[0].ptr) { + _sg_d3d11_fill_subres_data(img, &desc->data); + init_data = _sg.d3d11.subres_data; + } + if (img->cmn.type != SG_IMAGETYPE_3D) { + // 2D-, cube- or array-texture + // first check for injected texture and/or resource view + if (injected) { + img->d3d11.tex2d = (ID3D11Texture2D*) desc->d3d11_texture; + _sg_d3d11_AddRef(img->d3d11.tex2d); + } else { + // if not injected, create 2D texture + _SG_STRUCT(D3D11_TEXTURE2D_DESC, d3d11_tex_desc); + d3d11_tex_desc.Width = (UINT)img->cmn.width; + d3d11_tex_desc.Height = (UINT)img->cmn.height; + d3d11_tex_desc.MipLevels = (UINT)img->cmn.num_mipmaps; + d3d11_tex_desc.ArraySize = (UINT)img->cmn.num_slices; + d3d11_tex_desc.Format = img->d3d11.format; + d3d11_tex_desc.BindFlags = _sg_d3d11_image_bind_flags(&img->cmn.usage); + d3d11_tex_desc.Usage = _sg_d3d11_image_usage(&img->cmn.usage); + d3d11_tex_desc.CPUAccessFlags = _sg_d3d11_image_cpu_access_flags(&img->cmn.usage); + d3d11_tex_desc.SampleDesc.Count = (UINT)img->cmn.sample_count; + d3d11_tex_desc.SampleDesc.Quality = (UINT) (msaa ? D3D11_STANDARD_MULTISAMPLE_PATTERN : 0); + d3d11_tex_desc.MiscFlags = (img->cmn.type == SG_IMAGETYPE_CUBE) ? D3D11_RESOURCE_MISC_TEXTURECUBE : 0; + hr = _sg_d3d11_CreateTexture2D(_sg.d3d11.dev, &d3d11_tex_desc, init_data, &img->d3d11.tex2d); + if (!(SUCCEEDED(hr) && img->d3d11.tex2d)) { + _SG_ERROR(D3D11_CREATE_2D_TEXTURE_FAILED); + return SG_RESOURCESTATE_FAILED; + } + _sg_d3d11_setlabel(img->d3d11.tex2d, desc->label); + } + SOKOL_ASSERT(img->d3d11.tex2d); + img->d3d11.res = (ID3D11Resource*)img->d3d11.tex2d; + _sg_d3d11_AddRef(img->d3d11.res); + } else { + // 3D texture - same procedure, first check if injected, than create non-injected + if (injected) { + img->d3d11.tex3d = (ID3D11Texture3D*) desc->d3d11_texture; + _sg_d3d11_AddRef(img->d3d11.tex3d); + } else { + // not injected, create 3d texture + _SG_STRUCT(D3D11_TEXTURE3D_DESC, d3d11_tex_desc); + d3d11_tex_desc.Width = (UINT)img->cmn.width; + d3d11_tex_desc.Height = (UINT)img->cmn.height; + d3d11_tex_desc.Depth = (UINT)img->cmn.num_slices; + d3d11_tex_desc.MipLevels = (UINT)img->cmn.num_mipmaps; + d3d11_tex_desc.Format = img->d3d11.format; + d3d11_tex_desc.BindFlags = _sg_d3d11_image_bind_flags(&img->cmn.usage); + d3d11_tex_desc.Usage = _sg_d3d11_image_usage(&img->cmn.usage); + d3d11_tex_desc.CPUAccessFlags = _sg_d3d11_image_cpu_access_flags(&img->cmn.usage); + if (img->d3d11.format == DXGI_FORMAT_UNKNOWN) { + _SG_ERROR(D3D11_CREATE_3D_TEXTURE_UNSUPPORTED_PIXEL_FORMAT); + return SG_RESOURCESTATE_FAILED; + } + hr = _sg_d3d11_CreateTexture3D(_sg.d3d11.dev, &d3d11_tex_desc, init_data, &img->d3d11.tex3d); + if (!(SUCCEEDED(hr) && img->d3d11.tex3d)) { + _SG_ERROR(D3D11_CREATE_3D_TEXTURE_FAILED); + return SG_RESOURCESTATE_FAILED; + } + _sg_d3d11_setlabel(img->d3d11.tex3d, desc->label); + } + SOKOL_ASSERT(img->d3d11.tex3d); + img->d3d11.res = (ID3D11Resource*)img->d3d11.tex3d; + _sg_d3d11_AddRef(img->d3d11.res); + } + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_d3d11_discard_image(_sg_image_t* img) { + SOKOL_ASSERT(img); + if (img->d3d11.tex2d) { + _sg_d3d11_Release(img->d3d11.tex2d); + } + if (img->d3d11.tex3d) { + _sg_d3d11_Release(img->d3d11.tex3d); + } + if (img->d3d11.res) { + _sg_d3d11_Release(img->d3d11.res); + } +} + +_SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_sampler(_sg_sampler_t* smp, const sg_sampler_desc* desc) { + SOKOL_ASSERT(smp && desc); + SOKOL_ASSERT(0 == smp->d3d11.smp); + const bool injected = (0 != desc->d3d11_sampler); + if (injected) { + smp->d3d11.smp = (ID3D11SamplerState*)desc->d3d11_sampler; + _sg_d3d11_AddRef(smp->d3d11.smp); + } else { + _SG_STRUCT(D3D11_SAMPLER_DESC, d3d11_smp_desc); + d3d11_smp_desc.Filter = _sg_d3d11_filter(desc->min_filter, desc->mag_filter, desc->mipmap_filter, desc->compare != SG_COMPAREFUNC_NEVER, desc->max_anisotropy); + d3d11_smp_desc.AddressU = _sg_d3d11_address_mode(desc->wrap_u); + d3d11_smp_desc.AddressV = _sg_d3d11_address_mode(desc->wrap_v); + d3d11_smp_desc.AddressW = _sg_d3d11_address_mode(desc->wrap_w); + d3d11_smp_desc.MipLODBias = 0.0f; // FIXME? + switch (desc->border_color) { + case SG_BORDERCOLOR_TRANSPARENT_BLACK: + // all 0.0f + break; + case SG_BORDERCOLOR_OPAQUE_WHITE: + for (int i = 0; i < 4; i++) { + d3d11_smp_desc.BorderColor[i] = 1.0f; + } + break; + default: + // opaque black + d3d11_smp_desc.BorderColor[3] = 1.0f; + break; + } + d3d11_smp_desc.MaxAnisotropy = desc->max_anisotropy; + d3d11_smp_desc.ComparisonFunc = _sg_d3d11_compare_func(desc->compare); + d3d11_smp_desc.MinLOD = desc->min_lod; + d3d11_smp_desc.MaxLOD = desc->max_lod; + HRESULT hr = _sg_d3d11_CreateSamplerState(_sg.d3d11.dev, &d3d11_smp_desc, &smp->d3d11.smp); + if (!(SUCCEEDED(hr) && smp->d3d11.smp)) { + _SG_ERROR(D3D11_CREATE_SAMPLER_STATE_FAILED); + return SG_RESOURCESTATE_FAILED; + } + _sg_d3d11_setlabel(smp->d3d11.smp, desc->label); + } + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_d3d11_discard_sampler(_sg_sampler_t* smp) { + SOKOL_ASSERT(smp); + if (smp->d3d11.smp) { + _sg_d3d11_Release(smp->d3d11.smp); + } +} + +_SOKOL_PRIVATE bool _sg_d3d11_load_d3dcompiler_dll(void) { + if ((0 == _sg.d3d11.d3dcompiler_dll) && !_sg.d3d11.d3dcompiler_dll_load_failed) { + _sg.d3d11.d3dcompiler_dll = LoadLibraryA("d3dcompiler_47.dll"); + if (0 == _sg.d3d11.d3dcompiler_dll) { + // don't attempt to load missing DLL in the future + _SG_ERROR(D3D11_LOAD_D3DCOMPILER_47_DLL_FAILED); + _sg.d3d11.d3dcompiler_dll_load_failed = true; + return false; + } + // look up function pointers + _sg.d3d11.D3DCompile_func = (pD3DCompile)(void*) GetProcAddress(_sg.d3d11.d3dcompiler_dll, "D3DCompile"); + SOKOL_ASSERT(_sg.d3d11.D3DCompile_func); + } + return 0 != _sg.d3d11.d3dcompiler_dll; +} + +_SOKOL_PRIVATE ID3DBlob* _sg_d3d11_compile_shader(const sg_shader_function* shd_func) { + if (!_sg_d3d11_load_d3dcompiler_dll()) { + return NULL; + } + SOKOL_ASSERT(shd_func->d3d11_target); + UINT flags1 = D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR; + if (_sg.desc.d3d11.shader_debugging) { + flags1 |= D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION; + } else { + flags1 |= D3DCOMPILE_OPTIMIZATION_LEVEL3; + } + ID3DBlob* output = NULL; + ID3DBlob* errors_or_warnings = NULL; + HRESULT hr = _sg.d3d11.D3DCompile_func( + shd_func->source, // pSrcData + strlen(shd_func->source), // SrcDataSize + shd_func->d3d11_filepath, // pSourceName + NULL, // pDefines + D3D_COMPILE_STANDARD_FILE_INCLUDE, // pInclude + shd_func->entry ? shd_func->entry : "main", // pEntryPoint + shd_func->d3d11_target, // pTarget + flags1, // Flags1 + 0, // Flags2 + &output, // ppCode + &errors_or_warnings); // ppErrorMsgs + if (FAILED(hr)) { + _SG_ERROR(D3D11_SHADER_COMPILATION_FAILED); + } + if (errors_or_warnings) { + _SG_WARN(D3D11_SHADER_COMPILATION_OUTPUT); + _SG_LOGMSG(D3D11_SHADER_COMPILATION_OUTPUT, (LPCSTR)_sg_d3d11_GetBufferPointer(errors_or_warnings)); + _sg_d3d11_Release(errors_or_warnings); errors_or_warnings = NULL; + } + if (FAILED(hr)) { + // just in case, usually output is NULL here + if (output) { + _sg_d3d11_Release(output); + output = NULL; + } + } + return output; +} + +// NOTE: this is an out-of-range check for HLSL bindslots that's also active in release mode +_SOKOL_PRIVATE bool _sg_d3d11_ensure_hlsl_bindslot_ranges(const sg_shader_desc* desc) { + SOKOL_ASSERT(desc); + for (size_t i = 0; i < SG_MAX_UNIFORMBLOCK_BINDSLOTS; i++) { + const sg_shader_uniform_block* ub = &desc->uniform_blocks[i]; + if (ub->stage != SG_SHADERSTAGE_NONE) { + if (ub->hlsl_register_b_n >= _SG_D3D11_MAX_STAGE_UB_BINDINGS) { + _SG_ERROR(D3D11_UNIFORMBLOCK_HLSL_REGISTER_B_OUT_OF_RANGE); + return false; + } + } + } + for (size_t i = 0; i < SG_MAX_VIEW_BINDSLOTS; i++) { + const sg_shader_view* view = &desc->views[i]; + if (view->texture.stage != SG_SHADERSTAGE_NONE) { + if (view->texture.hlsl_register_t_n >= _SG_D3D11_MAX_STAGE_SRV_BINDINGS) { + _SG_ERROR(D3D11_IMAGE_HLSL_REGISTER_T_OUT_OF_RANGE); + return false; + } + } + if (view->storage_buffer.stage != SG_SHADERSTAGE_NONE) { + if (view->storage_buffer.hlsl_register_t_n >= _SG_D3D11_MAX_STAGE_SRV_BINDINGS) { + _SG_ERROR(D3D11_STORAGEBUFFER_HLSL_REGISTER_T_OUT_OF_RANGE); + return false; + } + if (view->storage_buffer.hlsl_register_u_n >= _SG_D3D11_MAX_STAGE_UAV_BINDINGS) { + _SG_ERROR(D3D11_STORAGEBUFFER_HLSL_REGISTER_U_OUT_OF_RANGE); + return false; + } + } + if (view->storage_image.stage != SG_SHADERSTAGE_NONE) { + if (view->storage_image.hlsl_register_u_n >= _SG_D3D11_MAX_STAGE_UAV_BINDINGS) { + _SG_ERROR(D3D11_STORAGEIMAGE_HLSL_REGISTER_U_OUT_OF_RANGE); + return false; + } + } + } + for (size_t i = 0; i < SG_MAX_SAMPLER_BINDSLOTS; i++) { + const sg_shader_sampler* smp = &desc->samplers[i]; + if (smp->stage != SG_SHADERSTAGE_NONE) { + if (smp->hlsl_register_s_n >= _SG_D3D11_MAX_STAGE_SMP_BINDINGS) { + _SG_ERROR(D3D11_SAMPLER_HLSL_REGISTER_S_OUT_OF_RANGE); + return false; + } + } + } + return true; +} + +_SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_shader(_sg_shader_t* shd, const sg_shader_desc* desc) { + SOKOL_ASSERT(shd && desc); + SOKOL_ASSERT(!shd->d3d11.vs && !shd->d3d11.fs && !shd->d3d11.cs && !shd->d3d11.vs_blob); + HRESULT hr; + + // perform a range-check on HLSL bindslots that's also active in release + // mode to avoid potential out-of-bounds array accesses + if (!_sg_d3d11_ensure_hlsl_bindslot_ranges(desc)) { + return SG_RESOURCESTATE_FAILED; + } + + // copy vertex attribute semantic names and indices + for (size_t i = 0; i < SG_MAX_VERTEX_ATTRIBUTES; i++) { + _sg_strcpy(&shd->d3d11.attrs[i].sem_name, desc->attrs[i].hlsl_sem_name); + shd->d3d11.attrs[i].sem_index = desc->attrs[i].hlsl_sem_index; + } + + // copy HLSL bind slots + for (size_t i = 0; i < SG_MAX_UNIFORMBLOCK_BINDSLOTS; i++) { + SOKOL_ASSERT(0 == shd->d3d11.ub_register_b_n[i]); + shd->d3d11.ub_register_b_n[i] = desc->uniform_blocks[i].hlsl_register_b_n; + } + for (size_t i = 0; i < SG_MAX_VIEW_BINDSLOTS; i++) { + const sg_shader_view* view = &desc->views[i]; + SOKOL_ASSERT((0 == shd->d3d11.view_register_t_n[i]) && (0 == shd->d3d11.view_register_u_n[i])); + if (view->storage_buffer.stage != SG_SHADERSTAGE_NONE) { + shd->d3d11.view_register_t_n[i] = view->storage_buffer.hlsl_register_t_n; + shd->d3d11.view_register_u_n[i] = view->storage_buffer.hlsl_register_u_n; + } else if (view->texture.stage != SG_SHADERSTAGE_NONE) { + shd->d3d11.view_register_t_n[i] = view->texture.hlsl_register_t_n; + } else if (view->storage_image.stage != SG_SHADERSTAGE_NONE) { + shd->d3d11.view_register_u_n[i] = view->storage_image.hlsl_register_u_n; + } + } + for (size_t i = 0; i < SG_MAX_SAMPLER_BINDSLOTS; i++) { + SOKOL_ASSERT(0 == shd->d3d11.smp_register_s_n[i]); + shd->d3d11.smp_register_s_n[i] = desc->samplers[i].hlsl_register_s_n; + } + + // create a D3D constant buffer for each uniform block + for (size_t ub_index = 0; ub_index < SG_MAX_UNIFORMBLOCK_BINDSLOTS; ub_index++) { + const sg_shader_stage stage = desc->uniform_blocks[ub_index].stage; + if (stage == SG_SHADERSTAGE_NONE) { + continue; + } + const _sg_shader_uniform_block_t* ub = &shd->cmn.uniform_blocks[ub_index]; + ID3D11Buffer* cbuf = 0; + _SG_STRUCT(D3D11_BUFFER_DESC, cb_desc); + cb_desc.ByteWidth = (UINT)_sg_roundup((int)ub->size, 16); + cb_desc.Usage = D3D11_USAGE_DEFAULT; + cb_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; + hr = _sg_d3d11_CreateBuffer(_sg.d3d11.dev, &cb_desc, NULL, &cbuf); + if (!(SUCCEEDED(hr) && cbuf)) { + _SG_ERROR(D3D11_CREATE_CONSTANT_BUFFER_FAILED); + return SG_RESOURCESTATE_FAILED; + } + _sg_d3d11_setlabel(cbuf, desc->label); + shd->d3d11.all_cbufs[ub_index] = cbuf; + + const uint8_t d3d11_slot = shd->d3d11.ub_register_b_n[ub_index]; + SOKOL_ASSERT(d3d11_slot < _SG_D3D11_MAX_STAGE_UB_BINDINGS); + if (stage == SG_SHADERSTAGE_VERTEX) { + SOKOL_ASSERT(0 == shd->d3d11.vs_cbufs[d3d11_slot]); + shd->d3d11.vs_cbufs[d3d11_slot] = cbuf; + } else if (stage == SG_SHADERSTAGE_FRAGMENT) { + SOKOL_ASSERT(0 == shd->d3d11.fs_cbufs[d3d11_slot]); + shd->d3d11.fs_cbufs[d3d11_slot] = cbuf; + } else if (stage == SG_SHADERSTAGE_COMPUTE) { + SOKOL_ASSERT(0 == shd->d3d11.cs_cbufs[d3d11_slot]); + shd->d3d11.cs_cbufs[d3d11_slot] = cbuf; + } else { + SOKOL_UNREACHABLE; + } + } + + // create shader functions + const bool has_vs = desc->vertex_func.bytecode.ptr || desc->vertex_func.source; + const bool has_fs = desc->fragment_func.bytecode.ptr || desc->fragment_func.source; + const bool has_cs = desc->compute_func.bytecode.ptr || desc->compute_func.source; + bool vs_valid = false; bool fs_valid = false; bool cs_valid = false; + if (has_vs) { + const void* vs_ptr = 0; SIZE_T vs_length = 0; + ID3DBlob* vs_blob = 0; + if (desc->vertex_func.bytecode.ptr) { + SOKOL_ASSERT(desc->vertex_func.bytecode.size > 0); + vs_ptr = desc->vertex_func.bytecode.ptr; + vs_length = desc->vertex_func.bytecode.size; + } else { + SOKOL_ASSERT(desc->vertex_func.source); + vs_blob = _sg_d3d11_compile_shader(&desc->vertex_func); + if (vs_blob) { + vs_ptr = _sg_d3d11_GetBufferPointer(vs_blob); + vs_length = _sg_d3d11_GetBufferSize(vs_blob); + } + } + if (vs_ptr && (vs_length > 0)) { + hr = _sg_d3d11_CreateVertexShader(_sg.d3d11.dev, vs_ptr, vs_length, NULL, &shd->d3d11.vs); + vs_valid = SUCCEEDED(hr) && shd->d3d11.vs; + } + // set label, and need to store a copy of the vertex shader blob for the pipeline creation + if (vs_valid) { + _sg_d3d11_setlabel(shd->d3d11.vs, desc->label); + shd->d3d11.vs_blob_length = vs_length; + shd->d3d11.vs_blob = _sg_malloc((size_t)vs_length); + SOKOL_ASSERT(shd->d3d11.vs_blob); + memcpy(shd->d3d11.vs_blob, vs_ptr, vs_length); + } + if (vs_blob) { + _sg_d3d11_Release(vs_blob); + } + } + if (has_fs) { + const void* fs_ptr = 0; SIZE_T fs_length = 0; + ID3DBlob* fs_blob = 0; + if (desc->fragment_func.bytecode.ptr) { + SOKOL_ASSERT(desc->fragment_func.bytecode.size > 0); + fs_ptr = desc->fragment_func.bytecode.ptr; + fs_length = desc->fragment_func.bytecode.size; + } else { + SOKOL_ASSERT(desc->fragment_func.source); + fs_blob = _sg_d3d11_compile_shader(&desc->fragment_func); + if (fs_blob) { + fs_ptr = _sg_d3d11_GetBufferPointer(fs_blob); + fs_length = _sg_d3d11_GetBufferSize(fs_blob); + } + } + if (fs_ptr && (fs_length > 0)) { + hr = _sg_d3d11_CreatePixelShader(_sg.d3d11.dev, fs_ptr, fs_length, NULL, &shd->d3d11.fs); + fs_valid = SUCCEEDED(hr) && shd->d3d11.fs; + } + if (fs_valid) { + _sg_d3d11_setlabel(shd->d3d11.fs, desc->label); + } + if (fs_blob) { + _sg_d3d11_Release(fs_blob); + } + } + if (has_cs) { + const void* cs_ptr = 0; SIZE_T cs_length = 0; + ID3DBlob* cs_blob = 0; + if (desc->compute_func.bytecode.ptr) { + SOKOL_ASSERT(desc->compute_func.bytecode.size > 0); + cs_ptr = desc->compute_func.bytecode.ptr; + cs_length = desc->compute_func.bytecode.size; + } else { + SOKOL_ASSERT(desc->compute_func.source); + cs_blob = _sg_d3d11_compile_shader(&desc->compute_func); + if (cs_blob) { + cs_ptr = _sg_d3d11_GetBufferPointer(cs_blob); + cs_length = _sg_d3d11_GetBufferSize(cs_blob); + } + } + if (cs_ptr && (cs_length > 0)) { + hr = _sg_d3d11_CreateComputeShader(_sg.d3d11.dev, cs_ptr, cs_length, NULL, &shd->d3d11.cs); + cs_valid = SUCCEEDED(hr) && shd->d3d11.cs; + } + if (cs_blob) { + _sg_d3d11_Release(cs_blob); + } + } + if ((vs_valid && fs_valid) || cs_valid) { + return SG_RESOURCESTATE_VALID; + } else { + return SG_RESOURCESTATE_FAILED; + } +} + +_SOKOL_PRIVATE void _sg_d3d11_discard_shader(_sg_shader_t* shd) { + SOKOL_ASSERT(shd); + if (shd->d3d11.vs) { + _sg_d3d11_Release(shd->d3d11.vs); + } + if (shd->d3d11.fs) { + _sg_d3d11_Release(shd->d3d11.fs); + } + if (shd->d3d11.cs) { + _sg_d3d11_Release(shd->d3d11.cs); + } + if (shd->d3d11.vs_blob) { + _sg_free(shd->d3d11.vs_blob); + } + for (size_t i = 0; i < SG_MAX_UNIFORMBLOCK_BINDSLOTS; i++) { + if (shd->d3d11.all_cbufs[i]) { + _sg_d3d11_Release(shd->d3d11.all_cbufs[i]); + } + } +} + +_SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_pipeline(_sg_pipeline_t* pip, const sg_pipeline_desc* desc) { + SOKOL_ASSERT(pip && desc); + _sg_shader_t* shd = _sg_shader_ref_ptr(&pip->cmn.shader); + + // if this is a compute pipeline, we're done here + if (pip->cmn.is_compute) { + return SG_RESOURCESTATE_VALID; + } + + // a render pipeline... + SOKOL_ASSERT(shd->d3d11.vs_blob && shd->d3d11.vs_blob_length > 0); + SOKOL_ASSERT(!pip->d3d11.il && !pip->d3d11.rs && !pip->d3d11.dss && !pip->d3d11.bs); + + pip->d3d11.index_format = _sg_d3d11_index_format(pip->cmn.index_type); + pip->d3d11.topology = _sg_d3d11_primitive_topology(desc->primitive_type); + pip->d3d11.stencil_ref = desc->stencil.ref; + + // create input layout object + HRESULT hr; + _SG_STRUCT(D3D11_INPUT_ELEMENT_DESC, d3d11_comps[SG_MAX_VERTEX_ATTRIBUTES]); + size_t attr_index = 0; + for (; attr_index < SG_MAX_VERTEX_ATTRIBUTES; attr_index++) { + const sg_vertex_attr_state* a_state = &desc->layout.attrs[attr_index]; + if (a_state->format == SG_VERTEXFORMAT_INVALID) { + break; + } + SOKOL_ASSERT(a_state->buffer_index < SG_MAX_VERTEXBUFFER_BINDSLOTS); + SOKOL_ASSERT(pip->cmn.vertex_buffer_layout_active[a_state->buffer_index]); + const sg_vertex_buffer_layout_state* l_state = &desc->layout.buffers[a_state->buffer_index]; + const sg_vertex_step step_func = l_state->step_func; + const int step_rate = l_state->step_rate; + D3D11_INPUT_ELEMENT_DESC* d3d11_comp = &d3d11_comps[attr_index]; + d3d11_comp->SemanticName = _sg_strptr(&shd->d3d11.attrs[attr_index].sem_name); + d3d11_comp->SemanticIndex = (UINT)shd->d3d11.attrs[attr_index].sem_index; + d3d11_comp->Format = _sg_d3d11_vertex_format(a_state->format); + d3d11_comp->InputSlot = (UINT)a_state->buffer_index; + d3d11_comp->AlignedByteOffset = (UINT)a_state->offset; + d3d11_comp->InputSlotClass = _sg_d3d11_input_classification(step_func); + if (SG_VERTEXSTEP_PER_INSTANCE == step_func) { + d3d11_comp->InstanceDataStepRate = (UINT)step_rate; + } + } + for (size_t layout_index = 0; layout_index < SG_MAX_VERTEXBUFFER_BINDSLOTS; layout_index++) { + if (pip->cmn.vertex_buffer_layout_active[layout_index]) { + const sg_vertex_buffer_layout_state* l_state = &desc->layout.buffers[layout_index]; + SOKOL_ASSERT(l_state->stride > 0); + pip->d3d11.vb_strides[layout_index] = (UINT)l_state->stride; + } else { + pip->d3d11.vb_strides[layout_index] = 0; + } + } + if (attr_index > 0) { + hr = _sg_d3d11_CreateInputLayout(_sg.d3d11.dev, + d3d11_comps, // pInputElementDesc + (UINT)attr_index, // NumElements + shd->d3d11.vs_blob, // pShaderByteCodeWithInputSignature + shd->d3d11.vs_blob_length, // BytecodeLength + &pip->d3d11.il); + if (!(SUCCEEDED(hr) && pip->d3d11.il)) { + _SG_ERROR(D3D11_CREATE_INPUT_LAYOUT_FAILED); + return SG_RESOURCESTATE_FAILED; + } + _sg_d3d11_setlabel(pip->d3d11.il, desc->label); + } + + // create rasterizer state + _SG_STRUCT(D3D11_RASTERIZER_DESC, rs_desc); + rs_desc.FillMode = D3D11_FILL_SOLID; + rs_desc.CullMode = _sg_d3d11_cull_mode(desc->cull_mode); + rs_desc.FrontCounterClockwise = desc->face_winding == SG_FACEWINDING_CCW; + rs_desc.DepthBias = (INT) pip->cmn.depth.bias; + rs_desc.DepthBiasClamp = pip->cmn.depth.bias_clamp; + rs_desc.SlopeScaledDepthBias = pip->cmn.depth.bias_slope_scale; + rs_desc.DepthClipEnable = TRUE; + rs_desc.ScissorEnable = TRUE; + rs_desc.MultisampleEnable = desc->sample_count > 1; + rs_desc.AntialiasedLineEnable = FALSE; + hr = _sg_d3d11_CreateRasterizerState(_sg.d3d11.dev, &rs_desc, &pip->d3d11.rs); + if (!(SUCCEEDED(hr) && pip->d3d11.rs)) { + _SG_ERROR(D3D11_CREATE_RASTERIZER_STATE_FAILED); + return SG_RESOURCESTATE_FAILED; + } + _sg_d3d11_setlabel(pip->d3d11.rs, desc->label); + + // create depth-stencil state + _SG_STRUCT(D3D11_DEPTH_STENCIL_DESC, dss_desc); + dss_desc.DepthEnable = TRUE; + dss_desc.DepthWriteMask = desc->depth.write_enabled ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO; + dss_desc.DepthFunc = _sg_d3d11_compare_func(desc->depth.compare); + dss_desc.StencilEnable = desc->stencil.enabled; + dss_desc.StencilReadMask = desc->stencil.read_mask; + dss_desc.StencilWriteMask = desc->stencil.write_mask; + const sg_stencil_face_state* sf = &desc->stencil.front; + dss_desc.FrontFace.StencilFailOp = _sg_d3d11_stencil_op(sf->fail_op); + dss_desc.FrontFace.StencilDepthFailOp = _sg_d3d11_stencil_op(sf->depth_fail_op); + dss_desc.FrontFace.StencilPassOp = _sg_d3d11_stencil_op(sf->pass_op); + dss_desc.FrontFace.StencilFunc = _sg_d3d11_compare_func(sf->compare); + const sg_stencil_face_state* sb = &desc->stencil.back; + dss_desc.BackFace.StencilFailOp = _sg_d3d11_stencil_op(sb->fail_op); + dss_desc.BackFace.StencilDepthFailOp = _sg_d3d11_stencil_op(sb->depth_fail_op); + dss_desc.BackFace.StencilPassOp = _sg_d3d11_stencil_op(sb->pass_op); + dss_desc.BackFace.StencilFunc = _sg_d3d11_compare_func(sb->compare); + hr = _sg_d3d11_CreateDepthStencilState(_sg.d3d11.dev, &dss_desc, &pip->d3d11.dss); + if (!(SUCCEEDED(hr) && pip->d3d11.dss)) { + _SG_ERROR(D3D11_CREATE_DEPTH_STENCIL_STATE_FAILED); + return SG_RESOURCESTATE_FAILED; + } + _sg_d3d11_setlabel(pip->d3d11.dss, desc->label); + + // create blend state + _SG_STRUCT(D3D11_BLEND_DESC, bs_desc); + bs_desc.AlphaToCoverageEnable = desc->alpha_to_coverage_enabled; + bs_desc.IndependentBlendEnable = TRUE; + { + size_t i = 0; + for (i = 0; i < (size_t)desc->color_count; i++) { + const sg_blend_state* src = &desc->colors[i].blend; + D3D11_RENDER_TARGET_BLEND_DESC* dst = &bs_desc.RenderTarget[i]; + dst->BlendEnable = src->enabled; + dst->SrcBlend = _sg_d3d11_blend_factor(src->src_factor_rgb); + dst->DestBlend = _sg_d3d11_blend_factor(src->dst_factor_rgb); + dst->BlendOp = _sg_d3d11_blend_op(src->op_rgb); + dst->SrcBlendAlpha = _sg_d3d11_blend_factor(src->src_factor_alpha); + dst->DestBlendAlpha = _sg_d3d11_blend_factor(src->dst_factor_alpha); + dst->BlendOpAlpha = _sg_d3d11_blend_op(src->op_alpha); + dst->RenderTargetWriteMask = _sg_d3d11_color_write_mask(desc->colors[i].write_mask); + } + for (; i < 8; i++) { + D3D11_RENDER_TARGET_BLEND_DESC* dst = &bs_desc.RenderTarget[i]; + dst->BlendEnable = FALSE; + dst->SrcBlend = dst->SrcBlendAlpha = D3D11_BLEND_ONE; + dst->DestBlend = dst->DestBlendAlpha = D3D11_BLEND_ZERO; + dst->BlendOp = dst->BlendOpAlpha = D3D11_BLEND_OP_ADD; + dst->RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; + } + } + hr = _sg_d3d11_CreateBlendState(_sg.d3d11.dev, &bs_desc, &pip->d3d11.bs); + if (!(SUCCEEDED(hr) && pip->d3d11.bs)) { + _SG_ERROR(D3D11_CREATE_BLEND_STATE_FAILED); + return SG_RESOURCESTATE_FAILED; + } + _sg_d3d11_setlabel(pip->d3d11.bs, desc->label); + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_d3d11_discard_pipeline(_sg_pipeline_t* pip) { + SOKOL_ASSERT(pip); + if (pip->d3d11.il) { + _sg_d3d11_Release(pip->d3d11.il); + } + if (pip->d3d11.rs) { + _sg_d3d11_Release(pip->d3d11.rs); + } + if (pip->d3d11.dss) { + _sg_d3d11_Release(pip->d3d11.dss); + } + if (pip->d3d11.bs) { + _sg_d3d11_Release(pip->d3d11.bs); + } +} + +_SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_view(_sg_view_t* view, const sg_view_desc* desc) { + SOKOL_ASSERT(view && desc); + _SOKOL_UNUSED(desc); + HRESULT hr; + if (view->cmn.type == SG_VIEWTYPE_STORAGEBUFFER) { + const _sg_buffer_t* buf = _sg_buffer_ref_ptr(&view->cmn.buf.ref); + SOKOL_ASSERT(buf->d3d11.buf); + const UINT size = (UINT) buf->cmn.size; + SOKOL_ASSERT(_sg_multiple_u64(size, 4)); + const UINT offset = (UINT) view->cmn.buf.offset; + SOKOL_ASSERT(_sg_multiple_u64(offset, 4)); + SOKOL_ASSERT(offset < size); + const UINT first_element = offset / 4; + const UINT num_elements = (size - offset) / 4; + _SG_STRUCT(D3D11_SHADER_RESOURCE_VIEW_DESC, d3d11_srv_desc); + d3d11_srv_desc.Format = DXGI_FORMAT_R32_TYPELESS; + d3d11_srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX; + d3d11_srv_desc.BufferEx.FirstElement = first_element; + d3d11_srv_desc.BufferEx.NumElements = num_elements; + d3d11_srv_desc.BufferEx.Flags = D3D11_BUFFEREX_SRV_FLAG_RAW; + SOKOL_ASSERT(!view->d3d11.srv); + hr = _sg_d3d11_CreateShaderResourceView(_sg.d3d11.dev, (ID3D11Resource*)buf->d3d11.buf, &d3d11_srv_desc, &view->d3d11.srv); + if (!(SUCCEEDED(hr) && view->d3d11.srv)) { + _SG_ERROR(D3D11_CREATE_BUFFER_SRV_FAILED); + return SG_RESOURCESTATE_FAILED; + } + _sg_d3d11_setlabel(view->d3d11.srv, desc->label); + if (buf->cmn.usage.immutable) { + _SG_STRUCT(D3D11_UNORDERED_ACCESS_VIEW_DESC, d3d11_uav_desc); + d3d11_uav_desc.Format = DXGI_FORMAT_R32_TYPELESS; + d3d11_uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER; + d3d11_uav_desc.Buffer.FirstElement = first_element; + d3d11_uav_desc.Buffer.NumElements = num_elements; + d3d11_uav_desc.Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW; + SOKOL_ASSERT(!view->d3d11.uav); + hr = _sg_d3d11_CreateUnorderedAccessView(_sg.d3d11.dev, (ID3D11Resource*)buf->d3d11.buf, &d3d11_uav_desc, &view->d3d11.uav); + if (!(SUCCEEDED(hr) && view->d3d11.uav)) { + _SG_ERROR(D3D11_CREATE_BUFFER_UAV_FAILED); + return SG_RESOURCESTATE_FAILED; + } + _sg_d3d11_setlabel(view->d3d11.uav, desc->label); + } + } else { + // it's an image view + const _sg_image_t* img = _sg_image_ref_ptr(&view->cmn.img.ref); + SOKOL_ASSERT(img->d3d11.res); + const bool msaa = img->cmn.sample_count > 1; + SOKOL_ASSERT(view->cmn.img.mip_level_count >= 1); + SOKOL_ASSERT(view->cmn.img.slice_count >= 1); + const UINT mip_level = (UINT)view->cmn.img.mip_level; + const UINT mip_count = (UINT)view->cmn.img.mip_level_count; + const UINT slice = (UINT)view->cmn.img.slice; + const UINT slice_count = (UINT)view->cmn.img.slice_count; + + if (view->cmn.type == SG_VIEWTYPE_STORAGEIMAGE) { + SOKOL_ASSERT(!msaa); + _SG_STRUCT(D3D11_UNORDERED_ACCESS_VIEW_DESC, d3d11_uav_desc); + d3d11_uav_desc.Format = _sg_d3d11_rtv_uav_pixel_format(img->cmn.pixel_format); + switch (img->cmn.type) { + case SG_IMAGETYPE_2D: + d3d11_uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D; + d3d11_uav_desc.Texture2D.MipSlice = mip_level; + break; + case SG_IMAGETYPE_CUBE: + case SG_IMAGETYPE_ARRAY: + d3d11_uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2DARRAY; + d3d11_uav_desc.Texture2DArray.MipSlice = mip_level; + d3d11_uav_desc.Texture2DArray.FirstArraySlice = slice; + d3d11_uav_desc.Texture2DArray.ArraySize = 1; + break; + case SG_IMAGETYPE_3D: + d3d11_uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE3D; + d3d11_uav_desc.Texture3D.MipSlice = mip_level; + d3d11_uav_desc.Texture3D.FirstWSlice = slice; + d3d11_uav_desc.Texture3D.WSize = 1; + break; + default: SOKOL_UNREACHABLE; break; + } + hr = _sg_d3d11_CreateUnorderedAccessView(_sg.d3d11.dev, img->d3d11.res, &d3d11_uav_desc, &view->d3d11.uav); + if (!(SUCCEEDED(hr) && view->d3d11.uav)) { + _SG_ERROR(D3D11_CREATE_UAV_FAILED); + return SG_RESOURCESTATE_FAILED; + } + _sg_d3d11_setlabel(view->d3d11.uav, desc->label); + + } else if (view->cmn.type == SG_VIEWTYPE_TEXTURE) { + + _SG_STRUCT(D3D11_SHADER_RESOURCE_VIEW_DESC, d3d11_srv_desc); + d3d11_srv_desc.Format = _sg_d3d11_srv_pixel_format(img->cmn.pixel_format); + switch (img->cmn.type) { + case SG_IMAGETYPE_2D: + if (msaa) { + d3d11_srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMS; + } else { + d3d11_srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; + d3d11_srv_desc.Texture2D.MostDetailedMip = mip_level; + d3d11_srv_desc.Texture2D.MipLevels = mip_count; + } + break; + case SG_IMAGETYPE_CUBE: + SOKOL_ASSERT(!msaa); + d3d11_srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE; + d3d11_srv_desc.TextureCube.MostDetailedMip = mip_level; + d3d11_srv_desc.TextureCube.MipLevels = mip_count; + break; + case SG_IMAGETYPE_ARRAY: + if (msaa) { + // NOTE: _sg_validate_image_desc() currently disallows MSAA array textures + d3d11_srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY; + d3d11_srv_desc.Texture2DMSArray.FirstArraySlice = slice; + d3d11_srv_desc.Texture2DMSArray.ArraySize = slice_count; + } else { + d3d11_srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY; + d3d11_srv_desc.Texture2DArray.MostDetailedMip = mip_level; + d3d11_srv_desc.Texture2DArray.MipLevels = mip_count; + d3d11_srv_desc.Texture2DArray.FirstArraySlice = slice; + d3d11_srv_desc.Texture2DArray.ArraySize = slice_count; + } + break; + case SG_IMAGETYPE_3D: + SOKOL_ASSERT(!msaa); + d3d11_srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D; + d3d11_srv_desc.Texture3D.MostDetailedMip = mip_level; + d3d11_srv_desc.Texture3D.MipLevels = mip_count; + break; + default: + SOKOL_UNREACHABLE; break; + } + hr = _sg_d3d11_CreateShaderResourceView(_sg.d3d11.dev, img->d3d11.res, &d3d11_srv_desc, &view->d3d11.srv); + if (!(SUCCEEDED(hr) && view->d3d11.srv)) { + _SG_ERROR(D3D11_CREATE_2D_SRV_FAILED); + return SG_RESOURCESTATE_FAILED; + } + _sg_d3d11_setlabel(view->d3d11.srv, desc->label); + + } else if (view->cmn.type == SG_VIEWTYPE_COLORATTACHMENT) { + + _SG_STRUCT(D3D11_RENDER_TARGET_VIEW_DESC, d3d11_rtv_desc); + d3d11_rtv_desc.Format = _sg_d3d11_rtv_uav_pixel_format(img->cmn.pixel_format); + switch (img->cmn.type) { + case SG_IMAGETYPE_2D: + if (msaa) { + d3d11_rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS; + } else { + d3d11_rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; + d3d11_rtv_desc.Texture2D.MipSlice = mip_level; + } + break; + case SG_IMAGETYPE_CUBE: + case SG_IMAGETYPE_ARRAY: + if (msaa) { + d3d11_rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY; + d3d11_rtv_desc.Texture2DMSArray.FirstArraySlice = slice; + d3d11_rtv_desc.Texture2DMSArray.ArraySize = 1; + } else { + d3d11_rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY; + d3d11_rtv_desc.Texture2DArray.MipSlice = mip_level; + d3d11_rtv_desc.Texture2DArray.FirstArraySlice = slice; + d3d11_rtv_desc.Texture2DArray.ArraySize = 1; + } + break; + case SG_IMAGETYPE_3D: + SOKOL_ASSERT(!msaa); + d3d11_rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D; + d3d11_rtv_desc.Texture3D.MipSlice = mip_level; + d3d11_rtv_desc.Texture3D.FirstWSlice = slice; + d3d11_rtv_desc.Texture3D.WSize = 1; + break; + default: SOKOL_UNREACHABLE; break; + } + hr = _sg_d3d11_CreateRenderTargetView(_sg.d3d11.dev, img->d3d11.res, &d3d11_rtv_desc, &view->d3d11.rtv); + if (!(SUCCEEDED(hr) && view->d3d11.rtv)) { + _SG_ERROR(D3D11_CREATE_RTV_FAILED); + return SG_RESOURCESTATE_FAILED; + } + _sg_d3d11_setlabel(view->d3d11.rtv, desc->label); + + } else if (view->cmn.type == SG_VIEWTYPE_DEPTHSTENCILATTACHMENT) { + + SOKOL_ASSERT(img->cmn.type != SG_IMAGETYPE_3D); + _SG_STRUCT(D3D11_DEPTH_STENCIL_VIEW_DESC, d3d11_dsv_desc); + d3d11_dsv_desc.Format = _sg_d3d11_dsv_pixel_format(img->cmn.pixel_format); + switch (img->cmn.type) { + case SG_IMAGETYPE_2D: + if (msaa) { + d3d11_dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMS; + } else { + d3d11_dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; + d3d11_dsv_desc.Texture2D.MipSlice = mip_level; + } + break; + case SG_IMAGETYPE_CUBE: + case SG_IMAGETYPE_ARRAY: + if (msaa) { + d3d11_dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY; + d3d11_dsv_desc.Texture2DMSArray.FirstArraySlice = slice; + d3d11_dsv_desc.Texture2DMSArray.ArraySize = 1; + } else { + d3d11_dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY; + d3d11_dsv_desc.Texture2DArray.MipSlice = mip_level; + d3d11_dsv_desc.Texture2DArray.FirstArraySlice = slice; + d3d11_dsv_desc.Texture2DArray.ArraySize = 1; + } + break; + default: SOKOL_UNREACHABLE; break; + } + hr = _sg_d3d11_CreateDepthStencilView(_sg.d3d11.dev, img->d3d11.res, &d3d11_dsv_desc, &view->d3d11.dsv); + if (!(SUCCEEDED(hr) && view->d3d11.dsv)) { + _SG_ERROR(D3D11_CREATE_DSV_FAILED); + return SG_RESOURCESTATE_FAILED; + } + _sg_d3d11_setlabel(view->d3d11.dsv, desc->label); + } + } + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_d3d11_discard_view(_sg_view_t* view) { + SOKOL_ASSERT(view); + if (view->d3d11.srv) { + _sg_d3d11_Release(view->d3d11.srv); + } + if (view->d3d11.uav) { + _sg_d3d11_Release(view->d3d11.uav); + } + if (view->d3d11.rtv) { + _sg_d3d11_Release(view->d3d11.rtv); + } + if (view->d3d11.dsv) { + _sg_d3d11_Release(view->d3d11.dsv); + } +} + +_SOKOL_PRIVATE void _sg_d3d11_begin_pass(const sg_pass* pass, const _sg_attachments_ptrs_t* atts) { + SOKOL_ASSERT(_sg.d3d11.ctx && pass && atts); + if (_sg.cur_pass.is_compute) { + // nothing to do in compute passes + return; + } + int num_rtvs = 0; + ID3D11RenderTargetView* rtvs[SG_MAX_COLOR_ATTACHMENTS] = { 0 }; + ID3D11DepthStencilView* dsv = 0; + _sg.d3d11.cur_swapchain.render_view = 0; + _sg.d3d11.cur_swapchain.resolve_view = 0; + if (!atts->empty) { + SOKOL_ASSERT(atts->num_color_views <= SG_MAX_COLOR_ATTACHMENTS); + num_rtvs = atts->num_color_views; + for (int i = 0; i < num_rtvs; i++) { + SOKOL_ASSERT(atts->color_views[i]); + SOKOL_ASSERT(atts->color_views[i]->d3d11.rtv); + rtvs[i] = atts->color_views[i]->d3d11.rtv; + } + if (atts->ds_view) { + SOKOL_ASSERT(atts->ds_view->d3d11.dsv); + dsv = atts->ds_view->d3d11.dsv; + } + } else { + // NOTE: swapchain depth-stencil-view is optional + const sg_swapchain* swapchain = &pass->swapchain; + SOKOL_ASSERT(swapchain->d3d11.render_view); + num_rtvs = 1; + rtvs[0] = (ID3D11RenderTargetView*) swapchain->d3d11.render_view; + dsv = (ID3D11DepthStencilView*) swapchain->d3d11.depth_stencil_view; + _sg.d3d11.cur_swapchain.render_view = (ID3D11RenderTargetView*) swapchain->d3d11.render_view; + _sg.d3d11.cur_swapchain.resolve_view = (ID3D11RenderTargetView*) swapchain->d3d11.resolve_view; + } + // apply the render-target- and depth-stencil-views + _sg_d3d11_OMSetRenderTargets(_sg.d3d11.ctx, SG_MAX_COLOR_ATTACHMENTS, rtvs, dsv); + _sg_stats_inc(d3d11.pass.num_om_set_render_targets); + + // set viewport and scissor rect to cover whole screen + _SG_STRUCT(D3D11_VIEWPORT, vp); + vp.Width = (FLOAT) _sg.cur_pass.dim.width; + vp.Height = (FLOAT) _sg.cur_pass.dim.height; + vp.MaxDepth = 1.0f; + _sg_d3d11_RSSetViewports(_sg.d3d11.ctx, 1, &vp); + D3D11_RECT rect; + rect.left = 0; + rect.top = 0; + rect.right = _sg.cur_pass.dim.width; + rect.bottom = _sg.cur_pass.dim.height; + _sg_d3d11_RSSetScissorRects(_sg.d3d11.ctx, 1, &rect); + + // perform clear action + const sg_pass_action* action = &pass->action; + for (size_t i = 0; i < (size_t)num_rtvs; i++) { + if (action->colors[i].load_action == SG_LOADACTION_CLEAR) { + _sg_d3d11_ClearRenderTargetView(_sg.d3d11.ctx, rtvs[i], (float*)&action->colors[i].clear_value); + _sg_stats_inc(d3d11.pass.num_clear_render_target_view); + } + } + UINT ds_flags = 0; + if (action->depth.load_action == SG_LOADACTION_CLEAR) { + ds_flags |= D3D11_CLEAR_DEPTH; + } + if (action->stencil.load_action == SG_LOADACTION_CLEAR) { + ds_flags |= D3D11_CLEAR_STENCIL; + } + if ((0 != ds_flags) && dsv) { + _sg_d3d11_ClearDepthStencilView(_sg.d3d11.ctx, dsv, ds_flags, action->depth.clear_value, action->stencil.clear_value); + _sg_stats_inc(d3d11.pass.num_clear_depth_stencil_view); + } +} + +// D3D11CalcSubresource only exists for C++ +_SOKOL_PRIVATE UINT _sg_d3d11_calcsubresource(UINT mip_slice, UINT array_slice, UINT mip_levels) { + return mip_slice + array_slice * mip_levels; +} + +_SOKOL_PRIVATE void _sg_d3d11_end_pass(const _sg_attachments_ptrs_t* atts) { + SOKOL_ASSERT(_sg.d3d11.ctx && atts); + + if (!_sg.cur_pass.is_compute) { + // need to resolve MSAA render attachments into texture? + if (!atts->empty) { + // ...for offscreen pass... + for (int i = 0; i < atts->num_color_views; i++) { + const _sg_view_t* resolve_view = atts->resolve_views[i]; + if (resolve_view) { + const _sg_image_t* resolve_img = _sg_image_ref_ptr(&resolve_view->cmn.img.ref); + const _sg_view_t* color_view = atts->color_views[i]; + SOKOL_ASSERT(color_view); + const _sg_image_t* color_img = _sg_image_ref_ptr(&color_view->cmn.img.ref); + SOKOL_ASSERT(color_img->cmn.sample_count > 1); + SOKOL_ASSERT(resolve_img->cmn.sample_count == 1); + const UINT src_subres = _sg_d3d11_calcsubresource( + (UINT)color_view->cmn.img.mip_level, + (UINT)color_view->cmn.img.slice, + (UINT)color_img->cmn.num_mipmaps); + const UINT dst_subres = _sg_d3d11_calcsubresource( + (UINT)resolve_view->cmn.img.mip_level, + (UINT)resolve_view->cmn.img.slice, + (UINT)resolve_img->cmn.num_mipmaps); + _sg_d3d11_ResolveSubresource(_sg.d3d11.ctx, + resolve_img->d3d11.res, + dst_subres, + color_img->d3d11.res, + src_subres, + color_img->d3d11.format); + _sg_stats_inc(d3d11.pass.num_resolve_subresource); + } + } + } else { + // ...for swapchain pass... + if (_sg.d3d11.cur_swapchain.resolve_view) { + SOKOL_ASSERT(_sg.d3d11.cur_swapchain.render_view); + SOKOL_ASSERT(_sg.cur_pass.swapchain.sample_count > 1); + SOKOL_ASSERT(_sg.cur_pass.swapchain.color_fmt > SG_PIXELFORMAT_NONE); + ID3D11Resource* d3d11_render_res = 0; + ID3D11Resource* d3d11_resolve_res = 0; + _sg_d3d11_GetResource((ID3D11View*)_sg.d3d11.cur_swapchain.render_view, &d3d11_render_res); + _sg_d3d11_GetResource((ID3D11View*)_sg.d3d11.cur_swapchain.resolve_view, &d3d11_resolve_res); + SOKOL_ASSERT(d3d11_render_res); + SOKOL_ASSERT(d3d11_resolve_res); + const sg_pixel_format color_fmt = _sg.cur_pass.swapchain.color_fmt; + _sg_d3d11_ResolveSubresource(_sg.d3d11.ctx, d3d11_resolve_res, 0, d3d11_render_res, 0, _sg_d3d11_rtv_uav_pixel_format(color_fmt)); + _sg_d3d11_Release(d3d11_render_res); + _sg_d3d11_Release(d3d11_resolve_res); + _sg_stats_inc(d3d11.pass.num_resolve_subresource); + } + } + } + _sg.d3d11.cur_swapchain.render_view = 0; + _sg.d3d11.cur_swapchain.resolve_view = 0; + _sg_d3d11_clear_state(); +} + +_SOKOL_PRIVATE void _sg_d3d11_apply_viewport(int x, int y, int w, int h, bool origin_top_left) { + SOKOL_ASSERT(_sg.d3d11.ctx); + D3D11_VIEWPORT vp; + vp.TopLeftX = (FLOAT) x; + vp.TopLeftY = (FLOAT) (origin_top_left ? y : (_sg.cur_pass.dim.height - (y + h))); + vp.Width = (FLOAT) w; + vp.Height = (FLOAT) h; + vp.MinDepth = 0.0f; + vp.MaxDepth = 1.0f; + _sg_d3d11_RSSetViewports(_sg.d3d11.ctx, 1, &vp); +} + +_SOKOL_PRIVATE void _sg_d3d11_apply_scissor_rect(int x, int y, int w, int h, bool origin_top_left) { + SOKOL_ASSERT(_sg.d3d11.ctx); + D3D11_RECT rect; + rect.left = x; + rect.top = (origin_top_left ? y : (_sg.cur_pass.dim.height - (y + h))); + rect.right = x + w; + rect.bottom = origin_top_left ? (y + h) : (_sg.cur_pass.dim.height - y); + _sg_d3d11_RSSetScissorRects(_sg.d3d11.ctx, 1, &rect); +} + +_SOKOL_PRIVATE void _sg_d3d11_apply_pipeline(_sg_pipeline_t* pip) { + SOKOL_ASSERT(pip); + SOKOL_ASSERT(_sg.d3d11.ctx); + + const _sg_shader_t* shd = _sg_shader_ref_ptr(&pip->cmn.shader); + if (pip->cmn.is_compute) { + // a compute pipeline + SOKOL_ASSERT(shd->d3d11.cs); + _sg_d3d11_CSSetShader(_sg.d3d11.ctx, shd->d3d11.cs, NULL, 0); + _sg_d3d11_CSSetConstantBuffers(_sg.d3d11.ctx, 0, _SG_D3D11_MAX_STAGE_UB_BINDINGS, shd->d3d11.cs_cbufs); + _sg_stats_inc(d3d11.pipeline.num_cs_set_shader); + _sg_stats_inc(d3d11.pipeline.num_cs_set_constant_buffers); + } else { + // a render pipeline + SOKOL_ASSERT(pip->d3d11.rs && pip->d3d11.bs && pip->d3d11.dss); + SOKOL_ASSERT(shd->d3d11.vs); + SOKOL_ASSERT(shd->d3d11.fs); + + _sg_d3d11_RSSetState(_sg.d3d11.ctx, pip->d3d11.rs); + _sg_d3d11_OMSetDepthStencilState(_sg.d3d11.ctx, pip->d3d11.dss, pip->d3d11.stencil_ref); + _sg_d3d11_OMSetBlendState(_sg.d3d11.ctx, pip->d3d11.bs, (float*)&pip->cmn.blend_color, 0xFFFFFFFF); + _sg_d3d11_IASetPrimitiveTopology(_sg.d3d11.ctx, pip->d3d11.topology); + _sg_d3d11_IASetInputLayout(_sg.d3d11.ctx, pip->d3d11.il); + _sg_d3d11_VSSetShader(_sg.d3d11.ctx, shd->d3d11.vs, NULL, 0); + _sg_d3d11_VSSetConstantBuffers(_sg.d3d11.ctx, 0, _SG_D3D11_MAX_STAGE_UB_BINDINGS, shd->d3d11.vs_cbufs); + _sg_d3d11_PSSetShader(_sg.d3d11.ctx, shd->d3d11.fs, NULL, 0); + _sg_d3d11_PSSetConstantBuffers(_sg.d3d11.ctx, 0, _SG_D3D11_MAX_STAGE_UB_BINDINGS, shd->d3d11.fs_cbufs); + _sg_stats_inc(d3d11.pipeline.num_rs_set_state); + _sg_stats_inc(d3d11.pipeline.num_om_set_depth_stencil_state); + _sg_stats_inc(d3d11.pipeline.num_om_set_blend_state); + _sg_stats_inc(d3d11.pipeline.num_ia_set_primitive_topology); + _sg_stats_inc(d3d11.pipeline.num_ia_set_input_layout); + _sg_stats_inc(d3d11.pipeline.num_vs_set_shader); + _sg_stats_inc(d3d11.pipeline.num_vs_set_constant_buffers); + _sg_stats_inc(d3d11.pipeline.num_ps_set_shader); + _sg_stats_inc(d3d11.pipeline.num_ps_set_constant_buffers); + } +} + +_SOKOL_PRIVATE bool _sg_d3d11_apply_bindings(_sg_bindings_ptrs_t* bnd) { + SOKOL_ASSERT(bnd); + SOKOL_ASSERT(bnd->pip); + SOKOL_ASSERT(_sg.d3d11.ctx); + const _sg_shader_t* shd = _sg_shader_ref_ptr(&bnd->pip->cmn.shader); + const bool is_compute = bnd->pip->cmn.is_compute; + + if (is_compute) { + _sg_clear(&_sg.d3d11.bnd.cs_srvs, sizeof(_sg.d3d11.bnd.cs_srvs)); + _sg_clear(&_sg.d3d11.bnd.cs_uavs, sizeof(_sg.d3d11.bnd.cs_uavs)); + _sg_clear(&_sg.d3d11.bnd.cs_smps, sizeof(_sg.d3d11.bnd.cs_smps)); + } else { + _sg_clear(&_sg.d3d11.bnd.vbs, sizeof(_sg.d3d11.bnd.vbs)); + _sg_clear(&_sg.d3d11.bnd.vb_offsets, sizeof(_sg.d3d11.bnd.vb_offsets)); + _sg_clear(&_sg.d3d11.bnd.vs_srvs, sizeof(_sg.d3d11.bnd.vs_srvs)); + _sg_clear(&_sg.d3d11.bnd.fs_srvs, sizeof(_sg.d3d11.bnd.fs_srvs)); + _sg_clear(&_sg.d3d11.bnd.vs_smps, sizeof(_sg.d3d11.bnd.vs_smps)); + _sg_clear(&_sg.d3d11.bnd.fs_smps, sizeof(_sg.d3d11.bnd.fs_smps)); + } + + // gather all the D3D11 resources into arrays + ID3D11Buffer* d3d11_ib = bnd->ib ? bnd->ib->d3d11.buf : 0; + + if (is_compute) { + // on D3D11 we need to break a chicken-egg-situation where a resource + // may still be set as shader resource view, but is going to be set + // as unordered-access-view, so first clear all shader resource view bindings + _sg_d3d11_CSSetShaderResources(_sg.d3d11.ctx, 0, _SG_D3D11_MAX_STAGE_SRV_BINDINGS, _sg.d3d11.bnd.cs_srvs); + } else { + for (size_t i = 0; i < SG_MAX_VERTEXBUFFER_BINDSLOTS; i++) { + const _sg_buffer_t* vb = bnd->vbs[i]; + if (vb == 0) { + continue; + } + SOKOL_ASSERT(vb->d3d11.buf); + _sg.d3d11.bnd.vbs[i] = vb->d3d11.buf; + _sg.d3d11.bnd.vb_offsets[i] = (UINT)bnd->vb_offsets[i]; + } + } + for (size_t i = 0; i < SG_MAX_VIEW_BINDSLOTS; i++) { + const _sg_view_t* view = bnd->views[i]; + if (0 == view) { + continue; + } + const _sg_shader_view_t* shd_view = &shd->cmn.views[i]; + const sg_shader_stage stage = shd_view->stage; + SOKOL_ASSERT((stage == SG_SHADERSTAGE_VERTEX) + || (stage == SG_SHADERSTAGE_FRAGMENT) + || (stage == SG_SHADERSTAGE_COMPUTE)); + SOKOL_ASSERT((shd_view->view_type == SG_VIEWTYPE_TEXTURE) + || (shd_view->view_type == SG_VIEWTYPE_STORAGEBUFFER) + || (shd_view->view_type == SG_VIEWTYPE_STORAGEIMAGE)); + if (shd_view->view_type == SG_VIEWTYPE_TEXTURE) { + const uint8_t d3d11_slot = shd->d3d11.view_register_t_n[i]; + SOKOL_ASSERT(d3d11_slot < _SG_D3D11_MAX_STAGE_SRV_BINDINGS); + ID3D11ShaderResourceView* d3d11_srv = view->d3d11.srv; + SOKOL_ASSERT(d3d11_srv); + switch (stage) { + case SG_SHADERSTAGE_VERTEX: _sg.d3d11.bnd.vs_srvs[d3d11_slot] = d3d11_srv; break; + case SG_SHADERSTAGE_FRAGMENT: _sg.d3d11.bnd.fs_srvs[d3d11_slot] = d3d11_srv; break; + case SG_SHADERSTAGE_COMPUTE: _sg.d3d11.bnd.cs_srvs[d3d11_slot] = d3d11_srv; break; + default: SOKOL_UNREACHABLE; + } + } else if (shd_view->view_type == SG_VIEWTYPE_STORAGEBUFFER) { + if (shd->cmn.views[i].sbuf_readonly) { + const uint8_t d3d11_slot = shd->d3d11.view_register_t_n[i]; + SOKOL_ASSERT(d3d11_slot < _SG_D3D11_MAX_STAGE_SRV_BINDINGS); + ID3D11ShaderResourceView* d3d11_srv = view->d3d11.srv; + SOKOL_ASSERT(d3d11_srv); + switch (stage) { + case SG_SHADERSTAGE_VERTEX: _sg.d3d11.bnd.vs_srvs[d3d11_slot] = d3d11_srv; break; + case SG_SHADERSTAGE_FRAGMENT: _sg.d3d11.bnd.fs_srvs[d3d11_slot] = d3d11_srv; break; + case SG_SHADERSTAGE_COMPUTE: _sg.d3d11.bnd.cs_srvs[d3d11_slot] = d3d11_srv; break; + default: SOKOL_UNREACHABLE; + } + } else { + SOKOL_ASSERT(stage == SG_SHADERSTAGE_COMPUTE); + const uint8_t d3d11_slot = shd->d3d11.view_register_u_n[i]; + SOKOL_ASSERT(d3d11_slot < _sg.limits.d3d11_max_unordered_access_views); + ID3D11UnorderedAccessView* d3d11_uav = view->d3d11.uav; + SOKOL_ASSERT(d3d11_uav); + _sg.d3d11.bnd.cs_uavs[d3d11_slot] = d3d11_uav; + } + } else if (shd_view->view_type == SG_VIEWTYPE_STORAGEIMAGE) { + SOKOL_ASSERT(stage == SG_SHADERSTAGE_COMPUTE); + const uint8_t d3d11_slot = shd->d3d11.view_register_u_n[i]; + SOKOL_ASSERT(d3d11_slot < _sg.limits.d3d11_max_unordered_access_views); + ID3D11UnorderedAccessView* d3d11_uav = view->d3d11.uav; + SOKOL_ASSERT(d3d11_uav); + _sg.d3d11.bnd.cs_uavs[d3d11_slot] = d3d11_uav; + } else SOKOL_UNREACHABLE; + } + for (size_t i = 0; i < SG_MAX_SAMPLER_BINDSLOTS; i++) { + const _sg_sampler_t* smp = bnd->smps[i]; + if (smp == 0) { + continue; + } + const sg_shader_stage stage = shd->cmn.samplers[i].stage; + SOKOL_ASSERT(stage != SG_SHADERSTAGE_NONE); + const uint8_t d3d11_slot = shd->d3d11.smp_register_s_n[i]; + SOKOL_ASSERT(d3d11_slot < _SG_D3D11_MAX_STAGE_SMP_BINDINGS); + SOKOL_ASSERT(smp->d3d11.smp); + ID3D11SamplerState* d3d11_smp = smp->d3d11.smp; + switch (stage) { + case SG_SHADERSTAGE_VERTEX: _sg.d3d11.bnd.vs_smps[d3d11_slot] = d3d11_smp; break; + case SG_SHADERSTAGE_FRAGMENT: _sg.d3d11.bnd.fs_smps[d3d11_slot] = d3d11_smp; break; + case SG_SHADERSTAGE_COMPUTE: _sg.d3d11.bnd.cs_smps[d3d11_slot] = d3d11_smp; break; + default: SOKOL_UNREACHABLE; + } + } + if (is_compute) { + SOKOL_ASSERT(_sg.limits.d3d11_max_unordered_access_views <= _SG_D3D11_MAX_STAGE_UAV_BINDINGS); + _sg_d3d11_CSSetUnorderedAccessViews(_sg.d3d11.ctx, 0, _sg.limits.d3d11_max_unordered_access_views, _sg.d3d11.bnd.cs_uavs, NULL); + _sg_d3d11_CSSetShaderResources(_sg.d3d11.ctx, 0, _SG_D3D11_MAX_STAGE_SRV_BINDINGS, _sg.d3d11.bnd.cs_srvs); + _sg_d3d11_CSSetSamplers(_sg.d3d11.ctx, 0, _SG_D3D11_MAX_STAGE_SMP_BINDINGS, _sg.d3d11.bnd.cs_smps); + _sg_stats_inc(d3d11.bindings.num_cs_set_shader_resources); + _sg_stats_inc(d3d11.bindings.num_cs_set_samplers); + _sg_stats_inc(d3d11.bindings.num_cs_set_unordered_access_views); + } else { + _sg_d3d11_IASetVertexBuffers(_sg.d3d11.ctx, 0, SG_MAX_VERTEXBUFFER_BINDSLOTS, _sg.d3d11.bnd.vbs, bnd->pip->d3d11.vb_strides, _sg.d3d11.bnd.vb_offsets); + _sg_d3d11_IASetIndexBuffer(_sg.d3d11.ctx, d3d11_ib, bnd->pip->d3d11.index_format, (UINT)bnd->ib_offset); + _sg_d3d11_VSSetShaderResources(_sg.d3d11.ctx, 0, _SG_D3D11_MAX_STAGE_SRV_BINDINGS, _sg.d3d11.bnd.vs_srvs); + _sg_d3d11_PSSetShaderResources(_sg.d3d11.ctx, 0, _SG_D3D11_MAX_STAGE_SRV_BINDINGS, _sg.d3d11.bnd.fs_srvs); + _sg_d3d11_VSSetSamplers(_sg.d3d11.ctx, 0, _SG_D3D11_MAX_STAGE_SMP_BINDINGS, _sg.d3d11.bnd.vs_smps); + _sg_d3d11_PSSetSamplers(_sg.d3d11.ctx, 0, _SG_D3D11_MAX_STAGE_SMP_BINDINGS, _sg.d3d11.bnd.fs_smps); + _sg_stats_inc(d3d11.bindings.num_ia_set_vertex_buffers); + _sg_stats_inc(d3d11.bindings.num_ia_set_index_buffer); + _sg_stats_inc(d3d11.bindings.num_vs_set_shader_resources); + _sg_stats_inc(d3d11.bindings.num_ps_set_shader_resources); + _sg_stats_inc(d3d11.bindings.num_vs_set_samplers); + _sg_stats_inc(d3d11.bindings.num_ps_set_samplers); + } + return true; +} + +_SOKOL_PRIVATE void _sg_d3d11_apply_uniforms(int ub_slot, const sg_range* data) { + SOKOL_ASSERT(_sg.d3d11.ctx); + SOKOL_ASSERT((ub_slot >= 0) && (ub_slot < SG_MAX_UNIFORMBLOCK_BINDSLOTS)); + const _sg_pipeline_t* pip = _sg_pipeline_ref_ptr(&_sg.cur_pip); + const _sg_shader_t* shd = _sg_shader_ref_ptr(&pip->cmn.shader); + SOKOL_ASSERT(data->size == shd->cmn.uniform_blocks[ub_slot].size); + + ID3D11Buffer* cbuf = shd->d3d11.all_cbufs[ub_slot]; + SOKOL_ASSERT(cbuf); + _sg_d3d11_UpdateSubresource(_sg.d3d11.ctx, (ID3D11Resource*)cbuf, 0, NULL, data->ptr, 0, 0); + _sg_stats_inc(d3d11.uniforms.num_update_subresource); +} + +_SOKOL_PRIVATE void _sg_d3d11_draw(int base_element, int num_elements, int num_instances, int base_vertex, int base_instance) { + const bool use_instanced_draw = (num_instances > 1) || (_sg.use_instanced_draw); + if (_sg.use_indexed_draw) { + if (use_instanced_draw) { + _sg_d3d11_DrawIndexedInstanced(_sg.d3d11.ctx, + (UINT)num_elements, + (UINT)num_instances, + (UINT)base_element, + base_vertex, + (UINT)base_instance); + _sg_stats_inc(d3d11.draw.num_draw_indexed_instanced); + } else { + _sg_d3d11_DrawIndexed(_sg.d3d11.ctx, (UINT)num_elements, (UINT)base_element, base_vertex); + _sg_stats_inc(d3d11.draw.num_draw_indexed); + } + } else { + if (use_instanced_draw) { + _sg_d3d11_DrawInstanced(_sg.d3d11.ctx, + (UINT)num_elements, + (UINT)num_instances, + (UINT)base_element, + (UINT)base_instance); + _sg_stats_inc(d3d11.draw.num_draw_instanced); + } else { + _sg_d3d11_Draw(_sg.d3d11.ctx, (UINT)num_elements, (UINT)base_element); + _sg_stats_inc(d3d11.draw.num_draw); + } + } +} + +_SOKOL_PRIVATE void _sg_d3d11_dispatch(int num_groups_x, int num_groups_y, int num_groups_z) { + _sg_d3d11_Dispatch(_sg.d3d11.ctx, (UINT)num_groups_x, (UINT)num_groups_y, (UINT)num_groups_z); +} + +_SOKOL_PRIVATE void _sg_d3d11_commit(void) { + // empty +} + +_SOKOL_PRIVATE void _sg_d3d11_update_buffer(_sg_buffer_t* buf, const sg_range* data) { + SOKOL_ASSERT(buf && data && data->ptr && (data->size > 0)); + SOKOL_ASSERT(_sg.d3d11.ctx); + SOKOL_ASSERT(buf->d3d11.buf); + D3D11_MAPPED_SUBRESOURCE d3d11_msr; + HRESULT hr = _sg_d3d11_Map(_sg.d3d11.ctx, (ID3D11Resource*)buf->d3d11.buf, 0, D3D11_MAP_WRITE_DISCARD, 0, &d3d11_msr); + _sg_stats_inc(d3d11.num_map); + if (SUCCEEDED(hr)) { + memcpy(d3d11_msr.pData, data->ptr, data->size); + _sg_d3d11_Unmap(_sg.d3d11.ctx, (ID3D11Resource*)buf->d3d11.buf, 0); + _sg_stats_inc(d3d11.num_unmap); + } else { + _SG_ERROR(D3D11_MAP_FOR_UPDATE_BUFFER_FAILED); + } +} + +_SOKOL_PRIVATE void _sg_d3d11_append_buffer(_sg_buffer_t* buf, const sg_range* data, bool new_frame) { + SOKOL_ASSERT(buf && data && data->ptr && (data->size > 0)); + SOKOL_ASSERT(_sg.d3d11.ctx); + SOKOL_ASSERT(buf->d3d11.buf); + D3D11_MAP map_type = new_frame ? D3D11_MAP_WRITE_DISCARD : D3D11_MAP_WRITE_NO_OVERWRITE; + D3D11_MAPPED_SUBRESOURCE d3d11_msr; + HRESULT hr = _sg_d3d11_Map(_sg.d3d11.ctx, (ID3D11Resource*)buf->d3d11.buf, 0, map_type, 0, &d3d11_msr); + _sg_stats_inc(d3d11.num_map); + if (SUCCEEDED(hr)) { + uint8_t* dst_ptr = (uint8_t*)d3d11_msr.pData + buf->cmn.append_pos; + memcpy(dst_ptr, data->ptr, data->size); + _sg_d3d11_Unmap(_sg.d3d11.ctx, (ID3D11Resource*)buf->d3d11.buf, 0); + _sg_stats_inc(d3d11.num_unmap); + } else { + _SG_ERROR(D3D11_MAP_FOR_APPEND_BUFFER_FAILED); + } +} + +// see: https://learn.microsoft.com/en-us/windows/win32/direct3d11/overviews-direct3d-11-resources-subresources +// also see: https://learn.microsoft.com/en-us/windows/win32/api/d3d11/nf-d3d11-d3d11calcsubresource +_SOKOL_PRIVATE void _sg_d3d11_update_image(_sg_image_t* img, const sg_image_data* data) { + SOKOL_ASSERT(img && data); + SOKOL_ASSERT(_sg.d3d11.ctx); + SOKOL_ASSERT(img->d3d11.res); + const int num_slices = (img->cmn.type == SG_IMAGETYPE_3D) ? 1 : img->cmn.num_slices; + const int num_depth_slices = (img->cmn.type == SG_IMAGETYPE_3D) ? img->cmn.num_slices : 1; + UINT subres_index = 0; + HRESULT hr; + D3D11_MAPPED_SUBRESOURCE d3d11_msr; + for (int slice_index = 0; slice_index < num_slices; slice_index++) { + for (int mip_index = 0; mip_index < img->cmn.num_mipmaps; mip_index++, subres_index++) { + SOKOL_ASSERT(subres_index < _SG_D3D11_MAX_TEXTURE_SUBRESOURCES); + const int mip_width = _sg_miplevel_dim(img->cmn.width, mip_index); + const int mip_height = _sg_miplevel_dim(img->cmn.height, mip_index); + const int src_row_pitch = _sg_row_pitch(img->cmn.pixel_format, mip_width, 1); + const int src_depth_pitch = _sg_surface_pitch(img->cmn.pixel_format, mip_width, mip_height, 1); + const sg_range* miplevel_data = &(data->mip_levels[mip_index]); + const size_t slice_size = miplevel_data->size / (size_t)num_slices; + SOKOL_ASSERT(slice_size == (size_t)(src_depth_pitch * num_depth_slices)); + const size_t slice_offset = slice_size * (size_t)slice_index; + const uint8_t* slice_ptr = ((const uint8_t*)miplevel_data->ptr) + slice_offset; + hr = _sg_d3d11_Map(_sg.d3d11.ctx, img->d3d11.res, subres_index, D3D11_MAP_WRITE_DISCARD, 0, &d3d11_msr); + _sg_stats_inc(d3d11.num_map); + if (SUCCEEDED(hr)) { + const uint8_t* src_ptr = slice_ptr; + uint8_t* dst_ptr = (uint8_t*)d3d11_msr.pData; + for (int depth_index = 0; depth_index < num_depth_slices; depth_index++) { + if (src_row_pitch == (int)d3d11_msr.RowPitch) { + const size_t copy_size = slice_size / (size_t)num_depth_slices; + SOKOL_ASSERT((copy_size * (size_t)num_depth_slices) == slice_size); + memcpy(dst_ptr, src_ptr, copy_size); + } else { + SOKOL_ASSERT(src_row_pitch < (int)d3d11_msr.RowPitch); + const uint8_t* src_row_ptr = src_ptr; + uint8_t* dst_row_ptr = dst_ptr; + for (int row_index = 0; row_index < mip_height; row_index++) { + memcpy(dst_row_ptr, src_row_ptr, (size_t)src_row_pitch); + src_row_ptr += src_row_pitch; + dst_row_ptr += d3d11_msr.RowPitch; + } + } + src_ptr += src_depth_pitch; + dst_ptr += d3d11_msr.DepthPitch; + } + _sg_d3d11_Unmap(_sg.d3d11.ctx, img->d3d11.res, subres_index); + _sg_stats_inc(d3d11.num_unmap); + } else { + _SG_ERROR(D3D11_MAP_FOR_UPDATE_IMAGE_FAILED); + } + } + } +} + +// ███ ███ ███████ ████████ █████ ██ ██████ █████ ██████ ██ ██ ███████ ███ ██ ██████ +// ████ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ +// ██ ████ ██ █████ ██ ███████ ██ ██████ ███████ ██ █████ █████ ██ ██ ██ ██ ██ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ██ ██ ███████ ██ ██ ██ ███████ ██████ ██ ██ ██████ ██ ██ ███████ ██ ████ ██████ +// +// >>metal backend +#elif defined(SOKOL_METAL) + +#if __has_feature(objc_arc) +#define _SG_OBJC_RETAIN(obj) { } +#define _SG_OBJC_RELEASE(obj) { obj = nil; } +#else +#define _SG_OBJC_RETAIN(obj) { [obj retain]; } +#define _SG_OBJC_RELEASE(obj) { [obj release]; obj = nil; } +#endif + +//-- enum translation functions ------------------------------------------------ +_SOKOL_PRIVATE MTLLoadAction _sg_mtl_load_action(sg_load_action a) { + switch (a) { + case SG_LOADACTION_CLEAR: return MTLLoadActionClear; + case SG_LOADACTION_LOAD: return MTLLoadActionLoad; + case SG_LOADACTION_DONTCARE: return MTLLoadActionDontCare; + default: SOKOL_UNREACHABLE; return (MTLLoadAction)0; + } +} + +_SOKOL_PRIVATE MTLStoreAction _sg_mtl_store_action(sg_store_action a, bool resolve) { + switch (a) { + case SG_STOREACTION_STORE: + if (resolve) { + return MTLStoreActionStoreAndMultisampleResolve; + } else { + return MTLStoreActionStore; + } + break; + case SG_STOREACTION_DONTCARE: + if (resolve) { + return MTLStoreActionMultisampleResolve; + } else { + return MTLStoreActionDontCare; + } + break; + default: SOKOL_UNREACHABLE; return (MTLStoreAction)0; + } +} + +_SOKOL_PRIVATE MTLResourceOptions _sg_mtl_resource_options_storage_mode_managed_or_shared(void) { + #if defined(_SG_TARGET_MACOS) + if (_sg.mtl.use_shared_storage_mode) { + return MTLResourceStorageModeShared; + } else { + return MTLResourceStorageModeManaged; + } + #else + // MTLResourceStorageModeManaged is not even defined on iOS SDK + return MTLResourceStorageModeShared; + #endif +} + +_SOKOL_PRIVATE MTLResourceOptions _sg_mtl_buffer_resource_options(const sg_buffer_usage* usage) { + if (usage->immutable) { + return _sg_mtl_resource_options_storage_mode_managed_or_shared(); + } else { + return MTLResourceCPUCacheModeWriteCombined | _sg_mtl_resource_options_storage_mode_managed_or_shared(); + } +} + +_SOKOL_PRIVATE MTLVertexStepFunction _sg_mtl_step_function(sg_vertex_step step) { + switch (step) { + case SG_VERTEXSTEP_PER_VERTEX: return MTLVertexStepFunctionPerVertex; + case SG_VERTEXSTEP_PER_INSTANCE: return MTLVertexStepFunctionPerInstance; + default: SOKOL_UNREACHABLE; return (MTLVertexStepFunction)0; + } +} + +_SOKOL_PRIVATE MTLVertexFormat _sg_mtl_vertex_format(sg_vertex_format fmt) { + switch (fmt) { + case SG_VERTEXFORMAT_FLOAT: return MTLVertexFormatFloat; + case SG_VERTEXFORMAT_FLOAT2: return MTLVertexFormatFloat2; + case SG_VERTEXFORMAT_FLOAT3: return MTLVertexFormatFloat3; + case SG_VERTEXFORMAT_FLOAT4: return MTLVertexFormatFloat4; + case SG_VERTEXFORMAT_INT: return MTLVertexFormatInt; + case SG_VERTEXFORMAT_INT2: return MTLVertexFormatInt2; + case SG_VERTEXFORMAT_INT3: return MTLVertexFormatInt3; + case SG_VERTEXFORMAT_INT4: return MTLVertexFormatInt4; + case SG_VERTEXFORMAT_UINT: return MTLVertexFormatUInt; + case SG_VERTEXFORMAT_UINT2: return MTLVertexFormatUInt2; + case SG_VERTEXFORMAT_UINT3: return MTLVertexFormatUInt3; + case SG_VERTEXFORMAT_UINT4: return MTLVertexFormatUInt4; + case SG_VERTEXFORMAT_BYTE4: return MTLVertexFormatChar4; + case SG_VERTEXFORMAT_BYTE4N: return MTLVertexFormatChar4Normalized; + case SG_VERTEXFORMAT_UBYTE4: return MTLVertexFormatUChar4; + case SG_VERTEXFORMAT_UBYTE4N: return MTLVertexFormatUChar4Normalized; + case SG_VERTEXFORMAT_SHORT2: return MTLVertexFormatShort2; + case SG_VERTEXFORMAT_SHORT2N: return MTLVertexFormatShort2Normalized; + case SG_VERTEXFORMAT_USHORT2: return MTLVertexFormatUShort2; + case SG_VERTEXFORMAT_USHORT2N: return MTLVertexFormatUShort2Normalized; + case SG_VERTEXFORMAT_SHORT4: return MTLVertexFormatShort4; + case SG_VERTEXFORMAT_SHORT4N: return MTLVertexFormatShort4Normalized; + case SG_VERTEXFORMAT_USHORT4: return MTLVertexFormatUShort4; + case SG_VERTEXFORMAT_USHORT4N: return MTLVertexFormatUShort4Normalized; + case SG_VERTEXFORMAT_INT10_N2: return MTLVertexFormatInt1010102Normalized; + case SG_VERTEXFORMAT_UINT10_N2: return MTLVertexFormatUInt1010102Normalized; + case SG_VERTEXFORMAT_HALF2: return MTLVertexFormatHalf2; + case SG_VERTEXFORMAT_HALF4: return MTLVertexFormatHalf4; + default: SOKOL_UNREACHABLE; return (MTLVertexFormat)0; + } +} + +_SOKOL_PRIVATE MTLPrimitiveType _sg_mtl_primitive_type(sg_primitive_type t) { + switch (t) { + case SG_PRIMITIVETYPE_POINTS: return MTLPrimitiveTypePoint; + case SG_PRIMITIVETYPE_LINES: return MTLPrimitiveTypeLine; + case SG_PRIMITIVETYPE_LINE_STRIP: return MTLPrimitiveTypeLineStrip; + case SG_PRIMITIVETYPE_TRIANGLES: return MTLPrimitiveTypeTriangle; + case SG_PRIMITIVETYPE_TRIANGLE_STRIP: return MTLPrimitiveTypeTriangleStrip; + default: SOKOL_UNREACHABLE; return (MTLPrimitiveType)0; + } +} + +_SOKOL_PRIVATE MTLPixelFormat _sg_mtl_pixel_format(sg_pixel_format fmt) { + switch (fmt) { + case SG_PIXELFORMAT_R8: return MTLPixelFormatR8Unorm; + case SG_PIXELFORMAT_R8SN: return MTLPixelFormatR8Snorm; + case SG_PIXELFORMAT_R8UI: return MTLPixelFormatR8Uint; + case SG_PIXELFORMAT_R8SI: return MTLPixelFormatR8Sint; + case SG_PIXELFORMAT_R16: return MTLPixelFormatR16Unorm; + case SG_PIXELFORMAT_R16SN: return MTLPixelFormatR16Snorm; + case SG_PIXELFORMAT_R16UI: return MTLPixelFormatR16Uint; + case SG_PIXELFORMAT_R16SI: return MTLPixelFormatR16Sint; + case SG_PIXELFORMAT_R16F: return MTLPixelFormatR16Float; + case SG_PIXELFORMAT_RG8: return MTLPixelFormatRG8Unorm; + case SG_PIXELFORMAT_RG8SN: return MTLPixelFormatRG8Snorm; + case SG_PIXELFORMAT_RG8UI: return MTLPixelFormatRG8Uint; + case SG_PIXELFORMAT_RG8SI: return MTLPixelFormatRG8Sint; + case SG_PIXELFORMAT_R32UI: return MTLPixelFormatR32Uint; + case SG_PIXELFORMAT_R32SI: return MTLPixelFormatR32Sint; + case SG_PIXELFORMAT_R32F: return MTLPixelFormatR32Float; + case SG_PIXELFORMAT_RG16: return MTLPixelFormatRG16Unorm; + case SG_PIXELFORMAT_RG16SN: return MTLPixelFormatRG16Snorm; + case SG_PIXELFORMAT_RG16UI: return MTLPixelFormatRG16Uint; + case SG_PIXELFORMAT_RG16SI: return MTLPixelFormatRG16Sint; + case SG_PIXELFORMAT_RG16F: return MTLPixelFormatRG16Float; + case SG_PIXELFORMAT_RGBA8: return MTLPixelFormatRGBA8Unorm; + case SG_PIXELFORMAT_SRGB8A8: return MTLPixelFormatRGBA8Unorm_sRGB; + case SG_PIXELFORMAT_RGBA8SN: return MTLPixelFormatRGBA8Snorm; + case SG_PIXELFORMAT_RGBA8UI: return MTLPixelFormatRGBA8Uint; + case SG_PIXELFORMAT_RGBA8SI: return MTLPixelFormatRGBA8Sint; + case SG_PIXELFORMAT_BGRA8: return MTLPixelFormatBGRA8Unorm; + case SG_PIXELFORMAT_RGB10A2: return MTLPixelFormatRGB10A2Unorm; + case SG_PIXELFORMAT_RG11B10F: return MTLPixelFormatRG11B10Float; + case SG_PIXELFORMAT_RGB9E5: return MTLPixelFormatRGB9E5Float; + case SG_PIXELFORMAT_RG32UI: return MTLPixelFormatRG32Uint; + case SG_PIXELFORMAT_RG32SI: return MTLPixelFormatRG32Sint; + case SG_PIXELFORMAT_RG32F: return MTLPixelFormatRG32Float; + case SG_PIXELFORMAT_RGBA16: return MTLPixelFormatRGBA16Unorm; + case SG_PIXELFORMAT_RGBA16SN: return MTLPixelFormatRGBA16Snorm; + case SG_PIXELFORMAT_RGBA16UI: return MTLPixelFormatRGBA16Uint; + case SG_PIXELFORMAT_RGBA16SI: return MTLPixelFormatRGBA16Sint; + case SG_PIXELFORMAT_RGBA16F: return MTLPixelFormatRGBA16Float; + case SG_PIXELFORMAT_RGBA32UI: return MTLPixelFormatRGBA32Uint; + case SG_PIXELFORMAT_RGBA32SI: return MTLPixelFormatRGBA32Sint; + case SG_PIXELFORMAT_RGBA32F: return MTLPixelFormatRGBA32Float; + case SG_PIXELFORMAT_DEPTH: return MTLPixelFormatDepth32Float; + case SG_PIXELFORMAT_DEPTH_STENCIL: return MTLPixelFormatDepth32Float_Stencil8; + #if defined(_SG_TARGET_MACOS) + case SG_PIXELFORMAT_BC1_RGBA: return MTLPixelFormatBC1_RGBA; + case SG_PIXELFORMAT_BC2_RGBA: return MTLPixelFormatBC2_RGBA; + case SG_PIXELFORMAT_BC3_RGBA: return MTLPixelFormatBC3_RGBA; + case SG_PIXELFORMAT_BC3_SRGBA: return MTLPixelFormatBC3_RGBA_sRGB; + case SG_PIXELFORMAT_BC4_R: return MTLPixelFormatBC4_RUnorm; + case SG_PIXELFORMAT_BC4_RSN: return MTLPixelFormatBC4_RSnorm; + case SG_PIXELFORMAT_BC5_RG: return MTLPixelFormatBC5_RGUnorm; + case SG_PIXELFORMAT_BC5_RGSN: return MTLPixelFormatBC5_RGSnorm; + case SG_PIXELFORMAT_BC6H_RGBF: return MTLPixelFormatBC6H_RGBFloat; + case SG_PIXELFORMAT_BC6H_RGBUF: return MTLPixelFormatBC6H_RGBUfloat; + case SG_PIXELFORMAT_BC7_RGBA: return MTLPixelFormatBC7_RGBAUnorm; + case SG_PIXELFORMAT_BC7_SRGBA: return MTLPixelFormatBC7_RGBAUnorm_sRGB; + #else + case SG_PIXELFORMAT_ETC2_RGB8: return MTLPixelFormatETC2_RGB8; + case SG_PIXELFORMAT_ETC2_SRGB8: return MTLPixelFormatETC2_RGB8_sRGB; + case SG_PIXELFORMAT_ETC2_RGB8A1: return MTLPixelFormatETC2_RGB8A1; + case SG_PIXELFORMAT_ETC2_RGBA8: return MTLPixelFormatEAC_RGBA8; + case SG_PIXELFORMAT_ETC2_SRGB8A8: return MTLPixelFormatEAC_RGBA8_sRGB; + case SG_PIXELFORMAT_EAC_R11: return MTLPixelFormatEAC_R11Unorm; + case SG_PIXELFORMAT_EAC_R11SN: return MTLPixelFormatEAC_R11Snorm; + case SG_PIXELFORMAT_EAC_RG11: return MTLPixelFormatEAC_RG11Unorm; + case SG_PIXELFORMAT_EAC_RG11SN: return MTLPixelFormatEAC_RG11Snorm; + case SG_PIXELFORMAT_ASTC_4x4_RGBA: return MTLPixelFormatASTC_4x4_LDR; + case SG_PIXELFORMAT_ASTC_4x4_SRGBA: return MTLPixelFormatASTC_4x4_sRGB; + #endif + default: return MTLPixelFormatInvalid; + } +} + +_SOKOL_PRIVATE MTLColorWriteMask _sg_mtl_color_write_mask(sg_color_mask m) { + MTLColorWriteMask mtl_mask = MTLColorWriteMaskNone; + if (m & SG_COLORMASK_R) { + mtl_mask |= MTLColorWriteMaskRed; + } + if (m & SG_COLORMASK_G) { + mtl_mask |= MTLColorWriteMaskGreen; + } + if (m & SG_COLORMASK_B) { + mtl_mask |= MTLColorWriteMaskBlue; + } + if (m & SG_COLORMASK_A) { + mtl_mask |= MTLColorWriteMaskAlpha; + } + return mtl_mask; +} + +_SOKOL_PRIVATE MTLBlendOperation _sg_mtl_blend_op(sg_blend_op op) { + switch (op) { + case SG_BLENDOP_ADD: return MTLBlendOperationAdd; + case SG_BLENDOP_SUBTRACT: return MTLBlendOperationSubtract; + case SG_BLENDOP_REVERSE_SUBTRACT: return MTLBlendOperationReverseSubtract; + case SG_BLENDOP_MIN: return MTLBlendOperationMin; + case SG_BLENDOP_MAX: return MTLBlendOperationMax; + default: SOKOL_UNREACHABLE; return (MTLBlendOperation)0; + } +} + +_SOKOL_PRIVATE MTLBlendFactor _sg_mtl_blend_factor(sg_blend_factor f) { + switch (f) { + case SG_BLENDFACTOR_ZERO: return MTLBlendFactorZero; + case SG_BLENDFACTOR_ONE: return MTLBlendFactorOne; + case SG_BLENDFACTOR_SRC_COLOR: return MTLBlendFactorSourceColor; + case SG_BLENDFACTOR_ONE_MINUS_SRC_COLOR: return MTLBlendFactorOneMinusSourceColor; + case SG_BLENDFACTOR_SRC_ALPHA: return MTLBlendFactorSourceAlpha; + case SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA: return MTLBlendFactorOneMinusSourceAlpha; + case SG_BLENDFACTOR_DST_COLOR: return MTLBlendFactorDestinationColor; + case SG_BLENDFACTOR_ONE_MINUS_DST_COLOR: return MTLBlendFactorOneMinusDestinationColor; + case SG_BLENDFACTOR_DST_ALPHA: return MTLBlendFactorDestinationAlpha; + case SG_BLENDFACTOR_ONE_MINUS_DST_ALPHA: return MTLBlendFactorOneMinusDestinationAlpha; + case SG_BLENDFACTOR_SRC_ALPHA_SATURATED: return MTLBlendFactorSourceAlphaSaturated; + case SG_BLENDFACTOR_BLEND_COLOR: return MTLBlendFactorBlendColor; + case SG_BLENDFACTOR_ONE_MINUS_BLEND_COLOR: return MTLBlendFactorOneMinusBlendColor; + case SG_BLENDFACTOR_BLEND_ALPHA: return MTLBlendFactorBlendAlpha; + case SG_BLENDFACTOR_ONE_MINUS_BLEND_ALPHA: return MTLBlendFactorOneMinusBlendAlpha; + case SG_BLENDFACTOR_SRC1_COLOR: return MTLBlendFactorSource1Color; + case SG_BLENDFACTOR_ONE_MINUS_SRC1_COLOR: return MTLBlendFactorOneMinusSource1Color; + case SG_BLENDFACTOR_SRC1_ALPHA: return MTLBlendFactorSource1Alpha; + case SG_BLENDFACTOR_ONE_MINUS_SRC1_ALPHA: return MTLBlendFactorOneMinusSource1Alpha; + default: SOKOL_UNREACHABLE; return (MTLBlendFactor)0; + } +} + +_SOKOL_PRIVATE MTLCompareFunction _sg_mtl_compare_func(sg_compare_func f) { + switch (f) { + case SG_COMPAREFUNC_NEVER: return MTLCompareFunctionNever; + case SG_COMPAREFUNC_LESS: return MTLCompareFunctionLess; + case SG_COMPAREFUNC_EQUAL: return MTLCompareFunctionEqual; + case SG_COMPAREFUNC_LESS_EQUAL: return MTLCompareFunctionLessEqual; + case SG_COMPAREFUNC_GREATER: return MTLCompareFunctionGreater; + case SG_COMPAREFUNC_NOT_EQUAL: return MTLCompareFunctionNotEqual; + case SG_COMPAREFUNC_GREATER_EQUAL: return MTLCompareFunctionGreaterEqual; + case SG_COMPAREFUNC_ALWAYS: return MTLCompareFunctionAlways; + default: SOKOL_UNREACHABLE; return (MTLCompareFunction)0; + } +} + +_SOKOL_PRIVATE MTLStencilOperation _sg_mtl_stencil_op(sg_stencil_op op) { + switch (op) { + case SG_STENCILOP_KEEP: return MTLStencilOperationKeep; + case SG_STENCILOP_ZERO: return MTLStencilOperationZero; + case SG_STENCILOP_REPLACE: return MTLStencilOperationReplace; + case SG_STENCILOP_INCR_CLAMP: return MTLStencilOperationIncrementClamp; + case SG_STENCILOP_DECR_CLAMP: return MTLStencilOperationDecrementClamp; + case SG_STENCILOP_INVERT: return MTLStencilOperationInvert; + case SG_STENCILOP_INCR_WRAP: return MTLStencilOperationIncrementWrap; + case SG_STENCILOP_DECR_WRAP: return MTLStencilOperationDecrementWrap; + default: SOKOL_UNREACHABLE; return (MTLStencilOperation)0; + } +} + +_SOKOL_PRIVATE MTLCullMode _sg_mtl_cull_mode(sg_cull_mode m) { + switch (m) { + case SG_CULLMODE_NONE: return MTLCullModeNone; + case SG_CULLMODE_FRONT: return MTLCullModeFront; + case SG_CULLMODE_BACK: return MTLCullModeBack; + default: SOKOL_UNREACHABLE; return (MTLCullMode)0; + } +} + +_SOKOL_PRIVATE MTLWinding _sg_mtl_winding(sg_face_winding w) { + switch (w) { + case SG_FACEWINDING_CW: return MTLWindingClockwise; + case SG_FACEWINDING_CCW: return MTLWindingCounterClockwise; + default: SOKOL_UNREACHABLE; return (MTLWinding)0; + } +} + +_SOKOL_PRIVATE MTLIndexType _sg_mtl_index_type(sg_index_type t) { + switch (t) { + case SG_INDEXTYPE_UINT16: return MTLIndexTypeUInt16; + case SG_INDEXTYPE_UINT32: return MTLIndexTypeUInt32; + default: SOKOL_UNREACHABLE; return (MTLIndexType)0; + } +} + +_SOKOL_PRIVATE int _sg_mtl_index_size(sg_index_type t) { + switch (t) { + case SG_INDEXTYPE_NONE: return 0; + case SG_INDEXTYPE_UINT16: return 2; + case SG_INDEXTYPE_UINT32: return 4; + default: SOKOL_UNREACHABLE; return 0; + } +} + +_SOKOL_PRIVATE MTLTextureType _sg_mtl_texture_type(sg_image_type t, bool msaa) { + switch (t) { + case SG_IMAGETYPE_2D: return msaa ? MTLTextureType2DMultisample : MTLTextureType2D; + case SG_IMAGETYPE_CUBE: return MTLTextureTypeCube; + case SG_IMAGETYPE_3D: return MTLTextureType3D; + // NOTE: MTLTextureType2DMultisampleArray requires macOS 10.14+, iOS 14.0+ + case SG_IMAGETYPE_ARRAY: return MTLTextureType2DArray; + default: SOKOL_UNREACHABLE; return (MTLTextureType)0; + } +} + +_SOKOL_PRIVATE MTLSamplerAddressMode _sg_mtl_address_mode(sg_wrap w) { + if (_sg.features.image_clamp_to_border) { + if (@available(macOS 12.0, iOS 14.0, *)) { + // border color feature available + switch (w) { + case SG_WRAP_REPEAT: return MTLSamplerAddressModeRepeat; + case SG_WRAP_CLAMP_TO_EDGE: return MTLSamplerAddressModeClampToEdge; + case SG_WRAP_CLAMP_TO_BORDER: return MTLSamplerAddressModeClampToBorderColor; + case SG_WRAP_MIRRORED_REPEAT: return MTLSamplerAddressModeMirrorRepeat; + default: SOKOL_UNREACHABLE; return (MTLSamplerAddressMode)0; + } + } + } + // fallthrough: clamp to border no supported + switch (w) { + case SG_WRAP_REPEAT: return MTLSamplerAddressModeRepeat; + case SG_WRAP_CLAMP_TO_EDGE: return MTLSamplerAddressModeClampToEdge; + case SG_WRAP_CLAMP_TO_BORDER: return MTLSamplerAddressModeClampToEdge; + case SG_WRAP_MIRRORED_REPEAT: return MTLSamplerAddressModeMirrorRepeat; + default: SOKOL_UNREACHABLE; return (MTLSamplerAddressMode)0; + } +} + +_SOKOL_PRIVATE API_AVAILABLE(ios(14.0), macos(12.0)) MTLSamplerBorderColor _sg_mtl_border_color(sg_border_color c) { + switch (c) { + case SG_BORDERCOLOR_TRANSPARENT_BLACK: return MTLSamplerBorderColorTransparentBlack; + case SG_BORDERCOLOR_OPAQUE_BLACK: return MTLSamplerBorderColorOpaqueBlack; + case SG_BORDERCOLOR_OPAQUE_WHITE: return MTLSamplerBorderColorOpaqueWhite; + default: SOKOL_UNREACHABLE; return (MTLSamplerBorderColor)0; + } +} + +_SOKOL_PRIVATE MTLSamplerMinMagFilter _sg_mtl_minmag_filter(sg_filter f) { + switch (f) { + case SG_FILTER_NEAREST: + return MTLSamplerMinMagFilterNearest; + case SG_FILTER_LINEAR: + return MTLSamplerMinMagFilterLinear; + default: + SOKOL_UNREACHABLE; return (MTLSamplerMinMagFilter)0; + } +} + +_SOKOL_PRIVATE MTLSamplerMipFilter _sg_mtl_mipmap_filter(sg_filter f) { + switch (f) { + case SG_FILTER_NEAREST: + return MTLSamplerMipFilterNearest; + case SG_FILTER_LINEAR: + return MTLSamplerMipFilterLinear; + default: + SOKOL_UNREACHABLE; return (MTLSamplerMipFilter)0; + } +} + +_SOKOL_PRIVATE size_t _sg_mtl_vertexbuffer_bindslot(size_t sokol_bindslot) { + return sokol_bindslot + _SG_MTL_MAX_STAGE_UB_SBUF_BINDINGS; +} + +//-- a pool for all Metal resource objects, with deferred release queue --------- +_SOKOL_PRIVATE void _sg_mtl_init_pool(const sg_desc* desc) { + _sg.mtl.idpool.num_slots = 2 * + ( + 2 * desc->buffer_pool_size + + 2 * desc->image_pool_size + + 1 * desc->sampler_pool_size + + 6 * desc->shader_pool_size + + 3 * desc->pipeline_pool_size + + 1 * desc->view_pool_size + + 128 + ); + _sg.mtl.idpool.pool = [NSMutableArray arrayWithCapacity:(NSUInteger)_sg.mtl.idpool.num_slots]; + _SG_OBJC_RETAIN(_sg.mtl.idpool.pool); + NSNull* null = [NSNull null]; + for (int i = 0; i < _sg.mtl.idpool.num_slots; i++) { + [_sg.mtl.idpool.pool addObject:null]; + } + SOKOL_ASSERT([_sg.mtl.idpool.pool count] == (NSUInteger)_sg.mtl.idpool.num_slots); + // a queue of currently free slot indices + _sg.mtl.idpool.free_queue_top = 0; + _sg.mtl.idpool.free_queue = (int*)_sg_malloc_clear((size_t)_sg.mtl.idpool.num_slots * sizeof(int)); + // pool slot 0 is reserved! + for (int i = _sg.mtl.idpool.num_slots-1; i >= 1; i--) { + _sg.mtl.idpool.free_queue[_sg.mtl.idpool.free_queue_top++] = i; + } + // a circular queue which holds release items (frame index when a resource is to be released, and the resource's pool index + _sg.mtl.idpool.release_queue_front = 0; + _sg.mtl.idpool.release_queue_back = 0; + _sg.mtl.idpool.release_queue = (_sg_mtl_release_item_t*)_sg_malloc_clear((size_t)_sg.mtl.idpool.num_slots * sizeof(_sg_mtl_release_item_t)); + for (int i = 0; i < _sg.mtl.idpool.num_slots; i++) { + _sg.mtl.idpool.release_queue[i].frame_index = 0; + _sg.mtl.idpool.release_queue[i].slot_index = _SG_MTL_INVALID_SLOT_INDEX; + } +} + +_SOKOL_PRIVATE void _sg_mtl_destroy_pool(void) { + _sg_free(_sg.mtl.idpool.release_queue); _sg.mtl.idpool.release_queue = 0; + _sg_free(_sg.mtl.idpool.free_queue); _sg.mtl.idpool.free_queue = 0; + _SG_OBJC_RELEASE(_sg.mtl.idpool.pool); +} + +// get a new free resource pool slot +_SOKOL_PRIVATE int _sg_mtl_alloc_pool_slot(void) { + SOKOL_ASSERT(_sg.mtl.idpool.free_queue_top > 0); + const int slot_index = _sg.mtl.idpool.free_queue[--_sg.mtl.idpool.free_queue_top]; + SOKOL_ASSERT((slot_index > 0) && (slot_index < _sg.mtl.idpool.num_slots)); + return slot_index; +} + +// put a free resource pool slot back into the free-queue +_SOKOL_PRIVATE void _sg_mtl_free_pool_slot(int slot_index) { + SOKOL_ASSERT(_sg.mtl.idpool.free_queue_top < _sg.mtl.idpool.num_slots); + SOKOL_ASSERT((slot_index > 0) && (slot_index < _sg.mtl.idpool.num_slots)); + _sg.mtl.idpool.free_queue[_sg.mtl.idpool.free_queue_top++] = slot_index; +} + +// add an MTLResource to the pool, return pool index or 0 if input was 'nil' +_SOKOL_PRIVATE int _sg_mtl_add_resource(id res) { + if (nil == res) { + return _SG_MTL_INVALID_SLOT_INDEX; + } + _sg_stats_inc(metal.idpool.num_added); + const int slot_index = _sg_mtl_alloc_pool_slot(); + // NOTE: the NSMutableArray will take ownership of its items + SOKOL_ASSERT([NSNull null] == _sg.mtl.idpool.pool[(NSUInteger)slot_index]); + _sg.mtl.idpool.pool[(NSUInteger)slot_index] = res; + return slot_index; +} + +/* mark an MTLResource for release, this will put the resource into the + deferred-release queue, and the resource will then be released N frames later, + the special pool index 0 will be ignored (this means that a nil + value was provided to _sg_mtl_add_resource() +*/ +_SOKOL_PRIVATE void _sg_mtl_release_resource(uint32_t frame_index, int slot_index) { + if (slot_index == _SG_MTL_INVALID_SLOT_INDEX) { + return; + } + _sg_stats_inc(metal.idpool.num_released); + SOKOL_ASSERT((slot_index > 0) && (slot_index < _sg.mtl.idpool.num_slots)); + SOKOL_ASSERT([NSNull null] != _sg.mtl.idpool.pool[(NSUInteger)slot_index]); + int release_index = _sg.mtl.idpool.release_queue_front++; + if (_sg.mtl.idpool.release_queue_front >= _sg.mtl.idpool.num_slots) { + // wrap-around + _sg.mtl.idpool.release_queue_front = 0; + } + // release queue full? + SOKOL_ASSERT(_sg.mtl.idpool.release_queue_front != _sg.mtl.idpool.release_queue_back); + SOKOL_ASSERT(0 == _sg.mtl.idpool.release_queue[release_index].frame_index); + const uint32_t safe_to_release_frame_index = frame_index + SG_NUM_INFLIGHT_FRAMES + 1; + _sg.mtl.idpool.release_queue[release_index].frame_index = safe_to_release_frame_index; + _sg.mtl.idpool.release_queue[release_index].slot_index = slot_index; +} + +// run garbage-collection pass on all resources in the release-queue +_SOKOL_PRIVATE void _sg_mtl_garbage_collect(uint32_t frame_index) { + while (_sg.mtl.idpool.release_queue_back != _sg.mtl.idpool.release_queue_front) { + if (frame_index < _sg.mtl.idpool.release_queue[_sg.mtl.idpool.release_queue_back].frame_index) { + // don't need to check further, release-items past this are too young + break; + } + _sg_stats_inc(metal.idpool.num_garbage_collected); + // safe to release this resource + const int slot_index = _sg.mtl.idpool.release_queue[_sg.mtl.idpool.release_queue_back].slot_index; + SOKOL_ASSERT((slot_index > 0) && (slot_index < _sg.mtl.idpool.num_slots)); + // note: the NSMutableArray takes ownership of its items, assigning an NSNull object will + // release the object, no matter if using ARC or not + SOKOL_ASSERT(_sg.mtl.idpool.pool[(NSUInteger)slot_index] != [NSNull null]); + _sg.mtl.idpool.pool[(NSUInteger)slot_index] = [NSNull null]; + // put the now free pool index back on the free queue + _sg_mtl_free_pool_slot(slot_index); + // reset the release queue slot and advance the back index + _sg.mtl.idpool.release_queue[_sg.mtl.idpool.release_queue_back].frame_index = 0; + _sg.mtl.idpool.release_queue[_sg.mtl.idpool.release_queue_back].slot_index = _SG_MTL_INVALID_SLOT_INDEX; + _sg.mtl.idpool.release_queue_back++; + if (_sg.mtl.idpool.release_queue_back >= _sg.mtl.idpool.num_slots) { + // wrap-around + _sg.mtl.idpool.release_queue_back = 0; + } + } +} + +_SOKOL_PRIVATE id _sg_mtl_id(int slot_index) { + return _sg.mtl.idpool.pool[(NSUInteger)slot_index]; +} + +_SOKOL_PRIVATE void _sg_mtl_clear_state_cache(void) { + _sg_clear(&_sg.mtl.cache, sizeof(_sg.mtl.cache)); +} + +// https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf +_SOKOL_PRIVATE void _sg_mtl_init_caps(void) { + #if defined(_SG_TARGET_MACOS) + _sg.backend = SG_BACKEND_METAL_MACOS; + #elif defined(_SG_TARGET_IOS) + #if defined(_SG_TARGET_IOS_SIMULATOR) + _sg.backend = SG_BACKEND_METAL_SIMULATOR; + #else + _sg.backend = SG_BACKEND_METAL_IOS; + #endif + #endif + _sg.features.origin_top_left = true; + _sg.features.mrt_independent_blend_state = true; + _sg.features.mrt_independent_write_mask = true; + _sg.features.compute = true; + _sg.features.msaa_texture_bindings = true; + _sg.features.draw_base_vertex = true; + _sg.features.draw_base_instance = true; + _sg.features.dual_source_blending = true; + _sg.features.vertexformat_int10_n2 = true; + + _sg.features.image_clamp_to_border = false; + #if (MAC_OS_X_VERSION_MAX_ALLOWED >= 120000) || (__IPHONE_OS_VERSION_MAX_ALLOWED >= 140000) + if (@available(macOS 12.0, iOS 14.0, *)) { + _sg.features.image_clamp_to_border = [_sg.mtl.device supportsFamily:MTLGPUFamilyApple7] + || [_sg.mtl.device supportsFamily:MTLGPUFamilyMac2]; + #if (MAC_OS_X_VERSION_MAX_ALLOWED >= 130000) || (__IPHONE_OS_VERSION_MAX_ALLOWED >= 160000) + if (!_sg.features.image_clamp_to_border) { + if (@available(macOS 13.0, iOS 16.0, *)) { + _sg.features.image_clamp_to_border = [_sg.mtl.device supportsFamily:MTLGPUFamilyMetal3]; + } + } + #endif + } + #endif + + #if defined(_SG_TARGET_MACOS) + _sg.limits.max_image_size_2d = 16 * 1024; + _sg.limits.max_image_size_cube = 16 * 1024; + _sg.limits.max_image_size_3d = 2 * 1024; + _sg.limits.max_image_size_array = 16 * 1024; + _sg.limits.max_image_array_layers = 2 * 1024; + _sg.limits.max_texture_bindings_per_stage = _sg_min(128, SG_MAX_VIEW_BINDSLOTS); + #else + // FIXME: newer iOS devices support 16k textures + _sg.limits.max_image_size_2d = 8 * 1024; + _sg.limits.max_image_size_cube = 8 * 1024; + _sg.limits.max_image_size_3d = 2 * 1024; + _sg.limits.max_image_size_array = 8 * 1024; + _sg.limits.max_image_array_layers = 2 * 1024; + _sg.limits.max_texture_bindings_per_stage = _sg_min(96, SG_MAX_VIEW_BINDSLOTS); // since iPhone8 + #endif + _sg.limits.max_storage_image_bindings_per_stage = _sg.limits.max_texture_bindings_per_stage; // shared with texture bindings + _sg.limits.max_storage_buffer_bindings_per_stage = _sg_min(_SG_MTL_MAX_STAGE_BUFFER_BINDINGS - (SG_MAX_VERTEXBUFFER_BINDSLOTS + SG_MAX_UNIFORMBLOCK_BINDSLOTS), SG_MAX_VIEW_BINDSLOTS); + _sg.limits.max_color_attachments = _sg_min(8, SG_MAX_COLOR_ATTACHMENTS); + _sg.limits.max_vertex_attrs = SG_MAX_VERTEX_ATTRIBUTES; + + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_R8]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_R8SN]); + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_R8UI]); + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_R8SI]); + #if defined(_SG_TARGET_MACOS) + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_R16]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_R16SN]); + #else + _sg_pixelformat_sfbr(&_sg.formats[SG_PIXELFORMAT_R16]); + _sg_pixelformat_sfbr(&_sg.formats[SG_PIXELFORMAT_R16SN]); + #endif + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_R16UI]); + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_R16SI]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_R16F]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RG8]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RG8SN]); + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_RG8UI]); + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_RG8SI]); + _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_R32UI]); + _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_R32SI]); + #if defined(_SG_TARGET_MACOS) + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_R32F]); + #else + _sg_pixelformat_sbr(&_sg.formats[SG_PIXELFORMAT_R32F]); + #endif + #if defined(_SG_TARGET_MACOS) + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RG16]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RG16SN]); + #else + _sg_pixelformat_sfbr(&_sg.formats[SG_PIXELFORMAT_RG16]); + _sg_pixelformat_sfbr(&_sg.formats[SG_PIXELFORMAT_RG16SN]); + #endif + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_RG16UI]); + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_RG16SI]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RG16F]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RGBA8]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_SRGB8A8]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RGBA8SN]); + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_RGBA8UI]); + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_RGBA8SI]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_BGRA8]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RGB10A2]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RG11B10F]); + #if defined(_SG_TARGET_MACOS) + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_RGB9E5]); + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_RG32UI]); + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_RG32SI]); + #else + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RGB9E5]); + _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_RG32UI]); + _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_RG32SI]); + #endif + #if defined(_SG_TARGET_MACOS) + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RG32F]); + #else + _sg_pixelformat_sbr(&_sg.formats[SG_PIXELFORMAT_RG32F]); + #endif + #if defined(_SG_TARGET_MACOS) + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RGBA16]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RGBA16SN]); + #else + _sg_pixelformat_sfbr(&_sg.formats[SG_PIXELFORMAT_RGBA16]); + _sg_pixelformat_sfbr(&_sg.formats[SG_PIXELFORMAT_RGBA16SN]); + #endif + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_RGBA16UI]); + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_RGBA16SI]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RGBA16F]); + #if defined(_SG_TARGET_MACOS) + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_RGBA32UI]); + _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_RGBA32SI]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RGBA32F]); + #else + _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_RGBA32UI]); + _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_RGBA32SI]); + _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_RGBA32F]); + #endif + _sg_pixelformat_srmd(&_sg.formats[SG_PIXELFORMAT_DEPTH]); + _sg_pixelformat_srmd(&_sg.formats[SG_PIXELFORMAT_DEPTH_STENCIL]); + #if defined(_SG_TARGET_MACOS) + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC1_RGBA]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC2_RGBA]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC3_RGBA]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC3_SRGBA]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC4_R]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC4_RSN]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC5_RG]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC5_RGSN]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC6H_RGBF]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC6H_RGBUF]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC7_RGBA]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC7_SRGBA]); + #else + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RGB8]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_SRGB8]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RGB8A1]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RGBA8]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_SRGB8A8]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_R11]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_R11SN]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_RG11]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_RG11SN]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ASTC_4x4_RGBA]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ASTC_4x4_SRGBA]); + #endif + + // compute shader access + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R8]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R8SN]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R8UI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R8SI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R16]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R16SN]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R16UI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R16SI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R16F]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG8]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG8SN]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG8UI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG8SI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R32UI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R32SI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R32F]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG16]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG16SN]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG16UI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG16SI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG16F]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA8]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA8SN]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA8UI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA8SI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_BGRA8]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGB10A2]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG11B10F]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG32UI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG32SI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG32F]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA16]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA16SN]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA16UI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA16SI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA16F]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA32UI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA32SI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA32F]); +} + +//-- main Metal backend state and functions ------------------------------------ +_SOKOL_PRIVATE void _sg_mtl_setup_backend(const sg_desc* desc) { + // assume already zero-initialized + SOKOL_ASSERT(desc); + SOKOL_ASSERT(desc->environment.metal.device); + SOKOL_ASSERT(desc->uniform_buffer_size > 0); + _sg_mtl_init_pool(desc); + _sg_mtl_clear_state_cache(); + _sg.mtl.valid = true; + _sg.mtl.ub_size = desc->uniform_buffer_size; + _sg.mtl.sem = dispatch_semaphore_create(SG_NUM_INFLIGHT_FRAMES); + _sg.mtl.device = (__bridge id) desc->environment.metal.device; + _sg.mtl.cmd_queue = [_sg.mtl.device newCommandQueue]; + + for (int i = 0; i < SG_NUM_INFLIGHT_FRAMES; i++) { + _sg.mtl.uniform_buffers[i] = [_sg.mtl.device + newBufferWithLength:(NSUInteger)_sg.mtl.ub_size + options:MTLResourceCPUCacheModeWriteCombined|MTLResourceStorageModeShared + ]; + #if defined(SOKOL_DEBUG) + _sg.mtl.uniform_buffers[i].label = [NSString stringWithFormat:@"sg-uniform-buffer.%d", i]; + #endif + } + + if (desc->metal.force_managed_storage_mode) { + _sg.mtl.use_shared_storage_mode = false; + } else if (@available(macOS 10.15, iOS 13.0, *)) { + // on Intel Macs, always use managed resources even though the + // device says it supports unified memory (because of texture restrictions) + const bool is_apple_gpu = [_sg.mtl.device supportsFamily:MTLGPUFamilyApple1]; + if (!is_apple_gpu) { + _sg.mtl.use_shared_storage_mode = false; + } else { + _sg.mtl.use_shared_storage_mode = true; + } + } else { + #if defined(_SG_TARGET_MACOS) + _sg.mtl.use_shared_storage_mode = false; + #else + _sg.mtl.use_shared_storage_mode = true; + #endif + } + _sg_mtl_init_caps(); +} + +_SOKOL_PRIVATE void _sg_mtl_discard_backend(void) { + SOKOL_ASSERT(_sg.mtl.valid); + // wait for the last frame to finish + for (int i = 0; i < SG_NUM_INFLIGHT_FRAMES; i++) { + dispatch_semaphore_wait(_sg.mtl.sem, DISPATCH_TIME_FOREVER); + } + // semaphore must be "relinquished" before destruction + for (int i = 0; i < SG_NUM_INFLIGHT_FRAMES; i++) { + dispatch_semaphore_signal(_sg.mtl.sem); + } + _sg_mtl_garbage_collect(_sg.frame_index + SG_NUM_INFLIGHT_FRAMES + 2); + _sg_mtl_destroy_pool(); + _sg.mtl.valid = false; + + _SG_OBJC_RELEASE(_sg.mtl.sem); + _SG_OBJC_RELEASE(_sg.mtl.device); + _SG_OBJC_RELEASE(_sg.mtl.cmd_queue); + for (int i = 0; i < SG_NUM_INFLIGHT_FRAMES; i++) { + _SG_OBJC_RELEASE(_sg.mtl.uniform_buffers[i]); + } + // NOTE: MTLCommandBuffer, MTLRenderCommandEncoder and MTLComputeCommandEncoder are auto-released + _sg.mtl.cmd_buffer = nil; + _sg.mtl.render_cmd_encoder = nil; + _sg.mtl.compute_cmd_encoder = nil; +} + +_SOKOL_PRIVATE void _sg_mtl_reset_state_cache(void) { + _sg_mtl_clear_state_cache(); +} + +_SOKOL_PRIVATE sg_resource_state _sg_mtl_create_buffer(_sg_buffer_t* buf, const sg_buffer_desc* desc) { + SOKOL_ASSERT(buf && desc); + SOKOL_ASSERT(buf->cmn.size > 0); + const bool injected = (0 != desc->mtl_buffers[0]); + MTLResourceOptions mtl_options = _sg_mtl_buffer_resource_options(&buf->cmn.usage); + for (int slot = 0; slot < buf->cmn.num_slots; slot++) { + id mtl_buf; + if (injected) { + SOKOL_ASSERT(desc->mtl_buffers[slot]); + mtl_buf = (__bridge id) desc->mtl_buffers[slot]; + } else { + if (desc->data.ptr) { + SOKOL_ASSERT(desc->data.size > 0); + mtl_buf = [_sg.mtl.device newBufferWithBytes:desc->data.ptr length:(NSUInteger)buf->cmn.size options:mtl_options]; + } else { + mtl_buf = [_sg.mtl.device newBufferWithLength:(NSUInteger)buf->cmn.size options:mtl_options]; + } + if (nil == mtl_buf) { + _SG_ERROR(METAL_CREATE_BUFFER_FAILED); + return SG_RESOURCESTATE_FAILED; + } + } + #if defined(SOKOL_DEBUG) + if (desc->label) { + mtl_buf.label = [NSString stringWithFormat:@"%s.%d", desc->label, slot]; + } + #endif + buf->mtl.buf[slot] = _sg_mtl_add_resource(mtl_buf); + _SG_OBJC_RELEASE(mtl_buf); + } + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_mtl_discard_buffer(_sg_buffer_t* buf) { + SOKOL_ASSERT(buf); + for (int slot = 0; slot < buf->cmn.num_slots; slot++) { + // it's valid to call release resource with '0' + _sg_mtl_release_resource(_sg.frame_index, buf->mtl.buf[slot]); + } +} + +_SOKOL_PRIVATE void _sg_mtl_copy_image_data(const _sg_image_t* img, __unsafe_unretained id mtl_tex, const sg_image_data* data) { + const int num_slices = (img->cmn.type == SG_IMAGETYPE_3D) ? 1 : img->cmn.num_slices; + for (int mip_index = 0; mip_index < img->cmn.num_mipmaps; mip_index++) { + SOKOL_ASSERT(data->mip_levels[mip_index].ptr); + SOKOL_ASSERT(data->mip_levels[mip_index].size > 0); + const uint8_t* data_ptr = (const uint8_t*)data->mip_levels[mip_index].ptr; + const int mip_width = _sg_miplevel_dim(img->cmn.width, mip_index); + const int mip_height = _sg_miplevel_dim(img->cmn.height, mip_index); + int bytes_per_row = _sg_row_pitch(img->cmn.pixel_format, mip_width, 1); + int bytes_per_slice = _sg_surface_pitch(img->cmn.pixel_format, mip_width, mip_height, 1); + /* bytesPerImage special case: https://developer.apple.com/documentation/metal/mtltexture/1515679-replaceregion + + "Supply a nonzero value only when you copy data to a MTLTextureType3D type texture" + */ + MTLRegion region; + int bytes_per_image; + if (img->cmn.type == SG_IMAGETYPE_3D) { + const int mip_depth = _sg_miplevel_dim(img->cmn.num_slices, mip_index); + region = MTLRegionMake3D(0, 0, 0, (NSUInteger)mip_width, (NSUInteger)mip_height, (NSUInteger)mip_depth); + bytes_per_image = bytes_per_slice; + // FIXME: apparently the minimal bytes_per_image size for 3D texture is 4 KByte... somehow need to handle this + } else { + region = MTLRegionMake2D(0, 0, (NSUInteger)mip_width, (NSUInteger)mip_height); + bytes_per_image = 0; + } + + for (int slice_index = 0; slice_index < num_slices; slice_index++) { + const int slice_offset = slice_index * bytes_per_slice; + SOKOL_ASSERT((slice_offset + bytes_per_slice) <= (int)data->mip_levels[mip_index].size); + [mtl_tex replaceRegion:region + mipmapLevel:(NSUInteger)mip_index + slice:(NSUInteger)slice_index + withBytes:data_ptr + slice_offset + bytesPerRow:(NSUInteger)bytes_per_row + bytesPerImage:(NSUInteger)bytes_per_image]; + } + } +} + +_SOKOL_PRIVATE bool _sg_mtl_init_texdesc(MTLTextureDescriptor* mtl_desc, _sg_image_t* img) { + mtl_desc.textureType = _sg_mtl_texture_type(img->cmn.type, img->cmn.sample_count > 1); + mtl_desc.pixelFormat = _sg_mtl_pixel_format(img->cmn.pixel_format); + if (MTLPixelFormatInvalid == mtl_desc.pixelFormat) { + _SG_ERROR(METAL_TEXTURE_FORMAT_NOT_SUPPORTED); + return false; + } + mtl_desc.width = (NSUInteger)img->cmn.width; + mtl_desc.height = (NSUInteger)img->cmn.height; + if (SG_IMAGETYPE_3D == img->cmn.type) { + mtl_desc.depth = (NSUInteger)img->cmn.num_slices; + } else { + mtl_desc.depth = 1; + } + mtl_desc.mipmapLevelCount = (NSUInteger)img->cmn.num_mipmaps; + if (SG_IMAGETYPE_ARRAY == img->cmn.type) { + mtl_desc.arrayLength = (NSUInteger)img->cmn.num_slices; + } else { + mtl_desc.arrayLength = 1; + } + mtl_desc.sampleCount = (NSUInteger)img->cmn.sample_count; + + const sg_image_usage* usg = &img->cmn.usage; + const bool any_attachment = usg->color_attachment || usg->resolve_attachment || usg->depth_stencil_attachment; + MTLTextureUsage mtl_tex_usage = MTLTextureUsageShaderRead; + if (any_attachment) { + mtl_tex_usage |= MTLTextureUsageRenderTarget; + } + if (img->cmn.usage.storage_image) { + mtl_tex_usage |= MTLTextureUsageShaderWrite; + } + mtl_desc.usage = mtl_tex_usage; + + MTLResourceOptions mtl_res_options = 0; + if (any_attachment || img->cmn.usage.storage_image) { + mtl_res_options |= MTLResourceStorageModePrivate; + } else { + mtl_res_options |= _sg_mtl_resource_options_storage_mode_managed_or_shared(); + if (!img->cmn.usage.immutable) { + mtl_res_options |= MTLResourceCPUCacheModeWriteCombined; + } + } + mtl_desc.resourceOptions = mtl_res_options; + return true; +} + +_SOKOL_PRIVATE sg_resource_state _sg_mtl_create_image(_sg_image_t* img, const sg_image_desc* desc) { + SOKOL_ASSERT(img && desc); + const bool injected = (0 != desc->mtl_textures[0]); + + // first initialize all Metal resource pool slots to 'empty' + for (int i = 0; i < SG_NUM_INFLIGHT_FRAMES; i++) { + img->mtl.tex[i] = _sg_mtl_add_resource(nil); + } + + // initialize a Metal texture descriptor + MTLTextureDescriptor* mtl_desc = [[MTLTextureDescriptor alloc] init]; + if (!_sg_mtl_init_texdesc(mtl_desc, img)) { + _SG_OBJC_RELEASE(mtl_desc); + return SG_RESOURCESTATE_FAILED; + } + for (int slot = 0; slot < img->cmn.num_slots; slot++) { + id mtl_tex; + if (injected) { + SOKOL_ASSERT(desc->mtl_textures[slot]); + mtl_tex = (__bridge id) desc->mtl_textures[slot]; + } else { + mtl_tex = [_sg.mtl.device newTextureWithDescriptor:mtl_desc]; + if (nil == mtl_tex) { + _SG_OBJC_RELEASE(mtl_desc); + _SG_ERROR(METAL_CREATE_TEXTURE_FAILED); + return SG_RESOURCESTATE_FAILED; + } + if (desc->data.mip_levels[0].ptr) { + _sg_mtl_copy_image_data(img, mtl_tex, &desc->data); + } + } + #if defined(SOKOL_DEBUG) + if (desc->label) { + mtl_tex.label = [NSString stringWithFormat:@"%s.%d", desc->label, slot]; + } + #endif + img->mtl.tex[slot] = _sg_mtl_add_resource(mtl_tex); + _SG_OBJC_RELEASE(mtl_tex); + } + _SG_OBJC_RELEASE(mtl_desc); + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_mtl_discard_image(_sg_image_t* img) { + SOKOL_ASSERT(img); + // it's valid to call release resource with a 'null resource' + for (int slot = 0; slot < img->cmn.num_slots; slot++) { + _sg_mtl_release_resource(_sg.frame_index, img->mtl.tex[slot]); + } +} + +_SOKOL_PRIVATE sg_resource_state _sg_mtl_create_sampler(_sg_sampler_t* smp, const sg_sampler_desc* desc) { + SOKOL_ASSERT(smp && desc); + id mtl_smp; + const bool injected = (0 != desc->mtl_sampler); + if (injected) { + SOKOL_ASSERT(desc->mtl_sampler); + mtl_smp = (__bridge id) desc->mtl_sampler; + } else { + MTLSamplerDescriptor* mtl_desc = [[MTLSamplerDescriptor alloc] init]; + mtl_desc.sAddressMode = _sg_mtl_address_mode(desc->wrap_u); + mtl_desc.tAddressMode = _sg_mtl_address_mode(desc->wrap_v); + mtl_desc.rAddressMode = _sg_mtl_address_mode(desc->wrap_w); + if (_sg.features.image_clamp_to_border) { + if (@available(macOS 12.0, iOS 14.0, *)) { + mtl_desc.borderColor = _sg_mtl_border_color(desc->border_color); + } + } + mtl_desc.minFilter = _sg_mtl_minmag_filter(desc->min_filter); + mtl_desc.magFilter = _sg_mtl_minmag_filter(desc->mag_filter); + mtl_desc.mipFilter = _sg_mtl_mipmap_filter(desc->mipmap_filter); + mtl_desc.lodMinClamp = desc->min_lod; + mtl_desc.lodMaxClamp = desc->max_lod; + // FIXME: lodAverage? + mtl_desc.maxAnisotropy = desc->max_anisotropy; + mtl_desc.normalizedCoordinates = YES; + mtl_desc.compareFunction = _sg_mtl_compare_func(desc->compare); + #if defined(SOKOL_DEBUG) + if (desc->label) { + mtl_desc.label = [NSString stringWithUTF8String:desc->label]; + } + #endif + mtl_smp = [_sg.mtl.device newSamplerStateWithDescriptor:mtl_desc]; + _SG_OBJC_RELEASE(mtl_desc); + if (nil == mtl_smp) { + _SG_ERROR(METAL_CREATE_SAMPLER_FAILED); + return SG_RESOURCESTATE_FAILED; + } + } + smp->mtl.sampler_state = _sg_mtl_add_resource(mtl_smp); + _SG_OBJC_RELEASE(mtl_smp); + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_mtl_discard_sampler(_sg_sampler_t* smp) { + SOKOL_ASSERT(smp); + // it's valid to call release resource with a 'null resource' + _sg_mtl_release_resource(_sg.frame_index, smp->mtl.sampler_state); +} + +_SOKOL_PRIVATE id _sg_mtl_compile_library(const char* src) { + NSError* err = NULL; + id lib = [_sg.mtl.device + newLibraryWithSource:[NSString stringWithUTF8String:src] + options:nil + error:&err + ]; + if (err) { + _SG_ERROR(METAL_SHADER_COMPILATION_FAILED); + _SG_LOGMSG(METAL_SHADER_COMPILATION_OUTPUT, [err.localizedDescription UTF8String]); + } + return lib; +} + +_SOKOL_PRIVATE id _sg_mtl_library_from_bytecode(const void* ptr, size_t num_bytes) { + NSError* err = NULL; + dispatch_data_t lib_data = dispatch_data_create(ptr, num_bytes, NULL, DISPATCH_DATA_DESTRUCTOR_DEFAULT); + id lib = [_sg.mtl.device newLibraryWithData:lib_data error:&err]; + if (err) { + _SG_ERROR(METAL_SHADER_CREATION_FAILED); + _SG_LOGMSG(METAL_SHADER_COMPILATION_OUTPUT, [err.localizedDescription UTF8String]); + } + _SG_OBJC_RELEASE(lib_data); + return lib; +} + +_SOKOL_PRIVATE bool _sg_mtl_create_shader_func(const sg_shader_function* func, const char* label, const char* label_ext, _sg_mtl_shader_func_t* res) { + SOKOL_ASSERT(res->mtl_lib == _SG_MTL_INVALID_SLOT_INDEX); + SOKOL_ASSERT(res->mtl_func == _SG_MTL_INVALID_SLOT_INDEX); + id mtl_lib = nil; + if (func->bytecode.ptr) { + SOKOL_ASSERT(func->bytecode.size > 0); + mtl_lib = _sg_mtl_library_from_bytecode(func->bytecode.ptr, func->bytecode.size); + } else if (func->source) { + mtl_lib = _sg_mtl_compile_library(func->source); + } + if (mtl_lib == nil) { + return false; + } + #if defined(SOKOL_DEBUG) + if (label) { + SOKOL_ASSERT(label_ext); + mtl_lib.label = [NSString stringWithFormat:@"%s.%s", label, label_ext]; + } + #else + _SOKOL_UNUSED(label); + _SOKOL_UNUSED(label_ext); + #endif + SOKOL_ASSERT(func->entry); + id mtl_func = [mtl_lib newFunctionWithName:[NSString stringWithUTF8String:func->entry]]; + if (mtl_func == nil) { + _SG_ERROR(METAL_SHADER_ENTRY_NOT_FOUND); + _SG_OBJC_RELEASE(mtl_lib); + return false; + } + res->mtl_lib = _sg_mtl_add_resource(mtl_lib); + res->mtl_func = _sg_mtl_add_resource(mtl_func); + _SG_OBJC_RELEASE(mtl_lib); + _SG_OBJC_RELEASE(mtl_func); + return true; +} + +_SOKOL_PRIVATE void _sg_mtl_discard_shader_func(const _sg_mtl_shader_func_t* func) { + // it is valid to call _sg_mtl_release_resource with a 'null resource' + _sg_mtl_release_resource(_sg.frame_index, func->mtl_func); + _sg_mtl_release_resource(_sg.frame_index, func->mtl_lib); +} + +// NOTE: this is an out-of-range check for MSL bindslots that's also active in release mode +_SOKOL_PRIVATE bool _sg_mtl_ensure_msl_bindslot_ranges(const sg_shader_desc* desc) { + SOKOL_ASSERT(desc); + for (size_t i = 0; i < SG_MAX_UNIFORMBLOCK_BINDSLOTS; i++) { + const sg_shader_uniform_block* ub = &desc->uniform_blocks[i]; + if (ub->stage != SG_SHADERSTAGE_NONE) { + if (ub->msl_buffer_n >= _SG_MTL_MAX_STAGE_UB_BINDINGS) { + _SG_ERROR(METAL_UNIFORMBLOCK_MSL_BUFFER_SLOT_OUT_OF_RANGE); + return false; + } + } + } + for (size_t i = 0; i < SG_MAX_VIEW_BINDSLOTS; i++) { + const sg_shader_view* view = &desc->views[i]; + if (view->texture.stage != SG_SHADERSTAGE_NONE) { + if (view->texture.msl_texture_n >= _SG_MTL_MAX_STAGE_TEXTURE_BINDINGS) { + _SG_ERROR(METAL_IMAGE_MSL_TEXTURE_SLOT_OUT_OF_RANGE); + return false; + } + } + if (view->storage_buffer.stage != SG_SHADERSTAGE_NONE) { + if ((view->storage_buffer.msl_buffer_n < _SG_MTL_MAX_STAGE_UB_BINDINGS) || + (view->storage_buffer.msl_buffer_n >= _SG_MTL_MAX_STAGE_UB_SBUF_BINDINGS)) + { + _SG_ERROR(METAL_STORAGEBUFFER_MSL_BUFFER_SLOT_OUT_OF_RANGE); + return false; + } + } + if (view->storage_image.stage != SG_SHADERSTAGE_NONE) { + if (view->storage_image.msl_texture_n >= _SG_MTL_MAX_STAGE_TEXTURE_BINDINGS) { + _SG_ERROR(METAL_STORAGEIMAGE_MSL_TEXTURE_SLOT_OUT_OF_RANGE); + return false; + } + } + } + for (size_t i = 0; i < SG_MAX_SAMPLER_BINDSLOTS; i++) { + const sg_shader_sampler* smp = &desc->samplers[i]; + if (smp->stage != SG_SHADERSTAGE_NONE) { + if (smp->msl_sampler_n >= _SG_MTL_MAX_STAGE_SAMPLER_BINDINGS) { + _SG_ERROR(METAL_SAMPLER_MSL_SAMPLER_SLOT_OUT_OF_RANGE); + return false; + } + } + } + return true; +} + +_SOKOL_PRIVATE sg_resource_state _sg_mtl_create_shader(_sg_shader_t* shd, const sg_shader_desc* desc) { + SOKOL_ASSERT(shd && desc); + + // do a MSL bindslot range check also in release mode, and if that fails, + // also fail shader creation + if (!_sg_mtl_ensure_msl_bindslot_ranges(desc)) { + return SG_RESOURCESTATE_FAILED; + } + + shd->mtl.threads_per_threadgroup = MTLSizeMake( + (NSUInteger)desc->mtl_threads_per_threadgroup.x, + (NSUInteger)desc->mtl_threads_per_threadgroup.y, + (NSUInteger)desc->mtl_threads_per_threadgroup.z); + + // copy resource bindslot mappings + for (size_t i = 0; i < SG_MAX_UNIFORMBLOCK_BINDSLOTS; i++) { + shd->mtl.ub_buffer_n[i] = desc->uniform_blocks[i].msl_buffer_n; + } + for (size_t i = 0; i < SG_MAX_VIEW_BINDSLOTS; i++) { + const sg_shader_view* view = &desc->views[i]; + SOKOL_ASSERT(0 == shd->mtl.view_buffer_texture_n[i]); + if (view->storage_buffer.stage != SG_SHADERSTAGE_NONE) { + shd->mtl.view_buffer_texture_n[i] = view->storage_buffer.msl_buffer_n; + } else if (view->texture.stage != SG_SHADERSTAGE_NONE) { + shd->mtl.view_buffer_texture_n[i] = view->texture.msl_texture_n; + } else if (view->storage_image.stage != SG_SHADERSTAGE_NONE) { + shd->mtl.view_buffer_texture_n[i] = view->storage_image.msl_texture_n; + } + } + for (size_t i = 0; i < SG_MAX_SAMPLER_BINDSLOTS; i++) { + shd->mtl.smp_sampler_n[i] = desc->samplers[i].msl_sampler_n; + } + + // create metal library and function objects + bool shd_valid = true; + if (desc->vertex_func.source || desc->vertex_func.bytecode.ptr) { + shd_valid &= _sg_mtl_create_shader_func(&desc->vertex_func, desc->label, "vs", &shd->mtl.vertex_func); + } + if (desc->fragment_func.source || desc->fragment_func.bytecode.ptr) { + shd_valid &= _sg_mtl_create_shader_func(&desc->fragment_func, desc->label, "fs", &shd->mtl.fragment_func); + } + if (desc->compute_func.source || desc->compute_func.bytecode.ptr) { + shd_valid &= _sg_mtl_create_shader_func(&desc->compute_func, desc->label, "cs", &shd->mtl.compute_func); + } + if (!shd_valid) { + _sg_mtl_discard_shader_func(&shd->mtl.vertex_func); + _sg_mtl_discard_shader_func(&shd->mtl.fragment_func); + _sg_mtl_discard_shader_func(&shd->mtl.compute_func); + } + return shd_valid ? SG_RESOURCESTATE_VALID : SG_RESOURCESTATE_FAILED; +} + +_SOKOL_PRIVATE void _sg_mtl_discard_shader(_sg_shader_t* shd) { + SOKOL_ASSERT(shd); + _sg_mtl_discard_shader_func(&shd->mtl.vertex_func); + _sg_mtl_discard_shader_func(&shd->mtl.fragment_func); + _sg_mtl_discard_shader_func(&shd->mtl.compute_func); +} + +_SOKOL_PRIVATE sg_resource_state _sg_mtl_create_pipeline(_sg_pipeline_t* pip, const sg_pipeline_desc* desc) { + SOKOL_ASSERT(pip && desc); + _sg_shader_t* shd = _sg_shader_ref_ptr(&pip->cmn.shader); + if (pip->cmn.is_compute) { + NSError* err = NULL; + MTLComputePipelineDescriptor* cp_desc = [[MTLComputePipelineDescriptor alloc] init]; + cp_desc.computeFunction = _sg_mtl_id(shd->mtl.compute_func.mtl_func); + cp_desc.threadGroupSizeIsMultipleOfThreadExecutionWidth = true; + for (size_t i = 0; i < SG_MAX_VIEW_BINDSLOTS; i++) { + const _sg_shader_view_t* view = &shd->cmn.views[i]; + if (view->view_type != SG_VIEWTYPE_STORAGEBUFFER) { + continue; + } + if (!view->sbuf_readonly) { + continue; + } + SOKOL_ASSERT(view->stage == SG_SHADERSTAGE_COMPUTE); + const NSUInteger mtl_slot = shd->mtl.view_buffer_texture_n[i]; + SOKOL_ASSERT(mtl_slot < _SG_MTL_MAX_STAGE_BUFFER_BINDINGS); + cp_desc.buffers[mtl_slot].mutability = MTLMutabilityImmutable; + } + #if defined(SOKOL_DEBUG) + if (desc->label) { + cp_desc.label = [NSString stringWithFormat:@"%s", desc->label]; + } + #endif + id mtl_cps = [_sg.mtl.device + newComputePipelineStateWithDescriptor:cp_desc + options:MTLPipelineOptionNone + reflection:nil + error:&err]; + _SG_OBJC_RELEASE(cp_desc); + if (nil == mtl_cps) { + SOKOL_ASSERT(err); + _SG_ERROR(METAL_CREATE_CPS_FAILED); + _SG_LOGMSG(METAL_CREATE_CPS_OUTPUT, [err.localizedDescription UTF8String]); + return SG_RESOURCESTATE_FAILED; + } + pip->mtl.cps = _sg_mtl_add_resource(mtl_cps); + _SG_OBJC_RELEASE(mtl_cps); + pip->mtl.threads_per_threadgroup = shd->mtl.threads_per_threadgroup; + } else { + sg_primitive_type prim_type = desc->primitive_type; + pip->mtl.prim_type = _sg_mtl_primitive_type(prim_type); + pip->mtl.index_size = _sg_mtl_index_size(pip->cmn.index_type); + if (SG_INDEXTYPE_NONE != pip->cmn.index_type) { + pip->mtl.index_type = _sg_mtl_index_type(pip->cmn.index_type); + } + pip->mtl.cull_mode = _sg_mtl_cull_mode(desc->cull_mode); + pip->mtl.winding = _sg_mtl_winding(desc->face_winding); + pip->mtl.stencil_ref = desc->stencil.ref; + + // create vertex-descriptor + MTLVertexDescriptor* vtx_desc = [MTLVertexDescriptor vertexDescriptor]; + for (NSUInteger attr_index = 0; attr_index < SG_MAX_VERTEX_ATTRIBUTES; attr_index++) { + const sg_vertex_attr_state* a_state = &desc->layout.attrs[attr_index]; + if (a_state->format == SG_VERTEXFORMAT_INVALID) { + break; + } + SOKOL_ASSERT(a_state->buffer_index < SG_MAX_VERTEXBUFFER_BINDSLOTS); + SOKOL_ASSERT(pip->cmn.vertex_buffer_layout_active[a_state->buffer_index]); + vtx_desc.attributes[attr_index].format = _sg_mtl_vertex_format(a_state->format); + vtx_desc.attributes[attr_index].offset = (NSUInteger)a_state->offset; + vtx_desc.attributes[attr_index].bufferIndex = _sg_mtl_vertexbuffer_bindslot((size_t)a_state->buffer_index); + } + for (NSUInteger layout_index = 0; layout_index < SG_MAX_VERTEXBUFFER_BINDSLOTS; layout_index++) { + if (pip->cmn.vertex_buffer_layout_active[layout_index]) { + const sg_vertex_buffer_layout_state* l_state = &desc->layout.buffers[layout_index]; + const NSUInteger mtl_vb_slot = _sg_mtl_vertexbuffer_bindslot(layout_index); + SOKOL_ASSERT(l_state->stride > 0); + vtx_desc.layouts[mtl_vb_slot].stride = (NSUInteger)l_state->stride; + vtx_desc.layouts[mtl_vb_slot].stepFunction = _sg_mtl_step_function(l_state->step_func); + vtx_desc.layouts[mtl_vb_slot].stepRate = (NSUInteger)l_state->step_rate; + } + } + + // render-pipeline descriptor + MTLRenderPipelineDescriptor* rp_desc = [[MTLRenderPipelineDescriptor alloc] init]; + rp_desc.vertexDescriptor = vtx_desc; + SOKOL_ASSERT(shd->mtl.vertex_func.mtl_func != _SG_MTL_INVALID_SLOT_INDEX); + rp_desc.vertexFunction = _sg_mtl_id(shd->mtl.vertex_func.mtl_func); + SOKOL_ASSERT(shd->mtl.fragment_func.mtl_func != _SG_MTL_INVALID_SLOT_INDEX); + rp_desc.fragmentFunction = _sg_mtl_id(shd->mtl.fragment_func.mtl_func); + rp_desc.rasterSampleCount = (NSUInteger)desc->sample_count; + rp_desc.alphaToCoverageEnabled = desc->alpha_to_coverage_enabled; + rp_desc.alphaToOneEnabled = NO; + rp_desc.rasterizationEnabled = YES; + rp_desc.depthAttachmentPixelFormat = _sg_mtl_pixel_format(desc->depth.pixel_format); + if (desc->depth.pixel_format == SG_PIXELFORMAT_DEPTH_STENCIL) { + rp_desc.stencilAttachmentPixelFormat = _sg_mtl_pixel_format(desc->depth.pixel_format); + } + for (NSUInteger i = 0; i < (NSUInteger)desc->color_count; i++) { + SOKOL_ASSERT(i < SG_MAX_COLOR_ATTACHMENTS); + const sg_color_target_state* cs = &desc->colors[i]; + rp_desc.colorAttachments[i].pixelFormat = _sg_mtl_pixel_format(cs->pixel_format); + rp_desc.colorAttachments[i].writeMask = _sg_mtl_color_write_mask(cs->write_mask); + rp_desc.colorAttachments[i].blendingEnabled = cs->blend.enabled; + rp_desc.colorAttachments[i].alphaBlendOperation = _sg_mtl_blend_op(cs->blend.op_alpha); + rp_desc.colorAttachments[i].rgbBlendOperation = _sg_mtl_blend_op(cs->blend.op_rgb); + rp_desc.colorAttachments[i].destinationAlphaBlendFactor = _sg_mtl_blend_factor(cs->blend.dst_factor_alpha); + rp_desc.colorAttachments[i].destinationRGBBlendFactor = _sg_mtl_blend_factor(cs->blend.dst_factor_rgb); + rp_desc.colorAttachments[i].sourceAlphaBlendFactor = _sg_mtl_blend_factor(cs->blend.src_factor_alpha); + rp_desc.colorAttachments[i].sourceRGBBlendFactor = _sg_mtl_blend_factor(cs->blend.src_factor_rgb); + } + // Set buffer mutability for all buffers (vertex buffers and storage buffers). + // For vertex buffer it is guaranteed that neither the GPU nor CPU will update their content + // as long as it is in flight (since dynamic buffers are double-buffered, and vertex-buffers + // are not updated by the GPU). + // For storage buffer the same double-buffering applies, and if they are applied + // to the vertex- or fragment-stage must be declared as readonly in the shader. + for (size_t i = 0; i < SG_MAX_VERTEXBUFFER_BINDSLOTS; i++) { + if (pip->cmn.vertex_buffer_layout_active[i]) { + const NSUInteger mtl_slot = _sg_mtl_vertexbuffer_bindslot(i); + rp_desc.vertexBuffers[mtl_slot].mutability = MTLMutabilityImmutable; + } + } + for (size_t i = 0; i < SG_MAX_VIEW_BINDSLOTS; i++) { + const _sg_shader_view_t* view = &shd->cmn.views[i]; + if (view->view_type != SG_VIEWTYPE_STORAGEBUFFER) { + continue; + } + const sg_shader_stage stage = view->stage; + SOKOL_ASSERT(view->stage != SG_SHADERSTAGE_COMPUTE); + SOKOL_ASSERT(view->sbuf_readonly); + const NSUInteger mtl_slot = shd->mtl.view_buffer_texture_n[i]; + SOKOL_ASSERT(mtl_slot < _SG_MTL_MAX_STAGE_BUFFER_BINDINGS); + if (stage == SG_SHADERSTAGE_VERTEX) { + rp_desc.vertexBuffers[mtl_slot].mutability = MTLMutabilityImmutable; + } else if (stage == SG_SHADERSTAGE_FRAGMENT) { + rp_desc.fragmentBuffers[mtl_slot].mutability = MTLMutabilityImmutable; + } + } + #if defined(SOKOL_DEBUG) + if (desc->label) { + rp_desc.label = [NSString stringWithFormat:@"%s", desc->label]; + } + #endif + NSError* err = NULL; + id mtl_rps = [_sg.mtl.device newRenderPipelineStateWithDescriptor:rp_desc error:&err]; + _SG_OBJC_RELEASE(rp_desc); + if (nil == mtl_rps) { + SOKOL_ASSERT(err); + _SG_ERROR(METAL_CREATE_RPS_FAILED); + _SG_LOGMSG(METAL_CREATE_RPS_OUTPUT, [err.localizedDescription UTF8String]); + return SG_RESOURCESTATE_FAILED; + } + pip->mtl.rps = _sg_mtl_add_resource(mtl_rps); + _SG_OBJC_RELEASE(mtl_rps); + + // depth-stencil-state + MTLDepthStencilDescriptor* ds_desc = [[MTLDepthStencilDescriptor alloc] init]; + ds_desc.depthCompareFunction = _sg_mtl_compare_func(desc->depth.compare); + ds_desc.depthWriteEnabled = desc->depth.write_enabled; + if (desc->stencil.enabled) { + const sg_stencil_face_state* sb = &desc->stencil.back; + ds_desc.backFaceStencil = [[MTLStencilDescriptor alloc] init]; + ds_desc.backFaceStencil.stencilFailureOperation = _sg_mtl_stencil_op(sb->fail_op); + ds_desc.backFaceStencil.depthFailureOperation = _sg_mtl_stencil_op(sb->depth_fail_op); + ds_desc.backFaceStencil.depthStencilPassOperation = _sg_mtl_stencil_op(sb->pass_op); + ds_desc.backFaceStencil.stencilCompareFunction = _sg_mtl_compare_func(sb->compare); + ds_desc.backFaceStencil.readMask = desc->stencil.read_mask; + ds_desc.backFaceStencil.writeMask = desc->stencil.write_mask; + const sg_stencil_face_state* sf = &desc->stencil.front; + ds_desc.frontFaceStencil = [[MTLStencilDescriptor alloc] init]; + ds_desc.frontFaceStencil.stencilFailureOperation = _sg_mtl_stencil_op(sf->fail_op); + ds_desc.frontFaceStencil.depthFailureOperation = _sg_mtl_stencil_op(sf->depth_fail_op); + ds_desc.frontFaceStencil.depthStencilPassOperation = _sg_mtl_stencil_op(sf->pass_op); + ds_desc.frontFaceStencil.stencilCompareFunction = _sg_mtl_compare_func(sf->compare); + ds_desc.frontFaceStencil.readMask = desc->stencil.read_mask; + ds_desc.frontFaceStencil.writeMask = desc->stencil.write_mask; + } + #if defined(SOKOL_DEBUG) + if (desc->label) { + ds_desc.label = [NSString stringWithFormat:@"%s.dss", desc->label]; + } + #endif + id mtl_dss = [_sg.mtl.device newDepthStencilStateWithDescriptor:ds_desc]; + _SG_OBJC_RELEASE(ds_desc); + if (nil == mtl_dss) { + _SG_ERROR(METAL_CREATE_DSS_FAILED); + return SG_RESOURCESTATE_FAILED; + } + pip->mtl.dss = _sg_mtl_add_resource(mtl_dss); + _SG_OBJC_RELEASE(mtl_dss); + } + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_mtl_discard_pipeline(_sg_pipeline_t* pip) { + SOKOL_ASSERT(pip); + // it's valid to call release resource with a 'null resource' + _sg_mtl_release_resource(_sg.frame_index, pip->mtl.cps); + _sg_mtl_release_resource(_sg.frame_index, pip->mtl.rps); + _sg_mtl_release_resource(_sg.frame_index, pip->mtl.dss); +} + +_SOKOL_PRIVATE sg_resource_state _sg_mtl_create_view(_sg_view_t* view, const sg_view_desc* desc) { + SOKOL_ASSERT(view && desc); + _SOKOL_UNUSED(desc); + if ((SG_VIEWTYPE_TEXTURE == view->cmn.type) || (SG_VIEWTYPE_STORAGEIMAGE == view->cmn.type)) { + const _sg_image_view_common_t* cmn = &view->cmn.img; + const _sg_image_t* img = _sg_image_ref_ptr(&cmn->ref); + SOKOL_ASSERT(cmn->mip_level_count >= 1); + SOKOL_ASSERT(cmn->slice_count >= 1); + for (int slot = 0; slot < img->cmn.num_slots; slot++) { + SOKOL_ASSERT(img->mtl.tex[slot] != _SG_MTL_INVALID_SLOT_INDEX); + id mtl_tex_view = [_sg_mtl_id(img->mtl.tex[slot]) + newTextureViewWithPixelFormat: _sg_mtl_pixel_format(img->cmn.pixel_format) + textureType: _sg_mtl_texture_type(img->cmn.type, img->cmn.sample_count > 1) + levels: NSMakeRange((NSUInteger)cmn->mip_level, (NSUInteger)cmn->mip_level_count) + slices: NSMakeRange((NSUInteger)cmn->slice, (NSUInteger)cmn->slice_count)]; + #if defined(SOKOL_DEBUG) + if (desc->label) { + mtl_tex_view.label = [NSString stringWithFormat:@"%s.%d", desc->label, slot]; + } + #endif + view->mtl.tex_view[slot] = _sg_mtl_add_resource(mtl_tex_view); + _SG_OBJC_RELEASE(mtl_tex_view); + } + } + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_mtl_discard_view(_sg_view_t* view) { + SOKOL_ASSERT(view); + for (size_t i = 0; i < SG_NUM_INFLIGHT_FRAMES; i++) { + // it's valid to call _sg_mtl_release_resource with a null handle + _sg_mtl_release_resource(_sg.frame_index, view->mtl.tex_view[i]); + } +} + +_SOKOL_PRIVATE void _sg_mtl_bind_uniform_buffers(void) { + // In the Metal backend, uniform buffer bindings happen once in sg_begin_pass() and + // remain valid for the entire pass. Only binding offsets will be updated + // in sg_apply_uniforms() + if (_sg.cur_pass.is_compute) { + SOKOL_ASSERT(nil != _sg.mtl.compute_cmd_encoder); + for (size_t slot = 0; slot < SG_MAX_UNIFORMBLOCK_BINDSLOTS; slot++) { + [_sg.mtl.compute_cmd_encoder + setBuffer:_sg.mtl.uniform_buffers[_sg.mtl.cur_frame_rotate_index] + offset:0 + atIndex:slot]; + } + } else { + SOKOL_ASSERT(nil != _sg.mtl.render_cmd_encoder); + for (size_t slot = 0; slot < SG_MAX_UNIFORMBLOCK_BINDSLOTS; slot++) { + [_sg.mtl.render_cmd_encoder + setVertexBuffer:_sg.mtl.uniform_buffers[_sg.mtl.cur_frame_rotate_index] + offset:0 + atIndex:slot]; + [_sg.mtl.render_cmd_encoder + setFragmentBuffer:_sg.mtl.uniform_buffers[_sg.mtl.cur_frame_rotate_index] + offset:0 + atIndex:slot]; + } + } +} + +_SOKOL_PRIVATE void _sg_mtl_begin_compute_pass(const sg_pass* pass) { + SOKOL_ASSERT(pass); (void)pass; + SOKOL_ASSERT(nil != _sg.mtl.cmd_buffer); + SOKOL_ASSERT(nil == _sg.mtl.compute_cmd_encoder); + SOKOL_ASSERT(nil == _sg.mtl.render_cmd_encoder); + + _sg.mtl.compute_cmd_encoder = [_sg.mtl.cmd_buffer computeCommandEncoder]; + if (nil == _sg.mtl.compute_cmd_encoder) { + _sg.cur_pass.valid = false; + return; + } + + #if defined(SOKOL_DEBUG) + if (pass->label) { + _sg.mtl.compute_cmd_encoder.label = [NSString stringWithUTF8String:pass->label]; + } + #endif +} + +_SOKOL_PRIVATE void _sg_mtl_begin_render_pass(const sg_pass* pass, const _sg_attachments_ptrs_t* atts) { + SOKOL_ASSERT(pass && atts); + SOKOL_ASSERT(nil != _sg.mtl.cmd_buffer); + SOKOL_ASSERT(nil == _sg.mtl.render_cmd_encoder); + SOKOL_ASSERT(nil == _sg.mtl.compute_cmd_encoder); + + const sg_swapchain* swapchain = &pass->swapchain; + const sg_pass_action* action = &pass->action; + + MTLRenderPassDescriptor* pass_desc = [MTLRenderPassDescriptor renderPassDescriptor]; + SOKOL_ASSERT(pass_desc); + if (!atts->empty) { + // setup pass descriptor for offscreen rendering + for (NSUInteger i = 0; i < (NSUInteger)atts->num_color_views; i++) { + const _sg_view_t* color_view = atts->color_views[i]; + SOKOL_ASSERT(color_view); + const _sg_view_t* resolve_view = atts->resolve_views[i]; + const _sg_image_t* color_img = _sg_image_ref_ptr(&color_view->cmn.img.ref); + SOKOL_ASSERT(color_img->slot.state == SG_RESOURCESTATE_VALID); + SOKOL_ASSERT(color_img->cmn.active_slot == 0); + SOKOL_ASSERT(color_img->mtl.tex[0] != _SG_MTL_INVALID_SLOT_INDEX); + pass_desc.colorAttachments[i].loadAction = _sg_mtl_load_action(action->colors[i].load_action); + pass_desc.colorAttachments[i].storeAction = _sg_mtl_store_action(action->colors[i].store_action, resolve_view != 0); + sg_color c = action->colors[i].clear_value; + pass_desc.colorAttachments[i].clearColor = MTLClearColorMake(c.r, c.g, c.b, c.a); + pass_desc.colorAttachments[i].texture = _sg_mtl_id(color_img->mtl.tex[0]); + pass_desc.colorAttachments[i].level = (NSUInteger)color_view->cmn.img.mip_level; + switch (color_img->cmn.type) { + case SG_IMAGETYPE_CUBE: + case SG_IMAGETYPE_ARRAY: + pass_desc.colorAttachments[i].slice = (NSUInteger)color_view->cmn.img.slice; + break; + case SG_IMAGETYPE_3D: + pass_desc.colorAttachments[i].depthPlane = (NSUInteger)color_view->cmn.img.slice; + break; + default: break; + } + if (resolve_view) { + const _sg_image_t* resolve_img = _sg_image_ref_ptr(&resolve_view->cmn.img.ref); + SOKOL_ASSERT(resolve_img->slot.state == SG_RESOURCESTATE_VALID); + SOKOL_ASSERT(resolve_img->cmn.active_slot == 0); + SOKOL_ASSERT(resolve_img->mtl.tex[0] != _SG_MTL_INVALID_SLOT_INDEX); + pass_desc.colorAttachments[i].resolveTexture = _sg_mtl_id(resolve_img->mtl.tex[0]); + pass_desc.colorAttachments[i].resolveLevel = (NSUInteger)resolve_view->cmn.img.mip_level; + switch (resolve_img->cmn.type) { + case SG_IMAGETYPE_CUBE: + case SG_IMAGETYPE_ARRAY: + pass_desc.colorAttachments[i].resolveSlice = (NSUInteger)resolve_view->cmn.img.slice; + break; + case SG_IMAGETYPE_3D: + pass_desc.colorAttachments[i].resolveDepthPlane = (NSUInteger)resolve_view->cmn.img.slice; + break; + default: break; + } + } + } + if (atts->ds_view) { + const _sg_view_t* ds_view = atts->ds_view; + const _sg_image_t* ds_img = _sg_image_ref_ptr(&ds_view->cmn.img.ref); + SOKOL_ASSERT(ds_img->slot.state == SG_RESOURCESTATE_VALID); + SOKOL_ASSERT(ds_img->cmn.active_slot == 0); + SOKOL_ASSERT(ds_img->mtl.tex[0] != _SG_MTL_INVALID_SLOT_INDEX); + pass_desc.depthAttachment.texture = _sg_mtl_id(ds_img->mtl.tex[0]); + pass_desc.depthAttachment.loadAction = _sg_mtl_load_action(action->depth.load_action); + pass_desc.depthAttachment.storeAction = _sg_mtl_store_action(action->depth.store_action, false); + pass_desc.depthAttachment.clearDepth = action->depth.clear_value; + switch (ds_img->cmn.type) { + case SG_IMAGETYPE_CUBE: + case SG_IMAGETYPE_ARRAY: + pass_desc.depthAttachment.slice = (NSUInteger)ds_view->cmn.img.slice; + break; + case SG_IMAGETYPE_3D: + pass_desc.depthAttachment.resolveDepthPlane = (NSUInteger)ds_view->cmn.img.slice; + break; + default: break; + } + if (_sg_is_depth_stencil_format(ds_img->cmn.pixel_format)) { + pass_desc.stencilAttachment.texture = _sg_mtl_id(ds_img->mtl.tex[0]); + pass_desc.stencilAttachment.loadAction = _sg_mtl_load_action(action->stencil.load_action); + pass_desc.stencilAttachment.storeAction = _sg_mtl_store_action(action->depth.store_action, false); + pass_desc.stencilAttachment.clearStencil = action->stencil.clear_value; + switch (ds_img->cmn.type) { + case SG_IMAGETYPE_CUBE: + case SG_IMAGETYPE_ARRAY: + pass_desc.stencilAttachment.slice = (NSUInteger)ds_view->cmn.img.slice; + break; + case SG_IMAGETYPE_3D: + pass_desc.stencilAttachment.resolveDepthPlane = (NSUInteger)ds_view->cmn.img.slice; + break; + default: break; + } + } + } + } else { + // setup pass descriptor for swapchain rendering + // + // NOTE: at least in macOS Sonoma this no longer seems to be the case, the + // current drawable is also valid in a minimized window + // === + // an MTKView current_drawable will not be valid if window is minimized, don't do any rendering in this case + if (0 == swapchain->metal.current_drawable) { + _sg.cur_pass.valid = false; + return; + } + // pin the swapchain resources into memory so that they outlive their command buffer + // (this is necessary because the command buffer doesn't retain references) + int pass_desc_ref = _sg_mtl_add_resource(pass_desc); + _sg_mtl_release_resource(_sg.frame_index, pass_desc_ref); + + _sg.mtl.cur_drawable = (__bridge id) swapchain->metal.current_drawable; + if (swapchain->sample_count > 1) { + // multi-sampling: render into msaa texture, resolve into drawable texture + id msaa_tex = (__bridge id) swapchain->metal.msaa_color_texture; + SOKOL_ASSERT(msaa_tex != nil); + pass_desc.colorAttachments[0].texture = msaa_tex; + pass_desc.colorAttachments[0].resolveTexture = _sg.mtl.cur_drawable.texture; + pass_desc.colorAttachments[0].storeAction = MTLStoreActionMultisampleResolve; + } else { + // non-msaa: render into current_drawable + pass_desc.colorAttachments[0].texture = _sg.mtl.cur_drawable.texture; + pass_desc.colorAttachments[0].storeAction = MTLStoreActionStore; + } + pass_desc.colorAttachments[0].loadAction = _sg_mtl_load_action(action->colors[0].load_action); + const sg_color c = action->colors[0].clear_value; + pass_desc.colorAttachments[0].clearColor = MTLClearColorMake(c.r, c.g, c.b, c.a); + + // optional depth-stencil texture + if (swapchain->metal.depth_stencil_texture) { + id ds_tex = (__bridge id) swapchain->metal.depth_stencil_texture; + SOKOL_ASSERT(ds_tex != nil); + pass_desc.depthAttachment.texture = ds_tex; + pass_desc.depthAttachment.storeAction = MTLStoreActionDontCare; + pass_desc.depthAttachment.loadAction = _sg_mtl_load_action(action->depth.load_action); + pass_desc.depthAttachment.clearDepth = action->depth.clear_value; + if (_sg_is_depth_stencil_format(swapchain->depth_format)) { + pass_desc.stencilAttachment.texture = ds_tex; + pass_desc.stencilAttachment.storeAction = MTLStoreActionDontCare; + pass_desc.stencilAttachment.loadAction = _sg_mtl_load_action(action->stencil.load_action); + pass_desc.stencilAttachment.clearStencil = action->stencil.clear_value; + } + } + } + + // NOTE: at least in macOS Sonoma, the following is no longer the case, a valid + // render command encoder is also returned in a minimized window + // === + // create a render command encoder, this might return nil if window is minimized + _sg.mtl.render_cmd_encoder = [_sg.mtl.cmd_buffer renderCommandEncoderWithDescriptor:pass_desc]; + if (nil == _sg.mtl.render_cmd_encoder) { + _sg.cur_pass.valid = false; + return; + } + + #if defined(SOKOL_DEBUG) + if (pass->label) { + _sg.mtl.render_cmd_encoder.label = [NSString stringWithUTF8String:pass->label]; + } + #endif +} + +_SOKOL_PRIVATE void _sg_mtl_begin_pass(const sg_pass* pass, const _sg_attachments_ptrs_t* atts) { + SOKOL_ASSERT(pass && atts); + SOKOL_ASSERT(_sg.mtl.cmd_queue); + SOKOL_ASSERT(nil == _sg.mtl.compute_cmd_encoder); + SOKOL_ASSERT(nil == _sg.mtl.render_cmd_encoder); + SOKOL_ASSERT(nil == _sg.mtl.cur_drawable); + _sg_mtl_clear_state_cache(); + + // if this is the first pass in the frame, create one command buffer and blit-cmd-encoder for the entire frame + if (nil == _sg.mtl.cmd_buffer) { + // block until the oldest frame in flight has finished + dispatch_semaphore_wait(_sg.mtl.sem, DISPATCH_TIME_FOREVER); + if (_sg.desc.metal.use_command_buffer_with_retained_references) { + _sg.mtl.cmd_buffer = [_sg.mtl.cmd_queue commandBuffer]; + } else { + _sg.mtl.cmd_buffer = [_sg.mtl.cmd_queue commandBufferWithUnretainedReferences]; + } + [_sg.mtl.cmd_buffer enqueue]; + [_sg.mtl.cmd_buffer addCompletedHandler:^(id cmd_buf) { + // NOTE: this code is called on a different thread! + _SOKOL_UNUSED(cmd_buf); + dispatch_semaphore_signal(_sg.mtl.sem); + }]; + } + + // if this is first pass in frame, get uniform buffer base pointer + if (0 == _sg.mtl.cur_ub_base_ptr) { + _sg.mtl.cur_ub_base_ptr = (uint8_t*)[_sg.mtl.uniform_buffers[_sg.mtl.cur_frame_rotate_index] contents]; + } + + if (pass->compute) { + _sg_mtl_begin_compute_pass(pass); + } else { + _sg_mtl_begin_render_pass(pass, atts); + } + + // bind uniform buffers, those bindings remain valid for the entire pass + if (_sg.cur_pass.valid) { + _sg_mtl_bind_uniform_buffers(); + } +} + +_SOKOL_PRIVATE void _sg_mtl_end_pass(const _sg_attachments_ptrs_t* atts) { + _SOKOL_UNUSED(atts); + if (nil != _sg.mtl.render_cmd_encoder) { + [_sg.mtl.render_cmd_encoder endEncoding]; + // NOTE: MTLRenderCommandEncoder is autoreleased + _sg.mtl.render_cmd_encoder = nil; + } + if (nil != _sg.mtl.compute_cmd_encoder) { + [_sg.mtl.compute_cmd_encoder endEncoding]; + // NOTE: MTLComputeCommandEncoder is autoreleased + _sg.mtl.compute_cmd_encoder = nil; + } + // if this is a swapchain pass, present the drawable + if (nil != _sg.mtl.cur_drawable) { + [_sg.mtl.cmd_buffer presentDrawable:_sg.mtl.cur_drawable]; + _sg.mtl.cur_drawable = nil; + } +} + +_SOKOL_PRIVATE void _sg_mtl_commit(void) { + SOKOL_ASSERT(nil == _sg.mtl.render_cmd_encoder); + SOKOL_ASSERT(nil == _sg.mtl.compute_cmd_encoder); + + // commit the frame's command buffer + if (_sg.mtl.cmd_buffer) { + [_sg.mtl.cmd_buffer commit]; + } + + // garbage-collect resources pending for release + _sg_mtl_garbage_collect(_sg.frame_index); + + // rotate uniform buffer slot + if (++_sg.mtl.cur_frame_rotate_index >= SG_NUM_INFLIGHT_FRAMES) { + _sg.mtl.cur_frame_rotate_index = 0; + } + _sg.mtl.cur_ub_offset = 0; + _sg.mtl.cur_ub_base_ptr = 0; + // NOTE: MTLCommandBuffer is autoreleased + _sg.mtl.cmd_buffer = nil; +} + +_SOKOL_PRIVATE void _sg_mtl_apply_viewport(int x, int y, int w, int h, bool origin_top_left) { + SOKOL_ASSERT(nil != _sg.mtl.render_cmd_encoder); + SOKOL_ASSERT(_sg.cur_pass.dim.height > 0); + MTLViewport vp; + vp.originX = (double) x; + vp.originY = (double) (origin_top_left ? y : (_sg.cur_pass.dim.height - (y + h))); + vp.width = (double) w; + vp.height = (double) h; + vp.znear = 0.0; + vp.zfar = 1.0; + [_sg.mtl.render_cmd_encoder setViewport:vp]; +} + +_SOKOL_PRIVATE void _sg_mtl_apply_scissor_rect(int x, int y, int w, int h, bool origin_top_left) { + SOKOL_ASSERT(nil != _sg.mtl.render_cmd_encoder); + SOKOL_ASSERT(_sg.cur_pass.dim.width > 0); + SOKOL_ASSERT(_sg.cur_pass.dim.height > 0); + // clip against framebuffer rect + const _sg_recti_t clip = _sg_clipi(x, y, w, h, _sg.cur_pass.dim.width, _sg.cur_pass.dim.height); + MTLScissorRect r; + r.x = (NSUInteger)clip.x; + r.y = (NSUInteger) (origin_top_left ? clip.y : (_sg.cur_pass.dim.height - (clip.y + clip.h))); + r.width = (NSUInteger)clip.w; + r.height = (NSUInteger)clip.h; + [_sg.mtl.render_cmd_encoder setScissorRect:r]; +} + +_SOKOL_PRIVATE void _sg_mtl_apply_pipeline(_sg_pipeline_t* pip) { + SOKOL_ASSERT(pip); + if (!_sg_sref_slot_eql(&_sg.mtl.cache.cur_pip, &pip->slot)) { + _sg.mtl.cache.cur_pip = _sg_sref(&pip->slot); + if (pip->cmn.is_compute) { + SOKOL_ASSERT(_sg.cur_pass.is_compute); + SOKOL_ASSERT(nil != _sg.mtl.compute_cmd_encoder); + SOKOL_ASSERT(pip->mtl.cps != _SG_MTL_INVALID_SLOT_INDEX); + [_sg.mtl.compute_cmd_encoder setComputePipelineState:_sg_mtl_id(pip->mtl.cps)]; + } else { + SOKOL_ASSERT(!_sg.cur_pass.is_compute); + SOKOL_ASSERT(nil != _sg.mtl.render_cmd_encoder); + sg_color c = pip->cmn.blend_color; + [_sg.mtl.render_cmd_encoder setBlendColorRed:c.r green:c.g blue:c.b alpha:c.a]; + _sg_stats_inc(metal.pipeline.num_set_blend_color); + [_sg.mtl.render_cmd_encoder setCullMode:pip->mtl.cull_mode]; + _sg_stats_inc(metal.pipeline.num_set_cull_mode); + [_sg.mtl.render_cmd_encoder setFrontFacingWinding:pip->mtl.winding]; + _sg_stats_inc(metal.pipeline.num_set_front_facing_winding); + [_sg.mtl.render_cmd_encoder setStencilReferenceValue:pip->mtl.stencil_ref]; + _sg_stats_inc(metal.pipeline.num_set_stencil_reference_value); + [_sg.mtl.render_cmd_encoder setDepthBias:pip->cmn.depth.bias slopeScale:pip->cmn.depth.bias_slope_scale clamp:pip->cmn.depth.bias_clamp]; + _sg_stats_inc(metal.pipeline.num_set_depth_bias); + SOKOL_ASSERT(pip->mtl.rps != _SG_MTL_INVALID_SLOT_INDEX); + [_sg.mtl.render_cmd_encoder setRenderPipelineState:_sg_mtl_id(pip->mtl.rps)]; + _sg_stats_inc(metal.pipeline.num_set_render_pipeline_state); + SOKOL_ASSERT(pip->mtl.dss != _SG_MTL_INVALID_SLOT_INDEX); + [_sg.mtl.render_cmd_encoder setDepthStencilState:_sg_mtl_id(pip->mtl.dss)]; + _sg_stats_inc(metal.pipeline.num_set_depth_stencil_state); + } + } +} + +_SOKOL_PRIVATE int _sg_mtl_cache_buf_cmp(const _sg_mtl_cache_buf_t* item, const _sg_slot_t* slot, int active_slot, int offset) { + int res = _SG_MTL_CACHE_CMP_EQUAL; + if (!_sg_sref_slot_eql(&item->sref, slot)) { + res |= _SG_MTL_CACHE_CMP_SREF; + } + if (item->active_slot != active_slot) { + res |= _SG_MTL_CACHE_CMP_ACTIVESLOT; + } + if (item->offset != offset) { + res |= _SG_MTL_CACHE_CMP_OFFSET; + } + return res; +} + +_SOKOL_PRIVATE void _sg_mtl_cache_buf_upd(_sg_mtl_cache_buf_t* item, const _sg_slot_t* slot, int active_slot, int offset) { + item->sref = _sg_sref(slot); + item->offset = offset; + item->active_slot = active_slot; +} + +_SOKOL_PRIVATE int _sg_mtl_cache_tex_cmp(const _sg_mtl_cache_tex_t* item, const _sg_slot_t* slot, int active_slot) { + int res = _SG_MTL_CACHE_CMP_EQUAL; + if (!_sg_sref_slot_eql(&item->sref, slot)) { + res |= _SG_MTL_CACHE_CMP_SREF; + } + if (item->active_slot != active_slot) { + res |= _SG_MTL_CACHE_CMP_ACTIVESLOT; + } + return res; +} + +_SOKOL_PRIVATE void _sg_mtl_cache_tex_upd(_sg_mtl_cache_tex_t* item, const _sg_slot_t* slot, int active_slot) { + item->sref = _sg_sref(slot); + item->active_slot = active_slot; +} + + +_SOKOL_PRIVATE bool _sg_mtl_apply_bindings(_sg_bindings_ptrs_t* bnd) { + SOKOL_ASSERT(bnd); + SOKOL_ASSERT(bnd->pip); + const _sg_shader_t* shd = _sg_shader_ref_ptr(&bnd->pip->cmn.shader); + + // don't set vertex- and index-buffers in compute passes + if (!_sg.cur_pass.is_compute) { + SOKOL_ASSERT(nil != _sg.mtl.render_cmd_encoder); + // store index buffer binding, this will be needed later in sg_draw() + _sg.mtl.cache.cur_ibuf = _sg_buffer_ref(bnd->ib); + _sg.mtl.cache.cur_ibuf_offset = bnd->ib_offset; + if (bnd->ib) { + SOKOL_ASSERT(bnd->pip->cmn.index_type != SG_INDEXTYPE_NONE); + } else { + SOKOL_ASSERT(bnd->pip->cmn.index_type == SG_INDEXTYPE_NONE); + } + // apply vertex buffers + for (size_t i = 0; i < SG_MAX_VERTEXBUFFER_BINDSLOTS; i++) { + const _sg_buffer_t* vb = bnd->vbs[i]; + if (vb == 0) { + continue; + } + const NSUInteger mtl_slot = _sg_mtl_vertexbuffer_bindslot(i); + SOKOL_ASSERT(mtl_slot < _SG_MTL_MAX_STAGE_BUFFER_BINDINGS); + const int active_slot = vb->cmn.active_slot; + SOKOL_ASSERT(vb->mtl.buf[active_slot] != _SG_MTL_INVALID_SLOT_INDEX); + const int offset = bnd->vb_offsets[i]; + _sg_mtl_cache_buf_t* cache_item = &_sg.mtl.cache.cur_vsbufs[i]; + const int cmp = _sg_mtl_cache_buf_cmp(cache_item, &vb->slot, active_slot, offset); + if (cmp != _SG_MTL_CACHE_CMP_EQUAL) { + _sg_mtl_cache_buf_upd(cache_item, &vb->slot, active_slot, offset); + if (0 == (cmp & ~_SG_MTL_CACHE_CMP_OFFSET)) { + // only vertex buffer offset has changed + [_sg.mtl.render_cmd_encoder setVertexBufferOffset:(NSUInteger)offset atIndex:mtl_slot]; + _sg_stats_inc(metal.bindings.num_set_vertex_buffer_offset); + } else { + [_sg.mtl.render_cmd_encoder setVertexBuffer:_sg_mtl_id(vb->mtl.buf[active_slot]) offset:(NSUInteger)offset atIndex:mtl_slot]; + _sg_stats_inc(metal.bindings.num_set_vertex_buffer); + } + } else { + _sg_stats_inc(metal.bindings.num_skip_redundant_vertex_buffer); + } + } + } + + // apply view bindings (textures, storage images, storage buffers) + for (size_t i = 0; i < SG_MAX_VIEW_BINDSLOTS; i++) { + const _sg_view_t* view = bnd->views[i]; + if (0 == view) { + continue; + } + const _sg_shader_view_t* shd_view = &shd->cmn.views[i]; + const sg_shader_stage stage = shd_view->stage; + SOKOL_ASSERT((stage == SG_SHADERSTAGE_VERTEX) + || (stage == SG_SHADERSTAGE_FRAGMENT) + || (stage == SG_SHADERSTAGE_COMPUTE)); + SOKOL_ASSERT((shd_view->view_type == SG_VIEWTYPE_TEXTURE) + || (shd_view->view_type == SG_VIEWTYPE_STORAGEBUFFER) + || (shd_view->view_type == SG_VIEWTYPE_STORAGEIMAGE)); + const NSUInteger mtl_slot = shd->mtl.view_buffer_texture_n[i]; + + // same handling for textures and storage images + if ((shd_view->view_type == SG_VIEWTYPE_TEXTURE) || (shd_view->view_type == SG_VIEWTYPE_STORAGEIMAGE)) { + SOKOL_ASSERT(mtl_slot < _SG_MTL_MAX_STAGE_TEXTURE_BINDINGS); + const int active_slot = _sg_image_ref_ptr(&view->cmn.img.ref)->cmn.active_slot; + SOKOL_ASSERT(view->mtl.tex_view[active_slot] != _SG_MTL_INVALID_SLOT_INDEX); + if (stage == SG_SHADERSTAGE_VERTEX) { + SOKOL_ASSERT(nil != _sg.mtl.render_cmd_encoder); + _sg_mtl_cache_tex_t* cache_item = &_sg.mtl.cache.cur_vstexs[mtl_slot]; + const int cmp = _sg_mtl_cache_tex_cmp(cache_item, &view->slot, active_slot); + if (cmp != _SG_MTL_CACHE_CMP_EQUAL) { + _sg_mtl_cache_tex_upd(cache_item, &view->slot, active_slot); + [_sg.mtl.render_cmd_encoder setVertexTexture:_sg_mtl_id(view->mtl.tex_view[active_slot]) atIndex:mtl_slot]; + _sg_stats_inc(metal.bindings.num_set_vertex_texture); + } else { + _sg_stats_inc(metal.bindings.num_skip_redundant_vertex_texture); + } + } else if (stage == SG_SHADERSTAGE_FRAGMENT) { + SOKOL_ASSERT(nil != _sg.mtl.render_cmd_encoder); + _sg_mtl_cache_tex_t* cache_item = &_sg.mtl.cache.cur_fstexs[mtl_slot]; + const int cmp = _sg_mtl_cache_tex_cmp(cache_item, &view->slot, active_slot); + if (cmp != _SG_MTL_CACHE_CMP_EQUAL) { + _sg_mtl_cache_tex_upd(cache_item, &view->slot, active_slot); + [_sg.mtl.render_cmd_encoder setFragmentTexture:_sg_mtl_id(view->mtl.tex_view[active_slot]) atIndex:mtl_slot]; + _sg_stats_inc(metal.bindings.num_set_fragment_texture); + } else { + _sg_stats_inc(metal.bindings.num_skip_redundant_fragment_texture); + } + } else if (stage == SG_SHADERSTAGE_COMPUTE) { + SOKOL_ASSERT(nil != _sg.mtl.compute_cmd_encoder); + _sg_mtl_cache_tex_t* cache_item = &_sg.mtl.cache.cur_cstexs[mtl_slot]; + const int cmp = _sg_mtl_cache_tex_cmp(cache_item, &view->slot, active_slot); + if (cmp != _SG_MTL_CACHE_CMP_EQUAL) { + _sg_mtl_cache_tex_upd(cache_item, &view->slot, active_slot); + [_sg.mtl.compute_cmd_encoder setTexture:_sg_mtl_id(view->mtl.tex_view[active_slot]) atIndex:mtl_slot]; + _sg_stats_inc(metal.bindings.num_set_compute_texture); + } else { + _sg_stats_inc(metal.bindings.num_skip_redundant_compute_texture); + } + } else SOKOL_UNREACHABLE; + } else if (shd_view->view_type == SG_VIEWTYPE_STORAGEBUFFER) { + SOKOL_ASSERT(mtl_slot < _SG_MTL_MAX_STAGE_UB_SBUF_BINDINGS); + const _sg_buffer_t* sbuf = _sg_buffer_ref_ptr(&view->cmn.buf.ref); + const int active_slot = sbuf->cmn.active_slot; + SOKOL_ASSERT(sbuf->mtl.buf[sbuf->cmn.active_slot] != _SG_MTL_INVALID_SLOT_INDEX); + const int offset = view->cmn.buf.offset; + if (stage == SG_SHADERSTAGE_VERTEX) { + SOKOL_ASSERT(nil != _sg.mtl.render_cmd_encoder); + _sg_mtl_cache_buf_t* cache_item = &_sg.mtl.cache.cur_vsbufs[mtl_slot]; + const int cmp = _sg_mtl_cache_buf_cmp(cache_item, &sbuf->slot, active_slot, offset); + if (cmp != _SG_MTL_CACHE_CMP_EQUAL) { + _sg_mtl_cache_buf_upd(cache_item, &sbuf->slot, active_slot, offset); + if (0 == (cmp & ~_SG_MTL_CACHE_CMP_OFFSET)) { + // only offset has changed + [_sg.mtl.render_cmd_encoder setVertexBufferOffset:(NSUInteger)offset atIndex:mtl_slot]; + _sg_stats_inc(metal.bindings.num_set_vertex_buffer_offset); + } else { + [_sg.mtl.render_cmd_encoder setVertexBuffer:_sg_mtl_id(sbuf->mtl.buf[sbuf->cmn.active_slot]) offset:(NSUInteger)offset atIndex:mtl_slot]; + _sg_stats_inc(metal.bindings.num_set_vertex_buffer); + } + } else { + _sg_stats_inc(metal.bindings.num_skip_redundant_vertex_buffer); + } + } else if (stage == SG_SHADERSTAGE_FRAGMENT) { + SOKOL_ASSERT(nil != _sg.mtl.render_cmd_encoder); + _sg_mtl_cache_buf_t* cache_item = &_sg.mtl.cache.cur_fsbufs[mtl_slot]; + const int cmp = _sg_mtl_cache_buf_cmp(cache_item, &sbuf->slot, active_slot, offset); + if (cmp != _SG_MTL_CACHE_CMP_EQUAL) { + _sg_mtl_cache_buf_upd(cache_item, &sbuf->slot, active_slot, offset); + if (0 == (cmp & ~_SG_MTL_CACHE_CMP_OFFSET)) { + // only offset has changed + [_sg.mtl.render_cmd_encoder setFragmentBufferOffset:(NSUInteger)offset atIndex:mtl_slot]; + _sg_stats_inc(metal.bindings.num_set_fragment_buffer_offset); + } else { + [_sg.mtl.render_cmd_encoder setFragmentBuffer:_sg_mtl_id(sbuf->mtl.buf[active_slot]) offset:(NSUInteger)offset atIndex:mtl_slot]; + _sg_stats_inc(metal.bindings.num_set_fragment_buffer); + } + } else { + _sg_stats_inc(metal.bindings.num_skip_redundant_fragment_buffer); + } + } else if (stage == SG_SHADERSTAGE_COMPUTE) { + SOKOL_ASSERT(nil != _sg.mtl.compute_cmd_encoder); + _sg_mtl_cache_buf_t* cache_item = &_sg.mtl.cache.cur_csbufs[mtl_slot]; + const int cmp = _sg_mtl_cache_buf_cmp(cache_item, &sbuf->slot, active_slot, offset); + if (cmp != _SG_MTL_CACHE_CMP_EQUAL) { + _sg_mtl_cache_buf_upd(cache_item, &sbuf->slot, active_slot, offset); + if (0 == (cmp & ~_SG_MTL_CACHE_CMP_OFFSET)) { + // only offset has changed + [_sg.mtl.compute_cmd_encoder setBufferOffset:(NSUInteger)offset atIndex:mtl_slot]; + _sg_stats_inc(metal.bindings.num_set_compute_buffer_offset); + } else { + [_sg.mtl.compute_cmd_encoder setBuffer:_sg_mtl_id(sbuf->mtl.buf[active_slot]) offset:(NSUInteger)offset atIndex:mtl_slot]; + _sg_stats_inc(metal.bindings.num_set_compute_buffer); + } + } else { + _sg_stats_inc(metal.bindings.num_skip_redundant_compute_buffer); + } + } + } else SOKOL_UNREACHABLE; + } + + // apply sampler bindings + for (size_t i = 0; i < SG_MAX_SAMPLER_BINDSLOTS; i++) { + const _sg_sampler_t* smp = bnd->smps[i]; + if (smp == 0) { + continue; + } + SOKOL_ASSERT(smp->mtl.sampler_state != _SG_MTL_INVALID_SLOT_INDEX); + const sg_shader_stage stage = shd->cmn.samplers[i].stage; + SOKOL_ASSERT((stage == SG_SHADERSTAGE_VERTEX) || (stage == SG_SHADERSTAGE_FRAGMENT) || (stage == SG_SHADERSTAGE_COMPUTE)); + const NSUInteger mtl_slot = shd->mtl.smp_sampler_n[i]; + SOKOL_ASSERT(mtl_slot < _SG_MTL_MAX_STAGE_SAMPLER_BINDINGS); + if (stage == SG_SHADERSTAGE_VERTEX) { + SOKOL_ASSERT(nil != _sg.mtl.render_cmd_encoder); + if (!_sg_sref_slot_eql(&_sg.mtl.cache.cur_vssmps[mtl_slot], &smp->slot)) { + _sg.mtl.cache.cur_vssmps[mtl_slot] = _sg_sref(&smp->slot); + [_sg.mtl.render_cmd_encoder setVertexSamplerState:_sg_mtl_id(smp->mtl.sampler_state) atIndex:mtl_slot]; + _sg_stats_inc(metal.bindings.num_set_vertex_sampler_state); + } else { + _sg_stats_inc(metal.bindings.num_skip_redundant_vertex_sampler_state); + } + } else if (stage == SG_SHADERSTAGE_FRAGMENT) { + SOKOL_ASSERT(nil != _sg.mtl.render_cmd_encoder); + if (!_sg_sref_slot_eql(&_sg.mtl.cache.cur_fssmps[mtl_slot], &smp->slot)) { + _sg.mtl.cache.cur_fssmps[mtl_slot] = _sg_sref(&smp->slot); + [_sg.mtl.render_cmd_encoder setFragmentSamplerState:_sg_mtl_id(smp->mtl.sampler_state) atIndex:mtl_slot]; + _sg_stats_inc(metal.bindings.num_set_fragment_sampler_state); + } else { + _sg_stats_inc(metal.bindings.num_skip_redundant_fragment_sampler_state); + } + } else if (stage == SG_SHADERSTAGE_COMPUTE) { + SOKOL_ASSERT(nil != _sg.mtl.compute_cmd_encoder); + if (!_sg_sref_slot_eql(&_sg.mtl.cache.cur_cssmps[mtl_slot], &smp->slot)) { + _sg.mtl.cache.cur_cssmps[mtl_slot] = _sg_sref(&smp->slot); + [_sg.mtl.compute_cmd_encoder setSamplerState:_sg_mtl_id(smp->mtl.sampler_state) atIndex:mtl_slot]; + _sg_stats_inc(metal.bindings.num_set_compute_sampler_state); + } else { + _sg_stats_inc(metal.bindings.num_skip_redundant_compute_sampler_state); + } + } else SOKOL_UNREACHABLE; + } + return true; +} + +_SOKOL_PRIVATE void _sg_mtl_apply_uniforms(int ub_slot, const sg_range* data) { + SOKOL_ASSERT((ub_slot >= 0) && (ub_slot < SG_MAX_UNIFORMBLOCK_BINDSLOTS)); + SOKOL_ASSERT(((size_t)_sg.mtl.cur_ub_offset + data->size) <= (size_t)_sg.mtl.ub_size); + SOKOL_ASSERT((_sg.mtl.cur_ub_offset & (_SG_MTL_UB_ALIGN-1)) == 0); + const _sg_pipeline_t* pip = _sg_pipeline_ref_ptr(&_sg.cur_pip); + SOKOL_ASSERT(pip); + const _sg_shader_t* shd = _sg_shader_ref_ptr(&pip->cmn.shader); + SOKOL_ASSERT(data->size == shd->cmn.uniform_blocks[ub_slot].size); + + const sg_shader_stage stage = shd->cmn.uniform_blocks[ub_slot].stage; + const NSUInteger mtl_slot = shd->mtl.ub_buffer_n[ub_slot]; + + // copy to global uniform buffer, record offset into cmd encoder, and advance offset + uint8_t* dst = &_sg.mtl.cur_ub_base_ptr[_sg.mtl.cur_ub_offset]; + memcpy(dst, data->ptr, data->size); + if (stage == SG_SHADERSTAGE_VERTEX) { + SOKOL_ASSERT(nil != _sg.mtl.render_cmd_encoder); + [_sg.mtl.render_cmd_encoder setVertexBufferOffset:(NSUInteger)_sg.mtl.cur_ub_offset atIndex:mtl_slot]; + _sg_stats_inc(metal.uniforms.num_set_vertex_buffer_offset); + } else if (stage == SG_SHADERSTAGE_FRAGMENT) { + SOKOL_ASSERT(nil != _sg.mtl.render_cmd_encoder); + [_sg.mtl.render_cmd_encoder setFragmentBufferOffset:(NSUInteger)_sg.mtl.cur_ub_offset atIndex:mtl_slot]; + _sg_stats_inc(metal.uniforms.num_set_fragment_buffer_offset); + } else if (stage == SG_SHADERSTAGE_COMPUTE) { + SOKOL_ASSERT(nil != _sg.mtl.compute_cmd_encoder); + [_sg.mtl.compute_cmd_encoder setBufferOffset:(NSUInteger)_sg.mtl.cur_ub_offset atIndex:mtl_slot]; + _sg_stats_inc(metal.uniforms.num_set_compute_buffer_offset); + } else { + SOKOL_UNREACHABLE; + } + _sg.mtl.cur_ub_offset = _sg_roundup(_sg.mtl.cur_ub_offset + (int)data->size, _SG_MTL_UB_ALIGN); +} + +_SOKOL_PRIVATE void _sg_mtl_draw(int base_element, int num_elements, int num_instances, int base_vertex, int base_instance) { + SOKOL_ASSERT(nil != _sg.mtl.render_cmd_encoder); + const _sg_pipeline_t* pip = _sg_pipeline_ref_ptr(&_sg.cur_pip); + SOKOL_ASSERT(pip); + if (_sg.use_indexed_draw) { + // indexed rendering + const _sg_buffer_t* ib = _sg_buffer_ref_ptr(&_sg.mtl.cache.cur_ibuf); + SOKOL_ASSERT(ib && (ib->mtl.buf[ib->cmn.active_slot] != _SG_MTL_INVALID_SLOT_INDEX)); + const NSUInteger index_buffer_offset = (NSUInteger) (_sg.mtl.cache.cur_ibuf_offset + base_element * pip->mtl.index_size); + [_sg.mtl.render_cmd_encoder drawIndexedPrimitives:pip->mtl.prim_type + indexCount:(NSUInteger)num_elements + indexType:pip->mtl.index_type + indexBuffer:_sg_mtl_id(ib->mtl.buf[ib->cmn.active_slot]) + indexBufferOffset:index_buffer_offset + instanceCount:(NSUInteger)num_instances + baseVertex:base_vertex + baseInstance:(NSUInteger)base_instance]; + } else { + // non-indexed rendering + [_sg.mtl.render_cmd_encoder drawPrimitives:pip->mtl.prim_type + vertexStart:(NSUInteger)base_element + vertexCount:(NSUInteger)num_elements + instanceCount:(NSUInteger)num_instances + baseInstance:(NSUInteger)base_instance]; + } +} + +_SOKOL_PRIVATE void _sg_mtl_dispatch(int num_groups_x, int num_groups_y, int num_groups_z) { + SOKOL_ASSERT(nil != _sg.mtl.compute_cmd_encoder); + const _sg_pipeline_t* pip = _sg_pipeline_ref_ptr(&_sg.cur_pip); + SOKOL_ASSERT(pip); + const MTLSize thread_groups = MTLSizeMake( + (NSUInteger)num_groups_x, + (NSUInteger)num_groups_y, + (NSUInteger)num_groups_z); + const MTLSize threads_per_threadgroup = pip->mtl.threads_per_threadgroup; + [_sg.mtl.compute_cmd_encoder dispatchThreadgroups:thread_groups threadsPerThreadgroup:threads_per_threadgroup]; +} + +_SOKOL_PRIVATE void _sg_mtl_update_buffer(_sg_buffer_t* buf, const sg_range* data) { + SOKOL_ASSERT(buf && data && data->ptr && (data->size > 0)); + if (++buf->cmn.active_slot >= buf->cmn.num_slots) { + buf->cmn.active_slot = 0; + } + __unsafe_unretained id mtl_buf = _sg_mtl_id(buf->mtl.buf[buf->cmn.active_slot]); + void* dst_ptr = [mtl_buf contents]; + memcpy(dst_ptr, data->ptr, data->size); + #if defined(_SG_TARGET_MACOS) + if (_sg_mtl_resource_options_storage_mode_managed_or_shared() == MTLResourceStorageModeManaged) { + [mtl_buf didModifyRange:NSMakeRange(0, data->size)]; + } + #endif +} + +_SOKOL_PRIVATE void _sg_mtl_append_buffer(_sg_buffer_t* buf, const sg_range* data, bool new_frame) { + SOKOL_ASSERT(buf && data && data->ptr && (data->size > 0)); + if (new_frame) { + if (++buf->cmn.active_slot >= buf->cmn.num_slots) { + buf->cmn.active_slot = 0; + } + } + __unsafe_unretained id mtl_buf = _sg_mtl_id(buf->mtl.buf[buf->cmn.active_slot]); + uint8_t* dst_ptr = (uint8_t*) [mtl_buf contents]; + dst_ptr += buf->cmn.append_pos; + memcpy(dst_ptr, data->ptr, data->size); + #if defined(_SG_TARGET_MACOS) + if (_sg_mtl_resource_options_storage_mode_managed_or_shared() == MTLResourceStorageModeManaged) { + [mtl_buf didModifyRange:NSMakeRange((NSUInteger)buf->cmn.append_pos, (NSUInteger)data->size)]; + } + #endif +} + +_SOKOL_PRIVATE void _sg_mtl_update_image(_sg_image_t* img, const sg_image_data* data) { + SOKOL_ASSERT(img && data); + if (++img->cmn.active_slot >= img->cmn.num_slots) { + img->cmn.active_slot = 0; + } + __unsafe_unretained id mtl_tex = _sg_mtl_id(img->mtl.tex[img->cmn.active_slot]); + _sg_mtl_copy_image_data(img, mtl_tex, data); +} + +_SOKOL_PRIVATE void _sg_mtl_push_debug_group(const char* name) { + SOKOL_ASSERT(name); + if (_sg.mtl.render_cmd_encoder) { + [_sg.mtl.render_cmd_encoder pushDebugGroup:[NSString stringWithUTF8String:name]]; + } else if (_sg.mtl.compute_cmd_encoder) { + [_sg.mtl.compute_cmd_encoder pushDebugGroup:[NSString stringWithUTF8String:name]]; + } +} + +_SOKOL_PRIVATE void _sg_mtl_pop_debug_group(void) { + if (_sg.mtl.render_cmd_encoder) { + [_sg.mtl.render_cmd_encoder popDebugGroup]; + } else if (_sg.mtl.compute_cmd_encoder) { + [_sg.mtl.compute_cmd_encoder popDebugGroup]; + } +} + +// ██ ██ ███████ ██████ ██████ ██████ ██ ██ ██████ █████ ██████ ██ ██ ███████ ███ ██ ██████ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ +// ██ █ ██ █████ ██████ ██ ███ ██████ ██ ██ ██████ ███████ ██ █████ █████ ██ ██ ██ ██ ██ +// ██ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ███ ███ ███████ ██████ ██████ ██ ██████ ██████ ██ ██ ██████ ██ ██ ███████ ██ ████ ██████ +// +// >>webgpu +// >>wgpu +#elif defined(SOKOL_WGPU) + +_SOKOL_PRIVATE WGPUStringView _sg_wgpu_stringview(const char* str) { + WGPUStringView res; + if (str) { + res.data = str; + res.length = strlen(str); + } else { + res.data = 0; + res.length = 0; + } + return res; +} + +_SOKOL_PRIVATE WGPUOptionalBool _sg_wgpu_optional_bool(bool b) { + return b ? WGPUOptionalBool_True : WGPUOptionalBool_False; +} + +_SOKOL_PRIVATE WGPUBufferUsage _sg_wgpu_buffer_usage(const sg_buffer_usage* usg) { + int res = 0; + if (usg->vertex_buffer) { + res |= (int)WGPUBufferUsage_Vertex; + } + if (usg->index_buffer) { + res |= (int)WGPUBufferUsage_Index; + } + if (usg->storage_buffer) { + res |= (int)WGPUBufferUsage_Storage; + } + if (!usg->immutable) { + res |= (int)WGPUBufferUsage_CopyDst; + } + return (WGPUBufferUsage)res; +} + +_SOKOL_PRIVATE WGPULoadOp _sg_wgpu_load_op(WGPUTextureView view, sg_load_action a) { + if (0 == view) { + return WGPULoadOp_Undefined; + } else switch (a) { + case SG_LOADACTION_CLEAR: + case SG_LOADACTION_DONTCARE: + return WGPULoadOp_Clear; + case SG_LOADACTION_LOAD: + return WGPULoadOp_Load; + default: + SOKOL_UNREACHABLE; + return WGPULoadOp_Force32; + } +} + +_SOKOL_PRIVATE WGPUStoreOp _sg_wgpu_store_op(WGPUTextureView view, sg_store_action a) { + if (0 == view) { + return WGPUStoreOp_Undefined; + } else switch (a) { + case SG_STOREACTION_STORE: + return WGPUStoreOp_Store; + case SG_STOREACTION_DONTCARE: + return WGPUStoreOp_Discard; + default: + SOKOL_UNREACHABLE; + return WGPUStoreOp_Force32; + } +} + +_SOKOL_PRIVATE WGPUTextureViewDimension _sg_wgpu_texture_view_dimension(sg_image_type t) { + switch (t) { + case SG_IMAGETYPE_2D: return WGPUTextureViewDimension_2D; + case SG_IMAGETYPE_CUBE: return WGPUTextureViewDimension_Cube; + case SG_IMAGETYPE_3D: return WGPUTextureViewDimension_3D; + case SG_IMAGETYPE_ARRAY: return WGPUTextureViewDimension_2DArray; + default: SOKOL_UNREACHABLE; return WGPUTextureViewDimension_Force32; + } +} + +_SOKOL_PRIVATE WGPUTextureViewDimension _sg_wgpu_attachment_view_dimension(sg_image_type t) { + switch (t) { + case SG_IMAGETYPE_2D: return WGPUTextureViewDimension_2D; + case SG_IMAGETYPE_CUBE: return WGPUTextureViewDimension_2DArray; // not a bug + case SG_IMAGETYPE_3D: return WGPUTextureViewDimension_2D; // not a bug + case SG_IMAGETYPE_ARRAY: return WGPUTextureViewDimension_2DArray; + default: SOKOL_UNREACHABLE; return WGPUTextureViewDimension_Force32; + } +} + +_SOKOL_PRIVATE WGPUTextureDimension _sg_wgpu_texture_dimension(sg_image_type t) { + if (SG_IMAGETYPE_3D == t) { + return WGPUTextureDimension_3D; + } else { + return WGPUTextureDimension_2D; + } +} + +_SOKOL_PRIVATE WGPUTextureSampleType _sg_wgpu_texture_sample_type(sg_image_sample_type t, bool msaa) { + switch (t) { + case SG_IMAGESAMPLETYPE_FLOAT: return msaa ? WGPUTextureSampleType_UnfilterableFloat : WGPUTextureSampleType_Float; + case SG_IMAGESAMPLETYPE_DEPTH: return WGPUTextureSampleType_Depth; + case SG_IMAGESAMPLETYPE_SINT: return WGPUTextureSampleType_Sint; + case SG_IMAGESAMPLETYPE_UINT: return WGPUTextureSampleType_Uint; + case SG_IMAGESAMPLETYPE_UNFILTERABLE_FLOAT: return WGPUTextureSampleType_UnfilterableFloat; + default: SOKOL_UNREACHABLE; return WGPUTextureSampleType_Force32; + } +} + +_SOKOL_PRIVATE WGPUSamplerBindingType _sg_wgpu_sampler_binding_type(sg_sampler_type t) { + switch (t) { + case SG_SAMPLERTYPE_FILTERING: return WGPUSamplerBindingType_Filtering; + case SG_SAMPLERTYPE_COMPARISON: return WGPUSamplerBindingType_Comparison; + case SG_SAMPLERTYPE_NONFILTERING: return WGPUSamplerBindingType_NonFiltering; + default: SOKOL_UNREACHABLE; return WGPUSamplerBindingType_Force32; + } +} + +_SOKOL_PRIVATE WGPUAddressMode _sg_wgpu_sampler_address_mode(sg_wrap m) { + switch (m) { + case SG_WRAP_REPEAT: + return WGPUAddressMode_Repeat; + case SG_WRAP_CLAMP_TO_EDGE: + case SG_WRAP_CLAMP_TO_BORDER: + return WGPUAddressMode_ClampToEdge; + case SG_WRAP_MIRRORED_REPEAT: + return WGPUAddressMode_MirrorRepeat; + default: + SOKOL_UNREACHABLE; + return WGPUAddressMode_Force32; + } +} + +_SOKOL_PRIVATE WGPUFilterMode _sg_wgpu_sampler_minmag_filter(sg_filter f) { + switch (f) { + case SG_FILTER_NEAREST: + return WGPUFilterMode_Nearest; + case SG_FILTER_LINEAR: + return WGPUFilterMode_Linear; + default: + SOKOL_UNREACHABLE; + return WGPUFilterMode_Force32; + } +} + +_SOKOL_PRIVATE WGPUMipmapFilterMode _sg_wgpu_sampler_mipmap_filter(sg_filter f) { + switch (f) { + case SG_FILTER_NEAREST: + return WGPUMipmapFilterMode_Nearest; + case SG_FILTER_LINEAR: + return WGPUMipmapFilterMode_Linear; + default: + SOKOL_UNREACHABLE; + return WGPUMipmapFilterMode_Force32; + } +} + +_SOKOL_PRIVATE WGPUIndexFormat _sg_wgpu_indexformat(sg_index_type t) { + // NOTE: there's no WGPUIndexFormat_None + return (t == SG_INDEXTYPE_UINT16) ? WGPUIndexFormat_Uint16 : WGPUIndexFormat_Uint32; +} + +_SOKOL_PRIVATE WGPUIndexFormat _sg_wgpu_stripindexformat(sg_primitive_type prim_type, sg_index_type idx_type) { + if (idx_type == SG_INDEXTYPE_NONE) { + return WGPUIndexFormat_Undefined; + } else if ((prim_type == SG_PRIMITIVETYPE_LINE_STRIP) || (prim_type == SG_PRIMITIVETYPE_TRIANGLE_STRIP)) { + return _sg_wgpu_indexformat(idx_type); + } else { + return WGPUIndexFormat_Undefined; + } +} + +_SOKOL_PRIVATE WGPUVertexStepMode _sg_wgpu_stepmode(sg_vertex_step s) { + return (s == SG_VERTEXSTEP_PER_VERTEX) ? WGPUVertexStepMode_Vertex : WGPUVertexStepMode_Instance; +} + +_SOKOL_PRIVATE WGPUVertexFormat _sg_wgpu_vertexformat(sg_vertex_format f) { + switch (f) { + case SG_VERTEXFORMAT_FLOAT: return WGPUVertexFormat_Float32; + case SG_VERTEXFORMAT_FLOAT2: return WGPUVertexFormat_Float32x2; + case SG_VERTEXFORMAT_FLOAT3: return WGPUVertexFormat_Float32x3; + case SG_VERTEXFORMAT_FLOAT4: return WGPUVertexFormat_Float32x4; + case SG_VERTEXFORMAT_INT: return WGPUVertexFormat_Sint32; + case SG_VERTEXFORMAT_INT2: return WGPUVertexFormat_Sint32x2; + case SG_VERTEXFORMAT_INT3: return WGPUVertexFormat_Sint32x3; + case SG_VERTEXFORMAT_INT4: return WGPUVertexFormat_Sint32x4; + case SG_VERTEXFORMAT_UINT: return WGPUVertexFormat_Uint32; + case SG_VERTEXFORMAT_UINT2: return WGPUVertexFormat_Uint32x2; + case SG_VERTEXFORMAT_UINT3: return WGPUVertexFormat_Uint32x3; + case SG_VERTEXFORMAT_UINT4: return WGPUVertexFormat_Uint32x4; + case SG_VERTEXFORMAT_BYTE4: return WGPUVertexFormat_Sint8x4; + case SG_VERTEXFORMAT_BYTE4N: return WGPUVertexFormat_Snorm8x4; + case SG_VERTEXFORMAT_UBYTE4: return WGPUVertexFormat_Uint8x4; + case SG_VERTEXFORMAT_UBYTE4N: return WGPUVertexFormat_Unorm8x4; + case SG_VERTEXFORMAT_SHORT2: return WGPUVertexFormat_Sint16x2; + case SG_VERTEXFORMAT_SHORT2N: return WGPUVertexFormat_Snorm16x2; + case SG_VERTEXFORMAT_USHORT2: return WGPUVertexFormat_Uint16x2; + case SG_VERTEXFORMAT_USHORT2N: return WGPUVertexFormat_Unorm16x2; + case SG_VERTEXFORMAT_SHORT4: return WGPUVertexFormat_Sint16x4; + case SG_VERTEXFORMAT_SHORT4N: return WGPUVertexFormat_Snorm16x4; + case SG_VERTEXFORMAT_USHORT4: return WGPUVertexFormat_Uint16x4; + case SG_VERTEXFORMAT_USHORT4N: return WGPUVertexFormat_Unorm16x4; + case SG_VERTEXFORMAT_UINT10_N2: return WGPUVertexFormat_Unorm10_10_10_2; + case SG_VERTEXFORMAT_HALF2: return WGPUVertexFormat_Float16x2; + case SG_VERTEXFORMAT_HALF4: return WGPUVertexFormat_Float16x4; + default: + SOKOL_UNREACHABLE; + return WGPUVertexFormat_Force32; + } +} + +_SOKOL_PRIVATE WGPUPrimitiveTopology _sg_wgpu_topology(sg_primitive_type t) { + switch (t) { + case SG_PRIMITIVETYPE_POINTS: return WGPUPrimitiveTopology_PointList; + case SG_PRIMITIVETYPE_LINES: return WGPUPrimitiveTopology_LineList; + case SG_PRIMITIVETYPE_LINE_STRIP: return WGPUPrimitiveTopology_LineStrip; + case SG_PRIMITIVETYPE_TRIANGLES: return WGPUPrimitiveTopology_TriangleList; + case SG_PRIMITIVETYPE_TRIANGLE_STRIP: return WGPUPrimitiveTopology_TriangleStrip; + default: + SOKOL_UNREACHABLE; + return WGPUPrimitiveTopology_Force32; + } +} + +_SOKOL_PRIVATE WGPUFrontFace _sg_wgpu_frontface(sg_face_winding fw) { + return (fw == SG_FACEWINDING_CCW) ? WGPUFrontFace_CCW : WGPUFrontFace_CW; +} + +_SOKOL_PRIVATE WGPUCullMode _sg_wgpu_cullmode(sg_cull_mode cm) { + switch (cm) { + case SG_CULLMODE_NONE: return WGPUCullMode_None; + case SG_CULLMODE_FRONT: return WGPUCullMode_Front; + case SG_CULLMODE_BACK: return WGPUCullMode_Back; + default: + SOKOL_UNREACHABLE; + return WGPUCullMode_Force32; + } +} + +_SOKOL_PRIVATE WGPUTextureFormat _sg_wgpu_textureformat(sg_pixel_format p) { + switch (p) { + case SG_PIXELFORMAT_NONE: return WGPUTextureFormat_Undefined; + case SG_PIXELFORMAT_R8: return WGPUTextureFormat_R8Unorm; + case SG_PIXELFORMAT_R8SN: return WGPUTextureFormat_R8Snorm; + case SG_PIXELFORMAT_R8UI: return WGPUTextureFormat_R8Uint; + case SG_PIXELFORMAT_R8SI: return WGPUTextureFormat_R8Sint; + case SG_PIXELFORMAT_R16: return WGPUTextureFormat_R16Unorm; + case SG_PIXELFORMAT_R16SN: return WGPUTextureFormat_R16Snorm; + case SG_PIXELFORMAT_R16UI: return WGPUTextureFormat_R16Uint; + case SG_PIXELFORMAT_R16SI: return WGPUTextureFormat_R16Sint; + case SG_PIXELFORMAT_R16F: return WGPUTextureFormat_R16Float; + case SG_PIXELFORMAT_RG8: return WGPUTextureFormat_RG8Unorm; + case SG_PIXELFORMAT_RG8SN: return WGPUTextureFormat_RG8Snorm; + case SG_PIXELFORMAT_RG8UI: return WGPUTextureFormat_RG8Uint; + case SG_PIXELFORMAT_RG8SI: return WGPUTextureFormat_RG8Sint; + case SG_PIXELFORMAT_R32UI: return WGPUTextureFormat_R32Uint; + case SG_PIXELFORMAT_R32SI: return WGPUTextureFormat_R32Sint; + case SG_PIXELFORMAT_R32F: return WGPUTextureFormat_R32Float; + case SG_PIXELFORMAT_RG16: return WGPUTextureFormat_RG16Unorm; + case SG_PIXELFORMAT_RG16SN: return WGPUTextureFormat_RG16Snorm; + case SG_PIXELFORMAT_RG16UI: return WGPUTextureFormat_RG16Uint; + case SG_PIXELFORMAT_RG16SI: return WGPUTextureFormat_RG16Sint; + case SG_PIXELFORMAT_RG16F: return WGPUTextureFormat_RG16Float; + case SG_PIXELFORMAT_RGBA8: return WGPUTextureFormat_RGBA8Unorm; + case SG_PIXELFORMAT_SRGB8A8: return WGPUTextureFormat_RGBA8UnormSrgb; + case SG_PIXELFORMAT_RGBA8SN: return WGPUTextureFormat_RGBA8Snorm; + case SG_PIXELFORMAT_RGBA8UI: return WGPUTextureFormat_RGBA8Uint; + case SG_PIXELFORMAT_RGBA8SI: return WGPUTextureFormat_RGBA8Sint; + case SG_PIXELFORMAT_BGRA8: return WGPUTextureFormat_BGRA8Unorm; + case SG_PIXELFORMAT_RGB10A2: return WGPUTextureFormat_RGB10A2Unorm; + case SG_PIXELFORMAT_RG11B10F: return WGPUTextureFormat_RG11B10Ufloat; + case SG_PIXELFORMAT_RGB9E5: return WGPUTextureFormat_RGB9E5Ufloat; + case SG_PIXELFORMAT_RG32UI: return WGPUTextureFormat_RG32Uint; + case SG_PIXELFORMAT_RG32SI: return WGPUTextureFormat_RG32Sint; + case SG_PIXELFORMAT_RG32F: return WGPUTextureFormat_RG32Float; + case SG_PIXELFORMAT_RGBA16: return WGPUTextureFormat_RGBA16Unorm; + case SG_PIXELFORMAT_RGBA16SN: return WGPUTextureFormat_RGBA16Snorm; + case SG_PIXELFORMAT_RGBA16UI: return WGPUTextureFormat_RGBA16Uint; + case SG_PIXELFORMAT_RGBA16SI: return WGPUTextureFormat_RGBA16Sint; + case SG_PIXELFORMAT_RGBA16F: return WGPUTextureFormat_RGBA16Float; + case SG_PIXELFORMAT_RGBA32UI: return WGPUTextureFormat_RGBA32Uint; + case SG_PIXELFORMAT_RGBA32SI: return WGPUTextureFormat_RGBA32Sint; + case SG_PIXELFORMAT_RGBA32F: return WGPUTextureFormat_RGBA32Float; + case SG_PIXELFORMAT_DEPTH: return WGPUTextureFormat_Depth32Float; + case SG_PIXELFORMAT_DEPTH_STENCIL: return WGPUTextureFormat_Depth32FloatStencil8; + case SG_PIXELFORMAT_BC1_RGBA: return WGPUTextureFormat_BC1RGBAUnorm; + case SG_PIXELFORMAT_BC2_RGBA: return WGPUTextureFormat_BC2RGBAUnorm; + case SG_PIXELFORMAT_BC3_RGBA: return WGPUTextureFormat_BC3RGBAUnorm; + case SG_PIXELFORMAT_BC3_SRGBA: return WGPUTextureFormat_BC3RGBAUnormSrgb; + case SG_PIXELFORMAT_BC4_R: return WGPUTextureFormat_BC4RUnorm; + case SG_PIXELFORMAT_BC4_RSN: return WGPUTextureFormat_BC4RSnorm; + case SG_PIXELFORMAT_BC5_RG: return WGPUTextureFormat_BC5RGUnorm; + case SG_PIXELFORMAT_BC5_RGSN: return WGPUTextureFormat_BC5RGSnorm; + case SG_PIXELFORMAT_BC6H_RGBF: return WGPUTextureFormat_BC6HRGBFloat; + case SG_PIXELFORMAT_BC6H_RGBUF: return WGPUTextureFormat_BC6HRGBUfloat; + case SG_PIXELFORMAT_BC7_RGBA: return WGPUTextureFormat_BC7RGBAUnorm; + case SG_PIXELFORMAT_BC7_SRGBA: return WGPUTextureFormat_BC7RGBAUnormSrgb; + case SG_PIXELFORMAT_ETC2_RGB8: return WGPUTextureFormat_ETC2RGB8Unorm; + case SG_PIXELFORMAT_ETC2_RGB8A1: return WGPUTextureFormat_ETC2RGB8A1Unorm; + case SG_PIXELFORMAT_ETC2_RGBA8: return WGPUTextureFormat_ETC2RGBA8Unorm; + case SG_PIXELFORMAT_ETC2_SRGB8: return WGPUTextureFormat_ETC2RGB8UnormSrgb; + case SG_PIXELFORMAT_ETC2_SRGB8A8: return WGPUTextureFormat_ETC2RGBA8UnormSrgb; + case SG_PIXELFORMAT_EAC_R11: return WGPUTextureFormat_EACR11Unorm; + case SG_PIXELFORMAT_EAC_R11SN: return WGPUTextureFormat_EACR11Snorm; + case SG_PIXELFORMAT_EAC_RG11: return WGPUTextureFormat_EACRG11Unorm; + case SG_PIXELFORMAT_EAC_RG11SN: return WGPUTextureFormat_EACRG11Snorm; + case SG_PIXELFORMAT_ASTC_4x4_RGBA: return WGPUTextureFormat_ASTC4x4Unorm; + case SG_PIXELFORMAT_ASTC_4x4_SRGBA: return WGPUTextureFormat_ASTC4x4UnormSrgb; + default: + SOKOL_UNREACHABLE; + return WGPUTextureFormat_Force32; + } +} + +_SOKOL_PRIVATE WGPUCompareFunction _sg_wgpu_comparefunc(sg_compare_func f) { + switch (f) { + case SG_COMPAREFUNC_NEVER: return WGPUCompareFunction_Never; + case SG_COMPAREFUNC_LESS: return WGPUCompareFunction_Less; + case SG_COMPAREFUNC_EQUAL: return WGPUCompareFunction_Equal; + case SG_COMPAREFUNC_LESS_EQUAL: return WGPUCompareFunction_LessEqual; + case SG_COMPAREFUNC_GREATER: return WGPUCompareFunction_Greater; + case SG_COMPAREFUNC_NOT_EQUAL: return WGPUCompareFunction_NotEqual; + case SG_COMPAREFUNC_GREATER_EQUAL: return WGPUCompareFunction_GreaterEqual; + case SG_COMPAREFUNC_ALWAYS: return WGPUCompareFunction_Always; + default: + SOKOL_UNREACHABLE; + return WGPUCompareFunction_Force32; + } +} + +_SOKOL_PRIVATE WGPUStencilOperation _sg_wgpu_stencilop(sg_stencil_op op) { + switch (op) { + case SG_STENCILOP_KEEP: return WGPUStencilOperation_Keep; + case SG_STENCILOP_ZERO: return WGPUStencilOperation_Zero; + case SG_STENCILOP_REPLACE: return WGPUStencilOperation_Replace; + case SG_STENCILOP_INCR_CLAMP: return WGPUStencilOperation_IncrementClamp; + case SG_STENCILOP_DECR_CLAMP: return WGPUStencilOperation_DecrementClamp; + case SG_STENCILOP_INVERT: return WGPUStencilOperation_Invert; + case SG_STENCILOP_INCR_WRAP: return WGPUStencilOperation_IncrementWrap; + case SG_STENCILOP_DECR_WRAP: return WGPUStencilOperation_DecrementWrap; + default: + SOKOL_UNREACHABLE; + return WGPUStencilOperation_Force32; + } +} + +_SOKOL_PRIVATE WGPUBlendOperation _sg_wgpu_blendop(sg_blend_op op) { + switch (op) { + case SG_BLENDOP_ADD: return WGPUBlendOperation_Add; + case SG_BLENDOP_SUBTRACT: return WGPUBlendOperation_Subtract; + case SG_BLENDOP_REVERSE_SUBTRACT: return WGPUBlendOperation_ReverseSubtract; + case SG_BLENDOP_MIN: return WGPUBlendOperation_Min; + case SG_BLENDOP_MAX: return WGPUBlendOperation_Max; + default: + SOKOL_UNREACHABLE; + return WGPUBlendOperation_Force32; + } +} + +_SOKOL_PRIVATE WGPUBlendFactor _sg_wgpu_blendfactor(sg_blend_factor f) { + switch (f) { + case SG_BLENDFACTOR_ZERO: return WGPUBlendFactor_Zero; + case SG_BLENDFACTOR_ONE: return WGPUBlendFactor_One; + case SG_BLENDFACTOR_SRC_COLOR: return WGPUBlendFactor_Src; + case SG_BLENDFACTOR_ONE_MINUS_SRC_COLOR: return WGPUBlendFactor_OneMinusSrc; + case SG_BLENDFACTOR_SRC_ALPHA: return WGPUBlendFactor_SrcAlpha; + case SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA: return WGPUBlendFactor_OneMinusSrcAlpha; + case SG_BLENDFACTOR_DST_COLOR: return WGPUBlendFactor_Dst; + case SG_BLENDFACTOR_ONE_MINUS_DST_COLOR: return WGPUBlendFactor_OneMinusDst; + case SG_BLENDFACTOR_DST_ALPHA: return WGPUBlendFactor_DstAlpha; + case SG_BLENDFACTOR_ONE_MINUS_DST_ALPHA: return WGPUBlendFactor_OneMinusDstAlpha; + case SG_BLENDFACTOR_SRC_ALPHA_SATURATED: return WGPUBlendFactor_SrcAlphaSaturated; + case SG_BLENDFACTOR_BLEND_COLOR: return WGPUBlendFactor_Constant; + case SG_BLENDFACTOR_ONE_MINUS_BLEND_COLOR: return WGPUBlendFactor_OneMinusConstant; + // FIXME: separate blend alpha value not supported? + case SG_BLENDFACTOR_BLEND_ALPHA: return WGPUBlendFactor_Constant; + case SG_BLENDFACTOR_ONE_MINUS_BLEND_ALPHA: return WGPUBlendFactor_OneMinusConstant; + case SG_BLENDFACTOR_SRC1_COLOR: return WGPUBlendFactor_Src1 ; + case SG_BLENDFACTOR_ONE_MINUS_SRC1_COLOR: return WGPUBlendFactor_OneMinusSrc1; + case SG_BLENDFACTOR_SRC1_ALPHA: return WGPUBlendFactor_Src1Alpha; + case SG_BLENDFACTOR_ONE_MINUS_SRC1_ALPHA: return WGPUBlendFactor_OneMinusSrc1Alpha; + default: + SOKOL_UNREACHABLE; + return WGPUBlendFactor_Force32; + } +} + +_SOKOL_PRIVATE WGPUColorWriteMask _sg_wgpu_colorwritemask(sg_color_mask m) { + int res = 0; + if (0 != (m & SG_COLORMASK_R)) { + res |= (int)WGPUColorWriteMask_Red; + } + if (0 != (m & SG_COLORMASK_G)) { + res |= (int)WGPUColorWriteMask_Green; + } + if (0 != (m & SG_COLORMASK_B)) { + res |= (int)WGPUColorWriteMask_Blue; + } + if (0 != (m & SG_COLORMASK_A)) { + res |= (int)WGPUColorWriteMask_Alpha; + } + return (WGPUColorWriteMask)res; +} + +_SOKOL_PRIVATE WGPUShaderStage _sg_wgpu_shader_stage(sg_shader_stage stage) { + switch (stage) { + case SG_SHADERSTAGE_VERTEX: return WGPUShaderStage_Vertex; + case SG_SHADERSTAGE_FRAGMENT: return WGPUShaderStage_Fragment; + case SG_SHADERSTAGE_COMPUTE: return WGPUShaderStage_Compute; + default: SOKOL_UNREACHABLE; return WGPUShaderStage_None; + } +} + +_SOKOL_PRIVATE void _sg_wgpu_init_caps(void) { + _sg.backend = SG_BACKEND_WGPU; + _sg.features.origin_top_left = true; + _sg.features.image_clamp_to_border = false; + _sg.features.mrt_independent_blend_state = true; + _sg.features.mrt_independent_write_mask = true; + _sg.features.compute = true; + _sg.features.msaa_texture_bindings = true; + _sg.features.draw_base_vertex = true; + _sg.features.draw_base_instance = true; + _sg.features.dual_source_blending = wgpuDeviceHasFeature(_sg.wgpu.dev, WGPUFeatureName_DualSourceBlending); + _sg.features.vertexformat_int10_n2 = false; + + wgpuDeviceGetLimits(_sg.wgpu.dev, &_sg.wgpu.limits); + + const WGPULimits* l = &_sg.wgpu.limits; + _sg.limits.max_image_size_2d = (int) l->maxTextureDimension2D; + _sg.limits.max_image_size_cube = (int) l->maxTextureDimension2D; // not a bug, see: https://github.com/gpuweb/gpuweb/issues/1327 + _sg.limits.max_image_size_3d = (int) l->maxTextureDimension3D; + _sg.limits.max_image_size_array = (int) l->maxTextureDimension2D; + _sg.limits.max_image_array_layers = (int) l->maxTextureArrayLayers; + _sg.limits.max_vertex_attrs = SG_MAX_VERTEX_ATTRIBUTES; + _sg.limits.max_color_attachments = _sg_min((int)l->maxColorAttachments, SG_MAX_COLOR_ATTACHMENTS); + _sg.limits.max_texture_bindings_per_stage = _sg_min((int)l->maxSampledTexturesPerShaderStage, SG_MAX_VIEW_BINDSLOTS); + _sg.limits.max_storage_buffer_bindings_per_stage = _sg_min((int)l->maxStorageBuffersPerShaderStage, SG_MAX_VIEW_BINDSLOTS); + _sg.limits.max_storage_image_bindings_per_stage = _sg_min((int)l->maxStorageTexturesPerShaderStage, SG_MAX_VIEW_BINDSLOTS); + + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_R8]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RG8]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RGBA8]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_SRGB8A8]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_BGRA8]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_R16F]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RG16F]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RGBA16F]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RGB10A2]); + + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_R8SN]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_RG8SN]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_RGBA8SN]); + + // FIXME: can be made renderable via extension + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_RG11B10F]); + + // NOTE: msaa rendering is possible in WebGPU, but no resolve + // which is a combination that's not currently supported in sokol-gfx + _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_R8UI]); + _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_R8SI]); + _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_RG8UI]); + _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_RG8SI]); + _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_RGBA8UI]); + _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_RGBA8SI]); + _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_R16UI]); + _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_R16SI]); + _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_RG16UI]); + _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_RG16SI]); + _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_RGBA16UI]); + _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_RGBA16SI]); + _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_R32UI]); + _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_R32SI]); + _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_RG32UI]); + _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_RG32SI]); + _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_RGBA32UI]); + _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_RGBA32SI]); + + if (wgpuDeviceHasFeature(_sg.wgpu.dev, WGPUFeatureName_Float32Filterable)) { + _sg_pixelformat_sfr(&_sg.formats[SG_PIXELFORMAT_R32F]); + _sg_pixelformat_sfr(&_sg.formats[SG_PIXELFORMAT_RG32F]); + _sg_pixelformat_sfr(&_sg.formats[SG_PIXELFORMAT_RGBA32F]); + } else { + _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_R32F]); + _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_RG32F]); + _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_RGBA32F]); + } + if (wgpuDeviceHasFeature(_sg.wgpu.dev, WGPUFeatureName_Float32Blendable)) { + _sg.formats[SG_PIXELFORMAT_R32F].blend = true; + _sg.formats[SG_PIXELFORMAT_RG32F].blend = true; + _sg.formats[SG_PIXELFORMAT_RGBA32F].blend = true; + } + if (wgpuDeviceHasFeature(_sg.wgpu.dev, WGPUFeatureName_TextureFormatsTier1)) { + _sg_pixelformat_sbr(&_sg.formats[SG_PIXELFORMAT_R16]); + _sg_pixelformat_sbr(&_sg.formats[SG_PIXELFORMAT_R16SN]); + _sg_pixelformat_sbr(&_sg.formats[SG_PIXELFORMAT_RG16]); + _sg_pixelformat_sbr(&_sg.formats[SG_PIXELFORMAT_RG16SN]); + _sg_pixelformat_sbr(&_sg.formats[SG_PIXELFORMAT_RGBA16]); + _sg_pixelformat_sbr(&_sg.formats[SG_PIXELFORMAT_RGBA16SN]); + _sg_pixelformat_sbr(&_sg.formats[SG_PIXELFORMAT_R8SN]); + _sg_pixelformat_sbr(&_sg.formats[SG_PIXELFORMAT_RG8SN]); + _sg_pixelformat_sbr(&_sg.formats[SG_PIXELFORMAT_RGBA8SN]); + } + + _sg_pixelformat_srmd(&_sg.formats[SG_PIXELFORMAT_DEPTH]); + _sg_pixelformat_srmd(&_sg.formats[SG_PIXELFORMAT_DEPTH_STENCIL]); + + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_RGB9E5]); + + if (wgpuDeviceHasFeature(_sg.wgpu.dev, WGPUFeatureName_TextureCompressionBC)) { + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC1_RGBA]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC2_RGBA]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC3_RGBA]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC3_SRGBA]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC4_R]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC4_RSN]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC5_RG]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC5_RGSN]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC6H_RGBF]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC6H_RGBUF]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC7_RGBA]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC7_SRGBA]); + } + if (wgpuDeviceHasFeature(_sg.wgpu.dev, WGPUFeatureName_TextureCompressionETC2)) { + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RGB8]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_SRGB8]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RGB8A1]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RGBA8]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_SRGB8A8]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_R11]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_R11SN]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_RG11]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_RG11SN]); + } + + if (wgpuDeviceHasFeature(_sg.wgpu.dev, WGPUFeatureName_TextureCompressionASTC)) { + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ASTC_4x4_RGBA]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ASTC_4x4_SRGBA]); + } + + // see: https://github.com/gpuweb/gpuweb/issues/513 + // NOTE: can't express read-only/write-only vs read-write in sokol-gfx + // e.g. some of the below formats are only read-write with texture-tier-2 + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA8]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA8SN]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA8UI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA8SI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA16UI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA16SI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA16F]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R32UI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R32SI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R32F]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG32UI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG32SI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG32F]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA32UI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA32SI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA32F]); + if (wgpuDeviceHasFeature(_sg.wgpu.dev, WGPUFeatureName_TextureFormatsTier2)) { + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R8]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R8UI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R8SI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R16UI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R16SI]); + _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R16F]); + } +} + +_SOKOL_PRIVATE void _sg_wgpu_uniform_system_init(const sg_desc* desc) { + SOKOL_ASSERT(0 == _sg.wgpu.uniform.staging); + SOKOL_ASSERT(0 == _sg.wgpu.uniform.buf); + + // Add the max-uniform-update size (64 KB) to the requested buffer size, + // this is to prevent validation errors in the WebGPU implementation + // if the entire buffer size is used per frame. 64 KB is the allowed + // max uniform update size on NVIDIA + // + // FIXME: is this still needed? + _sg.wgpu.uniform.num_bytes = (uint32_t)(desc->uniform_buffer_size + _SG_WGPU_MAX_UNIFORM_UPDATE_SIZE); + _sg.wgpu.uniform.staging = (uint8_t*)_sg_malloc(_sg.wgpu.uniform.num_bytes); + + _SG_STRUCT(WGPUBufferDescriptor, ub_desc); + ub_desc.size = _sg.wgpu.uniform.num_bytes; + ub_desc.usage = WGPUBufferUsage_Uniform|WGPUBufferUsage_CopyDst; + _sg.wgpu.uniform.buf = wgpuDeviceCreateBuffer(_sg.wgpu.dev, &ub_desc); + SOKOL_ASSERT(_sg.wgpu.uniform.buf); +} + +_SOKOL_PRIVATE void _sg_wgpu_uniform_system_discard(void) { + if (_sg.wgpu.uniform.buf) { + wgpuBufferRelease(_sg.wgpu.uniform.buf); + _sg.wgpu.uniform.buf = 0; + } + if (_sg.wgpu.uniform.staging) { + _sg_free(_sg.wgpu.uniform.staging); + _sg.wgpu.uniform.staging = 0; + } +} + +_SOKOL_PRIVATE void _sg_wgpu_uniform_system_set_bindgroup(void) { + SOKOL_ASSERT(_sg.wgpu.uniform.dirty); + _sg.wgpu.uniform.dirty = false; + const _sg_pipeline_t* pip = _sg_pipeline_ref_ptr(&_sg.cur_pip); + const _sg_shader_t* shd = _sg_shader_ref_ptr(&pip->cmn.shader); + // NOTE: dynamic offsets must be in binding order, not in BindGroupEntry order + SOKOL_ASSERT(shd->wgpu.ub_num_dynoffsets < SG_MAX_UNIFORMBLOCK_BINDSLOTS); + _SG_STRUCT(uint32_t, dyn_offsets[SG_MAX_UNIFORMBLOCK_BINDSLOTS]); + for (size_t i = 0; i < SG_MAX_UNIFORMBLOCK_BINDSLOTS; i++) { + if (shd->cmn.uniform_blocks[i].stage == SG_SHADERSTAGE_NONE) { + continue; + } + uint8_t dynoffset_index = shd->wgpu.ub_dynoffsets[i]; + SOKOL_ASSERT(dynoffset_index < shd->wgpu.ub_num_dynoffsets); + dyn_offsets[dynoffset_index] = _sg.wgpu.uniform.bind_offsets[i]; + } + if (_sg.cur_pass.is_compute) { + SOKOL_ASSERT(_sg.wgpu.cpass_enc); + wgpuComputePassEncoderSetBindGroup(_sg.wgpu.cpass_enc, + _SG_WGPU_UB_BINDGROUP_INDEX, + shd->wgpu.bg_ub, + shd->wgpu.ub_num_dynoffsets, + dyn_offsets); + } else { + SOKOL_ASSERT(_sg.wgpu.rpass_enc); + wgpuRenderPassEncoderSetBindGroup(_sg.wgpu.rpass_enc, + _SG_WGPU_UB_BINDGROUP_INDEX, + shd->wgpu.bg_ub, + shd->wgpu.ub_num_dynoffsets, + dyn_offsets); + } +} + +_SOKOL_PRIVATE void _sg_wgpu_uniform_system_on_apply_pipeline(void) { + _sg.wgpu.uniform.dirty = false; +} + +_SOKOL_PRIVATE void _sg_wgpu_uniform_system_on_commit(void) { + wgpuQueueWriteBuffer(_sg.wgpu.queue, _sg.wgpu.uniform.buf, 0, _sg.wgpu.uniform.staging, _sg.wgpu.uniform.offset); + _sg_stats_add(wgpu.uniforms.size_write_buffer, _sg.wgpu.uniform.offset); + _sg.wgpu.uniform.offset = 0; + _sg_clear(_sg.wgpu.uniform.bind_offsets, sizeof(_sg.wgpu.uniform.bind_offsets)); +} + +_SOKOL_PRIVATE void _sg_wgpu_bindgroups_pool_init(const sg_desc* desc) { + SOKOL_ASSERT((desc->wgpu.bindgroups_cache_size > 0) && (desc->wgpu.bindgroups_cache_size < _SG_MAX_POOL_SIZE)); + _sg_wgpu_bindgroups_pool_t* p = &_sg.wgpu.bindgroups_pool; + SOKOL_ASSERT(0 == p->bindgroups); + const int pool_size = desc->wgpu.bindgroups_cache_size; + _sg_pool_init(&p->pool, pool_size); + size_t pool_byte_size = sizeof(_sg_wgpu_bindgroup_t) * (size_t)p->pool.size; + p->bindgroups = (_sg_wgpu_bindgroup_t*) _sg_malloc_clear(pool_byte_size); +} + +_SOKOL_PRIVATE void _sg_wgpu_bindgroups_pool_discard(void) { + _sg_wgpu_bindgroups_pool_t* p = &_sg.wgpu.bindgroups_pool; + SOKOL_ASSERT(p->bindgroups); + _sg_free(p->bindgroups); p->bindgroups = 0; + _sg_pool_discard(&p->pool); +} + +_SOKOL_PRIVATE _sg_wgpu_bindgroup_t* _sg_wgpu_bindgroup_at(uint32_t bg_id) { + SOKOL_ASSERT(SG_INVALID_ID != bg_id); + _sg_wgpu_bindgroups_pool_t* p = &_sg.wgpu.bindgroups_pool; + int slot_index = _sg_slot_index(bg_id); + SOKOL_ASSERT((slot_index > _SG_INVALID_SLOT_INDEX) && (slot_index < p->pool.size)); + return &p->bindgroups[slot_index]; +} + +_SOKOL_PRIVATE _sg_wgpu_bindgroup_t* _sg_wgpu_lookup_bindgroup(uint32_t bg_id) { + if (SG_INVALID_ID != bg_id) { + _sg_wgpu_bindgroup_t* bg = _sg_wgpu_bindgroup_at(bg_id); + if (bg->slot.id == bg_id) { + return bg; + } + } + return 0; +} + +_SOKOL_PRIVATE _sg_wgpu_bindgroup_handle_t _sg_wgpu_alloc_bindgroup(void) { + _sg_wgpu_bindgroups_pool_t* p = &_sg.wgpu.bindgroups_pool; + _sg_wgpu_bindgroup_handle_t res; + int slot_index = _sg_pool_alloc_index(&p->pool); + if (_SG_INVALID_SLOT_INDEX != slot_index) { + res.id = _sg_slot_alloc(&p->pool, &p->bindgroups[slot_index].slot, slot_index); + } else { + res.id = SG_INVALID_ID; + _SG_ERROR(WGPU_BINDGROUPS_POOL_EXHAUSTED); + } + return res; +} + +_SOKOL_PRIVATE void _sg_wgpu_dealloc_bindgroup(_sg_wgpu_bindgroup_t* bg) { + SOKOL_ASSERT(bg && (bg->slot.state == SG_RESOURCESTATE_ALLOC) && (bg->slot.id != SG_INVALID_ID)); + _sg_wgpu_bindgroups_pool_t* p = &_sg.wgpu.bindgroups_pool; + _sg_pool_free_index(&p->pool, _sg_slot_index(bg->slot.id)); + _sg_slot_reset(&bg->slot); +} + +_SOKOL_PRIVATE void _sg_wgpu_reset_bindgroup_to_alloc_state(_sg_wgpu_bindgroup_t* bg) { + SOKOL_ASSERT(bg); + _sg_slot_t slot = bg->slot; + _sg_clear(bg, sizeof(_sg_wgpu_bindgroup_t)); + bg->slot = slot; + bg->slot.state = SG_RESOURCESTATE_ALLOC; +} + +// MurmurHash64B (see: https://github.com/aappleby/smhasher/blob/61a0530f28277f2e850bfc39600ce61d02b518de/src/MurmurHash2.cpp#L142) +_SOKOL_PRIVATE uint64_t _sg_wgpu_hash(const void* key, int len, uint64_t seed) { + const uint32_t m = 0x5bd1e995; + const int r = 24; + uint32_t h1 = (uint32_t)seed ^ (uint32_t)len; + uint32_t h2 = (uint32_t)(seed >> 32); + const uint32_t * data = (const uint32_t *)key; + while (len >= 8) { + uint32_t k1 = *data++; + k1 *= m; k1 ^= k1 >> r; k1 *= m; + h1 *= m; h1 ^= k1; + len -= 4; + uint32_t k2 = *data++; + k2 *= m; k2 ^= k2 >> r; k2 *= m; + h2 *= m; h2 ^= k2; + len -= 4; + } + if (len >= 4) { + uint32_t k1 = *data++; + k1 *= m; k1 ^= k1 >> r; k1 *= m; + h1 *= m; h1 ^= k1; + len -= 4; + } + switch(len) { + case 3: h2 ^= (uint32_t)(((unsigned char*)data)[2] << 16); + // fall through + case 2: h2 ^= (uint32_t)(((unsigned char*)data)[1] << 8); + // fall through + case 1: h2 ^= ((unsigned char*)data)[0]; + // fall through + h2 *= m; + }; + h1 ^= h2 >> 18; h1 *= m; + h2 ^= h1 >> 22; h2 *= m; + h1 ^= h2 >> 17; h1 *= m; + h2 ^= h1 >> 19; h2 *= m; + uint64_t h = h1; + h = (h << 32) | h2; + return h; +} + +_SOKOL_PRIVATE uint64_t _sg_wgpu_bindgroups_cache_item(_sg_wgpu_bindgroups_cache_item_type_t type, uint8_t wgpu_binding, uint32_t id, uint32_t uninit_count) { + const uint64_t bb = wgpu_binding; + const uint64_t t = type & 3; + const uint64_t ccccc = uninit_count & ((1 << 22) - 1); + const uint64_t iiiiiiii = id; + return (bb << 56) | (t << 54) | (ccccc << 32) | iiiiiiii; +} + +_SOKOL_PRIVATE uint64_t _sg_wgpu_bindgroups_cache_pip_item(const _sg_slot_t* slot) { + return _sg_wgpu_bindgroups_cache_item(_SG_WGPU_BINDGROUPSCACHEITEMTYPE_PIPELINE, 0xFF, slot->id, slot->uninit_count); +} + +_SOKOL_PRIVATE uint64_t _sg_wgpu_bindgroups_cache_view_item(uint8_t wgpu_binding, const _sg_slot_t* slot) { + return _sg_wgpu_bindgroups_cache_item(_SG_WGPU_BINDGROUPSCACHEITEMTYPE_VIEW, wgpu_binding, slot->id, slot->uninit_count); +} + +_SOKOL_PRIVATE uint64_t _sg_wgpu_bindgroups_cache_sampler_item(uint8_t wgpu_binding, const _sg_slot_t* slot) { + return _sg_wgpu_bindgroups_cache_item(_SG_WGPU_BINDGROUPSCACHEITEMTYPE_SAMPLER, wgpu_binding, slot->id, slot->uninit_count); +} + +_SOKOL_PRIVATE void _sg_wgpu_init_bindgroups_cache_key(_sg_wgpu_bindgroups_cache_key_t* key, const _sg_bindings_ptrs_t* bnd) { + SOKOL_ASSERT(bnd); + SOKOL_ASSERT(bnd->pip); + const _sg_shader_t* shd = _sg_shader_ref_ptr(&bnd->pip->cmn.shader); + + _sg_clear(key->items, sizeof(key->items)); + key->items[0] = _sg_wgpu_bindgroups_cache_pip_item(&bnd->pip->slot); + for (size_t i = 0; i < SG_MAX_VIEW_BINDSLOTS; i++) { + if (shd->cmn.views[i].stage == SG_SHADERSTAGE_NONE) { + continue; + } + SOKOL_ASSERT(bnd->views[i]); + const size_t item_idx = i + 1; + SOKOL_ASSERT(item_idx < _SG_WGPU_BINDGROUPSCACHEKEY_NUM_ITEMS); + SOKOL_ASSERT(0 == key->items[item_idx]); + const uint8_t wgpu_binding = shd->wgpu.view_grp1_bnd_n[i]; + key->items[item_idx] = _sg_wgpu_bindgroups_cache_view_item(wgpu_binding, &bnd->views[i]->slot); + } + for (size_t i = 0; i < SG_MAX_SAMPLER_BINDSLOTS; i++) { + if (shd->cmn.samplers[i].stage == SG_SHADERSTAGE_NONE) { + continue; + } + SOKOL_ASSERT(bnd->smps[i]); + const size_t item_idx = i + 1 + SG_MAX_VIEW_BINDSLOTS; + SOKOL_ASSERT(item_idx < _SG_WGPU_BINDGROUPSCACHEKEY_NUM_ITEMS); + SOKOL_ASSERT(0 == key->items[item_idx]); + const uint8_t wgpu_binding = shd->wgpu.smp_grp1_bnd_n[i]; + key->items[item_idx] = _sg_wgpu_bindgroups_cache_sampler_item(wgpu_binding, &bnd->smps[i]->slot); + } + key->hash = _sg_wgpu_hash(&key->items, (int)sizeof(key->items), 0x1234567887654321); +} + +_SOKOL_PRIVATE bool _sg_wgpu_compare_bindgroups_cache_key(_sg_wgpu_bindgroups_cache_key_t* k0, _sg_wgpu_bindgroups_cache_key_t* k1) { + SOKOL_ASSERT(k0 && k1); + if (k0->hash != k1->hash) { + return false; + } + if (memcmp(&k0->items, &k1->items, sizeof(k0->items)) != 0) { + _sg_stats_inc(wgpu.bindings.num_bindgroup_cache_hash_vs_key_mismatch); + return false; + } + return true; +} + +_SOKOL_PRIVATE _sg_wgpu_bindgroup_t* _sg_wgpu_create_bindgroup(_sg_bindings_ptrs_t* bnd) { + SOKOL_ASSERT(_sg.wgpu.dev); + SOKOL_ASSERT(bnd->pip); + const _sg_shader_t* shd = _sg_shader_ref_ptr(&bnd->pip->cmn.shader); + _sg_stats_inc(wgpu.bindings.num_create_bindgroup); + _sg_wgpu_bindgroup_handle_t bg_id = _sg_wgpu_alloc_bindgroup(); + if (bg_id.id == SG_INVALID_ID) { + return 0; + } + _sg_wgpu_bindgroup_t* bg = _sg_wgpu_bindgroup_at(bg_id.id); + SOKOL_ASSERT(bg && (bg->slot.state == SG_RESOURCESTATE_ALLOC)); + + // create wgpu bindgroup object (also see _sg_wgpu_create_shader()) + WGPUBindGroupLayout bgl = shd->wgpu.bgl_view_smp; + SOKOL_ASSERT(bgl); + _SG_STRUCT(WGPUBindGroupEntry, bg_entries[_SG_WGPU_MAX_VIEW_SMP_BINDGROUP_ENTRIES]); + size_t bgl_index = 0; + for (size_t i = 0; i < SG_MAX_VIEW_BINDSLOTS; i++) { + if (shd->cmn.views[i].stage == SG_SHADERSTAGE_NONE) { + continue; + } + const _sg_view_t* view = bnd->views[i]; + SOKOL_ASSERT(view); + SOKOL_ASSERT(bgl_index < _SG_WGPU_MAX_VIEW_SMP_BINDGROUP_ENTRIES); + WGPUBindGroupEntry* bg_entry = &bg_entries[bgl_index]; + bg_entry->binding = shd->wgpu.view_grp1_bnd_n[i]; + if (view->cmn.type == SG_VIEWTYPE_STORAGEBUFFER) { + const _sg_buffer_t* buf = _sg_buffer_ref_ptr(&view->cmn.buf.ref); + SOKOL_ASSERT(buf->wgpu.buf); + SOKOL_ASSERT(view->cmn.buf.offset < buf->cmn.size); + bg_entry->buffer = buf->wgpu.buf; + bg_entry->offset = (uint64_t)view->cmn.buf.offset; + bg_entry->size = (uint64_t)(buf->cmn.size - view->cmn.buf.offset); + } else { + SOKOL_ASSERT(view->wgpu.view); + bg_entry->textureView = view->wgpu.view; + } + bgl_index += 1; + } + for (size_t i = 0; i < SG_MAX_SAMPLER_BINDSLOTS; i++) { + if (shd->cmn.samplers[i].stage == SG_SHADERSTAGE_NONE) { + continue; + } + SOKOL_ASSERT(bnd->smps[i]); + SOKOL_ASSERT(bgl_index < _SG_WGPU_MAX_VIEW_SMP_BINDGROUP_ENTRIES); + WGPUBindGroupEntry* bg_entry = &bg_entries[bgl_index]; + bg_entry->binding = shd->wgpu.smp_grp1_bnd_n[i]; + bg_entry->sampler = bnd->smps[i]->wgpu.smp; + bgl_index += 1; + } + _SG_STRUCT(WGPUBindGroupDescriptor, bg_desc); + bg_desc.layout = bgl; + bg_desc.entryCount = bgl_index; + bg_desc.entries = bg_entries; + bg->bindgroup = wgpuDeviceCreateBindGroup(_sg.wgpu.dev, &bg_desc); + if (bg->bindgroup == 0) { + _SG_ERROR(WGPU_CREATEBINDGROUP_FAILED); + bg->slot.state = SG_RESOURCESTATE_FAILED; + return bg; + } + _sg_wgpu_init_bindgroups_cache_key(&bg->key, bnd); + bg->slot.state = SG_RESOURCESTATE_VALID; + return bg; +} + +_SOKOL_PRIVATE void _sg_wgpu_discard_bindgroup(_sg_wgpu_bindgroup_t* bg) { + SOKOL_ASSERT(bg); + _sg_stats_inc(wgpu.bindings.num_discard_bindgroup); + if (bg->slot.state == SG_RESOURCESTATE_VALID) { + if (bg->bindgroup) { + wgpuBindGroupRelease(bg->bindgroup); + bg->bindgroup = 0; + } + _sg_wgpu_reset_bindgroup_to_alloc_state(bg); + SOKOL_ASSERT(bg->slot.state == SG_RESOURCESTATE_ALLOC); + } + if (bg->slot.state == SG_RESOURCESTATE_ALLOC) { + _sg_wgpu_dealloc_bindgroup(bg); + SOKOL_ASSERT(bg->slot.state == SG_RESOURCESTATE_INITIAL); + } +} + +_SOKOL_PRIVATE void _sg_wgpu_discard_all_bindgroups(void) { + _sg_wgpu_bindgroups_pool_t* p = &_sg.wgpu.bindgroups_pool; + for (int i = 0; i < p->pool.size; i++) { + sg_resource_state state = p->bindgroups[i].slot.state; + if ((state == SG_RESOURCESTATE_VALID) || (state == SG_RESOURCESTATE_FAILED)) { + _sg_wgpu_discard_bindgroup(&p->bindgroups[i]); + } + } +} + +_SOKOL_PRIVATE void _sg_wgpu_bindgroups_cache_init(const sg_desc* desc) { + SOKOL_ASSERT(desc); + SOKOL_ASSERT(_sg.wgpu.bindgroups_cache.num == 0); + SOKOL_ASSERT(_sg.wgpu.bindgroups_cache.index_mask == 0); + SOKOL_ASSERT(_sg.wgpu.bindgroups_cache.items == 0); + const int num = desc->wgpu.bindgroups_cache_size; + if (num <= 1) { + _SG_PANIC(WGPU_BINDGROUPSCACHE_SIZE_GREATER_ONE); + } + if (!_sg_ispow2(num)) { + _SG_PANIC(WGPU_BINDGROUPSCACHE_SIZE_POW2); + } + _sg.wgpu.bindgroups_cache.num = (uint32_t)desc->wgpu.bindgroups_cache_size; + _sg.wgpu.bindgroups_cache.index_mask = _sg.wgpu.bindgroups_cache.num - 1; + size_t size_in_bytes = sizeof(_sg_wgpu_bindgroup_handle_t) * (size_t)num; + _sg.wgpu.bindgroups_cache.items = (_sg_wgpu_bindgroup_handle_t*)_sg_malloc_clear(size_in_bytes); +} + +_SOKOL_PRIVATE void _sg_wgpu_bindgroups_cache_discard(void) { + if (_sg.wgpu.bindgroups_cache.items) { + _sg_free(_sg.wgpu.bindgroups_cache.items); + _sg.wgpu.bindgroups_cache.items = 0; + } + _sg.wgpu.bindgroups_cache.num = 0; + _sg.wgpu.bindgroups_cache.index_mask = 0; +} + +_SOKOL_PRIVATE void _sg_wgpu_bindgroups_cache_set(uint64_t hash, uint32_t bg_id) { + uint32_t index = hash & _sg.wgpu.bindgroups_cache.index_mask; + SOKOL_ASSERT(index < _sg.wgpu.bindgroups_cache.num); + SOKOL_ASSERT(_sg.wgpu.bindgroups_cache.items); + _sg.wgpu.bindgroups_cache.items[index].id = bg_id; +} + +_SOKOL_PRIVATE uint32_t _sg_wgpu_bindgroups_cache_get(uint64_t hash) { + uint32_t index = hash & _sg.wgpu.bindgroups_cache.index_mask; + SOKOL_ASSERT(index < _sg.wgpu.bindgroups_cache.num); + SOKOL_ASSERT(_sg.wgpu.bindgroups_cache.items); + return _sg.wgpu.bindgroups_cache.items[index].id; +} + +// called from wgpu resource destroy functions to also invalidate any +// bindgroups cache slot and bindgroup referencing that resource +_SOKOL_PRIVATE void _sg_wgpu_bindgroups_cache_invalidate(_sg_wgpu_bindgroups_cache_item_type_t type, const _sg_slot_t* slot) { + const uint64_t key_mask = _sg_wgpu_bindgroups_cache_item(type, 0xFF, 0xFFFFFFFF, 0xFFFFFFFF); + const uint64_t key_item = _sg_wgpu_bindgroups_cache_item(type, 0, slot->id, slot->uninit_count) & key_mask; + SOKOL_ASSERT(_sg.wgpu.bindgroups_cache.items); + for (uint32_t cache_item_idx = 0; cache_item_idx < _sg.wgpu.bindgroups_cache.num; cache_item_idx++) { + const uint32_t bg_id = _sg.wgpu.bindgroups_cache.items[cache_item_idx].id; + if (bg_id != SG_INVALID_ID) { + _sg_wgpu_bindgroup_t* bg = _sg_wgpu_lookup_bindgroup(bg_id); + SOKOL_ASSERT(bg && (bg->slot.state == SG_RESOURCESTATE_VALID)); + // check if resource is in bindgroup, if yes discard bindgroup and invalidate cache slot + bool invalidate_cache_item = false; + for (int key_item_idx = 0; key_item_idx < _SG_WGPU_BINDGROUPSCACHEKEY_NUM_ITEMS; key_item_idx++) { + if ((bg->key.items[key_item_idx] & key_mask) == key_item) { + invalidate_cache_item = true; + break; + } + } + if (invalidate_cache_item) { + _sg_wgpu_discard_bindgroup(bg); bg = 0; + _sg_wgpu_bindgroups_cache_set(cache_item_idx, SG_INVALID_ID); + _sg_stats_inc(wgpu.bindings.num_bindgroup_cache_invalidates); + } + } + } +} + +_SOKOL_PRIVATE void _sg_wgpu_bindings_cache_clear(void) { + memset(&_sg.wgpu.bindings_cache, 0, sizeof(_sg.wgpu.bindings_cache)); +} + +_SOKOL_PRIVATE bool _sg_wgpu_bindings_cache_vb_dirty(size_t index, const _sg_buffer_t* vb, uint64_t offset) { + SOKOL_ASSERT(index < SG_MAX_VERTEXBUFFER_BINDSLOTS); + if (vb) { + return (_sg.wgpu.bindings_cache.vbs[index].buffer.id != vb->slot.id) + || (_sg.wgpu.bindings_cache.vbs[index].offset != offset); + } else { + return _sg.wgpu.bindings_cache.vbs[index].buffer.id != SG_INVALID_ID; + } +} + +_SOKOL_PRIVATE void _sg_wgpu_bindings_cache_vb_update(size_t index, const _sg_buffer_t* vb, uint64_t offset) { + SOKOL_ASSERT(index < SG_MAX_VERTEXBUFFER_BINDSLOTS); + if (vb) { + _sg.wgpu.bindings_cache.vbs[index].buffer.id = vb->slot.id; + _sg.wgpu.bindings_cache.vbs[index].offset = offset; + } else { + _sg.wgpu.bindings_cache.vbs[index].buffer.id = SG_INVALID_ID; + _sg.wgpu.bindings_cache.vbs[index].offset = 0; + } +} + +_SOKOL_PRIVATE bool _sg_wgpu_bindings_cache_ib_dirty(const _sg_buffer_t* ib, uint64_t offset) { + if (ib) { + return (_sg.wgpu.bindings_cache.ib.buffer.id != ib->slot.id) + || (_sg.wgpu.bindings_cache.ib.offset != offset); + } else { + return _sg.wgpu.bindings_cache.ib.buffer.id != SG_INVALID_ID; + } +} + +_SOKOL_PRIVATE void _sg_wgpu_bindings_cache_ib_update(const _sg_buffer_t* ib, uint64_t offset) { + if (ib) { + _sg.wgpu.bindings_cache.ib.buffer.id = ib->slot.id; + _sg.wgpu.bindings_cache.ib.offset = offset; + } else { + _sg.wgpu.bindings_cache.ib.buffer.id = SG_INVALID_ID; + _sg.wgpu.bindings_cache.ib.offset = 0; + } +} + +_SOKOL_PRIVATE bool _sg_wgpu_bindings_cache_bg_dirty(const _sg_wgpu_bindgroup_t* bg) { + if (bg) { + return _sg.wgpu.bindings_cache.bg.id != bg->slot.id; + } else { + return _sg.wgpu.bindings_cache.bg.id != SG_INVALID_ID; + } +} + +_SOKOL_PRIVATE void _sg_wgpu_bindings_cache_bg_update(const _sg_wgpu_bindgroup_t* bg) { + if (bg) { + _sg.wgpu.bindings_cache.bg.id = bg->slot.id; + } else { + _sg.wgpu.bindings_cache.bg.id = SG_INVALID_ID; + } +} + +_SOKOL_PRIVATE void _sg_wgpu_set_bindgroup(uint32_t bg_idx, _sg_wgpu_bindgroup_t* bg) { + if (_sg_wgpu_bindings_cache_bg_dirty(bg)) { + _sg_wgpu_bindings_cache_bg_update(bg); + _sg_stats_inc(wgpu.bindings.num_set_bindgroup); + if (_sg.cur_pass.is_compute) { + SOKOL_ASSERT(_sg.wgpu.cpass_enc); + if (bg) { + SOKOL_ASSERT(bg->slot.state == SG_RESOURCESTATE_VALID); + SOKOL_ASSERT(bg->bindgroup); + wgpuComputePassEncoderSetBindGroup(_sg.wgpu.cpass_enc, bg_idx, bg->bindgroup, 0, 0); + } else { + wgpuComputePassEncoderSetBindGroup(_sg.wgpu.cpass_enc, bg_idx, 0, 0, 0); + } + } else { + SOKOL_ASSERT(_sg.wgpu.rpass_enc); + if (bg) { + SOKOL_ASSERT(bg->slot.state == SG_RESOURCESTATE_VALID); + SOKOL_ASSERT(bg->bindgroup); + wgpuRenderPassEncoderSetBindGroup(_sg.wgpu.rpass_enc, bg_idx, bg->bindgroup, 0, 0); + } else { + wgpuRenderPassEncoderSetBindGroup(_sg.wgpu.rpass_enc, bg_idx, 0, 0, 0); + } + } + } else { + _sg_stats_inc(wgpu.bindings.num_skip_redundant_bindgroup); + } +} + +_SOKOL_PRIVATE bool _sg_wgpu_apply_bindings_bindgroup(_sg_bindings_ptrs_t* bnd) { + if (!_sg.desc.wgpu.disable_bindgroups_cache) { + _sg_wgpu_bindgroup_t* bg = 0; + _sg_wgpu_bindgroups_cache_key_t key; + _sg_wgpu_init_bindgroups_cache_key(&key, bnd); + uint32_t bg_id = _sg_wgpu_bindgroups_cache_get(key.hash); + if (bg_id != SG_INVALID_ID) { + // potential cache hit + bg = _sg_wgpu_lookup_bindgroup(bg_id); + SOKOL_ASSERT(bg && (bg->slot.state == SG_RESOURCESTATE_VALID)); + if (!_sg_wgpu_compare_bindgroups_cache_key(&key, &bg->key)) { + // cache collision, need to delete cached bindgroup + _sg_stats_inc(wgpu.bindings.num_bindgroup_cache_collisions); + _sg_wgpu_discard_bindgroup(bg); + _sg_wgpu_bindgroups_cache_set(key.hash, SG_INVALID_ID); + bg = 0; + } else { + _sg_stats_inc(wgpu.bindings.num_bindgroup_cache_hits); + } + } else { + _sg_stats_inc(wgpu.bindings.num_bindgroup_cache_misses); + } + if (bg == 0) { + // either no cache entry yet, or cache collision, create new bindgroup and store in cache + bg = _sg_wgpu_create_bindgroup(bnd); + _sg_wgpu_bindgroups_cache_set(key.hash, bg->slot.id); + } + if (bg && bg->slot.state == SG_RESOURCESTATE_VALID) { + _sg_wgpu_set_bindgroup(_SG_WGPU_VIEW_SMP_BINDGROUP_INDEX, bg); + } else { + return false; + } + } else { + // bindgroups cache disabled, create and destroy bindgroup on the fly (expensive!) + _sg_wgpu_bindgroup_t* bg = _sg_wgpu_create_bindgroup(bnd); + if (bg) { + if (bg->slot.state == SG_RESOURCESTATE_VALID) { + _sg_wgpu_set_bindgroup(_SG_WGPU_VIEW_SMP_BINDGROUP_INDEX, bg); + } + _sg_wgpu_discard_bindgroup(bg); + } else { + return false; + } + } + return true; +} + +_SOKOL_PRIVATE bool _sg_wgpu_apply_index_buffer(_sg_bindings_ptrs_t* bnd) { + SOKOL_ASSERT(_sg.wgpu.rpass_enc); + const _sg_buffer_t* ib = bnd->ib; + uint64_t offset = (uint64_t)bnd->ib_offset; + if (_sg_wgpu_bindings_cache_ib_dirty(ib, offset)) { + _sg_wgpu_bindings_cache_ib_update(ib, offset); + if (ib) { + const WGPUIndexFormat format = _sg_wgpu_indexformat(bnd->pip->cmn.index_type); + const uint64_t buf_size = (uint64_t)ib->cmn.size; + SOKOL_ASSERT(buf_size > offset); + const uint64_t max_bytes = buf_size - offset; + wgpuRenderPassEncoderSetIndexBuffer(_sg.wgpu.rpass_enc, ib->wgpu.buf, format, offset, max_bytes); + /* + NOTE: as per webgpu spec setIndexBuffer does not accept a null pointer + } else { + wgpuRenderPassEncoderSetIndexBuffer(_sg.wgpu.rpass_enc, 0, WGPUIndexFormat_Undefined, 0, 0); + */ + } + _sg_stats_inc(wgpu.bindings.num_set_index_buffer); + } else { + _sg_stats_inc(wgpu.bindings.num_skip_redundant_index_buffer); + } + return true; +} + +_SOKOL_PRIVATE bool _sg_wgpu_apply_vertex_buffers(_sg_bindings_ptrs_t* bnd) { + SOKOL_ASSERT(_sg.wgpu.rpass_enc); + for (uint32_t slot = 0; slot < SG_MAX_VERTEXBUFFER_BINDSLOTS; slot++) { + const _sg_buffer_t* vb = bnd->vbs[slot]; + const uint64_t offset = (uint64_t)bnd->vb_offsets[slot]; + if (_sg_wgpu_bindings_cache_vb_dirty(slot, vb, offset)) { + _sg_wgpu_bindings_cache_vb_update(slot, vb, offset); + if (vb) { + const uint64_t buf_size = (uint64_t)vb->cmn.size; + SOKOL_ASSERT(buf_size > offset); + const uint64_t max_bytes = buf_size - offset; + wgpuRenderPassEncoderSetVertexBuffer(_sg.wgpu.rpass_enc, slot, vb->wgpu.buf, offset, max_bytes); + } else { + wgpuRenderPassEncoderSetVertexBuffer(_sg.wgpu.rpass_enc, slot, 0, 0, 0); + } + _sg_stats_inc(wgpu.bindings.num_set_vertex_buffer); + } else { + _sg_stats_inc(wgpu.bindings.num_skip_redundant_vertex_buffer); + } + } + return true; +} + +_SOKOL_PRIVATE void _sg_wgpu_setup_backend(const sg_desc* desc) { + SOKOL_ASSERT(desc); + SOKOL_ASSERT(desc->environment.wgpu.device); + SOKOL_ASSERT(desc->uniform_buffer_size > 0); + _sg.wgpu.valid = true; + _sg.wgpu.dev = (WGPUDevice) desc->environment.wgpu.device; + _sg.wgpu.queue = wgpuDeviceGetQueue(_sg.wgpu.dev); + SOKOL_ASSERT(_sg.wgpu.queue); + + _sg_wgpu_init_caps(); + _sg_wgpu_uniform_system_init(desc); + _sg_wgpu_bindgroups_pool_init(desc); + _sg_wgpu_bindgroups_cache_init(desc); + _sg_wgpu_bindings_cache_clear(); +} + +_SOKOL_PRIVATE void _sg_wgpu_discard_backend(void) { + SOKOL_ASSERT(_sg.wgpu.valid); + _sg.wgpu.valid = false; + _sg_wgpu_discard_all_bindgroups(); + _sg_wgpu_bindgroups_cache_discard(); + _sg_wgpu_bindgroups_pool_discard(); + _sg_wgpu_uniform_system_discard(); + // the command encoder is usually released in sg_commit() + if (_sg.wgpu.cmd_enc) { + wgpuCommandEncoderRelease(_sg.wgpu.cmd_enc); _sg.wgpu.cmd_enc = 0; + } + wgpuQueueRelease(_sg.wgpu.queue); _sg.wgpu.queue = 0; +} + +_SOKOL_PRIVATE void _sg_wgpu_reset_state_cache(void) { + _sg_wgpu_bindings_cache_clear(); +} + +_SOKOL_PRIVATE sg_resource_state _sg_wgpu_create_buffer(_sg_buffer_t* buf, const sg_buffer_desc* desc) { + SOKOL_ASSERT(buf && desc); + SOKOL_ASSERT(buf->cmn.size > 0); + const bool injected = (0 != desc->wgpu_buffer); + if (injected) { + buf->wgpu.buf = (WGPUBuffer) desc->wgpu_buffer; + wgpuBufferAddRef(buf->wgpu.buf); + } else { + // buffer mapping size must be multiple of 4, so round up buffer size (only a problem + // with index buffers containing odd number of indices) + const uint64_t wgpu_buf_size = _sg_roundup_u64((uint64_t)buf->cmn.size, 4); + const bool map_at_creation = buf->cmn.usage.immutable && (desc->data.ptr); + + _SG_STRUCT(WGPUBufferDescriptor, wgpu_buf_desc); + wgpu_buf_desc.usage = _sg_wgpu_buffer_usage(&buf->cmn.usage); + wgpu_buf_desc.size = wgpu_buf_size; + wgpu_buf_desc.mappedAtCreation = map_at_creation; + wgpu_buf_desc.label = _sg_wgpu_stringview(desc->label); + buf->wgpu.buf = wgpuDeviceCreateBuffer(_sg.wgpu.dev, &wgpu_buf_desc); + if (0 == buf->wgpu.buf) { + _SG_ERROR(WGPU_CREATE_BUFFER_FAILED); + return SG_RESOURCESTATE_FAILED; + } + if (map_at_creation) { + SOKOL_ASSERT(desc->data.ptr && (desc->data.size > 0)); + SOKOL_ASSERT(desc->data.size <= (size_t)buf->cmn.size); + // FIXME: inefficient on WASM + void* ptr = wgpuBufferGetMappedRange(buf->wgpu.buf, 0, wgpu_buf_size); + SOKOL_ASSERT(ptr); + memcpy(ptr, desc->data.ptr, desc->data.size); + wgpuBufferUnmap(buf->wgpu.buf); + } + } + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_wgpu_discard_buffer(_sg_buffer_t* buf) { + SOKOL_ASSERT(buf); + if (buf->wgpu.buf) { + wgpuBufferRelease(buf->wgpu.buf); + } +} + +_SOKOL_PRIVATE void _sg_wgpu_copy_buffer_data(const _sg_buffer_t* buf, uint64_t offset, const sg_range* data) { + SOKOL_ASSERT((offset + data->size) <= (size_t)buf->cmn.size); + // WebGPU's write-buffer requires the size to be a multiple of four, so we may need to split the copy + // operation into two writeBuffer calls + uint64_t clamped_size = data->size & ~3UL; + uint64_t extra_size = data->size & 3UL; + SOKOL_ASSERT(extra_size < 4); + wgpuQueueWriteBuffer(_sg.wgpu.queue, buf->wgpu.buf, offset, data->ptr, clamped_size); + if (extra_size > 0) { + const uint64_t extra_src_offset = clamped_size; + const uint64_t extra_dst_offset = offset + clamped_size; + uint8_t extra_data[4] = { 0 }; + const uint8_t* extra_src_ptr = ((uint8_t*)data->ptr) + extra_src_offset; + for (size_t i = 0; i < extra_size; i++) { + extra_data[i] = extra_src_ptr[i]; + } + wgpuQueueWriteBuffer(_sg.wgpu.queue, buf->wgpu.buf, extra_dst_offset, extra_data, 4); + } +} + +_SOKOL_PRIVATE void _sg_wgpu_copy_image_data(const _sg_image_t* img, const sg_image_data* data) { + _SG_STRUCT(WGPUTexelCopyBufferLayout, wgpu_layout); + _SG_STRUCT(WGPUTexelCopyTextureInfo, wgpu_copy_tex); + wgpu_copy_tex.texture = img->wgpu.tex; + wgpu_copy_tex.aspect = WGPUTextureAspect_All; + _SG_STRUCT(WGPUExtent3D, wgpu_extent); + for (int mip_index = 0; mip_index < img->cmn.num_mipmaps; mip_index++) { + wgpu_copy_tex.mipLevel = (uint32_t)mip_index; + int mip_width = _sg_miplevel_dim(img->cmn.width, mip_index); + int mip_height = _sg_miplevel_dim(img->cmn.height, mip_index); + int mip_slices = (img->cmn.type == SG_IMAGETYPE_3D) ? _sg_miplevel_dim(img->cmn.num_slices, mip_index) : img->cmn.num_slices; + const int row_pitch = _sg_row_pitch(img->cmn.pixel_format, mip_width, 1); + const int num_rows = _sg_num_rows(img->cmn.pixel_format, mip_height); + if (_sg_is_compressed_pixel_format(img->cmn.pixel_format)) { + mip_width = _sg_roundup(mip_width, 4); + mip_height = _sg_roundup(mip_height, 4); + } + wgpu_layout.bytesPerRow = (uint32_t)row_pitch; + wgpu_layout.rowsPerImage = (uint32_t)num_rows; + wgpu_extent.width = (uint32_t)mip_width; + wgpu_extent.height = (uint32_t)mip_height; + wgpu_extent.depthOrArrayLayers = (uint32_t)mip_slices; + const sg_range* mip_data = &data->mip_levels[mip_index]; + wgpuQueueWriteTexture(_sg.wgpu.queue, &wgpu_copy_tex, mip_data->ptr, mip_data->size, &wgpu_layout, &wgpu_extent); + } +} + +_SOKOL_PRIVATE sg_resource_state _sg_wgpu_create_image(_sg_image_t* img, const sg_image_desc* desc) { + SOKOL_ASSERT(img && desc); + const bool injected = (0 != desc->wgpu_texture); + if (injected) { + img->wgpu.tex = (WGPUTexture)desc->wgpu_texture; + wgpuTextureAddRef(img->wgpu.tex); + } else { + _SG_STRUCT(WGPUTextureDescriptor, wgpu_tex_desc); + wgpu_tex_desc.label = _sg_wgpu_stringview(desc->label); + wgpu_tex_desc.usage = WGPUTextureUsage_TextureBinding|WGPUTextureUsage_CopyDst; + if (desc->usage.color_attachment || desc->usage.resolve_attachment || desc->usage.depth_stencil_attachment) { + wgpu_tex_desc.usage |= WGPUTextureUsage_RenderAttachment; + } + if (desc->usage.storage_image) { + wgpu_tex_desc.usage |= WGPUTextureUsage_StorageBinding; + } + wgpu_tex_desc.dimension = _sg_wgpu_texture_dimension(img->cmn.type); + wgpu_tex_desc.size.width = (uint32_t) img->cmn.width; + wgpu_tex_desc.size.height = (uint32_t) img->cmn.height; + wgpu_tex_desc.size.depthOrArrayLayers = (uint32_t) img->cmn.num_slices; + wgpu_tex_desc.format = _sg_wgpu_textureformat(img->cmn.pixel_format); + wgpu_tex_desc.mipLevelCount = (uint32_t) img->cmn.num_mipmaps; + wgpu_tex_desc.sampleCount = (uint32_t) img->cmn.sample_count; + img->wgpu.tex = wgpuDeviceCreateTexture(_sg.wgpu.dev, &wgpu_tex_desc); + if (0 == img->wgpu.tex) { + _SG_ERROR(WGPU_CREATE_TEXTURE_FAILED); + return SG_RESOURCESTATE_FAILED; + } + if (desc->data.mip_levels[0].ptr) { + _sg_wgpu_copy_image_data(img, &desc->data); + } + } + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_wgpu_discard_image(_sg_image_t* img) { + SOKOL_ASSERT(img); + if (img->wgpu.tex) { + wgpuTextureRelease(img->wgpu.tex); + img->wgpu.tex = 0; + } +} + +_SOKOL_PRIVATE sg_resource_state _sg_wgpu_create_sampler(_sg_sampler_t* smp, const sg_sampler_desc* desc) { + SOKOL_ASSERT(smp && desc); + SOKOL_ASSERT(_sg.wgpu.dev); + const bool injected = (0 != desc->wgpu_sampler); + if (injected) { + smp->wgpu.smp = (WGPUSampler) desc->wgpu_sampler; + wgpuSamplerAddRef(smp->wgpu.smp); + } else { + _SG_STRUCT(WGPUSamplerDescriptor, wgpu_desc); + wgpu_desc.label = _sg_wgpu_stringview(desc->label); + wgpu_desc.addressModeU = _sg_wgpu_sampler_address_mode(desc->wrap_u); + wgpu_desc.addressModeV = _sg_wgpu_sampler_address_mode(desc->wrap_v); + wgpu_desc.addressModeW = _sg_wgpu_sampler_address_mode(desc->wrap_w); + wgpu_desc.magFilter = _sg_wgpu_sampler_minmag_filter(desc->mag_filter); + wgpu_desc.minFilter = _sg_wgpu_sampler_minmag_filter(desc->min_filter); + wgpu_desc.mipmapFilter = _sg_wgpu_sampler_mipmap_filter(desc->mipmap_filter); + wgpu_desc.lodMinClamp = desc->min_lod; + wgpu_desc.lodMaxClamp = desc->max_lod; + wgpu_desc.compare = _sg_wgpu_comparefunc(desc->compare); + if (wgpu_desc.compare == WGPUCompareFunction_Never) { + wgpu_desc.compare = WGPUCompareFunction_Undefined; + } + wgpu_desc.maxAnisotropy = (uint16_t)desc->max_anisotropy; + smp->wgpu.smp = wgpuDeviceCreateSampler(_sg.wgpu.dev, &wgpu_desc); + if (0 == smp->wgpu.smp) { + _SG_ERROR(WGPU_CREATE_SAMPLER_FAILED); + return SG_RESOURCESTATE_FAILED; + } + } + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_wgpu_discard_sampler(_sg_sampler_t* smp) { + SOKOL_ASSERT(smp); + _sg_wgpu_bindgroups_cache_invalidate(_SG_WGPU_BINDGROUPSCACHEITEMTYPE_SAMPLER, &smp->slot); + if (smp->wgpu.smp) { + wgpuSamplerRelease(smp->wgpu.smp); + smp->wgpu.smp = 0; + } +} + +_SOKOL_PRIVATE _sg_wgpu_shader_func_t _sg_wgpu_create_shader_func(const sg_shader_function* func, const char* label) { + SOKOL_ASSERT(func); + SOKOL_ASSERT(func->source); + SOKOL_ASSERT(func->entry); + + _SG_STRUCT(_sg_wgpu_shader_func_t, res); + _sg_strcpy(&res.entry, func->entry); + + _SG_STRUCT(WGPUShaderSourceWGSL, wgpu_shdsrc_wgsl); + wgpu_shdsrc_wgsl.chain.sType = WGPUSType_ShaderSourceWGSL; + wgpu_shdsrc_wgsl.code = _sg_wgpu_stringview(func->source); + + _SG_STRUCT(WGPUShaderModuleDescriptor, wgpu_shdmod_desc); + wgpu_shdmod_desc.nextInChain = &wgpu_shdsrc_wgsl.chain; + wgpu_shdmod_desc.label = _sg_wgpu_stringview(label); + + // NOTE: if compilation fails we won't actually find out in this call since + // it always returns a valid module handle, and the GetCompilationInfo() call + // is asynchronous + res.module = wgpuDeviceCreateShaderModule(_sg.wgpu.dev, &wgpu_shdmod_desc); + if (0 == res.module) { + _SG_ERROR(WGPU_CREATE_SHADER_MODULE_FAILED); + } + return res; +} + +_SOKOL_PRIVATE void _sg_wgpu_discard_shader_func(_sg_wgpu_shader_func_t* func) { + if (func->module) { + wgpuShaderModuleRelease(func->module); + func->module = 0; + } +} + +typedef struct { uint8_t sokol_slot, wgpu_slot; } _sg_wgpu_dynoffset_mapping_t; + +_SOKOL_PRIVATE int _sg_wgpu_dynoffset_cmp(const void* a, const void* b) { + const _sg_wgpu_dynoffset_mapping_t* aa = (const _sg_wgpu_dynoffset_mapping_t*)a; + const _sg_wgpu_dynoffset_mapping_t* bb = (const _sg_wgpu_dynoffset_mapping_t*)b; + if (aa->wgpu_slot < bb->wgpu_slot) return -1; + else if (aa->wgpu_slot > bb->wgpu_slot) return 1; + return 0; +} + +// NOTE: this is an out-of-range check for WGSL bindslots that's also active in release mode +_SOKOL_PRIVATE bool _sg_wgpu_ensure_wgsl_bindslot_ranges(const sg_shader_desc* desc) { + SOKOL_ASSERT(desc); + for (size_t i = 0; i < SG_MAX_UNIFORMBLOCK_BINDSLOTS; i++) { + const sg_shader_uniform_block* ub = &desc->uniform_blocks[i]; + if (ub->stage != SG_SHADERSTAGE_NONE) { + if (ub->wgsl_group0_binding_n >= _SG_WGPU_MAX_UB_BINDGROUP_WGSL_SLOTS) { + _SG_ERROR(WGPU_UNIFORMBLOCK_WGSL_GROUP0_BINDING_OUT_OF_RANGE); + return false; + } + } + } + for (size_t i = 0; i < SG_MAX_VIEW_BINDSLOTS; i++) { + const sg_shader_view* view = &desc->views[i]; + if (view->texture.stage != SG_SHADERSTAGE_NONE) { + if (view->texture.wgsl_group1_binding_n >= _SG_WGPU_MAX_VIEW_SMP_BINDGROUP_WGSL_SLOTS) { + _SG_ERROR(WGPU_TEXTURE_WGSL_GROUP1_BINDING_OUT_OF_RANGE); + return false; + } + } + if (view->storage_buffer.stage != SG_SHADERSTAGE_NONE) { + if (view->storage_buffer.wgsl_group1_binding_n >= _SG_WGPU_MAX_VIEW_SMP_BINDGROUP_WGSL_SLOTS) { + _SG_ERROR(WGPU_STORAGEBUFFER_WGSL_GROUP1_BINDING_OUT_OF_RANGE); + return false; + } + } + if (view->storage_image.stage != SG_SHADERSTAGE_NONE) { + if (view->storage_image.wgsl_group1_binding_n >= _SG_WGPU_MAX_VIEW_SMP_BINDGROUP_WGSL_SLOTS) { + _SG_ERROR(WGPU_STORAGEIMAGE_WGSL_GROUP1_BINDING_OUT_OF_RANGE); + return false; + } + } + } + for (size_t i = 0; i < SG_MAX_SAMPLER_BINDSLOTS; i++) { + const sg_shader_sampler* smp = &desc->samplers[i]; + if (smp->stage != SG_SHADERSTAGE_NONE) { + if (smp->wgsl_group1_binding_n >= _SG_WGPU_MAX_VIEW_SMP_BINDGROUP_WGSL_SLOTS) { + _SG_ERROR(WGPU_SAMPLER_WGSL_GROUP1_BINDING_OUT_OF_RANGE); + return false; + } + } + } + return true; +} + +_SOKOL_PRIVATE sg_resource_state _sg_wgpu_create_shader(_sg_shader_t* shd, const sg_shader_desc* desc) { + SOKOL_ASSERT(shd && desc); + SOKOL_ASSERT(shd->wgpu.vertex_func.module == 0); + SOKOL_ASSERT(shd->wgpu.fragment_func.module == 0); + SOKOL_ASSERT(shd->wgpu.compute_func.module == 0); + SOKOL_ASSERT(shd->wgpu.bgl_ub == 0); + SOKOL_ASSERT(shd->wgpu.bg_ub == 0); + SOKOL_ASSERT(shd->wgpu.bgl_view_smp == 0); + + // do a release-mode bounds-check on wgsl bindslots, even though out-of-range + // bindslots can't cause out-of-bounds accesses in the wgpu backend, this + // is done to be consistent with the other backends + if (!_sg_wgpu_ensure_wgsl_bindslot_ranges(desc)) { + return SG_RESOURCESTATE_FAILED; + } + + // build shader modules + bool shd_valid = true; + if (desc->vertex_func.source) { + shd->wgpu.vertex_func = _sg_wgpu_create_shader_func(&desc->vertex_func, desc->label); + shd_valid &= shd->wgpu.vertex_func.module != 0; + } + if (desc->fragment_func.source) { + shd->wgpu.fragment_func = _sg_wgpu_create_shader_func(&desc->fragment_func, desc->label); + shd_valid &= shd->wgpu.fragment_func.module != 0; + } + if (desc->compute_func.source) { + shd->wgpu.compute_func = _sg_wgpu_create_shader_func(&desc->compute_func, desc->label); + shd_valid &= shd->wgpu.compute_func.module != 0; + } + if (!shd_valid) { + _sg_wgpu_discard_shader_func(&shd->wgpu.vertex_func); + _sg_wgpu_discard_shader_func(&shd->wgpu.fragment_func); + _sg_wgpu_discard_shader_func(&shd->wgpu.compute_func); + return SG_RESOURCESTATE_FAILED; + } + + // create bind group layout and bind group for uniform blocks + // NOTE also need to create a mapping of sokol ub bind slots to array indices + // for the dynamic offsets array in the setBindGroup call + SOKOL_ASSERT(_SG_WGPU_MAX_UB_BINDGROUP_ENTRIES <= _SG_WGPU_MAX_VIEW_SMP_BINDGROUP_ENTRIES); + _SG_STRUCT(WGPUBindGroupLayoutEntry, bgl_entries[_SG_WGPU_MAX_VIEW_SMP_BINDGROUP_ENTRIES]); + _SG_STRUCT(WGPUBindGroupLayoutDescriptor, bgl_desc); + _SG_STRUCT(WGPUBindGroupEntry, bg_entries[_SG_WGPU_MAX_VIEW_SMP_BINDGROUP_ENTRIES]); + _SG_STRUCT(WGPUBindGroupDescriptor, bg_desc); + _SG_STRUCT(_sg_wgpu_dynoffset_mapping_t, dynoffset_map[SG_MAX_UNIFORMBLOCK_BINDSLOTS]); + size_t bgl_index = 0; + for (size_t i = 0; i < SG_MAX_UNIFORMBLOCK_BINDSLOTS; i++) { + if (shd->cmn.uniform_blocks[i].stage == SG_SHADERSTAGE_NONE) { + continue; + } + shd->wgpu.ub_grp0_bnd_n[i] = desc->uniform_blocks[i].wgsl_group0_binding_n; + WGPUBindGroupEntry* bg_entry = &bg_entries[bgl_index]; + WGPUBindGroupLayoutEntry* bgl_entry = &bgl_entries[bgl_index]; + bgl_entry->binding = shd->wgpu.ub_grp0_bnd_n[i]; + bgl_entry->visibility = _sg_wgpu_shader_stage(shd->cmn.uniform_blocks[i].stage); + bgl_entry->buffer.type = WGPUBufferBindingType_Uniform; + bgl_entry->buffer.hasDynamicOffset = true; + bg_entry->binding = bgl_entry->binding; + bg_entry->buffer = _sg.wgpu.uniform.buf; + bg_entry->size = _SG_WGPU_MAX_UNIFORM_UPDATE_SIZE; + dynoffset_map[i].sokol_slot = (uint8_t)i; + dynoffset_map[i].wgpu_slot = (uint8_t)bgl_entry->binding; + bgl_index += 1; + } + bgl_desc.entryCount = bgl_index; + bgl_desc.entries = bgl_entries; + shd->wgpu.bgl_ub = wgpuDeviceCreateBindGroupLayout(_sg.wgpu.dev, &bgl_desc); + SOKOL_ASSERT(shd->wgpu.bgl_ub); + bg_desc.layout = shd->wgpu.bgl_ub; + bg_desc.entryCount = bgl_index; + bg_desc.entries = bg_entries; + shd->wgpu.bg_ub = wgpuDeviceCreateBindGroup(_sg.wgpu.dev, &bg_desc); + SOKOL_ASSERT(shd->wgpu.bg_ub); + + // sort the dynoffset_map by wgpu bindings, this is because the + // dynamic offsets of the WebGPU setBindGroup call must be in + // 'binding order', not 'bindgroup entry order' + qsort(dynoffset_map, bgl_index, sizeof(_sg_wgpu_dynoffset_mapping_t), _sg_wgpu_dynoffset_cmp); + shd->wgpu.ub_num_dynoffsets = (uint8_t)bgl_index; + for (uint8_t i = 0; i < bgl_index; i++) { + const uint8_t sokol_slot = dynoffset_map[i].sokol_slot; + shd->wgpu.ub_dynoffsets[sokol_slot] = i; + } + + // create bind group layout for textures, storage buffers/images and samplers + _sg_clear(bgl_entries, sizeof(bgl_entries)); + _sg_clear(&bgl_desc, sizeof(bgl_desc)); + bgl_index = 0; + for (size_t i = 0; i < SG_MAX_VIEW_BINDSLOTS; i++) { + if (shd->cmn.views[i].stage == SG_SHADERSTAGE_NONE) { + continue; + } + WGPUBindGroupLayoutEntry* bgl_entry = &bgl_entries[bgl_index]; + bgl_entry->visibility = _sg_wgpu_shader_stage(shd->cmn.views[i].stage); + if (shd->cmn.views[i].view_type == SG_VIEWTYPE_TEXTURE) { + shd->wgpu.view_grp1_bnd_n[i] = desc->views[i].texture.wgsl_group1_binding_n; + const bool msaa = shd->cmn.views[i].multisampled; + bgl_entry->texture.viewDimension = _sg_wgpu_texture_view_dimension(shd->cmn.views[i].image_type); + bgl_entry->texture.sampleType = _sg_wgpu_texture_sample_type(shd->cmn.views[i].sample_type, msaa); + bgl_entry->texture.multisampled = msaa; + } else if (shd->cmn.views[i].view_type == SG_VIEWTYPE_STORAGEBUFFER) { + shd->wgpu.view_grp1_bnd_n[i] = desc->views[i].storage_buffer.wgsl_group1_binding_n; + if (shd->cmn.views[i].sbuf_readonly) { + bgl_entry->buffer.type = WGPUBufferBindingType_ReadOnlyStorage; + } else { + bgl_entry->buffer.type = WGPUBufferBindingType_Storage; + } + } else if (shd->cmn.views[i].view_type == SG_VIEWTYPE_STORAGEIMAGE) { + shd->wgpu.view_grp1_bnd_n[i] = desc->views[i].storage_image.wgsl_group1_binding_n; + if (shd->cmn.views[i].simg_writeonly) { + bgl_entry->storageTexture.access = WGPUStorageTextureAccess_WriteOnly; + } else { + bgl_entry->storageTexture.access = WGPUStorageTextureAccess_ReadWrite; + } + bgl_entry->storageTexture.format = _sg_wgpu_textureformat(shd->cmn.views[i].access_format); + bgl_entry->texture.viewDimension = _sg_wgpu_texture_view_dimension(shd->cmn.views[i].image_type); + } else { + SOKOL_UNREACHABLE; + } + bgl_entry->binding = shd->wgpu.view_grp1_bnd_n[i]; + bgl_index += 1; + } + for (size_t i = 0; i < SG_MAX_SAMPLER_BINDSLOTS; i++) { + if (shd->cmn.samplers[i].stage == SG_SHADERSTAGE_NONE) { + continue; + } + shd->wgpu.smp_grp1_bnd_n[i] = desc->samplers[i].wgsl_group1_binding_n; + WGPUBindGroupLayoutEntry* bgl_entry = &bgl_entries[bgl_index]; + bgl_entry->binding = shd->wgpu.smp_grp1_bnd_n[i]; + bgl_entry->visibility = _sg_wgpu_shader_stage(shd->cmn.samplers[i].stage); + bgl_entry->sampler.type = _sg_wgpu_sampler_binding_type(shd->cmn.samplers[i].sampler_type); + bgl_index += 1; + } + bgl_desc.entryCount = bgl_index; + bgl_desc.entries = bgl_entries; + shd->wgpu.bgl_view_smp = wgpuDeviceCreateBindGroupLayout(_sg.wgpu.dev, &bgl_desc); + if (shd->wgpu.bgl_view_smp == 0) { + _SG_ERROR(WGPU_SHADER_CREATE_BINDGROUP_LAYOUT_FAILED); + return SG_RESOURCESTATE_FAILED; + } + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_wgpu_discard_shader(_sg_shader_t* shd) { + SOKOL_ASSERT(shd); + _sg_wgpu_discard_shader_func(&shd->wgpu.vertex_func); + _sg_wgpu_discard_shader_func(&shd->wgpu.fragment_func); + _sg_wgpu_discard_shader_func(&shd->wgpu.compute_func); + if (shd->wgpu.bgl_ub) { + wgpuBindGroupLayoutRelease(shd->wgpu.bgl_ub); + shd->wgpu.bgl_ub = 0; + } + if (shd->wgpu.bg_ub) { + wgpuBindGroupRelease(shd->wgpu.bg_ub); + shd->wgpu.bg_ub = 0; + } + if (shd->wgpu.bgl_view_smp) { + wgpuBindGroupLayoutRelease(shd->wgpu.bgl_view_smp); + shd->wgpu.bgl_view_smp = 0; + } +} + +_SOKOL_PRIVATE sg_resource_state _sg_wgpu_create_pipeline(_sg_pipeline_t* pip, const sg_pipeline_desc* desc) { + SOKOL_ASSERT(pip && desc); + + const _sg_shader_t* shd = _sg_shader_ref_ptr(&pip->cmn.shader); + SOKOL_ASSERT(shd->wgpu.bgl_ub); + SOKOL_ASSERT(shd->wgpu.bgl_view_smp); + + pip->wgpu.blend_color.r = (double) desc->blend_color.r; + pip->wgpu.blend_color.g = (double) desc->blend_color.g; + pip->wgpu.blend_color.b = (double) desc->blend_color.b; + pip->wgpu.blend_color.a = (double) desc->blend_color.a; + + // - @group(0) for uniform blocks + // - @group(1) for all image, sampler and storagebuffer resources + size_t num_bgls = 2; + _SG_STRUCT(WGPUBindGroupLayout, wgpu_bgl[_SG_WGPU_MAX_BINDGROUPS]); + wgpu_bgl[_SG_WGPU_UB_BINDGROUP_INDEX ] = shd->wgpu.bgl_ub; + wgpu_bgl[_SG_WGPU_VIEW_SMP_BINDGROUP_INDEX] = shd->wgpu.bgl_view_smp; + _SG_STRUCT(WGPUPipelineLayoutDescriptor, wgpu_pl_desc); + wgpu_pl_desc.bindGroupLayoutCount = num_bgls; + wgpu_pl_desc.bindGroupLayouts = &wgpu_bgl[0]; + const WGPUPipelineLayout wgpu_pip_layout = wgpuDeviceCreatePipelineLayout(_sg.wgpu.dev, &wgpu_pl_desc); + if (0 == wgpu_pip_layout) { + _SG_ERROR(WGPU_CREATE_PIPELINE_LAYOUT_FAILED); + return SG_RESOURCESTATE_FAILED; + } + SOKOL_ASSERT(wgpu_pip_layout); + + if (pip->cmn.is_compute) { + _SG_STRUCT(WGPUComputePipelineDescriptor, wgpu_pip_desc); + wgpu_pip_desc.label = _sg_wgpu_stringview(desc->label); + wgpu_pip_desc.layout = wgpu_pip_layout; + wgpu_pip_desc.compute.module = shd->wgpu.compute_func.module; + wgpu_pip_desc.compute.entryPoint = _sg_wgpu_stringview(shd->wgpu.compute_func.entry.buf); + pip->wgpu.cpip = wgpuDeviceCreateComputePipeline(_sg.wgpu.dev, &wgpu_pip_desc); + wgpuPipelineLayoutRelease(wgpu_pip_layout); + if (0 == pip->wgpu.cpip) { + _SG_ERROR(WGPU_CREATE_COMPUTE_PIPELINE_FAILED); + return SG_RESOURCESTATE_FAILED; + } + } else { + _SG_STRUCT(WGPUVertexBufferLayout, wgpu_vb_layouts[SG_MAX_VERTEXBUFFER_BINDSLOTS]); + _SG_STRUCT(WGPUVertexAttribute, wgpu_vtx_attrs[SG_MAX_VERTEXBUFFER_BINDSLOTS][SG_MAX_VERTEX_ATTRIBUTES]); + int wgpu_vb_num = 0; + for (int vb_idx = 0; vb_idx < SG_MAX_VERTEXBUFFER_BINDSLOTS; vb_idx++, wgpu_vb_num++) { + const sg_vertex_buffer_layout_state* vbl_state = &desc->layout.buffers[vb_idx]; + if (0 == vbl_state->stride) { + break; + } + wgpu_vb_layouts[vb_idx].arrayStride = (uint64_t)vbl_state->stride; + wgpu_vb_layouts[vb_idx].stepMode = _sg_wgpu_stepmode(vbl_state->step_func); + wgpu_vb_layouts[vb_idx].attributes = &wgpu_vtx_attrs[vb_idx][0]; + } + for (int va_idx = 0; va_idx < SG_MAX_VERTEX_ATTRIBUTES; va_idx++) { + const sg_vertex_attr_state* va_state = &desc->layout.attrs[va_idx]; + if (SG_VERTEXFORMAT_INVALID == va_state->format) { + break; + } + const int vb_idx = va_state->buffer_index; + SOKOL_ASSERT(vb_idx < SG_MAX_VERTEXBUFFER_BINDSLOTS); + SOKOL_ASSERT(pip->cmn.vertex_buffer_layout_active[vb_idx]); + const size_t wgpu_attr_idx = wgpu_vb_layouts[vb_idx].attributeCount; + wgpu_vb_layouts[vb_idx].attributeCount += 1; + wgpu_vtx_attrs[vb_idx][wgpu_attr_idx].format = _sg_wgpu_vertexformat(va_state->format); + wgpu_vtx_attrs[vb_idx][wgpu_attr_idx].offset = (uint64_t)va_state->offset; + wgpu_vtx_attrs[vb_idx][wgpu_attr_idx].shaderLocation = (uint32_t)va_idx; + } + + _SG_STRUCT(WGPURenderPipelineDescriptor, wgpu_pip_desc); + _SG_STRUCT(WGPUDepthStencilState, wgpu_ds_state); + _SG_STRUCT(WGPUFragmentState, wgpu_frag_state); + _SG_STRUCT(WGPUColorTargetState, wgpu_ctgt_state[SG_MAX_COLOR_ATTACHMENTS]); + _SG_STRUCT(WGPUBlendState, wgpu_blend_state[SG_MAX_COLOR_ATTACHMENTS]); + wgpu_pip_desc.label = _sg_wgpu_stringview(desc->label); + wgpu_pip_desc.layout = wgpu_pip_layout; + wgpu_pip_desc.vertex.module = shd->wgpu.vertex_func.module; + wgpu_pip_desc.vertex.entryPoint = _sg_wgpu_stringview(shd->wgpu.vertex_func.entry.buf); + wgpu_pip_desc.vertex.bufferCount = (size_t)wgpu_vb_num; + wgpu_pip_desc.vertex.buffers = &wgpu_vb_layouts[0]; + wgpu_pip_desc.primitive.topology = _sg_wgpu_topology(desc->primitive_type); + wgpu_pip_desc.primitive.stripIndexFormat = _sg_wgpu_stripindexformat(desc->primitive_type, desc->index_type); + wgpu_pip_desc.primitive.frontFace = _sg_wgpu_frontface(desc->face_winding); + wgpu_pip_desc.primitive.cullMode = _sg_wgpu_cullmode(desc->cull_mode); + if (SG_PIXELFORMAT_NONE != desc->depth.pixel_format) { + wgpu_ds_state.format = _sg_wgpu_textureformat(desc->depth.pixel_format); + wgpu_ds_state.depthWriteEnabled = _sg_wgpu_optional_bool(desc->depth.write_enabled); + wgpu_ds_state.depthCompare = _sg_wgpu_comparefunc(desc->depth.compare); + wgpu_ds_state.stencilFront.compare = _sg_wgpu_comparefunc(desc->stencil.front.compare); + wgpu_ds_state.stencilFront.failOp = _sg_wgpu_stencilop(desc->stencil.front.fail_op); + wgpu_ds_state.stencilFront.depthFailOp = _sg_wgpu_stencilop(desc->stencil.front.depth_fail_op); + wgpu_ds_state.stencilFront.passOp = _sg_wgpu_stencilop(desc->stencil.front.pass_op); + wgpu_ds_state.stencilBack.compare = _sg_wgpu_comparefunc(desc->stencil.back.compare); + wgpu_ds_state.stencilBack.failOp = _sg_wgpu_stencilop(desc->stencil.back.fail_op); + wgpu_ds_state.stencilBack.depthFailOp = _sg_wgpu_stencilop(desc->stencil.back.depth_fail_op); + wgpu_ds_state.stencilBack.passOp = _sg_wgpu_stencilop(desc->stencil.back.pass_op); + wgpu_ds_state.stencilReadMask = desc->stencil.read_mask; + wgpu_ds_state.stencilWriteMask = desc->stencil.write_mask; + wgpu_ds_state.depthBias = (int32_t)desc->depth.bias; + wgpu_ds_state.depthBiasSlopeScale = desc->depth.bias_slope_scale; + wgpu_ds_state.depthBiasClamp = desc->depth.bias_clamp; + wgpu_pip_desc.depthStencil = &wgpu_ds_state; + } + wgpu_pip_desc.multisample.count = (uint32_t)desc->sample_count; + wgpu_pip_desc.multisample.mask = 0xFFFFFFFF; + wgpu_pip_desc.multisample.alphaToCoverageEnabled = desc->alpha_to_coverage_enabled; + if (desc->color_count > 0) { + wgpu_frag_state.module = shd->wgpu.fragment_func.module; + wgpu_frag_state.entryPoint = _sg_wgpu_stringview(shd->wgpu.fragment_func.entry.buf); + wgpu_frag_state.targetCount = (size_t)desc->color_count; + wgpu_frag_state.targets = &wgpu_ctgt_state[0]; + for (int i = 0; i < desc->color_count; i++) { + SOKOL_ASSERT(i < SG_MAX_COLOR_ATTACHMENTS); + wgpu_ctgt_state[i].format = _sg_wgpu_textureformat(desc->colors[i].pixel_format); + wgpu_ctgt_state[i].writeMask = _sg_wgpu_colorwritemask(desc->colors[i].write_mask); + if (desc->colors[i].blend.enabled) { + wgpu_ctgt_state[i].blend = &wgpu_blend_state[i]; + wgpu_blend_state[i].color.operation = _sg_wgpu_blendop(desc->colors[i].blend.op_rgb); + wgpu_blend_state[i].color.srcFactor = _sg_wgpu_blendfactor(desc->colors[i].blend.src_factor_rgb); + wgpu_blend_state[i].color.dstFactor = _sg_wgpu_blendfactor(desc->colors[i].blend.dst_factor_rgb); + wgpu_blend_state[i].alpha.operation = _sg_wgpu_blendop(desc->colors[i].blend.op_alpha); + wgpu_blend_state[i].alpha.srcFactor = _sg_wgpu_blendfactor(desc->colors[i].blend.src_factor_alpha); + wgpu_blend_state[i].alpha.dstFactor = _sg_wgpu_blendfactor(desc->colors[i].blend.dst_factor_alpha); + } + } + wgpu_pip_desc.fragment = &wgpu_frag_state; + } + pip->wgpu.rpip = wgpuDeviceCreateRenderPipeline(_sg.wgpu.dev, &wgpu_pip_desc); + wgpuPipelineLayoutRelease(wgpu_pip_layout); + if (0 == pip->wgpu.rpip) { + _SG_ERROR(WGPU_CREATE_RENDER_PIPELINE_FAILED); + return SG_RESOURCESTATE_FAILED; + } + } + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_wgpu_discard_pipeline(_sg_pipeline_t* pip) { + SOKOL_ASSERT(pip); + _sg_wgpu_bindgroups_cache_invalidate(_SG_WGPU_BINDGROUPSCACHEITEMTYPE_PIPELINE, &pip->slot); + if (pip->wgpu.rpip) { + wgpuRenderPipelineRelease(pip->wgpu.rpip); + pip->wgpu.rpip = 0; + } + if (pip->wgpu.cpip) { + wgpuComputePipelineRelease(pip->wgpu.cpip); + pip->wgpu.cpip = 0; + } +} + +_SOKOL_PRIVATE sg_resource_state _sg_wgpu_create_view(_sg_view_t* view, const sg_view_desc* desc) { + SOKOL_ASSERT(view && desc); + if (view->cmn.type != SG_VIEWTYPE_STORAGEBUFFER) { + const _sg_image_t* img = _sg_image_ref_ptr(&view->cmn.img.ref); + SOKOL_ASSERT(img->wgpu.tex); + SOKOL_ASSERT(view->cmn.img.mip_level_count >= 1); + SOKOL_ASSERT(view->cmn.img.slice_count >= 1); + _SG_STRUCT(WGPUTextureViewDescriptor, wgpu_texview_desc); + wgpu_texview_desc.label = _sg_wgpu_stringview(desc->label); + wgpu_texview_desc.baseMipLevel = (uint32_t)view->cmn.img.mip_level; + wgpu_texview_desc.mipLevelCount = (uint32_t)view->cmn.img.mip_level_count; + wgpu_texview_desc.baseArrayLayer = (uint32_t)view->cmn.img.slice; + wgpu_texview_desc.arrayLayerCount = (uint32_t)view->cmn.img.slice_count; + if (view->cmn.type == SG_VIEWTYPE_TEXTURE) { + wgpu_texview_desc.dimension = _sg_wgpu_texture_view_dimension(img->cmn.type); + } else { + wgpu_texview_desc.dimension = _sg_wgpu_attachment_view_dimension(img->cmn.type); + } + if (view->cmn.type == SG_VIEWTYPE_DEPTHSTENCILATTACHMENT) { + wgpu_texview_desc.aspect = WGPUTextureAspect_All; + } else if (_sg_is_depth_or_depth_stencil_format(img->cmn.pixel_format)) { + wgpu_texview_desc.aspect = WGPUTextureAspect_DepthOnly; + } else { + wgpu_texview_desc.aspect = WGPUTextureAspect_All; + } + view->wgpu.view = wgpuTextureCreateView(img->wgpu.tex, &wgpu_texview_desc); + if (0 == view->wgpu.view) { + _SG_ERROR(WGPU_CREATE_TEXTURE_VIEW_FAILED); + return SG_RESOURCESTATE_FAILED; + } + } + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_wgpu_discard_view(_sg_view_t* view) { + SOKOL_ASSERT(view); + _sg_wgpu_bindgroups_cache_invalidate(_SG_WGPU_BINDGROUPSCACHEITEMTYPE_VIEW, &view->slot); + if (view->wgpu.view) { + wgpuTextureViewRelease(view->wgpu.view); + view->wgpu.view = 0; + } +} + +_SOKOL_PRIVATE void _sg_wgpu_init_color_att(WGPURenderPassColorAttachment* wgpu_att, const sg_color_attachment_action* action, WGPUTextureView color_view, WGPUTextureView resolve_view) { + wgpu_att->depthSlice = WGPU_DEPTH_SLICE_UNDEFINED; + wgpu_att->view = color_view; + wgpu_att->resolveTarget = resolve_view; + wgpu_att->loadOp = _sg_wgpu_load_op(color_view, action->load_action); + wgpu_att->storeOp = _sg_wgpu_store_op(color_view, action->store_action); + wgpu_att->clearValue.r = action->clear_value.r; + wgpu_att->clearValue.g = action->clear_value.g; + wgpu_att->clearValue.b = action->clear_value.b; + wgpu_att->clearValue.a = action->clear_value.a; +} + +_SOKOL_PRIVATE void _sg_wgpu_init_ds_att(WGPURenderPassDepthStencilAttachment* wgpu_att, const sg_pass_action* action, sg_pixel_format fmt, WGPUTextureView view) { + wgpu_att->view = view; + wgpu_att->depthLoadOp = _sg_wgpu_load_op(view, action->depth.load_action); + wgpu_att->depthStoreOp = _sg_wgpu_store_op(view, action->depth.store_action); + wgpu_att->depthClearValue = action->depth.clear_value; + wgpu_att->depthReadOnly = false; + if (_sg_is_depth_stencil_format(fmt)) { + wgpu_att->stencilLoadOp = _sg_wgpu_load_op(view, action->stencil.load_action); + wgpu_att->stencilStoreOp = _sg_wgpu_store_op(view, action->stencil.store_action); + } else { + wgpu_att->stencilLoadOp = WGPULoadOp_Undefined; + wgpu_att->stencilStoreOp = WGPUStoreOp_Undefined; + } + wgpu_att->stencilClearValue = action->stencil.clear_value; + wgpu_att->stencilReadOnly = false; +} + +_SOKOL_PRIVATE void _sg_wgpu_begin_compute_pass(const sg_pass* pass) { + _SG_STRUCT(WGPUComputePassDescriptor, wgpu_pass_desc); + wgpu_pass_desc.label = _sg_wgpu_stringview(pass->label); + _sg.wgpu.cpass_enc = wgpuCommandEncoderBeginComputePass(_sg.wgpu.cmd_enc, &wgpu_pass_desc); + SOKOL_ASSERT(_sg.wgpu.cpass_enc); + // clear initial bindings + wgpuComputePassEncoderSetBindGroup(_sg.wgpu.cpass_enc, _SG_WGPU_UB_BINDGROUP_INDEX, 0, 0, 0); + wgpuComputePassEncoderSetBindGroup(_sg.wgpu.cpass_enc, _SG_WGPU_VIEW_SMP_BINDGROUP_INDEX, 0, 0, 0); + _sg_stats_inc(wgpu.bindings.num_set_bindgroup); +} + +_SOKOL_PRIVATE void _sg_wgpu_begin_render_pass(const sg_pass* pass, const _sg_attachments_ptrs_t* atts) { + const sg_swapchain* swapchain = &pass->swapchain; + const sg_pass_action* action = &pass->action; + + _SG_STRUCT(WGPURenderPassDescriptor, wgpu_pass_desc); + _SG_STRUCT(WGPURenderPassColorAttachment, wgpu_color_att[SG_MAX_COLOR_ATTACHMENTS]); + _SG_STRUCT(WGPURenderPassDepthStencilAttachment, wgpu_ds_att); + wgpu_pass_desc.label = _sg_wgpu_stringview(pass->label); + if (!atts->empty) { + SOKOL_ASSERT(atts->num_color_views <= SG_MAX_COLOR_ATTACHMENTS); + for (int i = 0; i < atts->num_color_views; i++) { + SOKOL_ASSERT(atts->color_views[i]); + WGPUTextureView wgpu_color_view = atts->color_views[i]->wgpu.view; + WGPUTextureView wgpu_resolve_view = 0; + if (atts->resolve_views[i]) { + wgpu_resolve_view = atts->resolve_views[i]->wgpu.view; + } + _sg_wgpu_init_color_att(&wgpu_color_att[i], &action->colors[i], wgpu_color_view, wgpu_resolve_view); + } + wgpu_pass_desc.colorAttachmentCount = (size_t)atts->num_color_views; + wgpu_pass_desc.colorAttachments = &wgpu_color_att[0]; + if (atts->ds_view) { + const _sg_image_t* img = _sg_image_ref_ptr(&atts->ds_view->cmn.img.ref); + WGPUTextureView wgpu_ds_view = atts->ds_view->wgpu.view; + SOKOL_ASSERT(wgpu_ds_view); + _sg_wgpu_init_ds_att(&wgpu_ds_att, action, img->cmn.pixel_format, wgpu_ds_view); + wgpu_pass_desc.depthStencilAttachment = &wgpu_ds_att; + } + } else { + WGPUTextureView wgpu_color_view = (WGPUTextureView) swapchain->wgpu.render_view; + WGPUTextureView wgpu_resolve_view = (WGPUTextureView) swapchain->wgpu.resolve_view; + WGPUTextureView wgpu_depth_stencil_view = (WGPUTextureView) swapchain->wgpu.depth_stencil_view; + _sg_wgpu_init_color_att(&wgpu_color_att[0], &action->colors[0], wgpu_color_view, wgpu_resolve_view); + wgpu_pass_desc.colorAttachmentCount = 1; + wgpu_pass_desc.colorAttachments = &wgpu_color_att[0]; + if (wgpu_depth_stencil_view) { + SOKOL_ASSERT(swapchain->depth_format > SG_PIXELFORMAT_NONE); + _sg_wgpu_init_ds_att(&wgpu_ds_att, action, swapchain->depth_format, wgpu_depth_stencil_view); + wgpu_pass_desc.depthStencilAttachment = &wgpu_ds_att; + } + } + _sg.wgpu.rpass_enc = wgpuCommandEncoderBeginRenderPass(_sg.wgpu.cmd_enc, &wgpu_pass_desc); + SOKOL_ASSERT(_sg.wgpu.rpass_enc); + + wgpuRenderPassEncoderSetBindGroup(_sg.wgpu.rpass_enc, _SG_WGPU_UB_BINDGROUP_INDEX, 0, 0, 0); + wgpuRenderPassEncoderSetBindGroup(_sg.wgpu.rpass_enc, _SG_WGPU_VIEW_SMP_BINDGROUP_INDEX, 0, 0, 0); + _sg_stats_inc(wgpu.bindings.num_set_bindgroup); +} + +_SOKOL_PRIVATE void _sg_wgpu_begin_pass(const sg_pass* pass, const _sg_attachments_ptrs_t* atts) { + SOKOL_ASSERT(pass && atts); + SOKOL_ASSERT(_sg.wgpu.dev); + SOKOL_ASSERT(0 == _sg.wgpu.rpass_enc); + SOKOL_ASSERT(0 == _sg.wgpu.cpass_enc); + + // first pass in the frame? create command encoder + if (0 == _sg.wgpu.cmd_enc) { + _SG_STRUCT(WGPUCommandEncoderDescriptor, cmd_enc_desc); + _sg.wgpu.cmd_enc = wgpuDeviceCreateCommandEncoder(_sg.wgpu.dev, &cmd_enc_desc); + SOKOL_ASSERT(_sg.wgpu.cmd_enc); + } + + _sg_wgpu_bindings_cache_clear(); + if (pass->compute) { + _sg_wgpu_begin_compute_pass(pass); + } else { + _sg_wgpu_begin_render_pass(pass, atts); + } +} + +_SOKOL_PRIVATE void _sg_wgpu_end_pass(const _sg_attachments_ptrs_t* atts) { + _SOKOL_UNUSED(atts); + if (_sg.wgpu.rpass_enc) { + wgpuRenderPassEncoderEnd(_sg.wgpu.rpass_enc); + wgpuRenderPassEncoderRelease(_sg.wgpu.rpass_enc); + _sg.wgpu.rpass_enc = 0; + } + if (_sg.wgpu.cpass_enc) { + wgpuComputePassEncoderEnd(_sg.wgpu.cpass_enc); + wgpuComputePassEncoderRelease(_sg.wgpu.cpass_enc); + _sg.wgpu.cpass_enc = 0; + } +} + +_SOKOL_PRIVATE void _sg_wgpu_commit(void) { + if (!_sg.wgpu.cmd_enc) { + // no valid pass in this frame + return; + } + _sg_wgpu_uniform_system_on_commit(); + _SG_STRUCT(WGPUCommandBufferDescriptor, cmd_buf_desc); + WGPUCommandBuffer wgpu_cmd_buf = wgpuCommandEncoderFinish(_sg.wgpu.cmd_enc, &cmd_buf_desc); + SOKOL_ASSERT(wgpu_cmd_buf); + wgpuCommandEncoderRelease(_sg.wgpu.cmd_enc); + _sg.wgpu.cmd_enc = 0; + wgpuQueueSubmit(_sg.wgpu.queue, 1, &wgpu_cmd_buf); + wgpuCommandBufferRelease(wgpu_cmd_buf); +} + +_SOKOL_PRIVATE void _sg_wgpu_apply_viewport(int x, int y, int w, int h, bool origin_top_left) { + SOKOL_ASSERT(_sg.wgpu.rpass_enc); + float xf = (float) x; + float yf = (float) (origin_top_left ? y : (_sg.cur_pass.dim.height - (y + h))); + float wf = (float) w; + float hf = (float) h; + wgpuRenderPassEncoderSetViewport(_sg.wgpu.rpass_enc, xf, yf, wf, hf, 0.0f, 1.0f); +} + +_SOKOL_PRIVATE void _sg_wgpu_apply_scissor_rect(int x, int y, int w, int h, bool origin_top_left) { + SOKOL_ASSERT(_sg.wgpu.rpass_enc); + const _sg_recti_t clip = _sg_clipi(x, y, w, h, _sg.cur_pass.dim.width, _sg.cur_pass.dim.height); + uint32_t sx = (uint32_t) clip.x; + uint32_t sy = (uint32_t) (origin_top_left ? clip.y : (_sg.cur_pass.dim.height - (clip.y + clip.h))); + uint32_t sw = (uint32_t) clip.w; + uint32_t sh = (uint32_t) clip.h; + wgpuRenderPassEncoderSetScissorRect(_sg.wgpu.rpass_enc, sx, sy, sw, sh); +} + +_SOKOL_PRIVATE void _sg_wgpu_apply_pipeline(_sg_pipeline_t* pip) { + SOKOL_ASSERT(pip); + _sg_wgpu_uniform_system_on_apply_pipeline(); + if (pip->cmn.is_compute) { + SOKOL_ASSERT(_sg.cur_pass.is_compute); + SOKOL_ASSERT(pip->wgpu.cpip); + SOKOL_ASSERT(_sg.wgpu.cpass_enc); + wgpuComputePassEncoderSetPipeline(_sg.wgpu.cpass_enc, pip->wgpu.cpip); + } else { + SOKOL_ASSERT(!_sg.cur_pass.is_compute); + SOKOL_ASSERT(pip->wgpu.rpip); + SOKOL_ASSERT(_sg.wgpu.rpass_enc); + wgpuRenderPassEncoderSetPipeline(_sg.wgpu.rpass_enc, pip->wgpu.rpip); + wgpuRenderPassEncoderSetBlendConstant(_sg.wgpu.rpass_enc, &pip->wgpu.blend_color); + wgpuRenderPassEncoderSetStencilReference(_sg.wgpu.rpass_enc, pip->cmn.stencil.ref); + } +} + +_SOKOL_PRIVATE bool _sg_wgpu_apply_bindings(_sg_bindings_ptrs_t* bnd) { + SOKOL_ASSERT(bnd); + bool retval = true; + if (!_sg.cur_pass.is_compute) { + retval &= _sg_wgpu_apply_index_buffer(bnd); + retval &= _sg_wgpu_apply_vertex_buffers(bnd); + } + retval &= _sg_wgpu_apply_bindings_bindgroup(bnd); + return retval; +} + +_SOKOL_PRIVATE void _sg_wgpu_apply_uniforms(int ub_slot, const sg_range* data) { + const uint32_t alignment = _sg.wgpu.limits.minUniformBufferOffsetAlignment; + SOKOL_ASSERT(_sg.wgpu.uniform.staging); + SOKOL_ASSERT((ub_slot >= 0) && (ub_slot < SG_MAX_UNIFORMBLOCK_BINDSLOTS)); + SOKOL_ASSERT((_sg.wgpu.uniform.offset + data->size) <= _sg.wgpu.uniform.num_bytes); + SOKOL_ASSERT((_sg.wgpu.uniform.offset & (alignment - 1)) == 0); + SOKOL_ASSERT(data->size <= _SG_WGPU_MAX_UNIFORM_UPDATE_SIZE); + + _sg_stats_inc(wgpu.uniforms.num_set_bindgroup); + memcpy(_sg.wgpu.uniform.staging + _sg.wgpu.uniform.offset, data->ptr, data->size); + _sg.wgpu.uniform.bind_offsets[ub_slot] = _sg.wgpu.uniform.offset; + _sg.wgpu.uniform.offset = _sg_roundup_u32(_sg.wgpu.uniform.offset + (uint32_t)data->size, alignment); + _sg.wgpu.uniform.dirty = true; +} + +_SOKOL_PRIVATE void _sg_wgpu_draw(int base_element, int num_elements, int num_instances, int base_vertex, int base_instance) { + SOKOL_ASSERT(_sg.wgpu.rpass_enc); + if (_sg.wgpu.uniform.dirty) { + _sg_wgpu_uniform_system_set_bindgroup(); + } + if (_sg.use_indexed_draw) { + wgpuRenderPassEncoderDrawIndexed(_sg.wgpu.rpass_enc, + (uint32_t)num_elements, + (uint32_t)num_instances, + (uint32_t)base_element, + base_vertex, + (uint32_t)base_instance); + } else { + wgpuRenderPassEncoderDraw(_sg.wgpu.rpass_enc, + (uint32_t)num_elements, + (uint32_t)num_instances, + (uint32_t)base_element, + (uint32_t)base_instance); + } +} + +_SOKOL_PRIVATE void _sg_wgpu_dispatch(int num_groups_x, int num_groups_y, int num_groups_z) { + SOKOL_ASSERT(_sg.wgpu.cpass_enc); + if (_sg.wgpu.uniform.dirty) { + _sg_wgpu_uniform_system_set_bindgroup(); + } + wgpuComputePassEncoderDispatchWorkgroups(_sg.wgpu.cpass_enc, + (uint32_t)num_groups_x, + (uint32_t)num_groups_y, + (uint32_t)num_groups_z); +} + +_SOKOL_PRIVATE void _sg_wgpu_update_buffer(_sg_buffer_t* buf, const sg_range* data) { + SOKOL_ASSERT(buf && data && data->ptr && (data->size > 0)); + _sg_wgpu_copy_buffer_data(buf, 0, data); +} + +_SOKOL_PRIVATE void _sg_wgpu_append_buffer(_sg_buffer_t* buf, const sg_range* data, bool new_frame) { + SOKOL_ASSERT(buf && data && data->ptr && (data->size > 0)); + _SOKOL_UNUSED(new_frame); + _sg_wgpu_copy_buffer_data(buf, (uint64_t)buf->cmn.append_pos, data); +} + +_SOKOL_PRIVATE void _sg_wgpu_update_image(_sg_image_t* img, const sg_image_data* data) { + SOKOL_ASSERT(img && data); + _sg_wgpu_copy_image_data(img, data); +} + +// ██ ██ ██ ██ ██ ██ ██ █████ ███ ██ ██████ █████ ██████ ██ ██ ███████ ███ ██ ██████ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ +// ██ ██ ██ ██ ██ █████ ███████ ██ ██ ██ ██████ ███████ ██ █████ █████ ██ ██ ██ ██ ██ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ████ ██████ ███████ ██ ██ ██ ██ ██ ████ ██████ ██ ██ ██████ ██ ██ ███████ ██ ████ ██████ +// +// >>vulkan +// >>vk +#elif defined(SOKOL_VULKAN) + +_SOKOL_PRIVATE void _sg_vk_set_object_label(VkObjectType obj_type, uint64_t obj_handle, const char* label) { + #if defined(SOKOL_DEBUG) + SOKOL_ASSERT(_sg.vk.dev); + SOKOL_ASSERT(_sg.vk.ext.set_debug_utils_object_name_ext); + SOKOL_ASSERT(obj_handle != 0); + if (label) { + _SG_STRUCT(VkDebugUtilsObjectNameInfoEXT, name_info); + name_info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT; + name_info.objectType = obj_type; + name_info.objectHandle = obj_handle, + name_info.pObjectName = label; + VkResult res = _sg.vk.ext.set_debug_utils_object_name_ext(_sg.vk.dev, &name_info); + SOKOL_ASSERT(res == VK_SUCCESS); + } + #else + _SOKOL_UNUSED(obj_type); + _SOKOL_UNUSED(obj_handle); + _SOKOL_UNUSED(label); + #endif +} + +_SOKOL_PRIVATE bool _sg_vk_is_read_access(_sg_vk_access_t access) { + _sg_vk_access_t read_bits = + _SG_VK_ACCESS_VERTEXBUFFER | + _SG_VK_ACCESS_INDEXBUFFER | + _SG_VK_ACCESS_STORAGEBUFFER_RO | + _SG_VK_ACCESS_TEXTURE | + _SG_VK_ACCESS_PRESENT; + return 0 == (access & ~read_bits); +} + +_SOKOL_PRIVATE VkPipelineStageFlags2 _sg_vk_stage_mask(_sg_vk_access_t access, bool is_dst_access) { + access &= ~_SG_VK_ACCESS_DISCARD; + if (is_dst_access) { + SOKOL_ASSERT(access != _SG_VK_ACCESS_NONE); + } + VkPipelineStageFlags2 f = 0; + if (access == _SG_VK_ACCESS_NONE) { + return VK_PIPELINE_STAGE_2_NONE; + } + if (access & _SG_VK_ACCESS_PRESENT) { + return VK_PIPELINE_STAGE_2_NONE; + } + if (access & _SG_VK_ACCESS_STAGING) { + f |= VK_PIPELINE_STAGE_2_COPY_BIT; + } + if (access & _SG_VK_ACCESS_VERTEXBUFFER) { + f |= VK_PIPELINE_STAGE_2_VERTEX_ATTRIBUTE_INPUT_BIT; + } + if (access & _SG_VK_ACCESS_INDEXBUFFER) { + f |= VK_PIPELINE_STAGE_2_INDEX_INPUT_BIT; + } + if (access & (_SG_VK_ACCESS_STORAGEBUFFER_RO|_SG_VK_ACCESS_TEXTURE)) { + f |= VK_PIPELINE_STAGE_2_VERTEX_SHADER_BIT | + VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT | + VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT; + } + if (access & _SG_VK_ACCESS_STORAGEBUFFER_RW) { + f |= VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT; + } + if (access & _SG_VK_ACCESS_STORAGEIMAGE) { + f |= VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT; + } + if (access & _SG_VK_ACCESS_COLOR_ATTACHMENT) { + f |= VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT; + } + if (access & _SG_VK_ACCESS_RESOLVE_ATTACHMENT) { + f |= VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT; + } + if (access & (_SG_VK_ACCESS_DEPTH_ATTACHMENT|_SG_VK_ACCESS_STENCIL_ATTACHMENT)) { + f |= VK_PIPELINE_STAGE_2_EARLY_FRAGMENT_TESTS_BIT|VK_PIPELINE_STAGE_2_LATE_FRAGMENT_TESTS_BIT; + } + SOKOL_ASSERT(f != 0); + return f; +} + +// return pipeline stages on 'before' side of a barrier +_SOKOL_PRIVATE VkPipelineStageFlags2 _sg_vk_src_stage_mask(_sg_vk_access_t access) { + return _sg_vk_stage_mask(access, false); +} + +// return pipeline stage on 'after side' of a barrier +_SOKOL_PRIVATE VkPipelineStageFlags2 _sg_vk_dst_stage_mask(_sg_vk_access_t access) { + return _sg_vk_stage_mask(access, true); +} + +_SOKOL_PRIVATE VkAccessFlags2 _sg_vk_access_mask(_sg_vk_access_t access, bool is_dst_access) { + access &= ~_SG_VK_ACCESS_DISCARD; + if (access == _SG_VK_ACCESS_NONE) { + return VK_ACCESS_2_NONE; + } + if (access & _SG_VK_ACCESS_PRESENT) { + return VK_ACCESS_2_NONE; + } + VkAccessFlags2 f = VK_ACCESS_2_NONE; + if (is_dst_access) { + // NOTE: read bits don't make sense for src-mask + if (access & _SG_VK_ACCESS_VERTEXBUFFER) { + f |= VK_ACCESS_2_VERTEX_ATTRIBUTE_READ_BIT; + } + if (access & _SG_VK_ACCESS_INDEXBUFFER) { + f |= VK_ACCESS_2_INDEX_READ_BIT; + } + if (access & _SG_VK_ACCESS_STORAGEBUFFER_RO) { + f |= VK_ACCESS_2_SHADER_STORAGE_READ_BIT; + } + if (access & _SG_VK_ACCESS_TEXTURE) { + f |= VK_ACCESS_2_SHADER_SAMPLED_READ_BIT; + } + } + if (access & _SG_VK_ACCESS_STAGING) { + f |= VK_ACCESS_2_TRANSFER_WRITE_BIT; + } + if (access & _SG_VK_ACCESS_STORAGEBUFFER_RW) { + f |= VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT | VK_ACCESS_2_SHADER_STORAGE_READ_BIT; + } + if (access & _SG_VK_ACCESS_STORAGEIMAGE) { + f |= VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT | VK_ACCESS_2_SHADER_STORAGE_READ_BIT; + } + if (access & _SG_VK_ACCESS_COLOR_ATTACHMENT) { + f |= VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT; + } + if (access & _SG_VK_ACCESS_RESOLVE_ATTACHMENT) { + f |= VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT; + } + if (access & (_SG_VK_ACCESS_DEPTH_ATTACHMENT | _SG_VK_ACCESS_STENCIL_ATTACHMENT)) { + f |= VK_ACCESS_2_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; + if (is_dst_access) { + f |= VK_ACCESS_2_DEPTH_STENCIL_ATTACHMENT_READ_BIT; + } + } + return f; +} + +_SOKOL_PRIVATE VkAccessFlags2 _sg_vk_src_access_mask(_sg_vk_access_t access) { + return _sg_vk_access_mask(access, false); +} + +_SOKOL_PRIVATE VkAccessFlags2 _sg_vk_dst_access_mask(_sg_vk_access_t access) { + return _sg_vk_access_mask(access, true); +} + +_SOKOL_PRIVATE VkImageLayout _sg_vk_image_layout(_sg_vk_access_t access) { + // NOTE: "image layout transitions with VK_IMAGE_LAYOUT_UNDEFINED allow + // the implementation to discard the image subresource range" + if (access & _SG_VK_ACCESS_DISCARD) { + return VK_IMAGE_LAYOUT_UNDEFINED; + } + switch (access) { + case _SG_VK_ACCESS_NONE: + return VK_IMAGE_LAYOUT_UNDEFINED; + case _SG_VK_ACCESS_STAGING: + return VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; + case _SG_VK_ACCESS_TEXTURE: + return VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + case _SG_VK_ACCESS_STORAGEIMAGE: + return VK_IMAGE_LAYOUT_GENERAL; + case _SG_VK_ACCESS_COLOR_ATTACHMENT: + case _SG_VK_ACCESS_RESOLVE_ATTACHMENT: + case _SG_VK_ACCESS_DEPTH_ATTACHMENT: + case _SG_VK_ACCESS_DEPTH_ATTACHMENT|_SG_VK_ACCESS_STENCIL_ATTACHMENT: + return VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL; + case _SG_VK_ACCESS_PRESENT: + return VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; + default: + SOKOL_UNREACHABLE; + return VK_IMAGE_LAYOUT_UNDEFINED; + } +} + +_SOKOL_PRIVATE void _sg_vk_swapchain_beginpass_barrier(VkCommandBuffer cmd_buf, VkImage vkimg, _sg_vk_access_t pass_access) { + SOKOL_ASSERT(cmd_buf); + _SG_STRUCT(VkImageMemoryBarrier2, barrier); + barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2; + barrier.srcStageMask = _sg_vk_src_stage_mask(pass_access); + barrier.srcAccessMask = _sg_vk_src_access_mask(pass_access); + barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; + barrier.dstStageMask = _sg_vk_dst_stage_mask(pass_access); + barrier.dstAccessMask = _sg_vk_dst_access_mask(pass_access); + barrier.newLayout = VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL; + barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + barrier.image = vkimg; + if (0 != (pass_access & (_SG_VK_ACCESS_DEPTH_ATTACHMENT|_SG_VK_ACCESS_STENCIL_ATTACHMENT))) { + barrier.subresourceRange.aspectMask |= VK_IMAGE_ASPECT_DEPTH_BIT; + if (0 != (pass_access & _SG_VK_ACCESS_STENCIL_ATTACHMENT)) { + barrier.subresourceRange.aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT; + } + } else { + barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + } + barrier.subresourceRange.levelCount = 1; + barrier.subresourceRange.layerCount = 1; + _SG_STRUCT(VkDependencyInfo, dep_info); + dep_info.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO; + dep_info.imageMemoryBarrierCount = 1; + dep_info.pImageMemoryBarriers = &barrier; + vkCmdPipelineBarrier2(cmd_buf, &dep_info); + _sg_stats_inc(vk.num_cmd_pipeline_barrier); +} + +_SOKOL_PRIVATE void _sg_vk_swapchain_endpass_barrier(VkCommandBuffer cmd_buf, VkImage vkimg, _sg_vk_access_t pass_access, bool present) { + SOKOL_ASSERT(cmd_buf); + _SG_STRUCT(VkImageMemoryBarrier2, barrier); + barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2; + barrier.srcStageMask = _sg_vk_src_stage_mask(pass_access); + barrier.srcAccessMask = _sg_vk_src_access_mask(pass_access); + barrier.oldLayout = VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL; + barrier.dstStageMask = VK_PIPELINE_STAGE_2_NONE; + barrier.dstAccessMask = VK_ACCESS_2_NONE; + if (present) { + barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; + } else { + barrier.newLayout = VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL; + } + barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + barrier.image = vkimg; + if (0 != (pass_access & (_SG_VK_ACCESS_DEPTH_ATTACHMENT|_SG_VK_ACCESS_STENCIL_ATTACHMENT))) { + barrier.subresourceRange.aspectMask |= VK_IMAGE_ASPECT_DEPTH_BIT; + if (0 != (pass_access & _SG_VK_ACCESS_STENCIL_ATTACHMENT)) { + barrier.subresourceRange.aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT; + } + } else { + barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + } + barrier.subresourceRange.levelCount = 1; + barrier.subresourceRange.layerCount = 1; + _SG_STRUCT(VkDependencyInfo, dep_info); + dep_info.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO; + dep_info.imageMemoryBarrierCount = 1; + dep_info.pImageMemoryBarriers = &barrier; + vkCmdPipelineBarrier2(cmd_buf, &dep_info); + _sg_stats_inc(vk.num_cmd_pipeline_barrier); +} + +_SOKOL_PRIVATE void _sg_vk_image_barrier(VkCommandBuffer cmd_buf, _sg_image_t* img, _sg_vk_access_t new_access) { + SOKOL_ASSERT(cmd_buf && img && img->vk.img); + if (_sg_vk_is_read_access(img->vk.cur_access) && _sg_vk_is_read_access(new_access)) { + return; + } + _SG_STRUCT(VkImageMemoryBarrier2, barrier); + barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2; + barrier.srcStageMask = _sg_vk_src_stage_mask(img->vk.cur_access); + barrier.srcAccessMask = _sg_vk_src_access_mask(img->vk.cur_access); + barrier.oldLayout = _sg_vk_image_layout(img->vk.cur_access); + barrier.dstStageMask = _sg_vk_dst_stage_mask(new_access); + barrier.dstAccessMask = _sg_vk_dst_access_mask(new_access); + barrier.newLayout = _sg_vk_image_layout(new_access); + barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + barrier.image = img->vk.img; + if (_sg_is_depth_or_depth_stencil_format(img->cmn.pixel_format)) { + barrier.subresourceRange.aspectMask |= VK_IMAGE_ASPECT_DEPTH_BIT; + if (_sg_is_depth_stencil_format(img->cmn.pixel_format)) { + barrier.subresourceRange.aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT; + } + } else { + barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + } + barrier.subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS; + barrier.subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS; + _SG_STRUCT(VkDependencyInfo, dep_info); + dep_info.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO; + dep_info.imageMemoryBarrierCount = 1; + dep_info.pImageMemoryBarriers = &barrier; + vkCmdPipelineBarrier2(cmd_buf, &dep_info); + _sg_stats_inc(vk.num_cmd_pipeline_barrier); + img->vk.cur_access = new_access; +} + +_SOKOL_PRIVATE void _sg_vk_buffer_barrier(VkCommandBuffer cmd_buf, _sg_buffer_t* buf, _sg_vk_access_t new_access) { + SOKOL_ASSERT(cmd_buf && buf && buf->vk.buf); + if (_sg_vk_is_read_access(buf->vk.cur_access) && _sg_vk_is_read_access(new_access)) { + return; + } + _SG_STRUCT(VkBufferMemoryBarrier2, barrier); + barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2; + barrier.srcStageMask = _sg_vk_src_stage_mask(buf->vk.cur_access); + barrier.srcAccessMask = _sg_vk_src_access_mask(buf->vk.cur_access); + barrier.dstStageMask = _sg_vk_dst_stage_mask(new_access); + barrier.dstAccessMask = _sg_vk_dst_access_mask(new_access); + barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + barrier.buffer = buf->vk.buf; + barrier.offset = 0; + barrier.size = VK_WHOLE_SIZE; + _SG_STRUCT(VkDependencyInfo, dep_info); + dep_info.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO; + dep_info.bufferMemoryBarrierCount = 1; + dep_info.pBufferMemoryBarriers = &barrier; + vkCmdPipelineBarrier2(cmd_buf, &dep_info); + _sg_stats_inc(vk.num_cmd_pipeline_barrier); + buf->vk.cur_access = new_access; +} + +_SOKOL_PRIVATE void _sg_vk_barrier_on_begin_pass(VkCommandBuffer cmd_buf, const sg_pass* pass, const _sg_attachments_ptrs_t* atts, bool is_compute_pass) { + SOKOL_ASSERT(cmd_buf); + if (is_compute_pass) { + SOKOL_ASSERT(0 == _sg.vk.track.buffers.cur_slot); + SOKOL_ASSERT(0 == _sg.vk.track.images.cur_slot); + } else { + const bool is_swapchain_pass = atts->empty; + if (is_swapchain_pass) { + const sg_vulkan_swapchain* vk_swapchain = &pass->swapchain.vulkan; + SOKOL_ASSERT(vk_swapchain->render_image); + VkImage vk_color_image = (VkImage)vk_swapchain->render_image; + _sg_vk_swapchain_beginpass_barrier(cmd_buf, vk_color_image, _SG_VK_ACCESS_COLOR_ATTACHMENT); + if (_sg.cur_pass.swapchain.sample_count > 1) { + VkImage vk_resolve_image = (VkImage)vk_swapchain->resolve_image; + SOKOL_ASSERT(vk_resolve_image); + _sg_vk_swapchain_beginpass_barrier(cmd_buf, vk_resolve_image, _SG_VK_ACCESS_RESOLVE_ATTACHMENT); + } + if (vk_swapchain->depth_stencil_image) { + VkImage vk_ds_image = (VkImage)vk_swapchain->depth_stencil_image; + const bool has_stencil = _sg_is_depth_stencil_format(_sg.cur_pass.swapchain.depth_fmt); + _sg_vk_access_t access = _SG_VK_ACCESS_DEPTH_ATTACHMENT; + if (has_stencil) { + access |= _SG_VK_ACCESS_STENCIL_ATTACHMENT; + } + _sg_vk_swapchain_beginpass_barrier(cmd_buf, vk_ds_image, access); + } + } else { + SOKOL_ASSERT(atts->num_color_views <= SG_MAX_COLOR_ATTACHMENTS); + for (int i = 0; i < atts->num_color_views; i++) { + SOKOL_ASSERT(atts->color_views[i]); + _sg_image_t* color_image = _sg_image_ref_ptr(&atts->color_views[i]->cmn.img.ref); + if (pass->action.colors[i].load_action != SG_LOADACTION_LOAD) { + // don't need to preserve image content for clear and dontcare + color_image->vk.cur_access |= _SG_VK_ACCESS_DISCARD; + } + _sg_vk_image_barrier(cmd_buf, color_image, _SG_VK_ACCESS_COLOR_ATTACHMENT); + if (atts->resolve_views[i]) { + _sg_image_t* resolve_image = _sg_image_ref_ptr(&atts->resolve_views[i]->cmn.img.ref); + // never need to preserve content for resolve image + resolve_image->vk.cur_access |= _SG_VK_ACCESS_DISCARD; + _sg_vk_image_barrier(cmd_buf, resolve_image, _SG_VK_ACCESS_RESOLVE_ATTACHMENT); + } + } + if (atts->ds_view) { + _sg_image_t* ds_image = _sg_image_ref_ptr(&atts->ds_view->cmn.img.ref); + const bool has_stencil = _sg_is_depth_stencil_format(ds_image->cmn.pixel_format); + if ((pass->action.depth.load_action != SG_LOADACTION_LOAD) && + (pass->action.stencil.load_action != SG_LOADACTION_LOAD)) + { + // don't need to preserve image content for clear and dontcare + ds_image->vk.cur_access |= _SG_VK_ACCESS_DISCARD; + } + _sg_vk_access_t dst_access = _SG_VK_ACCESS_DEPTH_ATTACHMENT; + if (has_stencil) { + dst_access |= _SG_VK_ACCESS_STENCIL_ATTACHMENT; + } + _sg_vk_image_barrier(cmd_buf, ds_image, dst_access); + } + } + } +} + +_SOKOL_PRIVATE void _sg_vk_barrier_on_apply_bindings(VkCommandBuffer cmd_buf, const _sg_bindings_ptrs_t* bnd, bool is_compute_pass) { + SOKOL_ASSERT(bnd); + if (is_compute_pass) { + SOKOL_ASSERT(bnd->pip); + for (size_t i = 0; i < SG_MAX_VIEW_BINDSLOTS; i++) { + const _sg_view_t* view = bnd->views[i]; + if (0 == view) { + continue; + } else if (view->cmn.type == SG_VIEWTYPE_STORAGEBUFFER) { + const _sg_shader_t* shd = _sg_shader_ref_ptr(&bnd->pip->cmn.shader); + _sg_buffer_t* buf = _sg_buffer_ref_ptr(&view->cmn.buf.ref); + _sg_vk_access_t new_access = shd->cmn.views[i].sbuf_readonly + ? _SG_VK_ACCESS_STORAGEBUFFER_RO + : _SG_VK_ACCESS_STORAGEBUFFER_RW; + _sg_vk_buffer_barrier(cmd_buf, buf, new_access); + _sg_track_add(&_sg.vk.track.buffers, buf->slot.id); + } else if (view->cmn.type == SG_VIEWTYPE_STORAGEIMAGE) { + _sg_image_t* img = _sg_image_ref_ptr(&view->cmn.img.ref); + _sg_vk_image_barrier(cmd_buf, img, _SG_VK_ACCESS_STORAGEIMAGE); + _sg_track_add(&_sg.vk.track.images, img->slot.id); + } else if (view->cmn.type == SG_VIEWTYPE_TEXTURE) { + _sg_image_t* img = _sg_image_ref_ptr(&view->cmn.img.ref); + _sg_vk_image_barrier(cmd_buf, img, _SG_VK_ACCESS_TEXTURE); + _sg_track_add(&_sg.vk.track.images, img->slot.id); + } else { + SOKOL_UNREACHABLE; + } + } + } else { + // no transitions allowed in render passes, but check if resources are in + // correct access state + for (size_t i = 0; i < SG_MAX_VERTEXBUFFER_BINDSLOTS; i++) { + if (bnd->vbs[i]) { + SOKOL_ASSERT(0 != (bnd->vbs[i]->vk.cur_access & _SG_VK_ACCESS_VERTEXBUFFER)); + } + } + if (bnd->ib) { + SOKOL_ASSERT(0 != (bnd->ib->vk.cur_access & _SG_VK_ACCESS_INDEXBUFFER)); + } + for (size_t i = 0; i < SG_MAX_VIEW_BINDSLOTS; i++) { + const _sg_view_t* view = bnd->views[i]; + if (0 == view) { + continue; + } + else if (view->cmn.type == SG_VIEWTYPE_STORAGEBUFFER) { + const _sg_buffer_t* buf = _sg_buffer_ref_ptr(&view->cmn.buf.ref); + _SOKOL_UNUSED(buf); + SOKOL_ASSERT(0 != (buf->vk.cur_access & _SG_VK_ACCESS_STORAGEBUFFER_RO)); + } else if (view->cmn.type == SG_VIEWTYPE_TEXTURE) { + const _sg_image_t* img = _sg_image_ref_ptr(&view->cmn.img.ref); + _SOKOL_UNUSED(img); + SOKOL_ASSERT(0 != (img->vk.cur_access & _SG_VK_ACCESS_TEXTURE)); + } else { + SOKOL_UNREACHABLE; + } + } + } +} + +_SOKOL_PRIVATE void _sg_vk_barrier_on_end_pass(VkCommandBuffer cmd_buf, const _sg_attachments_ptrs_t* atts, bool is_compute_pass) { + SOKOL_ASSERT(cmd_buf); + if (is_compute_pass) { + // transition all tracked buffers into vertex+index+sbuf-ro access + const _sg_vk_access_t new_buf_access = _SG_VK_ACCESS_VERTEXBUFFER|_SG_VK_ACCESS_INDEXBUFFER|_SG_VK_ACCESS_STORAGEBUFFER_RO; + for (int i = 0; i < _sg.vk.track.buffers.cur_slot; i++) { + const uint32_t buf_id = _sg.vk.track.buffers.slots[i]; + _sg_buffer_t* buf = _sg_lookup_buffer(buf_id); + if (buf) { + _sg_vk_buffer_barrier(cmd_buf, buf, new_buf_access); + } + } + _sg_track_reset(&_sg.vk.track.buffers); + + // transition all tracked images into texture access + const _sg_vk_access_t new_img_access = _SG_VK_ACCESS_TEXTURE; + for (int i = 0; i < _sg.vk.track.images.cur_slot; i++) { + const uint32_t img_id = _sg.vk.track.images.slots[i]; + _sg_image_t* img = _sg_lookup_image(img_id); + if (img) { + _sg_vk_image_barrier(cmd_buf, img, new_img_access); + } + } + _sg_track_reset(&_sg.vk.track.images); + } else { + const bool is_swapchain_pass = atts->empty; + if (is_swapchain_pass) { + SOKOL_ASSERT(_sg.vk.swapchain.render_image); + VkImage present_image = _sg.vk.swapchain.resolve_image + ? (VkImage)_sg.vk.swapchain.resolve_image + : (VkImage)_sg.vk.swapchain.render_image; + _sg_vk_swapchain_endpass_barrier(cmd_buf, present_image, _SG_VK_ACCESS_COLOR_ATTACHMENT, true); + } else { + for (int i = 0; i < atts->num_color_views; i++) { + if (_sg.cur_pass.action.colors[i].store_action == SG_STOREACTION_STORE) { + SOKOL_ASSERT(atts->color_views[i]); + _sg_image_t* img = _sg_image_ref_ptr(&atts->color_views[i]->cmn.img.ref); + _sg_vk_image_barrier(cmd_buf, img, _SG_VK_ACCESS_TEXTURE); + } + if (atts->resolve_views[i]) { + _sg_image_t* img = _sg_image_ref_ptr(&atts->resolve_views[i]->cmn.img.ref); + _sg_vk_image_barrier(cmd_buf, img, _SG_VK_ACCESS_TEXTURE); + } + } + if (atts->ds_view) { + _sg_image_t* img = _sg_image_ref_ptr(&atts->ds_view->cmn.img.ref); + if (_sg.cur_pass.action.depth.store_action == SG_STOREACTION_STORE) { + _sg_vk_image_barrier(cmd_buf, img, _SG_VK_ACCESS_TEXTURE); + } + } + } + } +} + +_SOKOL_PRIVATE int _sg_vk_mem_find_memory_type_index(uint32_t type_filter, VkMemoryPropertyFlags props) { + SOKOL_ASSERT(_sg.vk.phys_dev); + _SG_STRUCT(VkPhysicalDeviceMemoryProperties, mem_props); + vkGetPhysicalDeviceMemoryProperties(_sg.vk.phys_dev, &mem_props); + for (uint32_t i = 0; i < mem_props.memoryTypeCount; i++) { + if ((type_filter & (1 << i)) && ((mem_props.memoryTypes[i].propertyFlags & props) == props)) { + return (int)i; + } + } + return -1; +} + +_SOKOL_PRIVATE VkDeviceMemory _sg_vk_mem_alloc_device_memory(_sg_vk_memtype_t mem_type, const VkMemoryRequirements* mem_reqs) { + SOKOL_ASSERT(_sg.vk.dev); + SOKOL_ASSERT(mem_reqs); + + VkMemoryPropertyFlags mem_prop_flags = 0; + VkMemoryAllocateFlags mem_alloc_flags = 0; + switch (mem_type) { + case _SG_VK_MEMTYPE_GENERIC_BUFFER: + mem_prop_flags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; + break; + case _SG_VK_MEMTYPE_STORAGE_BUFFER: + mem_prop_flags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; + mem_alloc_flags = VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT; + break; + case _SG_VK_MEMTYPE_IMAGE: + mem_prop_flags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; + break; + case _SG_VK_MEMTYPE_STAGING_COPY: + mem_prop_flags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; + break; + case _SG_VK_MEMTYPE_STAGING_STREAM: + mem_prop_flags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; + break; + case _SG_VK_MEMTYPE_UNIFORMS: + mem_prop_flags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; + mem_alloc_flags = VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT; + break; + case _SG_VK_MEMTYPE_DESCRIPTORS: + mem_prop_flags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; + mem_alloc_flags = VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT; + break; + default: + SOKOL_UNREACHABLE; + break; + } + + int mem_type_index = _sg_vk_mem_find_memory_type_index(mem_reqs->memoryTypeBits, mem_prop_flags); + if (-1 == mem_type_index) { + _SG_ERROR(VULKAN_ALLOC_DEVICE_MEMORY_NO_SUITABLE_MEMORY_TYPE); + return 0; + } + _SG_STRUCT(VkMemoryAllocateFlagsInfo, flags_info); + flags_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO; + flags_info.flags = mem_alloc_flags; + _SG_STRUCT(VkMemoryAllocateInfo, alloc_info); + alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + alloc_info.pNext = &flags_info; + alloc_info.allocationSize = mem_reqs->size; + alloc_info.memoryTypeIndex = (uint32_t) mem_type_index; + VkDeviceMemory vk_dev_mem = 0; + VkResult res = vkAllocateMemory(_sg.vk.dev, &alloc_info, 0, &vk_dev_mem); + _sg_stats_inc(vk.num_allocate_memory); + _sg_stats_add(vk.size_allocate_memory, (uint32_t)mem_reqs->size); + if (res != VK_SUCCESS) { + _SG_ERROR(VULKAN_ALLOCATE_MEMORY_FAILED); + return 0; + } + SOKOL_ASSERT(vk_dev_mem); + return vk_dev_mem; +} + +_SOKOL_PRIVATE void _sg_vk_mem_free_device_memory(VkDeviceMemory vk_dev_mem) { + SOKOL_ASSERT(_sg.vk.dev); + SOKOL_ASSERT(vk_dev_mem); + vkFreeMemory(_sg.vk.dev, vk_dev_mem, 0); + _sg_stats_inc(vk.num_free_memory); +} + +_SOKOL_PRIVATE bool _sg_vk_mem_alloc_buffer_device_memory(_sg_buffer_t* buf) { + SOKOL_ASSERT(_sg.vk.dev); + SOKOL_ASSERT(buf); + SOKOL_ASSERT(buf->vk.buf); + SOKOL_ASSERT(0 == buf->vk.mem); + _SG_STRUCT(VkMemoryRequirements, mem_reqs); + vkGetBufferMemoryRequirements(_sg.vk.dev, buf->vk.buf, &mem_reqs); + _sg_vk_memtype_t mem_type = buf->cmn.usage.storage_buffer + ? _SG_VK_MEMTYPE_STORAGE_BUFFER + : _SG_VK_MEMTYPE_GENERIC_BUFFER; + buf->vk.mem = _sg_vk_mem_alloc_device_memory(mem_type, &mem_reqs); + if (0 == buf->vk.mem) { + _SG_ERROR(VULKAN_ALLOC_BUFFER_DEVICE_MEMORY_FAILED); + return false; + } + return true; +} + +_SOKOL_PRIVATE bool _sg_vk_mem_alloc_image_device_memory(_sg_image_t* img) { + SOKOL_ASSERT(_sg.vk.dev); + SOKOL_ASSERT(img); + SOKOL_ASSERT(img->vk.img); + SOKOL_ASSERT(0 == img->vk.mem); + _SG_STRUCT(VkMemoryRequirements, mem_reqs); + vkGetImageMemoryRequirements(_sg.vk.dev, img->vk.img, &mem_reqs); + img->vk.mem = _sg_vk_mem_alloc_device_memory(_SG_VK_MEMTYPE_IMAGE, &mem_reqs); + if (0 == img->vk.mem) { + _SG_ERROR(VULKAN_ALLOC_IMAGE_DEVICE_MEMORY_FAILED); + return false; + } + return true; +} + +_SOKOL_PRIVATE void _sg_vk_create_delete_queues(void) { + const uint32_t num_items = (uint32_t) + (2 * _sg.desc.buffer_pool_size + + 2 * _sg.desc.image_pool_size + + 1 * _sg.desc.sampler_pool_size + + 5 * _sg.desc.shader_pool_size + + 2 * _sg.desc.pipeline_pool_size + + 1 * _sg.desc.view_pool_size + + 256); + for (size_t i = 0; i < SG_NUM_INFLIGHT_FRAMES; i++) { + _sg_vk_delete_queue_t* queue = &_sg.vk.frame.slot[i].delete_queue; + SOKOL_ASSERT(0 == queue->items); + SOKOL_ASSERT(0 == queue->index); + queue->num = num_items; + const size_t pool_size = num_items * sizeof(_sg_vk_delete_queue_item_t); + queue->items = (_sg_vk_delete_queue_item_t*)_sg_malloc(pool_size); + } +} + +_SOKOL_PRIVATE void _sg_vk_delete_queue_collect_items(_sg_vk_delete_queue_t* queue) { + SOKOL_ASSERT(queue && queue->items); + for (uint32_t i = 0; i < queue->index; i++) { + _sg_vk_delete_queue_item_t* item = &queue->items[i]; + SOKOL_ASSERT(item->destructor && item->obj); + item->destructor(item->obj); + item->destructor = 0; + item->obj = 0; + } + _sg_stats_add(vk.num_delete_queue_collected, queue->index); + queue->index = 0; +} + +_SOKOL_PRIVATE void _sg_vk_destroy_delete_queues(void) { + for (size_t i = 0; i < SG_NUM_INFLIGHT_FRAMES; i++) { + _sg_vk_delete_queue_t* queue = &_sg.vk.frame.slot[i].delete_queue; + SOKOL_ASSERT(queue->items); + _sg_vk_delete_queue_collect_items(queue); + _sg_free(queue->items); + SOKOL_ASSERT(queue->index == 0); + queue->items = 0; + queue->num = 0; + } +} + +_SOKOL_PRIVATE _sg_vk_delete_queue_t* _sg_vk_cur_delete_queue(void) { + return &_sg.vk.frame.slot[_sg.vk.frame_slot].delete_queue; +} + +_SOKOL_PRIVATE void _sg_vk_delete_queue_collect(void) { + _sg_vk_delete_queue_t* queue = _sg_vk_cur_delete_queue(); + _sg_vk_delete_queue_collect_items(queue); +} + +_SOKOL_PRIVATE void _sg_vk_delete_queue_add(_sg_vk_delete_queue_destructor_t destructor, void* obj) { + SOKOL_ASSERT(destructor && obj); + _sg_vk_delete_queue_t* queue = _sg_vk_cur_delete_queue(); + SOKOL_ASSERT(queue->items); + if (queue->index >= queue->num) { + _SG_PANIC(VULKAN_DELETE_QUEUE_EXHAUSTED); + } + queue->items[queue->index].destructor = destructor; + queue->items[queue->index].obj = obj; + queue->index += 1; + _sg_stats_inc(vk.num_delete_queue_added); +} + +// double-buffer system for any non-blocking CPU => GPU data +_SOKOL_PRIVATE void _sg_vk_shared_buffer_init(_sg_vk_shared_buffer_t* shbuf, uint32_t size, uint32_t align, _sg_vk_memtype_t mem_type, const char* label) { + SOKOL_ASSERT(_sg.vk.dev); + SOKOL_ASSERT(shbuf && (size > 0) && (align > 0)); + SOKOL_ASSERT(0 == shbuf->size); + SOKOL_ASSERT(0 == shbuf->offset); + SOKOL_ASSERT(0 == shbuf->cur_buf); + SOKOL_ASSERT(false == shbuf->overflown); + VkResult res; + VkBufferUsageFlags vk_usage = 0; + bool want_device_address = false; + switch (mem_type) { + case _SG_VK_MEMTYPE_STAGING_STREAM: + vk_usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; + break; + case _SG_VK_MEMTYPE_UNIFORMS: + vk_usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; + vk_usage |= VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT; + want_device_address = true; + break; + case _SG_VK_MEMTYPE_DESCRIPTORS: + vk_usage = VK_BUFFER_USAGE_RESOURCE_DESCRIPTOR_BUFFER_BIT_EXT; + vk_usage |= VK_BUFFER_USAGE_SAMPLER_DESCRIPTOR_BUFFER_BIT_EXT; + vk_usage |= VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT; + want_device_address = true; + break; + default: + SOKOL_UNREACHABLE; + break; + } + + shbuf->size = _sg_roundup_u32(size, align); + shbuf->align = align; + for (size_t i = 0; i < SG_NUM_INFLIGHT_FRAMES; i++) { + SOKOL_ASSERT(0 == shbuf->slots[i].buf); + SOKOL_ASSERT(0 == shbuf->slots[i].mem); + SOKOL_ASSERT(0 == shbuf->slots[i].mem_ptr); + _SG_STRUCT(VkBufferCreateInfo, buf_create_info); + buf_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buf_create_info.size = shbuf->size; + buf_create_info.usage = vk_usage; + buf_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + res = vkCreateBuffer(_sg.vk.dev, &buf_create_info, 0, &shbuf->slots[i].buf); + if (res != VK_SUCCESS) { + _SG_PANIC(VULKAN_CREATE_SHARED_BUFFER_FAILED); + } + SOKOL_ASSERT(shbuf->slots[i].buf); + _sg_vk_set_object_label(VK_OBJECT_TYPE_BUFFER, (uint64_t)shbuf->slots[i].buf, label); + + _SG_STRUCT(VkMemoryRequirements, mem_reqs); + vkGetBufferMemoryRequirements(_sg.vk.dev, shbuf->slots[i].buf, &mem_reqs); + shbuf->slots[i].mem = _sg_vk_mem_alloc_device_memory(mem_type, &mem_reqs); + if (0 == shbuf->slots[i].mem) { + _SG_PANIC(VULKAN_ALLOCATE_SHARED_BUFFER_MEMORY_FAILED); + } + res = vkBindBufferMemory(_sg.vk.dev, shbuf->slots[i].buf, shbuf->slots[i].mem, 0); + if (res != VK_SUCCESS) { + _SG_PANIC(VULKAN_BIND_SHARED_BUFFER_MEMORY_FAILED); + } + if (want_device_address) { + _SG_STRUCT(VkBufferDeviceAddressInfo, addr_info); + addr_info.sType = VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO; + addr_info.buffer = shbuf->slots[i].buf; + shbuf->slots[i].dev_addr = vkGetBufferDeviceAddress(_sg.vk.dev, &addr_info); + SOKOL_ASSERT(shbuf->slots[i].dev_addr); + } + res = vkMapMemory(_sg.vk.dev, shbuf->slots[i].mem, 0, VK_WHOLE_SIZE, 0, &shbuf->slots[i].mem_ptr); + if (res != VK_SUCCESS) { + _SG_PANIC(VULKAN_MAP_SHARED_BUFFER_MEMORY_FAILED); + } + SOKOL_ASSERT(shbuf->slots[i].mem_ptr); + } +} + +_SOKOL_PRIVATE void _sg_vk_shared_buffer_discard(_sg_vk_shared_buffer_t* shbuf) { + SOKOL_ASSERT(_sg.vk.dev); + SOKOL_ASSERT(shbuf); + for (size_t i = 0; i < SG_NUM_INFLIGHT_FRAMES; i++) { + SOKOL_ASSERT(shbuf->slots[i].buf); + SOKOL_ASSERT(shbuf->slots[i].mem); + SOKOL_ASSERT(shbuf->slots[i].mem_ptr); + vkUnmapMemory(_sg.vk.dev, shbuf->slots[i].mem); + shbuf->slots[i].mem_ptr = 0; + _sg_vk_mem_free_device_memory(shbuf->slots[i].mem); + shbuf->slots[i].mem = 0; + vkDestroyBuffer(_sg.vk.dev, shbuf->slots[i].buf, 0); + shbuf->slots[i].buf = 0; + shbuf->slots[i].dev_addr = 0; + } + shbuf->size = 0; + shbuf->offset = 0; + shbuf->cur_buf = 0; + shbuf->cur_dev_addr = 0; + shbuf->overflown = false; +} + +_SOKOL_PRIVATE void _sg_vk_shared_buffer_after_acquire(_sg_vk_shared_buffer_t* shbuf) { + SOKOL_ASSERT(_sg.vk.dev); + SOKOL_ASSERT(0 == shbuf->cur_buf); + SOKOL_ASSERT(0 == shbuf->cur_mem_ptr); + SOKOL_ASSERT(0 == shbuf->cur_dev_addr); + const uint32_t frame_slot = _sg.vk.frame_slot; + shbuf->offset = 0; + shbuf->cur_buf = shbuf->slots[frame_slot].buf; + shbuf->cur_mem_ptr = shbuf->slots[frame_slot].mem_ptr; + shbuf->cur_dev_addr = shbuf->slots[frame_slot].dev_addr; // NOTE: may be 0 + shbuf->overflown = false; + SOKOL_ASSERT(shbuf->cur_buf); + SOKOL_ASSERT(shbuf->cur_mem_ptr); +} + +_SOKOL_PRIVATE void _sg_vk_shared_buffer_before_submit(_sg_vk_shared_buffer_t* shbuf) { + SOKOL_ASSERT(shbuf->cur_buf); + SOKOL_ASSERT(shbuf->cur_mem_ptr); + // NOTE: if the buffer wouldn't be cache-coherent, this would be the place to do a flush + shbuf->cur_buf = 0; + shbuf->cur_mem_ptr = 0; + shbuf->cur_dev_addr = 0; +} + +_SOKOL_PRIVATE VkDeviceSize _sg_vk_shared_buffer_alloc(_sg_vk_shared_buffer_t* shbuf, uint32_t num_bytes) { + SOKOL_ASSERT(shbuf && (num_bytes > 0)); + if (shbuf->overflown) { + return _SG_VK_SHARED_BUFFER_OVERFLOW_RESULT; + } + if ((shbuf->offset + num_bytes) > shbuf->size) { + shbuf->overflown = true; + return _SG_VK_SHARED_BUFFER_OVERFLOW_RESULT; + } + SOKOL_ASSERT((shbuf->offset & (shbuf->align - 1)) == 0); + VkDeviceSize offset = shbuf->offset; + shbuf->offset = _sg_roundup_u32(shbuf->offset + num_bytes, shbuf->align); + return offset; +} + +_SOKOL_PRIVATE uint8_t* _sg_vk_shared_buffer_ptr(_sg_vk_shared_buffer_t* shbuf, VkDeviceSize offset) { + SOKOL_ASSERT(shbuf && shbuf->cur_mem_ptr); + SOKOL_ASSERT(!shbuf->overflown); + SOKOL_ASSERT(offset < shbuf->size); + return ((uint8_t*)shbuf->cur_mem_ptr) + offset; +} + +_SOKOL_PRIVATE VkDeviceSize _sg_vk_shared_buffer_memcpy(_sg_vk_shared_buffer_t* shbuf, const void* src_ptr, uint32_t num_bytes) { + SOKOL_ASSERT(shbuf && src_ptr && (num_bytes > 0)); + const VkDeviceSize offset = _sg_vk_shared_buffer_alloc(shbuf, num_bytes); + if (offset != _SG_VK_SHARED_BUFFER_OVERFLOW_RESULT) { + memcpy(_sg_vk_shared_buffer_ptr(shbuf, offset), src_ptr, num_bytes); + } + return offset; +} + +// staging system for blocking immutable and dynamic updates, can deal arbitrarily sized data +_SOKOL_PRIVATE void _sg_vk_staging_copy_init(void) { + SOKOL_ASSERT(_sg.vk.dev); + VkResult res; + + SOKOL_ASSERT(0 == _sg.vk.stage.copy.cmd_pool); + SOKOL_ASSERT(0 == _sg.vk.stage.copy.cmd_buf); + SOKOL_ASSERT(0 == _sg.vk.stage.copy.size); + SOKOL_ASSERT(0 == _sg.vk.stage.copy.buf); + SOKOL_ASSERT(0 == _sg.vk.stage.copy.mem); + SOKOL_ASSERT(_sg.desc.vulkan.copy_staging_buffer_size > 0); + + _SG_STRUCT(VkCommandPoolCreateInfo, pool_create_info); + pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; + pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT | VK_COMMAND_POOL_CREATE_TRANSIENT_BIT; + pool_create_info.queueFamilyIndex = _sg.vk.queue_family_index; + res = vkCreateCommandPool(_sg.vk.dev, &pool_create_info, 0, &_sg.vk.stage.copy.cmd_pool); + SOKOL_ASSERT((res == VK_SUCCESS && _sg.vk.stage.copy.cmd_pool)); + _sg_vk_set_object_label(VK_OBJECT_TYPE_COMMAND_POOL, (uint64_t)_sg.vk.stage.copy.cmd_pool, "copy-staging cmd pool"); + + _SG_STRUCT(VkCommandBufferAllocateInfo, cmdbuf_alloc_info); + cmdbuf_alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; + cmdbuf_alloc_info.commandPool = _sg.vk.stage.copy.cmd_pool; + cmdbuf_alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; + cmdbuf_alloc_info.commandBufferCount = 1; + res = vkAllocateCommandBuffers(_sg.vk.dev, &cmdbuf_alloc_info, &_sg.vk.stage.copy.cmd_buf); + SOKOL_ASSERT((res == VK_SUCCESS) && _sg.vk.stage.copy.cmd_buf); + _sg_vk_set_object_label(VK_OBJECT_TYPE_COMMAND_BUFFER, (uint64_t)_sg.vk.stage.copy.cmd_buf, "copy-staging cmd buffer"); + + _sg.vk.stage.copy.size = (uint32_t) _sg.desc.vulkan.copy_staging_buffer_size; + _SG_STRUCT(VkBufferCreateInfo, buf_create_info); + buf_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buf_create_info.size = _sg.vk.stage.copy.size; + buf_create_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; + buf_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + res = vkCreateBuffer(_sg.vk.dev, &buf_create_info, 0, &_sg.vk.stage.copy.buf); + if (res != VK_SUCCESS) { + _SG_PANIC(VULKAN_STAGING_CREATE_BUFFER_FAILED); + } + SOKOL_ASSERT(_sg.vk.stage.copy.buf); + _sg_vk_set_object_label(VK_OBJECT_TYPE_BUFFER, (uint64_t)_sg.vk.stage.copy.buf, "copy-staging staging buffer"); + + _SG_STRUCT(VkMemoryRequirements, mem_reqs); + vkGetBufferMemoryRequirements(_sg.vk.dev, _sg.vk.stage.copy.buf, &mem_reqs); + _sg.vk.stage.copy.mem = _sg_vk_mem_alloc_device_memory(_SG_VK_MEMTYPE_STAGING_COPY, &mem_reqs); + if (0 == _sg.vk.stage.copy.mem) { + _SG_PANIC(VULKAN_STAGING_ALLOCATE_MEMORY_FAILED); + } + res = vkBindBufferMemory(_sg.vk.dev, _sg.vk.stage.copy.buf, _sg.vk.stage.copy.mem, 0); + if (res != VK_SUCCESS) { + _SG_PANIC(VULKAN_STAGING_BIND_BUFFER_MEMORY_FAILED); + } +} + +_SOKOL_PRIVATE void _sg_vk_staging_copy_discard(void) { + SOKOL_ASSERT(_sg.vk.dev); + SOKOL_ASSERT(_sg.vk.stage.copy.cmd_pool); + SOKOL_ASSERT(_sg.vk.stage.copy.cmd_buf); + SOKOL_ASSERT(_sg.vk.stage.copy.size); + SOKOL_ASSERT(_sg.vk.stage.copy.buf); + SOKOL_ASSERT(_sg.vk.stage.copy.mem); + + _sg_vk_mem_free_device_memory(_sg.vk.stage.copy.mem); + _sg.vk.stage.copy.mem = 0; + vkDestroyBuffer(_sg.vk.dev, _sg.vk.stage.copy.buf, 0); + _sg.vk.stage.copy.buf = 0; + vkDestroyCommandPool(_sg.vk.dev, _sg.vk.stage.copy.cmd_pool, 0); + _sg.vk.stage.copy.cmd_pool = 0; + _sg.vk.stage.copy.cmd_buf = 0; + _sg.vk.stage.copy.size = 0; +} + +_SOKOL_PRIVATE VkCommandBuffer _sg_vk_staging_copy_begin(void) { + VkCommandBuffer cmd_buf = _sg.vk.stage.copy.cmd_buf; + _SG_STRUCT(VkCommandBufferBeginInfo, cmdbuf_begin_info); + cmdbuf_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; + cmdbuf_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; + VkResult res = vkBeginCommandBuffer(cmd_buf, &cmdbuf_begin_info); + SOKOL_ASSERT(res == VK_SUCCESS); _SOKOL_UNUSED(res); + return cmd_buf; +} + +_SOKOL_PRIVATE void _sg_vk_staging_copy_end(VkCommandBuffer cmd_buf, VkQueue queue) { + SOKOL_ASSERT(cmd_buf && queue); + VkResult res; + _SOKOL_UNUSED(res); + vkEndCommandBuffer(cmd_buf); + _SG_STRUCT(VkSubmitInfo, submit_info); + submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + submit_info.commandBufferCount = 1; + submit_info.pCommandBuffers = &cmd_buf; + res = vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); + SOKOL_ASSERT(res == VK_SUCCESS); + res = vkQueueWaitIdle(queue); + SOKOL_ASSERT(res == VK_SUCCESS); + res = vkResetCommandBuffer(cmd_buf, 0); + SOKOL_ASSERT(res == VK_SUCCESS); +} + +_SOKOL_PRIVATE void _sg_vk_staging_map_memcpy_unmap(VkDeviceMemory mem, const void* ptr, uint32_t num_bytes) { + SOKOL_ASSERT(_sg.vk.dev); + SOKOL_ASSERT(mem); + SOKOL_ASSERT(ptr); + SOKOL_ASSERT(num_bytes > 0); + void* dst_ptr = 0; + VkResult res = vkMapMemory(_sg.vk.dev, mem, 0, VK_WHOLE_SIZE, 0, &dst_ptr); + SOKOL_ASSERT((res == VK_SUCCESS) && dst_ptr); _SOKOL_UNUSED(res); + memcpy(dst_ptr, ptr, num_bytes); + vkUnmapMemory(_sg.vk.dev, mem); +} + +_SOKOL_PRIVATE void _sg_vk_staging_copy_buffer_data(_sg_buffer_t* buf, const sg_range* src_data, size_t dst_offset, bool initial_wait) { + SOKOL_ASSERT(_sg.vk.dev); + SOKOL_ASSERT(_sg.vk.queue); + SOKOL_ASSERT(_sg.vk.stage.copy.mem); + SOKOL_ASSERT(_sg.vk.stage.copy.buf); + SOKOL_ASSERT(buf && buf->vk.buf); + SOKOL_ASSERT(src_data && src_data->ptr && (src_data->size > 0)); + SOKOL_ASSERT((dst_offset + src_data->size) <= (size_t)buf->cmn.size); + + // an inital wait is only needed for updating existing resources but not when populating a new resource + if (initial_wait) { + VkResult res = vkQueueWaitIdle(_sg.vk.queue); + SOKOL_ASSERT(res == VK_SUCCESS); _SOKOL_UNUSED(res); + } + + VkDeviceMemory dst_mem = _sg.vk.stage.copy.mem; + VkBuffer src_buf = _sg.vk.stage.copy.buf; + VkBuffer dst_buf = buf->vk.buf; + const uint8_t* src_ptr = (const uint8_t*)src_data->ptr; + uint32_t dst_size = _sg.vk.stage.copy.size; + uint32_t bytes_remaining = (uint32_t)src_data->size; + _SG_STRUCT(VkBufferCopy, region); + region.dstOffset = dst_offset; + while (bytes_remaining > 0) { + uint64_t bytes_to_copy = bytes_remaining; + if (bytes_remaining > dst_size) { + bytes_to_copy = dst_size; + bytes_remaining -= dst_size; + } else { + bytes_to_copy = bytes_remaining; + bytes_remaining = 0; + } + region.size = bytes_to_copy; + _sg_vk_staging_map_memcpy_unmap(dst_mem, src_ptr, (uint32_t)bytes_to_copy); + VkCommandBuffer cmd_buf = _sg_vk_staging_copy_begin(); + vkCmdCopyBuffer(cmd_buf, src_buf, dst_buf, 1, ®ion); + _sg_stats_inc(vk.num_cmd_copy_buffer); + _sg_vk_staging_copy_end(cmd_buf, _sg.vk.queue); + src_ptr += bytes_to_copy; + region.dstOffset += bytes_to_copy; + } + buf->vk.cur_access = _SG_VK_ACCESS_VERTEXBUFFER | _SG_VK_ACCESS_INDEXBUFFER | _SG_VK_ACCESS_STORAGEBUFFER_RO; +} + +_SOKOL_PRIVATE void _sg_vk_init_vk_image_staging_structs(const _sg_image_t* img, VkBuffer vk_buf, VkBufferImageCopy2* region, VkCopyBufferToImageInfo2* copy_info) { + SOKOL_ASSERT(img && region && copy_info); + + region->sType = VK_STRUCTURE_TYPE_BUFFER_IMAGE_COPY_2; + if (_sg_is_depth_or_depth_stencil_format(img->cmn.pixel_format)) { + region->imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; + if (_sg_is_depth_stencil_format(img->cmn.pixel_format)) { + region->imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; + } + } else { + region->imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + } + region->imageSubresource.layerCount = 1; + region->imageExtent.depth = 1; + + copy_info->sType = VK_STRUCTURE_TYPE_COPY_BUFFER_TO_IMAGE_INFO_2; + copy_info->srcBuffer = vk_buf; + copy_info->dstImage = img->vk.img; + copy_info->dstImageLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; + copy_info->regionCount = 1; + copy_info->pRegions = region; +} + +_SOKOL_PRIVATE void _sg_vk_staging_copy_image_data(_sg_image_t* img, const sg_image_data* src_data, bool initial_wait) { + SOKOL_ASSERT(_sg.vk.dev); + SOKOL_ASSERT(_sg.vk.queue); + SOKOL_ASSERT(_sg.vk.stage.copy.mem); + SOKOL_ASSERT(_sg.vk.stage.copy.buf); + SOKOL_ASSERT(img && img->vk.img); + const uint32_t block_dim = (uint32_t)_sg_block_dim(img->cmn.pixel_format); + + // an inital wait is only needed for updating existing resources but not when populating a new resource + if (initial_wait) { + VkResult res = vkQueueWaitIdle(_sg.vk.queue); + SOKOL_ASSERT(res == VK_SUCCESS); _SOKOL_UNUSED(res); + } + + VkDeviceMemory mem = _sg.vk.stage.copy.mem; + _SG_STRUCT(VkBufferImageCopy2, region); + _SG_STRUCT(VkCopyBufferToImageInfo2, copy_info); + _sg_vk_init_vk_image_staging_structs(img, _sg.vk.stage.copy.buf, ®ion, ©_info); + for (int mip_index = 0; mip_index < img->cmn.num_mipmaps; mip_index++) { + const uint8_t* src_ptr = (uint8_t*)src_data->mip_levels[mip_index].ptr; + int mip_width = _sg_miplevel_dim(img->cmn.width, mip_index); + int mip_height = _sg_miplevel_dim(img->cmn.height, mip_index); + int mip_slices = (img->cmn.type == SG_IMAGETYPE_3D) ? _sg_miplevel_dim(img->cmn.num_slices, mip_index) : img->cmn.num_slices; + const uint32_t row_pitch = (uint32_t) _sg_row_pitch(img->cmn.pixel_format, mip_width, 1); + const uint32_t num_rows = (uint32_t) _sg_num_rows(img->cmn.pixel_format, mip_height); + region.imageSubresource.mipLevel = (uint32_t)mip_index; + region.imageExtent.width = (uint32_t)mip_width; + + const uint32_t max_rows = _sg.vk.stage.copy.size / row_pitch; + for (int slice_index = 0; slice_index < mip_slices; slice_index++) { + if (img->cmn.type == SG_IMAGETYPE_3D) { + region.imageOffset.z = slice_index; + } else { + region.imageSubresource.baseArrayLayer = (uint32_t)slice_index; + } + uint32_t rows_remaining = num_rows; + uint32_t cur_row = 0; + while (rows_remaining > 0) { + uint32_t rows_to_copy = rows_remaining; + if (rows_remaining > max_rows) { + rows_to_copy = max_rows; + rows_remaining -= max_rows; + } else { + rows_to_copy = rows_remaining; + rows_remaining = 0; + } + const uint32_t bytes_to_copy = rows_to_copy * row_pitch; + SOKOL_ASSERT(bytes_to_copy <= _sg.vk.stage.copy.size); + _sg_vk_staging_map_memcpy_unmap(mem, src_ptr, bytes_to_copy); + src_ptr += bytes_to_copy; + VkCommandBuffer cmd_buf = _sg_vk_staging_copy_begin(); + _sg_vk_image_barrier(cmd_buf, img, _SG_VK_ACCESS_STAGING); + region.imageOffset.y = (int32_t)(cur_row * block_dim); + region.imageExtent.height = _sg_min((uint32_t)mip_height, rows_to_copy * block_dim); + vkCmdCopyBufferToImage2(cmd_buf, ©_info); + _sg_stats_inc(vk.num_cmd_copy_buffer_to_image); + _sg_vk_image_barrier(cmd_buf, img, _SG_VK_ACCESS_TEXTURE); + + _sg_vk_staging_copy_end(cmd_buf, _sg.vk.queue); + cur_row += rows_to_copy; + } + } + } +} + +// staging system for non-blocking streaming updates with a max per-frame data limit +_SOKOL_PRIVATE void _sg_vk_staging_stream_init(void) { + SOKOL_ASSERT(_sg.desc.vulkan.stream_staging_buffer_size > 0); + _sg_vk_shared_buffer_init(&_sg.vk.stage.stream, + (uint32_t)_sg.desc.vulkan.stream_staging_buffer_size, + 16, // NOTE: arbitrary alignment (FIXME?) + _SG_VK_MEMTYPE_STAGING_STREAM, + "shared-stream-buffer"); +} + +_SOKOL_PRIVATE void _sg_vk_staging_stream_discard(void) { + _sg_vk_shared_buffer_discard(&_sg.vk.stage.stream); +} + +_SOKOL_PRIVATE void _sg_vk_staging_stream_after_acquire(void) { + _sg_vk_shared_buffer_after_acquire(&_sg.vk.stage.stream); +} + +_SOKOL_PRIVATE void _sg_vk_staging_stream_before_submit(void) { + _sg_vk_shared_buffer_before_submit(&_sg.vk.stage.stream); +} + +_SOKOL_PRIVATE void _sg_vk_staging_stream_buffer_data(_sg_buffer_t* buf, const sg_range* src_data, size_t dst_offset) { + SOKOL_ASSERT(_sg.vk.dev); + SOKOL_ASSERT(_sg.vk.frame.stream_cmd_buf); + SOKOL_ASSERT(_sg.vk.stage.stream.cur_buf); + SOKOL_ASSERT(buf && buf->vk.buf); + SOKOL_ASSERT(src_data && src_data->ptr && (src_data->size > 0)); + SOKOL_ASSERT((src_data->size + dst_offset) <= (size_t)buf->cmn.size); + + const uint32_t src_offset = (uint32_t)_sg_vk_shared_buffer_memcpy(&_sg.vk.stage.stream, src_data->ptr, (uint32_t)src_data->size); + if (src_offset == _SG_VK_SHARED_BUFFER_OVERFLOW_RESULT) { + _SG_ERROR(VULKAN_STAGING_STREAM_BUFFER_OVERFLOW); + return; + } + VkCommandBuffer cmd_buf = _sg.vk.frame.stream_cmd_buf; + VkBuffer vk_src_buf = _sg.vk.stage.stream.cur_buf; + VkBuffer vk_dst_buf = buf->vk.buf; + _SG_STRUCT(VkBufferCopy, region); + region.srcOffset = src_offset; + region.dstOffset = dst_offset; + region.size = src_data->size; + _sg_vk_buffer_barrier(cmd_buf, buf, _SG_VK_ACCESS_STAGING); + vkCmdCopyBuffer(cmd_buf, vk_src_buf, vk_dst_buf, 1, ®ion); + _sg_stats_inc(vk.num_cmd_copy_buffer); + // FIXME: not great to issue a barrier right here, + // rethink buffer barrier strategy? => a single memory barrier + // at the end of the stream command buffer should be sufficient? + _sg_vk_buffer_barrier(cmd_buf, buf, _SG_VK_ACCESS_VERTEXBUFFER|_SG_VK_ACCESS_INDEXBUFFER|_SG_VK_ACCESS_STORAGEBUFFER_RO); +} + +_SOKOL_PRIVATE void _sg_vk_staging_stream_image_data(_sg_image_t* img, const sg_image_data* src_data) { + SOKOL_ASSERT(_sg.vk.dev); + SOKOL_ASSERT(_sg.vk.frame.stream_cmd_buf); + SOKOL_ASSERT(img && img->vk.img); + SOKOL_ASSERT(src_data); + VkCommandBuffer cmd_buf = _sg.vk.frame.stream_cmd_buf; + _sg_vk_image_barrier(cmd_buf, img, _SG_VK_ACCESS_STAGING); + _SG_STRUCT(VkBufferImageCopy2, region); + _SG_STRUCT(VkCopyBufferToImageInfo2, copy_info); + _sg_vk_init_vk_image_staging_structs(img, _sg.vk.stage.stream.cur_buf, ®ion, ©_info); + for (int mip_index = 0; mip_index < img->cmn.num_mipmaps; mip_index++) { + const sg_range* src_mip = &src_data->mip_levels[mip_index]; + SOKOL_ASSERT(src_mip->ptr); + SOKOL_ASSERT(src_mip->size > 0); + const uint32_t src_offset = (uint32_t)_sg_vk_shared_buffer_memcpy(&_sg.vk.stage.stream, src_mip->ptr, (uint32_t)src_mip->size); + if (src_offset == _SG_VK_SHARED_BUFFER_OVERFLOW_RESULT) { + _SG_ERROR(VULKAN_STAGING_STREAM_BUFFER_OVERFLOW); + _sg_vk_image_barrier(cmd_buf, img, _SG_VK_ACCESS_TEXTURE); + return; + } + region.bufferOffset = src_offset; + int mip_width = _sg_miplevel_dim(img->cmn.width, mip_index); + int mip_height = _sg_miplevel_dim(img->cmn.height, mip_index); + int mip_slices = (img->cmn.type == SG_IMAGETYPE_3D) ? _sg_miplevel_dim(img->cmn.num_slices, mip_index) : img->cmn.num_slices; + region.imageExtent.width = (uint32_t)mip_width; + region.imageExtent.height = (uint32_t)mip_height; + region.imageSubresource.mipLevel = (uint32_t)mip_index; + if (img->cmn.type == SG_IMAGETYPE_3D) { + region.imageExtent.depth = (uint32_t)mip_slices; + region.imageSubresource.layerCount = 1; + } else { + region.imageExtent.depth = 1; + region.imageSubresource.layerCount = (uint32_t)mip_slices; + } + vkCmdCopyBufferToImage2(cmd_buf, ©_info); + _sg_stats_inc(vk.num_cmd_copy_buffer_to_image); + } + _sg_vk_image_barrier(cmd_buf, img, _SG_VK_ACCESS_TEXTURE); +} + +// uniform data system +_SOKOL_PRIVATE void _sg_vk_uniform_init(void) { + SOKOL_ASSERT(_sg.desc.uniform_buffer_size > 0); + SOKOL_ASSERT(0 == _sg.vk.uniforms.dset_cache); + + _sg_vk_shared_buffer_init(&_sg.vk.uniforms.dbuf, + (uint32_t)_sg.desc.uniform_buffer_size, + (uint32_t)_sg.vk.dev_props.properties.limits.minUniformBufferOffsetAlignment, + _SG_VK_MEMTYPE_UNIFORMS, + "shared-uniform-buffer"); + + for (size_t i = 0; i < SG_MAX_UNIFORMBLOCK_BINDSLOTS; i++) { + _sg.vk.uniforms.addr_info[i].sType = VK_STRUCTURE_TYPE_DESCRIPTOR_ADDRESS_INFO_EXT; + _sg.vk.uniforms.get_info[i].sType = VK_STRUCTURE_TYPE_DESCRIPTOR_GET_INFO_EXT; + _sg.vk.uniforms.get_info[i].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + _sg.vk.uniforms.get_info[i].data.pUniformBuffer = &_sg.vk.uniforms.addr_info[i]; + } + + // NOTE: we assume here that the max alignment for uniform buffer + // descriptors in the descriptor buffer is the same as the assumed max + // descriptor size (e.g. 256 bytes) + _sg.vk.uniforms.dset_cache_size = SG_MAX_UNIFORMBLOCK_BINDSLOTS * _SG_VK_MAX_DESCRIPTOR_DATA_SIZE; + _sg.vk.uniforms.dset_cache = (uint8_t*)_sg_malloc_clear(_sg.vk.uniforms.dset_cache_size); +} + +_SOKOL_PRIVATE void _sg_vk_uniform_discard(void) { + SOKOL_ASSERT(_sg.vk.uniforms.dset_cache); + _sg_free(_sg.vk.uniforms.dset_cache); _sg.vk.uniforms.dset_cache = 0; + _sg_vk_shared_buffer_discard(&_sg.vk.uniforms.dbuf); +} + +// called from _sg_vk_acquire_frame_command_buffer() +_SOKOL_PRIVATE void _sg_vk_uniform_after_acquire(void) { + _sg_vk_shared_buffer_after_acquire(&_sg.vk.uniforms.dbuf); + // reset uniform tracking data + for (size_t i = 0; i < SG_MAX_UNIFORMBLOCK_BINDSLOTS; i++) { + _sg.vk.uniforms.addr_info[i].address = 0; + _sg.vk.uniforms.addr_info[i].range = 0; + } +} + +// called from _sg_vk_submit_frame_command_buffer() +_SOKOL_PRIVATE void _sg_vk_uniform_before_submit(void) { + _sg_vk_shared_buffer_before_submit(&_sg.vk.uniforms.dbuf); +} + +// called form _sg_vk_apply_uniforms, returns offset of data snippet into uniform buffer +_SOKOL_PRIVATE uint32_t _sg_vk_uniform_copy(const sg_range* data) { + SOKOL_ASSERT(data && data->ptr && (data->size > 0)); + return (uint32_t)_sg_vk_shared_buffer_memcpy(&_sg.vk.uniforms.dbuf, data->ptr, (uint32_t)data->size); +} + +// resource binding system +_SOKOL_PRIVATE void _sg_vk_bind_init(void) { + SOKOL_ASSERT(_sg.desc.vulkan.descriptor_buffer_size > 0); + _sg_vk_shared_buffer_init(&_sg.vk.bind, + (uint32_t)_sg.desc.vulkan.descriptor_buffer_size, + (uint32_t)_sg.vk.descriptor_buffer_props.descriptorBufferOffsetAlignment, + _SG_VK_MEMTYPE_DESCRIPTORS, + "shared-descriptor-buffer"); +} + +_SOKOL_PRIVATE void _sg_vk_bind_discard(void) { + _sg_vk_shared_buffer_discard(&_sg.vk.bind); +} + +// called from _sg_vk_acquire_frame_command_buffer() +_SOKOL_PRIVATE void _sg_vk_bind_after_acquire(void) { + _sg_vk_shared_buffer_after_acquire(&_sg.vk.bind); + + // bind the current frame's descriptor buffer + SOKOL_ASSERT(_sg.vk.frame.cmd_buf); + SOKOL_ASSERT(_sg.vk.bind.cur_buf); + SOKOL_ASSERT(_sg.vk.bind.cur_dev_addr); + _SG_STRUCT(VkDescriptorBufferBindingInfoEXT, bind_info); + bind_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_BUFFER_BINDING_INFO_EXT; + bind_info.address = _sg.vk.bind.cur_dev_addr; + bind_info.usage = VK_BUFFER_USAGE_RESOURCE_DESCRIPTOR_BUFFER_BIT_EXT | + VK_BUFFER_USAGE_SAMPLER_DESCRIPTOR_BUFFER_BIT_EXT; + _sg.vk.ext.cmd_bind_descriptor_buffers(_sg.vk.frame.cmd_buf, 1, &bind_info); +} + +// called from _sg_vk_submit_frame_command_buffer() +_SOKOL_PRIVATE void _sg_vk_bind_before_submit(void) { + _sg_vk_shared_buffer_before_submit(&_sg.vk.bind); +} + +_SOKOL_PRIVATE bool _sg_vk_bind_view_smp_descriptor_set(VkCommandBuffer cmd_buf, const _sg_bindings_ptrs_t* bnd, VkPipelineBindPoint vk_bind_point) { + SOKOL_ASSERT(_sg.vk.dev); + SOKOL_ASSERT(cmd_buf); + SOKOL_ASSERT(bnd && bnd->pip); + const _sg_shader_t* shd = _sg_shader_ref_ptr(&bnd->pip->cmn.shader); + + // get next pointer in descriptor buffer + const VkDeviceSize dset_size = shd->vk.view_smp_dset_size; + if (dset_size == 0) { + // nothing to bind + return true; + } + const VkDeviceSize dbuf_offset = _sg_vk_shared_buffer_alloc(&_sg.vk.bind, (uint32_t)dset_size); + if (_sg.vk.bind.overflown) { + _SG_ERROR(VULKAN_DESCRIPTOR_BUFFER_OVERFLOW); + return false; + } + _sg_stats_add(vk.size_descriptor_buffer_writes, (uint32_t)dset_size); + uint8_t* dbuf_ptr = _sg_vk_shared_buffer_ptr(&_sg.vk.bind, dbuf_offset); + + // copy pre-recorded descriptor data into descriptor buffer + for (size_t i = 0; i < SG_MAX_VIEW_BINDSLOTS; i++) { + if (shd->cmn.views[i].stage == SG_SHADERSTAGE_NONE) { + continue; + } + const _sg_view_t* view = bnd->views[i]; + SOKOL_ASSERT(view && (view->vk.descriptor_size > 0)); + const void* src_ptr = view->vk.descriptor_data; + size_t size = view->vk.descriptor_size; + void* dst_ptr = dbuf_ptr + shd->vk.view_dset_offsets[i]; + memcpy(dst_ptr, src_ptr, size); + } + for (size_t i = 0; i < SG_MAX_SAMPLER_BINDSLOTS; i++) { + if (shd->cmn.samplers[i].stage == SG_SHADERSTAGE_NONE) { + continue; + } + const _sg_sampler_t* smp = bnd->smps[i]; + SOKOL_ASSERT(smp && (smp->vk.descriptor_size > 0)); + const void* src_ptr = smp->vk.descriptor_data; + size_t size = smp->vk.descriptor_size; + void* dst_ptr = dbuf_ptr + shd->vk.smp_dset_offsets[i]; + memcpy(dst_ptr, src_ptr, size); + } + + // record the new descriptor buffer offset + const uint32_t dbuf_index = 0; + SOKOL_ASSERT(shd->vk.pip_layout); + _sg.vk.ext.cmd_set_descriptor_buffer_offsets( + cmd_buf, + vk_bind_point, + shd->vk.pip_layout, + _SG_VK_VIEW_SMP_DESCRIPTORSET_INDEX, // firstSet + 1, // setCount + &dbuf_index, + &dbuf_offset); + _sg_stats_inc(vk.num_cmd_set_descriptor_buffer_offsets); + return true; +} + +_SOKOL_PRIVATE bool _sg_vk_bind_uniform_descriptor_set(VkCommandBuffer cmd_buf) { + SOKOL_ASSERT(cmd_buf); + SOKOL_ASSERT(_sg.vk.uniforms.dirty); + _sg.vk.uniforms.dirty = false; + const _sg_pipeline_t* pip = _sg_pipeline_ref_ptr(&_sg.cur_pip); + const _sg_shader_t* shd = _sg_shader_ref_ptr(&pip->cmn.shader); + + // get next pointer in descriptor buffer + const VkDeviceSize dbuf_offset = _sg_vk_shared_buffer_alloc(&_sg.vk.bind, (uint32_t)shd->vk.ub_dset_size); + if (_sg.vk.bind.overflown) { + _SG_ERROR(VULKAN_DESCRIPTOR_BUFFER_OVERFLOW); + return false; + } + _sg_stats_add(vk.size_descriptor_buffer_writes, (uint32_t)shd->vk.ub_dset_size); + uint8_t* dbuf_ptr = _sg_vk_shared_buffer_ptr(&_sg.vk.bind, dbuf_offset); + + // update descriptor buffer + SOKOL_ASSERT(shd->vk.ub_dset_size <= _sg.vk.uniforms.dset_cache_size); + memcpy(dbuf_ptr, _sg.vk.uniforms.dset_cache, shd->vk.ub_dset_size); + + // record the descriptor buffer offset + const VkPipelineBindPoint vk_bind_point = _sg.cur_pass.is_compute + ? VK_PIPELINE_BIND_POINT_COMPUTE + : VK_PIPELINE_BIND_POINT_GRAPHICS; + const uint32_t dbuf_index = 0; + SOKOL_ASSERT(shd->vk.pip_layout); + _sg.vk.ext.cmd_set_descriptor_buffer_offsets( + cmd_buf, + vk_bind_point, + shd->vk.pip_layout, + _SG_VK_UB_DESCRIPTORSET_INDEX, // firstIndex + 1, // setCount + &dbuf_index, + &dbuf_offset); + _sg_stats_inc(vk.num_cmd_set_descriptor_buffer_offsets); + return true; +} + +_SOKOL_PRIVATE void _sg_vk_memory_destructor(void* obj) { + SOKOL_ASSERT(_sg.vk.dev && obj); + _sg_vk_mem_free_device_memory((VkDeviceMemory)obj); +} + +_SOKOL_PRIVATE void _sg_vk_buffer_destructor(void* obj) { + SOKOL_ASSERT(_sg.vk.dev && obj); + vkDestroyBuffer(_sg.vk.dev, (VkBuffer)obj, 0); +} + +_SOKOL_PRIVATE void _sg_vk_image_destructor(void* obj) { + SOKOL_ASSERT(_sg.vk.dev && obj); + vkDestroyImage(_sg.vk.dev, (VkImage)obj, 0); +} + +_SOKOL_PRIVATE void _sg_vk_image_view_destructor(void* obj) { + SOKOL_ASSERT(_sg.vk.dev && obj); + vkDestroyImageView(_sg.vk.dev, (VkImageView)obj, 0); +} + +_SOKOL_PRIVATE void _sg_vk_sampler_destructor(void* obj) { + SOKOL_ASSERT(_sg.vk.dev && obj); + vkDestroySampler(_sg.vk.dev, (VkSampler)obj, 0); +} + +_SOKOL_PRIVATE void _sg_vk_shader_module_destructor(void* obj) { + SOKOL_ASSERT(_sg.vk.dev && obj); + vkDestroyShaderModule(_sg.vk.dev, (VkShaderModule)obj, 0); +} + +_SOKOL_PRIVATE void _sg_vk_pipelinelayout_destructor(void* obj) { + SOKOL_ASSERT(_sg.vk.dev && obj); + vkDestroyPipelineLayout(_sg.vk.dev, (VkPipelineLayout)obj, 0); +} + +_SOKOL_PRIVATE void _sg_vk_descriptorsetlayout_destructor(void* obj) { + SOKOL_ASSERT(_sg.vk.dev && obj); + vkDestroyDescriptorSetLayout(_sg.vk.dev, (VkDescriptorSetLayout)obj, 0); +} + +_SOKOL_PRIVATE void _sg_vk_pipeline_destructor(void* obj) { + SOKOL_ASSERT(_sg.vk.dev && obj); + vkDestroyPipeline(_sg.vk.dev, (VkPipeline)obj, 0); +} + +_SOKOL_PRIVATE VkBufferUsageFlags _sg_vk_buffer_usage(const sg_buffer_usage* usg) { + VkBufferUsageFlags res = VK_BUFFER_USAGE_TRANSFER_DST_BIT; + if (usg->vertex_buffer) { + res |= VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; + } + if (usg->index_buffer) { + res |= VK_BUFFER_USAGE_INDEX_BUFFER_BIT; + } + if (usg->storage_buffer) { + res |= VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT; + } + return res; +} + +_SOKOL_PRIVATE VkVertexInputRate _sg_vk_vertex_input_rate(sg_vertex_step s) { + return (s == SG_VERTEXSTEP_PER_VERTEX) ? VK_VERTEX_INPUT_RATE_VERTEX : VK_VERTEX_INPUT_RATE_INSTANCE; +} + +_SOKOL_PRIVATE VkFormat _sg_vk_vertex_format(sg_vertex_format f) { + switch (f) { + case SG_VERTEXFORMAT_FLOAT: return VK_FORMAT_R32_SFLOAT; + case SG_VERTEXFORMAT_FLOAT2: return VK_FORMAT_R32G32_SFLOAT; + case SG_VERTEXFORMAT_FLOAT3: return VK_FORMAT_R32G32B32_SFLOAT; + case SG_VERTEXFORMAT_FLOAT4: return VK_FORMAT_R32G32B32A32_SFLOAT; + case SG_VERTEXFORMAT_INT: return VK_FORMAT_R32_SINT; + case SG_VERTEXFORMAT_INT2: return VK_FORMAT_R32G32_SINT; + case SG_VERTEXFORMAT_INT3: return VK_FORMAT_R32G32B32_SINT; + case SG_VERTEXFORMAT_INT4: return VK_FORMAT_R32G32B32A32_SINT; + case SG_VERTEXFORMAT_UINT: return VK_FORMAT_R32_UINT; + case SG_VERTEXFORMAT_UINT2: return VK_FORMAT_R32G32_UINT; + case SG_VERTEXFORMAT_UINT3: return VK_FORMAT_R32G32B32_UINT; + case SG_VERTEXFORMAT_UINT4: return VK_FORMAT_R32G32B32A32_UINT; + case SG_VERTEXFORMAT_BYTE4: return VK_FORMAT_R8G8B8A8_SINT; + case SG_VERTEXFORMAT_BYTE4N: return VK_FORMAT_R8G8B8A8_SNORM; + case SG_VERTEXFORMAT_UBYTE4: return VK_FORMAT_R8G8B8A8_UINT; + case SG_VERTEXFORMAT_UBYTE4N: return VK_FORMAT_R8G8B8A8_UNORM; + case SG_VERTEXFORMAT_SHORT2: return VK_FORMAT_R16G16_SINT; + case SG_VERTEXFORMAT_SHORT2N: return VK_FORMAT_R16G16_SNORM; + case SG_VERTEXFORMAT_USHORT2: return VK_FORMAT_R16G16_UINT; + case SG_VERTEXFORMAT_USHORT2N: return VK_FORMAT_R16G16_UNORM; + case SG_VERTEXFORMAT_SHORT4: return VK_FORMAT_R16G16B16A16_SINT; + case SG_VERTEXFORMAT_SHORT4N: return VK_FORMAT_R16G16B16A16_SNORM; + case SG_VERTEXFORMAT_USHORT4: return VK_FORMAT_R16G16B16A16_UINT; + case SG_VERTEXFORMAT_USHORT4N: return VK_FORMAT_R16G16B16A16_UNORM; + case SG_VERTEXFORMAT_INT10_N2: return VK_FORMAT_A2B10G10R10_SNORM_PACK32; + case SG_VERTEXFORMAT_UINT10_N2: return VK_FORMAT_A2B10G10R10_UNORM_PACK32; + case SG_VERTEXFORMAT_HALF2: return VK_FORMAT_R16G16_SFLOAT; + case SG_VERTEXFORMAT_HALF4: return VK_FORMAT_R16G16B16A16_SFLOAT; + default: + SOKOL_UNREACHABLE; + return VK_FORMAT_UNDEFINED; + } +} + +_SOKOL_PRIVATE VkImageCreateFlags _sg_vk_image_create_flags(sg_image_type t) { + switch (t) { + case SG_IMAGETYPE_2D: return 0; + case SG_IMAGETYPE_CUBE: return VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT; + // FIXME: VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT needed for render to slice? + case SG_IMAGETYPE_3D: return 0; + case SG_IMAGETYPE_ARRAY: return 0; + default: + SOKOL_UNREACHABLE; + return 0; + } +} + +_SOKOL_PRIVATE VkImageType _sg_vk_image_type(sg_image_type t) { + return (SG_IMAGETYPE_3D == t) ? VK_IMAGE_TYPE_3D : VK_IMAGE_TYPE_2D; +} + +_SOKOL_PRIVATE VkImageUsageFlags _sg_vk_image_usage(const sg_image_usage* usg) { + VkImageUsageFlags res = VK_IMAGE_USAGE_TRANSFER_DST_BIT; + res |= VK_IMAGE_USAGE_SAMPLED_BIT; + if (usg->storage_image) { + res |= VK_IMAGE_USAGE_STORAGE_BIT; + } + if (usg->color_attachment || usg->resolve_attachment) { + res |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + } + if (usg->depth_stencil_attachment) { + res |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; + } + return res; +} + +_SOKOL_PRIVATE VkFormat _sg_vk_format(sg_pixel_format fmt) { + switch (fmt) { + case SG_PIXELFORMAT_NONE: return VK_FORMAT_UNDEFINED; + case SG_PIXELFORMAT_R8: return VK_FORMAT_R8_UNORM; + case SG_PIXELFORMAT_R8SN: return VK_FORMAT_R8_SNORM; + case SG_PIXELFORMAT_R8UI: return VK_FORMAT_R8_UINT; + case SG_PIXELFORMAT_R8SI: return VK_FORMAT_R8_SINT; + case SG_PIXELFORMAT_R16: return VK_FORMAT_R16_UNORM; + case SG_PIXELFORMAT_R16SN: return VK_FORMAT_R16_SNORM; + case SG_PIXELFORMAT_R16UI: return VK_FORMAT_R16_UINT; + case SG_PIXELFORMAT_R16SI: return VK_FORMAT_R16_SINT; + case SG_PIXELFORMAT_R16F: return VK_FORMAT_R16_SFLOAT; + case SG_PIXELFORMAT_RG8: return VK_FORMAT_R8G8_UNORM; + case SG_PIXELFORMAT_RG8SN: return VK_FORMAT_R8G8_SNORM; + case SG_PIXELFORMAT_RG8UI: return VK_FORMAT_R8G8_UINT; + case SG_PIXELFORMAT_RG8SI: return VK_FORMAT_R8G8_SINT; + case SG_PIXELFORMAT_R32UI: return VK_FORMAT_R32_UINT; + case SG_PIXELFORMAT_R32SI: return VK_FORMAT_R32_SINT; + case SG_PIXELFORMAT_R32F: return VK_FORMAT_R32_SFLOAT; + case SG_PIXELFORMAT_RG16: return VK_FORMAT_R16G16_UNORM; + case SG_PIXELFORMAT_RG16SN: return VK_FORMAT_R16G16_SNORM; + case SG_PIXELFORMAT_RG16UI: return VK_FORMAT_R16G16_UINT; + case SG_PIXELFORMAT_RG16SI: return VK_FORMAT_R16G16_SINT; + case SG_PIXELFORMAT_RG16F: return VK_FORMAT_R16G16_SFLOAT; + case SG_PIXELFORMAT_RGBA8: return VK_FORMAT_R8G8B8A8_UNORM; + case SG_PIXELFORMAT_SRGB8A8: return VK_FORMAT_R8G8B8A8_SRGB; + case SG_PIXELFORMAT_RGBA8SN: return VK_FORMAT_R8G8B8A8_SNORM; + case SG_PIXELFORMAT_RGBA8UI: return VK_FORMAT_R8G8B8A8_UINT; + case SG_PIXELFORMAT_RGBA8SI: return VK_FORMAT_R8G8B8A8_SINT; + case SG_PIXELFORMAT_BGRA8: return VK_FORMAT_B8G8R8A8_UNORM; + case SG_PIXELFORMAT_RGB10A2: return VK_FORMAT_A2R10G10B10_UNORM_PACK32; + case SG_PIXELFORMAT_RG11B10F: return VK_FORMAT_B10G11R11_UFLOAT_PACK32; + case SG_PIXELFORMAT_RGB9E5: return VK_FORMAT_E5B9G9R9_UFLOAT_PACK32; + case SG_PIXELFORMAT_RG32UI: return VK_FORMAT_R32G32_UINT; + case SG_PIXELFORMAT_RG32SI: return VK_FORMAT_R32G32_SINT; + case SG_PIXELFORMAT_RG32F: return VK_FORMAT_R32G32_SFLOAT; + case SG_PIXELFORMAT_RGBA16: return VK_FORMAT_R16G16B16A16_UNORM; + case SG_PIXELFORMAT_RGBA16SN: return VK_FORMAT_R16G16B16A16_SNORM; + case SG_PIXELFORMAT_RGBA16UI: return VK_FORMAT_R16G16B16A16_UINT; + case SG_PIXELFORMAT_RGBA16SI: return VK_FORMAT_R16G16B16A16_SINT; + case SG_PIXELFORMAT_RGBA16F: return VK_FORMAT_R16G16B16A16_SFLOAT; + case SG_PIXELFORMAT_RGBA32UI: return VK_FORMAT_R32G32B32A32_UINT; + case SG_PIXELFORMAT_RGBA32SI: return VK_FORMAT_R32G32B32A32_SINT; + case SG_PIXELFORMAT_RGBA32F: return VK_FORMAT_R32G32B32A32_SFLOAT; + case SG_PIXELFORMAT_DEPTH: return VK_FORMAT_D32_SFLOAT; + case SG_PIXELFORMAT_DEPTH_STENCIL: return VK_FORMAT_D32_SFLOAT_S8_UINT; + case SG_PIXELFORMAT_BC1_RGBA: return VK_FORMAT_BC1_RGBA_UNORM_BLOCK; + case SG_PIXELFORMAT_BC2_RGBA: return VK_FORMAT_BC2_UNORM_BLOCK; + case SG_PIXELFORMAT_BC3_RGBA: return VK_FORMAT_BC3_UNORM_BLOCK; + case SG_PIXELFORMAT_BC3_SRGBA: return VK_FORMAT_BC3_SRGB_BLOCK; + case SG_PIXELFORMAT_BC4_R: return VK_FORMAT_BC4_UNORM_BLOCK; + case SG_PIXELFORMAT_BC4_RSN: return VK_FORMAT_BC4_SNORM_BLOCK; + case SG_PIXELFORMAT_BC5_RG: return VK_FORMAT_BC5_UNORM_BLOCK; + case SG_PIXELFORMAT_BC5_RGSN: return VK_FORMAT_BC5_SNORM_BLOCK; + case SG_PIXELFORMAT_BC6H_RGBF: return VK_FORMAT_BC6H_SFLOAT_BLOCK; + case SG_PIXELFORMAT_BC6H_RGBUF: return VK_FORMAT_BC6H_UFLOAT_BLOCK; + case SG_PIXELFORMAT_BC7_RGBA: return VK_FORMAT_BC7_UNORM_BLOCK; + case SG_PIXELFORMAT_BC7_SRGBA: return VK_FORMAT_BC7_SRGB_BLOCK; + case SG_PIXELFORMAT_ETC2_RGB8: return VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK; + case SG_PIXELFORMAT_ETC2_RGB8A1: return VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK; + case SG_PIXELFORMAT_ETC2_RGBA8: return VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK; + case SG_PIXELFORMAT_ETC2_SRGB8: return VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK; + case SG_PIXELFORMAT_ETC2_SRGB8A8: return VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK; + case SG_PIXELFORMAT_EAC_R11: return VK_FORMAT_EAC_R11_UNORM_BLOCK; + case SG_PIXELFORMAT_EAC_R11SN: return VK_FORMAT_EAC_R11_SNORM_BLOCK; + case SG_PIXELFORMAT_EAC_RG11: return VK_FORMAT_EAC_R11G11_UNORM_BLOCK; + case SG_PIXELFORMAT_EAC_RG11SN: return VK_FORMAT_EAC_R11G11_SNORM_BLOCK; + case SG_PIXELFORMAT_ASTC_4x4_RGBA: return VK_FORMAT_ASTC_4x4_UNORM_BLOCK; + case SG_PIXELFORMAT_ASTC_4x4_SRGBA: return VK_FORMAT_ASTC_4x4_SRGB_BLOCK; + default: return VK_FORMAT_UNDEFINED; + }; +} + +_SOKOL_PRIVATE VkPrimitiveTopology _sg_vk_primitive_topology(sg_primitive_type t) { + switch (t) { + case SG_PRIMITIVETYPE_POINTS: return VK_PRIMITIVE_TOPOLOGY_POINT_LIST; + case SG_PRIMITIVETYPE_LINES: return VK_PRIMITIVE_TOPOLOGY_LINE_LIST; + case SG_PRIMITIVETYPE_LINE_STRIP: return VK_PRIMITIVE_TOPOLOGY_LINE_STRIP; + case SG_PRIMITIVETYPE_TRIANGLES: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + case SG_PRIMITIVETYPE_TRIANGLE_STRIP: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; + default: + SOKOL_UNREACHABLE; + return VK_PRIMITIVE_TOPOLOGY_MAX_ENUM; + } +} + +_SOKOL_PRIVATE VkCullModeFlags _sg_vk_cullmode(sg_cull_mode cm) { + switch (cm) { + case SG_CULLMODE_NONE: return VK_CULL_MODE_NONE; + case SG_CULLMODE_FRONT: return VK_CULL_MODE_FRONT_BIT; + case SG_CULLMODE_BACK: return VK_CULL_MODE_BACK_BIT; + default: + SOKOL_UNREACHABLE; + return VK_CULL_MODE_NONE; + } +} + +_SOKOL_PRIVATE VkFrontFace _sg_vk_frontface(sg_face_winding fw) { + return (fw == SG_FACEWINDING_CCW) ? VK_FRONT_FACE_COUNTER_CLOCKWISE : VK_FRONT_FACE_CLOCKWISE; +} + +_SOKOL_PRIVATE VkCompareOp _sg_vk_compare_op(sg_compare_func f) { + switch (f) { + case SG_COMPAREFUNC_NEVER: return VK_COMPARE_OP_NEVER; + case SG_COMPAREFUNC_LESS: return VK_COMPARE_OP_LESS; + case SG_COMPAREFUNC_EQUAL: return VK_COMPARE_OP_EQUAL; + case SG_COMPAREFUNC_LESS_EQUAL: return VK_COMPARE_OP_LESS_OR_EQUAL; + case SG_COMPAREFUNC_GREATER: return VK_COMPARE_OP_GREATER; + case SG_COMPAREFUNC_NOT_EQUAL: return VK_COMPARE_OP_NOT_EQUAL; + case SG_COMPAREFUNC_GREATER_EQUAL: return VK_COMPARE_OP_GREATER_OR_EQUAL; + case SG_COMPAREFUNC_ALWAYS: return VK_COMPARE_OP_ALWAYS; + default: + SOKOL_UNREACHABLE; + return VK_COMPARE_OP_ALWAYS; + } +} + +_SOKOL_PRIVATE VkStencilOp _sg_vk_stencil_op(sg_stencil_op op) { + switch (op) { + case SG_STENCILOP_KEEP: return VK_STENCIL_OP_KEEP; + case SG_STENCILOP_ZERO: return VK_STENCIL_OP_ZERO; + case SG_STENCILOP_REPLACE: return VK_STENCIL_OP_REPLACE; + case SG_STENCILOP_INCR_CLAMP: return VK_STENCIL_OP_INCREMENT_AND_CLAMP; + case SG_STENCILOP_DECR_CLAMP: return VK_STENCIL_OP_DECREMENT_AND_CLAMP; + case SG_STENCILOP_INVERT: return VK_STENCIL_OP_INVERT; + case SG_STENCILOP_INCR_WRAP: return VK_STENCIL_OP_INCREMENT_AND_WRAP; + case SG_STENCILOP_DECR_WRAP: return VK_STENCIL_OP_DECREMENT_AND_WRAP; + default: + SOKOL_UNREACHABLE; + return VK_STENCIL_OP_KEEP; + } +} + +_SOKOL_PRIVATE VkBlendOp _sg_vk_blend_op(sg_blend_op op) { + switch (op) { + case SG_BLENDOP_ADD: return VK_BLEND_OP_ADD; + case SG_BLENDOP_SUBTRACT: return VK_BLEND_OP_SUBTRACT; + case SG_BLENDOP_REVERSE_SUBTRACT: return VK_BLEND_OP_REVERSE_SUBTRACT; + case SG_BLENDOP_MIN: return VK_BLEND_OP_MIN; + case SG_BLENDOP_MAX: return VK_BLEND_OP_MAX; + default: + SOKOL_UNREACHABLE; + return VK_BLEND_OP_ADD; + } +} + +_SOKOL_PRIVATE VkBlendFactor _sg_vk_blend_factor(sg_blend_factor f) { + switch (f) { + case SG_BLENDFACTOR_ZERO: return VK_BLEND_FACTOR_ZERO; + case SG_BLENDFACTOR_ONE: return VK_BLEND_FACTOR_ONE; + case SG_BLENDFACTOR_SRC_COLOR: return VK_BLEND_FACTOR_SRC_COLOR; + case SG_BLENDFACTOR_ONE_MINUS_SRC_COLOR: return VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR; + case SG_BLENDFACTOR_SRC_ALPHA: return VK_BLEND_FACTOR_SRC_ALPHA; + case SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA: return VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; + case SG_BLENDFACTOR_DST_COLOR: return VK_BLEND_FACTOR_DST_COLOR; + case SG_BLENDFACTOR_ONE_MINUS_DST_COLOR: return VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR; + case SG_BLENDFACTOR_DST_ALPHA: return VK_BLEND_FACTOR_DST_ALPHA; + case SG_BLENDFACTOR_ONE_MINUS_DST_ALPHA: return VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA; + case SG_BLENDFACTOR_SRC_ALPHA_SATURATED: return VK_BLEND_FACTOR_SRC_ALPHA_SATURATE; + case SG_BLENDFACTOR_BLEND_COLOR: return VK_BLEND_FACTOR_CONSTANT_COLOR; + case SG_BLENDFACTOR_ONE_MINUS_BLEND_COLOR: return VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR; + case SG_BLENDFACTOR_BLEND_ALPHA: return VK_BLEND_FACTOR_CONSTANT_ALPHA; + case SG_BLENDFACTOR_ONE_MINUS_BLEND_ALPHA: return VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA; + case SG_BLENDFACTOR_SRC1_COLOR: return VK_BLEND_FACTOR_SRC1_COLOR ; + case SG_BLENDFACTOR_ONE_MINUS_SRC1_COLOR: return VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR; + case SG_BLENDFACTOR_SRC1_ALPHA: return VK_BLEND_FACTOR_SRC1_ALPHA; + case SG_BLENDFACTOR_ONE_MINUS_SRC1_ALPHA: return VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA; + default: + SOKOL_UNREACHABLE; + return VK_BLEND_FACTOR_ONE; + } +} + +_SOKOL_PRIVATE VkColorComponentFlags _sg_vk_color_write_mask(sg_color_mask m) { + int res = 0; + if (0 != (m & SG_COLORMASK_R)) { + res |= (int)VK_COLOR_COMPONENT_R_BIT; + } + if (0 != (m & SG_COLORMASK_G)) { + res |= (int)VK_COLOR_COMPONENT_G_BIT; + } + if (0 != (m & SG_COLORMASK_B)) { + res |= (int)VK_COLOR_COMPONENT_B_BIT; + } + if (0 != (m & SG_COLORMASK_A)) { + res |= (int)VK_COLOR_COMPONENT_A_BIT; + } + return (VkColorComponentFlags)res; +} + +_SOKOL_PRIVATE VkShaderStageFlags _sg_vk_shader_stage(sg_shader_stage s) { + switch (s) { + case SG_SHADERSTAGE_VERTEX: return VK_SHADER_STAGE_VERTEX_BIT; + case SG_SHADERSTAGE_FRAGMENT: return VK_SHADER_STAGE_FRAGMENT_BIT; + case SG_SHADERSTAGE_COMPUTE: return VK_SHADER_STAGE_COMPUTE_BIT; + default: SOKOL_UNREACHABLE; return 0; + } +} + +_SOKOL_PRIVATE VkAttachmentLoadOp _sg_vk_load_op(sg_load_action a) { + switch (a) { + case SG_LOADACTION_CLEAR: + return VK_ATTACHMENT_LOAD_OP_CLEAR; + case SG_LOADACTION_DONTCARE: + return VK_ATTACHMENT_LOAD_OP_DONT_CARE; + default: + return VK_ATTACHMENT_LOAD_OP_LOAD; + } +} + +_SOKOL_PRIVATE VkAttachmentStoreOp _sg_vk_store_op(sg_store_action a) { + switch (a) { + case SG_STOREACTION_STORE: + return VK_ATTACHMENT_STORE_OP_STORE; + default: + return VK_ATTACHMENT_STORE_OP_DONT_CARE; + } +} + +_SOKOL_PRIVATE VkIndexType _sg_vk_index_type(sg_index_type t) { + return (t == SG_INDEXTYPE_UINT16) ? VK_INDEX_TYPE_UINT16 : VK_INDEX_TYPE_UINT32; +} + +_SOKOL_PRIVATE VkImageViewType _sg_vk_texture_image_view_type(sg_image_type t) { + switch (t) { + case SG_IMAGETYPE_2D: return VK_IMAGE_VIEW_TYPE_2D; + case SG_IMAGETYPE_CUBE: return VK_IMAGE_VIEW_TYPE_CUBE; + case SG_IMAGETYPE_3D: return VK_IMAGE_VIEW_TYPE_3D; + case SG_IMAGETYPE_ARRAY: return VK_IMAGE_VIEW_TYPE_2D_ARRAY; + default: SOKOL_UNREACHABLE; return VK_IMAGE_VIEW_TYPE_2D; + } +} + +_SOKOL_PRIVATE VkImageViewType _sg_vk_attachment_image_view_type(sg_image_type t) { + switch (t) { + case SG_IMAGETYPE_2D: return VK_IMAGE_VIEW_TYPE_2D; + case SG_IMAGETYPE_CUBE: return VK_IMAGE_VIEW_TYPE_2D_ARRAY; // not a bug + case SG_IMAGETYPE_3D: return VK_IMAGE_VIEW_TYPE_2D; // not a bug + case SG_IMAGETYPE_ARRAY: return VK_IMAGE_VIEW_TYPE_2D_ARRAY; + default: SOKOL_UNREACHABLE; return VK_IMAGE_VIEW_TYPE_2D; + } +} + +_SOKOL_PRIVATE VkFilter _sg_vk_sampler_minmag_filter(sg_filter f) { + switch (f) { + case SG_FILTER_NEAREST: return VK_FILTER_NEAREST; + case SG_FILTER_LINEAR: return VK_FILTER_LINEAR; + default: SOKOL_UNREACHABLE; return VK_FILTER_NEAREST; + } +} + +_SOKOL_PRIVATE VkSamplerMipmapMode _sg_vk_sampler_mipmap_mode(sg_filter f) { + switch (f) { + case SG_FILTER_NEAREST: return VK_SAMPLER_MIPMAP_MODE_NEAREST; + case SG_FILTER_LINEAR: return VK_SAMPLER_MIPMAP_MODE_LINEAR; + default: SOKOL_UNREACHABLE; return VK_SAMPLER_MIPMAP_MODE_NEAREST; + } +} + +_SOKOL_PRIVATE VkSamplerAddressMode _sg_vk_sampler_address_mode(sg_wrap w) { + switch (w) { + case SG_WRAP_REPEAT: return VK_SAMPLER_ADDRESS_MODE_REPEAT; + case SG_WRAP_CLAMP_TO_EDGE: return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; + case SG_WRAP_CLAMP_TO_BORDER: return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER; + case SG_WRAP_MIRRORED_REPEAT: return VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT; + default: SOKOL_UNREACHABLE; return VK_SAMPLER_ADDRESS_MODE_REPEAT; + } +} + +_SOKOL_PRIVATE VkBorderColor _sg_vk_sampler_border_color(sg_border_color c) { + switch (c) { + case SG_BORDERCOLOR_TRANSPARENT_BLACK: return VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK; + case SG_BORDERCOLOR_OPAQUE_BLACK: return VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK; + case SG_BORDERCOLOR_OPAQUE_WHITE: return VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; + default: SOKOL_UNREACHABLE; return VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK; + } +} + +_SOKOL_PRIVATE void _sg_vk_load_ext_funcs(void) { + SOKOL_ASSERT(_sg.vk.dev); + #if defined(SOKOL_DEBUG) + _sg.vk.ext.set_debug_utils_object_name_ext = (PFN_vkSetDebugUtilsObjectNameEXT)vkGetInstanceProcAddr(_sg.vk.instance, "vkSetDebugUtilsObjectNameEXT"); + if (0 == _sg.vk.ext.set_debug_utils_object_name_ext) { + _SG_PANIC(VULKAN_REQUIRED_EXTENSION_FUNCTION_MISSING); + } + #endif + _sg.vk.ext.get_descriptor_set_layout_size = (PFN_vkGetDescriptorSetLayoutSizeEXT)vkGetDeviceProcAddr(_sg.vk.dev, "vkGetDescriptorSetLayoutSizeEXT"); + if (0 == _sg.vk.ext.get_descriptor_set_layout_size) { + _SG_PANIC(VULKAN_REQUIRED_EXTENSION_FUNCTION_MISSING); + } + _sg.vk.ext.get_descriptor_set_layout_binding_offset = (PFN_vkGetDescriptorSetLayoutBindingOffsetEXT)vkGetDeviceProcAddr(_sg.vk.dev, "vkGetDescriptorSetLayoutBindingOffsetEXT"); + if (0 == _sg.vk.ext.get_descriptor_set_layout_binding_offset) { + _SG_PANIC(VULKAN_REQUIRED_EXTENSION_FUNCTION_MISSING); + } + _sg.vk.ext.get_descriptor = (PFN_vkGetDescriptorEXT)vkGetDeviceProcAddr(_sg.vk.dev, "vkGetDescriptorEXT"); + if (0 == _sg.vk.ext.get_descriptor) { + _SG_PANIC(VULKAN_REQUIRED_EXTENSION_FUNCTION_MISSING); + } + _sg.vk.ext.cmd_bind_descriptor_buffers = (PFN_vkCmdBindDescriptorBuffersEXT)vkGetDeviceProcAddr(_sg.vk.dev, "vkCmdBindDescriptorBuffersEXT"); + if (0 == _sg.vk.ext.cmd_bind_descriptor_buffers) { + _SG_PANIC(VULKAN_REQUIRED_EXTENSION_FUNCTION_MISSING); + } + _sg.vk.ext.cmd_set_descriptor_buffer_offsets = (PFN_vkCmdSetDescriptorBufferOffsetsEXT)vkGetDeviceProcAddr(_sg.vk.dev, "vkCmdSetDescriptorBufferOffsetsEXT"); + if (0 == _sg.vk.ext.cmd_set_descriptor_buffer_offsets) { + _SG_PANIC(VULKAN_REQUIRED_EXTENSION_FUNCTION_MISSING); + } +} + +_SOKOL_PRIVATE void _sg_vk_init_caps(void) { + _sg.backend = SG_BACKEND_VULKAN; + _sg.features.origin_top_left = true; + _sg.features.image_clamp_to_border = false; // FIXME? + _sg.features.mrt_independent_blend_state = true; + _sg.features.mrt_independent_write_mask = true; + _sg.features.compute = true; + _sg.features.msaa_texture_bindings = true; + _sg.features.draw_base_vertex = true; + _sg.features.draw_base_instance = true; + _sg.features.dual_source_blending = true; + _sg.features.vertexformat_int10_n2 = true; + + SOKOL_ASSERT(_sg.vk.phys_dev); + _sg.vk.descriptor_buffer_props.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_BUFFER_PROPERTIES_EXT; + _sg.vk.dev_props.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2; + _sg.vk.dev_props.pNext = &_sg.vk.descriptor_buffer_props; + vkGetPhysicalDeviceProperties2(_sg.vk.phys_dev, &_sg.vk.dev_props); + _sg.vk.dev_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2; + vkGetPhysicalDeviceFeatures2(_sg.vk.phys_dev, &_sg.vk.dev_features); + + const VkPhysicalDeviceLimits* l = &_sg.vk.dev_props.properties.limits; + _sg.limits.max_image_size_2d = (int)l->maxImageDimension2D; + _sg.limits.max_image_size_cube = (int)l->maxImageDimensionCube; + _sg.limits.max_image_size_3d = (int)l->maxImageDimension3D; + _sg.limits.max_image_size_array = _sg.limits.max_image_size_2d; + _sg.limits.max_image_array_layers = (int)l->maxImageArrayLayers; + _sg.limits.max_vertex_attrs = _sg_min((int)l->maxVertexInputAttributes, SG_MAX_VERTEX_ATTRIBUTES); + _sg.limits.max_color_attachments = _sg_min((int)l->maxFragmentOutputAttachments, SG_MAX_COLOR_ATTACHMENTS); + _sg.limits.max_texture_bindings_per_stage = _sg_min((int)l->maxPerStageDescriptorSampledImages, SG_MAX_VIEW_BINDSLOTS); + _sg.limits.max_storage_buffer_bindings_per_stage = _sg_min((int)l->maxPerStageDescriptorStorageBuffers, SG_MAX_VIEW_BINDSLOTS); + _sg.limits.max_storage_image_bindings_per_stage = _sg_min((int)l->maxPerStageDescriptorStorageImages, SG_MAX_VIEW_BINDSLOTS); + _sg.limits.vk_min_uniform_buffer_offset_alignment = (int)l->minUniformBufferOffsetAlignment; + + _SG_STRUCT(VkPhysicalDeviceImageFormatInfo2, fmt_info); + fmt_info.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2; + fmt_info.type = VK_IMAGE_TYPE_2D; + fmt_info.tiling = VK_IMAGE_TILING_OPTIMAL; + _SG_STRUCT(VkImageFormatProperties2, props2); + props2.sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2; + for (int fmt = (SG_PIXELFORMAT_NONE+1); fmt < _SG_PIXELFORMAT_NUM; fmt++) { + _SG_STRUCT(VkFormatProperties, props); + VkFormat vkfmt = _sg_vk_format((sg_pixel_format)fmt); + vkGetPhysicalDeviceFormatProperties(_sg.vk.phys_dev, vkfmt, &props); + const VkFormatFeatureFlags f = props.optimalTilingFeatures; + _sg_pixelformat_info_t* info = &_sg.formats[fmt]; + info->sample = 0 != (f & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT); + info->filter = 0 != (f & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT); + info->render = 0 != (f & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT); + info->blend = 0 != (f & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT); + info->depth = 0 != (f & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT); + info->read = info->write = 0 != (f & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT); + if (info->depth) { + info->render = true; + } + if (info->render || info->depth) { + // query msaa support + fmt_info.format = vkfmt; + fmt_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; + if (info->depth) { + fmt_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; + } else { + fmt_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + } + VkResult res = vkGetPhysicalDeviceImageFormatProperties2(_sg.vk.phys_dev, &fmt_info, &props2); + if (res == VK_SUCCESS) { + info->msaa = props2.imageFormatProperties.sampleCounts > VK_SAMPLE_COUNT_1_BIT; + } + } + } +} + +_SOKOL_PRIVATE void _sg_vk_create_fences(void) { + SOKOL_ASSERT(_sg.vk.dev); + _SG_STRUCT(VkFenceCreateInfo, create_info); + create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + create_info.flags = VK_FENCE_CREATE_SIGNALED_BIT; + for (size_t i = 0; i < SG_NUM_INFLIGHT_FRAMES; i++) { + SOKOL_ASSERT(0 == _sg.vk.frame.slot[i].fence); + VkResult res = vkCreateFence(_sg.vk.dev, &create_info, 0, &_sg.vk.frame.slot[i].fence); + SOKOL_ASSERT((res == VK_SUCCESS) && _sg.vk.frame.slot[i].fence); _SOKOL_UNUSED(res); + } +} + +_SOKOL_PRIVATE void _sg_vk_destroy_fences(void) { + SOKOL_ASSERT(_sg.vk.dev); + for (size_t i = 0; i < SG_NUM_INFLIGHT_FRAMES; i++) { + SOKOL_ASSERT(_sg.vk.frame.slot[i].fence); + vkDestroyFence(_sg.vk.dev, _sg.vk.frame.slot[i].fence, 0); + _sg.vk.frame.slot[i].fence = 0; + } +} + +_SOKOL_PRIVATE void _sg_vk_create_frame_command_pool_and_buffers(void) { + SOKOL_ASSERT(_sg.vk.dev); + SOKOL_ASSERT(0 == _sg.vk.frame.cmd_pool); + _SG_STRUCT(VkCommandPoolCreateInfo, pool_create_info); + pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; + // FIXME: transient bit when the cmd buffers are reset each frame? + pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; + pool_create_info.queueFamilyIndex = _sg.vk.queue_family_index; + VkResult res = vkCreateCommandPool(_sg.vk.dev, &pool_create_info, 0, &_sg.vk.frame.cmd_pool); + SOKOL_ASSERT((res == VK_SUCCESS) && _sg.vk.frame.cmd_pool); _SOKOL_UNUSED(res); + + for (size_t i = 0; i < SG_NUM_INFLIGHT_FRAMES; i++) { + _SG_STRUCT(VkCommandBufferAllocateInfo, cmdbuf_alloc_info); + cmdbuf_alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; + cmdbuf_alloc_info.commandPool = _sg.vk.frame.cmd_pool; + cmdbuf_alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; + cmdbuf_alloc_info.commandBufferCount = 1; + res = vkAllocateCommandBuffers(_sg.vk.dev, &cmdbuf_alloc_info, &_sg.vk.frame.slot[i].command_buffer); + SOKOL_ASSERT((res == VK_SUCCESS) && _sg.vk.frame.slot[i].command_buffer); + res = vkAllocateCommandBuffers(_sg.vk.dev, &cmdbuf_alloc_info, &_sg.vk.frame.slot[i].stream_command_buffer); + SOKOL_ASSERT((res == VK_SUCCESS) && _sg.vk.frame.slot[i].stream_command_buffer); + } +} + +_SOKOL_PRIVATE void _sg_vk_destroy_frame_command_pool(void) { + SOKOL_ASSERT(_sg.vk.dev); + SOKOL_ASSERT(_sg.vk.frame.cmd_pool); + SOKOL_ASSERT(0 == _sg.vk.frame.cmd_buf); + SOKOL_ASSERT(0 == _sg.vk.frame.stream_cmd_buf); + // NOTE: command buffers owned by the pool will be automatically destroyed + vkDestroyCommandPool(_sg.vk.dev, _sg.vk.frame.cmd_pool, 0); + _sg.vk.frame.cmd_pool = 0; + for (size_t i = 0; i < SG_NUM_INFLIGHT_FRAMES; i++) { + SOKOL_ASSERT(_sg.vk.frame.slot[i].command_buffer); + _sg.vk.frame.slot[i].command_buffer = 0; + _sg.vk.frame.slot[i].stream_command_buffer = 0; + } +} + +_SOKOL_PRIVATE void _sg_vk_acquire_frame_command_buffers(void) { + SOKOL_ASSERT(_sg.vk.dev); + VkResult res; + if (0 == _sg.vk.frame.cmd_buf) { + SOKOL_ASSERT(0 == _sg.vk.frame.stream_cmd_buf); + _sg.vk.frame_slot = (_sg.vk.frame_slot + 1) % SG_NUM_INFLIGHT_FRAMES; + // block until oldest inflight-frame has finished + do { + res = vkWaitForFences(_sg.vk.dev, + 1, + &_sg.vk.frame.slot[_sg.vk.frame_slot].fence, + VK_TRUE, + UINT64_MAX); + } while (res == VK_TIMEOUT); + if (res != VK_SUCCESS) { + _SG_WARN(VULKAN_WAIT_FOR_FENCE_FAILED); + _sg.cur_pass.valid = false; + return; + } + res = vkResetFences(_sg.vk.dev, 1, &_sg.vk.frame.slot[_sg.vk.frame_slot].fence); + SOKOL_ASSERT(res == VK_SUCCESS); _SOKOL_UNUSED(res); + + _sg_vk_delete_queue_collect(); + + _sg.vk.frame.cmd_buf = _sg.vk.frame.slot[_sg.vk.frame_slot].command_buffer; + res = vkResetCommandBuffer(_sg.vk.frame.cmd_buf, 0); + SOKOL_ASSERT(res == VK_SUCCESS); + _sg.vk.frame.stream_cmd_buf = _sg.vk.frame.slot[_sg.vk.frame_slot].stream_command_buffer; + res = vkResetCommandBuffer(_sg.vk.frame.stream_cmd_buf, 0); + SOKOL_ASSERT(res == VK_SUCCESS); + + _SG_STRUCT(VkCommandBufferBeginInfo, cmdbuf_begin_info); + cmdbuf_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; + cmdbuf_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; + res = vkBeginCommandBuffer(_sg.vk.frame.cmd_buf, &cmdbuf_begin_info); + SOKOL_ASSERT(res == VK_SUCCESS); + res = vkBeginCommandBuffer(_sg.vk.frame.stream_cmd_buf, &cmdbuf_begin_info); + SOKOL_ASSERT(res == VK_SUCCESS); + + _sg_vk_uniform_after_acquire(); + _sg_vk_bind_after_acquire(); + _sg_vk_staging_stream_after_acquire(); + } + SOKOL_ASSERT(_sg.vk.frame.cmd_buf); +} + +_SOKOL_PRIVATE void _sg_vk_submit_frame_command_buffers(void) { + SOKOL_ASSERT(_sg.vk.frame.cmd_buf); + SOKOL_ASSERT(_sg.vk.frame.stream_cmd_buf); + VkResult res; + _SOKOL_UNUSED(res); + + _sg_vk_staging_stream_before_submit(); + _sg_vk_bind_before_submit(); + _sg_vk_uniform_before_submit(); + + res = vkEndCommandBuffer(_sg.vk.frame.stream_cmd_buf); + SOKOL_ASSERT(res == VK_SUCCESS); + res = vkEndCommandBuffer(_sg.vk.frame.cmd_buf); + SOKOL_ASSERT(res == VK_SUCCESS); + + _SG_STRUCT(VkSubmitInfo, submit_infos[2]); + // streaming-update command buffer + submit_infos[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + submit_infos[0].commandBufferCount = 1; + submit_infos[0].pCommandBuffers = &_sg.vk.frame.stream_cmd_buf; + // render command buffer + const VkPipelineStageFlags present_wait_dst_stage_mask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; + submit_infos[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + // NOTE: the render_finished_sem and present_complete_sem are only + // provided in swapchain passes, but rendering without a swapchain + // pass should be a valid scenario (for instance for 'headless rendering') + // + // see: https://github.com/floooh/sokol/issues/1459 + if (_sg.vk.present_complete_sem && _sg.vk.render_finished_sem) { + submit_infos[1].waitSemaphoreCount = 1; + submit_infos[1].pWaitSemaphores = &_sg.vk.present_complete_sem; + submit_infos[1].pWaitDstStageMask = &present_wait_dst_stage_mask; + submit_infos[1].signalSemaphoreCount = 1; + submit_infos[1].pSignalSemaphores = &_sg.vk.render_finished_sem; + } + submit_infos[1].commandBufferCount = 1; + submit_infos[1].pCommandBuffers = &_sg.vk.frame.cmd_buf; + res = vkQueueSubmit(_sg.vk.queue, 2, submit_infos, _sg.vk.frame.slot[_sg.vk.frame_slot].fence); + SOKOL_ASSERT(res == VK_SUCCESS); + + _sg.vk.frame.cmd_buf = 0; + _sg.vk.frame.stream_cmd_buf = 0; + + // NOTE: it's valid to register resource objects for destruction in the + // delete queue past this point (between _sg_vk_submit_frame_command_buffer() + // and the next _sg_vk_acquire_frame_command_buffer()) since resources which are + // destroyed in this 'gap' can at most have been used by the command + // buffer that was just submitted +} + +_SOKOL_PRIVATE void _sg_vk_setup_backend(const sg_desc* desc) { + SOKOL_ASSERT(desc); + SOKOL_ASSERT(desc->environment.vulkan.instance); + SOKOL_ASSERT(desc->environment.vulkan.physical_device); + SOKOL_ASSERT(desc->environment.vulkan.device); + SOKOL_ASSERT(desc->environment.vulkan.queue); + SOKOL_ASSERT(desc->uniform_buffer_size > 0); + _sg.vk.valid = true; + _sg.vk.instance = (VkInstance) desc->environment.vulkan.instance; + _sg.vk.phys_dev = (VkPhysicalDevice) desc->environment.vulkan.physical_device; + _sg.vk.dev = (VkDevice) desc->environment.vulkan.device; + _sg.vk.queue = (VkQueue) desc->environment.vulkan.queue; + _sg.vk.queue_family_index = desc->environment.vulkan.queue_family_index; + + _sg_track_init(&_sg.vk.track.buffers, _sg.pools.buffer_pool.size); + _sg_track_init(&_sg.vk.track.images, _sg.pools.image_pool.size); + _sg_vk_load_ext_funcs(); + _sg_vk_init_caps(); + _sg_vk_create_fences(); + _sg_vk_create_frame_command_pool_and_buffers(); + _sg_vk_staging_copy_init(); + _sg_vk_staging_stream_init(); + _sg_vk_uniform_init(); + _sg_vk_bind_init(); + _sg_vk_create_delete_queues(); +} + +_SOKOL_PRIVATE void _sg_vk_discard_backend(void) { + SOKOL_ASSERT(_sg.vk.valid); + SOKOL_ASSERT(_sg.vk.dev); + vkDeviceWaitIdle(_sg.vk.dev); + _sg_vk_destroy_delete_queues(); + _sg_vk_bind_discard(); + _sg_vk_uniform_discard(); + _sg_vk_staging_stream_discard(); + _sg_vk_staging_copy_discard(); + _sg_vk_destroy_frame_command_pool(); + _sg_vk_destroy_fences(); + _sg_track_discard(&_sg.vk.track.images); + _sg_track_discard(&_sg.vk.track.buffers); + _sg.vk.valid = false; +} + +_SOKOL_PRIVATE void _sg_vk_reset_state_cache(void) { + // nothing to do here +} + +_SOKOL_PRIVATE sg_resource_state _sg_vk_create_buffer(_sg_buffer_t* buf, const sg_buffer_desc* desc) { + SOKOL_ASSERT(_sg.vk.dev); + SOKOL_ASSERT(buf && desc); + SOKOL_ASSERT(buf->cmn.size > 0); + SOKOL_ASSERT(0 == buf->vk.buf); + SOKOL_ASSERT(0 == buf->vk.mem); + SOKOL_ASSERT(0 == buf->vk.dev_addr); + VkResult res; + // FIXME: inject external buffer + + buf->vk.cur_access = _SG_VK_ACCESS_NONE; + + _SG_STRUCT(VkBufferCreateInfo, create_info); + create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + create_info.size = (VkDeviceSize)buf->cmn.size; + create_info.usage = _sg_vk_buffer_usage(&buf->cmn.usage); + create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + res = vkCreateBuffer(_sg.vk.dev, &create_info, 0, &buf->vk.buf); + if (res != VK_SUCCESS) { + _SG_ERROR(VULKAN_CREATE_BUFFER_FAILED); + return SG_RESOURCESTATE_FAILED; + } + SOKOL_ASSERT(buf->vk.buf); + _sg_vk_set_object_label(VK_OBJECT_TYPE_BUFFER, (uint64_t)buf->vk.buf, desc->label); + + if (!_sg_vk_mem_alloc_buffer_device_memory(buf)) { + return SG_RESOURCESTATE_FAILED; + } + SOKOL_ASSERT(buf->vk.mem); + res = vkBindBufferMemory(_sg.vk.dev, buf->vk.buf, buf->vk.mem, 0); + if (res != VK_SUCCESS) { + _SG_ERROR(VULKAN_BIND_BUFFER_MEMORY_FAILED); + return SG_RESOURCESTATE_FAILED; + } + if (buf->cmn.usage.storage_buffer) { + _SG_STRUCT(VkBufferDeviceAddressInfo, addr_info); + addr_info.sType = VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO; + addr_info.buffer = buf->vk.buf; + buf->vk.dev_addr = vkGetBufferDeviceAddress(_sg.vk.dev, &addr_info); + SOKOL_ASSERT(buf->vk.dev_addr); + } + if (buf->cmn.usage.immutable && desc->data.ptr) { + _sg_vk_staging_copy_buffer_data(buf, &desc->data, 0, false); + } + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_vk_discard_buffer(_sg_buffer_t* buf) { + SOKOL_ASSERT(buf); + _sg_track_remove(&_sg.vk.track.buffers, buf->slot.id); + if (buf->vk.buf) { + _sg_vk_delete_queue_add(_sg_vk_buffer_destructor, (void*)buf->vk.buf); + buf->vk.buf = 0; + } + if (buf->vk.mem) { + _sg_vk_delete_queue_add(_sg_vk_memory_destructor, (void*)buf->vk.mem); + buf->vk.mem = 0; + } +} + +_SOKOL_PRIVATE sg_resource_state _sg_vk_create_image(_sg_image_t* img, const sg_image_desc* desc) { + SOKOL_ASSERT(img && desc); + VkResult res; + // FIXME: injected images + + img->vk.cur_access = _SG_VK_ACCESS_NONE; + + _SG_STRUCT(VkImageCreateInfo, create_info); + create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + create_info.flags = _sg_vk_image_create_flags(img->cmn.type); + create_info.imageType = _sg_vk_image_type(img->cmn.type); + create_info.format = _sg_vk_format(desc->pixel_format); + create_info.extent.width = (uint32_t)img->cmn.width; + create_info.extent.height = (uint32_t)img->cmn.height; + if (desc->type == SG_IMAGETYPE_3D) { + create_info.extent.depth = (uint32_t)img->cmn.num_slices; + create_info.arrayLayers = 1; + } else { + create_info.extent.depth = 1; + create_info.arrayLayers = (uint32_t)img->cmn.num_slices; + } + create_info.mipLevels = (uint32_t)img->cmn.num_mipmaps; + create_info.samples = (VkSampleCountFlagBits)desc->sample_count; + create_info.tiling = VK_IMAGE_TILING_OPTIMAL; + create_info.usage = _sg_vk_image_usage(&img->cmn.usage); + create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + res = vkCreateImage(_sg.vk.dev, &create_info, 0, &img->vk.img); + if (res != VK_SUCCESS) { + _SG_ERROR(VULKAN_CREATE_IMAGE_FAILED); + return SG_RESOURCESTATE_FAILED; + } + SOKOL_ASSERT(img->vk.img); + _sg_vk_set_object_label(VK_OBJECT_TYPE_IMAGE, (uint64_t)img->vk.img, desc->label); + + if (!_sg_vk_mem_alloc_image_device_memory(img)) { + return SG_RESOURCESTATE_FAILED; + } + SOKOL_ASSERT(img->vk.mem); + res = vkBindImageMemory(_sg.vk.dev, img->vk.img, img->vk.mem, 0); + if (res != VK_SUCCESS) { + _SG_ERROR(VULKAN_BIND_IMAGE_MEMORY_FAILED); + return SG_RESOURCESTATE_FAILED; + } + if (img->cmn.usage.immutable && desc->data.mip_levels[0].ptr) { + _sg_vk_staging_copy_image_data(img, &desc->data, false); + } + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_vk_discard_image(_sg_image_t* img) { + SOKOL_ASSERT(img); + _sg_track_remove(&_sg.vk.track.images, img->slot.id); + if (img->vk.img) { + _sg_vk_delete_queue_add(_sg_vk_image_destructor, (void*)img->vk.img); + img->vk.img = 0; + } + if (img->vk.mem) { + _sg_vk_delete_queue_add(_sg_vk_memory_destructor, (void*)img->vk.mem); + img->vk.mem = 0; + } +} + +_SOKOL_PRIVATE sg_resource_state _sg_vk_create_sampler(_sg_sampler_t* smp, const sg_sampler_desc* desc) { + SOKOL_ASSERT(smp && desc); + SOKOL_ASSERT(_sg.vk.dev); + SOKOL_ASSERT(0 == smp->vk.smp); + // FIXME: injection + + // create sampler object + _SG_STRUCT(VkSamplerCreateInfo, create_info); + create_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; + create_info.magFilter = _sg_vk_sampler_minmag_filter(desc->mag_filter); + create_info.minFilter = _sg_vk_sampler_minmag_filter(desc->min_filter); + create_info.mipmapMode = _sg_vk_sampler_mipmap_mode(desc->mipmap_filter); + create_info.addressModeU = _sg_vk_sampler_address_mode(desc->wrap_u); + create_info.addressModeV = _sg_vk_sampler_address_mode(desc->wrap_v); + create_info.addressModeW = _sg_vk_sampler_address_mode(desc->wrap_w); + create_info.mipLodBias = 0.0f; + if (desc->max_anisotropy > 1) { + create_info.anisotropyEnable = VK_TRUE; + create_info.maxAnisotropy = (float)desc->max_anisotropy; + } + if (desc->compare != SG_COMPAREFUNC_NEVER) { + create_info.compareEnable = VK_TRUE; + create_info.compareOp = _sg_vk_compare_op(desc->compare); + } + create_info.minLod = desc->min_lod; + create_info.maxLod = desc->max_lod; + create_info.borderColor = _sg_vk_sampler_border_color(desc->border_color); + VkResult res = vkCreateSampler(_sg.vk.dev, &create_info, 0, &smp->vk.smp); + if (res != VK_SUCCESS) { + _SG_ERROR(VULKAN_CREATE_SAMPLER_FAILED); + return SG_RESOURCESTATE_FAILED; + } + SOKOL_ASSERT(smp->vk.smp); + _sg_vk_set_object_label(VK_OBJECT_TYPE_SAMPLER, (uint64_t)smp->vk.smp, desc->label); + + // record sampler descriptor data + smp->vk.descriptor_size = _sg.vk.descriptor_buffer_props.samplerDescriptorSize; + if (_SG_VK_MAX_DESCRIPTOR_DATA_SIZE < smp->vk.descriptor_size) { + _SG_ERROR(VULKAN_SAMPLER_MAX_DESCRIPTOR_SIZE); + return SG_RESOURCESTATE_FAILED; + } + _SG_STRUCT(VkDescriptorGetInfoEXT, get_info); + get_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_GET_INFO_EXT; + get_info.type = VK_DESCRIPTOR_TYPE_SAMPLER; + get_info.data.pSampler = &smp->vk.smp; + _sg.vk.ext.get_descriptor(_sg.vk.dev, &get_info, smp->vk.descriptor_size, &smp->vk.descriptor_data); + + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_vk_discard_sampler(_sg_sampler_t* smp) { + SOKOL_ASSERT(smp); + if (smp->vk.smp) { + _sg_vk_delete_queue_add(_sg_vk_sampler_destructor, (void*)smp->vk.smp); + smp->vk.smp = 0; + } +} + +_SOKOL_PRIVATE _sg_vk_shader_func_t _sg_vk_create_shader_func(const sg_shader_function* func, const char* label) { + SOKOL_ASSERT(_sg.vk.dev); + SOKOL_ASSERT(func); + SOKOL_ASSERT(func->bytecode.ptr && (func->bytecode.size > 0)); + SOKOL_ASSERT(func->entry); + + _SG_STRUCT(_sg_vk_shader_func_t, vk_func); + _sg_strcpy(&vk_func.entry, func->entry); + + _SG_STRUCT(VkShaderModuleCreateInfo, create_info); + create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + create_info.codeSize = func->bytecode.size; + create_info.pCode = (uint32_t*)func->bytecode.ptr; + VkResult res = vkCreateShaderModule(_sg.vk.dev, &create_info, 0, &vk_func.module); + if (VK_SUCCESS != res) { + _SG_ERROR(VULKAN_CREATE_SHADER_MODULE_FAILED); + } else { + SOKOL_ASSERT(vk_func.module); + _sg_vk_set_object_label(VK_OBJECT_TYPE_SHADER_MODULE, (uint64_t)vk_func.module, label); + } + return vk_func; +} + +_SOKOL_PRIVATE void _sg_vk_discard_shader_func(_sg_vk_shader_func_t* func) { + SOKOL_ASSERT(_sg.vk.dev); + SOKOL_ASSERT(func); + if (func->module) { + _sg_vk_delete_queue_add(_sg_vk_shader_module_destructor, (void*)func->module); + func->module = 0; + } +} + +_SOKOL_PRIVATE bool _sg_vk_ensure_spirv_bindslot_ranges(const sg_shader_desc* desc) { + SOKOL_ASSERT(desc); + for (size_t i = 0; i < SG_MAX_UNIFORMBLOCK_BINDSLOTS; i++) { + const sg_shader_uniform_block* ub = &desc->uniform_blocks[i]; + if (ub->stage != SG_SHADERSTAGE_NONE) { + if (ub->spirv_set0_binding_n >= _SG_VK_MAX_UB_DESCRIPTORSET_SLOTS) { + _SG_ERROR(VULKAN_UNIFORMBLOCK_SPIRV_SET0_BINDING_OUT_OF_RANGE); + return false; + } + } + } + for (size_t i = 0; i < SG_MAX_VIEW_BINDSLOTS; i++) { + const sg_shader_view* view = &desc->views[i]; + if (view->texture.stage != SG_SHADERSTAGE_NONE) { + if (view->texture.spirv_set1_binding_n >= _SG_VK_MAX_VIEW_SMP_DESCRIPTORSET_SLOTS) { + _SG_ERROR(VULKAN_TEXTURE_SPIRV_SET1_BINDING_OUT_OF_RANGE); + return false; + } + } + if (view->storage_buffer.stage != SG_SHADERSTAGE_NONE) { + if (view->storage_buffer.spirv_set1_binding_n >= _SG_VK_MAX_VIEW_SMP_DESCRIPTORSET_SLOTS) { + _SG_ERROR(VULKAN_STORAGEBUFFER_SPIRV_SET1_BINDING_OUT_OF_RANGE); + return false; + } + } + if (view->storage_image.stage != SG_SHADERSTAGE_NONE) { + if (view->storage_image.spirv_set1_binding_n >= _SG_VK_MAX_VIEW_SMP_DESCRIPTORSET_SLOTS) { + _SG_ERROR(VULKAN_STORAGEIMAGE_SPIRV_SET1_BINDING_OUT_OF_RANGE); + return false; + } + } + } + for (size_t i = 0; i < SG_MAX_SAMPLER_BINDSLOTS; i++) { + const sg_shader_sampler* smp = &desc->samplers[i]; + if (smp->stage != SG_SHADERSTAGE_NONE) { + if (smp->spirv_set1_binding_n >= _SG_VK_MAX_VIEW_SMP_DESCRIPTORSET_SLOTS) { + _SG_ERROR(VULKAN_SAMPLER_SPIRV_SET1_BINDING_OUT_OF_RANGE); + return false; + } + } + } + return true; +} + +_SOKOL_PRIVATE sg_resource_state _sg_vk_create_shader(_sg_shader_t* shd, const sg_shader_desc* desc) { + SOKOL_ASSERT(shd && desc); + SOKOL_ASSERT(_sg.vk.dev); + SOKOL_ASSERT(shd->vk.vertex_func.module == 0); + SOKOL_ASSERT(shd->vk.fragment_func.module == 0); + SOKOL_ASSERT(shd->vk.compute_func.module == 0); + SOKOL_ASSERT(shd->vk.ub_dsl == 0); + SOKOL_ASSERT(shd->vk.view_smp_dsl == 0); + + if (!_sg_vk_ensure_spirv_bindslot_ranges(desc)) { + return SG_RESOURCESTATE_FAILED; + } + + // build shader modules + bool shd_valid = true; + if (desc->vertex_func.bytecode.ptr) { + shd->vk.vertex_func = _sg_vk_create_shader_func(&desc->vertex_func, desc->label); + shd_valid &= shd->vk.vertex_func.module != 0; + } + if (desc->fragment_func.bytecode.ptr) { + shd->vk.fragment_func = _sg_vk_create_shader_func(&desc->fragment_func, desc->label); + shd_valid &= shd->vk.fragment_func.module != 0; + } + if (desc->compute_func.bytecode.ptr) { + shd->vk.compute_func = _sg_vk_create_shader_func(&desc->compute_func, desc->label); + shd_valid &= shd->vk.compute_func.module != 0; + } + if (!shd_valid) { + _sg_vk_discard_shader_func(&shd->vk.vertex_func); + _sg_vk_discard_shader_func(&shd->vk.fragment_func); + _sg_vk_discard_shader_func(&shd->vk.compute_func); + return SG_RESOURCESTATE_FAILED; + } + + // descriptor set layouts and pipeline layout + VkResult res; + _SG_STRUCT(VkDescriptorSetLayoutBinding, dsl_entries[_SG_VK_MAX_VIEW_SMP_DESCRIPTORSET_ENTRIES]); + _SG_STRUCT(VkDescriptorSetLayoutCreateInfo, dsl_create_info); + uint32_t dsl_index = 0; + for (size_t i = 0; i < SG_MAX_UNIFORMBLOCK_BINDSLOTS; i++) { + if (shd->cmn.uniform_blocks[i].stage == SG_SHADERSTAGE_NONE) { + continue; + } + shd->vk.ub_set0_bnd_n[i] = desc->uniform_blocks[i].spirv_set0_binding_n; + VkDescriptorSetLayoutBinding* dsl_entry = &dsl_entries[dsl_index]; + dsl_entry->binding = shd->vk.ub_set0_bnd_n[i]; + dsl_entry->descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + dsl_entry->descriptorCount = 1; + dsl_entry->stageFlags = _sg_vk_shader_stage(shd->cmn.uniform_blocks[i].stage); + dsl_index += 1; + } + dsl_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + dsl_create_info.flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_DESCRIPTOR_BUFFER_BIT_EXT; + dsl_create_info.bindingCount = dsl_index; + dsl_create_info.pBindings = dsl_entries; + res = vkCreateDescriptorSetLayout(_sg.vk.dev, &dsl_create_info, 0, &shd->vk.ub_dsl); + if (res != VK_SUCCESS) { + _SG_ERROR(VULKAN_CREATE_DESCRIPTOR_SET_LAYOUT_FAILED); + return SG_RESOURCESTATE_FAILED; + } + + // store uniform descriptor set size and descriptor offsets + _sg.vk.ext.get_descriptor_set_layout_size(_sg.vk.dev, shd->vk.ub_dsl, &shd->vk.ub_dset_size); + if (shd->vk.ub_dset_size > _sg.vk.uniforms.dset_cache_size) { + _SG_ERROR(VULKAN_SHADER_UNIFORM_DESCRIPTOR_SET_SIZE_VS_CACHE_SIZE); + return SG_RESOURCESTATE_FAILED; + } + for (size_t i = 0; i < SG_MAX_UNIFORMBLOCK_BINDSLOTS; i++) { + if (shd->cmn.uniform_blocks[i].stage == SG_SHADERSTAGE_NONE) { + continue; + } + const uint8_t vk_bnd = shd->vk.ub_set0_bnd_n[i]; + VkDeviceSize dset_offset = 0; + _sg.vk.ext.get_descriptor_set_layout_binding_offset(_sg.vk.dev, shd->vk.ub_dsl, vk_bnd, &dset_offset); + shd->vk.ub_dset_offsets[i] = (uint16_t)dset_offset; + } + + _sg_clear(dsl_entries, sizeof(dsl_entries)); + _sg_clear(&dsl_create_info, sizeof(dsl_create_info)); + dsl_index = 0; + for (size_t i = 0; i < SG_MAX_VIEW_BINDSLOTS; i++) { + if (shd->cmn.views[i].stage == SG_SHADERSTAGE_NONE) { + continue; + } + SOKOL_ASSERT(dsl_index < _SG_VK_MAX_VIEW_SMP_DESCRIPTORSET_ENTRIES); + VkDescriptorSetLayoutBinding* dsl_entry = &dsl_entries[dsl_index]; + dsl_entry->stageFlags = _sg_vk_shader_stage(shd->cmn.views[i].stage); + if (shd->cmn.views[i].view_type == SG_VIEWTYPE_TEXTURE) { + shd->vk.view_set1_bnd_n[i] = desc->views[i].texture.spirv_set1_binding_n; + dsl_entry->descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; + } else if (shd->cmn.views[i].view_type == SG_VIEWTYPE_STORAGEBUFFER) { + shd->vk.view_set1_bnd_n[i] = desc->views[i].storage_buffer.spirv_set1_binding_n; + dsl_entry->descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; + } else if (shd->cmn.views[i].view_type == SG_VIEWTYPE_STORAGEIMAGE) { + shd->vk.view_set1_bnd_n[i] = desc->views[i].storage_image.spirv_set1_binding_n; + dsl_entry->descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; + } else { + SOKOL_UNREACHABLE; + } + dsl_entry->binding = shd->vk.view_set1_bnd_n[i]; + dsl_entry->descriptorCount = 1; + dsl_index += 1; + } + for (size_t i = 0; i < SG_MAX_SAMPLER_BINDSLOTS; i++) { + if (shd->cmn.samplers[i].stage == SG_SHADERSTAGE_NONE) { + continue; + } + shd->vk.smp_set1_bnd_n[i] = desc->samplers[i].spirv_set1_binding_n; + SOKOL_ASSERT(dsl_index < _SG_VK_MAX_VIEW_SMP_DESCRIPTORSET_ENTRIES); + VkDescriptorSetLayoutBinding* dsl_entry = &dsl_entries[dsl_index]; + dsl_entry->binding = shd->vk.smp_set1_bnd_n[i]; + dsl_entry->descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; + dsl_entry->descriptorCount = 1; + dsl_entry->stageFlags = _sg_vk_shader_stage(shd->cmn.samplers[i].stage); + dsl_index += 1; + } + dsl_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + dsl_create_info.flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_DESCRIPTOR_BUFFER_BIT_EXT; + dsl_create_info.bindingCount = dsl_index; + dsl_create_info.pBindings = dsl_entries; + res = vkCreateDescriptorSetLayout(_sg.vk.dev, &dsl_create_info, 0, &shd->vk.view_smp_dsl); + if (res != VK_SUCCESS) { + _SG_ERROR(VULKAN_CREATE_DESCRIPTOR_SET_LAYOUT_FAILED); + return SG_RESOURCESTATE_FAILED; + } + + // store view/smp descriptor set size and descriptor offsets + _sg.vk.ext.get_descriptor_set_layout_size(_sg.vk.dev, shd->vk.view_smp_dsl, &shd->vk.view_smp_dset_size); + for (size_t i = 0; i < SG_MAX_VIEW_BINDSLOTS; i++) { + if (shd->cmn.views[i].stage == SG_SHADERSTAGE_NONE) { + continue; + } + const uint8_t vk_bnd = shd->vk.view_set1_bnd_n[i]; + VkDeviceSize dset_offset = 0; + _sg.vk.ext.get_descriptor_set_layout_binding_offset(_sg.vk.dev, shd->vk.view_smp_dsl, vk_bnd, &dset_offset); + shd->vk.view_dset_offsets[i] = (uint16_t)dset_offset; + } + for (size_t i = 0; i < SG_MAX_SAMPLER_BINDSLOTS; i++) { + if (shd->cmn.samplers[i].stage == SG_SHADERSTAGE_NONE) { + continue; + } + const uint8_t vk_bnd = shd->vk.smp_set1_bnd_n[i]; + VkDeviceSize dset_offset = 0; + _sg.vk.ext.get_descriptor_set_layout_binding_offset(_sg.vk.dev, shd->vk.view_smp_dsl, vk_bnd, &dset_offset); + shd->vk.smp_dset_offsets[i] = (uint16_t)dset_offset; + } + + VkDescriptorSetLayout set_layouts[_SG_VK_NUM_DESCRIPTORSETS] = { + shd->vk.ub_dsl, + shd->vk.view_smp_dsl, + }; + _SG_STRUCT(VkPipelineLayoutCreateInfo, pl_create_info); + pl_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; + pl_create_info.setLayoutCount = _SG_VK_NUM_DESCRIPTORSETS; + pl_create_info.pSetLayouts = set_layouts; + res = vkCreatePipelineLayout(_sg.vk.dev, &pl_create_info, 0, &shd->vk.pip_layout); + if (res != VK_SUCCESS) { + _SG_ERROR(VULKAN_CREATE_PIPELINE_LAYOUT_FAILED); + return SG_RESOURCESTATE_FAILED; + } + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_vk_discard_shader(_sg_shader_t* shd) { + SOKOL_ASSERT(shd); + SOKOL_ASSERT(_sg.vk.dev); + _sg_vk_discard_shader_func(&shd->vk.vertex_func); + _sg_vk_discard_shader_func(&shd->vk.fragment_func); + _sg_vk_discard_shader_func(&shd->vk.compute_func); + if (shd->vk.pip_layout) { + _sg_vk_delete_queue_add(_sg_vk_pipelinelayout_destructor, (void*)shd->vk.pip_layout); + shd->vk.pip_layout = 0; + } + if (shd->vk.ub_dsl) { + _sg_vk_delete_queue_add(_sg_vk_descriptorsetlayout_destructor, (void*)shd->vk.ub_dsl); + shd->vk.ub_dsl = 0; + } + if (shd->vk.view_smp_dsl) { + _sg_vk_delete_queue_add(_sg_vk_descriptorsetlayout_destructor, (void*)shd->vk.view_smp_dsl); + shd->vk.view_smp_dsl = 0; + } +} + +_SOKOL_PRIVATE sg_resource_state _sg_vk_create_pipeline(_sg_pipeline_t* pip, const sg_pipeline_desc* desc) { + SOKOL_ASSERT(pip && desc); + SOKOL_ASSERT(_sg.vk.dev); + VkResult res; + + const _sg_shader_t* shd = _sg_shader_ref_ptr(&pip->cmn.shader); + SOKOL_ASSERT(shd->vk.pip_layout); + if (pip->cmn.is_compute) { + SOKOL_ASSERT(shd->vk.compute_func.module); + _SG_STRUCT(VkComputePipelineCreateInfo, pip_create_info); + pip_create_info.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO; + pip_create_info.flags = VK_PIPELINE_CREATE_DESCRIPTOR_BUFFER_BIT_EXT; + pip_create_info.stage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + pip_create_info.stage.stage = VK_SHADER_STAGE_COMPUTE_BIT; + pip_create_info.stage.module = shd->vk.compute_func.module; + pip_create_info.stage.pName = shd->vk.compute_func.entry.buf; + pip_create_info.layout = shd->vk.pip_layout; + res = vkCreateComputePipelines(_sg.vk.dev, VK_NULL_HANDLE, 1, &pip_create_info, 0, &pip->vk.pip); + if (res != VK_SUCCESS) { + _SG_ERROR(VULKAN_CREATE_COMPUTE_PIPELINE_FAILED); + return SG_RESOURCESTATE_FAILED; + } + } else { + uint32_t num_stages = 0; + _SG_STRUCT(VkPipelineShaderStageCreateInfo, stages[2]); + if (shd->vk.vertex_func.module) { + stages[num_stages].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + stages[num_stages].stage = VK_SHADER_STAGE_VERTEX_BIT; + stages[num_stages].module = shd->vk.vertex_func.module; + stages[num_stages].pName = shd->vk.vertex_func.entry.buf; + num_stages += 1; + } + if (shd->vk.fragment_func.module) { + stages[num_stages].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + stages[num_stages].stage = VK_SHADER_STAGE_FRAGMENT_BIT; + stages[num_stages].module = shd->vk.fragment_func.module; + stages[num_stages].pName = shd->vk.fragment_func.entry.buf; + num_stages += 1; + } + + uint32_t num_vtx_bnds = 0; + _SG_STRUCT(VkVertexInputBindingDescription, vtx_bnds[SG_MAX_VERTEXBUFFER_BINDSLOTS]); + for (uint32_t vbl_idx = 0; vbl_idx < SG_MAX_VERTEXBUFFER_BINDSLOTS; vbl_idx++, num_vtx_bnds++) { + const sg_vertex_buffer_layout_state* vbl_state = &desc->layout.buffers[vbl_idx]; + if (0 == vbl_state->stride) { + break; + } + vtx_bnds[vbl_idx].binding = vbl_idx; + vtx_bnds[vbl_idx].stride = (uint32_t)vbl_state->stride; + vtx_bnds[vbl_idx].inputRate = _sg_vk_vertex_input_rate(vbl_state->step_func); + } + + uint32_t num_vtx_attrs = 0; + _SG_STRUCT(VkVertexInputAttributeDescription, vtx_attrs[SG_MAX_VERTEX_ATTRIBUTES]); + for (uint32_t va_idx = 0; va_idx < SG_MAX_VERTEX_ATTRIBUTES; va_idx++, num_vtx_attrs++) { + const sg_vertex_attr_state* va_state = &desc->layout.attrs[va_idx]; + if (SG_VERTEXFORMAT_INVALID == va_state->format) { + break; + } + const uint32_t vbl_idx = (uint32_t)va_state->buffer_index; + SOKOL_ASSERT(vbl_idx < SG_MAX_VERTEXBUFFER_BINDSLOTS); + SOKOL_ASSERT(pip->cmn.vertex_buffer_layout_active[vbl_idx]); + vtx_attrs[va_idx].location = va_idx; + vtx_attrs[va_idx].binding = vbl_idx; + vtx_attrs[va_idx].format = _sg_vk_vertex_format(va_state->format); + vtx_attrs[va_idx].offset = (uint32_t)va_state->offset; + } + + _SG_STRUCT(VkPipelineVertexInputStateCreateInfo, vi_state); + vi_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; + vi_state.vertexBindingDescriptionCount = num_vtx_bnds; + vi_state.pVertexBindingDescriptions = vtx_bnds; + vi_state.vertexAttributeDescriptionCount = num_vtx_attrs; + vi_state.pVertexAttributeDescriptions = vtx_attrs; + + _SG_STRUCT(VkPipelineInputAssemblyStateCreateInfo, ia_state); + ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; + ia_state.topology = _sg_vk_primitive_topology(desc->primitive_type); + ia_state.primitiveRestartEnable = VK_FALSE; // FIXME: needs 'primitiveTopologyRestart feature enabled' + + _SG_STRUCT(VkPipelineViewportStateCreateInfo, vp_state); + vp_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; + vp_state.viewportCount = 1; + vp_state.scissorCount = 1; + + _SG_STRUCT(VkPipelineRasterizationStateCreateInfo, rs_state); + rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; + rs_state.depthClampEnable = false; + rs_state.rasterizerDiscardEnable = false; + rs_state.polygonMode = VK_POLYGON_MODE_FILL; + rs_state.cullMode = _sg_vk_cullmode(desc->cull_mode); + rs_state.frontFace = _sg_vk_frontface(desc->face_winding); + rs_state.depthBiasEnable = ((int32_t)desc->depth.bias) != 0; + rs_state.depthBiasConstantFactor = desc->depth.bias; + rs_state.depthBiasClamp = desc->depth.bias_clamp; + rs_state.depthBiasSlopeFactor = desc->depth.bias_slope_scale; + rs_state.lineWidth = 1.0f; + + _SG_STRUCT(VkPipelineMultisampleStateCreateInfo, ms_state); + ms_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; + ms_state.rasterizationSamples = (VkSampleCountFlagBits)desc->sample_count; + ms_state.alphaToCoverageEnable = desc->alpha_to_coverage_enabled; + + _SG_STRUCT(VkPipelineDepthStencilStateCreateInfo, ds_state); + ds_state.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; + ds_state.depthTestEnable = desc->depth.compare != SG_COMPAREFUNC_ALWAYS; + ds_state.depthWriteEnable = desc->depth.write_enabled; + ds_state.depthCompareOp = _sg_vk_compare_op(desc->depth.compare); + ds_state.depthBoundsTestEnable = false; + ds_state.stencilTestEnable = desc->stencil.enabled; + ds_state.front.failOp = _sg_vk_stencil_op(desc->stencil.front.fail_op); + ds_state.front.passOp = _sg_vk_stencil_op(desc->stencil.front.pass_op); + ds_state.front.depthFailOp = _sg_vk_stencil_op(desc->stencil.front.depth_fail_op); + ds_state.front.compareOp = _sg_vk_compare_op(desc->stencil.front.compare); + ds_state.front.compareMask = desc->stencil.read_mask; + ds_state.front.writeMask = desc->stencil.write_mask; + ds_state.front.reference = desc->stencil.ref; + ds_state.back.failOp = _sg_vk_stencil_op(desc->stencil.back.fail_op); + ds_state.back.passOp = _sg_vk_stencil_op(desc->stencil.back.pass_op); + ds_state.back.depthFailOp = _sg_vk_stencil_op(desc->stencil.back.depth_fail_op); + ds_state.back.compareOp = _sg_vk_compare_op(desc->stencil.back.compare); + ds_state.back.compareMask = desc->stencil.read_mask; + ds_state.back.writeMask = desc->stencil.write_mask; + ds_state.back.reference = desc->stencil.ref; + + _SG_STRUCT(VkPipelineColorBlendAttachmentState, att_states[SG_MAX_COLOR_ATTACHMENTS]); + SOKOL_ASSERT(desc->color_count < SG_MAX_COLOR_ATTACHMENTS); + for (int i = 0; i < desc->color_count; i++) { + att_states[i].blendEnable = desc->colors[i].blend.enabled; + att_states[i].srcColorBlendFactor = _sg_vk_blend_factor(desc->colors[i].blend.src_factor_rgb); + att_states[i].dstColorBlendFactor = _sg_vk_blend_factor(desc->colors[i].blend.dst_factor_rgb); + att_states[i].colorBlendOp = _sg_vk_blend_op(desc->colors[i].blend.op_rgb); + att_states[i].srcAlphaBlendFactor = _sg_vk_blend_factor(desc->colors[i].blend.src_factor_alpha); + att_states[i].dstAlphaBlendFactor = _sg_vk_blend_factor(desc->colors[i].blend.dst_factor_alpha); + att_states[i].alphaBlendOp = _sg_vk_blend_op(desc->colors[i].blend.op_alpha); + att_states[i].colorWriteMask = _sg_vk_color_write_mask(desc->colors[i].write_mask); + } + + _SG_STRUCT(VkPipelineColorBlendStateCreateInfo, cb_state); + cb_state.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; + cb_state.logicOpEnable = false; + cb_state.attachmentCount = (uint32_t)desc->color_count; + cb_state.pAttachments = att_states; + cb_state.blendConstants[0] = desc->blend_color.r; + cb_state.blendConstants[1] = desc->blend_color.g; + cb_state.blendConstants[2] = desc->blend_color.b; + cb_state.blendConstants[3] = desc->blend_color.a; + + _SG_STRUCT(VkFormat, color_formats[SG_MAX_COLOR_ATTACHMENTS]); + SOKOL_ASSERT(desc->color_count <= SG_MAX_COLOR_ATTACHMENTS); + for (int i = 0; i < desc->color_count; i++) { + color_formats[i] = _sg_vk_format(desc->colors[i].pixel_format); + } + _SG_STRUCT(VkPipelineRenderingCreateInfo, rnd_state); + rnd_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO; + rnd_state.colorAttachmentCount = (uint32_t)desc->color_count; + rnd_state.pColorAttachmentFormats = color_formats; + rnd_state.depthAttachmentFormat = _sg_vk_format(desc->depth.pixel_format); + if (_sg_is_depth_stencil_format(desc->depth.pixel_format)) { + rnd_state.stencilAttachmentFormat = _sg_vk_format(desc->depth.pixel_format); + } else { + rnd_state.stencilAttachmentFormat = VK_FORMAT_UNDEFINED; + } + VkDynamicState dyn_states[2] = { + VK_DYNAMIC_STATE_VIEWPORT, + VK_DYNAMIC_STATE_SCISSOR, + }; + _SG_STRUCT(VkPipelineDynamicStateCreateInfo, dyn_state); + dyn_state.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + dyn_state.dynamicStateCount = 2; + dyn_state.pDynamicStates = dyn_states; + + _SG_STRUCT(VkGraphicsPipelineCreateInfo, pip_create_info); + pip_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; + pip_create_info.pNext = &rnd_state; + pip_create_info.flags = VK_PIPELINE_CREATE_DESCRIPTOR_BUFFER_BIT_EXT; + pip_create_info.stageCount = num_stages; + pip_create_info.pStages = stages; + pip_create_info.pVertexInputState = &vi_state; + pip_create_info.pInputAssemblyState = &ia_state; + pip_create_info.pViewportState = &vp_state; + pip_create_info.pRasterizationState = &rs_state; + pip_create_info.pMultisampleState = &ms_state; + pip_create_info.pDepthStencilState = &ds_state; + pip_create_info.pColorBlendState = &cb_state; + pip_create_info.pDynamicState = &dyn_state; + pip_create_info.layout = shd->vk.pip_layout; + + res = vkCreateGraphicsPipelines(_sg.vk.dev, VK_NULL_HANDLE, 1, &pip_create_info, 0, &pip->vk.pip); + if (res != VK_SUCCESS) { + _SG_ERROR(VULKAN_CREATE_GRAPHICS_PIPELINE_FAILED); + return SG_RESOURCESTATE_FAILED; + } + } + SOKOL_ASSERT(pip->vk.pip); + _sg_vk_set_object_label(VK_OBJECT_TYPE_PIPELINE, (uint64_t)pip->vk.pip, desc->label); + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_vk_discard_pipeline(_sg_pipeline_t* pip) { + SOKOL_ASSERT(pip); + if (pip->vk.pip) { + _sg_vk_delete_queue_add(_sg_vk_pipeline_destructor, (void*)pip->vk.pip); + pip->vk.pip = 0; + } +} + +_SOKOL_PRIVATE sg_resource_state _sg_vk_create_view(_sg_view_t* view, const sg_view_desc* desc) { + SOKOL_ASSERT(view && desc); + SOKOL_ASSERT(_sg.vk.dev); + SOKOL_ASSERT(0 == view->vk.img_view); + VkResult res; + _SG_STRUCT(VkDescriptorGetInfoEXT, get_info); + get_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_GET_INFO_EXT; + if (view->cmn.type == SG_VIEWTYPE_STORAGEBUFFER) { + // record descriptor data for storage buffer + view->vk.descriptor_size = _sg.vk.descriptor_buffer_props.storageBufferDescriptorSize; + if (_SG_VK_MAX_DESCRIPTOR_DATA_SIZE < view->vk.descriptor_size) { + _SG_ERROR(VULKAN_VIEW_MAX_DESCRIPTOR_SIZE); + return SG_RESOURCESTATE_FAILED; + } + const _sg_buffer_t* buf = _sg_buffer_ref_ptr(&view->cmn.buf.ref); + SOKOL_ASSERT(buf->vk.dev_addr); + _SG_STRUCT(VkDescriptorAddressInfoEXT, addr_info); + addr_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_ADDRESS_INFO_EXT; + addr_info.address = buf->vk.dev_addr + (VkDeviceSize)view->cmn.buf.offset; + addr_info.range = (VkDeviceSize)(buf->cmn.size - view->cmn.buf.offset); + get_info.type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; + get_info.data.pStorageBuffer = &addr_info; + _sg.vk.ext.get_descriptor(_sg.vk.dev, &get_info, view->vk.descriptor_size, &view->vk.descriptor_data); + } else { + // create image view object + const _sg_image_t* img = _sg_image_ref_ptr(&view->cmn.img.ref); + SOKOL_ASSERT(img->vk.img); + SOKOL_ASSERT(view->cmn.img.mip_level_count >= 1); + SOKOL_ASSERT(view->cmn.img.slice_count >= 1); + _SG_STRUCT(VkImageViewCreateInfo, create_info); + create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + create_info.image = img->vk.img; + if (view->cmn.type == SG_VIEWTYPE_TEXTURE) { + create_info.viewType = _sg_vk_texture_image_view_type(img->cmn.type); + } else { + create_info.viewType = _sg_vk_attachment_image_view_type(img->cmn.type); + } + create_info.format = _sg_vk_format(img->cmn.pixel_format); + if (view->cmn.type == SG_VIEWTYPE_DEPTHSTENCILATTACHMENT) { + create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; + if (_sg_is_depth_stencil_format(img->cmn.pixel_format)) { + create_info.subresourceRange.aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT; + } + } else if (_sg_is_depth_or_depth_stencil_format(img->cmn.pixel_format)) { + create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; + } else { + create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + } + create_info.subresourceRange.baseMipLevel = (uint32_t)view->cmn.img.mip_level; + create_info.subresourceRange.levelCount = (uint32_t)view->cmn.img.mip_level_count; + create_info.subresourceRange.baseArrayLayer = (uint32_t)view->cmn.img.slice; + create_info.subresourceRange.layerCount = (uint32_t)view->cmn.img.slice_count; + res = vkCreateImageView(_sg.vk.dev, &create_info, 0, &view->vk.img_view); + if (res != VK_SUCCESS) { + _SG_ERROR(VULKAN_CREATE_IMAGE_VIEW_FAILED); + return SG_RESOURCESTATE_FAILED; + } + SOKOL_ASSERT(view->vk.img_view); + _sg_vk_set_object_label(VK_OBJECT_TYPE_IMAGE_VIEW, (uint64_t)view->vk.img_view, desc->label); + + // record descriptor data for storage images and textures + if ((view->cmn.type == SG_VIEWTYPE_STORAGEIMAGE) || (view->cmn.type == SG_VIEWTYPE_TEXTURE)) { + _SG_STRUCT(VkDescriptorImageInfo, img_info); + img_info.imageView = view->vk.img_view; + if (view->cmn.type == SG_VIEWTYPE_STORAGEIMAGE) { + view->vk.descriptor_size = _sg.vk.descriptor_buffer_props.storageImageDescriptorSize; + img_info.imageLayout = VK_IMAGE_LAYOUT_GENERAL; + get_info.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; + get_info.data.pStorageImage = &img_info; + } else { + view->vk.descriptor_size = _sg.vk.descriptor_buffer_props.sampledImageDescriptorSize; + img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + get_info.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; + get_info.data.pSampledImage = &img_info; + } + if (_SG_VK_MAX_DESCRIPTOR_DATA_SIZE < view->vk.descriptor_size) { + _SG_ERROR(VULKAN_VIEW_MAX_DESCRIPTOR_SIZE); + return SG_RESOURCESTATE_FAILED; + } + _sg.vk.ext.get_descriptor(_sg.vk.dev, &get_info, view->vk.descriptor_size, &view->vk.descriptor_data); + } + } + return SG_RESOURCESTATE_VALID; +} + +_SOKOL_PRIVATE void _sg_vk_discard_view(_sg_view_t* view) { + SOKOL_ASSERT(view); + if (view->vk.img_view) { + _sg_vk_delete_queue_add(_sg_vk_image_view_destructor, (void*)view->vk.img_view); + view->vk.img_view = 0; + } +} + +_SOKOL_PRIVATE void _sg_vk_apply_viewport(int x, int y, int w, int h, bool origin_top_left) { + SOKOL_ASSERT(_sg.vk.frame.cmd_buf); + _SG_STRUCT(VkViewport, vp); + vp.x = (float) x; + vp.width = (float) w; + vp.height = (float) -h; + vp.maxDepth = 1.0f; + if (origin_top_left) { + vp.y = (float)(y + h); + } else { + vp.y = (float)(_sg.cur_pass.dim.height - y); + } + vkCmdSetViewport(_sg.vk.frame.cmd_buf, 0, 1, &vp); +} + +_SOKOL_PRIVATE void _sg_vk_apply_scissor_rect(int x, int y, int w, int h, bool origin_top_left) { + SOKOL_ASSERT(_sg.vk.frame.cmd_buf); + const _sg_recti_t clip = _sg_clipi(x, y, w, h, _sg.cur_pass.dim.width, _sg.cur_pass.dim.height); + _SG_STRUCT(VkRect2D, rect); + rect.offset.x = clip.x; + rect.offset.y = (origin_top_left ? clip.y : (_sg.cur_pass.dim.height - (clip.y + clip.h))); + rect.extent.width = (uint32_t) clip.w; + rect.extent.height = (uint32_t) clip.h; + vkCmdSetScissor(_sg.vk.frame.cmd_buf, 0, 1, &rect); +} + +_SOKOL_PRIVATE void _sg_vk_init_color_attachment_info(VkRenderingAttachmentInfo* info, const sg_color_attachment_action* action, VkImageView color_view, VkImageView resolve_view) { + info->sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO; + info->imageView = color_view; + info->imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + if (resolve_view) { + info->resolveMode = VK_RESOLVE_MODE_AVERAGE_BIT; + info->resolveImageView = resolve_view; + info->resolveImageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + } else { + info->resolveMode = VK_RESOLVE_MODE_NONE; + info->resolveImageView = 0; + info->resolveImageLayout = VK_IMAGE_LAYOUT_UNDEFINED; + } + info->loadOp = _sg_vk_load_op(action->load_action); + info->storeOp = _sg_vk_store_op(action->store_action); + info->clearValue.color.float32[0] = action->clear_value.r; + info->clearValue.color.float32[1] = action->clear_value.g; + info->clearValue.color.float32[2] = action->clear_value.b; + info->clearValue.color.float32[3] = action->clear_value.a; +} + +_SOKOL_PRIVATE void _sg_vk_init_depth_attachment_info(VkRenderingAttachmentInfo* info, const sg_depth_attachment_action* action, VkImageView ds_view) { + info->sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO; + info->imageView = ds_view; + info->imageLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL; + info->resolveMode = VK_RESOLVE_MODE_NONE; + info->loadOp = _sg_vk_load_op(action->load_action); + info->storeOp = _sg_vk_store_op(action->store_action); + info->clearValue.depthStencil.depth = action->clear_value; +} + +_SOKOL_PRIVATE void _sg_vk_init_stencil_attachment_info(VkRenderingAttachmentInfo* info, const sg_stencil_attachment_action* action, VkImageView ds_view) { + info->sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO; + info->imageView = ds_view; + info->imageLayout = VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL; + info->resolveMode = VK_RESOLVE_MODE_NONE; + info->loadOp = _sg_vk_load_op(action->load_action); + info->storeOp = _sg_vk_store_op(action->store_action); + info->clearValue.depthStencil.stencil = action->clear_value; +} + +_SOKOL_PRIVATE void _sg_vk_begin_compute_pass(VkCommandBuffer cmd_buf, const sg_pass* pass) { + // FIXME: nothing to do here? + _SOKOL_UNUSED(cmd_buf && pass); +} + +_SOKOL_PRIVATE void _sg_vk_begin_render_pass(VkCommandBuffer cmd_buf, const sg_pass* pass, const _sg_attachments_ptrs_t* atts) { + const sg_pass_action* action = &pass->action; + const bool is_swapchain_pass = atts->empty; + + _SG_STRUCT(VkRenderingAttachmentInfo, color_att_infos[SG_MAX_COLOR_ATTACHMENTS]); + _SG_STRUCT(VkRenderingAttachmentInfo, depth_att_info); + _SG_STRUCT(VkRenderingAttachmentInfo, stencil_att_info); + _SG_STRUCT(VkRenderingInfo, render_info); + render_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO; + render_info.renderArea.extent.width = (uint32_t)_sg.cur_pass.dim.width; + render_info.renderArea.extent.height = (uint32_t)_sg.cur_pass.dim.height; + render_info.layerCount = 1; + + if (is_swapchain_pass) { + _sg.vk.swapchain = pass->swapchain.vulkan; + SOKOL_ASSERT(_sg.vk.swapchain.render_view); + if (pass->swapchain.sample_count > 1) { + SOKOL_ASSERT(_sg.vk.swapchain.resolve_view); + } + SOKOL_ASSERT(_sg.vk.swapchain.present_complete_semaphore); + SOKOL_ASSERT(_sg.vk.swapchain.render_finished_semaphore); + // FIXME: need to support multiple present_complete_semaphores + SOKOL_ASSERT(0 == _sg.vk.present_complete_sem); + _sg.vk.present_complete_sem = (VkSemaphore)_sg.vk.swapchain.present_complete_semaphore; + if (0 == _sg.vk.render_finished_sem) { + _sg.vk.render_finished_sem = (VkSemaphore)_sg.vk.swapchain.render_finished_semaphore; + } else { + SOKOL_ASSERT(_sg.vk.render_finished_sem == _sg.vk.swapchain.render_finished_semaphore); + } + VkImageView vk_color_view = (VkImageView)_sg.vk.swapchain.render_view; + VkImageView vk_resolve_view = (VkImageView)_sg.vk.swapchain.resolve_view; + _sg_vk_init_color_attachment_info(&color_att_infos[0], &action->colors[0], vk_color_view, vk_resolve_view); + render_info.colorAttachmentCount = 1; + render_info.pColorAttachments = color_att_infos; + if (_sg.vk.swapchain.depth_stencil_view) { + VkImageView vk_ds_view = (VkImageView)_sg.vk.swapchain.depth_stencil_view; + const bool has_stencil = _sg_is_depth_stencil_format(pass->swapchain.depth_format); + _sg_vk_init_depth_attachment_info(&depth_att_info, &action->depth, vk_ds_view); + render_info.pDepthAttachment = &depth_att_info; + if (has_stencil) { + _sg_vk_init_stencil_attachment_info(&stencil_att_info, &action->stencil, vk_ds_view); + render_info.pStencilAttachment = &stencil_att_info; + } + } + } else { + SOKOL_ASSERT(atts->num_color_views <= SG_MAX_COLOR_ATTACHMENTS); + for (int i = 0; i < atts->num_color_views; i++) { + SOKOL_ASSERT(atts->color_views[i]); + const _sg_view_t* color_view = atts->color_views[i]; + VkImageView vk_color_view = color_view->vk.img_view; + const _sg_view_t* resolve_view = atts->resolve_views[i]; + VkImageView vk_resolve_view = 0; + if (resolve_view) { + vk_resolve_view = resolve_view->vk.img_view; + } + _sg_vk_init_color_attachment_info(&color_att_infos[i], &action->colors[i], vk_color_view, vk_resolve_view); + } + if (atts->num_color_views > 0) { + render_info.colorAttachmentCount = (uint32_t)atts->num_color_views; + render_info.pColorAttachments = color_att_infos; + } + if (atts->ds_view) { + const _sg_view_t* ds_view = atts->ds_view; + const _sg_image_t* ds_image = _sg_image_ref_ptr(&ds_view->cmn.img.ref); + const bool has_stencil = _sg_is_depth_stencil_format(ds_image->cmn.pixel_format); + VkImageView vk_ds_view = ds_view->vk.img_view; + _sg_vk_init_depth_attachment_info(&depth_att_info, &action->depth, vk_ds_view); + render_info.pDepthAttachment = &depth_att_info; + if (has_stencil) { + _sg_vk_init_stencil_attachment_info(&stencil_att_info, &action->stencil, vk_ds_view); + render_info.pStencilAttachment = &stencil_att_info; + } + } + } + vkCmdBeginRendering(cmd_buf, &render_info); + + _SG_STRUCT(VkViewport, vp); + vp.y = (float)_sg.cur_pass.dim.height; + vp.width = (float)_sg.cur_pass.dim.width; + vp.height = (float)-_sg.cur_pass.dim.height; + vp.maxDepth = 1.0f; + vkCmdSetViewport(_sg.vk.frame.cmd_buf, 0, 1, &vp); + + _SG_STRUCT(VkRect2D, rect); + rect.extent.width = (uint32_t)_sg.cur_pass.dim.width; + rect.extent.height = (uint32_t)_sg.cur_pass.dim.height; + vkCmdSetScissor(_sg.vk.frame.cmd_buf, 0, 1, &rect); +} + +_SOKOL_PRIVATE void _sg_vk_begin_pass(const sg_pass* pass, const _sg_attachments_ptrs_t* atts) { + SOKOL_ASSERT(pass && atts); + _sg_vk_acquire_frame_command_buffers(); + SOKOL_ASSERT(_sg.vk.frame.cmd_buf); + _sg_vk_barrier_on_begin_pass(_sg.vk.frame.cmd_buf, pass, atts, _sg.cur_pass.is_compute); + if (_sg.cur_pass.is_compute) { + _sg_vk_begin_compute_pass(_sg.vk.frame.cmd_buf, pass); + } else { + _sg_vk_begin_render_pass(_sg.vk.frame.cmd_buf, pass, atts); + } +} + +_SOKOL_PRIVATE void _sg_vk_end_pass(const _sg_attachments_ptrs_t* atts) { + SOKOL_ASSERT(atts); + SOKOL_ASSERT(_sg.vk.frame.cmd_buf); + if (!_sg.cur_pass.is_compute) { + vkCmdEndRendering(_sg.vk.frame.cmd_buf); + } + _sg_vk_barrier_on_end_pass(_sg.vk.frame.cmd_buf, atts, _sg.cur_pass.is_compute); + _sg_clear(&_sg.vk.swapchain, sizeof(_sg.vk.swapchain)); +} + +_SOKOL_PRIVATE void _sg_vk_commit(void) { + SOKOL_ASSERT(_sg.vk.queue); + if (_sg.vk.frame.cmd_buf) { + _sg_vk_submit_frame_command_buffers(); + } + _sg.vk.present_complete_sem = 0; + _sg.vk.render_finished_sem = 0; +} + +_SOKOL_PRIVATE void _sg_vk_apply_pipeline(_sg_pipeline_t* pip) { + SOKOL_ASSERT(pip); + SOKOL_ASSERT(pip->vk.pip); + SOKOL_ASSERT(_sg.vk.frame.cmd_buf); + _sg.vk.uniforms.dirty = false; + VkPipelineBindPoint bindpoint = pip->cmn.is_compute + ? VK_PIPELINE_BIND_POINT_COMPUTE + : VK_PIPELINE_BIND_POINT_GRAPHICS; + vkCmdBindPipeline(_sg.vk.frame.cmd_buf, bindpoint, pip->vk.pip); +} + +_SOKOL_PRIVATE bool _sg_vk_apply_bindings(_sg_bindings_ptrs_t* bnd) { + SOKOL_ASSERT(bnd && bnd->pip); + SOKOL_ASSERT(_sg.vk.dev); + SOKOL_ASSERT(_sg.vk.frame.cmd_buf); + VkCommandBuffer cmd_buf = _sg.vk.frame.cmd_buf; + + // track or insert pipeline barriers + _sg_vk_barrier_on_apply_bindings(cmd_buf, bnd, _sg.cur_pass.is_compute); + + if (!_sg.cur_pass.is_compute) { + // bind vertex buffers + // FIXME: could do this in a single call if buffer bindings are guaranteed + // to be continuous (currently that's not checked anywhere), or alternative + // via nullDescriptor robustness feature (which apparently may have performance downsides) + for (uint32_t i = 0; i < SG_MAX_VERTEXBUFFER_BINDSLOTS; i++) { + if (bnd->vbs[i]) { + VkBuffer vk_buf = bnd->vbs[i]->vk.buf; + VkDeviceSize vk_offset = (VkDeviceSize)bnd->vb_offsets[i]; + vkCmdBindVertexBuffers(cmd_buf, i, 1, &vk_buf, &vk_offset); + } + } + if (bnd->ib) { + VkBuffer vk_buf = bnd->ib->vk.buf; + VkDeviceSize vk_offset = (VkDeviceSize)bnd->ib_offset; + VkIndexType vk_index_type = _sg_vk_index_type(bnd->pip->cmn.index_type); + vkCmdBindIndexBuffer(cmd_buf, vk_buf, vk_offset, vk_index_type); + } + } + + // bind views and samplers + const VkPipelineBindPoint pip_bind_point = _sg.cur_pass.is_compute + ? VK_PIPELINE_BIND_POINT_COMPUTE + : VK_PIPELINE_BIND_POINT_GRAPHICS; + return _sg_vk_bind_view_smp_descriptor_set(cmd_buf, bnd, pip_bind_point); +} + +_SOKOL_PRIVATE void _sg_vk_apply_uniforms(int ub_slot, const sg_range* data) { + SOKOL_ASSERT(_sg.vk.uniforms.dbuf.cur_dev_addr); + SOKOL_ASSERT(data && data->ptr && (data->size > 0)); + SOKOL_ASSERT((ub_slot >= 0) && (ub_slot < SG_MAX_UNIFORMBLOCK_BINDSLOTS)); + const _sg_pipeline_t* pip = _sg_pipeline_ref_ptr(&_sg.cur_pip); + const _sg_shader_t* shd = _sg_shader_ref_ptr(&pip->cmn.shader); + SOKOL_ASSERT(data->size == shd->cmn.uniform_blocks[ub_slot].size); + + // copy data into uniform buffer and keep track of uniform bind infos + const VkDeviceSize ubuf_offset = _sg_vk_uniform_copy(data); + if (_sg.vk.uniforms.dbuf.overflown) { + _SG_ERROR(VULKAN_UNIFORM_BUFFER_OVERFLOW); + _sg.next_draw_valid = false; + return; + } + _sg.vk.uniforms.addr_info[ub_slot].range = data->size; + _sg.vk.uniforms.addr_info[ub_slot].address = _sg.vk.uniforms.dbuf.cur_dev_addr + ubuf_offset; + + // copy uniform buffer descriptor data into intermediate sysmem buffer + // NOTE: letting vkGetDescriptorEXT write directly into the descriptor + // buffer has catastrophic performance on some Vulkan drivers, notably + // Intel's Windows driver + const size_t dsize = _sg.vk.descriptor_buffer_props.uniformBufferDescriptorSize; + SOKOL_ASSERT((shd->vk.ub_dset_offsets[ub_slot] + dsize) <= _sg.vk.uniforms.dset_cache_size); + uint8_t* dst_ptr = _sg.vk.uniforms.dset_cache + shd->vk.ub_dset_offsets[ub_slot]; + _sg.vk.ext.get_descriptor(_sg.vk.dev, &_sg.vk.uniforms.get_info[ub_slot], dsize, dst_ptr); + + // set uniforms dirty, applying the descriptor buffer offset is happens in draw/dispatch + _sg.vk.uniforms.dirty = true; +} + +_SOKOL_PRIVATE void _sg_vk_draw(int base_element, int num_elements, int num_instances, int base_vertex, int base_instance) { + SOKOL_ASSERT(_sg.vk.frame.cmd_buf); + VkCommandBuffer cmd_buf = _sg.vk.frame.cmd_buf; + if (_sg.vk.uniforms.dirty) { + if (!_sg_vk_bind_uniform_descriptor_set(cmd_buf)) { + return; + } + } + if (_sg.use_indexed_draw) { + vkCmdDrawIndexed(cmd_buf, + (uint32_t)num_elements, + (uint32_t)num_instances, + (uint32_t)base_element, + base_vertex, + (uint32_t)base_instance); + } else { + vkCmdDraw(cmd_buf, + (uint32_t)num_elements, + (uint32_t)num_instances, + (uint32_t)base_element, + (uint32_t)base_instance); + } +} + +_SOKOL_PRIVATE void _sg_vk_dispatch(int num_groups_x, int num_groups_y, int num_groups_z) { + SOKOL_ASSERT(_sg.vk.frame.cmd_buf); + VkCommandBuffer cmd_buf = _sg.vk.frame.cmd_buf; + if (_sg.vk.uniforms.dirty) { + if (!_sg_vk_bind_uniform_descriptor_set(cmd_buf)) { + return; + } + } + vkCmdDispatch(cmd_buf, (uint32_t)num_groups_x, (uint32_t)num_groups_y, (uint32_t)num_groups_z); +} + +_SOKOL_PRIVATE void _sg_vk_update_buffer(_sg_buffer_t* buf, const sg_range* data) { + SOKOL_ASSERT(buf && data && data->ptr && (data->size > 0)); + if (buf->cmn.usage.stream_update) { + _sg_vk_acquire_frame_command_buffers(); + _sg_vk_staging_stream_buffer_data(buf, data, 0); + } else { + _sg_vk_staging_copy_buffer_data(buf, data, 0, true); + } +} + +_SOKOL_PRIVATE void _sg_vk_append_buffer(_sg_buffer_t* buf, const sg_range* data, bool new_frame) { + SOKOL_ASSERT(buf && data && data->ptr && (data->size > 0)); + _SOKOL_UNUSED(new_frame); + if (buf->cmn.usage.stream_update) { + _sg_vk_acquire_frame_command_buffers(); + _sg_vk_staging_stream_buffer_data(buf, data, (size_t)buf->cmn.append_pos); + } else { + _sg_vk_staging_copy_buffer_data(buf, data, (size_t)buf->cmn.append_pos, true); + } +} + +_SOKOL_PRIVATE void _sg_vk_update_image(_sg_image_t* img, const sg_image_data* data) { + SOKOL_ASSERT(img && data); + if (img->cmn.usage.stream_update) { + _sg_vk_acquire_frame_command_buffers(); + _sg_vk_staging_stream_image_data(img, data); + } else { + _sg_vk_staging_copy_image_data(img, data, true); + } +} + +#endif + +// ██████ ███████ ███ ██ ███████ ██████ ██ ██████ ██████ █████ ██████ ██ ██ ███████ ███ ██ ██████ +// ██ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ +// ██ ███ █████ ██ ██ ██ █████ ██████ ██ ██ ██████ ███████ ██ █████ █████ ██ ██ ██ ██ ██ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ██████ ███████ ██ ████ ███████ ██ ██ ██ ██████ ██████ ██ ██ ██████ ██ ██ ███████ ██ ████ ██████ +// +// >>generic backend +static inline void _sg_setup_backend(const sg_desc* desc) { + #if defined(_SOKOL_ANY_GL) + _sg_gl_setup_backend(desc); + #elif defined(SOKOL_METAL) + _sg_mtl_setup_backend(desc); + #elif defined(SOKOL_D3D11) + _sg_d3d11_setup_backend(desc); + #elif defined(SOKOL_WGPU) + _sg_wgpu_setup_backend(desc); + #elif defined(SOKOL_VULKAN) + _sg_vk_setup_backend(desc); + #elif defined(SOKOL_DUMMY_BACKEND) + _sg_dummy_setup_backend(desc); + #else + #error("INVALID BACKEND"); + #endif +} + +static inline void _sg_discard_backend(void) { + #if defined(_SOKOL_ANY_GL) + _sg_gl_discard_backend(); + #elif defined(SOKOL_METAL) + _sg_mtl_discard_backend(); + #elif defined(SOKOL_D3D11) + _sg_d3d11_discard_backend(); + #elif defined(SOKOL_WGPU) + _sg_wgpu_discard_backend(); + #elif defined(SOKOL_VULKAN) + _sg_vk_discard_backend(); + #elif defined(SOKOL_DUMMY_BACKEND) + _sg_dummy_discard_backend(); + #else + #error("INVALID BACKEND"); + #endif +} + +static inline void _sg_reset_state_cache(void) { + #if defined(_SOKOL_ANY_GL) + _sg_gl_reset_state_cache(); + #elif defined(SOKOL_METAL) + _sg_mtl_reset_state_cache(); + #elif defined(SOKOL_D3D11) + _sg_d3d11_reset_state_cache(); + #elif defined(SOKOL_WGPU) + _sg_wgpu_reset_state_cache(); + #elif defined(SOKOL_VULKAN) + _sg_vk_reset_state_cache(); + #elif defined(SOKOL_DUMMY_BACKEND) + _sg_dummy_reset_state_cache(); + #else + #error("INVALID BACKEND"); + #endif +} + +static inline sg_resource_state _sg_create_buffer(_sg_buffer_t* buf, const sg_buffer_desc* desc) { + #if defined(_SOKOL_ANY_GL) + return _sg_gl_create_buffer(buf, desc); + #elif defined(SOKOL_METAL) + return _sg_mtl_create_buffer(buf, desc); + #elif defined(SOKOL_D3D11) + return _sg_d3d11_create_buffer(buf, desc); + #elif defined(SOKOL_WGPU) + return _sg_wgpu_create_buffer(buf, desc); + #elif defined(SOKOL_VULKAN) + return _sg_vk_create_buffer(buf, desc); + #elif defined(SOKOL_DUMMY_BACKEND) + return _sg_dummy_create_buffer(buf, desc); + #else + #error("INVALID BACKEND"); + #endif +} + +static inline void _sg_discard_buffer(_sg_buffer_t* buf) { + #if defined(_SOKOL_ANY_GL) + _sg_gl_discard_buffer(buf); + #elif defined(SOKOL_METAL) + _sg_mtl_discard_buffer(buf); + #elif defined(SOKOL_D3D11) + _sg_d3d11_discard_buffer(buf); + #elif defined(SOKOL_WGPU) + _sg_wgpu_discard_buffer(buf); + #elif defined(SOKOL_VULKAN) + _sg_vk_discard_buffer(buf); + #elif defined(SOKOL_DUMMY_BACKEND) + _sg_dummy_discard_buffer(buf); + #else + #error("INVALID BACKEND"); + #endif +} + +static inline sg_resource_state _sg_create_image(_sg_image_t* img, const sg_image_desc* desc) { + #if defined(_SOKOL_ANY_GL) + return _sg_gl_create_image(img, desc); + #elif defined(SOKOL_METAL) + return _sg_mtl_create_image(img, desc); + #elif defined(SOKOL_D3D11) + return _sg_d3d11_create_image(img, desc); + #elif defined(SOKOL_WGPU) + return _sg_wgpu_create_image(img, desc); + #elif defined(SOKOL_VULKAN) + return _sg_vk_create_image(img, desc); + #elif defined(SOKOL_DUMMY_BACKEND) + return _sg_dummy_create_image(img, desc); + #else + #error("INVALID BACKEND"); + #endif +} + +static inline void _sg_discard_image(_sg_image_t* img) { + #if defined(_SOKOL_ANY_GL) + _sg_gl_discard_image(img); + #elif defined(SOKOL_METAL) + _sg_mtl_discard_image(img); + #elif defined(SOKOL_D3D11) + _sg_d3d11_discard_image(img); + #elif defined(SOKOL_WGPU) + _sg_wgpu_discard_image(img); + #elif defined(SOKOL_VULKAN) + _sg_vk_discard_image(img); + #elif defined(SOKOL_DUMMY_BACKEND) + _sg_dummy_discard_image(img); + #else + #error("INVALID BACKEND"); + #endif +} + +static inline sg_resource_state _sg_create_sampler(_sg_sampler_t* smp, const sg_sampler_desc* desc) { + #if defined(_SOKOL_ANY_GL) + return _sg_gl_create_sampler(smp, desc); + #elif defined(SOKOL_METAL) + return _sg_mtl_create_sampler(smp, desc); + #elif defined(SOKOL_D3D11) + return _sg_d3d11_create_sampler(smp, desc); + #elif defined(SOKOL_WGPU) + return _sg_wgpu_create_sampler(smp, desc); + #elif defined(SOKOL_VULKAN) + return _sg_vk_create_sampler(smp, desc); + #elif defined(SOKOL_DUMMY_BACKEND) + return _sg_dummy_create_sampler(smp, desc); + #else + #error("INVALID BACKEND"); + #endif +} + +static inline void _sg_discard_sampler(_sg_sampler_t* smp) { + #if defined(_SOKOL_ANY_GL) + _sg_gl_discard_sampler(smp); + #elif defined(SOKOL_METAL) + _sg_mtl_discard_sampler(smp); + #elif defined(SOKOL_D3D11) + _sg_d3d11_discard_sampler(smp); + #elif defined(SOKOL_WGPU) + _sg_wgpu_discard_sampler(smp); + #elif defined(SOKOL_VULKAN) + _sg_vk_discard_sampler(smp); + #elif defined(SOKOL_DUMMY_BACKEND) + _sg_dummy_discard_sampler(smp); + #else + #error("INVALID BACKEND"); + #endif +} + +static inline sg_resource_state _sg_create_shader(_sg_shader_t* shd, const sg_shader_desc* desc) { + #if defined(_SOKOL_ANY_GL) + return _sg_gl_create_shader(shd, desc); + #elif defined(SOKOL_METAL) + return _sg_mtl_create_shader(shd, desc); + #elif defined(SOKOL_D3D11) + return _sg_d3d11_create_shader(shd, desc); + #elif defined(SOKOL_WGPU) + return _sg_wgpu_create_shader(shd, desc); + #elif defined(SOKOL_VULKAN) + return _sg_vk_create_shader(shd, desc); + #elif defined(SOKOL_DUMMY_BACKEND) + return _sg_dummy_create_shader(shd, desc); + #else + #error("INVALID BACKEND"); + #endif +} + +static inline void _sg_discard_shader(_sg_shader_t* shd) { + #if defined(_SOKOL_ANY_GL) + _sg_gl_discard_shader(shd); + #elif defined(SOKOL_METAL) + _sg_mtl_discard_shader(shd); + #elif defined(SOKOL_D3D11) + _sg_d3d11_discard_shader(shd); + #elif defined(SOKOL_WGPU) + _sg_wgpu_discard_shader(shd); + #elif defined(SOKOL_VULKAN) + _sg_vk_discard_shader(shd); + #elif defined(SOKOL_DUMMY_BACKEND) + _sg_dummy_discard_shader(shd); + #else + #error("INVALID BACKEND"); + #endif +} + +static inline sg_resource_state _sg_create_pipeline(_sg_pipeline_t* pip, const sg_pipeline_desc* desc) { + #if defined(_SOKOL_ANY_GL) + return _sg_gl_create_pipeline(pip, desc); + #elif defined(SOKOL_METAL) + return _sg_mtl_create_pipeline(pip, desc); + #elif defined(SOKOL_D3D11) + return _sg_d3d11_create_pipeline(pip, desc); + #elif defined(SOKOL_WGPU) + return _sg_wgpu_create_pipeline(pip, desc); + #elif defined(SOKOL_VULKAN) + return _sg_vk_create_pipeline(pip, desc); + #elif defined(SOKOL_DUMMY_BACKEND) + return _sg_dummy_create_pipeline(pip, desc); + #else + #error("INVALID BACKEND"); + #endif +} + +static inline void _sg_discard_pipeline(_sg_pipeline_t* pip) { + #if defined(_SOKOL_ANY_GL) + _sg_gl_discard_pipeline(pip); + #elif defined(SOKOL_METAL) + _sg_mtl_discard_pipeline(pip); + #elif defined(SOKOL_D3D11) + _sg_d3d11_discard_pipeline(pip); + #elif defined(SOKOL_WGPU) + _sg_wgpu_discard_pipeline(pip); + #elif defined(SOKOL_VULKAN) + _sg_vk_discard_pipeline(pip); + #elif defined(SOKOL_DUMMY_BACKEND) + _sg_dummy_discard_pipeline(pip); + #else + #error("INVALID BACKEND"); + #endif +} + +static inline sg_resource_state _sg_create_view(_sg_view_t* view, const sg_view_desc* desc) { + #if defined(_SOKOL_ANY_GL) + return _sg_gl_create_view(view, desc); + #elif defined(SOKOL_METAL) + return _sg_mtl_create_view(view, desc); + #elif defined(SOKOL_D3D11) + return _sg_d3d11_create_view(view, desc); + #elif defined(SOKOL_WGPU) + return _sg_wgpu_create_view(view, desc); + #elif defined(SOKOL_VULKAN) + return _sg_vk_create_view(view, desc); + #elif defined(SOKOL_DUMMY_BACKEND) + return _sg_dummy_create_view(view, desc); + #else + #error("INVALID BACKEND"); + #endif +} + +static inline void _sg_discard_view(_sg_view_t* view) { + #if defined(_SOKOL_ANY_GL) + _sg_gl_discard_view(view); + #elif defined(SOKOL_METAL) + _sg_mtl_discard_view(view); + #elif defined(SOKOL_D3D11) + _sg_d3d11_discard_view(view); + #elif defined(SOKOL_WGPU) + _sg_wgpu_discard_view(view); + #elif defined(SOKOL_VULKAN) + _sg_vk_discard_view(view); + #elif defined(SOKOL_DUMMY_BACKEND) + _sg_dummy_discard_view(view); + #else + #error("INVALID BACKEND"); + #endif +} + +static inline void _sg_begin_pass(const sg_pass* pass, const _sg_attachments_ptrs_t* atts) { + #if defined(_SOKOL_ANY_GL) + _sg_gl_begin_pass(pass, atts); + #elif defined(SOKOL_METAL) + _sg_mtl_begin_pass(pass, atts); + #elif defined(SOKOL_D3D11) + _sg_d3d11_begin_pass(pass, atts); + #elif defined(SOKOL_WGPU) + _sg_wgpu_begin_pass(pass, atts); + #elif defined(SOKOL_VULKAN) + _sg_vk_begin_pass(pass, atts); + #elif defined(SOKOL_DUMMY_BACKEND) + _sg_dummy_begin_pass(pass, atts); + #else + #error("INVALID BACKEND"); + #endif +} + +static inline void _sg_end_pass(const _sg_attachments_ptrs_t* atts) { + #if defined(_SOKOL_ANY_GL) + _sg_gl_end_pass(atts); + #elif defined(SOKOL_METAL) + _sg_mtl_end_pass(atts); + #elif defined(SOKOL_D3D11) + _sg_d3d11_end_pass(atts); + #elif defined(SOKOL_WGPU) + _sg_wgpu_end_pass(atts); + #elif defined(SOKOL_VULKAN) + _sg_vk_end_pass(atts); + #elif defined(SOKOL_DUMMY_BACKEND) + _sg_dummy_end_pass(atts); + #else + #error("INVALID BACKEND"); + #endif +} + +static inline void _sg_apply_viewport(int x, int y, int w, int h, bool origin_top_left) { + #if defined(_SOKOL_ANY_GL) + _sg_gl_apply_viewport(x, y, w, h, origin_top_left); + #elif defined(SOKOL_METAL) + _sg_mtl_apply_viewport(x, y, w, h, origin_top_left); + #elif defined(SOKOL_D3D11) + _sg_d3d11_apply_viewport(x, y, w, h, origin_top_left); + #elif defined(SOKOL_WGPU) + _sg_wgpu_apply_viewport(x, y, w, h, origin_top_left); + #elif defined(SOKOL_VULKAN) + _sg_vk_apply_viewport(x, y, w, h, origin_top_left); + #elif defined(SOKOL_DUMMY_BACKEND) + _sg_dummy_apply_viewport(x, y, w, h, origin_top_left); + #else + #error("INVALID BACKEND"); + #endif +} + +static inline void _sg_apply_scissor_rect(int x, int y, int w, int h, bool origin_top_left) { + #if defined(_SOKOL_ANY_GL) + _sg_gl_apply_scissor_rect(x, y, w, h, origin_top_left); + #elif defined(SOKOL_METAL) + _sg_mtl_apply_scissor_rect(x, y, w, h, origin_top_left); + #elif defined(SOKOL_D3D11) + _sg_d3d11_apply_scissor_rect(x, y, w, h, origin_top_left); + #elif defined(SOKOL_WGPU) + _sg_wgpu_apply_scissor_rect(x, y, w, h, origin_top_left); + #elif defined(SOKOL_VULKAN) + _sg_vk_apply_scissor_rect(x, y, w, h, origin_top_left); + #elif defined(SOKOL_DUMMY_BACKEND) + _sg_dummy_apply_scissor_rect(x, y, w, h, origin_top_left); + #else + #error("INVALID BACKEND"); + #endif +} + +static inline void _sg_apply_pipeline(_sg_pipeline_t* pip) { + #if defined(_SOKOL_ANY_GL) + _sg_gl_apply_pipeline(pip); + #elif defined(SOKOL_METAL) + _sg_mtl_apply_pipeline(pip); + #elif defined(SOKOL_D3D11) + _sg_d3d11_apply_pipeline(pip); + #elif defined(SOKOL_WGPU) + _sg_wgpu_apply_pipeline(pip); + #elif defined(SOKOL_VULKAN) + _sg_vk_apply_pipeline(pip); + #elif defined(SOKOL_DUMMY_BACKEND) + _sg_dummy_apply_pipeline(pip); + #else + #error("INVALID BACKEND"); + #endif +} + +static inline bool _sg_apply_bindings(_sg_bindings_ptrs_t* bnd) { + #if defined(_SOKOL_ANY_GL) + return _sg_gl_apply_bindings(bnd); + #elif defined(SOKOL_METAL) + return _sg_mtl_apply_bindings(bnd); + #elif defined(SOKOL_D3D11) + return _sg_d3d11_apply_bindings(bnd); + #elif defined(SOKOL_WGPU) + return _sg_wgpu_apply_bindings(bnd); + #elif defined(SOKOL_VULKAN) + return _sg_vk_apply_bindings(bnd); + #elif defined(SOKOL_DUMMY_BACKEND) + return _sg_dummy_apply_bindings(bnd); + #else + #error("INVALID BACKEND"); + #endif +} + +static inline void _sg_apply_uniforms(int ub_slot, const sg_range* data) { + #if defined(_SOKOL_ANY_GL) + _sg_gl_apply_uniforms(ub_slot, data); + #elif defined(SOKOL_METAL) + _sg_mtl_apply_uniforms(ub_slot, data); + #elif defined(SOKOL_D3D11) + _sg_d3d11_apply_uniforms(ub_slot, data); + #elif defined(SOKOL_WGPU) + _sg_wgpu_apply_uniforms(ub_slot, data); + #elif defined(SOKOL_VULKAN) + _sg_vk_apply_uniforms(ub_slot, data); + #elif defined(SOKOL_DUMMY_BACKEND) + _sg_dummy_apply_uniforms(ub_slot, data); + #else + #error("INVALID BACKEND"); + #endif +} + +static inline void _sg_draw(int base_element, int num_elements, int num_instances, int base_vertex, int base_index) { + #if defined(_SOKOL_ANY_GL) + _sg_gl_draw(base_element, num_elements, num_instances, base_vertex, base_index); + #elif defined(SOKOL_METAL) + _sg_mtl_draw(base_element, num_elements, num_instances, base_vertex, base_index); + #elif defined(SOKOL_D3D11) + _sg_d3d11_draw(base_element, num_elements, num_instances, base_vertex, base_index); + #elif defined(SOKOL_WGPU) + _sg_wgpu_draw(base_element, num_elements, num_instances, base_vertex, base_index); + #elif defined(SOKOL_VULKAN) + _sg_vk_draw(base_element, num_elements, num_instances, base_vertex, base_index); + #elif defined(SOKOL_DUMMY_BACKEND) + _sg_dummy_draw(base_element, num_elements, num_instances, base_vertex, base_index); + #else + #error("INVALID BACKEND"); + #endif +} + +static inline void _sg_dispatch(int num_groups_x, int num_groups_y, int num_groups_z) { + #if defined(_SOKOL_ANY_GL) + _sg_gl_dispatch(num_groups_x, num_groups_y, num_groups_z); + #elif defined(SOKOL_METAL) + _sg_mtl_dispatch(num_groups_x, num_groups_y, num_groups_z); + #elif defined(SOKOL_D3D11) + _sg_d3d11_dispatch(num_groups_x, num_groups_y, num_groups_z); + #elif defined(SOKOL_WGPU) + _sg_wgpu_dispatch(num_groups_x, num_groups_y, num_groups_z); + #elif defined(SOKOL_VULKAN) + _sg_vk_dispatch(num_groups_x, num_groups_y, num_groups_z); + #elif defined(SOKOL_DUMMY_BACKEND) + _sg_dummy_dispatch(num_groups_x, num_groups_y, num_groups_z); + #else + #error("INVALID BACKEND"); + #endif +} + +static inline void _sg_commit(void) { + #if defined(_SOKOL_ANY_GL) + _sg_gl_commit(); + #elif defined(SOKOL_METAL) + _sg_mtl_commit(); + #elif defined(SOKOL_D3D11) + _sg_d3d11_commit(); + #elif defined(SOKOL_WGPU) + _sg_wgpu_commit(); + #elif defined(SOKOL_VULKAN) + _sg_vk_commit(); + #elif defined(SOKOL_DUMMY_BACKEND) + _sg_dummy_commit(); + #else + #error("INVALID BACKEND"); + #endif +} + +static inline void _sg_update_buffer(_sg_buffer_t* buf, const sg_range* data) { + #if defined(_SOKOL_ANY_GL) + _sg_gl_update_buffer(buf, data); + #elif defined(SOKOL_METAL) + _sg_mtl_update_buffer(buf, data); + #elif defined(SOKOL_D3D11) + _sg_d3d11_update_buffer(buf, data); + #elif defined(SOKOL_WGPU) + _sg_wgpu_update_buffer(buf, data); + #elif defined(SOKOL_VULKAN) + _sg_vk_update_buffer(buf, data); + #elif defined(SOKOL_DUMMY_BACKEND) + _sg_dummy_update_buffer(buf, data); + #else + #error("INVALID BACKEND"); + #endif +} + +static inline void _sg_append_buffer(_sg_buffer_t* buf, const sg_range* data, bool new_frame) { + #if defined(_SOKOL_ANY_GL) + _sg_gl_append_buffer(buf, data, new_frame); + #elif defined(SOKOL_METAL) + _sg_mtl_append_buffer(buf, data, new_frame); + #elif defined(SOKOL_D3D11) + _sg_d3d11_append_buffer(buf, data, new_frame); + #elif defined(SOKOL_WGPU) + _sg_wgpu_append_buffer(buf, data, new_frame); + #elif defined(SOKOL_VULKAN) + _sg_vk_append_buffer(buf, data, new_frame); + #elif defined(SOKOL_DUMMY_BACKEND) + _sg_dummy_append_buffer(buf, data, new_frame); + #else + #error("INVALID BACKEND"); + #endif +} + +static inline void _sg_update_image(_sg_image_t* img, const sg_image_data* data) { + #if defined(_SOKOL_ANY_GL) + _sg_gl_update_image(img, data); + #elif defined(SOKOL_METAL) + _sg_mtl_update_image(img, data); + #elif defined(SOKOL_D3D11) + _sg_d3d11_update_image(img, data); + #elif defined(SOKOL_WGPU) + _sg_wgpu_update_image(img, data); + #elif defined(SOKOL_VULKAN) + _sg_vk_update_image(img, data); + #elif defined(SOKOL_DUMMY_BACKEND) + _sg_dummy_update_image(img, data); + #else + #error("INVALID BACKEND"); + #endif +} + +static inline void _sg_push_debug_group(const char* name) { + #if defined(SOKOL_METAL) + _sg_mtl_push_debug_group(name); + #elif defined(SOKOL_D3D11) + _sg_d3d11_push_debug_group(name); + #else + _SOKOL_UNUSED(name); + #endif +} + +static inline void _sg_pop_debug_group(void) { + #if defined(SOKOL_METAL) + _sg_mtl_pop_debug_group(); + #elif defined(SOKOL_D3D11) + _sg_d3d11_pop_debug_group(); + #endif +} + +// ██ ██ █████ ██ ██ ██████ █████ ████████ ██ ██████ ███ ██ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ +// ██ ██ ███████ ██ ██ ██ ██ ███████ ██ ██ ██ ██ ██ ██ ██ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ████ ██ ██ ███████ ██ ██████ ██ ██ ██ ██ ██████ ██ ████ +// +// >>validation +#if defined(SOKOL_DEBUG) +_SOKOL_PRIVATE void _sg_validate_begin(void) { + _sg.validate_error = SG_LOGITEM_OK; +} + +_SOKOL_PRIVATE bool _sg_validate_end(void) { + if (_sg.validate_error != SG_LOGITEM_OK) { + #if !defined(SOKOL_VALIDATE_NON_FATAL) + _SG_PANIC(VALIDATION_FAILED); + return false; + #else + return false; + #endif + } else { + return true; + } +} +#endif + +_SOKOL_PRIVATE bool _sg_one(bool b0, bool b1, bool b2) { + return (b0 && !b1 && !b2) || (!b0 && b1 && !b2) || (!b0 && !b1 && b2); +} + +_SOKOL_PRIVATE bool _sg_validate_buffer_desc(const sg_buffer_desc* desc) { + #if !defined(SOKOL_DEBUG) + _SOKOL_UNUSED(desc); + return true; + #else + if (_sg.desc.disable_validation) { + return true; + } + SOKOL_ASSERT(desc); + _sg_validate_begin(); + _SG_VALIDATE(desc->_start_canary == 0, VALIDATE_BUFFERDESC_CANARY); + _SG_VALIDATE(desc->_end_canary == 0, VALIDATE_BUFFERDESC_CANARY); + _SG_VALIDATE(desc->size > 0, VALIDATE_BUFFERDESC_EXPECT_NONZERO_SIZE); + _SG_VALIDATE(_sg_one(desc->usage.immutable, desc->usage.dynamic_update, desc->usage.stream_update), VALIDATE_BUFFERDESC_IMMUTABLE_DYNAMIC_STREAM); + if (_sg.features.separate_buffer_types) { + _SG_VALIDATE(_sg_one(desc->usage.vertex_buffer, desc->usage.index_buffer, desc->usage.storage_buffer), VALIDATE_BUFFERDESC_SEPARATE_BUFFER_TYPES); + } + bool injected = (0 != desc->gl_buffers[0]) || + (0 != desc->mtl_buffers[0]) || + (0 != desc->d3d11_buffer) || + (0 != desc->wgpu_buffer); + if (!injected && desc->usage.immutable) { + if (desc->data.ptr) { + _SG_VALIDATE(desc->size == desc->data.size, VALIDATE_BUFFERDESC_EXPECT_MATCHING_DATA_SIZE); + } else { + _SG_VALIDATE(desc->usage.storage_buffer, VALIDATE_BUFFERDESC_EXPECT_DATA); + _SG_VALIDATE(desc->data.size == 0, VALIDATE_BUFFERDESC_EXPECT_ZERO_DATA_SIZE); + } + } else { + _SG_VALIDATE(0 == desc->data.ptr, VALIDATE_BUFFERDESC_EXPECT_NO_DATA); + _SG_VALIDATE(desc->data.size == 0, VALIDATE_BUFFERDESC_EXPECT_ZERO_DATA_SIZE); + } + if (desc->usage.storage_buffer) { + _SG_VALIDATE(_sg.features.compute, VALIDATE_BUFFERDESC_STORAGEBUFFER_SUPPORTED); + _SG_VALIDATE(_sg_multiple_u64(desc->size, 4), VALIDATE_BUFFERDESC_STORAGEBUFFER_SIZE_MULTIPLE_4); + } + return _sg_validate_end(); + #endif +} + +_SOKOL_PRIVATE void _sg_validate_image_data(const sg_image_data* data, sg_pixel_format fmt, int width, int height, int num_mips, int num_slices) { + #if !defined(SOKOL_DEBUG) + _SOKOL_UNUSED(data); + _SOKOL_UNUSED(fmt); + _SOKOL_UNUSED(width); + _SOKOL_UNUSED(height); + _SOKOL_UNUSED(num_mips); + _SOKOL_UNUSED(num_slices); + #else + for (int mip_index = 0; mip_index < num_mips; mip_index++) { + const bool has_data = data->mip_levels[mip_index].ptr != 0; + const bool has_size = data->mip_levels[mip_index].size > 0; + _SG_VALIDATE(has_data && has_size, VALIDATE_IMAGEDATA_NODATA); + const int mip_width = _sg_miplevel_dim(width, mip_index); + const int mip_height = _sg_miplevel_dim(height, mip_index); + const int bytes_per_slice = _sg_surface_pitch(fmt, mip_width, mip_height, 1); + const int expected_size = bytes_per_slice * num_slices; + _SG_VALIDATE(expected_size == (int)data->mip_levels[mip_index].size, VALIDATE_IMAGEDATA_DATA_SIZE); + } + #endif +} + +_SOKOL_PRIVATE bool _sg_validate_image_desc(const sg_image_desc* desc) { + #if !defined(SOKOL_DEBUG) + _SOKOL_UNUSED(desc); + return true; + #else + if (_sg.desc.disable_validation) { + return true; + } + SOKOL_ASSERT(desc); + const sg_image_usage* usg = &desc->usage; + const bool any_attachment = usg->color_attachment || usg->resolve_attachment || usg->depth_stencil_attachment; + _sg_validate_begin(); + _SG_VALIDATE(desc->_start_canary == 0, VALIDATE_IMAGEDESC_CANARY); + _SG_VALIDATE(desc->_end_canary == 0, VALIDATE_IMAGEDESC_CANARY); + _SG_VALIDATE(_sg_one(usg->immutable, usg->dynamic_update, usg->stream_update), VALIDATE_IMAGEDESC_IMMUTABLE_DYNAMIC_STREAM); + _SG_VALIDATE(!(usg->color_attachment && usg->depth_stencil_attachment), VALIDATE_IMAGEDESC_ATTACHMENT_COLOR_DEPTH_STENCIL); + switch (desc->type) { + case SG_IMAGETYPE_2D: + _SG_VALIDATE(desc->num_slices == 1, VALIDATE_IMAGEDESC_IMAGETYPE_2D_NUMSLICES); + break; + case SG_IMAGETYPE_CUBE: + _SG_VALIDATE(desc->num_slices == 6, VALIDATE_IMAGEDESC_IMAGETYPE_CUBE_NUMSLICES); + break; + case SG_IMAGETYPE_ARRAY: + _SG_VALIDATE((desc->num_slices >= 1) && (desc->num_slices <= _sg.limits.max_image_array_layers), VALIDATE_IMAGEDESC_IMAGETYPE_ARRAY_NUMSLICES); + break; + case SG_IMAGETYPE_3D: + _SG_VALIDATE((desc->num_slices >= 1) && (desc->num_slices <= _sg.limits.max_image_size_3d), VALIDATE_IMAGEDESC_IMAGETYPE_3D_NUMSLICES); + break; + default: + SOKOL_UNREACHABLE; + break; + } + _SG_VALIDATE(desc->width > 0, VALIDATE_IMAGEDESC_WIDTH); + _SG_VALIDATE(desc->height > 0, VALIDATE_IMAGEDESC_HEIGHT); + const sg_pixel_format fmt = desc->pixel_format; + const bool injected = (0 != desc->gl_textures[0]) || + (0 != desc->mtl_textures[0]) || + (0 != desc->d3d11_texture) || + (0 != desc->wgpu_texture); + if (_sg_is_depth_or_depth_stencil_format(fmt)) { + _SG_VALIDATE(desc->type != SG_IMAGETYPE_3D, VALIDATE_IMAGEDESC_DEPTH_3D_IMAGE); + } + if (any_attachment || usg->storage_image) { + SOKOL_ASSERT(((int)fmt >= 0) && ((int)fmt < _SG_PIXELFORMAT_NUM)); + _SG_VALIDATE(usg->immutable, VALIDATE_IMAGEDESC_ATTACHMENT_EXPECT_IMMUTABLE); + _SG_VALIDATE(desc->data.mip_levels[0].ptr==0, VALIDATE_IMAGEDESC_ATTACHMENT_EXPECT_NO_DATA); + if (any_attachment) { + _SG_VALIDATE(_sg.formats[fmt].render, VALIDATE_IMAGEDESC_ATTACHMENT_PIXELFORMAT); + if (usg->resolve_attachment) { + _SG_VALIDATE(desc->sample_count == 1, VALIDATE_IMAGEDESC_ATTACHMENT_RESOLVE_EXPECT_NO_MSAA); + } + if (desc->sample_count > 1) { + _SG_VALIDATE(_sg.formats[fmt].msaa, VALIDATE_IMAGEDESC_ATTACHMENT_NO_MSAA_SUPPORT); + _SG_VALIDATE(desc->num_mipmaps == 1, VALIDATE_IMAGEDESC_ATTACHMENT_MSAA_NUM_MIPMAPS); + _SG_VALIDATE(desc->type != SG_IMAGETYPE_ARRAY, VALIDATE_IMAGEDESC_ATTACHMENT_MSAA_ARRAY_IMAGE); + _SG_VALIDATE(desc->type != SG_IMAGETYPE_3D, VALIDATE_IMAGEDESC_ATTACHMENT_MSAA_3D_IMAGE); + _SG_VALIDATE(desc->type != SG_IMAGETYPE_CUBE, VALIDATE_IMAGEDESC_ATTACHMENT_MSAA_CUBE_IMAGE); + } + } else if (usg->storage_image) { + _SG_VALIDATE(_sg_is_valid_storage_image_format(fmt), VALIDATE_IMAGEDESC_STORAGEIMAGE_PIXELFORMAT); + // D3D11 doesn't allow multisampled UAVs (see: https://github.com/gpuweb/gpuweb/issues/513) + _SG_VALIDATE(desc->sample_count == 1, VALIDATE_IMAGEDESC_STORAGEIMAGE_EXPECT_NO_MSAA); + } + } else { + _SG_VALIDATE(desc->sample_count == 1, VALIDATE_IMAGEDESC_MSAA_BUT_NO_ATTACHMENT); + const bool valid_nonrt_fmt = !_sg_is_valid_attachment_depth_format(fmt); + _SG_VALIDATE(valid_nonrt_fmt, VALIDATE_IMAGEDESC_NONRT_PIXELFORMAT); + const bool is_compressed = _sg_is_compressed_pixel_format(desc->pixel_format); + if (is_compressed) { + _SG_VALIDATE(usg->immutable, VALIDATE_IMAGEDESC_COMPRESSED_IMMUTABLE); + } + if (!injected && usg->immutable) { + // image desc must have valid data + _sg_validate_image_data(&desc->data, + desc->pixel_format, + desc->width, + desc->height, + desc->num_mipmaps, + desc->num_slices); + } else { + // image desc must not have data + for (int mip_index = 0; mip_index < SG_MAX_MIPMAPS; mip_index++) { + const bool no_data = 0 == desc->data.mip_levels[mip_index].ptr; + const bool no_size = 0 == desc->data.mip_levels[mip_index].size; + if (injected) { + _SG_VALIDATE(no_data && no_size, VALIDATE_IMAGEDESC_INJECTED_NO_DATA); + } + if (!usg->immutable) { + _SG_VALIDATE(no_data && no_size, VALIDATE_IMAGEDESC_DYNAMIC_NO_DATA); + } + } + } + } + return _sg_validate_end(); + #endif +} + +_SOKOL_PRIVATE bool _sg_validate_sampler_desc(const sg_sampler_desc* desc) { + #if !defined(SOKOL_DEBUG) + _SOKOL_UNUSED(desc); + return true; + #else + if (_sg.desc.disable_validation) { + return true; + } + SOKOL_ASSERT(desc); + _sg_validate_begin(); + _SG_VALIDATE(desc->_start_canary == 0, VALIDATE_SAMPLERDESC_CANARY); + _SG_VALIDATE(desc->_end_canary == 0, VALIDATE_SAMPLERDESC_CANARY); + // restriction from WebGPU: when anisotropy > 1, all filters must be linear + if (desc->max_anisotropy > 1) { + _SG_VALIDATE((desc->min_filter == SG_FILTER_LINEAR) + && (desc->mag_filter == SG_FILTER_LINEAR) + && (desc->mipmap_filter == SG_FILTER_LINEAR), + VALIDATE_SAMPLERDESC_ANISTROPIC_REQUIRES_LINEAR_FILTERING); + } + return _sg_validate_end(); + #endif +} + +typedef struct { + uint64_t lo, hi; +} _sg_u128_t; + +_SOKOL_PRIVATE _sg_u128_t _sg_u128(void) { + _SG_STRUCT(_sg_u128_t, res); + return res; +} + +_SOKOL_PRIVATE _sg_u128_t _sg_validate_set_slot_bit(_sg_u128_t bits, sg_shader_stage stage, uint8_t slot) { + switch (stage) { + case SG_SHADERSTAGE_NONE: + SOKOL_ASSERT(slot < 128); + if (slot < 64) { + bits.lo |= 1ULL << slot; + } else { + bits.hi |= 1ULL << (slot - 64); + } + break; + case SG_SHADERSTAGE_VERTEX: + SOKOL_ASSERT(slot < 64); + bits.lo |= 1ULL << slot; + break; + case SG_SHADERSTAGE_FRAGMENT: + SOKOL_ASSERT(slot < 64); + bits.hi |= 1ULL << slot; + break; + case SG_SHADERSTAGE_COMPUTE: + SOKOL_ASSERT(slot < 64); + bits.lo |= 1ULL << slot; + break; + default: + SOKOL_UNREACHABLE; + break; + } + return bits; +} + +_SOKOL_PRIVATE bool _sg_validate_slot_bits(_sg_u128_t bits, sg_shader_stage stage, uint8_t slot) { + _sg_u128_t mask = _sg_u128(); + switch (stage) { + case SG_SHADERSTAGE_NONE: + SOKOL_ASSERT(slot < 128); + if (slot < 64) { + mask.lo = 1ULL << slot; + } else { + mask.hi = 1ULL << (slot - 64); + } + break; + case SG_SHADERSTAGE_VERTEX: + SOKOL_ASSERT(slot < 64); + mask.lo = 1ULL << slot; + break; + case SG_SHADERSTAGE_FRAGMENT: + SOKOL_ASSERT(slot < 64); + mask.hi = 1ULL << slot; + break; + case SG_SHADERSTAGE_COMPUTE: + SOKOL_ASSERT(slot < 64); + mask.lo = 1ULL << slot; + break; + default: + SOKOL_UNREACHABLE; + break; + } + return ((bits.lo & mask.lo) == 0) && ((bits.hi & mask.hi) == 0); +} + +_SOKOL_PRIVATE bool _sg_validate_shader_desc(const sg_shader_desc* desc) { + #if !defined(SOKOL_DEBUG) + _SOKOL_UNUSED(desc); + return true; + #else + if (_sg.desc.disable_validation) { + return true; + } + SOKOL_ASSERT(desc); + bool is_compute_shader = (desc->compute_func.source != 0) || (desc->compute_func.bytecode.ptr != 0); + _sg_validate_begin(); + _SG_VALIDATE(desc->_start_canary == 0, VALIDATE_SHADERDESC_CANARY); + _SG_VALIDATE(desc->_end_canary == 0, VALIDATE_SHADERDESC_CANARY); + #if defined(SOKOL_GLCORE) || defined(SOKOL_GLES3) || defined(SOKOL_WGPU) + // on GL or WebGPU, must provide shader source code + if (is_compute_shader) { + _SG_VALIDATE(0 != desc->compute_func.source, VALIDATE_SHADERDESC_COMPUTE_SOURCE); + } else { + _SG_VALIDATE(0 != desc->vertex_func.source, VALIDATE_SHADERDESC_VERTEX_SOURCE); + _SG_VALIDATE(0 != desc->fragment_func.source, VALIDATE_SHADERDESC_FRAGMENT_SOURCE); + } + #elif defined(SOKOL_METAL) || defined(SOKOL_D3D11) + // on Metal or D3D11, must provide shader source code or byte code + if (is_compute_shader) { + _SG_VALIDATE((0 != desc->compute_func.source) || (0 != desc->compute_func.bytecode.ptr), VALIDATE_SHADERDESC_COMPUTE_SOURCE_OR_BYTECODE); + } else { + _SG_VALIDATE((0 != desc->vertex_func.source)|| (0 != desc->vertex_func.bytecode.ptr), VALIDATE_SHADERDESC_VERTEX_SOURCE_OR_BYTECODE); + _SG_VALIDATE((0 != desc->fragment_func.source) || (0 != desc->fragment_func.bytecode.ptr), VALIDATE_SHADERDESC_FRAGMENT_SOURCE_OR_BYTECODE); + } + #else + // Dummy Backend, don't require source or bytecode + #endif + if (is_compute_shader) { + _SG_VALIDATE((0 == desc->vertex_func.source) && (0 == desc->vertex_func.bytecode.ptr), VALIDATE_SHADERDESC_INVALID_SHADER_COMBO); + _SG_VALIDATE((0 == desc->fragment_func.source) && (0 == desc->fragment_func.bytecode.ptr), VALIDATE_SHADERDESC_INVALID_SHADER_COMBO); + } else { + _SG_VALIDATE((0 == desc->compute_func.source) && (0 == desc->compute_func.bytecode.ptr), VALIDATE_SHADERDESC_INVALID_SHADER_COMBO); + } + #if defined(SOKOL_METAL) + if (is_compute_shader) { + int x = desc->mtl_threads_per_threadgroup.x; + int y = desc->mtl_threads_per_threadgroup.y; + int z = desc->mtl_threads_per_threadgroup.z; + _SG_VALIDATE((x > 0) && (y > 0) && (z > 0), VALIDATE_SHADERDESC_METAL_THREADS_PER_THREADGROUP_INITIALIZED); + _SG_VALIDATE(((x * y * z) & 31) == 0, VALIDATE_SHADERDESC_METAL_THREADS_PER_THREADGROUP_MULTIPLE_32); + } + #endif + for (size_t i = 0; i < SG_MAX_VERTEX_ATTRIBUTES; i++) { + if (desc->attrs[i].glsl_name) { + _SG_VALIDATE(strlen(desc->attrs[i].glsl_name) < _SG_STRING_SIZE, VALIDATE_SHADERDESC_ATTR_STRING_TOO_LONG); + } + if (desc->attrs[i].hlsl_sem_name) { + _SG_VALIDATE(strlen(desc->attrs[i].hlsl_sem_name) < _SG_STRING_SIZE, VALIDATE_SHADERDESC_ATTR_STRING_TOO_LONG); + } + } + // if shader byte code, the size must also be provided + if (0 != desc->vertex_func.bytecode.ptr) { + _SG_VALIDATE(desc->vertex_func.bytecode.size > 0, VALIDATE_SHADERDESC_NO_BYTECODE_SIZE); + } + if (0 != desc->fragment_func.bytecode.ptr) { + _SG_VALIDATE(desc->fragment_func.bytecode.size > 0, VALIDATE_SHADERDESC_NO_BYTECODE_SIZE); + } + if (0 != desc->compute_func.bytecode.ptr) { + _SG_VALIDATE(desc->compute_func.bytecode.size > 0, VALIDATE_SHADERDESC_NO_BYTECODE_SIZE); + } + + #if defined(SOKOL_METAL) + _sg_u128_t msl_buf_bits = _sg_u128(); + _sg_u128_t msl_tex_bits = _sg_u128(); + _sg_u128_t msl_smp_bits = _sg_u128(); + #elif defined(SOKOL_D3D11) + _sg_u128_t hlsl_buf_bits = _sg_u128(); + _sg_u128_t hlsl_srv_bits = _sg_u128(); + _sg_u128_t hlsl_uav_bits = _sg_u128(); + _sg_u128_t hlsl_smp_bits = _sg_u128(); + #elif defined(_SOKOL_ANY_GL) + _sg_u128_t glsl_sbuf_bnd_bits = _sg_u128(); + _sg_u128_t glsl_simg_bnd_bits = _sg_u128(); + #elif defined(SOKOL_WGPU) + _sg_u128_t wgsl_group0_bits = _sg_u128(); + _sg_u128_t wgsl_group1_bits = _sg_u128(); + #elif defined(SOKOL_VULKAN) + _sg_u128_t spirv_set0_bits = _sg_u128(); + _sg_u128_t spirv_set1_bits = _sg_u128(); + #endif + for (size_t ub_idx = 0; ub_idx < SG_MAX_UNIFORMBLOCK_BINDSLOTS; ub_idx++) { + const sg_shader_uniform_block* ub_desc = &desc->uniform_blocks[ub_idx]; + if (ub_desc->stage == SG_SHADERSTAGE_NONE) { + continue; + } + _SG_VALIDATE(ub_desc->size > 0, VALIDATE_SHADERDESC_UNIFORMBLOCK_SIZE_IS_ZERO); + #if defined(SOKOL_METAL) + _SG_VALIDATE(_sg_validate_slot_bits(msl_buf_bits, ub_desc->stage, ub_desc->msl_buffer_n), VALIDATE_SHADERDESC_UNIFORMBLOCK_METAL_BUFFER_SLOT_COLLISION); + msl_buf_bits = _sg_validate_set_slot_bit(msl_buf_bits, ub_desc->stage, ub_desc->msl_buffer_n); + #elif defined(SOKOL_D3D11) + _SG_VALIDATE(_sg_validate_slot_bits(hlsl_buf_bits, ub_desc->stage, ub_desc->hlsl_register_b_n), VALIDATE_SHADERDESC_UNIFORMBLOCK_HLSL_REGISTER_B_COLLISION); + hlsl_buf_bits = _sg_validate_set_slot_bit(hlsl_buf_bits, ub_desc->stage, ub_desc->hlsl_register_b_n); + #elif defined(SOKOL_WGPU) + _SG_VALIDATE(_sg_validate_slot_bits(wgsl_group0_bits, SG_SHADERSTAGE_NONE, ub_desc->wgsl_group0_binding_n), VALIDATE_SHADERDESC_UNIFORMBLOCK_WGSL_GROUP0_BINDING_COLLISION); + wgsl_group0_bits = _sg_validate_set_slot_bit(wgsl_group0_bits, SG_SHADERSTAGE_NONE, ub_desc->wgsl_group0_binding_n); + #elif defined(SOKOL_VULKAN) + _SG_VALIDATE(_sg_validate_slot_bits(spirv_set0_bits, SG_SHADERSTAGE_NONE, ub_desc->spirv_set0_binding_n), VALIDATE_SHADERDESC_UNIFORMBLOCK_SPIRV_SET0_BINDING_COLLISION); + spirv_set0_bits = _sg_validate_set_slot_bit(spirv_set0_bits, SG_SHADERSTAGE_NONE, ub_desc->spirv_set0_binding_n); + #endif + #if defined(_SOKOL_ANY_GL) + bool uniforms_continuous = true; + uint32_t uniform_offset = 0; + int num_uniforms = 0; + for (size_t u_index = 0; u_index < SG_MAX_UNIFORMBLOCK_MEMBERS; u_index++) { + const sg_glsl_shader_uniform* u_desc = &ub_desc->glsl_uniforms[u_index]; + if (u_desc->type != SG_UNIFORMTYPE_INVALID) { + _SG_VALIDATE(uniforms_continuous, VALIDATE_SHADERDESC_UNIFORMBLOCK_NO_CONT_MEMBERS); + _SG_VALIDATE(u_desc->glsl_name, VALIDATE_SHADERDESC_UNIFORMBLOCK_UNIFORM_GLSL_NAME); + const int array_count = u_desc->array_count; + _SG_VALIDATE(array_count > 0, VALIDATE_SHADERDESC_UNIFORMBLOCK_ARRAY_COUNT); + const uint32_t u_align = _sg_uniform_alignment(u_desc->type, array_count, ub_desc->layout); + const uint32_t u_size = _sg_uniform_size(u_desc->type, array_count, ub_desc->layout); + uniform_offset = _sg_align_u32(uniform_offset, u_align); + uniform_offset += u_size; + num_uniforms++; + // with std140, arrays are only allowed for FLOAT4, INT4, MAT4 + if (ub_desc->layout == SG_UNIFORMLAYOUT_STD140) { + if (array_count > 1) { + _SG_VALIDATE((u_desc->type == SG_UNIFORMTYPE_FLOAT4) || (u_desc->type == SG_UNIFORMTYPE_INT4) || (u_desc->type == SG_UNIFORMTYPE_MAT4), VALIDATE_SHADERDESC_UNIFORMBLOCK_STD140_ARRAY_TYPE); + } + } + } else { + uniforms_continuous = false; + } + } + if (ub_desc->layout == SG_UNIFORMLAYOUT_STD140) { + uniform_offset = _sg_align_u32(uniform_offset, 16); + } + _SG_VALIDATE((size_t)uniform_offset == ub_desc->size, VALIDATE_SHADERDESC_UNIFORMBLOCK_SIZE_MISMATCH); + _SG_VALIDATE(num_uniforms > 0, VALIDATE_SHADERDESC_UNIFORMBLOCK_NO_MEMBERS); + #endif + } + + uint32_t texview_slot_mask = 0; + for (size_t view_idx = 0; view_idx < SG_MAX_VIEW_BINDSLOTS; view_idx++) { + const sg_shader_view* view_desc = &desc->views[view_idx]; + if (view_desc->texture.stage != SG_SHADERSTAGE_NONE) { + const sg_shader_texture_view* tex_desc = &view_desc->texture; + texview_slot_mask |= (1 << view_idx); + #if defined(SOKOL_METAL) + _SG_VALIDATE(_sg_validate_slot_bits(msl_tex_bits, tex_desc->stage, tex_desc->msl_texture_n), VALIDATE_SHADERDESC_VIEW_TEXTURE_METAL_TEXTURE_SLOT_COLLISION); + msl_tex_bits = _sg_validate_set_slot_bit(msl_tex_bits, tex_desc->stage, tex_desc->msl_texture_n); + #elif defined(SOKOL_D3D11) + _SG_VALIDATE(_sg_validate_slot_bits(hlsl_srv_bits, tex_desc->stage, tex_desc->hlsl_register_t_n), VALIDATE_SHADERDESC_VIEW_TEXTURE_HLSL_REGISTER_T_COLLISION); + hlsl_srv_bits = _sg_validate_set_slot_bit(hlsl_srv_bits, tex_desc->stage, tex_desc->hlsl_register_t_n); + #elif defined(SOKOL_WGPU) + _SG_VALIDATE(_sg_validate_slot_bits(wgsl_group1_bits, SG_SHADERSTAGE_NONE, tex_desc->wgsl_group1_binding_n), VALIDATE_SHADERDESC_VIEW_TEXTURE_WGSL_GROUP1_BINDING_COLLISION); + wgsl_group1_bits = _sg_validate_set_slot_bit(wgsl_group1_bits, SG_SHADERSTAGE_NONE, tex_desc->wgsl_group1_binding_n); + #elif defined(SOKOL_VULKAN) + _SG_VALIDATE(_sg_validate_slot_bits(spirv_set1_bits, SG_SHADERSTAGE_NONE, tex_desc->spirv_set1_binding_n), VALIDATE_SHADERDESC_VIEW_TEXTURE_SPIRV_SET1_BINDING_COLLISION); + spirv_set1_bits = _sg_validate_set_slot_bit(spirv_set1_bits, SG_SHADERSTAGE_NONE, tex_desc->spirv_set1_binding_n); + #elif defined(SOKOL_DUMMY_BACKEND) || defined(_SOKOL_ANY_GL) + _SOKOL_UNUSED(tex_desc); + #endif + } else if (view_desc->storage_buffer.stage != SG_SHADERSTAGE_NONE) { + const sg_shader_storage_buffer_view* sbuf_desc = &view_desc->storage_buffer; + #if defined(SOKOL_METAL) + _SG_VALIDATE(_sg_validate_slot_bits(msl_buf_bits, sbuf_desc->stage, sbuf_desc->msl_buffer_n), VALIDATE_SHADERDESC_VIEW_STORAGEBUFFER_METAL_BUFFER_SLOT_COLLISION); + msl_buf_bits = _sg_validate_set_slot_bit(msl_buf_bits, sbuf_desc->stage, sbuf_desc->msl_buffer_n); + #elif defined(SOKOL_D3D11) + if (sbuf_desc->readonly) { + _SG_VALIDATE(_sg_validate_slot_bits(hlsl_srv_bits, sbuf_desc->stage, sbuf_desc->hlsl_register_t_n), VALIDATE_SHADERDESC_VIEW_STORAGEBUFFER_HLSL_REGISTER_T_COLLISION); + hlsl_srv_bits = _sg_validate_set_slot_bit(hlsl_srv_bits, sbuf_desc->stage, sbuf_desc->hlsl_register_t_n); + } else { + _SG_VALIDATE(_sg_validate_slot_bits(hlsl_uav_bits, sbuf_desc->stage, sbuf_desc->hlsl_register_u_n), VALIDATE_SHADERDESC_VIEW_STORAGEBUFFER_HLSL_REGISTER_U_COLLISION); + hlsl_uav_bits = _sg_validate_set_slot_bit(hlsl_uav_bits, sbuf_desc->stage, sbuf_desc->hlsl_register_u_n); + } + #elif defined(_SOKOL_ANY_GL) + _SG_VALIDATE(_sg_validate_slot_bits(glsl_sbuf_bnd_bits, SG_SHADERSTAGE_NONE, sbuf_desc->glsl_binding_n), VALIDATE_SHADERDESC_VIEW_STORAGEBUFFER_GLSL_BINDING_COLLISION); + glsl_sbuf_bnd_bits = _sg_validate_set_slot_bit(glsl_sbuf_bnd_bits, SG_SHADERSTAGE_NONE, sbuf_desc->glsl_binding_n); + #elif defined(SOKOL_WGPU) + _SG_VALIDATE(_sg_validate_slot_bits(wgsl_group1_bits, SG_SHADERSTAGE_NONE, sbuf_desc->wgsl_group1_binding_n), VALIDATE_SHADERDESC_VIEW_STORAGEBUFFER_WGSL_GROUP1_BINDING_COLLISION); + wgsl_group1_bits = _sg_validate_set_slot_bit(wgsl_group1_bits, SG_SHADERSTAGE_NONE, sbuf_desc->wgsl_group1_binding_n); + #elif defined(SOKOL_VULKAN) + _SG_VALIDATE(_sg_validate_slot_bits(spirv_set1_bits, SG_SHADERSTAGE_NONE, sbuf_desc->spirv_set1_binding_n), VALIDATE_SHADERDESC_VIEW_STORAGEBUFFER_SPIRV_SET1_BINDING_COLLISION); + spirv_set1_bits = _sg_validate_set_slot_bit(spirv_set1_bits, SG_SHADERSTAGE_NONE, sbuf_desc->spirv_set1_binding_n); + #elif defined(SOKOL_DUMMY_BACKEND) + _SOKOL_UNUSED(sbuf_desc); + #endif + } else if (view_desc->storage_image.stage != SG_SHADERSTAGE_NONE) { + const sg_shader_storage_image_view* simg_desc = &view_desc->storage_image; + _SG_VALIDATE(simg_desc->stage == SG_SHADERSTAGE_COMPUTE, VALIDATE_SHADERDESC_VIEW_STORAGEIMAGE_EXPECT_COMPUTE_STAGE); + #if defined(SOKOL_METAL) + _SG_VALIDATE(_sg_validate_slot_bits(msl_tex_bits, simg_desc->stage, simg_desc->msl_texture_n), VALIDATE_SHADERDESC_VIEW_STORAGEIMAGE_METAL_TEXTURE_SLOT_COLLISION); + msl_tex_bits = _sg_validate_set_slot_bit(msl_tex_bits, simg_desc->stage, simg_desc->msl_texture_n); + #elif defined(SOKOL_D3D11) + _SG_VALIDATE(_sg_validate_slot_bits(hlsl_uav_bits, simg_desc->stage, simg_desc->hlsl_register_u_n), VALIDATE_SHADERDESC_VIEW_STORAGEIMAGE_HLSL_REGISTER_U_COLLISION); + hlsl_uav_bits = _sg_validate_set_slot_bit(hlsl_uav_bits, simg_desc->stage, simg_desc->hlsl_register_u_n); + #elif defined(_SOKOL_ANY_GL) + _SG_VALIDATE(_sg_validate_slot_bits(glsl_simg_bnd_bits, SG_SHADERSTAGE_NONE, simg_desc->glsl_binding_n), VALIDATE_SHADERDESC_VIEW_STORAGEIMAGE_GLSL_BINDING_COLLISION); + glsl_simg_bnd_bits = _sg_validate_set_slot_bit(glsl_simg_bnd_bits, SG_SHADERSTAGE_NONE, simg_desc->glsl_binding_n); + #elif defined(SOKOL_WGPU) + _SG_VALIDATE(_sg_validate_slot_bits(wgsl_group1_bits, SG_SHADERSTAGE_NONE, simg_desc->wgsl_group1_binding_n), VALIDATE_SHADERDESC_VIEW_STORAGEIMAGE_WGSL_GROUP1_BINDING_COLLISION); + wgsl_group1_bits = _sg_validate_set_slot_bit(wgsl_group1_bits, SG_SHADERSTAGE_NONE, simg_desc->wgsl_group1_binding_n); + #elif defined(SOKOL_VULKAN) + _SG_VALIDATE(_sg_validate_slot_bits(spirv_set1_bits, SG_SHADERSTAGE_NONE, simg_desc->spirv_set1_binding_n), VALIDATE_SHADERDESC_VIEW_STORAGEIMAGE_SPIRV_SET1_BINDING_COLLISION); + spirv_set1_bits = _sg_validate_set_slot_bit(spirv_set1_bits, SG_SHADERSTAGE_NONE, simg_desc->spirv_set1_binding_n); + #endif + } + } + + uint32_t smp_slot_mask = 0; + for (size_t smp_idx = 0; smp_idx < SG_MAX_SAMPLER_BINDSLOTS; smp_idx++) { + const sg_shader_sampler* smp_desc = &desc->samplers[smp_idx]; + if (smp_desc->stage == SG_SHADERSTAGE_NONE) { + continue; + } + smp_slot_mask |= (1 << smp_idx); + #if defined(SOKOL_METAL) + _SG_VALIDATE(_sg_validate_slot_bits(msl_smp_bits, smp_desc->stage, smp_desc->msl_sampler_n), VALIDATE_SHADERDESC_SAMPLER_METAL_SAMPLER_SLOT_COLLISION); + msl_smp_bits = _sg_validate_set_slot_bit(msl_smp_bits, smp_desc->stage, smp_desc->msl_sampler_n); + #elif defined(SOKOL_D3D11) + _SG_VALIDATE(_sg_validate_slot_bits(hlsl_smp_bits, smp_desc->stage, smp_desc->hlsl_register_s_n), VALIDATE_SHADERDESC_SAMPLER_HLSL_REGISTER_S_COLLISION); + hlsl_smp_bits = _sg_validate_set_slot_bit(hlsl_smp_bits, smp_desc->stage, smp_desc->hlsl_register_s_n); + #elif defined(SOKOL_WGPU) + _SG_VALIDATE(_sg_validate_slot_bits(wgsl_group1_bits, SG_SHADERSTAGE_NONE, smp_desc->wgsl_group1_binding_n), VALIDATE_SHADERDESC_SAMPLER_WGSL_GROUP1_BINDING_COLLISION); + wgsl_group1_bits = _sg_validate_set_slot_bit(wgsl_group1_bits, SG_SHADERSTAGE_NONE, smp_desc->wgsl_group1_binding_n); + #elif defined(SOKOL_VULKAN) + _SG_VALIDATE(_sg_validate_slot_bits(spirv_set1_bits, SG_SHADERSTAGE_NONE, smp_desc->spirv_set1_binding_n), VALIDATE_SHADERDESC_SAMPLER_SPIRV_SET1_BINDING_COLLISION); + spirv_set1_bits = _sg_validate_set_slot_bit(spirv_set1_bits, SG_SHADERSTAGE_NONE, smp_desc->spirv_set1_binding_n); + #endif + } + + uint32_t ref_texview_slot_mask = 0; + uint32_t ref_smp_slot_mask = 0; + for (size_t tex_smp_idx = 0; tex_smp_idx < SG_MAX_TEXTURE_SAMPLER_PAIRS; tex_smp_idx++) { + const sg_shader_texture_sampler_pair* tex_smp_desc = &desc->texture_sampler_pairs[tex_smp_idx]; + if (tex_smp_desc->stage == SG_SHADERSTAGE_NONE) { + continue; + } + #if defined(_SOKOL_ANY_GL) + _SG_VALIDATE(tex_smp_desc->glsl_name != 0, VALIDATE_SHADERDESC_TEXTURE_SAMPLER_PAIR_GLSL_NAME); + #endif + const bool view_slot_in_range = tex_smp_desc->view_slot < SG_MAX_VIEW_BINDSLOTS; + const bool smp_slot_in_range = tex_smp_desc->sampler_slot < SG_MAX_SAMPLER_BINDSLOTS; + _SG_VALIDATE(view_slot_in_range, VALIDATE_SHADERDESC_TEXTURE_SAMPLER_PAIR_VIEW_SLOT_OUT_OF_RANGE); + _SG_VALIDATE(smp_slot_in_range, VALIDATE_SHADERDESC_TEXTURE_SAMPLER_PAIR_SAMPLER_SLOT_OUT_OF_RANGE); + if (view_slot_in_range && smp_slot_in_range) { + ref_texview_slot_mask |= 1 << tex_smp_desc->view_slot; + ref_smp_slot_mask |= 1 << tex_smp_desc->sampler_slot; + const sg_shader_view* view_desc = &desc->views[tex_smp_desc->view_slot]; + const sg_shader_sampler* smp_desc = &desc->samplers[tex_smp_desc->sampler_slot]; + _SG_VALIDATE(view_desc->texture.stage != SG_SHADERSTAGE_NONE, VALIDATE_SHADERDESC_TEXTURE_SAMPLER_PAIR_EXPECT_TEXTURE_VIEW); + _SG_VALIDATE(view_desc->texture.stage == tex_smp_desc->stage, VALIDATE_SHADERDESC_TEXTURE_SAMPLER_PAIR_TEXTURE_STAGE_MISMATCH); + _SG_VALIDATE(smp_desc->stage == tex_smp_desc->stage, VALIDATE_SHADERDESC_TEXTURE_SAMPLER_PAIR_SAMPLER_STAGE_MISMATCH); + const bool needs_nonfiltering = (view_desc->texture.sample_type == SG_IMAGESAMPLETYPE_UINT) + || (view_desc->texture.sample_type == SG_IMAGESAMPLETYPE_SINT) + || (view_desc->texture.sample_type == SG_IMAGESAMPLETYPE_UNFILTERABLE_FLOAT); + const bool needs_comparison = view_desc->texture.sample_type == SG_IMAGESAMPLETYPE_DEPTH; + if (needs_nonfiltering) { + _SG_VALIDATE(needs_nonfiltering && (smp_desc->sampler_type == SG_SAMPLERTYPE_NONFILTERING), VALIDATE_SHADERDESC_NONFILTERING_SAMPLER_REQUIRED); + } + if (needs_comparison) { + _SG_VALIDATE(needs_comparison && (smp_desc->sampler_type == SG_SAMPLERTYPE_COMPARISON), VALIDATE_SHADERDESC_COMPARISON_SAMPLER_REQUIRED); + } + } + } + // each image and sampler must be referenced by an image sampler + _SG_VALIDATE(texview_slot_mask == ref_texview_slot_mask, VALIDATE_SHADERDESC_TEXVIEW_NOT_REFERENCED_BY_TEXTURE_SAMPLER_PAIRS); + _SG_VALIDATE(smp_slot_mask == ref_smp_slot_mask, VALIDATE_SHADERDESC_SAMPLER_NOT_REFERENCED_BY_TEXTURE_SAMPLER_PAIRS); + + return _sg_validate_end(); + #endif +} + +_SOKOL_PRIVATE bool _sg_validate_pipeline_desc(const sg_pipeline_desc* desc) { + #if !defined(SOKOL_DEBUG) + _SOKOL_UNUSED(desc); + return true; + #else + if (_sg.desc.disable_validation) { + return true; + } + SOKOL_ASSERT(desc); + _sg_validate_begin(); + _SG_VALIDATE(desc->_start_canary == 0, VALIDATE_PIPELINEDESC_CANARY); + _SG_VALIDATE(desc->_end_canary == 0, VALIDATE_PIPELINEDESC_CANARY); + _SG_VALIDATE(desc->shader.id != SG_INVALID_ID, VALIDATE_PIPELINEDESC_SHADER); + const _sg_shader_t* shd = _sg_lookup_shader(desc->shader.id); + _SG_VALIDATE(0 != shd, VALIDATE_PIPELINEDESC_SHADER); + if (shd) { + _SG_VALIDATE(shd->slot.state == SG_RESOURCESTATE_VALID, VALIDATE_PIPELINEDESC_SHADER); + if (desc->compute) { + _SG_VALIDATE(shd->cmn.is_compute, VALIDATE_PIPELINEDESC_COMPUTE_SHADER_EXPECTED); + } else { + _SG_VALIDATE(!shd->cmn.is_compute, VALIDATE_PIPELINEDESC_NO_COMPUTE_SHADER_EXPECTED); + bool attrs_cont = true; + for (size_t attr_index = 0; attr_index < SG_MAX_VERTEX_ATTRIBUTES; attr_index++) { + const sg_vertex_attr_state* a_state = &desc->layout.attrs[attr_index]; + if (a_state->format == SG_VERTEXFORMAT_INVALID) { + attrs_cont = false; + continue; + } + _SG_VALIDATE(attrs_cont, VALIDATE_PIPELINEDESC_NO_CONT_ATTRS); + SOKOL_ASSERT(a_state->buffer_index < SG_MAX_VERTEXBUFFER_BINDSLOTS); + // vertex format must match expected shader attribute base type (if provided) + if (shd->cmn.attrs[attr_index].base_type != SG_SHADERATTRBASETYPE_UNDEFINED) { + if (_sg_vertexformat_basetype(a_state->format) != shd->cmn.attrs[attr_index].base_type) { + _SG_VALIDATE(false, VALIDATE_PIPELINEDESC_ATTR_BASETYPE_MISMATCH); + _SG_LOGMSG(VALIDATE_PIPELINEDESC_ATTR_BASETYPE_MISMATCH, "attr format:"); + _SG_LOGMSG(VALIDATE_PIPELINEDESC_ATTR_BASETYPE_MISMATCH, _sg_vertexformat_to_string(a_state->format)); + _SG_LOGMSG(VALIDATE_PIPELINEDESC_ATTR_BASETYPE_MISMATCH, "shader attr base type:"); + _SG_LOGMSG(VALIDATE_PIPELINEDESC_ATTR_BASETYPE_MISMATCH, _sg_shaderattrbasetype_to_string(shd->cmn.attrs[attr_index].base_type)); + } + } + if (a_state->format == SG_VERTEXFORMAT_INT10_N2) { + _SG_VALIDATE(_sg.features.vertexformat_int10_n2, VALIDATE_PIPELINEDESC_ATTR_VERTEXFORMAT_INT10_N2_NOT_SUPPORTED); + } + #if defined(SOKOL_D3D11) + // on D3D11, semantic names (and semantic indices) must be provided + _SG_VALIDATE(!_sg_strempty(&shd->d3d11.attrs[attr_index].sem_name), VALIDATE_PIPELINEDESC_ATTR_SEMANTICS); + #endif + } + // must only use readonly storage buffer bindings in render pipelines + for (size_t i = 0; i < SG_MAX_VIEW_BINDSLOTS; i++) { + if (shd->cmn.views[i].view_type == SG_VIEWTYPE_STORAGEBUFFER) { + _SG_VALIDATE(shd->cmn.views[i].sbuf_readonly, VALIDATE_PIPELINEDESC_SHADER_READONLY_STORAGEBUFFERS); + } + } + for (int buf_index = 0; buf_index < SG_MAX_VERTEXBUFFER_BINDSLOTS; buf_index++) { + const sg_vertex_buffer_layout_state* l_state = &desc->layout.buffers[buf_index]; + if (l_state->stride == 0) { + continue; + } + _SG_VALIDATE(_sg_multiple_u64((uint64_t)l_state->stride, 4), VALIDATE_PIPELINEDESC_LAYOUT_STRIDE4); + } + } + } + for (size_t color_index = 0; color_index < (size_t)desc->color_count; color_index++) { + SOKOL_ASSERT(color_index < SG_MAX_COLOR_ATTACHMENTS); + const sg_blend_state* bs = &desc->colors[color_index].blend; + if ((bs->op_rgb == SG_BLENDOP_MIN) || (bs->op_rgb == SG_BLENDOP_MAX)) { + _SG_VALIDATE((bs->src_factor_rgb == SG_BLENDFACTOR_ONE) && (bs->dst_factor_rgb == SG_BLENDFACTOR_ONE), VALIDATE_PIPELINEDESC_BLENDOP_MINMAX_REQUIRES_BLENDFACTOR_ONE); + } + if ((bs->op_alpha == SG_BLENDOP_MIN) || (bs->op_alpha == SG_BLENDOP_MAX)) { + _SG_VALIDATE((bs->src_factor_alpha == SG_BLENDFACTOR_ONE) && (bs->dst_factor_alpha == SG_BLENDFACTOR_ONE), VALIDATE_PIPELINEDESC_BLENDOP_MINMAX_REQUIRES_BLENDFACTOR_ONE); + } + const bool needs_dualsource_blending = + _sg_is_dualsource_blendfactor(bs->src_factor_rgb) || + _sg_is_dualsource_blendfactor(bs->dst_factor_rgb) || + _sg_is_dualsource_blendfactor(bs->src_factor_alpha) || + _sg_is_dualsource_blendfactor(bs->dst_factor_alpha); + if (needs_dualsource_blending) { + _SG_VALIDATE(_sg.features.dual_source_blending, VALIDATE_PIPELINEDESC_DUAL_SOURCE_BLENDING_NOT_SUPPORTED); + } + } + return _sg_validate_end(); + #endif +} + +_SOKOL_PRIVATE bool _sg_validate_view_desc(const sg_view_desc* desc) { + #if !defined(SOKOL_DEBUG) + _SOKOL_UNUSED(desc); + return true; + #else + if (_sg.desc.disable_validation) { + return true; + } + SOKOL_ASSERT(desc); + _sg_validate_begin(); + _SG_VALIDATE(desc->_start_canary == 0, VALIDATE_VIEWDESC_CANARY); + _SG_VALIDATE(desc->_end_canary == 0, VALIDATE_VIEWDESC_CANARY); + + // only one view type can be define + sg_view_type view_type = SG_VIEWTYPE_INVALID; + const sg_image_view_desc* img_desc = 0; + const sg_texture_view_desc* tex_desc = 0; + const sg_buffer_view_desc* buf_desc = 0; + if (desc->texture.image.id != SG_INVALID_ID) { + view_type = SG_VIEWTYPE_TEXTURE; + tex_desc = &desc->texture; + } + if (desc->storage_buffer.buffer.id != SG_INVALID_ID) { + _SG_VALIDATE(SG_VIEWTYPE_INVALID == view_type, VALIDATE_VIEWDESC_UNIQUE_VIEWTYPE); + view_type = SG_VIEWTYPE_STORAGEBUFFER; + buf_desc = &desc->storage_buffer; + } + if (desc->storage_image.image.id != SG_INVALID_ID) { + _SG_VALIDATE(SG_VIEWTYPE_INVALID == view_type, VALIDATE_VIEWDESC_UNIQUE_VIEWTYPE); + view_type = SG_VIEWTYPE_STORAGEIMAGE; + img_desc = &desc->storage_image; + } + if (desc->color_attachment.image.id != SG_INVALID_ID) { + _SG_VALIDATE(SG_VIEWTYPE_INVALID == view_type, VALIDATE_VIEWDESC_UNIQUE_VIEWTYPE); + view_type = SG_VIEWTYPE_COLORATTACHMENT; + img_desc = &desc->color_attachment; + } + if (desc->resolve_attachment.image.id != SG_INVALID_ID) { + _SG_VALIDATE(SG_VIEWTYPE_INVALID == view_type, VALIDATE_VIEWDESC_UNIQUE_VIEWTYPE); + view_type = SG_VIEWTYPE_RESOLVEATTACHMENT; + img_desc = &desc->resolve_attachment; + } + if (desc->depth_stencil_attachment.image.id != SG_INVALID_ID) { + _SG_VALIDATE(SG_VIEWTYPE_INVALID == view_type, VALIDATE_VIEWDESC_UNIQUE_VIEWTYPE); + view_type = SG_VIEWTYPE_DEPTHSTENCILATTACHMENT; + img_desc = &desc->depth_stencil_attachment; + } + _SG_VALIDATE(SG_VIEWTYPE_INVALID != view_type, VALIDATE_VIEWDESC_ANY_VIEWTYPE); + + const _sg_buffer_t* buf = 0; + const _sg_image_t* img = 0; + bool res_valid = false; + if (buf_desc) { + SOKOL_ASSERT((img_desc == 0) && (tex_desc == 0)); + buf = _sg_lookup_buffer(buf_desc->buffer.id); + _SG_VALIDATE(buf, VALIDATE_VIEWDESC_RESOURCE_ALIVE); + if (buf) { + _SG_VALIDATE(buf->slot.state == SG_RESOURCESTATE_VALID, VALIDATE_VIEWDESC_RESOURCE_FAILED); + res_valid = buf->slot.state == SG_RESOURCESTATE_VALID; + } + } else if (img_desc) { + SOKOL_ASSERT((tex_desc == 0) && (buf_desc == 0)); + img = _sg_lookup_image(img_desc->image.id); + _SG_VALIDATE(img, VALIDATE_VIEWDESC_RESOURCE_ALIVE); + if (img) { + _SG_VALIDATE(img->slot.state == SG_RESOURCESTATE_VALID, VALIDATE_VIEWDESC_RESOURCE_FAILED); + res_valid = img->slot.state == SG_RESOURCESTATE_VALID; + } + } else { + SOKOL_ASSERT(tex_desc && (img_desc == 0) && (buf_desc == 0)); + img = _sg_lookup_image(tex_desc->image.id); + _SG_VALIDATE(img, VALIDATE_VIEWDESC_RESOURCE_ALIVE); + if (img) { + _SG_VALIDATE(img->slot.state == SG_RESOURCESTATE_VALID, VALIDATE_VIEWDESC_RESOURCE_FAILED); + res_valid = img->slot.state == SG_RESOURCESTATE_VALID; + } + } + if (res_valid) { + // check usage flags + switch (view_type) { + case SG_VIEWTYPE_STORAGEBUFFER: + SOKOL_ASSERT(buf); + _SG_VALIDATE(buf->cmn.usage.storage_buffer, VALIDATE_VIEWDESC_STORAGEBUFFER_USAGE); + break; + case SG_VIEWTYPE_STORAGEIMAGE: + SOKOL_ASSERT(img); + _SG_VALIDATE(img->cmn.usage.storage_image, VALIDATE_VIEWDESC_STORAGEIMAGE_USAGE); + _SG_VALIDATE(_sg_is_valid_storage_image_format(img->cmn.pixel_format), VALIDATE_VIEWDESC_STORAGEIMAGE_PIXELFORMAT); + break; + case SG_VIEWTYPE_TEXTURE: + if (!_sg.features.msaa_texture_bindings) { + _SG_VALIDATE(img->cmn.sample_count == 1, VALIDATE_VIEWDESC_TEXTURE_EXPECT_NO_MSAA); + } + break; + case SG_VIEWTYPE_COLORATTACHMENT: + SOKOL_ASSERT(img); + _SG_VALIDATE(img->cmn.usage.color_attachment, VALIDATE_VIEWDESC_COLORATTACHMENT_USAGE); + _SG_VALIDATE(_sg_is_valid_attachment_color_format(img->cmn.pixel_format), VALIDATE_VIEWDESC_COLORATTACHMENT_PIXELFORMAT); + break; + case SG_VIEWTYPE_RESOLVEATTACHMENT: + SOKOL_ASSERT(img); + _SG_VALIDATE(img->cmn.usage.resolve_attachment, VALIDATE_VIEWDESC_RESOLVEATTACHMENT_USAGE); + _SG_VALIDATE(img->cmn.sample_count == 1, VALIDATE_VIEWDESC_RESOLVEATTACHMENT_SAMPLECOUNT); + break; + case SG_VIEWTYPE_DEPTHSTENCILATTACHMENT: + SOKOL_ASSERT(img); + _SG_VALIDATE(img->cmn.usage.depth_stencil_attachment, VALIDATE_VIEWDESC_DEPTHSTENCILATTACHMENT_USAGE); + _SG_VALIDATE(_sg_is_valid_attachment_depth_format(img->cmn.pixel_format), VALIDATE_VIEWDESC_DEPTHSTENCILATTACHMENT_PIXELFORMAT); + break; + default: + SOKOL_UNREACHABLE; + break; + } + if (buf_desc) { + SOKOL_ASSERT(buf); + _SG_VALIDATE(buf_desc->offset < buf->cmn.size, VALIDATE_VIEWDESC_STORAGEBUFFER_OFFSET_VS_BUFFER_SIZE); + _SG_VALIDATE(_sg_multiple_u64((uint64_t)buf_desc->offset, 256), VALIDATE_VIEWDESC_STORAGEBUFFER_OFFSET_MULTIPLE_256); + } else if (img_desc) { + SOKOL_ASSERT(img); + _SG_VALIDATE((img_desc->mip_level >= 0) && (img_desc->mip_level < img->cmn.num_mipmaps), VALIDATE_VIEWDESC_IMAGE_MIPLEVEL); + if (img->cmn.type == SG_IMAGETYPE_2D) { + _SG_VALIDATE(img_desc->slice == 0, VALIDATE_VIEWDESC_IMAGE_2D_SLICE); + } else if (img->cmn.type == SG_IMAGETYPE_CUBE) { + _SG_VALIDATE((img_desc->slice >= 0) && (img_desc->slice < 6), VALIDATE_VIEWDESC_IMAGE_CUBEMAP_SLICE); + } else if (img->cmn.type == SG_IMAGETYPE_ARRAY) { + _SG_VALIDATE((img_desc->slice >= 0) && (img_desc->slice < img->cmn.num_slices), VALIDATE_VIEWDESC_IMAGE_ARRAY_SLICE); + } else if (img->cmn.type == SG_IMAGETYPE_3D) { + _SG_VALIDATE(img_desc->slice == 0, VALIDATE_VIEWDESC_IMAGE_3D_SLICE); + } + } else if (tex_desc) { + SOKOL_ASSERT(img); + // NOTE: it doesn't matter here if the mip/slice count is default-zero! + int max_mip_level = tex_desc->mip_levels.base + tex_desc->mip_levels.count; + int max_slice = tex_desc->slices.base + tex_desc->slices.count; + _SG_VALIDATE((tex_desc->mip_levels.base >= 0) && (max_mip_level <= img->cmn.num_mipmaps), VALIDATE_VIEWDESC_TEXTURE_MIPLEVELS); + if (img->cmn.type == SG_IMAGETYPE_2D) { + _SG_VALIDATE((tex_desc->slices.base == 0) && (max_slice <= 1), VALIDATE_VIEWDESC_TEXTURE_2D_SLICES); + } else if (img->cmn.type == SG_IMAGETYPE_CUBE) { + _SG_VALIDATE((tex_desc->slices.base == 0) && (max_slice <= 1), VALIDATE_VIEWDESC_TEXTURE_CUBEMAP_SLICES); + } else if (img->cmn.type == SG_IMAGETYPE_ARRAY) { + _SG_VALIDATE((tex_desc->slices.base >= 0) && (max_slice <= img->cmn.num_slices), VALIDATE_VIEWDESC_TEXTURE_ARRAY_SLICES); + } else if (img->cmn.type == SG_IMAGETYPE_3D) { + _SG_VALIDATE((tex_desc->slices.base == 0) && (max_slice <= 1), VALIDATE_VIEWDESC_TEXTURE_3D_SLICES); + } + } + } + return _sg_validate_end(); + #endif +} + +_SOKOL_PRIVATE bool _sg_validate_begin_pass(const sg_pass* pass) { + #if !defined(SOKOL_DEBUG) + _SOKOL_UNUSED(pass); + return true; + #else + if (_sg.desc.disable_validation) { + return true; + } + const bool is_invalid_swapchain_pass = pass->swapchain.invalid; + const bool is_compute_pass = pass->compute; + const bool is_swapchain_pass = !is_compute_pass && _sg_attachments_empty(&pass->attachments); + const bool is_offscreen_pass = !(is_compute_pass || is_swapchain_pass); + _sg_validate_begin(); + _SG_VALIDATE(pass->_start_canary == 0, VALIDATE_BEGINPASS_CANARY); + _SG_VALIDATE(pass->_end_canary == 0, VALIDATE_BEGINPASS_CANARY); + if (is_compute_pass) { + _SG_VALIDATE(_sg_attachments_empty(&pass->attachments), VALIDATE_BEGINPASS_COMPUTEPASS_EXPECT_NO_ATTACHMENTS); + } else if (is_invalid_swapchain_pass) { + // empty block not a bug, skips to 'swapchain zeroed' validation at the end + } else if (is_swapchain_pass) { + _SG_VALIDATE(pass->swapchain.width > 0, VALIDATE_BEGINPASS_SWAPCHAIN_EXPECT_WIDTH); + _SG_VALIDATE(pass->swapchain.height > 0, VALIDATE_BEGINPASS_SWAPCHAIN_EXPECT_HEIGHT); + _SG_VALIDATE(pass->swapchain.sample_count > 0, VALIDATE_BEGINPASS_SWAPCHAIN_EXPECT_SAMPLECOUNT); + _SG_VALIDATE(pass->swapchain.color_format > SG_PIXELFORMAT_NONE, VALIDATE_BEGINPASS_SWAPCHAIN_EXPECT_COLORFORMAT); + // NOTE: depth buffer is optional, so depth_format is allowed to be invalid + // NOTE: the GL framebuffer handle may actually be 0 + #if defined(SOKOL_METAL) + _SG_VALIDATE(pass->swapchain.metal.current_drawable != 0, VALIDATE_BEGINPASS_SWAPCHAIN_METAL_EXPECT_CURRENTDRAWABLE); + if (pass->swapchain.depth_format == SG_PIXELFORMAT_NONE) { + _SG_VALIDATE(pass->swapchain.metal.depth_stencil_texture == 0, VALIDATE_BEGINPASS_SWAPCHAIN_METAL_EXPECT_DEPTHSTENCILTEXTURE_NOTSET); + } else { + _SG_VALIDATE(pass->swapchain.metal.depth_stencil_texture != 0, VALIDATE_BEGINPASS_SWAPCHAIN_METAL_EXPECT_DEPTHSTENCILTEXTURE); + } + if (pass->swapchain.sample_count > 1) { + _SG_VALIDATE(pass->swapchain.metal.msaa_color_texture != 0, VALIDATE_BEGINPASS_SWAPCHAIN_METAL_EXPECT_MSAACOLORTEXTURE); + } else { + _SG_VALIDATE(pass->swapchain.metal.msaa_color_texture == 0, VALIDATE_BEGINPASS_SWAPCHAIN_METAL_EXPECT_MSAACOLORTEXTURE_NOTSET); + } + #elif defined(SOKOL_D3D11) + _SG_VALIDATE(pass->swapchain.d3d11.render_view != 0, VALIDATE_BEGINPASS_SWAPCHAIN_D3D11_EXPECT_RENDERVIEW); + if (pass->swapchain.depth_format == SG_PIXELFORMAT_NONE) { + _SG_VALIDATE(pass->swapchain.d3d11.depth_stencil_view == 0, VALIDATE_BEGINPASS_SWAPCHAIN_D3D11_EXPECT_DEPTHSTENCILVIEW_NOTSET); + } else { + _SG_VALIDATE(pass->swapchain.d3d11.depth_stencil_view != 0, VALIDATE_BEGINPASS_SWAPCHAIN_D3D11_EXPECT_DEPTHSTENCILVIEW); + } + if (pass->swapchain.sample_count > 1) { + _SG_VALIDATE(pass->swapchain.d3d11.resolve_view != 0, VALIDATE_BEGINPASS_SWAPCHAIN_D3D11_EXPECT_RESOLVEVIEW); + } else { + _SG_VALIDATE(pass->swapchain.d3d11.resolve_view == 0, VALIDATE_BEGINPASS_SWAPCHAIN_D3D11_EXPECT_RESOLVEVIEW_NOTSET); + } + #elif defined(SOKOL_WGPU) + _SG_VALIDATE(pass->swapchain.wgpu.render_view != 0, VALIDATE_BEGINPASS_SWAPCHAIN_WGPU_EXPECT_RENDERVIEW); + if (pass->swapchain.depth_format == SG_PIXELFORMAT_NONE) { + _SG_VALIDATE(pass->swapchain.wgpu.depth_stencil_view == 0, VALIDATE_BEGINPASS_SWAPCHAIN_WGPU_EXPECT_DEPTHSTENCILVIEW_NOTSET); + } else { + _SG_VALIDATE(pass->swapchain.wgpu.depth_stencil_view != 0, VALIDATE_BEGINPASS_SWAPCHAIN_WGPU_EXPECT_DEPTHSTENCILVIEW); + } + if (pass->swapchain.sample_count > 1) { + _SG_VALIDATE(pass->swapchain.wgpu.resolve_view != 0, VALIDATE_BEGINPASS_SWAPCHAIN_WGPU_EXPECT_RESOLVEVIEW); + } else { + _SG_VALIDATE(pass->swapchain.wgpu.resolve_view == 0, VALIDATE_BEGINPASS_SWAPCHAIN_WGPU_EXPECT_RESOLVEVIEW_NOTSET); + } + #elif defined(SOKOL_VULKAN) + _SG_VALIDATE(pass->swapchain.vulkan.render_image != 0, VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_RENDERIMAGE); + _SG_VALIDATE(pass->swapchain.vulkan.render_view != 0, VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_RENDERVIEW); + if (pass->swapchain.depth_format == SG_PIXELFORMAT_NONE) { + _SG_VALIDATE(pass->swapchain.vulkan.depth_stencil_image == 0, VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_DEPTHSTENCILIMAGE_NOTSET); + _SG_VALIDATE(pass->swapchain.vulkan.depth_stencil_view == 0, VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_DEPTHSTENCILVIEW_NOTSET); + } else { + _SG_VALIDATE(pass->swapchain.vulkan.depth_stencil_image != 0, VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_DEPTHSTENCILIMAGE); + _SG_VALIDATE(pass->swapchain.vulkan.depth_stencil_view != 0, VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_DEPTHSTENCILVIEW); + } + if (pass->swapchain.sample_count > 1) { + _SG_VALIDATE(pass->swapchain.vulkan.resolve_image != 0, VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_RESOLVEIMAGE); + _SG_VALIDATE(pass->swapchain.vulkan.resolve_view != 0, VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_RESOLVEVIEW); + } else { + _SG_VALIDATE(pass->swapchain.vulkan.resolve_image == 0, VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_RESOLVEIMAGE_NOTSET); + _SG_VALIDATE(pass->swapchain.vulkan.resolve_view == 0, VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_RESOLVEVIEW_NOTSET); + } + _SG_VALIDATE(pass->swapchain.vulkan.render_finished_semaphore != 0, VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_RENDERFINISHEDSEMAPHORE); + _SG_VALIDATE(pass->swapchain.vulkan.present_complete_semaphore != 0, VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_PRESENTCOMPLETESEMAPHORE); + #endif + } else { + // this is an 'offscreen pass' + bool has_color_atts = false; + bool has_depth_stencil_atts = false; + bool atts_cont = true; + int color_width = -1, color_height = -1, color_sample_count = -1; + for (int att_index = 0; att_index < SG_MAX_COLOR_ATTACHMENTS; att_index++) { + if (pass->attachments.colors[att_index].id == SG_INVALID_ID) { + atts_cont = false; + continue; + } + has_color_atts = true; + _SG_VALIDATE(atts_cont, VALIDATE_BEGINPASS_COLORATTACHMENTVIEWS_CONTINUOUS); + const _sg_view_t* view = _sg_lookup_view(pass->attachments.colors[att_index].id); + // the view object must be alive + _SG_VALIDATE(view != 0, VALIDATE_BEGINPASS_COLORATTACHMENTVIEW_ALIVE); + if (view) { + // the view object must be in valid state + _SG_VALIDATE(view->slot.state == SG_RESOURCESTATE_VALID, VALIDATE_BEGINPASS_COLORATTACHMENTVIEW_VALID); + if (view->slot.state == SG_RESOURCESTATE_VALID) { + // the view object must be a color attachment view + _SG_VALIDATE(view->cmn.type == SG_VIEWTYPE_COLORATTACHMENT, VALIDATE_BEGINPASS_COLORATTACHMENTVIEW_TYPE); + // the view's image object must be alive and valid + const _sg_image_t* img = _sg_image_ref_ptr_or_null(&view->cmn.img.ref); + _SG_VALIDATE(img, VALIDATE_BEGINPASS_COLORATTACHMENTVIEW_IMAGE_ALIVE); + if (img) { + _SG_VALIDATE(img->slot.state == SG_RESOURCESTATE_VALID, VALIDATE_BEGINPASS_COLORATTACHMENTVIEW_IMAGE_VALID); + if (img->slot.state == SG_RESOURCESTATE_VALID) { + if (color_width == -1) { + color_width = _sg_image_view_dim(view).width; + color_height = _sg_image_view_dim(view).height; + color_sample_count = img->cmn.sample_count; + } else { + _SG_VALIDATE(color_width == _sg_image_view_dim(view).width, VALIDATE_BEGINPASS_COLORATTACHMENTVIEW_SIZES); + _SG_VALIDATE(color_height == _sg_image_view_dim(view).height, VALIDATE_BEGINPASS_COLORATTACHMENTVIEW_SIZES); + _SG_VALIDATE(color_sample_count == img->cmn.sample_count, VALIDATE_BEGINPASS_COLORATTACHMENTVIEW_SAMPLECOUNTS_EQUAL); + } + } + } + } + } + } + // check resolve views + for (int att_index = 0; att_index < SG_MAX_COLOR_ATTACHMENTS; att_index++) { + if (pass->attachments.resolves[att_index].id == SG_INVALID_ID) { + continue; + } + _SG_VALIDATE(pass->attachments.colors[att_index].id != SG_INVALID_ID, VALIDATE_BEGINPASS_RESOLVEATTACHMENTVIEW_NO_COLORATTACHMENTVIEW); + const _sg_view_t* view = _sg_lookup_view(pass->attachments.resolves[att_index].id); + // the view object must be alive + _SG_VALIDATE(view != 0, VALIDATE_BEGINPASS_RESOLVEATTACHMENTVIEW_ALIVE); + if (view) { + // the view object must be in valid state + _SG_VALIDATE(view->slot.state == SG_RESOURCESTATE_VALID, VALIDATE_BEGINPASS_RESOLVEATTACHMENTVIEW_VALID); + if (view->slot.state == SG_RESOURCESTATE_VALID) { + // the view object must be a resolve attachment view + _SG_VALIDATE(view->cmn.type == SG_VIEWTYPE_RESOLVEATTACHMENT, VALIDATE_BEGINPASS_RESOLVEATTACHMENTVIEW_TYPE); + // the view's image object must be alive and valid + const _sg_image_t* img = _sg_image_ref_ptr_or_null(&view->cmn.img.ref); + _SG_VALIDATE(img, VALIDATE_BEGINPASS_RESOLVEATTACHMENTVIEW_IMAGE_ALIVE); + if (img) { + _SG_VALIDATE(img->slot.state == SG_RESOURCESTATE_VALID, VALIDATE_BEGINPASS_RESOLVEATTACHMENTVIEW_IMAGE_VALID); + if (img->slot.state == SG_RESOURCESTATE_VALID) { + if (color_width != -1) { + _SG_VALIDATE(color_sample_count > 1, VALIDATE_BEGINPASS_COLORATTACHMENTVIEW_SAMPLECOUNT); + _SG_VALIDATE(color_width == _sg_image_view_dim(view).width, VALIDATE_BEGINPASS_RESOLVEATTACHMENTVIEW_SIZES); + _SG_VALIDATE(color_height == _sg_image_view_dim(view).height, VALIDATE_BEGINPASS_RESOLVEATTACHMENTVIEW_SIZES); + } + } + } + } + } + } + // check depth-stencil view + if (pass->attachments.depth_stencil.id != SG_INVALID_ID) { + has_depth_stencil_atts = true; + const _sg_view_t* view = _sg_lookup_view(pass->attachments.depth_stencil.id); + // the view object must be valid + _SG_VALIDATE(view != 0, VALIDATE_BEGINPASS_DEPTHSTENCILATTACHMENTVIEW_ALIVE); + if (view) { + // the view object must be in valid state + _SG_VALIDATE(view->slot.state == SG_RESOURCESTATE_VALID, VALIDATE_BEGINPASS_DEPTHSTENCILATTACHMENTVIEW_VALID); + if (view->slot.state == SG_RESOURCESTATE_VALID) { + // the view object must be a depth stencil attachment view + _SG_VALIDATE(view->cmn.type == SG_VIEWTYPE_DEPTHSTENCILATTACHMENT, VALIDATE_BEGINPASS_DEPTHSTENCILATTACHMENTVIEW_TYPE); + // the view's image object must be alive and valid + const _sg_image_t* img = _sg_image_ref_ptr_or_null(&view->cmn.img.ref); + _SG_VALIDATE(img, VALIDATE_BEGINPASS_DEPTHSTENCILATTACHMENTVIEW_IMAGE_ALIVE); + if (img) { + _SG_VALIDATE(img->slot.state == SG_RESOURCESTATE_VALID, VALIDATE_BEGINPASS_DEPTHSTENCILATTACHMENTVIEW_IMAGE_VALID); + if (img->slot.state == SG_RESOURCESTATE_VALID) { + if (color_width != -1) { + _SG_VALIDATE(color_width == _sg_image_view_dim(view).width, VALIDATE_BEGINPASS_DEPTHSTENCILATTACHMENTVIEW_SIZES); + _SG_VALIDATE(color_height == _sg_image_view_dim(view).height, VALIDATE_BEGINPASS_DEPTHSTENCILATTACHMENTVIEW_SIZES); + _SG_VALIDATE(color_sample_count == img->cmn.sample_count, VALIDATE_BEGINPASS_DEPTHSTENCILATTACHMENTVIEW_SAMPLECOUNT); + } + } + } + } + } + } + // must have at least color- or depth-stencil-attachments + _SG_VALIDATE(has_color_atts || has_depth_stencil_atts, VALIDATE_BEGINPASS_ATTACHMENTS_EXPECTED); + } + if (is_compute_pass || is_offscreen_pass || is_invalid_swapchain_pass) { + _SG_VALIDATE(pass->swapchain.width == 0, VALIDATE_BEGINPASS_SWAPCHAIN_EXPECT_WIDTH_NOTSET); + _SG_VALIDATE(pass->swapchain.height == 0, VALIDATE_BEGINPASS_SWAPCHAIN_EXPECT_HEIGHT_NOTSET); + _SG_VALIDATE(pass->swapchain.sample_count == 0, VALIDATE_BEGINPASS_SWAPCHAIN_EXPECT_SAMPLECOUNT_NOTSET); + _SG_VALIDATE(pass->swapchain.color_format == _SG_PIXELFORMAT_DEFAULT, VALIDATE_BEGINPASS_SWAPCHAIN_EXPECT_COLORFORMAT_NOTSET); + _SG_VALIDATE(pass->swapchain.depth_format == _SG_PIXELFORMAT_DEFAULT, VALIDATE_BEGINPASS_SWAPCHAIN_EXPECT_DEPTHFORMAT_NOTSET); + #if defined(SOKOL_METAL) + _SG_VALIDATE(pass->swapchain.metal.current_drawable == 0, VALIDATE_BEGINPASS_SWAPCHAIN_METAL_EXPECT_CURRENTDRAWABLE_NOTSET); + _SG_VALIDATE(pass->swapchain.metal.depth_stencil_texture == 0, VALIDATE_BEGINPASS_SWAPCHAIN_METAL_EXPECT_DEPTHSTENCILTEXTURE_NOTSET); + _SG_VALIDATE(pass->swapchain.metal.msaa_color_texture == 0, VALIDATE_BEGINPASS_SWAPCHAIN_METAL_EXPECT_MSAACOLORTEXTURE_NOTSET); + #elif defined(SOKOL_D3D11) + _SG_VALIDATE(pass->swapchain.d3d11.render_view == 0, VALIDATE_BEGINPASS_SWAPCHAIN_D3D11_EXPECT_RENDERVIEW_NOTSET); + _SG_VALIDATE(pass->swapchain.d3d11.depth_stencil_view == 0, VALIDATE_BEGINPASS_SWAPCHAIN_D3D11_EXPECT_DEPTHSTENCILVIEW_NOTSET); + _SG_VALIDATE(pass->swapchain.d3d11.resolve_view == 0, VALIDATE_BEGINPASS_SWAPCHAIN_D3D11_EXPECT_RESOLVEVIEW_NOTSET); + #elif defined(SOKOL_WGPU) + _SG_VALIDATE(pass->swapchain.wgpu.render_view == 0, VALIDATE_BEGINPASS_SWAPCHAIN_WGPU_EXPECT_RENDERVIEW_NOTSET); + _SG_VALIDATE(pass->swapchain.wgpu.depth_stencil_view == 0, VALIDATE_BEGINPASS_SWAPCHAIN_WGPU_EXPECT_DEPTHSTENCILVIEW_NOTSET); + _SG_VALIDATE(pass->swapchain.wgpu.resolve_view == 0, VALIDATE_BEGINPASS_SWAPCHAIN_WGPU_EXPECT_RESOLVEVIEW_NOTSET); + #elif defined(_SOKOL_ANY_GL) + _SG_VALIDATE(pass->swapchain.gl.framebuffer == 0, VALIDATE_BEGINPASS_SWAPCHAIN_GL_EXPECT_FRAMEBUFFER_NOTSET); + #elif defined(SOKOL_VULKAN) + _SG_VALIDATE(pass->swapchain.vulkan.render_image == 0, VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_RENDERIMAGE_NOTSET); + _SG_VALIDATE(pass->swapchain.vulkan.render_view == 0, VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_RENDERVIEW_NOTSET); + _SG_VALIDATE(pass->swapchain.vulkan.depth_stencil_image == 0, VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_DEPTHSTENCILIMAGE_NOTSET); + _SG_VALIDATE(pass->swapchain.vulkan.depth_stencil_view == 0, VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_DEPTHSTENCILVIEW_NOTSET); + _SG_VALIDATE(pass->swapchain.vulkan.resolve_image == 0, VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_RESOLVEIMAGE_NOTSET); + _SG_VALIDATE(pass->swapchain.vulkan.resolve_view == 0, VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_RESOLVEVIEW_NOTSET); + _SG_VALIDATE(pass->swapchain.vulkan.render_finished_semaphore == 0, VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_RENDERFINISHEDSEMAPHORE_NOTSET); + _SG_VALIDATE(pass->swapchain.vulkan.present_complete_semaphore == 0, VALIDATE_BEGINPASS_SWAPCHAIN_VULKAN_EXPECT_PRESENTCOMPLETESEMAPHORE_NOTSET); + #endif + } + return _sg_validate_end(); + #endif +} + +_SOKOL_PRIVATE bool _sg_validate_apply_viewport(int x, int y, int width, int height, bool origin_top_left) { + _SOKOL_UNUSED(x); + _SOKOL_UNUSED(y); + _SOKOL_UNUSED(width); + _SOKOL_UNUSED(height); + _SOKOL_UNUSED(origin_top_left); + #if !defined(SOKOL_DEBUG) + return true; + #else + if (_sg.desc.disable_validation) { + return true; + } + _sg_validate_begin(); + _SG_VALIDATE(_sg.cur_pass.in_pass && !_sg.cur_pass.is_compute, VALIDATE_AVP_RENDERPASS_EXPECTED); + return _sg_validate_end(); + #endif +} + +_SOKOL_PRIVATE bool _sg_validate_apply_scissor_rect(int x, int y, int width, int height, bool origin_top_left) { + _SOKOL_UNUSED(x); + _SOKOL_UNUSED(y); + _SOKOL_UNUSED(width); + _SOKOL_UNUSED(height); + _SOKOL_UNUSED(origin_top_left); + #if !defined(SOKOL_DEBUG) + return true; + #else + if (_sg.desc.disable_validation) { + return true; + } + _sg_validate_begin(); + _SG_VALIDATE(_sg.cur_pass.in_pass && !_sg.cur_pass.is_compute, VALIDATE_ASR_RENDERPASS_EXPECTED); + return _sg_validate_end(); + #endif +} + +_SOKOL_PRIVATE bool _sg_validate_apply_pipeline(sg_pipeline pip_id) { + #if !defined(SOKOL_DEBUG) + _SOKOL_UNUSED(pip_id); + return true; + #else + if (_sg.desc.disable_validation) { + return true; + } + _sg_validate_begin(); + // the pipeline object must be alive and valid + _SG_VALIDATE(pip_id.id != SG_INVALID_ID, VALIDATE_APIP_PIPELINE_VALID_ID); + const _sg_pipeline_t* pip = _sg_lookup_pipeline(pip_id.id); + _SG_VALIDATE(pip != 0, VALIDATE_APIP_PIPELINE_EXISTS); + if (!pip) { + return _sg_validate_end(); + } + _SG_VALIDATE(pip->slot.state == SG_RESOURCESTATE_VALID, VALIDATE_APIP_PIPELINE_VALID); + + // the pipeline's shader must be alive and valid + _SG_VALIDATE(_sg.cur_pass.in_pass, VALIDATE_APIP_PASS_EXPECTED); + const bool shd_alive = _sg_shader_ref_alive(&pip->cmn.shader); + const _sg_shader_t* shd = shd_alive ? _sg_shader_ref_ptr(&pip->cmn.shader) : 0; + _SG_VALIDATE(shd_alive, VALIDATE_APIP_PIPELINE_SHADER_ALIVE); + if (shd_alive) { + _SG_VALIDATE(shd->slot.state == SG_RESOURCESTATE_VALID, VALIDATE_APIP_PIPELINE_SHADER_VALID); + } else { + return _sg_validate_end(); + } + + if (pip->cmn.is_compute) { + _SG_VALIDATE(_sg.cur_pass.is_compute, VALIDATE_APIP_COMPUTEPASS_EXPECTED); + } else { + _SG_VALIDATE(!_sg.cur_pass.is_compute, VALIDATE_APIP_RENDERPASS_EXPECTED); + if (_sg_attachments_empty(&_sg.cur_pass.atts)) { + // a swapchain pass + _SG_VALIDATE(pip->cmn.color_count == 1, VALIDATE_APIP_SWAPCHAIN_COLOR_COUNT); + _SG_VALIDATE(pip->cmn.colors[0].pixel_format == _sg.cur_pass.swapchain.color_fmt, VALIDATE_APIP_SWAPCHAIN_COLOR_FORMAT); + _SG_VALIDATE(pip->cmn.depth.pixel_format == _sg.cur_pass.swapchain.depth_fmt, VALIDATE_APIP_SWAPCHAIN_DEPTH_FORMAT); + _SG_VALIDATE(pip->cmn.sample_count == _sg.cur_pass.swapchain.sample_count, VALIDATE_APIP_SWAPCHAIN_SAMPLE_COUNT); + } else { + // an offscreen render pass check that pipeline attributes match current pass attachment attributes + const _sg_attachments_ptrs_t atts_ptrs = _sg_attachments_ptrs(&_sg.cur_pass.atts); + const bool alive = _sg_attachments_alive(&atts_ptrs); + _SG_VALIDATE(alive, VALIDATE_APIP_ATTACHMENTS_ALIVE); + if (alive) { + _SG_VALIDATE(pip->cmn.color_count == atts_ptrs.num_color_views, VALIDATE_APIP_COLORATTACHMENTS_COUNT); + for (int i = 0; i < pip->cmn.color_count; i++) { + const _sg_view_t* clr_view = atts_ptrs.color_views[i]; + SOKOL_ASSERT(clr_view); + _SG_VALIDATE(clr_view->slot.state == SG_RESOURCESTATE_VALID, VALIDATE_APIP_COLORATTACHMENTS_VIEW_VALID); + const _sg_image_t* clr_img = _sg_image_ref_ptr(&clr_view->cmn.img.ref); + SOKOL_ASSERT(clr_img); + _SG_VALIDATE(clr_img->slot.state == SG_RESOURCESTATE_VALID, VALIDATE_APIP_COLORATTACHMENTS_IMAGE_VALID); + _SG_VALIDATE(pip->cmn.colors[i].pixel_format == clr_img->cmn.pixel_format, VALIDATE_APIP_COLORATTACHMENTS_FORMAT); + _SG_VALIDATE(pip->cmn.sample_count == clr_img->cmn.sample_count, VALIDATE_APIP_ATTACHMENT_SAMPLE_COUNT); + } + const _sg_view_t* ds_view = atts_ptrs.ds_view; + if (ds_view) { + _SG_VALIDATE(ds_view->slot.state == SG_RESOURCESTATE_VALID, VALIDATE_APIP_DEPTHSTENCILATTACHMENT_VIEW_VALID); + const _sg_image_t* ds_img = _sg_image_ref_ptr(&ds_view->cmn.img.ref); + SOKOL_ASSERT(ds_img); + _SG_VALIDATE(ds_img->slot.state == SG_RESOURCESTATE_VALID, VALIDATE_APIP_DEPTHSTENCILATTACHMENT_IMAGE_VALID); + _SG_VALIDATE(pip->cmn.depth.pixel_format == ds_img->cmn.pixel_format, VALIDATE_APIP_DEPTHSTENCILATTACHMENT_FORMAT); + _SG_VALIDATE(pip->cmn.sample_count == ds_img->cmn.sample_count, VALIDATE_APIP_ATTACHMENT_SAMPLE_COUNT); + } else { + _SG_VALIDATE(pip->cmn.depth.pixel_format == SG_PIXELFORMAT_NONE, VALIDATE_APIP_DEPTHSTENCILATTACHMENT_FORMAT); + } + } + } + } + return _sg_validate_end(); + #endif +} + +_SOKOL_PRIVATE bool _sg_validate_apply_bindings(const sg_bindings* bindings) { + #if !defined(SOKOL_DEBUG) + _SOKOL_UNUSED(bindings); + return true; + #else + if (_sg.desc.disable_validation) { + return true; + } + _sg_validate_begin(); + + // must be called in a pass + _SG_VALIDATE(_sg.cur_pass.in_pass, VALIDATE_ABND_PASS_EXPECTED); + + // bindings must not be empty + bool has_any_bindings = bindings->index_buffer.id != SG_INVALID_ID; + if (!has_any_bindings) for (size_t i = 0; i < SG_MAX_VERTEXBUFFER_BINDSLOTS; i++) { + has_any_bindings |= bindings->vertex_buffers[i].id != SG_INVALID_ID; + } + if (!has_any_bindings) for (size_t i = 0; i < SG_MAX_VIEW_BINDSLOTS; i++) { + has_any_bindings |= bindings->views[i].id != SG_INVALID_ID; + } + if (!has_any_bindings) for (size_t i = 0; i < SG_MAX_SAMPLER_BINDSLOTS; i++) { + has_any_bindings |= bindings->samplers[i].id != SG_INVALID_ID; + } + _SG_VALIDATE(has_any_bindings, VALIDATE_ABND_EMPTY_BINDINGS); + + // a pipeline object must have been applied + const bool pip_null = _sg_pipeline_ref_null(&_sg.cur_pip); + const bool pip_alive = _sg_pipeline_ref_alive(&_sg.cur_pip); + _SG_VALIDATE(!pip_null, VALIDATE_ABND_NO_PIPELINE); + _SG_VALIDATE(pip_alive, VALIDATE_ABND_PIPELINE_ALIVE); + if (!pip_alive) { + return _sg_validate_end(); + } + const _sg_pipeline_t* pip = _sg_pipeline_ref_ptr(&_sg.cur_pip); + _SG_VALIDATE(pip->slot.state == SG_RESOURCESTATE_VALID, VALIDATE_ABND_PIPELINE_VALID); + + const bool shd_alive = _sg_shader_ref_alive(&pip->cmn.shader); + _SG_VALIDATE(shd_alive, VALIDATE_ABND_PIPELINE_SHADER_ALIVE); + if (!shd_alive) { + return _sg_validate_end(); + } + const _sg_shader_t* shd = _sg_shader_ref_ptr(&pip->cmn.shader); + _SG_VALIDATE(shd->slot.state == SG_RESOURCESTATE_VALID, VALIDATE_ABND_PIPELINE_SHADER_VALID); + + if (_sg.cur_pass.is_compute) { + for (size_t i = 0; i < SG_MAX_VERTEXBUFFER_BINDSLOTS; i++) { + _SG_VALIDATE(bindings->vertex_buffers[i].id == SG_INVALID_ID, VALIDATE_ABND_COMPUTE_EXPECTED_NO_VBUFS); + } + } else { + for (size_t i = 0; i < SG_MAX_VERTEXBUFFER_BINDSLOTS; i++) { + if (pip->cmn.vertex_buffer_layout_active[i]) { + _SG_VALIDATE(bindings->vertex_buffers[i].id != SG_INVALID_ID, VALIDATE_ABND_EXPECTED_VBUF); + if (bindings->vertex_buffers[i].id != SG_INVALID_ID) { + const _sg_buffer_t* buf = _sg_lookup_buffer(bindings->vertex_buffers[i].id); + _SG_VALIDATE(buf != 0, VALIDATE_ABND_VBUF_ALIVE); + // NOTE: state != VALID is legal and skips rendering! + if (buf && buf->slot.state == SG_RESOURCESTATE_VALID) { + _SG_VALIDATE(buf->cmn.usage.vertex_buffer, VALIDATE_ABND_VBUF_USAGE); + _SG_VALIDATE(!buf->cmn.append_overflow, VALIDATE_ABND_VBUF_OVERFLOW); + } + } + } + } + } + + if (_sg.cur_pass.is_compute) { + _SG_VALIDATE(bindings->index_buffer.id == SG_INVALID_ID, VALIDATE_ABND_COMPUTE_EXPECTED_NO_IBUF); + } else { + // index buffer expected or not, and index buffer still exists + if (pip->cmn.index_type == SG_INDEXTYPE_NONE) { + // pipeline defines non-indexed rendering, but index buffer provided + _SG_VALIDATE(bindings->index_buffer.id == SG_INVALID_ID, VALIDATE_ABND_EXPECTED_NO_IBUF); + } else { + // pipeline defines indexed rendering, but no index buffer provided + _SG_VALIDATE(bindings->index_buffer.id != SG_INVALID_ID, VALIDATE_ABND_EXPECTED_IBUF); + } + if (bindings->index_buffer.id != SG_INVALID_ID) { + // buffer in index-buffer-slot must have index buffer usage + const _sg_buffer_t* buf = _sg_lookup_buffer(bindings->index_buffer.id); + _SG_VALIDATE(buf != 0, VALIDATE_ABND_IBUF_ALIVE); + // NOTE: state != VALID is legal and skips rendering! + if (buf && buf->slot.state == SG_RESOURCESTATE_VALID) { + _SG_VALIDATE(buf->cmn.usage.index_buffer, VALIDATE_ABND_IBUF_USAGE); + _SG_VALIDATE(!buf->cmn.append_overflow, VALIDATE_ABND_IBUF_OVERFLOW); + } + } + } + + // has expected view bindings + for (size_t i = 0; i < SG_MAX_VIEW_BINDSLOTS; i++) { + if (shd->cmn.views[i].view_type != SG_VIEWTYPE_INVALID) { + _SG_VALIDATE(bindings->views[i].id != SG_INVALID_ID, VALIDATE_ABND_EXPECTED_VIEW_BINDING); + if (bindings->views[i].id != SG_INVALID_ID) { + const _sg_view_t* view = _sg_lookup_view(bindings->views[i].id); + _SG_VALIDATE(view != 0, VALIDATE_ABND_VIEW_ALIVE); + // the view object must be alive + if (view) { + // NOTE: an invalid view state is allowed and skips rendering + if (view->slot.state == SG_RESOURCESTATE_VALID) { + if (shd->cmn.views[i].view_type == SG_VIEWTYPE_TEXTURE) { + // the view object must be a texture view + _SG_VALIDATE(view->cmn.type == SG_VIEWTYPE_TEXTURE, VALIDATE_ABND_EXPECT_TEXVIEW); + // NOTE: an invalid image ref is allowed and skips rendering + if (_sg_image_ref_valid(&view->cmn.img.ref)) { + const _sg_image_t* img = _sg_image_ref_ptr(&view->cmn.img.ref); + _SG_VALIDATE(img->cmn.type == shd->cmn.views[i].image_type, VALIDATE_ABND_TEXVIEW_IMAGETYPE_MISMATCH); + if (shd->cmn.views[i].multisampled) { + _SG_VALIDATE(img->cmn.sample_count > 1, VALIDATE_ABND_TEXVIEW_EXPECTED_MULTISAMPLED_IMAGE); + } else { + _SG_VALIDATE(img->cmn.sample_count == 1, VALIDATE_ABND_TEXVIEW_EXPECTED_NON_MULTISAMPLED_IMAGE); + } + const _sg_pixelformat_info_t* info = &_sg.formats[img->cmn.pixel_format]; + switch (shd->cmn.views[i].sample_type) { + case SG_IMAGESAMPLETYPE_FLOAT: + _SG_VALIDATE(info->filter, VALIDATE_ABND_TEXVIEW_EXPECTED_FILTERABLE_IMAGE); + break; + case SG_IMAGESAMPLETYPE_DEPTH: + _SG_VALIDATE(info->depth, VALIDATE_ABND_TEXVIEW_EXPECTED_DEPTH_IMAGE); + break; + default: + break; + } + } + } else if (shd->cmn.views[i].view_type == SG_VIEWTYPE_STORAGEBUFFER) { + // the view object must be a storage buffer view + _SG_VALIDATE(view->cmn.type == SG_VIEWTYPE_STORAGEBUFFER, VALIDATE_ABND_EXPECT_SBVIEW); + // NOTE: an invalid buffer ref is allowed and skips rendering + if (_sg_buffer_ref_valid(&view->cmn.buf.ref)) { + const _sg_buffer_t* buf = _sg_buffer_ref_ptr(&view->cmn.buf.ref); + if (!shd->cmn.views[i].sbuf_readonly) { + _SG_VALIDATE(buf->cmn.usage.immutable, VALIDATE_ABND_SBVIEW_READWRITE_IMMUTABLE); + } + } + } else if (shd->cmn.views[i].view_type == SG_VIEWTYPE_STORAGEIMAGE) { + // the view object must be a storage-image-view + _SG_VALIDATE(view->cmn.type == SG_VIEWTYPE_STORAGEIMAGE, VALIDATE_ABND_EXPECT_SIMGVIEW); + // storage images only allowed in compute passes + _SG_VALIDATE(_sg.cur_pass.is_compute, VALIDATE_ABND_SIMGVIEW_COMPUTE_PASS_EXPECTED); + // NOTE: an invalid image ref is allowed and skips rendering + if (_sg_image_ref_valid(&view->cmn.img.ref)) { + const _sg_image_t* img = _sg_image_ref_ptr(&view->cmn.img.ref); + _SG_VALIDATE(img->cmn.type == shd->cmn.views[i].image_type, VALIDATE_ABND_SIMGVIEW_IMAGETYPE_MISMATCH); + _SG_VALIDATE(img->cmn.pixel_format == shd->cmn.views[i].access_format, VALIDATE_ABND_SIMGVIEW_ACCESSFORMAT); + } + } + } + } + } + } + } + + // has expected samplers + for (size_t i = 0; i < SG_MAX_SAMPLER_BINDSLOTS; i++) { + if (shd->cmn.samplers[i].stage != SG_SHADERSTAGE_NONE) { + _SG_VALIDATE(bindings->samplers[i].id != SG_INVALID_ID, VALIDATE_ABND_EXPECTED_SAMPLER_BINDING); + if (bindings->samplers[i].id != SG_INVALID_ID) { + const _sg_sampler_t* smp = _sg_lookup_sampler(bindings->samplers[i].id); + _SG_VALIDATE(smp != 0, VALIDATE_ABND_SAMPLER_ALIVE); + if (smp) { + // NOTE: for invalid samplers don't skip rendering, but are actually an error + _SG_VALIDATE(smp->slot.state == SG_RESOURCESTATE_VALID, VALIDATE_ABND_SAMPLER_VALID); + if (shd->cmn.samplers[i].sampler_type == SG_SAMPLERTYPE_COMPARISON) { + _SG_VALIDATE(smp->cmn.compare != SG_COMPAREFUNC_NEVER, VALIDATE_ABND_UNEXPECTED_SAMPLER_COMPARE_NEVER); + } else { + _SG_VALIDATE(smp->cmn.compare == SG_COMPAREFUNC_NEVER, VALIDATE_ABND_EXPECTED_SAMPLER_COMPARE_NEVER); + } + if (shd->cmn.samplers[i].sampler_type == SG_SAMPLERTYPE_NONFILTERING) { + const bool nonfiltering = (smp->cmn.min_filter != SG_FILTER_LINEAR) + && (smp->cmn.mag_filter != SG_FILTER_LINEAR) + && (smp->cmn.mipmap_filter != SG_FILTER_LINEAR); + _SG_VALIDATE(nonfiltering, VALIDATE_ABND_EXPECTED_NONFILTERING_SAMPLER); + } + } + } + } + } + + // the same image cannot be used as texture binding and pass attachment or storage image binding + for (size_t tex_view_idx = 0; tex_view_idx < SG_MAX_VIEW_BINDSLOTS; tex_view_idx++) { + if (shd->cmn.views[tex_view_idx].view_type == SG_VIEWTYPE_TEXTURE) { + if (bindings->views[tex_view_idx].id == SG_INVALID_ID) { + continue; + } + const _sg_view_t* tex_view = _sg_lookup_view(bindings->views[tex_view_idx].id); + if (tex_view) { + const uint32_t img_id = tex_view->cmn.img.ref.sref.id; + if (!_sg_attachments_empty(&_sg.cur_pass.atts)) { + const _sg_view_t* ds_view = _sg_lookup_view(_sg.cur_pass.atts.depth_stencil.id); + if (ds_view) { + _SG_VALIDATE(img_id != ds_view->cmn.img.ref.sref.id, VALIDATE_ABND_TEXTURE_BINDING_VS_DEPTHSTENCIL_ATTACHMENT); + } + for (size_t att_idx = 0; att_idx < SG_MAX_COLOR_ATTACHMENTS; att_idx++) { + const _sg_view_t* color_view = _sg_lookup_view(_sg.cur_pass.atts.colors[att_idx].id); + if (color_view) { + _SG_VALIDATE(img_id != color_view->cmn.img.ref.sref.id, VALIDATE_ABND_TEXTURE_BINDING_VS_COLOR_ATTACHMENT); + } + const _sg_view_t* resolve_view = _sg_lookup_view(_sg.cur_pass.atts.resolves[att_idx].id); + if (resolve_view) { + _SG_VALIDATE(img_id != resolve_view->cmn.img.ref.sref.id, VALIDATE_ABND_TEXTURE_BINDING_VS_RESOLVE_ATTACHMENT); + } + } + } + for (size_t simg_view_idx = 0; simg_view_idx < SG_MAX_VIEW_BINDSLOTS; simg_view_idx++) { + if (shd->cmn.views[simg_view_idx].view_type == SG_VIEWTYPE_STORAGEIMAGE) { + if (bindings->views[simg_view_idx].id == SG_INVALID_ID) { + continue; + } + const _sg_view_t* simg_view = _sg_lookup_view(bindings->views[simg_view_idx].id); + if (simg_view) { + _SG_VALIDATE(img_id != simg_view->cmn.img.ref.sref.id, VALIDATE_ABND_TEXTURE_VS_STORAGEIMAGE_BINDING); + } + } + } + } + } + } + return _sg_validate_end(); + #endif +} + +_SOKOL_PRIVATE bool _sg_validate_apply_uniforms(int ub_slot, const sg_range* data) { + #if !defined(SOKOL_DEBUG) + _SOKOL_UNUSED(ub_slot); + _SOKOL_UNUSED(data); + return true; + #else + if (_sg.desc.disable_validation) { + return true; + } + SOKOL_ASSERT((ub_slot >= 0) && (ub_slot < SG_MAX_UNIFORMBLOCK_BINDSLOTS)); + _sg_validate_begin(); + _SG_VALIDATE(_sg.cur_pass.in_pass, VALIDATE_AU_PASS_EXPECTED); + const _sg_pipeline_ref_t* pip_ref = &_sg.cur_pip; + const bool pip_null = _sg_pipeline_ref_null(pip_ref); + const bool pip_alive = _sg_pipeline_ref_alive(pip_ref); + _SG_VALIDATE(!pip_null, VALIDATE_AU_NO_PIPELINE); + _SG_VALIDATE(pip_alive, VALIDATE_AU_PIPELINE_ALIVE); + if (pip_alive) { + const _sg_pipeline_t* pip = _sg_pipeline_ref_ptr(pip_ref); + _SG_VALIDATE(pip->slot.state == SG_RESOURCESTATE_VALID, VALIDATE_AU_PIPELINE_VALID); + const _sg_shader_ref_t* shd_ref = &pip->cmn.shader; + const bool shd_alive = _sg_shader_ref_alive(shd_ref); + _SG_VALIDATE(shd_alive, VALIDATE_AU_PIPELINE_SHADER_ALIVE); + if (shd_alive) { + const _sg_shader_t* shd = _sg_shader_ref_ptr(shd_ref); + _SG_VALIDATE(shd->slot.state == SG_RESOURCESTATE_VALID, VALIDATE_AU_PIPELINE_SHADER_VALID); + _SG_VALIDATE(shd->cmn.uniform_blocks[ub_slot].stage != SG_SHADERSTAGE_NONE, VALIDATE_AU_NO_UNIFORMBLOCK_AT_SLOT); + _SG_VALIDATE(data->size == shd->cmn.uniform_blocks[ub_slot].size, VALIDATE_AU_SIZE); + } + } + return _sg_validate_end(); + #endif +} + +_SOKOL_PRIVATE bool _sg_validate_draw(int base_element, int num_elements, int num_instances) { + #if !defined(SOKOL_DEBUG) + _SOKOL_UNUSED(base_element); + _SOKOL_UNUSED(num_elements); + _SOKOL_UNUSED(num_instances); + return true; + #else + if (_sg.desc.disable_validation) { + return true; + } + _sg_validate_begin(); + _SG_VALIDATE(_sg.cur_pass.in_pass && !_sg.cur_pass.is_compute, VALIDATE_DRAW_RENDERPASS_EXPECTED); + _SG_VALIDATE(base_element >= 0, VALIDATE_DRAW_BASEELEMENT_GE_ZERO); + _SG_VALIDATE(num_elements >= 0, VALIDATE_DRAW_NUMELEMENTS_GE_ZERO); + _SG_VALIDATE(num_instances >= 0, VALIDATE_DRAW_NUMINSTANCES_GE_ZERO); + _SG_VALIDATE(_sg.required_bindings_and_uniforms == _sg.applied_bindings_and_uniforms, VALIDATE_DRAW_REQUIRED_BINDINGS_OR_UNIFORMS_MISSING); + return _sg_validate_end(); + #endif +} + +_SOKOL_PRIVATE bool _sg_validate_draw_ex(int base_element, int num_elements, int num_instances, int base_vertex, int base_instance) { + #if !defined(SOKOL_DEBUG) + _SOKOL_UNUSED(base_element); + _SOKOL_UNUSED(num_elements); + _SOKOL_UNUSED(num_instances); + _SOKOL_UNUSED(base_vertex); + _SOKOL_UNUSED(base_instance); + return true; + #else + if (_sg.desc.disable_validation) { + return true; + } + _sg_validate_begin(); + _SG_VALIDATE(_sg.cur_pass.in_pass && !_sg.cur_pass.is_compute, VALIDATE_DRAW_EX_RENDERPASS_EXPECTED); + // NOTE: base_vertex is allowed to be < 0 + _SG_VALIDATE(base_element >= 0, VALIDATE_DRAW_EX_BASEELEMENT_GE_ZERO); + _SG_VALIDATE(num_elements >= 0, VALIDATE_DRAW_EX_NUMELEMENTS_GE_ZERO); + _SG_VALIDATE(num_instances >= 0, VALIDATE_DRAW_EX_NUMINSTANCES_GE_ZERO); + _SG_VALIDATE(base_instance >= 0, VALIDATE_DRAW_EX_BASEINSTANCE_GE_ZERO); + if (base_vertex != 0) { + _SG_VALIDATE(_sg.features.draw_base_vertex, VALIDATE_DRAW_EX_BASEVERTEX_NOT_SUPPORTED); + } + if (base_instance > 0) { + _SG_VALIDATE(_sg.features.draw_base_instance, VALIDATE_DRAW_EX_BASEINSTANCE_NOT_SUPPORTED); + } + if (!_sg.use_indexed_draw) { + _SG_VALIDATE(base_vertex == 0, VALIDATE_DRAW_EX_BASEVERTEX_VS_INDEXED); + } + const bool use_instanced_draw = (num_instances > 1) || _sg.use_instanced_draw; + if (!use_instanced_draw) { + _SG_VALIDATE(base_instance == 0, VALIDATE_DRAW_EX_BASEINSTANCE_VS_INSTANCED); + } + _SG_VALIDATE(_sg.required_bindings_and_uniforms == _sg.applied_bindings_and_uniforms, VALIDATE_DRAW_REQUIRED_BINDINGS_OR_UNIFORMS_MISSING); + return _sg_validate_end(); + #endif +} + +_SOKOL_PRIVATE bool _sg_validate_dispatch(int num_groups_x, int num_groups_y, int num_groups_z) { + #if !defined(SOKOL_DEBUG) + _SOKOL_UNUSED(num_groups_x); + _SOKOL_UNUSED(num_groups_y); + _SOKOL_UNUSED(num_groups_z); + return true; + #else + if (_sg.desc.disable_validation) { + return true; + } + _sg_validate_begin(); + _SG_VALIDATE(_sg.cur_pass.in_pass && _sg.cur_pass.is_compute, VALIDATE_DISPATCH_COMPUTEPASS_EXPECTED); + _SG_VALIDATE((num_groups_x >= 0) && (num_groups_x < (1<<16)), VALIDATE_DISPATCH_NUMGROUPSX); + _SG_VALIDATE((num_groups_y >= 0) && (num_groups_y < (1<<16)), VALIDATE_DISPATCH_NUMGROUPSY); + _SG_VALIDATE((num_groups_z >= 0) && (num_groups_z < (1<<16)), VALIDATE_DISPATCH_NUMGROUPSZ); + _SG_VALIDATE(_sg.required_bindings_and_uniforms == _sg.applied_bindings_and_uniforms, VALIDATE_DRAW_REQUIRED_BINDINGS_OR_UNIFORMS_MISSING); + return _sg_validate_end(); + #endif +} + +_SOKOL_PRIVATE bool _sg_validate_update_buffer(const _sg_buffer_t* buf, const sg_range* data) { + #if !defined(SOKOL_DEBUG) + _SOKOL_UNUSED(buf); + _SOKOL_UNUSED(data); + return true; + #else + if (_sg.desc.disable_validation) { + return true; + } + SOKOL_ASSERT(buf && data && data->ptr); + _sg_validate_begin(); + _SG_VALIDATE(!buf->cmn.usage.immutable, VALIDATE_UPDATEBUF_USAGE); + _SG_VALIDATE(buf->cmn.size >= (int)data->size, VALIDATE_UPDATEBUF_SIZE); + _SG_VALIDATE(buf->cmn.update_frame_index != _sg.frame_index, VALIDATE_UPDATEBUF_ONCE); + _SG_VALIDATE(buf->cmn.append_frame_index != _sg.frame_index, VALIDATE_UPDATEBUF_APPEND); + return _sg_validate_end(); + #endif +} + +_SOKOL_PRIVATE bool _sg_validate_append_buffer(const _sg_buffer_t* buf, const sg_range* data) { + #if !defined(SOKOL_DEBUG) + _SOKOL_UNUSED(buf); + _SOKOL_UNUSED(data); + return true; + #else + if (_sg.desc.disable_validation) { + return true; + } + SOKOL_ASSERT(buf && data && data->ptr); + _sg_validate_begin(); + _SG_VALIDATE(!buf->cmn.usage.immutable, VALIDATE_APPENDBUF_USAGE); + _SG_VALIDATE(buf->cmn.size >= (buf->cmn.append_pos + (int)data->size), VALIDATE_APPENDBUF_SIZE); + _SG_VALIDATE(buf->cmn.update_frame_index != _sg.frame_index, VALIDATE_APPENDBUF_UPDATE); + return _sg_validate_end(); + #endif +} + +_SOKOL_PRIVATE bool _sg_validate_update_image(const _sg_image_t* img, const sg_image_data* data) { + #if !defined(SOKOL_DEBUG) + _SOKOL_UNUSED(img); + _SOKOL_UNUSED(data); + return true; + #else + if (_sg.desc.disable_validation) { + return true; + } + SOKOL_ASSERT(img && data); + _sg_validate_begin(); + _SG_VALIDATE(!img->cmn.usage.immutable, VALIDATE_UPDIMG_USAGE); + _SG_VALIDATE(img->cmn.upd_frame_index != _sg.frame_index, VALIDATE_UPDIMG_ONCE); + _sg_validate_image_data(data, + img->cmn.pixel_format, + img->cmn.width, + img->cmn.height, + img->cmn.num_mipmaps, + img->cmn.num_slices); + return _sg_validate_end(); + #endif +} + +_SOKOL_PRIVATE bool _sg_validate_shader_binding_limits(const sg_shader_desc* desc) { + SOKOL_ASSERT(desc); + + // NOTE: this validation check is also active in release mode, if a shader uses + // more bindings than allowed, shader creation will fail + int vs_num_tex = 0; + int fs_num_tex = 0; + int cs_num_tex = 0; + int vs_num_sbuf = 0; + int fs_num_sbuf = 0; + int cs_num_sbuf = 0; + int vs_num_simg = 0; + int fs_num_simg = 0; + int cs_num_simg = 0; + int vs_num_texsmp = 0; + int fs_num_texsmp = 0; + int cs_num_texsmp = 0; + for (size_t i = 0; i < SG_MAX_VIEW_BINDSLOTS; i++) { + switch (desc->views[i].texture.stage) { + case SG_SHADERSTAGE_VERTEX: vs_num_tex++; break; + case SG_SHADERSTAGE_FRAGMENT: fs_num_tex++; break; + case SG_SHADERSTAGE_COMPUTE: cs_num_tex++; break; + default: break; + } + switch (desc->views[i].storage_buffer.stage) { + case SG_SHADERSTAGE_VERTEX: vs_num_sbuf++; break; + case SG_SHADERSTAGE_FRAGMENT: fs_num_sbuf++; break; + case SG_SHADERSTAGE_COMPUTE: cs_num_sbuf++; break; + default: break; + } + switch (desc->views[i].storage_image.stage) { + case SG_SHADERSTAGE_VERTEX: vs_num_simg++; break; + case SG_SHADERSTAGE_FRAGMENT: fs_num_simg++; break; + case SG_SHADERSTAGE_COMPUTE: cs_num_simg++; break; + default: break; + } + } + for (size_t i = 0; i < SG_MAX_TEXTURE_SAMPLER_PAIRS; i++) { + switch (desc->texture_sampler_pairs[i].stage) { + case SG_SHADERSTAGE_VERTEX: vs_num_texsmp++; break; + case SG_SHADERSTAGE_FRAGMENT: fs_num_texsmp++; break; + case SG_SHADERSTAGE_COMPUTE: cs_num_texsmp++; break; + default: break; + } + } + const int max_tex = _sg.limits.max_texture_bindings_per_stage; + const int max_sbuf = _sg.limits.max_storage_buffer_bindings_per_stage; + const int max_simg = _sg.limits.max_storage_image_bindings_per_stage; + bool retval = true; + if (vs_num_tex > max_tex) { + _SG_ERROR(SHADERDESC_TOO_MANY_VERTEXSTAGE_TEXTURES); + retval = false; + } + if (fs_num_tex > max_tex) { + _SG_ERROR(SHADERDESC_TOO_MANY_FRAGMENTSTAGE_TEXTURES); + retval = false; + } + if (cs_num_tex > max_tex) { + _SG_ERROR(SHADERDESC_TOO_MANY_COMPUTESTAGE_TEXTURES); + retval = false; + } + if (vs_num_sbuf > max_sbuf) { + _SG_ERROR(SHADERDESC_TOO_MANY_VERTEXSTAGE_STORAGEBUFFERS); + retval = false; + } + if (fs_num_sbuf > max_sbuf) { + _SG_ERROR(SHADERDESC_TOO_MANY_FRAGMENTSTAGE_STORAGEBUFFERS); + retval = false; + } + if (cs_num_sbuf > max_sbuf) { + _SG_ERROR(SHADERDESC_TOO_MANY_COMPUTESTAGE_STORAGEBUFFERS); + retval = false; + } + if (vs_num_simg > max_simg) { + _SG_ERROR(SHADERDESC_TOO_MANY_VERTEXSTAGE_STORAGEIMAGES); + retval = false; + } + if (fs_num_simg > max_simg) { + _SG_ERROR(SHADERDESC_TOO_MANY_FRAGMENTSTAGE_STORAGEIMAGES); + retval = false; + } + if (cs_num_simg > max_simg) { + _SG_ERROR(SHADERDESC_TOO_MANY_COMPUTESTAGE_STORAGEIMAGES); + retval = false; + } + if (vs_num_texsmp > max_tex) { + _SG_ERROR(SHADERDESC_TOO_MANY_VERTEXSTAGE_TEXTURESAMPLERPAIRS); + retval = false; + } + if (fs_num_texsmp > max_tex) { + _SG_ERROR(SHADERDESC_TOO_MANY_FRAGMENTSTAGE_TEXTURESAMPLERPAIRS); + retval = false; + } + if (cs_num_texsmp > max_tex) { + _SG_ERROR(SHADERDESC_TOO_MANY_COMPUTESTAGE_TEXTURESAMPLERPAIRS); + retval = false; + } + return retval; +} + +_SOKOL_PRIVATE bool _sg_validate_pass_attachment_limits(const sg_pass* pass) { + SOKOL_ASSERT(pass); + int num_color_atts = 0; + int num_resolve_atts = 0; + for (int att_index = 0; att_index < SG_MAX_COLOR_ATTACHMENTS; att_index++) { + if (pass->attachments.colors[att_index].id != SG_INVALID_ID) { + num_color_atts += 1; + } + if (pass->attachments.resolves[att_index].id != SG_INVALID_ID) { + num_resolve_atts += 1; + } + } + bool retval = true; + int max_color_atts = _sg.limits.max_color_attachments; + if (num_color_atts > max_color_atts) { + _SG_ERROR(BEGINPASS_TOO_MANY_COLOR_ATTACHMENTS); + retval = false; + } + // max_color_attachments not a bug + if (num_resolve_atts > max_color_atts) { + _SG_ERROR(BEGINPASS_TOO_MANY_RESOLVE_ATTACHMENTS); + retval = false; + } + return retval; +} + +// ██████ ███████ ███████ ██████ ██ ██ ██████ ██████ ███████ ███████ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ██████ █████ ███████ ██ ██ ██ ██ ██████ ██ █████ ███████ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ██ ██ ███████ ███████ ██████ ██████ ██ ██ ██████ ███████ ███████ +// +// >>resources +_SOKOL_PRIVATE sg_buffer_usage _sg_buffer_usage_defaults(const sg_buffer_usage* usg) { + sg_buffer_usage def = *usg; + if (!(def.vertex_buffer || def.index_buffer || def.storage_buffer)) { + def.vertex_buffer = true; + } + if (!(def.immutable || def.stream_update || def.dynamic_update)) { + def.immutable = true; + } + return def; +} + + +_SOKOL_PRIVATE sg_buffer_desc _sg_buffer_desc_defaults(const sg_buffer_desc* desc) { + sg_buffer_desc def = *desc; + def.usage = _sg_buffer_usage_defaults(&def.usage); + if (def.size == 0) { + def.size = def.data.size; + } + return def; +} + +_SOKOL_PRIVATE sg_image_usage _sg_image_usage_defaults(const sg_image_usage *usg) { + sg_image_usage def = *usg; + if (!(def.immutable || def.stream_update || def.dynamic_update)) { + def.immutable = true; + } + return def; +} + +_SOKOL_PRIVATE sg_image_desc _sg_image_desc_defaults(const sg_image_desc* desc) { + sg_image_desc def = *desc; + def.type = _sg_def(def.type, SG_IMAGETYPE_2D); + def.usage = _sg_image_usage_defaults(&def.usage); + def.num_slices = _sg_def(def.num_slices, def.type == SG_IMAGETYPE_CUBE ? 6 : 1); + def.num_mipmaps = _sg_def(def.num_mipmaps, 1); + if (def.usage.color_attachment || def.usage.resolve_attachment) { + def.pixel_format = _sg_def(def.pixel_format, _sg.desc.environment.defaults.color_format); + def.sample_count = _sg_def(def.sample_count, _sg.desc.environment.defaults.sample_count); + } else if (def.usage.depth_stencil_attachment) { + def.pixel_format = _sg_def(def.pixel_format, _sg.desc.environment.defaults.depth_format); + def.sample_count = _sg_def(def.sample_count, _sg.desc.environment.defaults.sample_count); + } else { + def.pixel_format = _sg_def(def.pixel_format, SG_PIXELFORMAT_RGBA8); + def.sample_count = _sg_def(def.sample_count, 1); + } + return def; +} + +_SOKOL_PRIVATE sg_sampler_desc _sg_sampler_desc_defaults(const sg_sampler_desc* desc) { + sg_sampler_desc def = *desc; + def.min_filter = _sg_def(def.min_filter, SG_FILTER_NEAREST); + def.mag_filter = _sg_def(def.mag_filter, SG_FILTER_NEAREST); + def.mipmap_filter = _sg_def(def.mipmap_filter, SG_FILTER_NEAREST); + def.wrap_u = _sg_def(def.wrap_u, SG_WRAP_REPEAT); + def.wrap_v = _sg_def(def.wrap_v, SG_WRAP_REPEAT); + def.wrap_w = _sg_def(def.wrap_w, SG_WRAP_REPEAT); + def.max_lod = _sg_def_flt(def.max_lod, FLT_MAX); + def.border_color = _sg_def(def.border_color, SG_BORDERCOLOR_OPAQUE_BLACK); + def.compare = _sg_def(def.compare, SG_COMPAREFUNC_NEVER); + def.max_anisotropy = _sg_def(def.max_anisotropy, 1); + return def; +} + +_SOKOL_PRIVATE sg_shader_desc _sg_shader_desc_defaults(const sg_shader_desc* desc) { + sg_shader_desc def = *desc; + #if defined(SOKOL_METAL) + def.vertex_func.entry = _sg_def(def.vertex_func.entry, "_main"); + def.fragment_func.entry = _sg_def(def.fragment_func.entry, "_main"); + def.compute_func.entry = _sg_def(def.compute_func.entry, "_main"); + #else + def.vertex_func.entry = _sg_def(def.vertex_func.entry, "main"); + def.fragment_func.entry = _sg_def(def.fragment_func.entry, "main"); + def.compute_func.entry = _sg_def(def.compute_func.entry, "main"); + #endif + #if defined(SOKOL_D3D11) + if (def.vertex_func.source) { + def.vertex_func.d3d11_target = _sg_def(def.vertex_func.d3d11_target, "vs_4_0"); + } + if (def.fragment_func.source) { + def.fragment_func.d3d11_target = _sg_def(def.fragment_func.d3d11_target, "ps_4_0"); + } + if (def.compute_func.source) { + def.compute_func.d3d11_target = _sg_def(def.fragment_func.d3d11_target,"cs_5_0"); + } + #endif + def.mtl_threads_per_threadgroup.y = _sg_def(desc->mtl_threads_per_threadgroup.y, 1); + def.mtl_threads_per_threadgroup.z = _sg_def(desc->mtl_threads_per_threadgroup.z, 1); + for (size_t ub_index = 0; ub_index < SG_MAX_UNIFORMBLOCK_BINDSLOTS; ub_index++) { + sg_shader_uniform_block* ub_desc = &def.uniform_blocks[ub_index]; + if (ub_desc->stage != SG_SHADERSTAGE_NONE) { + ub_desc->layout = _sg_def(ub_desc->layout, SG_UNIFORMLAYOUT_NATIVE); + for (size_t u_index = 0; u_index < SG_MAX_UNIFORMBLOCK_MEMBERS; u_index++) { + sg_glsl_shader_uniform* u_desc = &ub_desc->glsl_uniforms[u_index]; + if (u_desc->type == SG_UNIFORMTYPE_INVALID) { + break; + } + u_desc->array_count = _sg_def(u_desc->array_count, 1); + } + } + } + for (size_t view_index = 0; view_index < SG_MAX_VIEW_BINDSLOTS; view_index++) { + sg_shader_view* view_desc = &def.views[view_index]; + if (view_desc->texture.stage != SG_SHADERSTAGE_NONE) { + view_desc->texture.image_type = _sg_def(view_desc->texture.image_type, SG_IMAGETYPE_2D); + view_desc->texture.sample_type = _sg_def(view_desc->texture.sample_type, SG_IMAGESAMPLETYPE_FLOAT); + } else if (view_desc->storage_image.stage != SG_SHADERSTAGE_NONE) { + view_desc->storage_image.image_type = _sg_def(view_desc->storage_image.image_type, SG_IMAGETYPE_2D); + } + } + for (size_t smp_index = 0; smp_index < SG_MAX_SAMPLER_BINDSLOTS; smp_index++) { + sg_shader_sampler* smp_desc = &def.samplers[smp_index]; + if (smp_desc->stage != SG_SHADERSTAGE_NONE) { + smp_desc->sampler_type = _sg_def(smp_desc->sampler_type, SG_SAMPLERTYPE_FILTERING); + } + } + return def; +} + +_SOKOL_PRIVATE sg_pipeline_desc _sg_pipeline_desc_defaults(const sg_pipeline_desc* desc) { + sg_pipeline_desc def = *desc; + + // FIXME: should we actually do all this stuff for a compute pipeline? + + def.primitive_type = _sg_def(def.primitive_type, SG_PRIMITIVETYPE_TRIANGLES); + def.index_type = _sg_def(def.index_type, SG_INDEXTYPE_NONE); + def.cull_mode = _sg_def(def.cull_mode, SG_CULLMODE_NONE); + def.face_winding = _sg_def(def.face_winding, SG_FACEWINDING_CW); + def.sample_count = _sg_def(def.sample_count, _sg.desc.environment.defaults.sample_count); + + def.stencil.front.compare = _sg_def(def.stencil.front.compare, SG_COMPAREFUNC_ALWAYS); + def.stencil.front.fail_op = _sg_def(def.stencil.front.fail_op, SG_STENCILOP_KEEP); + def.stencil.front.depth_fail_op = _sg_def(def.stencil.front.depth_fail_op, SG_STENCILOP_KEEP); + def.stencil.front.pass_op = _sg_def(def.stencil.front.pass_op, SG_STENCILOP_KEEP); + def.stencil.back.compare = _sg_def(def.stencil.back.compare, SG_COMPAREFUNC_ALWAYS); + def.stencil.back.fail_op = _sg_def(def.stencil.back.fail_op, SG_STENCILOP_KEEP); + def.stencil.back.depth_fail_op = _sg_def(def.stencil.back.depth_fail_op, SG_STENCILOP_KEEP); + def.stencil.back.pass_op = _sg_def(def.stencil.back.pass_op, SG_STENCILOP_KEEP); + + def.depth.compare = _sg_def(def.depth.compare, SG_COMPAREFUNC_ALWAYS); + def.depth.pixel_format = _sg_def(def.depth.pixel_format, _sg.desc.environment.defaults.depth_format); + if (def.colors[0].pixel_format == SG_PIXELFORMAT_NONE) { + // special case depth-only rendering, enforce a color count of 0 + def.color_count = 0; + } else { + def.color_count = _sg_def(def.color_count, 1); + } + if (def.color_count > SG_MAX_COLOR_ATTACHMENTS) { + def.color_count = SG_MAX_COLOR_ATTACHMENTS; + } + for (int i = 0; i < def.color_count; i++) { + sg_color_target_state* cs = &def.colors[i]; + cs->pixel_format = _sg_def(cs->pixel_format, _sg.desc.environment.defaults.color_format); + cs->write_mask = _sg_def(cs->write_mask, SG_COLORMASK_RGBA); + sg_blend_state* bs = &def.colors[i].blend; + bs->op_rgb = _sg_def(bs->op_rgb, SG_BLENDOP_ADD); + bs->src_factor_rgb = _sg_def(bs->src_factor_rgb, SG_BLENDFACTOR_ONE); + if ((bs->op_rgb == SG_BLENDOP_MIN) || (bs->op_rgb == SG_BLENDOP_MAX)) { + bs->dst_factor_rgb = _sg_def(bs->dst_factor_rgb, SG_BLENDFACTOR_ONE); + } else { + bs->dst_factor_rgb = _sg_def(bs->dst_factor_rgb, SG_BLENDFACTOR_ZERO); + } + bs->op_alpha = _sg_def(bs->op_alpha, SG_BLENDOP_ADD); + bs->src_factor_alpha = _sg_def(bs->src_factor_alpha, SG_BLENDFACTOR_ONE); + if ((bs->op_alpha == SG_BLENDOP_MIN) || (bs->op_alpha == SG_BLENDOP_MAX)) { + bs->dst_factor_alpha = _sg_def(bs->dst_factor_alpha, SG_BLENDFACTOR_ONE); + } else { + bs->dst_factor_alpha = _sg_def(bs->dst_factor_alpha, SG_BLENDFACTOR_ZERO); + } + } + + for (int attr_index = 0; attr_index < SG_MAX_VERTEX_ATTRIBUTES; attr_index++) { + sg_vertex_attr_state* a_state = &def.layout.attrs[attr_index]; + if (a_state->format == SG_VERTEXFORMAT_INVALID) { + break; + } + SOKOL_ASSERT((a_state->buffer_index >= 0) && (a_state->buffer_index < SG_MAX_VERTEXBUFFER_BINDSLOTS)); + sg_vertex_buffer_layout_state* l_state = &def.layout.buffers[a_state->buffer_index]; + l_state->step_func = _sg_def(l_state->step_func, SG_VERTEXSTEP_PER_VERTEX); + l_state->step_rate = _sg_def(l_state->step_rate, 1); + } + + // resolve vertex layout strides and offsets + _SG_STRUCT(int, auto_offset[SG_MAX_VERTEXBUFFER_BINDSLOTS]); + bool use_auto_offset = true; + for (int attr_index = 0; attr_index < SG_MAX_VERTEX_ATTRIBUTES; attr_index++) { + // to use computed offsets, *all* attr offsets must be 0 + if (def.layout.attrs[attr_index].offset != 0) { + use_auto_offset = false; + } + } + for (int attr_index = 0; attr_index < SG_MAX_VERTEX_ATTRIBUTES; attr_index++) { + sg_vertex_attr_state* a_state = &def.layout.attrs[attr_index]; + if (a_state->format == SG_VERTEXFORMAT_INVALID) { + break; + } + SOKOL_ASSERT((a_state->buffer_index >= 0) && (a_state->buffer_index < SG_MAX_VERTEXBUFFER_BINDSLOTS)); + if (use_auto_offset) { + a_state->offset = auto_offset[a_state->buffer_index]; + } + auto_offset[a_state->buffer_index] += _sg_vertexformat_bytesize(a_state->format); + } + // compute vertex strides if needed + for (int buf_index = 0; buf_index < SG_MAX_VERTEXBUFFER_BINDSLOTS; buf_index++) { + sg_vertex_buffer_layout_state* l_state = &def.layout.buffers[buf_index]; + if (l_state->stride == 0) { + l_state->stride = auto_offset[buf_index]; + } + } + + return def; +} + +_SOKOL_PRIVATE sg_view_desc _sg_view_desc_defaults(const sg_view_desc* desc) { + sg_view_desc def = *desc; + return def; +} + +_SOKOL_PRIVATE sg_buffer _sg_alloc_buffer(void) { + sg_buffer res; + int slot_index = _sg_pool_alloc_index(&_sg.pools.buffer_pool); + if (_SG_INVALID_SLOT_INDEX != slot_index) { + res.id = _sg_slot_alloc(&_sg.pools.buffer_pool, &_sg.pools.buffers[slot_index].slot, slot_index); + _sg_resource_stats_inc(buffers.allocated); + } else { + res.id = SG_INVALID_ID; + _SG_ERROR(BUFFER_POOL_EXHAUSTED); + } + return res; +} + +_SOKOL_PRIVATE sg_image _sg_alloc_image(void) { + sg_image res; + int slot_index = _sg_pool_alloc_index(&_sg.pools.image_pool); + if (_SG_INVALID_SLOT_INDEX != slot_index) { + res.id = _sg_slot_alloc(&_sg.pools.image_pool, &_sg.pools.images[slot_index].slot, slot_index); + _sg_resource_stats_inc(images.allocated); + } else { + res.id = SG_INVALID_ID; + _SG_ERROR(IMAGE_POOL_EXHAUSTED); + } + return res; +} + +_SOKOL_PRIVATE sg_sampler _sg_alloc_sampler(void) { + sg_sampler res; + int slot_index = _sg_pool_alloc_index(&_sg.pools.sampler_pool); + if (_SG_INVALID_SLOT_INDEX != slot_index) { + res.id = _sg_slot_alloc(&_sg.pools.sampler_pool, &_sg.pools.samplers[slot_index].slot, slot_index); + _sg_resource_stats_inc(samplers.allocated); + } else { + res.id = SG_INVALID_ID; + _SG_ERROR(SAMPLER_POOL_EXHAUSTED); + } + return res; +} + +_SOKOL_PRIVATE sg_shader _sg_alloc_shader(void) { + sg_shader res; + int slot_index = _sg_pool_alloc_index(&_sg.pools.shader_pool); + if (_SG_INVALID_SLOT_INDEX != slot_index) { + res.id = _sg_slot_alloc(&_sg.pools.shader_pool, &_sg.pools.shaders[slot_index].slot, slot_index); + _sg_resource_stats_inc(shaders.allocated); + } else { + res.id = SG_INVALID_ID; + _SG_ERROR(SHADER_POOL_EXHAUSTED); + } + return res; +} + +_SOKOL_PRIVATE sg_pipeline _sg_alloc_pipeline(void) { + sg_pipeline res; + int slot_index = _sg_pool_alloc_index(&_sg.pools.pipeline_pool); + if (_SG_INVALID_SLOT_INDEX != slot_index) { + res.id =_sg_slot_alloc(&_sg.pools.pipeline_pool, &_sg.pools.pipelines[slot_index].slot, slot_index); + _sg_resource_stats_inc(pipelines.allocated); + } else { + res.id = SG_INVALID_ID; + _SG_ERROR(PIPELINE_POOL_EXHAUSTED); + } + return res; +} + +_SOKOL_PRIVATE sg_view _sg_alloc_view(void) { + sg_view res; + int slot_index = _sg_pool_alloc_index(&_sg.pools.view_pool); + if (_SG_INVALID_SLOT_INDEX != slot_index) { + res.id = _sg_slot_alloc(&_sg.pools.view_pool, &_sg.pools.views[slot_index].slot, slot_index); + _sg_resource_stats_inc(views.allocated); + } else { + res.id = SG_INVALID_ID; + _SG_ERROR(VIEW_POOL_EXHAUSTED); + } + return res; +} + +_SOKOL_PRIVATE void _sg_dealloc_buffer(_sg_buffer_t* buf) { + SOKOL_ASSERT(buf && (buf->slot.state == SG_RESOURCESTATE_ALLOC) && (buf->slot.id != SG_INVALID_ID)); + _sg_pool_free_index(&_sg.pools.buffer_pool, _sg_slot_index(buf->slot.id)); + _sg_slot_reset(&buf->slot); + _sg_resource_stats_inc(buffers.deallocated); +} + +_SOKOL_PRIVATE void _sg_dealloc_image(_sg_image_t* img) { + SOKOL_ASSERT(img && (img->slot.state == SG_RESOURCESTATE_ALLOC) && (img->slot.id != SG_INVALID_ID)); + _sg_pool_free_index(&_sg.pools.image_pool, _sg_slot_index(img->slot.id)); + _sg_slot_reset(&img->slot); + _sg_resource_stats_inc(images.deallocated); +} + +_SOKOL_PRIVATE void _sg_dealloc_sampler(_sg_sampler_t* smp) { + SOKOL_ASSERT(smp && (smp->slot.state == SG_RESOURCESTATE_ALLOC) && (smp->slot.id != SG_INVALID_ID)); + _sg_pool_free_index(&_sg.pools.sampler_pool, _sg_slot_index(smp->slot.id)); + _sg_slot_reset(&smp->slot); + _sg_resource_stats_inc(samplers.deallocated); +} + +_SOKOL_PRIVATE void _sg_dealloc_shader(_sg_shader_t* shd) { + SOKOL_ASSERT(shd && (shd->slot.state == SG_RESOURCESTATE_ALLOC) && (shd->slot.id != SG_INVALID_ID)); + _sg_pool_free_index(&_sg.pools.shader_pool, _sg_slot_index(shd->slot.id)); + _sg_slot_reset(&shd->slot); + _sg_resource_stats_inc(shaders.deallocated); +} + +_SOKOL_PRIVATE void _sg_dealloc_pipeline(_sg_pipeline_t* pip) { + SOKOL_ASSERT(pip && (pip->slot.state == SG_RESOURCESTATE_ALLOC) && (pip->slot.id != SG_INVALID_ID)); + _sg_pool_free_index(&_sg.pools.pipeline_pool, _sg_slot_index(pip->slot.id)); + _sg_slot_reset(&pip->slot); + _sg_resource_stats_inc(pipelines.deallocated); +} + +_SOKOL_PRIVATE void _sg_dealloc_view(_sg_view_t* view) { + SOKOL_ASSERT(view && (view->slot.state == SG_RESOURCESTATE_ALLOC) && (view->slot.id != SG_INVALID_ID)); + _sg_pool_free_index(&_sg.pools.view_pool, _sg_slot_index(view->slot.id)); + _sg_slot_reset(&view->slot); + _sg_resource_stats_inc(views.deallocated); +} + +_SOKOL_PRIVATE void _sg_init_buffer(_sg_buffer_t* buf, const sg_buffer_desc* desc) { + SOKOL_ASSERT(buf && (buf->slot.state == SG_RESOURCESTATE_ALLOC)); + SOKOL_ASSERT(desc); + if (_sg_validate_buffer_desc(desc)) { + _sg_buffer_common_init(&buf->cmn, desc); + buf->slot.state = _sg_create_buffer(buf, desc); + } else { + buf->slot.state = SG_RESOURCESTATE_FAILED; + } + SOKOL_ASSERT((buf->slot.state == SG_RESOURCESTATE_VALID)||(buf->slot.state == SG_RESOURCESTATE_FAILED)); + _sg_resource_stats_inc(buffers.inited); +} + +_SOKOL_PRIVATE void _sg_init_image(_sg_image_t* img, const sg_image_desc* desc) { + SOKOL_ASSERT(img && (img->slot.state == SG_RESOURCESTATE_ALLOC)); + SOKOL_ASSERT(desc); + if (_sg_validate_image_desc(desc)) { + _sg_image_common_init(&img->cmn, desc); + img->slot.state = _sg_create_image(img, desc); + } else { + img->slot.state = SG_RESOURCESTATE_FAILED; + } + SOKOL_ASSERT((img->slot.state == SG_RESOURCESTATE_VALID)||(img->slot.state == SG_RESOURCESTATE_FAILED)); + _sg_resource_stats_inc(images.inited); +} + +_SOKOL_PRIVATE void _sg_init_sampler(_sg_sampler_t* smp, const sg_sampler_desc* desc) { + SOKOL_ASSERT(smp && (smp->slot.state == SG_RESOURCESTATE_ALLOC)); + SOKOL_ASSERT(desc); + if (_sg_validate_sampler_desc(desc)) { + _sg_sampler_common_init(&smp->cmn, desc); + smp->slot.state = _sg_create_sampler(smp, desc); + } else { + smp->slot.state = SG_RESOURCESTATE_FAILED; + } + SOKOL_ASSERT((smp->slot.state == SG_RESOURCESTATE_VALID)||(smp->slot.state == SG_RESOURCESTATE_FAILED)); + _sg_resource_stats_inc(samplers.inited); +} + +_SOKOL_PRIVATE void _sg_init_shader(_sg_shader_t* shd, const sg_shader_desc* desc) { + SOKOL_ASSERT(shd && (shd->slot.state == SG_RESOURCESTATE_ALLOC)); + SOKOL_ASSERT(desc); + if (!_sg_validate_shader_desc(desc)) { + shd->slot.state = SG_RESOURCESTATE_FAILED; + return; + } + if (!_sg_validate_shader_binding_limits(desc)) { + shd->slot.state = SG_RESOURCESTATE_FAILED; + return; + } + _sg_shader_common_init(&shd->cmn, desc); + shd->slot.state = _sg_create_shader(shd, desc); + SOKOL_ASSERT((shd->slot.state == SG_RESOURCESTATE_VALID)||(shd->slot.state == SG_RESOURCESTATE_FAILED)); + _sg_resource_stats_inc(shaders.inited); +} + +_SOKOL_PRIVATE void _sg_init_pipeline(_sg_pipeline_t* pip, const sg_pipeline_desc* desc) { + SOKOL_ASSERT(pip && (pip->slot.state == SG_RESOURCESTATE_ALLOC)); + SOKOL_ASSERT(desc); + if (_sg_validate_pipeline_desc(desc)) { + _sg_shader_t* shd = _sg_lookup_shader(desc->shader.id); + if (shd && (shd->slot.state == SG_RESOURCESTATE_VALID)) { + _sg_pipeline_common_init(&pip->cmn, desc, shd); + pip->slot.state = _sg_create_pipeline(pip, desc); + } else { + pip->slot.state = SG_RESOURCESTATE_FAILED; + } + } else { + pip->slot.state = SG_RESOURCESTATE_FAILED; + } + SOKOL_ASSERT((pip->slot.state == SG_RESOURCESTATE_VALID)||(pip->slot.state == SG_RESOURCESTATE_FAILED)); + _sg_resource_stats_inc(pipelines.inited); +} + +_SOKOL_PRIVATE void _sg_init_view(_sg_view_t* view, const sg_view_desc* desc) { + SOKOL_ASSERT(view && view->slot.state == SG_RESOURCESTATE_ALLOC); + SOKOL_ASSERT(desc); + if (_sg_validate_view_desc(desc)) { + uint32_t buf_id = desc->storage_buffer.buffer.id; + uint32_t img_id = desc->texture.image.id; + img_id = img_id ? img_id : desc->storage_image.image.id; + img_id = img_id ? img_id : desc->color_attachment.image.id; + img_id = img_id ? img_id : desc->resolve_attachment.image.id; + img_id = img_id ? img_id : desc->depth_stencil_attachment.image.id; + _sg_buffer_t* buf = buf_id ? _sg_lookup_buffer(buf_id) : 0; + _sg_image_t* img = img_id ? _sg_lookup_image(img_id) : 0; + sg_resource_state res_state = SG_RESOURCESTATE_INVALID; + if (buf) { + SOKOL_ASSERT(!img); + res_state = buf->slot.state; + } else if (img) { + SOKOL_ASSERT(!buf); + res_state = img->slot.state; + } + if (res_state == SG_RESOURCESTATE_VALID) { + _sg_view_common_init(&view->cmn, desc, buf, img); + view->slot.state = _sg_create_view(view, desc); + } else { + view->slot.state = SG_RESOURCESTATE_FAILED; + } + } else { + view->slot.state = SG_RESOURCESTATE_FAILED; + } + SOKOL_ASSERT((view->slot.state == SG_RESOURCESTATE_VALID) || (view->slot.state == SG_RESOURCESTATE_FAILED)); + _sg_resource_stats_inc(views.inited); +} + +_SOKOL_PRIVATE void _sg_uninit_buffer(_sg_buffer_t* buf) { + SOKOL_ASSERT(buf && ((buf->slot.state == SG_RESOURCESTATE_VALID) || (buf->slot.state == SG_RESOURCESTATE_FAILED))); + _sg_discard_buffer(buf); + _sg_reset_buffer_to_alloc_state(buf); + _sg_resource_stats_inc(buffers.uninited); +} + +_SOKOL_PRIVATE void _sg_uninit_image(_sg_image_t* img) { + SOKOL_ASSERT(img && ((img->slot.state == SG_RESOURCESTATE_VALID) || (img->slot.state == SG_RESOURCESTATE_FAILED))); + _sg_discard_image(img); + _sg_reset_image_to_alloc_state(img); + _sg_resource_stats_inc(images.uninited); +} + +_SOKOL_PRIVATE void _sg_uninit_sampler(_sg_sampler_t* smp) { + SOKOL_ASSERT(smp && ((smp->slot.state == SG_RESOURCESTATE_VALID) || (smp->slot.state == SG_RESOURCESTATE_FAILED))); + _sg_discard_sampler(smp); + _sg_reset_sampler_to_alloc_state(smp); + _sg_resource_stats_inc(samplers.uninited); +} + +_SOKOL_PRIVATE void _sg_uninit_shader(_sg_shader_t* shd) { + SOKOL_ASSERT(shd && ((shd->slot.state == SG_RESOURCESTATE_VALID) || (shd->slot.state == SG_RESOURCESTATE_FAILED))); + _sg_discard_shader(shd); + _sg_reset_shader_to_alloc_state(shd); + _sg_resource_stats_inc(shaders.uninited); +} + +_SOKOL_PRIVATE void _sg_uninit_pipeline(_sg_pipeline_t* pip) { + SOKOL_ASSERT(pip && ((pip->slot.state == SG_RESOURCESTATE_VALID) || (pip->slot.state == SG_RESOURCESTATE_FAILED))); + _sg_discard_pipeline(pip); + _sg_reset_pipeline_to_alloc_state(pip); + _sg_resource_stats_inc(pipelines.uninited); +} + +_SOKOL_PRIVATE void _sg_uninit_view(_sg_view_t* view) { + SOKOL_ASSERT(view && ((view->slot.state == SG_RESOURCESTATE_VALID) || (view->slot.state == SG_RESOURCESTATE_FAILED))); + _sg_discard_view(view); + _sg_reset_view_to_alloc_state(view); + _sg_resource_stats_inc(views.uninited); +} + +_SOKOL_PRIVATE void _sg_setup_commit_listeners(const sg_desc* desc) { + SOKOL_ASSERT(desc->max_commit_listeners > 0); + SOKOL_ASSERT(0 == _sg.commit_listeners.items); + SOKOL_ASSERT(0 == _sg.commit_listeners.num); + SOKOL_ASSERT(0 == _sg.commit_listeners.upper); + _sg.commit_listeners.num = desc->max_commit_listeners; + const size_t size = (size_t)_sg.commit_listeners.num * sizeof(sg_commit_listener); + _sg.commit_listeners.items = (sg_commit_listener*)_sg_malloc_clear(size); +} + +_SOKOL_PRIVATE void _sg_discard_commit_listeners(void) { + SOKOL_ASSERT(0 != _sg.commit_listeners.items); + _sg_free(_sg.commit_listeners.items); + _sg.commit_listeners.items = 0; +} + +_SOKOL_PRIVATE void _sg_notify_commit_listeners(void) { + SOKOL_ASSERT(_sg.commit_listeners.items); + for (int i = 0; i < _sg.commit_listeners.upper; i++) { + const sg_commit_listener* listener = &_sg.commit_listeners.items[i]; + if (listener->func) { + listener->func(listener->user_data); + } + } +} + +_SOKOL_PRIVATE bool _sg_add_commit_listener(const sg_commit_listener* new_listener) { + SOKOL_ASSERT(new_listener && new_listener->func); + SOKOL_ASSERT(_sg.commit_listeners.items); + // first check if the listener hadn't been added already + for (int i = 0; i < _sg.commit_listeners.upper; i++) { + const sg_commit_listener* slot = &_sg.commit_listeners.items[i]; + if ((slot->func == new_listener->func) && (slot->user_data == new_listener->user_data)) { + _SG_ERROR(IDENTICAL_COMMIT_LISTENER); + return false; + } + } + // first try to plug a hole + sg_commit_listener* slot = 0; + for (int i = 0; i < _sg.commit_listeners.upper; i++) { + if (_sg.commit_listeners.items[i].func == 0) { + slot = &_sg.commit_listeners.items[i]; + break; + } + } + if (!slot) { + // append to end + if (_sg.commit_listeners.upper < _sg.commit_listeners.num) { + slot = &_sg.commit_listeners.items[_sg.commit_listeners.upper++]; + } + } + if (!slot) { + _SG_ERROR(COMMIT_LISTENER_ARRAY_FULL); + return false; + } + *slot = *new_listener; + return true; +} + +_SOKOL_PRIVATE bool _sg_remove_commit_listener(const sg_commit_listener* listener) { + SOKOL_ASSERT(listener && listener->func); + SOKOL_ASSERT(_sg.commit_listeners.items); + for (int i = 0; i < _sg.commit_listeners.upper; i++) { + sg_commit_listener* slot = &_sg.commit_listeners.items[i]; + // both the function pointer and user data must match! + if ((slot->func == listener->func) && (slot->user_data == listener->user_data)) { + slot->func = 0; + slot->user_data = 0; + // NOTE: since _sg_add_commit_listener() already catches duplicates, + // we don't need to worry about them here + return true; + } + } + return false; +} + +_SOKOL_PRIVATE sg_desc _sg_desc_defaults(const sg_desc* desc) { + /* + NOTE: on WebGPU, the default color pixel format MUST be provided, + it cannot be a default compile-time constant. + */ + sg_desc res = *desc; + #if defined(SOKOL_WGPU) + SOKOL_ASSERT(SG_PIXELFORMAT_NONE < res.environment.defaults.color_format); + #elif defined(SOKOL_METAL) || defined(SOKOL_D3D11) + res.environment.defaults.color_format = _sg_def(res.environment.defaults.color_format, SG_PIXELFORMAT_BGRA8); + #else + res.environment.defaults.color_format = _sg_def(res.environment.defaults.color_format, SG_PIXELFORMAT_RGBA8); + #endif + res.environment.defaults.depth_format = _sg_def(res.environment.defaults.depth_format, SG_PIXELFORMAT_DEPTH_STENCIL); + res.environment.defaults.sample_count = _sg_def(res.environment.defaults.sample_count, 1); + res.buffer_pool_size = _sg_def(res.buffer_pool_size, _SG_DEFAULT_BUFFER_POOL_SIZE); + res.image_pool_size = _sg_def(res.image_pool_size, _SG_DEFAULT_IMAGE_POOL_SIZE); + res.sampler_pool_size = _sg_def(res.sampler_pool_size, _SG_DEFAULT_SAMPLER_POOL_SIZE); + res.shader_pool_size = _sg_def(res.shader_pool_size, _SG_DEFAULT_SHADER_POOL_SIZE); + res.pipeline_pool_size = _sg_def(res.pipeline_pool_size, _SG_DEFAULT_PIPELINE_POOL_SIZE); + res.view_pool_size = _sg_def(res.view_pool_size, _SG_DEFAULT_VIEW_POOL_SIZE); + res.uniform_buffer_size = _sg_def(res.uniform_buffer_size, _SG_DEFAULT_UB_SIZE); + res.max_commit_listeners = _sg_def(res.max_commit_listeners, _SG_DEFAULT_MAX_COMMIT_LISTENERS); + res.wgpu.bindgroups_cache_size = _sg_def(res.wgpu.bindgroups_cache_size, _SG_DEFAULT_WGPU_BINDGROUP_CACHE_SIZE); + res.vulkan.copy_staging_buffer_size = _sg_def(res.vulkan.copy_staging_buffer_size, _SG_DEFAULT_VK_COPY_STAGING_SIZE); + res.vulkan.stream_staging_buffer_size = _sg_def(res.vulkan.stream_staging_buffer_size, _SG_DEFAULT_VK_STREAM_STAGING_SIZE); + res.vulkan.descriptor_buffer_size = _sg_def(res.vulkan.descriptor_buffer_size, _SG_DEFAULT_VK_DESCRIPTOR_BUFFER_SIZE); + return res; +} + +_SOKOL_PRIVATE sg_pass _sg_pass_defaults(const sg_pass* pass) { + sg_pass res = *pass; + if (!res.compute) { + if (!pass->swapchain.invalid && _sg_attachments_empty(&pass->attachments)) { + // this is a swapchain-pass + res.swapchain.sample_count = _sg_def(res.swapchain.sample_count, _sg.desc.environment.defaults.sample_count); + res.swapchain.color_format = _sg_def(res.swapchain.color_format, _sg.desc.environment.defaults.color_format); + res.swapchain.depth_format = _sg_def(res.swapchain.depth_format, _sg.desc.environment.defaults.depth_format); + } + res.action = _sg_pass_action_defaults(&res.action); + } + return res; +} + +_SOKOL_PRIVATE void _sg_discard_all_resources(void) { + /* this is a bit dumb since it loops over all pool slots to + find the occupied slots, on the other hand it is only ever + executed at shutdown + NOTE: ONLY EXECUTE THIS AT SHUTDOWN + ...because the free queues will not be reset + and the resource slots not be cleared! + */ + for (int i = 1; i < _sg.pools.buffer_pool.size; i++) { + sg_resource_state state = _sg.pools.buffers[i].slot.state; + if ((state == SG_RESOURCESTATE_VALID) || (state == SG_RESOURCESTATE_FAILED)) { + _sg_discard_buffer(&_sg.pools.buffers[i]); + } + } + for (int i = 1; i < _sg.pools.image_pool.size; i++) { + sg_resource_state state = _sg.pools.images[i].slot.state; + if ((state == SG_RESOURCESTATE_VALID) || (state == SG_RESOURCESTATE_FAILED)) { + _sg_discard_image(&_sg.pools.images[i]); + } + } + for (int i = 1; i < _sg.pools.sampler_pool.size; i++) { + sg_resource_state state = _sg.pools.samplers[i].slot.state; + if ((state == SG_RESOURCESTATE_VALID) || (state == SG_RESOURCESTATE_FAILED)) { + _sg_discard_sampler(&_sg.pools.samplers[i]); + } + } + for (int i = 1; i < _sg.pools.shader_pool.size; i++) { + sg_resource_state state = _sg.pools.shaders[i].slot.state; + if ((state == SG_RESOURCESTATE_VALID) || (state == SG_RESOURCESTATE_FAILED)) { + _sg_discard_shader(&_sg.pools.shaders[i]); + } + } + for (int i = 1; i < _sg.pools.pipeline_pool.size; i++) { + sg_resource_state state = _sg.pools.pipelines[i].slot.state; + if ((state == SG_RESOURCESTATE_VALID) || (state == SG_RESOURCESTATE_FAILED)) { + _sg_discard_pipeline(&_sg.pools.pipelines[i]); + } + } + for (int i = 1; i < _sg.pools.view_pool.size; i++) { + sg_resource_state state = _sg.pools.views[i].slot.state; + if ((state == SG_RESOURCESTATE_VALID) || (state == SG_RESOURCESTATE_FAILED)) { + _sg_discard_view(&_sg.pools.views[i]); + } + } +} + +_SOKOL_PRIVATE void _sg_override_portable_limits(void) { + if (_sg.desc.enforce_portable_limits) { + _sg.limits.max_color_attachments = SG_MAX_PORTABLE_COLOR_ATTACHMENTS; + _sg.limits.max_texture_bindings_per_stage = SG_MAX_PORTABLE_TEXTURE_BINDINGS_PER_STAGE; + if (_sg.features.compute) { + _sg.limits.max_storage_buffer_bindings_per_stage = SG_MAX_PORTABLE_STORAGEBUFFER_BINDINGS_PER_STAGE; + _sg.limits.max_storage_image_bindings_per_stage = SG_MAX_PORTABLE_STORAGEIMAGE_BINDINGS_PER_STAGE; + } + } +} + +// ██████ ██ ██ ██████ ██ ██ ██████ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ██████ ██ ██ ██████ ██ ██ ██ +// ██ ██ ██ ██ ██ ██ ██ ██ +// ██ ██████ ██████ ███████ ██ ██████ +// +// >>public +SOKOL_API_IMPL void sg_setup(const sg_desc* desc) { + SOKOL_ASSERT(!_sg.valid); + SOKOL_ASSERT(desc); + SOKOL_ASSERT((desc->_start_canary == 0) && (desc->_end_canary == 0)); + SOKOL_ASSERT((desc->allocator.alloc_fn && desc->allocator.free_fn) || (!desc->allocator.alloc_fn && !desc->allocator.free_fn)); + _SG_CLEAR_ARC_STRUCT(_sg_state_t, _sg); + _sg.desc = _sg_desc_defaults(desc); + _sg_setup_pools(&_sg.pools, &_sg.desc); + _sg_setup_commit_listeners(&_sg.desc); + _sg.frame_index = 1; + _sg.stats_enabled = true; + _sg_setup_backend(&_sg.desc); + _sg_override_portable_limits(); + _sg.valid = true; +} + +SOKOL_API_IMPL void sg_shutdown(void) { + SOKOL_ASSERT(_sg.valid); + _sg_discard_all_resources(); + _sg_discard_backend(); + _sg_discard_commit_listeners(); + _sg_discard_pools(&_sg.pools); + _SG_CLEAR_ARC_STRUCT(_sg_state_t, _sg); +} + +SOKOL_API_IMPL bool sg_isvalid(void) { + return _sg.valid; +} + +SOKOL_API_IMPL sg_desc sg_query_desc(void) { + SOKOL_ASSERT(_sg.valid); + return _sg.desc; +} + +SOKOL_API_IMPL sg_backend sg_query_backend(void) { + SOKOL_ASSERT(_sg.valid); + return _sg.backend; +} + +SOKOL_API_IMPL sg_features sg_query_features(void) { + SOKOL_ASSERT(_sg.valid); + return _sg.features; +} + +SOKOL_API_IMPL sg_limits sg_query_limits(void) { + SOKOL_ASSERT(_sg.valid); + return _sg.limits; +} + +SOKOL_API_IMPL sg_pixelformat_info sg_query_pixelformat(sg_pixel_format fmt) { + SOKOL_ASSERT(_sg.valid); + int fmt_index = (int) fmt; + SOKOL_ASSERT((fmt_index > SG_PIXELFORMAT_NONE) && (fmt_index < _SG_PIXELFORMAT_NUM)); + const _sg_pixelformat_info_t* src = &_sg.formats[fmt_index]; + _SG_STRUCT(sg_pixelformat_info, res); + res.sample = src->sample; + res.filter = src->filter; + res.render = src->render; + res.blend = src->blend; + res.msaa = src->msaa; + res.depth = src->depth; + res.compressed = _sg_is_compressed_pixel_format(fmt); + res.read = src->read; + res.write = src->write; + if (!res.compressed) { + res.bytes_per_pixel = _sg_pixelformat_bytesize(fmt); + } + return res; +} + +SOKOL_API_IMPL int sg_query_row_pitch(sg_pixel_format fmt, int width, int row_align_bytes) { + SOKOL_ASSERT(_sg.valid); + SOKOL_ASSERT(width > 0); + SOKOL_ASSERT((row_align_bytes > 0) && _sg_ispow2(row_align_bytes)); + SOKOL_ASSERT(((int)fmt > SG_PIXELFORMAT_NONE) && ((int)fmt < _SG_PIXELFORMAT_NUM)); + return _sg_row_pitch(fmt, width, row_align_bytes); +} + +SOKOL_API_IMPL int sg_query_surface_pitch(sg_pixel_format fmt, int width, int height, int row_align_bytes) { + SOKOL_ASSERT(_sg.valid); + SOKOL_ASSERT((width > 0) && (height > 0)); + SOKOL_ASSERT((row_align_bytes > 0) && _sg_ispow2(row_align_bytes)); + SOKOL_ASSERT(((int)fmt > SG_PIXELFORMAT_NONE) && ((int)fmt < _SG_PIXELFORMAT_NUM)); + return _sg_surface_pitch(fmt, width, height, row_align_bytes); +} + +SOKOL_API_IMPL sg_stats sg_query_stats(void) { + SOKOL_ASSERT(_sg.valid); + _sg_update_alive_free_resource_stats(&_sg.stats.total.buffers, &_sg.pools.buffer_pool); + _sg_update_alive_free_resource_stats(&_sg.stats.total.images, &_sg.pools.image_pool); + _sg_update_alive_free_resource_stats(&_sg.stats.total.views, &_sg.pools.view_pool); + _sg_update_alive_free_resource_stats(&_sg.stats.total.samplers, &_sg.pools.sampler_pool); + _sg_update_alive_free_resource_stats(&_sg.stats.total.shaders, &_sg.pools.shader_pool); + _sg_update_alive_free_resource_stats(&_sg.stats.total.pipelines, &_sg.pools.pipeline_pool); + return _sg.stats; +} + +SOKOL_API_IMPL sg_trace_hooks sg_install_trace_hooks(const sg_trace_hooks* trace_hooks) { + SOKOL_ASSERT(_sg.valid); + SOKOL_ASSERT(trace_hooks); + _SOKOL_UNUSED(trace_hooks); + #if defined(SOKOL_TRACE_HOOKS) + sg_trace_hooks old_hooks = _sg.hooks; + _sg.hooks = *trace_hooks; + #else + static sg_trace_hooks old_hooks; + _SG_WARN(TRACE_HOOKS_NOT_ENABLED); + #endif + return old_hooks; +} + +SOKOL_API_IMPL sg_buffer sg_alloc_buffer(void) { + SOKOL_ASSERT(_sg.valid); + sg_buffer res = _sg_alloc_buffer(); + _SG_TRACE_ARGS(alloc_buffer, res); + return res; +} + +SOKOL_API_IMPL sg_image sg_alloc_image(void) { + SOKOL_ASSERT(_sg.valid); + sg_image res = _sg_alloc_image(); + _SG_TRACE_ARGS(alloc_image, res); + return res; +} + +SOKOL_API_IMPL sg_sampler sg_alloc_sampler(void) { + SOKOL_ASSERT(_sg.valid); + sg_sampler res = _sg_alloc_sampler(); + _SG_TRACE_ARGS(alloc_sampler, res); + return res; +} + +SOKOL_API_IMPL sg_shader sg_alloc_shader(void) { + SOKOL_ASSERT(_sg.valid); + sg_shader res = _sg_alloc_shader(); + _SG_TRACE_ARGS(alloc_shader, res); + return res; +} + +SOKOL_API_IMPL sg_pipeline sg_alloc_pipeline(void) { + SOKOL_ASSERT(_sg.valid); + sg_pipeline res = _sg_alloc_pipeline(); + _SG_TRACE_ARGS(alloc_pipeline, res); + return res; +} + +SOKOL_API_IMPL sg_view sg_alloc_view(void) { + SOKOL_ASSERT(_sg.valid); + sg_view res = _sg_alloc_view(); + _SG_TRACE_ARGS(alloc_view, res); + return res; +} + +SOKOL_API_IMPL void sg_dealloc_buffer(sg_buffer buf_id) { + SOKOL_ASSERT(_sg.valid); + _sg_buffer_t* buf = _sg_lookup_buffer(buf_id.id); + if (buf) { + if (buf->slot.state == SG_RESOURCESTATE_ALLOC) { + _sg_dealloc_buffer(buf); + } else { + _SG_ERROR(DEALLOC_BUFFER_INVALID_STATE); + } + } + _SG_TRACE_ARGS(dealloc_buffer, buf_id); +} + +SOKOL_API_IMPL void sg_dealloc_image(sg_image img_id) { + SOKOL_ASSERT(_sg.valid); + _sg_image_t* img = _sg_lookup_image(img_id.id); + if (img) { + if (img->slot.state == SG_RESOURCESTATE_ALLOC) { + _sg_dealloc_image(img); + } else { + _SG_ERROR(DEALLOC_IMAGE_INVALID_STATE); + } + } + _SG_TRACE_ARGS(dealloc_image, img_id); +} + +SOKOL_API_IMPL void sg_dealloc_sampler(sg_sampler smp_id) { + SOKOL_ASSERT(_sg.valid); + _sg_sampler_t* smp = _sg_lookup_sampler(smp_id.id); + if (smp) { + if (smp->slot.state == SG_RESOURCESTATE_ALLOC) { + _sg_dealloc_sampler(smp); + } else { + _SG_ERROR(DEALLOC_SAMPLER_INVALID_STATE); + } + } + _SG_TRACE_ARGS(dealloc_sampler, smp_id); +} + +SOKOL_API_IMPL void sg_dealloc_shader(sg_shader shd_id) { + SOKOL_ASSERT(_sg.valid); + _sg_shader_t* shd = _sg_lookup_shader(shd_id.id); + if (shd) { + if (shd->slot.state == SG_RESOURCESTATE_ALLOC) { + _sg_dealloc_shader(shd); + } else { + _SG_ERROR(DEALLOC_SHADER_INVALID_STATE); + } + } + _SG_TRACE_ARGS(dealloc_shader, shd_id); +} + +SOKOL_API_IMPL void sg_dealloc_pipeline(sg_pipeline pip_id) { + SOKOL_ASSERT(_sg.valid); + _sg_pipeline_t* pip = _sg_lookup_pipeline(pip_id.id); + if (pip) { + if (pip->slot.state == SG_RESOURCESTATE_ALLOC) { + _sg_dealloc_pipeline(pip); + } else { + _SG_ERROR(DEALLOC_PIPELINE_INVALID_STATE); + } + } + _SG_TRACE_ARGS(dealloc_pipeline, pip_id); +} + +SOKOL_API_IMPL void sg_dealloc_view(sg_view view_id) { + SOKOL_ASSERT(_sg.valid); + _sg_view_t* view = _sg_lookup_view(view_id.id); + if (view) { + if (view->slot.state == SG_RESOURCESTATE_ALLOC) { + _sg_dealloc_view(view); + } else { + _SG_ERROR(DEALLOC_VIEW_INVALID_STATE); + } + } + _SG_TRACE_ARGS(dealloc_view, view_id); +} + +SOKOL_API_IMPL void sg_init_buffer(sg_buffer buf_id, const sg_buffer_desc* desc) { + SOKOL_ASSERT(_sg.valid); + sg_buffer_desc desc_def = _sg_buffer_desc_defaults(desc); + _sg_buffer_t* buf = _sg_lookup_buffer(buf_id.id); + if (buf) { + if (buf->slot.state == SG_RESOURCESTATE_ALLOC) { + _sg_init_buffer(buf, &desc_def); + SOKOL_ASSERT((buf->slot.state == SG_RESOURCESTATE_VALID) || (buf->slot.state == SG_RESOURCESTATE_FAILED)); + } else { + _SG_ERROR(INIT_BUFFER_INVALID_STATE); + } + } + _SG_TRACE_ARGS(init_buffer, buf_id, &desc_def); +} + +SOKOL_API_IMPL void sg_init_image(sg_image img_id, const sg_image_desc* desc) { + SOKOL_ASSERT(_sg.valid); + sg_image_desc desc_def = _sg_image_desc_defaults(desc); + _sg_image_t* img = _sg_lookup_image(img_id.id); + if (img) { + if (img->slot.state == SG_RESOURCESTATE_ALLOC) { + _sg_init_image(img, &desc_def); + SOKOL_ASSERT((img->slot.state == SG_RESOURCESTATE_VALID) || (img->slot.state == SG_RESOURCESTATE_FAILED)); + } else { + _SG_ERROR(INIT_IMAGE_INVALID_STATE); + } + } + _SG_TRACE_ARGS(init_image, img_id, &desc_def); +} + +SOKOL_API_IMPL void sg_init_sampler(sg_sampler smp_id, const sg_sampler_desc* desc) { + SOKOL_ASSERT(_sg.valid); + sg_sampler_desc desc_def = _sg_sampler_desc_defaults(desc); + _sg_sampler_t* smp = _sg_lookup_sampler(smp_id.id); + if (smp) { + if (smp->slot.state == SG_RESOURCESTATE_ALLOC) { + _sg_init_sampler(smp, &desc_def); + SOKOL_ASSERT((smp->slot.state == SG_RESOURCESTATE_VALID) || (smp->slot.state == SG_RESOURCESTATE_FAILED)); + } else { + _SG_ERROR(INIT_SAMPLER_INVALID_STATE); + } + } + _SG_TRACE_ARGS(init_sampler, smp_id, &desc_def); +} + +SOKOL_API_IMPL void sg_init_shader(sg_shader shd_id, const sg_shader_desc* desc) { + SOKOL_ASSERT(_sg.valid); + sg_shader_desc desc_def = _sg_shader_desc_defaults(desc); + _sg_shader_t* shd = _sg_lookup_shader(shd_id.id); + if (shd) { + if (shd->slot.state == SG_RESOURCESTATE_ALLOC) { + _sg_init_shader(shd, &desc_def); + SOKOL_ASSERT((shd->slot.state == SG_RESOURCESTATE_VALID) || (shd->slot.state == SG_RESOURCESTATE_FAILED)); + } else { + _SG_ERROR(INIT_SHADER_INVALID_STATE); + } + } + _SG_TRACE_ARGS(init_shader, shd_id, &desc_def); +} + +SOKOL_API_IMPL void sg_init_pipeline(sg_pipeline pip_id, const sg_pipeline_desc* desc) { + SOKOL_ASSERT(_sg.valid); + sg_pipeline_desc desc_def = _sg_pipeline_desc_defaults(desc); + _sg_pipeline_t* pip = _sg_lookup_pipeline(pip_id.id); + if (pip) { + if (pip->slot.state == SG_RESOURCESTATE_ALLOC) { + _sg_init_pipeline(pip, &desc_def); + SOKOL_ASSERT((pip->slot.state == SG_RESOURCESTATE_VALID) || (pip->slot.state == SG_RESOURCESTATE_FAILED)); + } else { + _SG_ERROR(INIT_PIPELINE_INVALID_STATE); + } + } + _SG_TRACE_ARGS(init_pipeline, pip_id, &desc_def); +} + +SOKOL_API_IMPL void sg_init_view(sg_view view_id, const sg_view_desc* desc) { + SOKOL_ASSERT(_sg.valid); + sg_view_desc desc_def = _sg_view_desc_defaults(desc); + _sg_view_t* view = _sg_lookup_view(view_id.id); + if (view) { + if (view->slot.state == SG_RESOURCESTATE_ALLOC) { + _sg_init_view(view, &desc_def); + SOKOL_ASSERT((view->slot.state == SG_RESOURCESTATE_VALID) + || (view->slot.state == SG_RESOURCESTATE_FAILED) + || (view->slot.state == SG_RESOURCESTATE_ALLOC)); + } else { + _SG_ERROR(INIT_VIEW_INVALID_STATE); + } + } + _SG_TRACE_ARGS(init_view, view_id, &desc_def); +} + +SOKOL_API_IMPL void sg_uninit_buffer(sg_buffer buf_id) { + SOKOL_ASSERT(_sg.valid); + _sg_buffer_t* buf = _sg_lookup_buffer(buf_id.id); + if (buf) { + if ((buf->slot.state == SG_RESOURCESTATE_VALID) || (buf->slot.state == SG_RESOURCESTATE_FAILED)) { + _sg_uninit_buffer(buf); + SOKOL_ASSERT(buf->slot.state == SG_RESOURCESTATE_ALLOC); + } else if (buf->slot.state != SG_RESOURCESTATE_ALLOC) { + _SG_ERROR(UNINIT_BUFFER_INVALID_STATE); + } + } + _SG_TRACE_ARGS(uninit_buffer, buf_id); +} + +SOKOL_API_IMPL void sg_uninit_image(sg_image img_id) { + SOKOL_ASSERT(_sg.valid); + _sg_image_t* img = _sg_lookup_image(img_id.id); + if (img) { + if ((img->slot.state == SG_RESOURCESTATE_VALID) || (img->slot.state == SG_RESOURCESTATE_FAILED)) { + _sg_uninit_image(img); + SOKOL_ASSERT(img->slot.state == SG_RESOURCESTATE_ALLOC); + } else if (img->slot.state != SG_RESOURCESTATE_ALLOC) { + _SG_ERROR(UNINIT_IMAGE_INVALID_STATE); + } + } + _SG_TRACE_ARGS(uninit_image, img_id); +} + +SOKOL_API_IMPL void sg_uninit_sampler(sg_sampler smp_id) { + SOKOL_ASSERT(_sg.valid); + _sg_sampler_t* smp = _sg_lookup_sampler(smp_id.id); + if (smp) { + if ((smp->slot.state == SG_RESOURCESTATE_VALID) || (smp->slot.state == SG_RESOURCESTATE_FAILED)) { + _sg_uninit_sampler(smp); + SOKOL_ASSERT(smp->slot.state == SG_RESOURCESTATE_ALLOC); + } else if (smp->slot.state != SG_RESOURCESTATE_ALLOC) { + _SG_ERROR(UNINIT_SAMPLER_INVALID_STATE); + } + } + _SG_TRACE_ARGS(uninit_sampler, smp_id); +} + +SOKOL_API_IMPL void sg_uninit_shader(sg_shader shd_id) { + SOKOL_ASSERT(_sg.valid); + _sg_shader_t* shd = _sg_lookup_shader(shd_id.id); + if (shd) { + if ((shd->slot.state == SG_RESOURCESTATE_VALID) || (shd->slot.state == SG_RESOURCESTATE_FAILED)) { + _sg_uninit_shader(shd); + SOKOL_ASSERT(shd->slot.state == SG_RESOURCESTATE_ALLOC); + } else if (shd->slot.state != SG_RESOURCESTATE_ALLOC) { + _SG_ERROR(UNINIT_SHADER_INVALID_STATE); + } + } + _SG_TRACE_ARGS(uninit_shader, shd_id); +} + +SOKOL_API_IMPL void sg_uninit_pipeline(sg_pipeline pip_id) { + SOKOL_ASSERT(_sg.valid); + _sg_pipeline_t* pip = _sg_lookup_pipeline(pip_id.id); + if (pip) { + if ((pip->slot.state == SG_RESOURCESTATE_VALID) || (pip->slot.state == SG_RESOURCESTATE_FAILED)) { + _sg_uninit_pipeline(pip); + SOKOL_ASSERT(pip->slot.state == SG_RESOURCESTATE_ALLOC); + } else if (pip->slot.state != SG_RESOURCESTATE_ALLOC) { + _SG_ERROR(UNINIT_PIPELINE_INVALID_STATE); + } + } + _SG_TRACE_ARGS(uninit_pipeline, pip_id); +} + +SOKOL_API_IMPL void sg_uninit_view(sg_view view_id) { + SOKOL_ASSERT(_sg.valid); + _sg_view_t* view = _sg_lookup_view(view_id.id); + if (view) { + if ((view->slot.state == SG_RESOURCESTATE_VALID) || (view->slot.state == SG_RESOURCESTATE_FAILED)) { + _sg_uninit_view(view); + SOKOL_ASSERT(view->slot.state == SG_RESOURCESTATE_ALLOC); + } else if (view->slot.state != SG_RESOURCESTATE_ALLOC) { + _SG_ERROR(UNINIT_VIEW_INVALID_STATE); + } + } + _SG_TRACE_ARGS(uninit_view, view_id); +} + +SOKOL_API_IMPL void sg_fail_buffer(sg_buffer buf_id) { + SOKOL_ASSERT(_sg.valid); + _sg_buffer_t* buf = _sg_lookup_buffer(buf_id.id); + if (buf) { + if (buf->slot.state == SG_RESOURCESTATE_ALLOC) { + buf->slot.state = SG_RESOURCESTATE_FAILED; + } else { + _SG_ERROR(FAIL_BUFFER_INVALID_STATE); + } + } + _SG_TRACE_ARGS(fail_buffer, buf_id); +} + +SOKOL_API_IMPL void sg_fail_image(sg_image img_id) { + SOKOL_ASSERT(_sg.valid); + _sg_image_t* img = _sg_lookup_image(img_id.id); + if (img) { + if (img->slot.state == SG_RESOURCESTATE_ALLOC) { + img->slot.state = SG_RESOURCESTATE_FAILED; + } else { + _SG_ERROR(FAIL_IMAGE_INVALID_STATE); + } + } + _SG_TRACE_ARGS(fail_image, img_id); +} + +SOKOL_API_IMPL void sg_fail_sampler(sg_sampler smp_id) { + SOKOL_ASSERT(_sg.valid); + _sg_sampler_t* smp = _sg_lookup_sampler(smp_id.id); + if (smp) { + if (smp->slot.state == SG_RESOURCESTATE_ALLOC) { + smp->slot.state = SG_RESOURCESTATE_FAILED; + } else { + _SG_ERROR(FAIL_SAMPLER_INVALID_STATE); + } + } + _SG_TRACE_ARGS(fail_sampler, smp_id); +} + +SOKOL_API_IMPL void sg_fail_shader(sg_shader shd_id) { + SOKOL_ASSERT(_sg.valid); + _sg_shader_t* shd = _sg_lookup_shader(shd_id.id); + if (shd) { + if (shd->slot.state == SG_RESOURCESTATE_ALLOC) { + shd->slot.state = SG_RESOURCESTATE_FAILED; + } else { + _SG_ERROR(FAIL_SHADER_INVALID_STATE); + } + } + _SG_TRACE_ARGS(fail_shader, shd_id); +} + +SOKOL_API_IMPL void sg_fail_pipeline(sg_pipeline pip_id) { + SOKOL_ASSERT(_sg.valid); + _sg_pipeline_t* pip = _sg_lookup_pipeline(pip_id.id); + if (pip) { + if (pip->slot.state == SG_RESOURCESTATE_ALLOC) { + pip->slot.state = SG_RESOURCESTATE_FAILED; + } else { + _SG_ERROR(FAIL_PIPELINE_INVALID_STATE); + } + } + _SG_TRACE_ARGS(fail_pipeline, pip_id); +} + +SOKOL_API_IMPL void sg_fail_view(sg_view view_id) { + SOKOL_ASSERT(_sg.valid); + _sg_view_t* view = _sg_lookup_view(view_id.id); + if (view) { + if (view->slot.state == SG_RESOURCESTATE_ALLOC) { + view->slot.state = SG_RESOURCESTATE_FAILED; + } else { + _SG_ERROR(FAIL_VIEW_INVALID_STATE); + } + } + _SG_TRACE_ARGS(fail_view, view_id); +} + +SOKOL_API_IMPL sg_resource_state sg_query_buffer_state(sg_buffer buf_id) { + SOKOL_ASSERT(_sg.valid); + _sg_buffer_t* buf = _sg_lookup_buffer(buf_id.id); + sg_resource_state res = buf ? buf->slot.state : SG_RESOURCESTATE_INVALID; + return res; +} + +SOKOL_API_IMPL sg_resource_state sg_query_image_state(sg_image img_id) { + SOKOL_ASSERT(_sg.valid); + _sg_image_t* img = _sg_lookup_image(img_id.id); + sg_resource_state res = img ? img->slot.state : SG_RESOURCESTATE_INVALID; + return res; +} + +SOKOL_API_IMPL sg_resource_state sg_query_sampler_state(sg_sampler smp_id) { + SOKOL_ASSERT(_sg.valid); + _sg_sampler_t* smp = _sg_lookup_sampler(smp_id.id); + sg_resource_state res = smp ? smp->slot.state : SG_RESOURCESTATE_INVALID; + return res; +} + +SOKOL_API_IMPL sg_resource_state sg_query_shader_state(sg_shader shd_id) { + SOKOL_ASSERT(_sg.valid); + _sg_shader_t* shd = _sg_lookup_shader(shd_id.id); + sg_resource_state res = shd ? shd->slot.state : SG_RESOURCESTATE_INVALID; + return res; +} + +SOKOL_API_IMPL sg_resource_state sg_query_pipeline_state(sg_pipeline pip_id) { + SOKOL_ASSERT(_sg.valid); + _sg_pipeline_t* pip = _sg_lookup_pipeline(pip_id.id); + sg_resource_state res = pip ? pip->slot.state : SG_RESOURCESTATE_INVALID; + return res; +} + +SOKOL_API_IMPL sg_resource_state sg_query_view_state(sg_view view_id) { + SOKOL_ASSERT(_sg.valid); + _sg_view_t* view = _sg_lookup_view(view_id.id); + sg_resource_state res = view ? view->slot.state : SG_RESOURCESTATE_INVALID; + return res; +} + +SOKOL_API_IMPL sg_buffer sg_make_buffer(const sg_buffer_desc* desc) { + SOKOL_ASSERT(_sg.valid); + SOKOL_ASSERT(desc); + sg_buffer_desc desc_def = _sg_buffer_desc_defaults(desc); + sg_buffer buf_id = _sg_alloc_buffer(); + if (buf_id.id != SG_INVALID_ID) { + _sg_buffer_t* buf = _sg_buffer_at(buf_id.id); + SOKOL_ASSERT(buf && (buf->slot.state == SG_RESOURCESTATE_ALLOC)); + _sg_init_buffer(buf, &desc_def); + SOKOL_ASSERT((buf->slot.state == SG_RESOURCESTATE_VALID) || (buf->slot.state == SG_RESOURCESTATE_FAILED)); + } + _SG_TRACE_ARGS(make_buffer, &desc_def, buf_id); + return buf_id; +} + +SOKOL_API_IMPL sg_image sg_make_image(const sg_image_desc* desc) { + SOKOL_ASSERT(_sg.valid); + SOKOL_ASSERT(desc); + sg_image_desc desc_def = _sg_image_desc_defaults(desc); + sg_image img_id = _sg_alloc_image(); + if (img_id.id != SG_INVALID_ID) { + _sg_image_t* img = _sg_image_at(img_id.id); + SOKOL_ASSERT(img && (img->slot.state == SG_RESOURCESTATE_ALLOC)); + _sg_init_image(img, &desc_def); + SOKOL_ASSERT((img->slot.state == SG_RESOURCESTATE_VALID) || (img->slot.state == SG_RESOURCESTATE_FAILED)); + } + _SG_TRACE_ARGS(make_image, &desc_def, img_id); + return img_id; +} + +SOKOL_API_IMPL sg_sampler sg_make_sampler(const sg_sampler_desc* desc) { + SOKOL_ASSERT(_sg.valid); + SOKOL_ASSERT(desc); + sg_sampler_desc desc_def = _sg_sampler_desc_defaults(desc); + sg_sampler smp_id = _sg_alloc_sampler(); + if (smp_id.id != SG_INVALID_ID) { + _sg_sampler_t* smp = _sg_sampler_at(smp_id.id); + SOKOL_ASSERT(smp && (smp->slot.state == SG_RESOURCESTATE_ALLOC)); + _sg_init_sampler(smp, &desc_def); + SOKOL_ASSERT((smp->slot.state == SG_RESOURCESTATE_VALID) || (smp->slot.state == SG_RESOURCESTATE_FAILED)); + } + _SG_TRACE_ARGS(make_sampler, &desc_def, smp_id); + return smp_id; +} + +SOKOL_API_IMPL sg_shader sg_make_shader(const sg_shader_desc* desc) { + SOKOL_ASSERT(_sg.valid); + SOKOL_ASSERT(desc); + sg_shader_desc desc_def = _sg_shader_desc_defaults(desc); + sg_shader shd_id = _sg_alloc_shader(); + if (shd_id.id != SG_INVALID_ID) { + _sg_shader_t* shd = _sg_shader_at(shd_id.id); + SOKOL_ASSERT(shd && (shd->slot.state == SG_RESOURCESTATE_ALLOC)); + _sg_init_shader(shd, &desc_def); + SOKOL_ASSERT((shd->slot.state == SG_RESOURCESTATE_VALID) || (shd->slot.state == SG_RESOURCESTATE_FAILED)); + } + _SG_TRACE_ARGS(make_shader, &desc_def, shd_id); + return shd_id; +} + +SOKOL_API_IMPL sg_pipeline sg_make_pipeline(const sg_pipeline_desc* desc) { + SOKOL_ASSERT(_sg.valid); + SOKOL_ASSERT(desc); + sg_pipeline_desc desc_def = _sg_pipeline_desc_defaults(desc); + sg_pipeline pip_id = _sg_alloc_pipeline(); + if (pip_id.id != SG_INVALID_ID) { + _sg_pipeline_t* pip = _sg_pipeline_at(pip_id.id); + SOKOL_ASSERT(pip && (pip->slot.state == SG_RESOURCESTATE_ALLOC)); + _sg_init_pipeline(pip, &desc_def); + SOKOL_ASSERT((pip->slot.state == SG_RESOURCESTATE_VALID) || (pip->slot.state == SG_RESOURCESTATE_FAILED)); + } + _SG_TRACE_ARGS(make_pipeline, &desc_def, pip_id); + return pip_id; +} + +SOKOL_API_IMPL sg_view sg_make_view(const sg_view_desc* desc) { + SOKOL_ASSERT(_sg.valid); + SOKOL_ASSERT(desc); + sg_view_desc desc_def = _sg_view_desc_defaults(desc); + sg_view view_id = _sg_alloc_view(); + if (view_id.id != SG_INVALID_ID) { + _sg_view_t* view = _sg_view_at(view_id.id); + SOKOL_ASSERT(view && (view->slot.state == SG_RESOURCESTATE_ALLOC)); + _sg_init_view(view, &desc_def); + SOKOL_ASSERT((view->slot.state == SG_RESOURCESTATE_VALID) || (view->slot.state == SG_RESOURCESTATE_FAILED)); + } + _SG_TRACE_ARGS(make_view, &desc_def, view_id); + return view_id; +} + +SOKOL_API_IMPL void sg_destroy_buffer(sg_buffer buf_id) { + SOKOL_ASSERT(_sg.valid); + _SG_TRACE_ARGS(destroy_buffer, buf_id); + _sg_buffer_t* buf = _sg_lookup_buffer(buf_id.id); + if (buf) { + if ((buf->slot.state == SG_RESOURCESTATE_VALID) || (buf->slot.state == SG_RESOURCESTATE_FAILED)) { + _sg_uninit_buffer(buf); + SOKOL_ASSERT(buf->slot.state == SG_RESOURCESTATE_ALLOC); + } + if (buf->slot.state == SG_RESOURCESTATE_ALLOC) { + _sg_dealloc_buffer(buf); + SOKOL_ASSERT(buf->slot.state == SG_RESOURCESTATE_INITIAL); + } + } +} + +SOKOL_API_IMPL void sg_destroy_image(sg_image img_id) { + SOKOL_ASSERT(_sg.valid); + _SG_TRACE_ARGS(destroy_image, img_id); + _sg_image_t* img = _sg_lookup_image(img_id.id); + if (img) { + if ((img->slot.state == SG_RESOURCESTATE_VALID) || (img->slot.state == SG_RESOURCESTATE_FAILED)) { + _sg_uninit_image(img); + SOKOL_ASSERT(img->slot.state == SG_RESOURCESTATE_ALLOC); + } + if (img->slot.state == SG_RESOURCESTATE_ALLOC) { + _sg_dealloc_image(img); + SOKOL_ASSERT(img->slot.state == SG_RESOURCESTATE_INITIAL); + } + } +} + +SOKOL_API_IMPL void sg_destroy_sampler(sg_sampler smp_id) { + SOKOL_ASSERT(_sg.valid); + _SG_TRACE_ARGS(destroy_sampler, smp_id); + _sg_sampler_t* smp = _sg_lookup_sampler(smp_id.id); + if (smp) { + if ((smp->slot.state == SG_RESOURCESTATE_VALID) || (smp->slot.state == SG_RESOURCESTATE_FAILED)) { + _sg_uninit_sampler(smp); + SOKOL_ASSERT(smp->slot.state == SG_RESOURCESTATE_ALLOC); + } + if (smp->slot.state == SG_RESOURCESTATE_ALLOC) { + _sg_dealloc_sampler(smp); + SOKOL_ASSERT(smp->slot.state == SG_RESOURCESTATE_INITIAL); + } + } +} + +SOKOL_API_IMPL void sg_destroy_shader(sg_shader shd_id) { + SOKOL_ASSERT(_sg.valid); + _SG_TRACE_ARGS(destroy_shader, shd_id); + _sg_shader_t* shd = _sg_lookup_shader(shd_id.id); + if (shd) { + if ((shd->slot.state == SG_RESOURCESTATE_VALID) || (shd->slot.state == SG_RESOURCESTATE_FAILED)) { + _sg_uninit_shader(shd); + SOKOL_ASSERT(shd->slot.state == SG_RESOURCESTATE_ALLOC); + } + if (shd->slot.state == SG_RESOURCESTATE_ALLOC) { + _sg_dealloc_shader(shd); + SOKOL_ASSERT(shd->slot.state == SG_RESOURCESTATE_INITIAL); + } + } +} + +SOKOL_API_IMPL void sg_destroy_pipeline(sg_pipeline pip_id) { + SOKOL_ASSERT(_sg.valid); + _SG_TRACE_ARGS(destroy_pipeline, pip_id); + _sg_pipeline_t* pip = _sg_lookup_pipeline(pip_id.id); + if (pip) { + if ((pip->slot.state == SG_RESOURCESTATE_VALID) || (pip->slot.state == SG_RESOURCESTATE_FAILED)) { + _sg_uninit_pipeline(pip); + SOKOL_ASSERT(pip->slot.state == SG_RESOURCESTATE_ALLOC); + } + if (pip->slot.state == SG_RESOURCESTATE_ALLOC) { + _sg_dealloc_pipeline(pip); + SOKOL_ASSERT(pip->slot.state == SG_RESOURCESTATE_INITIAL); + } + } +} + +SOKOL_API_IMPL void sg_destroy_view(sg_view view_id) { + SOKOL_ASSERT(_sg.valid); + _SG_TRACE_ARGS(destroy_view, view_id); + _sg_view_t* view = _sg_lookup_view(view_id.id); + if (view) { + if ((view->slot.state == SG_RESOURCESTATE_VALID) || (view->slot.state == SG_RESOURCESTATE_FAILED)) { + _sg_uninit_view(view); + SOKOL_ASSERT(view->slot.state == SG_RESOURCESTATE_ALLOC); + } + if (view->slot.state == SG_RESOURCESTATE_ALLOC) { + _sg_dealloc_view(view); + SOKOL_ASSERT(view->slot.state == SG_RESOURCESTATE_INITIAL); + } + } +} + +SOKOL_API_IMPL void sg_begin_pass(const sg_pass* pass) { + SOKOL_ASSERT(_sg.valid); + SOKOL_ASSERT(!_sg.cur_pass.valid); + SOKOL_ASSERT(!_sg.cur_pass.in_pass); + SOKOL_ASSERT(_sg_attachments_empty(&_sg.cur_pass.atts)); + SOKOL_ASSERT(pass); + SOKOL_ASSERT((pass->_start_canary == 0) && (pass->_end_canary == 0)); + _sg.cur_pass.in_pass = true; + const sg_pass pass_def = _sg_pass_defaults(pass); + _SG_TRACE_ARGS(begin_pass, &pass_def); + if (!_sg_validate_pass_attachment_limits(&pass_def)) { + return; + } + if (!_sg_validate_begin_pass(&pass_def)) { + return; + } + const _sg_attachments_ptrs_t atts_ptrs = _sg_attachments_ptrs(&pass_def.attachments); + if (!atts_ptrs.empty) { + if (!_sg_attachments_alive(&atts_ptrs)) { + _SG_ERROR(BEGINPASS_ATTACHMENTS_ALIVE); + return; + } + _sg.cur_pass.atts = pass->attachments; + _sg.cur_pass.dim = _sg_attachments_dim(&atts_ptrs); + } else if (!pass_def.compute) { + // a swapchain pass + // NOTE: all values allowed to be zero if swapchain is invalid + _sg.cur_pass.swapchain.invalid = pass_def.swapchain.invalid; + _sg.cur_pass.swapchain.color_fmt = pass_def.swapchain.color_format; + _sg.cur_pass.swapchain.depth_fmt = pass_def.swapchain.depth_format; + _sg.cur_pass.swapchain.sample_count = pass_def.swapchain.sample_count; + _sg.cur_pass.dim.width = pass_def.swapchain.width; + _sg.cur_pass.dim.height = pass_def.swapchain.height; + } + _sg.cur_pass.action = pass_def.action; + _sg.cur_pass.valid = true; // may be overruled by backend begin-pass functions + _sg.cur_pass.is_compute = pass_def.compute; + if (_sg.cur_pass.swapchain.invalid) { + _sg.cur_pass.valid = false; + return; + } + _sg_begin_pass(&pass_def, &atts_ptrs); +} + +SOKOL_API_IMPL void sg_apply_viewport(int x, int y, int width, int height, bool origin_top_left) { + SOKOL_ASSERT(_sg.valid); + _sg_stats_inc(num_apply_viewport); + _SG_TRACE_ARGS(apply_viewport, x, y, width, height, origin_top_left); + if (!_sg.cur_pass.valid) { + return; + } + #if defined(SOKOL_DEBUG) + if (!_sg_validate_apply_viewport(x, y, width, height, origin_top_left)) { + return; + } + #endif + _sg_apply_viewport(x, y, width, height, origin_top_left); +} + +SOKOL_API_IMPL void sg_apply_viewportf(float x, float y, float width, float height, bool origin_top_left) { + sg_apply_viewport((int)x, (int)y, (int)width, (int)height, origin_top_left); +} + +SOKOL_API_IMPL void sg_apply_scissor_rect(int x, int y, int width, int height, bool origin_top_left) { + SOKOL_ASSERT(_sg.valid); + _sg_stats_inc(num_apply_scissor_rect); + _SG_TRACE_ARGS(apply_scissor_rect, x, y, width, height, origin_top_left); + if (!_sg.cur_pass.valid) { + return; + } + #if defined(SOKOL_DEBUG) + if (!_sg_validate_apply_scissor_rect(x, y, width, height, origin_top_left)) { + return; + } + #endif + _sg_apply_scissor_rect(x, y, width, height, origin_top_left); +} + +SOKOL_API_IMPL void sg_apply_scissor_rectf(float x, float y, float width, float height, bool origin_top_left) { + sg_apply_scissor_rect((int)x, (int)y, (int)width, (int)height, origin_top_left); +} + +SOKOL_API_IMPL void sg_apply_pipeline(sg_pipeline pip_id) { + SOKOL_ASSERT(_sg.valid); + _sg_stats_inc(num_apply_pipeline); + _SG_TRACE_ARGS(apply_pipeline, pip_id); + if (!_sg.cur_pass.valid) { + return; + } + if (!_sg_validate_apply_pipeline(pip_id)) { + _sg.next_draw_valid = false; + return; + } + _sg_pipeline_t* pip = _sg_lookup_pipeline(pip_id.id); + SOKOL_ASSERT(pip); + _sg.cur_pip = _sg_pipeline_ref(pip); + + _sg.next_draw_valid = (SG_RESOURCESTATE_VALID == pip->slot.state); + if (!_sg.next_draw_valid) { + return; + } + _sg.use_indexed_draw = pip->cmn.index_type != SG_INDEXTYPE_NONE; + _sg.use_instanced_draw = pip->cmn.use_instanced_draw; + + _sg_apply_pipeline(pip); + + // set the expected bindings and uniform block flags + const _sg_shader_t* shd = _sg_shader_ref_ptr(&pip->cmn.shader); + _sg.required_bindings_and_uniforms = pip->cmn.required_bindings_and_uniforms | shd->cmn.required_bindings_and_uniforms; + _sg.applied_bindings_and_uniforms = 0; +} + +SOKOL_API_IMPL void sg_apply_bindings(const sg_bindings* bindings) { + SOKOL_ASSERT(_sg.valid); + SOKOL_ASSERT(bindings); + _sg_stats_inc(num_apply_bindings); + _SG_TRACE_ARGS(apply_bindings, bindings); + if (!_sg.cur_pass.valid) { + return; + } + _sg.applied_bindings_and_uniforms |= (1 << SG_MAX_UNIFORMBLOCK_BINDSLOTS); + if (!_sg_validate_apply_bindings(bindings)) { + _sg.next_draw_valid = false; + } + SOKOL_ASSERT((bindings->_start_canary == 0) && (bindings->_end_canary==0)); + if (!_sg_pipeline_ref_alive(&_sg.cur_pip)) { + _sg.next_draw_valid = false; + } + if (!_sg.next_draw_valid) { + return; + } + + _SG_STRUCT(_sg_bindings_ptrs_t, bnd); + bnd.pip = _sg_pipeline_ref_ptr(&_sg.cur_pip); + const _sg_shader_t* shd = _sg_shader_ref_ptr(&bnd.pip->cmn.shader); + if (!_sg.cur_pass.is_compute) { + for (size_t i = 0; i < SG_MAX_VERTEXBUFFER_BINDSLOTS; i++) { + if (bnd.pip->cmn.vertex_buffer_layout_active[i]) { + SOKOL_ASSERT(bindings->vertex_buffers[i].id != SG_INVALID_ID); + bnd.vbs[i] = _sg_lookup_buffer(bindings->vertex_buffers[i].id); + bnd.vb_offsets[i] = bindings->vertex_buffer_offsets[i]; + _sg.next_draw_valid &= bnd.vbs[i] && (SG_RESOURCESTATE_VALID == bnd.vbs[i]->slot.state); + } + } + if (bindings->index_buffer.id) { + bnd.ib = _sg_lookup_buffer(bindings->index_buffer.id); + bnd.ib_offset = bindings->index_buffer_offset; + _sg.next_draw_valid &= bnd.ib && (SG_RESOURCESTATE_VALID == bnd.ib->slot.state); + } + } + + for (int i = 0; i < SG_MAX_VIEW_BINDSLOTS; i++) { + if (shd->cmn.views[i].view_type != SG_VIEWTYPE_INVALID) { + SOKOL_ASSERT(bindings->views[i].id != SG_INVALID_ID); + bnd.views[i] = _sg_lookup_view(bindings->views[i].id); + if (bnd.views[i]) { + if (bnd.views[i]->cmn.type == SG_VIEWTYPE_STORAGEBUFFER) { + _sg.next_draw_valid &= _sg_buffer_ref_valid(&bnd.views[i]->cmn.buf.ref); + } else { + _sg.next_draw_valid &= _sg_image_ref_valid(&bnd.views[i]->cmn.img.ref); + } + } else { + _sg.next_draw_valid = false; + } + } + } + + for (size_t i = 0; i < SG_MAX_SAMPLER_BINDSLOTS; i++) { + if (shd->cmn.samplers[i].stage != SG_SHADERSTAGE_NONE) { + SOKOL_ASSERT(bindings->samplers[i].id != SG_INVALID_ID); + bnd.smps[i] = _sg_lookup_sampler(bindings->samplers[i].id); + SOKOL_ASSERT(bnd.smps[i]); + } + } + + if (_sg.next_draw_valid) { + _sg.next_draw_valid &= _sg_apply_bindings(&bnd); + } +} + +SOKOL_API_IMPL void sg_apply_uniforms(int ub_slot, const sg_range* data) { + SOKOL_ASSERT(_sg.valid); + SOKOL_ASSERT((ub_slot >= 0) && (ub_slot < SG_MAX_UNIFORMBLOCK_BINDSLOTS)); + SOKOL_ASSERT(data && data->ptr && (data->size > 0)); + _sg_stats_inc(num_apply_uniforms); + _sg_stats_add(size_apply_uniforms, (uint32_t)data->size); + _SG_TRACE_ARGS(apply_uniforms, ub_slot, data); + if (!_sg.cur_pass.valid) { + return; + } + _sg.applied_bindings_and_uniforms |= 1 << ub_slot; + if (!_sg_validate_apply_uniforms(ub_slot, data)) { + _sg.next_draw_valid = false; + return; + } + if (!_sg.next_draw_valid) { + return; + } + _sg_apply_uniforms(ub_slot, data); +} + +_SOKOL_PRIVATE bool _sg_check_skip_draw(int num_elements, int num_instances) { + if (!_sg.cur_pass.valid) { + return true; + } + if (!_sg.next_draw_valid) { + return true; + } + // skip no-op draws + if ((0 == num_elements) || (0 == num_instances)) { + return true; + } + return false; +} + +SOKOL_API_IMPL void sg_draw(int base_element, int num_elements, int num_instances) { + SOKOL_ASSERT(_sg.valid); + _sg_stats_inc(num_draw); + _SG_TRACE_ARGS(draw, base_element, num_elements, num_instances); + if (_sg_check_skip_draw(num_elements, num_instances)) { + return; + } + #if defined(SOKOL_DEBUG) + if (!_sg_validate_draw(base_element, num_elements, num_instances)) { + return; + } + #endif + _sg_draw(base_element, num_elements, num_instances, 0, 0); +} + +SOKOL_API_IMPL void sg_draw_ex(int base_element, int num_elements, int num_instances, int base_vertex, int base_instance) { + SOKOL_ASSERT(_sg.valid); + _sg_stats_inc(num_draw_ex); + _SG_TRACE_ARGS(draw_ex, base_element, num_elements, num_instances, base_vertex, base_instance); + if (_sg_check_skip_draw(num_elements, num_instances)) { + return; + } + #if defined(SOKOL_DEBUG) + if (!_sg_validate_draw_ex(base_element, num_elements, num_instances, base_vertex, base_instance)) { + return; + } + #endif + _sg_draw(base_element, num_elements, num_instances, base_vertex, base_instance); +} + +SOKOL_API_IMPL void sg_dispatch(int num_groups_x, int num_groups_y, int num_groups_z) { + SOKOL_ASSERT(_sg.valid); + _sg_stats_inc(num_dispatch); + _SG_TRACE_ARGS(dispatch, num_groups_x, num_groups_y, num_groups_z); + if (!_sg.cur_pass.valid) { + return; + } + if (!_sg.next_draw_valid) { + return; + } + // skip no-op dispatches + if ((0 == num_groups_x) || (0 == num_groups_y) || (0 == num_groups_z)) { + return; + } + #if defined(SOKOL_DEBUG) + if (!_sg_validate_dispatch(num_groups_x, num_groups_y, num_groups_z)) { + return; + } + #endif + _sg_dispatch(num_groups_x, num_groups_y, num_groups_z); +} + +SOKOL_API_IMPL void sg_end_pass(void) { + SOKOL_ASSERT(_sg.valid); + SOKOL_ASSERT(_sg.cur_pass.in_pass); + _sg_stats_inc(num_passes); + _SG_TRACE_NOARGS(end_pass); + // NOTE: don't exit early if !_sg.cur_pass.valid + if (!_sg.cur_pass.swapchain.invalid) { + const _sg_attachments_ptrs_t atts_ptrs = _sg_attachments_ptrs(&_sg.cur_pass.atts); + _sg_end_pass(&atts_ptrs); + } + _sg.cur_pip = _sg_pipeline_ref(0); + _sg_clear(&_sg.cur_pass, sizeof(_sg.cur_pass)); +} + +SOKOL_API_IMPL void sg_commit(void) { + SOKOL_ASSERT(_sg.valid); + SOKOL_ASSERT(!_sg.cur_pass.valid); + SOKOL_ASSERT(!_sg.cur_pass.in_pass); + _sg_commit(); + _sg_update_stats(); + _sg_notify_commit_listeners(); + _SG_TRACE_NOARGS(commit); + _sg.frame_index++; +} + +SOKOL_API_IMPL void sg_reset_state_cache(void) { + SOKOL_ASSERT(_sg.valid); + _sg_reset_state_cache(); + _SG_TRACE_NOARGS(reset_state_cache); +} + +SOKOL_API_IMPL void sg_update_buffer(sg_buffer buf_id, const sg_range* data) { + SOKOL_ASSERT(_sg.valid); + SOKOL_ASSERT(data && data->ptr && (data->size > 0)); + _sg_stats_inc(num_update_buffer); + _sg_stats_add(size_update_buffer, (uint32_t)data->size); + _sg_buffer_t* buf = _sg_lookup_buffer(buf_id.id); + if ((data->size > 0) && buf && (buf->slot.state == SG_RESOURCESTATE_VALID)) { + if (_sg_validate_update_buffer(buf, data)) { + SOKOL_ASSERT(data->size <= (size_t)buf->cmn.size); + // only one update allowed per buffer and frame + SOKOL_ASSERT(buf->cmn.update_frame_index != _sg.frame_index); + // update and append on same buffer in same frame not allowed + SOKOL_ASSERT(buf->cmn.append_frame_index != _sg.frame_index); + _sg_update_buffer(buf, data); + buf->cmn.update_frame_index = _sg.frame_index; + } + } + _SG_TRACE_ARGS(update_buffer, buf_id, data); +} + +SOKOL_API_IMPL int sg_append_buffer(sg_buffer buf_id, const sg_range* data) { + SOKOL_ASSERT(_sg.valid); + SOKOL_ASSERT(data && data->ptr); + _sg_stats_inc(num_append_buffer); + _sg_stats_add(size_append_buffer, (uint32_t)data->size); + _sg_buffer_t* buf = _sg_lookup_buffer(buf_id.id); + int result; + if (buf) { + // rewind append cursor in a new frame + if (buf->cmn.append_frame_index != _sg.frame_index) { + buf->cmn.append_pos = 0; + buf->cmn.append_overflow = false; + } + if (((size_t)buf->cmn.append_pos + data->size) > (size_t)buf->cmn.size) { + buf->cmn.append_overflow = true; + } + const int start_pos = buf->cmn.append_pos; + // NOTE: the multiple-of-4 requirement for the buffer offset is coming + // from WebGPU, but we want identical behaviour between backends + SOKOL_ASSERT(_sg_multiple_u64((uint64_t)start_pos, 4)); + if (buf->slot.state == SG_RESOURCESTATE_VALID) { + if (_sg_validate_append_buffer(buf, data)) { + if (!buf->cmn.append_overflow && (data->size > 0)) { + // update and append on same buffer in same frame not allowed + SOKOL_ASSERT(buf->cmn.update_frame_index != _sg.frame_index); + _sg_append_buffer(buf, data, buf->cmn.append_frame_index != _sg.frame_index); + buf->cmn.append_pos += (int) _sg_roundup_u64(data->size, 4); + buf->cmn.append_frame_index = _sg.frame_index; + } + } + } + result = start_pos; + } else { + // FIXME: should we return -1 here? + result = 0; + } + _SG_TRACE_ARGS(append_buffer, buf_id, data, result); + return result; +} + +SOKOL_API_IMPL bool sg_query_buffer_overflow(sg_buffer buf_id) { + SOKOL_ASSERT(_sg.valid); + _sg_buffer_t* buf = _sg_lookup_buffer(buf_id.id); + bool result = buf ? buf->cmn.append_overflow : false; + return result; +} + +SOKOL_API_IMPL bool sg_query_buffer_will_overflow(sg_buffer buf_id, size_t size) { + SOKOL_ASSERT(_sg.valid); + _sg_buffer_t* buf = _sg_lookup_buffer(buf_id.id); + bool result = false; + if (buf) { + int append_pos = buf->cmn.append_pos; + // rewind append cursor in a new frame + if (buf->cmn.append_frame_index != _sg.frame_index) { + append_pos = 0; + } + if ((append_pos + _sg_roundup((int)size, 4)) > buf->cmn.size) { + result = true; + } + } + return result; +} + +SOKOL_API_IMPL void sg_update_image(sg_image img_id, const sg_image_data* data) { + SOKOL_ASSERT(_sg.valid); + _sg_stats_inc(num_update_image); + for (int mip_index = 0; mip_index < SG_MAX_MIPMAPS; mip_index++) { + if (data->mip_levels[mip_index].size == 0) { + break; + } + _sg_stats_add(size_update_image, (uint32_t)data->mip_levels[mip_index].size); + } + _sg_image_t* img = _sg_lookup_image(img_id.id); + if (img && img->slot.state == SG_RESOURCESTATE_VALID) { + if (_sg_validate_update_image(img, data)) { + SOKOL_ASSERT(img->cmn.upd_frame_index != _sg.frame_index); + _sg_update_image(img, data); + img->cmn.upd_frame_index = _sg.frame_index; + } + } + _SG_TRACE_ARGS(update_image, img_id, data); +} + +SOKOL_API_IMPL void sg_push_debug_group(const char* name) { + SOKOL_ASSERT(_sg.valid); + SOKOL_ASSERT(name); + _sg_push_debug_group(name); + _SG_TRACE_ARGS(push_debug_group, name); +} + +SOKOL_API_IMPL void sg_pop_debug_group(void) { + SOKOL_ASSERT(_sg.valid); + _sg_pop_debug_group(); + _SG_TRACE_NOARGS(pop_debug_group); +} + +SOKOL_API_IMPL bool sg_add_commit_listener(sg_commit_listener listener) { + SOKOL_ASSERT(_sg.valid); + return _sg_add_commit_listener(&listener); +} + +SOKOL_API_IMPL bool sg_remove_commit_listener(sg_commit_listener listener) { + SOKOL_ASSERT(_sg.valid); + return _sg_remove_commit_listener(&listener); +} + +SOKOL_API_IMPL void sg_enable_stats(void) { + SOKOL_ASSERT(_sg.valid); + _sg.stats_enabled = true; +} + +SOKOL_API_IMPL void sg_disable_stats(void) { + SOKOL_ASSERT(_sg.valid); + _sg.stats_enabled = false; +} + +SOKOL_API_IMPL bool sg_stats_enabled(void) { + return _sg.stats_enabled; +} + +SOKOL_API_IMPL sg_buffer_info sg_query_buffer_info(sg_buffer buf_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_buffer_info, info); + const _sg_buffer_t* buf = _sg_lookup_buffer(buf_id.id); + if (buf) { + info.slot.state = buf->slot.state; + info.slot.res_id = buf->slot.id; + info.slot.uninit_count = buf->slot.uninit_count; + info.update_frame_index = buf->cmn.update_frame_index; + info.append_frame_index = buf->cmn.append_frame_index; + info.append_pos = buf->cmn.append_pos; + info.append_overflow = buf->cmn.append_overflow; + #if defined(SOKOL_D3D11) + info.num_slots = 1; + info.active_slot = 0; + #else + info.num_slots = buf->cmn.num_slots; + info.active_slot = buf->cmn.active_slot; + #endif + } + return info; +} + +SOKOL_API_IMPL sg_image_info sg_query_image_info(sg_image img_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_image_info, info); + const _sg_image_t* img = _sg_lookup_image(img_id.id); + if (img) { + info.slot.state = img->slot.state; + info.slot.res_id = img->slot.id; + info.slot.uninit_count = img->slot.uninit_count; + info.upd_frame_index = img->cmn.upd_frame_index; + #if defined(SOKOL_D3D11) + info.num_slots = 1; + info.active_slot = 0; + #else + info.num_slots = img->cmn.num_slots; + info.active_slot = img->cmn.active_slot; + #endif + } + return info; +} + +SOKOL_API_IMPL sg_sampler_info sg_query_sampler_info(sg_sampler smp_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_sampler_info, info); + const _sg_sampler_t* smp = _sg_lookup_sampler(smp_id.id); + if (smp) { + info.slot.state = smp->slot.state; + info.slot.res_id = smp->slot.id; + info.slot.uninit_count = smp->slot.uninit_count; + } + return info; +} + +SOKOL_API_IMPL sg_shader_info sg_query_shader_info(sg_shader shd_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_shader_info, info); + const _sg_shader_t* shd = _sg_lookup_shader(shd_id.id); + if (shd) { + info.slot.state = shd->slot.state; + info.slot.res_id = shd->slot.id; + info.slot.uninit_count = shd->slot.uninit_count; + } + return info; +} + +SOKOL_API_IMPL sg_pipeline_info sg_query_pipeline_info(sg_pipeline pip_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_pipeline_info, info); + const _sg_pipeline_t* pip = _sg_lookup_pipeline(pip_id.id); + if (pip) { + info.slot.state = pip->slot.state; + info.slot.res_id = pip->slot.id; + info.slot.uninit_count = pip->slot.uninit_count; + } + return info; +} + +SOKOL_API_IMPL sg_view_info sg_query_view_info(sg_view view_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_view_info, info); + const _sg_view_t* view = _sg_lookup_view(view_id.id); + if (view) { + info.slot.state = view->slot.state; + info.slot.res_id = view->slot.id; + info.slot.uninit_count = view->slot.uninit_count; + } + return info; +} + +SOKOL_API_IMPL sg_buffer_desc sg_query_buffer_desc(sg_buffer buf_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_buffer_desc, desc); + const _sg_buffer_t* buf = _sg_lookup_buffer(buf_id.id); + if (buf) { + desc.size = (size_t)buf->cmn.size; + desc.usage = buf->cmn.usage; + } + return desc; +} + +SOKOL_API_IMPL size_t sg_query_buffer_size(sg_buffer buf_id) { + SOKOL_ASSERT(_sg.valid); + const _sg_buffer_t* buf = _sg_lookup_buffer(buf_id.id); + if (buf) { + return (size_t)buf->cmn.size; + } + return 0; +} + +SOKOL_API_IMPL sg_buffer_usage sg_query_buffer_usage(sg_buffer buf_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_buffer_usage, usg); + const _sg_buffer_t* buf = _sg_lookup_buffer(buf_id.id); + if (buf) { + usg = buf->cmn.usage; + } + return usg; +} + +SOKOL_API_IMPL sg_image_desc sg_query_image_desc(sg_image img_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_image_desc, desc); + const _sg_image_t* img = _sg_lookup_image(img_id.id); + if (img) { + desc.type = img->cmn.type; + desc.width = img->cmn.width; + desc.height = img->cmn.height; + desc.num_slices = img->cmn.num_slices; + desc.num_mipmaps = img->cmn.num_mipmaps; + desc.usage = img->cmn.usage; + desc.pixel_format = img->cmn.pixel_format; + desc.sample_count = img->cmn.sample_count; + } + return desc; +} + +SOKOL_API_IMPL sg_image_type sg_query_image_type(sg_image img_id) { + SOKOL_ASSERT(_sg.valid); + const _sg_image_t* img = _sg_lookup_image(img_id.id); + if (img) { + return img->cmn.type; + } + return _SG_IMAGETYPE_DEFAULT; +} + +SOKOL_API_IMPL int sg_query_image_width(sg_image img_id) { + SOKOL_ASSERT(_sg.valid); + const _sg_image_t* img = _sg_lookup_image(img_id.id); + if (img) { + return img->cmn.width; + } + return 0; +} + +SOKOL_API_IMPL int sg_query_image_height(sg_image img_id) { + SOKOL_ASSERT(_sg.valid); + const _sg_image_t* img = _sg_lookup_image(img_id.id); + if (img) { + return img->cmn.height; + } + return 0; +} + +SOKOL_API_IMPL int sg_query_image_num_slices(sg_image img_id) { + SOKOL_ASSERT(_sg.valid); + const _sg_image_t* img = _sg_lookup_image(img_id.id); + if (img) { + return img->cmn.num_slices; + } + return 0; +} + +SOKOL_API_IMPL int sg_query_image_num_mipmaps(sg_image img_id) { + SOKOL_ASSERT(_sg.valid); + const _sg_image_t* img = _sg_lookup_image(img_id.id); + if (img) { + return img->cmn.num_mipmaps; + } + return 0; +} + +SOKOL_API_IMPL sg_pixel_format sg_query_image_pixelformat(sg_image img_id) { + SOKOL_ASSERT(_sg.valid); + const _sg_image_t* img = _sg_lookup_image(img_id.id); + if (img) { + return img->cmn.pixel_format; + } + return _SG_PIXELFORMAT_DEFAULT; +} + +SOKOL_API_IMPL sg_image_usage sg_query_image_usage(sg_image img_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_image_usage, usg); + const _sg_image_t* img = _sg_lookup_image(img_id.id); + if (img) { + usg = img->cmn.usage; + } + return usg; +} + +SOKOL_API_IMPL int sg_query_image_sample_count(sg_image img_id) { + SOKOL_ASSERT(_sg.valid); + const _sg_image_t* img = _sg_lookup_image(img_id.id); + if (img) { + return img->cmn.sample_count; + } + return 0; +} + +SOKOL_API_IMPL sg_view_type sg_query_view_type(sg_view view_id) { + SOKOL_ASSERT(_sg.valid); + const _sg_view_t* view = _sg_lookup_view(view_id.id); + if (view) { + return view->cmn.type; + } else { + return SG_VIEWTYPE_INVALID; + } +} + +// NOTE: may return SG_INVALID_ID if view invalid or view not an image view +SOKOL_API_IMPL sg_image sg_query_view_image(sg_view view_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_image, img); + const _sg_view_t* view = _sg_lookup_view(view_id.id); + if (view) { + img.id = view->cmn.img.ref.sref.id; + } + return img; +} + +// NOTE: may return SG_INVALID_ID if view invalid or view not a buffer view +SOKOL_API_IMPL sg_buffer sg_query_view_buffer(sg_view view_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_buffer, buf); + const _sg_view_t* view = _sg_lookup_view(view_id.id); + if (view) { + buf.id = view->cmn.buf.ref.sref.id; + } + return buf; +} + +SOKOL_API_IMPL sg_sampler_desc sg_query_sampler_desc(sg_sampler smp_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_sampler_desc, desc); + const _sg_sampler_t* smp = _sg_lookup_sampler(smp_id.id); + if (smp) { + desc.min_filter = smp->cmn.min_filter; + desc.mag_filter = smp->cmn.mag_filter; + desc.mipmap_filter = smp->cmn.mipmap_filter; + desc.wrap_u = smp->cmn.wrap_u; + desc.wrap_v = smp->cmn.wrap_v; + desc.wrap_w = smp->cmn.wrap_w; + desc.min_lod = smp->cmn.min_lod; + desc.max_lod = smp->cmn.max_lod; + desc.border_color = smp->cmn.border_color; + desc.compare = smp->cmn.compare; + desc.max_anisotropy = smp->cmn.max_anisotropy; + } + return desc; +} + +SOKOL_API_IMPL sg_shader_desc sg_query_shader_desc(sg_shader shd_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_shader_desc, desc); + const _sg_shader_t* shd = _sg_lookup_shader(shd_id.id); + if (shd) { + for (size_t ub_idx = 0; ub_idx < SG_MAX_UNIFORMBLOCK_BINDSLOTS; ub_idx++) { + sg_shader_uniform_block* ub_desc = &desc.uniform_blocks[ub_idx]; + const _sg_shader_uniform_block_t* ub = &shd->cmn.uniform_blocks[ub_idx]; + ub_desc->stage = ub->stage; + ub_desc->size = ub->size; + } + for (size_t view_idx = 0; view_idx < SG_MAX_VIEW_BINDSLOTS; view_idx++) { + const _sg_shader_view_t* view = &shd->cmn.views[view_idx]; + if (view->view_type == SG_VIEWTYPE_TEXTURE) { + sg_shader_texture_view* tex_desc = &desc.views[view_idx].texture; + tex_desc->stage = view->stage; + tex_desc->image_type = view->image_type; + tex_desc->sample_type = view->sample_type; + tex_desc->multisampled = view->multisampled; + } else if (shd->cmn.views[view_idx].view_type == SG_VIEWTYPE_STORAGEBUFFER) { + sg_shader_storage_buffer_view* sbuf_desc = &desc.views[view_idx].storage_buffer; + sbuf_desc->stage = view->stage; + sbuf_desc->readonly = view->sbuf_readonly; + } else if (shd->cmn.views[view_idx].view_type == SG_VIEWTYPE_STORAGEIMAGE) { + sg_shader_storage_image_view* simg_desc = &desc.views[view_idx].storage_image; + simg_desc->stage = view->stage; + simg_desc->access_format = view->access_format; + simg_desc->image_type = view->image_type; + simg_desc->writeonly = view->simg_writeonly; + } + } + for (size_t smp_idx = 0; smp_idx < SG_MAX_SAMPLER_BINDSLOTS; smp_idx++) { + sg_shader_sampler* smp_desc = &desc.samplers[smp_idx]; + const _sg_shader_sampler_t* smp = &shd->cmn.samplers[smp_idx]; + smp_desc->stage = smp->stage; + smp_desc->sampler_type = smp->sampler_type; + } + for (size_t tex_smp_idx = 0; tex_smp_idx < SG_MAX_TEXTURE_SAMPLER_PAIRS; tex_smp_idx++) { + sg_shader_texture_sampler_pair* tex_smp_desc = &desc.texture_sampler_pairs[tex_smp_idx]; + const _sg_shader_texture_sampler_t* tex_smp = &shd->cmn.texture_samplers[tex_smp_idx]; + tex_smp_desc->stage = tex_smp->stage; + tex_smp_desc->view_slot = tex_smp->view_slot; + tex_smp_desc->sampler_slot = tex_smp->sampler_slot; + } + } + return desc; +} + +SOKOL_API_IMPL sg_pipeline_desc sg_query_pipeline_desc(sg_pipeline pip_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_pipeline_desc, desc); + const _sg_pipeline_t* pip = _sg_lookup_pipeline(pip_id.id); + if (pip) { + desc.compute = pip->cmn.is_compute; + desc.shader.id = pip->cmn.shader.sref.id; + desc.layout = pip->cmn.layout; + desc.depth = pip->cmn.depth; + desc.stencil = pip->cmn.stencil; + desc.color_count = pip->cmn.color_count; + for (int i = 0; i < pip->cmn.color_count; i++) { + desc.colors[i] = pip->cmn.colors[i]; + } + desc.primitive_type = pip->cmn.primitive_type; + desc.index_type = pip->cmn.index_type; + desc.cull_mode = pip->cmn.cull_mode; + desc.face_winding = pip->cmn.face_winding; + desc.sample_count = pip->cmn.sample_count; + desc.blend_color = pip->cmn.blend_color; + desc.alpha_to_coverage_enabled = pip->cmn.alpha_to_coverage_enabled; + } + return desc; +} + +SOKOL_API_IMPL sg_view_desc sg_query_view_desc(sg_view view_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_view_desc, desc); + const _sg_view_t* view = _sg_lookup_view(view_id.id); + if (view) { + switch (view->cmn.type) { + case SG_VIEWTYPE_STORAGEBUFFER: + desc.storage_buffer.buffer.id = view->cmn.buf.ref.sref.id; + desc.storage_buffer.offset = view->cmn.buf.offset; + break; + case SG_VIEWTYPE_STORAGEIMAGE: + desc.storage_image.image.id = view->cmn.img.ref.sref.id; + desc.storage_image.mip_level = view->cmn.img.mip_level; + desc.storage_image.slice = view->cmn.img.slice; + break; + case SG_VIEWTYPE_TEXTURE: + desc.texture.image.id = view->cmn.img.ref.sref.id; + desc.texture.mip_levels.base = view->cmn.img.mip_level; + desc.texture.mip_levels.count = view->cmn.img.mip_level_count; + desc.texture.slices.base = view->cmn.img.slice; + desc.texture.slices.count = view->cmn.img.slice_count; + break; + case SG_VIEWTYPE_COLORATTACHMENT: + desc.color_attachment.image.id = view->cmn.img.ref.sref.id; + desc.color_attachment.mip_level = view->cmn.img.mip_level; + desc.color_attachment.slice = view->cmn.img.slice; + break; + case SG_VIEWTYPE_RESOLVEATTACHMENT: + desc.resolve_attachment.image.id = view->cmn.img.ref.sref.id; + desc.resolve_attachment.mip_level = view->cmn.img.mip_level; + desc.resolve_attachment.slice = view->cmn.img.slice; + break; + case SG_VIEWTYPE_DEPTHSTENCILATTACHMENT: + desc.depth_stencil_attachment.image.id = view->cmn.img.ref.sref.id; + desc.depth_stencil_attachment.mip_level = view->cmn.img.mip_level; + desc.depth_stencil_attachment.slice = view->cmn.img.slice; + break; + default: + SOKOL_UNREACHABLE; + } + } + return desc; +} + +SOKOL_API_IMPL sg_buffer_desc sg_query_buffer_defaults(const sg_buffer_desc* desc) { + SOKOL_ASSERT(_sg.valid && desc); + return _sg_buffer_desc_defaults(desc); +} + +SOKOL_API_IMPL sg_image_desc sg_query_image_defaults(const sg_image_desc* desc) { + SOKOL_ASSERT(_sg.valid && desc); + return _sg_image_desc_defaults(desc); +} + +SOKOL_API_IMPL sg_sampler_desc sg_query_sampler_defaults(const sg_sampler_desc* desc) { + SOKOL_ASSERT(_sg.valid && desc); + return _sg_sampler_desc_defaults(desc); +} + +SOKOL_API_IMPL sg_shader_desc sg_query_shader_defaults(const sg_shader_desc* desc) { + SOKOL_ASSERT(_sg.valid && desc); + return _sg_shader_desc_defaults(desc); +} + +SOKOL_API_IMPL sg_pipeline_desc sg_query_pipeline_defaults(const sg_pipeline_desc* desc) { + SOKOL_ASSERT(_sg.valid && desc); + return _sg_pipeline_desc_defaults(desc); +} + +SOKOL_API_IMPL sg_view_desc sg_query_view_defaults(const sg_view_desc* desc) { + SOKOL_ASSERT(_sg.valid && desc); + return _sg_view_desc_defaults(desc); +} + +SOKOL_API_IMPL const void* sg_d3d11_device(void) { + #if defined(SOKOL_D3D11) + return (const void*) _sg.d3d11.dev; + #else + return 0; + #endif +} + +SOKOL_API_IMPL const void* sg_d3d11_device_context(void) { + #if defined(SOKOL_D3D11) + return (const void*) _sg.d3d11.ctx; + #else + return 0; + #endif +} + +SOKOL_API_IMPL sg_d3d11_buffer_info sg_d3d11_query_buffer_info(sg_buffer buf_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_d3d11_buffer_info, res); + #if defined(SOKOL_D3D11) + const _sg_buffer_t* buf = _sg_lookup_buffer(buf_id.id); + if (buf) { + res.buf = (const void*) buf->d3d11.buf; + } + #else + _SOKOL_UNUSED(buf_id); + #endif + return res; +} + +SOKOL_API_IMPL sg_d3d11_image_info sg_d3d11_query_image_info(sg_image img_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_d3d11_image_info, res); + #if defined(SOKOL_D3D11) + const _sg_image_t* img = _sg_lookup_image(img_id.id); + if (img) { + res.tex2d = (const void*) img->d3d11.tex2d; + res.tex3d = (const void*) img->d3d11.tex3d; + res.res = (const void*) img->d3d11.res; + } + #else + _SOKOL_UNUSED(img_id); + #endif + return res; +} + +SOKOL_API_IMPL sg_d3d11_sampler_info sg_d3d11_query_sampler_info(sg_sampler smp_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_d3d11_sampler_info, res); + #if defined(SOKOL_D3D11) + const _sg_sampler_t* smp = _sg_lookup_sampler(smp_id.id); + if (smp) { + res.smp = (const void*) smp->d3d11.smp; + } + #else + _SOKOL_UNUSED(smp_id); + #endif + return res; +} + +SOKOL_API_IMPL sg_d3d11_shader_info sg_d3d11_query_shader_info(sg_shader shd_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_d3d11_shader_info, res); + #if defined(SOKOL_D3D11) + const _sg_shader_t* shd = _sg_lookup_shader(shd_id.id); + if (shd) { + for (size_t i = 0; i < SG_MAX_UNIFORMBLOCK_BINDSLOTS; i++) { + res.cbufs[i] = (const void*) shd->d3d11.all_cbufs[i]; + } + res.vs = (const void*) shd->d3d11.vs; + res.fs = (const void*) shd->d3d11.fs; + } + #else + _SOKOL_UNUSED(shd_id); + #endif + return res; +} + +SOKOL_API_IMPL sg_d3d11_pipeline_info sg_d3d11_query_pipeline_info(sg_pipeline pip_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_d3d11_pipeline_info, res); + #if defined(SOKOL_D3D11) + const _sg_pipeline_t* pip = _sg_lookup_pipeline(pip_id.id); + if (pip) { + res.il = (const void*) pip->d3d11.il; + res.rs = (const void*) pip->d3d11.rs; + res.dss = (const void*) pip->d3d11.dss; + res.bs = (const void*) pip->d3d11.bs; + } + #else + _SOKOL_UNUSED(pip_id); + #endif + return res; +} + +SOKOL_API_IMPL sg_d3d11_view_info sg_d3d11_query_view_info(sg_view view_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_d3d11_view_info, res); + #if defined(SOKOL_D3D11) + const _sg_view_t* view = _sg_lookup_view(view_id.id); + res.srv = (const void*) view->d3d11.srv; + res.uav = (const void*) view->d3d11.uav; + res.rtv = (const void*) view->d3d11.rtv; + res.dsv = (const void*) view->d3d11.dsv; + #else + _SOKOL_UNUSED(view_id); + #endif + return res; +} + +SOKOL_API_IMPL const void* sg_mtl_device(void) { + #if defined(SOKOL_METAL) + if (nil != _sg.mtl.device) { + return (__bridge const void*) _sg.mtl.device; + } else { + return 0; + } + #else + return 0; + #endif +} + +SOKOL_API_IMPL const void* sg_mtl_render_command_encoder(void) { + #if defined(SOKOL_METAL) + if (nil != _sg.mtl.render_cmd_encoder) { + return (__bridge const void*) _sg.mtl.render_cmd_encoder; + } else { + return 0; + } + #else + return 0; + #endif +} + +SOKOL_API_IMPL const void* sg_mtl_compute_command_encoder(void) { + #if defined(SOKOL_METAL) + if (nil != _sg.mtl.compute_cmd_encoder) { + return (__bridge const void*) _sg.mtl.compute_cmd_encoder; + } else { + return 0; + } + #else + return 0; + #endif +} + +SOKOL_API_IMPL const void* sg_mtl_command_queue(void) { + #if defined(SOKOL_METAL) + if (nil != _sg.mtl.cmd_queue) { + return (__bridge const void*) _sg.mtl.cmd_queue; + } else { + return 0; + } + #else + return 0; + #endif +} + +SOKOL_API_IMPL sg_mtl_buffer_info sg_mtl_query_buffer_info(sg_buffer buf_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_mtl_buffer_info, res); + #if defined(SOKOL_METAL) + const _sg_buffer_t* buf = _sg_lookup_buffer(buf_id.id); + if (buf) { + for (int i = 0; i < SG_NUM_INFLIGHT_FRAMES; i++) { + if (buf->mtl.buf[i] != 0) { + res.buf[i] = (__bridge void*) _sg_mtl_id(buf->mtl.buf[i]); + } + } + res.active_slot = buf->cmn.active_slot; + } + #else + _SOKOL_UNUSED(buf_id); + #endif + return res; +} + +SOKOL_API_IMPL sg_mtl_image_info sg_mtl_query_image_info(sg_image img_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_mtl_image_info, res); + #if defined(SOKOL_METAL) + const _sg_image_t* img = _sg_lookup_image(img_id.id); + if (img) { + for (int i = 0; i < SG_NUM_INFLIGHT_FRAMES; i++) { + if (img->mtl.tex[i] != 0) { + res.tex[i] = (__bridge void*) _sg_mtl_id(img->mtl.tex[i]); + } + } + res.active_slot = img->cmn.active_slot; + } + #else + _SOKOL_UNUSED(img_id); + #endif + return res; +} + +SOKOL_API_IMPL sg_mtl_sampler_info sg_mtl_query_sampler_info(sg_sampler smp_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_mtl_sampler_info, res); + #if defined(SOKOL_METAL) + const _sg_sampler_t* smp = _sg_lookup_sampler(smp_id.id); + if (smp) { + if (smp->mtl.sampler_state != 0) { + res.smp = (__bridge void*) _sg_mtl_id(smp->mtl.sampler_state); + } + } + #else + _SOKOL_UNUSED(smp_id); + #endif + return res; +} + +SOKOL_API_IMPL sg_mtl_shader_info sg_mtl_query_shader_info(sg_shader shd_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_mtl_shader_info, res); + #if defined(SOKOL_METAL) + const _sg_shader_t* shd = _sg_lookup_shader(shd_id.id); + if (shd) { + const int vertex_lib = shd->mtl.vertex_func.mtl_lib; + const int vertex_func = shd->mtl.vertex_func.mtl_func; + const int fragment_lib = shd->mtl.fragment_func.mtl_lib; + const int fragment_func = shd->mtl.fragment_func.mtl_func; + if (vertex_lib != 0) { + res.vertex_lib = (__bridge void*) _sg_mtl_id(vertex_lib); + } + if (fragment_lib != 0) { + res.fragment_lib = (__bridge void*) _sg_mtl_id(fragment_lib); + } + if (vertex_func != 0) { + res.vertex_func = (__bridge void*) _sg_mtl_id(vertex_func); + } + if (fragment_func != 0) { + res.fragment_func = (__bridge void*) _sg_mtl_id(fragment_func); + } + } + #else + _SOKOL_UNUSED(shd_id); + #endif + return res; +} + +SOKOL_API_IMPL sg_mtl_pipeline_info sg_mtl_query_pipeline_info(sg_pipeline pip_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_mtl_pipeline_info, res); + #if defined(SOKOL_METAL) + const _sg_pipeline_t* pip = _sg_lookup_pipeline(pip_id.id); + if (pip) { + if (pip->mtl.rps != 0) { + res.rps = (__bridge void*) _sg_mtl_id(pip->mtl.rps); + } + if (pip->mtl.dss != 0) { + res.dss = (__bridge void*) _sg_mtl_id(pip->mtl.dss); + } + } + #else + _SOKOL_UNUSED(pip_id); + #endif + return res; +} + +SOKOL_API_IMPL const void* sg_wgpu_device(void) { + #if defined(SOKOL_WGPU) + return (const void*) _sg.wgpu.dev; + #else + return 0; + #endif +} + +SOKOL_API_IMPL const void* sg_wgpu_queue(void) { + #if defined(SOKOL_WGPU) + return (const void*) _sg.wgpu.queue; + #else + return 0; + #endif +} + +SOKOL_API_IMPL const void* sg_wgpu_command_encoder(void) { + #if defined(SOKOL_WGPU) + return (const void*) _sg.wgpu.cmd_enc; + #else + return 0; + #endif +} + +SOKOL_API_IMPL const void* sg_wgpu_render_pass_encoder(void) { + #if defined(SOKOL_WGPU) + return (const void*) _sg.wgpu.rpass_enc; + #else + return 0; + #endif +} + +SOKOL_API_IMPL const void* sg_wgpu_compute_pass_encoder(void) { + #if defined(SOKOL_WGPU) + return (const void*) _sg.wgpu.cpass_enc; + #else + return 0; + #endif +} + +SOKOL_API_IMPL sg_wgpu_buffer_info sg_wgpu_query_buffer_info(sg_buffer buf_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_wgpu_buffer_info, res); + #if defined(SOKOL_WGPU) + const _sg_buffer_t* buf = _sg_lookup_buffer(buf_id.id); + if (buf) { + res.buf = (const void*) buf->wgpu.buf; + } + #else + _SOKOL_UNUSED(buf_id); + #endif + return res; +} + +SOKOL_API_IMPL sg_wgpu_image_info sg_wgpu_query_image_info(sg_image img_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_wgpu_image_info, res); + #if defined(SOKOL_WGPU) + const _sg_image_t* img = _sg_lookup_image(img_id.id); + if (img) { + res.tex = (const void*) img->wgpu.tex; + } + #else + _SOKOL_UNUSED(img_id); + #endif + return res; +} + +SOKOL_API_IMPL sg_wgpu_sampler_info sg_wgpu_query_sampler_info(sg_sampler smp_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_wgpu_sampler_info, res); + #if defined(SOKOL_WGPU) + const _sg_sampler_t* smp = _sg_lookup_sampler(smp_id.id); + if (smp) { + res.smp = (const void*) smp->wgpu.smp; + } + #else + _SOKOL_UNUSED(smp_id); + #endif + return res; +} + +SOKOL_API_IMPL sg_wgpu_shader_info sg_wgpu_query_shader_info(sg_shader shd_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_wgpu_shader_info, res); + #if defined(SOKOL_WGPU) + const _sg_shader_t* shd = _sg_lookup_shader(shd_id.id); + if (shd) { + res.vs_mod = (const void*) shd->wgpu.vertex_func.module; + res.fs_mod = (const void*) shd->wgpu.fragment_func.module; + res.bgl = (const void*) shd->wgpu.bgl_view_smp; + } + #else + _SOKOL_UNUSED(shd_id); + #endif + return res; +} + +SOKOL_API_IMPL sg_wgpu_pipeline_info sg_wgpu_query_pipeline_info(sg_pipeline pip_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_wgpu_pipeline_info, res); + #if defined(SOKOL_WGPU) + const _sg_pipeline_t* pip = _sg_lookup_pipeline(pip_id.id); + if (pip) { + res.render_pipeline = (const void*) pip->wgpu.rpip; + res.compute_pipeline = (const void*) pip->wgpu.cpip; + } + #else + _SOKOL_UNUSED(pip_id); + #endif + return res; +} + +SOKOL_API_IMPL sg_wgpu_view_info sg_wgpu_query_view_info(sg_view view_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_wgpu_view_info, res); + #if defined(SOKOL_WGPU) + const _sg_view_t* view = _sg_lookup_view(view_id.id); + if (view) { + res.view = (const void*) view->wgpu.view; + } + #else + _SOKOL_UNUSED(view_id); + #endif + return res; +} + +SOKOL_API_IMPL sg_gl_buffer_info sg_gl_query_buffer_info(sg_buffer buf_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_gl_buffer_info, res); + #if defined(_SOKOL_ANY_GL) + const _sg_buffer_t* buf = _sg_lookup_buffer(buf_id.id); + if (buf) { + for (int i = 0; i < SG_NUM_INFLIGHT_FRAMES; i++) { + res.buf[i] = buf->gl.buf[i]; + } + res.active_slot = buf->cmn.active_slot; + } + #else + _SOKOL_UNUSED(buf_id); + #endif + return res; +} + +SOKOL_API_IMPL sg_gl_image_info sg_gl_query_image_info(sg_image img_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_gl_image_info, res); + #if defined(_SOKOL_ANY_GL) + const _sg_image_t* img = _sg_lookup_image(img_id.id); + if (img) { + for (int i = 0; i < SG_NUM_INFLIGHT_FRAMES; i++) { + res.tex[i] = img->gl.tex[i]; + } + res.tex_target = img->gl.target; + res.active_slot = img->cmn.active_slot; + } + #else + _SOKOL_UNUSED(img_id); + #endif + return res; +} + +SOKOL_API_IMPL sg_gl_sampler_info sg_gl_query_sampler_info(sg_sampler smp_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_gl_sampler_info, res); + #if defined(_SOKOL_ANY_GL) + const _sg_sampler_t* smp = _sg_lookup_sampler(smp_id.id); + if (smp) { + res.smp = smp->gl.smp; + } + #else + _SOKOL_UNUSED(smp_id); + #endif + return res; +} + +SOKOL_API_IMPL sg_gl_shader_info sg_gl_query_shader_info(sg_shader shd_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_gl_shader_info, res); + #if defined(_SOKOL_ANY_GL) + const _sg_shader_t* shd = _sg_lookup_shader(shd_id.id); + if (shd) { + res.prog = shd->gl.prog; + } + #else + _SOKOL_UNUSED(shd_id); + #endif + return res; +} + +SOKOL_API_IMPL sg_gl_view_info sg_gl_query_view_info(sg_view view_id) { + SOKOL_ASSERT(_sg.valid); + _SG_STRUCT(sg_gl_view_info, res); + #if defined(_SOKOL_ANY_GL) + const _sg_view_t* view = _sg_lookup_view(view_id.id); + if (view) { + for (size_t i = 0; i < SG_NUM_INFLIGHT_FRAMES; i++) { + res.tex_view[i] = view->gl.tex_view[i]; + } + res.msaa_render_buffer = view->gl.msaa_render_buffer; + res.msaa_resolve_frame_buffer = view->gl.msaa_resolve_frame_buffer; + } + #else + _SOKOL_UNUSED(view_id); + #endif + return res; +} + +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +#endif // SOKOL_GFX_IMPL diff --git a/extern/sokol/sokol_glue.h b/extern/sokol/sokol_glue.h new file mode 100644 index 0000000..d9a2ad4 --- /dev/null +++ b/extern/sokol/sokol_glue.h @@ -0,0 +1,207 @@ +#if defined(SOKOL_IMPL) && !defined(SOKOL_GLUE_IMPL) +#define SOKOL_GLUE_IMPL +#endif +#ifndef SOKOL_GLUE_INCLUDED +/* + sokol_glue.h -- glue helper functions for sokol headers + + Project URL: https://github.com/floooh/sokol + + Do this: + #define SOKOL_IMPL or + #define SOKOL_GLUE_IMPL + before you include this file in *one* C or C++ file to create the + implementation. + + ...optionally provide the following macros to override defaults: + + SOKOL_ASSERT(c) - your own assert macro (default: assert(c)) + SOKOL_GLUE_API_DECL - public function declaration prefix (default: extern) + SOKOL_API_DECL - same as SOKOL_GLUE_API_DECL + SOKOL_API_IMPL - public function implementation prefix (default: -) + + If sokol_glue.h is compiled as a DLL, define the following before + including the declaration or implementation: + + SOKOL_DLL + + On Windows, SOKOL_DLL will define SOKOL_GLUE_API_DECL as __declspec(dllexport) + or __declspec(dllimport) as needed. + + OVERVIEW + ======== + sokol_glue.h provides glue helper functions between sokol_gfx.h and sokol_app.h, + so that sokol_gfx.h doesn't need to depend on sokol_app.h but can be + used with different window system glue libraries. + + PROVIDED FUNCTIONS + ================== + + sg_environment sglue_environment(void) + + Returns an sg_environment struct initialized by calling sokol_app.h + functions. Use this in the sg_setup() call like this: + + sg_setup(&(sg_desc){ + .environment = sglue_environment(), + ... + }); + + sg_swapchain sglue_swapchain(void) + + Returns an sg_swapchain struct initialized by calling sokol_app.h + functions. Use this in sg_begin_pass() for a 'swapchain pass' like + this: + + sg_begin_pass(&(sg_pass){ .swapchain = sglue_swapchain(), ... }); + + LICENSE + ======= + zlib/libpng license + + Copyright (c) 2018 Andre Weissflog + + This software is provided 'as-is', without any express or implied warranty. + In no event will the authors be held liable for any damages arising from the + use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software in a + product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not + be misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*/ +#define SOKOL_GLUE_INCLUDED + +#if defined(SOKOL_API_DECL) && !defined(SOKOL_GLUE_API_DECL) +#define SOKOL_GLUE_API_DECL SOKOL_API_DECL +#endif +#ifndef SOKOL_GLUE_API_DECL +#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_GLUE_IMPL) +#define SOKOL_GLUE_API_DECL __declspec(dllexport) +#elif defined(_WIN32) && defined(SOKOL_DLL) +#define SOKOL_GLUE_API_DECL __declspec(dllimport) +#else +#define SOKOL_GLUE_API_DECL extern +#endif +#endif + +#ifndef SOKOL_GFX_INCLUDED +#error "Please include sokol_gfx.h before sokol_glue.h" +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +SOKOL_GLUE_API_DECL sg_environment sglue_environment(void); +SOKOL_GLUE_API_DECL sg_swapchain sglue_swapchain(void); + +#ifdef __cplusplus +} /* extern "C" */ +#endif +#endif /* SOKOL_GLUE_INCLUDED */ + +/*-- IMPLEMENTATION ----------------------------------------------------------*/ +#ifdef SOKOL_GLUE_IMPL +#define SOKOL_GLUE_IMPL_INCLUDED (1) +#include /* memset */ + +#ifndef SOKOL_APP_INCLUDED +#error "Please include sokol_app.h before the sokol_glue.h implementation" +#endif + +#ifndef SOKOL_API_IMPL +#define SOKOL_API_IMPL +#endif + +#ifndef _SOKOL_PRIVATE + #if defined(__GNUC__) || defined(__clang__) + #define _SOKOL_PRIVATE __attribute__((unused)) static + #else + #define _SOKOL_PRIVATE static + #endif +#endif + +#ifndef SOKOL_ASSERT + #include + #define SOKOL_ASSERT(c) assert(c) +#endif +#ifndef SOKOL_UNREACHABLE + #define SOKOL_UNREACHABLE SOKOL_ASSERT(false) +#endif + +_SOKOL_PRIVATE sg_pixel_format _sglue_to_sgpixelformat(sapp_pixel_format fmt) { + switch (fmt) { + case SAPP_PIXELFORMAT_NONE: return SG_PIXELFORMAT_NONE; + case SAPP_PIXELFORMAT_RGBA8: return SG_PIXELFORMAT_RGBA8; + case SAPP_PIXELFORMAT_SRGB8A8: return SG_PIXELFORMAT_SRGB8A8; + case SAPP_PIXELFORMAT_BGRA8: return SG_PIXELFORMAT_BGRA8; + case SAPP_PIXELFORMAT_DEPTH_STENCIL: return SG_PIXELFORMAT_DEPTH_STENCIL; + case SAPP_PIXELFORMAT_DEPTH: return SG_PIXELFORMAT_DEPTH; + case SAPP_PIXELFORMAT_SBGRA8: // FIXME! + default: + SOKOL_UNREACHABLE; + return SG_PIXELFORMAT_NONE; + } +} + +SOKOL_API_IMPL sg_environment sglue_environment(void) { + sg_environment res; + memset(&res, 0, sizeof(res)); + const sapp_environment env = sapp_get_environment(); + res.defaults.color_format = _sglue_to_sgpixelformat(env.defaults.color_format); + res.defaults.depth_format = _sglue_to_sgpixelformat(env.defaults.depth_format); + res.defaults.sample_count = env.defaults.sample_count; + res.metal.device = env.metal.device; + res.d3d11.device = env.d3d11.device; + res.d3d11.device_context = env.d3d11.device_context; + res.wgpu.device = env.wgpu.device; + res.vulkan.instance = env.vulkan.instance; + res.vulkan.physical_device = env.vulkan.physical_device; + res.vulkan.device = env.vulkan.device; + res.vulkan.queue = env.vulkan.queue; + res.vulkan.queue_family_index = env.vulkan.queue_family_index; + return res; +} + +SOKOL_API_IMPL sg_swapchain sglue_swapchain(void) { + sg_swapchain res; + memset(&res, 0, sizeof(res)); + const sapp_swapchain sc = sapp_get_swapchain(); + res.width = sc.width; + res.height = sc.height; + res.sample_count = sc.sample_count; + res.color_format = _sglue_to_sgpixelformat(sc.color_format); + res.depth_format = _sglue_to_sgpixelformat(sc.depth_format); + res.metal.current_drawable = sc.metal.current_drawable; + res.metal.depth_stencil_texture = sc.metal.depth_stencil_texture; + res.metal.msaa_color_texture = sc.metal.msaa_color_texture; + res.d3d11.render_view = sc.d3d11.render_view; + res.d3d11.resolve_view = sc.d3d11.resolve_view; + res.d3d11.depth_stencil_view = sc.d3d11.depth_stencil_view; + res.wgpu.render_view = sc.wgpu.render_view; + res.wgpu.resolve_view = sc.wgpu.resolve_view; + res.wgpu.depth_stencil_view = sc.wgpu.depth_stencil_view; + res.vulkan.render_image = sc.vulkan.render_image; + res.vulkan.render_view = sc.vulkan.render_view; + res.vulkan.resolve_image = sc.vulkan.resolve_image; + res.vulkan.resolve_view = sc.vulkan.resolve_view; + res.vulkan.depth_stencil_image = sc.vulkan.depth_stencil_image; + res.vulkan.depth_stencil_view = sc.vulkan.depth_stencil_view; + res.vulkan.render_finished_semaphore = sc.vulkan.render_finished_semaphore; + res.vulkan.present_complete_semaphore = sc.vulkan.present_complete_semaphore; + res.gl.framebuffer = sc.gl.framebuffer; + return res; +} + +#endif /* SOKOL_GLUE_IMPL */ diff --git a/extern/sokol/sokol_imgui.h b/extern/sokol/sokol_imgui.h new file mode 100644 index 0000000..2d0b58a --- /dev/null +++ b/extern/sokol/sokol_imgui.h @@ -0,0 +1,3171 @@ +#if defined(SOKOL_IMPL) && !defined(SOKOL_IMGUI_IMPL) +#define SOKOL_IMGUI_IMPL +#endif +#ifndef SOKOL_IMGUI_INCLUDED +/* + sokol_imgui.h -- drop-in Dear ImGui renderer/event-handler for sokol_gfx.h + + Project URL: https://github.com/floooh/sokol + + Do this: + #define SOKOL_IMPL or + #define SOKOL_IMGUI_IMPL + + before you include this file in *one* C or C++ file to create the + implementation. + + NOTE that the implementation can be compiled either as C++ or as C. + When compiled as C++, sokol_imgui.h will directly call into the + Dear ImGui C++ API. When compiled as C, sokol_imgui.h will call + cimgui.h functions instead. + + NOTE that the formerly separate header sokol_cimgui.h has been + merged into sokol_imgui.h + + The following defines are used by the implementation to select the + platform-specific embedded shader code (these are the same defines as + used by sokol_gfx.h and sokol_app.h): + + SOKOL_GLCORE + SOKOL_GLES3 + SOKOL_D3D11 + SOKOL_METAL + SOKOL_WGPU + SOKOL_VULKAN + + Optionally provide the following configuration define both before including the + the declaration and implementation: + + SOKOL_IMGUI_NO_SOKOL_APP - don't depend on sokol_app.h (see below for details) + + Optionally provide the following macros before including the implementation + to override defaults: + + SOKOL_ASSERT(c) - your own assert macro (default: assert(c)) + SOKOL_IMGUI_API_DECL- public function declaration prefix (default: extern) + SOKOL_API_DECL - same as SOKOL_IMGUI_API_DECL + SOKOL_API_IMPL - public function implementation prefix (default: -) + + If sokol_imgui.h is compiled as a DLL, define the following before + including the declaration or implementation: + + SOKOL_DLL + + On Windows, SOKOL_DLL will define SOKOL_IMGUI_API_DECL as __declspec(dllexport) + or __declspec(dllimport) as needed. + + Include the following headers before sokol_imgui.h (both before including + the declaration and implementation): + + sokol_gfx.h + sokol_app.h (except SOKOL_IMGUI_NO_SOKOL_APP) + + Additionally, include the following headers before including the + implementation: + + If the implementation is compiled as C++: + imgui.h + + If the implementation is compiled as C: + cimgui.h + + When compiling as C, you can override the Dear ImGui C bindings prefix + via the define SOKOL_IMGUI_CPREFIX before including the sokol_imgui.h + implementation: + + #define SOKOL_IMGUI_IMPL + #define SOKOL_IMGUI_CPREFIX ImGui_ + #include "sokol_imgui.h" + + Note that the default prefix is 'ig'. + + + FEATURE OVERVIEW: + ================= + sokol_imgui.h implements the initialization, rendering and event-handling + code for Dear ImGui (https://github.com/ocornut/imgui) on top of + sokol_gfx.h and (optionally) sokol_app.h. + + The sokol_app.h dependency is optional and used for input event handling. + If you only use sokol_gfx.h but not sokol_app.h in your application, + define SOKOL_IMGUI_NO_SOKOL_APP before including the implementation + of sokol_imgui.h, this will remove any dependency to sokol_app.h, but + you must feed input events into Dear ImGui yourself. + + sokol_imgui.h is not thread-safe, all calls must be made from the + same thread where sokol_gfx.h is running. + + HOWTO: + ====== + + --- To initialize sokol-imgui, call: + + simgui_setup(const simgui_desc_t* desc) + + This will initialize Dear ImGui and create sokol-gfx resources + (two buffers for vertices and indices, a font texture and a pipeline- + state-object). + + Use the following simgui_desc_t members to configure behaviour: + + int max_vertices + The maximum number of vertices used for UI rendering, default is 65536. + sokol-imgui will use this to compute the size of the vertex- + and index-buffers allocated via sokol_gfx.h + + sg_pixel_format color_format + The color pixel format of the render pass where the UI + will be rendered. The default (0) matches sokol_gfx.h's + default pass. + + sg_pixel_format depth_format + The depth-buffer pixel format of the render pass where + the UI will be rendered. The default (0) matches + sokol_gfx.h's default pass depth format. + + int sample_count + The MSAA sample-count of the render pass where the UI + will be rendered. The default (0) matches sokol_gfx.h's + default pass sample count. + + const char* ini_filename + Sets this path as ImGui::GetIO().IniFilename where ImGui will store + and load UI persistency data. By default this is 0, so that Dear ImGui + will not preserve state between sessions (and also won't do + any filesystem calls). Also see the ImGui functions: + - LoadIniSettingsFromMemory() + - SaveIniSettingsFromMemory() + These functions give you explicit control over loading and saving + UI state while using your own filesystem wrapper functions (in this + case keep simgui_desc.ini_filename zero) + + bool no_default_font + Set this to true if you don't want to use ImGui's default + font. In this case you need to initialize the font + yourself after simgui_setup() is called. + + bool disable_paste_override + If set to true, sokol_imgui.h will not 'emulate' a Dear Imgui + clipboard paste action on SAPP_EVENTTYPE_CLIPBOARD_PASTED event. + This is mainly a hack/workaround to allow external workarounds + for making copy/paste work on the web platform. In general, + copy/paste support isn't properly fleshed out in sokol_imgui.h yet. + + bool disable_set_mouse_cursor + If true, sokol_imgui.h will not control the mouse cursor type + by calling sapp_set_mouse_cursor(). + + bool disable_windows_resize_from_edges + If true, windows can only be resized from the bottom right corner. + The default is false, meaning windows can be resized from edges. + + bool write_alpha_channel + Set this to true if you want alpha values written to the + framebuffer. By default this behavior is disabled to prevent + undesired behavior on platforms like the web where the canvas is + always alpha-blended with the background. + + simgui_allocator_t allocator + Used to override memory allocation functions. See further below + for details. + + simgui_logger_t logger + A user-provided logging callback. Note that without logging + callback, sokol-imgui will be completely silent! + See the section about ERROR REPORTING AND LOGGING below + for more details. + + --- At the start of a frame, call: + + simgui_new_frame(&(simgui_frame_desc_t){ + .width = ..., + .height = ..., + .delta_time = ..., + .dpi_scale = ... + }); + + 'width' and 'height' are the dimensions of the rendering surface, + passed to ImGui::GetIO().DisplaySize. + + 'delta_time' is the frame duration passed to ImGui::GetIO().DeltaTime. + + 'dpi_scale' is the current DPI scale factor, if this is left zero-initialized, + 1.0f will be used instead. Typical values for dpi_scale are >= 1.0f. + + For example, if you're using sokol_app.h and render to the default framebuffer: + + simgui_new_frame(&(simgui_frame_desc_t){ + .width = sapp_width(), + .height = sapp_height(), + .delta_time = sapp_frame_duration(), + .dpi_scale = sapp_dpi_scale() + }); + + --- at the end of the frame, before the sg_end_pass() where you + want to render the UI, call: + + simgui_render() + + This will first call ImGui::Render(), and then render ImGui's draw list + through sokol_gfx.h + + --- if you're using sokol_app.h, from inside the sokol_app.h event callback, + call: + + bool simgui_handle_event(const sapp_event* ev); + + The return value is the value of ImGui::GetIO().WantCaptureKeyboard, + if this is true, you might want to skip keyboard input handling + in your own event handler. + + If you want to use the ImGui functions for checking if a key is pressed + (e.g. ImGui::IsKeyPressed()) the following helper function to map + an sapp_keycode to an ImGuiKey value may be useful: + + int simgui_map_keycode(sapp_keycode c); + + Note that simgui_map_keycode() can be called outside simgui_setup()/simgui_shutdown(). + + --- finally, on application shutdown, call + + simgui_shutdown() + + ON ATTACHING YOUR OWN FONTS + =========================== + Since Dear ImGui 1.92.0 using non-default fonts has been greatly simplified: + + First, call `simgui_setup()` with the `.no_default_font` so that + sokol_imgui.h skips adding the default font. + + ...then simply call `AddFontDefault()` or `AddFontFromMemoryTTF()` on + the Dear ImGui IO object, everything else is taken care of automatically. + + Specifically, do *NOT*: + - call the deprecated `GetTexDataAsRGBA32()` function + - create a sokol-gfx image object for the font atlas + - set the `Font->TexID` on the ImGui IO object + + All those things are now handled inside sokol_imgui.h via a new 'texture update' + callback which is called by Dear ImGui whenever the state of the font atlas + texture changes. + + ON USER-PROVIDED IMAGES AND SAMPLERS + ==================================== + To render your own images via ImGui::Image() you need to create a Dear ImGui + compatible texture handle (ImTextureID) from a sokol-gfx texture view handle + or optionally a texture view handle and a compatible sampler handle. + + To create a ImTextureID from a sokol-gfx image handle, call: + + sg_view tex_view = sg_make_view(&(sg_view_desc){ .texture_binding.image = img }); + ImTextureID imtex_id = simgui_imtextureid(tex_view); + + Since no sampler is provided, such a texture handle will use a default + sampler with nearest filtering and clamp-to-edge. + + If you need to render with a different sampler, do this instead: + + sg_view tex_view = ...; + sg_sampler smp = ...; + ImTextureID imtex_id = simgui_imtextureid_with_sampler(tex_img, smp); + + You don't need to 'release' the ImTextureID handle, the ImTextureID + bits is simply a combination of the sg_view and sg_sampler bits. + + Once you have constructed an ImTextureID handle via simgui_imtextureid() + or simgui_imtextureid_with_sampler(), it used in the ImGui::Image() + call like this: + + ImGui::Image(imtex_id, ...); + + To extract the sg_view and sg_sampler handle from an ImTextureID: + + sg_view tex_view = simgui_texture_view_from_imtextureid(imtex_id); + sg_sampler smp = simgui_sampler_from_imtextureid(imtex_id); + + ...use the sokol-gfx function sg_query_view_image() if you need to + extract the texture view's image object: + + sg_image img = sg_query_view_image(tex_view); + + NOTE on C bindings since Dear ImGui 1.92.0: + + Since Dear ImGui v1.92.0 the ImGui::Image function takes an + ImTextureRef object instead of ImTextureID. In C++ this doesn't + require a code change since the ImTextureRef is automatically constructed + from the ImTextureID. + + In C this doesn't work and you need to explicitly create an + ImTextureRef struct, for instance: + + igImage((ImTextureRef){ ._TexID = my_tex_id }, ...); + + Currently Dear Bindings is missing a wrapper function for this, + also see: https://github.com/dearimgui/dear_bindings/issues/99 + + + MEMORY ALLOCATION OVERRIDE + ========================== + You can override the memory allocation functions at initialization time + like this: + + void* my_alloc(size_t size, void* user_data) { + return malloc(size); + } + + void my_free(void* ptr, void* user_data) { + free(ptr); + } + + ... + simgui_setup(&(simgui_desc_t){ + // ... + .allocator = { + .alloc_fn = my_alloc, + .free_fn = my_free, + .user_data = ...; + } + }); + ... + + If no overrides are provided, malloc and free will be used. + + This only affects memory allocation calls done by sokol_imgui.h + itself though, not any allocations in Dear ImGui. + + + ERROR REPORTING AND LOGGING + =========================== + To get any logging information at all you need to provide a logging callback in the setup call + the easiest way is to use sokol_log.h: + + #include "sokol_log.h" + + simgui_setup(&(simgui_desc_t){ + .logger.func = slog_func + }); + + To override logging with your own callback, first write a logging function like this: + + void my_log(const char* tag, // e.g. 'simgui' + uint32_t log_level, // 0=panic, 1=error, 2=warn, 3=info + uint32_t log_item_id, // SIMGUI_LOGITEM_* + const char* message_or_null, // a message string, may be nullptr in release mode + uint32_t line_nr, // line number in sokol_imgui.h + const char* filename_or_null, // source filename, may be nullptr in release mode + void* user_data) + { + ... + } + + ...and then setup sokol-imgui like this: + + simgui_setup(&(simgui_desc_t){ + .logger = { + .func = my_log, + .user_data = my_user_data, + } + }); + + The provided logging function must be reentrant (e.g. be callable from + different threads). + + If you don't want to provide your own custom logger it is highly recommended to use + the standard logger in sokol_log.h instead, otherwise you won't see any warnings or + errors. + + + IMGUI EVENT HANDLING + ==================== + You can call these functions from your platform's events to handle ImGui events + when SOKOL_IMGUI_NO_SOKOL_APP is defined. + + E.g. mouse position events can be dispatched like this: + + simgui_add_mouse_pos_event(100, 200); + + For adding key events, you're responsible to map your own key codes to ImGuiKey + values and pass those as int: + + simgui_add_key_event(imgui_key, true); + + Take note that modifiers (shift, ctrl, etc.) must be updated manually. + + If sokol_app is being used, ImGui events are handled for you. + + + LICENSE + ======= + + zlib/libpng license + + Copyright (c) 2018 Andre Weissflog + + This software is provided 'as-is', without any express or implied warranty. + In no event will the authors be held liable for any damages arising from the + use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software in a + product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not + be misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*/ +#define SOKOL_IMGUI_INCLUDED (1) +#include +#include +#include // size_t + +#if !defined(SOKOL_GFX_INCLUDED) +#error "Please include sokol_gfx.h before sokol_imgui.h" +#endif +#if !defined(SOKOL_IMGUI_NO_SOKOL_APP) && !defined(SOKOL_APP_INCLUDED) +#error "Please include sokol_app.h before sokol_imgui.h" +#endif + +#if defined(SOKOL_API_DECL) && !defined(SOKOL_IMGUI_API_DECL) +#define SOKOL_IMGUI_API_DECL SOKOL_API_DECL +#endif +#ifndef SOKOL_IMGUI_API_DECL +#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_IMGUI_IMPL) +#define SOKOL_IMGUI_API_DECL __declspec(dllexport) +#elif defined(_WIN32) && defined(SOKOL_DLL) +#define SOKOL_IMGUI_API_DECL __declspec(dllimport) +#else +#define SOKOL_IMGUI_API_DECL extern +#endif +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* + simgui_log_item + + An enum with a unique item for each log message, warning, error + and validation layer message. +*/ +#define _SIMGUI_LOG_ITEMS \ + _SIMGUI_LOGITEM_XMACRO(OK, "Ok") \ + _SIMGUI_LOGITEM_XMACRO(MALLOC_FAILED, "memory allocation failed") \ + _SIMGUI_LOGITEM_XMACRO(BUFFER_OVERFLOW, "internal vertex/index buffer overflow (increase simgui_desc_t.max_vertices)") + +#define _SIMGUI_LOGITEM_XMACRO(item,msg) SIMGUI_LOGITEM_##item, +typedef enum simgui_log_item_t { + _SIMGUI_LOG_ITEMS +} simgui_log_item_t; +#undef _SIMGUI_LOGITEM_XMACRO + +/* + simgui_allocator_t + + Used in simgui_desc_t to provide custom memory-alloc and -free functions + to sokol_imgui.h. If memory management should be overridden, both the + alloc_fn and free_fn function must be provided (e.g. it's not valid to + override one function but not the other). +*/ +typedef struct simgui_allocator_t { + void* (*alloc_fn)(size_t size, void* user_data); + void (*free_fn)(void* ptr, void* user_data); + void* user_data; +} simgui_allocator_t; + +/* + simgui_logger + + Used in simgui_desc_t to provide a logging function. Please be aware + that without logging function, sokol-imgui will be completely + silent, e.g. it will not report errors, warnings and + validation layer messages. For maximum error verbosity, + compile in debug mode (e.g. NDEBUG *not* defined) and install + a logger (for instance the standard logging function from sokol_log.h). +*/ +typedef struct simgui_logger_t { + void (*func)( + const char* tag, // always "simgui" + uint32_t log_level, // 0=panic, 1=error, 2=warning, 3=info + uint32_t log_item_id, // SIMGUI_LOGITEM_* + const char* message_or_null, // a message string, may be nullptr in release mode + uint32_t line_nr, // line number in sokol_imgui.h + const char* filename_or_null, // source filename, may be nullptr in release mode + void* user_data); + void* user_data; +} simgui_logger_t; + +typedef struct simgui_desc_t { + int max_vertices; // default: 65536 + sg_pixel_format color_format; + sg_pixel_format depth_format; + int sample_count; + const char* ini_filename; + bool no_default_font; + bool disable_paste_override; // if true, don't send Ctrl-V on EVENTTYPE_CLIPBOARD_PASTED + bool disable_set_mouse_cursor; // if true, don't control the mouse cursor type via sapp_set_mouse_cursor() + bool disable_windows_resize_from_edges; // if true, only resize edges from the bottom right corner + bool write_alpha_channel; // if true, alpha values get written into the framebuffer + simgui_allocator_t allocator; // optional memory allocation overrides (default: malloc/free) + simgui_logger_t logger; // optional log function override +} simgui_desc_t; + +typedef struct simgui_frame_desc_t { + int width; + int height; + double delta_time; + float dpi_scale; +} simgui_frame_desc_t; + +typedef struct simgui_font_tex_desc_t { + sg_filter min_filter; + sg_filter mag_filter; +} simgui_font_tex_desc_t; + +SOKOL_IMGUI_API_DECL void simgui_setup(const simgui_desc_t* desc); +SOKOL_IMGUI_API_DECL void simgui_new_frame(const simgui_frame_desc_t* desc); +SOKOL_IMGUI_API_DECL void simgui_render(void); + +SOKOL_IMGUI_API_DECL uint64_t simgui_imtextureid(sg_view tex_view); +SOKOL_IMGUI_API_DECL uint64_t simgui_imtextureid_with_sampler(sg_view tex_view, sg_sampler smp); +SOKOL_IMGUI_API_DECL sg_view simgui_texture_view_from_imtextureid(uint64_t imtex_id); +SOKOL_IMGUI_API_DECL sg_sampler simgui_sampler_from_imtextureid(uint64_t imtex_id); + +SOKOL_IMGUI_API_DECL void simgui_add_focus_event(bool focus); +SOKOL_IMGUI_API_DECL void simgui_add_mouse_pos_event(float x, float y); +SOKOL_IMGUI_API_DECL void simgui_add_touch_pos_event(float x, float y); +SOKOL_IMGUI_API_DECL void simgui_add_mouse_button_event(int mouse_button, bool down); +SOKOL_IMGUI_API_DECL void simgui_add_mouse_wheel_event(float wheel_x, float wheel_y); +SOKOL_IMGUI_API_DECL void simgui_add_key_event(int imgui_key, bool down); +SOKOL_IMGUI_API_DECL void simgui_add_input_character(uint32_t c); +SOKOL_IMGUI_API_DECL void simgui_add_input_characters_utf8(const char* c); +SOKOL_IMGUI_API_DECL void simgui_add_touch_button_event(int mouse_button, bool down); + +#if !defined(SOKOL_IMGUI_NO_SOKOL_APP) +SOKOL_IMGUI_API_DECL bool simgui_handle_event(const sapp_event* ev); +SOKOL_IMGUI_API_DECL int simgui_map_keycode(sapp_keycode keycode); // returns ImGuiKey_* +#endif +SOKOL_IMGUI_API_DECL void simgui_shutdown(void); + +#ifdef __cplusplus +} // extern "C" + +// reference-based equivalents for C++ +inline void simgui_setup(const simgui_desc_t& desc) { return simgui_setup(&desc); } +inline void simgui_new_frame(const simgui_frame_desc_t& desc) { return simgui_new_frame(&desc); } + +#endif +#endif /* SOKOL_IMGUI_INCLUDED */ + +//-- IMPLEMENTATION ------------------------------------------------------------ +#ifdef SOKOL_IMGUI_IMPL +#define SOKOL_IMGUI_IMPL_INCLUDED (1) + +#ifndef SOKOL_IMGUI_CPREFIX +#define SOKOL_IMGUI_CPREFIX ig +#endif +#define _SIMGUI_CONCAT2(prefix, name) prefix ## name +#define _SIMGUI_CONCAT(prefix, name) _SIMGUI_CONCAT2(prefix, name) +#define _SIMGUI_CFUNC(name) _SIMGUI_CONCAT(SOKOL_IMGUI_CPREFIX, name) + +#if defined(SOKOL_MALLOC) || defined(SOKOL_CALLOC) || defined(SOKOL_FREE) +#error "SOKOL_MALLOC/CALLOC/FREE macros are no longer supported, please use simgui_desc_t.allocator to override memory allocation functions" +#endif + +#if defined(__cplusplus) + #if !defined(IMGUI_VERSION) + #error "Please include imgui.h before the sokol_imgui.h implementation" + #endif +#else + #if !defined(CIMGUI_API) + #error "Please include cimgui.h before the sokol_imgui.h implementation" + #endif +#endif + +#include // memset +#include // malloc/free + +#if defined(__EMSCRIPTEN__) && !defined(SOKOL_DUMMY_BACKEND) +#include +#endif + +#ifndef SOKOL_API_IMPL +#define SOKOL_API_IMPL +#endif +#ifndef SOKOL_DEBUG + #ifndef NDEBUG + #define SOKOL_DEBUG + #endif +#endif +#ifndef SOKOL_ASSERT + #include + #define SOKOL_ASSERT(c) assert(c) +#endif +#ifndef _SOKOL_PRIVATE + #if defined(__GNUC__) || defined(__clang__) + #define _SOKOL_PRIVATE __attribute__((unused)) static + #else + #define _SOKOL_PRIVATE static + #endif +#endif + +#define _SIMGUI_INIT_COOKIE (0xBABEBABE) + +// helper macros and constants +#define _simgui_def(val, def) (((val) == 0) ? (def) : (val)) + +// collisions with X11 headers +#if defined(Status) +#undef Status +#endif + +typedef struct { + ImVec2 disp_size; + uint8_t _pad_8[8]; +} _simgui_vs_params_t; + +typedef struct { + uint32_t init_cookie; + simgui_desc_t desc; + float cur_dpi_scale; + sg_buffer vbuf; + sg_buffer ibuf; + sg_sampler def_smp; // used as default sampler for user images + sg_shader def_shd; + sg_pipeline def_pip; + // separate shader and pipeline for unfilterable user images + sg_shader shd_unfilterable; + sg_pipeline pip_unfilterable; + sg_range vertices; + sg_range indices; + bool is_osx; +} _simgui_state_t; +static _simgui_state_t _simgui; + +//>#shdgen +#if defined(SOKOL_GLCORE) +static const uint8_t _simgui_shd_vs_source_glsl410[383] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x31,0x30,0x0a,0x0a,0x75,0x6e, + 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x73,0x5f,0x70,0x61, + 0x72,0x61,0x6d,0x73,0x5b,0x31,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28, + 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e, + 0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a, + 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20, + 0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x32,0x20,0x75,0x76, + 0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f, + 0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x74, + 0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, + 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x6f, + 0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c, + 0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d, + 0x20,0x32,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f, + 0x72,0x30,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69, + 0x6f,0x6e,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x28,0x28,0x70,0x6f,0x73,0x69, + 0x74,0x69,0x6f,0x6e,0x20,0x2f,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73, + 0x5b,0x30,0x5d,0x2e,0x78,0x79,0x29,0x20,0x2d,0x20,0x76,0x65,0x63,0x32,0x28,0x30, + 0x2e,0x35,0x29,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x32,0x28,0x32,0x2e,0x30,0x2c, + 0x20,0x2d,0x32,0x2e,0x30,0x29,0x2c,0x20,0x30,0x2e,0x35,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x76,0x20,0x3d,0x20,0x74,0x65,0x78,0x63, + 0x6f,0x6f,0x72,0x64,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +static const uint8_t _simgui_shd_fs_source_glsl410[219] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x31,0x30,0x0a,0x0a,0x75,0x6e, + 0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20, + 0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, + 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f, + 0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74, + 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x32, + 0x20,0x75,0x76,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63, + 0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d, + 0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65, + 0x28,0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x2c,0x20,0x75,0x76,0x29,0x20,0x2a,0x20, + 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +#elif defined(SOKOL_GLES3) +static const uint8_t _simgui_shd_vs_source_glsl300es[344] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, + 0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x73, + 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x31,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f, + 0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29, + 0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f, + 0x6e,0x3b,0x0a,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x32,0x20,0x75,0x76,0x3b,0x0a, + 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20, + 0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x74,0x65,0x78, + 0x63,0x6f,0x6f,0x72,0x64,0x30,0x3b,0x0a,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34, + 0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, + 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x69,0x6e,0x20, + 0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x0a,0x76,0x6f, + 0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x76,0x65, + 0x63,0x34,0x28,0x28,0x28,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x2f,0x20, + 0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x29, + 0x20,0x2d,0x20,0x76,0x65,0x63,0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2a,0x20, + 0x76,0x65,0x63,0x32,0x28,0x32,0x2e,0x30,0x2c,0x20,0x2d,0x32,0x2e,0x30,0x29,0x2c, + 0x20,0x30,0x2e,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x75,0x76,0x20,0x3d,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f, + 0x72,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +static const uint8_t _simgui_shd_fs_source_glsl300es[250] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, + 0x70,0x72,0x65,0x63,0x69,0x73,0x69,0x6f,0x6e,0x20,0x6d,0x65,0x64,0x69,0x75,0x6d, + 0x70,0x20,0x66,0x6c,0x6f,0x61,0x74,0x3b,0x0a,0x70,0x72,0x65,0x63,0x69,0x73,0x69, + 0x6f,0x6e,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x69,0x6e,0x74,0x3b,0x0a,0x0a,0x75, + 0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x3b,0x0a, + 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x68,0x69,0x67,0x68,0x70,0x20, + 0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b, + 0x0a,0x69,0x6e,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65,0x63,0x32,0x20,0x75, + 0x76,0x3b,0x0a,0x69,0x6e,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65,0x63,0x34, + 0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61, + 0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28, + 0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x2c,0x20,0x75,0x76,0x29,0x20,0x2a,0x20,0x63, + 0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +#elif defined(SOKOL_METAL) +static const uint8_t _simgui_shd_vs_bytecode_metal_macos[3130] = { + 0x4d,0x54,0x4c,0x42,0x01,0x80,0x02,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x3a,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x58,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x7b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xd7,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x3b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x12,0x01,0x00,0x00,0x00,0x00,0x00,0x00, + 0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1a,0x01,0x00,0x00,0x00,0x00,0x00,0x00, + 0x20,0x0b,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x7b,0x00,0x00,0x00, + 0x4e,0x41,0x4d,0x45,0x06,0x00,0x6d,0x61,0x69,0x6e,0x30,0x00,0x54,0x59,0x50,0x45, + 0x01,0x00,0x00,0x48,0x41,0x53,0x48,0x20,0x00,0x2e,0x36,0xeb,0x18,0xad,0xb5,0x12, + 0x9e,0xe9,0x2f,0x44,0xcb,0x90,0xf0,0x69,0xa7,0x46,0xfe,0xdd,0x80,0x09,0x9e,0xf1, + 0x64,0xdd,0xb9,0x77,0xc5,0x65,0xea,0x33,0xfe,0x4d,0x44,0x53,0x5a,0x08,0x00,0x20, + 0x0b,0x00,0x00,0x00,0x00,0x00,0x00,0x4f,0x46,0x46,0x54,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x56,0x45,0x52,0x53,0x08,0x00,0x01,0x00,0x0b,0x00,0x01, + 0x00,0x02,0x00,0x45,0x4e,0x44,0x54,0x37,0x00,0x00,0x00,0x56,0x41,0x54,0x54,0x22, + 0x00,0x03,0x00,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x00,0x00,0x80,0x74,0x65, + 0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x00,0x01,0x80,0x63,0x6f,0x6c,0x6f,0x72,0x30, + 0x00,0x02,0x80,0x56,0x41,0x54,0x59,0x05,0x00,0x03,0x00,0x04,0x04,0x06,0x45,0x4e, + 0x44,0x54,0x04,0x00,0x00,0x00,0x45,0x4e,0x44,0x54,0xde,0xc0,0x17,0x0b,0x00,0x00, + 0x00,0x00,0x14,0x00,0x00,0x00,0x08,0x0b,0x00,0x00,0xff,0xff,0xff,0xff,0x42,0x43, + 0xc0,0xde,0x21,0x0c,0x00,0x00,0xbf,0x02,0x00,0x00,0x0b,0x82,0x20,0x00,0x02,0x00, + 0x00,0x00,0x12,0x00,0x00,0x00,0x07,0x81,0x23,0x91,0x41,0xc8,0x04,0x49,0x06,0x10, + 0x32,0x39,0x92,0x01,0x84,0x0c,0x25,0x05,0x08,0x19,0x1e,0x04,0x8b,0x62,0x80,0x10, + 0x45,0x02,0x42,0x92,0x0b,0x42,0x84,0x10,0x32,0x14,0x38,0x08,0x18,0x49,0x0a,0x32, + 0x44,0x24,0x48,0x0a,0x90,0x21,0x23,0xc4,0x52,0x80,0x0c,0x19,0x21,0x72,0x24,0x07, + 0xc8,0x08,0x11,0x62,0xa8,0xa0,0xa8,0x40,0xc6,0xf0,0x01,0x00,0x00,0x00,0x51,0x18, + 0x00,0x00,0x68,0x00,0x00,0x00,0x1b,0x7e,0x24,0xf8,0xff,0xff,0xff,0xff,0x01,0x90, + 0x00,0x8a,0x08,0x07,0x78,0x80,0x07,0x79,0x78,0x07,0x7c,0x68,0x03,0x73,0xa8,0x07, + 0x77,0x18,0x87,0x36,0x30,0x07,0x78,0x68,0x83,0x76,0x08,0x07,0x7a,0x40,0x07,0x80, + 0x1e,0xe4,0xa1,0x1e,0xca,0x01,0x20,0xda,0x21,0x1d,0xdc,0xa1,0x0d,0xd8,0xa1,0x1c, + 0xce,0x21,0x1c,0xd8,0xa1,0x0d,0xec,0xa1,0x1c,0xc6,0x81,0x1e,0xde,0x41,0x1e,0xda, + 0xe0,0x1e,0xd2,0x81,0x1c,0xe8,0x01,0x1d,0x80,0x38,0x90,0x03,0x3c,0x00,0x06,0x77, + 0x78,0x87,0x36,0x10,0x87,0x7a,0x48,0x07,0x76,0xa0,0x87,0x74,0x70,0x87,0x79,0x00, + 0x08,0x77,0x78,0x87,0x36,0x30,0x07,0x79,0x08,0x87,0x76,0x28,0x87,0x36,0x80,0x87, + 0x77,0x48,0x07,0x77,0xa0,0x87,0x72,0x90,0x87,0x36,0x28,0x07,0x76,0x48,0x87,0x76, + 0x00,0xe8,0x41,0x1e,0xea,0xa1,0x1c,0x00,0xc2,0x1d,0xde,0xa1,0x0d,0xcc,0x41,0x1e, + 0xc2,0xa1,0x1d,0xca,0xa1,0x0d,0xe0,0xe1,0x1d,0xd2,0xc1,0x1d,0xe8,0xa1,0x1c,0xe4, + 0xa1,0x0d,0xca,0x81,0x1d,0xd2,0xa1,0x1d,0xda,0xc0,0x1d,0xde,0xc1,0x1d,0xda,0x80, + 0x1d,0xca,0x21,0x1c,0xcc,0x01,0xa0,0x07,0x79,0xa8,0x87,0x72,0x00,0x08,0x77,0x78, + 0x87,0x36,0x48,0x07,0x77,0x30,0x87,0x79,0x68,0x03,0x73,0x80,0x87,0x36,0x68,0x87, + 0x70,0xa0,0x07,0x74,0x00,0xe8,0x41,0x1e,0xea,0xa1,0x1c,0x00,0xc2,0x1d,0xde,0xa1, + 0x0d,0xdc,0x21,0x1c,0xdc,0x61,0x1e,0xda,0xc0,0x1c,0xe0,0xa1,0x0d,0xda,0x21,0x1c, + 0xe8,0x01,0x1d,0x00,0x7a,0x90,0x87,0x7a,0x28,0x07,0x80,0x70,0x87,0x77,0x68,0x83, + 0x79,0x48,0x87,0x73,0x70,0x87,0x72,0x20,0x87,0x36,0xd0,0x87,0x72,0x90,0x87,0x77, + 0x98,0x87,0x36,0x30,0x07,0x78,0x68,0x83,0x76,0x08,0x07,0x7a,0x40,0x07,0x80,0x1e, + 0xe4,0xa1,0x1e,0xca,0x01,0x20,0xdc,0xe1,0x1d,0xda,0x80,0x1e,0xe4,0x21,0x1c,0xe0, + 0x01,0x1e,0xd2,0xc1,0x1d,0xce,0xa1,0x0d,0xda,0x21,0x1c,0xe8,0x01,0x1d,0x00,0x7a, + 0x90,0x87,0x7a,0x28,0x07,0x80,0x98,0x07,0x7a,0x08,0x87,0x71,0x58,0x87,0x36,0x80, + 0x07,0x79,0x78,0x07,0x7a,0x28,0x87,0x71,0xa0,0x87,0x77,0x90,0x87,0x36,0x10,0x87, + 0x7a,0x30,0x07,0x73,0x28,0x07,0x79,0x68,0x83,0x79,0x48,0x07,0x7d,0x28,0x07,0x00, + 0x0f,0x00,0xa2,0x1e,0xdc,0x61,0x1e,0xc2,0xc1,0x1c,0xca,0xa1,0x0d,0xcc,0x01,0x1e, + 0xda,0xa0,0x1d,0xc2,0x81,0x1e,0xd0,0x01,0xa0,0x07,0x79,0xa8,0x87,0x72,0x00,0x36, + 0x18,0x02,0x01,0x2c,0x40,0x05,0x49,0x18,0x00,0x00,0x01,0x00,0x00,0x00,0x13,0x84, + 0x40,0x00,0x89,0x20,0x00,0x00,0x16,0x00,0x00,0x00,0x32,0x22,0x08,0x09,0x20,0x64, + 0x85,0x04,0x13,0x22,0xa4,0x84,0x04,0x13,0x22,0xe3,0x84,0xa1,0x90,0x14,0x12,0x4c, + 0x88,0x8c,0x0b,0x84,0x84,0x4c,0x10,0x3c,0x33,0x00,0xc3,0x08,0x02,0x30,0x8c,0x40, + 0x00,0x76,0x08,0x91,0x83,0xa4,0x29,0xa2,0x84,0xc9,0xaf,0xa4,0xff,0x01,0x22,0x80, + 0x91,0x50,0x10,0x83,0x08,0x84,0x50,0x8a,0x89,0x90,0x22,0x1b,0x08,0x98,0x23,0x00, + 0x83,0x14,0xc8,0x39,0x02,0x50,0x18,0x44,0x08,0x84,0x61,0x04,0x22,0x19,0x01,0x00, + 0x00,0x00,0x13,0xb2,0x70,0x48,0x07,0x79,0xb0,0x03,0x3a,0x68,0x83,0x70,0x80,0x07, + 0x78,0x60,0x87,0x72,0x68,0x83,0x76,0x08,0x87,0x71,0x78,0x87,0x79,0xc0,0x87,0x38, + 0x80,0x03,0x37,0x88,0x03,0x39,0x70,0x03,0x38,0xd8,0x70,0x1b,0xe5,0xd0,0x06,0xf0, + 0xa0,0x07,0x76,0x40,0x07,0x7a,0x60,0x07,0x74,0xa0,0x07,0x76,0x40,0x07,0x6d,0x90, + 0x0e,0x71,0xa0,0x07,0x78,0xa0,0x07,0x78,0xd0,0x06,0xe9,0x80,0x07,0x7a,0x80,0x07, + 0x7a,0x80,0x07,0x6d,0x90,0x0e,0x71,0x60,0x07,0x7a,0x10,0x07,0x76,0xa0,0x07,0x71, + 0x60,0x07,0x6d,0x90,0x0e,0x73,0x20,0x07,0x7a,0x30,0x07,0x72,0xa0,0x07,0x73,0x20, + 0x07,0x6d,0x90,0x0e,0x76,0x40,0x07,0x7a,0x60,0x07,0x74,0xa0,0x07,0x76,0x40,0x07, + 0x6d,0x60,0x0e,0x73,0x20,0x07,0x7a,0x30,0x07,0x72,0xa0,0x07,0x73,0x20,0x07,0x6d, + 0x60,0x0e,0x76,0x40,0x07,0x7a,0x60,0x07,0x74,0xa0,0x07,0x76,0x40,0x07,0x6d,0x60, + 0x0f,0x71,0x60,0x07,0x7a,0x10,0x07,0x76,0xa0,0x07,0x71,0x60,0x07,0x6d,0x60,0x0f, + 0x72,0x40,0x07,0x7a,0x30,0x07,0x72,0xa0,0x07,0x73,0x20,0x07,0x6d,0x60,0x0f,0x73, + 0x20,0x07,0x7a,0x30,0x07,0x72,0xa0,0x07,0x73,0x20,0x07,0x6d,0x60,0x0f,0x74,0x80, + 0x07,0x7a,0x60,0x07,0x74,0xa0,0x07,0x76,0x40,0x07,0x6d,0x60,0x0f,0x76,0x40,0x07, + 0x7a,0x60,0x07,0x74,0xa0,0x07,0x76,0x40,0x07,0x6d,0x60,0x0f,0x79,0x60,0x07,0x7a, + 0x10,0x07,0x72,0x80,0x07,0x7a,0x10,0x07,0x72,0x80,0x07,0x6d,0x60,0x0f,0x71,0x20, + 0x07,0x78,0xa0,0x07,0x71,0x20,0x07,0x78,0xa0,0x07,0x71,0x20,0x07,0x78,0xd0,0x06, + 0xf6,0x10,0x07,0x79,0x20,0x07,0x7a,0x20,0x07,0x75,0x60,0x07,0x7a,0x20,0x07,0x75, + 0x60,0x07,0x6d,0x60,0x0f,0x72,0x50,0x07,0x76,0xa0,0x07,0x72,0x50,0x07,0x76,0xa0, + 0x07,0x72,0x50,0x07,0x76,0xd0,0x06,0xf6,0x50,0x07,0x71,0x20,0x07,0x7a,0x50,0x07, + 0x71,0x20,0x07,0x7a,0x50,0x07,0x71,0x20,0x07,0x6d,0x60,0x0f,0x71,0x00,0x07,0x72, + 0x40,0x07,0x7a,0x10,0x07,0x70,0x20,0x07,0x74,0xa0,0x07,0x71,0x00,0x07,0x72,0x40, + 0x07,0x6d,0xe0,0x0e,0x78,0xa0,0x07,0x71,0x60,0x07,0x7a,0x30,0x07,0x72,0x30,0x84, + 0x39,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0xc8,0x02,0x01,0x00,0x00,0x09,0x00, + 0x00,0x00,0x32,0x1e,0x98,0x10,0x19,0x11,0x4c,0x90,0x8c,0x09,0x26,0x47,0xc6,0x04, + 0x43,0xca,0x12,0x18,0x01,0x28,0x82,0x82,0x28,0x84,0xb2,0x28,0x03,0xda,0x11,0x00, + 0xd2,0xb1,0x04,0x8d,0x00,0x00,0x79,0x18,0x00,0x00,0xe9,0x00,0x00,0x00,0x1a,0x03, + 0x4c,0x10,0x97,0x29,0xa2,0x25,0x10,0xab,0x32,0xb9,0xb9,0xb4,0x37,0xb7,0x21,0x46, + 0x32,0x20,0x80,0x92,0x50,0xb9,0x1b,0x43,0x0b,0x93,0xfb,0x9a,0x4b,0xd3,0x2b,0x1b, + 0x62,0x24,0x01,0x22,0x24,0x05,0xe3,0x20,0x08,0x0e,0x8e,0xad,0x0c,0xa4,0xad,0x8c, + 0x2e,0x8c,0x0d,0xc4,0xae,0x4c,0x6e,0x2e,0xed,0xcd,0x0d,0x64,0x46,0x06,0x46,0x66, + 0xc6,0x05,0x07,0x67,0x06,0x04,0xa5,0xad,0x8c,0x2e,0x8c,0xcd,0xac,0xac,0x65,0x46, + 0x06,0x46,0x66,0xc6,0x05,0x07,0x67,0x26,0x65,0x88,0x80,0x10,0x43,0x8c,0x24,0x48, + 0x8c,0x44,0x60,0xd1,0x54,0x46,0x17,0xc6,0x36,0x04,0x41,0x8e,0x24,0x48,0x86,0x44, + 0xe0,0x16,0x96,0x26,0xe7,0x32,0xf6,0xd6,0x06,0x97,0xc6,0x56,0xe6,0x42,0x56,0xe6, + 0xf6,0x26,0xd7,0x36,0xf7,0x45,0x96,0x36,0x17,0x26,0xc6,0x56,0x36,0x44,0x40,0x12, + 0x72,0x61,0x69,0x72,0x2e,0x63,0x6f,0x6d,0x70,0x69,0x6c,0x65,0x2e,0x66,0x61,0x73, + 0x74,0x5f,0x6d,0x61,0x74,0x68,0x5f,0x65,0x6e,0x61,0x62,0x6c,0x65,0x43,0x04,0x64, + 0x61,0x19,0x84,0xa5,0xc9,0xb9,0x8c,0xbd,0xb5,0xc1,0xa5,0xb1,0x95,0xb9,0x98,0xc9, + 0x85,0xb5,0x95,0x89,0xd5,0x99,0x99,0x95,0xc9,0x7d,0x99,0x95,0xd1,0x8d,0xa1,0x7d, + 0x91,0xa5,0xcd,0x85,0x89,0xb1,0x95,0x0d,0x11,0x90,0x86,0x51,0x58,0x9a,0x9c,0x8b, + 0x5d,0x99,0x1c,0x5d,0x19,0xde,0xd7,0x5b,0x1d,0x1d,0x5c,0x1d,0x1d,0x97,0xba,0xb9, + 0x32,0x39,0x14,0xb6,0xb7,0x31,0x37,0x98,0x14,0x46,0x61,0x69,0x72,0x2e,0x61,0x72, + 0x67,0x5f,0x74,0x79,0x70,0x65,0x5f,0x6e,0x61,0x6d,0x65,0x34,0xcc,0xd8,0xde,0xc2, + 0xe8,0x64,0xc8,0x84,0xa5,0xc9,0xb9,0x84,0xc9,0x9d,0x7d,0xb9,0x85,0xb5,0x95,0x51, + 0xa8,0xb3,0x1b,0xc2,0x20,0x0f,0x02,0x21,0x11,0x22,0x21,0x13,0x42,0x71,0xa9,0x9b, + 0x2b,0x93,0x43,0x61,0x7b,0x1b,0x73,0x8b,0x49,0xa1,0x61,0xc6,0xf6,0x16,0x46,0x47, + 0xc3,0x62,0xec,0x8d,0xed,0x4d,0x6e,0x08,0x83,0x3c,0x88,0x85,0x44,0xc8,0x85,0x4c, + 0x08,0x46,0x26,0x2c,0x4d,0xce,0x05,0xee,0x6d,0x2e,0x8d,0x2e,0xed,0xcd,0x8d,0xcb, + 0x19,0xdb,0x17,0xd4,0xdb,0x5c,0x1a,0x5d,0xda,0x9b,0xdb,0x10,0x05,0xd1,0x90,0x08, + 0xb9,0x90,0x09,0xd9,0x86,0x18,0x48,0x85,0x64,0x08,0x47,0x28,0x2c,0x4d,0xce,0xc5, + 0xae,0x4c,0x8e,0xae,0x0c,0xef,0x2b,0xcd,0x0d,0xae,0x8e,0x8e,0x52,0x58,0x9a,0x9c, + 0x0b,0xdb,0xdb,0x58,0x18,0x5d,0xda,0x9b,0xdb,0x57,0x9a,0x1b,0x59,0x19,0x1e,0xbd, + 0xb3,0x32,0xb7,0x32,0xb9,0x30,0xba,0x32,0x32,0x94,0xaf,0xaf,0xb0,0x34,0xb9,0x2f, + 0x38,0xb6,0xb0,0xb1,0x32,0xb4,0x37,0x36,0xb2,0x32,0xb9,0xaf,0xaf,0x14,0x22,0x70, + 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x43,0xa8,0x44,0x40,0x3c,0xe4,0x4b,0x84,0x24, + 0x40,0xc0,0x00,0x89,0x10,0x09,0x99,0x90,0x30,0x60,0x42,0x57,0x86,0x37,0xf6,0xf6, + 0x26,0x47,0x06,0x33,0x84,0x4a,0x02,0xc4,0x43,0xbe,0x24,0x48,0x02,0x04,0x0c,0x90, + 0x08,0x91,0x90,0x09,0x19,0x03,0x1a,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x43,0xa8,0x64, + 0x40,0x3c,0xe4,0x4b,0x86,0x24,0x40,0xc0,0x00,0x89,0x90,0x0b,0x99,0x90,0x32,0xa0, + 0x12,0x96,0x26,0xe7,0x22,0x56,0x67,0x66,0x56,0x26,0xc7,0x27,0x2c,0x4d,0xce,0x45, + 0xac,0xce,0xcc,0xac,0x4c,0xee,0x6b,0x2e,0x4d,0xaf,0x8c,0x48,0x58,0x9a,0x9c,0x8b, + 0x5c,0x59,0x18,0x19,0xa9,0xb0,0x34,0x39,0x97,0x39,0x3a,0xb9,0xba,0x31,0xba,0x2f, + 0xba,0x3c,0xb8,0xb2,0xaf,0x34,0x37,0xb3,0x37,0x26,0x64,0x69,0x73,0x70,0x5f,0x73, + 0x69,0x7a,0x65,0x43,0x94,0x44,0x48,0x88,0x44,0x40,0x24,0x64,0x0d,0x18,0x85,0xa5, + 0xc9,0xb9,0x84,0xc9,0x9d,0x7d,0xd1,0xe5,0xc1,0x95,0x7d,0xcd,0xa5,0xe9,0x95,0xf1, + 0x0a,0x4b,0x93,0x73,0x09,0x93,0x3b,0xfb,0xa2,0xcb,0x83,0x2b,0xfb,0x0a,0x63,0x4b, + 0x3b,0x73,0xfb,0x9a,0x4b,0xd3,0x2b,0x63,0x62,0x37,0xf7,0x05,0x17,0x26,0x17,0xd6, + 0x36,0xc7,0xe1,0x4b,0x46,0x66,0x08,0x19,0x24,0x07,0x72,0x06,0x08,0x1a,0x24,0x04, + 0xf2,0x25,0x42,0x12,0x20,0x69,0x80,0xa8,0x01,0xc2,0x06,0x48,0x1b,0x24,0x04,0xe2, + 0x06,0x09,0x81,0x44,0xc8,0x1b,0x20,0x13,0x02,0x07,0x43,0x10,0x44,0x0c,0x10,0x32, + 0x40,0xcc,0x00,0x89,0x83,0x21,0xc6,0x01,0x20,0x1d,0x22,0x07,0x7c,0xde,0xda,0xdc, + 0xd2,0xe0,0xde,0xe8,0xca,0xdc,0xe8,0x40,0xc6,0xd0,0xc2,0xe4,0xf8,0x4c,0xa5,0xb5, + 0xc1,0xb1,0x95,0x81,0x0c,0xad,0xac,0x80,0x50,0x09,0x05,0x05,0x0d,0x11,0x90,0x3a, + 0x18,0x62,0x20,0x74,0x80,0xd8,0xc1,0x82,0x0c,0x31,0x90,0x3b,0x40,0xee,0x60,0x41, + 0x46,0x44,0xec,0xc0,0x0e,0xf6,0xd0,0x0e,0x6e,0xd0,0x0e,0xef,0x40,0x0e,0xf5,0xc0, + 0x0e,0xe5,0xe0,0x06,0xe6,0xc0,0x0e,0xe1,0x70,0x0e,0xf3,0x30,0x45,0x08,0x86,0x11, + 0x0a,0x3b,0xb0,0x83,0x3d,0xb4,0x83,0x1b,0xa4,0x03,0x39,0x94,0x83,0x3b,0xd0,0xc3, + 0x94,0xa0,0x18,0xb1,0x84,0x43,0x3a,0xc8,0x83,0x1b,0xd8,0x43,0x39,0xc8,0xc3,0x3c, + 0xa4,0xc3,0x3b,0xb8,0xc3,0x94,0xc0,0x18,0x41,0x85,0x43,0x3a,0xc8,0x83,0x1b,0xb0, + 0x43,0x38,0xb8,0xc3,0x39,0xd4,0x43,0x38,0x9c,0x43,0x39,0xfc,0x82,0x3d,0x94,0x83, + 0x3c,0xcc,0x43,0x3a,0xbc,0x83,0x3b,0x4c,0x09,0x90,0x11,0x53,0x38,0xa4,0x83,0x3c, + 0xb8,0xc1,0x38,0xbc,0x43,0x3b,0xc0,0x43,0x3a,0xb0,0x43,0x39,0xfc,0xc2,0x3b,0xc0, + 0x03,0x3d,0xa4,0xc3,0x3b,0xb8,0xc3,0x3c,0x4c,0x19,0x14,0xc6,0x19,0xa1,0x84,0x43, + 0x3a,0xc8,0x83,0x1b,0xd8,0x43,0x39,0xc8,0x03,0x3d,0x94,0x03,0x3e,0x4c,0x09,0xe6, + 0x00,0x00,0x79,0x18,0x00,0x00,0xa5,0x00,0x00,0x00,0x33,0x08,0x80,0x1c,0xc4,0xe1, + 0x1c,0x66,0x14,0x01,0x3d,0x88,0x43,0x38,0x84,0xc3,0x8c,0x42,0x80,0x07,0x79,0x78, + 0x07,0x73,0x98,0x71,0x0c,0xe6,0x00,0x0f,0xed,0x10,0x0e,0xf4,0x80,0x0e,0x33,0x0c, + 0x42,0x1e,0xc2,0xc1,0x1d,0xce,0xa1,0x1c,0x66,0x30,0x05,0x3d,0x88,0x43,0x38,0x84, + 0x83,0x1b,0xcc,0x03,0x3d,0xc8,0x43,0x3d,0x8c,0x03,0x3d,0xcc,0x78,0x8c,0x74,0x70, + 0x07,0x7b,0x08,0x07,0x79,0x48,0x87,0x70,0x70,0x07,0x7a,0x70,0x03,0x76,0x78,0x87, + 0x70,0x20,0x87,0x19,0xcc,0x11,0x0e,0xec,0x90,0x0e,0xe1,0x30,0x0f,0x6e,0x30,0x0f, + 0xe3,0xf0,0x0e,0xf0,0x50,0x0e,0x33,0x10,0xc4,0x1d,0xde,0x21,0x1c,0xd8,0x21,0x1d, + 0xc2,0x61,0x1e,0x66,0x30,0x89,0x3b,0xbc,0x83,0x3b,0xd0,0x43,0x39,0xb4,0x03,0x3c, + 0xbc,0x83,0x3c,0x84,0x03,0x3b,0xcc,0xf0,0x14,0x76,0x60,0x07,0x7b,0x68,0x07,0x37, + 0x68,0x87,0x72,0x68,0x07,0x37,0x80,0x87,0x70,0x90,0x87,0x70,0x60,0x07,0x76,0x28, + 0x07,0x76,0xf8,0x05,0x76,0x78,0x87,0x77,0x80,0x87,0x5f,0x08,0x87,0x71,0x18,0x87, + 0x72,0x98,0x87,0x79,0x98,0x81,0x2c,0xee,0xf0,0x0e,0xee,0xe0,0x0e,0xf5,0xc0,0x0e, + 0xec,0x30,0x03,0x62,0xc8,0xa1,0x1c,0xe4,0xa1,0x1c,0xcc,0xa1,0x1c,0xe4,0xa1,0x1c, + 0xdc,0x61,0x1c,0xca,0x21,0x1c,0xc4,0x81,0x1d,0xca,0x61,0x06,0xd6,0x90,0x43,0x39, + 0xc8,0x43,0x39,0x98,0x43,0x39,0xc8,0x43,0x39,0xb8,0xc3,0x38,0x94,0x43,0x38,0x88, + 0x03,0x3b,0x94,0xc3,0x2f,0xbc,0x83,0x3c,0xfc,0x82,0x3b,0xd4,0x03,0x3b,0xb0,0xc3, + 0x0c,0xc7,0x69,0x87,0x70,0x58,0x87,0x72,0x70,0x83,0x74,0x68,0x07,0x78,0x60,0x87, + 0x74,0x18,0x87,0x74,0xa0,0x87,0x19,0xce,0x53,0x0f,0xee,0x00,0x0f,0xf2,0x50,0x0e, + 0xe4,0x90,0x0e,0xe3,0x40,0x0f,0xe1,0x20,0x0e,0xec,0x50,0x0e,0x33,0x20,0x28,0x1d, + 0xdc,0xc1,0x1e,0xc2,0x41,0x1e,0xd2,0x21,0x1c,0xdc,0x81,0x1e,0xdc,0xe0,0x1c,0xe4, + 0xe1,0x1d,0xea,0x01,0x1e,0x66,0x18,0x51,0x38,0xb0,0x43,0x3a,0x9c,0x83,0x3b,0xcc, + 0x50,0x24,0x76,0x60,0x07,0x7b,0x68,0x07,0x37,0x60,0x87,0x77,0x78,0x07,0x78,0x98, + 0x51,0x4c,0xf4,0x90,0x0f,0xf0,0x50,0x0e,0x33,0x1e,0x6a,0x1e,0xca,0x61,0x1c,0xe8, + 0x21,0x1d,0xde,0xc1,0x1d,0x7e,0x01,0x1e,0xe4,0xa1,0x1c,0xcc,0x21,0x1d,0xf0,0x61, + 0x06,0x54,0x85,0x83,0x38,0xcc,0xc3,0x3b,0xb0,0x43,0x3d,0xd0,0x43,0x39,0xfc,0xc2, + 0x3c,0xe4,0x43,0x3b,0x88,0xc3,0x3b,0xb0,0xc3,0x8c,0xc5,0x0a,0x87,0x79,0x98,0x87, + 0x77,0x18,0x87,0x74,0x08,0x07,0x7a,0x28,0x07,0x72,0x98,0x81,0x5c,0xe3,0x10,0x0e, + 0xec,0xc0,0x0e,0xe5,0x50,0x0e,0xf3,0x30,0x23,0xc1,0xd2,0x41,0x1e,0xe4,0xe1,0x17, + 0xd8,0xe1,0x1d,0xde,0x01,0x1e,0x66,0x48,0x19,0x3b,0xb0,0x83,0x3d,0xb4,0x83,0x1b, + 0x84,0xc3,0x38,0x8c,0x43,0x39,0xcc,0xc3,0x3c,0xb8,0xc1,0x39,0xc8,0xc3,0x3b,0xd4, + 0x03,0x3c,0xcc,0x48,0xb4,0x71,0x08,0x07,0x76,0x60,0x07,0x71,0x08,0x87,0x71,0x58, + 0x87,0x19,0xdb,0xc6,0x0e,0xec,0x60,0x0f,0xed,0xe0,0x06,0xf0,0x20,0x0f,0xe5,0x30, + 0x0f,0xe5,0x20,0x0f,0xf6,0x50,0x0e,0x6e,0x10,0x0e,0xe3,0x30,0x0e,0xe5,0x30,0x0f, + 0xf3,0xe0,0x06,0xe9,0xe0,0x0e,0xe4,0x50,0x0e,0xf8,0x30,0x23,0xe2,0xec,0x61,0x1c, + 0xc2,0x81,0x1d,0xd8,0xe1,0x17,0xec,0x21,0x1d,0xe6,0x21,0x1d,0xc4,0x21,0x1d,0xd8, + 0x21,0x1d,0xe8,0x21,0x1f,0x66,0x20,0x9d,0x3b,0xbc,0x43,0x3d,0xb8,0x03,0x39,0x94, + 0x83,0x39,0xcc,0x58,0xbc,0x70,0x70,0x07,0x77,0x78,0x07,0x7a,0x08,0x07,0x7a,0x48, + 0x87,0x77,0x70,0x87,0x19,0xce,0x87,0x0e,0xe5,0x10,0x0e,0xf0,0x10,0x0e,0xec,0xc0, + 0x0e,0xef,0x30,0x0e,0xf3,0x90,0x0e,0xf4,0x50,0x0e,0x33,0x28,0x30,0x08,0x87,0x74, + 0x90,0x07,0x37,0x30,0x87,0x7a,0x70,0x87,0x71,0xa0,0x87,0x74,0x78,0x07,0x77,0xf8, + 0x85,0x73,0x90,0x87,0x77,0xa8,0x07,0x78,0x98,0x07,0x00,0x00,0x00,0x00,0x71,0x20, + 0x00,0x00,0x02,0x00,0x00,0x00,0x06,0x50,0x30,0x00,0xd2,0xd0,0x00,0x00,0x61,0x20, + 0x00,0x00,0x23,0x00,0x00,0x00,0x13,0x04,0x41,0x2c,0x10,0x00,0x00,0x00,0x11,0x00, + 0x00,0x00,0xd4,0x63,0x11,0x40,0x60,0x1c,0x73,0x10,0x42,0x00,0x41,0x94,0x33,0x00, + 0x14,0x63,0x09,0x20,0x08,0x82,0xf0,0x2f,0x80,0x20,0x08,0xc2,0xbf,0x30,0x96,0x00, + 0x82,0x20,0x08,0x82,0x01,0x08,0x82,0x20,0x08,0x0e,0x33,0x00,0x24,0x73,0x10,0x18, + 0x76,0x59,0x34,0x33,0x00,0x04,0x63,0x04,0x20,0x08,0x82,0xf8,0x37,0x46,0x00,0x82, + 0x20,0x08,0x7f,0x33,0x00,0x00,0xe3,0x0d,0x4c,0x74,0x51,0x40,0x2c,0x0a,0xe8,0x63, + 0xc1,0x02,0x1f,0x0b,0x16,0xf9,0x0c,0x32,0x04,0xcb,0x33,0xc8,0x10,0x2c,0xd1,0x6c, + 0xc3,0x52,0x01,0xb3,0x0d,0x41,0x15,0xcc,0x36,0x04,0x83,0x90,0x41,0x40,0x0c,0x00, + 0x00,0x00,0x02,0x00,0x00,0x00,0x5b,0x86,0x20,0xc0,0x03,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; +static const uint8_t _simgui_shd_fs_bytecode_metal_macos[3047] = { + 0x4d,0x54,0x4c,0x42,0x01,0x80,0x02,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0xe7,0x0b,0x00,0x00,0x00,0x00,0x00,0x00,0x58,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x7b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xd7,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xdf,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe7,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x0b,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x7b,0x00,0x00,0x00, + 0x4e,0x41,0x4d,0x45,0x06,0x00,0x6d,0x61,0x69,0x6e,0x30,0x00,0x54,0x59,0x50,0x45, + 0x01,0x00,0x01,0x48,0x41,0x53,0x48,0x20,0x00,0xef,0x50,0xdf,0x57,0x8a,0xf8,0xb0, + 0x2f,0x0a,0xb5,0x85,0x86,0x49,0x87,0x52,0x6c,0xc0,0xe1,0x3f,0x4c,0x67,0x21,0x34, + 0xcb,0xe8,0xfc,0x6c,0x88,0xd8,0x32,0xef,0xfb,0x4d,0x44,0x53,0x5a,0x08,0x00,0x00, + 0x0b,0x00,0x00,0x00,0x00,0x00,0x00,0x4f,0x46,0x46,0x54,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x56,0x45,0x52,0x53,0x08,0x00,0x01,0x00,0x0b,0x00,0x01, + 0x00,0x02,0x00,0x45,0x4e,0x44,0x54,0x04,0x00,0x00,0x00,0x45,0x4e,0x44,0x54,0x04, + 0x00,0x00,0x00,0x45,0x4e,0x44,0x54,0xde,0xc0,0x17,0x0b,0x00,0x00,0x00,0x00,0x14, + 0x00,0x00,0x00,0xe0,0x0a,0x00,0x00,0xff,0xff,0xff,0xff,0x42,0x43,0xc0,0xde,0x21, + 0x0c,0x00,0x00,0xb5,0x02,0x00,0x00,0x0b,0x82,0x20,0x00,0x02,0x00,0x00,0x00,0x12, + 0x00,0x00,0x00,0x07,0x81,0x23,0x91,0x41,0xc8,0x04,0x49,0x06,0x10,0x32,0x39,0x92, + 0x01,0x84,0x0c,0x25,0x05,0x08,0x19,0x1e,0x04,0x8b,0x62,0x80,0x14,0x45,0x02,0x42, + 0x92,0x0b,0x42,0xa4,0x10,0x32,0x14,0x38,0x08,0x18,0x49,0x0a,0x32,0x44,0x24,0x48, + 0x0a,0x90,0x21,0x23,0xc4,0x52,0x80,0x0c,0x19,0x21,0x72,0x24,0x07,0xc8,0x48,0x11, + 0x62,0xa8,0xa0,0xa8,0x40,0xc6,0xf0,0x01,0x00,0x00,0x00,0x51,0x18,0x00,0x00,0x74, + 0x00,0x00,0x00,0x1b,0xc2,0x24,0xf8,0xff,0xff,0xff,0xff,0x01,0x60,0x00,0x09,0xa8, + 0x88,0x70,0x80,0x07,0x78,0x90,0x87,0x77,0xc0,0x87,0x36,0x30,0x87,0x7a,0x70,0x87, + 0x71,0x68,0x03,0x73,0x80,0x87,0x36,0x68,0x87,0x70,0xa0,0x07,0x74,0x00,0xe8,0x41, + 0x1e,0xea,0xa1,0x1c,0x00,0xa2,0x1d,0xd2,0xc1,0x1d,0xda,0x80,0x1d,0xca,0xe1,0x1c, + 0xc2,0x81,0x1d,0xda,0xc0,0x1e,0xca,0x61,0x1c,0xe8,0xe1,0x1d,0xe4,0xa1,0x0d,0xee, + 0x21,0x1d,0xc8,0x81,0x1e,0xd0,0x01,0x88,0x03,0x39,0xc0,0x03,0x60,0x70,0x87,0x77, + 0x68,0x03,0x71,0xa8,0x87,0x74,0x60,0x07,0x7a,0x48,0x07,0x77,0x98,0x07,0x80,0x70, + 0x87,0x77,0x68,0x03,0x73,0x90,0x87,0x70,0x68,0x87,0x72,0x68,0x03,0x78,0x78,0x87, + 0x74,0x70,0x07,0x7a,0x28,0x07,0x79,0x68,0x83,0x72,0x60,0x87,0x74,0x68,0x07,0x80, + 0x1e,0xe4,0xa1,0x1e,0xca,0x01,0x20,0xdc,0xe1,0x1d,0xda,0xc0,0x1c,0xe4,0x21,0x1c, + 0xda,0xa1,0x1c,0xda,0x00,0x1e,0xde,0x21,0x1d,0xdc,0x81,0x1e,0xca,0x41,0x1e,0xda, + 0xa0,0x1c,0xd8,0x21,0x1d,0xda,0xa1,0x0d,0xdc,0xe1,0x1d,0xdc,0xa1,0x0d,0xd8,0xa1, + 0x1c,0xc2,0xc1,0x1c,0x00,0x7a,0x90,0x87,0x7a,0x28,0x07,0x80,0x70,0x87,0x77,0x68, + 0x83,0x74,0x70,0x07,0x73,0x98,0x87,0x36,0x30,0x07,0x78,0x68,0x83,0x76,0x08,0x07, + 0x7a,0x40,0x07,0x80,0x1e,0xe4,0xa1,0x1e,0xca,0x01,0x20,0xdc,0xe1,0x1d,0xda,0xc0, + 0x1d,0xc2,0xc1,0x1d,0xe6,0xa1,0x0d,0xcc,0x01,0x1e,0xda,0xa0,0x1d,0xc2,0x81,0x1e, + 0xd0,0x01,0xa0,0x07,0x79,0xa8,0x87,0x72,0x00,0x08,0x77,0x78,0x87,0x36,0x98,0x87, + 0x74,0x38,0x07,0x77,0x28,0x07,0x72,0x68,0x03,0x7d,0x28,0x07,0x79,0x78,0x87,0x79, + 0x68,0x03,0x73,0x80,0x87,0x36,0x68,0x87,0x70,0xa0,0x07,0x74,0x00,0xe8,0x41,0x1e, + 0xea,0xa1,0x1c,0x00,0xc2,0x1d,0xde,0xa1,0x0d,0xe8,0x41,0x1e,0xc2,0x01,0x1e,0xe0, + 0x21,0x1d,0xdc,0xe1,0x1c,0xda,0xa0,0x1d,0xc2,0x81,0x1e,0xd0,0x01,0xa0,0x07,0x79, + 0xa8,0x87,0x72,0x00,0x88,0x79,0xa0,0x87,0x70,0x18,0x87,0x75,0x68,0x03,0x78,0x90, + 0x87,0x77,0xa0,0x87,0x72,0x18,0x07,0x7a,0x78,0x07,0x79,0x68,0x03,0x71,0xa8,0x07, + 0x73,0x30,0x87,0x72,0x90,0x87,0x36,0x98,0x87,0x74,0xd0,0x87,0x72,0x00,0xf0,0x00, + 0x20,0xea,0xc1,0x1d,0xe6,0x21,0x1c,0xcc,0xa1,0x1c,0xda,0xc0,0x1c,0xe0,0xa1,0x0d, + 0xda,0x21,0x1c,0xe8,0x01,0x1d,0x00,0x7a,0x90,0x87,0x7a,0x28,0x07,0x60,0x83,0x21, + 0x0c,0xc0,0x02,0x54,0x1b,0x8c,0x81,0x00,0x16,0xa0,0xda,0x80,0x10,0xff,0xff,0xff, + 0xff,0x3f,0x00,0x0c,0x20,0x01,0xd5,0x06,0xa3,0x08,0x80,0x05,0xa8,0x36,0x18,0x86, + 0x00,0x2c,0x40,0xb5,0x01,0x39,0xfe,0xff,0xff,0xff,0x7f,0x00,0x18,0x40,0x02,0x2a, + 0x00,0x00,0x00,0x49,0x18,0x00,0x00,0x04,0x00,0x00,0x00,0x13,0x86,0x40,0x18,0x26, + 0x0c,0x44,0x61,0x4c,0x18,0x8e,0xc2,0x00,0x00,0x00,0x00,0x89,0x20,0x00,0x00,0x1d, + 0x00,0x00,0x00,0x32,0x22,0x48,0x09,0x20,0x64,0x85,0x04,0x93,0x22,0xa4,0x84,0x04, + 0x93,0x22,0xe3,0x84,0xa1,0x90,0x14,0x12,0x4c,0x8a,0x8c,0x0b,0x84,0xa4,0x4c,0x10, + 0x48,0x33,0x00,0xc3,0x08,0x04,0x60,0x83,0x30,0x8c,0x20,0x00,0x47,0x49,0x53,0x44, + 0x09,0x93,0xff,0x4f,0xc4,0x35,0x51,0x11,0xf1,0xdb,0xc3,0x3f,0x8d,0x11,0x00,0x83, + 0x08,0x44,0x70,0x91,0x34,0x45,0x94,0x30,0xf9,0xbf,0x04,0x30,0xcf,0x42,0x44,0xff, + 0x34,0x46,0x00,0x0c,0x22,0x18,0x42,0x29,0xc4,0x08,0xe5,0x10,0x9a,0x23,0x08,0xe6, + 0x08,0xc0,0x60,0x18,0x41,0x58,0x0a,0x12,0xca,0x19,0x8a,0x29,0x40,0x6d,0x20,0x20, + 0x05,0xd6,0x08,0x00,0x00,0x00,0x00,0x13,0xb2,0x70,0x48,0x07,0x79,0xb0,0x03,0x3a, + 0x68,0x83,0x70,0x80,0x07,0x78,0x60,0x87,0x72,0x68,0x83,0x76,0x08,0x87,0x71,0x78, + 0x87,0x79,0xc0,0x87,0x38,0x80,0x03,0x37,0x88,0x03,0x39,0x70,0x03,0x38,0xd8,0x70, + 0x1b,0xe5,0xd0,0x06,0xf0,0xa0,0x07,0x76,0x40,0x07,0x7a,0x60,0x07,0x74,0xa0,0x07, + 0x76,0x40,0x07,0x6d,0x90,0x0e,0x71,0xa0,0x07,0x78,0xa0,0x07,0x78,0xd0,0x06,0xe9, + 0x80,0x07,0x7a,0x80,0x07,0x7a,0x80,0x07,0x6d,0x90,0x0e,0x71,0x60,0x07,0x7a,0x10, + 0x07,0x76,0xa0,0x07,0x71,0x60,0x07,0x6d,0x90,0x0e,0x73,0x20,0x07,0x7a,0x30,0x07, + 0x72,0xa0,0x07,0x73,0x20,0x07,0x6d,0x90,0x0e,0x76,0x40,0x07,0x7a,0x60,0x07,0x74, + 0xa0,0x07,0x76,0x40,0x07,0x6d,0x60,0x0e,0x73,0x20,0x07,0x7a,0x30,0x07,0x72,0xa0, + 0x07,0x73,0x20,0x07,0x6d,0x60,0x0e,0x76,0x40,0x07,0x7a,0x60,0x07,0x74,0xa0,0x07, + 0x76,0x40,0x07,0x6d,0x60,0x0f,0x71,0x60,0x07,0x7a,0x10,0x07,0x76,0xa0,0x07,0x71, + 0x60,0x07,0x6d,0x60,0x0f,0x72,0x40,0x07,0x7a,0x30,0x07,0x72,0xa0,0x07,0x73,0x20, + 0x07,0x6d,0x60,0x0f,0x73,0x20,0x07,0x7a,0x30,0x07,0x72,0xa0,0x07,0x73,0x20,0x07, + 0x6d,0x60,0x0f,0x74,0x80,0x07,0x7a,0x60,0x07,0x74,0xa0,0x07,0x76,0x40,0x07,0x6d, + 0x60,0x0f,0x76,0x40,0x07,0x7a,0x60,0x07,0x74,0xa0,0x07,0x76,0x40,0x07,0x6d,0x60, + 0x0f,0x79,0x60,0x07,0x7a,0x10,0x07,0x72,0x80,0x07,0x7a,0x10,0x07,0x72,0x80,0x07, + 0x6d,0x60,0x0f,0x71,0x20,0x07,0x78,0xa0,0x07,0x71,0x20,0x07,0x78,0xa0,0x07,0x71, + 0x20,0x07,0x78,0xd0,0x06,0xf6,0x10,0x07,0x79,0x20,0x07,0x7a,0x20,0x07,0x75,0x60, + 0x07,0x7a,0x20,0x07,0x75,0x60,0x07,0x6d,0x60,0x0f,0x72,0x50,0x07,0x76,0xa0,0x07, + 0x72,0x50,0x07,0x76,0xa0,0x07,0x72,0x50,0x07,0x76,0xd0,0x06,0xf6,0x50,0x07,0x71, + 0x20,0x07,0x7a,0x50,0x07,0x71,0x20,0x07,0x7a,0x50,0x07,0x71,0x20,0x07,0x6d,0x60, + 0x0f,0x71,0x00,0x07,0x72,0x40,0x07,0x7a,0x10,0x07,0x70,0x20,0x07,0x74,0xa0,0x07, + 0x71,0x00,0x07,0x72,0x40,0x07,0x6d,0xe0,0x0e,0x78,0xa0,0x07,0x71,0x60,0x07,0x7a, + 0x30,0x07,0x72,0x30,0x84,0x49,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x18,0xc2, + 0x38,0x40,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x64,0x81,0x00,0x00,0x00,0x00,0x08, + 0x00,0x00,0x00,0x32,0x1e,0x98,0x10,0x19,0x11,0x4c,0x90,0x8c,0x09,0x26,0x47,0xc6, + 0x04,0x43,0x5a,0x23,0x00,0x25,0x50,0x04,0x85,0x50,0x16,0x65,0x40,0x70,0x2c,0x41, + 0x23,0x00,0x00,0x79,0x18,0x00,0x00,0xd3,0x00,0x00,0x00,0x1a,0x03,0x4c,0x10,0x97, + 0x29,0xa2,0x25,0x10,0xab,0x32,0xb9,0xb9,0xb4,0x37,0xb7,0x21,0xc6,0x42,0x3c,0x00, + 0x84,0x50,0xb9,0x1b,0x43,0x0b,0x93,0xfb,0x9a,0x4b,0xd3,0x2b,0x1b,0x62,0x2c,0xc3, + 0x23,0x2c,0x05,0xe3,0x20,0x08,0x0e,0x8e,0xad,0x0c,0xa4,0xad,0x8c,0x2e,0x8c,0x0d, + 0xc4,0xae,0x4c,0x6e,0x2e,0xed,0xcd,0x0d,0x64,0x46,0x06,0x46,0x66,0xc6,0x05,0x07, + 0x67,0x06,0x04,0xa5,0xad,0x8c,0x2e,0x8c,0xcd,0xac,0xac,0x65,0x46,0x06,0x46,0x66, + 0xc6,0x05,0x07,0x67,0x26,0x65,0x88,0xf0,0x10,0x43,0x8c,0x65,0x58,0x8c,0x45,0x60, + 0xd1,0x54,0x46,0x17,0xc6,0x36,0x04,0x79,0x8e,0x65,0x58,0x88,0x45,0xe0,0x16,0x96, + 0x26,0xe7,0x32,0xf6,0xd6,0x06,0x97,0xc6,0x56,0xe6,0x42,0x56,0xe6,0xf6,0x26,0xd7, + 0x36,0xf7,0x45,0x96,0x36,0x17,0x26,0xc6,0x56,0x36,0x44,0x78,0x12,0x72,0x61,0x69, + 0x72,0x2e,0x63,0x6f,0x6d,0x70,0x69,0x6c,0x65,0x2e,0x66,0x61,0x73,0x74,0x5f,0x6d, + 0x61,0x74,0x68,0x5f,0x65,0x6e,0x61,0x62,0x6c,0x65,0x43,0x84,0x67,0x61,0x19,0x84, + 0xa5,0xc9,0xb9,0x8c,0xbd,0xb5,0xc1,0xa5,0xb1,0x95,0xb9,0x98,0xc9,0x85,0xb5,0x95, + 0x89,0xd5,0x99,0x99,0x95,0xc9,0x7d,0x99,0x95,0xd1,0x8d,0xa1,0x7d,0x91,0xa5,0xcd, + 0x85,0x89,0xb1,0x95,0x0d,0x11,0x9e,0x86,0x51,0x58,0x9a,0x9c,0x8b,0x5c,0x99,0x1b, + 0x59,0x99,0xdc,0x17,0x5d,0x98,0xdc,0x59,0x19,0x1d,0xa3,0xb0,0x34,0x39,0x97,0x30, + 0xb9,0xb3,0x2f,0xba,0x3c,0xb8,0xb2,0x2f,0xb7,0xb0,0xb6,0x32,0x1a,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x64,0xc2,0xd2,0xe4,0x5c,0xc2,0xe4,0xce,0xbe,0xdc,0xc2,0xda,0xca, + 0xa8,0x98,0xc9,0x85,0x9d,0x7d,0x8d,0xbd,0xb1,0xbd,0xc9,0x0d,0x71,0x9e,0x67,0x11, + 0x16,0xe1,0x81,0x9e,0xe8,0x91,0x9e,0x69,0x88,0xf0,0x50,0x94,0xc2,0xd2,0xe4,0x5c, + 0xcc,0xe4,0xc2,0xce,0xda,0xca,0xdc,0xe8,0xbe,0xd2,0xdc,0xe0,0xea,0xe8,0xb8,0xd4, + 0xcd,0x95,0xc9,0xa1,0xb0,0xbd,0x8d,0xb9,0xc1,0xa4,0x50,0x09,0x4b,0x93,0x73,0x19, + 0x2b,0x73,0xa3,0x2b,0x93,0xe3,0x13,0x96,0x26,0xe7,0x02,0x57,0x26,0x37,0x07,0x57, + 0x36,0x46,0x97,0x66,0x57,0x46,0xc3,0x8c,0xed,0x2d,0x8c,0x4e,0x86,0x42,0x9d,0xdd, + 0x10,0x69,0x11,0x1e,0xeb,0xb9,0x1e,0xec,0xc9,0x1e,0xe8,0xd1,0x1e,0xe9,0xd9,0xb8, + 0xd4,0xcd,0x95,0xc9,0xa1,0xb0,0xbd,0x8d,0xb9,0xc5,0xa4,0xb0,0x18,0x7b,0x63,0x7b, + 0x93,0x1b,0x22,0x2d,0xc3,0x63,0x3d,0xdd,0x83,0x3d,0xd9,0x03,0x3d,0xd1,0x23,0x3d, + 0x1e,0x97,0xb0,0x34,0x39,0x17,0xba,0x32,0x3c,0xba,0x3a,0xb9,0x32,0x4a,0x61,0x69, + 0x72,0x2e,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x5f,0x69,0x6e,0x64,0x65,0x78, + 0x54,0xc2,0xd2,0xe4,0x5c,0xe6,0xc2,0xda,0xe0,0xd8,0xca,0x88,0xd1,0x95,0xe1,0xd1, + 0xd5,0xc9,0x95,0xc9,0x90,0xf1,0x98,0xb1,0xbd,0x85,0xd1,0xb1,0x80,0xcc,0x85,0xb5, + 0xc1,0xb1,0x95,0xf9,0x70,0xa0,0x2b,0xc3,0x1b,0x42,0x2d,0xc4,0x03,0x06,0x4f,0x18, + 0x2c,0xc2,0x32,0x3c,0x62,0xf0,0x40,0xcf,0x18,0x3c,0xd2,0x43,0x06,0x5c,0xc2,0xd2, + 0xe4,0x5c,0xe6,0xc2,0xda,0xe0,0xd8,0xca,0xe4,0x78,0xcc,0x85,0xb5,0xc1,0xb1,0x95, + 0xc9,0x71,0x98,0x6b,0x83,0x1b,0x22,0x2d,0xc7,0x63,0x06,0x4f,0x18,0x2c,0xc2,0x32, + 0x3c,0xd0,0x73,0x06,0x8f,0xf4,0xa0,0xc1,0x10,0xe4,0xe1,0x9e,0xef,0x29,0x83,0x27, + 0x0d,0x86,0x18,0x09,0xf0,0x54,0x8f,0x1a,0xf0,0x0a,0x4b,0x93,0x6b,0x09,0x63,0x4b, + 0x0b,0x9b,0x6b,0x99,0x1b,0x7b,0x83,0x2b,0x9b,0x43,0x69,0x0b,0x4b,0x73,0x83,0x49, + 0x19,0x42,0x3c,0x6d,0xf0,0xb0,0x01,0xb1,0xb0,0x34,0xb9,0x96,0x30,0xb6,0xb4,0xb0, + 0xb9,0x96,0xb9,0xb1,0x37,0xb8,0xb2,0x16,0xba,0x32,0x3c,0xba,0x3a,0xb9,0xb2,0xb9, + 0x21,0xc6,0xf3,0x06,0x4f,0x1b,0x3c,0x6e,0x40,0x2c,0x2c,0x4d,0xae,0x25,0x8c,0x2d, + 0x2d,0x6c,0xae,0x65,0x6e,0xec,0x0d,0xae,0xac,0x65,0x2e,0xac,0x0d,0x8e,0xad,0x4c, + 0x6e,0x6e,0x88,0xf1,0xc4,0xc1,0xd3,0x06,0x0f,0x1c,0x0c,0x21,0x9e,0x37,0x78,0xe2, + 0x60,0x44,0xc4,0x0e,0xec,0x60,0x0f,0xed,0xe0,0x06,0xed,0xf0,0x0e,0xe4,0x50,0x0f, + 0xec,0x50,0x0e,0x6e,0x60,0x0e,0xec,0x10,0x0e,0xe7,0x30,0x0f,0x53,0x84,0x60,0x18, + 0xa1,0xb0,0x03,0x3b,0xd8,0x43,0x3b,0xb8,0x41,0x3a,0x90,0x43,0x39,0xb8,0x03,0x3d, + 0x4c,0x09,0x8a,0x11,0x4b,0x38,0xa4,0x83,0x3c,0xb8,0x81,0x3d,0x94,0x83,0x3c,0xcc, + 0x43,0x3a,0xbc,0x83,0x3b,0x4c,0x09,0x8c,0x11,0x54,0x38,0xa4,0x83,0x3c,0xb8,0x01, + 0x3b,0x84,0x83,0x3b,0x9c,0x43,0x3d,0x84,0xc3,0x39,0x94,0xc3,0x2f,0xd8,0x43,0x39, + 0xc8,0xc3,0x3c,0xa4,0xc3,0x3b,0xb8,0xc3,0x94,0x00,0x19,0x31,0x85,0x43,0x3a,0xc8, + 0x83,0x1b,0x8c,0xc3,0x3b,0xb4,0x03,0x3c,0xa4,0x03,0x3b,0x94,0xc3,0x2f,0xbc,0x03, + 0x3c,0xd0,0x43,0x3a,0xbc,0x83,0x3b,0xcc,0xc3,0x94,0x41,0x61,0x9c,0x11,0x4c,0x38, + 0xa4,0x83,0x3c,0xb8,0x81,0x39,0xc8,0x43,0x38,0x9c,0x43,0x3b,0x94,0x83,0x3b,0xd0, + 0xc3,0x94,0x60,0x0d,0x00,0x00,0x00,0x79,0x18,0x00,0x00,0xa5,0x00,0x00,0x00,0x33, + 0x08,0x80,0x1c,0xc4,0xe1,0x1c,0x66,0x14,0x01,0x3d,0x88,0x43,0x38,0x84,0xc3,0x8c, + 0x42,0x80,0x07,0x79,0x78,0x07,0x73,0x98,0x71,0x0c,0xe6,0x00,0x0f,0xed,0x10,0x0e, + 0xf4,0x80,0x0e,0x33,0x0c,0x42,0x1e,0xc2,0xc1,0x1d,0xce,0xa1,0x1c,0x66,0x30,0x05, + 0x3d,0x88,0x43,0x38,0x84,0x83,0x1b,0xcc,0x03,0x3d,0xc8,0x43,0x3d,0x8c,0x03,0x3d, + 0xcc,0x78,0x8c,0x74,0x70,0x07,0x7b,0x08,0x07,0x79,0x48,0x87,0x70,0x70,0x07,0x7a, + 0x70,0x03,0x76,0x78,0x87,0x70,0x20,0x87,0x19,0xcc,0x11,0x0e,0xec,0x90,0x0e,0xe1, + 0x30,0x0f,0x6e,0x30,0x0f,0xe3,0xf0,0x0e,0xf0,0x50,0x0e,0x33,0x10,0xc4,0x1d,0xde, + 0x21,0x1c,0xd8,0x21,0x1d,0xc2,0x61,0x1e,0x66,0x30,0x89,0x3b,0xbc,0x83,0x3b,0xd0, + 0x43,0x39,0xb4,0x03,0x3c,0xbc,0x83,0x3c,0x84,0x03,0x3b,0xcc,0xf0,0x14,0x76,0x60, + 0x07,0x7b,0x68,0x07,0x37,0x68,0x87,0x72,0x68,0x07,0x37,0x80,0x87,0x70,0x90,0x87, + 0x70,0x60,0x07,0x76,0x28,0x07,0x76,0xf8,0x05,0x76,0x78,0x87,0x77,0x80,0x87,0x5f, + 0x08,0x87,0x71,0x18,0x87,0x72,0x98,0x87,0x79,0x98,0x81,0x2c,0xee,0xf0,0x0e,0xee, + 0xe0,0x0e,0xf5,0xc0,0x0e,0xec,0x30,0x03,0x62,0xc8,0xa1,0x1c,0xe4,0xa1,0x1c,0xcc, + 0xa1,0x1c,0xe4,0xa1,0x1c,0xdc,0x61,0x1c,0xca,0x21,0x1c,0xc4,0x81,0x1d,0xca,0x61, + 0x06,0xd6,0x90,0x43,0x39,0xc8,0x43,0x39,0x98,0x43,0x39,0xc8,0x43,0x39,0xb8,0xc3, + 0x38,0x94,0x43,0x38,0x88,0x03,0x3b,0x94,0xc3,0x2f,0xbc,0x83,0x3c,0xfc,0x82,0x3b, + 0xd4,0x03,0x3b,0xb0,0xc3,0x0c,0xc7,0x69,0x87,0x70,0x58,0x87,0x72,0x70,0x83,0x74, + 0x68,0x07,0x78,0x60,0x87,0x74,0x18,0x87,0x74,0xa0,0x87,0x19,0xce,0x53,0x0f,0xee, + 0x00,0x0f,0xf2,0x50,0x0e,0xe4,0x90,0x0e,0xe3,0x40,0x0f,0xe1,0x20,0x0e,0xec,0x50, + 0x0e,0x33,0x20,0x28,0x1d,0xdc,0xc1,0x1e,0xc2,0x41,0x1e,0xd2,0x21,0x1c,0xdc,0x81, + 0x1e,0xdc,0xe0,0x1c,0xe4,0xe1,0x1d,0xea,0x01,0x1e,0x66,0x18,0x51,0x38,0xb0,0x43, + 0x3a,0x9c,0x83,0x3b,0xcc,0x50,0x24,0x76,0x60,0x07,0x7b,0x68,0x07,0x37,0x60,0x87, + 0x77,0x78,0x07,0x78,0x98,0x51,0x4c,0xf4,0x90,0x0f,0xf0,0x50,0x0e,0x33,0x1e,0x6a, + 0x1e,0xca,0x61,0x1c,0xe8,0x21,0x1d,0xde,0xc1,0x1d,0x7e,0x01,0x1e,0xe4,0xa1,0x1c, + 0xcc,0x21,0x1d,0xf0,0x61,0x06,0x54,0x85,0x83,0x38,0xcc,0xc3,0x3b,0xb0,0x43,0x3d, + 0xd0,0x43,0x39,0xfc,0xc2,0x3c,0xe4,0x43,0x3b,0x88,0xc3,0x3b,0xb0,0xc3,0x8c,0xc5, + 0x0a,0x87,0x79,0x98,0x87,0x77,0x18,0x87,0x74,0x08,0x07,0x7a,0x28,0x07,0x72,0x98, + 0x81,0x5c,0xe3,0x10,0x0e,0xec,0xc0,0x0e,0xe5,0x50,0x0e,0xf3,0x30,0x23,0xc1,0xd2, + 0x41,0x1e,0xe4,0xe1,0x17,0xd8,0xe1,0x1d,0xde,0x01,0x1e,0x66,0x48,0x19,0x3b,0xb0, + 0x83,0x3d,0xb4,0x83,0x1b,0x84,0xc3,0x38,0x8c,0x43,0x39,0xcc,0xc3,0x3c,0xb8,0xc1, + 0x39,0xc8,0xc3,0x3b,0xd4,0x03,0x3c,0xcc,0x48,0xb4,0x71,0x08,0x07,0x76,0x60,0x07, + 0x71,0x08,0x87,0x71,0x58,0x87,0x19,0xdb,0xc6,0x0e,0xec,0x60,0x0f,0xed,0xe0,0x06, + 0xf0,0x20,0x0f,0xe5,0x30,0x0f,0xe5,0x20,0x0f,0xf6,0x50,0x0e,0x6e,0x10,0x0e,0xe3, + 0x30,0x0e,0xe5,0x30,0x0f,0xf3,0xe0,0x06,0xe9,0xe0,0x0e,0xe4,0x50,0x0e,0xf8,0x30, + 0x23,0xe2,0xec,0x61,0x1c,0xc2,0x81,0x1d,0xd8,0xe1,0x17,0xec,0x21,0x1d,0xe6,0x21, + 0x1d,0xc4,0x21,0x1d,0xd8,0x21,0x1d,0xe8,0x21,0x1f,0x66,0x20,0x9d,0x3b,0xbc,0x43, + 0x3d,0xb8,0x03,0x39,0x94,0x83,0x39,0xcc,0x58,0xbc,0x70,0x70,0x07,0x77,0x78,0x07, + 0x7a,0x08,0x07,0x7a,0x48,0x87,0x77,0x70,0x87,0x19,0xce,0x87,0x0e,0xe5,0x10,0x0e, + 0xf0,0x10,0x0e,0xec,0xc0,0x0e,0xef,0x30,0x0e,0xf3,0x90,0x0e,0xf4,0x50,0x0e,0x33, + 0x28,0x30,0x08,0x87,0x74,0x90,0x07,0x37,0x30,0x87,0x7a,0x70,0x87,0x71,0xa0,0x87, + 0x74,0x78,0x07,0x77,0xf8,0x85,0x73,0x90,0x87,0x77,0xa8,0x07,0x78,0x98,0x07,0x00, + 0x00,0x00,0x00,0x71,0x20,0x00,0x00,0x08,0x00,0x00,0x00,0x16,0xb0,0x01,0x48,0xe4, + 0x4b,0x00,0xf3,0x2c,0xc4,0x3f,0x11,0xd7,0x44,0x45,0xc4,0x6f,0x0f,0x7e,0x85,0x17, + 0xb7,0x6d,0x00,0x05,0x03,0x20,0x0d,0x0d,0x00,0x00,0x00,0x61,0x20,0x00,0x00,0x11, + 0x00,0x00,0x00,0x13,0x04,0x41,0x2c,0x10,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0xc4, + 0x46,0x00,0x48,0x8d,0x00,0xd4,0x00,0x89,0x19,0x00,0x02,0x23,0x00,0x00,0x00,0x23, + 0x06,0xca,0x10,0x44,0x87,0x91,0x0c,0x05,0x11,0x58,0x90,0xc8,0x67,0xb6,0x81,0x08, + 0x80,0x0c,0x02,0x62,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x5b,0x06,0xe0,0x90,0x03, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; +static const uint8_t _simgui_shd_vs_bytecode_metal_ios[3402] = { + 0x4d,0x54,0x4c,0x42,0x01,0x00,0x02,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x4a,0x0d,0x00,0x00,0x00,0x00,0x00,0x00,0x58,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x7b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xd7,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x3b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x12,0x01,0x00,0x00,0x00,0x00,0x00,0x00, + 0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1a,0x01,0x00,0x00,0x00,0x00,0x00,0x00, + 0x30,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x7b,0x00,0x00,0x00, + 0x4e,0x41,0x4d,0x45,0x06,0x00,0x6d,0x61,0x69,0x6e,0x30,0x00,0x54,0x59,0x50,0x45, + 0x01,0x00,0x00,0x48,0x41,0x53,0x48,0x20,0x00,0x10,0xea,0x9b,0x86,0x1e,0x6b,0x5c, + 0x0c,0xda,0xe0,0xf8,0x3c,0x7c,0x3b,0x0c,0xef,0x83,0x8f,0x2c,0xc3,0x83,0xe1,0x41, + 0x8f,0x60,0x8a,0x88,0xa0,0xe3,0xe2,0xcd,0x49,0x4d,0x44,0x53,0x5a,0x08,0x00,0x30, + 0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x4f,0x46,0x46,0x54,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x56,0x45,0x52,0x53,0x08,0x00,0x02,0x00,0x00,0x00,0x02, + 0x00,0x00,0x00,0x45,0x4e,0x44,0x54,0x37,0x00,0x00,0x00,0x56,0x41,0x54,0x54,0x22, + 0x00,0x03,0x00,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x00,0x00,0x80,0x74,0x65, + 0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x00,0x01,0x80,0x63,0x6f,0x6c,0x6f,0x72,0x30, + 0x00,0x02,0x80,0x56,0x41,0x54,0x59,0x05,0x00,0x03,0x00,0x04,0x04,0x06,0x45,0x4e, + 0x44,0x54,0x04,0x00,0x00,0x00,0x45,0x4e,0x44,0x54,0xde,0xc0,0x17,0x0b,0x00,0x00, + 0x00,0x00,0x14,0x00,0x00,0x00,0x10,0x0c,0x00,0x00,0xff,0xff,0xff,0xff,0x42,0x43, + 0xc0,0xde,0x35,0x14,0x00,0x00,0x03,0x00,0x00,0x00,0x62,0x0c,0x30,0x24,0x80,0x10, + 0x05,0xc8,0x14,0x00,0x00,0x00,0x21,0x0c,0x00,0x00,0xfc,0x02,0x00,0x00,0x0b,0x82, + 0x20,0x00,0x02,0x00,0x00,0x00,0x13,0x00,0x00,0x00,0x07,0x81,0x23,0x91,0x41,0xc8, + 0x04,0x49,0x06,0x10,0x32,0x39,0x92,0x01,0x84,0x0c,0x25,0x05,0x08,0x19,0x1e,0x04, + 0x8b,0x62,0x80,0x10,0x45,0x02,0x42,0x92,0x0b,0x42,0x84,0x10,0x32,0x14,0x38,0x08, + 0x18,0x4b,0x0a,0x32,0x42,0x88,0x48,0x90,0x14,0x20,0x43,0x46,0x88,0xa5,0x00,0x19, + 0x32,0x42,0xe4,0x48,0x0e,0x90,0x11,0x22,0xc4,0x50,0x41,0x51,0x81,0x8c,0xe1,0x83, + 0xe5,0x8a,0x04,0x21,0x46,0x06,0x51,0x18,0x00,0x00,0x71,0x00,0x00,0x00,0x1b,0xc2, + 0x24,0xf8,0xff,0xff,0xff,0xff,0x01,0x80,0x03,0x40,0x02,0x28,0x22,0x1c,0xe0,0x01, + 0x1e,0xe4,0xe1,0x1d,0xf0,0xa1,0x0d,0xcc,0xa1,0x1e,0xdc,0x61,0x1c,0xda,0xc0,0x1c, + 0xe0,0xa1,0x0d,0xda,0x21,0x1c,0xe8,0x01,0x1d,0x00,0x7a,0x90,0x87,0x7a,0x28,0x07, + 0x80,0x68,0x87,0x74,0x70,0x87,0x36,0x60,0x87,0x72,0x38,0x87,0x70,0x60,0x87,0x36, + 0xb0,0x87,0x72,0x18,0x07,0x7a,0x78,0x07,0x79,0x68,0x83,0x7b,0x48,0x07,0x72,0xa0, + 0x07,0x74,0x00,0xe2,0x40,0x0e,0xf0,0x00,0x18,0xdc,0xe1,0x1d,0xda,0x40,0x1c,0xea, + 0x21,0x1d,0xd8,0x81,0x1e,0xd2,0xc1,0x1d,0xe6,0x01,0x20,0xdc,0xe1,0x1d,0xda,0xc0, + 0x1c,0xe4,0x21,0x1c,0xda,0xa1,0x1c,0xda,0x00,0x1e,0xde,0x21,0x1d,0xdc,0x81,0x1e, + 0xca,0x41,0x1e,0xda,0xa0,0x1c,0xd8,0x21,0x1d,0xda,0x01,0xa0,0x07,0x79,0xa8,0x87, + 0x72,0x00,0x08,0x77,0x78,0x87,0x36,0x30,0x07,0x79,0x08,0x87,0x76,0x28,0x87,0x36, + 0x80,0x87,0x77,0x48,0x07,0x77,0xa0,0x87,0x72,0x90,0x87,0x36,0x28,0x07,0x76,0x48, + 0x87,0x76,0x68,0x03,0x77,0x78,0x07,0x77,0x68,0x03,0x76,0x28,0x87,0x70,0x30,0x07, + 0x80,0x1e,0xe4,0xa1,0x1e,0xca,0x01,0x20,0xdc,0xe1,0x1d,0xda,0x20,0x1d,0xdc,0xc1, + 0x1c,0xe6,0xa1,0x0d,0xcc,0x01,0x1e,0xda,0xa0,0x1d,0xc2,0x81,0x1e,0xd0,0x01,0xa0, + 0x07,0x79,0xa8,0x87,0x72,0x00,0x08,0x77,0x78,0x87,0x36,0x70,0x87,0x70,0x70,0x87, + 0x79,0x68,0x03,0x73,0x80,0x87,0x36,0x68,0x87,0x70,0xa0,0x07,0x74,0x00,0xe8,0x41, + 0x1e,0xea,0xa1,0x1c,0x00,0xc2,0x1d,0xde,0xa1,0x0d,0xe6,0x21,0x1d,0xce,0xc1,0x1d, + 0xca,0x81,0x1c,0xda,0x40,0x1f,0xca,0x41,0x1e,0xde,0x61,0x1e,0xda,0xc0,0x1c,0xe0, + 0xa1,0x0d,0xda,0x21,0x1c,0xe8,0x01,0x1d,0x00,0x7a,0x90,0x87,0x7a,0x28,0x07,0x80, + 0x70,0x87,0x77,0x68,0x03,0x7a,0x90,0x87,0x70,0x80,0x07,0x78,0x48,0x07,0x77,0x38, + 0x87,0x36,0x68,0x87,0x70,0xa0,0x07,0x74,0x00,0xe8,0x41,0x1e,0xea,0xa1,0x1c,0x00, + 0x62,0x1e,0xe8,0x21,0x1c,0xc6,0x61,0x1d,0xda,0x00,0x1e,0xe4,0xe1,0x1d,0xe8,0xa1, + 0x1c,0xc6,0x81,0x1e,0xde,0x41,0x1e,0xda,0x40,0x1c,0xea,0xc1,0x1c,0xcc,0xa1,0x1c, + 0xe4,0xa1,0x0d,0xe6,0x21,0x1d,0xf4,0xa1,0x1c,0x00,0x3c,0x00,0x88,0x7a,0x70,0x87, + 0x79,0x08,0x07,0x73,0x28,0x87,0x36,0x30,0x07,0x78,0x68,0x83,0x76,0x08,0x07,0x7a, + 0x40,0x07,0x80,0x1e,0xe4,0xa1,0x1e,0xca,0x01,0xd8,0xe0,0x09,0x04,0xb0,0x00,0x55, + 0x90,0x06,0xc8,0x10,0x0e,0xe9,0x20,0x0f,0x6d,0x20,0x0e,0xf5,0x60,0x0e,0xe6,0x50, + 0x0e,0xf2,0xd0,0x06,0xee,0xf0,0x0e,0x6d,0x10,0x0e,0xec,0x90,0x0e,0xe1,0x30,0x0f, + 0x00,0x00,0x49,0x18,0x00,0x00,0x01,0x00,0x00,0x00,0x13,0x84,0x40,0x00,0x89,0x20, + 0x00,0x00,0x16,0x00,0x00,0x00,0x32,0x22,0x08,0x09,0x20,0x64,0x85,0x04,0x13,0x22, + 0xa4,0x84,0x04,0x13,0x22,0xe3,0x84,0xa1,0x90,0x14,0x12,0x4c,0x88,0x8c,0x0b,0x84, + 0x84,0x4c,0x10,0x3c,0x33,0x00,0xc3,0x08,0x02,0x30,0x8c,0x40,0x00,0x76,0x08,0x91, + 0x83,0xa4,0x29,0xa2,0x84,0xc9,0xaf,0xa4,0xff,0x01,0x22,0x80,0x91,0x50,0x10,0x83, + 0x08,0x84,0x50,0x8a,0x89,0x90,0x22,0x1b,0x08,0x98,0x23,0x00,0x83,0x14,0xc8,0x39, + 0x02,0x50,0x18,0x44,0x08,0x84,0x61,0x04,0x22,0x19,0x01,0x00,0x00,0x00,0x13,0xaa, + 0x70,0x48,0x07,0x79,0xb0,0x03,0x3a,0x68,0x83,0x70,0x80,0x07,0x78,0x60,0x87,0x72, + 0x68,0x83,0x74,0x78,0x87,0x79,0x88,0x83,0x38,0x70,0x03,0x38,0x70,0x03,0x38,0xd8, + 0x70,0x1b,0xe5,0xd0,0x06,0xf0,0xa0,0x07,0x76,0x40,0x07,0x7a,0x60,0x07,0x74,0xa0, + 0x07,0x76,0x40,0x07,0x6d,0x90,0x0e,0x71,0xa0,0x07,0x78,0xa0,0x07,0x78,0xd0,0x06, + 0xe9,0x80,0x07,0x7a,0x80,0x07,0x7a,0x80,0x07,0x6d,0x90,0x0e,0x71,0x60,0x07,0x7a, + 0x10,0x07,0x76,0xa0,0x07,0x71,0x60,0x07,0x6d,0x90,0x0e,0x73,0x20,0x07,0x7a,0x30, + 0x07,0x72,0xa0,0x07,0x73,0x20,0x07,0x6d,0x90,0x0e,0x76,0x40,0x07,0x7a,0x60,0x07, + 0x74,0xa0,0x07,0x76,0x40,0x07,0x6d,0x60,0x0e,0x73,0x20,0x07,0x7a,0x30,0x07,0x72, + 0xa0,0x07,0x73,0x20,0x07,0x6d,0x60,0x0e,0x76,0x40,0x07,0x7a,0x60,0x07,0x74,0xa0, + 0x07,0x76,0x40,0x07,0x6d,0x60,0x0f,0x71,0x60,0x07,0x7a,0x10,0x07,0x76,0xa0,0x07, + 0x71,0x60,0x07,0x6d,0x60,0x0f,0x72,0x40,0x07,0x7a,0x30,0x07,0x72,0xa0,0x07,0x73, + 0x20,0x07,0x6d,0x60,0x0f,0x73,0x20,0x07,0x7a,0x30,0x07,0x72,0xa0,0x07,0x73,0x20, + 0x07,0x6d,0x60,0x0f,0x74,0x80,0x07,0x7a,0x60,0x07,0x74,0xa0,0x07,0x76,0x40,0x07, + 0x6d,0x60,0x0f,0x76,0x40,0x07,0x7a,0x60,0x07,0x74,0xa0,0x07,0x76,0x40,0x07,0x6d, + 0x60,0x0f,0x79,0x60,0x07,0x7a,0x10,0x07,0x72,0x80,0x07,0x7a,0x10,0x07,0x72,0x80, + 0x07,0x6d,0x60,0x0f,0x71,0x20,0x07,0x78,0xa0,0x07,0x71,0x20,0x07,0x78,0xa0,0x07, + 0x71,0x20,0x07,0x78,0xd0,0x06,0xf6,0x10,0x07,0x79,0x20,0x07,0x7a,0x20,0x07,0x75, + 0x60,0x07,0x7a,0x20,0x07,0x75,0x60,0x07,0x6d,0x60,0x0f,0x72,0x50,0x07,0x76,0xa0, + 0x07,0x72,0x50,0x07,0x76,0xa0,0x07,0x72,0x50,0x07,0x76,0xd0,0x06,0xf6,0x50,0x07, + 0x71,0x20,0x07,0x7a,0x50,0x07,0x71,0x20,0x07,0x7a,0x50,0x07,0x71,0x20,0x07,0x6d, + 0x60,0x0f,0x71,0x00,0x07,0x72,0x40,0x07,0x7a,0x10,0x07,0x70,0x20,0x07,0x74,0xa0, + 0x07,0x71,0x00,0x07,0x72,0x40,0x07,0x6d,0xe0,0x0e,0x78,0xa0,0x07,0x71,0x60,0x07, + 0x7a,0x30,0x07,0x72,0x30,0xe4,0x31,0x00,0x00,0x08,0x00,0x00,0x00,0x04,0x00,0x00, + 0x00,0x40,0x23,0x84,0x21,0x0b,0x06,0x40,0x1a,0x5a,0x62,0x83,0x40,0x51,0x7d,0x01, + 0x00,0x80,0x2c,0x10,0x00,0x00,0x09,0x00,0x00,0x00,0x32,0x1e,0x98,0x10,0x19,0x11, + 0x4c,0x90,0x8c,0x09,0x26,0x47,0xc6,0x04,0x43,0xca,0x22,0x28,0x81,0x42,0x18,0x01, + 0x28,0x83,0x82,0xa0,0x1d,0x01,0x20,0x1d,0x4b,0xd0,0x08,0x00,0x00,0x00,0xb1,0x18, + 0x00,0x00,0xa5,0x00,0x00,0x00,0x33,0x08,0x80,0x1c,0xc4,0xe1,0x1c,0x66,0x14,0x01, + 0x3d,0x88,0x43,0x38,0x84,0xc3,0x8c,0x42,0x80,0x07,0x79,0x78,0x07,0x73,0x98,0x71, + 0x0c,0xe6,0x00,0x0f,0xed,0x10,0x0e,0xf4,0x80,0x0e,0x33,0x0c,0x42,0x1e,0xc2,0xc1, + 0x1d,0xce,0xa1,0x1c,0x66,0x30,0x05,0x3d,0x88,0x43,0x38,0x84,0x83,0x1b,0xcc,0x03, + 0x3d,0xc8,0x43,0x3d,0x8c,0x03,0x3d,0xcc,0x78,0x8c,0x74,0x70,0x07,0x7b,0x08,0x07, + 0x79,0x48,0x87,0x70,0x70,0x07,0x7a,0x70,0x03,0x76,0x78,0x87,0x70,0x20,0x87,0x19, + 0xcc,0x11,0x0e,0xec,0x90,0x0e,0xe1,0x30,0x0f,0x6e,0x30,0x0f,0xe3,0xf0,0x0e,0xf0, + 0x50,0x0e,0x33,0x10,0xc4,0x1d,0xde,0x21,0x1c,0xd8,0x21,0x1d,0xc2,0x61,0x1e,0x66, + 0x30,0x89,0x3b,0xbc,0x83,0x3b,0xd0,0x43,0x39,0xb4,0x03,0x3c,0xbc,0x83,0x3c,0x84, + 0x03,0x3b,0xcc,0xf0,0x14,0x76,0x60,0x07,0x7b,0x68,0x07,0x37,0x68,0x87,0x72,0x68, + 0x07,0x37,0x80,0x87,0x70,0x90,0x87,0x70,0x60,0x07,0x76,0x28,0x07,0x76,0xf8,0x05, + 0x76,0x78,0x87,0x77,0x80,0x87,0x5f,0x08,0x87,0x71,0x18,0x87,0x72,0x98,0x87,0x79, + 0x98,0x81,0x2c,0xee,0xf0,0x0e,0xee,0xe0,0x0e,0xf5,0xc0,0x0e,0xec,0x30,0x03,0x62, + 0xc8,0xa1,0x1c,0xe4,0xa1,0x1c,0xcc,0xa1,0x1c,0xe4,0xa1,0x1c,0xdc,0x61,0x1c,0xca, + 0x21,0x1c,0xc4,0x81,0x1d,0xca,0x61,0x06,0xd6,0x90,0x43,0x39,0xc8,0x43,0x39,0x98, + 0x43,0x39,0xc8,0x43,0x39,0xb8,0xc3,0x38,0x94,0x43,0x38,0x88,0x03,0x3b,0x94,0xc3, + 0x2f,0xbc,0x83,0x3c,0xfc,0x82,0x3b,0xd4,0x03,0x3b,0xb0,0xc3,0x0c,0xc7,0x69,0x87, + 0x70,0x58,0x87,0x72,0x70,0x83,0x74,0x68,0x07,0x78,0x60,0x87,0x74,0x18,0x87,0x74, + 0xa0,0x87,0x19,0xce,0x53,0x0f,0xee,0x00,0x0f,0xf2,0x50,0x0e,0xe4,0x90,0x0e,0xe3, + 0x40,0x0f,0xe1,0x20,0x0e,0xec,0x50,0x0e,0x33,0x20,0x28,0x1d,0xdc,0xc1,0x1e,0xc2, + 0x41,0x1e,0xd2,0x21,0x1c,0xdc,0x81,0x1e,0xdc,0xe0,0x1c,0xe4,0xe1,0x1d,0xea,0x01, + 0x1e,0x66,0x18,0x51,0x38,0xb0,0x43,0x3a,0x9c,0x83,0x3b,0xcc,0x50,0x24,0x76,0x60, + 0x07,0x7b,0x68,0x07,0x37,0x60,0x87,0x77,0x78,0x07,0x78,0x98,0x51,0x4c,0xf4,0x90, + 0x0f,0xf0,0x50,0x0e,0x33,0x1e,0x6a,0x1e,0xca,0x61,0x1c,0xe8,0x21,0x1d,0xde,0xc1, + 0x1d,0x7e,0x01,0x1e,0xe4,0xa1,0x1c,0xcc,0x21,0x1d,0xf0,0x61,0x06,0x54,0x85,0x83, + 0x38,0xcc,0xc3,0x3b,0xb0,0x43,0x3d,0xd0,0x43,0x39,0xfc,0xc2,0x3c,0xe4,0x43,0x3b, + 0x88,0xc3,0x3b,0xb0,0xc3,0x8c,0xc5,0x0a,0x87,0x79,0x98,0x87,0x77,0x18,0x87,0x74, + 0x08,0x07,0x7a,0x28,0x07,0x72,0x98,0x81,0x5c,0xe3,0x10,0x0e,0xec,0xc0,0x0e,0xe5, + 0x50,0x0e,0xf3,0x30,0x23,0xc1,0xd2,0x41,0x1e,0xe4,0xe1,0x17,0xd8,0xe1,0x1d,0xde, + 0x01,0x1e,0x66,0x48,0x19,0x3b,0xb0,0x83,0x3d,0xb4,0x83,0x1b,0x84,0xc3,0x38,0x8c, + 0x43,0x39,0xcc,0xc3,0x3c,0xb8,0xc1,0x39,0xc8,0xc3,0x3b,0xd4,0x03,0x3c,0xcc,0x48, + 0xb4,0x71,0x08,0x07,0x76,0x60,0x07,0x71,0x08,0x87,0x71,0x58,0x87,0x19,0xdb,0xc6, + 0x0e,0xec,0x60,0x0f,0xed,0xe0,0x06,0xf0,0x20,0x0f,0xe5,0x30,0x0f,0xe5,0x20,0x0f, + 0xf6,0x50,0x0e,0x6e,0x10,0x0e,0xe3,0x30,0x0e,0xe5,0x30,0x0f,0xf3,0xe0,0x06,0xe9, + 0xe0,0x0e,0xe4,0x50,0x0e,0xf8,0x30,0x23,0xe2,0xec,0x61,0x1c,0xc2,0x81,0x1d,0xd8, + 0xe1,0x17,0xec,0x21,0x1d,0xe6,0x21,0x1d,0xc4,0x21,0x1d,0xd8,0x21,0x1d,0xe8,0x21, + 0x1f,0x66,0x20,0x9d,0x3b,0xbc,0x43,0x3d,0xb8,0x03,0x39,0x94,0x83,0x39,0xcc,0x58, + 0xbc,0x70,0x70,0x07,0x77,0x78,0x07,0x7a,0x08,0x07,0x7a,0x48,0x87,0x77,0x70,0x87, + 0x19,0xce,0x87,0x0e,0xe5,0x10,0x0e,0xf0,0x10,0x0e,0xec,0xc0,0x0e,0xef,0x30,0x0e, + 0xf3,0x90,0x0e,0xf4,0x50,0x0e,0x33,0x28,0x30,0x08,0x87,0x74,0x90,0x07,0x37,0x30, + 0x87,0x7a,0x70,0x87,0x71,0xa0,0x87,0x74,0x78,0x07,0x77,0xf8,0x85,0x73,0x90,0x87, + 0x77,0xa8,0x07,0x78,0x98,0x07,0x00,0x00,0x00,0x00,0x79,0x18,0x00,0x00,0xcb,0x00, + 0x00,0x00,0x22,0x47,0xc8,0x90,0x51,0x86,0x01,0x97,0x3f,0x00,0x00,0x00,0x8b,0x12, + 0x07,0xc5,0xc6,0x91,0x41,0xb4,0x44,0x06,0x23,0x2c,0x46,0xc1,0x2c,0x90,0xe4,0x21, + 0x89,0xa1,0x3c,0x08,0x95,0x44,0x57,0x32,0x00,0x00,0x53,0x44,0x4b,0x20,0x56,0x65, + 0x72,0x73,0x69,0x6f,0x6e,0x77,0x63,0x68,0x61,0x72,0x5f,0x73,0x69,0x7a,0x65,0x41, + 0x70,0x70,0x6c,0x65,0x20,0x6d,0x65,0x74,0x61,0x6c,0x20,0x76,0x65,0x72,0x73,0x69, + 0x6f,0x6e,0x20,0x33,0x32,0x30,0x32,0x33,0x2e,0x38,0x38,0x33,0x20,0x28,0x6d,0x65, + 0x74,0x61,0x6c,0x66,0x65,0x2d,0x33,0x32,0x30,0x32,0x33,0x2e,0x38,0x38,0x33,0x29, + 0x4d,0x65,0x74,0x61,0x6c,0x61,0x69,0x72,0x2e,0x63,0x6f,0x6d,0x70,0x69,0x6c,0x65, + 0x2e,0x64,0x65,0x6e,0x6f,0x72,0x6d,0x73,0x5f,0x64,0x69,0x73,0x61,0x62,0x6c,0x65, + 0x61,0x69,0x72,0x2e,0x63,0x6f,0x6d,0x70,0x69,0x6c,0x65,0x2e,0x66,0x61,0x73,0x74, + 0x5f,0x6d,0x61,0x74,0x68,0x5f,0x65,0x6e,0x61,0x62,0x6c,0x65,0x61,0x69,0x72,0x2e, + 0x63,0x6f,0x6d,0x70,0x69,0x6c,0x65,0x2e,0x66,0x72,0x61,0x6d,0x65,0x62,0x75,0x66, + 0x66,0x65,0x72,0x5f,0x66,0x65,0x74,0x63,0x68,0x5f,0x65,0x6e,0x61,0x62,0x6c,0x65, + 0x61,0x69,0x72,0x2e,0x76,0x65,0x72,0x74,0x65,0x78,0x5f,0x6f,0x75,0x74,0x70,0x75, + 0x74,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x61,0x69,0x72,0x2e, + 0x61,0x72,0x67,0x5f,0x74,0x79,0x70,0x65,0x5f,0x6e,0x61,0x6d,0x65,0x66,0x6c,0x6f, + 0x61,0x74,0x32,0x61,0x69,0x72,0x2e,0x61,0x72,0x67,0x5f,0x6e,0x61,0x6d,0x65,0x75, + 0x76,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x63,0x6f,0x6c,0x6f,0x72,0x61,0x69,0x72,0x2e,0x70,0x6f,0x73,0x69,0x74, + 0x69,0x6f,0x6e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x61,0x69, + 0x72,0x2e,0x76,0x65,0x72,0x74,0x65,0x78,0x5f,0x69,0x6e,0x70,0x75,0x74,0x61,0x69, + 0x72,0x2e,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x5f,0x69,0x6e,0x64,0x65,0x78, + 0x67,0x65,0x6e,0x65,0x72,0x61,0x74,0x65,0x64,0x28,0x5f,0x5f,0x61,0x69,0x72,0x5f, + 0x70,0x6c,0x61,0x63,0x65,0x68,0x6f,0x6c,0x64,0x65,0x72,0x5f,0x5f,0x29,0x70,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x63, + 0x6f,0x6c,0x6f,0x72,0x30,0x61,0x69,0x72,0x2e,0x62,0x75,0x66,0x66,0x65,0x72,0x61, + 0x69,0x72,0x2e,0x62,0x75,0x66,0x66,0x65,0x72,0x5f,0x73,0x69,0x7a,0x65,0x61,0x69, + 0x72,0x2e,0x72,0x65,0x61,0x64,0x61,0x69,0x72,0x2e,0x73,0x74,0x72,0x75,0x63,0x74, + 0x5f,0x74,0x79,0x70,0x65,0x5f,0x69,0x6e,0x66,0x6f,0x64,0x69,0x73,0x70,0x5f,0x73, + 0x69,0x7a,0x65,0x61,0x69,0x72,0x2e,0x61,0x72,0x67,0x5f,0x74,0x79,0x70,0x65,0x5f, + 0x73,0x69,0x7a,0x65,0x61,0x69,0x72,0x2e,0x61,0x72,0x67,0x5f,0x74,0x79,0x70,0x65, + 0x5f,0x61,0x6c,0x69,0x67,0x6e,0x5f,0x73,0x69,0x7a,0x65,0x76,0x73,0x5f,0x70,0x61, + 0x72,0x61,0x6d,0x73,0x5f,0x32,0x32,0x00,0x00,0x00,0x13,0x84,0x24,0x98,0x20,0x28, + 0xc8,0x04,0x21,0x11,0x26,0x08,0xc9,0x30,0x41,0x48,0x88,0x09,0xc2,0x01,0x4c,0x10, + 0x92,0x62,0x82,0x90,0x18,0x1b,0x06,0x31,0x08,0xc6,0x60,0xc3,0x40,0x06,0x42,0x19, + 0x6c,0x08,0x86,0x0d,0x83,0x18,0x98,0x81,0x19,0x6c,0x20,0x08,0x31,0x30,0x03,0x33, + 0xd8,0x10,0x14,0x1b,0x02,0x63,0x43,0x70,0x6c,0x30,0x90,0x44,0x59,0x98,0x66,0x83, + 0x81,0x38,0xca,0xc3,0x40,0x1b,0x8a,0x48,0x79,0x18,0x69,0xc3,0x20,0x07,0x73,0x40, + 0x07,0x1b,0x14,0x33,0x98,0x28,0x33,0x20,0x83,0x4a,0x59,0x18,0x6b,0x83,0x42,0x06, + 0x13,0x45,0x06,0x64,0x50,0x29,0x0b,0x73,0x6d,0x50,0xc4,0x60,0xa2,0xc4,0x80,0x0c, + 0x2a,0xe5,0x61,0xb0,0x0d,0x85,0x19,0xa4,0x81,0x19,0x2c,0xdd,0x06,0x09,0x0d,0x32, + 0x2d,0x0d,0x28,0x33,0x20,0x83,0x8d,0xcb,0x03,0x2f,0x0d,0xbe,0x34,0x50,0xc0,0x80, + 0x09,0x83,0x0d,0x84,0x1d,0xdc,0x01,0x1e,0xe8,0xc1,0x86,0xe1,0x0c,0xea,0x60,0x0f, + 0x34,0x12,0x98,0xa0,0x46,0x6c,0x6c,0x76,0x6d,0x2e,0x6d,0x6f,0x64,0x75,0x6c,0x65, + 0x2e,0x66,0x6c,0x61,0x67,0x73,0x53,0x84,0x34,0x50,0x83,0x2a,0x6c,0x6c,0x76,0x6d, + 0x2e,0x69,0x64,0x65,0x6e,0x74,0x53,0x82,0x35,0xe8,0x12,0x96,0x26,0xe7,0x62,0x57, + 0x26,0x37,0x97,0xf6,0xe6,0x36,0x25,0x60,0x83,0x52,0x61,0x69,0x72,0x2e,0x6c,0x61, + 0x6e,0x67,0x75,0x61,0x67,0x65,0x5f,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x53,0x82, + 0x36,0xe8,0x14,0x96,0x26,0xe7,0x32,0xf6,0xd6,0x06,0x97,0xc6,0x56,0xf6,0xf5,0x06, + 0x47,0x97,0xf6,0xe6,0x36,0x37,0x65,0x70,0x83,0x37,0x80,0x83,0x2a,0x61,0x69,0x72, + 0x2e,0x76,0x65,0x72,0x74,0x65,0x78,0x53,0x82,0x3d,0x00,0x00,0x00,0x00,0xa9,0x18, + 0x00,0x00,0x25,0x00,0x00,0x00,0x0b,0x0a,0x72,0x28,0x87,0x77,0x80,0x07,0x7a,0x58, + 0x70,0x98,0x43,0x3d,0xb8,0xc3,0x38,0xb0,0x43,0x39,0xd0,0xc3,0x82,0xe6,0x1c,0xc6, + 0xa1,0x0d,0xe8,0x41,0x1e,0xc2,0xc1,0x1d,0xe6,0x21,0x1d,0xe8,0x21,0x1d,0xde,0xc1, + 0x1d,0x16,0x34,0xe3,0x60,0x0e,0xe7,0x50,0x0f,0xe1,0x20,0x0f,0xe4,0x40,0x0f,0xe1, + 0x20,0x0f,0xe7,0x50,0x0e,0xf4,0xb0,0x80,0x81,0x07,0x79,0x28,0x87,0x70,0x60,0x07, + 0x76,0x78,0x87,0x71,0x08,0x07,0x7a,0x28,0x07,0x72,0x58,0x70,0x9c,0xc3,0x38,0xb4, + 0x01,0x3b,0xa4,0x83,0x3d,0x94,0xc3,0x02,0x6b,0x1c,0xd8,0x21,0x1c,0xdc,0xe1,0x1c, + 0xdc,0x20,0x1c,0xe4,0x61,0x1c,0xdc,0x20,0x1c,0xe8,0x81,0x1e,0xc2,0x61,0x1c,0xd0, + 0xa1,0x1c,0xc8,0x61,0x1c,0xc2,0x81,0x1d,0xd8,0x61,0xc1,0x01,0x0f,0xf4,0x20,0x0f, + 0xe1,0x50,0x0f,0xf4,0x80,0x0e,0x00,0x00,0x00,0x00,0x61,0x20,0x00,0x00,0x45,0x00, + 0x00,0x00,0x13,0x04,0x41,0x2c,0x10,0x00,0x00,0x00,0x11,0x00,0x00,0x00,0x94,0x33, + 0x00,0xd4,0x73,0x10,0x84,0xd0,0x34,0x63,0x11,0x40,0x60,0x1c,0x04,0x33,0x00,0x63, + 0x04,0x20,0x08,0x82,0xf0,0x37,0x46,0x00,0x82,0x20,0x88,0x7f,0x14,0x63,0x09,0x20, + 0x08,0x82,0xf0,0x2f,0x80,0x20,0x08,0xc2,0xbf,0x30,0x96,0x00,0x82,0x20,0x08,0x82, + 0x01,0x08,0x82,0x20,0x08,0x0e,0x33,0x00,0x24,0x73,0x10,0x10,0x14,0x49,0x34,0x33, + 0x00,0x00,0xf1,0x30,0x00,0x00,0x20,0x00,0x00,0x00,0x22,0x47,0xc8,0x90,0x51,0x12, + 0xc4,0x2b,0x00,0x00,0x00,0x00,0xcf,0x73,0x59,0x00,0x6f,0x6d,0x6e,0x69,0x70,0x6f, + 0x74,0x65,0x6e,0x74,0x20,0x63,0x68,0x61,0x72,0x53,0x69,0x6d,0x70,0x6c,0x65,0x20, + 0x43,0x2b,0x2b,0x20,0x54,0x42,0x41,0x41,0x61,0x69,0x72,0x2d,0x61,0x6c,0x69,0x61, + 0x73,0x2d,0x73,0x63,0x6f,0x70,0x65,0x73,0x28,0x6d,0x61,0x69,0x6e,0x30,0x29,0x61, + 0x69,0x72,0x2d,0x61,0x6c,0x69,0x61,0x73,0x2d,0x73,0x63,0x6f,0x70,0x65,0x2d,0x61, + 0x72,0x67,0x28,0x33,0x29,0x00,0x13,0x84,0xe5,0x58,0x21,0x88,0xc2,0x1f,0xac,0x18, + 0x46,0x41,0x14,0x40,0x61,0x43,0xe0,0x07,0x1b,0x86,0x3e,0x20,0x85,0x50,0xd8,0x30, + 0x94,0x42,0x29,0x84,0xc2,0x86,0x60,0x14,0x00,0x00,0x9b,0x06,0x26,0xa2,0x28,0x08, + 0x62,0x51,0x40,0x1f,0x0b,0x10,0xf8,0x58,0x80,0xc8,0x67,0x90,0x21,0x40,0x9e,0x41, + 0x86,0x00,0x79,0x66,0x1b,0x90,0x0a,0x98,0x6d,0x08,0xaa,0x60,0xb6,0x21,0x18,0x84, + 0x0c,0x02,0x62,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x5b,0x8a,0x20,0x28,0x85,0xc3, + 0x14,0x00,0x00,0x00,0x00,0x00,0x71,0x20,0x00,0x00,0x07,0x00,0x00,0x00,0x52,0x0e, + 0x10,0x22,0x64,0x82,0xa4,0x1c,0x20,0x44,0xc8,0xe4,0x48,0x39,0x40,0x88,0x90,0xa1, + 0x02,0xcc,0x16,0x14,0x0c,0x80,0x34,0x34,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; +static const uint8_t _simgui_shd_fs_bytecode_metal_ios[3223] = { + 0x4d,0x54,0x4c,0x42,0x01,0x00,0x02,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x97,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x58,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x7b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xd7,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xdf,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe7,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0xb0,0x0b,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x7b,0x00,0x00,0x00, + 0x4e,0x41,0x4d,0x45,0x06,0x00,0x6d,0x61,0x69,0x6e,0x30,0x00,0x54,0x59,0x50,0x45, + 0x01,0x00,0x01,0x48,0x41,0x53,0x48,0x20,0x00,0xe2,0xaf,0x34,0xe2,0xac,0xc4,0x8d, + 0xf8,0xd8,0x48,0xfb,0xc1,0x81,0xd7,0xb7,0xb1,0x6f,0xc3,0x09,0x95,0x04,0xee,0xe1, + 0xc7,0x0b,0x0c,0xbf,0x72,0x15,0xe9,0xc3,0xb4,0x4d,0x44,0x53,0x5a,0x08,0x00,0xb0, + 0x0b,0x00,0x00,0x00,0x00,0x00,0x00,0x4f,0x46,0x46,0x54,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x56,0x45,0x52,0x53,0x08,0x00,0x02,0x00,0x00,0x00,0x02, + 0x00,0x00,0x00,0x45,0x4e,0x44,0x54,0x04,0x00,0x00,0x00,0x45,0x4e,0x44,0x54,0x04, + 0x00,0x00,0x00,0x45,0x4e,0x44,0x54,0xde,0xc0,0x17,0x0b,0x00,0x00,0x00,0x00,0x14, + 0x00,0x00,0x00,0x94,0x0b,0x00,0x00,0xff,0xff,0xff,0xff,0x42,0x43,0xc0,0xde,0x35, + 0x14,0x00,0x00,0x03,0x00,0x00,0x00,0x62,0x0c,0x30,0x24,0x80,0x10,0x05,0xc8,0x14, + 0x00,0x00,0x00,0x21,0x0c,0x00,0x00,0xdd,0x02,0x00,0x00,0x0b,0x82,0x20,0x00,0x02, + 0x00,0x00,0x00,0x13,0x00,0x00,0x00,0x07,0x81,0x23,0x91,0x41,0xc8,0x04,0x49,0x06, + 0x10,0x32,0x39,0x92,0x01,0x84,0x0c,0x25,0x05,0x08,0x19,0x1e,0x04,0x8b,0x62,0x80, + 0x14,0x45,0x02,0x42,0x92,0x0b,0x42,0xa4,0x10,0x32,0x14,0x38,0x08,0x18,0x4b,0x0a, + 0x32,0x52,0x88,0x48,0x90,0x14,0x20,0x43,0x46,0x88,0xa5,0x00,0x19,0x32,0x42,0xe4, + 0x48,0x0e,0x90,0x91,0x22,0xc4,0x50,0x41,0x51,0x81,0x8c,0xe1,0x83,0xe5,0x8a,0x04, + 0x29,0x46,0x06,0x51,0x18,0x00,0x00,0x76,0x00,0x00,0x00,0x1b,0xc6,0x24,0xf8,0xff, + 0xff,0xff,0xff,0x01,0x68,0x03,0x60,0x0d,0x00,0x09,0xa8,0x88,0x70,0x80,0x07,0x78, + 0x90,0x87,0x77,0xc0,0x87,0x36,0x30,0x87,0x7a,0x70,0x87,0x71,0x68,0x03,0x73,0x80, + 0x87,0x36,0x68,0x87,0x70,0xa0,0x07,0x74,0x00,0xe8,0x41,0x1e,0xea,0xa1,0x1c,0x00, + 0xa2,0x1d,0xd2,0xc1,0x1d,0xda,0x80,0x1d,0xca,0xe1,0x1c,0xc2,0x81,0x1d,0xda,0xc0, + 0x1e,0xca,0x61,0x1c,0xe8,0xe1,0x1d,0xe4,0xa1,0x0d,0xee,0x21,0x1d,0xc8,0x81,0x1e, + 0xd0,0x01,0x88,0x03,0x39,0xc0,0x03,0x60,0x70,0x87,0x77,0x68,0x03,0x71,0xa8,0x87, + 0x74,0x60,0x07,0x7a,0x48,0x07,0x77,0x98,0x07,0x80,0x70,0x87,0x77,0x68,0x03,0x73, + 0x90,0x87,0x70,0x68,0x87,0x72,0x68,0x03,0x78,0x78,0x87,0x74,0x70,0x07,0x7a,0x28, + 0x07,0x79,0x68,0x83,0x72,0x60,0x87,0x74,0x68,0x07,0x80,0x1e,0xe4,0xa1,0x1e,0xca, + 0x01,0x20,0xdc,0xe1,0x1d,0xda,0xc0,0x1c,0xe4,0x21,0x1c,0xda,0xa1,0x1c,0xda,0x00, + 0x1e,0xde,0x21,0x1d,0xdc,0x81,0x1e,0xca,0x41,0x1e,0xda,0xa0,0x1c,0xd8,0x21,0x1d, + 0xda,0xa1,0x0d,0xdc,0xe1,0x1d,0xdc,0xa1,0x0d,0xd8,0xa1,0x1c,0xc2,0xc1,0x1c,0x00, + 0x7a,0x90,0x87,0x7a,0x28,0x07,0x80,0x70,0x87,0x77,0x68,0x83,0x74,0x70,0x07,0x73, + 0x98,0x87,0x36,0x30,0x07,0x78,0x68,0x83,0x76,0x08,0x07,0x7a,0x40,0x07,0x80,0x1e, + 0xe4,0xa1,0x1e,0xca,0x01,0x20,0xdc,0xe1,0x1d,0xda,0xc0,0x1d,0xc2,0xc1,0x1d,0xe6, + 0xa1,0x0d,0xcc,0x01,0x1e,0xda,0xa0,0x1d,0xc2,0x81,0x1e,0xd0,0x01,0xa0,0x07,0x79, + 0xa8,0x87,0x72,0x00,0x08,0x77,0x78,0x87,0x36,0x98,0x87,0x74,0x38,0x07,0x77,0x28, + 0x07,0x72,0x68,0x03,0x7d,0x28,0x07,0x79,0x78,0x87,0x79,0x68,0x03,0x73,0x80,0x87, + 0x36,0x68,0x87,0x70,0xa0,0x07,0x74,0x00,0xe8,0x41,0x1e,0xea,0xa1,0x1c,0x00,0xc2, + 0x1d,0xde,0xa1,0x0d,0xe8,0x41,0x1e,0xc2,0x01,0x1e,0xe0,0x21,0x1d,0xdc,0xe1,0x1c, + 0xda,0xa0,0x1d,0xc2,0x81,0x1e,0xd0,0x01,0xa0,0x07,0x79,0xa8,0x87,0x72,0x00,0x88, + 0x79,0xa0,0x87,0x70,0x18,0x87,0x75,0x68,0x03,0x78,0x90,0x87,0x77,0xa0,0x87,0x72, + 0x18,0x07,0x7a,0x78,0x07,0x79,0x68,0x03,0x71,0xa8,0x07,0x73,0x30,0x87,0x72,0x90, + 0x87,0x36,0x98,0x87,0x74,0xd0,0x87,0x72,0x00,0xf0,0x00,0x20,0xea,0xc1,0x1d,0xe6, + 0x21,0x1c,0xcc,0xa1,0x1c,0xda,0xc0,0x1c,0xe0,0xa1,0x0d,0xda,0x21,0x1c,0xe8,0x01, + 0x1d,0x00,0x7a,0x90,0x87,0x7a,0x28,0x07,0x60,0x83,0x21,0x0c,0xc0,0x02,0x54,0x1b, + 0x8c,0x81,0x00,0x16,0xa0,0xda,0xa0,0x10,0xff,0xff,0xff,0xff,0x3f,0x00,0x6d,0x00, + 0xac,0x01,0x20,0x01,0xd5,0x06,0xa3,0x08,0x80,0x05,0xa8,0x36,0x18,0x86,0x00,0x2c, + 0x40,0xb5,0x41,0x39,0xfe,0xff,0xff,0xff,0x7f,0x00,0xda,0x00,0x58,0x03,0x40,0x02, + 0x2a,0x00,0x00,0x49,0x18,0x00,0x00,0x04,0x00,0x00,0x00,0x13,0x86,0x40,0x18,0x26, + 0x0c,0x44,0x61,0x4c,0x18,0x8e,0xc2,0x00,0x00,0x00,0x00,0x89,0x20,0x00,0x00,0x1d, + 0x00,0x00,0x00,0x32,0x22,0x48,0x09,0x20,0x64,0x85,0x04,0x93,0x22,0xa4,0x84,0x04, + 0x93,0x22,0xe3,0x84,0xa1,0x90,0x14,0x12,0x4c,0x8a,0x8c,0x0b,0x84,0xa4,0x4c,0x10, + 0x48,0x33,0x00,0xc3,0x08,0x04,0x60,0x83,0x30,0x8c,0x20,0x00,0x47,0x49,0x53,0x44, + 0x09,0x93,0xff,0x4f,0xc4,0x35,0x51,0x11,0xf1,0xdb,0xc3,0x3f,0x8d,0x11,0x00,0x83, + 0x08,0x44,0x70,0x91,0x34,0x45,0x94,0x30,0xf9,0xbf,0x04,0x30,0xcf,0x42,0x44,0xff, + 0x34,0x46,0x00,0x0c,0x22,0x18,0x42,0x29,0xc4,0x08,0xe5,0x10,0x9a,0x23,0x08,0xe6, + 0x08,0xc0,0x60,0x18,0x41,0x58,0x4a,0x12,0xca,0x19,0x8a,0x29,0xb0,0xa8,0x0d,0x04, + 0xa4,0xc0,0x1a,0x01,0x00,0x00,0x00,0x13,0xaa,0x70,0x48,0x07,0x79,0xb0,0x03,0x3a, + 0x68,0x83,0x70,0x80,0x07,0x78,0x60,0x87,0x72,0x68,0x83,0x74,0x78,0x87,0x79,0x88, + 0x83,0x38,0x70,0x03,0x38,0x70,0x03,0x38,0xd8,0x70,0x1b,0xe5,0xd0,0x06,0xf0,0xa0, + 0x07,0x76,0x40,0x07,0x7a,0x60,0x07,0x74,0xa0,0x07,0x76,0x40,0x07,0x6d,0x90,0x0e, + 0x71,0xa0,0x07,0x78,0xa0,0x07,0x78,0xd0,0x06,0xe9,0x80,0x07,0x7a,0x80,0x07,0x7a, + 0x80,0x07,0x6d,0x90,0x0e,0x71,0x60,0x07,0x7a,0x10,0x07,0x76,0xa0,0x07,0x71,0x60, + 0x07,0x6d,0x90,0x0e,0x73,0x20,0x07,0x7a,0x30,0x07,0x72,0xa0,0x07,0x73,0x20,0x07, + 0x6d,0x90,0x0e,0x76,0x40,0x07,0x7a,0x60,0x07,0x74,0xa0,0x07,0x76,0x40,0x07,0x6d, + 0x60,0x0e,0x73,0x20,0x07,0x7a,0x30,0x07,0x72,0xa0,0x07,0x73,0x20,0x07,0x6d,0x60, + 0x0e,0x76,0x40,0x07,0x7a,0x60,0x07,0x74,0xa0,0x07,0x76,0x40,0x07,0x6d,0x60,0x0f, + 0x71,0x60,0x07,0x7a,0x10,0x07,0x76,0xa0,0x07,0x71,0x60,0x07,0x6d,0x60,0x0f,0x72, + 0x40,0x07,0x7a,0x30,0x07,0x72,0xa0,0x07,0x73,0x20,0x07,0x6d,0x60,0x0f,0x73,0x20, + 0x07,0x7a,0x30,0x07,0x72,0xa0,0x07,0x73,0x20,0x07,0x6d,0x60,0x0f,0x74,0x80,0x07, + 0x7a,0x60,0x07,0x74,0xa0,0x07,0x76,0x40,0x07,0x6d,0x60,0x0f,0x76,0x40,0x07,0x7a, + 0x60,0x07,0x74,0xa0,0x07,0x76,0x40,0x07,0x6d,0x60,0x0f,0x79,0x60,0x07,0x7a,0x10, + 0x07,0x72,0x80,0x07,0x7a,0x10,0x07,0x72,0x80,0x07,0x6d,0x60,0x0f,0x71,0x20,0x07, + 0x78,0xa0,0x07,0x71,0x20,0x07,0x78,0xa0,0x07,0x71,0x20,0x07,0x78,0xd0,0x06,0xf6, + 0x10,0x07,0x79,0x20,0x07,0x7a,0x20,0x07,0x75,0x60,0x07,0x7a,0x20,0x07,0x75,0x60, + 0x07,0x6d,0x60,0x0f,0x72,0x50,0x07,0x76,0xa0,0x07,0x72,0x50,0x07,0x76,0xa0,0x07, + 0x72,0x50,0x07,0x76,0xd0,0x06,0xf6,0x50,0x07,0x71,0x20,0x07,0x7a,0x50,0x07,0x71, + 0x20,0x07,0x7a,0x50,0x07,0x71,0x20,0x07,0x6d,0x60,0x0f,0x71,0x00,0x07,0x72,0x40, + 0x07,0x7a,0x10,0x07,0x70,0x20,0x07,0x74,0xa0,0x07,0x71,0x00,0x07,0x72,0x40,0x07, + 0x6d,0xe0,0x0e,0x78,0xa0,0x07,0x71,0x60,0x07,0x7a,0x30,0x07,0x72,0x30,0xe4,0x41, + 0x00,0x00,0x08,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x60,0xc8,0xd3,0x00,0x01,0x20, + 0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x80,0x46,0x08,0x43,0x16,0x0c,0x80,0x34,0xb4, + 0xc4,0x06,0x81,0xa2,0xd5,0x02,0x00,0x00,0x59,0x20,0x00,0x08,0x00,0x00,0x00,0x32, + 0x1e,0x98,0x10,0x19,0x11,0x4c,0x90,0x8c,0x09,0x26,0x47,0xc6,0x04,0x43,0x5a,0x45, + 0x50,0x02,0x85,0x30,0x02,0x50,0x06,0x04,0xc7,0x12,0x34,0x02,0x00,0x00,0x00,0xb1, + 0x18,0x00,0x00,0xa5,0x00,0x00,0x00,0x33,0x08,0x80,0x1c,0xc4,0xe1,0x1c,0x66,0x14, + 0x01,0x3d,0x88,0x43,0x38,0x84,0xc3,0x8c,0x42,0x80,0x07,0x79,0x78,0x07,0x73,0x98, + 0x71,0x0c,0xe6,0x00,0x0f,0xed,0x10,0x0e,0xf4,0x80,0x0e,0x33,0x0c,0x42,0x1e,0xc2, + 0xc1,0x1d,0xce,0xa1,0x1c,0x66,0x30,0x05,0x3d,0x88,0x43,0x38,0x84,0x83,0x1b,0xcc, + 0x03,0x3d,0xc8,0x43,0x3d,0x8c,0x03,0x3d,0xcc,0x78,0x8c,0x74,0x70,0x07,0x7b,0x08, + 0x07,0x79,0x48,0x87,0x70,0x70,0x07,0x7a,0x70,0x03,0x76,0x78,0x87,0x70,0x20,0x87, + 0x19,0xcc,0x11,0x0e,0xec,0x90,0x0e,0xe1,0x30,0x0f,0x6e,0x30,0x0f,0xe3,0xf0,0x0e, + 0xf0,0x50,0x0e,0x33,0x10,0xc4,0x1d,0xde,0x21,0x1c,0xd8,0x21,0x1d,0xc2,0x61,0x1e, + 0x66,0x30,0x89,0x3b,0xbc,0x83,0x3b,0xd0,0x43,0x39,0xb4,0x03,0x3c,0xbc,0x83,0x3c, + 0x84,0x03,0x3b,0xcc,0xf0,0x14,0x76,0x60,0x07,0x7b,0x68,0x07,0x37,0x68,0x87,0x72, + 0x68,0x07,0x37,0x80,0x87,0x70,0x90,0x87,0x70,0x60,0x07,0x76,0x28,0x07,0x76,0xf8, + 0x05,0x76,0x78,0x87,0x77,0x80,0x87,0x5f,0x08,0x87,0x71,0x18,0x87,0x72,0x98,0x87, + 0x79,0x98,0x81,0x2c,0xee,0xf0,0x0e,0xee,0xe0,0x0e,0xf5,0xc0,0x0e,0xec,0x30,0x03, + 0x62,0xc8,0xa1,0x1c,0xe4,0xa1,0x1c,0xcc,0xa1,0x1c,0xe4,0xa1,0x1c,0xdc,0x61,0x1c, + 0xca,0x21,0x1c,0xc4,0x81,0x1d,0xca,0x61,0x06,0xd6,0x90,0x43,0x39,0xc8,0x43,0x39, + 0x98,0x43,0x39,0xc8,0x43,0x39,0xb8,0xc3,0x38,0x94,0x43,0x38,0x88,0x03,0x3b,0x94, + 0xc3,0x2f,0xbc,0x83,0x3c,0xfc,0x82,0x3b,0xd4,0x03,0x3b,0xb0,0xc3,0x0c,0xc7,0x69, + 0x87,0x70,0x58,0x87,0x72,0x70,0x83,0x74,0x68,0x07,0x78,0x60,0x87,0x74,0x18,0x87, + 0x74,0xa0,0x87,0x19,0xce,0x53,0x0f,0xee,0x00,0x0f,0xf2,0x50,0x0e,0xe4,0x90,0x0e, + 0xe3,0x40,0x0f,0xe1,0x20,0x0e,0xec,0x50,0x0e,0x33,0x20,0x28,0x1d,0xdc,0xc1,0x1e, + 0xc2,0x41,0x1e,0xd2,0x21,0x1c,0xdc,0x81,0x1e,0xdc,0xe0,0x1c,0xe4,0xe1,0x1d,0xea, + 0x01,0x1e,0x66,0x18,0x51,0x38,0xb0,0x43,0x3a,0x9c,0x83,0x3b,0xcc,0x50,0x24,0x76, + 0x60,0x07,0x7b,0x68,0x07,0x37,0x60,0x87,0x77,0x78,0x07,0x78,0x98,0x51,0x4c,0xf4, + 0x90,0x0f,0xf0,0x50,0x0e,0x33,0x1e,0x6a,0x1e,0xca,0x61,0x1c,0xe8,0x21,0x1d,0xde, + 0xc1,0x1d,0x7e,0x01,0x1e,0xe4,0xa1,0x1c,0xcc,0x21,0x1d,0xf0,0x61,0x06,0x54,0x85, + 0x83,0x38,0xcc,0xc3,0x3b,0xb0,0x43,0x3d,0xd0,0x43,0x39,0xfc,0xc2,0x3c,0xe4,0x43, + 0x3b,0x88,0xc3,0x3b,0xb0,0xc3,0x8c,0xc5,0x0a,0x87,0x79,0x98,0x87,0x77,0x18,0x87, + 0x74,0x08,0x07,0x7a,0x28,0x07,0x72,0x98,0x81,0x5c,0xe3,0x10,0x0e,0xec,0xc0,0x0e, + 0xe5,0x50,0x0e,0xf3,0x30,0x23,0xc1,0xd2,0x41,0x1e,0xe4,0xe1,0x17,0xd8,0xe1,0x1d, + 0xde,0x01,0x1e,0x66,0x48,0x19,0x3b,0xb0,0x83,0x3d,0xb4,0x83,0x1b,0x84,0xc3,0x38, + 0x8c,0x43,0x39,0xcc,0xc3,0x3c,0xb8,0xc1,0x39,0xc8,0xc3,0x3b,0xd4,0x03,0x3c,0xcc, + 0x48,0xb4,0x71,0x08,0x07,0x76,0x60,0x07,0x71,0x08,0x87,0x71,0x58,0x87,0x19,0xdb, + 0xc6,0x0e,0xec,0x60,0x0f,0xed,0xe0,0x06,0xf0,0x20,0x0f,0xe5,0x30,0x0f,0xe5,0x20, + 0x0f,0xf6,0x50,0x0e,0x6e,0x10,0x0e,0xe3,0x30,0x0e,0xe5,0x30,0x0f,0xf3,0xe0,0x06, + 0xe9,0xe0,0x0e,0xe4,0x50,0x0e,0xf8,0x30,0x23,0xe2,0xec,0x61,0x1c,0xc2,0x81,0x1d, + 0xd8,0xe1,0x17,0xec,0x21,0x1d,0xe6,0x21,0x1d,0xc4,0x21,0x1d,0xd8,0x21,0x1d,0xe8, + 0x21,0x1f,0x66,0x20,0x9d,0x3b,0xbc,0x43,0x3d,0xb8,0x03,0x39,0x94,0x83,0x39,0xcc, + 0x58,0xbc,0x70,0x70,0x07,0x77,0x78,0x07,0x7a,0x08,0x07,0x7a,0x48,0x87,0x77,0x70, + 0x87,0x19,0xce,0x87,0x0e,0xe5,0x10,0x0e,0xf0,0x10,0x0e,0xec,0xc0,0x0e,0xef,0x30, + 0x0e,0xf3,0x90,0x0e,0xf4,0x50,0x0e,0x33,0x28,0x30,0x08,0x87,0x74,0x90,0x07,0x37, + 0x30,0x87,0x7a,0x70,0x87,0x71,0xa0,0x87,0x74,0x78,0x07,0x77,0xf8,0x85,0x73,0x90, + 0x87,0x77,0xa8,0x07,0x78,0x98,0x07,0x00,0x00,0x00,0x00,0x79,0x18,0x00,0x00,0xaa, + 0x00,0x00,0x00,0x22,0x47,0xc8,0x90,0x51,0x72,0x58,0xd8,0x00,0x00,0x00,0x00,0x8b, + 0x12,0x07,0xc5,0xc6,0x91,0x41,0x14,0x19,0x8c,0x22,0x2d,0xca,0x63,0x08,0x4b,0xb1, + 0x48,0x0a,0x36,0x2c,0xc7,0x00,0x00,0x53,0x44,0x4b,0x20,0x56,0x65,0x72,0x73,0x69, + 0x6f,0x6e,0x77,0x63,0x68,0x61,0x72,0x5f,0x73,0x69,0x7a,0x65,0x41,0x70,0x70,0x6c, + 0x65,0x20,0x6d,0x65,0x74,0x61,0x6c,0x20,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20, + 0x33,0x32,0x30,0x32,0x33,0x2e,0x38,0x38,0x33,0x20,0x28,0x6d,0x65,0x74,0x61,0x6c, + 0x66,0x65,0x2d,0x33,0x32,0x30,0x32,0x33,0x2e,0x38,0x38,0x33,0x29,0x4d,0x65,0x74, + 0x61,0x6c,0x61,0x69,0x72,0x2e,0x63,0x6f,0x6d,0x70,0x69,0x6c,0x65,0x2e,0x64,0x65, + 0x6e,0x6f,0x72,0x6d,0x73,0x5f,0x64,0x69,0x73,0x61,0x62,0x6c,0x65,0x61,0x69,0x72, + 0x2e,0x63,0x6f,0x6d,0x70,0x69,0x6c,0x65,0x2e,0x66,0x61,0x73,0x74,0x5f,0x6d,0x61, + 0x74,0x68,0x5f,0x65,0x6e,0x61,0x62,0x6c,0x65,0x61,0x69,0x72,0x2e,0x63,0x6f,0x6d, + 0x70,0x69,0x6c,0x65,0x2e,0x66,0x72,0x61,0x6d,0x65,0x62,0x75,0x66,0x66,0x65,0x72, + 0x5f,0x66,0x65,0x74,0x63,0x68,0x5f,0x65,0x6e,0x61,0x62,0x6c,0x65,0x61,0x69,0x72, + 0x2e,0x72,0x65,0x6e,0x64,0x65,0x72,0x5f,0x74,0x61,0x72,0x67,0x65,0x74,0x61,0x69, + 0x72,0x2e,0x61,0x72,0x67,0x5f,0x74,0x79,0x70,0x65,0x5f,0x6e,0x61,0x6d,0x65,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x61,0x69,0x72,0x2e,0x61,0x72,0x67,0x5f,0x6e,0x61,0x6d, + 0x65,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x61,0x69,0x72,0x2e,0x66, + 0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x5f,0x69,0x6e,0x70,0x75,0x74,0x75,0x73,0x65, + 0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x61,0x69,0x72,0x2e,0x63,0x65,0x6e,0x74, + 0x65,0x72,0x61,0x69,0x72,0x2e,0x70,0x65,0x72,0x73,0x70,0x65,0x63,0x74,0x69,0x76, + 0x65,0x66,0x6c,0x6f,0x61,0x74,0x32,0x75,0x76,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f, + 0x63,0x6e,0x31,0x29,0x63,0x6f,0x6c,0x6f,0x72,0x61,0x69,0x72,0x2e,0x74,0x65,0x78, + 0x74,0x75,0x72,0x65,0x61,0x69,0x72,0x2e,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, + 0x5f,0x69,0x6e,0x64,0x65,0x78,0x61,0x69,0x72,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65, + 0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x2c, + 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x3e,0x74,0x65,0x78,0x61,0x69,0x72,0x2e,0x73, + 0x61,0x6d,0x70,0x6c,0x65,0x72,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x73,0x6d,0x70, + 0x00,0x00,0x00,0x13,0x84,0x45,0x98,0x20,0x40,0xc7,0x04,0x61,0x19,0x26,0x08,0x0b, + 0x31,0x41,0x58,0x8a,0x09,0x42,0x02,0x4c,0x10,0x16,0x63,0xc3,0xd0,0x05,0xde,0x86, + 0xe1,0x13,0xc0,0x60,0x43,0x30,0x6c,0x18,0xba,0x30,0x08,0x83,0x0d,0x04,0xd1,0x85, + 0x41,0x18,0x6c,0x08,0x8a,0x0d,0x81,0xb1,0x21,0x38,0x36,0x1c,0x48,0x18,0x84,0x41, + 0xa2,0x2c,0xcc,0x86,0x80,0x0d,0x36,0x24,0x61,0xd0,0x38,0x0f,0x94,0x44,0x8b,0xb4, + 0x21,0xf9,0x9a,0xe9,0x81,0x12,0x65,0xa1,0x36,0x28,0x5d,0x65,0x85,0xc1,0x77,0x25, + 0xd8,0x92,0x6d,0x48,0xc6,0x40,0xb3,0xc2,0xe0,0x4b,0xb6,0x85,0xdb,0x40,0xb8,0xc1, + 0x1b,0xc0,0x41,0x1c,0x6c,0x18,0xc4,0xa0,0x0d,0xe4,0x40,0x23,0x81,0x09,0x6a,0xc4, + 0xc6,0x66,0xd7,0xe6,0xd2,0xf6,0x46,0x56,0xc7,0x56,0xe6,0x62,0xc6,0x16,0x76,0x36, + 0x37,0x45,0x18,0x03,0x32,0xa8,0xc2,0xc6,0x66,0xd7,0xe6,0x92,0x46,0x56,0xe6,0x46, + 0x37,0x25,0x28,0x83,0x2e,0x61,0x69,0x72,0x2e,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e, + 0x53,0x02,0x33,0x28,0x15,0x96,0x26,0xe7,0xc2,0x16,0xe6,0x76,0x56,0x17,0x76,0x56, + 0xf6,0x65,0x57,0x26,0x37,0x97,0xf6,0xe6,0x36,0x25,0x38,0x83,0x4e,0x61,0x69,0x72, + 0x2e,0x63,0x6f,0x6d,0x70,0x69,0x6c,0x65,0x5f,0x6f,0x70,0x74,0x69,0x6f,0x6e,0x73, + 0x53,0x06,0x34,0x48,0x03,0x35,0x28,0x13,0x96,0x26,0xe7,0x62,0x26,0x17,0x76,0xd6, + 0x56,0xe6,0x46,0x37,0x25,0x90,0x03,0x00,0x00,0x00,0x00,0xa9,0x18,0x00,0x00,0x25, + 0x00,0x00,0x00,0x0b,0x0a,0x72,0x28,0x87,0x77,0x80,0x07,0x7a,0x58,0x70,0x98,0x43, + 0x3d,0xb8,0xc3,0x38,0xb0,0x43,0x39,0xd0,0xc3,0x82,0xe6,0x1c,0xc6,0xa1,0x0d,0xe8, + 0x41,0x1e,0xc2,0xc1,0x1d,0xe6,0x21,0x1d,0xe8,0x21,0x1d,0xde,0xc1,0x1d,0x16,0x34, + 0xe3,0x60,0x0e,0xe7,0x50,0x0f,0xe1,0x20,0x0f,0xe4,0x40,0x0f,0xe1,0x20,0x0f,0xe7, + 0x50,0x0e,0xf4,0xb0,0x80,0x81,0x07,0x79,0x28,0x87,0x70,0x60,0x07,0x76,0x78,0x87, + 0x71,0x08,0x07,0x7a,0x28,0x07,0x72,0x58,0x70,0x9c,0xc3,0x38,0xb4,0x01,0x3b,0xa4, + 0x83,0x3d,0x94,0xc3,0x02,0x6b,0x1c,0xd8,0x21,0x1c,0xdc,0xe1,0x1c,0xdc,0x20,0x1c, + 0xe4,0x61,0x1c,0xdc,0x20,0x1c,0xe8,0x81,0x1e,0xc2,0x61,0x1c,0xd0,0xa1,0x1c,0xc8, + 0x61,0x1c,0xc2,0x81,0x1d,0xd8,0x61,0xc1,0x01,0x0f,0xf4,0x20,0x0f,0xe1,0x50,0x0f, + 0xf4,0x80,0x0e,0x00,0x00,0x00,0x00,0x61,0x20,0x00,0x00,0x30,0x00,0x00,0x00,0x13, + 0x04,0x41,0x2c,0x10,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0xa4,0x6a,0x60,0x04,0x80, + 0xd8,0x08,0x00,0x81,0x11,0x00,0x12,0x33,0x00,0x00,0x00,0xf1,0x30,0x00,0x00,0x1c, + 0x00,0x00,0x00,0x22,0x47,0xc8,0x90,0x51,0x0e,0xc4,0x2a,0x00,0x00,0x00,0x00,0x17, + 0x86,0x01,0x00,0x61,0x69,0x72,0x2d,0x61,0x6c,0x69,0x61,0x73,0x2d,0x73,0x63,0x6f, + 0x70,0x65,0x73,0x28,0x6d,0x61,0x69,0x6e,0x30,0x29,0x61,0x69,0x72,0x2d,0x61,0x6c, + 0x69,0x61,0x73,0x2d,0x73,0x63,0x6f,0x70,0x65,0x2d,0x73,0x61,0x6d,0x70,0x6c,0x65, + 0x72,0x73,0x61,0x69,0x72,0x2d,0x61,0x6c,0x69,0x61,0x73,0x2d,0x73,0x63,0x6f,0x70, + 0x65,0x2d,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x73,0x00,0x2b,0x84,0x3b,0xa0,0x83, + 0x15,0x03,0x1e,0xdc,0x41,0x1d,0xac,0x18,0xf2,0xe0,0x0e,0xec,0x60,0x83,0x90,0x07, + 0x78,0x00,0x00,0x23,0x06,0xcd,0x10,0x82,0x60,0xf1,0x35,0xd0,0x61,0x24,0xc5,0x40, + 0x08,0x8c,0x05,0x89,0x7c,0x66,0x1b,0x86,0x00,0xc8,0x20,0x20,0x06,0x00,0x00,0x02, + 0x00,0x00,0x00,0x5b,0x06,0xe0,0xc8,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x71, + 0x20,0x00,0x00,0x0d,0x00,0x00,0x00,0x52,0x0e,0x10,0x22,0x64,0x82,0xa4,0x1c,0x20, + 0x44,0xc8,0xe4,0x48,0x39,0x40,0x88,0x90,0xa1,0x05,0x6c,0x00,0x12,0xf9,0x12,0xc0, + 0x3c,0x0b,0xf1,0x4f,0xc4,0x35,0x51,0x11,0xf1,0xdb,0x83,0x5f,0xe1,0xc5,0x6d,0x2b, + 0xc0,0x68,0x41,0xc1,0x00,0x48,0x43,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; +static const uint8_t _simgui_shd_vs_source_metal_sim[672] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x76, + 0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x32,0x20,0x64,0x69,0x73,0x70,0x5f,0x73,0x69,0x7a,0x65,0x3b, + 0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e, + 0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x32,0x20,0x75,0x76,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63, + 0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c, + 0x6f,0x63,0x6e,0x31,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20, + 0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69, + 0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70, + 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b,0x61,0x74,0x74,0x72,0x69,0x62, + 0x75,0x74,0x65,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x32,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x20,0x5b, + 0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28,0x31,0x29,0x5d,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f, + 0x72,0x30,0x20,0x5b,0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28,0x32, + 0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,0x65,0x78,0x20, + 0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28, + 0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74, + 0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61, + 0x6e,0x74,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x26,0x20,0x5f,0x32, + 0x32,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74, + 0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f, + 0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x28,0x69,0x6e,0x2e,0x70,0x6f,0x73, + 0x69,0x74,0x69,0x6f,0x6e,0x20,0x2f,0x20,0x5f,0x32,0x32,0x2e,0x64,0x69,0x73,0x70, + 0x5f,0x73,0x69,0x7a,0x65,0x29,0x20,0x2d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28, + 0x30,0x2e,0x35,0x29,0x29,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x32, + 0x2e,0x30,0x2c,0x20,0x2d,0x32,0x2e,0x30,0x29,0x2c,0x20,0x30,0x2e,0x35,0x2c,0x20, + 0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x75,0x76, + 0x20,0x3d,0x20,0x69,0x6e,0x2e,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, + 0x20,0x69,0x6e,0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +static const uint8_t _simgui_shd_fs_source_metal_sim[436] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d, + 0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x5b,0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d, + 0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f, + 0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20, + 0x75,0x76,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29, + 0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63, + 0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e, + 0x31,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65, + 0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69, + 0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b, + 0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78, + 0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65, + 0x78,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x30,0x29,0x5d,0x5d, + 0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x20,0x5b,0x5b, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75, + 0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e, + 0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x74,0x65,0x78, + 0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x2c,0x20,0x69,0x6e,0x2e, + 0x75,0x76,0x29,0x20,0x2a,0x20,0x69,0x6e,0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x00, +}; +#elif defined(SOKOL_D3D11) +static const uint8_t _simgui_shd_vs_bytecode_hlsl4[892] = { + 0x44,0x58,0x42,0x43,0x0d,0xbd,0x9e,0x9e,0x7d,0xc0,0x2b,0x54,0x88,0xf9,0xca,0x89, + 0x32,0xe4,0x0c,0x59,0x01,0x00,0x00,0x00,0x7c,0x03,0x00,0x00,0x05,0x00,0x00,0x00, + 0x34,0x00,0x00,0x00,0xfc,0x00,0x00,0x00,0x60,0x01,0x00,0x00,0xd0,0x01,0x00,0x00, + 0x00,0x03,0x00,0x00,0x52,0x44,0x45,0x46,0xc0,0x00,0x00,0x00,0x01,0x00,0x00,0x00, + 0x48,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x1c,0x00,0x00,0x00,0x00,0x04,0xfe,0xff, + 0x10,0x81,0x00,0x00,0x98,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d, + 0x73,0x00,0xab,0xab,0x3c,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x60,0x00,0x00,0x00, + 0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x88,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x5f,0x32,0x32,0x5f,0x64,0x69,0x73,0x70,0x5f,0x73,0x69,0x7a, + 0x65,0x00,0xab,0xab,0x01,0x00,0x03,0x00,0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x4d,0x69,0x63,0x72,0x6f,0x73,0x6f,0x66,0x74,0x20,0x28,0x52, + 0x29,0x20,0x48,0x4c,0x53,0x4c,0x20,0x53,0x68,0x61,0x64,0x65,0x72,0x20,0x43,0x6f, + 0x6d,0x70,0x69,0x6c,0x65,0x72,0x20,0x31,0x30,0x2e,0x31,0x00,0x49,0x53,0x47,0x4e, + 0x5c,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x50,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x03,0x03,0x00,0x00,0x50,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x03,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x03,0x03,0x00,0x00,0x50,0x00,0x00,0x00, + 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x02,0x00,0x00,0x00, + 0x0f,0x0f,0x00,0x00,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x00,0xab,0xab,0xab, + 0x4f,0x53,0x47,0x4e,0x68,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x08,0x00,0x00,0x00, + 0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x0c,0x00,0x00,0x50,0x00,0x00,0x00,0x01,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x0f,0x00,0x00,0x00, + 0x59,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x03,0x00,0x00,0x00, + 0x02,0x00,0x00,0x00,0x0f,0x00,0x00,0x00,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44, + 0x00,0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x00,0xab,0xab,0xab, + 0x53,0x48,0x44,0x52,0x28,0x01,0x00,0x00,0x40,0x00,0x01,0x00,0x4a,0x00,0x00,0x00, + 0x59,0x00,0x00,0x04,0x46,0x8e,0x20,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00, + 0x5f,0x00,0x00,0x03,0x32,0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x5f,0x00,0x00,0x03, + 0x32,0x10,0x10,0x00,0x01,0x00,0x00,0x00,0x5f,0x00,0x00,0x03,0xf2,0x10,0x10,0x00, + 0x02,0x00,0x00,0x00,0x65,0x00,0x00,0x03,0x32,0x20,0x10,0x00,0x00,0x00,0x00,0x00, + 0x65,0x00,0x00,0x03,0xf2,0x20,0x10,0x00,0x01,0x00,0x00,0x00,0x67,0x00,0x00,0x04, + 0xf2,0x20,0x10,0x00,0x02,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x68,0x00,0x00,0x02, + 0x01,0x00,0x00,0x00,0x36,0x00,0x00,0x05,0x32,0x20,0x10,0x00,0x00,0x00,0x00,0x00, + 0x46,0x10,0x10,0x00,0x01,0x00,0x00,0x00,0x36,0x00,0x00,0x05,0xf2,0x20,0x10,0x00, + 0x01,0x00,0x00,0x00,0x46,0x1e,0x10,0x00,0x02,0x00,0x00,0x00,0x0e,0x00,0x00,0x08, + 0x32,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x46,0x10,0x10,0x00,0x00,0x00,0x00,0x00, + 0x46,0x80,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0a, + 0x32,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x46,0x00,0x10,0x00,0x00,0x00,0x00,0x00, + 0x02,0x40,0x00,0x00,0x00,0x00,0x00,0xbf,0x00,0x00,0x00,0xbf,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x0a,0x32,0x20,0x10,0x00,0x02,0x00,0x00,0x00, + 0x46,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x02,0x40,0x00,0x00,0x00,0x00,0x00,0x40, + 0x00,0x00,0x00,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x08, + 0xc2,0x20,0x10,0x00,0x02,0x00,0x00,0x00,0x02,0x40,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0x00,0x00,0x80,0x3f,0x3e,0x00,0x00,0x01, + 0x53,0x54,0x41,0x54,0x74,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x01,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; +static const uint8_t _simgui_shd_fs_bytecode_hlsl4[608] = { + 0x44,0x58,0x42,0x43,0x3a,0xa7,0x41,0x21,0xb4,0x2d,0xa7,0x6e,0xfe,0x31,0xb0,0xe0, + 0x14,0xe0,0xdf,0x5a,0x01,0x00,0x00,0x00,0x60,0x02,0x00,0x00,0x05,0x00,0x00,0x00, + 0x34,0x00,0x00,0x00,0xc8,0x00,0x00,0x00,0x14,0x01,0x00,0x00,0x48,0x01,0x00,0x00, + 0xe4,0x01,0x00,0x00,0x52,0x44,0x45,0x46,0x8c,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x1c,0x00,0x00,0x00,0x00,0x04,0xff,0xff, + 0x10,0x81,0x00,0x00,0x64,0x00,0x00,0x00,0x5c,0x00,0x00,0x00,0x03,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x02,0x00,0x00,0x00, + 0x05,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00, + 0x01,0x00,0x00,0x00,0x0d,0x00,0x00,0x00,0x73,0x6d,0x70,0x00,0x74,0x65,0x78,0x00, + 0x4d,0x69,0x63,0x72,0x6f,0x73,0x6f,0x66,0x74,0x20,0x28,0x52,0x29,0x20,0x48,0x4c, + 0x53,0x4c,0x20,0x53,0x68,0x61,0x64,0x65,0x72,0x20,0x43,0x6f,0x6d,0x70,0x69,0x6c, + 0x65,0x72,0x20,0x31,0x30,0x2e,0x31,0x00,0x49,0x53,0x47,0x4e,0x44,0x00,0x00,0x00, + 0x02,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x03,0x00,0x00, + 0x38,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00, + 0x01,0x00,0x00,0x00,0x0f,0x0f,0x00,0x00,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44, + 0x00,0xab,0xab,0xab,0x4f,0x53,0x47,0x4e,0x2c,0x00,0x00,0x00,0x01,0x00,0x00,0x00, + 0x08,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0x00,0x00,0x00,0x53,0x56,0x5f,0x54, + 0x61,0x72,0x67,0x65,0x74,0x00,0xab,0xab,0x53,0x48,0x44,0x52,0x94,0x00,0x00,0x00, + 0x40,0x00,0x00,0x00,0x25,0x00,0x00,0x00,0x5a,0x00,0x00,0x03,0x00,0x60,0x10,0x00, + 0x00,0x00,0x00,0x00,0x58,0x18,0x00,0x04,0x00,0x70,0x10,0x00,0x00,0x00,0x00,0x00, + 0x55,0x55,0x00,0x00,0x62,0x10,0x00,0x03,0x32,0x10,0x10,0x00,0x00,0x00,0x00,0x00, + 0x62,0x10,0x00,0x03,0xf2,0x10,0x10,0x00,0x01,0x00,0x00,0x00,0x65,0x00,0x00,0x03, + 0xf2,0x20,0x10,0x00,0x00,0x00,0x00,0x00,0x68,0x00,0x00,0x02,0x01,0x00,0x00,0x00, + 0x45,0x00,0x00,0x09,0xf2,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x46,0x10,0x10,0x00, + 0x00,0x00,0x00,0x00,0x46,0x7e,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x10,0x00, + 0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x07,0xf2,0x20,0x10,0x00,0x00,0x00,0x00,0x00, + 0x46,0x0e,0x10,0x00,0x00,0x00,0x00,0x00,0x46,0x1e,0x10,0x00,0x01,0x00,0x00,0x00, + 0x3e,0x00,0x00,0x01,0x53,0x54,0x41,0x54,0x74,0x00,0x00,0x00,0x03,0x00,0x00,0x00, + 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x01,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; +#elif defined(SOKOL_WGPU) +static const uint8_t _simgui_shd_vs_source_wgsl[960] = { + 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, + 0x64,0x65,0x72,0x69,0x76,0x61,0x74,0x69,0x76,0x65,0x5f,0x75,0x6e,0x69,0x66,0x6f, + 0x72,0x6d,0x69,0x74,0x79,0x29,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20, + 0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x20,0x7b,0x0a,0x20,0x20,0x2f,0x2a, + 0x20,0x40,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x30,0x29,0x20,0x2a,0x2f,0x0a,0x20, + 0x20,0x64,0x69,0x73,0x70,0x5f,0x73,0x69,0x7a,0x65,0x20,0x3a,0x20,0x76,0x65,0x63, + 0x32,0x66,0x2c,0x0a,0x7d,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69,0x76,0x61, + 0x74,0x65,0x3e,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5f,0x31,0x20,0x3a, + 0x20,0x76,0x65,0x63,0x32,0x66,0x3b,0x0a,0x0a,0x40,0x62,0x69,0x6e,0x64,0x69,0x6e, + 0x67,0x28,0x30,0x29,0x20,0x40,0x67,0x72,0x6f,0x75,0x70,0x28,0x30,0x29,0x20,0x76, + 0x61,0x72,0x3c,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x3e,0x20,0x78,0x5f,0x32,0x32, + 0x20,0x3a,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a,0x0a,0x76, + 0x61,0x72,0x3c,0x70,0x72,0x69,0x76,0x61,0x74,0x65,0x3e,0x20,0x75,0x76,0x20,0x3a, + 0x20,0x76,0x65,0x63,0x32,0x66,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69, + 0x76,0x61,0x74,0x65,0x3e,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x20, + 0x3a,0x20,0x76,0x65,0x63,0x32,0x66,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72, + 0x69,0x76,0x61,0x74,0x65,0x3e,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x76, + 0x65,0x63,0x34,0x66,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69,0x76,0x61, + 0x74,0x65,0x3e,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x20,0x3a,0x20,0x76,0x65,0x63, + 0x34,0x66,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69,0x76,0x61,0x74,0x65, + 0x3e,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20, + 0x76,0x65,0x63,0x34,0x66,0x3b,0x0a,0x0a,0x66,0x6e,0x20,0x6d,0x61,0x69,0x6e,0x5f, + 0x31,0x28,0x29,0x20,0x7b,0x0a,0x20,0x20,0x6c,0x65,0x74,0x20,0x78,0x5f,0x33,0x33, + 0x20,0x3d,0x20,0x28,0x28,0x28,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5f,0x31, + 0x20,0x2f,0x20,0x78,0x5f,0x32,0x32,0x2e,0x64,0x69,0x73,0x70,0x5f,0x73,0x69,0x7a, + 0x65,0x29,0x20,0x2d,0x20,0x76,0x65,0x63,0x32,0x66,0x28,0x30,0x2e,0x35,0x66,0x29, + 0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x32,0x66,0x28,0x32,0x2e,0x30,0x66,0x2c,0x20, + 0x2d,0x32,0x2e,0x30,0x66,0x29,0x29,0x3b,0x0a,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x66,0x28,0x78, + 0x5f,0x33,0x33,0x2e,0x78,0x2c,0x20,0x78,0x5f,0x33,0x33,0x2e,0x79,0x2c,0x20,0x30, + 0x2e,0x35,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x75,0x76, + 0x20,0x3d,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x3b,0x0a,0x20,0x20, + 0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x72, + 0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x5f,0x6f,0x75,0x74,0x20,0x7b,0x0a,0x20, + 0x20,0x40,0x62,0x75,0x69,0x6c,0x74,0x69,0x6e,0x28,0x70,0x6f,0x73,0x69,0x74,0x69, + 0x6f,0x6e,0x29,0x0a,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f, + 0x6e,0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x2c,0x0a,0x20,0x20,0x40,0x6c,0x6f, + 0x63,0x61,0x74,0x69,0x6f,0x6e,0x28,0x30,0x29,0x0a,0x20,0x20,0x75,0x76,0x5f,0x31, + 0x20,0x3a,0x20,0x76,0x65,0x63,0x32,0x66,0x2c,0x0a,0x20,0x20,0x40,0x6c,0x6f,0x63, + 0x61,0x74,0x69,0x6f,0x6e,0x28,0x31,0x29,0x0a,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72, + 0x5f,0x31,0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x2c,0x0a,0x7d,0x0a,0x0a,0x40, + 0x76,0x65,0x72,0x74,0x65,0x78,0x0a,0x66,0x6e,0x20,0x6d,0x61,0x69,0x6e,0x28,0x40, + 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x28,0x30,0x29,0x20,0x70,0x6f,0x73,0x69, + 0x74,0x69,0x6f,0x6e,0x5f,0x31,0x5f,0x70,0x61,0x72,0x61,0x6d,0x20,0x3a,0x20,0x76, + 0x65,0x63,0x32,0x66,0x2c,0x20,0x40,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x28, + 0x31,0x29,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x5f,0x70,0x61,0x72, + 0x61,0x6d,0x20,0x3a,0x20,0x76,0x65,0x63,0x32,0x66,0x2c,0x20,0x40,0x6c,0x6f,0x63, + 0x61,0x74,0x69,0x6f,0x6e,0x28,0x32,0x29,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x5f, + 0x70,0x61,0x72,0x61,0x6d,0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x29,0x20,0x2d, + 0x3e,0x20,0x6d,0x61,0x69,0x6e,0x5f,0x6f,0x75,0x74,0x20,0x7b,0x0a,0x20,0x20,0x70, + 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5f,0x31,0x20,0x3d,0x20,0x70,0x6f,0x73,0x69, + 0x74,0x69,0x6f,0x6e,0x5f,0x31,0x5f,0x70,0x61,0x72,0x61,0x6d,0x3b,0x0a,0x20,0x20, + 0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x20,0x3d,0x20,0x74,0x65,0x78,0x63, + 0x6f,0x6f,0x72,0x64,0x30,0x5f,0x70,0x61,0x72,0x61,0x6d,0x3b,0x0a,0x20,0x20,0x63, + 0x6f,0x6c,0x6f,0x72,0x30,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x5f,0x70, + 0x61,0x72,0x61,0x6d,0x3b,0x0a,0x20,0x20,0x6d,0x61,0x69,0x6e,0x5f,0x31,0x28,0x29, + 0x3b,0x0a,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6d,0x61,0x69,0x6e,0x5f, + 0x6f,0x75,0x74,0x28,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x2c, + 0x20,0x75,0x76,0x2c,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x3b,0x0a,0x7d,0x0a,0x00, +}; +static const uint8_t _simgui_shd_fs_source_wgsl[585] = { + 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, + 0x64,0x65,0x72,0x69,0x76,0x61,0x74,0x69,0x76,0x65,0x5f,0x75,0x6e,0x69,0x66,0x6f, + 0x72,0x6d,0x69,0x74,0x79,0x29,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69, + 0x76,0x61,0x74,0x65,0x3e,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x3b,0x0a,0x0a,0x40,0x62,0x69,0x6e,0x64, + 0x69,0x6e,0x67,0x28,0x30,0x29,0x20,0x40,0x67,0x72,0x6f,0x75,0x70,0x28,0x31,0x29, + 0x20,0x76,0x61,0x72,0x20,0x74,0x65,0x78,0x20,0x3a,0x20,0x74,0x65,0x78,0x74,0x75, + 0x72,0x65,0x5f,0x32,0x64,0x3c,0x66,0x33,0x32,0x3e,0x3b,0x0a,0x0a,0x40,0x62,0x69, + 0x6e,0x64,0x69,0x6e,0x67,0x28,0x33,0x32,0x29,0x20,0x40,0x67,0x72,0x6f,0x75,0x70, + 0x28,0x31,0x29,0x20,0x76,0x61,0x72,0x20,0x73,0x6d,0x70,0x20,0x3a,0x20,0x73,0x61, + 0x6d,0x70,0x6c,0x65,0x72,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69,0x76, + 0x61,0x74,0x65,0x3e,0x20,0x75,0x76,0x20,0x3a,0x20,0x76,0x65,0x63,0x32,0x66,0x3b, + 0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69,0x76,0x61,0x74,0x65,0x3e,0x20,0x63, + 0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x3b,0x0a,0x0a,0x66, + 0x6e,0x20,0x6d,0x61,0x69,0x6e,0x5f,0x31,0x28,0x29,0x20,0x7b,0x0a,0x20,0x20,0x6c, + 0x65,0x74,0x20,0x78,0x5f,0x32,0x33,0x20,0x3d,0x20,0x75,0x76,0x3b,0x0a,0x20,0x20, + 0x6c,0x65,0x74,0x20,0x78,0x5f,0x32,0x34,0x20,0x3d,0x20,0x74,0x65,0x78,0x74,0x75, + 0x72,0x65,0x53,0x61,0x6d,0x70,0x6c,0x65,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d, + 0x70,0x2c,0x20,0x78,0x5f,0x32,0x33,0x29,0x3b,0x0a,0x20,0x20,0x66,0x72,0x61,0x67, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x28,0x78,0x5f,0x32,0x34,0x20,0x2a, + 0x20,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x3b,0x0a,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69, + 0x6e,0x5f,0x6f,0x75,0x74,0x20,0x7b,0x0a,0x20,0x20,0x40,0x6c,0x6f,0x63,0x61,0x74, + 0x69,0x6f,0x6e,0x28,0x30,0x29,0x0a,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x5f,0x31,0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x2c,0x0a,0x7d, + 0x0a,0x0a,0x40,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x0a,0x66,0x6e,0x20,0x6d, + 0x61,0x69,0x6e,0x28,0x40,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x28,0x30,0x29, + 0x20,0x75,0x76,0x5f,0x70,0x61,0x72,0x61,0x6d,0x20,0x3a,0x20,0x76,0x65,0x63,0x32, + 0x66,0x2c,0x20,0x40,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x28,0x31,0x29,0x20, + 0x63,0x6f,0x6c,0x6f,0x72,0x5f,0x70,0x61,0x72,0x61,0x6d,0x20,0x3a,0x20,0x76,0x65, + 0x63,0x34,0x66,0x29,0x20,0x2d,0x3e,0x20,0x6d,0x61,0x69,0x6e,0x5f,0x6f,0x75,0x74, + 0x20,0x7b,0x0a,0x20,0x20,0x75,0x76,0x20,0x3d,0x20,0x75,0x76,0x5f,0x70,0x61,0x72, + 0x61,0x6d,0x3b,0x0a,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f, + 0x6c,0x6f,0x72,0x5f,0x70,0x61,0x72,0x61,0x6d,0x3b,0x0a,0x20,0x20,0x6d,0x61,0x69, + 0x6e,0x5f,0x31,0x28,0x29,0x3b,0x0a,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x6d,0x61,0x69,0x6e,0x5f,0x6f,0x75,0x74,0x28,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x29,0x3b,0x0a,0x7d,0x0a,0x00, +}; +#elif defined(SOKOL_VULKAN) +static const uint8_t _simgui_shd_vs_bytecode_spirv_vk[1472] = { + 0x03,0x02,0x23,0x07,0x00,0x04,0x01,0x00,0x0b,0x00,0x08,0x00,0x30,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x11,0x00,0x02,0x00,0x01,0x00,0x00,0x00,0x0b,0x00,0x06,0x00, + 0x01,0x00,0x00,0x00,0x47,0x4c,0x53,0x4c,0x2e,0x73,0x74,0x64,0x2e,0x34,0x35,0x30, + 0x00,0x00,0x00,0x00,0x0e,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00, + 0x0f,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x6d,0x61,0x69,0x6e, + 0x00,0x00,0x00,0x00,0x0d,0x00,0x00,0x00,0x12,0x00,0x00,0x00,0x16,0x00,0x00,0x00, + 0x29,0x00,0x00,0x00,0x2a,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0x2e,0x00,0x00,0x00, + 0x03,0x00,0x03,0x00,0x02,0x00,0x00,0x00,0xcc,0x01,0x00,0x00,0x05,0x00,0x04,0x00, + 0x04,0x00,0x00,0x00,0x6d,0x61,0x69,0x6e,0x00,0x00,0x00,0x00,0x05,0x00,0x06,0x00, + 0x0b,0x00,0x00,0x00,0x67,0x6c,0x5f,0x50,0x65,0x72,0x56,0x65,0x72,0x74,0x65,0x78, + 0x00,0x00,0x00,0x00,0x06,0x00,0x06,0x00,0x0b,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x00,0x06,0x00,0x07,0x00, + 0x0b,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x67,0x6c,0x5f,0x50,0x6f,0x69,0x6e,0x74, + 0x53,0x69,0x7a,0x65,0x00,0x00,0x00,0x00,0x06,0x00,0x07,0x00,0x0b,0x00,0x00,0x00, + 0x02,0x00,0x00,0x00,0x67,0x6c,0x5f,0x43,0x6c,0x69,0x70,0x44,0x69,0x73,0x74,0x61, + 0x6e,0x63,0x65,0x00,0x06,0x00,0x07,0x00,0x0b,0x00,0x00,0x00,0x03,0x00,0x00,0x00, + 0x67,0x6c,0x5f,0x43,0x75,0x6c,0x6c,0x44,0x69,0x73,0x74,0x61,0x6e,0x63,0x65,0x00, + 0x05,0x00,0x03,0x00,0x0d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x05,0x00, + 0x12,0x00,0x00,0x00,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x00,0x00,0x00,0x00, + 0x05,0x00,0x05,0x00,0x14,0x00,0x00,0x00,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d, + 0x73,0x00,0x00,0x00,0x06,0x00,0x06,0x00,0x14,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x64,0x69,0x73,0x70,0x5f,0x73,0x69,0x7a,0x65,0x00,0x00,0x00,0x05,0x00,0x03,0x00, + 0x16,0x00,0x00,0x00,0x5f,0x32,0x32,0x00,0x05,0x00,0x03,0x00,0x29,0x00,0x00,0x00, + 0x75,0x76,0x00,0x00,0x05,0x00,0x05,0x00,0x2a,0x00,0x00,0x00,0x74,0x65,0x78,0x63, + 0x6f,0x6f,0x72,0x64,0x30,0x00,0x00,0x00,0x05,0x00,0x04,0x00,0x2c,0x00,0x00,0x00, + 0x63,0x6f,0x6c,0x6f,0x72,0x00,0x00,0x00,0x05,0x00,0x04,0x00,0x2e,0x00,0x00,0x00, + 0x63,0x6f,0x6c,0x6f,0x72,0x30,0x00,0x00,0x47,0x00,0x03,0x00,0x0b,0x00,0x00,0x00, + 0x02,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x0b,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x0b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x0b,0x00,0x00,0x00, + 0x01,0x00,0x00,0x00,0x0b,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x48,0x00,0x05,0x00, + 0x0b,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x0b,0x00,0x00,0x00,0x03,0x00,0x00,0x00, + 0x48,0x00,0x05,0x00,0x0b,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x0b,0x00,0x00,0x00, + 0x04,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x12,0x00,0x00,0x00,0x1e,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x47,0x00,0x03,0x00,0x14,0x00,0x00,0x00,0x02,0x00,0x00,0x00, + 0x48,0x00,0x05,0x00,0x14,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x16,0x00,0x00,0x00,0x21,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x16,0x00,0x00,0x00,0x22,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x29,0x00,0x00,0x00,0x1e,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x2a,0x00,0x00,0x00,0x1e,0x00,0x00,0x00, + 0x01,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x2c,0x00,0x00,0x00,0x1e,0x00,0x00,0x00, + 0x01,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x2e,0x00,0x00,0x00,0x1e,0x00,0x00,0x00, + 0x02,0x00,0x00,0x00,0x13,0x00,0x02,0x00,0x02,0x00,0x00,0x00,0x21,0x00,0x03,0x00, + 0x03,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x16,0x00,0x03,0x00,0x06,0x00,0x00,0x00, + 0x20,0x00,0x00,0x00,0x17,0x00,0x04,0x00,0x07,0x00,0x00,0x00,0x06,0x00,0x00,0x00, + 0x04,0x00,0x00,0x00,0x15,0x00,0x04,0x00,0x08,0x00,0x00,0x00,0x20,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x08,0x00,0x00,0x00,0x09,0x00,0x00,0x00, + 0x01,0x00,0x00,0x00,0x1c,0x00,0x04,0x00,0x0a,0x00,0x00,0x00,0x06,0x00,0x00,0x00, + 0x09,0x00,0x00,0x00,0x1e,0x00,0x06,0x00,0x0b,0x00,0x00,0x00,0x07,0x00,0x00,0x00, + 0x06,0x00,0x00,0x00,0x0a,0x00,0x00,0x00,0x0a,0x00,0x00,0x00,0x20,0x00,0x04,0x00, + 0x0c,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x0b,0x00,0x00,0x00,0x3b,0x00,0x04,0x00, + 0x0c,0x00,0x00,0x00,0x0d,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x15,0x00,0x04,0x00, + 0x0e,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, + 0x0e,0x00,0x00,0x00,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x17,0x00,0x04,0x00, + 0x10,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x20,0x00,0x04,0x00, + 0x11,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x3b,0x00,0x04,0x00, + 0x11,0x00,0x00,0x00,0x12,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x1e,0x00,0x03,0x00, + 0x14,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x15,0x00,0x00,0x00, + 0x02,0x00,0x00,0x00,0x14,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x15,0x00,0x00,0x00, + 0x16,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x17,0x00,0x00,0x00, + 0x02,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x06,0x00,0x00,0x00, + 0x1b,0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0x2c,0x00,0x05,0x00,0x10,0x00,0x00,0x00, + 0x1c,0x00,0x00,0x00,0x1b,0x00,0x00,0x00,0x1b,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, + 0x06,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x2b,0x00,0x04,0x00, + 0x06,0x00,0x00,0x00,0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0xc0,0x2c,0x00,0x05,0x00, + 0x10,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,0x1f,0x00,0x00,0x00, + 0x2b,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x22,0x00,0x00,0x00,0x00,0x00,0x80,0x3f, + 0x20,0x00,0x04,0x00,0x26,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x07,0x00,0x00,0x00, + 0x20,0x00,0x04,0x00,0x28,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x10,0x00,0x00,0x00, + 0x3b,0x00,0x04,0x00,0x28,0x00,0x00,0x00,0x29,0x00,0x00,0x00,0x03,0x00,0x00,0x00, + 0x3b,0x00,0x04,0x00,0x11,0x00,0x00,0x00,0x2a,0x00,0x00,0x00,0x01,0x00,0x00,0x00, + 0x3b,0x00,0x04,0x00,0x26,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0x03,0x00,0x00,0x00, + 0x20,0x00,0x04,0x00,0x2d,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x07,0x00,0x00,0x00, + 0x3b,0x00,0x04,0x00,0x2d,0x00,0x00,0x00,0x2e,0x00,0x00,0x00,0x01,0x00,0x00,0x00, + 0x36,0x00,0x05,0x00,0x02,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x03,0x00,0x00,0x00,0xf8,0x00,0x02,0x00,0x05,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, + 0x10,0x00,0x00,0x00,0x13,0x00,0x00,0x00,0x12,0x00,0x00,0x00,0x41,0x00,0x05,0x00, + 0x17,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x16,0x00,0x00,0x00,0x0f,0x00,0x00,0x00, + 0x3d,0x00,0x04,0x00,0x10,0x00,0x00,0x00,0x19,0x00,0x00,0x00,0x18,0x00,0x00,0x00, + 0x88,0x00,0x05,0x00,0x10,0x00,0x00,0x00,0x1a,0x00,0x00,0x00,0x13,0x00,0x00,0x00, + 0x19,0x00,0x00,0x00,0x83,0x00,0x05,0x00,0x10,0x00,0x00,0x00,0x1d,0x00,0x00,0x00, + 0x1a,0x00,0x00,0x00,0x1c,0x00,0x00,0x00,0x85,0x00,0x05,0x00,0x10,0x00,0x00,0x00, + 0x21,0x00,0x00,0x00,0x1d,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x51,0x00,0x05,0x00, + 0x06,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x21,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x51,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0x24,0x00,0x00,0x00,0x21,0x00,0x00,0x00, + 0x01,0x00,0x00,0x00,0x50,0x00,0x07,0x00,0x07,0x00,0x00,0x00,0x25,0x00,0x00,0x00, + 0x23,0x00,0x00,0x00,0x24,0x00,0x00,0x00,0x1b,0x00,0x00,0x00,0x22,0x00,0x00,0x00, + 0x41,0x00,0x05,0x00,0x26,0x00,0x00,0x00,0x27,0x00,0x00,0x00,0x0d,0x00,0x00,0x00, + 0x0f,0x00,0x00,0x00,0x3e,0x00,0x03,0x00,0x27,0x00,0x00,0x00,0x25,0x00,0x00,0x00, + 0x3d,0x00,0x04,0x00,0x10,0x00,0x00,0x00,0x2b,0x00,0x00,0x00,0x2a,0x00,0x00,0x00, + 0x3e,0x00,0x03,0x00,0x29,0x00,0x00,0x00,0x2b,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, + 0x07,0x00,0x00,0x00,0x2f,0x00,0x00,0x00,0x2e,0x00,0x00,0x00,0x3e,0x00,0x03,0x00, + 0x2c,0x00,0x00,0x00,0x2f,0x00,0x00,0x00,0xfd,0x00,0x01,0x00,0x38,0x00,0x01,0x00, +}; +static const uint8_t _simgui_shd_fs_bytecode_spirv_vk[780] = { + 0x03,0x02,0x23,0x07,0x00,0x04,0x01,0x00,0x0b,0x00,0x08,0x00,0x1d,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x11,0x00,0x02,0x00,0x01,0x00,0x00,0x00,0x0b,0x00,0x06,0x00, + 0x01,0x00,0x00,0x00,0x47,0x4c,0x53,0x4c,0x2e,0x73,0x74,0x64,0x2e,0x34,0x35,0x30, + 0x00,0x00,0x00,0x00,0x0e,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00, + 0x0f,0x00,0x0a,0x00,0x04,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x6d,0x61,0x69,0x6e, + 0x00,0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x10,0x00,0x00,0x00, + 0x16,0x00,0x00,0x00,0x1a,0x00,0x00,0x00,0x10,0x00,0x03,0x00,0x04,0x00,0x00,0x00, + 0x07,0x00,0x00,0x00,0x03,0x00,0x03,0x00,0x02,0x00,0x00,0x00,0xcc,0x01,0x00,0x00, + 0x05,0x00,0x04,0x00,0x04,0x00,0x00,0x00,0x6d,0x61,0x69,0x6e,0x00,0x00,0x00,0x00, + 0x05,0x00,0x05,0x00,0x09,0x00,0x00,0x00,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x00,0x00,0x05,0x00,0x03,0x00,0x0c,0x00,0x00,0x00,0x74,0x65,0x78,0x00, + 0x05,0x00,0x03,0x00,0x10,0x00,0x00,0x00,0x73,0x6d,0x70,0x00,0x05,0x00,0x03,0x00, + 0x16,0x00,0x00,0x00,0x75,0x76,0x00,0x00,0x05,0x00,0x04,0x00,0x1a,0x00,0x00,0x00, + 0x63,0x6f,0x6c,0x6f,0x72,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x09,0x00,0x00,0x00, + 0x1e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x0c,0x00,0x00,0x00, + 0x21,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x0c,0x00,0x00,0x00, + 0x22,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x10,0x00,0x00,0x00, + 0x21,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x10,0x00,0x00,0x00, + 0x22,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x16,0x00,0x00,0x00, + 0x1e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x1a,0x00,0x00,0x00, + 0x1e,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x13,0x00,0x02,0x00,0x02,0x00,0x00,0x00, + 0x21,0x00,0x03,0x00,0x03,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x16,0x00,0x03,0x00, + 0x06,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x17,0x00,0x04,0x00,0x07,0x00,0x00,0x00, + 0x06,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x08,0x00,0x00,0x00, + 0x03,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x08,0x00,0x00,0x00, + 0x09,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x19,0x00,0x09,0x00,0x0a,0x00,0x00,0x00, + 0x06,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x04,0x00, + 0x0b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0a,0x00,0x00,0x00,0x3b,0x00,0x04,0x00, + 0x0b,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1a,0x00,0x02,0x00, + 0x0e,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x0e,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x0f,0x00,0x00,0x00,0x10,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x1b,0x00,0x03,0x00,0x12,0x00,0x00,0x00,0x0a,0x00,0x00,0x00, + 0x17,0x00,0x04,0x00,0x14,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x02,0x00,0x00,0x00, + 0x20,0x00,0x04,0x00,0x15,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x14,0x00,0x00,0x00, + 0x3b,0x00,0x04,0x00,0x15,0x00,0x00,0x00,0x16,0x00,0x00,0x00,0x01,0x00,0x00,0x00, + 0x20,0x00,0x04,0x00,0x19,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x07,0x00,0x00,0x00, + 0x3b,0x00,0x04,0x00,0x19,0x00,0x00,0x00,0x1a,0x00,0x00,0x00,0x01,0x00,0x00,0x00, + 0x36,0x00,0x05,0x00,0x02,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x03,0x00,0x00,0x00,0xf8,0x00,0x02,0x00,0x05,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, + 0x0a,0x00,0x00,0x00,0x0d,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, + 0x0e,0x00,0x00,0x00,0x11,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x56,0x00,0x05,0x00, + 0x12,0x00,0x00,0x00,0x13,0x00,0x00,0x00,0x0d,0x00,0x00,0x00,0x11,0x00,0x00,0x00, + 0x3d,0x00,0x04,0x00,0x14,0x00,0x00,0x00,0x17,0x00,0x00,0x00,0x16,0x00,0x00,0x00, + 0x57,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x13,0x00,0x00,0x00, + 0x17,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00,0x1b,0x00,0x00,0x00, + 0x1a,0x00,0x00,0x00,0x85,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0x1c,0x00,0x00,0x00, + 0x18,0x00,0x00,0x00,0x1b,0x00,0x00,0x00,0x3e,0x00,0x03,0x00,0x09,0x00,0x00,0x00, + 0x1c,0x00,0x00,0x00,0xfd,0x00,0x01,0x00,0x38,0x00,0x01,0x00, +}; +#elif defined(SOKOL_DUMMY_BACKEND) +static const char* _simgui_vs_source_dummy = ""; +static const char* _simgui_fs_source_dummy = ""; +#else +#error "Please define one of SOKOL_GLCORE, SOKOL_GLES3, SOKOL_D3D11, SOKOL_METAL, SOKOL_WGPU, SOKOL_VULKAN or SOKOL_DUMMY_BACKEND!" +#endif +//<#shdgen + +#if !defined(SOKOL_IMGUI_NO_SOKOL_APP) +static void _simgui_set_clipboard(ImGuiContext* ctx, const char* text) { + (void)ctx; + sapp_set_clipboard_string(text); +} + +static const char* _simgui_get_clipboard(ImGuiContext* ctx) { + (void)ctx; + return sapp_get_clipboard_string(); +} +#endif + +#if defined(__EMSCRIPTEN__) && !defined(SOKOL_DUMMY_BACKEND) +EM_JS(int, simgui_js_is_osx, (void), { + if (navigator.userAgent.includes('Macintosh')) { + return 1; + } else { + return 0; + } +}) +#endif + +// ██ ██████ ██████ ██████ ██ ███ ██ ██████ +// ██ ██ ██ ██ ██ ██ ████ ██ ██ +// ██ ██ ██ ██ ███ ██ ███ ██ ██ ██ ██ ██ ███ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ███████ ██████ ██████ ██████ ██ ██ ████ ██████ +// +// >>logging +#if defined(SOKOL_DEBUG) +#define _SIMGUI_LOGITEM_XMACRO(item,msg) #item ": " msg, +static const char* _simgui_log_messages[] = { + _SIMGUI_LOG_ITEMS +}; +#undef _SIMGUI_LOGITEM_XMACRO +#endif // SOKOL_DEBUG + +#define _SIMGUI_PANIC(code) _simgui_log(SIMGUI_LOGITEM_ ##code, 0, 0, __LINE__) +#define _SIMGUI_ERROR(code) _simgui_log(SIMGUI_LOGITEM_ ##code, 1, 0, __LINE__) +#define _SIMGUI_WARN(code) _simgui_log(SIMGUI_LOGITEM_ ##code, 2, 0, __LINE__) +#define _SIMGUI_INFO(code) _simgui_log(SIMGUI_LOGITEM_ ##code, 3, 0, __LINE__) +#define _SIMGUI_LOGMSG(code,msg) _simgui_log(SIMGUI_LOGITEM_ ##code, 3, msg, __LINE__) + +static void _simgui_log(simgui_log_item_t log_item, uint32_t log_level, const char* msg, uint32_t line_nr) { + if (_simgui.desc.logger.func) { + const char* filename = 0; + #if defined(SOKOL_DEBUG) + filename = __FILE__; + if (0 == msg) { + msg = _simgui_log_messages[log_item]; + } + #endif + _simgui.desc.logger.func("simgui", log_level, (uint32_t)log_item, msg, line_nr, filename, _simgui.desc.logger.user_data); + } else { + // for log level PANIC it would be 'undefined behaviour' to continue + if (log_level == 0) { + abort(); + } + } +} + +// ███ ███ ███████ ███ ███ ██████ ██████ ██ ██ +// ████ ████ ██ ████ ████ ██ ██ ██ ██ ██ ██ +// ██ ████ ██ █████ ██ ████ ██ ██ ██ ██████ ████ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ██ ██ ███████ ██ ██ ██████ ██ ██ ██ +// +// >>memory +static void _simgui_clear(void* ptr, size_t size) { + SOKOL_ASSERT(ptr && (size > 0)); + memset(ptr, 0, size); +} + +static void* _simgui_malloc(size_t size) { + SOKOL_ASSERT(size > 0); + void* ptr; + if (_simgui.desc.allocator.alloc_fn) { + ptr = _simgui.desc.allocator.alloc_fn(size, _simgui.desc.allocator.user_data); + } else { + ptr = malloc(size); + } + if (0 == ptr) { + _SIMGUI_PANIC(MALLOC_FAILED); + } + return ptr; +} + +static void _simgui_free(void* ptr) { + if (_simgui.desc.allocator.free_fn) { + _simgui.desc.allocator.free_fn(ptr, _simgui.desc.allocator.user_data); + } else { + free(ptr); + } +} + +static bool _simgui_is_osx(void) { + #if defined(SOKOL_DUMMY_BACKEND) + return false; + #elif defined(__EMSCRIPTEN__) + return simgui_js_is_osx(); + #elif defined(__APPLE__) + return true; + #else + return false; + #endif +} + +static simgui_desc_t _simgui_desc_defaults(const simgui_desc_t* desc) { + SOKOL_ASSERT((desc->allocator.alloc_fn && desc->allocator.free_fn) || (!desc->allocator.alloc_fn && !desc->allocator.free_fn)); + simgui_desc_t res = *desc; + res.max_vertices = _simgui_def(res.max_vertices, 65536); + return res; +} + +static ImGuiPlatformIO* _simgui_imgui_get_platform_io(void) { + #if defined(__cplusplus) + return &ImGui::GetPlatformIO(); + #else + #if defined(CIMGUI_INCLUDED) + // 'original' cimgui + return _SIMGUI_CFUNC(GetPlatformIO_Nil)(); + #else + // dear bindings cimgui + return _SIMGUI_CFUNC(GetPlatformIO)(); + #endif + #endif +} + +static ImGuiIO* _simgui_imgui_get_io(void) { + #if defined(__cplusplus) + return &ImGui::GetIO(); + #else + #if defined(CIMGUI_INCLUDED) + // 'original' cimgui + return _SIMGUI_CFUNC(GetIO_Nil)(); + #else + // dear bindings cimgui + return _SIMGUI_CFUNC(GetIO)(); + #endif + #endif +} + +static void _simgui_imgui_newframe(void) { + #if defined(__cplusplus) + ImGui::NewFrame(); + #else + _SIMGUI_CFUNC(NewFrame)(); + #endif +} + +static void _simgui_imgui_create_context(void) { + #if defined(__cplusplus) + ImGui::CreateContext(); + #else + _SIMGUI_CFUNC(CreateContext)(0); + #endif +} + +static void _simgui_imgui_destroy_context(void) { + #if defined(__cplusplus) + ImGui::DestroyContext(); + #else + _SIMGUI_CFUNC(DestroyContext)(0); + #endif +} + +static void _simgui_imgui_style_colors_dark(void) { + #if defined(__cplusplus) + ImGui::StyleColorsDark(); + #else + _SIMGUI_CFUNC(StyleColorsDark)(_SIMGUI_CFUNC(GetStyle)()); + #endif +} + +static void _simgui_io_add_font_default(ImGuiIO* io) { + #if defined(__cplusplus) + io->Fonts->AddFontDefault(); + #else + ImFontAtlas_AddFontDefault(io->Fonts, 0); + #endif +} + +static void _simgui_io_add_focus_event(ImGuiIO* io, bool focus) { + #if defined(__cplusplus) + io->AddFocusEvent(focus); + #else + ImGuiIO_AddFocusEvent(io, focus); + #endif +} + +static void _simgui_io_add_mouse_source_event(ImGuiIO* io, ImGuiMouseSource source) { + #if defined(__cplusplus) + io->AddMouseSourceEvent(source); + #else + ImGuiIO_AddMouseSourceEvent(io, source); + #endif +} + +static void _simgui_io_add_mouse_pos_event(ImGuiIO* io, float x, float y) { + #if defined(__cplusplus) + io->AddMousePosEvent(x, y); + #else + ImGuiIO_AddMousePosEvent(io, x, y); + #endif +} + +static void _simgui_io_add_mouse_button_event(ImGuiIO* io, int mouse_button, bool down) { + #if defined(__cplusplus) + io->AddMouseButtonEvent(mouse_button, down); + #else + ImGuiIO_AddMouseButtonEvent(io, mouse_button, down); + #endif +} + +static void _simgui_io_add_mouse_wheel_event(ImGuiIO* io, float x, float y) { + #if defined(__cplusplus) + io->AddMouseWheelEvent(x, y); + #else + ImGuiIO_AddMouseWheelEvent(io, x, y); + #endif +} + +static void _simgui_io_add_key_event(ImGuiIO* io, ImGuiKey imgui_key, bool down) { + #if defined(__cplusplus) + io->AddKeyEvent(imgui_key, down); + #else + ImGuiIO_AddKeyEvent(io, imgui_key, down); + #endif +} + +static void _simgui_io_add_input_character(ImGuiIO* io, uint32_t c) { + #if defined(__cplusplus) + io->AddInputCharacter(c); + #else + ImGuiIO_AddInputCharacter(io, c); + #endif +} + +static void _simgui_io_add_input_characters_utf8(ImGuiIO* io, const char* c) { + #if defined(__cplusplus) + io->AddInputCharactersUTF8(c); + #else + ImGuiIO_AddInputCharactersUTF8(io, c); + #endif +} + +#if !defined(SOKOL_IMGUI_NO_SOKOL_APP) +static ImGuiMouseCursor _simgui_imgui_get_mouse_cursor(void) { + #if defined(__cplusplus) + return ImGui::GetMouseCursor(); + #else + return _SIMGUI_CFUNC(GetMouseCursor)(); + #endif +} +#endif + +static ImDrawList* _simgui_imdrawlist_at(ImDrawData* draw_data, int cl_index) { + #if defined(__cplusplus) + return draw_data->CmdLists[cl_index]; + #else + return draw_data->CmdLists.Data[cl_index]; + #endif +} + +static ImTextureID _simgui_imtexturedata_gettexid(ImTextureData* tex) { + #if defined(__cplusplus) + return tex->GetTexID(); + #else + return ImTextureData_GetTexID(tex); + #endif +} + +static void _simgui_imtexturedata_settexid(ImTextureData* tex, ImTextureID tex_id) { + #if defined(__cplusplus) + tex->SetTexID(tex_id); + #else + ImTextureData_SetTexID(tex, tex_id); + #endif +} + +static void _simgui_imtexturedata_setstatus(ImTextureData* tex, ImTextureStatus status) { + #if defined(__cplusplus) + tex->SetStatus(status); + #else + ImTextureData_SetStatus(tex, status); + #endif +} + +static void* _simgui_imtexturedata_getpixels(ImTextureData* tex) { + #if defined(__cplusplus) + return tex->GetPixels(); + #else + return ImTextureData_GetPixels(tex); + #endif +} + +static int _simgui_imtexturedata_getsizeinbytes(ImTextureData* tex) { + #if defined(__cplusplus) + return tex->GetSizeInBytes(); + #else + return ImTextureData_GetSizeInBytes(tex); + #endif +} + +static ImTextureID _simgui_imdrawcmd_gettexid(ImDrawCmd* cmd) { + #if defined(__cplusplus) + return cmd->GetTexID(); + #else + return ImDrawCmd_GetTexID(cmd); + #endif +} + +static int _simgui_imdrawlist_cmd_buffer_size(ImDrawList* cl) { + #if defined(__cplusplus) + return cl->CmdBuffer.size(); + #else + return cl->CmdBuffer.Size; + #endif +} + +static int _simgui_imdrawlist_vtx_buffer_size(ImDrawList* cl) { + #if defined(__cplusplus) + return cl->VtxBuffer.size(); + #else + return cl->VtxBuffer.Size; + #endif +} + +static int _simgui_imdrawlist_idx_buffer_size(ImDrawList* cl) { + #if defined(__cplusplus) + return cl->IdxBuffer.size(); + #else + return cl->IdxBuffer.Size; + #endif +} + +static void _simgui_imgui_render(void) { + #if defined(__cplusplus) + ImGui::Render(); + #else + _SIMGUI_CFUNC(Render)(); + #endif +} + +static ImDrawData* _simgui_imgui_get_draw_data(void) { + #if defined(__cplusplus) + return ImGui::GetDrawData(); + #else + return _SIMGUI_CFUNC(GetDrawData)(); + #endif +} + +static void _simgui_destroy_texture(ImTextureData* tex) { + SOKOL_ASSERT(tex); + const sg_view view = simgui_texture_view_from_imtextureid(_simgui_imtexturedata_gettexid(tex)); + const sg_image img = sg_query_view_image(view); + SOKOL_ASSERT(img.id != SG_INVALID_ID); + const sg_sampler smp = simgui_sampler_from_imtextureid(_simgui_imtexturedata_gettexid(tex)); + sg_destroy_view(view); + sg_destroy_image(img); + sg_destroy_sampler(smp); + _simgui_imtexturedata_settexid(tex, ImTextureID_Invalid); + _simgui_imtexturedata_setstatus(tex, ImTextureStatus_Destroyed); +} + +static void _simgui_update_texture(ImTextureData* tex) { + SOKOL_ASSERT(tex); + SOKOL_ASSERT(tex->Format == ImTextureFormat_RGBA32); + if (tex->Status == ImTextureStatus_WantCreate) { + // create new sokol-gfx image, view and sampler + SOKOL_ASSERT(tex->TexID == 0); + sg_image_desc img_desc; + _simgui_clear(&img_desc, sizeof(img_desc)); + img_desc.usage.dynamic_update = true; + img_desc.width = tex->Width; + img_desc.height = tex->Height; + img_desc.pixel_format = SG_PIXELFORMAT_RGBA8; + img_desc.label = "sokol-imgui-texture"; + sg_image img = sg_make_image(&img_desc); + + sg_view_desc view_desc; + _simgui_clear(&view_desc, sizeof(view_desc)); + view_desc.texture.image = img; + view_desc.label = "sokol-imgui-texture-view"; + sg_view view = sg_make_view(&view_desc); + + sg_sampler_desc smp_desc; + _simgui_clear(&smp_desc, sizeof(smp_desc)); + smp_desc.wrap_u = SG_WRAP_CLAMP_TO_EDGE; + smp_desc.wrap_v = SG_WRAP_CLAMP_TO_EDGE; + smp_desc.min_filter = SG_FILTER_LINEAR; + smp_desc.mag_filter = SG_FILTER_LINEAR; + smp_desc.label = "sokol-imgui-sampler"; + sg_sampler smp = sg_make_sampler(&smp_desc); + + _simgui_imtexturedata_settexid(tex, simgui_imtextureid_with_sampler(view, smp)); + } + if ((tex->Status == ImTextureStatus_WantCreate) || (tex->Status == ImTextureStatus_WantUpdates)) { + SOKOL_ASSERT(tex->TexID != 0); + const sg_view view = simgui_texture_view_from_imtextureid(_simgui_imtexturedata_gettexid(tex)); + const sg_image img = sg_query_view_image(view); + SOKOL_ASSERT(img.id != SG_INVALID_ID); + sg_image_data img_data; + _simgui_clear(&img_data, sizeof(img_data)); + img_data.mip_levels[0].ptr = _simgui_imtexturedata_getpixels(tex); + img_data.mip_levels[0].size = (size_t)_simgui_imtexturedata_getsizeinbytes(tex); + sg_update_image(img, &img_data); + _simgui_imtexturedata_setstatus(tex, ImTextureStatus_OK); + } + if ((tex->Status == ImTextureStatus_WantDestroy) && (tex->UnusedFrames > 0)) { + SOKOL_ASSERT(tex->TexID != 0); + _simgui_destroy_texture(tex); + } +} + +// ██████ ██ ██ ██████ ██ ██ ██████ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ██████ ██ ██ ██████ ██ ██ ██ +// ██ ██ ██ ██ ██ ██ ██ ██ +// ██ ██████ ██████ ███████ ██ ██████ +// +// >>public +SOKOL_API_IMPL void simgui_setup(const simgui_desc_t* desc) { + SOKOL_ASSERT(desc); + _simgui_clear(&_simgui, sizeof(_simgui)); + _simgui.init_cookie = _SIMGUI_INIT_COOKIE; + _simgui.desc = _simgui_desc_defaults(desc); + _simgui.cur_dpi_scale = 1.0f; + #if !defined(SOKOL_IMGUI_NO_SOKOL_APP) + _simgui.is_osx = _simgui_is_osx(); + #endif + // can keep color_format, depth_format and sample_count as is, + // since sokol_gfx.h will do its own default-value handling + + // allocate an intermediate vertex- and index-buffer + SOKOL_ASSERT(_simgui.desc.max_vertices > 0); + _simgui.vertices.size = (size_t)_simgui.desc.max_vertices * sizeof(ImDrawVert); + _simgui.vertices.ptr = _simgui_malloc(_simgui.vertices.size); + _simgui.indices.size = (size_t)_simgui.desc.max_vertices * 3 * sizeof(ImDrawIdx); + _simgui.indices.ptr = _simgui_malloc(_simgui.indices.size); + + // initialize Dear ImGui + _simgui_imgui_create_context(); + _simgui_imgui_style_colors_dark(); + ImGuiIO* io = _simgui_imgui_get_io(); + if (!_simgui.desc.no_default_font) { + _simgui_io_add_font_default(io); + } + io->IniFilename = _simgui.desc.ini_filename; + io->ConfigMacOSXBehaviors = _simgui_is_osx(); + io->BackendRendererName = "sokol-imgui"; + io->BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures; + #if !defined(SOKOL_IMGUI_NO_SOKOL_APP) + if (!_simgui.desc.disable_set_mouse_cursor) { + io->BackendFlags |= ImGuiBackendFlags_HasMouseCursors; + } + ImGuiPlatformIO* pio = _simgui_imgui_get_platform_io(); + pio->Platform_SetClipboardTextFn = _simgui_set_clipboard; + pio->Platform_GetClipboardTextFn = _simgui_get_clipboard; + #endif + io->ConfigWindowsResizeFromEdges = !_simgui.desc.disable_windows_resize_from_edges; + + // create sokol-gfx resources + sg_push_debug_group("sokol-imgui"); + + // shader object for using the embedded shader source (or bytecode) + sg_shader_desc shd_desc; + _simgui_clear(&shd_desc, sizeof(shd_desc)); + shd_desc.attrs[0].glsl_name = "position"; + shd_desc.attrs[1].glsl_name = "texcoord0"; + shd_desc.attrs[2].glsl_name = "color0"; + shd_desc.attrs[0].hlsl_sem_name = "TEXCOORD"; + shd_desc.attrs[0].hlsl_sem_index = 0; + shd_desc.attrs[1].hlsl_sem_name = "TEXCOORD"; + shd_desc.attrs[1].hlsl_sem_index = 1; + shd_desc.attrs[2].hlsl_sem_name = "TEXCOORD"; + shd_desc.attrs[2].hlsl_sem_index = 2; + shd_desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + shd_desc.attrs[1].base_type = SG_SHADERATTRBASETYPE_FLOAT; + shd_desc.attrs[2].base_type = SG_SHADERATTRBASETYPE_FLOAT; + shd_desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + shd_desc.uniform_blocks[0].size = sizeof(_simgui_vs_params_t); + shd_desc.uniform_blocks[0].hlsl_register_b_n = 0; + shd_desc.uniform_blocks[0].msl_buffer_n = 0; + shd_desc.uniform_blocks[0].wgsl_group0_binding_n = 0; + shd_desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "vs_params"; + shd_desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + shd_desc.uniform_blocks[0].glsl_uniforms[0].array_count = 1; + shd_desc.uniform_blocks[0].spirv_set0_binding_n = 0; + shd_desc.views[0].texture.stage = SG_SHADERSTAGE_FRAGMENT; + shd_desc.views[0].texture.image_type = SG_IMAGETYPE_2D; + shd_desc.views[0].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + shd_desc.views[0].texture.hlsl_register_t_n = 0; + shd_desc.views[0].texture.msl_texture_n = 0; + shd_desc.views[0].texture.wgsl_group1_binding_n = 0; + shd_desc.views[0].texture.spirv_set1_binding_n = 0; + shd_desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + shd_desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; + shd_desc.samplers[0].hlsl_register_s_n = 0; + shd_desc.samplers[0].msl_sampler_n = 0; + shd_desc.samplers[0].wgsl_group1_binding_n = 32; + shd_desc.samplers[0].spirv_set1_binding_n = 32; + shd_desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + shd_desc.texture_sampler_pairs[0].view_slot = 0; + shd_desc.texture_sampler_pairs[0].sampler_slot = 0; + shd_desc.texture_sampler_pairs[0].glsl_name = "tex_smp"; + shd_desc.label = "sokol-imgui-shader"; + #if defined(SOKOL_GLCORE) + shd_desc.vertex_func.source = (const char*)_simgui_shd_vs_source_glsl410; + shd_desc.fragment_func.source = (const char*)_simgui_shd_fs_source_glsl410; + #elif defined(SOKOL_GLES3) + shd_desc.vertex_func.source = (const char*)_simgui_shd_vs_source_glsl300es; + shd_desc.fragment_func.source = (const char*)_simgui_shd_fs_source_glsl300es; + #elif defined(SOKOL_METAL) + shd_desc.vertex_func.entry = "main0"; + shd_desc.fragment_func.entry = "main0"; + switch (sg_query_backend()) { + case SG_BACKEND_METAL_MACOS: + shd_desc.vertex_func.bytecode = SG_RANGE(_simgui_shd_vs_bytecode_metal_macos); + shd_desc.fragment_func.bytecode = SG_RANGE(_simgui_shd_fs_bytecode_metal_macos); + break; + case SG_BACKEND_METAL_IOS: + shd_desc.vertex_func.bytecode = SG_RANGE(_simgui_shd_vs_bytecode_metal_ios); + shd_desc.fragment_func.bytecode = SG_RANGE(_simgui_shd_fs_bytecode_metal_ios); + break; + default: + shd_desc.vertex_func.source = (const char*)_simgui_shd_vs_source_metal_sim; + shd_desc.fragment_func.source = (const char*)_simgui_shd_fs_source_metal_sim; + break; + } + #elif defined(SOKOL_D3D11) + shd_desc.vertex_func.bytecode = SG_RANGE(_simgui_shd_vs_bytecode_hlsl4); + shd_desc.fragment_func.bytecode = SG_RANGE(_simgui_shd_fs_bytecode_hlsl4); + #elif defined(SOKOL_WGPU) + shd_desc.vertex_func.source = (const char*)_simgui_shd_vs_source_wgsl; + shd_desc.fragment_func.source = (const char*)_simgui_shd_fs_source_wgsl; + #elif defined(SOKOL_VULKAN) + shd_desc.vertex_func.bytecode = SG_RANGE(_simgui_shd_vs_bytecode_spirv_vk); + shd_desc.vertex_func.entry = "main"; + shd_desc.fragment_func.bytecode = SG_RANGE(_simgui_shd_fs_bytecode_spirv_vk); + shd_desc.fragment_func.entry = "main"; + #else + shd_desc.vertex_func.source = _simgui_vs_source_dummy; + shd_desc.fragment_func.source = _simgui_fs_source_dummy; + #endif + _simgui.def_shd = sg_make_shader(&shd_desc); + + // pipeline object for imgui rendering + sg_pipeline_desc pip_desc; + _simgui_clear(&pip_desc, sizeof(pip_desc)); + pip_desc.layout.buffers[0].stride = sizeof(ImDrawVert); + { + sg_vertex_attr_state* attr = &pip_desc.layout.attrs[0]; + attr->offset = offsetof(ImDrawVert, pos); + attr->format = SG_VERTEXFORMAT_FLOAT2; + } + { + sg_vertex_attr_state* attr = &pip_desc.layout.attrs[1]; + attr->offset = offsetof(ImDrawVert, uv); + attr->format = SG_VERTEXFORMAT_FLOAT2; + } + { + sg_vertex_attr_state* attr = &pip_desc.layout.attrs[2]; + attr->offset = offsetof(ImDrawVert, col); + attr->format = SG_VERTEXFORMAT_UBYTE4N; + } + pip_desc.shader = _simgui.def_shd; + pip_desc.index_type = SG_INDEXTYPE_UINT16; + pip_desc.sample_count = _simgui.desc.sample_count; + pip_desc.depth.pixel_format = _simgui.desc.depth_format; + pip_desc.colors[0].pixel_format = _simgui.desc.color_format; + pip_desc.colors[0].write_mask = _simgui.desc.write_alpha_channel ? SG_COLORMASK_RGBA : SG_COLORMASK_RGB; + pip_desc.colors[0].blend.enabled = true; + pip_desc.colors[0].blend.src_factor_rgb = SG_BLENDFACTOR_SRC_ALPHA; + pip_desc.colors[0].blend.dst_factor_rgb = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA; + if (_simgui.desc.write_alpha_channel) { + pip_desc.colors[0].blend.src_factor_alpha = SG_BLENDFACTOR_ONE; + pip_desc.colors[0].blend.dst_factor_alpha = SG_BLENDFACTOR_ONE; + } + pip_desc.label = "sokol-imgui-pipeline"; + _simgui.def_pip = sg_make_pipeline(&pip_desc); + + // create unfilterable/nonfiltering variants of the shader and pipeline + shd_desc.views[0].texture.sample_type = SG_IMAGESAMPLETYPE_UNFILTERABLE_FLOAT; + shd_desc.samplers[0].sampler_type = SG_SAMPLERTYPE_NONFILTERING; + shd_desc.label = "sokol-imgui-shader-unfilterable"; + _simgui.shd_unfilterable = sg_make_shader(&shd_desc); + pip_desc.shader = _simgui.shd_unfilterable; + pip_desc.label = "sokol-imgui-pipeline-unfilterable"; + _simgui.pip_unfilterable = sg_make_pipeline(&pip_desc); + + // NOTE: since we're in C++ mode here we can't use C99 designated init + sg_buffer_desc vb_desc; + _simgui_clear(&vb_desc, sizeof(vb_desc)); + vb_desc.usage.stream_update = true; + vb_desc.size = _simgui.vertices.size; + vb_desc.label = "sokol-imgui-vertices"; + _simgui.vbuf = sg_make_buffer(&vb_desc); + + sg_buffer_desc ib_desc; + _simgui_clear(&ib_desc, sizeof(ib_desc)); + ib_desc.usage.index_buffer = true; + ib_desc.usage.stream_update = true; + ib_desc.size = _simgui.indices.size; + ib_desc.label = "sokol-imgui-indices"; + _simgui.ibuf = sg_make_buffer(&ib_desc); + + // a default user-image sampler + sg_sampler_desc def_sampler_desc; + _simgui_clear(&def_sampler_desc, sizeof(def_sampler_desc)); + def_sampler_desc.min_filter = SG_FILTER_NEAREST; + def_sampler_desc.mag_filter = SG_FILTER_NEAREST; + def_sampler_desc.wrap_u = SG_WRAP_CLAMP_TO_EDGE; + def_sampler_desc.wrap_v = SG_WRAP_CLAMP_TO_EDGE; + def_sampler_desc.label = "sokol-imgui-default-sampler"; + _simgui.def_smp = sg_make_sampler(&def_sampler_desc); + + sg_pop_debug_group(); +} + +SOKOL_API_IMPL void simgui_shutdown(void) { + SOKOL_ASSERT(_SIMGUI_INIT_COOKIE == _simgui.init_cookie); + + const ImGuiPlatformIO* pio = _simgui_imgui_get_platform_io(); + for (size_t i = 0; i < (size_t)pio->Textures.Size; i++) { + ImTextureData* tex = pio->Textures.Data[i]; + if (tex->RefCount == 1) { + _simgui_destroy_texture(tex); + } + } + _simgui_imgui_destroy_context(); + + // NOTE: it's valid to call the destroy funcs with SG_INVALID_ID + sg_push_debug_group("sokol-imgui"); + sg_destroy_pipeline(_simgui.pip_unfilterable); + sg_destroy_shader(_simgui.shd_unfilterable); + sg_destroy_pipeline(_simgui.def_pip); + sg_destroy_shader(_simgui.def_shd); + sg_destroy_sampler(_simgui.def_smp); + sg_destroy_buffer(_simgui.ibuf); + sg_destroy_buffer(_simgui.vbuf); + sg_pop_debug_group(); + SOKOL_ASSERT(_simgui.vertices.ptr); + _simgui_free((void*)_simgui.vertices.ptr); + SOKOL_ASSERT(_simgui.indices.ptr); + _simgui_free((void*)_simgui.indices.ptr); + _simgui.init_cookie = 0; +} + +SOKOL_API_IMPL uint64_t simgui_imtextureid_with_sampler(sg_view tex_view, sg_sampler smp) { + uint32_t view_id = tex_view.id; + uint32_t smp_id = smp.id; + return (((uint64_t)smp_id)<<32) | view_id; +} + +SOKOL_API_IMPL uint64_t simgui_imtextureid(sg_view tex_view) { + return simgui_imtextureid_with_sampler(tex_view, _simgui.def_smp); +} + +SOKOL_API_IMPL sg_view simgui_texture_view_from_imtextureid(uint64_t imtex_id) { + sg_view view = { (uint32_t)imtex_id }; + return view; +} + +SOKOL_API_IMPL sg_sampler simgui_sampler_from_imtextureid(uint64_t imtex_id) { + sg_sampler smp = { (uint32_t)(imtex_id >> 32) }; + return smp; +} + +SOKOL_API_IMPL void simgui_new_frame(const simgui_frame_desc_t* desc) { + SOKOL_ASSERT(_SIMGUI_INIT_COOKIE == _simgui.init_cookie); + SOKOL_ASSERT(desc); + SOKOL_ASSERT(desc->width > 0); + SOKOL_ASSERT(desc->height > 0); + _simgui.cur_dpi_scale = _simgui_def(desc->dpi_scale, 1.0f); + ImGuiIO* io = _simgui_imgui_get_io(); + io->DisplaySize.x = ((float)desc->width) / _simgui.cur_dpi_scale; + io->DisplaySize.y = ((float)desc->height) / _simgui.cur_dpi_scale; + io->DisplayFramebufferScale.x = _simgui.cur_dpi_scale; + io->DisplayFramebufferScale.y = _simgui.cur_dpi_scale; + io->DeltaTime = (float)desc->delta_time; + #if !defined(SOKOL_IMGUI_NO_SOKOL_APP) + if (io->WantTextInput && !sapp_keyboard_shown()) { + sapp_show_keyboard(true); + } + if (!io->WantTextInput && sapp_keyboard_shown()) { + sapp_show_keyboard(false); + } + if (!_simgui.desc.disable_set_mouse_cursor) { + ImGuiMouseCursor imgui_cursor = _simgui_imgui_get_mouse_cursor(); + sapp_mouse_cursor cursor = sapp_get_mouse_cursor(); + switch (imgui_cursor) { + case ImGuiMouseCursor_Arrow: cursor = SAPP_MOUSECURSOR_ARROW; break; + case ImGuiMouseCursor_TextInput: cursor = SAPP_MOUSECURSOR_IBEAM; break; + case ImGuiMouseCursor_ResizeAll: cursor = SAPP_MOUSECURSOR_RESIZE_ALL; break; + case ImGuiMouseCursor_ResizeNS: cursor = SAPP_MOUSECURSOR_RESIZE_NS; break; + case ImGuiMouseCursor_ResizeEW: cursor = SAPP_MOUSECURSOR_RESIZE_EW; break; + case ImGuiMouseCursor_ResizeNESW: cursor = SAPP_MOUSECURSOR_RESIZE_NESW; break; + case ImGuiMouseCursor_ResizeNWSE: cursor = SAPP_MOUSECURSOR_RESIZE_NWSE; break; + case ImGuiMouseCursor_Hand: cursor = SAPP_MOUSECURSOR_POINTING_HAND; break; + case ImGuiMouseCursor_NotAllowed: cursor = SAPP_MOUSECURSOR_NOT_ALLOWED; break; + default: break; + } + sapp_set_mouse_cursor(cursor); + } + #endif + _simgui_imgui_newframe(); +} + +static sg_pipeline _simgui_bind_texture_sampler(sg_bindings* bindings, ImTextureID imtex_id) { + const sg_view tex_view = simgui_texture_view_from_imtextureid(imtex_id); + SOKOL_ASSERT(tex_view.id != SG_INVALID_ID); + const sg_image img = sg_query_view_image(tex_view); + SOKOL_ASSERT(img.id != SG_INVALID_ID); + bindings->views[0] = tex_view; + bindings->samplers[0] = simgui_sampler_from_imtextureid(imtex_id); + SOKOL_ASSERT(bindings->samplers[0].id != SG_INVALID_ID); + if (sg_query_pixelformat(sg_query_image_pixelformat(img)).filter) { + return _simgui.def_pip; + } else { + return _simgui.pip_unfilterable; + } +} + +SOKOL_API_IMPL void simgui_render(void) { + SOKOL_ASSERT(_SIMGUI_INIT_COOKIE == _simgui.init_cookie); + ImGuiIO* io = _simgui_imgui_get_io(); + _simgui_imgui_render(); + ImDrawData* draw_data = _simgui_imgui_get_draw_data(); + if (0 == draw_data) { + return; + } + + // catch up with texture updates (important: this needs to happen before + // checking the CmdListsCount, otherwise textures might get stuck in + // 'WantCreate' state) + if (draw_data->Textures) { + for (size_t i = 0; i < (size_t)draw_data->Textures->Size; i++) { + ImTextureData* tex = draw_data->Textures->Data[i]; + if (tex->Status != ImTextureStatus_OK) { + _simgui_update_texture(tex); + } + } + } + + // early-out if nothing needs to be rendered + if (draw_data->CmdListsCount == 0) { + return; + } + + // copy vertices and indices into an intermediate buffer so that + // they can be updated with a single sg_update_buffer() call each + // (sg_append_buffer() has performance problems on some GL platforms), + // also keep track of valid number of command lists in case of a + // buffer overflow + size_t all_vtx_size = 0; + size_t all_idx_size = 0; + int cmd_list_count = 0; + for (int cl_index = 0; cl_index < draw_data->CmdListsCount; cl_index++, cmd_list_count++) { + ImDrawList* cl = _simgui_imdrawlist_at(draw_data, cl_index); + const size_t vtx_size = (size_t)cl->VtxBuffer.Size * sizeof(ImDrawVert); + const size_t idx_size = (size_t)cl->IdxBuffer.Size * sizeof(ImDrawIdx); + + // check for buffer overflow + if (((all_vtx_size + vtx_size) > _simgui.vertices.size) || + ((all_idx_size + idx_size) > _simgui.indices.size)) + { + _SIMGUI_ERROR(BUFFER_OVERFLOW); + break; + } + + // copy vertices and indices into common buffers + if (vtx_size > 0) { + const ImDrawVert* src_vtx_ptr = cl->VtxBuffer.Data; + void* dst_vtx_ptr = (void*) (((uint8_t*)_simgui.vertices.ptr) + all_vtx_size); + memcpy(dst_vtx_ptr, src_vtx_ptr, vtx_size); + } + if (idx_size > 0) { + const ImDrawIdx* src_idx_ptr = cl->IdxBuffer.Data; + void* dst_idx_ptr = (void*) (((uint8_t*)_simgui.indices.ptr) + all_idx_size); + memcpy(dst_idx_ptr, src_idx_ptr, idx_size); + } + all_vtx_size += vtx_size; + all_idx_size += idx_size; + } + if (0 == cmd_list_count) { + return; + } + + // update the sokol-gfx vertex- and index-buffer + sg_push_debug_group("sokol-imgui"); + if (all_vtx_size > 0) { + sg_range vtx_data = _simgui.vertices; + vtx_data.size = all_vtx_size; + sg_update_buffer(_simgui.vbuf, &vtx_data); + } + if (all_idx_size > 0) { + sg_range idx_data = _simgui.indices; + idx_data.size = all_idx_size; + sg_update_buffer(_simgui.ibuf, &idx_data); + } + + // render the ImGui command list + const int fb_width = (int) (io->DisplaySize.x * draw_data->FramebufferScale.x); + const int fb_height = (int) (io->DisplaySize.y * draw_data->FramebufferScale.y); + sg_apply_viewport(0, 0, fb_width, fb_height, true); + sg_apply_scissor_rect(0, 0, fb_width, fb_height, true); + + sg_apply_pipeline(_simgui.def_pip); + _simgui_vs_params_t vs_params; + _simgui_clear((void*)&vs_params, sizeof(vs_params)); + vs_params.disp_size.x = io->DisplaySize.x; + vs_params.disp_size.y = io->DisplaySize.y; + sg_apply_uniforms(0, SG_RANGE_REF(vs_params)); + sg_bindings bind; + _simgui_clear((void*)&bind, sizeof(bind)); + bind.vertex_buffers[0] = _simgui.vbuf; + bind.index_buffer = _simgui.ibuf; + ImTextureID tex_id = 0; + int vb_offset = 0; + int ib_offset = 0; + for (int cl_index = 0; cl_index < cmd_list_count; cl_index++) { + ImDrawList* cl = _simgui_imdrawlist_at(draw_data, cl_index); + + bind.vertex_buffer_offsets[0] = vb_offset; + bind.index_buffer_offset = ib_offset; + if (tex_id != 0) { + sg_apply_bindings(&bind); + } + + const int num_cmds = _simgui_imdrawlist_cmd_buffer_size(cl); + uint32_t vtx_offset = 0; + for (int cmd_index = 0; cmd_index < num_cmds; cmd_index++) { + ImDrawCmd* pcmd = &cl->CmdBuffer.Data[cmd_index]; + if (pcmd->UserCallback != 0) { + // User callback, registered via ImDrawList::AddCallback() + // (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.) + if (pcmd->UserCallback != ImDrawCallback_ResetRenderState) { + pcmd->UserCallback(cl, pcmd); + // need to re-apply all state after calling a user callback + sg_reset_state_cache(); + sg_apply_viewport(0, 0, fb_width, fb_height, true); + sg_apply_pipeline(_simgui.def_pip); + sg_apply_uniforms(0, SG_RANGE_REF(vs_params)); + sg_apply_bindings(&bind); + } + } else { + ImTextureID cmd_tex_id = _simgui_imdrawcmd_gettexid(pcmd); + if ((tex_id != cmd_tex_id) || (vtx_offset != pcmd->VtxOffset)) { + tex_id = cmd_tex_id; + vtx_offset = pcmd->VtxOffset; + sg_pipeline pip = _simgui_bind_texture_sampler(&bind, tex_id); + sg_apply_pipeline(pip); + sg_apply_uniforms(0, SG_RANGE_REF(vs_params)); + bind.vertex_buffer_offsets[0] = vb_offset + (int)(pcmd->VtxOffset * sizeof(ImDrawVert)); + sg_apply_bindings(&bind); + } + const int scissor_x = (int) (pcmd->ClipRect.x * draw_data->FramebufferScale.x); + const int scissor_y = (int) (pcmd->ClipRect.y * draw_data->FramebufferScale.y); + const int scissor_w = (int) ((pcmd->ClipRect.z - pcmd->ClipRect.x) * draw_data->FramebufferScale.x); + const int scissor_h = (int) ((pcmd->ClipRect.w - pcmd->ClipRect.y) * draw_data->FramebufferScale.y); + sg_apply_scissor_rect(scissor_x, scissor_y, scissor_w, scissor_h, true); + sg_draw((int)pcmd->IdxOffset, (int)pcmd->ElemCount, 1); + } + } + vb_offset += _simgui_imdrawlist_vtx_buffer_size(cl) * (int)sizeof(ImDrawVert); + ib_offset += _simgui_imdrawlist_idx_buffer_size(cl) * (int)sizeof(ImDrawIdx); + } + sg_apply_viewport(0, 0, fb_width, fb_height, true); + sg_apply_scissor_rect(0, 0, fb_width, fb_height, true); + sg_pop_debug_group(); +} + +SOKOL_API_IMPL void simgui_add_focus_event(bool focus) { + SOKOL_ASSERT(_SIMGUI_INIT_COOKIE == _simgui.init_cookie); + ImGuiIO* io = _simgui_imgui_get_io(); + _simgui_io_add_focus_event(io, focus); +} + +SOKOL_API_IMPL void simgui_add_mouse_pos_event(float x, float y) { + SOKOL_ASSERT(_SIMGUI_INIT_COOKIE == _simgui.init_cookie); + ImGuiIO* io = _simgui_imgui_get_io(); + _simgui_io_add_mouse_source_event(io, ImGuiMouseSource_Mouse); + _simgui_io_add_mouse_pos_event(io, x, y); +} + +SOKOL_API_IMPL void simgui_add_touch_pos_event(float x, float y) { + SOKOL_ASSERT(_SIMGUI_INIT_COOKIE == _simgui.init_cookie); + ImGuiIO* io = _simgui_imgui_get_io(); + _simgui_io_add_mouse_source_event(io, ImGuiMouseSource_TouchScreen); + _simgui_io_add_mouse_pos_event(io, x, y); +} + +SOKOL_API_IMPL void simgui_add_mouse_button_event(int mouse_button, bool down) { + SOKOL_ASSERT(_SIMGUI_INIT_COOKIE == _simgui.init_cookie); + ImGuiIO* io = _simgui_imgui_get_io(); + _simgui_io_add_mouse_source_event(io, ImGuiMouseSource_Mouse); + _simgui_io_add_mouse_button_event(io, mouse_button, down); +} + +SOKOL_API_IMPL void simgui_add_touch_button_event(int mouse_button, bool down) { + SOKOL_ASSERT(_SIMGUI_INIT_COOKIE == _simgui.init_cookie); + ImGuiIO* io = _simgui_imgui_get_io(); + _simgui_io_add_mouse_source_event(io, ImGuiMouseSource_TouchScreen); + _simgui_io_add_mouse_button_event(io, mouse_button, down); +} + +SOKOL_API_IMPL void simgui_add_mouse_wheel_event(float wheel_x, float wheel_y) { + SOKOL_ASSERT(_SIMGUI_INIT_COOKIE == _simgui.init_cookie); + ImGuiIO* io = _simgui_imgui_get_io(); + _simgui_io_add_mouse_source_event(io, ImGuiMouseSource_Mouse); + _simgui_io_add_mouse_wheel_event(io, wheel_x, wheel_y); +} + +SOKOL_API_IMPL void simgui_add_key_event(int imgui_key, bool down) { + SOKOL_ASSERT(_SIMGUI_INIT_COOKIE == _simgui.init_cookie); + ImGuiIO* io = _simgui_imgui_get_io(); + _simgui_io_add_key_event(io, (ImGuiKey)imgui_key, down); +} + +SOKOL_API_IMPL void simgui_add_input_character(uint32_t c) { + SOKOL_ASSERT(_SIMGUI_INIT_COOKIE == _simgui.init_cookie); + ImGuiIO* io = _simgui_imgui_get_io(); + _simgui_io_add_input_character(io, c); +} + +SOKOL_API_IMPL void simgui_add_input_characters_utf8(const char* c) { + SOKOL_ASSERT(_SIMGUI_INIT_COOKIE == _simgui.init_cookie); + ImGuiIO* io = _simgui_imgui_get_io(); + _simgui_io_add_input_characters_utf8(io, c); +} + +#if !defined(SOKOL_IMGUI_NO_SOKOL_APP) +_SOKOL_PRIVATE bool _simgui_is_ctrl(uint32_t modifiers) { + if (_simgui.is_osx) { + return 0 != (modifiers & SAPP_MODIFIER_SUPER); + } else { + return 0 != (modifiers & SAPP_MODIFIER_CTRL); + } +} + +_SOKOL_PRIVATE ImGuiKey _simgui_map_keycode(sapp_keycode key) { + switch (key) { + case SAPP_KEYCODE_SPACE: return ImGuiKey_Space; + case SAPP_KEYCODE_APOSTROPHE: return ImGuiKey_Apostrophe; + case SAPP_KEYCODE_COMMA: return ImGuiKey_Comma; + case SAPP_KEYCODE_MINUS: return ImGuiKey_Minus; + case SAPP_KEYCODE_PERIOD: return ImGuiKey_Period; + case SAPP_KEYCODE_SLASH: return ImGuiKey_Slash; + case SAPP_KEYCODE_0: return ImGuiKey_0; + case SAPP_KEYCODE_1: return ImGuiKey_1; + case SAPP_KEYCODE_2: return ImGuiKey_2; + case SAPP_KEYCODE_3: return ImGuiKey_3; + case SAPP_KEYCODE_4: return ImGuiKey_4; + case SAPP_KEYCODE_5: return ImGuiKey_5; + case SAPP_KEYCODE_6: return ImGuiKey_6; + case SAPP_KEYCODE_7: return ImGuiKey_7; + case SAPP_KEYCODE_8: return ImGuiKey_8; + case SAPP_KEYCODE_9: return ImGuiKey_9; + case SAPP_KEYCODE_SEMICOLON: return ImGuiKey_Semicolon; + case SAPP_KEYCODE_EQUAL: return ImGuiKey_Equal; + case SAPP_KEYCODE_A: return ImGuiKey_A; + case SAPP_KEYCODE_B: return ImGuiKey_B; + case SAPP_KEYCODE_C: return ImGuiKey_C; + case SAPP_KEYCODE_D: return ImGuiKey_D; + case SAPP_KEYCODE_E: return ImGuiKey_E; + case SAPP_KEYCODE_F: return ImGuiKey_F; + case SAPP_KEYCODE_G: return ImGuiKey_G; + case SAPP_KEYCODE_H: return ImGuiKey_H; + case SAPP_KEYCODE_I: return ImGuiKey_I; + case SAPP_KEYCODE_J: return ImGuiKey_J; + case SAPP_KEYCODE_K: return ImGuiKey_K; + case SAPP_KEYCODE_L: return ImGuiKey_L; + case SAPP_KEYCODE_M: return ImGuiKey_M; + case SAPP_KEYCODE_N: return ImGuiKey_N; + case SAPP_KEYCODE_O: return ImGuiKey_O; + case SAPP_KEYCODE_P: return ImGuiKey_P; + case SAPP_KEYCODE_Q: return ImGuiKey_Q; + case SAPP_KEYCODE_R: return ImGuiKey_R; + case SAPP_KEYCODE_S: return ImGuiKey_S; + case SAPP_KEYCODE_T: return ImGuiKey_T; + case SAPP_KEYCODE_U: return ImGuiKey_U; + case SAPP_KEYCODE_V: return ImGuiKey_V; + case SAPP_KEYCODE_W: return ImGuiKey_W; + case SAPP_KEYCODE_X: return ImGuiKey_X; + case SAPP_KEYCODE_Y: return ImGuiKey_Y; + case SAPP_KEYCODE_Z: return ImGuiKey_Z; + case SAPP_KEYCODE_LEFT_BRACKET: return ImGuiKey_LeftBracket; + case SAPP_KEYCODE_BACKSLASH: return ImGuiKey_Backslash; + case SAPP_KEYCODE_RIGHT_BRACKET:return ImGuiKey_RightBracket; + case SAPP_KEYCODE_GRAVE_ACCENT: return ImGuiKey_GraveAccent; + case SAPP_KEYCODE_ESCAPE: return ImGuiKey_Escape; + case SAPP_KEYCODE_ENTER: return ImGuiKey_Enter; + case SAPP_KEYCODE_TAB: return ImGuiKey_Tab; + case SAPP_KEYCODE_BACKSPACE: return ImGuiKey_Backspace; + case SAPP_KEYCODE_INSERT: return ImGuiKey_Insert; + case SAPP_KEYCODE_DELETE: return ImGuiKey_Delete; + case SAPP_KEYCODE_RIGHT: return ImGuiKey_RightArrow; + case SAPP_KEYCODE_LEFT: return ImGuiKey_LeftArrow; + case SAPP_KEYCODE_DOWN: return ImGuiKey_DownArrow; + case SAPP_KEYCODE_UP: return ImGuiKey_UpArrow; + case SAPP_KEYCODE_PAGE_UP: return ImGuiKey_PageUp; + case SAPP_KEYCODE_PAGE_DOWN: return ImGuiKey_PageDown; + case SAPP_KEYCODE_HOME: return ImGuiKey_Home; + case SAPP_KEYCODE_END: return ImGuiKey_End; + case SAPP_KEYCODE_CAPS_LOCK: return ImGuiKey_CapsLock; + case SAPP_KEYCODE_SCROLL_LOCK: return ImGuiKey_ScrollLock; + case SAPP_KEYCODE_NUM_LOCK: return ImGuiKey_NumLock; + case SAPP_KEYCODE_PRINT_SCREEN: return ImGuiKey_PrintScreen; + case SAPP_KEYCODE_PAUSE: return ImGuiKey_Pause; + case SAPP_KEYCODE_F1: return ImGuiKey_F1; + case SAPP_KEYCODE_F2: return ImGuiKey_F2; + case SAPP_KEYCODE_F3: return ImGuiKey_F3; + case SAPP_KEYCODE_F4: return ImGuiKey_F4; + case SAPP_KEYCODE_F5: return ImGuiKey_F5; + case SAPP_KEYCODE_F6: return ImGuiKey_F6; + case SAPP_KEYCODE_F7: return ImGuiKey_F7; + case SAPP_KEYCODE_F8: return ImGuiKey_F8; + case SAPP_KEYCODE_F9: return ImGuiKey_F9; + case SAPP_KEYCODE_F10: return ImGuiKey_F10; + case SAPP_KEYCODE_F11: return ImGuiKey_F11; + case SAPP_KEYCODE_F12: return ImGuiKey_F12; + case SAPP_KEYCODE_KP_0: return ImGuiKey_Keypad0; + case SAPP_KEYCODE_KP_1: return ImGuiKey_Keypad1; + case SAPP_KEYCODE_KP_2: return ImGuiKey_Keypad2; + case SAPP_KEYCODE_KP_3: return ImGuiKey_Keypad3; + case SAPP_KEYCODE_KP_4: return ImGuiKey_Keypad4; + case SAPP_KEYCODE_KP_5: return ImGuiKey_Keypad5; + case SAPP_KEYCODE_KP_6: return ImGuiKey_Keypad6; + case SAPP_KEYCODE_KP_7: return ImGuiKey_Keypad7; + case SAPP_KEYCODE_KP_8: return ImGuiKey_Keypad8; + case SAPP_KEYCODE_KP_9: return ImGuiKey_Keypad9; + case SAPP_KEYCODE_KP_DECIMAL: return ImGuiKey_KeypadDecimal; + case SAPP_KEYCODE_KP_DIVIDE: return ImGuiKey_KeypadDivide; + case SAPP_KEYCODE_KP_MULTIPLY: return ImGuiKey_KeypadMultiply; + case SAPP_KEYCODE_KP_SUBTRACT: return ImGuiKey_KeypadSubtract; + case SAPP_KEYCODE_KP_ADD: return ImGuiKey_KeypadAdd; + case SAPP_KEYCODE_KP_ENTER: return ImGuiKey_KeypadEnter; + case SAPP_KEYCODE_KP_EQUAL: return ImGuiKey_KeypadEqual; + case SAPP_KEYCODE_LEFT_SHIFT: return ImGuiKey_LeftShift; + case SAPP_KEYCODE_LEFT_CONTROL: return ImGuiKey_LeftCtrl; + case SAPP_KEYCODE_LEFT_ALT: return ImGuiKey_LeftAlt; + case SAPP_KEYCODE_LEFT_SUPER: return ImGuiKey_LeftSuper; + case SAPP_KEYCODE_RIGHT_SHIFT: return ImGuiKey_RightShift; + case SAPP_KEYCODE_RIGHT_CONTROL:return ImGuiKey_RightCtrl; + case SAPP_KEYCODE_RIGHT_ALT: return ImGuiKey_RightAlt; + case SAPP_KEYCODE_RIGHT_SUPER: return ImGuiKey_RightSuper; + case SAPP_KEYCODE_MENU: return ImGuiKey_Menu; + default: return ImGuiKey_None; + } +} + +_SOKOL_PRIVATE void _simgui_add_sapp_key_event(ImGuiIO* io, sapp_keycode sapp_key, bool down) { + const ImGuiKey imgui_key = _simgui_map_keycode(sapp_key); + _simgui_io_add_key_event(io, imgui_key, down); +} + +_SOKOL_PRIVATE void _simgui_update_modifiers(ImGuiIO* io, uint32_t mods) { + _simgui_io_add_key_event(io, ImGuiMod_Ctrl, (mods & SAPP_MODIFIER_CTRL) != 0); + _simgui_io_add_key_event(io, ImGuiMod_Shift, (mods & SAPP_MODIFIER_SHIFT) != 0); + _simgui_io_add_key_event(io, ImGuiMod_Alt, (mods & SAPP_MODIFIER_ALT) != 0); + _simgui_io_add_key_event(io, ImGuiMod_Super, (mods & SAPP_MODIFIER_SUPER) != 0); +} + +// returns Ctrl or Super, depending on platform +_SOKOL_PRIVATE ImGuiKey _simgui_copypaste_modifier(void) { + return _simgui.is_osx ? ImGuiMod_Super : ImGuiMod_Ctrl; +} + +SOKOL_API_IMPL int simgui_map_keycode(sapp_keycode keycode) { + SOKOL_ASSERT(_SIMGUI_INIT_COOKIE == _simgui.init_cookie); + return (int)_simgui_map_keycode(keycode); +} + +SOKOL_API_IMPL bool simgui_handle_event(const sapp_event* ev) { + SOKOL_ASSERT(_SIMGUI_INIT_COOKIE == _simgui.init_cookie); + const float dpi_scale = _simgui.cur_dpi_scale; + ImGuiIO* io = _simgui_imgui_get_io(); + switch (ev->type) { + case SAPP_EVENTTYPE_FOCUSED: + simgui_add_focus_event(true); + break; + case SAPP_EVENTTYPE_UNFOCUSED: + simgui_add_focus_event(false); + break; + case SAPP_EVENTTYPE_MOUSE_DOWN: + simgui_add_mouse_pos_event(ev->mouse_x / dpi_scale, ev->mouse_y / dpi_scale); + simgui_add_mouse_button_event((int)ev->mouse_button, true); + _simgui_update_modifiers(io, ev->modifiers); + break; + case SAPP_EVENTTYPE_MOUSE_UP: + simgui_add_mouse_pos_event(ev->mouse_x / dpi_scale, ev->mouse_y / dpi_scale); + simgui_add_mouse_button_event((int)ev->mouse_button, false); + _simgui_update_modifiers(io, ev->modifiers); + break; + case SAPP_EVENTTYPE_MOUSE_MOVE: + simgui_add_mouse_pos_event(ev->mouse_x / dpi_scale, ev->mouse_y / dpi_scale); + break; + case SAPP_EVENTTYPE_MOUSE_ENTER: + case SAPP_EVENTTYPE_MOUSE_LEAVE: + // FIXME: since the sokol_app.h emscripten backend doesn't support + // mouse capture, mouse buttons must be released when the mouse leaves the + // browser window, so that they don't "stick" when released outside the window. + // A cleaner solution would be a new sokol_app.h function to query + // "platform behaviour flags". + #if defined(__EMSCRIPTEN__) + for (int i = 0; i < SAPP_MAX_MOUSEBUTTONS; i++) { + simgui_add_mouse_button_event(i, false); + } + #endif + break; + case SAPP_EVENTTYPE_MOUSE_SCROLL: + simgui_add_mouse_wheel_event(ev->scroll_x, ev->scroll_y); + break; + case SAPP_EVENTTYPE_TOUCHES_BEGAN: + simgui_add_touch_pos_event(ev->touches[0].pos_x / dpi_scale, ev->touches[0].pos_y / dpi_scale); + simgui_add_touch_button_event(0, true); + break; + case SAPP_EVENTTYPE_TOUCHES_MOVED: + simgui_add_touch_pos_event(ev->touches[0].pos_x / dpi_scale, ev->touches[0].pos_y / dpi_scale); + break; + case SAPP_EVENTTYPE_TOUCHES_ENDED: + simgui_add_touch_pos_event(ev->touches[0].pos_x / dpi_scale, ev->touches[0].pos_y / dpi_scale); + simgui_add_touch_button_event(0, false); + break; + case SAPP_EVENTTYPE_TOUCHES_CANCELLED: + simgui_add_touch_button_event(0, false); + break; + case SAPP_EVENTTYPE_KEY_DOWN: + _simgui_update_modifiers(io, ev->modifiers); + // intercept Ctrl-V, this is handled via EVENTTYPE_CLIPBOARD_PASTED + if (!_simgui.desc.disable_paste_override) { + if (_simgui_is_ctrl(ev->modifiers) && (ev->key_code == SAPP_KEYCODE_V)) { + break; + } + } + // on web platform, don't forward Ctrl-X, Ctrl-V to the browser + if (_simgui_is_ctrl(ev->modifiers) && (ev->key_code == SAPP_KEYCODE_X)) { + sapp_consume_event(); + } + if (_simgui_is_ctrl(ev->modifiers) && (ev->key_code == SAPP_KEYCODE_C)) { + sapp_consume_event(); + } + // it's ok to add ImGuiKey_None key events + _simgui_add_sapp_key_event(io, ev->key_code, true); + break; + case SAPP_EVENTTYPE_KEY_UP: + _simgui_update_modifiers(io, ev->modifiers); + // intercept Ctrl-V, this is handled via EVENTTYPE_CLIPBOARD_PASTED + if (_simgui_is_ctrl(ev->modifiers) && (ev->key_code == SAPP_KEYCODE_V)) { + break; + } + // on web platform, don't forward Ctrl-X, Ctrl-V to the browser + if (_simgui_is_ctrl(ev->modifiers) && (ev->key_code == SAPP_KEYCODE_X)) { + sapp_consume_event(); + } + if (_simgui_is_ctrl(ev->modifiers) && (ev->key_code == SAPP_KEYCODE_C)) { + sapp_consume_event(); + } + // it's ok to add ImGuiKey_None key events + _simgui_add_sapp_key_event(io, ev->key_code, false); + break; + case SAPP_EVENTTYPE_CHAR: + /* on some platforms, special keys may be reported as + characters, which may confuse some ImGui widgets, + drop those, also don't forward characters if some + modifiers have been pressed + */ + _simgui_update_modifiers(io, ev->modifiers); + if ((ev->char_code >= 32) && + (ev->char_code != 127) && + (0 == (ev->modifiers & (SAPP_MODIFIER_ALT|SAPP_MODIFIER_CTRL|SAPP_MODIFIER_SUPER)))) + { + simgui_add_input_character(ev->char_code); + } + break; + case SAPP_EVENTTYPE_CLIPBOARD_PASTED: + // simulate a Ctrl-V key down/up + if (!_simgui.desc.disable_paste_override) { + _simgui_io_add_key_event(io, _simgui_copypaste_modifier(), true); + _simgui_io_add_key_event(io, ImGuiKey_V, true); + _simgui_io_add_key_event(io, ImGuiKey_V, false); + _simgui_io_add_key_event(io, _simgui_copypaste_modifier(), false); + } + break; + default: + break; + } + return io->WantCaptureKeyboard || io->WantCaptureMouse; +} +#endif // SOKOL_IMGUI_NO_SOKOL_APP + +#endif // SOKOL_IMPL diff --git a/extern/sokol/sokol_log.h b/extern/sokol/sokol_log.h new file mode 100644 index 0000000..7a271a6 --- /dev/null +++ b/extern/sokol/sokol_log.h @@ -0,0 +1,334 @@ +#if defined(SOKOL_IMPL) && !defined(SOKOL_LOG_IMPL) +#define SOKOL_LOG_IMPL +#endif +#ifndef SOKOL_LOG_INCLUDED +/* + sokol_log.h -- common logging callback for sokol headers + + Project URL: https://github.com/floooh/sokol + + Example code: https://github.com/floooh/sokol-samples + + Do this: + #define SOKOL_IMPL or + #define SOKOL_LOG_IMPL + before you include this file in *one* C or C++ file to create the + implementation. + + Optionally provide the following defines when building the implementation: + + SOKOL_ASSERT(c) - your own assert macro (default: assert(c)) + SOKOL_UNREACHABLE() - a guard macro for unreachable code (default: assert(false)) + SOKOL_LOG_API_DECL - public function declaration prefix (default: extern) + SOKOL_API_DECL - same as SOKOL_GFX_API_DECL + SOKOL_API_IMPL - public function implementation prefix (default: -) + + Optionally define the following for verbose output: + + SOKOL_DEBUG - by default this is defined if NDEBUG is not defined + + + OVERVIEW + ======== + sokol_log.h provides a default logging callback for other sokol headers. + + To use the default log callback, just include sokol_log.h and provide + a function pointer to the 'slog_func' function when setting up the + sokol library: + + For instance with sokol_audio.h: + + #include "sokol_log.h" + ... + saudio_setup(&(saudio_desc){ .logger.func = slog_func }); + + Logging output goes to stderr and/or a platform specific logging subsystem + (which means that in some scenarios you might see logging messages duplicated): + + - Windows: stderr + OutputDebugStringA() + - macOS/iOS/Linux: stderr + syslog() + - Emscripten: console.info()/warn()/error() + - Android: __android_log_write() + + On Windows with sokol_app.h also note the runtime config items to make + stdout/stderr output visible on the console for WinMain() applications + via sapp_desc.win32.console_attach or sapp_desc.win32.console_create, + however when running in a debugger on Windows, the logging output should + show up on the debug output UI panel. + + In debug mode, a log message might look like this: + + [sspine][error][id:12] /Users/floh/projects/sokol/util/sokol_spine.h:3472:0: + SKELETON_DESC_NO_ATLAS: no atlas object provided in sspine_skeleton_desc.atlas + + The source path and line number is formatted like compiler errors, in some IDEs (like VSCode) + such error messages are clickable. + + In release mode, logging is less verbose as to not bloat the executable with string data, but you still get + enough information to identify the type and location of an error: + + [sspine][error][id:12][line:3472] + + RULES FOR WRITING YOUR OWN LOGGING FUNCTION + =========================================== + - must be re-entrant because it might be called from different threads + - must treat **all** provided string pointers as optional (can be null) + - don't store the string pointers, copy the string data instead + - must not return for log level panic + + LICENSE + ======= + zlib/libpng license + + Copyright (c) 2023 Andre Weissflog + + This software is provided 'as-is', without any express or implied warranty. + In no event will the authors be held liable for any damages arising from the + use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software in a + product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not + be misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*/ +#define SOKOL_LOG_INCLUDED (1) +#include + +#if defined(SOKOL_API_DECL) && !defined(SOKOL_LOG_API_DECL) +#define SOKOL_LOG_API_DECL SOKOL_API_DECL +#endif +#ifndef SOKOL_LOG_API_DECL +#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_LOG_IMPL) +#define SOKOL_LOG_API_DECL __declspec(dllexport) +#elif defined(_WIN32) && defined(SOKOL_DLL) +#define SOKOL_LOG_API_DECL __declspec(dllimport) +#else +#define SOKOL_LOG_API_DECL extern +#endif +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* + Plug this function into the 'logger.func' struct item when initializing any of the sokol + headers. For instance for sokol_audio.h it would look like this: + + saudio_setup(&(saudio_desc){ + .logger = { + .func = slog_func + } + }); +*/ +SOKOL_LOG_API_DECL void slog_func(const char* tag, uint32_t log_level, uint32_t log_item, const char* message, uint32_t line_nr, const char* filename, void* user_data); + +#ifdef __cplusplus +} // extern "C" +#endif +#endif // SOKOL_LOG_INCLUDED + +// ██ ███ ███ ██████ ██ ███████ ███ ███ ███████ ███ ██ ████████ █████ ████████ ██ ██████ ███ ██ +// ██ ████ ████ ██ ██ ██ ██ ████ ████ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ +// ██ ██ ████ ██ ██████ ██ █████ ██ ████ ██ █████ ██ ██ ██ ██ ███████ ██ ██ ██ ██ ██ ██ ██ +// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +// ██ ██ ██ ██ ███████ ███████ ██ ██ ███████ ██ ████ ██ ██ ██ ██ ██ ██████ ██ ████ +// +// >>implementation +#ifdef SOKOL_LOG_IMPL +#define SOKOL_LOG_IMPL_INCLUDED (1) + +#ifndef SOKOL_API_IMPL + #define SOKOL_API_IMPL +#endif +#ifndef SOKOL_DEBUG + #ifndef NDEBUG + #define SOKOL_DEBUG + #endif +#endif +#ifndef SOKOL_ASSERT + #include + #define SOKOL_ASSERT(c) assert(c) +#endif + +#ifndef _SOKOL_PRIVATE + #if defined(__GNUC__) || defined(__clang__) + #define _SOKOL_PRIVATE __attribute__((unused)) static + #else + #define _SOKOL_PRIVATE static + #endif +#endif + +#ifndef _SOKOL_UNUSED + #define _SOKOL_UNUSED(x) (void)(x) +#endif + +// platform detection +#if defined(__APPLE__) + #define _SLOG_APPLE (1) +#elif defined(__EMSCRIPTEN__) + #define _SLOG_EMSCRIPTEN (1) +#elif defined(_WIN32) + #define _SLOG_WINDOWS (1) +#elif defined(__ANDROID__) + #define _SLOG_ANDROID (1) +#elif defined(__linux__) || defined(__unix__) + #define _SLOG_LINUX (1) +#else +#error "sokol_log.h: unknown platform" +#endif + +#include // abort +#include // fputs +#include // size_t + +#if defined(_SLOG_EMSCRIPTEN) +#include +#elif defined(_SLOG_WINDOWS) +#ifndef WIN32_LEAN_AND_MEAN + #define WIN32_LEAN_AND_MEAN +#endif +#ifndef NOMINMAX + #define NOMINMAX +#endif +#include +#elif defined(_SLOG_ANDROID) +#include +#elif defined(_SLOG_LINUX) || defined(_SLOG_APPLE) +#include +#endif + +// size of line buffer (on stack!) in bytes including terminating zero +#define _SLOG_LINE_LENGTH (512) + +_SOKOL_PRIVATE char* _slog_append(const char* str, char* dst, char* end) { + if (str) { + char c; + while (((c = *str++) != 0) && (dst < (end - 1))) { + *dst++ = c; + } + } + *dst = 0; + return dst; +} + +_SOKOL_PRIVATE char* _slog_itoa(uint32_t x, char* buf, size_t buf_size) { + const size_t max_digits_and_null = 11; + if (buf_size < max_digits_and_null) { + return 0; + } + char* p = buf + max_digits_and_null; + *--p = 0; + do { + *--p = '0' + (x % 10); + x /= 10; + } while (x != 0); + return p; +} + +#if defined(_SLOG_EMSCRIPTEN) +EM_JS(void, slog_js_log, (uint32_t level, const char* c_str), { + const str = UTF8ToString(c_str); + switch (level) { + case 0: console.error(str); break; + case 1: console.error(str); break; + case 2: console.warn(str); break; + default: console.info(str); break; + } +}) +#endif + +SOKOL_API_IMPL void slog_func(const char* tag, uint32_t log_level, uint32_t log_item, const char* message, uint32_t line_nr, const char* filename, void* user_data) { + _SOKOL_UNUSED(user_data); + + const char* log_level_str; + switch (log_level) { + case 0: log_level_str = "panic"; break; + case 1: log_level_str = "error"; break; + case 2: log_level_str = "warning"; break; + default: log_level_str = "info"; break; + } + + // build log output line + char line_buf[_SLOG_LINE_LENGTH]; + char* str = line_buf; + char* end = line_buf + sizeof(line_buf); + char num_buf[32]; + if (tag) { + str = _slog_append("[", str, end); + str = _slog_append(tag, str, end); + str = _slog_append("]", str, end); + } + str = _slog_append("[", str, end); + str = _slog_append(log_level_str, str, end); + str = _slog_append("]", str, end); + str = _slog_append("[id:", str, end); + str = _slog_append(_slog_itoa(log_item, num_buf, sizeof(num_buf)), str, end); + str = _slog_append("]", str, end); + // if a filename is provided, build a clickable log message that's compatible with compiler error messages + if (filename) { + str = _slog_append(" ", str, end); + #if defined(_MSC_VER) + // MSVC compiler error format + str = _slog_append(filename, str, end); + str = _slog_append("(", str, end); + str = _slog_append(_slog_itoa(line_nr, num_buf, sizeof(num_buf)), str, end); + str = _slog_append("): ", str, end); + #else + // gcc/clang compiler error format + str = _slog_append(filename, str, end); + str = _slog_append(":", str, end); + str = _slog_append(_slog_itoa(line_nr, num_buf, sizeof(num_buf)), str, end); + str = _slog_append(":0: ", str, end); + #endif + } + else { + str = _slog_append("[line:", str, end); + str = _slog_append(_slog_itoa(line_nr, num_buf, sizeof(num_buf)), str, end); + str = _slog_append("] ", str, end); + } + if (message) { + str = _slog_append("\n\t", str, end); + str = _slog_append(message, str, end); + } + str = _slog_append("\n\n", str, end); + if (0 == log_level) { + str = _slog_append("ABORTING because of [panic]\n", str, end); + (void)str; + } + + // print to stderr? + #if defined(_SLOG_LINUX) || defined(_SLOG_WINDOWS) || defined(_SLOG_APPLE) + fputs(line_buf, stderr); + #endif + + // platform specific logging calls + #if defined(_SLOG_WINDOWS) + OutputDebugStringA(line_buf); + #elif defined(_SLOG_ANDROID) + int prio; + switch (log_level) { + case 0: prio = ANDROID_LOG_FATAL; break; + case 1: prio = ANDROID_LOG_ERROR; break; + case 2: prio = ANDROID_LOG_WARN; break; + default: prio = ANDROID_LOG_INFO; break; + } + __android_log_write(prio, "SOKOL", line_buf); + #elif defined(_SLOG_EMSCRIPTEN) + slog_js_log(log_level, line_buf); + #endif + if (0 == log_level) { + abort(); + } +} +#endif // SOKOL_LOG_IMPL diff --git a/extern/stb/stb_image.h b/extern/stb/stb_image.h deleted file mode 100644 index 5e807a0..0000000 --- a/extern/stb/stb_image.h +++ /dev/null @@ -1,7987 +0,0 @@ -/* stb_image - v2.28 - public domain image loader - http://nothings.org/stb - no warranty implied; use at your own risk - - Do this: - #define STB_IMAGE_IMPLEMENTATION - before you include this file in *one* C or C++ file to create the implementation. - - // i.e. it should look like this: - #include ... - #include ... - #include ... - #define STB_IMAGE_IMPLEMENTATION - #include "stb_image.h" - - You can #define STBI_ASSERT(x) before the #include to avoid using assert.h. - And #define STBI_MALLOC, STBI_REALLOC, and STBI_FREE to avoid using malloc,realloc,free - - - QUICK NOTES: - Primarily of interest to game developers and other people who can - avoid problematic images and only need the trivial interface - - JPEG baseline & progressive (12 bpc/arithmetic not supported, same as stock IJG lib) - PNG 1/2/4/8/16-bit-per-channel - - TGA (not sure what subset, if a subset) - BMP non-1bpp, non-RLE - PSD (composited view only, no extra channels, 8/16 bit-per-channel) - - GIF (*comp always reports as 4-channel) - HDR (radiance rgbE format) - PIC (Softimage PIC) - PNM (PPM and PGM binary only) - - Animated GIF still needs a proper API, but here's one way to do it: - http://gist.github.com/urraka/685d9a6340b26b830d49 - - - decode from memory or through FILE (define STBI_NO_STDIO to remove code) - - decode from arbitrary I/O callbacks - - SIMD acceleration on x86/x64 (SSE2) and ARM (NEON) - - Full documentation under "DOCUMENTATION" below. - - -LICENSE - - See end of file for license information. - -RECENT REVISION HISTORY: - - 2.28 (2023-01-29) many error fixes, security errors, just tons of stuff - 2.27 (2021-07-11) document stbi_info better, 16-bit PNM support, bug fixes - 2.26 (2020-07-13) many minor fixes - 2.25 (2020-02-02) fix warnings - 2.24 (2020-02-02) fix warnings; thread-local failure_reason and flip_vertically - 2.23 (2019-08-11) fix clang static analysis warning - 2.22 (2019-03-04) gif fixes, fix warnings - 2.21 (2019-02-25) fix typo in comment - 2.20 (2019-02-07) support utf8 filenames in Windows; fix warnings and platform ifdefs - 2.19 (2018-02-11) fix warning - 2.18 (2018-01-30) fix warnings - 2.17 (2018-01-29) bugfix, 1-bit BMP, 16-bitness query, fix warnings - 2.16 (2017-07-23) all functions have 16-bit variants; optimizations; bugfixes - 2.15 (2017-03-18) fix png-1,2,4; all Imagenet JPGs; no runtime SSE detection on GCC - 2.14 (2017-03-03) remove deprecated STBI_JPEG_OLD; fixes for Imagenet JPGs - 2.13 (2016-12-04) experimental 16-bit API, only for PNG so far; fixes - 2.12 (2016-04-02) fix typo in 2.11 PSD fix that caused crashes - 2.11 (2016-04-02) 16-bit PNGS; enable SSE2 in non-gcc x64 - RGB-format JPEG; remove white matting in PSD; - allocate large structures on the stack; - correct channel count for PNG & BMP - 2.10 (2016-01-22) avoid warning introduced in 2.09 - 2.09 (2016-01-16) 16-bit TGA; comments in PNM files; STBI_REALLOC_SIZED - - See end of file for full revision history. - - - ============================ Contributors ========================= - - Image formats Extensions, features - Sean Barrett (jpeg, png, bmp) Jetro Lauha (stbi_info) - Nicolas Schulz (hdr, psd) Martin "SpartanJ" Golini (stbi_info) - Jonathan Dummer (tga) James "moose2000" Brown (iPhone PNG) - Jean-Marc Lienher (gif) Ben "Disch" Wenger (io callbacks) - Tom Seddon (pic) Omar Cornut (1/2/4-bit PNG) - Thatcher Ulrich (psd) Nicolas Guillemot (vertical flip) - Ken Miller (pgm, ppm) Richard Mitton (16-bit PSD) - github:urraka (animated gif) Junggon Kim (PNM comments) - Christopher Forseth (animated gif) Daniel Gibson (16-bit TGA) - socks-the-fox (16-bit PNG) - Jeremy Sawicki (handle all ImageNet JPGs) - Optimizations & bugfixes Mikhail Morozov (1-bit BMP) - Fabian "ryg" Giesen Anael Seghezzi (is-16-bit query) - Arseny Kapoulkine Simon Breuss (16-bit PNM) - John-Mark Allen - Carmelo J Fdez-Aguera - - Bug & warning fixes - Marc LeBlanc David Woo Guillaume George Martins Mozeiko - Christpher Lloyd Jerry Jansson Joseph Thomson Blazej Dariusz Roszkowski - Phil Jordan Dave Moore Roy Eltham - Hayaki Saito Nathan Reed Won Chun - Luke Graham Johan Duparc Nick Verigakis the Horde3D community - Thomas Ruf Ronny Chevalier github:rlyeh - Janez Zemva John Bartholomew Michal Cichon github:romigrou - Jonathan Blow Ken Hamada Tero Hanninen github:svdijk - Eugene Golushkov Laurent Gomila Cort Stratton github:snagar - Aruelien Pocheville Sergio Gonzalez Thibault Reuille github:Zelex - Cass Everitt Ryamond Barbiero github:grim210 - Paul Du Bois Engin Manap Aldo Culquicondor github:sammyhw - Philipp Wiesemann Dale Weiler Oriol Ferrer Mesia github:phprus - Josh Tobin Neil Bickford Matthew Gregan github:poppolopoppo - Julian Raschke Gregory Mullen Christian Floisand github:darealshinji - Baldur Karlsson Kevin Schmidt JR Smith github:Michaelangel007 - Brad Weinberger Matvey Cherevko github:mosra - Luca Sas Alexander Veselov Zack Middleton [reserved] - Ryan C. Gordon [reserved] [reserved] - DO NOT ADD YOUR NAME HERE - - Jacko Dirks - - To add your name to the credits, pick a random blank space in the middle and fill it. - 80% of merge conflicts on stb PRs are due to people adding their name at the end - of the credits. -*/ - -#ifndef STBI_INCLUDE_STB_IMAGE_H -#define STBI_INCLUDE_STB_IMAGE_H - -// DOCUMENTATION -// -// Limitations: -// - no 12-bit-per-channel JPEG -// - no JPEGs with arithmetic coding -// - GIF always returns *comp=4 -// -// Basic usage (see HDR discussion below for HDR usage): -// int x,y,n; -// unsigned char *data = stbi_load(filename, &x, &y, &n, 0); -// // ... process data if not NULL ... -// // ... x = width, y = height, n = # 8-bit components per pixel ... -// // ... replace '0' with '1'..'4' to force that many components per pixel -// // ... but 'n' will always be the number that it would have been if you said 0 -// stbi_image_free(data); -// -// Standard parameters: -// int *x -- outputs image width in pixels -// int *y -- outputs image height in pixels -// int *channels_in_file -- outputs # of image components in image file -// int desired_channels -- if non-zero, # of image components requested in result -// -// The return value from an image loader is an 'unsigned char *' which points -// to the pixel data, or NULL on an allocation failure or if the image is -// corrupt or invalid. The pixel data consists of *y scanlines of *x pixels, -// with each pixel consisting of N interleaved 8-bit components; the first -// pixel pointed to is top-left-most in the image. There is no padding between -// image scanlines or between pixels, regardless of format. The number of -// components N is 'desired_channels' if desired_channels is non-zero, or -// *channels_in_file otherwise. If desired_channels is non-zero, -// *channels_in_file has the number of components that _would_ have been -// output otherwise. E.g. if you set desired_channels to 4, you will always -// get RGBA output, but you can check *channels_in_file to see if it's trivially -// opaque because e.g. there were only 3 channels in the source image. -// -// An output image with N components has the following components interleaved -// in this order in each pixel: -// -// N=#comp components -// 1 grey -// 2 grey, alpha -// 3 red, green, blue -// 4 red, green, blue, alpha -// -// If image loading fails for any reason, the return value will be NULL, -// and *x, *y, *channels_in_file will be unchanged. The function -// stbi_failure_reason() can be queried for an extremely brief, end-user -// unfriendly explanation of why the load failed. Define STBI_NO_FAILURE_STRINGS -// to avoid compiling these strings at all, and STBI_FAILURE_USERMSG to get slightly -// more user-friendly ones. -// -// Paletted PNG, BMP, GIF, and PIC images are automatically depalettized. -// -// To query the width, height and component count of an image without having to -// decode the full file, you can use the stbi_info family of functions: -// -// int x,y,n,ok; -// ok = stbi_info(filename, &x, &y, &n); -// // returns ok=1 and sets x, y, n if image is a supported format, -// // 0 otherwise. -// -// Note that stb_image pervasively uses ints in its public API for sizes, -// including sizes of memory buffers. This is now part of the API and thus -// hard to change without causing breakage. As a result, the various image -// loaders all have certain limits on image size; these differ somewhat -// by format but generally boil down to either just under 2GB or just under -// 1GB. When the decoded image would be larger than this, stb_image decoding -// will fail. -// -// Additionally, stb_image will reject image files that have any of their -// dimensions set to a larger value than the configurable STBI_MAX_DIMENSIONS, -// which defaults to 2**24 = 16777216 pixels. Due to the above memory limit, -// the only way to have an image with such dimensions load correctly -// is for it to have a rather extreme aspect ratio. Either way, the -// assumption here is that such larger images are likely to be malformed -// or malicious. If you do need to load an image with individual dimensions -// larger than that, and it still fits in the overall size limit, you can -// #define STBI_MAX_DIMENSIONS on your own to be something larger. -// -// =========================================================================== -// -// UNICODE: -// -// If compiling for Windows and you wish to use Unicode filenames, compile -// with -// #define STBI_WINDOWS_UTF8 -// and pass utf8-encoded filenames. Call stbi_convert_wchar_to_utf8 to convert -// Windows wchar_t filenames to utf8. -// -// =========================================================================== -// -// Philosophy -// -// stb libraries are designed with the following priorities: -// -// 1. easy to use -// 2. easy to maintain -// 3. good performance -// -// Sometimes I let "good performance" creep up in priority over "easy to maintain", -// and for best performance I may provide less-easy-to-use APIs that give higher -// performance, in addition to the easy-to-use ones. Nevertheless, it's important -// to keep in mind that from the standpoint of you, a client of this library, -// all you care about is #1 and #3, and stb libraries DO NOT emphasize #3 above all. -// -// Some secondary priorities arise directly from the first two, some of which -// provide more explicit reasons why performance can't be emphasized. -// -// - Portable ("ease of use") -// - Small source code footprint ("easy to maintain") -// - No dependencies ("ease of use") -// -// =========================================================================== -// -// I/O callbacks -// -// I/O callbacks allow you to read from arbitrary sources, like packaged -// files or some other source. Data read from callbacks are processed -// through a small internal buffer (currently 128 bytes) to try to reduce -// overhead. -// -// The three functions you must define are "read" (reads some bytes of data), -// "skip" (skips some bytes of data), "eof" (reports if the stream is at the end). -// -// =========================================================================== -// -// SIMD support -// -// The JPEG decoder will try to automatically use SIMD kernels on x86 when -// supported by the compiler. For ARM Neon support, you must explicitly -// request it. -// -// (The old do-it-yourself SIMD API is no longer supported in the current -// code.) -// -// On x86, SSE2 will automatically be used when available based on a run-time -// test; if not, the generic C versions are used as a fall-back. On ARM targets, -// the typical path is to have separate builds for NEON and non-NEON devices -// (at least this is true for iOS and Android). Therefore, the NEON support is -// toggled by a build flag: define STBI_NEON to get NEON loops. -// -// If for some reason you do not want to use any of SIMD code, or if -// you have issues compiling it, you can disable it entirely by -// defining STBI_NO_SIMD. -// -// =========================================================================== -// -// HDR image support (disable by defining STBI_NO_HDR) -// -// stb_image supports loading HDR images in general, and currently the Radiance -// .HDR file format specifically. You can still load any file through the existing -// interface; if you attempt to load an HDR file, it will be automatically remapped -// to LDR, assuming gamma 2.2 and an arbitrary scale factor defaulting to 1; -// both of these constants can be reconfigured through this interface: -// -// stbi_hdr_to_ldr_gamma(2.2f); -// stbi_hdr_to_ldr_scale(1.0f); -// -// (note, do not use _inverse_ constants; stbi_image will invert them -// appropriately). -// -// Additionally, there is a new, parallel interface for loading files as -// (linear) floats to preserve the full dynamic range: -// -// float *data = stbi_loadf(filename, &x, &y, &n, 0); -// -// If you load LDR images through this interface, those images will -// be promoted to floating point values, run through the inverse of -// constants corresponding to the above: -// -// stbi_ldr_to_hdr_scale(1.0f); -// stbi_ldr_to_hdr_gamma(2.2f); -// -// Finally, given a filename (or an open file or memory block--see header -// file for details) containing image data, you can query for the "most -// appropriate" interface to use (that is, whether the image is HDR or -// not), using: -// -// stbi_is_hdr(char *filename); -// -// =========================================================================== -// -// iPhone PNG support: -// -// We optionally support converting iPhone-formatted PNGs (which store -// premultiplied BGRA) back to RGB, even though they're internally encoded -// differently. To enable this conversion, call -// stbi_convert_iphone_png_to_rgb(1). -// -// Call stbi_set_unpremultiply_on_load(1) as well to force a divide per -// pixel to remove any premultiplied alpha *only* if the image file explicitly -// says there's premultiplied data (currently only happens in iPhone images, -// and only if iPhone convert-to-rgb processing is on). -// -// =========================================================================== -// -// ADDITIONAL CONFIGURATION -// -// - You can suppress implementation of any of the decoders to reduce -// your code footprint by #defining one or more of the following -// symbols before creating the implementation. -// -// STBI_NO_JPEG -// STBI_NO_PNG -// STBI_NO_BMP -// STBI_NO_PSD -// STBI_NO_TGA -// STBI_NO_GIF -// STBI_NO_HDR -// STBI_NO_PIC -// STBI_NO_PNM (.ppm and .pgm) -// -// - You can request *only* certain decoders and suppress all other ones -// (this will be more forward-compatible, as addition of new decoders -// doesn't require you to disable them explicitly): -// -// STBI_ONLY_JPEG -// STBI_ONLY_PNG -// STBI_ONLY_BMP -// STBI_ONLY_PSD -// STBI_ONLY_TGA -// STBI_ONLY_GIF -// STBI_ONLY_HDR -// STBI_ONLY_PIC -// STBI_ONLY_PNM (.ppm and .pgm) -// -// - If you use STBI_NO_PNG (or _ONLY_ without PNG), and you still -// want the zlib decoder to be available, #define STBI_SUPPORT_ZLIB -// -// - If you define STBI_MAX_DIMENSIONS, stb_image will reject images greater -// than that size (in either width or height) without further processing. -// This is to let programs in the wild set an upper bound to prevent -// denial-of-service attacks on untrusted data, as one could generate a -// valid image of gigantic dimensions and force stb_image to allocate a -// huge block of memory and spend disproportionate time decoding it. By -// default this is set to (1 << 24), which is 16777216, but that's still -// very big. - -#ifndef STBI_NO_STDIO -#include -#endif // STBI_NO_STDIO - -#define STBI_VERSION 1 - -enum -{ - STBI_default = 0, // only used for desired_channels - - STBI_grey = 1, - STBI_grey_alpha = 2, - STBI_rgb = 3, - STBI_rgb_alpha = 4 -}; - -#include -typedef unsigned char stbi_uc; -typedef unsigned short stbi_us; - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef STBIDEF -#ifdef STB_IMAGE_STATIC -#define STBIDEF static -#else -#define STBIDEF extern -#endif -#endif - -////////////////////////////////////////////////////////////////////////////// -// -// PRIMARY API - works on images of any type -// - -// -// load image by filename, open file, or memory buffer -// - -typedef struct -{ - int (*read) (void *user,char *data,int size); // fill 'data' with 'size' bytes. return number of bytes actually read - void (*skip) (void *user,int n); // skip the next 'n' bytes, or 'unget' the last -n bytes if negative - int (*eof) (void *user); // returns nonzero if we are at end of file/data -} stbi_io_callbacks; - -//////////////////////////////////// -// -// 8-bits-per-channel interface -// - -STBIDEF stbi_uc *stbi_load_from_memory (stbi_uc const *buffer, int len , int *x, int *y, int *channels_in_file, int desired_channels); -STBIDEF stbi_uc *stbi_load_from_callbacks(stbi_io_callbacks const *clbk , void *user, int *x, int *y, int *channels_in_file, int desired_channels); - -#ifndef STBI_NO_STDIO -STBIDEF stbi_uc *stbi_load (char const *filename, int *x, int *y, int *channels_in_file, int desired_channels); -STBIDEF stbi_uc *stbi_load_from_file (FILE *f, int *x, int *y, int *channels_in_file, int desired_channels); -// for stbi_load_from_file, file pointer is left pointing immediately after image -#endif - -#ifndef STBI_NO_GIF -STBIDEF stbi_uc *stbi_load_gif_from_memory(stbi_uc const *buffer, int len, int **delays, int *x, int *y, int *z, int *comp, int req_comp); -#endif - -#ifdef STBI_WINDOWS_UTF8 -STBIDEF int stbi_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input); -#endif - -//////////////////////////////////// -// -// 16-bits-per-channel interface -// - -STBIDEF stbi_us *stbi_load_16_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *channels_in_file, int desired_channels); -STBIDEF stbi_us *stbi_load_16_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *channels_in_file, int desired_channels); - -#ifndef STBI_NO_STDIO -STBIDEF stbi_us *stbi_load_16 (char const *filename, int *x, int *y, int *channels_in_file, int desired_channels); -STBIDEF stbi_us *stbi_load_from_file_16(FILE *f, int *x, int *y, int *channels_in_file, int desired_channels); -#endif - -//////////////////////////////////// -// -// float-per-channel interface -// -#ifndef STBI_NO_LINEAR - STBIDEF float *stbi_loadf_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *channels_in_file, int desired_channels); - STBIDEF float *stbi_loadf_from_callbacks (stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *channels_in_file, int desired_channels); - - #ifndef STBI_NO_STDIO - STBIDEF float *stbi_loadf (char const *filename, int *x, int *y, int *channels_in_file, int desired_channels); - STBIDEF float *stbi_loadf_from_file (FILE *f, int *x, int *y, int *channels_in_file, int desired_channels); - #endif -#endif - -#ifndef STBI_NO_HDR - STBIDEF void stbi_hdr_to_ldr_gamma(float gamma); - STBIDEF void stbi_hdr_to_ldr_scale(float scale); -#endif // STBI_NO_HDR - -#ifndef STBI_NO_LINEAR - STBIDEF void stbi_ldr_to_hdr_gamma(float gamma); - STBIDEF void stbi_ldr_to_hdr_scale(float scale); -#endif // STBI_NO_LINEAR - -// stbi_is_hdr is always defined, but always returns false if STBI_NO_HDR -STBIDEF int stbi_is_hdr_from_callbacks(stbi_io_callbacks const *clbk, void *user); -STBIDEF int stbi_is_hdr_from_memory(stbi_uc const *buffer, int len); -#ifndef STBI_NO_STDIO -STBIDEF int stbi_is_hdr (char const *filename); -STBIDEF int stbi_is_hdr_from_file(FILE *f); -#endif // STBI_NO_STDIO - - -// get a VERY brief reason for failure -// on most compilers (and ALL modern mainstream compilers) this is threadsafe -STBIDEF const char *stbi_failure_reason (void); - -// free the loaded image -- this is just free() -STBIDEF void stbi_image_free (void *retval_from_stbi_load); - -// get image dimensions & components without fully decoding -STBIDEF int stbi_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp); -STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp); -STBIDEF int stbi_is_16_bit_from_memory(stbi_uc const *buffer, int len); -STBIDEF int stbi_is_16_bit_from_callbacks(stbi_io_callbacks const *clbk, void *user); - -#ifndef STBI_NO_STDIO -STBIDEF int stbi_info (char const *filename, int *x, int *y, int *comp); -STBIDEF int stbi_info_from_file (FILE *f, int *x, int *y, int *comp); -STBIDEF int stbi_is_16_bit (char const *filename); -STBIDEF int stbi_is_16_bit_from_file(FILE *f); -#endif - - - -// for image formats that explicitly notate that they have premultiplied alpha, -// we just return the colors as stored in the file. set this flag to force -// unpremultiplication. results are undefined if the unpremultiply overflow. -STBIDEF void stbi_set_unpremultiply_on_load(int flag_true_if_should_unpremultiply); - -// indicate whether we should process iphone images back to canonical format, -// or just pass them through "as-is" -STBIDEF void stbi_convert_iphone_png_to_rgb(int flag_true_if_should_convert); - -// flip the image vertically, so the first pixel in the output array is the bottom left -STBIDEF void stbi_set_flip_vertically_on_load(int flag_true_if_should_flip); - -// as above, but only applies to images loaded on the thread that calls the function -// this function is only available if your compiler supports thread-local variables; -// calling it will fail to link if your compiler doesn't -STBIDEF void stbi_set_unpremultiply_on_load_thread(int flag_true_if_should_unpremultiply); -STBIDEF void stbi_convert_iphone_png_to_rgb_thread(int flag_true_if_should_convert); -STBIDEF void stbi_set_flip_vertically_on_load_thread(int flag_true_if_should_flip); - -// ZLIB client - used by PNG, available for other purposes - -STBIDEF char *stbi_zlib_decode_malloc_guesssize(const char *buffer, int len, int initial_size, int *outlen); -STBIDEF char *stbi_zlib_decode_malloc_guesssize_headerflag(const char *buffer, int len, int initial_size, int *outlen, int parse_header); -STBIDEF char *stbi_zlib_decode_malloc(const char *buffer, int len, int *outlen); -STBIDEF int stbi_zlib_decode_buffer(char *obuffer, int olen, const char *ibuffer, int ilen); - -STBIDEF char *stbi_zlib_decode_noheader_malloc(const char *buffer, int len, int *outlen); -STBIDEF int stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const char *ibuffer, int ilen); - - -#ifdef __cplusplus -} -#endif - -// -// -//// end header file ///////////////////////////////////////////////////// -#endif // STBI_INCLUDE_STB_IMAGE_H - -#ifdef STB_IMAGE_IMPLEMENTATION - -#if defined(STBI_ONLY_JPEG) || defined(STBI_ONLY_PNG) || defined(STBI_ONLY_BMP) \ - || defined(STBI_ONLY_TGA) || defined(STBI_ONLY_GIF) || defined(STBI_ONLY_PSD) \ - || defined(STBI_ONLY_HDR) || defined(STBI_ONLY_PIC) || defined(STBI_ONLY_PNM) \ - || defined(STBI_ONLY_ZLIB) - #ifndef STBI_ONLY_JPEG - #define STBI_NO_JPEG - #endif - #ifndef STBI_ONLY_PNG - #define STBI_NO_PNG - #endif - #ifndef STBI_ONLY_BMP - #define STBI_NO_BMP - #endif - #ifndef STBI_ONLY_PSD - #define STBI_NO_PSD - #endif - #ifndef STBI_ONLY_TGA - #define STBI_NO_TGA - #endif - #ifndef STBI_ONLY_GIF - #define STBI_NO_GIF - #endif - #ifndef STBI_ONLY_HDR - #define STBI_NO_HDR - #endif - #ifndef STBI_ONLY_PIC - #define STBI_NO_PIC - #endif - #ifndef STBI_ONLY_PNM - #define STBI_NO_PNM - #endif -#endif - -#if defined(STBI_NO_PNG) && !defined(STBI_SUPPORT_ZLIB) && !defined(STBI_NO_ZLIB) -#define STBI_NO_ZLIB -#endif - - -#include -#include // ptrdiff_t on osx -#include -#include -#include - -#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR) -#include // ldexp, pow -#endif - -#ifndef STBI_NO_STDIO -#include -#endif - -#ifndef STBI_ASSERT -#include -#define STBI_ASSERT(x) assert(x) -#endif - -#ifdef __cplusplus -#define STBI_EXTERN extern "C" -#else -#define STBI_EXTERN extern -#endif - - -#ifndef _MSC_VER - #ifdef __cplusplus - #define stbi_inline inline - #else - #define stbi_inline - #endif -#else - #define stbi_inline __forceinline -#endif - -#ifndef STBI_NO_THREAD_LOCALS - #if defined(__cplusplus) && __cplusplus >= 201103L - #define STBI_THREAD_LOCAL thread_local - #elif defined(__GNUC__) && __GNUC__ < 5 - #define STBI_THREAD_LOCAL __thread - #elif defined(_MSC_VER) - #define STBI_THREAD_LOCAL __declspec(thread) - #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__) - #define STBI_THREAD_LOCAL _Thread_local - #endif - - #ifndef STBI_THREAD_LOCAL - #if defined(__GNUC__) - #define STBI_THREAD_LOCAL __thread - #endif - #endif -#endif - -#if defined(_MSC_VER) || defined(__SYMBIAN32__) -typedef unsigned short stbi__uint16; -typedef signed short stbi__int16; -typedef unsigned int stbi__uint32; -typedef signed int stbi__int32; -#else -#include -typedef uint16_t stbi__uint16; -typedef int16_t stbi__int16; -typedef uint32_t stbi__uint32; -typedef int32_t stbi__int32; -#endif - -// should produce compiler error if size is wrong -typedef unsigned char validate_uint32[sizeof(stbi__uint32)==4 ? 1 : -1]; - -#ifdef _MSC_VER -#define STBI_NOTUSED(v) (void)(v) -#else -#define STBI_NOTUSED(v) (void)sizeof(v) -#endif - -#ifdef _MSC_VER -#define STBI_HAS_LROTL -#endif - -#ifdef STBI_HAS_LROTL - #define stbi_lrot(x,y) _lrotl(x,y) -#else - #define stbi_lrot(x,y) (((x) << (y)) | ((x) >> (-(y) & 31))) -#endif - -#if defined(STBI_MALLOC) && defined(STBI_FREE) && (defined(STBI_REALLOC) || defined(STBI_REALLOC_SIZED)) -// ok -#elif !defined(STBI_MALLOC) && !defined(STBI_FREE) && !defined(STBI_REALLOC) && !defined(STBI_REALLOC_SIZED) -// ok -#else -#error "Must define all or none of STBI_MALLOC, STBI_FREE, and STBI_REALLOC (or STBI_REALLOC_SIZED)." -#endif - -#ifndef STBI_MALLOC -#define STBI_MALLOC(sz) malloc(sz) -#define STBI_REALLOC(p,newsz) realloc(p,newsz) -#define STBI_FREE(p) free(p) -#endif - -#ifndef STBI_REALLOC_SIZED -#define STBI_REALLOC_SIZED(p,oldsz,newsz) STBI_REALLOC(p,newsz) -#endif - -// x86/x64 detection -#if defined(__x86_64__) || defined(_M_X64) -#define STBI__X64_TARGET -#elif defined(__i386) || defined(_M_IX86) -#define STBI__X86_TARGET -#endif - -#if defined(__GNUC__) && defined(STBI__X86_TARGET) && !defined(__SSE2__) && !defined(STBI_NO_SIMD) -// gcc doesn't support sse2 intrinsics unless you compile with -msse2, -// which in turn means it gets to use SSE2 everywhere. This is unfortunate, -// but previous attempts to provide the SSE2 functions with runtime -// detection caused numerous issues. The way architecture extensions are -// exposed in GCC/Clang is, sadly, not really suited for one-file libs. -// New behavior: if compiled with -msse2, we use SSE2 without any -// detection; if not, we don't use it at all. -#define STBI_NO_SIMD -#endif - -#if defined(__MINGW32__) && defined(STBI__X86_TARGET) && !defined(STBI_MINGW_ENABLE_SSE2) && !defined(STBI_NO_SIMD) -// Note that __MINGW32__ doesn't actually mean 32-bit, so we have to avoid STBI__X64_TARGET -// -// 32-bit MinGW wants ESP to be 16-byte aligned, but this is not in the -// Windows ABI and VC++ as well as Windows DLLs don't maintain that invariant. -// As a result, enabling SSE2 on 32-bit MinGW is dangerous when not -// simultaneously enabling "-mstackrealign". -// -// See https://github.com/nothings/stb/issues/81 for more information. -// -// So default to no SSE2 on 32-bit MinGW. If you've read this far and added -// -mstackrealign to your build settings, feel free to #define STBI_MINGW_ENABLE_SSE2. -#define STBI_NO_SIMD -#endif - -#if !defined(STBI_NO_SIMD) && (defined(STBI__X86_TARGET) || defined(STBI__X64_TARGET)) -#define STBI_SSE2 -#include - -#ifdef _MSC_VER - -#if _MSC_VER >= 1400 // not VC6 -#include // __cpuid -static int stbi__cpuid3(void) -{ - int info[4]; - __cpuid(info,1); - return info[3]; -} -#else -static int stbi__cpuid3(void) -{ - int res; - __asm { - mov eax,1 - cpuid - mov res,edx - } - return res; -} -#endif - -#define STBI_SIMD_ALIGN(type, name) __declspec(align(16)) type name - -#if !defined(STBI_NO_JPEG) && defined(STBI_SSE2) -static int stbi__sse2_available(void) -{ - int info3 = stbi__cpuid3(); - return ((info3 >> 26) & 1) != 0; -} -#endif - -#else // assume GCC-style if not VC++ -#define STBI_SIMD_ALIGN(type, name) type name __attribute__((aligned(16))) - -#if !defined(STBI_NO_JPEG) && defined(STBI_SSE2) -static int stbi__sse2_available(void) -{ - // If we're even attempting to compile this on GCC/Clang, that means - // -msse2 is on, which means the compiler is allowed to use SSE2 - // instructions at will, and so are we. - return 1; -} -#endif - -#endif -#endif - -// ARM NEON -#if defined(STBI_NO_SIMD) && defined(STBI_NEON) -#undef STBI_NEON -#endif - -#ifdef STBI_NEON -#include -#ifdef _MSC_VER -#define STBI_SIMD_ALIGN(type, name) __declspec(align(16)) type name -#else -#define STBI_SIMD_ALIGN(type, name) type name __attribute__((aligned(16))) -#endif -#endif - -#ifndef STBI_SIMD_ALIGN -#define STBI_SIMD_ALIGN(type, name) type name -#endif - -#ifndef STBI_MAX_DIMENSIONS -#define STBI_MAX_DIMENSIONS (1 << 24) -#endif - -/////////////////////////////////////////////// -// -// stbi__context struct and start_xxx functions - -// stbi__context structure is our basic context used by all images, so it -// contains all the IO context, plus some basic image information -typedef struct -{ - stbi__uint32 img_x, img_y; - int img_n, img_out_n; - - stbi_io_callbacks io; - void *io_user_data; - - int read_from_callbacks; - int buflen; - stbi_uc buffer_start[128]; - int callback_already_read; - - stbi_uc *img_buffer, *img_buffer_end; - stbi_uc *img_buffer_original, *img_buffer_original_end; -} stbi__context; - - -static void stbi__refill_buffer(stbi__context *s); - -// initialize a memory-decode context -static void stbi__start_mem(stbi__context *s, stbi_uc const *buffer, int len) -{ - s->io.read = NULL; - s->read_from_callbacks = 0; - s->callback_already_read = 0; - s->img_buffer = s->img_buffer_original = (stbi_uc *) buffer; - s->img_buffer_end = s->img_buffer_original_end = (stbi_uc *) buffer+len; -} - -// initialize a callback-based context -static void stbi__start_callbacks(stbi__context *s, stbi_io_callbacks *c, void *user) -{ - s->io = *c; - s->io_user_data = user; - s->buflen = sizeof(s->buffer_start); - s->read_from_callbacks = 1; - s->callback_already_read = 0; - s->img_buffer = s->img_buffer_original = s->buffer_start; - stbi__refill_buffer(s); - s->img_buffer_original_end = s->img_buffer_end; -} - -#ifndef STBI_NO_STDIO - -static int stbi__stdio_read(void *user, char *data, int size) -{ - return (int) fread(data,1,size,(FILE*) user); -} - -static void stbi__stdio_skip(void *user, int n) -{ - int ch; - fseek((FILE*) user, n, SEEK_CUR); - ch = fgetc((FILE*) user); /* have to read a byte to reset feof()'s flag */ - if (ch != EOF) { - ungetc(ch, (FILE *) user); /* push byte back onto stream if valid. */ - } -} - -static int stbi__stdio_eof(void *user) -{ - return feof((FILE*) user) || ferror((FILE *) user); -} - -static stbi_io_callbacks stbi__stdio_callbacks = -{ - stbi__stdio_read, - stbi__stdio_skip, - stbi__stdio_eof, -}; - -static void stbi__start_file(stbi__context *s, FILE *f) -{ - stbi__start_callbacks(s, &stbi__stdio_callbacks, (void *) f); -} - -//static void stop_file(stbi__context *s) { } - -#endif // !STBI_NO_STDIO - -static void stbi__rewind(stbi__context *s) -{ - // conceptually rewind SHOULD rewind to the beginning of the stream, - // but we just rewind to the beginning of the initial buffer, because - // we only use it after doing 'test', which only ever looks at at most 92 bytes - s->img_buffer = s->img_buffer_original; - s->img_buffer_end = s->img_buffer_original_end; -} - -enum -{ - STBI_ORDER_RGB, - STBI_ORDER_BGR -}; - -typedef struct -{ - int bits_per_channel; - int num_channels; - int channel_order; -} stbi__result_info; - -#ifndef STBI_NO_JPEG -static int stbi__jpeg_test(stbi__context *s); -static void *stbi__jpeg_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri); -static int stbi__jpeg_info(stbi__context *s, int *x, int *y, int *comp); -#endif - -#ifndef STBI_NO_PNG -static int stbi__png_test(stbi__context *s); -static void *stbi__png_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri); -static int stbi__png_info(stbi__context *s, int *x, int *y, int *comp); -static int stbi__png_is16(stbi__context *s); -#endif - -#ifndef STBI_NO_BMP -static int stbi__bmp_test(stbi__context *s); -static void *stbi__bmp_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri); -static int stbi__bmp_info(stbi__context *s, int *x, int *y, int *comp); -#endif - -#ifndef STBI_NO_TGA -static int stbi__tga_test(stbi__context *s); -static void *stbi__tga_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri); -static int stbi__tga_info(stbi__context *s, int *x, int *y, int *comp); -#endif - -#ifndef STBI_NO_PSD -static int stbi__psd_test(stbi__context *s); -static void *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri, int bpc); -static int stbi__psd_info(stbi__context *s, int *x, int *y, int *comp); -static int stbi__psd_is16(stbi__context *s); -#endif - -#ifndef STBI_NO_HDR -static int stbi__hdr_test(stbi__context *s); -static float *stbi__hdr_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri); -static int stbi__hdr_info(stbi__context *s, int *x, int *y, int *comp); -#endif - -#ifndef STBI_NO_PIC -static int stbi__pic_test(stbi__context *s); -static void *stbi__pic_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri); -static int stbi__pic_info(stbi__context *s, int *x, int *y, int *comp); -#endif - -#ifndef STBI_NO_GIF -static int stbi__gif_test(stbi__context *s); -static void *stbi__gif_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri); -static void *stbi__load_gif_main(stbi__context *s, int **delays, int *x, int *y, int *z, int *comp, int req_comp); -static int stbi__gif_info(stbi__context *s, int *x, int *y, int *comp); -#endif - -#ifndef STBI_NO_PNM -static int stbi__pnm_test(stbi__context *s); -static void *stbi__pnm_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri); -static int stbi__pnm_info(stbi__context *s, int *x, int *y, int *comp); -static int stbi__pnm_is16(stbi__context *s); -#endif - -static -#ifdef STBI_THREAD_LOCAL -STBI_THREAD_LOCAL -#endif -const char *stbi__g_failure_reason; - -STBIDEF const char *stbi_failure_reason(void) -{ - return stbi__g_failure_reason; -} - -#ifndef STBI_NO_FAILURE_STRINGS -static int stbi__err(const char *str) -{ - stbi__g_failure_reason = str; - return 0; -} -#endif - -static void *stbi__malloc(size_t size) -{ - return STBI_MALLOC(size); -} - -// stb_image uses ints pervasively, including for offset calculations. -// therefore the largest decoded image size we can support with the -// current code, even on 64-bit targets, is INT_MAX. this is not a -// significant limitation for the intended use case. -// -// we do, however, need to make sure our size calculations don't -// overflow. hence a few helper functions for size calculations that -// multiply integers together, making sure that they're non-negative -// and no overflow occurs. - -// return 1 if the sum is valid, 0 on overflow. -// negative terms are considered invalid. -static int stbi__addsizes_valid(int a, int b) -{ - if (b < 0) return 0; - // now 0 <= b <= INT_MAX, hence also - // 0 <= INT_MAX - b <= INTMAX. - // And "a + b <= INT_MAX" (which might overflow) is the - // same as a <= INT_MAX - b (no overflow) - return a <= INT_MAX - b; -} - -// returns 1 if the product is valid, 0 on overflow. -// negative factors are considered invalid. -static int stbi__mul2sizes_valid(int a, int b) -{ - if (a < 0 || b < 0) return 0; - if (b == 0) return 1; // mul-by-0 is always safe - // portable way to check for no overflows in a*b - return a <= INT_MAX/b; -} - -#if !defined(STBI_NO_JPEG) || !defined(STBI_NO_PNG) || !defined(STBI_NO_TGA) || !defined(STBI_NO_HDR) -// returns 1 if "a*b + add" has no negative terms/factors and doesn't overflow -static int stbi__mad2sizes_valid(int a, int b, int add) -{ - return stbi__mul2sizes_valid(a, b) && stbi__addsizes_valid(a*b, add); -} -#endif - -// returns 1 if "a*b*c + add" has no negative terms/factors and doesn't overflow -static int stbi__mad3sizes_valid(int a, int b, int c, int add) -{ - return stbi__mul2sizes_valid(a, b) && stbi__mul2sizes_valid(a*b, c) && - stbi__addsizes_valid(a*b*c, add); -} - -// returns 1 if "a*b*c*d + add" has no negative terms/factors and doesn't overflow -#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR) || !defined(STBI_NO_PNM) -static int stbi__mad4sizes_valid(int a, int b, int c, int d, int add) -{ - return stbi__mul2sizes_valid(a, b) && stbi__mul2sizes_valid(a*b, c) && - stbi__mul2sizes_valid(a*b*c, d) && stbi__addsizes_valid(a*b*c*d, add); -} -#endif - -#if !defined(STBI_NO_JPEG) || !defined(STBI_NO_PNG) || !defined(STBI_NO_TGA) || !defined(STBI_NO_HDR) -// mallocs with size overflow checking -static void *stbi__malloc_mad2(int a, int b, int add) -{ - if (!stbi__mad2sizes_valid(a, b, add)) return NULL; - return stbi__malloc(a*b + add); -} -#endif - -static void *stbi__malloc_mad3(int a, int b, int c, int add) -{ - if (!stbi__mad3sizes_valid(a, b, c, add)) return NULL; - return stbi__malloc(a*b*c + add); -} - -#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR) || !defined(STBI_NO_PNM) -static void *stbi__malloc_mad4(int a, int b, int c, int d, int add) -{ - if (!stbi__mad4sizes_valid(a, b, c, d, add)) return NULL; - return stbi__malloc(a*b*c*d + add); -} -#endif - -// returns 1 if the sum of two signed ints is valid (between -2^31 and 2^31-1 inclusive), 0 on overflow. -static int stbi__addints_valid(int a, int b) -{ - if ((a >= 0) != (b >= 0)) return 1; // a and b have different signs, so no overflow - if (a < 0 && b < 0) return a >= INT_MIN - b; // same as a + b >= INT_MIN; INT_MIN - b cannot overflow since b < 0. - return a <= INT_MAX - b; -} - -// returns 1 if the product of two signed shorts is valid, 0 on overflow. -static int stbi__mul2shorts_valid(short a, short b) -{ - if (b == 0 || b == -1) return 1; // multiplication by 0 is always 0; check for -1 so SHRT_MIN/b doesn't overflow - if ((a >= 0) == (b >= 0)) return a <= SHRT_MAX/b; // product is positive, so similar to mul2sizes_valid - if (b < 0) return a <= SHRT_MIN / b; // same as a * b >= SHRT_MIN - return a >= SHRT_MIN / b; -} - -// stbi__err - error -// stbi__errpf - error returning pointer to float -// stbi__errpuc - error returning pointer to unsigned char - -#ifdef STBI_NO_FAILURE_STRINGS - #define stbi__err(x,y) 0 -#elif defined(STBI_FAILURE_USERMSG) - #define stbi__err(x,y) stbi__err(y) -#else - #define stbi__err(x,y) stbi__err(x) -#endif - -#define stbi__errpf(x,y) ((float *)(size_t) (stbi__err(x,y)?NULL:NULL)) -#define stbi__errpuc(x,y) ((unsigned char *)(size_t) (stbi__err(x,y)?NULL:NULL)) - -STBIDEF void stbi_image_free(void *retval_from_stbi_load) -{ - STBI_FREE(retval_from_stbi_load); -} - -#ifndef STBI_NO_LINEAR -static float *stbi__ldr_to_hdr(stbi_uc *data, int x, int y, int comp); -#endif - -#ifndef STBI_NO_HDR -static stbi_uc *stbi__hdr_to_ldr(float *data, int x, int y, int comp); -#endif - -static int stbi__vertically_flip_on_load_global = 0; - -STBIDEF void stbi_set_flip_vertically_on_load(int flag_true_if_should_flip) -{ - stbi__vertically_flip_on_load_global = flag_true_if_should_flip; -} - -#ifndef STBI_THREAD_LOCAL -#define stbi__vertically_flip_on_load stbi__vertically_flip_on_load_global -#else -static STBI_THREAD_LOCAL int stbi__vertically_flip_on_load_local, stbi__vertically_flip_on_load_set; - -STBIDEF void stbi_set_flip_vertically_on_load_thread(int flag_true_if_should_flip) -{ - stbi__vertically_flip_on_load_local = flag_true_if_should_flip; - stbi__vertically_flip_on_load_set = 1; -} - -#define stbi__vertically_flip_on_load (stbi__vertically_flip_on_load_set \ - ? stbi__vertically_flip_on_load_local \ - : stbi__vertically_flip_on_load_global) -#endif // STBI_THREAD_LOCAL - -static void *stbi__load_main(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri, int bpc) -{ - memset(ri, 0, sizeof(*ri)); // make sure it's initialized if we add new fields - ri->bits_per_channel = 8; // default is 8 so most paths don't have to be changed - ri->channel_order = STBI_ORDER_RGB; // all current input & output are this, but this is here so we can add BGR order - ri->num_channels = 0; - - // test the formats with a very explicit header first (at least a FOURCC - // or distinctive magic number first) - #ifndef STBI_NO_PNG - if (stbi__png_test(s)) return stbi__png_load(s,x,y,comp,req_comp, ri); - #endif - #ifndef STBI_NO_BMP - if (stbi__bmp_test(s)) return stbi__bmp_load(s,x,y,comp,req_comp, ri); - #endif - #ifndef STBI_NO_GIF - if (stbi__gif_test(s)) return stbi__gif_load(s,x,y,comp,req_comp, ri); - #endif - #ifndef STBI_NO_PSD - if (stbi__psd_test(s)) return stbi__psd_load(s,x,y,comp,req_comp, ri, bpc); - #else - STBI_NOTUSED(bpc); - #endif - #ifndef STBI_NO_PIC - if (stbi__pic_test(s)) return stbi__pic_load(s,x,y,comp,req_comp, ri); - #endif - - // then the formats that can end up attempting to load with just 1 or 2 - // bytes matching expectations; these are prone to false positives, so - // try them later - #ifndef STBI_NO_JPEG - if (stbi__jpeg_test(s)) return stbi__jpeg_load(s,x,y,comp,req_comp, ri); - #endif - #ifndef STBI_NO_PNM - if (stbi__pnm_test(s)) return stbi__pnm_load(s,x,y,comp,req_comp, ri); - #endif - - #ifndef STBI_NO_HDR - if (stbi__hdr_test(s)) { - float *hdr = stbi__hdr_load(s, x,y,comp,req_comp, ri); - return stbi__hdr_to_ldr(hdr, *x, *y, req_comp ? req_comp : *comp); - } - #endif - - #ifndef STBI_NO_TGA - // test tga last because it's a crappy test! - if (stbi__tga_test(s)) - return stbi__tga_load(s,x,y,comp,req_comp, ri); - #endif - - return stbi__errpuc("unknown image type", "Image not of any known type, or corrupt"); -} - -static stbi_uc *stbi__convert_16_to_8(stbi__uint16 *orig, int w, int h, int channels) -{ - int i; - int img_len = w * h * channels; - stbi_uc *reduced; - - reduced = (stbi_uc *) stbi__malloc(img_len); - if (reduced == NULL) return stbi__errpuc("outofmem", "Out of memory"); - - for (i = 0; i < img_len; ++i) - reduced[i] = (stbi_uc)((orig[i] >> 8) & 0xFF); // top half of each byte is sufficient approx of 16->8 bit scaling - - STBI_FREE(orig); - return reduced; -} - -static stbi__uint16 *stbi__convert_8_to_16(stbi_uc *orig, int w, int h, int channels) -{ - int i; - int img_len = w * h * channels; - stbi__uint16 *enlarged; - - enlarged = (stbi__uint16 *) stbi__malloc(img_len*2); - if (enlarged == NULL) return (stbi__uint16 *) stbi__errpuc("outofmem", "Out of memory"); - - for (i = 0; i < img_len; ++i) - enlarged[i] = (stbi__uint16)((orig[i] << 8) + orig[i]); // replicate to high and low byte, maps 0->0, 255->0xffff - - STBI_FREE(orig); - return enlarged; -} - -static void stbi__vertical_flip(void *image, int w, int h, int bytes_per_pixel) -{ - int row; - size_t bytes_per_row = (size_t)w * bytes_per_pixel; - stbi_uc temp[2048]; - stbi_uc *bytes = (stbi_uc *)image; - - for (row = 0; row < (h>>1); row++) { - stbi_uc *row0 = bytes + row*bytes_per_row; - stbi_uc *row1 = bytes + (h - row - 1)*bytes_per_row; - // swap row0 with row1 - size_t bytes_left = bytes_per_row; - while (bytes_left) { - size_t bytes_copy = (bytes_left < sizeof(temp)) ? bytes_left : sizeof(temp); - memcpy(temp, row0, bytes_copy); - memcpy(row0, row1, bytes_copy); - memcpy(row1, temp, bytes_copy); - row0 += bytes_copy; - row1 += bytes_copy; - bytes_left -= bytes_copy; - } - } -} - -#ifndef STBI_NO_GIF -static void stbi__vertical_flip_slices(void *image, int w, int h, int z, int bytes_per_pixel) -{ - int slice; - int slice_size = w * h * bytes_per_pixel; - - stbi_uc *bytes = (stbi_uc *)image; - for (slice = 0; slice < z; ++slice) { - stbi__vertical_flip(bytes, w, h, bytes_per_pixel); - bytes += slice_size; - } -} -#endif - -static unsigned char *stbi__load_and_postprocess_8bit(stbi__context *s, int *x, int *y, int *comp, int req_comp) -{ - stbi__result_info ri; - void *result = stbi__load_main(s, x, y, comp, req_comp, &ri, 8); - - if (result == NULL) - return NULL; - - // it is the responsibility of the loaders to make sure we get either 8 or 16 bit. - STBI_ASSERT(ri.bits_per_channel == 8 || ri.bits_per_channel == 16); - - if (ri.bits_per_channel != 8) { - result = stbi__convert_16_to_8((stbi__uint16 *) result, *x, *y, req_comp == 0 ? *comp : req_comp); - ri.bits_per_channel = 8; - } - - // @TODO: move stbi__convert_format to here - - if (stbi__vertically_flip_on_load) { - int channels = req_comp ? req_comp : *comp; - stbi__vertical_flip(result, *x, *y, channels * sizeof(stbi_uc)); - } - - return (unsigned char *) result; -} - -static stbi__uint16 *stbi__load_and_postprocess_16bit(stbi__context *s, int *x, int *y, int *comp, int req_comp) -{ - stbi__result_info ri; - void *result = stbi__load_main(s, x, y, comp, req_comp, &ri, 16); - - if (result == NULL) - return NULL; - - // it is the responsibility of the loaders to make sure we get either 8 or 16 bit. - STBI_ASSERT(ri.bits_per_channel == 8 || ri.bits_per_channel == 16); - - if (ri.bits_per_channel != 16) { - result = stbi__convert_8_to_16((stbi_uc *) result, *x, *y, req_comp == 0 ? *comp : req_comp); - ri.bits_per_channel = 16; - } - - // @TODO: move stbi__convert_format16 to here - // @TODO: special case RGB-to-Y (and RGBA-to-YA) for 8-bit-to-16-bit case to keep more precision - - if (stbi__vertically_flip_on_load) { - int channels = req_comp ? req_comp : *comp; - stbi__vertical_flip(result, *x, *y, channels * sizeof(stbi__uint16)); - } - - return (stbi__uint16 *) result; -} - -#if !defined(STBI_NO_HDR) && !defined(STBI_NO_LINEAR) -static void stbi__float_postprocess(float *result, int *x, int *y, int *comp, int req_comp) -{ - if (stbi__vertically_flip_on_load && result != NULL) { - int channels = req_comp ? req_comp : *comp; - stbi__vertical_flip(result, *x, *y, channels * sizeof(float)); - } -} -#endif - -#ifndef STBI_NO_STDIO - -#if defined(_WIN32) && defined(STBI_WINDOWS_UTF8) -STBI_EXTERN __declspec(dllimport) int __stdcall MultiByteToWideChar(unsigned int cp, unsigned long flags, const char *str, int cbmb, wchar_t *widestr, int cchwide); -STBI_EXTERN __declspec(dllimport) int __stdcall WideCharToMultiByte(unsigned int cp, unsigned long flags, const wchar_t *widestr, int cchwide, char *str, int cbmb, const char *defchar, int *used_default); -#endif - -#if defined(_WIN32) && defined(STBI_WINDOWS_UTF8) -STBIDEF int stbi_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input) -{ - return WideCharToMultiByte(65001 /* UTF8 */, 0, input, -1, buffer, (int) bufferlen, NULL, NULL); -} -#endif - -static FILE *stbi__fopen(char const *filename, char const *mode) -{ - FILE *f; -#if defined(_WIN32) && defined(STBI_WINDOWS_UTF8) - wchar_t wMode[64]; - wchar_t wFilename[1024]; - if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, filename, -1, wFilename, sizeof(wFilename)/sizeof(*wFilename))) - return 0; - - if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, mode, -1, wMode, sizeof(wMode)/sizeof(*wMode))) - return 0; - -#if defined(_MSC_VER) && _MSC_VER >= 1400 - if (0 != _wfopen_s(&f, wFilename, wMode)) - f = 0; -#else - f = _wfopen(wFilename, wMode); -#endif - -#elif defined(_MSC_VER) && _MSC_VER >= 1400 - if (0 != fopen_s(&f, filename, mode)) - f=0; -#else - f = fopen(filename, mode); -#endif - return f; -} - - -STBIDEF stbi_uc *stbi_load(char const *filename, int *x, int *y, int *comp, int req_comp) -{ - FILE *f = stbi__fopen(filename, "rb"); - unsigned char *result; - if (!f) return stbi__errpuc("can't fopen", "Unable to open file"); - result = stbi_load_from_file(f,x,y,comp,req_comp); - fclose(f); - return result; -} - -STBIDEF stbi_uc *stbi_load_from_file(FILE *f, int *x, int *y, int *comp, int req_comp) -{ - unsigned char *result; - stbi__context s; - stbi__start_file(&s,f); - result = stbi__load_and_postprocess_8bit(&s,x,y,comp,req_comp); - if (result) { - // need to 'unget' all the characters in the IO buffer - fseek(f, - (int) (s.img_buffer_end - s.img_buffer), SEEK_CUR); - } - return result; -} - -STBIDEF stbi__uint16 *stbi_load_from_file_16(FILE *f, int *x, int *y, int *comp, int req_comp) -{ - stbi__uint16 *result; - stbi__context s; - stbi__start_file(&s,f); - result = stbi__load_and_postprocess_16bit(&s,x,y,comp,req_comp); - if (result) { - // need to 'unget' all the characters in the IO buffer - fseek(f, - (int) (s.img_buffer_end - s.img_buffer), SEEK_CUR); - } - return result; -} - -STBIDEF stbi_us *stbi_load_16(char const *filename, int *x, int *y, int *comp, int req_comp) -{ - FILE *f = stbi__fopen(filename, "rb"); - stbi__uint16 *result; - if (!f) return (stbi_us *) stbi__errpuc("can't fopen", "Unable to open file"); - result = stbi_load_from_file_16(f,x,y,comp,req_comp); - fclose(f); - return result; -} - - -#endif //!STBI_NO_STDIO - -STBIDEF stbi_us *stbi_load_16_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *channels_in_file, int desired_channels) -{ - stbi__context s; - stbi__start_mem(&s,buffer,len); - return stbi__load_and_postprocess_16bit(&s,x,y,channels_in_file,desired_channels); -} - -STBIDEF stbi_us *stbi_load_16_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *channels_in_file, int desired_channels) -{ - stbi__context s; - stbi__start_callbacks(&s, (stbi_io_callbacks *)clbk, user); - return stbi__load_and_postprocess_16bit(&s,x,y,channels_in_file,desired_channels); -} - -STBIDEF stbi_uc *stbi_load_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp) -{ - stbi__context s; - stbi__start_mem(&s,buffer,len); - return stbi__load_and_postprocess_8bit(&s,x,y,comp,req_comp); -} - -STBIDEF stbi_uc *stbi_load_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp, int req_comp) -{ - stbi__context s; - stbi__start_callbacks(&s, (stbi_io_callbacks *) clbk, user); - return stbi__load_and_postprocess_8bit(&s,x,y,comp,req_comp); -} - -#ifndef STBI_NO_GIF -STBIDEF stbi_uc *stbi_load_gif_from_memory(stbi_uc const *buffer, int len, int **delays, int *x, int *y, int *z, int *comp, int req_comp) -{ - unsigned char *result; - stbi__context s; - stbi__start_mem(&s,buffer,len); - - result = (unsigned char*) stbi__load_gif_main(&s, delays, x, y, z, comp, req_comp); - if (stbi__vertically_flip_on_load) { - stbi__vertical_flip_slices( result, *x, *y, *z, *comp ); - } - - return result; -} -#endif - -#ifndef STBI_NO_LINEAR -static float *stbi__loadf_main(stbi__context *s, int *x, int *y, int *comp, int req_comp) -{ - unsigned char *data; - #ifndef STBI_NO_HDR - if (stbi__hdr_test(s)) { - stbi__result_info ri; - float *hdr_data = stbi__hdr_load(s,x,y,comp,req_comp, &ri); - if (hdr_data) - stbi__float_postprocess(hdr_data,x,y,comp,req_comp); - return hdr_data; - } - #endif - data = stbi__load_and_postprocess_8bit(s, x, y, comp, req_comp); - if (data) - return stbi__ldr_to_hdr(data, *x, *y, req_comp ? req_comp : *comp); - return stbi__errpf("unknown image type", "Image not of any known type, or corrupt"); -} - -STBIDEF float *stbi_loadf_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp) -{ - stbi__context s; - stbi__start_mem(&s,buffer,len); - return stbi__loadf_main(&s,x,y,comp,req_comp); -} - -STBIDEF float *stbi_loadf_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp, int req_comp) -{ - stbi__context s; - stbi__start_callbacks(&s, (stbi_io_callbacks *) clbk, user); - return stbi__loadf_main(&s,x,y,comp,req_comp); -} - -#ifndef STBI_NO_STDIO -STBIDEF float *stbi_loadf(char const *filename, int *x, int *y, int *comp, int req_comp) -{ - float *result; - FILE *f = stbi__fopen(filename, "rb"); - if (!f) return stbi__errpf("can't fopen", "Unable to open file"); - result = stbi_loadf_from_file(f,x,y,comp,req_comp); - fclose(f); - return result; -} - -STBIDEF float *stbi_loadf_from_file(FILE *f, int *x, int *y, int *comp, int req_comp) -{ - stbi__context s; - stbi__start_file(&s,f); - return stbi__loadf_main(&s,x,y,comp,req_comp); -} -#endif // !STBI_NO_STDIO - -#endif // !STBI_NO_LINEAR - -// these is-hdr-or-not is defined independent of whether STBI_NO_LINEAR is -// defined, for API simplicity; if STBI_NO_LINEAR is defined, it always -// reports false! - -STBIDEF int stbi_is_hdr_from_memory(stbi_uc const *buffer, int len) -{ - #ifndef STBI_NO_HDR - stbi__context s; - stbi__start_mem(&s,buffer,len); - return stbi__hdr_test(&s); - #else - STBI_NOTUSED(buffer); - STBI_NOTUSED(len); - return 0; - #endif -} - -#ifndef STBI_NO_STDIO -STBIDEF int stbi_is_hdr (char const *filename) -{ - FILE *f = stbi__fopen(filename, "rb"); - int result=0; - if (f) { - result = stbi_is_hdr_from_file(f); - fclose(f); - } - return result; -} - -STBIDEF int stbi_is_hdr_from_file(FILE *f) -{ - #ifndef STBI_NO_HDR - long pos = ftell(f); - int res; - stbi__context s; - stbi__start_file(&s,f); - res = stbi__hdr_test(&s); - fseek(f, pos, SEEK_SET); - return res; - #else - STBI_NOTUSED(f); - return 0; - #endif -} -#endif // !STBI_NO_STDIO - -STBIDEF int stbi_is_hdr_from_callbacks(stbi_io_callbacks const *clbk, void *user) -{ - #ifndef STBI_NO_HDR - stbi__context s; - stbi__start_callbacks(&s, (stbi_io_callbacks *) clbk, user); - return stbi__hdr_test(&s); - #else - STBI_NOTUSED(clbk); - STBI_NOTUSED(user); - return 0; - #endif -} - -#ifndef STBI_NO_LINEAR -static float stbi__l2h_gamma=2.2f, stbi__l2h_scale=1.0f; - -STBIDEF void stbi_ldr_to_hdr_gamma(float gamma) { stbi__l2h_gamma = gamma; } -STBIDEF void stbi_ldr_to_hdr_scale(float scale) { stbi__l2h_scale = scale; } -#endif - -static float stbi__h2l_gamma_i=1.0f/2.2f, stbi__h2l_scale_i=1.0f; - -STBIDEF void stbi_hdr_to_ldr_gamma(float gamma) { stbi__h2l_gamma_i = 1/gamma; } -STBIDEF void stbi_hdr_to_ldr_scale(float scale) { stbi__h2l_scale_i = 1/scale; } - - -////////////////////////////////////////////////////////////////////////////// -// -// Common code used by all image loaders -// - -enum -{ - STBI__SCAN_load=0, - STBI__SCAN_type, - STBI__SCAN_header -}; - -static void stbi__refill_buffer(stbi__context *s) -{ - int n = (s->io.read)(s->io_user_data,(char*)s->buffer_start,s->buflen); - s->callback_already_read += (int) (s->img_buffer - s->img_buffer_original); - if (n == 0) { - // at end of file, treat same as if from memory, but need to handle case - // where s->img_buffer isn't pointing to safe memory, e.g. 0-byte file - s->read_from_callbacks = 0; - s->img_buffer = s->buffer_start; - s->img_buffer_end = s->buffer_start+1; - *s->img_buffer = 0; - } else { - s->img_buffer = s->buffer_start; - s->img_buffer_end = s->buffer_start + n; - } -} - -stbi_inline static stbi_uc stbi__get8(stbi__context *s) -{ - if (s->img_buffer < s->img_buffer_end) - return *s->img_buffer++; - if (s->read_from_callbacks) { - stbi__refill_buffer(s); - return *s->img_buffer++; - } - return 0; -} - -#if defined(STBI_NO_JPEG) && defined(STBI_NO_HDR) && defined(STBI_NO_PIC) && defined(STBI_NO_PNM) -// nothing -#else -stbi_inline static int stbi__at_eof(stbi__context *s) -{ - if (s->io.read) { - if (!(s->io.eof)(s->io_user_data)) return 0; - // if feof() is true, check if buffer = end - // special case: we've only got the special 0 character at the end - if (s->read_from_callbacks == 0) return 1; - } - - return s->img_buffer >= s->img_buffer_end; -} -#endif - -#if defined(STBI_NO_JPEG) && defined(STBI_NO_PNG) && defined(STBI_NO_BMP) && defined(STBI_NO_PSD) && defined(STBI_NO_TGA) && defined(STBI_NO_GIF) && defined(STBI_NO_PIC) -// nothing -#else -static void stbi__skip(stbi__context *s, int n) -{ - if (n == 0) return; // already there! - if (n < 0) { - s->img_buffer = s->img_buffer_end; - return; - } - if (s->io.read) { - int blen = (int) (s->img_buffer_end - s->img_buffer); - if (blen < n) { - s->img_buffer = s->img_buffer_end; - (s->io.skip)(s->io_user_data, n - blen); - return; - } - } - s->img_buffer += n; -} -#endif - -#if defined(STBI_NO_PNG) && defined(STBI_NO_TGA) && defined(STBI_NO_HDR) && defined(STBI_NO_PNM) -// nothing -#else -static int stbi__getn(stbi__context *s, stbi_uc *buffer, int n) -{ - if (s->io.read) { - int blen = (int) (s->img_buffer_end - s->img_buffer); - if (blen < n) { - int res, count; - - memcpy(buffer, s->img_buffer, blen); - - count = (s->io.read)(s->io_user_data, (char*) buffer + blen, n - blen); - res = (count == (n-blen)); - s->img_buffer = s->img_buffer_end; - return res; - } - } - - if (s->img_buffer+n <= s->img_buffer_end) { - memcpy(buffer, s->img_buffer, n); - s->img_buffer += n; - return 1; - } else - return 0; -} -#endif - -#if defined(STBI_NO_JPEG) && defined(STBI_NO_PNG) && defined(STBI_NO_PSD) && defined(STBI_NO_PIC) -// nothing -#else -static int stbi__get16be(stbi__context *s) -{ - int z = stbi__get8(s); - return (z << 8) + stbi__get8(s); -} -#endif - -#if defined(STBI_NO_PNG) && defined(STBI_NO_PSD) && defined(STBI_NO_PIC) -// nothing -#else -static stbi__uint32 stbi__get32be(stbi__context *s) -{ - stbi__uint32 z = stbi__get16be(s); - return (z << 16) + stbi__get16be(s); -} -#endif - -#if defined(STBI_NO_BMP) && defined(STBI_NO_TGA) && defined(STBI_NO_GIF) -// nothing -#else -static int stbi__get16le(stbi__context *s) -{ - int z = stbi__get8(s); - return z + (stbi__get8(s) << 8); -} -#endif - -#ifndef STBI_NO_BMP -static stbi__uint32 stbi__get32le(stbi__context *s) -{ - stbi__uint32 z = stbi__get16le(s); - z += (stbi__uint32)stbi__get16le(s) << 16; - return z; -} -#endif - -#define STBI__BYTECAST(x) ((stbi_uc) ((x) & 255)) // truncate int to byte without warnings - -#if defined(STBI_NO_JPEG) && defined(STBI_NO_PNG) && defined(STBI_NO_BMP) && defined(STBI_NO_PSD) && defined(STBI_NO_TGA) && defined(STBI_NO_GIF) && defined(STBI_NO_PIC) && defined(STBI_NO_PNM) -// nothing -#else -////////////////////////////////////////////////////////////////////////////// -// -// generic converter from built-in img_n to req_comp -// individual types do this automatically as much as possible (e.g. jpeg -// does all cases internally since it needs to colorspace convert anyway, -// and it never has alpha, so very few cases ). png can automatically -// interleave an alpha=255 channel, but falls back to this for other cases -// -// assume data buffer is malloced, so malloc a new one and free that one -// only failure mode is malloc failing - -static stbi_uc stbi__compute_y(int r, int g, int b) -{ - return (stbi_uc) (((r*77) + (g*150) + (29*b)) >> 8); -} -#endif - -#if defined(STBI_NO_PNG) && defined(STBI_NO_BMP) && defined(STBI_NO_PSD) && defined(STBI_NO_TGA) && defined(STBI_NO_GIF) && defined(STBI_NO_PIC) && defined(STBI_NO_PNM) -// nothing -#else -static unsigned char *stbi__convert_format(unsigned char *data, int img_n, int req_comp, unsigned int x, unsigned int y) -{ - int i,j; - unsigned char *good; - - if (req_comp == img_n) return data; - STBI_ASSERT(req_comp >= 1 && req_comp <= 4); - - good = (unsigned char *) stbi__malloc_mad3(req_comp, x, y, 0); - if (good == NULL) { - STBI_FREE(data); - return stbi__errpuc("outofmem", "Out of memory"); - } - - for (j=0; j < (int) y; ++j) { - unsigned char *src = data + j * x * img_n ; - unsigned char *dest = good + j * x * req_comp; - - #define STBI__COMBO(a,b) ((a)*8+(b)) - #define STBI__CASE(a,b) case STBI__COMBO(a,b): for(i=x-1; i >= 0; --i, src += a, dest += b) - // convert source image with img_n components to one with req_comp components; - // avoid switch per pixel, so use switch per scanline and massive macros - switch (STBI__COMBO(img_n, req_comp)) { - STBI__CASE(1,2) { dest[0]=src[0]; dest[1]=255; } break; - STBI__CASE(1,3) { dest[0]=dest[1]=dest[2]=src[0]; } break; - STBI__CASE(1,4) { dest[0]=dest[1]=dest[2]=src[0]; dest[3]=255; } break; - STBI__CASE(2,1) { dest[0]=src[0]; } break; - STBI__CASE(2,3) { dest[0]=dest[1]=dest[2]=src[0]; } break; - STBI__CASE(2,4) { dest[0]=dest[1]=dest[2]=src[0]; dest[3]=src[1]; } break; - STBI__CASE(3,4) { dest[0]=src[0];dest[1]=src[1];dest[2]=src[2];dest[3]=255; } break; - STBI__CASE(3,1) { dest[0]=stbi__compute_y(src[0],src[1],src[2]); } break; - STBI__CASE(3,2) { dest[0]=stbi__compute_y(src[0],src[1],src[2]); dest[1] = 255; } break; - STBI__CASE(4,1) { dest[0]=stbi__compute_y(src[0],src[1],src[2]); } break; - STBI__CASE(4,2) { dest[0]=stbi__compute_y(src[0],src[1],src[2]); dest[1] = src[3]; } break; - STBI__CASE(4,3) { dest[0]=src[0];dest[1]=src[1];dest[2]=src[2]; } break; - default: STBI_ASSERT(0); STBI_FREE(data); STBI_FREE(good); return stbi__errpuc("unsupported", "Unsupported format conversion"); - } - #undef STBI__CASE - } - - STBI_FREE(data); - return good; -} -#endif - -#if defined(STBI_NO_PNG) && defined(STBI_NO_PSD) -// nothing -#else -static stbi__uint16 stbi__compute_y_16(int r, int g, int b) -{ - return (stbi__uint16) (((r*77) + (g*150) + (29*b)) >> 8); -} -#endif - -#if defined(STBI_NO_PNG) && defined(STBI_NO_PSD) -// nothing -#else -static stbi__uint16 *stbi__convert_format16(stbi__uint16 *data, int img_n, int req_comp, unsigned int x, unsigned int y) -{ - int i,j; - stbi__uint16 *good; - - if (req_comp == img_n) return data; - STBI_ASSERT(req_comp >= 1 && req_comp <= 4); - - good = (stbi__uint16 *) stbi__malloc(req_comp * x * y * 2); - if (good == NULL) { - STBI_FREE(data); - return (stbi__uint16 *) stbi__errpuc("outofmem", "Out of memory"); - } - - for (j=0; j < (int) y; ++j) { - stbi__uint16 *src = data + j * x * img_n ; - stbi__uint16 *dest = good + j * x * req_comp; - - #define STBI__COMBO(a,b) ((a)*8+(b)) - #define STBI__CASE(a,b) case STBI__COMBO(a,b): for(i=x-1; i >= 0; --i, src += a, dest += b) - // convert source image with img_n components to one with req_comp components; - // avoid switch per pixel, so use switch per scanline and massive macros - switch (STBI__COMBO(img_n, req_comp)) { - STBI__CASE(1,2) { dest[0]=src[0]; dest[1]=0xffff; } break; - STBI__CASE(1,3) { dest[0]=dest[1]=dest[2]=src[0]; } break; - STBI__CASE(1,4) { dest[0]=dest[1]=dest[2]=src[0]; dest[3]=0xffff; } break; - STBI__CASE(2,1) { dest[0]=src[0]; } break; - STBI__CASE(2,3) { dest[0]=dest[1]=dest[2]=src[0]; } break; - STBI__CASE(2,4) { dest[0]=dest[1]=dest[2]=src[0]; dest[3]=src[1]; } break; - STBI__CASE(3,4) { dest[0]=src[0];dest[1]=src[1];dest[2]=src[2];dest[3]=0xffff; } break; - STBI__CASE(3,1) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]); } break; - STBI__CASE(3,2) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]); dest[1] = 0xffff; } break; - STBI__CASE(4,1) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]); } break; - STBI__CASE(4,2) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]); dest[1] = src[3]; } break; - STBI__CASE(4,3) { dest[0]=src[0];dest[1]=src[1];dest[2]=src[2]; } break; - default: STBI_ASSERT(0); STBI_FREE(data); STBI_FREE(good); return (stbi__uint16*) stbi__errpuc("unsupported", "Unsupported format conversion"); - } - #undef STBI__CASE - } - - STBI_FREE(data); - return good; -} -#endif - -#ifndef STBI_NO_LINEAR -static float *stbi__ldr_to_hdr(stbi_uc *data, int x, int y, int comp) -{ - int i,k,n; - float *output; - if (!data) return NULL; - output = (float *) stbi__malloc_mad4(x, y, comp, sizeof(float), 0); - if (output == NULL) { STBI_FREE(data); return stbi__errpf("outofmem", "Out of memory"); } - // compute number of non-alpha components - if (comp & 1) n = comp; else n = comp-1; - for (i=0; i < x*y; ++i) { - for (k=0; k < n; ++k) { - output[i*comp + k] = (float) (pow(data[i*comp+k]/255.0f, stbi__l2h_gamma) * stbi__l2h_scale); - } - } - if (n < comp) { - for (i=0; i < x*y; ++i) { - output[i*comp + n] = data[i*comp + n]/255.0f; - } - } - STBI_FREE(data); - return output; -} -#endif - -#ifndef STBI_NO_HDR -#define stbi__float2int(x) ((int) (x)) -static stbi_uc *stbi__hdr_to_ldr(float *data, int x, int y, int comp) -{ - int i,k,n; - stbi_uc *output; - if (!data) return NULL; - output = (stbi_uc *) stbi__malloc_mad3(x, y, comp, 0); - if (output == NULL) { STBI_FREE(data); return stbi__errpuc("outofmem", "Out of memory"); } - // compute number of non-alpha components - if (comp & 1) n = comp; else n = comp-1; - for (i=0; i < x*y; ++i) { - for (k=0; k < n; ++k) { - float z = (float) pow(data[i*comp+k]*stbi__h2l_scale_i, stbi__h2l_gamma_i) * 255 + 0.5f; - if (z < 0) z = 0; - if (z > 255) z = 255; - output[i*comp + k] = (stbi_uc) stbi__float2int(z); - } - if (k < comp) { - float z = data[i*comp+k] * 255 + 0.5f; - if (z < 0) z = 0; - if (z > 255) z = 255; - output[i*comp + k] = (stbi_uc) stbi__float2int(z); - } - } - STBI_FREE(data); - return output; -} -#endif - -////////////////////////////////////////////////////////////////////////////// -// -// "baseline" JPEG/JFIF decoder -// -// simple implementation -// - doesn't support delayed output of y-dimension -// - simple interface (only one output format: 8-bit interleaved RGB) -// - doesn't try to recover corrupt jpegs -// - doesn't allow partial loading, loading multiple at once -// - still fast on x86 (copying globals into locals doesn't help x86) -// - allocates lots of intermediate memory (full size of all components) -// - non-interleaved case requires this anyway -// - allows good upsampling (see next) -// high-quality -// - upsampled channels are bilinearly interpolated, even across blocks -// - quality integer IDCT derived from IJG's 'slow' -// performance -// - fast huffman; reasonable integer IDCT -// - some SIMD kernels for common paths on targets with SSE2/NEON -// - uses a lot of intermediate memory, could cache poorly - -#ifndef STBI_NO_JPEG - -// huffman decoding acceleration -#define FAST_BITS 9 // larger handles more cases; smaller stomps less cache - -typedef struct -{ - stbi_uc fast[1 << FAST_BITS]; - // weirdly, repacking this into AoS is a 10% speed loss, instead of a win - stbi__uint16 code[256]; - stbi_uc values[256]; - stbi_uc size[257]; - unsigned int maxcode[18]; - int delta[17]; // old 'firstsymbol' - old 'firstcode' -} stbi__huffman; - -typedef struct -{ - stbi__context *s; - stbi__huffman huff_dc[4]; - stbi__huffman huff_ac[4]; - stbi__uint16 dequant[4][64]; - stbi__int16 fast_ac[4][1 << FAST_BITS]; - -// sizes for components, interleaved MCUs - int img_h_max, img_v_max; - int img_mcu_x, img_mcu_y; - int img_mcu_w, img_mcu_h; - -// definition of jpeg image component - struct - { - int id; - int h,v; - int tq; - int hd,ha; - int dc_pred; - - int x,y,w2,h2; - stbi_uc *data; - void *raw_data, *raw_coeff; - stbi_uc *linebuf; - short *coeff; // progressive only - int coeff_w, coeff_h; // number of 8x8 coefficient blocks - } img_comp[4]; - - stbi__uint32 code_buffer; // jpeg entropy-coded buffer - int code_bits; // number of valid bits - unsigned char marker; // marker seen while filling entropy buffer - int nomore; // flag if we saw a marker so must stop - - int progressive; - int spec_start; - int spec_end; - int succ_high; - int succ_low; - int eob_run; - int jfif; - int app14_color_transform; // Adobe APP14 tag - int rgb; - - int scan_n, order[4]; - int restart_interval, todo; - -// kernels - void (*idct_block_kernel)(stbi_uc *out, int out_stride, short data[64]); - void (*YCbCr_to_RGB_kernel)(stbi_uc *out, const stbi_uc *y, const stbi_uc *pcb, const stbi_uc *pcr, int count, int step); - stbi_uc *(*resample_row_hv_2_kernel)(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs); -} stbi__jpeg; - -static int stbi__build_huffman(stbi__huffman *h, int *count) -{ - int i,j,k=0; - unsigned int code; - // build size list for each symbol (from JPEG spec) - for (i=0; i < 16; ++i) { - for (j=0; j < count[i]; ++j) { - h->size[k++] = (stbi_uc) (i+1); - if(k >= 257) return stbi__err("bad size list","Corrupt JPEG"); - } - } - h->size[k] = 0; - - // compute actual symbols (from jpeg spec) - code = 0; - k = 0; - for(j=1; j <= 16; ++j) { - // compute delta to add to code to compute symbol id - h->delta[j] = k - code; - if (h->size[k] == j) { - while (h->size[k] == j) - h->code[k++] = (stbi__uint16) (code++); - if (code-1 >= (1u << j)) return stbi__err("bad code lengths","Corrupt JPEG"); - } - // compute largest code + 1 for this size, preshifted as needed later - h->maxcode[j] = code << (16-j); - code <<= 1; - } - h->maxcode[j] = 0xffffffff; - - // build non-spec acceleration table; 255 is flag for not-accelerated - memset(h->fast, 255, 1 << FAST_BITS); - for (i=0; i < k; ++i) { - int s = h->size[i]; - if (s <= FAST_BITS) { - int c = h->code[i] << (FAST_BITS-s); - int m = 1 << (FAST_BITS-s); - for (j=0; j < m; ++j) { - h->fast[c+j] = (stbi_uc) i; - } - } - } - return 1; -} - -// build a table that decodes both magnitude and value of small ACs in -// one go. -static void stbi__build_fast_ac(stbi__int16 *fast_ac, stbi__huffman *h) -{ - int i; - for (i=0; i < (1 << FAST_BITS); ++i) { - stbi_uc fast = h->fast[i]; - fast_ac[i] = 0; - if (fast < 255) { - int rs = h->values[fast]; - int run = (rs >> 4) & 15; - int magbits = rs & 15; - int len = h->size[fast]; - - if (magbits && len + magbits <= FAST_BITS) { - // magnitude code followed by receive_extend code - int k = ((i << len) & ((1 << FAST_BITS) - 1)) >> (FAST_BITS - magbits); - int m = 1 << (magbits - 1); - if (k < m) k += (~0U << magbits) + 1; - // if the result is small enough, we can fit it in fast_ac table - if (k >= -128 && k <= 127) - fast_ac[i] = (stbi__int16) ((k * 256) + (run * 16) + (len + magbits)); - } - } - } -} - -static void stbi__grow_buffer_unsafe(stbi__jpeg *j) -{ - do { - unsigned int b = j->nomore ? 0 : stbi__get8(j->s); - if (b == 0xff) { - int c = stbi__get8(j->s); - while (c == 0xff) c = stbi__get8(j->s); // consume fill bytes - if (c != 0) { - j->marker = (unsigned char) c; - j->nomore = 1; - return; - } - } - j->code_buffer |= b << (24 - j->code_bits); - j->code_bits += 8; - } while (j->code_bits <= 24); -} - -// (1 << n) - 1 -static const stbi__uint32 stbi__bmask[17]={0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535}; - -// decode a jpeg huffman value from the bitstream -stbi_inline static int stbi__jpeg_huff_decode(stbi__jpeg *j, stbi__huffman *h) -{ - unsigned int temp; - int c,k; - - if (j->code_bits < 16) stbi__grow_buffer_unsafe(j); - - // look at the top FAST_BITS and determine what symbol ID it is, - // if the code is <= FAST_BITS - c = (j->code_buffer >> (32 - FAST_BITS)) & ((1 << FAST_BITS)-1); - k = h->fast[c]; - if (k < 255) { - int s = h->size[k]; - if (s > j->code_bits) - return -1; - j->code_buffer <<= s; - j->code_bits -= s; - return h->values[k]; - } - - // naive test is to shift the code_buffer down so k bits are - // valid, then test against maxcode. To speed this up, we've - // preshifted maxcode left so that it has (16-k) 0s at the - // end; in other words, regardless of the number of bits, it - // wants to be compared against something shifted to have 16; - // that way we don't need to shift inside the loop. - temp = j->code_buffer >> 16; - for (k=FAST_BITS+1 ; ; ++k) - if (temp < h->maxcode[k]) - break; - if (k == 17) { - // error! code not found - j->code_bits -= 16; - return -1; - } - - if (k > j->code_bits) - return -1; - - // convert the huffman code to the symbol id - c = ((j->code_buffer >> (32 - k)) & stbi__bmask[k]) + h->delta[k]; - if(c < 0 || c >= 256) // symbol id out of bounds! - return -1; - STBI_ASSERT((((j->code_buffer) >> (32 - h->size[c])) & stbi__bmask[h->size[c]]) == h->code[c]); - - // convert the id to a symbol - j->code_bits -= k; - j->code_buffer <<= k; - return h->values[c]; -} - -// bias[n] = (-1<code_bits < n) stbi__grow_buffer_unsafe(j); - if (j->code_bits < n) return 0; // ran out of bits from stream, return 0s intead of continuing - - sgn = j->code_buffer >> 31; // sign bit always in MSB; 0 if MSB clear (positive), 1 if MSB set (negative) - k = stbi_lrot(j->code_buffer, n); - j->code_buffer = k & ~stbi__bmask[n]; - k &= stbi__bmask[n]; - j->code_bits -= n; - return k + (stbi__jbias[n] & (sgn - 1)); -} - -// get some unsigned bits -stbi_inline static int stbi__jpeg_get_bits(stbi__jpeg *j, int n) -{ - unsigned int k; - if (j->code_bits < n) stbi__grow_buffer_unsafe(j); - if (j->code_bits < n) return 0; // ran out of bits from stream, return 0s intead of continuing - k = stbi_lrot(j->code_buffer, n); - j->code_buffer = k & ~stbi__bmask[n]; - k &= stbi__bmask[n]; - j->code_bits -= n; - return k; -} - -stbi_inline static int stbi__jpeg_get_bit(stbi__jpeg *j) -{ - unsigned int k; - if (j->code_bits < 1) stbi__grow_buffer_unsafe(j); - if (j->code_bits < 1) return 0; // ran out of bits from stream, return 0s intead of continuing - k = j->code_buffer; - j->code_buffer <<= 1; - --j->code_bits; - return k & 0x80000000; -} - -// given a value that's at position X in the zigzag stream, -// where does it appear in the 8x8 matrix coded as row-major? -static const stbi_uc stbi__jpeg_dezigzag[64+15] = -{ - 0, 1, 8, 16, 9, 2, 3, 10, - 17, 24, 32, 25, 18, 11, 4, 5, - 12, 19, 26, 33, 40, 48, 41, 34, - 27, 20, 13, 6, 7, 14, 21, 28, - 35, 42, 49, 56, 57, 50, 43, 36, - 29, 22, 15, 23, 30, 37, 44, 51, - 58, 59, 52, 45, 38, 31, 39, 46, - 53, 60, 61, 54, 47, 55, 62, 63, - // let corrupt input sample past end - 63, 63, 63, 63, 63, 63, 63, 63, - 63, 63, 63, 63, 63, 63, 63 -}; - -// decode one 64-entry block-- -static int stbi__jpeg_decode_block(stbi__jpeg *j, short data[64], stbi__huffman *hdc, stbi__huffman *hac, stbi__int16 *fac, int b, stbi__uint16 *dequant) -{ - int diff,dc,k; - int t; - - if (j->code_bits < 16) stbi__grow_buffer_unsafe(j); - t = stbi__jpeg_huff_decode(j, hdc); - if (t < 0 || t > 15) return stbi__err("bad huffman code","Corrupt JPEG"); - - // 0 all the ac values now so we can do it 32-bits at a time - memset(data,0,64*sizeof(data[0])); - - diff = t ? stbi__extend_receive(j, t) : 0; - if (!stbi__addints_valid(j->img_comp[b].dc_pred, diff)) return stbi__err("bad delta","Corrupt JPEG"); - dc = j->img_comp[b].dc_pred + diff; - j->img_comp[b].dc_pred = dc; - if (!stbi__mul2shorts_valid(dc, dequant[0])) return stbi__err("can't merge dc and ac", "Corrupt JPEG"); - data[0] = (short) (dc * dequant[0]); - - // decode AC components, see JPEG spec - k = 1; - do { - unsigned int zig; - int c,r,s; - if (j->code_bits < 16) stbi__grow_buffer_unsafe(j); - c = (j->code_buffer >> (32 - FAST_BITS)) & ((1 << FAST_BITS)-1); - r = fac[c]; - if (r) { // fast-AC path - k += (r >> 4) & 15; // run - s = r & 15; // combined length - if (s > j->code_bits) return stbi__err("bad huffman code", "Combined length longer than code bits available"); - j->code_buffer <<= s; - j->code_bits -= s; - // decode into unzigzag'd location - zig = stbi__jpeg_dezigzag[k++]; - data[zig] = (short) ((r >> 8) * dequant[zig]); - } else { - int rs = stbi__jpeg_huff_decode(j, hac); - if (rs < 0) return stbi__err("bad huffman code","Corrupt JPEG"); - s = rs & 15; - r = rs >> 4; - if (s == 0) { - if (rs != 0xf0) break; // end block - k += 16; - } else { - k += r; - // decode into unzigzag'd location - zig = stbi__jpeg_dezigzag[k++]; - data[zig] = (short) (stbi__extend_receive(j,s) * dequant[zig]); - } - } - } while (k < 64); - return 1; -} - -static int stbi__jpeg_decode_block_prog_dc(stbi__jpeg *j, short data[64], stbi__huffman *hdc, int b) -{ - int diff,dc; - int t; - if (j->spec_end != 0) return stbi__err("can't merge dc and ac", "Corrupt JPEG"); - - if (j->code_bits < 16) stbi__grow_buffer_unsafe(j); - - if (j->succ_high == 0) { - // first scan for DC coefficient, must be first - memset(data,0,64*sizeof(data[0])); // 0 all the ac values now - t = stbi__jpeg_huff_decode(j, hdc); - if (t < 0 || t > 15) return stbi__err("can't merge dc and ac", "Corrupt JPEG"); - diff = t ? stbi__extend_receive(j, t) : 0; - - if (!stbi__addints_valid(j->img_comp[b].dc_pred, diff)) return stbi__err("bad delta", "Corrupt JPEG"); - dc = j->img_comp[b].dc_pred + diff; - j->img_comp[b].dc_pred = dc; - if (!stbi__mul2shorts_valid(dc, 1 << j->succ_low)) return stbi__err("can't merge dc and ac", "Corrupt JPEG"); - data[0] = (short) (dc * (1 << j->succ_low)); - } else { - // refinement scan for DC coefficient - if (stbi__jpeg_get_bit(j)) - data[0] += (short) (1 << j->succ_low); - } - return 1; -} - -// @OPTIMIZE: store non-zigzagged during the decode passes, -// and only de-zigzag when dequantizing -static int stbi__jpeg_decode_block_prog_ac(stbi__jpeg *j, short data[64], stbi__huffman *hac, stbi__int16 *fac) -{ - int k; - if (j->spec_start == 0) return stbi__err("can't merge dc and ac", "Corrupt JPEG"); - - if (j->succ_high == 0) { - int shift = j->succ_low; - - if (j->eob_run) { - --j->eob_run; - return 1; - } - - k = j->spec_start; - do { - unsigned int zig; - int c,r,s; - if (j->code_bits < 16) stbi__grow_buffer_unsafe(j); - c = (j->code_buffer >> (32 - FAST_BITS)) & ((1 << FAST_BITS)-1); - r = fac[c]; - if (r) { // fast-AC path - k += (r >> 4) & 15; // run - s = r & 15; // combined length - if (s > j->code_bits) return stbi__err("bad huffman code", "Combined length longer than code bits available"); - j->code_buffer <<= s; - j->code_bits -= s; - zig = stbi__jpeg_dezigzag[k++]; - data[zig] = (short) ((r >> 8) * (1 << shift)); - } else { - int rs = stbi__jpeg_huff_decode(j, hac); - if (rs < 0) return stbi__err("bad huffman code","Corrupt JPEG"); - s = rs & 15; - r = rs >> 4; - if (s == 0) { - if (r < 15) { - j->eob_run = (1 << r); - if (r) - j->eob_run += stbi__jpeg_get_bits(j, r); - --j->eob_run; - break; - } - k += 16; - } else { - k += r; - zig = stbi__jpeg_dezigzag[k++]; - data[zig] = (short) (stbi__extend_receive(j,s) * (1 << shift)); - } - } - } while (k <= j->spec_end); - } else { - // refinement scan for these AC coefficients - - short bit = (short) (1 << j->succ_low); - - if (j->eob_run) { - --j->eob_run; - for (k = j->spec_start; k <= j->spec_end; ++k) { - short *p = &data[stbi__jpeg_dezigzag[k]]; - if (*p != 0) - if (stbi__jpeg_get_bit(j)) - if ((*p & bit)==0) { - if (*p > 0) - *p += bit; - else - *p -= bit; - } - } - } else { - k = j->spec_start; - do { - int r,s; - int rs = stbi__jpeg_huff_decode(j, hac); // @OPTIMIZE see if we can use the fast path here, advance-by-r is so slow, eh - if (rs < 0) return stbi__err("bad huffman code","Corrupt JPEG"); - s = rs & 15; - r = rs >> 4; - if (s == 0) { - if (r < 15) { - j->eob_run = (1 << r) - 1; - if (r) - j->eob_run += stbi__jpeg_get_bits(j, r); - r = 64; // force end of block - } else { - // r=15 s=0 should write 16 0s, so we just do - // a run of 15 0s and then write s (which is 0), - // so we don't have to do anything special here - } - } else { - if (s != 1) return stbi__err("bad huffman code", "Corrupt JPEG"); - // sign bit - if (stbi__jpeg_get_bit(j)) - s = bit; - else - s = -bit; - } - - // advance by r - while (k <= j->spec_end) { - short *p = &data[stbi__jpeg_dezigzag[k++]]; - if (*p != 0) { - if (stbi__jpeg_get_bit(j)) - if ((*p & bit)==0) { - if (*p > 0) - *p += bit; - else - *p -= bit; - } - } else { - if (r == 0) { - *p = (short) s; - break; - } - --r; - } - } - } while (k <= j->spec_end); - } - } - return 1; -} - -// take a -128..127 value and stbi__clamp it and convert to 0..255 -stbi_inline static stbi_uc stbi__clamp(int x) -{ - // trick to use a single test to catch both cases - if ((unsigned int) x > 255) { - if (x < 0) return 0; - if (x > 255) return 255; - } - return (stbi_uc) x; -} - -#define stbi__f2f(x) ((int) (((x) * 4096 + 0.5))) -#define stbi__fsh(x) ((x) * 4096) - -// derived from jidctint -- DCT_ISLOW -#define STBI__IDCT_1D(s0,s1,s2,s3,s4,s5,s6,s7) \ - int t0,t1,t2,t3,p1,p2,p3,p4,p5,x0,x1,x2,x3; \ - p2 = s2; \ - p3 = s6; \ - p1 = (p2+p3) * stbi__f2f(0.5411961f); \ - t2 = p1 + p3*stbi__f2f(-1.847759065f); \ - t3 = p1 + p2*stbi__f2f( 0.765366865f); \ - p2 = s0; \ - p3 = s4; \ - t0 = stbi__fsh(p2+p3); \ - t1 = stbi__fsh(p2-p3); \ - x0 = t0+t3; \ - x3 = t0-t3; \ - x1 = t1+t2; \ - x2 = t1-t2; \ - t0 = s7; \ - t1 = s5; \ - t2 = s3; \ - t3 = s1; \ - p3 = t0+t2; \ - p4 = t1+t3; \ - p1 = t0+t3; \ - p2 = t1+t2; \ - p5 = (p3+p4)*stbi__f2f( 1.175875602f); \ - t0 = t0*stbi__f2f( 0.298631336f); \ - t1 = t1*stbi__f2f( 2.053119869f); \ - t2 = t2*stbi__f2f( 3.072711026f); \ - t3 = t3*stbi__f2f( 1.501321110f); \ - p1 = p5 + p1*stbi__f2f(-0.899976223f); \ - p2 = p5 + p2*stbi__f2f(-2.562915447f); \ - p3 = p3*stbi__f2f(-1.961570560f); \ - p4 = p4*stbi__f2f(-0.390180644f); \ - t3 += p1+p4; \ - t2 += p2+p3; \ - t1 += p2+p4; \ - t0 += p1+p3; - -static void stbi__idct_block(stbi_uc *out, int out_stride, short data[64]) -{ - int i,val[64],*v=val; - stbi_uc *o; - short *d = data; - - // columns - for (i=0; i < 8; ++i,++d, ++v) { - // if all zeroes, shortcut -- this avoids dequantizing 0s and IDCTing - if (d[ 8]==0 && d[16]==0 && d[24]==0 && d[32]==0 - && d[40]==0 && d[48]==0 && d[56]==0) { - // no shortcut 0 seconds - // (1|2|3|4|5|6|7)==0 0 seconds - // all separate -0.047 seconds - // 1 && 2|3 && 4|5 && 6|7: -0.047 seconds - int dcterm = d[0]*4; - v[0] = v[8] = v[16] = v[24] = v[32] = v[40] = v[48] = v[56] = dcterm; - } else { - STBI__IDCT_1D(d[ 0],d[ 8],d[16],d[24],d[32],d[40],d[48],d[56]) - // constants scaled things up by 1<<12; let's bring them back - // down, but keep 2 extra bits of precision - x0 += 512; x1 += 512; x2 += 512; x3 += 512; - v[ 0] = (x0+t3) >> 10; - v[56] = (x0-t3) >> 10; - v[ 8] = (x1+t2) >> 10; - v[48] = (x1-t2) >> 10; - v[16] = (x2+t1) >> 10; - v[40] = (x2-t1) >> 10; - v[24] = (x3+t0) >> 10; - v[32] = (x3-t0) >> 10; - } - } - - for (i=0, v=val, o=out; i < 8; ++i,v+=8,o+=out_stride) { - // no fast case since the first 1D IDCT spread components out - STBI__IDCT_1D(v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7]) - // constants scaled things up by 1<<12, plus we had 1<<2 from first - // loop, plus horizontal and vertical each scale by sqrt(8) so together - // we've got an extra 1<<3, so 1<<17 total we need to remove. - // so we want to round that, which means adding 0.5 * 1<<17, - // aka 65536. Also, we'll end up with -128 to 127 that we want - // to encode as 0..255 by adding 128, so we'll add that before the shift - x0 += 65536 + (128<<17); - x1 += 65536 + (128<<17); - x2 += 65536 + (128<<17); - x3 += 65536 + (128<<17); - // tried computing the shifts into temps, or'ing the temps to see - // if any were out of range, but that was slower - o[0] = stbi__clamp((x0+t3) >> 17); - o[7] = stbi__clamp((x0-t3) >> 17); - o[1] = stbi__clamp((x1+t2) >> 17); - o[6] = stbi__clamp((x1-t2) >> 17); - o[2] = stbi__clamp((x2+t1) >> 17); - o[5] = stbi__clamp((x2-t1) >> 17); - o[3] = stbi__clamp((x3+t0) >> 17); - o[4] = stbi__clamp((x3-t0) >> 17); - } -} - -#ifdef STBI_SSE2 -// sse2 integer IDCT. not the fastest possible implementation but it -// produces bit-identical results to the generic C version so it's -// fully "transparent". -static void stbi__idct_simd(stbi_uc *out, int out_stride, short data[64]) -{ - // This is constructed to match our regular (generic) integer IDCT exactly. - __m128i row0, row1, row2, row3, row4, row5, row6, row7; - __m128i tmp; - - // dot product constant: even elems=x, odd elems=y - #define dct_const(x,y) _mm_setr_epi16((x),(y),(x),(y),(x),(y),(x),(y)) - - // out(0) = c0[even]*x + c0[odd]*y (c0, x, y 16-bit, out 32-bit) - // out(1) = c1[even]*x + c1[odd]*y - #define dct_rot(out0,out1, x,y,c0,c1) \ - __m128i c0##lo = _mm_unpacklo_epi16((x),(y)); \ - __m128i c0##hi = _mm_unpackhi_epi16((x),(y)); \ - __m128i out0##_l = _mm_madd_epi16(c0##lo, c0); \ - __m128i out0##_h = _mm_madd_epi16(c0##hi, c0); \ - __m128i out1##_l = _mm_madd_epi16(c0##lo, c1); \ - __m128i out1##_h = _mm_madd_epi16(c0##hi, c1) - - // out = in << 12 (in 16-bit, out 32-bit) - #define dct_widen(out, in) \ - __m128i out##_l = _mm_srai_epi32(_mm_unpacklo_epi16(_mm_setzero_si128(), (in)), 4); \ - __m128i out##_h = _mm_srai_epi32(_mm_unpackhi_epi16(_mm_setzero_si128(), (in)), 4) - - // wide add - #define dct_wadd(out, a, b) \ - __m128i out##_l = _mm_add_epi32(a##_l, b##_l); \ - __m128i out##_h = _mm_add_epi32(a##_h, b##_h) - - // wide sub - #define dct_wsub(out, a, b) \ - __m128i out##_l = _mm_sub_epi32(a##_l, b##_l); \ - __m128i out##_h = _mm_sub_epi32(a##_h, b##_h) - - // butterfly a/b, add bias, then shift by "s" and pack - #define dct_bfly32o(out0, out1, a,b,bias,s) \ - { \ - __m128i abiased_l = _mm_add_epi32(a##_l, bias); \ - __m128i abiased_h = _mm_add_epi32(a##_h, bias); \ - dct_wadd(sum, abiased, b); \ - dct_wsub(dif, abiased, b); \ - out0 = _mm_packs_epi32(_mm_srai_epi32(sum_l, s), _mm_srai_epi32(sum_h, s)); \ - out1 = _mm_packs_epi32(_mm_srai_epi32(dif_l, s), _mm_srai_epi32(dif_h, s)); \ - } - - // 8-bit interleave step (for transposes) - #define dct_interleave8(a, b) \ - tmp = a; \ - a = _mm_unpacklo_epi8(a, b); \ - b = _mm_unpackhi_epi8(tmp, b) - - // 16-bit interleave step (for transposes) - #define dct_interleave16(a, b) \ - tmp = a; \ - a = _mm_unpacklo_epi16(a, b); \ - b = _mm_unpackhi_epi16(tmp, b) - - #define dct_pass(bias,shift) \ - { \ - /* even part */ \ - dct_rot(t2e,t3e, row2,row6, rot0_0,rot0_1); \ - __m128i sum04 = _mm_add_epi16(row0, row4); \ - __m128i dif04 = _mm_sub_epi16(row0, row4); \ - dct_widen(t0e, sum04); \ - dct_widen(t1e, dif04); \ - dct_wadd(x0, t0e, t3e); \ - dct_wsub(x3, t0e, t3e); \ - dct_wadd(x1, t1e, t2e); \ - dct_wsub(x2, t1e, t2e); \ - /* odd part */ \ - dct_rot(y0o,y2o, row7,row3, rot2_0,rot2_1); \ - dct_rot(y1o,y3o, row5,row1, rot3_0,rot3_1); \ - __m128i sum17 = _mm_add_epi16(row1, row7); \ - __m128i sum35 = _mm_add_epi16(row3, row5); \ - dct_rot(y4o,y5o, sum17,sum35, rot1_0,rot1_1); \ - dct_wadd(x4, y0o, y4o); \ - dct_wadd(x5, y1o, y5o); \ - dct_wadd(x6, y2o, y5o); \ - dct_wadd(x7, y3o, y4o); \ - dct_bfly32o(row0,row7, x0,x7,bias,shift); \ - dct_bfly32o(row1,row6, x1,x6,bias,shift); \ - dct_bfly32o(row2,row5, x2,x5,bias,shift); \ - dct_bfly32o(row3,row4, x3,x4,bias,shift); \ - } - - __m128i rot0_0 = dct_const(stbi__f2f(0.5411961f), stbi__f2f(0.5411961f) + stbi__f2f(-1.847759065f)); - __m128i rot0_1 = dct_const(stbi__f2f(0.5411961f) + stbi__f2f( 0.765366865f), stbi__f2f(0.5411961f)); - __m128i rot1_0 = dct_const(stbi__f2f(1.175875602f) + stbi__f2f(-0.899976223f), stbi__f2f(1.175875602f)); - __m128i rot1_1 = dct_const(stbi__f2f(1.175875602f), stbi__f2f(1.175875602f) + stbi__f2f(-2.562915447f)); - __m128i rot2_0 = dct_const(stbi__f2f(-1.961570560f) + stbi__f2f( 0.298631336f), stbi__f2f(-1.961570560f)); - __m128i rot2_1 = dct_const(stbi__f2f(-1.961570560f), stbi__f2f(-1.961570560f) + stbi__f2f( 3.072711026f)); - __m128i rot3_0 = dct_const(stbi__f2f(-0.390180644f) + stbi__f2f( 2.053119869f), stbi__f2f(-0.390180644f)); - __m128i rot3_1 = dct_const(stbi__f2f(-0.390180644f), stbi__f2f(-0.390180644f) + stbi__f2f( 1.501321110f)); - - // rounding biases in column/row passes, see stbi__idct_block for explanation. - __m128i bias_0 = _mm_set1_epi32(512); - __m128i bias_1 = _mm_set1_epi32(65536 + (128<<17)); - - // load - row0 = _mm_load_si128((const __m128i *) (data + 0*8)); - row1 = _mm_load_si128((const __m128i *) (data + 1*8)); - row2 = _mm_load_si128((const __m128i *) (data + 2*8)); - row3 = _mm_load_si128((const __m128i *) (data + 3*8)); - row4 = _mm_load_si128((const __m128i *) (data + 4*8)); - row5 = _mm_load_si128((const __m128i *) (data + 5*8)); - row6 = _mm_load_si128((const __m128i *) (data + 6*8)); - row7 = _mm_load_si128((const __m128i *) (data + 7*8)); - - // column pass - dct_pass(bias_0, 10); - - { - // 16bit 8x8 transpose pass 1 - dct_interleave16(row0, row4); - dct_interleave16(row1, row5); - dct_interleave16(row2, row6); - dct_interleave16(row3, row7); - - // transpose pass 2 - dct_interleave16(row0, row2); - dct_interleave16(row1, row3); - dct_interleave16(row4, row6); - dct_interleave16(row5, row7); - - // transpose pass 3 - dct_interleave16(row0, row1); - dct_interleave16(row2, row3); - dct_interleave16(row4, row5); - dct_interleave16(row6, row7); - } - - // row pass - dct_pass(bias_1, 17); - - { - // pack - __m128i p0 = _mm_packus_epi16(row0, row1); // a0a1a2a3...a7b0b1b2b3...b7 - __m128i p1 = _mm_packus_epi16(row2, row3); - __m128i p2 = _mm_packus_epi16(row4, row5); - __m128i p3 = _mm_packus_epi16(row6, row7); - - // 8bit 8x8 transpose pass 1 - dct_interleave8(p0, p2); // a0e0a1e1... - dct_interleave8(p1, p3); // c0g0c1g1... - - // transpose pass 2 - dct_interleave8(p0, p1); // a0c0e0g0... - dct_interleave8(p2, p3); // b0d0f0h0... - - // transpose pass 3 - dct_interleave8(p0, p2); // a0b0c0d0... - dct_interleave8(p1, p3); // a4b4c4d4... - - // store - _mm_storel_epi64((__m128i *) out, p0); out += out_stride; - _mm_storel_epi64((__m128i *) out, _mm_shuffle_epi32(p0, 0x4e)); out += out_stride; - _mm_storel_epi64((__m128i *) out, p2); out += out_stride; - _mm_storel_epi64((__m128i *) out, _mm_shuffle_epi32(p2, 0x4e)); out += out_stride; - _mm_storel_epi64((__m128i *) out, p1); out += out_stride; - _mm_storel_epi64((__m128i *) out, _mm_shuffle_epi32(p1, 0x4e)); out += out_stride; - _mm_storel_epi64((__m128i *) out, p3); out += out_stride; - _mm_storel_epi64((__m128i *) out, _mm_shuffle_epi32(p3, 0x4e)); - } - -#undef dct_const -#undef dct_rot -#undef dct_widen -#undef dct_wadd -#undef dct_wsub -#undef dct_bfly32o -#undef dct_interleave8 -#undef dct_interleave16 -#undef dct_pass -} - -#endif // STBI_SSE2 - -#ifdef STBI_NEON - -// NEON integer IDCT. should produce bit-identical -// results to the generic C version. -static void stbi__idct_simd(stbi_uc *out, int out_stride, short data[64]) -{ - int16x8_t row0, row1, row2, row3, row4, row5, row6, row7; - - int16x4_t rot0_0 = vdup_n_s16(stbi__f2f(0.5411961f)); - int16x4_t rot0_1 = vdup_n_s16(stbi__f2f(-1.847759065f)); - int16x4_t rot0_2 = vdup_n_s16(stbi__f2f( 0.765366865f)); - int16x4_t rot1_0 = vdup_n_s16(stbi__f2f( 1.175875602f)); - int16x4_t rot1_1 = vdup_n_s16(stbi__f2f(-0.899976223f)); - int16x4_t rot1_2 = vdup_n_s16(stbi__f2f(-2.562915447f)); - int16x4_t rot2_0 = vdup_n_s16(stbi__f2f(-1.961570560f)); - int16x4_t rot2_1 = vdup_n_s16(stbi__f2f(-0.390180644f)); - int16x4_t rot3_0 = vdup_n_s16(stbi__f2f( 0.298631336f)); - int16x4_t rot3_1 = vdup_n_s16(stbi__f2f( 2.053119869f)); - int16x4_t rot3_2 = vdup_n_s16(stbi__f2f( 3.072711026f)); - int16x4_t rot3_3 = vdup_n_s16(stbi__f2f( 1.501321110f)); - -#define dct_long_mul(out, inq, coeff) \ - int32x4_t out##_l = vmull_s16(vget_low_s16(inq), coeff); \ - int32x4_t out##_h = vmull_s16(vget_high_s16(inq), coeff) - -#define dct_long_mac(out, acc, inq, coeff) \ - int32x4_t out##_l = vmlal_s16(acc##_l, vget_low_s16(inq), coeff); \ - int32x4_t out##_h = vmlal_s16(acc##_h, vget_high_s16(inq), coeff) - -#define dct_widen(out, inq) \ - int32x4_t out##_l = vshll_n_s16(vget_low_s16(inq), 12); \ - int32x4_t out##_h = vshll_n_s16(vget_high_s16(inq), 12) - -// wide add -#define dct_wadd(out, a, b) \ - int32x4_t out##_l = vaddq_s32(a##_l, b##_l); \ - int32x4_t out##_h = vaddq_s32(a##_h, b##_h) - -// wide sub -#define dct_wsub(out, a, b) \ - int32x4_t out##_l = vsubq_s32(a##_l, b##_l); \ - int32x4_t out##_h = vsubq_s32(a##_h, b##_h) - -// butterfly a/b, then shift using "shiftop" by "s" and pack -#define dct_bfly32o(out0,out1, a,b,shiftop,s) \ - { \ - dct_wadd(sum, a, b); \ - dct_wsub(dif, a, b); \ - out0 = vcombine_s16(shiftop(sum_l, s), shiftop(sum_h, s)); \ - out1 = vcombine_s16(shiftop(dif_l, s), shiftop(dif_h, s)); \ - } - -#define dct_pass(shiftop, shift) \ - { \ - /* even part */ \ - int16x8_t sum26 = vaddq_s16(row2, row6); \ - dct_long_mul(p1e, sum26, rot0_0); \ - dct_long_mac(t2e, p1e, row6, rot0_1); \ - dct_long_mac(t3e, p1e, row2, rot0_2); \ - int16x8_t sum04 = vaddq_s16(row0, row4); \ - int16x8_t dif04 = vsubq_s16(row0, row4); \ - dct_widen(t0e, sum04); \ - dct_widen(t1e, dif04); \ - dct_wadd(x0, t0e, t3e); \ - dct_wsub(x3, t0e, t3e); \ - dct_wadd(x1, t1e, t2e); \ - dct_wsub(x2, t1e, t2e); \ - /* odd part */ \ - int16x8_t sum15 = vaddq_s16(row1, row5); \ - int16x8_t sum17 = vaddq_s16(row1, row7); \ - int16x8_t sum35 = vaddq_s16(row3, row5); \ - int16x8_t sum37 = vaddq_s16(row3, row7); \ - int16x8_t sumodd = vaddq_s16(sum17, sum35); \ - dct_long_mul(p5o, sumodd, rot1_0); \ - dct_long_mac(p1o, p5o, sum17, rot1_1); \ - dct_long_mac(p2o, p5o, sum35, rot1_2); \ - dct_long_mul(p3o, sum37, rot2_0); \ - dct_long_mul(p4o, sum15, rot2_1); \ - dct_wadd(sump13o, p1o, p3o); \ - dct_wadd(sump24o, p2o, p4o); \ - dct_wadd(sump23o, p2o, p3o); \ - dct_wadd(sump14o, p1o, p4o); \ - dct_long_mac(x4, sump13o, row7, rot3_0); \ - dct_long_mac(x5, sump24o, row5, rot3_1); \ - dct_long_mac(x6, sump23o, row3, rot3_2); \ - dct_long_mac(x7, sump14o, row1, rot3_3); \ - dct_bfly32o(row0,row7, x0,x7,shiftop,shift); \ - dct_bfly32o(row1,row6, x1,x6,shiftop,shift); \ - dct_bfly32o(row2,row5, x2,x5,shiftop,shift); \ - dct_bfly32o(row3,row4, x3,x4,shiftop,shift); \ - } - - // load - row0 = vld1q_s16(data + 0*8); - row1 = vld1q_s16(data + 1*8); - row2 = vld1q_s16(data + 2*8); - row3 = vld1q_s16(data + 3*8); - row4 = vld1q_s16(data + 4*8); - row5 = vld1q_s16(data + 5*8); - row6 = vld1q_s16(data + 6*8); - row7 = vld1q_s16(data + 7*8); - - // add DC bias - row0 = vaddq_s16(row0, vsetq_lane_s16(1024, vdupq_n_s16(0), 0)); - - // column pass - dct_pass(vrshrn_n_s32, 10); - - // 16bit 8x8 transpose - { -// these three map to a single VTRN.16, VTRN.32, and VSWP, respectively. -// whether compilers actually get this is another story, sadly. -#define dct_trn16(x, y) { int16x8x2_t t = vtrnq_s16(x, y); x = t.val[0]; y = t.val[1]; } -#define dct_trn32(x, y) { int32x4x2_t t = vtrnq_s32(vreinterpretq_s32_s16(x), vreinterpretq_s32_s16(y)); x = vreinterpretq_s16_s32(t.val[0]); y = vreinterpretq_s16_s32(t.val[1]); } -#define dct_trn64(x, y) { int16x8_t x0 = x; int16x8_t y0 = y; x = vcombine_s16(vget_low_s16(x0), vget_low_s16(y0)); y = vcombine_s16(vget_high_s16(x0), vget_high_s16(y0)); } - - // pass 1 - dct_trn16(row0, row1); // a0b0a2b2a4b4a6b6 - dct_trn16(row2, row3); - dct_trn16(row4, row5); - dct_trn16(row6, row7); - - // pass 2 - dct_trn32(row0, row2); // a0b0c0d0a4b4c4d4 - dct_trn32(row1, row3); - dct_trn32(row4, row6); - dct_trn32(row5, row7); - - // pass 3 - dct_trn64(row0, row4); // a0b0c0d0e0f0g0h0 - dct_trn64(row1, row5); - dct_trn64(row2, row6); - dct_trn64(row3, row7); - -#undef dct_trn16 -#undef dct_trn32 -#undef dct_trn64 - } - - // row pass - // vrshrn_n_s32 only supports shifts up to 16, we need - // 17. so do a non-rounding shift of 16 first then follow - // up with a rounding shift by 1. - dct_pass(vshrn_n_s32, 16); - - { - // pack and round - uint8x8_t p0 = vqrshrun_n_s16(row0, 1); - uint8x8_t p1 = vqrshrun_n_s16(row1, 1); - uint8x8_t p2 = vqrshrun_n_s16(row2, 1); - uint8x8_t p3 = vqrshrun_n_s16(row3, 1); - uint8x8_t p4 = vqrshrun_n_s16(row4, 1); - uint8x8_t p5 = vqrshrun_n_s16(row5, 1); - uint8x8_t p6 = vqrshrun_n_s16(row6, 1); - uint8x8_t p7 = vqrshrun_n_s16(row7, 1); - - // again, these can translate into one instruction, but often don't. -#define dct_trn8_8(x, y) { uint8x8x2_t t = vtrn_u8(x, y); x = t.val[0]; y = t.val[1]; } -#define dct_trn8_16(x, y) { uint16x4x2_t t = vtrn_u16(vreinterpret_u16_u8(x), vreinterpret_u16_u8(y)); x = vreinterpret_u8_u16(t.val[0]); y = vreinterpret_u8_u16(t.val[1]); } -#define dct_trn8_32(x, y) { uint32x2x2_t t = vtrn_u32(vreinterpret_u32_u8(x), vreinterpret_u32_u8(y)); x = vreinterpret_u8_u32(t.val[0]); y = vreinterpret_u8_u32(t.val[1]); } - - // sadly can't use interleaved stores here since we only write - // 8 bytes to each scan line! - - // 8x8 8-bit transpose pass 1 - dct_trn8_8(p0, p1); - dct_trn8_8(p2, p3); - dct_trn8_8(p4, p5); - dct_trn8_8(p6, p7); - - // pass 2 - dct_trn8_16(p0, p2); - dct_trn8_16(p1, p3); - dct_trn8_16(p4, p6); - dct_trn8_16(p5, p7); - - // pass 3 - dct_trn8_32(p0, p4); - dct_trn8_32(p1, p5); - dct_trn8_32(p2, p6); - dct_trn8_32(p3, p7); - - // store - vst1_u8(out, p0); out += out_stride; - vst1_u8(out, p1); out += out_stride; - vst1_u8(out, p2); out += out_stride; - vst1_u8(out, p3); out += out_stride; - vst1_u8(out, p4); out += out_stride; - vst1_u8(out, p5); out += out_stride; - vst1_u8(out, p6); out += out_stride; - vst1_u8(out, p7); - -#undef dct_trn8_8 -#undef dct_trn8_16 -#undef dct_trn8_32 - } - -#undef dct_long_mul -#undef dct_long_mac -#undef dct_widen -#undef dct_wadd -#undef dct_wsub -#undef dct_bfly32o -#undef dct_pass -} - -#endif // STBI_NEON - -#define STBI__MARKER_none 0xff -// if there's a pending marker from the entropy stream, return that -// otherwise, fetch from the stream and get a marker. if there's no -// marker, return 0xff, which is never a valid marker value -static stbi_uc stbi__get_marker(stbi__jpeg *j) -{ - stbi_uc x; - if (j->marker != STBI__MARKER_none) { x = j->marker; j->marker = STBI__MARKER_none; return x; } - x = stbi__get8(j->s); - if (x != 0xff) return STBI__MARKER_none; - while (x == 0xff) - x = stbi__get8(j->s); // consume repeated 0xff fill bytes - return x; -} - -// in each scan, we'll have scan_n components, and the order -// of the components is specified by order[] -#define STBI__RESTART(x) ((x) >= 0xd0 && (x) <= 0xd7) - -// after a restart interval, stbi__jpeg_reset the entropy decoder and -// the dc prediction -static void stbi__jpeg_reset(stbi__jpeg *j) -{ - j->code_bits = 0; - j->code_buffer = 0; - j->nomore = 0; - j->img_comp[0].dc_pred = j->img_comp[1].dc_pred = j->img_comp[2].dc_pred = j->img_comp[3].dc_pred = 0; - j->marker = STBI__MARKER_none; - j->todo = j->restart_interval ? j->restart_interval : 0x7fffffff; - j->eob_run = 0; - // no more than 1<<31 MCUs if no restart_interal? that's plenty safe, - // since we don't even allow 1<<30 pixels -} - -static int stbi__parse_entropy_coded_data(stbi__jpeg *z) -{ - stbi__jpeg_reset(z); - if (!z->progressive) { - if (z->scan_n == 1) { - int i,j; - STBI_SIMD_ALIGN(short, data[64]); - int n = z->order[0]; - // non-interleaved data, we just need to process one block at a time, - // in trivial scanline order - // number of blocks to do just depends on how many actual "pixels" this - // component has, independent of interleaved MCU blocking and such - int w = (z->img_comp[n].x+7) >> 3; - int h = (z->img_comp[n].y+7) >> 3; - for (j=0; j < h; ++j) { - for (i=0; i < w; ++i) { - int ha = z->img_comp[n].ha; - if (!stbi__jpeg_decode_block(z, data, z->huff_dc+z->img_comp[n].hd, z->huff_ac+ha, z->fast_ac[ha], n, z->dequant[z->img_comp[n].tq])) return 0; - z->idct_block_kernel(z->img_comp[n].data+z->img_comp[n].w2*j*8+i*8, z->img_comp[n].w2, data); - // every data block is an MCU, so countdown the restart interval - if (--z->todo <= 0) { - if (z->code_bits < 24) stbi__grow_buffer_unsafe(z); - // if it's NOT a restart, then just bail, so we get corrupt data - // rather than no data - if (!STBI__RESTART(z->marker)) return 1; - stbi__jpeg_reset(z); - } - } - } - return 1; - } else { // interleaved - int i,j,k,x,y; - STBI_SIMD_ALIGN(short, data[64]); - for (j=0; j < z->img_mcu_y; ++j) { - for (i=0; i < z->img_mcu_x; ++i) { - // scan an interleaved mcu... process scan_n components in order - for (k=0; k < z->scan_n; ++k) { - int n = z->order[k]; - // scan out an mcu's worth of this component; that's just determined - // by the basic H and V specified for the component - for (y=0; y < z->img_comp[n].v; ++y) { - for (x=0; x < z->img_comp[n].h; ++x) { - int x2 = (i*z->img_comp[n].h + x)*8; - int y2 = (j*z->img_comp[n].v + y)*8; - int ha = z->img_comp[n].ha; - if (!stbi__jpeg_decode_block(z, data, z->huff_dc+z->img_comp[n].hd, z->huff_ac+ha, z->fast_ac[ha], n, z->dequant[z->img_comp[n].tq])) return 0; - z->idct_block_kernel(z->img_comp[n].data+z->img_comp[n].w2*y2+x2, z->img_comp[n].w2, data); - } - } - } - // after all interleaved components, that's an interleaved MCU, - // so now count down the restart interval - if (--z->todo <= 0) { - if (z->code_bits < 24) stbi__grow_buffer_unsafe(z); - if (!STBI__RESTART(z->marker)) return 1; - stbi__jpeg_reset(z); - } - } - } - return 1; - } - } else { - if (z->scan_n == 1) { - int i,j; - int n = z->order[0]; - // non-interleaved data, we just need to process one block at a time, - // in trivial scanline order - // number of blocks to do just depends on how many actual "pixels" this - // component has, independent of interleaved MCU blocking and such - int w = (z->img_comp[n].x+7) >> 3; - int h = (z->img_comp[n].y+7) >> 3; - for (j=0; j < h; ++j) { - for (i=0; i < w; ++i) { - short *data = z->img_comp[n].coeff + 64 * (i + j * z->img_comp[n].coeff_w); - if (z->spec_start == 0) { - if (!stbi__jpeg_decode_block_prog_dc(z, data, &z->huff_dc[z->img_comp[n].hd], n)) - return 0; - } else { - int ha = z->img_comp[n].ha; - if (!stbi__jpeg_decode_block_prog_ac(z, data, &z->huff_ac[ha], z->fast_ac[ha])) - return 0; - } - // every data block is an MCU, so countdown the restart interval - if (--z->todo <= 0) { - if (z->code_bits < 24) stbi__grow_buffer_unsafe(z); - if (!STBI__RESTART(z->marker)) return 1; - stbi__jpeg_reset(z); - } - } - } - return 1; - } else { // interleaved - int i,j,k,x,y; - for (j=0; j < z->img_mcu_y; ++j) { - for (i=0; i < z->img_mcu_x; ++i) { - // scan an interleaved mcu... process scan_n components in order - for (k=0; k < z->scan_n; ++k) { - int n = z->order[k]; - // scan out an mcu's worth of this component; that's just determined - // by the basic H and V specified for the component - for (y=0; y < z->img_comp[n].v; ++y) { - for (x=0; x < z->img_comp[n].h; ++x) { - int x2 = (i*z->img_comp[n].h + x); - int y2 = (j*z->img_comp[n].v + y); - short *data = z->img_comp[n].coeff + 64 * (x2 + y2 * z->img_comp[n].coeff_w); - if (!stbi__jpeg_decode_block_prog_dc(z, data, &z->huff_dc[z->img_comp[n].hd], n)) - return 0; - } - } - } - // after all interleaved components, that's an interleaved MCU, - // so now count down the restart interval - if (--z->todo <= 0) { - if (z->code_bits < 24) stbi__grow_buffer_unsafe(z); - if (!STBI__RESTART(z->marker)) return 1; - stbi__jpeg_reset(z); - } - } - } - return 1; - } - } -} - -static void stbi__jpeg_dequantize(short *data, stbi__uint16 *dequant) -{ - int i; - for (i=0; i < 64; ++i) - data[i] *= dequant[i]; -} - -static void stbi__jpeg_finish(stbi__jpeg *z) -{ - if (z->progressive) { - // dequantize and idct the data - int i,j,n; - for (n=0; n < z->s->img_n; ++n) { - int w = (z->img_comp[n].x+7) >> 3; - int h = (z->img_comp[n].y+7) >> 3; - for (j=0; j < h; ++j) { - for (i=0; i < w; ++i) { - short *data = z->img_comp[n].coeff + 64 * (i + j * z->img_comp[n].coeff_w); - stbi__jpeg_dequantize(data, z->dequant[z->img_comp[n].tq]); - z->idct_block_kernel(z->img_comp[n].data+z->img_comp[n].w2*j*8+i*8, z->img_comp[n].w2, data); - } - } - } - } -} - -static int stbi__process_marker(stbi__jpeg *z, int m) -{ - int L; - switch (m) { - case STBI__MARKER_none: // no marker found - return stbi__err("expected marker","Corrupt JPEG"); - - case 0xDD: // DRI - specify restart interval - if (stbi__get16be(z->s) != 4) return stbi__err("bad DRI len","Corrupt JPEG"); - z->restart_interval = stbi__get16be(z->s); - return 1; - - case 0xDB: // DQT - define quantization table - L = stbi__get16be(z->s)-2; - while (L > 0) { - int q = stbi__get8(z->s); - int p = q >> 4, sixteen = (p != 0); - int t = q & 15,i; - if (p != 0 && p != 1) return stbi__err("bad DQT type","Corrupt JPEG"); - if (t > 3) return stbi__err("bad DQT table","Corrupt JPEG"); - - for (i=0; i < 64; ++i) - z->dequant[t][stbi__jpeg_dezigzag[i]] = (stbi__uint16)(sixteen ? stbi__get16be(z->s) : stbi__get8(z->s)); - L -= (sixteen ? 129 : 65); - } - return L==0; - - case 0xC4: // DHT - define huffman table - L = stbi__get16be(z->s)-2; - while (L > 0) { - stbi_uc *v; - int sizes[16],i,n=0; - int q = stbi__get8(z->s); - int tc = q >> 4; - int th = q & 15; - if (tc > 1 || th > 3) return stbi__err("bad DHT header","Corrupt JPEG"); - for (i=0; i < 16; ++i) { - sizes[i] = stbi__get8(z->s); - n += sizes[i]; - } - if(n > 256) return stbi__err("bad DHT header","Corrupt JPEG"); // Loop over i < n would write past end of values! - L -= 17; - if (tc == 0) { - if (!stbi__build_huffman(z->huff_dc+th, sizes)) return 0; - v = z->huff_dc[th].values; - } else { - if (!stbi__build_huffman(z->huff_ac+th, sizes)) return 0; - v = z->huff_ac[th].values; - } - for (i=0; i < n; ++i) - v[i] = stbi__get8(z->s); - if (tc != 0) - stbi__build_fast_ac(z->fast_ac[th], z->huff_ac + th); - L -= n; - } - return L==0; - } - - // check for comment block or APP blocks - if ((m >= 0xE0 && m <= 0xEF) || m == 0xFE) { - L = stbi__get16be(z->s); - if (L < 2) { - if (m == 0xFE) - return stbi__err("bad COM len","Corrupt JPEG"); - else - return stbi__err("bad APP len","Corrupt JPEG"); - } - L -= 2; - - if (m == 0xE0 && L >= 5) { // JFIF APP0 segment - static const unsigned char tag[5] = {'J','F','I','F','\0'}; - int ok = 1; - int i; - for (i=0; i < 5; ++i) - if (stbi__get8(z->s) != tag[i]) - ok = 0; - L -= 5; - if (ok) - z->jfif = 1; - } else if (m == 0xEE && L >= 12) { // Adobe APP14 segment - static const unsigned char tag[6] = {'A','d','o','b','e','\0'}; - int ok = 1; - int i; - for (i=0; i < 6; ++i) - if (stbi__get8(z->s) != tag[i]) - ok = 0; - L -= 6; - if (ok) { - stbi__get8(z->s); // version - stbi__get16be(z->s); // flags0 - stbi__get16be(z->s); // flags1 - z->app14_color_transform = stbi__get8(z->s); // color transform - L -= 6; - } - } - - stbi__skip(z->s, L); - return 1; - } - - return stbi__err("unknown marker","Corrupt JPEG"); -} - -// after we see SOS -static int stbi__process_scan_header(stbi__jpeg *z) -{ - int i; - int Ls = stbi__get16be(z->s); - z->scan_n = stbi__get8(z->s); - if (z->scan_n < 1 || z->scan_n > 4 || z->scan_n > (int) z->s->img_n) return stbi__err("bad SOS component count","Corrupt JPEG"); - if (Ls != 6+2*z->scan_n) return stbi__err("bad SOS len","Corrupt JPEG"); - for (i=0; i < z->scan_n; ++i) { - int id = stbi__get8(z->s), which; - int q = stbi__get8(z->s); - for (which = 0; which < z->s->img_n; ++which) - if (z->img_comp[which].id == id) - break; - if (which == z->s->img_n) return 0; // no match - z->img_comp[which].hd = q >> 4; if (z->img_comp[which].hd > 3) return stbi__err("bad DC huff","Corrupt JPEG"); - z->img_comp[which].ha = q & 15; if (z->img_comp[which].ha > 3) return stbi__err("bad AC huff","Corrupt JPEG"); - z->order[i] = which; - } - - { - int aa; - z->spec_start = stbi__get8(z->s); - z->spec_end = stbi__get8(z->s); // should be 63, but might be 0 - aa = stbi__get8(z->s); - z->succ_high = (aa >> 4); - z->succ_low = (aa & 15); - if (z->progressive) { - if (z->spec_start > 63 || z->spec_end > 63 || z->spec_start > z->spec_end || z->succ_high > 13 || z->succ_low > 13) - return stbi__err("bad SOS", "Corrupt JPEG"); - } else { - if (z->spec_start != 0) return stbi__err("bad SOS","Corrupt JPEG"); - if (z->succ_high != 0 || z->succ_low != 0) return stbi__err("bad SOS","Corrupt JPEG"); - z->spec_end = 63; - } - } - - return 1; -} - -static int stbi__free_jpeg_components(stbi__jpeg *z, int ncomp, int why) -{ - int i; - for (i=0; i < ncomp; ++i) { - if (z->img_comp[i].raw_data) { - STBI_FREE(z->img_comp[i].raw_data); - z->img_comp[i].raw_data = NULL; - z->img_comp[i].data = NULL; - } - if (z->img_comp[i].raw_coeff) { - STBI_FREE(z->img_comp[i].raw_coeff); - z->img_comp[i].raw_coeff = 0; - z->img_comp[i].coeff = 0; - } - if (z->img_comp[i].linebuf) { - STBI_FREE(z->img_comp[i].linebuf); - z->img_comp[i].linebuf = NULL; - } - } - return why; -} - -static int stbi__process_frame_header(stbi__jpeg *z, int scan) -{ - stbi__context *s = z->s; - int Lf,p,i,q, h_max=1,v_max=1,c; - Lf = stbi__get16be(s); if (Lf < 11) return stbi__err("bad SOF len","Corrupt JPEG"); // JPEG - p = stbi__get8(s); if (p != 8) return stbi__err("only 8-bit","JPEG format not supported: 8-bit only"); // JPEG baseline - s->img_y = stbi__get16be(s); if (s->img_y == 0) return stbi__err("no header height", "JPEG format not supported: delayed height"); // Legal, but we don't handle it--but neither does IJG - s->img_x = stbi__get16be(s); if (s->img_x == 0) return stbi__err("0 width","Corrupt JPEG"); // JPEG requires - if (s->img_y > STBI_MAX_DIMENSIONS) return stbi__err("too large","Very large image (corrupt?)"); - if (s->img_x > STBI_MAX_DIMENSIONS) return stbi__err("too large","Very large image (corrupt?)"); - c = stbi__get8(s); - if (c != 3 && c != 1 && c != 4) return stbi__err("bad component count","Corrupt JPEG"); - s->img_n = c; - for (i=0; i < c; ++i) { - z->img_comp[i].data = NULL; - z->img_comp[i].linebuf = NULL; - } - - if (Lf != 8+3*s->img_n) return stbi__err("bad SOF len","Corrupt JPEG"); - - z->rgb = 0; - for (i=0; i < s->img_n; ++i) { - static const unsigned char rgb[3] = { 'R', 'G', 'B' }; - z->img_comp[i].id = stbi__get8(s); - if (s->img_n == 3 && z->img_comp[i].id == rgb[i]) - ++z->rgb; - q = stbi__get8(s); - z->img_comp[i].h = (q >> 4); if (!z->img_comp[i].h || z->img_comp[i].h > 4) return stbi__err("bad H","Corrupt JPEG"); - z->img_comp[i].v = q & 15; if (!z->img_comp[i].v || z->img_comp[i].v > 4) return stbi__err("bad V","Corrupt JPEG"); - z->img_comp[i].tq = stbi__get8(s); if (z->img_comp[i].tq > 3) return stbi__err("bad TQ","Corrupt JPEG"); - } - - if (scan != STBI__SCAN_load) return 1; - - if (!stbi__mad3sizes_valid(s->img_x, s->img_y, s->img_n, 0)) return stbi__err("too large", "Image too large to decode"); - - for (i=0; i < s->img_n; ++i) { - if (z->img_comp[i].h > h_max) h_max = z->img_comp[i].h; - if (z->img_comp[i].v > v_max) v_max = z->img_comp[i].v; - } - - // check that plane subsampling factors are integer ratios; our resamplers can't deal with fractional ratios - // and I've never seen a non-corrupted JPEG file actually use them - for (i=0; i < s->img_n; ++i) { - if (h_max % z->img_comp[i].h != 0) return stbi__err("bad H","Corrupt JPEG"); - if (v_max % z->img_comp[i].v != 0) return stbi__err("bad V","Corrupt JPEG"); - } - - // compute interleaved mcu info - z->img_h_max = h_max; - z->img_v_max = v_max; - z->img_mcu_w = h_max * 8; - z->img_mcu_h = v_max * 8; - // these sizes can't be more than 17 bits - z->img_mcu_x = (s->img_x + z->img_mcu_w-1) / z->img_mcu_w; - z->img_mcu_y = (s->img_y + z->img_mcu_h-1) / z->img_mcu_h; - - for (i=0; i < s->img_n; ++i) { - // number of effective pixels (e.g. for non-interleaved MCU) - z->img_comp[i].x = (s->img_x * z->img_comp[i].h + h_max-1) / h_max; - z->img_comp[i].y = (s->img_y * z->img_comp[i].v + v_max-1) / v_max; - // to simplify generation, we'll allocate enough memory to decode - // the bogus oversized data from using interleaved MCUs and their - // big blocks (e.g. a 16x16 iMCU on an image of width 33); we won't - // discard the extra data until colorspace conversion - // - // img_mcu_x, img_mcu_y: <=17 bits; comp[i].h and .v are <=4 (checked earlier) - // so these muls can't overflow with 32-bit ints (which we require) - z->img_comp[i].w2 = z->img_mcu_x * z->img_comp[i].h * 8; - z->img_comp[i].h2 = z->img_mcu_y * z->img_comp[i].v * 8; - z->img_comp[i].coeff = 0; - z->img_comp[i].raw_coeff = 0; - z->img_comp[i].linebuf = NULL; - z->img_comp[i].raw_data = stbi__malloc_mad2(z->img_comp[i].w2, z->img_comp[i].h2, 15); - if (z->img_comp[i].raw_data == NULL) - return stbi__free_jpeg_components(z, i+1, stbi__err("outofmem", "Out of memory")); - // align blocks for idct using mmx/sse - z->img_comp[i].data = (stbi_uc*) (((size_t) z->img_comp[i].raw_data + 15) & ~15); - if (z->progressive) { - // w2, h2 are multiples of 8 (see above) - z->img_comp[i].coeff_w = z->img_comp[i].w2 / 8; - z->img_comp[i].coeff_h = z->img_comp[i].h2 / 8; - z->img_comp[i].raw_coeff = stbi__malloc_mad3(z->img_comp[i].w2, z->img_comp[i].h2, sizeof(short), 15); - if (z->img_comp[i].raw_coeff == NULL) - return stbi__free_jpeg_components(z, i+1, stbi__err("outofmem", "Out of memory")); - z->img_comp[i].coeff = (short*) (((size_t) z->img_comp[i].raw_coeff + 15) & ~15); - } - } - - return 1; -} - -// use comparisons since in some cases we handle more than one case (e.g. SOF) -#define stbi__DNL(x) ((x) == 0xdc) -#define stbi__SOI(x) ((x) == 0xd8) -#define stbi__EOI(x) ((x) == 0xd9) -#define stbi__SOF(x) ((x) == 0xc0 || (x) == 0xc1 || (x) == 0xc2) -#define stbi__SOS(x) ((x) == 0xda) - -#define stbi__SOF_progressive(x) ((x) == 0xc2) - -static int stbi__decode_jpeg_header(stbi__jpeg *z, int scan) -{ - int m; - z->jfif = 0; - z->app14_color_transform = -1; // valid values are 0,1,2 - z->marker = STBI__MARKER_none; // initialize cached marker to empty - m = stbi__get_marker(z); - if (!stbi__SOI(m)) return stbi__err("no SOI","Corrupt JPEG"); - if (scan == STBI__SCAN_type) return 1; - m = stbi__get_marker(z); - while (!stbi__SOF(m)) { - if (!stbi__process_marker(z,m)) return 0; - m = stbi__get_marker(z); - while (m == STBI__MARKER_none) { - // some files have extra padding after their blocks, so ok, we'll scan - if (stbi__at_eof(z->s)) return stbi__err("no SOF", "Corrupt JPEG"); - m = stbi__get_marker(z); - } - } - z->progressive = stbi__SOF_progressive(m); - if (!stbi__process_frame_header(z, scan)) return 0; - return 1; -} - -static int stbi__skip_jpeg_junk_at_end(stbi__jpeg *j) -{ - // some JPEGs have junk at end, skip over it but if we find what looks - // like a valid marker, resume there - while (!stbi__at_eof(j->s)) { - int x = stbi__get8(j->s); - while (x == 255) { // might be a marker - if (stbi__at_eof(j->s)) return STBI__MARKER_none; - x = stbi__get8(j->s); - if (x != 0x00 && x != 0xff) { - // not a stuffed zero or lead-in to another marker, looks - // like an actual marker, return it - return x; - } - // stuffed zero has x=0 now which ends the loop, meaning we go - // back to regular scan loop. - // repeated 0xff keeps trying to read the next byte of the marker. - } - } - return STBI__MARKER_none; -} - -// decode image to YCbCr format -static int stbi__decode_jpeg_image(stbi__jpeg *j) -{ - int m; - for (m = 0; m < 4; m++) { - j->img_comp[m].raw_data = NULL; - j->img_comp[m].raw_coeff = NULL; - } - j->restart_interval = 0; - if (!stbi__decode_jpeg_header(j, STBI__SCAN_load)) return 0; - m = stbi__get_marker(j); - while (!stbi__EOI(m)) { - if (stbi__SOS(m)) { - if (!stbi__process_scan_header(j)) return 0; - if (!stbi__parse_entropy_coded_data(j)) return 0; - if (j->marker == STBI__MARKER_none ) { - j->marker = stbi__skip_jpeg_junk_at_end(j); - // if we reach eof without hitting a marker, stbi__get_marker() below will fail and we'll eventually return 0 - } - m = stbi__get_marker(j); - if (STBI__RESTART(m)) - m = stbi__get_marker(j); - } else if (stbi__DNL(m)) { - int Ld = stbi__get16be(j->s); - stbi__uint32 NL = stbi__get16be(j->s); - if (Ld != 4) return stbi__err("bad DNL len", "Corrupt JPEG"); - if (NL != j->s->img_y) return stbi__err("bad DNL height", "Corrupt JPEG"); - m = stbi__get_marker(j); - } else { - if (!stbi__process_marker(j, m)) return 1; - m = stbi__get_marker(j); - } - } - if (j->progressive) - stbi__jpeg_finish(j); - return 1; -} - -// static jfif-centered resampling (across block boundaries) - -typedef stbi_uc *(*resample_row_func)(stbi_uc *out, stbi_uc *in0, stbi_uc *in1, - int w, int hs); - -#define stbi__div4(x) ((stbi_uc) ((x) >> 2)) - -static stbi_uc *resample_row_1(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs) -{ - STBI_NOTUSED(out); - STBI_NOTUSED(in_far); - STBI_NOTUSED(w); - STBI_NOTUSED(hs); - return in_near; -} - -static stbi_uc* stbi__resample_row_v_2(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs) -{ - // need to generate two samples vertically for every one in input - int i; - STBI_NOTUSED(hs); - for (i=0; i < w; ++i) - out[i] = stbi__div4(3*in_near[i] + in_far[i] + 2); - return out; -} - -static stbi_uc* stbi__resample_row_h_2(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs) -{ - // need to generate two samples horizontally for every one in input - int i; - stbi_uc *input = in_near; - - if (w == 1) { - // if only one sample, can't do any interpolation - out[0] = out[1] = input[0]; - return out; - } - - out[0] = input[0]; - out[1] = stbi__div4(input[0]*3 + input[1] + 2); - for (i=1; i < w-1; ++i) { - int n = 3*input[i]+2; - out[i*2+0] = stbi__div4(n+input[i-1]); - out[i*2+1] = stbi__div4(n+input[i+1]); - } - out[i*2+0] = stbi__div4(input[w-2]*3 + input[w-1] + 2); - out[i*2+1] = input[w-1]; - - STBI_NOTUSED(in_far); - STBI_NOTUSED(hs); - - return out; -} - -#define stbi__div16(x) ((stbi_uc) ((x) >> 4)) - -static stbi_uc *stbi__resample_row_hv_2(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs) -{ - // need to generate 2x2 samples for every one in input - int i,t0,t1; - if (w == 1) { - out[0] = out[1] = stbi__div4(3*in_near[0] + in_far[0] + 2); - return out; - } - - t1 = 3*in_near[0] + in_far[0]; - out[0] = stbi__div4(t1+2); - for (i=1; i < w; ++i) { - t0 = t1; - t1 = 3*in_near[i]+in_far[i]; - out[i*2-1] = stbi__div16(3*t0 + t1 + 8); - out[i*2 ] = stbi__div16(3*t1 + t0 + 8); - } - out[w*2-1] = stbi__div4(t1+2); - - STBI_NOTUSED(hs); - - return out; -} - -#if defined(STBI_SSE2) || defined(STBI_NEON) -static stbi_uc *stbi__resample_row_hv_2_simd(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs) -{ - // need to generate 2x2 samples for every one in input - int i=0,t0,t1; - - if (w == 1) { - out[0] = out[1] = stbi__div4(3*in_near[0] + in_far[0] + 2); - return out; - } - - t1 = 3*in_near[0] + in_far[0]; - // process groups of 8 pixels for as long as we can. - // note we can't handle the last pixel in a row in this loop - // because we need to handle the filter boundary conditions. - for (; i < ((w-1) & ~7); i += 8) { -#if defined(STBI_SSE2) - // load and perform the vertical filtering pass - // this uses 3*x + y = 4*x + (y - x) - __m128i zero = _mm_setzero_si128(); - __m128i farb = _mm_loadl_epi64((__m128i *) (in_far + i)); - __m128i nearb = _mm_loadl_epi64((__m128i *) (in_near + i)); - __m128i farw = _mm_unpacklo_epi8(farb, zero); - __m128i nearw = _mm_unpacklo_epi8(nearb, zero); - __m128i diff = _mm_sub_epi16(farw, nearw); - __m128i nears = _mm_slli_epi16(nearw, 2); - __m128i curr = _mm_add_epi16(nears, diff); // current row - - // horizontal filter works the same based on shifted vers of current - // row. "prev" is current row shifted right by 1 pixel; we need to - // insert the previous pixel value (from t1). - // "next" is current row shifted left by 1 pixel, with first pixel - // of next block of 8 pixels added in. - __m128i prv0 = _mm_slli_si128(curr, 2); - __m128i nxt0 = _mm_srli_si128(curr, 2); - __m128i prev = _mm_insert_epi16(prv0, t1, 0); - __m128i next = _mm_insert_epi16(nxt0, 3*in_near[i+8] + in_far[i+8], 7); - - // horizontal filter, polyphase implementation since it's convenient: - // even pixels = 3*cur + prev = cur*4 + (prev - cur) - // odd pixels = 3*cur + next = cur*4 + (next - cur) - // note the shared term. - __m128i bias = _mm_set1_epi16(8); - __m128i curs = _mm_slli_epi16(curr, 2); - __m128i prvd = _mm_sub_epi16(prev, curr); - __m128i nxtd = _mm_sub_epi16(next, curr); - __m128i curb = _mm_add_epi16(curs, bias); - __m128i even = _mm_add_epi16(prvd, curb); - __m128i odd = _mm_add_epi16(nxtd, curb); - - // interleave even and odd pixels, then undo scaling. - __m128i int0 = _mm_unpacklo_epi16(even, odd); - __m128i int1 = _mm_unpackhi_epi16(even, odd); - __m128i de0 = _mm_srli_epi16(int0, 4); - __m128i de1 = _mm_srli_epi16(int1, 4); - - // pack and write output - __m128i outv = _mm_packus_epi16(de0, de1); - _mm_storeu_si128((__m128i *) (out + i*2), outv); -#elif defined(STBI_NEON) - // load and perform the vertical filtering pass - // this uses 3*x + y = 4*x + (y - x) - uint8x8_t farb = vld1_u8(in_far + i); - uint8x8_t nearb = vld1_u8(in_near + i); - int16x8_t diff = vreinterpretq_s16_u16(vsubl_u8(farb, nearb)); - int16x8_t nears = vreinterpretq_s16_u16(vshll_n_u8(nearb, 2)); - int16x8_t curr = vaddq_s16(nears, diff); // current row - - // horizontal filter works the same based on shifted vers of current - // row. "prev" is current row shifted right by 1 pixel; we need to - // insert the previous pixel value (from t1). - // "next" is current row shifted left by 1 pixel, with first pixel - // of next block of 8 pixels added in. - int16x8_t prv0 = vextq_s16(curr, curr, 7); - int16x8_t nxt0 = vextq_s16(curr, curr, 1); - int16x8_t prev = vsetq_lane_s16(t1, prv0, 0); - int16x8_t next = vsetq_lane_s16(3*in_near[i+8] + in_far[i+8], nxt0, 7); - - // horizontal filter, polyphase implementation since it's convenient: - // even pixels = 3*cur + prev = cur*4 + (prev - cur) - // odd pixels = 3*cur + next = cur*4 + (next - cur) - // note the shared term. - int16x8_t curs = vshlq_n_s16(curr, 2); - int16x8_t prvd = vsubq_s16(prev, curr); - int16x8_t nxtd = vsubq_s16(next, curr); - int16x8_t even = vaddq_s16(curs, prvd); - int16x8_t odd = vaddq_s16(curs, nxtd); - - // undo scaling and round, then store with even/odd phases interleaved - uint8x8x2_t o; - o.val[0] = vqrshrun_n_s16(even, 4); - o.val[1] = vqrshrun_n_s16(odd, 4); - vst2_u8(out + i*2, o); -#endif - - // "previous" value for next iter - t1 = 3*in_near[i+7] + in_far[i+7]; - } - - t0 = t1; - t1 = 3*in_near[i] + in_far[i]; - out[i*2] = stbi__div16(3*t1 + t0 + 8); - - for (++i; i < w; ++i) { - t0 = t1; - t1 = 3*in_near[i]+in_far[i]; - out[i*2-1] = stbi__div16(3*t0 + t1 + 8); - out[i*2 ] = stbi__div16(3*t1 + t0 + 8); - } - out[w*2-1] = stbi__div4(t1+2); - - STBI_NOTUSED(hs); - - return out; -} -#endif - -static stbi_uc *stbi__resample_row_generic(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs) -{ - // resample with nearest-neighbor - int i,j; - STBI_NOTUSED(in_far); - for (i=0; i < w; ++i) - for (j=0; j < hs; ++j) - out[i*hs+j] = in_near[i]; - return out; -} - -// this is a reduced-precision calculation of YCbCr-to-RGB introduced -// to make sure the code produces the same results in both SIMD and scalar -#define stbi__float2fixed(x) (((int) ((x) * 4096.0f + 0.5f)) << 8) -static void stbi__YCbCr_to_RGB_row(stbi_uc *out, const stbi_uc *y, const stbi_uc *pcb, const stbi_uc *pcr, int count, int step) -{ - int i; - for (i=0; i < count; ++i) { - int y_fixed = (y[i] << 20) + (1<<19); // rounding - int r,g,b; - int cr = pcr[i] - 128; - int cb = pcb[i] - 128; - r = y_fixed + cr* stbi__float2fixed(1.40200f); - g = y_fixed + (cr*-stbi__float2fixed(0.71414f)) + ((cb*-stbi__float2fixed(0.34414f)) & 0xffff0000); - b = y_fixed + cb* stbi__float2fixed(1.77200f); - r >>= 20; - g >>= 20; - b >>= 20; - if ((unsigned) r > 255) { if (r < 0) r = 0; else r = 255; } - if ((unsigned) g > 255) { if (g < 0) g = 0; else g = 255; } - if ((unsigned) b > 255) { if (b < 0) b = 0; else b = 255; } - out[0] = (stbi_uc)r; - out[1] = (stbi_uc)g; - out[2] = (stbi_uc)b; - out[3] = 255; - out += step; - } -} - -#if defined(STBI_SSE2) || defined(STBI_NEON) -static void stbi__YCbCr_to_RGB_simd(stbi_uc *out, stbi_uc const *y, stbi_uc const *pcb, stbi_uc const *pcr, int count, int step) -{ - int i = 0; - -#ifdef STBI_SSE2 - // step == 3 is pretty ugly on the final interleave, and i'm not convinced - // it's useful in practice (you wouldn't use it for textures, for example). - // so just accelerate step == 4 case. - if (step == 4) { - // this is a fairly straightforward implementation and not super-optimized. - __m128i signflip = _mm_set1_epi8(-0x80); - __m128i cr_const0 = _mm_set1_epi16( (short) ( 1.40200f*4096.0f+0.5f)); - __m128i cr_const1 = _mm_set1_epi16( - (short) ( 0.71414f*4096.0f+0.5f)); - __m128i cb_const0 = _mm_set1_epi16( - (short) ( 0.34414f*4096.0f+0.5f)); - __m128i cb_const1 = _mm_set1_epi16( (short) ( 1.77200f*4096.0f+0.5f)); - __m128i y_bias = _mm_set1_epi8((char) (unsigned char) 128); - __m128i xw = _mm_set1_epi16(255); // alpha channel - - for (; i+7 < count; i += 8) { - // load - __m128i y_bytes = _mm_loadl_epi64((__m128i *) (y+i)); - __m128i cr_bytes = _mm_loadl_epi64((__m128i *) (pcr+i)); - __m128i cb_bytes = _mm_loadl_epi64((__m128i *) (pcb+i)); - __m128i cr_biased = _mm_xor_si128(cr_bytes, signflip); // -128 - __m128i cb_biased = _mm_xor_si128(cb_bytes, signflip); // -128 - - // unpack to short (and left-shift cr, cb by 8) - __m128i yw = _mm_unpacklo_epi8(y_bias, y_bytes); - __m128i crw = _mm_unpacklo_epi8(_mm_setzero_si128(), cr_biased); - __m128i cbw = _mm_unpacklo_epi8(_mm_setzero_si128(), cb_biased); - - // color transform - __m128i yws = _mm_srli_epi16(yw, 4); - __m128i cr0 = _mm_mulhi_epi16(cr_const0, crw); - __m128i cb0 = _mm_mulhi_epi16(cb_const0, cbw); - __m128i cb1 = _mm_mulhi_epi16(cbw, cb_const1); - __m128i cr1 = _mm_mulhi_epi16(crw, cr_const1); - __m128i rws = _mm_add_epi16(cr0, yws); - __m128i gwt = _mm_add_epi16(cb0, yws); - __m128i bws = _mm_add_epi16(yws, cb1); - __m128i gws = _mm_add_epi16(gwt, cr1); - - // descale - __m128i rw = _mm_srai_epi16(rws, 4); - __m128i bw = _mm_srai_epi16(bws, 4); - __m128i gw = _mm_srai_epi16(gws, 4); - - // back to byte, set up for transpose - __m128i brb = _mm_packus_epi16(rw, bw); - __m128i gxb = _mm_packus_epi16(gw, xw); - - // transpose to interleave channels - __m128i t0 = _mm_unpacklo_epi8(brb, gxb); - __m128i t1 = _mm_unpackhi_epi8(brb, gxb); - __m128i o0 = _mm_unpacklo_epi16(t0, t1); - __m128i o1 = _mm_unpackhi_epi16(t0, t1); - - // store - _mm_storeu_si128((__m128i *) (out + 0), o0); - _mm_storeu_si128((__m128i *) (out + 16), o1); - out += 32; - } - } -#endif - -#ifdef STBI_NEON - // in this version, step=3 support would be easy to add. but is there demand? - if (step == 4) { - // this is a fairly straightforward implementation and not super-optimized. - uint8x8_t signflip = vdup_n_u8(0x80); - int16x8_t cr_const0 = vdupq_n_s16( (short) ( 1.40200f*4096.0f+0.5f)); - int16x8_t cr_const1 = vdupq_n_s16( - (short) ( 0.71414f*4096.0f+0.5f)); - int16x8_t cb_const0 = vdupq_n_s16( - (short) ( 0.34414f*4096.0f+0.5f)); - int16x8_t cb_const1 = vdupq_n_s16( (short) ( 1.77200f*4096.0f+0.5f)); - - for (; i+7 < count; i += 8) { - // load - uint8x8_t y_bytes = vld1_u8(y + i); - uint8x8_t cr_bytes = vld1_u8(pcr + i); - uint8x8_t cb_bytes = vld1_u8(pcb + i); - int8x8_t cr_biased = vreinterpret_s8_u8(vsub_u8(cr_bytes, signflip)); - int8x8_t cb_biased = vreinterpret_s8_u8(vsub_u8(cb_bytes, signflip)); - - // expand to s16 - int16x8_t yws = vreinterpretq_s16_u16(vshll_n_u8(y_bytes, 4)); - int16x8_t crw = vshll_n_s8(cr_biased, 7); - int16x8_t cbw = vshll_n_s8(cb_biased, 7); - - // color transform - int16x8_t cr0 = vqdmulhq_s16(crw, cr_const0); - int16x8_t cb0 = vqdmulhq_s16(cbw, cb_const0); - int16x8_t cr1 = vqdmulhq_s16(crw, cr_const1); - int16x8_t cb1 = vqdmulhq_s16(cbw, cb_const1); - int16x8_t rws = vaddq_s16(yws, cr0); - int16x8_t gws = vaddq_s16(vaddq_s16(yws, cb0), cr1); - int16x8_t bws = vaddq_s16(yws, cb1); - - // undo scaling, round, convert to byte - uint8x8x4_t o; - o.val[0] = vqrshrun_n_s16(rws, 4); - o.val[1] = vqrshrun_n_s16(gws, 4); - o.val[2] = vqrshrun_n_s16(bws, 4); - o.val[3] = vdup_n_u8(255); - - // store, interleaving r/g/b/a - vst4_u8(out, o); - out += 8*4; - } - } -#endif - - for (; i < count; ++i) { - int y_fixed = (y[i] << 20) + (1<<19); // rounding - int r,g,b; - int cr = pcr[i] - 128; - int cb = pcb[i] - 128; - r = y_fixed + cr* stbi__float2fixed(1.40200f); - g = y_fixed + cr*-stbi__float2fixed(0.71414f) + ((cb*-stbi__float2fixed(0.34414f)) & 0xffff0000); - b = y_fixed + cb* stbi__float2fixed(1.77200f); - r >>= 20; - g >>= 20; - b >>= 20; - if ((unsigned) r > 255) { if (r < 0) r = 0; else r = 255; } - if ((unsigned) g > 255) { if (g < 0) g = 0; else g = 255; } - if ((unsigned) b > 255) { if (b < 0) b = 0; else b = 255; } - out[0] = (stbi_uc)r; - out[1] = (stbi_uc)g; - out[2] = (stbi_uc)b; - out[3] = 255; - out += step; - } -} -#endif - -// set up the kernels -static void stbi__setup_jpeg(stbi__jpeg *j) -{ - j->idct_block_kernel = stbi__idct_block; - j->YCbCr_to_RGB_kernel = stbi__YCbCr_to_RGB_row; - j->resample_row_hv_2_kernel = stbi__resample_row_hv_2; - -#ifdef STBI_SSE2 - if (stbi__sse2_available()) { - j->idct_block_kernel = stbi__idct_simd; - j->YCbCr_to_RGB_kernel = stbi__YCbCr_to_RGB_simd; - j->resample_row_hv_2_kernel = stbi__resample_row_hv_2_simd; - } -#endif - -#ifdef STBI_NEON - j->idct_block_kernel = stbi__idct_simd; - j->YCbCr_to_RGB_kernel = stbi__YCbCr_to_RGB_simd; - j->resample_row_hv_2_kernel = stbi__resample_row_hv_2_simd; -#endif -} - -// clean up the temporary component buffers -static void stbi__cleanup_jpeg(stbi__jpeg *j) -{ - stbi__free_jpeg_components(j, j->s->img_n, 0); -} - -typedef struct -{ - resample_row_func resample; - stbi_uc *line0,*line1; - int hs,vs; // expansion factor in each axis - int w_lores; // horizontal pixels pre-expansion - int ystep; // how far through vertical expansion we are - int ypos; // which pre-expansion row we're on -} stbi__resample; - -// fast 0..255 * 0..255 => 0..255 rounded multiplication -static stbi_uc stbi__blinn_8x8(stbi_uc x, stbi_uc y) -{ - unsigned int t = x*y + 128; - return (stbi_uc) ((t + (t >>8)) >> 8); -} - -static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp, int req_comp) -{ - int n, decode_n, is_rgb; - z->s->img_n = 0; // make stbi__cleanup_jpeg safe - - // validate req_comp - if (req_comp < 0 || req_comp > 4) return stbi__errpuc("bad req_comp", "Internal error"); - - // load a jpeg image from whichever source, but leave in YCbCr format - if (!stbi__decode_jpeg_image(z)) { stbi__cleanup_jpeg(z); return NULL; } - - // determine actual number of components to generate - n = req_comp ? req_comp : z->s->img_n >= 3 ? 3 : 1; - - is_rgb = z->s->img_n == 3 && (z->rgb == 3 || (z->app14_color_transform == 0 && !z->jfif)); - - if (z->s->img_n == 3 && n < 3 && !is_rgb) - decode_n = 1; - else - decode_n = z->s->img_n; - - // nothing to do if no components requested; check this now to avoid - // accessing uninitialized coutput[0] later - if (decode_n <= 0) { stbi__cleanup_jpeg(z); return NULL; } - - // resample and color-convert - { - int k; - unsigned int i,j; - stbi_uc *output; - stbi_uc *coutput[4] = { NULL, NULL, NULL, NULL }; - - stbi__resample res_comp[4]; - - for (k=0; k < decode_n; ++k) { - stbi__resample *r = &res_comp[k]; - - // allocate line buffer big enough for upsampling off the edges - // with upsample factor of 4 - z->img_comp[k].linebuf = (stbi_uc *) stbi__malloc(z->s->img_x + 3); - if (!z->img_comp[k].linebuf) { stbi__cleanup_jpeg(z); return stbi__errpuc("outofmem", "Out of memory"); } - - r->hs = z->img_h_max / z->img_comp[k].h; - r->vs = z->img_v_max / z->img_comp[k].v; - r->ystep = r->vs >> 1; - r->w_lores = (z->s->img_x + r->hs-1) / r->hs; - r->ypos = 0; - r->line0 = r->line1 = z->img_comp[k].data; - - if (r->hs == 1 && r->vs == 1) r->resample = resample_row_1; - else if (r->hs == 1 && r->vs == 2) r->resample = stbi__resample_row_v_2; - else if (r->hs == 2 && r->vs == 1) r->resample = stbi__resample_row_h_2; - else if (r->hs == 2 && r->vs == 2) r->resample = z->resample_row_hv_2_kernel; - else r->resample = stbi__resample_row_generic; - } - - // can't error after this so, this is safe - output = (stbi_uc *) stbi__malloc_mad3(n, z->s->img_x, z->s->img_y, 1); - if (!output) { stbi__cleanup_jpeg(z); return stbi__errpuc("outofmem", "Out of memory"); } - - // now go ahead and resample - for (j=0; j < z->s->img_y; ++j) { - stbi_uc *out = output + n * z->s->img_x * j; - for (k=0; k < decode_n; ++k) { - stbi__resample *r = &res_comp[k]; - int y_bot = r->ystep >= (r->vs >> 1); - coutput[k] = r->resample(z->img_comp[k].linebuf, - y_bot ? r->line1 : r->line0, - y_bot ? r->line0 : r->line1, - r->w_lores, r->hs); - if (++r->ystep >= r->vs) { - r->ystep = 0; - r->line0 = r->line1; - if (++r->ypos < z->img_comp[k].y) - r->line1 += z->img_comp[k].w2; - } - } - if (n >= 3) { - stbi_uc *y = coutput[0]; - if (z->s->img_n == 3) { - if (is_rgb) { - for (i=0; i < z->s->img_x; ++i) { - out[0] = y[i]; - out[1] = coutput[1][i]; - out[2] = coutput[2][i]; - out[3] = 255; - out += n; - } - } else { - z->YCbCr_to_RGB_kernel(out, y, coutput[1], coutput[2], z->s->img_x, n); - } - } else if (z->s->img_n == 4) { - if (z->app14_color_transform == 0) { // CMYK - for (i=0; i < z->s->img_x; ++i) { - stbi_uc m = coutput[3][i]; - out[0] = stbi__blinn_8x8(coutput[0][i], m); - out[1] = stbi__blinn_8x8(coutput[1][i], m); - out[2] = stbi__blinn_8x8(coutput[2][i], m); - out[3] = 255; - out += n; - } - } else if (z->app14_color_transform == 2) { // YCCK - z->YCbCr_to_RGB_kernel(out, y, coutput[1], coutput[2], z->s->img_x, n); - for (i=0; i < z->s->img_x; ++i) { - stbi_uc m = coutput[3][i]; - out[0] = stbi__blinn_8x8(255 - out[0], m); - out[1] = stbi__blinn_8x8(255 - out[1], m); - out[2] = stbi__blinn_8x8(255 - out[2], m); - out += n; - } - } else { // YCbCr + alpha? Ignore the fourth channel for now - z->YCbCr_to_RGB_kernel(out, y, coutput[1], coutput[2], z->s->img_x, n); - } - } else - for (i=0; i < z->s->img_x; ++i) { - out[0] = out[1] = out[2] = y[i]; - out[3] = 255; // not used if n==3 - out += n; - } - } else { - if (is_rgb) { - if (n == 1) - for (i=0; i < z->s->img_x; ++i) - *out++ = stbi__compute_y(coutput[0][i], coutput[1][i], coutput[2][i]); - else { - for (i=0; i < z->s->img_x; ++i, out += 2) { - out[0] = stbi__compute_y(coutput[0][i], coutput[1][i], coutput[2][i]); - out[1] = 255; - } - } - } else if (z->s->img_n == 4 && z->app14_color_transform == 0) { - for (i=0; i < z->s->img_x; ++i) { - stbi_uc m = coutput[3][i]; - stbi_uc r = stbi__blinn_8x8(coutput[0][i], m); - stbi_uc g = stbi__blinn_8x8(coutput[1][i], m); - stbi_uc b = stbi__blinn_8x8(coutput[2][i], m); - out[0] = stbi__compute_y(r, g, b); - out[1] = 255; - out += n; - } - } else if (z->s->img_n == 4 && z->app14_color_transform == 2) { - for (i=0; i < z->s->img_x; ++i) { - out[0] = stbi__blinn_8x8(255 - coutput[0][i], coutput[3][i]); - out[1] = 255; - out += n; - } - } else { - stbi_uc *y = coutput[0]; - if (n == 1) - for (i=0; i < z->s->img_x; ++i) out[i] = y[i]; - else - for (i=0; i < z->s->img_x; ++i) { *out++ = y[i]; *out++ = 255; } - } - } - } - stbi__cleanup_jpeg(z); - *out_x = z->s->img_x; - *out_y = z->s->img_y; - if (comp) *comp = z->s->img_n >= 3 ? 3 : 1; // report original components, not output - return output; - } -} - -static void *stbi__jpeg_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri) -{ - unsigned char* result; - stbi__jpeg* j = (stbi__jpeg*) stbi__malloc(sizeof(stbi__jpeg)); - if (!j) return stbi__errpuc("outofmem", "Out of memory"); - memset(j, 0, sizeof(stbi__jpeg)); - STBI_NOTUSED(ri); - j->s = s; - stbi__setup_jpeg(j); - result = load_jpeg_image(j, x,y,comp,req_comp); - STBI_FREE(j); - return result; -} - -static int stbi__jpeg_test(stbi__context *s) -{ - int r; - stbi__jpeg* j = (stbi__jpeg*)stbi__malloc(sizeof(stbi__jpeg)); - if (!j) return stbi__err("outofmem", "Out of memory"); - memset(j, 0, sizeof(stbi__jpeg)); - j->s = s; - stbi__setup_jpeg(j); - r = stbi__decode_jpeg_header(j, STBI__SCAN_type); - stbi__rewind(s); - STBI_FREE(j); - return r; -} - -static int stbi__jpeg_info_raw(stbi__jpeg *j, int *x, int *y, int *comp) -{ - if (!stbi__decode_jpeg_header(j, STBI__SCAN_header)) { - stbi__rewind( j->s ); - return 0; - } - if (x) *x = j->s->img_x; - if (y) *y = j->s->img_y; - if (comp) *comp = j->s->img_n >= 3 ? 3 : 1; - return 1; -} - -static int stbi__jpeg_info(stbi__context *s, int *x, int *y, int *comp) -{ - int result; - stbi__jpeg* j = (stbi__jpeg*) (stbi__malloc(sizeof(stbi__jpeg))); - if (!j) return stbi__err("outofmem", "Out of memory"); - memset(j, 0, sizeof(stbi__jpeg)); - j->s = s; - result = stbi__jpeg_info_raw(j, x, y, comp); - STBI_FREE(j); - return result; -} -#endif - -// public domain zlib decode v0.2 Sean Barrett 2006-11-18 -// simple implementation -// - all input must be provided in an upfront buffer -// - all output is written to a single output buffer (can malloc/realloc) -// performance -// - fast huffman - -#ifndef STBI_NO_ZLIB - -// fast-way is faster to check than jpeg huffman, but slow way is slower -#define STBI__ZFAST_BITS 9 // accelerate all cases in default tables -#define STBI__ZFAST_MASK ((1 << STBI__ZFAST_BITS) - 1) -#define STBI__ZNSYMS 288 // number of symbols in literal/length alphabet - -// zlib-style huffman encoding -// (jpegs packs from left, zlib from right, so can't share code) -typedef struct -{ - stbi__uint16 fast[1 << STBI__ZFAST_BITS]; - stbi__uint16 firstcode[16]; - int maxcode[17]; - stbi__uint16 firstsymbol[16]; - stbi_uc size[STBI__ZNSYMS]; - stbi__uint16 value[STBI__ZNSYMS]; -} stbi__zhuffman; - -stbi_inline static int stbi__bitreverse16(int n) -{ - n = ((n & 0xAAAA) >> 1) | ((n & 0x5555) << 1); - n = ((n & 0xCCCC) >> 2) | ((n & 0x3333) << 2); - n = ((n & 0xF0F0) >> 4) | ((n & 0x0F0F) << 4); - n = ((n & 0xFF00) >> 8) | ((n & 0x00FF) << 8); - return n; -} - -stbi_inline static int stbi__bit_reverse(int v, int bits) -{ - STBI_ASSERT(bits <= 16); - // to bit reverse n bits, reverse 16 and shift - // e.g. 11 bits, bit reverse and shift away 5 - return stbi__bitreverse16(v) >> (16-bits); -} - -static int stbi__zbuild_huffman(stbi__zhuffman *z, const stbi_uc *sizelist, int num) -{ - int i,k=0; - int code, next_code[16], sizes[17]; - - // DEFLATE spec for generating codes - memset(sizes, 0, sizeof(sizes)); - memset(z->fast, 0, sizeof(z->fast)); - for (i=0; i < num; ++i) - ++sizes[sizelist[i]]; - sizes[0] = 0; - for (i=1; i < 16; ++i) - if (sizes[i] > (1 << i)) - return stbi__err("bad sizes", "Corrupt PNG"); - code = 0; - for (i=1; i < 16; ++i) { - next_code[i] = code; - z->firstcode[i] = (stbi__uint16) code; - z->firstsymbol[i] = (stbi__uint16) k; - code = (code + sizes[i]); - if (sizes[i]) - if (code-1 >= (1 << i)) return stbi__err("bad codelengths","Corrupt PNG"); - z->maxcode[i] = code << (16-i); // preshift for inner loop - code <<= 1; - k += sizes[i]; - } - z->maxcode[16] = 0x10000; // sentinel - for (i=0; i < num; ++i) { - int s = sizelist[i]; - if (s) { - int c = next_code[s] - z->firstcode[s] + z->firstsymbol[s]; - stbi__uint16 fastv = (stbi__uint16) ((s << 9) | i); - z->size [c] = (stbi_uc ) s; - z->value[c] = (stbi__uint16) i; - if (s <= STBI__ZFAST_BITS) { - int j = stbi__bit_reverse(next_code[s],s); - while (j < (1 << STBI__ZFAST_BITS)) { - z->fast[j] = fastv; - j += (1 << s); - } - } - ++next_code[s]; - } - } - return 1; -} - -// zlib-from-memory implementation for PNG reading -// because PNG allows splitting the zlib stream arbitrarily, -// and it's annoying structurally to have PNG call ZLIB call PNG, -// we require PNG read all the IDATs and combine them into a single -// memory buffer - -typedef struct -{ - stbi_uc *zbuffer, *zbuffer_end; - int num_bits; - stbi__uint32 code_buffer; - - char *zout; - char *zout_start; - char *zout_end; - int z_expandable; - - stbi__zhuffman z_length, z_distance; -} stbi__zbuf; - -stbi_inline static int stbi__zeof(stbi__zbuf *z) -{ - return (z->zbuffer >= z->zbuffer_end); -} - -stbi_inline static stbi_uc stbi__zget8(stbi__zbuf *z) -{ - return stbi__zeof(z) ? 0 : *z->zbuffer++; -} - -static void stbi__fill_bits(stbi__zbuf *z) -{ - do { - if (z->code_buffer >= (1U << z->num_bits)) { - z->zbuffer = z->zbuffer_end; /* treat this as EOF so we fail. */ - return; - } - z->code_buffer |= (unsigned int) stbi__zget8(z) << z->num_bits; - z->num_bits += 8; - } while (z->num_bits <= 24); -} - -stbi_inline static unsigned int stbi__zreceive(stbi__zbuf *z, int n) -{ - unsigned int k; - if (z->num_bits < n) stbi__fill_bits(z); - k = z->code_buffer & ((1 << n) - 1); - z->code_buffer >>= n; - z->num_bits -= n; - return k; -} - -static int stbi__zhuffman_decode_slowpath(stbi__zbuf *a, stbi__zhuffman *z) -{ - int b,s,k; - // not resolved by fast table, so compute it the slow way - // use jpeg approach, which requires MSbits at top - k = stbi__bit_reverse(a->code_buffer, 16); - for (s=STBI__ZFAST_BITS+1; ; ++s) - if (k < z->maxcode[s]) - break; - if (s >= 16) return -1; // invalid code! - // code size is s, so: - b = (k >> (16-s)) - z->firstcode[s] + z->firstsymbol[s]; - if (b >= STBI__ZNSYMS) return -1; // some data was corrupt somewhere! - if (z->size[b] != s) return -1; // was originally an assert, but report failure instead. - a->code_buffer >>= s; - a->num_bits -= s; - return z->value[b]; -} - -stbi_inline static int stbi__zhuffman_decode(stbi__zbuf *a, stbi__zhuffman *z) -{ - int b,s; - if (a->num_bits < 16) { - if (stbi__zeof(a)) { - return -1; /* report error for unexpected end of data. */ - } - stbi__fill_bits(a); - } - b = z->fast[a->code_buffer & STBI__ZFAST_MASK]; - if (b) { - s = b >> 9; - a->code_buffer >>= s; - a->num_bits -= s; - return b & 511; - } - return stbi__zhuffman_decode_slowpath(a, z); -} - -static int stbi__zexpand(stbi__zbuf *z, char *zout, int n) // need to make room for n bytes -{ - char *q; - unsigned int cur, limit, old_limit; - z->zout = zout; - if (!z->z_expandable) return stbi__err("output buffer limit","Corrupt PNG"); - cur = (unsigned int) (z->zout - z->zout_start); - limit = old_limit = (unsigned) (z->zout_end - z->zout_start); - if (UINT_MAX - cur < (unsigned) n) return stbi__err("outofmem", "Out of memory"); - while (cur + n > limit) { - if(limit > UINT_MAX / 2) return stbi__err("outofmem", "Out of memory"); - limit *= 2; - } - q = (char *) STBI_REALLOC_SIZED(z->zout_start, old_limit, limit); - STBI_NOTUSED(old_limit); - if (q == NULL) return stbi__err("outofmem", "Out of memory"); - z->zout_start = q; - z->zout = q + cur; - z->zout_end = q + limit; - return 1; -} - -static const int stbi__zlength_base[31] = { - 3,4,5,6,7,8,9,10,11,13, - 15,17,19,23,27,31,35,43,51,59, - 67,83,99,115,131,163,195,227,258,0,0 }; - -static const int stbi__zlength_extra[31]= -{ 0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0 }; - -static const int stbi__zdist_base[32] = { 1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193, -257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0}; - -static const int stbi__zdist_extra[32] = -{ 0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13}; - -static int stbi__parse_huffman_block(stbi__zbuf *a) -{ - char *zout = a->zout; - for(;;) { - int z = stbi__zhuffman_decode(a, &a->z_length); - if (z < 256) { - if (z < 0) return stbi__err("bad huffman code","Corrupt PNG"); // error in huffman codes - if (zout >= a->zout_end) { - if (!stbi__zexpand(a, zout, 1)) return 0; - zout = a->zout; - } - *zout++ = (char) z; - } else { - stbi_uc *p; - int len,dist; - if (z == 256) { - a->zout = zout; - return 1; - } - if (z >= 286) return stbi__err("bad huffman code","Corrupt PNG"); // per DEFLATE, length codes 286 and 287 must not appear in compressed data - z -= 257; - len = stbi__zlength_base[z]; - if (stbi__zlength_extra[z]) len += stbi__zreceive(a, stbi__zlength_extra[z]); - z = stbi__zhuffman_decode(a, &a->z_distance); - if (z < 0 || z >= 30) return stbi__err("bad huffman code","Corrupt PNG"); // per DEFLATE, distance codes 30 and 31 must not appear in compressed data - dist = stbi__zdist_base[z]; - if (stbi__zdist_extra[z]) dist += stbi__zreceive(a, stbi__zdist_extra[z]); - if (zout - a->zout_start < dist) return stbi__err("bad dist","Corrupt PNG"); - if (zout + len > a->zout_end) { - if (!stbi__zexpand(a, zout, len)) return 0; - zout = a->zout; - } - p = (stbi_uc *) (zout - dist); - if (dist == 1) { // run of one byte; common in images. - stbi_uc v = *p; - if (len) { do *zout++ = v; while (--len); } - } else { - if (len) { do *zout++ = *p++; while (--len); } - } - } - } -} - -static int stbi__compute_huffman_codes(stbi__zbuf *a) -{ - static const stbi_uc length_dezigzag[19] = { 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15 }; - stbi__zhuffman z_codelength; - stbi_uc lencodes[286+32+137];//padding for maximum single op - stbi_uc codelength_sizes[19]; - int i,n; - - int hlit = stbi__zreceive(a,5) + 257; - int hdist = stbi__zreceive(a,5) + 1; - int hclen = stbi__zreceive(a,4) + 4; - int ntot = hlit + hdist; - - memset(codelength_sizes, 0, sizeof(codelength_sizes)); - for (i=0; i < hclen; ++i) { - int s = stbi__zreceive(a,3); - codelength_sizes[length_dezigzag[i]] = (stbi_uc) s; - } - if (!stbi__zbuild_huffman(&z_codelength, codelength_sizes, 19)) return 0; - - n = 0; - while (n < ntot) { - int c = stbi__zhuffman_decode(a, &z_codelength); - if (c < 0 || c >= 19) return stbi__err("bad codelengths", "Corrupt PNG"); - if (c < 16) - lencodes[n++] = (stbi_uc) c; - else { - stbi_uc fill = 0; - if (c == 16) { - c = stbi__zreceive(a,2)+3; - if (n == 0) return stbi__err("bad codelengths", "Corrupt PNG"); - fill = lencodes[n-1]; - } else if (c == 17) { - c = stbi__zreceive(a,3)+3; - } else if (c == 18) { - c = stbi__zreceive(a,7)+11; - } else { - return stbi__err("bad codelengths", "Corrupt PNG"); - } - if (ntot - n < c) return stbi__err("bad codelengths", "Corrupt PNG"); - memset(lencodes+n, fill, c); - n += c; - } - } - if (n != ntot) return stbi__err("bad codelengths","Corrupt PNG"); - if (!stbi__zbuild_huffman(&a->z_length, lencodes, hlit)) return 0; - if (!stbi__zbuild_huffman(&a->z_distance, lencodes+hlit, hdist)) return 0; - return 1; -} - -static int stbi__parse_uncompressed_block(stbi__zbuf *a) -{ - stbi_uc header[4]; - int len,nlen,k; - if (a->num_bits & 7) - stbi__zreceive(a, a->num_bits & 7); // discard - // drain the bit-packed data into header - k = 0; - while (a->num_bits > 0) { - header[k++] = (stbi_uc) (a->code_buffer & 255); // suppress MSVC run-time check - a->code_buffer >>= 8; - a->num_bits -= 8; - } - if (a->num_bits < 0) return stbi__err("zlib corrupt","Corrupt PNG"); - // now fill header the normal way - while (k < 4) - header[k++] = stbi__zget8(a); - len = header[1] * 256 + header[0]; - nlen = header[3] * 256 + header[2]; - if (nlen != (len ^ 0xffff)) return stbi__err("zlib corrupt","Corrupt PNG"); - if (a->zbuffer + len > a->zbuffer_end) return stbi__err("read past buffer","Corrupt PNG"); - if (a->zout + len > a->zout_end) - if (!stbi__zexpand(a, a->zout, len)) return 0; - memcpy(a->zout, a->zbuffer, len); - a->zbuffer += len; - a->zout += len; - return 1; -} - -static int stbi__parse_zlib_header(stbi__zbuf *a) -{ - int cmf = stbi__zget8(a); - int cm = cmf & 15; - /* int cinfo = cmf >> 4; */ - int flg = stbi__zget8(a); - if (stbi__zeof(a)) return stbi__err("bad zlib header","Corrupt PNG"); // zlib spec - if ((cmf*256+flg) % 31 != 0) return stbi__err("bad zlib header","Corrupt PNG"); // zlib spec - if (flg & 32) return stbi__err("no preset dict","Corrupt PNG"); // preset dictionary not allowed in png - if (cm != 8) return stbi__err("bad compression","Corrupt PNG"); // DEFLATE required for png - // window = 1 << (8 + cinfo)... but who cares, we fully buffer output - return 1; -} - -static const stbi_uc stbi__zdefault_length[STBI__ZNSYMS] = -{ - 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, - 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, - 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, - 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, - 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, - 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, - 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, - 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8 -}; -static const stbi_uc stbi__zdefault_distance[32] = -{ - 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5 -}; -/* -Init algorithm: -{ - int i; // use <= to match clearly with spec - for (i=0; i <= 143; ++i) stbi__zdefault_length[i] = 8; - for ( ; i <= 255; ++i) stbi__zdefault_length[i] = 9; - for ( ; i <= 279; ++i) stbi__zdefault_length[i] = 7; - for ( ; i <= 287; ++i) stbi__zdefault_length[i] = 8; - - for (i=0; i <= 31; ++i) stbi__zdefault_distance[i] = 5; -} -*/ - -static int stbi__parse_zlib(stbi__zbuf *a, int parse_header) -{ - int final, type; - if (parse_header) - if (!stbi__parse_zlib_header(a)) return 0; - a->num_bits = 0; - a->code_buffer = 0; - do { - final = stbi__zreceive(a,1); - type = stbi__zreceive(a,2); - if (type == 0) { - if (!stbi__parse_uncompressed_block(a)) return 0; - } else if (type == 3) { - return 0; - } else { - if (type == 1) { - // use fixed code lengths - if (!stbi__zbuild_huffman(&a->z_length , stbi__zdefault_length , STBI__ZNSYMS)) return 0; - if (!stbi__zbuild_huffman(&a->z_distance, stbi__zdefault_distance, 32)) return 0; - } else { - if (!stbi__compute_huffman_codes(a)) return 0; - } - if (!stbi__parse_huffman_block(a)) return 0; - } - } while (!final); - return 1; -} - -static int stbi__do_zlib(stbi__zbuf *a, char *obuf, int olen, int exp, int parse_header) -{ - a->zout_start = obuf; - a->zout = obuf; - a->zout_end = obuf + olen; - a->z_expandable = exp; - - return stbi__parse_zlib(a, parse_header); -} - -STBIDEF char *stbi_zlib_decode_malloc_guesssize(const char *buffer, int len, int initial_size, int *outlen) -{ - stbi__zbuf a; - char *p = (char *) stbi__malloc(initial_size); - if (p == NULL) return NULL; - a.zbuffer = (stbi_uc *) buffer; - a.zbuffer_end = (stbi_uc *) buffer + len; - if (stbi__do_zlib(&a, p, initial_size, 1, 1)) { - if (outlen) *outlen = (int) (a.zout - a.zout_start); - return a.zout_start; - } else { - STBI_FREE(a.zout_start); - return NULL; - } -} - -STBIDEF char *stbi_zlib_decode_malloc(char const *buffer, int len, int *outlen) -{ - return stbi_zlib_decode_malloc_guesssize(buffer, len, 16384, outlen); -} - -STBIDEF char *stbi_zlib_decode_malloc_guesssize_headerflag(const char *buffer, int len, int initial_size, int *outlen, int parse_header) -{ - stbi__zbuf a; - char *p = (char *) stbi__malloc(initial_size); - if (p == NULL) return NULL; - a.zbuffer = (stbi_uc *) buffer; - a.zbuffer_end = (stbi_uc *) buffer + len; - if (stbi__do_zlib(&a, p, initial_size, 1, parse_header)) { - if (outlen) *outlen = (int) (a.zout - a.zout_start); - return a.zout_start; - } else { - STBI_FREE(a.zout_start); - return NULL; - } -} - -STBIDEF int stbi_zlib_decode_buffer(char *obuffer, int olen, char const *ibuffer, int ilen) -{ - stbi__zbuf a; - a.zbuffer = (stbi_uc *) ibuffer; - a.zbuffer_end = (stbi_uc *) ibuffer + ilen; - if (stbi__do_zlib(&a, obuffer, olen, 0, 1)) - return (int) (a.zout - a.zout_start); - else - return -1; -} - -STBIDEF char *stbi_zlib_decode_noheader_malloc(char const *buffer, int len, int *outlen) -{ - stbi__zbuf a; - char *p = (char *) stbi__malloc(16384); - if (p == NULL) return NULL; - a.zbuffer = (stbi_uc *) buffer; - a.zbuffer_end = (stbi_uc *) buffer+len; - if (stbi__do_zlib(&a, p, 16384, 1, 0)) { - if (outlen) *outlen = (int) (a.zout - a.zout_start); - return a.zout_start; - } else { - STBI_FREE(a.zout_start); - return NULL; - } -} - -STBIDEF int stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const char *ibuffer, int ilen) -{ - stbi__zbuf a; - a.zbuffer = (stbi_uc *) ibuffer; - a.zbuffer_end = (stbi_uc *) ibuffer + ilen; - if (stbi__do_zlib(&a, obuffer, olen, 0, 0)) - return (int) (a.zout - a.zout_start); - else - return -1; -} -#endif - -// public domain "baseline" PNG decoder v0.10 Sean Barrett 2006-11-18 -// simple implementation -// - only 8-bit samples -// - no CRC checking -// - allocates lots of intermediate memory -// - avoids problem of streaming data between subsystems -// - avoids explicit window management -// performance -// - uses stb_zlib, a PD zlib implementation with fast huffman decoding - -#ifndef STBI_NO_PNG -typedef struct -{ - stbi__uint32 length; - stbi__uint32 type; -} stbi__pngchunk; - -static stbi__pngchunk stbi__get_chunk_header(stbi__context *s) -{ - stbi__pngchunk c; - c.length = stbi__get32be(s); - c.type = stbi__get32be(s); - return c; -} - -static int stbi__check_png_header(stbi__context *s) -{ - static const stbi_uc png_sig[8] = { 137,80,78,71,13,10,26,10 }; - int i; - for (i=0; i < 8; ++i) - if (stbi__get8(s) != png_sig[i]) return stbi__err("bad png sig","Not a PNG"); - return 1; -} - -typedef struct -{ - stbi__context *s; - stbi_uc *idata, *expanded, *out; - int depth; -} stbi__png; - - -enum { - STBI__F_none=0, - STBI__F_sub=1, - STBI__F_up=2, - STBI__F_avg=3, - STBI__F_paeth=4, - // synthetic filters used for first scanline to avoid needing a dummy row of 0s - STBI__F_avg_first, - STBI__F_paeth_first -}; - -static stbi_uc first_row_filter[5] = -{ - STBI__F_none, - STBI__F_sub, - STBI__F_none, - STBI__F_avg_first, - STBI__F_paeth_first -}; - -static int stbi__paeth(int a, int b, int c) -{ - int p = a + b - c; - int pa = abs(p-a); - int pb = abs(p-b); - int pc = abs(p-c); - if (pa <= pb && pa <= pc) return a; - if (pb <= pc) return b; - return c; -} - -static const stbi_uc stbi__depth_scale_table[9] = { 0, 0xff, 0x55, 0, 0x11, 0,0,0, 0x01 }; - -// create the png data from post-deflated data -static int stbi__create_png_image_raw(stbi__png *a, stbi_uc *raw, stbi__uint32 raw_len, int out_n, stbi__uint32 x, stbi__uint32 y, int depth, int color) -{ - int bytes = (depth == 16? 2 : 1); - stbi__context *s = a->s; - stbi__uint32 i,j,stride = x*out_n*bytes; - stbi__uint32 img_len, img_width_bytes; - int k; - int img_n = s->img_n; // copy it into a local for later - - int output_bytes = out_n*bytes; - int filter_bytes = img_n*bytes; - int width = x; - - STBI_ASSERT(out_n == s->img_n || out_n == s->img_n+1); - a->out = (stbi_uc *) stbi__malloc_mad3(x, y, output_bytes, 0); // extra bytes to write off the end into - if (!a->out) return stbi__err("outofmem", "Out of memory"); - - if (!stbi__mad3sizes_valid(img_n, x, depth, 7)) return stbi__err("too large", "Corrupt PNG"); - img_width_bytes = (((img_n * x * depth) + 7) >> 3); - img_len = (img_width_bytes + 1) * y; - - // we used to check for exact match between raw_len and img_len on non-interlaced PNGs, - // but issue #276 reported a PNG in the wild that had extra data at the end (all zeros), - // so just check for raw_len < img_len always. - if (raw_len < img_len) return stbi__err("not enough pixels","Corrupt PNG"); - - for (j=0; j < y; ++j) { - stbi_uc *cur = a->out + stride*j; - stbi_uc *prior; - int filter = *raw++; - - if (filter > 4) - return stbi__err("invalid filter","Corrupt PNG"); - - if (depth < 8) { - if (img_width_bytes > x) return stbi__err("invalid width","Corrupt PNG"); - cur += x*out_n - img_width_bytes; // store output to the rightmost img_len bytes, so we can decode in place - filter_bytes = 1; - width = img_width_bytes; - } - prior = cur - stride; // bugfix: need to compute this after 'cur +=' computation above - - // if first row, use special filter that doesn't sample previous row - if (j == 0) filter = first_row_filter[filter]; - - // handle first byte explicitly - for (k=0; k < filter_bytes; ++k) { - switch (filter) { - case STBI__F_none : cur[k] = raw[k]; break; - case STBI__F_sub : cur[k] = raw[k]; break; - case STBI__F_up : cur[k] = STBI__BYTECAST(raw[k] + prior[k]); break; - case STBI__F_avg : cur[k] = STBI__BYTECAST(raw[k] + (prior[k]>>1)); break; - case STBI__F_paeth : cur[k] = STBI__BYTECAST(raw[k] + stbi__paeth(0,prior[k],0)); break; - case STBI__F_avg_first : cur[k] = raw[k]; break; - case STBI__F_paeth_first: cur[k] = raw[k]; break; - } - } - - if (depth == 8) { - if (img_n != out_n) - cur[img_n] = 255; // first pixel - raw += img_n; - cur += out_n; - prior += out_n; - } else if (depth == 16) { - if (img_n != out_n) { - cur[filter_bytes] = 255; // first pixel top byte - cur[filter_bytes+1] = 255; // first pixel bottom byte - } - raw += filter_bytes; - cur += output_bytes; - prior += output_bytes; - } else { - raw += 1; - cur += 1; - prior += 1; - } - - // this is a little gross, so that we don't switch per-pixel or per-component - if (depth < 8 || img_n == out_n) { - int nk = (width - 1)*filter_bytes; - #define STBI__CASE(f) \ - case f: \ - for (k=0; k < nk; ++k) - switch (filter) { - // "none" filter turns into a memcpy here; make that explicit. - case STBI__F_none: memcpy(cur, raw, nk); break; - STBI__CASE(STBI__F_sub) { cur[k] = STBI__BYTECAST(raw[k] + cur[k-filter_bytes]); } break; - STBI__CASE(STBI__F_up) { cur[k] = STBI__BYTECAST(raw[k] + prior[k]); } break; - STBI__CASE(STBI__F_avg) { cur[k] = STBI__BYTECAST(raw[k] + ((prior[k] + cur[k-filter_bytes])>>1)); } break; - STBI__CASE(STBI__F_paeth) { cur[k] = STBI__BYTECAST(raw[k] + stbi__paeth(cur[k-filter_bytes],prior[k],prior[k-filter_bytes])); } break; - STBI__CASE(STBI__F_avg_first) { cur[k] = STBI__BYTECAST(raw[k] + (cur[k-filter_bytes] >> 1)); } break; - STBI__CASE(STBI__F_paeth_first) { cur[k] = STBI__BYTECAST(raw[k] + stbi__paeth(cur[k-filter_bytes],0,0)); } break; - } - #undef STBI__CASE - raw += nk; - } else { - STBI_ASSERT(img_n+1 == out_n); - #define STBI__CASE(f) \ - case f: \ - for (i=x-1; i >= 1; --i, cur[filter_bytes]=255,raw+=filter_bytes,cur+=output_bytes,prior+=output_bytes) \ - for (k=0; k < filter_bytes; ++k) - switch (filter) { - STBI__CASE(STBI__F_none) { cur[k] = raw[k]; } break; - STBI__CASE(STBI__F_sub) { cur[k] = STBI__BYTECAST(raw[k] + cur[k- output_bytes]); } break; - STBI__CASE(STBI__F_up) { cur[k] = STBI__BYTECAST(raw[k] + prior[k]); } break; - STBI__CASE(STBI__F_avg) { cur[k] = STBI__BYTECAST(raw[k] + ((prior[k] + cur[k- output_bytes])>>1)); } break; - STBI__CASE(STBI__F_paeth) { cur[k] = STBI__BYTECAST(raw[k] + stbi__paeth(cur[k- output_bytes],prior[k],prior[k- output_bytes])); } break; - STBI__CASE(STBI__F_avg_first) { cur[k] = STBI__BYTECAST(raw[k] + (cur[k- output_bytes] >> 1)); } break; - STBI__CASE(STBI__F_paeth_first) { cur[k] = STBI__BYTECAST(raw[k] + stbi__paeth(cur[k- output_bytes],0,0)); } break; - } - #undef STBI__CASE - - // the loop above sets the high byte of the pixels' alpha, but for - // 16 bit png files we also need the low byte set. we'll do that here. - if (depth == 16) { - cur = a->out + stride*j; // start at the beginning of the row again - for (i=0; i < x; ++i,cur+=output_bytes) { - cur[filter_bytes+1] = 255; - } - } - } - } - - // we make a separate pass to expand bits to pixels; for performance, - // this could run two scanlines behind the above code, so it won't - // intefere with filtering but will still be in the cache. - if (depth < 8) { - for (j=0; j < y; ++j) { - stbi_uc *cur = a->out + stride*j; - stbi_uc *in = a->out + stride*j + x*out_n - img_width_bytes; - // unpack 1/2/4-bit into a 8-bit buffer. allows us to keep the common 8-bit path optimal at minimal cost for 1/2/4-bit - // png guarante byte alignment, if width is not multiple of 8/4/2 we'll decode dummy trailing data that will be skipped in the later loop - stbi_uc scale = (color == 0) ? stbi__depth_scale_table[depth] : 1; // scale grayscale values to 0..255 range - - // note that the final byte might overshoot and write more data than desired. - // we can allocate enough data that this never writes out of memory, but it - // could also overwrite the next scanline. can it overwrite non-empty data - // on the next scanline? yes, consider 1-pixel-wide scanlines with 1-bit-per-pixel. - // so we need to explicitly clamp the final ones - - if (depth == 4) { - for (k=x*img_n; k >= 2; k-=2, ++in) { - *cur++ = scale * ((*in >> 4) ); - *cur++ = scale * ((*in ) & 0x0f); - } - if (k > 0) *cur++ = scale * ((*in >> 4) ); - } else if (depth == 2) { - for (k=x*img_n; k >= 4; k-=4, ++in) { - *cur++ = scale * ((*in >> 6) ); - *cur++ = scale * ((*in >> 4) & 0x03); - *cur++ = scale * ((*in >> 2) & 0x03); - *cur++ = scale * ((*in ) & 0x03); - } - if (k > 0) *cur++ = scale * ((*in >> 6) ); - if (k > 1) *cur++ = scale * ((*in >> 4) & 0x03); - if (k > 2) *cur++ = scale * ((*in >> 2) & 0x03); - } else if (depth == 1) { - for (k=x*img_n; k >= 8; k-=8, ++in) { - *cur++ = scale * ((*in >> 7) ); - *cur++ = scale * ((*in >> 6) & 0x01); - *cur++ = scale * ((*in >> 5) & 0x01); - *cur++ = scale * ((*in >> 4) & 0x01); - *cur++ = scale * ((*in >> 3) & 0x01); - *cur++ = scale * ((*in >> 2) & 0x01); - *cur++ = scale * ((*in >> 1) & 0x01); - *cur++ = scale * ((*in ) & 0x01); - } - if (k > 0) *cur++ = scale * ((*in >> 7) ); - if (k > 1) *cur++ = scale * ((*in >> 6) & 0x01); - if (k > 2) *cur++ = scale * ((*in >> 5) & 0x01); - if (k > 3) *cur++ = scale * ((*in >> 4) & 0x01); - if (k > 4) *cur++ = scale * ((*in >> 3) & 0x01); - if (k > 5) *cur++ = scale * ((*in >> 2) & 0x01); - if (k > 6) *cur++ = scale * ((*in >> 1) & 0x01); - } - if (img_n != out_n) { - int q; - // insert alpha = 255 - cur = a->out + stride*j; - if (img_n == 1) { - for (q=x-1; q >= 0; --q) { - cur[q*2+1] = 255; - cur[q*2+0] = cur[q]; - } - } else { - STBI_ASSERT(img_n == 3); - for (q=x-1; q >= 0; --q) { - cur[q*4+3] = 255; - cur[q*4+2] = cur[q*3+2]; - cur[q*4+1] = cur[q*3+1]; - cur[q*4+0] = cur[q*3+0]; - } - } - } - } - } else if (depth == 16) { - // force the image data from big-endian to platform-native. - // this is done in a separate pass due to the decoding relying - // on the data being untouched, but could probably be done - // per-line during decode if care is taken. - stbi_uc *cur = a->out; - stbi__uint16 *cur16 = (stbi__uint16*)cur; - - for(i=0; i < x*y*out_n; ++i,cur16++,cur+=2) { - *cur16 = (cur[0] << 8) | cur[1]; - } - } - - return 1; -} - -static int stbi__create_png_image(stbi__png *a, stbi_uc *image_data, stbi__uint32 image_data_len, int out_n, int depth, int color, int interlaced) -{ - int bytes = (depth == 16 ? 2 : 1); - int out_bytes = out_n * bytes; - stbi_uc *final; - int p; - if (!interlaced) - return stbi__create_png_image_raw(a, image_data, image_data_len, out_n, a->s->img_x, a->s->img_y, depth, color); - - // de-interlacing - final = (stbi_uc *) stbi__malloc_mad3(a->s->img_x, a->s->img_y, out_bytes, 0); - if (!final) return stbi__err("outofmem", "Out of memory"); - for (p=0; p < 7; ++p) { - int xorig[] = { 0,4,0,2,0,1,0 }; - int yorig[] = { 0,0,4,0,2,0,1 }; - int xspc[] = { 8,8,4,4,2,2,1 }; - int yspc[] = { 8,8,8,4,4,2,2 }; - int i,j,x,y; - // pass1_x[4] = 0, pass1_x[5] = 1, pass1_x[12] = 1 - x = (a->s->img_x - xorig[p] + xspc[p]-1) / xspc[p]; - y = (a->s->img_y - yorig[p] + yspc[p]-1) / yspc[p]; - if (x && y) { - stbi__uint32 img_len = ((((a->s->img_n * x * depth) + 7) >> 3) + 1) * y; - if (!stbi__create_png_image_raw(a, image_data, image_data_len, out_n, x, y, depth, color)) { - STBI_FREE(final); - return 0; - } - for (j=0; j < y; ++j) { - for (i=0; i < x; ++i) { - int out_y = j*yspc[p]+yorig[p]; - int out_x = i*xspc[p]+xorig[p]; - memcpy(final + out_y*a->s->img_x*out_bytes + out_x*out_bytes, - a->out + (j*x+i)*out_bytes, out_bytes); - } - } - STBI_FREE(a->out); - image_data += img_len; - image_data_len -= img_len; - } - } - a->out = final; - - return 1; -} - -static int stbi__compute_transparency(stbi__png *z, stbi_uc tc[3], int out_n) -{ - stbi__context *s = z->s; - stbi__uint32 i, pixel_count = s->img_x * s->img_y; - stbi_uc *p = z->out; - - // compute color-based transparency, assuming we've - // already got 255 as the alpha value in the output - STBI_ASSERT(out_n == 2 || out_n == 4); - - if (out_n == 2) { - for (i=0; i < pixel_count; ++i) { - p[1] = (p[0] == tc[0] ? 0 : 255); - p += 2; - } - } else { - for (i=0; i < pixel_count; ++i) { - if (p[0] == tc[0] && p[1] == tc[1] && p[2] == tc[2]) - p[3] = 0; - p += 4; - } - } - return 1; -} - -static int stbi__compute_transparency16(stbi__png *z, stbi__uint16 tc[3], int out_n) -{ - stbi__context *s = z->s; - stbi__uint32 i, pixel_count = s->img_x * s->img_y; - stbi__uint16 *p = (stbi__uint16*) z->out; - - // compute color-based transparency, assuming we've - // already got 65535 as the alpha value in the output - STBI_ASSERT(out_n == 2 || out_n == 4); - - if (out_n == 2) { - for (i = 0; i < pixel_count; ++i) { - p[1] = (p[0] == tc[0] ? 0 : 65535); - p += 2; - } - } else { - for (i = 0; i < pixel_count; ++i) { - if (p[0] == tc[0] && p[1] == tc[1] && p[2] == tc[2]) - p[3] = 0; - p += 4; - } - } - return 1; -} - -static int stbi__expand_png_palette(stbi__png *a, stbi_uc *palette, int len, int pal_img_n) -{ - stbi__uint32 i, pixel_count = a->s->img_x * a->s->img_y; - stbi_uc *p, *temp_out, *orig = a->out; - - p = (stbi_uc *) stbi__malloc_mad2(pixel_count, pal_img_n, 0); - if (p == NULL) return stbi__err("outofmem", "Out of memory"); - - // between here and free(out) below, exitting would leak - temp_out = p; - - if (pal_img_n == 3) { - for (i=0; i < pixel_count; ++i) { - int n = orig[i]*4; - p[0] = palette[n ]; - p[1] = palette[n+1]; - p[2] = palette[n+2]; - p += 3; - } - } else { - for (i=0; i < pixel_count; ++i) { - int n = orig[i]*4; - p[0] = palette[n ]; - p[1] = palette[n+1]; - p[2] = palette[n+2]; - p[3] = palette[n+3]; - p += 4; - } - } - STBI_FREE(a->out); - a->out = temp_out; - - STBI_NOTUSED(len); - - return 1; -} - -static int stbi__unpremultiply_on_load_global = 0; -static int stbi__de_iphone_flag_global = 0; - -STBIDEF void stbi_set_unpremultiply_on_load(int flag_true_if_should_unpremultiply) -{ - stbi__unpremultiply_on_load_global = flag_true_if_should_unpremultiply; -} - -STBIDEF void stbi_convert_iphone_png_to_rgb(int flag_true_if_should_convert) -{ - stbi__de_iphone_flag_global = flag_true_if_should_convert; -} - -#ifndef STBI_THREAD_LOCAL -#define stbi__unpremultiply_on_load stbi__unpremultiply_on_load_global -#define stbi__de_iphone_flag stbi__de_iphone_flag_global -#else -static STBI_THREAD_LOCAL int stbi__unpremultiply_on_load_local, stbi__unpremultiply_on_load_set; -static STBI_THREAD_LOCAL int stbi__de_iphone_flag_local, stbi__de_iphone_flag_set; - -STBIDEF void stbi_set_unpremultiply_on_load_thread(int flag_true_if_should_unpremultiply) -{ - stbi__unpremultiply_on_load_local = flag_true_if_should_unpremultiply; - stbi__unpremultiply_on_load_set = 1; -} - -STBIDEF void stbi_convert_iphone_png_to_rgb_thread(int flag_true_if_should_convert) -{ - stbi__de_iphone_flag_local = flag_true_if_should_convert; - stbi__de_iphone_flag_set = 1; -} - -#define stbi__unpremultiply_on_load (stbi__unpremultiply_on_load_set \ - ? stbi__unpremultiply_on_load_local \ - : stbi__unpremultiply_on_load_global) -#define stbi__de_iphone_flag (stbi__de_iphone_flag_set \ - ? stbi__de_iphone_flag_local \ - : stbi__de_iphone_flag_global) -#endif // STBI_THREAD_LOCAL - -static void stbi__de_iphone(stbi__png *z) -{ - stbi__context *s = z->s; - stbi__uint32 i, pixel_count = s->img_x * s->img_y; - stbi_uc *p = z->out; - - if (s->img_out_n == 3) { // convert bgr to rgb - for (i=0; i < pixel_count; ++i) { - stbi_uc t = p[0]; - p[0] = p[2]; - p[2] = t; - p += 3; - } - } else { - STBI_ASSERT(s->img_out_n == 4); - if (stbi__unpremultiply_on_load) { - // convert bgr to rgb and unpremultiply - for (i=0; i < pixel_count; ++i) { - stbi_uc a = p[3]; - stbi_uc t = p[0]; - if (a) { - stbi_uc half = a / 2; - p[0] = (p[2] * 255 + half) / a; - p[1] = (p[1] * 255 + half) / a; - p[2] = ( t * 255 + half) / a; - } else { - p[0] = p[2]; - p[2] = t; - } - p += 4; - } - } else { - // convert bgr to rgb - for (i=0; i < pixel_count; ++i) { - stbi_uc t = p[0]; - p[0] = p[2]; - p[2] = t; - p += 4; - } - } - } -} - -#define STBI__PNG_TYPE(a,b,c,d) (((unsigned) (a) << 24) + ((unsigned) (b) << 16) + ((unsigned) (c) << 8) + (unsigned) (d)) - -static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp) -{ - stbi_uc palette[1024], pal_img_n=0; - stbi_uc has_trans=0, tc[3]={0}; - stbi__uint16 tc16[3]; - stbi__uint32 ioff=0, idata_limit=0, i, pal_len=0; - int first=1,k,interlace=0, color=0, is_iphone=0; - stbi__context *s = z->s; - - z->expanded = NULL; - z->idata = NULL; - z->out = NULL; - - if (!stbi__check_png_header(s)) return 0; - - if (scan == STBI__SCAN_type) return 1; - - for (;;) { - stbi__pngchunk c = stbi__get_chunk_header(s); - switch (c.type) { - case STBI__PNG_TYPE('C','g','B','I'): - is_iphone = 1; - stbi__skip(s, c.length); - break; - case STBI__PNG_TYPE('I','H','D','R'): { - int comp,filter; - if (!first) return stbi__err("multiple IHDR","Corrupt PNG"); - first = 0; - if (c.length != 13) return stbi__err("bad IHDR len","Corrupt PNG"); - s->img_x = stbi__get32be(s); - s->img_y = stbi__get32be(s); - if (s->img_y > STBI_MAX_DIMENSIONS) return stbi__err("too large","Very large image (corrupt?)"); - if (s->img_x > STBI_MAX_DIMENSIONS) return stbi__err("too large","Very large image (corrupt?)"); - z->depth = stbi__get8(s); if (z->depth != 1 && z->depth != 2 && z->depth != 4 && z->depth != 8 && z->depth != 16) return stbi__err("1/2/4/8/16-bit only","PNG not supported: 1/2/4/8/16-bit only"); - color = stbi__get8(s); if (color > 6) return stbi__err("bad ctype","Corrupt PNG"); - if (color == 3 && z->depth == 16) return stbi__err("bad ctype","Corrupt PNG"); - if (color == 3) pal_img_n = 3; else if (color & 1) return stbi__err("bad ctype","Corrupt PNG"); - comp = stbi__get8(s); if (comp) return stbi__err("bad comp method","Corrupt PNG"); - filter= stbi__get8(s); if (filter) return stbi__err("bad filter method","Corrupt PNG"); - interlace = stbi__get8(s); if (interlace>1) return stbi__err("bad interlace method","Corrupt PNG"); - if (!s->img_x || !s->img_y) return stbi__err("0-pixel image","Corrupt PNG"); - if (!pal_img_n) { - s->img_n = (color & 2 ? 3 : 1) + (color & 4 ? 1 : 0); - if ((1 << 30) / s->img_x / s->img_n < s->img_y) return stbi__err("too large", "Image too large to decode"); - } else { - // if paletted, then pal_n is our final components, and - // img_n is # components to decompress/filter. - s->img_n = 1; - if ((1 << 30) / s->img_x / 4 < s->img_y) return stbi__err("too large","Corrupt PNG"); - } - // even with SCAN_header, have to scan to see if we have a tRNS - break; - } - - case STBI__PNG_TYPE('P','L','T','E'): { - if (first) return stbi__err("first not IHDR", "Corrupt PNG"); - if (c.length > 256*3) return stbi__err("invalid PLTE","Corrupt PNG"); - pal_len = c.length / 3; - if (pal_len * 3 != c.length) return stbi__err("invalid PLTE","Corrupt PNG"); - for (i=0; i < pal_len; ++i) { - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - } - break; - } - - case STBI__PNG_TYPE('t','R','N','S'): { - if (first) return stbi__err("first not IHDR", "Corrupt PNG"); - if (z->idata) return stbi__err("tRNS after IDAT","Corrupt PNG"); - if (pal_img_n) { - if (scan == STBI__SCAN_header) { s->img_n = 4; return 1; } - if (pal_len == 0) return stbi__err("tRNS before PLTE","Corrupt PNG"); - if (c.length > pal_len) return stbi__err("bad tRNS len","Corrupt PNG"); - pal_img_n = 4; - for (i=0; i < c.length; ++i) - palette[i*4+3] = stbi__get8(s); - } else { - if (!(s->img_n & 1)) return stbi__err("tRNS with alpha","Corrupt PNG"); - if (c.length != (stbi__uint32) s->img_n*2) return stbi__err("bad tRNS len","Corrupt PNG"); - has_trans = 1; - // non-paletted with tRNS = constant alpha. if header-scanning, we can stop now. - if (scan == STBI__SCAN_header) { ++s->img_n; return 1; } - if (z->depth == 16) { - for (k = 0; k < s->img_n; ++k) tc16[k] = (stbi__uint16)stbi__get16be(s); // copy the values as-is - } else { - for (k = 0; k < s->img_n; ++k) tc[k] = (stbi_uc)(stbi__get16be(s) & 255) * stbi__depth_scale_table[z->depth]; // non 8-bit images will be larger - } - } - break; - } - - case STBI__PNG_TYPE('I','D','A','T'): { - if (first) return stbi__err("first not IHDR", "Corrupt PNG"); - if (pal_img_n && !pal_len) return stbi__err("no PLTE","Corrupt PNG"); - if (scan == STBI__SCAN_header) { - // header scan definitely stops at first IDAT - if (pal_img_n) - s->img_n = pal_img_n; - return 1; - } - if (c.length > (1u << 30)) return stbi__err("IDAT size limit", "IDAT section larger than 2^30 bytes"); - if ((int)(ioff + c.length) < (int)ioff) return 0; - if (ioff + c.length > idata_limit) { - stbi__uint32 idata_limit_old = idata_limit; - stbi_uc *p; - if (idata_limit == 0) idata_limit = c.length > 4096 ? c.length : 4096; - while (ioff + c.length > idata_limit) - idata_limit *= 2; - STBI_NOTUSED(idata_limit_old); - p = (stbi_uc *) STBI_REALLOC_SIZED(z->idata, idata_limit_old, idata_limit); if (p == NULL) return stbi__err("outofmem", "Out of memory"); - z->idata = p; - } - if (!stbi__getn(s, z->idata+ioff,c.length)) return stbi__err("outofdata","Corrupt PNG"); - ioff += c.length; - break; - } - - case STBI__PNG_TYPE('I','E','N','D'): { - stbi__uint32 raw_len, bpl; - if (first) return stbi__err("first not IHDR", "Corrupt PNG"); - if (scan != STBI__SCAN_load) return 1; - if (z->idata == NULL) return stbi__err("no IDAT","Corrupt PNG"); - // initial guess for decoded data size to avoid unnecessary reallocs - bpl = (s->img_x * z->depth + 7) / 8; // bytes per line, per component - raw_len = bpl * s->img_y * s->img_n /* pixels */ + s->img_y /* filter mode per row */; - z->expanded = (stbi_uc *) stbi_zlib_decode_malloc_guesssize_headerflag((char *) z->idata, ioff, raw_len, (int *) &raw_len, !is_iphone); - if (z->expanded == NULL) return 0; // zlib should set error - STBI_FREE(z->idata); z->idata = NULL; - if ((req_comp == s->img_n+1 && req_comp != 3 && !pal_img_n) || has_trans) - s->img_out_n = s->img_n+1; - else - s->img_out_n = s->img_n; - if (!stbi__create_png_image(z, z->expanded, raw_len, s->img_out_n, z->depth, color, interlace)) return 0; - if (has_trans) { - if (z->depth == 16) { - if (!stbi__compute_transparency16(z, tc16, s->img_out_n)) return 0; - } else { - if (!stbi__compute_transparency(z, tc, s->img_out_n)) return 0; - } - } - if (is_iphone && stbi__de_iphone_flag && s->img_out_n > 2) - stbi__de_iphone(z); - if (pal_img_n) { - // pal_img_n == 3 or 4 - s->img_n = pal_img_n; // record the actual colors we had - s->img_out_n = pal_img_n; - if (req_comp >= 3) s->img_out_n = req_comp; - if (!stbi__expand_png_palette(z, palette, pal_len, s->img_out_n)) - return 0; - } else if (has_trans) { - // non-paletted image with tRNS -> source image has (constant) alpha - ++s->img_n; - } - STBI_FREE(z->expanded); z->expanded = NULL; - // end of PNG chunk, read and skip CRC - stbi__get32be(s); - return 1; - } - - default: - // if critical, fail - if (first) return stbi__err("first not IHDR", "Corrupt PNG"); - if ((c.type & (1 << 29)) == 0) { - #ifndef STBI_NO_FAILURE_STRINGS - // not threadsafe - static char invalid_chunk[] = "XXXX PNG chunk not known"; - invalid_chunk[0] = STBI__BYTECAST(c.type >> 24); - invalid_chunk[1] = STBI__BYTECAST(c.type >> 16); - invalid_chunk[2] = STBI__BYTECAST(c.type >> 8); - invalid_chunk[3] = STBI__BYTECAST(c.type >> 0); - #endif - return stbi__err(invalid_chunk, "PNG not supported: unknown PNG chunk type"); - } - stbi__skip(s, c.length); - break; - } - // end of PNG chunk, read and skip CRC - stbi__get32be(s); - } -} - -static void *stbi__do_png(stbi__png *p, int *x, int *y, int *n, int req_comp, stbi__result_info *ri) -{ - void *result=NULL; - if (req_comp < 0 || req_comp > 4) return stbi__errpuc("bad req_comp", "Internal error"); - if (stbi__parse_png_file(p, STBI__SCAN_load, req_comp)) { - if (p->depth <= 8) - ri->bits_per_channel = 8; - else if (p->depth == 16) - ri->bits_per_channel = 16; - else - return stbi__errpuc("bad bits_per_channel", "PNG not supported: unsupported color depth"); - result = p->out; - p->out = NULL; - if (req_comp && req_comp != p->s->img_out_n) { - if (ri->bits_per_channel == 8) - result = stbi__convert_format((unsigned char *) result, p->s->img_out_n, req_comp, p->s->img_x, p->s->img_y); - else - result = stbi__convert_format16((stbi__uint16 *) result, p->s->img_out_n, req_comp, p->s->img_x, p->s->img_y); - p->s->img_out_n = req_comp; - if (result == NULL) return result; - } - *x = p->s->img_x; - *y = p->s->img_y; - if (n) *n = p->s->img_n; - } - STBI_FREE(p->out); p->out = NULL; - STBI_FREE(p->expanded); p->expanded = NULL; - STBI_FREE(p->idata); p->idata = NULL; - - return result; -} - -static void *stbi__png_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri) -{ - stbi__png p; - p.s = s; - return stbi__do_png(&p, x,y,comp,req_comp, ri); -} - -static int stbi__png_test(stbi__context *s) -{ - int r; - r = stbi__check_png_header(s); - stbi__rewind(s); - return r; -} - -static int stbi__png_info_raw(stbi__png *p, int *x, int *y, int *comp) -{ - if (!stbi__parse_png_file(p, STBI__SCAN_header, 0)) { - stbi__rewind( p->s ); - return 0; - } - if (x) *x = p->s->img_x; - if (y) *y = p->s->img_y; - if (comp) *comp = p->s->img_n; - return 1; -} - -static int stbi__png_info(stbi__context *s, int *x, int *y, int *comp) -{ - stbi__png p; - p.s = s; - return stbi__png_info_raw(&p, x, y, comp); -} - -static int stbi__png_is16(stbi__context *s) -{ - stbi__png p; - p.s = s; - if (!stbi__png_info_raw(&p, NULL, NULL, NULL)) - return 0; - if (p.depth != 16) { - stbi__rewind(p.s); - return 0; - } - return 1; -} -#endif - -// Microsoft/Windows BMP image - -#ifndef STBI_NO_BMP -static int stbi__bmp_test_raw(stbi__context *s) -{ - int r; - int sz; - if (stbi__get8(s) != 'B') return 0; - if (stbi__get8(s) != 'M') return 0; - stbi__get32le(s); // discard filesize - stbi__get16le(s); // discard reserved - stbi__get16le(s); // discard reserved - stbi__get32le(s); // discard data offset - sz = stbi__get32le(s); - r = (sz == 12 || sz == 40 || sz == 56 || sz == 108 || sz == 124); - return r; -} - -static int stbi__bmp_test(stbi__context *s) -{ - int r = stbi__bmp_test_raw(s); - stbi__rewind(s); - return r; -} - - -// returns 0..31 for the highest set bit -static int stbi__high_bit(unsigned int z) -{ - int n=0; - if (z == 0) return -1; - if (z >= 0x10000) { n += 16; z >>= 16; } - if (z >= 0x00100) { n += 8; z >>= 8; } - if (z >= 0x00010) { n += 4; z >>= 4; } - if (z >= 0x00004) { n += 2; z >>= 2; } - if (z >= 0x00002) { n += 1;/* >>= 1;*/ } - return n; -} - -static int stbi__bitcount(unsigned int a) -{ - a = (a & 0x55555555) + ((a >> 1) & 0x55555555); // max 2 - a = (a & 0x33333333) + ((a >> 2) & 0x33333333); // max 4 - a = (a + (a >> 4)) & 0x0f0f0f0f; // max 8 per 4, now 8 bits - a = (a + (a >> 8)); // max 16 per 8 bits - a = (a + (a >> 16)); // max 32 per 8 bits - return a & 0xff; -} - -// extract an arbitrarily-aligned N-bit value (N=bits) -// from v, and then make it 8-bits long and fractionally -// extend it to full full range. -static int stbi__shiftsigned(unsigned int v, int shift, int bits) -{ - static unsigned int mul_table[9] = { - 0, - 0xff/*0b11111111*/, 0x55/*0b01010101*/, 0x49/*0b01001001*/, 0x11/*0b00010001*/, - 0x21/*0b00100001*/, 0x41/*0b01000001*/, 0x81/*0b10000001*/, 0x01/*0b00000001*/, - }; - static unsigned int shift_table[9] = { - 0, 0,0,1,0,2,4,6,0, - }; - if (shift < 0) - v <<= -shift; - else - v >>= shift; - STBI_ASSERT(v < 256); - v >>= (8-bits); - STBI_ASSERT(bits >= 0 && bits <= 8); - return (int) ((unsigned) v * mul_table[bits]) >> shift_table[bits]; -} - -typedef struct -{ - int bpp, offset, hsz; - unsigned int mr,mg,mb,ma, all_a; - int extra_read; -} stbi__bmp_data; - -static int stbi__bmp_set_mask_defaults(stbi__bmp_data *info, int compress) -{ - // BI_BITFIELDS specifies masks explicitly, don't override - if (compress == 3) - return 1; - - if (compress == 0) { - if (info->bpp == 16) { - info->mr = 31u << 10; - info->mg = 31u << 5; - info->mb = 31u << 0; - } else if (info->bpp == 32) { - info->mr = 0xffu << 16; - info->mg = 0xffu << 8; - info->mb = 0xffu << 0; - info->ma = 0xffu << 24; - info->all_a = 0; // if all_a is 0 at end, then we loaded alpha channel but it was all 0 - } else { - // otherwise, use defaults, which is all-0 - info->mr = info->mg = info->mb = info->ma = 0; - } - return 1; - } - return 0; // error -} - -static void *stbi__bmp_parse_header(stbi__context *s, stbi__bmp_data *info) -{ - int hsz; - if (stbi__get8(s) != 'B' || stbi__get8(s) != 'M') return stbi__errpuc("not BMP", "Corrupt BMP"); - stbi__get32le(s); // discard filesize - stbi__get16le(s); // discard reserved - stbi__get16le(s); // discard reserved - info->offset = stbi__get32le(s); - info->hsz = hsz = stbi__get32le(s); - info->mr = info->mg = info->mb = info->ma = 0; - info->extra_read = 14; - - if (info->offset < 0) return stbi__errpuc("bad BMP", "bad BMP"); - - if (hsz != 12 && hsz != 40 && hsz != 56 && hsz != 108 && hsz != 124) return stbi__errpuc("unknown BMP", "BMP type not supported: unknown"); - if (hsz == 12) { - s->img_x = stbi__get16le(s); - s->img_y = stbi__get16le(s); - } else { - s->img_x = stbi__get32le(s); - s->img_y = stbi__get32le(s); - } - if (stbi__get16le(s) != 1) return stbi__errpuc("bad BMP", "bad BMP"); - info->bpp = stbi__get16le(s); - if (hsz != 12) { - int compress = stbi__get32le(s); - if (compress == 1 || compress == 2) return stbi__errpuc("BMP RLE", "BMP type not supported: RLE"); - if (compress >= 4) return stbi__errpuc("BMP JPEG/PNG", "BMP type not supported: unsupported compression"); // this includes PNG/JPEG modes - if (compress == 3 && info->bpp != 16 && info->bpp != 32) return stbi__errpuc("bad BMP", "bad BMP"); // bitfields requires 16 or 32 bits/pixel - stbi__get32le(s); // discard sizeof - stbi__get32le(s); // discard hres - stbi__get32le(s); // discard vres - stbi__get32le(s); // discard colorsused - stbi__get32le(s); // discard max important - if (hsz == 40 || hsz == 56) { - if (hsz == 56) { - stbi__get32le(s); - stbi__get32le(s); - stbi__get32le(s); - stbi__get32le(s); - } - if (info->bpp == 16 || info->bpp == 32) { - if (compress == 0) { - stbi__bmp_set_mask_defaults(info, compress); - } else if (compress == 3) { - info->mr = stbi__get32le(s); - info->mg = stbi__get32le(s); - info->mb = stbi__get32le(s); - info->extra_read += 12; - // not documented, but generated by photoshop and handled by mspaint - if (info->mr == info->mg && info->mg == info->mb) { - // ?!?!? - return stbi__errpuc("bad BMP", "bad BMP"); - } - } else - return stbi__errpuc("bad BMP", "bad BMP"); - } - } else { - // V4/V5 header - int i; - if (hsz != 108 && hsz != 124) - return stbi__errpuc("bad BMP", "bad BMP"); - info->mr = stbi__get32le(s); - info->mg = stbi__get32le(s); - info->mb = stbi__get32le(s); - info->ma = stbi__get32le(s); - if (compress != 3) // override mr/mg/mb unless in BI_BITFIELDS mode, as per docs - stbi__bmp_set_mask_defaults(info, compress); - stbi__get32le(s); // discard color space - for (i=0; i < 12; ++i) - stbi__get32le(s); // discard color space parameters - if (hsz == 124) { - stbi__get32le(s); // discard rendering intent - stbi__get32le(s); // discard offset of profile data - stbi__get32le(s); // discard size of profile data - stbi__get32le(s); // discard reserved - } - } - } - return (void *) 1; -} - - -static void *stbi__bmp_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri) -{ - stbi_uc *out; - unsigned int mr=0,mg=0,mb=0,ma=0, all_a; - stbi_uc pal[256][4]; - int psize=0,i,j,width; - int flip_vertically, pad, target; - stbi__bmp_data info; - STBI_NOTUSED(ri); - - info.all_a = 255; - if (stbi__bmp_parse_header(s, &info) == NULL) - return NULL; // error code already set - - flip_vertically = ((int) s->img_y) > 0; - s->img_y = abs((int) s->img_y); - - if (s->img_y > STBI_MAX_DIMENSIONS) return stbi__errpuc("too large","Very large image (corrupt?)"); - if (s->img_x > STBI_MAX_DIMENSIONS) return stbi__errpuc("too large","Very large image (corrupt?)"); - - mr = info.mr; - mg = info.mg; - mb = info.mb; - ma = info.ma; - all_a = info.all_a; - - if (info.hsz == 12) { - if (info.bpp < 24) - psize = (info.offset - info.extra_read - 24) / 3; - } else { - if (info.bpp < 16) - psize = (info.offset - info.extra_read - info.hsz) >> 2; - } - if (psize == 0) { - // accept some number of extra bytes after the header, but if the offset points either to before - // the header ends or implies a large amount of extra data, reject the file as malformed - int bytes_read_so_far = s->callback_already_read + (int)(s->img_buffer - s->img_buffer_original); - int header_limit = 1024; // max we actually read is below 256 bytes currently. - int extra_data_limit = 256*4; // what ordinarily goes here is a palette; 256 entries*4 bytes is its max size. - if (bytes_read_so_far <= 0 || bytes_read_so_far > header_limit) { - return stbi__errpuc("bad header", "Corrupt BMP"); - } - // we established that bytes_read_so_far is positive and sensible. - // the first half of this test rejects offsets that are either too small positives, or - // negative, and guarantees that info.offset >= bytes_read_so_far > 0. this in turn - // ensures the number computed in the second half of the test can't overflow. - if (info.offset < bytes_read_so_far || info.offset - bytes_read_so_far > extra_data_limit) { - return stbi__errpuc("bad offset", "Corrupt BMP"); - } else { - stbi__skip(s, info.offset - bytes_read_so_far); - } - } - - if (info.bpp == 24 && ma == 0xff000000) - s->img_n = 3; - else - s->img_n = ma ? 4 : 3; - if (req_comp && req_comp >= 3) // we can directly decode 3 or 4 - target = req_comp; - else - target = s->img_n; // if they want monochrome, we'll post-convert - - // sanity-check size - if (!stbi__mad3sizes_valid(target, s->img_x, s->img_y, 0)) - return stbi__errpuc("too large", "Corrupt BMP"); - - out = (stbi_uc *) stbi__malloc_mad3(target, s->img_x, s->img_y, 0); - if (!out) return stbi__errpuc("outofmem", "Out of memory"); - if (info.bpp < 16) { - int z=0; - if (psize == 0 || psize > 256) { STBI_FREE(out); return stbi__errpuc("invalid", "Corrupt BMP"); } - for (i=0; i < psize; ++i) { - pal[i][2] = stbi__get8(s); - pal[i][1] = stbi__get8(s); - pal[i][0] = stbi__get8(s); - if (info.hsz != 12) stbi__get8(s); - pal[i][3] = 255; - } - stbi__skip(s, info.offset - info.extra_read - info.hsz - psize * (info.hsz == 12 ? 3 : 4)); - if (info.bpp == 1) width = (s->img_x + 7) >> 3; - else if (info.bpp == 4) width = (s->img_x + 1) >> 1; - else if (info.bpp == 8) width = s->img_x; - else { STBI_FREE(out); return stbi__errpuc("bad bpp", "Corrupt BMP"); } - pad = (-width)&3; - if (info.bpp == 1) { - for (j=0; j < (int) s->img_y; ++j) { - int bit_offset = 7, v = stbi__get8(s); - for (i=0; i < (int) s->img_x; ++i) { - int color = (v>>bit_offset)&0x1; - out[z++] = pal[color][0]; - out[z++] = pal[color][1]; - out[z++] = pal[color][2]; - if (target == 4) out[z++] = 255; - if (i+1 == (int) s->img_x) break; - if((--bit_offset) < 0) { - bit_offset = 7; - v = stbi__get8(s); - } - } - stbi__skip(s, pad); - } - } else { - for (j=0; j < (int) s->img_y; ++j) { - for (i=0; i < (int) s->img_x; i += 2) { - int v=stbi__get8(s),v2=0; - if (info.bpp == 4) { - v2 = v & 15; - v >>= 4; - } - out[z++] = pal[v][0]; - out[z++] = pal[v][1]; - out[z++] = pal[v][2]; - if (target == 4) out[z++] = 255; - if (i+1 == (int) s->img_x) break; - v = (info.bpp == 8) ? stbi__get8(s) : v2; - out[z++] = pal[v][0]; - out[z++] = pal[v][1]; - out[z++] = pal[v][2]; - if (target == 4) out[z++] = 255; - } - stbi__skip(s, pad); - } - } - } else { - int rshift=0,gshift=0,bshift=0,ashift=0,rcount=0,gcount=0,bcount=0,acount=0; - int z = 0; - int easy=0; - stbi__skip(s, info.offset - info.extra_read - info.hsz); - if (info.bpp == 24) width = 3 * s->img_x; - else if (info.bpp == 16) width = 2*s->img_x; - else /* bpp = 32 and pad = 0 */ width=0; - pad = (-width) & 3; - if (info.bpp == 24) { - easy = 1; - } else if (info.bpp == 32) { - if (mb == 0xff && mg == 0xff00 && mr == 0x00ff0000 && ma == 0xff000000) - easy = 2; - } - if (!easy) { - if (!mr || !mg || !mb) { STBI_FREE(out); return stbi__errpuc("bad masks", "Corrupt BMP"); } - // right shift amt to put high bit in position #7 - rshift = stbi__high_bit(mr)-7; rcount = stbi__bitcount(mr); - gshift = stbi__high_bit(mg)-7; gcount = stbi__bitcount(mg); - bshift = stbi__high_bit(mb)-7; bcount = stbi__bitcount(mb); - ashift = stbi__high_bit(ma)-7; acount = stbi__bitcount(ma); - if (rcount > 8 || gcount > 8 || bcount > 8 || acount > 8) { STBI_FREE(out); return stbi__errpuc("bad masks", "Corrupt BMP"); } - } - for (j=0; j < (int) s->img_y; ++j) { - if (easy) { - for (i=0; i < (int) s->img_x; ++i) { - unsigned char a; - out[z+2] = stbi__get8(s); - out[z+1] = stbi__get8(s); - out[z+0] = stbi__get8(s); - z += 3; - a = (easy == 2 ? stbi__get8(s) : 255); - all_a |= a; - if (target == 4) out[z++] = a; - } - } else { - int bpp = info.bpp; - for (i=0; i < (int) s->img_x; ++i) { - stbi__uint32 v = (bpp == 16 ? (stbi__uint32) stbi__get16le(s) : stbi__get32le(s)); - unsigned int a; - out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mr, rshift, rcount)); - out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mg, gshift, gcount)); - out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mb, bshift, bcount)); - a = (ma ? stbi__shiftsigned(v & ma, ashift, acount) : 255); - all_a |= a; - if (target == 4) out[z++] = STBI__BYTECAST(a); - } - } - stbi__skip(s, pad); - } - } - - // if alpha channel is all 0s, replace with all 255s - if (target == 4 && all_a == 0) - for (i=4*s->img_x*s->img_y-1; i >= 0; i -= 4) - out[i] = 255; - - if (flip_vertically) { - stbi_uc t; - for (j=0; j < (int) s->img_y>>1; ++j) { - stbi_uc *p1 = out + j *s->img_x*target; - stbi_uc *p2 = out + (s->img_y-1-j)*s->img_x*target; - for (i=0; i < (int) s->img_x*target; ++i) { - t = p1[i]; p1[i] = p2[i]; p2[i] = t; - } - } - } - - if (req_comp && req_comp != target) { - out = stbi__convert_format(out, target, req_comp, s->img_x, s->img_y); - if (out == NULL) return out; // stbi__convert_format frees input on failure - } - - *x = s->img_x; - *y = s->img_y; - if (comp) *comp = s->img_n; - return out; -} -#endif - -// Targa Truevision - TGA -// by Jonathan Dummer -#ifndef STBI_NO_TGA -// returns STBI_rgb or whatever, 0 on error -static int stbi__tga_get_comp(int bits_per_pixel, int is_grey, int* is_rgb16) -{ - // only RGB or RGBA (incl. 16bit) or grey allowed - if (is_rgb16) *is_rgb16 = 0; - switch(bits_per_pixel) { - case 8: return STBI_grey; - case 16: if(is_grey) return STBI_grey_alpha; - // fallthrough - case 15: if(is_rgb16) *is_rgb16 = 1; - return STBI_rgb; - case 24: // fallthrough - case 32: return bits_per_pixel/8; - default: return 0; - } -} - -static int stbi__tga_info(stbi__context *s, int *x, int *y, int *comp) -{ - int tga_w, tga_h, tga_comp, tga_image_type, tga_bits_per_pixel, tga_colormap_bpp; - int sz, tga_colormap_type; - stbi__get8(s); // discard Offset - tga_colormap_type = stbi__get8(s); // colormap type - if( tga_colormap_type > 1 ) { - stbi__rewind(s); - return 0; // only RGB or indexed allowed - } - tga_image_type = stbi__get8(s); // image type - if ( tga_colormap_type == 1 ) { // colormapped (paletted) image - if (tga_image_type != 1 && tga_image_type != 9) { - stbi__rewind(s); - return 0; - } - stbi__skip(s,4); // skip index of first colormap entry and number of entries - sz = stbi__get8(s); // check bits per palette color entry - if ( (sz != 8) && (sz != 15) && (sz != 16) && (sz != 24) && (sz != 32) ) { - stbi__rewind(s); - return 0; - } - stbi__skip(s,4); // skip image x and y origin - tga_colormap_bpp = sz; - } else { // "normal" image w/o colormap - only RGB or grey allowed, +/- RLE - if ( (tga_image_type != 2) && (tga_image_type != 3) && (tga_image_type != 10) && (tga_image_type != 11) ) { - stbi__rewind(s); - return 0; // only RGB or grey allowed, +/- RLE - } - stbi__skip(s,9); // skip colormap specification and image x/y origin - tga_colormap_bpp = 0; - } - tga_w = stbi__get16le(s); - if( tga_w < 1 ) { - stbi__rewind(s); - return 0; // test width - } - tga_h = stbi__get16le(s); - if( tga_h < 1 ) { - stbi__rewind(s); - return 0; // test height - } - tga_bits_per_pixel = stbi__get8(s); // bits per pixel - stbi__get8(s); // ignore alpha bits - if (tga_colormap_bpp != 0) { - if((tga_bits_per_pixel != 8) && (tga_bits_per_pixel != 16)) { - // when using a colormap, tga_bits_per_pixel is the size of the indexes - // I don't think anything but 8 or 16bit indexes makes sense - stbi__rewind(s); - return 0; - } - tga_comp = stbi__tga_get_comp(tga_colormap_bpp, 0, NULL); - } else { - tga_comp = stbi__tga_get_comp(tga_bits_per_pixel, (tga_image_type == 3) || (tga_image_type == 11), NULL); - } - if(!tga_comp) { - stbi__rewind(s); - return 0; - } - if (x) *x = tga_w; - if (y) *y = tga_h; - if (comp) *comp = tga_comp; - return 1; // seems to have passed everything -} - -static int stbi__tga_test(stbi__context *s) -{ - int res = 0; - int sz, tga_color_type; - stbi__get8(s); // discard Offset - tga_color_type = stbi__get8(s); // color type - if ( tga_color_type > 1 ) goto errorEnd; // only RGB or indexed allowed - sz = stbi__get8(s); // image type - if ( tga_color_type == 1 ) { // colormapped (paletted) image - if (sz != 1 && sz != 9) goto errorEnd; // colortype 1 demands image type 1 or 9 - stbi__skip(s,4); // skip index of first colormap entry and number of entries - sz = stbi__get8(s); // check bits per palette color entry - if ( (sz != 8) && (sz != 15) && (sz != 16) && (sz != 24) && (sz != 32) ) goto errorEnd; - stbi__skip(s,4); // skip image x and y origin - } else { // "normal" image w/o colormap - if ( (sz != 2) && (sz != 3) && (sz != 10) && (sz != 11) ) goto errorEnd; // only RGB or grey allowed, +/- RLE - stbi__skip(s,9); // skip colormap specification and image x/y origin - } - if ( stbi__get16le(s) < 1 ) goto errorEnd; // test width - if ( stbi__get16le(s) < 1 ) goto errorEnd; // test height - sz = stbi__get8(s); // bits per pixel - if ( (tga_color_type == 1) && (sz != 8) && (sz != 16) ) goto errorEnd; // for colormapped images, bpp is size of an index - if ( (sz != 8) && (sz != 15) && (sz != 16) && (sz != 24) && (sz != 32) ) goto errorEnd; - - res = 1; // if we got this far, everything's good and we can return 1 instead of 0 - -errorEnd: - stbi__rewind(s); - return res; -} - -// read 16bit value and convert to 24bit RGB -static void stbi__tga_read_rgb16(stbi__context *s, stbi_uc* out) -{ - stbi__uint16 px = (stbi__uint16)stbi__get16le(s); - stbi__uint16 fiveBitMask = 31; - // we have 3 channels with 5bits each - int r = (px >> 10) & fiveBitMask; - int g = (px >> 5) & fiveBitMask; - int b = px & fiveBitMask; - // Note that this saves the data in RGB(A) order, so it doesn't need to be swapped later - out[0] = (stbi_uc)((r * 255)/31); - out[1] = (stbi_uc)((g * 255)/31); - out[2] = (stbi_uc)((b * 255)/31); - - // some people claim that the most significant bit might be used for alpha - // (possibly if an alpha-bit is set in the "image descriptor byte") - // but that only made 16bit test images completely translucent.. - // so let's treat all 15 and 16bit TGAs as RGB with no alpha. -} - -static void *stbi__tga_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri) -{ - // read in the TGA header stuff - int tga_offset = stbi__get8(s); - int tga_indexed = stbi__get8(s); - int tga_image_type = stbi__get8(s); - int tga_is_RLE = 0; - int tga_palette_start = stbi__get16le(s); - int tga_palette_len = stbi__get16le(s); - int tga_palette_bits = stbi__get8(s); - int tga_x_origin = stbi__get16le(s); - int tga_y_origin = stbi__get16le(s); - int tga_width = stbi__get16le(s); - int tga_height = stbi__get16le(s); - int tga_bits_per_pixel = stbi__get8(s); - int tga_comp, tga_rgb16=0; - int tga_inverted = stbi__get8(s); - // int tga_alpha_bits = tga_inverted & 15; // the 4 lowest bits - unused (useless?) - // image data - unsigned char *tga_data; - unsigned char *tga_palette = NULL; - int i, j; - unsigned char raw_data[4] = {0}; - int RLE_count = 0; - int RLE_repeating = 0; - int read_next_pixel = 1; - STBI_NOTUSED(ri); - STBI_NOTUSED(tga_x_origin); // @TODO - STBI_NOTUSED(tga_y_origin); // @TODO - - if (tga_height > STBI_MAX_DIMENSIONS) return stbi__errpuc("too large","Very large image (corrupt?)"); - if (tga_width > STBI_MAX_DIMENSIONS) return stbi__errpuc("too large","Very large image (corrupt?)"); - - // do a tiny bit of precessing - if ( tga_image_type >= 8 ) - { - tga_image_type -= 8; - tga_is_RLE = 1; - } - tga_inverted = 1 - ((tga_inverted >> 5) & 1); - - // If I'm paletted, then I'll use the number of bits from the palette - if ( tga_indexed ) tga_comp = stbi__tga_get_comp(tga_palette_bits, 0, &tga_rgb16); - else tga_comp = stbi__tga_get_comp(tga_bits_per_pixel, (tga_image_type == 3), &tga_rgb16); - - if(!tga_comp) // shouldn't really happen, stbi__tga_test() should have ensured basic consistency - return stbi__errpuc("bad format", "Can't find out TGA pixelformat"); - - // tga info - *x = tga_width; - *y = tga_height; - if (comp) *comp = tga_comp; - - if (!stbi__mad3sizes_valid(tga_width, tga_height, tga_comp, 0)) - return stbi__errpuc("too large", "Corrupt TGA"); - - tga_data = (unsigned char*)stbi__malloc_mad3(tga_width, tga_height, tga_comp, 0); - if (!tga_data) return stbi__errpuc("outofmem", "Out of memory"); - - // skip to the data's starting position (offset usually = 0) - stbi__skip(s, tga_offset ); - - if ( !tga_indexed && !tga_is_RLE && !tga_rgb16 ) { - for (i=0; i < tga_height; ++i) { - int row = tga_inverted ? tga_height -i - 1 : i; - stbi_uc *tga_row = tga_data + row*tga_width*tga_comp; - stbi__getn(s, tga_row, tga_width * tga_comp); - } - } else { - // do I need to load a palette? - if ( tga_indexed) - { - if (tga_palette_len == 0) { /* you have to have at least one entry! */ - STBI_FREE(tga_data); - return stbi__errpuc("bad palette", "Corrupt TGA"); - } - - // any data to skip? (offset usually = 0) - stbi__skip(s, tga_palette_start ); - // load the palette - tga_palette = (unsigned char*)stbi__malloc_mad2(tga_palette_len, tga_comp, 0); - if (!tga_palette) { - STBI_FREE(tga_data); - return stbi__errpuc("outofmem", "Out of memory"); - } - if (tga_rgb16) { - stbi_uc *pal_entry = tga_palette; - STBI_ASSERT(tga_comp == STBI_rgb); - for (i=0; i < tga_palette_len; ++i) { - stbi__tga_read_rgb16(s, pal_entry); - pal_entry += tga_comp; - } - } else if (!stbi__getn(s, tga_palette, tga_palette_len * tga_comp)) { - STBI_FREE(tga_data); - STBI_FREE(tga_palette); - return stbi__errpuc("bad palette", "Corrupt TGA"); - } - } - // load the data - for (i=0; i < tga_width * tga_height; ++i) - { - // if I'm in RLE mode, do I need to get a RLE stbi__pngchunk? - if ( tga_is_RLE ) - { - if ( RLE_count == 0 ) - { - // yep, get the next byte as a RLE command - int RLE_cmd = stbi__get8(s); - RLE_count = 1 + (RLE_cmd & 127); - RLE_repeating = RLE_cmd >> 7; - read_next_pixel = 1; - } else if ( !RLE_repeating ) - { - read_next_pixel = 1; - } - } else - { - read_next_pixel = 1; - } - // OK, if I need to read a pixel, do it now - if ( read_next_pixel ) - { - // load however much data we did have - if ( tga_indexed ) - { - // read in index, then perform the lookup - int pal_idx = (tga_bits_per_pixel == 8) ? stbi__get8(s) : stbi__get16le(s); - if ( pal_idx >= tga_palette_len ) { - // invalid index - pal_idx = 0; - } - pal_idx *= tga_comp; - for (j = 0; j < tga_comp; ++j) { - raw_data[j] = tga_palette[pal_idx+j]; - } - } else if(tga_rgb16) { - STBI_ASSERT(tga_comp == STBI_rgb); - stbi__tga_read_rgb16(s, raw_data); - } else { - // read in the data raw - for (j = 0; j < tga_comp; ++j) { - raw_data[j] = stbi__get8(s); - } - } - // clear the reading flag for the next pixel - read_next_pixel = 0; - } // end of reading a pixel - - // copy data - for (j = 0; j < tga_comp; ++j) - tga_data[i*tga_comp+j] = raw_data[j]; - - // in case we're in RLE mode, keep counting down - --RLE_count; - } - // do I need to invert the image? - if ( tga_inverted ) - { - for (j = 0; j*2 < tga_height; ++j) - { - int index1 = j * tga_width * tga_comp; - int index2 = (tga_height - 1 - j) * tga_width * tga_comp; - for (i = tga_width * tga_comp; i > 0; --i) - { - unsigned char temp = tga_data[index1]; - tga_data[index1] = tga_data[index2]; - tga_data[index2] = temp; - ++index1; - ++index2; - } - } - } - // clear my palette, if I had one - if ( tga_palette != NULL ) - { - STBI_FREE( tga_palette ); - } - } - - // swap RGB - if the source data was RGB16, it already is in the right order - if (tga_comp >= 3 && !tga_rgb16) - { - unsigned char* tga_pixel = tga_data; - for (i=0; i < tga_width * tga_height; ++i) - { - unsigned char temp = tga_pixel[0]; - tga_pixel[0] = tga_pixel[2]; - tga_pixel[2] = temp; - tga_pixel += tga_comp; - } - } - - // convert to target component count - if (req_comp && req_comp != tga_comp) - tga_data = stbi__convert_format(tga_data, tga_comp, req_comp, tga_width, tga_height); - - // the things I do to get rid of an error message, and yet keep - // Microsoft's C compilers happy... [8^( - tga_palette_start = tga_palette_len = tga_palette_bits = - tga_x_origin = tga_y_origin = 0; - STBI_NOTUSED(tga_palette_start); - // OK, done - return tga_data; -} -#endif - -// ************************************************************************************************* -// Photoshop PSD loader -- PD by Thatcher Ulrich, integration by Nicolas Schulz, tweaked by STB - -#ifndef STBI_NO_PSD -static int stbi__psd_test(stbi__context *s) -{ - int r = (stbi__get32be(s) == 0x38425053); - stbi__rewind(s); - return r; -} - -static int stbi__psd_decode_rle(stbi__context *s, stbi_uc *p, int pixelCount) -{ - int count, nleft, len; - - count = 0; - while ((nleft = pixelCount - count) > 0) { - len = stbi__get8(s); - if (len == 128) { - // No-op. - } else if (len < 128) { - // Copy next len+1 bytes literally. - len++; - if (len > nleft) return 0; // corrupt data - count += len; - while (len) { - *p = stbi__get8(s); - p += 4; - len--; - } - } else if (len > 128) { - stbi_uc val; - // Next -len+1 bytes in the dest are replicated from next source byte. - // (Interpret len as a negative 8-bit int.) - len = 257 - len; - if (len > nleft) return 0; // corrupt data - val = stbi__get8(s); - count += len; - while (len) { - *p = val; - p += 4; - len--; - } - } - } - - return 1; -} - -static void *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri, int bpc) -{ - int pixelCount; - int channelCount, compression; - int channel, i; - int bitdepth; - int w,h; - stbi_uc *out; - STBI_NOTUSED(ri); - - // Check identifier - if (stbi__get32be(s) != 0x38425053) // "8BPS" - return stbi__errpuc("not PSD", "Corrupt PSD image"); - - // Check file type version. - if (stbi__get16be(s) != 1) - return stbi__errpuc("wrong version", "Unsupported version of PSD image"); - - // Skip 6 reserved bytes. - stbi__skip(s, 6 ); - - // Read the number of channels (R, G, B, A, etc). - channelCount = stbi__get16be(s); - if (channelCount < 0 || channelCount > 16) - return stbi__errpuc("wrong channel count", "Unsupported number of channels in PSD image"); - - // Read the rows and columns of the image. - h = stbi__get32be(s); - w = stbi__get32be(s); - - if (h > STBI_MAX_DIMENSIONS) return stbi__errpuc("too large","Very large image (corrupt?)"); - if (w > STBI_MAX_DIMENSIONS) return stbi__errpuc("too large","Very large image (corrupt?)"); - - // Make sure the depth is 8 bits. - bitdepth = stbi__get16be(s); - if (bitdepth != 8 && bitdepth != 16) - return stbi__errpuc("unsupported bit depth", "PSD bit depth is not 8 or 16 bit"); - - // Make sure the color mode is RGB. - // Valid options are: - // 0: Bitmap - // 1: Grayscale - // 2: Indexed color - // 3: RGB color - // 4: CMYK color - // 7: Multichannel - // 8: Duotone - // 9: Lab color - if (stbi__get16be(s) != 3) - return stbi__errpuc("wrong color format", "PSD is not in RGB color format"); - - // Skip the Mode Data. (It's the palette for indexed color; other info for other modes.) - stbi__skip(s,stbi__get32be(s) ); - - // Skip the image resources. (resolution, pen tool paths, etc) - stbi__skip(s, stbi__get32be(s) ); - - // Skip the reserved data. - stbi__skip(s, stbi__get32be(s) ); - - // Find out if the data is compressed. - // Known values: - // 0: no compression - // 1: RLE compressed - compression = stbi__get16be(s); - if (compression > 1) - return stbi__errpuc("bad compression", "PSD has an unknown compression format"); - - // Check size - if (!stbi__mad3sizes_valid(4, w, h, 0)) - return stbi__errpuc("too large", "Corrupt PSD"); - - // Create the destination image. - - if (!compression && bitdepth == 16 && bpc == 16) { - out = (stbi_uc *) stbi__malloc_mad3(8, w, h, 0); - ri->bits_per_channel = 16; - } else - out = (stbi_uc *) stbi__malloc(4 * w*h); - - if (!out) return stbi__errpuc("outofmem", "Out of memory"); - pixelCount = w*h; - - // Initialize the data to zero. - //memset( out, 0, pixelCount * 4 ); - - // Finally, the image data. - if (compression) { - // RLE as used by .PSD and .TIFF - // Loop until you get the number of unpacked bytes you are expecting: - // Read the next source byte into n. - // If n is between 0 and 127 inclusive, copy the next n+1 bytes literally. - // Else if n is between -127 and -1 inclusive, copy the next byte -n+1 times. - // Else if n is 128, noop. - // Endloop - - // The RLE-compressed data is preceded by a 2-byte data count for each row in the data, - // which we're going to just skip. - stbi__skip(s, h * channelCount * 2 ); - - // Read the RLE data by channel. - for (channel = 0; channel < 4; channel++) { - stbi_uc *p; - - p = out+channel; - if (channel >= channelCount) { - // Fill this channel with default data. - for (i = 0; i < pixelCount; i++, p += 4) - *p = (channel == 3 ? 255 : 0); - } else { - // Read the RLE data. - if (!stbi__psd_decode_rle(s, p, pixelCount)) { - STBI_FREE(out); - return stbi__errpuc("corrupt", "bad RLE data"); - } - } - } - - } else { - // We're at the raw image data. It's each channel in order (Red, Green, Blue, Alpha, ...) - // where each channel consists of an 8-bit (or 16-bit) value for each pixel in the image. - - // Read the data by channel. - for (channel = 0; channel < 4; channel++) { - if (channel >= channelCount) { - // Fill this channel with default data. - if (bitdepth == 16 && bpc == 16) { - stbi__uint16 *q = ((stbi__uint16 *) out) + channel; - stbi__uint16 val = channel == 3 ? 65535 : 0; - for (i = 0; i < pixelCount; i++, q += 4) - *q = val; - } else { - stbi_uc *p = out+channel; - stbi_uc val = channel == 3 ? 255 : 0; - for (i = 0; i < pixelCount; i++, p += 4) - *p = val; - } - } else { - if (ri->bits_per_channel == 16) { // output bpc - stbi__uint16 *q = ((stbi__uint16 *) out) + channel; - for (i = 0; i < pixelCount; i++, q += 4) - *q = (stbi__uint16) stbi__get16be(s); - } else { - stbi_uc *p = out+channel; - if (bitdepth == 16) { // input bpc - for (i = 0; i < pixelCount; i++, p += 4) - *p = (stbi_uc) (stbi__get16be(s) >> 8); - } else { - for (i = 0; i < pixelCount; i++, p += 4) - *p = stbi__get8(s); - } - } - } - } - } - - // remove weird white matte from PSD - if (channelCount >= 4) { - if (ri->bits_per_channel == 16) { - for (i=0; i < w*h; ++i) { - stbi__uint16 *pixel = (stbi__uint16 *) out + 4*i; - if (pixel[3] != 0 && pixel[3] != 65535) { - float a = pixel[3] / 65535.0f; - float ra = 1.0f / a; - float inv_a = 65535.0f * (1 - ra); - pixel[0] = (stbi__uint16) (pixel[0]*ra + inv_a); - pixel[1] = (stbi__uint16) (pixel[1]*ra + inv_a); - pixel[2] = (stbi__uint16) (pixel[2]*ra + inv_a); - } - } - } else { - for (i=0; i < w*h; ++i) { - unsigned char *pixel = out + 4*i; - if (pixel[3] != 0 && pixel[3] != 255) { - float a = pixel[3] / 255.0f; - float ra = 1.0f / a; - float inv_a = 255.0f * (1 - ra); - pixel[0] = (unsigned char) (pixel[0]*ra + inv_a); - pixel[1] = (unsigned char) (pixel[1]*ra + inv_a); - pixel[2] = (unsigned char) (pixel[2]*ra + inv_a); - } - } - } - } - - // convert to desired output format - if (req_comp && req_comp != 4) { - if (ri->bits_per_channel == 16) - out = (stbi_uc *) stbi__convert_format16((stbi__uint16 *) out, 4, req_comp, w, h); - else - out = stbi__convert_format(out, 4, req_comp, w, h); - if (out == NULL) return out; // stbi__convert_format frees input on failure - } - - if (comp) *comp = 4; - *y = h; - *x = w; - - return out; -} -#endif - -// ************************************************************************************************* -// Softimage PIC loader -// by Tom Seddon -// -// See http://softimage.wiki.softimage.com/index.php/INFO:_PIC_file_format -// See http://ozviz.wasp.uwa.edu.au/~pbourke/dataformats/softimagepic/ - -#ifndef STBI_NO_PIC -static int stbi__pic_is4(stbi__context *s,const char *str) -{ - int i; - for (i=0; i<4; ++i) - if (stbi__get8(s) != (stbi_uc)str[i]) - return 0; - - return 1; -} - -static int stbi__pic_test_core(stbi__context *s) -{ - int i; - - if (!stbi__pic_is4(s,"\x53\x80\xF6\x34")) - return 0; - - for(i=0;i<84;++i) - stbi__get8(s); - - if (!stbi__pic_is4(s,"PICT")) - return 0; - - return 1; -} - -typedef struct -{ - stbi_uc size,type,channel; -} stbi__pic_packet; - -static stbi_uc *stbi__readval(stbi__context *s, int channel, stbi_uc *dest) -{ - int mask=0x80, i; - - for (i=0; i<4; ++i, mask>>=1) { - if (channel & mask) { - if (stbi__at_eof(s)) return stbi__errpuc("bad file","PIC file too short"); - dest[i]=stbi__get8(s); - } - } - - return dest; -} - -static void stbi__copyval(int channel,stbi_uc *dest,const stbi_uc *src) -{ - int mask=0x80,i; - - for (i=0;i<4; ++i, mask>>=1) - if (channel&mask) - dest[i]=src[i]; -} - -static stbi_uc *stbi__pic_load_core(stbi__context *s,int width,int height,int *comp, stbi_uc *result) -{ - int act_comp=0,num_packets=0,y,chained; - stbi__pic_packet packets[10]; - - // this will (should...) cater for even some bizarre stuff like having data - // for the same channel in multiple packets. - do { - stbi__pic_packet *packet; - - if (num_packets==sizeof(packets)/sizeof(packets[0])) - return stbi__errpuc("bad format","too many packets"); - - packet = &packets[num_packets++]; - - chained = stbi__get8(s); - packet->size = stbi__get8(s); - packet->type = stbi__get8(s); - packet->channel = stbi__get8(s); - - act_comp |= packet->channel; - - if (stbi__at_eof(s)) return stbi__errpuc("bad file","file too short (reading packets)"); - if (packet->size != 8) return stbi__errpuc("bad format","packet isn't 8bpp"); - } while (chained); - - *comp = (act_comp & 0x10 ? 4 : 3); // has alpha channel? - - for(y=0; ytype) { - default: - return stbi__errpuc("bad format","packet has bad compression type"); - - case 0: {//uncompressed - int x; - - for(x=0;xchannel,dest)) - return 0; - break; - } - - case 1://Pure RLE - { - int left=width, i; - - while (left>0) { - stbi_uc count,value[4]; - - count=stbi__get8(s); - if (stbi__at_eof(s)) return stbi__errpuc("bad file","file too short (pure read count)"); - - if (count > left) - count = (stbi_uc) left; - - if (!stbi__readval(s,packet->channel,value)) return 0; - - for(i=0; ichannel,dest,value); - left -= count; - } - } - break; - - case 2: {//Mixed RLE - int left=width; - while (left>0) { - int count = stbi__get8(s), i; - if (stbi__at_eof(s)) return stbi__errpuc("bad file","file too short (mixed read count)"); - - if (count >= 128) { // Repeated - stbi_uc value[4]; - - if (count==128) - count = stbi__get16be(s); - else - count -= 127; - if (count > left) - return stbi__errpuc("bad file","scanline overrun"); - - if (!stbi__readval(s,packet->channel,value)) - return 0; - - for(i=0;ichannel,dest,value); - } else { // Raw - ++count; - if (count>left) return stbi__errpuc("bad file","scanline overrun"); - - for(i=0;ichannel,dest)) - return 0; - } - left-=count; - } - break; - } - } - } - } - - return result; -} - -static void *stbi__pic_load(stbi__context *s,int *px,int *py,int *comp,int req_comp, stbi__result_info *ri) -{ - stbi_uc *result; - int i, x,y, internal_comp; - STBI_NOTUSED(ri); - - if (!comp) comp = &internal_comp; - - for (i=0; i<92; ++i) - stbi__get8(s); - - x = stbi__get16be(s); - y = stbi__get16be(s); - - if (y > STBI_MAX_DIMENSIONS) return stbi__errpuc("too large","Very large image (corrupt?)"); - if (x > STBI_MAX_DIMENSIONS) return stbi__errpuc("too large","Very large image (corrupt?)"); - - if (stbi__at_eof(s)) return stbi__errpuc("bad file","file too short (pic header)"); - if (!stbi__mad3sizes_valid(x, y, 4, 0)) return stbi__errpuc("too large", "PIC image too large to decode"); - - stbi__get32be(s); //skip `ratio' - stbi__get16be(s); //skip `fields' - stbi__get16be(s); //skip `pad' - - // intermediate buffer is RGBA - result = (stbi_uc *) stbi__malloc_mad3(x, y, 4, 0); - if (!result) return stbi__errpuc("outofmem", "Out of memory"); - memset(result, 0xff, x*y*4); - - if (!stbi__pic_load_core(s,x,y,comp, result)) { - STBI_FREE(result); - result=0; - } - *px = x; - *py = y; - if (req_comp == 0) req_comp = *comp; - result=stbi__convert_format(result,4,req_comp,x,y); - - return result; -} - -static int stbi__pic_test(stbi__context *s) -{ - int r = stbi__pic_test_core(s); - stbi__rewind(s); - return r; -} -#endif - -// ************************************************************************************************* -// GIF loader -- public domain by Jean-Marc Lienher -- simplified/shrunk by stb - -#ifndef STBI_NO_GIF -typedef struct -{ - stbi__int16 prefix; - stbi_uc first; - stbi_uc suffix; -} stbi__gif_lzw; - -typedef struct -{ - int w,h; - stbi_uc *out; // output buffer (always 4 components) - stbi_uc *background; // The current "background" as far as a gif is concerned - stbi_uc *history; - int flags, bgindex, ratio, transparent, eflags; - stbi_uc pal[256][4]; - stbi_uc lpal[256][4]; - stbi__gif_lzw codes[8192]; - stbi_uc *color_table; - int parse, step; - int lflags; - int start_x, start_y; - int max_x, max_y; - int cur_x, cur_y; - int line_size; - int delay; -} stbi__gif; - -static int stbi__gif_test_raw(stbi__context *s) -{ - int sz; - if (stbi__get8(s) != 'G' || stbi__get8(s) != 'I' || stbi__get8(s) != 'F' || stbi__get8(s) != '8') return 0; - sz = stbi__get8(s); - if (sz != '9' && sz != '7') return 0; - if (stbi__get8(s) != 'a') return 0; - return 1; -} - -static int stbi__gif_test(stbi__context *s) -{ - int r = stbi__gif_test_raw(s); - stbi__rewind(s); - return r; -} - -static void stbi__gif_parse_colortable(stbi__context *s, stbi_uc pal[256][4], int num_entries, int transp) -{ - int i; - for (i=0; i < num_entries; ++i) { - pal[i][2] = stbi__get8(s); - pal[i][1] = stbi__get8(s); - pal[i][0] = stbi__get8(s); - pal[i][3] = transp == i ? 0 : 255; - } -} - -static int stbi__gif_header(stbi__context *s, stbi__gif *g, int *comp, int is_info) -{ - stbi_uc version; - if (stbi__get8(s) != 'G' || stbi__get8(s) != 'I' || stbi__get8(s) != 'F' || stbi__get8(s) != '8') - return stbi__err("not GIF", "Corrupt GIF"); - - version = stbi__get8(s); - if (version != '7' && version != '9') return stbi__err("not GIF", "Corrupt GIF"); - if (stbi__get8(s) != 'a') return stbi__err("not GIF", "Corrupt GIF"); - - stbi__g_failure_reason = ""; - g->w = stbi__get16le(s); - g->h = stbi__get16le(s); - g->flags = stbi__get8(s); - g->bgindex = stbi__get8(s); - g->ratio = stbi__get8(s); - g->transparent = -1; - - if (g->w > STBI_MAX_DIMENSIONS) return stbi__err("too large","Very large image (corrupt?)"); - if (g->h > STBI_MAX_DIMENSIONS) return stbi__err("too large","Very large image (corrupt?)"); - - if (comp != 0) *comp = 4; // can't actually tell whether it's 3 or 4 until we parse the comments - - if (is_info) return 1; - - if (g->flags & 0x80) - stbi__gif_parse_colortable(s,g->pal, 2 << (g->flags & 7), -1); - - return 1; -} - -static int stbi__gif_info_raw(stbi__context *s, int *x, int *y, int *comp) -{ - stbi__gif* g = (stbi__gif*) stbi__malloc(sizeof(stbi__gif)); - if (!g) return stbi__err("outofmem", "Out of memory"); - if (!stbi__gif_header(s, g, comp, 1)) { - STBI_FREE(g); - stbi__rewind( s ); - return 0; - } - if (x) *x = g->w; - if (y) *y = g->h; - STBI_FREE(g); - return 1; -} - -static void stbi__out_gif_code(stbi__gif *g, stbi__uint16 code) -{ - stbi_uc *p, *c; - int idx; - - // recurse to decode the prefixes, since the linked-list is backwards, - // and working backwards through an interleaved image would be nasty - if (g->codes[code].prefix >= 0) - stbi__out_gif_code(g, g->codes[code].prefix); - - if (g->cur_y >= g->max_y) return; - - idx = g->cur_x + g->cur_y; - p = &g->out[idx]; - g->history[idx / 4] = 1; - - c = &g->color_table[g->codes[code].suffix * 4]; - if (c[3] > 128) { // don't render transparent pixels; - p[0] = c[2]; - p[1] = c[1]; - p[2] = c[0]; - p[3] = c[3]; - } - g->cur_x += 4; - - if (g->cur_x >= g->max_x) { - g->cur_x = g->start_x; - g->cur_y += g->step; - - while (g->cur_y >= g->max_y && g->parse > 0) { - g->step = (1 << g->parse) * g->line_size; - g->cur_y = g->start_y + (g->step >> 1); - --g->parse; - } - } -} - -static stbi_uc *stbi__process_gif_raster(stbi__context *s, stbi__gif *g) -{ - stbi_uc lzw_cs; - stbi__int32 len, init_code; - stbi__uint32 first; - stbi__int32 codesize, codemask, avail, oldcode, bits, valid_bits, clear; - stbi__gif_lzw *p; - - lzw_cs = stbi__get8(s); - if (lzw_cs > 12) return NULL; - clear = 1 << lzw_cs; - first = 1; - codesize = lzw_cs + 1; - codemask = (1 << codesize) - 1; - bits = 0; - valid_bits = 0; - for (init_code = 0; init_code < clear; init_code++) { - g->codes[init_code].prefix = -1; - g->codes[init_code].first = (stbi_uc) init_code; - g->codes[init_code].suffix = (stbi_uc) init_code; - } - - // support no starting clear code - avail = clear+2; - oldcode = -1; - - len = 0; - for(;;) { - if (valid_bits < codesize) { - if (len == 0) { - len = stbi__get8(s); // start new block - if (len == 0) - return g->out; - } - --len; - bits |= (stbi__int32) stbi__get8(s) << valid_bits; - valid_bits += 8; - } else { - stbi__int32 code = bits & codemask; - bits >>= codesize; - valid_bits -= codesize; - // @OPTIMIZE: is there some way we can accelerate the non-clear path? - if (code == clear) { // clear code - codesize = lzw_cs + 1; - codemask = (1 << codesize) - 1; - avail = clear + 2; - oldcode = -1; - first = 0; - } else if (code == clear + 1) { // end of stream code - stbi__skip(s, len); - while ((len = stbi__get8(s)) > 0) - stbi__skip(s,len); - return g->out; - } else if (code <= avail) { - if (first) { - return stbi__errpuc("no clear code", "Corrupt GIF"); - } - - if (oldcode >= 0) { - p = &g->codes[avail++]; - if (avail > 8192) { - return stbi__errpuc("too many codes", "Corrupt GIF"); - } - - p->prefix = (stbi__int16) oldcode; - p->first = g->codes[oldcode].first; - p->suffix = (code == avail) ? p->first : g->codes[code].first; - } else if (code == avail) - return stbi__errpuc("illegal code in raster", "Corrupt GIF"); - - stbi__out_gif_code(g, (stbi__uint16) code); - - if ((avail & codemask) == 0 && avail <= 0x0FFF) { - codesize++; - codemask = (1 << codesize) - 1; - } - - oldcode = code; - } else { - return stbi__errpuc("illegal code in raster", "Corrupt GIF"); - } - } - } -} - -// this function is designed to support animated gifs, although stb_image doesn't support it -// two back is the image from two frames ago, used for a very specific disposal format -static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, int req_comp, stbi_uc *two_back) -{ - int dispose; - int first_frame; - int pi; - int pcount; - STBI_NOTUSED(req_comp); - - // on first frame, any non-written pixels get the background colour (non-transparent) - first_frame = 0; - if (g->out == 0) { - if (!stbi__gif_header(s, g, comp,0)) return 0; // stbi__g_failure_reason set by stbi__gif_header - if (!stbi__mad3sizes_valid(4, g->w, g->h, 0)) - return stbi__errpuc("too large", "GIF image is too large"); - pcount = g->w * g->h; - g->out = (stbi_uc *) stbi__malloc(4 * pcount); - g->background = (stbi_uc *) stbi__malloc(4 * pcount); - g->history = (stbi_uc *) stbi__malloc(pcount); - if (!g->out || !g->background || !g->history) - return stbi__errpuc("outofmem", "Out of memory"); - - // image is treated as "transparent" at the start - ie, nothing overwrites the current background; - // background colour is only used for pixels that are not rendered first frame, after that "background" - // color refers to the color that was there the previous frame. - memset(g->out, 0x00, 4 * pcount); - memset(g->background, 0x00, 4 * pcount); // state of the background (starts transparent) - memset(g->history, 0x00, pcount); // pixels that were affected previous frame - first_frame = 1; - } else { - // second frame - how do we dispose of the previous one? - dispose = (g->eflags & 0x1C) >> 2; - pcount = g->w * g->h; - - if ((dispose == 3) && (two_back == 0)) { - dispose = 2; // if I don't have an image to revert back to, default to the old background - } - - if (dispose == 3) { // use previous graphic - for (pi = 0; pi < pcount; ++pi) { - if (g->history[pi]) { - memcpy( &g->out[pi * 4], &two_back[pi * 4], 4 ); - } - } - } else if (dispose == 2) { - // restore what was changed last frame to background before that frame; - for (pi = 0; pi < pcount; ++pi) { - if (g->history[pi]) { - memcpy( &g->out[pi * 4], &g->background[pi * 4], 4 ); - } - } - } else { - // This is a non-disposal case eithe way, so just - // leave the pixels as is, and they will become the new background - // 1: do not dispose - // 0: not specified. - } - - // background is what out is after the undoing of the previou frame; - memcpy( g->background, g->out, 4 * g->w * g->h ); - } - - // clear my history; - memset( g->history, 0x00, g->w * g->h ); // pixels that were affected previous frame - - for (;;) { - int tag = stbi__get8(s); - switch (tag) { - case 0x2C: /* Image Descriptor */ - { - stbi__int32 x, y, w, h; - stbi_uc *o; - - x = stbi__get16le(s); - y = stbi__get16le(s); - w = stbi__get16le(s); - h = stbi__get16le(s); - if (((x + w) > (g->w)) || ((y + h) > (g->h))) - return stbi__errpuc("bad Image Descriptor", "Corrupt GIF"); - - g->line_size = g->w * 4; - g->start_x = x * 4; - g->start_y = y * g->line_size; - g->max_x = g->start_x + w * 4; - g->max_y = g->start_y + h * g->line_size; - g->cur_x = g->start_x; - g->cur_y = g->start_y; - - // if the width of the specified rectangle is 0, that means - // we may not see *any* pixels or the image is malformed; - // to make sure this is caught, move the current y down to - // max_y (which is what out_gif_code checks). - if (w == 0) - g->cur_y = g->max_y; - - g->lflags = stbi__get8(s); - - if (g->lflags & 0x40) { - g->step = 8 * g->line_size; // first interlaced spacing - g->parse = 3; - } else { - g->step = g->line_size; - g->parse = 0; - } - - if (g->lflags & 0x80) { - stbi__gif_parse_colortable(s,g->lpal, 2 << (g->lflags & 7), g->eflags & 0x01 ? g->transparent : -1); - g->color_table = (stbi_uc *) g->lpal; - } else if (g->flags & 0x80) { - g->color_table = (stbi_uc *) g->pal; - } else - return stbi__errpuc("missing color table", "Corrupt GIF"); - - o = stbi__process_gif_raster(s, g); - if (!o) return NULL; - - // if this was the first frame, - pcount = g->w * g->h; - if (first_frame && (g->bgindex > 0)) { - // if first frame, any pixel not drawn to gets the background color - for (pi = 0; pi < pcount; ++pi) { - if (g->history[pi] == 0) { - g->pal[g->bgindex][3] = 255; // just in case it was made transparent, undo that; It will be reset next frame if need be; - memcpy( &g->out[pi * 4], &g->pal[g->bgindex], 4 ); - } - } - } - - return o; - } - - case 0x21: // Comment Extension. - { - int len; - int ext = stbi__get8(s); - if (ext == 0xF9) { // Graphic Control Extension. - len = stbi__get8(s); - if (len == 4) { - g->eflags = stbi__get8(s); - g->delay = 10 * stbi__get16le(s); // delay - 1/100th of a second, saving as 1/1000ths. - - // unset old transparent - if (g->transparent >= 0) { - g->pal[g->transparent][3] = 255; - } - if (g->eflags & 0x01) { - g->transparent = stbi__get8(s); - if (g->transparent >= 0) { - g->pal[g->transparent][3] = 0; - } - } else { - // don't need transparent - stbi__skip(s, 1); - g->transparent = -1; - } - } else { - stbi__skip(s, len); - break; - } - } - while ((len = stbi__get8(s)) != 0) { - stbi__skip(s, len); - } - break; - } - - case 0x3B: // gif stream termination code - return (stbi_uc *) s; // using '1' causes warning on some compilers - - default: - return stbi__errpuc("unknown code", "Corrupt GIF"); - } - } -} - -static void *stbi__load_gif_main_outofmem(stbi__gif *g, stbi_uc *out, int **delays) -{ - STBI_FREE(g->out); - STBI_FREE(g->history); - STBI_FREE(g->background); - - if (out) STBI_FREE(out); - if (delays && *delays) STBI_FREE(*delays); - return stbi__errpuc("outofmem", "Out of memory"); -} - -static void *stbi__load_gif_main(stbi__context *s, int **delays, int *x, int *y, int *z, int *comp, int req_comp) -{ - if (stbi__gif_test(s)) { - int layers = 0; - stbi_uc *u = 0; - stbi_uc *out = 0; - stbi_uc *two_back = 0; - stbi__gif g; - int stride; - int out_size = 0; - int delays_size = 0; - - STBI_NOTUSED(out_size); - STBI_NOTUSED(delays_size); - - memset(&g, 0, sizeof(g)); - if (delays) { - *delays = 0; - } - - do { - u = stbi__gif_load_next(s, &g, comp, req_comp, two_back); - if (u == (stbi_uc *) s) u = 0; // end of animated gif marker - - if (u) { - *x = g.w; - *y = g.h; - ++layers; - stride = g.w * g.h * 4; - - if (out) { - void *tmp = (stbi_uc*) STBI_REALLOC_SIZED( out, out_size, layers * stride ); - if (!tmp) - return stbi__load_gif_main_outofmem(&g, out, delays); - else { - out = (stbi_uc*) tmp; - out_size = layers * stride; - } - - if (delays) { - int *new_delays = (int*) STBI_REALLOC_SIZED( *delays, delays_size, sizeof(int) * layers ); - if (!new_delays) - return stbi__load_gif_main_outofmem(&g, out, delays); - *delays = new_delays; - delays_size = layers * sizeof(int); - } - } else { - out = (stbi_uc*)stbi__malloc( layers * stride ); - if (!out) - return stbi__load_gif_main_outofmem(&g, out, delays); - out_size = layers * stride; - if (delays) { - *delays = (int*) stbi__malloc( layers * sizeof(int) ); - if (!*delays) - return stbi__load_gif_main_outofmem(&g, out, delays); - delays_size = layers * sizeof(int); - } - } - memcpy( out + ((layers - 1) * stride), u, stride ); - if (layers >= 2) { - two_back = out - 2 * stride; - } - - if (delays) { - (*delays)[layers - 1U] = g.delay; - } - } - } while (u != 0); - - // free temp buffer; - STBI_FREE(g.out); - STBI_FREE(g.history); - STBI_FREE(g.background); - - // do the final conversion after loading everything; - if (req_comp && req_comp != 4) - out = stbi__convert_format(out, 4, req_comp, layers * g.w, g.h); - - *z = layers; - return out; - } else { - return stbi__errpuc("not GIF", "Image was not as a gif type."); - } -} - -static void *stbi__gif_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri) -{ - stbi_uc *u = 0; - stbi__gif g; - memset(&g, 0, sizeof(g)); - STBI_NOTUSED(ri); - - u = stbi__gif_load_next(s, &g, comp, req_comp, 0); - if (u == (stbi_uc *) s) u = 0; // end of animated gif marker - if (u) { - *x = g.w; - *y = g.h; - - // moved conversion to after successful load so that the same - // can be done for multiple frames. - if (req_comp && req_comp != 4) - u = stbi__convert_format(u, 4, req_comp, g.w, g.h); - } else if (g.out) { - // if there was an error and we allocated an image buffer, free it! - STBI_FREE(g.out); - } - - // free buffers needed for multiple frame loading; - STBI_FREE(g.history); - STBI_FREE(g.background); - - return u; -} - -static int stbi__gif_info(stbi__context *s, int *x, int *y, int *comp) -{ - return stbi__gif_info_raw(s,x,y,comp); -} -#endif - -// ************************************************************************************************* -// Radiance RGBE HDR loader -// originally by Nicolas Schulz -#ifndef STBI_NO_HDR -static int stbi__hdr_test_core(stbi__context *s, const char *signature) -{ - int i; - for (i=0; signature[i]; ++i) - if (stbi__get8(s) != signature[i]) - return 0; - stbi__rewind(s); - return 1; -} - -static int stbi__hdr_test(stbi__context* s) -{ - int r = stbi__hdr_test_core(s, "#?RADIANCE\n"); - stbi__rewind(s); - if(!r) { - r = stbi__hdr_test_core(s, "#?RGBE\n"); - stbi__rewind(s); - } - return r; -} - -#define STBI__HDR_BUFLEN 1024 -static char *stbi__hdr_gettoken(stbi__context *z, char *buffer) -{ - int len=0; - char c = '\0'; - - c = (char) stbi__get8(z); - - while (!stbi__at_eof(z) && c != '\n') { - buffer[len++] = c; - if (len == STBI__HDR_BUFLEN-1) { - // flush to end of line - while (!stbi__at_eof(z) && stbi__get8(z) != '\n') - ; - break; - } - c = (char) stbi__get8(z); - } - - buffer[len] = 0; - return buffer; -} - -static void stbi__hdr_convert(float *output, stbi_uc *input, int req_comp) -{ - if ( input[3] != 0 ) { - float f1; - // Exponent - f1 = (float) ldexp(1.0f, input[3] - (int)(128 + 8)); - if (req_comp <= 2) - output[0] = (input[0] + input[1] + input[2]) * f1 / 3; - else { - output[0] = input[0] * f1; - output[1] = input[1] * f1; - output[2] = input[2] * f1; - } - if (req_comp == 2) output[1] = 1; - if (req_comp == 4) output[3] = 1; - } else { - switch (req_comp) { - case 4: output[3] = 1; /* fallthrough */ - case 3: output[0] = output[1] = output[2] = 0; - break; - case 2: output[1] = 1; /* fallthrough */ - case 1: output[0] = 0; - break; - } - } -} - -static float *stbi__hdr_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri) -{ - char buffer[STBI__HDR_BUFLEN]; - char *token; - int valid = 0; - int width, height; - stbi_uc *scanline; - float *hdr_data; - int len; - unsigned char count, value; - int i, j, k, c1,c2, z; - const char *headerToken; - STBI_NOTUSED(ri); - - // Check identifier - headerToken = stbi__hdr_gettoken(s,buffer); - if (strcmp(headerToken, "#?RADIANCE") != 0 && strcmp(headerToken, "#?RGBE") != 0) - return stbi__errpf("not HDR", "Corrupt HDR image"); - - // Parse header - for(;;) { - token = stbi__hdr_gettoken(s,buffer); - if (token[0] == 0) break; - if (strcmp(token, "FORMAT=32-bit_rle_rgbe") == 0) valid = 1; - } - - if (!valid) return stbi__errpf("unsupported format", "Unsupported HDR format"); - - // Parse width and height - // can't use sscanf() if we're not using stdio! - token = stbi__hdr_gettoken(s,buffer); - if (strncmp(token, "-Y ", 3)) return stbi__errpf("unsupported data layout", "Unsupported HDR format"); - token += 3; - height = (int) strtol(token, &token, 10); - while (*token == ' ') ++token; - if (strncmp(token, "+X ", 3)) return stbi__errpf("unsupported data layout", "Unsupported HDR format"); - token += 3; - width = (int) strtol(token, NULL, 10); - - if (height > STBI_MAX_DIMENSIONS) return stbi__errpf("too large","Very large image (corrupt?)"); - if (width > STBI_MAX_DIMENSIONS) return stbi__errpf("too large","Very large image (corrupt?)"); - - *x = width; - *y = height; - - if (comp) *comp = 3; - if (req_comp == 0) req_comp = 3; - - if (!stbi__mad4sizes_valid(width, height, req_comp, sizeof(float), 0)) - return stbi__errpf("too large", "HDR image is too large"); - - // Read data - hdr_data = (float *) stbi__malloc_mad4(width, height, req_comp, sizeof(float), 0); - if (!hdr_data) - return stbi__errpf("outofmem", "Out of memory"); - - // Load image data - // image data is stored as some number of sca - if ( width < 8 || width >= 32768) { - // Read flat data - for (j=0; j < height; ++j) { - for (i=0; i < width; ++i) { - stbi_uc rgbe[4]; - main_decode_loop: - stbi__getn(s, rgbe, 4); - stbi__hdr_convert(hdr_data + j * width * req_comp + i * req_comp, rgbe, req_comp); - } - } - } else { - // Read RLE-encoded data - scanline = NULL; - - for (j = 0; j < height; ++j) { - c1 = stbi__get8(s); - c2 = stbi__get8(s); - len = stbi__get8(s); - if (c1 != 2 || c2 != 2 || (len & 0x80)) { - // not run-length encoded, so we have to actually use THIS data as a decoded - // pixel (note this can't be a valid pixel--one of RGB must be >= 128) - stbi_uc rgbe[4]; - rgbe[0] = (stbi_uc) c1; - rgbe[1] = (stbi_uc) c2; - rgbe[2] = (stbi_uc) len; - rgbe[3] = (stbi_uc) stbi__get8(s); - stbi__hdr_convert(hdr_data, rgbe, req_comp); - i = 1; - j = 0; - STBI_FREE(scanline); - goto main_decode_loop; // yes, this makes no sense - } - len <<= 8; - len |= stbi__get8(s); - if (len != width) { STBI_FREE(hdr_data); STBI_FREE(scanline); return stbi__errpf("invalid decoded scanline length", "corrupt HDR"); } - if (scanline == NULL) { - scanline = (stbi_uc *) stbi__malloc_mad2(width, 4, 0); - if (!scanline) { - STBI_FREE(hdr_data); - return stbi__errpf("outofmem", "Out of memory"); - } - } - - for (k = 0; k < 4; ++k) { - int nleft; - i = 0; - while ((nleft = width - i) > 0) { - count = stbi__get8(s); - if (count > 128) { - // Run - value = stbi__get8(s); - count -= 128; - if ((count == 0) || (count > nleft)) { STBI_FREE(hdr_data); STBI_FREE(scanline); return stbi__errpf("corrupt", "bad RLE data in HDR"); } - for (z = 0; z < count; ++z) - scanline[i++ * 4 + k] = value; - } else { - // Dump - if ((count == 0) || (count > nleft)) { STBI_FREE(hdr_data); STBI_FREE(scanline); return stbi__errpf("corrupt", "bad RLE data in HDR"); } - for (z = 0; z < count; ++z) - scanline[i++ * 4 + k] = stbi__get8(s); - } - } - } - for (i=0; i < width; ++i) - stbi__hdr_convert(hdr_data+(j*width + i)*req_comp, scanline + i*4, req_comp); - } - if (scanline) - STBI_FREE(scanline); - } - - return hdr_data; -} - -static int stbi__hdr_info(stbi__context *s, int *x, int *y, int *comp) -{ - char buffer[STBI__HDR_BUFLEN]; - char *token; - int valid = 0; - int dummy; - - if (!x) x = &dummy; - if (!y) y = &dummy; - if (!comp) comp = &dummy; - - if (stbi__hdr_test(s) == 0) { - stbi__rewind( s ); - return 0; - } - - for(;;) { - token = stbi__hdr_gettoken(s,buffer); - if (token[0] == 0) break; - if (strcmp(token, "FORMAT=32-bit_rle_rgbe") == 0) valid = 1; - } - - if (!valid) { - stbi__rewind( s ); - return 0; - } - token = stbi__hdr_gettoken(s,buffer); - if (strncmp(token, "-Y ", 3)) { - stbi__rewind( s ); - return 0; - } - token += 3; - *y = (int) strtol(token, &token, 10); - while (*token == ' ') ++token; - if (strncmp(token, "+X ", 3)) { - stbi__rewind( s ); - return 0; - } - token += 3; - *x = (int) strtol(token, NULL, 10); - *comp = 3; - return 1; -} -#endif // STBI_NO_HDR - -#ifndef STBI_NO_BMP -static int stbi__bmp_info(stbi__context *s, int *x, int *y, int *comp) -{ - void *p; - stbi__bmp_data info; - - info.all_a = 255; - p = stbi__bmp_parse_header(s, &info); - if (p == NULL) { - stbi__rewind( s ); - return 0; - } - if (x) *x = s->img_x; - if (y) *y = s->img_y; - if (comp) { - if (info.bpp == 24 && info.ma == 0xff000000) - *comp = 3; - else - *comp = info.ma ? 4 : 3; - } - return 1; -} -#endif - -#ifndef STBI_NO_PSD -static int stbi__psd_info(stbi__context *s, int *x, int *y, int *comp) -{ - int channelCount, dummy, depth; - if (!x) x = &dummy; - if (!y) y = &dummy; - if (!comp) comp = &dummy; - if (stbi__get32be(s) != 0x38425053) { - stbi__rewind( s ); - return 0; - } - if (stbi__get16be(s) != 1) { - stbi__rewind( s ); - return 0; - } - stbi__skip(s, 6); - channelCount = stbi__get16be(s); - if (channelCount < 0 || channelCount > 16) { - stbi__rewind( s ); - return 0; - } - *y = stbi__get32be(s); - *x = stbi__get32be(s); - depth = stbi__get16be(s); - if (depth != 8 && depth != 16) { - stbi__rewind( s ); - return 0; - } - if (stbi__get16be(s) != 3) { - stbi__rewind( s ); - return 0; - } - *comp = 4; - return 1; -} - -static int stbi__psd_is16(stbi__context *s) -{ - int channelCount, depth; - if (stbi__get32be(s) != 0x38425053) { - stbi__rewind( s ); - return 0; - } - if (stbi__get16be(s) != 1) { - stbi__rewind( s ); - return 0; - } - stbi__skip(s, 6); - channelCount = stbi__get16be(s); - if (channelCount < 0 || channelCount > 16) { - stbi__rewind( s ); - return 0; - } - STBI_NOTUSED(stbi__get32be(s)); - STBI_NOTUSED(stbi__get32be(s)); - depth = stbi__get16be(s); - if (depth != 16) { - stbi__rewind( s ); - return 0; - } - return 1; -} -#endif - -#ifndef STBI_NO_PIC -static int stbi__pic_info(stbi__context *s, int *x, int *y, int *comp) -{ - int act_comp=0,num_packets=0,chained,dummy; - stbi__pic_packet packets[10]; - - if (!x) x = &dummy; - if (!y) y = &dummy; - if (!comp) comp = &dummy; - - if (!stbi__pic_is4(s,"\x53\x80\xF6\x34")) { - stbi__rewind(s); - return 0; - } - - stbi__skip(s, 88); - - *x = stbi__get16be(s); - *y = stbi__get16be(s); - if (stbi__at_eof(s)) { - stbi__rewind( s); - return 0; - } - if ( (*x) != 0 && (1 << 28) / (*x) < (*y)) { - stbi__rewind( s ); - return 0; - } - - stbi__skip(s, 8); - - do { - stbi__pic_packet *packet; - - if (num_packets==sizeof(packets)/sizeof(packets[0])) - return 0; - - packet = &packets[num_packets++]; - chained = stbi__get8(s); - packet->size = stbi__get8(s); - packet->type = stbi__get8(s); - packet->channel = stbi__get8(s); - act_comp |= packet->channel; - - if (stbi__at_eof(s)) { - stbi__rewind( s ); - return 0; - } - if (packet->size != 8) { - stbi__rewind( s ); - return 0; - } - } while (chained); - - *comp = (act_comp & 0x10 ? 4 : 3); - - return 1; -} -#endif - -// ************************************************************************************************* -// Portable Gray Map and Portable Pixel Map loader -// by Ken Miller -// -// PGM: http://netpbm.sourceforge.net/doc/pgm.html -// PPM: http://netpbm.sourceforge.net/doc/ppm.html -// -// Known limitations: -// Does not support comments in the header section -// Does not support ASCII image data (formats P2 and P3) - -#ifndef STBI_NO_PNM - -static int stbi__pnm_test(stbi__context *s) -{ - char p, t; - p = (char) stbi__get8(s); - t = (char) stbi__get8(s); - if (p != 'P' || (t != '5' && t != '6')) { - stbi__rewind( s ); - return 0; - } - return 1; -} - -static void *stbi__pnm_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri) -{ - stbi_uc *out; - STBI_NOTUSED(ri); - - ri->bits_per_channel = stbi__pnm_info(s, (int *)&s->img_x, (int *)&s->img_y, (int *)&s->img_n); - if (ri->bits_per_channel == 0) - return 0; - - if (s->img_y > STBI_MAX_DIMENSIONS) return stbi__errpuc("too large","Very large image (corrupt?)"); - if (s->img_x > STBI_MAX_DIMENSIONS) return stbi__errpuc("too large","Very large image (corrupt?)"); - - *x = s->img_x; - *y = s->img_y; - if (comp) *comp = s->img_n; - - if (!stbi__mad4sizes_valid(s->img_n, s->img_x, s->img_y, ri->bits_per_channel / 8, 0)) - return stbi__errpuc("too large", "PNM too large"); - - out = (stbi_uc *) stbi__malloc_mad4(s->img_n, s->img_x, s->img_y, ri->bits_per_channel / 8, 0); - if (!out) return stbi__errpuc("outofmem", "Out of memory"); - if (!stbi__getn(s, out, s->img_n * s->img_x * s->img_y * (ri->bits_per_channel / 8))) { - STBI_FREE(out); - return stbi__errpuc("bad PNM", "PNM file truncated"); - } - - if (req_comp && req_comp != s->img_n) { - if (ri->bits_per_channel == 16) { - out = (stbi_uc *) stbi__convert_format16((stbi__uint16 *) out, s->img_n, req_comp, s->img_x, s->img_y); - } else { - out = stbi__convert_format(out, s->img_n, req_comp, s->img_x, s->img_y); - } - if (out == NULL) return out; // stbi__convert_format frees input on failure - } - return out; -} - -static int stbi__pnm_isspace(char c) -{ - return c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r'; -} - -static void stbi__pnm_skip_whitespace(stbi__context *s, char *c) -{ - for (;;) { - while (!stbi__at_eof(s) && stbi__pnm_isspace(*c)) - *c = (char) stbi__get8(s); - - if (stbi__at_eof(s) || *c != '#') - break; - - while (!stbi__at_eof(s) && *c != '\n' && *c != '\r' ) - *c = (char) stbi__get8(s); - } -} - -static int stbi__pnm_isdigit(char c) -{ - return c >= '0' && c <= '9'; -} - -static int stbi__pnm_getinteger(stbi__context *s, char *c) -{ - int value = 0; - - while (!stbi__at_eof(s) && stbi__pnm_isdigit(*c)) { - value = value*10 + (*c - '0'); - *c = (char) stbi__get8(s); - if((value > 214748364) || (value == 214748364 && *c > '7')) - return stbi__err("integer parse overflow", "Parsing an integer in the PPM header overflowed a 32-bit int"); - } - - return value; -} - -static int stbi__pnm_info(stbi__context *s, int *x, int *y, int *comp) -{ - int maxv, dummy; - char c, p, t; - - if (!x) x = &dummy; - if (!y) y = &dummy; - if (!comp) comp = &dummy; - - stbi__rewind(s); - - // Get identifier - p = (char) stbi__get8(s); - t = (char) stbi__get8(s); - if (p != 'P' || (t != '5' && t != '6')) { - stbi__rewind(s); - return 0; - } - - *comp = (t == '6') ? 3 : 1; // '5' is 1-component .pgm; '6' is 3-component .ppm - - c = (char) stbi__get8(s); - stbi__pnm_skip_whitespace(s, &c); - - *x = stbi__pnm_getinteger(s, &c); // read width - if(*x == 0) - return stbi__err("invalid width", "PPM image header had zero or overflowing width"); - stbi__pnm_skip_whitespace(s, &c); - - *y = stbi__pnm_getinteger(s, &c); // read height - if (*y == 0) - return stbi__err("invalid width", "PPM image header had zero or overflowing width"); - stbi__pnm_skip_whitespace(s, &c); - - maxv = stbi__pnm_getinteger(s, &c); // read max value - if (maxv > 65535) - return stbi__err("max value > 65535", "PPM image supports only 8-bit and 16-bit images"); - else if (maxv > 255) - return 16; - else - return 8; -} - -static int stbi__pnm_is16(stbi__context *s) -{ - if (stbi__pnm_info(s, NULL, NULL, NULL) == 16) - return 1; - return 0; -} -#endif - -static int stbi__info_main(stbi__context *s, int *x, int *y, int *comp) -{ - #ifndef STBI_NO_JPEG - if (stbi__jpeg_info(s, x, y, comp)) return 1; - #endif - - #ifndef STBI_NO_PNG - if (stbi__png_info(s, x, y, comp)) return 1; - #endif - - #ifndef STBI_NO_GIF - if (stbi__gif_info(s, x, y, comp)) return 1; - #endif - - #ifndef STBI_NO_BMP - if (stbi__bmp_info(s, x, y, comp)) return 1; - #endif - - #ifndef STBI_NO_PSD - if (stbi__psd_info(s, x, y, comp)) return 1; - #endif - - #ifndef STBI_NO_PIC - if (stbi__pic_info(s, x, y, comp)) return 1; - #endif - - #ifndef STBI_NO_PNM - if (stbi__pnm_info(s, x, y, comp)) return 1; - #endif - - #ifndef STBI_NO_HDR - if (stbi__hdr_info(s, x, y, comp)) return 1; - #endif - - // test tga last because it's a crappy test! - #ifndef STBI_NO_TGA - if (stbi__tga_info(s, x, y, comp)) - return 1; - #endif - return stbi__err("unknown image type", "Image not of any known type, or corrupt"); -} - -static int stbi__is_16_main(stbi__context *s) -{ - #ifndef STBI_NO_PNG - if (stbi__png_is16(s)) return 1; - #endif - - #ifndef STBI_NO_PSD - if (stbi__psd_is16(s)) return 1; - #endif - - #ifndef STBI_NO_PNM - if (stbi__pnm_is16(s)) return 1; - #endif - return 0; -} - -#ifndef STBI_NO_STDIO -STBIDEF int stbi_info(char const *filename, int *x, int *y, int *comp) -{ - FILE *f = stbi__fopen(filename, "rb"); - int result; - if (!f) return stbi__err("can't fopen", "Unable to open file"); - result = stbi_info_from_file(f, x, y, comp); - fclose(f); - return result; -} - -STBIDEF int stbi_info_from_file(FILE *f, int *x, int *y, int *comp) -{ - int r; - stbi__context s; - long pos = ftell(f); - stbi__start_file(&s, f); - r = stbi__info_main(&s,x,y,comp); - fseek(f,pos,SEEK_SET); - return r; -} - -STBIDEF int stbi_is_16_bit(char const *filename) -{ - FILE *f = stbi__fopen(filename, "rb"); - int result; - if (!f) return stbi__err("can't fopen", "Unable to open file"); - result = stbi_is_16_bit_from_file(f); - fclose(f); - return result; -} - -STBIDEF int stbi_is_16_bit_from_file(FILE *f) -{ - int r; - stbi__context s; - long pos = ftell(f); - stbi__start_file(&s, f); - r = stbi__is_16_main(&s); - fseek(f,pos,SEEK_SET); - return r; -} -#endif // !STBI_NO_STDIO - -STBIDEF int stbi_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp) -{ - stbi__context s; - stbi__start_mem(&s,buffer,len); - return stbi__info_main(&s,x,y,comp); -} - -STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const *c, void *user, int *x, int *y, int *comp) -{ - stbi__context s; - stbi__start_callbacks(&s, (stbi_io_callbacks *) c, user); - return stbi__info_main(&s,x,y,comp); -} - -STBIDEF int stbi_is_16_bit_from_memory(stbi_uc const *buffer, int len) -{ - stbi__context s; - stbi__start_mem(&s,buffer,len); - return stbi__is_16_main(&s); -} - -STBIDEF int stbi_is_16_bit_from_callbacks(stbi_io_callbacks const *c, void *user) -{ - stbi__context s; - stbi__start_callbacks(&s, (stbi_io_callbacks *) c, user); - return stbi__is_16_main(&s); -} - -#endif // STB_IMAGE_IMPLEMENTATION - -/* - revision history: - 2.20 (2019-02-07) support utf8 filenames in Windows; fix warnings and platform ifdefs - 2.19 (2018-02-11) fix warning - 2.18 (2018-01-30) fix warnings - 2.17 (2018-01-29) change sbti__shiftsigned to avoid clang -O2 bug - 1-bit BMP - *_is_16_bit api - avoid warnings - 2.16 (2017-07-23) all functions have 16-bit variants; - STBI_NO_STDIO works again; - compilation fixes; - fix rounding in unpremultiply; - optimize vertical flip; - disable raw_len validation; - documentation fixes - 2.15 (2017-03-18) fix png-1,2,4 bug; now all Imagenet JPGs decode; - warning fixes; disable run-time SSE detection on gcc; - uniform handling of optional "return" values; - thread-safe initialization of zlib tables - 2.14 (2017-03-03) remove deprecated STBI_JPEG_OLD; fixes for Imagenet JPGs - 2.13 (2016-11-29) add 16-bit API, only supported for PNG right now - 2.12 (2016-04-02) fix typo in 2.11 PSD fix that caused crashes - 2.11 (2016-04-02) allocate large structures on the stack - remove white matting for transparent PSD - fix reported channel count for PNG & BMP - re-enable SSE2 in non-gcc 64-bit - support RGB-formatted JPEG - read 16-bit PNGs (only as 8-bit) - 2.10 (2016-01-22) avoid warning introduced in 2.09 by STBI_REALLOC_SIZED - 2.09 (2016-01-16) allow comments in PNM files - 16-bit-per-pixel TGA (not bit-per-component) - info() for TGA could break due to .hdr handling - info() for BMP to shares code instead of sloppy parse - can use STBI_REALLOC_SIZED if allocator doesn't support realloc - code cleanup - 2.08 (2015-09-13) fix to 2.07 cleanup, reading RGB PSD as RGBA - 2.07 (2015-09-13) fix compiler warnings - partial animated GIF support - limited 16-bpc PSD support - #ifdef unused functions - bug with < 92 byte PIC,PNM,HDR,TGA - 2.06 (2015-04-19) fix bug where PSD returns wrong '*comp' value - 2.05 (2015-04-19) fix bug in progressive JPEG handling, fix warning - 2.04 (2015-04-15) try to re-enable SIMD on MinGW 64-bit - 2.03 (2015-04-12) extra corruption checking (mmozeiko) - stbi_set_flip_vertically_on_load (nguillemot) - fix NEON support; fix mingw support - 2.02 (2015-01-19) fix incorrect assert, fix warning - 2.01 (2015-01-17) fix various warnings; suppress SIMD on gcc 32-bit without -msse2 - 2.00b (2014-12-25) fix STBI_MALLOC in progressive JPEG - 2.00 (2014-12-25) optimize JPG, including x86 SSE2 & NEON SIMD (ryg) - progressive JPEG (stb) - PGM/PPM support (Ken Miller) - STBI_MALLOC,STBI_REALLOC,STBI_FREE - GIF bugfix -- seemingly never worked - STBI_NO_*, STBI_ONLY_* - 1.48 (2014-12-14) fix incorrectly-named assert() - 1.47 (2014-12-14) 1/2/4-bit PNG support, both direct and paletted (Omar Cornut & stb) - optimize PNG (ryg) - fix bug in interlaced PNG with user-specified channel count (stb) - 1.46 (2014-08-26) - fix broken tRNS chunk (colorkey-style transparency) in non-paletted PNG - 1.45 (2014-08-16) - fix MSVC-ARM internal compiler error by wrapping malloc - 1.44 (2014-08-07) - various warning fixes from Ronny Chevalier - 1.43 (2014-07-15) - fix MSVC-only compiler problem in code changed in 1.42 - 1.42 (2014-07-09) - don't define _CRT_SECURE_NO_WARNINGS (affects user code) - fixes to stbi__cleanup_jpeg path - added STBI_ASSERT to avoid requiring assert.h - 1.41 (2014-06-25) - fix search&replace from 1.36 that messed up comments/error messages - 1.40 (2014-06-22) - fix gcc struct-initialization warning - 1.39 (2014-06-15) - fix to TGA optimization when req_comp != number of components in TGA; - fix to GIF loading because BMP wasn't rewinding (whoops, no GIFs in my test suite) - add support for BMP version 5 (more ignored fields) - 1.38 (2014-06-06) - suppress MSVC warnings on integer casts truncating values - fix accidental rename of 'skip' field of I/O - 1.37 (2014-06-04) - remove duplicate typedef - 1.36 (2014-06-03) - convert to header file single-file library - if de-iphone isn't set, load iphone images color-swapped instead of returning NULL - 1.35 (2014-05-27) - various warnings - fix broken STBI_SIMD path - fix bug where stbi_load_from_file no longer left file pointer in correct place - fix broken non-easy path for 32-bit BMP (possibly never used) - TGA optimization by Arseny Kapoulkine - 1.34 (unknown) - use STBI_NOTUSED in stbi__resample_row_generic(), fix one more leak in tga failure case - 1.33 (2011-07-14) - make stbi_is_hdr work in STBI_NO_HDR (as specified), minor compiler-friendly improvements - 1.32 (2011-07-13) - support for "info" function for all supported filetypes (SpartanJ) - 1.31 (2011-06-20) - a few more leak fixes, bug in PNG handling (SpartanJ) - 1.30 (2011-06-11) - added ability to load files via callbacks to accomidate custom input streams (Ben Wenger) - removed deprecated format-specific test/load functions - removed support for installable file formats (stbi_loader) -- would have been broken for IO callbacks anyway - error cases in bmp and tga give messages and don't leak (Raymond Barbiero, grisha) - fix inefficiency in decoding 32-bit BMP (David Woo) - 1.29 (2010-08-16) - various warning fixes from Aurelien Pocheville - 1.28 (2010-08-01) - fix bug in GIF palette transparency (SpartanJ) - 1.27 (2010-08-01) - cast-to-stbi_uc to fix warnings - 1.26 (2010-07-24) - fix bug in file buffering for PNG reported by SpartanJ - 1.25 (2010-07-17) - refix trans_data warning (Won Chun) - 1.24 (2010-07-12) - perf improvements reading from files on platforms with lock-heavy fgetc() - minor perf improvements for jpeg - deprecated type-specific functions so we'll get feedback if they're needed - attempt to fix trans_data warning (Won Chun) - 1.23 fixed bug in iPhone support - 1.22 (2010-07-10) - removed image *writing* support - stbi_info support from Jetro Lauha - GIF support from Jean-Marc Lienher - iPhone PNG-extensions from James Brown - warning-fixes from Nicolas Schulz and Janez Zemva (i.stbi__err. Janez (U+017D)emva) - 1.21 fix use of 'stbi_uc' in header (reported by jon blow) - 1.20 added support for Softimage PIC, by Tom Seddon - 1.19 bug in interlaced PNG corruption check (found by ryg) - 1.18 (2008-08-02) - fix a threading bug (local mutable static) - 1.17 support interlaced PNG - 1.16 major bugfix - stbi__convert_format converted one too many pixels - 1.15 initialize some fields for thread safety - 1.14 fix threadsafe conversion bug - header-file-only version (#define STBI_HEADER_FILE_ONLY before including) - 1.13 threadsafe - 1.12 const qualifiers in the API - 1.11 Support installable IDCT, colorspace conversion routines - 1.10 Fixes for 64-bit (don't use "unsigned long") - optimized upsampling by Fabian "ryg" Giesen - 1.09 Fix format-conversion for PSD code (bad global variables!) - 1.08 Thatcher Ulrich's PSD code integrated by Nicolas Schulz - 1.07 attempt to fix C++ warning/errors again - 1.06 attempt to fix C++ warning/errors again - 1.05 fix TGA loading to return correct *comp and use good luminance calc - 1.04 default float alpha is 1, not 255; use 'void *' for stbi_image_free - 1.03 bugfixes to STBI_NO_STDIO, STBI_NO_HDR - 1.02 support for (subset of) HDR files, float interface for preferred access to them - 1.01 fix bug: possible bug in handling right-side up bmps... not sure - fix bug: the stbi__bmp_load() and stbi__tga_load() functions didn't work at all - 1.00 interface to zlib that skips zlib header - 0.99 correct handling of alpha in palette - 0.98 TGA loader by lonesock; dynamically add loaders (untested) - 0.97 jpeg errors on too large a file; also catch another malloc failure - 0.96 fix detection of invalid v value - particleman@mollyrocket forum - 0.95 during header scan, seek to markers in case of padding - 0.94 STBI_NO_STDIO to disable stdio usage; rename all #defines the same - 0.93 handle jpegtran output; verbose errors - 0.92 read 4,8,16,24,32-bit BMP files of several formats - 0.91 output 24-bit Windows 3.0 BMP files - 0.90 fix a few more warnings; bump version number to approach 1.0 - 0.61 bugfixes due to Marc LeBlanc, Christopher Lloyd - 0.60 fix compiling as c++ - 0.59 fix warnings: merge Dave Moore's -Wall fixes - 0.58 fix bug: zlib uncompressed mode len/nlen was wrong endian - 0.57 fix bug: jpg last huffman symbol before marker was >9 bits but less than 16 available - 0.56 fix bug: zlib uncompressed mode len vs. nlen - 0.55 fix bug: restart_interval not initialized to 0 - 0.54 allow NULL for 'int *comp' - 0.53 fix bug in png 3->4; speedup png decoding - 0.52 png handles req_comp=3,4 directly; minor cleanup; jpeg comments - 0.51 obey req_comp requests, 1-component jpegs return as 1-component, - on 'test' only check type, not whether we support this variant - 0.50 (2006-11-19) - first released version -*/ - - -/* ------------------------------------------------------------------------------- -This software is available under 2 licenses -- choose whichever you prefer. ------------------------------------------------------------------------------- -ALTERNATIVE A - MIT License -Copyright (c) 2017 Sean Barrett -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. ------------------------------------------------------------------------------- -ALTERNATIVE B - Public Domain (www.unlicense.org) -This is free and unencumbered software released into the public domain. -Anyone is free to copy, modify, publish, use, compile, sell, or distribute this -software, either in source code form or as a compiled binary, for any purpose, -commercial or non-commercial, and by any means. -In jurisdictions that recognize copyright laws, the author or authors of this -software dedicate any and all copyright interest in the software to the public -domain. We make this dedication for the benefit of the public at large and to -the detriment of our heirs and successors. We intend this dedication to be an -overt act of relinquishment in perpetuity of all present and future rights to -this software under copyright law. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------- -*/ diff --git a/include/box3d/base.h b/include/box3d/base.h index 4f16490..eb08060 100644 --- a/include/box3d/base.h +++ b/include/box3d/base.h @@ -158,6 +158,9 @@ B3_API float b3GetMillisecondsAndReset( uint64_t* ticks ); /// Yield to be used in a busy loop. B3_API void b3Yield( void ); +/// Sleep the current thread for a number of milliseconds. +B3_API void b3Sleep( int milliseconds ); + // Simple djb2 hash function for determinism testing #define B3_HASH_INIT 5381 B3_API uint32_t b3Hash( uint32_t hash, const uint8_t* data, int count ); diff --git a/include/box3d/collision.h b/include/box3d/collision.h index 96596dd..8c677f2 100644 --- a/include/box3d/collision.h +++ b/include/box3d/collision.h @@ -31,7 +31,8 @@ typedef struct b3SurfaceMaterial /// combining functions. It is not used internally. uint64_t userMaterialId; - /// Custom debug draw color. Ignored if 0. + /// Custom debug draw color. Ignored if 0. The low 24 bits are RGB. The high byte may + /// carry a b3DebugMaterial preset, see b3MakeDebugColor. /// @see b3HexColor uint32_t customColor; } b3SurfaceMaterial; diff --git a/include/box3d/types.h b/include/box3d/types.h index fad01d6..45727b7 100644 --- a/include/box3d/types.h +++ b/include/box3d/types.h @@ -1457,6 +1457,27 @@ typedef enum b3HexColor b3_colorBox2DYellow = 0xFFEE8C } b3HexColor; +/// Debug draw material preset. Optionally packed into the unused high byte of a +/// b3HexColor (or b3SurfaceMaterial::customColor) to drive the renderer's PBR +/// roughness and metalness. The low 24 bits stay RGB, so a plain 0xRRGGBB color +/// reads as b3_debugMaterialDefault and keeps the renderer's per-body-type look. +typedef enum b3DebugMaterial +{ + b3_debugMaterialDefault = 0, + b3_debugMaterialMatte, + b3_debugMaterialSoft, + b3_debugMaterialDead, + b3_debugMaterialGlossy, + b3_debugMaterialMetallic +} b3DebugMaterial; + +/// Pack an RGB color with a material preset for debug draw. The preset rides in +/// the high byte where the color converters ignore it. +B3_INLINE uint32_t b3MakeDebugColor( b3HexColor rgb, b3DebugMaterial material ) +{ + return ( (uint32_t)rgb & 0x00FFFFFFu ) | ( (uint32_t)material << 24 ); +} + /// Get the visualization color assigned to a constraint graph color slot. The last index /// (B3_GRAPH_COLOR_COUNT - 1) is the overflow color. B3_API b3HexColor b3GetGraphColor( int index ); diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 05f97d2..609df17 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -1,149 +1,191 @@ -# Samples app +# Box3D samples -option(BUILD_SHARED_LIBS "Build using shared libraries" OFF) -# set(FETCHCONTENT_QUIET FALSE) - -# glad for OpenGL API -set(GLAD_DIR ${CMAKE_SOURCE_DIR}/extern/glad) - -add_library( - glad STATIC - ${GLAD_DIR}/src/glad.c - ${GLAD_DIR}/include/glad/glad.h - ${GLAD_DIR}/include/KHR/khrplatform.h +FetchContent_Declare(imgui + GIT_REPOSITORY https://github.com/ocornut/imgui.git + GIT_TAG v1.92.7 + GIT_SHALLOW TRUE + GIT_PROGRESS TRUE ) -target_include_directories(glad PUBLIC ${GLAD_DIR}/include) +FetchContent_MakeAvailable(imgui) -# glfw for windowing and input -SET(GLFW_BUILD_DOCS OFF CACHE BOOL "GLFW Docs") -SET(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "GLFW Examples") -SET(GLFW_BUILD_TESTS OFF CACHE BOOL "GLFW Tests") -SET(GLFW_INSTALL OFF CACHE BOOL "GLFW Install") - -FetchContent_Declare( - glfw - GIT_REPOSITORY https://github.com/glfw/glfw.git - GIT_TAG master - GIT_SHALLOW TRUE - GIT_PROGRESS TRUE -) -FetchContent_MakeAvailable(glfw) - -# imgui and glfw backend for GUI -# https://gist.github.com/jeffamstutz/992723dfabac4e3ffff265eb71a24cd9 -# Modified to pin to a specific imgui release -FetchContent_Populate(imgui - URL https://github.com/ocornut/imgui/archive/refs/tags/v1.92.5.zip - SOURCE_DIR ${CMAKE_SOURCE_DIR}/build/imgui -) - -set(IMGUI_DIR ${CMAKE_SOURCE_DIR}/build/imgui) - -add_library(imgui STATIC - ${IMGUI_DIR}/imconfig.h - ${IMGUI_DIR}/imgui.h - ${IMGUI_DIR}/imstb_truetype.h - - ${IMGUI_DIR}/imgui.cpp - ${IMGUI_DIR}/imgui_draw.cpp - ${IMGUI_DIR}/imgui_demo.cpp - ${IMGUI_DIR}/imgui_tables.cpp - ${IMGUI_DIR}/imgui_widgets.cpp - - ${IMGUI_DIR}/backends/imgui_impl_glfw.cpp - ${IMGUI_DIR}/backends/imgui_impl_opengl3.cpp -) - -target_link_libraries(imgui PUBLIC glfw glad) -target_include_directories(imgui PUBLIC ${IMGUI_DIR} ${IMGUI_DIR}/backends) -# The sample app also uses stb_truetype and this keeps the symbols separate -target_compile_definitions(imgui PRIVATE IMGUI_STB_NAMESPACE=imgui_stb) -set_target_properties(imgui PROPERTIES - CXX_STANDARD 20 - CXX_STANDARD_REQUIRED YES - CXX_EXTENSIONS NO -) - -# implot for drawing real time plots -FetchContent_Declare( - implot +FetchContent_Declare(implot GIT_REPOSITORY https://github.com/epezent/implot.git - GIT_TAG v0.17 - GIT_SHALLOW TRUE - GIT_PROGRESS TRUE + GIT_TAG v0.17 + GIT_SHALLOW TRUE + GIT_PROGRESS TRUE ) FetchContent_MakeAvailable(implot) +# The shader compiler is only needed when recompiling shaders. A fresh clone +# with BOX3D_BUILD_SHADERS=OFF builds from the committed headers and skips this. +if(BOX3D_BUILD_SHADERS) + FetchContent_Declare(sokol_tools_bin + GIT_REPOSITORY https://github.com/floooh/sokol-tools-bin.git + GIT_TAG 1a9a4e54090fec42c5d13169b638f09f25474953 + # unfortunately cannot be shallow when using a SHA + # GIT_SHALLOW TRUE + GIT_PROGRESS TRUE + ) + FetchContent_MakeAvailable(sokol_tools_bin) +endif() + +# imgui static lib: the five core sources. sokol_imgui is the backend (no +# glfw/opengl3 backend sources), so it is not listed here. +add_library(imgui STATIC + "${imgui_SOURCE_DIR}/imgui.cpp" + "${imgui_SOURCE_DIR}/imgui_draw.cpp" + "${imgui_SOURCE_DIR}/imgui_tables.cpp" + "${imgui_SOURCE_DIR}/imgui_widgets.cpp" + "${imgui_SOURCE_DIR}/imgui_demo.cpp" +) +target_include_directories(imgui SYSTEM PUBLIC "${imgui_SOURCE_DIR}") +set_target_properties(imgui PROPERTIES + CXX_STANDARD 20 + CXX_STANDARD_REQUIRED ON + CXX_EXTENSIONS OFF + POSITION_INDEPENDENT_CODE ON +) + add_library(implot STATIC - ${implot_SOURCE_DIR}/implot.cpp - ${implot_SOURCE_DIR}/implot_items.cpp - ${implot_SOURCE_DIR}/implot_demo.cpp - ${implot_SOURCE_DIR}/implot.h - ${implot_SOURCE_DIR}/implot_internal.h + "${implot_SOURCE_DIR}/implot.cpp" + "${implot_SOURCE_DIR}/implot_items.cpp" + "${implot_SOURCE_DIR}/implot_demo.cpp" + "${implot_SOURCE_DIR}/implot.h" + "${implot_SOURCE_DIR}/implot_internal.h" ) target_link_libraries(implot PUBLIC imgui) -target_include_directories(implot PUBLIC ${implot_SOURCE_DIR}) - -set (BOX3D_SAMPLE_FILES - camera.cpp - camera.h - earcut.h - font.cpp - font.h - geo_buffer.cpp - geo_buffer.h - jsmn.h - main.cpp - mesh_loader.cpp - mesh_loader.h - renderer.cpp - renderer.h - sample.cpp - sample.h - scene.cpp - scene.h - shader.cpp - shader.h - ssao_buffer.cpp - ssao_buffer.h - stb_image_write.h - stb_truetype.h - tiny_obj_loader.h - utility.h - - sample_benchmark.cpp - sample_bodies.cpp - sample_character.cpp - sample_collision.cpp - sample_compound.cpp - sample_continuous.cpp - sample_determinism.cpp - sample_events.cpp - sample_geometry.cpp - sample_issues.cpp - sample_joint.cpp - sample_manifold.cpp - sample_mesh.cpp - sample_ragdoll.cpp - sample_robustness.cpp - sample_shapes.cpp - sample_stacking.cpp - sample_tree.cpp +target_include_directories(implot SYSTEM PUBLIC "${implot_SOURCE_DIR}") +set_target_properties(implot PROPERTIES + CXX_STANDARD 20 + CXX_STANDARD_REQUIRED ON + CXX_EXTENSIONS OFF + POSITION_INDEPENDENT_CODE ON ) -add_executable(samples ${BOX3D_SAMPLE_FILES}) -target_include_directories(samples PRIVATE ${CMAKE_SOURCE_DIR}/data) -target_include_directories(samples PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) -target_link_libraries(samples PRIVATE box3d shared glfw imgui implot glad) +# --- sokol: vendored headers INTERFACE target + per-platform backend. -------- +set(sokol_SOURCE_DIR "${CMAKE_SOURCE_DIR}/extern/sokol") +add_library(sokol INTERFACE) +target_include_directories(sokol SYSTEM INTERFACE "${sokol_SOURCE_DIR}") +if(WIN32) + target_compile_definitions(sokol INTERFACE SOKOL_D3D11) + target_link_libraries(sokol INTERFACE + d3d11 dxgi dxguid + user32 gdi32 shell32 ole32) +elseif(APPLE) + target_compile_definitions(sokol INTERFACE SOKOL_METAL) + target_link_libraries(sokol INTERFACE + "-framework Foundation" + "-framework Cocoa" + "-framework QuartzCore" + "-framework Metal" + "-framework MetalKit") +elseif(UNIX) + target_compile_definitions(sokol INTERFACE SOKOL_GLCORE) + find_package(OpenGL REQUIRED) + find_package(Threads REQUIRED) + find_package(X11 REQUIRED) + if(NOT X11_Xi_FOUND OR NOT X11_Xcursor_FOUND) + message(FATAL_ERROR + "sokol_app needs Xi and Xcursor; install libxi-dev and libxcursor-dev.") + endif() + target_link_libraries(sokol INTERFACE + OpenGL::GL Threads::Threads ${CMAKE_DL_LIBS} m + X11::X11 X11::Xi X11::Xcursor) +else() + message(FATAL_ERROR "Unsupported platform for sokol backend selection.") +endif() + +# sokol-shdc executable path, consumed by shaders/CMakeLists.txt. +if(BOX3D_BUILD_SHADERS) + if(WIN32) + set(_shdc_subdir win32) + set(_shdc_exe sokol-shdc.exe) + elseif(APPLE) + if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64") + set(_shdc_subdir osx_arm64) + else() + set(_shdc_subdir osx) + endif() + set(_shdc_exe sokol-shdc) + else() + set(_shdc_subdir linux) + set(_shdc_exe sokol-shdc) + endif() + set(SOKOL_SHDC_EXECUTABLE + "${sokol_tools_bin_SOURCE_DIR}/bin/${_shdc_subdir}/${_shdc_exe}" + CACHE FILEPATH "Path to sokol-shdc binary") + unset(_shdc_subdir) + unset(_shdc_exe) +endif() + +# --- Renderer + shaders (ported verbatim from render3d). --------------------- +add_subdirectory(shaders) +add_subdirectory(gfx) + +set(SAMPLE_FILES + main.cpp + + # Host glue (ported from render3d's app/). + host/camera.cpp + host/camera.h + host/gui.cpp + host/gui.h + host/imgui_impl.cpp + host/sokol_app_impl.c + + sample.cpp + sample.h + mesh_loader.cpp + mesh_loader.h + jsmn.h + tiny_obj_loader.h + earcut.h + + # Samples + sample_stacking.cpp + sample_character.cpp + sample_collision.cpp + sample_determinism.cpp + sample_robustness.cpp + sample_benchmark.cpp + sample_ragdoll.cpp + sample_geometry.cpp + sample_issues.cpp + sample_shapes.cpp + sample_tree.cpp + sample_mesh.cpp + sample_compound.cpp + sample_events.cpp + sample_bodies.cpp + sample_manifold.cpp + sample_continuous.cpp + sample_joint.cpp +) + +add_executable(samples ${SAMPLE_FILES}) + +if(APPLE) + # sokol_app's Cocoa backend is Objective-C; compile its impl TU as OBJC + # with ARC, matching render3d's app/CMakeLists. + set_source_files_properties(host/sokol_app_impl.c PROPERTIES LANGUAGE OBJC) + set_source_files_properties(host/sokol_app_impl.c PROPERTIES COMPILE_OPTIONS "-fobjc-arc") +endif() + +# Include root is the samples dir so "gfx/..." and "host/..." prefixes resolve. +# The data dir is on the path too so samples can #include recorded dumps +# (sample_issues pulls dumps/.../box3d_dump.inl at compile time). +target_include_directories(samples PRIVATE + "${CMAKE_CURRENT_SOURCE_DIR}" + "${CMAKE_CURRENT_SOURCE_DIR}/../data") + +# gfx: the renderer + Draw*/adapter. shared: human, utils (Random*), the +# benchmark/determinism helpers the samples lean on. +target_link_libraries(samples PRIVATE gfx shared imgui implot sokol) set_target_properties(samples PROPERTIES - CMAKE_COMPILE_WARNING_AS_ERROR ON - CXX_STANDARD 20 - CXX_STANDARD_REQUIRED YES - CXX_EXTENSIONS NO + CXX_STANDARD 20 + CXX_STANDARD_REQUIRED ON + CXX_EXTENSIONS OFF ) -source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${BOX3D_SAMPLE_FILES}) - -message(STATUS "runtime = ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") -message(STATUS "binary = ${CMAKE_CURRENT_BINARY_DIR}") +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SAMPLE_FILES}) diff --git a/samples/camera.cpp b/samples/camera.cpp deleted file mode 100644 index 2c56951..0000000 --- a/samples/camera.cpp +++ /dev/null @@ -1,332 +0,0 @@ -// SPDX-FileCopyrightText: 2025 Erin Catto -// SPDX-License-Identifier: MIT - -#include "camera.h" - -#include -// prevent clang format sorting glad.h with glfw3.h -#include - -// ImGui -#include -#include - -Matrix4 MakeOrthographicMatrix( float left, float right, float bottom, float top, float near, float far) -{ - Matrix4 m; - m.cx = Vector4{ 2.0f / (right - left), 0.0f, 0.0f, 0.0f }; - m.cy = Vector4{ 0.0f, 2.0f / (top - bottom), 0.0f, 0.0f }; - m.cz = Vector4{ 0.0f, 0.0f, -2.0f / (far - near), 0.0f }; - m.cw.x = -(right + left) / (right - left); - m.cw.y = -(top + bottom) / (top - bottom); - m.cw.z = -(far + near) / (far - near); - m.cw.w = 1.0f; - return m; -} - -Camera::Camera() -{ - m_yaw = 0.0f; - m_pitch = 0.0f; - m_radius = 1.0f; - m_speed = 20.0f; - m_pivot = b3Vec3_zero; - m_nearPlane = 0.02f; - m_farPlane = 100000.0f; - m_fovY = 50.0f; - m_tanY = tanf( 0.5f * B3_DEG_TO_RAD * m_fovY ); - m_thirdPerson = false; - - m_bufferWidth = 1920; - m_bufferHeight = 1080; - - Resize(1920, 1080); - UpdateTransform(); -} - -void Camera::Resize( int width, int height ) -{ - m_width = b3MaxInt(width, 1 ); - m_height = b3MaxInt(height, 1 ); - m_ratio = float( m_width ) / float( m_height ); - - m_nearHeight = 2.0f * m_nearPlane * m_tanY; - m_nearWidth = m_ratio * m_nearHeight; - - m_farHeight = m_farPlane * ( m_nearHeight / m_nearPlane ); - m_farWidth = m_farPlane * ( m_nearWidth / m_nearPlane ); -} - -b3Vec3 Camera::GetRight() const -{ - return m_right; -} - -b3Vec3 Camera::GetUp() const -{ - return m_up; -} - -b3Vec3 Camera::GetForward() const -{ - return m_forward; -} - -b3Vec3 Camera::GetPosition() const -{ - return m_position; -} - -void Camera::Frame( b3AABB bounds) -{ - b3Vec3 center = b3AABB_Center(bounds); - b3Vec3 extent = b3AABB_Extents(bounds); - - float height = 2.0f * b3MaxFloat(extent.x, b3MaxFloat(extent.y, extent.z ) ); - float radius = 0.5f * height / tanf( 0.5f * B3_DEG_TO_RAD * m_fovY ); - - m_pivot = center; - m_radius = 1.25f * radius; -} - -void Camera::SetView( float yaw, float pitch, float radius, b3Vec3 pivot) -{ - m_yaw = yaw; - m_pitch = pitch; - m_radius = radius; - m_pivot = pivot; - UpdateTransform(); -} - -Matrix4 Camera::GetWorldMatrix() const -{ - Matrix4 m; - m.cx = { m_right.x, m_right.y, m_right.z, 0.0f }; - m.cy = { m_up.x, m_up.y, m_up.z, 0.0f }; - m.cz = { m_forward.x, m_forward.y, m_forward.z, 0.0f }; - m.cw = { m_position.x, m_position.y, m_position.z, 1.0f }; - return m; -} - -static Matrix4 InvertOrthonormal( const Matrix4& m) -{ - // [ R | t ] - // M = [ --+-- ] - // [ 0 | 1 ] - // - // y = M * x -> y = R * x + t -> x = R^-1 * (y - t) -> x = R^-1 * y - R^-1 * t - // - // [ R | t ]-1 [ R^-1 | -R^-1 * t ] - // M^-1 = [ --+-- ] = [ -----+---------- ] - // [ 0 | 1 ] [ 0 | 1 ] - b3Matrix3 r; - r.cx = {m.cx.x, m.cx.y, m.cx.z }; - r.cy = {m.cy.x, m.cy.y, m.cy.z }; - r.cz = {m.cz.x, m.cz.y, m.cz.z }; - - // todo just transpose in place into out matrix - b3Matrix3 invR = b3Transpose(r); - - b3Vec3 t{m.cw.x, m.cw.y, m.cw.z }; - b3Vec3 invRXT = invR * t; - - Matrix4 out; - out.cx = {invR.cx.x, invR.cx.y, invR.cx.z, 0.0f }; - out.cy = {invR.cy.x, invR.cy.y, invR.cy.z, 0.0f }; - out.cz = {invR.cz.x, invR.cz.y, invR.cz.z, 0.0f }; - out.cw = { -invRXT.x, -invRXT.y, -invRXT.z, 1.0f }; - - return out; -} - -Matrix4 Camera::GetViewMatrix() const -{ - Matrix4 v = GetWorldMatrix(); - v = InvertOrthonormal(v); - return v; -} - -// http://www.songho.ca/opengl/gl_projectionmatrix.html -// https://unspecified.wordpress.com/2012/06/21/calculating-the-gluperspective-matrix-and-other-opengl-matrix-maths/ -// https://software.intel.com/en-us/articles/alternatives-to-using-z-bias-to-fix-z-fighting-issues -static Matrix4 Perspective( float fieldOfViewY, float aspectRatio, float nearPlane, float farPlane) -{ - float cot = 1.0f / tanf( 0.5f * fieldOfViewY); - float depth = farPlane - nearPlane; - - Matrix4 out; - out.cx = {cot / aspectRatio, 0.0f, 0.0f, 0.0f }; - out.cy = { 0.0f, cot, 0.0f, 0.0f }; - out.cz = { 0.0f, 0.0f, -(nearPlane + farPlane) / depth, -1.0f }; - out.cw = { 0.0f, 0.0f, -2.0f * nearPlane * farPlane / depth, 0.0f }; - return out; -} - -Matrix4 Camera::GetProjectionMatrix() const -{ - return Perspective( B3_DEG_TO_RAD * m_fovY, m_ratio, m_nearPlane, m_farPlane ); -} - -PickRay Camera::BuildPickRay( float x, float y) const -{ - // Use similar triangles to build pick ray - - // Scale, flip, shift into frustum coordinates - float xRatio = x / m_width - 0.5f; - float yRatio = 0.5f - y / m_height; - - // Near plane coordinates using ratio - float xNear = xRatio * m_nearWidth; - float yNear = yRatio * m_nearHeight; - - // Far plane coordinates using ratio - float xFar = xRatio * m_farWidth; - float yFar = yRatio * m_farHeight; - - // Coordinates of near and far plane points in camera space - Vector4 nearPoint{xNear, yNear, -m_nearPlane, 1.0f }; - Vector4 farPoint{xFar, yFar, -m_farPlane, 1.0f }; - - // Convert to world space - Matrix4 m = GetWorldMatrix(); - nearPoint = MulMV(m, nearPoint); - farPoint = MulMV(m, farPoint); - - PickRay ray; - ray.origin = {nearPoint.x, nearPoint.y, nearPoint.z }; - ray.translation = b3Vec3{farPoint.x, farPoint.y, farPoint.z } - ray.origin; - return ray; -} - -bool Camera::WorldToScreen( float& xScreen, float& yScreen, b3Vec3 worldPoint) const -{ - Matrix4 view = GetViewMatrix(); - Vector4 cameraPoint = MulMV(view, Vector4{ worldPoint.x, worldPoint.y, worldPoint.z, 1.0f }); - - float x = cameraPoint.x; - float y = cameraPoint.y; - float z = cameraPoint.z; - - // Frustum comes out the back of the camera - if (z > -m_nearPlane || z < -m_farPlane ) - { - return false; - } - - // Find the frustum size at depth Z - float heightAtZ = -2.0f * z * m_tanY; - float widthAtZ = m_ratio * heightAtZ; - - // Compute ratios of the point within the frustum rectangle at Z - float xRatio = x / widthAtZ; - float yRatio = y / heightAtZ; - - // Shift, flip, and scale - xScreen = (xRatio + 0.5f ) * m_width; - yScreen = ( 0.5f - yRatio) * m_height; - - return true; -} - -void Camera::Update( GLFWwindow* window, float elapsedTime) -{ - ImGuiIO& io = ImGui::GetIO(); - - if ( m_thirdPerson ) - { - const float sensitivity = 1.0f; - m_radius -= sensitivity * io.MouseWheel; - m_radius = b3MaxFloat( 0.25f, m_radius ); - return; - } - - if (io.KeyAlt ) - { - // Orbit - if ( ImGui::IsMouseDragging( ImGuiMouseButton_Left ) ) - { - const float sensitivity = 0.2f; - m_yaw -= sensitivity * io.MouseDelta.x; - m_pitch += sensitivity * io.MouseDelta.y; - m_pitch = b3ClampFloat( m_pitch, -85.0f, 85.0f ); - } - - if ( ImGui::IsMouseDragging( ImGuiMouseButton_Middle ) ) - { - const float sensitivity = 0.01f; - m_pivot -= sensitivity * io.MouseDelta.x * m_right; - m_pivot += sensitivity * io.MouseDelta.y * m_up; - } - - if ( ImGui::IsMouseDragging( ImGuiMouseButton_Right ) ) - { - const float sensitivity = 0.02f; - m_radius -= sensitivity * io.MouseDelta.y; - m_radius = b3MaxFloat( 0.001f, m_radius ); - } - - const float sensitivity = 1.0f; - m_radius -= sensitivity * io.MouseWheel; - m_radius = b3MaxFloat( 0.001f, m_radius ); - - UpdateTransform(); - } - else if ( ImGui::IsMouseDown( ImGuiMouseButton_Right ) ) - { - m_speed += io.MouseWheel; - m_speed = b3ClampFloat( m_speed, 0.001f * 60.0f, 500.0f * 60.0f ); - - if ( ImGui::IsMouseDragging( ImGuiMouseButton_Right ) ) - { - const float sensitivity = 0.2f; - m_yaw -= sensitivity * io.MouseDelta.x; - m_pitch += sensitivity * io.MouseDelta.y; - m_pitch = b3ClampFloat( m_pitch, -85.0f, 85.0f ); - - float sinYaw = sinf( B3_DEG_TO_RAD * m_yaw ), cosYaw = cosf( B3_DEG_TO_RAD * m_yaw ); - float sinPitch = sinf( B3_DEG_TO_RAD * m_pitch ), cosPitch = cosf( B3_DEG_TO_RAD * m_pitch ); - - m_forward = {sinYaw * cosPitch, sinPitch, cosYaw * cosPitch}; - m_up = { 0.0f, 1.0f, 0.0f }; - m_up = b3Normalize( m_up - b3Dot( m_forward, m_up ) * m_forward ); - m_right = b3Normalize( b3Cross( m_up, m_forward ) ); - } - - // Smoother with GLFW - if ( glfwGetKey(window, GLFW_KEY_W ) ) - { - m_position -= m_speed * elapsedTime * m_forward; - } - - if ( glfwGetKey(window, GLFW_KEY_S ) ) - { - m_position += m_speed * elapsedTime * m_forward; - } - - if ( glfwGetKey(window, GLFW_KEY_A ) ) - { - m_position -= m_speed * elapsedTime * m_right; - } - - if ( glfwGetKey(window, GLFW_KEY_D ) ) - { - m_position += m_speed * elapsedTime * m_right; - } - - m_pivot = m_position - m_radius * m_forward; - } -} - -void Camera::UpdateTransform() -{ - m_yaw = B3_RAD_TO_DEG * b3UnwindAngle( B3_DEG_TO_RAD * m_yaw ); - float sinYaw = sinf( B3_DEG_TO_RAD * m_yaw ), cosYaw = cosf( B3_DEG_TO_RAD * m_yaw ); - float sinPitch = sinf( B3_DEG_TO_RAD * m_pitch ), cosPitch = cosf( B3_DEG_TO_RAD * m_pitch ); - - m_forward = {sinYaw * cosPitch, sinPitch, cosYaw * cosPitch}; - m_up = { 0.0f, 1.0f, 0.0f }; - m_up = b3Normalize( m_up - b3Dot( m_forward, m_up ) * m_forward ); - m_right = b3Normalize( b3Cross( m_up, m_forward ) ); - - m_position = m_pivot + m_radius * m_forward; -} diff --git a/samples/camera.h b/samples/camera.h deleted file mode 100644 index 21a3d5b..0000000 --- a/samples/camera.h +++ /dev/null @@ -1,85 +0,0 @@ -// SPDX-FileCopyrightText: 2025 Erin Catto -// SPDX-License-Identifier: MIT - -#pragma once - -#include "utility.h" - -#include "box3d/types.h" - -struct GLFWwindow; - -struct PickRay -{ - b3Vec3 origin; - b3Vec3 translation; -}; - -struct Camera -{ - Camera(); - - // Window - void Resize( int width, int height ); - - // View - b3Vec3 GetRight() const; - b3Vec3 GetUp() const; - b3Vec3 GetForward() const; - b3Vec3 GetPosition() const; - - void Frame( b3AABB bounds); - void SetView( float yaw, float pitch, float radius, b3Vec3 pivot = b3Vec3_zero ); - - Matrix4 GetWorldMatrix() const; - Matrix4 GetViewMatrix() const; - - // Projection - Matrix4 GetProjectionMatrix() const; - PickRay BuildPickRay( float x, float y) const; - bool WorldToScreen( float& xScreen, float& yScreen, b3Vec3 worldPoint) const; - - // Control - void Update( GLFWwindow* window, float elapsedTime); - - void UpdateTransform(); - - // Window - int m_width; - int m_height; - - // Frame buffer - int m_bufferWidth; - int m_bufferHeight; - - // View yaw in degrees - float m_yaw; - - // View pitch in degrees - float m_pitch; - - float m_radius; - b3Vec3 m_pivot; - float m_speed; - - // Projection - float m_fovY; - float m_tanY; - float m_ratio; - float m_nearPlane; - float m_farPlane; - - float m_nearWidth; - float m_nearHeight; - - float m_farWidth; - float m_farHeight; - - // World coordinates - b3Vec3 m_right; - b3Vec3 m_up; - b3Vec3 m_forward; - b3Vec3 m_position; - - bool m_thirdPerson; -}; diff --git a/samples/font.cpp b/samples/font.cpp deleted file mode 100644 index f60d82c..0000000 --- a/samples/font.cpp +++ /dev/null @@ -1,276 +0,0 @@ -// SPDX-FileCopyrightText: 2025 Erin Catto -// SPDX-License-Identifier: MIT - -#if defined( _MSC_VER ) && !defined( _CRT_SECURE_NO_WARNINGS ) -#define _CRT_SECURE_NO_WARNINGS -#endif - -#include "font.h" - -#include "camera.h" -#include "shader.h" -#include "utility.h" - -#define STBTT_STATIC -#define STB_TRUETYPE_IMPLEMENTATION -#include "stb_truetype.h" - -//#define STB_IMAGE_WRITE_IMPLEMENTATION -//#include "stb_image_write.h" - -#include "glad/glad.h" - -#include -#include - -static const char* vertexShaderSrc = R"( -#version 330 core - -layout (location = 0) in vec2 aPosition; -layout (location = 1) in vec2 aUV; -layout (location = 2) in vec4 aColor; - -out vec4 color; -out vec2 uv; - -uniform mat4 ProjectionMatrix; - -void main() -{ - gl_Position = ProjectionMatrix * vec4(aPosition, 0.0, 1.0); - - color = aColor; - uv = aUV; -} -)"; - -static const char* fragmentShaderSrc = R"( -#version 330 core - -in vec4 color; -in vec2 uv; - -uniform sampler2D FontAtlas; - -out vec4 fragColor; - -void main() -{ - fragColor = vec4(color.rgb, color.a * texture(FontAtlas, uv).r); -} -)"; - -Font::Font( const Camera* camera, float fontSize ) -{ - m_camera = camera; - m_fontSize = fontSize; - m_characters = (stbtt_bakedchar*)malloc( m_characterCount * sizeof( stbtt_bakedchar ) ); - m_textureId = 0; - m_vaoId = 0; - m_vboId = 0; - m_programId = 0; -} - -Font::~Font() -{ - if ( m_programId != 0 ) - { - DestroyShader( m_programId ); - } - - glDeleteBuffers( 1, &m_vboId ); - glDeleteVertexArrays( 1, &m_vaoId ); - - if ( m_textureId != 0 ) - { - glDeleteTextures( 1, &m_textureId ); - } - - free( m_characters ); -} - -void Font::AddText( float x, float y, b3HexColor color, const char* text ) -{ - if (text == nullptr) - { - return; - } - - b3Vec3 position = { x, y, 0.0f }; - RGBA8 c = MakeRGBA8( color ); - int pw = m_atlasWidth; - int ph = m_atlasHeight; - - int i = 0; - while ( text[i] != 0 ) - { - int index = (int)text[i] - m_firstCharacter; - - if ( 0 <= index && index < m_characterCount ) - { - // 1=opengl - stbtt_aligned_quad q; - stbtt_GetBakedQuad( m_characters, pw, ph, index, &position.x, &position.y, &q, 1 ); - - Vertex v1 = { { q.x0, q.y0 }, { q.s0, q.t0 }, c }; - Vertex v2 = { { q.x1, q.y0 }, { q.s1, q.t0 }, c }; - Vertex v3 = { { q.x1, q.y1 }, { q.s1, q.t1 }, c }; - Vertex v4 = { { q.x0, q.y1 }, { q.s0, q.t1 }, c }; - - m_vertices.push_back( v1 ); - m_vertices.push_back( v3 ); - m_vertices.push_back( v2 ); - m_vertices.push_back( v1 ); - m_vertices.push_back( v4 ); - m_vertices.push_back( v3 ); - } - - i += 1; - } -} - -void Font::Flush() -{ - Matrix4 projectionMatrix = MakeOrthographicMatrix( 0.0f, m_camera->m_width, m_camera->m_height, 0.0f, -1.0f, 1.0f ); - - glUseProgram( m_programId ); - - glEnable( GL_BLEND ); - glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); - glDisable( GL_DEPTH_TEST ); - - int slot = 0; - glActiveTexture( GL_TEXTURE0 + slot ); - glBindTexture( GL_TEXTURE_2D, m_textureId ); - - glBindVertexArray( m_vaoId ); - glBindBuffer( GL_ARRAY_BUFFER, m_vboId ); - - int textureUniform = glGetUniformLocation( m_programId, "FontAtlas" ); - glUniform1i( textureUniform, slot ); - - int matrixUniform = glGetUniformLocation( m_programId, "ProjectionMatrix" ); - glUniformMatrix4fv( matrixUniform, 1, GL_FALSE, &projectionMatrix.cx.x ); - - int totalVertexCount = int( m_vertices.size() ); - int drawCallCount = ( totalVertexCount / m_vboCapacity ) + 1; - - for ( int i = 0; i < drawCallCount; i++ ) - { - const Vertex* data = m_vertices.data() + i * m_vboCapacity; - - int vertexCount; - if ( i == drawCallCount - 1 ) - { - vertexCount = totalVertexCount % m_vboCapacity; - } - else - { - vertexCount = m_vboCapacity; - } - - // todo macOS optimization? - // glBufferData( GL_ARRAY_BUFFER, m_vboCapacity * sizeof( Vertex ), nullptr, GL_DYNAMIC_DRAW ); - glBufferSubData( GL_ARRAY_BUFFER, 0, vertexCount * sizeof( Vertex ), data ); - glDrawArrays( GL_TRIANGLES, 0, vertexCount ); - } - - glBindBuffer( GL_ARRAY_BUFFER, 0 ); - glBindVertexArray( 0 ); - glBindTexture( GL_TEXTURE_2D, 0 ); - - glDisable( GL_BLEND ); - glEnable( GL_DEPTH_TEST ); - - CheckOpenGL(); - - m_vertices.clear(); -} - -bool Font::Initialize( const char* path ) -{ - // Create atlas - FILE* file = fopen( path, "rb" ); - if ( file == nullptr ) - { - assert( false ); - return false; - } - - int fileBufferCapacity = 1 << 20; - unsigned char* fileBuffer = (unsigned char*)malloc( fileBufferCapacity * sizeof( unsigned char ) ); - fread( fileBuffer, 1, fileBufferCapacity, file ); - - int pw = m_atlasWidth; - int ph = m_atlasHeight; - unsigned char* tempBitmap = (unsigned char*)malloc( pw * ph * sizeof( unsigned char ) ); - stbtt_BakeFontBitmap( fileBuffer, 0, m_fontSize, tempBitmap, pw, ph, m_firstCharacter, m_characterCount, m_characters ); - - glGenTextures( 1, &m_textureId ); - glBindTexture( GL_TEXTURE_2D, m_textureId ); - glTexImage2D( GL_TEXTURE_2D, 0, GL_R8, pw, ph, 0, GL_RED, GL_UNSIGNED_BYTE, tempBitmap ); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); - - // stbi_write_png( "build/fontAtlas.png", pw, ph, 1, tempBitmap, pw ); - - fclose( file ); - free( fileBuffer ); - free( tempBitmap ); - fileBuffer = nullptr; - tempBitmap = nullptr; - - m_programId = CreateProgramFromStrings( vertexShaderSrc, fragmentShaderSrc ); - if ( m_programId == 0 ) - { - return false; - } - - // Setting up the VAO and VBO - glGenBuffers( 1, &m_vboId ); - glBindBuffer( GL_ARRAY_BUFFER, m_vboId ); - glBufferData( GL_ARRAY_BUFFER, m_vboCapacity * sizeof( Vertex ), nullptr, GL_DYNAMIC_DRAW ); - - glGenVertexArrays( 1, &m_vaoId ); - glBindVertexArray( m_vaoId ); - - // position attribute - glVertexAttribPointer( 0, 2, GL_FLOAT, GL_FALSE, sizeof( Vertex ), (void*)offsetof( Vertex, position ) ); - glEnableVertexAttribArray( 0 ); - - // uv attribute - glVertexAttribPointer( 1, 2, GL_FLOAT, GL_FALSE, sizeof( Vertex ), (void*)offsetof( Vertex, uv ) ); - glEnableVertexAttribArray( 1 ); - - // color attribute will be expanded to floats using normalization - glVertexAttribPointer( 2, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof( Vertex ), (void*)offsetof( Vertex, color ) ); - glEnableVertexAttribArray( 2 ); - - glBindVertexArray( 0 ); - - CheckOpenGL(); - - return true; -} - -// For testing -// Matrix4 MakeProjectionMatrix( float width, float height ) -//{ -// Matrix4 m; -// m.cx = { 2.0f / width, 0.0f, 0.0f, 0.0f }; -// m.cy = { 0.0f, 2.0f / height, 0.0f, 0.0f }; -// m.cz = { 0.0f, 0.0f, -1.0f, 0.0f }; -// m.cw = { -1.0f, -1.0f, 0.0f, 1.0f }; -// return m; -//} - -Font* Font::Create( const Camera* camera, const char* path, int fontSize ) -{ - Font* font = new Font( camera, fontSize ); - if ( font->Initialize( path ) == false ) - { - delete font; - font = nullptr; - } - - return font; -} diff --git a/samples/font.h b/samples/font.h deleted file mode 100644 index dd37ab9..0000000 --- a/samples/font.h +++ /dev/null @@ -1,51 +0,0 @@ -// SPDX-FileCopyrightText: 2025 Erin Catto -// SPDX-License-Identifier: MIT - -#pragma once - -#include "box3d/types.h" -#include "utility.h" -#include "stb_truetype.h" - -#include - -struct Camera; - -struct Vertex -{ - b3Vec2 position; - b3Vec2 uv; - RGBA8 color; -}; - -class Font -{ -public: - static Font* Create( const Camera* camera, const char* path, int fontSize ); - ~Font(); - - void AddText( float x, float y, b3HexColor color, const char* text); - - void Flush( ); - -private: - Font( const Camera* camera, float fontSize ); - bool Initialize( const char* path ); - - static constexpr int m_firstCharacter = 32; - static constexpr int m_characterCount = 96; - static constexpr int m_atlasWidth = 512; - static constexpr int m_atlasHeight = 512; - - // The number of vertices the vbo can hold - static constexpr int m_vboCapacity = 6 * 10000; - - const Camera* m_camera; - float m_fontSize; - stbtt_bakedchar* m_characters; - std::vector m_vertices; - unsigned int m_textureId; - uint32_t m_vaoId; - uint32_t m_vboId; - uint32_t m_programId; -}; diff --git a/samples/geo_buffer.cpp b/samples/geo_buffer.cpp deleted file mode 100644 index 1e23dc2..0000000 --- a/samples/geo_buffer.cpp +++ /dev/null @@ -1,150 +0,0 @@ -// SPDX-FileCopyrightText: 2025 Erin Catto -// SPDX-License-Identifier: MIT - -#include "geo_buffer.h" - -#include -#include -#include -#include - -struct GeoBuffer -{ - int32_t width, height; - uint32_t frameBufferId; - uint32_t positionId; - uint32_t normalId; - uint32_t albedoId; - uint32_t depthTextureId; -}; - -GeoBuffer* CreateGeoBuffer(int32_t width, int32_t height) -{ - GeoBuffer* buffer = new GeoBuffer; - - buffer->width = width; - buffer->height = height; - - glGenFramebuffers(1, &buffer->frameBufferId); - glBindFramebuffer(GL_FRAMEBUFFER, buffer->frameBufferId); - - // position color buffer - glGenTextures(1, &buffer->positionId); - glBindTexture(GL_TEXTURE_2D, buffer->positionId); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_FLOAT, nullptr); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, buffer->positionId, 0); - - // normal color buffer - glGenTextures(1, &buffer->normalId); - glBindTexture(GL_TEXTURE_2D, buffer->normalId); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_FLOAT, nullptr); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, buffer->normalId, 0); - - // color + specular color buffer - glGenTextures(1, &buffer->albedoId); - glBindTexture(GL_TEXTURE_2D, buffer->albedoId); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, buffer->albedoId, 0); - - // tell OpenGL which color attachments we'll use (of this framebuffer) for rendering - const unsigned int attachments[3] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2}; - glDrawBuffers(3, attachments); - - // create and attach depth buffer as a texture - // Using a texture instead of a renderbuffer avoids a slow blit path on Apple Silicon - glGenTextures(1, &buffer->depthTextureId); - glBindTexture(GL_TEXTURE_2D, buffer->depthTextureId); - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, buffer->depthTextureId, 0); - - // finally check if framebuffer is complete - if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) - { - fprintf(stderr, "Failed to initialize glad\n"); - free(buffer); - return nullptr; - } - - glBindFramebuffer(GL_FRAMEBUFFER, 0); - return buffer; -} - -void BindGeoBuffer(GeoBuffer* buffer) -{ - glBindFramebuffer(GL_FRAMEBUFFER, buffer->frameBufferId); - - // Clear each attachment to zero independently of the global glClearColor, so the - // deferred lighting pass can identify sky pixels by gPosition.xyz == 0. - static const GLfloat zero[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; - glClearBufferfv(GL_COLOR, 0, zero); - glClearBufferfv(GL_COLOR, 1, zero); - glClearBufferfv(GL_COLOR, 2, zero); - glClear(GL_DEPTH_BUFFER_BIT); -} - -#if 0 -void tbBindGeoPositionNormal(GeoBuffer* buffer) -{ - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, buffer->positionId); - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, buffer->normalId); -} -#endif - -void BindGeoTextures(GeoBuffer* buffer) -{ - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, buffer->positionId); - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, buffer->normalId); - glActiveTexture(GL_TEXTURE2); - glBindTexture(GL_TEXTURE_2D, buffer->albedoId); -} - -void BindGeoPosition(GeoBuffer* buffer, int textureUnit) -{ - glActiveTexture(GL_TEXTURE0 + textureUnit); - glBindTexture(GL_TEXTURE_2D, buffer->positionId); -} - -void BindGeoDepthTexture(GeoBuffer* buffer, int textureUnit) -{ - glActiveTexture(GL_TEXTURE0 + textureUnit); - glBindTexture(GL_TEXTURE_2D, buffer->depthTextureId); -} - -#if 0 -void tbResize(GeoBuffer* buffer, int32_t width, int32_t height) -{ - glBindTexture(GL_TEXTURE_2D, buffer->positionId); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_FLOAT, nullptr); - - glBindTexture(GL_TEXTURE_2D, buffer->normalId); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_FLOAT, nullptr); - - glBindTexture(GL_TEXTURE_2D, buffer->albedoId); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); -} -#endif - -void DestroyGeoBuffer(GeoBuffer* buffer) -{ - glDeleteFramebuffers(1, &buffer->frameBufferId); - glDeleteTextures(1, &buffer->positionId); - glDeleteTextures(1, &buffer->normalId); - glDeleteTextures(1, &buffer->albedoId); - glDeleteTextures(1, &buffer->depthTextureId); - - delete buffer; -} diff --git a/samples/geo_buffer.h b/samples/geo_buffer.h deleted file mode 100644 index 4bee59a..0000000 --- a/samples/geo_buffer.h +++ /dev/null @@ -1,17 +0,0 @@ -// SPDX-FileCopyrightText: 2025 Erin Catto -// SPDX-License-Identifier: MIT - -#pragma once - -#include - -struct GeoBuffer; - -GeoBuffer* CreateGeoBuffer(int32_t width, int32_t height); -void DestroyGeoBuffer(GeoBuffer* buffer); - -void BindGeoBuffer(GeoBuffer* buffer); -//void tbBindGeoPositionNormal(GeoBuffer* buffer); -void BindGeoTextures(GeoBuffer* buffer); -void BindGeoPosition(GeoBuffer* buffer, int textureUnit); -void BindGeoDepthTexture(GeoBuffer* buffer, int textureUnit); diff --git a/samples/gfx/CMakeLists.txt b/samples/gfx/CMakeLists.txt new file mode 100644 index 0000000..5192203 --- /dev/null +++ b/samples/gfx/CMakeLists.txt @@ -0,0 +1,63 @@ +set(GFX_FILES + arena.c + arena.h + debug_adapter.c + debug_adapter.h + debug_shapes.c + debug_shapes.h + draw_overlay.h + draw.c + draw.h + edges.c + edges.h + geometry_registry.c + geometry_registry.h + gtao.c + gtao.h + highlight_mask.c + highlight_mask.h + highlight_outline.c + highlight_outline.h + highlight_target.c + highlight_target.h + ibl.c + ibl.h + overlay.c + overlay.h + picking.h + projection.h + qsort.h + renderer.c + renderer.h + scene_target.c + scene_target.h + shadow.c + shadow.h + sky.c + sky.h + sokol_impl.c + text.c + text.h + tone_map.c + tone_map.h + utility.h +) + +add_library(gfx STATIC ${GFX_FILES}) + +if(APPLE) + set_source_files_properties( + sokol_impl.c + PROPERTIES LANGUAGE OBJC) + target_compile_options(gfx PRIVATE -fobjc-arc) +endif() + +# Include root is the samples dir so "gfx/foo.h" / "host/foo.h" prefixes +# resolve (render3d used its repo root; here gfx lives under samples/). +target_include_directories(gfx PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..") +target_link_libraries(gfx + PUBLIC sokol box3d + PRIVATE shader_gen +) + +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${GFX_FILES}) diff --git a/samples/gfx/arena.c b/samples/gfx/arena.c new file mode 100644 index 0000000..663231a --- /dev/null +++ b/samples/gfx/arena.c @@ -0,0 +1,62 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +#include "gfx/arena.h" + +#include +#include +#include + +int ArenaInit( Arena* a, size_t capacity ) +{ + assert( a ); + assert( capacity > 0 ); + a->base = (uint8_t*)malloc( capacity ); + if ( !a->base ) + { + a->capacity = 0; + a->used = 0; + return -1; + } + a->capacity = capacity; + a->used = 0; + return 0; +} + +void ArenaShutdown( Arena* a ) +{ + if ( !a ) + { + return; + } + free( a->base ); + a->base = NULL; + a->capacity = 0; + a->used = 0; +} + +void* ArenaAlloc( Arena* a, size_t size, size_t align ) +{ + assert( a ); + assert( align > 0 && ( align & ( align - 1 ) ) == 0 ); // power of two + // Align the absolute address, malloc's base is only guaranteed to be + // alignof(max_align_t)-aligned (16 on x64 MSVC), so aligning the offset + // alone breaks for align > 16. + const uintptr_t mask = (uintptr_t)align - 1; + const uintptr_t cur = (uintptr_t)a->base + a->used; + const uintptr_t aligned = ( cur + mask ) & ~mask; + const size_t alignedUsed = (size_t)( aligned - (uintptr_t)a->base ); + if ( alignedUsed > a->capacity || size > a->capacity - alignedUsed ) + { + fprintf( stderr, "[arena/error] out of space: used=%zu cap=%zu req=%zu align=%zu\n", a->used, a->capacity, size, align ); + return NULL; + } + a->used = alignedUsed + size; + return (void*)aligned; +} + +void ArenaReset( Arena* a ) +{ + assert( a ); + a->used = 0; +} diff --git a/samples/gfx/arena.h b/samples/gfx/arena.h new file mode 100644 index 0000000..db535d6 --- /dev/null +++ b/samples/gfx/arena.h @@ -0,0 +1,37 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef struct Arena +{ + uint8_t* base; // owned heap allocation, capacity bytes + size_t capacity; + size_t used; +} Arena; + +// Returns 0 on success, -1 on allocation failure. capacity must be > 0. +int ArenaInit( Arena* a, size_t capacity ); + +// Free backing storage. Safe on a zero-initialized arena. +void ArenaShutdown( Arena* a ); + +// Bump-allocate `size` bytes with `align` alignment (must be power-of-two). +// Returns NULL if the request would overflow the arena, logs to stderr. +void* ArenaAlloc( Arena* a, size_t size, size_t align ); + +// Reset to empty without freeing backing storage. Invalidates all +// pointers handed out before the reset. +void ArenaReset( Arena* a ); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/samples/gfx/debug_adapter.c b/samples/gfx/debug_adapter.c new file mode 100644 index 0000000..b31ba5e --- /dev/null +++ b/samples/gfx/debug_adapter.c @@ -0,0 +1,916 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +#include "gfx/debug_adapter.h" + +#include "box3d/box3d.h" +#include "gfx/debug_shapes.h" +#include "gfx/draw.h" +#include "gfx/geometry_registry.h" +#include "gfx/highlight_mask.h" +#include "gfx/overlay.h" +#include "gfx/renderer.h" +#include "gfx/text.h" + +#include +#include +#include +#include +#include +#include + +#define BOX3D_USER_SHAPE_CAPACITY 65536 +#define BOX3D_FREELIST_END ( -1 ) +#define BOX3D_MATERIAL_OVERRIDE_CAPACITY 256 + +typedef enum +{ + Box3DUS_Free = 0, + Box3DUS_Sphere, + Box3DUS_Capsule, + Box3DUS_Hull, + Box3DUS_Mesh, + Box3DUS_HeightField, + Box3DUS_Compound, +} DebugShapeKind; + +typedef struct +{ + b3Vec3 center; + float radius; +} DebugSphere; + +typedef struct +{ + b3Transform localFrame; + float halfLength; + float radius; +} DebugCapsule; + +// Hull/mesh/heightfield. Scale only for mesh. +typedef struct +{ + MeshHandle handle; + b3Vec3 scale; +} DebugMesh; + +typedef struct +{ + DebugShapeKind kind; + // valid only when kind == Box3DUS_Free + int nextFree; + b3BodyType bodyType; + bool isGround; + b3ShapeId shapeId; + b3BodyId bodyId; + bool hasMaterial; + Vec4 color; + float metallic; + float roughness; + + // Compound children are flattened into their own pool slots. A child links + // to its sibling through nextChild and is placed by childTransform under the + // owning body transform. Identity transform and no sibling for top-level shapes. + int nextChild; + b3Transform childTransform; + union + { + DebugSphere sphere; + DebugCapsule capsule; + DebugMesh geom; + struct + { + int firstChild; + } compound; + }; +} DebugShape; + +typedef struct +{ + b3ShapeId shapeId; + Vec4 color; + float metallic; + float roughness; +} MaterialOverride; + +typedef struct +{ + DebugShape pool[BOX3D_USER_SHAPE_CAPACITY]; + int firstFree; + int allocCount; + + // For the ground grid + b3ShapeId groundShapeId; + + // Per-shape PBR overrides + MaterialOverride materialOverrides[BOX3D_MATERIAL_OVERRIDE_CAPACITY]; + int materialOverrideCount; + + b3BodyId hoveredBodyId; + b3BodyId selectedBodyId; + + // Function pointers, drawingBounds, and context inside this struct are NOT used. + // Only used for settings + b3DebugDraw guiDraw; + + bool transparentDynamic; +} AdapterState; + +static AdapterState s_adapter; + +// Per-bodyType PBR material defaults. Indexed by b3BodyType +// (b3_staticBody = 0, b3_kinematicBody = 1, b3_dynamicBody = 2). +static const float kBodyTypeMetallic[3] = { 0.0f, 0.0f, 0.0f }; +static const float kBodyTypeRoughness[3] = { 0.70f, 0.55f, 0.40f }; + +// PBR presets packed into the debug color high byte. Indexed by b3DebugMaterial. +// Default (0) is unused here, the caller falls back to the per-bodyType table. +// default matte soft dead glossy metal +static const float kDebugMaterialMetallic[6] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.85f }; +static const float kDebugMaterialRoughness[6] = { 0.50f, 0.85f, 0.65f, 0.95f, 0.30f, 0.35f }; + +void InitAdapter( void ) +{ + for ( int i = 0; i < BOX3D_USER_SHAPE_CAPACITY; ++i ) + { + s_adapter.pool[i].kind = Box3DUS_Free; + s_adapter.pool[i].nextFree = ( i + 1 < BOX3D_USER_SHAPE_CAPACITY ) ? ( i + 1 ) : BOX3D_FREELIST_END; + } + s_adapter.firstFree = 0; + s_adapter.allocCount = 0; + s_adapter.groundShapeId = b3_nullShapeId; + s_adapter.materialOverrideCount = 0; + s_adapter.hoveredBodyId = b3_nullBodyId; + s_adapter.selectedBodyId = b3_nullBodyId; + s_adapter.transparentDynamic = false; + + s_adapter.guiDraw = b3DefaultDebugDraw(); + s_adapter.guiDraw.drawShapes = true; +} + +void ResetAdapterPool( void ) +{ + // Release GPU mesh refs still held by live geom shapes, then rebuild the + // free list from scratch. Mirrors InitAdapter's pool setup. The O(capacity) + // sweep is cheap and guarantees a clean slate even if a shape leaked a ref. + for ( int i = 0; i < BOX3D_USER_SHAPE_CAPACITY; ++i ) + { + DebugShape* us = &s_adapter.pool[i]; + if ( us->kind == Box3DUS_Hull || us->kind == Box3DUS_Mesh || us->kind == Box3DUS_HeightField ) + { + ReleaseMeshReference( us->geom.handle ); + } + us->kind = Box3DUS_Free; + us->nextFree = ( i + 1 < BOX3D_USER_SHAPE_CAPACITY ) ? ( i + 1 ) : BOX3D_FREELIST_END; + } + s_adapter.firstFree = 0; + s_adapter.allocCount = 0; + + s_adapter.groundShapeId = b3_nullShapeId; + s_adapter.materialOverrideCount = 0; + s_adapter.hoveredBodyId = b3_nullBodyId; + s_adapter.selectedBodyId = b3_nullBodyId; + s_adapter.transparentDynamic = false; +} + +b3DebugDraw* GetGuiDraw( void ) +{ + return &s_adapter.guiDraw; +} + +void ApplyGuiFlags( b3DebugDraw* out ) +{ + assert( out != NULL ); + out->forceScale = s_adapter.guiDraw.forceScale; + out->jointScale = s_adapter.guiDraw.jointScale; + out->drawShapes = s_adapter.guiDraw.drawShapes; + out->drawJoints = s_adapter.guiDraw.drawJoints; + out->drawJointExtras = s_adapter.guiDraw.drawJointExtras; + out->drawBounds = s_adapter.guiDraw.drawBounds; + out->drawMass = s_adapter.guiDraw.drawMass; + out->drawBodyNames = s_adapter.guiDraw.drawBodyNames; + out->drawContacts = s_adapter.guiDraw.drawContacts; + out->drawAnchorA = s_adapter.guiDraw.drawAnchorA; + out->drawGraphColors = s_adapter.guiDraw.drawGraphColors; + out->drawContactFeatures = s_adapter.guiDraw.drawContactFeatures; + out->drawContactNormals = s_adapter.guiDraw.drawContactNormals; + out->drawContactForces = s_adapter.guiDraw.drawContactForces; + out->drawFrictionForces = s_adapter.guiDraw.drawFrictionForces; + out->drawIslands = s_adapter.guiDraw.drawIslands; +} + +void SetTransparentDynamic( bool enabled ) +{ + s_adapter.transparentDynamic = enabled; +} + +bool GetTransparentDynamic( void ) +{ + return s_adapter.transparentDynamic; +} + +void SetGroundShape( b3ShapeId shapeId ) +{ + s_adapter.groundShapeId = shapeId; +} + +void SetShapeMaterial( b3ShapeId shapeId, Vec4 color, float metallic, float roughness ) +{ + for ( int i = 0; i < s_adapter.materialOverrideCount; ++i ) + { + if ( B3_ID_EQUALS( s_adapter.materialOverrides[i].shapeId, shapeId ) ) + { + s_adapter.materialOverrides[i].color = color; + s_adapter.materialOverrides[i].metallic = metallic; + s_adapter.materialOverrides[i].roughness = roughness; + return; + } + } + + if ( s_adapter.materialOverrideCount >= BOX3D_MATERIAL_OVERRIDE_CAPACITY ) + { + return; + } + + int index = s_adapter.materialOverrideCount++; + s_adapter.materialOverrides[index].shapeId = shapeId; + s_adapter.materialOverrides[index].color = color; + s_adapter.materialOverrides[index].metallic = metallic; + s_adapter.materialOverrides[index].roughness = roughness; +} + +int GetDebugShapeCount( void ) +{ + return s_adapter.allocCount; +} + +void SetHoveredBody( b3BodyId bodyId ) +{ + s_adapter.hoveredBodyId = b3Body_IsValid( bodyId ) ? bodyId : b3_nullBodyId; +} + +b3BodyId GetHoveredBody( void ) +{ + return s_adapter.hoveredBodyId; +} + +void SetSelectedBody( b3BodyId bodyId ) +{ + s_adapter.selectedBodyId = b3Body_IsValid( bodyId ) ? bodyId : b3_nullBodyId; +} + +void ClearSelection( void ) +{ + s_adapter.selectedBodyId = b3_nullBodyId; +} + +b3BodyId GetSelectedBody( void ) +{ + return s_adapter.selectedBodyId; +} + +bool IsBodySelected( b3BodyId bodyId ) +{ + if ( B3_IS_NULL( s_adapter.selectedBodyId ) ) + { + return false; + } + + return B3_ID_EQUALS( s_adapter.selectedBodyId, bodyId ); +} + +static HighlightKind ResolveHighlightKind( b3BodyId bodyId ) +{ + if ( IsBodySelected( bodyId ) ) + { + return HIGHLIGHT_KIND_SELECT; + } + + if ( B3_ID_EQUALS( bodyId, s_adapter.hoveredBodyId ) ) + { + return HIGHLIGHT_KIND_HOVER; + } + + return HIGHLIGHT_KIND_NONE; +} + +static int AllocDebugShape( void ) +{ + if ( s_adapter.firstFree == BOX3D_FREELIST_END ) + { + return -1; + } + const int index = s_adapter.firstFree; + s_adapter.firstFree = s_adapter.pool[index].nextFree; + s_adapter.allocCount += 1; + return index; +} + +static void FreeDebugShape( int index ) +{ + assert( index >= 0 && index < BOX3D_USER_SHAPE_CAPACITY ); + + // A sample switch cleans the pool twice: ResetAdapterPool sweeps it, then + // b3DestroyWorld fires the destroy callback per shape. Relinking a slot + // that is already free loops the free list, and a later alloc then hands + // one slot to two shapes so the second overwrites the first. + if ( s_adapter.pool[index].kind == Box3DUS_Free ) + { + return; + } + + s_adapter.pool[index].kind = Box3DUS_Free; + s_adapter.pool[index].nextFree = s_adapter.firstFree; + s_adapter.firstFree = index; + s_adapter.allocCount -= 1; +} + +// Color + transform helpers + +// b3HexColor is the SVG palette as 0xRRGGBB hex literals, sRGB-encoded, +// like every CSS/SVG color. + +// sRGB values used directly as linear albedo for overlays and in world text +static Vec4 HexColorToVec4( b3HexColor color ) +{ + const uint32_t v = (uint32_t)color; + const float r = (float)( ( v >> 16 ) & 0xFFu ) * ( 1.0f / 255.0f ); + const float g = (float)( ( v >> 8 ) & 0xFFu ) * ( 1.0f / 255.0f ); + const float b = (float)( v & 0xFFu ) * ( 1.0f / 255.0f ); + return MakeVec4( r, g, b, 1.0f ); +} + +// sRGB EOTF, the standard piecewise curve (IEC 61966-2-1), one channel. +static float SRGBToLinear( float c ) +{ + return ( c <= 0.04045f ) ? ( c * ( 1.0f / 12.92f ) ) : powf( ( c + 0.055f ) * ( 1.0f / 1.055f ), 2.4f ); +} + +// sRGB 0xRRGGBB -> linear RGBA. Alpha carries no transfer function. Used +// for lit shape base colors, see the hexColorToVec4 note above. +static Vec4 HexColorToLinear( b3HexColor color ) +{ + const Vec4 s = HexColorToVec4( color ); + return MakeVec4( SRGBToLinear( s.x ), SRGBToLinear( s.y ), SRGBToLinear( s.z ), s.w ); +} + +// Get a capsule transform to represent axial spin +static b3Transform GetCapsuleLocalFrame( b3Vec3 c1, b3Vec3 c2, float* outHalfLength ) +{ + b3Vec3 d = b3Sub(c2, c1); + float length = b3Length( d ); + *outHalfLength = 0.5f * length; + + b3Transform t; + t.q = b3Quat_identity; + if ( length > 1.0e-6f ) + { + b3Vec3 axis = b3MulSV( 1.0f / length, d ); + + // For rendering, the capsule axis is along x + t.q = b3ComputeQuatBetweenUnitVectors( b3Vec3_axisX, axis ); + } + t.p = b3Lerp( c1, c2, 0.5f ); + return t; +} + +static void RefreshMaterialFromOverride( DebugShape* us ) +{ + us->hasMaterial = false; + for ( int i = 0; i < s_adapter.materialOverrideCount; ++i ) + { + if ( B3_ID_EQUALS( s_adapter.materialOverrides[i].shapeId, us->shapeId ) ) + { + us->hasMaterial = true; + us->color = s_adapter.materialOverrides[i].color; + us->metallic = s_adapter.materialOverrides[i].metallic; + us->roughness = s_adapter.materialOverrides[i].roughness; + return; + } + } +} + +static void PopulateCommonFields( DebugShape* us, const b3DebugShape* debugShape ) +{ + const b3BodyId bodyId = b3Shape_GetBody( debugShape->shapeId ); + us->bodyType = b3Body_GetType( bodyId ); + us->isGround = B3_ID_EQUALS( debugShape->shapeId, s_adapter.groundShapeId ); + us->shapeId = debugShape->shapeId; + us->bodyId = bodyId; + RefreshMaterialFromOverride( us ); +} + +// Resolve one compound child into its own pool slot, mirroring the top-level +// create path. Hull and mesh children take a mesh reference released on destroy. +// Common fields are inherited from the parent so material and highlight stay +// keyed to the compound's single shape. Returns the pool index, or -1 if the +// pool is full or the geometry could not be registered. +static int CreateCompoundChild( const b3ChildShape* child, const DebugShape* parent ) +{ + const bool needsHandle = ( child->type == b3_hullShape || child->type == b3_meshShape ); + MeshHandle handle = InvalidMeshHandle(); + if ( child->type == b3_hullShape ) + { + handle = FindOrAddHull( child->hull ); + } + else if ( child->type == b3_meshShape ) + { + handle = FindOrAddMesh( child->mesh.data ); + } + if ( needsHandle && !IsMeshHandleValid( handle ) ) + { + return -1; + } + + const int index = AllocDebugShape(); + if ( index < 0 ) + { + if ( needsHandle ) + { + ReleaseMeshReference( handle ); + } + return -1; + } + + DebugShape* us = &s_adapter.pool[index]; + us->bodyType = parent->bodyType; + us->isGround = parent->isGround; + us->shapeId = parent->shapeId; + us->bodyId = parent->bodyId; + us->hasMaterial = parent->hasMaterial; + us->color = parent->color; + us->metallic = parent->metallic; + us->roughness = parent->roughness; + + switch ( child->type ) + { + case b3_sphereShape: + us->kind = Box3DUS_Sphere; + us->sphere.center = child->sphere.center; + us->sphere.radius = child->sphere.radius; + break; + case b3_capsuleShape: + us->kind = Box3DUS_Capsule; + us->capsule.localFrame = + GetCapsuleLocalFrame( child->capsule.center1, child->capsule.center2, &us->capsule.halfLength ); + us->capsule.radius = child->capsule.radius; + break; + case b3_hullShape: + us->kind = Box3DUS_Hull; + us->geom.handle = handle; + us->geom.scale = b3Vec3_one; + break; + case b3_meshShape: + us->kind = Box3DUS_Mesh; + us->geom.handle = handle; + us->geom.scale = (b3Vec3){ child->mesh.scale.x, child->mesh.scale.y, child->mesh.scale.z }; + break; + default: + assert( false ); + break; + } + + us->childTransform = child->transform; + us->nextChild = -1; + return index; +} + +static void* AdapterCreateDebugShape( const b3DebugShape* debugShape, void* context ) +{ + (void)context; + assert( debugShape != NULL ); + + if ( debugShape->type == b3_sphereShape ) + { + int index = AllocDebugShape(); + if ( index < 0 ) + { + return NULL; // pool exhausted, Box3D treats NULL as "skip draw" + } + DebugShape* us = &s_adapter.pool[index]; + us->kind = Box3DUS_Sphere; + PopulateCommonFields( us, debugShape ); + us->sphere.center = debugShape->sphere->center; + us->sphere.radius = debugShape->sphere->radius; + return us; + } + + if ( debugShape->type == b3_capsuleShape ) + { + int index = AllocDebugShape(); + if ( index < 0 ) + { + return NULL; + } + const b3Capsule* cap = debugShape->capsule; + DebugShape* us = &s_adapter.pool[index]; + us->kind = Box3DUS_Capsule; + PopulateCommonFields( us, debugShape ); + us->capsule.localFrame = GetCapsuleLocalFrame( cap->center1, cap->center2, &us->capsule.halfLength ); + us->capsule.radius = cap->radius; + return us; + } + + if ( debugShape->type == b3_hullShape ) + { + const b3Hull* hull = debugShape->hull; + MeshHandle handle = FindOrAddHull( hull ); + if ( !IsMeshHandleValid( handle ) ) + { + return NULL; + } + int index = AllocDebugShape(); + if ( index < 0 ) + { + ReleaseMeshReference( handle ); + return NULL; + } + DebugShape* us = &s_adapter.pool[index]; + us->kind = Box3DUS_Hull; + PopulateCommonFields( us, debugShape ); + us->geom.handle = handle; + us->geom.scale = b3Vec3_one; + return us; + } + + if ( debugShape->type == b3_meshShape ) + { + const b3Mesh* mesh = debugShape->mesh; + MeshHandle handle = FindOrAddMesh( mesh->data ); + if ( !IsMeshHandleValid( handle ) ) + { + return NULL; + } + int index = AllocDebugShape(); + if ( index < 0 ) + { + ReleaseMeshReference( handle ); + return NULL; + } + DebugShape* us = &s_adapter.pool[index]; + us->kind = Box3DUS_Mesh; + PopulateCommonFields( us, debugShape ); + us->geom.handle = handle; + us->geom.scale = (b3Vec3){ mesh->scale.x, mesh->scale.y, mesh->scale.z }; + return us; + } + + if ( debugShape->type == b3_heightShape ) + { + const b3HeightField* hf = debugShape->heightField; + const MeshHandle handle = FindOrAddHeightField( hf ); + if ( !IsMeshHandleValid( handle ) ) + { + return NULL; + } + const int index = AllocDebugShape(); + if ( index < 0 ) + { + ReleaseMeshReference( handle ); + return NULL; + } + DebugShape* us = &s_adapter.pool[index]; + us->kind = Box3DUS_HeightField; + PopulateCommonFields( us, debugShape ); + us->geom.handle = handle; + us->geom.scale = b3Vec3_one; + return us; + } + + if ( debugShape->type == b3_compoundShape ) + { + const int index = AllocDebugShape(); + if ( index < 0 ) + { + return NULL; + } + DebugShape* us = &s_adapter.pool[index]; + us->kind = Box3DUS_Compound; + PopulateCommonFields( us, debugShape ); + us->compound.firstChild = -1; + + // Flatten the children once. The fixed pool never relocates, so the + // parent pointer stays valid while children are allocated. + const b3Compound* compound = debugShape->compound; + const int total = compound->capsuleCount + compound->hullCount + compound->meshCount + compound->sphereCount; + int prev = -1; + for ( int i = 0; i < total; ++i ) + { + b3ChildShape child = b3GetCompoundChild( compound, i ); + const int childIndex = CreateCompoundChild( &child, us ); + if ( childIndex < 0 ) + { + continue; // skip a child we couldn't register, keep the rest + } + if ( prev < 0 ) + { + us->compound.firstChild = childIndex; + } + else + { + s_adapter.pool[prev].nextChild = childIndex; + } + prev = childIndex; + } + return us; + } + + // Unknown shape type. Return NULL so Box3D skips drawing it. + return NULL; +} + +static void DestroyDebugShape( void* userShape, void* context ) +{ + (void)context; + if ( userShape == NULL ) + { + return; + } + DebugShape* us = (DebugShape*)userShape; + + if ( us->kind == Box3DUS_Compound ) + { + int ci = us->compound.firstChild; + while ( ci != -1 ) + { + DebugShape* child = &s_adapter.pool[ci]; + const int next = child->nextChild; + if ( child->kind == Box3DUS_Hull || child->kind == Box3DUS_Mesh || child->kind == Box3DUS_HeightField ) + { + ReleaseMeshReference( child->geom.handle ); + } + FreeDebugShape( ci ); + ci = next; + } + } + else if ( us->kind == Box3DUS_Hull || us->kind == Box3DUS_Mesh || us->kind == Box3DUS_HeightField ) + { + ReleaseMeshReference( us->geom.handle ); + } + + const int index = (int)( us - s_adapter.pool ); + FreeDebugShape( index ); +} + +// World-space cell size for the procedural ground grid (meters per minor +// cell, major lines fire every 10 cells inside the shader). +#define BOX3D_GROUND_GRID_CELL_SIZE 1.0f + +// Alpha applied to non-static shapes when box3dAdapterSetTransparentDynamic is on. +#define BOX3D_TRANSPARENT_DYNAMIC_ALPHA 0.5f + +// Emit one resolved primitive at baseTransform. The per-kind offset (sphere +// center, capsule frame) layers on top of baseTransform, so the same path +// serves a top-level shape (base = body transform) and a compound child +// (base = body transform composed with the child transform). +static void AppendResolvedShape( const DebugShape* us, b3Transform baseTransform, Vec4 c, float metallic, float roughness, + TransparentShadowCast shadowCast, HighlightKind hk ) +{ + if ( us->kind == Box3DUS_Sphere ) + { + b3Transform transform = { b3TransformPoint( baseTransform, us->sphere.center ), baseTransform.q }; + AppendSphere( transform, us->sphere.radius, c, metallic, roughness, shadowCast ); + if ( hk != HIGHLIGHT_KIND_NONE ) + { + AppendHighlightSphere( transform, us->sphere.radius, hk ); + } + } + else if ( us->kind == Box3DUS_Capsule ) + { + b3Transform transform = b3MulTransforms( baseTransform, us->capsule.localFrame ); + AppendCapsule( transform, us->capsule.halfLength, us->capsule.radius, c, metallic, roughness, shadowCast ); + if ( hk != HIGHLIGHT_KIND_NONE ) + { + AppendHighlightCapsule( transform, us->capsule.halfLength, us->capsule.radius, hk ); + } + } + else if ( us->kind == Box3DUS_Hull || us->kind == Box3DUS_Mesh || us->kind == Box3DUS_HeightField ) + { + MeshMaterialMode mode = us->isGround ? MESH_MATERIAL_MODE_GROUND_GRID : MESH_MATERIAL_MODE_SOLID; + float cell = us->isGround ? BOX3D_GROUND_GRID_CELL_SIZE : 0.0f; + AppendMesh( us->geom.handle, baseTransform, us->geom.scale, c, metallic, roughness, mode, cell, shadowCast ); + if ( hk != HIGHLIGHT_KIND_NONE && us->kind == Box3DUS_Hull ) + { + AppendHighlightHull( us->geom.handle, baseTransform, us->geom.scale, hk ); + } + } +} + +static bool DrawShape( void* userShape, b3Transform shapeTransform, b3HexColor color, void* context ) +{ + (void)context; + if ( userShape == NULL ) + { + return true; // unsupported shape type, skip and continue + } + + DebugShape* us = (DebugShape*)userShape; + + RefreshMaterialFromOverride( us ); + + Vec4 c; + float metallic; + float roughness; + if ( us->hasMaterial ) + { + c = us->color; + metallic = us->metallic; + roughness = us->roughness; + } + else + { + c = HexColorToLinear( color ); + + // State-driven preset rides in the color high byte. Default falls back to + // the per-bodyType material. + b3DebugMaterial preset = (b3DebugMaterial)( ( (uint32_t)color >> 24 ) & 0xFFu ); + if ( preset > b3_debugMaterialDefault && preset <= b3_debugMaterialMetallic ) + { + metallic = kDebugMaterialMetallic[preset]; + roughness = kDebugMaterialRoughness[preset]; + } + else + { + int type = (int)us->bodyType; + metallic = ( type >= 0 && type < 3 ) ? kBodyTypeMetallic[type] : 0.0f; + roughness = ( type >= 0 && type < 3 ) ? kBodyTypeRoughness[type] : 0.5f; + } + } + + if ( s_adapter.transparentDynamic && us->bodyType == b3_dynamicBody ) + { + c.w = BOX3D_TRANSPARENT_DYNAMIC_ALPHA; + } + + TransparentShadowCast shadowCast = TRANSPARENT_SHADOW_NONE; + + // Resolve hover/select state once. Body-keyed, so every supported shape on + // a hovered/selected body outlines together, compound children included. + HighlightKind hk = ResolveHighlightKind( us->bodyId ); + + if ( us->kind == Box3DUS_Compound ) + { + for ( int ci = us->compound.firstChild; ci != -1; ci = s_adapter.pool[ci].nextChild ) + { + b3Transform base = b3MulTransforms( shapeTransform, s_adapter.pool[ci].childTransform ); + AppendResolvedShape( &s_adapter.pool[ci], base, c, metallic, roughness, shadowCast, hk ); + } + } + else + { + AppendResolvedShape( us, shapeTransform, c, metallic, roughness, shadowCast, hk ); + } + + return true; +} + +#define BOX3D_LINE_THICKNESS_PX 2.5f +#define BOX3D_TRANSFORM_LENGTH (0.25f * b3GetLengthUnitsPerMeter()) + +static void DrawSegmentFcn( b3Vec3 p1, b3Vec3 p2, b3HexColor color, void* context ) +{ + (void)context; + OverlayAppendLine( p1, p2, HexColorToVec4( color ), BOX3D_LINE_THICKNESS_PX, OVERLAY_THICKNESS_PIXELS, + OVERLAY_OCCLUSION_HIDE ); +} + +static void DrawTransformFcn( b3Transform transform, void* context ) +{ + (void)context; + b3Vec3 origin = transform.p; + b3Matrix3 basis = b3MakeMatrixFromQuat( transform.q ); + float L = BOX3D_TRANSFORM_LENGTH; + Vec4 red = MakeVec4( 1.0f, 0.0f, 0.0f, 1.0f ); + Vec4 green = MakeVec4( 0.0f, 1.0f, 0.0f, 1.0f ); + Vec4 blue = MakeVec4( 0.0f, 0.0f, 1.0f, 1.0f ); + OverlayAppendLine( origin, b3MulAdd( origin, L, basis.cx ), red, BOX3D_LINE_THICKNESS_PX, OVERLAY_THICKNESS_PIXELS, + OVERLAY_OCCLUSION_HIDE ); + OverlayAppendLine( origin, b3MulAdd( origin, L, basis.cy ), green, BOX3D_LINE_THICKNESS_PX, OVERLAY_THICKNESS_PIXELS, + OVERLAY_OCCLUSION_HIDE ); + OverlayAppendLine( origin, b3MulAdd( origin, L, basis.cz ), blue, BOX3D_LINE_THICKNESS_PX, OVERLAY_THICKNESS_PIXELS, + OVERLAY_OCCLUSION_HIDE ); +} + +static void DrawPointFcn( b3Vec3 p, float size, b3HexColor color, void* context ) +{ + (void)context; + OverlayAppendPoint( p, HexColorToVec4( color ), size, OVERLAY_THICKNESS_PIXELS, OVERLAY_OCCLUSION_HIDE ); +} + +static void DrawBoundsFcn( b3AABB aabb, b3HexColor color, void* context ) +{ + (void)context; + + b3Vec3 lower = aabb.lowerBound; + b3Vec3 upper = aabb.upperBound; + Vec4 c = HexColorToVec4( color ); + + b3Vec3 c000 = { lower.x, lower.y, lower.z }; + b3Vec3 c100 = { upper.x, lower.y, lower.z }; + b3Vec3 c010 = { lower.x, upper.y, lower.z }; + b3Vec3 c110 = { upper.x, upper.y, lower.z }; + b3Vec3 c001 = { lower.x, lower.y, upper.z }; + b3Vec3 c101 = { upper.x, lower.y, upper.z }; + b3Vec3 c011 = { lower.x, upper.y, upper.z }; + b3Vec3 c111 = { upper.x, upper.y, upper.z }; + + float th = BOX3D_LINE_THICKNESS_PX; + OverlayThicknessUnit u = OVERLAY_THICKNESS_PIXELS; + OverlayOcclusionMode o = OVERLAY_OCCLUSION_HIDE; + + // Bottom face + OverlayAppendLine( c000, c100, c, th, u, o ); + OverlayAppendLine( c100, c101, c, th, u, o ); + OverlayAppendLine( c101, c001, c, th, u, o ); + OverlayAppendLine( c001, c000, c, th, u, o ); + + // Top face + OverlayAppendLine( c010, c110, c, th, u, o ); + OverlayAppendLine( c110, c111, c, th, u, o ); + OverlayAppendLine( c111, c011, c, th, u, o ); + OverlayAppendLine( c011, c010, c, th, u, o ); + + // Vertical edges + OverlayAppendLine( c000, c010, c, th, u, o ); + OverlayAppendLine( c100, c110, c, th, u, o ); + OverlayAppendLine( c101, c111, c, th, u, o ); + OverlayAppendLine( c001, c011, c, th, u, o ); +} + +// Oriented box: 8 corners are transform * (+/-ex, +/-ey, +/-ez). 12 edges +// connect adjacent corners along each axis. +static void DrawBoxFcn( b3Vec3 extents, b3Transform transform, b3HexColor color, void* context ) +{ + (void)context; + Vec4 c = HexColorToVec4( color ); + + // Local-space corners (8 = 2^3 sign combinations along each axis). + float signs[2] = { -1.0f, 1.0f }; + b3Vec3 corners[8]; + for ( int xi = 0; xi < 2; ++xi ) + { + for ( int yi = 0; yi < 2; ++yi ) + { + for ( int zi = 0; zi < 2; ++zi ) + { + float lx = signs[xi] * extents.x; + float ly = signs[yi] * extents.y; + float lz = signs[zi] * extents.z; + corners[( xi << 2 ) | ( yi << 1 ) | zi] = b3TransformPoint( transform, (b3Vec3){ lx, ly, lz } ); + } + } + } + + // Edges: bit-pattern walk where each edge connects two corner indices + // that differ in exactly one axis bit. + int edges[12][2] = { + { 0, 4 }, { 4, 5 }, { 5, 1 }, { 1, 0 }, // bottom face (yi = 0) + { 2, 6 }, { 6, 7 }, { 7, 3 }, { 3, 2 }, // top face (yi = 1) + { 0, 2 }, { 4, 6 }, { 5, 7 }, { 1, 3 }, // verticals (yi differs) + }; + + float th = BOX3D_LINE_THICKNESS_PX; + OverlayThicknessUnit u = OVERLAY_THICKNESS_PIXELS; + OverlayOcclusionMode o = OVERLAY_OCCLUSION_HIDE; + + for ( int i = 0; i < 12; ++i ) + { + OverlayAppendLine( corners[edges[i][0]], corners[edges[i][1]], c, th, u, o ); + } +} + +static void DrawStringFcn( b3Vec3 p, const char* s, b3HexColor color, void* context ) +{ + (void)context; + if ( s == NULL ) + { + return; + } + DrawString( p, HexColorToVec4( color ), s ); +} + +void AttachToWorldDef( b3WorldDef* def ) +{ + assert( def != NULL ); + def->createDebugShape = AdapterCreateDebugShape; + def->destroyDebugShape = DestroyDebugShape; + def->userDebugShapeContext = NULL; +} + +void MakeDebugDraw( b3DebugDraw* out ) +{ + assert( out != NULL ); + + *out = b3DefaultDebugDraw(); + + out->DrawShapeFcn = DrawShape; + out->DrawSegmentFcn = DrawSegmentFcn; + out->DrawTransformFcn = DrawTransformFcn; + out->DrawPointFcn = DrawPointFcn; + out->DrawBoundsFcn = DrawBoundsFcn; + out->DrawBoxFcn = DrawBoxFcn; + out->DrawStringFcn = DrawStringFcn; + + // No context needed because globals are used + out->context = NULL; +} diff --git a/samples/gfx/debug_adapter.h b/samples/gfx/debug_adapter.h new file mode 100644 index 0000000..e4a6000 --- /dev/null +++ b/samples/gfx/debug_adapter.h @@ -0,0 +1,45 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +#pragma once + +#include "box3d/types.h" +#include "gfx/utility.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +void InitAdapter( void ); + +// Unconditionally flush the debug-shape pool: release the GPU mesh references +// held by live hull/mesh/heightfield shapes and rebuild the free list. Call +// before b3DestroyWorld (or on scene switch). Defensive even when +// destroyDebugShape already fired for every shape. After this, +// GetDebugShapeCount() == 0 and the next world allocates from the pool bottom. +void ResetAdapterPool( void ); + +void AttachToWorldDef( b3WorldDef* def ); +void MakeDebugDraw( b3DebugDraw* out ); +b3DebugDraw* GetGuiDraw( void ); +void ApplyGuiFlags( b3DebugDraw* out ); +int GetDebugShapeCount( void ); + +// Tag a Box3D shape so the renderer draws it with the procedural ground grid. +void SetGroundShape( b3ShapeId shapeId ); +void SetShapeMaterial( b3ShapeId shapeId, Vec4 color, float metallic, float roughness ); +void SetTransparentDynamic( bool enabled ); +bool GetTransparentDynamic( void ); + +void SetHoveredBody( b3BodyId bodyId ); +b3BodyId GetHoveredBody( void ); + +void SetSelectedBody( b3BodyId bodyId ); +void ClearSelection( void ); +b3BodyId GetSelectedBody( void ); +bool IsBodySelected( b3BodyId bodyId ); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/samples/gfx/debug_shapes.c b/samples/gfx/debug_shapes.c new file mode 100644 index 0000000..442239b --- /dev/null +++ b/samples/gfx/debug_shapes.c @@ -0,0 +1,839 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +#include "gfx/debug_shapes.h" + +#include "gfx/qsort.h" + +#include +#include +#include +#include +#include +#include + +// vertex/index buffer construction helpers + +typedef struct BuildBuffer +{ + MeshVertex* vertices; + int vertexCount; + int vertexCapacity; + + uint32_t* indices; + int indexCount; + int indexCapacity; +} BuildBuffer; + +// Edge build record. Stored only on the CPU during shape acquire, sorted +// and deduplicated in place, then expanded into EdgeVertex pairs at upload +// time. `v0 < v1` after canonicalization so duplicate edges from adjacent +// triangles compare equal regardless of which triangle emitted them. +typedef struct EdgeRecord +{ + uint32_t v0; + uint32_t v1; + uint32_t flags; +} EdgeRecord; + +typedef struct EdgeBuilder +{ + EdgeRecord* edges; + int count; + int capacity; +} EdgeBuilder; + +// Render class carried in the edge flag. Convex must stay 1 so hull edges +// (which emit 1u directly) keep their color. Concave stays 0 to match the +// old binary flag value. +typedef enum EdgeClass +{ + EDGE_CONCAVE = 0, + EDGE_CONVEX = 1, + EDGE_FLAT = 2, +} EdgeClass; + +// Collapse Box3D's two-bit edge flags to a render class. Concave bit clear +// means convex, a true convex edge or an open boundary with neither bit. +// Both bits set means nearly coplanar. +static uint32_t ClassifyEdge( uint8_t flags, uint8_t concaveBit, uint8_t inverseBit ) +{ + if ( flags & concaveBit ) + { + return ( flags & inverseBit ) ? (uint32_t)EDGE_FLAT : (uint32_t)EDGE_CONCAVE; + } + return (uint32_t)EDGE_CONVEX; +} + +// Dedup priority when two adjacent triangles disagree on a shared edge. They +// normally agree, this only matters at non-manifold joints. Convex wins as the +// most prominent feature, then concave, then flat. +static uint32_t EdgeClassRank( uint32_t c ) +{ + if ( c == EDGE_CONVEX ) + { + return 2; + } + if ( c == EDGE_CONCAVE ) + { + return 1; + } + return 0; +} + +static bool EdgeBuilderReserve( EdgeBuilder* b, int extra ) +{ + const int need = b->count + extra; + if ( need <= b->capacity ) + { + return true; + } + int newCap = b->capacity == 0 ? 64 : b->capacity; + while ( newCap < need ) + { + newCap *= 2; + } + EdgeRecord* grown = (EdgeRecord*)realloc( b->edges, (size_t)newCap * sizeof( EdgeRecord ) ); + if ( !grown ) + { + fprintf( stderr, "error: edge buffer realloc failed (cap=%d)\n", newCap ); + return false; + } + b->edges = grown; + b->capacity = newCap; + return true; +} + +static void EdgeBuilderFree( EdgeBuilder* b ) +{ + free( b->edges ); + b->edges = NULL; + b->count = 0; + b->capacity = 0; +} + +// Push one canonicalized edge into the builder. Returns false on OOM. +static bool EmitEdge( EdgeBuilder* b, uint32_t a, uint32_t c, uint32_t flag ) +{ + if ( !EdgeBuilderReserve( b, 1 ) ) + { + return false; + } + EdgeRecord* r = &b->edges[b->count++]; + if ( a <= c ) + { + r->v0 = a; + r->v1 = c; + } + else + { + r->v0 = c; + r->v1 = a; + } + r->flags = flag; + return true; +} + +// Expand a sorted, deduplicated EdgeRecord array into the EdgeVertex pair +// layout the geometry registry wants. Two consecutive EdgeVertex entries per +// edge (the two endpoints), each carrying the same `flags`. Returns NULL on +// OOM (caller treats as "no edges"). +static EdgeVertex* ExpandEdgesForUpload( const EdgeRecord* edges, int edgeCount, const b3Vec3* vertices ) +{ + if ( edgeCount == 0 ) + { + return NULL; + } + + EdgeVertex* out = (EdgeVertex*)malloc( (size_t)( 2 * edgeCount ) * sizeof( EdgeVertex ) ); + if ( !out ) + { + fprintf( stderr, "error: edge upload buffer alloc failed (edges=%d)\n", edgeCount ); + return NULL; + } + + for ( int i = 0; i < edgeCount; ++i ) + { + const EdgeRecord r = edges[i]; + const b3Vec3 a = vertices[r.v0]; + const b3Vec3 c = vertices[r.v1]; + const float flagF = (float)r.flags; + out[2 * i + 0].position[0] = a.x; + out[2 * i + 0].position[1] = a.y; + out[2 * i + 0].position[2] = a.z; + out[2 * i + 0].flag = flagF; + out[2 * i + 1].position[0] = c.x; + out[2 * i + 1].position[1] = c.y; + out[2 * i + 1].position[2] = c.z; + out[2 * i + 1].flag = flagF; + } + + return out; +} + +static bool BufferReserveVertices( BuildBuffer* b, int extra ) +{ + const int need = b->vertexCount + extra; + if ( need <= b->vertexCapacity ) + { + return true; + } + int newCap = b->vertexCapacity == 0 ? 256 : b->vertexCapacity; + while ( newCap < need ) + { + newCap *= 2; + } + MeshVertex* grown = (MeshVertex*)realloc( b->vertices, (size_t)newCap * sizeof( MeshVertex ) ); + if ( !grown ) + { + fprintf( stderr, "error: vertex buffer realloc failed (cap=%d)\n", newCap ); + return false; + } + b->vertices = grown; + b->vertexCapacity = newCap; + return true; +} + +static bool BufferReserveIndices( BuildBuffer* b, int extra ) +{ + const int need = b->indexCount + extra; + if ( need <= b->indexCapacity ) + { + return true; + } + int newCap = b->indexCapacity == 0 ? 384 : b->indexCapacity; + while ( newCap < need ) + { + newCap *= 2; + } + uint32_t* grown = (uint32_t*)realloc( b->indices, (size_t)newCap * sizeof( uint32_t ) ); + if ( !grown ) + { + fprintf( stderr, "error: index buffer realloc failed (cap=%d)\n", newCap ); + return false; + } + b->indices = grown; + b->indexCapacity = newCap; + return true; +} + +static void BufferFree( BuildBuffer* b ) +{ + free( b->vertices ); + free( b->indices ); + b->vertices = NULL; + b->indices = NULL; + b->vertexCount = 0; + b->vertexCapacity = 0; + b->indexCount = 0; + b->indexCapacity = 0; +} + +// Append three vertices (one triangle) with a shared face normal and add +// three consecutive indices that reference them. Returns false on OOM. +static bool EmitFlatTriangle( BuildBuffer* b, b3Vec3 p0, b3Vec3 p1, b3Vec3 p2, b3Vec3 normal ) +{ + if ( !BufferReserveVertices( b, 3 ) || !BufferReserveIndices( b, 3 ) ) + { + return false; + } + + MeshVertex* v = &b->vertices[b->vertexCount]; + v[0].position[0] = p0.x; + v[0].position[1] = p0.y; + v[0].position[2] = p0.z; + v[0].normal[0] = normal.x; + v[0].normal[1] = normal.y; + v[0].normal[2] = normal.z; + v[1].position[0] = p1.x; + v[1].position[1] = p1.y; + v[1].position[2] = p1.z; + v[1].normal[0] = normal.x; + v[1].normal[1] = normal.y; + v[1].normal[2] = normal.z; + v[2].position[0] = p2.x; + v[2].position[1] = p2.y; + v[2].position[2] = p2.z; + v[2].normal[0] = normal.x; + v[2].normal[1] = normal.y; + v[2].normal[2] = normal.z; + + const uint32_t base = (uint32_t)b->vertexCount; + b->indices[b->indexCount + 0] = base + 0u; + b->indices[b->indexCount + 1] = base + 1u; + b->indices[b->indexCount + 2] = base + 2u; + + b->vertexCount += 3; + b->indexCount += 3; + return true; +} + +static b3Vec3 TriangleNormal( b3Vec3 a, b3Vec3 b, b3Vec3 c ) +{ + const float ex = b.x - a.x, ey = b.y - a.y, ez = b.z - a.z; + const float fx = c.x - a.x, fy = c.y - a.y, fz = c.z - a.z; + b3Vec3 n; + n.x = ey * fz - ez * fy; + n.y = ez * fx - ex * fz; + n.z = ex * fy - ey * fx; + const float lenSq = n.x * n.x + n.y * n.y + n.z * n.z; + if ( lenSq > 1.0e-20f ) + { + const float inv = 1.0f / sqrtf( lenSq ); + n.x *= inv; + n.y *= inv; + n.z *= inv; + } + else + { + n.x = 0.0f; + n.y = 1.0f; + n.z = 0.0f; + } + return n; +} + +static MeshHandle BuildHull( const b3Hull* hull ) +{ + const b3Vec3* points = b3GetHullPoints( hull ); + const b3HullHalfEdge* edges = b3GetHullEdges( hull ); + const b3HullFace* faces = b3GetHullFaces( hull ); + const b3Plane* planes = b3GetHullPlanes( hull ); + if ( !points || !edges || !faces || !planes ) + { + fprintf( stderr, "error: hull missing arrays (hash=0x%08x)\n", hull->hash ); + return InvalidMeshHandle(); + } + + BuildBuffer buf = { 0 }; + EdgeBuilder eb = { 0 }; + + // Per-face fan triangulation. Each face's half-edges form a CCW loop + // (viewed from outside, against the face's outward normal). The fan + // pivot is the loop's first vertex, subsequent triangles are + // (v0, v_i, v_{i+1}) for i from 1 to count-2. Plane normal carries + // the outward direction. + for ( int faceIdx = 0; faceIdx < hull->faceCount; ++faceIdx ) + { + const b3HullFace face = faces[faceIdx]; + const b3Vec3 normal = planes[faceIdx].normal; + const uint8_t startEdge = face.edge; + + // First pass: count loop length so we know how to fan it. b3 hull + // faces are bounded (max half-edge count fits a uint8_t) so this + // terminates cleanly. + uint8_t e = startEdge; + int loopLen = 0; + do + { + loopLen += 1; + e = edges[e].next; + if ( loopLen > 256 ) + { + fprintf( stderr, "error: hull face loop runaway (hash=0x%08x)\n", hull->hash ); + BufferFree( &buf ); + return InvalidMeshHandle(); + } + } + while ( e != startEdge ); + + if ( loopLen < 3 ) + { + continue; + } + + // Second pass: emit fan. Collect the loop's vertex indices on the stack. + // loopLen <= 256. + uint8_t loop[256]; + e = startEdge; + for ( int i = 0; i < loopLen; ++i ) + { + loop[i] = edges[e].origin; + e = edges[e].next; + } + + b3Vec3 p0 = points[loop[0]]; + for ( int i = 1; i < loopLen - 1; ++i ) + { + b3Vec3 p1 = points[loop[i]]; + b3Vec3 p2 = points[loop[i + 1]]; + if ( !EmitFlatTriangle( &buf, p0, p1, p2, normal ) ) + { + BufferFree( &buf ); + return InvalidMeshHandle(); + } + } + } + + if ( buf.indexCount == 0 ) + { + BufferFree( &buf ); + return InvalidMeshHandle(); + } + + // Emit hull edges. This automatically prevents duplicates. No sorting needed. + int pairCount = hull->edgeCount / 2; + for ( int i = 0; i < pairCount; i += 1 ) + { + uint8_t a = edges[2 * i + 0].origin; + uint8_t c = edges[2 * i + 1].origin; + + if ( !EmitEdge( &eb, (uint32_t)a, (uint32_t)c, 1u ) ) + { + EdgeBuilderFree( &eb ); + BufferFree( &buf ); + return InvalidMeshHandle(); + } + } + + MeshHandle h = RegisterMesh( hull->hash, buf.vertices, buf.vertexCount, buf.indices, buf.indexCount, "geom_hull" ); + + if ( IsMeshHandleValid( h ) ) + { + SetMeshKind( h, MESH_KIND_HULL ); + if ( eb.count > 0 ) + { + EdgeVertex* upload = ExpandEdgesForUpload( eb.edges, eb.count, points ); + if ( upload ) + { + RegisterMeshEdges( h, upload, eb.count, "geom_hull_edges" ); + free( upload ); + } + } + } + + EdgeBuilderFree( &eb ); + BufferFree( &buf ); + return h; +} + +// Mesh edge sort/dedup. EdgeRecord is canonicalized (v0 <= v1) by emitEdge, +// so a shared interior edge from two adjacent triangles compares equal and +// the unique pass drops the duplicate. Sort key is (v0, v1) lex order. +static inline int MeshEdgeLess( const EdgeRecord* a, const EdgeRecord* b ) +{ + if ( a->v0 != b->v0 ) + { + return a->v0 < b->v0; + } + return a->v1 < b->v1; +} + +static MeshHandle BuildMeshData( const b3MeshData* meshData ) +{ + const b3Vec3* verts = b3GetMeshVertices( meshData ); + const b3MeshTriangle* tris = b3GetMeshTriangles( meshData ); + const uint8_t* flags = b3GetMeshFlags( meshData ); + if ( !verts || !tris || meshData->triangleCount <= 0 ) + { + fprintf( stderr, "error: mesh missing arrays or empty (hash=0x%08x)\n", meshData->hash ); + return InvalidMeshHandle(); + } + + BuildBuffer buf = { 0 }; + EdgeBuilder eb = { 0 }; + + for ( int t = 0; t < meshData->triangleCount; ++t ) + { + const b3MeshTriangle tri = tris[t]; + const b3Vec3 a = verts[tri.index1]; + const b3Vec3 b = verts[tri.index2]; + const b3Vec3 c = verts[tri.index3]; + const b3Vec3 n = TriangleNormal( a, b, c ); + if ( !EmitFlatTriangle( &buf, a, b, c, n ) ) + { + EdgeBuilderFree( &eb ); + BufferFree( &buf ); + return InvalidMeshHandle(); + } + + // Emit all three edges, classified by convexity + const uint8_t f = flags ? flags[t] : 0u; + bool ok = EmitEdge( &eb, (uint32_t)tri.index1, (uint32_t)tri.index2, + ClassifyEdge( f, b3_concaveEdge1, b3_inverseConcaveEdge1 ) ); + if ( ok ) + { + ok = EmitEdge( &eb, (uint32_t)tri.index2, (uint32_t)tri.index3, + ClassifyEdge( f, b3_concaveEdge2, b3_inverseConcaveEdge2 ) ); + } + + if ( ok ) + { + ok = EmitEdge( &eb, (uint32_t)tri.index3, (uint32_t)tri.index1, + ClassifyEdge( f, b3_concaveEdge3, b3_inverseConcaveEdge3 ) ); + } + + if ( !ok ) + { + EdgeBuilderFree( &eb ); + BufferFree( &buf ); + return InvalidMeshHandle(); + } + } + + if ( buf.indexCount == 0 ) + { + EdgeBuilderFree( &eb ); + BufferFree( &buf ); + return InvalidMeshHandle(); + } + + // Sort + unique on the canonicalized (v0, v1) key. svpv/qsort macro + // inlines the comparator and swap so this is fast even for very dense + // meshes, runs once at acquire, not per frame. + if ( eb.count > 1 ) + { +#define LESS( i, j ) MeshEdgeLess( &eb.edges[(int)( i )], &eb.edges[(int)( j )] ) +#define SWAP( i, j ) \ + do \ + { \ + EdgeRecord tmp_ = eb.edges[(int)( i )]; \ + eb.edges[(int)( i )] = eb.edges[(int)( j )]; \ + eb.edges[(int)( j )] = tmp_; \ + } \ + while ( 0 ) + + QSORT( eb.count, LESS, SWAP ); +#undef LESS +#undef SWAP + + // In-place unique. Two records compare equal when (v0, v1) match. + // On a flag tie the higher-rank class wins so the overlay renders the + // edge in the more prominent color when the two triangles' bits + // disagree (rare but possible at non-manifold joints). + int write = 0; + for ( int read = 1; read < eb.count; ++read ) + { + EdgeRecord* w = &eb.edges[write]; + EdgeRecord* r = &eb.edges[read]; + if ( w->v0 == r->v0 && w->v1 == r->v1 ) + { + if ( EdgeClassRank( r->flags ) > EdgeClassRank( w->flags ) ) + { + w->flags = r->flags; + } + } + else + { + ++write; + eb.edges[write] = *r; + } + } + eb.count = write + 1; + } + + const MeshHandle h = RegisterMesh( meshData->hash, buf.vertices, buf.vertexCount, buf.indices, buf.indexCount, "geom_mesh" ); + + if ( IsMeshHandleValid( h ) ) + { + SetMeshKind( h, MESH_KIND_MESH ); + if ( eb.count > 0 ) + { + EdgeVertex* upload = ExpandEdgesForUpload( eb.edges, eb.count, verts ); + if ( upload ) + { + RegisterMeshEdges( h, upload, eb.count, "geom_mesh_edges" ); + free( upload ); + } + } + } + + EdgeBuilderFree( &eb ); + BufferFree( &buf ); + return h; +} + +static b3Vec3 HeightFieldSample( const b3HeightField* hf, int row, int col ) +{ + int index = row * hf->columnCount + col; + float decoded = hf->minHeight + hf->heightScale * (float)hf->compressedHeights[index]; + b3Vec3 scale = hf->scale; + b3Vec3 v; + v.x = scale.x * (float)col; + v.y = scale.y * decoded; + v.z = scale.z * (float)row; + return v; +} + +static MeshHandle BuildHeightField( const b3HeightField* hf ) +{ + if ( hf->columnCount < 2 || hf->rowCount < 2 || !hf->compressedHeights ) + { + fprintf( stderr, "error: heightfield degenerate (hash=0x%08x)\n", hf->hash ); + return InvalidMeshHandle(); + } + + BuildBuffer buf = { 0 }; + EdgeBuilder eb = { 0 }; + + const int cols = hf->columnCount; + const int rows = hf->rowCount; + const uint8_t* materials = hf->materialIndices; // may be NULL if all solid + const uint8_t* edgeFlags = hf->flags; // per-triangle concave bits + const bool clockwise = hf->clockwise; + + // Build a (rows x cols) grid vertex array up front. Triangle emission + // stays per-cell with duplicated corners for flat shading, the edge + // builder refers to grid indices, so it needs a contiguous grid array + // to expand against at upload time. + b3Vec3* gridVertices = (b3Vec3*)malloc( (size_t)( rows * cols ) * sizeof( b3Vec3 ) ); + if ( !gridVertices ) + { + fprintf( stderr, "error: hf grid alloc failed (rows=%d cols=%d)\n", rows, cols ); + return InvalidMeshHandle(); + } + for ( int row = 0; row < rows; ++row ) + { + for ( int col = 0; col < cols; ++col ) + { + gridVertices[row * cols + col] = HeightFieldSample( hf, row, col ); + } + } + + // Each cell (row, col) covers world rectangle: + // x in [scale.x * col, scale.x * (col + 1)] + // z in [scale.z * row, scale.z * (row + 1)] + // with corner heights at the four grid corners. b3HeightField holds + // per-cell material. B3_HEIGHT_FIELD_HOLE (0xFF) marks a hole, skip + // both triangles for that cell. Triangulation matches Box3D's collision + // triangulation (see height_field.c line 228+): + // + // tri0: (col, row), (col, row+1), (col+1, row) + // tri1: (col+1, row+1), (col+1, row), (col, row+1) + // + // Box3D's `clockwise` flag flips the index order. The "clockwise" + // terminology is the source-side winding seen from +Y above, the + // renderer wants CCW-from-outside (which for an upward-facing + // heightfield means CCW from +Y). When clockwise=true we mirror the + // indices to flip the winding. + for ( int row = 0; row < rows - 1; ++row ) + { + for ( int col = 0; col < cols - 1; ++col ) + { + const int cellIndex = row * ( cols - 1 ) + col; + if ( materials && materials[cellIndex] == B3_HEIGHT_FIELD_HOLE ) + { + continue; + } + + const uint32_t i00 = (uint32_t)( row * cols + col ); + const uint32_t i10 = (uint32_t)( row * cols + col + 1 ); + const uint32_t i01 = (uint32_t)( ( row + 1 ) * cols + col ); + const uint32_t i11 = (uint32_t)( ( row + 1 ) * cols + col + 1 ); + + const b3Vec3 p00 = gridVertices[i00]; + const b3Vec3 p10 = gridVertices[i10]; + const b3Vec3 p01 = gridVertices[i01]; + const b3Vec3 p11 = gridVertices[i11]; + + b3Vec3 a0, b0, c0, a1, b1, c1; + if ( clockwise ) + { + a0 = p00; + b0 = p10; + c0 = p01; + a1 = p11; + b1 = p01; + c1 = p10; + } + else + { + a0 = p00; + b0 = p01; + c0 = p10; + a1 = p11; + b1 = p10; + c1 = p01; + } + + const b3Vec3 n0 = TriangleNormal( a0, b0, c0 ); + const b3Vec3 n1 = TriangleNormal( a1, b1, c1 ); + if ( !EmitFlatTriangle( &buf, a0, b0, c0, n0 ) || !EmitFlatTriangle( &buf, a1, b1, c1, n1 ) ) + { + EdgeBuilderFree( &eb ); + BufferFree( &buf ); + free( gridVertices ); + return InvalidMeshHandle(); + } + + // Diagonal edge (shared between tri0 and tri1), classified by + // convexity. b3's flag interpretation is fixed to the + // source-order triangulation, independent of our render-side + // clockwise flip. + const int tri0 = 2 * cellIndex; + const uint8_t f0 = edgeFlags ? edgeFlags[tri0] : 0u; + if ( !EmitEdge( &eb, i10, i01, ClassifyEdge( f0, b3_concaveEdge2, b3_inverseConcaveEdge2 ) ) ) + { + EdgeBuilderFree( &eb ); + BufferFree( &buf ); + free( gridVertices ); + return InvalidMeshHandle(); + } + } + } + + if ( buf.indexCount == 0 ) + { + EdgeBuilderFree( &eb ); + BufferFree( &buf ); + free( gridVertices ); + return InvalidMeshHandle(); + } + + // Row edges (horizontal, between (row, col) and (row, col+1)). Iterate + // every grid row including the outer two. Flag from concaveEdge3 of the + // adjacent tri0 (cell below the edge) or, on the boundary row, of the + // adjacent tri1 (cell above). Skip edges whose only adjacent cell is a + // hole. + for ( int row = 0; row < rows; ++row ) + { + for ( int col = 0; col < cols - 1; ++col ) + { + int triangleIndex = -1; + if ( row < rows - 1 ) + { + const int cellIndex = row * ( cols - 1 ) + col; + if ( !materials || materials[cellIndex] != B3_HEIGHT_FIELD_HOLE ) + { + triangleIndex = 2 * cellIndex; + } + } + if ( triangleIndex < 0 && row > 0 ) + { + const int cellIndex = ( row - 1 ) * ( cols - 1 ) + col; + if ( !materials || materials[cellIndex] != B3_HEIGHT_FIELD_HOLE ) + { + triangleIndex = 2 * cellIndex + 1; + } + } + if ( triangleIndex < 0 ) + { + continue; + } + + const uint8_t f = edgeFlags ? edgeFlags[triangleIndex] : 0u; + const uint32_t i0 = (uint32_t)( row * cols + col ); + const uint32_t i1 = (uint32_t)( row * cols + col + 1 ); + if ( !EmitEdge( &eb, i0, i1, ClassifyEdge( f, b3_concaveEdge3, b3_inverseConcaveEdge3 ) ) ) + { + EdgeBuilderFree( &eb ); + BufferFree( &buf ); + free( gridVertices ); + return InvalidMeshHandle(); + } + } + } + + // Column edges (vertical, between (row, col) and (row+1, col)). Same + // flag-sourcing logic, looking at the cell to the right (concaveEdge1 + // of its tri0) or, on the boundary column, the cell to the left + // (concaveEdge1 of its tri1). + for ( int col = 0; col < cols; ++col ) + { + for ( int row = 0; row < rows - 1; ++row ) + { + int triangleIndex = -1; + if ( col < cols - 1 ) + { + const int cellIndex = row * ( cols - 1 ) + col; + if ( !materials || materials[cellIndex] != B3_HEIGHT_FIELD_HOLE ) + { + triangleIndex = 2 * cellIndex; + } + } + if ( triangleIndex < 0 && col > 0 ) + { + const int cellIndex = row * ( cols - 1 ) + col - 1; + if ( !materials || materials[cellIndex] != B3_HEIGHT_FIELD_HOLE ) + { + triangleIndex = 2 * cellIndex + 1; + } + } + if ( triangleIndex < 0 ) + { + continue; + } + + const uint8_t f = edgeFlags ? edgeFlags[triangleIndex] : 0u; + const uint32_t i0 = (uint32_t)( row * cols + col ); + const uint32_t i1 = (uint32_t)( ( row + 1 ) * cols + col ); + if ( !EmitEdge( &eb, i0, i1, ClassifyEdge( f, b3_concaveEdge1, b3_inverseConcaveEdge1 ) ) ) + { + EdgeBuilderFree( &eb ); + BufferFree( &buf ); + free( gridVertices ); + return InvalidMeshHandle(); + } + } + } + + const MeshHandle h = RegisterMesh( hf->hash, buf.vertices, buf.vertexCount, buf.indices, buf.indexCount, "geom_heightfield" ); + + if ( IsMeshHandleValid( h ) ) + { + SetMeshKind( h, MESH_KIND_HEIGHTFIELD ); + if ( eb.count > 0 ) + { + EdgeVertex* upload = ExpandEdgesForUpload( eb.edges, eb.count, gridVertices ); + if ( upload ) + { + RegisterMeshEdges( h, upload, eb.count, "geom_heightfield_edges" ); + free( upload ); + } + } + } + + EdgeBuilderFree( &eb ); + BufferFree( &buf ); + free( gridVertices ); + return h; +} + +MeshHandle FindOrAddHull( const b3Hull* hull ) +{ + if ( !hull || hull->hash == 0u ) + { + return InvalidMeshHandle(); + } + + MeshHandle existing = FindMesh( hull->hash ); + if ( IsMeshHandleValid( existing ) ) + { + AddMeshReference( existing ); + return existing; + } + + return BuildHull( hull ); +} + +MeshHandle FindOrAddMesh( const b3MeshData* meshData ) +{ + if ( !meshData || meshData->hash == 0u ) + { + return InvalidMeshHandle(); + } + + MeshHandle existing = FindMesh( meshData->hash ); + if ( IsMeshHandleValid( existing ) ) + { + AddMeshReference( existing ); + return existing; + } + + return BuildMeshData( meshData ); +} + +MeshHandle FindOrAddHeightField( const b3HeightField* heightField ) +{ + if ( !heightField || heightField->hash == 0u ) + { + return InvalidMeshHandle(); + } + MeshHandle existing = FindMesh( heightField->hash ); + if ( IsMeshHandleValid( existing ) ) + { + AddMeshReference( existing ); + return existing; + } + return BuildHeightField( heightField ); +} diff --git a/samples/gfx/debug_shapes.h b/samples/gfx/debug_shapes.h new file mode 100644 index 0000000..13d8dda --- /dev/null +++ b/samples/gfx/debug_shapes.h @@ -0,0 +1,50 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Box3D -> gfx geometry-registry bridge for shapes with intrinsic +// topology (hulls, triangle meshes, heightfields). +// +// Each Acquire* function checks the registry for an existing entry under +// the Box3D struct's `hash` field (computed by Box3D at construction) and, +// on miss, builds a flat-shaded triangle list and registers it. On hit +// the existing entry's refcount is bumped. Symmetric Release* via the +// returned MeshHandle goes through ReleaseMeshReference directly. +// +// All three builders emit duplicated vertices (one per triangle corner) +// so the per-vertex normal is the face normal, flat shading falls out +// of the rasterizer without any extra shader logic. This costs ~3x the +// vertex memory of a deduplicated mesh, acceptable at this scale. +// +// Builders run from createDebugShape callbacks (Box3D path). They are NOT hot-path, +// running once per distinct geometry per renderer session, so transient build +// buffers use malloc/free rather than the frame arena. + +#pragma once + +#include "box3d/collision.h" +#include "gfx/geometry_registry.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +// Acquire a registry handle for the given Box3D hull. Returns an invalid +// handle on registry-full or zero hash. The caller owns one refcount. Pair +// each Acquire with a single ReleaseMeshReference when the consumer goes away. +MeshHandle FindOrAddHull( const b3Hull* hull ); + +// Acquire for b3MeshData. The b3Mesh struct's per-instance `scale` is NOT +// part of the geometry, callers pass it as the per-instance scale at +// draw time. Two b3Mesh sharing the same b3MeshData share one entry. +MeshHandle FindOrAddMesh( const b3MeshData* meshData ); + +// Acquire for b3HeightField. The `scale` vector is part of the height +// field's hash (folded into construction), so two heightfields with +// different scales hash to different entries, per-instance scale stays +// at (1, 1, 1) for heightfield draws. +MeshHandle FindOrAddHeightField( const b3HeightField* heightField ); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/samples/gfx/draw.c b/samples/gfx/draw.c new file mode 100644 index 0000000..f61db7b --- /dev/null +++ b/samples/gfx/draw.c @@ -0,0 +1,370 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +#include "gfx/draw.h" + +#include "gfx/overlay.h" +#include "gfx/renderer.h" +#include "gfx/text.h" + +#include +#include + +void DrawCubeEx( b3Transform transform, b3Vec3 scale, Vec4 baseColor, float metallic, float roughness, + TransparentShadowCast shadowCast ) +{ + AppendCube( transform, scale, baseColor, metallic, roughness, shadowCast ); +} + +void DrawCube( b3Transform transform, b3Vec3 scale, Vec4 baseColor ) +{ + DrawCubeEx( transform, scale, baseColor, DEFAULT_METALLIC, DEFAULT_ROUGHNESS, TRANSPARENT_SHADOW_FULL ); +} + +void DrawSphereEx( b3Transform transform, float radius, Vec4 baseColor, float metallic, float roughness, + TransparentShadowCast shadowCast ) +{ + AppendSphere( transform, radius, baseColor, metallic, roughness, shadowCast ); +} + +void DrawSphere( b3Transform transform, float radius, Vec4 baseColor ) +{ + DrawSphereEx( transform, radius, baseColor, DEFAULT_METALLIC, DEFAULT_ROUGHNESS, TRANSPARENT_SHADOW_FULL ); +} + +void DrawCapsuleEx( b3Transform transform, float halfLength, float radius, Vec4 baseColor, float metallic, float roughness, + TransparentShadowCast shadowCast ) +{ + AppendCapsule( transform, halfLength, radius, baseColor, metallic, roughness, shadowCast ); +} + +void DrawCapsule( b3Transform transform, float halfLength, float radius, Vec4 baseColor ) +{ + DrawCapsuleEx( transform, halfLength, radius, baseColor, DEFAULT_METALLIC, DEFAULT_ROUGHNESS, TRANSPARENT_SHADOW_FULL ); +} + +void DrawSolidSphere( b3Transform transform, b3Sphere sphere, Vec4 color ) +{ + b3Transform world = { b3TransformPoint( transform, sphere.center ), transform.q }; + DrawSphere( world, sphere.radius, color ); +} + +void DrawSolidCapsule( b3Transform transform, b3Capsule capsule, Vec4 color ) +{ + b3Vec3 c1 = b3TransformPoint( transform, capsule.center1 ); + b3Vec3 c2 = b3TransformPoint( transform, capsule.center2 ); + b3Vec3 axis = b3Sub( c2, c1 ); + float length = b3Length( axis ); + + // Impostor cylinder runs along local +X, so align +X with the capsule axis. + b3Quat q = transform.q; + if ( length > 1e-6f ) + { + q = b3ComputeQuatBetweenUnitVectors( b3Vec3_axisX, b3MulSV( 1.0f / length, axis ) ); + } + + b3Transform world = { b3MulSV( 0.5f, b3Add( c1, c2 ) ), q }; + DrawCapsule( world, 0.5f * length, capsule.radius, color ); +} + +void DrawHull( b3Transform transform, const b3Hull* hull, Vec4 color ) +{ + const b3Vec3* points = b3GetHullPoints( hull ); + const b3HullHalfEdge* edges = b3GetHullEdges( hull ); + + // Half-edges come in twin pairs, so draw each undirected edge once. + for ( int i = 0; i < hull->edgeCount; ++i ) + { + if ( i >= edges[i].twin ) + { + continue; + } + b3Vec3 p1 = b3TransformPoint( transform, points[edges[i].origin] ); + b3Vec3 p2 = b3TransformPoint( transform, points[edges[edges[i].twin].origin] ); + DrawLine( p1, p2, color ); + } +} + +void DrawPlane( b3Vec3 normal, b3Vec3 point, Vec4 color ) +{ + b3Vec3 perp1 = b3Perp( normal ); + b3Vec3 perp2 = b3Cross( perp1, normal ); + b3Vec3 p1 = b3Add( point, b3Add( perp1, perp2 ) ); + b3Vec3 p2 = b3Add( point, b3Sub( perp2, perp1 ) ); + b3Vec3 p3 = b3Sub( point, b3Add( perp1, perp2 ) ); + b3Vec3 p4 = b3Add( point, b3Sub( perp1, perp2 ) ); + DrawLine( p1, p2, color ); + DrawLine( p2, p3, color ); + DrawLine( p3, p4, color ); + DrawLine( p4, p1, color ); + DrawLine( point, b3Add( point, b3MulSV( 0.5f, normal ) ), color ); + DrawPoint( point, 10.0f, color ); +} + +void DrawLineEx( b3Vec3 a, b3Vec3 b, Vec4 color, float thickness, OverlayThicknessUnit thicknessUnit, + OverlayOcclusionMode occlusionMode ) +{ + OverlayAppendLine( a, b, color, thickness, thicknessUnit, occlusionMode ); +} + +void DrawLine( b3Vec3 a, b3Vec3 b, Vec4 color ) +{ + DrawLineEx( a, b, color, DEFAULT_LINE_THICKNESS_PX, OVERLAY_THICKNESS_PIXELS, OVERLAY_OCCLUSION_HIDE ); +} + +void DrawPointEx( b3Vec3 p, Vec4 color, float size, OverlayThicknessUnit sizeUnit, OverlayOcclusionMode occlusionMode ) +{ + OverlayAppendPoint( p, color, size, sizeUnit, occlusionMode ); +} + +void DrawPoint( b3Vec3 p, float size, Vec4 color ) +{ + DrawPointEx( p, color, size, OVERLAY_THICKNESS_PIXELS, OVERLAY_OCCLUSION_DIM ); +} + +void DrawArrowEx( b3Vec3 a, b3Vec3 b, Vec4 color, float thickness, OverlayThicknessUnit thicknessUnit, + OverlayOcclusionMode occlusionMode, float headLengthFrac ) +{ + DrawLineEx( a, b, color, thickness, thicknessUnit, occlusionMode ); + + b3Vec3 shaft = b3Sub( b, a ); + float shaftLen = b3Length( shaft ); + if ( shaftLen < 1e-6f ) + { + return; + } + b3Vec3 dir = { shaft.x / shaftLen, shaft.y / shaftLen, shaft.z / shaftLen }; + b3Vec3 perp = b3Perp( dir ); + float headLen = shaftLen * headLengthFrac; + + b3Vec3 backFromTip = b3MulSV( -headLen, dir ); + b3Vec3 sideStep = b3MulSV( headLen * 0.5f, perp ); + b3Vec3 tip1 = b3Add( b, b3Add( backFromTip, sideStep ) ); + b3Vec3 tip2 = b3Add( b, b3Sub( backFromTip, sideStep ) ); + DrawLineEx( b, tip1, color, thickness, thicknessUnit, occlusionMode ); + DrawLineEx( b, tip2, color, thickness, thicknessUnit, occlusionMode ); +} + +void DrawArrow( b3Vec3 a, b3Vec3 b, Vec4 color ) +{ + DrawArrowEx( a, b, color, DEFAULT_LINE_THICKNESS_PX, OVERLAY_THICKNESS_PIXELS, OVERLAY_OCCLUSION_HIDE, + DEFAULT_ARROW_HEAD_FRAC ); +} + +void DrawCrossEx( b3Vec3 center, float size, Vec4 color, float thickness, OverlayThicknessUnit thicknessUnit, + OverlayOcclusionMode occlusionMode ) +{ + float h = size * 0.5f; + DrawLineEx( (b3Vec3){ center.x - h, center.y, center.z }, (b3Vec3){ center.x + h, center.y, center.z }, color, thickness, + thicknessUnit, occlusionMode ); + DrawLineEx( (b3Vec3){ center.x, center.y - h, center.z }, (b3Vec3){ center.x, center.y + h, center.z }, color, thickness, + thicknessUnit, occlusionMode ); + DrawLineEx( (b3Vec3){ center.x, center.y, center.z - h }, (b3Vec3){ center.x, center.y, center.z + h }, color, thickness, + thicknessUnit, occlusionMode ); +} + +void DrawCross( b3Vec3 center, float size, Vec4 color ) +{ + DrawCrossEx( center, size, color, DEFAULT_LINE_THICKNESS_PX, OVERLAY_THICKNESS_PIXELS, OVERLAY_OCCLUSION_HIDE ); +} + +void DrawAabbEx( b3Vec3 mn, b3Vec3 mx, Vec4 color, float thickness, OverlayThicknessUnit thicknessUnit, + OverlayOcclusionMode occlusionMode ) +{ + // 8 corners of the box. + b3Vec3 c000 = { mn.x, mn.y, mn.z }; + b3Vec3 c100 = { mx.x, mn.y, mn.z }; + b3Vec3 c010 = { mn.x, mx.y, mn.z }; + b3Vec3 c110 = { mx.x, mx.y, mn.z }; + b3Vec3 c001 = { mn.x, mn.y, mx.z }; + b3Vec3 c101 = { mx.x, mn.y, mx.z }; + b3Vec3 c011 = { mn.x, mx.y, mx.z }; + b3Vec3 c111 = { mx.x, mx.y, mx.z }; + + // 4 bottom edges (y = mn.y). + DrawLineEx( c000, c100, color, thickness, thicknessUnit, occlusionMode ); + DrawLineEx( c100, c101, color, thickness, thicknessUnit, occlusionMode ); + DrawLineEx( c101, c001, color, thickness, thicknessUnit, occlusionMode ); + DrawLineEx( c001, c000, color, thickness, thicknessUnit, occlusionMode ); + // 4 top edges (y = mx.y). + DrawLineEx( c010, c110, color, thickness, thicknessUnit, occlusionMode ); + DrawLineEx( c110, c111, color, thickness, thicknessUnit, occlusionMode ); + DrawLineEx( c111, c011, color, thickness, thicknessUnit, occlusionMode ); + DrawLineEx( c011, c010, color, thickness, thicknessUnit, occlusionMode ); + // 4 vertical edges. + DrawLineEx( c000, c010, color, thickness, thicknessUnit, occlusionMode ); + DrawLineEx( c100, c110, color, thickness, thicknessUnit, occlusionMode ); + DrawLineEx( c101, c111, color, thickness, thicknessUnit, occlusionMode ); + DrawLineEx( c001, c011, color, thickness, thicknessUnit, occlusionMode ); +} + +void DrawAabb( b3Vec3 mn, b3Vec3 mx, Vec4 color ) +{ + DrawAabbEx( mn, mx, color, DEFAULT_LINE_THICKNESS_PX, OVERLAY_THICKNESS_PIXELS, OVERLAY_OCCLUSION_HIDE ); +} + +void DrawBounds( b3AABB bounds, float extension, Vec4 color ) +{ + b3Vec3 e = { extension, extension, extension }; + DrawAabb( b3Sub( bounds.lowerBound, e ), b3Add( bounds.upperBound, e ), color ); +} + +void DrawAxesEx( b3Transform transform, float size, float thickness, OverlayThicknessUnit thicknessUnit, + OverlayOcclusionMode occlusionMode ) +{ + b3Vec3 origin = transform.p; + b3Matrix3 basis = b3MakeMatrixFromQuat( transform.q ); + DrawLineEx( origin, b3MulAdd( origin, size, basis.cx ), MakeVec4( 1.0f, 0.0f, 0.0f, 1.0f ), thickness, thicknessUnit, + occlusionMode ); + DrawLineEx( origin, b3MulAdd( origin, size, basis.cy ), MakeVec4( 0.0f, 1.0f, 0.0f, 1.0f ), thickness, thicknessUnit, + occlusionMode ); + DrawLineEx( origin, b3MulAdd( origin, size, basis.cz ), MakeVec4( 0.0f, 0.0f, 1.0f, 1.0f ), thickness, thicknessUnit, + occlusionMode ); +} + +void DrawAxes( b3Transform transform, float size ) +{ + DrawAxesEx( transform, size, DEFAULT_LINE_THICKNESS_PX, OVERLAY_THICKNESS_PIXELS, OVERLAY_OCCLUSION_HIDE ); +} + +void DrawGrid( b3Vec3 center, b3Vec3 normal, float halfExtent, int divisions, Vec4 color ) +{ + if ( divisions < 1 || halfExtent <= 0.0f ) + { + return; + } + // Orthonormal in-plane axes from the normal. + b3Vec3 n = b3Normalize( normal ); + b3Vec3 u = b3Normalize( b3Perp( n ) ); + b3Vec3 v = b3Cross( n, u ); + + const float step = ( 2.0f * halfExtent ) / (float)divisions; + for ( int i = 0; i <= divisions; ++i ) + { + const float o = -halfExtent + (float)i * step; + // Line spanning u at this offset along v. + b3Vec3 ua = b3Add( center, b3Add( b3MulSV( -halfExtent, u ), b3MulSV( o, v ) ) ); + b3Vec3 ub = b3Add( center, b3Add( b3MulSV( halfExtent, u ), b3MulSV( o, v ) ) ); + DrawLineEx( ua, ub, color, DEFAULT_LINE_THICKNESS_PX, OVERLAY_THICKNESS_PIXELS, OVERLAY_OCCLUSION_HIDE ); + // Line spanning v at this offset along u. + b3Vec3 va = b3Add( center, b3Add( b3MulSV( o, u ), b3MulSV( -halfExtent, v ) ) ); + b3Vec3 vb = b3Add( center, b3Add( b3MulSV( o, u ), b3MulSV( halfExtent, v ) ) ); + DrawLineEx( va, vb, color, DEFAULT_LINE_THICKNESS_PX, OVERLAY_THICKNESS_PIXELS, OVERLAY_OCCLUSION_HIDE ); + } +} + +void DrawGroundGrid( int size ) +{ + Vec4 color = MakeVec4( 0.3f, 0.3f, 0.3f, 1.0f ); + DrawGrid( b3Vec3_zero, b3Vec3_axisY, (float)size, size, color ); +} + +void DrawTriangle( b3Vec3 a, b3Vec3 b, b3Vec3 c, Vec4 color ) +{ + DrawLineEx( a, b, color, DEFAULT_LINE_THICKNESS_PX, OVERLAY_THICKNESS_PIXELS, OVERLAY_OCCLUSION_HIDE ); + DrawLineEx( b, c, color, DEFAULT_LINE_THICKNESS_PX, OVERLAY_THICKNESS_PIXELS, OVERLAY_OCCLUSION_HIDE ); + DrawLineEx( c, a, color, DEFAULT_LINE_THICKNESS_PX, OVERLAY_THICKNESS_PIXELS, OVERLAY_OCCLUSION_HIDE ); +} + +static void DrawDisc( b3Vec3 center, b3Vec3 normal, float radius, int segments, Vec4 color ) +{ + b3Vec3 tangent1 = b3Perp( normal ); + b3Vec3 tangent2 = b3Cross( normal, tangent1 ); + + float delta = 2.0f * B3_PI / segments; + float cosine = cosf( delta ); + float sine = sinf( delta ); + + float x1 = radius, y1 = 0.0f; + b3Vec3 vertex1 = b3Add( center, b3Blend2( x1, tangent1, y1, tangent2 ) ); + + for ( int i = 0; i < segments; ++i ) + { + float x2 = cosine * x1 - sine * y1; + float y2 = sine * x1 + cosine * y1; + b3Vec3 vertex2 = b3Add( center, b3Blend2( x2, tangent1, y2, tangent2 ) ); + + DrawLineEx( vertex1, vertex2, color, 2.0f, OVERLAY_THICKNESS_PIXELS, OVERLAY_OCCLUSION_DIM ); + + x1 = x2; + y1 = y2; + vertex1 = vertex2; + } +} + +static void DrawArc( b3Vec3 center, b3Vec3 normal, float radius, b3Vec3 start, float maxDegrees, int segments, Vec4 color ) +{ + b3Vec3 tangent1 = b3Normalize( start ); + b3Vec3 tangent2 = b3Cross( normal, tangent1 ); + + float deltaDegrees = maxDegrees / segments; + b3CosSin cs = b3ComputeCosSin( B3_DEG_TO_RAD * deltaDegrees ); + float x1 = radius, y1 = 0.0f; + + b3Vec3 vertex1 = b3Add( center, b3Blend2( x1, tangent1, y1, tangent2 ) ); + + for ( float angle = 0.0f; angle < maxDegrees - 0.001f; angle += deltaDegrees ) + { + float x2 = cs.cosine * x1 - cs.sine * y1; + float y2 = cs.sine * x1 + cs.cosine * y1; + b3Vec3 vertex2 = b3Add( center, b3Blend2( x2, tangent1, y2, tangent2 ) ); + + DrawLineEx( vertex1, vertex2, color, 2.0f, OVERLAY_THICKNESS_PIXELS, OVERLAY_OCCLUSION_DASHED ); + + x1 = x2; + y1 = y2; + vertex1 = vertex2; + } +} + +void DrawWireSphere( b3Transform transform, const b3Sphere* sphere, int segments, Vec4 color ) +{ + b3Vec3 center = b3TransformPoint( transform, sphere->center ); + float radius = sphere->radius; + + b3Vec3 axisX = b3RotateVector( transform.q, (b3Vec3){ 1.0f, 0.0f, 0.0f } ); + b3Vec3 axisY = b3RotateVector( transform.q, (b3Vec3){ 0.0f, 1.0f, 0.0f } ); + b3Vec3 axisZ = b3RotateVector( transform.q, (b3Vec3){ 0.0f, 0.0f, 1.0f } ); + + DrawDisc( center, axisX, radius, segments, color ); + DrawDisc( center, axisY, radius, segments, color ); + DrawDisc( center, axisZ, radius, segments, color ); +} + +void DrawWireCapsule( b3Transform transform, const b3Capsule* capsule, int segments, Vec4 color ) +{ + b3Vec3 center1 = b3TransformPoint( transform, capsule->center1 ); + b3Vec3 center2 = b3TransformPoint( transform, capsule->center2 ); + float radius = capsule->radius; + + b3Vec3 normal = b3Normalize( b3Sub( center2, center1 ) ); + b3Vec3 tangent1 = b3Perp( normal ); + b3Vec3 tangent2 = b3Cross( normal, tangent1 ); + + DrawLineEx( b3MulAdd( center1, radius, tangent1 ), b3MulAdd( center2, radius, tangent1 ), color, 2.0f, + OVERLAY_THICKNESS_PIXELS, OVERLAY_OCCLUSION_DASHED ); + DrawLineEx( b3MulAdd( center1, radius, tangent2 ), b3MulAdd( center2, radius, tangent2 ), color, 2.0f, + OVERLAY_THICKNESS_PIXELS, OVERLAY_OCCLUSION_DASHED ); + DrawLineEx( b3MulSub( center1, radius, tangent1 ), b3MulSub( center2, radius, tangent1 ), color, 2.0f, + OVERLAY_THICKNESS_PIXELS, OVERLAY_OCCLUSION_DASHED ); + DrawLineEx( b3MulSub( center1, radius, tangent2 ), b3MulSub( center2, radius, tangent2 ), color, 2.0f, + OVERLAY_THICKNESS_PIXELS, OVERLAY_OCCLUSION_DASHED ); + + DrawArc( center1, b3Neg( tangent1 ), radius, tangent2, 180.0f, segments / 2, color ); + DrawArc( center1, tangent2, radius, tangent1, 180.0f, segments / 2, color ); + DrawArc( center2, tangent1, radius, tangent2, 180.0f, segments / 2, color ); + DrawArc( center2, b3Neg( tangent2 ), radius, tangent1, 180.0f, segments / 2, color ); + + DrawDisc( center1, normal, radius, segments, color ); + DrawDisc( center2, normal, radius, segments, color ); +} + +void DrawWorldString( b3Vec3 point, Vec4 color, const char* format, ... ) +{ + va_list args; + va_start( args, format ); + char buffer[256]; + vsnprintf( buffer, sizeof( buffer ), format, args ); + va_end( args ); + DrawString( point, color, buffer ); +} diff --git a/samples/gfx/draw.h b/samples/gfx/draw.h new file mode 100644 index 0000000..a1440af --- /dev/null +++ b/samples/gfx/draw.h @@ -0,0 +1,117 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +#pragma once + +#include "gfx/draw_overlay.h" +#include "gfx/utility.h" + +#include "box3d/collision.h" + +// Neutral-dielectric material defaults for the short-form shape calls. +#define DEFAULT_METALLIC 0.0f +#define DEFAULT_ROUGHNESS 0.5f + +// Thickness/size defaults for the short-form overlay calls +#define DEFAULT_LINE_THICKNESS_PX 1.5f +#define DEFAULT_POINT_SIZE_PX 4.0f + +// Arrow head length as a fraction of the shaft length +#define DEFAULT_ARROW_HEAD_FRAC 0.15f + +#ifdef __cplusplus +extern "C" +{ +#endif + +// Cube. transform places and orients the cube. scale is the cube's full side +// lengths (it multiplies the unit cube proxy, which spans [-0.5, 0.5]). +void DrawCube( b3Transform transform, b3Vec3 scale, Vec4 baseColor ); +void DrawCubeEx( b3Transform transform, b3Vec3 scale, Vec4 baseColor, float metallic, float roughness, + TransparentShadowCast shadowCast ); + +// Sphere impostor. transform supplies the orientation (rotation drives the +// surface pattern so spin is visible) and the center (translation). +void DrawSphere( b3Transform transform, float radius, Vec4 baseColor ); +void DrawSphereEx( b3Transform transform, float radius, Vec4 baseColor, float metallic, float roughness, + TransparentShadowCast shadowCast ); + +// Capsule impostor. transform supplies the orientation (the capsule's local +X +// axis becomes the world long axis, rotation about local +X drives the +// cylinder/cap surface pattern so roll is visible) and the center +// (translation). halfLength is the distance from center to either cap +// center along local +X. radius is the cap radius. +void DrawCapsule( b3Transform transform, float halfLength, float radius, Vec4 baseColor ); +void DrawCapsuleEx( b3Transform transform, float halfLength, float radius, Vec4 baseColor, float metallic, float roughness, + TransparentShadowCast shadowCast ); + +// Solid shape wrappers over the impostor primitives. They take Box3D shape +// types and fold the shape-local frame into the transform, so samples draw +// straight from collision data. +void DrawSolidSphere( b3Transform transform, b3Sphere sphere, Vec4 color ); +void DrawSolidCapsule( b3Transform transform, b3Capsule capsule, Vec4 color ); + +// Convex hull wireframe. Each undirected edge once, in world space. +void DrawHull( b3Transform transform, const b3Hull* hull, Vec4 color ); + +// Plane as a unit wireframe quad through the point, plus a short normal and a dot. +void DrawPlane( b3Vec3 normal, b3Vec3 point, Vec4 color ); + +// All overlay submissions land in the renderer's per-frame overlay arenas +// and are drawn into the MSAA HDR scene target after opaque + sky, before +// the AgX tone map pass. Colors are straight (non-premultiplied) linear RGBA. + +void DrawLine( b3Vec3 a, b3Vec3 b, Vec4 color ); +void DrawLineEx( b3Vec3 a, b3Vec3 b, Vec4 color, float thickness, OverlayThicknessUnit thicknessUnit, + OverlayOcclusionMode occlusionMode ); + +// Debug point, size in pixels. Dimmed rather than hidden when occluded so +// contact and witness points stay visible through geometry. +void DrawPoint( b3Vec3 p, float size, Vec4 color ); +void DrawPointEx( b3Vec3 p, Vec4 color, float size, OverlayThicknessUnit sizeUnit, OverlayOcclusionMode occlusionMode ); + +// Single-arrow shaft from a to b with two short angled head segments at b. +// headLengthFrac is the head length as a fraction of the shaft length +void DrawArrow( b3Vec3 a, b3Vec3 b, Vec4 color ); +void DrawArrowEx( b3Vec3 a, b3Vec3 b, Vec4 color, float thickness, OverlayThicknessUnit thicknessUnit, + OverlayOcclusionMode occlusionMode, float headLengthFrac ); + +// Three orthogonal lines through center, total length size per axis, uniform color. +void DrawCross( b3Vec3 center, float size, Vec4 color ); +void DrawCrossEx( b3Vec3 center, float size, Vec4 color, float thickness, OverlayThicknessUnit thicknessUnit, + OverlayOcclusionMode occlusionMode ); + +// Wireframe AABB (12 edges) between world-space min and max corners. +void DrawAabb( b3Vec3 min, b3Vec3 max, Vec4 color ); +void DrawAabbEx( b3Vec3 min, b3Vec3 max, Vec4 color, float thickness, OverlayThicknessUnit thicknessUnit, + OverlayOcclusionMode occlusionMode ); + +// AABB wireframe expanded outward by `extension` on every side. +void DrawBounds( b3AABB bounds, float extension, Vec4 color ); + +// Draw RGB axes +void DrawAxes( b3Transform transform, float size ); +void DrawAxesEx( b3Transform transform, float size, float thickness, OverlayThicknessUnit thicknessUnit, + OverlayOcclusionMode occlusionMode ); + +// Planar overlay grid centered at `center`, lying in the plane defined by +// `normal`. `halfExtent` is the half-width per in-plane axis, `divisions` the +// cell count per axis. Emits 2 * (divisions + 1) lines along an orthonormal +// basis derived from the normal, so it is not pinned to a Y-up ground plane. +void DrawGrid( b3Vec3 center, b3Vec3 normal, float halfExtent, int divisions, Vec4 color ); + +// Gray ground grid in the XZ plane, `size` meters half-extent with 1 m cells. +void DrawGroundGrid( int size ); + +// Wireframe triangle: three overlay lines a -> b -> c -> a. +void DrawTriangle( b3Vec3 a, b3Vec3 b, b3Vec3 c, Vec4 color ); + +void DrawWireSphere( b3Transform transform, const b3Sphere* sphere, int segments, Vec4 color ); +void DrawWireCapsule( b3Transform transform, const b3Capsule* capsule, int segments, Vec4 color ); + +// printf-style world-space text label. The renderer projects with its latched camera. +void DrawWorldString( b3Vec3 point, Vec4 color, const char* format, ... ); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/samples/gfx/draw_overlay.h b/samples/gfx/draw_overlay.h new file mode 100644 index 0000000..877e1d5 --- /dev/null +++ b/samples/gfx/draw_overlay.h @@ -0,0 +1,37 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +#pragma once + +// How a line or point reacts when scene geometry sits in front of it. +typedef enum OverlayOcclusionMode +{ + // depth tested + OVERLAY_OCCLUSION_HIDE = 0, + + // reduced alpha + OVERLAY_OCCLUSION_DIM = 1, + + // screen-space dash pattern + OVERLAY_OCCLUSION_DASHED = 2, +} OverlayOcclusionMode; + +// How to interpret the `thickness` (lines) or `size` (points) argument +typedef enum OverlayThicknessUnit +{ + // screen-space pixels + OVERLAY_THICKNESS_PIXELS = 0, + + // world-space meters + OVERLAY_THICKNESS_WORLD = 1, +} OverlayThicknessUnit; + +// Whether a shape draw call participates in the shadow caster pass. +typedef enum TransparentShadowCast +{ + // regular shadow + TRANSPARENT_SHADOW_FULL = 0, + + // disable shadow + TRANSPARENT_SHADOW_NONE = 1, +} TransparentShadowCast; diff --git a/samples/gfx/edges.c b/samples/gfx/edges.c new file mode 100644 index 0000000..c11d23e --- /dev/null +++ b/samples/gfx/edges.c @@ -0,0 +1,349 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +#include "gfx/edges.h" + +#include "edge.glsl.h" +#include "box3d/types.h" +#include "gfx/geometry_registry.h" +#include "gfx/scene_target.h" + +// Two pipelines off the same shader: + +// pipelineMsaa: sample_count=SCENE_SAMPLE_COUNT, scene_target color+depth, +// for the opaque path (drawn inside the open MSAA scene pass). + +// pipelineTransparent: sample_count=1, RGBA16F + SG_PIXELFORMAT_DEPTH, for +// the transparent path (own pass against resolve + GTAO prepass depth). +// Note: the edges are not transparent, they are being drawn after transparent +// shapes, which looks good on transparent hulls. + +// Both share blend (premultiplied alpha) and depth state (GREATER_EQUAL, +// no write, reverse-Z, the VS adds zBias toward camera). +static struct +{ + sg_shader shader; + sg_pipeline pipelineMsaa; + sg_pipeline pipelineTransparent; + bool ready; +} s_edges; + +EdgeOverlayParams GetDefaultEdgeParams( void ) +{ + EdgeOverlayParams p; + p.enabled = true; + p.showHulls = true; + p.showMeshes = true; + p.showHeightfields = true; + p.showEdgeConvexity = false; + p.thicknessPx = 1.5f; + p.zBias = 1.0e-6f; + p.convexColor = MakeVec4( 0.1f, 0.8f, 0.1f, 0.75f ); + p.concaveColor = MakeVec4( 0.8f, 0.10f, 0.10f, 0.75f ); + p.flatColor = MakeVec4( 0.6f, 0.6f, 0.6f, 0.5f ); + return p; +} + +static void ApplyCommonPipelineState( sg_pipeline_desc* p ) +{ + p->shader = s_edges.shader; + p->index_type = SG_INDEXTYPE_NONE; + p->cull_mode = SG_CULLMODE_NONE; + p->colors[0].pixel_format = SG_PIXELFORMAT_RGBA16F; + p->color_count = 1; + p->colors[0].blend.enabled = true; + p->colors[0].blend.src_factor_rgb = SG_BLENDFACTOR_ONE; + p->colors[0].blend.dst_factor_rgb = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA; + p->colors[0].blend.op_rgb = SG_BLENDOP_ADD; + p->colors[0].blend.src_factor_alpha = SG_BLENDFACTOR_ONE; + p->colors[0].blend.dst_factor_alpha = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA; + p->colors[0].blend.op_alpha = SG_BLENDOP_ADD; + p->depth.compare = SG_COMPAREFUNC_GREATER_EQUAL; + p->depth.write_enabled = false; +} + +void InitEdges( void ) +{ + if ( s_edges.ready ) + { + return; + } + s_edges.shader = sg_make_shader( edge_edge_overlay_shader_desc( sg_query_backend() ) ); + + // MSAA pipeline, depth format mirrors the scene target's MSAA depth + // attachment (env.defaults.depth_format). + sg_pipeline_desc msaaPdesc = { 0 }; + ApplyCommonPipelineState( &msaaPdesc ); + msaaPdesc.depth.pixel_format = GetSceneTargetDepthFormat(); + msaaPdesc.sample_count = SCENE_SAMPLE_COUNT; + msaaPdesc.label = "edge_overlay_pipeline_msaa"; + s_edges.pipelineMsaa = sg_make_pipeline( &msaaPdesc ); + + // Transparent pipeline, single-sample, depth matches the GTAO prepass attachment + // (SG_PIXELFORMAT_DEPTH) that the post-resolve pass binds. + sg_pipeline_desc xpPdesc = { 0 }; + ApplyCommonPipelineState( &xpPdesc ); + xpPdesc.depth.pixel_format = SG_PIXELFORMAT_DEPTH; + xpPdesc.sample_count = 1; + xpPdesc.label = "edge_overlay_pipeline_transparent"; + s_edges.pipelineTransparent = sg_make_pipeline( &xpPdesc ); + + s_edges.ready = true; +} + +void ShutdownEdges( void ) +{ + if ( !s_edges.ready ) + { + return; + } + sg_destroy_pipeline( s_edges.pipelineTransparent ); + s_edges.pipelineTransparent.id = 0; + sg_destroy_pipeline( s_edges.pipelineMsaa ); + s_edges.pipelineMsaa.id = 0; + sg_destroy_shader( s_edges.shader ); + s_edges.shader.id = 0; + s_edges.ready = false; +} + +static inline Vec4 Premultiply( Vec4 c ) +{ + return MakeVec4( c.x * c.w, c.y * c.w, c.z * c.w, c.w ); +} + +// Per-batch policy: does the toggle want this batch drawn at all? +static bool IsBatchEnabled( const MeshEdgeBatch* b, const EdgeOverlayParams* p ) +{ + switch ( b->kind ) + { + case MESH_KIND_HULL: + // Hull edges on every hull, opaque and transparent. Opaque hulls + // pick up MSAA in the scene pass, transparent ones draw post-resolve. + return p->showHulls; + case MESH_KIND_MESH: + return p->showMeshes; + case MESH_KIND_HEIGHTFIELD: + return p->showHeightfields; + case MESH_KIND_UNKNOWN: + default: + return false; + } +} + +// Pack ub_frame + ub_pass + select pipeline + iterate batches. When +// `ArenaFilter` is ARENA_FILTER_BOTH, iterates every surviving batch +// and picks the matching instance view per batch (used by the MSAA path +// during the "transparent edges in MSAA pass" experiment). Otherwise restricts to +// the matching arena. +typedef enum ArenaFilter +{ + ARENA_FILTER_OPAQUE_ONLY = 0, + ARENA_FILTER_TRANSPARENT_ONLY, + ARENA_FILTER_BOTH, +} ArenaFilter; + +static void SubmitBatches( int width, int height, const Mat4* view, const Mat4* proj, sg_pipeline pip, sg_view opaqueInstanceView, + sg_view transparentInstanceView, ArenaFilter arenaFilter, const EdgeOverlayParams* params ) +{ + sg_apply_pipeline( pip ); + + edge_ub_frame_t uf = { 0 }; + uf.view_proj = MulMM4( *proj, *view ); + uf.viewport = + MakeVec4( (float)width, (float)height, width > 0 ? 1.0f / (float)width : 0.0f, height > 0 ? 1.0f / (float)height : 0.0f ); + sg_apply_uniforms( UB_edge_ub_frame, &SG_RANGE( uf ) ); + + // Mesh and heightfield edges color by convexity (or collapse to flat when + // convexity coloring is off). Hull edges ignore convexity and always draw + // in the hard-coded hull color, so every class maps to it. Pass colors are + // shared across a draw, so select per batch kind inside the loop. + edge_ub_pass_t passMesh = { 0 }; + if ( params->showEdgeConvexity ) + { + passMesh.convex_color = Premultiply( params->convexColor ); + passMesh.concave_color = Premultiply( params->concaveColor ); + passMesh.flat_color = Premultiply( params->flatColor ); + } + else + { + Vec4 flat = Premultiply( params->flatColor ); + passMesh.convex_color = flat; + passMesh.concave_color = flat; + passMesh.flat_color = flat; + } + + edge_ub_pass_t passHull = { 0 }; + + Vec4 hullEdgeColor = { 0.5f, 0.5f, 0.5f, 0.5f }; + Vec4 hull = Premultiply( hullEdgeColor ); + passHull.convex_color = hull; + passHull.concave_color = hull; + passHull.flat_color = hull; + + sg_view currentEdgeView = { SG_INVALID_ID }; + sg_view currentInstView = { SG_INVALID_ID }; + int currentPassKind = -1; // -1 none, 0 mesh colors, 1 hull color + + int batchCount = GetMeshEdgeBatchCount(); + for ( int i = 0; i < batchCount; ++i ) + { + MeshEdgeBatch b = GetMeshEdgeBatch( i ); + if ( arenaFilter == ARENA_FILTER_OPAQUE_ONLY && b.isTransparent ) + { + continue; + } + if ( arenaFilter == ARENA_FILTER_TRANSPARENT_ONLY && b.isTransparent == false ) + { + continue; + } + if ( b.instanceCount <= 0 ) + { + continue; + } + if ( b.edgeCount <= 0 ) + { + continue; + } + if ( IsBatchEnabled( &b, params ) == false ) + { + continue; + } + + int passKind = ( b.kind == MESH_KIND_HULL ) ? 1 : 0; + if ( passKind != currentPassKind ) + { + if ( passKind == 1 ) + { + sg_apply_uniforms( UB_edge_ub_pass, &SG_RANGE( passHull ) ); + } + else + { + sg_apply_uniforms( UB_edge_ub_pass, &SG_RANGE( passMesh ) ); + } + currentPassKind = passKind; + } + + sg_view instView = b.isTransparent ? transparentInstanceView : opaqueInstanceView; + if ( instView.id != currentInstView.id || b.edgeStorageView.id != currentEdgeView.id ) + { + sg_bindings bnd = { 0 }; + bnd.views[VIEW_edge_geom_instances] = instView; + bnd.views[VIEW_edge_edge_endpoints] = b.edgeStorageView; + sg_apply_bindings( &bnd ); + currentInstView = instView; + currentEdgeView = b.edgeStorageView; + } + + edge_ub_draw_t ud = { 0 }; + ud.inst_base[0] = b.firstInstance; + ud.edge_params = MakeVec4( params->thicknessPx, params->zBias, 0.0f, 0.0f ); + sg_apply_uniforms( UB_edge_ub_draw, &SG_RANGE( ud ) ); + + sg_draw( 0, 6 * b.edgeCount, b.instanceCount ); + } +} + +// Cheap pre-walk to avoid issuing pipeline / bindings / uniforms when no +// batch survives the filter. +static bool DoesAnyBatchSurvive( ArenaFilter arenaFilter, const EdgeOverlayParams* params ) +{ + const int batchCount = GetMeshEdgeBatchCount(); + for ( int i = 0; i < batchCount; ++i ) + { + const MeshEdgeBatch b = GetMeshEdgeBatch( i ); + if ( arenaFilter == ARENA_FILTER_OPAQUE_ONLY && b.isTransparent ) + continue; + if ( arenaFilter == ARENA_FILTER_TRANSPARENT_ONLY && !b.isTransparent ) + continue; + if ( b.instanceCount <= 0 ) + continue; + if ( b.edgeCount <= 0 ) + continue; + if ( IsBatchEnabled( &b, params ) ) + return true; + } + return false; +} + +// When true, the MSAA path draws BOTH opaque AND transparent edge batches, so +// transparent-hull edges also pick up 4x MSAA at the cost of the translucent body +// blending over them post-resolve. +// Result: rendering transparent hulls after their edges yields jaggies +#define EDGES_MSAA_INCLUDES_TRANSPARENT 0 + +// Mirror experiment: route ALL edge batches (opaque-arena meshes / +// heightfields as well as the transparent-arena hulls) through the +// post-resolve transparent path and skip the MSAA submission entirely. +// Edges lose 4x MSAA (they fall back to fwidth-based fragment AA) but +// they're guaranteed crisp on top of everything, including transparent +// hulls. +// Result: rendering edges for opaque meshes after MSAA resolve yields jaggies +// probably due to inconsistent AA on the edges and the MSAA opaque geometry. +#define EDGES_TRANSPARENT_INCLUDES_OPAQUE 0 + +// Conclusion: the split edge rendering is worth it. Must keep. + +#if EDGES_MSAA_INCLUDES_TRANSPARENT && EDGES_TRANSPARENT_INCLUDES_OPAQUE +#error "EDGES_MSAA_INCLUDES_TRANSPARENT and EDGES_TRANSPARENT_INCLUDES_OPAQUE are mutually exclusive" +#endif + +void RenderEdgesInMSAA( int width, int height, const Mat4* view, const Mat4* proj, sg_view opaqueInstanceView, + sg_view transparentInstanceView, const EdgeOverlayParams* params ) +{ + if ( !s_edges.ready || !params || !params->enabled ) + { + return; + } + + // Experiment drawing all edges after transparent shapes with no MSAA + if ( EDGES_TRANSPARENT_INCLUDES_OPAQUE ) + { + return; + } + + const ArenaFilter filter = EDGES_MSAA_INCLUDES_TRANSPARENT ? ARENA_FILTER_BOTH : ARENA_FILTER_OPAQUE_ONLY; + if ( !DoesAnyBatchSurvive( filter, params ) ) + { + return; + } + SubmitBatches( width, height, view, proj, s_edges.pipelineMsaa, opaqueInstanceView, transparentInstanceView, filter, params ); +} + +void RenderEdgesPostTransparent( int width, int height, const Mat4* view, const Mat4* proj, sg_view colorAttachView, + sg_view depthAttachView, sg_view opaqueInstanceView, sg_view transparentInstanceView, + const EdgeOverlayParams* params ) +{ + if ( !s_edges.ready || !params || !params->enabled ) + { + return; + } + + // Experiment drawing all edges in the MSAA scene, even for edges on transparent hulls. + if ( EDGES_MSAA_INCLUDES_TRANSPARENT ) + { + return; + } + const ArenaFilter filter = EDGES_TRANSPARENT_INCLUDES_OPAQUE ? ARENA_FILTER_BOTH : ARENA_FILTER_TRANSPARENT_ONLY; + if ( !DoesAnyBatchSurvive( filter, params ) ) + { + return; + } + + sg_pass pass = { 0 }; + pass.action.colors[0].load_action = SG_LOADACTION_LOAD; + pass.action.colors[0].store_action = SG_STOREACTION_STORE; + pass.action.depth.load_action = SG_LOADACTION_LOAD; + pass.action.depth.store_action = SG_STOREACTION_DONTCARE; + pass.attachments.colors[0] = colorAttachView; + pass.attachments.depth_stencil = depthAttachView; + pass.label = "edge_overlay_pass_transparent"; + sg_push_debug_group( "edges_transparent" ); + sg_begin_pass( &pass ); + sg_apply_viewport( 0, 0, width, height, true ); + + SubmitBatches( width, height, view, proj, s_edges.pipelineTransparent, opaqueInstanceView, transparentInstanceView, filter, + params ); + + sg_end_pass(); + sg_pop_debug_group(); +} diff --git a/samples/gfx/edges.h b/samples/gfx/edges.h new file mode 100644 index 0000000..d38d6fd --- /dev/null +++ b/samples/gfx/edges.h @@ -0,0 +1,71 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Renders per-shape edges for hulls, meshes, and heightfields registered in +// the geometry registry. Same shader / batching for both arenas. Split +// into two submission paths to match the silhouette quality of the +// rest of the scene: +// +// Opaque path (RenderEdgesInMSAA): opaque-arena batches (meshes, +// heightfields, opaque hulls if policy 1b is ever relaxed). Draws +// inside the caller's currently-open MSAA scene pass, picking up the +// same 4x MSAA as the opaque shapes. Pipeline tracks scene_target's +// color/depth formats and sample_count. +// +// Transparent path (RenderEdgesPostTransparent): transparent-arena batches +// (hulls per policy 1b). Opens its own single-sample pass against the +// resolved scene color + GTAO prepass depth, so edges sit on top of the +// transparent draws that have already blended into the resolve. MSAA +// isn't available here (the resolve already happened), the FS's +// fwidth-based AA does what it can. + +#pragma once + +#include "gfx/utility.h" +#include "sokol_gfx.h" + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef struct EdgeOverlayParams +{ + bool enabled; + bool showHulls; + bool showMeshes; + bool showHeightfields; + bool showEdgeConvexity; + float thicknessPx; + float zBias; // reverse-Z nudge toward camera, ~5e-5 is a good start + Vec4 convexColor; // straight (non-premultiplied) linear RGBA, premultiplied inside + Vec4 concaveColor; + Vec4 flatColor; +} EdgeOverlayParams; + +EdgeOverlayParams GetDefaultEdgeParams( void ); + +void InitEdges( void ); +void ShutdownEdges( void ); + +// Draw edge batches into the caller's currently-open render pass. The pass +// must be the MSAA scene pass (sceneTargetAttachments), the pipeline +// matches its color format (RGBA16F), depth format (sceneTargetDepthFormat), +// and sample_count (4). +void RenderEdgesInMSAA( int width, int height, const Mat4* view, const Mat4* proj, sg_view opaqueInstanceView, + sg_view transparentInstanceView, const EdgeOverlayParams* params ); + +// Open a single-sample render pass against (colorAttachView, depthAttachView) +// and draw transparent-arena edge batches. When the +// EDGES_TRANSPARENT_INCLUDES_OPAQUE experiment is enabled, opaque-arena +// batches are also drawn here (and the MSAA path becomes a no-op), so the +// caller must pass a valid opaqueInstanceView too. +void RenderEdgesPostTransparent( int width, int height, const Mat4* view, const Mat4* proj, sg_view colorAttachView, + sg_view depthAttachView, sg_view opaqueInstanceView, sg_view transparentInstanceView, + const EdgeOverlayParams* params ); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/samples/gfx/geometry_registry.c b/samples/gfx/geometry_registry.c new file mode 100644 index 0000000..c318b23 --- /dev/null +++ b/samples/gfx/geometry_registry.c @@ -0,0 +1,770 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +#include "gfx/geometry_registry.h" + +#include "geom.glsl.h" + +#include +#include +#include +#include + +#define MAX_REGISTRY_ENTRIES 256 +#define MAX_GEOM_INSTANCES_GLOBAL 65536 +#define INITIAL_PER_ENTRY_CAPACITY 8 + +typedef struct Entry +{ + uint32_t hash; + int refCount; // 0 means free + sg_buffer vbo; + sg_buffer ibo; + int indexCount; + MeshKind kind; // shape-kind tag, default UNKNOWN + + // edge overlay data. edgeCount == 0 and edgeBuf.id == SG_INVALID_ID + // means "no edges registered", HasEdges returns false. Otherwise + // edgeBuf is a storage-buffer-usage GPU buffer of 2*edgeCount EdgeVertex + // entries (two endpoints per edge), accessed via edgeStorageView. + sg_buffer edgeBuf; + sg_view edgeStorageView; + int edgeCount; + + // per-entry xp-arena first instance offset, captured during the + // xp upload loop. Valid for the rest of the frame when xpCount > 0. + int xpFirstInstance; + + // Per-frame CPU staging for the opaque path. instances grows on demand + // (doubling) so the first frame for a given geometry may allocate, + // later frames reuse the buffer. + geom_instance_t* instances; + int count; + int capacity; + + // Set during UploadMeshInstances. Valid for the rest of the frame. + int firstInstance; + + // transparent path. Parallel arena per entry, packed into the + // shared xp instance GPU buffer at upload time. + geom_instance_t* xpInstances; + int xpCount; + int xpCapacity; +} Entry; + +static struct +{ + Entry entries[MAX_REGISTRY_ENTRIES]; + int entryCount; // high-water mark, freed slots are reused + + // Shared GPU storage buffer for instance data across all entries. + sg_buffer instBuf; + sg_view instView; + + // Packing scratch: rebuilt every frame by UploadMeshInstances. + geom_instance_t* uploadScratch; + int uploadScratchCap; + + // Draw spans for the frame. Rebuilt by UploadMeshInstances. drawSpans + // holds positive-determinant runs (back-culled), mirrorDrawSpans holds + // negative-determinant runs (front-culled). A mesh entry with a mix of + // both contributes one span to each, so each list caps at one per entry. + MeshDrawSpan drawSpans[MAX_REGISTRY_ENTRIES]; + int drawSpanCount; + MeshDrawSpan mirrorDrawSpans[MAX_REGISTRY_ENTRIES]; + int mirrorDrawSpanCount; + + // transparent path. xpInstBuf holds at most + // MAX_GEOM_XP_INSTANCES_GLOBAL instances, xpDraws[] is the per- + // instance draw list the renderer's back-to-front sort consumes. + sg_buffer xpInstBuf; + sg_view xpInstView; + geom_instance_t* xpUploadScratch; + int xpUploadScratchCap; + MeshXpInstance xpDraws[MAX_GEOM_XP_INSTANCES_GLOBAL]; + int xpDrawCount; + + // per-entry edge batches, rebuilt by UploadMeshInstances. + // Two slots per entry (opaque + xp) so the cap is 2 x MAX_REGISTRY. + MeshEdgeBatch edgeBatches[2 * MAX_REGISTRY_ENTRIES]; + int edgeBatchCount; +} s_geom; + +void CreateMeshRegistry( void ) +{ + sg_buffer_desc bdesc = { 0 }; + bdesc.usage.storage_buffer = true; + bdesc.usage.stream_update = true; + bdesc.size = (size_t)MAX_GEOM_INSTANCES_GLOBAL * sizeof( geom_instance_t ); + bdesc.label = "geom_instances"; + s_geom.instBuf = sg_make_buffer( &bdesc ); + + sg_view_desc vdesc = { 0 }; + vdesc.storage_buffer.buffer = s_geom.instBuf; + vdesc.label = "geom_instances_view"; + s_geom.instView = sg_make_view( &vdesc ); + + sg_buffer_desc xpbdesc = { 0 }; + xpbdesc.usage.storage_buffer = true; + xpbdesc.usage.stream_update = true; + xpbdesc.size = (size_t)MAX_GEOM_XP_INSTANCES_GLOBAL * sizeof( geom_instance_t ); + xpbdesc.label = "geom_instances_xp"; + s_geom.xpInstBuf = sg_make_buffer( &xpbdesc ); + + sg_view_desc xpvdesc = { 0 }; + xpvdesc.storage_buffer.buffer = s_geom.xpInstBuf; + xpvdesc.label = "geom_instances_xp_view"; + s_geom.xpInstView = sg_make_view( &xpvdesc ); + + s_geom.uploadScratch = NULL; + s_geom.uploadScratchCap = 0; + s_geom.xpUploadScratch = NULL; + s_geom.xpUploadScratchCap = 0; + s_geom.entryCount = 0; + s_geom.drawSpanCount = 0; + s_geom.mirrorDrawSpanCount = 0; + s_geom.xpDrawCount = 0; + s_geom.edgeBatchCount = 0; +} + +void DestroyMeshRegistry( void ) +{ + for ( int i = 0; i < s_geom.entryCount; ++i ) + { + Entry* e = &s_geom.entries[i]; + if ( e->refCount > 0 ) + { + sg_destroy_buffer( e->ibo ); + sg_destroy_buffer( e->vbo ); + if ( e->edgeCount > 0 ) + { + sg_destroy_view( e->edgeStorageView ); + sg_destroy_buffer( e->edgeBuf ); + } + } + free( e->instances ); + e->instances = NULL; + e->capacity = 0; + free( e->xpInstances ); + e->xpInstances = NULL; + e->xpCapacity = 0; + } + s_geom.entryCount = 0; + + free( s_geom.uploadScratch ); + s_geom.uploadScratch = NULL; + s_geom.uploadScratchCap = 0; + free( s_geom.xpUploadScratch ); + s_geom.xpUploadScratch = NULL; + s_geom.xpUploadScratchCap = 0; + + sg_destroy_view( s_geom.xpInstView ); + sg_destroy_buffer( s_geom.xpInstBuf ); + sg_destroy_view( s_geom.instView ); + sg_destroy_buffer( s_geom.instBuf ); +} + +MeshHandle FindMesh( uint32_t hash ) +{ + if ( hash == 0u ) + { + return InvalidMeshHandle(); + } + + for ( int i = 0; i < s_geom.entryCount; ++i ) + { + const Entry* e = &s_geom.entries[i]; + if ( e->refCount > 0 && e->hash == hash ) + { + MeshHandle h = { i, hash }; + return h; + } + } + + return InvalidMeshHandle(); +} + +static int FindFreeSlot( void ) +{ + for ( int i = 0; i < s_geom.entryCount; ++i ) + { + if ( s_geom.entries[i].refCount == 0 ) + { + return i; + } + } + if ( s_geom.entryCount >= MAX_REGISTRY_ENTRIES ) + { + return -1; + } + return s_geom.entryCount++; +} + +MeshHandle RegisterMesh( uint32_t hash, const MeshVertex* vertices, int vertexCount, const uint32_t* indices, + int indexCount, const char* debugLabel ) +{ + assert( hash != 0u ); + assert( vertexCount > 0 ); + assert( indexCount > 0 ); + + const int slot = FindFreeSlot(); + if ( slot < 0 ) + { + fprintf( stderr, "error: registry full (cap=%d), dropping geometry\n", MAX_REGISTRY_ENTRIES ); + return InvalidMeshHandle(); + } + + Entry* e = &s_geom.entries[slot]; + + sg_buffer_desc vbDesc = { 0 }; + vbDesc.usage.vertex_buffer = true; + vbDesc.usage.immutable = true; + vbDesc.data.ptr = vertices; + vbDesc.data.size = (size_t)vertexCount * sizeof( MeshVertex ); + vbDesc.label = debugLabel ? debugLabel : "geom_vbo"; + e->vbo = sg_make_buffer( &vbDesc ); + + sg_buffer_desc ibDesc = { 0 }; + ibDesc.usage.index_buffer = true; + ibDesc.usage.immutable = true; + ibDesc.data.ptr = indices; + ibDesc.data.size = (size_t)indexCount * sizeof( uint32_t ); + ibDesc.label = debugLabel ? debugLabel : "geom_ibo"; + e->ibo = sg_make_buffer( &ibDesc ); + + e->hash = hash; + e->refCount = 1; + e->indexCount = indexCount; + e->kind = MESH_KIND_UNKNOWN; + e->edgeBuf.id = SG_INVALID_ID; + e->edgeStorageView.id = SG_INVALID_ID; + e->edgeCount = 0; + e->xpFirstInstance = 0; + e->count = 0; + e->xpCount = 0; + // instances/xpInstances/capacities persist across re-registration in + // the same slot. + + MeshHandle h = { slot, hash }; + return h; +} + +void RegisterMeshEdges( MeshHandle h, const EdgeVertex* edges, int edgeCount, const char* debugLabel ) +{ + if ( !IsMeshHandleValid( h ) ) + { + return; + } + if ( edges == NULL || edgeCount <= 0 ) + { + return; + } + Entry* e = &s_geom.entries[h.index]; + if ( e->refCount == 0 || e->hash != h.hash ) + { + return; + } + assert( e->edgeCount == 0 && "RegisterMeshEdges already called for this entry" ); + + sg_buffer_desc bdesc = { 0 }; + bdesc.usage.storage_buffer = true; + bdesc.usage.immutable = true; + bdesc.data.ptr = edges; + bdesc.data.size = (size_t)( 2 * edgeCount ) * sizeof( EdgeVertex ); + bdesc.label = debugLabel ? debugLabel : "geom_edges"; + e->edgeBuf = sg_make_buffer( &bdesc ); + + sg_view_desc vdesc = { 0 }; + vdesc.storage_buffer.buffer = e->edgeBuf; + vdesc.label = debugLabel ? debugLabel : "geom_edges_view"; + e->edgeStorageView = sg_make_view( &vdesc ); + + e->edgeCount = edgeCount; +} + +bool HasEdges( MeshHandle h ) +{ + if ( !IsMeshHandleValid( h ) ) + { + return false; + } + const Entry* e = &s_geom.entries[h.index]; + if ( e->refCount == 0 || e->hash != h.hash ) + { + return false; + } + return e->edgeCount > 0; +} + +int GetEdgeCount( MeshHandle h ) +{ + if ( !IsMeshHandleValid( h ) ) + { + return 0; + } + const Entry* e = &s_geom.entries[h.index]; + if ( e->refCount == 0 || e->hash != h.hash ) + { + return 0; + } + return e->edgeCount; +} + +sg_view GetEdgeStorageView( MeshHandle h ) +{ + sg_view invalid = { SG_INVALID_ID }; + if ( !IsMeshHandleValid( h ) ) + { + return invalid; + } + const Entry* e = &s_geom.entries[h.index]; + if ( e->refCount == 0 || e->hash != h.hash || e->edgeCount == 0 ) + { + return invalid; + } + return e->edgeStorageView; +} + +void SetMeshKind( MeshHandle h, MeshKind kind ) +{ + if ( !IsMeshHandleValid( h ) ) + { + return; + } + Entry* e = &s_geom.entries[h.index]; + if ( e->refCount == 0 || e->hash != h.hash ) + { + return; + } + e->kind = kind; +} + +MeshKind GetMeshKind( MeshHandle h ) +{ + if ( !IsMeshHandleValid( h ) ) + { + return MESH_KIND_UNKNOWN; + } + const Entry* e = &s_geom.entries[h.index]; + if ( e->refCount == 0 || e->hash != h.hash ) + { + return MESH_KIND_UNKNOWN; + } + return e->kind; +} + +bool GetMeshBuffers( MeshHandle h, MeshBuffers* out ) +{ + if ( !IsMeshHandleValid( h ) || !out ) + { + return false; + } + const Entry* e = &s_geom.entries[h.index]; + if ( e->refCount == 0 || e->hash != h.hash ) + { + return false; + } + out->vbo = e->vbo; + out->ibo = e->ibo; + out->indexCount = e->indexCount; + return true; +} + +void AddMeshReference( MeshHandle h ) +{ + if ( !IsMeshHandleValid( h ) ) + { + return; + } + Entry* e = &s_geom.entries[h.index]; + assert( e->refCount > 0 && e->hash == h.hash ); + e->refCount += 1; +} + +void ReleaseMeshReference( MeshHandle h ) +{ + if ( !IsMeshHandleValid( h ) ) + { + return; + } + Entry* e = &s_geom.entries[h.index]; + assert( e->refCount > 0 && e->hash == h.hash ); + e->refCount -= 1; + if ( e->refCount == 0 ) + { + sg_destroy_buffer( e->ibo ); + sg_destroy_buffer( e->vbo ); + if ( e->edgeCount > 0 ) + { + sg_destroy_view( e->edgeStorageView ); + sg_destroy_buffer( e->edgeBuf ); + } + e->hash = 0u; + e->indexCount = 0; + e->edgeBuf.id = SG_INVALID_ID; + e->edgeStorageView.id = SG_INVALID_ID; + e->edgeCount = 0; + e->count = 0; + e->xpCount = 0; + // Keep instances/xpInstances/capacities for the slot's next tenant. + } +} + +void ResetFrameForMeshes( void ) +{ + for ( int i = 0; i < s_geom.entryCount; ++i ) + { + s_geom.entries[i].count = 0; + s_geom.entries[i].xpCount = 0; + } + s_geom.drawSpanCount = 0; + s_geom.mirrorDrawSpanCount = 0; + s_geom.xpDrawCount = 0; + s_geom.edgeBatchCount = 0; +} + +static void PackMat4ToInstance( const Mat4* transform, b3Vec3 scale, Vec4 baseColor, float metallic, float roughness, + MeshMaterialMode materialMode, float gridCellSize, TransparentShadowCast shadowCast, + geom_instance_t* inst ) +{ + // 3x4 affine pack identical to PackXformRows in renderer.c. Rotation + // rows in .xyz, translation column in .w of each row. + inst->xform_row0.x = transform->cx.x; + inst->xform_row0.y = transform->cy.x; + inst->xform_row0.z = transform->cz.x; + inst->xform_row0.w = transform->cw.x; + inst->xform_row1.x = transform->cx.y; + inst->xform_row1.y = transform->cy.y; + inst->xform_row1.z = transform->cz.y; + inst->xform_row1.w = transform->cw.y; + inst->xform_row2.x = transform->cx.z; + inst->xform_row2.y = transform->cy.z; + inst->xform_row2.z = transform->cz.z; + inst->xform_row2.w = transform->cw.z; + + inst->base_color = baseColor; + + inst->scale.x = scale.x; + inst->scale.y = scale.y; + inst->scale.z = scale.z; + inst->scale.w = 0.0f; + + // overload material.w with the shadow-cast bit for SOLID shapes. + // GROUND_GRID's gridCellSize stays put, the geom FS reads material.w + // only inside the GROUND_GRID branch (`v_material.z > 0.5`), so SOLID + // shapes can repurpose the slot. Ground shapes are always opaque + + // FULL by usage, the dual use is safe by construction. Renderer-side + // shadow-cast queries go through MeshXpInstance.shadowCast, not + // material.w, so this packing is purely about keeping the GPU + // instance-struct stride unchanged. + const bool isGround = ( materialMode == MESH_MATERIAL_MODE_GROUND_GRID ); + inst->material.x = metallic; + inst->material.y = roughness; + inst->material.z = (float)materialMode; + inst->material.w = isGround ? gridCellSize : ( ( shadowCast == TRANSPARENT_SHADOW_FULL ) ? 1.0f : 0.0f ); +} + +static b3Vec3 GetOriginFromInstance( const geom_instance_t* inst ) +{ + return (b3Vec3){ inst->xform_row0.w, inst->xform_row1.w, inst->xform_row2.w }; +} + +void AppendMesh( MeshHandle h, b3Transform transform, b3Vec3 scale, Vec4 baseColor, float metallic, float roughness, + MeshMaterialMode materialMode, float gridCellSize, TransparentShadowCast shadowCast ) +{ + if ( !IsMeshHandleValid( h ) ) + { + return; + } + Entry* e = &s_geom.entries[h.index]; + if ( e->refCount == 0 || e->hash != h.hash ) + { + // Stale handle, slot got reused. Caller messed up retain/release. + return; + } + + const bool xp = baseColor.w < 1.0f; + geom_instance_t** arr = xp ? &e->xpInstances : &e->instances; + int* cnt = xp ? &e->xpCount : &e->count; + int* cap = xp ? &e->xpCapacity : &e->capacity; + + if ( *cnt >= *cap ) + { + const int newCap = *cap == 0 ? INITIAL_PER_ENTRY_CAPACITY : *cap * 2; + geom_instance_t* grown = (geom_instance_t*)realloc( *arr, (size_t)newCap * sizeof( geom_instance_t ) ); + if ( !grown ) + { + fprintf( stderr, "error: per-entry%s grow failed (newCap=%d)\n", xp ? "(xp)" : "", newCap ); + return; + } + *arr = grown; + *cap = newCap; + } + Mat4 m = MakeMat4FromTransform( transform, b3Vec3_one ); + PackMat4ToInstance( &m, scale, baseColor, metallic, roughness, materialMode, gridCellSize, shadowCast, + &( *arr )[( *cnt )++] ); +} + +int UploadMeshInstances( void ) +{ + // Opaque pack + int total = 0; + for ( int i = 0; i < s_geom.entryCount; ++i ) + { + total += s_geom.entries[i].count; + } + s_geom.drawSpanCount = 0; + if ( total > MAX_GEOM_INSTANCES_GLOBAL ) + { + fprintf( stderr, "error: %d opaque instances exceeds global cap %d\n", total, MAX_GEOM_INSTANCES_GLOBAL ); + total = MAX_GEOM_INSTANCES_GLOBAL; + } + int opaqueCursor = 0; + if ( total > 0 ) + { + if ( total > s_geom.uploadScratchCap ) + { + geom_instance_t* grown = (geom_instance_t*)realloc( s_geom.uploadScratch, (size_t)total * sizeof( geom_instance_t ) ); + if ( !grown ) + { + fprintf( stderr, "error: upload scratch grow failed\n" ); + return 0; + } + s_geom.uploadScratch = grown; + s_geom.uploadScratchCap = total; + } + + for ( int i = 0; i < s_geom.entryCount && opaqueCursor < total; ++i ) + { + Entry* e = &s_geom.entries[i]; + if ( e->refCount == 0 || e->count == 0 ) + { + continue; + } + int take = e->count; + if ( opaqueCursor + take > total ) + { + take = total - opaqueCursor; + } + + // Stable-partition the run, positive-determinant instances first + // then mirror-scaled ones. Rotation is proper so sign(scale.x*y*z) + // is the winding sign. The two sub-runs stay contiguous, the + // renderer draws the front part back-culled and the tail (mirror) + // front-culled. + geom_instance_t* dst = &s_geom.uploadScratch[opaqueCursor]; + int posCount = 0; + for ( int k = 0; k < take; ++k ) + { + const geom_instance_t* inst = &e->instances[k]; + if ( inst->scale.x * inst->scale.y * inst->scale.z >= 0.0f ) + { + dst[posCount++] = *inst; + } + } + int negCount = 0; + for ( int k = 0; k < take; ++k ) + { + const geom_instance_t* inst = &e->instances[k]; + if ( inst->scale.x * inst->scale.y * inst->scale.z < 0.0f ) + { + dst[posCount + negCount++] = *inst; + } + } + e->firstInstance = opaqueCursor; + + if ( posCount > 0 ) + { + MeshDrawSpan span; + span.vbo = e->vbo; + span.ibo = e->ibo; + span.indexCount = e->indexCount; + span.firstInstance = opaqueCursor; + span.instanceCount = posCount; + s_geom.drawSpans[s_geom.drawSpanCount++] = span; + } + if ( negCount > 0 ) + { + MeshDrawSpan span; + span.vbo = e->vbo; + span.ibo = e->ibo; + span.indexCount = e->indexCount; + span.firstInstance = opaqueCursor + posCount; + span.instanceCount = negCount; + s_geom.mirrorDrawSpans[s_geom.mirrorDrawSpanCount++] = span; + } + + // Edge batch covers the whole run, partition order is irrelevant + // to the edge pass (each instance draws via firstInstance + index). + if ( e->edgeCount > 0 ) + { + MeshEdgeBatch eb; + eb.kind = e->kind; + eb.edgeStorageView = e->edgeStorageView; + eb.edgeCount = e->edgeCount; + eb.firstInstance = opaqueCursor; + eb.instanceCount = take; + eb.isTransparent = false; + s_geom.edgeBatches[s_geom.edgeBatchCount++] = eb; + } + + opaqueCursor += take; + } + + sg_range r; + r.ptr = s_geom.uploadScratch; + r.size = (size_t)opaqueCursor * sizeof( geom_instance_t ); + sg_update_buffer( s_geom.instBuf, &r ); + } + + // Transparent pack + int xpTotal = 0; + for ( int i = 0; i < s_geom.entryCount; ++i ) + { + xpTotal += s_geom.entries[i].xpCount; + } + s_geom.xpDrawCount = 0; + if ( xpTotal > MAX_GEOM_XP_INSTANCES_GLOBAL ) + { + fprintf( stderr, "error: %d transparent instances exceeds cap %d\n", xpTotal, MAX_GEOM_XP_INSTANCES_GLOBAL ); + xpTotal = MAX_GEOM_XP_INSTANCES_GLOBAL; + } + int xpCursor = 0; + if ( xpTotal > 0 ) + { + if ( xpTotal > s_geom.xpUploadScratchCap ) + { + geom_instance_t* grown = + (geom_instance_t*)realloc( s_geom.xpUploadScratch, (size_t)xpTotal * sizeof( geom_instance_t ) ); + if ( !grown ) + { + fprintf( stderr, "error: xp upload scratch grow failed\n" ); + return opaqueCursor; + } + s_geom.xpUploadScratch = grown; + s_geom.xpUploadScratchCap = xpTotal; + } + + // Walk each entry's xpInstances and emit one xpDraws entry per + // instance. The xp draw list is a flat per-instance enumeration, + // the renderer's back-to-front sort consumes individual entries, + // not per-entry spans (transparent draws can't share a single + // sg_draw across entries with different vbo/ibo). + for ( int i = 0; i < s_geom.entryCount && xpCursor < xpTotal; ++i ) + { + Entry* e = &s_geom.entries[i]; + if ( e->refCount == 0 || e->xpCount == 0 ) + { + continue; + } + int take = e->xpCount; + if ( xpCursor + take > xpTotal ) + { + take = xpTotal - xpCursor; + } + memcpy( &s_geom.xpUploadScratch[xpCursor], e->xpInstances, (size_t)take * sizeof( geom_instance_t ) ); + e->xpFirstInstance = xpCursor; + for ( int k = 0; k < take && s_geom.xpDrawCount < MAX_GEOM_XP_INSTANCES_GLOBAL; ++k ) + { + const geom_instance_t* src = &e->xpInstances[k]; + MeshXpInstance d; + d.vbo = e->vbo; + d.ibo = e->ibo; + d.indexCount = e->indexCount; + d.firstInstance = xpCursor + k; + d.origin = GetOriginFromInstance( src ); + // shadowCast is packed into material.w for SOLID shapes, + // GROUND_GRID can't be transparent in practice (ground + // shapes are submitted opaque), so reading material.w as + // the cast bit is safe for everything that lands here. + d.shadowCast = src->material.w; + s_geom.xpDraws[s_geom.xpDrawCount++] = d; + } + + // Edge batch for this entry's xp run. The edge pass draws all + // xp instances of an entry in a single sg_draw, it doesn't + // need per-instance back-to-front ordering (depth test handles + // occlusion against opaque scene, edges over transparent + // shapes blend additively without ordering concerns). + if ( e->edgeCount > 0 ) + { + MeshEdgeBatch eb; + eb.kind = e->kind; + eb.edgeStorageView = e->edgeStorageView; + eb.edgeCount = e->edgeCount; + eb.firstInstance = xpCursor; + eb.instanceCount = take; + eb.isTransparent = true; + s_geom.edgeBatches[s_geom.edgeBatchCount++] = eb; + } + + xpCursor += take; + } + + sg_range xr; + xr.ptr = s_geom.xpUploadScratch; + xr.size = (size_t)xpCursor * sizeof( geom_instance_t ); + sg_update_buffer( s_geom.xpInstBuf, &xr ); + } + + return opaqueCursor + xpCursor; +} + +int GetMeshDrawSpanCount( void ) +{ + return s_geom.drawSpanCount; +} + +MeshDrawSpan GetMeshDrawSpan( int i ) +{ + assert( i >= 0 && i < s_geom.drawSpanCount ); + return s_geom.drawSpans[i]; +} + +int GetMeshMirrorDrawSpanCount( void ) +{ + return s_geom.mirrorDrawSpanCount; +} + +MeshDrawSpan GetMeshMirrorDrawSpan( int i ) +{ + assert( i >= 0 && i < s_geom.mirrorDrawSpanCount ); + return s_geom.mirrorDrawSpans[i]; +} + +sg_view GetMeshInstanceView( void ) +{ + return s_geom.instView; +} + +int GetTransparentMeshInstanceCount( void ) +{ + return s_geom.xpDrawCount; +} + +MeshXpInstance GetTransparentMeshInstance( int i ) +{ + assert( i >= 0 && i < s_geom.xpDrawCount ); + return s_geom.xpDraws[i]; +} + +sg_view GetTransparentMeshInstanceView( void ) +{ + return s_geom.xpInstView; +} + +int GetMeshEntryCount( void ) +{ + return s_geom.entryCount; +} + +int GetMeshEdgeBatchCount( void ) +{ + return s_geom.edgeBatchCount; +} + +MeshEdgeBatch GetMeshEdgeBatch( int i ) +{ + assert( i >= 0 && i < s_geom.edgeBatchCount ); + return s_geom.edgeBatches[i]; +} diff --git a/samples/gfx/geometry_registry.h b/samples/gfx/geometry_registry.h new file mode 100644 index 0000000..e689c31 --- /dev/null +++ b/samples/gfx/geometry_registry.h @@ -0,0 +1,243 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Ref-counted GPU buffer store for triangle geometries (convex hulls, +// triangle meshes, heightfields). Owned by the renderer +// Keyed by uint32_t content hash for Box3D shapes we +// pass through b3Hull.hash / b3MeshData.hash / b3HeightField.hash +// +// Lifecycle: +// +// handle = FindMesh(hash) +// if (!IsMeshHandleValid(handle)) { +// // Build CPU verts + indices, then: +// handle = RegisterMesh(hash, verts, vc, index, ic, "label"); +// } else { +// AddMeshReference(handle); +// } +// // ...later, when the owning shape is destroyed: +// ReleaseMeshReference(handle); +// +// Per-frame: +// +// ResetFrameForMeshes(); // reset all entry counts +// AppendMesh(handle, &transform, scale, color); // many times, across handles +// +// Renderer drains via GetMeshDrawSpanCount + GetMeshDrawSpan. +// +// All instances across all entries land in one shared GPU storage buffer. +// Each draw call rebinds the entry's vbo/ibo and sets `inst_base` (the +// offset into the global instance array) via ub_draw so the shader can +// index correctly. sokol_gfx's sg_draw has no first_instance parameter, +// so the offset is plumbed as a per-draw uniform. + +#pragma once + +#include "gfx/draw_overlay.h" +#include "gfx/utility.h" +#include "sokol_gfx.h" + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +// Upper bound on transparent mesh instances drained in a frame. Shared so the +// renderer can size its sort scratch to match the registry cap. +#define MAX_GEOM_XP_INSTANCES_GLOBAL ( 16 * 1024 ) + +typedef struct MeshHandle +{ + int index; // -1 means invalid + uint32_t hash; // for cheap validation against index reuse +} MeshHandle; + +static inline MeshHandle InvalidMeshHandle( void ) +{ + MeshHandle h = { -1, 0u }; + return h; +} + +static inline bool IsMeshHandleValid( MeshHandle h ) +{ + return h.index >= 0; +} + +// Per-vertex data uploaded to the GPU. +typedef struct MeshVertex +{ + float position[3]; + float normal[3]; +} MeshVertex; + +// Per-edge-endpoint data for the edge overlay. Two consecutive entries +// per edge (the two endpoints). `flag` carries the Box3D edge classification +// as 0.0 = concave, 1.0 = convex/face boundary, 2.0 = flat (coplanar), used +// by the FS to pick between the concave/convex/flat color uniforms. Stored as +// a float (not uint) so the shader struct can be a flat vec4, sidesteps +// std430 vec3+uint padding ambiguity across GLSL/HLSL/MSL cross-compilers. +typedef struct EdgeVertex +{ + float position[3]; + float flag; +} EdgeVertex; + +// One draw span returned by the registry to the renderer. Spans are +// produced in registry-entry order. The renderer iterates and issues one +// sg_draw per span. +typedef struct MeshDrawSpan +{ + sg_buffer vbo; + sg_buffer ibo; + int indexCount; + int firstInstance; + int instanceCount; +} MeshDrawSpan; + +// Shape kind tag carried by a registry entry +typedef enum MeshKind +{ + MESH_KIND_UNKNOWN = 0, + MESH_KIND_HULL, + MESH_KIND_MESH, + MESH_KIND_HEIGHTFIELD, +} MeshKind; + +// Per-entry edge-draw batch produced by UploadMeshInstances. One batch +// per (entry x arena) with non-empty instance count and registered edges: +// up to two batches per entry (opaque + transparent). `firstInstance` +// indexes the opaque buffer when `isXp == false`, the xp buffer otherwise, +// the edge pass picks the matching storage view via +// GetMeshInstanceView / GetTransparentMeshInstanceView. +typedef struct MeshEdgeBatch +{ + MeshKind kind; + sg_view edgeStorageView; + int edgeCount; + int firstInstance; + int instanceCount; + bool isTransparent; +} MeshEdgeBatch; + +// One transparent geom instance, ready to feed into the back-to-front +// sort and a per-instance draw. `firstInstance` indexes the shared +// transparent geom buffer (bound via GetTransparentMeshInstanceView). `origin` is +// the world-space position of the instance, recovered from xform_row*.w. +// The renderer uses it as the back-to-front sort key. `shadowCast` is 1.0 +// when SHADOW_FULL, 0.0 otherwise (packed from the instance's material.z +// so the renderer doesn't have to repeat the unpack). +typedef struct MeshXpInstance +{ + sg_buffer vbo; + sg_buffer ibo; + int indexCount; + int firstInstance; + b3Vec3 origin; + float shadowCast; +} MeshXpInstance; + +void CreateMeshRegistry( void ); +void DestroyMeshRegistry( void ); + +MeshHandle FindMesh( uint32_t hash ); + +MeshHandle RegisterMesh( uint32_t hash, const MeshVertex* vertices, int vertexCount, const uint32_t* indices, + int indexCount, const char* debugLabel ); + +// Optional: register an edge list for a geometry already registered via +// RegisterMesh. Must be called at most once per registration (i.e. between +// RegisterMesh and the matching ReleaseMeshReference that drops refCount to 0). +// `edges` points to `2 * edgeCount` EdgeVertex entries (two endpoints per +// edge, consecutive). Storage-buffer-backed and immutable on the GPU. Caller +// is free to free the input array after this returns. Safe no-op if `h` is +// invalid. +void RegisterMeshEdges( MeshHandle h, const EdgeVertex* edges, int edgeCount, const char* debugLabel ); + +// Edge data queries used by the edge overlay pass. +bool HasEdges( MeshHandle h ); +int GetEdgeCount( MeshHandle h ); +sg_view GetEdgeStorageView( MeshHandle h ); + +// Shape-kind tag, see MeshKind enum above. Safe no-op on invalid handle. +void SetMeshKind( MeshHandle h, MeshKind kind ); +MeshKind GetMeshKind( MeshHandle h ); + +// Direct GPU buffer accessor, used by passes that need to draw a single +// registered geometry by handle (e.g. highlight mask issues one draw +// per selected hull, bypassing the per-frame instance arenas). Writes +// (vbo, ibo, indexCount) into *out and returns true. Returns false + +// leaves *out untouched if the handle is invalid. +typedef struct MeshBuffers +{ + sg_buffer vbo; + sg_buffer ibo; + int indexCount; +} MeshBuffers; + +bool GetMeshBuffers( MeshHandle h, MeshBuffers* out ); + +void AddMeshReference( MeshHandle h ); +void ReleaseMeshReference( MeshHandle h ); + +void ResetFrameForMeshes( void ); + +// Material modes packed into the instance buffer's material.z slot. The +// fragment shader branches on this to either feed baseColor straight into +// the BRDF or run a procedural-grid shader first (used for ground planes +// tagged via the Box3D adapter). +typedef enum MeshMaterialMode +{ + MESH_MATERIAL_MODE_SOLID = 0, + MESH_MATERIAL_MODE_GROUND_GRID = 1, +} MeshMaterialMode; + +void AppendMesh( MeshHandle h, b3Transform transform, b3Vec3 scale, Vec4 baseColor, float metallic, float roughness, + MeshMaterialMode materialMode, float gridCellSize, TransparentShadowCast shadowCast ); + +// Pack per-entry instances into the global GPU buffer. Called once per +// frame by the renderer before draw. Returns the total instance count +// (opaque + transparent combined, transparent instances live in a +// separate GPU buffer accessed through GetTransparentMeshInstanceView). +int UploadMeshInstances( void ); + +int GetMeshDrawSpanCount( void ); + +MeshDrawSpan GetMeshDrawSpan( int i ); + +// Mirror spans carry negative-determinant (mirror-scaled) instances. Their +// flipped winding needs the opposite cull face, so the renderer draws them +// with a front-cull pipeline after the back-cull pass over the normal spans. +// Usually empty, only a few sample scenes mirror a mesh. +int GetMeshMirrorDrawSpanCount( void ); + +MeshDrawSpan GetMeshMirrorDrawSpan( int i ); + +// Bound to the geom pipeline by the renderer. Exposed so renderer.c can +// bind a single view across all draws without recreating it per span. +sg_view GetMeshInstanceView( void ); + +// Transparent geom queries. Returns the count of transparent geom +// instances submitted this frame (after UploadMeshInstances) and the +// per-instance metadata for each. The renderer mixes these with cube/ +// sphere/capsule transparent instances in its back-to-front sort, then +// issues one sg_draw per entry using inst_base = firstInstance. +int GetTransparentMeshInstanceCount( void ); +MeshXpInstance GetTransparentMeshInstance( int i ); +sg_view GetTransparentMeshInstanceView( void ); + +// Per-entry edge-draw batches built during UploadMeshInstances. +// Up to two batches per entry (opaque + xp) when both arenas are non-empty +// and the entry has edges registered. The edge pass iterates these in +// arbitrary order, depth-test handles occlusion. +int GetMeshEdgeBatchCount( void ); +MeshEdgeBatch GetMeshEdgeBatch( int i ); + +// Total registry entry count for diagnostics. +int GetMeshEntryCount( void ); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/samples/gfx/gtao.c b/samples/gfx/gtao.c new file mode 100644 index 0000000..2e622d8 --- /dev/null +++ b/samples/gfx/gtao.c @@ -0,0 +1,890 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +#include "gfx/gtao.h" + +#include "gtao_denoise.glsl.h" +#include "gtao_main_pass.glsl.h" +#include "gtao_prefilter_depth.glsl.h" + +#include + +// Owned targets for the GTAO pipeline: +// +// * Depth pre-pass D32F image (`prepassDepthImage`), rasterizer / +// early-Z attachment, never sampled as a texture but re-attached as +// the depth_stencil of the transparent pass (LOAD + GREATER test, +// no depth write). Lives alongside the R32F color attachment to give +// the rasterizer a proper depth buffer for closest-fragment selection, +// the GTAO trace itself reads linear view-z out of the color +// attachment, not this. +// * Linear-depth R32F image (`linearDepthImage`), color attachment + +// sample. Filled by the depth_only_* pipelines with positive linear +// view-space depth. Source for the prefiltered-depth chain and +// MainPass's in-place normal reconstruction taps (which read raw +// depth, not the prefiltered chain, mirrors MainPass.esf:122). +// * Prefiltered-depth R32F mip chain (`prefilterDepthImage`, 5 mips, +// storage_image), populated by `PrefilterDepth`. Each mip has +// its own writeonly storage_image view, a single full-chain texture +// view feeds the MainPass trace samples (textureLod at a computed +// mip per sample). +// * Edges R32F image (`edgesImage`, storage_image), written by +// MainPass alongside the noisy AO. Carries 4 packed edge gradients +// per pixel consumed by every Denoise dispatch. +// * Two ping-pong R32F AO targets (`noisy0Image`, `noisy1Image`, +// storage_image + texture). MainPass writes the raw noisy term into +// `noisy0`. Denoise pass 0 reads `noisy0`, writes `noisy1`. Denoise +// pass 1 reads `noisy1`, writes `noisy0`. The final Denoise +// dispatch reads `noisy0` and writes `result` with the +// XE_GTAO_OCCLUSION_TERM_SCALE (1.5) rescale applied on store. +// * `result` R32F image, full-res AO output sampled by lit shaders. +// Has BOTH color_attachment (for the clear-to-1.0 fallback path) and +// storage_image (so the Denoise final apply can imageStore into it). +// +// All targets are single-sample. MSAA-resolved depth would be per-pixel +// filtered and break the GTAO trace's expectation of analytic surface +// samples at each pixel, re-rendering the depth pre-pass single-sample +// costs one extra vertex pass which is acceptable for a debug renderer. + +#define GTAO_PREFILTER_MIP_COUNT 5 + +static struct +{ + int width; + int height; + + sg_image prepassDepthImage; + sg_view prepassDepthAttachView; + + sg_image linearDepthImage; + sg_view linearDepthAttachView; + sg_view linearDepthSampleView; + + sg_image prefilterDepthImage; // R32F, 5 mips, storage_image + sg_view prefilterMipStorageView[GTAO_PREFILTER_MIP_COUNT]; + sg_view prefilterChainSampleView; + + sg_image edgesImage; // R32F, storage_image + sg_view edgesStorageView; + sg_view edgesSampleView; + + // Ping-pong noisy AO targets. R32F + storage_image + texture. + // MainPass writes noisy0 directly. Denoise then bounces noisy0 <-> noisy1 + // and the final apply lands in result. + sg_image noisy0Image; + sg_view noisy0StorageView; + sg_view noisy0SampleView; + sg_image noisy1Image; + sg_view noisy1StorageView; + sg_view noisy1SampleView; + + sg_image resultImage; // R32F + sg_view resultAttachView; // color attach (clear-to-1 fallback) + sg_view resultStorageView; // storage_image (Denoise final apply writes via imageStore) + sg_view resultSampleView; + + sg_sampler linearSampler; // linear-filter, clamp, lit shaders sample tex_ao with this + sg_sampler pointSampler; // point-clamp, bound by every GTAO compute (texelFetch doesn't filter, textureLod on the prefilter + // chain needs point so neighbouring mip texels don't bilerp) + + sg_shader prefilterShader; + sg_pipeline prefilterPipeline; + + sg_shader mainPassShader; + sg_pipeline mainPassPipeline; + + sg_shader denoiseShader; + sg_pipeline denoisePipeline; + + GtaoTraceParams params; // XeGTAO trace knobs +} s_gtao; + +// XeGTAO continuous-knob defaults from XeGTAO_Types.esh:107-114, mirrored +// here so a "reset" button in the panel can restore them without +// recompiling. Quality defaults to High (3 x 3 slices/steps), not XeGTAO's +// Ultra (9 x 3), High is the ship default. Ultra is one combo step away. +static const GtaoTraceParams k_gtao_default_params = { + .radius = 0.5f, + .falloff = 0.615f, + .radiusMul = 1.457f, + .finalValuePow = 2.2f, + .denoiseBlurBeta = 1.2f, + .sampleDistPow = 2.0f, + .thinOcclComp = 0.0f, + .depthMipSampOffset = 3.30f, + .quality = AO_QUALITY_HIGH, + .denoisePassCount = 3, +}; + +// Slice and step counts per quality tier. Internal, the public knob is quality. +static void GtaoQualityToCounts( AmbientOcclusionQuality quality, int* sliceCount, int* stepsPerSlice ) +{ + switch ( quality ) + { + case AO_QUALITY_MEDIUM: + *sliceCount = 2; + *stepsPerSlice = 2; + break; + case AO_QUALITY_ULTRA: + *sliceCount = 9; + *stepsPerSlice = 3; + break; + case AO_QUALITY_HIGH: + default: + *sliceCount = 3; + *stepsPerSlice = 3; + break; + } +} + +void InitAmbientOcclusion( void ) +{ + s_gtao.width = 0; + s_gtao.height = 0; + s_gtao.params = k_gtao_default_params; + + sg_sampler_desc linDesc = { 0 }; + linDesc.min_filter = SG_FILTER_LINEAR; + linDesc.mag_filter = SG_FILTER_LINEAR; + linDesc.mipmap_filter = SG_FILTER_NEAREST; + linDesc.wrap_u = SG_WRAP_CLAMP_TO_EDGE; + linDesc.wrap_v = SG_WRAP_CLAMP_TO_EDGE; + linDesc.wrap_w = SG_WRAP_CLAMP_TO_EDGE; + linDesc.label = "gtao_linear_sampler"; + s_gtao.linearSampler = sg_make_sampler( &linDesc ); + + // Point-clamp sampler bound by the prefilter compute. The shader + // only ever reads via texelFetch (which ignores the sampler's + // filter mode), but sokol-gfx requires a sampler binding for every + // texture binding, point/clamp is the safe default. + sg_sampler_desc pointDesc = { 0 }; + pointDesc.min_filter = SG_FILTER_NEAREST; + pointDesc.mag_filter = SG_FILTER_NEAREST; + pointDesc.mipmap_filter = SG_FILTER_NEAREST; + pointDesc.wrap_u = SG_WRAP_CLAMP_TO_EDGE; + pointDesc.wrap_v = SG_WRAP_CLAMP_TO_EDGE; + pointDesc.wrap_w = SG_WRAP_CLAMP_TO_EDGE; + pointDesc.label = "gtao_point_sampler"; + s_gtao.pointSampler = sg_make_sampler( &pointDesc ); + + // PrefilterDepth compute pipeline. Built once at init, its bindings + // are all view-driven and resize without needing a new shader/pipeline. + s_gtao.prefilterShader = sg_make_shader( gtao_prefilter_depth_prog_shader_desc( sg_query_backend() ) ); + + sg_pipeline_desc ppdesc = { 0 }; + ppdesc.compute = true; + ppdesc.shader = s_gtao.prefilterShader; + ppdesc.label = "gtao_prefilter_pipeline"; + s_gtao.prefilterPipeline = sg_make_pipeline( &ppdesc ); + + // MainPass compute pipeline. Same view-driven bindings idiom. + s_gtao.mainPassShader = sg_make_shader( gtao_main_pass_prog_shader_desc( sg_query_backend() ) ); + + sg_pipeline_desc mpdesc = { 0 }; + mpdesc.compute = true; + mpdesc.shader = s_gtao.mainPassShader; + mpdesc.label = "gtao_main_pass_pipeline"; + s_gtao.mainPassPipeline = sg_make_pipeline( &mpdesc ); + + // Denoise compute pipeline. One pipeline drives all three + // dispatches, the per-dispatch finalApply flag is delivered through + // the dedicated ub_denoise UBO (binding=1). Source/destination images + // are swapped between dispatches via sg_apply_bindings. + s_gtao.denoiseShader = sg_make_shader( gtao_denoise_prog_shader_desc( sg_query_backend() ) ); + + sg_pipeline_desc dndesc = { 0 }; + dndesc.compute = true; + dndesc.shader = s_gtao.denoiseShader; + dndesc.label = "gtao_denoise_pipeline"; + s_gtao.denoisePipeline = sg_make_pipeline( &dndesc ); +} + +static void destroyTargets( void ) +{ + if ( s_gtao.resultSampleView.id ) + { + sg_destroy_view( s_gtao.resultSampleView ); + s_gtao.resultSampleView.id = 0; + } + if ( s_gtao.resultStorageView.id ) + { + sg_destroy_view( s_gtao.resultStorageView ); + s_gtao.resultStorageView.id = 0; + } + if ( s_gtao.resultAttachView.id ) + { + sg_destroy_view( s_gtao.resultAttachView ); + s_gtao.resultAttachView.id = 0; + } + if ( s_gtao.resultImage.id ) + { + sg_destroy_image( s_gtao.resultImage ); + s_gtao.resultImage.id = 0; + } + if ( s_gtao.noisy1SampleView.id ) + { + sg_destroy_view( s_gtao.noisy1SampleView ); + s_gtao.noisy1SampleView.id = 0; + } + if ( s_gtao.noisy1StorageView.id ) + { + sg_destroy_view( s_gtao.noisy1StorageView ); + s_gtao.noisy1StorageView.id = 0; + } + if ( s_gtao.noisy1Image.id ) + { + sg_destroy_image( s_gtao.noisy1Image ); + s_gtao.noisy1Image.id = 0; + } + if ( s_gtao.noisy0SampleView.id ) + { + sg_destroy_view( s_gtao.noisy0SampleView ); + s_gtao.noisy0SampleView.id = 0; + } + if ( s_gtao.noisy0StorageView.id ) + { + sg_destroy_view( s_gtao.noisy0StorageView ); + s_gtao.noisy0StorageView.id = 0; + } + if ( s_gtao.noisy0Image.id ) + { + sg_destroy_image( s_gtao.noisy0Image ); + s_gtao.noisy0Image.id = 0; + } + if ( s_gtao.edgesSampleView.id ) + { + sg_destroy_view( s_gtao.edgesSampleView ); + s_gtao.edgesSampleView.id = 0; + } + if ( s_gtao.edgesStorageView.id ) + { + sg_destroy_view( s_gtao.edgesStorageView ); + s_gtao.edgesStorageView.id = 0; + } + if ( s_gtao.edgesImage.id ) + { + sg_destroy_image( s_gtao.edgesImage ); + s_gtao.edgesImage.id = 0; + } + if ( s_gtao.prefilterChainSampleView.id ) + { + sg_destroy_view( s_gtao.prefilterChainSampleView ); + s_gtao.prefilterChainSampleView.id = 0; + } + for ( int i = 0; i < GTAO_PREFILTER_MIP_COUNT; ++i ) + { + if ( s_gtao.prefilterMipStorageView[i].id ) + { + sg_destroy_view( s_gtao.prefilterMipStorageView[i] ); + s_gtao.prefilterMipStorageView[i].id = 0; + } + } + if ( s_gtao.prefilterDepthImage.id ) + { + sg_destroy_image( s_gtao.prefilterDepthImage ); + s_gtao.prefilterDepthImage.id = 0; + } + if ( s_gtao.linearDepthSampleView.id ) + { + sg_destroy_view( s_gtao.linearDepthSampleView ); + s_gtao.linearDepthSampleView.id = 0; + } + if ( s_gtao.linearDepthAttachView.id ) + { + sg_destroy_view( s_gtao.linearDepthAttachView ); + s_gtao.linearDepthAttachView.id = 0; + } + if ( s_gtao.linearDepthImage.id ) + { + sg_destroy_image( s_gtao.linearDepthImage ); + s_gtao.linearDepthImage.id = 0; + } + if ( s_gtao.prepassDepthAttachView.id ) + { + sg_destroy_view( s_gtao.prepassDepthAttachView ); + s_gtao.prepassDepthAttachView.id = 0; + } + if ( s_gtao.prepassDepthImage.id ) + { + sg_destroy_image( s_gtao.prepassDepthImage ); + s_gtao.prepassDepthImage.id = 0; + } +} + +void ShutdownAmbientOcclusion( void ) +{ + destroyTargets(); + if ( s_gtao.denoisePipeline.id ) + { + sg_destroy_pipeline( s_gtao.denoisePipeline ); + s_gtao.denoisePipeline.id = 0; + } + if ( s_gtao.denoiseShader.id ) + { + sg_destroy_shader( s_gtao.denoiseShader ); + s_gtao.denoiseShader.id = 0; + } + if ( s_gtao.mainPassPipeline.id ) + { + sg_destroy_pipeline( s_gtao.mainPassPipeline ); + s_gtao.mainPassPipeline.id = 0; + } + if ( s_gtao.mainPassShader.id ) + { + sg_destroy_shader( s_gtao.mainPassShader ); + s_gtao.mainPassShader.id = 0; + } + if ( s_gtao.prefilterPipeline.id ) + { + sg_destroy_pipeline( s_gtao.prefilterPipeline ); + s_gtao.prefilterPipeline.id = 0; + } + if ( s_gtao.prefilterShader.id ) + { + sg_destroy_shader( s_gtao.prefilterShader ); + s_gtao.prefilterShader.id = 0; + } + if ( s_gtao.pointSampler.id ) + { + sg_destroy_sampler( s_gtao.pointSampler ); + s_gtao.pointSampler.id = 0; + } + if ( s_gtao.linearSampler.id ) + { + sg_destroy_sampler( s_gtao.linearSampler ); + s_gtao.linearSampler.id = 0; + } + s_gtao.width = 0; + s_gtao.height = 0; +} + +void ResizeGTAO( int width, int height ) +{ + if ( width <= 0 || height <= 0 ) + { + return; + } + if ( width == s_gtao.width && height == s_gtao.height && s_gtao.linearDepthImage.id ) + { + return; + } + + destroyTargets(); + + s_gtao.width = width; + s_gtao.height = height; + + // Transient D32F depth-stencil attachment (rasterizer-only) + sg_image_desc didesc = { 0 }; + didesc.usage.depth_stencil_attachment = true; + didesc.width = width; + didesc.height = height; + didesc.pixel_format = SG_PIXELFORMAT_DEPTH; + didesc.sample_count = 1; + didesc.label = "gtao_prepass_depth"; + s_gtao.prepassDepthImage = sg_make_image( &didesc ); + + sg_view_desc davdesc = { 0 }; + davdesc.depth_stencil_attachment.image = s_gtao.prepassDepthImage; + davdesc.label = "gtao_prepass_depth_attach"; + s_gtao.prepassDepthAttachView = sg_make_view( &davdesc ); + + // R32F linear-depth color attachment + sg_image_desc ldesc = { 0 }; + ldesc.usage.color_attachment = true; + ldesc.width = width; + ldesc.height = height; + ldesc.pixel_format = SG_PIXELFORMAT_R32F; + ldesc.sample_count = 1; + ldesc.label = "gtao_linear_depth"; + s_gtao.linearDepthImage = sg_make_image( &ldesc ); + + sg_view_desc lavdesc = { 0 }; + lavdesc.color_attachment.image = s_gtao.linearDepthImage; + lavdesc.label = "gtao_linear_depth_attach"; + s_gtao.linearDepthAttachView = sg_make_view( &lavdesc ); + + sg_view_desc lsvdesc = { 0 }; + lsvdesc.texture.image = s_gtao.linearDepthImage; + lsvdesc.label = "gtao_linear_depth_sample"; + s_gtao.linearDepthSampleView = sg_make_view( &lsvdesc ); + + // R32F prefiltered linear-depth chain (5 mips, storage_image) + // The chain dimensions cover only the in-bounds region: mip N is + // `max(1, w >> N)` x `max(1, h >> N)`. The shader's per-thread early- + // out skips writes past the viewport bound, so mips don't need + // padding to a multiple of 16 for correctness, sokol-gfx sizes the + // sub-mips itself from num_mipmaps. + sg_image_desc pdesc = { 0 }; + pdesc.usage.storage_image = true; + pdesc.width = width; + pdesc.height = height; + pdesc.num_mipmaps = GTAO_PREFILTER_MIP_COUNT; + pdesc.pixel_format = SG_PIXELFORMAT_R32F; + pdesc.sample_count = 1; + pdesc.label = "gtao_prefilter_depth"; + s_gtao.prefilterDepthImage = sg_make_image( &pdesc ); + + for ( int i = 0; i < GTAO_PREFILTER_MIP_COUNT; ++i ) + { + sg_view_desc msvdesc = { 0 }; + msvdesc.storage_image.image = s_gtao.prefilterDepthImage; + msvdesc.storage_image.mip_level = i; + msvdesc.label = "gtao_prefilter_mip_storage"; + s_gtao.prefilterMipStorageView[i] = sg_make_view( &msvdesc ); + } + + sg_view_desc pcsvdesc = { 0 }; + pcsvdesc.texture.image = s_gtao.prefilterDepthImage; + + // mip_levels.count == 0 means "all remaining mips" (sokol-gfx + // convention), leaving the rest zero-initialized gives a view over + // the full chain that MainPass can textureLod into. + pcsvdesc.label = "gtao_prefilter_chain_sample"; + s_gtao.prefilterChainSampleView = sg_make_view( &pcsvdesc ); + + // R32F edges target + // storage_image so MainPass can imageStore the packed edge gradients + // per pixel, texture sample view alone is the eventual Denoise read + // path. Allocated now even though the sample view goes + // unused for one commit cycle. The alternative is conditioning + // MainPass's edges output, and that's worse than the storage cost. + // + // Format deviation from Esoterica's R8 UNORM: sokol-shdc / SPIRV- + // Cross only allow r32f/r32i/r32ui plus rgba/rg{32,16} variants for + // storage_image access formats (D3D11 typed-UAV constraint). R32F + // is the cheapest single-channel fp format that survives cross- + // compilation, the packed-edges value range stays in [0,1] so + // XeGTAO_UnpackEdges is unchanged. + sg_image_desc edesc = { 0 }; + edesc.usage.storage_image = true; + edesc.width = width; + edesc.height = height; + edesc.pixel_format = SG_PIXELFORMAT_R32F; + edesc.sample_count = 1; + edesc.label = "gtao_edges"; + s_gtao.edgesImage = sg_make_image( &edesc ); + + sg_view_desc esvdesc = { 0 }; + esvdesc.storage_image.image = s_gtao.edgesImage; + esvdesc.label = "gtao_edges_storage"; + s_gtao.edgesStorageView = sg_make_view( &esvdesc ); + + sg_view_desc etxvdesc = { 0 }; + etxvdesc.texture.image = s_gtao.edgesImage; + etxvdesc.label = "gtao_edges_sample"; + s_gtao.edgesSampleView = sg_make_view( &etxvdesc ); + + // R32F noisy AO ping-pong targets + // Two textures with identical descriptors. MainPass writes noisy0, + // the three Denoise dispatches bounce noisy0 -> noisy1 -> noisy0 + // and then noisy0 -> result. Format deviation same rationale as + // edges + result above (sokol-shdc storage_image access-format + // restriction). + sg_image_desc ndesc = { 0 }; + ndesc.usage.storage_image = true; + ndesc.width = width; + ndesc.height = height; + ndesc.pixel_format = SG_PIXELFORMAT_R32F; + ndesc.sample_count = 1; + + ndesc.label = "gtao_noisy0"; + s_gtao.noisy0Image = sg_make_image( &ndesc ); + ndesc.label = "gtao_noisy1"; + s_gtao.noisy1Image = sg_make_image( &ndesc ); + + sg_view_desc n0stvdesc = { 0 }; + n0stvdesc.storage_image.image = s_gtao.noisy0Image; + n0stvdesc.label = "gtao_noisy0_storage"; + s_gtao.noisy0StorageView = sg_make_view( &n0stvdesc ); + + sg_view_desc n0txvdesc = { 0 }; + n0txvdesc.texture.image = s_gtao.noisy0Image; + n0txvdesc.label = "gtao_noisy0_sample"; + s_gtao.noisy0SampleView = sg_make_view( &n0txvdesc ); + + sg_view_desc n1stvdesc = { 0 }; + n1stvdesc.storage_image.image = s_gtao.noisy1Image; + n1stvdesc.label = "gtao_noisy1_storage"; + s_gtao.noisy1StorageView = sg_make_view( &n1stvdesc ); + + sg_view_desc n1txvdesc = { 0 }; + n1txvdesc.texture.image = s_gtao.noisy1Image; + n1txvdesc.label = "gtao_noisy1_sample"; + s_gtao.noisy1SampleView = sg_make_view( &n1txvdesc ); + + // R32F `result` AO target + // Dual usage: color_attachment for the ClearAmbientOcclusion path + // (sg_begin_pass with SG_LOADACTION_CLEAR), storage_image for + // MainPass's imageStore output. sokol-gfx is OK with both flags on + // the same image, each consumer binds via its own sg_view. + // + // Format deviation from Esoterica's R16F: same sokol-shdc storage_ + // image access-format restriction as `edges` above (D3D11 typed-UAV + // constraint). R32F doubles the storage cost but is a transparent + // drop-in for the float visibility term. Lit shaders sampling + // tex_ao read .x as a float either way. + sg_image_desc rdesc = { 0 }; + rdesc.usage.color_attachment = true; + rdesc.usage.storage_image = true; + rdesc.width = width; + rdesc.height = height; + rdesc.pixel_format = SG_PIXELFORMAT_R32F; + rdesc.sample_count = 1; + rdesc.label = "gtao_result"; + s_gtao.resultImage = sg_make_image( &rdesc ); + + sg_view_desc ravdesc = { 0 }; + ravdesc.color_attachment.image = s_gtao.resultImage; + ravdesc.label = "gtao_result_attach"; + s_gtao.resultAttachView = sg_make_view( &ravdesc ); + + sg_view_desc rstvdesc = { 0 }; + rstvdesc.storage_image.image = s_gtao.resultImage; + rstvdesc.label = "gtao_result_storage"; + s_gtao.resultStorageView = sg_make_view( &rstvdesc ); + + sg_view_desc rsvdesc = { 0 }; + rsvdesc.texture.image = s_gtao.resultImage; + rsvdesc.label = "gtao_result_sample"; + s_gtao.resultSampleView = sg_make_view( &rsvdesc ); +} + +sg_view GetLinearDepthAttachmentView( void ) +{ + return s_gtao.linearDepthAttachView; +} + +sg_view GetPrepassDepthAttachmentView( void ) +{ + return s_gtao.prepassDepthAttachView; +} + +sg_view GetLinearDepthSampleView( void ) +{ + return s_gtao.linearDepthSampleView; +} + +sg_view GetPrefilterDepthSampleView( void ) +{ + return s_gtao.prefilterChainSampleView; +} + +sg_view GetAOResultSampleView( void ) +{ + return s_gtao.resultSampleView; +} + +sg_sampler GetAOLinearSampler( void ) +{ + return s_gtao.linearSampler; +} + +void ClearAmbientOcclusion( void ) +{ + if ( !s_gtao.resultImage.id ) + { + fprintf( stderr, "[gtao/error] ClearAmbientOcclusion called before ResizeGTAO succeeded\n" ); + return; + } + sg_pass pass = { 0 }; + pass.action.colors[0].load_action = SG_LOADACTION_CLEAR; + pass.action.colors[0].clear_value.r = 1.0f; + pass.action.colors[0].clear_value.g = 1.0f; + pass.action.colors[0].clear_value.b = 1.0f; + pass.action.colors[0].clear_value.a = 1.0f; + pass.action.colors[0].store_action = SG_STOREACTION_STORE; + pass.attachments.colors[0] = s_gtao.resultAttachView; + sg_push_debug_group( "gtao_clear_white" ); + sg_begin_pass( &pass ); + sg_end_pass(); + sg_pop_debug_group(); +} + +// Derived inputs that all three GTAO shaders' UBOs are projections of. +// Computed once per dispatch from the camera + current trace params, +// each per-shader builder picks the subset it needs. +// +// NoiseIndex deliberately absent, the main pass hardcodes 0 at the +// SpatioTemporalNoise call site (no TAA). Same goes for +// DepthUnpackConsts and CameraTanHalfFOV: our source depth is already +// positive linear view-Z so XeGTAO_ScreenSpaceToViewSpaceDepth is the +// identity and none of the consumed helpers ever touch them. +typedef struct +{ + int viewportWidth; + int viewportHeight; + b3Vec2 viewportPixelSize; + b3Vec2 ndcToViewMul; + b3Vec2 ndcToViewAdd; + b3Vec2 ndcToViewMul_x_PixelSize; + GtaoTraceParams params; +} GtaoUboInputs; + +// `proj` is column-major (Mat4 cx/cy/cz/cw), cx.x = 1/tanHalfFOVX and +// cy.y = 1/tanHalfFOVY for a standard reverse-Z perspective matrix as +// produced by Camera::Proj. The NDC-to-view factors are Esoterica's +// post-fix form (no spurious double-0.5, see the plan note on Known +// Esoterica bugs we deliberately fix). +static GtaoUboInputs ComputeUboInputs( const Mat4* proj, int viewportWidth, int viewportHeight ) +{ + GtaoUboInputs in; + in.viewportWidth = viewportWidth; + in.viewportHeight = viewportHeight; + in.viewportPixelSize = (b3Vec2){ 1.0f / (float)viewportWidth, 1.0f / (float)viewportHeight }; + + const float tanHalfFOVY = 1.0f / proj->cy.y; + const float tanHalfFOVX = 1.0f / proj->cx.x; + in.ndcToViewMul = (b3Vec2){ tanHalfFOVX * 2.0f, tanHalfFOVY * -2.0f }; + in.ndcToViewAdd = (b3Vec2){ tanHalfFOVX * -1.0f, tanHalfFOVY * 1.0f }; + in.ndcToViewMul_x_PixelSize = (b3Vec2){ + in.ndcToViewMul.x * in.viewportPixelSize.x, + in.ndcToViewMul.y * in.viewportPixelSize.y, + }; + + in.params = s_gtao.params; + return in; +} + +static gtao_prefilter_depth_ub_gtao_t buildPrefilterUbo( const GtaoUboInputs* in ) +{ + gtao_prefilter_depth_ub_gtao_t c = { 0 }; + c.ViewportSize[0] = in->viewportWidth; + c.ViewportSize[1] = in->viewportHeight; + c.EffectRadius = in->params.radius; + c.EffectFalloffRange = in->params.falloff; + c.RadiusMultiplier = in->params.radiusMul; + return c; +} + +static gtao_main_pass_ub_gtao_t MakeMainPassUbo( const GtaoUboInputs* in ) +{ + gtao_main_pass_ub_gtao_t c = { 0 }; + c.ViewportSize[0] = in->viewportWidth; + c.ViewportSize[1] = in->viewportHeight; + c.ViewportPixelSize = in->viewportPixelSize; + c.NDCToViewMul = in->ndcToViewMul; + c.NDCToViewAdd = in->ndcToViewAdd; + c.NDCToViewMul_x_PixelSize = in->ndcToViewMul_x_PixelSize; + c.EffectRadius = in->params.radius; + c.EffectFalloffRange = in->params.falloff; + c.RadiusMultiplier = in->params.radiusMul; + c.FinalValuePower = in->params.finalValuePow; + c.SampleDistributionPower = in->params.sampleDistPow; + c.ThinOccluderCompensation = in->params.thinOcclComp; + c.DepthMIPSamplingOffset = in->params.depthMipSampOffset; + int sliceCount, stepsPerSlice; + GtaoQualityToCounts( in->params.quality, &sliceCount, &stepsPerSlice ); + c.SliceCount = (float)sliceCount; + c.StepsPerSlice = (float)stepsPerSlice; + return c; +} + +static gtao_denoise_ub_gtao_t MakeDenoiseUbo( const GtaoUboInputs* in ) +{ + gtao_denoise_ub_gtao_t c = { 0 }; + c.ViewportSize[0] = in->viewportWidth; + c.ViewportSize[1] = in->viewportHeight; + c.DenoiseBlurBeta = in->params.denoiseBlurBeta; + return c; +} + +GtaoTraceParams GetGtaoTraceParams( void ) +{ + return s_gtao.params; +} +void SetGtaoTraceParams( GtaoTraceParams p ) +{ + if ( p.denoisePassCount < 1 ) + { + p.denoisePassCount = 1; + } + if ( p.denoisePassCount > GTAO_MAX_DENOISE_PASSES ) + { + p.denoisePassCount = GTAO_MAX_DENOISE_PASSES; + } + s_gtao.params = p; +} + +GtaoTraceParams GetDefaultGtaoTraceParams( void ) +{ + return k_gtao_default_params; +} + +AmbientOcclusionQuality GetAOQualityForPixelScale( float dpiScale ) +{ + // Retina-class panels (DPI scale ~2x) render densely enough that High's + // per-pixel sample noise stays sub-perceptual. + const float highMinDpiScale = 2.0f; + return ( dpiScale >= highMinDpiScale ) ? AO_QUALITY_HIGH : AO_QUALITY_ULTRA; +} + +void PrefilterDepth( const Mat4* proj, int viewportWidth, int viewportHeight ) +{ + if ( !s_gtao.prefilterDepthImage.id ) + { + fprintf( stderr, "[gtao/error] PrefilterDepth called before ResizeGTAO succeeded\n" ); + return; + } + + GtaoUboInputs inputs = ComputeUboInputs( proj, viewportWidth, viewportHeight ); + gtao_prefilter_depth_ub_gtao_t consts = buildPrefilterUbo( &inputs ); + + sg_pass pass = { 0 }; + pass.compute = true; + pass.label = "gtao_prefilter_depth"; + sg_push_debug_group( "gtao_prefilter_depth" ); + sg_begin_pass( &pass ); + + sg_apply_pipeline( s_gtao.prefilterPipeline ); + + sg_bindings bindings = { 0 }; + bindings.views[VIEW_gtao_prefilter_depth_out_depth0] = s_gtao.prefilterMipStorageView[0]; + bindings.views[VIEW_gtao_prefilter_depth_out_depth1] = s_gtao.prefilterMipStorageView[1]; + bindings.views[VIEW_gtao_prefilter_depth_out_depth2] = s_gtao.prefilterMipStorageView[2]; + bindings.views[VIEW_gtao_prefilter_depth_out_depth3] = s_gtao.prefilterMipStorageView[3]; + bindings.views[VIEW_gtao_prefilter_depth_out_depth4] = s_gtao.prefilterMipStorageView[4]; + bindings.views[VIEW_gtao_prefilter_depth_tex_src_depth] = s_gtao.linearDepthSampleView; + bindings.samplers[SMP_gtao_prefilter_depth_smp_src_depth] = s_gtao.pointSampler; + sg_apply_bindings( &bindings ); + + sg_apply_uniforms( UB_gtao_prefilter_depth_ub_gtao, &SG_RANGE( consts ) ); + + // 16x16 destination pixels per workgroup (8x8 threads x 2x2 per + // thread). Round up so partially-covered groups still execute. + const int groupsX = ( viewportWidth + 15 ) / 16; + const int groupsY = ( viewportHeight + 15 ) / 16; + sg_dispatch( groupsX, groupsY, 1 ); + + sg_end_pass(); + sg_pop_debug_group(); +} + +void ComputeNoisyResult( const Mat4* proj, int viewportWidth, int viewportHeight ) +{ + if ( !s_gtao.noisy0Image.id || !s_gtao.edgesImage.id || !s_gtao.prefilterDepthImage.id ) + { + fprintf( stderr, "[gtao/error] ComputeNoisyResult called before ResizeGTAO succeeded\n" ); + return; + } + + GtaoUboInputs inputs = ComputeUboInputs( proj, viewportWidth, viewportHeight ); + gtao_main_pass_ub_gtao_t consts = MakeMainPassUbo( &inputs ); + + sg_pass pass = { 0 }; + pass.compute = true; + pass.label = "gtao_main_pass"; + sg_push_debug_group( "gtao_main_pass" ); + sg_begin_pass( &pass ); + + sg_apply_pipeline( s_gtao.mainPassPipeline ); + + sg_bindings bindings = { 0 }; + // MainPass writes the raw noisy term into noisy0 (the first ping-pong + // target). The Denoise dispatches that follow chain noisy0 -> noisy1 + // -> noisy0 -> result. tex_raw_depth is the full-res linearDepth. + bindings.views[VIEW_gtao_main_pass_out_noisy_ao] = s_gtao.noisy0StorageView; + bindings.views[VIEW_gtao_main_pass_out_edges] = s_gtao.edgesStorageView; + bindings.views[VIEW_gtao_main_pass_tex_raw_depth] = s_gtao.linearDepthSampleView; + bindings.views[VIEW_gtao_main_pass_tex_prefilter_depth] = s_gtao.prefilterChainSampleView; + bindings.samplers[SMP_gtao_main_pass_smp_point_clamp] = s_gtao.pointSampler; + sg_apply_bindings( &bindings ); + + sg_apply_uniforms( UB_gtao_main_pass_ub_gtao, &SG_RANGE( consts ) ); + + // 8x8 numthreads, 1 destination pixel per thread. Round up so the + // partially-covered groups still execute, the shader's + // bounds-guarded early-out skips OOB threads. + const int groupsX = ( viewportWidth + 7 ) / 8; + const int groupsY = ( viewportHeight + 7 ) / 8; + sg_dispatch( groupsX, groupsY, 1 ); + + sg_end_pass(); + sg_pop_debug_group(); +} + +// Helper for Denoise, one of three near-identical dispatches. +// `srcSample` is the texture view of the noisy AO source, `dstStorage` +// is the storage_image view of the destination. `finalApply` controls +// the XE_GTAO_OCCLUSION_TERM_SCALE rescale on store. Each dispatch +// opens its own compute pass so sokol can insert the +// storage_image -> sampled-texture barrier between adjacent passes. +static void runDenoiseDispatch( const gtao_denoise_ub_gtao_t* consts, sg_view srcSample, sg_view dstStorage, bool finalApply, + const char* label ) +{ + sg_pass pass = { 0 }; + pass.compute = true; + pass.label = label; + sg_push_debug_group( label ); + sg_begin_pass( &pass ); + + sg_apply_pipeline( s_gtao.denoisePipeline ); + + sg_bindings bindings = { 0 }; + bindings.views[VIEW_gtao_denoise_out_ao] = dstStorage; + bindings.views[VIEW_gtao_denoise_tex_edges] = s_gtao.edgesSampleView; + bindings.views[VIEW_gtao_denoise_tex_noisy_ao] = srcSample; + bindings.samplers[SMP_gtao_denoise_smp_point_clamp] = s_gtao.pointSampler; + sg_apply_bindings( &bindings ); + + sg_apply_uniforms( UB_gtao_denoise_ub_gtao, &SG_RANGE( *consts ) ); + + gtao_denoise_ub_denoise_t apply = { finalApply ? 1 : 0, 0, 0, 0 }; + sg_apply_uniforms( UB_gtao_denoise_ub_denoise, &SG_RANGE( apply ) ); + + // 8x8 numthreads, 2 horizontal pixels per thread -> 16x8 destination + // pixels per workgroup. Deviates from Esoterica's (W+7)/8 dispatch + // sizing (which over-covers by 2x, the surplus threads write OOB, + // silent no-op in D3D11/Vulkan/Metal compute). The visible output + // is the same. + const int groupsX = ( s_gtao.width + 15 ) / 16; + const int groupsY = ( s_gtao.height + 7 ) / 8; + sg_dispatch( groupsX, groupsY, 1 ); + + sg_end_pass(); + sg_pop_debug_group(); +} + +void Denoise( const Mat4* proj, int viewportWidth, int viewportHeight ) +{ + if ( !s_gtao.noisy0Image.id || !s_gtao.noisy1Image.id || !s_gtao.resultImage.id || !s_gtao.edgesImage.id ) + { + fprintf( stderr, "[gtao/error] Denoise called before ResizeGTAO succeeded\n" ); + return; + } + + GtaoUboInputs inputs = ComputeUboInputs( proj, viewportWidth, viewportHeight ); + gtao_denoise_ub_gtao_t consts = MakeDenoiseUbo( &inputs ); + + int passCount = s_gtao.params.denoisePassCount; + if ( passCount < 1 ) + { + passCount = 1; + } + if ( passCount > GTAO_MAX_DENOISE_PASSES ) + { + passCount = GTAO_MAX_DENOISE_PASSES; + } + + static const char* k_intermediateLabels[GTAO_MAX_DENOISE_PASSES] = { + "gtao_denoise_pass0", "gtao_denoise_pass1", "gtao_denoise_pass2", + "gtao_denoise_pass3", "gtao_denoise_pass4", + }; + + sg_view src = s_gtao.noisy0SampleView; + sg_view dst = s_gtao.noisy1StorageView; + sg_view srcAlt = s_gtao.noisy1SampleView; + sg_view dstAlt = s_gtao.noisy0StorageView; + + for ( int i = 0; i < passCount - 1; ++i ) + { + runDenoiseDispatch( &consts, src, dst, false, k_intermediateLabels[i] ); + sg_view tmpS = src; + src = srcAlt; + srcAlt = tmpS; + sg_view tmpD = dst; + dst = dstAlt; + dstAlt = tmpD; + } + runDenoiseDispatch( &consts, src, s_gtao.resultStorageView, true, "gtao_denoise_final" ); +} diff --git a/samples/gfx/gtao.h b/samples/gfx/gtao.h new file mode 100644 index 0000000..b757dd0 --- /dev/null +++ b/samples/gfx/gtao.h @@ -0,0 +1,164 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// GTAO (ground truth ambient occlusion): +// * A full-res depth-only pre-pass color attachment carrying positive +// linear view-space depth (R32F). Shapes rasterize their analytic +// surface depth into it, the GTAO compute pipeline samples this as +// the source for its prefiltered depth chain and for the MainPass +// normal reconstruction taps. +// * A D32F depth-stencil attachment that runs alongside the R32F color +// attachment for early-Z and correct closest-fragment selection. Never +// sampled, without it, overlapping primitives produce "whoever drew +// last wins" in the R32F color, which is wrong. Also re-attached as +// the depth_stencil of the transparent pass (LOAD + GREATER, no +// depth write). +// * A 5-mip R32F prefiltered linear-depth chain populated by a compute +// dispatch over the depth pre-pass. Mip 0 is a verbatim copy of the +// source, mips 1-4 use the XeGTAO depth-MIP filter (weighted average +// that biases toward the closer of each 2x2 footprint). Consumed by +// MainPass for the trace samples. +// * An R32F `edges` texture written by MainPass alongside the noisy AO +// term. Encodes 4 packed edge gradients per pixel consumed by the +// Denoise step. R32F (not Esoterica's R8 UNORM) because sokol-shdc / +// SPIRV-Cross only allows r32f / r32i / r32ui plus rgba/rg{32,16} +// variants as storage_image access formats. +// * Two R32F ping-pong AO targets `noisy0` / `noisy1`. MainPass writes +// the raw noisy term into `noisy0`. Denoise pass 0 reads `noisy0`, +// writes `noisy1`. Denoise pass 1 reads `noisy1`, writes `noisy0`. +// Denoise final pass reads `noisy0` and writes `result` with the +// XE_GTAO_OCCLUSION_TERM_SCALE rescale. +// * A full-res R32F `result` AO texture sampled by lit shape shaders +// via `tex_ao`. Cleared to 1.0 when GTAO is disabled at runtime, +// written by Denoise final apply. +// +// Sizing: targets follow the main pass's width/height. ResizeGTAO is +// called once per frame with the swapchain or offscreen attachment size, +// reallocates only on actual changes. + +// Must of the code and shaders for XeGTAO are ported from Esoterica Engine +// https://github.com/BobbyAnguelov/Esoterica + +#pragma once + +#include "gfx/utility.h" +#include "sokol_gfx.h" + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +void InitAmbientOcclusion( void ); +void ShutdownAmbientOcclusion( void ); + +// Selects the slice count and steps-per-slice +typedef enum AmbientOcclusionQuality +{ + // 2 slices and 2 steps + AO_QUALITY_MEDIUM = 0, + + // 3 slices and 3 steps + AO_QUALITY_HIGH = 1, + + // 9 slices and 3 steps + AO_QUALITY_ULTRA = 2, +} AmbientOcclusionQuality; + +// 3 to 4 is the sweet spot +#define GTAO_MAX_DENOISE_PASSES 5 + +typedef struct GtaoTraceParams +{ + float radius; // EffectRadius, world-space sample radius + float falloff; // EffectFalloffRange, fraction of radius over which the weight tapers + float radiusMul; // RadiusMultiplier, per-MIP scale + float finalValuePow; // FinalValuePower, non-linear contrast on the final term + float denoiseBlurBeta; // DenoiseBlurBeta, bilateral blur strength + float sampleDistPow; // SampleDistributionPower, exponent on the slice-sampling distribution + float thinOcclComp; // ThinOccluderCompensation, extra weight for thin features + float depthMipSampOffset; // DepthMIPSamplingOffset, bias on the prefilter MIP selection + AmbientOcclusionQuality quality; // Trace quality tier, picks the slice and step counts internally + int denoisePassCount; // Total denoise dispatches, >=1 (final apply), clamped to GTAO_MAX_DENOISE_PASSES +} GtaoTraceParams; + +GtaoTraceParams GetGtaoTraceParams( void ); +void SetGtaoTraceParams( GtaoTraceParams p ); +GtaoTraceParams GetDefaultGtaoTraceParams( void ); + +AmbientOcclusionQuality GetAOQualityForPixelScale( float dpiScale ); + +// Ensure the owned targets are sized to match (width, height). No-op if +// the size hasn't changed, destroys + recreates on resize. Must be called +// before any gtao*View accessor each frame. +void ResizeGTAO( int width, int height ); + +// Depth pre-pass attachment views. Bind as pass.attachments.colors[0] +// (linear-depth R32F) and pass.attachments.depth_stencil (transient D32F, +// rasterizer-only). The renderer's DepthPrepass writes both. +sg_view GetLinearDepthAttachmentView( void ); +sg_view GetPrepassDepthAttachmentView( void ); + +// Texture view of the R32F linear-depth target. Consumed by the GTAO +// PrefilterDepth compute. +sg_view GetLinearDepthSampleView( void ); + +// Dispatch the PrefilterDepth compute. Builds GTAOConstants +// from `proj` + viewport dims, then runs one ceil(w/16) x ceil(h/16) +// workgroup over the linear-depth target to populate all 5 mips of the +// prefiltered chain. Must be called after the depth pre-pass has +// written `linearDepthImage` and before MainPass tries to read +// the prefiltered chain. +void PrefilterDepth( const Mat4* proj, int viewportWidth, int viewportHeight ); + +// Texture view of the full prefiltered linear-depth mip chain (R32F, +// 5 mips). Consumed by MainPass. The chain view samples every mip, the +// bound shader picks a mip via textureLod at trace time. +sg_view GetPrefilterDepthSampleView( void ); + +// Dispatch the MainPass compute. Per-pixel: reconstructs the +// view-space normal in-place from depth derivatives, generates Hilbert +// + R2 spatial noise (NoiseIndex = 0, no TAA), runs the XeGTAO Ultra- +// tier slice trace (9 slices x 3 steps) against the prefiltered depth +// chain. Writes the noisy AO term (divided by 1.5 per +// XeGTAO_OutputWorkingTerm) to `noisy0Image` and the packed edges to +// `edgesImage`. Must be called after PrefilterDepth has populated +// the prefiltered chain. +// +// `noisy0` is fed into Denoise next, lit shaders sample `result` +// which only receives a write on the denoise final-apply dispatch. +void ComputeNoisyResult( const Mat4* proj, int viewportWidth, int viewportHeight ); + +// Dispatch the cross-bilateral denoise. Runs N = params.denoisePassCount +// dispatches total: (N - 1) intermediates that ping-pong noisy0 <-> noisy1 +// with finalApply = 0, then one final dispatch with finalApply = 1 that +// rescales by XE_GTAO_OCCLUSION_TERM_SCALE (1.5) and writes `result`. At +// N = 1 only the final dispatch runs and reads noisy0 directly. +// +// Each dispatch is a 8x8 num threads compute over ceil(W/16) x ceil(H/8) +// workgroups (each thread handles 2 horizontal pixels). The edge texture +// written by MainPass is bound on every dispatch. +// +// Must be called after ComputeNoisyResult(). This is the last GTAO +// dispatch and lit shaders can sample `result` via GetAOResultSampleView +// right after. +void Denoise( const Mat4* proj, int viewportWidth, int viewportHeight ); + +// Clear the full-res `result` AO target to 1.0 (no occlusion). Used when +// GTAO is disabled at runtime (FrameInput.disable_gtao = true), lit +// shaders (which always sample tex_ao) see a fully-lit ambient. +void ClearAmbientOcclusion( void ); + +// Texture view of the full-res `result` AO output (R32F). Lit shape +// shaders bind this and sample at gl_FragCoord.xy * viewport.zw to look +// up their per-pixel AO term. After the Denoise final apply this is the +// rescaled [0, 1.5] visibility term (XE_GTAO_OCCLUSION_TERM_SCALE). +sg_view GetAOResultSampleView( void ); + +sg_sampler GetAOLinearSampler( void ); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/samples/gfx/highlight_mask.c b/samples/gfx/highlight_mask.c new file mode 100644 index 0000000..ec609cb --- /dev/null +++ b/samples/gfx/highlight_mask.c @@ -0,0 +1,413 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +#include "gfx/highlight_mask.h" + +#include "gfx/renderer.h" +#include "mask_capsule.glsl.h" +#include "mask_hull.glsl.h" +#include "mask_sphere.glsl.h" + +#include +#include + +#define MAX_HIGHLIGHTS_PER_KIND 64 + +// Mirrors of the shader-side instance structs. sokol-shdc generates these +// as mask_*_instance_t in the per-shader header. The CPU staging arrays +// upload directly into the per-pipeline storage buffers without an extra +// pack step. + +static struct +{ + sg_shader shader; + sg_pipeline pipeline; + sg_buffer instBuf; + sg_view instView; + mask_sphere_instance_t cpu[MAX_HIGHLIGHTS_PER_KIND]; + int count; +} s_sphere; + +static struct +{ + sg_shader shader; + sg_pipeline pipeline; + sg_buffer instBuf; + sg_view instView; + mask_capsule_instance_t cpu[MAX_HIGHLIGHTS_PER_KIND]; + int count; +} s_capsule; + +// Hulls draw one-by-one (each with its own vbo/ibo binding). The CPU staging +// holds the instance struct array. The per-frame draw list holds the +// matching geometry buffers + indexCount. +typedef struct HullDraw +{ + sg_buffer vbo; + sg_buffer ibo; + int indexCount; +} HullDraw; + +static struct +{ + sg_shader shader; + sg_pipeline pipeline; + sg_buffer instBuf; + sg_view instView; + mask_hull_instance_t cpu[MAX_HIGHLIGHTS_PER_KIND]; + HullDraw draws[MAX_HIGHLIGHTS_PER_KIND]; + int count; +} s_hull; + +static bool s_uiInitialized = false; + +// Init / shutdown + +void HighlightMaskInit( void ) +{ + if ( s_uiInitialized ) + return; + + // Sphere mask pipeline + s_sphere.shader = sg_make_shader( mask_sphere_prog_shader_desc( sg_query_backend() ) ); + + sg_buffer_desc sphBufDesc = { 0 }; + sphBufDesc.usage.storage_buffer = true; + sphBufDesc.usage.stream_update = true; + sphBufDesc.size = sizeof( s_sphere.cpu ); + sphBufDesc.label = "highlight_sphere_instances"; + s_sphere.instBuf = sg_make_buffer( &sphBufDesc ); + + sg_view_desc sphViewDesc = { 0 }; + sphViewDesc.storage_buffer.buffer = s_sphere.instBuf; + sphViewDesc.label = "highlight_sphere_instances_view"; + s_sphere.instView = sg_make_view( &sphViewDesc ); + + sg_pipeline_desc sphPdesc = { 0 }; + sphPdesc.shader = s_sphere.shader; + sphPdesc.layout.buffers[0].stride = sizeof( float ) * 3; + sphPdesc.layout.attrs[ATTR_mask_sphere_prog_in_pos].format = SG_VERTEXFORMAT_FLOAT3; + sphPdesc.layout.attrs[ATTR_mask_sphere_prog_in_pos].buffer_index = 0; + sphPdesc.index_type = SG_INDEXTYPE_UINT16; + sphPdesc.colors[0].pixel_format = SG_PIXELFORMAT_R8; + sphPdesc.color_count = 1; + sphPdesc.depth.pixel_format = SG_PIXELFORMAT_DEPTH; + sphPdesc.depth.compare = SG_COMPAREFUNC_GREATER_EQUAL; + sphPdesc.depth.write_enabled = false; + // Impostor convention: front-face cull on the proxy box, so the + // analytic intersection is rasterized from the back faces and remains + // visible when the camera sits inside the proxy AABB but outside the + // analytic sphere. + sphPdesc.cull_mode = SG_CULLMODE_FRONT; + sphPdesc.face_winding = SG_FACEWINDING_CCW; + sphPdesc.sample_count = 1; + sphPdesc.label = "highlight_sphere_pipeline"; + s_sphere.pipeline = sg_make_pipeline( &sphPdesc ); + + // Capsule mask pipeline + s_capsule.shader = sg_make_shader( mask_capsule_prog_shader_desc( sg_query_backend() ) ); + + sg_buffer_desc capBufDesc = { 0 }; + capBufDesc.usage.storage_buffer = true; + capBufDesc.usage.stream_update = true; + capBufDesc.size = sizeof( s_capsule.cpu ); + capBufDesc.label = "highlight_capsule_instances"; + s_capsule.instBuf = sg_make_buffer( &capBufDesc ); + + sg_view_desc capViewDesc = { 0 }; + capViewDesc.storage_buffer.buffer = s_capsule.instBuf; + capViewDesc.label = "highlight_capsule_instances_view"; + s_capsule.instView = sg_make_view( &capViewDesc ); + + sg_pipeline_desc capPdesc = { 0 }; + capPdesc.shader = s_capsule.shader; + capPdesc.layout.buffers[0].stride = sizeof( float ) * 3; + capPdesc.layout.attrs[ATTR_mask_capsule_prog_in_pos].format = SG_VERTEXFORMAT_FLOAT3; + capPdesc.layout.attrs[ATTR_mask_capsule_prog_in_pos].buffer_index = 0; + capPdesc.index_type = SG_INDEXTYPE_UINT16; + capPdesc.colors[0].pixel_format = SG_PIXELFORMAT_R8; + capPdesc.color_count = 1; + capPdesc.depth.pixel_format = SG_PIXELFORMAT_DEPTH; + capPdesc.depth.compare = SG_COMPAREFUNC_GREATER_EQUAL; + capPdesc.depth.write_enabled = false; + capPdesc.cull_mode = SG_CULLMODE_FRONT; + capPdesc.face_winding = SG_FACEWINDING_CCW; + capPdesc.sample_count = 1; + capPdesc.label = "highlight_capsule_pipeline"; + s_capsule.pipeline = sg_make_pipeline( &capPdesc ); + + // Hull mask pipeline + s_hull.shader = sg_make_shader( mask_hull_prog_shader_desc( sg_query_backend() ) ); + + sg_buffer_desc hullBufDesc = { 0 }; + hullBufDesc.usage.storage_buffer = true; + hullBufDesc.usage.stream_update = true; + hullBufDesc.size = sizeof( s_hull.cpu ); + hullBufDesc.label = "highlight_hull_instances"; + s_hull.instBuf = sg_make_buffer( &hullBufDesc ); + + sg_view_desc hullViewDesc = { 0 }; + hullViewDesc.storage_buffer.buffer = s_hull.instBuf; + hullViewDesc.label = "highlight_hull_instances_view"; + s_hull.instView = sg_make_view( &hullViewDesc ); + + sg_pipeline_desc hullPdesc = { 0 }; + hullPdesc.shader = s_hull.shader; + // Geometry registry vbo is interleaved {position(3), normal(3)}, keep + // the stride matching the lit geom vbo so this pipeline can share it. + // in_normal is declared by the lit shader at offset 12 but unused here. + // The shader doesn't declare it so the binding is skipped to match. + hullPdesc.layout.buffers[0].stride = sizeof( float ) * 6; + hullPdesc.layout.attrs[ATTR_mask_hull_prog_in_pos].format = SG_VERTEXFORMAT_FLOAT3; + hullPdesc.layout.attrs[ATTR_mask_hull_prog_in_pos].buffer_index = 0; + hullPdesc.layout.attrs[ATTR_mask_hull_prog_in_pos].offset = 0; + hullPdesc.index_type = SG_INDEXTYPE_UINT32; + hullPdesc.colors[0].pixel_format = SG_PIXELFORMAT_R8; + hullPdesc.color_count = 1; + hullPdesc.depth.pixel_format = SG_PIXELFORMAT_DEPTH; + hullPdesc.depth.compare = SG_COMPAREFUNC_GREATER_EQUAL; + hullPdesc.depth.write_enabled = false; + hullPdesc.cull_mode = SG_CULLMODE_BACK; + hullPdesc.face_winding = SG_FACEWINDING_CCW; + hullPdesc.sample_count = 1; + hullPdesc.label = "highlight_hull_pipeline"; + s_hull.pipeline = sg_make_pipeline( &hullPdesc ); + + s_uiInitialized = true; +} + +void HighlightMaskShutdown( void ) +{ + if ( !s_uiInitialized ) + return; + + sg_destroy_pipeline( s_hull.pipeline ); + s_hull.pipeline.id = 0; + sg_destroy_view( s_hull.instView ); + s_hull.instView.id = 0; + sg_destroy_buffer( s_hull.instBuf ); + s_hull.instBuf.id = 0; + sg_destroy_shader( s_hull.shader ); + s_hull.shader.id = 0; + + sg_destroy_pipeline( s_capsule.pipeline ); + s_capsule.pipeline.id = 0; + sg_destroy_view( s_capsule.instView ); + s_capsule.instView.id = 0; + sg_destroy_buffer( s_capsule.instBuf ); + s_capsule.instBuf.id = 0; + sg_destroy_shader( s_capsule.shader ); + s_capsule.shader.id = 0; + + sg_destroy_pipeline( s_sphere.pipeline ); + s_sphere.pipeline.id = 0; + sg_destroy_view( s_sphere.instView ); + s_sphere.instView.id = 0; + sg_destroy_buffer( s_sphere.instBuf ); + s_sphere.instBuf.id = 0; + sg_destroy_shader( s_sphere.shader ); + s_sphere.shader.id = 0; + + s_uiInitialized = false; +} + +void HighlightMaskBeginFrame( void ) +{ + s_sphere.count = 0; + s_capsule.count = 0; + s_hull.count = 0; +} + +bool HasHighlightMaskContent( void ) +{ + return ( s_sphere.count + s_capsule.count + s_hull.count ) > 0; +} + +// Append API + +void AppendHighlightSphere( b3Transform transform, float radius, HighlightKind kind ) +{ + if ( kind == HIGHLIGHT_KIND_NONE ) + return; + if ( s_sphere.count >= MAX_HIGHLIGHTS_PER_KIND ) + { + fprintf( stderr, "[highlight/error] sphere overflow: dropping (cap=%d)\n", MAX_HIGHLIGHTS_PER_KIND ); + return; + } + mask_sphere_instance_t* inst = &s_sphere.cpu[s_sphere.count++]; + // transform's translation is the world-space center. + inst->center_radius = MakeVec4( transform.p.x, transform.p.y, transform.p.z, radius ); + inst->kind = MakeVec4( (float)kind, 0.0f, 0.0f, 0.0f ); +} + +void AppendHighlightCapsule( b3Transform transform, float halfLength, float radius, HighlightKind kind ) +{ + if ( kind == HIGHLIGHT_KIND_NONE ) + return; + if ( s_capsule.count >= MAX_HIGHLIGHTS_PER_KIND ) + { + fprintf( stderr, "[highlight/error] capsule overflow: dropping (cap=%d)\n", MAX_HIGHLIGHTS_PER_KIND ); + return; + } + mask_capsule_instance_t* inst = &s_capsule.cpu[s_capsule.count++]; + // 3x4 affine row layout: row i = (R_i0, R_i1, R_i2, t_i). + Mat4 m = MakeMat4FromTransform( transform, b3Vec3_one ); + inst->xform_row0 = MakeVec4( m.cx.x, m.cy.x, m.cz.x, m.cw.x ); + inst->xform_row1 = MakeVec4( m.cx.y, m.cy.y, m.cz.y, m.cw.y ); + inst->xform_row2 = MakeVec4( m.cx.z, m.cy.z, m.cz.z, m.cw.z ); + inst->params = MakeVec4( halfLength, radius, (float)kind, 0.0f ); +} + +void AppendHighlightHull( MeshHandle handle, b3Transform transform, b3Vec3 scale, HighlightKind kind ) +{ + if ( kind == HIGHLIGHT_KIND_NONE ) + return; + if ( s_hull.count >= MAX_HIGHLIGHTS_PER_KIND ) + { + fprintf( stderr, "[highlight/error] hull overflow: dropping (cap=%d)\n", MAX_HIGHLIGHTS_PER_KIND ); + return; + } + MeshBuffers gb = { 0 }; + if ( !GetMeshBuffers( handle, &gb ) ) + { + return; // stale or invalid handle, skip silently + } + const int index = s_hull.count++; + mask_hull_instance_t* inst = &s_hull.cpu[index]; + Mat4 m = MakeMat4FromTransform( transform, b3Vec3_one ); + inst->xform_row0 = MakeVec4( m.cx.x, m.cy.x, m.cz.x, m.cw.x ); + inst->xform_row1 = MakeVec4( m.cx.y, m.cy.y, m.cz.y, m.cw.y ); + inst->xform_row2 = MakeVec4( m.cx.z, m.cy.z, m.cz.z, m.cw.z ); + inst->scale_kind = MakeVec4( scale.x, scale.y, scale.z, (float)kind ); + s_hull.draws[index].vbo = gb.vbo; + s_hull.draws[index].ibo = gb.ibo; + s_hull.draws[index].indexCount = gb.indexCount; +} + +// Submit + +void SubmitHighlightMask( int width, int height, const Mat4* viewProj, b3Vec3 cameraPosWorld, sg_view maskAttachView, + sg_view depthAttachView ) +{ + if ( !s_uiInitialized ) + return; + if ( !HasHighlightMaskContent() ) + return; + + sg_pass pass = { 0 }; + pass.action.colors[0].load_action = SG_LOADACTION_CLEAR; + pass.action.colors[0].clear_value.r = 0.0f; + pass.action.colors[0].clear_value.g = 0.0f; + pass.action.colors[0].clear_value.b = 0.0f; + pass.action.colors[0].clear_value.a = 0.0f; + pass.action.colors[0].store_action = SG_STOREACTION_STORE; + pass.action.depth.load_action = SG_LOADACTION_LOAD; + pass.action.depth.store_action = SG_STOREACTION_DONTCARE; + pass.attachments.colors[0] = maskAttachView; + pass.attachments.depth_stencil = depthAttachView; + pass.label = "highlight_mask_pass"; + sg_push_debug_group( "highlight_mask" ); + sg_begin_pass( &pass ); + sg_apply_viewport( 0, 0, width, height, true ); + + const sg_buffer cubeVbuf = GetCubeProxyVertexBuffer(); + const sg_buffer cubeIbuf = GetCubeProxyIndexBuffer(); + const int cubeCount = GetCubeProxyIndexCount(); + + // Spheres + if ( s_sphere.count > 0 ) + { + sg_range upload; + upload.ptr = s_sphere.cpu; + upload.size = (size_t)s_sphere.count * sizeof( mask_sphere_instance_t ); + sg_update_buffer( s_sphere.instBuf, &upload ); + + sg_apply_pipeline( s_sphere.pipeline ); + + sg_bindings b = { 0 }; + b.vertex_buffers[0] = cubeVbuf; + b.index_buffer = cubeIbuf; + b.views[VIEW_mask_sphere_instances] = s_sphere.instView; + sg_apply_bindings( &b ); + + mask_sphere_ub_frame_t uf = { 0 }; + uf.view_proj = *viewProj; + sg_apply_uniforms( UB_mask_sphere_ub_frame, &SG_RANGE( uf ) ); + + mask_sphere_ub_pass_t up = { 0 }; + up.view_proj = *viewProj; + up.camera_pos = MakeVec4( cameraPosWorld.x, cameraPosWorld.y, cameraPosWorld.z, 0.0f ); + sg_apply_uniforms( UB_mask_sphere_ub_pass, &SG_RANGE( up ) ); + + sg_draw( 0, cubeCount, s_sphere.count ); + } + + // Capsules + if ( s_capsule.count > 0 ) + { + sg_range upload; + upload.ptr = s_capsule.cpu; + upload.size = (size_t)s_capsule.count * sizeof( mask_capsule_instance_t ); + sg_update_buffer( s_capsule.instBuf, &upload ); + + sg_apply_pipeline( s_capsule.pipeline ); + + sg_bindings b = { 0 }; + b.vertex_buffers[0] = cubeVbuf; + b.index_buffer = cubeIbuf; + b.views[VIEW_mask_capsule_instances] = s_capsule.instView; + sg_apply_bindings( &b ); + + mask_capsule_ub_frame_t uf = { 0 }; + uf.view_proj = *viewProj; + sg_apply_uniforms( UB_mask_capsule_ub_frame, &SG_RANGE( uf ) ); + + mask_capsule_ub_pass_t up = { 0 }; + up.view_proj = *viewProj; + up.camera_pos = MakeVec4( cameraPosWorld.x, cameraPosWorld.y, cameraPosWorld.z, 0.0f ); + sg_apply_uniforms( UB_mask_capsule_ub_pass, &SG_RANGE( up ) ); + + sg_draw( 0, cubeCount, s_capsule.count ); + } + + // Hulls + if ( s_hull.count > 0 ) + { + sg_range upload; + upload.ptr = s_hull.cpu; + upload.size = (size_t)s_hull.count * sizeof( mask_hull_instance_t ); + sg_update_buffer( s_hull.instBuf, &upload ); + + sg_apply_pipeline( s_hull.pipeline ); + + mask_hull_ub_frame_t uf = { 0 }; + uf.view_proj = *viewProj; + sg_apply_uniforms( UB_mask_hull_ub_frame, &SG_RANGE( uf ) ); + + // One draw per hull, each binds its own (vbo, ibo) but shares the + // mask hull instance storage view. inst_base picks the slot. + sg_buffer currentVbo = { 0 }; + sg_buffer currentIbo = { 0 }; + for ( int i = 0; i < s_hull.count; ++i ) + { + const HullDraw d = s_hull.draws[i]; + if ( d.vbo.id != currentVbo.id || d.ibo.id != currentIbo.id ) + { + sg_bindings b = { 0 }; + b.vertex_buffers[0] = d.vbo; + b.index_buffer = d.ibo; + b.views[VIEW_mask_hull_instances] = s_hull.instView; + sg_apply_bindings( &b ); + currentVbo = d.vbo; + currentIbo = d.ibo; + } + mask_hull_ub_draw_t ud = { 0 }; + ud.inst_base[0] = i; + sg_apply_uniforms( UB_mask_hull_ub_draw, &SG_RANGE( ud ) ); + sg_draw( 0, d.indexCount, 1 ); + } + } + + sg_end_pass(); + sg_pop_debug_group(); +} diff --git a/samples/gfx/highlight_mask.h b/samples/gfx/highlight_mask.h new file mode 100644 index 0000000..e159e4e --- /dev/null +++ b/samples/gfx/highlight_mask.h @@ -0,0 +1,74 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Per-frame append API + the render pass that rasterizes a small set +// "highlighted" shapes into the renderer-owned R8 mask target. The pass +// runs once per frame, after the GTAO depth prepass, before tonemap, the +// outline post-pass then reads the mask and composites silhouette colors +// over the resolved scene. +// +// Restricted to spheres, capsules, and hulls by design, meshes and +// heightfields look poor outlined and aren't worth the pipeline weight. +// +// Encodes one of three states per pixel as the kind value passed in: +// 1 = hover -> R8 UNORM 0.5 +// 2 = select -> R8 UNORM 1.0 +// 0 -> unhighlighted, never written +// +// Single-threaded, render-thread only. Submission counts capped per +// shape class, overflows log and drop. + +#pragma once + +#include "gfx/geometry_registry.h" +#include "gfx/utility.h" +#include "sokol_gfx.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef enum HighlightKind +{ + HIGHLIGHT_KIND_NONE = 0, + HIGHLIGHT_KIND_HOVER = 1, + HIGHLIGHT_KIND_SELECT = 2, +} HighlightKind; + +void HighlightMaskInit( void ); +void HighlightMaskShutdown( void ); + +// Reset per-frame counts. Called from ResetFrameArena. +void HighlightMaskBeginFrame( void ); + +// Append a highlighted sphere. transform supplies the world-space center via +// its translation, rotation is ignored (a sphere is rotationally invariant +// for silhouette purposes). Logs + drops on overflow. +void AppendHighlightSphere( b3Transform transform, float radius, HighlightKind kind ); + +// Append a highlighted capsule. transform follows the same convention as +// AppendCapsule (rotation places local +X along the long axis, +// translation is the capsule center). halfLength and radius are +// world-space scalars. Logs + drops on overflow. +void AppendHighlightCapsule( b3Transform transform, float halfLength, float radius, HighlightKind kind ); + +// Append a highlighted hull. handle resolves to a registered geometry +// (vbo/ibo). transform + scale match AppendMesh, rotation matters because +// hulls aren't rotationally symmetric. Logs + drops on overflow. +void AppendHighlightHull( MeshHandle handle, b3Transform transform, b3Vec3 scale, HighlightKind kind ); + +// True when at least one shape was submitted this frame. Lets the caller +// skip mask + outline passes entirely on the common empty case. +bool HasHighlightMaskContent( void ); + +// Open a single-sample render pass against (maskAttachView, +// depthAttachView), clear the mask to 0, and rasterize all submitted +// highlights. Depth-tests GREATER_EQUAL against the supplied prepass depth +// (no write). No-op when no highlights were submitted. +void SubmitHighlightMask( int width, int height, const Mat4* viewProj, b3Vec3 cameraPosWorld, sg_view maskAttachView, + sg_view depthAttachView ); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/samples/gfx/highlight_outline.c b/samples/gfx/highlight_outline.c new file mode 100644 index 0000000..dddbf78 --- /dev/null +++ b/samples/gfx/highlight_outline.c @@ -0,0 +1,155 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +#include "gfx/highlight_outline.h" + +#include "highlight_outline.glsl.h" + +#include +#include + +#define HIGHLIGHT_OUTLINE_MAX_PIPELINES 2 + +static struct +{ + sg_shader shader; + sg_sampler sampler; + struct + { + sg_pixel_format colorFormat; + sg_pixel_format depthFormat; + sg_pipeline pipeline; + } pipelines[HIGHLIGHT_OUTLINE_MAX_PIPELINES]; + int pipelineCount; + bool ready; +} s_ho; + +HighlightParams GetDefaultHighlightParams( void ) +{ + HighlightParams p; + p.enabled = true; + p.hoverThicknessPx = 1.0f; + p.selectThicknessPx = 2.0f; + // Cool cyan for hover at moderate alpha. Warm orange-yellow for select + // at full alpha. Authored as straight RGBA. Premultiplied in the + // submit step. + p.hoverColor = MakeVec4( 0.35f, 0.85f, 1.0f, 0.75f ); + p.selectColor = MakeVec4( 1.0f, 0.78f, 0.20f, 1.0f ); + return p; +} + +static sg_pipeline ensurePipeline( sg_pixel_format colorFormat, sg_pixel_format depthFormat ) +{ + for ( int i = 0; i < s_ho.pipelineCount; ++i ) + { + if ( s_ho.pipelines[i].colorFormat == colorFormat && s_ho.pipelines[i].depthFormat == depthFormat ) + { + return s_ho.pipelines[i].pipeline; + } + } + if ( s_ho.pipelineCount >= HIGHLIGHT_OUTLINE_MAX_PIPELINES ) + { + fprintf( stderr, "highlight_outline: pipeline cache exhausted (max %d format pairs)\n", HIGHLIGHT_OUTLINE_MAX_PIPELINES ); + sg_pipeline empty = { 0 }; + return empty; + } + + sg_pipeline_desc pdesc = { 0 }; + pdesc.shader = s_ho.shader; + pdesc.colors[0].pixel_format = colorFormat; + pdesc.color_count = 1; + // Premultiplied-alpha blend over the resolved scene color. ub_pass + // colors are premultiplied by the C side. + pdesc.colors[0].blend.enabled = true; + pdesc.colors[0].blend.src_factor_rgb = SG_BLENDFACTOR_ONE; + pdesc.colors[0].blend.dst_factor_rgb = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA; + pdesc.colors[0].blend.op_rgb = SG_BLENDOP_ADD; + pdesc.colors[0].blend.src_factor_alpha = SG_BLENDFACTOR_ONE; + pdesc.colors[0].blend.dst_factor_alpha = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA; + pdesc.colors[0].blend.op_alpha = SG_BLENDOP_ADD; + pdesc.depth.pixel_format = depthFormat; + pdesc.depth.write_enabled = false; + pdesc.depth.compare = SG_COMPAREFUNC_ALWAYS; + pdesc.cull_mode = SG_CULLMODE_NONE; + pdesc.face_winding = SG_FACEWINDING_CCW; + pdesc.sample_count = 1; + pdesc.label = "highlight_outline_pipeline"; + + const sg_pipeline pip = sg_make_pipeline( &pdesc ); + s_ho.pipelines[s_ho.pipelineCount].colorFormat = colorFormat; + s_ho.pipelines[s_ho.pipelineCount].depthFormat = depthFormat; + s_ho.pipelines[s_ho.pipelineCount].pipeline = pip; + ++s_ho.pipelineCount; + return pip; +} + +void InitHighlightOutline( void ) +{ + if ( s_ho.ready ) + return; + s_ho.shader = sg_make_shader( highlight_outline_prog_shader_desc( sg_query_backend() ) ); + + // texelFetch reads ignore sampler state, but sokol-gfx still requires a + // sampler binding for any texture binding. Nearest + clamp. Nothing + // exotic. + sg_sampler_desc sdesc = { 0 }; + sdesc.min_filter = SG_FILTER_NEAREST; + sdesc.mag_filter = SG_FILTER_NEAREST; + sdesc.mipmap_filter = SG_FILTER_NEAREST; + sdesc.wrap_u = SG_WRAP_CLAMP_TO_EDGE; + sdesc.wrap_v = SG_WRAP_CLAMP_TO_EDGE; + sdesc.label = "highlight_outline_sampler"; + s_ho.sampler = sg_make_sampler( &sdesc ); + + s_ho.ready = true; +} + +void ShutdownHighlightOutline( void ) +{ + if ( !s_ho.ready ) + return; + for ( int i = 0; i < s_ho.pipelineCount; ++i ) + { + sg_destroy_pipeline( s_ho.pipelines[i].pipeline ); + s_ho.pipelines[i].pipeline.id = 0; + s_ho.pipelines[i].colorFormat = SG_PIXELFORMAT_NONE; + s_ho.pipelines[i].depthFormat = SG_PIXELFORMAT_NONE; + } + s_ho.pipelineCount = 0; + sg_destroy_sampler( s_ho.sampler ); + s_ho.sampler.id = 0; + sg_destroy_shader( s_ho.shader ); + s_ho.shader.id = 0; + s_ho.ready = false; +} + +static inline Vec4 Premultiply( Vec4 c ) +{ + return MakeVec4( c.x * c.w, c.y * c.w, c.z * c.w, c.w ); +} + +void SubmitHighlightOutline( sg_view maskSampleView, sg_pixel_format colorFormat, sg_pixel_format depthFormat, + const HighlightParams* params ) +{ + if ( !s_ho.ready || !params || !params->enabled ) + return; + + const sg_pipeline pip = ensurePipeline( colorFormat, depthFormat ); + if ( pip.id == 0 ) + return; + + sg_apply_pipeline( pip ); + + sg_bindings b = { 0 }; + b.views[VIEW_highlight_outline_tex_mask] = maskSampleView; + b.samplers[SMP_highlight_outline_smp_mask] = s_ho.sampler; + sg_apply_bindings( &b ); + + highlight_outline_ub_pass_t up = { 0 }; + up.hover_color = Premultiply( params->hoverColor ); + up.select_color = Premultiply( params->selectColor ); + up.thickness_px = MakeVec4( params->hoverThicknessPx, params->selectThicknessPx, 0.0f, 0.0f ); + sg_apply_uniforms( UB_highlight_outline_ub_pass, &SG_RANGE( up ) ); + + sg_draw( 0, 3, 1 ); +} diff --git a/samples/gfx/highlight_outline.h b/samples/gfx/highlight_outline.h new file mode 100644 index 0000000..012b3a8 --- /dev/null +++ b/samples/gfx/highlight_outline.h @@ -0,0 +1,57 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Fullscreen pass that reads the R8 highlight mask (filled by the +// highlight_mask pass) and composites silhouette outline colors onto the +// already-tone-mapped scene image. Runs against the same swap chain / +// offscreen attachment the tone-map pass wrote to, with LOAD on color and +// no depth. +// +// Two outline styles, both authored in linear premultiplied alpha space: +// hover, typically thinner, more subtle (default 1 px, cool color) +// select, wider and more saturated (default 2 px, warm color). + +#pragma once + +#include "gfx/utility.h" +#include "sokol_gfx.h" + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef struct HighlightParams +{ + bool enabled; + float hoverThicknessPx; + float selectThicknessPx; + // straight (non-premultiplied) linear RGBA, premultiplied inside + Vec4 hoverColor; + Vec4 selectColor; +} HighlightParams; + +HighlightParams GetDefaultHighlightParams( void ); + +void InitHighlightOutline( void ); +void ShutdownHighlightOutline( void ); + +// Submit the outline post-pass against the currently-open render pass. +// The caller is responsible for having opened a pass against the desired +// destination (the swap-chain after tone map, or the offscreen tone map target) +// with LOAD action on color. The pass's color attachment format must match +// colorFormat and its depth format must match depthFormat (depth is not +// read or written by this pass, but the pipeline declaration needs the +// formats to match for sokol-gfx validation). +// +// maskSampleView is the texture-sample view over the R8 mask image. The +// pipeline is cached per (colorFormat, depthFormat) pair so repeat calls +// from RenderFrame / RenderFrameOffscreen reuse one pipeline each. +void SubmitHighlightOutline( sg_view maskSampleView, sg_pixel_format colorFormat, sg_pixel_format depthFormat, + const HighlightParams* params ); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/samples/gfx/highlight_target.c b/samples/gfx/highlight_target.c new file mode 100644 index 0000000..0092c35 --- /dev/null +++ b/samples/gfx/highlight_target.c @@ -0,0 +1,90 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +#include "gfx/highlight_target.h" + +static struct +{ + int width; + int height; + sg_image image; + sg_view attachView; + sg_view sampleView; + bool ready; +} s_ht; + +static void destroyTargets( void ) +{ + if ( s_ht.sampleView.id ) + { + sg_destroy_view( s_ht.sampleView ); + s_ht.sampleView.id = 0; + } + if ( s_ht.attachView.id ) + { + sg_destroy_view( s_ht.attachView ); + s_ht.attachView.id = 0; + } + if ( s_ht.image.id ) + { + sg_destroy_image( s_ht.image ); + s_ht.image.id = 0; + } +} + +void InitHighlightTarget( void ) +{ + s_ht.width = 0; + s_ht.height = 0; + s_ht.ready = true; +} + +void ShutdownHighlightTarget( void ) +{ + if ( !s_ht.ready ) + return; + destroyTargets(); + s_ht.width = 0; + s_ht.height = 0; + s_ht.ready = false; +} + +void ResizeHighlightTarget( int width, int height ) +{ + if ( !s_ht.ready || width <= 0 || height <= 0 ) + return; + if ( width == s_ht.width && height == s_ht.height && s_ht.image.id ) + return; + + destroyTargets(); + s_ht.width = width; + s_ht.height = height; + + sg_image_desc idesc = { 0 }; + idesc.usage.color_attachment = true; + idesc.width = width; + idesc.height = height; + idesc.pixel_format = SG_PIXELFORMAT_R8; + idesc.sample_count = 1; + idesc.label = "highlight_mask"; + s_ht.image = sg_make_image( &idesc ); + + sg_view_desc avdesc = { 0 }; + avdesc.color_attachment.image = s_ht.image; + avdesc.label = "highlight_mask_attach"; + s_ht.attachView = sg_make_view( &avdesc ); + + sg_view_desc svdesc = { 0 }; + svdesc.texture.image = s_ht.image; + svdesc.label = "highlight_mask_sample"; + s_ht.sampleView = sg_make_view( &svdesc ); +} + +sg_view GetHighlightTargetMaskAttachView( void ) +{ + return s_ht.attachView; +} +sg_view GetHighlightTargetMaskSampleView( void ) +{ + return s_ht.sampleView; +} diff --git a/samples/gfx/highlight_target.h b/samples/gfx/highlight_target.h new file mode 100644 index 0000000..94e5001 --- /dev/null +++ b/samples/gfx/highlight_target.h @@ -0,0 +1,44 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Single-sample R8 UNORM image at scene resolution, written by the +// highlight_mask pass and sampled by the highlight_outline post-pass. Sized +// alongside the scene target, both resize when the framebuffer does. +// +// The mask encodes one of three states as a UNORM byte: 0.0 = no highlight, +// 0.5 = hover, 1.0 = select. R8 UNORM (rather than R8_UINT) so the outline +// shader can sample via the standard texture/sampler path, sokol-shdc's +// integer-texture binding has cross-backend quirks we'd rather not eat for +// a 3-value mask. Thresholds in the FS (>0.25, >0.75) recover the discrete +// kinds. +// +// Single-sample (no MSAA), keeps the mask pipeline matched to the GTAO +// prepass depth (also 1 sample) it depth-tests against. Silhouette softness +// comes from the outline shader's tap pattern + alpha blend, not from MSAA +// on the mask itself. + +#pragma once + +#include "sokol_gfx.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +void InitHighlightTarget( void ); +void ShutdownHighlightTarget( void ); + +// Resize to (width, height) if changed. No-op when stable. Recreates the +// image + views on size change. +void ResizeHighlightTarget( int width, int height ); + +// Color-attachment view over the mask image. Bound by the highlight_mask pass. +sg_view GetHighlightTargetMaskAttachView( void ); + +// Texture-sample view over the mask image. Bound by the highlight_outline pass. +sg_view GetHighlightTargetMaskSampleView( void ); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/samples/gfx/ibl.c b/samples/gfx/ibl.c new file mode 100644 index 0000000..45ea24e --- /dev/null +++ b/samples/gfx/ibl.c @@ -0,0 +1,667 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +#include "gfx/ibl.h" + +#include "brdf_lut.glsl.h" +#include "gfx/sky.h" +#include "prefilter.glsl.h" +#include "sky_to_cube.glsl.h" + +#include + +// Per-face basis vectors that map a fragment's v_uv in [0,1]^2 to a +// world-space direction. Match the GL cubemap sampling convention (which +// sokol abstracts uniformly across backends), so a direction d written +// at (face F, uv) is recovered by sampling the cubemap with the same d. +// Order: +X, -X, +Y, -Y, +Z, -Z. +typedef struct +{ + b3Vec3 right; + b3Vec3 up; + b3Vec3 forward; +} CubeFaceBasis; + +// SH projection grid resolution per face. 32 -> 6 * 32^2 = 6144 sample +// evaluations per rebuild. Cheap on CPU and well above the SH order-2 +// Nyquist for the smooth Preetham function. +#define IBL_SH_SAMPLES_PER_FACE 32 + +// Funk-Hecke / Ramamoorthi diffuse convolution weights, pre-multiplied +// into the stored SH coefficients so the shader reads them as +// E(N) = sum(coef[i] * basis_i(N)), L_diffuse = (albedo / pi) * E(N). +// A_0 = pi, A_1 = 2pi/3, A_2 = pi/4 (Ramamoorthi & Hanrahan 2001, eq.5). +#define SH_A0 ( 3.14159265358979323846f ) +#define SH_A1 ( 3.14159265358979323846f * 2.0f / 3.0f ) +#define SH_A2 ( 3.14159265358979323846f / 4.0f ) + +// SH-basis normalization constants (real spherical harmonics, l=0..2). +// Order matches Sloan / Ramamoorthi: index 0 = (l=0,m=0), 1..3 = l=1 +// with m = -1,0,+1, 4..8 = l=2 with m = -2,-1,0,+1,+2. +#define SH_Y00 0.282094791773878f // 0.5 / sqrt(pi) +#define SH_Y1n1 0.488602511902919f // sqrt(3/(4pi)) +#define SH_Y10 0.488602511902919f +#define SH_Y1p1 0.488602511902919f +#define SH_Y2n2 1.092548430592079f // sqrt(15/(4pi)) +#define SH_Y2n1 1.092548430592079f +#define SH_Y20 0.315391565252520f // sqrt(5/(16pi)) +#define SH_Y2p1 1.092548430592079f +#define SH_Y2p2 0.546274215296039f // sqrt(15/(16pi)) = SH_Y2n2/2 + +static const CubeFaceBasis s_cubeFaceBasis[6] = { + // +X + { { 0.0f, 0.0f, -1.0f }, { 0.0f, -1.0f, 0.0f }, { 1.0f, 0.0f, 0.0f } }, + // -X + { { 0.0f, 0.0f, 1.0f }, { 0.0f, -1.0f, 0.0f }, { -1.0f, 0.0f, 0.0f } }, + // +Y + { { 1.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 1.0f }, { 0.0f, 1.0f, 0.0f } }, + // -Y + { { 1.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, -1.0f }, { 0.0f, -1.0f, 0.0f } }, + // +Z + { { 1.0f, 0.0f, 0.0f }, { 0.0f, -1.0f, 0.0f }, { 0.0f, 0.0f, 1.0f } }, + // -Z + { { -1.0f, 0.0f, 0.0f }, { 0.0f, -1.0f, 0.0f }, { 0.0f, 0.0f, -1.0f } }, +}; + +static struct +{ + // BRDF integration LUT (Karis split-sum). RG16F at GFX_IBL_LUT_SIZE^2. + // Generated once at InitImageBasedLighting. Environment-independent so it never + // needs to be rebuilt. + sg_image brdfLut; + sg_view brdfLutColorAttachmentView; // used during generation + sg_view brdfLutSampleView; // bound by lit pipelines + sg_sampler brdfLutSampler; + sg_shader brdfLutShader; + sg_pipeline brdfLutPipeline; + + // Raw Preetham sky cube. 1 mip, 6 faces. Filled by sky_to_cube. Read + // by the prefilter pass as the input cube. Not bound to lit pipelines. + sg_image skyCubeRaw; + sg_view skyCubeRawFaceAttachmentViews[6]; + sg_view skyCubeRawSampleView; + sg_shader skyToCubeShader; + sg_pipeline skyToCubePipeline; + + // GGX-prefiltered sky cube. GFX_IBL_CUBE_MIPS mips x 6 faces. Mip 0 + // is the mirror (effectively a copy of skyCubeRaw). Deeper mips are + // progressively rougher. This is what the lit pipelines sample. + sg_image skyCube; + sg_view skyCubeFaceMipAttachmentViews[6 * GFX_IBL_CUBE_MIPS]; + sg_view skyCubeSampleView; + sg_sampler skyCubeSampler; // trilinear, clamp_to_edge + sg_shader prefilterShader; + sg_pipeline prefilterPipeline; + + // SH cache. Filled by RebuildImageBasedLightingIfDirty. + b3Vec3 shCoeffs[9]; + + // Dirty flag. Set true by MarkIblDirty + initial state. Cleared + // by RebuildImageBasedLightingIfDirty after a successful rebuild. + bool dirty; + bool ready; +} s_ibl; + +// CPU Preetham (mirror of common/preetham.glsl) +// +// Keeps SH projection in lockstep with the GPU sky. The math is verbatim +// from the shader. Comments are deliberately spare to avoid two sources +// of truth, read preetham.glsl for the rationale. + +static float PreethamPerezC( float cos_theta, float cos_gamma, float gamma, float A, float B, float C, float D, float E ) +{ + const float ct = ( cos_theta < 0.01f ) ? 0.01f : cos_theta; + const float term1 = 1.0f + A * expf( B / ct ); + const float term2 = 1.0f + C * expf( D * gamma ) + E * cos_gamma * cos_gamma; + return term1 * term2; +} + +static b3Vec3 PreethamSkyScaledC( b3Vec3 view_dir, b3Vec3 sun_dir, float turbidity, float fade ) +{ + const float PI = 3.14159265358979323846f; + const float LUMINANCE_SCALE = 0.06f; // mirrors PREETHAM_LUMINANCE_SCALE + + const float sun_y_clamped = ( sun_dir.y < 0.0f ) ? 0.0f : ( sun_dir.y > 1.0f ) ? 1.0f : sun_dir.y; + + b3Vec3 view_clamped; + view_clamped.x = view_dir.x; + view_clamped.y = ( view_dir.y > 0.0f ? view_dir.y : 0.0f ) + 0.01f; + view_clamped.z = view_dir.z; + const float vlen = + sqrtf( view_clamped.x * view_clamped.x + view_clamped.y * view_clamped.y + view_clamped.z * view_clamped.z ); + if ( vlen > 0.0f ) + { + view_clamped.x /= vlen; + view_clamped.y /= vlen; + view_clamped.z /= vlen; + } + + const float cos_theta = ( view_clamped.y > 0.0f ) ? view_clamped.y : 0.0f; + float cos_gamma = sun_dir.x * view_clamped.x + sun_dir.y * view_clamped.y + sun_dir.z * view_clamped.z; + if ( cos_gamma < -1.0f ) + cos_gamma = -1.0f; + if ( cos_gamma > 1.0f ) + cos_gamma = 1.0f; + const float gamma = acosf( cos_gamma ); + const float sun_theta = acosf( sun_y_clamped ); + + const float T = ( turbidity < 1.0f ) ? 1.0f : turbidity; + const float T2 = T * T; + + const float A_Y = 0.1787f * T - 1.4630f; + const float B_Y = -0.3554f * T + 0.4275f; + const float C_Y = -0.0227f * T + 5.3251f; + const float D_Y = 0.1206f * T - 2.5771f; + const float E_Y = -0.0670f * T + 0.3703f; + const float A_x = -0.0193f * T - 0.2592f; + const float B_x = -0.0665f * T + 0.0008f; + const float C_x = -0.0004f * T + 0.2125f; + const float D_x = -0.0641f * T - 0.8989f; + const float E_x = -0.0033f * T + 0.0452f; + const float A_y = -0.0167f * T - 0.2608f; + const float B_y = -0.0950f * T + 0.0092f; + const float C_y = -0.0079f * T + 0.2102f; + const float D_y = -0.0441f * T - 1.6537f; + const float E_y = -0.0109f * T + 0.0529f; + + const float ts = sun_theta; + const float ts2 = ts * ts; + const float ts3 = ts2 * ts; + + const float x_z = ( 0.00166f * ts3 - 0.00375f * ts2 + 0.00209f * ts ) * T2 + + ( -0.02903f * ts3 + 0.06377f * ts2 - 0.03202f * ts + 0.00394f ) * T + + ( 0.11693f * ts3 - 0.21196f * ts2 + 0.06052f * ts + 0.25886f ); + const float y_z = ( 0.00275f * ts3 - 0.00610f * ts2 + 0.00317f * ts ) * T2 + + ( -0.04214f * ts3 + 0.08970f * ts2 - 0.04153f * ts + 0.00516f ) * T + + ( 0.15346f * ts3 - 0.26756f * ts2 + 0.06670f * ts + 0.26688f ); + + const float chi = ( 4.0f / 9.0f - T / 120.0f ) * ( PI - 2.0f * sun_theta ); + const float Y_z = ( 4.0453f * T - 4.9710f ) * tanf( chi ) - 0.2155f * T + 2.4192f; + + const float cos_zen_gamma = sun_y_clamped; + const float pY_v = PreethamPerezC( cos_theta, cos_gamma, gamma, A_Y, B_Y, C_Y, D_Y, E_Y ); + const float px_v = PreethamPerezC( cos_theta, cos_gamma, gamma, A_x, B_x, C_x, D_x, E_x ); + const float py_v = PreethamPerezC( cos_theta, cos_gamma, gamma, A_y, B_y, C_y, D_y, E_y ); + const float pY_z = PreethamPerezC( 1.0f, cos_zen_gamma, sun_theta, A_Y, B_Y, C_Y, D_Y, E_Y ); + const float px_z = PreethamPerezC( 1.0f, cos_zen_gamma, sun_theta, A_x, B_x, C_x, D_x, E_x ); + const float py_z = PreethamPerezC( 1.0f, cos_zen_gamma, sun_theta, A_y, B_y, C_y, D_y, E_y ); + + const float pY_z_safe = ( pY_z < 1.0e-5f ) ? 1.0e-5f : pY_z; + const float px_z_safe = ( px_z < 1.0e-5f ) ? 1.0e-5f : px_z; + const float py_z_safe = ( py_z < 1.0e-5f ) ? 1.0e-5f : py_z; + + float Y = Y_z * pY_v / pY_z_safe; + if ( Y < 0.0f ) + Y = 0.0f; + const float x = x_z * px_v / px_z_safe; + const float y = y_z * py_v / py_z_safe; + + const float yy = ( y < 1.0e-5f ) ? 1.0e-5f : y; + const float X_xyz = Y * x / yy; + const float Y_xyz = Y; + const float Z_xyz = Y * ( 1.0f - x - y ) / yy; + + b3Vec3 rgb; + rgb.x = ( X_xyz * 3.2404542f ) + ( Y_xyz * -1.5371385f ) + ( Z_xyz * -0.4985314f ); + rgb.y = ( X_xyz * -0.9692660f ) + ( Y_xyz * 1.8760108f ) + ( Z_xyz * 0.0415560f ); + rgb.z = ( X_xyz * 0.0556434f ) + ( Y_xyz * -0.2040259f ) + ( Z_xyz * 1.0572252f ); + if ( rgb.x < 0.0f ) + rgb.x = 0.0f; + if ( rgb.y < 0.0f ) + rgb.y = 0.0f; + if ( rgb.z < 0.0f ) + rgb.z = 0.0f; + rgb.x *= LUMINANCE_SCALE * fade; + rgb.y *= LUMINANCE_SCALE * fade; + rgb.z *= LUMINANCE_SCALE * fade; + return rgb; +} + +// Cube-texel solid-angle approximation. Closed form: +// domega = 4 / ((u^2 + v^2 + 1)^1.5 * N^2) +// where (u, v) in [-1, +1] is the texel-center face coordinate and N is +// the face resolution. Sufficient at the 32^2 SH sampling grid. +static float cubeTexelSolidAngle( float u, float v, int n ) +{ + const float d2 = u * u + v * v + 1.0f; + const float denom = sqrtf( d2 * d2 * d2 ) * (float)n * (float)n; + return 4.0f / denom; +} + +// Project the procedural sky into 9 RGB SH coefficients (band 0..2) by +// evaluating closed-form Preetham at 32^2 stratified samples per face, +// accumulating sum L(omega) * Y_i(omega) * domega, then multiplying by the Funk-Hecke +// diffuse convolution weights so the shader's evaluation is a straight +// dot product against the SH basis. +static void ProjectSkyToSh( b3Vec3 dirToSun, float turbidity, float fade ) +{ + b3Vec3 coef[9]; + for ( int i = 0; i < 9; ++i ) + { + coef[i] = b3Vec3_zero; + } + + const int N = IBL_SH_SAMPLES_PER_FACE; + const float pixSize = 2.0f / (float)N; + + for ( int face = 0; face < 6; ++face ) + { + const CubeFaceBasis b = s_cubeFaceBasis[face]; + for ( int row = 0; row < N; ++row ) + { + for ( int col = 0; col < N; ++col ) + { + const float u = ( (float)col + 0.5f ) * pixSize - 1.0f; + const float v = ( (float)row + 0.5f ) * pixSize - 1.0f; + + b3Vec3 dir; + dir.x = b.forward.x + u * b.right.x + v * b.up.x; + dir.y = b.forward.y + u * b.right.y + v * b.up.y; + dir.z = b.forward.z + u * b.right.z + v * b.up.z; + const float dlen = sqrtf( dir.x * dir.x + dir.y * dir.y + dir.z * dir.z ); + if ( dlen > 0.0f ) + { + dir.x /= dlen; + dir.y /= dlen; + dir.z /= dlen; + } + + const float dW = cubeTexelSolidAngle( u, v, N ); + const b3Vec3 L = PreethamSkyScaledC( dir, dirToSun, turbidity, fade ); + + const float x = dir.x; + const float y = dir.y; + const float z = dir.z; + + const float basis[9] = { + SH_Y00, + -SH_Y1n1 * y, + SH_Y10 * z, + -SH_Y1p1 * x, + SH_Y2n2 * x * y, + -SH_Y2n1 * y * z, + SH_Y20 * ( 3.0f * z * z - 1.0f ), + -SH_Y2p1 * x * z, + SH_Y2p2 * ( x * x - y * y ), + }; + + for ( int i = 0; i < 9; ++i ) + { + const float w = basis[i] * dW; + coef[i].x += L.x * w; + coef[i].y += L.y * w; + coef[i].z += L.z * w; + } + } + } + } + + // Apply Funk-Hecke / Ramamoorthi convolution weights so the shader + // can evaluate irradiance as a straight dot product. + const float scale[9] = { + SH_A0, SH_A1, SH_A1, SH_A1, SH_A2, SH_A2, SH_A2, SH_A2, SH_A2, + }; + for ( int i = 0; i < 9; ++i ) + { + s_ibl.shCoeffs[i].x = coef[i].x * scale[i]; + s_ibl.shCoeffs[i].y = coef[i].y * scale[i]; + s_ibl.shCoeffs[i].z = coef[i].z * scale[i]; + } +} + +static void GenerateBrdfLut( void ) +{ + // One-shot pass into the LUT's color attachment. Discard load (we + // overwrite every pixel), no clear necessary. + sg_pass pass = { 0 }; + pass.action.colors[0].load_action = SG_LOADACTION_DONTCARE; + pass.action.colors[0].store_action = SG_STOREACTION_STORE; + pass.attachments.colors[0] = s_ibl.brdfLutColorAttachmentView; + + sg_push_debug_group( "ibl_brdf_lut" ); + sg_begin_pass( &pass ); + sg_apply_pipeline( s_ibl.brdfLutPipeline ); + // params.x: backend-conditional UV.y sign for the LUT's render-target + // V orientation, see brdf_lut.glsl. +1 on GL (NDC.y=+1 stores at the + // texel addressed by sampling V=1), -1 on D3D11/Metal/WGPU (NDC.y=+1 + // stores at the texel addressed by sampling V=0). Without this, the + // lit shaders' sample at (n_dot_v, roughness) reads the LUT for + // (n_dot_v, 1-roughness) on non-GL backends, metals look dark and + // rough materials look mirror-smooth. + const sg_backend backend = sg_query_backend(); + const float uvYSign = ( backend == SG_BACKEND_GLCORE || backend == SG_BACKEND_GLES3 ) ? 1.0f : -1.0f; + brdf_lut_ub_brdf_t ub = { 0 }; + ub.params = MakeVec4( uvYSign, 0.0f, 0.0f, 0.0f ); + sg_apply_uniforms( UB_brdf_lut_ub_brdf, &SG_RANGE( ub ) ); + // No texture bindings, sokol's VALIDATE_ABND_EMPTY_BINDINGS rejects + // an empty sg_apply_bindings call, so skip it entirely. + sg_draw( 0, 3, 1 ); + sg_end_pass(); + sg_pop_debug_group(); +} + +static void GenerateSkyCube( b3Vec3 dirToSun, float turbidity, float fade ) +{ + // Six passes, one per face. Each pass fills the raw cube's + // corresponding face via a fullscreen-triangle Preetham eval. + sg_push_debug_group( "ibl_sky_to_cube" ); + for ( int face = 0; face < 6; ++face ) + { + sg_pass pass = { 0 }; + pass.action.colors[0].load_action = SG_LOADACTION_DONTCARE; + pass.action.colors[0].store_action = SG_STOREACTION_STORE; + pass.attachments.colors[0] = s_ibl.skyCubeRawFaceAttachmentViews[face]; + + sg_begin_pass( &pass ); + sg_apply_pipeline( s_ibl.skyToCubePipeline ); + + const CubeFaceBasis b = s_cubeFaceBasis[face]; + sky_to_cube_ub_face_t up = { 0 }; + up.face_right = MakeVec4( b.right.x, b.right.y, b.right.z, 0.0f ); + up.face_up = MakeVec4( b.up.x, b.up.y, b.up.z, 0.0f ); + up.face_forward = MakeVec4( b.forward.x, b.forward.y, b.forward.z, fade ); + up.sun_dir_world = MakeVec4( dirToSun.x, dirToSun.y, dirToSun.z, turbidity ); + sg_apply_uniforms( UB_sky_to_cube_ub_face, &SG_RANGE( up ) ); + + sg_draw( 0, 3, 1 ); + sg_end_pass(); + } + sg_pop_debug_group(); +} + +static void GeneratePrefilter( void ) +{ + // For each mip x face, importance-sample the raw cube into the + // prefiltered cube's corresponding face slice. Roughness maps + // linearly across mips: mip 0 = 0 (mirror), mip N-1 = 1 (max rough). + sg_push_debug_group( "ibl_prefilter" ); + const float mipDenom = (float)( GFX_IBL_CUBE_MIPS - 1 ); + + for ( int mip = 0; mip < GFX_IBL_CUBE_MIPS; ++mip ) + { + const float roughness = ( mipDenom > 0.0f ) ? ( (float)mip / mipDenom ) : 0.0f; + for ( int face = 0; face < 6; ++face ) + { + sg_pass pass = { 0 }; + pass.action.colors[0].load_action = SG_LOADACTION_DONTCARE; + pass.action.colors[0].store_action = SG_STOREACTION_STORE; + pass.attachments.colors[0] = s_ibl.skyCubeFaceMipAttachmentViews[face * GFX_IBL_CUBE_MIPS + mip]; + + sg_begin_pass( &pass ); + sg_apply_pipeline( s_ibl.prefilterPipeline ); + + sg_bindings bindings = { 0 }; + bindings.views[VIEW_prefilter_tex_sky] = s_ibl.skyCubeRawSampleView; + bindings.samplers[SMP_prefilter_smp_sky] = s_ibl.skyCubeSampler; + sg_apply_bindings( &bindings ); + + const CubeFaceBasis b = s_cubeFaceBasis[face]; + prefilter_ub_pass_t up = { 0 }; + up.face_right = MakeVec4( b.right.x, b.right.y, b.right.z, 0.0f ); + up.face_up = MakeVec4( b.up.x, b.up.y, b.up.z, 0.0f ); + up.face_forward = MakeVec4( b.forward.x, b.forward.y, b.forward.z, 0.0f ); + up.params = MakeVec4( roughness, 0.0f, 0.0f, 0.0f ); + sg_apply_uniforms( UB_prefilter_ub_pass, &SG_RANGE( up ) ); + + sg_draw( 0, 3, 1 ); + sg_end_pass(); + } + } + sg_pop_debug_group(); +} + +void InitImageBasedLighting( const sg_environment* env ) +{ + (void)env; + + // BRDF LUT image + views + sampler + sg_image_desc lutDesc = { 0 }; + lutDesc.usage.color_attachment = true; + lutDesc.width = GFX_IBL_LUT_SIZE; + lutDesc.height = GFX_IBL_LUT_SIZE; + lutDesc.pixel_format = SG_PIXELFORMAT_RG16F; + lutDesc.sample_count = 1; + lutDesc.label = "ibl_brdf_lut"; + s_ibl.brdfLut = sg_make_image( &lutDesc ); + + sg_view_desc lutAttachDesc = { 0 }; + lutAttachDesc.color_attachment.image = s_ibl.brdfLut; + lutAttachDesc.label = "ibl_brdf_lut_attachment"; + s_ibl.brdfLutColorAttachmentView = sg_make_view( &lutAttachDesc ); + + sg_view_desc lutSampleDesc = { 0 }; + lutSampleDesc.texture.image = s_ibl.brdfLut; + lutSampleDesc.label = "ibl_brdf_lut_sample"; + s_ibl.brdfLutSampleView = sg_make_view( &lutSampleDesc ); + + sg_sampler_desc lutSampDesc = { 0 }; + lutSampDesc.min_filter = SG_FILTER_LINEAR; + lutSampDesc.mag_filter = SG_FILTER_LINEAR; + lutSampDesc.mipmap_filter = SG_FILTER_NEAREST; + lutSampDesc.wrap_u = SG_WRAP_CLAMP_TO_EDGE; + lutSampDesc.wrap_v = SG_WRAP_CLAMP_TO_EDGE; + lutSampDesc.wrap_w = SG_WRAP_CLAMP_TO_EDGE; + lutSampDesc.label = "ibl_brdf_lut_sampler"; + s_ibl.brdfLutSampler = sg_make_sampler( &lutSampDesc ); + + s_ibl.brdfLutShader = sg_make_shader( brdf_lut_build_shader_desc( sg_query_backend() ) ); + + sg_pipeline_desc lutPipeDesc = { 0 }; + lutPipeDesc.shader = s_ibl.brdfLutShader; + lutPipeDesc.colors[0].pixel_format = SG_PIXELFORMAT_RG16F; + lutPipeDesc.color_count = 1; + lutPipeDesc.depth.pixel_format = SG_PIXELFORMAT_NONE; + lutPipeDesc.depth.write_enabled = false; + lutPipeDesc.depth.compare = SG_COMPAREFUNC_ALWAYS; + lutPipeDesc.cull_mode = SG_CULLMODE_NONE; + lutPipeDesc.face_winding = SG_FACEWINDING_CCW; + lutPipeDesc.sample_count = 1; + lutPipeDesc.label = "ibl_brdf_lut_pipeline"; + s_ibl.brdfLutPipeline = sg_make_pipeline( &lutPipeDesc ); + + GenerateBrdfLut(); + + // Raw sky cube (sky_to_cube target / prefilter input) + sg_image_desc rawDesc = { 0 }; + rawDesc.type = SG_IMAGETYPE_CUBE; + rawDesc.usage.color_attachment = true; + rawDesc.width = GFX_IBL_CUBE_SIZE; + rawDesc.height = GFX_IBL_CUBE_SIZE; + rawDesc.num_mipmaps = 1; + rawDesc.pixel_format = SG_PIXELFORMAT_RGBA16F; + rawDesc.sample_count = 1; + rawDesc.label = "ibl_sky_cube_raw"; + s_ibl.skyCubeRaw = sg_make_image( &rawDesc ); + + for ( int face = 0; face < 6; ++face ) + { + sg_view_desc fdesc = { 0 }; + fdesc.color_attachment.image = s_ibl.skyCubeRaw; + fdesc.color_attachment.slice = face; + fdesc.color_attachment.mip_level = 0; + fdesc.label = "ibl_sky_cube_raw_face"; + s_ibl.skyCubeRawFaceAttachmentViews[face] = sg_make_view( &fdesc ); + } + + sg_view_desc rawSampleDesc = { 0 }; + rawSampleDesc.texture.image = s_ibl.skyCubeRaw; + rawSampleDesc.label = "ibl_sky_cube_raw_sample"; + s_ibl.skyCubeRawSampleView = sg_make_view( &rawSampleDesc ); + + // Prefiltered sky cube (lit-pipeline input) + sg_image_desc cubeDesc = { 0 }; + cubeDesc.type = SG_IMAGETYPE_CUBE; + cubeDesc.usage.color_attachment = true; + cubeDesc.width = GFX_IBL_CUBE_SIZE; + cubeDesc.height = GFX_IBL_CUBE_SIZE; + cubeDesc.num_mipmaps = GFX_IBL_CUBE_MIPS; + cubeDesc.pixel_format = SG_PIXELFORMAT_RGBA16F; + cubeDesc.sample_count = 1; + cubeDesc.label = "ibl_sky_cube"; + s_ibl.skyCube = sg_make_image( &cubeDesc ); + + for ( int face = 0; face < 6; ++face ) + { + for ( int mip = 0; mip < GFX_IBL_CUBE_MIPS; ++mip ) + { + sg_view_desc fdesc = { 0 }; + fdesc.color_attachment.image = s_ibl.skyCube; + fdesc.color_attachment.slice = face; + fdesc.color_attachment.mip_level = mip; + fdesc.label = "ibl_sky_cube_face_mip"; + s_ibl.skyCubeFaceMipAttachmentViews[face * GFX_IBL_CUBE_MIPS + mip] = sg_make_view( &fdesc ); + } + } + + sg_view_desc cubeSampleDesc = { 0 }; + cubeSampleDesc.texture.image = s_ibl.skyCube; + cubeSampleDesc.label = "ibl_sky_cube_sample"; + s_ibl.skyCubeSampleView = sg_make_view( &cubeSampleDesc ); + + sg_sampler_desc cubeSampDesc = { 0 }; + cubeSampDesc.min_filter = SG_FILTER_LINEAR; + cubeSampDesc.mag_filter = SG_FILTER_LINEAR; + cubeSampDesc.mipmap_filter = SG_FILTER_LINEAR; + cubeSampDesc.wrap_u = SG_WRAP_CLAMP_TO_EDGE; + cubeSampDesc.wrap_v = SG_WRAP_CLAMP_TO_EDGE; + cubeSampDesc.wrap_w = SG_WRAP_CLAMP_TO_EDGE; + cubeSampDesc.label = "ibl_sky_cube_sampler"; + s_ibl.skyCubeSampler = sg_make_sampler( &cubeSampDesc ); + + // sky_to_cube pipeline + s_ibl.skyToCubeShader = sg_make_shader( sky_to_cube_build_shader_desc( sg_query_backend() ) ); + + sg_pipeline_desc skyPipeDesc = { 0 }; + skyPipeDesc.shader = s_ibl.skyToCubeShader; + skyPipeDesc.colors[0].pixel_format = SG_PIXELFORMAT_RGBA16F; + skyPipeDesc.color_count = 1; + skyPipeDesc.depth.pixel_format = SG_PIXELFORMAT_NONE; + skyPipeDesc.depth.write_enabled = false; + skyPipeDesc.depth.compare = SG_COMPAREFUNC_ALWAYS; + skyPipeDesc.cull_mode = SG_CULLMODE_NONE; + skyPipeDesc.face_winding = SG_FACEWINDING_CCW; + skyPipeDesc.sample_count = 1; + skyPipeDesc.label = "ibl_sky_to_cube_pipeline"; + s_ibl.skyToCubePipeline = sg_make_pipeline( &skyPipeDesc ); + + // prefilter pipeline + s_ibl.prefilterShader = sg_make_shader( prefilter_build_shader_desc( sg_query_backend() ) ); + + sg_pipeline_desc prePipeDesc = { 0 }; + prePipeDesc.shader = s_ibl.prefilterShader; + prePipeDesc.colors[0].pixel_format = SG_PIXELFORMAT_RGBA16F; + prePipeDesc.color_count = 1; + prePipeDesc.depth.pixel_format = SG_PIXELFORMAT_NONE; + prePipeDesc.depth.write_enabled = false; + prePipeDesc.depth.compare = SG_COMPAREFUNC_ALWAYS; + prePipeDesc.cull_mode = SG_CULLMODE_NONE; + prePipeDesc.face_winding = SG_FACEWINDING_CCW; + prePipeDesc.sample_count = 1; + prePipeDesc.label = "ibl_prefilter_pipeline"; + s_ibl.prefilterPipeline = sg_make_pipeline( &prePipeDesc ); + + // SH cache starts zero, RebuildImageBasedLightingIfDirty fills it. + for ( int i = 0; i < 9; ++i ) + { + s_ibl.shCoeffs[i] = b3Vec3_zero; + } + s_ibl.dirty = true; + s_ibl.ready = true; +} + +void ShutdownImageBasedLighting( void ) +{ + if ( !s_ibl.ready ) + { + return; + } + + sg_destroy_pipeline( s_ibl.prefilterPipeline ); + sg_destroy_shader( s_ibl.prefilterShader ); + sg_destroy_pipeline( s_ibl.skyToCubePipeline ); + sg_destroy_shader( s_ibl.skyToCubeShader ); + + sg_destroy_sampler( s_ibl.skyCubeSampler ); + sg_destroy_view( s_ibl.skyCubeSampleView ); + for ( int i = 0; i < 6 * GFX_IBL_CUBE_MIPS; ++i ) + { + sg_destroy_view( s_ibl.skyCubeFaceMipAttachmentViews[i] ); + } + sg_destroy_image( s_ibl.skyCube ); + + sg_destroy_view( s_ibl.skyCubeRawSampleView ); + for ( int face = 0; face < 6; ++face ) + { + sg_destroy_view( s_ibl.skyCubeRawFaceAttachmentViews[face] ); + } + sg_destroy_image( s_ibl.skyCubeRaw ); + + sg_destroy_pipeline( s_ibl.brdfLutPipeline ); + sg_destroy_shader( s_ibl.brdfLutShader ); + sg_destroy_sampler( s_ibl.brdfLutSampler ); + sg_destroy_view( s_ibl.brdfLutSampleView ); + sg_destroy_view( s_ibl.brdfLutColorAttachmentView ); + sg_destroy_image( s_ibl.brdfLut ); + s_ibl.ready = false; +} + +void MarkIblDirty( void ) +{ + s_ibl.dirty = true; +} + +void RebuildImageBasedLightingIfDirty( b3Vec3 dirToSun, float turbidity ) +{ + if ( s_ibl.dirty == false || s_ibl.ready == false ) + { + return; + } + + // Renormalize just in case to avoid NaNs + float lenSq = dirToSun.x * dirToSun.x + dirToSun.y * dirToSun.y + dirToSun.z * dirToSun.z; + b3Vec3 sun = ( lenSq > 0.0f ) ? b3Normalize( dirToSun ) : b3Vec3_axisY; + float fade = SkySunFadeWeight( sun ); + + sg_push_debug_group( "ibl_rebuild" ); + + GenerateSkyCube( sun, turbidity, fade ); + GeneratePrefilter(); + ProjectSkyToSh( sun, turbidity, fade ); + + sg_pop_debug_group(); + + s_ibl.dirty = false; +} + +sg_view GetIblSpecularView( void ) +{ + return s_ibl.skyCubeSampleView; +} + +sg_sampler GetIblSpecularSampler( void ) +{ + return s_ibl.skyCubeSampler; +} + +float GetIblSpecularMaxLod( void ) +{ + return (float)( GFX_IBL_CUBE_MIPS - 1 ); +} + +sg_view GetIblBrdfLutView( void ) +{ + return s_ibl.brdfLutSampleView; +} + +sg_sampler GetIblBrdfLutSampler( void ) +{ + return s_ibl.brdfLutSampler; +} + +void GetIblSphericalHarmonicCoefficients( b3Vec3 out[9] ) +{ + for ( int i = 0; i < 9; ++i ) + { + out[i] = s_ibl.shCoeffs[i]; + } +} diff --git a/samples/gfx/ibl.h b/samples/gfx/ibl.h new file mode 100644 index 0000000..a5b9278 --- /dev/null +++ b/samples/gfx/ibl.h @@ -0,0 +1,75 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Image-based lighting from the procedural sky. +// +// Owns three persistent GPU resources plus a CPU-side cache: +// * BRDF integration LUT (Karis split-sum, RG16F 256^2), generated once +// at boot. Environment-independent. +// * Sky cubemap with full GGX-prefiltered mip chain (RGBA16F 6x256^2), +// regenerated when the sun direction or turbidity changes. +// * Diffuse irradiance, 9 spherical-harmonic coefficients per channel, +// evaluated on the CPU from the closed-form Preetham model. Cached +// and uploaded into the lit pipelines' ub_pass each frame. +// +// The lit pipelines consume IBL by: +// 1. Calling GetIblSphericalHarmonicCoefficients to get the diffuse SH (copied into ub_pass). +// 2. Binding GetIblSpecularView / GetIblSpecularSampler for the +// prefiltered cubemap and GetIblBrdfLutView / GetIblBrdfLutSampler +// for the LUT. +// 3. Passing GetIblSpecularMaxLod so the shader can scale roughness +// to a mip level. +// +// MarkIblDirty + RebuildImageBasedLightingIfDirty are the rebuild hook. The +// renderer marks dirty when SetSun is called, then calls +// RebuildImageBasedLightingIfDirty at the top of DrawScene, the rebuild is a no-op +// when not dirty. + +#pragma once + +#include "gfx/utility.h" +#include "sokol_gfx.h" + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +// Cube faces are 256^2, small enough for cheap regeneration on sun +// change, large enough that mid-roughness prefilter mips read clean. +// 7 mip levels covers all roughness from 0 (mip 0) to 1 (mip 6 = 4^2). +#define GFX_IBL_CUBE_SIZE 256 +#define GFX_IBL_CUBE_MIPS 7 +#define GFX_IBL_LUT_SIZE 256 + +void InitImageBasedLighting( const sg_environment* env ); +void ShutdownImageBasedLighting( void ); + +// Mark the cube map + SH as stale. Cheap, the actual GPU regen + CPU SH +// projection happens on the next RebuildImageBasedLightingIfDirty call. +void MarkIblDirty( void ); + +// If dirty, regenerate the prefiltered sky cube and recompute SH from +// the current sun direction + turbidity. Idempotent when clean. +void RebuildImageBasedLightingIfDirty( b3Vec3 dirToSun, float turbidity ); + +// Prefiltered sky cubemap (mip 0 = mirror, mip GFX_IBL_CUBE_MIPS-1 = +// fully rough). Bind once per lit-pipeline draw. +sg_view GetIblSpecularView( void ); +sg_sampler GetIblSpecularSampler( void ); +float GetIblSpecularMaxLod( void ); + +// BRDF integration LUT. Sample with (n_dot_v, roughness) UVs. +sg_view GetIblBrdfLutView( void ); +sg_sampler GetIblBrdfLutSampler( void ); + +// Copy the 9 RGB SH coefficients (band 0 through band 2) into `out`. +// Layout matches the lit shaders' ub_pass.sh[9] slot, each coefficient +// is a vec3, written as 9 consecutive b3Vec3. +void GetIblSphericalHarmonicCoefficients( b3Vec3 out[9] ); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/samples/gfx/keycodes.h b/samples/gfx/keycodes.h new file mode 100644 index 0000000..e3d804d --- /dev/null +++ b/samples/gfx/keycodes.h @@ -0,0 +1,55 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Named key / modifier / mouse-button aliases over sokol_app's codes, so +// host Sample code can read input without including sokol_app.h directly. +// render3d's own code uses SAPP_* directly; this header is for the port-side +// host shell. The aliases are the codes actually exercised by the samples +// (character + joint movers, scene hotkeys, picking). + +#pragma once + +#include "sokol_app.h" + +#include + +enum +{ + KEY_A = SAPP_KEYCODE_A, + KEY_B = SAPP_KEYCODE_B, + KEY_D = SAPP_KEYCODE_D, + KEY_F = SAPP_KEYCODE_F, + KEY_L = SAPP_KEYCODE_L, + KEY_M = SAPP_KEYCODE_M, + KEY_O = SAPP_KEYCODE_O, + KEY_P = SAPP_KEYCODE_P, + KEY_R = SAPP_KEYCODE_R, + KEY_S = SAPP_KEYCODE_S, + KEY_T = SAPP_KEYCODE_T, + KEY_V = SAPP_KEYCODE_V, + KEY_W = SAPP_KEYCODE_W, + KEY_SPACE = SAPP_KEYCODE_SPACE, + KEY_ESCAPE = SAPP_KEYCODE_ESCAPE, + KEY_TAB = SAPP_KEYCODE_TAB, + KEY_HOME = SAPP_KEYCODE_HOME, + KEY_LEFT_SHIFT = SAPP_KEYCODE_LEFT_SHIFT, + KEY_LEFT_BRACKET = SAPP_KEYCODE_LEFT_BRACKET, + KEY_RIGHT_BRACKET = SAPP_KEYCODE_RIGHT_BRACKET, + + MOD_SHIFT = SAPP_MODIFIER_SHIFT, + MOD_CTRL = SAPP_MODIFIER_CTRL, + MOD_ALT = SAPP_MODIFIER_ALT, + + MOUSE_LEFT = SAPP_MOUSEBUTTON_LEFT, + MOUSE_RIGHT = SAPP_MOUSEBUTTON_RIGHT, + MOUSE_MIDDLE = SAPP_MOUSEBUTTON_MIDDLE, +}; + +// Spot-check that the aliases still track sokol_app at compile time. One per +// enum source (keycode, modifier, mouse button) is enough to catch a drift. +// Cast to int so the compare doesn't trip C++'s deprecated cross-enum-type +// comparison warning under -Werror. +static_assert( (int)KEY_W == (int)SAPP_KEYCODE_W, "keycode alias drift" ); +static_assert( (int)KEY_ESCAPE == (int)SAPP_KEYCODE_ESCAPE, "keycode alias drift" ); +static_assert( (int)MOD_SHIFT == (int)SAPP_MODIFIER_SHIFT, "modifier alias drift" ); +static_assert( (int)MOUSE_LEFT == (int)SAPP_MOUSEBUTTON_LEFT, "mouse button alias drift" ); diff --git a/samples/gfx/overlay.c b/samples/gfx/overlay.c new file mode 100644 index 0000000..8927f35 --- /dev/null +++ b/samples/gfx/overlay.c @@ -0,0 +1,403 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +#include "gfx/overlay.h" + +#include "gfx/arena.h" +#include "overlay_line.glsl.h" +#include "overlay_point.glsl.h" + +#include +#include + +#define MAX_LINES 65536 +#define MAX_POINTS 65536 + +// The overlay draws into the post-tone map target (swap chain or the offscreen +// test target). Two slots cover both. The swap chain (has a depth +// attachment) and the color-only offscreen target. Mirrors tonemap.c's +// cache. Hitting the cap means a third color/depth pair appeared. +#define OVERLAY_MAX_PIPELINES 2 + +static struct +{ + Arena lineArena; + Arena pointArena; + + overlay_line_line_instance_t* lineBase; + overlay_point_point_instance_t* pointBase; + int lineCount; + int pointCount; + + sg_shader lineShader; + sg_shader pointShader; + + // Pipelines are created lazily per (color, depth) output-format pair. + // The post-tone map target's format isn't known at init time. + struct + { + sg_pixel_format colorFormat; + sg_pixel_format depthFormat; + sg_pipeline linePipeline; + sg_pipeline pointPipeline; + } pipelines[OVERLAY_MAX_PIPELINES]; + int pipelineCount; + + sg_buffer lineInstBuf; + sg_buffer pointInstBuf; + sg_view lineInstView; + sg_view pointInstView; + + bool ready; +} s_overlay; + +static uint32_t PackThicknessFlag( OverlayThicknessUnit unit ) +{ + return ( unit == OVERLAY_THICKNESS_WORLD ) ? 1u : 0u; +} + +static uint32_t PackOcclusionFlag( OverlayOcclusionMode mode ) +{ + switch ( mode ) + { + case OVERLAY_OCCLUSION_DIM: + return 1u; + case OVERLAY_OCCLUSION_DASHED: + return 2u; + case OVERLAY_OCCLUSION_HIDE: /* fallthrough */ + default: + return 0u; + } +} + +static Vec4 Premultiply( Vec4 c ) +{ + return MakeVec4( c.x * c.w, c.y * c.w, c.z * c.w, c.w ); +} + +// Lazily create (and cache) the line + point pipelines for one output +// format pair. Mirrors tonemap.c::ensurePipeline. The overlay draws +// post-tonemap into the swapchain or an offscreen test target, both +// single-sample, so sample_count is fixed at 1. The line/point shaders +// carry their own SDF coverage AA. Returns false (and logs) if the cache +// is full. +static bool EnsurePipelines( sg_pixel_format colorFormat, sg_pixel_format depthFormat, sg_pipeline* outLine, + sg_pipeline* outPoint ) +{ + for ( int i = 0; i < s_overlay.pipelineCount; ++i ) + { + if ( s_overlay.pipelines[i].colorFormat == colorFormat && s_overlay.pipelines[i].depthFormat == depthFormat ) + { + *outLine = s_overlay.pipelines[i].linePipeline; + *outPoint = s_overlay.pipelines[i].pointPipeline; + return true; + } + } + if ( s_overlay.pipelineCount >= OVERLAY_MAX_PIPELINES ) + { + fprintf( stderr, "[overlay] pipeline cache exhausted (max %d format pairs)\n", OVERLAY_MAX_PIPELINES ); + return false; + } + + // Line pipeline + sg_pipeline_desc linePdesc = { 0 }; + linePdesc.shader = s_overlay.lineShader; + // No VBO / no IBO, VS expands six vertices per instance from + // gl_VertexIndex. Default layout (no attrs declared) is correct. + linePdesc.index_type = SG_INDEXTYPE_NONE; + linePdesc.cull_mode = SG_CULLMODE_NONE; + linePdesc.colors[0].pixel_format = colorFormat; + linePdesc.color_count = 1; + // Premultiplied-alpha blend. CPU side premultiplies color.rgb by .a. + linePdesc.colors[0].blend.enabled = true; + linePdesc.colors[0].blend.src_factor_rgb = SG_BLENDFACTOR_ONE; + linePdesc.colors[0].blend.dst_factor_rgb = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA; + linePdesc.colors[0].blend.op_rgb = SG_BLENDOP_ADD; + linePdesc.colors[0].blend.src_factor_alpha = SG_BLENDFACTOR_ONE; + linePdesc.colors[0].blend.dst_factor_alpha = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA; + linePdesc.colors[0].blend.op_alpha = SG_BLENDOP_ADD; + // Depth-blind: compare ALWAYS, write off. pixel_format still has to + // match the target's depth attachment (or NONE) for sokol's validation. + linePdesc.depth.pixel_format = depthFormat; + linePdesc.depth.compare = SG_COMPAREFUNC_ALWAYS; + linePdesc.depth.write_enabled = false; + linePdesc.sample_count = 1; + linePdesc.label = "overlay_line_pipeline"; + const sg_pipeline linePip = sg_make_pipeline( &linePdesc ); + + // Point pipeline + sg_pipeline_desc pointPdesc = { 0 }; + pointPdesc.shader = s_overlay.pointShader; + pointPdesc.index_type = SG_INDEXTYPE_NONE; + pointPdesc.cull_mode = SG_CULLMODE_NONE; + pointPdesc.colors[0].pixel_format = colorFormat; + pointPdesc.color_count = 1; + pointPdesc.colors[0].blend.enabled = true; + pointPdesc.colors[0].blend.src_factor_rgb = SG_BLENDFACTOR_ONE; + pointPdesc.colors[0].blend.dst_factor_rgb = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA; + pointPdesc.colors[0].blend.op_rgb = SG_BLENDOP_ADD; + pointPdesc.colors[0].blend.src_factor_alpha = SG_BLENDFACTOR_ONE; + pointPdesc.colors[0].blend.dst_factor_alpha = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA; + pointPdesc.colors[0].blend.op_alpha = SG_BLENDOP_ADD; + pointPdesc.depth.pixel_format = depthFormat; + pointPdesc.depth.compare = SG_COMPAREFUNC_ALWAYS; + pointPdesc.depth.write_enabled = false; + pointPdesc.sample_count = 1; + pointPdesc.label = "overlay_point_pipeline"; + const sg_pipeline pointPip = sg_make_pipeline( &pointPdesc ); + + s_overlay.pipelines[s_overlay.pipelineCount].colorFormat = colorFormat; + s_overlay.pipelines[s_overlay.pipelineCount].depthFormat = depthFormat; + s_overlay.pipelines[s_overlay.pipelineCount].linePipeline = linePip; + s_overlay.pipelines[s_overlay.pipelineCount].pointPipeline = pointPip; + ++s_overlay.pipelineCount; + + *outLine = linePip; + *outPoint = pointPip; + return true; +} + +void OverlayInit( void ) +{ + if ( s_overlay.ready ) + { + return; + } + + if ( ArenaInit( &s_overlay.lineArena, (size_t)MAX_LINES * sizeof( overlay_line_line_instance_t ) ) != 0 ) + { + fprintf( stderr, "[overlay] failed to init line arena\n" ); + return; + } + if ( ArenaInit( &s_overlay.pointArena, (size_t)MAX_POINTS * sizeof( overlay_point_point_instance_t ) ) != 0 ) + { + fprintf( stderr, "[overlay] failed to init point arena\n" ); + ArenaShutdown( &s_overlay.lineArena ); + return; + } + + // Line instance buffer + shader + sg_buffer_desc lineBufDesc = { 0 }; + lineBufDesc.usage.storage_buffer = true; + lineBufDesc.usage.stream_update = true; + lineBufDesc.size = (size_t)MAX_LINES * sizeof( overlay_line_line_instance_t ); + lineBufDesc.label = "overlay_line_instances"; + s_overlay.lineInstBuf = sg_make_buffer( &lineBufDesc ); + + sg_view_desc lineViewDesc = { 0 }; + lineViewDesc.storage_buffer.buffer = s_overlay.lineInstBuf; + lineViewDesc.label = "overlay_line_instances_view"; + s_overlay.lineInstView = sg_make_view( &lineViewDesc ); + + s_overlay.lineShader = sg_make_shader( overlay_line_prog_shader_desc( sg_query_backend() ) ); + + // Point instance buffer + shader + sg_buffer_desc pointBufDesc = { 0 }; + pointBufDesc.usage.storage_buffer = true; + pointBufDesc.usage.stream_update = true; + pointBufDesc.size = (size_t)MAX_POINTS * sizeof( overlay_point_point_instance_t ); + pointBufDesc.label = "overlay_point_instances"; + s_overlay.pointInstBuf = sg_make_buffer( &pointBufDesc ); + + sg_view_desc pointViewDesc = { 0 }; + pointViewDesc.storage_buffer.buffer = s_overlay.pointInstBuf; + pointViewDesc.label = "overlay_point_instances_view"; + s_overlay.pointInstView = sg_make_view( &pointViewDesc ); + + s_overlay.pointShader = sg_make_shader( overlay_point_prog_shader_desc( sg_query_backend() ) ); + + s_overlay.ready = true; +} + +void OverlayShutdown( void ) +{ + if ( !s_overlay.ready ) + { + return; + } + for ( int i = 0; i < s_overlay.pipelineCount; ++i ) + { + sg_destroy_pipeline( s_overlay.pipelines[i].linePipeline ); + sg_destroy_pipeline( s_overlay.pipelines[i].pointPipeline ); + s_overlay.pipelines[i].linePipeline.id = 0; + s_overlay.pipelines[i].pointPipeline.id = 0; + s_overlay.pipelines[i].colorFormat = SG_PIXELFORMAT_NONE; + s_overlay.pipelines[i].depthFormat = SG_PIXELFORMAT_NONE; + } + s_overlay.pipelineCount = 0; + sg_destroy_shader( s_overlay.lineShader ); + s_overlay.lineShader.id = 0; + sg_destroy_shader( s_overlay.pointShader ); + s_overlay.pointShader.id = 0; + sg_destroy_view( s_overlay.lineInstView ); + s_overlay.lineInstView.id = 0; + sg_destroy_view( s_overlay.pointInstView ); + s_overlay.pointInstView.id = 0; + sg_destroy_buffer( s_overlay.lineInstBuf ); + s_overlay.lineInstBuf.id = 0; + sg_destroy_buffer( s_overlay.pointInstBuf ); + s_overlay.pointInstBuf.id = 0; + ArenaShutdown( &s_overlay.lineArena ); + ArenaShutdown( &s_overlay.pointArena ); + s_overlay.lineBase = NULL; + s_overlay.pointBase = NULL; + s_overlay.lineCount = 0; + s_overlay.pointCount = 0; + s_overlay.ready = false; +} + +void OverlayResetFrame( void ) +{ + ArenaReset( &s_overlay.lineArena ); + ArenaReset( &s_overlay.pointArena ); + s_overlay.lineBase = NULL; + s_overlay.pointBase = NULL; + s_overlay.lineCount = 0; + s_overlay.pointCount = 0; +} + +int OverlayLineCount( void ) +{ + return s_overlay.lineCount; +} +int OverlayPointCount( void ) +{ + return s_overlay.pointCount; +} + +void OverlayAppendLine( b3Vec3 a, b3Vec3 b, Vec4 linearColor, float thickness, OverlayThicknessUnit thicknessUnit, + OverlayOcclusionMode occlusionMode ) +{ + if ( s_overlay.lineCount >= MAX_LINES ) + { + return; + } + overlay_line_line_instance_t* inst = (overlay_line_line_instance_t*)ArenaAlloc( + &s_overlay.lineArena, sizeof( overlay_line_line_instance_t ), _Alignof( overlay_line_line_instance_t ) ); + if ( !inst ) + { + return; + } + if ( s_overlay.lineCount == 0 ) + { + s_overlay.lineBase = inst; + } + s_overlay.lineCount++; + + const Vec4 cpremul = Premultiply( linearColor ); + inst->a = MakeVec4( a.x, a.y, a.z, thickness ); + inst->b = MakeVec4( b.x, b.y, b.z, 0.0f ); + inst->color = cpremul; + inst->flags[0] = PackThicknessFlag( thicknessUnit ); + inst->flags[1] = PackOcclusionFlag( occlusionMode ); + inst->flags[2] = 0; + inst->flags[3] = 0; +} + +void OverlayAppendPoint( b3Vec3 p, Vec4 linearColor, float size, OverlayThicknessUnit sizeUnit, OverlayOcclusionMode occlusionMode ) +{ + if ( s_overlay.pointCount >= MAX_POINTS ) + { + return; + } + overlay_point_point_instance_t* inst = (overlay_point_point_instance_t*)ArenaAlloc( + &s_overlay.pointArena, sizeof( overlay_point_point_instance_t ), _Alignof( overlay_point_point_instance_t ) ); + if ( !inst ) + { + return; + } + if ( s_overlay.pointCount == 0 ) + { + s_overlay.pointBase = inst; + } + s_overlay.pointCount++; + + const Vec4 cpremul = Premultiply( linearColor ); + inst->p = MakeVec4( p.x, p.y, p.z, size ); + inst->color = cpremul; + inst->flags[0] = PackThicknessFlag( sizeUnit ); + inst->flags[1] = PackOcclusionFlag( occlusionMode ); + inst->flags[2] = 0; + inst->flags[3] = 0; +} + +void OverlaySubmit( int width, int height, const Mat4* view, const Mat4* viewInv, const Mat4* proj, const Mat4* projInv, + b3Vec3 cameraPos, float time, + sg_view linearDepthView, sg_sampler linearDepthSampler, sg_pixel_format colorFormat, + sg_pixel_format depthFormat ) +{ + if ( !s_overlay.ready ) + { + return; + } + if ( s_overlay.lineCount == 0 && s_overlay.pointCount == 0 ) + { + return; + } + + sg_pipeline linePipeline = { 0 }; + sg_pipeline pointPipeline = { 0 }; + if ( !EnsurePipelines( colorFormat, depthFormat, &linePipeline, &pointPipeline ) ) + { + return; + } + + // Build the shared ub_frame data. Both shaders' reflected ub_frame + // structs have the same layout (declared identically in both .glsl), + // so one struct populates both via sg_apply_uniforms. + const Mat4 view_proj = MulMM4( *proj, *view ); + // inv(P*V) = inv(V)*inv(P). The camera builds both inverses from the + // same parameters as the forward matrices, so this is a single multiply + // instead of a general 4x4 inversion. + const Mat4 inv_view_proj = MulMM4( *viewInv, *projInv ); + const float w = (float)width; + const float h = (float)height; + overlay_line_ub_frame_t ub = { 0 }; + ub.view = *view; + ub.proj = *proj; + ub.view_proj = view_proj; + ub.inv_view_proj = inv_view_proj; + ub.camera_pos = MakeVec4( cameraPos.x, cameraPos.y, cameraPos.z, time ); + ub.viewport = MakeVec4( w, h, w > 0.0f ? 1.0f / w : 0.0f, h > 0.0f ? 1.0f / h : 0.0f ); + + // Lines + if ( s_overlay.lineCount > 0 ) + { + sg_range r; + r.ptr = s_overlay.lineBase; + r.size = (size_t)s_overlay.lineCount * sizeof( overlay_line_line_instance_t ); + sg_update_buffer( s_overlay.lineInstBuf, &r ); + + sg_apply_pipeline( linePipeline ); + sg_bindings b = { 0 }; + b.views[VIEW_overlay_line_line_instances] = s_overlay.lineInstView; + b.views[VIEW_overlay_line_tex_depth] = linearDepthView; + b.samplers[SMP_overlay_line_smp_depth] = linearDepthSampler; + sg_apply_bindings( &b ); + sg_apply_uniforms( UB_overlay_line_ub_frame, &SG_RANGE( ub ) ); + sg_draw( 0, 6, s_overlay.lineCount ); + } + + // Points + if ( s_overlay.pointCount > 0 ) + { + sg_range r; + r.ptr = s_overlay.pointBase; + r.size = (size_t)s_overlay.pointCount * sizeof( overlay_point_point_instance_t ); + sg_update_buffer( s_overlay.pointInstBuf, &r ); + + // Same ub_frame data. The generated _t names differ but the layout + // matches byte-for-byte (both glsl files declare identical ub_frame). + overlay_point_ub_frame_t pub; + memcpy( &pub, &ub, sizeof( pub ) ); + + sg_apply_pipeline( pointPipeline ); + sg_bindings b = { 0 }; + b.views[VIEW_overlay_point_point_instances] = s_overlay.pointInstView; + b.views[VIEW_overlay_point_tex_depth] = linearDepthView; + b.samplers[SMP_overlay_point_smp_depth] = linearDepthSampler; + sg_apply_bindings( &b ); + sg_apply_uniforms( UB_overlay_point_ub_frame, &SG_RANGE( pub ) ); + sg_draw( 0, 6, s_overlay.pointCount ); + } +} diff --git a/samples/gfx/overlay.h b/samples/gfx/overlay.h new file mode 100644 index 0000000..f46ce30 --- /dev/null +++ b/samples/gfx/overlay.h @@ -0,0 +1,75 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Overlay pipeline, lines and points. +// +// Owns two pipelines (overlay_line, overlay_point), two per-frame instance +// arenas, and the upload-side storage buffers. The renderer wires the +// per-frame reset and the draw call. +// +// Pass placement: the renderer calls OverlaySubmit in the post-tone map +// pass, the same swap chain (or offscreen test) pass that AgX tone map and +// the highlight outline write to, after both and before sg_end_pass. So +// overlay fragments are display-referred: a submitted color reaches the +// screen verbatim, NOT run through exposure + AgX. This keeps debug +// overlays consistent with the ImGui text labels (also post-tone map) and +// makes their colors WYSIWYG. The target is single-sample, the line/point +// shaders carry their own SDF coverage AA, so MSAA isn't needed. +// +// Depth-test = ALWAYS (depth-write off), the fragment shader samples the +// GTAO linear-depth pre-pass for the DIM / DASHED / HIDE occlusion-mode +// branches. Pipelines are created lazily per output format pair (the +// post-tone map target's format isn't known until submit). + +#pragma once + +#include "gfx/draw_overlay.h" +#include "gfx/utility.h" +#include "sokol_gfx.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +void OverlayInit( void ); +void OverlayShutdown( void ); + +// Reset both per-primitive instance arenas. Called from +// ResetFrameArena once per frame before any append. +void OverlayResetFrame( void ); + +// Append an overlay line. Dropped if the arena overflows. +void OverlayAppendLine( b3Vec3 a, b3Vec3 b, Vec4 linearColor, float thickness, OverlayThicknessUnit thicknessUnit, + OverlayOcclusionMode occlusionMode ); + +// Append an overlay point. Dropped if the arena overflows. +void OverlayAppendPoint( b3Vec3 p, Vec4 linearColor, float size, OverlayThicknessUnit sizeUnit, OverlayOcclusionMode occlusionMode ); + +// Encode line + point draws into the currently-open render pass. The +// renderer calls this once per frame in the post-tone map pass, after +// tone map + the highlight outline. No-op if both arenas are empty. +// +// width, height: viewport size in pixels (for ub_frame.viewport). +// view, viewInv, proj, projInv: camera matrices paired with their inverses +// (produced by the camera alongside the forward matrices). The overlay +// shaders read view_proj and inv_view_proj from ub_frame, inv_view_proj is +// built here as viewInv * projInv, no matrix inversion at runtime. +// cameraPos: world-space camera position +// time: seconds since InitRenderer, packed into camera_pos.w. +// linearDepthView: texture view over the R32F linear-depth pre-pass target. +// linearDepthSampler: matching sampler (existing GetAOLinearSampler reused). +// colorFormat: pixel format of the pass's color attachment. +// depthFormat: pixel format of the pass's depth attachment, or +// SG_PIXELFORMAT_NONE for a color-only target. Both select/build the cached pipeline pair. +void OverlaySubmit( int width, int height, const Mat4* view, const Mat4* viewInv, const Mat4* proj, const Mat4* projInv, + b3Vec3 cameraPos, float time, sg_view linearDepthView, sg_sampler linearDepthSampler, sg_pixel_format colorFormat, + sg_pixel_format depthFormat ); + +// Per-frame primitive counts +int OverlayLineCount( void ); +int OverlayPointCount( void ); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/samples/gfx/picking.h b/samples/gfx/picking.h new file mode 100644 index 0000000..ba33a2e --- /dev/null +++ b/samples/gfx/picking.h @@ -0,0 +1,67 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Pick-ray helper. +// +// Build a world-space ray from a screen-pixel coordinate using the latched +// camera state set each frame by RenderFrame / RenderFrameOffscreen. +// Pure-C / header-only so the demo app and the Box3D adapter share one +// implementation without dragging the rest of the renderer in. +// +// Conventions match the rest of the renderer: +// * Column-major matrices, multiplied as M * v +// * Reverse-Z clip space (near maps to clip-Z = +w, far to 0) +// * Mouse (x, y) in framebuffer pixels with origin at the top-left +// (Y grows downward, matches ImGui and sokol_app) +// +// Output matches Box3D's `b3World_CastRayClosest(origin, translation, ...)` +// convention: `*outOrigin` is the world point on the near plane along the +// pick ray, and `*outTranslation` is the unnormalized vector pointing from +// the near to the far plane along that ray. Pass them straight through. +// +// Returns false (and leaves outputs untouched) when the matrices are +// degenerate or the camera state hasn't been initialized (viewportW/H 0). + +#pragma once + +#include "gfx/renderer.h" +#include "gfx/utility.h" + +#include + +static inline bool BuildPickRay( float mouseX, float mouseY, b3Vec3* outOrigin, b3Vec3* outTranslation ) +{ + CameraState s = GetCameraState(); + if ( s.viewportW <= 0 || s.viewportH <= 0 ) + return false; + + // Pixel -> NDC. Origin top-left, Y down. NDC has Y up, X right. + const float ndcX = ( 2.0f * mouseX / (float)s.viewportW ) - 1.0f; + const float ndcY = 1.0f - ( 2.0f * mouseY / (float)s.viewportH ); + + // Reverse-Z: near plane z = 1, far plane z = 0 in NDC. We pick those + // two clip-space points (w = 1) and run them through the inverse VP to + // recover world-space. inv(P*V) = inv(V)*inv(P) = viewInv * projInv, + // both produced by the camera alongside their forward matrices, no + // runtime matrix inversion. + const Mat4 invVP = MulMM4( s.viewInv, s.projInv ); + + const Vec4 clipN = MakeVec4( ndcX, ndcY, 1.0f, 1.0f ); + const Vec4 clipF = MakeVec4( ndcX, ndcY, 0.0f, 1.0f ); + + const Vec4 wN = MulMV4( invVP, clipN ); + const Vec4 wF = MulMV4( invVP, clipF ); + + if ( wN.w == 0.0f || wF.w == 0.0f ) + return false; + + const float invWN = 1.0f / wN.w; + const float invWF = 1.0f / wF.w; + + b3Vec3 nearWorld = { wN.x * invWN, wN.y * invWN, wN.z * invWN }; + b3Vec3 farWorld = { wF.x * invWF, wF.y * invWF, wF.z * invWF }; + + *outOrigin = nearWorld; + *outTranslation = b3Sub( farWorld, nearWorld ); + return true; +} diff --git a/samples/gfx/projection.h b/samples/gfx/projection.h new file mode 100644 index 0000000..87282bc --- /dev/null +++ b/samples/gfx/projection.h @@ -0,0 +1,56 @@ +// World-to-screen projection helper used by the in-world text overlay +// and its unit test. Header-only / pure C so the unit test can pull it in +// without dragging the rest of the renderer along. +// +// Convention matches the renderer: column-major matrices multiplied as +// `M * v`, reverse-Z clip space (near maps to clip-Z = +w, far to 0), Y-up +// view space. Screen pixels follow ImGui's origin convention: (0,0) at the +// top-left of the viewport, Y growing downward. + +#pragma once + +#include "gfx/utility.h" + +#include + +// Project a world-space point through `view`/`proj` for a viewport of size +// `viewportW` x `viewportH` pixels. Writes the screen-pixel position into +// `*outScreenX`/`*outScreenY` and returns true when the point is visible +// (in front of the near plane and inside the X/Y frustum). Returns false +// without writing the outputs when the point is behind the camera (clip.w +// non-positive) or outside the frustum in either axis. +static inline bool ProjectWorldToScreen( Mat4 view, Mat4 proj, int viewportW, int viewportH, b3Vec3 worldPos, float* outScreenX, + float* outScreenY ) +{ + Vec4 world = MakeVec4( worldPos.x, worldPos.y, worldPos.z, 1.0f ); + Vec4 viewP = MulMV4( view, world ); + Vec4 clip = MulMV4( proj, viewP ); + + // Reverse-Z still uses a positive w for "in front of camera", w is the + // view-space depth before the proj divide. Reject behind-camera and + // numerically degenerate cases together. + if ( clip.w <= 1e-6f ) + { + return false; + } + + const float invW = 1.0f / clip.w; + const float ndcX = clip.x * invW; + const float ndcY = clip.y * invW; + + if ( ndcX < -1.0f || ndcX > 1.0f ) + { + return false; + } + + if ( ndcY < -1.0f || ndcY > 1.0f ) + { + return false; + } + + // NDC (-1..1, Y up) -> screen pixels (0..W, 0..H, Y down). + *outScreenX = ( ndcX * 0.5f + 0.5f ) * (float)viewportW; + *outScreenY = ( 1.0f - ( ndcY * 0.5f + 0.5f ) ) * (float)viewportH; + + return true; +} diff --git a/samples/gfx/qsort.h b/samples/gfx/qsort.h new file mode 100644 index 0000000..df75653 --- /dev/null +++ b/samples/gfx/qsort.h @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2013, 2017 Alexey Tourbin + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* + * Vendored from github.com/svpv/qsort (commit 32667a20d3725f62ab2c3def00fcaa96ce2a5508, + * last upstream commit Jan 2019). Header-only inline-sort macro; small enough + * and stable enough that paying for a FetchContent pin no longer earns its keep. + * + * This is a traditional Quicksort implementation which mostly follows + * [Sedgewick 1978]. Sorting is performed entirely on array indices, + * while actual access to the array elements is abstracted out with the + * user-defined `LESS` and `SWAP` primitives. + * + * Synopsis: + * QSORT(N, LESS, SWAP); + * where + * N - the number of elements in A[]; + * LESS(i, j) - compares A[i] to A[j]; + * SWAP(i, j) - exchanges A[i] with A[j]. + */ + +#ifndef QSORT_H +#define QSORT_H + +/* Sort 3 elements. */ +#define Q_SORT3(q_a1, q_a2, q_a3, Q_LESS, Q_SWAP) \ +do { \ + if (Q_LESS(q_a2, q_a1)) { \ + if (Q_LESS(q_a3, q_a2)) \ + Q_SWAP(q_a1, q_a3); \ + else { \ + Q_SWAP(q_a1, q_a2); \ + if (Q_LESS(q_a3, q_a2)) \ + Q_SWAP(q_a2, q_a3); \ + } \ + } \ + else if (Q_LESS(q_a3, q_a2)) { \ + Q_SWAP(q_a2, q_a3); \ + if (Q_LESS(q_a2, q_a1)) \ + Q_SWAP(q_a1, q_a2); \ + } \ +} while (0) + +/* Partition [q_l,q_r] around a pivot. After partitioning, + * [q_l,q_j] are the elements that are less than or equal to the pivot, + * while [q_i,q_r] are the elements greater than or equal to the pivot. */ +#define Q_PARTITION(q_l, q_r, q_i, q_j, Q_UINT, Q_LESS, Q_SWAP) \ +do { \ + /* The middle element, not to be confused with the median. */ \ + Q_UINT q_m = q_l + ((q_r - q_l) >> 1); \ + /* Reorder the second, the middle, and the last items. \ + * As [Edelkamp Weiss 2016] explain, using the second element \ + * instead of the first one helps avoid bad behaviour for \ + * decreasingly sorted arrays. This method is used in recent \ + * versions of gcc's std::sort, see gcc bug 58437#c13, although \ + * the details are somewhat different (cf. #c14). */ \ + Q_SORT3(q_l + 1, q_m, q_r, Q_LESS, Q_SWAP); \ + /* Place the median at the beginning. */ \ + Q_SWAP(q_l, q_m); \ + /* Partition [q_l+2, q_r-1] around the median which is in q_l. \ + * q_i and q_j are initially off by one, they get decremented \ + * in the do-while loops. */ \ + q_i = q_l + 1; q_j = q_r; \ + while (1) { \ + do q_i++; while (Q_LESS(q_i, q_l)); \ + do q_j--; while (Q_LESS(q_l, q_j)); \ + if (q_i >= q_j) break; /* Sedgewick says "until j < i" */ \ + Q_SWAP(q_i, q_j); \ + } \ + /* Compensate for the i==j case. */ \ + q_i = q_j + 1; \ + /* Put the median to its final place. */ \ + Q_SWAP(q_l, q_j); \ + /* The median is not part of the left subfile. */ \ + q_j--; \ +} while (0) + +/* Insertion sort is applied to small subfiles - this is contrary to + * Sedgewick's suggestion to run a separate insertion sort pass after + * the partitioning is done. The reason I don't like a separate pass + * is that it triggers extra comparisons, because it can't see that the + * medians are already in their final positions and need not be rechecked. + * Since I do not assume that comparisons are cheap, I also do not try + * to eliminate the (q_j > q_l) boundary check. */ +#define Q_INSERTION_SORT(q_l, q_r, Q_UINT, Q_LESS, Q_SWAP) \ +do { \ + Q_UINT q_i, q_j; \ + /* For each item starting with the second... */ \ + for (q_i = q_l + 1; q_i <= q_r; q_i++) \ + /* move it down the array so that the first part is sorted. */ \ + for (q_j = q_i; q_j > q_l && (Q_LESS(q_j, q_j - 1)); q_j--) \ + Q_SWAP(q_j, q_j - 1); \ +} while (0) + +/* When the size of [q_l,q_r], i.e. q_r-q_l+1, is greater than or equal to + * Q_THRESH, the algorithm performs recursive partitioning. When the size + * drops below Q_THRESH, the algorithm switches to insertion sort. + * The minimum valid value is probably 5 (with 5 items, the second and + * the middle items, the middle itself being rounded down, are distinct). */ +#define Q_THRESH 16 + +/* The main loop. */ +#define Q_LOOP(Q_UINT, Q_N, Q_LESS, Q_SWAP) \ +do { \ + Q_UINT q_l = 0; \ + Q_UINT q_r = (Q_N) - 1; \ + Q_UINT q_sp = 0; /* the number of frames pushed to the stack */ \ + struct { Q_UINT q_l, q_r; } \ + /* On 32-bit platforms, to sort a "char[3GB+]" array, \ + * it may take full 32 stack frames. On 64-bit CPUs, \ + * though, the address space is limited to 48 bits. \ + * The usage is further reduced if Q_N has a 32-bit type. */ \ + q_st[sizeof(Q_UINT) > 4 && sizeof(Q_N) > 4 ? 48 : 32]; \ + while (1) { \ + if (q_r - q_l + 1 >= Q_THRESH) { \ + Q_UINT q_i, q_j; \ + Q_PARTITION(q_l, q_r, q_i, q_j, Q_UINT, Q_LESS, Q_SWAP); \ + /* Now have two subfiles: [q_l,q_j] and [q_i,q_r]. \ + * Dealing with them depends on which one is bigger. */ \ + if (q_j - q_l >= q_r - q_i) \ + Q_SUBFILES(q_l, q_j, q_i, q_r); \ + else \ + Q_SUBFILES(q_i, q_r, q_l, q_j); \ + } \ + else { \ + Q_INSERTION_SORT(q_l, q_r, Q_UINT, Q_LESS, Q_SWAP); \ + /* Pop subfiles from the stack, until it gets empty. */ \ + if (q_sp == 0) break; \ + q_sp--; \ + q_l = q_st[q_sp].q_l; \ + q_r = q_st[q_sp].q_r; \ + } \ + } \ +} while (0) + +/* The missing part: dealing with subfiles. + * Assumes that the first subfile is not smaller than the second. */ +#define Q_SUBFILES(q_l1, q_r1, q_l2, q_r2) \ +do { \ + /* If the second subfile is only a single element, it needs \ + * no further processing. The first subfile will be processed \ + * on the next iteration (both subfiles cannot be only a single \ + * element, due to Q_THRESH). */ \ + if (q_l2 == q_r2) { \ + q_l = q_l1; \ + q_r = q_r1; \ + } \ + else { \ + /* Otherwise, both subfiles need processing. \ + * Push the larger subfile onto the stack. */ \ + q_st[q_sp].q_l = q_l1; \ + q_st[q_sp].q_r = q_r1; \ + q_sp++; \ + /* Process the smaller subfile on the next iteration. */ \ + q_l = q_l2; \ + q_r = q_r2; \ + } \ +} while (0) + +/* And now, ladies and gentlemen, may I proudly present to you... */ +#define QSORT(Q_N, Q_LESS, Q_SWAP) \ +do { \ + if ((Q_N) > 1) \ + /* We could check sizeof(Q_N) and use "unsigned", but at least \ + * on x86_64, this has the performance penalty of up to 5%. */ \ + Q_LOOP(unsigned long, Q_N, Q_LESS, Q_SWAP); \ +} while (0) + +#endif + +/* ex:set ts=8 sts=4 sw=4 noet: */ diff --git a/samples/gfx/renderer.c b/samples/gfx/renderer.c new file mode 100644 index 0000000..d3a8b86 --- /dev/null +++ b/samples/gfx/renderer.c @@ -0,0 +1,3087 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +#include "gfx/renderer.h" + +#include "capsule.glsl.h" +#include "cube.glsl.h" +#include "depth_only_capsule.glsl.h" +#include "depth_only_cube.glsl.h" +#include "depth_only_geom.glsl.h" +#include "depth_only_sphere.glsl.h" +#include "geom.glsl.h" +#include "gfx/arena.h" +#include "gfx/edges.h" +#include "gfx/geometry_registry.h" +#include "gfx/gtao.h" +#include "gfx/highlight_mask.h" +#include "gfx/highlight_outline.h" +#include "gfx/highlight_target.h" +#include "gfx/ibl.h" +#include "gfx/overlay.h" +#include "gfx/qsort.h" +#include "gfx/scene_target.h" +#include "gfx/shadow.h" +#include "gfx/sky.h" +#include "gfx/text.h" +#include "gfx/tone_map.h" +#include "shadow_caster_capsule.glsl.h" +#include "shadow_caster_cube.glsl.h" +#include "shadow_caster_geom.glsl.h" +#include "shadow_caster_sphere.glsl.h" +#include "sphere.glsl.h" + +#include +#include +#include +#include +#include + +// Shape instance arena sizes +#define SHAPE_CAPACITY 65536 + +// Transparent shape instance arena sizes +#define TRANSPARENT_SHAPE_CAPACITY 1024 + +static struct +{ + // Unit cube shared by cubes, spheres, and capsules + sg_buffer vbuf; // 8 unit-cube positions + sg_buffer ibuf; // 36 indices + + // Cube pipeline + per-instance storage. + sg_buffer cubeInstBuf; + sg_view cubeInstView; + sg_shader cubeShader; + sg_pipeline cubePipeline; + + // Sphere-impostor pipeline + per-instance storage. + sg_buffer sphereInstBuf; + sg_view sphereInstView; + sg_shader sphereShader; + sg_pipeline spherePipeline; + + // Capsule-impostor pipeline + per-instance storage. + sg_buffer capsuleInstBuf; + sg_view capsuleInstView; + sg_shader capsuleShader; + sg_pipeline capsulePipeline; + + // Triangle-geometry pipeline (hulls, meshes, heightfields). Per-instance + // storage and per-geometry vbo/ibo live inside the geometry_registry. + sg_shader geomShader; + sg_pipeline geomPipeline; + // Front-cull sibling for mirror-scaled (negative determinant) instances. + sg_pipeline geomPipelineMirror; + + // Shadow caster pipeline (cube). Reuses cubeInstBuf, caster and lit + // pipelines share the same per-instance data, just sample different + // ub_frame matrices. + sg_shader shadowCubeShader; + sg_pipeline shadowCubePipeline; + + // Shadow caster pipeline (geom). Reuses the geom registry's per-entry + // vbo/ibo + global instance buffer, one draw per entry per cascade, + // mirroring the lit geom path. + sg_shader shadowGeomShader; + sg_pipeline shadowGeomPipeline; + sg_pipeline shadowGeomPipelineMirror; + + // Shadow caster pipeline (sphere). The lit sphere pipeline is an + // analytic impostor, too expensive for the shadow pass, so the + // caster rasterizes a low-poly icosphere proxy generated at InitRenderer. + // The icosphere vbo/ibo live here, the sphere instance buffer is + // shared with the lit pipeline. + sg_buffer icosphereVbuf; + sg_buffer icosphereIbuf; + int icosphereIndexCount; + sg_shader shadowSphereShader; + sg_pipeline shadowSpherePipeline; + + // Shadow caster pipeline (capsule). Cylinder-plus-caps proxy mesh + // built once at InitRenderer, the capsule instance buffer is shared with + // the lit pipeline. Per-vertex format is two vec3s: in_axis (scaled + // by halfLength) + in_radial (scaled by radius). + sg_buffer capsuleProxyVbuf; + sg_buffer capsuleProxyIbuf; + int capsuleProxyIndexCount; + sg_shader shadowCapsuleShader; + sg_pipeline shadowCapsulePipeline; + + // depth-only pre-pass: dedicated shaders that write positive + // linear view-space depth into an R32F color attachment. The + // transient D32F depth attachment is bound alongside for early-Z and + // closest-fragment selection only, it is never sampled. + sg_shader depthOnlyCubeShader; + sg_pipeline depthOnlyCubePipeline; + sg_shader depthOnlySphereShader; + sg_pipeline depthOnlySpherePipeline; + sg_shader depthOnlyCapsuleShader; + sg_pipeline depthOnlyCapsulePipeline; + sg_shader depthOnlyGeomShader; + sg_pipeline depthOnlyGeomPipeline; + sg_pipeline depthOnlyGeomPipelineMirror; + + int errorCount; + + // Per-shape frame arenas. One bump allocator per stream so a stream's + // entries stay contiguous regardless of how callers interleave DrawCube, + // DrawSphere, etc. The GPU upload reads each as a single span. + Arena cubeArena; + cube_instance_t* cubeBase; + size_t cubeCount; + Arena sphereArena; + sphere_instance_t* sphereBase; + size_t sphereCount; + Arena capsuleArena; + capsule_instance_t* capsuleBase; + size_t capsuleCount; + + // transparent arenas. Parallel to the opaque arenas above, a single + // instance never lives in both. Each gets its own GPU buffer + view + + // pipeline so the opaque path stays byte-identical when no transparent + // shapes are submitted (no extra apply_bindings, no extra apply_uniforms). + Arena cubeArenaXp; + cube_instance_t* cubeBaseXp; + size_t cubeCountXp; + Arena sphereArenaXp; + sphere_instance_t* sphereBaseXp; + size_t sphereCountXp; + Arena capsuleArenaXp; + capsule_instance_t* capsuleBaseXp; + size_t capsuleCountXp; + + // transparent pipelines + GPU instance buffers. Same shaders as the + // opaque variants, only blend/depth/sample state differs. + sg_buffer cubeInstBufXp; + sg_view cubeInstViewXp; + sg_pipeline cubePipelineXp; + sg_buffer sphereInstBufXp; + sg_view sphereInstViewXp; + sg_pipeline spherePipelineXp; + sg_buffer capsuleInstBufXp; + sg_view capsuleInstViewXp; + sg_pipeline capsulePipelineXp; + sg_pipeline geomPipelineXp; + + // Directional light. Persists across frames, SetSun replaces it. + // Read by DrawScene to populate the lit shaders' ub_pass blocks. + Sun sun; + + // AgX exposure stop. Applied as pow(2, ev) by the tonemap pass on + // the resolved HDR scene color. Default set in InitRenderer, SetExposure + // overrides. Tests/demos can override per-scene if they want to deviate + // from the spec calibration. + float exposureEv; + + // AgX-look saturation applied by the tonemap pass after the sigmoid. + // 1.0 = identity (stock AgX Standard look). SetToneMapSaturation + // overrides, default set in InitRenderer. + float tonemapSaturation; + + // IBL master switch for the lit shapes' ambient term. true = image- + // based lighting from the sky, false = legacy flat ambient + // (base_color * sun.ambient). Packed into every lit pipeline's + // ub_pass.ibl_params.y each frame. + bool iblEnabled; + + // output color format. Captured at InitRenderer from env.defaults.color_format + // and used as the tonemap pipeline cache key for the swapchain path. + // Offscreen callers pass their own format through RenderFrameOffscreen. + sg_pixel_format swapchainColorFormat; + + // Preetham turbidity. Single source of truth for both the sky pass and + // the IBL cubemap rebuild. Default 2.2 (spec). SetSkyTurbidity marks + // IBL dirty. + float turbidity; + + // edge overlay knobs. Default off (edgesDefaultParams), SetEdgeOverlayParams + // overrides. Consumed by the edge pass each frame. + EdgeOverlayParams edgeOverlay; + + // highlight outline knobs. Defaults from GetDefaultHighlightParams(), + // SetHighlightParams overrides. Consumed by the outline pass each + // frame. The mask pass itself is unconditional, it only runs when the + // adapter submits any hover/select instances. + HighlightParams highlight; + + // stats snapshot from the last completed frame. Populated at the + // end of RenderFrame / RenderFrameOffscreen. + RenderStats stats; + + // last-frame camera state for post-scene consumers (the ImGui text + // overlay in gui.cpp). Latched at the top of each render entry point. + CameraState cameraState; +} s_gfx; + +static void OnSokolLog( const char* tag, uint32_t logLevel, uint32_t logItemId, const char* message, uint32_t lineNr, + const char* filename, void* userData ) +{ + (void)logItemId; + (void)userData; + const char* levelName = ( logLevel == 0 ) ? "panic" : ( logLevel == 1 ) ? "error" : ( logLevel == 2 ) ? "warn" : "info"; + fprintf( stderr, "[%s/%s] %s (%s:%u)\n", tag ? tag : "?", levelName, message ? message : "(no message)", + filename ? filename : "?", (unsigned)lineNr ); + if ( logLevel <= 1 ) + { + s_gfx.errorCount++; + } +} + +// Cube geometry +// 8 corners of a unit cube centered at origin (half-extent 0.5). Per-vertex +// data is just position, flat shading is recovered in the fragment shader +// via dFdx/dFdy of view-space position, so no per-vertex normals are needed. +static const float CUBE_VERTS[8 * 3] = { + -0.5f, -0.5f, -0.5f, // 0: (-,-,-) + 0.5f, -0.5f, -0.5f, // 1: (+,-,-) + -0.5f, 0.5f, -0.5f, // 2: (-,+,-) + 0.5f, 0.5f, -0.5f, // 3: (+,+,-) + -0.5f, -0.5f, 0.5f, // 4: (-,-,+) + 0.5f, -0.5f, 0.5f, // 5: (+,-,+) + -0.5f, 0.5f, 0.5f, // 6: (-,+,+) + 0.5f, 0.5f, 0.5f, // 7: (+,+,+) +}; + +// CCW outward winding, pipeline cull mode = BACK, face_winding = CCW. +static const uint16_t CUBE_INDICES[36] = { + 0, 4, 6, 0, 6, 2, // -X + 1, 3, 7, 1, 7, 5, // +X + 0, 1, 5, 0, 5, 4, // -Y + 2, 6, 7, 2, 7, 3, // +Y + 0, 2, 3, 0, 3, 1, // -Z + 4, 5, 7, 4, 7, 6, // +Z +}; + +// Ico-sphere shadow proxy +// N-level subdivided ico-sphere built from a 12-vert icosahedron: each +// subdivision step splits every face into 4 by inserting edge midpoints, +// then renormalizes every new vertex to the unit sphere. After L levels: +// verts = 10 * 4^L + 2, tris = 20 * 4^L. Built once at InitRenderer and uploaded +// to dedicated vbuf/ibuf for the shadow_caster_sphere pipeline. +// +// We use L=2 (162 verts, 320 tris), subdiv-1 gave visibly polygonal +// shadow silhouettes when the sun grazed a sphere, subdiv-2 reads as +// round at any zoom we're likely to use. Subdiv-3 (1280 tris) is overkill. +// +// The icosahedron's golden-ratio coordinates produce a remarkably even +// vertex distribution, better silhouette quality than a UV sphere +// comparable triangle count. +#define ICO_SPHERE_SUBDIV_LEVEL 2 +#define ICO_SPHERE_VERTICES 162 // 10 * 4^L + 2 for L=2 +#define ICO_SPHERE_INDICES ( 320 * 3 ) // 20 * 4^L for L=2 + +static void BuildIcosphere( float ( *outVerts )[3], uint32_t* outIndices ) +{ + const float phi = ( 1.0f + sqrtf( 5.0f ) ) * 0.5f; + const float invLen = 1.0f / sqrtf( 1.0f + phi * phi ); + + // 12 icosahedron vertices, normalized to the unit sphere. + const float baseVerts[12][3] = { + { -1.0f, phi, 0.0f }, { 1.0f, phi, 0.0f }, { -1.0f, -phi, 0.0f }, { 1.0f, -phi, 0.0f }, + { 0.0f, -1.0f, phi }, { 0.0f, 1.0f, phi }, { 0.0f, -1.0f, -phi }, { 0.0f, 1.0f, -phi }, + { phi, 0.0f, -1.0f }, { phi, 0.0f, 1.0f }, { -phi, 0.0f, -1.0f }, { -phi, 0.0f, 1.0f }, + }; + for ( int i = 0; i < 12; ++i ) + { + outVerts[i][0] = baseVerts[i][0] * invLen; + outVerts[i][1] = baseVerts[i][1] * invLen; + outVerts[i][2] = baseVerts[i][2] * invLen; + } + + // 20 base faces, CCW from outside. + static const uint32_t baseTris[20 * 3] = { + 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11, 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8, + 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9, 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1, + }; + + // Ping-pong tri buffers. Each level reads `cur` and writes `nxt`, then + // swaps. Static so the ~7.5 KB doesn't pressure the call-site stack. + static uint32_t triA[ICO_SPHERE_INDICES]; + static uint32_t triB[ICO_SPHERE_INDICES]; + uint32_t* cur = triA; + uint32_t* nxt = triB; + int triCount = 20; + for ( int i = 0; i < 20 * 3; ++i ) + cur[i] = baseTris[i]; + + int vertCount = 12; + + // Edge midpoint cache, sized for the final vertex count. Each edge + // the *current* tri set pairs exactly two faces, so a midpoint computed + // for one face is reused by exactly one other. Cleared per level so + // midpoint indices from earlier levels don't leak in. ~104 KB static. + static int midCache[ICO_SPHERE_VERTICES][ICO_SPHERE_VERTICES]; + + for ( int L = 0; L < ICO_SPHERE_SUBDIV_LEVEL; ++L ) + { + for ( int i = 0; i < ICO_SPHERE_VERTICES; ++i ) + { + for ( int j = 0; j < ICO_SPHERE_VERTICES; ++j ) + { + midCache[i][j] = -1; + } + } + + int nxtCount = 0; + for ( int t = 0; t < triCount; ++t ) + { + const uint32_t v[3] = { cur[t * 3 + 0], cur[t * 3 + 1], cur[t * 3 + 2] }; + + uint32_t mid[3]; + for ( int e = 0; e < 3; ++e ) + { + uint32_t a = v[e]; + uint32_t b = v[( e + 1 ) % 3]; + if ( a > b ) + { + uint32_t tmp = a; + a = b; + b = tmp; + } + if ( midCache[a][b] < 0 ) + { + const int index = vertCount++; + float mx = 0.5f * ( outVerts[a][0] + outVerts[b][0] ); + float my = 0.5f * ( outVerts[a][1] + outVerts[b][1] ); + float mz = 0.5f * ( outVerts[a][2] + outVerts[b][2] ); + const float len = sqrtf( mx * mx + my * my + mz * mz ); + if ( len > 0.0f ) + { + mx /= len; + my /= len; + mz /= len; + } + outVerts[index][0] = mx; + outVerts[index][1] = my; + outVerts[index][2] = mz; + midCache[a][b] = index; + } + mid[e] = (uint32_t)midCache[a][b]; + } + + // Subdivide one tri (v0,v1,v2) into four: + // (v0, m01, m20), (v1, m12, m01), (v2, m20, m12), (m01, m12, m20). + // mid[0] = m01, mid[1] = m12, mid[2] = m20. + nxt[nxtCount++] = v[0]; + nxt[nxtCount++] = mid[0]; + nxt[nxtCount++] = mid[2]; + nxt[nxtCount++] = v[1]; + nxt[nxtCount++] = mid[1]; + nxt[nxtCount++] = mid[0]; + nxt[nxtCount++] = v[2]; + nxt[nxtCount++] = mid[2]; + nxt[nxtCount++] = mid[1]; + nxt[nxtCount++] = mid[0]; + nxt[nxtCount++] = mid[1]; + nxt[nxtCount++] = mid[2]; + } + triCount = nxtCount / 3; + uint32_t* tmp = cur; + cur = nxt; + nxt = tmp; + } + + for ( int i = 0; i < triCount * 3; ++i ) + outIndices[i] = cur[i]; +} + +// Capsule proxy for shadows +// 12-slice cylinder + two hemispherical caps with 2 latitude rings each +// (alpha at pi/6 and pi/3, plus a single pole). Verts are encoded with two +// vec3s, in_axis (scaled by halfLength) and in_radial (scaled by radius), +// so the same proxy mesh works for any (halfLength, radius) pair. +// +// Layout (74 vertices, 144 tris): +// 0..11 body ring -X in_axis=(-1,0,0), in_radial=(0, cos beta, sin beta) +// 12..23 body ring +X in_axis=(+1,0,0), in_radial=(0, cos beta, sin beta) +// 24..35 +X cap ring alpha=pi/6 in_axis=(+1,0,0), in_radial=(sin alpha, cos alpha cos beta, cos alpha sin beta) +// 36..47 +X cap ring alpha=pi/3 ditto with alpha=pi/3 +// 48 +X pole in_axis=(+1,0,0), in_radial=(1, 0, 0) +// 49..60 -X cap ring alpha=pi/6 in_axis=(-1,0,0), in_radial=(-sin alpha, cos alpha cos beta, cos alpha sin beta) +// 61..72 -X cap ring alpha=pi/3 ditto +// 73 -X pole in_axis=(-1,0,0), in_radial=(-1, 0, 0) +// +// Caps share their equator ring with the body's end ring (the body ring +// at +X is the +X cap's alpha=0 equator, etc.), saves 24 verts and avoids +// any seam in the depth render. +#define CAPSULE_SLICES 12 +#define CAPSULE_VERTICES 74 +#define CAPSULE_INDICES ( 144 * 3 ) + +typedef struct CapsuleVertex +{ + float axis[3]; + float radial[3]; +} CapsuleVertex; + +// Helper macro: emit two triangles for a quad with corners +// bl, br, tr, tl (CCW outside-front). +#define CAPSULE_QUAD( bl, br, tr, tl ) \ + do \ + { \ + outIndices[index++] = (uint32_t)( bl ); \ + outIndices[index++] = (uint32_t)( br ); \ + outIndices[index++] = (uint32_t)( tr ); \ + outIndices[index++] = (uint32_t)( bl ); \ + outIndices[index++] = (uint32_t)( tr ); \ + outIndices[index++] = (uint32_t)( tl ); \ + } \ + while ( 0 ) + +static void BuildCapsuleProxy( CapsuleVertex* outVerts, uint32_t* outIndices ) +{ + const float TWO_PI = 6.28318530717958647692f; + const float ALPHA1 = TWO_PI / 12.0f; // pi/6 + const float ALPHA2 = 2.0f * TWO_PI / 12.0f; // pi/3 + + // Vertices + int v = 0; + // 0..11: body ring -X + for ( int i = 0; i < CAPSULE_SLICES; ++i, ++v ) + { + const float beta = TWO_PI * (float)i / (float)CAPSULE_SLICES; + outVerts[v].axis[0] = -1.0f; + outVerts[v].axis[1] = 0.0f; + outVerts[v].axis[2] = 0.0f; + outVerts[v].radial[0] = 0.0f; + outVerts[v].radial[1] = cosf( beta ); + outVerts[v].radial[2] = sinf( beta ); + } + // 12..23: body ring +X + for ( int i = 0; i < CAPSULE_SLICES; ++i, ++v ) + { + const float beta = TWO_PI * (float)i / (float)CAPSULE_SLICES; + outVerts[v].axis[0] = +1.0f; + outVerts[v].axis[1] = 0.0f; + outVerts[v].axis[2] = 0.0f; + outVerts[v].radial[0] = 0.0f; + outVerts[v].radial[1] = cosf( beta ); + outVerts[v].radial[2] = sinf( beta ); + } + // 24..35: +X cap ring alpha=pi/6 + for ( int i = 0; i < CAPSULE_SLICES; ++i, ++v ) + { + const float beta = TWO_PI * (float)i / (float)CAPSULE_SLICES; + outVerts[v].axis[0] = +1.0f; + outVerts[v].axis[1] = 0.0f; + outVerts[v].axis[2] = 0.0f; + outVerts[v].radial[0] = sinf( ALPHA1 ); + outVerts[v].radial[1] = cosf( ALPHA1 ) * cosf( beta ); + outVerts[v].radial[2] = cosf( ALPHA1 ) * sinf( beta ); + } + // 36..47: +X cap ring alpha=pi/3 + for ( int i = 0; i < CAPSULE_SLICES; ++i, ++v ) + { + const float beta = TWO_PI * (float)i / (float)CAPSULE_SLICES; + outVerts[v].axis[0] = +1.0f; + outVerts[v].axis[1] = 0.0f; + outVerts[v].axis[2] = 0.0f; + outVerts[v].radial[0] = sinf( ALPHA2 ); + outVerts[v].radial[1] = cosf( ALPHA2 ) * cosf( beta ); + outVerts[v].radial[2] = cosf( ALPHA2 ) * sinf( beta ); + } + // 48: +X pole + outVerts[v].axis[0] = +1.0f; + outVerts[v].axis[1] = 0.0f; + outVerts[v].axis[2] = 0.0f; + outVerts[v].radial[0] = +1.0f; + outVerts[v].radial[1] = 0.0f; + outVerts[v].radial[2] = 0.0f; + ++v; + // 49..60: -X cap ring alpha=pi/6 + for ( int i = 0; i < CAPSULE_SLICES; ++i, ++v ) + { + const float beta = TWO_PI * (float)i / (float)CAPSULE_SLICES; + outVerts[v].axis[0] = -1.0f; + outVerts[v].axis[1] = 0.0f; + outVerts[v].axis[2] = 0.0f; + outVerts[v].radial[0] = -sinf( ALPHA1 ); + outVerts[v].radial[1] = cosf( ALPHA1 ) * cosf( beta ); + outVerts[v].radial[2] = cosf( ALPHA1 ) * sinf( beta ); + } + // 61..72: -X cap ring alpha=pi/3 + for ( int i = 0; i < CAPSULE_SLICES; ++i, ++v ) + { + const float beta = TWO_PI * (float)i / (float)CAPSULE_SLICES; + outVerts[v].axis[0] = -1.0f; + outVerts[v].axis[1] = 0.0f; + outVerts[v].axis[2] = 0.0f; + outVerts[v].radial[0] = -sinf( ALPHA2 ); + outVerts[v].radial[1] = cosf( ALPHA2 ) * cosf( beta ); + outVerts[v].radial[2] = cosf( ALPHA2 ) * sinf( beta ); + } + // 73: -X pole + outVerts[v].axis[0] = -1.0f; + outVerts[v].axis[1] = 0.0f; + outVerts[v].axis[2] = 0.0f; + outVerts[v].radial[0] = -1.0f; + outVerts[v].radial[1] = 0.0f; + outVerts[v].radial[2] = 0.0f; + ++v; + + // Indices + int index = 0; + + // Body: ring -X (verts 0..11) to ring +X (verts 12..23). For slice i + // and i+1, the outward face winds from -X[i] up the slice direction + // (beta increasing) to -X[i+1], across to +X[i+1], down to +X[i]. + for ( int i = 0; i < CAPSULE_SLICES; ++i ) + { + const int next = ( i + 1 ) % CAPSULE_SLICES; + const int mxi = i; // ring -X + const int mxn = next; + const int pxi = 12 + i; // ring +X + const int pxn = 12 + next; + CAPSULE_QUAD( mxi, mxn, pxn, pxi ); + } + + // +X cap: equator (ring +X, 12..23) -> alpha=pi/6 ring (24..35) -> alpha=pi/3 (36..47) -> pole (48). + // Going outward, alpha increases. For slice i to i+1, the outward face + // winds equator[i] -> equator[i+1] -> ring1[i+1] -> ring1[i]. + for ( int i = 0; i < CAPSULE_SLICES; ++i ) + { + const int next = ( i + 1 ) % CAPSULE_SLICES; + CAPSULE_QUAD( 12 + i, 12 + next, 24 + next, 24 + i ); + CAPSULE_QUAD( 24 + i, 24 + next, 36 + next, 36 + i ); + // Fan to pole: tri (ring2[i], ring2[i+1], pole). + outIndices[index++] = (uint32_t)( 36 + i ); + outIndices[index++] = (uint32_t)( 36 + next ); + outIndices[index++] = (uint32_t)48; + } + + // -X cap: equator (ring -X, 0..11) -> alpha=pi/6 ring (49..60) -> alpha=pi/3 (61..72) -> pole (73). + // Winding flipped relative to +X cap because the outward normal points + // toward -X, the "outside-front" side of each quad swaps slice order. + for ( int i = 0; i < CAPSULE_SLICES; ++i ) + { + const int next = ( i + 1 ) % CAPSULE_SLICES; + CAPSULE_QUAD( 0 + next, 0 + i, 49 + i, 49 + next ); + CAPSULE_QUAD( 49 + next, 49 + i, 61 + i, 61 + next ); + // Fan to pole: tri (ring2[i+1], ring2[i], pole), opposite winding to +X. + outIndices[index++] = (uint32_t)( 61 + next ); + outIndices[index++] = (uint32_t)( 61 + i ); + outIndices[index++] = (uint32_t)73; + } +} + +#undef CAPSULE_QUAD + +// On the GL backend, set clip-space Z to [0,1] so the rasterizer's +// gl_FragCoord.z matches what the impostor shaders write into gl_FragDepth +// (hit_clip.z / hit_clip.w). Default GL clip space is [-1,1], remapped by +// the rasterizer to [0.5,1] when fed our mat4Perspective projection, +// which leaves cube depths biased above sphere/capsule depths and breaks +// the GREATER reverse-Z compare across rasterized/gl_FragDepth draws. +// glClipControl is GL 4.5 core / ARB_clip_control, both have been +// universally available on Linux drivers for a decade. D3D11 and Metal are +// natively [0,1] in clip space, so this is a no-op there. +#if defined( SOKOL_GLCORE ) +#include + +#ifndef GL_LOWER_LEFT +#define GL_LOWER_LEFT 0x8CA1 +#endif +#ifndef GL_ZERO_TO_ONE +#define GL_ZERO_TO_ONE 0x935F +#endif +#ifndef GL_VENDOR +#define GL_VENDOR 0x1F00 +#endif +#ifndef GL_RENDERER +#define GL_RENDERER 0x1F01 +#endif + +typedef void ( *PFN_glClipControl )( uint32_t origin, uint32_t depth ); +typedef const unsigned char* ( *PFN_glGetString )( uint32_t name ); + +static void ConfigureGLClipControl( void ) +{ + // Hard requirement: without [0,1] clip-space Z, reverse-Z is a no-op + // (GL's default [-1,1] mapping wastes all the float precision in the + // middle of the range) and the GREATER compare between rasterized + // geometry and impostor gl_FragDepth writes is broken. Abort rather + // than render with a silently-wrong depth pipeline. + void* libgl = dlopen( "libGL.so.1", RTLD_LAZY | RTLD_GLOBAL ); + if ( !libgl ) + { + fprintf( stderr, "[gfx/fatal] clip control: dlopen libGL.so.1 failed: %s\n", dlerror() ); + abort(); + } + // POSIX dlsym returns void*, ISO C forbids the direct cast to a function + // pointer. The void**-aliasing dance is the standard workaround. + PFN_glClipControl fn = NULL; + *(void**)( &fn ) = dlsym( libgl, "glClipControl" ); + if ( !fn ) + { + fprintf( stderr, "[gfx/fatal] clip control: glClipControl symbol not found " + "(GL 4.5 / ARB_clip_control required)\n" ); + abort(); + } + fn( GL_LOWER_LEFT, GL_ZERO_TO_ONE ); +} + +static void LogGLDeviceInfo( void ) +{ + void* libgl = dlopen( "libGL.so.1", RTLD_LAZY | RTLD_GLOBAL ); + if ( !libgl ) + { + fprintf( stderr, "[gfx/info] GPU: dlopen libGL.so.1 failed: %s\n", dlerror() ); + return; + } + PFN_glGetString fn = NULL; + *(void**)( &fn ) = dlsym( libgl, "glGetString" ); + if ( !fn ) + { + fprintf( stderr, "[gfx/info] GPU: glGetString symbol not found\n" ); + return; + } + const unsigned char* renderer = fn( GL_RENDERER ); + const unsigned char* vendor = fn( GL_VENDOR ); + fprintf( stderr, "[gfx/info] GPU: %s (%s)\n", renderer ? (const char*)renderer : "unknown", + vendor ? (const char*)vendor : "unknown" ); +} +#endif + +// public API +void InitRenderer( const sg_environment* env ) +{ + sg_desc desc = { 0 }; + desc.environment = *env; + desc.logger.func = OnSokolLog; + // Sokol's default buffer/view pools are 128/256, which is fine for the + // demo scenes but exhausts on Box3D benchmark scenes that register many + // unique hull geometries (the washer benchmark: 40 distinct 8-vertex + // hulls, each consuming 1 vertex + 1 index + 1 edge buffer + 1 edge + // view in the geometry registry). Size up generously, each pool slot + // is a small struct, so 1024 each is < 1 MB of headroom. + desc.buffer_pool_size = 1024; + desc.view_pool_size = 1024; + sg_setup( &desc ); + +#if defined( SOKOL_GLCORE ) + ConfigureGLClipControl(); + LogGLDeviceInfo(); +#endif + + sg_buffer_desc vdesc = { 0 }; + vdesc.usage.vertex_buffer = true; + vdesc.data.ptr = CUBE_VERTS; + vdesc.data.size = sizeof( CUBE_VERTS ); + vdesc.label = "cube_verts"; + s_gfx.vbuf = sg_make_buffer( &vdesc ); + + sg_buffer_desc idesc = { 0 }; + idesc.usage.index_buffer = true; + idesc.data.ptr = CUBE_INDICES; + idesc.data.size = sizeof( CUBE_INDICES ); + idesc.label = "cube_indices"; + s_gfx.ibuf = sg_make_buffer( &idesc ); + + // Cube pipeline + sg_buffer_desc cubeInstDesc = { 0 }; + cubeInstDesc.usage.storage_buffer = true; + cubeInstDesc.usage.stream_update = true; + cubeInstDesc.size = (size_t)SHAPE_CAPACITY * sizeof( cube_instance_t ); + cubeInstDesc.label = "cube_instances"; + s_gfx.cubeInstBuf = sg_make_buffer( &cubeInstDesc ); + + sg_view_desc cubeViewDesc = { 0 }; + cubeViewDesc.storage_buffer.buffer = s_gfx.cubeInstBuf; + cubeViewDesc.label = "cube_instances_view"; + s_gfx.cubeInstView = sg_make_view( &cubeViewDesc ); + + s_gfx.cubeShader = sg_make_shader( cube_shader_desc( sg_query_backend() ) ); + + sg_pipeline_desc cubePdesc = { 0 }; + cubePdesc.shader = s_gfx.cubeShader; + cubePdesc.layout.buffers[0].stride = sizeof( float ) * 3; + cubePdesc.layout.attrs[ATTR_cube_in_pos].format = SG_VERTEXFORMAT_FLOAT3; + cubePdesc.layout.attrs[ATTR_cube_in_pos].buffer_index = 0; + cubePdesc.index_type = SG_INDEXTYPE_UINT16; + // Color attachment is the HDR scene target (RGBA16F MSAA, resolved + // single-sample for the tonemap pass). Depth format mirrors the + // environment's default, sokol_app reports DEPTH_STENCIL on every + // backend, and the scene target's MSAA depth image uses the same. + cubePdesc.colors[0].pixel_format = SG_PIXELFORMAT_RGBA16F; + cubePdesc.color_count = 1; + cubePdesc.depth.pixel_format = env->defaults.depth_format; + cubePdesc.depth.compare = SG_COMPAREFUNC_GREATER; + cubePdesc.depth.write_enabled = true; + cubePdesc.cull_mode = SG_CULLMODE_BACK; + cubePdesc.face_winding = SG_FACEWINDING_CCW; + cubePdesc.sample_count = SCENE_SAMPLE_COUNT; + cubePdesc.label = "cube_pipeline"; + s_gfx.cubePipeline = sg_make_pipeline( &cubePdesc ); + + // Sphere-impostor pipeline + // Reuses cube vbuf/ibuf for the bounding-cube proxy. Cull mode FRONT, + // the sphere lives entirely inside the proxy, so the back faces are + // strictly closer to the camera than the front ones, raster the back + // faces and the impostor still draws the same image while staying + // visible when the camera is inside the proxy AABB but outside the + // sphere itself. (Front-face cull is the standard impostor trick). + sg_buffer_desc sphereInstDesc = { 0 }; + sphereInstDesc.usage.storage_buffer = true; + sphereInstDesc.usage.stream_update = true; + sphereInstDesc.size = (size_t)SHAPE_CAPACITY * sizeof( sphere_instance_t ); + sphereInstDesc.label = "sphere_instances"; + s_gfx.sphereInstBuf = sg_make_buffer( &sphereInstDesc ); + + sg_view_desc sphereViewDesc = { 0 }; + sphereViewDesc.storage_buffer.buffer = s_gfx.sphereInstBuf; + sphereViewDesc.label = "sphere_instances_view"; + s_gfx.sphereInstView = sg_make_view( &sphereViewDesc ); + + s_gfx.sphereShader = sg_make_shader( sphere_impostor_shader_desc( sg_query_backend() ) ); + + sg_pipeline_desc spherePdesc = { 0 }; + spherePdesc.shader = s_gfx.sphereShader; + spherePdesc.layout.buffers[0].stride = sizeof( float ) * 3; + spherePdesc.layout.attrs[ATTR_sphere_impostor_in_pos].format = SG_VERTEXFORMAT_FLOAT3; + spherePdesc.layout.attrs[ATTR_sphere_impostor_in_pos].buffer_index = 0; + spherePdesc.index_type = SG_INDEXTYPE_UINT16; + spherePdesc.colors[0].pixel_format = SG_PIXELFORMAT_RGBA16F; + spherePdesc.color_count = 1; + spherePdesc.depth.pixel_format = env->defaults.depth_format; + spherePdesc.depth.compare = SG_COMPAREFUNC_GREATER; + spherePdesc.depth.write_enabled = true; + spherePdesc.cull_mode = SG_CULLMODE_FRONT; + spherePdesc.face_winding = SG_FACEWINDING_CCW; + spherePdesc.sample_count = SCENE_SAMPLE_COUNT; + // Analytical silhouette AA: the FS writes a sub-pixel coverage value into + // alpha (see shaders/shapes/sphere.glsl). At MSAA this maps it to the + // sample mask. At sample_count=1 alpha-to-coverage would degenerate to an + // alpha test, which is why the transparent variant turns this back off + // and relies on the premultiplied alpha blend instead. + spherePdesc.alpha_to_coverage_enabled = true; + spherePdesc.label = "sphere_pipeline"; + s_gfx.spherePipeline = sg_make_pipeline( &spherePdesc ); + + // Capsule-impostor pipeline + // Reuses cube vbuf/ibuf for the OBB proxy (the VS scales the unit cube + // non-uniformly per instance to match each capsule's bounds). Cull mode + // FRONT, same impostor trick as the sphere pipeline. + sg_buffer_desc capsuleInstDesc = { 0 }; + capsuleInstDesc.usage.storage_buffer = true; + capsuleInstDesc.usage.stream_update = true; + capsuleInstDesc.size = (size_t)SHAPE_CAPACITY * sizeof( capsule_instance_t ); + capsuleInstDesc.label = "capsule_instances"; + s_gfx.capsuleInstBuf = sg_make_buffer( &capsuleInstDesc ); + + sg_view_desc capsuleViewDesc = { 0 }; + capsuleViewDesc.storage_buffer.buffer = s_gfx.capsuleInstBuf; + capsuleViewDesc.label = "capsule_instances_view"; + s_gfx.capsuleInstView = sg_make_view( &capsuleViewDesc ); + + s_gfx.capsuleShader = sg_make_shader( capsule_impostor_shader_desc( sg_query_backend() ) ); + + sg_pipeline_desc capsulePdesc = { 0 }; + capsulePdesc.shader = s_gfx.capsuleShader; + capsulePdesc.layout.buffers[0].stride = sizeof( float ) * 3; + capsulePdesc.layout.attrs[ATTR_capsule_impostor_in_pos].format = SG_VERTEXFORMAT_FLOAT3; + capsulePdesc.layout.attrs[ATTR_capsule_impostor_in_pos].buffer_index = 0; + capsulePdesc.index_type = SG_INDEXTYPE_UINT16; + capsulePdesc.colors[0].pixel_format = SG_PIXELFORMAT_RGBA16F; + capsulePdesc.color_count = 1; + capsulePdesc.depth.pixel_format = env->defaults.depth_format; + capsulePdesc.depth.compare = SG_COMPAREFUNC_GREATER; + capsulePdesc.depth.write_enabled = true; + capsulePdesc.cull_mode = SG_CULLMODE_FRONT; + capsulePdesc.face_winding = SG_FACEWINDING_CCW; + capsulePdesc.sample_count = SCENE_SAMPLE_COUNT; + // Analytical silhouette AA. See spherePdesc above for the rationale. + capsulePdesc.alpha_to_coverage_enabled = true; + capsulePdesc.label = "capsule_pipeline"; + s_gfx.capsulePipeline = sg_make_pipeline( &capsulePdesc ); + + // Triangle mesh pipeline + // Real geometry uploaded per-registry-entry, no proxy. Each draw rebinds + // the entry's vbo/ibo and sets `inst_base` (ub_draw) so the shader can + // index the global instance buffer. Cull mode BACK, CCW winding, the + // builders emit CCW outward triangles for hulls and CCW upward for + // heightfields, mesh winding follows whatever the source data carries. + CreateMeshRegistry(); + + s_gfx.geomShader = sg_make_shader( geom_triangle_shader_desc( sg_query_backend() ) ); + + sg_pipeline_desc geomPdesc = { 0 }; + geomPdesc.shader = s_gfx.geomShader; + geomPdesc.layout.buffers[0].stride = sizeof( float ) * 6; + geomPdesc.layout.attrs[ATTR_geom_triangle_in_pos].format = SG_VERTEXFORMAT_FLOAT3; + geomPdesc.layout.attrs[ATTR_geom_triangle_in_pos].buffer_index = 0; + geomPdesc.layout.attrs[ATTR_geom_triangle_in_pos].offset = 0; + geomPdesc.layout.attrs[ATTR_geom_triangle_in_normal].format = SG_VERTEXFORMAT_FLOAT3; + geomPdesc.layout.attrs[ATTR_geom_triangle_in_normal].buffer_index = 0; + geomPdesc.layout.attrs[ATTR_geom_triangle_in_normal].offset = sizeof( float ) * 3; + geomPdesc.index_type = SG_INDEXTYPE_UINT32; + geomPdesc.colors[0].pixel_format = SG_PIXELFORMAT_RGBA16F; + geomPdesc.color_count = 1; + geomPdesc.depth.pixel_format = env->defaults.depth_format; + geomPdesc.depth.compare = SG_COMPAREFUNC_GREATER; + geomPdesc.depth.write_enabled = true; + // Back-cull the common case. A mesh instance may carry a negative + // determinant scale that flips winding, those are partitioned out by the + // registry and drawn with the front-cull sibling below. The FS faces the + // shading normal toward the camera, so both pipelines shade correctly. + geomPdesc.cull_mode = SG_CULLMODE_BACK; + geomPdesc.face_winding = SG_FACEWINDING_CCW; + geomPdesc.sample_count = SCENE_SAMPLE_COUNT; + geomPdesc.label = "geom_pipeline"; + s_gfx.geomPipeline = sg_make_pipeline( &geomPdesc ); + + sg_pipeline_desc geomMirrorPdesc = geomPdesc; + geomMirrorPdesc.cull_mode = SG_CULLMODE_FRONT; + geomMirrorPdesc.label = "geom_pipeline_mirror"; + s_gfx.geomPipelineMirror = sg_make_pipeline( &geomMirrorPdesc ); + + InitShadows(); + + // Shadow caster pipeline: cubes + // Depth-only, color_count=0 means the FS's empty main doesn't need + // any color attachment. Pixel format must match the shadow depth + // texture's D32F (SG_PIXELFORMAT_DEPTH). Compare LESS (standard Z, not + // reverse-Z) and write enabled. + s_gfx.shadowCubeShader = sg_make_shader( shadow_cube_caster_shader_desc( sg_query_backend() ) ); + + sg_pipeline_desc shadowCubePdesc = { 0 }; + shadowCubePdesc.shader = s_gfx.shadowCubeShader; + shadowCubePdesc.layout.buffers[0].stride = sizeof( float ) * 3; + shadowCubePdesc.layout.attrs[ATTR_shadow_cube_caster_in_pos].format = SG_VERTEXFORMAT_FLOAT3; + shadowCubePdesc.layout.attrs[ATTR_shadow_cube_caster_in_pos].buffer_index = 0; + shadowCubePdesc.index_type = SG_INDEXTYPE_UINT16; + + // Depth-only: setting colors[0].pixel_format to NONE is the documented + // way to force color_count to 0 (sokol treats color_count=0 from the + // caller as "default to 1"). + shadowCubePdesc.colors[0].pixel_format = SG_PIXELFORMAT_NONE; + shadowCubePdesc.depth.pixel_format = SG_PIXELFORMAT_DEPTH; + shadowCubePdesc.depth.compare = SG_COMPAREFUNC_LESS; + shadowCubePdesc.depth.write_enabled = true; + shadowCubePdesc.cull_mode = SG_CULLMODE_BACK; + shadowCubePdesc.face_winding = SG_FACEWINDING_CCW; + + // Shadow attachments are single-sample. The env default sample_count is + // now 4 (lit-path MSAA), so we must override here. Otherwise pipelines + // pick up the env default and fail validation against shadow passes. + shadowCubePdesc.sample_count = 1; + shadowCubePdesc.label = "shadow_cube_pipeline"; + s_gfx.shadowCubePipeline = sg_make_pipeline( &shadowCubePdesc ); + + // Shadow caster pipeline: mesh + // Same depth-only setup as the cube caster. The per-entry vbo/ibo and + // per-draw inst_base offset come from the geometry_registry, identical + // to the lit geom pipeline. + s_gfx.shadowGeomShader = sg_make_shader( shadow_geom_caster_shader_desc( sg_query_backend() ) ); + + sg_pipeline_desc shadowGeomPdesc = { 0 }; + shadowGeomPdesc.shader = s_gfx.shadowGeomShader; + + // Stride matches the lit geom pipeline (position+normal interleaved), + // but the caster shader only declares in_pos, the normal slot in + // each vertex is skipped, which is fine. + shadowGeomPdesc.layout.buffers[0].stride = sizeof( float ) * 6; + shadowGeomPdesc.layout.attrs[ATTR_shadow_geom_caster_in_pos].format = SG_VERTEXFORMAT_FLOAT3; + shadowGeomPdesc.layout.attrs[ATTR_shadow_geom_caster_in_pos].buffer_index = 0; + shadowGeomPdesc.layout.attrs[ATTR_shadow_geom_caster_in_pos].offset = 0; + shadowGeomPdesc.index_type = SG_INDEXTYPE_UINT32; + shadowGeomPdesc.colors[0].pixel_format = SG_PIXELFORMAT_NONE; + shadowGeomPdesc.depth.pixel_format = SG_PIXELFORMAT_DEPTH; + shadowGeomPdesc.depth.compare = SG_COMPAREFUNC_LESS; + shadowGeomPdesc.depth.write_enabled = true; + shadowGeomPdesc.cull_mode = SG_CULLMODE_BACK; // match geom pipeline, mirror runs use the front-cull sibling + shadowGeomPdesc.face_winding = SG_FACEWINDING_CCW; + shadowGeomPdesc.sample_count = 1; + shadowGeomPdesc.label = "shadow_geom_pipeline"; + s_gfx.shadowGeomPipeline = sg_make_pipeline( &shadowGeomPdesc ); + + sg_pipeline_desc shadowGeomMirrorPdesc = shadowGeomPdesc; + shadowGeomMirrorPdesc.cull_mode = SG_CULLMODE_FRONT; + shadowGeomMirrorPdesc.label = "shadow_geom_pipeline_mirror"; + s_gfx.shadowGeomPipelineMirror = sg_make_pipeline( &shadowGeomMirrorPdesc ); + + // Shadow caster pipeline: spheres + // Build the ico-sphere proxy once and upload to a + // dedicated vbo/ibo. Position-only vertex layout (no normals, the + // caster shader never reads them). + { + float icoVerts[ICO_SPHERE_VERTICES][3]; + uint32_t icoIndices[ICO_SPHERE_INDICES]; + BuildIcosphere( icoVerts, icoIndices ); + s_gfx.icosphereIndexCount = ICO_SPHERE_INDICES; + + sg_buffer_desc ivdesc = { 0 }; + ivdesc.usage.vertex_buffer = true; + ivdesc.data.ptr = icoVerts; + ivdesc.data.size = sizeof( icoVerts ); + ivdesc.label = "icosphere_verts"; + s_gfx.icosphereVbuf = sg_make_buffer( &ivdesc ); + + sg_buffer_desc iidesc = { 0 }; + iidesc.usage.index_buffer = true; + iidesc.data.ptr = icoIndices; + iidesc.data.size = sizeof( icoIndices ); + iidesc.label = "icosphere_indices"; + s_gfx.icosphereIbuf = sg_make_buffer( &iidesc ); + } + + s_gfx.shadowSphereShader = sg_make_shader( shadow_sphere_caster_shader_desc( sg_query_backend() ) ); + + sg_pipeline_desc shadowSpherePdesc = { 0 }; + shadowSpherePdesc.shader = s_gfx.shadowSphereShader; + shadowSpherePdesc.layout.buffers[0].stride = sizeof( float ) * 3; + shadowSpherePdesc.layout.attrs[ATTR_shadow_sphere_caster_in_pos].format = SG_VERTEXFORMAT_FLOAT3; + shadowSpherePdesc.layout.attrs[ATTR_shadow_sphere_caster_in_pos].buffer_index = 0; + shadowSpherePdesc.index_type = SG_INDEXTYPE_UINT32; + shadowSpherePdesc.colors[0].pixel_format = SG_PIXELFORMAT_NONE; + shadowSpherePdesc.depth.pixel_format = SG_PIXELFORMAT_DEPTH; + shadowSpherePdesc.depth.compare = SG_COMPAREFUNC_LESS; + shadowSpherePdesc.depth.write_enabled = true; + shadowSpherePdesc.cull_mode = SG_CULLMODE_BACK; + shadowSpherePdesc.face_winding = SG_FACEWINDING_CCW; + shadowSpherePdesc.sample_count = 1; + shadowSpherePdesc.label = "shadow_sphere_pipeline"; + s_gfx.shadowSpherePipeline = sg_make_pipeline( &shadowSpherePdesc ); + + // Shadow caster pipeline: capsules + { + CapsuleVertex capsVerts[CAPSULE_VERTICES]; + uint32_t capsIndices[CAPSULE_INDICES]; + BuildCapsuleProxy( capsVerts, capsIndices ); + s_gfx.capsuleProxyIndexCount = CAPSULE_INDICES; + + sg_buffer_desc cvdesc = { 0 }; + cvdesc.usage.vertex_buffer = true; + cvdesc.data.ptr = capsVerts; + cvdesc.data.size = sizeof( capsVerts ); + cvdesc.label = "capsule_proxy_verts"; + s_gfx.capsuleProxyVbuf = sg_make_buffer( &cvdesc ); + + sg_buffer_desc cidesc = { 0 }; + cidesc.usage.index_buffer = true; + cidesc.data.ptr = capsIndices; + cidesc.data.size = sizeof( capsIndices ); + cidesc.label = "capsule_proxy_indices"; + s_gfx.capsuleProxyIbuf = sg_make_buffer( &cidesc ); + } + + s_gfx.shadowCapsuleShader = sg_make_shader( shadow_capsule_caster_shader_desc( sg_query_backend() ) ); + + sg_pipeline_desc shadowCapsulePdesc = { 0 }; + shadowCapsulePdesc.shader = s_gfx.shadowCapsuleShader; + shadowCapsulePdesc.layout.buffers[0].stride = sizeof( float ) * 6; + shadowCapsulePdesc.layout.attrs[ATTR_shadow_capsule_caster_in_axis].format = SG_VERTEXFORMAT_FLOAT3; + shadowCapsulePdesc.layout.attrs[ATTR_shadow_capsule_caster_in_axis].buffer_index = 0; + shadowCapsulePdesc.layout.attrs[ATTR_shadow_capsule_caster_in_axis].offset = 0; + shadowCapsulePdesc.layout.attrs[ATTR_shadow_capsule_caster_in_radial].format = SG_VERTEXFORMAT_FLOAT3; + shadowCapsulePdesc.layout.attrs[ATTR_shadow_capsule_caster_in_radial].buffer_index = 0; + shadowCapsulePdesc.layout.attrs[ATTR_shadow_capsule_caster_in_radial].offset = sizeof( float ) * 3; + shadowCapsulePdesc.index_type = SG_INDEXTYPE_UINT32; + shadowCapsulePdesc.colors[0].pixel_format = SG_PIXELFORMAT_NONE; + shadowCapsulePdesc.depth.pixel_format = SG_PIXELFORMAT_DEPTH; + shadowCapsulePdesc.depth.compare = SG_COMPAREFUNC_LESS; + shadowCapsulePdesc.depth.write_enabled = true; + shadowCapsulePdesc.cull_mode = SG_CULLMODE_BACK; + shadowCapsulePdesc.face_winding = SG_FACEWINDING_CCW; + shadowCapsulePdesc.sample_count = 1; + shadowCapsulePdesc.label = "shadow_capsule_pipeline"; + s_gfx.shadowCapsulePipeline = sg_make_pipeline( &shadowCapsulePdesc ); + + // Depth-only pre-pass pipelines + // Renders all opaque shapes from the main camera into a depth target + // (rasterizer / early-Z) and an R32F color target carrying positive + // linear view-space depth. The GTAO compute pipeline (lands in step + // 3 of the rework) reconstructs normals from depth derivatives, so + // no normal channel is produced here. Sphere/capsule pipelines reuse + // the lit impostor pattern. Cubes and mesh use the standard raster path. + + s_gfx.depthOnlyCubeShader = sg_make_shader( depth_only_cube_prog_shader_desc( sg_query_backend() ) ); + + sg_pipeline_desc dnCubePdesc = { 0 }; + dnCubePdesc.shader = s_gfx.depthOnlyCubeShader; + dnCubePdesc.layout.buffers[0].stride = sizeof( float ) * 3; + dnCubePdesc.layout.attrs[ATTR_depth_only_cube_prog_in_pos].format = SG_VERTEXFORMAT_FLOAT3; + dnCubePdesc.layout.attrs[ATTR_depth_only_cube_prog_in_pos].buffer_index = 0; + dnCubePdesc.index_type = SG_INDEXTYPE_UINT16; + dnCubePdesc.colors[0].pixel_format = SG_PIXELFORMAT_R32F; + dnCubePdesc.depth.pixel_format = SG_PIXELFORMAT_DEPTH; + dnCubePdesc.depth.compare = SG_COMPAREFUNC_GREATER; + dnCubePdesc.depth.write_enabled = true; + dnCubePdesc.cull_mode = SG_CULLMODE_BACK; + dnCubePdesc.face_winding = SG_FACEWINDING_CCW; + dnCubePdesc.sample_count = 1; + dnCubePdesc.label = "depth_only_cube_pipeline"; + s_gfx.depthOnlyCubePipeline = sg_make_pipeline( &dnCubePdesc ); + + s_gfx.depthOnlySphereShader = sg_make_shader( depth_only_sphere_prog_shader_desc( sg_query_backend() ) ); + + sg_pipeline_desc dnSpherePdesc = { 0 }; + dnSpherePdesc.shader = s_gfx.depthOnlySphereShader; + dnSpherePdesc.layout.buffers[0].stride = sizeof( float ) * 3; + dnSpherePdesc.layout.attrs[ATTR_depth_only_sphere_prog_in_pos].format = SG_VERTEXFORMAT_FLOAT3; + dnSpherePdesc.layout.attrs[ATTR_depth_only_sphere_prog_in_pos].buffer_index = 0; + dnSpherePdesc.index_type = SG_INDEXTYPE_UINT16; + dnSpherePdesc.colors[0].pixel_format = SG_PIXELFORMAT_R32F; + dnSpherePdesc.depth.pixel_format = SG_PIXELFORMAT_DEPTH; + dnSpherePdesc.depth.compare = SG_COMPAREFUNC_GREATER; + dnSpherePdesc.depth.write_enabled = true; + + // Impostor: bounding-cube proxy with front-face cull (same as lit + // sphere). Ensures the impostor draws even when the camera is inside + // the proxy AABB but outside the analytic sphere. + dnSpherePdesc.cull_mode = SG_CULLMODE_FRONT; + dnSpherePdesc.face_winding = SG_FACEWINDING_CCW; + dnSpherePdesc.sample_count = 1; + dnSpherePdesc.label = "depth_only_sphere_pipeline"; + s_gfx.depthOnlySpherePipeline = sg_make_pipeline( &dnSpherePdesc ); + + s_gfx.depthOnlyCapsuleShader = sg_make_shader( depth_only_capsule_prog_shader_desc( sg_query_backend() ) ); + + sg_pipeline_desc dnCapsulePdesc = { 0 }; + dnCapsulePdesc.shader = s_gfx.depthOnlyCapsuleShader; + dnCapsulePdesc.layout.buffers[0].stride = sizeof( float ) * 3; + dnCapsulePdesc.layout.attrs[ATTR_depth_only_capsule_prog_in_pos].format = SG_VERTEXFORMAT_FLOAT3; + dnCapsulePdesc.layout.attrs[ATTR_depth_only_capsule_prog_in_pos].buffer_index = 0; + dnCapsulePdesc.index_type = SG_INDEXTYPE_UINT16; + dnCapsulePdesc.colors[0].pixel_format = SG_PIXELFORMAT_R32F; + dnCapsulePdesc.depth.pixel_format = SG_PIXELFORMAT_DEPTH; + dnCapsulePdesc.depth.compare = SG_COMPAREFUNC_GREATER; + dnCapsulePdesc.depth.write_enabled = true; + dnCapsulePdesc.cull_mode = SG_CULLMODE_FRONT; + dnCapsulePdesc.face_winding = SG_FACEWINDING_CCW; + dnCapsulePdesc.sample_count = 1; + dnCapsulePdesc.label = "depth_only_capsule_pipeline"; + s_gfx.depthOnlyCapsulePipeline = sg_make_pipeline( &dnCapsulePdesc ); + + s_gfx.depthOnlyGeomShader = sg_make_shader( depth_only_geom_prog_shader_desc( sg_query_backend() ) ); + + sg_pipeline_desc dnGeomPdesc = { 0 }; + dnGeomPdesc.shader = s_gfx.depthOnlyGeomShader; + dnGeomPdesc.layout.buffers[0].stride = sizeof( float ) * 6; + dnGeomPdesc.layout.attrs[ATTR_depth_only_geom_prog_in_pos].format = SG_VERTEXFORMAT_FLOAT3; + dnGeomPdesc.layout.attrs[ATTR_depth_only_geom_prog_in_pos].buffer_index = 0; + dnGeomPdesc.layout.attrs[ATTR_depth_only_geom_prog_in_pos].offset = 0; + // in_normal is declared by the lit geom vbo at offset 12 but unused here, + // the shader doesn't declare it so the binding is skipped to match. + dnGeomPdesc.index_type = SG_INDEXTYPE_UINT32; + dnGeomPdesc.colors[0].pixel_format = SG_PIXELFORMAT_R32F; + dnGeomPdesc.depth.pixel_format = SG_PIXELFORMAT_DEPTH; + dnGeomPdesc.depth.compare = SG_COMPAREFUNC_GREATER; + dnGeomPdesc.depth.write_enabled = true; + dnGeomPdesc.cull_mode = SG_CULLMODE_BACK; // match geom pipeline, mirror runs use the front-cull sibling + dnGeomPdesc.face_winding = SG_FACEWINDING_CCW; + dnGeomPdesc.sample_count = 1; + dnGeomPdesc.label = "depth_only_geom_pipeline"; + s_gfx.depthOnlyGeomPipeline = sg_make_pipeline( &dnGeomPdesc ); + + sg_pipeline_desc dnGeomMirrorPdesc = dnGeomPdesc; + dnGeomMirrorPdesc.cull_mode = SG_CULLMODE_FRONT; + dnGeomMirrorPdesc.label = "depth_only_geom_pipeline_mirror"; + s_gfx.depthOnlyGeomPipelineMirror = sg_make_pipeline( &dnGeomMirrorPdesc ); + + // transparent pipelines + per-shape transparent buffers + // Same shaders as the opaque variants (cubeShader, sphereShader, + // capsuleShader, geomShader), only the pipeline state differs: + // * sample_count = 1 (single-sample resolved scene target) + // * depth.compare = GREATER, depth.write_enabled = false + // * depth.pixel_format = SG_PIXELFORMAT_DEPTH to match the GTAO + // prepass attachment (not env->defaults.depth_format, the + // transparent pass re-attaches the prepass depth, not the MSAA + // scene depth, so the format must match the prepass image). + // * premultiplied-alpha blend (ONE / ONE_MINUS_SRC_ALPHA, ADD, RGB+A) + // matching's overlay convention. + { + sg_buffer_desc cb = { 0 }; + cb.usage.storage_buffer = true; + cb.usage.stream_update = true; + cb.size = (size_t)TRANSPARENT_SHAPE_CAPACITY * sizeof( cube_instance_t ); + cb.label = "cube_instances_xp"; + s_gfx.cubeInstBufXp = sg_make_buffer( &cb ); + sg_view_desc cv = { 0 }; + cv.storage_buffer.buffer = s_gfx.cubeInstBufXp; + cv.label = "cube_instances_xp_view"; + s_gfx.cubeInstViewXp = sg_make_view( &cv ); + + sg_buffer_desc sb = { 0 }; + sb.usage.storage_buffer = true; + sb.usage.stream_update = true; + sb.size = (size_t)TRANSPARENT_SHAPE_CAPACITY * sizeof( sphere_instance_t ); + sb.label = "sphere_instances_xp"; + s_gfx.sphereInstBufXp = sg_make_buffer( &sb ); + sg_view_desc sv = { 0 }; + sv.storage_buffer.buffer = s_gfx.sphereInstBufXp; + sv.label = "sphere_instances_xp_view"; + s_gfx.sphereInstViewXp = sg_make_view( &sv ); + + sg_buffer_desc kb = { 0 }; + kb.usage.storage_buffer = true; + kb.usage.stream_update = true; + kb.size = (size_t)TRANSPARENT_SHAPE_CAPACITY * sizeof( capsule_instance_t ); + kb.label = "capsule_instances_xp"; + s_gfx.capsuleInstBufXp = sg_make_buffer( &kb ); + sg_view_desc kv = { 0 }; + kv.storage_buffer.buffer = s_gfx.capsuleInstBufXp; + kv.label = "capsule_instances_xp_view"; + s_gfx.capsuleInstViewXp = sg_make_view( &kv ); + } + + // The transparent pipelines share their shader with the opaque sibling + // and differ only in blend/depth/sample/depth-format. Build a desc by + // copying the opaque one and patching the differing fields. + sg_pipeline_desc cubeXpDesc = cubePdesc; + cubeXpDesc.depth.pixel_format = SG_PIXELFORMAT_DEPTH; + cubeXpDesc.depth.compare = SG_COMPAREFUNC_GREATER; + cubeXpDesc.depth.write_enabled = false; + cubeXpDesc.sample_count = 1; + cubeXpDesc.colors[0].blend.enabled = true; + cubeXpDesc.colors[0].blend.src_factor_rgb = SG_BLENDFACTOR_ONE; + cubeXpDesc.colors[0].blend.dst_factor_rgb = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA; + cubeXpDesc.colors[0].blend.op_rgb = SG_BLENDOP_ADD; + cubeXpDesc.colors[0].blend.src_factor_alpha = SG_BLENDFACTOR_ONE; + cubeXpDesc.colors[0].blend.dst_factor_alpha = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA; + cubeXpDesc.colors[0].blend.op_alpha = SG_BLENDOP_ADD; + cubeXpDesc.label = "cube_pipeline_xp"; + s_gfx.cubePipelineXp = sg_make_pipeline( &cubeXpDesc ); + + sg_pipeline_desc sphereXpDesc = spherePdesc; + sphereXpDesc.depth.pixel_format = SG_PIXELFORMAT_DEPTH; + sphereXpDesc.depth.compare = SG_COMPAREFUNC_GREATER; + sphereXpDesc.depth.write_enabled = false; + sphereXpDesc.sample_count = 1; + sphereXpDesc.alpha_to_coverage_enabled = false; + sphereXpDesc.colors[0].blend = cubeXpDesc.colors[0].blend; + sphereXpDesc.label = "sphere_pipeline_xp"; + s_gfx.spherePipelineXp = sg_make_pipeline( &sphereXpDesc ); + + sg_pipeline_desc capsuleXpDesc = capsulePdesc; + capsuleXpDesc.depth.pixel_format = SG_PIXELFORMAT_DEPTH; + capsuleXpDesc.depth.compare = SG_COMPAREFUNC_GREATER; + capsuleXpDesc.depth.write_enabled = false; + capsuleXpDesc.sample_count = 1; + capsuleXpDesc.alpha_to_coverage_enabled = false; + capsuleXpDesc.colors[0].blend = cubeXpDesc.colors[0].blend; + capsuleXpDesc.label = "capsule_pipeline_xp"; + s_gfx.capsulePipelineXp = sg_make_pipeline( &capsuleXpDesc ); + + sg_pipeline_desc geomXpDesc = geomPdesc; + geomXpDesc.depth.pixel_format = SG_PIXELFORMAT_DEPTH; + geomXpDesc.depth.compare = SG_COMPAREFUNC_GREATER; + geomXpDesc.depth.write_enabled = false; + // Only hulls are drawn transparent and they never have negative scale + geomXpDesc.cull_mode = SG_CULLMODE_BACK; + geomXpDesc.sample_count = 1; + geomXpDesc.colors[0].blend = cubeXpDesc.colors[0].blend; + geomXpDesc.label = "geom_pipeline_xp"; + s_gfx.geomPipelineXp = sg_make_pipeline( &geomXpDesc ); + + if ( ArenaInit( &s_gfx.cubeArena, (size_t)SHAPE_CAPACITY * sizeof( cube_instance_t ) ) != 0 ) + { + fprintf( stderr, "[gfx/error] cube arena alloc failed\n" ); + s_gfx.errorCount++; + } + if ( ArenaInit( &s_gfx.sphereArena, (size_t)SHAPE_CAPACITY * sizeof( sphere_instance_t ) ) != 0 ) + { + fprintf( stderr, "[gfx/error] sphere arena alloc failed\n" ); + s_gfx.errorCount++; + } + if ( ArenaInit( &s_gfx.capsuleArena, (size_t)SHAPE_CAPACITY * sizeof( capsule_instance_t ) ) != 0 ) + { + fprintf( stderr, "[gfx/error] capsule arena alloc failed\n" ); + s_gfx.errorCount++; + } + if ( ArenaInit( &s_gfx.cubeArenaXp, (size_t)TRANSPARENT_SHAPE_CAPACITY * sizeof( cube_instance_t ) ) != 0 ) + { + fprintf( stderr, "[gfx/error] cube(xp) arena alloc failed\n" ); + s_gfx.errorCount++; + } + if ( ArenaInit( &s_gfx.sphereArenaXp, (size_t)TRANSPARENT_SHAPE_CAPACITY * sizeof( sphere_instance_t ) ) != 0 ) + { + fprintf( stderr, "[gfx/error] sphere(xp) arena alloc failed\n" ); + s_gfx.errorCount++; + } + if ( ArenaInit( &s_gfx.capsuleArenaXp, (size_t)TRANSPARENT_SHAPE_CAPACITY * sizeof( capsule_instance_t ) ) != 0 ) + { + fprintf( stderr, "[gfx/error] capsule(xp) arena alloc failed\n" ); + s_gfx.errorCount++; + } + + // procedural sky pipeline (drawn after opaque in DrawScene). + InitSky( env ); + + // IBL: BRDF LUT generated immediately at boot, sky cubemap + + // SH coefficients are filled on the first DrawScene via the dirty + // flag picked up by RebuildImageBasedLightingIfDirty. + InitImageBasedLighting( env ); + + // GTAO: owns the depth pre-pass target plus the AO trace targets. + // Sized lazily per frame via ResizeGTAO from the main render + // entry points. + InitAmbientOcclusion(); + + // HDR scene target (RGBA16F MSAA + resolve), the opaque-scene pass + // writes here, the tonemap pass samples the resolved copy and writes + // the swapchain/test output. + InitSceneTarget( env ); + InitToneMap(); + InitEdges(); + InitHighlightTarget(); + HighlightMaskInit(); + InitHighlightOutline(); + OverlayInit(); + s_gfx.swapchainColorFormat = env->defaults.color_format; + + s_gfx.sun.dirToSun = b3Normalize( (b3Vec3){ 0.5f, 0.8f, 0.4f } ); + + // Sun strength 8.0 matches the target "soft" sun:sky luminance ratio + // (~8:1) under AgX with EV=-2. AgX's curve absorbs the extra headroom + // and the image lands at a sensible exposure. + // Using s to reduce the sun strength + s_gfx.sun.color = (b3Vec3){ 8.0f, 7.6f, 6.8f }; + + // Multiplies the color to make the strength easily tuned + s_gfx.sun.strength = 0.8f; + + // Ambient 0.10 keeps the ~10:1 sun:sky luminance ratio under the PBR + // ambient term (added flat as base_color * ambient). + s_gfx.sun.ambient = 0.10f; + + // Default exposure: Preetham at physical strength is bright, -2 EV + // brings the integrated sky+sun into AgX's sweet spot. + s_gfx.exposureEv = -2.5f; + + // 1.0 is AgX's stock Standard look (identity), the Render Settings + // panel raises it to counteract AgX's path-to-white desaturation. + s_gfx.tonemapSaturation = 1.4f; + + // IBL on by default, the Render Settings panel toggles it. + s_gfx.iblEnabled = true; + + // Spec turbidity. + s_gfx.turbidity = 2.2f; + + // edge overlay: off by default, SetEdgeOverlayParams flips it on. + s_gfx.edgeOverlay = GetDefaultEdgeParams(); + + // highlight outline: enabled by default but the mask is empty until + // the adapter forwards hovered/selected shapes, so nothing draws unless + // the host wires up picking. + s_gfx.highlight = GetDefaultHighlightParams(); + + // Bring IBL in sync with the initial sun before the first frame so + // lit pipelines (once they sample the cubemap) don't read garbage + // upper mips on frame 0. Per-frame mark-dirty/rebuild is not yet implemented. + RebuildImageBasedLightingIfDirty( s_gfx.sun.dirToSun, s_gfx.turbidity ); +} + +void SetSun( Sun sun ) +{ + const float lenSq = sun.dirToSun.x * sun.dirToSun.x + sun.dirToSun.y * sun.dirToSun.y + sun.dirToSun.z * sun.dirToSun.z; + if ( lenSq > 0.0f ) + { + sun.dirToSun = b3Normalize( sun.dirToSun ); + } + else + { + sun.dirToSun = b3Vec3_axisY; + } + s_gfx.sun = sun; + s_gfx.sun.strength = b3ClampFloat( s_gfx.sun.strength, 0.0f, 1.0f ); + + SetShadowSunDir( sun.dirToSun ); + // The sun direction is a single source of truth, every consumer + // (shadow caster, direct lighting, sky, IBL) reads it through the + // renderer. Marking IBL dirty here ensures the cubemap + SH stay in + // step on the next DrawScene without callers having to remember. + MarkIblDirty(); +} + +static b3Vec3 TransformDir( Mat4 m, b3Vec3 v ) +{ + // 3x3 of m times v (treats v as a direction, ignores translation). + Vec4 r = MulMV4( m, MakeVec4( v.x, v.y, v.z, 0.0f ) ); + return (b3Vec3){ r.x, r.y, r.z }; +} + +static sg_pass_action MakeSceneClear( void ) +{ + sg_pass_action a = { 0 }; + a.colors[0].load_action = SG_LOADACTION_CLEAR; + a.colors[0].clear_value = (sg_color){ 0.0f, 0.0f, 0.0f, 1.0f }; + a.depth.load_action = SG_LOADACTION_CLEAR; + a.depth.clear_value = 0.0f; // reverse-Z far + return a; +} + +static void UploadInstances( void ) +{ + if ( s_gfx.cubeCount > 0 ) + { + sg_range r; + r.ptr = s_gfx.cubeBase; + r.size = s_gfx.cubeCount * sizeof( cube_instance_t ); + sg_update_buffer( s_gfx.cubeInstBuf, &r ); + } + if ( s_gfx.sphereCount > 0 ) + { + sg_range r; + r.ptr = s_gfx.sphereBase; + r.size = s_gfx.sphereCount * sizeof( sphere_instance_t ); + sg_update_buffer( s_gfx.sphereInstBuf, &r ); + } + if ( s_gfx.capsuleCount > 0 ) + { + sg_range r; + r.ptr = s_gfx.capsuleBase; + r.size = s_gfx.capsuleCount * sizeof( capsule_instance_t ); + sg_update_buffer( s_gfx.capsuleInstBuf, &r ); + } + // same shape arena upload pattern for the transparent buffers. + // Per-instance picks happen at draw time via ub_draw.inst_base, so the + // buffers can stay in append-order (no need to permute by view-Z here). + if ( s_gfx.cubeCountXp > 0 ) + { + sg_range r; + r.ptr = s_gfx.cubeBaseXp; + r.size = s_gfx.cubeCountXp * sizeof( cube_instance_t ); + sg_update_buffer( s_gfx.cubeInstBufXp, &r ); + } + if ( s_gfx.sphereCountXp > 0 ) + { + sg_range r; + r.ptr = s_gfx.sphereBaseXp; + r.size = s_gfx.sphereCountXp * sizeof( sphere_instance_t ); + sg_update_buffer( s_gfx.sphereInstBufXp, &r ); + } + if ( s_gfx.capsuleCountXp > 0 ) + { + sg_range r; + r.ptr = s_gfx.capsuleBaseXp; + r.size = s_gfx.capsuleCountXp * sizeof( capsule_instance_t ); + sg_update_buffer( s_gfx.capsuleInstBufXp, &r ); + } + UploadMeshInstances(); +} + +// Render every caster shape into the cascade i shadow map. Each cascade +// gets one pass, depth attachment is the per-cascade view, viewport is +// the full shadow texture. The pass is always begun (even with zero +// casters) so the attachment gets cleared and lit shaders won't read +// stale data. +static void DrawShadowCascade( int cascade ) +{ + char cascadeMarker[24]; + snprintf( cascadeMarker, sizeof( cascadeMarker ), "shadow_cascade_%d", cascade ); + sg_push_debug_group( cascadeMarker ); + BeginShadowPass( cascade ); + + const Mat4 lightVP = GetCascadeMatrix( cascade ); + bool viewportApplied = false; + + // Cubes + if ( s_gfx.cubeCount > 0 ) + { + sg_push_debug_group( "caster_cube" ); + if ( !viewportApplied ) + { + sg_apply_viewport( 0, 0, SHADOW_RESOLUTION, SHADOW_RESOLUTION, true ); + viewportApplied = true; + } + sg_apply_pipeline( s_gfx.shadowCubePipeline ); + sg_bindings bindings = { 0 }; + bindings.vertex_buffers[0] = s_gfx.vbuf; + bindings.index_buffer = s_gfx.ibuf; + bindings.views[VIEW_shadow_cube_cube_instances] = s_gfx.cubeInstView; + sg_apply_bindings( &bindings ); + + shadow_cube_ub_frame_t ub = { 0 }; + ub.light_view_proj = lightVP; + sg_apply_uniforms( UB_shadow_cube_ub_frame, &SG_RANGE( ub ) ); + shadow_cube_ub_draw_t udraw = { 0 }; + sg_apply_uniforms( UB_shadow_cube_ub_draw, &SG_RANGE( udraw ) ); + + sg_draw( 0, (int)( sizeof( CUBE_INDICES ) / sizeof( CUBE_INDICES[0] ) ), (int)s_gfx.cubeCount ); + sg_pop_debug_group(); + } + + // Spheres (low-poly icosphere proxy) + if ( s_gfx.sphereCount > 0 ) + { + sg_push_debug_group( "caster_sphere" ); + if ( !viewportApplied ) + { + sg_apply_viewport( 0, 0, SHADOW_RESOLUTION, SHADOW_RESOLUTION, true ); + viewportApplied = true; + } + sg_apply_pipeline( s_gfx.shadowSpherePipeline ); + sg_bindings bindings = { 0 }; + bindings.vertex_buffers[0] = s_gfx.icosphereVbuf; + bindings.index_buffer = s_gfx.icosphereIbuf; + bindings.views[VIEW_shadow_sphere_instances] = s_gfx.sphereInstView; + sg_apply_bindings( &bindings ); + + shadow_sphere_ub_frame_t sub = { 0 }; + sub.light_view_proj = lightVP; + sg_apply_uniforms( UB_shadow_sphere_ub_frame, &SG_RANGE( sub ) ); + shadow_sphere_ub_draw_t sudraw = { 0 }; + sg_apply_uniforms( UB_shadow_sphere_ub_draw, &SG_RANGE( sudraw ) ); + + sg_draw( 0, s_gfx.icosphereIndexCount, (int)s_gfx.sphereCount ); + sg_pop_debug_group(); + } + + // Capsules (cylinder + caps proxy) + if ( s_gfx.capsuleCount > 0 ) + { + sg_push_debug_group( "caster_capsule" ); + if ( !viewportApplied ) + { + sg_apply_viewport( 0, 0, SHADOW_RESOLUTION, SHADOW_RESOLUTION, true ); + viewportApplied = true; + } + sg_apply_pipeline( s_gfx.shadowCapsulePipeline ); + sg_bindings bindings = { 0 }; + bindings.vertex_buffers[0] = s_gfx.capsuleProxyVbuf; + bindings.index_buffer = s_gfx.capsuleProxyIbuf; + bindings.views[VIEW_shadow_capsule_instances] = s_gfx.capsuleInstView; + sg_apply_bindings( &bindings ); + + shadow_capsule_ub_frame_t cub = { 0 }; + cub.light_view_proj = lightVP; + sg_apply_uniforms( UB_shadow_capsule_ub_frame, &SG_RANGE( cub ) ); + shadow_capsule_ub_draw_t cudraw = { 0 }; + sg_apply_uniforms( UB_shadow_capsule_ub_draw, &SG_RANGE( cudraw ) ); + + sg_draw( 0, s_gfx.capsuleProxyIndexCount, (int)s_gfx.capsuleCount ); + sg_pop_debug_group(); + } + + // Triangle geometries (hulls, meshes, heightfields) + // One draw per registry entry, same per-entry bindings as the lit + // pipeline, just a different (depth-only) shader and ub_frame. + const int geomSpanCount = GetMeshDrawSpanCount(); + const int geomMirrorSpanCount = GetMeshMirrorDrawSpanCount(); + if ( geomSpanCount > 0 || geomMirrorSpanCount > 0 ) + { + sg_push_debug_group( "caster_geom" ); + if ( !viewportApplied ) + { + sg_apply_viewport( 0, 0, SHADOW_RESOLUTION, SHADOW_RESOLUTION, true ); + viewportApplied = true; + } + + shadow_geom_ub_frame_t gub = { 0 }; + gub.light_view_proj = lightVP; + + const sg_view geomInstView = GetMeshInstanceView(); + for ( int pass = 0; pass < 2; ++pass ) + { + const int spanCount = ( pass == 0 ) ? geomSpanCount : geomMirrorSpanCount; + if ( spanCount == 0 ) + { + continue; + } + sg_apply_pipeline( ( pass == 0 ) ? s_gfx.shadowGeomPipeline : s_gfx.shadowGeomPipelineMirror ); + sg_apply_uniforms( UB_shadow_geom_ub_frame, &SG_RANGE( gub ) ); + + for ( int i = 0; i < spanCount; ++i ) + { + const MeshDrawSpan span = ( pass == 0 ) ? GetMeshDrawSpan( i ) : GetMeshMirrorDrawSpan( i ); + + sg_bindings bindings = { 0 }; + bindings.vertex_buffers[0] = span.vbo; + bindings.index_buffer = span.ibo; + bindings.views[VIEW_shadow_geom_instances] = geomInstView; + sg_apply_bindings( &bindings ); + + shadow_geom_ub_draw_t gud = { 0 }; + gud.inst_base[0] = span.firstInstance; + sg_apply_uniforms( UB_shadow_geom_ub_draw, &SG_RANGE( gud ) ); + + sg_draw( 0, span.indexCount, span.instanceCount ); + } + } + sg_pop_debug_group(); + } + + // Transparent shadow casters + // Per-instance per-shape: emit a 1-instance shadow draw for each + // transparent shape with material.z packed as SHADOW_FULL. SHADOW_NONE + // entries are skipped here, so the cascade depth map ignores them. + // Opaque casters above are batched, transparent counts are small + // enough that per-instance draws are fine. + if ( s_gfx.cubeCountXp > 0 ) + { + sg_push_debug_group( "caster_cube_xp" ); + if ( !viewportApplied ) + { + sg_apply_viewport( 0, 0, SHADOW_RESOLUTION, SHADOW_RESOLUTION, true ); + viewportApplied = true; + } + sg_apply_pipeline( s_gfx.shadowCubePipeline ); + sg_bindings bindings = { 0 }; + bindings.vertex_buffers[0] = s_gfx.vbuf; + bindings.index_buffer = s_gfx.ibuf; + bindings.views[VIEW_shadow_cube_cube_instances] = s_gfx.cubeInstViewXp; + sg_apply_bindings( &bindings ); + + shadow_cube_ub_frame_t ub = { 0 }; + ub.light_view_proj = lightVP; + sg_apply_uniforms( UB_shadow_cube_ub_frame, &SG_RANGE( ub ) ); + + for ( size_t i = 0; i < s_gfx.cubeCountXp; ++i ) + { + if ( s_gfx.cubeBaseXp[i].material.z < 0.5f ) + continue; // SHADOW_NONE + shadow_cube_ub_draw_t udraw = { 0 }; + udraw.inst_base[0] = (int)i; + sg_apply_uniforms( UB_shadow_cube_ub_draw, &SG_RANGE( udraw ) ); + sg_draw( 0, (int)( sizeof( CUBE_INDICES ) / sizeof( CUBE_INDICES[0] ) ), 1 ); + } + sg_pop_debug_group(); + } + + if ( s_gfx.sphereCountXp > 0 ) + { + sg_push_debug_group( "caster_sphere_xp" ); + if ( !viewportApplied ) + { + sg_apply_viewport( 0, 0, SHADOW_RESOLUTION, SHADOW_RESOLUTION, true ); + viewportApplied = true; + } + sg_apply_pipeline( s_gfx.shadowSpherePipeline ); + sg_bindings bindings = { 0 }; + bindings.vertex_buffers[0] = s_gfx.icosphereVbuf; + bindings.index_buffer = s_gfx.icosphereIbuf; + bindings.views[VIEW_shadow_sphere_instances] = s_gfx.sphereInstViewXp; + sg_apply_bindings( &bindings ); + + shadow_sphere_ub_frame_t sub = { 0 }; + sub.light_view_proj = lightVP; + sg_apply_uniforms( UB_shadow_sphere_ub_frame, &SG_RANGE( sub ) ); + + for ( size_t i = 0; i < s_gfx.sphereCountXp; ++i ) + { + if ( s_gfx.sphereBaseXp[i].material.z < 0.5f ) + continue; + shadow_sphere_ub_draw_t sudraw = { 0 }; + sudraw.inst_base[0] = (int)i; + sg_apply_uniforms( UB_shadow_sphere_ub_draw, &SG_RANGE( sudraw ) ); + sg_draw( 0, s_gfx.icosphereIndexCount, 1 ); + } + sg_pop_debug_group(); + } + + if ( s_gfx.capsuleCountXp > 0 ) + { + sg_push_debug_group( "caster_capsule_xp" ); + if ( !viewportApplied ) + { + sg_apply_viewport( 0, 0, SHADOW_RESOLUTION, SHADOW_RESOLUTION, true ); + viewportApplied = true; + } + sg_apply_pipeline( s_gfx.shadowCapsulePipeline ); + sg_bindings bindings = { 0 }; + bindings.vertex_buffers[0] = s_gfx.capsuleProxyVbuf; + bindings.index_buffer = s_gfx.capsuleProxyIbuf; + bindings.views[VIEW_shadow_capsule_instances] = s_gfx.capsuleInstViewXp; + sg_apply_bindings( &bindings ); + + shadow_capsule_ub_frame_t cub = { 0 }; + cub.light_view_proj = lightVP; + sg_apply_uniforms( UB_shadow_capsule_ub_frame, &SG_RANGE( cub ) ); + + for ( size_t i = 0; i < s_gfx.capsuleCountXp; ++i ) + { + if ( s_gfx.capsuleBaseXp[i].material.z < 0.5f ) + continue; + shadow_capsule_ub_draw_t cudraw = { 0 }; + cudraw.inst_base[0] = (int)i; + sg_apply_uniforms( UB_shadow_capsule_ub_draw, &SG_RANGE( cudraw ) ); + sg_draw( 0, s_gfx.capsuleProxyIndexCount, 1 ); + } + sg_pop_debug_group(); + } + + const int geomXpCount = GetTransparentMeshInstanceCount(); + if ( geomXpCount > 0 ) + { + sg_push_debug_group( "caster_geom_xp" ); + if ( !viewportApplied ) + { + sg_apply_viewport( 0, 0, SHADOW_RESOLUTION, SHADOW_RESOLUTION, true ); + viewportApplied = true; + } + sg_apply_pipeline( s_gfx.shadowGeomPipeline ); + + shadow_geom_ub_frame_t gub = { 0 }; + gub.light_view_proj = lightVP; + sg_apply_uniforms( UB_shadow_geom_ub_frame, &SG_RANGE( gub ) ); + + const sg_view xpInstView = GetTransparentMeshInstanceView(); + sg_buffer currentVbo = { 0 }; + sg_buffer currentIbo = { 0 }; + for ( int i = 0; i < geomXpCount; ++i ) + { + const MeshXpInstance xp = GetTransparentMeshInstance( i ); + if ( xp.shadowCast < 0.5f ) + continue; + if ( xp.vbo.id != currentVbo.id || xp.ibo.id != currentIbo.id ) + { + sg_bindings bindings = { 0 }; + bindings.vertex_buffers[0] = xp.vbo; + bindings.index_buffer = xp.ibo; + bindings.views[VIEW_shadow_geom_instances] = xpInstView; + sg_apply_bindings( &bindings ); + currentVbo = xp.vbo; + currentIbo = xp.ibo; + } + shadow_geom_ub_draw_t gud = { 0 }; + gud.inst_base[0] = xp.firstInstance; + sg_apply_uniforms( UB_shadow_geom_ub_draw, &SG_RANGE( gud ) ); + sg_draw( 0, xp.indexCount, 1 ); + } + sg_pop_debug_group(); + } + + EndShadowPass(); + sg_pop_debug_group(); +} + +static void DrawScene( int targetWidth, int targetHeight, const FrameInput* frame ) +{ + const Mat4 viewProj = MulMM4( frame->proj, frame->view ); + // inv(P*V) = inv(V)*inv(P), produced from the same params as P and V. + const Mat4 invViewProj = MulMM4( frame->viewInv, frame->projInv ); + + const float w = (float)targetWidth; + const float h = (float)targetHeight; + const Vec4 viewport = MakeVec4( w, h, w > 0.0f ? 1.0f / w : 0.0f, h > 0.0f ? 1.0f / h : 0.0f ); + + // Sun direction TO the light. Sphere/capsule/geom shaders work in + // world space (analytic normals or per-vertex-data normals), the cube + // shader works in view space (dFdx/dFdy of v_view_pos, converting to + // world inverts the normal on D3D11). Both forms uploaded so each + // pipeline takes what it needs. + const b3Vec3 sunWorld = s_gfx.sun.dirToSun; + const b3Vec3 sunView = b3Normalize( TransformDir( frame->view, sunWorld ) ); + // pre-multiply sun_color RGB by pi so the BRDF's `baseColor / pi` + // diffuse term cancels out to the old Lambert magnitude. This treats + // sun.color as illuminance (user-facing convention preserved from + // ) rather than radiance, keeps existing scenes recognizable + // through the PBR transition. Ambient (sun_color.a) is unscaled. + float str = s_gfx.sun.strength * B3_PI; + const Vec4 sunColor = + MakeVec4( s_gfx.sun.color.x * str, s_gfx.sun.color.y * str, s_gfx.sun.color.z * str, s_gfx.sun.ambient ); + + // Cascade data built once and copied into each lit pipeline's ub_pass. + // .w packs a backend-conditional UV.y sign for the shadow lookup: + // OpenGL render targets have V=0 at the bottom (UV.y matches NDC.y so + // sign = +1), D3D11/Metal/WebGPU put V=0 at the top (sign = -1 to + // flip). The shader multiplies NDC.y by this before mapping to UV.y. + const sg_backend backend = sg_query_backend(); + const float uvYSign = ( backend == SG_BACKEND_GLCORE || backend == SG_BACKEND_GLES3 ) ? 1.0f : -1.0f; + const Vec4 cascadeFarViewZ = MakeVec4( GetCascadeFarViewZ( 0 ), GetCascadeFarViewZ( 1 ), GetCascadeFarViewZ( 2 ), uvYSign ); + Mat4 cascadeMatrices[3]; + for ( int i = 0; i < 3; ++i ) + { + cascadeMatrices[i] = GetCascadeMatrix( i ); + } + const sg_view shadowSampleView = GetShadowSampleView(); + const sg_sampler shadowSampler = GetShadowSampler(); + + // IBL state, pulled once, shared across every lit pipeline. + // sh is stored as b3Vec3 in the IBL cache, the UBO layout expects + // Vec4 with .w padding (std140 array stride). + const sg_view iblSpecView = GetIblSpecularView(); + const sg_sampler iblSpecSampler = GetIblSpecularSampler(); + const sg_view iblLutView = GetIblBrdfLutView(); + const sg_sampler iblLutSampler = GetIblBrdfLutSampler(); + const float iblMaxLod = GetIblSpecularMaxLod(); + // ibl_params.y: 1.0 = IBL ambient, 0.0 = legacy flat ambient. Shared + // across all four lit pipelines' ub_pass below. + const float iblEnabledFlag = s_gfx.iblEnabled ? 1.0f : 0.0f; + b3Vec3 iblSh[9]; + GetIblSphericalHarmonicCoefficients( iblSh ); + + // GTAO state, full-res R16F `result` AO target sampled per- + // fragment in every lit pipeline. Between rework steps 1 and 4 this + // is cleared to 1.0 every frame (no occlusion), the denoise compute + // final-apply replaces the clear. + const sg_view aoView = GetAOResultSampleView(); + const sg_sampler aoSampler = GetAOLinearSampler(); + + // Cubes + if ( s_gfx.cubeCount > 0 ) + { + ub_frame_t ub = { 0 }; + ub.view = frame->view; + ub.proj = frame->proj; + ub.view_proj = viewProj; + ub.inv_view_proj = invViewProj; + ub.camera_pos = MakeVec4( frame->cameraPosition.x, frame->cameraPosition.y, frame->cameraPosition.z, frame->time ); + ub.viewport = viewport; + + ub_pass_t up = { 0 }; + up.sun_dir_view = MakeVec4( sunView.x, sunView.y, sunView.z, 0.0f ); + up.sun_color = sunColor; + up.flags[0] = frame->debugMode; + up.cascade_far_view_z = cascadeFarViewZ; + for ( int i = 0; i < 3; ++i ) + up.cascade_matrices[i] = cascadeMatrices[i]; + up.view = frame->view; + up.camera_pos_world = MakeVec4( frame->cameraPosition.x, frame->cameraPosition.y, frame->cameraPosition.z, 0.0f ); + for ( int i = 0; i < 9; ++i ) + { + up.sh[i] = MakeVec4( iblSh[i].x, iblSh[i].y, iblSh[i].z, 0.0f ); + } + up.ibl_params = MakeVec4( iblMaxLod, iblEnabledFlag, 0.0f, 0.0f ); + + sg_apply_pipeline( s_gfx.cubePipeline ); + sg_bindings bindings = { 0 }; + bindings.vertex_buffers[0] = s_gfx.vbuf; + bindings.index_buffer = s_gfx.ibuf; + bindings.views[VIEW_cube_instances] = s_gfx.cubeInstView; + bindings.views[VIEW_tex_shadow] = shadowSampleView; + bindings.views[VIEW_tex_ibl_spec] = iblSpecView; + bindings.views[VIEW_tex_brdf_lut] = iblLutView; + bindings.views[VIEW_tex_ao] = aoView; + bindings.samplers[SMP_smp_shadow] = shadowSampler; + bindings.samplers[SMP_smp_ibl_spec] = iblSpecSampler; + bindings.samplers[SMP_smp_brdf_lut] = iblLutSampler; + bindings.samplers[SMP_smp_ao] = aoSampler; + sg_apply_bindings( &bindings ); + sg_apply_uniforms( UB_ub_frame, &SG_RANGE( ub ) ); + sg_apply_uniforms( UB_ub_pass, &SG_RANGE( up ) ); + // opaque draws bind the contiguous opaque arena, inst_base = 0 + // collapses items[inst_base.x + gl_InstanceIndex] back to plain + // items[gl_InstanceIndex], bit-identical to the lookup. + ub_draw_t udraw = { 0 }; + sg_apply_uniforms( UB_ub_draw, &SG_RANGE( udraw ) ); + sg_draw( 0, (int)( sizeof( CUBE_INDICES ) / sizeof( CUBE_INDICES[0] ) ), (int)s_gfx.cubeCount ); + } + + // Sphere impostors + if ( s_gfx.sphereCount > 0 ) + { + sphere_ub_frame_t sub = { 0 }; + sub.view_proj = viewProj; + + sphere_ub_pass_t sup = { 0 }; + sup.sun_dir_world = MakeVec4( sunWorld.x, sunWorld.y, sunWorld.z, 0.0f ); + sup.sun_color = sunColor; + sup.flags[0] = frame->debugMode; + sup.camera_pos = MakeVec4( frame->cameraPosition.x, frame->cameraPosition.y, frame->cameraPosition.z, 0.0f ); + sup.view_proj = viewProj; + sup.view = frame->view; + sup.cascade_far_view_z = cascadeFarViewZ; + for ( int i = 0; i < 3; ++i ) + sup.cascade_matrices[i] = cascadeMatrices[i]; + for ( int i = 0; i < 9; ++i ) + { + sup.sh[i] = MakeVec4( iblSh[i].x, iblSh[i].y, iblSh[i].z, 0.0f ); + } + sup.ibl_params = MakeVec4( iblMaxLod, iblEnabledFlag, 0.0f, 0.0f ); + + sg_apply_pipeline( s_gfx.spherePipeline ); + sg_bindings bindings = { 0 }; + bindings.vertex_buffers[0] = s_gfx.vbuf; + bindings.index_buffer = s_gfx.ibuf; + bindings.views[VIEW_sphere_instances] = s_gfx.sphereInstView; + bindings.views[VIEW_sphere_tex_shadow] = shadowSampleView; + bindings.views[VIEW_sphere_tex_ibl_spec] = iblSpecView; + bindings.views[VIEW_sphere_tex_brdf_lut] = iblLutView; + bindings.views[VIEW_sphere_tex_ao] = aoView; + bindings.samplers[SMP_sphere_smp_shadow] = shadowSampler; + bindings.samplers[SMP_sphere_smp_ibl_spec] = iblSpecSampler; + bindings.samplers[SMP_sphere_smp_brdf_lut] = iblLutSampler; + bindings.samplers[SMP_sphere_smp_ao] = aoSampler; + sg_apply_bindings( &bindings ); + sg_apply_uniforms( UB_sphere_ub_frame, &SG_RANGE( sub ) ); + sg_apply_uniforms( UB_sphere_ub_pass, &SG_RANGE( sup ) ); + sphere_ub_draw_t sudraw = { 0 }; + sg_apply_uniforms( UB_sphere_ub_draw, &SG_RANGE( sudraw ) ); + sg_draw( 0, (int)( sizeof( CUBE_INDICES ) / sizeof( CUBE_INDICES[0] ) ), (int)s_gfx.sphereCount ); + } + + // Capsule impostors + if ( s_gfx.capsuleCount > 0 ) + { + capsule_ub_frame_t cub = { 0 }; + cub.view_proj = viewProj; + + capsule_ub_pass_t cup = { 0 }; + cup.sun_dir_world = MakeVec4( sunWorld.x, sunWorld.y, sunWorld.z, 0.0f ); + cup.sun_color = sunColor; + cup.flags[0] = frame->debugMode; + cup.camera_pos = MakeVec4( frame->cameraPosition.x, frame->cameraPosition.y, frame->cameraPosition.z, 0.0f ); + cup.view_proj = viewProj; + cup.view = frame->view; + cup.cascade_far_view_z = cascadeFarViewZ; + for ( int i = 0; i < 3; ++i ) + cup.cascade_matrices[i] = cascadeMatrices[i]; + for ( int i = 0; i < 9; ++i ) + { + cup.sh[i] = MakeVec4( iblSh[i].x, iblSh[i].y, iblSh[i].z, 0.0f ); + } + cup.ibl_params = MakeVec4( iblMaxLod, iblEnabledFlag, 0.0f, 0.0f ); + + sg_apply_pipeline( s_gfx.capsulePipeline ); + sg_bindings bindings = { 0 }; + bindings.vertex_buffers[0] = s_gfx.vbuf; + bindings.index_buffer = s_gfx.ibuf; + bindings.views[VIEW_capsule_instances] = s_gfx.capsuleInstView; + bindings.views[VIEW_capsule_tex_shadow] = shadowSampleView; + bindings.views[VIEW_capsule_tex_ibl_spec] = iblSpecView; + bindings.views[VIEW_capsule_tex_brdf_lut] = iblLutView; + bindings.views[VIEW_capsule_tex_ao] = aoView; + bindings.samplers[SMP_capsule_smp_shadow] = shadowSampler; + bindings.samplers[SMP_capsule_smp_ibl_spec] = iblSpecSampler; + bindings.samplers[SMP_capsule_smp_brdf_lut] = iblLutSampler; + bindings.samplers[SMP_capsule_smp_ao] = aoSampler; + sg_apply_bindings( &bindings ); + sg_apply_uniforms( UB_capsule_ub_frame, &SG_RANGE( cub ) ); + sg_apply_uniforms( UB_capsule_ub_pass, &SG_RANGE( cup ) ); + capsule_ub_draw_t cudraw = { 0 }; + sg_apply_uniforms( UB_capsule_ub_draw, &SG_RANGE( cudraw ) ); + sg_draw( 0, (int)( sizeof( CUBE_INDICES ) / sizeof( CUBE_INDICES[0] ) ), (int)s_gfx.capsuleCount ); + } + + // Triangle geometries (hulls, meshes, heightfields) + // The registry produced one draw span per geometry that had at least one + // instance this frame. Each span carries its own vbo+ibo and a base + // offset into the shared instance buffer. Normal spans back-cull, mirror + // spans front-cull, drawn in two passes so the pipeline binds at most + // twice. Uniforms re-apply after each pipeline switch, only the bindings + // (vbo/ibo) and ub_draw (inst_base) change per span. + const int geomSpanCount = GetMeshDrawSpanCount(); + const int geomMirrorSpanCount = GetMeshMirrorDrawSpanCount(); + if ( geomSpanCount > 0 || geomMirrorSpanCount > 0 ) + { + geom_ub_frame_t gub = { 0 }; + gub.view_proj = viewProj; + + geom_ub_pass_t gup = { 0 }; + gup.sun_dir_world = MakeVec4( sunWorld.x, sunWorld.y, sunWorld.z, 0.0f ); + gup.sun_color = sunColor; + gup.flags[0] = frame->debugMode; + gup.camera_pos = MakeVec4( frame->cameraPosition.x, frame->cameraPosition.y, frame->cameraPosition.z, 0.0f ); + gup.view = frame->view; + gup.cascade_far_view_z = cascadeFarViewZ; + for ( int i = 0; i < 3; ++i ) + gup.cascade_matrices[i] = cascadeMatrices[i]; + for ( int i = 0; i < 9; ++i ) + { + gup.sh[i] = MakeVec4( iblSh[i].x, iblSh[i].y, iblSh[i].z, 0.0f ); + } + gup.ibl_params = MakeVec4( iblMaxLod, iblEnabledFlag, 0.0f, 0.0f ); + + const sg_view geomInstView = GetMeshInstanceView(); + for ( int pass = 0; pass < 2; ++pass ) + { + const int spanCount = ( pass == 0 ) ? geomSpanCount : geomMirrorSpanCount; + if ( spanCount == 0 ) + { + continue; + } + sg_apply_pipeline( ( pass == 0 ) ? s_gfx.geomPipeline : s_gfx.geomPipelineMirror ); + sg_apply_uniforms( UB_geom_ub_frame, &SG_RANGE( gub ) ); + sg_apply_uniforms( UB_geom_ub_pass, &SG_RANGE( gup ) ); + + for ( int i = 0; i < spanCount; ++i ) + { + const MeshDrawSpan span = ( pass == 0 ) ? GetMeshDrawSpan( i ) : GetMeshMirrorDrawSpan( i ); + + sg_bindings bindings = { 0 }; + bindings.vertex_buffers[0] = span.vbo; + bindings.index_buffer = span.ibo; + bindings.views[VIEW_geom_instances] = geomInstView; + bindings.views[VIEW_geom_tex_shadow] = shadowSampleView; + bindings.views[VIEW_geom_tex_ibl_spec] = iblSpecView; + bindings.views[VIEW_geom_tex_brdf_lut] = iblLutView; + bindings.views[VIEW_geom_tex_ao] = aoView; + bindings.samplers[SMP_geom_smp_shadow] = shadowSampler; + bindings.samplers[SMP_geom_smp_ibl_spec] = iblSpecSampler; + bindings.samplers[SMP_geom_smp_brdf_lut] = iblLutSampler; + bindings.samplers[SMP_geom_smp_ao] = aoSampler; + sg_apply_bindings( &bindings ); + + geom_ub_draw_t gud = { 0 }; + gud.inst_base[0] = span.firstInstance; + sg_apply_uniforms( UB_geom_ub_draw, &SG_RANGE( gud ) ); + + sg_draw( 0, span.indexCount, span.instanceCount ); + } + } + } + + // Sky + // Draw after all opaque shapes. The sky pipeline tests GREATER_EQUAL + // at NDC z = 0 against the reverse-Z cleared depth (0), so it fills + // only pixels that no opaque draw touched. + DrawSky( s_gfx.sun.dirToSun, s_gfx.turbidity, frame->cameraPosition, invViewProj ); +} + +// Depth-only pre-pass. Renders all opaque shapes from the main camera +// into two attachments owned by the gtao module: +// * R32F color attachment, positive linear view-space depth. Sampled +// by the GTAO compute pipeline. +// * D32F depth attachment, reverse-Z clip depth, transient, rasterizer +// / early-Z only. Never sampled, but required so overlapping +// primitives get correct closest-fragment selection in the R32F +// color attachment. +// +// Sphere/capsule pipelines reuse the lit impostor ray-cast (writes the +// analytic surface's linear depth + gl_FragDepth), cube/geom use the +// standard raster path. +// +// Color attachment is cleared to (SKY_SENTINEL, 0, 0, 0) with +// SKY_SENTINEL = 1e9 so sky pixels (which no draw touches) carry an +// unmistakably-far depth value while staying well-defined for the later +// bilateral-upsample depth-diff math. +static void DepthPrepass( int targetWidth, int targetHeight, Mat4 view, Mat4 viewProj, b3Vec3 camera_pos_world ) +{ + sg_pass pass = { 0 }; + pass.action.colors[0].load_action = SG_LOADACTION_CLEAR; + pass.action.colors[0].clear_value.r = 1.0e9f; // sky sentinel + pass.action.colors[0].clear_value.g = 0.0f; + pass.action.colors[0].clear_value.b = 0.0f; + pass.action.colors[0].clear_value.a = 0.0f; + pass.action.colors[0].store_action = SG_STOREACTION_STORE; + pass.action.depth.load_action = SG_LOADACTION_CLEAR; + pass.action.depth.clear_value = 0.0f; // reverse-Z far + // STORE rather than DONTCARE: the transparent pass re-attaches + // this depth view as its depth_stencil and LOADs it for depth-test + // against the opaque scene. + pass.action.depth.store_action = SG_STOREACTION_STORE; + pass.attachments.colors[0] = GetLinearDepthAttachmentView(); + pass.attachments.depth_stencil = GetPrepassDepthAttachmentView(); + sg_push_debug_group( "depth_prepass" ); + sg_begin_pass( &pass ); + + sg_apply_viewport( 0, 0, targetWidth, targetHeight, true ); + + // Cubes + if ( s_gfx.cubeCount > 0 ) + { + sg_apply_pipeline( s_gfx.depthOnlyCubePipeline ); + sg_bindings bindings = { 0 }; + bindings.vertex_buffers[0] = s_gfx.vbuf; + bindings.index_buffer = s_gfx.ibuf; + bindings.views[VIEW_depth_only_cube_cube_instances] = s_gfx.cubeInstView; + sg_apply_bindings( &bindings ); + + depth_only_cube_ub_frame_t ub = { 0 }; + ub.view_proj = viewProj; + ub.view = view; + sg_apply_uniforms( UB_depth_only_cube_ub_frame, &SG_RANGE( ub ) ); + + sg_draw( 0, (int)( sizeof( CUBE_INDICES ) / sizeof( CUBE_INDICES[0] ) ), (int)s_gfx.cubeCount ); + } + + // Spheres (analytic impostor) + if ( s_gfx.sphereCount > 0 ) + { + sg_apply_pipeline( s_gfx.depthOnlySpherePipeline ); + sg_bindings bindings = { 0 }; + bindings.vertex_buffers[0] = s_gfx.vbuf; + bindings.index_buffer = s_gfx.ibuf; + bindings.views[VIEW_depth_only_sphere_instances] = s_gfx.sphereInstView; + sg_apply_bindings( &bindings ); + + depth_only_sphere_ub_frame_t sub = { 0 }; + sub.view_proj = viewProj; + sg_apply_uniforms( UB_depth_only_sphere_ub_frame, &SG_RANGE( sub ) ); + + depth_only_sphere_ub_pass_t spp = { 0 }; + spp.view_proj = viewProj; + spp.view = view; + spp.camera_pos = MakeVec4( camera_pos_world.x, camera_pos_world.y, camera_pos_world.z, 0.0f ); + sg_apply_uniforms( UB_depth_only_sphere_ub_pass, &SG_RANGE( spp ) ); + + sg_draw( 0, (int)( sizeof( CUBE_INDICES ) / sizeof( CUBE_INDICES[0] ) ), (int)s_gfx.sphereCount ); + } + + // Capsules (analytic impostor) + if ( s_gfx.capsuleCount > 0 ) + { + sg_apply_pipeline( s_gfx.depthOnlyCapsulePipeline ); + sg_bindings bindings = { 0 }; + bindings.vertex_buffers[0] = s_gfx.vbuf; + bindings.index_buffer = s_gfx.ibuf; + bindings.views[VIEW_depth_only_capsule_instances] = s_gfx.capsuleInstView; + sg_apply_bindings( &bindings ); + + depth_only_capsule_ub_frame_t cub = { 0 }; + cub.view_proj = viewProj; + sg_apply_uniforms( UB_depth_only_capsule_ub_frame, &SG_RANGE( cub ) ); + + depth_only_capsule_ub_pass_t cpp = { 0 }; + cpp.view_proj = viewProj; + cpp.view = view; + cpp.camera_pos = MakeVec4( camera_pos_world.x, camera_pos_world.y, camera_pos_world.z, 0.0f ); + sg_apply_uniforms( UB_depth_only_capsule_ub_pass, &SG_RANGE( cpp ) ); + + sg_draw( 0, (int)( sizeof( CUBE_INDICES ) / sizeof( CUBE_INDICES[0] ) ), (int)s_gfx.capsuleCount ); + } + + // Triangle geometries (hulls/meshes/heightfields) + const int geomSpanCount = GetMeshDrawSpanCount(); + const int geomMirrorSpanCount = GetMeshMirrorDrawSpanCount(); + if ( geomSpanCount > 0 || geomMirrorSpanCount > 0 ) + { + depth_only_geom_ub_frame_t gub = { 0 }; + gub.view_proj = viewProj; + gub.view = view; + + const sg_view geomInstView = GetMeshInstanceView(); + + // 0 for normal and 1 for reflect geometry (non-uniform scale polarity) + for ( int j = 0; j < 2; ++j ) + { + const int spanCount = ( j == 0 ) ? geomSpanCount : geomMirrorSpanCount; + if ( spanCount == 0 ) + { + continue; + } + sg_apply_pipeline( ( j == 0 ) ? s_gfx.depthOnlyGeomPipeline : s_gfx.depthOnlyGeomPipelineMirror ); + sg_apply_uniforms( UB_depth_only_geom_ub_frame, &SG_RANGE( gub ) ); + + for ( int i = 0; i < spanCount; ++i ) + { + const MeshDrawSpan span = ( j == 0 ) ? GetMeshDrawSpan( i ) : GetMeshMirrorDrawSpan( i ); + + sg_bindings bindings = { 0 }; + bindings.vertex_buffers[0] = span.vbo; + bindings.index_buffer = span.ibo; + bindings.views[VIEW_depth_only_geom_instances] = geomInstView; + sg_apply_bindings( &bindings ); + + depth_only_geom_ub_draw_t gud = { 0 }; + gud.inst_base[0] = span.firstInstance; + sg_apply_uniforms( UB_depth_only_geom_ub_draw, &SG_RANGE( gud ) ); + + sg_draw( 0, span.indexCount, span.instanceCount ); + } + } + } + + sg_end_pass(); + sg_pop_debug_group(); +} + +// Cascade fitting + caster passes. Runs before the main pass so the lit +// shaders can sample populated shadow data. +// +// When `castersEnabled` is false (FrameInput.disable_shadows = true) each +// cascade pass is opened and immediately closed, the pass clears the +// attachment to depth=1.0, which the LESS_EQUAL comparison sampler reads +// as "lit" for every fragment, so lit shaders see no shadows without +// needing a shader-side branch. +static void RenderShadowCascades( const FrameInput* frame, bool castersEnabled ) +{ + FitShadows( &frame->viewInv, &frame->proj ); + for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i ) + { + if ( castersEnabled ) + { + DrawShadowCascade( i ); + } + else + { + char cascadeMarker[24]; + snprintf( cascadeMarker, sizeof( cascadeMarker ), "shadow_cascade_%d_clear", i ); + sg_push_debug_group( cascadeMarker ); + BeginShadowPass( i ); + EndShadowPass(); + sg_pop_debug_group(); + } + } +} + +// All pre-scene work (instance upload, IBL regen, shadow cascades, GTAO chain). +static void PreSceneWork( int width, int height, const FrameInput* frame ) +{ + UploadInstances(); + + // IBL regen must run before the main pass starts + RebuildImageBasedLightingIfDirty( s_gfx.sun.dirToSun, s_gfx.turbidity ); + + RenderShadowCascades( frame, frame->disableShadows == false ); + + ResizeGTAO( width, height ); + + const Mat4 view_proj = MulMM4( frame->proj, frame->view ); + DepthPrepass( width, height, frame->view, view_proj, frame->cameraPosition ); + + if ( frame->disableAmbientOcclusion == false ) + { + PrefilterDepth( &frame->proj, width, height ); + ComputeNoisyResult( &frame->proj, width, height ); + Denoise( &frame->proj, width, height ); + } + else + { + ClearAmbientOcclusion(); + } +} + +// Renders the opaque scene into the HDR scene target (RGBA16F MSAA -> +// single-sample resolve). Pass action clears the MSAA color to a dark +// background (covered by the sky on every visible pixel) and the MSAA +// depth to the reverse-Z far value. +static void DrawSceneIntoHdr( int width, int height, const FrameInput* frame ) +{ + ResizeSceneTarget( width, height ); + + sg_pass pass = { 0 }; + pass.action = MakeSceneClear(); + + // Resolve store-action defaults to STORE when a resolve view is bound. + // Sample the resolve image from the tone-map pass. + pass.attachments = GetSceneTargetAttachments(); + sg_push_debug_group( "scene_hdr" ); + sg_begin_pass( &pass ); + DrawScene( width, height, frame ); + + // Edge overlay drawn inside the MSAA scene pass so edges get the same MSAA as the opaque shapes. + RenderEdgesInMSAA( width, height, &frame->view, &frame->proj, GetMeshInstanceView(), GetTransparentMeshInstanceView(), + &s_gfx.edgeOverlay ); + sg_end_pass(); + sg_pop_debug_group(); +} + +// Transparent pass +// +// Runs after the scene is drawn into HDR resolve and before tone-map. +// Attachments: +// * colors[0] = scene resolve image (LOAD), so we blend over the +// resolved opaque scene rather than overwriting it. +// * depth_stencil = GTAO prepass depth (LOAD), so depth-test against +// the opaque scene works. Single-sample, matches the prepass image +// format. Depth write is OFF on the transparent pipelines. +// +// Order across shape types is realized through a back-to-front sort on the +// view-space Z of each instance's world-space origin. Per shape kind, the +// per-instance pick is via inst_base (UBO at binding=2) so each transparent +// draw is one sg_draw(0, indexCount, 1). + +typedef enum +{ + TRANSPARENT_KIND_CUBE = 0, + TRANSPARENT_KIND_SPHERE, + TRANSPARENT_KIND_CAPSULE, + TRANSPARENT_KIND_MESH, +} TransparentShapeKind; + +typedef struct +{ + float viewZ; // positive = farther from camera + uint16_t kind; + uint16_t srcIndex; // arena index for cube/sphere/capsule, xpDraws[] index for geom +} TransparentRef; + +// Project an instance's world-space origin to view-space and return the +// positive distance (-view_pos.z). Matches the lit shaders' view_z convention. +static inline float ComputeOriginViewZ( const Mat4* view, b3Vec3 origin ) +{ + Vec4 viewPos = MulMV4( *view, MakeVec4( origin.x, origin.y, origin.z, 1.0f ) ); + return -viewPos.z; +} + +// Draw transparent shapes into the MSAA resolved target +static void DrawTransparentIntoResolve( int width, int height, const FrameInput* frame ) +{ + int cubeXp = (int)s_gfx.cubeCountXp; + int sphereXp = (int)s_gfx.sphereCountXp; + int capsuleXp = (int)s_gfx.capsuleCountXp; + int geomXp = GetTransparentMeshInstanceCount(); + int total = cubeXp + sphereXp + capsuleXp + geomXp; + if ( total <= 0 ) + { + return; + } + + // Static scratch sized to hold every instance the four streams can emit: + // three primitive streams capped at TRANSPARENT_SHAPE_CAPACITY each, plus the + // geom stream capped at MAX_GEOM_XP_INSTANCES_GLOBAL. The geom cap dwarfs the + // others, so a uniform multiple of the small cap would overflow. + static TransparentRef refs[3 * TRANSPARENT_SHAPE_CAPACITY + MAX_GEOM_XP_INSTANCES_GLOBAL]; + int n = 0; + + for ( int i = 0; i < cubeXp; ++i ) + { + const cube_instance_t* inst = &s_gfx.cubeBaseXp[i]; + b3Vec3 origin = { inst->xform_row0.w, inst->xform_row1.w, inst->xform_row2.w }; + refs[n].viewZ = ComputeOriginViewZ( &frame->view, origin ); + refs[n].kind = TRANSPARENT_KIND_CUBE; + refs[n].srcIndex = (uint16_t)i; + ++n; + } + for ( int i = 0; i < sphereXp; ++i ) + { + const sphere_instance_t* inst = &s_gfx.sphereBaseXp[i]; + b3Vec3 origin = { inst->xform_row0.w, inst->xform_row1.w, inst->xform_row2.w }; + refs[n].viewZ = ComputeOriginViewZ( &frame->view, origin ); + refs[n].kind = TRANSPARENT_KIND_SPHERE; + refs[n].srcIndex = (uint16_t)i; + ++n; + } + for ( int i = 0; i < capsuleXp; ++i ) + { + const capsule_instance_t* inst = &s_gfx.capsuleBaseXp[i]; + b3Vec3 origin = { inst->xform_row0.w, inst->xform_row1.w, inst->xform_row2.w }; + refs[n].viewZ = ComputeOriginViewZ( &frame->view, origin ); + refs[n].kind = TRANSPARENT_KIND_CAPSULE; + refs[n].srcIndex = (uint16_t)i; + ++n; + } + for ( int i = 0; i < geomXp; ++i ) + { + const MeshXpInstance xp = GetTransparentMeshInstance( i ); + refs[n].viewZ = ComputeOriginViewZ( &frame->view, xp.origin ); + refs[n].kind = TRANSPARENT_KIND_MESH; + refs[n].srcIndex = (uint16_t)i; + ++n; + } + + // Back-to-front: larger viewZ first. +#define LESS( i, j ) refs[i].viewZ > refs[j].viewZ +#define SWAP( i, j ) \ + do \ + { \ + TransparentRef tmp_ = refs[i]; \ + refs[i] = refs[j]; \ + refs[j] = tmp_; \ + } \ + while ( 0 ) + QSORT( n, LESS, SWAP ); +#undef LESS +#undef SWAP + + // Build per-shape ub_frame / ub_pass once + // Mirrors DrawScene, the transparent pass needs the same lighting + + // shadow + IBL + AO context. Computed once outside the draw loop, then + // re-applied each time the pipeline switches to a new shape kind. + const Mat4 view_proj = MulMM4( frame->proj, frame->view ); + const Mat4 inv_view_proj = MulMM4( frame->viewInv, frame->projInv ); + const float w = (float)width; + const float h = (float)height; + const Vec4 viewport = MakeVec4( w, h, w > 0.0f ? 1.0f / w : 0.0f, h > 0.0f ? 1.0f / h : 0.0f ); + + const b3Vec3 sunWorld = s_gfx.sun.dirToSun; + const b3Vec3 sunView = b3Normalize( TransformDir( frame->view, sunWorld ) ); + float str = s_gfx.sun.strength * B3_PI; + const Vec4 sunColor = + MakeVec4( s_gfx.sun.color.x * str, s_gfx.sun.color.y * str, s_gfx.sun.color.z * str, s_gfx.sun.ambient ); + + const sg_backend backend = sg_query_backend(); + const float uvYSign = ( backend == SG_BACKEND_GLCORE || backend == SG_BACKEND_GLES3 ) ? 1.0f : -1.0f; + const Vec4 cascadeFarViewZ = MakeVec4( GetCascadeFarViewZ( 0 ), GetCascadeFarViewZ( 1 ), GetCascadeFarViewZ( 2 ), uvYSign ); + Mat4 cascadeMatrices[3]; + for ( int i = 0; i < 3; ++i ) + { + cascadeMatrices[i] = GetCascadeMatrix( i ); + } + const sg_view shadowSampleView = GetShadowSampleView(); + const sg_sampler shadowSampler = GetShadowSampler(); + + const sg_view iblSpecView = GetIblSpecularView(); + const sg_sampler iblSpecSampler = GetIblSpecularSampler(); + const sg_view iblLutView = GetIblBrdfLutView(); + const sg_sampler iblLutSampler = GetIblBrdfLutSampler(); + const float iblMaxLod = GetIblSpecularMaxLod(); + // ibl_params.y: 1.0 = IBL ambient, 0.0 = legacy flat ambient. Shared + // across all four lit pipelines' ub_pass below. + const float iblEnabledFlag = s_gfx.iblEnabled ? 1.0f : 0.0f; + b3Vec3 iblSh[9]; + GetIblSphericalHarmonicCoefficients( iblSh ); + const sg_view aoView = GetAOResultSampleView(); + const sg_sampler aoSampler = GetAOLinearSampler(); + + ub_frame_t cubeFrame = { 0 }; + cubeFrame.view = frame->view; + cubeFrame.proj = frame->proj; + cubeFrame.view_proj = view_proj; + cubeFrame.inv_view_proj = inv_view_proj; + cubeFrame.camera_pos = MakeVec4( frame->cameraPosition.x, frame->cameraPosition.y, frame->cameraPosition.z, frame->time ); + cubeFrame.viewport = viewport; + + ub_pass_t cubePass = { 0 }; + cubePass.sun_dir_view = MakeVec4( sunView.x, sunView.y, sunView.z, 0.0f ); + cubePass.sun_color = sunColor; + cubePass.flags[0] = frame->debugMode; + cubePass.cascade_far_view_z = cascadeFarViewZ; + for ( int i = 0; i < 3; ++i ) + { + cubePass.cascade_matrices[i] = cascadeMatrices[i]; + } + cubePass.view = frame->view; + cubePass.camera_pos_world = MakeVec4( frame->cameraPosition.x, frame->cameraPosition.y, frame->cameraPosition.z, 0.0f ); + for ( int i = 0; i < 9; ++i ) + { + cubePass.sh[i] = MakeVec4( iblSh[i].x, iblSh[i].y, iblSh[i].z, 0.0f ); + } + cubePass.ibl_params = MakeVec4( iblMaxLod, iblEnabledFlag, 0.0f, 0.0f ); + + sphere_ub_frame_t sphereFrame = { 0 }; + sphereFrame.view_proj = view_proj; + sphere_ub_pass_t spherePass = { 0 }; + spherePass.sun_dir_world = MakeVec4( sunWorld.x, sunWorld.y, sunWorld.z, 0.0f ); + spherePass.sun_color = sunColor; + spherePass.flags[0] = frame->debugMode; + spherePass.camera_pos = MakeVec4( frame->cameraPosition.x, frame->cameraPosition.y, frame->cameraPosition.z, 0.0f ); + spherePass.view_proj = view_proj; + spherePass.view = frame->view; + spherePass.cascade_far_view_z = cascadeFarViewZ; + for ( int i = 0; i < 3; ++i ) + spherePass.cascade_matrices[i] = cascadeMatrices[i]; + for ( int i = 0; i < 9; ++i ) + spherePass.sh[i] = MakeVec4( iblSh[i].x, iblSh[i].y, iblSh[i].z, 0.0f ); + spherePass.ibl_params = MakeVec4( iblMaxLod, iblEnabledFlag, 0.0f, 0.0f ); + + capsule_ub_frame_t capsuleFrame = { 0 }; + capsuleFrame.view_proj = view_proj; + capsule_ub_pass_t capsulePass = { 0 }; + capsulePass.sun_dir_world = MakeVec4( sunWorld.x, sunWorld.y, sunWorld.z, 0.0f ); + capsulePass.sun_color = sunColor; + capsulePass.flags[0] = frame->debugMode; + capsulePass.camera_pos = MakeVec4( frame->cameraPosition.x, frame->cameraPosition.y, frame->cameraPosition.z, 0.0f ); + capsulePass.view_proj = view_proj; + capsulePass.view = frame->view; + capsulePass.cascade_far_view_z = cascadeFarViewZ; + for ( int i = 0; i < 3; ++i ) + capsulePass.cascade_matrices[i] = cascadeMatrices[i]; + for ( int i = 0; i < 9; ++i ) + capsulePass.sh[i] = MakeVec4( iblSh[i].x, iblSh[i].y, iblSh[i].z, 0.0f ); + capsulePass.ibl_params = MakeVec4( iblMaxLod, iblEnabledFlag, 0.0f, 0.0f ); + + geom_ub_frame_t geomFrame = { 0 }; + geomFrame.view_proj = view_proj; + geom_ub_pass_t geomPass = { 0 }; + geomPass.sun_dir_world = MakeVec4( sunWorld.x, sunWorld.y, sunWorld.z, 0.0f ); + geomPass.sun_color = sunColor; + geomPass.flags[0] = frame->debugMode; + geomPass.camera_pos = MakeVec4( frame->cameraPosition.x, frame->cameraPosition.y, frame->cameraPosition.z, 0.0f ); + geomPass.view = frame->view; + geomPass.cascade_far_view_z = cascadeFarViewZ; + for ( int i = 0; i < 3; ++i ) + geomPass.cascade_matrices[i] = cascadeMatrices[i]; + for ( int i = 0; i < 9; ++i ) + geomPass.sh[i] = MakeVec4( iblSh[i].x, iblSh[i].y, iblSh[i].z, 0.0f ); + geomPass.ibl_params = MakeVec4( iblMaxLod, iblEnabledFlag, 0.0f, 0.0f ); + + // Begin transparent pass + sg_pass pass = { 0 }; + pass.action.colors[0].load_action = SG_LOADACTION_LOAD; + pass.action.colors[0].store_action = SG_STOREACTION_STORE; + pass.action.depth.load_action = SG_LOADACTION_LOAD; + pass.action.depth.store_action = SG_STOREACTION_DONTCARE; + pass.attachments.colors[0] = GetSceneTargetResolveColorAttachView(); + pass.attachments.depth_stencil = GetPrepassDepthAttachmentView(); + pass.label = "transparent_pass"; + sg_push_debug_group( "transparent" ); + sg_begin_pass( &pass ); + sg_apply_viewport( 0, 0, width, height, true ); + + // forces first-iteration pipeline + bindings + uniforms apply + int currentKind = -1; + sg_buffer currentGeomVbo = { 0 }; + sg_buffer currentGeomIbo = { 0 }; + + for ( int i = 0; i < n; ++i ) + { + const TransparentRef ref = refs[i]; + + if ( (int)ref.kind != currentKind ) + { + switch ( (TransparentShapeKind)ref.kind ) + { + case TRANSPARENT_KIND_CUBE: + { + sg_apply_pipeline( s_gfx.cubePipelineXp ); + sg_bindings b = { 0 }; + b.vertex_buffers[0] = s_gfx.vbuf; + b.index_buffer = s_gfx.ibuf; + b.views[VIEW_cube_instances] = s_gfx.cubeInstViewXp; + b.views[VIEW_tex_shadow] = shadowSampleView; + b.views[VIEW_tex_ibl_spec] = iblSpecView; + b.views[VIEW_tex_brdf_lut] = iblLutView; + b.views[VIEW_tex_ao] = aoView; + b.samplers[SMP_smp_shadow] = shadowSampler; + b.samplers[SMP_smp_ibl_spec] = iblSpecSampler; + b.samplers[SMP_smp_brdf_lut] = iblLutSampler; + b.samplers[SMP_smp_ao] = aoSampler; + sg_apply_bindings( &b ); + sg_apply_uniforms( UB_ub_frame, &SG_RANGE( cubeFrame ) ); + sg_apply_uniforms( UB_ub_pass, &SG_RANGE( cubePass ) ); + } + break; + case TRANSPARENT_KIND_SPHERE: + { + sg_apply_pipeline( s_gfx.spherePipelineXp ); + sg_bindings b = { 0 }; + b.vertex_buffers[0] = s_gfx.vbuf; + b.index_buffer = s_gfx.ibuf; + b.views[VIEW_sphere_instances] = s_gfx.sphereInstViewXp; + b.views[VIEW_sphere_tex_shadow] = shadowSampleView; + b.views[VIEW_sphere_tex_ibl_spec] = iblSpecView; + b.views[VIEW_sphere_tex_brdf_lut] = iblLutView; + b.views[VIEW_sphere_tex_ao] = aoView; + b.samplers[SMP_sphere_smp_shadow] = shadowSampler; + b.samplers[SMP_sphere_smp_ibl_spec] = iblSpecSampler; + b.samplers[SMP_sphere_smp_brdf_lut] = iblLutSampler; + b.samplers[SMP_sphere_smp_ao] = aoSampler; + sg_apply_bindings( &b ); + sg_apply_uniforms( UB_sphere_ub_frame, &SG_RANGE( sphereFrame ) ); + sg_apply_uniforms( UB_sphere_ub_pass, &SG_RANGE( spherePass ) ); + } + break; + case TRANSPARENT_KIND_CAPSULE: + { + sg_apply_pipeline( s_gfx.capsulePipelineXp ); + sg_bindings b = { 0 }; + b.vertex_buffers[0] = s_gfx.vbuf; + b.index_buffer = s_gfx.ibuf; + b.views[VIEW_capsule_instances] = s_gfx.capsuleInstViewXp; + b.views[VIEW_capsule_tex_shadow] = shadowSampleView; + b.views[VIEW_capsule_tex_ibl_spec] = iblSpecView; + b.views[VIEW_capsule_tex_brdf_lut] = iblLutView; + b.views[VIEW_capsule_tex_ao] = aoView; + b.samplers[SMP_capsule_smp_shadow] = shadowSampler; + b.samplers[SMP_capsule_smp_ibl_spec] = iblSpecSampler; + b.samplers[SMP_capsule_smp_brdf_lut] = iblLutSampler; + b.samplers[SMP_capsule_smp_ao] = aoSampler; + sg_apply_bindings( &b ); + sg_apply_uniforms( UB_capsule_ub_frame, &SG_RANGE( capsuleFrame ) ); + sg_apply_uniforms( UB_capsule_ub_pass, &SG_RANGE( capsulePass ) ); + } + break; + case TRANSPARENT_KIND_MESH: + { + sg_apply_pipeline( s_gfx.geomPipelineXp ); + sg_apply_uniforms( UB_geom_ub_frame, &SG_RANGE( geomFrame ) ); + sg_apply_uniforms( UB_geom_ub_pass, &SG_RANGE( geomPass ) ); + // Geom bindings rebound per draw below (per-entry + // vbo/ibo). Reset the tracker so the first geom draw + // applies bindings. + currentGeomVbo.id = 0; + currentGeomIbo.id = 0; + } + break; + } + currentKind = (int)ref.kind; + } + + switch ( (TransparentShapeKind)ref.kind ) + { + case TRANSPARENT_KIND_CUBE: + { + ub_draw_t ud = { 0 }; + ud.inst_base[0] = (int)ref.srcIndex; + sg_apply_uniforms( UB_ub_draw, &SG_RANGE( ud ) ); + sg_draw( 0, (int)( sizeof( CUBE_INDICES ) / sizeof( CUBE_INDICES[0] ) ), 1 ); + } + break; + case TRANSPARENT_KIND_SPHERE: + { + sphere_ub_draw_t sd = { 0 }; + sd.inst_base[0] = (int)ref.srcIndex; + sg_apply_uniforms( UB_sphere_ub_draw, &SG_RANGE( sd ) ); + sg_draw( 0, (int)( sizeof( CUBE_INDICES ) / sizeof( CUBE_INDICES[0] ) ), 1 ); + } + break; + case TRANSPARENT_KIND_CAPSULE: + { + capsule_ub_draw_t cd = { 0 }; + cd.inst_base[0] = (int)ref.srcIndex; + sg_apply_uniforms( UB_capsule_ub_draw, &SG_RANGE( cd ) ); + sg_draw( 0, (int)( sizeof( CUBE_INDICES ) / sizeof( CUBE_INDICES[0] ) ), 1 ); + } + break; + case TRANSPARENT_KIND_MESH: + { + const MeshXpInstance xp = GetTransparentMeshInstance( (int)ref.srcIndex ); + if ( xp.vbo.id != currentGeomVbo.id || xp.ibo.id != currentGeomIbo.id ) + { + sg_bindings b = { 0 }; + b.vertex_buffers[0] = xp.vbo; + b.index_buffer = xp.ibo; + b.views[VIEW_geom_instances] = GetTransparentMeshInstanceView(); + b.views[VIEW_geom_tex_shadow] = shadowSampleView; + b.views[VIEW_geom_tex_ibl_spec] = iblSpecView; + b.views[VIEW_geom_tex_brdf_lut] = iblLutView; + b.views[VIEW_geom_tex_ao] = aoView; + b.samplers[SMP_geom_smp_shadow] = shadowSampler; + b.samplers[SMP_geom_smp_ibl_spec] = iblSpecSampler; + b.samplers[SMP_geom_smp_brdf_lut] = iblLutSampler; + b.samplers[SMP_geom_smp_ao] = aoSampler; + sg_apply_bindings( &b ); + currentGeomVbo = xp.vbo; + currentGeomIbo = xp.ibo; + } + geom_ub_draw_t gd = { 0 }; + gd.inst_base[0] = xp.firstInstance; + sg_apply_uniforms( UB_geom_ub_draw, &SG_RANGE( gd ) ); + sg_draw( 0, xp.indexCount, 1 ); + } + break; + } + } + + sg_end_pass(); + sg_pop_debug_group(); +} + +// Snapshot per-frame counters into s_gfx.stats. Called at the end of each +// render path so the panel reads a consistent set. Geom counts are summed +// across the upload spans recorded by GetMeshDrawSpan(), transparent geom +// instance count comes from the dedicated accessor. +static void PopulateStats( float frameTimeMs ) +{ + RenderStats st = { 0 }; + st.cubeCount = (int)s_gfx.cubeCount; + st.sphereCount = (int)s_gfx.sphereCount; + st.capsuleCount = (int)s_gfx.capsuleCount; + st.cubeCountXp = (int)s_gfx.cubeCountXp; + st.sphereCountXp = (int)s_gfx.sphereCountXp; + st.capsuleCountXp = (int)s_gfx.capsuleCountXp; + + const int geomSpans = GetMeshDrawSpanCount(); + const int geomMirrorSpans = GetMeshMirrorDrawSpanCount(); + st.geomSpanCount = geomSpans + geomMirrorSpans; + int geomInstSum = 0; + for ( int i = 0; i < geomSpans; ++i ) + { + geomInstSum += GetMeshDrawSpan( i ).instanceCount; + } + for ( int i = 0; i < geomMirrorSpans; ++i ) + { + geomInstSum += GetMeshMirrorDrawSpan( i ).instanceCount; + } + st.geomInstanceCount = geomInstSum; + st.geomInstanceCountXp = GetTransparentMeshInstanceCount(); + + st.lineCount = OverlayLineCount(); + st.pointCount = OverlayPointCount(); + + // Approximate draw count: one per non-empty opaque shape stream, one per + // geom span, one per transparent instance (each gets its own draw call + // in the sorted pass), plus the line/point pipelines and the always- + // present sky + tonemap. Shadow caster pass adds one draw per cascade + // per non-empty caster type. This is a rough indicator, not an exact + // GPU profile. + int draws = 0; + draws += ( st.cubeCount > 0 ) ? 1 : 0; + draws += ( st.sphereCount > 0 ) ? 1 : 0; + draws += ( st.capsuleCount > 0 ) ? 1 : 0; + draws += st.geomSpanCount; + draws += st.cubeCountXp + st.sphereCountXp + st.capsuleCountXp; + draws += st.geomInstanceCountXp; + draws += ( st.lineCount > 0 ) ? 1 : 0; + draws += ( st.pointCount > 0 ) ? 1 : 0; + draws += 1; // sky + draws += 1; // tonemap + st.drawCallCount = draws; + + st.frameTimeMs = frameTimeMs; + s_gfx.stats = st; +} + +void RenderFrame( const sg_swapchain* swapChain, const FrameInput* frame ) +{ + uint64_t tStart = b3GetTicks(); + + s_gfx.cameraState = (CameraState){ + .view = frame->view, + .viewInv = frame->viewInv, + .proj = frame->proj, + .projInv = frame->projInv, + .viewportW = swapChain->width, + .viewportH = swapChain->height, + }; + + PreSceneWork( swapChain->width, swapChain->height, frame ); + DrawSceneIntoHdr( swapChain->width, swapChain->height, frame ); + DrawTransparentIntoResolve( swapChain->width, swapChain->height, frame ); + + // Transparent edge overlay: read+test against the GTAO prepass depth, write + // into the resolved scene color above the transparent pass. Opaque- + // arena edges were already drawn into the MSAA scene target inside + // DrawSceneIntoHdr, this pass picks up the transparent-hull edges + // that need to sit on top of the transparent blend. (Under the + // EDGES_TRANSPARENT_INCLUDES_OPAQUE experiment the opaque-arena edges + // flow through here too.). + RenderEdgesPostTransparent( swapChain->width, swapChain->height, &frame->view, &frame->proj, + GetSceneTargetResolveColorAttachView(), GetPrepassDepthAttachmentView(), GetMeshInstanceView(), + GetTransparentMeshInstanceView(), &s_gfx.edgeOverlay ); + + // highlight mask, only when the box3d adapter (or test scene) + // forwarded hovered/selected shapes for this frame. Mask depth-tests + // against the GTAO prepass depth so occluded highlights don't bleed. + const bool drawHighlights = s_gfx.highlight.enabled && HasHighlightMaskContent(); + if ( drawHighlights ) + { + ResizeHighlightTarget( swapChain->width, swapChain->height ); + const Mat4 viewProj = MulMM4( frame->proj, frame->view ); + SubmitHighlightMask( swapChain->width, swapChain->height, &viewProj, frame->cameraPosition, + GetHighlightTargetMaskAttachView(), GetPrepassDepthAttachmentView() ); + } + + // tonemap: read the resolved HDR scene color, apply exposure + + // AgX, write display-encoded sRGB to the swapchain. The outline + // post-pass piggybacks on the same swapchain pass so the outline + // composites in display space, behind ImGui (which the caller draws + // after RenderFrame returns). + sg_pass tmPass = { 0 }; + tmPass.action.colors[0].load_action = SG_LOADACTION_DONTCARE; + tmPass.swapchain = *swapChain; + sg_push_debug_group( "present" ); + sg_begin_pass( &tmPass ); + // Swapchain has its own depth attachment (sokol_app default), the + // tonemap pipeline must declare a matching depth format even though + // it doesn't read or write depth. + sg_push_debug_group( "tonemap" ); + SubmitToneMap( GetSceneTargetResolveSampleView(), swapChain->color_format, swapChain->depth_format, s_gfx.exposureEv, + s_gfx.tonemapSaturation ); + sg_pop_debug_group(); + if ( drawHighlights ) + { + sg_push_debug_group( "highlight_outline" ); + SubmitHighlightOutline( GetHighlightTargetMaskSampleView(), swapChain->color_format, swapChain->depth_format, + &s_gfx.highlight ); + sg_pop_debug_group(); + } + // overlays, lines + points, drawn post-tonemap so their colors are + // display-referred (WYSIWYG, consistent with the ImGui text labels) + // rather than run through exposure + AgX. Occlusion modes still sample + // the GTAO linear-depth pre-pass. + sg_push_debug_group( "overlays" ); + OverlaySubmit( swapChain->width, swapChain->height, &frame->view, &frame->viewInv, &frame->proj, &frame->projInv, + frame->cameraPosition, frame->time, GetLinearDepthSampleView(), GetAOLinearSampler(), swapChain->color_format, + swapChain->depth_format ); + sg_pop_debug_group(); + sg_end_pass(); + sg_pop_debug_group(); + + // No sg_commit here, the caller may append more passes (e.g. the imgui + // overlay) and is responsible for the single per-frame commit. + PopulateStats( b3GetMilliseconds( tStart ) ); +} + +void RenderFrameOffscreen( const sg_attachments* attachments, sg_pixel_format outputFormat, int width, int height, + const FrameInput* frame ) +{ + uint64_t tStart = b3GetTicks(); + + s_gfx.cameraState = (CameraState){ + .view = frame->view, + .viewInv = frame->viewInv, + .proj = frame->proj, + .projInv = frame->projInv, + .viewportW = width, + .viewportH = height, + }; + + PreSceneWork( width, height, frame ); + DrawSceneIntoHdr( width, height, frame ); + DrawTransparentIntoResolve( width, height, frame ); + + RenderEdgesPostTransparent( width, height, &frame->view, &frame->proj, GetSceneTargetResolveColorAttachView(), + GetPrepassDepthAttachmentView(), GetMeshInstanceView(), GetTransparentMeshInstanceView(), + &s_gfx.edgeOverlay ); + + const bool drawHighlights = s_gfx.highlight.enabled && HasHighlightMaskContent(); + if ( drawHighlights ) + { + ResizeHighlightTarget( width, height ); + const Mat4 viewProj = MulMM4( frame->proj, frame->view ); + SubmitHighlightMask( width, height, &viewProj, frame->cameraPosition, GetHighlightTargetMaskAttachView(), + GetPrepassDepthAttachmentView() ); + } + + sg_pass tmPass = { 0 }; + tmPass.action.colors[0].load_action = SG_LOADACTION_DONTCARE; + tmPass.attachments = *attachments; + sg_push_debug_group( "present_offscreen" ); + sg_begin_pass( &tmPass ); + // Offscreen test targets are color-only (no depth attachment), the + // pipeline declares NONE for depth so sokol's validation passes. + sg_push_debug_group( "tonemap" ); + SubmitToneMap( GetSceneTargetResolveSampleView(), outputFormat, SG_PIXELFORMAT_NONE, s_gfx.exposureEv, + s_gfx.tonemapSaturation ); + sg_pop_debug_group(); + if ( drawHighlights ) + { + sg_push_debug_group( "highlight_outline" ); + SubmitHighlightOutline( GetHighlightTargetMaskSampleView(), outputFormat, SG_PIXELFORMAT_NONE, &s_gfx.highlight ); + sg_pop_debug_group(); + } + // overlays, drawn post-tonemap (display-referred). The offscreen + // test target is color-only, so depth format is NONE. + sg_push_debug_group( "overlays" ); + OverlaySubmit( width, height, &frame->view, &frame->viewInv, &frame->proj, &frame->projInv, frame->cameraPosition, + frame->time, GetLinearDepthSampleView(), GetAOLinearSampler(), outputFormat, SG_PIXELFORMAT_NONE ); + sg_pop_debug_group(); + sg_end_pass(); + sg_pop_debug_group(); + + sg_commit(); + + PopulateStats( b3GetMilliseconds( tStart ) ); +} + +void SetExposure( float ev ) +{ + s_gfx.exposureEv = ev; +} + +float GetExposure( void ) +{ + return s_gfx.exposureEv; +} + +void SetToneMapSaturation( float saturation ) +{ + s_gfx.tonemapSaturation = saturation; +} + +float GetToneMapSaturation( void ) +{ + return s_gfx.tonemapSaturation; +} + +void SetIblEnabled( bool enabled ) +{ + s_gfx.iblEnabled = enabled; +} + +bool GetIblEnabled( void ) +{ + return s_gfx.iblEnabled; +} + +void SetEdgeOverlayParams( const EdgeOverlayParams* settings ) +{ + if ( !settings ) + { + return; + } + s_gfx.edgeOverlay = *settings; +} + +EdgeOverlayParams GetEdgeOverlayParams( void ) +{ + return s_gfx.edgeOverlay; +} + +void SetHighlightParams( const HighlightParams* params ) +{ + if ( !params ) + return; + s_gfx.highlight = *params; +} + +HighlightParams GetHighlightParams( void ) +{ + return s_gfx.highlight; +} + +Sun GetSun( void ) +{ + return s_gfx.sun; +} + +void SetSkyTurbidity( float t ) +{ + if ( t < 1.0f ) + t = 1.0f; + if ( t != s_gfx.turbidity ) + { + s_gfx.turbidity = t; + MarkIblDirty(); + } +} + +float GetSkyTurbidity( void ) +{ + return s_gfx.turbidity; +} + +RenderStats GetRenderStats( void ) +{ + return s_gfx.stats; +} + +CameraState GetCameraState( void ) +{ + return s_gfx.cameraState; +} + +sg_buffer GetCubeProxyVertexBuffer( void ) +{ + return s_gfx.vbuf; +} + +sg_buffer GetCubeProxyIndexBuffer( void ) +{ + return s_gfx.ibuf; +} + +int GetCubeProxyIndexCount( void ) +{ + return (int)( sizeof( CUBE_INDICES ) / sizeof( CUBE_INDICES[0] ) ); +} + +void ShutdownRenderer( void ) +{ + OverlayShutdown(); + ShutdownHighlightOutline(); + HighlightMaskShutdown(); + ShutdownHighlightTarget(); + ShutdownEdges(); + ShutdownToneMap(); + ShutdownSceneTarget(); + ShutdownAmbientOcclusion(); + sg_destroy_pipeline( s_gfx.depthOnlyGeomPipelineMirror ); + sg_destroy_pipeline( s_gfx.depthOnlyGeomPipeline ); + sg_destroy_shader( s_gfx.depthOnlyGeomShader ); + sg_destroy_pipeline( s_gfx.depthOnlyCapsulePipeline ); + sg_destroy_shader( s_gfx.depthOnlyCapsuleShader ); + sg_destroy_pipeline( s_gfx.depthOnlySpherePipeline ); + sg_destroy_shader( s_gfx.depthOnlySphereShader ); + sg_destroy_pipeline( s_gfx.depthOnlyCubePipeline ); + sg_destroy_shader( s_gfx.depthOnlyCubeShader ); + ShutdownImageBasedLighting(); + ShutdownSky(); + sg_destroy_pipeline( s_gfx.shadowCapsulePipeline ); + sg_destroy_shader( s_gfx.shadowCapsuleShader ); + sg_destroy_buffer( s_gfx.capsuleProxyIbuf ); + sg_destroy_buffer( s_gfx.capsuleProxyVbuf ); + sg_destroy_pipeline( s_gfx.shadowSpherePipeline ); + sg_destroy_shader( s_gfx.shadowSphereShader ); + sg_destroy_buffer( s_gfx.icosphereIbuf ); + sg_destroy_buffer( s_gfx.icosphereVbuf ); + sg_destroy_pipeline( s_gfx.shadowGeomPipelineMirror ); + sg_destroy_pipeline( s_gfx.shadowGeomPipeline ); + sg_destroy_shader( s_gfx.shadowGeomShader ); + sg_destroy_pipeline( s_gfx.shadowCubePipeline ); + sg_destroy_shader( s_gfx.shadowCubeShader ); + ShutdownShadows(); + sg_destroy_pipeline( s_gfx.geomPipelineXp ); + sg_destroy_pipeline( s_gfx.geomPipelineMirror ); + sg_destroy_pipeline( s_gfx.geomPipeline ); + sg_destroy_shader( s_gfx.geomShader ); + DestroyMeshRegistry(); + sg_destroy_pipeline( s_gfx.capsulePipelineXp ); + sg_destroy_view( s_gfx.capsuleInstViewXp ); + sg_destroy_buffer( s_gfx.capsuleInstBufXp ); + sg_destroy_pipeline( s_gfx.capsulePipeline ); + sg_destroy_shader( s_gfx.capsuleShader ); + sg_destroy_view( s_gfx.capsuleInstView ); + sg_destroy_buffer( s_gfx.capsuleInstBuf ); + sg_destroy_pipeline( s_gfx.spherePipelineXp ); + sg_destroy_view( s_gfx.sphereInstViewXp ); + sg_destroy_buffer( s_gfx.sphereInstBufXp ); + sg_destroy_pipeline( s_gfx.spherePipeline ); + sg_destroy_shader( s_gfx.sphereShader ); + sg_destroy_view( s_gfx.sphereInstView ); + sg_destroy_buffer( s_gfx.sphereInstBuf ); + sg_destroy_pipeline( s_gfx.cubePipelineXp ); + sg_destroy_view( s_gfx.cubeInstViewXp ); + sg_destroy_buffer( s_gfx.cubeInstBufXp ); + sg_destroy_pipeline( s_gfx.cubePipeline ); + sg_destroy_shader( s_gfx.cubeShader ); + sg_destroy_view( s_gfx.cubeInstView ); + sg_destroy_buffer( s_gfx.cubeInstBuf ); + sg_destroy_buffer( s_gfx.ibuf ); + sg_destroy_buffer( s_gfx.vbuf ); + sg_shutdown(); + ArenaShutdown( &s_gfx.cubeArena ); + ArenaShutdown( &s_gfx.sphereArena ); + ArenaShutdown( &s_gfx.capsuleArena ); + ArenaShutdown( &s_gfx.cubeArenaXp ); + ArenaShutdown( &s_gfx.sphereArenaXp ); + ArenaShutdown( &s_gfx.capsuleArenaXp ); + s_gfx.cubeBase = NULL; + s_gfx.cubeCount = 0; + s_gfx.sphereBase = NULL; + s_gfx.sphereCount = 0; + s_gfx.capsuleBase = NULL; + s_gfx.capsuleCount = 0; + s_gfx.cubeBaseXp = NULL; + s_gfx.cubeCountXp = 0; + s_gfx.sphereBaseXp = NULL; + s_gfx.sphereCountXp = 0; + s_gfx.capsuleBaseXp = NULL; + s_gfx.capsuleCountXp = 0; +} + +int GetRenderErrorCount( void ) +{ + return s_gfx.errorCount; +} + +void ResetFrameArena( void ) +{ + ArenaReset( &s_gfx.cubeArena ); + ArenaReset( &s_gfx.sphereArena ); + ArenaReset( &s_gfx.capsuleArena ); + ArenaReset( &s_gfx.cubeArenaXp ); + ArenaReset( &s_gfx.sphereArenaXp ); + ArenaReset( &s_gfx.capsuleArenaXp ); + s_gfx.cubeBase = NULL; + s_gfx.cubeCount = 0; + s_gfx.sphereBase = NULL; + s_gfx.sphereCount = 0; + s_gfx.capsuleBase = NULL; + s_gfx.capsuleCount = 0; + s_gfx.cubeBaseXp = NULL; + s_gfx.cubeCountXp = 0; + s_gfx.sphereBaseXp = NULL; + s_gfx.sphereCountXp = 0; + s_gfx.capsuleBaseXp = NULL; + s_gfx.capsuleCountXp = 0; + ResetFrameForMeshes(); + OverlayResetFrame(); + ResetTextArena(); + HighlightMaskBeginFrame(); +} + +static void PackTransformRows( const Mat4* transform, Vec4* row0, Vec4* row1, Vec4* row2 ) +{ + row0->x = transform->cx.x; + row0->y = transform->cy.x; + row0->z = transform->cz.x; + row0->w = transform->cw.x; + row1->x = transform->cx.y; + row1->y = transform->cy.y; + row1->z = transform->cz.y; + row1->w = transform->cw.y; + row2->x = transform->cx.z; + row2->y = transform->cy.z; + row2->z = transform->cz.z; + row2->w = transform->cw.z; +} + +static inline bool IsTransparent( Vec4 baseColor ) +{ + return baseColor.w < 0.99f; +} + +// Pack the shadow-cast flag into material.z. The shader never reads this +// (shape FSes only read material.x/.y for metallic/roughness), but the C +// side reads it back during transparent shadow caster filtering. Using a +// reserved slot in the existing instance struct keeps the GPU layout +// unchanged. +static inline float PackShadowCast( TransparentShadowCast s ) +{ + return ( s == TRANSPARENT_SHADOW_FULL ) ? 1.0f : 0.0f; +} + +void AppendCube( b3Transform transform, b3Vec3 scale, Vec4 baseColor, float metallic, float roughness, + TransparentShadowCast shadowCast ) +{ + bool transparent = IsTransparent( baseColor ); + size_t* count = transparent ? &s_gfx.cubeCountXp : &s_gfx.cubeCount; + cube_instance_t** base = transparent ? &s_gfx.cubeBaseXp : &s_gfx.cubeBase; + Arena* arena = transparent ? &s_gfx.cubeArenaXp : &s_gfx.cubeArena; + size_t capacity = transparent ? TRANSPARENT_SHAPE_CAPACITY : SHAPE_CAPACITY; + if ( *count >= capacity ) + { + fprintf( stderr, "cube%s overflow: dropping (cap=%zu)\n", transparent ? "(xp)" : "", capacity ); + return; + } + cube_instance_t* inst = ArenaAlloc( arena, sizeof( cube_instance_t ), _Alignof( cube_instance_t ) ); + if ( inst == NULL ) + { + return; + } + if ( *count == 0 ) + { + *base = inst; + } + *count += 1; + + Mat4 m = MakeMat4FromTransform( transform, scale ); + PackTransformRows( &m, &inst->xform_row0, &inst->xform_row1, &inst->xform_row2 ); + inst->base_color = baseColor; + inst->material.x = metallic; + inst->material.y = roughness; + inst->material.z = PackShadowCast( shadowCast ); + inst->material.w = 0.0f; +} + +void AppendSphere( b3Transform transform, float radius, Vec4 baseColor, float metallic, float roughness, + TransparentShadowCast shadowCast ) +{ + bool transparent = IsTransparent( baseColor ); + size_t* count = transparent ? &s_gfx.sphereCountXp : &s_gfx.sphereCount; + sphere_instance_t** base = transparent ? &s_gfx.sphereBaseXp : &s_gfx.sphereBase; + Arena* arena = transparent ? &s_gfx.sphereArenaXp : &s_gfx.sphereArena; + size_t capacity = transparent ? TRANSPARENT_SHAPE_CAPACITY : SHAPE_CAPACITY; + if ( *count >= capacity ) + { + fprintf( stderr, "sphere%s overflow: dropping (cap=%zu)\n", transparent ? "(xp)" : "", capacity ); + return; + } + + sphere_instance_t* inst = ArenaAlloc( arena, sizeof( sphere_instance_t ), _Alignof( sphere_instance_t ) ); + if ( inst == NULL ) + { + return; + } + if ( *count == 0 ) + { + *base = inst; + } + *count += 1; + + Mat4 m = MakeMat4FromTransform( transform, b3Vec3_one ); + PackTransformRows( &m, &inst->xform_row0, &inst->xform_row1, &inst->xform_row2 ); + inst->base_color = baseColor; + inst->params.x = radius; + inst->params.y = 0.0f; + inst->params.z = 0.0f; + inst->params.w = 0.0f; + inst->material.x = metallic; + inst->material.y = roughness; + inst->material.z = PackShadowCast( shadowCast ); + inst->material.w = 0.0f; +} + +void AppendCapsule( b3Transform transform, float halfLength, float radius, Vec4 baseColor, float metallic, float roughness, + TransparentShadowCast shadowCast ) +{ + bool transparent = IsTransparent( baseColor ); + size_t* count = transparent ? &s_gfx.capsuleCountXp : &s_gfx.capsuleCount; + capsule_instance_t** base = transparent ? &s_gfx.capsuleBaseXp : &s_gfx.capsuleBase; + Arena* arena = transparent ? &s_gfx.capsuleArenaXp : &s_gfx.capsuleArena; + size_t capacity = transparent ? TRANSPARENT_SHAPE_CAPACITY : SHAPE_CAPACITY; + if ( *count >= capacity ) + { + fprintf( stderr, "[gfx/error] capsule%s overflow: dropping (cap=%zu)\n", transparent ? "(xp)" : "", capacity ); + return; + } + capsule_instance_t* inst = ArenaAlloc( arena, sizeof( capsule_instance_t ), _Alignof( capsule_instance_t ) ); + if ( inst == NULL ) + { + return; + } + if ( *count == 0 ) + { + *base = inst; + } + *count += 1; + + Mat4 m = MakeMat4FromTransform( transform, b3Vec3_one ); + PackTransformRows( &m, &inst->xform_row0, &inst->xform_row1, &inst->xform_row2 ); + inst->base_color = baseColor; + inst->params.x = halfLength; + inst->params.y = radius; + inst->params.z = 0.0f; + inst->params.w = 0.0f; + inst->material.x = metallic; + inst->material.y = roughness; + inst->material.z = PackShadowCast( shadowCast ); + inst->material.w = 0.0f; +} diff --git a/samples/gfx/renderer.h b/samples/gfx/renderer.h new file mode 100644 index 0000000..6af60d4 --- /dev/null +++ b/samples/gfx/renderer.h @@ -0,0 +1,179 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +#pragma once + +#include "gfx/draw_overlay.h" +#include "gfx/edges.h" +#include "gfx/highlight_outline.h" +#include "gfx/utility.h" +#include "sokol_gfx.h" + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef struct FrameInput +{ + Mat4 view; + Mat4 viewInv; + Mat4 proj; + Mat4 projInv; + b3Vec3 cameraPosition; + + // seconds since InitRenderer + float time; + + // 0 = lit, 1 = view-space depth grayscale, 2 = CSM cascade index, + // 3 = view-space normal (RGB, [-1,1] mapped to [0,1]), + // 4 = raw GTAO ambient-occlusion (grayscale, post-upsample). + int debugMode; + + // cascade passes still clear to depth=1.0 + bool disableShadows; + + // depth pre-pass + trace + upsample skipped + // the full-res AO target is cleared to 1.0 (no occlusion) instead + bool disableAmbientOcclusion; +} FrameInput; + +// Directional light. The renderer owns one. Defaults are set in InitRenderer: +// dirToSun normalized from (0.5, 0.8, 0.4), color (1.0, 0.95, 0.85), +// ambient 0.10. Apps can override via SetSun before any draw call. +// dirToSun is normalized internally, caller need not pre-normalize. +typedef struct Sun +{ + b3Vec3 dirToSun; // world-space direction TO the sun + b3Vec3 color; // RGB intensity, multiplied by N.L for direct light + float ambient; // ambient strength added to direct light (0..1 typical) + float strength; // multiplies color [0,1] +} Sun; + +void InitRenderer( const sg_environment* env ); + +// Sun settings +void SetSun( Sun sun ); +Sun GetSun( void ); + +// Exposure stop applied by the AgX tone map pass (final image multiplied +// by pow(2, ev) before tone map). +void SetExposure( float ev ); +float GetExposure( void ); + +// AgX-look saturation applied by the tone map pass after the AgX sigmoid. +// 1.0 (default) is AgX's stock Standard look. >1.0 counteracts the +// path-to-white desaturation for punchier debug colors, <1.0 mutes them. +void SetToneMapSaturation( float saturation ); +float GetToneMapSaturation( void ); + +// Preetham turbidity, fed to both the sky pass and the IBL cube map rebuild. +void SetSkyTurbidity( float t ); +float GetSkyTurbidity( void ); + +// Toggle image-based lighting (IBL). Ambient comes from the procedural sky +// (diffuse SH + prefiltered specular). When disabled, lit shapes fall back +// to flat ambient, base_color * sun.ambient. Does not affect the sky background. +void SetIblEnabled( bool enabled ); +bool GetIblEnabled( void ); + +void SetEdgeOverlayParams( const EdgeOverlayParams* settings ); +EdgeOverlayParams GetEdgeOverlayParams( void ); + +// Body highlighting parameters +void SetHighlightParams( const HighlightParams* params ); +HighlightParams GetHighlightParams( void ); + +typedef struct +{ + int cubeCount; + int sphereCount; + int capsuleCount; + int cubeCountXp; + int sphereCountXp; + int capsuleCountXp; + int geomInstanceCount; // sum across all draw spans (opaque) + int geomInstanceCountXp; + int geomSpanCount; + int lineCount; + int pointCount; + int drawCallCount; // approximate, one per non-empty shape stream + spans + float frameTimeMs; // last RenderFrame cost +} RenderStats; + +RenderStats GetRenderStats( void ); + +// Last-frame camera latch. Populated at the top of RenderFrame / +// RenderFrameOffscreen so post-scene consumers (e.g. the ImGui-backed +// in-world text overlay) can project world positions to screen pixels using +// the same matrices the scene was rasterized with. viewportW/H are in pixels, +// matching the framebuffer the scene rendered to. +typedef struct CameraState +{ + Mat4 view; + Mat4 viewInv; + Mat4 proj; + Mat4 projInv; + int viewportW; + int viewportH; +} CameraState; +CameraState GetCameraState( void ); + +// Cube proxy buffer shared by sphere and capsule impostors +sg_buffer GetCubeProxyVertexBuffer( void ); +sg_buffer GetCubeProxyIndexBuffer( void ); +int GetCubeProxyIndexCount( void ); + +void RenderFrame( const sg_swapchain* swapChain, const FrameInput* frame ); + +// Render the scene into a caller-owned offscreen attachment set. The +// renderer is host-agnostic. This is the entry point a non-sokol_app +// host (e.g. a GLFW-based Box3D sample) would call. `attachments` describes +// the tonemap output target (single-sample, sRGB-encoded BGRA8/RGBA8), the +// renderer owns its own MSAA HDR scene target internally. `outputFormat` is +// the color format of attachments.colors[0], used to key the tonemap pipeline +// cache. width/height are the attachment image dimensions, fed into +// ub_frame.viewport. +void RenderFrameOffscreen( const sg_attachments* attachments, sg_pixel_format outputFormat, int width, int height, + const FrameInput* frame ); +void ShutdownRenderer( void ); + +int GetRenderErrorCount( void ); + +// Reset the per-frame arena and clear all instance counts. Safe to call +// every frame even if no submissions follow. +void ResetFrameArena( void ); + +// Append one cube instance into the frame arena. transform places and orients +// the cube. scale multiplies the unit cube proxy (which spans [-0.5, 0.5]), so +// scale is the cube's full side lengths. baseColor is linear RGBA (alpha < 1.0 +// routes to the transparent arena, alpha == 1.0 to the opaque arena). metallic +// and roughness feed the PBR BRDF (clamp to [0,1] at the call site). shadowCast +// picks whether this instance contributes to the shadow caster pass. Logs and +// drops on overflow. +void AppendCube( b3Transform transform, b3Vec3 scale, Vec4 baseColor, float metallic, float roughness, TransparentShadowCast shadowCast ); + +// Append one sphere instance. transform's rotation drives the surface pattern +// so spin is visible, its translation is the sphere center. radius is the only +// scale, given separately so the bounding-cube proxy matches the analytic +// silhouette. baseColor, metallic, roughness feed the PBR BRDF, the impostor +// pattern modulates baseColor before lighting. shadowCast as in AppendCube. +// Logs and drops on overflow. +void AppendSphere( b3Transform transform, float radius, Vec4 baseColor, float metallic, float roughness, + TransparentShadowCast shadowCast ); + +// Append one capsule instance. transform's rotation places the capsule's local +// +X axis (the long axis) in world space and drives the surface pattern so +// all three rotational axes are visible, its translation is the capsule +// center. halfLength is the distance from center to either cap center along +// local +X. radius is the cap radius. baseColor, metallic, roughness feed +// the PBR BRDF, the impostor pattern modulates baseColor before lighting. +// shadowCast as in AppendCube. Logs and drops on overflow. +void AppendCapsule( b3Transform transform, float halfLength, float radius, Vec4 baseColor, float metallic, float roughness, + TransparentShadowCast shadowCast ); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/samples/gfx/scene_target.c b/samples/gfx/scene_target.c new file mode 100644 index 0000000..703a752 --- /dev/null +++ b/samples/gfx/scene_target.c @@ -0,0 +1,220 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +#include "gfx/scene_target.h" + +#include + +#define SCENE_COLOR_FORMAT SG_PIXELFORMAT_RGBA16F + +// At SCENE_SAMPLE_COUNT > 1: colorMsaaImage holds the MSAA color, sokol_gfx +// auto-resolves into colorResolveImage at end-of-pass, and the tone map + +// transparent passes consume the resolve image. +// At SCENE_SAMPLE_COUNT == 1: colorResolveImage is unused (id = 0). The +// "MSAA" image is itself 1x and serves as both the scene_hdr color +// attachment AND the sampled scene color for downstream passes. The +// public sceneTargetResolve* accessors transparently point at it. +static struct +{ + sg_pixel_format depthFormat; + int width; + int height; + + sg_image colorMsaaImage; // sample_count = SCENE_SAMPLE_COUNT + sg_image depthMsaaImage; // sample_count = SCENE_SAMPLE_COUNT + sg_image colorResolveImage; // sample_count = 1, unused when SCENE_SAMPLE_COUNT == 1 + + sg_view colorMsaaView; // color_attachment over colorMsaaImage + sg_view depthMsaaView; // depth_stencil_attachment over depthMsaaImage + sg_view colorResolveAttachView; // resolve_attachment, unused when SCENE_SAMPLE_COUNT == 1 + sg_view colorResolveColorAttachView; // color_attachment over resolved scene color (transparent pass) + sg_view colorResolveSampleView; // texture view for sampling in tonemap + + bool ready; +} s_st; + +static void destroyTargets( void ) +{ + if ( s_st.colorResolveSampleView.id ) + { + sg_destroy_view( s_st.colorResolveSampleView ); + s_st.colorResolveSampleView.id = 0; + } + if ( s_st.colorResolveColorAttachView.id ) + { + sg_destroy_view( s_st.colorResolveColorAttachView ); + s_st.colorResolveColorAttachView.id = 0; + } + if ( s_st.colorResolveAttachView.id ) + { + sg_destroy_view( s_st.colorResolveAttachView ); + s_st.colorResolveAttachView.id = 0; + } + if ( s_st.depthMsaaView.id ) + { + sg_destroy_view( s_st.depthMsaaView ); + s_st.depthMsaaView.id = 0; + } + if ( s_st.colorMsaaView.id ) + { + sg_destroy_view( s_st.colorMsaaView ); + s_st.colorMsaaView.id = 0; + } + if ( s_st.colorResolveImage.id ) + { + sg_destroy_image( s_st.colorResolveImage ); + s_st.colorResolveImage.id = 0; + } + if ( s_st.depthMsaaImage.id ) + { + sg_destroy_image( s_st.depthMsaaImage ); + s_st.depthMsaaImage.id = 0; + } + if ( s_st.colorMsaaImage.id ) + { + sg_destroy_image( s_st.colorMsaaImage ); + s_st.colorMsaaImage.id = 0; + } +} + +void InitSceneTarget( const sg_environment* env ) +{ + s_st.depthFormat = env->defaults.depth_format; + s_st.width = 0; + s_st.height = 0; + s_st.ready = true; +} + +void ShutdownSceneTarget( void ) +{ + if ( !s_st.ready ) + { + return; + } + destroyTargets(); + s_st.width = 0; + s_st.height = 0; + s_st.ready = false; +} + +void ResizeSceneTarget( int width, int height ) +{ + if ( !s_st.ready || width <= 0 || height <= 0 ) + { + return; + } + if ( width == s_st.width && height == s_st.height && s_st.colorMsaaImage.id ) + { + return; + } + + destroyTargets(); + s_st.width = width; + s_st.height = height; + + sg_image_desc cdesc = { 0 }; + cdesc.usage.color_attachment = true; + cdesc.width = width; + cdesc.height = height; + cdesc.pixel_format = SCENE_COLOR_FORMAT; + cdesc.sample_count = SCENE_SAMPLE_COUNT; + cdesc.label = "scene_color_msaa"; + s_st.colorMsaaImage = sg_make_image( &cdesc ); + + sg_image_desc ddesc = { 0 }; + ddesc.usage.depth_stencil_attachment = true; + ddesc.width = width; + ddesc.height = height; + ddesc.pixel_format = s_st.depthFormat; + ddesc.sample_count = SCENE_SAMPLE_COUNT; + ddesc.label = "scene_depth_msaa"; + s_st.depthMsaaImage = sg_make_image( &ddesc ); + + if ( SCENE_SAMPLE_COUNT > 1 ) + { + sg_image_desc rdesc = { 0 }; + rdesc.usage.resolve_attachment = true; + // Also bind as a regular color_attachment for the transparent pass + // that runs after the opaque MSAA pass has resolved. + rdesc.usage.color_attachment = true; + rdesc.width = width; + rdesc.height = height; + rdesc.pixel_format = SCENE_COLOR_FORMAT; + rdesc.sample_count = 1; + rdesc.label = "scene_color_resolve"; + s_st.colorResolveImage = sg_make_image( &rdesc ); + } + + sg_view_desc cmvdesc = { 0 }; + cmvdesc.color_attachment.image = s_st.colorMsaaImage; + cmvdesc.label = "scene_color_msaa_attach"; + s_st.colorMsaaView = sg_make_view( &cmvdesc ); + + sg_view_desc dmvdesc = { 0 }; + dmvdesc.depth_stencil_attachment.image = s_st.depthMsaaImage; + dmvdesc.label = "scene_depth_msaa_attach"; + s_st.depthMsaaView = sg_make_view( &dmvdesc ); + + if ( SCENE_SAMPLE_COUNT > 1 ) + { + sg_view_desc cravdesc = { 0 }; + cravdesc.resolve_attachment.image = s_st.colorResolveImage; + cravdesc.label = "scene_color_resolve_attach"; + s_st.colorResolveAttachView = sg_make_view( &cravdesc ); + + sg_view_desc crcadesc = { 0 }; + crcadesc.color_attachment.image = s_st.colorResolveImage; + crcadesc.label = "scene_color_resolve_color_attach"; + s_st.colorResolveColorAttachView = sg_make_view( &crcadesc ); + + sg_view_desc crsvdesc = { 0 }; + crsvdesc.texture.image = s_st.colorResolveImage; + crsvdesc.label = "scene_color_resolve_sample"; + s_st.colorResolveSampleView = sg_make_view( &crsvdesc ); + } + else + { + // 1x: there is no resolve. The scene color image IS the 1x image + // the transparent pass and tonemap want. Reuse it via the same + // public accessors so callers stay backend-agnostic. + sg_view_desc crcadesc = { 0 }; + crcadesc.color_attachment.image = s_st.colorMsaaImage; + crcadesc.label = "scene_color_attach_1x"; + s_st.colorResolveColorAttachView = sg_make_view( &crcadesc ); + + sg_view_desc crsvdesc = { 0 }; + crsvdesc.texture.image = s_st.colorMsaaImage; + crsvdesc.label = "scene_color_sample_1x"; + s_st.colorResolveSampleView = sg_make_view( &crsvdesc ); + } +} + +sg_attachments GetSceneTargetAttachments( void ) +{ + sg_attachments a = { 0 }; + a.colors[0] = s_st.colorMsaaView; + // resolves[0] paired with a 1x color attachment fails sokol_gfx + // validation. At SCENE_SAMPLE_COUNT == 1 the colorMsaaView is itself + // the single-sample target, no resolve step needed. + if ( SCENE_SAMPLE_COUNT > 1 ) + { + a.resolves[0] = s_st.colorResolveAttachView; + } + a.depth_stencil = s_st.depthMsaaView; + return a; +} + +sg_view GetSceneTargetResolveSampleView( void ) +{ + return s_st.colorResolveSampleView; +} + +sg_view GetSceneTargetResolveColorAttachView( void ) +{ + return s_st.colorResolveColorAttachView; +} + +sg_pixel_format GetSceneTargetDepthFormat( void ) +{ + return s_st.depthFormat; +} diff --git a/samples/gfx/scene_target.h b/samples/gfx/scene_target.h new file mode 100644 index 0000000..16d266c --- /dev/null +++ b/samples/gfx/scene_target.h @@ -0,0 +1,69 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// HDR scene target. +// +// Renderer-owned 4x MSAA color + matching MSAA depth + single-sample +// resolve color, all sized to the current frame's render width/height. +// The opaque-scene pass writes into the MSAA color (with hardware resolve +// into the resolve image at end-of-pass), the tonemap pass samples the +// resolve image and writes the final swapchain/test target. +// +// Color format is fixed at RGBA16F across all backends, renderable + +// filterable + MSAA-resolvable on D3D11, Metal, and GL 4.5 core. Alpha is +// kept (vs. R11G11B10F) because the transparent pass uses it for +// sorted-alpha transparency. +// +// Depth format mirrors env.defaults.depth_format so the shape pipelines +// (depth.pixel_format = env->defaults.depth_format) remain compatible. +// +// Per-frame sizing: RenderFrame calls ResizeSceneTarget(W,H) before +// opening the lit pass. Recreates on size change, no-op when stable. + +#pragma once + +#include "sokol_gfx.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +// MSAA sample count for the scene_hdr pass. Every pipeline that targets +// scene_hdr (lit shapes in renderer.c, sky in sky.c, MSAA edge overlay in +// edges.c) must declare a matching pipeline sample_count, so they all +// reference this constant. Valid values: 1, 2, 4, 8. At 1, the resolve +// attachment is omitted (sokol_gfx rejects a resolve paired with a 1x +// color attachment) and the scene color image is sampled directly by the +// tone map pass, the transparent pass binds it as a regular color +// attachment with LOAD. Change here, rebuild, re-run. +#define SCENE_SAMPLE_COUNT 4 + +void InitSceneTarget( const sg_environment* env ); +void ShutdownSceneTarget( void ); + +void ResizeSceneTarget( int width, int height ); + +// Attachment set the opaque-scene pass binds: colors[0] = MSAA color view, +// resolves[0] = single-sample resolve view, depth_stencil = MSAA depth view. +sg_attachments GetSceneTargetAttachments( void ); + +// Texture-view over the single-sample resolved color image. The tone map +// pass samples this. +sg_view GetSceneTargetResolveSampleView( void ); + +// Color-attachment view over the single-sample resolved image, for the +// transparent pass that runs after the opaque MSAA pass has resolved. +// The transparent pass binds this with LOADACTION_LOAD so it blends over +// the resolved opaque scene rather than overwriting it. +sg_view GetSceneTargetResolveColorAttachView( void ); + +// MSAA depth-attachment format used by the scene target. Mirrors the +// env.defaults.depth_format passed to sceneTargetInit, surfaced for pass +// modules (e.g. the edge overlay) that want to add a pipeline state +// matching the MSAA scene attachments without re-querying the env. +sg_pixel_format GetSceneTargetDepthFormat( void ); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/samples/gfx/shadow.c b/samples/gfx/shadow.c new file mode 100644 index 0000000..3e2b161 --- /dev/null +++ b/samples/gfx/shadow.c @@ -0,0 +1,350 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +#include "gfx/shadow.h" + +#include +#include +#include + +// Cascade fitting parameters. SHADOW_SPLIT_NEAR and the default far +// (SHADOW_SPLIT_FAR, in shadow.h) are *view-space* distances from the camera +// (positive). CSM quality at distance falls off fast, so cascades focus on +// near content. +// +// PSSM_LAMBDA blends the uniform split scheme (each cascade covers an +// equal slice of view-space distance) and the logarithmic scheme (each +// cascade covers an equal multiplicative range). 0 = pure uniform, +// 1 = pure log. 0.5 is the sweet spot at the default range. The blend is +// pushed toward log up to PSSM_LAMBDA_MAX as the range widens, otherwise a +// large far would balloon the near cascade and coarsen close-up shadows. +// +// CASTER_MARGIN_M expands the orthographic light frustum's near edge +// toward the sun so casters above the camera frustum slice (e.g. the +// building roof at y=3 when the slice itself only reaches y=1) still cast +// onto receivers inside the slice. +#define SHADOW_SPLIT_NEAR 0.1f +#define PSSM_LAMBDA 0.5f +#define PSSM_LAMBDA_MAX 0.9f +#define CASTER_MARGIN_M 50.0f + +static struct +{ + b3Vec3 sunDir; // world-space dir TO sun, normalized + float splitNear; // PSSM split range near (positive view-Z) + float splitFar; // PSSM split range far (positive view-Z) + float splitLambda; // uniform/log split blend, widens with range + sg_image depthArray; // D32F, cascade layers + sg_view cascadeAttachmentViews[SHADOW_CASCADE_COUNT]; // depth-stencil view per cascade + sg_view sampleView; // full-array texture-sample view + sg_sampler sampler; // comparison sampler (LESS_EQUAL, linear PCF) + Mat4 cascadeMatrices[SHADOW_CASCADE_COUNT]; // light-space view-proj per cascade + float cascadeFarViewZ[SHADOW_CASCADE_COUNT]; // far end (positive view-Z) per cascade + bool inPass; // safety against unbalanced begin/end +} s_shadow; + +// PSSM split scheme: blend uniform and logarithmic. Returns the *positive* +// view-space distance at the boundary of cascade `i` (i in [0..N], where +// split[0] = near and split[N] = far). +static inline float ComputeSplitDistance( int i, int cascadeCount, float nearZ, float farZ ) +{ + const float fi = (float)i / (float)cascadeCount; + const float u = nearZ + ( farZ - nearZ ) * fi; + const float l = nearZ * powf( farZ / nearZ, fi ); + return s_shadow.splitLambda * l + ( 1.0f - s_shadow.splitLambda ) * u; +} + +// Push the uniform/log blend toward log as the split range widens, so the near +// cascade stays tight when far is large. Anchored at the default range so the +// reference scenes keep the 0.5 sweet spot. +static inline float SplitLambdaForRange( float nearZ, float farZ ) +{ + float decades = log10f( ( farZ / nearZ ) / ( SHADOW_SPLIT_FAR / SHADOW_SPLIT_NEAR ) ); + return b3ClampFloat( PSSM_LAMBDA + 0.4f * decades, PSSM_LAMBDA, PSSM_LAMBDA_MAX ); +} + +// Fill cornersOut with the 8 world-space corners of the camera frustum +// slice between view-space distances nearZ and farZ (both positive, the +// camera looks down its own -Z axis in view space). +// +// Camera basis comes straight from `viewInv` (the camera's world matrix +// produced by mat4ViewAndInverse): column 0 is right, column 1 is up, +// column 2 is back (i.e., -forward), column 3 is eye, no inversion. +// FovY and aspect are read from the projection matrix: mat4Perspective +// puts proj[1][1] = 1/tan(fovY/2) and proj[0][0] = proj[1][1] / aspect. +static void FrustumSliceCornersWorld( const Mat4* viewInv, const Mat4* proj, float nearZ, float farZ, b3Vec3 cornersOut[8] ) +{ + const b3Vec3 eye = { viewInv->cw.x, viewInv->cw.y, viewInv->cw.z }; + const b3Vec3 right = { viewInv->cx.x, viewInv->cx.y, viewInv->cx.z }; + const b3Vec3 up = { viewInv->cy.x, viewInv->cy.y, viewInv->cy.z }; + const b3Vec3 forward = { -viewInv->cz.x, -viewInv->cz.y, -viewInv->cz.z }; + + const float tanHalfFovY = ( proj->cy.y != 0.0f ) ? ( 1.0f / proj->cy.y ) : 1.0f; + const float aspect = ( proj->cx.x != 0.0f ) ? ( proj->cy.y / proj->cx.x ) : 1.0f; + + const float distances[2] = { nearZ, farZ }; + for ( int s = 0; s < 2; ++s ) + { + const float d = distances[s]; + const float h = d * tanHalfFovY; + const float w = h * aspect; + const b3Vec3 center = b3MulAdd( eye, d, forward ); + for ( int j = 0; j < 4; ++j ) + { + const float sx = ( j & 1 ) ? +w : -w; + const float sy = ( j & 2 ) ? +h : -h; + b3Vec3 c = b3MulAdd( center, sx, right ); + c = b3MulAdd( c, sy, up ); + cornersOut[s * 4 + j] = c; + } + } +} + +// Fit one cascade's light-space view-projection matrix to the camera +// frustum slice [nearZ, farZ] for the configured sun direction. +// +// The slice is bounded by a *world-space sphere* (centroid + max radius +// from centroid to any slice corner). The sphere is rotation-invariant. +// Rotating the camera around its eye doesn't move it, which is the key +// property that lets the texel-snap stabilization avoid swimming edges. +// +// Light view: orthonormal frame whose -Z axis points toward the sun. +// Light proj: orthographic, sized to enclose the sphere. The near plane +// is pushed back along +sun by CASTER_MARGIN_M so casters between the +// slice and the sun are not clipped. +// +// Texel-snap: after the unsnapped lightVP is built, transform the slice +// center through it to clip space, round the resulting clip-space xy to +// the nearest texel grid step, and apply the rounding delta as a +// post-translation. This pins the cascade to a fixed grid in light +// space, small camera motions no longer cause the shadow texels to +// drift relative to the casters. +static Mat4 FitCascade( const Mat4* viewInv, const Mat4* proj, b3Vec3 dirToSun, float nearZ, float farZ ) +{ + b3Vec3 corners[8]; + FrustumSliceCornersWorld( viewInv, proj, nearZ, farZ, corners ); + + b3Vec3 center = b3Vec3_zero; + for ( int i = 0; i < 8; ++i ) + { + center = b3Add( center, corners[i] ); + } + center = b3MulSV( 1.0f / 8.0f, center ); + + float radius = 0.0f; + for ( int i = 0; i < 8; ++i ) + { + const b3Vec3 d = b3Sub( corners[i], center ); + const float r = sqrtf( d.x * d.x + d.y * d.y + d.z * d.z ); + if ( r > radius ) + { + radius = r; + } + } + if ( radius < 0.01f ) + { + radius = 0.01f; + } + + // Avoid a degenerate up vector when the sun is straight up/down. + b3Vec3 up = b3Vec3_axisY; + if ( fabsf( dirToSun.y ) > 0.999f ) + { + up = b3Vec3_axisZ; + } + + // Place the light eye behind the sphere along +sun. Far clip extends + // past the sphere's back face. Near clip pulls forward by + // CASTER_MARGIN_M to admit casters above the slice. + const b3Vec3 eyeWorld = b3MulAdd( center, radius + CASTER_MARGIN_M, dirToSun ); + const Mat4 lightView = MakeLookAt( eyeWorld, center, up ); + const Mat4 lightProj = MakeOrthographic( -radius, radius, -radius, radius, 0.0f, 2.0f * radius + CASTER_MARGIN_M ); + Mat4 lightVP = MulMM4( lightProj, lightView ); + + // Texel-snap stabilization. Transform the sphere center through the + // unsnapped lightVP. Project to texel coords, round, convert the + // delta back to clip space, and add as a post-translation. + const Vec4 centerClip = MulMV4( lightVP, MakeVec4( center.x, center.y, center.z, 1.0f ) ); + const float halfRes = (float)SHADOW_RESOLUTION * 0.5f; + const float texX = centerClip.x * halfRes; + const float texY = centerClip.y * halfRes; + const float dx = ( roundf( texX ) - texX ) / halfRes; + const float dy = ( roundf( texY ) - texY ) / halfRes; + + Mat4 snapMat = MakeIdentity(); + snapMat.cw.x = dx; + snapMat.cw.y = dy; + return MulMM4( snapMat, lightVP ); +} + +void InitShadows( void ) +{ + s_shadow.sunDir = b3Normalize( (b3Vec3){ 0.5f, 0.8f, 0.4f } ); + s_shadow.splitNear = SHADOW_SPLIT_NEAR; + s_shadow.splitFar = SHADOW_SPLIT_FAR; + s_shadow.splitLambda = SplitLambdaForRange( s_shadow.splitNear, s_shadow.splitFar ); + + sg_image_desc desc = { 0 }; + desc.type = SG_IMAGETYPE_ARRAY; + desc.usage.depth_stencil_attachment = true; + desc.width = SHADOW_RESOLUTION; + desc.height = SHADOW_RESOLUTION; + desc.num_slices = SHADOW_CASCADE_COUNT; + desc.pixel_format = SG_PIXELFORMAT_DEPTH; + desc.sample_count = 1; + desc.label = "shadow_depth_array"; + s_shadow.depthArray = sg_make_image( &desc ); + + // Per-cascade depth attachment view (slice = cascade index). + for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i ) + { + sg_view_desc vdesc = { 0 }; + vdesc.depth_stencil_attachment.image = s_shadow.depthArray; + vdesc.depth_stencil_attachment.slice = i; + vdesc.label = "shadow_cascade_attachment"; + s_shadow.cascadeAttachmentViews[i] = sg_make_view( &vdesc ); + } + + // Whole-array texture sample view: layer index becomes the .z arg in + // the shader's sampler2DArrayShadow lookup. Explicitly range over all + // cascade slices so the view binds the full array + // (careful: sokol's "count = 0 means all remaining" default). + sg_view_desc svdesc = { 0 }; + svdesc.texture.image = s_shadow.depthArray; + svdesc.texture.slices.base = 0; + svdesc.texture.slices.count = SHADOW_CASCADE_COUNT; + svdesc.label = "shadow_sample_view"; + s_shadow.sampleView = sg_make_view( &svdesc ); + + // Comparison sampler: LESS_EQUAL means the test returns 1.0 (lit) when + // the receiver's reference depth is <= the stored depth, i.e., the + // receiver is the closest surface to the light. Linear PCF: each + // texture call returns a 2x2 weighted compare-result mix. + sg_sampler_desc sdesc = { 0 }; + sdesc.min_filter = SG_FILTER_LINEAR; + sdesc.mag_filter = SG_FILTER_LINEAR; + sdesc.mipmap_filter = SG_FILTER_NEAREST; + sdesc.wrap_u = SG_WRAP_CLAMP_TO_EDGE; + sdesc.wrap_v = SG_WRAP_CLAMP_TO_EDGE; + sdesc.wrap_w = SG_WRAP_CLAMP_TO_EDGE; + sdesc.compare = SG_COMPAREFUNC_LESS_EQUAL; + sdesc.label = "shadow_compare_sampler"; + s_shadow.sampler = sg_make_sampler( &sdesc ); + + s_shadow.inPass = false; +} + +void ShutdownShadows( void ) +{ + sg_destroy_sampler( s_shadow.sampler ); + sg_destroy_view( s_shadow.sampleView ); + for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i ) + { + sg_destroy_view( s_shadow.cascadeAttachmentViews[i] ); + } + sg_destroy_image( s_shadow.depthArray ); +} + +void SetShadowSplits( float nearViewZ, float farViewZ ) +{ + if ( nearViewZ <= 0.0f || farViewZ <= nearViewZ ) + { + // Restore defaults on (0, 0) or any nonsense input. + nearViewZ = SHADOW_SPLIT_NEAR; + farViewZ = SHADOW_SPLIT_FAR; + } + + s_shadow.splitNear = nearViewZ; + s_shadow.splitFar = farViewZ; + s_shadow.splitLambda = SplitLambdaForRange( nearViewZ, farViewZ ); +} + +void SetShadowSplitFar( float farViewZ ) +{ + SetShadowSplits( s_shadow.splitNear, farViewZ ); +} + +void SetShadowSunDir( b3Vec3 dirToSun ) +{ + const float lenSq = dirToSun.x * dirToSun.x + dirToSun.y * dirToSun.y + dirToSun.z * dirToSun.z; + if ( lenSq > 0.0f ) + { + s_shadow.sunDir = b3Normalize( dirToSun ); + } +} + +void FitShadows( const Mat4* viewInv, const Mat4* proj ) +{ + // PSSM splits across [splitNear, splitFar]. split[0] = near, + // split[N] = far. Cascade i covers (split[i], split[i+1]]. + float splits[SHADOW_CASCADE_COUNT + 1]; + for ( int i = 0; i <= SHADOW_CASCADE_COUNT; ++i ) + { + splits[i] = ComputeSplitDistance( i, SHADOW_CASCADE_COUNT, s_shadow.splitNear, s_shadow.splitFar ); + } + + for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i ) + { + s_shadow.cascadeMatrices[i] = FitCascade( viewInv, proj, s_shadow.sunDir, splits[i], splits[i + 1] ); + s_shadow.cascadeFarViewZ[i] = splits[i + 1]; + } +} + +void BeginShadowPass( int cascade ) +{ + if ( cascade < 0 || cascade >= SHADOW_CASCADE_COUNT ) + { + fprintf( stderr, "cascade index out of range: %d\n", cascade ); + return; + } + sg_pass pass = { 0 }; + pass.action.depth.load_action = SG_LOADACTION_CLEAR; + pass.action.depth.clear_value = 1.0f; // standard Z far + pass.action.depth.store_action = SG_STOREACTION_STORE; + pass.attachments.depth_stencil = s_shadow.cascadeAttachmentViews[cascade]; + sg_begin_pass( &pass ); + s_shadow.inPass = true; +} + +void EndShadowPass( void ) +{ + if ( !s_shadow.inPass ) + { + return; + } + sg_end_pass(); + s_shadow.inPass = false; +} + +Mat4 GetCascadeMatrix( int cascade ) +{ + if ( cascade < 0 || cascade >= SHADOW_CASCADE_COUNT ) + { + return MakeIdentity(); + } + return s_shadow.cascadeMatrices[cascade]; +} + +float GetCascadeFarViewZ( int cascade ) +{ + if ( cascade < 0 || cascade >= SHADOW_CASCADE_COUNT ) + { + return 0.0f; + } + return s_shadow.cascadeFarViewZ[cascade]; +} + +sg_view GetShadowSampleView( void ) +{ + return s_shadow.sampleView; +} + +sg_sampler GetShadowSampler( void ) +{ + return s_shadow.sampler; +} + +float GetShadowTexelSize( void ) +{ + return 1.0f / (float)SHADOW_RESOLUTION; +} diff --git a/samples/gfx/shadow.h b/samples/gfx/shadow.h new file mode 100644 index 0000000..829cbe3 --- /dev/null +++ b/samples/gfx/shadow.h @@ -0,0 +1,102 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Cascaded-shadow-map infrastructure. +// +// One depth array texture (D32F) holds all cascades, each cascade gets its +// own depth-only view used as the depth attachment for that cascade's +// shadow pass. A single comparison sampler (LESS_EQUAL with linear PCF) +// is shared by every lit shader that reads from the array. +// +// Light-space matrices and split distances are computed by FitShadows +// each frame from the camera frustum and the sun direction. +// +// Coordinate convention inside shadow space: +// - Standard Z (not reverse-Z): 0 at near, 1 at far. The shadow pass +// clears depth to 1.0, fragments closer to the light overwrite with +// smaller values, the sampler compares LESS_EQUAL to determine "this +// fragment is the closest one, so lit". +// - Right-handed orthographic projection, 0..1 clip-Z. +// +// Public surface: +// InitShadows / ShutdownShadows, lifecycle. +// SetShadowSunDir, store the direction the renderer will use when +// fitting cascades. +// FitShadows, recompute cascade matrices and split distances for a +// given camera frustum. +// BeginShadowPass / EndShadowPass, open/close the depth pass per cascade. +// GetShadowSampleView / GetShadowSampler, for lit pipelines to +// bind once and sample across all cascades. +// GetCascadeMatrix / GetCascadeFarViewZ, for lit +// shaders to transform world positions and select the right cascade. + +#pragma once + +#include "gfx/utility.h" +#include "sokol_gfx.h" + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +#define SHADOW_CASCADE_COUNT 3 +#define SHADOW_RESOLUTION 2048 + +// Default cascade far split, view-space distance from the camera. Scenes +// smaller than this keep the default range, larger ones widen it. +#define SHADOW_SPLIT_FAR 50.0f + +void InitShadows( void ); +void ShutdownShadows( void ); + +// Set the world-space direction TO the sun +void SetShadowSunDir( b3Vec3 dirToSun ); + +// Override the view-space distance range PSSM splits over. Defaults to +// (0.1, SHADOW_SPLIT_FAR), sufficient for the reference scenes but too short +// for larger ones. The split blend is derived from the range, so a wider far +// keeps the near cascade tight. Pass (0, 0) to restore defaults. +void SetShadowSplits( float nearViewZ, float farViewZ ); + +// Fit the cascade far split to a scene of this view-space depth, keeping the +// current near and recomputing the split blend. +void SetShadowSplitFar( float farViewZ ); + +// Recompute per-cascade light-space matrices and split distances for the +// camera frustum described by viewInv + proj. viewInv (the camera's world +// matrix) supplies eye + basis directly, so the slice-corner walk does no +// matrix inversion. proj supplies fovY + aspect via proj[1][1] / proj[0][0]. +// Cascade slices are fit to the camera frustum and snapped to texel +// boundaries to avoid swimming edges as the camera moves. +void FitShadows( const Mat4* viewInv, const Mat4* proj ); + +// Begin / end the depth-only render pass for a cascade. Bind this as +// the surrounding pass before issuing caster draws into the cascade. +void BeginShadowPass( int cascade ); +void EndShadowPass( void ); + +// Light-space view-proj matrix for a cascade. Lit shaders multiply a +// world-space position by this to get shadow-space coordinates. +Mat4 GetCascadeMatrix( int cascade ); + +// Far view-space Z (positive value, distance from camera) for the end +// cascade. Lit shaders compare a fragment's view-space depth against +// these to pick which cascade to sample. +float GetCascadeFarViewZ( int cascade ); + +// Bound by lit pipelines once for sampling across all cascades. The view +// is the depth array's full-array sampling view. Per-cascade selection +// happens inside the shader by passing `cascade` as the layer index. +sg_view GetShadowSampleView( void ); +sg_sampler GetShadowSampler( void ); + +// One-texel size in shadow space (1 / SHADOW_RESOLUTION). Lit shaders +// use this to size PCF taps and slope-scale bias. +float GetShadowTexelSize( void ); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/samples/gfx/sky.c b/samples/gfx/sky.c new file mode 100644 index 0000000..934bbf5 --- /dev/null +++ b/samples/gfx/sky.c @@ -0,0 +1,109 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +#include "gfx/sky.h" + +#include "gfx/scene_target.h" +#include "sky.glsl.h" + +// Below-horizon fade: the renderer feeds the FS a [0,1] weight derived from +// the sun's elevation, smoothly stepped between BELOW_HORIZON_FADE_START +// (~2 deg) and BELOW_HORIZON_FADE_END (~5 deg). Preetham diverges at and below +// the horizon, so we fade to zero there rather than render garbage. Values +// in radians via sin so we can compare against dirToSun.y directly. +#define BELOW_HORIZON_FADE_START_SIN 0.0349f // sin(2 deg) +#define BELOW_HORIZON_FADE_END_SIN 0.0872f // sin(5 deg) + +static struct +{ + sg_shader shader; + sg_pipeline pipeline; + bool ready; +} s_sky; + +void InitSky( const sg_environment* env ) +{ + s_sky.shader = sg_make_shader( sky_shader_desc( sg_query_backend() ) ); + + sg_pipeline_desc pdesc = { 0 }; + pdesc.shader = s_sky.shader; + // No vertex attributes, the VS pulls 3 fullscreen-triangle corners from + // gl_VertexIndex. Leaving layout.attrs zeroed tells sokol the pipeline + // has no input bindings (D3D11 builds an empty input layout). + // Color attachment is the HDR scene target (RGBA16F MSAA). + pdesc.colors[0].pixel_format = SG_PIXELFORMAT_RGBA16F; + pdesc.depth.pixel_format = env->defaults.depth_format; + // Reverse-Z: depth was cleared to 0 (far). Sky vertices sit at NDC z=0 + // (also far). GREATER_EQUAL passes against the cleared value on + // untouched pixels and fails on opaque pixels (whose z > 0 means + // they're closer than the far plane in reverse-Z). + pdesc.depth.compare = SG_COMPAREFUNC_GREATER_EQUAL; + pdesc.depth.write_enabled = false; + // No back-face winding to enforce, but matching the rest of the + // pipeline's CCW front face means the rasterizer's culling logic + // never sees a back face on the fullscreen triangle. + pdesc.cull_mode = SG_CULLMODE_NONE; + pdesc.face_winding = SG_FACEWINDING_CCW; + // Must match the scene_hdr MSAA color attachment's sample count. + pdesc.sample_count = SCENE_SAMPLE_COUNT; + pdesc.label = "sky_pipeline"; + s_sky.pipeline = sg_make_pipeline( &pdesc ); + + s_sky.ready = true; +} + +void ShutdownSky( void ) +{ + if ( !s_sky.ready ) + { + return; + } + sg_destroy_pipeline( s_sky.pipeline ); + sg_destroy_shader( s_sky.shader ); + s_sky.ready = false; +} + +float SkySunFadeWeight( b3Vec3 dirToSun ) +{ + // dirToSun is assumed unit-length. The rendering side renormalizes + // before calling. The fade reads dirToSun.y directly as sin(elevation). + float t = ( dirToSun.y - BELOW_HORIZON_FADE_START_SIN ) / ( BELOW_HORIZON_FADE_END_SIN - BELOW_HORIZON_FADE_START_SIN ); + t = ( t < 0.0f ) ? 0.0f : ( t > 1.0f ? 1.0f : t ); + return t * t * ( 3.0f - 2.0f * t ); +} + +void DrawSky( b3Vec3 dirToSun, float turbidity, b3Vec3 cameraPos, Mat4 invViewProj ) +{ + if ( !s_sky.ready ) + { + return; + } + + // Renormalize defensively. Caller is the renderer with sun.dirToSun + // already normalized, but the FS reads sun_dir_world.xyz expecting unit + // length and an undetected zero vector here would emit NaNs. + const float lenSq = dirToSun.x * dirToSun.x + dirToSun.y * dirToSun.y + dirToSun.z * dirToSun.z; + b3Vec3 sun = ( lenSq > 0.0f ) ? b3Normalize( dirToSun ) : b3Vec3_axisY; + + const float fade = SkySunFadeWeight( sun ); + + sky_ub_frame_t ub = { 0 }; + ub.inv_view_proj = invViewProj; + + sky_ub_pass_t up = { 0 }; + up.sun_dir_world = MakeVec4( sun.x, sun.y, sun.z, fade ); + up.sky_params = MakeVec4( turbidity, 0.0f, 0.0f, 0.0f ); + up.camera_pos = MakeVec4( cameraPos.x, cameraPos.y, cameraPos.z, 0.0f ); + + sg_apply_pipeline( s_sky.pipeline ); + + // Deliberately no sg_apply_bindings: the pipeline declares no vertex + // buffers, no textures, and no storage views, so its required_bindings + // mask is empty. Sokol's draw-time check is "applied == required". An + // entirely-empty sg_bindings actually FAILS validation + // (VALIDATE_ABND_EMPTY_BINDINGS, sokol_gfx.h:23591), so the only way + // to draw a bindings-free pipeline is to skip the call. + sg_apply_uniforms( UB_sky_ub_frame, &SG_RANGE( ub ) ); + sg_apply_uniforms( UB_sky_ub_pass, &SG_RANGE( up ) ); + sg_draw( 0, 3, 1 ); +} diff --git a/samples/gfx/sky.h b/samples/gfx/sky.h new file mode 100644 index 0000000..8e24f23 --- /dev/null +++ b/samples/gfx/sky.h @@ -0,0 +1,49 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Procedural sky +// +// Renders a Preetham analytic daylight skybox into the main lit pass after +// all opaque shapes. Uses a fullscreen triangle drawn at the reverse-Z far +// plane (NDC z = 0) with depth test GREATER_EQUAL and depth-write off, so +// pixels covered by opaque geometry pass through unchanged and untouched +// pixels (still at the cleared depth of 0) receive the sky. +// +// The sun direction is the renderer's single source of truth, the shadow +// caster, direct lighting, and sky all consume the same world-space vector +// (set via SetSun). Below-horizon fade is computed C-side and passed in +// alongside the direction so the FS doesn't need to know the threshold. + +#pragma once + +#include "gfx/utility.h" +#include "sokol_gfx.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +void InitSky( const sg_environment* env ); +void ShutdownSky( void ); + +// Below-horizon fade weight in [0, 1], 1 well above the horizon, 0 +// below it, smoothstep between sin(2 deg) and sin(5 deg). The IBL cubemap +// renderer reads this so its sky matches the backdrop exactly when the +// sun is near the horizon. dirToSun.y == sin(elevation) when normalized. +float SkySunFadeWeight( b3Vec3 dirToSun ); + +// Issue the sky draw. Call inside the main lit pass after all opaque +// shape draws. Parameters: +// dirToSun world-space direction TO the sun, renormalized internally, +// may be the same vector handed to SetSun. +// turbidity Preetham T (project spec = 2.2). +// cameraPos world-space camera position, the FS reconstructs view +// direction as (world_far_point - cameraPos). +// invViewProj inverse of proj * view for the current frame, the VS +// unprojects NDC corners through this to get world rays. +void DrawSky( b3Vec3 dirToSun, float turbidity, b3Vec3 cameraPos, Mat4 invViewProj ); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/samples/gfx/sokol_impl.c b/samples/gfx/sokol_impl.c new file mode 100644 index 0000000..35a5edb --- /dev/null +++ b/samples/gfx/sokol_impl.c @@ -0,0 +1,10 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Single-translation-unit build of sokol_gfx's implementation. +// Backend macro (SOKOL_D3D11 / SOKOL_METAL / SOKOL_GLCORE) is provided by +// the `sokol` INTERFACE target. On macOS this file is compiled as +// Objective-C with ARC. + +#define SOKOL_IMPL +#include "sokol_gfx.h" diff --git a/samples/gfx/text.c b/samples/gfx/text.c new file mode 100644 index 0000000..3bf0a9d --- /dev/null +++ b/samples/gfx/text.c @@ -0,0 +1,115 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +#include "gfx/text.h" + +#include +#include +#include +#include +#include +#include + +// Per-frame array of label entries. Cap and per-entry text length are sized +// for the highest-density label scene we expect (Box3D's body names + joint +// types + contact IDs on a busy demo). Bump if a real scene saturates. The +// text fits inline so an entry stays small and we don't need a second arena +// for the strings. +#define TEXT_CAPACITY 1024 +#define TEXT_BUFFER_SIZE 64 // 63 chars + NUL + +typedef struct TextSlot +{ + TextSpace space; + b3Vec3 worldPos; + int screenX; + int screenY; + Vec4 color; + char text[TEXT_BUFFER_SIZE]; +} TextSlot; + +static TextSlot s_slots[TEXT_CAPACITY]; +static TextEntry s_entries[TEXT_CAPACITY]; +static int s_count; + +void ResetTextArena( void ) +{ + s_count = 0; +} + +// Claim a slot and copy the text in, truncating at the cap boundary. Returns +// the slot or NULL on overflow. Caller fills the space-specific fields. +static TextSlot* AppendSlot( Vec4 color, const char* text ) +{ + if ( text == NULL ) + return NULL; + if ( s_count >= TEXT_CAPACITY ) + return NULL; + + TextSlot* slot = &s_slots[s_count]; + slot->color = color; + // strncpy intentionally, we want explicit NUL-termination at the cap + // boundary even if the source is longer. strncpy alone doesn't guarantee + // the terminator on truncation. The explicit write below does. + strncpy( slot->text, text, TEXT_BUFFER_SIZE - 1 ); + slot->text[TEXT_BUFFER_SIZE - 1] = '\0'; + return slot; +} + +static void PublishSlot( const TextSlot* slot ) +{ + s_entries[s_count].space = slot->space; + s_entries[s_count].worldPos = slot->worldPos; + s_entries[s_count].screenX = slot->screenX; + s_entries[s_count].screenY = slot->screenY; + s_entries[s_count].color = slot->color; + s_entries[s_count].text = slot->text; + s_count += 1; +} + +void DrawString( b3Vec3 worldPos, Vec4 color, const char* text ) +{ + TextSlot* slot = AppendSlot( color, text ); + if ( slot == NULL ) + return; + slot->space = TEXT_SPACE_WORLD; + slot->worldPos = worldPos; + slot->screenX = 0; + slot->screenY = 0; + PublishSlot( slot ); +} + +void DrawScreenString( int x, int y, Vec4 color, const char* text ) +{ + TextSlot* slot = AppendSlot( color, text ); + if ( slot == NULL ) + return; + slot->space = TEXT_SPACE_SCREEN; + slot->worldPos = b3Vec3_zero; + slot->screenX = x; + slot->screenY = y; + PublishSlot( slot ); +} + +void DrawScreenStringFormat( int x, int y, Vec4 color, const char* fmt, ... ) +{ + if ( fmt == NULL ) + return; + char buffer[TEXT_BUFFER_SIZE]; + va_list args; + va_start( args, fmt ); + vsnprintf( buffer, sizeof( buffer ), fmt, args ); + va_end( args ); + DrawScreenString( x, y, color, buffer ); +} + +int GetTextCount( void ) +{ + return s_count; +} + +const TextEntry* GetTextAt( int i ) +{ + assert( i >= 0 && i < s_count ); + return &s_entries[i]; +} diff --git a/samples/gfx/text.h b/samples/gfx/text.h new file mode 100644 index 0000000..636541d --- /dev/null +++ b/samples/gfx/text.h @@ -0,0 +1,84 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Text label storage, world space and screen space. +// +// Pure C so the box3d adapter (also C) can submit labels via DrawString, and +// the unit test for the projection helper can pull this in without ImGui. +// The renderer doesn't rasterize text itself: labels accumulate in a fixed +// per-frame array, ResetTextArena clears the array at the start of each +// frame (called from ResetFrameArena), and the GUI shell drains the +// array after the scene renders. World entries project to screen pixels +// with the last rendered camera, screen entries pass through their pixel +// position as-is, both emit via ImGui's background draw list. That means +// labels only appear when the app runs through StartUIFrame, +// RenderFrameOffscreen alone is not a label-rendering path. + +#pragma once + +#include "gfx/projection.h" +#include "gfx/utility.h" + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +// Whether an entry carries a world position to project or a screen pixel to +// use directly. +typedef enum TextSpace +{ + TEXT_SPACE_WORLD = 0, + TEXT_SPACE_SCREEN = 1, +} TextSpace; + +typedef struct TextEntry +{ + TextSpace space; + b3Vec3 worldPos; // valid when space == TEXT_SPACE_WORLD + int screenX; // framebuffer pixels, origin top-left, when space == TEXT_SPACE_SCREEN + int screenY; + Vec4 color; // linear RGBA, bytes pass through to ImGui as-is + const char* text; // points into the per-frame text arena, NUL-terminated +} TextEntry; + +// Submit a UTF-8 string at a world-space position. Text is copied into the +// per-frame text arena and truncated to fit (current cap: 63 chars + NUL). +// Color is linear RGBA. Logs and drops on overflow. +void DrawString( b3Vec3 worldPos, Vec4 color, const char* text ); + +// Submit a UTF-8 string at a screen-pixel position (origin top-left, Y down, +// framebuffer pixels). Same copy/truncation/overflow rules as DrawString. +void DrawScreenString( int x, int y, Vec4 color, const char* text ); +void DrawScreenStringFormat( int x, int y, Vec4 color, const char* fmt, ... ); + +// Iteration surface for the GUI shell. Pointers/strings are valid until +// the next ResetTextArena (called by ResetFrameArena, which the GUI shell +// invokes each frame). Caller is expected to honor 0 <= i < count. +int GetTextCount( void ); +const TextEntry* GetTextAt( int i ); + +// Wipe the per-frame text array. Called from ResetFrameArena. +void ResetTextArena( void ); + +// Resolve an entry to its screen-pixel position. Screen entries pass through; +// world entries project through view/proj for the given viewport. Returns +// false (leaving outputs untouched) when a world entry is off-frustum or +// behind the camera, matching ProjectWorldToScreen. +static inline bool ResolveTextScreenPos( const TextEntry* e, Mat4 view, Mat4 proj, int viewportW, int viewportH, + float* outScreenX, float* outScreenY ) +{ + if ( e->space == TEXT_SPACE_SCREEN ) + { + *outScreenX = (float)e->screenX; + *outScreenY = (float)e->screenY; + return true; + } + return ProjectWorldToScreen( view, proj, viewportW, viewportH, e->worldPos, outScreenX, outScreenY ); +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/samples/gfx/tone_map.c b/samples/gfx/tone_map.c new file mode 100644 index 0000000..e24ed4b --- /dev/null +++ b/samples/gfx/tone_map.c @@ -0,0 +1,137 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +#include "gfx/tone_map.h" + +#include "gfx/utility.h" +#include "tonemap.glsl.h" + +#include +#include + +// Two slots cover the only realistic divergence, the swapchain target +// (has depth attachment from sokol_app's default) and the offscreen test +// target (color only, no depth). Hitting this cap means a third +// color/depth pair showed up. Raise it (and probably ask why). +#define TONEMAP_MAX_PIPELINES 2 + +static struct +{ + sg_shader shader; + sg_sampler sampler; + struct + { + sg_pixel_format colorFormat; + sg_pixel_format depthFormat; + sg_pipeline pipeline; + } pipelines[TONEMAP_MAX_PIPELINES]; + int pipelineCount; + bool ready; +} s_tm; + +static sg_pipeline ensurePipeline( sg_pixel_format colorFormat, sg_pixel_format depthFormat ) +{ + for ( int i = 0; i < s_tm.pipelineCount; ++i ) + { + if ( s_tm.pipelines[i].colorFormat == colorFormat && s_tm.pipelines[i].depthFormat == depthFormat ) + { + return s_tm.pipelines[i].pipeline; + } + } + if ( s_tm.pipelineCount >= TONEMAP_MAX_PIPELINES ) + { + fprintf( stderr, "tonemap: pipeline cache exhausted (max %d format pairs)\n", TONEMAP_MAX_PIPELINES ); + sg_pipeline empty = { 0 }; + return empty; + } + + sg_pipeline_desc pdesc = { 0 }; + pdesc.shader = s_tm.shader; + pdesc.colors[0].pixel_format = colorFormat; + // color_count isn't inferred from a single non-NONE entry, has to be + // explicit (cf. MEMORY note on MRT color_count gotcha). + pdesc.color_count = 1; + // Depth format mirrors the target's depth attachment (or NONE) so + // sokol's pipeline-vs-attachment validation is happy. Write/compare + // are off either way, the tonemap is depth-blind. + pdesc.depth.pixel_format = depthFormat; + pdesc.depth.write_enabled = false; + pdesc.depth.compare = SG_COMPAREFUNC_ALWAYS; + pdesc.cull_mode = SG_CULLMODE_NONE; + pdesc.face_winding = SG_FACEWINDING_CCW; + pdesc.sample_count = 1; + pdesc.label = "tonemap_pipeline"; + + const sg_pipeline pip = sg_make_pipeline( &pdesc ); + s_tm.pipelines[s_tm.pipelineCount].colorFormat = colorFormat; + s_tm.pipelines[s_tm.pipelineCount].depthFormat = depthFormat; + s_tm.pipelines[s_tm.pipelineCount].pipeline = pip; + ++s_tm.pipelineCount; + return pip; +} + +void InitToneMap( void ) +{ + s_tm.shader = sg_make_shader( tonemap_prog_shader_desc( sg_query_backend() ) ); + + sg_sampler_desc sdesc = { 0 }; + sdesc.min_filter = SG_FILTER_LINEAR; + sdesc.mag_filter = SG_FILTER_LINEAR; + sdesc.mipmap_filter = SG_FILTER_NEAREST; + sdesc.wrap_u = SG_WRAP_CLAMP_TO_EDGE; + sdesc.wrap_v = SG_WRAP_CLAMP_TO_EDGE; + sdesc.wrap_w = SG_WRAP_CLAMP_TO_EDGE; + sdesc.label = "tonemap_sampler"; + s_tm.sampler = sg_make_sampler( &sdesc ); + + s_tm.ready = true; +} + +void ShutdownToneMap( void ) +{ + if ( !s_tm.ready ) + { + return; + } + for ( int i = 0; i < s_tm.pipelineCount; ++i ) + { + sg_destroy_pipeline( s_tm.pipelines[i].pipeline ); + s_tm.pipelines[i].pipeline.id = 0; + s_tm.pipelines[i].colorFormat = SG_PIXELFORMAT_NONE; + s_tm.pipelines[i].depthFormat = SG_PIXELFORMAT_NONE; + } + s_tm.pipelineCount = 0; + sg_destroy_sampler( s_tm.sampler ); + sg_destroy_shader( s_tm.shader ); + s_tm.ready = false; +} + +void SubmitToneMap( sg_view sceneColorView, sg_pixel_format outputColorFormat, sg_pixel_format outputDepthFormat, float ev, + float saturation ) +{ + if ( !s_tm.ready ) + { + return; + } + const sg_pipeline pip = ensurePipeline( outputColorFormat, outputDepthFormat ); + if ( pip.id == 0 ) + { + return; + } + + sg_apply_pipeline( pip ); + + sg_bindings bindings = { 0 }; + bindings.views[VIEW_tonemap_tex_scene] = sceneColorView; + bindings.samplers[SMP_tonemap_smp_scene] = s_tm.sampler; + sg_apply_bindings( &bindings ); + + const sg_backend backend = sg_query_backend(); + const float uvYSign = ( backend == SG_BACKEND_GLCORE || backend == SG_BACKEND_GLES3 ) ? 1.0f : -1.0f; + + tonemap_ub_tonemap_t ub = { 0 }; + ub.params = MakeVec4( ev, uvYSign, saturation, 0.0f ); + sg_apply_uniforms( UB_tonemap_ub_tonemap, &SG_RANGE( ub ) ); + + sg_draw( 0, 3, 1 ); +} diff --git a/samples/gfx/tone_map.h b/samples/gfx/tone_map.h new file mode 100644 index 0000000..09b2c33 --- /dev/null +++ b/samples/gfx/tone_map.h @@ -0,0 +1,56 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// AgX tonemap pass. +// +// Final post-process: reads the resolved HDR scene color (RGBA16F) and +// writes display-encoded sRGB to a linear-format LDR target (swapchain +// in the demo, caller-owned attachment via RenderFrameOffscreen). See +// the shader at shaders/post/tonemap.glsl for the AgX implementation +// and the rationale for skipping the trailing pow(2.2) EOTF. +// +// The pass owns its pipeline cache. The output color format isn't known at +// init time, RenderFrame targets the swapchain format, while +// RenderFrameOffscreen targets whatever the caller supplies. Currently +// both resolve to env.defaults.color_format, but the cache covers a future +// where they diverge (capacity = 2). +// +// Single-threaded, render-thread only. + +#pragma once + +#include "sokol_gfx.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +void InitToneMap( void ); +void ShutdownToneMap( void ); + +// Encodes one fullscreen AgX pass into the currently-open render pass. +// The caller is responsible for sg_begin_pass / sg_end_pass on the output +// target, this function only binds + draws. +// +// sceneColorView: texture-view over the resolved (single-sample) HDR +// scene color image. +// outputColorFormat: pixel format of the color attachment in the open +// pass. Pipeline cache key. +// outputDepthFormat: pixel format of the depth attachment in the open +// pass, or SG_PIXELFORMAT_NONE if the target has no +// depth. The swapchain path supplies the env default, +// offscreen tests pass NONE. Pipeline cache key, +// sokol enforces a pipeline-vs-attachment match even +// though the tonemap pipeline doesn't touch depth. +// ev: exposure stops applied before AgX. -2.0 matches +// the spec for Preetham at physical strength. +// saturation: AgX-look saturation applied after the AgX sigmoid. +// 1.0 is the stock Standard look. >1.0 counteracts +// AgX's path-to-white desaturation. +void SubmitToneMap( sg_view sceneColorView, sg_pixel_format outputColorFormat, sg_pixel_format outputDepthFormat, float ev, + float saturation ); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/samples/gfx/utility.h b/samples/gfx/utility.h new file mode 100644 index 0000000..a52c898 --- /dev/null +++ b/samples/gfx/utility.h @@ -0,0 +1,228 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Math utilities: the 4-wide types Box3D does not provide. +// +// Vec4, linear-RGBA colors and matrix columns. +// Mat4, camera-space matrices (view / proj / view-proj / shadow). +// +// Per-shape transforms use b3Transform directly. Mat4 only appears for +// camera-space matrices. These two types may later move into Box3D, this +// header is written to make that a clean cut-paste. +// +// Conventions match the renderer and Box3D: +// * Column-major storage, multiplied as M * v. +// * Right-handed, Y-up. The renderer drives reverse-Z by passing near/far +// swapped into the perspective builder. + +#pragma once + +#include "box3d/math_functions.h" +#include "box3d/types.h" + +#include + +typedef struct Vec4 +{ + float x, y, z, w; +} Vec4; + +// Column-major 4x4. cx / cy / cz are the basis columns and cw the +// translation column, matching b3Matrix3's cx / cy / cz naming. +typedef struct Mat4 +{ + Vec4 cx, cy, cz, cw; +} Mat4; + +static inline Vec4 MakeVec4( float x, float y, float z, float w ) +{ + Vec4 v = { x, y, z, w }; + return v; +} + +static inline Mat4 MakeIdentity( void ) +{ + Mat4 m = { + { 1.0f, 0.0f, 0.0f, 0.0f }, + { 0.0f, 1.0f, 0.0f, 0.0f }, + { 0.0f, 0.0f, 1.0f, 0.0f }, + { 0.0f, 0.0f, 0.0f, 1.0f }, + }; + return m; +} + +// Matrix times column-vector. +static inline Vec4 MulMV4( Mat4 m, Vec4 v ) +{ + Vec4 r; + r.x = m.cx.x * v.x + m.cy.x * v.y + m.cz.x * v.z + m.cw.x * v.w; + r.y = m.cx.y * v.x + m.cy.y * v.y + m.cz.y * v.z + m.cw.y * v.w; + r.z = m.cx.z * v.x + m.cy.z * v.y + m.cz.z * v.z + m.cw.z * v.w; + r.w = m.cx.w * v.x + m.cy.w * v.y + m.cz.w * v.z + m.cw.w * v.w; + return r; +} + +// Matrix product: applying the result is equivalent to applying b then a. +static inline Mat4 MulMM4( Mat4 a, Mat4 b ) +{ + Mat4 r; + r.cx = MulMV4( a, b.cx ); + r.cy = MulMV4( a, b.cy ); + r.cz = MulMV4( a, b.cz ); + r.cw = MulMV4( a, b.cw ); + return r; +} + +static inline Mat4 Transpose4( Mat4 m ) +{ + Mat4 r; + r.cx = MakeVec4( m.cx.x, m.cy.x, m.cz.x, m.cw.x ); + r.cy = MakeVec4( m.cx.y, m.cy.y, m.cz.y, m.cw.y ); + r.cz = MakeVec4( m.cx.z, m.cy.z, m.cz.z, m.cw.z ); + r.cw = MakeVec4( m.cx.w, m.cy.w, m.cz.w, m.cw.w ); + return r; +} + +// Right-handed perspective with a 0..1 clip-Z. The renderer drives reverse-Z by passing +// nearPlane / farPlane swapped, which puts clip-Z = 1 at the near plane and 0 at the far. +// +// This is the finite-far form. The infinite-far variant (set cz.z = 0, +// cw.z = nearPlane in the reverse-Z arg order) would give strictly better +// precision at distance and remove `far` from the matrix entirely, per +// Upchurch & Desbrun's roundoff analysis. +static inline Mat4 MakePerspective( float fovY, float aspect, float nearPlane, float farPlane ) +{ + Mat4 m = { { 0.0f, 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f, 0.0f } }; + + float cotangent = 1.0f / tanf( fovY / 2.0f ); + m.cx.x = cotangent / aspect; + m.cy.y = cotangent; + m.cz.w = -1.0f; + m.cz.z = farPlane / ( nearPlane - farPlane ); + m.cw.z = ( nearPlane * farPlane ) / ( nearPlane - farPlane ); + return m; +} + +// Same perspective as MakePerspective, but also fills the closed-form +// inverse from the same parameters. The general inverse of a perspective +// matrix is lossy. Building it analytically here keeps the un-project path +// more accurate. +static inline void MakePerspectiveAndInverse( Mat4* outProj, Mat4* outProjInv, float fovY, float aspect, float nearPlane, + float farPlane ) +{ + float tanHalf = tanf( fovY / 2.0f ); + float cotangent = 1.0f / tanHalf; + + // c, d are the two non-trivial slots of the forward matrix. + float c = farPlane / ( nearPlane - farPlane ); + float d = ( nearPlane * farPlane ) / ( nearPlane - farPlane ); + + Mat4 p = { { 0.0f, 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f, 0.0f } }; + p.cx.x = cotangent / aspect; + p.cy.y = cotangent; + p.cz.z = c; + p.cz.w = -1.0f; + p.cw.z = d; + *outProj = p; + + Mat4 pi = { { 0.0f, 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f, 0.0f } }; + pi.cx.x = aspect * tanHalf; + pi.cy.y = tanHalf; + pi.cz.w = 1.0f / d; + pi.cw.z = -1.0f; + pi.cw.w = c / d; + *outProjInv = pi; +} + +// Right-handed orthographic projection with a 0..1 clip-Z. Used for the shadow cascade light matrices. +static inline Mat4 MakeOrthographic( float left, float right, float bottom, float top, float nearPlane, float farPlane ) +{ + Mat4 m = { { 0.0f, 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f, 0.0f } }; + m.cx.x = 2.0f / ( right - left ); + m.cy.y = 2.0f / ( top - bottom ); + m.cz.z = 1.0f / ( nearPlane - farPlane ); + m.cw.w = 1.0f; + m.cw.x = ( left + right ) / ( left - right ); + m.cw.y = ( bottom + top ) / ( bottom - top ); + m.cw.z = nearPlane / ( nearPlane - farPlane ); + return m; +} + +// Right-handed look-at. +static inline Mat4 MakeLookAt( b3Vec3 eye, b3Vec3 center, b3Vec3 up ) +{ + b3Vec3 f = b3Normalize( b3Sub( center, eye ) ); + b3Vec3 s = b3Normalize( b3Cross( f, up ) ); + b3Vec3 u = b3Cross( s, f ); + + Mat4 m; + m.cx = MakeVec4( s.x, u.x, -f.x, 0.0f ); + m.cy = MakeVec4( s.y, u.y, -f.y, 0.0f ); + m.cz = MakeVec4( s.z, u.z, -f.z, 0.0f ); + m.cw = MakeVec4( -b3Dot( s, eye ), -b3Dot( u, eye ), b3Dot( f, eye ), 1.0f ); + return m; +} + +// Build a view matrix and its inverse together from the camera basis. `right`, +// `up` and `forward` are the world-space view-X / view-Y / view-Z directions: +// forward is +view-Z (pivot -> eye), so +// the camera looks down -forward. The basis must be orthonormal and right- +// handed (right = cross(up, forward)), both outputs assume that. +// +// viewInv is the camera's "world matrix": columns are right / up / forward / +// eye. view is its transpose-with-shifted-translation form. Neither requires +// any inversion at runtime. +static inline void MakeViewAndInverse( Mat4* outView, Mat4* outViewInv, b3Vec3 right, b3Vec3 up, b3Vec3 forward, b3Vec3 eye ) +{ + Mat4 v; + v.cx = MakeVec4( right.x, up.x, forward.x, 0.0f ); + v.cy = MakeVec4( right.y, up.y, forward.y, 0.0f ); + v.cz = MakeVec4( right.z, up.z, forward.z, 0.0f ); + v.cw = MakeVec4( -b3Dot( right, eye ), -b3Dot( up, eye ), -b3Dot( forward, eye ), 1.0f ); + *outView = v; + + Mat4 vi; + vi.cx = MakeVec4( right.x, right.y, right.z, 0.0f ); + vi.cy = MakeVec4( up.x, up.y, up.z, 0.0f ); + vi.cz = MakeVec4( forward.x, forward.y, forward.z, 0.0f ); + vi.cw = MakeVec4( eye.x, eye.y, eye.z, 1.0f ); + *outViewInv = vi; +} + +// Build a 4x4 model matrix from a Box3D rigid transform plus a (possibly +// non-uniform) scale. +static inline Mat4 MakeMat4FromTransform( b3Transform t, b3Vec3 scale ) +{ + b3Matrix3 r = b3MakeMatrixFromQuat( t.q ); + Mat4 m; + m.cx = MakeVec4( scale.x * r.cx.x, scale.x * r.cx.y, scale.x * r.cx.z, 0.0f ); + m.cy = MakeVec4( scale.y * r.cy.x, scale.y * r.cy.y, scale.y * r.cy.z, 0.0f ); + m.cz = MakeVec4( scale.z * r.cz.x, scale.z * r.cz.y, scale.z * r.cz.z, 0.0f ); + m.cw = MakeVec4( t.p.x, t.p.y, t.p.z, 1.0f ); + return m; +} + +static inline float SrgbToLinear( float c ) +{ + return c <= 0.04045f ? c / 12.92f : powf( ( c + 0.055f ) / 1.055f, 2.4f ); +} + +static inline Vec4 MakeColor( b3HexColor hexColor ) +{ + uint32_t v = (uint32_t)hexColor; + float k = 1.0f / 255.0f; + float r = (float)( ( v >> 16 ) & 0xFFu ) * k; + float g = (float)( ( v >> 8 ) & 0xFFu ) * k; + float b = (float)( v & 0xFFu ) * k; + return MakeVec4( SrgbToLinear( r ), SrgbToLinear( g ), SrgbToLinear( b ), 1.0f ); +} + +static inline Vec4 MakeColorAlpha( b3HexColor hexColor, float alpha ) +{ + uint32_t v = (uint32_t)hexColor; + float k = 1.0f / 255.0f; + float r = (float)( ( v >> 16 ) & 0xFFu ) * k; + float g = (float)( ( v >> 8 ) & 0xFFu ) * k; + float b = (float)( v & 0xFFu ) * k; + return MakeVec4( SrgbToLinear( r ), SrgbToLinear( g ), SrgbToLinear( b ), alpha ); +} diff --git a/samples/host/camera.cpp b/samples/host/camera.cpp new file mode 100644 index 0000000..2be74b1 --- /dev/null +++ b/samples/host/camera.cpp @@ -0,0 +1,449 @@ +#include "camera.h" + +#include "gfx/picking.h" + +#include "box3d/math_functions.h" +#include "sokol_app.h" + +#include + +static constexpr float HALF_PI = B3_PI * 0.5f; +static constexpr float DEG_TO_RAD = B3_PI / 180.0f; +static constexpr float ORBIT_SENS = 0.005f; // radians per pixel +static constexpr float FLY_LOOK_SENS = 0.005f; // radians per pixel +static constexpr float PAN_SENS = 0.005f; // meters per pixel per meter of radius +static constexpr float RADIAL_ZOOM_SENS = 0.02f; // meters per pixel (alt+right-drag) +static constexpr float FLY_SPEED_STEP = 1.0f; // m/s per scroll tick +static constexpr float ZOOM_STEP = 0.9f; // multiplier per scroll tick +static constexpr float MIN_DIST = 0.1f; +static constexpr float MAX_DIST = 1000.0f; +static constexpr float MIN_SPEED = 0.06f; // matches box3d's 0.001*60 +static constexpr float MAX_SPEED = 30000.0f; // matches box3d's 500*60 +static constexpr float PITCH_LIM = HALF_PI - 0.01f; +static constexpr float THIRD_PERSON_MIN_RADIUS = 0.25f; // matches box3d + +// Build a reverse-Z RH projection and its inverse together by swapping the +// near/far args. mat4PerspectiveAndInverse normally puts ndc.z=0 at near, 1 +// at far; with the arguments swapped you get 1 at near, 0 at far - what the +// project's pipeline expects (compare GREATER, far-clear 0). The inverse is +// closed-form from the same params so the un-project path stays accurate. +static void ReverseZPerspectiveAndInverse( Mat4* outProj, Mat4* outProjInv, float fov, float aspect, float n, float f ) +{ + MakePerspectiveAndInverse( outProj, outProjInv, fov, aspect, f, n ); +} + +// Yaw/pitch -> the "+view-Z" direction (pivot -> camera), matching Box3D's +// sample convention. The actual looking direction is -ForwardFromAngles. +static b3Vec3 ForwardFromAngles( float yaw, float pitch ) +{ + const float cp = cosf( pitch ); + return b3Vec3{ sinf( yaw ) * cp, sinf( pitch ), cosf( yaw ) * cp }; +} + +// Refresh the world-space basis and the view / viewInv pair from yaw / pitch / +// pivot / radius. Called from every state mutator (SetOrbit, Frame, Update) +// so consumers can read m_view / m_viewInv without an inversion step. +static void RebuildBasisAndView( Camera& c ) +{ + const b3Vec3 forward = ForwardFromAngles( c.m_yaw, c.m_pitch ); + const b3Vec3 worldUp = { 0.0f, 1.0f, 0.0f }; + // up = worldUp re-orthogonalized against forward. right = up x forward. + // Matches Box3D's UpdateTransform; produces a right-handed view basis. + const b3Vec3 upUnnorm = b3Sub( worldUp, b3MulSV( b3Dot( worldUp, forward ), forward ) ); + const b3Vec3 up = b3Normalize( upUnnorm ); + const b3Vec3 right = b3Normalize( b3Cross( up, forward ) ); + const b3Vec3 position = { c.m_pivot.x + forward.x * c.m_radius, c.m_pivot.y + forward.y * c.m_radius, + c.m_pivot.z + forward.z * c.m_radius }; + + c.m_position = position; + c.m_right = right; + c.m_up = up; + c.m_forward = forward; + MakeViewAndInverse( &c.m_view, &c.m_viewInv, right, up, forward, position ); +} + +Camera::Camera() + : m_pivot{ 0.0f, 0.0f, 0.0f } + , m_yaw( 35.0f * DEG_TO_RAD ) + , m_pitch( -25.0f * DEG_TO_RAD ) + , m_radius( 25.0f ) + , m_fov( 60.0f * DEG_TO_RAD ) + , m_near( 0.1f ) + , m_far( 1000.0f ) + , m_speed( 10.0f ) + , m_width( 0 ) + , m_height( 0 ) + , m_thirdPerson( false ) + , m_position{ 0.0f, 0.0f, 0.0f } + , m_right{ 1.0f, 0.0f, 0.0f } + , m_up{ 0.0f, 1.0f, 0.0f } + , m_forward{ 0.0f, 0.0f, 1.0f } + , m_view( MakeIdentity() ) + , m_viewInv( MakeIdentity() ) + , m_proj( MakeIdentity() ) + , m_projInv( MakeIdentity() ) +{ + RebuildBasisAndView( *this ); + RebuildProj( 1.0f ); +} + +void Camera::RebuildProj( float aspect ) +{ + if ( aspect <= 0.0f ) + aspect = 1.0f; + ReverseZPerspectiveAndInverse( &m_proj, &m_projInv, m_fov, aspect, m_near, m_far ); +} + +void Camera::Frame( b3AABB aabb, float aspect, float padding ) +{ + if ( !b3IsValidAABB( aabb ) ) + { + return; + } + b3Vec3 center = b3AABB_Center( aabb ); + b3Vec3 ext = b3AABB_Extents( aabb ); // half-extents + float r = sqrtf( ext.x * ext.x + ext.y * ext.y + ext.z * ext.z ); + m_pivot = center; + if ( r < 1.0e-6f ) + { + // Point-like; preserve current radius, just retarget. The cached + // position/basis depend on m_pivot, so refresh them before returning. + RebuildBasisAndView( *this ); + return; + } + if ( aspect <= 0.0f ) + { + aspect = 1.0f; + } + float halfFovY = 0.5f * m_fov; + float invTan = 1.0f / tanf( halfFovY ); + float distV = r * invTan; + float distH = r * invTan / aspect; + float d = ( distV > distH ) ? distV : distH; + d *= padding; + SetOrbit( m_yaw, m_pitch, d ); +} + +void Camera::SetOrbit( float yawRadians, float pitchRadians, float radius ) +{ + m_yaw = yawRadians; + if ( pitchRadians > PITCH_LIM ) + pitchRadians = PITCH_LIM; + if ( pitchRadians < -PITCH_LIM ) + pitchRadians = -PITCH_LIM; + m_pitch = pitchRadians; + if ( radius < MIN_DIST ) + radius = MIN_DIST; + if ( radius > MAX_DIST ) + radius = MAX_DIST; + m_radius = radius; + RebuildBasisAndView( *this ); +} + +void Camera::SetView( float yawDegrees, float pitchDegrees, float radius, b3Vec3 pivot ) +{ + // Box3D feeds degrees; render3d stores radians. Pivot first so SetOrbit's + // basis rebuild uses the new pivot. + SetPivot( pivot ); + SetOrbit( yawDegrees * DEG_TO_RAD, pitchDegrees * DEG_TO_RAD, radius ); +} + +void Camera::UpdateTransform() +{ + RebuildBasisAndView( *this ); +} + +b3Vec3 Camera::Position() const +{ + return m_position; +} + +PickRay Camera::BuildPickRay( float x, float y ) const +{ + PickRay ray; + if ( !::BuildPickRay( x, y, &ray.origin, &ray.translation ) ) + { + // Camera state not latched yet, or degenerate matrices: defined zero + // ray so callers never read uninitialized values. + ray.origin = m_position; + ray.translation = b3Vec3_zero; + } + return ray; +} + +void Camera::OnEvent( const sapp_event* e ) +{ + uint32_t mods = e->modifiers & ( SAPP_MODIFIER_SHIFT | SAPP_MODIFIER_CTRL | SAPP_MODIFIER_ALT ); + const bool canOrbit = mods == SAPP_MODIFIER_ALT; + + switch ( e->type ) + { + case SAPP_EVENTTYPE_MOUSE_DOWN: + if ( e->mouse_button == SAPP_MOUSEBUTTON_LEFT ) + m_leftDown = true; + if ( e->mouse_button == SAPP_MOUSEBUTTON_RIGHT ) + m_rightDown = true; + if ( e->mouse_button == SAPP_MOUSEBUTTON_MIDDLE ) + m_middleDown = true; + break; + case SAPP_EVENTTYPE_MOUSE_UP: + if ( e->mouse_button == SAPP_MOUSEBUTTON_LEFT ) + m_leftDown = false; + if ( e->mouse_button == SAPP_MOUSEBUTTON_RIGHT ) + m_rightDown = false; + if ( e->mouse_button == SAPP_MOUSEBUTTON_MIDDLE ) + m_middleDown = false; + break; + case SAPP_EVENTTYPE_MOUSE_MOVE: + if ( canOrbit && m_leftDown ) + { + m_orbitDX += e->mouse_dx; + m_orbitDY += e->mouse_dy; + } + else if ( canOrbit && m_middleDown ) + { + m_panDX += e->mouse_dx; + m_panDY += e->mouse_dy; + } + else if ( canOrbit && m_rightDown ) + { + m_radialZoomDY += e->mouse_dy; + } + else if ( !canOrbit && m_rightDown ) + { + // Fly-look: routed into the same orbit accumulators; Update + // interprets them differently when m_rightDown && !m_altDown. + m_orbitDX += e->mouse_dx; + m_orbitDY += e->mouse_dy; + } + break; + case SAPP_EVENTTYPE_MOUSE_SCROLL: + if ( !canOrbit && m_rightDown ) + m_speedScrollAccum += e->scroll_y; + else + m_scrollAccum += e->scroll_y; + break; + case SAPP_EVENTTYPE_KEY_DOWN: + switch ( e->key_code ) + { + case SAPP_KEYCODE_W: + m_wDown = true; + break; + case SAPP_KEYCODE_A: + m_aDown = true; + break; + case SAPP_KEYCODE_S: + m_sDown = true; + break; + case SAPP_KEYCODE_D: + m_dDown = true; + break; + case SAPP_KEYCODE_LEFT_ALT: + case SAPP_KEYCODE_RIGHT_ALT: + m_altDown = true; + break; + default: + break; + } + break; + case SAPP_EVENTTYPE_KEY_UP: + switch ( e->key_code ) + { + case SAPP_KEYCODE_W: + m_wDown = false; + break; + case SAPP_KEYCODE_A: + m_aDown = false; + break; + case SAPP_KEYCODE_S: + m_sDown = false; + break; + case SAPP_KEYCODE_D: + m_dDown = false; + break; + case SAPP_KEYCODE_LEFT_ALT: + case SAPP_KEYCODE_RIGHT_ALT: + m_altDown = false; + break; + default: + break; + } + break; + case SAPP_EVENTTYPE_UNFOCUSED: + // Drop every held input on focus loss. Otherwise a drag or a held WASD + // key survives an alt-tab and the camera keeps moving. + m_leftDown = false; + m_rightDown = false; + m_middleDown = false; + m_wDown = false; + m_aDown = false; + m_sDown = false; + m_dDown = false; + m_altDown = false; + break; + default: + break; + } +} + +void Camera::Update( float dt, int width, int height ) +{ + m_width = width; + m_height = height; + const float aspect = ( height > 0 ) ? (float)width / (float)height : 1.0f; + + if ( m_thirdPerson ) + { + // Follow cam: the sample drives m_pivot to the tracked body and calls + // UpdateTransform. The only camera input is wheel zoom on the radius. + if ( m_scrollAccum != 0.0f ) + { + m_radius -= m_scrollAccum; + if ( m_radius < THIRD_PERSON_MIN_RADIUS ) + m_radius = THIRD_PERSON_MIN_RADIUS; + } + // Drop the other accumulators so a return to orbit/fly starts clean. + m_orbitDX = 0.0f; + m_orbitDY = 0.0f; + m_panDX = 0.0f; + m_panDY = 0.0f; + m_radialZoomDY = 0.0f; + m_scrollAccum = 0.0f; + m_speedScrollAccum = 0.0f; + RebuildBasisAndView( *this ); + RebuildProj( aspect ); + return; + } + + const bool flyMode = m_rightDown && !m_altDown; + + if ( flyMode ) + { + // Snapshot eye BEFORE rotating so yaw/pitch pivot around the eye + // (FPS) instead of around m_pivot (orbit). After rotation we + // back-derive m_pivot from this preserved eye so Position() + // returns the same point regardless of look angle. + const b3Vec3 eyeBefore = Position(); + + // FPS look: drag right -> yaw decreases (turn head right, scene + // shifts left); drag down -> pitch increases (look down). Box3D's + // signs - opposite of render3d's orbit pitch sign on purpose. + if ( m_orbitDX != 0.0f || m_orbitDY != 0.0f ) + { + m_yaw -= m_orbitDX * FLY_LOOK_SENS; + m_pitch += m_orbitDY * FLY_LOOK_SENS; + if ( m_pitch > PITCH_LIM ) + m_pitch = PITCH_LIM; + if ( m_pitch < -PITCH_LIM ) + m_pitch = -PITCH_LIM; + } + + const b3Vec3 forward = ForwardFromAngles( m_yaw, m_pitch ); + + float wasdF = 0.0f; // +forward = backwards, since forward = pivot->eye + float wasdR = 0.0f; + if ( m_wDown ) + wasdF -= 1.0f; + if ( m_sDown ) + wasdF += 1.0f; + if ( m_dDown ) + wasdR += 1.0f; + if ( m_aDown ) + wasdR -= 1.0f; + + b3Vec3 eye = eyeBefore; + if ( wasdF != 0.0f || wasdR != 0.0f ) + { + // Right = normalize(worldUp x forward), matching Box3D's + // UpdateTransform. worldUp = (0,1,0). + const b3Vec3 worldUp = { 0.0f, 1.0f, 0.0f }; + b3Vec3 right = b3Cross( worldUp, forward ); + const float rlen = sqrtf( right.x * right.x + right.y * right.y + right.z * right.z ); + if ( rlen > 1.0e-6f ) + { + right.x /= rlen; + right.y /= rlen; + right.z /= rlen; + } + const float step = m_speed * dt; + eye.x += forward.x * wasdF * step + right.x * wasdR * step; + eye.y += forward.y * wasdF * step + right.y * wasdR * step; + eye.z += forward.z * wasdF * step + right.z * wasdR * step; + } + + // Back-derive the pivot so Position() stays consistent and a return + // to orbit mode preserves the current look direction. + m_pivot.x = eye.x - forward.x * m_radius; + m_pivot.y = eye.y - forward.y * m_radius; + m_pivot.z = eye.z - forward.z * m_radius; + + if ( m_speedScrollAccum != 0.0f ) + { + m_speed += m_speedScrollAccum * FLY_SPEED_STEP; + if ( m_speed < MIN_SPEED ) + m_speed = MIN_SPEED; + if ( m_speed > MAX_SPEED ) + m_speed = MAX_SPEED; + } + } + else + { + // Orbit mode. + if ( m_orbitDX != 0.0f || m_orbitDY != 0.0f ) + { + m_yaw -= m_orbitDX * ORBIT_SENS; + m_pitch -= m_orbitDY * ORBIT_SENS; + if ( m_pitch > PITCH_LIM ) + m_pitch = PITCH_LIM; + if ( m_pitch < -PITCH_LIM ) + m_pitch = -PITCH_LIM; + } + + if ( m_panDX != 0.0f || m_panDY != 0.0f ) + { + // Move pivot along view-space right/up. m_right / m_up are still + // last frame's values (orbit yaw/pitch haven't been rebuilt yet), + // which matches the screen the user dragged against. + const float panScale = PAN_SENS * m_radius; + m_pivot.x -= m_right.x * m_panDX * panScale; + m_pivot.y -= m_right.y * m_panDX * panScale; + m_pivot.z -= m_right.z * m_panDX * panScale; + m_pivot.x += m_up.x * m_panDY * panScale; + m_pivot.y += m_up.y * m_panDY * panScale; + m_pivot.z += m_up.z * m_panDY * panScale; + } + + if ( m_radialZoomDY != 0.0f ) + { + // Drag down -> zoom in (radius shrinks). Matches Box3D. + m_radius -= RADIAL_ZOOM_SENS * m_radialZoomDY; + if ( m_radius < MIN_DIST ) + m_radius = MIN_DIST; + if ( m_radius > MAX_DIST ) + m_radius = MAX_DIST; + } + + if ( m_scrollAccum != 0.0f ) + { + m_radius *= powf( ZOOM_STEP, m_scrollAccum ); + if ( m_radius < MIN_DIST ) + m_radius = MIN_DIST; + if ( m_radius > MAX_DIST ) + m_radius = MAX_DIST; + } + } + + // Keep yaw bounded across long sessions. b3UnwindAngle wraps to (-pi, pi]. + m_yaw = b3UnwindAngle( m_yaw ); + + m_orbitDX = 0.0f; + m_orbitDY = 0.0f; + m_panDX = 0.0f; + m_panDY = 0.0f; + m_radialZoomDY = 0.0f; + m_scrollAccum = 0.0f; + m_speedScrollAccum = 0.0f; + + RebuildBasisAndView( *this ); + RebuildProj( aspect ); +} diff --git a/samples/host/camera.h b/samples/host/camera.h new file mode 100644 index 0000000..2c7cadb --- /dev/null +++ b/samples/host/camera.h @@ -0,0 +1,198 @@ +// Orbit + fly camera, modeled after Box3D's sample camera. +// +// Two modes share one state. Sticky mouse-button + Alt-modifier flags +// select which mode each gesture drives: +// +// ORBIT (Alt held) +// Alt + left-drag : orbit (yaw/pitch around pivot) +// Alt + middle-drag : pan pivot in view-space XY +// Alt + right-drag-Y : radial zoom (adjust radius) +// +// FLY (right mouse held, no Alt) +// right-drag : FPS look (yaw/pitch the view direction) +// WASD : translate eye along view forward/right at m_speed +// scroll : tune m_speed +// +// Always +// bare scroll : multiplicative zoom on radius +// +// OnEvent accumulates input deltas; Update consumes them and folds them +// into the camera state. View / Proj produce the matrices the renderer +// consumes. +// +// m_pivot is the look-at pivot, m_radius the radial offset, m_yaw / m_pitch +// the spherical angles in radians. In fly mode the eye is the primary anchor +// and m_pivot is back-derived so re-entering orbit mode preserves the look +// direction. Box3D's sample camera keeps yaw/pitch in degrees, so SetView +// converts at the boundary. + +#pragma once + +#include "gfx/utility.h" + +struct sapp_event; + +// World-space ray from a screen pixel: origin sits on the near plane, +// translation spans near -> far. Feeds straight into b3World_CastRay*. +struct PickRay +{ + b3Vec3 origin; + b3Vec3 translation; +}; + +class Camera +{ +public: + Camera(); + + // Feed each sokol_app event here. Safe to call from event_cb at any + // time during the frame; deltas are summed and consumed by Update(). + void OnEvent( const sapp_event* e ); + + // Width/height are the latched framebuffer pixels; aspect derives from + // them and they back BuildPickRay and ImGui bottom-anchored panels. + void Update( float dt, int width, int height ); + + Mat4 View() const + { + return m_view; + } + Mat4 ViewInverse() const + { + return m_viewInv; + } + Mat4 Proj() const + { + return m_proj; + } + Mat4 ProjInverse() const + { + return m_projInv; + } + + b3Vec3 Position() const; + + // Cached basis accessors (Box3D parity). Forward is +view-Z (pivot -> eye), + // so the look direction is -GetForward(). + b3Vec3 GetPosition() const + { + return m_position; + } + b3Vec3 GetForward() const + { + return m_forward; + } + b3Vec3 GetRight() const + { + return m_right; + } + b3Vec3 GetUp() const + { + return m_up; + } + + // Snap to a fixed orientation; used by scene init paths that frame + // the camera independently of mouse state. + void SetOrbit( float yawRadians, float pitchRadians, float radius ); + + // Box3D's sample signature: angles in degrees, pivot folded in. Mirrors + // the ~140 sample call sites exactly so they need no edits. + void SetView( float yawDegrees, float pitchDegrees, float radius, b3Vec3 pivot = b3Vec3_zero ); + + void SetPivot( b3Vec3 pivot ) + { + m_pivot = pivot; + } + // Forwarder for existing render3d call sites. + void SetTarget( b3Vec3 target ) + { + m_pivot = target; + } + + // Frame an AABB: keep current yaw/pitch, move pivot to the AABB center, + // and refit radius so the AABB fits in view at the current FOV+aspect. + // `padding` (>= 1) scales the fit radius (1.2 leaves a small margin). + // A degenerate / invalid AABB is a no-op. + void Frame( b3AABB aabb, float aspect, float padding ); + void SetFov( float fovRadians ) + { + m_fov = fovRadians; + } + void SetClip( float near, float far ) + { + m_near = near; + m_far = far; + } + + // Recomputes the projection. Call after any SetFov / SetClip change, or + // when the target framebuffer aspect changes outside Update(). + void RebuildProj( float aspect ); + + // Recompute the basis + view from yaw/pitch/pivot/radius. Public entry + // point for sample code that mutates m_pivot directly (third-person follow). + void UpdateTransform(); + + // World-space pick ray from a framebuffer-pixel coordinate, using the + // latched camera state. Wraps the free function in gfx/picking.h; hands + // back a zero-translation ray (origin at the eye) if that state is not + // ready yet, so callers never read uninitialized values. + PickRay BuildPickRay( float x, float y ) const; + + b3Vec3 m_pivot; + float m_yaw; // radians, around Y + float m_pitch; // radians, around camera-frame X + float m_radius; // meters from pivot + + float m_fov; // radians, vertical + float m_near; + float m_far; + + // Fly-mode translation speed, m/s. Scroll-tunable while right-mouse held. + float m_speed; + + // Latched framebuffer pixels, refreshed each Update. Sample UI anchors + // panels relative to m_height. + int m_width; + int m_height; + + // Locks input to wheel-zoom; the sample drives m_pivot to a followed body + // and calls UpdateTransform. Eye placement stays the orbit formula. + bool m_thirdPerson; + + // Cached basis (Box3D-style: forward is +view-Z, i.e. pivot->eye), refreshed + // alongside m_view / m_viewInv whenever yaw/pitch/pivot/radius change. + // These let consumers (picking, shadow frustum) skip re-inverting m_view. + b3Vec3 m_position; + b3Vec3 m_right; + b3Vec3 m_up; + b3Vec3 m_forward; + + // All four matrices are produced together — view / viewInv from the basis, + // proj / projInv from fov/aspect/near/far — so the renderer never inverts + // at runtime. + Mat4 m_view; + Mat4 m_viewInv; + Mat4 m_proj; + Mat4 m_projInv; + + // Per-frame input deltas accumulated by OnEvent and zeroed by Update. + // Routing into the right bucket happens in OnEvent based on which mouse + // buttons + Alt are held when the event arrives. + float m_orbitDX = 0.0f; // alt+left-drag, or right-drag (fly look) + float m_orbitDY = 0.0f; + float m_panDX = 0.0f; // alt+middle-drag + float m_panDY = 0.0f; + float m_radialZoomDY = 0.0f; // alt+right-drag, Y component + float m_scrollAccum = 0.0f; // bare scroll: orbit zoom + float m_speedScrollAccum = 0.0f; // scroll while right held (no alt): tune speed + + // Sticky button/key state, toggled by MOUSE_DOWN/UP and KEY_DOWN/UP. + bool m_leftDown = false; + bool m_rightDown = false; + bool m_middleDown = false; + bool m_altDown = false; + bool m_wDown = false; + bool m_aDown = false; + bool m_sDown = false; + bool m_dDown = false; +}; diff --git a/samples/host/gui.cpp b/samples/host/gui.cpp new file mode 100644 index 0000000..1c092d0 --- /dev/null +++ b/samples/host/gui.cpp @@ -0,0 +1,402 @@ +// Dear ImGui shell - implementation. +// +// Owns the simgui setup and the ImGui pass, runs the app's UI draw callback +// (the menu bar, panels, and diagnostics drawn by DrawUI), and +// drains the in-world text overlay. Panels are anchored with BeginPanel / +// EndPanel; the menu bar and drawer the app draws itself. +// +// Render path: ImGui draws on a NEW swapchain pass opened in RenderUI, +// LOADed on top of the already-tonemapped swapchain image. The simgui +// pipeline therefore inherits the swapchain's color + depth format and +// sample_count=1. + +#include "gui.h" + +#include "gfx/draw.h" +#include "gfx/projection.h" +#include "gfx/renderer.h" +#include "gfx/text.h" +#include "imgui.h" +#include "implot.h" +#include "sokol_app.h" +#include "sokol_imgui.h" +#include "sokol_log.h" + +#include +#include +#include + +static bool s_uiInitialized = false; + +// Display scale (sapp_dpi_scale) latched once in InitUI. ImGui runs in +// physical framebuffer pixels, so panel code multiplies explicit pixel sizes +// by this; the font atlas and the rest of the style are pre-scaled by it too. +static float s_uiScale = 1.0f; + +static DrawUiFcn* s_uiCallback; + +// Restyle Dear ImGui away from the stock dark theme: a desaturated steel-blue +// accent over neutral charcoal, one consistent rounding system, and roomier +// padding. Sets base (unscaled) metrics - InitUI runs ScaleAllSizes after +// this on hi-DPI displays; colors are scale-independent so they need no pass. +static void guiApplyStyle( void ) +{ + ImGuiStyle& style = ImGui::GetStyle(); + + // Metrics: containers round at 4px, controls at 3px - one deliberate + // system instead of the stock mix. Padding gives rows room to breathe. + style.WindowPadding = ImVec2( 10.0f, 10.0f ); + style.FramePadding = ImVec2( 8.0f, 4.0f ); + style.CellPadding = ImVec2( 6.0f, 4.0f ); + style.ItemSpacing = ImVec2( 8.0f, 7.0f ); + style.ItemInnerSpacing = ImVec2( 7.0f, 4.0f ); + style.IndentSpacing = 18.0f; + style.ScrollbarSize = 12.0f; + style.GrabMinSize = 10.0f; + + style.WindowBorderSize = 1.0f; + style.FrameBorderSize = 0.0f; + style.PopupBorderSize = 1.0f; + style.TabBorderSize = 0.0f; + style.SeparatorTextBorderSize = 1.0f; + + style.WindowRounding = 4.0f; + style.ChildRounding = 4.0f; + style.PopupRounding = 4.0f; + style.FrameRounding = 3.0f; + style.GrabRounding = 3.0f; + style.ScrollbarRounding = 3.0f; + style.TabRounding = 3.0f; + + style.WindowTitleAlign = ImVec2( 0.0f, 0.5f ); + + // Palette: neutral charcoal surfaces, one steel-blue accent at three + // brightnesses. Replaces stock ImGui's saturated cornflower blue. + const ImVec4 accent = ImVec4( 0.28f, 0.48f, 0.66f, 1.00f ); + const ImVec4 accentHi = ImVec4( 0.38f, 0.60f, 0.80f, 1.00f ); + const ImVec4 accentLo = ImVec4( 0.22f, 0.36f, 0.50f, 1.00f ); + + ImVec4* c = style.Colors; + c[ImGuiCol_Text] = ImVec4( 0.90f, 0.91f, 0.93f, 1.00f ); + c[ImGuiCol_TextDisabled] = ImVec4( 0.49f, 0.51f, 0.55f, 1.00f ); + c[ImGuiCol_WindowBg] = ImVec4( 0.110f, 0.115f, 0.125f, 0.97f ); + c[ImGuiCol_ChildBg] = ImVec4( 0.00f, 0.00f, 0.00f, 0.00f ); + c[ImGuiCol_PopupBg] = ImVec4( 0.100f, 0.105f, 0.115f, 0.98f ); + c[ImGuiCol_Border] = ImVec4( 0.00f, 0.00f, 0.00f, 0.45f ); + c[ImGuiCol_BorderShadow] = ImVec4( 0.00f, 0.00f, 0.00f, 0.00f ); + c[ImGuiCol_FrameBg] = ImVec4( 0.18f, 0.19f, 0.21f, 1.00f ); + c[ImGuiCol_FrameBgHovered] = ImVec4( 0.24f, 0.26f, 0.29f, 1.00f ); + c[ImGuiCol_FrameBgActive] = ImVec4( 0.29f, 0.32f, 0.36f, 1.00f ); + c[ImGuiCol_TitleBg] = ImVec4( 0.090f, 0.095f, 0.105f, 1.00f ); + c[ImGuiCol_TitleBgActive] = ImVec4( 0.14f, 0.16f, 0.19f, 1.00f ); + c[ImGuiCol_TitleBgCollapsed] = ImVec4( 0.090f, 0.095f, 0.105f, 0.75f ); + c[ImGuiCol_MenuBarBg] = ImVec4( 0.13f, 0.14f, 0.16f, 1.00f ); + c[ImGuiCol_ScrollbarBg] = ImVec4( 0.06f, 0.06f, 0.07f, 0.55f ); + c[ImGuiCol_ScrollbarGrab] = ImVec4( 0.28f, 0.30f, 0.33f, 1.00f ); + c[ImGuiCol_ScrollbarGrabHovered] = ImVec4( 0.36f, 0.39f, 0.43f, 1.00f ); + c[ImGuiCol_ScrollbarGrabActive] = accent; + c[ImGuiCol_CheckMark] = accentHi; + c[ImGuiCol_SliderGrab] = accent; + c[ImGuiCol_SliderGrabActive] = accentHi; + c[ImGuiCol_Button] = ImVec4( 0.22f, 0.24f, 0.27f, 1.00f ); + c[ImGuiCol_ButtonHovered] = accentLo; + c[ImGuiCol_ButtonActive] = accent; + c[ImGuiCol_Header] = ImVec4( 0.19f, 0.21f, 0.24f, 1.00f ); + c[ImGuiCol_HeaderHovered] = accentLo; + c[ImGuiCol_HeaderActive] = accent; + c[ImGuiCol_Separator] = ImVec4( 1.00f, 1.00f, 1.00f, 0.09f ); + c[ImGuiCol_SeparatorHovered] = accentLo; + c[ImGuiCol_SeparatorActive] = accent; + c[ImGuiCol_ResizeGrip] = ImVec4( 1.00f, 1.00f, 1.00f, 0.06f ); + c[ImGuiCol_ResizeGripHovered] = accentLo; + c[ImGuiCol_ResizeGripActive] = accent; + c[ImGuiCol_Tab] = ImVec4( 0.15f, 0.16f, 0.18f, 1.00f ); + c[ImGuiCol_TabHovered] = accentLo; + c[ImGuiCol_TabSelected] = accent; + c[ImGuiCol_TabSelectedOverline] = accentHi; + c[ImGuiCol_TabDimmed] = ImVec4( 0.12f, 0.13f, 0.14f, 1.00f ); + c[ImGuiCol_TabDimmedSelected] = accentLo; + c[ImGuiCol_TextSelectedBg] = ImVec4( accent.x, accent.y, accent.z, 0.40f ); + c[ImGuiCol_DragDropTarget] = accentHi; + c[ImGuiCol_NavCursor] = accentHi; + c[ImGuiCol_PlotLines] = ImVec4( 0.70f, 0.72f, 0.75f, 1.00f ); + c[ImGuiCol_PlotLinesHovered] = accentHi; + c[ImGuiCol_PlotHistogram] = accent; + c[ImGuiCol_PlotHistogramHovered] = accentHi; +} + +void InitUI( const sg_environment* env, DrawUiFcn* drawGuiFcn ) +{ + s_uiCallback = drawGuiFcn; + + simgui_desc_t desc = {}; + desc.color_format = env->defaults.color_format; + desc.depth_format = env->defaults.depth_format; + desc.sample_count = env->defaults.sample_count; + desc.ini_filename = "imgui.ini"; + desc.logger.func = slog_func; + // Skip ImGui's auto-pick so we always get the vector font we add below. + desc.no_default_font = true; + simgui_setup( &desc ); + + // simgui_setup creates the ImGui context, so ImPlot has to come after it. + ImPlot::CreateContext(); + + // DPI handling mirrors the Box2D sample app, which gets crisp text at + // fractional Windows display scales. ImGui runs in physical framebuffer + // pixels: StartUIFrame feeds simgui dpi_scale=1.0, so DisplaySize is the + // framebuffer size and DisplayFramebufferScale is 1.0. The display scale + // is then applied by hand - the font atlas is baked once at an integer + // pixel size and ScaleAllSizes scales the rest of the style. Drawing + // ImGui 1:1 against the framebuffer with an integer-sized atlas is what + // keeps glyphs sharp; letting sokol_imgui scale a logical-pixel UI up by + // a fractional factor instead leaves every glyph on a sub-pixel boundary. + s_uiScale = sapp_dpi_scale(); + + ImGuiIO& io = ImGui::GetIO(); + io.Fonts->Clear(); + + // Restyle before the hi-DPI branch: guiApplyStyle sets base metrics, then + // ScaleAllSizes (below) multiplies them up. Colors are unscaled. + guiApplyStyle(); + + io.Fonts->AddFontDefaultVector(); + + ImGuiStyle& style = ImGui::GetStyle(); + if ( s_uiScale != 1.0f ) + { + style.ScaleAllSizes( s_uiScale ); + } + + // 13px base for the proportional UI font, scaled to a whole physical + // pixel. Rasterizer density is 1.0 (DisplayFramebufferScale 1.0), so the + // atlas bakes at exactly this - floorf keeps it on a whole-pixel size. + style.FontSizeBase = floorf( 13.0f * s_uiScale ); + + s_uiInitialized = true; +} + +void ShutdownUI( void ) +{ + if ( !s_uiInitialized ) + return; + + ImPlot::DestroyContext(); + simgui_shutdown(); + s_uiInitialized = false; +} + +bool HandleEvent( const sapp_event* e ) +{ + if ( !s_uiInitialized ) + { + return false; + } + + bool handled = simgui_handle_event( e ); + const ImGuiIO& io = ImGui::GetIO(); + + if ( handled ) + { + return true; + } + + if ( e->type == SAPP_EVENTTYPE_KEY_DOWN || e->type == SAPP_EVENTTYPE_KEY_UP || e->type == SAPP_EVENTTYPE_CHAR ) + { + return io.WantCaptureKeyboard; + } + + if ( e->type == SAPP_EVENTTYPE_MOUSE_DOWN || e->type == SAPP_EVENTTYPE_MOUSE_UP || e->type == SAPP_EVENTTYPE_MOUSE_MOVE || + e->type == SAPP_EVENTTYPE_MOUSE_SCROLL ) + { + return io.WantCaptureMouse; + } + + return false; +} + +// Gap between a panel and the window edge +static const float PANEL_GAP = 5.0f; + +// Running top Y for the next panel on each side, indexed by GuiPanelAnchor. +static float s_panelCursorY[2]; +// Side of the panel currently open between guiBeginPanel and guiEndPanel. +static GuiPanelAnchor s_panelOpenSide; +static bool s_panelOpen = false; + +static void ResetUIPanelLayout( void ) +{ + const ImGuiViewport* vp = ImGui::GetMainViewport(); + // Clear the main menu bar. Without docking the bar does not shrink the + // viewport work area, so panels would otherwise start under it. + const float top = vp->WorkPos.y + ImGui::GetFrameHeight() + PANEL_GAP * s_uiScale; + s_panelCursorY[GUI_ANCHOR_LEFT] = top; + s_panelCursorY[GUI_ANCHOR_RIGHT] = top; + s_panelOpen = false; +} + +bool BeginPanel( const char* name, GuiPanelAnchor anchor, float width ) +{ + ImGuiViewport* vp = ImGui::GetMainViewport(); + float gap = PANEL_GAP * s_uiScale; + float w = width * s_uiScale; + float cursorY = s_panelCursorY[anchor]; + + // Left panels pin their top-left corner to the left edge; right panels + // pin their top-right corner to the right edge (pivot picks the corner). + float anchorX; + ImVec2 pivot; + if ( anchor == GUI_ANCHOR_RIGHT ) + { + anchorX = vp->WorkPos.x + vp->WorkSize.x - gap; + pivot = ImVec2( 1.0f, 0.0f ); + } + else + { + anchorX = vp->WorkPos.x + gap; + pivot = ImVec2( 0.0f, 0.0f ); + } + ImGui::SetNextWindowPos( ImVec2( anchorX, cursorY ), ImGuiCond_Always, pivot ); + + // SetNextWindowSize y=0 auto-fits height to content; the constraint caps + // it so a tall panel can't run past the window's bottom edge (the panel + // gains a scrollbar past the cap). Width is locked to w by both calls. + float maxH = vp->WorkPos.y + vp->WorkSize.y - gap - cursorY; + if ( maxH < ImGui::GetFrameHeight() ) + maxH = ImGui::GetFrameHeight(); + ImGui::SetNextWindowSizeConstraints( ImVec2( w, 0.0f ), ImVec2( w, maxH ) ); + ImGui::SetNextWindowSize( ImVec2( w, 0.0f ), ImGuiCond_Always ); + + s_panelOpenSide = anchor; + s_panelOpen = true; + return ImGui::Begin( name, nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize ); +} + +void EndPanel( void ) +{ + // Advance this side's cursor past the panel just drawn so the next panel + // stacks directly below it. GetWindowSize is valid here whether or not + // Begin returned true - a collapsed panel reports its title-bar height, + // so the next panel snugs up under the collapsed bar. + if ( s_panelOpen ) + { + s_panelCursorY[s_panelOpenSide] += ImGui::GetWindowSize().y + PANEL_GAP * s_uiScale; + s_panelOpen = false; + } + ImGui::End(); +} + +// Text overlay. Drain the per-frame label arena (filled by DrawString / +// DrawScreenString and the Box3D adapter's DrawString callback). World +// entries project to screen pixels with the last rendered camera, screen +// entries pass through their pixel position, and both emit into ImGui's +// background draw list - labels sit on the scene but under any ImGui +// windows. The drain runs in StartUIFrame because the calling app +// guarantees RenderFrame already ran this frame, so GetCameraState +// returns the matrices the scene was actually rasterized with. +static void RenderText() +{ + const int n = GetTextCount(); + if ( n <= 0 ) + return; + + const CameraState cam = GetCameraState(); + if ( cam.viewportW <= 0 || cam.viewportH <= 0 ) + return; + + // ImGui runs in physical framebuffer pixels (see InitUI), so the main + // viewport's Size matches cam.viewportW/H. Project against the viewport + // Size and offset by vp->Pos so this stays correct even if ImGui's space + // ever gains an origin offset. Aspect is encoded in cam.proj, so any + // width/height with the scene's ratio yields identical NDC. + ImGuiViewport* vp = ImGui::GetMainViewport(); + const int vpW = (int)vp->Size.x; + const int vpH = (int)vp->Size.y; + if ( vpW <= 0 || vpH <= 0 ) + return; + ImDrawList* dl = ImGui::GetBackgroundDrawList(); + const ImVec2 origin = vp->Pos; + + for ( int i = 0; i < n; ++i ) + { + const TextEntry* e = GetTextAt( i ); + float sx, sy; + if ( !ResolveTextScreenPos( e, cam.view, cam.proj, vpW, vpH, &sx, &sy ) ) + { + continue; + } + // Linear-to-byte: pass straight through (no sRGB encode) - matches + // how Box3D's b3HexColor literals reach the Draw* path, so a label + // color reads the same as the SVG hex it came from. + const auto byte = []( float v ) -> uint32_t { + if ( v < 0.0f ) + v = 0.0f; + if ( v > 1.0f ) + v = 1.0f; + return (uint32_t)( v * 255.0f + 0.5f ); + }; + const uint32_t col = IM_COL32( byte( e->color.x ), byte( e->color.y ), byte( e->color.z ), byte( e->color.w ) ); + dl->AddText( nullptr, 0.0f, ImVec2( origin.x + sx, origin.y + sy ), col, e->text ); + } +} + +void StartUIFrame( float dtSec ) +{ + if ( !s_uiInitialized ) + { + return; + } + + simgui_frame_desc_t fd = {}; + fd.width = sapp_width(); + fd.height = sapp_height(); + + // Clamp the delta we hand to ImGui to at least ~1ms. With swap_interval=0 + // sokol_app can call OnFrame back-to-back fast enough that stm_laptime + // returns sub-microsecond deltas, and once cast to float ImGui's g.Time + // fails to advance. That breaks the per-frame reset of the BG/FG draw + // lists (their reset gate is `(float)BgFgDrawListsLastTimeActive != + // (float)g.Time`), so subsequent AddText calls into the background draw + // list pile on top of the prior frame's vertices instead of replacing + // them - visible as in-world labels flickering bright/dim as overlapping + // copies alpha-blend over each other. + const float kMinDt = 1.0f / 1000.0f; + fd.delta_time = ( dtSec >= kMinDt ) ? (double)dtSec : (double)kMinDt; + + // dpi_scale 1.0 on purpose: it keeps ImGui in physical framebuffer pixels + // (DisplaySize = framebuffer, DisplayFramebufferScale = 1.0). The display + // scale is baked into the font and style in InitUI instead. See there. + fd.dpi_scale = 1.0f; + simgui_new_frame( &fd ); + + // Reset the edge-anchor cursors before any panel opens - they accumulate + // per panel within this frame and must start fresh each frame. + ResetUIPanelLayout(); + + // The callback runs every frame; it branches on the sample context's showUI + // (full UI vs the minimal HUD) the way Box2D's DrawUI does. + if ( s_uiCallback != nullptr ) + { + s_uiCallback(); + } + + RenderText(); +} + +void RenderUI( const sg_swapchain* swapchain ) +{ + if ( !s_uiInitialized ) + { + return; + } + + sg_pass pass = {}; + pass.action.colors[0].load_action = SG_LOADACTION_LOAD; // sit on top of tonemap + pass.action.depth.load_action = SG_LOADACTION_DONTCARE; + pass.action.stencil.load_action = SG_LOADACTION_DONTCARE; + pass.swapchain = *swapchain; + pass.label = "imgui"; + sg_begin_pass( &pass ); + simgui_render(); + sg_end_pass(); +} diff --git a/samples/host/gui.h b/samples/host/gui.h new file mode 100644 index 0000000..b187fc1 --- /dev/null +++ b/samples/host/gui.h @@ -0,0 +1,56 @@ +// Dear ImGui shell. +// +// Wraps sokol_imgui.h, runs the app's UI draw callback (the DrawUiFcn passed +// to InitUI) on top of the live scene, and drains the in-world text overlay. +// Used only by the renderer binary; the visual-test targets call +// RenderFrameOffscreen directly and never instantiate ImGui. +// +// Lifecycle from main.cpp's sapp callbacks: +// +// OnInit: InitRenderer(&env); InitUI(&env, DrawUI); +// OnEvent: if (HandleEvent(e)) return; // skip camera if ImGui ate it +// OnFrame: ResetFrameArena(); +// scene draws... +// RenderFrame(&sc, &frame); +// StartUIFrame(dt); // runs the UI draw callback, drains in-world text +// RenderUI(&sc); // separate pass on the swapchain +// OnCleanup: ShutdownUI(); ShutdownRenderer(); +// +// RenderUI opens its own swapchain pass with LOAD action so ImGui sits on +// top of the tonemapped scene without disturbing it. Single-threaded; +// render-thread only. + +#pragma once + +#include "sokol_app.h" +#include "sokol_gfx.h" + +// Screen edge a panel anchors to. Panels sharing a side stack top-down in +// the order they call guiBeginPanel within a frame. +typedef enum GuiPanelAnchor +{ + GUI_ANCHOR_LEFT = 0, + GUI_ANCHOR_RIGHT = 1, +} GuiPanelAnchor; + +typedef void DrawUiFcn( void ); + +void InitUI( const sg_environment* env, DrawUiFcn* drawGuiFcn ); +void ShutdownUI( void ); + +bool HandleEvent( const sapp_event* e ); + +void StartUIFrame( float dtSec ); +void RenderUI( const sg_swapchain* swapchain ); + +// Begin an edge-anchored panel. A thin wrapper over ImGui::Begin. Pins the +// window flush against anchor's screen edge, stacked below any panel +// already opened on that side this frame, and re-anchors it there every +// frame so it tracks the edge when the window resizes (unlike a one-shot +// ImGuiCond_FirstUseEver position, which drifts off a shrinking window). +// width is in unscaled pixels. The UI DPI scale is applied internally. +// Height auto-fits the content, capped to the remaining viewport height +// (the panel gains a scrollbar past the cap). Returns ImGui::Begin's value; +// pair every call with EndPanel, including when it returns false. +bool BeginPanel( const char* name, GuiPanelAnchor anchor, float width ); +void EndPanel( void ); diff --git a/samples/host/imgui_impl.cpp b/samples/host/imgui_impl.cpp new file mode 100644 index 0000000..87f7387 --- /dev/null +++ b/samples/host/imgui_impl.cpp @@ -0,0 +1,17 @@ +// Single translation unit for sokol_imgui.h's implementation. +// +// Built as C++ so it can call into the C++ Dear ImGui API directly (the C +// path needs cimgui, which we don't pull in). Compiled as part of the +// renderer binary; not linked into tests, which never instantiate the GUI. +// +// The sokol_app/glue/time *_IMPL macros live in src/app/sokol_app_impl.c and +// sokol_gfx's SOKOL_IMPL lives in src/gfx/sokol_impl.c - we only enable +// SOKOL_IMGUI_IMPL here. + +#include "imgui.h" + +#include "sokol_gfx.h" +#include "sokol_app.h" + +#define SOKOL_IMGUI_IMPL +#include "sokol_imgui.h" diff --git a/samples/host/sokol_app_impl.c b/samples/host/sokol_app_impl.c new file mode 100644 index 0000000..3113529 --- /dev/null +++ b/samples/host/sokol_app_impl.c @@ -0,0 +1,29 @@ +// Single-TU build of sokol_app + sokol_glue + sokol_time. +// +// sokol_gfx's implementation lives in src/gfx/sokol_impl.c. We only include +// its header here (without SOKOL_IMPL) so that sokol_glue can see the +// sg_environment / sg_swapchain declarations it translates into. +// +// Backend macro (SOKOL_D3D11 / SOKOL_METAL / SOKOL_GLCORE) comes from the +// `sokol` INTERFACE target. On Apple this file is compiled as Objective-C +// with ARC (see src/app/CMakeLists.txt) so sokol_app's Cocoa backend builds. +// +// SOKOL_WIN32_FORCE_MAIN: sokol_app defaults to WinMain (subsystem:windows) +// on Windows. Our binaries are console-subsystem so the smoke test can +// surface stderr to ctest, so force the int main variant. +// +// _POSIX_C_SOURCE: glibc gates clock_gettime / CLOCK_MONOTONIC behind a +// POSIX feature-test macro under -std=c17. Define before any system headers. +#if defined(__linux__) && !defined(_POSIX_C_SOURCE) +#define _POSIX_C_SOURCE 200809L +#endif + +#define SOKOL_APP_IMPL +#define SOKOL_GLUE_IMPL +#define SOKOL_LOG_IMPL +#define SOKOL_WIN32_FORCE_MAIN + +#include "sokol_gfx.h" +#include "sokol_app.h" +#include "sokol_glue.h" +#include "sokol_log.h" diff --git a/samples/imconfig.h b/samples/imconfig.h deleted file mode 100644 index 5841c82..0000000 --- a/samples/imconfig.h +++ /dev/null @@ -1,156 +0,0 @@ -//----------------------------------------------------------------------------- -// DEAR IMGUI COMPILE-TIME OPTIONS -// Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure. -// You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions. -//----------------------------------------------------------------------------- -// A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/rebased branch with your -// modifications to it) B) or '#define IMGUI_USER_CONFIG "my_imgui_config.h"' in your project and then add directives in your own -// file without touching this template. -//----------------------------------------------------------------------------- -// You need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include the -// imgui*.cpp files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on -// data structures. Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure -// layouts. Call IMGUI_CHECKVERSION() from your .cpp file to verify that the data structures your files are using are matching the -// ones imgui.cpp is using. -//----------------------------------------------------------------------------- - -#pragma once - -//---- Define assertion handler. Defaults to calling assert(). -// If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single -// statement. -// #define IM_ASSERT(_EXPR) MyAssert(_EXPR) -// #define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts - -//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows -// Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee -// backward nor forward ABI compatibility. -// - Windows DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + -// SetAllocatorFunctions() -// for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more -// details. -// #define IMGUI_API __declspec(dllexport) // MSVC Windows: DLL export -// #define IMGUI_API __declspec(dllimport) // MSVC Windows: DLL import -// #define IMGUI_API __attribute__((visibility("default"))) // GCC/Clang: override visibility when set is hidden - -//---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to clean your code of -//obsolete function/names. #define IMGUI_DISABLE_OBSOLETE_FUNCTIONS #define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87+ disable legacy -// io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This is automatically done by IMGUI_DISABLE_OBSOLETE_FUNCTIONS. - -//---- Disable all of Dear ImGui or don't implement standard windows/tools. -// It is very strongly recommended to NOT disable the demo windows and debug tool during development. They are extremely useful in -// day to day work. Please read comments in imgui_demo.cpp. -// #define IMGUI_DISABLE // Disable everything: all headers and source files will be empty. -// #define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be -// empty. #define IMGUI_DISABLE_DEBUG_TOOLS // Disable metrics/debugger and other debug tools: -// ShowMetricsWindow(), ShowDebugLogWindow() and ShowIDStackToolWindow() will be empty. - -//---- Don't implement some functions to reduce linkage requirements. -// #define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and -// link with OpenClipboard/GetClipboardData/CloseClipboard etc. (user32.lib/.a, kernel32.lib/.a) #define -// IMGUI_ENABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with Visual Studio] Implement default IME handler -// (require imm32.lib/.a, auto-link for Visual Studio, -limm32 on command-line for MinGW) #define -// IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with non-Visual Studio compilers] Don't implement default -// IME handler (won't require imm32.lib/.a) #define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and -// link with any Win32 function (clipboard, IME). #define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement -// default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default). -// #define IMGUI_DISABLE_DEFAULT_SHELL_FUNCTIONS // Don't implement default platform_io.Platform_OpenInShellFn() -// handler (Win32: ShellExecute(), require shell32.lib/.a, Mac/Linux: use system("")). #define -// IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them -// yourself (e.g. if you don't want to link with vsnprintf) #define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't -// implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself. #define -// IMGUI_DISABLE_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and -// ImFileHandle at all (replace them with dummies) #define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement -// ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle so you can implement them yourself if you don't want to link -// with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function. #define IMGUI_DISABLE_DEFAULT_ALLOCATORS // -// Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call -// ImGui::SetAllocatorFunctions(). #define IMGUI_DISABLE_SSE // Disable use of SSE intrinsics even -// if available - -//---- Enable Test Engine / Automation features. -// #define IMGUI_ENABLE_TEST_ENGINE // Enable imgui_test_engine hooks. Generally set automatically by -// include "imgui_te_config.h", see Test Engine for details. - -//---- Include imgui_user.h at the end of imgui.h as a convenience -// May be convenient for some users to only explicitly include vanilla imgui.h and have extra stuff included. -// #define IMGUI_INCLUDE_IMGUI_USER_H -// #define IMGUI_USER_H_FILENAME "my_folder/my_imgui_user.h" - -//---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another) -// #define IMGUI_USE_BGRA_PACKED_COLOR - -//---- Use 32-bit for ImWchar (default is 16-bit) to support Unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, -//dingbats, symbols, shapes, ancient languages, etc...) #define IMGUI_USE_WCHAR32 - -//---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version -// By default the embedded implementations are declared static and not available outside of Dear ImGui sources files. -// #define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h" -// #define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h" -// #define IMGUI_STB_SPRINTF_FILENAME "my_folder/stb_sprintf.h" // only used if IMGUI_USE_STB_SPRINTF is defined. -// #define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION -// #define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION -// #define IMGUI_DISABLE_STB_SPRINTF_IMPLEMENTATION // only disabled if IMGUI_USE_STB_SPRINTF is defined. - -//---- Use stb_sprintf.h for a faster implementation of vsnprintf instead of the one from libc (unless -//IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined) -// Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats -// provided by stb_sprintf.h. -// #define IMGUI_USE_STB_SPRINTF - -//---- Use FreeType to build and rasterize the font atlas (instead of stb_truetype which is embedded by default in Dear ImGui) -// Requires FreeType headers to be available in the include path. Requires program to be compiled with -// 'misc/freetype/imgui_freetype.cpp' (in this repository) + the FreeType library (not provided). On Windows you may use vcpkg -// with 'vcpkg install freetype --triplet=x64-windows' + 'vcpkg integrate install'. -#define IMGUI_ENABLE_FREETYPE - -//---- Use FreeType+lunasvg library to render OpenType SVG fonts (SVGinOT) -// Requires lunasvg headers to be available in the include path + program to be linked with the lunasvg library (not provided). -// Only works in combination with IMGUI_ENABLE_FREETYPE. -// (implementation is based on Freetype's rsvg-port.c which is licensed under CeCILL-C Free Software License Agreement) -// #define IMGUI_ENABLE_FREETYPE_LUNASVG - -//---- Use stb_truetype to build and rasterize the font atlas (default) -// The only purpose of this define is if you want force compilation of the stb_truetype backend ALONG with the FreeType backend. -// #define IMGUI_ENABLE_STB_TRUETYPE - -//---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4. -// This will be inlined as part of ImVec2 and ImVec4 class declarations. -/* -#define IM_VEC2_CLASS_EXTRA \ - constexpr ImVec2(const MyVec2& f) : x(f.x), y(f.y) {} \ - operator MyVec2() const { return MyVec2(x,y); } - -#define IM_VEC4_CLASS_EXTRA \ - constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \ - operator MyVec4() const { return MyVec4(x,y,z,w); } -*/ -//---- ...Or use Dear ImGui's own very basic math operators. -// #define IMGUI_DEFINE_MATH_OPERATORS - -//---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices. -// Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices). -// Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer. -// Read about ImGuiBackendFlags_RendererHasVtxOffset for details. -// #define ImDrawIdx unsigned int - -//---- Override ImDrawCallback signature (will need to modify renderer backends accordingly) -// struct ImDrawList; -// struct ImDrawCmd; -// typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data); -// #define ImDrawCallback MyImDrawCallback - -//---- Debug Tools: Macro to break in Debugger (we provide a default implementation of this in the codebase) -// (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.) -// #define IM_DEBUG_BREAK IM_ASSERT(0) -// #define IM_DEBUG_BREAK __debugbreak() - -//---- Debug Tools: Enable slower asserts -// #define IMGUI_DEBUG_PARANOID - -//---- Tip: You can add extra functions within the ImGui:: namespace from anywhere (e.g. your own sources/header files) -/* -namespace ImGui -{ - void MyFunction(const char* name, MyMatrix44* mtx); -} -*/ diff --git a/samples/main.cpp b/samples/main.cpp index f8fa767..7941c77 100644 --- a/samples/main.cpp +++ b/samples/main.cpp @@ -1,356 +1,410 @@ // SPDX-FileCopyrightText: 2025 Erin Catto // SPDX-License-Identifier: MIT -// CRT's memory leak detection -#if defined( _WIN64 ) -#ifndef _CRTDBG_MAP_ALLOC -#define _CRTDBG_MAP_ALLOC -#endif -#include -#endif +// Box3D samples host: a sokol_app shell driving render3d's renderer. The four +// sokol_app callbacks own the window and input; everything below the entry +// points (InitRenderer, RenderFrame, the Draw* API, the b3DebugDraw adapter) is +// host-agnostic. See render3d's HOST_INTEGRATION.md for the contract this fills. +// +// OnInit: InitRenderer -> InitUI -> InitAdapter -> Load -> SelectSample +// OnEvent: Esc quits; ImGui gate; else feed camera + dispatch to the sample +// OnFrame: ResetFrameArena -> Step -> Render -> RenderFrame -> UI -> commit +// OnCleanup: destroy sample + Save -> ShutdownUI -> ShutdownRenderer +// +// --frames N runs N frames then exits with status = sokol validation-error +// count, the automated regression net for the port. -// clang-format off -#include "glad/glad.h" -#include "GLFW/glfw3.h" -// clang-format on - -#include "font.h" -#include "imgui.h" -#include "imgui_impl_glfw.h" -#include "imgui_impl_opengl3.h" -#include "implot.h" -#include "renderer.h" +#include "gfx/debug_adapter.h" +#include "gfx/keycodes.h" +#include "gfx/renderer.h" +#include "host/gui.h" #include "sample.h" -#include "shader.h" +#include "sokol_app.h" +#include "sokol_glue.h" + +#include "box3d/box3d.h" +#include "box3d/math_functions.h" #include +#include +#include +#include -#ifdef TRACY_ENABLE -#include +#if defined( _WIN32 ) +#define WIN32_LEAN_AND_MEAN +#define NOMINMAX +// clang-format off +#include +#include // timeBeginPeriod for fine sleep granularity +// clang-format on +#pragma comment( lib, "winmm.lib" ) // MSVC auto-link #endif -// imgui notes -// high-dpi support: https://github.com/ocornut/imgui/issues/5081 -// linear blending: -// http://arkanis.de/weblog/2023-08-14-simple-good-quality-subpixel-text-rendering-in-opengl-with-stb-truetype-and-dual-source-blending +static SampleContext s_context; +static int s_frame = 0; +static int s_frameLimit = -1; +static int s_sampleOverride = -1; -inline bool IsPowerOfTwo( int32_t x ) +static int CompareSamples( const void* a, const void* b ) { - return ( x != 0 ) && ( ( x & ( x - 1 ) ) == 0 ); + SampleEntry* entryA = (SampleEntry*)a; + SampleEntry* entryB = (SampleEntry*)b; + + int result = strcmp( entryA->Category, entryB->Category ); + if ( result == 0 ) + { + result = strcmp( entryA->Name, entryB->Name ); + } + + return result; } -void* AllocFcn( int32_t size, int32_t alignment ) +static void SortSamples() { - // Allocation must be a multiple of alignment or risk a seg fault - // https://en.cppreference.com/w/c/memory/aligned_alloc - assert( IsPowerOfTwo( alignment ) ); - size_t sizeAligned = ( ( size - 1 ) | ( alignment - 1 ) ) + 1; - assert( ( sizeAligned & ( alignment - 1 ) ) == 0 ); + qsort( g_sampleEntries, g_sampleCount, sizeof( SampleEntry ), CompareSamples ); +} -#if defined( _MSC_VER ) - void* ptr = _aligned_malloc( sizeAligned, alignment ); -#else - void* ptr = aligned_alloc( alignment, sizeAligned ); +// Single host UI callback fired from inside StartUIFrame: menu bar, panels, and +// the active sample's drawer. +static void OnDrawUI( void ) +{ + DrawUI( &s_context ); +} + +static void OnInit( void ) +{ +#if defined( _WIN32 ) + timeBeginPeriod( 1 ); #endif - assert( ptr != nullptr ); - return ptr; + + const sg_environment env = sglue_environment(); + InitRenderer( &env ); + InitUI( &env, OnDrawUI ); + InitAdapter(); + + constexpr float DEG = 3.14159265358979323846f / 180.0f; + s_context.camera.SetFov( 50.0f * DEG ); + s_context.camera.SetClip( 0.1f, 1000.0f ); + + s_context.Load(); + + int cores = (int)std::thread::hardware_concurrency(); + s_context.workerCount = b3ClampInt( cores / 2, 1, 8 ); + s_context.windowWidth = sapp_width(); + s_context.windowHeight = sapp_height(); + + SortSamples(); + + // --sample N selects a registered sample by sorted index, overriding the + // persisted one. Lets a headless --frames run target a specific sample. + int index = s_context.sampleIndex; + if ( s_sampleOverride >= 0 && s_sampleOverride < g_sampleCount ) + { + index = s_sampleOverride; + } + + SelectSample( &s_context, index, false ); } -void FreeFcn( void* mem ) +static void OnEvent( const sapp_event* e ) { -#if defined( _MSC_VER ) - _aligned_free( mem ); -#else - free( mem ); -#endif -} + // Esc quits even with ImGui focus so a text field can't trap the app. + if ( e->type == SAPP_EVENTTYPE_KEY_DOWN && e->key_code == SAPP_KEYCODE_ESCAPE ) + { + sapp_request_quit(); + return; + } -static int AssertHandler( const char* cond, const char* file, int line ) -{ - printf( "Box3D Assert: %s, %s, line %d\n", cond, file, line ); - return 1; -} + const bool imguiCaptured = HandleEvent( e ); -#define WINDOW_TITLE "Box3D v0.1.0" + // The camera must always see button releases and focus loss, even when the UI + // captures the event. Otherwise a release over an ImGui panel never clears the + // drag flag and the camera keeps orbiting. + const bool releaseOrUnfocus = e->type == SAPP_EVENTTYPE_MOUSE_UP || e->type == SAPP_EVENTTYPE_UNFOCUSED; + if ( imguiCaptured == false || releaseOrUnfocus ) + { + s_context.camera.OnEvent( e ); + } -static int s_windowWidth = 1920; -static int s_windowHeight = 1080; -static int s_bufferWidth = s_windowWidth; -static int s_bufferHeight = s_windowHeight; - -Font* s_font = nullptr; -SampleManager s_manager; - -static void WindowSizeCallback( GLFWwindow* window, int width, int height ) -{ - s_windowWidth = width; - s_windowHeight = height; - glfwGetFramebufferSize( window, &s_bufferWidth, &s_bufferHeight ); - s_manager.Resize( s_windowWidth, s_windowHeight, s_bufferWidth, s_bufferHeight ); -} - -static void ErrorCallback( int error, const char* description ) -{ - // Report GLFW error - printf( "GLFW Error %d: %s", error, description ); -} - -static void KeyCallback( GLFWwindow* window, int key, int scancode, int action, int mods ) -{ - ImGui_ImplGlfw_KeyCallback( window, key, scancode, action, mods ); - if ( ImGui::GetIO().WantCaptureKeyboard ) + if ( imguiCaptured ) { return; } - s_manager.Keyboard( key, action, mods ); -} + // Keep keyboard mods only. sokol packs the held mouse button into modifiers + // (SAPP_MODIFIER_LMB == 0x100), which would defeat the sample's modifiers == 0 checks. + const int mods = e->modifiers & ( SAPP_MODIFIER_SHIFT | SAPP_MODIFIER_CTRL | SAPP_MODIFIER_ALT | SAPP_MODIFIER_SUPER ); -void CharCallback( GLFWwindow* window, unsigned int character ) -{ - ImGui_ImplGlfw_CharCallback( window, character ); -} - -static void MouseButtonCallback( GLFWwindow* window, int button, int action, int modifiers ) -{ - ImGui_ImplGlfw_MouseButtonCallback( window, button, action, modifiers ); - if ( ImGui::GetIO().WantCaptureMouse ) + switch ( e->type ) { + case SAPP_EVENTTYPE_KEY_DOWN: + SetKeyDown( e->key_code, true ); + + // Global shortcuts on first press; repeats are ignored. The sokol + // analog of Box2D's KeyCallback. + if ( e->key_repeat == false ) + { + switch ( e->key_code ) + { + case KEY_TAB: + s_context.showUI = !s_context.showUI; + break; + + case KEY_O: + if ( mods & MOD_CTRL ) + { + // Ctrl+O opens the fuzzy picker. Force the UI visible so it shows. + s_context.showUI = true; + s_context.openSamplePicker = true; + } + else + { + s_context.singleStep += ( mods & MOD_SHIFT ) ? 5 : 1; + } + break; + + case KEY_P: + s_context.pause = !s_context.pause; + break; + + case KEY_M: + s_context.showMetrics = !s_context.showMetrics; + break; + + case KEY_R: + SelectSample( &s_context, s_context.sampleIndex, true ); + break; + + case KEY_LEFT_BRACKET: + SelectSample( &s_context, b3MaxInt( 0, s_context.sampleIndex - 1 ), false ); + break; + + case KEY_RIGHT_BRACKET: + SelectSample( &s_context, b3MinInt( g_sampleCount - 1, s_context.sampleIndex + 1 ), false ); + break; + + case KEY_F: + case KEY_HOME: + { + // Frame the selection, or the whole world when nothing is selected. + b3BodyId bodyId = GetHoveredBody(); + b3AABB aabb; + float padding; + if ( B3_IS_NON_NULL( bodyId ) ) + { + aabb = b3Body_ComputeAABB( bodyId ); + padding = 1.5f; + } + else + { + aabb = b3World_GetBounds( s_context.sample->m_worldId ); + padding = 0.75f; + } + + Camera& cam = s_context.camera; + float aspect = cam.m_height > 0 ? (float)cam.m_width / (float)cam.m_height : 1.0f; + cam.Frame( aabb, aspect, padding ); + } + break; + + default: + s_context.sample->Keyboard( e->key_code, ACTION_PRESS, mods ); + break; + } + } + break; + + case SAPP_EVENTTYPE_KEY_UP: + SetKeyDown( e->key_code, false ); + break; + + case SAPP_EVENTTYPE_MOUSE_DOWN: + s_context.mouseX = e->mouse_x; + s_context.mouseY = e->mouse_y; + s_context.sample->MouseDown( { e->mouse_x, e->mouse_y }, e->mouse_button, mods ); + break; + + case SAPP_EVENTTYPE_MOUSE_UP: + s_context.sample->MouseUp( { e->mouse_x, e->mouse_y }, e->mouse_button ); + break; + + case SAPP_EVENTTYPE_MOUSE_MOVE: + s_context.mouseX = e->mouse_x; + s_context.mouseY = e->mouse_y; + s_context.mouseDX = e->mouse_dx; + s_context.mouseDY = e->mouse_dy; + s_context.sample->MouseMove( { e->mouse_x, e->mouse_y } ); + break; + + case SAPP_EVENTTYPE_RESIZED: + { + int w = sapp_width(); + int h = sapp_height(); + s_context.minimized = ( w == 0 || h == 0 ); + if ( s_context.minimized == false ) + { + s_context.windowWidth = w; + s_context.windowHeight = h; + } + } + break; + + default: + break; + } +} + +// Pace the loop to 60 Hz so the fixed 1/60 physics step plays at real time on any +// display. Sleep the bulk of the idle time, then spin the last bit since sleep wakes +// are only accurate to about a millisecond. +static void LimitFrameRate( uint64_t frameStart ) +{ + const float targetMs = 1000.0f / 60.0f; + const float spinMs = 2.0f; + + int sleepMs = (int)( targetMs - spinMs - b3GetMilliseconds( frameStart ) ); + if ( sleepMs > 0 ) + { + b3Sleep( sleepMs ); + } + + while ( b3GetMilliseconds( frameStart ) < targetMs ) + { + b3Yield(); + } +} + +static void OnFrame( void ) +{ + if ( s_frameLimit >= 0 && s_frame >= s_frameLimit ) + { + sapp_quit(); return; } - double xd, yd; - glfwGetCursorPos( window, &xd, &yd ); + const uint64_t frameStart = b3GetTicks(); - b3Vec2 ps = { float( xd ), float( yd ) }; - - // Use the mouse to move things around. - if ( button == GLFW_MOUSE_BUTTON_1 ) + // Nothing to draw while minimized. sapp reports a 0x0 framebuffer then, which + // would drive the swapchain and every render target to zero size. Pace the + // loop so it doesn't spin and bail. + if ( s_context.minimized ) { - if ( action == GLFW_PRESS ) + if ( s_frameLimit < 0 ) { - s_manager.m_sample->MouseDown( ps, button, modifiers ); - } - - if ( action == GLFW_RELEASE ) - { - s_manager.m_sample->MouseUp( ps, button ); + LimitFrameRate( frameStart ); } + return; } -} -static void MouseMotionCallback( GLFWwindow* window, double x, double y ) -{ - b3Vec2 ps = { float( x ), float( y ) }; + const float dt = (float)sapp_frame_duration(); + const int W = sapp_width(); + const int H = sapp_height(); - ImGui_ImplGlfw_CursorPosCallback( window, ps.x, ps.y ); + Camera& camera = s_context.camera; + camera.Update( dt, W, H ); - s_manager.m_sample->MouseMove( ps ); -} + ResetFrameArena(); -static void ScrollCallback( GLFWwindow* window, double deltaX, double deltaY ) -{ - ImGui_ImplGlfw_ScrollCallback( window, deltaX, deltaY ); -} + // Apply the per-frame draw state the UI owns, then advance the sample. Step + // queues the HUD text; Render fills the instance and overlay arenas via the + // b3DebugDraw adapter and the sample's own Draw* calls. + SetTransparentDynamic( s_context.transparentDynamic ); + s_context.sample->ResetText(); -static void Startup( GLFWwindow* window ) -{ - // Initialize font - s_font = Font::Create( &s_manager.m_context.camera, "data/fonts/Roboto-Medium.ttf", 18.0f ); - - if ( s_font == nullptr ) + // Pause banner only with the UI up, matching Box2D. + if ( s_context.pause && s_context.showUI ) { - exit( EXIT_FAILURE ); + s_context.sample->DrawTextLine( "****PAUSED****" ); + s_context.sample->DrawTextLine( "" ); } - IMGUI_CHECKVERSION(); - ImGui::CreateContext(); - ImPlot::CreateContext(); + s_context.sample->Step(); + s_context.sample->Render(); - // Setup Platform/Renderer bindings - ImGui_ImplGlfw_InitForOpenGL( window, false ); - ImGui_ImplOpenGL3_Init(); + FrameInput fi{}; + fi.view = camera.View(); + fi.viewInv = camera.ViewInverse(); + fi.proj = camera.Proj(); + fi.projInv = camera.ProjInverse(); + fi.cameraPosition = camera.Position(); + fi.time = (float)sapp_frame_count() / 60.0f; + fi.debugMode = s_context.debugView; + fi.disableShadows = !s_context.enableShadows; + fi.disableAmbientOcclusion = !s_context.enableGtao; - ImGuiIO& io = ImGui::GetIO(); - io.Fonts->AddFontFromFileTTF( "data/fonts/Roboto-Medium.ttf", 16.0f ); + const sg_swapchain sc = sglue_swapchain(); + RenderFrame( &sc, &fi ); - // Initialize test manager - s_manager.Startup( window, s_windowWidth, s_windowHeight, s_bufferWidth, s_bufferHeight ); -} + // StartUIFrame runs after RenderFrame: it drains the text arena with the + // camera state RenderFrame just latched and runs the UI draw callback. + StartUIFrame( dt ); -static void Render( GLFWwindow* window, float elapsedTime ) -{ - // Start the Dear ImGui frame - ImGui_ImplOpenGL3_NewFrame(); - ImGui_ImplGlfw_NewFrame(); + RenderUI( &sc ); + sg_commit(); + ++s_frame; - ImGui::NewFrame(); - - glViewport( 0, 0, s_bufferWidth, s_bufferHeight ); - - glClearColor( 0.3f, 0.3f, 0.3f, 1.0f ); - glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); - - s_manager.Render( window, elapsedTime ); - - int y = s_windowHeight - 10; - - int triangleIndex = s_manager.m_sample->m_triangleIndex; - uint64_t materialId = s_manager.m_sample->m_userMaterialId; - - const Camera* camera = &s_manager.m_context.camera; - static char buffer[128]; - snprintf( buffer, 128, "%.1f ms - step %d - camera (%g, %g, %g, %g) - tri %d - mat %d", 1000.0f * elapsedTime, s_manager.m_sample->m_stepCount, - camera->m_yaw, camera->m_pitch, camera->m_radius, camera->m_speed, triangleIndex, (int)materialId ); - DrawText( 10, y, b3_colorLightGray, buffer ); - - if ( s_font != nullptr ) + if ( s_frameLimit < 0 ) { - s_font->Flush(); + LimitFrameRate( frameStart ); } - - //ImGui::ShowDemoWindow(); - //ImPlot::ShowDemoWindow(); - - ImGui::Render(); - ImGui_ImplOpenGL3_RenderDrawData( ImGui::GetDrawData() ); - - // Platform functions may have changed the current OpenGL context - glfwMakeContextCurrent( window ); - glfwSwapBuffers( window ); } -static void Shutdown( GLFWwindow* window ) +static void OnCleanup( void ) { - // Shutdown test manager - s_manager.Shutdown( window ); + // Destroy the sample first because it will destroy debug shapes. + delete s_context.sample; + s_context.sample = nullptr; + s_context.Save(); - ImGui_ImplOpenGL3_Shutdown(); - ImGui_ImplGlfw_Shutdown(); - ImPlot::DestroyContext(); - ImGui::DestroyContext(); + ShutdownUI(); + ShutdownRenderer(); - delete s_font; - s_font = nullptr; -} + const int errors = GetRenderErrorCount(); + fprintf( stderr, "samples: %d frames, %d sokol errors\n", s_frame, errors ); -int main() -{ -#if defined( _WIN64 ) - // Enable run-time memory check for debug builds - // How to break at the leaking allocation, in the watch window enter this variable - // and set it to the allocation number in {}. Do this at the first line in main. - // https://learn.microsoft.com/en-us/troubleshoot/developer/visualstudio/cpp/libraries/use-rtbreakalloc-debug-memory-allocation - //_CrtSetBreakAlloc(1392); - _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE ); - _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT ); - //_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); +#if defined( _WIN32 ) + timeEndPeriod( 1 ); #endif -#ifdef TRACY_ENABLE - tracy::StartupProfiler(); -#endif - - b3SetAllocator( AllocFcn, FreeFcn ); - b3SetAssertFcn( AssertHandler ); - - // Initialize GLFW - glfwSetErrorCallback( ErrorCallback ); - if ( !glfwInit() ) - { - fprintf( stderr, "Failed to initialize GLFW\n" ); - return -1; - } - - // Create OpenGL window - glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, 4 ); - glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, 1 ); - glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE ); - - // MSAA - glfwWindowHint( GLFW_SAMPLES, 4 ); - - GLFWwindow* window = glfwCreateWindow( s_windowWidth, s_windowHeight, WINDOW_TITLE, nullptr, nullptr ); - if ( window == nullptr ) - { - glfwTerminate(); - return -1; - } - - glfwGetWindowSize( window, &s_windowWidth, &s_windowHeight ); - glfwGetFramebufferSize( window, &s_bufferWidth, &s_bufferHeight ); - - // Set window callbacks - glfwSetKeyCallback( window, KeyCallback ); - glfwSetCharCallback( window, CharCallback ); - glfwSetCursorPosCallback( window, MouseMotionCallback ); - glfwSetMouseButtonCallback( window, MouseButtonCallback ); - glfwSetScrollCallback( window, ScrollCallback ); - glfwSetWindowSizeCallback( window, WindowSizeCallback ); - - // Make OpenGL context current - glfwMakeContextCurrent( window ); - - // This enables v-sync - // glfwSwapInterval( 1 ); - - // Setup GLAD bindings - if ( !gladLoadGL() ) - { - fprintf( stderr, "Failed to initialize glad\n" ); - glfwTerminate(); - return -1; - } - - { - const char* glVersionString = (const char*)glGetString( GL_VERSION ); - const char* glslVersionString = (const char*)glGetString( GL_SHADING_LANGUAGE_VERSION ); - printf( "OpenGL %s, GLSL %s\n", glVersionString, glslVersionString ); - } - - Startup( window ); - - glEnable( GL_DEPTH_TEST ); - - float frameTime = 0.0f; - while ( !glfwWindowShouldClose( window ) ) - { - glfwPollEvents(); - - if (s_manager.m_context.minimized) - { - continue; - } - - double time1 = glfwGetTime(); - - s_manager.Step(); - Render( window, frameTime ); - - // Limit frame rate to 60Hz - double time2 = glfwGetTime(); - double targetTime = time1 + 1.0 / 60.0; - while ( time2 < targetTime ) - { - b3Yield(); - time2 = glfwGetTime(); - } - - frameTime = float( time2 - time1 ); - } - - Shutdown( window ); - - glfwDestroyWindow( window ); - glfwTerminate(); - -#ifdef TRACY_ENABLE - tracy::ShutdownProfiler(); -#endif - -#if defined( _WIN64 ) - _CrtDumpMemoryLeaks(); -#endif - - return 0; + exit( errors == 0 ? 0 : 1 ); +} + +sapp_desc sokol_main( int argc, char** argv ) +{ + for ( int i = 1; i < argc; ++i ) + { + if ( strcmp( argv[i], "--frames" ) == 0 && i + 1 < argc ) + { + s_frameLimit = atoi( argv[++i] ); + } + else if ( strcmp( argv[i], "--sample" ) == 0 && i + 1 < argc ) + { + s_sampleOverride = atoi( argv[++i] ); + } + } + + sapp_desc desc{}; + desc.init_cb = OnInit; + desc.frame_cb = OnFrame; + desc.event_cb = OnEvent; + desc.cleanup_cb = OnCleanup; + + // GL 4.5 for glClipControl (reverse-Z). Ignored on D3D11 / Metal. + desc.gl.major_version = 4; + desc.gl.minor_version = 5; + + desc.width = 1920; + desc.height = 1080; + + // No swap-chain MSAA. The renderer runs MSAA in its own scene target. + desc.sample_count = 1; + + desc.window_title = "Box3D Samples"; + + // Vsync off: the software limiter in OnFrame owns the cadence. A hard 60 Hz + // cap under vsync would beat against a non-60 display and pace to the wrong rate. + desc.swap_interval = 0; + desc.high_dpi = true; + + return desc; } diff --git a/samples/renderer.cpp b/samples/renderer.cpp deleted file mode 100644 index df2c108..0000000 --- a/samples/renderer.cpp +++ /dev/null @@ -1,746 +0,0 @@ -// SPDX-FileCopyrightText: 2025 Erin Catto -// SPDX-License-Identifier: MIT - -#include "renderer.h" - -#include "camera.h" -#include "font.h" -#include "sample.h" -#include "scene.h" -#include "shader.h" - -#include "box3d/collision.h" -#include "box3d/math_functions.h" - -// clang-format off -#include -#include -// clang-format on - -#include "box3d/box3d.h" - -#include -#include -#include -#include -#include -#include - -struct PointData -{ - b3Vec3 position; - float size; - RGBA8 rgba; -}; - -struct PointDraw -{ - enum - { - e_batchSize = 2048 - }; - - std::vector Points; - - uint32_t programId; - - uint32_t vaoId; - uint32_t vboId; - - int ProjectionUniform; - int ViewUniform; - int SizeUniform; -}; - -PointDraw* CreateDebugPoints() -{ - const char* vs = R"( - #version 330 core - uniform mat4 projection; - uniform mat4 view; - layout(location = 0) in vec3 point; - layout(location = 1) in vec4 color; - layout(location = 2) in float size; - out vec4 f_color; - void main(void) - { - gl_Position = projection * view * vec4(point, 1.0f); - f_color = color; - gl_PointSize = size; - } - )"; - - const char* fs = R"( - #version 330 core - in vec4 f_color; - out vec4 color; - void main(void) - { - color = f_color; - } - )"; - - PointDraw* draw = new PointDraw; - - draw->programId = CreateProgramFromStrings( vs, fs ); - draw->ProjectionUniform = GetUniformLocation( draw->programId, "projection" ); - draw->ViewUniform = GetUniformLocation( draw->programId, "view" ); - - constexpr int vertexAttribute = 0; - constexpr int sizeAttribute = 1; - constexpr int colorAttribute = 2; - - // Generate - glGenVertexArrays( 1, &draw->vaoId ); - glGenBuffers( 1, &draw->vboId ); - - glBindVertexArray( draw->vaoId ); - glEnableVertexAttribArray( vertexAttribute ); - glEnableVertexAttribArray( sizeAttribute ); - glEnableVertexAttribArray( colorAttribute ); - - // Vertex buffer - glBindBuffer( GL_ARRAY_BUFFER, draw->vboId ); - - glBufferData( GL_ARRAY_BUFFER, PointDraw::e_batchSize * sizeof( PointData ), nullptr, GL_DYNAMIC_DRAW ); - - glVertexAttribPointer( vertexAttribute, 3, GL_FLOAT, GL_FALSE, sizeof( PointData ), (void*)offsetof( PointData, position ) ); - glVertexAttribPointer( colorAttribute, 4, GL_FLOAT, GL_FALSE, sizeof( PointData ), (void*)offsetof( PointData, size ) ); - // save bandwidth by expanding color to floats in the shader - glVertexAttribPointer( sizeAttribute, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof( PointData ), (void*)offsetof( PointData, rgba ) ); - - CheckOpenGL(); - - // Cleanup - glBindBuffer( GL_ARRAY_BUFFER, 0 ); - glBindVertexArray( 0 ); - - return draw; -} - -void DestroyDebugPoints( PointDraw* draw ) -{ - if ( draw->vaoId ) - { - glDeleteVertexArrays( 1, &draw->vaoId ); - glDeleteBuffers( 1, &draw->vboId ); - draw->vaoId = 0; - } - - DestroyShader( draw->programId ); - draw->programId = 0; - - delete draw; -} - -void AddPoint( PointDraw* draw, b3Vec3 point, float size, b3HexColor color ) -{ - draw->Points.push_back( { point, size, MakeRGBA8( color ) } ); -} - -void FlushPoints( PointDraw* draw, Camera* camera ) -{ - if ( draw->Points.size() == 0 ) - { - return; - } - - glDepthFunc( GL_LEQUAL ); - - glUseProgram( draw->programId ); - - Matrix4 projection = camera->GetProjectionMatrix(); - Matrix4 view = camera->GetViewMatrix(); - - SetUniformMatrix4( draw->ProjectionUniform, projection ); - SetUniformMatrix4( draw->ViewUniform, view ); - - glBindVertexArray( draw->vaoId ); - - int totalCount = (int)draw->Points.size(); - PointData* points = draw->Points.data(); - - while ( totalCount > 0 ) - { - int count = b3MinInt( totalCount, PointDraw::e_batchSize ); - - glBindBuffer( GL_ARRAY_BUFFER, draw->vboId ); - // todo macOS optimization? - // glBufferData( GL_ARRAY_BUFFER, PointDraw::e_batchSize * sizeof( PointData ), nullptr, GL_DYNAMIC_DRAW ); - glBufferSubData( GL_ARRAY_BUFFER, 0, count * sizeof( PointData ), points ); - - glEnable( GL_PROGRAM_POINT_SIZE ); - glDrawArrays( GL_POINTS, 0, count ); - glDisable( GL_PROGRAM_POINT_SIZE ); - - points += count; - totalCount -= count; - } - - CheckOpenGL(); - - glBindBuffer( GL_ARRAY_BUFFER, 0 ); - glBindVertexArray( 0 ); - glUseProgram( 0 ); - - draw->Points.clear(); -} - -struct LinePoint -{ - b3Vec3 position; - RGBA8 rgba; -}; - -struct LineDraw -{ - enum - { - e_batchSize = 2048 - }; - - std::vector points; - - uint32_t programId; - - uint32_t VaoId; - uint32_t VboId; - - int ProjectionUniform; - int ViewUniform; -}; - -LineDraw* CreateDebugLines() -{ - const char* vs = R"( - #version 330 core - uniform mat4 projection; - uniform mat4 view; - layout(location = 0) in vec3 point; - layout(location = 1) in vec4 color; - out vec4 f_color; - void main(void) - { - gl_Position = projection * view * vec4(point, 1.0f); - f_color = color; - } - )"; - - const char* fs = R"( - #version 330 core - in vec4 f_color; - out vec4 color; - void main(void) - { - color = f_color; - } - )"; - - LineDraw* draw = new LineDraw; - - draw->programId = CreateProgramFromStrings( vs, fs ); - draw->ProjectionUniform = GetUniformLocation( draw->programId, "projection" ); - draw->ViewUniform = GetUniformLocation( draw->programId, "view" ); - - constexpr int vertexAttribute = 0; - constexpr int colorAttribute = 1; - - // Generate - glGenVertexArrays( 1, &draw->VaoId ); - glGenBuffers( 1, &draw->VboId ); - - glBindVertexArray( draw->VaoId ); - glEnableVertexAttribArray( vertexAttribute ); - glEnableVertexAttribArray( colorAttribute ); - - // Vertex buffer - glBindBuffer( GL_ARRAY_BUFFER, draw->VboId ); - glBufferData( GL_ARRAY_BUFFER, LineDraw::e_batchSize * sizeof( LinePoint ), nullptr, GL_DYNAMIC_DRAW ); - - glVertexAttribPointer( vertexAttribute, 3, GL_FLOAT, GL_FALSE, sizeof( LinePoint ), - (void*)offsetof( LinePoint, position ) ); - // save bandwidth by expanding color to floats in the shader - glVertexAttribPointer( colorAttribute, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof( LinePoint ), - (void*)offsetof( LinePoint, rgba ) ); - - CheckOpenGL(); - - // Cleanup - glBindBuffer( GL_ARRAY_BUFFER, 0 ); - glBindVertexArray( 0 ); - - return draw; -} - -void DestroyDebugLines( LineDraw* draw ) -{ - if ( draw->VaoId ) - { - glDeleteVertexArrays( 1, &draw->VaoId ); - glDeleteBuffers( 1, &draw->VboId ); - draw->VaoId = 0; - } - - DestroyShader( draw->programId ); - draw->programId = 0; - - delete draw; -} - -void AddLine( LineDraw* draw, b3Vec3 point1, b3Vec3 point2, b3HexColor color ) -{ - draw->points.push_back( { point1, MakeRGBA8( color ) } ); - draw->points.push_back( { point2, MakeRGBA8( color ) } ); -} - -void FlushLines( LineDraw* draw, Camera* camera ) -{ - if ( draw->points.size() == 0 ) - { - return; - } - - // WARNING: very slow - //glEnable( GL_LINE_SMOOTH ); - - glEnable( GL_BLEND ); - glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); - - glUseProgram( draw->programId ); - - Matrix4 projection = camera->GetProjectionMatrix(); - Matrix4 view = camera->GetViewMatrix(); - - SetUniformMatrix4( draw->ProjectionUniform, projection ); - SetUniformMatrix4( draw->ViewUniform, view ); - - glBindVertexArray( draw->VaoId ); - glBindBuffer( GL_ARRAY_BUFFER, draw->VboId ); - - int count = (int)draw->points.size(); - LinePoint* points = draw->points.data(); - - while ( count > 0 ) - { - int batchCount = b3MinInt( count, LineDraw::e_batchSize ); - - // todo buffer orphaning for macOS? - // glBufferData( GL_ARRAY_BUFFER, LineDraw::e_batchSize * sizeof( LinePoint ), nullptr, GL_DYNAMIC_DRAW ); - glBufferSubData( GL_ARRAY_BUFFER, 0, batchCount * sizeof( LinePoint ), points ); - glDrawArrays( GL_LINES, 0, batchCount ); - - points += batchCount; - count -= batchCount; - } - - CheckOpenGL(); - - glBindBuffer( GL_ARRAY_BUFFER, 0 ); - glBindVertexArray( 0 ); - glUseProgram( 0 ); - glDisable( GL_BLEND ); - - draw->points.clear(); -} - -static DebugShape* CreateDebugSphere( const b3Sphere* sphere ) -{ - DebugShape* s = new DebugShape; - s->type = DebugShapeType::sphere; - s->sphere.center = sphere->center; - s->sphere.radius = sphere->radius; - return s; -} - -static DebugShape* CreateDebugCapsule( const b3Capsule* capsule, Arena arena ) -{ - DebugShape* s = new DebugShape; - s->type = DebugShapeType::capsule; - s->capsule.center1 = capsule->center1; - s->capsule.center2 = capsule->center2; - s->capsule.radius = capsule->radius; - return s; -} - -static DebugShape* CreateDebugCompound(Scene* scene, const b3Compound* compound, Arena arena ) -{ - DebugShape* s = new DebugShape; - memset( s, 0, sizeof( DebugShape ) ); - s->type = DebugShapeType::compound; - - // Capsules - s->compound.capsuleCount = compound->capsuleCount; - DebugCapsule* debugCapsules = new DebugCapsule[s->compound.capsuleCount]; - for (int i = 0; i < s->compound.capsuleCount; ++i) - { - b3CompoundCapsule element = b3GetCompoundCapsule( compound, i ); - - debugCapsules[i].center1 = element.capsule.center1; - debugCapsules[i].center2 = element.capsule.center2; - debugCapsules[i].radius = element.capsule.radius; - } - s->compound.capsules = debugCapsules; - - // Hulls - s->compound.hullCount = compound->hullCount; - DebugHull* debugHulls = new DebugHull[s->compound.hullCount]; - for (int i = 0; i < s->compound.hullCount; ++i) - { - b3CompoundHull hull = b3GetCompoundHull( compound, i ); - - uint32_t id = CreateInstanceHull( scene, hull.hull, arena ); - debugHulls[i].transform = hull.transform; - debugHulls[i].id = id; - } - s->compound.hulls = debugHulls; - - // Meshes - s->compound.meshCount = compound->meshCount; - DebugMesh* debugMeshes = new DebugMesh[s->compound.meshCount]; - for ( int i = 0; i < s->compound.meshCount; ++i ) - { - b3CompoundMesh mesh = b3GetCompoundMesh( compound, i ); - - uint32_t id = CreateInstanceMesh( scene, mesh.meshData, arena ); - debugMeshes[i].transform = mesh.transform; - debugMeshes[i].scale = mesh.scale; - debugMeshes[i].id = id; - } - s->compound.meshes = debugMeshes; - - // Spheres - s->compound.sphereCount = compound->sphereCount; - DebugSphere* debugSpheres = new DebugSphere[s->compound.sphereCount]; - for (int i = 0; i < s->compound.sphereCount; ++i) - { - b3CompoundSphere sphere = b3GetCompoundSphere( compound, i ); - debugSpheres[i].center = sphere.sphere.center; - debugSpheres[i].radius = sphere.sphere.radius; - } - s->compound.spheres = debugSpheres; - - return s; -} - -static void DestroyDebugCompound( DebugCompound* compound ) -{ - delete[] compound->capsules; - delete[] compound->hulls; - delete[] compound->meshes; - delete[] compound->spheres; -} - -static DebugShape* CreateDebugHull( Scene* scene, const b3Hull* hull, Arena arena ) -{ - uint32_t id = CreateInstanceHull( scene, hull, arena ); - - DebugShape* s = new DebugShape; - s->type = DebugShapeType::hull; - s->hull.id = id; - s->hull.transform = b3Transform_identity; - return s; -} - -static DebugShape* CreateDebugMesh( Scene* scene, const b3Mesh* mesh, Arena arena ) -{ - uint32_t id = CreateInstanceMesh( scene, mesh->data, arena ); - - DebugShape* s = new DebugShape; - s->type = DebugShapeType::mesh; - s->mesh.id = id; - s->mesh.transform = b3Transform_identity; - s->mesh.scale = mesh->scale; - return s; -} - -static DebugShape* CreateDebugHeightField( Scene* scene, const b3HeightField* heightField, Arena arena ) -{ - uint32_t id = CreateInstanceHeightField( scene, heightField, arena ); - - DebugShape* s = new DebugShape; - s->type = DebugShapeType::heightField; - s->heightField.id = id; - return s; -} - -void* CreateDebugShape( const b3DebugShape* debugShape, void* context ) -{ - SampleContext* sampleContext = static_cast( context ); - DebugShape* s = nullptr; - switch ( debugShape->type ) - { - case b3_capsuleShape: - s = CreateDebugCapsule( debugShape->capsule, sampleContext->arena ); - break; - - case b3_compoundShape: - s = CreateDebugCompound( sampleContext->scene, debugShape->compound, sampleContext->arena ); - break; - - case b3_hullShape: - s = CreateDebugHull( sampleContext->scene, debugShape->hull, sampleContext->arena ); - break; - - case b3_meshShape: - s = CreateDebugMesh( sampleContext->scene, debugShape->mesh, sampleContext->arena ); - break; - - case b3_heightShape: - s = CreateDebugHeightField( sampleContext->scene, debugShape->heightField, sampleContext->arena ); - break; - - case b3_sphereShape: - s = CreateDebugSphere( debugShape->sphere ); - break; - - default: - break; - } - - if (s != nullptr) - { - b3BodyId bodyId = b3Shape_GetBody( debugShape->shapeId ); - s->bodyType = b3Body_GetType( bodyId ); - } - else - { - s->bodyType = b3_staticBody; - } - - return s; -} - -void DestroyDebugShape( void* userShape, void* context ) -{ - DebugShape* s = static_cast( userShape ); - switch ( s->type ) - { - case DebugShapeType::compound: - DestroyDebugCompound( &s->compound ); - break; - - default: - break; - } - - delete s; -} - -extern Font* s_font; -void DrawText( int x, int y, b3HexColor color, const char* text ) -{ - s_font->AddText( x, y, color, text ); -} - -void DrawFormat( int x, int y, b3HexColor color, const char* format, ... ) -{ - va_list args; - va_start( args, format ); - char text[512]; - vsnprintf( text, sizeof( text ), format, args ); - DrawText( x, y, color, text ); - va_end( args ); -} - -void DrawWorldString( Camera* camera, b3Vec3 point, b3HexColor color, const char* format, ... ) -{ - float x, y; - bool valid = camera->WorldToScreen( x, y, point ); - if ( valid ) - { - va_list args; - va_start( args, format ); - char text[512]; - vsnprintf( text, sizeof( text ), format, args ); - DrawText( (int)x, (int)y, color, text ); - va_end( args ); - } -} - -static void DrawDisc( Scene* scene, b3Vec3 center, b3Vec3 normal, float radius, b3HexColor color ) -{ - b3Vec3 tangent1 = b3Perp( normal ); - b3Vec3 tangent2 = b3Cross( normal, tangent1 ); - - int n = 9; - float delta = B3_PI / (float)n; - b3CosSin cs = b3ComputeCosSin( delta ); - float x1 = radius, y1 = 0.0f; - b3Vec3 vertex1 = center + x1 * tangent1 + y1 * tangent2; - - for ( int i = 0; i < 2 * n; ++i ) - { - float x2 = cs.cosine * x1 - cs.sine * y1; - float y2 = cs.sine * x1 + cs.cosine * y1; - b3Vec3 vertex2 = center + x2 * tangent1 + y2 * tangent2; - - DrawLine( scene, vertex1, vertex2, color ); - - x1 = x2; - y1 = y2; - vertex1 = vertex2; - } -} - -static void DrawArc( Scene* scene, b3Vec3 center, b3Vec3 normal, float radius, b3Vec3 start, float maxAngle, b3HexColor color ) -{ - b3Vec3 tangent1 = b3Normalize( start ); - b3Vec3 tangent2 = b3Cross( normal, tangent1 ); - - for ( float angle = 0.0f; angle < maxAngle; angle += 5.0f ) - { - float alpha1 = B3_DEG_TO_RAD * ( angle + 0.0f ); - b3Vec3 vertex1 = center + b3Cos( alpha1 ) * radius * tangent1 + b3Sin( alpha1 ) * radius * tangent2; - float alpha2 = B3_DEG_TO_RAD * ( angle + 5.0f ); - b3Vec3 vertex2 = center + b3Cos( alpha2 ) * radius * tangent1 + b3Sin( alpha2 ) * radius * tangent2; - - DrawLine( scene, vertex1, vertex2, color ); - } -} - -void DrawGrid( Scene* scene, int size ) -{ - float grid = float( size ); - - for ( int x = -size; x <= size; ++x ) - { - if ( x == 0 ) - { - DrawLine( scene, { 0.0f, 0.0f, -grid }, { 0.0f, 0.0f, 0.0f }, b3_colorLightGray ); - DrawLine( scene, { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, grid }, b3_colorBlue ); - } - else if ( ( x % 10 ) == 0 ) - { - DrawLine( scene, { float( x ), 0.0f, -grid }, { float( x ), 0.0f, grid }, b3_colorDarkGray ); - } - else - { - DrawLine( scene, { float( x ), 0.0f, -grid }, { float( x ), 0.0f, grid }, b3_colorGray ); - } - } - - for ( int z = -size; z <= size; ++z ) - { - if ( z == 0 ) - { - DrawLine( scene, { -grid, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f }, b3_colorLightGray ); - DrawLine( scene, { 0.0f, 0.0f, 0.0f }, { grid, 0.0f, 0.0f }, b3_colorRed ); - } - else if ( ( z % 10 ) == 0 ) - { - DrawLine( scene, { -grid, 0.0f, float( z ) }, { grid, 0.0f, float( z ) }, b3_colorDarkGray ); - } - else - { - DrawLine( scene, { -grid, 0.0f, float( z ) }, { grid, 0.0f, float( z ) }, b3_colorGray ); - } - } -} - -void DrawCross( Scene* scene, b3Vec3 center, float radius, b3HexColor color ) -{ - DrawLine( scene, center - b3Vec3{ radius, 0.0, 0.0f }, center + b3Vec3{ radius, 0.0f, 0.0f }, color ); - DrawLine( scene, center - b3Vec3{ 0.0f, radius, 0.0f }, center + b3Vec3{ 0.0f, radius, 0.0f }, color ); - DrawLine( scene, center - b3Vec3{ 0.0f, 0.0f, radius }, center + b3Vec3{ 0.0f, 0.0f, radius }, color ); -} - -void DrawSphere( Scene* scene, const b3Transform& transform, const b3Sphere& sphere, b3HexColor color ) -{ - b3Vec3 center = b3TransformPoint( transform, sphere.center ); - float radius = sphere.radius; - - b3Vec3 axisX = b3RotateVector( transform.q, { 1.0f, 0.0f, 0.0f } ); - b3Vec3 axisY = b3RotateVector( transform.q, { 0.0f, 1.0f, 0.0f } ); - b3Vec3 axisZ = b3RotateVector( transform.q, { 0.0f, 0.0f, 1.0f } ); - - DrawDisc( scene, center, axisX, radius, color ); - DrawDisc( scene, center, axisY, radius, color ); - DrawDisc( scene, center, axisZ, radius, color ); -} - -void DrawCapsule( Scene* scene, const b3Transform& transform, const b3Capsule& capsule, b3HexColor color ) -{ - b3Vec3 center1 = b3TransformPoint( transform, capsule.center1 ); - b3Vec3 center2 = b3TransformPoint( transform, capsule.center2 ); - float radius = capsule.radius; - - b3Vec3 normal = b3Normalize( center2 - center1 ); - b3Vec3 tangent1 = b3Perp( normal ); - b3Vec3 tangent2 = b3Cross( normal, tangent1 ); - - DrawLine( scene, center1 + radius * tangent1, center2 + radius * tangent1, color ); - DrawLine( scene, center1 + radius * tangent2, center2 + radius * tangent2, color ); - DrawLine( scene, center1 - radius * tangent1, center2 - radius * tangent1, color ); - DrawLine( scene, center1 - radius * tangent2, center2 - radius * tangent2, color ); - - DrawArc( scene, center1, -tangent1, radius, tangent2, 180.0f, color ); - DrawArc( scene, center1, tangent2, radius, tangent1, 180.0f, color ); - DrawArc( scene, center2, tangent1, radius, tangent2, 180.0f, color ); - DrawArc( scene, center2, -tangent2, radius, tangent1, 180.0f, color ); - - DrawDisc( scene, center1, normal, radius, color ); - DrawDisc( scene, center2, normal, radius, color ); -} - -void DrawHull( Scene* scene, const b3Transform& transform, const b3Hull* hull, b3HexColor color, bool drawNormals ) -{ - const b3HullHalfEdge* edges = b3GetHullEdges( hull ); - const b3Vec3* points = b3GetHullPoints( hull ); - - for ( int edgeIndex = 0; edgeIndex < hull->edgeCount; edgeIndex += 2 ) - { - const b3HullHalfEdge* edge = edges + edgeIndex + 0; - const b3HullHalfEdge* twin = edges + edgeIndex + 1; - - b3Vec3 vertex1 = b3TransformPoint( transform, points[edge->origin] ); - b3Vec3 vertex2 = b3TransformPoint( transform, points[twin->origin] ); - - DrawLine( scene, vertex1, vertex2, color ); - } - - if (drawNormals) - { - const b3HullFace* faces = b3GetHullFaces( hull ); - const b3Plane* planes = b3GetHullPlanes( hull ); - int faceCount = hull->faceCount; - - for (int i = 0; i < faceCount; ++i) - { - uint8_t startEdgeIndex = faces[i].edge; - uint8_t edgeIndex = startEdgeIndex; - - int count = 0; - b3Vec3 p1 = b3Vec3_zero; - do - { - const b3HullHalfEdge* edge = edges + edgeIndex; - p1 += points[edge->origin]; - count += 1; - edgeIndex = edge->next; - } - while ( edgeIndex != startEdgeIndex ); - - assert( count > 0 ); - p1 = b3MulSV( 1.0f / count, p1 ); - b3Vec3 p2 = p1 + 0.2f * planes[i].normal; - - p1 = b3TransformPoint( transform, p1 ); - p2 = b3TransformPoint( transform, p2 ); - - DrawLine( scene, p1, p2, b3_colorWhite ); - DrawPoint( scene, p1, 6.0f, b3_colorLime ); - } - } -} - -void DrawTransform( Scene* scene, const b3Transform& transform, float length ) -{ - b3Vec3 p = transform.p; - b3Vec3 ax = b3RotateVector( transform.q, { 1.0f, 0.0f, 0.0f } ); - b3Vec3 ay = b3RotateVector( transform.q, { 0.0f, 1.0f, 0.0f } ); - b3Vec3 az = b3RotateVector( transform.q, { 0.0f, 0.0f, 1.0f } ); - - DrawLine( scene, p, p + length * ax, b3_colorRed ); - DrawLine( scene, p, p + length * ay, b3_colorGreen ); - DrawLine( scene, p, p + length * az, b3_colorBlue ); -} diff --git a/samples/renderer.h b/samples/renderer.h deleted file mode 100644 index 51ad57c..0000000 --- a/samples/renderer.h +++ /dev/null @@ -1,43 +0,0 @@ -// SPDX-FileCopyrightText: 2025 Erin Catto -// SPDX-License-Identifier: MIT - -#pragma once - -#include "utility.h" - -struct b3Capsule; -struct b3DebugShape; -struct b3Hull; -struct b3MeshData; -struct b3Sphere; - -struct Camera; -struct LineDraw; -struct PointDraw; -struct Scene; - -void* CreateDebugShape( const b3DebugShape* debugShape, void* context ); -void DestroyDebugShape( void* userShape, void* userContext ); - -void DrawText( int x, int y, b3HexColor color, const char* text ); -void DrawFormat( int x, int y, b3HexColor color, const char* format, ... ); -void DrawWorldString( Camera* camera, b3Vec3 point, b3HexColor color, const char* format, ... ); - -void DrawGrid( Scene* scene, int size ); -void DrawCross( Scene* scene, b3Vec3 center, float radius, b3HexColor color ); -void DrawSphere( Scene* scene, const b3Transform& transform, const b3Sphere& sphere, b3HexColor color ); -void DrawCapsule( Scene* scene, const b3Transform& transform, const b3Capsule& capsule, b3HexColor color ); -void DrawHull( Scene* scene, const b3Transform& transform, const b3Hull* hull, b3HexColor color, bool drawNormals ); -void DrawTransform( Scene* scene, const b3Transform& transform, float length ); - -// Debug points -PointDraw* CreateDebugPoints(); -void DestroyDebugPoints( PointDraw* draw ); -void AddPoint( PointDraw* draw, b3Vec3 point, float size, b3HexColor color ); -void FlushPoints( PointDraw* draw, Camera* camera ); - -// Debug lines -LineDraw* CreateDebugLines(); -void DestroyDebugLines( LineDraw* draw ); -void AddLine( LineDraw* draw, b3Vec3 point1, b3Vec3 point2, b3HexColor color ); -void FlushLines( LineDraw* draw, Camera* camera ); diff --git a/samples/sample.cpp b/samples/sample.cpp index 5f6e739..9c46423 100644 --- a/samples/sample.cpp +++ b/samples/sample.cpp @@ -7,26 +7,29 @@ #include "sample.h" -#include "camera.h" +#include "benchmarks.h" +#include "gfx/debug_adapter.h" +#include "gfx/draw.h" +#include "gfx/gtao.h" +#include "gfx/keycodes.h" +#include "gfx/renderer.h" +#include "gfx/shadow.h" +#include "gfx/text.h" +#include "human.h" #include "imgui.h" #include "implot.h" #include "jsmn.h" -#include "renderer.h" -#include "scene.h" -#include "shader.h" +#include "sokol_app.h" #include "utils.h" -// clang-format off -#include "glad/glad.h" -#include "GLFW/glfw3.h" -// clang-format on - -#include "human.h" - #include "box3d/box3d.h" +#include +#include #include #include +#include +#include // Load a file. You must free the character array. static char* ReadFile( int& size, const char* filename ) @@ -57,105 +60,53 @@ static char* ReadFile( int& size, const char* filename ) static const char* settingsFileName = "settings.ini"; -void Arena::Create( int byteCount ) +// Polled key state, fed from the host event loop (see main.cpp). Indexed by +// sokol keycode; samples read it through the KEY_* aliases in gfx/keycodes.h. +static bool s_keyDown[512]; + +bool IsKeyDown( int key ) { - data = (char*)malloc( byteCount ); - capacity = byteCount; - index = 0; + return (unsigned)key < 512u ? s_keyDown[key] : false; } -void Arena::Destroy() +void SetKeyDown( int key, bool down ) { - free( data ); - data = nullptr; - capacity = 0; - index = 0; -} - -void* Arena::Allocate( int byteCount ) -{ - if ( index + byteCount > capacity ) + if ( (unsigned)key < 512u ) { - assert( false ); - return nullptr; + s_keyDown[key] = down; } - - void* mem = data + index; - index += byteCount; - return mem; -} - -void Arena::Clear() -{ - index = 0; -} - -static bool DrawShapeCallback( void* userShape, b3Transform transform, b3HexColor color, void* context ) -{ - DebugShape* shape = (DebugShape*)userShape; - SampleContext* sampleContext = (SampleContext*)context; - float alpha = sampleContext->transparentDynamic && shape->bodyType != b3_staticBody ? 0.6f : 1.0f; - DrawDebugShape( sampleContext->scene, shape, transform, color, alpha ); - return true; -} - -static void DrawPointCallback( b3Vec3 point, float size, b3HexColor color, void* context ) -{ - SampleContext* sampleContext = (SampleContext*)context; - DrawPoint( sampleContext->scene, point, size, color ); -} - -static void DrawLineCallback( b3Vec3 vertex1, b3Vec3 vertex2, b3HexColor color, void* context ) -{ - SampleContext* sampleContext = (SampleContext*)context; - DrawLine( sampleContext->scene, vertex1, vertex2, color ); -} - -static void DrawBoundsCallback( b3AABB bounds, b3HexColor color, void* context ) -{ - SampleContext* sampleContext = (SampleContext*)context; - float extension = 0.0f; - DrawBounds( sampleContext->scene, bounds, extension, color ); -} - -static void DrawBoxCallback( b3Vec3 extents, b3Transform transform, b3HexColor color, void* context ) -{ - SampleContext* sampleContext = (SampleContext*)context; - DrawBox( sampleContext->scene, extents, transform, color ); -} - -static void DrawTransformCallback( b3Transform transform, void* context ) -{ - SampleContext* sampleContext = (SampleContext*)context; - DrawTransform( sampleContext->scene, transform, 0.25f ); -} - -static void DrawSceneTextCallback( b3Vec3 position, const char* text, b3HexColor color, void* context ) -{ - SampleContext* sampleContext = (SampleContext*)context; - DrawWorldString( &sampleContext->camera, position, color, text ); } void SampleContext::Save() { + const b3DebugDraw* gd = GetGuiDraw(); + int gtaoQuality = GetGtaoTraceParams().quality; + FILE* file = fopen( settingsFileName, "w" ); + if ( file == nullptr ) + { + return; + } fprintf( file, "{\n" ); fprintf( file, " \"sampleIndex\": %d,\n", sampleIndex ); - fprintf( file, " \"drawShapes\": %s,\n", debugDraw.drawShapes ? "true" : "false" ); - fprintf( file, " \"drawJoints\": %s,\n", debugDraw.drawJoints ? "true" : "false" ); - fprintf( file, " \"drawContacts\": %s,\n", debugDraw.drawContacts ? "true" : "false" ); - fprintf( file, " \"drawImpulses\": %s,\n", debugDraw.drawContactForces ? "true" : "false" ); - fprintf( file, " \"drawBounds\": %s,\n", debugDraw.drawBounds ? "true" : "false" ); - fprintf( file, " \"drawCounters\": %s,\n", drawCounters ? "true" : "false" ); - fprintf( file, " \"drawProfile\": %s,\n", drawProfile ? "true" : "false" ); - fprintf( file, " \"transparent\": %s,\n", transparent ? "true" : "false" ); - fprintf( file, " \"enableSleep\": %s\n", enableSleep ? "true" : "false" ); - fprintf( file, " \"enableContinuous\": %s,\n", enableContinuous ? "true" : "false" ); + fprintf( file, " \"drawShapes\": %s,\n", gd->drawShapes ? "true" : "false" ); + fprintf( file, " \"drawJoints\": %s,\n", gd->drawJoints ? "true" : "false" ); + fprintf( file, " \"drawContacts\": %s,\n", gd->drawContacts ? "true" : "false" ); + fprintf( file, " \"showDiagnostics\": %s,\n", showMetrics ? "true" : "false" ); + fprintf( file, " \"enableShadows\": %s,\n", enableShadows ? "true" : "false" ); + fprintf( file, " \"enableGtao\": %s,\n", enableGtao ? "true" : "false" ); + fprintf( file, " \"gtaoQuality\": %d,\n", gtaoQuality ); + fprintf( file, " \"enableIbl\": %s,\n", GetIblEnabled() ? "true" : "false" ); + fprintf( file, " \"exposure\": %g,\n", GetExposure() ); + fprintf( file, " \"sunStrength\": %g,\n", GetSun().strength ); + fprintf( file, " \"debugView\": %d,\n", debugView ); + fprintf( file, " \"showHullEdges\": %s,\n", GetEdgeOverlayParams().showHulls ? "true" : "false" ); + fprintf( file, " \"showEdgeConvexity\": %s\n", GetEdgeOverlayParams().showEdgeConvexity ? "true" : "false" ); fprintf( file, "}\n" ); fclose( file ); } -#define MAX_TOKENS 32 +#define MAX_TOKENS 64 static int jsoneq( const char* json, jsmntok_t* tok, const char* s ) { @@ -169,16 +120,6 @@ static int jsoneq( const char* json, jsmntok_t* tok, const char* s ) void SampleContext::Load() { - debugDraw = b3DefaultDebugDraw(); - debugDraw.DrawShapeFcn = DrawShapeCallback; - debugDraw.DrawSegmentFcn = DrawLineCallback; - debugDraw.DrawPointFcn = DrawPointCallback; - debugDraw.DrawBoundsFcn = DrawBoundsCallback; - debugDraw.DrawBoxFcn = DrawBoxCallback; - debugDraw.DrawTransformFcn = DrawTransformCallback; - debugDraw.DrawStringFcn = DrawSceneTextCallback; - debugDraw.context = this; - recycleDistance = B3_CONTACT_RECYCLE_DISTANCE; int size = 0; @@ -212,22 +153,101 @@ void SampleContext::Load() { sampleIndex = 0; } - else if ( sampleIndex >= SampleManager::sEntryCount ) + else if ( sampleIndex >= g_sampleCount ) { - sampleIndex = SampleManager::sEntryCount - 1; + sampleIndex = g_sampleCount - 1; } } else if ( jsoneq( data, &tokens[i], "drawShapes" ) == 0 ) { const char* s = data + tokens[i + 1].start; - if ( strncmp( s, "true", 4 ) == 0 ) - { - debugDraw.drawShapes = true; - } - else if ( strncmp( s, "false", 5 ) == 0 ) - { - debugDraw.drawShapes = false; - } + GetGuiDraw()->drawShapes = strncmp( s, "true", 4 ) == 0; + } + else if ( jsoneq( data, &tokens[i], "drawJoints" ) == 0 ) + { + const char* s = data + tokens[i + 1].start; + GetGuiDraw()->drawJoints = strncmp( s, "true", 4 ) == 0; + } + else if ( jsoneq( data, &tokens[i], "drawContacts" ) == 0 ) + { + const char* s = data + tokens[i + 1].start; + GetGuiDraw()->drawContacts = strncmp( s, "true", 4 ) == 0; + } + else if ( jsoneq( data, &tokens[i], "showDiagnostics" ) == 0 ) + { + const char* s = data + tokens[i + 1].start; + showMetrics = strncmp( s, "true", 4 ) == 0; + } + else if ( jsoneq( data, &tokens[i], "enableShadows" ) == 0 ) + { + const char* s = data + tokens[i + 1].start; + enableShadows = strncmp( s, "true", 4 ) == 0; + } + else if ( jsoneq( data, &tokens[i], "enableGtao" ) == 0 ) + { + const char* s = data + tokens[i + 1].start; + enableGtao = strncmp( s, "true", 4 ) == 0; + } + else if ( jsoneq( data, &tokens[i], "gtaoQuality" ) == 0 ) + { + int count = tokens[i + 1].end - tokens[i + 1].start; + assert( count < 32 ); + const char* s = data + tokens[i + 1].start; + strncpy( buffer, s, count ); + buffer[count] = 0; + int quality = b3ClampInt( (int)strtol( buffer, nullptr, 10 ), 0, 2 ); + + GtaoTraceParams p = GetGtaoTraceParams(); + p.quality = (AmbientOcclusionQuality)quality; + SetGtaoTraceParams( p ); + } + else if ( jsoneq( data, &tokens[i], "enableIbl" ) == 0 ) + { + const char* s = data + tokens[i + 1].start; + SetIblEnabled( strncmp( s, "true", 4 ) == 0 ); + } + else if ( jsoneq( data, &tokens[i], "exposure" ) == 0 ) + { + int count = tokens[i + 1].end - tokens[i + 1].start; + assert( count < 32 ); + const char* s = data + tokens[i + 1].start; + strncpy( buffer, s, count ); + buffer[count] = 0; + SetExposure( strtof( buffer, nullptr ) ); + } + else if ( jsoneq( data, &tokens[i], "sunStrength" ) == 0 ) + { + int count = tokens[i + 1].end - tokens[i + 1].start; + assert( count < 32 ); + const char* s = data + tokens[i + 1].start; + strncpy( buffer, s, count ); + buffer[count] = 0; + Sun sun = GetSun(); + sun.strength = strtof( buffer, nullptr ); + SetSun( sun ); + } + else if ( jsoneq( data, &tokens[i], "debugView" ) == 0 ) + { + int count = tokens[i + 1].end - tokens[i + 1].start; + assert( count < 32 ); + const char* s = data + tokens[i + 1].start; + strncpy( buffer, s, count ); + buffer[count] = 0; + debugView = b3ClampInt( (int)strtol( buffer, nullptr, 10 ), 0, 4 ); + } + else if ( jsoneq( data, &tokens[i], "showHullEdges" ) == 0 ) + { + const char* s = data + tokens[i + 1].start; + EdgeOverlayParams p = GetEdgeOverlayParams(); + p.showHulls = strncmp( s, "true", 4 ) == 0; + SetEdgeOverlayParams( &p ); + } + else if ( jsoneq( data, &tokens[i], "showEdgeConvexity" ) == 0 ) + { + const char* s = data + tokens[i + 1].start; + EdgeOverlayParams p = GetEdgeOverlayParams(); + p.showEdgeConvexity = strncmp( s, "true", 4 ) == 0; + SetEdgeOverlayParams( &p ); } } @@ -237,10 +257,14 @@ void SampleContext::Load() Sample::Sample( SampleContext* context ) { m_context = context; - m_window = context->window; - m_scene = m_context->scene; m_camera = &m_context->camera; + if ( m_camera->m_thirdPerson ) + { + sapp_lock_mouse( false ); + m_camera->m_thirdPerson = false; + } + m_worldId = b3_nullWorldId; m_mouseBodyId = {}; @@ -274,9 +298,9 @@ Sample::Sample( SampleContext* context ) Sample::~Sample() { + ResetAdapterPool(); + ResetGroundShapeId(); b3DestroyWorld( m_worldId ); - - DestroySharedMeshes( m_context->scene ); } void Sample::CreateWorld( b3Capacity* capacity ) @@ -293,10 +317,8 @@ void Sample::CreateWorld( b3Capacity* capacity ) b3WorldDef worldDef = b3DefaultWorldDef(); worldDef.workerCount = m_context->workerCount; worldDef.enableSleep = m_context->enableSleep; - worldDef.createDebugShape = CreateDebugShape; - worldDef.destroyDebugShape = DestroyDebugShape; - worldDef.userDebugShapeContext = m_context; - if (capacity != nullptr) + AttachToWorldDef( &worldDef ); + if ( capacity != nullptr ) { worldDef.capacity = *capacity; } @@ -305,6 +327,21 @@ void Sample::CreateWorld( b3Capacity* capacity ) b3World_SetContactRecycleDistance( m_worldId, m_context->recycleDistance ); } +void Sample::ResetText() +{ + // Below the menu bar when the UI shows. Hidden, the minimal HUD owns the + // top-left, so start lower. + float fontSize = ImGui::GetFontSize(); + if ( m_context->showUI ) + { + m_textLine = (int)( ImGui::GetFrameHeight() + 0.5f * fontSize ); + } + else + { + m_textLine = (int)( 3.0f * fontSize ); + } +} + void Sample::Step() { m_didStep = false; @@ -342,11 +379,6 @@ void Sample::Step() b3World_Step( m_worldId, timeStep, m_context->subStepCount ); } - // if (glfwGetKey( m_window, 'F' )) - //{ - // b3World_DumpShapeBounds( m_worldId, b3_staticBody ); - // } - if ( timeStep > 0.0f ) { m_stepCount += 1; @@ -367,12 +399,11 @@ void Sample::Step() m_userMaterialId = 0; { - double screenX, screenY; - glfwGetCursorPos( m_window, &screenX, &screenY ); - PickRay pickRay = m_camera->BuildPickRay( (float)screenX, (float)screenY ); + PickRay pickRay = m_camera->BuildPickRay( m_context->mouseX, m_context->mouseY ); b3RayResult result = b3World_CastRayClosest( m_worldId, pickRay.origin, pickRay.translation, b3DefaultQueryFilter() ); + b3BodyId hovered = b3_nullBodyId; if ( result.hit ) { b3ShapeType type = b3Shape_GetType( result.shapeId ); @@ -382,19 +413,33 @@ void Sample::Step() } m_userMaterialId = result.userMaterialId; + + // Only dynamic bodies highlight, so the static ground never lights up. + b3BodyId bodyId = b3Shape_GetBody( result.shapeId ); + if ( b3Body_GetType( bodyId ) == b3_dynamicBody ) + { + hovered = bodyId; + } } + + SetHoveredBody( hovered ); } } void Sample::Render() { - // Draw world - b3Vec3 position = m_context->camera.GetPosition(); - b3Vec3 r = { 1000.0f, 1000.0f, 1000.0f }; - b3AABB bounds = { position - r, position + r }; - m_context->debugDraw.drawingBounds = bounds; + b3DebugDraw debugDraw; + MakeDebugDraw( &debugDraw ); - b3World_Draw( m_worldId, &m_context->debugDraw, B3_DEFAULT_MASK_BITS ); + // Generous visible volume around the eye. Box3D uses this to decide which + // shapes enter the draw set and lazily fire createDebugShape. + b3Vec3 position = m_camera->GetPosition(); + b3Vec3 r = { 1000.0f, 1000.0f, 1000.0f }; + debugDraw.drawingBounds = { position - r, position + r }; + + ApplyGuiFlags( &debugDraw ); + + b3World_Draw( m_worldId, &debugDraw, B3_DEFAULT_MASK_BITS ); } void Sample::ResetProfile() @@ -406,16 +451,73 @@ void Sample::ResetProfile() m_profileWriteIndex = 0; } -void Sample::UpdateUI() +b3BodyId Sample::AddGroundBox( float extent ) { - float fontSize = ImGui::GetFontSize(); + b3BodyDef bodyDef = b3DefaultBodyDef(); + bodyDef.name = "ground"; + bodyDef.position = { 0.0f, -1.0f, 0.0f }; + b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - if ( m_context->drawProfile ) + b3ShapeDef shapeDef = b3DefaultShapeDef(); + b3BoxHull hull = b3MakeBoxHull( extent, 1.0f, extent ); + b3ShapeId shapeId = b3CreateHullShape( groundId, &shapeDef, &hull.base ); + + // Draw the ground with the procedural grid material + SetGroundShape( shapeId ); + + return groundId; +} + +struct RowDef +{ + const char* name; + int indent; + ImU32 color; +}; + +float AddSegment( ImDrawList* dl, float availWidth, float t, float stepNow, ImU32 col, float x, ImVec2 cursor, float barHeight ) +{ + float w = availWidth * ( t / stepNow ); + if ( w > 0.0f ) { - ImGui::SetNextWindowPos( { fontSize, 8.0f * fontSize }, ImGuiCond_FirstUseEver ); - ImGui::Begin( "Profile (ms)", nullptr, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_AlwaysAutoResize ); + dl->AddRectFilled( ImVec2( x, cursor.y ), ImVec2( x + w, cursor.y + barHeight ), col ); + x += w; + } - const int count = static_cast( m_profileWriteIndex - m_profileReadIndex ); + return x; +} + +// Bottom diagnostics drawer (M). Tabs: Profile, Counters, Renderer, and the +// optional ImPlot frame-time chart. Anchored along the window bottom, clear +// of the right info panel. +void Sample::DrawMetrics() +{ + if ( m_context->showMetrics == false ) + { + return; + } + + float fontSize = ImGui::GetFontSize(); + float menuWidth = 14.0f * fontSize; + float drawerHeight = 16.0f * fontSize; + float drawerWidth = m_camera->m_width - menuWidth - 1.5f * fontSize; + + ImGui::SetNextWindowPos( { 0.5f * fontSize, m_camera->m_height - drawerHeight - 0.5f * fontSize } ); + ImGui::SetNextWindowSize( { drawerWidth, drawerHeight } ); + + ImGui::Begin( "Metrics", nullptr, + ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | + ImGuiWindowFlags_NoTitleBar ); + + if ( ImGui::BeginTabBar( "MetricsTabs", ImGuiTabBarFlags_None ) == false ) + { + ImGui::End(); + return; + } + + if ( ImGui::BeginTabItem( "Profile" ) ) + { + int count = m_profileWriteIndex - m_profileReadIndex; // Unroll ring buffer into per-field histories. constexpr int kRowCount = 22; @@ -423,7 +525,7 @@ void Sample::UpdateUI() float totals[kRowCount] = {}; for ( int i = 0; i < count; ++i ) { - int idx = static_cast( ( m_profileReadIndex + i ) & ( m_profileCapacity - 1 ) ); + int idx = ( m_profileReadIndex + i ) & ( m_profileCapacity - 1 ); const b3Profile& p = m_profiles[idx]; histories[0][i] = p.step; histories[1][i] = p.pairs; @@ -472,31 +574,25 @@ void Sample::UpdateUI() totals[21] += p.sensors; } - const b3Profile& cur = m_profiles[m_currentProfileIndex]; - const float now[kRowCount] = { - cur.step, - cur.pairs, - cur.collide, - cur.solve, - cur.solverSetup, - cur.constraints, - cur.prepareConstraints, - cur.integrateVelocities, - cur.warmStart, - cur.solveImpulses, - cur.integratePositions, - cur.relaxImpulses, - cur.applyRestitution, - cur.storeImpulses, - cur.splitIslands, - cur.transforms, - cur.jointEvents, - cur.hitEvents, - cur.refit, - cur.sleepIslands, - cur.bullets, - cur.sensors, - }; + // Smoothed over the last few frames so bars don't jitter visibly. + constexpr int kNowWindow = 10; + float now[kRowCount] = {}; + { + int n = count < kNowWindow ? count : kNowWindow; + if ( n > 0 ) + { + float inv = 1.0f / n; + for ( int r = 0; r < kRowCount; ++r ) + { + float sum = 0.0f; + for ( int i = count - n; i < count; ++i ) + { + sum += histories[r][i]; + } + now[r] = sum * inv; + } + } + } // Rolling average float avg[kRowCount] = {}; @@ -509,27 +605,36 @@ void Sample::UpdateUI() } } + float rowMax[kRowCount] = {}; + for ( int r = 0; r < kRowCount; ++r ) + { + for ( int i = 0; i < count; ++i ) + { + if ( histories[r][i] > rowMax[r] ) + { + rowMax[r] = histories[r][i]; + } + } + } + // Match Frame Time chart's first three colors so rows read with the line plot. const ImU32 colorStep = IM_COL32( 102, 153, 255, 255 ); + const ImU32 colorPairs = IM_COL32( 220, 220, 220, 255 ); const ImU32 colorCollide = IM_COL32( 255, 140, 51, 255 ); const ImU32 colorSolve = IM_COL32( 102, 204, 102, 255 ); + const ImU32 colorSensors = IM_COL32( 200, 120, 220, 255 ); + const ImU32 colorOther = IM_COL32( 90, 90, 90, 255 ); const ImU32 colorDefault = IM_COL32( 220, 220, 220, 255 ); - struct RowDef - { - const char* name; - int indent; - ImU32 color; - }; const RowDef rows[kRowCount] = { - { "step", 0, colorStep }, { "pairs", 0, colorDefault }, { "collide", 0, colorCollide }, + { "step", 0, colorStep }, { "pairs", 0, colorPairs }, { "collide", 0, colorCollide }, { "solve", 0, colorSolve }, { "setup", 1, colorDefault }, { "constraints", 1, colorDefault }, { "prepare", 2, colorDefault }, { "velocities", 2, colorDefault }, { "warm start", 2, colorDefault }, { "bias", 2, colorDefault }, { "positions", 2, colorDefault }, { "relax", 2, colorDefault }, { "restitution", 2, colorDefault }, { "store", 2, colorDefault }, { "split islands", 2, colorDefault }, { "transforms", 1, colorDefault }, { "joint events", 1, colorDefault }, { "hit events", 1, colorDefault }, { "refit BVH", 1, colorDefault }, { "sleep", 1, colorDefault }, { "bullets", 1, colorDefault }, - { "sensors", 0, colorDefault }, + { "sensors", 0, colorSensors }, }; // Derive parent/child links from the indent levels so we can collapse subtrees. @@ -557,7 +662,7 @@ void Sample::UpdateUI() static bool s_showPlots = false; // Bars are drawn relative to the step row so the proportions are visually consistent. - const float stepNow = b3MaxFloat( cur.step, 0.001f ); + const float stepNow = b3MaxFloat( now[0], 0.001f ); if ( ImGui::Button( "Reset" ) ) { @@ -565,11 +670,38 @@ void Sample::UpdateUI() } ImGui::SameLine(); ImGui::Checkbox( "Show plots", &s_showPlots ); + ImGui::SameLine(); + ImGui::Text( " step %.2f ms", now[0] ); - const ImGuiTableFlags tableFlags = ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit; + // Flame strip: step subdivided by top-level children. + { + float pairsT = now[1]; + float collideT = now[2]; + float solveT = now[3]; + float sensorsT = now[21]; + float otherT = b3MaxFloat( stepNow - pairsT - collideT - solveT - sensorsT, 0.0f ); + + float availWidth = ImGui::GetContentRegionAvail().x; + float barHeight = 1.5f * fontSize; + ImDrawList* dl = ImGui::GetWindowDrawList(); + ImVec2 cursor = ImGui::GetCursorScreenPos(); + float x = cursor.x; + + x = AddSegment( dl, availWidth, pairsT, stepNow, colorPairs, x, cursor, barHeight ); + x = AddSegment( dl, availWidth, collideT, stepNow, colorCollide, x, cursor, barHeight ); + x = AddSegment( dl, availWidth, solveT, stepNow, colorSolve, x, cursor, barHeight ); + x = AddSegment( dl, availWidth, sensorsT, stepNow, colorSensors, x, cursor, barHeight ); + x = AddSegment( dl, availWidth, otherT, stepNow, colorOther, x, cursor, barHeight ); + + ImGui::Dummy( ImVec2( availWidth, barHeight ) ); + } + + const ImGuiTableFlags tableFlags = + ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_ScrollY; const int colCount = s_showPlots ? 6 : 5; - if ( ImGui::BeginTable( "profile", colCount, tableFlags ) ) + ImVec2 tableSize = ImGui::GetContentRegionAvail(); + if ( ImGui::BeginTable( "profile", colCount, tableFlags, tableSize ) ) { ImGui::TableSetupColumn( "section", ImGuiTableColumnFlags_WidthFixed, 8.0f * fontSize ); ImGui::TableSetupColumn( "now", ImGuiTableColumnFlags_WidthFixed, 3.0f * fontSize ); @@ -600,15 +732,15 @@ void Sample::UpdateUI() continue; } + // Hide leaf rows that are entirely zero. Parents stay so structure reads. + if ( !hasChildren[r] && now[r] == 0.0f && avg[r] == 0.0f && rowMax[r] == 0.0f ) + { + continue; + } + const RowDef& d = rows[r]; const float* hist = histories[r]; - float rollingMax = 0.0f; - for ( int i = 0; i < count; ++i ) - { - rollingMax = b3MaxFloat( rollingMax, hist[i] ); - } - ImGui::TableNextRow(); ImGui::TableNextColumn(); @@ -643,7 +775,7 @@ void Sample::UpdateUI() ImGui::TableNextColumn(); ImGui::Text( "%6.2f", avg[r] ); ImGui::TableNextColumn(); - ImGui::Text( "%6.2f", rollingMax ); + ImGui::Text( "%6.2f", rowMax[r] ); ImGui::TableNextColumn(); float frac = b3ClampFloat( now[r] / stepNow, 0.0f, 1.0f ); @@ -659,7 +791,7 @@ void Sample::UpdateUI() char id[16]; snprintf( id, sizeof( id ), "##h%d", r ); ImGui::PushStyleColor( ImGuiCol_PlotLines, d.color ); - ImGui::PlotLines( id, hist, count, 0, nullptr, 0.0f, rollingMax * 1.05f + 0.001f, + ImGui::PlotLines( id, hist, count, 0, nullptr, 0.0f, rowMax[r] * 1.05f + 0.001f, ImVec2( -FLT_MIN, rowHeight ) ); ImGui::PopStyleColor(); } @@ -668,11 +800,12 @@ void Sample::UpdateUI() ImGui::EndTable(); } - ImGui::End(); + ImGui::EndTabItem(); } - if ( m_context->drawCounters ) + if ( ImGui::BeginTabItem( "Counters" ) ) { + ImGui::BeginChild( "##counters_scroll" ); b3Counters s = b3World_GetCounters( m_worldId ); constexpr int colorCount = sizeof( s.colorCounts ) / sizeof( s.colorCounts[0] ); const int overflowIndex = colorCount - 1; @@ -702,9 +835,6 @@ void Sample::UpdateUI() } } - ImGui::SetNextWindowPos( { fontSize, 8.0f * fontSize }, ImGuiCond_FirstUseEver ); - ImGui::Begin( "Counters", nullptr, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_AlwaysAutoResize ); - ImGui::Text( "bodies/shapes/contacts/joints = %d/%d/%d/%d", s.bodyCount, s.shapeCount, s.contactCount, s.jointCount ); { float frac = s.awakeContactCount > 0 @@ -793,7 +923,7 @@ void Sample::UpdateUI() ImGui::Text( "%d manifolds across %d buckets", totalManifolds, manifoldBucketCount ); if ( ImGui::BeginTable( "manifolds", 3, tableFlags ) ) { - ImGui::TableSetupColumn( "points", ImGuiTableColumnFlags_WidthFixed, 3.5f * fontSize ); + ImGui::TableSetupColumn( "manifolds", ImGuiTableColumnFlags_WidthFixed, 3.5f * fontSize ); ImGui::TableSetupColumn( "count", ImGuiTableColumnFlags_WidthFixed, 5.0f * fontSize ); ImGui::TableSetupColumn( "share", ImGuiTableColumnFlags_WidthFixed, 16.0f * fontSize ); ImGui::TableHeadersRow(); @@ -823,21 +953,59 @@ void Sample::UpdateUI() ImGui::EndTable(); } - ImGui::End(); + ImGui::EndChild(); + ImGui::EndTabItem(); } - if ( m_context->frameTime ) + if ( ImGui::BeginTabItem( "Renderer" ) ) { - float frameTimeHeight = 400.0f; - float frameTimeWidth = 800.0f; + const RenderStats st = GetRenderStats(); - ImGui::SetNextWindowPos( { 30.0f, 30.0f }, ImGuiCond_FirstUseEver ); - ImGui::SetNextWindowSize( { frameTimeWidth, frameTimeHeight }, ImGuiCond_FirstUseEver ); + // Display-link frame time vs the RenderFrame submit cost, both + // EMA-smoothed so the readout doesn't flicker. + const float frameMs = (float)( sapp_frame_duration() * 1000.0 ); + static float smoothedFrameMs = 0.0f; + static float smoothedCpuMs = 0.0f; + smoothedFrameMs = ( smoothedFrameMs <= 0.0f ) ? frameMs : smoothedFrameMs * 0.9f + frameMs * 0.1f; + smoothedCpuMs = ( smoothedCpuMs <= 0.0f ) ? st.frameTimeMs : smoothedCpuMs * 0.9f + st.frameTimeMs * 0.1f; + const float fps = ( smoothedFrameMs > 0.0f ) ? ( 1000.0f / smoothedFrameMs ) : 0.0f; - ImGui::Begin( "Frame Time", nullptr, ImGuiWindowFlags_NoCollapse ); + const char* backend = "?"; + switch ( sg_query_backend() ) + { + case SG_BACKEND_D3D11: + backend = "D3D11"; + break; + case SG_BACKEND_METAL_MACOS: + backend = "Metal"; + break; + case SG_BACKEND_GLCORE: + backend = "GLCORE"; + break; + case SG_BACKEND_GLES3: + backend = "GLES3"; + break; + case SG_BACKEND_WGPU: + backend = "WGPU"; + break; + default: + break; + } - ImGui::PushItemWidth( ImGui::GetWindowWidth() - 20.0f ); + ImGui::Text( "%s %.2f ms (%.0f FPS) CPU %.2f ms", backend, smoothedFrameMs, fps, smoothedCpuMs ); + ImGui::Text( "draw calls %d (approx)", st.drawCallCount ); + ImGui::Separator(); + ImGui::Text( "opaque cubes %d spheres %d capsules %d geom %d (%d spans)", st.cubeCount, st.sphereCount, + st.capsuleCount, st.geomInstanceCount, st.geomSpanCount ); + ImGui::Text( "transp. cubes %d spheres %d capsules %d geom %d", st.cubeCountXp, st.sphereCountXp, st.capsuleCountXp, + st.geomInstanceCountXp ); + ImGui::Text( "overlays lines %d points %d", st.lineCount, st.pointCount ); + ImGui::EndTabItem(); + } + + if ( ImGui::BeginTabItem( "Frame Time" ) ) + { float maxValue = 0.0f; float times[m_profileCapacity]; float stepTimes[m_profileCapacity]; @@ -854,27 +1022,28 @@ void Sample::UpdateUI() maxValue = b3MaxFloat( stepTimes[i], maxValue ); } - // This is the pixel size, not the range. - ImVec2 plotSize = { -1, 22.0f * ImGui::GetTextLineHeight() }; + ImVec2 plotSize = ImGui::GetContentRegionAvail(); if ( ImPlot::BeginPlot( "Profile", plotSize, ImPlotFlags_NoTitle ) ) { ImPlot::SetupAxes( "t", "ms" ); - ImPlot::SetupAxes( "t", "ms", 0, ImPlotAxisFlags_AutoFit | ImPlotAxisFlags_RangeFit ); - ImPlot::SetupAxesLimits( 0, m_profileCapacity / 60.0, 0.0, maxValue ); + ImPlot::SetupAxisLimits( ImAxis_X1, 0.0, m_profileCapacity / 60.0 ); + ImPlot::SetupAxisLimits( ImAxis_Y1, 0.0, b3MaxFloat( maxValue, 1.0f ) * 1.05, ImPlotCond_Always ); ImPlot::PlotLine( "step", times, stepTimes, count ); ImPlot::PlotLine( "collide", times, collideTimes, count ); ImPlot::PlotLine( "solve", times, solveTimes, count ); ImPlot::EndPlot(); } - ImGui::PopItemWidth(); - ImGui::End(); + ImGui::EndTabItem(); } + + ImGui::EndTabBar(); + ImGui::End(); } void Sample::MouseDown( b3Vec2 p, int button, int modifiers ) { - if ( modifiers == 0 ) + if ( button == 0 && modifiers == 0 ) { PickRay pickRay = m_camera->BuildPickRay( p.x, p.y ); @@ -892,6 +1061,16 @@ void Sample::MouseDown( b3Vec2 p, int button, int modifiers ) b3BodyId bodyId = b3Shape_GetBody( result.shapeId ); + // A plain click also sets the selection. Dynamic only, matching hover. + if ( b3Body_GetType( bodyId ) == b3_dynamicBody ) + { + SetSelectedBody( bodyId ); + } + else + { + ClearSelection(); + } + b3MotorJointDef jointDef = b3DefaultMotorJointDef(); jointDef.base.bodyIdA = m_mouseBodyId; jointDef.base.bodyIdB = bodyId; @@ -918,14 +1097,19 @@ void Sample::MouseDown( b3Vec2 p, int button, int modifiers ) m_mouseFraction = result.fraction; } + else + { + // Click into empty space clears the selection. + ClearSelection(); + } } - else if ( modifiers & GLFW_MOD_SHIFT ) + else if ( modifiers & MOD_SHIFT ) { PickRay pickRay = m_camera->BuildPickRay( p.x, p.y ); b3Vec3 direction = b3Normalize( pickRay.translation ); b3ShapeDef shapeDef = b3DefaultShapeDef(); - if ( modifiers & GLFW_MOD_CONTROL ) + if ( modifiers & MOD_CTRL ) { b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.type = b3_dynamicBody; @@ -937,11 +1121,12 @@ void Sample::MouseDown( b3Vec2 p, int button, int modifiers ) b3CreateHullShape( bodyId, &shapeDef, hull ); b3DestroyHull( hull ); } - else if ( modifiers & GLFW_MOD_ALT ) + else if ( modifiers & MOD_ALT ) { b3Vec3 position = pickRay.origin + 2.0f * direction; Human human = {}; CreateHuman( &human, m_worldId, position, 1.0f, 1.0f, 1.0f, 0, nullptr, true ); + Human_SetBullet( &human, true ); Human_SetVelocity( &human, ( 5.0f * m_launchSpeedScale ) * direction ); } else @@ -975,36 +1160,28 @@ void Sample::MouseUp( b3Vec2 p, int button ) m_mouseJointId = b3_nullJointId; m_mouseBodyId = b3_nullBodyId; m_mouseFraction = 0.0f; + + ClearSelection(); } void Sample::MouseMove( b3Vec2 p ) { if ( m_camera->m_thirdPerson ) { - if ( m_haveMouseLast == false ) - { - m_mouseLast = p; - m_haveMouseLast = true; - } - else - { - m_mouseDelta = { p.x - m_mouseLast.x, p.y - m_mouseLast.y }; - // printf( "mdx = %g, mdy = %g\n", m_mouseDelta.x, m_mouseDelta.y ); - m_mouseLast = p; - } + // The cursor is locked in third person, so look uses the host's + // relative deltas. Camera angles are radians here (host camera). + m_mouseDelta = { m_context->mouseDX, m_context->mouseDY }; - const float sensitivity = 0.1f; + const float sensitivity = 0.1f * B3_DEG_TO_RAD; m_camera->m_yaw -= 2.0f * sensitivity * m_mouseDelta.x; m_camera->m_pitch += sensitivity * m_mouseDelta.y; - m_camera->m_pitch = b3ClampFloat( m_camera->m_pitch, -85.0f, 85.0f ); + m_camera->m_pitch = b3ClampFloat( m_camera->m_pitch, -85.0f * B3_DEG_TO_RAD, 85.0f * B3_DEG_TO_RAD ); } PickRay pickRay = m_camera->BuildPickRay( p.x, p.y ); if ( B3_IS_NON_NULL( m_mouseJointId ) ) { m_mousePoint = pickRay.origin + m_mouseFraction * pickRay.translation; - // b3Transform localFrameA = { target, b3Quat_identity }; - // b3Joint_SetLocalFrameA( m_mouseJointId, localFrameA ); } } @@ -1014,405 +1191,662 @@ void Sample::DrawTextLine( const char* text, ... ) va_start( args, text ); char buffer[512]; vsnprintf( buffer, sizeof( buffer ), text, args ); - DrawText( 5, m_textLine, b3_colorWhite, buffer ); va_end( args ); + DrawScreenString( 5, m_textLine, MakeColor( b3_colorWhite ), buffer ); m_textLine += m_textIncrement; } -SampleEntry SampleManager::sEntries[MAX_SAMPLES]; -int SampleManager::sEntryCount = 0; +SampleEntry g_sampleEntries[MAX_SAMPLES]; +int g_sampleCount = 0; -int SampleManager::Register( const char* category, const char* name, SampleCreateFcn* fcn ) +int RegisterSample( const char* category, const char* name, SampleCreateFcn* fcn ) { - int index = sEntryCount; + int index = g_sampleCount; if ( index < MAX_SAMPLES ) { - sEntries[index] = { category, name, fcn }; - sEntryCount += 1; + g_sampleEntries[index] = { category, name, fcn }; + g_sampleCount += 1; return index; } return -1; } -static int CompareSamples( const void* a, const void* b ) +void SelectSample( SampleContext* context, int selection, bool restart ) { - SampleEntry* entryA = (SampleEntry*)a; - SampleEntry* entryB = (SampleEntry*)b; - - int result = strcmp( entryA->Category, entryB->Category ); - if ( result == 0 ) + if ( selection < 0 || selection >= g_sampleCount ) { - result = strcmp( entryA->Name, entryB->Name ); - } - - return result; -} - -void SampleManager::Startup( GLFWwindow* window, int width, int height, int bufferWidth, int bufferHeight ) -{ - m_context.Load(); - - m_context.workerCount = b3MinInt( 8, GetNumberOfCores() / 2 ); - - // todo_erin testing - // m_context.settings.workerCount = 1; - - m_context.arena.Create( 400 * 1024 * 1024 ); - m_context.window = window; - m_context.camera.Resize( width, height ); - - assert( bufferWidth > 0 && bufferHeight > 0 ); - m_context.camera.m_bufferWidth = bufferWidth; - m_context.camera.m_bufferHeight = bufferHeight; - m_context.scene = CreateScene( &m_context.camera, m_context.arena ); - - if ( m_context.scene == nullptr ) - { - fprintf( stderr, "Failed to create scene\n" ); - glfwTerminate(); - } - - qsort( sEntries, sEntryCount, sizeof( SampleEntry ), CompareSamples ); - - m_sample = sEntries[m_context.sampleIndex].CreateFcn( &m_context ); -} - -void SampleManager::Step() -{ - const SampleEntry* entry = sEntries + m_context.sampleIndex; - DrawFormat( 5, m_sample->m_textIncrement, b3_colorCyan, "%s : %s", entry->Category, entry->Name ); - m_sample->m_textLine = 2 * m_sample->m_textIncrement; - - if ( m_context.pause ) - { - m_sample->DrawTextLine( "****PAUSED****" ); - } - - m_sample->Step(); -} - -void SampleManager::Resize( int width, int height, int bufferWidth, int bufferHeight ) -{ - m_context.minimized = false; - if ( width == 0 || height == 0 || bufferWidth == 0 || bufferHeight == 0 ) - { - m_context.minimized = true; + // Out of range: keep the current sample rather than calling a null factory. return; } - m_context.camera.Resize( width, height ); - m_context.camera.m_bufferWidth = bufferWidth; - m_context.camera.m_bufferHeight = bufferHeight; - ResizeScene( m_context.scene, &m_context.camera ); + // delete tolerates the first selection, before any sample exists. + delete context->sample; + context->sample = nullptr; + + context->sampleIndex = selection; + context->restart = restart; + context->sample = g_sampleEntries[selection].CreateFcn( context ); + + // Fit the shadow cascade range to the world bounds. + b3AABB bounds = b3World_GetBounds( context->sample->m_worldId ); + float diagonal = b3Distance( bounds.lowerBound, bounds.upperBound ); + SetShadowSplitFar( b3ClampFloat( diagonal, SHADOW_SPLIT_FAR, 200.0f ) ); + + // Samples read restart only while constructing, to keep the camera across a + // restart. Clear it so a later switch starts fresh. + context->restart = false; } -void SampleManager::Render( GLFWwindow* window, float elapsedTime ) +// Subsequence fuzzy match. Returns a score (higher is better) or -1 if the +// needle is not a subsequence of the haystack. Bonuses for a prefix match, a +// word start, and a contiguous run, so "stack" ranks Pyramid > Stack sensibly. +static int FuzzyScore( const char* needle, const char* haystack ) { - RenderScene( window, elapsedTime ); - UpdateUI( window ); -} - -void SampleManager::Shutdown( GLFWwindow* window ) -{ - // Must destroy sample first because it will destroy debug shapes. - delete m_sample; - m_sample = nullptr; - - m_context.Save(); - - DestroyScene( m_context.scene ); - m_context.scene = nullptr; - - m_context.arena.Destroy(); -} - -void SampleManager::Keyboard( int key, int action, int modifiers ) -{ - if ( action == GLFW_PRESS ) + if ( needle == nullptr || needle[0] == '\0' ) { - switch ( key ) + return 0; + } + + int score = 0; + int hi = 0; + int prevMatchHi = -2; + + for ( int ni = 0; needle[ni] != '\0'; ++ni ) + { + int nc = tolower( (unsigned char)needle[ni] ); + while ( haystack[hi] != '\0' && tolower( (unsigned char)haystack[hi] ) != nc ) { - case GLFW_KEY_ESCAPE: - glfwSetWindowShouldClose( m_context.window, GL_TRUE ); - break; - - case GLFW_KEY_TAB: - m_showMenu = !m_showMenu; - break; - - case GLFW_KEY_O: - if ( modifiers & GLFW_MOD_SHIFT ) - { - m_context.singleStep += 5; - } - else - { - m_context.singleStep += 1; - } - break; - - case GLFW_KEY_P: - m_context.pause = !m_context.pause; - break; - - case GLFW_KEY_R: - m_context.restart = true; - CreateSample(); - break; - - case GLFW_KEY_LEFT_BRACKET: - m_context.sampleIndex = b3MaxInt( 0, m_context.sampleIndex - 1 ); - m_context.restart = false; - CreateSample(); - break; - - case GLFW_KEY_RIGHT_BRACKET: - m_context.sampleIndex = b3MinInt( sEntryCount - 1, m_context.sampleIndex + 1 ); - m_context.restart = false; - CreateSample(); - break; - - default: - m_sample->Keyboard( key, action, modifiers ); - break; + ++hi; } - } -} - -void SampleManager::CreateSample() -{ - B3_ASSERT( m_sample ); - - if (m_context.restart == false) - { - EnableGrid( m_context.scene, false ); - } - - delete m_sample; - m_sample = sEntries[m_context.sampleIndex].CreateFcn( &m_context ); -} - -void SampleManager::RenderScene( GLFWwindow* window, float elapsedTime ) -{ - // Update camera - m_context.camera.Update( window, elapsedTime ); - - m_sample->Render(); - // CheckOpenGL(); - - // Actually render - DrawScene( m_context.scene, &m_context.camera ); - // CheckOpenGL(); -} - -void SampleManager::UpdateUI( GLFWwindow* window ) -{ - if ( m_showMenu == false ) - { - return; - } - - int maxWorkers = B3_MAX_WORKERS; - - int savedTestIndex = m_context.sampleIndex; - float menuWidth = 220.0f; - b3WorldId worldId = m_sample->m_worldId; - - ImGui::SetNextWindowPos( { m_context.camera.m_width - menuWidth - 10.0f, 10.0f } ); - ImGui::SetNextWindowSize( { menuWidth, m_context.camera.m_height - 20.0f } ); - - ImGui::Begin( "Tools", &m_showMenu, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse ); - - if ( ImGui::BeginTabBar( "ControlTabs", ImGuiTabBarFlags_None ) ) - { - if ( ImGui::BeginTabItem( "Controls" ) ) + if ( haystack[hi] == '\0' ) { - ImGui::SliderInt( "Sub-steps", &m_context.subStepCount, 1, 50 ); - ImGui::SliderFloat( "Hertz", &m_context.hertz, 5.0f, 2000.0f, "%.0f hz" ); - - if ( ImGui::SliderInt( "Workers", &m_context.workerCount, 1, maxWorkers ) ) - { - m_context.workerCount = b3ClampInt( m_context.workerCount, 1, maxWorkers ); - m_context.restart = true; - CreateSample(); - } - - ImGui::Separator(); - - ImGui::Checkbox( "Sleep", &m_context.enableSleep ); - ImGui::Checkbox( "Warm Starting", &m_context.enableWarmStarting ); - ImGui::Checkbox( "Continuous", &m_context.enableContinuous ); - - ImGui::PushItemWidth( 100.0f ); - float recyclingCentimeters = 100.0f * m_context.recycleDistance; - if ( ImGui::SliderFloat( "Recycle", &recyclingCentimeters, 0.0f, 10.0f, "%.1f cm" ) ) - { - m_context.recycleDistance = 0.01f * recyclingCentimeters; - b3World_SetContactRecycleDistance( worldId, m_context.recycleDistance ); - } - ImGui::PopItemWidth(); - - ImGui::Separator(); - - ImGui::Checkbox( "Shapes", &m_context.debugDraw.drawShapes ); - ImGui::Checkbox( "Transparent", &m_context.transparentDynamic ); - ImGui::Checkbox( "Joints", &m_context.debugDraw.drawJoints ); - ImGui::Checkbox( "Joint Extras", &m_context.debugDraw.drawJointExtras ); - ImGui::Checkbox( "Bounds", &m_context.debugDraw.drawBounds ); - - ImGui::Separator(); - - ImGui::Checkbox( "Contact Points", &m_context.debugDraw.drawContacts ); - ImGui::RadioButton( "Anchor A", &m_context.debugDraw.drawAnchorA, 1 ); - ImGui::SameLine(); - ImGui::RadioButton( "Anchor B", &m_context.debugDraw.drawAnchorA, 0 ); - ImGui::Checkbox( "Contact Normals", &m_context.debugDraw.drawContactNormals ); - ImGui::Checkbox( "Contact Forces", &m_context.debugDraw.drawContactForces ); - ImGui::Checkbox( "Contact Features", &m_context.debugDraw.drawContactFeatures ); - ImGui::Checkbox( "Friction Forces", &m_context.debugDraw.drawFrictionForces ); - - ImGui::Separator(); - - ImGui::Checkbox( "Mass", &m_context.debugDraw.drawMass ); - ImGui::Checkbox( "Body Names", &m_context.debugDraw.drawBodyNames ); - ImGui::Checkbox( "Graph Colors", &m_context.debugDraw.drawGraphColors ); - ImGui::Checkbox( "Draw Islands", &m_context.debugDraw.drawIslands ); - ImGui::Checkbox( "Counters", &m_context.drawCounters ); - ImGui::Checkbox( "Profile", &m_context.drawProfile ); - ImGui::Checkbox( "Frame Time", &m_context.frameTime ); - - ImGui::PushItemWidth( 80.0f ); - ImGui::InputFloat( "Joint Scale", &m_context.debugDraw.jointScale ); - ImGui::InputFloat( "Force Scale", &m_context.debugDraw.forceScale ); - ImGui::PopItemWidth(); - - ImGui::Separator(); - - bool useSSAO = IsSSAOEnabled( m_context.scene ); - if ( ImGui::Checkbox( "SSAO", &useSSAO ) ) - { - EnableSSAO( m_context.scene, useSSAO ); - } - - bool useShadows = AreShadowsEnabled( m_context.scene ); - if ( ImGui::Checkbox( "Shadows", &useShadows ) ) - { - EnableShadows( m_context.scene, useShadows ); - } - - SceneAOSettings* ao = GetAOSettings( m_context.scene ); - ImGui::SliderFloat( "AO Radius", &ao->radius, 0.0f, 5.0f ); - ImGui::SliderFloat( "AO Bias", &ao->bias, 0.0f, 0.5f ); - ImGui::SliderFloat( "AO Min", &ao->minScale, 0.0f, 1.0f ); - ImGui::SliderFloat( "AO Power", &ao->power, 0.5f, 8.0f ); - ImGui::SliderFloat( "AO Direct", &ao->direct, 0.0f, 1.0f ); - ImGui::Checkbox( "AO Only", &ao->aoOnly ); - - ImGui::Separator(); - - if ( ImGui::Button( "Pause", ImVec2( -1, 0 ) ) ) - { - m_context.pause = !m_context.pause; - } - - if ( ImGui::Button( "Restart", ImVec2( -1, 0 ) ) ) - { - m_context.restart = true; - CreateSample(); - } - - if ( ImGui::Button( "Dump", ImVec2( -1, 0 ) ) ) - { - b3World_Dump( m_sample->m_worldId ); - } - - if ( ImGui::Button( "Dump Awake", ImVec2( -1, 0 ) ) ) - { - b3World_DumpAwake( m_sample->m_worldId ); - } - - if ( ImGui::Button( "Quit", ImVec2( -1, 0 ) ) ) - { - glfwSetWindowShouldClose( window, GL_TRUE ); - } - - ImGui::EndTabItem(); + return -1; } - ImGuiTreeNodeFlags leafNodeFlags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick; - leafNodeFlags |= ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen; - - ImGuiTreeNodeFlags nodeFlags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick; - - if ( ImGui::BeginTabItem( "Tests" ) ) + int bonus = 1; + if ( hi == 0 ) + { + bonus += 10; // prefix + } + else if ( !isalnum( (unsigned char)haystack[hi - 1] ) ) + { + bonus += 5; // word start + } + if ( hi == prevMatchHi + 1 ) + { + bonus += 3; // contiguous run + } + + score += bonus; + prevMatchHi = hi; + ++hi; + } + + return score; +} + +struct Scored +{ + int idx; + int score; +}; + +// Filter and rank the sample registry against the picker query. Name matches +// outweigh category-only matches. Equal scores keep the sorted registry order. +static void RebuildPicker( const char* q, int* outFiltered, int* outCount ) +{ + static Scored scored[MAX_SAMPLES]; + int n = 0; + for ( int i = 0; i < g_sampleCount; ++i ) + { + int nameScore = FuzzyScore( q, g_sampleEntries[i].Name ); + int catScore = FuzzyScore( q, g_sampleEntries[i].Category ); + int best = -1; + if ( nameScore >= 0 ) + { + best = nameScore * 2; + } + if ( catScore >= 0 && catScore > best ) + { + best = catScore; + } + if ( best < 0 ) + { + continue; + } + scored[n].idx = i; + scored[n].score = best; + n += 1; + } + + // Stable insertion sort by score descending. + for ( int i = 1; i < n; ++i ) + { + Scored tmp = scored[i]; + int j = i - 1; + while ( j >= 0 && scored[j].score < tmp.score ) + { + scored[j + 1] = scored[j]; + --j; + } + scored[j + 1] = tmp; + } + + for ( int i = 0; i < n; ++i ) + { + outFiltered[i] = scored[i].idx; + } + *outCount = n; +} + +static void DrawRow( const char* key, const char* desc ) +{ + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex( 0 ); + ImGui::TextUnformatted( key ); + ImGui::TableSetColumnIndex( 1 ); + ImGui::TextUnformatted( desc ); +} + +// b3HexColor (0xRRGGBB) to an opaque ImVec4 for panel text. Distinct from +// gfx/utility.h's MakeColor, which returns the renderer's linear Vec4. +static ImVec4 HexColor( b3HexColor hexColor ) +{ + uint32_t h = (uint32_t)hexColor; + ImU32 color = IM_COL32( ( h >> 16 ) & 0xFF, ( h >> 8 ) & 0xFF, h & 0xFF, 255 ); + return ImGui::ColorConvertU32ToFloat4( color ); +} + +// Abbreviated render controls: mostly visualization/debug toggles plus a single +// exposure slider. The deep GTAO knobs and most edge/outline parameters keep +// their renderer defaults, only the edge convexity coloring is exposed. +static void DrawRenderMenu( SampleContext& ctx ) +{ + ImGui::MenuItem( "Shadows", nullptr, &ctx.enableShadows ); + + if ( ImGui::BeginMenu( "GTAO" ) ) + { + ImGui::MenuItem( "Enable", nullptr, &ctx.enableGtao ); + + GtaoTraceParams p = GetGtaoTraceParams(); + int quality = p.quality; + static const char* qualityNames[] = { "Medium", "High", "Ultra" }; + if ( ImGui::Combo( "Quality", &quality, qualityNames, 3 ) ) + { + p.quality = (AmbientOcclusionQuality)quality; + SetGtaoTraceParams( p ); + } + ImGui::EndMenu(); + } + + bool ibl = GetIblEnabled(); + if ( ImGui::MenuItem( "IBL", nullptr, &ibl ) ) + { + SetIblEnabled( ibl ); + } + + EdgeOverlayParams edgeParams = GetEdgeOverlayParams(); + if ( ImGui::MenuItem( "Hull Edges", nullptr, &edgeParams.showHulls ) ) + { + SetEdgeOverlayParams( &edgeParams ); + } + if ( ImGui::MenuItem( "Edge Convexity", nullptr, &edgeParams.showEdgeConvexity ) ) + { + SetEdgeOverlayParams( &edgeParams ); + } + + ImGui::Separator(); + + ImGui::PushItemWidth( 8.0f * ImGui::GetFontSize() ); + float ev = GetExposure(); + if ( ImGui::SliderFloat( "Exposure", &ev, -8.0f, 4.0f, "%.2f" ) ) + { + SetExposure( ev ); + } + + Sun sun = GetSun(); + if ( ImGui::SliderFloat( "Sun", &sun.strength, 0.0f, 1.0f, "%.2f" ) ) + { + SetSun( sun ); + } + + ImGui::PopItemWidth(); + + ImGui::Separator(); + + if ( ImGui::BeginMenu( "Debug View" ) ) + { + static const char* viewNames[] = { + "0 - lit", "1 - view-space distance", "2 - CSM cascade", "3 - view-space normal", "4 - raw GTAO", + }; + for ( int i = 0; i < 5; ++i ) + { + if ( ImGui::RadioButton( viewNames[i], ctx.debugView == i ) ) + { + ctx.debugView = i; + } + } + ImGui::EndMenu(); + } +} + +static void DrawMenuBar( SampleContext* context ) +{ + b3DebugDraw* gd = GetGuiDraw(); + float fontSize = ImGui::GetFontSize(); + + if ( ImGui::BeginMainMenuBar() ) + { + if ( ImGui::BeginMenu( "Sim" ) ) + { + ImGui::MenuItem( "Pause", "P", &context->pause ); + if ( ImGui::MenuItem( "Single Step", "O" ) ) + { + context->singleStep += 1; + } + if ( ImGui::MenuItem( "Restart", "R" ) ) + { + SelectSample( context, context->sampleIndex, true ); + } + ImGui::Separator(); + if ( ImGui::MenuItem( "Previous Sample", "[" ) ) + { + SelectSample( context, b3MaxInt( 0, context->sampleIndex - 1 ), false ); + } + if ( ImGui::MenuItem( "Next Sample", "]" ) ) + { + SelectSample( context, b3MinInt( g_sampleCount - 1, context->sampleIndex + 1 ), false ); + } + ImGui::Separator(); + if ( ImGui::MenuItem( "Reset Profile" ) ) + { + context->sample->ResetProfile(); + } + if ( ImGui::MenuItem( "Dump" ) ) + { + b3World_Dump( context->sample->m_worldId ); + } + if ( ImGui::MenuItem( "Dump Awake" ) ) + { + b3World_DumpAwake( context->sample->m_worldId ); + } + ImGui::Separator(); + if ( ImGui::MenuItem( "Quit", "Esc" ) ) + { + sapp_request_quit(); + } + ImGui::EndMenu(); + } + + if ( ImGui::BeginMenu( "View" ) ) + { + if ( ImGui::MenuItem( "Hide UI", "Tab" ) ) + { + context->showUI = false; + } + if ( ImGui::MenuItem( "Frame Camera", "Home" ) ) + { + b3AABB aabb = b3World_GetBounds( context->sample->m_worldId ); + Camera& cam = context->camera; + float aspect = cam.m_height > 0 ? (float)cam.m_width / (float)cam.m_height : 1.0f; + cam.Frame( aabb, aspect, 0.75f ); + } + ImGui::Separator(); + ImGui::MenuItem( "Shapes", nullptr, &gd->drawShapes ); + ImGui::MenuItem( "Transparent", nullptr, &context->transparentDynamic ); + ImGui::MenuItem( "Joints", nullptr, &gd->drawJoints ); + ImGui::MenuItem( "Joint Extras", nullptr, &gd->drawJointExtras ); + ImGui::MenuItem( "Bounds", nullptr, &gd->drawBounds ); + ImGui::MenuItem( "Mass", nullptr, &gd->drawMass ); + ImGui::MenuItem( "Body Names", nullptr, &gd->drawBodyNames ); + ImGui::MenuItem( "Graph Colors", nullptr, &gd->drawGraphColors ); + ImGui::MenuItem( "Islands", nullptr, &gd->drawIslands ); + ImGui::Separator(); + ImGui::MenuItem( "Contact Points", nullptr, &gd->drawContacts ); + ImGui::MenuItem( "Contact Normals", nullptr, &gd->drawContactNormals ); + ImGui::MenuItem( "Contact Features", nullptr, &gd->drawContactFeatures ); + ImGui::MenuItem( "Contact Forces", nullptr, &gd->drawContactForces ); + ImGui::MenuItem( "Friction Forces", nullptr, &gd->drawFrictionForces ); + if ( ImGui::BeginMenu( "Anchor" ) ) + { + if ( ImGui::MenuItem( "Anchor A", nullptr, gd->drawAnchorA != 0 ) ) + { + gd->drawAnchorA = 1; + } + if ( ImGui::MenuItem( "Anchor B", nullptr, gd->drawAnchorA == 0 ) ) + { + gd->drawAnchorA = 0; + } + ImGui::EndMenu(); + } + ImGui::Separator(); + ImGui::MenuItem( "Diagnostics", "M", &context->showMetrics ); + ImGui::Separator(); + if ( ImGui::BeginMenu( "Scale" ) ) + { + ImGui::PushItemWidth( 6.0f * fontSize ); + ImGui::InputFloat( "Joint", &gd->jointScale ); + ImGui::InputFloat( "Force", &gd->forceScale ); + ImGui::PopItemWidth(); + ImGui::EndMenu(); + } + ImGui::EndMenu(); + } + + if ( ImGui::BeginMenu( "Render" ) ) + { + DrawRenderMenu( *context ); + ImGui::EndMenu(); + } + + if ( ImGui::BeginMenu( "Samples" ) ) { - const char* category = sEntries[0].Category; int i = 0; - while ( i < sEntryCount ) + while ( i < g_sampleCount ) { - bool categorySelected = strcmp( category, sEntries[m_context.sampleIndex].Category ) == 0; - ImGuiTreeNodeFlags nodeSelectionFlags = categorySelected ? ImGuiTreeNodeFlags_Selected : 0; - bool nodeOpen = ImGui::TreeNodeEx( category, nodeFlags | nodeSelectionFlags ); - - if ( nodeOpen ) + const char* category = g_sampleEntries[i].Category; + if ( ImGui::BeginMenu( category ) ) { - while ( i < sEntryCount && strcmp( category, sEntries[i].Category ) == 0 ) + while ( i < g_sampleCount && strcmp( category, g_sampleEntries[i].Category ) == 0 ) { - ImGuiTreeNodeFlags selectionFlags = 0; - if ( m_context.sampleIndex == i ) + bool selected = ( i == context->sampleIndex ); + if ( ImGui::MenuItem( g_sampleEntries[i].Name, nullptr, selected ) ) { - selectionFlags = ImGuiTreeNodeFlags_Selected; - } - ImGui::TreeNodeEx( (void*)(intptr_t)i, leafNodeFlags | selectionFlags, "%s", sEntries[i].Name ); - if ( ImGui::IsItemClicked() ) - { - m_context.sampleIndex = i; + SelectSample( context, i, false ); } ++i; } - ImGui::TreePop(); + ImGui::EndMenu(); } else { - while ( i < sEntryCount && strcmp( category, sEntries[i].Category ) == 0 ) + while ( i < g_sampleCount && strcmp( category, g_sampleEntries[i].Category ) == 0 ) { ++i; } } + } + ImGui::EndMenu(); + } - if ( i < sEntryCount ) + static bool showHelp = false; + static bool showAbout = false; + if ( ImGui::BeginMenu( "Help" ) ) + { + ImGui::MenuItem( "Controls", nullptr, &showHelp ); + ImGui::MenuItem( "About", nullptr, &showAbout ); + ImGui::EndMenu(); + } + + ImGui::EndMainMenuBar(); + + if ( showHelp ) + { + ImGui::SetNextWindowPos( { context->camera.m_width * 0.5f, context->camera.m_height * 0.5f }, ImGuiCond_Appearing, + { 0.5f, 0.5f } ); + ImGui::SetNextWindowSize( { 26.0f * fontSize, 0.0f }, ImGuiCond_Appearing ); + + if ( ImGui::Begin( "Controls", &showHelp, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_AlwaysAutoResize ) ) + { + ImGui::SeparatorText( "Keyboard" ); + if ( ImGui::BeginTable( "keys", 2, ImGuiTableFlags_SizingFixedFit ) ) { - category = sEntries[i].Category; + DrawRow( "Tab", "Show / hide UI" ); + DrawRow( "M", "Show / hide diagnostics" ); + DrawRow( "P", "Pause / resume" ); + DrawRow( "O", "Single step (Shift: 5)" ); + DrawRow( "R", "Restart sample" ); + DrawRow( "[ ]", "Previous / next sample" ); + DrawRow( "Ctrl+O", "Open sample picker" ); + DrawRow( "F / Home", "Frame selection / world" ); + DrawRow( "Esc", "Quit" ); + ImGui::EndTable(); + } + + ImGui::SeparatorText( "Mouse" ); + if ( ImGui::BeginTable( "mouse", 2, ImGuiTableFlags_SizingFixedFit ) ) + { + DrawRow( "Left drag", "Move bodies (mouse joint)" ); + DrawRow( "Alt + left drag", "Orbit camera" ); + DrawRow( "Alt + middle drag", "Pan camera" ); + DrawRow( "Right drag", "Fly look (WASD to move)" ); + DrawRow( "Scroll", "Zoom" ); + DrawRow( "Shift + left", "Shoot (Ctrl spin, Alt ragdoll)" ); + ImGui::EndTable(); } } - ImGui::EndTabItem(); + ImGui::End(); + } + + if ( showAbout ) + { + ImGui::SetNextWindowPos( { context->camera.m_width * 0.5f, context->camera.m_height * 0.5f }, ImGuiCond_Appearing, + { 0.5f, 0.5f } ); + ImGui::SetNextWindowSize( { 22.0f * fontSize, 0.0f }, ImGuiCond_Appearing ); + + if ( ImGui::Begin( "About", &showAbout, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_AlwaysAutoResize ) ) + { + b3Version version = b3GetVersion(); + ImGui::Text( "Box3D %d.%d.%d", version.major, version.minor, version.revision ); + ImGui::Spacing(); + ImGui::TextLinkOpenURL( "github.com/erincatto/box3d", "https://github.com/erincatto/box3d" ); + } + ImGui::End(); + } + } +} + +static void DrawSamplePicker( SampleContext* context ) +{ + float fontSize = ImGui::GetFontSize(); + + // Opens a transient popup; type to filter by name or category, Up/Down to + // navigate, Enter to select, Esc / click-outside to dismiss. + static char query[64] = {}; + static char prevQuery[64] = {}; + static int highlight = 0; + static int prevHighlight = 0; + static int filtered[MAX_SAMPLES]; + static int filteredCount = 0; + static bool justOpened = false; + static bool forceScroll = false; + + if ( context->openSamplePicker ) + { + ImGui::OpenPopup( "##sample_picker" ); + context->openSamplePicker = false; + query[0] = '\0'; + prevQuery[0] = '\0'; + highlight = 0; + prevHighlight = 0; + RebuildPicker( query, filtered, &filteredCount ); + justOpened = true; + forceScroll = true; + } + + ImGui::SetNextWindowPos( { context->camera.m_width * 0.5f, context->camera.m_height * 0.35f }, ImGuiCond_Appearing, + { 0.5f, 0.5f } ); + ImGui::SetNextWindowSize( { 32.0f * fontSize, 0.0f }, ImGuiCond_Appearing ); + + if ( ImGui::BeginPopup( "##sample_picker", + ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings ) ) + { + if ( justOpened ) + { + ImGui::SetKeyboardFocusHere(); + justOpened = false; + } + + ImGui::PushItemWidth( -1.0f ); + ImGui::InputTextWithHint( "##q", "Search by name or category...", query, sizeof( query ) ); + ImGui::PopItemWidth(); + + if ( strcmp( query, prevQuery ) != 0 ) + { + RebuildPicker( query, filtered, &filteredCount ); + strncpy( prevQuery, query, sizeof( prevQuery ) ); + prevQuery[sizeof( prevQuery ) - 1] = '\0'; + highlight = 0; + forceScroll = true; + } + + if ( filteredCount > 0 ) + { + if ( ImGui::IsKeyPressed( ImGuiKey_DownArrow, true ) ) + { + highlight = ( highlight + 1 ) % filteredCount; + } + if ( ImGui::IsKeyPressed( ImGuiKey_UpArrow, true ) ) + { + highlight = ( highlight + filteredCount - 1 ) % filteredCount; + } + } + bool commit = ImGui::IsKeyPressed( ImGuiKey_Enter, false ) || ImGui::IsKeyPressed( ImGuiKey_KeypadEnter, false ); + + ImGui::BeginChild( "##results", { 0.0f, 14.0f * fontSize }, ImGuiChildFlags_Borders ); + for ( int row = 0; row < filteredCount; ++row ) + { + int i = filtered[row]; + char label[160]; + snprintf( label, sizeof( label ), "%s > %s", g_sampleEntries[i].Category, g_sampleEntries[i].Name ); + bool sel = ( row == highlight ); + if ( ImGui::Selectable( label, sel ) ) + { + highlight = row; + commit = true; + } + if ( sel && ( forceScroll || highlight != prevHighlight ) ) + { + ImGui::SetScrollHereY(); + } + } + ImGui::EndChild(); + prevHighlight = highlight; + forceScroll = false; + + if ( commit && filteredCount > 0 ) + { + SelectSample( context, filtered[highlight], false ); + ImGui::CloseCurrentPopup(); + } + + ImGui::EndPopup(); + } +} + +static void DrawInfoPanel( SampleContext* context ) +{ + const SampleEntry& entry = g_sampleEntries[context->sampleIndex]; + float fontSize = ImGui::GetFontSize(); + float menuWidth = 16.0f * fontSize; + float menuBarHeight = ImGui::GetFrameHeight(); + + // Full-height panel pinned under the menu bar at the right edge, matching Box2D. + ImGui::SetNextWindowPos( { context->camera.m_width - menuWidth - 0.5f * fontSize, menuBarHeight + 0.5f * fontSize } ); + ImGui::SetNextWindowSize( { menuWidth, context->camera.m_height - menuBarHeight - fontSize } ); + + ImGui::Begin( "Info", nullptr, + ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | + ImGuiWindowFlags_NoTitleBar ); + + ImGui::TextColored( HexColor( b3_colorGoldenRod ), "%s", entry.Name ); + ImGui::TextColored( HexColor( b3_colorLightGray ), "%s", entry.Category ); + ImGui::Separator(); + + const float frameMs = (float)( sapp_frame_duration() * 1000.0 ); + ImGui::TextColored( HexColor( b3_colorSeaGreen ), "%.1f ms", frameMs ); + ImGui::TextColored( HexColor( b3_colorSeaGreen ), "step %d", context->sample->m_stepCount ); + ImGui::Separator(); + + b3Vec3 p = context->camera.m_pivot; + ImGui::TextColored( HexColor( b3_colorSeaGreen ), "pivot (%.1f, %.1f, %.1f)", p.x, p.y, p.z ); + float yawDeg = B3_RAD_TO_DEG * context->camera.m_yaw; + float pitchDeg = B3_RAD_TO_DEG * context->camera.m_pitch; + ImGui::TextColored( HexColor( b3_colorSeaGreen ), "yaw/pitch (%.1f, %.1f)", yawDeg, pitchDeg ); + ImGui::TextColored( HexColor( b3_colorSeaGreen ), "radius %.1f", context->camera.m_radius ); + + ImGui::Separator(); + + ImGui::PushItemWidth( 6.0f * fontSize ); + if ( context->sample->DrawControls() ) + { + ImGui::Separator(); + } + ImGui::PopItemWidth(); + + if ( context->sample->HasSolverControls() && ImGui::CollapsingHeader( "Solver", ImGuiTreeNodeFlags_DefaultOpen ) ) + { + ImGui::PushItemWidth( 6.0f * fontSize ); + ImGui::SliderInt( "Sub-steps##Solver", &context->subStepCount, 1, 50 ); + ImGui::SliderFloat( "Hertz##Solver", &context->hertz, 5.0f, 240.0f, "%.0f hz" ); + + if ( ImGui::SliderInt( "Workers##Solver", &context->workerCount, 1, B3_MAX_WORKERS ) ) + { + context->workerCount = b3ClampInt( context->workerCount, 1, B3_MAX_WORKERS ); + SelectSample( context, context->sampleIndex, true ); + } + + float recyclingCentimeters = 100.0f * context->recycleDistance; + if ( ImGui::SliderFloat( "Recycle##Solver", &recyclingCentimeters, 0.0f, 10.0f, "%.1f cm" ) ) + { + context->recycleDistance = 0.01f * recyclingCentimeters; + b3World_SetContactRecycleDistance( context->sample->m_worldId, context->recycleDistance ); + } + ImGui::PopItemWidth(); + + ImGui::Checkbox( "Sleep##Solver", &context->enableSleep ); + ImGui::Checkbox( "Warm Starting##Solver", &context->enableWarmStarting ); + ImGui::Checkbox( "Continuous##Solver", &context->enableContinuous ); + + if ( ImGui::Shortcut( ImGuiKey_R ) || ImGui::Button( "Restart" ) ) + { + SelectSample( context, context->sampleIndex, true ); } - ImGui::EndTabBar(); } ImGui::End(); +} - m_sample->UpdateUI(); +// Minimal in-world HUD shown only when the UI is hidden: sample identity at the +// top-left, frame time and step count at the bottom-left. Matches Box2D DrawHud. +static void DrawHud( SampleContext* context ) +{ + const SampleEntry& entry = g_sampleEntries[context->sampleIndex]; + float fontSize = ImGui::GetFontSize(); - // todo wrong place for this - if ( m_context.sampleIndex != savedTestIndex ) + DrawScreenStringFormat( 5, (int)( 1.5f * fontSize ), MakeColor( b3_colorYellow ), "%s : %s", entry.Category, entry.Name ); + DrawScreenStringFormat( 5, context->camera.m_height - (int)( 1.5f * fontSize ), MakeColor( b3_colorSeaGreen ), + "%.1f ms step %d", 1000.0f * (float)sapp_frame_duration(), context->sample->m_stepCount ); +} + +void DrawUI( SampleContext* context ) +{ + // Hidden shows only the minimal in-world HUD. + if ( context->showUI == false ) { - m_context.restart = false; - CreateSample(); + DrawHud( context ); + return; } + + DrawMenuBar( context ); + DrawSamplePicker( context ); + DrawInfoPanel( context ); + + // Bottom diagnostics drawer. Sample controls live in the info panel. + context->sample->DrawMetrics(); } void Sample::ToggleThirdPerson() { if ( m_camera->m_thirdPerson ) { - glfwSetInputMode( m_window, GLFW_CURSOR, GLFW_CURSOR_NORMAL ); + sapp_lock_mouse( false ); m_camera->m_thirdPerson = false; } else { - glfwSetInputMode( m_window, GLFW_CURSOR, GLFW_CURSOR_DISABLED ); + sapp_lock_mouse( true ); m_camera->m_thirdPerson = true; } } @@ -1555,7 +1989,6 @@ void CharacterMover::SolveMove( float timeStep, b3Vec3 forward, b3Vec3 right, b3 m_velocity.y -= m_gravity * timeStep; b3WorldId worldId = m_sample->m_worldId; - Scene* scene = m_sample->m_scene; float pogoRestLength = 3.0f * m_capsule.radius; float rayLength = pogoRestLength + m_capsule.radius; @@ -1569,7 +2002,7 @@ void CharacterMover::SolveMove( float timeStep, b3Vec3 forward, b3Vec3 right, b3 m_onGround = false; m_pogoVelocity = 0.0f; - DrawLine( scene, rayOrigin, rayOrigin + rayTranslation, b3_colorGray ); + DrawLine( rayOrigin, rayOrigin + rayTranslation, MakeColor( b3_colorGray ) ); } else { @@ -1583,7 +2016,7 @@ void CharacterMover::SolveMove( float timeStep, b3Vec3 forward, b3Vec3 right, b3 m_pogoVelocity = ( m_pogoVelocity - omega * omegaH * ( pogoCurrentLength - pogoRestLength ) ) / ( 1.0f + 2.0f * zeta * omegaH + omegaH * omegaH ); - DrawLine( scene, rayOrigin, rayResult.point, b3_colorGreen ); + DrawLine( rayOrigin, rayResult.point, MakeColor( b3_colorGreen ) ); } b3Vec3 startPosition = m_transform.p; @@ -1687,27 +2120,27 @@ void CharacterMover::Step( b3ShapeId* ignoreShapes, int ignoreCount, bool clipVe if ( m_sample->m_camera->m_thirdPerson ) { - if ( glfwGetKey( m_sample->m_window, GLFW_KEY_W ) ) + if ( IsKeyDown( KEY_W ) ) { throttle.x += 1.0f; } - if ( glfwGetKey( m_sample->m_window, GLFW_KEY_S ) ) + if ( IsKeyDown( KEY_S ) ) { throttle.x -= 1.0f; } - if ( glfwGetKey( m_sample->m_window, GLFW_KEY_A ) ) + if ( IsKeyDown( KEY_A ) ) { throttle.y -= 1.0f; } - if ( glfwGetKey( m_sample->m_window, GLFW_KEY_D ) ) + if ( IsKeyDown( KEY_D ) ) { throttle.y += 1.0f; } - if ( glfwGetKey( m_sample->m_window, GLFW_KEY_SPACE ) && m_onGround == true ) + if ( IsKeyDown( KEY_SPACE ) && m_onGround == true ) { m_velocity.y = m_jumpSpeed; m_onGround = false; @@ -1715,7 +2148,7 @@ void CharacterMover::Step( b3ShapeId* ignoreShapes, int ignoreCount, bool clipVe if ( m_onGround == true ) { - m_sprint = glfwGetKey( m_sample->m_window, GLFW_KEY_LEFT_SHIFT ) != 0; + m_sprint = IsKeyDown( KEY_LEFT_SHIFT ); } else { @@ -1730,20 +2163,18 @@ void CharacterMover::Step( b3ShapeId* ignoreShapes, int ignoreCount, bool clipVe SolveMove( timeStep, forward, right, throttle, clipVelocity ); - Scene* scene = m_sample->m_scene; - int count = m_planeCount; for ( int i = 0; i < count; ++i ) { b3Plane plane = m_planes[i].plane; b3Vec3 p1 = m_transform.p + ( plane.offset - m_capsule.radius ) * plane.normal; b3Vec3 p2 = p1 + 0.1f * plane.normal; - DrawPoint( scene, p1, 5.0f, b3_colorYellow ); - DrawLine( scene, p1, p2, b3_colorYellow ); + DrawPoint( p1, 5.0f, MakeColor( b3_colorYellow ) ); + DrawLine( p1, p2, MakeColor( b3_colorYellow ) ); } - DrawCapsule( scene, m_transform, m_capsule, b3_colorBlue ); - DrawLine( scene, m_transform.p, m_transform.p + m_velocity, b3_colorPurple ); + DrawSolidCapsule( m_transform, m_capsule, MakeColor( b3_colorBlue ) ); + DrawLine( m_transform.p, m_transform.p + m_velocity, MakeColor( b3_colorPurple ) ); b3Vec3 p = m_transform.p; // m_sample->DrawTextLine( "position %.2f %.2f %.2f", p.x, p.y, p.z ); diff --git a/samples/sample.h b/samples/sample.h index e490bb8..369b8a4 100644 --- a/samples/sample.h +++ b/samples/sample.h @@ -3,28 +3,42 @@ #pragma once -#include "camera.h" +#include "host/camera.h" -class Font; -struct MouseEvent; -struct MouseMoveEvent; -struct MouseWheelEvent; -struct Scene; -struct GLFWwindow; +#include "box3d/types.h" + +// Polled key state for samples that need continuous input (character movers). +// Fed from the host event loop; read with the KEY_* aliases in gfx/keycodes.h. +bool IsKeyDown( int key ); +void SetKeyDown( int key, bool down ); + +// Key action passed to Keyboard, matching the old GLFW press/release values so +// sample code reads naturally without leaking sokol_app event types. +enum +{ + ACTION_RELEASE = 0, + ACTION_PRESS = 1, +}; struct SampleContext { void Save(); void Load(); - GLFWwindow* window = nullptr; Camera camera; - Arena arena; - Scene* scene = nullptr; bool minimized = false; class Sample* sample = nullptr; b3Capacity capacity; - b3DebugDraw debugDraw; + + // Latest cursor position in framebuffer pixels, fed from the host event + // loop. Drives picking on the step that follows a mouse move. + float mouseX = 0.0f; + float mouseY = 0.0f; + + // Relative cursor motion for the latest move, fed from the host. Used for + // third-person look while the cursor is locked. + float mouseDX = 0.0f; + float mouseDY = 0.0f; int windowWidth = 1920; int windowHeight = 1080; @@ -37,9 +51,6 @@ struct SampleContext int subStepCount = 4; int workerCount = 1; bool transparentDynamic = false; - bool drawCounters = false; - bool drawProfile = false; - bool frameTime = false; bool transparent = false; bool enableWarmStarting = true; bool enableContinuous = true; @@ -48,6 +59,21 @@ struct SampleContext int singleStep = 0; bool restart = false; + // UI visibility (Tab / View > Hide UI). When hidden only the minimal HUD shows. + bool showUI = true; + + // Bottom diagnostics drawer (M), set by Ctrl+O for the fuzzy picker. + bool showMetrics = false; + bool openSamplePicker = false; + + // Render toggles fed into FrameInput each frame. They live here, not in + // main.cpp, so the Render menu and the frame loop share one source. + bool enableShadows = true; + bool enableGtao = true; + + float sunStrength = 1.0f; + int debugView = 0; + int sampleIndex = 0; }; @@ -59,12 +85,30 @@ public: void CreateWorld( b3Capacity* capacity ); + // Position the first HUD text line below the menu bar, or near the top when + // the UI is hidden. Mirrors Box2D ResetText. + void ResetText(); + // Update and render are split to support pausing the simulation virtual void Step(); virtual void Render(); - virtual void UpdateUI(); + // Draw sample controls into the shared info panel. Return true if any widget + // was drawn so the panel can add a separator. + virtual bool DrawControls() + { + return false; + } + + // Let a debug sample hide the Solver section. + virtual bool HasSolverControls() const + { + return true; + } + + // Bottom diagnostics drawer (Profile / Counters / Renderer / Frame Time). + void DrawMetrics(); virtual void Keyboard( int key, int action, int modifiers ) { @@ -78,6 +122,9 @@ public: void DrawTextLine( const char* text, ... ); void ResetProfile(); + // Static ground box at the origin, drawn with the procedural grid material + b3BodyId AddGroundBox( float extent ); + #if defined( NDEBUG ) static constexpr bool m_isDebug = false; #else @@ -89,8 +136,6 @@ public: static constexpr int m_profileCapacity = 512; SampleContext* m_context; - GLFWwindow* m_window; - Scene* m_scene; Camera* m_camera; b3WorldId m_worldId; @@ -105,12 +150,12 @@ public: int m_textIncrement; int m_triangleIndex; uint64_t m_userMaterialId; - + b3Profile m_profiles[m_profileCapacity]; int m_currentProfileIndex; int m_profileReadIndex; int m_profileWriteIndex; - + b3Vec2 m_mouseLast; b3Vec2 m_mouseDelta; bool m_didStep; @@ -129,31 +174,18 @@ struct SampleEntry SampleCreateFcn* CreateFcn; }; -class SampleManager -{ -public: - static int Register( const char* category, const char* name, SampleCreateFcn* fcn ); +extern SampleEntry g_sampleEntries[MAX_SAMPLES]; +extern int g_sampleCount; - void Startup( GLFWwindow* window, int width, int height, int bufferWidth, int bufferHeight ); - void Step(); - void Resize( int width, int height, int bufferWidth, int bufferHeight ); - void Render( GLFWwindow* window, float elapsedTime ); - void Shutdown( GLFWwindow* window ); +int RegisterSample( const char* category, const char* name, SampleCreateFcn* fcn ); - void Keyboard( int key, int action, int modifiers ); +// Destroy the active sample and build the selected one. restart keeps the camera +// by leaving the restart flag set while the new sample constructs. +void SelectSample( SampleContext* context, int selection, bool restart ); - void CreateSample(); - - void RenderScene( GLFWwindow* window, float elapsedTime ); - void UpdateUI( GLFWwindow* window ); - - static SampleEntry sEntries[MAX_SAMPLES]; - static int sEntryCount; - - SampleContext m_context; - Sample* m_sample = nullptr; - bool m_showMenu = true; -}; +// The single host UI callback: menu bar, sample picker, info panel, and the +// bottom diagnostics drawer. +void DrawUI( SampleContext* context ); struct CastClosestContext { @@ -167,8 +199,8 @@ struct CastClosestContext bool hit; }; -float CastClosestCallback( b3ShapeId shapeId, b3Vec3 point, b3Vec3 normal, float fraction, uint64_t materialId, - int triangleIndex, int childIndex, void* context ); +float CastClosestCallback( b3ShapeId shapeId, b3Vec3 point, b3Vec3 normal, float fraction, uint64_t materialId, int triangleIndex, + int childIndex, void* context ); struct MoverShapeUserData { diff --git a/samples/sample_benchmark.cpp b/samples/sample_benchmark.cpp index 8a4f401..eef2665 100644 --- a/samples/sample_benchmark.cpp +++ b/samples/sample_benchmark.cpp @@ -2,11 +2,10 @@ // SPDX-License-Identifier: MIT #include "benchmarks.h" -#include "camera.h" +#include "gfx/debug_adapter.h" +#include "gfx/draw.h" #include "imgui.h" -#include "renderer.h" #include "sample.h" -#include "scene.h" #include "utils.h" #include "box3d/box3d.h" @@ -28,11 +27,12 @@ public: { if ( context->restart == false ) { - m_camera->SetView( 0.0f, 5.0f, 80.0f, { 0.0f, 18.0f, 0.0f } ); - EnableGrid( m_scene, true ); + m_camera->SetView( 40.0f, -10.0f, 110.0f, { 0.0f, 40.0f, 0.0f } ); } CreateLargePyramid( m_worldId ); + + SetGroundShape( GetGroundShapeId() ); } static Sample* Create( SampleContext* context ) @@ -41,7 +41,7 @@ public: } }; -static int sampleLargePyramid = SampleManager::Register( "Benchmark", "Large Pyramid", BenchmarkLargePyramid::Create ); +static int sampleLargePyramid = RegisterSample( "Benchmark", "Large Pyramid", BenchmarkLargePyramid::Create ); class BenchmarkWidePyramid : public Sample { @@ -52,10 +52,11 @@ public: if ( context->restart == false ) { m_camera->SetView( 0.0f, 5.0f, 80.0f, { 0.0f, 18.0f, 0.0f } ); - EnableGrid( m_scene, true ); } CreateWidePyramid( m_worldId ); + + SetGroundShape( GetGroundShapeId() ); } static Sample* Create( SampleContext* context ) @@ -64,7 +65,7 @@ public: } }; -static int sampleWidePyramid = SampleManager::Register( "Benchmark", "Wide Pyramid", BenchmarkWidePyramid::Create ); +static int sampleWidePyramid = RegisterSample( "Benchmark", "Wide Pyramid", BenchmarkWidePyramid::Create ); class BenchmarkManyPyramids : public Sample { @@ -74,8 +75,7 @@ public: { if ( context->restart == false ) { - m_camera->SetView( 0.0f, 5.0f, 80.0f, { 0.0f, 18.0f, 0.0f } ); - EnableGrid( m_scene, true ); + m_camera->SetView( -10.0f, 10.0f, 120.0f, { 0.0f, 5.0f, 0.0f } ); } CreateManyPyramids( m_worldId ); @@ -88,13 +88,8 @@ public: // Human human = {}; // b3Vec3 position = m_isDebug ? b3Vec3{ 0.0f, 20.0f, 0.0f } : b3Vec3{ 5.0f, 20.0f, 53.0f }; // CreateHuman( &human, m_worldId, position, frictionTorque, hertz, dampingRatio, 0, nullptr, colorize ); - } - void Render() override - { - Sample::Render(); - b3Transform transform = { { 0.0f, 0.1f, 0.0f }, b3Quat_identity }; - DrawTransform( m_scene, transform, 4.0f ); + SetGroundShape( GetGroundShapeId() ); } static Sample* Create( SampleContext* context ) @@ -103,7 +98,7 @@ public: } }; -static int sampleManyPyramids = SampleManager::Register( "Benchmark", "Many Pyramids", BenchmarkManyPyramids::Create ); +static int sampleManyPyramids = RegisterSample( "Benchmark", "Many Pyramids", BenchmarkManyPyramids::Create ); class BenchmarkRain : public Sample { @@ -113,8 +108,8 @@ public: { if ( context->restart == false ) { - m_camera->SetView( 45.0f, 30.0f, 40.0f, b3Vec3_zero ); - context->debugDraw.drawJoints = false; + m_camera->SetView( 25.0f, 10.0f, 70.0f, b3Vec3_zero ); + GetGuiDraw()->drawJoints = false; } b3Capacity capacity = {}; @@ -147,7 +142,7 @@ public: { Sample::Render(); b3Transform transform = { { 0.0f, 0.1f, 0.0f }, b3Quat_identity }; - DrawTransform( m_scene, transform, 2.0f ); + DrawAxes( transform, 2.0f ); } static Sample* Create( SampleContext* context ) @@ -156,7 +151,7 @@ public: } }; -static int sampleRain = SampleManager::Register( "Benchmark", "Rain", BenchmarkRain::Create ); +static int sampleRain = RegisterSample( "Benchmark", "Rain", BenchmarkRain::Create ); #if 0 class BenchmarkLargeWorld : public Sample @@ -196,7 +191,7 @@ public: { Sample::Render(); b3Transform transform = { { 0.0f, 0.1f, 0.0f }, b3Quat_identity }; - DrawTransform( m_scene, transform, 2.0f ); + DrawAxes( transform, 2.0f ); } static Sample* Create( SampleContext* context ) @@ -205,7 +200,7 @@ public: } }; -static int sampleLargeWorld = SampleManager::Register( "Benchmark", "Large World", BenchmarkLargeWorld::Create ); +static int sampleLargeWorld = RegisterSample( "Benchmark", "Large World", BenchmarkLargeWorld::Create ); #endif class BenchmarkJointGrid : public Sample @@ -226,7 +221,7 @@ public: { Sample::Render(); b3Transform transform = { { 0.0f, 0.1f, 0.0f }, b3Quat_identity }; - DrawTransform( m_scene, transform, 4.0f ); + DrawAxes( transform, 4.0f ); // transform.p.y = 0.0f; // transform.p.z = -5.0f; @@ -250,7 +245,7 @@ public: } }; -static int sampleJointGrid = SampleManager::Register( "Benchmark", "Joint Grid", BenchmarkJointGrid::Create ); +static int sampleJointGrid = RegisterSample( "Benchmark", "Joint Grid", BenchmarkJointGrid::Create ); class FallingBoxes : public Sample { @@ -260,27 +255,19 @@ public: { if ( context->restart == false ) { - m_camera->SetView( 45.0f, 45.0f, 250.0f, b3Vec3_zero ); - EnableGrid( m_scene, true ); + m_camera->SetView( 45.0f, 10.0f, 80.0f, { 0.0f, 20.0f, 0.0f } ); } - { - b3BoxHull groundBox = b3MakeBoxHull( 250.0f, 1.0f, 250.0f ); - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - b3CreateHullShape( groundId, &shapeDef, &groundBox.base ); - } + AddGroundBox( 100.0f ); { constexpr int n = m_isDebug ? 4 : 50; + float a = 0.5f; b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.type = b3_dynamicBody; b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull box = b3MakeBoxHull( 1.0f, 1.0f, 1.0f ); + b3BoxHull box = b3MakeCubeHull( a ); for ( int i = 0; i < n; ++i ) { @@ -288,7 +275,7 @@ public: { for ( int k = 0; k < 8; ++k ) { - bodyDef.position = { -16.0f + 4.0f * j, 4.0f * i + 5.0f, -16.0f + 4.0f * k }; + bodyDef.position = { -16.0f * a + 4.0f * a * j, 4.0f * a * i + 5.0f * a, -16.0f * a + 4.0f * a * k }; b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef ); b3CreateHullShape( bodyId, &shapeDef, &box.base ); } @@ -303,7 +290,7 @@ public: } }; -static int sampleFallingBoxes = SampleManager::Register( "Benchmark", "Falling Boxes", FallingBoxes::Create ); +static int sampleFallingBoxes = RegisterSample( "Benchmark", "Falling Boxes", FallingBoxes::Create ); class CandyCups : public Sample { @@ -313,19 +300,11 @@ public: { if ( context->restart == false ) { - m_camera->SetView( 45.0f, 35.0f, 40.0f, b3Vec3_zero ); - EnableGrid( m_scene, true ); + float radius = m_isDebug ? 20.0f : 70.0f; + m_camera->SetView( 45.0f, 20.0f, radius, b3Vec3_zero ); } - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull groundBox = b3MakeBoxHull( 250.0f, 1.0f, 250.0f ); - b3CreateHullShape( groundId, &shapeDef, &groundBox.base ); - } + AddGroundBox( 60.0f ); { constexpr int n = m_isDebug ? 4 : 16; @@ -334,7 +313,7 @@ public: b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.type = b3_dynamicBody; b3ShapeDef shapeDef = b3DefaultShapeDef(); - m_convex = CreateConvex( 0.6f, 0.0f, 0.95f, 1.0f, context->arena ); + m_convex = CreateConvex( 0.6f, 0.0f, 0.95f, 1.0f ); for ( int i = 0; i < n; ++i ) { for ( int j = 0; j < m; ++j ) @@ -355,13 +334,13 @@ public: b3DestroyHull( m_convex ); } - b3Hull* CreateConvex( float radius1, float height1, float radius2, float height2, Arena arena ) const + b3Hull* CreateConvex( float radius1, float height1, float radius2, float height2 ) const { - const int sideCount = 8; + constexpr int sideCount = 8; const float deltaAlpha = 2.0f * B3_PI / sideCount; int vertexCount = 2 * sideCount; - b3Vec3* vertexBase = static_cast( arena.Allocate( vertexCount * sizeof( b3Vec3 ) ) ); + b3Vec3 vertexBase[2 * sideCount]; float alpha = 0.0f; for ( int sideIndex = 0; sideIndex < sideCount; ++sideIndex ) @@ -389,7 +368,7 @@ public: b3Hull* m_convex; }; -static int sampleSmallConvexes = SampleManager::Register( "Benchmark", "Candy Cups", CandyCups::Create ); +static int sampleSmallConvexes = RegisterSample( "Benchmark", "Candy Cups", CandyCups::Create ); class BenchmarkExplosion : public Sample { @@ -399,7 +378,8 @@ public: { if ( m_context->restart == false ) { - m_camera->SetView( 0.0f, 40.0f, 10.0f, { 0.0f, 0.0f, 0.0f } ); + float radius = m_isDebug ? 15.0f : 30.0f; + m_camera->SetView( 45.0f, 20.0f, radius, { 0.0f, 0.0f, 0.0f } ); } b3ShapeDef shapeDef = b3DefaultShapeDef(); @@ -410,38 +390,40 @@ public: b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); b3CreateMeshShape( groundId, &shapeDef, m_gridMesh, b3Vec3_one ); + float hy = 1.0f; + { b3Transform transform; - transform.p = { 0.0f, 5.0f, -20.0f }; + transform.p = { 0.0f, hy, -20.0f }; transform.q = b3Quat_identity; - b3BoxHull wallBox = b3MakeTransformedBoxHull( 20.0f, 5.0f, 0.1f, transform ); + b3BoxHull wallBox = b3MakeTransformedBoxHull( 20.0f, hy, 0.1f, transform ); shapeDef.name = "wall1"; b3CreateHullShape( groundId, &shapeDef, &wallBox.base ); } { b3Transform transform; - transform.p = { 0.0f, 5.0f, 20.0f }; + transform.p = { 0.0f, hy, 20.0f }; transform.q = b3Quat_identity; - b3BoxHull wallBox = b3MakeTransformedBoxHull( 20.0f, 5.0f, 0.1f, transform ); + b3BoxHull wallBox = b3MakeTransformedBoxHull( 20.0f, hy, 0.1f, transform ); shapeDef.name = "wall2"; b3CreateHullShape( groundId, &shapeDef, &wallBox.base ); } { b3Transform transform; - transform.p = { -20.0f, 5.0f, 0.0f }; + transform.p = { -20.0f, hy, 0.0f }; transform.q = b3Quat_identity; - b3BoxHull wallBox = b3MakeTransformedBoxHull( 0.1f, 5.0f, 20.0f, transform ); + b3BoxHull wallBox = b3MakeTransformedBoxHull( 0.1f, hy, 20.0f, transform ); shapeDef.name = "wall3"; b3CreateHullShape( groundId, &shapeDef, &wallBox.base ); } { b3Transform transform; - transform.p = { 20.0f, 5.0f, 0.0f }; + transform.p = { 20.0f, hy, 0.0f }; transform.q = b3Quat_identity; - b3BoxHull wallBox = b3MakeTransformedBoxHull( 0.1f, 5.0f, 20.0f, transform ); + b3BoxHull wallBox = b3MakeTransformedBoxHull( 0.1f, hy, 20.0f, transform ); shapeDef.name = "wall4"; b3CreateHullShape( groundId, &shapeDef, &wallBox.base ); } @@ -486,32 +468,16 @@ public: b3World_Explode( m_worldId, &def ); } - void UpdateUI() override + bool DrawControls() override { - Sample::UpdateUI(); + ImGui::SliderFloat( "Magnitude", &m_impulse, 0.0f, 2000.0f, "%.0f" ); - float fontSize = ImGui::GetFontSize(); - float height = 10.0f * fontSize; - ImGui::SetNextWindowPos( { 1.0f * fontSize, m_camera->m_height - height - 3.0f * fontSize }, ImGuiCond_Once ); - ImGui::SetNextWindowSize( { 20.0f * fontSize, height } ); - - ImGui::Begin( "Explosion", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize ); - - ImGui::SliderFloat( "impulse", &m_impulse, 0.0f, 2000.0f, "%.0f" ); - - if ( ImGui::Button( "explode" ) ) + if ( ImGui::Button( "Explode" ) ) { Explode(); } - ImGui::End(); - } - - void Render() override - { - Sample::Render(); - b3Transform transform = { { 0.0f, 0.1f, 0.0f }, b3Quat_identity }; - DrawTransform( m_scene, transform, 4.0f ); + return true; } static Sample* Create( SampleContext* context ) @@ -524,7 +490,7 @@ public: float m_impulse; }; -static int sampleExplosion = SampleManager::Register( "Benchmark", "Explosion", BenchmarkExplosion::Create ); +static int sampleExplosion = RegisterSample( "Benchmark", "Explosion", BenchmarkExplosion::Create ); class BenchmarkHeightField : public Sample { @@ -558,7 +524,7 @@ public: { if ( context->restart == false ) { - m_camera->SetView( 45.0f, 30.0f, 20.0f ); + m_camera->SetView( 0.0f, 20.0f, 50.0f ); } m_columnCount = 50; @@ -579,25 +545,19 @@ public: b3DestroyHeightField( m_heightField ); } - void UpdateUI() override + bool DrawControls() override { - float fontSize = ImGui::GetFontSize(); - float height = 4.0f * fontSize; - ImGui::SetNextWindowPos( { 1.0f * fontSize, m_camera->m_height - height - 3.0f * fontSize }, ImGuiCond_Once ); - ImGui::SetNextWindowSize( { 20.0f * fontSize, height } ); - - ImGui::Begin( "Height Field", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize ); - ImGui::SliderFloat( "radius", &m_radius, 0.0f, 1.0f, "%.1f" ); - ImGui::End(); + ImGui::SliderFloat( "Radius", &m_radius, 0.0f, 1.0f, "%.1f" ); + return true; } void Render() override { Sample::Render(); - DrawLine( m_scene, b3Vec3_zero, 0.4f * b3Vec3_axisX, b3_colorRed ); - DrawLine( m_scene, b3Vec3_zero, 0.4f * b3Vec3_axisY, b3_colorGreen ); - DrawLine( m_scene, b3Vec3_zero, 0.4f * b3Vec3_axisZ, b3_colorBlue ); + DrawLine( b3Vec3_zero, 0.4f * b3Vec3_axisX, MakeColor( b3_colorRed ) ); + DrawLine( b3Vec3_zero, 0.4f * b3Vec3_axisY, MakeColor( b3_colorGreen ) ); + DrawLine( b3Vec3_zero, 0.4f * b3Vec3_axisZ, MakeColor( b3_colorBlue ) ); int hitCount = 0; int iterationCount = 0; @@ -650,28 +610,29 @@ public: if ( m_isDebug ) { b3Vec3 point = result.point; - DrawLine( m_scene, point, point + 0.5f * result.normal, b3_colorGreen ); - DrawPoint( m_scene, point, 10.0f, b3_colorGreen ); + DrawLine( point, point + 0.5f * result.normal, MakeColor( b3_colorGreen ) ); + DrawPoint( point, 10.0f, MakeColor( b3_colorGreen ) ); if ( m_radius > 0.0f ) { b3Transform transform = b3Transform_identity; transform.p = rayOrigin + result.fraction * rayTranslation; - DrawSphere( m_scene, transform, sphere, b3_colorPurple ); + DrawSphereEx( transform, m_radius, MakeColorAlpha( b3_colorPurple, 0.5f ), 0.0f, 0.5f, + TRANSPARENT_SHADOW_NONE ); } b3Vec3 rayEnd = rayOrigin + result.fraction * rayTranslation; - DrawLine( m_scene, rayOrigin, rayEnd, b3_colorYellow ); - DrawPoint( m_scene, rayOrigin, 2.0f, b3_colorRed ); - DrawPoint( m_scene, rayEnd, 2.0f, b3_colorRed ); + DrawLine( rayOrigin, rayEnd, MakeColor( b3_colorYellow ) ); + DrawPoint( rayOrigin, 2.0f, MakeColor( b3_colorRed ) ); + DrawPoint( rayEnd, 2.0f, MakeColor( b3_colorRed ) ); } } else if ( m_isDebug ) { b3Vec3 rayEnd = rayOrigin + rayTranslation; - DrawLine( m_scene, rayOrigin, rayEnd, b3_colorYellow ); - DrawPoint( m_scene, rayOrigin, 2.0f, b3_colorRed ); - DrawPoint( m_scene, rayEnd, 2.0f, b3_colorRed ); + DrawLine( rayOrigin, rayEnd, MakeColor( b3_colorYellow ) ); + DrawPoint( rayOrigin, 2.0f, MakeColor( b3_colorRed ) ); + DrawPoint( rayEnd, 2.0f, MakeColor( b3_colorRed ) ); } } } @@ -700,7 +661,7 @@ public: float m_radius; }; -static int sampleHeightFieldBenchmark = SampleManager::Register( "Benchmark", "Height Field", BenchmarkHeightField::Create ); +static int sampleHeightFieldBenchmark = RegisterSample( "Benchmark", "Height Field", BenchmarkHeightField::Create ); class BenchmarkFallingTrees : public Sample { @@ -710,9 +671,7 @@ public: { if ( context->restart == false ) { - float distance = 220.0f; - float height = 20.0f; - m_camera->SetView( 25.0f, 10.0f, distance, { 0.0f, height, 0.0f } ); + m_camera->SetView( 20.0f, 0.0f, 140.0f, { 0.0f, 15.0f, 0.0f } ); } m_gridSize = 100; @@ -746,17 +705,8 @@ public: } } - void UpdateUI() override + bool DrawControls() override { - Sample::UpdateUI(); - - float fontSize = ImGui::GetFontSize(); - float height = 10.0f * fontSize; - ImGui::SetNextWindowPos( { 1.0f * fontSize, m_camera->m_height - height - 3.0f * fontSize }, ImGuiCond_Once ); - ImGui::SetNextWindowSize( { 20.0f * fontSize, height } ); - - ImGui::Begin( "Falling Trees", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize ); - if ( ImGui::RadioButton( "100cm", &m_gridSize, 100 ) ) { Generate(); @@ -772,7 +722,7 @@ public: Generate(); } - ImGui::End(); + return true; } static Sample* Create( SampleContext* context ) @@ -783,7 +733,7 @@ public: int m_gridSize; }; -static int sampleFallingTrees = SampleManager::Register( "Benchmark", "Falling Trees", BenchmarkFallingTrees::Create ); +static int sampleFallingTrees = RegisterSample( "Benchmark", "Falling Trees", BenchmarkFallingTrees::Create ); struct ShapeUserData { @@ -799,7 +749,7 @@ public: { if ( m_context->restart == false ) { - m_camera->SetView( 5.0f, 18.0f, 180.0f, { 0.0f, 5.0f, 0.0f } ); + m_camera->SetView( 0.0f, 0.0f, 250.0f, { 0.0f, 110.0f, 0.0f } ); } b3World_SetCustomFilterCallback( m_worldId, FilterFcn, this ); @@ -807,61 +757,77 @@ public: m_activeSensor.row = 0; m_activeSensor.active = true; - b3BodyDef bodyDef = b3DefaultBodyDef(); - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - { float gridSize = 3.0f; + // These destroy anything they touch, including themselves. + b3BoxHull box = b3MakeCubeHull( 0.48f * gridSize ); + b3BodyDef bodyDef = b3DefaultBodyDef(); + b3ShapeDef shapeDef = b3DefaultShapeDef(); shapeDef.isSensor = true; shapeDef.enableSensorEvents = true; shapeDef.userData = &m_activeSensor; + shapeDef.baseMaterial.customColor = b3MakeDebugColor( (b3HexColor)0x505050u, b3_debugMaterialMetallic ); float y = 0.0f; float x = -40.0f * gridSize; for ( int i = 0; i < 81; ++i ) { - b3Vec3 extents = { 0.5f * gridSize, 0.5f * gridSize, 0.5f * gridSize }; - b3Transform transform = { { x, y, 0.0f }, b3Quat_identity }; - b3BoxHull box = b3MakeTransformedBoxHull( extents.x, extents.y, extents.z, transform ); + bodyDef.position = { x, y, 0.0f }; + b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); b3CreateHullShape( groundId, &shapeDef, &box.base ); x += gridSize; } } - g_randomSeed = 42; - - float shift = 5.0f; - float xCenter = 0.5f * shift * m_columnCount; - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.isSensor = true; - shapeDef.enableSensorEvents = true; - - float yStart = 10.0f; - - for ( int j = 0; j < m_rowCount; ++j ) { - m_passiveSensors[j].row = j; - m_passiveSensors[j].active = false; - shapeDef.userData = m_passiveSensors + j; + g_randomSeed = 42; - float y = j * shift + yStart; - for ( int i = 0; i < m_columnCount; ++i ) + float shift = 5.0f; + float xCenter = 0.5f * shift * m_columnCount; + + b3BodyDef bodyDef = b3DefaultBodyDef(); + + b3BoxHull box = b3MakeCubeHull( 0.5f ); + b3ShapeDef shapeDef = b3DefaultShapeDef(); + shapeDef.isSensor = true; + shapeDef.enableSensorEvents = true; + + float yStart = 10.0f; + m_filterRow = m_rowCount >> 1; + + for ( int j = 0; j < m_rowCount; ++j ) { - float x = i * shift - xCenter; - b3Vec3 extents = { 0.5f, 0.5f, 0.5f }; - b3Transform transform = { { x, y, 0.0f }, b3Quat_identity }; - b3BoxHull box = b3MakeTransformedBoxHull( extents.x, extents.y, extents.z, transform ); - b3CreateHullShape( groundId, &shapeDef, &box.base ); + m_passiveSensors[j].row = j; + m_passiveSensors[j].active = false; + shapeDef.userData = m_passiveSensors + j; + + if ( j == m_filterRow ) + { + shapeDef.enableCustomFiltering = true; + shapeDef.baseMaterial.customColor = b3_colorFuchsia; + } + else + { + shapeDef.enableCustomFiltering = false; + shapeDef.baseMaterial.customColor = 0; + } + + float y = j * shift + yStart; + for ( int i = 0; i < m_columnCount; ++i ) + { + float x = i * shift - xCenter; + bodyDef.position = { x, y, 0.0f }; + b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); + b3CreateHullShape( groundId, &shapeDef, &box.base ); + } } } m_maxBeginCount = 0; m_maxEndCount = 0; m_lastStepCount = 0; - m_filterRow = m_rowCount >> 1; } void CreateRow( float y ) @@ -1000,7 +966,7 @@ public: int m_filterRow; }; -static int benchmarkSensor = SampleManager::Register( "Benchmark", "Sensor", BenchmarkSensor::Create ); +static int benchmarkSensor = RegisterSample( "Benchmark", "Sensor", BenchmarkSensor::Create ); class BenchmarkWasher : public Sample { @@ -1010,8 +976,7 @@ public: { if ( m_context->restart == false ) { - m_camera->SetView( 0.0f, 20.0f, 60.0, { 0.0f, 15.0f, 0.0f } ); - EnableGrid( m_scene, true ); + m_camera->SetView( 15.0f, 20.0f, 60.0, { 0.0f, 15.0f, 0.0f } ); } b3Capacity capacity = {}; @@ -1019,6 +984,7 @@ public: CreateWorld( &capacity ); CreateWasher( m_worldId ); + SetGroundShape( GetGroundShapeId() ); } static Sample* Create( SampleContext* context ) @@ -1027,7 +993,7 @@ public: } }; -static int benchmarkWasher = SampleManager::Register( "Benchmark", "Washer", BenchmarkWasher::Create ); +static int benchmarkWasher = RegisterSample( "Benchmark", "Washer", BenchmarkWasher::Create ); class BenchmarkLargeWorld : public Sample { @@ -1037,8 +1003,7 @@ public: { if ( context->restart == false ) { - m_camera->SetView( 0.0f, 60.0f, 80.0f, b3Vec3_zero ); - EnableGrid( m_scene, false ); + m_camera->SetView( 0.0f, 10.0f, 250.0f, b3Vec3_zero ); } b3Capacity capacity = {}; @@ -1060,7 +1025,7 @@ public: } }; -static int sampleLargeWorld = SampleManager::Register( "Benchmark", "Large World", BenchmarkLargeWorld::Create ); +static int sampleLargeWorld = RegisterSample( "Benchmark", "Large World", BenchmarkLargeWorld::Create ); class BenchmarkHull : public Sample { @@ -1097,8 +1062,8 @@ public: b3Transform transform1 = { { -2.0f, 0.0f, 0.0f }, b3Quat_identity }; b3Transform transform2 = { { 2.0f, 0.0f, 0.0f }, b3Quat_identity }; - DrawHull( m_scene, transform1, m_hull, b3_colorGreen, true ); - DrawHull( m_scene, transform2, m_transformedHull, b3_colorYellow, true ); + DrawHull( transform1, m_hull, MakeColor( b3_colorGreen ) ); + DrawHull( transform2, m_transformedHull, MakeColor( b3_colorYellow ) ); Sample::Render(); } @@ -1148,7 +1113,7 @@ public: int m_count; }; -static int sampleBenchmarkHull = SampleManager::Register( "Benchmark", "Hull", BenchmarkHull::Create ); +static int sampleBenchmarkHull = RegisterSample( "Benchmark", "Hull", BenchmarkHull::Create ); class BenchmarkChains : public Sample { @@ -1159,7 +1124,6 @@ public: if ( context->restart == false ) { m_camera->SetView( 0.0f, 15.0f, 50.0f, { 0.0f, 5.0f, 0.0f } ); - EnableGrid( context->scene, false ); } b3BodyDef bodyDef = b3DefaultBodyDef(); @@ -1261,7 +1225,7 @@ public: b3Vec3 m_noise; }; -static int sampleBenchmarkChains = SampleManager::Register( "Benchmark", "Chains", BenchmarkChains::Create ); +static int sampleBenchmarkChains = RegisterSample( "Benchmark", "Chains", BenchmarkChains::Create ); class BenchmarkDestruction : public Sample { @@ -1273,13 +1237,12 @@ public: { if ( m_small ) { - m_camera->SetView( 0.0f, 40.0f, 10.0f, { 0.0f, 0.0f, 0.0f } ); + m_camera->SetView( 0.0f, 40.0f, 20.0f, { 0.0f, 0.0f, 0.0f } ); } else { m_camera->SetView( 0.0f, 40.0f, 30.0f, { 0.0f, 0.0f, 0.0f } ); } - EnableGrid( m_context->scene, false ); } int bodyCapacity = m_gridCount * m_gridCount * m_gridCount; @@ -1298,6 +1261,7 @@ public: b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); b3CreateMeshShape( groundId, &shapeDef, m_gridMesh, b3Vec3_one ); +#if 0 { b3Transform transform; transform.p = { 0.0f, 5.0f, -20.0f }; @@ -1333,6 +1297,7 @@ public: shapeDef.name = "wall4"; b3CreateHullShape( groundId, &shapeDef, &wallBox.base ); } +#endif m_bodyIds = (b3BodyId*)malloc( bodyCapacity * sizeof( b3BodyId ) ); memset( m_bodyIds, 0, bodyCapacity * sizeof( b3BodyId ) ); @@ -1414,17 +1379,16 @@ public: { Sample::Render(); - b3Transform transform = { { 0.0f, 0.1f, 0.0f }, b3Quat_identity }; - DrawTransform( m_scene, transform, 4.0f ); - DrawTextLine( "spawn = %.2f ms", m_spawnMilliseconds ); DrawTextLine( "destroy = %.2f ms", m_destroyMilliseconds ); float r = m_explosionDef.radius; - DrawSphere( m_scene, b3Transform_identity, { m_explosionDef.position, r }, b3_colorAqua ); + b3Sphere sphere1 = { m_explosionDef.position, r }; + DrawWireSphere( b3Transform_identity, &sphere1, 24, MakeColor( b3_colorAqua ) ); float rf = r + m_explosionDef.falloff; - DrawSphere( m_scene, b3Transform_identity, { m_explosionDef.position, rf }, b3_colorCornsilk ); + b3Sphere sphere2 = { m_explosionDef.position, rf }; + DrawWireSphere( b3Transform_identity, &sphere2, 24, MakeColor( b3_colorCornsilk ) ); } void Step() override @@ -1456,7 +1420,7 @@ public: float m_destroyMilliseconds; }; -static int sampleDestruction = SampleManager::Register( "Benchmark", "Destruction", BenchmarkDestruction::Create ); +static int sampleDestruction = RegisterSample( "Benchmark", "Destruction", BenchmarkDestruction::Create ); class BenchmarkJunkyard : public Sample { @@ -1466,12 +1430,13 @@ public: { if ( context->restart == false ) { - m_camera->SetView( 45.0f, 30.0f, 100.0f, b3Vec3_zero ); - context->debugDraw.drawJoints = false; - EnableGrid( m_scene, true ); + m_camera->SetView( 45.0f, 30.0f, 125.0f, b3Vec3_zero ); + GetGuiDraw()->drawJoints = false; } CreateJunkyard( m_worldId ); + + SetGroundShape( GetGroundShapeId() ); } void Step() override @@ -1486,4 +1451,4 @@ public: } }; -static int sampleJunkyard = SampleManager::Register( "Benchmark", "Junkyard", BenchmarkJunkyard::Create ); +static int sampleJunkyard = RegisterSample( "Benchmark", "Junkyard", BenchmarkJunkyard::Create ); diff --git a/samples/sample_bodies.cpp b/samples/sample_bodies.cpp index d58095d..aaad92d 100644 --- a/samples/sample_bodies.cpp +++ b/samples/sample_bodies.cpp @@ -1,14 +1,13 @@ // SPDX-FileCopyrightText: 2025 Erin Catto // SPDX-License-Identifier: MIT -#include "GLFW/glfw3.h" -#include "camera.h" #include "imgui.h" -#include "renderer.h" #include "sample.h" -#include "scene.h" + +#include "gfx/keycodes.h" #include "box3d/box3d.h" +#include "gfx/draw.h" class BodyType : public Sample { @@ -24,18 +23,7 @@ public: m_type = b3_dynamicBody; m_isEnabled = true; - b3BodyId groundId = b3_nullBodyId; - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position.y = -1.0f; - bodyDef.name = "ground"; - groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3BoxHull box = b3MakeBoxHull( 20.0f, 1.0f, 20.0f ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHullShape( groundId, &shapeDef, &box.base ); - } + b3BodyId groundId = AddGroundBox( 20.0f ); // Define attachment { @@ -188,14 +176,8 @@ public: } } - void UpdateUI() override + bool DrawControls() override { - float fontSize = ImGui::GetFontSize(); - float height = 11.0f * fontSize; - ImGui::SetNextWindowPos( ImVec2( 0.5f * fontSize, m_camera->m_height - height - 2.0f * fontSize ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 9.0f * fontSize, height ) ); - ImGui::Begin( "Body Type", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize ); - if ( ImGui::RadioButton( "Static", m_type == b3_staticBody ) ) { m_type = b3_staticBody; @@ -248,7 +230,7 @@ public: } } - ImGui::End(); + return true; } void Step() override @@ -285,7 +267,7 @@ public: bool m_isEnabled; }; -static int sampleBodyType = SampleManager::Register( "Bodies", "Body Type", BodyType::Create ); +static int sampleBodyType = RegisterSample( "Bodies", "Body Type", BodyType::Create ); class SpinningBooks : public Sample { @@ -298,6 +280,8 @@ public: m_camera->SetView( 0.0f, 30.0f, 10.0f, { 0.0f, 1.0f, 0.0f } ); } + AddGroundBox( 10.0f ); + b3BoxHull box = b3MakeBoxHull( 0.35f, 0.08f, 0.5f ); b3BodyDef bodyDef = b3DefaultBodyDef(); @@ -325,19 +309,13 @@ public: b3CreateHullShape( body3, &shapeDef, &box.base ); } - void Render() override - { - DrawGrid( m_scene, 10 ); - Sample::Render(); - } - static Sample* Create( SampleContext* context ) { return new SpinningBooks( context ); } }; -static int sampleBook = SampleManager::Register( "Bodies", "Spinning Book", SpinningBooks::Create ); +static int sampleBook = RegisterSample( "Bodies", "Spinning Book", SpinningBooks::Create ); // Dzhanibekov effect class GyroscopicTorque : public Sample @@ -351,6 +329,8 @@ public: m_camera->SetView( 0.0f, 20.0f, 4.0f, { 0.0f, 2.0f, 0.0f } ); } + AddGroundBox( 20.0f ); + b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.type = b3_dynamicBody; bodyDef.position = { 0.0f, 2.0f, 0.0f }; @@ -368,28 +348,17 @@ public: b3DestroyHull( cylinder ); } - void Render() override - { - Sample::Render(); - DrawGrid( m_scene, 10 ); - } - static Sample* Create( SampleContext* sampleContext ) { return new GyroscopicTorque( sampleContext ); } }; -static int sampleGyroscopicTorque = SampleManager::Register( "Bodies", "Gyroscopic Torque", GyroscopicTorque::Create ); +static int sampleGyroscopicTorque = RegisterSample( "Bodies", "Gyroscopic Torque", GyroscopicTorque::Create ); class Weeble : public Sample { public: - static Sample* Create( SampleContext* context ) - { - return new Weeble( context ); - } - explicit Weeble( SampleContext* context ) : Sample( context ) { @@ -398,19 +367,15 @@ public: m_camera->SetView( 45.0f, 25.0f, 25.0f, b3Vec3_zero ); } + AddGroundBox( 30.0f ); + b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - b3BodyId groundBody = b3CreateBody( m_worldId, &bodyDef ); - - b3BoxHull box = b3MakeBoxHull( 32.0f, 1.0f, 32.0f ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHullShape( groundBody, &shapeDef, &box.base ); - bodyDef.type = b3_dynamicBody; bodyDef.position = { 0.0f, 3.0f, 0.0f }; m_weebleId = b3CreateBody( m_worldId, &bodyDef ); b3Capsule capsule = { { 0.0f, -1.0f }, { 0.0f, 1.0f }, 1.0f }; + b3ShapeDef shapeDef = b3DefaultShapeDef(); shapeDef.baseMaterial.rollingResistance = 0.1f; b3CreateCapsuleShape( m_weebleId, &shapeDef, &capsule ); @@ -432,16 +397,11 @@ public: m_explosionPosition = { 0.0f, -0.1f, 0.0f }; m_explosionRadius = 8.0f; - m_explosionMagnitude = 10000.0f; + m_explosionMagnitude = 20000.0f; } - void UpdateUI() override + bool DrawControls() override { - float height = 120.0f; - ImGui::SetNextWindowPos( ImVec2( 10.0f, m_camera->m_height - height - 50.0f ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 200.0f, height ) ); - - ImGui::Begin( "Weeble", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize ); if ( ImGui::Button( "Teleport" ) ) { b3Body_SetTransform( m_weebleId, { 0.0f, 5.0f, 0.0f }, b3MakeQuatFromAxisAngle( b3Vec3_axisZ, 0.95f * B3_PI ) ); @@ -457,27 +417,20 @@ public: def.impulsePerArea = m_explosionMagnitude; b3World_Explode( m_worldId, &def ); } - ImGui::PushItemWidth( 100.0f ); + ImGui::PushItemWidth( 6.0f * ImGui::GetFontSize() ); ImGui::SliderFloat( "Magnitude", &m_explosionMagnitude, -100000.0f, 100000.0f, "%.0f" ); ImGui::PopItemWidth(); - ImGui::End(); - } - - void Render() override - { - Sample::Render(); - b3Transform transform = { { 0.0f, 0.1f, 0.0f }, b3Quat_identity }; - DrawTransform( m_scene, transform, 4.0f ); + return true; } void Step() override { Sample::Step(); - b3Sphere sphere = { b3Vec3_zero, m_explosionRadius }; - DrawSphere( m_scene, { m_explosionPosition, b3Quat_identity }, sphere, b3_colorAzure ); + b3Sphere sphere = { m_explosionPosition, m_explosionRadius }; + DrawWireSphere(b3Transform_identity, &sphere, 64, MakeColor(b3_colorAzure) ); // This shows how to get the velocity of a point on a body b3Vec3 localPoint = { 0.0f, 2.0f, 0.0f }; @@ -487,8 +440,13 @@ public: b3Vec3 v2 = b3Body_GetWorldPointVelocity( m_weebleId, worldPoint ); b3Vec3 offset = { 0.05f, 0.0f }; - DrawLine( m_scene, worldPoint, worldPoint + v1, b3_colorRed ); - DrawLine( m_scene, worldPoint + offset, worldPoint + v2 + offset, b3_colorGreen ); + DrawLine( worldPoint, worldPoint + v1, MakeColor( b3_colorRed ) ); + DrawLine( worldPoint + offset, worldPoint + v2 + offset, MakeColor( b3_colorGreen ) ); + } + + static Sample* Create( SampleContext* context ) + { + return new Weeble( context ); } b3BodyId m_weebleId; @@ -497,7 +455,7 @@ public: float m_explosionMagnitude; }; -static int sampleWeeble = SampleManager::Register( "Bodies", "Weeble", Weeble::Create ); +static int sampleWeeble = RegisterSample( "Bodies", "Weeble", Weeble::Create ); class DisableBody : public Sample { @@ -515,23 +473,19 @@ public: m_camera->SetView( 45.0f, 25.0f, 10.0f, b3Vec3_zero ); } + AddGroundBox( 20.0f ); + b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - - b3BodyId groundBody = b3CreateBody( m_worldId, &bodyDef ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull box = b3MakeBoxHull( 25.0f, 1.0f, 25.0f ); - b3CreateHullShape( groundBody, &shapeDef, &box.base ); float linkRadius = 0.1f; float linkLength = 5.0f * linkRadius; - b3Capsule capsule = { { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, linkLength }, linkRadius }; + b3Capsule capsule = { { 0.0f, 0.0f, 0.0f }, { 0.0f, -linkLength, 0.0f }, linkRadius }; b3BodyId parentId = {}; for ( int link = 0; link < e_count; ++link ) { - bodyDef.position = { 0.0f, 0.8f * float( e_count ) * linkLength, link * linkLength }; + bodyDef.position = { 0.0f, (float( e_count ) - link) * linkLength + 1.0f, 0.0f }; bodyDef.type = B3_IS_NULL( parentId ) ? b3_kinematicBody : b3_dynamicBody; b3BodyId childId = b3CreateBody( m_worldId, &bodyDef ); b3CreateCapsuleShape( childId, &shapeDef, &capsule ); @@ -542,7 +496,7 @@ public: b3WeldJointDef jointDef = b3DefaultWeldJointDef(); jointDef.base.bodyIdA = parentId; jointDef.base.bodyIdB = childId; - jointDef.base.localFrameA.p = { 0.0f, 0.0f, linkLength }; + jointDef.base.localFrameA.p = { 0.0f, -linkLength, 0.0f }; jointDef.angularHertz = 10.0f; jointDef.angularDampingRatio = 1.0f; b3CreateWeldJoint( m_worldId, &jointDef ); @@ -559,14 +513,8 @@ public: b3CreateSphereShape( m_ballId, &shapeDef, &sphere ); } - void UpdateUI() override + bool DrawControls() override { - float height = 100.0f; - ImGui::SetNextWindowPos( ImVec2( 10.0f, m_camera->m_height - height - 50.0f ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 200.0f, height ) ); - - ImGui::Begin( "Distance", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize ); - { bool enabled = b3Body_IsEnabled( m_bodyIds[2] ); if ( ImGui::Checkbox( "Enable Link", &enabled ) ) @@ -597,7 +545,7 @@ public: } } - ImGui::End(); + return true; } void Step() override @@ -616,7 +564,7 @@ public: b3BodyId m_ballId; }; -static int sampleDisable = SampleManager::Register( "Bodies", "Disable", DisableBody::Create ); +static int sampleDisable = RegisterSample( "Bodies", "Disable", DisableBody::Create ); class BodyCast : public Sample { @@ -657,7 +605,7 @@ public: void MouseDown( b3Vec2 p, int button, int modifiers ) override { - if ( button == 0 && modifiers == GLFW_MOD_ALT ) + if ( button == 0 && modifiers == MOD_ALT ) { PickRay pickRay = m_camera->BuildPickRay( p.x, p.y ); m_origin = pickRay.origin + 10.0f * b3Normalize( pickRay.translation ); @@ -684,11 +632,11 @@ public: { Sample::Render(); - DrawGrid( m_scene, 10 ); + DrawGroundGrid( 10 ); b3Transform transform = { { 0.0f, 0.1f, 0.0f }, b3Quat_identity }; - DrawTransform( m_scene, transform, 4.0f ); + DrawAxes( transform, 4.0f ); - DrawHull( m_scene, m_transform, m_cylinder, b3_colorBlue, false ); + DrawHull( m_transform, m_cylinder, MakeColor( b3_colorBlue ) ); } void Step() override @@ -702,16 +650,16 @@ public: input.maxFraction = 1.0f; b3BodyCastResult result = b3Body_CastRay( m_bodyId, &input, m_transform ); - DrawLine( m_scene, input.origin, input.origin + input.maxFraction * input.translation, b3_colorCyan ); + DrawLine( input.origin, input.origin + input.maxFraction * input.translation, MakeColor( b3_colorCyan ) ); if ( result.hit ) { - DrawLine( m_scene, result.point, result.point + 0.2f * result.normal, b3_colorYellow ); - DrawPoint( m_scene, result.point, 10.0f, b3_colorYellow ); + DrawLine( result.point, result.point + 0.2f * result.normal, MakeColor( b3_colorYellow ) ); + DrawPoint( result.point, 10.0f, MakeColor( b3_colorYellow ) ); } - DrawPoint( m_scene, input.origin, 10.0f, b3_colorGreen ); - DrawPoint( m_scene, input.origin + input.translation, 10.0f, b3_colorRed ); + DrawPoint( input.origin, 10.0f, MakeColor( b3_colorGreen ) ); + DrawPoint( input.origin + input.translation, 10.0f, MakeColor( b3_colorRed ) ); } // Cast sphere @@ -729,18 +677,18 @@ public: if ( result.hit ) { b3Transform transform = { result.fraction * input.translation, b3Quat_identity }; - DrawSphere( m_scene, transform, sphere, b3_colorGreen ); - DrawLine( m_scene, result.point, result.point + 0.2f * result.normal, b3_colorYellow ); + DrawSolidSphere( transform, sphere, MakeColor( b3_colorGreen ) ); + DrawLine( result.point, result.point + 0.2f * result.normal, MakeColor( b3_colorYellow ) ); } else { b3Transform transform = { input.maxFraction * input.translation, b3Quat_identity }; - DrawSphere( m_scene, transform, sphere, b3_colorWhite ); + DrawSolidSphere( transform, sphere, MakeColor( b3_colorWhite ) ); } - DrawLine( m_scene, sphere.center, sphere.center + input.maxFraction * input.translation, b3_colorWhite ); - DrawPoint( m_scene, sphere.center, 10.0f, b3_colorGreen ); - DrawPoint( m_scene, sphere.center + input.maxFraction * input.translation, 10.0f, b3_colorRed ); + DrawLine( sphere.center, sphere.center + input.maxFraction * input.translation, MakeColor( b3_colorWhite ) ); + DrawPoint( sphere.center, 10.0f, MakeColor( b3_colorGreen ) ); + DrawPoint( sphere.center + input.maxFraction * input.translation, 10.0f, MakeColor( b3_colorRed ) ); } // Overlap capsule @@ -751,11 +699,11 @@ public: if ( overlaps ) { - DrawCapsule( m_scene, b3Transform_identity, capsule, b3_colorGreen ); + DrawSolidCapsule( b3Transform_identity, capsule, MakeColor( b3_colorGreen ) ); } else { - DrawCapsule( m_scene, b3Transform_identity, capsule, b3_colorGray ); + DrawSolidCapsule( b3Transform_identity, capsule, MakeColor( b3_colorGray ) ); } } @@ -764,12 +712,12 @@ public: b3Capsule capsule = { { -10.25f, 2.0f, -0.75f }, { -10.25f, 3.0f, -0.75f }, 0.3f }; b3BodyPlaneResult bodyPlanes[4]; int count = b3Body_CollideMover( m_bodyId, bodyPlanes, 4, &capsule, b3DefaultQueryFilter(), m_transform ); - DrawCapsule( m_scene, b3Transform_identity, capsule, b3_colorPurple ); + DrawSolidCapsule( b3Transform_identity, capsule, MakeColor( b3_colorPurple ) ); for ( int i = 0; i < count; ++i ) { b3PlaneResult result = bodyPlanes[i].result; - DrawPlane( m_scene, result.plane.normal, result.point, b3_colorOrange ); + DrawPlane( result.plane.normal, result.point, MakeColor( b3_colorOrange ) ); } } } @@ -790,7 +738,7 @@ public: bool m_tracking; }; -static int sampleBodyCast = SampleManager::Register( "Bodies", "Cast", BodyCast::Create ); +static int sampleBodyCast = RegisterSample( "Bodies", "Cast", BodyCast::Create ); // This shows how to drive a kinematic body to reach a target class Kinematic : public Sample @@ -803,6 +751,8 @@ public: { m_camera->SetView( 0.0f, 30.0f, 10.0f, { 0.0f, 1.5f, 0.0f } ); } + + AddGroundBox( 20.0f ); m_amplitude = 2.0f; @@ -810,7 +760,7 @@ public: b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.type = b3_kinematicBody; bodyDef.position.x = 2.0f * m_amplitude; - bodyDef.position.y = m_amplitude; + bodyDef.position.y = m_amplitude + 1.0f; m_bodyId = b3CreateBody( m_worldId, &bodyDef ); @@ -822,13 +772,6 @@ public: m_time = 0.0f; } - void Render() override - { - Sample::Render(); - DrawGrid( m_scene, 10 ); - DrawTransform( m_scene, b3Transform_identity, 4.0f ); - } - void Step() override { float timeStep = m_context->hertz > 0.0f ? 1.0f / m_context->hertz : 0.0f; @@ -845,13 +788,13 @@ public: b3Vec3 point; point.x = 2.0f * m_amplitude * cosf( t ); - point.y = m_amplitude * ( sinf( 2.0f * t ) + 1.0f ); + point.y = m_amplitude * ( sinf( 2.0f * t ) + 1.0f ) + 1.0f; point.z = 0.0f; b3Quat rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, 2.0f * t ); b3Vec3 axis = b3RotateVector( rotation, { 0.0f, 1.0f, 0.0f } ); - DrawLine( m_scene, point - 0.5f * axis, point + 0.5f * axis, b3_colorPlum ); - DrawPoint( m_scene, point, 10.0f, b3_colorPlum ); + DrawLine( point - 0.5f * axis, point + 0.5f * axis, MakeColor( b3_colorPlum ) ); + DrawPoint( point, 10.0f, MakeColor( b3_colorPlum ) ); b3Body_SetTargetTransform( m_bodyId, { point, rotation }, timeStep, true ); } @@ -871,7 +814,7 @@ public: float m_time; }; -static int sampleKinematic = SampleManager::Register( "Bodies", "Kinematic", Kinematic::Create ); +static int sampleKinematic = RegisterSample( "Bodies", "Kinematic", Kinematic::Create ); class LockMixing : public Sample { @@ -884,16 +827,7 @@ public: m_camera->SetView( 45.0f, 30.0f, 40.0f, b3Vec3_zero ); } - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull hull = b3MakeBoxHull( 15.0f, 1.0f, 15.0f ); - b3CreateHullShape( groundId, &shapeDef, &hull.base ); - } + AddGroundBox( 20.0f ); b3BoxHull cube = b3MakeBoxHull( 1.0f, 1.0f, 1.0f ); b3ShapeDef shapeDef = b3DefaultShapeDef(); @@ -962,7 +896,7 @@ public: } }; -static int sampleLockMixing = SampleManager::Register( "Bodies", "Lock Mixing", LockMixing::Create ); +static int sampleLockMixing = RegisterSample( "Bodies", "Lock Mixing", LockMixing::Create ); // A fully rotation locked body uses a zero inverse inertia tensor class FixedRotation : public Sample @@ -976,16 +910,7 @@ public: m_camera->SetView( 0.0f, 15.0f, 10.0f, b3Vec3_zero ); } - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull hull = b3MakeBoxHull( 15.0f, 1.0f, 15.0f ); - b3CreateHullShape( groundId, &shapeDef, &hull.base ); - } + AddGroundBox( 20.0f ); b3Capsule capsule = { { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 0.3f }; b3ShapeDef shapeDef = b3DefaultShapeDef(); @@ -1020,4 +945,4 @@ public: } }; -static int sampleFixedRotation = SampleManager::Register( "Bodies", "Fixed Rotation", FixedRotation::Create ); +static int sampleFixedRotation = RegisterSample( "Bodies", "Fixed Rotation", FixedRotation::Create ); diff --git a/samples/sample_character.cpp b/samples/sample_character.cpp index c660fe3..f95eb21 100644 --- a/samples/sample_character.cpp +++ b/samples/sample_character.cpp @@ -1,17 +1,15 @@ // SPDX-FileCopyrightText: 2025 Erin Catto // SPDX-License-Identifier: MIT -#include "camera.h" -#include "mesh_loader.h" -#include "renderer.h" #include "sample.h" -#include "scene.h" + +#include "mesh_loader.h" +#include "gfx/draw.h" + +#include "gfx/keycodes.h" #include "box3d/box3d.h" -#include -// prevent clang format sorting glad.h with glfw3.h -#include #include class CapsulePlane : public Sample @@ -59,24 +57,20 @@ public: { Sample::Render(); - DrawGrid( m_scene, 10 ); - DrawLine( m_scene, b3Vec3_zero, 2.0f * b3Vec3_axisX, b3_colorRed ); - DrawLine( m_scene, b3Vec3_zero, 2.0f * b3Vec3_axisY, b3_colorGreen ); - DrawLine( m_scene, b3Vec3_zero, 2.0f * b3Vec3_axisZ, b3_colorBlue ); + DrawGroundGrid( 10 ); + DrawLine( b3Vec3_zero, 2.0f * b3Vec3_axisX, MakeColor( b3_colorRed ) ); + DrawLine( b3Vec3_zero, 2.0f * b3Vec3_axisY, MakeColor( b3_colorGreen ) ); + DrawLine( b3Vec3_zero, 2.0f * b3Vec3_axisZ, MakeColor( b3_colorBlue ) ); } - void UpdateUI() override + bool DrawControls() override { - ImGui::SetNextWindowPos( ImVec2( 10.0f, 600.0f ) ); - ImGui::SetNextWindowSize( ImVec2( 240.0f, 80.0f ) ); - ImGui::Begin( "Capsule Plane", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize ); - if ( ImGui::Button( "Solve" ) ) { Solve(); } - ImGui::End(); + return true; } static bool PlaneResultFcn( b3ShapeId shape, const b3PlaneResult* results, int planeCount, void* context ) @@ -92,7 +86,7 @@ public: void MouseDown( b3Vec2 p, int button, int modifiers ) override { - if ( button == 0 && ( modifiers & GLFW_MOD_ALT ) == 0 ) + if ( button == 0 && ( modifiers & MOD_ALT ) == 0 ) { PickRay pickRay = m_camera->BuildPickRay( p.x, p.y ); m_origin = pickRay.origin + 10.0f * b3Normalize( pickRay.translation ); @@ -120,7 +114,7 @@ public: { m_planeCount = 0; - DrawCapsule( m_scene, m_transform, m_capsule, b3_colorGreen ); + DrawSolidCapsule( m_transform, m_capsule, MakeColor( b3_colorGreen ) ); b3QueryFilter filter = b3DefaultQueryFilter(); b3Capsule capsule = { m_capsule.center1 + m_transform.p, m_capsule.center2 + m_transform.p, m_capsule.radius }; @@ -131,8 +125,8 @@ public: b3Plane plane = m_planes[i].plane; b3Vec3 p1 = m_transform.p + ( plane.offset - m_capsule.radius ) * plane.normal; b3Vec3 p2 = p1 + 0.1f * plane.normal; - DrawPoint( m_scene, p1, 5.0f, b3_colorYellow ); - DrawLine( m_scene, p1, p2, b3_colorYellow ); + DrawPoint( p1, 5.0f, MakeColor( b3_colorYellow ) ); + DrawLine( p1, p2, MakeColor( b3_colorYellow ) ); } } @@ -150,7 +144,7 @@ public: bool m_tracking; }; -static int sampleCapsulePlane = SampleManager::Register( "Character", "CapsulePlane", CapsulePlane::Create ); +static int sampleCapsulePlane = RegisterSample( "Character", "CapsulePlane", CapsulePlane::Create ); // Exercises the deep-overlap path of b3World_CollideMover against each primitive // shape type: drag the mover capsule (yellow) into the static sphere, capsule, @@ -216,7 +210,7 @@ public: void Render() override { Sample::Render(); - DrawGrid( m_scene, 12 ); + DrawGroundGrid( 12 ); } static bool PlaneResultFcn( b3ShapeId /*shape*/, const b3PlaneResult* results, int planeCount, void* context ) @@ -232,7 +226,7 @@ public: void MouseDown( b3Vec2 p, int button, int modifiers ) override { - if ( button == 0 && ( modifiers & GLFW_MOD_ALT ) == 0 ) + if ( button == 0 && ( modifiers & MOD_ALT ) == 0 ) { PickRay pickRay = m_camera->BuildPickRay( p.x, p.y ); m_origin = pickRay.origin + 10.0f * b3Normalize( pickRay.translation ); @@ -267,7 +261,7 @@ public: b3World_CollideMover( m_worldId, &worldMover, filter, PlaneResultFcn, this ); // Mover at the queried position. - DrawCapsule( m_scene, m_transform, m_capsule, b3_colorYellow ); + DrawSolidCapsule( m_transform, m_capsule, MakeColor( b3_colorYellow ) ); // One arrow per returned plane, drawn from the contact point along the // normal. A degenerate (zero) normal is drawn red to surface the bug. @@ -277,8 +271,8 @@ public: b3PlaneResult r = m_results[i]; bool valid = b3IsNormalized( r.plane.normal ); b3HexColor color = valid ? b3_colorLimeGreen : b3_colorRed; - DrawPoint( m_scene, r.point, 6.0f, color ); - DrawArrow( m_scene, r.point, r.point + 0.5f * r.plane.normal, 0.05f, color ); + DrawPoint( r.point, 6.0f, MakeColor( color ) ); + DrawArrow( r.point, r.point + 0.5f * r.plane.normal, MakeColor( color ) ); if ( valid == false ) { m_zeroNormalCount += 1; @@ -289,22 +283,18 @@ public: // Solve the planes and show the pushed-out capsule pose. b3PlaneSolverResult solved = b3SolvePlanes( b3Vec3_zero, solverPlanes, m_planeCount ); b3Transform pushed = { m_transform.p + solved.delta, m_transform.q }; - DrawCapsule( m_scene, pushed, m_capsule, b3_colorCyan ); + DrawSolidCapsule( pushed, m_capsule, MakeColor( b3_colorCyan ) ); DrawTextLine( "drag the capsule with the left mouse to push it into the shapes" ); DrawTextLine( "yellow = queried pose, cyan = solved push-out, lime = valid plane normals" ); DrawTextLine( "planes: %d degenerate normals: %d", m_planeCount, m_zeroNormalCount ); } - void UpdateUI() override + bool DrawControls() override { - float fontSize = ImGui::GetFontSize(); - ImGui::SetNextWindowPos( ImVec2( 10.0f, 600.0f ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 18.0f * fontSize, 5.0f * fontSize ) ); - ImGui::Begin( "Mover Overlap", nullptr, ImGuiWindowFlags_NoResize ); ImGui::Text( "planes: %d", m_planeCount ); ImGui::Text( "degenerate normals: %d", m_zeroNormalCount ); - ImGui::End(); + return true; } static constexpr int m_planeCapacity = 32; @@ -320,7 +310,7 @@ public: bool m_tracking; }; -static int sampleMoverOverlap = SampleManager::Register( "Character", "MoverOverlap", MoverOverlap::Create ); +static int sampleMoverOverlap = RegisterSample( "Character", "MoverOverlap", MoverOverlap::Create ); class BasicMover : public Sample { @@ -527,9 +517,9 @@ public: // Body->AddSphere( &ShapeDef, Sphere ); //} - m_camera->m_thirdPerson = true; + m_camera->m_thirdPerson = false; m_clipVelocity = true; - glfwSetInputMode( m_window, GLFW_CURSOR, GLFW_CURSOR_DISABLED ); + // sapp_lock_mouse( true ); //m_haveMouseLast = false; //m_mouseLast = { 0.0f, 0.0f }; @@ -539,7 +529,7 @@ public: ~BasicMover() override { m_camera->m_thirdPerson = false; - glfwSetInputMode( m_window, GLFW_CURSOR, GLFW_CURSOR_NORMAL ); + sapp_lock_mouse( false ); b3DestroyMesh( m_levelMesh ); b3DestroyMesh( m_stairs ); b3DestroyMesh( m_torus ); @@ -549,32 +539,25 @@ public: void Render() override { Sample::Render(); - DrawTransform( m_scene, { { 0.0f, 0.0f, 0.02f }, b3Quat_identity }, 2.0f ); + DrawAxes( { { 0.0f, 0.0f, 0.02f }, b3Quat_identity }, 2.0f ); } - void UpdateUI() override + bool DrawControls() override { - float fontSize = ImGui::GetFontSize(); - float height = 9.0f * fontSize; - ImGui::SetNextWindowPos( ImVec2( 0.5f * fontSize, m_camera->m_height - height - 2.0f * fontSize ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 19.0f * fontSize, height ) ); - - ImGui::Begin( "Mover", nullptr, ImGuiWindowFlags_NoResize ); - bool thirdPerson = m_camera->m_thirdPerson; - if ( ImGui::Checkbox( "Third Person (Key: T)", &thirdPerson ) ) + if ( ImGui::Checkbox( "Third Person (T)", &thirdPerson ) ) { ToggleThirdPerson(); } ImGui::Checkbox( "Clip Velocity", &m_clipVelocity ); - ImGui::End(); + return true; } void Keyboard( int key, int action, int mods ) override { - if ( key == GLFW_KEY_T && action == GLFW_PRESS ) + if ( key == KEY_T && action == ACTION_PRESS ) { ToggleThirdPerson(); } @@ -605,7 +588,7 @@ public: bool m_clipVelocity; }; -static int sampleMover = SampleManager::Register( "Character", "Mover", BasicMover::Create ); +static int sampleMover = RegisterSample( "Character", "Mover", BasicMover::Create ); struct ClosestShapeCastContext { @@ -893,7 +876,6 @@ struct RigidbodyCharacter // --- CategorizeGround: s&box-style box cast with radius shrinking --- void CategorizeGround() { - Scene* scene = m_sample->m_scene; b3Vec3 feet = GetFeetPosition(); // s&box: from = WorldPosition + Up*4, to = WorldPosition + Down*2 (Source units) @@ -910,7 +892,7 @@ struct RigidbodyCharacter if ( radiusScale < 0.7f ) { UpdateGround( false, b3Vec3_axisY ); - DrawLine( scene, from, to, b3_colorRed ); + DrawLine( from, to, MakeColor( b3_colorRed ) ); return; } tr = TraceBody( from, to, radiusScale, 0.5f ); @@ -919,13 +901,13 @@ struct RigidbodyCharacter if ( !tr.startedSolid && tr.hit && IsStandableSurface( tr.normal ) && m_jumpCooldown <= 0.0f ) { UpdateGround( true, tr.normal ); - DrawLine( scene, from, tr.hitPoint, b3_colorGreen ); - DrawPoint( scene, tr.hitPoint, 5.0f, b3_colorGreen ); + DrawLine( from, tr.hitPoint, MakeColor( b3_colorGreen ) ); + DrawPoint( tr.hitPoint, 5.0f, MakeColor( b3_colorGreen ) ); } else { UpdateGround( false, b3Vec3_axisY ); - DrawLine( scene, from, to, b3_colorGray ); + DrawLine( from, to, MakeColor( b3_colorGray ) ); } } @@ -947,7 +929,6 @@ struct RigidbodyCharacter return; } - Scene* scene = m_sample->m_scene; b3Vec3 pos = b3Body_GetPosition( m_bodyId ); b3Vec3 from = { pos.x, pos.y + 0.05f, pos.z }; @@ -982,7 +963,7 @@ struct RigidbodyCharacter b3Body_SetLinearVelocity( m_bodyId, vel ); } - DrawLine( scene, from, tr.endPosition, b3_colorCyan ); + DrawLine( from, tr.endPosition, MakeColor( b3_colorCyan ) ); } } @@ -990,7 +971,6 @@ struct RigidbodyCharacter // Returns true if a step was taken and m_stepPosition was set. bool TryStep( float maxStepHeight ) { - Scene* scene = m_sample->m_scene; b3Vec3 pos = b3Body_GetPosition( m_bodyId ); b3Vec3 vel = b3Body_GetLinearVelocity( m_bodyId ); @@ -1023,7 +1003,7 @@ struct RigidbodyCharacter radiusScale -= 0.1f; if ( radiusScale < 0.6f ) { - DrawLine( scene, forwardFrom, forwardTo, b3_colorRed ); + DrawLine( forwardFrom, forwardTo, MakeColor( b3_colorRed ) ); return false; } trForward = TraceBody( forwardFrom, forwardTo, radiusScale ); @@ -1035,7 +1015,7 @@ struct RigidbodyCharacter return false; } - DrawLine( scene, forwardFrom, trForward.endPosition, b3_colorYellow ); + DrawLine( forwardFrom, trForward.endPosition, MakeColor( b3_colorYellow ) ); // Remaining velocity direction after hit b3Vec3 hitPos = trForward.endPosition; @@ -1047,7 +1027,7 @@ struct RigidbodyCharacter if ( trUp.startedSolid ) { - DrawLine( scene, upFrom, upTo, b3_colorRed ); + DrawLine( upFrom, upTo, MakeColor( b3_colorRed ) ); return false; } @@ -1056,11 +1036,11 @@ struct RigidbodyCharacter if ( upDistance < 0.005f ) { // Too tight to step up - DrawLine( scene, upFrom, topPos, b3_colorRed ); + DrawLine( upFrom, topPos, MakeColor( b3_colorRed ) ); return false; } - DrawLine( scene, upFrom, topPos, b3_colorYellow ); + DrawLine( upFrom, topPos, MakeColor( b3_colorYellow ) ); // Phase 3 — ACROSS: from top position, trace in move direction float acrossDist = forwardDist * ( 1.0f - trForward.fraction ) + m_bodyRadius * 0.5f; @@ -1070,12 +1050,12 @@ struct RigidbodyCharacter if ( trAcross.startedSolid ) { - DrawLine( scene, acrossFrom, acrossTo, b3_colorRed ); + DrawLine( acrossFrom, acrossTo, MakeColor( b3_colorRed ) ); return false; } b3Vec3 acrossPos = trAcross.hit ? trAcross.endPosition : acrossTo; - DrawLine( scene, acrossFrom, acrossPos, b3_colorYellow ); + DrawLine( acrossFrom, acrossPos, MakeColor( b3_colorYellow ) ); // Phase 4 — DOWN: from across position, trace straight down b3Vec3 downFrom = acrossPos; @@ -1084,13 +1064,13 @@ struct RigidbodyCharacter if ( !trDown.hit ) { - DrawLine( scene, downFrom, downTo, b3_colorRed ); + DrawLine( downFrom, downTo, MakeColor( b3_colorRed ) ); return false; } if ( !IsStandableSurface( trDown.normal ) ) { - DrawLine( scene, downFrom, trDown.endPosition, b3_colorRed ); + DrawLine( downFrom, trDown.endPosition, MakeColor( b3_colorRed ) ); return false; } @@ -1101,8 +1081,8 @@ struct RigidbodyCharacter return false; } - DrawLine( scene, downFrom, trDown.endPosition, b3_colorYellow ); - DrawPoint( scene, trDown.endPosition, 8.0f, b3_colorYellow ); + DrawLine( downFrom, trDown.endPosition, MakeColor( b3_colorYellow ) ); + DrawPoint( trDown.endPosition, 8.0f, MakeColor( b3_colorYellow ) ); // Teleport body to step position b3Vec3 stepPos = { trDown.endPosition.x, trDown.endPosition.y + 0.01f, trDown.endPosition.z }; @@ -1316,24 +1296,23 @@ struct RigidbodyCharacter void DrawDebug() const { - Scene* scene = m_sample->m_scene; b3Vec3 pos = b3Body_GetPosition( m_bodyId ); b3Vec3 vel = b3Body_GetLinearVelocity( m_bodyId ); // Draw velocity vector (purple) - DrawLine( scene, pos, pos + vel, b3_colorPurple ); + DrawLine( pos, pos + vel, MakeColor( b3_colorPurple ) ); // Draw wish velocity (orange) - DrawLine( scene, pos, pos + m_lastWishVelocity, b3_colorOrange ); + DrawLine( pos, pos + m_lastWishVelocity, MakeColor( b3_colorOrange ) ); // Draw mass center (yellow dot) - DrawPoint( scene, m_massCenterWorld, 8.0f, b3_colorYellow ); + DrawPoint( m_massCenterWorld, 8.0f, MakeColor( b3_colorYellow ) ); // Draw ground indicator if ( m_onGround ) { b3Vec3 bottom = { pos.x, pos.y - m_totalHeight * 0.5f, pos.z }; - DrawLine( scene, bottom, bottom + 0.3f * m_groundNormal, b3_colorGreen ); + DrawLine( bottom, bottom + 0.3f * m_groundNormal, MakeColor( b3_colorGreen ) ); } } }; @@ -1514,13 +1493,13 @@ public: m_camera->m_thirdPerson = true; m_showDebug = true; - glfwSetInputMode( m_window, GLFW_CURSOR, GLFW_CURSOR_DISABLED ); + sapp_lock_mouse( true ); } ~RigidBodyCharacter() override { m_camera->m_thirdPerson = false; - glfwSetInputMode( m_window, GLFW_CURSOR, GLFW_CURSOR_NORMAL ); + sapp_lock_mouse( false ); b3DestroyMesh( m_levelMesh ); b3DestroyMesh( m_stairs ); b3DestroyMesh( m_building ); @@ -1531,12 +1510,12 @@ public: void Keyboard( int key, int action, int mods ) override { - if ( key == GLFW_KEY_T && action == GLFW_PRESS ) + if ( key == KEY_T && action == ACTION_PRESS ) { ToggleThirdPerson(); } - if ( key == GLFW_KEY_V && action == GLFW_PRESS ) + if ( key == KEY_V && action == ACTION_PRESS ) { m_showDebug = !m_showDebug; } @@ -1562,29 +1541,29 @@ public: if ( m_camera->m_thirdPerson ) { - if ( glfwGetKey( m_window, GLFW_KEY_W ) ) + if ( IsKeyDown( KEY_W ) ) { throttle.x += 1.0f; } - if ( glfwGetKey( m_window, GLFW_KEY_S ) ) + if ( IsKeyDown( KEY_S ) ) { throttle.x -= 1.0f; } - if ( glfwGetKey( m_window, GLFW_KEY_A ) ) + if ( IsKeyDown( KEY_A ) ) { throttle.y -= 1.0f; } - if ( glfwGetKey( m_window, GLFW_KEY_D ) ) + if ( IsKeyDown( KEY_D ) ) { throttle.y += 1.0f; } - if ( glfwGetKey( m_window, GLFW_KEY_SPACE ) ) + if ( IsKeyDown( KEY_SPACE ) ) { m_character.Jump(); } - m_character.m_sprint = m_character.m_onGround && glfwGetKey( m_window, GLFW_KEY_LEFT_SHIFT ) != 0; + m_character.m_sprint = m_character.m_onGround && IsKeyDown( KEY_LEFT_SHIFT ); } // Pre-step: manipulate velocity before physics @@ -1654,25 +1633,18 @@ public: void Render() override { Sample::Render(); - DrawTransform( m_scene, { { 0.0f, 0.0f, 0.02f }, b3Quat_identity }, 2.0f ); + DrawAxes( { { 0.0f, 0.0f, 0.02f }, b3Quat_identity }, 2.0f ); } - void UpdateUI() override + bool DrawControls() override { - float fontSize = ImGui::GetFontSize(); - float height = 12.0f * fontSize; - ImGui::SetNextWindowPos( ImVec2( 0.5f * fontSize, m_camera->m_height - height - 2.0f * fontSize ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 22.0f * fontSize, height ) ); - - ImGui::Begin( "Rigidbody Character", nullptr, ImGuiWindowFlags_NoResize ); - bool thirdPerson = m_camera->m_thirdPerson; - if ( ImGui::Checkbox( "Third Person (Key: T)", &thirdPerson ) ) + if ( ImGui::Checkbox( "Third Person (T)", &thirdPerson ) ) { ToggleThirdPerson(); } - ImGui::Checkbox( "Debug Visualization (Key: V)", &m_showDebug ); + ImGui::Checkbox( "Debug (V)", &m_showDebug ); ImGui::Separator(); ImGui::Text( "Ground: %s", m_character.m_onGround ? "YES" : "NO" ); @@ -1686,7 +1658,7 @@ public: b3Vec3 pos = b3Body_GetPosition( m_character.m_bodyId ); ImGui::Text( "Mass center offset: %.2f", mc.y - pos.y ); - ImGui::End(); + return true; } static Sample* Create( SampleContext* context ) @@ -1704,4 +1676,4 @@ public: bool m_showDebug; }; -static int sampleRBCharacter = SampleManager::Register( "Character", "Rigid Body", RigidBodyCharacter::Create ); +static int sampleRBCharacter = RegisterSample( "Character", "Rigid Body", RigidBodyCharacter::Create ); diff --git a/samples/sample_collision.cpp b/samples/sample_collision.cpp index 88419cf..883e053 100644 --- a/samples/sample_collision.cpp +++ b/samples/sample_collision.cpp @@ -1,12 +1,13 @@ // SPDX-FileCopyrightText: 2025 Erin Catto // SPDX-License-Identifier: MIT -#include "GLFW/glfw3.h" -#include "camera.h" -#include "utils.h" -#include "renderer.h" #include "sample.h" -#include "scene.h" + +#include "gfx/draw.h" +#include "utils.h" + +#include "gfx/debug_adapter.h" +#include "gfx/keycodes.h" #include "box3d/box3d.h" @@ -73,10 +74,10 @@ public: { Sample::Render(); - DrawGrid( m_scene, 10 ); - DrawLine( m_scene, b3Vec3_zero, 0.4f * b3Vec3_axisX, b3_colorRed ); - DrawLine( m_scene, b3Vec3_zero, 0.4f * b3Vec3_axisY, b3_colorGreen ); - DrawLine( m_scene, b3Vec3_zero, 0.4f * b3Vec3_axisZ, b3_colorBlue ); + DrawGroundGrid( 10 ); + DrawLine( b3Vec3_zero, 0.4f * b3Vec3_axisX, MakeColor( b3_colorRed ) ); + DrawLine( b3Vec3_zero, 0.4f * b3Vec3_axisY, MakeColor( b3_colorGreen ) ); + DrawLine( b3Vec3_zero, 0.4f * b3Vec3_axisZ, MakeColor( b3_colorBlue ) ); for ( float x = -8.0f; x <= 8.0f; x += 0.1f ) { @@ -88,12 +89,12 @@ public: { b3Vec3 point = result.point; - DrawLine( m_scene, point, point + 0.5f * result.normal, b3_colorGreen ); + DrawLine( point, point + 0.5f * result.normal, MakeColor( b3_colorGreen ) ); } - DrawPoint( m_scene, rayOrigin, 4.0f, b3_colorGreen ); - DrawPoint( m_scene, rayOrigin + rayTranslation, 4.0f, b3_colorRed ); - DrawLine( m_scene, rayOrigin, rayOrigin + rayTranslation, b3_colorYellow ); + DrawPoint( rayOrigin, 4.0f, MakeColor( b3_colorGreen ) ); + DrawPoint( rayOrigin + rayTranslation, 4.0f, MakeColor( b3_colorRed ) ); + DrawLine( rayOrigin, rayOrigin + rayTranslation, MakeColor( b3_colorYellow ) ); } if ( m_offset > 2.0f ) @@ -117,7 +118,7 @@ public: b3MeshData* m_mesh; }; -static int sampleRayCurtain = SampleManager::Register( "Collision", "Ray Curtain", RayCurtain::Create ); +static int sampleRayCurtain = RegisterSample( "Collision", "Ray Curtain", RayCurtain::Create ); // Context for ray cast callbacks. Do what you want with this. struct CastContext @@ -510,7 +511,7 @@ public: void MouseDown( b3Vec2 p, int button, int modifiers ) override { - if ( button == 0 && modifiers == GLFW_MOD_CONTROL ) + if ( button == 0 && modifiers == MOD_CTRL ) { PickRay pickRay = m_camera->BuildPickRay( p.x, p.y ); m_origin = pickRay.origin; @@ -518,14 +519,13 @@ public: } } - void UpdateUI() override + bool HasSolverControls() const override { - float height = 360.0f; - ImGui::SetNextWindowPos( ImVec2( 10.0f, m_camera->m_height - height - 50.0f ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 210.0f, height ) ); - - ImGui::Begin( "Options", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize ); + return false; + } + bool DrawControls() override + { const char* castTypes[] = { "Ray", "Sphere", "Capsule", "Box" }; if ( ImGui::Combo( "Cast Type", &m_castType, castTypes, IM_ARRAYSIZE( castTypes ) ) ) { @@ -573,16 +573,7 @@ public: DestroyBody(); } - ImGui::End(); - - for ( int i = 0; i < m_maxCount; ++i ) - { - if ( ( i & m_ignoreBase ) == m_ignoreBase && B3_IS_NULL( m_bodies[i] ) == false ) - { - b3AABB bounds = b3Body_ComputeAABB( m_bodies[i] ); - DrawBounds( m_scene, bounds, 0.0f, b3_colorYellow ); - } - } + return true; } void Render() override @@ -590,6 +581,16 @@ public: DrawTextLine( "Ctrl + left mouse to cast through cursor" ); DrawTextLine( "Shapes drawn in yellow boxes are ignored by the ray" ); + // Outline the bodies the cast ignores + for ( int i = 0; i < m_maxCount; ++i ) + { + if ( ( i & m_ignoreBase ) == m_ignoreBase && B3_IS_NULL( m_bodies[i] ) == false ) + { + b3AABB bounds = b3Body_ComputeAABB( m_bodies[i] ); + DrawBounds( bounds, 0.0f, MakeColor( b3_colorYellow ) ); + } + } + switch ( m_mode ) { case e_any: @@ -618,8 +619,8 @@ public: DrawTextLine( "material = %d, triangle = %d", m_castContext.materialIds[i], m_castContext.triangleIndices[i] ); } - DrawGrid( m_scene, 10 ); - DrawTransform( m_scene, b3Transform_identity, 1.0f ); + DrawGroundGrid( 10 ); + DrawAxes( b3Transform_identity, 1.0f ); Sample::Render(); } @@ -700,59 +701,59 @@ public: { assert( m_castContext.count <= 3 ); b3HexColor colors[3] = { b3_colorRed, b3_colorGreen, b3_colorBlue }; - DrawLine( m_scene, m_origin, m_origin + m_translation, color2 ); + DrawLine( m_origin, m_origin + m_translation, MakeColor( color2 ) ); for ( int i = 0; i < m_castContext.count; ++i ) { b3Vec3 point = m_castContext.points[i]; b3Vec3 normal = m_castContext.normals[i]; - DrawPoint( m_scene, point, 10.0f, colors[i] ); + DrawPoint( point, 10.0f, MakeColor( colors[i] ) ); b3Vec3 head = point + 0.5f * normal; b3Transform transform = { m_castContext.fractions[i] * m_translation, b3Quat_identity }; if ( m_castType == e_rayCast ) { - DrawLine( m_scene, point, head, colors[i] ); + DrawLine( point, head, MakeColor( colors[i] ) ); } else if ( m_castType == e_sphereCast ) { - DrawLine( m_scene, point, head, color1 ); - DrawSphere( m_scene, transform, sphere, colors[i] ); + DrawLine( point, head, MakeColor( color1 ) ); + DrawSolidSphere( transform, sphere, MakeColorAlpha( colors[i], 0.5f ) ); } else if ( m_castType == e_capsuleCast ) { - DrawLine( m_scene, point, head, color1 ); - DrawCapsule( m_scene, transform, capsule, colors[i] ); + DrawLine( point, head, MakeColor( color1 ) ); + DrawSolidCapsule( transform, capsule, MakeColor( colors[i] ) ); } else if ( m_castType == e_boxCast ) { - DrawLine( m_scene, point, head, color1 ); - DrawHull( m_scene, transform, &box.base, colors[i], false ); + DrawLine( point, head, MakeColor( color1 ) ); + DrawHull( transform, &box.base, MakeColor( colors[i] ) ); } } } else { - DrawLine( m_scene, m_origin, m_origin + m_translation, color2 ); + DrawLine( m_origin, m_origin + m_translation, MakeColor( color2 ) ); b3Transform transform = { m_translation, b3Quat_identity }; if ( m_castType == e_sphereCast ) { - DrawSphere( m_scene, transform, sphere, gray ); + DrawSolidSphere( transform, sphere, MakeColor( gray ) ); } else if ( m_castType == e_capsuleCast ) { - DrawCapsule( m_scene, transform, capsule, gray ); + DrawSolidCapsule( transform, capsule, MakeColor( gray ) ); } else if ( m_castType == e_boxCast ) { - DrawHull( m_scene, transform, &box.base, gray, false ); + DrawHull( transform, &box.base, MakeColor( gray ) ); } } - DrawPoint( m_scene, m_origin, 2.0f, green ); + DrawPoint( m_origin, 10.0f, MakeColor( green ) ); } static constexpr int m_maxCount = 64; @@ -777,7 +778,7 @@ public: CastContext m_castContext; }; -static int sampleCastWorld = SampleManager::Register( "Collision", "Cast World", CastWorld::Create ); +static int sampleCastWorld = RegisterSample( "Collision", "Cast World", CastWorld::Create ); class MeshScale : public Sample { @@ -812,14 +813,13 @@ public: b3DestroyMesh( m_mesh ); } - void UpdateUI() override + bool HasSolverControls() const override { - float height = 200.0f; - ImGui::SetNextWindowPos( ImVec2( 10.0f, m_camera->m_height - height - 50.0f ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 200.0f, height ) ); - - ImGui::Begin( "Mesh Scale", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize ); + return false; + } + bool DrawControls() override + { b3Vec3 scale = m_scale; bool changed = false; changed = changed || ImGui::SliderFloat( "Scale X", &scale.x, -2.0f, 2.0f, "%.1f" ); @@ -837,7 +837,7 @@ public: ImGui::Checkbox( "sphere Cast", &m_sphereCast ); - ImGui::End(); + return true; } void Step() override @@ -845,9 +845,9 @@ public: b3Vec3 rayOrigin = m_start; b3Vec3 rayTranslation = { 4.0f, 0.0f, 0.0f }; - DrawPoint( m_scene, rayOrigin, 8.0f, b3_colorGreen ); - DrawPoint( m_scene, rayOrigin + rayTranslation, 8.0f, b3_colorRed ); - DrawLine( m_scene, rayOrigin, rayOrigin + rayTranslation, b3_colorWhite ); + DrawPoint( rayOrigin, 8.0f, MakeColor( b3_colorGreen ) ); + DrawPoint( rayOrigin + rayTranslation, 8.0f, MakeColor( b3_colorRed ) ); + DrawLine( rayOrigin, rayOrigin + rayTranslation, MakeColor( b3_colorWhite ) ); if ( m_sphereCast ) { @@ -860,16 +860,16 @@ public: if ( context.count > 0 ) { b3Transform transform = { context.fractions[0] * rayTranslation, b3Quat_identity }; - DrawSphere( m_scene, transform, sphere, b3_colorYellow ); + DrawSolidSphere( transform, sphere, MakeColor( b3_colorYellow ) ); b3Vec3 point = context.points[0]; - DrawLine( m_scene, point, point + 0.5f * context.normals[0], b3_colorGreen ); - DrawPoint( m_scene, point, 5.0f, b3_colorYellow ); + DrawLine( point, point + 0.5f * context.normals[0], MakeColor( b3_colorGreen ) ); + DrawPoint( point, 5.0f, MakeColor( b3_colorYellow ) ); } else { b3Transform transform = { rayTranslation, b3Quat_identity }; - DrawSphere( m_scene, transform, sphere, b3_colorGray ); + DrawSolidSphere( transform, sphere, MakeColor( b3_colorGray ) ); } } else @@ -878,8 +878,8 @@ public: if ( result.hit ) { b3Vec3 point = result.point; - DrawLine( m_scene, point, point + 0.5f * result.normal, b3_colorGreen ); - DrawPoint( m_scene, point, 5.0f, b3_colorYellow ); + DrawLine( point, point + 0.5f * result.normal, MakeColor( b3_colorGreen ) ); + DrawPoint( point, 5.0f, MakeColor( b3_colorYellow ) ); } } } @@ -892,7 +892,7 @@ public: bool m_sphereCast; }; -static int sampleMeshScale = SampleManager::Register( "Collision", "Mesh Scale", MeshScale::Create ); +static int sampleMeshScale = RegisterSample( "Collision", "Mesh Scale", MeshScale::Create ); class ShapeCast : public Sample { @@ -964,7 +964,7 @@ public: b3World_CastShape( m_worldId, &proxy, translation, b3DefaultQueryFilter(), RayCastClosestCallback, &context ); - DrawSphere( m_scene, b3Transform_identity, sphere, b3_colorGreen ); + DrawSolidSphere( b3Transform_identity, sphere, MakeColor( b3_colorGreen ) ); if ( context.count > 0 ) { @@ -973,14 +973,14 @@ public: float fraction = context.fractions[0]; // final position with overlap resolution - DrawSphere( m_scene, { fraction * translation, b3Quat_identity }, sphere, b3_colorRed ); + DrawSolidSphere( { fraction * translation, b3Quat_identity }, sphere, MakeColor( b3_colorRed ) ); - DrawPoint( m_scene, point, 2.0f, b3_colorRed ); - DrawLine( m_scene, point, point + 0.2f * normal, b3_colorYellow ); + DrawPoint( point, 2.0f, MakeColor( b3_colorRed ) ); + DrawLine( point, point + 0.2f * normal, MakeColor( b3_colorYellow ) ); } else { - DrawSphere( m_scene, { translation, b3Quat_identity }, sphere, b3_colorGray ); + DrawSolidSphere( { translation, b3Quat_identity }, sphere, MakeColor( b3_colorGray ) ); } } } @@ -1001,7 +1001,7 @@ public: b3World_CastShape( m_worldId, &proxy, translation, b3DefaultQueryFilter(), RayCastClosestCallback, &context ); - DrawCapsule( m_scene, b3Transform_identity, capsule, b3_colorGreen ); + DrawSolidCapsule( b3Transform_identity, capsule, MakeColor( b3_colorGreen ) ); if ( context.count > 0 ) { @@ -1009,14 +1009,14 @@ public: b3Vec3 normal = context.normals[0]; float fraction = context.fractions[0]; - DrawCapsule( m_scene, { fraction * translation, b3Quat_identity }, capsule, b3_colorRed ); + DrawSolidCapsule( { fraction * translation, b3Quat_identity }, capsule, MakeColor( b3_colorRed ) ); - DrawPoint( m_scene, point, 2.0f, b3_colorRed ); - DrawLine( m_scene, point, point + 0.2f * normal, b3_colorYellow ); + DrawPoint( point, 2.0f, MakeColor( b3_colorRed ) ); + DrawLine( point, point + 0.2f * normal, MakeColor( b3_colorYellow ) ); } else { - DrawCapsule( m_scene, { translation, b3Quat_identity }, capsule, b3_colorGray ); + DrawSolidCapsule( { translation, b3Quat_identity }, capsule, MakeColor( b3_colorGray ) ); } } } @@ -1044,7 +1044,7 @@ public: b3World_CastShape( m_worldId, &proxy, translation, b3DefaultQueryFilter(), RayCastClosestCallback, &context ); - DrawHull( m_scene, b3Transform_identity, &box.base, b3_colorGreen, false ); + DrawHull( b3Transform_identity, &box.base, MakeColor( b3_colorGreen ) ); if ( context.count > 0 ) { @@ -1053,26 +1053,27 @@ public: float fraction = context.fractions[0]; // final position with overlap resolution - DrawHull( m_scene, { fraction * translation, b3Quat_identity }, &box.base, b3_colorRed, false ); + DrawHull( { fraction * translation, b3Quat_identity }, &box.base, MakeColor( b3_colorRed ) ); - DrawPoint( m_scene, point, 2.0f, b3_colorRed ); - DrawLine( m_scene, point, point + 0.2f * normal, b3_colorYellow ); + DrawPoint( point, 2.0f, MakeColor( b3_colorRed ) ); + DrawLine( point, point + 0.2f * normal, MakeColor( b3_colorYellow ) ); } else { - DrawHull( m_scene, { translation, b3Quat_identity }, &box.base, b3_colorGray, false ); + DrawHull( { translation, b3Quat_identity }, &box.base, MakeColor( b3_colorGray ) ); } } } - void UpdateUI() override + bool HasSolverControls() const override + { + return false; + } + + bool DrawControls() override { - float height = 80.0f; - ImGui::SetNextWindowPos( ImVec2( 10.0f, m_camera->m_height - height - 50.0f ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 210.0f, height ) ); - ImGui::Begin( "Shape Cast", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize ); ImGui::Checkbox( "Initial Overlap", &m_initialOverlap ); - ImGui::End(); + return true; } void Render() override @@ -1081,20 +1082,20 @@ public: DrawTextLine( "Shift + LMB and drag to shift start position" ); - DrawGrid( m_scene, 10 ); - DrawTransform( m_scene, b3Transform_identity, 1.0f ); + DrawGroundGrid( 10 ); + DrawAxes( b3Transform_identity, 1.0f ); } void MouseDown( b3Vec2 p, int button, int modifiers ) override { if ( button == 0 ) { - if ( modifiers == GLFW_MOD_SHIFT ) + if ( modifiers == MOD_SHIFT ) { m_trackingX = true; m_baseX = p.x; } - else if ( modifiers == GLFW_MOD_CONTROL ) + else if ( modifiers == MOD_CTRL ) { m_trackingY = true; m_baseY = p.y; @@ -1145,7 +1146,7 @@ public: bool m_initialOverlap; }; -static int sampleShapeCast = SampleManager::Register( "Collision", "Shape Cast", ShapeCast::Create ); +static int sampleShapeCast = RegisterSample( "Collision", "Shape Cast", ShapeCast::Create ); // Tests shape overlap versus world class OverlapWorld : public Sample @@ -1246,7 +1247,7 @@ public: b3ShapeProxy proxy = { &sphere.center, 1, sphere.radius }; b3HexColor color = b3_colorGreen; b3World_OverlapShape( m_worldId, &proxy, b3DefaultQueryFilter(), OverlapResultFcn, &color ); - DrawSphere( m_scene, b3Transform_identity, sphere, color ); + DrawSolidSphere( b3Transform_identity, sphere, MakeColor( color ) ); } } @@ -1262,7 +1263,7 @@ public: b3ShapeProxy proxy = { &capsule.center1, 2, capsule.radius }; b3HexColor color = b3_colorGreen; b3World_OverlapShape( m_worldId, &proxy, b3DefaultQueryFilter(), OverlapResultFcn, &color ); - DrawCapsule( m_scene, b3Transform_identity, capsule, color ); + DrawSolidCapsule( b3Transform_identity, capsule, MakeColor( color ) ); } } @@ -1275,7 +1276,7 @@ public: b3ShapeProxy proxy = { box.boxPoints, box.base.vertexCount, 0.0f }; b3HexColor color = b3_colorGreen; b3World_OverlapShape( m_worldId, &proxy, b3DefaultQueryFilter(), OverlapResultFcn, &color ); - DrawHull( m_scene, b3Transform_identity, &box.base, color, false ); + DrawHull( b3Transform_identity, &box.base, MakeColor( color ) ); } } @@ -1285,17 +1286,17 @@ public: DrawTextLine( "Shift + LMB and drag to move shapes" ); - DrawGrid( m_scene, 10 ); - DrawLine( m_scene, b3Vec3_zero, 0.4f * b3Vec3_axisX, b3_colorRed ); - DrawLine( m_scene, b3Vec3_zero, 0.4f * b3Vec3_axisY, b3_colorGreen ); - DrawLine( m_scene, b3Vec3_zero, 0.4f * b3Vec3_axisZ, b3_colorBlue ); + DrawGroundGrid( 10 ); + DrawLine( b3Vec3_zero, 0.4f * b3Vec3_axisX, MakeColor( b3_colorRed ) ); + DrawLine( b3Vec3_zero, 0.4f * b3Vec3_axisY, MakeColor( b3_colorGreen ) ); + DrawLine( b3Vec3_zero, 0.4f * b3Vec3_axisZ, MakeColor( b3_colorBlue ) ); } void MouseDown( b3Vec2 p, int button, int modifiers ) override { if ( button == 0 ) { - if ( modifiers == GLFW_MOD_SHIFT ) + if ( modifiers == MOD_SHIFT ) { m_tracking = true; m_baseX = p.x; @@ -1334,7 +1335,7 @@ public: bool m_tracking; }; -static int sampleOverlapWorld = SampleManager::Register( "Collision", "Overlap World", OverlapWorld::Create ); +static int sampleOverlapWorld = RegisterSample( "Collision", "Overlap World", OverlapWorld::Create ); class InitialOverlap : public Sample { @@ -1381,17 +1382,18 @@ public: { Sample::Render(); - DrawTransform( m_scene, b3Transform_identity, 1.0f ); + DrawAxes( b3Transform_identity, 1.0f ); } - void UpdateUI() override + bool HasSolverControls() const override + { + return false; + } + + bool DrawControls() override { - float height = 80.0f; - ImGui::SetNextWindowPos( ImVec2( 10.0f, m_camera->m_height - height - 50.0f ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 200.0f, height ) ); - ImGui::Begin( "Initial Overlap", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize ); ImGui::Checkbox( "initial overlap", &m_initialOverlap ); - ImGui::End(); + return true; } void Step() override @@ -1414,20 +1416,20 @@ public: b3ShapeProxy proxy = { &capsule.center1, 2, capsule.radius }; - DrawCapsule( m_scene, b3Transform_identity, capsule, b3_colorGreen ); + DrawSolidCapsule( b3Transform_identity, capsule, MakeColor( b3_colorGreen ) ); b3World_CastShape( m_worldId, &proxy, translation, b3DefaultQueryFilter(), RayCastClosestCallback, &context ); float fraction = context.count > 0 ? context.fractions[0] : 1.0f; b3Transform shapeEnd = { fraction * translation, b3Quat_identity }; - DrawCapsule( m_scene, shapeEnd, capsule, context.count > 0 ? b3_colorRed : b3_colorGreen ); + DrawSolidCapsule( shapeEnd, capsule, MakeColor( context.count > 0 ? b3_colorRed : b3_colorGreen ) ); if ( context.count > 0 ) { b3Vec3 p = context.points[0]; b3Vec3 n = context.normals[0]; - DrawLine( m_scene, p, p + 0.5f * n, b3_colorAliceBlue ); - DrawPoint( m_scene, p, 8.0f, b3_colorAliceBlue ); + DrawLine( p, p + 0.5f * n, MakeColor( b3_colorAliceBlue ) ); + DrawPoint( p, 8.0f, MakeColor( b3_colorAliceBlue ) ); } } @@ -1440,7 +1442,7 @@ public: bool m_initialOverlap; }; -static int sampleInitialOverlap = SampleManager::Register( "Collision", "Initial Overlap", InitialOverlap::Create ); +static int sampleInitialOverlap = RegisterSample( "Collision", "Initial Overlap", InitialOverlap::Create ); // pointA[0] = {0.000000000, 0.000000000, 0.000000000} // pointA[1] = {0.000000000, -6400.000000000, 0.000000000} @@ -1507,8 +1509,8 @@ public: { Sample::Render(); - DrawGrid( m_scene, 10 ); - DrawTransform( m_scene, b3Transform_identity, 1.0f ); + DrawGroundGrid( 10 ); + DrawAxes( b3Transform_identity, 1.0f ); b3ShapeCastPairInput input; input.proxyA = { m_triangle, 3, 0.0f }; @@ -1522,21 +1524,21 @@ public: b3CastOutput output = b3ShapeCast( &input ); - DrawFace( m_scene, m_triangle[0], m_triangle[1], m_triangle[2], b3_colorCyan ); + DrawTriangle( m_triangle[0], m_triangle[1], m_triangle[2], MakeColor( b3_colorCyan ) ); // DrawHull( m_scene, m_transform, m_box, b3_colorGreen, false ); - DrawCapsule( m_scene, m_transform, m_capsule, b3_colorGreen ); + DrawSolidCapsule( m_transform, m_capsule, MakeColor( b3_colorGreen ) ); if ( output.hit ) { // final position with overlap resolution b3Vec3 shapeEnd = m_transform.p + output.fraction * m_translation; // DrawHull( m_scene, { shapeEnd, m_transform.q }, m_box, b3_colorRed, false ); - DrawCapsule( m_scene, { shapeEnd, m_transform.q }, m_capsule, b3_colorRed ); + DrawSolidCapsule( { shapeEnd, m_transform.q }, m_capsule, MakeColor( b3_colorRed ) ); } b3Vec3 shapeEnd = m_transform.p + m_translation; // DrawHull( m_scene, { shapeEnd, m_transform.q }, m_box, b3_colorGray, false ); - DrawCapsule( m_scene, { shapeEnd, m_transform.q }, m_capsule, b3_colorGray ); + DrawSolidCapsule( { shapeEnd, m_transform.q }, m_capsule, MakeColor( b3_colorGray ) ); } static Sample* Create( SampleContext* context ) @@ -1552,7 +1554,7 @@ public: b3Vec3 m_triangle[3]; }; -static int sampleShapeCastDebug = SampleManager::Register( "Collision", "Shape Cast Debug", ShapeCastDebug::Create ); +static int sampleShapeCastDebug = RegisterSample( "Collision", "Shape Cast Debug", ShapeCastDebug::Create ); class DistanceDebug : public Sample { @@ -1616,21 +1618,20 @@ public: { Sample::Render(); - DrawGrid( m_scene, 10 ); - DrawTransform( m_scene, b3Transform_identity, 1.0f ); + DrawGroundGrid( 10 ); + DrawAxes( b3Transform_identity, 1.0f ); } - void UpdateUI() override + bool HasSolverControls() const override { - float height = 80.0f; - ImGui::SetNextWindowPos( ImVec2( 10.0f, m_camera->m_height - height - 50.0f ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 240.0f, height ) ); - - ImGui::Begin( "Distance Debug", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize ); + return false; + } + bool DrawControls() override + { ImGui::SliderInt( "simplex index", &m_simplexIndex, 0, m_simplexCount - 1 ); - ImGui::End(); + return true; } static void BuildWitnessPoints( const b3Simplex* simplex, b3Vec3& vertexA, b3Vec3& vertexB ) @@ -1712,18 +1713,18 @@ public: // DrawFace( m_scene, m_triangle[0], m_triangle[1], m_triangle[2], b3_colorCyan ); // DrawHull( m_scene, m_transformB, m_box, b3_colorGreen, false ); - DrawHull( m_scene, b3Transform_identity, &m_boxA.base, b3_colorGreen, false ); - DrawHull( m_scene, m_transformB, &m_boxB.base, b3_colorCyan, false ); + DrawHull( b3Transform_identity, &m_boxA.base, MakeColor( b3_colorGreen ) ); + DrawHull( m_transformB, &m_boxB.base, MakeColor( b3_colorCyan ) ); for ( int i = 0; i < m_boxB.base.vertexCount; ++i ) { b3Vec3 p = b3TransformPoint( m_transformB, m_boxB.boxPoints[i] ); - DrawWorldString( m_camera, p, b3_colorAliceBlue, " %d", i ); + DrawWorldString( p, MakeColor( b3_colorAliceBlue ), " %d", i ); } - DrawPoint( m_scene, output.pointA, 5.0f, b3_colorWhite ); - DrawPoint( m_scene, output.pointB, 5.0f, b3_colorWhite ); - DrawLine( m_scene, output.pointA, output.pointA + 1.0f * output.normal, b3_colorWhite ); + DrawPoint( output.pointA, 5.0f, MakeColor( b3_colorWhite ) ); + DrawPoint( output.pointB, 5.0f, MakeColor( b3_colorWhite ) ); + DrawLine( output.pointA, output.pointA + 1.0f * output.normal, MakeColor( b3_colorWhite ) ); b3Vec3 n = output.normal; DrawTextLine( "distance = %g, normal = %g, %g, %g", output.distance, n.x, n.y, n.z ); @@ -1737,15 +1738,15 @@ public: b3Vec3 v1, v2; BuildWitnessPoints( simplex, v1, v2 ); - DrawPoint( m_scene, v1, 10.0f, b3_colorGreen ); - DrawPoint( m_scene, v2, 10.0f, b3_colorGreen ); + DrawPoint( v1, 10.0f, MakeColor( b3_colorGreen ) ); + DrawPoint( v2, 10.0f, MakeColor( b3_colorGreen ) ); for ( int i = 0; i < simplex->count; ++i ) { v1 = simplex->vertices[i].wA; v2 = simplex->vertices[i].wB; - DrawPoint( m_scene, v1, 5.0f, b3_colorRed ); - DrawPoint( m_scene, v2, 5.0f, b3_colorRed ); + DrawPoint( v1, 5.0f, MakeColor( b3_colorRed ) ); + DrawPoint( v2, 5.0f, MakeColor( b3_colorRed ) ); } b3Vec3 p = GetClosestPoint( simplex ); @@ -1805,7 +1806,7 @@ public: int m_simplexCount; }; -static int sampleDistanceDebug = SampleManager::Register( "Collision", "Distance Debug", DistanceDebug::Create ); +static int sampleDistanceDebug = RegisterSample( "Collision", "Distance Debug", DistanceDebug::Create ); class ShapeDistance : public Sample { @@ -1914,12 +1915,12 @@ public: .center = m_point, .radius = radius, }; - DrawSphere( m_scene, transform, sphere, color ); + DrawSolidSphere( transform, sphere, MakeColor( color ) ); } else { b3Vec3 p = b3TransformPoint( transform, m_point ); - DrawPoint( m_scene, p, 5.0f, color ); + DrawPoint( p, 5.0f, MakeColor( color ) ); } } break; @@ -1934,13 +1935,13 @@ public: .radius = radius, }; - DrawCapsule( m_scene, transform, capsule, color ); + DrawSolidCapsule( transform, capsule, MakeColor( color ) ); } else { b3Vec3 p1 = b3TransformPoint( transform, m_segment[0] ); b3Vec3 p2 = b3TransformPoint( transform, m_segment[1] ); - DrawLine( m_scene, p1, p2, color ); + DrawLine( p1, p2, MakeColor( color ) ); } } break; @@ -1950,14 +1951,14 @@ public: b3Vec3 p1 = b3TransformPoint( transform, m_triangle[0] ); b3Vec3 p2 = b3TransformPoint( transform, m_triangle[1] ); b3Vec3 p3 = b3TransformPoint( transform, m_triangle[2] ); - DrawLine( m_scene, p1, p2, color ); - DrawLine( m_scene, p2, p3, color ); - DrawLine( m_scene, p3, p1, color ); + DrawLine( p1, p2, MakeColor( color ) ); + DrawLine( p2, p3, MakeColor( color ) ); + DrawLine( p3, p1, MakeColor( color ) ); } break; case e_box: - DrawHull( m_scene, transform, &m_box.base, color, false ); + DrawHull( transform, &m_box.base, MakeColor( color ) ); break; default: @@ -1965,15 +1966,13 @@ public: } } - void UpdateUI() override + bool HasSolverControls() const override { - float fontSize = ImGui::GetFontSize(); - float height = 16.0f * fontSize; - ImGui::SetNextWindowPos( ImVec2( 0.5f * fontSize, m_camera->m_height - height - 2.0f * fontSize ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 19.0f * fontSize, height ) ); - - ImGui::Begin( "Shape Distance", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize ); + return false; + } + bool DrawControls() override + { const char* shapeTypes[] = { "point", "segment", "triangle", "box" }; int shapeType = int( m_typeA ); if ( ImGui::Combo( "shape A", &shapeType, shapeTypes, IM_ARRAYSIZE( shapeTypes ) ) ) @@ -2017,12 +2016,12 @@ public: m_simplexIndex = b3ClampInt( m_simplexIndex, 0, m_simplexCount - 1 ); } - ImGui::End(); + return true; } void MouseDown( b3Vec2 ps, int button, int mods ) override { - if ( button == GLFW_MOUSE_BUTTON_1 ) + if ( button == MOUSE_LEFT ) { if ( mods == 0 && m_rotating == false ) { @@ -2038,7 +2037,7 @@ public: m_dragStart = b3MulSub( ray.origin, b3Dot( ray.origin, d ), d ); m_basePosition = m_transform.p; } - else if ( mods == GLFW_MOD_SHIFT && m_dragging == false ) + else if ( mods == MOD_SHIFT && m_dragging == false ) { m_rotating = true; m_rotateStart = ps.x; @@ -2049,7 +2048,7 @@ public: void MouseUp( b3Vec2, int button ) override { - if ( button == GLFW_MOUSE_BUTTON_1 ) + if ( button == MOUSE_LEFT ) { m_dragging = false; m_rotating = false; @@ -2121,7 +2120,7 @@ public: void Render() override { - DrawTransform( m_scene, b3Transform_identity, 0.5f ); + DrawAxes( b3Transform_identity, 0.5f ); Sample::Render(); } @@ -2169,9 +2168,9 @@ public: b3Vec3 pointA, pointB; ComputeWitnessPoints( &pointA, &pointB, simplex ); - DrawLine( m_scene, pointA, pointB, b3_colorWhite ); - DrawPoint( m_scene, pointA, 10.0f, b3_colorLightGreen ); - DrawPoint( m_scene, pointB, 10.0f, b3_colorLightBlue ); + DrawLine( pointA, pointB, MakeColor( b3_colorWhite ) ); + DrawPoint( pointA, 10.0f, MakeColor( b3_colorLightGreen ) ); + DrawPoint( pointB, 10.0f, MakeColor( b3_colorLightBlue ) ); } b3HexColor colors[3] = { b3_colorRed, b3_colorGreen, b3_colorBlue }; @@ -2179,16 +2178,16 @@ public: for ( int i = 0; i < simplex->count; ++i ) { b3SimplexVertex* vertex = vertices + i; - DrawPoint( m_scene, vertex->wA, 10.0f, colors[i] ); - DrawPoint( m_scene, vertex->wB, 10.0f, colors[i] ); + DrawPoint( vertex->wA, 10.0f, MakeColor( colors[i] ) ); + DrawPoint( vertex->wB, 10.0f, MakeColor( colors[i] ) ); } } else { - DrawLine( m_scene, output.pointA, output.pointB, b3_colorDimGray ); - DrawPoint( m_scene, output.pointA, 10.0f, b3_colorLightGreen ); - DrawPoint( m_scene, output.pointB, 10.0f, b3_colorLightBlue ); - DrawLine( m_scene, output.pointA, output.pointA + 0.5f * output.normal, b3_colorYellow ); + DrawLine( output.pointA, output.pointB, MakeColor( b3_colorDimGray ) ); + DrawPoint( output.pointA, 10.0f, MakeColor( b3_colorLightGreen ) ); + DrawPoint( output.pointB, 10.0f, MakeColor( b3_colorLightBlue ) ); + DrawLine( output.pointA, output.pointA + 0.5f * output.normal, MakeColor( b3_colorYellow ) ); } if ( m_showIndices ) @@ -2196,13 +2195,13 @@ public: for ( int i = 0; i < m_proxyA.count; ++i ) { b3Vec3 p = m_proxyA.points[i]; - DrawWorldString( m_camera, p, b3_colorWhite, " %d", i ); + DrawWorldString( p, MakeColor( b3_colorWhite ), " %d", i ); } for ( int i = 0; i < m_proxyB.count; ++i ) { b3Vec3 p = b3TransformPoint( m_transform, m_proxyB.points[i] ); - DrawWorldString( m_camera, p, b3_colorWhite, " %d", i ); + DrawWorldString( p, MakeColor( b3_colorWhite ), " %d", i ); } } @@ -2265,7 +2264,7 @@ public: bool m_drawSimplex; }; -static int sampleShapeDistance = SampleManager::Register( "Collision", "Shape Distance", ShapeDistance::Create ); +static int sampleShapeDistance = RegisterSample( "Collision", "Shape Distance", ShapeDistance::Create ); class TimeOfImpact : public Sample { @@ -2343,14 +2342,14 @@ public: { case e_capsule: { - DrawCapsule( m_scene, transform, m_capsule, color ); + DrawSolidCapsule( transform, m_capsule, MakeColor( color ) ); b3Vec3 center = b3Lerp( m_capsule.center1, m_capsule.center2, 0.5f ); center = b3TransformPoint( transform, center ); b3Transform xf = { .p = center, .q = transform.q, }; - DrawTransform( m_scene, xf, 0.025f ); + DrawAxes( xf, 0.025f ); } break; @@ -2359,17 +2358,17 @@ public: b3Vec3 p1 = b3TransformPoint( transform, m_triangle[0] ); b3Vec3 p2 = b3TransformPoint( transform, m_triangle[1] ); b3Vec3 p3 = b3TransformPoint( transform, m_triangle[2] ); - DrawLine( m_scene, p1, p2, color ); - DrawLine( m_scene, p2, p3, color ); - DrawLine( m_scene, p3, p1, color ); - DrawWorldString( m_camera, p1, b3_colorWhite, "0" ); - DrawWorldString( m_camera, p2, b3_colorWhite, "1" ); - DrawWorldString( m_camera, p3, b3_colorWhite, "2" ); + DrawLine( p1, p2, MakeColor( color ) ); + DrawLine( p2, p3, MakeColor( color ) ); + DrawLine( p3, p1, MakeColor( color ) ); + DrawWorldString( p1, MakeColor( b3_colorWhite ), "0" ); + DrawWorldString( p2, MakeColor( b3_colorWhite ), "1" ); + DrawWorldString( p3, MakeColor( b3_colorWhite ), "2" ); } break; case e_box: - DrawHull( m_scene, transform, &m_box.base, color, false ); + DrawHull( transform, &m_box.base, MakeColor( color ) ); break; default: @@ -2377,15 +2376,13 @@ public: } } - void UpdateUI() override + bool HasSolverControls() const override { - float fontSize = ImGui::GetFontSize(); - float height = 16.0f * fontSize; - ImGui::SetNextWindowPos( ImVec2( 0.5f * fontSize, m_camera->m_height - height - 2.0f * fontSize ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 19.0f * fontSize, height ) ); - - ImGui::Begin( "Time of Impact", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize ); + return false; + } + bool DrawControls() override + { const char* shapeTypes[] = { "point", "segment", "triangle", "box" }; int shapeType = int( m_typeA ); if ( ImGui::Combo( "shape A", &shapeType, shapeTypes, IM_ARRAYSIZE( shapeTypes ) ) ) @@ -2401,14 +2398,12 @@ public: m_proxyB = MakeProxy( m_typeB ); } - ImGui::Separator(); - - ImGui::End(); + return true; } void Render() override { - DrawTransform( m_scene, b3Transform_identity, 0.5f ); + DrawAxes( b3Transform_identity, 0.5f ); Sample::Render(); } @@ -2445,8 +2440,8 @@ public: if ( output.state == b3_toiStateHit || output.state == b3_toiStateFailed ) { - DrawLine( m_scene, output.point, output.point + 0.5f * output.normal, b3_colorDimGray ); - DrawPoint( m_scene, output.point, 10.0f, b3_colorLightGreen ); + DrawLine( output.point, output.point + 0.5f * output.normal, MakeColor( b3_colorDimGray ) ); + DrawPoint( output.point, 10.0f, MakeColor( b3_colorLightGreen ) ); } switch ( output.state ) @@ -2497,7 +2492,7 @@ public: b3Sweep m_sweepB; }; -static int sampleTimeOfImpact = SampleManager::Register( "Collision", "Time of Impact", TimeOfImpact::Create ); +static int sampleTimeOfImpact = RegisterSample( "Collision", "Time of Impact", TimeOfImpact::Create ); class CapsuleCastRay : public Sample { @@ -2542,10 +2537,10 @@ public: { Sample::Render(); - DrawGrid( m_scene, 10 ); - DrawLine( m_scene, b3Vec3_zero, 0.4f * b3Vec3_axisX, b3_colorRed ); - DrawLine( m_scene, b3Vec3_zero, 0.4f * b3Vec3_axisY, b3_colorGreen ); - DrawLine( m_scene, b3Vec3_zero, 0.4f * b3Vec3_axisZ, b3_colorBlue ); + DrawGroundGrid( 10 ); + DrawLine( b3Vec3_zero, 0.4f * b3Vec3_axisX, MakeColor( b3_colorRed ) ); + DrawLine( b3Vec3_zero, 0.4f * b3Vec3_axisY, MakeColor( b3_colorGreen ) ); + DrawLine( b3Vec3_zero, 0.4f * b3Vec3_axisZ, MakeColor( b3_colorBlue ) ); b3BodyRayCastInput input; input.origin = { -1.0f, 0.5f, 0.0f }; @@ -2555,13 +2550,13 @@ public: b3BodyCastResult result = b3Body_CastRay( m_bodyId, &input, b3Transform_identity ); - DrawLine( m_scene, input.origin, input.origin + input.translation, b3_colorGray ); - DrawPoint( m_scene, input.origin, 4.0f, b3_colorGreen ); - DrawPoint( m_scene, input.origin + input.translation, 4.0f, b3_colorRed ); + DrawLine( input.origin, input.origin + input.translation, MakeColor( b3_colorGray ) ); + DrawPoint( input.origin, 4.0f, MakeColor( b3_colorGreen ) ); + DrawPoint( input.origin + input.translation, 4.0f, MakeColor( b3_colorRed ) ); if ( result.hit ) { - DrawPoint( m_scene, result.point, 4.0f, b3_colorOrange ); + DrawPoint( result.point, 4.0f, MakeColor( b3_colorOrange ) ); } } @@ -2570,4 +2565,4 @@ public: float m_scale; }; -static int sampleCapsuleCastRay = SampleManager::Register( "Collision", "Capsule Cast Ray", CapsuleCastRay::Create ); +static int sampleCapsuleCastRay = RegisterSample( "Collision", "Capsule Cast Ray", CapsuleCastRay::Create ); diff --git a/samples/sample_compound.cpp b/samples/sample_compound.cpp index 67a263c..2b8ace1 100644 --- a/samples/sample_compound.cpp +++ b/samples/sample_compound.cpp @@ -1,12 +1,10 @@ // SPDX-FileCopyrightText: 2025 Erin Catto // SPDX-License-Identifier: MIT -#include "camera.h" #include "human.h" #include "mesh_loader.h" -#include "renderer.h" #include "sample.h" -#include "scene.h" +#include "gfx/draw.h" #include "utils.h" #include "box3d/box3d.h" @@ -91,7 +89,7 @@ public: { Sample::Render(); b3Transform transform = { { 0.0f, 0.01f, 0.0f }, b3Quat_identity }; - DrawTransform( m_scene, transform, 1.0f ); + DrawAxes( transform, 1.0f ); int height = b3DynamicTree_GetHeight( &m_compound->tree ); DrawTextLine( "compound tree height = %d", height ); @@ -105,7 +103,7 @@ public: b3Compound* m_compound; }; -static int sampleSimple = SampleManager::Register( "Compound", "Simple", SimpleCompound::Create ); +static int sampleSimple = RegisterSample( "Compound", "Simple", SimpleCompound::Create ); class CompoundSpheres : public Sample { @@ -151,7 +149,7 @@ public: { Sample::Render(); b3Transform transform = { { 0.0f, 0.01f, 0.0f }, b3Quat_identity }; - DrawTransform( m_scene, transform, 1.0f ); + DrawAxes( transform, 1.0f ); int height = b3DynamicTree_GetHeight( &m_compound->tree ); DrawTextLine( "compound tree height = %d", height ); @@ -166,7 +164,7 @@ public: b3Compound* m_compound; }; -static int sampleCompoundSpheres = SampleManager::Register( "Compound", "Spheres", CompoundSpheres::Create ); +static int sampleCompoundSpheres = RegisterSample( "Compound", "Spheres", CompoundSpheres::Create ); class CompoundHulls : public Sample { @@ -225,7 +223,7 @@ public: { Sample::Render(); b3Transform transform = { { 0.0f, 0.01f, 0.0f }, b3Quat_identity }; - DrawTransform( m_scene, transform, 1.0f ); + DrawAxes( transform, 1.0f ); int height = b3DynamicTree_GetHeight( &m_compound->tree ); DrawTextLine( "compound tree height = %d", height ); @@ -240,7 +238,7 @@ public: b3Compound* m_compound; }; -static int sampleCompoundHulls = SampleManager::Register( "Compound", "Hulls", CompoundHulls::Create ); +static int sampleCompoundHulls = RegisterSample( "Compound", "Hulls", CompoundHulls::Create ); class TileFloor : public Sample { @@ -340,7 +338,7 @@ public: { Sample::Render(); b3Transform transform = { { 0.0f, 0.01f, 0.0f }, b3Quat_identity }; - DrawTransform( m_scene, transform, 1.0f ); + DrawAxes( transform, 1.0f ); DrawTextLine( "compound hull count = %d, mesh count = %d", m_compound->hullCount, m_compound->meshCount ); DrawTextLine( "compound byte count = %d", m_compound->byteCount ); @@ -358,7 +356,7 @@ public: b3Compound* m_compound; }; -static int sampleTileFloor = SampleManager::Register( "Compound", "Tile Floor", TileFloor::Create ); +static int sampleTileFloor = RegisterSample( "Compound", "Tile Floor", TileFloor::Create ); class MeshTile : public Sample { @@ -457,7 +455,7 @@ public: { Sample::Render(); b3Transform transform = { { 0.0f, 0.01f, 0.0f }, b3Quat_identity }; - DrawTransform( m_scene, transform, 1.0f ); + DrawAxes( transform, 1.0f ); DrawTextLine( "compound instance count = %d, byte count = %d", m_compound->meshCount, m_compound->byteCount ); @@ -474,7 +472,7 @@ public: b3Compound* m_compound; }; -static int sampleCompoundMesh = SampleManager::Register( "Compound", "Mesh Tile", MeshTile::Create ); +static int sampleCompoundMesh = RegisterSample( "Compound", "Mesh Tile", MeshTile::Create ); static bool OverlapResultFcn( b3ShapeId shapeId, void* context ) { @@ -688,7 +686,7 @@ public: { Sample::Render(); b3Transform transform = { { 0.0f, 0.01f, 0.0f }, b3Quat_identity }; - DrawTransform( m_scene, transform, 4.0f ); + DrawAxes( transform, 4.0f ); DrawTextLine( "surface type = %d", m_userMaterialId ); DrawTextLine( "compound capsules/hulls/meshes/sphere = %d / %d / %d / %d", m_compound->capsuleCount, @@ -712,13 +710,13 @@ public: CastClosestContext context = {}; (void)b3World_CastRay( m_worldId, m_rayOrigin, translation, filter, CastClosestCallback, &context ); - DrawLine( m_scene, m_rayOrigin, m_rayOrigin + translation, b3_colorAliceBlue ); + DrawLine( m_rayOrigin, m_rayOrigin + translation, MakeColor( b3_colorAliceBlue ) ); if ( context.hit ) { b3Vec3 p1 = context.point; b3Vec3 p2 = b3MulAdd( p1, 0.5f, context.normal ); - DrawLine( m_scene, p1, p2, b3_colorYellow ); - DrawPoint( m_scene, p1, 8.0f, b3_colorLightCoral ); + DrawLine( p1, p2, MakeColor( b3_colorYellow ) ); + DrawPoint( p1, 8.0f, MakeColor( b3_colorLightCoral ) ); DrawTextLine( "ray hit triangle/child/material = %d / %d / %d", context.triangleIndex, context.childIndex, context.materialId ); } @@ -734,16 +732,16 @@ public: b3ShapeProxy proxy = { &origin, 1, 0.25f }; b3World_CastShape( m_worldId, &proxy, translation, filter, CastClosestCallback, &context ); - DrawLine( m_scene, origin, origin + translation, b3_colorAliceBlue ); + DrawLine( origin, origin + translation, MakeColor( b3_colorAliceBlue ) ); if ( context.hit ) { b3Vec3 position = b3MulAdd( origin, context.fraction, translation ); b3Vec3 p1 = context.point; b3Vec3 p2 = b3MulAdd( p1, 0.5f, context.normal ); - DrawLine( m_scene, p1, p2, b3_colorYellow ); - DrawPoint( m_scene, p1, 8.0f, b3_colorLightCoral ); + DrawLine( p1, p2, MakeColor( b3_colorYellow ) ); + DrawPoint( p1, 8.0f, MakeColor( b3_colorLightCoral ) ); b3Sphere sphere = { position, 0.25f }; - DrawSphere( m_scene, b3Transform_identity, sphere, b3_colorOrchid ); + DrawSolidSphere( b3Transform_identity, sphere, MakeColor( b3_colorOrchid ) ); DrawTextLine( "shape hit triangle/child/material = %d / %d / %d", context.triangleIndex, context.childIndex, context.materialId ); } @@ -761,7 +759,7 @@ public: b3HexColor color = overlap ? b3_colorDarkMagenta : b3_colorDarkSeaGreen; b3Sphere sphere = { origin, 0.3f }; - DrawSphere( m_scene, b3Transform_identity, sphere, color ); + DrawSolidSphere( b3Transform_identity, sphere, MakeColor( color ) ); } if ( m_rayOrigin.x > 0.45f * m_worldWidth ) @@ -797,4 +795,4 @@ public: b3Vec3 m_rayOrigin; }; -static int sampleVillage = SampleManager::Register( "Compound", "Village", Village::Create ); +static int sampleVillage = RegisterSample( "Compound", "Village", Village::Create ); diff --git a/samples/sample_continuous.cpp b/samples/sample_continuous.cpp index c4c6e16..2062051 100644 --- a/samples/sample_continuous.cpp +++ b/samples/sample_continuous.cpp @@ -1,15 +1,14 @@ // SPDX-FileCopyrightText: 2025 Erin Catto // SPDX-License-Identifier: MIT -#include "GLFW/glfw3.h" -#include "camera.h" #include "imgui.h" -#include "renderer.h" #include "sample.h" -#include "scene.h" +#include "gfx/draw.h" #include "stability.h" #include "utils.h" +#include "gfx/debug_adapter.h" + #include "box3d/box3d.h" #include @@ -26,14 +25,11 @@ public: m_camera->SetView( 45.0f, 30.0f, 30.0f, b3Vec3_zero ); } + AddGroundBox( 40.0f ); + b3BodyDef bodyDef = b3DefaultBodyDef(); b3ShapeDef shapeDef = b3DefaultShapeDef(); - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - b3BoxHull groundBox = b3MakeBoxHull( 50.0f, 1.0f, 50.0f ); - b3CreateHullShape( groundId, &shapeDef, &groundBox.base ); - bodyDef.position = { 0.0f, 10.0f, 0.0f }; bodyDef.rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisX, 90.0f * B3_DEG_TO_RAD ); b3BodyId wallId = b3CreateBody( m_worldId, &bodyDef ); @@ -74,7 +70,7 @@ public: } }; -static int sampleThinWall = SampleManager::Register( "Continuous", "Thin Wall", ThinWall::Create ); +static int sampleThinWall = RegisterSample( "Continuous", "Thin Wall", ThinWall::Create ); class BounceHouse : public Sample { @@ -87,14 +83,14 @@ public: m_camera->SetView( 45.0f, 45.0f, 50.0f, b3Vec3_zero ); } + AddGroundBox( 10.0f ); + b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.position = { 0.0f, -1.0f, 0.0f }; b3BodyId groundBodyId = b3CreateBody( m_worldId, &bodyDef ); b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull groundBox = b3MakeBoxHull( 10.0f, 1.0f, 10.0f ); - b3CreateHullShape( groundBodyId, &shapeDef, &groundBox.base ); { b3Transform transform = { { 10.0f, 5.0f, 0.0f }, b3Quat_identity }; @@ -148,7 +144,7 @@ public: b3MeshData* m_dummyMesh; }; -static int sampleBounceHouse = SampleManager::Register( "Continuous", "Bounce House", BounceHouse::Create ); +static int sampleBounceHouse = RegisterSample( "Continuous", "Bounce House", BounceHouse::Create ); class SpinningStick : public Sample { @@ -158,20 +154,17 @@ public: { if ( context->restart == false ) { - m_camera->SetView( 45.0f, 25.0f, 50.0f, { 0.0f, 2.0f, 0.0f } ); + m_camera->SetView( 45.0f, 25.0f, 20.0f, { 0.0f, 2.0f, 0.0f } ); } + AddGroundBox( 10.0f ); + b3BodyDef bodyDef = b3DefaultBodyDef(); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - - bodyDef.position = { 0.0f, -0.1f, 0.0f }; - b3BodyId groundBodyId = b3CreateBody( m_worldId, &bodyDef ); - b3BoxHull groundBox = b3MakeBoxHull( 10.0f, 0.1f, 10.0f ); - b3CreateHullShape( groundBodyId, &shapeDef, &groundBox.base ); - bodyDef.position = { 0.0f, 0.5f, 0.0f }; b3BodyId wallBodyId = b3CreateBody( m_worldId, &bodyDef ); + b3BoxHull wallBox = b3MakeBoxHull( 0.125f, 0.5f, 10.0f ); + b3ShapeDef shapeDef = b3DefaultShapeDef(); b3CreateHullShape( wallBodyId, &shapeDef, &wallBox.base ); bodyDef.type = b3_dynamicBody; @@ -193,7 +186,7 @@ public: } }; -static int sampleSpinningStick = SampleManager::Register( "Continuous", "Spinning Stick", SpinningStick::Create ); +static int sampleSpinningStick = RegisterSample( "Continuous", "Spinning Stick", SpinningStick::Create ); // This tests bullets and chain reactions class BulletVersusStack : public Sample @@ -209,18 +202,17 @@ public: { if ( context->restart == false ) { - m_camera->SetView( -7.5f, 20.0f, 30.0f, { 0.0f, 2.0f, 0.0f } ); + m_camera->SetView( 15.0f, 20.0f, 30.0f, { 0.0f, 2.0f, 0.0f } ); } + AddGroundBox( 50.0f ); + { b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.position = { 0.0f, -1.0f, 0.0f }; b3BodyId groundBodyId = b3CreateBody( m_worldId, &bodyDef ); - b3BoxHull groundBox = b3MakeBoxHull( 50.0f, 1.0f, 50.0f ); b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHullShape( groundBodyId, &shapeDef, &groundBox.base ); - - b3Transform transform = { { 1.0f, 5.0f, 0.0f }, b3Quat_identity }; + b3Transform transform = { { -1.0f, 5.0f, 0.0f }, b3Quat_identity }; b3BoxHull wallBox = b3MakeTransformedBoxHull( 0.1f, 5.0f, 10.0f, transform ); b3CreateHullShape( groundBodyId, &shapeDef, &wallBox.base ); } @@ -239,12 +231,6 @@ public: m_bulletId = b3_nullBodyId; } - void Render() override - { - Sample::Render(); - DrawTransform( m_scene, { { 0.0f, 0.1f, 0.0f }, b3Quat_identity }, 1.0f ); - } - void Launch() { if ( B3_IS_NON_NULL( m_bulletId ) ) @@ -255,8 +241,8 @@ public: b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.type = b3_dynamicBody; bodyDef.isBullet = true; - bodyDef.position = { -20.5f, 5.5f, 0.0f }; - bodyDef.linearVelocity = { 500.0f, 0.0f, 0.0f }; + bodyDef.position = { 20.5f, 5.5f, 0.0f }; + bodyDef.linearVelocity = { -500.0f, 0.0f, 0.0f }; m_bulletId = b3CreateBody( m_worldId, &bodyDef ); b3ShapeDef shapeDef = b3DefaultShapeDef(); @@ -273,15 +259,9 @@ public: } } - void UpdateUI() override + bool DrawControls() override { - float height = 80.0f; - ImGui::SetNextWindowPos( ImVec2( 10.0f, m_camera->m_height - height - 50.0f ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 150.0f, height ) ); - - ImGui::Begin( "Bullet vs Stack", nullptr, ImGuiWindowFlags_NoResize ); - - ImGui::PushItemWidth( 200.0f ); + ImGui::PushItemWidth( 6.0f * ImGui::GetFontSize() ); if ( ImGui::Button( "Launch" ) ) { @@ -290,13 +270,13 @@ public: ImGui::PopItemWidth(); - ImGui::End(); + return true; } b3BodyId m_bulletId; }; -static int sampleContinuous6 = SampleManager::Register( "Continuous", "Bullet vs Stack", BulletVersusStack::Create ); +static int sampleContinuous6 = RegisterSample( "Continuous", "Bullet vs Stack", BulletVersusStack::Create ); class NeedleMesh : public Sample { @@ -343,7 +323,7 @@ public: void Render() override { - DrawGrid( m_scene, 10 ); + DrawGroundGrid( 10 ); Sample::Render(); } @@ -407,7 +387,7 @@ public: b3Hull* mConvex; }; -static int sampleNeedleMesh = SampleManager::Register( "Continuous", "Needle Mesh", NeedleMesh::Create ); +static int sampleNeedleMesh = RegisterSample( "Continuous", "Needle Mesh", NeedleMesh::Create ); struct IndexPair { @@ -447,7 +427,7 @@ public: if ( context->restart == false ) { m_camera->SetView( 0.0f, 30.0f, 20.0f, b3Vec3_zero ); - m_context->debugDraw.forceScale = 0.1f; + GetGuiDraw()->forceScale = 0.1f; } m_groundId = b3_nullBodyId; @@ -632,17 +612,8 @@ public: assert( bodyIndex == m_bodyCount ); } - void UpdateUI() override + bool DrawControls() override { - Sample::UpdateUI(); - - float fontSize = ImGui::GetFontSize(); - float height = 9.0f * fontSize; - ImGui::SetNextWindowPos( ImVec2( 0.5f * fontSize, m_camera->m_height - height - 2.0f * fontSize ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 19.0f * fontSize, height ) ); - - ImGui::Begin( "Mesh Drop", nullptr, ImGuiWindowFlags_NoResize ); - const char* shapeTypes[] = { "box", "capsule", "cylinder", "sphere" }; int shapeType = (int)m_shapeType; if ( ImGui::Combo( "Type", &shapeType, shapeTypes, IM_ARRAYSIZE( shapeTypes ) ) ) @@ -669,7 +640,7 @@ public: m_stepCount = 0; } - ImGui::End(); + return true; } void Step() override @@ -677,9 +648,7 @@ public: Sample::Step(); { - double screenX, screenY; - glfwGetCursorPos( m_window, &screenX, &screenY ); - PickRay pickRay = m_camera->BuildPickRay( (float)screenX, (float)screenY ); + PickRay pickRay = m_camera->BuildPickRay( m_context->mouseX, m_context->mouseY ); b3RayResult result = b3World_CastRayClosest( m_worldId, pickRay.origin, pickRay.translation, b3DefaultQueryFilter() ); @@ -773,7 +742,7 @@ public: bool m_autoGenerate; }; -static int sampleMeshDrop = SampleManager::Register( "Continuous", "Mesh Drop", MeshDrop::Create ); +static int sampleMeshDrop = RegisterSample( "Continuous", "Mesh Drop", MeshDrop::Create ); class MeshDropUnitTest : public Sample { @@ -784,7 +753,7 @@ public: if ( context->restart == false ) { m_camera->SetView( 0.0f, 30.0f, 20.0f, b3Vec3_zero ); - m_context->debugDraw.forceScale = 0.1f; + GetGuiDraw()->forceScale = 0.1f; } m_data = CreateMeshDrop( m_worldId ); @@ -827,7 +796,7 @@ public: bool m_failed; }; -static int sampleMeshDropUnitTest = SampleManager::Register( "Continuous", "Mesh Drop Unit Test", MeshDropUnitTest::Create ); +static int sampleMeshDropUnitTest = RegisterSample( "Continuous", "Mesh Drop Unit Test", MeshDropUnitTest::Create ); // This sample shows that clustering based on the manifold normal can lead to clipping and/or tunneling. class HumpMesh : public Sample @@ -838,9 +807,11 @@ public: { if ( context->restart == false ) { - m_camera->SetView( 45.0f, 25.0f, 4.0f, { 0.0f, 1.2f, 0.0f } ); + m_camera->SetView( 45.0f, 25.0f, 10.0f, { 0.0f, 1.2f, 0.0f } ); } + AddGroundBox( 20.0f ); + m_hump = CreateHump( 8.0f ); b3BodyDef bodyDef = b3DefaultBodyDef(); @@ -863,12 +834,6 @@ public: b3DestroyMesh( m_hump ); } - void Render() override - { - DrawGrid( m_scene, 10 ); - Sample::Render(); - } - b3MeshData* CreateHump( float cellWidth ) const { // Vertices @@ -944,7 +909,7 @@ public: b3MeshData* m_hump; }; -static int sampleHumpMesh = SampleManager::Register( "Continuous", "Hump Mesh", HumpMesh::Create ); +static int sampleHumpMesh = RegisterSample( "Continuous", "Hump Mesh", HumpMesh::Create ); class IsFast : public Sample { @@ -955,19 +920,10 @@ public: if ( context->restart == false ) { m_camera->SetView( 0.0f, 15.0f, 50.0f, { 0.0f, 15.0f, 0.0f } ); - EnableGrid( m_scene, true ); + } - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_staticBody; - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - b3BodyId groundBody = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull groundBox = b3MakeBoxHull( 40.0f, 1.0f, 40.0f ); - b3CreateHullShape( groundBody, &shapeDef, &groundBox.base ); - } + AddGroundBox( 40.0f ); b3BoxHull box = b3MakeBoxHull( 0.5f, 10.0f, 0.5f ); b3Capsule capsule = {{0.0f, -9.5f, 0.0f}, {0.0f, 9.5f, 0.0f}, 0.5f}; @@ -1038,4 +994,4 @@ public: } }; -static int sampleIsFast = SampleManager::Register( "Continuous", "Is Fast", IsFast::Create ); +static int sampleIsFast = RegisterSample( "Continuous", "Is Fast", IsFast::Create ); diff --git a/samples/sample_determinism.cpp b/samples/sample_determinism.cpp index 8e8a273..2421e7d 100644 --- a/samples/sample_determinism.cpp +++ b/samples/sample_determinism.cpp @@ -1,10 +1,10 @@ // SPDX-FileCopyrightText: 2025 Erin Catto // SPDX-License-Identifier: MIT -#include "camera.h" #include "determinism.h" #include "sample.h" -#include "scene.h" + +#include "box3d/box3d.h" #include @@ -56,4 +56,4 @@ public: bool m_done; }; -static int sampleFallingRagdolls = SampleManager::Register( "Determinism", "Falling Ragdolls", FallingRagdolls::Create ); +static int sampleFallingRagdolls = RegisterSample( "Determinism", "Falling Ragdolls", FallingRagdolls::Create ); diff --git a/samples/sample_events.cpp b/samples/sample_events.cpp index 2222a6e..86fb61a 100644 --- a/samples/sample_events.cpp +++ b/samples/sample_events.cpp @@ -1,14 +1,13 @@ // SPDX-FileCopyrightText: 2025 Erin Catto // SPDX-License-Identifier: MIT -#include "GLFW/glfw3.h" -#include "camera.h" #include "imgui.h" -#include "renderer.h" #include "sample.h" -#include "scene.h" +#include "gfx/draw.h" #include "utils.h" +#include "gfx/keycodes.h" + #include "box3d/box3d.h" #include @@ -54,7 +53,7 @@ public: void Render() override { - DrawGrid( m_scene, 10 ); + DrawGroundGrid( 10 ); Sample::Render(); } @@ -79,7 +78,7 @@ public: b3ShapeId m_sensorShapeId; }; -static int sampleSensorVisit = SampleManager::Register( "Events", "Sensor Visit", SensorVisit::Create ); +static int sampleSensorVisit = RegisterSample( "Events", "Sensor Visit", SensorVisit::Create ); class HitEvent : public Sample { @@ -207,7 +206,7 @@ public: { Sample::Render(); b3Transform transform = { { 0.0f, 0.1f, 0.0f }, b3Quat_identity }; - DrawTransform( m_scene, transform, 4.0f ); + DrawAxes( transform, 4.0f ); for ( int i = 0; i < m_eventCount; ++i ) { @@ -215,12 +214,12 @@ public: // void DrawPoint(Scene * Scene, b3Vector3 Point, b3Color Color, float Size); b3Vec3 p1 = m_events[i].point; - DrawPoint( m_scene, m_events[i].point, 10.0f, b3_colorYellow ); + DrawPoint( m_events[i].point, 10.0f, MakeColor( b3_colorYellow ) ); b3Vec3 p2 = p1 - m_events[i].approachSpeed * m_events[i].normal; - DrawLine( m_scene, p1, p2, b3_colorYellow ); + DrawLine( p1, p2, MakeColor( b3_colorYellow ) ); - DrawWorldString( m_camera, p1, b3_colorWhite, "%.1f, %d", m_events[i].approachSpeed, m_events[i].userMaterialIdA ); + DrawWorldString( p1, MakeColor( b3_colorWhite ), "%.1f, %d", m_events[i].approachSpeed, m_events[i].userMaterialIdA ); } DrawTextLine( "event count = %d", m_eventCount ); @@ -244,7 +243,7 @@ public: int m_eventCount; }; -static int sampleHitEvent = SampleManager::Register( "Events", "Hit", HitEvent::Create ); +static int sampleHitEvent = RegisterSample( "Events", "Hit", HitEvent::Create ); class MoveEvent : public Sample { @@ -255,19 +254,12 @@ public: if ( context->restart == false ) { m_camera->SetView( 0.0f, 30.0f, 40.0f, { 0.0f, 5.0f, 0.0f } ); - EnableGrid( m_scene, true ); + } + AddGroundBox( 40.0f ); + b3BodyDef bodyDef = b3DefaultBodyDef(); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - - bodyDef.type = b3_staticBody; - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - b3BodyId groundBody = b3CreateBody( m_worldId, &bodyDef ); - - b3BoxHull groundBox = b3MakeBoxHull( 40.0f, 1.0f, 40.0f ); - b3CreateHullShape( groundBody, &shapeDef, &groundBox.base ); - b3Vec3 pivot = { 0.0f, 1.0f, 0.0f }; bodyDef.type = b3_dynamicBody; bodyDef.position = pivot; @@ -276,6 +268,7 @@ public: m_localPivot = b3Body_GetLocalPoint( m_bodyId, pivot ); + b3ShapeDef shapeDef = b3DefaultShapeDef(); shapeDef.enableHitEvents = true; b3BoxHull dynamicBox = b3MakeTransformedBoxHull( 0.5f, 10.0f, 0.5f, { { 0.0f, 10.0f, 0.0f }, b3Quat_identity } ); b3CreateHullShape( m_bodyId, &shapeDef, &dynamicBox.base ); @@ -296,8 +289,6 @@ public: void Render() override { Sample::Render(); - b3Transform transform = { { 0.0f, 0.1f, 0.0f }, b3Quat_identity }; - DrawTransform( m_scene, transform, 4.0f ); b3Vec3 vp = b3Body_GetLocalPointVelocity( m_bodyId, m_localPivot ); b3Vec3 v = b3Body_GetLinearVelocity( m_bodyId ); @@ -335,7 +326,7 @@ public: b3Vec3 m_localPivot; }; -static int sampleMoveEvent = SampleManager::Register( "Events", "Move", MoveEvent::Create ); +static int sampleMoveEvent = RegisterSample( "Events", "Move", MoveEvent::Create ); // This sample shows how to break joints when the internal reaction force becomes large. Instead of polling, this uses events. class JointEvent : public Sample @@ -352,16 +343,15 @@ public: if ( m_context->restart == false ) { m_camera->SetView( 0.0f, 30.0f, 40.0f, { 0.0f, 5.0f, 0.0f } ); - EnableGrid( m_scene, true ); + } + AddGroundBox( 20.0f ); + b3BodyId groundId; { b3BodyDef bodyDef = b3DefaultBodyDef(); groundId = b3CreateBody( m_worldId, &bodyDef ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull box = b3MakeTransformedBoxHull( 20.0f, 1.0f, 20.0f, { { 0.0f, -1.0f, 0.0f }, b3Quat_identity } ); - b3CreateHullShape( groundId, &shapeDef, &box.base ); } for ( int i = 0; i < e_count; ++i ) @@ -579,7 +569,7 @@ public: b3JointId m_jointIds[e_count]; }; -static int sampleJointEvent = SampleManager::Register( "Events", "Joint", JointEvent::Create ); +static int sampleJointEvent = RegisterSample( "Events", "Joint", JointEvent::Create ); class PersistentContact : public Sample { @@ -657,9 +647,9 @@ public: const b3ManifoldPoint* manifoldPoint = manifold->points + i; b3Vec3 p1 = manifoldPoint->anchorA + centerOfMass; b3Vec3 p2 = p1 + manifoldPoint->totalNormalImpulse * normal; - DrawLine( m_scene, p1, p2, b3_colorCrimson ); - DrawPoint( m_scene, p1, 6.0f, b3_colorCrimson ); - DrawWorldString( m_camera, p1, b3_colorGray, "%.2f", manifoldPoint->totalNormalImpulse ); + DrawLine( p1, p2, MakeColor( b3_colorCrimson ) ); + DrawPoint( p1, 6.0f, MakeColor( b3_colorCrimson ) ); + DrawWorldString( p1, MakeColor( b3_colorGray ), "%.2f", manifoldPoint->totalNormalImpulse ); } } } @@ -678,7 +668,7 @@ public: b3MeshData* m_meshData; }; -static int samplePersistentContact = SampleManager::Register( "Events", "Persistent Contact", PersistentContact::Create ); +static int samplePersistentContact = RegisterSample( "Events", "Persistent Contact", PersistentContact::Create ); class SensorHits : public Sample { @@ -690,9 +680,11 @@ public: if ( m_context->restart == false ) { m_camera->SetView( 0.0f, 30.0f, 40.0f, { 0.0f, 5.0f, 0.0f } ); - EnableGrid( m_scene, true ); + } + AddGroundBox( 10.0f ); + b3BodyId groundId; { b3BodyDef bodyDef = b3DefaultBodyDef(); @@ -701,9 +693,6 @@ public: groundId = b3CreateBody( m_worldId, &bodyDef ); b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull groundBox = b3MakeOffsetBoxHull( 10.0f, 1.0f, 10.0f, {0.0f, -1.0f, 0.0f} ); - b3CreateHullShape( groundId, &shapeDef, &groundBox.base ); - b3BoxHull wallBox = b3MakeTransformedBoxHull( 0.1f, 5.0f, 5.0f, { { 10.0f, 5.0f, 0.0f }, b3Quat_identity } ); b3CreateHullShape( groundId, &shapeDef, &wallBox.base ); } @@ -812,22 +801,16 @@ public: m_shapeId = b3CreateSphereShape( m_bodyId, &shapeDef, &sphere ); } - void UpdateUI() override + bool DrawControls() override { - float height = 120.0f; - ImGui::SetNextWindowPos( ImVec2( 10.0f, m_context->camera.m_height - height - 50.0f ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 120.0f, height ) ); - - ImGui::Begin( "Sensor Hit", nullptr, ImGuiWindowFlags_NoResize ); - ImGui::Checkbox( "Bullet", &m_isBullet ); - if ( ImGui::Button( "Launch" ) || glfwGetKey( m_context->window, GLFW_KEY_B ) == GLFW_PRESS ) + if ( ImGui::Button( "Launch" ) || IsKeyDown( KEY_B ) ) { Launch(); } - ImGui::End(); + return true; } void CollectTransforms( b3ShapeId sensorShapeId ) @@ -871,7 +854,7 @@ public: for ( int i = 0; i < m_transformCount; ++i ) { - DrawTransform( m_scene, m_transforms[i], 0.1f ); + DrawAxes( m_transforms[i], 0.1f ); } b3SensorEvents sensorEvents = b3World_GetSensorEvents( m_worldId ); @@ -915,4 +898,4 @@ public: int m_endCount; }; -static int sampleSensorHits = SampleManager::Register( "Events", "Sensor Hits", SensorHits::Create ); +static int sampleSensorHits = RegisterSample( "Events", "Sensor Hits", SensorHits::Create ); diff --git a/samples/sample_geometry.cpp b/samples/sample_geometry.cpp index eda7496..15e17d7 100644 --- a/samples/sample_geometry.cpp +++ b/samples/sample_geometry.cpp @@ -1,12 +1,12 @@ // SPDX-FileCopyrightText: 2025 Erin Catto // SPDX-License-Identifier: MIT -#include "camera.h" -#include "renderer.h" #include "sample.h" -#include "scene.h" +#include "gfx/draw.h" #include "utils.h" +#include "box3d/box3d.h" + #include class BoxHull : public Sample @@ -69,14 +69,15 @@ public: m_box = b3MakeScaledBoxHull( h, transform, postScale ); } - void UpdateUI() override + bool HasSolverControls() const override { - float height = 180.0f; - ImGui::SetNextWindowPos( ImVec2( 10.0f, m_camera->m_height - height - 50.0f ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 350.0f, height ) ); - ImGui::Begin( "Box Hull", nullptr, 0 ); + return false; + } - ImGui::PushItemWidth( 320.0f ); + bool DrawControls() override + { + float fontSize = ImGui::GetFontSize(); + ImGui::PushItemWidth( 10.0f * fontSize ); if ( ImGui::SliderFloat3( "h", &m_halfWidths.x, 0.1f, 2.0f, "%.1f" ) ) { @@ -99,22 +100,22 @@ public: CreateHulls( m_halfWidths, m_transform, m_postScale ); } - ImGui::PopItemWidth(); - - if ( ImGui::Button( "refresh" ) ) + if ( ImGui::Button( "Refresh" ) ) { CreateHulls( m_halfWidths, m_transform, m_postScale ); } - ImGui::End(); + ImGui::PopItemWidth(); + + return true; } void Render() override { - DrawHull( m_scene, b3Transform_identity, m_hull, b3_colorYellow, true ); - DrawHull( m_scene, b3Transform_identity, &m_box.base, b3_colorCyan, true ); + DrawHull( b3Transform_identity, m_hull, MakeColor( b3_colorYellow ) ); + DrawHull( b3Transform_identity, &m_box.base, MakeColor( b3_colorCyan ) ); - DrawTransform( m_scene, b3Transform_identity, 1.0f ); + DrawAxes( b3Transform_identity, 1.0f ); Sample::Render(); } @@ -132,7 +133,7 @@ public: b3Hull* m_hull; }; -static int sampleBoxHull = SampleManager::Register( "Geometry", "Box Hull", BoxHull::Create ); +static int sampleBoxHull = RegisterSample( "Geometry", "Box Hull", BoxHull::Create ); class Hull : public Sample { @@ -208,10 +209,10 @@ public: { if ( m_hull != nullptr ) { - DrawHull( m_scene, b3Transform_identity, m_hull, b3_colorYellow, true ); + DrawHull( b3Transform_identity, m_hull, MakeColor( b3_colorYellow ) ); } - DrawTransform( m_scene, b3Transform_identity, 1.0f ); + DrawAxes( b3Transform_identity, 1.0f ); Sample::Render(); } @@ -227,7 +228,7 @@ public: int m_count; }; -static int sampleHull = SampleManager::Register( "Geometry", "Hull", Hull::Create ); +static int sampleHull = RegisterSample( "Geometry", "Hull", Hull::Create ); class HullReduction : public Sample { @@ -301,15 +302,13 @@ public: } } - void UpdateUI() override + bool HasSolverControls() const override { - float fontSize = ImGui::GetFontSize(); - float height = 12.0f * fontSize; - ImGui::SetNextWindowPos( { 1.0f * fontSize, m_camera->m_height - height - 3.0f * fontSize }, ImGuiCond_Once ); - ImGui::SetNextWindowSize( { 16.0f * fontSize, height } ); - - ImGui::Begin( "Hull Reduction", nullptr, ImGuiWindowFlags_NoResize ); + return false; + } + bool DrawControls() override + { if ( ImGui::RadioButton( "Box", m_type == e_box ) ) { m_type = e_box; @@ -329,19 +328,19 @@ public: GenerateHull(); } - ImGui::End(); + return true; } void Render() override { if ( m_hull != nullptr ) { - DrawHull( m_scene, b3Transform_identity, m_hull, b3_colorYellow, true ); + DrawHull( b3Transform_identity, m_hull, MakeColor( b3_colorYellow ) ); DrawTextLine( "v/f/e = %d/%d/%d", m_hull->vertexCount, m_hull->faceCount, m_hull->edgeCount / 2 ); } - DrawTransform( m_scene, b3Transform_identity, 1.0f ); + DrawAxes( b3Transform_identity, 1.0f ); Sample::Render(); } @@ -358,7 +357,7 @@ public: int m_count; }; -static int sampleHullReduction = SampleManager::Register( "Geometry", "Hull Reduction", HullReduction::Create ); +static int sampleHullReduction = RegisterSample( "Geometry", "Hull Reduction", HullReduction::Create ); class HullScale : public Sample { @@ -407,9 +406,9 @@ public: b3Transform transform1 = { { -2.0f, 0.0f, 0.0f }, b3Quat_identity }; b3Transform transform2 = { { 2.0f, 0.0f, 0.0f }, b3Quat_identity }; - DrawHull( m_scene, transform1, m_original, b3_colorGreen, true ); - DrawHull( m_scene, transform2, m_hull, b3_colorYellow, true ); - DrawTransform( m_scene, b3Transform_identity, 1.0f ); + DrawHull( transform1, m_original, MakeColor( b3_colorGreen ) ); + DrawHull( transform2, m_hull, MakeColor( b3_colorYellow ) ); + DrawAxes( b3Transform_identity, 1.0f ); DrawTextLine( "hull 1: area = %g, volume = %g, radius = %g", m_original->surfaceArea, m_original->volume, m_original->innerRadius ); @@ -418,15 +417,13 @@ public: Sample::Render(); } - void UpdateUI() override + bool HasSolverControls() const override { - float fontSize = ImGui::GetFontSize(); - float height = 18.0f * fontSize; - ImGui::SetNextWindowPos( { 1.0f * fontSize, m_camera->m_height - height - 3.0f * fontSize }, ImGuiCond_Once ); - ImGui::SetNextWindowSize( { 18.0f * fontSize, height } ); - - ImGui::Begin( "Hull Scale", nullptr, ImGuiWindowFlags_NoResize ); + return false; + } + bool DrawControls() override + { if ( ImGui::SliderFloat( "sx", &m_scale.x, -2.0f, 2.0f, "%.1f" ) ) { UpdateHull(); @@ -472,7 +469,7 @@ public: UpdateHull(); } - ImGui::End(); + return true; } static Sample* Create( SampleContext* sampleContext ) @@ -488,7 +485,7 @@ public: b3Vec3 m_offset; }; -static int sampleHullScale = SampleManager::Register( "Geometry", "Hull Scale", HullScale::Create ); +static int sampleHullScale = RegisterSample( "Geometry", "Hull Scale", HullScale::Create ); class CapsuleMass : public Sample { @@ -582,15 +579,15 @@ public: void Render() override { - DrawCapsule( m_scene, b3Transform_identity, m_capsule, b3_colorAqua ); - DrawHull( m_scene, b3Transform_identity, &m_box.base, b3_colorBlueViolet, true ); + DrawSolidCapsule( b3Transform_identity, m_capsule, MakeColorAlpha( b3_colorAqua, 0.8f ) ); + DrawHull( b3Transform_identity, &m_box.base, MakeColor( b3_colorBlueViolet ) ); if ( m_hull != nullptr ) { - DrawHull( m_scene, b3Transform_identity, m_hull, b3_colorYellow, true ); + DrawHull( b3Transform_identity, m_hull, MakeColor( b3_colorYellow ) ); } - DrawTransform( m_scene, b3Transform_identity, 1.0f ); + DrawAxes( b3Transform_identity, 1.0f ); if ( m_hull != nullptr ) { @@ -618,19 +615,19 @@ public: Sample::Render(); } - void UpdateUI() override + bool HasSolverControls() const override { - float height = 180.0f; - ImGui::SetNextWindowPos( ImVec2( 10.0f, m_camera->m_height - height - 50.0f ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 350.0f, height ) ); - ImGui::Begin( "Mass Data", nullptr, 0 ); + return false; + } + bool DrawControls() override + { if ( ImGui::SliderInt( "sides", &m_sides, 3, m_maxSides ) ) { CreateCapsuleHull( m_sides ); } - ImGui::End(); + return true; } static Sample* Create( SampleContext* sampleContext ) @@ -648,4 +645,4 @@ public: int m_sides; }; -static int sampleCapsuleMass = SampleManager::Register( "Geometry", "Capsule Mass", CapsuleMass::Create ); +static int sampleCapsuleMass = RegisterSample( "Geometry", "Capsule Mass", CapsuleMass::Create ); diff --git a/samples/sample_issues.cpp b/samples/sample_issues.cpp index 6e8d6a2..a548197 100644 --- a/samples/sample_issues.cpp +++ b/samples/sample_issues.cpp @@ -1,12 +1,10 @@ // SPDX-FileCopyrightText: 2025 Erin Catto // SPDX-License-Identifier: MIT -#include "camera.h" #include "imgui.h" #include "mesh_loader.h" -#include "renderer.h" #include "sample.h" -#include "scene.h" +#include "gfx/draw.h" #include "box3d/box3d.h" @@ -49,7 +47,7 @@ public: std::vector m_meshes; }; -static int sampleDumpLoader = SampleManager::Register( "Issues", "Dump Loader", DumpLoader::Create ); +static int sampleDumpLoader = RegisterSample( "Issues", "Dump Loader", DumpLoader::Create ); class Crash : public Sample { @@ -92,14 +90,8 @@ public: b3DestroyMesh( m_gridMesh ); } - void UpdateUI() override + bool DrawControls() override { - float height = 320.0f; - ImGui::SetNextWindowPos( ImVec2( 10.0f, m_camera->m_height - height - 50.0f ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 300.0f, height ) ); - - ImGui::Begin( "Crash", nullptr, ImGuiWindowFlags_NoResize ); - if ( ImGui::Button( "Add Joint" ) ) { b3WeldJointDef jointDef = b3DefaultWeldJointDef(); @@ -108,7 +100,7 @@ public: b3CreateWeldJoint( m_worldId, &jointDef ); } - ImGui::End(); + return true; } static Sample* Create( SampleContext* context ) @@ -121,7 +113,7 @@ public: b3MeshData* m_gridMesh; }; -static int sampleCrash = SampleManager::Register( "Issues", "Crash", Crash::Create ); +static int sampleCrash = RegisterSample( "Issues", "Crash", Crash::Create ); class MultiplePrismatic : public Sample { @@ -131,7 +123,7 @@ public: { if ( context->restart == false ) { - m_camera->SetView( 0.0f, 0.0f, 65.0f, { 0.0f, 0.0f, 0.0f } ); + m_camera->SetView( 0.0f, 0.0f, 25.0f, { 0.0f, 5.0f, 0.0f } ); } b3BodyId groundId; @@ -177,7 +169,7 @@ public: } }; -static int sampleMultiplePrismatic = SampleManager::Register( "Issues", "Multiple Prismatic", MultiplePrismatic::Create ); +static int sampleMultiplePrismatic = RegisterSample( "Issues", "Multiple Prismatic", MultiplePrismatic::Create ); class HullCrash : public Sample { @@ -252,17 +244,17 @@ public: { if ( m_hull != nullptr ) { - DrawHull( m_scene, b3Transform_identity, m_hull, b3_colorYellow, true ); + DrawHull( b3Transform_identity, m_hull, MakeColor( b3_colorYellow ) ); } else { for ( int i = 0; i < m_count; ++i ) { - DrawPoint( m_scene, m_points[i], 5.0f, b3_colorWhite ); + DrawPoint( m_points[i], 5.0f, MakeColor( b3_colorWhite ) ); } } - DrawTransform( m_scene, b3Transform_identity, 1.0f ); + DrawAxes( b3Transform_identity, 1.0f ); Sample::Render(); } @@ -278,7 +270,7 @@ public: int m_count; }; -static int sampleHullCrash = SampleManager::Register( "Issues", "Hull Crash", HullCrash::Create ); +static int sampleHullCrash = RegisterSample( "Issues", "Hull Crash", HullCrash::Create ); class ConvexJitter : public Sample { @@ -289,20 +281,10 @@ public: if ( context->restart == false ) { m_camera->SetView( 0.0f, 15.0f, 10.0f, { 0.0f, 2.0f, 0.0f } ); - EnableGrid( m_scene, true ); + } -#if 1 - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull box = b3MakeBoxHull( 10.0f, 1.0f, 10.0f ); - b3CreateHullShape( groundId, &shapeDef, &box.base ); - } -#endif + AddGroundBox( 10.0f ); float s = 0.01f; @@ -398,7 +380,7 @@ public: } }; -static int sampleConvexJitter = SampleManager::Register( "Issues", "Convex Jitter", ConvexJitter::Create ); +static int sampleConvexJitter = RegisterSample( "Issues", "Convex Jitter", ConvexJitter::Create ); class SBoxMover : public Sample { @@ -463,7 +445,7 @@ public: { Sample::Render(); b3Transform transform = { { 0.0f, 1.1f, 0.0f }, b3Quat_identity }; - DrawTransform( m_scene, transform, 3.0f ); + DrawAxes( transform, 3.0f ); } static Sample* Create( SampleContext* context ) @@ -476,7 +458,7 @@ public: b3MeshData* m_gridMesh; }; -static int sampleBoxMesh = SampleManager::Register( "Issues", "s&box mover", SBoxMover::Create ); +static int sampleBoxMesh = RegisterSample( "Issues", "s&box mover", SBoxMover::Create ); class CapsuleMeshBug : public Sample { @@ -486,7 +468,7 @@ public: { if ( m_context->restart == false ) { - m_camera->SetView( 120.0f, 30.0f, 10.0f, { 0.0f, 2.0f, 0.0f } ); + m_camera->SetView( 20.0f, 10.0f, 30.0f, { 0.0f, 2.0f, 0.0f } ); } // --- Ground plane --- @@ -547,4 +529,4 @@ public: b3MeshData* m_building = nullptr; }; -static int sampleIndex = SampleManager::Register( "Issues", "Capsule Mesh", CapsuleMeshBug::Create ); +static int sampleIndex = RegisterSample( "Issues", "Capsule Mesh", CapsuleMeshBug::Create ); diff --git a/samples/sample_joint.cpp b/samples/sample_joint.cpp index df32cd8..46cec60 100644 --- a/samples/sample_joint.cpp +++ b/samples/sample_joint.cpp @@ -1,12 +1,10 @@ // SPDX-FileCopyrightText: 2025 Erin Catto // SPDX-License-Identifier: MIT -#include "GLFW/glfw3.h" -#include "camera.h" +#include "gfx/draw.h" +#include "gfx/keycodes.h" #include "imgui.h" -#include "renderer.h" #include "sample.h" -#include "scene.h" #include "box3d/box3d.h" @@ -14,11 +12,6 @@ class DistanceJoint : public Sample { public: - enum - { - e_maxCount = 10 - }; - explicit DistanceJoint( SampleContext* context ) : Sample( context ) { @@ -27,6 +20,8 @@ public: m_camera->SetView( 0.0f, 0.0f, 40.0f, { 0.0f, 10.0f, 0.0f } ); } + AddGroundBox( 20.0f ); + { b3BodyDef bodyDef = b3DefaultBodyDef(); m_groundId = b3CreateBody( m_worldId, &bodyDef ); @@ -43,7 +38,7 @@ public: m_enableSpring = false; m_enableLimit = false; - for ( int i = 0; i < e_maxCount; ++i ) + for ( int i = 0; i < m_maxCount; ++i ) { m_bodyIds[i] = b3_nullBodyId; m_jointIds[i] = b3_nullJointId; @@ -109,16 +104,8 @@ public: } } - void UpdateUI() override + bool DrawControls() override { - float fontSize = ImGui::GetFontSize(); - float height = 20.0f * fontSize; - ImGui::SetNextWindowPos( { 0.5f * fontSize, m_camera->m_height - height - 2.0f * fontSize }, ImGuiCond_Once ); - ImGui::SetNextWindowSize( { 18.0f * fontSize, height } ); - - ImGui::Begin( "Distance Joint", nullptr, ImGuiWindowFlags_NoResize ); - ImGui::PushItemWidth( 10.0f * fontSize ); - if ( ImGui::SliderFloat( "Length", &m_length, 0.1f, 4.0f, "%3.1f" ) ) { for ( int i = 0; i < m_count; ++i ) @@ -139,7 +126,7 @@ public: if ( m_enableSpring ) { - if ( ImGui::SliderFloat( "Tension", &m_tensionForce, 0.0f, 4000.0f ) ) + if ( ImGui::SliderFloat( "Tension##Spring", &m_tensionForce, 0.0f, 4000.0f ) ) { for ( int i = 0; i < m_count; ++i ) { @@ -148,7 +135,7 @@ public: } } - if ( ImGui::SliderFloat( "Compression", &m_compressionForce, 0.0f, 200.0f ) ) + if ( ImGui::SliderFloat( "Compression##Spring", &m_compressionForce, 0.0f, 200.0f ) ) { for ( int i = 0; i < m_count; ++i ) { @@ -157,7 +144,7 @@ public: } } - if ( ImGui::SliderFloat( "Hertz", &m_hertz, 0.0f, 15.0f, "%3.1f" ) ) + if ( ImGui::SliderFloat( "Hertz##Spring", &m_hertz, 0.0f, 15.0f, "%3.1f" ) ) { for ( int i = 0; i < m_count; ++i ) { @@ -166,7 +153,7 @@ public: } } - if ( ImGui::SliderFloat( "Damping", &m_dampingRatio, 0.0f, 4.0f, "%3.1f" ) ) + if ( ImGui::SliderFloat( "Damping##Spring", &m_dampingRatio, 0.0f, 4.0f, "%3.1f" ) ) { for ( int i = 0; i < m_count; ++i ) { @@ -174,6 +161,8 @@ public: b3Joint_WakeBodies( m_jointIds[i] ); } } + + ImGui::Separator(); } if ( ImGui::Checkbox( "Limit", &m_enableLimit ) ) @@ -187,7 +176,7 @@ public: if ( m_enableLimit ) { - if ( ImGui::SliderFloat( "Min Length", &m_minLength, 0.1f, 4.0f, "%3.1f" ) ) + if ( ImGui::SliderFloat( "Min##Limit", &m_minLength, 0.1f, 4.0f, "%3.1f" ) ) { for ( int i = 0; i < m_count; ++i ) { @@ -196,7 +185,7 @@ public: } } - if ( ImGui::SliderFloat( "Max Length", &m_maxLength, 0.1f, 4.0f, "%3.1f" ) ) + if ( ImGui::SliderFloat( "Max##Limit", &m_maxLength, 0.1f, 4.0f, "%3.1f" ) ) { for ( int i = 0; i < m_count; ++i ) { @@ -204,23 +193,17 @@ public: b3Joint_WakeBodies( m_jointIds[i] ); } } + + ImGui::Separator(); } int count = m_count; - if ( ImGui::SliderInt( "Count", &count, 1, e_maxCount ) ) + if ( ImGui::SliderInt( "Count", &count, 1, m_maxCount ) ) { CreateScene( count ); } - ImGui::PopItemWidth(); - ImGui::End(); - } - - void Render() override - { - Sample::Render(); - - DrawGrid( m_scene, 20 ); + return true; } static Sample* Create( SampleContext* context ) @@ -228,9 +211,11 @@ public: return new DistanceJoint( context ); } + static constexpr int m_maxCount = 20; + b3BodyId m_groundId; - b3BodyId m_bodyIds[e_maxCount]; - b3JointId m_jointIds[e_maxCount]; + b3BodyId m_bodyIds[m_maxCount]; + b3JointId m_jointIds[m_maxCount]; int m_count; float m_hertz; float m_dampingRatio; @@ -243,7 +228,7 @@ public: bool m_enableLimit; }; -static int sampleDistanceJoint = SampleManager::Register( "Joints", "Distance Joint", DistanceJoint::Create ); +static int sampleDistanceJoint = RegisterSample( "Joints", "Distance Joint", DistanceJoint::Create ); class FilterJoint : public Sample { @@ -254,19 +239,9 @@ public: if ( context->restart == false ) { m_camera->SetView( 45.0f, 30.0f, 15.0f, { 0.0f, 2.0f, 0.0f } ); - EnableGrid( m_scene, true ); } - b3BodyId groundId; - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull groundBox = b3MakeBoxHull( 20.0f, 1.0f, 20.0f ); - b3CreateHullShape( groundId, &shapeDef, &groundBox.base ); - } + AddGroundBox( 20.0f ); b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.type = b3_dynamicBody; @@ -287,22 +262,13 @@ public: b3CreateFilterJoint( m_worldId, &jointDef ); } - void Render() override - { - Sample::Render(); - - b3Transform transform = b3Transform_identity; - transform.p.y += 0.05f; - DrawTransform( m_scene, transform, 2.0f ); - } - static Sample* Create( SampleContext* context ) { return new FilterJoint( context ); } }; -static int sampleFilterJoint = SampleManager::Register( "Joints", "Filter", FilterJoint::Create ); +static int sampleFilterJoint = RegisterSample( "Joints", "Filter", FilterJoint::Create ); /// This test shows how to use a motor joint. A motor joint /// can be used to animate a dynamic body. With finite motor forces @@ -315,18 +281,16 @@ public: { if ( context->restart == false ) { - m_camera->SetView( 0.0f, 0.0f, 40.0f, { 0.0f, 10.0f, 0.0f } ); - EnableGrid( m_scene, true ); + m_camera->SetView( 0.0f, 0.0f, 25.0f, { 0.0f, 8.0f, 0.0f } ); } + AddGroundBox( 20.0f ); + b3BodyId groundId; { b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.position.y = -1.0f; groundId = b3CreateBody( m_worldId, &bodyDef ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull box = b3MakeBoxHull( 20.0f, 1.0f, 20.0f ); - b3CreateHullShape( groundId, &shapeDef, &box.base ); } m_transform = { .p = { 0.0f, 10.0f, 0.0f }, .q = b3Quat_identity }; @@ -397,15 +361,8 @@ public: m_time = 0.0f; } - void UpdateUI() override + bool DrawControls() override { - float fontSize = ImGui::GetFontSize(); - float height = 180.0f; - ImGui::SetNextWindowPos( ImVec2( 0.5f * fontSize, m_camera->m_height - height - 2.0f * fontSize ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 240.0f, height ) ); - - ImGui::Begin( "Motor Joint", nullptr, ImGuiWindowFlags_NoResize ); - if ( ImGui::SliderFloat( "Speed", &m_speed, -5.0f, 5.0f, "%.0f" ) ) { } @@ -425,7 +382,7 @@ public: b3Body_ApplyLinearImpulseToCenter( m_bodyId, { 100000.0f, 0.0f }, true ); } - ImGui::End(); + return true; } void Step() override @@ -455,7 +412,7 @@ public: b3Body_SetTargetTransform( m_targetId, m_transform, timeStep, true ); } - DrawTransform( m_scene, m_transform, 1.0f ); + DrawAxes( m_transform, 1.0f ); Sample::Step(); @@ -480,7 +437,7 @@ public: float m_maxTorque; }; -static int sampleMotorJoint = SampleManager::Register( "Joints", "Motor Joint", MotorJoint::Create ); +static int sampleMotorJoint = RegisterSample( "Joints", "Motor Joint", MotorJoint::Create ); class TopDownFriction : public Sample { @@ -490,7 +447,7 @@ public: { if ( context->restart == false ) { - m_camera->SetView( 0.0f, 0.0f, 25.0f, { 0.0f, 10.0f, 0.0f } ); + m_camera->SetView( 0.0f, 0.0f, 26.0f, { 0.0f, 10.0f, 0.0f } ); } b3BodyId groundId; @@ -498,16 +455,16 @@ public: b3BodyDef bodyDef = b3DefaultBodyDef(); groundId = b3CreateBody( m_worldId, &bodyDef ); b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull box = b3MakeTransformedBoxHull( 10.0f, 0.5f, 50.0f, { b3Vec3_zero, b3Quat_identity } ); + b3BoxHull box = b3MakeTransformedBoxHull( 10.0f, 0.5f, 4.0f, { b3Vec3_zero, b3Quat_identity } ); b3CreateHullShape( groundId, &shapeDef, &box.base ); - box = b3MakeTransformedBoxHull( 0.5f, 10.0f, 50.0f, { { -10.0f, 10.0f, 0.0f }, b3Quat_identity } ); + box = b3MakeTransformedBoxHull( 0.5f, 10.0f, 4.0f, { { -10.0f, 10.0f, 0.0f }, b3Quat_identity } ); b3CreateHullShape( groundId, &shapeDef, &box.base ); - box = b3MakeTransformedBoxHull( 0.5f, 10.0f, 50.0f, { { 10.0f, 10.0f, 0.0f }, b3Quat_identity } ); + box = b3MakeTransformedBoxHull( 0.5f, 10.0f, 4.0f, { { 10.0f, 10.0f, 0.0f }, b3Quat_identity } ); b3CreateHullShape( groundId, &shapeDef, &box.base ); - box = b3MakeTransformedBoxHull( 10.0f, 0.5f, 50.0f, { { 00.0f, 20.0f, 0.0f }, b3Quat_identity } ); + box = b3MakeTransformedBoxHull( 10.0f, 0.5f, 4.0f, { { 00.0f, 20.0f, 0.0f }, b3Quat_identity } ); b3CreateHullShape( groundId, &shapeDef, &box.base ); } @@ -561,15 +518,8 @@ public: } } - void UpdateUI() override + bool DrawControls() override { - float fontSize = ImGui::GetFontSize(); - float height = 180.0f; - ImGui::SetNextWindowPos( ImVec2( 0.5f * fontSize, m_camera->m_height - height - 2.0f * fontSize ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 240.0f, height ) ); - - ImGui::Begin( "Top Down Friction", nullptr, ImGuiWindowFlags_NoResize ); - if ( ImGui::Button( "Explode" ) ) { b3Sphere sphere = { { 0.0f, 10.0f, 0.0 }, 10.0f }; @@ -580,10 +530,10 @@ public: def.impulsePerArea = 10000.0f; b3World_Explode( m_worldId, &def ); - DrawSphere( m_scene, b3Transform_identity, sphere, b3_colorWhite ); + DrawSolidSphere( b3Transform_identity, sphere, MakeColor( b3_colorWhite ) ); } - ImGui::End(); + return true; } static Sample* Create( SampleContext* context ) @@ -592,7 +542,7 @@ public: } }; -static int sampleTopDownFriction = SampleManager::Register( "Joints", "Top Down Friction", TopDownFriction::Create ); +static int sampleTopDownFriction = RegisterSample( "Joints", "Top Down Friction", TopDownFriction::Create ); class PrismaticJoint : public Sample { @@ -603,7 +553,6 @@ public: if ( context->restart == false ) { m_camera->SetView( 45.0f, 30.0f, 15.0f, { 0.0f, 2.0f, 0.0f } ); - EnableGrid( m_scene, true ); } m_targetTranslation = 0.0f; @@ -617,15 +566,13 @@ public: m_enableMotor = false; m_enableLimit = false; + AddGroundBox( 20.0f ); + b3BodyId groundId; { b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.position = { 0.0f, -1.0f, 0.0f }; groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull groundBox = b3MakeBoxHull( 20.0f, 1.0f, 20.0f ); - b3CreateHullShape( groundId, &shapeDef, &groundBox.base ); } b3BodyDef bodyDef = b3DefaultBodyDef(); @@ -659,14 +606,8 @@ public: m_jointId = b3CreatePrismaticJoint( m_worldId, &jointDef ); } - void UpdateUI() override + bool DrawControls() override { - float height = 320.0f; - ImGui::SetNextWindowPos( ImVec2( 10.0f, m_camera->m_height - height - 50.0f ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 300.0f, height ) ); - - ImGui::Begin( "Prismatic Joint", nullptr, ImGuiWindowFlags_NoResize ); - if ( ImGui::Checkbox( "Limit", &m_enableLimit ) ) { b3PrismaticJoint_EnableLimit( m_jointId, m_enableLimit ); @@ -690,6 +631,8 @@ public: } } + ImGui::Separator(); + if ( ImGui::Checkbox( "Motor", &m_enableMotor ) ) { b3PrismaticJoint_EnableMotor( m_jointId, m_enableMotor ); @@ -711,6 +654,8 @@ public: } } + ImGui::Separator(); + if ( ImGui::Checkbox( "Spring", &m_enableSpring ) ) { b3PrismaticJoint_EnableSpring( m_jointId, m_enableSpring ); @@ -738,7 +683,7 @@ public: } } - ImGui::End(); + return true; } void Render() override @@ -765,7 +710,7 @@ public: bool m_enableLimit; }; -static int samplePrismaticJoint = SampleManager::Register( "Joints", "Prismatic", PrismaticJoint::Create ); +static int samplePrismaticJoint = RegisterSample( "Joints", "Prismatic", PrismaticJoint::Create ); class SphericalJoint : public Sample { @@ -776,37 +721,35 @@ public: if ( context->restart == false ) { m_camera->SetView( 45.0f, 30.0f, 15.0f, { 0.0f, 2.0f, 0.0f } ); - EnableGrid( m_scene, true ); } + AddGroundBox( 20.0f ); + b3BodyId groundId; { b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.position = { 0.0f, -1.0f, 0.0f }; groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull groundBox = b3MakeBoxHull( 20.0f, 1.0f, 20.0f ); - b3CreateHullShape( groundId, &shapeDef, &groundBox.base ); } b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.type = b3_dynamicBody; - bodyDef.position = { 0.0f, 4.0f, 1.5f }; + bodyDef.position = { 0.0f, 4.0f, 0.0f }; bodyDef.gravityScale = 0.0f; m_bodyId = b3CreateBody( m_worldId, &bodyDef ); b3ShapeDef shapeDef = b3DefaultShapeDef(); + shapeDef.density = 100.0f; - b3BoxHull box = b3MakeBoxHull( 0.5f, 0.25f, 1.5f ); + b3BoxHull box = b3MakeBoxHull( 0.5f, 1.5f, 0.25f ); b3CreateHullShape( m_bodyId, &shapeDef, &box.base ); b3SphericalJointDef jointDef = b3DefaultSphericalJointDef(); jointDef.base.bodyIdA = groundId; jointDef.base.bodyIdB = m_bodyId; jointDef.base.drawScale = 2.0f; - jointDef.base.localFrameA.p = { 0.0f, 5.5f, 0.0f }; - jointDef.base.localFrameB.p = { 0.0f, 0.0f, -1.5f }; + jointDef.base.localFrameA.p = { 0.0f, 6.5f, 0.0f }; + jointDef.base.localFrameB.p = { 0.0f, 1.5f, 0.0f }; jointDef.enableConeLimit = m_enableConeLimit; jointDef.coneAngle = B3_DEG_TO_RAD * m_coneAngleDegrees; jointDef.enableTwistLimit = m_enableTwistLimit; @@ -822,14 +765,8 @@ public: m_jointId = b3CreateSphericalJoint( m_worldId, &jointDef ); } - void UpdateUI() override + bool DrawControls() override { - float height = 360.0f; - ImGui::SetNextWindowPos( ImVec2( 10.0f, m_camera->m_height - height - 50.0f ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 300.0f, height ) ); - - ImGui::Begin( "Spherical Joint", nullptr, ImGuiWindowFlags_NoResize ); - if ( ImGui::Checkbox( "Cone Limit", &m_enableConeLimit ) ) { b3SphericalJoint_EnableConeLimit( m_jointId, m_enableConeLimit ); @@ -845,6 +782,8 @@ public: } } + ImGui::Separator(); + if ( ImGui::Checkbox( "Twist Limit", &m_enableTwistLimit ) ) { b3SphericalJoint_EnableTwistLimit( m_jointId, m_enableTwistLimit ); @@ -870,6 +809,8 @@ public: } } + ImGui::Separator(); + if ( ImGui::Checkbox( "Motor", &m_enableMotor ) ) { b3SphericalJoint_EnableMotor( m_jointId, m_enableMotor ); @@ -878,7 +819,7 @@ public: if ( m_enableMotor ) { - if ( ImGui::SliderFloat( "Max Torque", &m_motorTorque, 0.0f, 50.0f, "%.0f" ) ) + if ( ImGui::SliderFloat( "Max Torque", &m_motorTorque, 0.0f, 10000.0f, "%.0f" ) ) { b3SphericalJoint_SetMaxMotorTorque( m_jointId, m_motorTorque ); b3Joint_WakeBodies( m_jointId ); @@ -891,6 +832,8 @@ public: } } + ImGui::Separator(); + if ( ImGui::Checkbox( "Spring", &m_enableSpring ) ) { b3SphericalJoint_EnableSpring( m_jointId, m_enableSpring ); @@ -922,19 +865,7 @@ public: } } - ImGui::End(); - } - - void Render() override - { - Sample::Render(); - - b3Transform transform = b3Transform_identity; - transform.p.y += 0.05f; - DrawTransform( m_scene, transform, 2.0f ); - - transform = b3Body_GetTransform( m_bodyId ); - DrawTransform( m_scene, transform, 2.0f ); + return true; } static Sample* Create( SampleContext* context ) @@ -958,7 +889,7 @@ public: bool m_enableConeLimit = false; }; -static int sampleSphericalJoint = SampleManager::Register( "Joints", "Spherical", SphericalJoint::Create ); +static int sampleSphericalJoint = RegisterSample( "Joints", "Spherical", SphericalJoint::Create ); class ParallelJoint : public Sample { @@ -969,22 +900,19 @@ public: if ( context->restart == false ) { m_camera->SetView( 45.0f, 30.0f, 15.0f, { 0.0f, 2.0f, 0.0f } ); - EnableGrid( m_scene, true ); } m_hertz = 10.0f; m_dampingRatio = 0.7f; m_maxTorque = 5000.0f; + AddGroundBox( 20.0f ); + b3BodyId groundId; { b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.position = { 0.0f, -1.0f, 0.0f }; groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull groundBox = b3MakeBoxHull( 20.0f, 1.0f, 20.0f ); - b3CreateHullShape( groundId, &shapeDef, &groundBox.base ); } { @@ -1048,15 +976,8 @@ public: m_jointId = b3CreateParallelJoint( m_worldId, &jointDef ); } - void UpdateUI() override + bool DrawControls() override { - float fontSize = ImGui::GetFontSize(); - float height = 20.0f * fontSize; - ImGui::SetNextWindowPos( { 1.0f * fontSize, m_camera->m_height - height - 3.0f * fontSize }, ImGuiCond_Once ); - ImGui::SetNextWindowSize( { 20.0f * fontSize, height } ); - - ImGui::Begin( "Parallel Joint", nullptr, ImGuiWindowFlags_NoResize ); - if ( ImGui::SliderFloat( "Hertz", &m_hertz, 0.0f, 5.0f, "%.1f" ) ) { b3ParallelJoint_SetSpringHertz( m_jointId, m_hertz ); @@ -1069,7 +990,7 @@ public: b3Joint_WakeBodies( m_jointId ); } - ImGui::End(); + return true; } static Sample* Create( SampleContext* context ) @@ -1084,7 +1005,7 @@ public: float m_dampingRatio; }; -static int sampleParallelJoint = SampleManager::Register( "Joints", "Parallel Spring", ParallelJoint::Create ); +static int sampleParallelJoint = RegisterSample( "Joints", "Parallel Spring", ParallelJoint::Create ); class RevoluteJoint : public Sample { @@ -1095,7 +1016,6 @@ public: if ( context->restart == false ) { m_camera->SetView( 45.0f, 30.0f, 15.0f, { 0.0f, 2.0f, 0.0f } ); - EnableGrid( m_scene, true ); } m_targetAngle = 0.0f; @@ -1109,15 +1029,13 @@ public: m_enableMotor = false; m_enableLimit = false; + AddGroundBox( 20.0f ); + b3BodyId groundId; { b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.position = { 0.0f, -1.0f, 0.0f }; groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull groundBox = b3MakeBoxHull( 20.0f, 1.0f, 20.0f ); - b3CreateHullShape( groundId, &shapeDef, &groundBox.base ); } b3BodyDef bodyDef = b3DefaultBodyDef(); @@ -1149,14 +1067,8 @@ public: m_jointId = b3CreateRevoluteJoint( m_worldId, &jointDef ); } - void UpdateUI() override + bool DrawControls() override { - float height = 320.0f; - ImGui::SetNextWindowPos( ImVec2( 10.0f, m_camera->m_height - height - 50.0f ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 300.0f, height ) ); - - ImGui::Begin( "Revolute Joint", nullptr, ImGuiWindowFlags_NoResize ); - if ( ImGui::Checkbox( "Limit", &m_enableLimit ) ) { b3RevoluteJoint_EnableLimit( m_jointId, m_enableLimit ); @@ -1180,6 +1092,8 @@ public: } } + ImGui::Separator(); + if ( ImGui::Checkbox( "Motor", &m_enableMotor ) ) { b3RevoluteJoint_EnableMotor( m_jointId, m_enableMotor ); @@ -1201,6 +1115,8 @@ public: } } + ImGui::Separator(); + if ( ImGui::Checkbox( "Spring", &m_enableSpring ) ) { b3RevoluteJoint_EnableSpring( m_jointId, m_enableSpring ); @@ -1228,7 +1144,7 @@ public: } } - ImGui::End(); + return true; } void Render() override @@ -1267,7 +1183,7 @@ public: bool m_enableLimit; }; -static int sampleRevoluteJoint = SampleManager::Register( "Joints", "Revolute", RevoluteJoint::Create ); +static int sampleRevoluteJoint = RegisterSample( "Joints", "Revolute", RevoluteJoint::Create ); class WeldJoint : public Sample { @@ -1278,18 +1194,15 @@ public: if ( context->restart == false ) { m_camera->SetView( 45.0f, 30.0f, 15.0f, { 0.0f, 2.0f, 0.0f } ); - EnableGrid( m_scene, true ); } + AddGroundBox( 20.0f ); + b3BodyId groundId; { b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.position = { 0.0f, -1.0f, 0.0f }; groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull groundBox = b3MakeBoxHull( 20.0f, 1.0f, 20.0f ); - b3CreateHullShape( groundId, &shapeDef, &groundBox.base ); } b3BodyDef bodyDef = b3DefaultBodyDef(); @@ -1318,15 +1231,9 @@ public: m_jointId = b3CreateWeldJoint( m_worldId, &jointDef ); } - void UpdateUI() override + bool DrawControls() override { - float height = 150.0f; - ImGui::SetNextWindowPos( ImVec2( 10.0f, m_camera->m_height - height - 50.0f ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 350.0f, height ) ); - - ImGui::Begin( "Weld Joint", nullptr, ImGuiWindowFlags_NoResize ); - - ImGui::PushItemWidth( 200.0f ); + ImGui::PushItemWidth( 6.0f * ImGui::GetFontSize() ); if ( ImGui::SliderFloat( "Linear Hertz", &m_linearHertz, 0.0f, 10.0f, "%.1f" ) ) { @@ -1354,7 +1261,7 @@ public: ImGui::PopItemWidth(); - ImGui::End(); + return true; } void Render() override @@ -1375,7 +1282,7 @@ public: float m_angularDampingRatio = 0.7f; }; -static int sampleWeldJoint = SampleManager::Register( "Joints", "Weld", WeldJoint::Create ); +static int sampleWeldJoint = RegisterSample( "Joints", "Weld", WeldJoint::Create ); class WheelJoint : public Sample { @@ -1386,7 +1293,6 @@ public: if ( context->restart == false ) { m_camera->SetView( 25.0f, 20.0f, 7.0f, { 0.0f, 2.0f, 0.0f } ); - EnableGrid( m_scene, true ); } m_spinSpeed = 0.0f; @@ -1408,15 +1314,13 @@ public: m_maxSteeringTorque = 20.0f; m_targetSteeringDegrees = 0.0f; + AddGroundBox( 20.0f ); + b3BodyId groundId; { b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.position = { 0.0f, -1.0f, 0.0f }; groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull groundBox = b3MakeBoxHull( 20.0f, 1.0f, 20.0f ); - b3CreateHullShape( groundId, &shapeDef, &groundBox.base ); } b3BodyDef bodyDef = b3DefaultBodyDef(); @@ -1462,15 +1366,8 @@ public: m_jointId = b3CreateWheelJoint( m_worldId, &jointDef ); } - void UpdateUI() override + bool DrawControls() override { - float fontSize = ImGui::GetFontSize(); - float height = 30.0f * fontSize; - ImGui::SetNextWindowPos( { 1.0f * fontSize, m_camera->m_height - height - 3.0f * fontSize }, ImGuiCond_Once ); - ImGui::SetNextWindowSize( { 25.0f * fontSize, height } ); - - ImGui::Begin( "Wheel Joint", nullptr, ImGuiWindowFlags_NoResize ); - if ( ImGui::Checkbox( "Suspension Limit", &m_enableSuspensionLimit ) ) { b3WheelJoint_EnableSuspensionLimit( m_jointId, m_enableSuspensionLimit ); @@ -1479,14 +1376,14 @@ public: if ( m_enableSuspensionLimit ) { - if ( ImGui::SliderFloat( "Lower Translation", &m_lowerTranslation, -10.0f, 10.0f, "%.1f" ) ) + if ( ImGui::SliderFloat( "Min##Limit", &m_lowerTranslation, -10.0f, 10.0f, "%.1f" ) ) { m_lowerTranslation = b3MinFloat( m_lowerTranslation, m_upperTranslation ); b3WheelJoint_SetSuspensionLimits( m_jointId, m_lowerTranslation, m_upperTranslation ); b3Joint_WakeBodies( m_jointId ); } - if ( ImGui::SliderFloat( "Upper Translation", &m_upperTranslation, -10.0f, 10.0f, "%.1f" ) ) + if ( ImGui::SliderFloat( "Max##Limit", &m_upperTranslation, -10.0f, 10.0f, "%.1f" ) ) { m_upperTranslation = b3MaxFloat( m_upperTranslation, m_lowerTranslation ); b3WheelJoint_SetSuspensionLimits( m_jointId, m_lowerTranslation, m_upperTranslation ); @@ -1494,6 +1391,8 @@ public: } } + ImGui::Separator(); + if ( ImGui::Checkbox( "Motor", &m_enableSpinMotor ) ) { b3WheelJoint_EnableSpinMotor( m_jointId, m_enableSpinMotor ); @@ -1515,7 +1414,9 @@ public: } } - if ( ImGui::Checkbox( "Suspension", &m_enableSuspension ) ) + ImGui::Separator(); + + if ( ImGui::Checkbox( "Suspension Spring", &m_enableSuspension ) ) { b3WheelJoint_EnableSuspension( m_jointId, m_enableSuspension ); b3Joint_WakeBodies( m_jointId ); @@ -1523,19 +1424,21 @@ public: if ( m_enableSuspension ) { - if ( ImGui::SliderFloat( "Suspension Hertz", &m_suspensionHertz, 0.0f, 10.0f, "%.1f" ) ) + if ( ImGui::SliderFloat( "Hertz##Suspension", &m_suspensionHertz, 0.0f, 10.0f, "%.1f" ) ) { b3WheelJoint_SetSuspensionHertz( m_jointId, m_suspensionHertz ); b3Joint_WakeBodies( m_jointId ); } - if ( ImGui::SliderFloat( "Suspension Damping", &m_suspensionDampingRatio, 0.0f, 2.0f, "%.1f" ) ) + if ( ImGui::SliderFloat( "Damping##Suspension", &m_suspensionDampingRatio, 0.0f, 2.0f, "%.1f" ) ) { b3WheelJoint_SetSuspensionDampingRatio( m_jointId, m_suspensionDampingRatio ); b3Joint_WakeBodies( m_jointId ); } } + ImGui::Separator(); + if ( ImGui::Checkbox( "Steering", &m_enableSteering ) ) { b3WheelJoint_EnableSteering( m_jointId, m_enableSteering ); @@ -1544,24 +1447,26 @@ public: if ( m_enableSteering ) { - if ( ImGui::SliderFloat( "Steering Hertz", &m_steeringHertz, 0.0f, 10.0f, "%.1f" ) ) + if ( ImGui::SliderFloat( "Hertz##Steering", &m_steeringHertz, 0.0f, 10.0f, "%.1f" ) ) { b3WheelJoint_SetSteeringHertz( m_jointId, m_steeringHertz ); b3Joint_WakeBodies( m_jointId ); } - if ( ImGui::SliderFloat( "Steering Damping", &m_steeringDampingRatio, 0.0f, 2.0f, "%.1f" ) ) + if ( ImGui::SliderFloat( "Damping##Steering", &m_steeringDampingRatio, 0.0f, 2.0f, "%.1f" ) ) { b3WheelJoint_SetSuspensionDampingRatio( m_jointId, m_suspensionDampingRatio ); b3Joint_WakeBodies( m_jointId ); } - if ( ImGui::SliderFloat( "Steering Degrees", &m_targetSteeringDegrees, -90.0f, 90.0f, "%.0f" ) ) + if ( ImGui::SliderFloat( "Degrees##Steering", &m_targetSteeringDegrees, -90.0f, 90.0f, "%.0f" ) ) { b3WheelJoint_SetTargetSteeringAngle( m_jointId, m_targetSteeringDegrees * B3_PI / 180.0f ); b3Joint_WakeBodies( m_jointId ); } + ImGui::Separator(); + if ( ImGui::Checkbox( "Steering Limit", &m_enableSteeringLimit ) ) { b3WheelJoint_EnableSteeringLimit( m_jointId, m_enableSteeringLimit ); @@ -1570,14 +1475,14 @@ public: if ( m_enableSteeringLimit ) { - if ( ImGui::SliderFloat( "Lower Degrees", &m_lowerSteeringDegrees, -90.0f, 0.0f, "%.0f" ) ) + if ( ImGui::SliderFloat( "Min Degrees", &m_lowerSteeringDegrees, -90.0f, 0.0f, "%.0f" ) ) { b3WheelJoint_SetSteeringLimits( m_jointId, B3_PI / 180.0f * m_lowerSteeringDegrees, B3_PI / 180.0f * m_upperSteeringDegrees ); b3Joint_WakeBodies( m_jointId ); } - if ( ImGui::SliderFloat( "Upper Degrees", &m_upperSteeringDegrees, 0.0f, 90.0f, "%.0f" ) ) + if ( ImGui::SliderFloat( "Max Degrees", &m_upperSteeringDegrees, 0.0f, 90.0f, "%.0f" ) ) { b3WheelJoint_SetSteeringLimits( m_jointId, B3_PI / 180.0f * m_lowerSteeringDegrees, B3_PI / 180.0f * m_upperSteeringDegrees ); @@ -1586,7 +1491,7 @@ public: } } - ImGui::End(); + return true; } void Render() override @@ -1595,10 +1500,6 @@ public: float angle = b3WheelJoint_GetSteeringAngle( m_jointId ); DrawTextLine( "steering degrees = %.1f", 180.0f / B3_PI * angle ); - - b3Transform transform = b3Transform_identity; - transform.p.y += 0.05f; - DrawTransform( m_scene, transform, 2.0f ); } static Sample* Create( SampleContext* context ) @@ -1627,7 +1528,7 @@ public: float m_targetSteeringDegrees; }; -static int sampleWheelJoint = SampleManager::Register( "Joints", "Wheel", WheelJoint::Create ); +static int sampleWheelJoint = RegisterSample( "Joints", "Wheel", WheelJoint::Create ); class BallAndChain : public Sample { @@ -1693,7 +1594,7 @@ public: } }; -static int sampleBallAndChain = SampleManager::Register( "Joints", "Ball and Chain", BallAndChain::Create ); +static int sampleBallAndChain = RegisterSample( "Joints", "Ball and Chain", BallAndChain::Create ); class Door : public Sample { @@ -1704,18 +1605,9 @@ public: if ( context->restart == false ) { m_camera->SetView( 45.0f, 30.0f, 15.0f, { 0.0f, 2.0f, 0.0f } ); - EnableGrid( m_scene, true ); } - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - m_groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull groundBox = b3MakeBoxHull( 20.0f, 1.0f, 20.0f ); - b3CreateHullShape( m_groundId, &shapeDef, &groundBox.base ); - } + m_groundId = AddGroundBox( 20.0f ); { b3BodyDef bodyDef = b3DefaultBodyDef(); @@ -1840,17 +1732,11 @@ public: } } - void UpdateUI() override + bool DrawControls() override { - float height = 220.0f; - ImGui::SetNextWindowPos( ImVec2( 10.0f, m_camera->m_height - height - 50.0f ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 350.0f, height ) ); + ImGui::PushItemWidth( 6.0f * ImGui::GetFontSize() ); - ImGui::Begin( "Door", nullptr, ImGuiWindowFlags_NoResize ); - - ImGui::PushItemWidth( 200.0f ); - - if ( ImGui::Button( "impulse" ) ) + if ( ImGui::Button( "Impulse##Door" ) ) { b3Vec3 p = b3Body_GetWorldPoint( m_doorId, { 0.75f, 0.0f, 0.0f } ); b3Body_ApplyLinearImpulse( m_doorId, { 0.0f, 0.0f, -m_magnitude }, p, true ); @@ -1858,9 +1744,9 @@ public: m_translationError2 = 0.0f; } - ImGui::SliderFloat( "magnitude", &m_magnitude, 1000.0f, 100000.0f, "%.0f" ); + ImGui::SliderFloat( "Magnitude##Door", &m_magnitude, 1000.0f, 100000.0f, "%.0f" ); - if ( ImGui::Checkbox( "limit", &m_enableLimit ) ) + if ( ImGui::Checkbox( "Limit##Door", &m_enableLimit ) ) { b3RevoluteJoint_EnableLimit( m_jointId1, m_enableLimit ); @@ -1870,12 +1756,12 @@ public: } } - if ( ImGui::Checkbox( "two joints", &m_twoJoints ) ) + if ( ImGui::Checkbox( "Two joints##Door", &m_twoJoints ) ) { CreateJoints(); } - if ( ImGui::SliderFloat( "hertz", &m_constraintHertz, 15.0f, 240.0f, "%.0f" ) ) + if ( ImGui::SliderFloat( "Hertz##Door", &m_constraintHertz, 15.0f, 240.0f, "%.0f" ) ) { b3Joint_SetConstraintTuning( m_jointId1, m_constraintHertz, m_constraintDampingRatio ); @@ -1885,7 +1771,7 @@ public: } } - if ( ImGui::SliderFloat( "damping", &m_constraintDampingRatio, 0.0f, 10.0f, "%.1f" ) ) + if ( ImGui::SliderFloat( "Damping##Door", &m_constraintDampingRatio, 0.0f, 10.0f, "%.1f" ) ) { b3Joint_SetConstraintTuning( m_jointId1, m_constraintHertz, m_constraintDampingRatio ); @@ -1897,7 +1783,7 @@ public: ImGui::PopItemWidth(); - ImGui::End(); + return true; } void Step() override @@ -1905,9 +1791,7 @@ public: Sample::Step(); b3Vec3 p = b3Body_GetWorldPoint( m_doorId, { 0.75f, 0.0f, 0.0f } ); - DrawPoint( m_scene, p, 10.0f, b3_colorDarkKhaki ); - - DrawTransform( m_scene, b3Transform_identity, 1.0f ); + DrawPoint( p, 10.0f, MakeColor( b3_colorDarkKhaki ) ); float translationError1 = b3Joint_GetLinearSeparation( m_jointId1 ); m_translationError1 = b3MaxFloat( m_translationError1, translationError1 ); @@ -1939,7 +1823,7 @@ public: bool m_twoJoints; }; -static int sampleDoor = SampleManager::Register( "Joints", "Door", Door::Create ); +static int sampleDoor = RegisterSample( "Joints", "Door", Door::Create ); // A suspension bridge class Bridge : public Sample @@ -1953,6 +1837,8 @@ public: m_camera->SetView( 0.0f, 20.0f, 35.0, { 0.0f, 10.0f, 0.0f } ); } + AddGroundBox( 60.0f ); + b3BodyId groundId = b3_nullBodyId; { b3BodyDef bodyDef = b3DefaultBodyDef(); @@ -2034,16 +1920,9 @@ public: } } - void UpdateUI() override + bool DrawControls() override { - float height = 80.0f; - ImGui::SetNextWindowPos( ImVec2( 10.0f, m_context->camera.m_height - height - 50.0f ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 240.0f, height ) ); - - ImGui::Begin( "Bridge", nullptr, ImGuiWindowFlags_NoResize ); - - // Slider takes half the window - ImGui::PushItemWidth( ImGui::GetWindowWidth() * 0.5f ); + ImGui::PushItemWidth( 6.0f * ImGui::GetFontSize() ); if ( ImGui::SliderFloat( "Gravity scale", &m_gravityScale, -1.0f, 1.0f, "%.1f" ) ) { @@ -2053,14 +1932,8 @@ public: } } - ImGui::End(); - } - - void Render() override - { - Sample::Render(); - - DrawGrid( m_scene, 20 ); + ImGui::PopItemWidth(); + return true; } static Sample* Create( SampleContext* context ) @@ -2073,7 +1946,7 @@ public: float m_gravityScale; }; -static int sampleBridgeIndex = SampleManager::Register( "Joints", "Bridge", Bridge::Create ); +static int sampleBridgeIndex = RegisterSample( "Joints", "Bridge", Bridge::Create ); // This test ensures joints work correctly with bodies that have motion locks class MotionLocks : public Sample @@ -2085,16 +1958,14 @@ public: if ( m_context->restart == false ) { m_camera->SetView( 0.0f, 30.0f, 40.0f, { 0.0f, 5.0f, 0.0f } ); - EnableGrid( m_scene, true ); } + AddGroundBox( 20.0f ); + b3BodyId groundId; { b3BodyDef bodyDef = b3DefaultBodyDef(); groundId = b3CreateBody( m_worldId, &bodyDef ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull box = b3MakeTransformedBoxHull( 20.0f, 1.0f, 20.0f, { { 0.0f, -1.0f, 0.0f }, b3Quat_identity } ); - b3CreateHullShape( groundId, &shapeDef, &box.base ); } m_motionLocks = {}; @@ -2281,15 +2152,8 @@ public: #endif } - void UpdateUI() override + bool DrawControls() override { - float fontSize = ImGui::GetFontSize(); - float height = 13.0f * fontSize; - ImGui::SetNextWindowPos( ImVec2( 0.5f * fontSize, m_camera->m_height - height - 2.0f * fontSize ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 10.0f * fontSize, height ) ); - - ImGui::Begin( "Motion Locks", nullptr, ImGuiWindowFlags_NoResize ); - if ( ImGui::Checkbox( "Lock Linear X", &m_motionLocks.linearX ) ) { for ( int i = 0; i < m_count; ++i ) @@ -2344,20 +2208,12 @@ public: } } - ImGui::End(); - - if ( glfwGetKey( m_context->window, GLFW_KEY_L ) == GLFW_PRESS ) + if ( IsKeyDown( KEY_L ) ) { b3Body_ApplyLinearImpulseToCenter( m_bodyIds[0], { 100.0f, 0.0f }, true ); } - } - void Render() override - { - Sample::Render(); - - b3Transform transform = { { 0.0f, 0.1f, 0.0f }, b3Quat_identity }; - DrawTransform( m_scene, transform, 1.0f ); + return true; } static Sample* Create( SampleContext* context ) @@ -2371,7 +2227,7 @@ public: b3MotionLocks m_motionLocks; }; -static int sampleMotionLocks = SampleManager::Register( "Joints", "Motion Locks", MotionLocks::Create ); +static int sampleMotionLocks = RegisterSample( "Joints", "Motion Locks", MotionLocks::Create ); class Driving : public Sample { @@ -2534,7 +2390,7 @@ public: // b3DestroyHull( hull ); m_camera->m_thirdPerson = true; - glfwSetInputMode( m_window, GLFW_CURSOR, GLFW_CURSOR_DISABLED ); + sapp_lock_mouse( true ); m_haveMouseLast = false; m_mouseLast = { 0.0f, 0.0f }; @@ -2544,7 +2400,7 @@ public: ~Driving() override { m_camera->m_thirdPerson = false; - glfwSetInputMode( m_window, GLFW_CURSOR, GLFW_CURSOR_NORMAL ); + sapp_lock_mouse( false ); b3DestroyHeightField( m_heightField ); } @@ -2576,22 +2432,16 @@ public: void Keyboard( int key, int action, int mods ) override { - if ( key == GLFW_KEY_T && action == GLFW_PRESS ) + if ( key == KEY_T && action == ACTION_PRESS ) { ToggleThirdPerson(); } } - void UpdateUI() override + bool DrawControls() override { - float fontSize = ImGui::GetFontSize(); - float height = 22.0f * fontSize; - ImGui::SetNextWindowPos( { 1.0f * fontSize, m_camera->m_height - height - 3.0f * fontSize }, ImGuiCond_Once ); - ImGui::SetNextWindowSize( { 25.0f * fontSize, height } ); - - ImGui::Begin( "Driving", nullptr, ImGuiWindowFlags_NoResize ); - - if ( ImGui::SliderFloat( "Lower Translation", &m_lowerTranslation, -10.0f, 10.0f, "%.1f" ) ) + ImGui::Text( "Suspension" ); + if ( ImGui::SliderFloat( "Min##Suspension", &m_lowerTranslation, -10.0f, 10.0f, "%.1f" ) ) { m_lowerTranslation = b3MinFloat( m_lowerTranslation, m_upperTranslation ); b3WheelJoint_SetSuspensionLimits( m_frontLeftId, m_lowerTranslation, m_upperTranslation ); @@ -2600,7 +2450,7 @@ public: b3WheelJoint_SetSuspensionLimits( m_rearRightId, m_lowerTranslation, m_upperTranslation ); } - if ( ImGui::SliderFloat( "Upper Translation", &m_upperTranslation, -10.0f, 10.0f, "%.1f" ) ) + if ( ImGui::SliderFloat( "Max##Suspension", &m_upperTranslation, -10.0f, 10.0f, "%.1f" ) ) { m_upperTranslation = b3MaxFloat( m_upperTranslation, m_lowerTranslation ); b3WheelJoint_SetSuspensionLimits( m_frontLeftId, m_lowerTranslation, m_upperTranslation ); @@ -2609,10 +2459,7 @@ public: b3WheelJoint_SetSuspensionLimits( m_rearRightId, m_lowerTranslation, m_upperTranslation ); } - ImGui::SliderFloat( "Max Torque", &m_maxSpinTorque, 0.0f, 100.0f, "%.0f" ); - ImGui::SliderFloat( "Speed", &m_spinSpeed, 0.0f, 100.0f, "%.0f" ); - - if ( ImGui::SliderFloat( "Suspension Hertz", &m_suspensionHertz, 0.0f, 10.0f, "%.1f" ) ) + if ( ImGui::SliderFloat( "Hertz##Suspension", &m_suspensionHertz, 0.0f, 10.0f, "%.1f" ) ) { b3WheelJoint_SetSuspensionHertz( m_frontLeftId, m_suspensionHertz ); b3WheelJoint_SetSuspensionHertz( m_frontRightId, m_suspensionHertz ); @@ -2620,7 +2467,7 @@ public: b3WheelJoint_SetSuspensionHertz( m_rearRightId, m_suspensionHertz ); } - if ( ImGui::SliderFloat( "Suspension Damping", &m_suspensionDampingRatio, 0.0f, 2.0f, "%.1f" ) ) + if ( ImGui::SliderFloat( "Damping##Suspension", &m_suspensionDampingRatio, 0.0f, 2.0f, "%.1f" ) ) { b3WheelJoint_SetSuspensionDampingRatio( m_frontLeftId, m_suspensionDampingRatio ); b3WheelJoint_SetSuspensionDampingRatio( m_frontRightId, m_suspensionDampingRatio ); @@ -2628,25 +2475,36 @@ public: b3WheelJoint_SetSuspensionDampingRatio( m_rearRightId, m_suspensionDampingRatio ); } - if ( ImGui::SliderFloat( "Steering Hertz", &m_steeringHertz, 0.0f, 10.0f, "%.1f" ) ) + ImGui::Separator(); + + ImGui::Text( "Motor" ); + + ImGui::SliderFloat( "Max Torque", &m_maxSpinTorque, 0.0f, 100.0f, "%.0f" ); + ImGui::SliderFloat( "Speed", &m_spinSpeed, 0.0f, 100.0f, "%.0f" ); + + ImGui::Separator(); + + ImGui::Text( "Steering" ); + + if ( ImGui::SliderFloat( "Hertz##Steering", &m_steeringHertz, 0.0f, 10.0f, "%.1f" ) ) { b3WheelJoint_SetSteeringHertz( m_frontLeftId, m_steeringHertz ); b3WheelJoint_SetSteeringHertz( m_frontRightId, m_steeringHertz ); } - if ( ImGui::SliderFloat( "Steering Damping", &m_steeringDampingRatio, 0.0f, 2.0f, "%.1f" ) ) + if ( ImGui::SliderFloat( "Damping##Steering", &m_steeringDampingRatio, 0.0f, 2.0f, "%.1f" ) ) { b3WheelJoint_SetSteeringDampingRatio( m_frontLeftId, m_steeringDampingRatio ); b3WheelJoint_SetSteeringDampingRatio( m_frontRightId, m_steeringDampingRatio ); } - if ( ImGui::SliderFloat( "Steering Torque", &m_maxSteeringTorque, 0.0f, 20.0f, "%.1f" ) ) + if ( ImGui::SliderFloat( "Torque##Steering", &m_maxSteeringTorque, 0.0f, 20.0f, "%.1f" ) ) { b3WheelJoint_SetMaxSteeringTorque( m_frontLeftId, m_maxSteeringTorque ); b3WheelJoint_SetMaxSteeringTorque( m_frontRightId, m_maxSteeringTorque ); } - if ( ImGui::SliderFloat( "Lower Degrees", &m_lowerSteeringDegrees, -90.0f, 0.0f, "%.0f" ) ) + if ( ImGui::SliderFloat( "Min Deg##Steering", &m_lowerSteeringDegrees, -90.0f, 0.0f, "%.0f" ) ) { b3WheelJoint_SetSteeringLimits( m_frontLeftId, B3_PI / 180.0f * m_lowerSteeringDegrees, B3_PI / 180.0f * m_upperSteeringDegrees ); @@ -2654,7 +2512,7 @@ public: B3_PI / 180.0f * m_upperSteeringDegrees ); } - if ( ImGui::SliderFloat( "Upper Degrees", &m_upperSteeringDegrees, 0.0f, 90.0f, "%.0f" ) ) + if ( ImGui::SliderFloat( "Max Deg##Steering", &m_upperSteeringDegrees, 0.0f, 90.0f, "%.0f" ) ) { b3WheelJoint_SetSteeringLimits( m_frontLeftId, B3_PI / 180.0f * m_lowerSteeringDegrees, B3_PI / 180.0f * m_upperSteeringDegrees ); @@ -2662,13 +2520,15 @@ public: B3_PI / 180.0f * m_upperSteeringDegrees ); } + ImGui::Separator(); + bool thirdPerson = m_camera->m_thirdPerson; - if ( ImGui::Checkbox( "Third Person (Key: T)", &thirdPerson ) ) + if ( ImGui::Checkbox( "Third Person (T)", &thirdPerson ) ) { ToggleThirdPerson(); } - ImGui::End(); + return true; } void Render() override @@ -2699,7 +2559,7 @@ public: b3Transform transform = b3Transform_identity; transform.p.y += 0.05f; - DrawTransform( m_scene, transform, 2.0f ); + DrawAxes( transform, 2.0f ); } void Step() override @@ -2708,25 +2568,25 @@ public: if ( m_camera->m_thirdPerson ) { - if ( glfwGetKey( m_window, GLFW_KEY_W ) ) + if ( IsKeyDown( KEY_W ) ) { throttle.x += 1.0f; b3Body_SetAwake( m_chassisId, true ); } - if ( glfwGetKey( m_window, GLFW_KEY_S ) ) + if ( IsKeyDown( KEY_S ) ) { throttle.x -= 1.0f; b3Body_SetAwake( m_chassisId, true ); } - if ( glfwGetKey( m_window, GLFW_KEY_A ) ) + if ( IsKeyDown( KEY_A ) ) { throttle.y += 1.0f; b3Body_SetAwake( m_chassisId, true ); } - if ( glfwGetKey( m_window, GLFW_KEY_D ) ) + if ( IsKeyDown( KEY_D ) ) { throttle.y -= 1.0f; b3Body_SetAwake( m_chassisId, true ); @@ -2780,4 +2640,4 @@ public: bool m_haveMouseLast; }; -static int sampleDriving = SampleManager::Register( "Joints", "Driving", Driving::Create ); +static int sampleDriving = RegisterSample( "Joints", "Driving", Driving::Create ); diff --git a/samples/sample_manifold.cpp b/samples/sample_manifold.cpp index 8f800f3..34e5468 100644 --- a/samples/sample_manifold.cpp +++ b/samples/sample_manifold.cpp @@ -1,12 +1,12 @@ // SPDX-FileCopyrightText: 2025 Erin Catto // SPDX-License-Identifier: MIT -#include "GLFW/glfw3.h" -#include "camera.h" -#include "renderer.h" #include "sample.h" -#include "scene.h" +#include "gfx/draw.h" +#include "gfx/keycodes.h" + +#include "box3d/box3d.h" #include "box3d/constants.h" #include @@ -54,7 +54,7 @@ public: DrawTextLine( "origin: %g %g %g", m_origin.x, m_origin.y, m_origin.z ); DrawTextLine( "count = %d", m_manifold.pointCount ); - DrawTransform( m_scene, b3Transform_identity, 1.0f ); + DrawAxes( b3Transform_identity, 1.0f ); if ( m_manifold.pointCount == 0 ) { @@ -70,35 +70,34 @@ public: b3Vec3 point = b3TransformPoint( m_transformA, manifoldPoint.point ); - DrawLine( m_scene, point, point + length * normal, b3_colorWhite ); + DrawLine( point, point + length * normal, MakeColor( b3_colorWhite ) ); if ( manifoldPoint.separation > 0.0f ) { - DrawPoint( m_scene, point, 10.0f, b3_colorWhite ); + DrawPoint( point, 10.0f, MakeColor( b3_colorWhite ) ); } else { - DrawPoint( m_scene, point, 10.0f, b3_colorYellow ); + DrawPoint( point, 10.0f, MakeColor( b3_colorYellow ) ); } - DrawWorldString( m_camera, point, b3_colorWhite, " %.3f", manifoldPoint.separation ); + DrawWorldString( point, MakeColor( b3_colorWhite ), " %.3f", manifoldPoint.separation ); b3Vec3 perp = b3Perp( normal ); b3FeaturePair pair = manifoldPoint.pair; - DrawWorldString( m_camera, point + 0.025f * normal + 0.05f * perp, b3_colorPapayaWhip, " %X:%X %X:%X", pair.owner1, - pair.index1, pair.owner2, pair.index2 ); + DrawWorldString( point + 0.025f * normal + 0.05f * perp, MakeColor( b3_colorPapayaWhip ), " %X:%X %X:%X", pair.owner1, pair.index1, pair.owner2, pair.index2 ); } Sample::Render(); } - void UpdateUI() override + bool HasSolverControls() const override + { + return false; + } + + bool DrawControls() override { - float fontSize = ImGui::GetFontSize(); - float height = 12.0f * fontSize; - ImGui::SetNextWindowPos( ImVec2( 0.5f * fontSize, m_camera->m_height - height - 2.0f * fontSize ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 10.0f * fontSize, height ) ); - ImGui::Begin( "Manifold", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize ); ImGui::Checkbox( "Use cache", &m_useCache ); if ( m_useCache ) { @@ -108,14 +107,14 @@ public: ImGui::RadioButton( "edgePair", &m_manualFeature, 3 ); } - ImGui::End(); + return true; } void MouseDown( b3Vec2 p, int button, int modifiers ) override { - if ( button == 0 && ( modifiers & GLFW_MOD_ALT ) == 0 ) + if ( button == 0 && ( modifiers & MOD_ALT ) == 0 ) { - if ( modifiers & GLFW_MOD_SHIFT ) + if ( modifiers & MOD_SHIFT ) { m_baseX = p.x; m_baseY = p.y; @@ -222,7 +221,7 @@ public: DrawTextLine( "feature = %d", m_manifold.feature ); DrawTextLine( "cache hit = %d", m_satCache.hit ); - DrawTransform( m_scene, b3Transform_identity, 1.0f ); + DrawAxes( b3Transform_identity, 1.0f ); if ( m_manifold.pointCount > 0 ) { @@ -234,49 +233,47 @@ public: b3Vec3 point = manifoldPoint.point; - DrawLine( m_scene, point, point + length * m_manifold.normal, b3_colorWhite ); + DrawLine( point, point + length * m_manifold.normal, MakeColor( b3_colorWhite ) ); if ( manifoldPoint.separation > 0.0f ) { - DrawPoint( m_scene, point, 10.0f, b3_colorWhite ); + DrawPoint( point, 10.0f, MakeColor( b3_colorWhite ) ); } else { - DrawPoint( m_scene, point, 10.0f, b3_colorYellow ); + DrawPoint( point, 10.0f, MakeColor( b3_colorYellow ) ); } - DrawWorldString( m_camera, point, b3_colorWhite, " %.2f", 100.0f * manifoldPoint.separation ); + DrawWorldString( point, MakeColor( b3_colorWhite ), " %.2f", 100.0f * manifoldPoint.separation ); b3FeaturePair pair = manifoldPoint.pair; - DrawWorldString( m_camera, point + 0.025f * m_manifold.normal, b3_colorPapayaWhip, " %X:%X %X:%X", pair.owner1, - pair.index1, pair.owner2, pair.index2 ); + DrawWorldString( point + 0.025f * m_manifold.normal, MakeColor( b3_colorPapayaWhip ), " %X:%X %X:%X", pair.owner1, pair.index1, pair.owner2, pair.index2 ); } } b3Vec3 p1 = b3TransformPoint( m_transformA, m_triangle[0] ); b3Vec3 p2 = b3TransformPoint( m_transformA, m_triangle[1] ); b3Vec3 p3 = b3TransformPoint( m_transformA, m_triangle[2] ); - DrawFace( m_scene, p1, p2, p3, b3_colorCyan ); + DrawTriangle( p1, p2, p3, MakeColor( b3_colorCyan ) ); - DrawWorldString( m_camera, p1, b3_colorWhite, "0" ); - DrawWorldString( m_camera, p2, b3_colorWhite, "1" ); - DrawWorldString( m_camera, p3, b3_colorWhite, "2" ); + DrawWorldString( p1, MakeColor( b3_colorWhite ), "0" ); + DrawWorldString( p2, MakeColor( b3_colorWhite ), "1" ); + DrawWorldString( p3, MakeColor( b3_colorWhite ), "2" ); b3Vec3 center = 1.0f / 3.0f * ( p1 + p2 + p3 ); b3Vec3 normal = b3Normalize( b3Cross( p2 - p1, p3 - p1 ) ); - DrawArrow( m_scene, center, center + 0.5f * normal, 0.05f, b3_colorMediumPurple ); + DrawArrow( center, center + 0.5f * normal, MakeColor( b3_colorMediumPurple ) ); Sample::Render(); } - void UpdateUI() override + bool HasSolverControls() const override { - float fontSize = ImGui::GetFontSize(); - float height = 12.0f * fontSize; - ImGui::SetNextWindowPos( ImVec2( 0.5f * fontSize, m_camera->m_height - height - 2.0f * fontSize ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 10.0f * fontSize, height ) ); + return false; + } - ImGui::Begin( "Triangle Manifold", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize ); + bool DrawControls() override + { ImGui::Checkbox( "Use cache", &m_useCache ); if ( m_useCache ) { @@ -286,14 +283,14 @@ public: ImGui::RadioButton( "edgePair", &m_manualFeature, 3 ); } - ImGui::End(); + return true; } void MouseDown( b3Vec2 p, int button, int modifiers ) override { - if ( button == 0 && ( modifiers & GLFW_MOD_ALT ) == 0 ) + if ( button == 0 && ( modifiers & MOD_ALT ) == 0 ) { - if ( modifiers & GLFW_MOD_SHIFT ) + if ( modifiers & MOD_SHIFT ) { m_baseX = p.x; m_baseY = p.y; @@ -366,8 +363,8 @@ public: void Render() override { - DrawSphere( m_scene, m_transformA, m_sphere, b3_colorGreen ); - DrawSphere( m_scene, m_transformB, m_sphere, b3_colorCyan ); + DrawSolidSphere( m_transformA, m_sphere, MakeColor( b3_colorGreen ) ); + DrawSolidSphere( m_transformB, m_sphere, MakeColor( b3_colorCyan ) ); Manifold::Render(); } @@ -386,7 +383,7 @@ public: b3Sphere m_sphere; }; -static int sampleCollideSpheres = SampleManager::Register( "Manifold", "Sphere vs Sphere", SphereAndSphere::Create ); +static int sampleCollideSpheres = RegisterSample( "Manifold", "Sphere vs Sphere", SphereAndSphere::Create ); class CapsuleAndSphere : public Manifold { @@ -408,8 +405,8 @@ public: void Render() override { - DrawCapsule( m_scene, m_transformA, m_capsule, b3_colorCyan ); - DrawSphere( m_scene, m_transformB, m_sphere, b3_colorGreen ); + DrawSolidCapsule( m_transformA, m_capsule, MakeColor( b3_colorCyan ) ); + DrawSolidSphere( m_transformB, m_sphere, MakeColor( b3_colorGreen ) ); Manifold::Render(); } @@ -424,7 +421,7 @@ public: b3Capsule m_capsule; }; -static int sampleSphereAndCapsule = SampleManager::Register( "Manifold", "Capsule vs Sphere", CapsuleAndSphere::Create ); +static int sampleSphereAndCapsule = RegisterSample( "Manifold", "Capsule vs Sphere", CapsuleAndSphere::Create ); class HullAndSphere : public Manifold { @@ -441,8 +438,8 @@ public: void Render() override { - DrawHull( m_scene, m_transformA, &m_hull.base, b3_colorCyan, false ); - DrawSphere( m_scene, m_transformB, m_sphere, b3_colorGreen ); + DrawHull( m_transformA, &m_hull.base, MakeColor( b3_colorCyan ) ); + DrawSolidSphere( m_transformB, m_sphere, MakeColor( b3_colorGreen ) ); Manifold::Render(); } @@ -467,7 +464,7 @@ public: b3BoxHull m_hull; }; -static int sampleSphereAndHull = SampleManager::Register( "Manifold", "Hull vs Sphere", HullAndSphere::Create ); +static int sampleSphereAndHull = RegisterSample( "Manifold", "Hull vs Sphere", HullAndSphere::Create ); class TriangleAndSphere : public TriangleManifold { @@ -499,7 +496,7 @@ public: void Render() override { - DrawSphere( m_scene, m_transformB, m_sphere, b3_colorGreen ); + DrawSolidSphere( m_transformB, m_sphere, MakeColor( b3_colorGreen ) ); TriangleManifold::Render(); } @@ -527,7 +524,7 @@ public: b3Sphere m_sphere; }; -static int sampleSphereAndTriangle = SampleManager::Register( "Manifold", "Triangle vs Sphere", TriangleAndSphere::Create ); +static int sampleSphereAndTriangle = RegisterSample( "Manifold", "Triangle vs Sphere", TriangleAndSphere::Create ); class CapsuleAndCapsule : public Manifold { @@ -543,8 +540,8 @@ public: void Render() override { - DrawCapsule( m_scene, m_transformA, m_capsule, b3_colorGreen ); - DrawCapsule( m_scene, m_transformB, m_capsule, b3_colorCyan ); + DrawSolidCapsule( m_transformA, m_capsule, MakeColor( b3_colorGreen ) ); + DrawSolidCapsule( m_transformB, m_capsule, MakeColor( b3_colorCyan ) ); Manifold::Render(); } @@ -563,7 +560,7 @@ public: b3Capsule m_capsule; }; -static int sampleCapsuleAndCapsule = SampleManager::Register( "Manifold", "Capsule vs Capsule", CapsuleAndCapsule::Create ); +static int sampleCapsuleAndCapsule = RegisterSample( "Manifold", "Capsule vs Capsule", CapsuleAndCapsule::Create ); class CapsuleAndHull : public Manifold { @@ -596,8 +593,8 @@ public: void Render() override { - DrawHull( m_scene, m_transformA, &m_hull.base, b3_colorCyan, false ); - DrawCapsule( m_scene, m_transformB, m_capsule, b3_colorGreen ); + DrawHull( m_transformA, &m_hull.base, MakeColor( b3_colorCyan ) ); + DrawSolidCapsule( m_transformB, m_capsule, MakeColor( b3_colorGreen ) ); Manifold::Render(); } @@ -622,7 +619,7 @@ public: b3Capsule m_capsule; }; -static int sampleCapsuleAndHull = SampleManager::Register( "Manifold", "Capsule vs Hull", CapsuleAndHull::Create ); +static int sampleCapsuleAndHull = RegisterSample( "Manifold", "Capsule vs Hull", CapsuleAndHull::Create ); class TriangleAndCapsule : public TriangleManifold { @@ -655,8 +652,8 @@ public: void Render() override { - DrawCapsule( m_scene, m_transformB, m_capsule, b3_colorGreen ); - DrawTransform( m_scene, m_transformB, 0.1f ); + DrawSolidCapsule( m_transformB, m_capsule, MakeColor( b3_colorGreen ) ); + DrawAxes( m_transformB, 0.1f ); TriangleManifold::Render(); } @@ -689,7 +686,7 @@ public: b3Capsule m_capsule; }; -static int sampleCapsuleAndTriangle = SampleManager::Register( "Manifold", "Triangle vs Capsule", TriangleAndCapsule::Create ); +static int sampleCapsuleAndTriangle = RegisterSample( "Manifold", "Triangle vs Capsule", TriangleAndCapsule::Create ); class HullAndHull : public Manifold { @@ -749,13 +746,13 @@ public: } } - b3Hull* CreateConvex( float radius1, float height1, float radius2, float height2, Arena arena ) const + b3Hull* CreateConvex( float radius1, float height1, float radius2, float height2 ) const { - const int sideCount = 32; + constexpr int sideCount = 32; const float deltaAlpha = 2.0f * B3_PI / sideCount; int vertexCount = 2 * sideCount; - b3Vec3* vertexBase = static_cast( arena.Allocate( vertexCount * sizeof( b3Vec3 ) ) ); + b3Vec3 vertexBase[2 * sideCount]; float alpha = 0.0f; for ( int sideIndex = 0; sideIndex < sideCount; ++sideIndex ) @@ -777,8 +774,8 @@ public: void Render() override { - DrawHull( m_scene, m_transformA, m_hullA, b3_colorGreen, false ); - DrawHull( m_scene, m_transformB, m_hullB, b3_colorCyan, false ); + DrawHull( m_transformA, m_hullA, MakeColor( b3_colorGreen ) ); + DrawHull( m_transformB, m_hullB, MakeColor( b3_colorCyan ) ); Manifold::Render(); } @@ -822,7 +819,7 @@ public: b3Hull* m_hullB; }; -static int sampleCollideHulls = SampleManager::Register( "Manifold", "Hull vs Hull", HullAndHull::Create ); +static int sampleCollideHulls = RegisterSample( "Manifold", "Hull vs Hull", HullAndHull::Create ); class TriangleAndHull : public TriangleManifold { @@ -882,12 +879,12 @@ public: void Render() override { - DrawHull( m_scene, m_transformB, m_hull, b3_colorGreen, false ); + DrawHull( m_transformB, m_hull, MakeColor( b3_colorGreen ) ); b3Transform xf; xf.p = b3TransformPoint( m_transformB, m_hull->center ); xf.q = m_transformB.q; - DrawTransform( m_scene, xf, 0.1f ); + DrawAxes( xf, 0.1f ); TriangleManifold::Render(); } @@ -938,4 +935,4 @@ public: b3Hull* m_hull; }; -static int sampleHullAndTriangle = SampleManager::Register( "Manifold", "Triangle vs Hull", TriangleAndHull::Create ); +static int sampleHullAndTriangle = RegisterSample( "Manifold", "Triangle vs Hull", TriangleAndHull::Create ); diff --git a/samples/sample_mesh.cpp b/samples/sample_mesh.cpp index b5c175d..3f67760 100644 --- a/samples/sample_mesh.cpp +++ b/samples/sample_mesh.cpp @@ -1,12 +1,12 @@ // SPDX-FileCopyrightText: 2025 Erin Catto // SPDX-License-Identifier: MIT -#include "camera.h" #include "human.h" #include "mesh_loader.h" -#include "renderer.h" #include "sample.h" -#include "scene.h" +#include "gfx/draw.h" + +#include "gfx/debug_adapter.h" #include "box3d/box3d.h" @@ -55,7 +55,7 @@ public: Spawn(); - m_context->debugDraw.forceScale = 0.01f; + GetGuiDraw()->forceScale = 0.01f; } ~GridMesh() override @@ -125,13 +125,8 @@ public: } } - void UpdateUI() override + bool DrawControls() override { - float height = 220.0f; - ImGui::SetNextWindowPos( ImVec2( 10.0f, m_camera->m_height - height - 50.0f ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 280.0f, height ) ); - ImGui::Begin( "Mesh Grid", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize ); - if ( ImGui::RadioButton( "Sphere", m_shapeType == ShapeType::sphere ) ) { m_shapeType = ShapeType::sphere; @@ -167,7 +162,7 @@ public: b3Shape_SetMesh( m_gridShapeId, m_gridMesh, m_scale ); } - ImGui::End(); + return true; } void Render() override @@ -176,7 +171,7 @@ public: DrawTextLine( "triangle count = %d, bytes = %d", m_gridMesh->triangleCount, m_gridMesh->byteCount ); b3Transform transform = { { 0.0f, 0.01f, 0.0f }, b3Quat_identity }; - DrawTransform( m_scene, transform, 1.0f ); + DrawAxes( transform, 1.0f ); } void Step() override @@ -210,7 +205,7 @@ public: b3Vec3 m_scale; }; -static int sampleGridMesh = SampleManager::Register( "Mesh", "Grid", GridMesh::Create ); +static int sampleGridMesh = RegisterSample( "Mesh", "Grid", GridMesh::Create ); class BigBoxMesh : public Sample { @@ -306,13 +301,8 @@ public: } } - void UpdateUI() override + bool DrawControls() override { - float height = 220.0f; - ImGui::SetNextWindowPos( ImVec2( 10.0f, m_camera->m_height - height - 50.0f ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 280.0f, height ) ); - ImGui::Begin( "Mesh Grid", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize ); - if ( ImGui::RadioButton( "Sphere", m_shapeType == ShapeType::sphere ) ) { m_shapeType = ShapeType::sphere; @@ -348,14 +338,14 @@ public: b3Shape_SetMesh( m_gridShapeId, m_boxMesh, m_scale ); } - ImGui::End(); + return true; } void Render() override { Sample::Render(); b3Transform transform = { { 0.0f, 0.01f, 0.0f }, b3Quat_identity }; - DrawTransform( m_scene, transform, 1.0f ); + DrawAxes( transform, 1.0f ); } void Step() override @@ -389,7 +379,7 @@ public: b3Vec3 m_scale; }; -static int sampleBigBoxMesh = SampleManager::Register( "Mesh", "Big Box", BigBoxMesh::Create ); +static int sampleBigBoxMesh = RegisterSample( "Mesh", "Big Box", BigBoxMesh::Create ); class BoxMesh : public Sample { @@ -400,17 +390,17 @@ public: if ( m_context->restart == false ) { m_camera->SetView( 45.0f, 30.0f, 6.0f, b3Vec3_zero ); - EnableGrid( m_scene, true ); + } + AddGroundBox( 20.0f ); + b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.position = { 0.0f, -1.0f, 0.0f }; bodyDef.rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisY, 0.25f * B3_PI ); b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull box = b3MakeBoxHull( 20.0f, 1.0f, 20.0f ); - b3CreateHullShape( groundId, &shapeDef, &box.base ); m_boxMesh = b3CreateBoxMesh( { 0.0f, 1.0f, 0.0f }, { 1.0f, 1.0f, 1.0f }, true ); // m_scale = { -0.6f, 1.0f, 2.0f }; @@ -487,13 +477,8 @@ public: } } - void UpdateUI() override + bool DrawControls() override { - float height = 220.0f; - ImGui::SetNextWindowPos( ImVec2( 10.0f, m_camera->m_height - height - 50.0f ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 280.0f, height ) ); - ImGui::Begin( "Box Mesh", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize ); - if ( ImGui::RadioButton( "Sphere", m_shapeType == ShapeType::sphere ) ) { m_shapeType = ShapeType::sphere; @@ -529,14 +514,7 @@ public: b3Shape_SetMesh( m_boxShapeId, m_boxMesh, m_scale ); } - ImGui::End(); - } - - void Render() override - { - Sample::Render(); - b3Transform transform = { { 0.0f, 0.1f, 0.0f }, b3Quat_identity }; - DrawTransform( m_scene, transform, 2.0f ); + return true; } void Step() override @@ -570,7 +548,7 @@ public: b3Vec3 m_scale; }; -static int sampleBoxMesh = SampleManager::Register( "Mesh", "Box", BoxMesh::Create ); +static int sampleBoxMesh = RegisterSample( "Mesh", "Box", BoxMesh::Create ); class MeshReflection : public Sample { @@ -682,12 +660,8 @@ public: } } - void UpdateUI() override + bool DrawControls() override { - ImGui::SetNextWindowPos( ImVec2( 10.0f, 600.0f ) ); - ImGui::SetNextWindowSize( ImVec2( 200.0f, 150.0f ) ); - ImGui::Begin( "Mesh Reflection", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize ); - bool changed = false; b3Vec3 scale = m_scale; if ( ImGui::RadioButton( "Neg X", scale.x < 0.0f ) ) @@ -739,7 +713,7 @@ public: b3Shape_SetMesh( m_meshShapeId, m_buildingMesh, m_scale ); } - ImGui::End(); + return true; } void Render() override @@ -763,7 +737,7 @@ public: Human m_humans[e_humanCount]; }; -static int sampleMeshReflection = SampleManager::Register( "Mesh", "Reflection", MeshReflection::Create ); +static int sampleMeshReflection = RegisterSample( "Mesh", "Reflection", MeshReflection::Create ); struct CastContext { @@ -883,16 +857,9 @@ public: #endif } - void UpdateUI() override + bool DrawControls() override { - float fontSize = ImGui::GetFontSize(); - float height = 18.0f * fontSize; - ImGui::SetNextWindowPos( { 1.0f * fontSize, m_camera->m_height - height - 3.0f * fontSize }, ImGuiCond_Once ); - ImGui::SetNextWindowSize( { 40.0f * fontSize, height } ); - - ImGui::Begin( "Height Field", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize ); - - ImGui::PushItemWidth( 500.0f ); + ImGui::PushItemWidth( 6.0f * ImGui::GetFontSize() ); if ( ImGui::SliderInt( "columns", &m_columnCount, 1, 500 ) ) { @@ -925,14 +892,14 @@ public: ImGui::SliderFloat( "radius", &m_radius, 0.0f, 1.0f ); ImGui::PopItemWidth(); - ImGui::End(); + return true; } void Render() override { Sample::Render(); b3Transform transform = { { 0.0f, 0.1f, 0.0f }, b3Quat_identity }; - DrawTransform( m_scene, transform, 0.5f ); + DrawAxes( transform, 0.5f ); } // This callback finds the closest hit. @@ -968,15 +935,15 @@ public: b3RayResult result = b3World_CastRayClosest( m_worldId, m_rayOrigin, m_rayTranslation, b3DefaultQueryFilter() ); - DrawPoint( m_scene, m_rayOrigin, 6.0f, b3_colorGreenYellow ); - DrawPoint( m_scene, m_rayOrigin + m_rayTranslation, 6.0f, b3_colorRed ); - DrawLine( m_scene, m_rayOrigin, m_rayOrigin + m_rayTranslation, b3_colorGray ); + DrawPoint( m_rayOrigin, 6.0f, MakeColor( b3_colorGreenYellow ) ); + DrawPoint( m_rayOrigin + m_rayTranslation, 6.0f, MakeColor( b3_colorRed ) ); + DrawLine( m_rayOrigin, m_rayOrigin + m_rayTranslation, MakeColor( b3_colorGray ) ); if ( result.hit ) { b3Vec3 point = result.point; - DrawLine( m_scene, point, point + 0.5f * result.normal, b3_colorGray ); - DrawPoint( m_scene, point, 10.0f, b3_colorOrange ); + DrawLine( point, point + 0.5f * result.normal, MakeColor( b3_colorGray ) ); + DrawPoint( point, 10.0f, MakeColor( b3_colorOrange ) ); } } else @@ -992,18 +959,18 @@ public: b3World_CastShape( m_worldId, &proxy, m_rayTranslation, b3DefaultQueryFilter(), CastCallback, &result ); - DrawPoint( m_scene, m_rayOrigin, 2.0f, b3_colorGreen ); - DrawPoint( m_scene, m_rayOrigin + m_rayTranslation, 2.0f, b3_colorRed ); - DrawLine( m_scene, m_rayOrigin, m_rayOrigin + m_rayTranslation, b3_colorYellow ); + DrawPoint( m_rayOrigin, 2.0f, MakeColor( b3_colorGreen ) ); + DrawPoint( m_rayOrigin + m_rayTranslation, 2.0f, MakeColor( b3_colorRed ) ); + DrawLine( m_rayOrigin, m_rayOrigin + m_rayTranslation, MakeColor( b3_colorYellow ) ); b3Sphere sphere = { b3Vec3_zero, m_radius }; - DrawSphere( m_scene, { m_rayOrigin + result.fraction * m_rayTranslation, b3Quat_identity }, sphere, b3_colorOrange ); + DrawSolidSphere( { m_rayOrigin + result.fraction * m_rayTranslation, b3Quat_identity }, sphere, MakeColor( b3_colorOrange ) ); if ( result.hit ) { b3Vec3 point = result.point; - DrawLine( m_scene, point, point + 0.5f * result.normal, b3_colorGreen ); - DrawPoint( m_scene, point, 6.0f, b3_colorPurple ); + DrawLine( point, point + 0.5f * result.normal, MakeColor( b3_colorGreen ) ); + DrawPoint( point, 6.0f, MakeColor( b3_colorPurple ) ); } } } @@ -1022,7 +989,7 @@ public: bool m_holes; }; -static int sampleHeightField = SampleManager::Register( "Mesh", "Height Field", HeightField::Create ); +static int sampleHeightField = RegisterSample( "Mesh", "Height Field", HeightField::Create ); static float ComputeInternalSurfaceArea( const b3MeshData* data ) { @@ -1178,25 +1145,25 @@ public: node->lowerBound, node->upperBound, }; - DrawBounds( m_scene, box, 0.0f, colors[level % colorCount] ); + DrawBounds( box, 0.0f, MakeColor( colors[level % colorCount] ) ); int axis = node->data.asNode.axis; b3Vec3 center = b3AABB_Center( box ); if ( axis == 0 ) { - DrawArrow( m_scene, center, center + 0.1f * b3Vec3_axisX, 0.02f, b3_colorRed ); + DrawArrow( center, center + 0.1f * b3Vec3_axisX, MakeColor( b3_colorRed ) ); } else if ( axis == 1 ) { - DrawArrow( m_scene, center, center + 0.1f * b3Vec3_axisY, 0.02f, b3_colorGreen ); + DrawArrow( center, center + 0.1f * b3Vec3_axisY, MakeColor( b3_colorGreen ) ); } else if ( axis == 2 ) { - DrawArrow( m_scene, center, center + 0.1f * b3Vec3_axisZ, 0.02f, b3_colorBlue ); + DrawArrow( center, center + 0.1f * b3Vec3_axisZ, MakeColor( b3_colorBlue ) ); } else { - DrawSphere( m_scene, b3Transform_identity, { center, 0.03f }, b3_colorOrange ); + DrawSolidSphere( b3Transform_identity, { center, 0.03f }, MakeColor( b3_colorOrange ) ); } } @@ -1217,15 +1184,8 @@ public: } } - void UpdateUI() override + bool DrawControls() override { - float fontSize = ImGui::GetFontSize(); - float height = 14.0f * fontSize; - ImGui::SetNextWindowPos( { 1.0f * fontSize, m_camera->m_height - height - 3.0f * fontSize }, ImGuiCond_Once ); - ImGui::SetNextWindowSize( { 20.0f * fontSize, height } ); - - ImGui::Begin( "Mesh Viewer", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize ); - if ( ImGui::SliderInt( "index", &m_meshIndex, 0, m_meshCount - 1 ) ) { LoadMesh(); @@ -1259,13 +1219,13 @@ public: } ImGui::SliderInt( "draw level", &m_drawLevel, -1, m_height ); - ImGui::End(); + return true; } void Render() override { Sample::Render(); - DrawTransform( m_scene, b3Transform_identity, 1.0f ); + DrawAxes( b3Transform_identity, 1.0f ); DrawTextLine( "triangle count = %d", m_mesh->triangleCount ); DrawTextLine( "vertex count = %d", m_mesh->vertexCount ); @@ -1291,18 +1251,18 @@ public: (void)area; b3Vec3 p = ( 1.0f / 3.0f ) * ( v1 + v2 + v3 ); - DrawPoint( m_scene, p, 10.0f, b3_colorCyan ); + DrawPoint( p, 10.0f, MakeColor( b3_colorCyan ) ); - DrawWorldString( m_camera, p + offset, b3_colorOrange, "%d", triangleIndex ); + DrawWorldString( p + offset, MakeColor( b3_colorOrange ), "%d", triangleIndex ); { - DrawPoint( m_scene, v1, 10.0f, b3_colorRed ); - DrawPoint( m_scene, v2, 10.0f, b3_colorGreen ); - DrawPoint( m_scene, v3, 10.0f, b3_colorBlue ); + DrawPoint( v1, 10.0f, MakeColor( b3_colorRed ) ); + DrawPoint( v2, 10.0f, MakeColor( b3_colorGreen ) ); + DrawPoint( v3, 10.0f, MakeColor( b3_colorBlue ) ); - DrawWorldString( m_camera, v1 + offset, b3_colorRed, "%d", i1 ); - DrawWorldString( m_camera, v2 + offset, b3_colorGreen, "%d", i2 ); - DrawWorldString( m_camera, v3 + offset, b3_colorBlue, "%d", i3 ); + DrawWorldString( v1 + offset, MakeColor( b3_colorRed ), "%d", i1 ); + DrawWorldString( v2 + offset, MakeColor( b3_colorGreen ), "%d", i2 ); + DrawWorldString( v3 + offset, MakeColor( b3_colorBlue ), "%d", i3 ); } } } @@ -1329,7 +1289,7 @@ public: bool m_weldVertices; }; -static int sampleMeshViewer = SampleManager::Register( "Mesh", "Viewer", MeshViewer::Create ); +static int sampleMeshViewer = RegisterSample( "Mesh", "Viewer", MeshViewer::Create ); // Results 9/29/25 // base median split: 0.222 ms per mesh @@ -1410,7 +1370,7 @@ public: float m_time; }; -static int sampleMeshCreationBenchmark = SampleManager::Register( "Mesh", "Creation Benchmark", MeshCreationBenchmark::Create ); +static int sampleMeshCreationBenchmark = RegisterSample( "Mesh", "Creation Benchmark", MeshCreationBenchmark::Create ); class VoxelMesh : public Sample { @@ -1526,7 +1486,7 @@ public: Human m_human; }; -static int sampleVoxelMesh = SampleManager::Register( "Mesh", "Voxel", VoxelMesh::Create ); +static int sampleVoxelMesh = RegisterSample( "Mesh", "Voxel", VoxelMesh::Create ); // Pause this to check contact manifolds for axis aligned collisions. class HollowBox : public Sample @@ -1537,7 +1497,7 @@ public: { if ( m_context->restart == false ) { - m_camera->SetView( 45.0f, 30.0f, 6.0f, b3Vec3_zero ); + m_camera->SetView( 45.0f, 30.0f, 30.0f, b3Vec3_zero ); } { @@ -1601,7 +1561,7 @@ public: Sample::Render(); b3Transform transform = { { 0.0f, 0.01f, 0.0f }, b3Quat_identity }; - DrawTransform( m_scene, transform, 1.0f ); + DrawAxes( transform, 1.0f ); } void Step() override @@ -1617,4 +1577,4 @@ public: b3MeshData* m_mesh; }; -static int sampleHollowBox = SampleManager::Register( "Mesh", "Hollow Box", HollowBox::Create ); +static int sampleHollowBox = RegisterSample( "Mesh", "Hollow Box", HollowBox::Create ); diff --git a/samples/sample_ragdoll.cpp b/samples/sample_ragdoll.cpp index 86b31d2..af30f69 100644 --- a/samples/sample_ragdoll.cpp +++ b/samples/sample_ragdoll.cpp @@ -1,11 +1,10 @@ // SPDX-FileCopyrightText: 2025 Erin Catto // SPDX-License-Identifier: MIT -#include "camera.h" #include "human.h" #include "imgui.h" #include "sample.h" -#include "scene.h" +#include "gfx/draw.h" #include "box3d/box3d.h" @@ -18,18 +17,9 @@ public: if ( context->restart == false ) { m_camera->SetView( 45.0f, 30.0f, 6.0f, b3Vec3_zero ); - EnableGrid( m_scene, true ); } - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull box = b3MakeBoxHull( 10.0f, 1.0f, 10.0f ); - b3CreateHullShape( groundId, &shapeDef, &box.base ); - } + AddGroundBox( 20.0f ); m_jointFrictionTorque = 5.0f; m_jointHertz = 1.0f; @@ -47,14 +37,9 @@ public: // Human_ApplyRandomAngularImpulse( &m_human, 10.0f ); } - void UpdateUI() override + bool DrawControls() override { - float height = 140.0f; - ImGui::SetNextWindowPos( ImVec2( 10.0f, m_camera->m_height - height - 50.0f ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 350.0f, height ) ); - - ImGui::Begin( "Ragdoll on Box", nullptr, ImGuiWindowFlags_NoResize ); - ImGui::PushItemWidth( 200.0f ); + ImGui::PushItemWidth( 6.0f * ImGui::GetFontSize() ); if ( ImGui::SliderFloat( "Joint Friction", &m_jointFrictionTorque, 0.0f, 20.0f, "%3.0f" ) ) { @@ -77,7 +62,7 @@ public: Spawn(); } ImGui::PopItemWidth(); - ImGui::End(); + return true; } static Sample* Create( SampleContext* context ) @@ -91,7 +76,7 @@ public: float m_jointDampingRatio; }; -static int sampleRagdollOnBox = SampleManager::Register( "Ragdoll", "Box", RagdollOnBox::Create ); +static int sampleRagdollOnBox = RegisterSample( "Ragdoll", "Box", RagdollOnBox::Create ); class RagdollOnMesh : public Sample { @@ -176,14 +161,9 @@ public: Human_CreateParallelAnchors( &m_human, m_worldId ); } - void UpdateUI() override + bool DrawControls() override { - float height = 140.0f; - ImGui::SetNextWindowPos( ImVec2( 10.0f, m_camera->m_height - height - 50.0f ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 350.0f, height ) ); - - ImGui::Begin( "Ragdoll", nullptr, ImGuiWindowFlags_NoResize ); - ImGui::PushItemWidth( 200.0f ); + ImGui::PushItemWidth( 6.0f * ImGui::GetFontSize() ); if ( ImGui::SliderFloat( "Joint Friction", &m_jointFrictionTorque, 0.0f, 20.0f, "%3.0f" ) ) { @@ -206,7 +186,7 @@ public: Spawn(); } ImGui::PopItemWidth(); - ImGui::End(); + return true; } static Sample* Create( SampleContext* context ) @@ -222,7 +202,7 @@ public: float m_jointDampingRatio; }; -static int sampleRagdollMesh = SampleManager::Register( "Ragdoll", "Mesh", RagdollOnMesh::Create ); +static int sampleRagdollMesh = RegisterSample( "Ragdoll", "Mesh", RagdollOnMesh::Create ); class RagdollPile : public Sample { @@ -279,7 +259,7 @@ public: Human m_humans[e_count] = {}; }; -static int sampleRagdollPile = SampleManager::Register( "Ragdoll", "Pile", RagdollPile::Create ); +static int sampleRagdollPile = RegisterSample( "Ragdoll", "Pile", RagdollPile::Create ); class RagdollIncline : public Sample { @@ -354,7 +334,7 @@ public: bool m_motorized; }; -static int sampleRagdollIncline = SampleManager::Register( "Ragdoll", "Incline", RagdollIncline::Create ); +static int sampleRagdollIncline = RegisterSample( "Ragdoll", "Incline", RagdollIncline::Create ); #if 0 class RagdollPose : public Sample @@ -480,5 +460,5 @@ public: bool m_poseControl; }; -static int sampleRagodllPose = SampleManager::Register( "Ragdoll", "Pose", RagdollPose::Create ); +static int sampleRagodllPose = RegisterSample( "Ragdoll", "Pose", RagdollPose::Create ); #endif diff --git a/samples/sample_robustness.cpp b/samples/sample_robustness.cpp index 0fa8887..af846e0 100644 --- a/samples/sample_robustness.cpp +++ b/samples/sample_robustness.cpp @@ -1,13 +1,13 @@ // SPDX-FileCopyrightText: 2025 Erin Catto // SPDX-License-Identifier: MIT -#include "camera.h" #include "overflow_color.h" #include "sample.h" -#include "scene.h" +#include "gfx/draw.h" #include "box3d/box3d.h" #include "box3d/constants.h" +#include "gfx/debug_adapter.h" #include #include @@ -21,20 +21,14 @@ public: { if ( m_context->restart == false ) { - m_camera->SetView( 45.0f, 20.0f, 50.0f, b3Vec3_zero ); - EnableGrid( m_scene, true ); + m_camera->SetView( 30.0f, 15.0f, 70.0f, b3Vec3_zero ); + } + AddGroundBox( 50.0f ); + float extent = 1.0f; - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull box = b3MakeTransformedBoxHull( 50.0f, 1.0f, 50.0f, { { 0.0f, -1.0f, 0.0f }, b3Quat_identity } ); - b3CreateHullShape( groundId, &shapeDef, &box.base ); - } - { b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.type = b3_dynamicBody; @@ -73,7 +67,7 @@ public: } }; -static int sampleHighMassRatio1 = SampleManager::Register( "Robustness", "HighMassRatio1", HighMassRatio1::Create ); +static int sampleHighMassRatio1 = RegisterSample( "Robustness", "HighMassRatio1", HighMassRatio1::Create ); // A pyramid of 5cm boxes. Stacking tiny objects is challenging for physics engines due to rotational effects. // This is also challenging for Box3D because of the AABB margin and linear slop are close to the shape size. This @@ -86,17 +80,10 @@ public: { if ( m_context->restart == false ) { - m_camera->SetView( 0.0f, 20.0f, 2.5f, { 0.0f, 0.75f, 0.0f } ); - EnableGrid( m_scene, true ); + m_camera->SetView( -30.0f, 20.0f, 10.0f, { 0.0f, 0.5f, 0.0f } ); } - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull box = b3MakeTransformedBoxHull( 40.0f, 1.0f, 40.0f, { { 0.0f, -1.0f, 0.0f }, b3Quat_identity } ); - b3CreateHullShape( groundId, &shapeDef, &box.base ); - } + AddGroundBox( 20.0f ); { m_extent = 0.025f; @@ -139,7 +126,7 @@ public: float m_extent; }; -static int sampleTinyPyramid = SampleManager::Register( "Robustness", "Tiny Pyramid", TinyPyramid::Create ); +static int sampleTinyPyramid = RegisterSample( "Robustness", "Tiny Pyramid", TinyPyramid::Create ); class OverlapRecovery : public Sample { @@ -149,8 +136,7 @@ public: { if ( m_context->restart == false ) { - m_camera->SetView( 45.0f, 20.0f, 50.0f, b3Vec3_zero ); - EnableGrid( m_scene, true ); + m_camera->SetView( 45.0f, 20.0f, 15.0f, b3Vec3_zero ); } m_bodyIds = nullptr; @@ -162,13 +148,7 @@ public: m_hertz = 30.0f; m_dampingRatio = 10.0f; - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull box = b3MakeTransformedBoxHull( 20.0f, 1.0f, 20.0f, { { 0.0f, -1.0f, 0.0f }, b3Quat_identity } ); - b3CreateHullShape( groundId, &shapeDef, &box.base ); - } + AddGroundBox( 20.0f ); CreateScene(); } @@ -221,14 +201,9 @@ public: assert( bodyIndex == m_bodyCount ); } - void UpdateUI() override + bool DrawControls() override { - float height = 220.0f; - ImGui::SetNextWindowPos( ImVec2( 10.0f, m_context->camera.m_height - height - 50.0f ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 220.0f, height ) ); - - ImGui::Begin( "Overlap Recovery", nullptr, ImGuiWindowFlags_NoResize ); - ImGui::PushItemWidth( 100.0f ); + ImGui::PushItemWidth( 6.0f * ImGui::GetFontSize() ); bool changed = false; changed = changed || ImGui::SliderFloat( "Extent", &m_extent, 0.1f, 1.0f, "%.1f" ); @@ -245,7 +220,7 @@ public: } ImGui::PopItemWidth(); - ImGui::End(); + return true; } static Sample* Create( SampleContext* context ) @@ -263,7 +238,7 @@ public: float m_dampingRatio; }; -static int sampleOverlapRecovery = SampleManager::Register( "Robustness", "Overlap Recovery", OverlapRecovery::Create ); +static int sampleOverlapRecovery = RegisterSample( "Robustness", "Overlap Recovery", OverlapRecovery::Create ); class Cart : public Sample { @@ -275,18 +250,10 @@ public: { m_camera->SetView( 45.0f, 30.0f, 15.0f, { 0.0f, 2.0f, 0.0f } ); //context->settings.subStepCount = 12; - EnableGrid( m_scene, true ); + } - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull groundBox = b3MakeBoxHull( 20.0f, 1.0f, 20.0f ); - b3CreateHullShape( groundId, &shapeDef, &groundBox.base ); - } + AddGroundBox( 20.0f ); b3World_SetGravity( m_worldId, { 0, -22, 0 } ); @@ -402,14 +369,9 @@ public: m_jointId4 = b3CreateSphericalJoint( m_worldId, &jointDef ); } - void UpdateUI() override + bool DrawControls() override { - float height = 240.0f; - ImGui::SetNextWindowPos( ImVec2( 10.0f, m_context->camera.m_height - height - 50.0f ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 320.0f, height ) ); - - ImGui::Begin( "Cart", nullptr, ImGuiWindowFlags_NoResize ); - ImGui::PushItemWidth( 200.0f ); + ImGui::PushItemWidth( 6.0f * ImGui::GetFontSize() ); bool changed = false; ImGui::Text( "Contact" ); @@ -444,7 +406,7 @@ public: } ImGui::PopItemWidth(); - ImGui::End(); + return true; } static Sample* Create( SampleContext* context ) @@ -469,13 +431,9 @@ public: float m_constraintDampingRatio; }; -static int sampleCart = SampleManager::Register( "Robustness", "Cart", Cart::Create ); +static int sampleCart = RegisterSample( "Robustness", "Cart", Cart::Create ); -// Drives the b3*_Overflow solver path. A heavy hub touches more dynamic -// neighbors than B3_DYNAMIC_COLOR_COUNT (= 20), so several contacts land in -// the overflow color. The HUD reports the per-step overflow contact count -// because the scene is visually unremarkable when working correctly — the -// point is that it stays unremarkable. +// This forces a constraint graph color overflow class OverflowColorPile : public Sample { public: @@ -484,11 +442,13 @@ public: { if ( m_context->restart == false ) { - m_camera->SetView( 5.0f, 3.0f, 6.0f, b3Vec3_zero ); - EnableGrid( m_scene, true ); + m_camera->SetView( 30.0f, 35.0f, 15.0f, b3Vec3_zero ); + } m_data = CreateOverflowColorPile( m_worldId ); + + SetGroundShape( m_data.groundShapeId ); } void Step() override @@ -511,4 +471,4 @@ public: OverflowColorPileData m_data; }; -static int sampleOverflowColorPile = SampleManager::Register( "Robustness", "Overflow Color Pile", OverflowColorPile::Create ); +static int sampleOverflowColorPile = RegisterSample( "Robustness", "Overflow Color Pile", OverflowColorPile::Create ); diff --git a/samples/sample_shapes.cpp b/samples/sample_shapes.cpp index 3ec2f61..8415c0b 100644 --- a/samples/sample_shapes.cpp +++ b/samples/sample_shapes.cpp @@ -1,14 +1,12 @@ // SPDX-FileCopyrightText: 2025 Erin Catto // SPDX-License-Identifier: MIT -#include "camera.h" +#include "gfx/draw.h" #include "human.h" #include "imgui.h" #include "mesh_loader.h" -#include "utils.h" -#include "renderer.h" #include "sample.h" -#include "scene.h" +#include "utils.h" #include "box3d/box3d.h" @@ -21,22 +19,16 @@ public: if ( context->restart == false ) { m_camera->SetView( -55.0f, 30.0f, 60.0f, { 0.0f, 7.5f, 0.0f } ); - EnableGrid( m_scene, true ); } + AddGroundBox( 50.0f ); + b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - b3BodyId groundBody = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.friction = 1.0f; - b3BoxHull groundBox = b3MakeBoxHull( 50.0f, 1.0f, 50.0f ); - b3CreateHullShape( groundBody, &shapeDef, &groundBox.base ); - bodyDef.position = { 0.0f, 7.5f, -5.0f }; bodyDef.rotation = b3MakeQuatFromAxisAngle( { 1.0f, 0.0f, 0.0f }, 40.0f * B3_DEG_TO_RAD ); b3BodyId planeBody = b3CreateBody( m_worldId, &bodyDef ); b3BoxHull planeBox = b3MakeBoxHull( 16.0f, 0.5f, 10.0f ); + b3ShapeDef shapeDef = b3DefaultShapeDef(); shapeDef.baseMaterial.friction = 1.0f; b3CreateHullShape( planeBody, &shapeDef, &planeBox.base ); @@ -59,7 +51,7 @@ public: static constexpr int m_boxCount = 5; }; -static int sampleInclinedPlane = SampleManager::Register( "Shapes", "Inclined Plane", InclinedPlane::Create ); +static int sampleInclinedPlane = RegisterSample( "Shapes", "Inclined Plane", InclinedPlane::Create ); class RollingResistance : public Sample { @@ -70,24 +62,19 @@ public: if ( m_context->restart == false ) { m_camera->SetView( -140.0f, 17.0f, 60.0f, { 0.0f, 7.5f, 0.0f } ); - EnableGrid( m_scene, true ); } + AddGroundBox( 50.0f ); + b3BodyDef bodyDef = b3DefaultBodyDef(); b3ShapeDef shapeDef = b3DefaultShapeDef(); - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - b3BodyId groundBody = b3CreateBody( m_worldId, &bodyDef ); - - b3BoxHull mGround = b3MakeBoxHull( 50.0f, 1.0f, 50.0f ); - b3CreateHullShape( groundBody, &shapeDef, &mGround.base ); - bodyDef.position = { 0.0f, 2.0f, -20.0f }; bodyDef.rotation = b3MakeQuatFromAxisAngle( { 1.0f, 0.0f, 0.0f }, 10.0f * B3_DEG_TO_RAD ); b3BodyId planeBody = b3CreateBody( m_worldId, &bodyDef ); - b3BoxHull mPlane = b3MakeBoxHull( 32.0f, 0.5f, 15.0f ); - b3CreateHullShape( planeBody, &shapeDef, &mPlane.base ); + b3BoxHull plane = b3MakeBoxHull( 32.0f, 0.5f, 15.0f ); + b3CreateHullShape( planeBody, &shapeDef, &plane.base ); b3Sphere sphere = { b3Vec3_zero, 1.0f }; bodyDef.type = b3_dynamicBody; @@ -120,7 +107,7 @@ public: } }; -static int sampleRollingResistance = SampleManager::Register( "Shapes", "Rolling Resistance", RollingResistance::Create ); +static int sampleRollingResistance = RegisterSample( "Shapes", "Rolling Resistance", RollingResistance::Create ); class HighResistance : public Sample { @@ -131,18 +118,13 @@ public: if ( m_context->restart == false ) { m_camera->SetView( 0.0f, 5.0f, 40.0f, { 0.0f, 7.5f, 0.0f } ); - EnableGrid( m_scene, true ); } + AddGroundBox( 50.0f ); + b3BodyDef bodyDef = b3DefaultBodyDef(); b3ShapeDef shapeDef = b3DefaultShapeDef(); - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - b3BodyId groundBody = b3CreateBody( m_worldId, &bodyDef ); - - b3BoxHull mGround = b3MakeBoxHull( 50.0f, 1.0f, 50.0f ); - b3CreateHullShape( groundBody, &shapeDef, &mGround.base ); - b3Capsule capsule = { { 0.0f, -1.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 0.5f }; bodyDef.type = b3_dynamicBody; bodyDef.rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, B3_DEG_TO_RAD * 30.0f ); @@ -164,7 +146,7 @@ public: static constexpr int m_count = 10; }; -static int sampleHighResistance = SampleManager::Register( "Shapes", "High Resistance", HighResistance::Create ); +static int sampleHighResistance = RegisterSample( "Shapes", "High Resistance", HighResistance::Create ); class IsotropicFriction : public Sample { @@ -175,20 +157,14 @@ public: if ( context->restart == false ) { m_camera->SetView( 45.0f, 30.0f, 150.0f, b3Vec3_zero ); - EnableGrid( m_scene, true ); } + AddGroundBox( 100.0f ); + b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - b3BodyId groundBody = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull mGround = b3MakeBoxHull( 75.0f, 1.0f, 75.0f ); - shapeDef.baseMaterial.friction = 1.0f; - b3CreateHullShape( groundBody, &shapeDef, &mGround.base ); - b3BoxHull box = b3MakeBoxHull( 1.0f, 1.0f, 1.0f ); bodyDef.type = b3_dynamicBody; + b3ShapeDef shapeDef = b3DefaultShapeDef(); shapeDef.baseMaterial.friction = 0.6f; for ( int index = 0; index < m_boxCount; ++index ) { @@ -214,7 +190,7 @@ public: static constexpr int m_boxCount = 32; }; -static int sampleIsotropicFriction = SampleManager::Register( "Shapes", "Isotropic Friction", IsotropicFriction::Create ); +static int sampleIsotropicFriction = RegisterSample( "Shapes", "Isotropic Friction", IsotropicFriction::Create ); // todo what is the point of this? class SlideTwist : public Sample @@ -225,28 +201,24 @@ public: { if ( context->restart == false ) { - m_camera->SetView( -30.0f, 17.0f, 22.0f, { 0.0f, 5.0f, 0.0f } ); - EnableGrid( m_scene, true ); + m_camera->SetView( -30.0f, 17.0f, 30.0f, { 0.0f, 5.0f, 0.0f } ); } + AddGroundBox( 50.0f ); + b3Quat orientation = b3MakeQuatFromAxisAngle( b3Vec3_axisX, 20.0f * B3_DEG_TO_RAD ); b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - b3BodyId groundBody = b3CreateBody( m_worldId, &bodyDef ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); shapeDef.baseMaterial.friction = 1.0f; - b3BoxHull mGround = b3MakeBoxHull( 50.0f, 1.0f, 50.0f ); - b3CreateHullShape( groundBody, &shapeDef, &mGround.base ); bodyDef.position = { 0.0f, 4.0f, 0.0f }; bodyDef.rotation = orientation; b3BodyId planeBody = b3CreateBody( m_worldId, &bodyDef ); - b3BoxHull mPlane = b3MakeBoxHull( 10.0f, 0.5f, 10.0f ); + b3BoxHull plane = b3MakeBoxHull( 10.0f, 0.5f, 10.0f ); shapeDef.baseMaterial.friction = 0.6f; - b3CreateHullShape( planeBody, &shapeDef, &mPlane.base ); + b3CreateHullShape( planeBody, &shapeDef, &plane.base ); bodyDef.type = b3_dynamicBody; bodyDef.position = { 0.0f, 5.0f, 0.0f }; @@ -264,7 +236,7 @@ public: } }; -static int sampleSlideTwist = SampleManager::Register( "Shapes", "Slide Twist", SlideTwist::Create ); +static int sampleSlideTwist = RegisterSample( "Shapes", "Slide Twist", SlideTwist::Create ); class Restitution : public Sample { @@ -281,15 +253,9 @@ public: if ( context->restart == false ) { m_camera->SetView( 0.0f, 25.0f, 85.0f, { 0.0f, 20.0f, 0.0f } ); - EnableGrid( m_scene, true ); } - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - b3BodyId groundBody = b3CreateBody( m_worldId, &bodyDef ); - b3BoxHull groundBox = b3MakeBoxHull( 50.0f, 1.0f, 20.0f ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHullShape( groundBody, &shapeDef, &groundBox.base ); + AddGroundBox( 50.0f ); m_shapeType = e_sphereShape; @@ -340,14 +306,8 @@ public: } } - void UpdateUI() override + bool DrawControls() override { - float height = 100.0f; - ImGui::SetNextWindowPos( ImVec2( 10.0f, m_camera->m_height - height - 50.0f ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 240.0f, height ) ); - - ImGui::Begin( "Restitution", nullptr, ImGuiWindowFlags_NoResize ); - if ( ImGui::RadioButton( "Sphere", m_shapeType == e_sphereShape ) ) { m_shapeType = e_sphereShape; @@ -360,7 +320,7 @@ public: CreateBodies(); } - ImGui::End(); + return true; } static Sample* Create( SampleContext* context ) @@ -374,7 +334,7 @@ public: ShapeType m_shapeType; }; -static int sampleRestitution = SampleManager::Register( "Shapes", "Restitution", Restitution::Create ); +static int sampleRestitution = RegisterSample( "Shapes", "Restitution", Restitution::Create ); // This shows an optimization when creating many static shapes you can skip having them invoke collision, assuming // dynamic bodies are added after the static bodies. @@ -387,20 +347,16 @@ public: if ( context->restart == false ) { m_camera->SetView( 0.0f, 25.0f, 10.0f, { 0.0f, 1.0f, 0.0f } ); - EnableGrid( m_scene, true ); } - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - b3BodyId groundBody = b3CreateBody( m_worldId, &bodyDef ); - b3BoxHull groundBox = b3MakeBoxHull( 20.0f, 1.0f, 20.0f ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHullShape( groundBody, &shapeDef, &groundBox.base ); + AddGroundBox( 20.0f ); + b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.type = b3_dynamicBody; bodyDef.position = { 0.25f, 1.0f, 0.0f }; b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef ); + b3ShapeDef shapeDef = b3DefaultShapeDef(); shapeDef.baseMaterial.rollingResistance = 0.2f; b3Sphere sphere = { b3Vec3_zero, 0.5f }; b3CreateSphereShape( bodyId, &shapeDef, &sphere ); @@ -427,14 +383,8 @@ public: b3CreateSphereShape( m_bodyId, &shapeDef, &sphere ); } - void UpdateUI() override + bool DrawControls() override { - float height = 150.0f; - ImGui::SetNextWindowPos( ImVec2( 10.0f, m_camera->m_height - height - 50.0f ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 240.0f, height ) ); - - ImGui::Begin( "Restitution", nullptr, ImGuiWindowFlags_NoResize ); - if ( ImGui::RadioButton( "Invoke", m_invoke == true ) ) { m_invoke = true; @@ -461,14 +411,7 @@ public: } } - ImGui::End(); - } - - void Render() override - { - Sample::Render(); - b3Transform transform = { { 0.0f, 0.1f, 0.0f }, b3Quat_identity }; - DrawTransform( m_scene, transform, 4.0f ); + return true; } void Step() override @@ -490,7 +433,7 @@ public: bool m_invoke; }; -static int sampleStaticInvoke = SampleManager::Register( "Shapes", "Static Invoke", StaticInvoke::Create ); +static int sampleStaticInvoke = RegisterSample( "Shapes", "Static Invoke", StaticInvoke::Create ); class ConveyorBelt : public Sample { @@ -501,19 +444,9 @@ public: if ( context->restart == false ) { m_camera->SetView( 0.0f, 25.0f, 40.0f, { 0.0f, 1.0f, 0.0f } ); - EnableGrid( m_scene, true ); } - // Ground - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3BoxHull groundBox = b3MakeBoxHull( 20.0f, 1.0f, 20.0f ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHullShape( groundId, &shapeDef, &groundBox.base ); - } + AddGroundBox( 20.0f ); // Platform { @@ -544,20 +477,13 @@ public: } } - void Render() override - { - Sample::Render(); - b3Transform transform = { { 0.0f, 0.1f, 0.0f }, b3Quat_identity }; - DrawTransform( m_scene, transform, 4.0f ); - } - static Sample* Create( SampleContext* context ) { return new ConveyorBelt( context ); } }; -static int sampleConveyorBelt = SampleManager::Register( "Shapes", "Conveyor Belt", ConveyorBelt::Create ); +static int sampleConveyorBelt = RegisterSample( "Shapes", "Conveyor Belt", ConveyorBelt::Create ); class ConveyorMesh : public Sample { @@ -568,19 +494,9 @@ public: if ( context->restart == false ) { m_camera->SetView( 65.0f, 25.0f, 28.0f, { 0.0f, 1.0f, 0.0f } ); - EnableGrid( m_scene, true ); } - // Ground - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3BoxHull groundBox = b3MakeBoxHull( 20.0f, 1.0f, 20.0f ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHullShape( groundId, &shapeDef, &groundBox.base ); - } + AddGroundBox( 20.0f ); // Mesh { @@ -623,12 +539,18 @@ public: materialIndices[24] = 6; m_velocities[6] = { 0.0f, 0.0f, -1.3f }; + b3HexColor colors[7] = { + b3_colorGreen, b3_colorGreenYellow, b3_colorHoneyDew, b3_colorHotPink, + b3_colorIndianRed, b3_colorIndigo, b3_colorIvory, + }; + b3SurfaceMaterial materials[7]; for ( int i = 0; i < 7; ++i ) { materials[i] = b3DefaultSurfaceMaterial(); materials[i].friction = 0.8f; materials[i].tangentVelocity = 2.0f * m_velocities[i]; + materials[i].customColor = colors[i]; } m_meshTransform.p = { 0.0f, 0.5f, 6.0f }; @@ -729,15 +651,15 @@ public: b3Vec3 p = 1.0f / 3.0f * ( v1 + v2 + v3 ); p = b3TransformPoint( m_meshTransform, p ); - DrawWorldString( m_camera, p, b3_colorAqua, "%d", i ); + DrawWorldString( p, MakeColor( b3_colorAqua ), "%d", i ); int materialIndex = materialIndices[i]; b3Vec3 v = b3RotateVector( m_meshTransform.q, m_velocities[materialIndex] ); - DrawLine( m_scene, p, p + v, b3_colorBlueViolet ); + DrawLine( p, p + v, MakeColor( b3_colorBlueViolet ) ); } - DrawTransform( m_scene, b3Transform_identity, 0.5f ); + DrawAxes( b3Transform_identity, 0.5f ); } static Sample* Create( SampleContext* context ) @@ -751,7 +673,7 @@ public: b3Vec3 m_velocities[7]; }; -static int sampleConveyorMesh = SampleManager::Register( "Shapes", "Conveyor Mesh", ConveyorMesh::Create ); +static int sampleConveyorMesh = RegisterSample( "Shapes", "Conveyor Mesh", ConveyorMesh::Create ); class Wind : public Sample { @@ -770,20 +692,21 @@ public: if ( context->restart == false ) { m_camera->SetView( 0.0f, 0.0f, 5.0f, { 0.0f, 1.0f, 0.0f } ); - EnableGrid( m_scene, true ); } + AddGroundBox( 20.0f ); + { b3BodyDef bodyDef = b3DefaultBodyDef(); m_groundId = b3CreateBody( m_worldId, &bodyDef ); } - m_shapeType = e_sphereShape; - m_wind = { 6.0f, 0.0f }; + m_shapeType = e_boxShape; + m_wind = { 6.0f, 0.0f, 0.0f }; m_drag = 1.0f; m_lift = 0.75f; m_count = 10; - m_noise = { 0.0f, 0.0f }; + m_noise = { 0.0f, 0.0f, 0.0f }; // Need this to be false for debug draw to work m_stepWhilePaused = false; @@ -803,13 +726,15 @@ public: } float radius = 0.1f; + float verticalOffset = 2.0f; + b3Sphere sphere = { { 0.0f, 0.0f, 0.0f }, radius }; - b3Capsule capsule = { { 0.0f, -radius }, { 0.0f, radius }, 0.25f * radius }; - b3BoxHull box = b3MakeBoxHull( 0.25f * radius, 1.25f * radius, 0.5f * radius ); + b3Capsule capsule = { { -radius, 0.0f, 0.0f }, { radius, 0.0f, 0.0f }, 0.5f * radius }; + b3BoxHull box = b3MakeBoxHull( 1.25f * radius, 0.75f * radius, 0.125f * radius ); b3SphericalJointDef jointDef = b3DefaultSphericalJointDef(); jointDef.base.bodyIdA = m_groundId; - jointDef.base.localFrameA.p = { 0.0f, 2.0f + radius }; + jointDef.base.localFrameA.p = { 0.0f, verticalOffset, 0.0f }; jointDef.base.drawScale = 0.1f; b3ShapeDef shapeDef = b3DefaultShapeDef(); @@ -822,7 +747,7 @@ public: for ( int i = 0; i < m_count; ++i ) { - bodyDef.position = { 0.0f, 2.0f - 2.0f * radius * i }; + bodyDef.position = { ( 2.0f * i + 1.0f ) * radius, verticalOffset, 0.0f }; m_bodyIds[i] = b3CreateBody( m_worldId, &bodyDef ); if ( m_shapeType == e_sphereShape ) @@ -839,24 +764,16 @@ public: } jointDef.base.bodyIdB = m_bodyIds[i]; - jointDef.base.localFrameB.p = { 0.0f, radius }; + jointDef.base.localFrameB.p = { -radius, 0.0f, 0.0f }; b3CreateSphericalJoint( m_worldId, &jointDef ); jointDef.base.bodyIdA = m_bodyIds[i]; - jointDef.base.localFrameA.p = { 0.0f, -radius }; + jointDef.base.localFrameA.p = { radius, 0.0f, 0.0f }; } } - void UpdateUI() override + bool DrawControls() override { - float fontSize = ImGui::GetFontSize(); - float height = 15.0f * fontSize; - ImGui::SetNextWindowPos( { 0.5f * fontSize, m_camera->m_height - height - 2.0f * fontSize }, ImGuiCond_Once ); - ImGui::SetNextWindowSize( { 24.0f * fontSize, height } ); - - ImGui::Begin( "Wind", nullptr, ImGuiWindowFlags_NoResize ); - ImGui::PushItemWidth( 18.0f * fontSize ); - const char* shapeTypes[] = { "Circle", "Capsule", "Box" }; int shapeType = int( m_shapeType ); if ( ImGui::Combo( "Shape", &shapeType, shapeTypes, IM_ARRAYSIZE( shapeTypes ) ) ) @@ -865,7 +782,7 @@ public: CreateScene(); } - ImGui::SliderFloat2( "Wind", &m_wind.x, -50.0f, 50.0f, "%.1f" ); + ImGui::SliderFloat( "Wind", &m_wind.x, -50.0f, 50.0f, "%.1f" ); ImGui::SliderFloat( "Drag", &m_drag, 0.0f, 1.0f, "%.2f" ); ImGui::SliderFloat( "Lift", &m_lift, 0.0f, 4.0f, "%.2f" ); if ( ImGui::SliderInt( "Count", &m_count, 1, m_maxCount, "%d" ) ) @@ -873,15 +790,7 @@ public: CreateScene(); } - ImGui::PopItemWidth(); - ImGui::End(); - } - - void Render() override - { - Sample::Render(); - - DrawGrid( m_scene, 20 ); + return true; } void Step() override @@ -908,7 +817,9 @@ public: b3Vec3 rand = RandomVec3( { -0.3f, -0.3f, -0.3f }, { 0.3f, 0.3f, 0.3f } ); m_noise = b3Lerp( m_noise, rand, 0.05f ); - DrawLine( m_scene, b3Vec3_zero, b3MulSV( 0.2f, wind ), b3_colorFuchsia ); + b3Vec3 p1 = { 0.0f, 0.5f, 0.0f }; + b3Vec3 p2 = b3MulAdd( p1, 0.2f, wind ); + DrawArrow( p1, p2, MakeColor( b3_colorFuchsia ) ); } } @@ -929,7 +840,7 @@ public: int m_count; }; -static int sampleWind = SampleManager::Register( "Shapes", "Wind", Wind::Create ); +static int sampleWind = RegisterSample( "Shapes", "Wind", Wind::Create ); class WindDrop : public Sample { @@ -939,20 +850,10 @@ public: { if ( context->restart == false ) { - m_camera->SetView( 0.0f, -10.0f, 20.0f, { 0.0f, 5.0f, 0.0f } ); + m_camera->SetView( -45.0f, 15.0f, 20.0f, { 0.0f, 5.0f, 0.0f } ); } - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.name = "ground"; - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull hull = b3MakeBoxHull( 15.0f, 1.0f, 15.0f ); - b3CreateHullShape( groundId, &shapeDef, &hull.base ); - } + AddGroundBox( 15.0f ); m_drag = 1.0f; m_lift = 4.0f; @@ -979,14 +880,6 @@ public: m_shapeId = b3CreateHullShape( bodyId, &shapeDef, &box.base ); } - void Render() override - { - Sample::Render(); - - b3Transform transform = { { 0.0f, 0.1f, 0.0f }, b3Quat_identity }; - DrawTransform( m_scene, transform, 1.0f ); - } - void Step() override { bool shouldStep = m_context->pause == false || m_context->singleStep > 0; @@ -1008,7 +901,7 @@ public: b3ShapeId m_shapeId; }; -static int sampleWindDrop = SampleManager::Register( "Shapes", "Wind Drop", WindDrop::Create ); +static int sampleWindDrop = RegisterSample( "Shapes", "Wind Drop", WindDrop::Create ); class WindFlap : public Sample { @@ -1018,20 +911,10 @@ public: { if ( context->restart == false ) { - m_camera->SetView( 0.0f, -10.0f, 20.0f, { 0.0f, 5.0f, 0.0f } ); + m_camera->SetView( -35.0f, 15.0f, 65.0f, { 0.0f, 5.0f, 10.0f } ); } - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.name = "ground"; - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull hull = b3MakeBoxHull( 50.0f, 1.0f, 50.0f ); - b3CreateHullShape( groundId, &shapeDef, &hull.base ); - } + AddGroundBox( 50.0f ); m_drag = 1.0f; m_lift = 2.0f; @@ -1042,10 +925,10 @@ public: float a = 0.4f; // b3BoxHull box = b3MakeBoxHull( 0.25f * radius, 1.25f * radius, 0.25f * radius ); b3Capsule capsule = { { 0.0f, 0.0f, -a }, { 0.0f, 0.0f, a }, 0.25f * a }; - //b3BoxHull box = b3MakeBoxHull( 2.0f * a, 0.01f, a ); - b3Transform wingTransform1 = {b3Vec3_zero, b3MakeQuatFromAxisAngle(b3Vec3_axisX, 0.1f)}; + // b3BoxHull box = b3MakeBoxHull( 2.0f * a, 0.01f, a ); + b3Transform wingTransform1 = { b3Vec3_zero, b3MakeQuatFromAxisAngle( b3Vec3_axisX, 0.1f ) }; b3BoxHull box1 = b3MakeTransformedBoxHull( 2.0f * a, 0.01f, a, wingTransform1 ); - b3Transform wingTransform2 = {b3Vec3_zero, b3MakeQuatFromAxisAngle(b3Vec3_axisX, 0.1f)}; + b3Transform wingTransform2 = { b3Vec3_zero, b3MakeQuatFromAxisAngle( b3Vec3_axisX, 0.1f ) }; b3BoxHull box2 = b3MakeTransformedBoxHull( 2.0f * a, 0.01f, a, wingTransform2 ); float y = 20.0f; @@ -1054,7 +937,7 @@ public: b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.type = b3_dynamicBody; - //bodyDef.gravityScale = 0.5f; + // bodyDef.gravityScale = 0.5f; shapeDef.density = 5.0f; bodyDef.position = { -2.0f * a, y, 0.0f }; @@ -1066,9 +949,9 @@ public: m_shapeId2 = b3CreateHullShape( wingBodyId2, &shapeDef, &box2.base ); bodyDef.position = { 0.0f, y, 0.0f }; - //bodyDef.type = b3_staticBody; + // bodyDef.type = b3_staticBody; b3BodyId torsoBodyId = b3CreateBody( m_worldId, &bodyDef ); - + shapeDef.density = 10.0f; m_torsoShapeId = b3CreateCapsuleShape( torsoBodyId, &shapeDef, &capsule ); @@ -1098,14 +981,6 @@ public: m_time = 0.0f; } - void Render() override - { - Sample::Render(); - - b3Transform transform = { { 0.0f, 0.1f, 0.0f }, b3Quat_identity }; - DrawTransform( m_scene, transform, 1.0f ); - } - void Step() override { bool shouldStep = m_context->pause == false || m_context->singleStep > 0; @@ -1117,11 +992,11 @@ public: bool wake = false; b3Shape_ApplyWind( m_shapeId1, b3Vec3_zero, m_drag, m_lift, maxSpeed, wake ); b3Shape_ApplyWind( m_shapeId2, b3Vec3_zero, m_drag, m_lift, maxSpeed, wake ); - //b3Shape_ApplyWind( m_torsoShapeId, b3Vec3_zero, m_drag, m_lift, maxSpeed, wake ); + // b3Shape_ApplyWind( m_torsoShapeId, b3Vec3_zero, m_drag, m_lift, maxSpeed, wake ); float angle = b3Sin( 10.0f * m_time ); - b3RevoluteJoint_SetTargetAngle(m_jointId1, angle); - b3RevoluteJoint_SetTargetAngle(m_jointId2, -angle); + b3RevoluteJoint_SetTargetAngle( m_jointId1, angle ); + b3RevoluteJoint_SetTargetAngle( m_jointId2, -angle ); m_time += m_context->hertz > 0.0f ? 1.0f / m_context->hertz : 0.0f; } @@ -1142,4 +1017,4 @@ public: b3JointId m_jointId2; }; -static int sampleWindFlap = SampleManager::Register( "Shapes", "Wind Flap", WindFlap::Create ); +static int sampleWindFlap = RegisterSample( "Shapes", "Wind Flap", WindFlap::Create ); diff --git a/samples/sample_stacking.cpp b/samples/sample_stacking.cpp index eee0b7b..7c55605 100644 --- a/samples/sample_stacking.cpp +++ b/samples/sample_stacking.cpp @@ -1,11 +1,12 @@ // SPDX-FileCopyrightText: 2025 Erin Catto // SPDX-License-Identifier: MIT -#include "camera.h" +#include "gfx/debug_adapter.h" +#include "gfx/keycodes.h" #include "imgui.h" #include "mesh_loader.h" #include "sample.h" -#include "scene.h" +#include "gfx/draw.h" #include "box3d/box3d.h" @@ -18,9 +19,10 @@ public: if ( context->restart == false ) { m_camera->SetView( 0.0f, 25.0f, 10.0f, { 0.0f, 2.0f, 0.0f } ); - EnableGrid( m_scene, true ); } + AddGroundBox( 10.0f ); + const float alpha = 25.0f * B3_DEG_TO_RAD; const float width = 0.38f; const float height = 0.98f; @@ -29,13 +31,6 @@ public: float offsetX = 0.5f * height * b3Sin( alpha ) + 0.045f; float offsetY = 0.5f * height * b3Cos( alpha ) + 0.035f; - b3BodyDef bodyDef = b3DefaultBodyDef(); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - - b3BoxHull mGround = b3MakeOffsetBoxHull( 10.0f, 1.0f, 10.0f, {0.0f, -1.0f, 0.0f} ); - b3BodyId groundBody = b3CreateBody( m_worldId, &bodyDef ); - b3CreateHullShape( groundBody, &shapeDef, &mGround.base ); - b3BoxHull box = b3MakeBoxHull( 0.5f * depth, 0.5f * height, 0.5f * width ); AddVerticalRow( 4, -6.0f * offsetX, offsetX, offsetY, alpha, box ); AddHorizontalRow( 3, -4.0f * offsetX, 4.0f * offsetX, 2.0f * offsetY + 0.04f, box ); @@ -91,7 +86,7 @@ public: } }; -static int sampleCardHouseThick = SampleManager::Register( "Stacking", "Card House Thick", CardHouseThick::Create ); +static int sampleCardHouseThick = RegisterSample( "Stacking", "Card House Thick", CardHouseThick::Create ); // From PEEL class CardHouse : public Sample @@ -102,21 +97,14 @@ public: { if ( context->restart == false ) { - b3Vec3 pivot = { 0.75, 1.0, 0.4f }; - m_camera->SetView( 0.0f, 15.0f, 3.0f, pivot ); - EnableGrid( m_scene, true ); + m_camera->SetView( 30.0f, 10.0f, 3.0f, { 0.75, 1.0, 0.4f } ); } - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { 0.0f, -2.0f }; - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); + AddGroundBox( 10.0f ); b3ShapeDef shapeDef = b3DefaultShapeDef(); shapeDef.baseMaterial.friction = 0.7f; - b3BoxHull groundBox = b3MakeBoxHull( 40.0f, 2.0f, 40.0f ); - b3CreateHullShape( groundId, &shapeDef, &groundBox.base ); - float cardHeight = 0.2f; float cardThickness = 0.001f; float cardDepth = 0.1f; @@ -127,6 +115,7 @@ public: // todo box hull is limiting the minimum thickness, breaking this test b3BoxHull cardBox = b3MakeBoxHull( cardThickness, cardHeight, cardDepth ); + b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.type = b3_dynamicBody; int Nb = 5; @@ -171,7 +160,7 @@ public: } }; -static int sampleCardHouse = SampleManager::Register( "Stacking", "Card House", CardHouse::Create ); +static int sampleCardHouse = RegisterSample( "Stacking", "Card House", CardHouse::Create ); class SphereStack : public Sample { @@ -181,21 +170,10 @@ public: { if ( context->restart == false ) { - m_camera->SetView( 0.0f, 15.0f, 50.0f, {0.0f, 10.0f, 0.0f} ); - EnableGrid( m_scene, true ); + m_camera->SetView( 0.0f, 15.0f, 50.0f, { 0.0f, 10.0f, 0.0f } ); } - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.name = "ground"; - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull hull = b3MakeBoxHull( 15.0f, 1.0f, 15.0f ); - b3CreateHullShape( groundId, &shapeDef, &hull.base ); - } + AddGroundBox( 15.0f ); b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.type = b3_dynamicBody; @@ -210,7 +188,7 @@ public: for ( int i = 0; i < 30; ++i ) { bodyDef.name = "sphere"; - //bodyDef.position.x = 0.1f * i; + // bodyDef.position.x = 0.1f * i; bodyDef.position.y = y; bodyDef.angularVelocity = { 0.0f, 0.0f, 0.0f }; b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef ); @@ -243,7 +221,7 @@ public: b3BodyId m_bodyId; }; -static int sampleSphereStack = SampleManager::Register( "Stacking", "Sphere Stack", SphereStack::Create ); +static int sampleSphereStack = RegisterSample( "Stacking", "Sphere Stack", SphereStack::Create ); class CapsuleStack : public Sample { @@ -254,20 +232,9 @@ public: if ( context->restart == false ) { m_camera->SetView( 0.0f, 15.0f, 50.0f, { 0.0f, 10.0f, 0.0f } ); - EnableGrid( m_scene, true ); } - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.name = "ground"; - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull hull = b3MakeBoxHull( 40.0f, 1.0f, 40.0f ); - b3CreateHullShape( groundId, &shapeDef, &hull.base ); - } + AddGroundBox( 40.0f ); b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.type = b3_dynamicBody; @@ -277,7 +244,7 @@ public: bodyDef.motionLocks.angularZ = true; float r = 0.5f; - b3Capsule capsule = { {-1.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, r }; + b3Capsule capsule = { { -1.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f }, r }; b3ShapeDef shapeDef = b3DefaultShapeDef(); float y = 1.5f * r; @@ -298,7 +265,7 @@ public: } }; -static int sampleCapsuleStack = SampleManager::Register( "Stacking", "Capsule Stack", CapsuleStack::Create ); +static int sampleCapsuleStack = RegisterSample( "Stacking", "Capsule Stack", CapsuleStack::Create ); class SingleBox : public Sample { @@ -309,48 +276,22 @@ public: if ( context->restart == false ) { m_camera->SetView( 0.0f, 25.0f, 10.0f, b3Vec3_zero ); - EnableGrid( m_scene, true ); } + AddGroundBox( 20.0f ); + { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.name = "ground"; - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull hull = b3MakeBoxHull( 15.0f, 1.0f, 15.0f ); - b3CreateHullShape( groundId, &shapeDef, &hull.base ); - } - -#if 1 - { - b3BoxHull cube = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); + b3BoxHull cube = b3MakeCubeHull( 0.5f ); b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.name = "cube"; bodyDef.type = b3_dynamicBody; bodyDef.position = { 0.0f, 0.5f, 0.0f }; - //bodyDef.linearVelocity = { 4.0f, 0.0f, 0.0f }; bodyDef.angularVelocity = { 0.0f, 10.0f, 0.0f }; m_bodyId = b3CreateBody( m_worldId, &bodyDef ); b3ShapeDef shapeDef = b3DefaultShapeDef(); b3CreateHullShape( m_bodyId, &shapeDef, &cube.base ); } -#else - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.name = "capsule"; - bodyDef.type = b3_dynamicBody; - bodyDef.position = { 0.0f, 2.0f, 0.0f }; - m_bodyId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3Capsule capsule = { { -0.25f, 0.0f }, { 0.25f, 0.0f }, 0.1f }; - b3CreateCapsuleShape( m_bodyId, &shapeDef, &capsule ); - } -#endif } void Step() override @@ -369,7 +310,7 @@ public: b3BodyId m_bodyId; }; -static int sampleSingleBox = SampleManager::Register( "Stacking", "Single Box", SingleBox::Create ); +static int sampleSingleBox = RegisterSample( "Stacking", "Single Box", SingleBox::Create ); class Cylinder : public Sample { @@ -380,20 +321,9 @@ public: if ( context->restart == false ) { m_camera->SetView( 0.0f, 15.0f, 10.0f, b3Vec3_zero ); - EnableGrid( m_scene, true ); } - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.name = "ground"; - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull hull = b3MakeBoxHull( 10.0f, 1.0f, 10.0f ); - b3CreateHullShape( groundId, &shapeDef, &hull.base ); - } + AddGroundBox( 10.0f ); { m_hull = b3CreateCylinder( 1.0f, 0.25f, 0.0f, 12 ); @@ -410,7 +340,7 @@ public: b3CreateHullShape( bodyId, &shapeDef, m_hull ); } - m_context->debugDraw.forceScale = 0.01f; + GetGuiDraw()->forceScale = 0.01f; } ~Cylinder() override @@ -431,7 +361,7 @@ public: b3Hull* m_hull; }; -static int sampleCylinder = SampleManager::Register( "Stacking", "Cylinder", Cylinder::Create ); +static int sampleCylinder = RegisterSample( "Stacking", "Cylinder", Cylinder::Create ); class CylinderStack : public Sample { @@ -441,21 +371,10 @@ public: { if ( context->restart == false ) { - m_camera->SetView( 0.0f, 15.0f, 15.0f, {0.0f, 5.0f, 0.0f} ); - EnableGrid( m_scene, true ); + m_camera->SetView( 0.0f, 15.0f, 15.0f, { 0.0f, 5.0f, 0.0f } ); } - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.name = "ground"; - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull hull = b3MakeBoxHull( 10.0f, 1.0f, 10.0f ); - b3CreateHullShape( groundId, &shapeDef, &hull.base ); - } + AddGroundBox( 10.0f ); m_hull = b3CreateCylinder( 1.0f, 0.5f, 0.0f, 15 ); @@ -475,11 +394,11 @@ public: b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef ); b3ShapeDef shapeDef = b3DefaultShapeDef(); - //shapeDef.baseMaterial.rollingResistance = 0.1f; + // shapeDef.baseMaterial.rollingResistance = 0.1f; b3CreateTransformedHullShape( bodyId, &shapeDef, m_hull, b3Transform_identity, scales[i % 4] ); } - m_context->debugDraw.forceScale = 0.001f; + GetGuiDraw()->forceScale = 0.001f; } ~CylinderStack() override @@ -500,7 +419,7 @@ public: b3Hull* m_hull; }; -static int sampleCylinderStack = SampleManager::Register( "Stacking", "Cylinder Stack", CylinderStack::Create ); +static int sampleCylinderStack = RegisterSample( "Stacking", "Cylinder Stack", CylinderStack::Create ); class BoxStack : public Sample { @@ -510,21 +429,10 @@ public: { if ( context->restart == false ) { - m_camera->SetView( 0.0f, 15.0f, 50.0f, {0.0f, 20.0f, 0.0f} ); - EnableGrid( m_scene, true ); + m_camera->SetView( 0.0f, 15.0f, 50.0f, { 0.0f, 20.0f, 0.0f } ); } - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.name = "ground"; - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull hull = b3MakeBoxHull( 40.0f, 1.0f, 40.0f ); - b3CreateHullShape( groundId, &shapeDef, &hull.base ); - } + AddGroundBox( 40.0f ); float a = 0.5f; b3BodyDef bodyDef = b3DefaultBodyDef(); @@ -566,7 +474,7 @@ public: } }; -static int sampleBoxStack = SampleManager::Register( "Stacking", "Box Stack", BoxStack::Create ); +static int sampleBoxStack = RegisterSample( "Stacking", "Box Stack", BoxStack::Create ); class JengaStack : public Sample { @@ -577,7 +485,6 @@ public: if ( m_context->restart == false ) { m_camera->SetView( 35.0f, 15.0f, 30.0f, { 0.0f, 10.0f, 0.0f } ); - EnableGrid( m_scene, true ); } m_shapeType = b3_hullShape; @@ -586,15 +493,7 @@ public: void CreateStack() { - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull groundBox = b3MakeBoxHull( 50.0f, 1.0f, 50.0f ); - b3CreateHullShape( groundId, &shapeDef, &groundBox.base ); - } + AddGroundBox( 60.0f ); { b3ShapeDef shapeDef = b3DefaultShapeDef(); @@ -634,15 +533,8 @@ public: } } - void UpdateUI() override + bool DrawControls() override { - float fontSize = ImGui::GetFontSize(); - float height = 6.0f * fontSize; - ImGui::SetNextWindowPos( ImVec2( 0.5f * fontSize, m_camera->m_height - height - 2.0f * fontSize ), ImGuiCond_Once ); - ImGui::SetNextWindowSize( ImVec2( 8.0f * fontSize, height ) ); - - ImGui::Begin( "Jenga Stack", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize ); - b3Capacity capacity = {}; if ( ImGui::RadioButton( "Capsule", m_shapeType == b3_capsuleShape ) ) @@ -659,9 +551,7 @@ public: CreateStack(); } - ImGui::End(); - - Sample::UpdateUI(); + return true; } static Sample* Create( SampleContext* context ) @@ -673,7 +563,7 @@ public: b3ShapeType m_shapeType; }; -static int sampleJengaStack = SampleManager::Register( "Stacking", "Jenga Stack", JengaStack::Create ); +static int sampleJengaStack = RegisterSample( "Stacking", "Jenga Stack", JengaStack::Create ); class Dominoes : public Sample { @@ -683,17 +573,17 @@ public: { if ( m_context->restart == false ) { - m_camera->SetView( 0.0f, 15.0f, 50.0f, b3Vec3_zero ); - EnableGrid( m_scene, true ); + if (m_isDebug) + { + m_camera->SetView( 0.0f, 15.0f, 25.0f, b3Vec3_zero ); + } + else + { + m_camera->SetView( 0.0f, 15.0f, 75.0f, b3Vec3_zero ); + } } - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - b3BodyId groundBody = b3CreateBody( m_worldId, &bodyDef ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - - b3BoxHull groundBox = b3MakeBoxHull( 80.0f, 1.0f, 80.0f ); - b3CreateHullShape( groundBody, &shapeDef, &groundBox.base ); + AddGroundBox( 80.0f ); constexpr int n = m_isDebug ? 2 : 30; @@ -739,7 +629,7 @@ public: } }; -static int sampleDominoes = SampleManager::Register( "Stacking", "Dominoes", Dominoes::Create ); +static int sampleDominoes = RegisterSample( "Stacking", "Dominoes", Dominoes::Create ); // This wedge shape can have an incorrect manifold if not handled correctly class Wedge : public Sample @@ -755,16 +645,10 @@ public: { if ( context->restart == false ) { - m_camera->SetView( 77.0f, 10.0f, 5.0f ); + m_camera->SetView( 75.0f, 10.0f, 10.0f ); } - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull groundBox = b3MakeBoxHull( 25.0f, 1.0f, 25.0f ); - b3CreateHullShape( groundId, &shapeDef, &groundBox.base ); + AddGroundBox( 20.0f ); b3Vec3 vertices[] = { { -1.0, 1.0f, -0.1f }, { 1.0, 1.0f, -0.1f }, { -1.0, 1.0f, 0.1f }, @@ -773,9 +657,12 @@ public: m_wedgeHull = b3CreateHull( vertices, 6, 6 ); + b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.type = b3_dynamicBody; bodyDef.position = { 0.0f, 1.0f, 0.0f }; b3BodyId wedgeBody = b3CreateBody( m_worldId, &bodyDef ); + + b3ShapeDef shapeDef = b3DefaultShapeDef(); b3CreateHullShape( wedgeBody, &shapeDef, m_wedgeHull ); } @@ -787,7 +674,7 @@ public: b3Hull* m_wedgeHull; }; -static int sampleWedge = SampleManager::Register( "Stacking", "Wedge", Wedge::Create ); +static int sampleWedge = RegisterSample( "Stacking", "Wedge", Wedge::Create ); // jitter /* @@ -846,10 +733,11 @@ public: { if ( context->restart == false ) { - m_camera->SetView( 0.0f, 15.0f, 30.0f, { 0.0f, 5.0f, 0.0f } ); - EnableGrid( m_scene, true ); + m_camera->SetView( 25.0f, 10.0f, 30.0f, { 0.0f, 5.0f, 0.0f } ); } + AddGroundBox( 40.0f ); + b3Vec3 ps1[9] = { { 16.0f, 0.0f, 0.0f }, { 14.93803712795643f, 5.133601056842984f, 0.0f }, { 13.79871746027416f, 10.24928069555078f, 0.0f }, @@ -882,14 +770,7 @@ public: const float halfDepth = 0.5f; b3ShapeDef shapeDef = b3DefaultShapeDef(); - - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - b3BoxHull groundBox = b3MakeBoxHull( 50.0f, 1.0f, 50.0f ); - b3CreateHullShape( groundId, &shapeDef, &groundBox.base ); - } + shapeDef.density = 200.0f; b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.type = b3_dynamicBody; @@ -898,10 +779,10 @@ public: { b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef ); b3Vec3 ps[8] = { - { ps1[i].x, ps1[i].y, -halfDepth }, { ps2[i].x, ps2[i].y, -halfDepth }, + { ps1[i].x, ps1[i].y, -halfDepth }, { ps2[i].x, ps2[i].y, -halfDepth }, { ps2[i + 1].x, ps2[i + 1].y, -halfDepth }, { ps1[i + 1].x, ps1[i + 1].y, -halfDepth }, - { ps1[i].x, ps1[i].y, halfDepth }, { ps2[i].x, ps2[i].y, halfDepth }, - { ps2[i + 1].x, ps2[i + 1].y, halfDepth }, { ps1[i + 1].x, ps1[i + 1].y, halfDepth }, + { ps1[i].x, ps1[i].y, halfDepth }, { ps2[i].x, ps2[i].y, halfDepth }, + { ps2[i + 1].x, ps2[i + 1].y, halfDepth }, { ps1[i + 1].x, ps1[i + 1].y, halfDepth }, }; b3Hull* hull = b3CreateHull( ps, 8, 8 ); b3CreateHullShape( bodyId, &shapeDef, hull ); @@ -912,10 +793,10 @@ public: { b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef ); b3Vec3 ps[8] = { - { -ps2[i].x, ps2[i].y, -halfDepth }, { -ps1[i].x, ps1[i].y, -halfDepth }, + { -ps2[i].x, ps2[i].y, -halfDepth }, { -ps1[i].x, ps1[i].y, -halfDepth }, { -ps1[i + 1].x, ps1[i + 1].y, -halfDepth }, { -ps2[i + 1].x, ps2[i + 1].y, -halfDepth }, - { -ps2[i].x, ps2[i].y, halfDepth }, { -ps1[i].x, ps1[i].y, halfDepth }, - { -ps1[i + 1].x, ps1[i + 1].y, halfDepth }, { -ps2[i + 1].x, ps2[i + 1].y, halfDepth }, + { -ps2[i].x, ps2[i].y, halfDepth }, { -ps1[i].x, ps1[i].y, halfDepth }, + { -ps1[i + 1].x, ps1[i + 1].y, halfDepth }, { -ps2[i + 1].x, ps2[i + 1].y, halfDepth }, }; b3Hull* hull = b3CreateHull( ps, 8, 8 ); b3CreateHullShape( bodyId, &shapeDef, hull ); @@ -925,10 +806,9 @@ public: { b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef ); b3Vec3 ps[8] = { - { ps1[8].x, ps1[8].y, -halfDepth }, { ps2[8].x, ps2[8].y, -halfDepth }, - { -ps2[8].x, ps2[8].y, -halfDepth }, { -ps1[8].x, ps1[8].y, -halfDepth }, - { ps1[8].x, ps1[8].y, halfDepth }, { ps2[8].x, ps2[8].y, halfDepth }, - { -ps2[8].x, ps2[8].y, halfDepth }, { -ps1[8].x, ps1[8].y, halfDepth }, + { ps1[8].x, ps1[8].y, -halfDepth }, { ps2[8].x, ps2[8].y, -halfDepth }, { -ps2[8].x, ps2[8].y, -halfDepth }, + { -ps1[8].x, ps1[8].y, -halfDepth }, { ps1[8].x, ps1[8].y, halfDepth }, { ps2[8].x, ps2[8].y, halfDepth }, + { -ps2[8].x, ps2[8].y, halfDepth }, { -ps1[8].x, ps1[8].y, halfDepth }, }; b3Hull* hull = b3CreateHull( ps, 8, 8 ); b3CreateHullShape( bodyId, &shapeDef, hull ); @@ -950,7 +830,7 @@ public: } }; -static int sampleArch = SampleManager::Register( "Stacking", "Arch", Arch::Create ); +static int sampleArch = RegisterSample( "Stacking", "Arch", Arch::Create ); class DoubleDomino : public Sample { @@ -960,18 +840,10 @@ public: { if ( m_context->restart == false ) { - m_camera->SetView( 0.0f, 15.0f, 20.0f, { 0.0f, 4.0f, 0.0f } ); + m_camera->SetView( 0.0f, 15.0f, 15.0f, { 0.0f, 0.5f, 1.0f } ); } - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3BoxHull groundBox = b3MakeBoxHull( 50.0f, 1.0f, 50.0f ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHullShape( groundId, &shapeDef, &groundBox.base ); - } + AddGroundBox( 20.0f ); b3BoxHull box = b3MakeBoxHull( 0.125f, 0.5f, 0.25f ); @@ -1004,7 +876,7 @@ public: } }; -static int sampleDoubleDomino = SampleManager::Register( "Stacking", "Double Domino", DoubleDomino::Create ); +static int sampleDoubleDomino = RegisterSample( "Stacking", "Double Domino", DoubleDomino::Create ); class Pyramid2D : public Sample { @@ -1017,17 +889,7 @@ public: m_camera->SetView( 0.0f, 30.0f, 50.0f, { 0.0f, 5.0f, 0.0f } ); } - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3BoxHull groundBox = b3MakeBoxHull( 50.0f, 1.0f, 50.0f ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - // shapeDef.filter = { 1, ~0u, 0 }; - - b3CreateHullShape( groundId, &shapeDef, &groundBox.base ); - } + AddGroundBox( 40.0f ); float a = 1.0f; b3BoxHull box = b3MakeBoxHull( a, a, a ); @@ -1043,7 +905,7 @@ public: { for ( int column = 0; column < m_size - row; ++column ) { - bodyDef.position = { ( -20.0f + 2.0f * column + row ) * a, ( 1.5f + 2.5f * row ) * a, 0.0f }; + bodyDef.position = { ( -10.0f + 2.0f * column + row ) * a, ( 1.5f + 2.5f * row ) * a, 0.0f }; b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef ); b3CreateHullShape( bodyId, &shapeDef, &box.base ); @@ -1059,5 +921,4 @@ public: static constexpr int m_size = 12; }; -static int samplePyramid2D = SampleManager::Register( "Stacking", "Pyramid2D", Pyramid2D::Create ); - +static int samplePyramid2D = RegisterSample( "Stacking", "Pyramid2D", Pyramid2D::Create ); diff --git a/samples/sample_tree.cpp b/samples/sample_tree.cpp index ac03af4..e9bb5aa 100644 --- a/samples/sample_tree.cpp +++ b/samples/sample_tree.cpp @@ -5,12 +5,12 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#include "camera.h" #include "imgui.h" #include "utils.h" -#include "renderer.h" #include "sample.h" -#include "scene.h" +#include "gfx/draw.h" + +#include "box3d/box3d.h" #include #include @@ -615,7 +615,12 @@ public: m_closestTime = b3GetMilliseconds( ticks ); } - void UpdateUI() override + bool HasSolverControls() const override + { + return false; + } + + bool DrawControls() override { DrawTextLine( "leaves = %d, height = %d, area = %g", m_tree.proxyCount, m_height, m_areaRatio ); DrawTextLine( "build time = %g ms", m_buildTime ); @@ -624,13 +629,6 @@ public: float s = 1000.0f / m_testCount; DrawTextLine( "ave: ray = %g us, overlap = %g us, closest = %g us", s * m_rayTime, s * m_overlapTime, s * m_closestTime ); - float fontSize = ImGui::GetFontSize(); - float height = 23.0f * fontSize; - ImGui::SetNextWindowPos( { 0.5f * fontSize, m_camera->m_height - height - 2.0f * fontSize }, ImGuiCond_Once ); - ImGui::SetNextWindowSize( { 18.0f * fontSize, height } ); - - ImGui::Begin( "Tree", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize ); - if ( ImGui::Combo( "File", &m_fileIndex, m_fileNames, m_fileCount ) ) { CreateTree(); @@ -672,14 +670,14 @@ public: ImGui::SliderFloat( "Load Scale", &m_loadScale, 0.01f, 1.0f ); - ImGui::End(); + return true; } void Render() override { Sample::Render(); - DrawTransform( m_scene, b3Transform_identity, 2.0f ); + DrawAxes( b3Transform_identity, 2.0f ); b3Vec3 cp = m_camera->GetPosition(); b3TreeNode* nodes = m_tree.nodes; @@ -708,7 +706,7 @@ public: b3Vec3 c = b3AABB_Center( node->aabb ); if ( m_drawLevel < 10 || b3DistanceSquared( c, cp ) < distSquared ) { - DrawBounds( m_scene, node->aabb, 0.0f, colors[m_drawLevel % colorCount] ); + DrawBounds( node->aabb, 0.0f, MakeColor( colors[m_drawLevel % colorCount] ) ); } } } @@ -733,13 +731,13 @@ public: Proxy& proxy = m_proxies[node->userData]; if ( proxy.queryTimeStamp == m_timeStamp || proxy.rayTimeStamp == m_timeStamp ) { - DrawBounds( m_scene, node->aabb, 0.0f, b3_colorLightGray ); + DrawBounds( node->aabb, 0.0f, MakeColor( b3_colorLightGray ) ); } else { // float extension = 0.01f * node->height; float extension = 0.0f; - DrawBounds( m_scene, node->aabb, extension, b3_colorLightBlue ); + DrawBounds( node->aabb, extension, MakeColor( b3_colorLightBlue ) ); } } } @@ -747,20 +745,20 @@ public: if ( m_doRay ) { Ray ray = m_rays[m_testIndex]; - DrawLine( m_scene, ray.origin, ray.origin + ray.translation, b3_colorRed ); + DrawLine( ray.origin, ray.origin + ray.translation, MakeColor( b3_colorRed ) ); } if ( m_doOverlap ) { - DrawBounds( m_scene, m_overlapQueries[m_testIndex], 0.0f, b3_colorRed ); + DrawBounds( m_overlapQueries[m_testIndex], 0.0f, MakeColor( b3_colorRed ) ); } if ( m_doClosest ) { - DrawSphere( m_scene, b3Transform_identity, m_closestPointQueries[m_testIndex], b3_colorCyan ); + DrawSolidSphere( b3Transform_identity, m_closestPointQueries[m_testIndex], MakeColor( b3_colorCyan ) ); if ( m_haveClosest ) { - DrawPoint( m_scene, m_closestPoint, 15.0f, b3_colorOrange ); + DrawPoint( m_closestPoint, 15.0f, MakeColor( b3_colorOrange ) ); } } } @@ -845,4 +843,4 @@ public: bool m_doRay; }; -static int sampleTree = SampleManager::Register( "Tree", "Benchmark", TreeBenchmark::Create ); +static int sampleTree = RegisterSample( "Tree", "Benchmark", TreeBenchmark::Create ); diff --git a/samples/scene.cpp b/samples/scene.cpp deleted file mode 100644 index 6587554..0000000 --- a/samples/scene.cpp +++ /dev/null @@ -1,2146 +0,0 @@ -// SPDX-FileCopyrightText: 2025 Erin Catto -// SPDX-License-Identifier: MIT - -#include "scene.h" - -#include "../src/core.h" -#include "camera.h" -#include "geo_buffer.h" -#include "renderer.h" -#include "shader.h" -#include "ssao_buffer.h" -#include "utility.h" - -#include "box3d/math_functions.h" - -#include -#include -#include -#include -#include -#include -#include - -static const int shadowWidth = 4096; -static const int shadowHeight = 4096; -static constexpr int s_batchSize = 256; - -// The number of sides of the base circle. For spheres and capsules. -static constexpr int s_sideCount = 16; - -// The number of quad rings going from the middle to the sphere end point -// for example, a value of 2 has 2 rings plus the end cone. For spheres and capsules. -static constexpr int s_ringCount = 8; - -struct Cube -{ - b3Transform transform; - RGBAf color; - bool invert; - bool shadowCaster; -}; - -struct DebugCube -{ - b3Transform transform; - RGBAf color; -}; - -struct Edge -{ - int index1; - int index2; - int flags; -}; - -struct EdgeData -{ - b3Vec3 position; - int flags; -}; - -struct InstanceShape -{ - int triangleCount; - uint32_t triangleArrayId; - - // Static and dynamic buffers - uint32_t triangleBufferIds[2]; - - int edgeCount; - uint32_t edgeArrayId; - - // Static and dynamic buffers - uint32_t edgeBufferIds[2]; -}; - -struct InstanceData -{ - RGBA8 rgba8; - Matrix4 matrix; -}; - -struct Scene -{ - Scene() = default; - - Arena arena; - - std::vector debugCubes; - std::vector sphereInstances; - std::vector openHemisphereInstances; - std::vector openCylinderInstances; - - // Instances organized by hash - std::unordered_map> hullInstances; - std::unordered_map> meshInstances; - std::unordered_map> heightFieldInstances; - - std::vector transparentSphereInstances; - std::vector transparentOpenHemisphereInstances; - std::vector transparentOpenCylinderInstances; - std::unordered_map> transparentHullInstances; - - uint32_t shadowShader = 0; - uint32_t meshShader = 0; - uint32_t meshShadowShader = 0; - uint32_t meshEdgeShader = 0; - uint32_t geometryShader = 0; - uint32_t ssaoShader = 0; - uint32_t ssaoBlurShader = 0; - uint32_t deferredShader = 0; - uint32_t meshForwardShader = 0; - uint32_t forwardShader = 0; - uint32_t depthCopyShader = 0; - - uint32_t depthMapFBO = 0; - uint32_t depthMap = 0; - - PointDraw* pointDraw = nullptr; - LineDraw* lineDraw = nullptr; - GeoBuffer* geoBuffer = nullptr; - SsaoBuffer* ssaoBuffer = nullptr; - - InstanceShape sphere; - - // Building blocks for capsules - InstanceShape openHemisphere; - InstanceShape openCylinder; - - std::unordered_map sharedHulls; - std::unordered_map sharedMeshes; - std::unordered_map sharedHeightFields; - - SceneAOSettings ao = {}; - - b3Vec3 lightPosition{ -16.0f, 40.0f, 10.0f }; - - bool useSSAO = false; - bool useShadow = false; - bool useGrid = false; -}; - -// Renders a 1x1 XY quad in NDC -static uint32_t quadVAO = 0; -static uint32_t quadVBO = 0; -static void DrawQuad() -{ - if ( quadVAO == 0 ) - { - float quadVertices[] = { - // positions texture Coords - // (x, y, z, u, v) - -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, - 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, - }; - - glGenVertexArrays( 1, &quadVAO ); - glGenBuffers( 1, &quadVBO ); - glBindVertexArray( quadVAO ); - glBindBuffer( GL_ARRAY_BUFFER, quadVBO ); - glBufferData( GL_ARRAY_BUFFER, sizeof( quadVertices ), &quadVertices, GL_STATIC_DRAW ); - glEnableVertexAttribArray( 0 ); - glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof( float ), (void*)0 ); - glEnableVertexAttribArray( 1 ); - glVertexAttribPointer( 1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof( float ), (void*)( 3 * sizeof( float ) ) ); - } - - glBindVertexArray( quadVAO ); - glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 ); - glBindVertexArray( 0 ); -} - -static uint32_t cubeArrayId = 0; -static uint32_t cubeBufferId = 0; -void DrawCube( Scene* scene, b3Transform transform, b3HexColor color, const Matrix4& view, const Matrix4& projection ) -{ - // initialize (if necessary) - if ( cubeArrayId == 0 ) - { - // position / normal / uv - - float vertices[] = { - // back face - -1.0f, -1.0f, -1.0f, 0.0f, 0.0f, -1.0f, // bottom-left - 1.0f, 1.0f, -1.0f, 0.0f, 0.0f, -1.0f, // top-right - 1.0f, -1.0f, -1.0f, 0.0f, 0.0f, -1.0f, // bottom-right - 1.0f, 1.0f, -1.0f, 0.0f, 0.0f, -1.0f, // top-right - -1.0f, -1.0f, -1.0f, 0.0f, 0.0f, -1.0f, // bottom-left - -1.0f, 1.0f, -1.0f, 0.0f, 0.0f, -1.0f, // top-left - // front face - -1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, // bottom-left - 1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, // bottom-right - 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, // top-right - 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, // top-right - -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, // top-left - -1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, // bottom-left - // left face - -1.0f, 1.0f, 1.0f, -1.0f, 0.0f, 0.0f, // top-right - -1.0f, 1.0f, -1.0f, -1.0f, 0.0f, 0.0f, // top-left - -1.0f, -1.0f, -1.0f, -1.0f, 0.0f, 0.0f, // bottom-left - -1.0f, -1.0f, -1.0f, -1.0f, 0.0f, 0.0f, // bottom-left - -1.0f, -1.0f, 1.0f, -1.0f, 0.0f, 0.0f, // bottom-right - -1.0f, 1.0f, 1.0f, -1.0f, 0.0f, 0.0f, // top-right - // right face - 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, // top-left - 1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 0.0f, // bottom-right - 1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f, // top-right - 1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 0.0f, // bottom-right - 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, // top-left - 1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, // bottom-left - // bottom face - -1.0f, -1.0f, -1.0f, 0.0f, -1.0f, 0.0f, // top-right - 1.0f, -1.0f, -1.0f, 0.0f, -1.0f, 0.0f, // top-left - 1.0f, -1.0f, 1.0f, 0.0f, -1.0f, 0.0f, // bottom-left - 1.0f, -1.0f, 1.0f, 0.0f, -1.0f, 0.0f, // bottom-left - -1.0f, -1.0f, 1.0f, 0.0f, -1.0f, 0.0f, // bottom-right - -1.0f, -1.0f, -1.0f, 0.0f, -1.0f, 0.0f, // top-right - // top face - -1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, // top-left - 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, // bottom-right - 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, // top-right - 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, // bottom-right - -1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, // top-left - -1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f // bottom-left - }; - - glGenVertexArrays( 1, &cubeArrayId ); - glGenBuffers( 1, &cubeBufferId ); - - // fill buffer - glBindBuffer( GL_ARRAY_BUFFER, cubeBufferId ); - glBufferData( GL_ARRAY_BUFFER, sizeof( vertices ), vertices, GL_STATIC_DRAW ); - - // link vertex attributes - glBindVertexArray( cubeArrayId ); - - // position - glEnableVertexAttribArray( 0 ); - glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof( float ), (void*)0 ); - - // normal - glEnableVertexAttribArray( 1 ); - glVertexAttribPointer( 1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof( float ), (void*)( 3 * sizeof( float ) ) ); - - glBindBuffer( GL_ARRAY_BUFFER, 0 ); - glBindVertexArray( 0 ); - } - - glUseProgram( scene->forwardShader ); - SetUniformMatrix4( scene->forwardShader, "projection", projection ); - SetUniformMatrix4( scene->forwardShader, "view", view ); - - Matrix4 m = MakeMatrix4( transform, 0.25f ); - SetUniformMatrix4( scene->forwardShader, "model", m ); - - RGBAf c = MakeRGBAf( color ); - SetUniformVec3( scene->forwardShader, "color", { c.r, c.g, c.b } ); - - glBindVertexArray( cubeArrayId ); - glDrawArrays( GL_TRIANGLES, 0, 36 ); - glBindVertexArray( 0 ); -} - -struct VertexData -{ - b3Vec3 position; - b3Vec3 normal; - int material; -}; - -// Creates a shape that can be instanced -InstanceShape CreateInstanceShape( const b3Vec3* vertexPositions, const b3Vec3* vertexNormals, const int* triangleIndices, - int triangleCount, const Edge* edges, int edgeCount, const int* materials, Arena arena ) -{ - InstanceShape shape = {}; - - // Vertex buffer - { - int vertexCount = 3 * triangleCount; - VertexData* vertexData = (VertexData*)arena.Allocate( vertexCount * sizeof( VertexData ) ); - - int index = 0; - for ( int triangleIndex = 0; triangleIndex < triangleCount; ++triangleIndex ) - { - int vertexIndex1 = triangleIndices[3 * triangleIndex + 0]; - int vertexIndex2 = triangleIndices[3 * triangleIndex + 1]; - int vertexIndex3 = triangleIndices[3 * triangleIndex + 2]; - - b3Vec3 vertexPosition1 = vertexPositions[vertexIndex1]; - b3Vec3 vertexPosition2 = vertexPositions[vertexIndex2]; - b3Vec3 vertexPosition3 = vertexPositions[vertexIndex3]; - - vertexData[index + 0].position = vertexPosition1; - vertexData[index + 1].position = vertexPosition2; - vertexData[index + 2].position = vertexPosition3; - - b3Vec3 vertexNormal1, vertexNormal2, vertexNormal3; - if ( vertexNormals ) - { - vertexNormal1 = vertexNormals[vertexIndex1]; - vertexNormal2 = vertexNormals[vertexIndex2]; - vertexNormal3 = vertexNormals[vertexIndex3]; - } - else - { - b3Vec3 edge1 = vertexPosition2 - vertexPosition1; - b3Vec3 edge2 = vertexPosition3 - vertexPosition1; - b3Vec3 normal = b3Cross( edge1, edge2 ); - normal = b3Normalize( normal ); - - vertexNormal1 = normal; - vertexNormal2 = normal; - vertexNormal3 = normal; - } - - vertexData[index + 0].normal = vertexNormal1; - vertexData[index + 1].normal = vertexNormal2; - vertexData[index + 2].normal = vertexNormal3; - - if ( materials != nullptr ) - { - vertexData[index + 0].material = materials[triangleIndex]; - vertexData[index + 1].material = materials[triangleIndex]; - vertexData[index + 2].material = materials[triangleIndex]; - } - else - { - vertexData[index + 0].material = -1; - vertexData[index + 1].material = -1; - vertexData[index + 2].material = -1; - } - - index += 3; - } - - assert( index == vertexCount ); - - // Fill vertex buffers - shape.triangleCount = triangleCount; - - glGenVertexArrays( 1, &shape.triangleArrayId ); - glGenBuffers( 2, shape.triangleBufferIds ); - - // Copy static vertex data - glBindVertexArray( shape.triangleArrayId ); - glBindBuffer( GL_ARRAY_BUFFER, shape.triangleBufferIds[0] ); - glBufferData( GL_ARRAY_BUFFER, vertexCount * sizeof( VertexData ), vertexData, GL_STATIC_DRAW ); - - // positions - uint32_t positionAttribute = 0; - glEnableVertexAttribArray( positionAttribute ); - glVertexAttribPointer( positionAttribute, 3, GL_FLOAT, GL_FALSE, sizeof( VertexData ), - (void*)offsetof( VertexData, position ) ); - - // normals - uint32_t normalAttribute = 1; - glEnableVertexAttribArray( normalAttribute ); - glVertexAttribPointer( normalAttribute, 3, GL_FLOAT, GL_FALSE, sizeof( VertexData ), - (void*)offsetof( VertexData, normal ) ); - - // materials - uint32_t materialAttribute = 2; - glEnableVertexAttribArray( materialAttribute ); - glVertexAttribIPointer( materialAttribute, 1, GL_INT, sizeof( VertexData ), (void*)offsetof( VertexData, material ) ); - - // Instance data setup - glBindBuffer( GL_ARRAY_BUFFER, shape.triangleBufferIds[1] ); - glBufferData( GL_ARRAY_BUFFER, s_batchSize * sizeof( InstanceData ), nullptr, GL_DYNAMIC_DRAW ); - - uint32_t colorInstance = 3; - glEnableVertexAttribArray( colorInstance ); - // Save bandwidth by expanding color to floats in the shader - glVertexAttribPointer( colorInstance, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof( InstanceData ), - (void*)offsetof( InstanceData, rgba8 ) ); - - // This makes the color an instance - glVertexAttribDivisor( colorInstance, 1 ); - - // Matrix has to use 4 attributes each 16 bytes - uint32_t matrixAttribute = 4; - glEnableVertexAttribArray( matrixAttribute + 0 ); - glEnableVertexAttribArray( matrixAttribute + 1 ); - glEnableVertexAttribArray( matrixAttribute + 2 ); - glEnableVertexAttribArray( matrixAttribute + 3 ); - - glVertexAttribPointer( matrixAttribute + 0, 4, GL_FLOAT, GL_FALSE, sizeof( InstanceData ), - (void*)offsetof( InstanceData, matrix.cx ) ); - glVertexAttribPointer( matrixAttribute + 1, 4, GL_FLOAT, GL_FALSE, sizeof( InstanceData ), - (void*)offsetof( InstanceData, matrix.cy ) ); - glVertexAttribPointer( matrixAttribute + 2, 4, GL_FLOAT, GL_FALSE, sizeof( InstanceData ), - (void*)offsetof( InstanceData, matrix.cz ) ); - glVertexAttribPointer( matrixAttribute + 3, 4, GL_FLOAT, GL_FALSE, sizeof( InstanceData ), - (void*)offsetof( InstanceData, matrix.cw ) ); - - // This makes the matrix an instance - glVertexAttribDivisor( matrixAttribute + 0, 1 ); - glVertexAttribDivisor( matrixAttribute + 1, 1 ); - glVertexAttribDivisor( matrixAttribute + 2, 1 ); - glVertexAttribDivisor( matrixAttribute + 3, 1 ); - - glBindBuffer( GL_ARRAY_BUFFER, 0 ); - glBindVertexArray( 0 ); - } - - CheckOpenGL(); - - // Edges are optional - if ( edgeCount > 0 ) - { - // Create edge buffer - EdgeData* edgeBuffer = (EdgeData*)arena.Allocate( 2 * edgeCount * sizeof( EdgeData ) ); - for ( int edgeIndex = 0; edgeIndex < edgeCount; ++edgeIndex ) - { - int vertexIndex1 = edges[edgeIndex].index1; - int vertexIndex2 = edges[edgeIndex].index2; - int flags = edges[edgeIndex].flags; - - const b3Vec3* vb = vertexPositions; - b3Vec3 vertexPosition1 = vb[vertexIndex1]; - b3Vec3 vertexPosition2 = vb[vertexIndex2]; - - edgeBuffer[2 * edgeIndex + 0].position = vertexPosition1; - edgeBuffer[2 * edgeIndex + 0].flags = flags; - edgeBuffer[2 * edgeIndex + 1].position = vertexPosition2; - edgeBuffer[2 * edgeIndex + 1].flags = flags; - } - - shape.edgeCount = edgeCount; - - glGenVertexArrays( 1, &shape.edgeArrayId ); - glGenBuffers( 2, shape.edgeBufferIds ); - - // Copy static vertex data - glBindVertexArray( shape.edgeArrayId ); - glBindBuffer( GL_ARRAY_BUFFER, shape.edgeBufferIds[0] ); - glBufferData( GL_ARRAY_BUFFER, 2 * edgeCount * sizeof( EdgeData ), edgeBuffer, GL_STATIC_DRAW ); - - uint32_t positionIndex = 0; - glEnableVertexAttribArray( positionIndex ); - glVertexAttribPointer( positionIndex, 3, GL_FLOAT, GL_FALSE, sizeof( EdgeData ), (void*)offsetof( EdgeData, position ) ); - - uint32_t flagsIndex = 1; - glEnableVertexAttribArray( flagsIndex ); - glVertexAttribIPointer( flagsIndex, 1, GL_INT, sizeof( EdgeData ), (void*)offsetof( EdgeData, flags ) ); - - // Instance data setup - glBindBuffer( GL_ARRAY_BUFFER, shape.edgeBufferIds[1] ); - glBufferData( GL_ARRAY_BUFFER, s_batchSize * sizeof( InstanceData ), nullptr, GL_DYNAMIC_DRAW ); - - uint32_t colorInstance = 2; - glEnableVertexAttribArray( colorInstance ); - // Save bandwidth by expanding color to floats in the shader - glVertexAttribPointer( colorInstance, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof( InstanceData ), - (void*)offsetof( InstanceData, rgba8 ) ); - - // This makes the color an instance - glVertexAttribDivisor( colorInstance, 1 ); - - // Matrix has to use 4 attributes each 16 bytes - uint32_t matrixAttribute = 3; - glEnableVertexAttribArray( matrixAttribute + 0 ); - glEnableVertexAttribArray( matrixAttribute + 1 ); - glEnableVertexAttribArray( matrixAttribute + 2 ); - glEnableVertexAttribArray( matrixAttribute + 3 ); - - glVertexAttribPointer( matrixAttribute + 0, 4, GL_FLOAT, GL_FALSE, sizeof( InstanceData ), - (void*)offsetof( InstanceData, matrix.cx ) ); - glVertexAttribPointer( matrixAttribute + 1, 4, GL_FLOAT, GL_FALSE, sizeof( InstanceData ), - (void*)offsetof( InstanceData, matrix.cy ) ); - glVertexAttribPointer( matrixAttribute + 2, 4, GL_FLOAT, GL_FALSE, sizeof( InstanceData ), - (void*)offsetof( InstanceData, matrix.cz ) ); - glVertexAttribPointer( matrixAttribute + 3, 4, GL_FLOAT, GL_FALSE, sizeof( InstanceData ), - (void*)offsetof( InstanceData, matrix.cw ) ); - - // This makes the matrix an instance - glVertexAttribDivisor( matrixAttribute + 0, 1 ); - glVertexAttribDivisor( matrixAttribute + 1, 1 ); - glVertexAttribDivisor( matrixAttribute + 2, 1 ); - glVertexAttribDivisor( matrixAttribute + 3, 1 ); - - glBindBuffer( GL_ARRAY_BUFFER, 0 ); - glBindVertexArray( 0 ); - } - - CheckOpenGL(); - - return shape; -} - -void DestroySharedShape( InstanceShape shape ) -{ - glDeleteBuffers( 2, shape.triangleBufferIds ); - glDeleteVertexArrays( 1, &shape.triangleArrayId ); - - if ( shape.edgeCount > 0 ) - { - glDeleteBuffers( 2, shape.edgeBufferIds ); - glDeleteVertexArrays( 1, &shape.edgeArrayId ); - } -} - -static InstanceShape CreateSphere( Arena arena ) -{ - float radius = 1.0f; - - int vertexCount = s_sideCount * s_ringCount + 2; - b3Vec3* vertices = (b3Vec3*)arena.Allocate( vertexCount * sizeof( b3Vec3 ) ); - b3Vec3* normals = (b3Vec3*)arena.Allocate( vertexCount * sizeof( b3Vec3 ) ); - - int triangleCount = s_sideCount * 2 * s_ringCount; - int* indices = (int*)arena.Allocate( 3 * triangleCount * sizeof( int ) ); - - // poles - vertices[s_sideCount * s_ringCount + 0] = b3Vec3{ -radius, 0.0f, 0.0f }; - normals[s_sideCount * s_ringCount + 0] = { -1.0f, 0.0f, 0.0f }; - vertices[s_sideCount * s_ringCount + 1] = b3Vec3{ radius, 0.0f, 0.0f }; - normals[s_sideCount * s_ringCount + 1] = { 1.0f, 0.0f, 0.0f }; - - int j = 0; - - for ( int i = 0; i < s_sideCount; ++i ) - { - float theta = ( -2 * B3_PI * i ) / s_sideCount; - float s0 = b3Sin( theta ); - float c0 = b3Cos( theta ); - - int i1 = ( i + 1 ) % s_sideCount; - - // Sides - for ( int k = 0; k <= s_ringCount; ++k ) - { - float phi = ( k + 1 ) * B3_PI / ( s_ringCount + 1 ) - 0.5f * B3_PI; - float x0 = b3Sin( phi ); - float y0 = b3Cos( phi ); - - b3Vec3 normal = { x0, c0 * y0, s0 * y0 }; - vertices[s_ringCount * i + k] = radius * normal; - normals[s_ringCount * i + k] = normal; - - if ( k + 1 < s_ringCount ) - { - indices[j++] = s_ringCount * i1 + k; - indices[j++] = s_ringCount * i + k; - indices[j++] = s_ringCount * i1 + k + 1; - - indices[j++] = s_ringCount * i1 + k + 1; - indices[j++] = s_ringCount * i + k; - indices[j++] = s_ringCount * i + k + 1; - } - else - { - // Needed the vertices, but not the indices - break; - } - - B3_ASSERT( s_ringCount * i + k + 1 < vertexCount ); - } - - // Caps - indices[j++] = s_ringCount * s_sideCount; - indices[j++] = s_ringCount * i; - indices[j++] = s_ringCount * i1; - - indices[j++] = s_ringCount * s_sideCount + 1; - indices[j++] = s_ringCount * i1 + s_ringCount - 1; - indices[j++] = s_ringCount * i + s_ringCount - 1; - } - - B3_ASSERT( j == 3 * triangleCount ); - - // todo add line discs for transparent view - - return CreateInstanceShape( vertices, normals, indices, triangleCount, nullptr, 0, nullptr, arena ); -} - -// Open hemisphere along x-axis. Radius is 1. -static InstanceShape CreateOpenHemisphere( Arena arena ) -{ - float radius = 1.0f; - - const int sideVertexCount = s_ringCount + 1; - - // Vertex count including pole - int vertexCount = s_sideCount * sideVertexCount + 1; - b3Vec3* vertices = (b3Vec3*)arena.Allocate( vertexCount * sizeof( b3Vec3 ) ); - b3Vec3* normals = (b3Vec3*)arena.Allocate( vertexCount * sizeof( b3Vec3 ) ); - - // Hemisphere quad rings and a cone at the pole - int triangleCount = 2 * s_sideCount * s_ringCount + s_sideCount; - int* indices = (int*)arena.Allocate( 3 * triangleCount * sizeof( int ) ); - - // Pole at the end of the array - vertices[s_sideCount * sideVertexCount] = b3Vec3{ radius, 0.0f, 0.0f }; - normals[s_sideCount * sideVertexCount] = b3Vec3{ 1.0f, 0.0f, 0.0f }; - - int j = 0; - - // loop sides - for ( int i = 0; i < s_sideCount; ++i ) - { - int i1 = ( i + 1 ) % s_sideCount; - - float theta = ( -2.0f * B3_PI * i ) / s_sideCount; - b3CosSin csTheta = b3ComputeCosSin( theta ); - float c0 = csTheta.cosine; - float s0 = csTheta.sine; - - // loop rings - for ( int k = 0;; ++k ) - { - int k1 = k + 1; - - float phi = ( 0.5f * k * B3_PI ) / ( s_ringCount + 1 ); - b3CosSin csPhi = b3ComputeCosSin( phi ); - float y0 = csPhi.cosine; - float x0 = csPhi.sine; - - b3Vec3 normal = { x0, c0 * y0, s0 * y0 }; - b3Vec3 vertex = radius * normal; - vertices[sideVertexCount * i + k] = vertex; - normals[sideVertexCount * i + k] = normal; - - if ( k < s_ringCount ) - { - // ring quad - indices[j++] = sideVertexCount * i1 + k; - indices[j++] = sideVertexCount * i + k; - indices[j++] = sideVertexCount * i1 + k1; - - indices[j++] = sideVertexCount * i1 + k1; - indices[j++] = sideVertexCount * i + k; - indices[j++] = sideVertexCount * i + k1; - } - else - { - // cone - indices[j++] = s_sideCount * sideVertexCount; - indices[j++] = sideVertexCount * i1 + k; - indices[j++] = sideVertexCount * i + k; - break; - } - } - } - - B3_ASSERT( j == 3 * triangleCount ); - - return CreateInstanceShape( vertices, normals, indices, triangleCount, nullptr, 0, nullptr, arena ); -} - -static InstanceShape CreateOpenCylinder( Arena arena ) -{ - float radius = 1.0f; - float height = 1.0f; - - int vertexCount = 2 * s_sideCount; - b3Vec3* vertices = (b3Vec3*)arena.Allocate( vertexCount * sizeof( b3Vec3 ) ); - b3Vec3* normals = (b3Vec3*)arena.Allocate( vertexCount * sizeof( b3Vec3 ) ); - - int triangleCount = 2 * s_sideCount; - int* indices = (int*)arena.Allocate( 3 * triangleCount * sizeof( int ) ); - - int j = 0; - - // loop sides - for ( int i = 0; i < s_sideCount; ++i ) - { - int i1 = ( i + 1 ) % s_sideCount; - - float theta = ( -2.0f * B3_PI * i ) / s_sideCount; - b3CosSin csTheta = b3ComputeCosSin( theta ); - float c0 = csTheta.cosine; - float s0 = csTheta.sine; - - b3Vec3 normal = { 0.0f, c0, s0 }; - b3Vec3 vertex1 = radius * normal - b3Vec3{ 0.5f * height, 0.0f, 0.0f }; - vertices[2 * i + 0] = vertex1; - normals[2 * i + 0] = normal; - - b3Vec3 vertex2 = radius * normal + b3Vec3{ 0.5f * height, 0.0f, 0.0f }; - vertices[2 * i + 1] = vertex2; - normals[2 * i + 1] = normal; - - // side quad - indices[j++] = 2 * i1; - indices[j++] = 2 * i; - indices[j++] = 2 * i1 + 1; - - indices[j++] = 2 * i1 + 1; - indices[j++] = 2 * i; - indices[j++] = 2 * i + 1; - } - - B3_ASSERT( j == 3 * triangleCount ); - - return CreateInstanceShape( vertices, normals, indices, triangleCount, nullptr, 0, nullptr, arena ); -} - -Scene* CreateScene( const Camera* camera, Arena arena ) -{ - Scene* scene = new Scene; - - scene->ao.radius = 1.0f; - scene->ao.bias = 0.25f; - scene->ao.minScale = 0.0f; - scene->ao.power = 2.0f; - scene->ao.direct = 0.5f; - scene->ao.aoOnly = false; - scene->useSSAO = true; - scene->useShadow = true; - scene->useGrid = false; - - scene->pointDraw = CreateDebugPoints(); - scene->lineDraw = CreateDebugLines(); - - scene->shadowShader = CreateProgramFromFiles( "shaders/shadow_map.vs", "shaders/empty.fs" ); - scene->meshShader = CreateProgramFromFiles( "shaders/mesh.vs", "shaders/mesh.fs" ); - scene->meshShadowShader = CreateProgramFromFiles( "shaders/mesh_shadow.vs", "shaders/empty.fs" ); - scene->meshEdgeShader = CreateProgramFromFiles( "shaders/mesh_edge.vs", "shaders/forward.fs" ); - scene->geometryShader = CreateProgramFromFiles( "shaders/geometry_vs.glsl", "shaders/geometry_fs.glsl" ); - scene->ssaoShader = CreateProgramFromFiles( "shaders/quad_vs.glsl", "shaders/ssao_fs.glsl" ); - scene->ssaoBlurShader = CreateProgramFromFiles( "shaders/quad_vs.glsl", "shaders/ssao_blur_fs.glsl" ); - scene->deferredShader = CreateProgramFromFiles( "shaders/quad_vs.glsl", "shaders/deferred_lighting_fs.glsl" ); - scene->meshForwardShader = CreateProgramFromFiles( "shaders/mesh_forward.vs", "shaders/mesh_forward.fs" ); - scene->forwardShader = CreateProgramFromFiles( "shaders/forward.vs", "shaders/forward.fs" ); - scene->depthCopyShader = CreateProgramFromFiles( "shaders/quad_vs.glsl", "shaders/depth_copy_fs.glsl" ); - - scene->sphere = CreateSphere( arena ); - scene->openHemisphere = CreateOpenHemisphere( arena ); - scene->openCylinder = CreateOpenCylinder( arena ); - - if ( scene->shadowShader == 0 || scene->meshShader == 0 || scene->meshEdgeShader == 0 || scene->meshEdgeShader == 0 || - scene->geometryShader == 0 || scene->ssaoShader == 0 || scene->ssaoBlurShader == 0 || scene->deferredShader == 0 || - scene->forwardShader == 0 || scene->depthCopyShader == 0 ) - { - fprintf( stderr, "Failed to create shaders\n" ); - return nullptr; - } - - // configure depth map FBO for shadow map - glGenFramebuffers( 1, &scene->depthMapFBO ); - - // create depth texture - glGenTextures( 1, &scene->depthMap ); - glBindTexture( GL_TEXTURE_2D, scene->depthMap ); - glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, shadowWidth, shadowHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr ); - // Linear filtering combined with comparison mode gives free hardware 2x2 PCF - // inside each tap when sampled via sampler2DShadow. - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER ); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER ); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE ); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL ); - float borderColor[] = { 1.0f, 1.0f, 1.0f, 1.0f }; - glTexParameterfv( GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor ); - - // attach depth texture as FBO's depth buffer - glBindFramebuffer( GL_FRAMEBUFFER, scene->depthMapFBO ); - glFramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, scene->depthMap, 0 ); - glDrawBuffer( GL_NONE ); - glReadBuffer( GL_NONE ); - glBindFramebuffer( GL_FRAMEBUFFER, 0 ); - - scene->geoBuffer = CreateGeoBuffer( camera->m_bufferWidth, camera->m_bufferHeight ); - scene->ssaoBuffer = CreateSsaoBuffer( camera->m_bufferWidth, camera->m_bufferHeight ); - - glUseProgram( scene->ssaoShader ); - SetUniformInt( scene->ssaoShader, "gPosition", 0 ); - SetUniformInt( scene->ssaoShader, "gNormal", 1 ); - SetUniformInt( scene->ssaoShader, "texNoise", 2 ); - - glUseProgram( scene->ssaoBlurShader ); - SetUniformInt( scene->ssaoBlurShader, "ssaoInput", 0 ); - SetUniformInt( scene->ssaoBlurShader, "gPosition", 1 ); - - glUseProgram( scene->deferredShader ); - SetUniformInt( scene->deferredShader, "gPosition", 0 ); - SetUniformInt( scene->deferredShader, "gNormal", 1 ); - SetUniformInt( scene->deferredShader, "gAlbedoSpec", 2 ); - SetUniformInt( scene->deferredShader, "ssao", 3 ); - SetUniformInt( scene->deferredShader, "shadowMap", 4 ); - - glUseProgram( scene->depthCopyShader ); - SetUniformInt( scene->depthCopyShader, "depthTexture", 0 ); - - return scene; -} - -void DestroySharedMeshes( Scene* scene ) -{ - for ( std::unordered_map::iterator shared = scene->sharedHeightFields.begin(); - shared != scene->sharedHeightFields.end(); ++shared ) - { - DestroySharedShape( shared->second ); - } - - for ( std::unordered_map::iterator shared = scene->sharedHulls.begin(); - shared != scene->sharedHulls.end(); ++shared ) - { - DestroySharedShape( shared->second ); - } - - for ( std::unordered_map::iterator shared = scene->sharedMeshes.begin(); - shared != scene->sharedMeshes.end(); ++shared ) - { - DestroySharedShape( shared->second ); - } - - scene->sharedHeightFields.clear(); - scene->sharedHulls.clear(); - scene->sharedMeshes.clear(); - scene->heightFieldInstances.clear(); - scene->hullInstances.clear(); - scene->meshInstances.clear(); - scene->transparentHullInstances.clear(); -} - -void DestroyScene( Scene* scene ) -{ - DestroyDebugPoints( scene->pointDraw ); - DestroyDebugLines( scene->lineDraw ); - DestroyGeoBuffer( scene->geoBuffer ); - DestroySsaoBuffer( scene->ssaoBuffer ); - - DestroySharedShape( scene->sphere ); - DestroySharedShape( scene->openHemisphere ); - DestroySharedShape( scene->openCylinder ); - - DestroySharedMeshes( scene ); - - DestroyShader( scene->shadowShader ); - DestroyShader( scene->meshShader ); - DestroyShader( scene->meshShadowShader ); - DestroyShader( scene->meshEdgeShader ); - DestroyShader( scene->geometryShader ); - DestroyShader( scene->ssaoShader ); - DestroyShader( scene->ssaoBlurShader ); - DestroyShader( scene->deferredShader ); - DestroyShader( scene->meshForwardShader ); - DestroyShader( scene->forwardShader ); - DestroyShader( scene->depthCopyShader ); - - delete scene; -} - -uint32_t CreateInstanceHull( Scene* scene, const b3Hull* hull, Arena arena ) -{ - uint32_t hash = hull->hash; - - std::unordered_map::iterator result = scene->sharedHulls.find( hash ); - if ( result != scene->sharedHulls.end() ) - { - // Already created - return hash; - } - - int vertexCount = hull->vertexCount; - b3Vec3* vertices = (b3Vec3*)arena.Allocate( hull->vertexCount * sizeof( b3Vec3 ) ); - - const b3Vec3* hullPoints = b3GetHullPoints( hull ); - memcpy( vertices, hullPoints, vertexCount * sizeof( b3Vec3 ) ); - - int triangleCount = 0; - int faceCount = hull->faceCount; - const b3HullFace* hullFaces = b3GetHullFaces( hull ); - const b3HullHalfEdge* hullEdges = b3GetHullEdges( hull ); - - // Count triangles - for ( int i = 0; i < faceCount; ++i ) - { - const b3HullFace* face = hullFaces + i; - - const b3HullHalfEdge* edge1 = hullEdges + face->edge; - const b3HullHalfEdge* edge2 = hullEdges + edge1->next; - const b3HullHalfEdge* edge3 = hullEdges + edge2->next; - B3_ASSERT( edge1 != edge3 ); - - do - { - triangleCount += 1; - edge3 = hullEdges + edge3->next; - } - while ( edge1 != edge3 ); - } - - int* indices = (int*)arena.Allocate( 3 * triangleCount * sizeof( int ) ); - int triangleIndex = 0; - - for ( int i = 0; i < faceCount; ++i ) - { - const b3HullFace* face = hullFaces + i; - - const b3HullHalfEdge* edge1 = hullEdges + face->edge; - const b3HullHalfEdge* edge2 = hullEdges + edge1->next; - const b3HullHalfEdge* edge3 = hullEdges + edge2->next; - B3_ASSERT( edge1 != edge3 ); - - do - { - B3_ASSERT( triangleIndex < triangleCount ); - indices[3 * triangleIndex + 0] = edge1->origin; - indices[3 * triangleIndex + 1] = edge2->origin; - indices[3 * triangleIndex + 2] = edge3->origin; - triangleIndex += 1; - - edge2 = edge3; - edge3 = hullEdges + edge3->next; - } - while ( edge1 != edge3 ); - } - - B3_ASSERT( triangleIndex == triangleCount ); - - int edgeCount = hull->edgeCount / 2; - Edge* edges = (Edge*)arena.Allocate( edgeCount * sizeof( Edge ) ); - - for ( int i = 0; i < edgeCount; ++i ) - { - const b3HullHalfEdge* edge = hullEdges + 2 * i + 0; - const b3HullHalfEdge* twin = hullEdges + 2 * i + 1; - - edges[i].index1 = edge->origin; - edges[i].index2 = twin->origin; - edges[i].flags = 0; - } - - InstanceShape shape = CreateInstanceShape( vertices, nullptr, indices, triangleCount, edges, edgeCount, nullptr, arena ); - scene->sharedHulls[hash] = shape; - - // reserve a slot - scene->hullInstances[hash] = {}; - scene->transparentHullInstances[hash] = {}; - - return hash; -} - -static inline bool EdgeLess( Edge e1, Edge e2 ) -{ - if ( e1.index1 == e2.index1 ) - { - return e1.index2 < e2.index2; - } - - return e1.index1 < e2.index1; -} - -static bool EdgeEquals( Edge e1, Edge e2 ) -{ - return e1.index1 == e2.index1 && e1.index2 == e2.index2; -} - -uint32_t CreateInstanceMesh( Scene* scene, const b3MeshData* meshData, Arena arena ) -{ - uint32_t hash = meshData->hash; - - std::unordered_map::iterator result = scene->sharedMeshes.find( hash ); - if ( result != scene->sharedMeshes.end() ) - { - // Already created - return hash; - } - - int vertexCount = meshData->vertexCount; - const b3Vec3* meshVertices = b3GetMeshVertices( meshData ); - - int triangleCount = meshData->triangleCount; - std::vector indices; - indices.resize( 3 * triangleCount ); - - int edgeCount = 3 * triangleCount; - std::vector edges; - edges.resize( edgeCount ); - - std::vector materials; - materials.resize( triangleCount ); - - const b3MeshTriangle* meshTriangles = b3GetMeshTriangles( meshData ); - const uint8_t* materialIndices = b3GetMeshMaterialIndices( meshData ); - const uint8_t* meshFlags = b3GetMeshFlags( meshData ); - - for ( int i = 0; i < triangleCount; ++i ) - { - b3MeshTriangle triangle = meshTriangles[i]; - - int i1 = triangle.index1; - int i2 = triangle.index2; - int i3 = triangle.index3; - - assert( i1 < vertexCount && i2 < vertexCount && i3 < vertexCount ); - - indices[3 * i + 0] = i1; - indices[3 * i + 1] = i2; - indices[3 * i + 2] = i3; - - uint8_t triangleFlags = meshFlags[i]; - - int flag1 = ( triangleFlags & b3_concaveEdge1 ) != 0 ? 0 : 1; - int flag2 = ( triangleFlags & b3_concaveEdge2 ) != 0 ? 0 : 1; - int flag3 = ( triangleFlags & b3_concaveEdge3 ) != 0 ? 0 : 1; - - edges[3 * i + 0] = { i1, i2, flag1 }; - edges[3 * i + 1] = { i2, i3, flag2 }; - edges[3 * i + 2] = { i3, i1, flag3 }; - - if ( materialIndices != nullptr ) - { - materials[i] = materialIndices[i]; - } - else - { - materials[i] = 0; - } - } - - // Remove duplicate edges - std::sort( edges.data(), edges.data() + edges.size(), EdgeLess ); - auto last = std::ranges::unique( edges, EdgeEquals ).begin(); - edges.erase( last, edges.end() ); - edgeCount = (int)edges.size(); - - InstanceShape shape = CreateInstanceShape( meshVertices, nullptr, indices.data(), triangleCount, edges.data(), edgeCount, - materials.data(), arena ); - scene->sharedMeshes[hash] = shape; - - // reserve a slot - scene->meshInstances[hash] = {}; - - return hash; -} - -uint32_t CreateInstanceHeightField( Scene* scene, const b3HeightField* heightField, Arena arena ) -{ - uint32_t hash = heightField->hash; - - std::unordered_map::iterator result = scene->sharedHeightFields.find( hash ); - if ( result != scene->sharedHeightFields.end() ) - { - // Already created - return hash; - } - - int rowCount = heightField->rowCount; - int columnCount = heightField->columnCount; - uint16_t* compressedHeights = heightField->compressedHeights; - uint8_t* materialIndices = heightField->materialIndices; - uint8_t* flags = heightField->flags; - float minHeight = heightField->minHeight; - float heightScale = heightField->heightScale; - b3Vec3 scale = heightField->scale; - - int vertexCount = rowCount * columnCount; - int cellCount = ( rowCount - 1 ) * ( columnCount - 1 ); - - std::vector vertices; - vertices.resize( vertexCount ); - - int vertexIndex = 0; - for ( int row = 0; row < rowCount; ++row ) - { - for ( int column = 0; column < columnCount; ++column ) - { - int heightIndex = row * columnCount + column; - - float x = float( column ); - float y = minHeight + heightScale * compressedHeights[heightIndex]; - float z = float( row ); - - vertices[vertexIndex] = scale * b3Vec3{ x, y, z }; - vertexIndex += 1; - } - } - assert( vertexIndex == vertexCount ); - - int triangleCount = 2 * ( rowCount - 1 ) * ( columnCount - 1 ); - - std::vector materials; - materials.resize( triangleCount ); - - // int cellCount = triangleCount >> 1; - int materialIndex = 0; - for ( int i = 0; i < cellCount; ++i ) - { - uint8_t index = materialIndices[i]; - if ( index != B3_HEIGHT_FIELD_HOLE ) - { - materials[materialIndex + 0] = index; - materials[materialIndex + 1] = index; - materialIndex += 2; - } - } - - int indexCount = 3 * triangleCount; - std::vector indices; - indices.resize( indexCount ); - - // Edge along each column, row, and diagonal - int edgeCount = columnCount * ( rowCount - 1 ) + rowCount * ( columnCount - 1 ) + ( rowCount - 1 ) * ( columnCount - 1 ); - std::vector edges; - edges.resize( edgeCount ); - - int index = 0; - int edgeIndex = 0; - for ( int row = 0; row < rowCount - 1; ++row ) - { - for ( int column = 0; column < columnCount - 1; ++column ) - { - int cellIndex = row * ( columnCount - 1 ) + column; - int triangleIndex = 2 * cellIndex; - assert( triangleIndex < triangleCount ); - - assert( cellIndex < cellCount ); - if ( materialIndices[cellIndex] == B3_HEIGHT_FIELD_HOLE ) - { - continue; - } - - int index11 = row * columnCount + column; - int index12 = index11 + 1; - int index21 = ( row + 1 ) * columnCount + column; - int index22 = index21 + 1; - - indices[index + 0] = index11; - indices[index + 1] = index21; - indices[index + 2] = index12; - - indices[index + 3] = index22; - indices[index + 4] = index12; - indices[index + 5] = index21; - - index += 6; - - int flag = ( flags[triangleIndex] & b3_concaveEdge2 ) != 0 ? 0 : 1; - edges[edgeIndex] = { index12, index21, flag }; - edgeIndex += 1; - } - } - assert( index <= indexCount ); - indexCount = index; - - // Edge rows - for ( int row = 0; row < rowCount; ++row ) - { - for ( int column = 0; column < columnCount - 1; ++column ) - { - int index1 = row * columnCount + column; - int index2 = index1 + 1; - - int flag; - if ( row < rowCount - 1 ) - { - int cellIndex = row * ( columnCount - 1 ) + column; - int triangleIndex = 2 * cellIndex; - - assert( triangleIndex < triangleCount ); - flag = ( flags[triangleIndex] & b3_concaveEdge3 ) != 0 ? 0 : 1; - } - else - { - int cellIndex = ( row - 1 ) * ( columnCount - 1 ) + column; - int triangleIndex = 2 * cellIndex + 1; - assert( triangleIndex < triangleCount ); - flag = ( flags[triangleIndex] & b3_concaveEdge3 ) != 0 ? 0 : 1; - } - - edges[edgeIndex + 0] = { index1, index2, flag }; - edgeIndex += 1; - } - } - - // Edge columns - for ( int column = 0; column < columnCount; ++column ) - { - for ( int row = 0; row < rowCount - 1; ++row ) - { - int index1 = row * columnCount + column; - int index2 = ( row + 1 ) * columnCount + column; - - int flag; - if ( column < columnCount - 1 ) - { - int cellIndex = row * ( columnCount - 1 ) + column; - int triangleIndex = 2 * cellIndex; - assert( triangleIndex < triangleCount ); - flag = ( flags[triangleIndex] & b3_concaveEdge1 ) != 0 ? 0 : 1; - } - else - { - int cellIndex = row * ( columnCount - 1 ) + column - 1; - int triangleIndex = 2 * cellIndex + 1; - assert( triangleIndex < triangleCount ); - flag = ( flags[triangleIndex] & b3_concaveEdge1 ) != 0 ? 0 : 1; - } - - edges[edgeIndex + 0] = { index1, index2, flag }; - edgeIndex += 1; - } - } - assert( edgeIndex <= edgeCount ); - edgeCount = edgeIndex; - - triangleCount = indexCount / 3; - - assert( materialIndex == triangleCount ); - - InstanceShape shape = CreateInstanceShape( vertices.data(), nullptr, indices.data(), triangleCount, edges.data(), edgeCount, - materials.data(), arena ); - scene->sharedHeightFields[hash] = shape; - - // reserve a slot - scene->heightFieldInstances[hash] = {}; - - return hash; -} - -void ResizeScene( Scene* scene, const Camera* camera ) -{ - DestroyGeoBuffer( scene->geoBuffer ); - scene->geoBuffer = CreateGeoBuffer( camera->m_bufferWidth, camera->m_bufferHeight ); - - DestroySsaoBuffer( scene->ssaoBuffer ); - scene->ssaoBuffer = CreateSsaoBuffer( camera->m_bufferWidth, camera->m_bufferHeight ); - - CheckOpenGL(); -} - -void DrawDebugCapsule( Scene* scene, DebugCapsule* capsule, b3Transform transform, b3HexColor color, float alpha ) -{ - float radius = capsule->radius; - b3Vec3 c1 = capsule->center1; - b3Vec3 c2 = capsule->center2; - b3Vec3 origin = 0.5f * ( c1 + c2 ); - b3Vec3 d = c2 - c1; - float length = b3Length( d ); - - assert( length > 0.005f ); - - RGBA8 rgba8 = MakeRGBA8( color, alpha ); - b3Vec3 axis = b3Normalize( d ); - - // Capsule mesh is along x-axis. Build from two open hemispheres and an open cylinder. - - // Left cap - b3Quat qc1 = b3ComputeQuatBetweenUnitVectors( b3Vec3_axisX, -axis ); - - b3Transform xfCap1 = { - .p = b3TransformPoint( transform, c1 ), - .q = b3MulQuat( transform.q, qc1 ), - }; - - Matrix4 matrixCap1 = MakeMatrix4( xfCap1, radius ); - - // Right cap - b3Quat qc2 = b3ComputeQuatBetweenUnitVectors( b3Vec3_axisX, axis ); - - b3Transform xfCap2 = { - .p = b3TransformPoint( transform, c2 ), - .q = b3MulQuat( transform.q, qc2 ), - }; - - Matrix4 matrixCap2 = MakeMatrix4( xfCap2, radius ); - - // Middle - b3Transform xfMiddle = { - .p = b3TransformPoint( transform, origin ), - .q = b3MulQuat( transform.q, qc2 ), - }; - - Matrix4 matrixMiddle = MakeMatrix4( xfMiddle, { length, radius, radius } ); - - if ( alpha < 1.0f ) - { - scene->transparentOpenHemisphereInstances.push_back( { - .rgba8 = rgba8, - .matrix = matrixCap1, - } ); - - scene->transparentOpenHemisphereInstances.push_back( { - .rgba8 = rgba8, - .matrix = matrixCap2, - } ); - - scene->transparentOpenCylinderInstances.push_back( { - .rgba8 = rgba8, - .matrix = matrixMiddle, - } ); - } - else - { - scene->openHemisphereInstances.push_back( { - .rgba8 = rgba8, - .matrix = matrixCap1, - } ); - - scene->openHemisphereInstances.push_back( { - .rgba8 = rgba8, - .matrix = matrixCap2, - } ); - - scene->openCylinderInstances.push_back( { - .rgba8 = rgba8, - .matrix = matrixMiddle, - } ); - } -} - -void DrawDebugHull( Scene* scene, DebugHull* hull, b3Transform transform, b3HexColor color, float alpha ) -{ - b3Transform worldTransform = b3MulTransforms( transform, hull->transform ); - Matrix4 matrix = MakeMatrix4( worldTransform, 1.0f ); - InstanceData instanceData = { - .rgba8 = MakeRGBA8( color, alpha ), - .matrix = matrix, - }; - - uint32_t id = hull->id; - if ( alpha < 1.0f ) - { - assert( scene->transparentHullInstances.contains( id ) ); - scene->transparentHullInstances[id].push_back( instanceData ); - } - else - { - assert( scene->hullInstances.contains( id ) ); - scene->hullInstances[id].push_back( instanceData ); - } -} - -void DrawDebugMesh( Scene* scene, DebugMesh* mesh, b3Transform transform, b3HexColor color, float alpha ) -{ - b3Transform worldTransform = b3MulTransforms( transform, mesh->transform ); - Matrix4 matrix = MakeMatrix4( worldTransform, mesh->scale ); - InstanceData instanceData = { - .rgba8 = MakeRGBA8( color, alpha ), - .matrix = matrix, - }; - - uint32_t id = mesh->id; - assert( scene->meshInstances.contains( id ) ); - scene->meshInstances[id].push_back( instanceData ); -} - -void DrawDebugSphere( Scene* scene, DebugSphere* sphere, b3Transform transform, b3HexColor color, float alpha ) -{ - b3Vec3 center = sphere->center; - b3Transform xf = { - .p = b3TransformPoint( transform, center ), - .q = transform.q, - }; - Matrix4 matrix = MakeMatrix4( xf, sphere->radius ); - InstanceData instanceData = { - .rgba8 = MakeRGBA8( color, alpha ), - .matrix = matrix, - }; - - if ( alpha < 1.0f ) - { - scene->transparentSphereInstances.push_back( instanceData ); - } - else - { - scene->sphereInstances.push_back( instanceData ); - } -} - -void DrawDebugShape( Scene* scene, DebugShape* debugShape, b3Transform transform, b3HexColor color, float alpha ) -{ - switch ( debugShape->type ) - { - case DebugShapeType::capsule: - DrawDebugCapsule( scene, &debugShape->capsule, transform, color, alpha ); - break; - - case DebugShapeType::compound: - { - DebugCompound* compound = &debugShape->compound; - for ( int i = 0; i < compound->capsuleCount; ++i ) - { - DrawDebugCapsule( scene, compound->capsules + i, transform, color, alpha ); - } - - for ( int i = 0; i < compound->hullCount; ++i ) - { - DrawDebugHull( scene, compound->hulls + i, transform, color, alpha ); - } - - for ( int i = 0; i < compound->meshCount; ++i ) - { - DrawDebugMesh( scene, compound->meshes + i, transform, color, alpha ); - } - - for ( int i = 0; i < compound->sphereCount; ++i ) - { - DrawDebugSphere( scene, compound->spheres + i, transform, color, alpha ); - } - } - break; - - case DebugShapeType::hull: - DrawDebugHull( scene, &debugShape->hull, transform, color, alpha ); - break; - - case DebugShapeType::heightField: - { - Matrix4 matrix = MakeMatrix4( transform, 1.0f ); - InstanceData instanceData = { - .rgba8 = MakeRGBA8( color, alpha ), - .matrix = matrix, - }; - - uint32_t id = debugShape->heightField.id; - assert( scene->heightFieldInstances.contains( id ) ); - scene->heightFieldInstances[id].push_back( instanceData ); - } - break; - - case DebugShapeType::mesh: - { - b3Transform xf = b3MulTransforms( transform, debugShape->hull.transform ); - Matrix4 matrix = MakeMatrix4( xf, debugShape->mesh.scale ); - InstanceData instanceData = { - .rgba8 = MakeRGBA8( color, alpha ), - .matrix = matrix, - }; - - uint32_t id = debugShape->mesh.id; - assert( scene->meshInstances.contains( id ) ); - scene->meshInstances[id].push_back( instanceData ); - } - break; - - case DebugShapeType::sphere: - DrawDebugSphere( scene, &debugShape->sphere, transform, color, alpha ); - break; - - default: - assert( false ); - break; - } -} - -static void DrawMeshInstances( InstanceShape shape, const InstanceData* instances, int count, bool cull ) -{ - if ( count == 0 ) - { - return; - } - - if ( cull == false ) - { - glDisable( GL_CULL_FACE ); - } - - glBindVertexArray( shape.triangleArrayId ); - glBindBuffer( GL_ARRAY_BUFFER, shape.triangleBufferIds[1] ); - - int base = 0; - while ( count > 0 ) - { - int batchCount = b3MinInt( count, s_batchSize ); - - glBufferData( GL_ARRAY_BUFFER, s_batchSize * sizeof( InstanceData ), nullptr, GL_DYNAMIC_DRAW ); - glBufferSubData( GL_ARRAY_BUFFER, 0, batchCount * sizeof( InstanceData ), &instances[base] ); - glDrawArraysInstanced( GL_TRIANGLES, 0, 3 * shape.triangleCount, batchCount ); - - // CheckOpenGL(); - - count -= s_batchSize; - base += s_batchSize; - } - - glBindBuffer( GL_ARRAY_BUFFER, 0 ); - glBindVertexArray( 0 ); - - if ( cull == false ) - { - glEnable( GL_CULL_FACE ); - } -} - -static void DrawEdgeInstances( InstanceShape shape, const InstanceData* instances, int count ) -{ - if ( count == 0 ) - { - return; - } - - glBindVertexArray( shape.edgeArrayId ); - glBindBuffer( GL_ARRAY_BUFFER, shape.edgeBufferIds[1] ); - - int base = 0; - while ( count > 0 ) - { - int batchCount = b3MinInt( count, s_batchSize ); - - glBufferData( GL_ARRAY_BUFFER, s_batchSize * sizeof( InstanceData ), nullptr, GL_DYNAMIC_DRAW ); - glBufferSubData( GL_ARRAY_BUFFER, 0, batchCount * sizeof( InstanceData ), &instances[base] ); - glDrawArraysInstanced( GL_LINES, 0, 2 * shape.edgeCount, batchCount ); - - // CheckOpenGL(); - - count -= s_batchSize; - base += s_batchSize; - } - - glBindBuffer( GL_ARRAY_BUFFER, 0 ); - glBindVertexArray( 0 ); -} - -static void DrawMeshes( Scene* scene, const Matrix4& view, const Matrix4& projection, bool forShadow ) -{ - if ( forShadow == true ) - { - // Receiver-plane depth bias in the deferred shader handles per-pixel bias - // precisely, so the shadow pass needs no polygon offset. Adding one back - // reintroduces "Peter Panning" — a visible gap between objects and their - // contact shadows. - glDisable( GL_POLYGON_OFFSET_FILL ); - - glUseProgram( scene->meshShadowShader ); - SetUniformMatrix4( scene->meshShadowShader, "lightSpaceMatrix", view ); - } - else - { - glEnable( GL_POLYGON_OFFSET_FILL ); - glPolygonOffset( 2.0f, 2.0f ); - - glUseProgram( scene->meshShader ); - SetUniformMatrix4( scene->meshShader, "view", view ); - SetUniformMatrix4( scene->meshShader, "projection", projection ); - } - - DrawMeshInstances( scene->sphere, scene->sphereInstances.data(), (int)scene->sphereInstances.size(), true ); - DrawMeshInstances( scene->openHemisphere, scene->openHemisphereInstances.data(), (int)scene->openHemisphereInstances.size(), - true ); - DrawMeshInstances( scene->openCylinder, scene->openCylinderInstances.data(), (int)scene->openCylinderInstances.size(), true ); - - for ( std::unordered_map>::iterator instances = scene->heightFieldInstances.begin(); - instances != scene->heightFieldInstances.end(); ++instances ) - { - uint32_t id = instances->first; - InstanceShape shape = scene->sharedHeightFields.at( id ); - DrawMeshInstances( shape, instances->second.data(), (int)instances->second.size(), true ); - } - - for ( std::unordered_map>::iterator instances = scene->hullInstances.begin(); - instances != scene->hullInstances.end(); ++instances ) - { - uint32_t id = instances->first; - InstanceShape shape = scene->sharedHulls.at( id ); - DrawMeshInstances( shape, instances->second.data(), (int)instances->second.size(), true ); - } - - for ( std::unordered_map>::iterator instances = scene->meshInstances.begin(); - instances != scene->meshInstances.end(); ++instances ) - { - uint32_t id = instances->first; - InstanceShape shape = scene->sharedMeshes.at( id ); - DrawMeshInstances( shape, instances->second.data(), (int)instances->second.size(), false ); - } - - glDisable( GL_POLYGON_OFFSET_FILL ); -} - -static void DrawTransparentShapes( Scene* scene, const Matrix4& view, const Matrix4& projection, b3Vec3 sunDirWorld, - b3Vec3 cameraPos ) -{ - glUseProgram( scene->meshForwardShader ); - SetUniformVec3( scene->meshForwardShader, "sunDirWorld", sunDirWorld ); - SetUniformVec3( scene->meshForwardShader, "cameraPos", cameraPos ); - - SetUniformMatrix4( scene->meshForwardShader, "view", view ); - SetUniformMatrix4( scene->meshForwardShader, "projection", projection ); - - glEnable( GL_POLYGON_OFFSET_FILL ); - glPolygonOffset( 2.0, 2.0 ); - - glCullFace( GL_BACK ); - glEnable( GL_CULL_FACE ); - glEnable( GL_BLEND ); - glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); - glDepthMask( GL_FALSE ); - - DrawMeshInstances( scene->sphere, scene->transparentSphereInstances.data(), (int)scene->transparentSphereInstances.size(), - true ); - DrawMeshInstances( scene->openHemisphere, scene->transparentOpenHemisphereInstances.data(), - (int)scene->transparentOpenHemisphereInstances.size(), true ); - DrawMeshInstances( scene->openCylinder, scene->transparentOpenCylinderInstances.data(), - (int)scene->transparentOpenCylinderInstances.size(), true ); - - for ( std::unordered_map>::iterator hulls = scene->transparentHullInstances.begin(); - hulls != scene->transparentHullInstances.end(); ++hulls ) - { - uint32_t id = hulls->first; - InstanceShape shape = scene->sharedHulls.at( id ); - DrawMeshInstances( shape, hulls->second.data(), (int)hulls->second.size(), true ); - } - - glDisable( GL_POLYGON_OFFSET_FILL ); - glDisable( GL_BLEND ); - glDepthMask( GL_TRUE ); -} - -#if 0 -static void DrawObjects( Scene* scene, uint32_t shader, bool isShadow ) -{ - CheckOpenGL(); - - // glFrontFace( GL_CCW ); - // glDepthFunc( GL_LESS ); - // glCullFace( GL_BACK ); - glEnable( GL_POLYGON_OFFSET_FILL ); - glPolygonOffset( 2.0, 2.0 ); - - for ( int i = 0; i < scene->uniqueShapes.size(); ++i ) - { - UniqueShape& shape = scene->uniqueShapes[i]; - if ( isShadow && shape.mesh->shadowCaster == false ) - { - continue; - } - - if ( shape.color.a < 1.0f ) - { - continue; - } - - SetUniformMatrix4( shader, "model", shape.matrix ); - SetUniformColor( shader, "objectColor", shape.color ); - SetUniformBool( shader, "invertedNormals", false ); - CheckOpenGL(); - - glBindVertexArray( shape.mesh->vertexArrayId ); - glDrawArrays( GL_TRIANGLES, 0, 3 * shape.mesh->triangleCount ); - glBindVertexArray( 0 ); - - CheckOpenGL(); - } - - glDisable( GL_POLYGON_OFFSET_FILL ); -} -#endif - -static void DrawLines( Scene* scene, const Matrix4& view, const Matrix4& projection ) -{ - // WARNING: very slow - // glEnable( GL_LINE_SMOOTH ); - - glEnable( GL_BLEND ); - glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); - - glUseProgram( scene->meshEdgeShader ); - SetUniformMatrix4( scene->meshEdgeShader, "view", view ); - SetUniformMatrix4( scene->meshEdgeShader, "projection", projection ); - - for ( std::unordered_map>::iterator instances = scene->heightFieldInstances.begin(); - instances != scene->heightFieldInstances.end(); ++instances ) - { - uint32_t id = instances->first; - InstanceShape shape = scene->sharedHeightFields.at( id ); - DrawEdgeInstances( shape, instances->second.data(), (int)instances->second.size() ); - } - - for ( std::unordered_map>::iterator instances = scene->hullInstances.begin(); - instances != scene->hullInstances.end(); ++instances ) - { - uint32_t id = instances->first; - InstanceShape shape = scene->sharedHulls.at( id ); - DrawEdgeInstances( shape, instances->second.data(), (int)instances->second.size() ); - } - - for ( std::unordered_map>::iterator instances = scene->meshInstances.begin(); - instances != scene->meshInstances.end(); ++instances ) - { - uint32_t id = instances->first; - InstanceShape shape = scene->sharedMeshes.at( id ); - DrawEdgeInstances( shape, instances->second.data(), (int)instances->second.size() ); - } - - glDisable( GL_BLEND ); -} - -static Matrix4 LookAt( b3Vec3 eye, b3Vec3 center, b3Vec3 up ) -{ - // Build view transform - b3Vec3 axisZ = b3Normalize( center - eye ); - b3Vec3 axisX = b3Normalize( b3Cross( axisZ, up ) ); - b3Vec3 axisY = b3Cross( axisX, axisZ ); - - // Negate - axisZ = -axisZ; - - Matrix4 out; - out.cx = { axisX.x, axisY.x, axisZ.x, 0.0f }; - out.cy = { axisX.y, axisY.y, axisZ.y, 0.0f }; - out.cz = { axisX.z, axisY.z, axisZ.z, 0.0f }; - out.cw = { -b3Dot( axisX, eye ), -b3Dot( axisY, eye ), -b3Dot( axisZ, eye ), 1.0f }; - - return out; -} - -void DrawScene( Scene* scene, Camera* camera ) -{ - // float temp1[2] = {}; - // glGetFloatv( GL_ALIASED_LINE_WIDTH_RANGE, temp1 ); - - // float temp2[2] = {}; - // glGetFloatv( GL_SMOOTH_LINE_WIDTH_RANGE, temp2 ); - - // CheckOpenGL(); - // glDisable( GL_LINE_SMOOTH ); - - // GLboolean test = glIsEnabled( GL_LINE_SMOOTH ); - // B3_UNUSED( test ); - - // todo wirefame - // glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); - - glDepthFunc( GL_LESS ); - - // Get camera matrices - Matrix4 projection = camera->GetProjectionMatrix(); - Matrix4 view = camera->GetViewMatrix(); - Matrix4 cameraMatrix = camera->GetWorldMatrix(); - - // 1. render shadow map — fit the ortho frustum to the camera's view frustum - // each frame so all shadow-map texels go to what the camera can actually see. - Matrix4 lightView = LookAt( scene->lightPosition, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f } ); - - // Scale the shadow region with camera radius so large scenes still get - // covered. Trades off texel density at long camera distances — true large - // scenes want cascaded shadow maps, but a single fitted cascade plus an edge - // fade in the shader keeps the cutoff invisible at this scale. - // - // In third-person the radius is the orbit distance to the pivot, so - // 1.5 * radius is a tight cover of the actual scene of interest and a small - // floor (8) gives great texel density at close orbits. In first-person the - // radius is a stale value — the camera moves m_position directly while - // m_radius keeps whatever it was last set to. Fall back to a wider fixed - // floor there so the shadow frustum still covers the scene the camera can - // see, at the cost of some texel density. - float minShadowDistance = camera->m_thirdPerson ? 8.0f : 60.0f; - const float shadowDistance = b3ClampFloat( 1.5f * camera->m_radius, minShadowDistance, 500.0f ); - float shadowNear = camera->m_nearPlane; - float shadowFar = b3MinFloat( shadowDistance, camera->m_farPlane ); - - b3Vec3 lookDir = -camera->m_forward; // m_forward is the camera-z axis (away from view) - b3Vec3 nearC = camera->m_position + shadowNear * lookDir; - b3Vec3 farC = camera->m_position + shadowFar * lookDir; - float nearH = shadowNear * camera->m_tanY; - float nearW = camera->m_ratio * nearH; - float farH = shadowFar * camera->m_tanY; - float farW = camera->m_ratio * farH; - - b3Vec3 frustumCorners[8] = { - nearC + ( -nearW ) * camera->m_right + ( -nearH ) * camera->m_up, - nearC + (nearW)*camera->m_right + ( -nearH ) * camera->m_up, - nearC + (nearW)*camera->m_right + (nearH)*camera->m_up, - nearC + ( -nearW ) * camera->m_right + (nearH)*camera->m_up, - farC + ( -farW ) * camera->m_right + ( -farH ) * camera->m_up, - farC + (farW)*camera->m_right + ( -farH ) * camera->m_up, - farC + (farW)*camera->m_right + (farH)*camera->m_up, - farC + ( -farW ) * camera->m_right + (farH)*camera->m_up, - }; - - Vector4 c0 = MulMV( lightView, { frustumCorners[0].x, frustumCorners[0].y, frustumCorners[0].z, 1.0f } ); - float minX = c0.x, maxX = c0.x; - float minY = c0.y, maxY = c0.y; - float minZ = c0.z, maxZ = c0.z; - for ( int i = 1; i < 8; ++i ) - { - Vector4 c = MulMV( lightView, { frustumCorners[i].x, frustumCorners[i].y, frustumCorners[i].z, 1.0f } ); - minX = b3MinFloat( minX, c.x ); - maxX = b3MaxFloat( maxX, c.x ); - minY = b3MinFloat( minY, c.y ); - maxY = b3MaxFloat( maxY, c.y ); - minZ = b3MinFloat( minZ, c.z ); - maxZ = b3MaxFloat( maxZ, c.z ); - } - - // Texel-snap the fitted ortho origin so the shadow texel grid stays - // world-locked frame-to-frame. Without this, sub-texel drift as the camera - // moves creates a wandering pattern on lit surfaces that reads as banding. - // Span is held constant within a frame, so each shadow texel maps to exactly - // (texelX, texelY) world-space units perpendicular to the light direction. - float texelX = ( maxX - minX ) / float( shadowWidth ); - float texelY = ( maxY - minY ) / float( shadowHeight ); - minX = floorf( minX / texelX ) * texelX; - minY = floorf( minY / texelY ) * texelY; - maxX = minX + texelX * float( shadowWidth ); - maxY = minY + texelY * float( shadowHeight ); - - // Pull the near plane back so off-camera geometry between the light and the - // view frustum still casts shadows into the visible region. - const float zPad = 50.0f; - float lightNearPlane = -maxZ - zPad; - float lightFarPlane = -minZ; - - Matrix4 lightProjection = MakeOrthographicMatrix( minX, maxX, minY, maxY, lightNearPlane, lightFarPlane ); - Matrix4 lightSpaceMatrix = MulMM( lightProjection, lightView ); - - // World-space size of one shadow texel (light view is rigid, so light-space - // distances equal world-space distances). The deferred shader uses this for - // normal-offset bias; max() keeps the offset conservative when texels are - // non-square. - float worldTexelSize = b3MaxFloat( texelX, texelY ); - - // render scene from light's point of view - glUseProgram( scene->shadowShader ); - SetUniformMatrix4( scene->shadowShader, "lightSpaceMatrix", lightSpaceMatrix ); - CheckOpenGL(); - - glViewport( 0, 0, shadowWidth, shadowHeight ); - glBindFramebuffer( GL_FRAMEBUFFER, scene->depthMapFBO ); - glClear( GL_DEPTH_BUFFER_BIT ); - glActiveTexture( GL_TEXTURE0 ); - - // Back-face cull during the shadow pass: combined with slope-scaled polygon - // offset (applied in DrawMeshes) this eliminates self-shadow acne on solid - // hulls without the gap that front-face culling introduces. - glCullFace( GL_BACK ); - glEnable( GL_CULL_FACE ); - - CheckOpenGL(); - - // DrawObjects( scene, scene->shadowShader, true ); - DrawMeshes( scene, lightSpaceMatrix, Matrix4{}, true ); - - glBindFramebuffer( GL_FRAMEBUFFER, 0 ); - - // reset viewport - glViewport( 0, 0, camera->m_bufferWidth, camera->m_bufferHeight ); - glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); - - // 2. geometry pass: render scene's geometry/color data into geoBuffer - BindGeoBuffer( scene->geoBuffer ); - glUseProgram( scene->geometryShader ); - SetUniformMatrix4( scene->geometryShader, "view", view ); - SetUniformMatrix4( scene->geometryShader, "projection", projection ); - - glCullFace( GL_BACK ); - glEnable( GL_CULL_FACE ); - - // DrawObjects( scene, scene->geometryShader, false ); - DrawMeshes( scene, view, projection, false ); - - glBindFramebuffer( GL_FRAMEBUFFER, 0 ); - - // 3. generate SSAO texture (full resolution — sharp silhouettes) - BindSsaoBuffer( scene->ssaoBuffer ); - glUseProgram( scene->ssaoShader ); - SetUniformMatrix4( scene->ssaoShader, "projection", projection ); - SetUniformFloat( scene->ssaoShader, "radius", scene->ao.radius ); - SetUniformFloat( scene->ssaoShader, "bias", scene->ao.bias ); - SetUniformFloat( scene->ssaoShader, "minScale", scene->ao.minScale ); - { - int loc = glGetUniformLocation( scene->ssaoShader, "noiseScale" ); - glUniform2f( loc, float( camera->m_bufferWidth ) / 4.0f, float( camera->m_bufferHeight ) / 4.0f ); - } - SetSsaoSamples( scene->ssaoBuffer, scene->ssaoShader ); - BindGeoTextures( scene->geoBuffer ); - BindSsaoTextures( scene->ssaoBuffer ); - DrawQuad(); - glBindFramebuffer( GL_FRAMEBUFFER, 0 ); - - CheckOpenGL(); - - // 4. bilateral blur of SSAO — depth-weighted so the blur doesn't leak across silhouettes. - BindSsaoBlurBuffer( scene->ssaoBuffer ); - glUseProgram( scene->ssaoBlurShader ); - BindSsaoColorTexture( scene->ssaoBuffer ); - BindGeoPosition( scene->geoBuffer, 1 ); - DrawQuad(); - glBindFramebuffer( GL_FRAMEBUFFER, 0 ); - - CheckOpenGL(); - - // 5. lighting pass: calculate lighting by iterating over a screen filled quad pixel-by-pixel using the geoBuffer's content. - glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); - glUseProgram( scene->deferredShader ); - BindGeoTextures( scene->geoBuffer ); - BindSsaoBlurTexture( scene->ssaoBuffer ); - - glActiveTexture( GL_TEXTURE4 ); - glBindTexture( GL_TEXTURE_2D, scene->depthMap ); - - SetUniformBool( scene->deferredShader, "useSSAO", scene->useSSAO ); - SetUniformBool( scene->deferredShader, "useShadow", scene->useShadow ); - SetUniformBool( scene->deferredShader, "useGrid", scene->useGrid ); - SetUniformFloat( scene->deferredShader, "aoPower", scene->ao.power ); - SetUniformFloat( scene->deferredShader, "aoDirect", scene->ao.direct ); - SetUniformBool( scene->deferredShader, "aoOnly", scene->ao.aoOnly ); - - // Sun direction in world space (from scene toward sun) — shared with the shadow projection, - // which already uses scene->lightPosition as the light source. - b3Vec3 sunDirWorld = b3Normalize( scene->lightPosition ); - SetUniformVec3( scene->deferredShader, "sunDirWorld", sunDirWorld ); - - // View-ray reconstruction parameters for the sky/fog path. - SetUniformFloat( scene->deferredShader, "tanHalfFovY", camera->m_tanY ); - SetUniformFloat( scene->deferredShader, "aspectRatio", camera->m_ratio ); - - SetUniformMatrix4( scene->deferredShader, "lightSpaceMatrix", lightSpaceMatrix ); - SetUniformMatrix4( scene->deferredShader, "cameraMatrix", cameraMatrix ); - SetUniformFloat( scene->deferredShader, "worldTexelSize", worldTexelSize ); - SetUniformFloat( scene->deferredShader, "lightZRange", lightFarPlane - lightNearPlane ); - - // finally render quad - DrawQuad(); - - CheckOpenGL(); - - // 5.5. Copy geometry depth to the default framebuffer using a depth-only draw pass. - // This avoids glBlitFramebuffer which is very slow on Apple Silicon. - glUseProgram( scene->depthCopyShader ); - BindGeoDepthTexture( scene->geoBuffer, 0 ); - glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE ); - glDepthFunc( GL_ALWAYS ); - glDepthMask( GL_TRUE ); - DrawQuad(); - glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE ); - glDepthFunc( GL_LESS ); - - CheckOpenGL(); - - // 6. forward render lights on top of scene - // glUseProgram( scene->forwardShader ); - // SetUniformMatrix4( scene->forwardShader, "projection", projection ); - // SetUniformMatrix4( scene->forwardShader, "view", view ); - - // b3Transform transform; - // transform.p = scene->lightPosition; - // transform.q = b3Quat_identity; - // Matrix4 m = MakeMatrix4( transform, 0.25f ); - // SetUniformMatrix4( scene->forwardShader, "model", m ); - // SetUniformVec3( scene->forwardShader, "color", { 1.0f, 1.0f, 1.0f } ); - // DrawCube( scene, transform, b3_colorWhite, view, projection ); - - // Draw mesh edges - DrawLines( scene, view, projection ); - - // Draw transparent hulls - DrawTransparentShapes( scene, view, projection, b3Normalize( scene->lightPosition ), camera->GetPosition() ); - - // 7. Debug draw lines and points - FlushLines( scene->lineDraw, camera ); - FlushPoints( scene->pointDraw, camera ); - - // 8. Clear instances - // scene->uniqueShapes.clear(); - scene->sphereInstances.clear(); - scene->openHemisphereInstances.clear(); - scene->openCylinderInstances.clear(); - - // Clear instances - for ( std::unordered_map>::iterator instance = scene->heightFieldInstances.begin(); - instance != scene->heightFieldInstances.end(); ++instance ) - { - instance->second.clear(); - } - - for ( std::unordered_map>::iterator instance = scene->hullInstances.begin(); - instance != scene->hullInstances.end(); ++instance ) - { - instance->second.clear(); - } - - for ( std::unordered_map>::iterator instance = scene->meshInstances.begin(); - instance != scene->meshInstances.end(); ++instance ) - { - instance->second.clear(); - } - - scene->transparentSphereInstances.clear(); - scene->transparentOpenHemisphereInstances.clear(); - scene->transparentOpenCylinderInstances.clear(); - - for ( std::unordered_map>::iterator hulls = scene->transparentHullInstances.begin(); - hulls != scene->transparentHullInstances.end(); ++hulls ) - { - hulls->second.clear(); - } -} - -void DrawDebugCube( Scene* scene, b3Transform transform, RGBAf color ) -{ - int index = (int)scene->debugCubes.size(); - scene->debugCubes[index] = { transform, color }; -} - -void EnableShadows( Scene* scene, bool useShadows ) -{ - scene->useShadow = useShadows; -} - -bool AreShadowsEnabled( Scene* scene ) -{ - return scene->useShadow; -} - -void EnableSSAO( Scene* scene, bool enable ) -{ - scene->useSSAO = enable; -} - -bool IsSSAOEnabled( Scene* scene ) -{ - return scene->useSSAO; -} - -void EnableGrid( Scene* scene, bool enable ) -{ - scene->useGrid = enable; -} - -bool IsGridEnabled( Scene* scene ) -{ - return scene->useGrid; -} - -SceneAOSettings* GetAOSettings( Scene* scene ) -{ - return &scene->ao; -} - -void DrawPoint( Scene* scene, b3Vec3 point, float size, b3HexColor color ) -{ - AddPoint( scene->pointDraw, point, size, color ); -} - -void DrawLine( Scene* scene, b3Vec3 point1, b3Vec3 point2, b3HexColor color ) -{ - AddLine( scene->lineDraw, point1, point2, color ); -} - -void DrawPlane( Scene* scene, b3Vec3 normal, b3Vec3 point, b3HexColor color ) -{ - b3Vec3 perp1 = b3Perp( normal ); - b3Vec3 perp2 = b3Cross( perp1, normal ); - b3Vec3 p = point; - float a = 1.0f; - b3Vec3 p1 = p + a * perp1 + a * perp2; - b3Vec3 p2 = p - a * perp1 + a * perp2; - b3Vec3 p3 = p - a * perp1 - a * perp2; - b3Vec3 p4 = p + a * perp1 - a * perp2; - - AddLine( scene->lineDraw, p1, p2, color ); - AddLine( scene->lineDraw, p2, p3, color ); - AddLine( scene->lineDraw, p3, p4, color ); - AddLine( scene->lineDraw, p4, p1, color ); - AddLine( scene->lineDraw, p, p + 0.5f * normal, color ); - AddPoint( scene->pointDraw, p, 10.0f, color ); -} - -void DrawArrow( Scene* scene, b3Vec3 point1, b3Vec3 point2, float size, b3HexColor color ) -{ - AddLine( scene->lineDraw, point1, point2, color ); - b3Vec3 axis = b3Normalize( point2 - point1 ); - b3Vec3 perp = b3Perp( axis ); - AddLine( scene->lineDraw, point2, point2 - size * axis + size * perp, color ); - AddLine( scene->lineDraw, point2, point2 - size * axis - size * perp, color ); -} - -void DrawBounds( Scene* scene, b3AABB bounds, float extension, b3HexColor color ) -{ - LineDraw* draw = scene->lineDraw; - - b3Vec3 extents = b3AABB_Extents( bounds ); - b3Vec3 center = b3AABB_Center( bounds ); - float hx = extents.x + extension; - float hy = extents.y + extension; - float hz = extents.z + extension; - - b3Vec3 p1 = b3Vec3{ -hx, -hy, hz } + center; - b3Vec3 p2 = b3Vec3{ -hx, hy, hz } + center; - b3Vec3 p3 = b3Vec3{ -hx, hy, -hz } + center; - b3Vec3 p4 = b3Vec3{ -hx, -hy, -hz } + center; - - b3Vec3 p5 = b3Vec3{ hx, -hy, hz } + center; - b3Vec3 p6 = b3Vec3{ hx, hy, hz } + center; - b3Vec3 p7 = b3Vec3{ hx, hy, -hz } + center; - b3Vec3 p8 = b3Vec3{ hx, -hy, -hz } + center; - - // negative x loop - AddLine( draw, p1, p2, color ); - AddLine( draw, p2, p3, color ); - AddLine( draw, p3, p4, color ); - AddLine( draw, p4, p1, color ); - - // positive x loop - AddLine( draw, p5, p6, color ); - AddLine( draw, p6, p7, color ); - AddLine( draw, p7, p8, color ); - AddLine( draw, p8, p5, color ); - - // connect loops - AddLine( draw, p1, p5, color ); - AddLine( draw, p2, p6, color ); - AddLine( draw, p3, p7, color ); - AddLine( draw, p4, p8, color ); -} - -void DrawBox( Scene* scene, b3Vec3 extents, b3Transform transform, b3HexColor color ) -{ - LineDraw* draw = scene->lineDraw; - - float hx = extents.x; - float hy = extents.y; - float hz = extents.z; - - b3Vec3 p1 = b3TransformPoint( transform, { -hx, -hy, hz } ); - b3Vec3 p2 = b3TransformPoint( transform, { -hx, hy, hz } ); - b3Vec3 p3 = b3TransformPoint( transform, { -hx, hy, -hz } ); - b3Vec3 p4 = b3TransformPoint( transform, { -hx, -hy, -hz } ); - - b3Vec3 p5 = b3TransformPoint( transform, { hx, -hy, hz } ); - b3Vec3 p6 = b3TransformPoint( transform, { hx, hy, hz } ); - b3Vec3 p7 = b3TransformPoint( transform, { hx, hy, -hz } ); - b3Vec3 p8 = b3TransformPoint( transform, { hx, -hy, -hz } ); - - // negative x loop - AddLine( draw, p1, p2, color ); - AddLine( draw, p2, p3, color ); - AddLine( draw, p3, p4, color ); - AddLine( draw, p4, p1, color ); - - // positive x loop - AddLine( draw, p5, p6, color ); - AddLine( draw, p6, p7, color ); - AddLine( draw, p7, p8, color ); - AddLine( draw, p8, p5, color ); - - // connect loops - AddLine( draw, p1, p5, color ); - AddLine( draw, p2, p6, color ); - AddLine( draw, p3, p7, color ); - AddLine( draw, p4, p8, color ); -} - -void DrawFace( Scene* scene, b3Vec3 vertex1, b3Vec3 vertex2, b3Vec3 vertex3, b3HexColor color ) -{ - LineDraw* draw = scene->lineDraw; - - AddLine( draw, vertex1, vertex2, color ); - AddLine( draw, vertex2, vertex3, color ); - AddLine( draw, vertex3, vertex1, color ); -} diff --git a/samples/scene.h b/samples/scene.h deleted file mode 100644 index 837bade..0000000 --- a/samples/scene.h +++ /dev/null @@ -1,147 +0,0 @@ -// SPDX-FileCopyrightText: 2025 Erin Catto -// SPDX-License-Identifier: MIT - -#pragma once - -#include "utility.h" - -#include "box3d/math_functions.h" - -struct Camera; -struct b3DebugShape; -struct Scene; -struct UniqueMesh; - -enum struct DebugShapeType -{ - capsule, - compound, - hull, - heightField, - mesh, - sphere, -}; - -struct DebugSphere -{ - b3Vec3 center; - float radius; -}; - -struct DebugCapsule -{ - b3Vec3 center1, center2; - float radius; -}; - -struct DebugHeightField -{ - uint32_t id; -}; - -struct DebugHull -{ - b3Transform transform; - uint32_t id; -}; - -struct DebugMesh -{ - b3Transform transform; - b3Vec3 scale; - uint32_t id; -}; - -struct DebugCompound -{ - DebugCapsule* capsules; - int capsuleCount; - - DebugHull* hulls; - int hullCount; - - DebugMesh* meshes; - int meshCount; - - DebugSphere* spheres; - int sphereCount; -}; - -struct DebugShape -{ - DebugShapeType type; - b3BodyType bodyType; - union - { - DebugCapsule capsule; - DebugCompound compound; - DebugHeightField heightField; - DebugHull hull; - DebugMesh mesh; - DebugSphere sphere; - }; -}; - -Scene* CreateScene( const Camera* camera, Arena arena ); -void DestroyScene( Scene* scene ); - -// Register a hull and get an id to render it later -uint32_t CreateInstanceHull( Scene* scene, const b3Hull* hull, Arena arena ); - -// Register a mesh and get an id to render it later -uint32_t CreateInstanceMesh( Scene* scene, const b3MeshData* meshData, Arena arena ); - -// Register a height field and get an id to render it later -uint32_t CreateInstanceHeightField( Scene* scene, const b3HeightField* heightField, Arena arena ); - -// This should be called when a sample is destroyed to avoid leaking instances -void DestroySharedMeshes( Scene* scene ); - -void ResizeScene( Scene* scene, const Camera* camera ); - -// UniqueMesh CreateUniqueMesh( const b3Vec3* vertexPositions, const b3Vec3* vertexNormals, int triangleCount, -// const int* triangleIndices, const Edge* edges, int edgeCount, const int* materials, -// Arena arena ); -// void DestroyUniqueMesh( UniqueMesh* shape ); - -void DrawDebugShape( Scene* scene, DebugShape* debugShape, b3Transform transform, b3HexColor color, float alpha ); - -void DrawScene( Scene* scene, Camera* camera ); - -void DrawCube( Scene* scene, b3Transform transform, b3HexColor color, const Matrix4& view, const Matrix4& projection ); - -void DrawDebugCube( Scene* scene, b3Transform transform, b3HexColor color ); - -struct SceneAOSettings -{ - float radius; - float bias; - float minScale; - float power; - float direct; - bool aoOnly; -}; - -// Mutable view of the scene's SSAO parameters. Pointer is valid for the lifetime of the scene. -SceneAOSettings* GetAOSettings( Scene* scene ); - -void EnableShadows( Scene* scene, bool useShadows ); -bool AreShadowsEnabled( Scene* scene ); - -void EnableSSAO( Scene* scene, bool enable ); -bool IsSSAOEnabled( Scene* scene ); - -// World-space ground grid drawn on near-horizontal upward faces. Useful on -// flat-box ground; should be disabled for samples whose ground is a mesh -// (the mesh's triangle wireframe already provides the grid signal). -void EnableGrid( Scene* scene, bool enable ); -bool IsGridEnabled( Scene* scene ); - -void DrawPoint( Scene* scene, b3Vec3 point, float size, b3HexColor color ); -void DrawLine( Scene* scene, b3Vec3 point1, b3Vec3 point2, b3HexColor color ); -void DrawPlane( Scene* scene, b3Vec3 normal, b3Vec3 point, b3HexColor color ); -void DrawArrow( Scene* scene, b3Vec3 point1, b3Vec3 point2, float size, b3HexColor color ); - -void DrawBounds( Scene* scene, b3AABB bounds, float extension, b3HexColor color ); -void DrawBox( Scene* scene, b3Vec3 extents, b3Transform transform, b3HexColor color ); -void DrawFace( Scene* scene, b3Vec3 vertex1, b3Vec3 vertex2, b3Vec3 vertex3, b3HexColor color ); diff --git a/samples/shader.cpp b/samples/shader.cpp deleted file mode 100644 index c904fd1..0000000 --- a/samples/shader.cpp +++ /dev/null @@ -1,465 +0,0 @@ -// SPDX-FileCopyrightText: 2025 Erin Catto -// SPDX-License-Identifier: MIT - -#if defined( _MSC_VER ) && !defined( _CRT_SECURE_NO_WARNINGS ) - #define _CRT_SECURE_NO_WARNINGS -#endif - -#include "shader.h" - -#include -#include -#include -#include -#include -#include - -#include - -void CheckOpenGL() -{ - GLenum errCode = glGetError(); - if ( errCode != GL_NO_ERROR ) - { - fprintf( stderr, "OpenGL error = %d\n", errCode ); - assert( false ); - } -} - -void DumpGLInfo( bool dumpExtensions ) -{ - const GLubyte* renderer = glGetString( GL_RENDERER ); - const GLubyte* vendor = glGetString( GL_VENDOR ); - const GLubyte* version = glGetString( GL_VERSION ); - const GLubyte* glslVersion = glGetString( GL_SHADING_LANGUAGE_VERSION ); - - int major, minor; - glGetIntegerv( GL_MAJOR_VERSION, &major ); - glGetIntegerv( GL_MINOR_VERSION, &minor ); - - printf( "-------------------------------------------------------------\n" ); - printf( "GL Vendor : %s\n", vendor ); - printf( "GL Renderer : %s\n", renderer ); - printf( "GL Version : %s\n", version ); - printf( "GL Version : %d.%d\n", major, minor ); - printf( "GLSL Version : %s\n", glslVersion ); - printf( "-------------------------------------------------------------\n" ); - - if ( dumpExtensions ) - { - int nExtensions; - glGetIntegerv( GL_NUM_EXTENSIONS, &nExtensions ); - for ( int i = 0; i < nExtensions; i++ ) - { - printf( "%s\n", glGetStringi( GL_EXTENSIONS, i ) ); - } - } -} - -static void PrintLog( uint32_t object ) -{ - int length = 0; - if ( glIsShader( object ) ) - { - glGetShaderiv( object, GL_INFO_LOG_LENGTH, &length ); - } - else if ( glIsProgram( object ) ) - { - glGetProgramiv( object, GL_INFO_LOG_LENGTH, &length ); - } - else - { - fprintf( stderr, "printlog: Not a shader or a program\n" ); - return; - } - - char* log = static_cast( malloc( length * sizeof( char ) ) ); - - if ( glIsShader( object ) ) - { - glGetShaderInfoLog( object, length, nullptr, log ); - } - else if ( glIsProgram( object ) ) - { - glGetProgramInfoLog( object, length, nullptr, log ); - } - - fprintf( stderr, "%s", log ); - free( log ); -} - -static uint32_t CreateShaderFromString( const char* source, GLenum type ) -{ - uint32_t shader = glCreateShader( type ); - const char* sources[] = { source }; - - glShaderSource( shader, 1, sources, nullptr ); - glCompileShader( shader ); - - int success = GL_FALSE; - glGetShaderiv( shader, GL_COMPILE_STATUS, &success ); - - if ( success == GL_FALSE ) - { - fprintf( stderr, "Error compiling shader of type %d!\n", type ); - PrintLog( shader ); - } - - return shader; -} - -static bool ReadFile( const char* filename, std::string& out ) -{ - FILE* file = fopen( filename, "rb" ); - if ( file == nullptr ) - { - return false; - } - - fseek( file, 0, SEEK_END ); - long size = ftell( file ); - fseek( file, 0, SEEK_SET ); - - out.resize( (size_t)size ); - if ( size > 0 ) - { - fread( &out[0], 1, (size_t)size, file ); - } - fclose( file ); - return true; -} - -static std::string DirectoryOf( const char* path ) -{ - const char* lastSep = nullptr; - for ( const char* p = path; *p; ++p ) - { - if ( *p == '/' || *p == '\\' ) - { - lastSep = p; - } - } - return lastSep ? std::string( path, lastSep + 1 ) : std::string(); -} - -// Substitutes lines of the form `#include "name"` with the contents of that -// file (resolved relative to `baseDir`). Recursive but not cyclic-safe — keep -// the include graph a DAG. Emits `#line` directives so compile errors keep -// readable line numbers in both the parent and the included file. -static bool ResolveIncludes( const std::string& source, const std::string& baseDir, std::string& out ) -{ - out.reserve( out.size() + source.size() * 2 ); - - int lineNo = 1; - size_t i = 0; - while ( i < source.size() ) - { - size_t lineStart = i; - size_t lineEnd = source.find( '\n', i ); - if ( lineEnd == std::string::npos ) - { - lineEnd = source.size(); - } - - size_t t = lineStart; - while ( t < lineEnd && ( source[t] == ' ' || source[t] == '\t' ) ) - { - t++; - } - - bool isInclude = false; - std::string includeName; - if ( lineEnd >= t + 9 && source.compare( t, 8, "#include" ) == 0 && - ( source[t + 8] == ' ' || source[t + 8] == '\t' ) ) - { - size_t q1 = source.find( '"', t + 8 ); - size_t q2 = ( q1 != std::string::npos && q1 < lineEnd ) ? source.find( '"', q1 + 1 ) : std::string::npos; - if ( q1 != std::string::npos && q2 != std::string::npos && q2 < lineEnd ) - { - isInclude = true; - includeName = source.substr( q1 + 1, q2 - q1 - 1 ); - } - } - - if ( isInclude ) - { - std::string includePath = baseDir + includeName; - std::string includedRaw; - if ( !ReadFile( includePath.c_str(), includedRaw ) ) - { - fprintf( stderr, "Cannot open include '%s'\n", includePath.c_str() ); - return false; - } - - char hdr[64]; - snprintf( hdr, sizeof( hdr ), "#line 1\n" ); - out += hdr; - - if ( !ResolveIncludes( includedRaw, DirectoryOf( includePath.c_str() ), out ) ) - { - return false; - } - - if ( !out.empty() && out.back() != '\n' ) - { - out += '\n'; - } - - snprintf( hdr, sizeof( hdr ), "#line %d\n", lineNo + 1 ); - out += hdr; - } - else - { - out.append( source, lineStart, lineEnd - lineStart ); - out += '\n'; - } - - i = ( lineEnd < source.size() ) ? lineEnd + 1 : lineEnd; - lineNo++; - } - return true; -} - -static uint32_t CreateShaderFromFile( const char* filename, GLenum type ) -{ - std::string raw; - if ( !ReadFile( filename, raw ) ) - { - fprintf( stderr, "Error opening %s\n", filename ); - return 0; - } - - std::string source; - if ( !ResolveIncludes( raw, DirectoryOf( filename ), source ) ) - { - fprintf( stderr, "Error resolving includes in %s\n", filename ); - return 0; - } - - uint32_t shader = glCreateShader( type ); - const char* sources[] = { source.c_str() }; - - glShaderSource( shader, 1, sources, nullptr ); - glCompileShader( shader ); - - int success = GL_FALSE; - glGetShaderiv( shader, GL_COMPILE_STATUS, &success ); - - if ( success == GL_FALSE ) - { - fprintf( stderr, "Error compiling shader of type %d in %s!\n", type, filename ); - PrintLog( shader ); - } - - return shader; -} - -uint32_t CreateProgramFromFiles( const char* vertexPath, const char* fragmentPath ) -{ - uint32_t vertex = CreateShaderFromFile( vertexPath, GL_VERTEX_SHADER ); - if ( vertex == 0 ) - { - return 0; - } - - uint32_t fragment = CreateShaderFromFile( fragmentPath, GL_FRAGMENT_SHADER ); - if ( fragment == 0 ) - { - return 0; - } - - uint32_t program = glCreateProgram(); - glAttachShader( program, vertex ); - glAttachShader( program, fragment ); - - glLinkProgram( program ); - - int success = GL_FALSE; - glGetProgramiv( program, GL_LINK_STATUS, &success ); - if ( success == GL_FALSE ) - { - fprintf( stderr, "glLinkProgram:" ); - PrintLog( program ); - return 0; - } - - glDeleteShader( vertex ); - glDeleteShader( fragment ); - - return program; -} - -uint32_t CreateProgramFromStrings( const char* vs, const char* fs ) -{ - uint32_t vertex = CreateShaderFromString( vs, GL_VERTEX_SHADER ); - if ( vertex == 0 ) - { - return 0; - } - - uint32_t fragment = CreateShaderFromString( fs, GL_FRAGMENT_SHADER ); - if ( fragment == 0 ) - { - return 0; - } - - uint32_t programId = glCreateProgram(); - glAttachShader( programId, vertex ); - glAttachShader( programId, fragment ); - - glLinkProgram( programId ); - - int success = GL_FALSE; - glGetProgramiv( programId, GL_LINK_STATUS, &success ); - if ( success == GL_FALSE ) - { - fprintf( stderr, "glLinkProgram:" ); - PrintLog( programId ); - return 0; - } - - glDeleteShader( vertex ); - glDeleteShader( fragment ); - - return programId; -} - -void DestroyShader( uint32_t programId ) -{ - glDeleteProgram( programId ); -} - -int GetUniformLocation( uint32_t programId, const char* name ) -{ - return glGetUniformLocation( programId, name ); -} - -void SetUniformBool( int location, bool value ) -{ - glUniform1i( location, (int)value ); -} - -void SetUniformInt( int location, int value ) -{ - glUniform1i( location, value ); -} - -void SetUniformFloat( int location, float value ) -{ - glUniform1f( location, value ); -} - -void SetUniformVec3( int location, b3Vec3 value ) -{ - glUniform3fv( location, 1, &value.x ); -} - -void SetUniformVec3( int location, float x, float y, float z ) -{ - glUniform3f( location, x, y, z ); -} - -void SetUniformVec4( int location, Vector4 value ) -{ - glUniform4fv( location, 1, &value.x ); -} - -void SetUniformColor( int location, RGBAf value ) -{ - glUniform4fv( location, 1, &value.r ); -} - -void SetUniformVec4( int location, float x, float y, float z, float w ) -{ - glUniform4f( location, x, y, z, w ); -} - -void SetUniformMatrix4( int location, const Matrix4& mat ) -{ - glUniformMatrix4fv( location, 1, GL_FALSE, &mat.cx.x ); -} - -void SetUniformBool( uint32_t programId, const char* name, bool value ) -{ - int location = glGetUniformLocation( programId, name ); - if ( location != -1 ) - { - glUniform1i( location, (int)value ); - } - else - { - location += 0; - } -} - -void SetUniformInt( uint32_t programId, const char* name, int value ) -{ - int location = glGetUniformLocation( programId, name ); - if ( location != -1 ) - { - glUniform1i( location, value ); - } -} - -void SetUniformFloat( uint32_t programId, const char* name, float value ) -{ - int location = glGetUniformLocation( programId, name ); - if ( location != -1 ) - { - glUniform1f( location, value ); - } -} - -void SetUniformVec3( uint32_t programId, const char* name, b3Vec3 value ) -{ - int location = glGetUniformLocation( programId, name ); - if ( location != -1 ) - { - glUniform3fv( location, 1, &value.x ); - } -} - -void SetUniformVec3( uint32_t programId, const char* name, float x, float y, float z ) -{ - int location = glGetUniformLocation( programId, name ); - if ( location != -1 ) - { - glUniform3f( location, x, y, z ); - } -} - -void SetUniformVec4( uint32_t programId, const char* name, Vector4 value ) -{ - int location = glGetUniformLocation( programId, name ); - if ( location != -1 ) - { - glUniform4fv( location, 1, &value.x ); - } -} - -void SetUniformVec4( uint32_t programId, const char* name, float x, float y, float z, float w ) -{ - int location = glGetUniformLocation( programId, name ); - if ( location != -1 ) - { - glUniform4f( location, x, y, z, w ); - } -} - -void SetUniformColor( uint32_t programId, const char* name, RGBAf value ) -{ - int location = glGetUniformLocation( programId, name ); - if ( location != -1 ) - { - glUniform4fv( location, 1, &value.r ); - } -} - -void SetUniformMatrix4( uint32_t programId, const char* name, const Matrix4& mat ) -{ - int location = glGetUniformLocation( programId, name ); - if ( location != -1 ) - { - glUniformMatrix4fv( location, 1, GL_FALSE, &mat.cx.x ); - } -} diff --git a/samples/shader.h b/samples/shader.h deleted file mode 100644 index c180333..0000000 --- a/samples/shader.h +++ /dev/null @@ -1,39 +0,0 @@ -// SPDX-FileCopyrightText: 2025 Erin Catto -// SPDX-License-Identifier: MIT - -#pragma once - -#include "utility.h" - -#include "box3d/types.h" - -uint32_t CreateProgramFromFiles( const char* vertexPath, const char* fragmentPath ); -uint32_t CreateProgramFromStrings( const char* vs, const char* fs ); - -void DestroyShader( uint32_t programId ); - -// todo these are low value wrappers -int GetUniformLocation( uint32_t programId, const char* name ); - -void SetUniformBool( int location, bool value ); -void SetUniformInt( int location, int value ); -void SetUniformFloat( int location, float value ); -void SetUniformVec3( int location, b3Vec3 value ); -void SetUniformVec3( int location, float x, float y, float z ); -void SetUniformVec4( int location, Vector4 value ); -void SetUniformVec4( int location, float x, float y, float z, float w ); -void SetUniformColor( int location, RGBAf value ); -void SetUniformMatrix4( int location, const Matrix4& mat ); - -void SetUniformBool( uint32_t programId, const char* name, bool value ); -void SetUniformInt( uint32_t programId, const char* name, int value ); -void SetUniformFloat( uint32_t programId, const char* name, float value ); -void SetUniformVec3( uint32_t programId, const char* name, b3Vec3 value ); -void SetUniformVec3( uint32_t programId, const char* name, float x, float y, float z ); -void SetUniformVec4( uint32_t programId, const char* name, Vector4 value ); -void SetUniformVec4( uint32_t programId, const char* name, float x, float y, float z, float w ); -void SetUniformColor( uint32_t programId, const char* name, RGBAf value ); -void SetUniformMatrix4( uint32_t programId, const char* name, const Matrix4& mat ); - -void CheckOpenGL(); -void DumpGLInfo( bool dumpExtensions ); diff --git a/samples/shaders/.gitkeep b/samples/shaders/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/samples/shaders/CLAUDE.md b/samples/shaders/CLAUDE.md new file mode 100644 index 0000000..886a678 --- /dev/null +++ b/samples/shaders/CLAUDE.md @@ -0,0 +1,286 @@ +# Shaders + +This directory contains all GPU shader code for the renderer. Authored in +GLSL, cross-compiled to per-backend variants (HLSL for D3D11, MSL for Metal, +GLSL 410 for desktop GL) by **sokol-shdc**. + +Read this file before writing or editing any `.glsl` file. The root +`CLAUDE.md` covers project-wide conventions; this file covers shader-specific +rules that don't apply elsewhere. + +## Toolchain + +- Author in **GLSL 4.30 core** dialect, with sokol-shdc directives. +- sokol-shdc generates a single C header per shader file, containing the + bytecode/source for every enabled backend plus pipeline reflection. +- Generated headers live in `shaders/generated/` and **are committed**, so a + fresh clone builds without sokol-shdc. `BOX3D_BUILD_SHADERS` (default ON) + recompiles them in place via a CMake custom command; build with it OFF to + use the committed headers and fetch no tooling. +- Shader edits trigger the custom command automatically; run + `cmake --build build --target shaders` to force a rebuild. + +Backends configured in `cmake/Shaders.cmake`: +- `hlsl5` for D3D11 (Windows) +- `metal_macos` for Metal (macOS) +- `glsl430` for GL 4.3 core (Linux). 4.3 is the floor sokol_gfx requires + for storage buffers; we use storage buffers for per-instance data. + +If sokol-shdc rejects a shader, it's a hard build break - there is no +fallback path. Fix the shader, don't disable a backend. + +## File layout + +One shader program per `.glsl` file. The filename is the program name. + +``` +shaders/ + CLAUDE.md this file + sky.glsl procedural Preetham sky + common/ shared @include fragments + pbr.glsl PBR helpers (BRDF, IBL evaluation) + preetham.glsl Preetham sky radiance function + xe_gtao_common.glsl XeGTAO helper block (PrefilterDepth, + MainPass, Denoise primitives) + shapes/ + cube.glsl instanced cube + sphere.glsl ray-cast sphere impostor + capsule.glsl ray-cast capsule impostor + geom.glsl hulls + meshes + heightfields + edge.glsl per-shape edge overlay + shadow_caster_cube.glsl depth-only shadow caster, + shadow_caster_sphere.glsl per-shape, one per primitive class + shadow_caster_capsule.glsl + shadow_caster_geom.glsl + ibl/ one-time cubemap / LUT builders + sky_to_cube.glsl rasterize sky into a cubemap face + prefilter.glsl GGX prefilter the IBL cubemap + brdf_lut.glsl split-sum integration LUT + post/ + depth_only_cube.glsl GTAO/shadow prepass per primitive + depth_only_sphere.glsl class - outputs linear view-Z + depth_only_capsule.glsl + depth_only_geom.glsl + gtao_prefilter_depth.glsl XeGTAO compute + gtao_main_pass.glsl + gtao_denoise.glsl + mask_sphere.glsl hover/select highlight mask, + mask_capsule.glsl uint output, GREATER depth test + mask_hull.glsl + highlight_outline.glsl edge-detect + premult-alpha composite + tonemap.glsl AgX + overlays/ + line.glsl shader-expanded lines + point.glsl shader-expanded points +``` + +Each shader currently inlines its own UBO declarations (`ub_frame`, +`ub_pass`, `ub_draw`) - there is no shared `frame_ubo.glsl` / +`pass_ubo.glsl` block to `@include`. The three shared blocks that do +exist are `common/pbr.glsl`, `common/preetham.glsl`, and +`common/xe_gtao_common.glsl`; the lit shape shaders `@include` PBR and +the sky shaders include Preetham. Shadow-cascade sampling is inlined +per shape shader (`sampleShadowPCF` / `sampleCascade` / +`sampleShadowCascaded` in each of cube/sphere/capsule/geom) - keep +those four implementations in sync if you change the algorithm. + +A shader file has, in order: +1. `@ctype` directives mapping GLSL types to C types (mat4 -> Mat4, + vec4 -> Vec4, vec3 -> b3Vec3, vec2 -> b3Vec2). +2. `@include` of any common blocks needed. +3. `@vs` block - vertex stage. +4. `@fs` block - fragment stage. +5. `@program ` declaration. + +Don't put multiple programs in one file. Don't share `@vs` or `@fs` blocks +across programs except via `@include`. + +## Naming inside shaders + +- Uniform blocks: `ub_frame`, `ub_pass`, `ub_draw`. Lowercase, prefixed `ub_`. +- Samplers: `smp_` (e.g. `smp_shadow`, `smp_blue_noise`). +- Textures: `tex_` (e.g. `tex_depth`, `tex_normal`, `tex_shadow`). +- Vertex inputs: `in_` (e.g. `in_pos`, `in_normal`, `in_inst_xform0`). +- Varyings (vs->fs): `v_` (e.g. `v_view_pos`, `v_world_normal`). +- Fragment outputs: `out_` (e.g. `out_color`, `out_normal`, `out_id`). +- Locals: `snake_case`. Constants: `SCREAMING_SNAKE_CASE`. + +## Uniform organization + +Three UBO frequencies, **never** mixed: + +```glsl +// ub_frame - updated once per frame, bound at slot 0 +layout(binding=0) uniform ub_frame { + mat4 view; + mat4 proj; + mat4 view_proj; + mat4 inv_view_proj; + vec4 camera_pos; // .xyz = pos, .w = time + vec4 viewport; // .xy = size px, .zw = 1/size + vec4 sun_dir; // .xyz = world-space dir TO sun, .w = unused + vec4 sun_color; // .rgb = color * intensity, .a = ambient strength +}; + +// ub_pass - updated once per render pass, bound at slot 1 +layout(binding=1) uniform ub_pass { + // per-pass data: shadow matrices, post-process knobs, etc. +}; + +// ub_draw - updated per draw call, bound at slot 2 +layout(binding=2) uniform ub_draw { + // small per-draw data; instance arrays go in storage buffers, not UBOs +}; +``` + +Per-instance data lives in **storage buffers**, indexed by `gl_InstanceIndex`. +Don't pack instance data into UBOs - they're size-limited and the wrong tool. + +A UBO declared at `binding=N` is **stage-specific** in sokol-shdc - declaring +the same UBO in both `@vs` and `@fs` collides. Place each UBO in the stage +that reads it; if a value is needed in both stages, either replicate it at +a different binding, precompute on the C side and split into VS/FS-only +UBOs, or pass via a varying. The three-tier scheme above describes update +frequencies, not a guarantee that every shader exposes all three to both +stages. + +## Coordinate spaces + +Be explicit about which space a value lives in. Suffix variable names: +`*_world`, `*_view`, `*_clip`, `*_ndc`, `*_screen`. Mixing spaces silently +is the single most common shader bug. + +- **Reverse-Z**: clip-space Z is 1 at near, 0 at far. Depth comparison is + `GREATER`. Far-plane clears to 0, not 1. +- **View space**: right-handed, Y-up, Z out of screen (camera looks down -Z). +- **NDC**: `[-1, 1]` for X and Y; Z is `[0, 1]` (reverse-Z). +- **UV**: `[0, 1]`, top-left origin in sampling. sokol-shdc handles the + GL/D3D/Metal Y-flip difference automatically when sampling render targets; + don't flip manually. + +When reconstructing world position from depth, sample reverse-Z and +transform through `inv_view_proj` (declared in the per-shader UBO that +needs it - see `sky.glsl`, `overlays/line.glsl`, the lit shape +shaders). There is no shared math helper for this - it's inlined where +needed. + +## Flat shading + +Compute view-space normal from `dFdx`/`dFdy` of view-space position: + +```glsl +vec3 dx = dFdx(v_view_pos); +vec3 dy = dFdy(v_view_pos); +vec3 n_view = normalize(cross(dx, dy)); +``` + +This works for any triangle mesh and gives free flat shading without +duplicating vertices. Impostors compute their analytic normal directly +and skip this. + +Do **not** pass per-vertex normals as varyings unless the shape needs +smooth shading (which, in this renderer, none of them do). + +## Impostor shaders + +Sphere and capsule impostors all follow the same structure: + +1. Vertex shader emits a bounding proxy (cube for spheres, OBB for capsules). +2. Fragment shader reconstructs the view ray from `gl_FragCoord` and + `inv_view_proj`. +3. Ray-cast against the analytic primitive in **world space** (not view + space - keeps the math simpler when transforming ray origins). +4. On miss: `discard`. +5. On hit: write `gl_FragDepth` from the hit point in clip space, output + the analytic surface normal in view space. + +Reference math: Inigo Quilez, https://iquilezles.org/articles/intersectors/. + +`gl_FragDepth` writes disable early-Z. That's fine for impostors but it +means the impostor pipelines don't get the hi-Z optimization. Don't write +`gl_FragDepth` from triangle-mesh shaders - let the rasterizer do it. + +When writing `gl_FragDepth`, write the **reverse-Z** value (1 at near, +0 at far). The impostor shaders show the pattern: compute clip-space Z +from a world-space hit point via the view-proj matrix, then +`gl_FragDepth = clip.z / clip.w`. + +## Shadow sampling + +The four lit shape shaders (`cube.glsl`, `sphere.glsl`, `capsule.glsl`, +`geom.glsl`) each inline their own `sampleShadowPCF` / +`sampleCascade` / `sampleShadowCascaded` functions. They read +`cascade_matrices[3]`, `cascade_far_view_z`, and the shadow-atlas +sampler from the per-shape UBO + per-pass binding. The four +implementations are intentionally identical - if you change the +algorithm (kernel, bias formula, cascade-blend logic), update all four +at once. A future cleanup would lift them into a shared +`common/shadow.glsl` block; until then, treat the four copies as one +unit. + +Don't sample shadow maps from any other shader without going through +the same helper trio - non-standard sample patterns (PCSS, +contact-hardening) belong inside `sampleShadowPCF` behind a flag, not +forked into new call sites. + +## Things to NOT do + +- Don't use `#ifdef ` to branch on backend. sokol-shdc handles + cross-compilation; backend-specific shader code means we've lost. +- Don't sample a depth target with a regular sampler when you need raw + depth values. Use the depth-specific sampler binding declared in the + pass - drivers compare-sample by default on depth textures otherwise. +- Don't use derivatives (`dFdx`/`dFdy`/`fwidth`) in non-uniform control + flow. They produce undefined results inside `if`/`discard` branches. + Compute derivatives at top level, then branch. +- Don't write to `gl_FragDepth` conditionally (some pixels write, others + don't). Either every pixel writes it or none do - otherwise the early-Z + decision is per-draw, not per-pixel, and you get the worst of both. +- Don't use `texture()` without an explicit LOD in fragment shaders that + contain `discard` or `gl_FragDepth` writes after the sample. The + derivative for mipmap selection becomes undefined. Use `textureLod()` + with LOD 0 if mipmapping isn't needed. +- Don't pack different update frequencies into one UBO. Use the three-tier + scheme above. +- Don't store full 4x4 instance transforms. 3x4 affine; the bottom row is + always `(0, 0, 0, 1)` and we don't need perspective from instance data. +- Don't encode normals as `vec3` in storage buffers if you're tight on + bandwidth - octahedral encoding to two `f16`s saves the byte. There's + no shared helper yet; if a second use case comes up, lift it into + `common/`. Don't do this preemptively; profile first. +- Don't write debug colors (red for "this branch ran") and leave them in. + Use the debug view-mode mechanism instead - it's a uniform switch, not + edited shader code. +- Don't add new uniform blocks without updating the C-side reflection. + sokol-shdc generates `_uniformblock_size()` and `_uniformblock_slot()` + helpers; use them, don't hardcode sizes or slot indices. + +## Debugging shaders + +- The **debug view-modes** machinery is controlled by + `fi.debug_view_mode` and runtime keys 0-6. A single uniform selects: + lit, view-space distance, CSM cascade index, view-space normal, raw + GTAO AO. This is faster than RenderDoc for 90% of issues. +- Use **RenderDoc** on Linux/Windows or **Xcode GPU frame capture** on + macOS for the other 10%. Both work with sokol's backends. +- When a shader looks wrong, check coordinate spaces first, depth + reverse-Z second, derivatives in branches third. In that order. +- sokol's validation layer catches most binding mistakes. If something + renders black, check the validation log before reading shader code. + +## When adding a new shader + +1. Decide which file it belongs in (or create a new one if it's a new + pipeline). One program per file. +2. Add `@ctype` directives matching the C-side struct layouts. +3. Pick the right UBO tier for each uniform - frame, pass, or draw. +4. Author the shader; build with `cmake --build build --target shaders` + and watch sokol-shdc output for warnings (it's strict, that's good). +5. Make sure at least one scene in `main.cpp`'s `k_sceneTable` exercises + the new pipeline - the smoke test cycles every scene, so a scene + that touches the shader is render3d's regression net for sokol + validation errors. If no existing scene covers it, add a new + `src/app/*_scene.{cpp,h}` (mirror the `pbr_scene` / `gtao_scene` + pattern) and wire it through `SceneKind`. +6. Update this file if the shader introduces a new convention worth + documenting. diff --git a/samples/shaders/CMakeLists.txt b/samples/shaders/CMakeLists.txt new file mode 100644 index 0000000..cb4921f --- /dev/null +++ b/samples/shaders/CMakeLists.txt @@ -0,0 +1,140 @@ +# Shader compilation via sokol-shdc. + +# Each .glsl file in shaders/ becomes a single C header in +# generated/.glsl.h that holds source/bytecode for every enabled backend +# (D3D11, Metal, GL 4.5 core). The generated headers are committed so a fresh +# clone builds without sokol-shdc. BOX3D_BUILD_SHADERS (default ON) recompiles +# them in place when a .glsl changes; off builds straight from the committed +# headers and fetches no tooling. + +set(SHADER_OUTPUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/generated" + CACHE INTERNAL "Directory holding generated shader headers") + +if(BOX3D_BUILD_SHADERS) + if(NOT SOKOL_SHDC_EXECUTABLE OR NOT EXISTS "${SOKOL_SHDC_EXECUTABLE}") + message(FATAL_ERROR + "SOKOL_SHDC_EXECUTABLE is not set or does not exist: " + "${SOKOL_SHDC_EXECUTABLE}") + endif() + file(MAKE_DIRECTORY "${SHADER_OUTPUT_DIR}") + + # Shared @include fragments - sokol-shdc's @include resolves relative to + # the input file, so shaders include these via "../common/.glsl". + # Tracked as DEPENDS on every shader so an edit to a shared file triggers + # a rebuild of everything that might include it, and listed in the shaders + # target's SOURCES so they show up in IDE project trees - sokol-shdc never + # sees them as direct inputs, so they would be invisible otherwise. + # CONFIGURE_DEPENDS re-globs when a new common file appears, at the cost of + # a configure-step stat each build. + file(GLOB SHADER_COMMON_INCLUDES CONFIGURE_DEPENDS + "${CMAKE_CURRENT_LIST_DIR}/common/*.glsl") +endif() + +# Reset the accumulators on every configure so stale entries from a prior +# `cmake --fresh`-skipped run don't carry over. +set_property(GLOBAL PROPERTY SHADER_OUTPUTS "") +set_property(GLOBAL PROPERTY SHADER_INPUTS "") + +# Backends: hlsl5 (D3D11), metal_macos (Metal), glsl430 (GL 4.5). +set(SHADER_LANGUAGES "hlsl5:metal_macos:glsl430") + +# Registers a custom_command per .glsl input so only changed shaders re-run +# sokol-shdc on incremental builds. Skipped when BOX3D_BUILD_SHADERS is off - +# the committed header stands in for the input then. Either way the output +# path is recorded for the include dir and the IDE source list. After every +# shader is declared the trailing block produces the `shaders` target (the +# build entry point) and the `shaders` INTERFACE library consumers link to. +function(add_shader name input) + if(NOT IS_ABSOLUTE "${input}") + set(input "${CMAKE_CURRENT_SOURCE_DIR}/${input}") + endif() + set(output "${SHADER_OUTPUT_DIR}/${name}.glsl.h") + + if(BOX3D_BUILD_SHADERS) + add_custom_command( + OUTPUT "${output}" + COMMAND "${SOKOL_SHDC_EXECUTABLE}" + --input "${input}" + --output "${output}" + --slang "${SHADER_LANGUAGES}" + # --reflection + DEPENDS "${input}" ${SHADER_COMMON_INCLUDES} + COMMENT "sokol-shdc ${name}.glsl" + VERBATIM + ) + set_source_files_properties("${output}" PROPERTIES GENERATED TRUE) + endif() + + set_property(GLOBAL APPEND PROPERTY SHADER_OUTPUTS "${output}") + set_property(GLOBAL APPEND PROPERTY SHADER_INPUTS "${input}") +endfunction() + +# shapes +add_shader(cube "shapes/cube.glsl") +add_shader(sphere "shapes/sphere.glsl") +add_shader(capsule "shapes/capsule.glsl") +add_shader(geom "shapes/geom.glsl") +add_shader(edge "shapes/edge.glsl") +add_shader(shadow_caster_cube "shapes/shadow_caster_cube.glsl") +add_shader(shadow_caster_geom "shapes/shadow_caster_geom.glsl") +add_shader(shadow_caster_sphere "shapes/shadow_caster_sphere.glsl") +add_shader(shadow_caster_capsule "shapes/shadow_caster_capsule.glsl") + +# ibl +add_shader(sky "ibl/sky.glsl") +add_shader(brdf_lut "ibl/brdf_lut.glsl") +add_shader(sky_to_cube "ibl/sky_to_cube.glsl") +add_shader(prefilter "ibl/prefilter.glsl") + +# post +add_shader(depth_only_cube "post/depth_only_cube.glsl") +add_shader(depth_only_sphere "post/depth_only_sphere.glsl") +add_shader(depth_only_capsule "post/depth_only_capsule.glsl") +add_shader(depth_only_geom "post/depth_only_geom.glsl") +add_shader(gtao_prefilter_depth "post/gtao_prefilter_depth.glsl") +add_shader(gtao_main_pass "post/gtao_main_pass.glsl") +add_shader(gtao_denoise "post/gtao_denoise.glsl") +add_shader(tonemap "post/tonemap.glsl") +add_shader(mask_sphere "post/mask_sphere.glsl") +add_shader(mask_capsule "post/mask_capsule.glsl") +add_shader(mask_hull "post/mask_hull.glsl") +add_shader(highlight_outline "post/highlight_outline.glsl") + +# overlay +add_shader(overlay_line "overlays/line.glsl") +add_shader(overlay_point "overlays/point.glsl") + +get_property(_outputs GLOBAL PROPERTY SHADER_OUTPUTS) +get_property(_inputs GLOBAL PROPERTY SHADER_INPUTS) + +if(BOX3D_BUILD_SHADERS) + # DEPENDS drives the build (run sokol-shdc when the .glsl inputs change). + # SOURCES is purely an IDE hint - Visual Studio and Xcode show listed files + # in the project tree even though nothing here is compiled. We list the leaf + # .glsl shaders, the common/ @include fragments, and the generated .glsl.h. + add_custom_target(shaders + DEPENDS ${_outputs} + SOURCES ${_inputs} ${SHADER_COMMON_INCLUDES} ${_outputs} + ) + + # IDE grouping. TREE mirrors the on-disk shaders layout. + source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" + FILES ${_inputs} ${SHADER_COMMON_INCLUDES}) + source_group("Generated" FILES ${_outputs}) + + # The Visual Studio generator emits a build-stamp file named + # CMakeFiles/ for each custom target. Left ungrouped it floats at + # the project root as a stray "shaders" node with a can't-find-file icon - + # file it under the build-rule machinery. + source_group("CMake Rules" FILES "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/shaders") +else() + # No codegen: the samples build straight from the committed headers. + add_custom_target(shaders SOURCES ${_inputs} ${_outputs}) +endif() + +# shader_gen is the INTERFACE library consumers link to. It forwards the include +# path for the generated headers (SYSTEM so /WX doesn't trip on shdc output) and +# pulls in the shaders target so any link forces the headers to exist first. +add_library(shader_gen INTERFACE) +add_dependencies(shader_gen shaders) +target_include_directories(shader_gen SYSTEM INTERFACE "${SHADER_OUTPUT_DIR}") diff --git a/samples/shaders/common/pbr.glsl b/samples/shaders/common/pbr.glsl new file mode 100644 index 0000000..350b838 --- /dev/null +++ b/samples/shaders/common/pbr.glsl @@ -0,0 +1,238 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Shared PBR helpers, included via `@include../common/pbr.glsl` by each +// lit shape shader (cube, sphere, capsule, geom). +// +// brdf_evaluate: a subset of Disney/Principled. GGX (Trowbridge-Reitz) +// NDF, Smith correlated geometry, Schlick Fresnel, Lambert diffuse. No +// subsurface, transmission, clearcoat, sheen, anisotropy. References: +// Walter et al. 2007, Karis 2013 (UE4), Heitz 2014. +// +// proceduralGrid: fwidth-antialiased two-tier grid pattern over world-space +// XZ. Used by the geom pipeline when v_material.z selects the ground +// material. Designed to feed straight into brdf_evaluate as baseColor. +// +// Callers pick the coordinate space. N, V, L must all be in the same +// space. n.l, n.v, n.h are rotation-invariant. The cube shader uses view +// space (its dFdx/dFdy normal can't safely cross to world on D3D11, see +// cube.glsl), every other lit shader uses world space. + +const float PBR_PI = 3.14159265358979323846; + +float pbrDistributionGGX(float n_dot_h, float alpha) +{ + float a2 = alpha * alpha; + float d = (n_dot_h * n_dot_h) * (a2 - 1.0) + 1.0; + return a2 / (PBR_PI * d * d); +} + +// Smith correlated G, Heitz 2014. +float pbrVisibilitySmithCorrelated(float n_dot_v, float n_dot_l, float alpha) +{ + float a2 = alpha * alpha; + float vv = n_dot_l * sqrt(n_dot_v * n_dot_v * (1.0 - a2) + a2); + float vl = n_dot_v * sqrt(n_dot_l * n_dot_l * (1.0 - a2) + a2); + return 0.5 / (vv + vl + 1e-5); +} + +vec3 pbrFresnelSchlick(float v_dot_h, vec3 f0) +{ + float t = 1.0 - v_dot_h; + float t2 = t * t; + return f0 + (vec3(1.0) - f0) * (t2 * t2 * t); +} + +// Direct sun lighting only. sun_radiance is sun_color.rgb premultiplied +// by the shadow factor so the caller's existing shadow path is unchanged. +// Ambient is split out into pbrEvaluateIbl below, callers compose +// direct + ibl_ambient. +vec3 brdf_evaluate(vec3 N, vec3 V, vec3 L, vec3 sun_radiance, + vec3 base_color, float metallic, float roughness) +{ + float n_dot_l = max(dot(N, L), 0.0); + float n_dot_v = max(dot(N, V), 1e-4); + + vec3 H = normalize(V + L); + float n_dot_h = max(dot(N, H), 0.0); + float v_dot_h = max(dot(V, H), 0.0); + + // Perceptual roughness -> roughness alpha (Karis). The 0.045 floor + // keeps the specular highlight from collapsing to a singular point + // at roughness 0, which causes hot-pixel sparkle under MSAA. + float perc = max(roughness, 0.045); + float alpha = perc * perc; + + vec3 f0 = mix(vec3(0.04), base_color, metallic); + + float D = pbrDistributionGGX(n_dot_h, alpha); + float Vis = pbrVisibilitySmithCorrelated(n_dot_v, n_dot_l, alpha); + vec3 F = pbrFresnelSchlick(v_dot_h, f0); + + vec3 specular = D * Vis * F; + vec3 diffuse = (vec3(1.0) - F) * (1.0 - metallic) * base_color / PBR_PI; + + return (diffuse + specular) * sun_radiance * n_dot_l; +} + +// Evaluate band-0..2 SH at world-space direction N. The stored +// coefficients (sh[0..8].xyz) are already pre-multiplied with the +// Funk-Hecke / Ramamoorthi diffuse convolution weights, so this returns +// irradiance E(N) directly. Pre-multiply convention is fixed C-side in +// projectSkyToSh, the shader just dots against the SH basis. +// +// Index order matches Sloan / Ramamoorthi: +// 0 = (l=0,m= 0) +// 1 = (l=1,m=-1) 2 = (l=1,m= 0) 3 = (l=1,m=+1) +// 4 = (l=2,m=-2) 5 = (l=2,m=-1) 6 = (l=2,m= 0) 7 = (l=2,m=+1) 8 = (l=2,m=+2). +vec3 pbrEvaluateShIrradiance(vec3 N, vec4 sh[9]) +{ + const float Y00 = 0.282094791773878; + const float Y1n1 = 0.488602511902919; + const float Y10 = 0.488602511902919; + const float Y1p1 = 0.488602511902919; + const float Y2n2 = 1.092548430592079; + const float Y2n1 = 1.092548430592079; + const float Y20 = 0.315391565252520; + const float Y2p1 = 1.092548430592079; + const float Y2p2 = 0.546274215296039; + + float b0 = Y00; + float b1 = -Y1n1 * N.y; + float b2 = Y10 * N.z; + float b3 = -Y1p1 * N.x; + float b4 = Y2n2 * N.x * N.y; + float b5 = -Y2n1 * N.y * N.z; + float b6 = Y20 * (3.0 * N.z * N.z - 1.0); + float b7 = -Y2p1 * N.x * N.z; + float b8 = Y2p2 * (N.x * N.x - N.y * N.y); + + return sh[0].xyz * b0 + + sh[1].xyz * b1 + sh[2].xyz * b2 + sh[3].xyz * b3 + + sh[4].xyz * b4 + sh[5].xyz * b5 + sh[6].xyz * b6 + + sh[7].xyz * b7 + sh[8].xyz * b8; +} + +// IBL ambient: SH diffuse + GGX prefilter specular via Karis split-sum. +// Returns the ambient RGB to add to the direct lighting term. N_world +// and V_world must be in world space (the cube shader transforms its +// view-space normal here before calling). +// +// Fresnel-roughness compensates the diffuse fraction at grazing angles +// for rough surfaces, Lagarde 2014. F0_max = max(1-roughness, F0) lets +// dielectrics stay bright even when roughness is high. +vec3 pbrEvaluateIbl(vec3 N_world, vec3 V_world, vec3 base_color, float metallic, + float roughness, vec4 sh[9], + textureCube tex_spec_cube, sampler smp_spec_cube, + texture2D tex_brdf_lut, sampler smp_brdf_lut, + float max_lod) +{ + // Clamp upper bound too: impostor n_world (sphere/capsule) comes from + // (hit - center) / radius and isn't explicitly normalized, so float + // drift can push |n_world| slightly above 1 and n_dot_v above 1. Then + // 1.0 - n_dot_v < 0 and pow(negative, 5.0) is undefined per GLSL spec + // (NVIDIA returns NaN), which propagates through F and renders as + // isolated black pixels on the surface. + float n_dot_v = clamp(dot(N_world, V_world), 1e-4, 1.0); + vec3 R = reflect(-V_world, N_world); + + vec3 F0 = mix(vec3(0.04), base_color, metallic); + vec3 F0m = max(vec3(1.0 - roughness), F0); + + // max(0, ...) is a no-op given the n_dot_v clamp above, but the HLSL + // cross-compile loses the range info and warns about pow(negative, n) + // (X3571) without it. + vec3 F = F0 + (F0m - F0) * pow(max(0.0, 1.0 - n_dot_v), 5.0); + + vec3 kS = F; + vec3 kD = (vec3(1.0) - kS) * (1.0 - metallic); + + vec3 irradiance = max(pbrEvaluateShIrradiance(N_world, sh), vec3(0.0)); + vec3 diffuse = kD * base_color * irradiance / PBR_PI; + + float lod = roughness * max_lod; + vec3 prefiltered = textureLod(samplerCube(tex_spec_cube, smp_spec_cube), R, lod).rgb; + vec2 brdf = texture(sampler2D(tex_brdf_lut, smp_brdf_lut), + vec2(n_dot_v, roughness)).rg; + vec3 specular = prefiltered * (F0 * brdf.x + brdf.y); + + return diffuse + specular; +} + +// Ambient selector. iblEnabled chooses between the image-based ambient +// (pbrEvaluateIbl above) and the legacy flat ambient, base_color * +// flat_strength, that the renderer used. The renderer drives +// iblEnabled from a Render Settings panel toggle so the IBL contribution +// can be A/B'd against the flat term. +// +// The branch is on a uniform: every fragment of every lit draw sees the +// same iblEnabled, so this is uniform control flow and the implicit-LOD +// BRDF-LUT fetch inside pbrEvaluateIbl stays well-defined. Callers pass the +// same N_world/V_world/base_color they would have passed to pbrEvaluateIbl. +vec3 pbrEvaluateAmbient(bool iblEnabled, + vec3 N_world, vec3 V_world, + vec3 base_color, float metallic, float roughness, + float flat_strength, + vec4 sh[9], + textureCube tex_spec_cube, sampler smp_spec_cube, + texture2D tex_brdf_lut, sampler smp_brdf_lut, +float max_lod) +{ + // Single result, pre-seeded with the flat-ambient fallback. The early- + // return form `if (iblEnabled) return...; return flat;` cross- + // compiles through SPIRV-Cross into a returned-flag pattern whose return + // temp fxc can't prove definitely-assigned (warning X4000). Seeding the + // result and overwriting it in the one branch sidesteps that. The IBL + // path is still evaluated only when enabled, and the value is bit- + // identical to a direct pbrEvaluateIbl call. + vec3 result = base_color * flat_strength; + if (iblEnabled) { + result = pbrEvaluateIbl(N_world, V_world, + base_color, metallic, roughness, + sh, + tex_spec_cube, smp_spec_cube, + tex_brdf_lut, smp_brdf_lut, + max_lod); + } + return result; +} + +// Two-tier antialiased grid: +// * minor lines at `cell_size` cadence, slight darkening +// * major lines every 10 cells, stronger darkening +// `fwidth` of the cell coordinate keeps the line width near 1 screen pixel +// at any distance / viewing angle. Caller passes a flat per-instance +// `cell_size`, the result is suitable as `base_color` for brdf_evaluate. +// +// Derivatives are valid here only because the geom shader calls this +// from a branch on a flat per-instance varying (every fragment in a +// quad of a single draw shares the same materialMode). +vec3 proceduralGrid(vec2 world_xz, vec3 base_color, float cell_size) +{ + vec2 coord_minor = world_xz / cell_size; + vec2 d_minor = max(fwidth(coord_minor), vec2(1.0e-6)); + vec2 g_minor = abs(fract(coord_minor - 0.5) - 0.5) / d_minor; + float line_minor = 1.0 - clamp(min(g_minor.x, g_minor.y), 0.0, 1.0); + + vec2 coord_major = world_xz / (cell_size * 10.0); + vec2 d_major = max(fwidth(coord_major), vec2(1.0e-6)); + vec2 g_major = abs(fract(coord_major - 0.5) - 0.5) / d_major; + float line_major = 1.0 - clamp(min(g_major.x, g_major.y), 0.0, 1.0); + + vec3 minor_color = base_color * 0.70; + vec3 major_color = base_color * 0.35; + + vec3 result = mix(base_color, minor_color, line_minor); + result = mix(result, major_color, line_major); + + // Colored axes: red along +X, blue along +Z. Pixel-wide like the grid + // lines, gated to the positive half so the origin reads as a corner. + // Saturated primaries are identical in linear and sRGB, so they need no + // encoding fixup before the BRDF. + vec2 d_axis = max(fwidth(world_xz), vec2(1.0e-6)); + float axis_x = (1.0 - clamp(abs(world_xz.y) / d_axis.y, 0.0, 1.0)) * step(0.0, world_xz.x); + float axis_z = (1.0 - clamp(abs(world_xz.x) / d_axis.x, 0.0, 1.0)) * step(0.0, world_xz.y); + result = mix(result, vec3(1.0, 0.0, 0.0), axis_x); + result = mix(result, vec3(0.0, 0.0, 1.0), axis_z); + return result; +} diff --git a/samples/shaders/common/preetham.glsl b/samples/shaders/common/preetham.glsl new file mode 100644 index 0000000..dc84bdd --- /dev/null +++ b/samples/shaders/common/preetham.glsl @@ -0,0 +1,146 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Preetham/Shirley/Smits 1999 analytic daylight sky. +// +// preethamSky(view_dir, sun_dir, turbidity) returns linear-sRGB radiance +// for an unoccluded sky direction. Both directions must be unit-length, +// Y is up. Output is unmultiplied, callers apply the luminance scale +// and below-horizon fade themselves, or call preethamSkyScaled which +// does both. +// +// Preetham diverges at and below the horizon. The helper clamps the +// view direction to slightly above the horizon and clamps sun.y to the +// upper hemisphere so the Perez/zenith math stays finite when the sun +// is below the horizon, the caller is responsible for fading output to +// zero in that case. + +const float PREETHAM_PI = 3.14159265358979323846; + +// Empirical luminance scale, chosen to land near the target ~10:1 +// sun:sky ratio under the renderer's sun_color premultiplied-by-pi +// convention. Shared between the sky backdrop (sky.glsl) and the IBL +// sky cubemap (sky_to_cube.glsl) so both consumers see the same sky. +const float PREETHAM_LUMINANCE_SCALE = 0.06; + +// Perez luminance distribution: +// F(theta, gamma) = (1 + A * exp(B / cos(theta))) +// * (1 + C * exp(D * gamma) + E * cos^2(gamma)) +// theta = view angle from zenith, gamma = view angle from sun direction. +// cos_theta is clamped >= 0.01 to avoid the exp(B / 0) singularity at +// the horizon (Preetham is invalid there anyway). +float preethamPerez(float cos_theta, float cos_gamma, float gamma, + float A, float B, float C, float D, float E) +{ + float term1 = 1.0 + A * exp(B / max(cos_theta, 0.01)); + float term2 = 1.0 + C * exp(D * gamma) + E * cos_gamma * cos_gamma; + return term1 * term2; +} + +// CIE xyY -> XYZ. +vec3 preethamXyY_to_XYZ(float x, float y, float Y) +{ + float yy = max(y, 1.0e-5); + return vec3(Y * x / yy, Y, Y * (1.0 - x - y) / yy); +} + +// CIE XYZ (D65) -> linear sRGB. +vec3 preethamXYZ_to_linear_srgb(vec3 c) +{ + return vec3( + dot(c, vec3(3.2404542, - 1.5371385, - 0.4985314)), + dot(c, vec3(-0.9692660, 1.8760108, 0.0415560)), + dot(c, vec3(0.0556434, - 0.2040259, 1.0572252)) + ); +} + +vec3 preethamSky(vec3 view_dir, vec3 sun_dir, float turbidity) +{ + // Clamp sun's elevation to the upper hemisphere so the Perez/zenith + // math stays finite below the horizon. The horizontal components + // sun_dir are intentionally kept unmodified, cos_gamma reads the + // original direction so the sun's azimuth is preserved. + float sun_y = clamp(sun_dir.y, 0.0, 1.0); + + // Pin the look-up direction to slightly above the horizon when the + // view points downward. Preetham diverges below the horizon, and + // this gives the sky a sensible colour where the ground would + // otherwise occlude it (e.g. scenes with no ground in the lower + // portion of frame). + vec3 view_clamped = normalize(vec3(view_dir.x, max(view_dir.y, 0.0) + 0.01, view_dir.z)); + + float cos_theta = max(view_clamped.y, 0.0); // zenith angle of view + float cos_gamma = clamp(dot(sun_dir, view_clamped), - 1.0, 1.0); // sun-to-view angle + float gamma = acos(cos_gamma); + float sun_theta = acos(sun_y); + + // Perez coefficients as functions of turbidity T (Preetham table 2) + float T = max(turbidity, 1.0); + float T2 = T * T; + + // Y (luminance): + float A_Y = 0.1787 * T - 1.4630; + float B_Y = -0.3554 * T + 0.4275; + float C_Y = -0.0227 * T + 5.3251; + float D_Y = 0.1206 * T - 2.5771; + float E_Y = -0.0670 * T + 0.3703; + // x (chromaticity): + float A_x = -0.0193 * T - 0.2592; + float B_x = -0.0665 * T + 0.0008; + float C_x = -0.0004 * T + 0.2125; + float D_x = -0.0641 * T - 0.8989; + float E_x = -0.0033 * T + 0.0452; + // y (chromaticity): + float A_y = -0.0167 * T - 0.2608; + float B_y = -0.0950 * T + 0.0092; + float C_y = -0.0079 * T + 0.2102; + float D_y = -0.0441 * T - 1.6537; + float E_y = -0.0109 * T + 0.0529; + + // Zenith chromaticities (Preetham Eq. A.3, polynomial in T and sun_theta). + float ts = sun_theta; + float ts2 = ts * ts; + float ts3 = ts2 * ts; + + float x_z = + (0.00166 * ts3 - 0.00375 * ts2 + 0.00209 * ts) * T2 + + (-0.02903 * ts3 + 0.06377 * ts2 - 0.03202 * ts + 0.00394) * T + + (0.11693 * ts3 - 0.21196 * ts2 + 0.06052 * ts + 0.25886); + + float y_z = + (0.00275 * ts3 - 0.00610 * ts2 + 0.00317 * ts) * T2 + + (-0.04214 * ts3 + 0.08970 * ts2 - 0.04153 * ts + 0.00516) * T + + (0.15346 * ts3 - 0.26756 * ts2 + 0.06670 * ts + 0.26688); + + // Zenith luminance (Preetham Eq. A.2). Result in kcd/m^2. + float chi = (4.0 / 9.0 - T / 120.0) * (PREETHAM_PI - 2.0 * sun_theta); + float Y_z = (4.0453 * T - 4.9710) * tan(chi) - 0.2155 * T + 2.4192; + + // Normalize: F(theta=0, gamma=sun_theta) at zenith equals zenith + // values, so divide by perez(zenith) and multiply by perez(view). + float cos_zen_gamma = sun_y; // dot(zenith, sun_dir) = sun_dir.y + float pY_v = preethamPerez(cos_theta, cos_gamma, gamma, A_Y, B_Y, C_Y, D_Y, E_Y); + float px_v = preethamPerez(cos_theta, cos_gamma, gamma, A_x, B_x, C_x, D_x, E_x); + float py_v = preethamPerez(cos_theta, cos_gamma, gamma, A_y, B_y, C_y, D_y, E_y); + float pY_z = preethamPerez(1.0, cos_zen_gamma, sun_theta, A_Y, B_Y, C_Y, D_Y, E_Y); + float px_z = preethamPerez(1.0, cos_zen_gamma, sun_theta, A_x, B_x, C_x, D_x, E_x); + float py_z = preethamPerez(1.0, cos_zen_gamma, sun_theta, A_y, B_y, C_y, D_y, E_y); + + float Y = max(Y_z * pY_v / max(pY_z, 1.0e-5), 0.0); + float x = x_z * px_v / max(px_z, 1.0e-5); + float y = y_z * py_v / max(py_z, 1.0e-5); + + vec3 XYZ = preethamXyY_to_XYZ(x, y, Y); + vec3 rgb = preethamXYZ_to_linear_srgb(XYZ); + return max(rgb, vec3(0.0)); +} + +// Convenience wrapper: raw Preetham scaled by the empirical luminance +// factor and the caller's below-horizon fade weight (1 above horizon, +// 0 below). The sky backdrop shader and the IBL sky cubemap both call +// this so they're guaranteed to agree pixel-for-pixel. +vec3 preethamSkyScaled(vec3 view_dir, vec3 sun_dir, float turbidity, float fade) +{ + return preethamSky(view_dir, sun_dir, turbidity) * PREETHAM_LUMINANCE_SCALE * fade; +} + \ No newline at end of file diff --git a/samples/shaders/common/xe_gtao_common.glsl b/samples/shaders/common/xe_gtao_common.glsl new file mode 100644 index 0000000..adf41aa --- /dev/null +++ b/samples/shaders/common/xe_gtao_common.glsl @@ -0,0 +1,192 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// XeGTAO helper functions shared between the GTAO compute shaders +// (MainPass, Denoise). Ported from Esoterica HLSL with the following +// GLSL adaptations: +// +// * lpfloat collapses to float (XE_GTAO_USE_HALF_FLOAT_PRECISION=0, +// XE_GTAO_FP32_DEPTHS=1, matches Esoterica's config). +// * HLSL `out` parameters become inout where needed. +// * `mul(matrix, vec)` is rewritten as `matrix * vec` and column-major +// conventions are preserved. +// * Functions that took a `Texture2D` / `SamplerState` / +// `RWTexture2D` parameter in HLSL cannot be cleanly expressed +// in cross-compiled GLSL. Those functions (XeGTAO_MainPass, +// XeGTAO_ComputeViewspaceNormal, XeGTAO_OutputWorkingTerm, +// XeGTAO_Denoise) are inlined into the consuming shader and reference +// its texture/image bindings directly. This file holds only the pure +// helpers. +// * GTAOConsts is a plain struct populated once per dispatch from the +// ub_gtao UBO. Each consumer constructs a GTAOConsts in main and +// passes it down to the helpers below. The struct is a strict subset +// of Esoterica's `GTAOConstants`, only the fields the helpers +// actually read are carried, so each consuming shader's ub_gtao only +// needs to declare those (plus whatever else its own main reads +// directly). +// +// Include via `@include xe_gtao_common.glsl` inside the consumer's @cs +// block. The consumer is responsible for declaring the ub_gtao UBO with +// the fields its main reads. + +const float XE_GTAO_PI = 3.1415926535897932384626433832795; +const float XE_GTAO_PI_HALF = 1.5707963267948966192313216916398; + +// Esoterica's XE_GTAO_OCCLUSION_TERM_SCALE, applied by +// XeGTAO_OutputWorkingTerm (divides) and the denoise finalApply +// (multiplies). Keeps the noisy occlusion-term in [0,1] for storage, +// rescaled to ~[0,1.5] for the final lit lookup. +const float XE_GTAO_OCCLUSION_TERM_SCALE = 1.5; + +// XE_GTAO_DEPTH_MIP_LEVELS = 5, the prefiltered depth chain has 5 mips +// (mip 0..4). MainPass clamps the computed sample mip to [0, 5). +const float XE_GTAO_DEPTH_MIP_LEVELS = 5.0; + +// HilbertIndex parameters, XE_HILBERT_LEVEL = 6U, width 64. +const uint XE_HILBERT_WIDTH = 64u; + +struct GTAOConsts +{ + vec2 ViewportPixelSize; + vec2 NDCToViewMul; + vec2 NDCToViewAdd; + vec2 NDCToViewMul_x_PixelSize; + float EffectRadius; + float EffectFalloffRange; + float RadiusMultiplier; + float FinalValuePower; + float SampleDistributionPower; + float ThinOccluderCompensation; + float DepthMIPSamplingOffset; + float SliceCount; + float StepsPerSlice; +}; + +// http://h14s.p5r.org/2012/09/0x5f3759df.html via XeGTAO.esh:184-187. +// Bit-cast through floatBitsToInt / intBitsToFloat for the GLSL idiom. +float XeGTAO_FastSqrt(float x) +{ + return intBitsToFloat(0x1fbd1df5 + (floatBitsToInt(x) >> 1)); +} + +// Lagarde 2014 approximation, input [-1, 1], output [0, PI]. XeGTAO.esh:189. +float XeGTAO_FastACos(float inX) +{ + float x = abs(inX); + float res = -0.156583 * x + XE_GTAO_PI_HALF; + res *= XeGTAO_FastSqrt(1.0 - x); + return (inX >= 0.0) ? res : (XE_GTAO_PI - res); +} + +// Clamp depth into fp32-finite range. XeGTAO.esh:648-655. +float XeGTAO_ClampDepth(float depth) +{ + return clamp(depth, 0.0, 3.402823466e+38); +} + +// Pass-through: our input depth is already positive linear view-Z, so the +// "screen-space -> view-space" linearize step is the identity. Kept for +// signature parity with XeGTAO.esh:117-123 so ports of MainPass and +// ComputeViewspaceNormal stay verbatim. +float XeGTAO_ScreenSpaceToViewSpaceDepth(float screenDepth, GTAOConsts consts) +{ + return screenDepth; +} + +// XeGTAO.esh:104-115 with the Esoterica reverse-Z patch (negate Z so it +// points OUT of the screen in view space). render3d's view space is +// also right-handed Y-up with camera looking down -Z, matching Esoterica. +vec3 XeGTAO_ComputeViewspacePosition(vec2 screenPos, float viewspaceDepth, GTAOConsts consts) { + vec3 ret; + ret.xy = (consts.NDCToViewMul * screenPos + consts.NDCToViewAdd) * viewspaceDepth; + ret.z = -viewspaceDepth; + return ret; +} + +// XeGTAO.esh:125-134. Output is in [0,1] per channel, 0 = strong edge, +// 1 = no edge. Used by both the edges-output (PackEdges) and the +// normal-from-depth pass (CalculateNormal). +vec4 XeGTAO_CalculateEdges(float centerZ, float leftZ, float rightZ, float topZ, float bottomZ) +{ + vec4 edgesLRTB = vec4(leftZ, rightZ, topZ, bottomZ) - centerZ; + + float slopeLR = (edgesLRTB.y - edgesLRTB.x) * 0.5; + float slopeTB = (edgesLRTB.w - edgesLRTB.z) * 0.5; + vec4 edgesLRTBSlopeAdjusted = edgesLRTB + vec4(slopeLR, - slopeLR, slopeTB, - slopeTB); + edgesLRTB = min(abs(edgesLRTB), abs(edgesLRTBSlopeAdjusted)); + return vec4(clamp((1.25 - edgesLRTB / (centerZ * 0.011)), 0.0, 1.0)); +} + +// XeGTAO.esh:137-146. Packs 4 edge gradients (2 bits each) into a single +// UNORM8 channel. The dot-product form matches the reference, rounding +// happens before the dot so the four bins are { 0, 64, 128, 192 } / 255. +float XeGTAO_PackEdges(vec4 edgesLRTB) +{ + edgesLRTB = round(clamp(edgesLRTB, 0.0, 1.0) * 2.9); + return dot(edgesLRTB, vec4(64.0 / 255.0, 16.0 / 255.0, 4.0 / 255.0, 1.0 / 255.0)); +} + +// XeGTAO.esh:727-737. Reverse of PackEdges. Used by Denoise. +vec4 XeGTAO_UnpackEdges(float packed_val) +{ + uint p = uint(packed_val * 255.5); + vec4 edgesLRTB; + edgesLRTB.x = float((p >> 6)& 0x03u) / 3.0; + edgesLRTB.y = float((p >> 4)& 0x03u) / 3.0; + edgesLRTB.z = float((p >> 2)& 0x03u) / 3.0; + edgesLRTB.w = float((p >> 0)& 0x03u) / 3.0; + return clamp(edgesLRTB, 0.0, 1.0); +} + +// XeGTAO.esh:148-173 with the Esoterica reverse-Z cross-product reorder +// (cross args swapped to keep the winding consistent with view space +// pointing OUT of the screen). +vec3 XeGTAO_CalculateNormal(vec4 edgesLRTB, vec3 pixCenterPos, + vec3 pixLPos, vec3 pixRPos, vec3 pixTPos, vec3 pixBPos) +{ + vec4 acceptedNormals = clamp(vec4( + edgesLRTB.x * edgesLRTB.z, + edgesLRTB.z * edgesLRTB.y, + edgesLRTB.y * edgesLRTB.w, + edgesLRTB.w * edgesLRTB.x) + 0.01, 0.0, 1.0); + + pixLPos = normalize(pixLPos - pixCenterPos); + pixRPos = normalize(pixRPos - pixCenterPos); + pixTPos = normalize(pixTPos - pixCenterPos); + pixBPos = normalize(pixBPos - pixCenterPos); + + vec3 pixelNormal = acceptedNormals.x * cross(pixTPos, pixLPos) + + acceptedNormals.y * cross(pixRPos, pixTPos) + + acceptedNormals.z * cross(pixBPos, pixRPos) + + acceptedNormals.w * cross(pixLPos, pixBPos); + + return normalize(pixelNormal); +} + +// XeGTAO_Types.esh:120-142. Hilbert curve index for a 64x64 tile +// pixCoord (pixCoord & 63). Combined with the R2 sequence in the +// consumer's SpatioTemporalNoise to produce blue-noise-like spatial +// distribution. No LUT, generated in-shader, matches Esoterica's +// `#ifndef XE_GTAO_HILBERT_LUT_AVAILABLE` branch. +uint HilbertIndex(uint posX, uint posY) +{ + uint index = 0u; + for (uint curLevel = XE_HILBERT_WIDTH / 2u; curLevel > 0u; curLevel /= 2u) + { + uint regionX = (posX & curLevel) > 0u ? 1u : 0u; + uint regionY = (posY & curLevel) > 0u ? 1u : 0u; + index += curLevel * curLevel * ((3u * regionX)^ regionY); + if (regionY == 0u) + { + if (regionX == 1u) + { + posX = (XE_HILBERT_WIDTH - 1u) - posX; + posY = (XE_HILBERT_WIDTH - 1u) - posY; + } + uint temp = posX; + posX = posY; + posY = temp; + } + } + return index; +} diff --git a/samples/shaders/generated/brdf_lut.glsl.h b/samples/shaders/generated/brdf_lut.glsl.h new file mode 100644 index 0000000..9999a0d --- /dev/null +++ b/samples/shaders/generated/brdf_lut.glsl.h @@ -0,0 +1,1093 @@ +#pragma once +/* + #version:1# (machine generated, don't edit!) + + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) + + Cmdline: + sokol-shdc --input E:/box/box3d/samples/shaders/ibl/brdf_lut.glsl --output E:/box/box3d/samples/shaders/generated/brdf_lut.glsl.h --slang hlsl5:metal_macos:glsl430 + + Overview: + ========= + Shader program: 'build': + Get shader desc: brdf_lut_build_shader_desc(sg_query_backend()); + Vertex Shader: vs + Fragment Shader: fs + Attributes: + Bindings: + Uniform block 'ub_brdf': + C struct: brdf_lut_ub_brdf_t + Bind slot: UB_brdf_lut_ub_brdf => 0 +*/ +#if !defined(SOKOL_GFX_INCLUDED) +#error "Please include sokol_gfx.h before brdf_lut.glsl.h" +#endif +#if !defined(SOKOL_SHDC_ALIGN) +#if defined(_MSC_VER) +#define SOKOL_SHDC_ALIGN(a) __declspec(align(a)) +#else +#define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) +#endif +#endif +#define UB_brdf_lut_ub_brdf (0) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct brdf_lut_ub_brdf_t { + Vec4 params; +} brdf_lut_ub_brdf_t; +#pragma pack(pop) +/* + #version 430 + + uniform vec4 ub_brdf[1]; + layout(location = 0) out vec2 v_uv; + + void main() + { + vec2 _27 = (vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2)) * 2.0) - vec2(1.0); + float _34 = _27.x; + v_uv = vec2((_34 * 0.5) + 0.5, 0.5 + ((_27.y * 0.5) * ub_brdf[0].x)); + gl_Position = vec4(_34, _27.y, 0.0, 1.0); + } + +*/ +static const uint8_t brdf_lut_vs_source_glsl430[333] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x75,0x6e, + 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x62,0x72, + 0x64,0x66,0x5b,0x31,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f, + 0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20, + 0x76,0x65,0x63,0x32,0x20,0x76,0x5f,0x75,0x76,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64, + 0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x32,0x20,0x5f,0x32,0x37,0x20,0x3d,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x66, + 0x6c,0x6f,0x61,0x74,0x28,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49, + 0x44,0x20,0x3c,0x3c,0x20,0x31,0x29,0x20,0x26,0x20,0x32,0x29,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x44,0x20, + 0x26,0x20,0x32,0x29,0x29,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x20,0x2d,0x20,0x76, + 0x65,0x63,0x32,0x28,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x33,0x34,0x20,0x3d,0x20,0x5f,0x32,0x37,0x2e,0x78,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x75,0x76,0x20,0x3d,0x20,0x76,0x65,0x63,0x32, + 0x28,0x28,0x5f,0x33,0x34,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30, + 0x2e,0x35,0x2c,0x20,0x30,0x2e,0x35,0x20,0x2b,0x20,0x28,0x28,0x5f,0x32,0x37,0x2e, + 0x79,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2a,0x20,0x75,0x62,0x5f,0x62,0x72, + 0x64,0x66,0x5b,0x30,0x5d,0x2e,0x78,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67, + 0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x76,0x65,0x63, + 0x34,0x28,0x5f,0x33,0x34,0x2c,0x20,0x5f,0x32,0x37,0x2e,0x79,0x2c,0x20,0x30,0x2e, + 0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + #version 430 + + layout(location = 0) in vec2 v_uv; + layout(location = 0) out vec2 out_color; + + float radicalInverseVdC(inout uint bits) + { + bits = (bits << 16u) | (bits >> 16u); + bits = ((bits & 1431655765u) << 1u) | ((bits & 2863311530u) >> 1u); + bits = ((bits & 858993459u) << 2u) | ((bits & 3435973836u) >> 2u); + bits = ((bits & 252645135u) << 4u) | ((bits & 4042322160u) >> 4u); + bits = ((bits & 16711935u) << 8u) | ((bits & 4278255360u) >> 8u); + return float(bits) * 2.3283064365386962890625e-10; + } + + vec2 hammersley(uint i, uint n) + { + uint param = i; + float _97 = radicalInverseVdC(param); + return vec2(float(i) / float(n), _97); + } + + vec3 importanceSampleGGX(vec2 Xi, float alpha) + { + float _110 = 6.283185482025146484375 * Xi.x; + float _123 = sqrt((1.0 - Xi.y) / (1.0 + (((alpha * alpha) - 1.0) * Xi.y))); + float _131 = sqrt(max(1.0 - (_123 * _123), 0.0)); + return vec3(_131 * cos(_110), _131 * sin(_110), _123); + } + + float smithGggxIbl(float n_dot_v, float n_dot_l, float alpha) + { + float _149 = (alpha * alpha) * 0.5; + float _154 = 1.0 - _149; + return (n_dot_v / ((n_dot_v * _154) + _149)) * (n_dot_l / ((n_dot_l * _154) + _149)); + } + + vec2 integrateBRDF(float n_dot_v, float roughness) + { + vec3 _182 = vec3(sqrt(max(1.0 - (n_dot_v * n_dot_v), 0.0)), 0.0, n_dot_v); + float A = 0.0; + float B = 0.0; + float _188 = roughness * roughness; + for (uint i = 0u; i < 1024u; i++) + { + uint param = i; + uint param_1 = 1024u; + vec2 param_2 = hammersley(param, param_1); + float param_3 = _188; + vec3 _209 = importanceSampleGGX(param_2, param_3); + float _214 = dot(_182, _209); + float _223 = max(((_209 * (2.0 * _214)) - _182).z, 0.0); + float _232 = max(_214, 0.0); + if (_223 > 0.0) + { + float param_4 = n_dot_v; + float param_5 = _223; + float param_6 = _188; + float _254 = (smithGggxIbl(param_4, param_5, param_6) * _232) / max(max(_209.z, 0.0) * n_dot_v, 9.9999997473787516355514526367188e-06); + float _260 = pow(max(0.0, 1.0 - _232), 5.0); + A += ((1.0 - _260) * _254); + B += (_260 * _254); + } + } + return vec2(A, B) * vec2(0.0009765625); + } + + void main() + { + float param = max(v_uv.x, 0.001000000047497451305389404296875); + float param_1 = max(v_uv.y, 0.001000000047497451305389404296875); + out_color = integrateBRDF(param, param_1); + } + +*/ +static const uint8_t brdf_lut_fs_source_glsl430[2450] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x76,0x5f,0x75,0x76,0x3b, + 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x32,0x20,0x6f, + 0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x72,0x61,0x64,0x69,0x63,0x61,0x6c,0x49,0x6e,0x76,0x65,0x72,0x73,0x65,0x56, + 0x64,0x43,0x28,0x69,0x6e,0x6f,0x75,0x74,0x20,0x75,0x69,0x6e,0x74,0x20,0x62,0x69, + 0x74,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x62,0x69,0x74,0x73,0x20,0x3d, + 0x20,0x28,0x62,0x69,0x74,0x73,0x20,0x3c,0x3c,0x20,0x31,0x36,0x75,0x29,0x20,0x7c, + 0x20,0x28,0x62,0x69,0x74,0x73,0x20,0x3e,0x3e,0x20,0x31,0x36,0x75,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x62,0x69,0x74,0x73,0x20,0x3d,0x20,0x28,0x28,0x62,0x69,0x74, + 0x73,0x20,0x26,0x20,0x31,0x34,0x33,0x31,0x36,0x35,0x35,0x37,0x36,0x35,0x75,0x29, + 0x20,0x3c,0x3c,0x20,0x31,0x75,0x29,0x20,0x7c,0x20,0x28,0x28,0x62,0x69,0x74,0x73, + 0x20,0x26,0x20,0x32,0x38,0x36,0x33,0x33,0x31,0x31,0x35,0x33,0x30,0x75,0x29,0x20, + 0x3e,0x3e,0x20,0x31,0x75,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x69,0x74,0x73, + 0x20,0x3d,0x20,0x28,0x28,0x62,0x69,0x74,0x73,0x20,0x26,0x20,0x38,0x35,0x38,0x39, + 0x39,0x33,0x34,0x35,0x39,0x75,0x29,0x20,0x3c,0x3c,0x20,0x32,0x75,0x29,0x20,0x7c, + 0x20,0x28,0x28,0x62,0x69,0x74,0x73,0x20,0x26,0x20,0x33,0x34,0x33,0x35,0x39,0x37, + 0x33,0x38,0x33,0x36,0x75,0x29,0x20,0x3e,0x3e,0x20,0x32,0x75,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x62,0x69,0x74,0x73,0x20,0x3d,0x20,0x28,0x28,0x62,0x69,0x74,0x73, + 0x20,0x26,0x20,0x32,0x35,0x32,0x36,0x34,0x35,0x31,0x33,0x35,0x75,0x29,0x20,0x3c, + 0x3c,0x20,0x34,0x75,0x29,0x20,0x7c,0x20,0x28,0x28,0x62,0x69,0x74,0x73,0x20,0x26, + 0x20,0x34,0x30,0x34,0x32,0x33,0x32,0x32,0x31,0x36,0x30,0x75,0x29,0x20,0x3e,0x3e, + 0x20,0x34,0x75,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x69,0x74,0x73,0x20,0x3d, + 0x20,0x28,0x28,0x62,0x69,0x74,0x73,0x20,0x26,0x20,0x31,0x36,0x37,0x31,0x31,0x39, + 0x33,0x35,0x75,0x29,0x20,0x3c,0x3c,0x20,0x38,0x75,0x29,0x20,0x7c,0x20,0x28,0x28, + 0x62,0x69,0x74,0x73,0x20,0x26,0x20,0x34,0x32,0x37,0x38,0x32,0x35,0x35,0x33,0x36, + 0x30,0x75,0x29,0x20,0x3e,0x3e,0x20,0x38,0x75,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x62,0x69,0x74, + 0x73,0x29,0x20,0x2a,0x20,0x32,0x2e,0x33,0x32,0x38,0x33,0x30,0x36,0x34,0x33,0x36, + 0x35,0x33,0x38,0x36,0x39,0x36,0x32,0x38,0x39,0x30,0x36,0x32,0x35,0x65,0x2d,0x31, + 0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x32,0x20,0x68,0x61,0x6d,0x6d,0x65, + 0x72,0x73,0x6c,0x65,0x79,0x28,0x75,0x69,0x6e,0x74,0x20,0x69,0x2c,0x20,0x75,0x69, + 0x6e,0x74,0x20,0x6e,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x69,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x37,0x20,0x3d,0x20,0x72,0x61,0x64,0x69, + 0x63,0x61,0x6c,0x49,0x6e,0x76,0x65,0x72,0x73,0x65,0x56,0x64,0x43,0x28,0x70,0x61, + 0x72,0x61,0x6d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x76,0x65,0x63,0x32,0x28,0x66,0x6c,0x6f,0x61,0x74,0x28,0x69,0x29,0x20,0x2f, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x6e,0x29,0x2c,0x20,0x5f,0x39,0x37,0x29,0x3b, + 0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x69,0x6d,0x70,0x6f,0x72,0x74,0x61, + 0x6e,0x63,0x65,0x53,0x61,0x6d,0x70,0x6c,0x65,0x47,0x47,0x58,0x28,0x76,0x65,0x63, + 0x32,0x20,0x58,0x69,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70,0x68, + 0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x31,0x30,0x20,0x3d,0x20,0x36,0x2e,0x32,0x38,0x33,0x31,0x38,0x35,0x34,0x38, + 0x32,0x30,0x32,0x35,0x31,0x34,0x36,0x34,0x38,0x34,0x33,0x37,0x35,0x20,0x2a,0x20, + 0x58,0x69,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x32,0x33,0x20,0x3d,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x31,0x2e,0x30, + 0x20,0x2d,0x20,0x58,0x69,0x2e,0x79,0x29,0x20,0x2f,0x20,0x28,0x31,0x2e,0x30,0x20, + 0x2b,0x20,0x28,0x28,0x28,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70, + 0x68,0x61,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x29,0x20,0x2a,0x20,0x58,0x69,0x2e, + 0x79,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x33,0x31,0x20,0x3d,0x20,0x73,0x71,0x72,0x74,0x28,0x6d,0x61,0x78,0x28, + 0x31,0x2e,0x30,0x20,0x2d,0x20,0x28,0x5f,0x31,0x32,0x33,0x20,0x2a,0x20,0x5f,0x31, + 0x32,0x33,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x31,0x33,0x31, + 0x20,0x2a,0x20,0x63,0x6f,0x73,0x28,0x5f,0x31,0x31,0x30,0x29,0x2c,0x20,0x5f,0x31, + 0x33,0x31,0x20,0x2a,0x20,0x73,0x69,0x6e,0x28,0x5f,0x31,0x31,0x30,0x29,0x2c,0x20, + 0x5f,0x31,0x32,0x33,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x73,0x6d,0x69,0x74,0x68,0x47,0x67,0x67,0x78,0x49,0x62,0x6c,0x28,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x39,0x20,0x3d,0x20,0x28,0x61,0x6c,0x70,0x68, + 0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x34, + 0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f,0x31,0x34,0x39,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74, + 0x5f,0x76,0x20,0x2f,0x20,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a, + 0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2b,0x20,0x5f,0x31,0x34,0x39,0x29,0x29,0x20, + 0x2a,0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2f,0x20,0x28,0x28,0x6e, + 0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2b, + 0x20,0x5f,0x31,0x34,0x39,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x32, + 0x20,0x69,0x6e,0x74,0x65,0x67,0x72,0x61,0x74,0x65,0x42,0x52,0x44,0x46,0x28,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x38,0x32,0x20,0x3d, + 0x20,0x76,0x65,0x63,0x33,0x28,0x73,0x71,0x72,0x74,0x28,0x6d,0x61,0x78,0x28,0x31, + 0x2e,0x30,0x20,0x2d,0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20, + 0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,0x2c, + 0x20,0x30,0x2e,0x30,0x2c,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x41,0x20,0x3d,0x20,0x30,0x2e, + 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x42,0x20,0x3d, + 0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x38,0x38,0x20,0x3d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73, + 0x20,0x2a,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6f,0x72,0x20,0x28,0x75,0x69,0x6e,0x74,0x20,0x69,0x20,0x3d,0x20, + 0x30,0x75,0x3b,0x20,0x69,0x20,0x3c,0x20,0x31,0x30,0x32,0x34,0x75,0x3b,0x20,0x69, + 0x2b,0x2b,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x69, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x31,0x30,0x32,0x34,0x75,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x68,0x61,0x6d,0x6d,0x65,0x72,0x73,0x6c,0x65, + 0x79,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31,0x38,0x38,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x32, + 0x30,0x39,0x20,0x3d,0x20,0x69,0x6d,0x70,0x6f,0x72,0x74,0x61,0x6e,0x63,0x65,0x53, + 0x61,0x6d,0x70,0x6c,0x65,0x47,0x47,0x58,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x34,0x20,0x3d, + 0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x38,0x32,0x2c,0x20,0x5f,0x32,0x30,0x39,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x32,0x32,0x33,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x28,0x28,0x5f,0x32,0x30, + 0x39,0x20,0x2a,0x20,0x28,0x32,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x32,0x31,0x34,0x29, + 0x29,0x20,0x2d,0x20,0x5f,0x31,0x38,0x32,0x29,0x2e,0x7a,0x2c,0x20,0x30,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x32,0x33,0x32,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x5f,0x32,0x31,0x34, + 0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x5f,0x32,0x32,0x33,0x20,0x3e,0x20,0x30,0x2e,0x30,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x34,0x20,0x3d,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x5f,0x32,0x32,0x33,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f,0x31,0x38, + 0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x35,0x34,0x20,0x3d,0x20,0x28,0x73,0x6d,0x69, + 0x74,0x68,0x47,0x67,0x67,0x78,0x49,0x62,0x6c,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x36,0x29,0x20,0x2a,0x20,0x5f,0x32,0x33,0x32,0x29,0x20,0x2f,0x20,0x6d, + 0x61,0x78,0x28,0x6d,0x61,0x78,0x28,0x5f,0x32,0x30,0x39,0x2e,0x7a,0x2c,0x20,0x30, + 0x2e,0x30,0x29,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x2c,0x20,0x39, + 0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31, + 0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38, + 0x65,0x2d,0x30,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x36,0x30,0x20,0x3d,0x20, + 0x70,0x6f,0x77,0x28,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30, + 0x20,0x2d,0x20,0x5f,0x32,0x33,0x32,0x29,0x2c,0x20,0x35,0x2e,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x41,0x20,0x2b,0x3d, + 0x20,0x28,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f,0x32,0x36,0x30,0x29,0x20,0x2a, + 0x20,0x5f,0x32,0x35,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x42,0x20,0x2b,0x3d,0x20,0x28,0x5f,0x32,0x36,0x30,0x20,0x2a, + 0x20,0x5f,0x32,0x35,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x76,0x65,0x63,0x32,0x28,0x41,0x2c,0x20,0x42,0x29,0x20,0x2a,0x20, + 0x76,0x65,0x63,0x32,0x28,0x30,0x2e,0x30,0x30,0x30,0x39,0x37,0x36,0x35,0x36,0x32, + 0x35,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e, + 0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x76,0x5f,0x75,0x76,0x2e, + 0x78,0x2c,0x20,0x30,0x2e,0x30,0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x34, + 0x37,0x34,0x39,0x37,0x34,0x35,0x31,0x33,0x30,0x35,0x33,0x38,0x39,0x34,0x30,0x34, + 0x32,0x39,0x36,0x38,0x37,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x6d,0x61,0x78, + 0x28,0x76,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x30,0x2e,0x30,0x30,0x31,0x30,0x30, + 0x30,0x30,0x30,0x30,0x30,0x34,0x37,0x34,0x39,0x37,0x34,0x35,0x31,0x33,0x30,0x35, + 0x33,0x38,0x39,0x34,0x30,0x34,0x32,0x39,0x36,0x38,0x37,0x35,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x69, + 0x6e,0x74,0x65,0x67,0x72,0x61,0x74,0x65,0x42,0x52,0x44,0x46,0x28,0x70,0x61,0x72, + 0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x00, +}; +/* + cbuffer ub_brdf : register(b0) + { + float4 _45_params : packoffset(c0); + }; + + + static float4 gl_Position; + static int gl_VertexIndex; + static float2 v_uv; + + struct SPIRV_Cross_Input + { + uint gl_VertexIndex : SV_VertexID; + }; + + struct SPIRV_Cross_Output + { + float2 v_uv : TEXCOORD0; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + float2 _27 = (float2(float((gl_VertexIndex << 1) & 2), float(gl_VertexIndex & 2)) * 2.0f) - 1.0f.xx; + float _34 = _27.x; + v_uv = float2((_34 * 0.5f) + 0.5f, 0.5f + ((_27.y * 0.5f) * _45_params.x)); + gl_Position = float4(_34, _27.y, 0.0f, 1.0f); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_VertexIndex = int(stage_input.gl_VertexIndex); + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.v_uv = v_uv; + return stage_output; + } +*/ +static const uint8_t brdf_lut_vs_source_hlsl5[869] = { + 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x62,0x72,0x64,0x66,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x34,0x35,0x5f, + 0x70,0x61,0x72,0x61,0x6d,0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66, + 0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x0a,0x73,0x74, + 0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50, + 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, + 0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64, + 0x65,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x32,0x20,0x76,0x5f,0x75,0x76,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20, + 0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75, + 0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f, + 0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x3a,0x20,0x53,0x56, + 0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x44,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73, + 0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73, + 0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x32,0x20,0x76,0x5f,0x75,0x76,0x20,0x3a,0x20,0x54,0x45,0x58, + 0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a, + 0x20,0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e, + 0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20, + 0x5f,0x32,0x37,0x20,0x3d,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x66,0x6c, + 0x6f,0x61,0x74,0x28,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e, + 0x64,0x65,0x78,0x20,0x3c,0x3c,0x20,0x31,0x29,0x20,0x26,0x20,0x32,0x29,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49, + 0x6e,0x64,0x65,0x78,0x20,0x26,0x20,0x32,0x29,0x29,0x20,0x2a,0x20,0x32,0x2e,0x30, + 0x66,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x33,0x34,0x20,0x3d,0x20,0x5f,0x32, + 0x37,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x75,0x76,0x20,0x3d,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x28,0x5f,0x33,0x34,0x20,0x2a,0x20,0x30,0x2e, + 0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2c,0x20,0x30,0x2e,0x35,0x66, + 0x20,0x2b,0x20,0x28,0x28,0x5f,0x32,0x37,0x2e,0x79,0x20,0x2a,0x20,0x30,0x2e,0x35, + 0x66,0x29,0x20,0x2a,0x20,0x5f,0x34,0x35,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e, + 0x78,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x33, + 0x34,0x2c,0x20,0x5f,0x32,0x37,0x2e,0x79,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20, + 0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f, + 0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69, + 0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e, + 0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78, + 0x49,0x6e,0x64,0x65,0x78,0x20,0x3d,0x20,0x69,0x6e,0x74,0x28,0x73,0x74,0x61,0x67, + 0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65, + 0x78,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x72, + 0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50, + 0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74, + 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e, + 0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x67,0x6c, + 0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73, + 0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x75,0x76, + 0x20,0x3d,0x20,0x76,0x5f,0x75,0x76,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74, + 0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + static float2 v_uv; + static float2 out_color; + + struct SPIRV_Cross_Input + { + float2 v_uv : TEXCOORD0; + }; + + struct SPIRV_Cross_Output + { + float2 out_color : SV_Target0; + }; + + float radicalInverseVdC(inout uint bits) + { + bits = (bits << 16u) | (bits >> 16u); + bits = ((bits & 1431655765u) << 1u) | ((bits & 2863311530u) >> 1u); + bits = ((bits & 858993459u) << 2u) | ((bits & 3435973836u) >> 2u); + bits = ((bits & 252645135u) << 4u) | ((bits & 4042322160u) >> 4u); + bits = ((bits & 16711935u) << 8u) | ((bits & 4278255360u) >> 8u); + return float(bits) * 2.3283064365386962890625e-10f; + } + + float2 hammersley(uint i, uint n) + { + uint param = i; + float _97 = radicalInverseVdC(param); + return float2(float(i) / float(n), _97); + } + + float3 importanceSampleGGX(float2 Xi, float alpha) + { + float _110 = 6.283185482025146484375f * Xi.x; + float _123 = sqrt((1.0f - Xi.y) / (1.0f + (((alpha * alpha) - 1.0f) * Xi.y))); + float _131 = sqrt(max(1.0f - (_123 * _123), 0.0f)); + return float3(_131 * cos(_110), _131 * sin(_110), _123); + } + + float smithGggxIbl(float n_dot_v, float n_dot_l, float alpha) + { + float _149 = (alpha * alpha) * 0.5f; + float _154 = 1.0f - _149; + return (n_dot_v / ((n_dot_v * _154) + _149)) * (n_dot_l / ((n_dot_l * _154) + _149)); + } + + float2 integrateBRDF(float n_dot_v, float roughness) + { + float3 _182 = float3(sqrt(max(1.0f - (n_dot_v * n_dot_v), 0.0f)), 0.0f, n_dot_v); + float A = 0.0f; + float B = 0.0f; + float _188 = roughness * roughness; + for (uint i = 0u; i < 1024u; i++) + { + uint param = i; + uint param_1 = 1024u; + float2 param_2 = hammersley(param, param_1); + float param_3 = _188; + float3 _209 = importanceSampleGGX(param_2, param_3); + float _214 = dot(_182, _209); + float _223 = max(((_209 * (2.0f * _214)) - _182).z, 0.0f); + float _232 = max(_214, 0.0f); + if (_223 > 0.0f) + { + float param_4 = n_dot_v; + float param_5 = _223; + float param_6 = _188; + float _254 = (smithGggxIbl(param_4, param_5, param_6) * _232) / max(max(_209.z, 0.0f) * n_dot_v, 9.9999997473787516355514526367188e-06f); + float _260 = pow(max(0.0f, 1.0f - _232), 5.0f); + A += ((1.0f - _260) * _254); + B += (_260 * _254); + } + } + return float2(A, B) * 0.0009765625f.xx; + } + + void frag_main() + { + float param = max(v_uv.x, 0.001000000047497451305389404296875f); + float param_1 = max(v_uv.y, 0.001000000047497451305389404296875f); + out_color = integrateBRDF(param, param_1); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + v_uv = stage_input.v_uv; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.out_color = out_color; + return stage_output; + } +*/ +static const uint8_t brdf_lut_fs_source_hlsl5[2790] = { + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x76,0x5f, + 0x75,0x76,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x32,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73, + 0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x32,0x20,0x76,0x5f,0x75,0x76,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f, + 0x4f,0x52,0x44,0x30,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74, + 0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74, + 0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, + 0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x53,0x56,0x5f, + 0x54,0x61,0x72,0x67,0x65,0x74,0x30,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x72,0x61,0x64,0x69,0x63,0x61,0x6c,0x49,0x6e,0x76,0x65,0x72,0x73, + 0x65,0x56,0x64,0x43,0x28,0x69,0x6e,0x6f,0x75,0x74,0x20,0x75,0x69,0x6e,0x74,0x20, + 0x62,0x69,0x74,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x62,0x69,0x74,0x73, + 0x20,0x3d,0x20,0x28,0x62,0x69,0x74,0x73,0x20,0x3c,0x3c,0x20,0x31,0x36,0x75,0x29, + 0x20,0x7c,0x20,0x28,0x62,0x69,0x74,0x73,0x20,0x3e,0x3e,0x20,0x31,0x36,0x75,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x69,0x74,0x73,0x20,0x3d,0x20,0x28,0x28,0x62, + 0x69,0x74,0x73,0x20,0x26,0x20,0x31,0x34,0x33,0x31,0x36,0x35,0x35,0x37,0x36,0x35, + 0x75,0x29,0x20,0x3c,0x3c,0x20,0x31,0x75,0x29,0x20,0x7c,0x20,0x28,0x28,0x62,0x69, + 0x74,0x73,0x20,0x26,0x20,0x32,0x38,0x36,0x33,0x33,0x31,0x31,0x35,0x33,0x30,0x75, + 0x29,0x20,0x3e,0x3e,0x20,0x31,0x75,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x69, + 0x74,0x73,0x20,0x3d,0x20,0x28,0x28,0x62,0x69,0x74,0x73,0x20,0x26,0x20,0x38,0x35, + 0x38,0x39,0x39,0x33,0x34,0x35,0x39,0x75,0x29,0x20,0x3c,0x3c,0x20,0x32,0x75,0x29, + 0x20,0x7c,0x20,0x28,0x28,0x62,0x69,0x74,0x73,0x20,0x26,0x20,0x33,0x34,0x33,0x35, + 0x39,0x37,0x33,0x38,0x33,0x36,0x75,0x29,0x20,0x3e,0x3e,0x20,0x32,0x75,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x62,0x69,0x74,0x73,0x20,0x3d,0x20,0x28,0x28,0x62,0x69, + 0x74,0x73,0x20,0x26,0x20,0x32,0x35,0x32,0x36,0x34,0x35,0x31,0x33,0x35,0x75,0x29, + 0x20,0x3c,0x3c,0x20,0x34,0x75,0x29,0x20,0x7c,0x20,0x28,0x28,0x62,0x69,0x74,0x73, + 0x20,0x26,0x20,0x34,0x30,0x34,0x32,0x33,0x32,0x32,0x31,0x36,0x30,0x75,0x29,0x20, + 0x3e,0x3e,0x20,0x34,0x75,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x69,0x74,0x73, + 0x20,0x3d,0x20,0x28,0x28,0x62,0x69,0x74,0x73,0x20,0x26,0x20,0x31,0x36,0x37,0x31, + 0x31,0x39,0x33,0x35,0x75,0x29,0x20,0x3c,0x3c,0x20,0x38,0x75,0x29,0x20,0x7c,0x20, + 0x28,0x28,0x62,0x69,0x74,0x73,0x20,0x26,0x20,0x34,0x32,0x37,0x38,0x32,0x35,0x35, + 0x33,0x36,0x30,0x75,0x29,0x20,0x3e,0x3e,0x20,0x38,0x75,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x62, + 0x69,0x74,0x73,0x29,0x20,0x2a,0x20,0x32,0x2e,0x33,0x32,0x38,0x33,0x30,0x36,0x34, + 0x33,0x36,0x35,0x33,0x38,0x36,0x39,0x36,0x32,0x38,0x39,0x30,0x36,0x32,0x35,0x65, + 0x2d,0x31,0x30,0x66,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20, + 0x68,0x61,0x6d,0x6d,0x65,0x72,0x73,0x6c,0x65,0x79,0x28,0x75,0x69,0x6e,0x74,0x20, + 0x69,0x2c,0x20,0x75,0x69,0x6e,0x74,0x20,0x6e,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x75,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x69,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x37,0x20,0x3d, + 0x20,0x72,0x61,0x64,0x69,0x63,0x61,0x6c,0x49,0x6e,0x76,0x65,0x72,0x73,0x65,0x56, + 0x64,0x43,0x28,0x70,0x61,0x72,0x61,0x6d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x66,0x6c,0x6f, + 0x61,0x74,0x28,0x69,0x29,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x6e,0x29, + 0x2c,0x20,0x5f,0x39,0x37,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x69,0x6d,0x70,0x6f,0x72,0x74,0x61,0x6e,0x63,0x65,0x53,0x61,0x6d,0x70, + 0x6c,0x65,0x47,0x47,0x58,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x58,0x69,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x30,0x20,0x3d, + 0x20,0x36,0x2e,0x32,0x38,0x33,0x31,0x38,0x35,0x34,0x38,0x32,0x30,0x32,0x35,0x31, + 0x34,0x36,0x34,0x38,0x34,0x33,0x37,0x35,0x66,0x20,0x2a,0x20,0x58,0x69,0x2e,0x78, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x33, + 0x20,0x3d,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20, + 0x58,0x69,0x2e,0x79,0x29,0x20,0x2f,0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2b,0x20, + 0x28,0x28,0x28,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61, + 0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x66,0x29,0x20,0x2a,0x20,0x58,0x69,0x2e,0x79, + 0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x33,0x31,0x20,0x3d,0x20,0x73,0x71,0x72,0x74,0x28,0x6d,0x61,0x78,0x28,0x31, + 0x2e,0x30,0x66,0x20,0x2d,0x20,0x28,0x5f,0x31,0x32,0x33,0x20,0x2a,0x20,0x5f,0x31, + 0x32,0x33,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f, + 0x31,0x33,0x31,0x20,0x2a,0x20,0x63,0x6f,0x73,0x28,0x5f,0x31,0x31,0x30,0x29,0x2c, + 0x20,0x5f,0x31,0x33,0x31,0x20,0x2a,0x20,0x73,0x69,0x6e,0x28,0x5f,0x31,0x31,0x30, + 0x29,0x2c,0x20,0x5f,0x31,0x32,0x33,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x73,0x6d,0x69,0x74,0x68,0x47,0x67,0x67,0x78,0x49,0x62,0x6c,0x28, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x39,0x20,0x3d,0x20,0x28,0x61, + 0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x20,0x2a,0x20, + 0x30,0x2e,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x35,0x34,0x20,0x3d,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x5f,0x31, + 0x34,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28, + 0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2f,0x20,0x28,0x28,0x6e,0x5f,0x64,0x6f, + 0x74,0x5f,0x76,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2b,0x20,0x5f,0x31, + 0x34,0x39,0x29,0x29,0x20,0x2a,0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20, + 0x2f,0x20,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x5f,0x31, + 0x35,0x34,0x29,0x20,0x2b,0x20,0x5f,0x31,0x34,0x39,0x29,0x29,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x69,0x6e,0x74,0x65,0x67,0x72,0x61,0x74, + 0x65,0x42,0x52,0x44,0x46,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f, + 0x74,0x5f,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68, + 0x6e,0x65,0x73,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x5f,0x31,0x38,0x32,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x28,0x73,0x71,0x72,0x74,0x28,0x6d,0x61,0x78,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d, + 0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f, + 0x74,0x5f,0x76,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x29,0x2c,0x20,0x30,0x2e, + 0x30,0x66,0x2c,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x41,0x20,0x3d,0x20,0x30,0x2e,0x30,0x66, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x42,0x20,0x3d,0x20, + 0x30,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x38,0x38,0x20,0x3d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73, + 0x20,0x2a,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6f,0x72,0x20,0x28,0x75,0x69,0x6e,0x74,0x20,0x69,0x20,0x3d,0x20, + 0x30,0x75,0x3b,0x20,0x69,0x20,0x3c,0x20,0x31,0x30,0x32,0x34,0x75,0x3b,0x20,0x69, + 0x2b,0x2b,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x69, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x31,0x30,0x32,0x34,0x75,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x68,0x61,0x6d,0x6d,0x65,0x72,0x73, + 0x6c,0x65,0x79,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31,0x38, + 0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x5f,0x32,0x30,0x39,0x20,0x3d,0x20,0x69,0x6d,0x70,0x6f,0x72,0x74,0x61, + 0x6e,0x63,0x65,0x53,0x61,0x6d,0x70,0x6c,0x65,0x47,0x47,0x58,0x28,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32, + 0x31,0x34,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x38,0x32,0x2c,0x20,0x5f, + 0x32,0x30,0x39,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x32,0x32,0x33,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x28, + 0x28,0x5f,0x32,0x30,0x39,0x20,0x2a,0x20,0x28,0x32,0x2e,0x30,0x66,0x20,0x2a,0x20, + 0x5f,0x32,0x31,0x34,0x29,0x29,0x20,0x2d,0x20,0x5f,0x31,0x38,0x32,0x29,0x2e,0x7a, + 0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x33,0x32,0x20,0x3d,0x20,0x6d,0x61, + 0x78,0x28,0x5f,0x32,0x31,0x34,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x32,0x32,0x33,0x20, + 0x3e,0x20,0x30,0x2e,0x30,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x6e,0x5f, + 0x64,0x6f,0x74,0x5f,0x76,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35, + 0x20,0x3d,0x20,0x5f,0x32,0x32,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x36,0x20,0x3d,0x20,0x5f,0x31,0x38,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x35, + 0x34,0x20,0x3d,0x20,0x28,0x73,0x6d,0x69,0x74,0x68,0x47,0x67,0x67,0x78,0x49,0x62, + 0x6c,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x20,0x2a,0x20,0x5f, + 0x32,0x33,0x32,0x29,0x20,0x2f,0x20,0x6d,0x61,0x78,0x28,0x6d,0x61,0x78,0x28,0x5f, + 0x32,0x30,0x39,0x2e,0x7a,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x20,0x2a,0x20,0x6e, + 0x5f,0x64,0x6f,0x74,0x5f,0x76,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39, + 0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34, + 0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x66,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x32,0x36,0x30,0x20,0x3d,0x20,0x70,0x6f,0x77,0x28,0x6d,0x61, + 0x78,0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x5f, + 0x32,0x33,0x32,0x29,0x2c,0x20,0x35,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x41,0x20,0x2b,0x3d,0x20,0x28,0x28, + 0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x5f,0x32,0x36,0x30,0x29,0x20,0x2a,0x20,0x5f, + 0x32,0x35,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x42,0x20,0x2b,0x3d,0x20,0x28,0x5f,0x32,0x36,0x30,0x20,0x2a,0x20,0x5f, + 0x32,0x35,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x41,0x2c,0x20,0x42,0x29,0x20,0x2a,0x20, + 0x30,0x2e,0x30,0x30,0x30,0x39,0x37,0x36,0x35,0x36,0x32,0x35,0x66,0x2e,0x78,0x78, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d, + 0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x76,0x5f, + 0x75,0x76,0x2e,0x78,0x2c,0x20,0x30,0x2e,0x30,0x30,0x31,0x30,0x30,0x30,0x30,0x30, + 0x30,0x30,0x34,0x37,0x34,0x39,0x37,0x34,0x35,0x31,0x33,0x30,0x35,0x33,0x38,0x39, + 0x34,0x30,0x34,0x32,0x39,0x36,0x38,0x37,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d, + 0x20,0x6d,0x61,0x78,0x28,0x76,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x30,0x2e,0x30, + 0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x34,0x37,0x34,0x39,0x37,0x34,0x35, + 0x31,0x33,0x30,0x35,0x33,0x38,0x39,0x34,0x30,0x34,0x32,0x39,0x36,0x38,0x37,0x35, + 0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x20,0x3d,0x20,0x69,0x6e,0x74,0x65,0x67,0x72,0x61,0x74,0x65,0x42,0x52,0x44, + 0x46,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73, + 0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50, + 0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x5f,0x75,0x76,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f, + 0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x75,0x76,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74, + 0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70, + 0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x6f, + 0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75, + 0x74,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + struct ub_brdf + { + float4 params; + }; + + struct main0_out + { + float2 v_uv [[user(locn0)]]; + float4 gl_Position [[position]]; + }; + + vertex main0_out main0(constant ub_brdf& _45 [[buffer(0)]], uint gl_VertexIndex [[vertex_id]]) + { + main0_out out = {}; + float2 _27 = (float2(float((int(gl_VertexIndex) << 1) & 2), float(int(gl_VertexIndex) & 2)) * 2.0) - float2(1.0); + float _34 = _27.x; + out.v_uv = float2((_34 * 0.5) + 0.5, 0.5 + ((_27.y * 0.5) * _45.params.x)); + out.gl_Position = float4(_34, _27.y, 0.0, 1.0); + return out; + } + +*/ +static const uint8_t brdf_lut_vs_source_metal_macos[619] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75, + 0x62,0x5f,0x62,0x72,0x64,0x66,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a, + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x76,0x5f, + 0x75,0x76,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29, + 0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67, + 0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b,0x70,0x6f,0x73, + 0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x65,0x72, + 0x74,0x65,0x78,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61, + 0x69,0x6e,0x30,0x28,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f, + 0x62,0x72,0x64,0x66,0x26,0x20,0x5f,0x34,0x35,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66, + 0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c, + 0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x5b,0x5b,0x76, + 0x65,0x72,0x74,0x65,0x78,0x5f,0x69,0x64,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20, + 0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, + 0x20,0x5f,0x32,0x37,0x20,0x3d,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x66, + 0x6c,0x6f,0x61,0x74,0x28,0x28,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72, + 0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x3c,0x3c,0x20,0x31,0x29,0x20, + 0x26,0x20,0x32,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x69,0x6e,0x74,0x28, + 0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x29,0x20, + 0x26,0x20,0x32,0x29,0x29,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x20,0x2d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x32,0x28,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x33,0x34,0x20,0x3d,0x20,0x5f,0x32,0x37,0x2e, + 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x75,0x76,0x20, + 0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x28,0x5f,0x33,0x34,0x20,0x2a,0x20, + 0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x30,0x2e,0x35,0x20, + 0x2b,0x20,0x28,0x28,0x5f,0x32,0x37,0x2e,0x79,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29, + 0x20,0x2a,0x20,0x5f,0x34,0x35,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, + 0x5f,0x33,0x34,0x2c,0x20,0x5f,0x32,0x37,0x2e,0x79,0x2c,0x20,0x30,0x2e,0x30,0x2c, + 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + #pragma clang diagnostic ignored "-Wmissing-prototypes" + + #include + #include + + using namespace metal; + + struct main0_out + { + float2 out_color [[color(0)]]; + }; + + struct main0_in + { + float2 v_uv [[user(locn0)]]; + }; + + static inline __attribute__((always_inline)) + float radicalInverseVdC(thread uint& bits) + { + bits = (bits << 16u) | (bits >> 16u); + bits = ((bits & 1431655765u) << 1u) | ((bits & 2863311530u) >> 1u); + bits = ((bits & 858993459u) << 2u) | ((bits & 3435973836u) >> 2u); + bits = ((bits & 252645135u) << 4u) | ((bits & 4042322160u) >> 4u); + bits = ((bits & 16711935u) << 8u) | ((bits & 4278255360u) >> 8u); + return float(bits) * 2.3283064365386962890625e-10; + } + + static inline __attribute__((always_inline)) + float2 hammersley(thread const uint& i, thread const uint& n) + { + uint param = i; + float _97 = radicalInverseVdC(param); + return float2(float(i) / float(n), _97); + } + + static inline __attribute__((always_inline)) + float3 importanceSampleGGX(thread const float2& Xi, thread const float& alpha) + { + float _110 = 6.283185482025146484375 * Xi.x; + float _123 = sqrt((1.0 - Xi.y) / (1.0 + (((alpha * alpha) - 1.0) * Xi.y))); + float _131 = sqrt(fast::max(1.0 - (_123 * _123), 0.0)); + return float3(_131 * cos(_110), _131 * sin(_110), _123); + } + + static inline __attribute__((always_inline)) + float smithGggxIbl(thread const float& n_dot_v, thread const float& n_dot_l, thread const float& alpha) + { + float _149 = (alpha * alpha) * 0.5; + float _154 = 1.0 - _149; + return (n_dot_v / ((n_dot_v * _154) + _149)) * (n_dot_l / ((n_dot_l * _154) + _149)); + } + + static inline __attribute__((always_inline)) + float2 integrateBRDF(thread const float& n_dot_v, thread const float& roughness) + { + float3 _182 = float3(sqrt(fast::max(1.0 - (n_dot_v * n_dot_v), 0.0)), 0.0, n_dot_v); + float A = 0.0; + float B = 0.0; + float _188 = roughness * roughness; + for (uint i = 0u; i < 1024u; i++) + { + uint param = i; + uint param_1 = 1024u; + float2 param_2 = hammersley(param, param_1); + float param_3 = _188; + float3 _209 = importanceSampleGGX(param_2, param_3); + float _214 = dot(_182, _209); + float _223 = fast::max(((_209 * (2.0 * _214)) - _182).z, 0.0); + float _232 = fast::max(_214, 0.0); + if (_223 > 0.0) + { + float param_4 = n_dot_v; + float param_5 = _223; + float param_6 = _188; + float _254 = (smithGggxIbl(param_4, param_5, param_6) * _232) / fast::max(fast::max(_209.z, 0.0) * n_dot_v, 9.9999997473787516355514526367188e-06); + float _260 = powr(fast::max(0.0, 1.0 - _232), 5.0); + A += ((1.0 - _260) * _254); + B += (_260 * _254); + } + } + return float2(A, B) * float2(0.0009765625); + } + + fragment main0_out main0(main0_in in [[stage_in]]) + { + main0_out out = {}; + float param = fast::max(in.v_uv.x, 0.001000000047497451305389404296875); + float param_1 = fast::max(in.v_uv.y, 0.001000000047497451305389404296875); + out.out_color = integrateBRDF(param, param_1); + return out; + } + +*/ +static const uint8_t brdf_lut_fs_source_metal_macos[3122] = { + 0x23,0x70,0x72,0x61,0x67,0x6d,0x61,0x20,0x63,0x6c,0x61,0x6e,0x67,0x20,0x64,0x69, + 0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x20,0x69,0x67,0x6e,0x6f,0x72,0x65,0x64, + 0x20,0x22,0x2d,0x57,0x6d,0x69,0x73,0x73,0x69,0x6e,0x67,0x2d,0x70,0x72,0x6f,0x74, + 0x6f,0x74,0x79,0x70,0x65,0x73,0x22,0x0a,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64, + 0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f,0x73,0x74,0x64,0x6c,0x69,0x62,0x3e, + 0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f, + 0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a,0x75,0x73,0x69,0x6e,0x67,0x20,0x6e, + 0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20,0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a, + 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75, + 0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x6f, + 0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x63,0x6f,0x6c,0x6f,0x72, + 0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63, + 0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x76,0x5f,0x75,0x76,0x20,0x5b,0x5b,0x75, + 0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20, + 0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61, + 0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x72,0x61,0x64,0x69,0x63,0x61,0x6c,0x49,0x6e,0x76,0x65, + 0x72,0x73,0x65,0x56,0x64,0x43,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x75,0x69, + 0x6e,0x74,0x26,0x20,0x62,0x69,0x74,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x62,0x69,0x74,0x73,0x20,0x3d,0x20,0x28,0x62,0x69,0x74,0x73,0x20,0x3c,0x3c,0x20, + 0x31,0x36,0x75,0x29,0x20,0x7c,0x20,0x28,0x62,0x69,0x74,0x73,0x20,0x3e,0x3e,0x20, + 0x31,0x36,0x75,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x69,0x74,0x73,0x20,0x3d, + 0x20,0x28,0x28,0x62,0x69,0x74,0x73,0x20,0x26,0x20,0x31,0x34,0x33,0x31,0x36,0x35, + 0x35,0x37,0x36,0x35,0x75,0x29,0x20,0x3c,0x3c,0x20,0x31,0x75,0x29,0x20,0x7c,0x20, + 0x28,0x28,0x62,0x69,0x74,0x73,0x20,0x26,0x20,0x32,0x38,0x36,0x33,0x33,0x31,0x31, + 0x35,0x33,0x30,0x75,0x29,0x20,0x3e,0x3e,0x20,0x31,0x75,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x62,0x69,0x74,0x73,0x20,0x3d,0x20,0x28,0x28,0x62,0x69,0x74,0x73,0x20, + 0x26,0x20,0x38,0x35,0x38,0x39,0x39,0x33,0x34,0x35,0x39,0x75,0x29,0x20,0x3c,0x3c, + 0x20,0x32,0x75,0x29,0x20,0x7c,0x20,0x28,0x28,0x62,0x69,0x74,0x73,0x20,0x26,0x20, + 0x33,0x34,0x33,0x35,0x39,0x37,0x33,0x38,0x33,0x36,0x75,0x29,0x20,0x3e,0x3e,0x20, + 0x32,0x75,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x69,0x74,0x73,0x20,0x3d,0x20, + 0x28,0x28,0x62,0x69,0x74,0x73,0x20,0x26,0x20,0x32,0x35,0x32,0x36,0x34,0x35,0x31, + 0x33,0x35,0x75,0x29,0x20,0x3c,0x3c,0x20,0x34,0x75,0x29,0x20,0x7c,0x20,0x28,0x28, + 0x62,0x69,0x74,0x73,0x20,0x26,0x20,0x34,0x30,0x34,0x32,0x33,0x32,0x32,0x31,0x36, + 0x30,0x75,0x29,0x20,0x3e,0x3e,0x20,0x34,0x75,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x62,0x69,0x74,0x73,0x20,0x3d,0x20,0x28,0x28,0x62,0x69,0x74,0x73,0x20,0x26,0x20, + 0x31,0x36,0x37,0x31,0x31,0x39,0x33,0x35,0x75,0x29,0x20,0x3c,0x3c,0x20,0x38,0x75, + 0x29,0x20,0x7c,0x20,0x28,0x28,0x62,0x69,0x74,0x73,0x20,0x26,0x20,0x34,0x32,0x37, + 0x38,0x32,0x35,0x35,0x33,0x36,0x30,0x75,0x29,0x20,0x3e,0x3e,0x20,0x38,0x75,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x28,0x62,0x69,0x74,0x73,0x29,0x20,0x2a,0x20,0x32,0x2e,0x33,0x32,0x38, + 0x33,0x30,0x36,0x34,0x33,0x36,0x35,0x33,0x38,0x36,0x39,0x36,0x32,0x38,0x39,0x30, + 0x36,0x32,0x35,0x65,0x2d,0x31,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74, + 0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72, + 0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f, + 0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20, + 0x68,0x61,0x6d,0x6d,0x65,0x72,0x73,0x6c,0x65,0x79,0x28,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x75,0x69,0x6e,0x74,0x26,0x20,0x69,0x2c, + 0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x75,0x69, + 0x6e,0x74,0x26,0x20,0x6e,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x69,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x37,0x20,0x3d,0x20,0x72,0x61,0x64, + 0x69,0x63,0x61,0x6c,0x49,0x6e,0x76,0x65,0x72,0x73,0x65,0x56,0x64,0x43,0x28,0x70, + 0x61,0x72,0x61,0x6d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x66,0x6c,0x6f,0x61,0x74,0x28,0x69, + 0x29,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x6e,0x29,0x2c,0x20,0x5f,0x39, + 0x37,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e, + 0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65, + 0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e, + 0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6d,0x70,0x6f,0x72, + 0x74,0x61,0x6e,0x63,0x65,0x53,0x61,0x6d,0x70,0x6c,0x65,0x47,0x47,0x58,0x28,0x74, + 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x32,0x26,0x20,0x58,0x69,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x61,0x6c,0x70,0x68, + 0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x31,0x30,0x20,0x3d,0x20,0x36,0x2e,0x32,0x38,0x33,0x31,0x38,0x35,0x34,0x38, + 0x32,0x30,0x32,0x35,0x31,0x34,0x36,0x34,0x38,0x34,0x33,0x37,0x35,0x20,0x2a,0x20, + 0x58,0x69,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x32,0x33,0x20,0x3d,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x31,0x2e,0x30, + 0x20,0x2d,0x20,0x58,0x69,0x2e,0x79,0x29,0x20,0x2f,0x20,0x28,0x31,0x2e,0x30,0x20, + 0x2b,0x20,0x28,0x28,0x28,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70, + 0x68,0x61,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x29,0x20,0x2a,0x20,0x58,0x69,0x2e, + 0x79,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x33,0x31,0x20,0x3d,0x20,0x73,0x71,0x72,0x74,0x28,0x66,0x61,0x73,0x74, + 0x3a,0x3a,0x6d,0x61,0x78,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x28,0x5f,0x31,0x32, + 0x33,0x20,0x2a,0x20,0x5f,0x31,0x32,0x33,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x28,0x5f,0x31,0x33,0x31,0x20,0x2a,0x20,0x63,0x6f,0x73,0x28,0x5f, + 0x31,0x31,0x30,0x29,0x2c,0x20,0x5f,0x31,0x33,0x31,0x20,0x2a,0x20,0x73,0x69,0x6e, + 0x28,0x5f,0x31,0x31,0x30,0x29,0x2c,0x20,0x5f,0x31,0x32,0x33,0x29,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20, + 0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61, + 0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x73,0x6d,0x69,0x74,0x68,0x47,0x67,0x67,0x78,0x49,0x62, + 0x6c,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x26,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x2c,0x20,0x74, + 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x26,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x74,0x68,0x72,0x65, + 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20, + 0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x34,0x39,0x20,0x3d,0x20,0x28,0x61,0x6c,0x70,0x68,0x61, + 0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x34,0x20, + 0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f,0x31,0x34,0x39,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f, + 0x76,0x20,0x2f,0x20,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20, + 0x5f,0x31,0x35,0x34,0x29,0x20,0x2b,0x20,0x5f,0x31,0x34,0x39,0x29,0x29,0x20,0x2a, + 0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2f,0x20,0x28,0x28,0x6e,0x5f, + 0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2b,0x20, + 0x5f,0x31,0x34,0x39,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69, + 0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69, + 0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69, + 0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x69, + 0x6e,0x74,0x65,0x67,0x72,0x61,0x74,0x65,0x42,0x52,0x44,0x46,0x28,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26, + 0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x72,0x6f, + 0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x38,0x32,0x20,0x3d,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x28,0x73,0x71,0x72,0x74,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d, + 0x61,0x78,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f, + 0x76,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x29,0x2c,0x20,0x30,0x2e, + 0x30,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f, + 0x76,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x41,0x20, + 0x3d,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x42,0x20,0x3d,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x31,0x38,0x38,0x20,0x3d,0x20,0x72,0x6f,0x75,0x67,0x68, + 0x6e,0x65,0x73,0x73,0x20,0x2a,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x20,0x28,0x75,0x69,0x6e,0x74,0x20, + 0x69,0x20,0x3d,0x20,0x30,0x75,0x3b,0x20,0x69,0x20,0x3c,0x20,0x31,0x30,0x32,0x34, + 0x75,0x3b,0x20,0x69,0x2b,0x2b,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x20,0x3d,0x20,0x69,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x75,0x69, + 0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x31,0x30,0x32, + 0x34,0x75,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x68,0x61,0x6d, + 0x6d,0x65,0x72,0x73,0x6c,0x65,0x79,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d, + 0x20,0x5f,0x31,0x38,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x32,0x30,0x39,0x20,0x3d,0x20,0x69,0x6d,0x70, + 0x6f,0x72,0x74,0x61,0x6e,0x63,0x65,0x53,0x61,0x6d,0x70,0x6c,0x65,0x47,0x47,0x58, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x32,0x31,0x34,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x38, + 0x32,0x2c,0x20,0x5f,0x32,0x30,0x39,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x32,0x33,0x20,0x3d,0x20,0x66, + 0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x28,0x28,0x5f,0x32,0x30,0x39,0x20, + 0x2a,0x20,0x28,0x32,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x32,0x31,0x34,0x29,0x29,0x20, + 0x2d,0x20,0x5f,0x31,0x38,0x32,0x29,0x2e,0x7a,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x32,0x33,0x32,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28, + 0x5f,0x32,0x31,0x34,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x32,0x32,0x33,0x20,0x3e,0x20,0x30, + 0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f, + 0x76,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x5f, + 0x32,0x32,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d, + 0x20,0x5f,0x31,0x38,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x35,0x34,0x20,0x3d,0x20, + 0x28,0x73,0x6d,0x69,0x74,0x68,0x47,0x67,0x67,0x78,0x49,0x62,0x6c,0x28,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x20,0x2a,0x20,0x5f,0x32,0x33,0x32,0x29, + 0x20,0x2f,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x66,0x61,0x73, + 0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x5f,0x32,0x30,0x39,0x2e,0x7a,0x2c,0x20,0x30, + 0x2e,0x30,0x29,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x2c,0x20,0x39, + 0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31, + 0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38, + 0x65,0x2d,0x30,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x36,0x30,0x20,0x3d,0x20, + 0x70,0x6f,0x77,0x72,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x30, + 0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f,0x32,0x33,0x32,0x29,0x2c, + 0x20,0x35,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x41,0x20,0x2b,0x3d,0x20,0x28,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20, + 0x5f,0x32,0x36,0x30,0x29,0x20,0x2a,0x20,0x5f,0x32,0x35,0x34,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x42,0x20,0x2b,0x3d,0x20, + 0x28,0x5f,0x32,0x36,0x30,0x20,0x2a,0x20,0x5f,0x32,0x35,0x34,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, + 0x28,0x41,0x2c,0x20,0x42,0x29,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28, + 0x30,0x2e,0x30,0x30,0x30,0x39,0x37,0x36,0x35,0x36,0x32,0x35,0x29,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30, + 0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30, + 0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69, + 0x6e,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30, + 0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d, + 0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x69,0x6e,0x2e,0x76,0x5f, + 0x75,0x76,0x2e,0x78,0x2c,0x20,0x30,0x2e,0x30,0x30,0x31,0x30,0x30,0x30,0x30,0x30, + 0x30,0x30,0x34,0x37,0x34,0x39,0x37,0x34,0x35,0x31,0x33,0x30,0x35,0x33,0x38,0x39, + 0x34,0x30,0x34,0x32,0x39,0x36,0x38,0x37,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20, + 0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x75, + 0x76,0x2e,0x79,0x2c,0x20,0x30,0x2e,0x30,0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30, + 0x30,0x34,0x37,0x34,0x39,0x37,0x34,0x35,0x31,0x33,0x30,0x35,0x33,0x38,0x39,0x34, + 0x30,0x34,0x32,0x39,0x36,0x38,0x37,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f, + 0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x69, + 0x6e,0x74,0x65,0x67,0x72,0x61,0x74,0x65,0x42,0x52,0x44,0x46,0x28,0x70,0x61,0x72, + 0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x00, +}; +static inline const sg_shader_desc* brdf_lut_build_shader_desc(sg_backend backend) { + if (backend == SG_BACKEND_GLCORE) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)brdf_lut_vs_source_glsl430; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)brdf_lut_fs_source_glsl430; + desc.fragment_func.entry = "main"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 16; + desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[0].glsl_uniforms[0].array_count = 1; + desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_brdf"; + desc.label = "brdf_lut_build_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_D3D11) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)brdf_lut_vs_source_hlsl5; + desc.vertex_func.d3d11_target = "vs_5_0"; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)brdf_lut_fs_source_hlsl5; + desc.fragment_func.d3d11_target = "ps_5_0"; + desc.fragment_func.entry = "main"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 16; + desc.uniform_blocks[0].hlsl_register_b_n = 0; + desc.label = "brdf_lut_build_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_METAL_MACOS) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)brdf_lut_vs_source_metal_macos; + desc.vertex_func.entry = "main0"; + desc.fragment_func.source = (const char*)brdf_lut_fs_source_metal_macos; + desc.fragment_func.entry = "main0"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 16; + desc.uniform_blocks[0].msl_buffer_n = 0; + desc.label = "brdf_lut_build_shader"; + } + return &desc; + } + return 0; +} diff --git a/samples/shaders/generated/capsule.glsl.h b/samples/shaders/generated/capsule.glsl.h new file mode 100644 index 0000000..51244f2 --- /dev/null +++ b/samples/shaders/generated/capsule.glsl.h @@ -0,0 +1,5707 @@ +#pragma once +/* + #version:1# (machine generated, don't edit!) + + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) + + Cmdline: + sokol-shdc --input E:/box/box3d/samples/shaders/shapes/capsule.glsl --output E:/box/box3d/samples/shaders/generated/capsule.glsl.h --slang hlsl5:metal_macos:glsl430 + + Overview: + ========= + Shader program: 'impostor': + Get shader desc: capsule_impostor_shader_desc(sg_query_backend()); + Vertex Shader: vs + Fragment Shader: fs + Attributes: + ATTR_capsule_impostor_in_pos => 0 + Bindings: + Uniform block 'ub_draw': + C struct: capsule_ub_draw_t + Bind slot: UB_capsule_ub_draw => 2 + Uniform block 'ub_frame': + C struct: capsule_ub_frame_t + Bind slot: UB_capsule_ub_frame => 0 + Uniform block 'ub_pass': + C struct: capsule_ub_pass_t + Bind slot: UB_capsule_ub_pass => 1 + Storage buffer 'instances': + C struct: capsule_instance_t + Bind slot: VIEW_capsule_instances => 0 + Readonly: true + Texture 'tex_shadow': + Image type: SG_IMAGETYPE_ARRAY + Sample type: SG_IMAGESAMPLETYPE_DEPTH + Multisampled: false + Bind slot: VIEW_capsule_tex_shadow => 1 + Texture 'tex_ao': + Image type: SG_IMAGETYPE_2D + Sample type: SG_IMAGESAMPLETYPE_FLOAT + Multisampled: false + Bind slot: VIEW_capsule_tex_ao => 4 + Texture 'tex_ibl_spec': + Image type: SG_IMAGETYPE_CUBE + Sample type: SG_IMAGESAMPLETYPE_FLOAT + Multisampled: false + Bind slot: VIEW_capsule_tex_ibl_spec => 2 + Texture 'tex_brdf_lut': + Image type: SG_IMAGETYPE_2D + Sample type: SG_IMAGESAMPLETYPE_FLOAT + Multisampled: false + Bind slot: VIEW_capsule_tex_brdf_lut => 3 + Sampler 'smp_shadow': + Type: SG_SAMPLERTYPE_COMPARISON + Bind slot: SMP_capsule_smp_shadow => 0 + Sampler 'smp_ao': + Type: SG_SAMPLERTYPE_FILTERING + Bind slot: SMP_capsule_smp_ao => 3 + Sampler 'smp_ibl_spec': + Type: SG_SAMPLERTYPE_FILTERING + Bind slot: SMP_capsule_smp_ibl_spec => 1 + Sampler 'smp_brdf_lut': + Type: SG_SAMPLERTYPE_FILTERING + Bind slot: SMP_capsule_smp_brdf_lut => 2 +*/ +#if !defined(SOKOL_GFX_INCLUDED) +#error "Please include sokol_gfx.h before capsule.glsl.h" +#endif +#if !defined(SOKOL_SHDC_ALIGN) +#if defined(_MSC_VER) +#define SOKOL_SHDC_ALIGN(a) __declspec(align(a)) +#else +#define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) +#endif +#endif +#define ATTR_capsule_impostor_in_pos (0) +#define UB_capsule_ub_draw (2) +#define UB_capsule_ub_frame (0) +#define UB_capsule_ub_pass (1) +#define VIEW_capsule_instances (0) +#define VIEW_capsule_tex_shadow (1) +#define VIEW_capsule_tex_ao (4) +#define VIEW_capsule_tex_ibl_spec (2) +#define VIEW_capsule_tex_brdf_lut (3) +#define SMP_capsule_smp_shadow (0) +#define SMP_capsule_smp_ao (3) +#define SMP_capsule_smp_ibl_spec (1) +#define SMP_capsule_smp_brdf_lut (2) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct capsule_ub_draw_t { + int inst_base[4]; +} capsule_ub_draw_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct capsule_ub_frame_t { + Mat4 view_proj; +} capsule_ub_frame_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct capsule_ub_pass_t { + Vec4 sun_dir_world; + Vec4 sun_color; + int flags[4]; + Vec4 camera_pos; + Mat4 view_proj; + Mat4 view; + Vec4 cascade_far_view_z; + Mat4 cascade_matrices[3]; + Vec4 sh[9]; + Vec4 ibl_params; +} capsule_ub_pass_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct capsule_instance_t { + Vec4 xform_row0; + Vec4 xform_row1; + Vec4 xform_row2; + Vec4 base_color; + Vec4 params; + Vec4 material; +} capsule_instance_t; +#pragma pack(pop) +/* + #version 430 + + struct instance + { + vec4 xform_row0; + vec4 xform_row1; + vec4 xform_row2; + vec4 base_color; + vec4 params; + vec4 material; + }; + + layout(binding = 0, std430) readonly buffer instances + { + instance items[]; + } _15; + + uniform ivec4 ub_draw[1]; + uniform vec4 ub_frame[4]; + layout(location = 0) in vec3 in_pos; + layout(location = 0) out vec3 v_world_pos_proxy; + layout(location = 1) flat out vec3 v_center; + layout(location = 2) flat out float v_half_length; + layout(location = 3) flat out float v_radius; + layout(location = 4) flat out vec3 v_axis_x_world; + layout(location = 5) flat out vec3 v_rot_row0; + layout(location = 6) flat out vec3 v_rot_row1; + layout(location = 7) flat out vec3 v_rot_row2; + layout(location = 8) flat out vec4 v_base_color; + layout(location = 9) flat out vec4 v_material; + + void main() + { + int _30 = ub_draw[0].x + gl_InstanceID; + vec3 _63 = vec3(_15.items[_30].xform_row0.w, _15.items[_30].xform_row1.w, _15.items[_30].xform_row2.w); + vec3 _94 = vec3((in_pos.x * 2.0) * (_15.items[_30].params.x + _15.items[_30].params.y), (in_pos.y * 2.0) * _15.items[_30].params.y, (in_pos.z * 2.0) * _15.items[_30].params.y); + vec3 _113 = _63 + vec3(dot(_15.items[_30].xform_row0.xyz, _94), dot(_15.items[_30].xform_row1.xyz, _94), dot(_15.items[_30].xform_row2.xyz, _94)); + v_world_pos_proxy = _113; + v_center = _63; + v_half_length = _15.items[_30].params.x; + v_radius = _15.items[_30].params.y; + v_axis_x_world = vec3(_15.items[_30].xform_row0.x, _15.items[_30].xform_row1.x, _15.items[_30].xform_row2.x); + v_rot_row0 = _15.items[_30].xform_row0.xyz; + v_rot_row1 = _15.items[_30].xform_row1.xyz; + v_rot_row2 = _15.items[_30].xform_row2.xyz; + v_base_color = _15.items[_30].base_color; + v_material = _15.items[_30].material; + gl_Position = mat4(ub_frame[0], ub_frame[1], ub_frame[2], ub_frame[3]) * vec4(_113, 1.0); + } + +*/ +static const uint8_t capsule_vs_source_glsl430[1888] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72, + 0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x6d,0x61, + 0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f, + 0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x30,0x2c,0x20, + 0x73,0x74,0x64,0x34,0x33,0x30,0x29,0x20,0x72,0x65,0x61,0x64,0x6f,0x6e,0x6c,0x79, + 0x20,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x20,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5d,0x3b,0x0a,0x7d,0x20,0x5f,0x31,0x35,0x3b, + 0x0a,0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x69,0x76,0x65,0x63,0x34,0x20, + 0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x5b,0x31,0x5d,0x3b,0x0a,0x75,0x6e,0x69,0x66, + 0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d, + 0x65,0x5b,0x34,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63, + 0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65, + 0x63,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75, + 0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20, + 0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x6c,0x61,0x79,0x6f, + 0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29, + 0x20,0x66,0x6c,0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20,0x76, + 0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28, + 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x66,0x6c, + 0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x68, + 0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x6c,0x61,0x79,0x6f, + 0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x33,0x29, + 0x20,0x66,0x6c,0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, + 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x34,0x29,0x20,0x66, + 0x6c,0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x61, + 0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x6c,0x61,0x79, + 0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x35, + 0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20, + 0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x6c,0x61,0x79,0x6f, + 0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x36,0x29, + 0x20,0x66,0x6c,0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20,0x76, + 0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75, + 0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x37,0x29,0x20, + 0x66,0x6c,0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f, + 0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, + 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x38,0x29,0x20,0x66, + 0x6c,0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x5f,0x62, + 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75, + 0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x39,0x29,0x20, + 0x66,0x6c,0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x5f, + 0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20, + 0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74, + 0x20,0x5f,0x33,0x30,0x20,0x3d,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x5b,0x30, + 0x5d,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x49,0x44,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x36, + 0x33,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65, + 0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f, + 0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b, + 0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e, + 0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30, + 0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x77,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x39,0x34,0x20,0x3d,0x20, + 0x76,0x65,0x63,0x33,0x28,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x20,0x2a, + 0x20,0x32,0x2e,0x30,0x29,0x20,0x2a,0x20,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65, + 0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78, + 0x20,0x2b,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30, + 0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x29,0x2c,0x20,0x28,0x69,0x6e, + 0x5f,0x70,0x6f,0x73,0x2e,0x79,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x20,0x2a,0x20, + 0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x70, + 0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x2c,0x20,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73, + 0x2e,0x7a,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x2e, + 0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d, + 0x73,0x2e,0x79,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f, + 0x31,0x31,0x33,0x20,0x3d,0x20,0x5f,0x36,0x33,0x20,0x2b,0x20,0x76,0x65,0x63,0x33, + 0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f, + 0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x78, + 0x79,0x7a,0x2c,0x20,0x5f,0x39,0x34,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31, + 0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x39,0x34, + 0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73, + 0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32, + 0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x39,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f, + 0x78,0x79,0x20,0x3d,0x20,0x5f,0x31,0x31,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3d,0x20,0x5f,0x36,0x33,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68, + 0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30, + 0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69, + 0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73, + 0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x31, + 0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69, + 0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f, + 0x72,0x6f,0x77,0x31,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d, + 0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77, + 0x32,0x2e,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f, + 0x72,0x6f,0x77,0x30,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73, + 0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30, + 0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f, + 0x72,0x6f,0x77,0x31,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73, + 0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31, + 0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f, + 0x72,0x6f,0x77,0x32,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73, + 0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32, + 0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x62,0x61,0x73,0x65, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65, + 0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69, + 0x61,0x6c,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f, + 0x33,0x30,0x5d,0x2e,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x6d,0x61,0x74,0x34,0x28,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x30,0x5d, + 0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x31,0x5d,0x2c,0x20,0x75, + 0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x32,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66, + 0x72,0x61,0x6d,0x65,0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28, + 0x5f,0x31,0x31,0x33,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + +}; +/* + #version 430 + + struct ub_pass + { + vec4 sun_dir_world; + vec4 sun_color; + ivec4 flags; + vec4 camera_pos; + mat4 view_proj; + mat4 view; + vec4 cascade_far_view_z; + mat4 cascade_matrices[3]; + vec4 sh[9]; + vec4 ibl_params; + }; + + uniform ub_pass _707; + + layout(binding = 0) uniform sampler2D tex_ao_smp_ao; + layout(binding = 1) uniform sampler2DArrayShadow tex_shadow_smp_shadow; + layout(binding = 2) uniform samplerCube tex_ibl_spec_smp_ibl_spec; + layout(binding = 3) uniform sampler2D tex_brdf_lut_smp_brdf_lut; + + layout(location = 0) in vec3 v_world_pos_proxy; + layout(location = 4) flat in vec3 v_axis_x_world; + layout(location = 1) flat in vec3 v_center; + layout(location = 2) flat in float v_half_length; + layout(location = 3) flat in float v_radius; + layout(location = 5) flat in vec3 v_rot_row0; + layout(location = 6) flat in vec3 v_rot_row1; + layout(location = 7) flat in vec3 v_rot_row2; + layout(location = 8) flat in vec4 v_base_color; + layout(location = 0) out vec4 out_color; + layout(location = 9) flat in vec4 v_material; + + float sampleShadowPCF(int cascade, vec3 light_uv, float bias) + { + float _529 = float(cascade); + float _534 = light_uv.z - bias; + float _550 = light_uv.x - 0.00048828125; + float _554 = light_uv.y - 0.00048828125; + float _584 = light_uv.x + 0.00048828125; + float _652 = light_uv.y + 0.00048828125; + return ((((((((texture(tex_shadow_smp_shadow, vec4(vec4(_550, _554, _529, _534).xyz, _534)) + texture(tex_shadow_smp_shadow, vec4(vec4(light_uv.x, _554, _529, _534).xyz, _534))) + texture(tex_shadow_smp_shadow, vec4(vec4(_584, _554, _529, _534).xyz, _534))) + texture(tex_shadow_smp_shadow, vec4(vec4(_550, light_uv.y, _529, _534).xyz, _534))) + texture(tex_shadow_smp_shadow, vec4(vec4(light_uv.xy, _529, _534).xyz, _534))) + texture(tex_shadow_smp_shadow, vec4(vec4(_584, light_uv.y, _529, _534).xyz, _534))) + texture(tex_shadow_smp_shadow, vec4(vec4(_550, _652, _529, _534).xyz, _534))) + texture(tex_shadow_smp_shadow, vec4(vec4(light_uv.x, _652, _529, _534).xyz, _534))) + texture(tex_shadow_smp_shadow, vec4(vec4(_584, _652, _529, _534).xyz, _534))) * 0.111111111938953399658203125; + } + + float sampleCascade(int cascade, vec3 world_pos, vec3 world_normal) + { + vec4 _717 = _707.cascade_matrices[cascade] * vec4(world_pos, 1.0); + vec3 _724 = _717.xyz / vec3(_717.w); + vec3 _742 = vec3((_724.x * 0.5) + 0.5, ((_724.y * _707.cascade_far_view_z.w) * 0.5) + 0.5, _724.z); + bool _746 = any(lessThan(_742, vec3(0.0))); + bool _753; + if (!_746) + { + _753 = any(greaterThan(_742, vec3(1.0))); + } + else + { + _753 = _746; + } + if (_753) + { + return 1.0; + } + int param = cascade; + vec3 param_1 = _742; + float param_2 = mix(0.0040000001899898052215576171875, 0.0007999999797903001308441162109375, max(dot(world_normal, normalize(_707.sun_dir_world.xyz)), 0.0)); + float pcf = sampleShadowPCF(param, param_1, param_2); + if (cascade == 2) + { + vec2 _785 = _742.xy; + vec2 _790 = min(_785, vec2(1.0) - _785); + pcf = mix(1.0, pcf, clamp(min(_790.x, _790.y) * 10.0, 0.0, 1.0)); + } + return pcf; + } + + float sampleShadowCascaded(vec3 world_pos, vec3 world_normal, float view_z) + { + int cascade = 2; + if (view_z < _707.cascade_far_view_z.x) + { + cascade = 0; + } + else + { + if (view_z < _707.cascade_far_view_z.y) + { + cascade = 1; + } + } + int param = cascade; + vec3 param_1 = world_pos; + vec3 param_2 = world_normal; + float shadow = sampleCascade(param, param_1, param_2); + if (cascade < 2) + { + float _835; + if (cascade == 0) + { + _835 = _707.cascade_far_view_z.x; + } + else + { + _835 = _707.cascade_far_view_z.y; + } + float _847; + if (cascade == 0) + { + _847 = 0.0; + } + else + { + _847 = _707.cascade_far_view_z.x; + } + float _858 = mix(_835, _847, 0.100000001490116119384765625); + if (view_z > _858) + { + int param_3 = cascade + 1; + vec3 param_4 = world_pos; + vec3 param_5 = world_normal; + shadow = mix(shadow, sampleCascade(param_3, param_4, param_5), (view_z - _858) / (_835 - _858)); + } + } + return shadow; + } + + float pbrDistributionGGX(float n_dot_h, float alpha) + { + float _107 = alpha * alpha; + float _116 = ((n_dot_h * n_dot_h) * (_107 - 1.0)) + 1.0; + return _107 / ((3.1415927410125732421875 * _116) * _116); + } + + float pbrVisibilitySmithCorrelated(float n_dot_v, float n_dot_l, float alpha) + { + float _129 = alpha * alpha; + float _136 = 1.0 - _129; + return 0.5 / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _136) + _129)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _136) + _129))) + 9.9999997473787516355514526367188e-06); + } + + vec3 pbrFresnelSchlick(float v_dot_h, vec3 f0) + { + float _165 = 1.0 - v_dot_h; + float _169 = _165 * _165; + return f0 + ((vec3(1.0) - f0) * ((_169 * _169) * _165)); + } + + vec3 brdf_evaluate(vec3 N, vec3 V, vec3 L, vec3 sun_radiance, vec3 base_color, float metallic, float roughness) + { + float _188 = max(dot(N, L), 0.0); + vec3 _199 = normalize(V + L); + float _213 = max(roughness, 0.04500000178813934326171875); + float _217 = _213 * _213; + float param = max(dot(N, _199), 0.0); + float param_1 = _217; + float param_2 = max(dot(N, V), 9.9999997473787516355514526367188e-05); + float param_3 = _188; + float param_4 = _217; + float param_5 = max(dot(V, _199), 0.0); + vec3 param_6 = mix(vec3(0.039999999105930328369140625), base_color, vec3(metallic)); + vec3 _244 = pbrFresnelSchlick(param_5, param_6); + return ((((((vec3(1.0) - _244) * (1.0 - metallic)) * base_color) * vec3(0.3183098733425140380859375)) + (_244 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _188; + } + + vec3 pbrEvaluateShIrradiance(vec3 N, vec4 sh[9]) + { + vec3 _399 = ((((((((sh[0].xyz * 0.2820948064327239990234375) + (sh[1].xyz * ((-0.48860251903533935546875) * N.y))) + (sh[2].xyz * (0.48860251903533935546875 * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125 * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125 * (((3.0 * N.z) * N.z) - 1.0)))) + (sh[7].xyz * (((-1.09254848957061767578125) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625 * ((N.x * N.x) - (N.y * N.y)))); + return _399; + } + + vec3 pbrEvaluateIbl(vec3 N_world, vec3 V_world, vec3 base_color, float metallic, float roughness, vec4 sh[9], float max_lod, samplerCube SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, sampler2D SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut) + { + float _406 = clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05, 1.0); + vec3 _416 = mix(vec3(0.039999999105930328369140625), base_color, vec3(metallic)); + vec3 param = N_world; + vec4 param_1[9] = sh; + vec4 _482 = texture(SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut, vec2(_406, roughness)); + return (((((vec3(1.0) - (_416 + ((max(vec3(1.0 - roughness), _416) - _416) * pow(max(0.0, 1.0 - _406), 5.0)))) * (1.0 - metallic)) * base_color) * max(pbrEvaluateShIrradiance(param, param_1), vec3(0.0))) * vec3(0.3183098733425140380859375)) + (textureLod(SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, reflect(-V_world, N_world), roughness * max_lod).xyz * ((_416 * _482.x) + vec3(_482.y))); + } + + vec3 pbrEvaluateAmbient(bool iblEnabled, vec3 N_world, vec3 V_world, vec3 base_color, float metallic, float roughness, float flat_strength, vec4 sh[9], float max_lod, samplerCube SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, sampler2D SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut) + { + vec3 result = base_color * flat_strength; + if (iblEnabled) + { + vec3 param = N_world; + vec3 param_1 = V_world; + vec3 param_2 = base_color; + float param_3 = metallic; + float param_4 = roughness; + vec4 param_5[9] = sh; + float param_6 = max_lod; + result = pbrEvaluateIbl(param, param_1, param_2, param_3, param_4, param_5, param_6, SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut); + } + return result; + } + + void main() + { + vec3 _896 = normalize(v_world_pos_proxy - _707.camera_pos.xyz); + vec3 _907 = v_axis_x_world * v_half_length; + vec3 _908 = v_center - _907; + vec3 _914 = v_center + _907; + vec3 _918 = _914 - _908; + vec3 _922 = _707.camera_pos.xyz - _908; + float _926 = dot(_918, _918); + float _930 = dot(_918, _896); + float _934 = dot(_918, _922); + float _942 = dot(_922, _922); + float _948 = _926 - (_930 * _930); + float _956 = (_926 * dot(_896, _922)) - (_934 * _930); + float _968 = v_radius * v_radius; + float _979 = (_956 * _956) - (_948 * (((_926 * _942) - (_934 * _934)) - (_968 * _926))); + vec3 _1000 = _908 + (_918 * clamp((_934 - ((_956 / max(_948, 9.9999999392252902907785028219223e-09)) * _930)) / _926, 0.0, 1.0)); + vec3 _1004 = _707.camera_pos.xyz - _1000; + float _1008 = dot(_1004, _896); + float _1022 = sqrt(max(0.0, dot(_1004, _1004) - (_1008 * _1008))) - v_radius; + float _1025 = fwidth(_1022); + float _1027 = max(_1025, 9.9999999747524270787835121154785e-07); + float _1034 = 1.0 - smoothstep(-_1027, _1027, _1022); + float t = -1.0; + vec3 n_world = vec3(0.0); + if ((_979 >= 0.0) && (_948 > 9.9999999392252902907785028219223e-09)) + { + float _1052 = ((-_956) - sqrt(_979)) / _948; + float _1058 = _934 + (_1052 * _930); + if (((_1052 > 0.0) && (_1058 > 0.0)) && (_1058 < _926)) + { + n_world = ((_707.camera_pos.xyz + (_896 * _1052)) - (_908 + (_918 * (_1058 / _926)))) / vec3(v_radius); + t = _1052; + } + } + float _1098 = dot(_922, _896); + float _1112 = (_1098 * _1098) - (_942 - _968); + if (_1112 >= 0.0) + { + float _1122 = (-_1098) - sqrt(_1112); + bool _1124 = _1122 > 0.0; + bool _1133; + if (_1124) + { + _1133 = (t < 0.0) || (_1122 < t); + } + else + { + _1133 = _1124; + } + if (_1133) + { + vec3 _1144 = (_707.camera_pos.xyz + (_896 * _1122)) - _908; + if (dot(_1144, v_axis_x_world) <= 0.0) + { + n_world = _1144 / vec3(v_radius); + t = _1122; + } + } + } + vec3 _1160 = _707.camera_pos.xyz - _914; + float _1164 = dot(_1160, _896); + float _1178 = (_1164 * _1164) - (dot(_1160, _1160) - _968); + if (_1178 >= 0.0) + { + float _1188 = (-_1164) - sqrt(_1178); + bool _1190 = _1188 > 0.0; + bool _1199; + if (_1190) + { + _1199 = (t < 0.0) || (_1188 < t); + } + else + { + _1199 = _1190; + } + if (_1199) + { + vec3 _1210 = (_707.camera_pos.xyz + (_896 * _1188)) - _914; + if (dot(_1210, v_axis_x_world) >= 0.0) + { + n_world = _1210 / vec3(v_radius); + t = _1188; + } + } + } + if (t < 0.0) + { + float _1228 = -_1008; + t = _1228; + n_world = normalize((_707.camera_pos.xyz + (_896 * _1228)) - _1000); + } + if ((_1034 <= 0.0) || (t < 0.0)) + { + discard; + } + vec3 _1252 = _707.camera_pos.xyz + (_896 * t); + float _1290 = ((v_rot_row0.y * n_world.x) + (v_rot_row1.y * n_world.y)) + (v_rot_row2.y * n_world.z); + float _1307 = ((v_rot_row0.z * n_world.x) + (v_rot_row1.z * n_world.y)) + (v_rot_row2.z * n_world.z); + vec3 _1321 = v_base_color.xyz * ((_1290 > 0.0) ? 1.0 : 0.64999997615814208984375); + float _1325 = fwidth(_1290); + float _1336 = fwidth(_1307); + vec3 _1356 = mix(_1321, _1321 * 0.3499999940395355224609375, vec3(max(1.0 - smoothstep(0.0, _1325 * 1.5, abs(_1290)), 1.0 - smoothstep(0.0, _1336 * 1.5, abs(_1307))))); + vec4 _1364 = vec4(_1252, 1.0); + vec4 _1365 = _707.view_proj * _1364; + gl_FragDepth = _1365.z / _1365.w; + if (_707.flags.x == 1) + { + float _1397 = clamp((_707.view * _1364).z * (-0.0199999995529651641845703125), 0.0, 1.0); + out_color = vec4(_1397, _1397, _1397, 1.0); + return; + } + if (_707.flags.x == 2) + { + float _1418 = -(_707.view * _1364).z; + int cascade = 2; + if (_1418 < _707.cascade_far_view_z.x) + { + cascade = 0; + } + else + { + if (_1418 < _707.cascade_far_view_z.y) + { + cascade = 1; + } + } + vec4 _1442 = _707.cascade_matrices[cascade] * _1364; + vec3 _1449 = _1442.xyz / vec3(_1442.w); + vec3 _1466 = vec3((_1449.x * 0.5) + 0.5, ((_1449.y * _707.cascade_far_view_z.w) * 0.5) + 0.5, _1449.z); + bool _1470 = any(lessThan(_1466, vec3(0.0))); + bool _1477; + if (!_1470) + { + _1477 = any(greaterThan(_1466, vec3(1.0))); + } + else + { + _1477 = _1470; + } + vec3 tint = vec3(1.0); + if (!_1477) + { + if (cascade == 0) + { + tint = vec3(1.0, 0.4000000059604644775390625, 0.4000000059604644775390625); + } + else + { + if (cascade == 1) + { + tint = vec3(0.4000000059604644775390625, 1.0, 0.4000000059604644775390625); + } + else + { + tint = vec3(0.4000000059604644775390625, 0.4000000059604644775390625, 1.0); + } + } + } + out_color = vec4(tint, 1.0); + return; + } + if (_707.flags.x == 3) + { + out_color = vec4((normalize((_707.view * vec4(n_world, 0.0)).xyz) * 0.5) + vec3(0.5), 1.0); + return; + } + vec4 _1547 = textureLod(tex_ao_smp_ao, gl_FragCoord.xy / vec2(textureSize(tex_ao_smp_ao, 0)), 0.0); + float _1548 = _1547.x; + if (_707.flags.x == 4) + { + out_color = vec4(_1548, _1548, _1548, 1.0); + return; + } + vec3 param = _1252; + vec3 param_1 = n_world; + float param_2 = -(_707.view * _1364).z; + vec3 _1596 = normalize(_707.camera_pos.xyz - _1252); + vec3 param_3 = n_world; + vec3 param_4 = _1596; + vec3 param_5 = normalize(_707.sun_dir_world.xyz); + vec3 param_6 = _707.sun_color.xyz * sampleShadowCascaded(param, param_1, param_2); + vec3 param_7 = _1356; + float param_8 = v_material.x; + float param_9 = v_material.y; + bool param_10 = _707.ibl_params.y > 0.5; + vec3 param_11 = n_world; + vec3 param_12 = _1596; + vec3 param_13 = _1356; + float param_14 = v_material.x; + float param_15 = v_material.y; + float param_16 = _707.sun_color.w; + vec4 param_17[9]; + param_17[0] = _707.sh[0]; + param_17[1] = _707.sh[1]; + param_17[2] = _707.sh[2]; + param_17[3] = _707.sh[3]; + param_17[4] = _707.sh[4]; + param_17[5] = _707.sh[5]; + param_17[6] = _707.sh[6]; + param_17[7] = _707.sh[7]; + param_17[8] = _707.sh[8]; + float param_18 = _707.ibl_params.x; + float _1675 = v_base_color.w * _1034; + out_color = vec4((brdf_evaluate(param_3, param_4, param_5, param_6, param_7, param_8, param_9) + (pbrEvaluateAmbient(param_10, param_11, param_12, param_13, param_14, param_15, param_16, param_17, param_18, tex_ibl_spec_smp_ibl_spec, tex_brdf_lut_smp_brdf_lut) * _1548)) * _1675, _1675); + } + +*/ +static const uint8_t capsule_fs_source_glsl430[15511] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20, + 0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x76,0x65,0x63,0x34,0x20,0x66,0x6c,0x61,0x67,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x65,0x63,0x34,0x20,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x74,0x34,0x20,0x76,0x69,0x65,0x77,0x5f,0x70, + 0x72,0x6f,0x6a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x74,0x34,0x20,0x76,0x69, + 0x65,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x74,0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x33,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61, + 0x6d,0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20, + 0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x20,0x5f,0x37,0x30,0x37,0x3b,0x0a,0x0a,0x6c, + 0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20, + 0x30,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x5f,0x73,0x6d,0x70,0x5f, + 0x61,0x6f,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69, + 0x6e,0x67,0x20,0x3d,0x20,0x31,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x41,0x72,0x72,0x61,0x79,0x53,0x68, + 0x61,0x64,0x6f,0x77,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f, + 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x6c,0x61,0x79,0x6f, + 0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x32,0x29,0x20, + 0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43, + 0x75,0x62,0x65,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63, + 0x5f,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x3b,0x0a,0x6c, + 0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20, + 0x33,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75, + 0x74,0x5f,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x3b,0x0a, + 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b, + 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x34,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65, + 0x63,0x33,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69, + 0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20, + 0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x6c, + 0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d, + 0x20,0x32,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x3b, + 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x33,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x35,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20, + 0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x6c,0x61,0x79,0x6f, + 0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x36,0x29, + 0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f, + 0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, + 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x37,0x29,0x20,0x66, + 0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x72,0x6f, + 0x74,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, + 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x38,0x29,0x20,0x66,0x6c,0x61, + 0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, + 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74, + 0x20,0x76,0x65,0x63,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b, + 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x39,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65, + 0x63,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x0a, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64, + 0x6f,0x77,0x50,0x43,0x46,0x28,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x62,0x69,0x61,0x73,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x32,0x39,0x20,0x3d, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x33,0x34,0x20, + 0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x7a,0x20,0x2d,0x20,0x62, + 0x69,0x61,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x35,0x35,0x30,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78, + 0x20,0x2d,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x35,0x34, + 0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x20,0x2d,0x20, + 0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x38,0x34,0x20,0x3d,0x20, + 0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20,0x2b,0x20,0x30,0x2e,0x30, + 0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x35,0x32,0x20,0x3d,0x20,0x6c,0x69,0x67, + 0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34, + 0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x74,0x65,0x78,0x74, + 0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73, + 0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28, + 0x76,0x65,0x63,0x34,0x28,0x5f,0x35,0x35,0x30,0x2c,0x20,0x5f,0x35,0x35,0x34,0x2c, + 0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a, + 0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75, + 0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d, + 0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76, + 0x65,0x63,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20, + 0x5f,0x35,0x35,0x34,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34, + 0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x29,0x20,0x2b, + 0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20, + 0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x5f,0x35,0x38,0x34,0x2c,0x20, + 0x5f,0x35,0x35,0x34,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34, + 0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x29,0x20,0x2b, + 0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20, + 0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x5f,0x35,0x35,0x30,0x2c,0x20, + 0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x5f,0x35,0x32,0x39, + 0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33, + 0x34,0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74, + 0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68, + 0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28, + 0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x79,0x2c,0x20,0x5f,0x35,0x32, + 0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35, + 0x33,0x34,0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28, + 0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34, + 0x28,0x5f,0x35,0x38,0x34,0x2c,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e, + 0x79,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78, + 0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65, + 0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63, + 0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x5f,0x35,0x35,0x30,0x2c,0x20,0x5f,0x36,0x35, + 0x32,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78, + 0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65, + 0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63, + 0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e, + 0x78,0x2c,0x20,0x5f,0x36,0x35,0x32,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f, + 0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29, + 0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x5f,0x35,0x38, + 0x34,0x2c,0x20,0x5f,0x36,0x35,0x32,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f, + 0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29, + 0x29,0x20,0x2a,0x20,0x30,0x2e,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x39, + 0x33,0x38,0x39,0x35,0x33,0x33,0x39,0x39,0x36,0x35,0x38,0x32,0x30,0x33,0x31,0x32, + 0x35,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x69,0x6e,0x74,0x20,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x65,0x63,0x34,0x20,0x5f,0x37,0x31,0x37,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37, + 0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65, + 0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x20,0x2a,0x20,0x76,0x65,0x63, + 0x34,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x37,0x32,0x34, + 0x20,0x3d,0x20,0x5f,0x37,0x31,0x37,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x76,0x65, + 0x63,0x33,0x28,0x5f,0x37,0x31,0x37,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x65,0x63,0x33,0x20,0x5f,0x37,0x34,0x32,0x20,0x3d,0x20,0x76,0x65,0x63,0x33, + 0x28,0x28,0x5f,0x37,0x32,0x34,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20, + 0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x28,0x28,0x5f,0x37,0x32,0x34,0x2e,0x79,0x20, + 0x2a,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66, + 0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30, + 0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x37,0x32,0x34,0x2e, + 0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x37,0x34, + 0x36,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x6c,0x65,0x73,0x73,0x54,0x68,0x61,0x6e, + 0x28,0x5f,0x37,0x34,0x32,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x29, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x37,0x35, + 0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x37,0x34,0x36, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x5f,0x37,0x35,0x33,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x67,0x72,0x65,0x61,0x74, + 0x65,0x72,0x54,0x68,0x61,0x6e,0x28,0x5f,0x37,0x34,0x32,0x2c,0x20,0x76,0x65,0x63, + 0x33,0x28,0x31,0x2e,0x30,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x37,0x35,0x33,0x20,0x3d,0x20,0x5f,0x37, + 0x34,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x5f,0x37,0x35,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e,0x30, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6d,0x69, + 0x78,0x28,0x30,0x2e,0x30,0x30,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x38,0x39, + 0x39,0x38,0x39,0x38,0x30,0x35,0x32,0x32,0x31,0x35,0x35,0x37,0x36,0x31,0x37,0x31, + 0x38,0x37,0x35,0x2c,0x20,0x30,0x2e,0x30,0x30,0x30,0x37,0x39,0x39,0x39,0x39,0x39, + 0x39,0x37,0x39,0x37,0x39,0x30,0x33,0x30,0x30,0x31,0x33,0x30,0x38,0x34,0x34,0x31, + 0x31,0x36,0x32,0x31,0x30,0x39,0x33,0x37,0x35,0x2c,0x20,0x6d,0x61,0x78,0x28,0x64, + 0x6f,0x74,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c, + 0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37,0x30,0x37,0x2e, + 0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79, + 0x7a,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f, + 0x37,0x38,0x35,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x2e,0x78,0x79,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x37,0x39,0x30, + 0x20,0x3d,0x20,0x6d,0x69,0x6e,0x28,0x5f,0x37,0x38,0x35,0x2c,0x20,0x76,0x65,0x63, + 0x32,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x37,0x38,0x35,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x6d,0x69, + 0x78,0x28,0x31,0x2e,0x30,0x2c,0x20,0x70,0x63,0x66,0x2c,0x20,0x63,0x6c,0x61,0x6d, + 0x70,0x28,0x6d,0x69,0x6e,0x28,0x5f,0x37,0x39,0x30,0x2e,0x78,0x2c,0x20,0x5f,0x37, + 0x39,0x30,0x2e,0x79,0x29,0x20,0x2a,0x20,0x31,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e, + 0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x70,0x63,0x66,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53, + 0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x76,0x65, + 0x63,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x76,0x65, + 0x63,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x69,0x65,0x77,0x5f,0x7a,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20, + 0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d, + 0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x77, + 0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61, + 0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3c,0x20,0x32,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x38,0x33,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x33,0x35,0x20,0x3d,0x20,0x5f,0x37, + 0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x33,0x35,0x20,0x3d,0x20,0x5f,0x37,0x30, + 0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x38,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x34,0x37,0x20,0x3d,0x20,0x30,0x2e,0x30, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f, + 0x38,0x34,0x37,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x35,0x38,0x20,0x3d,0x20, + 0x6d,0x69,0x78,0x28,0x5f,0x38,0x33,0x35,0x2c,0x20,0x5f,0x38,0x34,0x37,0x2c,0x20, + 0x30,0x2e,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x34,0x39,0x30,0x31,0x31, + 0x36,0x31,0x31,0x39,0x33,0x38,0x34,0x37,0x36,0x35,0x36,0x32,0x35,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77, + 0x5f,0x7a,0x20,0x3e,0x20,0x5f,0x38,0x35,0x38,0x29,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x2b,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x77,0x6f,0x72, + 0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20, + 0x6d,0x69,0x78,0x28,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x35,0x29,0x2c,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x2d,0x20, + 0x5f,0x38,0x35,0x38,0x29,0x20,0x2f,0x20,0x28,0x5f,0x38,0x33,0x35,0x20,0x2d,0x20, + 0x5f,0x38,0x35,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74, + 0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64, + 0x6f,0x74,0x5f,0x68,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70,0x68, + 0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x30,0x37,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c, + 0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x31,0x36,0x20,0x3d,0x20,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x20, + 0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x29,0x20,0x2a,0x20,0x28,0x5f,0x31, + 0x30,0x37,0x20,0x2d,0x20,0x31,0x2e,0x30,0x29,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x30, + 0x37,0x20,0x2f,0x20,0x28,0x28,0x33,0x2e,0x31,0x34,0x31,0x35,0x39,0x32,0x37,0x34, + 0x31,0x30,0x31,0x32,0x35,0x37,0x33,0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x20,0x2a, + 0x20,0x5f,0x31,0x31,0x36,0x29,0x20,0x2a,0x20,0x5f,0x31,0x31,0x36,0x29,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69, + 0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65, + 0x6c,0x61,0x74,0x65,0x64,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f, + 0x74,0x5f,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74, + 0x5f,0x6c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70,0x68,0x61,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32, + 0x39,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68, + 0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33, + 0x36,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f,0x31,0x32,0x39,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x30,0x2e,0x35,0x20,0x2f, + 0x20,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x73,0x71, + 0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x6e, + 0x5f,0x64,0x6f,0x74,0x5f,0x76,0x29,0x20,0x2a,0x20,0x5f,0x31,0x33,0x36,0x29,0x20, + 0x2b,0x20,0x5f,0x31,0x32,0x39,0x29,0x29,0x20,0x2b,0x20,0x28,0x6e,0x5f,0x64,0x6f, + 0x74,0x5f,0x76,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64, + 0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x29,0x20, + 0x2a,0x20,0x5f,0x31,0x33,0x36,0x29,0x20,0x2b,0x20,0x5f,0x31,0x32,0x39,0x29,0x29, + 0x29,0x20,0x2b,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33, + 0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33, + 0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76, + 0x65,0x63,0x33,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63, + 0x68,0x6c,0x69,0x63,0x6b,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x64,0x6f, + 0x74,0x5f,0x68,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x66,0x30,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x35,0x20,0x3d, + 0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x39,0x20,0x3d, + 0x20,0x5f,0x31,0x36,0x35,0x20,0x2a,0x20,0x5f,0x31,0x36,0x35,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x30,0x20,0x2b,0x20,0x28,0x28, + 0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x66,0x30,0x29,0x20, + 0x2a,0x20,0x28,0x28,0x5f,0x31,0x36,0x39,0x20,0x2a,0x20,0x5f,0x31,0x36,0x39,0x29, + 0x20,0x2a,0x20,0x5f,0x31,0x36,0x35,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65, + 0x63,0x33,0x20,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65, + 0x28,0x76,0x65,0x63,0x33,0x20,0x4e,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x56,0x2c, + 0x20,0x76,0x65,0x63,0x33,0x20,0x4c,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x73,0x75, + 0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x2c,0x20,0x76,0x65,0x63,0x33, + 0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x38,0x38,0x20,0x3d, + 0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x4c,0x29,0x2c,0x20, + 0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f, + 0x31,0x39,0x39,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28, + 0x56,0x20,0x2b,0x20,0x4c,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x32,0x31,0x33,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x72,0x6f,0x75, + 0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x30,0x2e,0x30,0x34,0x35,0x30,0x30,0x30, + 0x30,0x30,0x31,0x37,0x38,0x38,0x31,0x33,0x39,0x33,0x34,0x33,0x32,0x36,0x31,0x37, + 0x31,0x38,0x37,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x32,0x31,0x37,0x20,0x3d,0x20,0x5f,0x32,0x31,0x33,0x20,0x2a,0x20,0x5f, + 0x32,0x31,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e, + 0x2c,0x20,0x5f,0x31,0x39,0x39,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x20,0x3d,0x20,0x5f,0x32,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6d,0x61,0x78, + 0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x56,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39, + 0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35, + 0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30, + 0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31,0x38,0x38,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20, + 0x3d,0x20,0x5f,0x32,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28, + 0x64,0x6f,0x74,0x28,0x56,0x2c,0x20,0x5f,0x31,0x39,0x39,0x29,0x2c,0x20,0x30,0x2e, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x76,0x65,0x63,0x33,0x28, + 0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33, + 0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c,0x20, + 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x76,0x65,0x63,0x33, + 0x28,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x32,0x34,0x34,0x20,0x3d,0x20,0x70,0x62,0x72, + 0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28, + 0x28,0x28,0x28,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f, + 0x32,0x34,0x34,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65, + 0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e, + 0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30, + 0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x5f, + 0x32,0x34,0x34,0x20,0x2a,0x20,0x28,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69, + 0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x20,0x2a,0x20,0x70,0x62,0x72,0x56, + 0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f, + 0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x34,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64, + 0x69,0x61,0x6e,0x63,0x65,0x29,0x20,0x2a,0x20,0x5f,0x31,0x38,0x38,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61, + 0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x76, + 0x65,0x63,0x33,0x20,0x4e,0x2c,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39, + 0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x33, + 0x39,0x39,0x20,0x3d,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x73,0x68,0x5b, + 0x30,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x30,0x2e,0x32,0x38,0x32,0x30,0x39, + 0x34,0x38,0x30,0x36,0x34,0x33,0x32,0x37,0x32,0x33,0x39,0x39,0x39,0x30,0x32,0x33, + 0x34,0x33,0x37,0x35,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x31,0x5d,0x2e,0x78, + 0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32, + 0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37, + 0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73, + 0x68,0x5b,0x32,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x34,0x38, + 0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35, + 0x34,0x36,0x38,0x37,0x35,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b, + 0x20,0x28,0x73,0x68,0x5b,0x33,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28, + 0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33, + 0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e, + 0x78,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x34,0x5d,0x2e,0x78,0x79, + 0x7a,0x20,0x2a,0x20,0x28,0x28,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38, + 0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x20, + 0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20, + 0x2b,0x20,0x28,0x73,0x68,0x5b,0x35,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28, + 0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37, + 0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20, + 0x4e,0x2e,0x79,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20, + 0x28,0x73,0x68,0x5b,0x36,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e, + 0x33,0x31,0x35,0x33,0x39,0x31,0x35,0x37,0x30,0x33,0x32,0x39,0x36,0x36,0x36,0x31, + 0x33,0x37,0x36,0x39,0x35,0x33,0x31,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x28,0x33, + 0x2e,0x30,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29, + 0x20,0x2d,0x20,0x31,0x2e,0x30,0x29,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68, + 0x5b,0x37,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e, + 0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36, + 0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20, + 0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x38, + 0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x35,0x34,0x36,0x32,0x37, + 0x34,0x32,0x34,0x34,0x37,0x38,0x35,0x33,0x30,0x38,0x38,0x33,0x37,0x38,0x39,0x30, + 0x36,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x4e,0x2e,0x78,0x20,0x2a,0x20,0x4e,0x2e, + 0x78,0x29,0x20,0x2d,0x20,0x28,0x4e,0x2e,0x79,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29, + 0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x5f,0x33,0x39,0x39,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x70,0x62, + 0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x76,0x65,0x63, + 0x33,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20, + 0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x62,0x61, + 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x76,0x65,0x63,0x34,0x20, + 0x73,0x68,0x5b,0x39,0x5d,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61,0x78, + 0x5f,0x6c,0x6f,0x64,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x75,0x62, + 0x65,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f, + 0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63, + 0x75,0x62,0x65,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65, + 0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x53,0x50,0x49,0x52, + 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64, + 0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f, + 0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x30,0x36,0x20,0x3d,0x20,0x63,0x6c,0x61, + 0x6d,0x70,0x28,0x64,0x6f,0x74,0x28,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20, + 0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39, + 0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35, + 0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x2c, + 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, + 0x5f,0x34,0x31,0x36,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x76,0x65,0x63,0x33,0x28, + 0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33, + 0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c,0x20, + 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x76,0x65,0x63,0x33, + 0x28,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x5b,0x39,0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x34,0x38,0x32,0x20,0x3d, + 0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, + 0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78, + 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64, + 0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x76,0x65,0x63,0x32,0x28,0x5f,0x34,0x30,0x36, + 0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x76, + 0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x28,0x5f,0x34,0x31,0x36, + 0x20,0x2b,0x20,0x28,0x28,0x6d,0x61,0x78,0x28,0x76,0x65,0x63,0x33,0x28,0x31,0x2e, + 0x30,0x20,0x2d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x2c,0x20, + 0x5f,0x34,0x31,0x36,0x29,0x20,0x2d,0x20,0x5f,0x34,0x31,0x36,0x29,0x20,0x2a,0x20, + 0x70,0x6f,0x77,0x28,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30, + 0x20,0x2d,0x20,0x5f,0x34,0x30,0x36,0x29,0x2c,0x20,0x35,0x2e,0x30,0x29,0x29,0x29, + 0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c, + 0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x29,0x20,0x2a,0x20,0x6d,0x61,0x78,0x28,0x70,0x62,0x72,0x45,0x76,0x61, + 0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63, + 0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x29,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x29,0x20,0x2a, + 0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37, + 0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37, + 0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x4c,0x6f, + 0x64,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f, + 0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63, + 0x75,0x62,0x65,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65, + 0x2c,0x20,0x72,0x65,0x66,0x6c,0x65,0x63,0x74,0x28,0x2d,0x56,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x2c,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x72,0x6f, + 0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x20,0x2a,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f, + 0x64,0x29,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x34,0x31,0x36,0x20, + 0x2a,0x20,0x5f,0x34,0x38,0x32,0x2e,0x78,0x29,0x20,0x2b,0x20,0x76,0x65,0x63,0x33, + 0x28,0x5f,0x34,0x38,0x32,0x2e,0x79,0x29,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76, + 0x65,0x63,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41, + 0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x62,0x6f,0x6f,0x6c,0x20,0x69,0x62,0x6c,0x45, + 0x6e,0x61,0x62,0x6c,0x65,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x4e,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x56,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c, + 0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68, + 0x6e,0x65,0x73,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x66,0x6c,0x61,0x74, + 0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x2c,0x20,0x76,0x65,0x63,0x34,0x20, + 0x73,0x68,0x5b,0x39,0x5d,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61,0x78, + 0x5f,0x6c,0x6f,0x64,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x75,0x62, + 0x65,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f, + 0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63, + 0x75,0x62,0x65,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65, + 0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x53,0x50,0x49,0x52, + 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64, + 0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f, + 0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x65,0x63,0x33,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x62,0x61, + 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x66,0x6c,0x61,0x74,0x5f, + 0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x6d,0x65,0x74, + 0x61,0x6c,0x6c,0x69,0x63,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x72, + 0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x5b,0x39, + 0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20, + 0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x70,0x62,0x72,0x45,0x76,0x61, + 0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x36,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73, + 0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70, + 0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f, + 0x63,0x75,0x62,0x65,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73, + 0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x62,0x72, + 0x64,0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, + 0x75,0x74,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x38,0x39,0x36,0x20,0x3d,0x20,0x6e, + 0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x5f,0x37,0x30, + 0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x39,0x30,0x37, + 0x20,0x3d,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x20,0x2a,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74, + 0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x39,0x30,0x38, + 0x20,0x3d,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x2d,0x20,0x5f,0x39, + 0x30,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x39,0x31, + 0x34,0x20,0x3d,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x2b,0x20,0x5f, + 0x39,0x30,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x39, + 0x31,0x38,0x20,0x3d,0x20,0x5f,0x39,0x31,0x34,0x20,0x2d,0x20,0x5f,0x39,0x30,0x38, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x39,0x32,0x32,0x20, + 0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f, + 0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x39,0x30,0x38,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x32,0x36,0x20,0x3d,0x20,0x64, + 0x6f,0x74,0x28,0x5f,0x39,0x31,0x38,0x2c,0x20,0x5f,0x39,0x31,0x38,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x33,0x30,0x20,0x3d, + 0x20,0x64,0x6f,0x74,0x28,0x5f,0x39,0x31,0x38,0x2c,0x20,0x5f,0x38,0x39,0x36,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x33,0x34, + 0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x39,0x31,0x38,0x2c,0x20,0x5f,0x39,0x32, + 0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39, + 0x34,0x32,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x39,0x32,0x32,0x2c,0x20,0x5f, + 0x39,0x32,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x39,0x34,0x38,0x20,0x3d,0x20,0x5f,0x39,0x32,0x36,0x20,0x2d,0x20,0x28,0x5f, + 0x39,0x33,0x30,0x20,0x2a,0x20,0x5f,0x39,0x33,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x35,0x36,0x20,0x3d,0x20,0x28,0x5f, + 0x39,0x32,0x36,0x20,0x2a,0x20,0x64,0x6f,0x74,0x28,0x5f,0x38,0x39,0x36,0x2c,0x20, + 0x5f,0x39,0x32,0x32,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f,0x39,0x33,0x34,0x20,0x2a, + 0x20,0x5f,0x39,0x33,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x39,0x36,0x38,0x20,0x3d,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75, + 0x73,0x20,0x2a,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x37,0x39,0x20,0x3d,0x20,0x28, + 0x5f,0x39,0x35,0x36,0x20,0x2a,0x20,0x5f,0x39,0x35,0x36,0x29,0x20,0x2d,0x20,0x28, + 0x5f,0x39,0x34,0x38,0x20,0x2a,0x20,0x28,0x28,0x28,0x5f,0x39,0x32,0x36,0x20,0x2a, + 0x20,0x5f,0x39,0x34,0x32,0x29,0x20,0x2d,0x20,0x28,0x5f,0x39,0x33,0x34,0x20,0x2a, + 0x20,0x5f,0x39,0x33,0x34,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f,0x39,0x36,0x38,0x20, + 0x2a,0x20,0x5f,0x39,0x32,0x36,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x33,0x20,0x5f,0x31,0x30,0x30,0x30,0x20,0x3d,0x20,0x5f,0x39,0x30,0x38, + 0x20,0x2b,0x20,0x28,0x5f,0x39,0x31,0x38,0x20,0x2a,0x20,0x63,0x6c,0x61,0x6d,0x70, + 0x28,0x28,0x5f,0x39,0x33,0x34,0x20,0x2d,0x20,0x28,0x28,0x5f,0x39,0x35,0x36,0x20, + 0x2f,0x20,0x6d,0x61,0x78,0x28,0x5f,0x39,0x34,0x38,0x2c,0x20,0x39,0x2e,0x39,0x39, + 0x39,0x39,0x39,0x39,0x39,0x33,0x39,0x32,0x32,0x35,0x32,0x39,0x30,0x32,0x39,0x30, + 0x37,0x37,0x38,0x35,0x30,0x32,0x38,0x32,0x31,0x39,0x32,0x32,0x33,0x65,0x2d,0x30, + 0x39,0x29,0x29,0x20,0x2a,0x20,0x5f,0x39,0x33,0x30,0x29,0x29,0x20,0x2f,0x20,0x5f, + 0x39,0x32,0x36,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x30,0x30,0x34,0x20, + 0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f, + 0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x31,0x30,0x30,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x30,0x38,0x20,0x3d, + 0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x30,0x30,0x34,0x2c,0x20,0x5f,0x38,0x39,0x36, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30, + 0x32,0x32,0x20,0x3d,0x20,0x73,0x71,0x72,0x74,0x28,0x6d,0x61,0x78,0x28,0x30,0x2e, + 0x30,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x30,0x30,0x34,0x2c,0x20,0x5f,0x31, + 0x30,0x30,0x34,0x29,0x20,0x2d,0x20,0x28,0x5f,0x31,0x30,0x30,0x38,0x20,0x2a,0x20, + 0x5f,0x31,0x30,0x30,0x38,0x29,0x29,0x29,0x20,0x2d,0x20,0x76,0x5f,0x72,0x61,0x64, + 0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x30,0x32,0x35,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31, + 0x30,0x32,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x30,0x32,0x37,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x5f,0x31,0x30,0x32, + 0x35,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x35, + 0x32,0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38,0x33,0x35,0x31,0x32,0x31,0x31,0x35, + 0x34,0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x33,0x34,0x20,0x3d,0x20,0x31,0x2e,0x30, + 0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x2d,0x5f, + 0x31,0x30,0x32,0x37,0x2c,0x20,0x5f,0x31,0x30,0x32,0x37,0x2c,0x20,0x5f,0x31,0x30, + 0x32,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x74, + 0x20,0x3d,0x20,0x2d,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x33,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x76,0x65,0x63,0x33, + 0x28,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28, + 0x5f,0x39,0x37,0x39,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x20,0x26,0x26,0x20, + 0x28,0x5f,0x39,0x34,0x38,0x20,0x3e,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39, + 0x39,0x33,0x39,0x32,0x32,0x35,0x32,0x39,0x30,0x32,0x39,0x30,0x37,0x37,0x38,0x35, + 0x30,0x32,0x38,0x32,0x31,0x39,0x32,0x32,0x33,0x65,0x2d,0x30,0x39,0x29,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x32,0x20,0x3d,0x20,0x28,0x28,0x2d,0x5f, + 0x39,0x35,0x36,0x29,0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x39,0x37,0x39, + 0x29,0x29,0x20,0x2f,0x20,0x5f,0x39,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x38,0x20,0x3d, + 0x20,0x5f,0x39,0x33,0x34,0x20,0x2b,0x20,0x28,0x5f,0x31,0x30,0x35,0x32,0x20,0x2a, + 0x20,0x5f,0x39,0x33,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x28,0x28,0x5f,0x31,0x30,0x35,0x32,0x20,0x3e,0x20,0x30,0x2e, + 0x30,0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x31,0x30,0x35,0x38,0x20,0x3e,0x20,0x30, + 0x2e,0x30,0x29,0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x31,0x30,0x35,0x38,0x20,0x3c, + 0x20,0x5f,0x39,0x32,0x36,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x28,0x28,0x5f,0x37,0x30,0x37,0x2e,0x63, + 0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20, + 0x28,0x5f,0x38,0x39,0x36,0x20,0x2a,0x20,0x5f,0x31,0x30,0x35,0x32,0x29,0x29,0x20, + 0x2d,0x20,0x28,0x5f,0x39,0x30,0x38,0x20,0x2b,0x20,0x28,0x5f,0x39,0x31,0x38,0x20, + 0x2a,0x20,0x28,0x5f,0x31,0x30,0x35,0x38,0x20,0x2f,0x20,0x5f,0x39,0x32,0x36,0x29, + 0x29,0x29,0x29,0x20,0x2f,0x20,0x76,0x65,0x63,0x33,0x28,0x76,0x5f,0x72,0x61,0x64, + 0x69,0x75,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x74,0x20,0x3d,0x20,0x5f,0x31,0x30,0x35,0x32,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x39,0x38,0x20,0x3d,0x20,0x64, + 0x6f,0x74,0x28,0x5f,0x39,0x32,0x32,0x2c,0x20,0x5f,0x38,0x39,0x36,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x31,0x32,0x20, + 0x3d,0x20,0x28,0x5f,0x31,0x30,0x39,0x38,0x20,0x2a,0x20,0x5f,0x31,0x30,0x39,0x38, + 0x29,0x20,0x2d,0x20,0x28,0x5f,0x39,0x34,0x32,0x20,0x2d,0x20,0x5f,0x39,0x36,0x38, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x31,0x32, + 0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31, + 0x32,0x32,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x31,0x30,0x39,0x38,0x29,0x20,0x2d,0x20, + 0x73,0x71,0x72,0x74,0x28,0x5f,0x31,0x31,0x31,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x32,0x34,0x20, + 0x3d,0x20,0x5f,0x31,0x31,0x32,0x32,0x20,0x3e,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x33, + 0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, + 0x31,0x31,0x32,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x33, + 0x33,0x20,0x3d,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x20,0x7c,0x7c, + 0x20,0x28,0x5f,0x31,0x31,0x32,0x32,0x20,0x3c,0x20,0x74,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x33,0x33, + 0x20,0x3d,0x20,0x5f,0x31,0x31,0x32,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x5f,0x31,0x31,0x33,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x33,0x20,0x5f,0x31,0x31,0x34,0x34,0x20,0x3d,0x20,0x28,0x5f,0x37,0x30,0x37,0x2e, + 0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b, + 0x20,0x28,0x5f,0x38,0x39,0x36,0x20,0x2a,0x20,0x5f,0x31,0x31,0x32,0x32,0x29,0x29, + 0x20,0x2d,0x20,0x5f,0x39,0x30,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x31, + 0x34,0x34,0x2c,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x29,0x20,0x3c,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x20,0x3d,0x20,0x5f,0x31,0x31,0x34,0x34,0x20,0x2f,0x20,0x76,0x65,0x63,0x33, + 0x28,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20, + 0x5f,0x31,0x31,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31, + 0x31,0x36,0x30,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x6d,0x65,0x72, + 0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x39,0x31,0x34, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x36, + 0x34,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x31,0x36,0x30,0x2c,0x20,0x5f, + 0x38,0x39,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x31,0x37,0x38,0x20,0x3d,0x20,0x28,0x5f,0x31,0x31,0x36,0x34,0x20,0x2a, + 0x20,0x5f,0x31,0x31,0x36,0x34,0x29,0x20,0x2d,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f, + 0x31,0x31,0x36,0x30,0x2c,0x20,0x5f,0x31,0x31,0x36,0x30,0x29,0x20,0x2d,0x20,0x5f, + 0x39,0x36,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31, + 0x31,0x37,0x38,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x31,0x38,0x38,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x31,0x31,0x36,0x34,0x29, + 0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x31,0x31,0x37,0x38,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31, + 0x39,0x30,0x20,0x3d,0x20,0x5f,0x31,0x31,0x38,0x38,0x20,0x3e,0x20,0x30,0x2e,0x30, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f, + 0x31,0x31,0x39,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x5f,0x31,0x31,0x39,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f, + 0x31,0x31,0x39,0x39,0x20,0x3d,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29, + 0x20,0x7c,0x7c,0x20,0x28,0x5f,0x31,0x31,0x38,0x38,0x20,0x3c,0x20,0x74,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31, + 0x31,0x39,0x39,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x30,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x5f,0x31,0x31,0x39,0x39,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x32,0x31,0x30,0x20,0x3d,0x20,0x28,0x5f,0x37, + 0x30,0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79, + 0x7a,0x20,0x2b,0x20,0x28,0x5f,0x38,0x39,0x36,0x20,0x2a,0x20,0x5f,0x31,0x31,0x38, + 0x38,0x29,0x29,0x20,0x2d,0x20,0x5f,0x39,0x31,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x64,0x6f,0x74,0x28, + 0x5f,0x31,0x32,0x31,0x30,0x2c,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x29,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x5f,0x31,0x32,0x31,0x30,0x20,0x2f,0x20,0x76, + 0x65,0x63,0x33,0x28,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74, + 0x20,0x3d,0x20,0x5f,0x31,0x31,0x38,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32, + 0x32,0x38,0x20,0x3d,0x20,0x2d,0x5f,0x31,0x30,0x30,0x38,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20,0x5f,0x31,0x32,0x32,0x38,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20, + 0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x28,0x5f,0x37,0x30, + 0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a, + 0x20,0x2b,0x20,0x28,0x5f,0x38,0x39,0x36,0x20,0x2a,0x20,0x5f,0x31,0x32,0x32,0x38, + 0x29,0x29,0x20,0x2d,0x20,0x5f,0x31,0x30,0x30,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x5f,0x31,0x30,0x33, + 0x34,0x20,0x3c,0x3d,0x20,0x30,0x2e,0x30,0x29,0x20,0x7c,0x7c,0x20,0x28,0x74,0x20, + 0x3c,0x20,0x30,0x2e,0x30,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31, + 0x32,0x35,0x32,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x6d,0x65,0x72, + 0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x38,0x39, + 0x36,0x20,0x2a,0x20,0x74,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x31,0x32,0x39,0x30,0x20,0x3d,0x20,0x28,0x28,0x76,0x5f,0x72,0x6f, + 0x74,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x79,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x2e,0x78,0x29,0x20,0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72, + 0x6f,0x77,0x31,0x2e,0x79,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e, + 0x79,0x29,0x29,0x20,0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77, + 0x32,0x2e,0x79,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x7a,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x30, + 0x37,0x20,0x3d,0x20,0x28,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30, + 0x2e,0x7a,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x29,0x20, + 0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x7a,0x20, + 0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x79,0x29,0x29,0x20,0x2b,0x20, + 0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x7a,0x20,0x2a,0x20, + 0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x33,0x32,0x31,0x20,0x3d,0x20,0x76,0x5f,0x62, + 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, + 0x28,0x28,0x5f,0x31,0x32,0x39,0x30,0x20,0x3e,0x20,0x30,0x2e,0x30,0x29,0x20,0x3f, + 0x20,0x31,0x2e,0x30,0x20,0x3a,0x20,0x30,0x2e,0x36,0x34,0x39,0x39,0x39,0x39,0x39, + 0x37,0x36,0x31,0x35,0x38,0x31,0x34,0x32,0x30,0x38,0x39,0x38,0x34,0x33,0x37,0x35, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33, + 0x32,0x35,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31,0x32,0x39, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x33,0x33,0x36,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31,0x33, + 0x30,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31, + 0x33,0x35,0x36,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x5f,0x31,0x33,0x32,0x31,0x2c, + 0x20,0x5f,0x31,0x33,0x32,0x31,0x20,0x2a,0x20,0x30,0x2e,0x33,0x34,0x39,0x39,0x39, + 0x39,0x39,0x39,0x34,0x30,0x33,0x39,0x35,0x33,0x35,0x35,0x32,0x32,0x34,0x36,0x30, + 0x39,0x33,0x37,0x35,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x6d,0x61,0x78,0x28,0x31, + 0x2e,0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28, + 0x30,0x2e,0x30,0x2c,0x20,0x5f,0x31,0x33,0x32,0x35,0x20,0x2a,0x20,0x31,0x2e,0x35, + 0x2c,0x20,0x61,0x62,0x73,0x28,0x5f,0x31,0x32,0x39,0x30,0x29,0x29,0x2c,0x20,0x31, + 0x2e,0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28, + 0x30,0x2e,0x30,0x2c,0x20,0x5f,0x31,0x33,0x33,0x36,0x20,0x2a,0x20,0x31,0x2e,0x35, + 0x2c,0x20,0x61,0x62,0x73,0x28,0x5f,0x31,0x33,0x30,0x37,0x29,0x29,0x29,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x31,0x33,0x36,0x34, + 0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x31,0x32,0x35,0x32,0x2c,0x20,0x31, + 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x31, + 0x33,0x36,0x35,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x76,0x69,0x65,0x77,0x5f, + 0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20,0x5f,0x31,0x33,0x36,0x34,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d, + 0x20,0x5f,0x31,0x33,0x36,0x35,0x2e,0x7a,0x20,0x2f,0x20,0x5f,0x31,0x33,0x36,0x35, + 0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x37, + 0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x33,0x39,0x37,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70, + 0x28,0x28,0x5f,0x37,0x30,0x37,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x5f,0x31, + 0x33,0x36,0x34,0x29,0x2e,0x7a,0x20,0x2a,0x20,0x28,0x2d,0x30,0x2e,0x30,0x31,0x39, + 0x39,0x39,0x39,0x39,0x39,0x39,0x35,0x35,0x32,0x39,0x36,0x35,0x31,0x36,0x34,0x31, + 0x38,0x34,0x35,0x37,0x30,0x33,0x31,0x32,0x35,0x29,0x2c,0x20,0x30,0x2e,0x30,0x2c, + 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f, + 0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28, + 0x5f,0x31,0x33,0x39,0x37,0x2c,0x20,0x5f,0x31,0x33,0x39,0x37,0x2c,0x20,0x5f,0x31, + 0x33,0x39,0x37,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x37,0x2e,0x66,0x6c, + 0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x34,0x31,0x38,0x20,0x3d,0x20,0x2d,0x28,0x5f,0x37,0x30,0x37,0x2e,0x76, + 0x69,0x65,0x77,0x20,0x2a,0x20,0x5f,0x31,0x33,0x36,0x34,0x29,0x2e,0x7a,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x34,0x31,0x38,0x20,0x3c,0x20,0x5f,0x37,0x30, + 0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, + 0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x34,0x31, + 0x38,0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f, + 0x31,0x34,0x34,0x32,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x5d,0x20,0x2a,0x20,0x5f,0x31,0x33,0x36,0x34,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x34,0x34, + 0x39,0x20,0x3d,0x20,0x5f,0x31,0x34,0x34,0x32,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20, + 0x76,0x65,0x63,0x33,0x28,0x5f,0x31,0x34,0x34,0x32,0x2e,0x77,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x34,0x36, + 0x36,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x28,0x5f,0x31,0x34,0x34,0x39,0x2e, + 0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20, + 0x28,0x28,0x5f,0x31,0x34,0x34,0x39,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x37,0x30,0x37, + 0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65, + 0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20, + 0x30,0x2e,0x35,0x2c,0x20,0x5f,0x31,0x34,0x34,0x39,0x2e,0x7a,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x34,0x37, + 0x30,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x6c,0x65,0x73,0x73,0x54,0x68,0x61,0x6e, + 0x28,0x5f,0x31,0x34,0x36,0x36,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30, + 0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f, + 0x6c,0x20,0x5f,0x31,0x34,0x37,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x34,0x37,0x30,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x5f,0x31,0x34,0x37,0x37,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x67, + 0x72,0x65,0x61,0x74,0x65,0x72,0x54,0x68,0x61,0x6e,0x28,0x5f,0x31,0x34,0x36,0x36, + 0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x34,0x37, + 0x37,0x20,0x3d,0x20,0x5f,0x31,0x34,0x37,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x33,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x21,0x5f,0x31,0x34,0x37,0x37,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69, + 0x6e,0x74,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x2c,0x20,0x30, + 0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34, + 0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x34,0x30, + 0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37, + 0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74, + 0x69,0x6e,0x74,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x34,0x30,0x30, + 0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35, + 0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x34, + 0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37, + 0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, + 0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x76, + 0x65,0x63,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39, + 0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c, + 0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34, + 0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20, + 0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x74,0x69,0x6e,0x74,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x5f,0x37,0x30,0x37,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d, + 0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65, + 0x63,0x34,0x28,0x28,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x28,0x5f, + 0x37,0x30,0x37,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28, + 0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,0x2e,0x78, + 0x79,0x7a,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x76,0x65,0x63, + 0x33,0x28,0x30,0x2e,0x35,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x31,0x35, + 0x34,0x37,0x20,0x3d,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x4c,0x6f,0x64,0x28, + 0x74,0x65,0x78,0x5f,0x61,0x6f,0x5f,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20,0x67, + 0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x20,0x2f, + 0x20,0x76,0x65,0x63,0x32,0x28,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x53,0x69,0x7a, + 0x65,0x28,0x74,0x65,0x78,0x5f,0x61,0x6f,0x5f,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c, + 0x20,0x30,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x34,0x38,0x20,0x3d,0x20,0x5f,0x31, + 0x35,0x34,0x37,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, + 0x37,0x30,0x37,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x34, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34, + 0x28,0x5f,0x31,0x35,0x34,0x38,0x2c,0x20,0x5f,0x31,0x35,0x34,0x38,0x2c,0x20,0x5f, + 0x31,0x35,0x34,0x38,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x20,0x3d,0x20,0x5f,0x31,0x32,0x35,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x6e,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x2d,0x28,0x5f,0x37,0x30,0x37, + 0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x5f,0x31,0x33,0x36,0x34,0x29,0x2e,0x7a, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x35,0x39,0x36, + 0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37,0x30, + 0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a, + 0x20,0x2d,0x20,0x5f,0x31,0x32,0x35,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x6e,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x31,0x35,0x39,0x36,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x35,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37, + 0x30,0x37,0x2e,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73, + 0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x73, + 0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61, + 0x64,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d, + 0x20,0x5f,0x31,0x33,0x35,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61, + 0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x76,0x5f, + 0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x62,0x6f,0x6f,0x6c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20, + 0x5f,0x37,0x30,0x37,0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e, + 0x79,0x20,0x3e,0x20,0x30,0x2e,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x6e,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x5f,0x31,0x35,0x39,0x36,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x33,0x20,0x3d,0x20,0x5f,0x31,0x33,0x35,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d, + 0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x35,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x75,0x6e,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x39,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x30,0x5d,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x31,0x5d,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x32,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30, + 0x37,0x2e,0x73,0x68,0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x37,0x5b,0x33,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e, + 0x73,0x68,0x5b,0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x37,0x5b,0x34,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68, + 0x5b,0x34,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x37,0x5b,0x35,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x35, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b, + 0x36,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x36,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x37,0x5d, + 0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x37,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x38,0x5d,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x38,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20, + 0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d, + 0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x36,0x37,0x35,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x2e,0x77,0x20,0x2a,0x20,0x5f,0x31,0x30,0x33,0x34,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76, + 0x65,0x63,0x34,0x28,0x28,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61, + 0x74,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39, + 0x29,0x20,0x2b,0x20,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65, + 0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38, + 0x2c,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x5f,0x73, + 0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x74,0x65,0x78, + 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x73,0x6d,0x70,0x5f,0x62,0x72, + 0x64,0x66,0x5f,0x6c,0x75,0x74,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x38,0x29, + 0x29,0x20,0x2a,0x20,0x5f,0x31,0x36,0x37,0x35,0x2c,0x20,0x5f,0x31,0x36,0x37,0x35, + 0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + struct instance + { + float4 xform_row0; + float4 xform_row1; + float4 xform_row2; + float4 base_color; + float4 params; + float4 material; + }; + + ByteAddressBuffer _15 : register(t0); + cbuffer ub_draw : register(b2) + { + int4 _21_inst_base : packoffset(c0); + }; + + cbuffer ub_frame : register(b0) + { + row_major float4x4 _158_view_proj : packoffset(c0); + }; + + + static float4 gl_Position; + static int gl_InstanceIndex; + static float3 in_pos; + static float3 v_world_pos_proxy; + static float3 v_center; + static float v_half_length; + static float v_radius; + static float3 v_axis_x_world; + static float3 v_rot_row0; + static float3 v_rot_row1; + static float3 v_rot_row2; + static float4 v_base_color; + static float4 v_material; + + struct SPIRV_Cross_Input + { + float3 in_pos : TEXCOORD0; + uint gl_InstanceIndex : SV_InstanceID; + }; + + struct SPIRV_Cross_Output + { + float3 v_world_pos_proxy : TEXCOORD0; + nointerpolation float3 v_center : TEXCOORD1; + nointerpolation float v_half_length : TEXCOORD2; + nointerpolation float v_radius : TEXCOORD3; + nointerpolation float3 v_axis_x_world : TEXCOORD4; + nointerpolation float3 v_rot_row0 : TEXCOORD5; + nointerpolation float3 v_rot_row1 : TEXCOORD6; + nointerpolation float3 v_rot_row2 : TEXCOORD7; + nointerpolation float4 v_base_color : TEXCOORD8; + nointerpolation float4 v_material : TEXCOORD9; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + instance _33; + _33.xform_row0 = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 0)); + _33.xform_row1 = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 16)); + _33.xform_row2 = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 32)); + _33.base_color = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 48)); + _33.params = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 64)); + _33.material = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 80)); + float3 _63 = float3(_33.xform_row0.w, _33.xform_row1.w, _33.xform_row2.w); + float3 _94 = float3((in_pos.x * 2.0f) * (_33.params.x + _33.params.y), (in_pos.y * 2.0f) * _33.params.y, (in_pos.z * 2.0f) * _33.params.y); + float3 _113 = _63 + float3(dot(_33.xform_row0.xyz, _94), dot(_33.xform_row1.xyz, _94), dot(_33.xform_row2.xyz, _94)); + v_world_pos_proxy = _113; + v_center = _63; + v_half_length = _33.params.x; + v_radius = _33.params.y; + v_axis_x_world = float3(_33.xform_row0.x, _33.xform_row1.x, _33.xform_row2.x); + v_rot_row0 = _33.xform_row0.xyz; + v_rot_row1 = _33.xform_row1.xyz; + v_rot_row2 = _33.xform_row2.xyz; + v_base_color = _33.base_color; + v_material = _33.material; + gl_Position = mul(float4(_113, 1.0f), _158_view_proj); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_InstanceIndex = int(stage_input.gl_InstanceIndex); + in_pos = stage_input.in_pos; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.v_world_pos_proxy = v_world_pos_proxy; + stage_output.v_center = v_center; + stage_output.v_half_length = v_half_length; + stage_output.v_radius = v_radius; + stage_output.v_axis_x_world = v_axis_x_world; + stage_output.v_rot_row0 = v_rot_row0; + stage_output.v_rot_row1 = v_rot_row1; + stage_output.v_rot_row2 = v_rot_row2; + stage_output.v_base_color = v_base_color; + stage_output.v_material = v_material; + return stage_output; + } +*/ +static const uint8_t capsule_vs_source_hlsl5[3455] = { + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d, + 0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x73,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6d,0x61,0x74,0x65, + 0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x42,0x79,0x74,0x65,0x41,0x64, + 0x64,0x72,0x65,0x73,0x73,0x42,0x75,0x66,0x66,0x65,0x72,0x20,0x5f,0x31,0x35,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x30,0x29,0x3b,0x0a, + 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x32,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x34,0x20,0x5f,0x32,0x31,0x5f,0x69,0x6e, + 0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66, + 0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x63,0x62, + 0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x20,0x3a, + 0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x31,0x35,0x38,0x5f,0x76,0x69,0x65,0x77, + 0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73, + 0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x0a,0x73,0x74,0x61, + 0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69, + 0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e, + 0x64,0x65,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69, + 0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x73,0x74,0x61,0x74, + 0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74, + 0x65,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a, + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72, + 0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x73, + 0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72, + 0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77, + 0x32,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x73, + 0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x6d, + 0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74, + 0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70, + 0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52, + 0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f, + 0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x3a,0x20, + 0x53,0x56,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x3b,0x0a,0x7d, + 0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f, + 0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3a,0x20,0x54,0x45, + 0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69, + 0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3a,0x20,0x54, + 0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f, + 0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74, + 0x68,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69, + 0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75, + 0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x33,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69, + 0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x61,0x78,0x69,0x73, + 0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f, + 0x4f,0x52,0x44,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65, + 0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x20,0x3a,0x20,0x54,0x45, + 0x58,0x43,0x4f,0x4f,0x52,0x44,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69, + 0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x20,0x3a, + 0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77, + 0x32,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x37,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69, + 0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52, + 0x44,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70, + 0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76, + 0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3a,0x20,0x54,0x45,0x58,0x43, + 0x4f,0x4f,0x52,0x44,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20, + 0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a, + 0x0a,0x76,0x6f,0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x20,0x5f,0x33,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f, + 0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32, + 0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20, + 0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78, + 0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31, + 0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c, + 0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62, + 0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61, + 0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b, + 0x20,0x31,0x36,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78, + 0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c, + 0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f, + 0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b, + 0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65, + 0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x33,0x32,0x29,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35, + 0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74, + 0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73, + 0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36, + 0x20,0x2b,0x20,0x34,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33, + 0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61, + 0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31, + 0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67, + 0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29, + 0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x36,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x5f,0x33,0x33,0x2e,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3d, + 0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61, + 0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73, + 0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x38, + 0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x5f,0x36,0x33,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x33,0x33, + 0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f, + 0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x77,0x2c, + 0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e, + 0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f, + 0x39,0x34,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x69,0x6e,0x5f, + 0x70,0x6f,0x73,0x2e,0x78,0x20,0x2a,0x20,0x32,0x2e,0x30,0x66,0x29,0x20,0x2a,0x20, + 0x28,0x5f,0x33,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x20,0x2b,0x20, + 0x5f,0x33,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x29,0x2c,0x20,0x28, + 0x69,0x6e,0x5f,0x70,0x6f,0x73,0x2e,0x79,0x20,0x2a,0x20,0x32,0x2e,0x30,0x66,0x29, + 0x20,0x2a,0x20,0x5f,0x33,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x2c, + 0x20,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x2e,0x7a,0x20,0x2a,0x20,0x32,0x2e,0x30, + 0x66,0x29,0x20,0x2a,0x20,0x5f,0x33,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e, + 0x79,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f, + 0x31,0x31,0x33,0x20,0x3d,0x20,0x5f,0x36,0x33,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x64,0x6f,0x74,0x28,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d, + 0x5f,0x72,0x6f,0x77,0x30,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x39,0x34,0x29,0x2c, + 0x20,0x64,0x6f,0x74,0x28,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72, + 0x6f,0x77,0x31,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x39,0x34,0x29,0x2c,0x20,0x64, + 0x6f,0x74,0x28,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77, + 0x32,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x39,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72, + 0x6f,0x78,0x79,0x20,0x3d,0x20,0x5f,0x31,0x31,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3d,0x20,0x5f,0x36,0x33,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74, + 0x68,0x20,0x3d,0x20,0x5f,0x33,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d, + 0x20,0x5f,0x33,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x33,0x33,0x2e,0x78, + 0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x78,0x2c,0x20,0x5f,0x33,0x33, + 0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x2c,0x20,0x5f, + 0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x78,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30, + 0x20,0x3d,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77, + 0x30,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x6f,0x74, + 0x5f,0x72,0x6f,0x77,0x31,0x20,0x3d,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x20,0x3d,0x20,0x5f,0x33,0x33, + 0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x78,0x79,0x7a,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x20,0x3d,0x20,0x5f,0x33,0x33,0x2e,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69, + 0x61,0x6c,0x20,0x3d,0x20,0x5f,0x33,0x33,0x2e,0x6d,0x61,0x74,0x65,0x72,0x69,0x61, + 0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69, + 0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, + 0x5f,0x31,0x31,0x33,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f,0x31,0x35, + 0x38,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x29,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74, + 0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, + 0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65, + 0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c, + 0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x3d, + 0x20,0x69,0x6e,0x74,0x28,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74, + 0x2e,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65, + 0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x3d, + 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x69,0x6e,0x5f, + 0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61, + 0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f, + 0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73, + 0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50, + 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73, + 0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65, + 0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x76,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e, + 0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3d,0x20,0x76,0x5f,0x63,0x65,0x6e, + 0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f, + 0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e, + 0x67,0x74,0x68,0x20,0x3d,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e, + 0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f, + 0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d, + 0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73, + 0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x61,0x78, + 0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x76,0x5f,0x61, + 0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f, + 0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x20,0x3d,0x20,0x76,0x5f,0x72,0x6f,0x74, + 0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65, + 0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f, + 0x77,0x31,0x20,0x3d,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75, + 0x74,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x20,0x3d,0x20,0x76, + 0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73, + 0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x62,0x61, + 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73, + 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65, + 0x72,0x69,0x61,0x6c,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61, + 0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74, + 0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + cbuffer ub_pass : register(b1) + { + float4 _707_sun_dir_world : packoffset(c0); + float4 _707_sun_color : packoffset(c1); + int4 _707_flags : packoffset(c2); + float4 _707_camera_pos : packoffset(c3); + row_major float4x4 _707_view_proj : packoffset(c4); + row_major float4x4 _707_view : packoffset(c8); + float4 _707_cascade_far_view_z : packoffset(c12); + row_major float4x4 _707_cascade_matrices[3] : packoffset(c13); + float4 _707_sh[9] : packoffset(c25); + float4 _707_ibl_params : packoffset(c34); + }; + + Texture2DArray tex_shadow : register(t0); + SamplerComparisonState smp_shadow : register(s0); + Texture2D tex_ao : register(t3); + SamplerState smp_ao : register(s3); + TextureCube tex_ibl_spec : register(t1); + SamplerState smp_ibl_spec : register(s1); + Texture2D tex_brdf_lut : register(t2); + SamplerState smp_brdf_lut : register(s2); + + static float4 gl_FragCoord; + static float gl_FragDepth; + static float3 v_world_pos_proxy; + static float3 v_axis_x_world; + static float3 v_center; + static float v_half_length; + static float v_radius; + static float3 v_rot_row0; + static float3 v_rot_row1; + static float3 v_rot_row2; + static float4 v_base_color; + static float4 out_color; + static float4 v_material; + + struct SPIRV_Cross_Input + { + float3 v_world_pos_proxy : TEXCOORD0; + nointerpolation float3 v_center : TEXCOORD1; + nointerpolation float v_half_length : TEXCOORD2; + nointerpolation float v_radius : TEXCOORD3; + nointerpolation float3 v_axis_x_world : TEXCOORD4; + nointerpolation float3 v_rot_row0 : TEXCOORD5; + nointerpolation float3 v_rot_row1 : TEXCOORD6; + nointerpolation float3 v_rot_row2 : TEXCOORD7; + nointerpolation float4 v_base_color : TEXCOORD8; + nointerpolation float4 v_material : TEXCOORD9; + float4 gl_FragCoord : SV_Position; + }; + + struct SPIRV_Cross_Output + { + float4 out_color : SV_Target0; + float gl_FragDepth : SV_Depth; + }; + + uint2 spvTextureSize(Texture2D Tex, uint Level, out uint Param) + { + uint2 ret; + Tex.GetDimensions(Level, ret.x, ret.y, Param); + return ret; + } + + float sampleShadowPCF(int cascade, float3 light_uv, float bias) + { + float _529 = float(cascade); + float _534 = light_uv.z - bias; + float _550 = light_uv.x - 0.00048828125f; + float _554 = light_uv.y - 0.00048828125f; + float _584 = light_uv.x + 0.00048828125f; + float _652 = light_uv.y + 0.00048828125f; + return ((((((((tex_shadow.SampleCmp(smp_shadow, float4(_550, _554, _529, _534).xyz, _534) + tex_shadow.SampleCmp(smp_shadow, float4(light_uv.x, _554, _529, _534).xyz, _534)) + tex_shadow.SampleCmp(smp_shadow, float4(_584, _554, _529, _534).xyz, _534)) + tex_shadow.SampleCmp(smp_shadow, float4(_550, light_uv.y, _529, _534).xyz, _534)) + tex_shadow.SampleCmp(smp_shadow, float4(light_uv.xy, _529, _534).xyz, _534)) + tex_shadow.SampleCmp(smp_shadow, float4(_584, light_uv.y, _529, _534).xyz, _534)) + tex_shadow.SampleCmp(smp_shadow, float4(_550, _652, _529, _534).xyz, _534)) + tex_shadow.SampleCmp(smp_shadow, float4(light_uv.x, _652, _529, _534).xyz, _534)) + tex_shadow.SampleCmp(smp_shadow, float4(_584, _652, _529, _534).xyz, _534)) * 0.111111111938953399658203125f; + } + + float sampleCascade(int cascade, float3 world_pos, float3 world_normal) + { + float4 _717 = mul(float4(world_pos, 1.0f), _707_cascade_matrices[cascade]); + float3 _724 = _717.xyz / _717.w.xxx; + float3 _742 = float3((_724.x * 0.5f) + 0.5f, ((_724.y * _707_cascade_far_view_z.w) * 0.5f) + 0.5f, _724.z); + bool _746 = any(bool3(_742.x < 0.0f.xxx.x, _742.y < 0.0f.xxx.y, _742.z < 0.0f.xxx.z)); + bool _753; + if (!_746) + { + _753 = any(bool3(_742.x > 1.0f.xxx.x, _742.y > 1.0f.xxx.y, _742.z > 1.0f.xxx.z)); + } + else + { + _753 = _746; + } + if (_753) + { + return 1.0f; + } + int param = cascade; + float3 param_1 = _742; + float param_2 = lerp(0.0040000001899898052215576171875f, 0.0007999999797903001308441162109375f, max(dot(world_normal, normalize(_707_sun_dir_world.xyz)), 0.0f)); + float pcf = sampleShadowPCF(param, param_1, param_2); + if (cascade == 2) + { + float2 _785 = _742.xy; + float2 _790 = min(_785, 1.0f.xx - _785); + pcf = lerp(1.0f, pcf, clamp(min(_790.x, _790.y) * 10.0f, 0.0f, 1.0f)); + } + return pcf; + } + + float sampleShadowCascaded(float3 world_pos, float3 world_normal, float view_z) + { + int cascade = 2; + if (view_z < _707_cascade_far_view_z.x) + { + cascade = 0; + } + else + { + if (view_z < _707_cascade_far_view_z.y) + { + cascade = 1; + } + } + int param = cascade; + float3 param_1 = world_pos; + float3 param_2 = world_normal; + float shadow = sampleCascade(param, param_1, param_2); + if (cascade < 2) + { + float _835; + if (cascade == 0) + { + _835 = _707_cascade_far_view_z.x; + } + else + { + _835 = _707_cascade_far_view_z.y; + } + float _847; + if (cascade == 0) + { + _847 = 0.0f; + } + else + { + _847 = _707_cascade_far_view_z.x; + } + float _858 = lerp(_835, _847, 0.100000001490116119384765625f); + if (view_z > _858) + { + int param_3 = cascade + 1; + float3 param_4 = world_pos; + float3 param_5 = world_normal; + shadow = lerp(shadow, sampleCascade(param_3, param_4, param_5), (view_z - _858) / (_835 - _858)); + } + } + return shadow; + } + + float pbrDistributionGGX(float n_dot_h, float alpha) + { + float _107 = alpha * alpha; + float _116 = ((n_dot_h * n_dot_h) * (_107 - 1.0f)) + 1.0f; + return _107 / ((3.1415927410125732421875f * _116) * _116); + } + + float pbrVisibilitySmithCorrelated(float n_dot_v, float n_dot_l, float alpha) + { + float _129 = alpha * alpha; + float _136 = 1.0f - _129; + return 0.5f / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _136) + _129)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _136) + _129))) + 9.9999997473787516355514526367188e-06f); + } + + float3 pbrFresnelSchlick(float v_dot_h, float3 f0) + { + float _165 = 1.0f - v_dot_h; + float _169 = _165 * _165; + return f0 + ((1.0f.xxx - f0) * ((_169 * _169) * _165)); + } + + float3 brdf_evaluate(float3 N, float3 V, float3 L, float3 sun_radiance, float3 base_color, float metallic, float roughness) + { + float _188 = max(dot(N, L), 0.0f); + float3 _199 = normalize(V + L); + float _213 = max(roughness, 0.04500000178813934326171875f); + float _217 = _213 * _213; + float param = max(dot(N, _199), 0.0f); + float param_1 = _217; + float param_2 = max(dot(N, V), 9.9999997473787516355514526367188e-05f); + float param_3 = _188; + float param_4 = _217; + float param_5 = max(dot(V, _199), 0.0f); + float3 param_6 = lerp(0.039999999105930328369140625f.xxx, base_color, metallic.xxx); + float3 _244 = pbrFresnelSchlick(param_5, param_6); + return ((((((1.0f.xxx - _244) * (1.0f - metallic)) * base_color) * 0.3183098733425140380859375f.xxx) + (_244 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _188; + } + + float3 pbrEvaluateShIrradiance(float3 N, float4 sh[9]) + { + float3 _399 = ((((((((sh[0].xyz * 0.2820948064327239990234375f) + (sh[1].xyz * ((-0.48860251903533935546875f) * N.y))) + (sh[2].xyz * (0.48860251903533935546875f * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875f) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125f * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125f) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125f * (((3.0f * N.z) * N.z) - 1.0f)))) + (sh[7].xyz * (((-1.09254848957061767578125f) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625f * ((N.x * N.x) - (N.y * N.y)))); + return _399; + } + + float3 pbrEvaluateIbl(float3 N_world, float3 V_world, float3 base_color, float metallic, float roughness, float4 sh[9], TextureCube tex_spec_cube, SamplerState smp_spec_cube, Texture2D tex_brdf_lut_1, SamplerState smp_brdf_lut_1, float max_lod) + { + float _406 = clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05f, 1.0f); + float3 _416 = lerp(0.039999999105930328369140625f.xxx, base_color, metallic.xxx); + float3 param = N_world; + float4 param_1[9] = sh; + float4 _482 = tex_brdf_lut_1.Sample(smp_brdf_lut_1, float2(_406, roughness)); + return (((((1.0f.xxx - (_416 + ((max((1.0f - roughness).xxx, _416) - _416) * pow(max(0.0f, 1.0f - _406), 5.0f)))) * (1.0f - metallic)) * base_color) * max(pbrEvaluateShIrradiance(param, param_1), 0.0f.xxx)) * 0.3183098733425140380859375f.xxx) + (tex_spec_cube.SampleLevel(smp_spec_cube, reflect(-V_world, N_world), roughness * max_lod).xyz * ((_416 * _482.x) + _482.y.xxx)); + } + + float3 pbrEvaluateAmbient(bool iblEnabled, float3 N_world, float3 V_world, float3 base_color, float metallic, float roughness, float flat_strength, float4 sh[9], TextureCube tex_spec_cube, SamplerState smp_spec_cube, Texture2D tex_brdf_lut_1, SamplerState smp_brdf_lut_1, float max_lod) + { + float3 result = base_color * flat_strength; + if (iblEnabled) + { + float3 param = N_world; + float3 param_1 = V_world; + float3 param_2 = base_color; + float param_3 = metallic; + float param_4 = roughness; + float4 param_5[9] = sh; + float param_6 = max_lod; + result = pbrEvaluateIbl(param, param_1, param_2, param_3, param_4, param_5, tex_spec_cube, smp_spec_cube, tex_brdf_lut_1, smp_brdf_lut_1, param_6); + } + return result; + } + + void frag_main() + { + float3 _896 = normalize(v_world_pos_proxy - _707_camera_pos.xyz); + float3 _907 = v_axis_x_world * v_half_length; + float3 _908 = v_center - _907; + float3 _914 = v_center + _907; + float3 _918 = _914 - _908; + float3 _922 = _707_camera_pos.xyz - _908; + float _926 = dot(_918, _918); + float _930 = dot(_918, _896); + float _934 = dot(_918, _922); + float _942 = dot(_922, _922); + float _948 = _926 - (_930 * _930); + float _956 = (_926 * dot(_896, _922)) - (_934 * _930); + float _968 = v_radius * v_radius; + float _979 = (_956 * _956) - (_948 * (((_926 * _942) - (_934 * _934)) - (_968 * _926))); + float3 _1000 = _908 + (_918 * clamp((_934 - ((_956 / max(_948, 9.9999999392252902907785028219223e-09f)) * _930)) / _926, 0.0f, 1.0f)); + float3 _1004 = _707_camera_pos.xyz - _1000; + float _1008 = dot(_1004, _896); + float _1022 = sqrt(max(0.0f, dot(_1004, _1004) - (_1008 * _1008))) - v_radius; + float _1025 = fwidth(_1022); + float _1027 = max(_1025, 9.9999999747524270787835121154785e-07f); + float _1034 = 1.0f - smoothstep(-_1027, _1027, _1022); + float t = -1.0f; + float3 n_world = 0.0f.xxx; + if ((_979 >= 0.0f) && (_948 > 9.9999999392252902907785028219223e-09f)) + { + float _1052 = ((-_956) - sqrt(_979)) / _948; + float _1058 = _934 + (_1052 * _930); + if (((_1052 > 0.0f) && (_1058 > 0.0f)) && (_1058 < _926)) + { + n_world = ((_707_camera_pos.xyz + (_896 * _1052)) - (_908 + (_918 * (_1058 / _926)))) / v_radius.xxx; + t = _1052; + } + } + float _1098 = dot(_922, _896); + float _1112 = (_1098 * _1098) - (_942 - _968); + if (_1112 >= 0.0f) + { + float _1122 = (-_1098) - sqrt(_1112); + bool _1124 = _1122 > 0.0f; + bool _1133; + if (_1124) + { + _1133 = (t < 0.0f) || (_1122 < t); + } + else + { + _1133 = _1124; + } + if (_1133) + { + float3 _1144 = (_707_camera_pos.xyz + (_896 * _1122)) - _908; + if (dot(_1144, v_axis_x_world) <= 0.0f) + { + n_world = _1144 / v_radius.xxx; + t = _1122; + } + } + } + float3 _1160 = _707_camera_pos.xyz - _914; + float _1164 = dot(_1160, _896); + float _1178 = (_1164 * _1164) - (dot(_1160, _1160) - _968); + if (_1178 >= 0.0f) + { + float _1188 = (-_1164) - sqrt(_1178); + bool _1190 = _1188 > 0.0f; + bool _1199; + if (_1190) + { + _1199 = (t < 0.0f) || (_1188 < t); + } + else + { + _1199 = _1190; + } + if (_1199) + { + float3 _1210 = (_707_camera_pos.xyz + (_896 * _1188)) - _914; + if (dot(_1210, v_axis_x_world) >= 0.0f) + { + n_world = _1210 / v_radius.xxx; + t = _1188; + } + } + } + if (t < 0.0f) + { + float _1228 = -_1008; + t = _1228; + n_world = normalize((_707_camera_pos.xyz + (_896 * _1228)) - _1000); + } + if ((_1034 <= 0.0f) || (t < 0.0f)) + { + discard; + } + float3 _1252 = _707_camera_pos.xyz + (_896 * t); + float _1290 = ((v_rot_row0.y * n_world.x) + (v_rot_row1.y * n_world.y)) + (v_rot_row2.y * n_world.z); + float _1307 = ((v_rot_row0.z * n_world.x) + (v_rot_row1.z * n_world.y)) + (v_rot_row2.z * n_world.z); + float3 _1321 = v_base_color.xyz * ((_1290 > 0.0f) ? 1.0f : 0.64999997615814208984375f); + float _1325 = fwidth(_1290); + float _1336 = fwidth(_1307); + float3 _1356 = lerp(_1321, _1321 * 0.3499999940395355224609375f, max(1.0f - smoothstep(0.0f, _1325 * 1.5f, abs(_1290)), 1.0f - smoothstep(0.0f, _1336 * 1.5f, abs(_1307))).xxx); + float4 _1364 = float4(_1252, 1.0f); + float4 _1365 = mul(_1364, _707_view_proj); + gl_FragDepth = _1365.z / _1365.w; + if (_707_flags.x == 1) + { + float _1397 = clamp(mul(_1364, _707_view).z * (-0.0199999995529651641845703125f), 0.0f, 1.0f); + out_color = float4(_1397, _1397, _1397, 1.0f); + return; + } + if (_707_flags.x == 2) + { + float _1418 = -mul(_1364, _707_view).z; + int cascade = 2; + if (_1418 < _707_cascade_far_view_z.x) + { + cascade = 0; + } + else + { + if (_1418 < _707_cascade_far_view_z.y) + { + cascade = 1; + } + } + float4 _1442 = mul(_1364, _707_cascade_matrices[cascade]); + float3 _1449 = _1442.xyz / _1442.w.xxx; + float3 _1466 = float3((_1449.x * 0.5f) + 0.5f, ((_1449.y * _707_cascade_far_view_z.w) * 0.5f) + 0.5f, _1449.z); + bool _1470 = any(bool3(_1466.x < 0.0f.xxx.x, _1466.y < 0.0f.xxx.y, _1466.z < 0.0f.xxx.z)); + bool _1477; + if (!_1470) + { + _1477 = any(bool3(_1466.x > 1.0f.xxx.x, _1466.y > 1.0f.xxx.y, _1466.z > 1.0f.xxx.z)); + } + else + { + _1477 = _1470; + } + float3 tint = 1.0f.xxx; + if (!_1477) + { + if (cascade == 0) + { + tint = float3(1.0f, 0.4000000059604644775390625f, 0.4000000059604644775390625f); + } + else + { + if (cascade == 1) + { + tint = float3(0.4000000059604644775390625f, 1.0f, 0.4000000059604644775390625f); + } + else + { + tint = float3(0.4000000059604644775390625f, 0.4000000059604644775390625f, 1.0f); + } + } + } + out_color = float4(tint, 1.0f); + return; + } + if (_707_flags.x == 3) + { + out_color = float4((normalize(mul(float4(n_world, 0.0f), _707_view).xyz) * 0.5f) + 0.5f.xxx, 1.0f); + return; + } + uint _1539_dummy_parameter; + float4 _1547 = tex_ao.SampleLevel(smp_ao, gl_FragCoord.xy / float2(int2(spvTextureSize(tex_ao, uint(0), _1539_dummy_parameter))), 0.0f); + float _1548 = _1547.x; + if (_707_flags.x == 4) + { + out_color = float4(_1548, _1548, _1548, 1.0f); + return; + } + float3 param = _1252; + float3 param_1 = n_world; + float param_2 = -mul(_1364, _707_view).z; + float3 _1596 = normalize(_707_camera_pos.xyz - _1252); + float3 param_3 = n_world; + float3 param_4 = _1596; + float3 param_5 = normalize(_707_sun_dir_world.xyz); + float3 param_6 = _707_sun_color.xyz * sampleShadowCascaded(param, param_1, param_2); + float3 param_7 = _1356; + float param_8 = v_material.x; + float param_9 = v_material.y; + bool param_10 = _707_ibl_params.y > 0.5f; + float3 param_11 = n_world; + float3 param_12 = _1596; + float3 param_13 = _1356; + float param_14 = v_material.x; + float param_15 = v_material.y; + float param_16 = _707_sun_color.w; + float4 param_17[9]; + param_17[0] = _707_sh[0]; + param_17[1] = _707_sh[1]; + param_17[2] = _707_sh[2]; + param_17[3] = _707_sh[3]; + param_17[4] = _707_sh[4]; + param_17[5] = _707_sh[5]; + param_17[6] = _707_sh[6]; + param_17[7] = _707_sh[7]; + param_17[8] = _707_sh[8]; + float param_18 = _707_ibl_params.x; + float _1675 = v_base_color.w * _1034; + out_color = float4((brdf_evaluate(param_3, param_4, param_5, param_6, param_7, param_8, param_9) + (pbrEvaluateAmbient(param_10, param_11, param_12, param_13, param_14, param_15, param_16, param_17, tex_ibl_spec, smp_ibl_spec, tex_brdf_lut, smp_brdf_lut, param_18) * _1548)) * _1675, _1675); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_FragCoord = stage_input.gl_FragCoord; + gl_FragCoord.w = 1.0 / gl_FragCoord.w; + v_world_pos_proxy = stage_input.v_world_pos_proxy; + v_axis_x_world = stage_input.v_axis_x_world; + v_center = stage_input.v_center; + v_half_length = stage_input.v_half_length; + v_radius = stage_input.v_radius; + v_rot_row0 = stage_input.v_rot_row0; + v_rot_row1 = stage_input.v_rot_row1; + v_rot_row2 = stage_input.v_rot_row2; + v_base_color = stage_input.v_base_color; + v_material = stage_input.v_material; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_FragDepth = gl_FragDepth; + stage_output.out_color = out_color; + return stage_output; + } +*/ +static const uint8_t capsule_fs_source_hlsl5[17765] = { + 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x31,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x30,0x37, + 0x5f,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3a, + 0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x30,0x37, + 0x5f,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x70,0x61,0x63, + 0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x6e,0x74,0x34,0x20,0x5f,0x37,0x30,0x37,0x5f,0x66,0x6c,0x61,0x67,0x73, + 0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x32, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37, + 0x30,0x37,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20, + 0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x33,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x37,0x30,0x37,0x5f,0x76,0x69,0x65,0x77, + 0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73, + 0x65,0x74,0x28,0x63,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f, + 0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f, + 0x37,0x30,0x37,0x5f,0x76,0x69,0x65,0x77,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f, + 0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3a,0x20, + 0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x32,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x33,0x5d, + 0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31, + 0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f, + 0x37,0x30,0x37,0x5f,0x73,0x68,0x5b,0x39,0x5d,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b, + 0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x30,0x37,0x5f,0x69,0x62,0x6c, + 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66, + 0x66,0x73,0x65,0x74,0x28,0x63,0x33,0x34,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x54, + 0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x30,0x29,0x3b, + 0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x6f,0x6d,0x70,0x61,0x72,0x69,0x73, + 0x6f,0x6e,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x30, + 0x29,0x3b,0x0a,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x20,0x3a,0x20,0x72,0x65, + 0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x33,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70, + 0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x33,0x29,0x3b,0x0a, + 0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x43,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63, + 0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x31,0x29,0x3b, + 0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d, + 0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x20,0x3a,0x20,0x72,0x65,0x67, + 0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x31,0x29,0x3b,0x0a,0x54,0x65,0x78,0x74,0x75, + 0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78, + 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x20,0x3a,0x20,0x72,0x65,0x67,0x69, + 0x73,0x74,0x65,0x72,0x28,0x74,0x32,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65, + 0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f, + 0x6c,0x75,0x74,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73, + 0x32,0x29,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x3b, + 0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c, + 0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x3b,0x0a,0x73,0x74,0x61,0x74, + 0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x73,0x74,0x61, + 0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x61,0x78,0x69, + 0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69, + 0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65, + 0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x73, + 0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61, + 0x64,0x69,0x75,0x73,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a, + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f, + 0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f, + 0x77,0x32,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a, + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75, + 0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61, + 0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56, + 0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3a,0x20,0x54,0x45, + 0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69, + 0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3a,0x20,0x54, + 0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f, + 0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74, + 0x68,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69, + 0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75, + 0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x33,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69, + 0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x61,0x78,0x69,0x73, + 0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f, + 0x4f,0x52,0x44,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65, + 0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x20,0x3a,0x20,0x54,0x45, + 0x58,0x43,0x4f,0x4f,0x52,0x44,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69, + 0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x20,0x3a, + 0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77, + 0x32,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x37,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69, + 0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52, + 0x44,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70, + 0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76, + 0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3a,0x20,0x54,0x45,0x58,0x43, + 0x4f,0x4f,0x52,0x44,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x20,0x3a, + 0x20,0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, + 0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x20,0x3a,0x20,0x53,0x56,0x5f,0x54,0x61,0x72,0x67,0x65,0x74,0x30,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,0x46,0x72, + 0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3a,0x20,0x53,0x56,0x5f,0x44,0x65,0x70, + 0x74,0x68,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x75,0x69,0x6e,0x74,0x32,0x20,0x73,0x70, + 0x76,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x54,0x65,0x78, + 0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x54, + 0x65,0x78,0x2c,0x20,0x75,0x69,0x6e,0x74,0x20,0x4c,0x65,0x76,0x65,0x6c,0x2c,0x20, + 0x6f,0x75,0x74,0x20,0x75,0x69,0x6e,0x74,0x20,0x50,0x61,0x72,0x61,0x6d,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x32,0x20,0x72,0x65,0x74,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x54,0x65,0x78,0x2e,0x47,0x65,0x74,0x44,0x69,0x6d,0x65, + 0x6e,0x73,0x69,0x6f,0x6e,0x73,0x28,0x4c,0x65,0x76,0x65,0x6c,0x2c,0x20,0x72,0x65, + 0x74,0x2e,0x78,0x2c,0x20,0x72,0x65,0x74,0x2e,0x79,0x2c,0x20,0x50,0x61,0x72,0x61, + 0x6d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x72, + 0x65,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x69,0x6e,0x74, + 0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x62,0x69,0x61,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x35,0x32,0x39,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x35,0x33,0x34,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74, + 0x5f,0x75,0x76,0x2e,0x7a,0x20,0x2d,0x20,0x62,0x69,0x61,0x73,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x35,0x30,0x20,0x3d,0x20,0x6c, + 0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20,0x2d,0x20,0x30,0x2e,0x30,0x30, + 0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x35,0x34,0x20,0x3d,0x20,0x6c,0x69,0x67, + 0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x20,0x2d,0x20,0x30,0x2e,0x30,0x30,0x30,0x34, + 0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x35,0x38,0x34,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74, + 0x5f,0x75,0x76,0x2e,0x78,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38, + 0x32,0x38,0x31,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x36,0x35,0x32,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75, + 0x76,0x2e,0x79,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38, + 0x31,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d, + 0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x28,0x5f,0x35,0x35,0x30,0x2c,0x20,0x5f,0x35,0x35,0x34,0x2c,0x20,0x5f,0x35,0x32, + 0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35, + 0x33,0x34,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6c,0x69, + 0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20,0x5f,0x35,0x35,0x34,0x2c,0x20, + 0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c, + 0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68, + 0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73, + 0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x28,0x5f,0x35,0x38,0x34,0x2c,0x20,0x5f,0x35,0x35,0x34,0x2c,0x20,0x5f,0x35, + 0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f, + 0x35,0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, + 0x5f,0x35,0x35,0x30,0x2c,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79, + 0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79, + 0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70, + 0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x79,0x2c, + 0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a, + 0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28, + 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x28,0x5f,0x35,0x38,0x34,0x2c,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75, + 0x76,0x2e,0x79,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29, + 0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74, + 0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65, + 0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x35,0x30,0x2c,0x20,0x5f,0x36,0x35, + 0x32,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78, + 0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d, + 0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c, + 0x20,0x5f,0x36,0x35,0x32,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33, + 0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b, + 0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70, + 0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x38,0x34,0x2c,0x20,0x5f, + 0x36,0x35,0x32,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29, + 0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2a,0x20,0x30, + 0x2e,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x39,0x33,0x38,0x39,0x35,0x33, + 0x33,0x39,0x39,0x36,0x35,0x38,0x32,0x30,0x33,0x31,0x32,0x35,0x66,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61, + 0x73,0x63,0x61,0x64,0x65,0x28,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x70,0x6f,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x31,0x37,0x20,0x3d,0x20,0x6d,0x75, + 0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70, + 0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f,0x37,0x30,0x37,0x5f, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73, + 0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x37,0x32,0x34,0x20,0x3d,0x20,0x5f,0x37, + 0x31,0x37,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x5f,0x37,0x31,0x37,0x2e,0x77,0x2e, + 0x78,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x5f,0x37,0x34,0x32,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x5f, + 0x37,0x32,0x34,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20, + 0x30,0x2e,0x35,0x66,0x2c,0x20,0x28,0x28,0x5f,0x37,0x32,0x34,0x2e,0x79,0x20,0x2a, + 0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61, + 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e, + 0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2c,0x20,0x5f,0x37,0x32,0x34, + 0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x37, + 0x34,0x36,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c,0x33,0x28,0x5f, + 0x37,0x34,0x32,0x2e,0x78,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78, + 0x2e,0x78,0x2c,0x20,0x5f,0x37,0x34,0x32,0x2e,0x79,0x20,0x3c,0x20,0x30,0x2e,0x30, + 0x66,0x2e,0x78,0x78,0x78,0x2e,0x79,0x2c,0x20,0x5f,0x37,0x34,0x32,0x2e,0x7a,0x20, + 0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x7a,0x29,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x37,0x35,0x33,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x37,0x34,0x36,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x37,0x35,0x33, + 0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c,0x33,0x28,0x5f,0x37,0x34, + 0x32,0x2e,0x78,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x78, + 0x2c,0x20,0x5f,0x37,0x34,0x32,0x2e,0x79,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e, + 0x78,0x78,0x78,0x2e,0x79,0x2c,0x20,0x5f,0x37,0x34,0x32,0x2e,0x7a,0x20,0x3e,0x20, + 0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x7a,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x37,0x35,0x33,0x20, + 0x3d,0x20,0x5f,0x37,0x34,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x35,0x33,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x30,0x2e,0x30,0x30,0x34,0x30, + 0x30,0x30,0x30,0x30,0x30,0x31,0x38,0x39,0x39,0x38,0x39,0x38,0x30,0x35,0x32,0x32, + 0x31,0x35,0x35,0x37,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x66,0x2c,0x20,0x30,0x2e, + 0x30,0x30,0x30,0x37,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x39,0x37,0x39,0x30,0x33, + 0x30,0x30,0x31,0x33,0x30,0x38,0x34,0x34,0x31,0x31,0x36,0x32,0x31,0x30,0x39,0x33, + 0x37,0x35,0x66,0x2c,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x77,0x6f,0x72, + 0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37,0x30,0x37,0x5f,0x73,0x75,0x6e,0x5f,0x64,0x69, + 0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x29,0x29,0x2c,0x20,0x30, + 0x2e,0x30,0x66,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61, + 0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x37,0x38,0x35, + 0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x2e,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x37,0x39,0x30,0x20, + 0x3d,0x20,0x6d,0x69,0x6e,0x28,0x5f,0x37,0x38,0x35,0x2c,0x20,0x31,0x2e,0x30,0x66, + 0x2e,0x78,0x78,0x20,0x2d,0x20,0x5f,0x37,0x38,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28, + 0x31,0x2e,0x30,0x66,0x2c,0x20,0x70,0x63,0x66,0x2c,0x20,0x63,0x6c,0x61,0x6d,0x70, + 0x28,0x6d,0x69,0x6e,0x28,0x5f,0x37,0x39,0x30,0x2e,0x78,0x2c,0x20,0x5f,0x37,0x39, + 0x30,0x2e,0x79,0x29,0x20,0x2a,0x20,0x31,0x30,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e, + 0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x70,0x63,0x66, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e, + 0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x69,0x65, + 0x77,0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x37,0x30, + 0x37,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20, + 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, + 0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x37,0x30, + 0x37,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x2e,0x79,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70, + 0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e, + 0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, + 0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x20,0x3c,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x33,0x35,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x5f,0x38,0x33,0x35,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e, + 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x5f,0x38,0x33,0x35,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x34,0x37,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x5f,0x38,0x34,0x37,0x20,0x3d,0x20,0x30,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65, + 0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x34,0x37,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61, + 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x38,0x35,0x38,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28, + 0x5f,0x38,0x33,0x35,0x2c,0x20,0x5f,0x38,0x34,0x37,0x2c,0x20,0x30,0x2e,0x31,0x30, + 0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x34,0x39,0x30,0x31,0x31,0x36,0x31,0x31,0x39, + 0x33,0x38,0x34,0x37,0x36,0x35,0x36,0x32,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20, + 0x3e,0x20,0x5f,0x38,0x35,0x38,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x20,0x2b,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x34,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d, + 0x20,0x6c,0x65,0x72,0x70,0x28,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x61, + 0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x35,0x29,0x2c,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20, + 0x2d,0x20,0x5f,0x38,0x35,0x38,0x29,0x20,0x2f,0x20,0x28,0x5f,0x38,0x33,0x35,0x20, + 0x2d,0x20,0x5f,0x38,0x35,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x7d,0x0a,0x0a, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62, + 0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e, + 0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c, + 0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x30,0x37,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20, + 0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x31,0x36,0x20,0x3d,0x20,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f, + 0x68,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x29,0x20,0x2a,0x20,0x28, + 0x5f,0x31,0x30,0x37,0x20,0x2d,0x20,0x31,0x2e,0x30,0x66,0x29,0x29,0x20,0x2b,0x20, + 0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x5f,0x31,0x30,0x37,0x20,0x2f,0x20,0x28,0x28,0x33,0x2e,0x31,0x34,0x31,0x35, + 0x39,0x32,0x37,0x34,0x31,0x30,0x31,0x32,0x35,0x37,0x33,0x32,0x34,0x32,0x31,0x38, + 0x37,0x35,0x66,0x20,0x2a,0x20,0x5f,0x31,0x31,0x36,0x29,0x20,0x2a,0x20,0x5f,0x31, + 0x31,0x36,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62, + 0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68, + 0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61, + 0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x31,0x32,0x39,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a, + 0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x31,0x33,0x36,0x20,0x3d,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20, + 0x5f,0x31,0x32,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x30,0x2e,0x35,0x66,0x20,0x2f,0x20,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74, + 0x5f,0x6c,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f, + 0x74,0x5f,0x76,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x29,0x20,0x2a, + 0x20,0x5f,0x31,0x33,0x36,0x29,0x20,0x2b,0x20,0x5f,0x31,0x32,0x39,0x29,0x29,0x20, + 0x2b,0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x73,0x71,0x72, + 0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x6e,0x5f, + 0x64,0x6f,0x74,0x5f,0x6c,0x29,0x20,0x2a,0x20,0x5f,0x31,0x33,0x36,0x29,0x20,0x2b, + 0x20,0x5f,0x31,0x32,0x39,0x29,0x29,0x29,0x20,0x2b,0x20,0x39,0x2e,0x39,0x39,0x39, + 0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35, + 0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36, + 0x66,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62, + 0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x66,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x35,0x20,0x3d,0x20,0x31,0x2e,0x30, + 0x66,0x20,0x2d,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x39,0x20,0x3d,0x20,0x5f,0x31, + 0x36,0x35,0x20,0x2a,0x20,0x5f,0x31,0x36,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x30,0x20,0x2b,0x20,0x28,0x28,0x31,0x2e,0x30, + 0x66,0x2e,0x78,0x78,0x78,0x20,0x2d,0x20,0x66,0x30,0x29,0x20,0x2a,0x20,0x28,0x28, + 0x5f,0x31,0x36,0x39,0x20,0x2a,0x20,0x5f,0x31,0x36,0x39,0x29,0x20,0x2a,0x20,0x5f, + 0x31,0x36,0x35,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x4e,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x56,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4c,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c, + 0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68, + 0x6e,0x65,0x73,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x31,0x38,0x38,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74, + 0x28,0x4e,0x2c,0x20,0x4c,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x39,0x39,0x20,0x3d, + 0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x56,0x20,0x2b,0x20,0x4c, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31, + 0x33,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73, + 0x73,0x2c,0x20,0x30,0x2e,0x30,0x34,0x35,0x30,0x30,0x30,0x30,0x30,0x31,0x37,0x38, + 0x38,0x31,0x33,0x39,0x33,0x34,0x33,0x32,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x66, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31, + 0x37,0x20,0x3d,0x20,0x5f,0x32,0x31,0x33,0x20,0x2a,0x20,0x5f,0x32,0x31,0x33,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x5f,0x31, + 0x39,0x39,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20, + 0x5f,0x32,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f, + 0x74,0x28,0x4e,0x2c,0x20,0x56,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39, + 0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31, + 0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x66,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31,0x38,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20, + 0x5f,0x32,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f, + 0x74,0x28,0x56,0x2c,0x20,0x5f,0x31,0x39,0x39,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x30,0x2e,0x30, + 0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32, + 0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x66,0x2e,0x78,0x78,0x78,0x2c, + 0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x6d,0x65,0x74, + 0x61,0x6c,0x6c,0x69,0x63,0x2e,0x78,0x78,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x32,0x34,0x34,0x20,0x3d,0x20,0x70,0x62, + 0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28, + 0x28,0x28,0x28,0x28,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x20,0x2d,0x20,0x5f, + 0x32,0x34,0x34,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x6d, + 0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x30,0x2e,0x33,0x31,0x38,0x33, + 0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38, + 0x35,0x39,0x33,0x37,0x35,0x66,0x2e,0x78,0x78,0x78,0x29,0x20,0x2b,0x20,0x28,0x5f, + 0x32,0x34,0x34,0x20,0x2a,0x20,0x28,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69, + 0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x20,0x2a,0x20,0x70,0x62,0x72,0x56, + 0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f, + 0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x34,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64, + 0x69,0x61,0x6e,0x63,0x65,0x29,0x20,0x2a,0x20,0x5f,0x31,0x38,0x38,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c, + 0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65, + 0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4e,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x33,0x39,0x39,0x20,0x3d,0x20,0x28,0x28,0x28, + 0x28,0x28,0x28,0x28,0x28,0x73,0x68,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a, + 0x20,0x30,0x2e,0x32,0x38,0x32,0x30,0x39,0x34,0x38,0x30,0x36,0x34,0x33,0x32,0x37, + 0x32,0x33,0x39,0x39,0x39,0x30,0x32,0x33,0x34,0x33,0x37,0x35,0x66,0x29,0x20,0x2b, + 0x20,0x28,0x73,0x68,0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28, + 0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33, + 0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e, + 0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x32,0x5d,0x2e,0x78, + 0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31, + 0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x66, + 0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b, + 0x33,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38, + 0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35, + 0x34,0x36,0x38,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x29,0x29, + 0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x34,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, + 0x28,0x28,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30, + 0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x66,0x20,0x2a,0x20,0x4e, + 0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28, + 0x73,0x68,0x5b,0x35,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d, + 0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31, + 0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e, + 0x79,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73, + 0x68,0x5b,0x36,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x33,0x31, + 0x35,0x33,0x39,0x31,0x35,0x37,0x30,0x33,0x32,0x39,0x36,0x36,0x36,0x31,0x33,0x37, + 0x36,0x39,0x35,0x33,0x31,0x32,0x35,0x66,0x20,0x2a,0x20,0x28,0x28,0x28,0x33,0x2e, + 0x30,0x66,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29, + 0x20,0x2d,0x20,0x31,0x2e,0x30,0x66,0x29,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73, + 0x68,0x5b,0x37,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31, + 0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37, + 0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78, + 0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68, + 0x5b,0x38,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x35,0x34,0x36, + 0x32,0x37,0x34,0x32,0x34,0x34,0x37,0x38,0x35,0x33,0x30,0x38,0x38,0x33,0x37,0x38, + 0x39,0x30,0x36,0x32,0x35,0x66,0x20,0x2a,0x20,0x28,0x28,0x4e,0x2e,0x78,0x20,0x2a, + 0x20,0x4e,0x2e,0x78,0x29,0x20,0x2d,0x20,0x28,0x4e,0x2e,0x79,0x20,0x2a,0x20,0x4e, + 0x2e,0x79,0x29,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x5f,0x33,0x39,0x39,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62, + 0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c, + 0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68, + 0x6e,0x65,0x73,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x5b, + 0x39,0x5d,0x2c,0x20,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x43,0x75,0x62,0x65,0x3c, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63, + 0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74, + 0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62, + 0x65,0x2c,0x20,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75, + 0x74,0x5f,0x31,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74, + 0x65,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x30, + 0x36,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x64,0x6f,0x74,0x28,0x4e,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c, + 0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37, + 0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31, + 0x38,0x38,0x65,0x2d,0x30,0x35,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x34,0x31,0x36,0x20, + 0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39, + 0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34, + 0x30,0x36,0x32,0x35,0x66,0x2e,0x78,0x78,0x78,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2e, + 0x78,0x78,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x5b,0x39,0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x34,0x38,0x32,0x20,0x3d,0x20, + 0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2e,0x53, + 0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, + 0x75,0x74,0x5f,0x31,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x34,0x30, + 0x36,0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28, + 0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x20,0x2d,0x20,0x28,0x5f,0x34,0x31,0x36, + 0x20,0x2b,0x20,0x28,0x28,0x6d,0x61,0x78,0x28,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d, + 0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x2e,0x78,0x78,0x78,0x2c, + 0x20,0x5f,0x34,0x31,0x36,0x29,0x20,0x2d,0x20,0x5f,0x34,0x31,0x36,0x29,0x20,0x2a, + 0x20,0x70,0x6f,0x77,0x28,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31, + 0x2e,0x30,0x66,0x20,0x2d,0x20,0x5f,0x34,0x30,0x36,0x29,0x2c,0x20,0x35,0x2e,0x30, + 0x66,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73, + 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x6d,0x61,0x78,0x28,0x70, + 0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61, + 0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78, + 0x29,0x29,0x20,0x2a,0x20,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33, + 0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35, + 0x66,0x2e,0x78,0x78,0x78,0x29,0x20,0x2b,0x20,0x28,0x74,0x65,0x78,0x5f,0x73,0x70, + 0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x4c,0x65, + 0x76,0x65,0x6c,0x28,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62, + 0x65,0x2c,0x20,0x72,0x65,0x66,0x6c,0x65,0x63,0x74,0x28,0x2d,0x56,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x2c,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x72, + 0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x20,0x2a,0x20,0x6d,0x61,0x78,0x5f,0x6c, + 0x6f,0x64,0x29,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x34,0x31,0x36, + 0x20,0x2a,0x20,0x5f,0x34,0x38,0x32,0x2e,0x78,0x29,0x20,0x2b,0x20,0x5f,0x34,0x38, + 0x32,0x2e,0x79,0x2e,0x78,0x78,0x78,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65, + 0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x62,0x6f,0x6f,0x6c,0x20,0x69,0x62,0x6c, + 0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x2c,0x20, + 0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x43,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62, + 0x65,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20, + 0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x54, + 0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e, + 0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c, + 0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d, + 0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x72,0x65,0x73,0x75,0x6c,0x74, + 0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20, + 0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65, + 0x64,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20, + 0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20, + 0x3d,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e, + 0x65,0x73,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x5b,0x39,0x5d,0x20,0x3d, + 0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x61,0x78, + 0x5f,0x6c,0x6f,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65, + 0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61, + 0x74,0x65,0x49,0x62,0x6c,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x70, + 0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65, + 0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66, + 0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66, + 0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f, + 0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x38,0x39,0x36, + 0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x76,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d, + 0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73, + 0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x5f,0x39,0x30,0x37,0x20,0x3d,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f, + 0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x2a,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66, + 0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x5f,0x39,0x30,0x38,0x20,0x3d,0x20,0x76,0x5f,0x63,0x65,0x6e, + 0x74,0x65,0x72,0x20,0x2d,0x20,0x5f,0x39,0x30,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x39,0x31,0x34,0x20,0x3d,0x20,0x76,0x5f, + 0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x2b,0x20,0x5f,0x39,0x30,0x37,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x39,0x31,0x38,0x20,0x3d, + 0x20,0x5f,0x39,0x31,0x34,0x20,0x2d,0x20,0x5f,0x39,0x30,0x38,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x39,0x32,0x32,0x20,0x3d,0x20, + 0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e, + 0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x39,0x30,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x32,0x36,0x20,0x3d,0x20,0x64,0x6f,0x74, + 0x28,0x5f,0x39,0x31,0x38,0x2c,0x20,0x5f,0x39,0x31,0x38,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x33,0x30,0x20,0x3d,0x20,0x64, + 0x6f,0x74,0x28,0x5f,0x39,0x31,0x38,0x2c,0x20,0x5f,0x38,0x39,0x36,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x33,0x34,0x20,0x3d, + 0x20,0x64,0x6f,0x74,0x28,0x5f,0x39,0x31,0x38,0x2c,0x20,0x5f,0x39,0x32,0x32,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x34,0x32, + 0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x39,0x32,0x32,0x2c,0x20,0x5f,0x39,0x32, + 0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39, + 0x34,0x38,0x20,0x3d,0x20,0x5f,0x39,0x32,0x36,0x20,0x2d,0x20,0x28,0x5f,0x39,0x33, + 0x30,0x20,0x2a,0x20,0x5f,0x39,0x33,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x35,0x36,0x20,0x3d,0x20,0x28,0x5f,0x39,0x32, + 0x36,0x20,0x2a,0x20,0x64,0x6f,0x74,0x28,0x5f,0x38,0x39,0x36,0x2c,0x20,0x5f,0x39, + 0x32,0x32,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f,0x39,0x33,0x34,0x20,0x2a,0x20,0x5f, + 0x39,0x33,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x39,0x36,0x38,0x20,0x3d,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20, + 0x2a,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x37,0x39,0x20,0x3d,0x20,0x28,0x5f,0x39, + 0x35,0x36,0x20,0x2a,0x20,0x5f,0x39,0x35,0x36,0x29,0x20,0x2d,0x20,0x28,0x5f,0x39, + 0x34,0x38,0x20,0x2a,0x20,0x28,0x28,0x28,0x5f,0x39,0x32,0x36,0x20,0x2a,0x20,0x5f, + 0x39,0x34,0x32,0x29,0x20,0x2d,0x20,0x28,0x5f,0x39,0x33,0x34,0x20,0x2a,0x20,0x5f, + 0x39,0x33,0x34,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f,0x39,0x36,0x38,0x20,0x2a,0x20, + 0x5f,0x39,0x32,0x36,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x5f,0x31,0x30,0x30,0x30,0x20,0x3d,0x20,0x5f,0x39,0x30,0x38, + 0x20,0x2b,0x20,0x28,0x5f,0x39,0x31,0x38,0x20,0x2a,0x20,0x63,0x6c,0x61,0x6d,0x70, + 0x28,0x28,0x5f,0x39,0x33,0x34,0x20,0x2d,0x20,0x28,0x28,0x5f,0x39,0x35,0x36,0x20, + 0x2f,0x20,0x6d,0x61,0x78,0x28,0x5f,0x39,0x34,0x38,0x2c,0x20,0x39,0x2e,0x39,0x39, + 0x39,0x39,0x39,0x39,0x39,0x33,0x39,0x32,0x32,0x35,0x32,0x39,0x30,0x32,0x39,0x30, + 0x37,0x37,0x38,0x35,0x30,0x32,0x38,0x32,0x31,0x39,0x32,0x32,0x33,0x65,0x2d,0x30, + 0x39,0x66,0x29,0x29,0x20,0x2a,0x20,0x5f,0x39,0x33,0x30,0x29,0x29,0x20,0x2f,0x20, + 0x5f,0x39,0x32,0x36,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f, + 0x31,0x30,0x30,0x34,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x6d,0x65, + 0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x31,0x30, + 0x30,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x30,0x30,0x38,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x30,0x30,0x34,0x2c, + 0x20,0x5f,0x38,0x39,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x31,0x30,0x32,0x32,0x20,0x3d,0x20,0x73,0x71,0x72,0x74,0x28,0x6d, + 0x61,0x78,0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x30, + 0x30,0x34,0x2c,0x20,0x5f,0x31,0x30,0x30,0x34,0x29,0x20,0x2d,0x20,0x28,0x5f,0x31, + 0x30,0x30,0x38,0x20,0x2a,0x20,0x5f,0x31,0x30,0x30,0x38,0x29,0x29,0x29,0x20,0x2d, + 0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x32,0x35,0x20,0x3d,0x20,0x66,0x77,0x69, + 0x64,0x74,0x68,0x28,0x5f,0x31,0x30,0x32,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x32,0x37,0x20,0x3d,0x20,0x6d,0x61, + 0x78,0x28,0x5f,0x31,0x30,0x32,0x35,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39, + 0x39,0x39,0x37,0x34,0x37,0x35,0x32,0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38,0x33, + 0x35,0x31,0x32,0x31,0x31,0x35,0x34,0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x66,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x33, + 0x34,0x20,0x3d,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74, + 0x68,0x73,0x74,0x65,0x70,0x28,0x2d,0x5f,0x31,0x30,0x32,0x37,0x2c,0x20,0x5f,0x31, + 0x30,0x32,0x37,0x2c,0x20,0x5f,0x31,0x30,0x32,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x74,0x20,0x3d,0x20,0x2d,0x31,0x2e,0x30,0x66, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x6e,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x5f,0x39,0x37,0x39,0x20,0x3e, + 0x3d,0x20,0x30,0x2e,0x30,0x66,0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x39,0x34,0x38, + 0x20,0x3e,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x33,0x39,0x32,0x32, + 0x35,0x32,0x39,0x30,0x32,0x39,0x30,0x37,0x37,0x38,0x35,0x30,0x32,0x38,0x32,0x31, + 0x39,0x32,0x32,0x33,0x65,0x2d,0x30,0x39,0x66,0x29,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x30,0x35,0x32,0x20,0x3d,0x20,0x28,0x28,0x2d,0x5f,0x39,0x35,0x36,0x29, + 0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x39,0x37,0x39,0x29,0x29,0x20,0x2f, + 0x20,0x5f,0x39,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x38,0x20,0x3d,0x20,0x5f,0x39,0x33, + 0x34,0x20,0x2b,0x20,0x28,0x5f,0x31,0x30,0x35,0x32,0x20,0x2a,0x20,0x5f,0x39,0x33, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x28,0x28,0x5f,0x31,0x30,0x35,0x32,0x20,0x3e,0x20,0x30,0x2e,0x30,0x66,0x29,0x20, + 0x26,0x26,0x20,0x28,0x5f,0x31,0x30,0x35,0x38,0x20,0x3e,0x20,0x30,0x2e,0x30,0x66, + 0x29,0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x31,0x30,0x35,0x38,0x20,0x3c,0x20,0x5f, + 0x39,0x32,0x36,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x20,0x3d,0x20,0x28,0x28,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x6d, + 0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f, + 0x38,0x39,0x36,0x20,0x2a,0x20,0x5f,0x31,0x30,0x35,0x32,0x29,0x29,0x20,0x2d,0x20, + 0x28,0x5f,0x39,0x30,0x38,0x20,0x2b,0x20,0x28,0x5f,0x39,0x31,0x38,0x20,0x2a,0x20, + 0x28,0x5f,0x31,0x30,0x35,0x38,0x20,0x2f,0x20,0x5f,0x39,0x32,0x36,0x29,0x29,0x29, + 0x29,0x20,0x2f,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x2e,0x78,0x78,0x78, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x20, + 0x3d,0x20,0x5f,0x31,0x30,0x35,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x30,0x39,0x38,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f, + 0x39,0x32,0x32,0x2c,0x20,0x5f,0x38,0x39,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x31,0x32,0x20,0x3d,0x20,0x28,0x5f, + 0x31,0x30,0x39,0x38,0x20,0x2a,0x20,0x5f,0x31,0x30,0x39,0x38,0x29,0x20,0x2d,0x20, + 0x28,0x5f,0x39,0x34,0x32,0x20,0x2d,0x20,0x5f,0x39,0x36,0x38,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x31,0x32,0x20,0x3e,0x3d,0x20, + 0x30,0x2e,0x30,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x32,0x32,0x20, + 0x3d,0x20,0x28,0x2d,0x5f,0x31,0x30,0x39,0x38,0x29,0x20,0x2d,0x20,0x73,0x71,0x72, + 0x74,0x28,0x5f,0x31,0x31,0x31,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x32,0x34,0x20,0x3d,0x20,0x5f, + 0x31,0x31,0x32,0x32,0x20,0x3e,0x20,0x30,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x33,0x33,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31, + 0x32,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x33,0x33,0x20, + 0x3d,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x29,0x20,0x7c,0x7c,0x20, + 0x28,0x5f,0x31,0x31,0x32,0x32,0x20,0x3c,0x20,0x74,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65, + 0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x33,0x33,0x20, + 0x3d,0x20,0x5f,0x31,0x31,0x32,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, + 0x31,0x31,0x33,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x5f,0x31,0x31,0x34,0x34,0x20,0x3d,0x20,0x28,0x5f,0x37,0x30,0x37, + 0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20, + 0x2b,0x20,0x28,0x5f,0x38,0x39,0x36,0x20,0x2a,0x20,0x5f,0x31,0x31,0x32,0x32,0x29, + 0x29,0x20,0x2d,0x20,0x5f,0x39,0x30,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31, + 0x31,0x34,0x34,0x2c,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x29,0x20,0x3c,0x3d,0x20,0x30,0x2e,0x30,0x66,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x20,0x3d,0x20,0x5f,0x31,0x31,0x34,0x34,0x20,0x2f,0x20,0x76,0x5f, + 0x72,0x61,0x64,0x69,0x75,0x73,0x2e,0x78,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20, + 0x5f,0x31,0x31,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x5f,0x31,0x31,0x36,0x30,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x6d, + 0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x39, + 0x31,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x31,0x36,0x34,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x31,0x36,0x30,0x2c, + 0x20,0x5f,0x38,0x39,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x31,0x31,0x37,0x38,0x20,0x3d,0x20,0x28,0x5f,0x31,0x31,0x36,0x34, + 0x20,0x2a,0x20,0x5f,0x31,0x31,0x36,0x34,0x29,0x20,0x2d,0x20,0x28,0x64,0x6f,0x74, + 0x28,0x5f,0x31,0x31,0x36,0x30,0x2c,0x20,0x5f,0x31,0x31,0x36,0x30,0x29,0x20,0x2d, + 0x20,0x5f,0x39,0x36,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x5f,0x31,0x31,0x37,0x38,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x66,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x31,0x38,0x38,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x31,0x31, + 0x36,0x34,0x29,0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x31,0x31,0x37,0x38, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20, + 0x5f,0x31,0x31,0x39,0x30,0x20,0x3d,0x20,0x5f,0x31,0x31,0x38,0x38,0x20,0x3e,0x20, + 0x30,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f, + 0x6f,0x6c,0x20,0x5f,0x31,0x31,0x39,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x39,0x30,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x5f,0x31,0x31,0x39,0x39,0x20,0x3d,0x20,0x28,0x74,0x20,0x3c,0x20, + 0x30,0x2e,0x30,0x66,0x29,0x20,0x7c,0x7c,0x20,0x28,0x5f,0x31,0x31,0x38,0x38,0x20, + 0x3c,0x20,0x74,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x5f,0x31,0x31,0x39,0x39,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x30, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x39,0x39,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x32,0x31, + 0x30,0x20,0x3d,0x20,0x28,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61, + 0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x38,0x39,0x36, + 0x20,0x2a,0x20,0x5f,0x31,0x31,0x38,0x38,0x29,0x29,0x20,0x2d,0x20,0x5f,0x39,0x31, + 0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x32,0x31,0x30,0x2c,0x20,0x76,0x5f, + 0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x20,0x3e,0x3d, + 0x20,0x30,0x2e,0x30,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x5f, + 0x31,0x32,0x31,0x30,0x20,0x2f,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x2e, + 0x78,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20,0x5f,0x31,0x31,0x38,0x38,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x32,0x38,0x20,0x3d,0x20,0x2d,0x5f,0x31,0x30, + 0x30,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20, + 0x5f,0x31,0x32,0x32,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69, + 0x7a,0x65,0x28,0x28,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f, + 0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x38,0x39,0x36,0x20, + 0x2a,0x20,0x5f,0x31,0x32,0x32,0x38,0x29,0x29,0x20,0x2d,0x20,0x5f,0x31,0x30,0x30, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x28,0x5f,0x31,0x30,0x33,0x34,0x20,0x3c,0x3d,0x20,0x30,0x2e,0x30,0x66, + 0x29,0x20,0x7c,0x7c,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x29,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x64, + 0x69,0x73,0x63,0x61,0x72,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x32,0x35,0x32,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73, + 0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x38,0x39,0x36,0x20,0x2a,0x20,0x74, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32, + 0x39,0x30,0x20,0x3d,0x20,0x28,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77, + 0x30,0x2e,0x79,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x29, + 0x20,0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x79, + 0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x79,0x29,0x29,0x20,0x2b, + 0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x79,0x20,0x2a, + 0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x30,0x37,0x20,0x3d,0x20,0x28, + 0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x7a,0x20,0x2a,0x20, + 0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x29,0x20,0x2b,0x20,0x28,0x76,0x5f, + 0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x7a,0x20,0x2a,0x20,0x6e,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x2e,0x79,0x29,0x29,0x20,0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f, + 0x74,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x7a,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x5f,0x31,0x33,0x32,0x31,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f, + 0x31,0x32,0x39,0x30,0x20,0x3e,0x20,0x30,0x2e,0x30,0x66,0x29,0x20,0x3f,0x20,0x31, + 0x2e,0x30,0x66,0x20,0x3a,0x20,0x30,0x2e,0x36,0x34,0x39,0x39,0x39,0x39,0x39,0x37, + 0x36,0x31,0x35,0x38,0x31,0x34,0x32,0x30,0x38,0x39,0x38,0x34,0x33,0x37,0x35,0x66, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33, + 0x32,0x35,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31,0x32,0x39, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x33,0x33,0x36,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31,0x33, + 0x30,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x5f,0x31,0x33,0x35,0x36,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x5f,0x31,0x33, + 0x32,0x31,0x2c,0x20,0x5f,0x31,0x33,0x32,0x31,0x20,0x2a,0x20,0x30,0x2e,0x33,0x34, + 0x39,0x39,0x39,0x39,0x39,0x39,0x34,0x30,0x33,0x39,0x35,0x33,0x35,0x35,0x32,0x32, + 0x34,0x36,0x30,0x39,0x33,0x37,0x35,0x66,0x2c,0x20,0x6d,0x61,0x78,0x28,0x31,0x2e, + 0x30,0x66,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28, + 0x30,0x2e,0x30,0x66,0x2c,0x20,0x5f,0x31,0x33,0x32,0x35,0x20,0x2a,0x20,0x31,0x2e, + 0x35,0x66,0x2c,0x20,0x61,0x62,0x73,0x28,0x5f,0x31,0x32,0x39,0x30,0x29,0x29,0x2c, + 0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74, + 0x65,0x70,0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x5f,0x31,0x33,0x33,0x36,0x20,0x2a, + 0x20,0x31,0x2e,0x35,0x66,0x2c,0x20,0x61,0x62,0x73,0x28,0x5f,0x31,0x33,0x30,0x37, + 0x29,0x29,0x29,0x2e,0x78,0x78,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x33,0x36,0x34,0x20,0x3d,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x28,0x5f,0x31,0x32,0x35,0x32,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x33, + 0x36,0x35,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x5f,0x31,0x33,0x36,0x34,0x2c,0x20, + 0x5f,0x37,0x30,0x37,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74, + 0x68,0x20,0x3d,0x20,0x5f,0x31,0x33,0x36,0x35,0x2e,0x7a,0x20,0x2f,0x20,0x5f,0x31, + 0x33,0x36,0x35,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, + 0x37,0x30,0x37,0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x31, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x39,0x37,0x20,0x3d,0x20,0x63,0x6c, + 0x61,0x6d,0x70,0x28,0x6d,0x75,0x6c,0x28,0x5f,0x31,0x33,0x36,0x34,0x2c,0x20,0x5f, + 0x37,0x30,0x37,0x5f,0x76,0x69,0x65,0x77,0x29,0x2e,0x7a,0x20,0x2a,0x20,0x28,0x2d, + 0x30,0x2e,0x30,0x31,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x35,0x35,0x32,0x39,0x36, + 0x35,0x31,0x36,0x34,0x31,0x38,0x34,0x35,0x37,0x30,0x33,0x31,0x32,0x35,0x66,0x29, + 0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x33,0x39,0x37,0x2c, + 0x20,0x5f,0x31,0x33,0x39,0x37,0x2c,0x20,0x5f,0x31,0x33,0x39,0x37,0x2c,0x20,0x31, + 0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x37,0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78, + 0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x31,0x38, + 0x20,0x3d,0x20,0x2d,0x6d,0x75,0x6c,0x28,0x5f,0x31,0x33,0x36,0x34,0x2c,0x20,0x5f, + 0x37,0x30,0x37,0x5f,0x76,0x69,0x65,0x77,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x5f,0x31,0x34,0x31,0x38,0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x34,0x31,0x38,0x20,0x3c, + 0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61, + 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31, + 0x34,0x34,0x32,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x5f,0x31,0x33,0x36,0x34,0x2c, + 0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61, + 0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x5f,0x31,0x34,0x34,0x39,0x20,0x3d,0x20,0x5f,0x31,0x34,0x34,0x32,0x2e,0x78, + 0x79,0x7a,0x20,0x2f,0x20,0x5f,0x31,0x34,0x34,0x32,0x2e,0x77,0x2e,0x78,0x78,0x78, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x5f,0x31,0x34,0x36,0x36,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, + 0x28,0x5f,0x31,0x34,0x34,0x39,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29, + 0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2c,0x20,0x28,0x28,0x5f,0x31,0x34,0x34,0x39, + 0x2e,0x79,0x20,0x2a,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20, + 0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2c,0x20, + 0x5f,0x31,0x34,0x34,0x39,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x34,0x37,0x30,0x20,0x3d,0x20,0x61, + 0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c,0x33,0x28,0x5f,0x31,0x34,0x36,0x36,0x2e,0x78, + 0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x78,0x2c,0x20,0x5f, + 0x31,0x34,0x36,0x36,0x2e,0x79,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78, + 0x78,0x2e,0x79,0x2c,0x20,0x5f,0x31,0x34,0x36,0x36,0x2e,0x7a,0x20,0x3c,0x20,0x30, + 0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x7a,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x34,0x37,0x37,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31, + 0x34,0x37,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x34,0x37,0x37, + 0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c,0x33,0x28,0x5f,0x31,0x34, + 0x36,0x36,0x2e,0x78,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e, + 0x78,0x2c,0x20,0x5f,0x31,0x34,0x36,0x36,0x2e,0x79,0x20,0x3e,0x20,0x31,0x2e,0x30, + 0x66,0x2e,0x78,0x78,0x78,0x2e,0x79,0x2c,0x20,0x5f,0x31,0x34,0x36,0x36,0x2e,0x7a, + 0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x7a,0x29,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31, + 0x34,0x37,0x37,0x20,0x3d,0x20,0x5f,0x31,0x34,0x37,0x30,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x31,0x2e,0x30, + 0x66,0x2e,0x78,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x21,0x5f,0x31,0x34,0x37,0x37,0x29,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20, + 0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31, + 0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35, + 0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35, + 0x66,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36, + 0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x31,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35, + 0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35, + 0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30, + 0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39, + 0x30,0x36,0x32,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36, + 0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x2c, + 0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34, + 0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x2c,0x20,0x31, + 0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x74,0x69,0x6e,0x74,0x2c, + 0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x37,0x5f,0x66,0x6c,0x61,0x67,0x73, + 0x2e,0x78,0x20,0x3d,0x3d,0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x69,0x7a,0x65,0x28,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, + 0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x2c,0x20, + 0x5f,0x37,0x30,0x37,0x5f,0x76,0x69,0x65,0x77,0x29,0x2e,0x78,0x79,0x7a,0x29,0x20, + 0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2e,0x78, + 0x78,0x78,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x5f,0x31,0x35,0x33,0x39,0x5f, + 0x64,0x75,0x6d,0x6d,0x79,0x5f,0x70,0x61,0x72,0x61,0x6d,0x65,0x74,0x65,0x72,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x35,0x34, + 0x37,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e,0x53,0x61,0x6d,0x70,0x6c, + 0x65,0x4c,0x65,0x76,0x65,0x6c,0x28,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20,0x67, + 0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x20,0x2f, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x69,0x6e,0x74,0x32,0x28,0x73,0x70,0x76, + 0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x74,0x65,0x78,0x5f, + 0x61,0x6f,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x30,0x29,0x2c,0x20,0x5f,0x31,0x35, + 0x33,0x39,0x5f,0x64,0x75,0x6d,0x6d,0x79,0x5f,0x70,0x61,0x72,0x61,0x6d,0x65,0x74, + 0x65,0x72,0x29,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x34,0x38,0x20,0x3d,0x20, + 0x5f,0x31,0x35,0x34,0x37,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x5f,0x37,0x30,0x37,0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d, + 0x20,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x35,0x34,0x38,0x2c,0x20,0x5f,0x31,0x35,0x34, + 0x38,0x2c,0x20,0x5f,0x31,0x35,0x34,0x38,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f,0x31,0x32,0x35,0x32,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x20,0x3d,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x20,0x3d,0x20,0x2d,0x6d,0x75,0x6c,0x28,0x5f,0x31,0x33,0x36,0x34,0x2c,0x20,0x5f, + 0x37,0x30,0x37,0x5f,0x76,0x69,0x65,0x77,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x35,0x39,0x36,0x20,0x3d,0x20, + 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37,0x30,0x37,0x5f,0x63, + 0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20, + 0x5f,0x31,0x32,0x35,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x6e,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x31,0x35,0x39,0x36, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65, + 0x28,0x5f,0x37,0x30,0x37,0x5f,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x37,0x5f,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79, + 0x7a,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77, + 0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x5f,0x31,0x33,0x35,0x36,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38, + 0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x39,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e, + 0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x69,0x62,0x6c,0x5f, + 0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x20,0x3e,0x20,0x30,0x2e,0x35,0x66,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x32,0x20,0x3d,0x20,0x5f,0x31,0x35,0x39,0x36,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33, + 0x20,0x3d,0x20,0x5f,0x31,0x33,0x35,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x76, + 0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20, + 0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x36,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x73,0x75,0x6e,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x39,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x30,0x5d,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x5f,0x73,0x68,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x31,0x5d,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x37,0x5f,0x73,0x68,0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x32,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30, + 0x37,0x5f,0x73,0x68,0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x37,0x5b,0x33,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f, + 0x73,0x68,0x5b,0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x37,0x5b,0x34,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x73,0x68, + 0x5b,0x34,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x37,0x5b,0x35,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x73,0x68,0x5b,0x35, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b, + 0x36,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x73,0x68,0x5b,0x36,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x37,0x5d, + 0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x73,0x68,0x5b,0x37,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x38,0x5d,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x5f,0x73,0x68,0x5b,0x38,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20, + 0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d, + 0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x36,0x37,0x35,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x2e,0x77,0x20,0x2a,0x20,0x5f,0x31,0x30,0x33,0x34,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c, + 0x75,0x61,0x74,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x39,0x29,0x20,0x2b,0x20,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61, + 0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20,0x74,0x65,0x78,0x5f,0x69,0x62, + 0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f, + 0x73,0x70,0x65,0x63,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, + 0x75,0x74,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x29,0x20,0x2a,0x20,0x5f,0x31, + 0x35,0x34,0x38,0x29,0x29,0x20,0x2a,0x20,0x5f,0x31,0x36,0x37,0x35,0x2c,0x20,0x5f, + 0x31,0x36,0x37,0x35,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f, + 0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69, + 0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e, + 0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f, + 0x6f,0x72,0x64,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75, + 0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64, + 0x2e,0x77,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2f,0x20,0x67,0x6c,0x5f,0x46,0x72, + 0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79, + 0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70, + 0x75,0x74,0x2e,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20, + 0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f, + 0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x68,0x61, + 0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x20,0x3d,0x20,0x73,0x74,0x61,0x67, + 0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c, + 0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x61,0x64, + 0x69,0x75,0x73,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75, + 0x74,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x20,0x3d,0x20,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72, + 0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72, + 0x6f,0x77,0x31,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75, + 0x74,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x20,0x3d,0x20,0x73, + 0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x72,0x6f,0x74, + 0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x62,0x61,0x73, + 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f, + 0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69, + 0x61,0x6c,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74, + 0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75, + 0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75, + 0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74, + 0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68, + 0x20,0x3d,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75, + 0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x6f,0x75, + 0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74, + 0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + struct instance + { + float4 xform_row0; + float4 xform_row1; + float4 xform_row2; + float4 base_color; + float4 params; + float4 material; + }; + + struct instances + { + instance items[1]; + }; + + struct ub_draw + { + int4 inst_base; + }; + + struct ub_frame + { + float4x4 view_proj; + }; + + struct main0_out + { + float3 v_world_pos_proxy [[user(locn0)]]; + float3 v_center [[user(locn1)]]; + float v_half_length [[user(locn2)]]; + float v_radius [[user(locn3)]]; + float3 v_axis_x_world [[user(locn4)]]; + float3 v_rot_row0 [[user(locn5)]]; + float3 v_rot_row1 [[user(locn6)]]; + float3 v_rot_row2 [[user(locn7)]]; + float4 v_base_color [[user(locn8)]]; + float4 v_material [[user(locn9)]]; + float4 gl_Position [[position]]; + }; + + struct main0_in + { + float3 in_pos [[attribute(0)]]; + }; + + vertex main0_out main0(main0_in in [[stage_in]], constant ub_frame& _158 [[buffer(0)]], constant ub_draw& _21 [[buffer(2)]], const device instances& _15 [[buffer(8)]], uint gl_InstanceIndex [[instance_id]]) + { + main0_out out = {}; + int _30 = _21.inst_base.x + int(gl_InstanceIndex); + float3 _63 = float3(_15.items[_30].xform_row0.w, _15.items[_30].xform_row1.w, _15.items[_30].xform_row2.w); + float3 _94 = float3((in.in_pos.x * 2.0) * (_15.items[_30].params.x + _15.items[_30].params.y), (in.in_pos.y * 2.0) * _15.items[_30].params.y, (in.in_pos.z * 2.0) * _15.items[_30].params.y); + float3 _113 = _63 + float3(dot(_15.items[_30].xform_row0.xyz, _94), dot(_15.items[_30].xform_row1.xyz, _94), dot(_15.items[_30].xform_row2.xyz, _94)); + out.v_world_pos_proxy = _113; + out.v_center = _63; + out.v_half_length = _15.items[_30].params.x; + out.v_radius = _15.items[_30].params.y; + out.v_axis_x_world = float3(_15.items[_30].xform_row0.x, _15.items[_30].xform_row1.x, _15.items[_30].xform_row2.x); + out.v_rot_row0 = _15.items[_30].xform_row0.xyz; + out.v_rot_row1 = _15.items[_30].xform_row1.xyz; + out.v_rot_row2 = _15.items[_30].xform_row2.xyz; + out.v_base_color = _15.items[_30].base_color; + out.v_material = _15.items[_30].material; + out.gl_Position = _158.view_proj * float4(_113, 1.0); + return out; + } + +*/ +static const uint8_t capsule_vs_source_metal_macos[2227] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x20,0x69,0x74,0x65,0x6d,0x73,0x5b,0x31,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a, + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x34,0x20,0x69,0x6e,0x73,0x74,0x5f,0x62, + 0x61,0x73,0x65,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20, + 0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f, + 0x6a,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61, + 0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, + 0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f, + 0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x5b,0x5b,0x75,0x73, + 0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65, + 0x6e,0x67,0x74,0x68,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e, + 0x32,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28, + 0x6c,0x6f,0x63,0x6e,0x33,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x34, + 0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x20,0x5b,0x5b,0x75,0x73,0x65, + 0x72,0x28,0x6c,0x6f,0x63,0x6e,0x35,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77, + 0x31,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x36,0x29,0x5d, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f, + 0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28, + 0x6c,0x6f,0x63,0x6e,0x37,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x38,0x29,0x5d, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f, + 0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28, + 0x6c,0x6f,0x63,0x6e,0x39,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e, + 0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x3b,0x0a,0x7d, + 0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f, + 0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x5b,0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75, + 0x74,0x65,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x65,0x72, + 0x74,0x65,0x78,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61, + 0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20, + 0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x26, + 0x20,0x5f,0x31,0x35,0x38,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x30, + 0x29,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62, + 0x5f,0x64,0x72,0x61,0x77,0x26,0x20,0x5f,0x32,0x31,0x20,0x5b,0x5b,0x62,0x75,0x66, + 0x66,0x65,0x72,0x28,0x32,0x29,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, + 0x64,0x65,0x76,0x69,0x63,0x65,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73, + 0x26,0x20,0x5f,0x31,0x35,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x38, + 0x29,0x5d,0x5d,0x2c,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73, + 0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x5b,0x5b,0x69,0x6e,0x73, + 0x74,0x61,0x6e,0x63,0x65,0x5f,0x69,0x64,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20, + 0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x33, + 0x30,0x20,0x3d,0x20,0x5f,0x32,0x31,0x2e,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73, + 0x65,0x2e,0x78,0x20,0x2b,0x20,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73, + 0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x36,0x33,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f, + 0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77, + 0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d, + 0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f, + 0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x39,0x34,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x28,0x28,0x69,0x6e,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x2e, + 0x78,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x20,0x2a,0x20,0x28,0x5f,0x31,0x35,0x2e, + 0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d, + 0x73,0x2e,0x78,0x20,0x2b,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b, + 0x5f,0x33,0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x29,0x2c,0x20, + 0x28,0x69,0x6e,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x2e,0x79,0x20,0x2a,0x20,0x32, + 0x2e,0x30,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b, + 0x5f,0x33,0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x2c,0x20,0x28, + 0x69,0x6e,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x2e,0x7a,0x20,0x2a,0x20,0x32,0x2e, + 0x30,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f, + 0x33,0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x31,0x33,0x20,0x3d, + 0x20,0x5f,0x36,0x33,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x64,0x6f, + 0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d, + 0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x78,0x79,0x7a,0x2c, + 0x20,0x5f,0x39,0x34,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69, + 0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f, + 0x72,0x6f,0x77,0x31,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x39,0x34,0x29,0x2c,0x20, + 0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33, + 0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x78,0x79, + 0x7a,0x2c,0x20,0x5f,0x39,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75, + 0x74,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72, + 0x6f,0x78,0x79,0x20,0x3d,0x20,0x5f,0x31,0x31,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x6f,0x75,0x74,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3d,0x20,0x5f, + 0x36,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x68,0x61, + 0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e, + 0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d, + 0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x72, + 0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d, + 0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f, + 0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e, + 0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x78,0x2c,0x20,0x5f,0x31, + 0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69, + 0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f, + 0x72,0x6f,0x77,0x32,0x2e,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, + 0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x20,0x3d,0x20,0x5f,0x31, + 0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x20, + 0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d, + 0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x79,0x7a,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72, + 0x6f,0x77,0x32,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b, + 0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e, + 0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x62, + 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e, + 0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x62,0x61,0x73,0x65,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76, + 0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e, + 0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x6d,0x61,0x74,0x65,0x72, + 0x69,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f, + 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x5f,0x31,0x35,0x38,0x2e, + 0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x28,0x5f,0x31,0x31,0x33,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x00, +}; +/* + #pragma clang diagnostic ignored "-Wmissing-prototypes" + #pragma clang diagnostic ignored "-Wmissing-braces" + + #include + #include + + using namespace metal; + + template + struct spvUnsafeArray + { + T elements[Num ? Num : 1]; + + thread T& operator [] (size_t pos) thread + { + return elements[pos]; + } + constexpr const thread T& operator [] (size_t pos) const thread + { + return elements[pos]; + } + + device T& operator [] (size_t pos) device + { + return elements[pos]; + } + constexpr const device T& operator [] (size_t pos) const device + { + return elements[pos]; + } + + constexpr const constant T& operator [] (size_t pos) const constant + { + return elements[pos]; + } + + threadgroup T& operator [] (size_t pos) threadgroup + { + return elements[pos]; + } + constexpr const threadgroup T& operator [] (size_t pos) const threadgroup + { + return elements[pos]; + } + }; + + struct ub_pass + { + float4 sun_dir_world; + float4 sun_color; + int4 flags; + float4 camera_pos; + float4x4 view_proj; + float4x4 view; + float4 cascade_far_view_z; + float4x4 cascade_matrices[3]; + float4 sh[9]; + float4 ibl_params; + }; + + struct main0_out + { + float4 out_color [[color(0)]]; + float gl_FragDepth [[depth(any)]]; + }; + + struct main0_in + { + float3 v_world_pos_proxy [[user(locn0)]]; + float3 v_center [[user(locn1), flat]]; + float v_half_length [[user(locn2), flat]]; + float v_radius [[user(locn3), flat]]; + float3 v_axis_x_world [[user(locn4), flat]]; + float3 v_rot_row0 [[user(locn5), flat]]; + float3 v_rot_row1 [[user(locn6), flat]]; + float3 v_rot_row2 [[user(locn7), flat]]; + float4 v_base_color [[user(locn8), flat]]; + float4 v_material [[user(locn9), flat]]; + }; + + static inline __attribute__((always_inline)) + float sampleShadowPCF(thread const int& cascade, thread const float3& light_uv, thread const float& bias0, depth2d_array tex_shadow, sampler smp_shadow) + { + float _529 = float(cascade); + float _534 = light_uv.z - bias0; + float _550 = light_uv.x - 0.00048828125; + float _554 = light_uv.y - 0.00048828125; + float4 _557 = float4(_550, _554, _529, _534); + float4 _573 = float4(light_uv.x, _554, _529, _534); + float _584 = light_uv.x + 0.00048828125; + float4 _591 = float4(_584, _554, _529, _534); + float4 _607 = float4(_550, light_uv.y, _529, _534); + float4 _621 = float4(light_uv.xy, _529, _534); + float4 _637 = float4(_584, light_uv.y, _529, _534); + float _652 = light_uv.y + 0.00048828125; + float4 _655 = float4(_550, _652, _529, _534); + float4 _671 = float4(light_uv.x, _652, _529, _534); + float4 _689 = float4(_584, _652, _529, _534); + return ((((((((tex_shadow.sample_compare(smp_shadow, _557.xy, uint(rint(_557.z)), _534) + tex_shadow.sample_compare(smp_shadow, _573.xy, uint(rint(_573.z)), _534)) + tex_shadow.sample_compare(smp_shadow, _591.xy, uint(rint(_591.z)), _534)) + tex_shadow.sample_compare(smp_shadow, _607.xy, uint(rint(_607.z)), _534)) + tex_shadow.sample_compare(smp_shadow, _621.xy, uint(rint(_621.z)), _534)) + tex_shadow.sample_compare(smp_shadow, _637.xy, uint(rint(_637.z)), _534)) + tex_shadow.sample_compare(smp_shadow, _655.xy, uint(rint(_655.z)), _534)) + tex_shadow.sample_compare(smp_shadow, _671.xy, uint(rint(_671.z)), _534)) + tex_shadow.sample_compare(smp_shadow, _689.xy, uint(rint(_689.z)), _534)) * 0.111111111938953399658203125; + } + + static inline __attribute__((always_inline)) + float sampleCascade(thread const int& cascade, thread const float3& world_pos, thread const float3& world_normal, depth2d_array tex_shadow, sampler smp_shadow, constant ub_pass& _707) + { + float4 _717 = _707.cascade_matrices[cascade] * float4(world_pos, 1.0); + float3 _724 = _717.xyz / float3(_717.w); + float3 _742 = float3((_724.x * 0.5) + 0.5, ((_724.y * _707.cascade_far_view_z.w) * 0.5) + 0.5, _724.z); + bool _746 = any(_742 < float3(0.0)); + bool _753; + if (!_746) + { + _753 = any(_742 > float3(1.0)); + } + else + { + _753 = _746; + } + if (_753) + { + return 1.0; + } + int param = cascade; + float3 param_1 = _742; + float param_2 = mix(0.0040000001899898052215576171875, 0.0007999999797903001308441162109375, fast::max(dot(world_normal, fast::normalize(_707.sun_dir_world.xyz)), 0.0)); + float pcf = sampleShadowPCF(param, param_1, param_2, tex_shadow, smp_shadow); + if (cascade == 2) + { + float2 _785 = _742.xy; + float2 _790 = fast::min(_785, float2(1.0) - _785); + pcf = mix(1.0, pcf, fast::clamp(fast::min(_790.x, _790.y) * 10.0, 0.0, 1.0)); + } + return pcf; + } + + static inline __attribute__((always_inline)) + float sampleShadowCascaded(thread const float3& world_pos, thread const float3& world_normal, thread const float& view_z, depth2d_array tex_shadow, sampler smp_shadow, constant ub_pass& _707) + { + int cascade = 2; + if (view_z < _707.cascade_far_view_z.x) + { + cascade = 0; + } + else + { + if (view_z < _707.cascade_far_view_z.y) + { + cascade = 1; + } + } + int param = cascade; + float3 param_1 = world_pos; + float3 param_2 = world_normal; + float shadow = sampleCascade(param, param_1, param_2, tex_shadow, smp_shadow, _707); + if (cascade < 2) + { + float _835; + if (cascade == 0) + { + _835 = _707.cascade_far_view_z.x; + } + else + { + _835 = _707.cascade_far_view_z.y; + } + float _847; + if (cascade == 0) + { + _847 = 0.0; + } + else + { + _847 = _707.cascade_far_view_z.x; + } + float _858 = mix(_835, _847, 0.100000001490116119384765625); + if (view_z > _858) + { + int param_3 = cascade + 1; + float3 param_4 = world_pos; + float3 param_5 = world_normal; + shadow = mix(shadow, sampleCascade(param_3, param_4, param_5, tex_shadow, smp_shadow, _707), (view_z - _858) / (_835 - _858)); + } + } + return shadow; + } + + static inline __attribute__((always_inline)) + float pbrDistributionGGX(thread const float& n_dot_h, thread const float& alpha) + { + float _107 = alpha * alpha; + float _116 = ((n_dot_h * n_dot_h) * (_107 - 1.0)) + 1.0; + return _107 / ((3.1415927410125732421875 * _116) * _116); + } + + static inline __attribute__((always_inline)) + float pbrVisibilitySmithCorrelated(thread const float& n_dot_v, thread const float& n_dot_l, thread const float& alpha) + { + float _129 = alpha * alpha; + float _136 = 1.0 - _129; + return 0.5 / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _136) + _129)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _136) + _129))) + 9.9999997473787516355514526367188e-06); + } + + static inline __attribute__((always_inline)) + float3 pbrFresnelSchlick(thread const float& v_dot_h, thread const float3& f0) + { + float _165 = 1.0 - v_dot_h; + float _169 = _165 * _165; + return f0 + ((float3(1.0) - f0) * ((_169 * _169) * _165)); + } + + static inline __attribute__((always_inline)) + float3 brdf_evaluate(thread const float3& N, thread const float3& V, thread const float3& L, thread const float3& sun_radiance, thread const float3& base_color, thread const float& metallic, thread const float& roughness) + { + float _188 = fast::max(dot(N, L), 0.0); + float3 _199 = fast::normalize(V + L); + float _213 = fast::max(roughness, 0.04500000178813934326171875); + float _217 = _213 * _213; + float param = fast::max(dot(N, _199), 0.0); + float param_1 = _217; + float param_2 = fast::max(dot(N, V), 9.9999997473787516355514526367188e-05); + float param_3 = _188; + float param_4 = _217; + float param_5 = fast::max(dot(V, _199), 0.0); + float3 param_6 = mix(float3(0.039999999105930328369140625), base_color, float3(metallic)); + float3 _244 = pbrFresnelSchlick(param_5, param_6); + return ((((((float3(1.0) - _244) * (1.0 - metallic)) * base_color) * float3(0.3183098733425140380859375)) + (_244 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _188; + } + + static inline __attribute__((always_inline)) + float3 pbrEvaluateShIrradiance(thread const float3& N, thread const spvUnsafeArray& sh) + { + float3 _399 = ((((((((sh[0].xyz * 0.2820948064327239990234375) + (sh[1].xyz * ((-0.48860251903533935546875) * N.y))) + (sh[2].xyz * (0.48860251903533935546875 * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125 * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125 * (((3.0 * N.z) * N.z) - 1.0)))) + (sh[7].xyz * (((-1.09254848957061767578125) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625 * ((N.x * N.x) - (N.y * N.y)))); + return _399; + } + + static inline __attribute__((always_inline)) + float3 pbrEvaluateIbl(thread const float3& N_world, thread const float3& V_world, thread const float3& base_color, thread const float& metallic, thread const float& roughness, thread const spvUnsafeArray& sh, texturecube tex_spec_cube, sampler smp_spec_cube, texture2d tex_brdf_lut, sampler smp_brdf_lut, thread const float& max_lod) + { + float _406 = fast::clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05, 1.0); + float3 _416 = mix(float3(0.039999999105930328369140625), base_color, float3(metallic)); + float3 param = N_world; + spvUnsafeArray param_1 = sh; + float4 _482 = tex_brdf_lut.sample(smp_brdf_lut, float2(_406, roughness)); + return (((((float3(1.0) - (_416 + ((fast::max(float3(1.0 - roughness), _416) - _416) * powr(fast::max(0.0, 1.0 - _406), 5.0)))) * (1.0 - metallic)) * base_color) * fast::max(pbrEvaluateShIrradiance(param, param_1), float3(0.0))) * float3(0.3183098733425140380859375)) + (tex_spec_cube.sample(smp_spec_cube, reflect(-V_world, N_world), level(roughness * max_lod)).xyz * ((_416 * _482.x) + float3(_482.y))); + } + + static inline __attribute__((always_inline)) + float3 pbrEvaluateAmbient(thread const bool& iblEnabled, thread const float3& N_world, thread const float3& V_world, thread const float3& base_color, thread const float& metallic, thread const float& roughness, thread const float& flat_strength, thread const spvUnsafeArray& sh, texturecube tex_spec_cube, sampler smp_spec_cube, texture2d tex_brdf_lut, sampler smp_brdf_lut, thread const float& max_lod) + { + float3 result = base_color * flat_strength; + if (iblEnabled) + { + float3 param = N_world; + float3 param_1 = V_world; + float3 param_2 = base_color; + float param_3 = metallic; + float param_4 = roughness; + spvUnsafeArray param_5 = sh; + float param_6 = max_lod; + result = pbrEvaluateIbl(param, param_1, param_2, param_3, param_4, param_5, tex_spec_cube, smp_spec_cube, tex_brdf_lut, smp_brdf_lut, param_6); + } + return result; + } + + fragment main0_out main0(main0_in in [[stage_in]], constant ub_pass& _707 [[buffer(1)]], depth2d_array tex_shadow [[texture(0)]], texturecube tex_ibl_spec [[texture(1)]], texture2d tex_brdf_lut [[texture(2)]], texture2d tex_ao [[texture(3)]], sampler smp_shadow [[sampler(0)]], sampler smp_ibl_spec [[sampler(1)]], sampler smp_brdf_lut [[sampler(2)]], sampler smp_ao [[sampler(3)]], float4 gl_FragCoord [[position]]) + { + main0_out out = {}; + float3 _896 = fast::normalize(in.v_world_pos_proxy - _707.camera_pos.xyz); + float3 _907 = in.v_axis_x_world * in.v_half_length; + float3 _908 = in.v_center - _907; + float3 _914 = in.v_center + _907; + float3 _918 = _914 - _908; + float3 _922 = _707.camera_pos.xyz - _908; + float _926 = dot(_918, _918); + float _930 = dot(_918, _896); + float _934 = dot(_918, _922); + float _942 = dot(_922, _922); + float _948 = _926 - (_930 * _930); + float _956 = (_926 * dot(_896, _922)) - (_934 * _930); + float _968 = in.v_radius * in.v_radius; + float _979 = (_956 * _956) - (_948 * (((_926 * _942) - (_934 * _934)) - (_968 * _926))); + float3 _1000 = _908 + (_918 * fast::clamp((_934 - ((_956 / fast::max(_948, 9.9999999392252902907785028219223e-09)) * _930)) / _926, 0.0, 1.0)); + float3 _1004 = _707.camera_pos.xyz - _1000; + float _1008 = dot(_1004, _896); + float _1022 = sqrt(fast::max(0.0, dot(_1004, _1004) - (_1008 * _1008))) - in.v_radius; + float _1025 = fwidth(_1022); + float _1027 = fast::max(_1025, 9.9999999747524270787835121154785e-07); + float _1034 = 1.0 - smoothstep(-_1027, _1027, _1022); + float t = -1.0; + float3 n_world = float3(0.0); + if ((_979 >= 0.0) && (_948 > 9.9999999392252902907785028219223e-09)) + { + float _1052 = ((-_956) - sqrt(_979)) / _948; + float _1058 = _934 + (_1052 * _930); + if (((_1052 > 0.0) && (_1058 > 0.0)) && (_1058 < _926)) + { + n_world = ((_707.camera_pos.xyz + (_896 * _1052)) - (_908 + (_918 * (_1058 / _926)))) / float3(in.v_radius); + t = _1052; + } + } + float _1098 = dot(_922, _896); + float _1112 = (_1098 * _1098) - (_942 - _968); + if (_1112 >= 0.0) + { + float _1122 = (-_1098) - sqrt(_1112); + bool _1124 = _1122 > 0.0; + bool _1133; + if (_1124) + { + _1133 = (t < 0.0) || (_1122 < t); + } + else + { + _1133 = _1124; + } + if (_1133) + { + float3 _1144 = (_707.camera_pos.xyz + (_896 * _1122)) - _908; + if (dot(_1144, in.v_axis_x_world) <= 0.0) + { + n_world = _1144 / float3(in.v_radius); + t = _1122; + } + } + } + float3 _1160 = _707.camera_pos.xyz - _914; + float _1164 = dot(_1160, _896); + float _1178 = (_1164 * _1164) - (dot(_1160, _1160) - _968); + if (_1178 >= 0.0) + { + float _1188 = (-_1164) - sqrt(_1178); + bool _1190 = _1188 > 0.0; + bool _1199; + if (_1190) + { + _1199 = (t < 0.0) || (_1188 < t); + } + else + { + _1199 = _1190; + } + if (_1199) + { + float3 _1210 = (_707.camera_pos.xyz + (_896 * _1188)) - _914; + if (dot(_1210, in.v_axis_x_world) >= 0.0) + { + n_world = _1210 / float3(in.v_radius); + t = _1188; + } + } + } + if (t < 0.0) + { + float _1228 = -_1008; + t = _1228; + n_world = fast::normalize((_707.camera_pos.xyz + (_896 * _1228)) - _1000); + } + if ((_1034 <= 0.0) || (t < 0.0)) + { + discard_fragment(); + } + float3 _1252 = _707.camera_pos.xyz + (_896 * t); + float _1290 = ((in.v_rot_row0.y * n_world.x) + (in.v_rot_row1.y * n_world.y)) + (in.v_rot_row2.y * n_world.z); + float _1307 = ((in.v_rot_row0.z * n_world.x) + (in.v_rot_row1.z * n_world.y)) + (in.v_rot_row2.z * n_world.z); + float3 _1321 = in.v_base_color.xyz * ((_1290 > 0.0) ? 1.0 : 0.64999997615814208984375); + float _1325 = fwidth(_1290); + float _1336 = fwidth(_1307); + float3 _1356 = mix(_1321, _1321 * 0.3499999940395355224609375, float3(fast::max(1.0 - smoothstep(0.0, _1325 * 1.5, abs(_1290)), 1.0 - smoothstep(0.0, _1336 * 1.5, abs(_1307))))); + float4 _1364 = float4(_1252, 1.0); + float4 _1365 = _707.view_proj * _1364; + out.gl_FragDepth = _1365.z / _1365.w; + if (_707.flags.x == 1) + { + float _1397 = fast::clamp((_707.view * _1364).z * (-0.0199999995529651641845703125), 0.0, 1.0); + out.out_color = float4(_1397, _1397, _1397, 1.0); + return out; + } + if (_707.flags.x == 2) + { + float _1418 = -(_707.view * _1364).z; + int cascade = 2; + if (_1418 < _707.cascade_far_view_z.x) + { + cascade = 0; + } + else + { + if (_1418 < _707.cascade_far_view_z.y) + { + cascade = 1; + } + } + float4 _1442 = _707.cascade_matrices[cascade] * _1364; + float3 _1449 = _1442.xyz / float3(_1442.w); + float3 _1466 = float3((_1449.x * 0.5) + 0.5, ((_1449.y * _707.cascade_far_view_z.w) * 0.5) + 0.5, _1449.z); + bool _1470 = any(_1466 < float3(0.0)); + bool _1477; + if (!_1470) + { + _1477 = any(_1466 > float3(1.0)); + } + else + { + _1477 = _1470; + } + float3 tint = float3(1.0); + if (!_1477) + { + if (cascade == 0) + { + tint = float3(1.0, 0.4000000059604644775390625, 0.4000000059604644775390625); + } + else + { + if (cascade == 1) + { + tint = float3(0.4000000059604644775390625, 1.0, 0.4000000059604644775390625); + } + else + { + tint = float3(0.4000000059604644775390625, 0.4000000059604644775390625, 1.0); + } + } + } + out.out_color = float4(tint, 1.0); + return out; + } + if (_707.flags.x == 3) + { + out.out_color = float4((fast::normalize((_707.view * float4(n_world, 0.0)).xyz) * 0.5) + float3(0.5), 1.0); + return out; + } + float4 _1547 = tex_ao.sample(smp_ao, (gl_FragCoord.xy / float2(int2(tex_ao.get_width(), tex_ao.get_height()))), level(0.0)); + float _1548 = _1547.x; + if (_707.flags.x == 4) + { + out.out_color = float4(_1548, _1548, _1548, 1.0); + return out; + } + float3 param = _1252; + float3 param_1 = n_world; + float param_2 = -(_707.view * _1364).z; + float3 _1596 = fast::normalize(_707.camera_pos.xyz - _1252); + float3 param_3 = n_world; + float3 param_4 = _1596; + float3 param_5 = fast::normalize(_707.sun_dir_world.xyz); + float3 param_6 = _707.sun_color.xyz * sampleShadowCascaded(param, param_1, param_2, tex_shadow, smp_shadow, _707); + float3 param_7 = _1356; + float param_8 = in.v_material.x; + float param_9 = in.v_material.y; + bool param_10 = _707.ibl_params.y > 0.5; + float3 param_11 = n_world; + float3 param_12 = _1596; + float3 param_13 = _1356; + float param_14 = in.v_material.x; + float param_15 = in.v_material.y; + float param_16 = _707.sun_color.w; + spvUnsafeArray param_17; + param_17[0] = _707.sh[0]; + param_17[1] = _707.sh[1]; + param_17[2] = _707.sh[2]; + param_17[3] = _707.sh[3]; + param_17[4] = _707.sh[4]; + param_17[5] = _707.sh[5]; + param_17[6] = _707.sh[6]; + param_17[7] = _707.sh[7]; + param_17[8] = _707.sh[8]; + float param_18 = _707.ibl_params.x; + float _1675 = in.v_base_color.w * _1034; + out.out_color = float4((brdf_evaluate(param_3, param_4, param_5, param_6, param_7, param_8, param_9) + (pbrEvaluateAmbient(param_10, param_11, param_12, param_13, param_14, param_15, param_16, param_17, tex_ibl_spec, smp_ibl_spec, tex_brdf_lut, smp_brdf_lut, param_18) * _1548)) * _1675, _1675); + return out; + } + +*/ +static const uint8_t capsule_fs_source_metal_macos[19080] = { + 0x23,0x70,0x72,0x61,0x67,0x6d,0x61,0x20,0x63,0x6c,0x61,0x6e,0x67,0x20,0x64,0x69, + 0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x20,0x69,0x67,0x6e,0x6f,0x72,0x65,0x64, + 0x20,0x22,0x2d,0x57,0x6d,0x69,0x73,0x73,0x69,0x6e,0x67,0x2d,0x70,0x72,0x6f,0x74, + 0x6f,0x74,0x79,0x70,0x65,0x73,0x22,0x0a,0x23,0x70,0x72,0x61,0x67,0x6d,0x61,0x20, + 0x63,0x6c,0x61,0x6e,0x67,0x20,0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63, + 0x20,0x69,0x67,0x6e,0x6f,0x72,0x65,0x64,0x20,0x22,0x2d,0x57,0x6d,0x69,0x73,0x73, + 0x69,0x6e,0x67,0x2d,0x62,0x72,0x61,0x63,0x65,0x73,0x22,0x0a,0x0a,0x23,0x69,0x6e, + 0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f,0x73,0x74,0x64, + 0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x73, + 0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a,0x75,0x73,0x69, + 0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20,0x6d,0x65,0x74, + 0x61,0x6c,0x3b,0x0a,0x0a,0x74,0x65,0x6d,0x70,0x6c,0x61,0x74,0x65,0x3c,0x74,0x79, + 0x70,0x65,0x6e,0x61,0x6d,0x65,0x20,0x54,0x2c,0x20,0x73,0x69,0x7a,0x65,0x5f,0x74, + 0x20,0x4e,0x75,0x6d,0x3e,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x73,0x70,0x76, + 0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x54,0x20,0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x4e,0x75,0x6d, + 0x20,0x3f,0x20,0x4e,0x75,0x6d,0x20,0x3a,0x20,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x0a,0x20,0x20,0x20,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x54,0x26,0x20, + 0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72,0x20,0x5b,0x5d,0x20,0x28,0x73,0x69,0x7a, + 0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f, + 0x73,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x65,0x78,0x70,0x72,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x74,0x68, + 0x72,0x65,0x61,0x64,0x20,0x54,0x26,0x20,0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72, + 0x20,0x5b,0x5d,0x20,0x28,0x73,0x69,0x7a,0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f,0x73,0x5d, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x0a,0x20,0x20,0x20, + 0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x20,0x54,0x26,0x20,0x6f,0x70,0x65,0x72,0x61, + 0x74,0x6f,0x72,0x20,0x5b,0x5d,0x20,0x28,0x73,0x69,0x7a,0x65,0x5f,0x74,0x20,0x70, + 0x6f,0x73,0x29,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f,0x73,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6e,0x73,0x74,0x65,0x78, + 0x70,0x72,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x20, + 0x54,0x26,0x20,0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72,0x20,0x5b,0x5d,0x20,0x28, + 0x73,0x69,0x7a,0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x65,0x6c, + 0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f,0x73,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x65,0x78,0x70,0x72,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x61,0x6e,0x74,0x20,0x54,0x26,0x20,0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72, + 0x20,0x5b,0x5d,0x20,0x28,0x73,0x69,0x7a,0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f, + 0x73,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x0a,0x20, + 0x20,0x20,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x67,0x72,0x6f,0x75,0x70,0x20,0x54, + 0x26,0x20,0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72,0x20,0x5b,0x5d,0x20,0x28,0x73, + 0x69,0x7a,0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x67,0x72,0x6f,0x75,0x70,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x65,0x6c,0x65,0x6d, + 0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f,0x73,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6e,0x73,0x74,0x65,0x78,0x70,0x72,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x67,0x72,0x6f,0x75,0x70, + 0x20,0x54,0x26,0x20,0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72,0x20,0x5b,0x5d,0x20, + 0x28,0x73,0x69,0x7a,0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x67,0x72,0x6f,0x75,0x70,0x0a,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f,0x73, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72, + 0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x6e,0x74,0x34,0x20,0x66,0x6c,0x61,0x67,0x73,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f, + 0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78, + 0x34,0x20,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x76,0x69,0x65,0x77,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x33,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x5b,0x39, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x69,0x62, + 0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29, + 0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c, + 0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x5b,0x5b,0x64,0x65,0x70, + 0x74,0x68,0x28,0x61,0x6e,0x79,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73, + 0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x5b,0x5b, + 0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74, + 0x65,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29, + 0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74, + 0x68,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x32,0x29,0x2c, + 0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x5b,0x5b,0x75,0x73, + 0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x33,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f, + 0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x5b,0x5b,0x75, + 0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x34,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74, + 0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76, + 0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72, + 0x28,0x6c,0x6f,0x63,0x6e,0x35,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f, + 0x74,0x5f,0x72,0x6f,0x77,0x31,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f, + 0x63,0x6e,0x36,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72, + 0x6f,0x77,0x32,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x37, + 0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x38,0x29, + 0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20, + 0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x39,0x29,0x2c,0x20,0x66, + 0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69, + 0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69, + 0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69, + 0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61, + 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x74,0x68, + 0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x69,0x6e,0x74,0x26,0x20, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20, + 0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x6c,0x69, + 0x67,0x68,0x74,0x5f,0x75,0x76,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x62,0x69,0x61,0x73, + 0x30,0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61,0x79, + 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x35,0x32,0x39,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x33,0x34,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68, + 0x74,0x5f,0x75,0x76,0x2e,0x7a,0x20,0x2d,0x20,0x62,0x69,0x61,0x73,0x30,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x35,0x30,0x20,0x3d, + 0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20,0x2d,0x20,0x30,0x2e, + 0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x35,0x34,0x20,0x3d,0x20,0x6c,0x69, + 0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x20,0x2d,0x20,0x30,0x2e,0x30,0x30,0x30, + 0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x5f,0x35,0x35,0x37,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x28,0x5f,0x35,0x35,0x30,0x2c,0x20,0x5f,0x35,0x35,0x34,0x2c,0x20,0x5f, + 0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x35,0x37,0x33,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c, + 0x20,0x5f,0x35,0x35,0x34,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33, + 0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35, + 0x38,0x34,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20, + 0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x35,0x39,0x31, + 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x38,0x34,0x2c,0x20, + 0x5f,0x35,0x35,0x34,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36, + 0x30,0x37,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x35,0x30, + 0x2c,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x5f,0x35, + 0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36,0x32,0x31,0x20,0x3d,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x79,0x2c, + 0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36,0x33,0x37,0x20,0x3d,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x38,0x34,0x2c,0x20,0x6c,0x69,0x67, + 0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f, + 0x35,0x33,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x36,0x35,0x32,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e, + 0x79,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32, + 0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36, + 0x35,0x35,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x35,0x30, + 0x2c,0x20,0x5f,0x36,0x35,0x32,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35, + 0x33,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x5f,0x36,0x37,0x31,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6c,0x69, + 0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20,0x5f,0x36,0x35,0x32,0x2c,0x20, + 0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36,0x38,0x39,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x38,0x34,0x2c,0x20,0x5f,0x36,0x35,0x32, + 0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28, + 0x28,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x35,0x35,0x37,0x2e,0x78,0x79,0x2c, + 0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x35,0x35,0x37,0x2e, + 0x7a,0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x20,0x2b,0x20,0x74,0x65,0x78, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63, + 0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2c,0x20,0x5f,0x35,0x37,0x33,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74, + 0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x35,0x37,0x33,0x2e,0x7a,0x29,0x29,0x2c,0x20, + 0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61, + 0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f, + 0x35,0x39,0x31,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e, + 0x74,0x28,0x5f,0x35,0x39,0x31,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x34, + 0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73, + 0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x36,0x30,0x37,0x2e, + 0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x36, + 0x30,0x37,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b, + 0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x36,0x32,0x31,0x2e,0x78,0x79,0x2c,0x20, + 0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x36,0x32,0x31,0x2e,0x7a, + 0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63, + 0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2c,0x20,0x5f,0x36,0x33,0x37,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74, + 0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x36,0x33,0x37,0x2e,0x7a,0x29,0x29,0x2c,0x20, + 0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61, + 0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f, + 0x36,0x35,0x35,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e, + 0x74,0x28,0x5f,0x36,0x35,0x35,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x34, + 0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73, + 0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x36,0x37,0x31,0x2e, + 0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x36, + 0x37,0x31,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b, + 0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x36,0x38,0x39,0x2e,0x78,0x79,0x2c,0x20, + 0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x36,0x38,0x39,0x2e,0x7a, + 0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2a,0x20,0x30,0x2e,0x31, + 0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x39,0x33,0x38,0x39,0x35,0x33,0x33,0x39, + 0x39,0x36,0x35,0x38,0x32,0x30,0x33,0x31,0x32,0x35,0x3b,0x0a,0x7d,0x0a,0x0a,0x73, + 0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61, + 0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61, + 0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28, + 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x69,0x6e,0x74, + 0x26,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20, + 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20, + 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x64,0x65, + 0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61, + 0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73, + 0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x70, + 0x61,0x73,0x73,0x26,0x20,0x5f,0x37,0x30,0x37,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x31,0x37,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72, + 0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x20,0x2a,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, + 0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x5f,0x37,0x32,0x34,0x20,0x3d,0x20,0x5f,0x37,0x31,0x37,0x2e,0x78, + 0x79,0x7a,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x37,0x31,0x37, + 0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x5f,0x37,0x34,0x32,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x5f, + 0x37,0x32,0x34,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30, + 0x2e,0x35,0x2c,0x20,0x28,0x28,0x5f,0x37,0x32,0x34,0x2e,0x79,0x20,0x2a,0x20,0x5f, + 0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29, + 0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x37,0x32,0x34,0x2e,0x7a,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x37,0x34,0x36,0x20,0x3d, + 0x20,0x61,0x6e,0x79,0x28,0x5f,0x37,0x34,0x32,0x20,0x3c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f, + 0x6f,0x6c,0x20,0x5f,0x37,0x35,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x21,0x5f,0x37,0x34,0x36,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x37,0x35,0x33,0x20,0x3d,0x20,0x61,0x6e,0x79, + 0x28,0x5f,0x37,0x34,0x32,0x20,0x3e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31, + 0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x5f,0x37,0x35,0x33,0x20,0x3d,0x20,0x5f,0x37,0x34,0x36,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37, + 0x35,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20, + 0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28, + 0x30,0x2e,0x30,0x30,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x38,0x39,0x39,0x38, + 0x39,0x38,0x30,0x35,0x32,0x32,0x31,0x35,0x35,0x37,0x36,0x31,0x37,0x31,0x38,0x37, + 0x35,0x2c,0x20,0x30,0x2e,0x30,0x30,0x30,0x37,0x39,0x39,0x39,0x39,0x39,0x39,0x37, + 0x39,0x37,0x39,0x30,0x33,0x30,0x30,0x31,0x33,0x30,0x38,0x34,0x34,0x31,0x31,0x36, + 0x32,0x31,0x30,0x39,0x33,0x37,0x35,0x2c,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d, + 0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72, + 0x6d,0x61,0x6c,0x2c,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37,0x30,0x37,0x2e,0x73,0x75,0x6e,0x5f,0x64,0x69, + 0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x29,0x29,0x2c,0x20,0x30, + 0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x63,0x66,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64, + 0x6f,0x77,0x50,0x43,0x46,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x74, + 0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x32,0x20,0x5f,0x37,0x38,0x35,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x2e,0x78, + 0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x32,0x20,0x5f,0x37,0x39,0x30,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d, + 0x69,0x6e,0x28,0x5f,0x37,0x38,0x35,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28, + 0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x37,0x38,0x35,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28, + 0x31,0x2e,0x30,0x2c,0x20,0x70,0x63,0x66,0x2c,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a, + 0x63,0x6c,0x61,0x6d,0x70,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x69,0x6e,0x28, + 0x5f,0x37,0x39,0x30,0x2e,0x78,0x2c,0x20,0x5f,0x37,0x39,0x30,0x2e,0x79,0x29,0x20, + 0x2a,0x20,0x31,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x70,0x63,0x66,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61, + 0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74, + 0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73, + 0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63, + 0x61,0x64,0x65,0x64,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x70,0x6f,0x73,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x76,0x69,0x65,0x77, + 0x5f,0x7a,0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61, + 0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e, + 0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x37,0x30,0x37,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a, + 0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a, + 0x2e,0x79,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63, + 0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x74,0x65,0x78, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2c,0x20,0x5f,0x37,0x30,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3c,0x20,0x32,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x33,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d, + 0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x33,0x35,0x20, + 0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66, + 0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65, + 0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x33,0x35,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61, + 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x38,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d, + 0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x34,0x37,0x20,0x3d, + 0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x5f,0x38,0x34,0x37,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x35, + 0x38,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x5f,0x38,0x33,0x35,0x2c,0x20,0x5f,0x38, + 0x34,0x37,0x2c,0x20,0x30,0x2e,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x34, + 0x39,0x30,0x31,0x31,0x36,0x31,0x31,0x39,0x33,0x38,0x34,0x37,0x36,0x35,0x36,0x32, + 0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3e,0x20,0x5f,0x38,0x35,0x38,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, + 0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x2b,0x20,0x31,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x77,0x6f,0x72, + 0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x35,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64, + 0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x74,0x65,0x78, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2c,0x20,0x5f,0x37,0x30,0x37,0x29,0x2c,0x20,0x28,0x76,0x69,0x65, + 0x77,0x5f,0x7a,0x20,0x2d,0x20,0x5f,0x38,0x35,0x38,0x29,0x20,0x2f,0x20,0x28,0x5f, + 0x38,0x33,0x35,0x20,0x2d,0x20,0x5f,0x38,0x35,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x3b, + 0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e, + 0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28, + 0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29, + 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69, + 0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x74,0x68,0x72,0x65,0x61,0x64, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6e,0x5f, + 0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x61,0x6c,0x70,0x68,0x61, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x30,0x37,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70, + 0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x31,0x36,0x20,0x3d,0x20,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x20,0x2a, + 0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x29,0x20,0x2a,0x20,0x28,0x5f,0x31,0x30, + 0x37,0x20,0x2d,0x20,0x31,0x2e,0x30,0x29,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x30,0x37, + 0x20,0x2f,0x20,0x28,0x28,0x33,0x2e,0x31,0x34,0x31,0x35,0x39,0x32,0x37,0x34,0x31, + 0x30,0x31,0x32,0x35,0x37,0x33,0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x20,0x2a,0x20, + 0x5f,0x31,0x31,0x36,0x29,0x20,0x2a,0x20,0x5f,0x31,0x31,0x36,0x29,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20, + 0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61, + 0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69, + 0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65, + 0x64,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x26,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x2c,0x20,0x74, + 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x26,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x74,0x68,0x72,0x65, + 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20, + 0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x32,0x39,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20, + 0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x33,0x36,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20, + 0x5f,0x31,0x32,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x30,0x2e,0x35,0x20,0x2f,0x20,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f, + 0x6c,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74, + 0x5f,0x76,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x29,0x20,0x2a,0x20, + 0x5f,0x31,0x33,0x36,0x29,0x20,0x2b,0x20,0x5f,0x31,0x32,0x39,0x29,0x29,0x20,0x2b, + 0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x73,0x71,0x72,0x74, + 0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x6e,0x5f,0x64, + 0x6f,0x74,0x5f,0x6c,0x29,0x20,0x2a,0x20,0x5f,0x31,0x33,0x36,0x29,0x20,0x2b,0x20, + 0x5f,0x31,0x32,0x39,0x29,0x29,0x29,0x20,0x2b,0x20,0x39,0x2e,0x39,0x39,0x39,0x39, + 0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35, + 0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x29, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69, + 0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f, + 0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29, + 0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73, + 0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x76, + 0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x66,0x30,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36, + 0x35,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f, + 0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36, + 0x39,0x20,0x3d,0x20,0x5f,0x31,0x36,0x35,0x20,0x2a,0x20,0x5f,0x31,0x36,0x35,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x30,0x20,0x2b, + 0x20,0x28,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d, + 0x20,0x66,0x30,0x29,0x20,0x2a,0x20,0x28,0x28,0x5f,0x31,0x36,0x39,0x20,0x2a,0x20, + 0x5f,0x31,0x36,0x39,0x29,0x20,0x2a,0x20,0x5f,0x31,0x36,0x35,0x29,0x29,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65, + 0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28, + 0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c, + 0x75,0x61,0x74,0x65,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4e,0x2c,0x20,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x26,0x20,0x56,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4c,0x2c,0x20,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x26,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x2c,0x20, + 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x26,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c, + 0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x26,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x74, + 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x26,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x38,0x38,0x20,0x3d, + 0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e, + 0x2c,0x20,0x4c,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x39,0x39,0x20,0x3d,0x20,0x66,0x61, + 0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x56,0x20, + 0x2b,0x20,0x4c,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x32,0x31,0x33,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78, + 0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x30,0x2e,0x30,0x34, + 0x35,0x30,0x30,0x30,0x30,0x30,0x31,0x37,0x38,0x38,0x31,0x33,0x39,0x33,0x34,0x33, + 0x32,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x37,0x20,0x3d,0x20,0x5f,0x32,0x31,0x33, + 0x20,0x2a,0x20,0x5f,0x32,0x31,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a, + 0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x5f,0x31,0x39,0x39, + 0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x32,0x31, + 0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78, + 0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x56,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39, + 0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35, + 0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30, + 0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31,0x38,0x38,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20, + 0x3d,0x20,0x5f,0x32,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x66,0x61,0x73,0x74, + 0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x56,0x2c,0x20,0x5f,0x31,0x39, + 0x39,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d, + 0x69,0x78,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x33,0x39,0x39, + 0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38,0x33,0x36, + 0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x6d,0x65,0x74, + 0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x5f,0x32,0x34,0x34,0x20,0x3d,0x20,0x70,0x62,0x72,0x46,0x72, + 0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28, + 0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f, + 0x32,0x34,0x34,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65, + 0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, + 0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31, + 0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x29,0x29,0x20,0x2b,0x20, + 0x28,0x5f,0x32,0x34,0x34,0x20,0x2a,0x20,0x28,0x70,0x62,0x72,0x44,0x69,0x73,0x74, + 0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x20,0x2a,0x20,0x70,0x62, + 0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68, + 0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x34,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x73,0x75,0x6e,0x5f,0x72, + 0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x29,0x20,0x2a,0x20,0x5f,0x31,0x38,0x38,0x3b, + 0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e, + 0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28, + 0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29, + 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75, + 0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28, + 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x26,0x20,0x4e,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72, + 0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x26,0x20, + 0x73,0x68,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x5f,0x33,0x39,0x39,0x20,0x3d,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28, + 0x73,0x68,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x30,0x2e,0x32,0x38, + 0x32,0x30,0x39,0x34,0x38,0x30,0x36,0x34,0x33,0x32,0x37,0x32,0x33,0x39,0x39,0x39, + 0x30,0x32,0x33,0x34,0x33,0x37,0x35,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x31, + 0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38, + 0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34, + 0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b, + 0x20,0x28,0x73,0x68,0x5b,0x32,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30, + 0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39, + 0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29, + 0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x33,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a, + 0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30, + 0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a, + 0x20,0x4e,0x2e,0x78,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x34,0x5d, + 0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x31,0x2e,0x30,0x39,0x32,0x35,0x34, + 0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31, + 0x32,0x35,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29, + 0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x35,0x5d,0x2e,0x78,0x79,0x7a,0x20, + 0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38, + 0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x29, + 0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29, + 0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x36,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, + 0x28,0x30,0x2e,0x33,0x31,0x35,0x33,0x39,0x31,0x35,0x37,0x30,0x33,0x32,0x39,0x36, + 0x36,0x36,0x31,0x33,0x37,0x36,0x39,0x35,0x33,0x31,0x32,0x35,0x20,0x2a,0x20,0x28, + 0x28,0x28,0x33,0x2e,0x30,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2a,0x20,0x4e, + 0x2e,0x7a,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x29,0x29,0x29,0x29,0x20,0x2b,0x20, + 0x28,0x73,0x68,0x5b,0x37,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28, + 0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36, + 0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e, + 0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73, + 0x68,0x5b,0x38,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x35,0x34, + 0x36,0x32,0x37,0x34,0x32,0x34,0x34,0x37,0x38,0x35,0x33,0x30,0x38,0x38,0x33,0x37, + 0x38,0x39,0x30,0x36,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x4e,0x2e,0x78,0x20,0x2a, + 0x20,0x4e,0x2e,0x78,0x29,0x20,0x2d,0x20,0x28,0x4e,0x2e,0x79,0x20,0x2a,0x20,0x4e, + 0x2e,0x79,0x29,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x5f,0x33,0x39,0x39,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74, + 0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72, + 0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f, + 0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x74, + 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x26,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x26,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20, + 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x74,0x68,0x72,0x65, + 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x72,0x6f, + 0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20, + 0x63,0x6f,0x6e,0x73,0x74,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41, + 0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x26, + 0x20,0x73,0x68,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x63,0x75,0x62,0x65, + 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63, + 0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73, + 0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x74,0x65, + 0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74, + 0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75, + 0x74,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x30,0x36, + 0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x64, + 0x6f,0x74,0x28,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x56,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34, + 0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32, + 0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x34, + 0x31,0x36,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, + 0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33, + 0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c,0x20, + 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20, + 0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73, + 0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x5f,0x34,0x38,0x32,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64, + 0x66,0x5f,0x6c,0x75,0x74,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70, + 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x32,0x28,0x5f,0x34,0x30,0x36,0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73, + 0x73,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x28,0x28,0x28,0x28,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29, + 0x20,0x2d,0x20,0x28,0x5f,0x34,0x31,0x36,0x20,0x2b,0x20,0x28,0x28,0x66,0x61,0x73, + 0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e, + 0x30,0x20,0x2d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x2c,0x20, + 0x5f,0x34,0x31,0x36,0x29,0x20,0x2d,0x20,0x5f,0x34,0x31,0x36,0x29,0x20,0x2a,0x20, + 0x70,0x6f,0x77,0x72,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x30, + 0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f,0x34,0x30,0x36,0x29,0x2c, + 0x20,0x35,0x2e,0x30,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20, + 0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62, + 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x66,0x61,0x73, + 0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61, + 0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x70, + 0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x29,0x20,0x2a,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38, + 0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33, + 0x37,0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63, + 0x5f,0x63,0x75,0x62,0x65,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70, + 0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x72,0x65,0x66,0x6c, + 0x65,0x63,0x74,0x28,0x2d,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x4e,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x6c,0x65,0x76,0x65,0x6c,0x28,0x72,0x6f, + 0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x20,0x2a,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f, + 0x64,0x29,0x29,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x34,0x31,0x36, + 0x20,0x2a,0x20,0x5f,0x34,0x38,0x32,0x2e,0x78,0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x28,0x5f,0x34,0x38,0x32,0x2e,0x79,0x29,0x29,0x29,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20, + 0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61, + 0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74, + 0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20, + 0x63,0x6f,0x6e,0x73,0x74,0x20,0x62,0x6f,0x6f,0x6c,0x26,0x20,0x69,0x62,0x6c,0x45, + 0x6e,0x61,0x62,0x6c,0x65,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4e,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x56,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69, + 0x63,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73, + 0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x26,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e, + 0x67,0x74,0x68,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79, + 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x26,0x20,0x73,0x68,0x2c, + 0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x63,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f, + 0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62, + 0x65,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73, + 0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72, + 0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62, + 0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72, + 0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x74, + 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x26,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20, + 0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x66, + 0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d, + 0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65, + 0x73,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x70,0x76,0x55, + 0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x2c,0x20,0x39,0x3e,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20, + 0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x61,0x78,0x5f, + 0x6c,0x6f,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x73, + 0x75,0x6c,0x74,0x20,0x3d,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74, + 0x65,0x49,0x62,0x6c,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65, + 0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63, + 0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f, + 0x6c,0x75,0x74,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75, + 0x74,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x72,0x65, + 0x73,0x75,0x6c,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e, + 0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e, + 0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x37, + 0x30,0x37,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x31,0x29,0x5d,0x5d, + 0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61,0x79,0x3c, + 0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x30,0x29,0x5d,0x5d, + 0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x63,0x75,0x62,0x65,0x3c,0x66,0x6c, + 0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65, + 0x63,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x31,0x29,0x5d,0x5d, + 0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61, + 0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x20, + 0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x32,0x29,0x5d,0x5d,0x2c,0x20, + 0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e, + 0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72, + 0x65,0x28,0x33,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20, + 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x5b,0x5b,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x20, + 0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x31,0x29,0x5d,0x5d,0x2c,0x20, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66, + 0x5f,0x6c,0x75,0x74,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x32, + 0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70, + 0x5f,0x61,0x6f,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x33,0x29, + 0x5d,0x5d,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x46,0x72, + 0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69, + 0x6f,0x6e,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e, + 0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x38,0x39,0x36,0x20, + 0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a, + 0x65,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, + 0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61, + 0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x39,0x30,0x37,0x20,0x3d, + 0x20,0x69,0x6e,0x2e,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x20,0x2a,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c, + 0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x5f,0x39,0x30,0x38,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x63,0x65, + 0x6e,0x74,0x65,0x72,0x20,0x2d,0x20,0x5f,0x39,0x30,0x37,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x39,0x31,0x34,0x20,0x3d,0x20,0x69, + 0x6e,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x2b,0x20,0x5f,0x39,0x30, + 0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x39, + 0x31,0x38,0x20,0x3d,0x20,0x5f,0x39,0x31,0x34,0x20,0x2d,0x20,0x5f,0x39,0x30,0x38, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x39,0x32, + 0x32,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f, + 0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x39,0x30,0x38,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x32,0x36,0x20,0x3d, + 0x20,0x64,0x6f,0x74,0x28,0x5f,0x39,0x31,0x38,0x2c,0x20,0x5f,0x39,0x31,0x38,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x33,0x30, + 0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x39,0x31,0x38,0x2c,0x20,0x5f,0x38,0x39, + 0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39, + 0x33,0x34,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x39,0x31,0x38,0x2c,0x20,0x5f, + 0x39,0x32,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x39,0x34,0x32,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x39,0x32,0x32,0x2c, + 0x20,0x5f,0x39,0x32,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x39,0x34,0x38,0x20,0x3d,0x20,0x5f,0x39,0x32,0x36,0x20,0x2d,0x20, + 0x28,0x5f,0x39,0x33,0x30,0x20,0x2a,0x20,0x5f,0x39,0x33,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x35,0x36,0x20,0x3d,0x20, + 0x28,0x5f,0x39,0x32,0x36,0x20,0x2a,0x20,0x64,0x6f,0x74,0x28,0x5f,0x38,0x39,0x36, + 0x2c,0x20,0x5f,0x39,0x32,0x32,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f,0x39,0x33,0x34, + 0x20,0x2a,0x20,0x5f,0x39,0x33,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x39,0x36,0x38,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f, + 0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x2a,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x61, + 0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x39,0x37,0x39,0x20,0x3d,0x20,0x28,0x5f,0x39,0x35,0x36,0x20,0x2a,0x20,0x5f, + 0x39,0x35,0x36,0x29,0x20,0x2d,0x20,0x28,0x5f,0x39,0x34,0x38,0x20,0x2a,0x20,0x28, + 0x28,0x28,0x5f,0x39,0x32,0x36,0x20,0x2a,0x20,0x5f,0x39,0x34,0x32,0x29,0x20,0x2d, + 0x20,0x28,0x5f,0x39,0x33,0x34,0x20,0x2a,0x20,0x5f,0x39,0x33,0x34,0x29,0x29,0x20, + 0x2d,0x20,0x28,0x5f,0x39,0x36,0x38,0x20,0x2a,0x20,0x5f,0x39,0x32,0x36,0x29,0x29, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31, + 0x30,0x30,0x30,0x20,0x3d,0x20,0x5f,0x39,0x30,0x38,0x20,0x2b,0x20,0x28,0x5f,0x39, + 0x31,0x38,0x20,0x2a,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70, + 0x28,0x28,0x5f,0x39,0x33,0x34,0x20,0x2d,0x20,0x28,0x28,0x5f,0x39,0x35,0x36,0x20, + 0x2f,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x5f,0x39,0x34,0x38, + 0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x33,0x39,0x32,0x32,0x35, + 0x32,0x39,0x30,0x32,0x39,0x30,0x37,0x37,0x38,0x35,0x30,0x32,0x38,0x32,0x31,0x39, + 0x32,0x32,0x33,0x65,0x2d,0x30,0x39,0x29,0x29,0x20,0x2a,0x20,0x5f,0x39,0x33,0x30, + 0x29,0x29,0x20,0x2f,0x20,0x5f,0x39,0x32,0x36,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20, + 0x31,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x5f,0x31,0x30,0x30,0x34,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63, + 0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20, + 0x5f,0x31,0x30,0x30,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x30,0x30,0x38,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x30, + 0x30,0x34,0x2c,0x20,0x5f,0x38,0x39,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x32,0x32,0x20,0x3d,0x20,0x73,0x71,0x72, + 0x74,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x2c, + 0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x30,0x30,0x34,0x2c,0x20,0x5f,0x31,0x30,0x30, + 0x34,0x29,0x20,0x2d,0x20,0x28,0x5f,0x31,0x30,0x30,0x38,0x20,0x2a,0x20,0x5f,0x31, + 0x30,0x30,0x38,0x29,0x29,0x29,0x20,0x2d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x61, + 0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x30,0x32,0x35,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f, + 0x31,0x30,0x32,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x30,0x32,0x37,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d, + 0x61,0x78,0x28,0x5f,0x31,0x30,0x32,0x35,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39, + 0x39,0x39,0x39,0x37,0x34,0x37,0x35,0x32,0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38, + 0x33,0x35,0x31,0x32,0x31,0x31,0x35,0x34,0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x33, + 0x34,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68, + 0x73,0x74,0x65,0x70,0x28,0x2d,0x5f,0x31,0x30,0x32,0x37,0x2c,0x20,0x5f,0x31,0x30, + 0x32,0x37,0x2c,0x20,0x5f,0x31,0x30,0x32,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x74,0x20,0x3d,0x20,0x2d,0x31,0x2e,0x30,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x6e,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x5f,0x39,0x37,0x39,0x20, + 0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x39,0x34,0x38, + 0x20,0x3e,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x33,0x39,0x32,0x32, + 0x35,0x32,0x39,0x30,0x32,0x39,0x30,0x37,0x37,0x38,0x35,0x30,0x32,0x38,0x32,0x31, + 0x39,0x32,0x32,0x33,0x65,0x2d,0x30,0x39,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x30,0x35,0x32,0x20,0x3d,0x20,0x28,0x28,0x2d,0x5f,0x39,0x35,0x36,0x29,0x20, + 0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x39,0x37,0x39,0x29,0x29,0x20,0x2f,0x20, + 0x5f,0x39,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x38,0x20,0x3d,0x20,0x5f,0x39,0x33,0x34, + 0x20,0x2b,0x20,0x28,0x5f,0x31,0x30,0x35,0x32,0x20,0x2a,0x20,0x5f,0x39,0x33,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28, + 0x28,0x5f,0x31,0x30,0x35,0x32,0x20,0x3e,0x20,0x30,0x2e,0x30,0x29,0x20,0x26,0x26, + 0x20,0x28,0x5f,0x31,0x30,0x35,0x38,0x20,0x3e,0x20,0x30,0x2e,0x30,0x29,0x29,0x20, + 0x26,0x26,0x20,0x28,0x5f,0x31,0x30,0x35,0x38,0x20,0x3c,0x20,0x5f,0x39,0x32,0x36, + 0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x20,0x3d,0x20,0x28,0x28,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61, + 0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x38,0x39,0x36, + 0x20,0x2a,0x20,0x5f,0x31,0x30,0x35,0x32,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f,0x39, + 0x30,0x38,0x20,0x2b,0x20,0x28,0x5f,0x39,0x31,0x38,0x20,0x2a,0x20,0x28,0x5f,0x31, + 0x30,0x35,0x38,0x20,0x2f,0x20,0x5f,0x39,0x32,0x36,0x29,0x29,0x29,0x29,0x20,0x2f, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x61,0x64, + 0x69,0x75,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x74,0x20,0x3d,0x20,0x5f,0x31,0x30,0x35,0x32,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x39,0x38,0x20,0x3d,0x20,0x64, + 0x6f,0x74,0x28,0x5f,0x39,0x32,0x32,0x2c,0x20,0x5f,0x38,0x39,0x36,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x31,0x32,0x20, + 0x3d,0x20,0x28,0x5f,0x31,0x30,0x39,0x38,0x20,0x2a,0x20,0x5f,0x31,0x30,0x39,0x38, + 0x29,0x20,0x2d,0x20,0x28,0x5f,0x39,0x34,0x32,0x20,0x2d,0x20,0x5f,0x39,0x36,0x38, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x31,0x32, + 0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31, + 0x32,0x32,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x31,0x30,0x39,0x38,0x29,0x20,0x2d,0x20, + 0x73,0x71,0x72,0x74,0x28,0x5f,0x31,0x31,0x31,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x32,0x34,0x20, + 0x3d,0x20,0x5f,0x31,0x31,0x32,0x32,0x20,0x3e,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x33, + 0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, + 0x31,0x31,0x32,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x33, + 0x33,0x20,0x3d,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x20,0x7c,0x7c, + 0x20,0x28,0x5f,0x31,0x31,0x32,0x32,0x20,0x3c,0x20,0x74,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x33,0x33, + 0x20,0x3d,0x20,0x5f,0x31,0x31,0x32,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x5f,0x31,0x31,0x33,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x5f,0x31,0x31,0x34,0x34,0x20,0x3d,0x20,0x28,0x5f,0x37,0x30, + 0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a, + 0x20,0x2b,0x20,0x28,0x5f,0x38,0x39,0x36,0x20,0x2a,0x20,0x5f,0x31,0x31,0x32,0x32, + 0x29,0x29,0x20,0x2d,0x20,0x5f,0x39,0x30,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f, + 0x31,0x31,0x34,0x34,0x2c,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f, + 0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x20,0x3c,0x3d,0x20,0x30,0x2e,0x30,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x5f,0x31,0x31,0x34,0x34,0x20,0x2f, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x61,0x64, + 0x69,0x75,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20,0x5f,0x31,0x31,0x32,0x32,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x31,0x36,0x30,0x20, + 0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f, + 0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x39,0x31,0x34,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x36,0x34,0x20,0x3d,0x20, + 0x64,0x6f,0x74,0x28,0x5f,0x31,0x31,0x36,0x30,0x2c,0x20,0x5f,0x38,0x39,0x36,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x37, + 0x38,0x20,0x3d,0x20,0x28,0x5f,0x31,0x31,0x36,0x34,0x20,0x2a,0x20,0x5f,0x31,0x31, + 0x36,0x34,0x29,0x20,0x2d,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x31,0x36,0x30, + 0x2c,0x20,0x5f,0x31,0x31,0x36,0x30,0x29,0x20,0x2d,0x20,0x5f,0x39,0x36,0x38,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x37,0x38,0x20, + 0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x38, + 0x38,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x31,0x31,0x36,0x34,0x29,0x20,0x2d,0x20,0x73, + 0x71,0x72,0x74,0x28,0x5f,0x31,0x31,0x37,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x39,0x30,0x20,0x3d, + 0x20,0x5f,0x31,0x31,0x38,0x38,0x20,0x3e,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x39,0x39, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31, + 0x31,0x39,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x39,0x39, + 0x20,0x3d,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x20,0x7c,0x7c,0x20, + 0x28,0x5f,0x31,0x31,0x38,0x38,0x20,0x3c,0x20,0x74,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65, + 0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x39,0x39,0x20, + 0x3d,0x20,0x5f,0x31,0x31,0x39,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, + 0x31,0x31,0x39,0x39,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x5f,0x31,0x32,0x31,0x30,0x20,0x3d,0x20,0x28,0x5f,0x37,0x30,0x37, + 0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20, + 0x2b,0x20,0x28,0x5f,0x38,0x39,0x36,0x20,0x2a,0x20,0x5f,0x31,0x31,0x38,0x38,0x29, + 0x29,0x20,0x2d,0x20,0x5f,0x39,0x31,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31, + 0x32,0x31,0x30,0x2c,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x5f,0x31,0x32,0x31,0x30,0x20,0x2f,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69, + 0x75,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20,0x5f,0x31,0x31,0x38,0x38,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x32,0x32,0x38,0x20,0x3d,0x20,0x2d,0x5f,0x31,0x30,0x30, + 0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20,0x5f, + 0x31,0x32,0x32,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f, + 0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x28,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61, + 0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28, + 0x5f,0x38,0x39,0x36,0x20,0x2a,0x20,0x5f,0x31,0x32,0x32,0x38,0x29,0x29,0x20,0x2d, + 0x20,0x5f,0x31,0x30,0x30,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x5f,0x31,0x30,0x33,0x34,0x20,0x3c,0x3d, + 0x20,0x30,0x2e,0x30,0x29,0x20,0x7c,0x7c,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e, + 0x30,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64,0x5f,0x66,0x72,0x61,0x67,0x6d,0x65, + 0x6e,0x74,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x32,0x35,0x32,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78, + 0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x38,0x39,0x36,0x20,0x2a,0x20,0x74,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x39,0x30, + 0x20,0x3d,0x20,0x28,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f, + 0x77,0x30,0x2e,0x79,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78, + 0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f, + 0x77,0x31,0x2e,0x79,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x79, + 0x29,0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72, + 0x6f,0x77,0x32,0x2e,0x79,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e, + 0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x33,0x30,0x37,0x20,0x3d,0x20,0x28,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f,0x74, + 0x5f,0x72,0x6f,0x77,0x30,0x2e,0x7a,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x2e,0x78,0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f,0x74, + 0x5f,0x72,0x6f,0x77,0x31,0x2e,0x7a,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x2e,0x79,0x29,0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f, + 0x74,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x7a,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x5f,0x31,0x33,0x32,0x31,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x62, + 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, + 0x28,0x28,0x5f,0x31,0x32,0x39,0x30,0x20,0x3e,0x20,0x30,0x2e,0x30,0x29,0x20,0x3f, + 0x20,0x31,0x2e,0x30,0x20,0x3a,0x20,0x30,0x2e,0x36,0x34,0x39,0x39,0x39,0x39,0x39, + 0x37,0x36,0x31,0x35,0x38,0x31,0x34,0x32,0x30,0x38,0x39,0x38,0x34,0x33,0x37,0x35, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33, + 0x32,0x35,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31,0x32,0x39, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x33,0x33,0x36,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31,0x33, + 0x30,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x5f,0x31,0x33,0x35,0x36,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x5f,0x31,0x33,0x32, + 0x31,0x2c,0x20,0x5f,0x31,0x33,0x32,0x31,0x20,0x2a,0x20,0x30,0x2e,0x33,0x34,0x39, + 0x39,0x39,0x39,0x39,0x39,0x34,0x30,0x33,0x39,0x35,0x33,0x35,0x35,0x32,0x32,0x34, + 0x36,0x30,0x39,0x33,0x37,0x35,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x66, + 0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73, + 0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30,0x2c,0x20,0x5f, + 0x31,0x33,0x32,0x35,0x20,0x2a,0x20,0x31,0x2e,0x35,0x2c,0x20,0x61,0x62,0x73,0x28, + 0x5f,0x31,0x32,0x39,0x30,0x29,0x29,0x2c,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73, + 0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30,0x2c,0x20,0x5f, + 0x31,0x33,0x33,0x36,0x20,0x2a,0x20,0x31,0x2e,0x35,0x2c,0x20,0x61,0x62,0x73,0x28, + 0x5f,0x31,0x33,0x30,0x37,0x29,0x29,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x33,0x36,0x34,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x32,0x35,0x32,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31, + 0x33,0x36,0x35,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x76,0x69,0x65,0x77,0x5f, + 0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20,0x5f,0x31,0x33,0x36,0x34,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70, + 0x74,0x68,0x20,0x3d,0x20,0x5f,0x31,0x33,0x36,0x35,0x2e,0x7a,0x20,0x2f,0x20,0x5f, + 0x31,0x33,0x36,0x35,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x5f,0x37,0x30,0x37,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20, + 0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x39,0x37,0x20,0x3d,0x20,0x66, + 0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x28,0x5f,0x37,0x30,0x37, + 0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x5f,0x31,0x33,0x36,0x34,0x29,0x2e,0x7a, + 0x20,0x2a,0x20,0x28,0x2d,0x30,0x2e,0x30,0x31,0x39,0x39,0x39,0x39,0x39,0x39,0x39, + 0x35,0x35,0x32,0x39,0x36,0x35,0x31,0x36,0x34,0x31,0x38,0x34,0x35,0x37,0x30,0x33, + 0x31,0x32,0x35,0x29,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, + 0x5f,0x31,0x33,0x39,0x37,0x2c,0x20,0x5f,0x31,0x33,0x39,0x37,0x2c,0x20,0x5f,0x31, + 0x33,0x39,0x37,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30, + 0x37,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x31,0x38,0x20,0x3d,0x20,0x2d,0x28,0x5f,0x37, + 0x30,0x37,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x5f,0x31,0x33,0x36,0x34,0x29, + 0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x34,0x31,0x38,0x20,0x3c, + 0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61, + 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x5f,0x31,0x34,0x31,0x38,0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e, + 0x79,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x34,0x34,0x32,0x20,0x3d,0x20,0x5f,0x37,0x30, + 0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63, + 0x65,0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x20,0x2a,0x20,0x5f,0x31, + 0x33,0x36,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x5f,0x31,0x34,0x34,0x39,0x20,0x3d,0x20,0x5f,0x31,0x34,0x34, + 0x32,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f, + 0x31,0x34,0x34,0x32,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x34,0x36,0x36,0x20,0x3d,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x5f,0x31,0x34,0x34,0x39,0x2e,0x78,0x20, + 0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x28,0x28, + 0x5f,0x31,0x34,0x34,0x39,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e, + 0x35,0x2c,0x20,0x5f,0x31,0x34,0x34,0x39,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x34,0x37,0x30,0x20, + 0x3d,0x20,0x61,0x6e,0x79,0x28,0x5f,0x31,0x34,0x36,0x36,0x20,0x3c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x34,0x37,0x37,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x34, + 0x37,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x34,0x37,0x37,0x20, + 0x3d,0x20,0x61,0x6e,0x79,0x28,0x5f,0x31,0x34,0x36,0x36,0x20,0x3e,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c, + 0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x34,0x37,0x37,0x20,0x3d, + 0x20,0x5f,0x31,0x34,0x37,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31, + 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x21,0x5f,0x31,0x34,0x37,0x37,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74, + 0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30, + 0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30, + 0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x30, + 0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34, + 0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, + 0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36, + 0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30, + 0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30, + 0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e, + 0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30, + 0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35, + 0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30, + 0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30, + 0x36,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, + 0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x28,0x74,0x69,0x6e,0x74,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f, + 0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x5f,0x37,0x30,0x37,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d, + 0x3d,0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x66,0x61,0x73,0x74,0x3a, + 0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x28,0x5f,0x37,0x30,0x37, + 0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6e, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,0x2e,0x78,0x79, + 0x7a,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x30,0x2e,0x35,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75, + 0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x5f,0x31,0x35,0x34,0x37,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f, + 0x61,0x6f,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x61,0x6f, + 0x2c,0x20,0x28,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e, + 0x78,0x79,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x69,0x6e,0x74,0x32, + 0x28,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e,0x67,0x65,0x74,0x5f,0x77,0x69,0x64,0x74, + 0x68,0x28,0x29,0x2c,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e,0x67,0x65,0x74,0x5f, + 0x68,0x65,0x69,0x67,0x68,0x74,0x28,0x29,0x29,0x29,0x29,0x2c,0x20,0x6c,0x65,0x76, + 0x65,0x6c,0x28,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x34,0x38,0x20,0x3d,0x20,0x5f,0x31,0x35,0x34, + 0x37,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30, + 0x37,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x34,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75, + 0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x35,0x34,0x38,0x2c,0x20,0x5f,0x31,0x35,0x34, + 0x38,0x2c,0x20,0x5f,0x31,0x35,0x34,0x38,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f, + 0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f,0x31,0x32, + 0x35,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x20,0x3d,0x20,0x2d,0x28,0x5f,0x37,0x30,0x37,0x2e,0x76,0x69,0x65, + 0x77,0x20,0x2a,0x20,0x5f,0x31,0x33,0x36,0x34,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x35,0x39,0x36,0x20,0x3d, + 0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65, + 0x28,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73, + 0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x31,0x32,0x35,0x32,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x20,0x3d,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20, + 0x3d,0x20,0x5f,0x31,0x35,0x39,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x66,0x61, + 0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37, + 0x30,0x37,0x2e,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37, + 0x2e,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a, + 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73, + 0x63,0x61,0x64,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x74, + 0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x37,0x30,0x37,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37, + 0x20,0x3d,0x20,0x5f,0x31,0x33,0x35,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x69,0x6e, + 0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39, + 0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c, + 0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x69,0x62,0x6c, + 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x20,0x3e,0x20,0x30,0x2e,0x35,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x32,0x20,0x3d,0x20,0x5f,0x31,0x35,0x39,0x36,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33, + 0x20,0x3d,0x20,0x5f,0x31,0x33,0x35,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x69, + 0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x35,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69, + 0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e, + 0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x37,0x5b,0x30,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x30, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b, + 0x31,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x31,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x32,0x5d, + 0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x32,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x33,0x5d,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x34,0x5d,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x34,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x35,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30, + 0x37,0x2e,0x73,0x68,0x5b,0x35,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x37,0x5b,0x36,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e, + 0x73,0x68,0x5b,0x36,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x37,0x5b,0x37,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68, + 0x5b,0x37,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x37,0x5b,0x38,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x38, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x69,0x62,0x6c, + 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x37,0x35,0x20,0x3d,0x20,0x69,0x6e,0x2e, + 0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x20,0x2a, + 0x20,0x5f,0x31,0x30,0x33,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e, + 0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x28,0x28,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74, + 0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x29, + 0x20,0x2b,0x20,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41, + 0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73, + 0x70,0x65,0x63,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65, + 0x63,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c, + 0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x38, + 0x29,0x29,0x20,0x2a,0x20,0x5f,0x31,0x36,0x37,0x35,0x2c,0x20,0x5f,0x31,0x36,0x37, + 0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f, + 0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +static inline const sg_shader_desc* capsule_impostor_shader_desc(sg_backend backend) { + if (backend == SG_BACKEND_GLCORE) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)capsule_vs_source_glsl430; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)capsule_fs_source_glsl430; + desc.fragment_func.entry = "main"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[0].glsl_name = "in_pos"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[0].glsl_uniforms[0].array_count = 4; + desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_frame"; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 560; + desc.uniform_blocks[1].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[0].array_count = 0; + desc.uniform_blocks[1].glsl_uniforms[0].glsl_name = "_707.sun_dir_world"; + desc.uniform_blocks[1].glsl_uniforms[1].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[1].array_count = 0; + desc.uniform_blocks[1].glsl_uniforms[1].glsl_name = "_707.sun_color"; + desc.uniform_blocks[1].glsl_uniforms[2].type = SG_UNIFORMTYPE_INT4; + desc.uniform_blocks[1].glsl_uniforms[2].array_count = 0; + desc.uniform_blocks[1].glsl_uniforms[2].glsl_name = "_707.flags"; + desc.uniform_blocks[1].glsl_uniforms[3].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[3].array_count = 0; + desc.uniform_blocks[1].glsl_uniforms[3].glsl_name = "_707.camera_pos"; + desc.uniform_blocks[1].glsl_uniforms[4].type = SG_UNIFORMTYPE_MAT4; + desc.uniform_blocks[1].glsl_uniforms[4].array_count = 0; + desc.uniform_blocks[1].glsl_uniforms[4].glsl_name = "_707.view_proj"; + desc.uniform_blocks[1].glsl_uniforms[5].type = SG_UNIFORMTYPE_MAT4; + desc.uniform_blocks[1].glsl_uniforms[5].array_count = 0; + desc.uniform_blocks[1].glsl_uniforms[5].glsl_name = "_707.view"; + desc.uniform_blocks[1].glsl_uniforms[6].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[6].array_count = 0; + desc.uniform_blocks[1].glsl_uniforms[6].glsl_name = "_707.cascade_far_view_z"; + desc.uniform_blocks[1].glsl_uniforms[7].type = SG_UNIFORMTYPE_MAT4; + desc.uniform_blocks[1].glsl_uniforms[7].array_count = 3; + desc.uniform_blocks[1].glsl_uniforms[7].glsl_name = "_707.cascade_matrices"; + desc.uniform_blocks[1].glsl_uniforms[8].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[8].array_count = 9; + desc.uniform_blocks[1].glsl_uniforms[8].glsl_name = "_707.sh"; + desc.uniform_blocks[1].glsl_uniforms[9].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[9].array_count = 0; + desc.uniform_blocks[1].glsl_uniforms[9].glsl_name = "_707.ibl_params"; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 16; + desc.uniform_blocks[2].glsl_uniforms[0].type = SG_UNIFORMTYPE_INT4; + desc.uniform_blocks[2].glsl_uniforms[0].array_count = 1; + desc.uniform_blocks[2].glsl_uniforms[0].glsl_name = "ub_draw"; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.glsl_binding_n = 0; + desc.views[1].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[1].texture.image_type = SG_IMAGETYPE_ARRAY; + desc.views[1].texture.sample_type = SG_IMAGESAMPLETYPE_DEPTH; + desc.views[1].texture.multisampled = false; + desc.views[2].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[2].texture.image_type = SG_IMAGETYPE_CUBE; + desc.views[2].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[2].texture.multisampled = false; + desc.views[3].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[3].texture.image_type = SG_IMAGETYPE_2D; + desc.views[3].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[3].texture.multisampled = false; + desc.views[4].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[4].texture.image_type = SG_IMAGETYPE_2D; + desc.views[4].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[4].texture.multisampled = false; + desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_COMPARISON; + desc.samplers[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[1].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[2].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[2].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[3].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[3].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[0].view_slot = 4; + desc.texture_sampler_pairs[0].sampler_slot = 3; + desc.texture_sampler_pairs[0].glsl_name = "tex_ao_smp_ao"; + desc.texture_sampler_pairs[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[1].view_slot = 1; + desc.texture_sampler_pairs[1].sampler_slot = 0; + desc.texture_sampler_pairs[1].glsl_name = "tex_shadow_smp_shadow"; + desc.texture_sampler_pairs[2].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[2].view_slot = 2; + desc.texture_sampler_pairs[2].sampler_slot = 1; + desc.texture_sampler_pairs[2].glsl_name = "tex_ibl_spec_smp_ibl_spec"; + desc.texture_sampler_pairs[3].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[3].view_slot = 3; + desc.texture_sampler_pairs[3].sampler_slot = 2; + desc.texture_sampler_pairs[3].glsl_name = "tex_brdf_lut_smp_brdf_lut"; + desc.label = "capsule_impostor_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_D3D11) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)capsule_vs_source_hlsl5; + desc.vertex_func.d3d11_target = "vs_5_0"; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)capsule_fs_source_hlsl5; + desc.fragment_func.d3d11_target = "ps_5_0"; + desc.fragment_func.entry = "main"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[0].hlsl_sem_name = "TEXCOORD"; + desc.attrs[0].hlsl_sem_index = 0; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].hlsl_register_b_n = 0; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 560; + desc.uniform_blocks[1].hlsl_register_b_n = 1; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 16; + desc.uniform_blocks[2].hlsl_register_b_n = 2; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.hlsl_register_t_n = 0; + desc.views[1].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[1].texture.image_type = SG_IMAGETYPE_ARRAY; + desc.views[1].texture.sample_type = SG_IMAGESAMPLETYPE_DEPTH; + desc.views[1].texture.multisampled = false; + desc.views[1].texture.hlsl_register_t_n = 0; + desc.views[2].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[2].texture.image_type = SG_IMAGETYPE_CUBE; + desc.views[2].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[2].texture.multisampled = false; + desc.views[2].texture.hlsl_register_t_n = 1; + desc.views[3].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[3].texture.image_type = SG_IMAGETYPE_2D; + desc.views[3].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[3].texture.multisampled = false; + desc.views[3].texture.hlsl_register_t_n = 2; + desc.views[4].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[4].texture.image_type = SG_IMAGETYPE_2D; + desc.views[4].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[4].texture.multisampled = false; + desc.views[4].texture.hlsl_register_t_n = 3; + desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_COMPARISON; + desc.samplers[0].hlsl_register_s_n = 0; + desc.samplers[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[1].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[1].hlsl_register_s_n = 1; + desc.samplers[2].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[2].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[2].hlsl_register_s_n = 2; + desc.samplers[3].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[3].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[3].hlsl_register_s_n = 3; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[0].view_slot = 4; + desc.texture_sampler_pairs[0].sampler_slot = 3; + desc.texture_sampler_pairs[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[1].view_slot = 1; + desc.texture_sampler_pairs[1].sampler_slot = 0; + desc.texture_sampler_pairs[2].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[2].view_slot = 2; + desc.texture_sampler_pairs[2].sampler_slot = 1; + desc.texture_sampler_pairs[3].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[3].view_slot = 3; + desc.texture_sampler_pairs[3].sampler_slot = 2; + desc.label = "capsule_impostor_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_METAL_MACOS) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)capsule_vs_source_metal_macos; + desc.vertex_func.entry = "main0"; + desc.fragment_func.source = (const char*)capsule_fs_source_metal_macos; + desc.fragment_func.entry = "main0"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].msl_buffer_n = 0; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 560; + desc.uniform_blocks[1].msl_buffer_n = 1; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 16; + desc.uniform_blocks[2].msl_buffer_n = 2; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.msl_buffer_n = 8; + desc.views[1].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[1].texture.image_type = SG_IMAGETYPE_ARRAY; + desc.views[1].texture.sample_type = SG_IMAGESAMPLETYPE_DEPTH; + desc.views[1].texture.multisampled = false; + desc.views[1].texture.msl_texture_n = 0; + desc.views[2].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[2].texture.image_type = SG_IMAGETYPE_CUBE; + desc.views[2].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[2].texture.multisampled = false; + desc.views[2].texture.msl_texture_n = 1; + desc.views[3].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[3].texture.image_type = SG_IMAGETYPE_2D; + desc.views[3].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[3].texture.multisampled = false; + desc.views[3].texture.msl_texture_n = 2; + desc.views[4].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[4].texture.image_type = SG_IMAGETYPE_2D; + desc.views[4].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[4].texture.multisampled = false; + desc.views[4].texture.msl_texture_n = 3; + desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_COMPARISON; + desc.samplers[0].msl_sampler_n = 0; + desc.samplers[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[1].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[1].msl_sampler_n = 1; + desc.samplers[2].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[2].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[2].msl_sampler_n = 2; + desc.samplers[3].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[3].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[3].msl_sampler_n = 3; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[0].view_slot = 4; + desc.texture_sampler_pairs[0].sampler_slot = 3; + desc.texture_sampler_pairs[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[1].view_slot = 1; + desc.texture_sampler_pairs[1].sampler_slot = 0; + desc.texture_sampler_pairs[2].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[2].view_slot = 2; + desc.texture_sampler_pairs[2].sampler_slot = 1; + desc.texture_sampler_pairs[3].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[3].view_slot = 3; + desc.texture_sampler_pairs[3].sampler_slot = 2; + desc.label = "capsule_impostor_shader"; + } + return &desc; + } + return 0; +} diff --git a/samples/shaders/generated/cube.glsl.h b/samples/shaders/generated/cube.glsl.h new file mode 100644 index 0000000..70d5460 --- /dev/null +++ b/samples/shaders/generated/cube.glsl.h @@ -0,0 +1,4408 @@ +#pragma once +/* + #version:1# (machine generated, don't edit!) + + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) + + Cmdline: + sokol-shdc --input E:/box/box3d/samples/shaders/shapes/cube.glsl --output E:/box/box3d/samples/shaders/generated/cube.glsl.h --slang hlsl5:metal_macos:glsl430 + + Overview: + ========= + Shader program: 'cube': + Get shader desc: cube_shader_desc(sg_query_backend()); + Vertex Shader: vs + Fragment Shader: fs + Attributes: + ATTR_cube_in_pos => 0 + Bindings: + Uniform block 'ub_draw': + C struct: ub_draw_t + Bind slot: UB_ub_draw => 2 + Uniform block 'ub_frame': + C struct: ub_frame_t + Bind slot: UB_ub_frame => 0 + Uniform block 'ub_pass': + C struct: ub_pass_t + Bind slot: UB_ub_pass => 1 + Storage buffer 'cube_instances': + C struct: cube_instance_t + Bind slot: VIEW_cube_instances => 0 + Readonly: true + Texture 'tex_shadow': + Image type: SG_IMAGETYPE_ARRAY + Sample type: SG_IMAGESAMPLETYPE_DEPTH + Multisampled: false + Bind slot: VIEW_tex_shadow => 1 + Texture 'tex_ao': + Image type: SG_IMAGETYPE_2D + Sample type: SG_IMAGESAMPLETYPE_FLOAT + Multisampled: false + Bind slot: VIEW_tex_ao => 4 + Texture 'tex_ibl_spec': + Image type: SG_IMAGETYPE_CUBE + Sample type: SG_IMAGESAMPLETYPE_FLOAT + Multisampled: false + Bind slot: VIEW_tex_ibl_spec => 2 + Texture 'tex_brdf_lut': + Image type: SG_IMAGETYPE_2D + Sample type: SG_IMAGESAMPLETYPE_FLOAT + Multisampled: false + Bind slot: VIEW_tex_brdf_lut => 3 + Sampler 'smp_shadow': + Type: SG_SAMPLERTYPE_COMPARISON + Bind slot: SMP_smp_shadow => 0 + Sampler 'smp_ao': + Type: SG_SAMPLERTYPE_FILTERING + Bind slot: SMP_smp_ao => 3 + Sampler 'smp_ibl_spec': + Type: SG_SAMPLERTYPE_FILTERING + Bind slot: SMP_smp_ibl_spec => 1 + Sampler 'smp_brdf_lut': + Type: SG_SAMPLERTYPE_FILTERING + Bind slot: SMP_smp_brdf_lut => 2 +*/ +#if !defined(SOKOL_GFX_INCLUDED) +#error "Please include sokol_gfx.h before cube.glsl.h" +#endif +#if !defined(SOKOL_SHDC_ALIGN) +#if defined(_MSC_VER) +#define SOKOL_SHDC_ALIGN(a) __declspec(align(a)) +#else +#define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) +#endif +#endif +#define ATTR_cube_in_pos (0) +#define UB_ub_draw (2) +#define UB_ub_frame (0) +#define UB_ub_pass (1) +#define VIEW_cube_instances (0) +#define VIEW_tex_shadow (1) +#define VIEW_tex_ao (4) +#define VIEW_tex_ibl_spec (2) +#define VIEW_tex_brdf_lut (3) +#define SMP_smp_shadow (0) +#define SMP_smp_ao (3) +#define SMP_smp_ibl_spec (1) +#define SMP_smp_brdf_lut (2) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct ub_draw_t { + int inst_base[4]; +} ub_draw_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct ub_frame_t { + Mat4 view; + Mat4 proj; + Mat4 view_proj; + Mat4 inv_view_proj; + Vec4 camera_pos; + Vec4 viewport; +} ub_frame_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct ub_pass_t { + Vec4 sun_dir_view; + Vec4 sun_color; + int flags[4]; + Vec4 cascade_far_view_z; + Mat4 cascade_matrices[3]; + Mat4 view; + Vec4 camera_pos_world; + Vec4 sh[9]; + Vec4 ibl_params; +} ub_pass_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct cube_instance_t { + Vec4 xform_row0; + Vec4 xform_row1; + Vec4 xform_row2; + Vec4 base_color; + Vec4 material; +} cube_instance_t; +#pragma pack(pop) +/* + #version 430 + + struct cube_instance + { + vec4 xform_row0; + vec4 xform_row1; + vec4 xform_row2; + vec4 base_color; + vec4 material; + }; + + layout(binding = 0, std430) readonly buffer cube_instances + { + cube_instance instances[]; + } _15; + + uniform ivec4 ub_draw[1]; + uniform vec4 ub_frame[18]; + layout(location = 0) in vec3 in_pos; + layout(location = 0) out vec3 v_view_pos; + layout(location = 1) out vec3 v_world_pos; + layout(location = 2) flat out vec4 v_base_color; + layout(location = 3) flat out vec4 v_material; + + void main() + { + int _30 = ub_draw[0].x + gl_InstanceID; + vec4 _58 = vec4(in_pos, 1.0); + float _64 = dot(_15.instances[_30].xform_row0, _58); + float _68 = dot(_15.instances[_30].xform_row1, _58); + float _72 = dot(_15.instances[_30].xform_row2, _58); + vec4 _87 = mat4(ub_frame[0], ub_frame[1], ub_frame[2], ub_frame[3]) * vec4(_64, _68, _72, 1.0); + v_view_pos = _87.xyz; + v_world_pos = vec3(_64, _68, _72); + v_base_color = _15.instances[_30].base_color; + v_material = _15.instances[_30].material; + gl_Position = mat4(ub_frame[4], ub_frame[5], ub_frame[6], ub_frame[7]) * _87; + } + +*/ +static const uint8_t vs_source_glsl430[1126] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x63,0x75,0x62,0x65,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f, + 0x77,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x62,0x61,0x73, + 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x34,0x20,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a, + 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d, + 0x20,0x30,0x2c,0x20,0x73,0x74,0x64,0x34,0x33,0x30,0x29,0x20,0x72,0x65,0x61,0x64, + 0x6f,0x6e,0x6c,0x79,0x20,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x63,0x75,0x62,0x65, + 0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x63,0x75,0x62,0x65,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20,0x69, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x5d,0x3b,0x0a,0x7d,0x20,0x5f,0x31, + 0x35,0x3b,0x0a,0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x69,0x76,0x65,0x63, + 0x34,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x5b,0x31,0x5d,0x3b,0x0a,0x75,0x6e, + 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x66,0x72, + 0x61,0x6d,0x65,0x5b,0x31,0x38,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28, + 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e, + 0x20,0x76,0x65,0x63,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, + 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x6f,0x75,0x74, + 0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f, + 0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69, + 0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x6f,0x75,0x74, + 0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74, + 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x33,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x6f,0x75, + 0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61, + 0x6c,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x33,0x30,0x20,0x3d,0x20, + 0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x5b,0x30,0x5d,0x2e,0x78,0x20,0x2b,0x20,0x67, + 0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x35,0x38,0x20,0x3d,0x20,0x76,0x65,0x63, + 0x34,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x34,0x20,0x3d,0x20, + 0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77, + 0x30,0x2c,0x20,0x5f,0x35,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x36,0x38,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35, + 0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e, + 0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2c,0x20,0x5f,0x35,0x38,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x32,0x20, + 0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72, + 0x6f,0x77,0x32,0x2c,0x20,0x5f,0x35,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x34,0x20,0x5f,0x38,0x37,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x75, + 0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x30,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66, + 0x72,0x61,0x6d,0x65,0x5b,0x31,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d, + 0x65,0x5b,0x32,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x33, + 0x5d,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x36,0x34,0x2c,0x20,0x5f, + 0x36,0x38,0x2c,0x20,0x5f,0x37,0x32,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x20,0x3d,0x20, + 0x5f,0x38,0x37,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28, + 0x5f,0x36,0x34,0x2c,0x20,0x5f,0x36,0x38,0x2c,0x20,0x5f,0x37,0x32,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73, + 0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c, + 0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73, + 0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20, + 0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b, + 0x34,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x35,0x5d,0x2c, + 0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x36,0x5d,0x2c,0x20,0x75,0x62, + 0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x37,0x5d,0x29,0x20,0x2a,0x20,0x5f,0x38,0x37, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + #version 430 + + struct ub_pass + { + vec4 sun_dir_view; + vec4 sun_color; + ivec4 flags; + vec4 cascade_far_view_z; + mat4 cascade_matrices[3]; + mat4 view; + vec4 camera_pos_world; + vec4 sh[9]; + vec4 ibl_params; + }; + + uniform ub_pass _706; + + layout(binding = 0) uniform sampler2D tex_ao_smp_ao; + layout(binding = 1) uniform sampler2DArrayShadow tex_shadow_smp_shadow; + layout(binding = 2) uniform samplerCube tex_ibl_spec_smp_ibl_spec; + layout(binding = 3) uniform sampler2D tex_brdf_lut_smp_brdf_lut; + + layout(location = 0) in vec3 v_view_pos; + layout(location = 0) out vec4 out_color; + layout(location = 1) in vec3 v_world_pos; + layout(location = 2) flat in vec4 v_base_color; + layout(location = 3) flat in vec4 v_material; + + float sampleShadowPCF(int cascade, vec3 light_uv, float bias) + { + float _528 = float(cascade); + float _533 = light_uv.z - bias; + float _549 = light_uv.x - 0.00048828125; + float _553 = light_uv.y - 0.00048828125; + float _583 = light_uv.x + 0.00048828125; + float _651 = light_uv.y + 0.00048828125; + return ((((((((texture(tex_shadow_smp_shadow, vec4(vec4(_549, _553, _528, _533).xyz, _533)) + texture(tex_shadow_smp_shadow, vec4(vec4(light_uv.x, _553, _528, _533).xyz, _533))) + texture(tex_shadow_smp_shadow, vec4(vec4(_583, _553, _528, _533).xyz, _533))) + texture(tex_shadow_smp_shadow, vec4(vec4(_549, light_uv.y, _528, _533).xyz, _533))) + texture(tex_shadow_smp_shadow, vec4(vec4(light_uv.xy, _528, _533).xyz, _533))) + texture(tex_shadow_smp_shadow, vec4(vec4(_583, light_uv.y, _528, _533).xyz, _533))) + texture(tex_shadow_smp_shadow, vec4(vec4(_549, _651, _528, _533).xyz, _533))) + texture(tex_shadow_smp_shadow, vec4(vec4(light_uv.x, _651, _528, _533).xyz, _533))) + texture(tex_shadow_smp_shadow, vec4(vec4(_583, _651, _528, _533).xyz, _533))) * 0.111111111938953399658203125; + } + + float sampleCascade(int cascade, vec3 world_pos, float n_dot_l) + { + vec4 _716 = _706.cascade_matrices[cascade] * vec4(world_pos, 1.0); + vec3 _723 = _716.xyz / vec3(_716.w); + vec3 _741 = vec3((_723.x * 0.5) + 0.5, ((_723.y * _706.cascade_far_view_z.w) * 0.5) + 0.5, _723.z); + bool _745 = any(lessThan(_741, vec3(0.0))); + bool _752; + if (!_745) + { + _752 = any(greaterThan(_741, vec3(1.0))); + } + else + { + _752 = _745; + } + if (_752) + { + return 1.0; + } + float _759 = clamp(n_dot_l, 0.001000000047497451305389404296875, 1.0); + int param = cascade; + vec3 param_1 = _741; + float param_2 = clamp(0.001000000047497451305389404296875 * (sqrt(1.0 - (_759 * _759)) / _759), 0.0005000000237487256526947021484375, 0.0500000007450580596923828125); + float pcf = sampleShadowPCF(param, param_1, param_2); + if (cascade == 2) + { + vec2 _790 = _741.xy; + vec2 _795 = min(_790, vec2(1.0) - _790); + pcf = mix(1.0, pcf, clamp(min(_795.x, _795.y) * 10.0, 0.0, 1.0)); + } + return pcf; + } + + float sampleShadowCascaded(vec3 world_pos, float n_dot_l, float view_z) + { + int cascade = 2; + if (view_z < _706.cascade_far_view_z.x) + { + cascade = 0; + } + else + { + if (view_z < _706.cascade_far_view_z.y) + { + cascade = 1; + } + } + int param = cascade; + vec3 param_1 = world_pos; + float param_2 = n_dot_l; + float shadow = sampleCascade(param, param_1, param_2); + if (cascade < 2) + { + float _840; + if (cascade == 0) + { + _840 = _706.cascade_far_view_z.x; + } + else + { + _840 = _706.cascade_far_view_z.y; + } + float _852; + if (cascade == 0) + { + _852 = 0.0; + } + else + { + _852 = _706.cascade_far_view_z.x; + } + float _863 = mix(_840, _852, 0.100000001490116119384765625); + if (view_z > _863) + { + int param_3 = cascade + 1; + vec3 param_4 = world_pos; + float param_5 = n_dot_l; + shadow = mix(shadow, sampleCascade(param_3, param_4, param_5), (view_z - _863) / (_840 - _863)); + } + } + return shadow; + } + + float pbrDistributionGGX(float n_dot_h, float alpha) + { + float _106 = alpha * alpha; + float _115 = ((n_dot_h * n_dot_h) * (_106 - 1.0)) + 1.0; + return _106 / ((3.1415927410125732421875 * _115) * _115); + } + + float pbrVisibilitySmithCorrelated(float n_dot_v, float n_dot_l, float alpha) + { + float _128 = alpha * alpha; + float _135 = 1.0 - _128; + return 0.5 / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _135) + _128)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _135) + _128))) + 9.9999997473787516355514526367188e-06); + } + + vec3 pbrFresnelSchlick(float v_dot_h, vec3 f0) + { + float _164 = 1.0 - v_dot_h; + float _168 = _164 * _164; + return f0 + ((vec3(1.0) - f0) * ((_168 * _168) * _164)); + } + + vec3 brdf_evaluate(vec3 N, vec3 V, vec3 L, vec3 sun_radiance, vec3 base_color, float metallic, float roughness) + { + float _187 = max(dot(N, L), 0.0); + vec3 _198 = normalize(V + L); + float _212 = max(roughness, 0.04500000178813934326171875); + float _216 = _212 * _212; + float param = max(dot(N, _198), 0.0); + float param_1 = _216; + float param_2 = max(dot(N, V), 9.9999997473787516355514526367188e-05); + float param_3 = _187; + float param_4 = _216; + float param_5 = max(dot(V, _198), 0.0); + vec3 param_6 = mix(vec3(0.039999999105930328369140625), base_color, vec3(metallic)); + vec3 _243 = pbrFresnelSchlick(param_5, param_6); + return ((((((vec3(1.0) - _243) * (1.0 - metallic)) * base_color) * vec3(0.3183098733425140380859375)) + (_243 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _187; + } + + vec3 pbrEvaluateShIrradiance(vec3 N, vec4 sh[9]) + { + vec3 _398 = ((((((((sh[0].xyz * 0.2820948064327239990234375) + (sh[1].xyz * ((-0.48860251903533935546875) * N.y))) + (sh[2].xyz * (0.48860251903533935546875 * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125 * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125 * (((3.0 * N.z) * N.z) - 1.0)))) + (sh[7].xyz * (((-1.09254848957061767578125) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625 * ((N.x * N.x) - (N.y * N.y)))); + return _398; + } + + vec3 pbrEvaluateIbl(vec3 N_world, vec3 V_world, vec3 base_color, float metallic, float roughness, vec4 sh[9], float max_lod, samplerCube SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, sampler2D SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut) + { + float _405 = clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05, 1.0); + vec3 _415 = mix(vec3(0.039999999105930328369140625), base_color, vec3(metallic)); + vec3 param = N_world; + vec4 param_1[9] = sh; + vec4 _481 = texture(SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut, vec2(_405, roughness)); + return (((((vec3(1.0) - (_415 + ((max(vec3(1.0 - roughness), _415) - _415) * pow(max(0.0, 1.0 - _405), 5.0)))) * (1.0 - metallic)) * base_color) * max(pbrEvaluateShIrradiance(param, param_1), vec3(0.0))) * vec3(0.3183098733425140380859375)) + (textureLod(SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, reflect(-V_world, N_world), roughness * max_lod).xyz * ((_415 * _481.x) + vec3(_481.y))); + } + + vec3 pbrEvaluateAmbient(bool iblEnabled, vec3 N_world, vec3 V_world, vec3 base_color, float metallic, float roughness, float flat_strength, vec4 sh[9], float max_lod, samplerCube SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, sampler2D SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut) + { + vec3 result = base_color * flat_strength; + if (iblEnabled) + { + vec3 param = N_world; + vec3 param_1 = V_world; + vec3 param_2 = base_color; + float param_3 = metallic; + float param_4 = roughness; + vec4 param_5[9] = sh; + float param_6 = max_lod; + result = pbrEvaluateIbl(param, param_1, param_2, param_3, param_4, param_5, param_6, SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut); + } + return result; + } + + void main() + { + vec3 _895 = dFdx(v_view_pos); + vec3 _898 = dFdy(v_view_pos); + vec3 _907 = normalize(cross(_898 * (-_706.cascade_far_view_z.w), _895)); + float _912 = -v_view_pos.z; + if (_706.flags.x == 1) + { + float _923 = clamp(v_view_pos.z * (-0.0199999995529651641845703125), 0.0, 1.0); + out_color = vec4(_923, _923, _923, 1.0); + return; + } + if (_706.flags.x == 2) + { + int cascade = 2; + if (_912 < _706.cascade_far_view_z.x) + { + cascade = 0; + } + else + { + if (_912 < _706.cascade_far_view_z.y) + { + cascade = 1; + } + } + vec4 _958 = _706.cascade_matrices[cascade] * vec4(v_world_pos, 1.0); + vec3 _965 = _958.xyz / vec3(_958.w); + vec3 _982 = vec3((_965.x * 0.5) + 0.5, ((_965.y * _706.cascade_far_view_z.w) * 0.5) + 0.5, _965.z); + bool _986 = any(lessThan(_982, vec3(0.0))); + bool _993; + if (!_986) + { + _993 = any(greaterThan(_982, vec3(1.0))); + } + else + { + _993 = _986; + } + vec3 tint = vec3(1.0); + if (!_993) + { + if (cascade == 0) + { + tint = vec3(1.0, 0.4000000059604644775390625, 0.4000000059604644775390625); + } + else + { + if (cascade == 1) + { + tint = vec3(0.4000000059604644775390625, 1.0, 0.4000000059604644775390625); + } + else + { + tint = vec3(0.4000000059604644775390625, 0.4000000059604644775390625, 1.0); + } + } + } + out_color = vec4(tint, 1.0); + return; + } + if (_706.flags.x == 3) + { + out_color = vec4((_907 * 0.5) + vec3(0.5), 1.0); + return; + } + vec4 _1053 = textureLod(tex_ao_smp_ao, gl_FragCoord.xy / vec2(textureSize(tex_ao_smp_ao, 0)), 0.0); + float _1054 = _1053.x; + if (_706.flags.x == 4) + { + out_color = vec4(_1054, _1054, _1054, 1.0); + return; + } + vec3 _1072 = normalize(_706.sun_dir_view.xyz); + vec3 param = v_world_pos; + float param_1 = max(dot(_907, _1072), 0.0); + float param_2 = _912; + vec3 param_3 = _907; + vec3 param_4 = normalize(-v_view_pos); + vec3 param_5 = _1072; + vec3 param_6 = _706.sun_color.xyz * sampleShadowCascaded(param, param_1, param_2); + vec3 param_7 = v_base_color.xyz; + float param_8 = v_material.x; + float param_9 = v_material.y; + bool param_10 = _706.ibl_params.y > 0.5; + vec3 param_11 = normalize(transpose(mat3(_706.view[0].xyz, _706.view[1].xyz, _706.view[2].xyz)) * _907); + vec3 param_12 = normalize(_706.camera_pos_world.xyz - v_world_pos); + vec3 param_13 = v_base_color.xyz; + float param_14 = v_material.x; + float param_15 = v_material.y; + float param_16 = _706.sun_color.w; + vec4 param_17[9]; + param_17[0] = _706.sh[0]; + param_17[1] = _706.sh[1]; + param_17[2] = _706.sh[2]; + param_17[3] = _706.sh[3]; + param_17[4] = _706.sh[4]; + param_17[5] = _706.sh[5]; + param_17[6] = _706.sh[6]; + param_17[7] = _706.sh[7]; + param_17[8] = _706.sh[8]; + float param_18 = _706.ibl_params.x; + out_color = vec4((brdf_evaluate(param_3, param_4, param_5, param_6, param_7, param_8, param_9) + (pbrEvaluateAmbient(param_10, param_11, param_12, param_13, param_14, param_15, param_16, param_17, param_18, tex_ibl_spec_smp_ibl_spec, tex_brdf_lut_smp_brdf_lut) * _1054)) * v_base_color.w, v_base_color.w); + } + +*/ +static const uint8_t fs_source_glsl430[11675] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f, + 0x76,0x69,0x65,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x73, + 0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x76, + 0x65,0x63,0x34,0x20,0x66,0x6c,0x61,0x67,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x74,0x34, + 0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65, + 0x73,0x5b,0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x74,0x34,0x20,0x76, + 0x69,0x65,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x61, + 0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72, + 0x61,0x6d,0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d, + 0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x20,0x5f,0x37,0x30,0x36,0x3b,0x0a,0x0a, + 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d, + 0x20,0x30,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x5f,0x73,0x6d,0x70, + 0x5f,0x61,0x6f,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64, + 0x69,0x6e,0x67,0x20,0x3d,0x20,0x31,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d, + 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x41,0x72,0x72,0x61,0x79,0x53, + 0x68,0x61,0x64,0x6f,0x77,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x6c,0x61,0x79, + 0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x32,0x29, + 0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72, + 0x43,0x75,0x62,0x65,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65, + 0x63,0x5f,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x3b,0x0a, + 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d, + 0x20,0x33,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, + 0x75,0x74,0x5f,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x3b, + 0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f, + 0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76, + 0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75, + 0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20, + 0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74, + 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33, + 0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x32,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20, + 0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x33,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20, + 0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x0a,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50, + 0x43,0x46,0x28,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20, + 0x76,0x65,0x63,0x33,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x62,0x69,0x61,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x32,0x38,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x33,0x33,0x20,0x3d,0x20,0x6c, + 0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x7a,0x20,0x2d,0x20,0x62,0x69,0x61,0x73, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x34,0x39, + 0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20,0x2d,0x20, + 0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x35,0x33,0x20,0x3d,0x20, + 0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x20,0x2d,0x20,0x30,0x2e,0x30, + 0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x38,0x33,0x20,0x3d,0x20,0x6c,0x69,0x67, + 0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34, + 0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x36,0x35,0x31,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f, + 0x75,0x76,0x2e,0x79,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32, + 0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x74,0x65,0x78,0x74,0x75,0x72,0x65, + 0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63, + 0x34,0x28,0x5f,0x35,0x34,0x39,0x2c,0x20,0x5f,0x35,0x35,0x33,0x2c,0x20,0x5f,0x35, + 0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f, + 0x35,0x33,0x33,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28, + 0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34, + 0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20,0x5f,0x35,0x35, + 0x33,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x2e,0x78, + 0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65, + 0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63, + 0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x5f,0x35,0x38,0x33,0x2c,0x20,0x5f,0x35,0x35, + 0x33,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x2e,0x78, + 0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65, + 0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63, + 0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x5f,0x35,0x34,0x39,0x2c,0x20,0x6c,0x69,0x67, + 0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f, + 0x35,0x33,0x33,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29, + 0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x6c,0x69,0x67, + 0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x79,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20, + 0x5f,0x35,0x33,0x33,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29, + 0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x5f,0x35, + 0x38,0x33,0x2c,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20, + 0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x2e,0x78,0x79,0x7a,0x2c, + 0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75, + 0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d, + 0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76, + 0x65,0x63,0x34,0x28,0x5f,0x35,0x34,0x39,0x2c,0x20,0x5f,0x36,0x35,0x31,0x2c,0x20, + 0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x2e,0x78,0x79,0x7a,0x2c, + 0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75, + 0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d, + 0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76, + 0x65,0x63,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20, + 0x5f,0x36,0x35,0x31,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33, + 0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x29,0x20,0x2b, + 0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20, + 0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x5f,0x35,0x38,0x33,0x2c,0x20, + 0x5f,0x36,0x35,0x31,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33, + 0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x29,0x20,0x2a, + 0x20,0x30,0x2e,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x39,0x33,0x38,0x39, + 0x35,0x33,0x33,0x39,0x39,0x36,0x35,0x38,0x32,0x30,0x33,0x31,0x32,0x35,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43, + 0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70, + 0x6f,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f, + 0x6c,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x37, + 0x31,0x36,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x5d,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x77,0x6f,0x72,0x6c,0x64, + 0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x65,0x63,0x33,0x20,0x5f,0x37,0x32,0x33,0x20,0x3d,0x20,0x5f,0x37,0x31,0x36, + 0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x37,0x31,0x36, + 0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x37, + 0x34,0x31,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x28,0x5f,0x37,0x32,0x33,0x2e, + 0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20, + 0x28,0x28,0x5f,0x37,0x32,0x33,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x37,0x30,0x36,0x2e, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77, + 0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30, + 0x2e,0x35,0x2c,0x20,0x5f,0x37,0x32,0x33,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x37,0x34,0x35,0x20,0x3d,0x20,0x61,0x6e,0x79, + 0x28,0x6c,0x65,0x73,0x73,0x54,0x68,0x61,0x6e,0x28,0x5f,0x37,0x34,0x31,0x2c,0x20, + 0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x37,0x35,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x21,0x5f,0x37,0x34,0x35,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x37,0x35,0x32,0x20,0x3d,0x20, + 0x61,0x6e,0x79,0x28,0x67,0x72,0x65,0x61,0x74,0x65,0x72,0x54,0x68,0x61,0x6e,0x28, + 0x5f,0x37,0x34,0x31,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x29, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, + 0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x5f,0x37,0x35,0x32,0x20,0x3d,0x20,0x5f,0x37,0x34,0x35,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x35,0x32,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x35,0x39,0x20, + 0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c, + 0x20,0x30,0x2e,0x30,0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x34,0x37,0x34, + 0x39,0x37,0x34,0x35,0x31,0x33,0x30,0x35,0x33,0x38,0x39,0x34,0x30,0x34,0x32,0x39, + 0x36,0x38,0x37,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x37,0x34,0x31,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20, + 0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x30,0x2e,0x30,0x30,0x31,0x30,0x30,0x30, + 0x30,0x30,0x30,0x30,0x34,0x37,0x34,0x39,0x37,0x34,0x35,0x31,0x33,0x30,0x35,0x33, + 0x38,0x39,0x34,0x30,0x34,0x32,0x39,0x36,0x38,0x37,0x35,0x20,0x2a,0x20,0x28,0x73, + 0x71,0x72,0x74,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x28,0x5f,0x37,0x35,0x39,0x20, + 0x2a,0x20,0x5f,0x37,0x35,0x39,0x29,0x29,0x20,0x2f,0x20,0x5f,0x37,0x35,0x39,0x29, + 0x2c,0x20,0x30,0x2e,0x30,0x30,0x30,0x35,0x30,0x30,0x30,0x30,0x30,0x30,0x32,0x33, + 0x37,0x34,0x38,0x37,0x32,0x35,0x36,0x35,0x32,0x36,0x39,0x34,0x37,0x30,0x32,0x31, + 0x34,0x38,0x34,0x33,0x37,0x35,0x2c,0x20,0x30,0x2e,0x30,0x35,0x30,0x30,0x30,0x30, + 0x30,0x30,0x30,0x37,0x34,0x35,0x30,0x35,0x38,0x30,0x35,0x39,0x36,0x39,0x32,0x33, + 0x38,0x32,0x38,0x31,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53, + 0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x37,0x39,0x30, + 0x20,0x3d,0x20,0x5f,0x37,0x34,0x31,0x2e,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x37,0x39,0x35,0x20,0x3d,0x20, + 0x6d,0x69,0x6e,0x28,0x5f,0x37,0x39,0x30,0x2c,0x20,0x76,0x65,0x63,0x32,0x28,0x31, + 0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x37,0x39,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x31, + 0x2e,0x30,0x2c,0x20,0x70,0x63,0x66,0x2c,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6d, + 0x69,0x6e,0x28,0x5f,0x37,0x39,0x35,0x2e,0x78,0x2c,0x20,0x5f,0x37,0x39,0x35,0x2e, + 0x79,0x29,0x20,0x2a,0x20,0x31,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20, + 0x31,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x70,0x63,0x66,0x3b,0x0a,0x7d,0x0a,0x0a, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64, + 0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x76,0x65,0x63,0x33,0x20, + 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e, + 0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20, + 0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72, + 0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20, + 0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72, + 0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x29,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61, + 0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3c,0x20,0x32, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x34,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20, + 0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x34,0x30, + 0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, + 0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x34,0x30,0x20, + 0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66, + 0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x35,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d, + 0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x35,0x32,0x20, + 0x3d,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x5f,0x38,0x35,0x32,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77, + 0x5f,0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38, + 0x36,0x33,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x5f,0x38,0x34,0x30,0x2c,0x20,0x5f, + 0x38,0x35,0x32,0x2c,0x20,0x30,0x2e,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x31, + 0x34,0x39,0x30,0x31,0x31,0x36,0x31,0x31,0x39,0x33,0x38,0x34,0x37,0x36,0x35,0x36, + 0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3e,0x20,0x5f,0x38,0x36,0x33,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x2b,0x20,0x31,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35, + 0x20,0x3d,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d, + 0x20,0x6d,0x69,0x78,0x28,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x35,0x29,0x2c,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x2d, + 0x20,0x5f,0x38,0x36,0x33,0x29,0x20,0x2f,0x20,0x28,0x5f,0x38,0x34,0x30,0x20,0x2d, + 0x20,0x5f,0x38,0x36,0x33,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x7d,0x0a,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75, + 0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f, + 0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70, + 0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x30,0x36,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61, + 0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x31,0x35,0x20,0x3d,0x20,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68, + 0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x29,0x20,0x2a,0x20,0x28,0x5f, + 0x31,0x30,0x36,0x20,0x2d,0x20,0x31,0x2e,0x30,0x29,0x29,0x20,0x2b,0x20,0x31,0x2e, + 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31, + 0x30,0x36,0x20,0x2f,0x20,0x28,0x28,0x33,0x2e,0x31,0x34,0x31,0x35,0x39,0x32,0x37, + 0x34,0x31,0x30,0x31,0x32,0x35,0x37,0x33,0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x20, + 0x2a,0x20,0x5f,0x31,0x31,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x31,0x35,0x29,0x3b, + 0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x56,0x69,0x73, + 0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72, + 0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64, + 0x6f,0x74,0x5f,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f, + 0x74,0x5f,0x6c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70,0x68,0x61, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x32,0x38,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70, + 0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x33,0x35,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f,0x31,0x32,0x38,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x30,0x2e,0x35,0x20, + 0x2f,0x20,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x73, + 0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20, + 0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x29,0x20,0x2a,0x20,0x5f,0x31,0x33,0x35,0x29, + 0x20,0x2b,0x20,0x5f,0x31,0x32,0x38,0x29,0x29,0x20,0x2b,0x20,0x28,0x6e,0x5f,0x64, + 0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f, + 0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x29, + 0x20,0x2a,0x20,0x5f,0x31,0x33,0x35,0x29,0x20,0x2b,0x20,0x5f,0x31,0x32,0x38,0x29, + 0x29,0x29,0x20,0x2b,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37, + 0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36, + 0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x29,0x3b,0x0a,0x7d,0x0a,0x0a, + 0x76,0x65,0x63,0x33,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53, + 0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x64, + 0x6f,0x74,0x5f,0x68,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x66,0x30,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x34,0x20, + 0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x38,0x20, + 0x3d,0x20,0x5f,0x31,0x36,0x34,0x20,0x2a,0x20,0x5f,0x31,0x36,0x34,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x30,0x20,0x2b,0x20,0x28, + 0x28,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x66,0x30,0x29, + 0x20,0x2a,0x20,0x28,0x28,0x5f,0x31,0x36,0x38,0x20,0x2a,0x20,0x5f,0x31,0x36,0x38, + 0x29,0x20,0x2a,0x20,0x5f,0x31,0x36,0x34,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76, + 0x65,0x63,0x33,0x20,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74, + 0x65,0x28,0x76,0x65,0x63,0x33,0x20,0x4e,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x56, + 0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x4c,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x73, + 0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x2c,0x20,0x76,0x65,0x63, + 0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x38,0x37,0x20, + 0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x4c,0x29,0x2c, + 0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, + 0x5f,0x31,0x39,0x38,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65, + 0x28,0x56,0x20,0x2b,0x20,0x4c,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x32,0x31,0x32,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x72,0x6f, + 0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x30,0x2e,0x30,0x34,0x35,0x30,0x30, + 0x30,0x30,0x30,0x31,0x37,0x38,0x38,0x31,0x33,0x39,0x33,0x34,0x33,0x32,0x36,0x31, + 0x37,0x31,0x38,0x37,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x32,0x31,0x36,0x20,0x3d,0x20,0x5f,0x32,0x31,0x32,0x20,0x2a,0x20, + 0x5f,0x32,0x31,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28, + 0x4e,0x2c,0x20,0x5f,0x31,0x39,0x38,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x20,0x3d,0x20,0x5f,0x32,0x31,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6d,0x61, + 0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x56,0x29,0x2c,0x20,0x39,0x2e,0x39, + 0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33, + 0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d, + 0x30,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31,0x38,0x37,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, + 0x20,0x3d,0x20,0x5f,0x32,0x31,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x6d,0x61,0x78, + 0x28,0x64,0x6f,0x74,0x28,0x56,0x2c,0x20,0x5f,0x31,0x39,0x38,0x29,0x2c,0x20,0x30, + 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x76,0x65,0x63,0x33, + 0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39, + 0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c, + 0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x76,0x65,0x63, + 0x33,0x28,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x32,0x34,0x33,0x20,0x3d,0x20,0x70,0x62, + 0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28, + 0x28,0x28,0x28,0x28,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20, + 0x5f,0x32,0x34,0x33,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d, + 0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x33,0x28,0x30, + 0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34, + 0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x29,0x29,0x20,0x2b,0x20,0x28, + 0x5f,0x32,0x34,0x33,0x20,0x2a,0x20,0x28,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72, + 0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x70,0x61,0x72,0x61,0x6d, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x20,0x2a,0x20,0x70,0x62,0x72, + 0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43, + 0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x34,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61, + 0x64,0x69,0x61,0x6e,0x63,0x65,0x29,0x20,0x2a,0x20,0x5f,0x31,0x38,0x37,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75, + 0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28, + 0x76,0x65,0x63,0x33,0x20,0x4e,0x2c,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b, + 0x39,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f, + 0x33,0x39,0x38,0x20,0x3d,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x73,0x68, + 0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x30,0x2e,0x32,0x38,0x32,0x30, + 0x39,0x34,0x38,0x30,0x36,0x34,0x33,0x32,0x37,0x32,0x33,0x39,0x39,0x39,0x30,0x32, + 0x33,0x34,0x33,0x37,0x35,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x31,0x5d,0x2e, + 0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30, + 0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38, + 0x37,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28, + 0x73,0x68,0x5b,0x32,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x34, + 0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35, + 0x35,0x34,0x36,0x38,0x37,0x35,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20, + 0x2b,0x20,0x28,0x73,0x68,0x5b,0x33,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28, + 0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35, + 0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x4e, + 0x2e,0x78,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x34,0x5d,0x2e,0x78, + 0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34, + 0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35, + 0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29, + 0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x35,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, + 0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35, + 0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x29,0x20,0x2a, + 0x20,0x4e,0x2e,0x79,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b, + 0x20,0x28,0x73,0x68,0x5b,0x36,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30, + 0x2e,0x33,0x31,0x35,0x33,0x39,0x31,0x35,0x37,0x30,0x33,0x32,0x39,0x36,0x36,0x36, + 0x31,0x33,0x37,0x36,0x39,0x35,0x33,0x31,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x28, + 0x33,0x2e,0x30,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a, + 0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x29,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73, + 0x68,0x5b,0x37,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31, + 0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37, + 0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29, + 0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b, + 0x38,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x35,0x34,0x36,0x32, + 0x37,0x34,0x32,0x34,0x34,0x37,0x38,0x35,0x33,0x30,0x38,0x38,0x33,0x37,0x38,0x39, + 0x30,0x36,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x4e,0x2e,0x78,0x20,0x2a,0x20,0x4e, + 0x2e,0x78,0x29,0x20,0x2d,0x20,0x28,0x4e,0x2e,0x79,0x20,0x2a,0x20,0x4e,0x2e,0x79, + 0x29,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x5f,0x33,0x39,0x38,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x70, + 0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x76,0x65, + 0x63,0x33,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x76,0x65,0x63,0x33, + 0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x62, + 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x76,0x65,0x63,0x34, + 0x20,0x73,0x68,0x5b,0x39,0x5d,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61, + 0x78,0x5f,0x6c,0x6f,0x64,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x75, + 0x62,0x65,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43, + 0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f, + 0x63,0x75,0x62,0x65,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62, + 0x65,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x53,0x50,0x49, + 0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65, + 0x64,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70, + 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x30,0x35,0x20,0x3d,0x20,0x63,0x6c, + 0x61,0x6d,0x70,0x28,0x64,0x6f,0x74,0x28,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c, + 0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39, + 0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35, + 0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35, + 0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, + 0x20,0x5f,0x34,0x31,0x35,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x76,0x65,0x63,0x33, + 0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39, + 0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c, + 0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x76,0x65,0x63, + 0x33,0x28,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x5b,0x39,0x5d,0x20,0x3d,0x20,0x73,0x68, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x34,0x38,0x31,0x20, + 0x3d,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x53,0x50,0x49,0x52,0x56,0x5f, + 0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65, + 0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72, + 0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x76,0x65,0x63,0x32,0x28,0x5f,0x34,0x30, + 0x35,0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28, + 0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x28,0x5f,0x34,0x31, + 0x35,0x20,0x2b,0x20,0x28,0x28,0x6d,0x61,0x78,0x28,0x76,0x65,0x63,0x33,0x28,0x31, + 0x2e,0x30,0x20,0x2d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x2c, + 0x20,0x5f,0x34,0x31,0x35,0x29,0x20,0x2d,0x20,0x5f,0x34,0x31,0x35,0x29,0x20,0x2a, + 0x20,0x70,0x6f,0x77,0x28,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e, + 0x30,0x20,0x2d,0x20,0x5f,0x34,0x30,0x35,0x29,0x2c,0x20,0x35,0x2e,0x30,0x29,0x29, + 0x29,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61, + 0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x6d,0x61,0x78,0x28,0x70,0x62,0x72,0x45,0x76, + 0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e, + 0x63,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x29,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x29,0x20, + 0x2a,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38, + 0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33, + 0x37,0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x4c, + 0x6f,0x64,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43, + 0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f, + 0x63,0x75,0x62,0x65,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62, + 0x65,0x2c,0x20,0x72,0x65,0x66,0x6c,0x65,0x63,0x74,0x28,0x2d,0x56,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x2c,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x72, + 0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x20,0x2a,0x20,0x6d,0x61,0x78,0x5f,0x6c, + 0x6f,0x64,0x29,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x34,0x31,0x35, + 0x20,0x2a,0x20,0x5f,0x34,0x38,0x31,0x2e,0x78,0x29,0x20,0x2b,0x20,0x76,0x65,0x63, + 0x33,0x28,0x5f,0x34,0x38,0x31,0x2e,0x79,0x29,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a, + 0x76,0x65,0x63,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65, + 0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x62,0x6f,0x6f,0x6c,0x20,0x69,0x62,0x6c, + 0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x4e,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x56,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61, + 0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67, + 0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x66,0x6c,0x61, + 0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x2c,0x20,0x76,0x65,0x63,0x34, + 0x20,0x73,0x68,0x5b,0x39,0x5d,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61, + 0x78,0x5f,0x6c,0x6f,0x64,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x75, + 0x62,0x65,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43, + 0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f, + 0x63,0x75,0x62,0x65,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62, + 0x65,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x53,0x50,0x49, + 0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65, + 0x64,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70, + 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x33,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x62, + 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x66,0x6c,0x61,0x74, + 0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x6d,0x65, + 0x74,0x61,0x6c,0x6c,0x69,0x63,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20, + 0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x5b, + 0x39,0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d, + 0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x70,0x62,0x72,0x45,0x76, + 0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, + 0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x73, + 0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63, + 0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, + 0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x62, + 0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f, + 0x6c,0x75,0x74,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x38,0x39,0x35,0x20,0x3d,0x20, + 0x64,0x46,0x64,0x78,0x28,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x38,0x39,0x38,0x20, + 0x3d,0x20,0x64,0x46,0x64,0x79,0x28,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f, + 0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x39,0x30, + 0x37,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x63,0x72, + 0x6f,0x73,0x73,0x28,0x5f,0x38,0x39,0x38,0x20,0x2a,0x20,0x28,0x2d,0x5f,0x37,0x30, + 0x36,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x2c,0x20,0x5f,0x38,0x39,0x35,0x29,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x31,0x32,0x20, + 0x3d,0x20,0x2d,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2e,0x7a,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x36,0x2e,0x66,0x6c, + 0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x39,0x32,0x33,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x76,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2e,0x7a,0x20,0x2a,0x20,0x28,0x2d,0x30,0x2e, + 0x30,0x31,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x35,0x35,0x32,0x39,0x36,0x35,0x31, + 0x36,0x34,0x31,0x38,0x34,0x35,0x37,0x30,0x33,0x31,0x32,0x35,0x29,0x2c,0x20,0x30, + 0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65, + 0x63,0x34,0x28,0x5f,0x39,0x32,0x33,0x2c,0x20,0x5f,0x39,0x32,0x33,0x2c,0x20,0x5f, + 0x39,0x32,0x33,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x36,0x2e,0x66,0x6c, + 0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x39,0x31,0x32,0x20,0x3c,0x20,0x5f,0x37, + 0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c, + 0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x39,0x31, + 0x32,0x20,0x3c,0x20,0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f, + 0x39,0x35,0x38,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5d,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x39,0x36,0x35, + 0x20,0x3d,0x20,0x5f,0x39,0x35,0x38,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x76,0x65, + 0x63,0x33,0x28,0x5f,0x39,0x35,0x38,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x39,0x38,0x32,0x20,0x3d,0x20, + 0x76,0x65,0x63,0x33,0x28,0x28,0x5f,0x39,0x36,0x35,0x2e,0x78,0x20,0x2a,0x20,0x30, + 0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x28,0x28,0x5f,0x39,0x36, + 0x35,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29, + 0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f, + 0x39,0x36,0x35,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x39,0x38,0x36,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28, + 0x6c,0x65,0x73,0x73,0x54,0x68,0x61,0x6e,0x28,0x5f,0x39,0x38,0x32,0x2c,0x20,0x76, + 0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x39,0x39,0x33,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x39,0x38,0x36, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x39,0x39,0x33,0x20,0x3d,0x20,0x61, + 0x6e,0x79,0x28,0x67,0x72,0x65,0x61,0x74,0x65,0x72,0x54,0x68,0x61,0x6e,0x28,0x5f, + 0x39,0x38,0x32,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f, + 0x39,0x39,0x33,0x20,0x3d,0x20,0x5f,0x39,0x38,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x33,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x31, + 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x21,0x5f,0x39,0x39,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69, + 0x6e,0x74,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x2c,0x20,0x30, + 0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34, + 0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x34,0x30, + 0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37, + 0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74, + 0x69,0x6e,0x74,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x34,0x30,0x30, + 0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35, + 0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x34, + 0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37, + 0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, + 0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x76, + 0x65,0x63,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39, + 0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c, + 0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34, + 0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20, + 0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x74,0x69,0x6e,0x74,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x5f,0x37,0x30,0x36,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d, + 0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65, + 0x63,0x34,0x28,0x28,0x5f,0x39,0x30,0x37,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20, + 0x2b,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x35,0x29,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x34,0x20,0x5f,0x31,0x30,0x35,0x33,0x20,0x3d,0x20,0x74,0x65,0x78,0x74,0x75,0x72, + 0x65,0x4c,0x6f,0x64,0x28,0x74,0x65,0x78,0x5f,0x61,0x6f,0x5f,0x73,0x6d,0x70,0x5f, + 0x61,0x6f,0x2c,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64, + 0x2e,0x78,0x79,0x20,0x2f,0x20,0x76,0x65,0x63,0x32,0x28,0x74,0x65,0x78,0x74,0x75, + 0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x74,0x65,0x78,0x5f,0x61,0x6f,0x5f,0x73,0x6d, + 0x70,0x5f,0x61,0x6f,0x2c,0x20,0x30,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x34, + 0x20,0x3d,0x20,0x5f,0x31,0x30,0x35,0x33,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x36,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78, + 0x20,0x3d,0x3d,0x20,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, + 0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x31,0x30,0x35,0x34,0x2c,0x20,0x5f,0x31,0x30, + 0x35,0x34,0x2c,0x20,0x5f,0x31,0x30,0x35,0x34,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, + 0x5f,0x31,0x30,0x37,0x32,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a, + 0x65,0x28,0x5f,0x37,0x30,0x36,0x2e,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x76, + 0x69,0x65,0x77,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x76,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28, + 0x64,0x6f,0x74,0x28,0x5f,0x39,0x30,0x37,0x2c,0x20,0x5f,0x31,0x30,0x37,0x32,0x29, + 0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x39,0x31,0x32, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x33,0x20,0x3d,0x20,0x5f,0x39,0x30,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x6e,0x6f, + 0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x2d,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x70,0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x32,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36, + 0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68, + 0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x70,0x61,0x72, + 0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20, + 0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20, + 0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x30,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72, + 0x61,0x6d,0x73,0x2e,0x79,0x20,0x3e,0x20,0x30,0x2e,0x35,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d, + 0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x74,0x72,0x61,0x6e,0x73, + 0x70,0x6f,0x73,0x65,0x28,0x6d,0x61,0x74,0x33,0x28,0x5f,0x37,0x30,0x36,0x2e,0x76, + 0x69,0x65,0x77,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x37,0x30,0x36, + 0x2e,0x76,0x69,0x65,0x77,0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x37, + 0x30,0x36,0x2e,0x76,0x69,0x65,0x77,0x5b,0x32,0x5d,0x2e,0x78,0x79,0x7a,0x29,0x29, + 0x20,0x2a,0x20,0x5f,0x39,0x30,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x6e,0x6f, + 0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x6d, + 0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79, + 0x7a,0x20,0x2d,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x33,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x76,0x5f,0x6d, + 0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20, + 0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36, + 0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x39,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x30,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30, + 0x36,0x2e,0x73,0x68,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x37,0x5b,0x31,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e, + 0x73,0x68,0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x37,0x5b,0x32,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x73,0x68, + 0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x37,0x5b,0x33,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x73,0x68,0x5b,0x33, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b, + 0x34,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x73,0x68,0x5b,0x34,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x35,0x5d, + 0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x73,0x68,0x5b,0x35,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x36,0x5d,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x36,0x2e,0x73,0x68,0x5b,0x36,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x37,0x5d,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x36,0x2e,0x73,0x68,0x5b,0x37,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x38,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30, + 0x36,0x2e,0x73,0x68,0x5b,0x38,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x5f,0x37, + 0x30,0x36,0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, + 0x20,0x76,0x65,0x63,0x34,0x28,0x28,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c, + 0x75,0x61,0x74,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x39,0x29,0x20,0x2b,0x20,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61, + 0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x38,0x2c,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63, + 0x5f,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x74, + 0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x73,0x6d,0x70,0x5f, + 0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x29,0x20,0x2a,0x20,0x5f,0x31,0x30,0x35, + 0x34,0x29,0x29,0x20,0x2a,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x2e,0x77,0x2c,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x2e,0x77,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + struct cube_instance + { + float4 xform_row0; + float4 xform_row1; + float4 xform_row2; + float4 base_color; + float4 material; + }; + + ByteAddressBuffer _15 : register(t0); + cbuffer ub_draw : register(b2) + { + int4 _21_inst_base : packoffset(c0); + }; + + cbuffer ub_frame : register(b0) + { + row_major float4x4 _78_view : packoffset(c0); + row_major float4x4 _78_proj : packoffset(c4); + row_major float4x4 _78_view_proj : packoffset(c8); + row_major float4x4 _78_inv_view_proj : packoffset(c12); + float4 _78_camera_pos : packoffset(c16); + float4 _78_viewport : packoffset(c17); + }; + + + static float4 gl_Position; + static int gl_InstanceIndex; + static float3 in_pos; + static float3 v_view_pos; + static float3 v_world_pos; + static float4 v_base_color; + static float4 v_material; + + struct SPIRV_Cross_Input + { + float3 in_pos : TEXCOORD0; + uint gl_InstanceIndex : SV_InstanceID; + }; + + struct SPIRV_Cross_Output + { + float3 v_view_pos : TEXCOORD0; + float3 v_world_pos : TEXCOORD1; + nointerpolation float4 v_base_color : TEXCOORD2; + nointerpolation float4 v_material : TEXCOORD3; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + cube_instance _33; + _33.xform_row0 = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 80 + 0)); + _33.xform_row1 = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 80 + 16)); + _33.xform_row2 = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 80 + 32)); + _33.base_color = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 80 + 48)); + _33.material = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 80 + 64)); + float4 _58 = float4(in_pos, 1.0f); + float _64 = dot(_33.xform_row0, _58); + float _68 = dot(_33.xform_row1, _58); + float _72 = dot(_33.xform_row2, _58); + float4 _87 = mul(float4(_64, _68, _72, 1.0f), _78_view); + v_view_pos = _87.xyz; + v_world_pos = float3(_64, _68, _72); + v_base_color = _33.base_color; + v_material = _33.material; + gl_Position = mul(_87, _78_proj); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_InstanceIndex = int(stage_input.gl_InstanceIndex); + in_pos = stage_input.in_pos; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.v_view_pos = v_view_pos; + stage_output.v_world_pos = v_world_pos; + stage_output.v_base_color = v_base_color; + stage_output.v_material = v_material; + return stage_output; + } +*/ +static const uint8_t vs_source_hlsl5[2466] = { + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x63,0x75,0x62,0x65,0x5f,0x69,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72, + 0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6d,0x61, + 0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x42,0x79,0x74,0x65, + 0x41,0x64,0x64,0x72,0x65,0x73,0x73,0x42,0x75,0x66,0x66,0x65,0x72,0x20,0x5f,0x31, + 0x35,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x30,0x29, + 0x3b,0x0a,0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x64,0x72,0x61, + 0x77,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x32,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x34,0x20,0x5f,0x32,0x31,0x5f, + 0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b, + 0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a, + 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65, + 0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x37,0x38,0x5f,0x76,0x69,0x65, + 0x77,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f, + 0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x37,0x38,0x5f,0x70, + 0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74, + 0x28,0x63,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61, + 0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x37,0x38, + 0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61,0x63, + 0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x78,0x34,0x20,0x5f,0x37,0x38,0x5f,0x69,0x6e,0x76,0x5f,0x76,0x69,0x65,0x77, + 0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73, + 0x65,0x74,0x28,0x63,0x31,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x5f,0x37,0x38,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70, + 0x6f,0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28, + 0x63,0x31,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x5f,0x37,0x38,0x5f,0x76,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x20,0x3a,0x20, + 0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x37,0x29,0x3b, + 0x0a,0x7d,0x3b,0x0a,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b, + 0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x3b,0x0a,0x73,0x74, + 0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70, + 0x6f,0x73,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x73,0x74, + 0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x0a, + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, + 0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20,0x54, + 0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69, + 0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e, + 0x64,0x65,0x78,0x20,0x3a,0x20,0x53,0x56,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x49,0x44,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20, + 0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70, + 0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20,0x54,0x45,0x58, + 0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x20,0x3a, + 0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x32,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61, + 0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x6d,0x61, + 0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52, + 0x44,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67, + 0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,0x53,0x56,0x5f, + 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x6f, + 0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x63,0x75,0x62,0x65,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x20,0x5f,0x33,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e, + 0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x20,0x3d,0x20,0x61,0x73,0x66, + 0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28, + 0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20, + 0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64, + 0x65,0x78,0x29,0x20,0x2a,0x20,0x38,0x30,0x20,0x2b,0x20,0x30,0x29,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f, + 0x77,0x31,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35, + 0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74, + 0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73, + 0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x38,0x30, + 0x20,0x2b,0x20,0x31,0x36,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33, + 0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x20,0x3d,0x20,0x61,0x73, + 0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28, + 0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78, + 0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e, + 0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x38,0x30,0x20,0x2b,0x20,0x33,0x32,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f, + 0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e, + 0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20, + 0x38,0x30,0x20,0x2b,0x20,0x34,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f, + 0x33,0x33,0x2e,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3d,0x20,0x61,0x73, + 0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28, + 0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78, + 0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e, + 0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x38,0x30,0x20,0x2b,0x20,0x36,0x34,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x35,0x38, + 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73, + 0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x36,0x34,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x33,0x33, + 0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2c,0x20,0x5f,0x35,0x38, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x38, + 0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d, + 0x5f,0x72,0x6f,0x77,0x31,0x2c,0x20,0x5f,0x35,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x32,0x20,0x3d,0x20,0x64,0x6f,0x74, + 0x28,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2c, + 0x20,0x5f,0x35,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x5f,0x38,0x37,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x28,0x5f,0x36,0x34,0x2c,0x20,0x5f,0x36,0x38,0x2c,0x20,0x5f,0x37,0x32, + 0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f,0x37,0x38,0x5f,0x76,0x69,0x65, + 0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70, + 0x6f,0x73,0x20,0x3d,0x20,0x5f,0x38,0x37,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x20,0x3d,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x36,0x34,0x2c,0x20,0x5f,0x36,0x38,0x2c, + 0x20,0x5f,0x37,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x62,0x61,0x73, + 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x5f,0x33,0x33,0x2e,0x62,0x61, + 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f, + 0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3d,0x20,0x5f,0x33,0x33,0x2e,0x6d, + 0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f, + 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x5f, + 0x38,0x37,0x2c,0x20,0x5f,0x37,0x38,0x5f,0x70,0x72,0x6f,0x6a,0x29,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75, + 0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f, + 0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67, + 0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67, + 0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20, + 0x3d,0x20,0x69,0x6e,0x74,0x28,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75, + 0x74,0x2e,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64, + 0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20, + 0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x69,0x6e, + 0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d, + 0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56, + 0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74, + 0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f, + 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x50,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67, + 0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x70,0x6f,0x73,0x20,0x3d,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70, + 0x75,0x74,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x20,0x3d, + 0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76, + 0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x5f, + 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x6d, + 0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65, + 0x72,0x69,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d, + 0x0a,0x00, +}; +/* + cbuffer ub_pass : register(b1) + { + float4 _706_sun_dir_view : packoffset(c0); + float4 _706_sun_color : packoffset(c1); + int4 _706_flags : packoffset(c2); + float4 _706_cascade_far_view_z : packoffset(c3); + row_major float4x4 _706_cascade_matrices[3] : packoffset(c4); + row_major float4x4 _706_view : packoffset(c16); + float4 _706_camera_pos_world : packoffset(c20); + float4 _706_sh[9] : packoffset(c21); + float4 _706_ibl_params : packoffset(c30); + }; + + Texture2DArray tex_shadow : register(t0); + SamplerComparisonState smp_shadow : register(s0); + Texture2D tex_ao : register(t3); + SamplerState smp_ao : register(s3); + TextureCube tex_ibl_spec : register(t1); + SamplerState smp_ibl_spec : register(s1); + Texture2D tex_brdf_lut : register(t2); + SamplerState smp_brdf_lut : register(s2); + + static float4 gl_FragCoord; + static float3 v_view_pos; + static float4 out_color; + static float3 v_world_pos; + static float4 v_base_color; + static float4 v_material; + + struct SPIRV_Cross_Input + { + float3 v_view_pos : TEXCOORD0; + float3 v_world_pos : TEXCOORD1; + nointerpolation float4 v_base_color : TEXCOORD2; + nointerpolation float4 v_material : TEXCOORD3; + float4 gl_FragCoord : SV_Position; + }; + + struct SPIRV_Cross_Output + { + float4 out_color : SV_Target0; + }; + + uint2 spvTextureSize(Texture2D Tex, uint Level, out uint Param) + { + uint2 ret; + Tex.GetDimensions(Level, ret.x, ret.y, Param); + return ret; + } + + float sampleShadowPCF(int cascade, float3 light_uv, float bias) + { + float _528 = float(cascade); + float _533 = light_uv.z - bias; + float _549 = light_uv.x - 0.00048828125f; + float _553 = light_uv.y - 0.00048828125f; + float _583 = light_uv.x + 0.00048828125f; + float _651 = light_uv.y + 0.00048828125f; + return ((((((((tex_shadow.SampleCmp(smp_shadow, float4(_549, _553, _528, _533).xyz, _533) + tex_shadow.SampleCmp(smp_shadow, float4(light_uv.x, _553, _528, _533).xyz, _533)) + tex_shadow.SampleCmp(smp_shadow, float4(_583, _553, _528, _533).xyz, _533)) + tex_shadow.SampleCmp(smp_shadow, float4(_549, light_uv.y, _528, _533).xyz, _533)) + tex_shadow.SampleCmp(smp_shadow, float4(light_uv.xy, _528, _533).xyz, _533)) + tex_shadow.SampleCmp(smp_shadow, float4(_583, light_uv.y, _528, _533).xyz, _533)) + tex_shadow.SampleCmp(smp_shadow, float4(_549, _651, _528, _533).xyz, _533)) + tex_shadow.SampleCmp(smp_shadow, float4(light_uv.x, _651, _528, _533).xyz, _533)) + tex_shadow.SampleCmp(smp_shadow, float4(_583, _651, _528, _533).xyz, _533)) * 0.111111111938953399658203125f; + } + + float sampleCascade(int cascade, float3 world_pos, float n_dot_l) + { + float4 _716 = mul(float4(world_pos, 1.0f), _706_cascade_matrices[cascade]); + float3 _723 = _716.xyz / _716.w.xxx; + float3 _741 = float3((_723.x * 0.5f) + 0.5f, ((_723.y * _706_cascade_far_view_z.w) * 0.5f) + 0.5f, _723.z); + bool _745 = any(bool3(_741.x < 0.0f.xxx.x, _741.y < 0.0f.xxx.y, _741.z < 0.0f.xxx.z)); + bool _752; + if (!_745) + { + _752 = any(bool3(_741.x > 1.0f.xxx.x, _741.y > 1.0f.xxx.y, _741.z > 1.0f.xxx.z)); + } + else + { + _752 = _745; + } + if (_752) + { + return 1.0f; + } + float _759 = clamp(n_dot_l, 0.001000000047497451305389404296875f, 1.0f); + int param = cascade; + float3 param_1 = _741; + float param_2 = clamp(0.001000000047497451305389404296875f * (sqrt(1.0f - (_759 * _759)) / _759), 0.0005000000237487256526947021484375f, 0.0500000007450580596923828125f); + float pcf = sampleShadowPCF(param, param_1, param_2); + if (cascade == 2) + { + float2 _790 = _741.xy; + float2 _795 = min(_790, 1.0f.xx - _790); + pcf = lerp(1.0f, pcf, clamp(min(_795.x, _795.y) * 10.0f, 0.0f, 1.0f)); + } + return pcf; + } + + float sampleShadowCascaded(float3 world_pos, float n_dot_l, float view_z) + { + int cascade = 2; + if (view_z < _706_cascade_far_view_z.x) + { + cascade = 0; + } + else + { + if (view_z < _706_cascade_far_view_z.y) + { + cascade = 1; + } + } + int param = cascade; + float3 param_1 = world_pos; + float param_2 = n_dot_l; + float shadow = sampleCascade(param, param_1, param_2); + if (cascade < 2) + { + float _840; + if (cascade == 0) + { + _840 = _706_cascade_far_view_z.x; + } + else + { + _840 = _706_cascade_far_view_z.y; + } + float _852; + if (cascade == 0) + { + _852 = 0.0f; + } + else + { + _852 = _706_cascade_far_view_z.x; + } + float _863 = lerp(_840, _852, 0.100000001490116119384765625f); + if (view_z > _863) + { + int param_3 = cascade + 1; + float3 param_4 = world_pos; + float param_5 = n_dot_l; + shadow = lerp(shadow, sampleCascade(param_3, param_4, param_5), (view_z - _863) / (_840 - _863)); + } + } + return shadow; + } + + float pbrDistributionGGX(float n_dot_h, float alpha) + { + float _106 = alpha * alpha; + float _115 = ((n_dot_h * n_dot_h) * (_106 - 1.0f)) + 1.0f; + return _106 / ((3.1415927410125732421875f * _115) * _115); + } + + float pbrVisibilitySmithCorrelated(float n_dot_v, float n_dot_l, float alpha) + { + float _128 = alpha * alpha; + float _135 = 1.0f - _128; + return 0.5f / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _135) + _128)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _135) + _128))) + 9.9999997473787516355514526367188e-06f); + } + + float3 pbrFresnelSchlick(float v_dot_h, float3 f0) + { + float _164 = 1.0f - v_dot_h; + float _168 = _164 * _164; + return f0 + ((1.0f.xxx - f0) * ((_168 * _168) * _164)); + } + + float3 brdf_evaluate(float3 N, float3 V, float3 L, float3 sun_radiance, float3 base_color, float metallic, float roughness) + { + float _187 = max(dot(N, L), 0.0f); + float3 _198 = normalize(V + L); + float _212 = max(roughness, 0.04500000178813934326171875f); + float _216 = _212 * _212; + float param = max(dot(N, _198), 0.0f); + float param_1 = _216; + float param_2 = max(dot(N, V), 9.9999997473787516355514526367188e-05f); + float param_3 = _187; + float param_4 = _216; + float param_5 = max(dot(V, _198), 0.0f); + float3 param_6 = lerp(0.039999999105930328369140625f.xxx, base_color, metallic.xxx); + float3 _243 = pbrFresnelSchlick(param_5, param_6); + return ((((((1.0f.xxx - _243) * (1.0f - metallic)) * base_color) * 0.3183098733425140380859375f.xxx) + (_243 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _187; + } + + float3 pbrEvaluateShIrradiance(float3 N, float4 sh[9]) + { + float3 _398 = ((((((((sh[0].xyz * 0.2820948064327239990234375f) + (sh[1].xyz * ((-0.48860251903533935546875f) * N.y))) + (sh[2].xyz * (0.48860251903533935546875f * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875f) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125f * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125f) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125f * (((3.0f * N.z) * N.z) - 1.0f)))) + (sh[7].xyz * (((-1.09254848957061767578125f) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625f * ((N.x * N.x) - (N.y * N.y)))); + return _398; + } + + float3 pbrEvaluateIbl(float3 N_world, float3 V_world, float3 base_color, float metallic, float roughness, float4 sh[9], TextureCube tex_spec_cube, SamplerState smp_spec_cube, Texture2D tex_brdf_lut_1, SamplerState smp_brdf_lut_1, float max_lod) + { + float _405 = clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05f, 1.0f); + float3 _415 = lerp(0.039999999105930328369140625f.xxx, base_color, metallic.xxx); + float3 param = N_world; + float4 param_1[9] = sh; + float4 _481 = tex_brdf_lut_1.Sample(smp_brdf_lut_1, float2(_405, roughness)); + return (((((1.0f.xxx - (_415 + ((max((1.0f - roughness).xxx, _415) - _415) * pow(max(0.0f, 1.0f - _405), 5.0f)))) * (1.0f - metallic)) * base_color) * max(pbrEvaluateShIrradiance(param, param_1), 0.0f.xxx)) * 0.3183098733425140380859375f.xxx) + (tex_spec_cube.SampleLevel(smp_spec_cube, reflect(-V_world, N_world), roughness * max_lod).xyz * ((_415 * _481.x) + _481.y.xxx)); + } + + float3 pbrEvaluateAmbient(bool iblEnabled, float3 N_world, float3 V_world, float3 base_color, float metallic, float roughness, float flat_strength, float4 sh[9], TextureCube tex_spec_cube, SamplerState smp_spec_cube, Texture2D tex_brdf_lut_1, SamplerState smp_brdf_lut_1, float max_lod) + { + float3 result = base_color * flat_strength; + if (iblEnabled) + { + float3 param = N_world; + float3 param_1 = V_world; + float3 param_2 = base_color; + float param_3 = metallic; + float param_4 = roughness; + float4 param_5[9] = sh; + float param_6 = max_lod; + result = pbrEvaluateIbl(param, param_1, param_2, param_3, param_4, param_5, tex_spec_cube, smp_spec_cube, tex_brdf_lut_1, smp_brdf_lut_1, param_6); + } + return result; + } + + void frag_main() + { + float3 _895 = ddx(v_view_pos); + float3 _898 = ddy(v_view_pos); + float3 _907 = normalize(cross(_898 * (-_706_cascade_far_view_z.w), _895)); + float _912 = -v_view_pos.z; + if (_706_flags.x == 1) + { + float _923 = clamp(v_view_pos.z * (-0.0199999995529651641845703125f), 0.0f, 1.0f); + out_color = float4(_923, _923, _923, 1.0f); + return; + } + if (_706_flags.x == 2) + { + int cascade = 2; + if (_912 < _706_cascade_far_view_z.x) + { + cascade = 0; + } + else + { + if (_912 < _706_cascade_far_view_z.y) + { + cascade = 1; + } + } + float4 _958 = mul(float4(v_world_pos, 1.0f), _706_cascade_matrices[cascade]); + float3 _965 = _958.xyz / _958.w.xxx; + float3 _982 = float3((_965.x * 0.5f) + 0.5f, ((_965.y * _706_cascade_far_view_z.w) * 0.5f) + 0.5f, _965.z); + bool _986 = any(bool3(_982.x < 0.0f.xxx.x, _982.y < 0.0f.xxx.y, _982.z < 0.0f.xxx.z)); + bool _993; + if (!_986) + { + _993 = any(bool3(_982.x > 1.0f.xxx.x, _982.y > 1.0f.xxx.y, _982.z > 1.0f.xxx.z)); + } + else + { + _993 = _986; + } + float3 tint = 1.0f.xxx; + if (!_993) + { + if (cascade == 0) + { + tint = float3(1.0f, 0.4000000059604644775390625f, 0.4000000059604644775390625f); + } + else + { + if (cascade == 1) + { + tint = float3(0.4000000059604644775390625f, 1.0f, 0.4000000059604644775390625f); + } + else + { + tint = float3(0.4000000059604644775390625f, 0.4000000059604644775390625f, 1.0f); + } + } + } + out_color = float4(tint, 1.0f); + return; + } + if (_706_flags.x == 3) + { + out_color = float4((_907 * 0.5f) + 0.5f.xxx, 1.0f); + return; + } + uint _1045_dummy_parameter; + float4 _1053 = tex_ao.SampleLevel(smp_ao, gl_FragCoord.xy / float2(int2(spvTextureSize(tex_ao, uint(0), _1045_dummy_parameter))), 0.0f); + float _1054 = _1053.x; + if (_706_flags.x == 4) + { + out_color = float4(_1054, _1054, _1054, 1.0f); + return; + } + float3 _1072 = normalize(_706_sun_dir_view.xyz); + float3 param = v_world_pos; + float param_1 = max(dot(_907, _1072), 0.0f); + float param_2 = _912; + float3 param_3 = _907; + float3 param_4 = normalize(-v_view_pos); + float3 param_5 = _1072; + float3 param_6 = _706_sun_color.xyz * sampleShadowCascaded(param, param_1, param_2); + float3 param_7 = v_base_color.xyz; + float param_8 = v_material.x; + float param_9 = v_material.y; + bool param_10 = _706_ibl_params.y > 0.5f; + float3 param_11 = normalize(mul(_907, transpose(float3x3(_706_view[0].xyz, _706_view[1].xyz, _706_view[2].xyz)))); + float3 param_12 = normalize(_706_camera_pos_world.xyz - v_world_pos); + float3 param_13 = v_base_color.xyz; + float param_14 = v_material.x; + float param_15 = v_material.y; + float param_16 = _706_sun_color.w; + float4 param_17[9]; + param_17[0] = _706_sh[0]; + param_17[1] = _706_sh[1]; + param_17[2] = _706_sh[2]; + param_17[3] = _706_sh[3]; + param_17[4] = _706_sh[4]; + param_17[5] = _706_sh[5]; + param_17[6] = _706_sh[6]; + param_17[7] = _706_sh[7]; + param_17[8] = _706_sh[8]; + float param_18 = _706_ibl_params.x; + out_color = float4((brdf_evaluate(param_3, param_4, param_5, param_6, param_7, param_8, param_9) + (pbrEvaluateAmbient(param_10, param_11, param_12, param_13, param_14, param_15, param_16, param_17, tex_ibl_spec, smp_ibl_spec, tex_brdf_lut, smp_brdf_lut, param_18) * _1054)) * v_base_color.w, v_base_color.w); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_FragCoord = stage_input.gl_FragCoord; + gl_FragCoord.w = 1.0 / gl_FragCoord.w; + v_view_pos = stage_input.v_view_pos; + v_world_pos = stage_input.v_world_pos; + v_base_color = stage_input.v_base_color; + v_material = stage_input.v_material; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.out_color = out_color; + return stage_output; + } +*/ +static const uint8_t fs_source_hlsl5[13249] = { + 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x31,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x30,0x36, + 0x5f,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x76,0x69,0x65,0x77,0x20,0x3a,0x20, + 0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x30,0x36,0x5f, + 0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b, + 0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x6e,0x74,0x34,0x20,0x5f,0x37,0x30,0x36,0x5f,0x66,0x6c,0x61,0x67,0x73,0x20, + 0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x32,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x30, + 0x36,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65, + 0x74,0x28,0x63,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d, + 0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x37, + 0x30,0x36,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69, + 0x63,0x65,0x73,0x5b,0x33,0x5d,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66, + 0x73,0x65,0x74,0x28,0x63,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77, + 0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20, + 0x5f,0x37,0x30,0x36,0x5f,0x76,0x69,0x65,0x77,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b, + 0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x30,0x36,0x5f,0x63,0x61,0x6d, + 0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3a,0x20, + 0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x32,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x30,0x36, + 0x5f,0x73,0x68,0x5b,0x39,0x5d,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66, + 0x73,0x65,0x74,0x28,0x63,0x32,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x30,0x36,0x5f,0x69,0x62,0x6c,0x5f,0x70,0x61, + 0x72,0x61,0x6d,0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65, + 0x74,0x28,0x63,0x33,0x30,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x54,0x65,0x78,0x74, + 0x75,0x72,0x65,0x32,0x44,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3a,0x20, + 0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x30,0x29,0x3b,0x0a,0x53,0x61, + 0x6d,0x70,0x6c,0x65,0x72,0x43,0x6f,0x6d,0x70,0x61,0x72,0x69,0x73,0x6f,0x6e,0x53, + 0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x30,0x29,0x3b,0x0a, + 0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x3e,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73, + 0x74,0x65,0x72,0x28,0x74,0x33,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72, + 0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x20,0x3a,0x20,0x72, + 0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x33,0x29,0x3b,0x0a,0x54,0x65,0x78, + 0x74,0x75,0x72,0x65,0x43,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e, + 0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x20,0x3a,0x20, + 0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x31,0x29,0x3b,0x0a,0x53,0x61, + 0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x69, + 0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74, + 0x65,0x72,0x28,0x73,0x31,0x29,0x3b,0x0a,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32, + 0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72, + 0x64,0x66,0x5f,0x6c,0x75,0x74,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65, + 0x72,0x28,0x74,0x32,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74, + 0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74, + 0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x32,0x29,0x3b, + 0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x3b,0x0a,0x73,0x74, + 0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b, + 0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x73,0x74,0x61,0x74, + 0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c, + 0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f, + 0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x70,0x6f,0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f, + 0x52,0x44,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72, + 0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x54, + 0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f, + 0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20, + 0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x33,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43, + 0x6f,0x6f,0x72,0x64,0x20,0x3a,0x20,0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69, + 0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53, + 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75, + 0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f, + 0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x53,0x56,0x5f,0x54,0x61, + 0x72,0x67,0x65,0x74,0x30,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x75,0x69,0x6e,0x74,0x32, + 0x20,0x73,0x70,0x76,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x53,0x69,0x7a,0x65,0x28, + 0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x3e,0x20,0x54,0x65,0x78,0x2c,0x20,0x75,0x69,0x6e,0x74,0x20,0x4c,0x65,0x76,0x65, + 0x6c,0x2c,0x20,0x6f,0x75,0x74,0x20,0x75,0x69,0x6e,0x74,0x20,0x50,0x61,0x72,0x61, + 0x6d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x32,0x20,0x72, + 0x65,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x54,0x65,0x78,0x2e,0x47,0x65,0x74,0x44, + 0x69,0x6d,0x65,0x6e,0x73,0x69,0x6f,0x6e,0x73,0x28,0x4c,0x65,0x76,0x65,0x6c,0x2c, + 0x20,0x72,0x65,0x74,0x2e,0x78,0x2c,0x20,0x72,0x65,0x74,0x2e,0x79,0x2c,0x20,0x50, + 0x61,0x72,0x61,0x6d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x72,0x65,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28, + 0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x62,0x69,0x61,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x32,0x38,0x20,0x3d,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x33,0x33,0x20,0x3d,0x20,0x6c,0x69, + 0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x7a,0x20,0x2d,0x20,0x62,0x69,0x61,0x73,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x34,0x39,0x20, + 0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20,0x2d,0x20,0x30, + 0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x66,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x35,0x33,0x20,0x3d,0x20, + 0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x20,0x2d,0x20,0x30,0x2e,0x30, + 0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x38,0x33,0x20,0x3d,0x20,0x6c,0x69, + 0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30, + 0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x35,0x31,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68, + 0x74,0x5f,0x75,0x76,0x2e,0x79,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38, + 0x38,0x32,0x38,0x31,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x74,0x65,0x78,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70, + 0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x28,0x5f,0x35,0x34,0x39,0x2c,0x20,0x5f,0x35,0x35,0x33,0x2c,0x20, + 0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x2e,0x78,0x79,0x7a,0x2c, + 0x20,0x5f,0x35,0x33,0x33,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d, + 0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20,0x5f,0x35,0x35, + 0x33,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x2e,0x78, + 0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d, + 0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x38,0x33,0x2c,0x20,0x5f,0x35,0x35,0x33,0x2c, + 0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x2e,0x78,0x79,0x7a, + 0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28, + 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x28,0x5f,0x35,0x34,0x39,0x2c,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75, + 0x76,0x2e,0x79,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29, + 0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x20,0x2b,0x20,0x74, + 0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65, + 0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e, + 0x78,0x79,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x2e, + 0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x20,0x2b,0x20,0x74,0x65, + 0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43, + 0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x38,0x33,0x2c,0x20,0x6c,0x69,0x67,0x68, + 0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35, + 0x33,0x33,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x20, + 0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d, + 0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x34,0x39,0x2c,0x20, + 0x5f,0x36,0x35,0x31,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33, + 0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x20,0x2b,0x20, + 0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c, + 0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76, + 0x2e,0x78,0x2c,0x20,0x5f,0x36,0x35,0x31,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20, + 0x5f,0x35,0x33,0x33,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29, + 0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53, + 0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x38,0x33, + 0x2c,0x20,0x5f,0x36,0x35,0x31,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35, + 0x33,0x33,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x20, + 0x2a,0x20,0x30,0x2e,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x39,0x33,0x38, + 0x39,0x35,0x33,0x33,0x39,0x39,0x36,0x35,0x38,0x32,0x30,0x33,0x31,0x32,0x35,0x66, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x69,0x6e,0x74,0x20,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x77,0x6f,0x72, + 0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f, + 0x64,0x6f,0x74,0x5f,0x6c,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x5f,0x37,0x31,0x36,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c, + 0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f,0x37,0x30,0x36,0x5f,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x5d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x5f,0x37,0x32,0x33,0x20,0x3d,0x20,0x5f,0x37,0x31,0x36,0x2e, + 0x78,0x79,0x7a,0x20,0x2f,0x20,0x5f,0x37,0x31,0x36,0x2e,0x77,0x2e,0x78,0x78,0x78, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x37,0x34, + 0x31,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x5f,0x37,0x32,0x33, + 0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35, + 0x66,0x2c,0x20,0x28,0x28,0x5f,0x37,0x32,0x33,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x37, + 0x30,0x36,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29, + 0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2c,0x20,0x5f,0x37,0x32,0x33,0x2e,0x7a,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x37,0x34,0x35,0x20, + 0x3d,0x20,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c,0x33,0x28,0x5f,0x37,0x34,0x31, + 0x2e,0x78,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x78,0x2c, + 0x20,0x5f,0x37,0x34,0x31,0x2e,0x79,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78, + 0x78,0x78,0x2e,0x79,0x2c,0x20,0x5f,0x37,0x34,0x31,0x2e,0x7a,0x20,0x3c,0x20,0x30, + 0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x7a,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x37,0x35,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x21,0x5f,0x37,0x34,0x35,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x37,0x35,0x32,0x20,0x3d,0x20, + 0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c,0x33,0x28,0x5f,0x37,0x34,0x31,0x2e,0x78, + 0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x78,0x2c,0x20,0x5f, + 0x37,0x34,0x31,0x2e,0x79,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78, + 0x2e,0x79,0x2c,0x20,0x5f,0x37,0x34,0x31,0x2e,0x7a,0x20,0x3e,0x20,0x31,0x2e,0x30, + 0x66,0x2e,0x78,0x78,0x78,0x2e,0x7a,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x37,0x35,0x32,0x20,0x3d,0x20,0x5f, + 0x37,0x34,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x5f,0x37,0x35,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e, + 0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x37,0x35,0x39,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70, + 0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x30,0x2e,0x30,0x30,0x31,0x30, + 0x30,0x30,0x30,0x30,0x30,0x30,0x34,0x37,0x34,0x39,0x37,0x34,0x35,0x31,0x33,0x30, + 0x35,0x33,0x38,0x39,0x34,0x30,0x34,0x32,0x39,0x36,0x38,0x37,0x35,0x66,0x2c,0x20, + 0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x20,0x3d,0x20,0x5f,0x37,0x34,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x63, + 0x6c,0x61,0x6d,0x70,0x28,0x30,0x2e,0x30,0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30, + 0x30,0x34,0x37,0x34,0x39,0x37,0x34,0x35,0x31,0x33,0x30,0x35,0x33,0x38,0x39,0x34, + 0x30,0x34,0x32,0x39,0x36,0x38,0x37,0x35,0x66,0x20,0x2a,0x20,0x28,0x73,0x71,0x72, + 0x74,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x28,0x5f,0x37,0x35,0x39,0x20,0x2a, + 0x20,0x5f,0x37,0x35,0x39,0x29,0x29,0x20,0x2f,0x20,0x5f,0x37,0x35,0x39,0x29,0x2c, + 0x20,0x30,0x2e,0x30,0x30,0x30,0x35,0x30,0x30,0x30,0x30,0x30,0x30,0x32,0x33,0x37, + 0x34,0x38,0x37,0x32,0x35,0x36,0x35,0x32,0x36,0x39,0x34,0x37,0x30,0x32,0x31,0x34, + 0x38,0x34,0x33,0x37,0x35,0x66,0x2c,0x20,0x30,0x2e,0x30,0x35,0x30,0x30,0x30,0x30, + 0x30,0x30,0x30,0x37,0x34,0x35,0x30,0x35,0x38,0x30,0x35,0x39,0x36,0x39,0x32,0x33, + 0x38,0x32,0x38,0x31,0x32,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, + 0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f, + 0x37,0x39,0x30,0x20,0x3d,0x20,0x5f,0x37,0x34,0x31,0x2e,0x78,0x79,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x37, + 0x39,0x35,0x20,0x3d,0x20,0x6d,0x69,0x6e,0x28,0x5f,0x37,0x39,0x30,0x2c,0x20,0x31, + 0x2e,0x30,0x66,0x2e,0x78,0x78,0x20,0x2d,0x20,0x5f,0x37,0x39,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x6c,0x65, + 0x72,0x70,0x28,0x31,0x2e,0x30,0x66,0x2c,0x20,0x70,0x63,0x66,0x2c,0x20,0x63,0x6c, + 0x61,0x6d,0x70,0x28,0x6d,0x69,0x6e,0x28,0x5f,0x37,0x39,0x35,0x2e,0x78,0x2c,0x20, + 0x5f,0x37,0x39,0x35,0x2e,0x79,0x29,0x20,0x2a,0x20,0x31,0x30,0x2e,0x30,0x66,0x2c, + 0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x70,0x63,0x66,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61, + 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64, + 0x65,0x64,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x70,0x6f,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74, + 0x5f,0x6c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x69,0x65,0x77,0x5f,0x7a, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x37,0x30,0x36,0x5f,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x37,0x30,0x36,0x5f,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x7a,0x2e,0x79,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x20,0x3d,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d, + 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70, + 0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3c,0x20,0x32,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x38,0x34,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x34,0x30,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x36,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x34,0x30,0x20,0x3d,0x20,0x5f,0x37, + 0x30,0x36,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x38,0x35,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x35,0x32,0x20,0x3d,0x20,0x30,0x2e, + 0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x5f,0x38,0x35,0x32,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x5f,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e, + 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x36,0x33,0x20, + 0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x5f,0x38,0x34,0x30,0x2c,0x20,0x5f,0x38,0x35, + 0x32,0x2c,0x20,0x30,0x2e,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x34,0x39, + 0x30,0x31,0x31,0x36,0x31,0x31,0x39,0x33,0x38,0x34,0x37,0x36,0x35,0x36,0x32,0x35, + 0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3e,0x20,0x5f,0x38,0x36,0x33,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, + 0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x2b,0x20,0x31,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x77,0x6f,0x72, + 0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x35,0x20,0x3d,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20, + 0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73, + 0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x35,0x29,0x2c,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a, + 0x20,0x2d,0x20,0x5f,0x38,0x36,0x33,0x29,0x20,0x2f,0x20,0x28,0x5f,0x38,0x34,0x30, + 0x20,0x2d,0x20,0x5f,0x38,0x36,0x33,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69, + 0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61, + 0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x31,0x30,0x36,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a, + 0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x31,0x31,0x35,0x20,0x3d,0x20,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74, + 0x5f,0x68,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x29,0x20,0x2a,0x20, + 0x28,0x5f,0x31,0x30,0x36,0x20,0x2d,0x20,0x31,0x2e,0x30,0x66,0x29,0x29,0x20,0x2b, + 0x20,0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x5f,0x31,0x30,0x36,0x20,0x2f,0x20,0x28,0x28,0x33,0x2e,0x31,0x34,0x31, + 0x35,0x39,0x32,0x37,0x34,0x31,0x30,0x31,0x32,0x35,0x37,0x33,0x32,0x34,0x32,0x31, + 0x38,0x37,0x35,0x66,0x20,0x2a,0x20,0x5f,0x31,0x31,0x35,0x29,0x20,0x2a,0x20,0x5f, + 0x31,0x31,0x35,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74, + 0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x32,0x38,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20, + 0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x33,0x35,0x20,0x3d,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d, + 0x20,0x5f,0x31,0x32,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x30,0x2e,0x35,0x66,0x20,0x2f,0x20,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f, + 0x74,0x5f,0x6c,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64, + 0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x29,0x20, + 0x2a,0x20,0x5f,0x31,0x33,0x35,0x29,0x20,0x2b,0x20,0x5f,0x31,0x32,0x38,0x29,0x29, + 0x20,0x2b,0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x73,0x71, + 0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x6e, + 0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x29,0x20,0x2a,0x20,0x5f,0x31,0x33,0x35,0x29,0x20, + 0x2b,0x20,0x5f,0x31,0x32,0x38,0x29,0x29,0x29,0x20,0x2b,0x20,0x39,0x2e,0x39,0x39, + 0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35, + 0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30, + 0x36,0x66,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, + 0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b, + 0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x66,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x34,0x20,0x3d,0x20,0x31,0x2e, + 0x30,0x66,0x20,0x2d,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x38,0x20,0x3d,0x20,0x5f, + 0x31,0x36,0x34,0x20,0x2a,0x20,0x5f,0x31,0x36,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x30,0x20,0x2b,0x20,0x28,0x28,0x31,0x2e, + 0x30,0x66,0x2e,0x78,0x78,0x78,0x20,0x2d,0x20,0x66,0x30,0x29,0x20,0x2a,0x20,0x28, + 0x28,0x5f,0x31,0x36,0x38,0x20,0x2a,0x20,0x5f,0x31,0x36,0x38,0x29,0x20,0x2a,0x20, + 0x5f,0x31,0x36,0x34,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4e,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x56,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4c,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63, + 0x65,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61, + 0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67, + 0x68,0x6e,0x65,0x73,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x38,0x37,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f, + 0x74,0x28,0x4e,0x2c,0x20,0x4c,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x39,0x38,0x20, + 0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x56,0x20,0x2b,0x20, + 0x4c,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32, + 0x31,0x32,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65, + 0x73,0x73,0x2c,0x20,0x30,0x2e,0x30,0x34,0x35,0x30,0x30,0x30,0x30,0x30,0x31,0x37, + 0x38,0x38,0x31,0x33,0x39,0x33,0x34,0x33,0x32,0x36,0x31,0x37,0x31,0x38,0x37,0x35, + 0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32, + 0x31,0x36,0x20,0x3d,0x20,0x5f,0x32,0x31,0x32,0x20,0x2a,0x20,0x5f,0x32,0x31,0x32, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x5f, + 0x31,0x39,0x38,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d, + 0x20,0x5f,0x32,0x31,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64, + 0x6f,0x74,0x28,0x4e,0x2c,0x20,0x56,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39, + 0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35, + 0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x66, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31,0x38,0x37,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d, + 0x20,0x5f,0x32,0x31,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64, + 0x6f,0x74,0x28,0x56,0x2c,0x20,0x5f,0x31,0x39,0x38,0x29,0x2c,0x20,0x30,0x2e,0x30, + 0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x30,0x2e, + 0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33, + 0x32,0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x66,0x2e,0x78,0x78,0x78, + 0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x6d,0x65, + 0x74,0x61,0x6c,0x6c,0x69,0x63,0x2e,0x78,0x78,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x32,0x34,0x33,0x20,0x3d,0x20,0x70, + 0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28, + 0x28,0x28,0x28,0x28,0x28,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x20,0x2d,0x20, + 0x5f,0x32,0x34,0x33,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73, + 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x30,0x2e,0x33,0x31,0x38, + 0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30, + 0x38,0x35,0x39,0x33,0x37,0x35,0x66,0x2e,0x78,0x78,0x78,0x29,0x20,0x2b,0x20,0x28, + 0x5f,0x32,0x34,0x33,0x20,0x2a,0x20,0x28,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72, + 0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x70,0x61,0x72,0x61,0x6d, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x20,0x2a,0x20,0x70,0x62,0x72, + 0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43, + 0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x34,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61, + 0x64,0x69,0x61,0x6e,0x63,0x65,0x29,0x20,0x2a,0x20,0x5f,0x31,0x38,0x37,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61, + 0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63, + 0x65,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4e,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x33,0x39,0x38,0x20,0x3d,0x20,0x28,0x28, + 0x28,0x28,0x28,0x28,0x28,0x28,0x73,0x68,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a,0x20, + 0x2a,0x20,0x30,0x2e,0x32,0x38,0x32,0x30,0x39,0x34,0x38,0x30,0x36,0x34,0x33,0x32, + 0x37,0x32,0x33,0x39,0x39,0x39,0x30,0x32,0x33,0x34,0x33,0x37,0x35,0x66,0x29,0x20, + 0x2b,0x20,0x28,0x73,0x68,0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28, + 0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35, + 0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x66,0x29,0x20,0x2a,0x20, + 0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x32,0x5d,0x2e, + 0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35, + 0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35, + 0x66,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68, + 0x5b,0x33,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34, + 0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35, + 0x35,0x34,0x36,0x38,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x29, + 0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x34,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a, + 0x20,0x28,0x28,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37, + 0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x66,0x20,0x2a,0x20, + 0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20, + 0x28,0x73,0x68,0x5b,0x35,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28, + 0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36, + 0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e, + 0x2e,0x79,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28, + 0x73,0x68,0x5b,0x36,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x33, + 0x31,0x35,0x33,0x39,0x31,0x35,0x37,0x30,0x33,0x32,0x39,0x36,0x36,0x36,0x31,0x33, + 0x37,0x36,0x39,0x35,0x33,0x31,0x32,0x35,0x66,0x20,0x2a,0x20,0x28,0x28,0x28,0x33, + 0x2e,0x30,0x66,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a, + 0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x66,0x29,0x29,0x29,0x29,0x20,0x2b,0x20,0x28, + 0x73,0x68,0x5b,0x37,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d, + 0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31, + 0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e, + 0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73, + 0x68,0x5b,0x38,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x35,0x34, + 0x36,0x32,0x37,0x34,0x32,0x34,0x34,0x37,0x38,0x35,0x33,0x30,0x38,0x38,0x33,0x37, + 0x38,0x39,0x30,0x36,0x32,0x35,0x66,0x20,0x2a,0x20,0x28,0x28,0x4e,0x2e,0x78,0x20, + 0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2d,0x20,0x28,0x4e,0x2e,0x79,0x20,0x2a,0x20, + 0x4e,0x2e,0x79,0x29,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x5f,0x33,0x39,0x38,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49, + 0x62,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61, + 0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67, + 0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68, + 0x5b,0x39,0x5d,0x2c,0x20,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x43,0x75,0x62,0x65, + 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65, + 0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53, + 0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75, + 0x62,0x65,0x2c,0x20,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, + 0x75,0x74,0x5f,0x31,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61, + 0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f, + 0x31,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34, + 0x30,0x35,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x64,0x6f,0x74,0x28,0x4e, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29, + 0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38, + 0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37, + 0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x34,0x31,0x35, + 0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39, + 0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31, + 0x34,0x30,0x36,0x32,0x35,0x66,0x2e,0x78,0x78,0x78,0x2c,0x20,0x62,0x61,0x73,0x65, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63, + 0x2e,0x78,0x78,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x5b,0x39,0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x34,0x38,0x31,0x20,0x3d, + 0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2e, + 0x53,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f, + 0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x34, + 0x30,0x35,0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28, + 0x28,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x20,0x2d,0x20,0x28,0x5f,0x34,0x31, + 0x35,0x20,0x2b,0x20,0x28,0x28,0x6d,0x61,0x78,0x28,0x28,0x31,0x2e,0x30,0x66,0x20, + 0x2d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x2e,0x78,0x78,0x78, + 0x2c,0x20,0x5f,0x34,0x31,0x35,0x29,0x20,0x2d,0x20,0x5f,0x34,0x31,0x35,0x29,0x20, + 0x2a,0x20,0x70,0x6f,0x77,0x28,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x66,0x2c,0x20, + 0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x5f,0x34,0x30,0x35,0x29,0x2c,0x20,0x35,0x2e, + 0x30,0x66,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d, + 0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61, + 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x6d,0x61,0x78,0x28, + 0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72, + 0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78, + 0x78,0x29,0x29,0x20,0x2a,0x20,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37, + 0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37, + 0x35,0x66,0x2e,0x78,0x78,0x78,0x29,0x20,0x2b,0x20,0x28,0x74,0x65,0x78,0x5f,0x73, + 0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x4c, + 0x65,0x76,0x65,0x6c,0x28,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75, + 0x62,0x65,0x2c,0x20,0x72,0x65,0x66,0x6c,0x65,0x63,0x74,0x28,0x2d,0x56,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x2c,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20, + 0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x20,0x2a,0x20,0x6d,0x61,0x78,0x5f, + 0x6c,0x6f,0x64,0x29,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x34,0x31, + 0x35,0x20,0x2a,0x20,0x5f,0x34,0x38,0x31,0x2e,0x78,0x29,0x20,0x2b,0x20,0x5f,0x34, + 0x38,0x31,0x2e,0x79,0x2e,0x78,0x78,0x78,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74, + 0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x62,0x6f,0x6f,0x6c,0x20,0x69,0x62, + 0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74, + 0x68,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x2c, + 0x20,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x43,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75, + 0x62,0x65,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65, + 0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20, + 0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31, + 0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73, + 0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x72,0x65,0x73,0x75,0x6c, + 0x74,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a, + 0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c, + 0x65,0x64,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d, + 0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x20,0x3d,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69, + 0x63,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x72,0x6f,0x75,0x67,0x68, + 0x6e,0x65,0x73,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x5b,0x39,0x5d,0x20, + 0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x61, + 0x78,0x5f,0x6c,0x6f,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72, + 0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75, + 0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73, + 0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70, + 0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64, + 0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64, + 0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x76, + 0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x38,0x39, + 0x35,0x20,0x3d,0x20,0x64,0x64,0x78,0x28,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70, + 0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x5f,0x38,0x39,0x38,0x20,0x3d,0x20,0x64,0x64,0x79,0x28,0x76,0x5f,0x76,0x69,0x65, + 0x77,0x5f,0x70,0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x5f,0x39,0x30,0x37,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c, + 0x69,0x7a,0x65,0x28,0x63,0x72,0x6f,0x73,0x73,0x28,0x5f,0x38,0x39,0x38,0x20,0x2a, + 0x20,0x28,0x2d,0x5f,0x37,0x30,0x36,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, + 0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x2c,0x20,0x5f, + 0x38,0x39,0x35,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x39,0x31,0x32,0x20,0x3d,0x20,0x2d,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x70,0x6f,0x73,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, + 0x37,0x30,0x36,0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x31, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x32,0x33,0x20,0x3d,0x20,0x63,0x6c,0x61, + 0x6d,0x70,0x28,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2e,0x7a,0x20, + 0x2a,0x20,0x28,0x2d,0x30,0x2e,0x30,0x31,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x35, + 0x35,0x32,0x39,0x36,0x35,0x31,0x36,0x34,0x31,0x38,0x34,0x35,0x37,0x30,0x33,0x31, + 0x32,0x35,0x66,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x39, + 0x32,0x33,0x2c,0x20,0x5f,0x39,0x32,0x33,0x2c,0x20,0x5f,0x39,0x32,0x33,0x2c,0x20, + 0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x36,0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e, + 0x78,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x5f,0x39,0x31,0x32,0x20,0x3c,0x20,0x5f,0x37,0x30,0x36,0x5f,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x39,0x31,0x32,0x20,0x3c,0x20, + 0x5f,0x37,0x30,0x36,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72, + 0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x29,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x39,0x35, + 0x38,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x76, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x66, + 0x29,0x2c,0x20,0x5f,0x37,0x30,0x36,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, + 0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x5d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x5f,0x39,0x36,0x35,0x20,0x3d,0x20,0x5f,0x39,0x35,0x38,0x2e,0x78, + 0x79,0x7a,0x20,0x2f,0x20,0x5f,0x39,0x35,0x38,0x2e,0x77,0x2e,0x78,0x78,0x78,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x5f,0x39,0x38,0x32,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x5f, + 0x39,0x36,0x35,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20, + 0x30,0x2e,0x35,0x66,0x2c,0x20,0x28,0x28,0x5f,0x39,0x36,0x35,0x2e,0x79,0x20,0x2a, + 0x20,0x5f,0x37,0x30,0x36,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61, + 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e, + 0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2c,0x20,0x5f,0x39,0x36,0x35, + 0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f, + 0x6c,0x20,0x5f,0x39,0x38,0x36,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f, + 0x6c,0x33,0x28,0x5f,0x39,0x38,0x32,0x2e,0x78,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66, + 0x2e,0x78,0x78,0x78,0x2e,0x78,0x2c,0x20,0x5f,0x39,0x38,0x32,0x2e,0x79,0x20,0x3c, + 0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x79,0x2c,0x20,0x5f,0x39,0x38, + 0x32,0x2e,0x7a,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x7a, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c, + 0x20,0x5f,0x39,0x39,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x21,0x5f,0x39,0x38,0x36,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x5f,0x39,0x39,0x33,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c,0x33, + 0x28,0x5f,0x39,0x38,0x32,0x2e,0x78,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78, + 0x78,0x78,0x2e,0x78,0x2c,0x20,0x5f,0x39,0x38,0x32,0x2e,0x79,0x20,0x3e,0x20,0x31, + 0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x79,0x2c,0x20,0x5f,0x39,0x38,0x32,0x2e, + 0x7a,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x7a,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f, + 0x39,0x39,0x33,0x20,0x3d,0x20,0x5f,0x39,0x38,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x31,0x2e,0x30,0x66, + 0x2e,0x78,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x21,0x5f,0x39,0x39,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74, + 0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30, + 0x66,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36, + 0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x2c, + 0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34, + 0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36, + 0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x2c, + 0x20,0x31,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30, + 0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36, + 0x32,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34, + 0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x2c,0x20,0x30, + 0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34, + 0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x2c,0x20,0x31,0x2e,0x30, + 0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20, + 0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x74,0x69,0x6e,0x74,0x2c,0x20,0x31, + 0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x36,0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78, + 0x20,0x3d,0x3d,0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x5f,0x39,0x30,0x37,0x20,0x2a,0x20, + 0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2e,0x78,0x78,0x78, + 0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x5f,0x31,0x30,0x34,0x35,0x5f,0x64,0x75, + 0x6d,0x6d,0x79,0x5f,0x70,0x61,0x72,0x61,0x6d,0x65,0x74,0x65,0x72,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x30,0x35,0x33,0x20, + 0x3d,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x4c, + 0x65,0x76,0x65,0x6c,0x28,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20,0x67,0x6c,0x5f, + 0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x20,0x2f,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x32,0x28,0x69,0x6e,0x74,0x32,0x28,0x73,0x70,0x76,0x54,0x65, + 0x78,0x74,0x75,0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x74,0x65,0x78,0x5f,0x61,0x6f, + 0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x30,0x29,0x2c,0x20,0x5f,0x31,0x30,0x34,0x35, + 0x5f,0x64,0x75,0x6d,0x6d,0x79,0x5f,0x70,0x61,0x72,0x61,0x6d,0x65,0x74,0x65,0x72, + 0x29,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x34,0x20,0x3d,0x20,0x5f,0x31, + 0x30,0x35,0x33,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, + 0x37,0x30,0x36,0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x34, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x28,0x5f,0x31,0x30,0x35,0x34,0x2c,0x20,0x5f,0x31,0x30,0x35,0x34,0x2c, + 0x20,0x5f,0x31,0x30,0x35,0x34,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x5f,0x31,0x30,0x37,0x32,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a, + 0x65,0x28,0x5f,0x37,0x30,0x36,0x5f,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x76, + 0x69,0x65,0x77,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x76,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x6d,0x61, + 0x78,0x28,0x64,0x6f,0x74,0x28,0x5f,0x39,0x30,0x37,0x2c,0x20,0x5f,0x31,0x30,0x37, + 0x32,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f, + 0x39,0x31,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x39,0x30,0x37,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x34,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x2d, + 0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20, + 0x3d,0x20,0x5f,0x31,0x30,0x37,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f,0x37, + 0x30,0x36,0x5f,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a, + 0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43, + 0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x76,0x5f,0x6d, + 0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x76, + 0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x62,0x6f,0x6f,0x6c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x36,0x5f,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73, + 0x2e,0x79,0x20,0x3e,0x20,0x30,0x2e,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d, + 0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x6d,0x75,0x6c,0x28,0x5f, + 0x39,0x30,0x37,0x2c,0x20,0x74,0x72,0x61,0x6e,0x73,0x70,0x6f,0x73,0x65,0x28,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x78,0x33,0x28,0x5f,0x37,0x30,0x36,0x5f,0x76,0x69,0x65, + 0x77,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x37,0x30,0x36,0x5f,0x76, + 0x69,0x65,0x77,0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x37,0x30,0x36, + 0x5f,0x76,0x69,0x65,0x77,0x5b,0x32,0x5d,0x2e,0x78,0x79,0x7a,0x29,0x29,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a, + 0x65,0x28,0x5f,0x37,0x30,0x36,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f, + 0x73,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x76,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x20, + 0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78, + 0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72, + 0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61, + 0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x36,0x5f,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x37,0x5b,0x39,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x37,0x5b,0x30,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x5f, + 0x73,0x68,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x37,0x5b,0x31,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x5f,0x73,0x68, + 0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x37,0x5b,0x32,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x5f,0x73,0x68,0x5b,0x32, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b, + 0x33,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x5f,0x73,0x68,0x5b,0x33,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x34,0x5d, + 0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x5f,0x73,0x68,0x5b,0x34,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x35,0x5d,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x36,0x5f,0x73,0x68,0x5b,0x35,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x36,0x5d,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x36,0x5f,0x73,0x68,0x5b,0x36,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x37,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30, + 0x36,0x5f,0x73,0x68,0x5b,0x37,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x37,0x5b,0x38,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x5f, + 0x73,0x68,0x5b,0x38,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36, + 0x5f,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c, + 0x75,0x61,0x74,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x39,0x29,0x20,0x2b,0x20,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61, + 0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20,0x74,0x65,0x78,0x5f,0x69,0x62, + 0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f, + 0x73,0x70,0x65,0x63,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, + 0x75,0x74,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x29,0x20,0x2a,0x20,0x5f,0x31, + 0x30,0x35,0x34,0x29,0x29,0x20,0x2a,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x2c,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52, + 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d, + 0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, + 0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75, + 0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67, + 0x43,0x6f,0x6f,0x72,0x64,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e, + 0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f, + 0x72,0x64,0x2e,0x77,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2f,0x20,0x67,0x6c,0x5f, + 0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x20,0x3d,0x20,0x73,0x74, + 0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x76,0x69,0x65,0x77, + 0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x70,0x6f,0x73,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e, + 0x70,0x75,0x74,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e, + 0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3d,0x20,0x73, + 0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x6d,0x61,0x74, + 0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f, + 0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52, + 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73, + 0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x6f,0x75, + 0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a, + 0x00, +}; +/* + #include + #include + + using namespace metal; + + struct cube_instance + { + float4 xform_row0; + float4 xform_row1; + float4 xform_row2; + float4 base_color; + float4 material; + }; + + struct cube_instances + { + cube_instance instances[1]; + }; + + struct ub_draw + { + int4 inst_base; + }; + + struct ub_frame + { + float4x4 view; + float4x4 proj; + float4x4 view_proj; + float4x4 inv_view_proj; + float4 camera_pos; + float4 viewport; + }; + + struct main0_out + { + float3 v_view_pos [[user(locn0)]]; + float3 v_world_pos [[user(locn1)]]; + float4 v_base_color [[user(locn2)]]; + float4 v_material [[user(locn3)]]; + float4 gl_Position [[position]]; + }; + + struct main0_in + { + float3 in_pos [[attribute(0)]]; + }; + + vertex main0_out main0(main0_in in [[stage_in]], constant ub_frame& _78 [[buffer(0)]], constant ub_draw& _21 [[buffer(2)]], const device cube_instances& _15 [[buffer(8)]], uint gl_InstanceIndex [[instance_id]]) + { + main0_out out = {}; + int _30 = _21.inst_base.x + int(gl_InstanceIndex); + float4 _58 = float4(in.in_pos, 1.0); + float _64 = dot(_15.instances[_30].xform_row0, _58); + float _68 = dot(_15.instances[_30].xform_row1, _58); + float _72 = dot(_15.instances[_30].xform_row2, _58); + float4 _87 = _78.view * float4(_64, _68, _72, 1.0); + out.v_view_pos = _87.xyz; + out.v_world_pos = float3(_64, _68, _72); + out.v_base_color = _15.instances[_30].base_color; + out.v_material = _15.instances[_30].material; + out.gl_Position = _78.proj * _87; + return out; + } + +*/ +static const uint8_t vs_source_metal_macos[1543] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x63, + 0x75,0x62,0x65,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f, + 0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f, + 0x77,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x62, + 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a, + 0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x63,0x75,0x62,0x65,0x5f, + 0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x63,0x75,0x62,0x65,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20,0x69,0x6e, + 0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x31,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a, + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x34,0x20,0x69,0x6e,0x73,0x74,0x5f,0x62, + 0x61,0x73,0x65,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20, + 0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x76,0x69,0x65,0x77,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x70,0x72,0x6f,0x6a,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x76,0x69, + 0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x78,0x34,0x20,0x69,0x6e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70, + 0x72,0x6f,0x6a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x3b, + 0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e, + 0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x20,0x5b,0x5b, + 0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x70,0x6f,0x73,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63, + 0x6e,0x31,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b, + 0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x32,0x29,0x5d,0x5d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74, + 0x65,0x72,0x69,0x61,0x6c,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63, + 0x6e,0x33,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b, + 0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a, + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f, + 0x70,0x6f,0x73,0x20,0x5b,0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28, + 0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,0x65,0x78, + 0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30, + 0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73, + 0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x26,0x20,0x5f,0x37, + 0x38,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x64,0x72,0x61, + 0x77,0x26,0x20,0x5f,0x32,0x31,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28, + 0x32,0x29,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x64,0x65,0x76,0x69, + 0x63,0x65,0x20,0x63,0x75,0x62,0x65,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x73,0x26,0x20,0x5f,0x31,0x35,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28, + 0x38,0x29,0x5d,0x5d,0x2c,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e, + 0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x5b,0x5b,0x69,0x6e, + 0x73,0x74,0x61,0x6e,0x63,0x65,0x5f,0x69,0x64,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74, + 0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f, + 0x33,0x30,0x20,0x3d,0x20,0x5f,0x32,0x31,0x2e,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61, + 0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e, + 0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x35,0x38,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x69,0x6e,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x2c, + 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x36,0x34,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2c,0x20,0x5f,0x35,0x38,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x38,0x20,0x3d,0x20, + 0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77, + 0x31,0x2c,0x20,0x5f,0x35,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x37,0x32,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35, + 0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e, + 0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2c,0x20,0x5f,0x35,0x38,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x38,0x37, + 0x20,0x3d,0x20,0x5f,0x37,0x38,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x5f,0x36,0x34,0x2c,0x20,0x5f,0x36,0x38,0x2c,0x20,0x5f, + 0x37,0x32,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75, + 0x74,0x2e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x20,0x3d,0x20,0x5f, + 0x38,0x37,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e, + 0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x28,0x5f,0x36,0x34,0x2c,0x20,0x5f,0x36,0x38,0x2c,0x20,0x5f, + 0x37,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x62, + 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e, + 0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x62, + 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f, + 0x75,0x74,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3d,0x20, + 0x5f,0x31,0x35,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x5f,0x33, + 0x30,0x5d,0x2e,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x5f,0x37,0x38,0x2e,0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20,0x5f,0x38, + 0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75, + 0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + #pragma clang diagnostic ignored "-Wmissing-prototypes" + #pragma clang diagnostic ignored "-Wmissing-braces" + + #include + #include + + using namespace metal; + + template + struct spvUnsafeArray + { + T elements[Num ? Num : 1]; + + thread T& operator [] (size_t pos) thread + { + return elements[pos]; + } + constexpr const thread T& operator [] (size_t pos) const thread + { + return elements[pos]; + } + + device T& operator [] (size_t pos) device + { + return elements[pos]; + } + constexpr const device T& operator [] (size_t pos) const device + { + return elements[pos]; + } + + constexpr const constant T& operator [] (size_t pos) const constant + { + return elements[pos]; + } + + threadgroup T& operator [] (size_t pos) threadgroup + { + return elements[pos]; + } + constexpr const threadgroup T& operator [] (size_t pos) const threadgroup + { + return elements[pos]; + } + }; + + struct ub_pass + { + float4 sun_dir_view; + float4 sun_color; + int4 flags; + float4 cascade_far_view_z; + float4x4 cascade_matrices[3]; + float4x4 view; + float4 camera_pos_world; + float4 sh[9]; + float4 ibl_params; + }; + + struct main0_out + { + float4 out_color [[color(0)]]; + }; + + struct main0_in + { + float3 v_view_pos [[user(locn0)]]; + float3 v_world_pos [[user(locn1)]]; + float4 v_base_color [[user(locn2), flat]]; + float4 v_material [[user(locn3), flat]]; + }; + + static inline __attribute__((always_inline)) + float sampleShadowPCF(thread const int& cascade, thread const float3& light_uv, thread const float& bias0, depth2d_array tex_shadow, sampler smp_shadow) + { + float _528 = float(cascade); + float _533 = light_uv.z - bias0; + float _549 = light_uv.x - 0.00048828125; + float _553 = light_uv.y - 0.00048828125; + float4 _556 = float4(_549, _553, _528, _533); + float4 _572 = float4(light_uv.x, _553, _528, _533); + float _583 = light_uv.x + 0.00048828125; + float4 _590 = float4(_583, _553, _528, _533); + float4 _606 = float4(_549, light_uv.y, _528, _533); + float4 _620 = float4(light_uv.xy, _528, _533); + float4 _636 = float4(_583, light_uv.y, _528, _533); + float _651 = light_uv.y + 0.00048828125; + float4 _654 = float4(_549, _651, _528, _533); + float4 _670 = float4(light_uv.x, _651, _528, _533); + float4 _688 = float4(_583, _651, _528, _533); + return ((((((((tex_shadow.sample_compare(smp_shadow, _556.xy, uint(rint(_556.z)), _533) + tex_shadow.sample_compare(smp_shadow, _572.xy, uint(rint(_572.z)), _533)) + tex_shadow.sample_compare(smp_shadow, _590.xy, uint(rint(_590.z)), _533)) + tex_shadow.sample_compare(smp_shadow, _606.xy, uint(rint(_606.z)), _533)) + tex_shadow.sample_compare(smp_shadow, _620.xy, uint(rint(_620.z)), _533)) + tex_shadow.sample_compare(smp_shadow, _636.xy, uint(rint(_636.z)), _533)) + tex_shadow.sample_compare(smp_shadow, _654.xy, uint(rint(_654.z)), _533)) + tex_shadow.sample_compare(smp_shadow, _670.xy, uint(rint(_670.z)), _533)) + tex_shadow.sample_compare(smp_shadow, _688.xy, uint(rint(_688.z)), _533)) * 0.111111111938953399658203125; + } + + static inline __attribute__((always_inline)) + float sampleCascade(thread const int& cascade, thread const float3& world_pos, thread const float& n_dot_l, depth2d_array tex_shadow, sampler smp_shadow, constant ub_pass& _706) + { + float4 _716 = _706.cascade_matrices[cascade] * float4(world_pos, 1.0); + float3 _723 = _716.xyz / float3(_716.w); + float3 _741 = float3((_723.x * 0.5) + 0.5, ((_723.y * _706.cascade_far_view_z.w) * 0.5) + 0.5, _723.z); + bool _745 = any(_741 < float3(0.0)); + bool _752; + if (!_745) + { + _752 = any(_741 > float3(1.0)); + } + else + { + _752 = _745; + } + if (_752) + { + return 1.0; + } + float _759 = fast::clamp(n_dot_l, 0.001000000047497451305389404296875, 1.0); + int param = cascade; + float3 param_1 = _741; + float param_2 = fast::clamp(0.001000000047497451305389404296875 * (sqrt(1.0 - (_759 * _759)) / _759), 0.0005000000237487256526947021484375, 0.0500000007450580596923828125); + float pcf = sampleShadowPCF(param, param_1, param_2, tex_shadow, smp_shadow); + if (cascade == 2) + { + float2 _790 = _741.xy; + float2 _795 = fast::min(_790, float2(1.0) - _790); + pcf = mix(1.0, pcf, fast::clamp(fast::min(_795.x, _795.y) * 10.0, 0.0, 1.0)); + } + return pcf; + } + + static inline __attribute__((always_inline)) + float sampleShadowCascaded(thread const float3& world_pos, thread const float& n_dot_l, thread const float& view_z, depth2d_array tex_shadow, sampler smp_shadow, constant ub_pass& _706) + { + int cascade = 2; + if (view_z < _706.cascade_far_view_z.x) + { + cascade = 0; + } + else + { + if (view_z < _706.cascade_far_view_z.y) + { + cascade = 1; + } + } + int param = cascade; + float3 param_1 = world_pos; + float param_2 = n_dot_l; + float shadow = sampleCascade(param, param_1, param_2, tex_shadow, smp_shadow, _706); + if (cascade < 2) + { + float _840; + if (cascade == 0) + { + _840 = _706.cascade_far_view_z.x; + } + else + { + _840 = _706.cascade_far_view_z.y; + } + float _852; + if (cascade == 0) + { + _852 = 0.0; + } + else + { + _852 = _706.cascade_far_view_z.x; + } + float _863 = mix(_840, _852, 0.100000001490116119384765625); + if (view_z > _863) + { + int param_3 = cascade + 1; + float3 param_4 = world_pos; + float param_5 = n_dot_l; + shadow = mix(shadow, sampleCascade(param_3, param_4, param_5, tex_shadow, smp_shadow, _706), (view_z - _863) / (_840 - _863)); + } + } + return shadow; + } + + static inline __attribute__((always_inline)) + float pbrDistributionGGX(thread const float& n_dot_h, thread const float& alpha) + { + float _106 = alpha * alpha; + float _115 = ((n_dot_h * n_dot_h) * (_106 - 1.0)) + 1.0; + return _106 / ((3.1415927410125732421875 * _115) * _115); + } + + static inline __attribute__((always_inline)) + float pbrVisibilitySmithCorrelated(thread const float& n_dot_v, thread const float& n_dot_l, thread const float& alpha) + { + float _128 = alpha * alpha; + float _135 = 1.0 - _128; + return 0.5 / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _135) + _128)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _135) + _128))) + 9.9999997473787516355514526367188e-06); + } + + static inline __attribute__((always_inline)) + float3 pbrFresnelSchlick(thread const float& v_dot_h, thread const float3& f0) + { + float _164 = 1.0 - v_dot_h; + float _168 = _164 * _164; + return f0 + ((float3(1.0) - f0) * ((_168 * _168) * _164)); + } + + static inline __attribute__((always_inline)) + float3 brdf_evaluate(thread const float3& N, thread const float3& V, thread const float3& L, thread const float3& sun_radiance, thread const float3& base_color, thread const float& metallic, thread const float& roughness) + { + float _187 = fast::max(dot(N, L), 0.0); + float3 _198 = fast::normalize(V + L); + float _212 = fast::max(roughness, 0.04500000178813934326171875); + float _216 = _212 * _212; + float param = fast::max(dot(N, _198), 0.0); + float param_1 = _216; + float param_2 = fast::max(dot(N, V), 9.9999997473787516355514526367188e-05); + float param_3 = _187; + float param_4 = _216; + float param_5 = fast::max(dot(V, _198), 0.0); + float3 param_6 = mix(float3(0.039999999105930328369140625), base_color, float3(metallic)); + float3 _243 = pbrFresnelSchlick(param_5, param_6); + return ((((((float3(1.0) - _243) * (1.0 - metallic)) * base_color) * float3(0.3183098733425140380859375)) + (_243 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _187; + } + + static inline __attribute__((always_inline)) + float3 pbrEvaluateShIrradiance(thread const float3& N, thread const spvUnsafeArray& sh) + { + float3 _398 = ((((((((sh[0].xyz * 0.2820948064327239990234375) + (sh[1].xyz * ((-0.48860251903533935546875) * N.y))) + (sh[2].xyz * (0.48860251903533935546875 * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125 * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125 * (((3.0 * N.z) * N.z) - 1.0)))) + (sh[7].xyz * (((-1.09254848957061767578125) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625 * ((N.x * N.x) - (N.y * N.y)))); + return _398; + } + + static inline __attribute__((always_inline)) + float3 pbrEvaluateIbl(thread const float3& N_world, thread const float3& V_world, thread const float3& base_color, thread const float& metallic, thread const float& roughness, thread const spvUnsafeArray& sh, texturecube tex_spec_cube, sampler smp_spec_cube, texture2d tex_brdf_lut, sampler smp_brdf_lut, thread const float& max_lod) + { + float _405 = fast::clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05, 1.0); + float3 _415 = mix(float3(0.039999999105930328369140625), base_color, float3(metallic)); + float3 param = N_world; + spvUnsafeArray param_1 = sh; + float4 _481 = tex_brdf_lut.sample(smp_brdf_lut, float2(_405, roughness)); + return (((((float3(1.0) - (_415 + ((fast::max(float3(1.0 - roughness), _415) - _415) * powr(fast::max(0.0, 1.0 - _405), 5.0)))) * (1.0 - metallic)) * base_color) * fast::max(pbrEvaluateShIrradiance(param, param_1), float3(0.0))) * float3(0.3183098733425140380859375)) + (tex_spec_cube.sample(smp_spec_cube, reflect(-V_world, N_world), level(roughness * max_lod)).xyz * ((_415 * _481.x) + float3(_481.y))); + } + + static inline __attribute__((always_inline)) + float3 pbrEvaluateAmbient(thread const bool& iblEnabled, thread const float3& N_world, thread const float3& V_world, thread const float3& base_color, thread const float& metallic, thread const float& roughness, thread const float& flat_strength, thread const spvUnsafeArray& sh, texturecube tex_spec_cube, sampler smp_spec_cube, texture2d tex_brdf_lut, sampler smp_brdf_lut, thread const float& max_lod) + { + float3 result = base_color * flat_strength; + if (iblEnabled) + { + float3 param = N_world; + float3 param_1 = V_world; + float3 param_2 = base_color; + float param_3 = metallic; + float param_4 = roughness; + spvUnsafeArray param_5 = sh; + float param_6 = max_lod; + result = pbrEvaluateIbl(param, param_1, param_2, param_3, param_4, param_5, tex_spec_cube, smp_spec_cube, tex_brdf_lut, smp_brdf_lut, param_6); + } + return result; + } + + fragment main0_out main0(main0_in in [[stage_in]], constant ub_pass& _706 [[buffer(1)]], depth2d_array tex_shadow [[texture(0)]], texturecube tex_ibl_spec [[texture(1)]], texture2d tex_brdf_lut [[texture(2)]], texture2d tex_ao [[texture(3)]], sampler smp_shadow [[sampler(0)]], sampler smp_ibl_spec [[sampler(1)]], sampler smp_brdf_lut [[sampler(2)]], sampler smp_ao [[sampler(3)]], float4 gl_FragCoord [[position]]) + { + main0_out out = {}; + float3 _895 = dfdx(in.v_view_pos); + float3 _898 = dfdy(in.v_view_pos); + float3 _907 = fast::normalize(cross(_898 * (-_706.cascade_far_view_z.w), _895)); + float _912 = -in.v_view_pos.z; + if (_706.flags.x == 1) + { + float _923 = fast::clamp(in.v_view_pos.z * (-0.0199999995529651641845703125), 0.0, 1.0); + out.out_color = float4(_923, _923, _923, 1.0); + return out; + } + if (_706.flags.x == 2) + { + int cascade = 2; + if (_912 < _706.cascade_far_view_z.x) + { + cascade = 0; + } + else + { + if (_912 < _706.cascade_far_view_z.y) + { + cascade = 1; + } + } + float4 _958 = _706.cascade_matrices[cascade] * float4(in.v_world_pos, 1.0); + float3 _965 = _958.xyz / float3(_958.w); + float3 _982 = float3((_965.x * 0.5) + 0.5, ((_965.y * _706.cascade_far_view_z.w) * 0.5) + 0.5, _965.z); + bool _986 = any(_982 < float3(0.0)); + bool _993; + if (!_986) + { + _993 = any(_982 > float3(1.0)); + } + else + { + _993 = _986; + } + float3 tint = float3(1.0); + if (!_993) + { + if (cascade == 0) + { + tint = float3(1.0, 0.4000000059604644775390625, 0.4000000059604644775390625); + } + else + { + if (cascade == 1) + { + tint = float3(0.4000000059604644775390625, 1.0, 0.4000000059604644775390625); + } + else + { + tint = float3(0.4000000059604644775390625, 0.4000000059604644775390625, 1.0); + } + } + } + out.out_color = float4(tint, 1.0); + return out; + } + if (_706.flags.x == 3) + { + out.out_color = float4((_907 * 0.5) + float3(0.5), 1.0); + return out; + } + float4 _1053 = tex_ao.sample(smp_ao, (gl_FragCoord.xy / float2(int2(tex_ao.get_width(), tex_ao.get_height()))), level(0.0)); + float _1054 = _1053.x; + if (_706.flags.x == 4) + { + out.out_color = float4(_1054, _1054, _1054, 1.0); + return out; + } + float3 _1072 = fast::normalize(_706.sun_dir_view.xyz); + float3 param = in.v_world_pos; + float param_1 = fast::max(dot(_907, _1072), 0.0); + float param_2 = _912; + float3 param_3 = _907; + float3 param_4 = fast::normalize(-in.v_view_pos); + float3 param_5 = _1072; + float3 param_6 = _706.sun_color.xyz * sampleShadowCascaded(param, param_1, param_2, tex_shadow, smp_shadow, _706); + float3 param_7 = in.v_base_color.xyz; + float param_8 = in.v_material.x; + float param_9 = in.v_material.y; + bool param_10 = _706.ibl_params.y > 0.5; + float3 param_11 = fast::normalize(transpose(float3x3(_706.view[0].xyz, _706.view[1].xyz, _706.view[2].xyz)) * _907); + float3 param_12 = fast::normalize(_706.camera_pos_world.xyz - in.v_world_pos); + float3 param_13 = in.v_base_color.xyz; + float param_14 = in.v_material.x; + float param_15 = in.v_material.y; + float param_16 = _706.sun_color.w; + spvUnsafeArray param_17; + param_17[0] = _706.sh[0]; + param_17[1] = _706.sh[1]; + param_17[2] = _706.sh[2]; + param_17[3] = _706.sh[3]; + param_17[4] = _706.sh[4]; + param_17[5] = _706.sh[5]; + param_17[6] = _706.sh[6]; + param_17[7] = _706.sh[7]; + param_17[8] = _706.sh[8]; + float param_18 = _706.ibl_params.x; + out.out_color = float4((brdf_evaluate(param_3, param_4, param_5, param_6, param_7, param_8, param_9) + (pbrEvaluateAmbient(param_10, param_11, param_12, param_13, param_14, param_15, param_16, param_17, tex_ibl_spec, smp_ibl_spec, tex_brdf_lut, smp_brdf_lut, param_18) * _1054)) * in.v_base_color.w, in.v_base_color.w); + return out; + } + +*/ +static const uint8_t fs_source_metal_macos[15098] = { + 0x23,0x70,0x72,0x61,0x67,0x6d,0x61,0x20,0x63,0x6c,0x61,0x6e,0x67,0x20,0x64,0x69, + 0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x20,0x69,0x67,0x6e,0x6f,0x72,0x65,0x64, + 0x20,0x22,0x2d,0x57,0x6d,0x69,0x73,0x73,0x69,0x6e,0x67,0x2d,0x70,0x72,0x6f,0x74, + 0x6f,0x74,0x79,0x70,0x65,0x73,0x22,0x0a,0x23,0x70,0x72,0x61,0x67,0x6d,0x61,0x20, + 0x63,0x6c,0x61,0x6e,0x67,0x20,0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63, + 0x20,0x69,0x67,0x6e,0x6f,0x72,0x65,0x64,0x20,0x22,0x2d,0x57,0x6d,0x69,0x73,0x73, + 0x69,0x6e,0x67,0x2d,0x62,0x72,0x61,0x63,0x65,0x73,0x22,0x0a,0x0a,0x23,0x69,0x6e, + 0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f,0x73,0x74,0x64, + 0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x73, + 0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a,0x75,0x73,0x69, + 0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20,0x6d,0x65,0x74, + 0x61,0x6c,0x3b,0x0a,0x0a,0x74,0x65,0x6d,0x70,0x6c,0x61,0x74,0x65,0x3c,0x74,0x79, + 0x70,0x65,0x6e,0x61,0x6d,0x65,0x20,0x54,0x2c,0x20,0x73,0x69,0x7a,0x65,0x5f,0x74, + 0x20,0x4e,0x75,0x6d,0x3e,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x73,0x70,0x76, + 0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x54,0x20,0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x4e,0x75,0x6d, + 0x20,0x3f,0x20,0x4e,0x75,0x6d,0x20,0x3a,0x20,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x0a,0x20,0x20,0x20,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x54,0x26,0x20, + 0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72,0x20,0x5b,0x5d,0x20,0x28,0x73,0x69,0x7a, + 0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f, + 0x73,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x65,0x78,0x70,0x72,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x74,0x68, + 0x72,0x65,0x61,0x64,0x20,0x54,0x26,0x20,0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72, + 0x20,0x5b,0x5d,0x20,0x28,0x73,0x69,0x7a,0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f,0x73,0x5d, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x0a,0x20,0x20,0x20, + 0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x20,0x54,0x26,0x20,0x6f,0x70,0x65,0x72,0x61, + 0x74,0x6f,0x72,0x20,0x5b,0x5d,0x20,0x28,0x73,0x69,0x7a,0x65,0x5f,0x74,0x20,0x70, + 0x6f,0x73,0x29,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f,0x73,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6e,0x73,0x74,0x65,0x78, + 0x70,0x72,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x20, + 0x54,0x26,0x20,0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72,0x20,0x5b,0x5d,0x20,0x28, + 0x73,0x69,0x7a,0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x65,0x6c, + 0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f,0x73,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x65,0x78,0x70,0x72,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x61,0x6e,0x74,0x20,0x54,0x26,0x20,0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72, + 0x20,0x5b,0x5d,0x20,0x28,0x73,0x69,0x7a,0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f, + 0x73,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x0a,0x20, + 0x20,0x20,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x67,0x72,0x6f,0x75,0x70,0x20,0x54, + 0x26,0x20,0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72,0x20,0x5b,0x5d,0x20,0x28,0x73, + 0x69,0x7a,0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x67,0x72,0x6f,0x75,0x70,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x65,0x6c,0x65,0x6d, + 0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f,0x73,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6e,0x73,0x74,0x65,0x78,0x70,0x72,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x67,0x72,0x6f,0x75,0x70, + 0x20,0x54,0x26,0x20,0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72,0x20,0x5b,0x5d,0x20, + 0x28,0x73,0x69,0x7a,0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x67,0x72,0x6f,0x75,0x70,0x0a,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f,0x73, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72, + 0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72, + 0x5f,0x76,0x69,0x65,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x6e,0x74,0x34,0x20,0x66,0x6c,0x61,0x67,0x73,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, + 0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x33,0x5d,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x76,0x69,0x65,0x77,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x61,0x6d,0x65, + 0x72,0x61,0x5f,0x70,0x6f,0x73,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x69,0x62,0x6c,0x5f,0x70, + 0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63, + 0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x20,0x5b,0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29,0x5d,0x5d,0x3b, + 0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e, + 0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x20,0x5b,0x5b,0x75, + 0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x5f,0x70,0x6f,0x73,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e, + 0x31,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b, + 0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x32,0x29,0x2c,0x20,0x66,0x6c,0x61, + 0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x5b,0x5b,0x75,0x73,0x65, + 0x72,0x28,0x6c,0x6f,0x63,0x6e,0x33,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d, + 0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c, + 0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f, + 0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65, + 0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53, + 0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20, + 0x63,0x6f,0x6e,0x73,0x74,0x20,0x69,0x6e,0x74,0x26,0x20,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75, + 0x76,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x62,0x69,0x61,0x73,0x30,0x2c,0x20,0x64,0x65, + 0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61, + 0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73, + 0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x35,0x32,0x38,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x35,0x33,0x33,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e, + 0x7a,0x20,0x2d,0x20,0x62,0x69,0x61,0x73,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x34,0x39,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68, + 0x74,0x5f,0x75,0x76,0x2e,0x78,0x20,0x2d,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38, + 0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x35,0x35,0x33,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75, + 0x76,0x2e,0x79,0x20,0x2d,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38, + 0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x5f,0x35,0x35,0x36,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35, + 0x34,0x39,0x2c,0x20,0x5f,0x35,0x35,0x33,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20, + 0x5f,0x35,0x33,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x5f,0x35,0x37,0x32,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, + 0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20,0x5f,0x35,0x35,0x33, + 0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x38,0x33,0x20,0x3d,0x20, + 0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20,0x2b,0x20,0x30,0x2e,0x30, + 0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x35,0x39,0x30,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x38,0x33,0x2c,0x20,0x5f,0x35,0x35,0x33,0x2c, + 0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36,0x30,0x36,0x20,0x3d,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x34,0x39,0x2c,0x20,0x6c,0x69,0x67, + 0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f, + 0x35,0x33,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x5f,0x36,0x32,0x30,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6c, + 0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x79,0x2c,0x20,0x5f,0x35,0x32,0x38, + 0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x5f,0x36,0x33,0x36,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x28,0x5f,0x35,0x38,0x33,0x2c,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76, + 0x2e,0x79,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x35,0x31,0x20, + 0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x20,0x2b,0x20,0x30, + 0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36,0x35,0x34,0x20,0x3d,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x34,0x39,0x2c,0x20,0x5f,0x36,0x35, + 0x31,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36,0x37,0x30,0x20, + 0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75, + 0x76,0x2e,0x78,0x2c,0x20,0x5f,0x36,0x35,0x31,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c, + 0x20,0x5f,0x35,0x33,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x5f,0x36,0x38,0x38,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x28,0x5f,0x35,0x38,0x33,0x2c,0x20,0x5f,0x36,0x35,0x31,0x2c,0x20,0x5f,0x35,0x32, + 0x38,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x74,0x65,0x78, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63, + 0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2c,0x20,0x5f,0x35,0x35,0x36,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74, + 0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x35,0x35,0x36,0x2e,0x7a,0x29,0x29,0x2c,0x20, + 0x5f,0x35,0x33,0x33,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72, + 0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x35, + 0x37,0x32,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74, + 0x28,0x5f,0x35,0x37,0x32,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29, + 0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73, + 0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d, + 0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x35,0x39,0x30,0x2e,0x78, + 0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x35,0x39, + 0x30,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x20,0x2b,0x20, + 0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68, + 0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x36,0x30,0x36,0x2e,0x78,0x79,0x2c,0x20,0x75, + 0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x36,0x30,0x36,0x2e,0x7a,0x29, + 0x29,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f, + 0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x2c,0x20,0x5f,0x36,0x32,0x30,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28, + 0x72,0x69,0x6e,0x74,0x28,0x5f,0x36,0x32,0x30,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f, + 0x35,0x33,0x33,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72, + 0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x36, + 0x33,0x36,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74, + 0x28,0x5f,0x36,0x33,0x36,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29, + 0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73, + 0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d, + 0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x36,0x35,0x34,0x2e,0x78, + 0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x36,0x35, + 0x34,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x20,0x2b,0x20, + 0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68, + 0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x36,0x37,0x30,0x2e,0x78,0x79,0x2c,0x20,0x75, + 0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x36,0x37,0x30,0x2e,0x7a,0x29, + 0x29,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f, + 0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x2c,0x20,0x5f,0x36,0x38,0x38,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28, + 0x72,0x69,0x6e,0x74,0x28,0x5f,0x36,0x38,0x38,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f, + 0x35,0x33,0x33,0x29,0x29,0x20,0x2a,0x20,0x30,0x2e,0x31,0x31,0x31,0x31,0x31,0x31, + 0x31,0x31,0x31,0x39,0x33,0x38,0x39,0x35,0x33,0x33,0x39,0x39,0x36,0x35,0x38,0x32, + 0x30,0x33,0x31,0x32,0x35,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63, + 0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62, + 0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e, + 0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x69,0x6e,0x74,0x26,0x20,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x77,0x6f,0x72,0x6c,0x64, + 0x5f,0x70,0x6f,0x73,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f, + 0x6c,0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61,0x79, + 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74, + 0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x37,0x30,0x36,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x31, + 0x36,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x5d,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x37,0x32,0x33,0x20,0x3d,0x20,0x5f, + 0x37,0x31,0x36,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x28,0x5f,0x37,0x31,0x36,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x5f,0x37,0x34,0x31,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x28,0x5f,0x37,0x32,0x33,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35, + 0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x28,0x28,0x5f,0x37,0x32,0x33,0x2e, + 0x79,0x20,0x2a,0x20,0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a, + 0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x37,0x32, + 0x33,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f, + 0x37,0x34,0x35,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x5f,0x37,0x34,0x31,0x20,0x3c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x37,0x35,0x32,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x37,0x34,0x35,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x37,0x35,0x32,0x20, + 0x3d,0x20,0x61,0x6e,0x79,0x28,0x5f,0x37,0x34,0x31,0x20,0x3e,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x37,0x35,0x32,0x20,0x3d,0x20,0x5f, + 0x37,0x34,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x5f,0x37,0x35,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e, + 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x37,0x35,0x39,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a, + 0x63,0x6c,0x61,0x6d,0x70,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x30, + 0x2e,0x30,0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x34,0x37,0x34,0x39,0x37, + 0x34,0x35,0x31,0x33,0x30,0x35,0x33,0x38,0x39,0x34,0x30,0x34,0x32,0x39,0x36,0x38, + 0x37,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x37,0x34,0x31,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20, + 0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x30,0x2e, + 0x30,0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x34,0x37,0x34,0x39,0x37,0x34, + 0x35,0x31,0x33,0x30,0x35,0x33,0x38,0x39,0x34,0x30,0x34,0x32,0x39,0x36,0x38,0x37, + 0x35,0x20,0x2a,0x20,0x28,0x73,0x71,0x72,0x74,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20, + 0x28,0x5f,0x37,0x35,0x39,0x20,0x2a,0x20,0x5f,0x37,0x35,0x39,0x29,0x29,0x20,0x2f, + 0x20,0x5f,0x37,0x35,0x39,0x29,0x2c,0x20,0x30,0x2e,0x30,0x30,0x30,0x35,0x30,0x30, + 0x30,0x30,0x30,0x30,0x32,0x33,0x37,0x34,0x38,0x37,0x32,0x35,0x36,0x35,0x32,0x36, + 0x39,0x34,0x37,0x30,0x32,0x31,0x34,0x38,0x34,0x33,0x37,0x35,0x2c,0x20,0x30,0x2e, + 0x30,0x35,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x37,0x34,0x35,0x30,0x35,0x38,0x30, + 0x35,0x39,0x36,0x39,0x32,0x33,0x38,0x32,0x38,0x31,0x32,0x35,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x73, + 0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x70, + 0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x37,0x39,0x30, + 0x20,0x3d,0x20,0x5f,0x37,0x34,0x31,0x2e,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x37,0x39,0x35,0x20, + 0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x69,0x6e,0x28,0x5f,0x37,0x39,0x30, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20, + 0x5f,0x37,0x39,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x70, + 0x63,0x66,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x31,0x2e,0x30,0x2c,0x20,0x70,0x63, + 0x66,0x2c,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x66, + 0x61,0x73,0x74,0x3a,0x3a,0x6d,0x69,0x6e,0x28,0x5f,0x37,0x39,0x35,0x2e,0x78,0x2c, + 0x20,0x5f,0x37,0x39,0x35,0x2e,0x79,0x29,0x20,0x2a,0x20,0x31,0x30,0x2e,0x30,0x2c, + 0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x70,0x63, + 0x66,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c, + 0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f, + 0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65, + 0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53, + 0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x74,0x68, + 0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x26,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x74,0x68, + 0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x26,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x76, + 0x69,0x65,0x77,0x5f,0x7a,0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61, + 0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20, + 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x37, + 0x30,0x36,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x37,0x30,0x36, + 0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65, + 0x77,0x5f,0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x30, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x37,0x30,0x36, + 0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65, + 0x77,0x5f,0x7a,0x2e,0x79,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f, + 0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x68, + 0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x2c,0x20,0x5f,0x37,0x30,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3c,0x20,0x32,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x38,0x34,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x34,0x30,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x34,0x30,0x20,0x3d,0x20,0x5f,0x37, + 0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x38,0x35,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x35,0x32,0x20,0x3d,0x20,0x30,0x2e, + 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x5f,0x38,0x35,0x32,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x36,0x33,0x20,0x3d, + 0x20,0x6d,0x69,0x78,0x28,0x5f,0x38,0x34,0x30,0x2c,0x20,0x5f,0x38,0x35,0x32,0x2c, + 0x20,0x30,0x2e,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x34,0x39,0x30,0x31, + 0x31,0x36,0x31,0x31,0x39,0x33,0x38,0x34,0x37,0x36,0x35,0x36,0x32,0x35,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65, + 0x77,0x5f,0x7a,0x20,0x3e,0x20,0x5f,0x38,0x36,0x33,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x2b,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d, + 0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x6d, + 0x69,0x78,0x28,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x35,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20, + 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x37,0x30,0x36, + 0x29,0x2c,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x2d,0x20,0x5f,0x38,0x36, + 0x33,0x29,0x20,0x2f,0x20,0x28,0x5f,0x38,0x34,0x30,0x20,0x2d,0x20,0x5f,0x38,0x36, + 0x33,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69, + 0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69, + 0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69, + 0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62, + 0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58, + 0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x26,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x74,0x68, + 0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x26,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x36,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68, + 0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x35,0x20,0x3d,0x20,0x28,0x28,0x6e,0x5f, + 0x64,0x6f,0x74,0x5f,0x68,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x29, + 0x20,0x2a,0x20,0x28,0x5f,0x31,0x30,0x36,0x20,0x2d,0x20,0x31,0x2e,0x30,0x29,0x29, + 0x20,0x2b,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x5f,0x31,0x30,0x36,0x20,0x2f,0x20,0x28,0x28,0x33,0x2e,0x31,0x34, + 0x31,0x35,0x39,0x32,0x37,0x34,0x31,0x30,0x31,0x32,0x35,0x37,0x33,0x32,0x34,0x32, + 0x31,0x38,0x37,0x35,0x20,0x2a,0x20,0x5f,0x31,0x31,0x35,0x29,0x20,0x2a,0x20,0x5f, + 0x31,0x31,0x35,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, + 0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75, + 0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c, + 0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x56, + 0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f, + 0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20, + 0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6e,0x5f,0x64, + 0x6f,0x74,0x5f,0x76,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f, + 0x6c,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x38,0x20,0x3d, + 0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x35,0x20,0x3d, + 0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f,0x31,0x32,0x38,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x30,0x2e,0x35,0x20,0x2f,0x20,0x28,0x28, + 0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28, + 0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f, + 0x74,0x5f,0x76,0x29,0x20,0x2a,0x20,0x5f,0x31,0x33,0x35,0x29,0x20,0x2b,0x20,0x5f, + 0x31,0x32,0x38,0x29,0x29,0x20,0x2b,0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76, + 0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f, + 0x6c,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x29,0x20,0x2a,0x20,0x5f, + 0x31,0x33,0x35,0x29,0x20,0x2b,0x20,0x5f,0x31,0x32,0x38,0x29,0x29,0x29,0x20,0x2b, + 0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37, + 0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31, + 0x38,0x38,0x65,0x2d,0x30,0x36,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74, + 0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72, + 0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f, + 0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63, + 0x6b,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x26,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x74, + 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x26,0x20,0x66,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x34,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d, + 0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x38,0x20,0x3d,0x20,0x5f,0x31,0x36,0x34,0x20, + 0x2a,0x20,0x5f,0x31,0x36,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x66,0x30,0x20,0x2b,0x20,0x28,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x66,0x30,0x29,0x20,0x2a,0x20,0x28,0x28, + 0x5f,0x31,0x36,0x38,0x20,0x2a,0x20,0x5f,0x31,0x36,0x38,0x29,0x20,0x2a,0x20,0x5f, + 0x31,0x36,0x34,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63, + 0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62, + 0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e, + 0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x72, + 0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x74,0x68,0x72,0x65, + 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26, + 0x20,0x4e,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x56,0x2c,0x20,0x74,0x68,0x72,0x65, + 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26, + 0x20,0x4c,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64, + 0x69,0x61,0x6e,0x63,0x65,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x62,0x61,0x73,0x65, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x65,0x74,0x61, + 0x6c,0x6c,0x69,0x63,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e, + 0x65,0x73,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x38,0x37,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61, + 0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x4c,0x29,0x2c,0x20,0x30,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31, + 0x39,0x38,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x69,0x7a,0x65,0x28,0x56,0x20,0x2b,0x20,0x4c,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x32,0x20,0x3d,0x20,0x66,0x61, + 0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73, + 0x73,0x2c,0x20,0x30,0x2e,0x30,0x34,0x35,0x30,0x30,0x30,0x30,0x30,0x31,0x37,0x38, + 0x38,0x31,0x33,0x39,0x33,0x34,0x33,0x32,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x36, + 0x20,0x3d,0x20,0x5f,0x32,0x31,0x32,0x20,0x2a,0x20,0x5f,0x32,0x31,0x32,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20, + 0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28, + 0x4e,0x2c,0x20,0x5f,0x31,0x39,0x38,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x20,0x3d,0x20,0x5f,0x32,0x31,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x66,0x61, + 0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x56, + 0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37, + 0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36, + 0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f, + 0x31,0x38,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x32,0x31,0x36,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35, + 0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74, + 0x28,0x56,0x2c,0x20,0x5f,0x31,0x39,0x38,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39, + 0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c, + 0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x28,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x32,0x34,0x33,0x20, + 0x3d,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c, + 0x69,0x63,0x6b,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31, + 0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x32,0x34,0x33,0x29,0x20,0x2a,0x20,0x28,0x31, + 0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20, + 0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38, + 0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33, + 0x37,0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x5f,0x32,0x34,0x33,0x20,0x2a,0x20,0x28, + 0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47, + 0x47,0x58,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x29,0x20,0x2a,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69, + 0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65, + 0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29,0x29,0x29,0x29,0x20, + 0x2a,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x29,0x20, + 0x2a,0x20,0x5f,0x31,0x38,0x37,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69, + 0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69, + 0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69, + 0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, + 0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61, + 0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4e,0x2c,0x20,0x74, + 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x73,0x70,0x76,0x55, + 0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x2c,0x20,0x39,0x3e,0x26,0x20,0x73,0x68,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x33,0x39,0x38,0x20,0x3d,0x20,0x28, + 0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x73,0x68,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a, + 0x20,0x2a,0x20,0x30,0x2e,0x32,0x38,0x32,0x30,0x39,0x34,0x38,0x30,0x36,0x34,0x33, + 0x32,0x37,0x32,0x33,0x39,0x39,0x39,0x30,0x32,0x33,0x34,0x33,0x37,0x35,0x29,0x20, + 0x2b,0x20,0x28,0x73,0x68,0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28, + 0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35, + 0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x4e, + 0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x32,0x5d,0x2e,0x78, + 0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31, + 0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x20, + 0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x33, + 0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38, + 0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34, + 0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x29,0x29,0x20,0x2b, + 0x20,0x28,0x73,0x68,0x5b,0x34,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28, + 0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31, + 0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29, + 0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b, + 0x35,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30, + 0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37, + 0x35,0x37,0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x20,0x2a, + 0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x36,0x5d, + 0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x33,0x31,0x35,0x33,0x39,0x31, + 0x35,0x37,0x30,0x33,0x32,0x39,0x36,0x36,0x36,0x31,0x33,0x37,0x36,0x39,0x35,0x33, + 0x31,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x28,0x33,0x2e,0x30,0x20,0x2a,0x20,0x4e, + 0x2e,0x7a,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30, + 0x29,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x37,0x5d,0x2e,0x78,0x79, + 0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38, + 0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32, + 0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29, + 0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x38,0x5d,0x2e,0x78,0x79,0x7a,0x20, + 0x2a,0x20,0x28,0x30,0x2e,0x35,0x34,0x36,0x32,0x37,0x34,0x32,0x34,0x34,0x37,0x38, + 0x35,0x33,0x30,0x38,0x38,0x33,0x37,0x38,0x39,0x30,0x36,0x32,0x35,0x20,0x2a,0x20, + 0x28,0x28,0x4e,0x2e,0x78,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2d,0x20,0x28, + 0x4e,0x2e,0x79,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x33,0x39,0x38,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65, + 0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28, + 0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61, + 0x74,0x65,0x49,0x62,0x6c,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4e,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c, + 0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x26,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20, + 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x73,0x70,0x76, + 0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x2c,0x20,0x39,0x3e,0x26,0x20,0x73,0x68,0x2c,0x20,0x74,0x65,0x78,0x74, + 0x75,0x72,0x65,0x63,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74, + 0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x61, + 0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63, + 0x75,0x62,0x65,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66, + 0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, + 0x75,0x74,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f, + 0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x61, + 0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x34,0x30,0x35,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a, + 0x63,0x6c,0x61,0x6d,0x70,0x28,0x64,0x6f,0x74,0x28,0x4e,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x2c,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x39,0x2e,0x39, + 0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33, + 0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d, + 0x30,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x5f,0x34,0x31,0x35,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39, + 0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34, + 0x30,0x36,0x32,0x35,0x29,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x6d,0x65,0x74,0x61,0x6c,0x6c, + 0x69,0x63,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41, + 0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x34,0x38,0x31,0x20,0x3d,0x20, + 0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2e,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x34,0x30,0x35,0x2c,0x20,0x72, + 0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x28,0x5f,0x34,0x31,0x35,0x20, + 0x2b,0x20,0x28,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x72,0x6f,0x75,0x67,0x68, + 0x6e,0x65,0x73,0x73,0x29,0x2c,0x20,0x5f,0x34,0x31,0x35,0x29,0x20,0x2d,0x20,0x5f, + 0x34,0x31,0x35,0x29,0x20,0x2a,0x20,0x70,0x6f,0x77,0x72,0x28,0x66,0x61,0x73,0x74, + 0x3a,0x3a,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x20,0x2d, + 0x20,0x5f,0x34,0x30,0x35,0x29,0x2c,0x20,0x35,0x2e,0x30,0x29,0x29,0x29,0x29,0x20, + 0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69, + 0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x29,0x20,0x2a,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x70,0x62, + 0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64, + 0x69,0x61,0x6e,0x63,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e, + 0x30,0x29,0x29,0x29,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e, + 0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30, + 0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x74, + 0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2e,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62, + 0x65,0x2c,0x20,0x72,0x65,0x66,0x6c,0x65,0x63,0x74,0x28,0x2d,0x56,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x2c,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x6c, + 0x65,0x76,0x65,0x6c,0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x20,0x2a, + 0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x29,0x2e,0x78,0x79,0x7a,0x20,0x2a, + 0x20,0x28,0x28,0x5f,0x34,0x31,0x35,0x20,0x2a,0x20,0x5f,0x34,0x38,0x31,0x2e,0x78, + 0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x34,0x38,0x31,0x2e, + 0x79,0x29,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, + 0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75, + 0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c, + 0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72, + 0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28, + 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x62,0x6f,0x6f, + 0x6c,0x26,0x20,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x2c,0x20,0x74, + 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x26,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x26,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20, + 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x74,0x68,0x72,0x65, + 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x72,0x6f, + 0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20, + 0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x66,0x6c,0x61, + 0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x2c,0x20,0x74,0x68,0x72,0x65, + 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61, + 0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20, + 0x39,0x3e,0x26,0x20,0x73,0x68,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x63, + 0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73, + 0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, + 0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c, + 0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74, + 0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66, + 0x5f,0x6c,0x75,0x74,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f, + 0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x20,0x2a,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e, + 0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x62,0x6c, + 0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x6d,0x65, + 0x74,0x61,0x6c,0x6c,0x69,0x63,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20, + 0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61, + 0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36, + 0x20,0x3d,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x70,0x62,0x72, + 0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20, + 0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73, + 0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x74,0x65, + 0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73,0x6d,0x70,0x5f, + 0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x3b,0x0a,0x7d,0x0a,0x0a, + 0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f, + 0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69, + 0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d, + 0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x70, + 0x61,0x73,0x73,0x26,0x20,0x5f,0x37,0x30,0x36,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66, + 0x65,0x72,0x28,0x31,0x29,0x5d,0x5d,0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64, + 0x5f,0x61,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65, + 0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75, + 0x72,0x65,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65, + 0x63,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f, + 0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75, + 0x72,0x65,0x28,0x31,0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65, + 0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72, + 0x64,0x66,0x5f,0x6c,0x75,0x74,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65, + 0x28,0x32,0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64, + 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x20,0x5b, + 0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x33,0x29,0x5d,0x5d,0x2c,0x20,0x73, + 0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d, + 0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x69,0x62, + 0x6c,0x5f,0x73,0x70,0x65,0x63,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72, + 0x28,0x31,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73, + 0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x20,0x5b,0x5b,0x73,0x61, + 0x6d,0x70,0x6c,0x65,0x72,0x28,0x32,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x20,0x5b,0x5b,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x72,0x28,0x33,0x29,0x5d,0x5d,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x20,0x5b, + 0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74, + 0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x5f,0x38,0x39,0x35,0x20,0x3d,0x20,0x64,0x66,0x64,0x78,0x28,0x69,0x6e, + 0x2e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x38,0x39,0x38,0x20,0x3d,0x20, + 0x64,0x66,0x64,0x79,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70, + 0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x5f,0x39,0x30,0x37,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72, + 0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x63,0x72,0x6f,0x73,0x73,0x28,0x5f,0x38,0x39, + 0x38,0x20,0x2a,0x20,0x28,0x2d,0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29, + 0x2c,0x20,0x5f,0x38,0x39,0x35,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x39,0x31,0x32,0x20,0x3d,0x20,0x2d,0x69,0x6e,0x2e,0x76, + 0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x36,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e, + 0x78,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x32,0x33, + 0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x69, + 0x6e,0x2e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2e,0x7a,0x20,0x2a, + 0x20,0x28,0x2d,0x30,0x2e,0x30,0x31,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x35,0x35, + 0x32,0x39,0x36,0x35,0x31,0x36,0x34,0x31,0x38,0x34,0x35,0x37,0x30,0x33,0x31,0x32, + 0x35,0x29,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x39, + 0x32,0x33,0x2c,0x20,0x5f,0x39,0x32,0x33,0x2c,0x20,0x5f,0x39,0x32,0x33,0x2c,0x20, + 0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x36,0x2e,0x66,0x6c,0x61, + 0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x39,0x31,0x32,0x20,0x3c,0x20,0x5f,0x37,0x30, + 0x36,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, + 0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x39,0x31,0x32, + 0x20,0x3c,0x20,0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, + 0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x5f,0x39,0x35,0x38,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x5d,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x69, + 0x6e,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31, + 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x5f,0x39,0x36,0x35,0x20,0x3d,0x20,0x5f,0x39,0x35,0x38,0x2e, + 0x78,0x79,0x7a,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x39,0x35, + 0x38,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x5f,0x39,0x38,0x32,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x28,0x5f,0x39,0x36,0x35,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35, + 0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x28,0x28,0x5f,0x39,0x36,0x35,0x2e, + 0x79,0x20,0x2a,0x20,0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a, + 0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x39,0x36, + 0x35,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f, + 0x6f,0x6c,0x20,0x5f,0x39,0x38,0x36,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x5f,0x39, + 0x38,0x32,0x20,0x3c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x29, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20, + 0x5f,0x39,0x39,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x21,0x5f,0x39,0x38,0x36,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f, + 0x39,0x39,0x33,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x5f,0x39,0x38,0x32,0x20,0x3e, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x39,0x39,0x33, + 0x20,0x3d,0x20,0x5f,0x39,0x38,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, + 0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x21,0x5f,0x39,0x39,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74, + 0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30, + 0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30, + 0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x30, + 0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34, + 0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, + 0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36, + 0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30, + 0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30, + 0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e, + 0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30, + 0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35, + 0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30, + 0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30, + 0x36,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, + 0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x28,0x74,0x69,0x6e,0x74,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f, + 0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x5f,0x37,0x30,0x36,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d, + 0x3d,0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x5f,0x39,0x30,0x37,0x20, + 0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, + 0x30,0x2e,0x35,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x5f,0x31,0x30,0x35,0x33,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20,0x28, + 0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x20, + 0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x69,0x6e,0x74,0x32,0x28,0x74,0x65, + 0x78,0x5f,0x61,0x6f,0x2e,0x67,0x65,0x74,0x5f,0x77,0x69,0x64,0x74,0x68,0x28,0x29, + 0x2c,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e,0x67,0x65,0x74,0x5f,0x68,0x65,0x69, + 0x67,0x68,0x74,0x28,0x29,0x29,0x29,0x29,0x2c,0x20,0x6c,0x65,0x76,0x65,0x6c,0x28, + 0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x30,0x35,0x34,0x20,0x3d,0x20,0x5f,0x31,0x30,0x35,0x33,0x2e,0x78, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x36,0x2e,0x66, + 0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x34,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f, + 0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x28,0x5f,0x31,0x30,0x35,0x34,0x2c,0x20,0x5f,0x31,0x30,0x35,0x34,0x2c,0x20, + 0x5f,0x31,0x30,0x35,0x34,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x5f,0x31,0x30,0x37,0x32,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a, + 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37,0x30,0x36,0x2e,0x73, + 0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x76,0x69,0x65,0x77,0x2e,0x78,0x79,0x7a,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d, + 0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x5f,0x39,0x30,0x37,0x2c,0x20,0x5f,0x31,0x30, + 0x37,0x32,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f, + 0x39,0x31,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x39,0x30,0x37,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x34,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x69,0x7a,0x65,0x28,0x2d,0x69,0x6e,0x2e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x70,0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x32, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x73,0x75,0x6e,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x68, + 0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x2c,0x20,0x5f,0x37,0x30,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x69,0x6e, + 0x2e,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79, + 0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65, + 0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76, + 0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x62,0x6f,0x6f,0x6c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x36,0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73, + 0x2e,0x79,0x20,0x3e,0x20,0x30,0x2e,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20, + 0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28, + 0x74,0x72,0x61,0x6e,0x73,0x70,0x6f,0x73,0x65,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x78,0x33,0x28,0x5f,0x37,0x30,0x36,0x2e,0x76,0x69,0x65,0x77,0x5b,0x30,0x5d,0x2e, + 0x78,0x79,0x7a,0x2c,0x20,0x5f,0x37,0x30,0x36,0x2e,0x76,0x69,0x65,0x77,0x5b,0x31, + 0x5d,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x37,0x30,0x36,0x2e,0x76,0x69,0x65,0x77, + 0x5b,0x32,0x5d,0x2e,0x78,0x79,0x7a,0x29,0x29,0x20,0x2a,0x20,0x5f,0x39,0x30,0x37, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e, + 0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37,0x30,0x36,0x2e,0x63,0x61, + 0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78, + 0x79,0x7a,0x20,0x2d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x70,0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76, + 0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x34,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72, + 0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76, + 0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20, + 0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66, + 0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39, + 0x3e,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x30,0x5d,0x20,0x3d,0x20,0x5f,0x37, + 0x30,0x36,0x2e,0x73,0x68,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x31,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36, + 0x2e,0x73,0x68,0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x37,0x5b,0x32,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x73, + 0x68,0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x37,0x5b,0x33,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x73,0x68,0x5b, + 0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37, + 0x5b,0x34,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x73,0x68,0x5b,0x34,0x5d, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x35, + 0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x73,0x68,0x5b,0x35,0x5d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x36,0x5d,0x20, + 0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x73,0x68,0x5b,0x36,0x5d,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x37,0x5d,0x20,0x3d,0x20, + 0x5f,0x37,0x30,0x36,0x2e,0x73,0x68,0x5b,0x37,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x38,0x5d,0x20,0x3d,0x20,0x5f,0x37, + 0x30,0x36,0x2e,0x73,0x68,0x5b,0x38,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x36,0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x62,0x72, + 0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x29,0x20,0x2b,0x20,0x28,0x70,0x62, + 0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c, + 0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x73, + 0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x74,0x65,0x78, + 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62, + 0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x38,0x29,0x20,0x2a,0x20,0x5f,0x31,0x30,0x35,0x34,0x29,0x29,0x20,0x2a,0x20,0x69, + 0x6e,0x2e,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77, + 0x2c,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +static inline const sg_shader_desc* cube_shader_desc(sg_backend backend) { + if (backend == SG_BACKEND_GLCORE) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)vs_source_glsl430; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)fs_source_glsl430; + desc.fragment_func.entry = "main"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[0].glsl_name = "in_pos"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 288; + desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[0].glsl_uniforms[0].array_count = 18; + desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_frame"; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 496; + desc.uniform_blocks[1].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[0].array_count = 0; + desc.uniform_blocks[1].glsl_uniforms[0].glsl_name = "_706.sun_dir_view"; + desc.uniform_blocks[1].glsl_uniforms[1].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[1].array_count = 0; + desc.uniform_blocks[1].glsl_uniforms[1].glsl_name = "_706.sun_color"; + desc.uniform_blocks[1].glsl_uniforms[2].type = SG_UNIFORMTYPE_INT4; + desc.uniform_blocks[1].glsl_uniforms[2].array_count = 0; + desc.uniform_blocks[1].glsl_uniforms[2].glsl_name = "_706.flags"; + desc.uniform_blocks[1].glsl_uniforms[3].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[3].array_count = 0; + desc.uniform_blocks[1].glsl_uniforms[3].glsl_name = "_706.cascade_far_view_z"; + desc.uniform_blocks[1].glsl_uniforms[4].type = SG_UNIFORMTYPE_MAT4; + desc.uniform_blocks[1].glsl_uniforms[4].array_count = 3; + desc.uniform_blocks[1].glsl_uniforms[4].glsl_name = "_706.cascade_matrices"; + desc.uniform_blocks[1].glsl_uniforms[5].type = SG_UNIFORMTYPE_MAT4; + desc.uniform_blocks[1].glsl_uniforms[5].array_count = 0; + desc.uniform_blocks[1].glsl_uniforms[5].glsl_name = "_706.view"; + desc.uniform_blocks[1].glsl_uniforms[6].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[6].array_count = 0; + desc.uniform_blocks[1].glsl_uniforms[6].glsl_name = "_706.camera_pos_world"; + desc.uniform_blocks[1].glsl_uniforms[7].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[7].array_count = 9; + desc.uniform_blocks[1].glsl_uniforms[7].glsl_name = "_706.sh"; + desc.uniform_blocks[1].glsl_uniforms[8].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[8].array_count = 0; + desc.uniform_blocks[1].glsl_uniforms[8].glsl_name = "_706.ibl_params"; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 16; + desc.uniform_blocks[2].glsl_uniforms[0].type = SG_UNIFORMTYPE_INT4; + desc.uniform_blocks[2].glsl_uniforms[0].array_count = 1; + desc.uniform_blocks[2].glsl_uniforms[0].glsl_name = "ub_draw"; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.glsl_binding_n = 0; + desc.views[1].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[1].texture.image_type = SG_IMAGETYPE_ARRAY; + desc.views[1].texture.sample_type = SG_IMAGESAMPLETYPE_DEPTH; + desc.views[1].texture.multisampled = false; + desc.views[2].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[2].texture.image_type = SG_IMAGETYPE_CUBE; + desc.views[2].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[2].texture.multisampled = false; + desc.views[3].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[3].texture.image_type = SG_IMAGETYPE_2D; + desc.views[3].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[3].texture.multisampled = false; + desc.views[4].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[4].texture.image_type = SG_IMAGETYPE_2D; + desc.views[4].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[4].texture.multisampled = false; + desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_COMPARISON; + desc.samplers[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[1].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[2].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[2].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[3].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[3].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[0].view_slot = 4; + desc.texture_sampler_pairs[0].sampler_slot = 3; + desc.texture_sampler_pairs[0].glsl_name = "tex_ao_smp_ao"; + desc.texture_sampler_pairs[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[1].view_slot = 1; + desc.texture_sampler_pairs[1].sampler_slot = 0; + desc.texture_sampler_pairs[1].glsl_name = "tex_shadow_smp_shadow"; + desc.texture_sampler_pairs[2].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[2].view_slot = 2; + desc.texture_sampler_pairs[2].sampler_slot = 1; + desc.texture_sampler_pairs[2].glsl_name = "tex_ibl_spec_smp_ibl_spec"; + desc.texture_sampler_pairs[3].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[3].view_slot = 3; + desc.texture_sampler_pairs[3].sampler_slot = 2; + desc.texture_sampler_pairs[3].glsl_name = "tex_brdf_lut_smp_brdf_lut"; + desc.label = "cube_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_D3D11) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)vs_source_hlsl5; + desc.vertex_func.d3d11_target = "vs_5_0"; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)fs_source_hlsl5; + desc.fragment_func.d3d11_target = "ps_5_0"; + desc.fragment_func.entry = "main"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[0].hlsl_sem_name = "TEXCOORD"; + desc.attrs[0].hlsl_sem_index = 0; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 288; + desc.uniform_blocks[0].hlsl_register_b_n = 0; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 496; + desc.uniform_blocks[1].hlsl_register_b_n = 1; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 16; + desc.uniform_blocks[2].hlsl_register_b_n = 2; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.hlsl_register_t_n = 0; + desc.views[1].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[1].texture.image_type = SG_IMAGETYPE_ARRAY; + desc.views[1].texture.sample_type = SG_IMAGESAMPLETYPE_DEPTH; + desc.views[1].texture.multisampled = false; + desc.views[1].texture.hlsl_register_t_n = 0; + desc.views[2].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[2].texture.image_type = SG_IMAGETYPE_CUBE; + desc.views[2].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[2].texture.multisampled = false; + desc.views[2].texture.hlsl_register_t_n = 1; + desc.views[3].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[3].texture.image_type = SG_IMAGETYPE_2D; + desc.views[3].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[3].texture.multisampled = false; + desc.views[3].texture.hlsl_register_t_n = 2; + desc.views[4].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[4].texture.image_type = SG_IMAGETYPE_2D; + desc.views[4].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[4].texture.multisampled = false; + desc.views[4].texture.hlsl_register_t_n = 3; + desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_COMPARISON; + desc.samplers[0].hlsl_register_s_n = 0; + desc.samplers[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[1].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[1].hlsl_register_s_n = 1; + desc.samplers[2].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[2].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[2].hlsl_register_s_n = 2; + desc.samplers[3].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[3].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[3].hlsl_register_s_n = 3; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[0].view_slot = 4; + desc.texture_sampler_pairs[0].sampler_slot = 3; + desc.texture_sampler_pairs[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[1].view_slot = 1; + desc.texture_sampler_pairs[1].sampler_slot = 0; + desc.texture_sampler_pairs[2].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[2].view_slot = 2; + desc.texture_sampler_pairs[2].sampler_slot = 1; + desc.texture_sampler_pairs[3].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[3].view_slot = 3; + desc.texture_sampler_pairs[3].sampler_slot = 2; + desc.label = "cube_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_METAL_MACOS) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)vs_source_metal_macos; + desc.vertex_func.entry = "main0"; + desc.fragment_func.source = (const char*)fs_source_metal_macos; + desc.fragment_func.entry = "main0"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 288; + desc.uniform_blocks[0].msl_buffer_n = 0; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 496; + desc.uniform_blocks[1].msl_buffer_n = 1; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 16; + desc.uniform_blocks[2].msl_buffer_n = 2; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.msl_buffer_n = 8; + desc.views[1].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[1].texture.image_type = SG_IMAGETYPE_ARRAY; + desc.views[1].texture.sample_type = SG_IMAGESAMPLETYPE_DEPTH; + desc.views[1].texture.multisampled = false; + desc.views[1].texture.msl_texture_n = 0; + desc.views[2].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[2].texture.image_type = SG_IMAGETYPE_CUBE; + desc.views[2].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[2].texture.multisampled = false; + desc.views[2].texture.msl_texture_n = 1; + desc.views[3].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[3].texture.image_type = SG_IMAGETYPE_2D; + desc.views[3].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[3].texture.multisampled = false; + desc.views[3].texture.msl_texture_n = 2; + desc.views[4].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[4].texture.image_type = SG_IMAGETYPE_2D; + desc.views[4].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[4].texture.multisampled = false; + desc.views[4].texture.msl_texture_n = 3; + desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_COMPARISON; + desc.samplers[0].msl_sampler_n = 0; + desc.samplers[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[1].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[1].msl_sampler_n = 1; + desc.samplers[2].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[2].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[2].msl_sampler_n = 2; + desc.samplers[3].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[3].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[3].msl_sampler_n = 3; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[0].view_slot = 4; + desc.texture_sampler_pairs[0].sampler_slot = 3; + desc.texture_sampler_pairs[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[1].view_slot = 1; + desc.texture_sampler_pairs[1].sampler_slot = 0; + desc.texture_sampler_pairs[2].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[2].view_slot = 2; + desc.texture_sampler_pairs[2].sampler_slot = 1; + desc.texture_sampler_pairs[3].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[3].view_slot = 3; + desc.texture_sampler_pairs[3].sampler_slot = 2; + desc.label = "cube_shader"; + } + return &desc; + } + return 0; +} diff --git a/samples/shaders/generated/depth_only_capsule.glsl.h b/samples/shaders/generated/depth_only_capsule.glsl.h new file mode 100644 index 0000000..e12b61b --- /dev/null +++ b/samples/shaders/generated/depth_only_capsule.glsl.h @@ -0,0 +1,1620 @@ +#pragma once +/* + #version:1# (machine generated, don't edit!) + + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) + + Cmdline: + sokol-shdc --input E:/box/box3d/samples/shaders/post/depth_only_capsule.glsl --output E:/box/box3d/samples/shaders/generated/depth_only_capsule.glsl.h --slang hlsl5:metal_macos:glsl430 + + Overview: + ========= + Shader program: 'prog': + Get shader desc: depth_only_capsule_prog_shader_desc(sg_query_backend()); + Vertex Shader: vs + Fragment Shader: fs + Attributes: + ATTR_depth_only_capsule_prog_in_pos => 0 + Bindings: + Uniform block 'ub_frame': + C struct: depth_only_capsule_ub_frame_t + Bind slot: UB_depth_only_capsule_ub_frame => 0 + Uniform block 'ub_pass': + C struct: depth_only_capsule_ub_pass_t + Bind slot: UB_depth_only_capsule_ub_pass => 1 + Storage buffer 'instances': + C struct: depth_only_capsule_instance_t + Bind slot: VIEW_depth_only_capsule_instances => 0 + Readonly: true +*/ +#if !defined(SOKOL_GFX_INCLUDED) +#error "Please include sokol_gfx.h before depth_only_capsule.glsl.h" +#endif +#if !defined(SOKOL_SHDC_ALIGN) +#if defined(_MSC_VER) +#define SOKOL_SHDC_ALIGN(a) __declspec(align(a)) +#else +#define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) +#endif +#endif +#define ATTR_depth_only_capsule_prog_in_pos (0) +#define UB_depth_only_capsule_ub_frame (0) +#define UB_depth_only_capsule_ub_pass (1) +#define VIEW_depth_only_capsule_instances (0) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct depth_only_capsule_ub_frame_t { + Mat4 view_proj; +} depth_only_capsule_ub_frame_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct depth_only_capsule_ub_pass_t { + Mat4 view_proj; + Mat4 view; + Vec4 camera_pos; +} depth_only_capsule_ub_pass_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct depth_only_capsule_instance_t { + Vec4 xform_row0; + Vec4 xform_row1; + Vec4 xform_row2; + Vec4 base_color; + Vec4 params; + Vec4 material; +} depth_only_capsule_instance_t; +#pragma pack(pop) +/* + #version 430 + + struct instance + { + vec4 xform_row0; + vec4 xform_row1; + vec4 xform_row2; + vec4 base_color; + vec4 params; + vec4 material; + }; + + layout(binding = 0, std430) readonly buffer instances + { + instance items[]; + } _15; + + uniform vec4 ub_frame[4]; + layout(location = 0) in vec3 in_pos; + layout(location = 0) sample out vec3 v_world_pos_proxy; + layout(location = 1) flat out vec3 v_center; + layout(location = 2) flat out float v_half_length; + layout(location = 3) flat out float v_radius; + layout(location = 4) flat out vec3 v_axis_x_world; + + void main() + { + vec3 _54 = vec3(_15.items[gl_InstanceID].xform_row0.w, _15.items[gl_InstanceID].xform_row1.w, _15.items[gl_InstanceID].xform_row2.w); + vec3 _86 = vec3((in_pos.x * 2.0) * (_15.items[gl_InstanceID].params.x + _15.items[gl_InstanceID].params.y), (in_pos.y * 2.0) * _15.items[gl_InstanceID].params.y, (in_pos.z * 2.0) * _15.items[gl_InstanceID].params.y); + vec3 _105 = _54 + vec3(dot(_15.items[gl_InstanceID].xform_row0.xyz, _86), dot(_15.items[gl_InstanceID].xform_row1.xyz, _86), dot(_15.items[gl_InstanceID].xform_row2.xyz, _86)); + v_world_pos_proxy = _105; + v_center = _54; + v_half_length = _15.items[gl_InstanceID].params.x; + v_radius = _15.items[gl_InstanceID].params.y; + v_axis_x_world = vec3(_15.items[gl_InstanceID].xform_row0.x, _15.items[gl_InstanceID].xform_row1.x, _15.items[gl_InstanceID].xform_row2.x); + gl_Position = mat4(ub_frame[0], ub_frame[1], ub_frame[2], ub_frame[3]) * vec4(_105, 1.0); + } + +*/ +static const uint8_t depth_only_capsule_vs_source_glsl430[1506] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72, + 0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x6d,0x61, + 0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f, + 0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x30,0x2c,0x20, + 0x73,0x74,0x64,0x34,0x33,0x30,0x29,0x20,0x72,0x65,0x61,0x64,0x6f,0x6e,0x6c,0x79, + 0x20,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x20,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5d,0x3b,0x0a,0x7d,0x20,0x5f,0x31,0x35,0x3b, + 0x0a,0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75, + 0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x34,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f, + 0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29, + 0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b, + 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x30,0x29,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x20,0x6f,0x75,0x74, + 0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f, + 0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28, + 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x66,0x6c, + 0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x63,0x65, + 0x6e,0x74,0x65,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63, + 0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x66,0x6c,0x61,0x74,0x20, + 0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66, + 0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28, + 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x33,0x29,0x20,0x66,0x6c, + 0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72, + 0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f, + 0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x34,0x29,0x20,0x66,0x6c,0x61,0x74, + 0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x61,0x78,0x69,0x73, + 0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20, + 0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x33,0x20,0x5f,0x35,0x34,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x31,0x35, + 0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x49,0x44,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30, + 0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x67,0x6c, + 0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69, + 0x74,0x65,0x6d,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x49,0x44,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x77, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x38,0x36,0x20, + 0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x2e,0x78, + 0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x20,0x2a,0x20,0x28,0x5f,0x31,0x35,0x2e,0x69, + 0x74,0x65,0x6d,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x49,0x44,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x20,0x2b,0x20,0x5f, + 0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79, + 0x29,0x2c,0x20,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x2e,0x79,0x20,0x2a,0x20,0x32, + 0x2e,0x30,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b, + 0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x70, + 0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x2c,0x20,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73, + 0x2e,0x7a,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x2e, + 0x69,0x74,0x65,0x6d,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x49,0x44,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x30,0x35,0x20,0x3d,0x20, + 0x5f,0x35,0x34,0x20,0x2b,0x20,0x76,0x65,0x63,0x33,0x28,0x64,0x6f,0x74,0x28,0x5f, + 0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f, + 0x77,0x30,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x38,0x36,0x29,0x2c,0x20,0x64,0x6f, + 0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x67,0x6c,0x5f,0x49, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d, + 0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x38,0x36,0x29,0x2c, + 0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x67, + 0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x38, + 0x36,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x5f,0x31,0x30, + 0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20, + 0x3d,0x20,0x5f,0x35,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x68,0x61,0x6c, + 0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69, + 0x74,0x65,0x6d,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x49,0x44,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x5f,0x31,0x35, + 0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x49,0x44,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74, + 0x65,0x6d,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49, + 0x44,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x78,0x2c, + 0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e, + 0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f, + 0x72,0x6f,0x77,0x31,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d, + 0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d, + 0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x78,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20, + 0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b, + 0x30,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x31,0x5d,0x2c, + 0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x32,0x5d,0x2c,0x20,0x75,0x62, + 0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x76,0x65,0x63, + 0x34,0x28,0x5f,0x31,0x30,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x00, +}; +/* + #version 430 + + uniform vec4 ub_pass[9]; + layout(location = 0) sample in vec3 v_world_pos_proxy; + layout(location = 4) flat in vec3 v_axis_x_world; + layout(location = 1) flat in vec3 v_center; + layout(location = 2) flat in float v_half_length; + layout(location = 3) flat in float v_radius; + layout(location = 0) out vec4 out_linear_depth; + + void main() + { + vec3 _27 = normalize(v_world_pos_proxy - ub_pass[8].xyz); + vec3 _38 = v_axis_x_world * v_half_length; + vec3 _39 = v_center - _38; + vec3 _45 = v_center + _38; + vec3 _49 = _45 - _39; + vec3 _53 = ub_pass[8].xyz - _39; + float _58 = dot(_49, _49); + float _62 = dot(_49, _27); + float _66 = dot(_49, _53); + float _74 = dot(_53, _53); + float _80 = _58 - (_62 * _62); + float _88 = (_58 * dot(_27, _53)) - (_66 * _62); + float _100 = v_radius * v_radius; + float _111 = (_88 * _88) - (_80 * (((_58 * _74) - (_66 * _66)) - (_100 * _58))); + float t = -1.0; + if ((_111 >= 0.0) && (_80 > 9.9999999392252902907785028219223e-09)) + { + float _131 = ((-_88) - sqrt(_111)) / _80; + float _137 = _66 + (_131 * _62); + if (((_131 > 0.0) && (_137 > 0.0)) && (_137 < _58)) + { + t = _131; + } + } + float _157 = dot(_53, _27); + float _171 = (_157 * _157) - (_74 - _100); + if (_171 >= 0.0) + { + float _181 = (-_157) - sqrt(_171); + bool _183 = _181 > 0.0; + bool _192; + if (_183) + { + _192 = (t < 0.0) || (_181 < t); + } + else + { + _192 = _183; + } + if (_192) + { + if (dot((ub_pass[8].xyz + (_27 * _181)) - _39, v_axis_x_world) <= 0.0) + { + t = _181; + } + } + } + vec3 _213 = ub_pass[8].xyz - _45; + float _217 = dot(_213, _27); + float _231 = (_217 * _217) - (dot(_213, _213) - _100); + if (_231 >= 0.0) + { + float _241 = (-_217) - sqrt(_231); + bool _243 = _241 > 0.0; + bool _252; + if (_243) + { + _252 = (t < 0.0) || (_241 < t); + } + else + { + _252 = _243; + } + if (_252) + { + if (dot((ub_pass[8].xyz + (_27 * _241)) - _45, v_axis_x_world) >= 0.0) + { + t = _241; + } + } + } + if (t < 0.0) + { + discard; + } + vec4 _291 = vec4(ub_pass[8].xyz + (_27 * t), 1.0); + vec4 _307 = mat4(ub_pass[0], ub_pass[1], ub_pass[2], ub_pass[3]) * _291; + gl_FragDepth = _307.z / _307.w; + out_linear_depth = vec4(-(mat4(ub_pass[4], ub_pass[5], ub_pass[6], ub_pass[7]) * _291).z, 0.0, 0.0, 0.0); + } + +*/ +static const uint8_t depth_only_capsule_fs_source_glsl430[2633] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x75,0x6e, + 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x70,0x61, + 0x73,0x73,0x5b,0x39,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f, + 0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x34,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20, + 0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a, + 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20, + 0x3d,0x20,0x31,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63, + 0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f, + 0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29, + 0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76, + 0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x33,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75, + 0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20, + 0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x6f,0x75,0x74,0x5f,0x6c,0x69,0x6e, + 0x65,0x61,0x72,0x5f,0x64,0x65,0x70,0x74,0x68,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64, + 0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x33,0x20,0x5f,0x32,0x37,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69, + 0x7a,0x65,0x28,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70, + 0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x38, + 0x5d,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, + 0x20,0x5f,0x33,0x38,0x20,0x3d,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x20,0x2a,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c, + 0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, + 0x5f,0x33,0x39,0x20,0x3d,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x2d, + 0x20,0x5f,0x33,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f, + 0x34,0x35,0x20,0x3d,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x2b,0x20, + 0x5f,0x33,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x34, + 0x39,0x20,0x3d,0x20,0x5f,0x34,0x35,0x20,0x2d,0x20,0x5f,0x33,0x39,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x35,0x33,0x20,0x3d,0x20,0x75,0x62, + 0x5f,0x70,0x61,0x73,0x73,0x5b,0x38,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f, + 0x33,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35, + 0x38,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x34,0x39,0x2c,0x20,0x5f,0x34,0x39, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x32, + 0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x34,0x39,0x2c,0x20,0x5f,0x32,0x37,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x36,0x20, + 0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x34,0x39,0x2c,0x20,0x5f,0x35,0x33,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x34,0x20,0x3d, + 0x20,0x64,0x6f,0x74,0x28,0x5f,0x35,0x33,0x2c,0x20,0x5f,0x35,0x33,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x30,0x20,0x3d,0x20, + 0x5f,0x35,0x38,0x20,0x2d,0x20,0x28,0x5f,0x36,0x32,0x20,0x2a,0x20,0x5f,0x36,0x32, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x38, + 0x20,0x3d,0x20,0x28,0x5f,0x35,0x38,0x20,0x2a,0x20,0x64,0x6f,0x74,0x28,0x5f,0x32, + 0x37,0x2c,0x20,0x5f,0x35,0x33,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f,0x36,0x36,0x20, + 0x2a,0x20,0x5f,0x36,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x31,0x30,0x30,0x20,0x3d,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75, + 0x73,0x20,0x2a,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x31,0x20,0x3d,0x20,0x28, + 0x5f,0x38,0x38,0x20,0x2a,0x20,0x5f,0x38,0x38,0x29,0x20,0x2d,0x20,0x28,0x5f,0x38, + 0x30,0x20,0x2a,0x20,0x28,0x28,0x28,0x5f,0x35,0x38,0x20,0x2a,0x20,0x5f,0x37,0x34, + 0x29,0x20,0x2d,0x20,0x28,0x5f,0x36,0x36,0x20,0x2a,0x20,0x5f,0x36,0x36,0x29,0x29, + 0x20,0x2d,0x20,0x28,0x5f,0x31,0x30,0x30,0x20,0x2a,0x20,0x5f,0x35,0x38,0x29,0x29, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x74,0x20,0x3d, + 0x20,0x2d,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28, + 0x5f,0x31,0x31,0x31,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x20,0x26,0x26,0x20, + 0x28,0x5f,0x38,0x30,0x20,0x3e,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39, + 0x33,0x39,0x32,0x32,0x35,0x32,0x39,0x30,0x32,0x39,0x30,0x37,0x37,0x38,0x35,0x30, + 0x32,0x38,0x32,0x31,0x39,0x32,0x32,0x33,0x65,0x2d,0x30,0x39,0x29,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x33,0x31,0x20,0x3d,0x20,0x28,0x28,0x2d,0x5f,0x38,0x38, + 0x29,0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x31,0x31,0x31,0x29,0x29,0x20, + 0x2f,0x20,0x5f,0x38,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x37,0x20,0x3d,0x20,0x5f,0x36,0x36,0x20, + 0x2b,0x20,0x28,0x5f,0x31,0x33,0x31,0x20,0x2a,0x20,0x5f,0x36,0x32,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x28,0x5f,0x31, + 0x33,0x31,0x20,0x3e,0x20,0x30,0x2e,0x30,0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x31, + 0x33,0x37,0x20,0x3e,0x20,0x30,0x2e,0x30,0x29,0x29,0x20,0x26,0x26,0x20,0x28,0x5f, + 0x31,0x33,0x37,0x20,0x3c,0x20,0x5f,0x35,0x38,0x29,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x74,0x20,0x3d,0x20,0x5f,0x31,0x33,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x37,0x20,0x3d,0x20,0x64,0x6f,0x74, + 0x28,0x5f,0x35,0x33,0x2c,0x20,0x5f,0x32,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x37,0x31,0x20,0x3d,0x20,0x28,0x5f,0x31, + 0x35,0x37,0x20,0x2a,0x20,0x5f,0x31,0x35,0x37,0x29,0x20,0x2d,0x20,0x28,0x5f,0x37, + 0x34,0x20,0x2d,0x20,0x5f,0x31,0x30,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x5f,0x31,0x37,0x31,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x31,0x38,0x31,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x31,0x35, + 0x37,0x29,0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x31,0x37,0x31,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31, + 0x38,0x33,0x20,0x3d,0x20,0x5f,0x31,0x38,0x31,0x20,0x3e,0x20,0x30,0x2e,0x30,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31, + 0x39,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x5f,0x31,0x38,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x39,0x32, + 0x20,0x3d,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x20,0x7c,0x7c,0x20, + 0x28,0x5f,0x31,0x38,0x31,0x20,0x3c,0x20,0x74,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c, + 0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x39,0x32,0x20,0x3d,0x20, + 0x5f,0x31,0x38,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x39,0x32, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x64,0x6f,0x74,0x28, + 0x28,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x38,0x5d,0x2e,0x78,0x79,0x7a,0x20, + 0x2b,0x20,0x28,0x5f,0x32,0x37,0x20,0x2a,0x20,0x5f,0x31,0x38,0x31,0x29,0x29,0x20, + 0x2d,0x20,0x5f,0x33,0x39,0x2c,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x29,0x20,0x3c,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d, + 0x20,0x5f,0x31,0x38,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x32, + 0x31,0x33,0x20,0x3d,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x38,0x5d,0x2e, + 0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x34,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x37,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28, + 0x5f,0x32,0x31,0x33,0x2c,0x20,0x5f,0x32,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x33,0x31,0x20,0x3d,0x20,0x28,0x5f,0x32, + 0x31,0x37,0x20,0x2a,0x20,0x5f,0x32,0x31,0x37,0x29,0x20,0x2d,0x20,0x28,0x64,0x6f, + 0x74,0x28,0x5f,0x32,0x31,0x33,0x2c,0x20,0x5f,0x32,0x31,0x33,0x29,0x20,0x2d,0x20, + 0x5f,0x31,0x30,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, + 0x32,0x33,0x31,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x32,0x34,0x31,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x32,0x31,0x37,0x29,0x20,0x2d, + 0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x32,0x33,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x32,0x34,0x33,0x20,0x3d, + 0x20,0x5f,0x32,0x34,0x31,0x20,0x3e,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x32,0x35,0x32,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x32,0x34,0x33, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x32,0x35,0x32,0x20,0x3d,0x20,0x28, + 0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x20,0x7c,0x7c,0x20,0x28,0x5f,0x32,0x34, + 0x31,0x20,0x3c,0x20,0x74,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x5f,0x32,0x35,0x32,0x20,0x3d,0x20,0x5f,0x32,0x34,0x33, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x32,0x35,0x32,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x64,0x6f,0x74,0x28,0x28,0x75,0x62,0x5f, + 0x70,0x61,0x73,0x73,0x5b,0x38,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f, + 0x32,0x37,0x20,0x2a,0x20,0x5f,0x32,0x34,0x31,0x29,0x29,0x20,0x2d,0x20,0x5f,0x34, + 0x35,0x2c,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x29,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20,0x5f,0x32,0x34, + 0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x64,0x69,0x73,0x63,0x61,0x72,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x32,0x39,0x31,0x20,0x3d,0x20,0x76, + 0x65,0x63,0x34,0x28,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x38,0x5d,0x2e,0x78, + 0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x32,0x37,0x20,0x2a,0x20,0x74,0x29,0x2c,0x20, + 0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f, + 0x33,0x30,0x37,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x75,0x62,0x5f,0x70,0x61, + 0x73,0x73,0x5b,0x30,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x31, + 0x5d,0x2c,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x32,0x5d,0x2c,0x20,0x75, + 0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x5f,0x32,0x39, + 0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65, + 0x70,0x74,0x68,0x20,0x3d,0x20,0x5f,0x33,0x30,0x37,0x2e,0x7a,0x20,0x2f,0x20,0x5f, + 0x33,0x30,0x37,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x6c, + 0x69,0x6e,0x65,0x61,0x72,0x5f,0x64,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x76,0x65, + 0x63,0x34,0x28,0x2d,0x28,0x6d,0x61,0x74,0x34,0x28,0x75,0x62,0x5f,0x70,0x61,0x73, + 0x73,0x5b,0x34,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x35,0x5d, + 0x2c,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x36,0x5d,0x2c,0x20,0x75,0x62, + 0x5f,0x70,0x61,0x73,0x73,0x5b,0x37,0x5d,0x29,0x20,0x2a,0x20,0x5f,0x32,0x39,0x31, + 0x29,0x2e,0x7a,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30, + 0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + struct instance + { + float4 xform_row0; + float4 xform_row1; + float4 xform_row2; + float4 base_color; + float4 params; + float4 material; + }; + + ByteAddressBuffer _15 : register(t0); + cbuffer ub_frame : register(b0) + { + row_major float4x4 _131_view_proj : packoffset(c0); + }; + + + static float4 gl_Position; + static int gl_InstanceIndex; + static float3 in_pos; + static float3 v_world_pos_proxy; + static float3 v_center; + static float v_half_length; + static float v_radius; + static float3 v_axis_x_world; + + struct SPIRV_Cross_Input + { + float3 in_pos : TEXCOORD0; + uint gl_InstanceIndex : SV_InstanceID; + }; + + struct SPIRV_Cross_Output + { + sample float3 v_world_pos_proxy : TEXCOORD0; + nointerpolation float3 v_center : TEXCOORD1; + nointerpolation float v_half_length : TEXCOORD2; + nointerpolation float v_radius : TEXCOORD3; + nointerpolation float3 v_axis_x_world : TEXCOORD4; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + instance _23; + _23.xform_row0 = asfloat(_15.Load4(gl_InstanceIndex * 96 + 0)); + _23.xform_row1 = asfloat(_15.Load4(gl_InstanceIndex * 96 + 16)); + _23.xform_row2 = asfloat(_15.Load4(gl_InstanceIndex * 96 + 32)); + _23.base_color = asfloat(_15.Load4(gl_InstanceIndex * 96 + 48)); + _23.params = asfloat(_15.Load4(gl_InstanceIndex * 96 + 64)); + _23.material = asfloat(_15.Load4(gl_InstanceIndex * 96 + 80)); + float3 _54 = float3(_23.xform_row0.w, _23.xform_row1.w, _23.xform_row2.w); + float3 _86 = float3((in_pos.x * 2.0f) * (_23.params.x + _23.params.y), (in_pos.y * 2.0f) * _23.params.y, (in_pos.z * 2.0f) * _23.params.y); + float3 _105 = _54 + float3(dot(_23.xform_row0.xyz, _86), dot(_23.xform_row1.xyz, _86), dot(_23.xform_row2.xyz, _86)); + v_world_pos_proxy = _105; + v_center = _54; + v_half_length = _23.params.x; + v_radius = _23.params.y; + v_axis_x_world = float3(_23.xform_row0.x, _23.xform_row1.x, _23.xform_row2.x); + gl_Position = mul(float4(_105, 1.0f), _131_view_proj); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_InstanceIndex = int(stage_input.gl_InstanceIndex); + in_pos = stage_input.in_pos; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.v_world_pos_proxy = v_world_pos_proxy; + stage_output.v_center = v_center; + stage_output.v_half_length = v_half_length; + stage_output.v_radius = v_radius; + stage_output.v_axis_x_world = v_axis_x_world; + return stage_output; + } +*/ +static const uint8_t depth_only_capsule_vs_source_hlsl5[2484] = { + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d, + 0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x73,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6d,0x61,0x74,0x65, + 0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x42,0x79,0x74,0x65,0x41,0x64, + 0x64,0x72,0x65,0x73,0x73,0x42,0x75,0x66,0x66,0x65,0x72,0x20,0x5f,0x31,0x35,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x30,0x29,0x3b,0x0a, + 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65, + 0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x31,0x33,0x31,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66, + 0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x0a,0x73, + 0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f, + 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63, + 0x20,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x49,0x6e,0x64,0x65,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x73,0x74,0x61, + 0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x73,0x74, + 0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65, + 0x6e,0x74,0x65,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68, + 0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76, + 0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53, + 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e, + 0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e, + 0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x3a,0x20,0x53,0x56, + 0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x3b,0x0a,0x7d,0x3b,0x0a, + 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, + 0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79, + 0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f, + 0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65, + 0x72,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69, + 0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f, + 0x6c,0x65,0x6e,0x67,0x74,0x68,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52, + 0x44,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70, + 0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f, + 0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52, + 0x44,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70, + 0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76, + 0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3a,0x20, + 0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f, + 0x6e,0x20,0x3a,0x20,0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b, + 0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d, + 0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x20,0x5f,0x32,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x32, + 0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x20,0x3d,0x20,0x61, + 0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34, + 0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65, + 0x78,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x5f,0x32,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31, + 0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c, + 0x6f,0x61,0x64,0x34,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x49,0x6e,0x64,0x65,0x78,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x31,0x36,0x29, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x32,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d, + 0x5f,0x72,0x6f,0x77,0x32,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28, + 0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73, + 0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x2a,0x20,0x39,0x36,0x20, + 0x2b,0x20,0x33,0x32,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x32,0x33,0x2e, + 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x61,0x73,0x66, + 0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x67, + 0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20, + 0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x34,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x5f,0x32,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x20,0x3d,0x20,0x61,0x73, + 0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28, + 0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78, + 0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x36,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x5f,0x32,0x33,0x2e,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3d, + 0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61, + 0x64,0x34,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e, + 0x64,0x65,0x78,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x38,0x30,0x29,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x35,0x34,0x20, + 0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x32,0x33,0x2e,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f,0x32,0x33,0x2e,0x78, + 0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f,0x32,0x33, + 0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x77,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x38,0x36,0x20,0x3d, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x2e, + 0x78,0x20,0x2a,0x20,0x32,0x2e,0x30,0x66,0x29,0x20,0x2a,0x20,0x28,0x5f,0x32,0x33, + 0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x20,0x2b,0x20,0x5f,0x32,0x33,0x2e, + 0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x29,0x2c,0x20,0x28,0x69,0x6e,0x5f,0x70, + 0x6f,0x73,0x2e,0x79,0x20,0x2a,0x20,0x32,0x2e,0x30,0x66,0x29,0x20,0x2a,0x20,0x5f, + 0x32,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x2c,0x20,0x28,0x69,0x6e, + 0x5f,0x70,0x6f,0x73,0x2e,0x7a,0x20,0x2a,0x20,0x32,0x2e,0x30,0x66,0x29,0x20,0x2a, + 0x20,0x5f,0x32,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x30,0x35,0x20, + 0x3d,0x20,0x5f,0x35,0x34,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x64, + 0x6f,0x74,0x28,0x5f,0x32,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77, + 0x30,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x38,0x36,0x29,0x2c,0x20,0x64,0x6f,0x74, + 0x28,0x5f,0x32,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e, + 0x78,0x79,0x7a,0x2c,0x20,0x5f,0x38,0x36,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f, + 0x32,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x78,0x79, + 0x7a,0x2c,0x20,0x5f,0x38,0x36,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20, + 0x3d,0x20,0x5f,0x31,0x30,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x63,0x65, + 0x6e,0x74,0x65,0x72,0x20,0x3d,0x20,0x5f,0x35,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x20,0x3d,0x20, + 0x5f,0x32,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x5f,0x32,0x33, + 0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x32,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d, + 0x5f,0x72,0x6f,0x77,0x30,0x2e,0x78,0x2c,0x20,0x5f,0x32,0x33,0x2e,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x2c,0x20,0x5f,0x32,0x33,0x2e,0x78, + 0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x78,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x30,0x35,0x2c, + 0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f,0x31,0x33,0x31,0x5f,0x76,0x69,0x65, + 0x77,0x5f,0x70,0x72,0x6f,0x6a,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52, + 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d, + 0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, + 0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75, + 0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x3d,0x20,0x69,0x6e,0x74,0x28, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x49, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x3d,0x20,0x73,0x74,0x61,0x67, + 0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73, + 0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75, + 0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f, + 0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69, + 0x6f,0x6e,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70, + 0x75,0x74,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70, + 0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70, + 0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74, + 0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x63,0x65,0x6e, + 0x74,0x65,0x72,0x20,0x3d,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74, + 0x2e,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x20,0x3d, + 0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74, + 0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x76,0x5f,0x72,0x61, + 0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f, + 0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b, + 0x0a,0x7d,0x0a,0x00, +}; +/* + cbuffer ub_pass : register(b1) + { + row_major float4x4 _14_view_proj : packoffset(c0); + row_major float4x4 _14_view : packoffset(c4); + float4 _14_camera_pos : packoffset(c8); + }; + + + static float gl_FragDepth; + static float3 v_world_pos_proxy; + static float3 v_axis_x_world; + static float3 v_center; + static float v_half_length; + static float v_radius; + static float4 out_linear_depth; + + struct SPIRV_Cross_Input + { + sample float3 v_world_pos_proxy : TEXCOORD0; + nointerpolation float3 v_center : TEXCOORD1; + nointerpolation float v_half_length : TEXCOORD2; + nointerpolation float v_radius : TEXCOORD3; + nointerpolation float3 v_axis_x_world : TEXCOORD4; + }; + + struct SPIRV_Cross_Output + { + float4 out_linear_depth : SV_Target0; + float gl_FragDepth : SV_Depth; + }; + + void frag_main() + { + float3 _27 = normalize(v_world_pos_proxy - _14_camera_pos.xyz); + float3 _38 = v_axis_x_world * v_half_length; + float3 _39 = v_center - _38; + float3 _45 = v_center + _38; + float3 _49 = _45 - _39; + float3 _53 = _14_camera_pos.xyz - _39; + float _58 = dot(_49, _49); + float _62 = dot(_49, _27); + float _66 = dot(_49, _53); + float _74 = dot(_53, _53); + float _80 = _58 - (_62 * _62); + float _88 = (_58 * dot(_27, _53)) - (_66 * _62); + float _100 = v_radius * v_radius; + float _111 = (_88 * _88) - (_80 * (((_58 * _74) - (_66 * _66)) - (_100 * _58))); + float t = -1.0f; + if ((_111 >= 0.0f) && (_80 > 9.9999999392252902907785028219223e-09f)) + { + float _131 = ((-_88) - sqrt(_111)) / _80; + float _137 = _66 + (_131 * _62); + if (((_131 > 0.0f) && (_137 > 0.0f)) && (_137 < _58)) + { + t = _131; + } + } + float _157 = dot(_53, _27); + float _171 = (_157 * _157) - (_74 - _100); + if (_171 >= 0.0f) + { + float _181 = (-_157) - sqrt(_171); + bool _183 = _181 > 0.0f; + bool _192; + if (_183) + { + _192 = (t < 0.0f) || (_181 < t); + } + else + { + _192 = _183; + } + if (_192) + { + if (dot((_14_camera_pos.xyz + (_27 * _181)) - _39, v_axis_x_world) <= 0.0f) + { + t = _181; + } + } + } + float3 _213 = _14_camera_pos.xyz - _45; + float _217 = dot(_213, _27); + float _231 = (_217 * _217) - (dot(_213, _213) - _100); + if (_231 >= 0.0f) + { + float _241 = (-_217) - sqrt(_231); + bool _243 = _241 > 0.0f; + bool _252; + if (_243) + { + _252 = (t < 0.0f) || (_241 < t); + } + else + { + _252 = _243; + } + if (_252) + { + if (dot((_14_camera_pos.xyz + (_27 * _241)) - _45, v_axis_x_world) >= 0.0f) + { + t = _241; + } + } + } + if (t < 0.0f) + { + discard; + } + float4 _291 = float4(_14_camera_pos.xyz + (_27 * t), 1.0f); + float4 _307 = mul(_291, _14_view_proj); + gl_FragDepth = _307.z / _307.w; + out_linear_depth = float4(-mul(_291, _14_view).z, 0.0f, 0.0f, 0.0f); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + v_world_pos_proxy = stage_input.v_world_pos_proxy; + v_axis_x_world = stage_input.v_axis_x_world; + v_center = stage_input.v_center; + v_half_length = stage_input.v_half_length; + v_radius = stage_input.v_radius; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_FragDepth = gl_FragDepth; + stage_output.out_linear_depth = out_linear_depth; + return stage_output; + } +*/ +static const uint8_t depth_only_capsule_fs_source_hlsl5[3535] = { + 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x31,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x31,0x34,0x5f,0x76,0x69,0x65,0x77, + 0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73, + 0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f, + 0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f, + 0x31,0x34,0x5f,0x76,0x69,0x65,0x77,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66, + 0x66,0x73,0x65,0x74,0x28,0x63,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x34,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f, + 0x70,0x6f,0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74, + 0x28,0x63,0x38,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69, + 0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44, + 0x65,0x70,0x74,0x68,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f, + 0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x73,0x74,0x61, + 0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66, + 0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a, + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75, + 0x74,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x64,0x65,0x70,0x74,0x68,0x3b,0x0a, + 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, + 0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20, + 0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72, + 0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f, + 0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c, + 0x65,0x6e,0x67,0x74,0x68,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44, + 0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f, + 0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72, + 0x61,0x64,0x69,0x75,0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44, + 0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f, + 0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f, + 0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3a,0x20,0x54, + 0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x34,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73, + 0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f, + 0x64,0x65,0x70,0x74,0x68,0x20,0x3a,0x20,0x53,0x56,0x5f,0x54,0x61,0x72,0x67,0x65, + 0x74,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c, + 0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3a,0x20,0x53,0x56,0x5f, + 0x44,0x65,0x70,0x74,0x68,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20, + 0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x32,0x37,0x20,0x3d,0x20,0x6e, + 0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x5f,0x31,0x34, + 0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x33,0x38, + 0x20,0x3d,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x20,0x2a,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74, + 0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x33, + 0x39,0x20,0x3d,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x2d,0x20,0x5f, + 0x33,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f, + 0x34,0x35,0x20,0x3d,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x2b,0x20, + 0x5f,0x33,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x5f,0x34,0x39,0x20,0x3d,0x20,0x5f,0x34,0x35,0x20,0x2d,0x20,0x5f,0x33,0x39,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x35,0x33,0x20, + 0x3d,0x20,0x5f,0x31,0x34,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73, + 0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x33,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x38,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28, + 0x5f,0x34,0x39,0x2c,0x20,0x5f,0x34,0x39,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x32,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f, + 0x34,0x39,0x2c,0x20,0x5f,0x32,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x36,0x36,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x34, + 0x39,0x2c,0x20,0x5f,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x37,0x34,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x35,0x33, + 0x2c,0x20,0x5f,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x38,0x30,0x20,0x3d,0x20,0x5f,0x35,0x38,0x20,0x2d,0x20,0x28,0x5f, + 0x36,0x32,0x20,0x2a,0x20,0x5f,0x36,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x38,0x20,0x3d,0x20,0x28,0x5f,0x35,0x38,0x20, + 0x2a,0x20,0x64,0x6f,0x74,0x28,0x5f,0x32,0x37,0x2c,0x20,0x5f,0x35,0x33,0x29,0x29, + 0x20,0x2d,0x20,0x28,0x5f,0x36,0x36,0x20,0x2a,0x20,0x5f,0x36,0x32,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x30,0x20,0x3d, + 0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x2a,0x20,0x76,0x5f,0x72,0x61, + 0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x31,0x31,0x20,0x3d,0x20,0x28,0x5f,0x38,0x38,0x20,0x2a,0x20,0x5f,0x38, + 0x38,0x29,0x20,0x2d,0x20,0x28,0x5f,0x38,0x30,0x20,0x2a,0x20,0x28,0x28,0x28,0x5f, + 0x35,0x38,0x20,0x2a,0x20,0x5f,0x37,0x34,0x29,0x20,0x2d,0x20,0x28,0x5f,0x36,0x36, + 0x20,0x2a,0x20,0x5f,0x36,0x36,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f,0x31,0x30,0x30, + 0x20,0x2a,0x20,0x5f,0x35,0x38,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x74,0x20,0x3d,0x20,0x2d,0x31,0x2e,0x30,0x66,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x5f,0x31,0x31,0x31,0x20,0x3e,0x3d, + 0x20,0x30,0x2e,0x30,0x66,0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x38,0x30,0x20,0x3e, + 0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x33,0x39,0x32,0x32,0x35,0x32, + 0x39,0x30,0x32,0x39,0x30,0x37,0x37,0x38,0x35,0x30,0x32,0x38,0x32,0x31,0x39,0x32, + 0x32,0x33,0x65,0x2d,0x30,0x39,0x66,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x33,0x31,0x20,0x3d,0x20,0x28,0x28,0x2d,0x5f,0x38,0x38,0x29,0x20,0x2d,0x20,0x73, + 0x71,0x72,0x74,0x28,0x5f,0x31,0x31,0x31,0x29,0x29,0x20,0x2f,0x20,0x5f,0x38,0x30, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x33,0x37,0x20,0x3d,0x20,0x5f,0x36,0x36,0x20,0x2b,0x20,0x28,0x5f,0x31, + 0x33,0x31,0x20,0x2a,0x20,0x5f,0x36,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x28,0x5f,0x31,0x33,0x31,0x20,0x3e,0x20, + 0x30,0x2e,0x30,0x66,0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x31,0x33,0x37,0x20,0x3e, + 0x20,0x30,0x2e,0x30,0x66,0x29,0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x31,0x33,0x37, + 0x20,0x3c,0x20,0x5f,0x35,0x38,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74, + 0x20,0x3d,0x20,0x5f,0x31,0x33,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x35,0x37,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x35, + 0x33,0x2c,0x20,0x5f,0x32,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x37,0x31,0x20,0x3d,0x20,0x28,0x5f,0x31,0x35,0x37,0x20, + 0x2a,0x20,0x5f,0x31,0x35,0x37,0x29,0x20,0x2d,0x20,0x28,0x5f,0x37,0x34,0x20,0x2d, + 0x20,0x5f,0x31,0x30,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x5f,0x31,0x37,0x31,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x66,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x31,0x38,0x31,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x31,0x35,0x37,0x29, + 0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x31,0x37,0x31,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x38,0x33, + 0x20,0x3d,0x20,0x5f,0x31,0x38,0x31,0x20,0x3e,0x20,0x30,0x2e,0x30,0x66,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x39, + 0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, + 0x31,0x38,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x39,0x32,0x20, + 0x3d,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x29,0x20,0x7c,0x7c,0x20, + 0x28,0x5f,0x31,0x38,0x31,0x20,0x3c,0x20,0x74,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c, + 0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x39,0x32,0x20,0x3d,0x20, + 0x5f,0x31,0x38,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x39,0x32, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x64,0x6f,0x74,0x28, + 0x28,0x5f,0x31,0x34,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e, + 0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x32,0x37,0x20,0x2a,0x20,0x5f,0x31,0x38, + 0x31,0x29,0x29,0x20,0x2d,0x20,0x5f,0x33,0x39,0x2c,0x20,0x76,0x5f,0x61,0x78,0x69, + 0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x20,0x3c,0x3d,0x20,0x30,0x2e, + 0x30,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x74,0x20,0x3d,0x20,0x5f,0x31,0x38,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x5f,0x32,0x31,0x33,0x20,0x3d,0x20,0x5f,0x31,0x34,0x5f, + 0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d, + 0x20,0x5f,0x34,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x32,0x31,0x37,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x32,0x31,0x33,0x2c, + 0x20,0x5f,0x32,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x32,0x33,0x31,0x20,0x3d,0x20,0x28,0x5f,0x32,0x31,0x37,0x20,0x2a,0x20, + 0x5f,0x32,0x31,0x37,0x29,0x20,0x2d,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x32,0x31, + 0x33,0x2c,0x20,0x5f,0x32,0x31,0x33,0x29,0x20,0x2d,0x20,0x5f,0x31,0x30,0x30,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x32,0x33,0x31,0x20,0x3e, + 0x3d,0x20,0x30,0x2e,0x30,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x34,0x31, + 0x20,0x3d,0x20,0x28,0x2d,0x5f,0x32,0x31,0x37,0x29,0x20,0x2d,0x20,0x73,0x71,0x72, + 0x74,0x28,0x5f,0x32,0x33,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x32,0x34,0x33,0x20,0x3d,0x20,0x5f,0x32,0x34, + 0x31,0x20,0x3e,0x20,0x30,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x32,0x35,0x32,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x32,0x34,0x33,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x5f,0x32,0x35,0x32,0x20,0x3d,0x20,0x28,0x74,0x20,0x3c, + 0x20,0x30,0x2e,0x30,0x66,0x29,0x20,0x7c,0x7c,0x20,0x28,0x5f,0x32,0x34,0x31,0x20, + 0x3c,0x20,0x74,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x5f,0x32,0x35,0x32,0x20,0x3d,0x20,0x5f,0x32,0x34,0x33,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x32,0x35,0x32,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x64,0x6f,0x74,0x28,0x28,0x5f,0x31,0x34,0x5f,0x63, + 0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20, + 0x28,0x5f,0x32,0x37,0x20,0x2a,0x20,0x5f,0x32,0x34,0x31,0x29,0x29,0x20,0x2d,0x20, + 0x5f,0x34,0x35,0x2c,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x29,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x66,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20, + 0x5f,0x32,0x34,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x74,0x20,0x3c,0x20, + 0x30,0x2e,0x30,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x32, + 0x39,0x31,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x34,0x5f, + 0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b, + 0x20,0x28,0x5f,0x32,0x37,0x20,0x2a,0x20,0x74,0x29,0x2c,0x20,0x31,0x2e,0x30,0x66, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x33, + 0x30,0x37,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x5f,0x32,0x39,0x31,0x2c,0x20,0x5f, + 0x31,0x34,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20, + 0x3d,0x20,0x5f,0x33,0x30,0x37,0x2e,0x7a,0x20,0x2f,0x20,0x5f,0x33,0x30,0x37,0x2e, + 0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x6c,0x69,0x6e,0x65,0x61, + 0x72,0x5f,0x64,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x28,0x2d,0x6d,0x75,0x6c,0x28,0x5f,0x32,0x39,0x31,0x2c,0x20,0x5f,0x31,0x34,0x5f, + 0x76,0x69,0x65,0x77,0x29,0x2e,0x7a,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x30, + 0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53, + 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75, + 0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, + 0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69, + 0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3d,0x20, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e, + 0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3d,0x20,0x73, + 0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x63,0x65,0x6e, + 0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f, + 0x6c,0x65,0x6e,0x67,0x74,0x68,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69, + 0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67, + 0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73, + 0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76, + 0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61, + 0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50, + 0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74, + 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e, + 0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x67, + 0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x6f,0x75, + 0x74,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x64,0x65,0x70,0x74,0x68,0x20,0x3d, + 0x20,0x6f,0x75,0x74,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x64,0x65,0x70,0x74, + 0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74, + 0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + struct instance + { + float4 xform_row0; + float4 xform_row1; + float4 xform_row2; + float4 base_color; + float4 params; + float4 material; + }; + + struct instances + { + instance items[1]; + }; + + struct ub_frame + { + float4x4 view_proj; + }; + + struct main0_out + { + float3 v_world_pos_proxy [[user(locn0)]]; + float3 v_center [[user(locn1)]]; + float v_half_length [[user(locn2)]]; + float v_radius [[user(locn3)]]; + float3 v_axis_x_world [[user(locn4)]]; + float4 gl_Position [[position]]; + }; + + struct main0_in + { + float3 in_pos [[attribute(0)]]; + }; + + vertex main0_out main0(main0_in in [[stage_in]], constant ub_frame& _131 [[buffer(0)]], const device instances& _15 [[buffer(8)]], uint gl_InstanceIndex [[instance_id]]) + { + main0_out out = {}; + float3 _54 = float3(_15.items[int(gl_InstanceIndex)].xform_row0.w, _15.items[int(gl_InstanceIndex)].xform_row1.w, _15.items[int(gl_InstanceIndex)].xform_row2.w); + float3 _86 = float3((in.in_pos.x * 2.0) * (_15.items[int(gl_InstanceIndex)].params.x + _15.items[int(gl_InstanceIndex)].params.y), (in.in_pos.y * 2.0) * _15.items[int(gl_InstanceIndex)].params.y, (in.in_pos.z * 2.0) * _15.items[int(gl_InstanceIndex)].params.y); + float3 _105 = _54 + float3(dot(_15.items[int(gl_InstanceIndex)].xform_row0.xyz, _86), dot(_15.items[int(gl_InstanceIndex)].xform_row1.xyz, _86), dot(_15.items[int(gl_InstanceIndex)].xform_row2.xyz, _86)); + out.v_world_pos_proxy = _105; + out.v_center = _54; + out.v_half_length = _15.items[int(gl_InstanceIndex)].params.x; + out.v_radius = _15.items[int(gl_InstanceIndex)].params.y; + out.v_axis_x_world = float3(_15.items[int(gl_InstanceIndex)].xform_row0.x, _15.items[int(gl_InstanceIndex)].xform_row1.x, _15.items[int(gl_InstanceIndex)].xform_row2.x); + out.gl_Position = _131.view_proj * float4(_105, 1.0); + return out; + } + +*/ +static const uint8_t depth_only_capsule_vs_source_metal_macos[1915] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x20,0x69,0x74,0x65,0x6d,0x73,0x5b,0x31,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a, + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x76, + 0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x5b,0x5b, + 0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74, + 0x65,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29, + 0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f, + 0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x20,0x5b,0x5b,0x75,0x73, + 0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x32,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20, + 0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x33,0x29,0x5d,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x61,0x78, + 0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x5b,0x5b,0x75,0x73,0x65, + 0x72,0x28,0x6c,0x6f,0x63,0x6e,0x34,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69, + 0x6f,0x6e,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x3b, + 0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e, + 0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x5b,0x5b,0x61,0x74,0x74,0x72,0x69, + 0x62,0x75,0x74,0x65,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76, + 0x65,0x72,0x74,0x65,0x78,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20, + 0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69, + 0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20, + 0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d, + 0x65,0x26,0x20,0x5f,0x31,0x33,0x31,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72, + 0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x64,0x65,0x76, + 0x69,0x63,0x65,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x26,0x20,0x5f, + 0x31,0x35,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x38,0x29,0x5d,0x5d, + 0x2c,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x5b,0x5b,0x69,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x5f,0x69,0x64,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d, + 0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b, + 0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x35, + 0x34,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x31,0x35,0x2e,0x69, + 0x74,0x65,0x6d,0x73,0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74, + 0x65,0x6d,0x73,0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61, + 0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d, + 0x5f,0x72,0x6f,0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65, + 0x6d,0x73,0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f, + 0x72,0x6f,0x77,0x32,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x5f,0x38,0x36,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x28,0x28,0x69,0x6e,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x20,0x2a,0x20, + 0x32,0x2e,0x30,0x29,0x20,0x2a,0x20,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d, + 0x73,0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e, + 0x78,0x20,0x2b,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x69,0x6e, + 0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64, + 0x65,0x78,0x29,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x29,0x2c,0x20, + 0x28,0x69,0x6e,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x2e,0x79,0x20,0x2a,0x20,0x32, + 0x2e,0x30,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b, + 0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49, + 0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x2c, + 0x20,0x28,0x69,0x6e,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x2e,0x7a,0x20,0x2a,0x20, + 0x32,0x2e,0x30,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73, + 0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x49,0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31, + 0x30,0x35,0x20,0x3d,0x20,0x5f,0x35,0x34,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b, + 0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49, + 0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77, + 0x30,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x38,0x36,0x29,0x2c,0x20,0x64,0x6f,0x74, + 0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x69,0x6e,0x74,0x28,0x67, + 0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29, + 0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x79,0x7a, + 0x2c,0x20,0x5f,0x38,0x36,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e, + 0x69,0x74,0x65,0x6d,0x73,0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73, + 0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x38,0x36, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3d,0x20, + 0x5f,0x31,0x30,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f, + 0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3d,0x20,0x5f,0x35,0x34,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e, + 0x67,0x74,0x68,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b, + 0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49, + 0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75, + 0x73,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x69,0x6e, + 0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64, + 0x65,0x78,0x29,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f, + 0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f, + 0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e, + 0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x78,0x2c,0x20,0x5f,0x31, + 0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x78, + 0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x35, + 0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e, + 0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x5f,0x31,0x33,0x31,0x2e,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f, + 0x6a,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x30,0x35,0x2c, + 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + struct ub_pass + { + float4x4 view_proj; + float4x4 view; + float4 camera_pos; + }; + + struct main0_out + { + float4 out_linear_depth [[color(0)]]; + float gl_FragDepth [[depth(any)]]; + }; + + struct main0_in + { + float3 v_world_pos_proxy [[user(locn0), sample_perspective]]; + float3 v_center [[user(locn1), flat]]; + float v_half_length [[user(locn2), flat]]; + float v_radius [[user(locn3), flat]]; + float3 v_axis_x_world [[user(locn4), flat]]; + }; + + fragment main0_out main0(main0_in in [[stage_in]], constant ub_pass& _14 [[buffer(1)]]) + { + main0_out out = {}; + float3 _27 = fast::normalize(in.v_world_pos_proxy - _14.camera_pos.xyz); + float3 _38 = in.v_axis_x_world * in.v_half_length; + float3 _39 = in.v_center - _38; + float3 _45 = in.v_center + _38; + float3 _49 = _45 - _39; + float3 _53 = _14.camera_pos.xyz - _39; + float _58 = dot(_49, _49); + float _62 = dot(_49, _27); + float _66 = dot(_49, _53); + float _74 = dot(_53, _53); + float _80 = _58 - (_62 * _62); + float _88 = (_58 * dot(_27, _53)) - (_66 * _62); + float _100 = in.v_radius * in.v_radius; + float _111 = (_88 * _88) - (_80 * (((_58 * _74) - (_66 * _66)) - (_100 * _58))); + float t = -1.0; + if ((_111 >= 0.0) && (_80 > 9.9999999392252902907785028219223e-09)) + { + float _131 = ((-_88) - sqrt(_111)) / _80; + float _137 = _66 + (_131 * _62); + if (((_131 > 0.0) && (_137 > 0.0)) && (_137 < _58)) + { + t = _131; + } + } + float _157 = dot(_53, _27); + float _171 = (_157 * _157) - (_74 - _100); + if (_171 >= 0.0) + { + float _181 = (-_157) - sqrt(_171); + bool _183 = _181 > 0.0; + bool _192; + if (_183) + { + _192 = (t < 0.0) || (_181 < t); + } + else + { + _192 = _183; + } + if (_192) + { + if (dot((_14.camera_pos.xyz + (_27 * _181)) - _39, in.v_axis_x_world) <= 0.0) + { + t = _181; + } + } + } + float3 _213 = _14.camera_pos.xyz - _45; + float _217 = dot(_213, _27); + float _231 = (_217 * _217) - (dot(_213, _213) - _100); + if (_231 >= 0.0) + { + float _241 = (-_217) - sqrt(_231); + bool _243 = _241 > 0.0; + bool _252; + if (_243) + { + _252 = (t < 0.0) || (_241 < t); + } + else + { + _252 = _243; + } + if (_252) + { + if (dot((_14.camera_pos.xyz + (_27 * _241)) - _45, in.v_axis_x_world) >= 0.0) + { + t = _241; + } + } + } + if (t < 0.0) + { + discard_fragment(); + } + float4 _291 = float4(_14.camera_pos.xyz + (_27 * t), 1.0); + float4 _307 = _14.view_proj * _291; + out.gl_FragDepth = _307.z / _307.w; + out.out_linear_depth = float4(-(_14.view * _291).z, 0.0, 0.0, 0.0); + return out; + } + +*/ +static const uint8_t depth_only_capsule_fs_source_metal_macos[2964] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75, + 0x62,0x5f,0x70,0x61,0x73,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x78,0x34,0x20,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x76,0x69, + 0x65,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63, + 0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73, + 0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74, + 0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x64,0x65,0x70,0x74,0x68,0x20,0x5b,0x5b, + 0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70, + 0x74,0x68,0x20,0x5b,0x5b,0x64,0x65,0x70,0x74,0x68,0x28,0x61,0x6e,0x79,0x29,0x5d, + 0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61, + 0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f, + 0x70,0x72,0x6f,0x78,0x79,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63, + 0x6e,0x30,0x29,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x70,0x65,0x72,0x73, + 0x70,0x65,0x63,0x74,0x69,0x76,0x65,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x5b, + 0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29,0x2c,0x20,0x66,0x6c, + 0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x20,0x5b,0x5b, + 0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x32,0x29,0x2c,0x20,0x66,0x6c,0x61, + 0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76, + 0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c, + 0x6f,0x63,0x6e,0x33,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x61,0x78,0x69,0x73, + 0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28, + 0x6c,0x6f,0x63,0x6e,0x34,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a, + 0x7d,0x3b,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x20,0x6d,0x61,0x69, + 0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69, + 0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65, + 0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20, + 0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x31,0x34,0x20,0x5b,0x5b,0x62, + 0x75,0x66,0x66,0x65,0x72,0x28,0x31,0x29,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20, + 0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x5f,0x32,0x37,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72, + 0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x5f,0x31, + 0x34,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x33, + 0x38,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x20,0x2a,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x68,0x61,0x6c, + 0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x5f,0x33,0x39,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f, + 0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x2d,0x20,0x5f,0x33,0x38,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x34,0x35,0x20,0x3d,0x20,0x69, + 0x6e,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x2b,0x20,0x5f,0x33,0x38, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x34,0x39, + 0x20,0x3d,0x20,0x5f,0x34,0x35,0x20,0x2d,0x20,0x5f,0x33,0x39,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x35,0x33,0x20,0x3d,0x20,0x5f, + 0x31,0x34,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79, + 0x7a,0x20,0x2d,0x20,0x5f,0x33,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x35,0x38,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x34,0x39, + 0x2c,0x20,0x5f,0x34,0x39,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x36,0x32,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x34,0x39,0x2c, + 0x20,0x5f,0x32,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x36,0x36,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x34,0x39,0x2c,0x20, + 0x5f,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x37,0x34,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x35,0x33,0x2c,0x20,0x5f, + 0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x38,0x30,0x20,0x3d,0x20,0x5f,0x35,0x38,0x20,0x2d,0x20,0x28,0x5f,0x36,0x32,0x20, + 0x2a,0x20,0x5f,0x36,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x38,0x38,0x20,0x3d,0x20,0x28,0x5f,0x35,0x38,0x20,0x2a,0x20,0x64, + 0x6f,0x74,0x28,0x5f,0x32,0x37,0x2c,0x20,0x5f,0x35,0x33,0x29,0x29,0x20,0x2d,0x20, + 0x28,0x5f,0x36,0x36,0x20,0x2a,0x20,0x5f,0x36,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x30,0x20,0x3d,0x20,0x69,0x6e, + 0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x2a,0x20,0x69,0x6e,0x2e,0x76, + 0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x31,0x31,0x20,0x3d,0x20,0x28,0x5f,0x38,0x38,0x20,0x2a, + 0x20,0x5f,0x38,0x38,0x29,0x20,0x2d,0x20,0x28,0x5f,0x38,0x30,0x20,0x2a,0x20,0x28, + 0x28,0x28,0x5f,0x35,0x38,0x20,0x2a,0x20,0x5f,0x37,0x34,0x29,0x20,0x2d,0x20,0x28, + 0x5f,0x36,0x36,0x20,0x2a,0x20,0x5f,0x36,0x36,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f, + 0x31,0x30,0x30,0x20,0x2a,0x20,0x5f,0x35,0x38,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x74,0x20,0x3d,0x20,0x2d,0x31,0x2e,0x30, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x5f,0x31,0x31,0x31,0x20, + 0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x38,0x30,0x20, + 0x3e,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x33,0x39,0x32,0x32,0x35, + 0x32,0x39,0x30,0x32,0x39,0x30,0x37,0x37,0x38,0x35,0x30,0x32,0x38,0x32,0x31,0x39, + 0x32,0x32,0x33,0x65,0x2d,0x30,0x39,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x33,0x31,0x20,0x3d,0x20,0x28,0x28,0x2d,0x5f,0x38,0x38,0x29,0x20,0x2d,0x20,0x73, + 0x71,0x72,0x74,0x28,0x5f,0x31,0x31,0x31,0x29,0x29,0x20,0x2f,0x20,0x5f,0x38,0x30, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x33,0x37,0x20,0x3d,0x20,0x5f,0x36,0x36,0x20,0x2b,0x20,0x28,0x5f,0x31, + 0x33,0x31,0x20,0x2a,0x20,0x5f,0x36,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x28,0x5f,0x31,0x33,0x31,0x20,0x3e,0x20, + 0x30,0x2e,0x30,0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x31,0x33,0x37,0x20,0x3e,0x20, + 0x30,0x2e,0x30,0x29,0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x31,0x33,0x37,0x20,0x3c, + 0x20,0x5f,0x35,0x38,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d, + 0x20,0x5f,0x31,0x33,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x35,0x37,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x35,0x33,0x2c, + 0x20,0x5f,0x32,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x37,0x31,0x20,0x3d,0x20,0x28,0x5f,0x31,0x35,0x37,0x20,0x2a,0x20, + 0x5f,0x31,0x35,0x37,0x29,0x20,0x2d,0x20,0x28,0x5f,0x37,0x34,0x20,0x2d,0x20,0x5f, + 0x31,0x30,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31, + 0x37,0x31,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x38,0x31,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x31,0x35,0x37,0x29,0x20,0x2d,0x20, + 0x73,0x71,0x72,0x74,0x28,0x5f,0x31,0x37,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x38,0x33,0x20,0x3d,0x20, + 0x5f,0x31,0x38,0x31,0x20,0x3e,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x39,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x38,0x33,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x39,0x32,0x20,0x3d,0x20,0x28,0x74, + 0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x20,0x7c,0x7c,0x20,0x28,0x5f,0x31,0x38,0x31, + 0x20,0x3c,0x20,0x74,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x5f,0x31,0x39,0x32,0x20,0x3d,0x20,0x5f,0x31,0x38,0x33,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x39,0x32,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x64,0x6f,0x74,0x28,0x28,0x5f,0x31,0x34,0x2e, + 0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b, + 0x20,0x28,0x5f,0x32,0x37,0x20,0x2a,0x20,0x5f,0x31,0x38,0x31,0x29,0x29,0x20,0x2d, + 0x20,0x5f,0x33,0x39,0x2c,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f, + 0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x20,0x3c,0x3d,0x20,0x30,0x2e,0x30,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74, + 0x20,0x3d,0x20,0x5f,0x31,0x38,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x5f,0x32,0x31,0x33,0x20,0x3d,0x20,0x5f,0x31,0x34,0x2e,0x63,0x61,0x6d, + 0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x34, + 0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31, + 0x37,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x32,0x31,0x33,0x2c,0x20,0x5f,0x32, + 0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32, + 0x33,0x31,0x20,0x3d,0x20,0x28,0x5f,0x32,0x31,0x37,0x20,0x2a,0x20,0x5f,0x32,0x31, + 0x37,0x29,0x20,0x2d,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x32,0x31,0x33,0x2c,0x20, + 0x5f,0x32,0x31,0x33,0x29,0x20,0x2d,0x20,0x5f,0x31,0x30,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x32,0x33,0x31,0x20,0x3e,0x3d,0x20,0x30, + 0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x34,0x31,0x20,0x3d,0x20,0x28, + 0x2d,0x5f,0x32,0x31,0x37,0x29,0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x32, + 0x33,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f, + 0x6c,0x20,0x5f,0x32,0x34,0x33,0x20,0x3d,0x20,0x5f,0x32,0x34,0x31,0x20,0x3e,0x20, + 0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f, + 0x6c,0x20,0x5f,0x32,0x35,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x5f,0x32,0x34,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x5f,0x32,0x35,0x32,0x20,0x3d,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29, + 0x20,0x7c,0x7c,0x20,0x28,0x5f,0x32,0x34,0x31,0x20,0x3c,0x20,0x74,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x32,0x35, + 0x32,0x20,0x3d,0x20,0x5f,0x32,0x34,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x5f,0x32,0x35,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x64,0x6f,0x74,0x28,0x28,0x5f,0x31,0x34,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f, + 0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x32,0x37,0x20,0x2a, + 0x20,0x5f,0x32,0x34,0x31,0x29,0x29,0x20,0x2d,0x20,0x5f,0x34,0x35,0x2c,0x20,0x69, + 0x6e,0x2e,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x29,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20,0x5f,0x32,0x34,0x31, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x64, + 0x69,0x73,0x63,0x61,0x72,0x64,0x5f,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x28, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x5f,0x32,0x39,0x31,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x28,0x5f,0x31,0x34,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73, + 0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x32,0x37,0x20,0x2a,0x20,0x74,0x29, + 0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x5f,0x33,0x30,0x37,0x20,0x3d,0x20,0x5f,0x31,0x34,0x2e,0x76,0x69, + 0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20,0x5f,0x32,0x39,0x31,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44, + 0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x5f,0x33,0x30,0x37,0x2e,0x7a,0x20,0x2f,0x20, + 0x5f,0x33,0x30,0x37,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e, + 0x6f,0x75,0x74,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x64,0x65,0x70,0x74,0x68, + 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x2d,0x28,0x5f,0x31,0x34,0x2e, + 0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x5f,0x32,0x39,0x31,0x29,0x2e,0x7a,0x2c,0x20, + 0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x00, +}; +static inline const sg_shader_desc* depth_only_capsule_prog_shader_desc(sg_backend backend) { + if (backend == SG_BACKEND_GLCORE) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)depth_only_capsule_vs_source_glsl430; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)depth_only_capsule_fs_source_glsl430; + desc.fragment_func.entry = "main"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[0].glsl_name = "in_pos"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[0].glsl_uniforms[0].array_count = 4; + desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_frame"; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 144; + desc.uniform_blocks[1].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[0].array_count = 9; + desc.uniform_blocks[1].glsl_uniforms[0].glsl_name = "ub_pass"; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.glsl_binding_n = 0; + desc.label = "depth_only_capsule_prog_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_D3D11) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)depth_only_capsule_vs_source_hlsl5; + desc.vertex_func.d3d11_target = "vs_5_0"; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)depth_only_capsule_fs_source_hlsl5; + desc.fragment_func.d3d11_target = "ps_5_0"; + desc.fragment_func.entry = "main"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[0].hlsl_sem_name = "TEXCOORD"; + desc.attrs[0].hlsl_sem_index = 0; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].hlsl_register_b_n = 0; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 144; + desc.uniform_blocks[1].hlsl_register_b_n = 1; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.hlsl_register_t_n = 0; + desc.label = "depth_only_capsule_prog_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_METAL_MACOS) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)depth_only_capsule_vs_source_metal_macos; + desc.vertex_func.entry = "main0"; + desc.fragment_func.source = (const char*)depth_only_capsule_fs_source_metal_macos; + desc.fragment_func.entry = "main0"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].msl_buffer_n = 0; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 144; + desc.uniform_blocks[1].msl_buffer_n = 1; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.msl_buffer_n = 8; + desc.label = "depth_only_capsule_prog_shader"; + } + return &desc; + } + return 0; +} diff --git a/samples/shaders/generated/depth_only_cube.glsl.h b/samples/shaders/generated/depth_only_cube.glsl.h new file mode 100644 index 0000000..1b12967 --- /dev/null +++ b/samples/shaders/generated/depth_only_cube.glsl.h @@ -0,0 +1,626 @@ +#pragma once +/* + #version:1# (machine generated, don't edit!) + + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) + + Cmdline: + sokol-shdc --input E:/box/box3d/samples/shaders/post/depth_only_cube.glsl --output E:/box/box3d/samples/shaders/generated/depth_only_cube.glsl.h --slang hlsl5:metal_macos:glsl430 + + Overview: + ========= + Shader program: 'prog': + Get shader desc: depth_only_cube_prog_shader_desc(sg_query_backend()); + Vertex Shader: vs + Fragment Shader: fs + Attributes: + ATTR_depth_only_cube_prog_in_pos => 0 + Bindings: + Uniform block 'ub_frame': + C struct: depth_only_cube_ub_frame_t + Bind slot: UB_depth_only_cube_ub_frame => 0 + Storage buffer 'cube_instances': + C struct: depth_only_cube_cube_instance_t + Bind slot: VIEW_depth_only_cube_cube_instances => 0 + Readonly: true +*/ +#if !defined(SOKOL_GFX_INCLUDED) +#error "Please include sokol_gfx.h before depth_only_cube.glsl.h" +#endif +#if !defined(SOKOL_SHDC_ALIGN) +#if defined(_MSC_VER) +#define SOKOL_SHDC_ALIGN(a) __declspec(align(a)) +#else +#define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) +#endif +#endif +#define ATTR_depth_only_cube_prog_in_pos (0) +#define UB_depth_only_cube_ub_frame (0) +#define VIEW_depth_only_cube_cube_instances (0) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct depth_only_cube_ub_frame_t { + Mat4 view_proj; + Mat4 view; +} depth_only_cube_ub_frame_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct depth_only_cube_cube_instance_t { + Vec4 xform_row0; + Vec4 xform_row1; + Vec4 xform_row2; + Vec4 base_color; + Vec4 material; +} depth_only_cube_cube_instance_t; +#pragma pack(pop) +/* + #version 430 + + struct cube_instance + { + vec4 xform_row0; + vec4 xform_row1; + vec4 xform_row2; + vec4 base_color; + vec4 material; + }; + + layout(binding = 0, std430) readonly buffer cube_instances + { + cube_instance instances[]; + } _15; + + uniform vec4 ub_frame[8]; + layout(location = 0) in vec3 in_pos; + layout(location = 0) out float v_linear_view_z; + + void main() + { + vec4 _48 = vec4(in_pos, 1.0); + vec4 _76 = vec4(dot(_15.instances[gl_InstanceID].xform_row0, _48), dot(_15.instances[gl_InstanceID].xform_row1, _48), dot(_15.instances[gl_InstanceID].xform_row2, _48), 1.0); + v_linear_view_z = -(mat4(ub_frame[4], ub_frame[5], ub_frame[6], ub_frame[7]) * _76).z; + gl_Position = mat4(ub_frame[0], ub_frame[1], ub_frame[2], ub_frame[3]) * _76; + } + +*/ +static const uint8_t depth_only_cube_vs_source_glsl430[760] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x63,0x75,0x62,0x65,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f, + 0x77,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x62,0x61,0x73, + 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x34,0x20,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a, + 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d, + 0x20,0x30,0x2c,0x20,0x73,0x74,0x64,0x34,0x33,0x30,0x29,0x20,0x72,0x65,0x61,0x64, + 0x6f,0x6e,0x6c,0x79,0x20,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x63,0x75,0x62,0x65, + 0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x63,0x75,0x62,0x65,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20,0x69, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x5d,0x3b,0x0a,0x7d,0x20,0x5f,0x31, + 0x35,0x3b,0x0a,0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34, + 0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x38,0x5d,0x3b,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f, + 0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69, + 0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x76,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x7a,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x34,0x38,0x20,0x3d, + 0x20,0x76,0x65,0x63,0x34,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x37,0x36, + 0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e, + 0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73, + 0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72, + 0x6f,0x77,0x30,0x2c,0x20,0x5f,0x34,0x38,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f, + 0x31,0x35,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x67,0x6c,0x5f, + 0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2c,0x20,0x5f,0x34,0x38,0x29,0x2c,0x20,0x64,0x6f, + 0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b, + 0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x78, + 0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2c,0x20,0x5f,0x34,0x38,0x29,0x2c, + 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x6c,0x69,0x6e, + 0x65,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3d,0x20,0x2d,0x28,0x6d, + 0x61,0x74,0x34,0x28,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x34,0x5d,0x2c, + 0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x35,0x5d,0x2c,0x20,0x75,0x62, + 0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x36,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72, + 0x61,0x6d,0x65,0x5b,0x37,0x5d,0x29,0x20,0x2a,0x20,0x5f,0x37,0x36,0x29,0x2e,0x7a, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f, + 0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d, + 0x65,0x5b,0x30,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x31, + 0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x32,0x5d,0x2c,0x20, + 0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x5f, + 0x37,0x36,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + #version 430 + + layout(location = 0) out vec4 out_linear_depth; + layout(location = 0) in float v_linear_view_z; + + void main() + { + out_linear_depth = vec4(v_linear_view_z, 0.0, 0.0, 0.0); + } + +*/ +static const uint8_t depth_only_cube_fs_source_glsl430[189] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x6f,0x75,0x74,0x5f, + 0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x64,0x65,0x70,0x74,0x68,0x3b,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x30,0x29,0x20,0x69,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x6c,0x69, + 0x6e,0x65,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x0a,0x76,0x6f, + 0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x6f,0x75,0x74,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x64,0x65,0x70,0x74,0x68, + 0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72, + 0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e, + 0x30,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + struct cube_instance + { + float4 xform_row0; + float4 xform_row1; + float4 xform_row2; + float4 base_color; + float4 material; + }; + + ByteAddressBuffer _15 : register(t0); + cbuffer ub_frame : register(b0) + { + row_major float4x4 _68_view_proj : packoffset(c0); + row_major float4x4 _68_view : packoffset(c4); + }; + + + static float4 gl_Position; + static int gl_InstanceIndex; + static float3 in_pos; + static float v_linear_view_z; + + struct SPIRV_Cross_Input + { + float3 in_pos : TEXCOORD0; + uint gl_InstanceIndex : SV_InstanceID; + }; + + struct SPIRV_Cross_Output + { + float v_linear_view_z : TEXCOORD0; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + cube_instance _23; + _23.xform_row0 = asfloat(_15.Load4(gl_InstanceIndex * 80 + 0)); + _23.xform_row1 = asfloat(_15.Load4(gl_InstanceIndex * 80 + 16)); + _23.xform_row2 = asfloat(_15.Load4(gl_InstanceIndex * 80 + 32)); + _23.base_color = asfloat(_15.Load4(gl_InstanceIndex * 80 + 48)); + _23.material = asfloat(_15.Load4(gl_InstanceIndex * 80 + 64)); + float4 _48 = float4(in_pos, 1.0f); + float4 _76 = float4(dot(_23.xform_row0, _48), dot(_23.xform_row1, _48), dot(_23.xform_row2, _48), 1.0f); + v_linear_view_z = -mul(_76, _68_view).z; + gl_Position = mul(_76, _68_view_proj); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_InstanceIndex = int(stage_input.gl_InstanceIndex); + in_pos = stage_input.in_pos; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.v_linear_view_z = v_linear_view_z; + return stage_output; + } +*/ +static const uint8_t depth_only_cube_vs_source_hlsl5[1594] = { + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x63,0x75,0x62,0x65,0x5f,0x69,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72, + 0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6d,0x61, + 0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x42,0x79,0x74,0x65, + 0x41,0x64,0x64,0x72,0x65,0x73,0x73,0x42,0x75,0x66,0x66,0x65,0x72,0x20,0x5f,0x31, + 0x35,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x30,0x29, + 0x3b,0x0a,0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x66,0x72,0x61, + 0x6d,0x65,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x30, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f, + 0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x36,0x38,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f, + 0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78, + 0x34,0x20,0x5f,0x36,0x38,0x5f,0x76,0x69,0x65,0x77,0x20,0x3a,0x20,0x70,0x61,0x63, + 0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x34,0x29,0x3b,0x0a,0x7d,0x3b,0x0a, + 0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x73,0x74,0x61, + 0x74,0x69,0x63,0x20,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61, + 0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a, + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x6c, + 0x69,0x6e,0x65,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x0a,0x73, + 0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73, + 0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20,0x54,0x45, + 0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e, + 0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64, + 0x65,0x78,0x20,0x3a,0x20,0x53,0x56,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x49,0x44,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53, + 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75, + 0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f, + 0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3a,0x20, + 0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f, + 0x6e,0x20,0x3a,0x20,0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b, + 0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d, + 0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x63,0x75,0x62,0x65, + 0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20,0x5f,0x32,0x33,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x5f,0x32,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77, + 0x30,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e, + 0x4c,0x6f,0x61,0x64,0x34,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x2a,0x20,0x38,0x30,0x20,0x2b,0x20,0x30,0x29, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x32,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d, + 0x5f,0x72,0x6f,0x77,0x31,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28, + 0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73, + 0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x2a,0x20,0x38,0x30,0x20, + 0x2b,0x20,0x31,0x36,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x32,0x33,0x2e, + 0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x20,0x3d,0x20,0x61,0x73,0x66, + 0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x67, + 0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20, + 0x2a,0x20,0x38,0x30,0x20,0x2b,0x20,0x33,0x32,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x5f,0x32,0x33,0x2e,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20, + 0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f, + 0x61,0x64,0x34,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49, + 0x6e,0x64,0x65,0x78,0x20,0x2a,0x20,0x38,0x30,0x20,0x2b,0x20,0x34,0x38,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x32,0x33,0x2e,0x6d,0x61,0x74,0x65,0x72,0x69, + 0x61,0x6c,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35, + 0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x2a,0x20,0x38,0x30,0x20,0x2b,0x20,0x36, + 0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x5f,0x34,0x38,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x69,0x6e,0x5f, + 0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x36,0x20,0x3d,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x28,0x64,0x6f,0x74,0x28,0x5f,0x32,0x33,0x2e,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2c,0x20,0x5f,0x34,0x38,0x29,0x2c,0x20,0x64,0x6f, + 0x74,0x28,0x5f,0x32,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31, + 0x2c,0x20,0x5f,0x34,0x38,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x32,0x33,0x2e, + 0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2c,0x20,0x5f,0x34,0x38,0x29, + 0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x6c, + 0x69,0x6e,0x65,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3d,0x20,0x2d, + 0x6d,0x75,0x6c,0x28,0x5f,0x37,0x36,0x2c,0x20,0x5f,0x36,0x38,0x5f,0x76,0x69,0x65, + 0x77,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73, + 0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x5f,0x37,0x36,0x2c, + 0x20,0x5f,0x36,0x38,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x29,0x3b, + 0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, + 0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52, + 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74, + 0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65, + 0x78,0x20,0x3d,0x20,0x69,0x6e,0x74,0x28,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e, + 0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49, + 0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x5f,0x70,0x6f, + 0x73,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e, + 0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x72,0x74, + 0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49, + 0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67, + 0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x67,0x6c,0x5f, + 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74, + 0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x6c,0x69,0x6e, + 0x65,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3d,0x20,0x76,0x5f,0x6c, + 0x69,0x6e,0x65,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f, + 0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + static float4 out_linear_depth; + static float v_linear_view_z; + + struct SPIRV_Cross_Input + { + float v_linear_view_z : TEXCOORD0; + }; + + struct SPIRV_Cross_Output + { + float4 out_linear_depth : SV_Target0; + }; + + void frag_main() + { + out_linear_depth = float4(v_linear_view_z, 0.0f, 0.0f, 0.0f); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + v_linear_view_z = stage_input.v_linear_view_z; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.out_linear_depth = out_linear_depth; + return stage_output; + } +*/ +static const uint8_t depth_only_cube_fs_source_hlsl5[539] = { + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75, + 0x74,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x64,0x65,0x70,0x74,0x68,0x3b,0x0a, + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x6c, + 0x69,0x6e,0x65,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x0a,0x73, + 0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73, + 0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x76,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x76,0x69,0x65, + 0x77,0x5f,0x7a,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b, + 0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52, + 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f, + 0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x64,0x65,0x70,0x74,0x68,0x20,0x3a,0x20,0x53, + 0x56,0x5f,0x54,0x61,0x72,0x67,0x65,0x74,0x30,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76, + 0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72, + 0x5f,0x64,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, + 0x76,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2c, + 0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30, + 0x66,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, + 0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53, + 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74, + 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x76,0x69,0x65, + 0x77,0x5f,0x7a,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75, + 0x74,0x2e,0x76,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e, + 0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, + 0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65, + 0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x6c,0x69, + 0x6e,0x65,0x61,0x72,0x5f,0x64,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x6f,0x75,0x74, + 0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x64,0x65,0x70,0x74,0x68,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f, + 0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + struct cube_instance + { + float4 xform_row0; + float4 xform_row1; + float4 xform_row2; + float4 base_color; + float4 material; + }; + + struct cube_instances + { + cube_instance instances[1]; + }; + + struct ub_frame + { + float4x4 view_proj; + float4x4 view; + }; + + struct main0_out + { + float v_linear_view_z [[user(locn0)]]; + float4 gl_Position [[position]]; + }; + + struct main0_in + { + float3 in_pos [[attribute(0)]]; + }; + + vertex main0_out main0(main0_in in [[stage_in]], constant ub_frame& _68 [[buffer(0)]], const device cube_instances& _15 [[buffer(8)]], uint gl_InstanceIndex [[instance_id]]) + { + main0_out out = {}; + float4 _48 = float4(in.in_pos, 1.0); + float4 _76 = float4(dot(_15.instances[int(gl_InstanceIndex)].xform_row0, _48), dot(_15.instances[int(gl_InstanceIndex)].xform_row1, _48), dot(_15.instances[int(gl_InstanceIndex)].xform_row2, _48), 1.0); + out.v_linear_view_z = -(_68.view * _76).z; + out.gl_Position = _68.view_proj * _76; + return out; + } + +*/ +static const uint8_t depth_only_cube_vs_source_metal_macos[1056] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x63, + 0x75,0x62,0x65,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f, + 0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f, + 0x77,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x62, + 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a, + 0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x63,0x75,0x62,0x65,0x5f, + 0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x63,0x75,0x62,0x65,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20,0x69,0x6e, + 0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x31,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a, + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x76, + 0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x76,0x69,0x65,0x77,0x3b,0x0a,0x7d,0x3b,0x0a, + 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75, + 0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f, + 0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x5b,0x5b, + 0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73, + 0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e, + 0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d, + 0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x5b,0x5b,0x61,0x74, + 0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x76,0x65,0x72,0x74,0x65,0x78,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f, + 0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69, + 0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d, + 0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x66, + 0x72,0x61,0x6d,0x65,0x26,0x20,0x5f,0x36,0x38,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66, + 0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x64, + 0x65,0x76,0x69,0x63,0x65,0x20,0x63,0x75,0x62,0x65,0x5f,0x69,0x6e,0x73,0x74,0x61, + 0x6e,0x63,0x65,0x73,0x26,0x20,0x5f,0x31,0x35,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66, + 0x65,0x72,0x28,0x38,0x29,0x5d,0x5d,0x2c,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c, + 0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x5b, + 0x5b,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x5f,0x69,0x64,0x5d,0x5d,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20, + 0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x5f,0x34,0x38,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x28,0x69,0x6e,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37, + 0x36,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x64,0x6f,0x74,0x28,0x5f, + 0x31,0x35,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x69,0x6e,0x74, + 0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65, + 0x78,0x29,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2c,0x20, + 0x5f,0x34,0x38,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x6e, + 0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x78, + 0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2c,0x20,0x5f,0x34,0x38,0x29,0x2c, + 0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x73,0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f, + 0x72,0x6f,0x77,0x32,0x2c,0x20,0x5f,0x34,0x38,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x6c,0x69,0x6e,0x65, + 0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3d,0x20,0x2d,0x28,0x5f,0x36, + 0x38,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x5f,0x37,0x36,0x29,0x2e,0x7a,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x5f,0x36,0x38,0x2e,0x76,0x69,0x65,0x77,0x5f, + 0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20,0x5f,0x37,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + +}; +/* + #include + #include + + using namespace metal; + + struct main0_out + { + float4 out_linear_depth [[color(0)]]; + }; + + struct main0_in + { + float v_linear_view_z [[user(locn0)]]; + }; + + fragment main0_out main0(main0_in in [[stage_in]]) + { + main0_out out = {}; + out.out_linear_depth = float4(in.v_linear_view_z, 0.0, 0.0, 0.0); + return out; + } + +*/ +static const uint8_t depth_only_cube_fs_source_metal_macos[369] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d, + 0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72, + 0x5f,0x64,0x65,0x70,0x74,0x68,0x20,0x5b,0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30, + 0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20, + 0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e, + 0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65, + 0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69, + 0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b, + 0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74, + 0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f, + 0x75,0x74,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x64,0x65,0x70,0x74,0x68,0x20, + 0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x6c,0x69, + 0x6e,0x65,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2c,0x20,0x30,0x2e,0x30, + 0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a, + 0x00, +}; +static inline const sg_shader_desc* depth_only_cube_prog_shader_desc(sg_backend backend) { + if (backend == SG_BACKEND_GLCORE) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)depth_only_cube_vs_source_glsl430; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)depth_only_cube_fs_source_glsl430; + desc.fragment_func.entry = "main"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[0].glsl_name = "in_pos"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 128; + desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[0].glsl_uniforms[0].array_count = 8; + desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_frame"; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.glsl_binding_n = 0; + desc.label = "depth_only_cube_prog_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_D3D11) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)depth_only_cube_vs_source_hlsl5; + desc.vertex_func.d3d11_target = "vs_5_0"; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)depth_only_cube_fs_source_hlsl5; + desc.fragment_func.d3d11_target = "ps_5_0"; + desc.fragment_func.entry = "main"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[0].hlsl_sem_name = "TEXCOORD"; + desc.attrs[0].hlsl_sem_index = 0; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 128; + desc.uniform_blocks[0].hlsl_register_b_n = 0; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.hlsl_register_t_n = 0; + desc.label = "depth_only_cube_prog_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_METAL_MACOS) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)depth_only_cube_vs_source_metal_macos; + desc.vertex_func.entry = "main0"; + desc.fragment_func.source = (const char*)depth_only_cube_fs_source_metal_macos; + desc.fragment_func.entry = "main0"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 128; + desc.uniform_blocks[0].msl_buffer_n = 0; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.msl_buffer_n = 8; + desc.label = "depth_only_cube_prog_shader"; + } + return &desc; + } + return 0; +} diff --git a/samples/shaders/generated/depth_only_geom.glsl.h b/samples/shaders/generated/depth_only_geom.glsl.h new file mode 100644 index 0000000..682d356 --- /dev/null +++ b/samples/shaders/generated/depth_only_geom.glsl.h @@ -0,0 +1,693 @@ +#pragma once +/* + #version:1# (machine generated, don't edit!) + + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) + + Cmdline: + sokol-shdc --input E:/box/box3d/samples/shaders/post/depth_only_geom.glsl --output E:/box/box3d/samples/shaders/generated/depth_only_geom.glsl.h --slang hlsl5:metal_macos:glsl430 + + Overview: + ========= + Shader program: 'prog': + Get shader desc: depth_only_geom_prog_shader_desc(sg_query_backend()); + Vertex Shader: vs + Fragment Shader: fs + Attributes: + ATTR_depth_only_geom_prog_in_pos => 0 + Bindings: + Uniform block 'ub_draw': + C struct: depth_only_geom_ub_draw_t + Bind slot: UB_depth_only_geom_ub_draw => 2 + Uniform block 'ub_frame': + C struct: depth_only_geom_ub_frame_t + Bind slot: UB_depth_only_geom_ub_frame => 0 + Storage buffer 'instances': + C struct: depth_only_geom_instance_t + Bind slot: VIEW_depth_only_geom_instances => 0 + Readonly: true +*/ +#if !defined(SOKOL_GFX_INCLUDED) +#error "Please include sokol_gfx.h before depth_only_geom.glsl.h" +#endif +#if !defined(SOKOL_SHDC_ALIGN) +#if defined(_MSC_VER) +#define SOKOL_SHDC_ALIGN(a) __declspec(align(a)) +#else +#define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) +#endif +#endif +#define ATTR_depth_only_geom_prog_in_pos (0) +#define UB_depth_only_geom_ub_draw (2) +#define UB_depth_only_geom_ub_frame (0) +#define VIEW_depth_only_geom_instances (0) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct depth_only_geom_ub_draw_t { + int inst_base[4]; +} depth_only_geom_ub_draw_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct depth_only_geom_ub_frame_t { + Mat4 view_proj; + Mat4 view; +} depth_only_geom_ub_frame_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct depth_only_geom_instance_t { + Vec4 xform_row0; + Vec4 xform_row1; + Vec4 xform_row2; + Vec4 base_color; + Vec4 scale; + Vec4 material; +} depth_only_geom_instance_t; +#pragma pack(pop) +/* + #version 430 + + struct instance + { + vec4 xform_row0; + vec4 xform_row1; + vec4 xform_row2; + vec4 base_color; + vec4 scale; + vec4 material; + }; + + layout(binding = 0, std430) readonly buffer instances + { + instance items[]; + } _15; + + uniform ivec4 ub_draw[1]; + uniform vec4 ub_frame[8]; + layout(location = 0) in vec3 in_pos; + layout(location = 0) out float v_linear_view_z; + + void main() + { + int _30 = ub_draw[0].x + gl_InstanceID; + vec4 _68 = vec4(in_pos * _15.items[_30].scale.xyz, 1.0); + vec4 _95 = vec4(dot(_15.items[_30].xform_row0, _68), dot(_15.items[_30].xform_row1, _68), dot(_15.items[_30].xform_row2, _68), 1.0); + v_linear_view_z = -(mat4(ub_frame[4], ub_frame[5], ub_frame[6], ub_frame[7]) * _95).z; + gl_Position = mat4(ub_frame[0], ub_frame[1], ub_frame[2], ub_frame[3]) * _95; + } + +*/ +static const uint8_t depth_only_geom_vs_source_glsl430[812] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72, + 0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x63,0x61, + 0x6c,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x6d,0x61,0x74, + 0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75, + 0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x30,0x2c,0x20,0x73, + 0x74,0x64,0x34,0x33,0x30,0x29,0x20,0x72,0x65,0x61,0x64,0x6f,0x6e,0x6c,0x79,0x20, + 0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20, + 0x69,0x74,0x65,0x6d,0x73,0x5b,0x5d,0x3b,0x0a,0x7d,0x20,0x5f,0x31,0x35,0x3b,0x0a, + 0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x69,0x76,0x65,0x63,0x34,0x20,0x75, + 0x62,0x5f,0x64,0x72,0x61,0x77,0x5b,0x31,0x5d,0x3b,0x0a,0x75,0x6e,0x69,0x66,0x6f, + 0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65, + 0x5b,0x38,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63, + 0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, + 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f, + 0x75,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x6c,0x69,0x6e,0x65,0x61, + 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20, + 0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74, + 0x20,0x5f,0x33,0x30,0x20,0x3d,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x5b,0x30, + 0x5d,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x49,0x44,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x36, + 0x38,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20, + 0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d, + 0x2e,0x73,0x63,0x61,0x6c,0x65,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31,0x2e,0x30,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x39,0x35,0x20,0x3d, + 0x20,0x76,0x65,0x63,0x34,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74, + 0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72, + 0x6f,0x77,0x30,0x2c,0x20,0x5f,0x36,0x38,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f, + 0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2c,0x20,0x5f,0x36,0x38,0x29,0x2c,0x20, + 0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33, + 0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2c,0x20,0x5f, + 0x36,0x38,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3d, + 0x20,0x2d,0x28,0x6d,0x61,0x74,0x34,0x28,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65, + 0x5b,0x34,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x35,0x5d, + 0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x36,0x5d,0x2c,0x20,0x75, + 0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x37,0x5d,0x29,0x20,0x2a,0x20,0x5f,0x39, + 0x35,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73, + 0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x75,0x62,0x5f, + 0x66,0x72,0x61,0x6d,0x65,0x5b,0x30,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61, + 0x6d,0x65,0x5b,0x31,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b, + 0x32,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x33,0x5d,0x29, + 0x20,0x2a,0x20,0x5f,0x39,0x35,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + #version 430 + + layout(location = 0) out vec4 out_linear_depth; + layout(location = 0) in float v_linear_view_z; + + void main() + { + out_linear_depth = vec4(v_linear_view_z, 0.0, 0.0, 0.0); + } + +*/ +static const uint8_t depth_only_geom_fs_source_glsl430[189] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x6f,0x75,0x74,0x5f, + 0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x64,0x65,0x70,0x74,0x68,0x3b,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x30,0x29,0x20,0x69,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x6c,0x69, + 0x6e,0x65,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x0a,0x76,0x6f, + 0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x6f,0x75,0x74,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x64,0x65,0x70,0x74,0x68, + 0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72, + 0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e, + 0x30,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + struct instance + { + float4 xform_row0; + float4 xform_row1; + float4 xform_row2; + float4 base_color; + float4 scale; + float4 material; + }; + + ByteAddressBuffer _15 : register(t0); + cbuffer ub_draw : register(b2) + { + int4 _21_inst_base : packoffset(c0); + }; + + cbuffer ub_frame : register(b0) + { + row_major float4x4 _87_view_proj : packoffset(c0); + row_major float4x4 _87_view : packoffset(c4); + }; + + + static float4 gl_Position; + static int gl_InstanceIndex; + static float3 in_pos; + static float v_linear_view_z; + + struct SPIRV_Cross_Input + { + float3 in_pos : TEXCOORD0; + uint gl_InstanceIndex : SV_InstanceID; + }; + + struct SPIRV_Cross_Output + { + float v_linear_view_z : TEXCOORD0; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + instance _33; + _33.xform_row0 = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 0)); + _33.xform_row1 = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 16)); + _33.xform_row2 = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 32)); + _33.base_color = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 48)); + _33.scale = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 64)); + _33.material = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 80)); + float4 _68 = float4(in_pos * _33.scale.xyz, 1.0f); + float4 _95 = float4(dot(_33.xform_row0, _68), dot(_33.xform_row1, _68), dot(_33.xform_row2, _68), 1.0f); + v_linear_view_z = -mul(_95, _87_view).z; + gl_Position = mul(_95, _87_view_proj); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_InstanceIndex = int(stage_input.gl_InstanceIndex); + in_pos = stage_input.in_pos; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.v_linear_view_z = v_linear_view_z; + return stage_output; + } +*/ +static const uint8_t depth_only_geom_vs_source_hlsl5[1880] = { + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d, + 0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x63,0x61,0x6c,0x65,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6d,0x61,0x74,0x65,0x72, + 0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x42,0x79,0x74,0x65,0x41,0x64,0x64, + 0x72,0x65,0x73,0x73,0x42,0x75,0x66,0x66,0x65,0x72,0x20,0x5f,0x31,0x35,0x20,0x3a, + 0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x30,0x29,0x3b,0x0a,0x63, + 0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x20,0x3a, + 0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x32,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x34,0x20,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73, + 0x74,0x5f,0x62,0x61,0x73,0x65,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66, + 0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x63,0x62,0x75, + 0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x20,0x3a,0x20, + 0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x38,0x37,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70, + 0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74, + 0x28,0x63,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61, + 0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x38,0x37, + 0x5f,0x76,0x69,0x65,0x77,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73, + 0x65,0x74,0x28,0x63,0x34,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x0a,0x73,0x74,0x61, + 0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69, + 0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e, + 0x64,0x65,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69, + 0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72, + 0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74, + 0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70, + 0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52, + 0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f, + 0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x3a,0x20, + 0x53,0x56,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x3b,0x0a,0x7d, + 0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f, + 0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x6c,0x69,0x6e,0x65,0x61, + 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f, + 0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,0x53, + 0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a, + 0x76,0x6f,0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20, + 0x5f,0x33,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61, + 0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31, + 0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67, + 0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29, + 0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x20, + 0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f, + 0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61, + 0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20, + 0x31,0x36,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f, + 0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32, + 0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20, + 0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78, + 0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x33,0x32,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e, + 0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f, + 0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20, + 0x2b,0x20,0x34,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e, + 0x73,0x63,0x61,0x6c,0x65,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28, + 0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69, + 0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f, + 0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a, + 0x20,0x39,0x36,0x20,0x2b,0x20,0x36,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x5f,0x33,0x33,0x2e,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3d,0x20,0x61, + 0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34, + 0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e, + 0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49, + 0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x38,0x30,0x29, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36, + 0x38,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x69,0x6e,0x5f,0x70,0x6f, + 0x73,0x20,0x2a,0x20,0x5f,0x33,0x33,0x2e,0x73,0x63,0x61,0x6c,0x65,0x2e,0x78,0x79, + 0x7a,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x5f,0x39,0x35,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x28,0x64,0x6f,0x74,0x28,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f, + 0x72,0x6f,0x77,0x30,0x2c,0x20,0x5f,0x36,0x38,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28, + 0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2c,0x20, + 0x5f,0x36,0x38,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x33,0x33,0x2e,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2c,0x20,0x5f,0x36,0x38,0x29,0x2c,0x20, + 0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x6c,0x69,0x6e, + 0x65,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3d,0x20,0x2d,0x6d,0x75, + 0x6c,0x28,0x5f,0x39,0x35,0x2c,0x20,0x5f,0x38,0x37,0x5f,0x76,0x69,0x65,0x77,0x29, + 0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74, + 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x5f,0x39,0x35,0x2c,0x20,0x5f, + 0x38,0x37,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x29,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75, + 0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f, + 0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67, + 0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67, + 0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20, + 0x3d,0x20,0x69,0x6e,0x74,0x28,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75, + 0x74,0x2e,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64, + 0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20, + 0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x69,0x6e, + 0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d, + 0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56, + 0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74, + 0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f, + 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x50,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67, + 0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x6c,0x69,0x6e,0x65,0x61, + 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3d,0x20,0x76,0x5f,0x6c,0x69,0x6e, + 0x65,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74, + 0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + static float4 out_linear_depth; + static float v_linear_view_z; + + struct SPIRV_Cross_Input + { + float v_linear_view_z : TEXCOORD0; + }; + + struct SPIRV_Cross_Output + { + float4 out_linear_depth : SV_Target0; + }; + + void frag_main() + { + out_linear_depth = float4(v_linear_view_z, 0.0f, 0.0f, 0.0f); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + v_linear_view_z = stage_input.v_linear_view_z; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.out_linear_depth = out_linear_depth; + return stage_output; + } +*/ +static const uint8_t depth_only_geom_fs_source_hlsl5[539] = { + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75, + 0x74,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x64,0x65,0x70,0x74,0x68,0x3b,0x0a, + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x6c, + 0x69,0x6e,0x65,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x0a,0x73, + 0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73, + 0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x76,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x76,0x69,0x65, + 0x77,0x5f,0x7a,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b, + 0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52, + 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f, + 0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x64,0x65,0x70,0x74,0x68,0x20,0x3a,0x20,0x53, + 0x56,0x5f,0x54,0x61,0x72,0x67,0x65,0x74,0x30,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76, + 0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72, + 0x5f,0x64,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, + 0x76,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2c, + 0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30, + 0x66,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, + 0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53, + 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74, + 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x76,0x69,0x65, + 0x77,0x5f,0x7a,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75, + 0x74,0x2e,0x76,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e, + 0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, + 0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65, + 0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x6c,0x69, + 0x6e,0x65,0x61,0x72,0x5f,0x64,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x6f,0x75,0x74, + 0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x64,0x65,0x70,0x74,0x68,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f, + 0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + struct instance + { + float4 xform_row0; + float4 xform_row1; + float4 xform_row2; + float4 base_color; + float4 scale; + float4 material; + }; + + struct instances + { + instance items[1]; + }; + + struct ub_draw + { + int4 inst_base; + }; + + struct ub_frame + { + float4x4 view_proj; + float4x4 view; + }; + + struct main0_out + { + float v_linear_view_z [[user(locn0)]]; + float4 gl_Position [[position]]; + }; + + struct main0_in + { + float3 in_pos [[attribute(0)]]; + }; + + vertex main0_out main0(main0_in in [[stage_in]], constant ub_frame& _87 [[buffer(0)]], constant ub_draw& _21 [[buffer(2)]], const device instances& _15 [[buffer(8)]], uint gl_InstanceIndex [[instance_id]]) + { + main0_out out = {}; + int _30 = _21.inst_base.x + int(gl_InstanceIndex); + float4 _68 = float4(in.in_pos * _15.items[_30].scale.xyz, 1.0); + float4 _95 = float4(dot(_15.items[_30].xform_row0, _68), dot(_15.items[_30].xform_row1, _68), dot(_15.items[_30].xform_row2, _68), 1.0); + out.v_linear_view_z = -(_87.view * _95).z; + out.gl_Position = _87.view_proj * _95; + return out; + } + +*/ +static const uint8_t depth_only_geom_vs_source_metal_macos[1144] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x73,0x63,0x61,0x6c,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a, + 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x20,0x69,0x74,0x65,0x6d,0x73,0x5b,0x31,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73, + 0x74,0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x34,0x20,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61, + 0x73,0x65,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75, + 0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x76, + 0x69,0x65,0x77,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20, + 0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x7a,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63, + 0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b, + 0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a, + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f, + 0x70,0x6f,0x73,0x20,0x5b,0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28, + 0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,0x65,0x78, + 0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30, + 0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73, + 0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x26,0x20,0x5f,0x38, + 0x37,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x64,0x72,0x61, + 0x77,0x26,0x20,0x5f,0x32,0x31,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28, + 0x32,0x29,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x64,0x65,0x76,0x69, + 0x63,0x65,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x26,0x20,0x5f,0x31, + 0x35,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x38,0x29,0x5d,0x5d,0x2c, + 0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x5b,0x5b,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x5f,0x69,0x64,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61, + 0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x33,0x30,0x20,0x3d,0x20, + 0x5f,0x32,0x31,0x2e,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20, + 0x2b,0x20,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x5f,0x36,0x38,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x28,0x69,0x6e,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x2a,0x20,0x5f,0x31,0x35, + 0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x73,0x63,0x61,0x6c, + 0x65,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x39,0x35,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65, + 0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f, + 0x77,0x30,0x2c,0x20,0x5f,0x36,0x38,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31, + 0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2c,0x20,0x5f,0x36,0x38,0x29,0x2c,0x20,0x64, + 0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30, + 0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2c,0x20,0x5f,0x36, + 0x38,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75, + 0x74,0x2e,0x76,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x7a,0x20,0x3d,0x20,0x2d,0x28,0x5f,0x38,0x37,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a, + 0x20,0x5f,0x39,0x35,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, + 0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x5f, + 0x38,0x37,0x2e,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20,0x5f, + 0x39,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f, + 0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + struct main0_out + { + float4 out_linear_depth [[color(0)]]; + }; + + struct main0_in + { + float v_linear_view_z [[user(locn0)]]; + }; + + fragment main0_out main0(main0_in in [[stage_in]]) + { + main0_out out = {}; + out.out_linear_depth = float4(in.v_linear_view_z, 0.0, 0.0, 0.0); + return out; + } + +*/ +static const uint8_t depth_only_geom_fs_source_metal_macos[369] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d, + 0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72, + 0x5f,0x64,0x65,0x70,0x74,0x68,0x20,0x5b,0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30, + 0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20, + 0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e, + 0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65, + 0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69, + 0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b, + 0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74, + 0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f, + 0x75,0x74,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x64,0x65,0x70,0x74,0x68,0x20, + 0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x6c,0x69, + 0x6e,0x65,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2c,0x20,0x30,0x2e,0x30, + 0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a, + 0x00, +}; +static inline const sg_shader_desc* depth_only_geom_prog_shader_desc(sg_backend backend) { + if (backend == SG_BACKEND_GLCORE) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)depth_only_geom_vs_source_glsl430; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)depth_only_geom_fs_source_glsl430; + desc.fragment_func.entry = "main"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[0].glsl_name = "in_pos"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 128; + desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[0].glsl_uniforms[0].array_count = 8; + desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_frame"; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 16; + desc.uniform_blocks[2].glsl_uniforms[0].type = SG_UNIFORMTYPE_INT4; + desc.uniform_blocks[2].glsl_uniforms[0].array_count = 1; + desc.uniform_blocks[2].glsl_uniforms[0].glsl_name = "ub_draw"; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.glsl_binding_n = 0; + desc.label = "depth_only_geom_prog_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_D3D11) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)depth_only_geom_vs_source_hlsl5; + desc.vertex_func.d3d11_target = "vs_5_0"; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)depth_only_geom_fs_source_hlsl5; + desc.fragment_func.d3d11_target = "ps_5_0"; + desc.fragment_func.entry = "main"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[0].hlsl_sem_name = "TEXCOORD"; + desc.attrs[0].hlsl_sem_index = 0; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 128; + desc.uniform_blocks[0].hlsl_register_b_n = 0; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 16; + desc.uniform_blocks[2].hlsl_register_b_n = 2; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.hlsl_register_t_n = 0; + desc.label = "depth_only_geom_prog_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_METAL_MACOS) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)depth_only_geom_vs_source_metal_macos; + desc.vertex_func.entry = "main0"; + desc.fragment_func.source = (const char*)depth_only_geom_fs_source_metal_macos; + desc.fragment_func.entry = "main0"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 128; + desc.uniform_blocks[0].msl_buffer_n = 0; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 16; + desc.uniform_blocks[2].msl_buffer_n = 2; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.msl_buffer_n = 8; + desc.label = "depth_only_geom_prog_shader"; + } + return &desc; + } + return 0; +} diff --git a/samples/shaders/generated/depth_only_sphere.glsl.h b/samples/shaders/generated/depth_only_sphere.glsl.h new file mode 100644 index 0000000..9388b9e --- /dev/null +++ b/samples/shaders/generated/depth_only_sphere.glsl.h @@ -0,0 +1,939 @@ +#pragma once +/* + #version:1# (machine generated, don't edit!) + + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) + + Cmdline: + sokol-shdc --input E:/box/box3d/samples/shaders/post/depth_only_sphere.glsl --output E:/box/box3d/samples/shaders/generated/depth_only_sphere.glsl.h --slang hlsl5:metal_macos:glsl430 + + Overview: + ========= + Shader program: 'prog': + Get shader desc: depth_only_sphere_prog_shader_desc(sg_query_backend()); + Vertex Shader: vs + Fragment Shader: fs + Attributes: + ATTR_depth_only_sphere_prog_in_pos => 0 + Bindings: + Uniform block 'ub_frame': + C struct: depth_only_sphere_ub_frame_t + Bind slot: UB_depth_only_sphere_ub_frame => 0 + Uniform block 'ub_pass': + C struct: depth_only_sphere_ub_pass_t + Bind slot: UB_depth_only_sphere_ub_pass => 1 + Storage buffer 'instances': + C struct: depth_only_sphere_instance_t + Bind slot: VIEW_depth_only_sphere_instances => 0 + Readonly: true +*/ +#if !defined(SOKOL_GFX_INCLUDED) +#error "Please include sokol_gfx.h before depth_only_sphere.glsl.h" +#endif +#if !defined(SOKOL_SHDC_ALIGN) +#if defined(_MSC_VER) +#define SOKOL_SHDC_ALIGN(a) __declspec(align(a)) +#else +#define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) +#endif +#endif +#define ATTR_depth_only_sphere_prog_in_pos (0) +#define UB_depth_only_sphere_ub_frame (0) +#define UB_depth_only_sphere_ub_pass (1) +#define VIEW_depth_only_sphere_instances (0) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct depth_only_sphere_ub_frame_t { + Mat4 view_proj; +} depth_only_sphere_ub_frame_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct depth_only_sphere_ub_pass_t { + Mat4 view_proj; + Mat4 view; + Vec4 camera_pos; +} depth_only_sphere_ub_pass_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct depth_only_sphere_instance_t { + Vec4 xform_row0; + Vec4 xform_row1; + Vec4 xform_row2; + Vec4 base_color; + Vec4 params; + Vec4 material; +} depth_only_sphere_instance_t; +#pragma pack(pop) +/* + #version 430 + + struct instance + { + vec4 xform_row0; + vec4 xform_row1; + vec4 xform_row2; + vec4 base_color; + vec4 params; + vec4 material; + }; + + layout(binding = 0, std430) readonly buffer instances + { + instance items[]; + } _15; + + uniform vec4 ub_frame[4]; + layout(location = 0) in vec3 in_pos; + layout(location = 0) sample out vec3 v_world_pos_proxy; + layout(location = 1) flat out vec3 v_center; + layout(location = 2) flat out float v_radius; + + void main() + { + vec3 _54 = vec3(_15.items[gl_InstanceID].xform_row0.w, _15.items[gl_InstanceID].xform_row1.w, _15.items[gl_InstanceID].xform_row2.w); + vec3 _68 = _54 + (in_pos * (2.0 * _15.items[gl_InstanceID].params.x)); + v_world_pos_proxy = _68; + v_center = _54; + v_radius = _15.items[gl_InstanceID].params.x; + gl_Position = mat4(ub_frame[0], ub_frame[1], ub_frame[2], ub_frame[3]) * vec4(_68, 1.0); + } + +*/ +static const uint8_t depth_only_sphere_vs_source_glsl430[876] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72, + 0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x6d,0x61, + 0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f, + 0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x30,0x2c,0x20, + 0x73,0x74,0x64,0x34,0x33,0x30,0x29,0x20,0x72,0x65,0x61,0x64,0x6f,0x6e,0x6c,0x79, + 0x20,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x20,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5d,0x3b,0x0a,0x7d,0x20,0x5f,0x31,0x35,0x3b, + 0x0a,0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75, + 0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x34,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f, + 0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29, + 0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b, + 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x30,0x29,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x20,0x6f,0x75,0x74, + 0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f, + 0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28, + 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x66,0x6c, + 0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x63,0x65, + 0x6e,0x74,0x65,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63, + 0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x66,0x6c,0x61,0x74,0x20, + 0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69, + 0x75,0x73,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x35,0x34,0x20, + 0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73, + 0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e, + 0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f,0x31, + 0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61, + 0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77, + 0x31,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x67, + 0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x36,0x38,0x20,0x3d,0x20,0x5f,0x35,0x34,0x20, + 0x2b,0x20,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x2a,0x20,0x28,0x32,0x2e,0x30, + 0x20,0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x67,0x6c,0x5f, + 0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x70,0x61,0x72,0x61, + 0x6d,0x73,0x2e,0x78,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3d,0x20, + 0x5f,0x36,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65, + 0x72,0x20,0x3d,0x20,0x5f,0x35,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72, + 0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d, + 0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d, + 0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67, + 0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74, + 0x34,0x28,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x30,0x5d,0x2c,0x20,0x75, + 0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x31,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66, + 0x72,0x61,0x6d,0x65,0x5b,0x32,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d, + 0x65,0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x36,0x38, + 0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + #version 430 + + uniform vec4 ub_pass[9]; + layout(location = 0) sample in vec3 v_world_pos_proxy; + layout(location = 1) flat in vec3 v_center; + layout(location = 2) flat in float v_radius; + layout(location = 0) out vec4 out_linear_depth; + + void main() + { + vec3 _27 = normalize(v_world_pos_proxy - ub_pass[8].xyz); + vec3 _32 = ub_pass[8].xyz - v_center; + float _37 = dot(_32, _27); + float _53 = (_37 * _37) - (dot(_32, _32) - (v_radius * v_radius)); + if (_53 < 0.0) + { + discard; + } + float _66 = (-_37) - sqrt(_53); + if (_66 < 0.0) + { + discard; + } + vec4 _88 = vec4(ub_pass[8].xyz + (_27 * _66), 1.0); + vec4 _104 = mat4(ub_pass[0], ub_pass[1], ub_pass[2], ub_pass[3]) * _88; + gl_FragDepth = _104.z / _104.w; + out_linear_depth = vec4(-(mat4(ub_pass[4], ub_pass[5], ub_pass[6], ub_pass[7]) * _88).z, 0.0, 0.0, 0.0); + } + +*/ +static const uint8_t depth_only_sphere_fs_source_glsl430[865] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x75,0x6e, + 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x70,0x61, + 0x73,0x73,0x5b,0x39,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f, + 0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x31,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20, + 0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, + 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x66, + 0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72, + 0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f, + 0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20, + 0x76,0x65,0x63,0x34,0x20,0x6f,0x75,0x74,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f, + 0x64,0x65,0x70,0x74,0x68,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69, + 0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f, + 0x32,0x37,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x76, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79, + 0x20,0x2d,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x38,0x5d,0x2e,0x78,0x79, + 0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x33,0x32, + 0x20,0x3d,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x38,0x5d,0x2e,0x78,0x79, + 0x7a,0x20,0x2d,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x33,0x37,0x20,0x3d,0x20,0x64,0x6f, + 0x74,0x28,0x5f,0x33,0x32,0x2c,0x20,0x5f,0x32,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x33,0x20,0x3d,0x20,0x28,0x5f,0x33, + 0x37,0x20,0x2a,0x20,0x5f,0x33,0x37,0x29,0x20,0x2d,0x20,0x28,0x64,0x6f,0x74,0x28, + 0x5f,0x33,0x32,0x2c,0x20,0x5f,0x33,0x32,0x29,0x20,0x2d,0x20,0x28,0x76,0x5f,0x72, + 0x61,0x64,0x69,0x75,0x73,0x20,0x2a,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x35,0x33,0x20, + 0x3c,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36, + 0x36,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x33,0x37,0x29,0x20,0x2d,0x20,0x73,0x71,0x72, + 0x74,0x28,0x5f,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x5f,0x36,0x36,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34, + 0x20,0x5f,0x38,0x38,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x75,0x62,0x5f,0x70, + 0x61,0x73,0x73,0x5b,0x38,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x32, + 0x37,0x20,0x2a,0x20,0x5f,0x36,0x36,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x31,0x30,0x34,0x20,0x3d,0x20, + 0x6d,0x61,0x74,0x34,0x28,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x30,0x5d,0x2c, + 0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x31,0x5d,0x2c,0x20,0x75,0x62,0x5f, + 0x70,0x61,0x73,0x73,0x5b,0x32,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73, + 0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x5f,0x38,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x5f, + 0x31,0x30,0x34,0x2e,0x7a,0x20,0x2f,0x20,0x5f,0x31,0x30,0x34,0x2e,0x77,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x64, + 0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x2d,0x28,0x6d,0x61, + 0x74,0x34,0x28,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x34,0x5d,0x2c,0x20,0x75, + 0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x35,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x70,0x61, + 0x73,0x73,0x5b,0x36,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x37, + 0x5d,0x29,0x20,0x2a,0x20,0x5f,0x38,0x38,0x29,0x2e,0x7a,0x2c,0x20,0x30,0x2e,0x30, + 0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a, + 0x00, +}; +/* + struct instance + { + float4 xform_row0; + float4 xform_row1; + float4 xform_row2; + float4 base_color; + float4 params; + float4 material; + }; + + ByteAddressBuffer _15 : register(t0); + cbuffer ub_frame : register(b0) + { + row_major float4x4 _85_view_proj : packoffset(c0); + }; + + + static float4 gl_Position; + static int gl_InstanceIndex; + static float3 in_pos; + static float3 v_world_pos_proxy; + static float3 v_center; + static float v_radius; + + struct SPIRV_Cross_Input + { + float3 in_pos : TEXCOORD0; + uint gl_InstanceIndex : SV_InstanceID; + }; + + struct SPIRV_Cross_Output + { + sample float3 v_world_pos_proxy : TEXCOORD0; + nointerpolation float3 v_center : TEXCOORD1; + nointerpolation float v_radius : TEXCOORD2; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + instance _23; + _23.xform_row0 = asfloat(_15.Load4(gl_InstanceIndex * 96 + 0)); + _23.xform_row1 = asfloat(_15.Load4(gl_InstanceIndex * 96 + 16)); + _23.xform_row2 = asfloat(_15.Load4(gl_InstanceIndex * 96 + 32)); + _23.base_color = asfloat(_15.Load4(gl_InstanceIndex * 96 + 48)); + _23.params = asfloat(_15.Load4(gl_InstanceIndex * 96 + 64)); + _23.material = asfloat(_15.Load4(gl_InstanceIndex * 96 + 80)); + float3 _54 = float3(_23.xform_row0.w, _23.xform_row1.w, _23.xform_row2.w); + float3 _68 = _54 + (in_pos * (2.0f * _23.params.x)); + v_world_pos_proxy = _68; + v_center = _54; + v_radius = _23.params.x; + gl_Position = mul(float4(_68, 1.0f), _85_view_proj); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_InstanceIndex = int(stage_input.gl_InstanceIndex); + in_pos = stage_input.in_pos; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.v_world_pos_proxy = v_world_pos_proxy; + stage_output.v_center = v_center; + stage_output.v_radius = v_radius; + return stage_output; + } +*/ +static const uint8_t depth_only_sphere_vs_source_hlsl5[1890] = { + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d, + 0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x73,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6d,0x61,0x74,0x65, + 0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x42,0x79,0x74,0x65,0x41,0x64, + 0x64,0x72,0x65,0x73,0x73,0x42,0x75,0x66,0x66,0x65,0x72,0x20,0x5f,0x31,0x35,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x30,0x29,0x3b,0x0a, + 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65, + 0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x38,0x35,0x5f,0x76,0x69,0x65, + 0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66, + 0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x0a,0x73,0x74, + 0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50, + 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, + 0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49, + 0x6e,0x64,0x65,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x73,0x74,0x61,0x74, + 0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x73,0x74,0x61, + 0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e, + 0x74,0x65,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x0a,0x73,0x74,0x72, + 0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, + 0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43, + 0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20, + 0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78, + 0x20,0x3a,0x20,0x53,0x56,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44, + 0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49, + 0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f, + 0x70,0x72,0x6f,0x78,0x79,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44, + 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f, + 0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f, + 0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52, + 0x44,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70, + 0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f, + 0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52, + 0x44,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67, + 0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,0x53,0x56,0x5f, + 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x6f, + 0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20,0x5f,0x32, + 0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x32,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d, + 0x5f,0x72,0x6f,0x77,0x30,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28, + 0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73, + 0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x2a,0x20,0x39,0x36,0x20, + 0x2b,0x20,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x32,0x33,0x2e,0x78, + 0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c, + 0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x67,0x6c, + 0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x2a, + 0x20,0x39,0x36,0x20,0x2b,0x20,0x31,0x36,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x5f,0x32,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x20,0x3d, + 0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61, + 0x64,0x34,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e, + 0x64,0x65,0x78,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x33,0x32,0x29,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x5f,0x32,0x33,0x2e,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31, + 0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61, + 0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20, + 0x34,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x32,0x33,0x2e,0x70,0x61, + 0x72,0x61,0x6d,0x73,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f, + 0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b, + 0x20,0x36,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x32,0x33,0x2e,0x6d, + 0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61, + 0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x67,0x6c,0x5f,0x49, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x2a,0x20,0x39, + 0x36,0x20,0x2b,0x20,0x38,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x5f,0x35,0x34,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x28,0x5f,0x32,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30, + 0x2e,0x77,0x2c,0x20,0x5f,0x32,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f, + 0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f,0x32,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f, + 0x72,0x6f,0x77,0x32,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x5f,0x36,0x38,0x20,0x3d,0x20,0x5f,0x35,0x34,0x20,0x2b,0x20, + 0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x2a,0x20,0x28,0x32,0x2e,0x30,0x66,0x20, + 0x2a,0x20,0x5f,0x32,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f, + 0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x5f,0x36,0x38,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3d,0x20,0x5f,0x35, + 0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20, + 0x3d,0x20,0x5f,0x32,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20, + 0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x36,0x38, + 0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f,0x38,0x35,0x5f,0x76,0x69,0x65, + 0x77,0x5f,0x70,0x72,0x6f,0x6a,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52, + 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d, + 0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, + 0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75, + 0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x3d,0x20,0x69,0x6e,0x74,0x28, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x49, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x3d,0x20,0x73,0x74,0x61,0x67, + 0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73, + 0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75, + 0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f, + 0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69, + 0x6f,0x6e,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70, + 0x75,0x74,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70, + 0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70, + 0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74, + 0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x63,0x65,0x6e, + 0x74,0x65,0x72,0x20,0x3d,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74, + 0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x76,0x5f,0x72,0x61, + 0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d, + 0x0a,0x00, +}; +/* + cbuffer ub_pass : register(b1) + { + row_major float4x4 _14_view_proj : packoffset(c0); + row_major float4x4 _14_view : packoffset(c4); + float4 _14_camera_pos : packoffset(c8); + }; + + + static float gl_FragDepth; + static float3 v_world_pos_proxy; + static float3 v_center; + static float v_radius; + static float4 out_linear_depth; + + struct SPIRV_Cross_Input + { + sample float3 v_world_pos_proxy : TEXCOORD0; + nointerpolation float3 v_center : TEXCOORD1; + nointerpolation float v_radius : TEXCOORD2; + }; + + struct SPIRV_Cross_Output + { + float4 out_linear_depth : SV_Target0; + float gl_FragDepth : SV_Depth; + }; + + void frag_main() + { + float3 _27 = normalize(v_world_pos_proxy - _14_camera_pos.xyz); + float3 _32 = _14_camera_pos.xyz - v_center; + float _37 = dot(_32, _27); + float _53 = (_37 * _37) - (dot(_32, _32) - (v_radius * v_radius)); + if (_53 < 0.0f) + { + discard; + } + float _66 = (-_37) - sqrt(_53); + if (_66 < 0.0f) + { + discard; + } + float4 _88 = float4(_14_camera_pos.xyz + (_27 * _66), 1.0f); + float4 _104 = mul(_88, _14_view_proj); + gl_FragDepth = _104.z / _104.w; + out_linear_depth = float4(-mul(_88, _14_view).z, 0.0f, 0.0f, 0.0f); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + v_world_pos_proxy = stage_input.v_world_pos_proxy; + v_center = stage_input.v_center; + v_radius = stage_input.v_radius; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_FragDepth = gl_FragDepth; + stage_output.out_linear_depth = out_linear_depth; + return stage_output; + } +*/ +static const uint8_t depth_only_sphere_fs_source_hlsl5[1571] = { + 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x31,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x31,0x34,0x5f,0x76,0x69,0x65,0x77, + 0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73, + 0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f, + 0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f, + 0x31,0x34,0x5f,0x76,0x69,0x65,0x77,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66, + 0x66,0x73,0x65,0x74,0x28,0x63,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x34,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f, + 0x70,0x6f,0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74, + 0x28,0x63,0x38,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69, + 0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44, + 0x65,0x70,0x74,0x68,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f, + 0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x73, + 0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61, + 0x64,0x69,0x75,0x73,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x64, + 0x65,0x70,0x74,0x68,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50, + 0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f, + 0x70,0x72,0x6f,0x78,0x79,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44, + 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f, + 0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f, + 0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52, + 0x44,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70, + 0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f, + 0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52, + 0x44,0x32,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53, + 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75, + 0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f, + 0x75,0x74,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x64,0x65,0x70,0x74,0x68,0x20, + 0x3a,0x20,0x53,0x56,0x5f,0x54,0x61,0x72,0x67,0x65,0x74,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44, + 0x65,0x70,0x74,0x68,0x20,0x3a,0x20,0x53,0x56,0x5f,0x44,0x65,0x70,0x74,0x68,0x3b, + 0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d, + 0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x5f,0x32,0x37,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69, + 0x7a,0x65,0x28,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70, + 0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x5f,0x31,0x34,0x5f,0x63,0x61,0x6d,0x65,0x72, + 0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x33,0x32,0x20,0x3d,0x20,0x5f,0x31,0x34, + 0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20, + 0x2d,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x33,0x37,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28, + 0x5f,0x33,0x32,0x2c,0x20,0x5f,0x32,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x33,0x20,0x3d,0x20,0x28,0x5f,0x33,0x37,0x20, + 0x2a,0x20,0x5f,0x33,0x37,0x29,0x20,0x2d,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x33, + 0x32,0x2c,0x20,0x5f,0x33,0x32,0x29,0x20,0x2d,0x20,0x28,0x76,0x5f,0x72,0x61,0x64, + 0x69,0x75,0x73,0x20,0x2a,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x35,0x33,0x20,0x3c,0x20, + 0x30,0x2e,0x30,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x36, + 0x20,0x3d,0x20,0x28,0x2d,0x5f,0x33,0x37,0x29,0x20,0x2d,0x20,0x73,0x71,0x72,0x74, + 0x28,0x5f,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, + 0x36,0x36,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x5f,0x38,0x38,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, + 0x5f,0x31,0x34,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78, + 0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x32,0x37,0x20,0x2a,0x20,0x5f,0x36,0x36,0x29, + 0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x5f,0x31,0x30,0x34,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x5f, + 0x38,0x38,0x2c,0x20,0x5f,0x31,0x34,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f, + 0x6a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44, + 0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x5f,0x31,0x30,0x34,0x2e,0x7a,0x20,0x2f,0x20, + 0x5f,0x31,0x30,0x34,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f, + 0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x64,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x2d,0x6d,0x75,0x6c,0x28,0x5f,0x38,0x38,0x2c,0x20, + 0x5f,0x31,0x34,0x5f,0x76,0x69,0x65,0x77,0x29,0x2e,0x7a,0x2c,0x20,0x30,0x2e,0x30, + 0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f, + 0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56, + 0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78, + 0x79,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e, + 0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78, + 0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20, + 0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f, + 0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x61, + 0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70, + 0x75,0x74,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75, + 0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75, + 0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74, + 0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68, + 0x20,0x3d,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75, + 0x74,0x2e,0x6f,0x75,0x74,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x64,0x65,0x70, + 0x74,0x68,0x20,0x3d,0x20,0x6f,0x75,0x74,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f, + 0x64,0x65,0x70,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a, + 0x7d,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + struct instance + { + float4 xform_row0; + float4 xform_row1; + float4 xform_row2; + float4 base_color; + float4 params; + float4 material; + }; + + struct instances + { + instance items[1]; + }; + + struct ub_frame + { + float4x4 view_proj; + }; + + struct main0_out + { + float3 v_world_pos_proxy [[user(locn0)]]; + float3 v_center [[user(locn1)]]; + float v_radius [[user(locn2)]]; + float4 gl_Position [[position]]; + }; + + struct main0_in + { + float3 in_pos [[attribute(0)]]; + }; + + vertex main0_out main0(main0_in in [[stage_in]], constant ub_frame& _85 [[buffer(0)]], const device instances& _15 [[buffer(8)]], uint gl_InstanceIndex [[instance_id]]) + { + main0_out out = {}; + float3 _54 = float3(_15.items[int(gl_InstanceIndex)].xform_row0.w, _15.items[int(gl_InstanceIndex)].xform_row1.w, _15.items[int(gl_InstanceIndex)].xform_row2.w); + float3 _68 = _54 + (in.in_pos * (2.0 * _15.items[int(gl_InstanceIndex)].params.x)); + out.v_world_pos_proxy = _68; + out.v_center = _54; + out.v_radius = _15.items[int(gl_InstanceIndex)].params.x; + out.gl_Position = _85.view_proj * float4(_68, 1.0); + return out; + } + +*/ +static const uint8_t depth_only_sphere_vs_source_metal_macos[1199] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x20,0x69,0x74,0x65,0x6d,0x73,0x5b,0x31,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a, + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x76, + 0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x5b,0x5b, + 0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74, + 0x65,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29, + 0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f, + 0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f, + 0x63,0x6e,0x32,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b, + 0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a, + 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e, + 0x5f,0x70,0x6f,0x73,0x20,0x5b,0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65, + 0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,0x65, + 0x78,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e, + 0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x26,0x20,0x5f, + 0x38,0x35,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d, + 0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x20,0x69, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x26,0x20,0x5f,0x31,0x35,0x20,0x5b,0x5b, + 0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x38,0x29,0x5d,0x5d,0x2c,0x20,0x75,0x69,0x6e, + 0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64, + 0x65,0x78,0x20,0x5b,0x5b,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x5f,0x69,0x64, + 0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f, + 0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x35,0x34,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b, + 0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49, + 0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77, + 0x30,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x69, + 0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e, + 0x64,0x65,0x78,0x29,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31, + 0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x69,0x6e, + 0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64, + 0x65,0x78,0x29,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e, + 0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f, + 0x36,0x38,0x20,0x3d,0x20,0x5f,0x35,0x34,0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x69, + 0x6e,0x5f,0x70,0x6f,0x73,0x20,0x2a,0x20,0x28,0x32,0x2e,0x30,0x20,0x2a,0x20,0x5f, + 0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f, + 0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e, + 0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x6f,0x75,0x74,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f, + 0x70,0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x5f,0x36,0x38,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3d,0x20, + 0x5f,0x35,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x72, + 0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d, + 0x73,0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e, + 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x5f,0x38,0x35,0x2e,0x76,0x69,0x65, + 0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, + 0x5f,0x36,0x38,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + struct ub_pass + { + float4x4 view_proj; + float4x4 view; + float4 camera_pos; + }; + + struct main0_out + { + float4 out_linear_depth [[color(0)]]; + float gl_FragDepth [[depth(any)]]; + }; + + struct main0_in + { + float3 v_world_pos_proxy [[user(locn0), sample_perspective]]; + float3 v_center [[user(locn1), flat]]; + float v_radius [[user(locn2), flat]]; + }; + + fragment main0_out main0(main0_in in [[stage_in]], constant ub_pass& _14 [[buffer(1)]]) + { + main0_out out = {}; + float3 _27 = fast::normalize(in.v_world_pos_proxy - _14.camera_pos.xyz); + float3 _32 = _14.camera_pos.xyz - in.v_center; + float _37 = dot(_32, _27); + float _53 = (_37 * _37) - (dot(_32, _32) - (in.v_radius * in.v_radius)); + if (_53 < 0.0) + { + discard_fragment(); + } + float _66 = (-_37) - sqrt(_53); + if (_66 < 0.0) + { + discard_fragment(); + } + float4 _88 = float4(_14.camera_pos.xyz + (_27 * _66), 1.0); + float4 _104 = _14.view_proj * _88; + out.gl_FragDepth = _104.z / _104.w; + out.out_linear_depth = float4(-(_14.view * _88).z, 0.0, 0.0, 0.0); + return out; + } + +*/ +static const uint8_t depth_only_sphere_fs_source_metal_macos[1174] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75, + 0x62,0x5f,0x70,0x61,0x73,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x78,0x34,0x20,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x76,0x69, + 0x65,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63, + 0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73, + 0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74, + 0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x64,0x65,0x70,0x74,0x68,0x20,0x5b,0x5b, + 0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70, + 0x74,0x68,0x20,0x5b,0x5b,0x64,0x65,0x70,0x74,0x68,0x28,0x61,0x6e,0x79,0x29,0x5d, + 0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61, + 0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f, + 0x70,0x72,0x6f,0x78,0x79,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63, + 0x6e,0x30,0x29,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x70,0x65,0x72,0x73, + 0x70,0x65,0x63,0x74,0x69,0x76,0x65,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x5b, + 0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29,0x2c,0x20,0x66,0x6c, + 0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28, + 0x6c,0x6f,0x63,0x6e,0x32,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a, + 0x7d,0x3b,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x20,0x6d,0x61,0x69, + 0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69, + 0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65, + 0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20, + 0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x31,0x34,0x20,0x5b,0x5b,0x62, + 0x75,0x66,0x66,0x65,0x72,0x28,0x31,0x29,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20, + 0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x5f,0x32,0x37,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72, + 0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x5f,0x31, + 0x34,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x33, + 0x32,0x20,0x3d,0x20,0x5f,0x31,0x34,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70, + 0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x63,0x65, + 0x6e,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x33,0x37,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x33,0x32,0x2c,0x20,0x5f, + 0x32,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x35,0x33,0x20,0x3d,0x20,0x28,0x5f,0x33,0x37,0x20,0x2a,0x20,0x5f,0x33,0x37,0x29, + 0x20,0x2d,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x33,0x32,0x2c,0x20,0x5f,0x33,0x32, + 0x29,0x20,0x2d,0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73, + 0x20,0x2a,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x35,0x33,0x20,0x3c,0x20, + 0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64,0x5f,0x66,0x72,0x61,0x67,0x6d, + 0x65,0x6e,0x74,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x36,0x20,0x3d,0x20,0x28,0x2d,0x5f, + 0x33,0x37,0x29,0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x35,0x33,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x36,0x36,0x20,0x3c,0x20,0x30, + 0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64,0x5f,0x66,0x72,0x61,0x67,0x6d,0x65, + 0x6e,0x74,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x38,0x38,0x20,0x3d,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x28,0x5f,0x31,0x34,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70, + 0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x32,0x37,0x20,0x2a,0x20, + 0x5f,0x36,0x36,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x30,0x34,0x20,0x3d,0x20,0x5f,0x31, + 0x34,0x2e,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20,0x5f,0x38, + 0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72, + 0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x5f,0x31,0x30,0x34,0x2e,0x7a, + 0x20,0x2f,0x20,0x5f,0x31,0x30,0x34,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f, + 0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x64,0x65, + 0x70,0x74,0x68,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x2d,0x28,0x5f, + 0x31,0x34,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x5f,0x38,0x38,0x29,0x2e,0x7a, + 0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +static inline const sg_shader_desc* depth_only_sphere_prog_shader_desc(sg_backend backend) { + if (backend == SG_BACKEND_GLCORE) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)depth_only_sphere_vs_source_glsl430; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)depth_only_sphere_fs_source_glsl430; + desc.fragment_func.entry = "main"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[0].glsl_name = "in_pos"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[0].glsl_uniforms[0].array_count = 4; + desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_frame"; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 144; + desc.uniform_blocks[1].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[0].array_count = 9; + desc.uniform_blocks[1].glsl_uniforms[0].glsl_name = "ub_pass"; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.glsl_binding_n = 0; + desc.label = "depth_only_sphere_prog_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_D3D11) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)depth_only_sphere_vs_source_hlsl5; + desc.vertex_func.d3d11_target = "vs_5_0"; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)depth_only_sphere_fs_source_hlsl5; + desc.fragment_func.d3d11_target = "ps_5_0"; + desc.fragment_func.entry = "main"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[0].hlsl_sem_name = "TEXCOORD"; + desc.attrs[0].hlsl_sem_index = 0; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].hlsl_register_b_n = 0; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 144; + desc.uniform_blocks[1].hlsl_register_b_n = 1; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.hlsl_register_t_n = 0; + desc.label = "depth_only_sphere_prog_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_METAL_MACOS) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)depth_only_sphere_vs_source_metal_macos; + desc.vertex_func.entry = "main0"; + desc.fragment_func.source = (const char*)depth_only_sphere_fs_source_metal_macos; + desc.fragment_func.entry = "main0"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].msl_buffer_n = 0; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 144; + desc.uniform_blocks[1].msl_buffer_n = 1; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.msl_buffer_n = 8; + desc.label = "depth_only_sphere_prog_shader"; + } + return &desc; + } + return 0; +} diff --git a/samples/shaders/generated/edge.glsl.h b/samples/shaders/generated/edge.glsl.h new file mode 100644 index 0000000..d7bb3d9 --- /dev/null +++ b/samples/shaders/generated/edge.glsl.h @@ -0,0 +1,1384 @@ +#pragma once +/* + #version:1# (machine generated, don't edit!) + + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) + + Cmdline: + sokol-shdc --input E:/box/box3d/samples/shaders/shapes/edge.glsl --output E:/box/box3d/samples/shaders/generated/edge.glsl.h --slang hlsl5:metal_macos:glsl430 + + Overview: + ========= + Shader program: 'edge_overlay': + Get shader desc: edge_edge_overlay_shader_desc(sg_query_backend()); + Vertex Shader: vs + Fragment Shader: fs + Attributes: + Bindings: + Uniform block 'ub_draw': + C struct: edge_ub_draw_t + Bind slot: UB_edge_ub_draw => 2 + Uniform block 'ub_frame': + C struct: edge_ub_frame_t + Bind slot: UB_edge_ub_frame => 0 + Uniform block 'ub_pass': + C struct: edge_ub_pass_t + Bind slot: UB_edge_ub_pass => 1 + Storage buffer 'geom_instances': + C struct: edge_geom_instance_t + Bind slot: VIEW_edge_geom_instances => 0 + Readonly: true + Storage buffer 'edge_endpoints': + C struct: edge_edge_endpoint_t + Bind slot: VIEW_edge_edge_endpoints => 1 + Readonly: true +*/ +#if !defined(SOKOL_GFX_INCLUDED) +#error "Please include sokol_gfx.h before edge.glsl.h" +#endif +#if !defined(SOKOL_SHDC_ALIGN) +#if defined(_MSC_VER) +#define SOKOL_SHDC_ALIGN(a) __declspec(align(a)) +#else +#define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) +#endif +#endif +#define UB_edge_ub_draw (2) +#define UB_edge_ub_frame (0) +#define UB_edge_ub_pass (1) +#define VIEW_edge_geom_instances (0) +#define VIEW_edge_edge_endpoints (1) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct edge_ub_draw_t { + int inst_base[4]; + Vec4 edge_params; +} edge_ub_draw_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct edge_ub_frame_t { + Mat4 view_proj; + Vec4 viewport; +} edge_ub_frame_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct edge_ub_pass_t { + Vec4 convex_color; + Vec4 concave_color; + Vec4 flat_color; +} edge_ub_pass_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct edge_geom_instance_t { + Vec4 xform_row0; + Vec4 xform_row1; + Vec4 xform_row2; + Vec4 base_color; + Vec4 scale; + Vec4 material; +} edge_geom_instance_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct edge_edge_endpoint_t { + Vec4 pos_and_flag; +} edge_edge_endpoint_t; +#pragma pack(pop) +/* + #version 430 + + struct geom_instance + { + vec4 xform_row0; + vec4 xform_row1; + vec4 xform_row2; + vec4 base_color; + vec4 scale; + vec4 material; + }; + + struct edge_endpoint + { + vec4 pos_and_flag; + }; + + layout(binding = 0, std430) readonly buffer geom_instances + { + geom_instance gi_items[]; + } _60; + + struct ub_draw + { + ivec4 inst_base; + vec4 edge_params; + }; + + uniform ub_draw _65; + + layout(binding = 1, std430) readonly buffer edge_endpoints + { + edge_endpoint ee_items[]; + } _95; + + uniform vec4 ub_frame[5]; + layout(location = 0) noperspective out float v_dist_from_axis_px; + layout(location = 1) flat out float v_half_width_px; + layout(location = 2) flat out float v_flag; + + void main() + { + int _16 = int(uint(gl_VertexID) / 6u); + int _22 = gl_VertexID - (_16 * 6); + bool _31 = _22 == 2; + bool _35 = _22 == 4; + float _51 = ((_31 || _35) || (_22 == 5)) ? 1.0 : (-1.0); + int _72 = _65.inst_base.x + gl_InstanceID; + int _97 = 2 * _16; + vec4 _131 = vec4(_95.ee_items[_97].pos_and_flag.xyz * _60.gi_items[_72].scale.xyz, 1.0); + vec4 _157 = vec4(_95.ee_items[_97 + 1].pos_and_flag.xyz * _60.gi_items[_72].scale.xyz, 1.0); + mat4 _183 = mat4(ub_frame[0], ub_frame[1], ub_frame[2], ub_frame[3]); + vec4 _189 = _183 * vec4(dot(_60.gi_items[_72].xform_row0, _131), dot(_60.gi_items[_72].xform_row1, _131), dot(_60.gi_items[_72].xform_row2, _131), 1.0); + vec4 _198 = _183 * vec4(dot(_60.gi_items[_72].xform_row0, _157), dot(_60.gi_items[_72].xform_row1, _157), dot(_60.gi_items[_72].xform_row2, _157), 1.0); + bvec4 _204 = bvec4(((_22 == 1) || _31) || _35); + vec4 _205 = vec4(_204.x ? _198.x : _189.x, _204.y ? _198.y : _189.y, _204.z ? _198.z : _189.z, _204.w ? _198.w : _189.w); + vec2 _245 = ((((_198.xy / vec2(_198.w)) * 0.5) + vec2(0.5)) * ub_frame[4].xy) - ((((_189.xy / vec2(_189.w)) * 0.5) + vec2(0.5)) * ub_frame[4].xy); + float _248 = length(_245); + vec2 _253; + if (_248 > 9.9999999747524270787835121154785e-07) + { + _253 = _245 / vec2(_248); + } + else + { + _253 = vec2(1.0, 0.0); + } + float _277 = max(_65.edge_params.x * 0.5, 0.5); + float _281 = _277 + 1.5; + float _300 = _205.w; + vec2 _304 = _205.xy + ((((vec2(-_253.y, _253.x) * _51) * _281) * (ub_frame[4].zw * 2.0)) * _300); + vec4 _348 = _205; + _348.x = _304.x; + _348.y = _304.y; + _348.z = _205.z + (_65.edge_params.y * _300); + gl_Position = _348; + v_dist_from_axis_px = _51 * _281; + v_half_width_px = _277; + v_flag = _95.ee_items[_97].pos_and_flag.w; + } + +*/ +static const uint8_t edge_vs_source_glsl430[2529] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x67,0x65,0x6f,0x6d,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f, + 0x77,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x62,0x61,0x73, + 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x34,0x20,0x73,0x63,0x61,0x6c,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x34,0x20,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a, + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x65,0x64,0x67,0x65,0x5f,0x65,0x6e,0x64,0x70, + 0x6f,0x69,0x6e,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20, + 0x70,0x6f,0x73,0x5f,0x61,0x6e,0x64,0x5f,0x66,0x6c,0x61,0x67,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67, + 0x20,0x3d,0x20,0x30,0x2c,0x20,0x73,0x74,0x64,0x34,0x33,0x30,0x29,0x20,0x72,0x65, + 0x61,0x64,0x6f,0x6e,0x6c,0x79,0x20,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x67,0x65, + 0x6f,0x6d,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x67,0x65,0x6f,0x6d,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x20,0x67,0x69,0x5f,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5d,0x3b,0x0a,0x7d,0x20,0x5f, + 0x36,0x30,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x64, + 0x72,0x61,0x77,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x76,0x65,0x63,0x34,0x20, + 0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x34,0x20,0x65,0x64,0x67,0x65,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x3b, + 0x0a,0x7d,0x3b,0x0a,0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x75,0x62,0x5f, + 0x64,0x72,0x61,0x77,0x20,0x5f,0x36,0x35,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75, + 0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x31,0x2c,0x20,0x73, + 0x74,0x64,0x34,0x33,0x30,0x29,0x20,0x72,0x65,0x61,0x64,0x6f,0x6e,0x6c,0x79,0x20, + 0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x65,0x64,0x67,0x65,0x5f,0x65,0x6e,0x64,0x70, + 0x6f,0x69,0x6e,0x74,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x65,0x64,0x67,0x65, + 0x5f,0x65,0x6e,0x64,0x70,0x6f,0x69,0x6e,0x74,0x20,0x65,0x65,0x5f,0x69,0x74,0x65, + 0x6d,0x73,0x5b,0x5d,0x3b,0x0a,0x7d,0x20,0x5f,0x39,0x35,0x3b,0x0a,0x0a,0x75,0x6e, + 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x66,0x72, + 0x61,0x6d,0x65,0x5b,0x35,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, + 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6e,0x6f,0x70, + 0x65,0x72,0x73,0x70,0x65,0x63,0x74,0x69,0x76,0x65,0x20,0x6f,0x75,0x74,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x64,0x69,0x73,0x74,0x5f,0x66,0x72,0x6f,0x6d, + 0x5f,0x61,0x78,0x69,0x73,0x5f,0x70,0x78,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, + 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x66, + 0x6c,0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f, + 0x68,0x61,0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x3b,0x0a,0x6c, + 0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d, + 0x20,0x32,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x76,0x5f,0x66,0x6c,0x61,0x67,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64, + 0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e, + 0x74,0x20,0x5f,0x31,0x36,0x20,0x3d,0x20,0x69,0x6e,0x74,0x28,0x75,0x69,0x6e,0x74, + 0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x44,0x29,0x20,0x2f,0x20, + 0x36,0x75,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x32,0x32, + 0x20,0x3d,0x20,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x44,0x20,0x2d, + 0x20,0x28,0x5f,0x31,0x36,0x20,0x2a,0x20,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x33,0x31,0x20,0x3d,0x20,0x5f,0x32,0x32,0x20,0x3d, + 0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x33, + 0x35,0x20,0x3d,0x20,0x5f,0x32,0x32,0x20,0x3d,0x3d,0x20,0x34,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x31,0x20,0x3d,0x20,0x28,0x28, + 0x5f,0x33,0x31,0x20,0x7c,0x7c,0x20,0x5f,0x33,0x35,0x29,0x20,0x7c,0x7c,0x20,0x28, + 0x5f,0x32,0x32,0x20,0x3d,0x3d,0x20,0x35,0x29,0x29,0x20,0x3f,0x20,0x31,0x2e,0x30, + 0x20,0x3a,0x20,0x28,0x2d,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x6e,0x74,0x20,0x5f,0x37,0x32,0x20,0x3d,0x20,0x5f,0x36,0x35,0x2e,0x69,0x6e,0x73, + 0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e, + 0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e, + 0x74,0x20,0x5f,0x39,0x37,0x20,0x3d,0x20,0x32,0x20,0x2a,0x20,0x5f,0x31,0x36,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x31,0x33,0x31,0x20,0x3d, + 0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x39,0x35,0x2e,0x65,0x65,0x5f,0x69,0x74,0x65, + 0x6d,0x73,0x5b,0x5f,0x39,0x37,0x5d,0x2e,0x70,0x6f,0x73,0x5f,0x61,0x6e,0x64,0x5f, + 0x66,0x6c,0x61,0x67,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x5f,0x36,0x30,0x2e,0x67, + 0x69,0x5f,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x37,0x32,0x5d,0x2e,0x73,0x63,0x61, + 0x6c,0x65,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x31,0x35,0x37,0x20,0x3d,0x20,0x76,0x65, + 0x63,0x34,0x28,0x5f,0x39,0x35,0x2e,0x65,0x65,0x5f,0x69,0x74,0x65,0x6d,0x73,0x5b, + 0x5f,0x39,0x37,0x20,0x2b,0x20,0x31,0x5d,0x2e,0x70,0x6f,0x73,0x5f,0x61,0x6e,0x64, + 0x5f,0x66,0x6c,0x61,0x67,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x5f,0x36,0x30,0x2e, + 0x67,0x69,0x5f,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x37,0x32,0x5d,0x2e,0x73,0x63, + 0x61,0x6c,0x65,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6d,0x61,0x74,0x34,0x20,0x5f,0x31,0x38,0x33,0x20,0x3d,0x20,0x6d, + 0x61,0x74,0x34,0x28,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x30,0x5d,0x2c, + 0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x31,0x5d,0x2c,0x20,0x75,0x62, + 0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x32,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72, + 0x61,0x6d,0x65,0x5b,0x33,0x5d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x34,0x20,0x5f,0x31,0x38,0x39,0x20,0x3d,0x20,0x5f,0x31,0x38,0x33,0x20,0x2a,0x20, + 0x76,0x65,0x63,0x34,0x28,0x64,0x6f,0x74,0x28,0x5f,0x36,0x30,0x2e,0x67,0x69,0x5f, + 0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x37,0x32,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d, + 0x5f,0x72,0x6f,0x77,0x30,0x2c,0x20,0x5f,0x31,0x33,0x31,0x29,0x2c,0x20,0x64,0x6f, + 0x74,0x28,0x5f,0x36,0x30,0x2e,0x67,0x69,0x5f,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f, + 0x37,0x32,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2c,0x20, + 0x5f,0x31,0x33,0x31,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x36,0x30,0x2e,0x67, + 0x69,0x5f,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x37,0x32,0x5d,0x2e,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2c,0x20,0x5f,0x31,0x33,0x31,0x29,0x2c,0x20, + 0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f, + 0x31,0x39,0x38,0x20,0x3d,0x20,0x5f,0x31,0x38,0x33,0x20,0x2a,0x20,0x76,0x65,0x63, + 0x34,0x28,0x64,0x6f,0x74,0x28,0x5f,0x36,0x30,0x2e,0x67,0x69,0x5f,0x69,0x74,0x65, + 0x6d,0x73,0x5b,0x5f,0x37,0x32,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f, + 0x77,0x30,0x2c,0x20,0x5f,0x31,0x35,0x37,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f, + 0x36,0x30,0x2e,0x67,0x69,0x5f,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x37,0x32,0x5d, + 0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2c,0x20,0x5f,0x31,0x35, + 0x37,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x36,0x30,0x2e,0x67,0x69,0x5f,0x69, + 0x74,0x65,0x6d,0x73,0x5b,0x5f,0x37,0x32,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f, + 0x72,0x6f,0x77,0x32,0x2c,0x20,0x5f,0x31,0x35,0x37,0x29,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x76,0x65,0x63,0x34,0x20,0x5f,0x32,0x30, + 0x34,0x20,0x3d,0x20,0x62,0x76,0x65,0x63,0x34,0x28,0x28,0x28,0x5f,0x32,0x32,0x20, + 0x3d,0x3d,0x20,0x31,0x29,0x20,0x7c,0x7c,0x20,0x5f,0x33,0x31,0x29,0x20,0x7c,0x7c, + 0x20,0x5f,0x33,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20, + 0x5f,0x32,0x30,0x35,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x32,0x30,0x34, + 0x2e,0x78,0x20,0x3f,0x20,0x5f,0x31,0x39,0x38,0x2e,0x78,0x20,0x3a,0x20,0x5f,0x31, + 0x38,0x39,0x2e,0x78,0x2c,0x20,0x5f,0x32,0x30,0x34,0x2e,0x79,0x20,0x3f,0x20,0x5f, + 0x31,0x39,0x38,0x2e,0x79,0x20,0x3a,0x20,0x5f,0x31,0x38,0x39,0x2e,0x79,0x2c,0x20, + 0x5f,0x32,0x30,0x34,0x2e,0x7a,0x20,0x3f,0x20,0x5f,0x31,0x39,0x38,0x2e,0x7a,0x20, + 0x3a,0x20,0x5f,0x31,0x38,0x39,0x2e,0x7a,0x2c,0x20,0x5f,0x32,0x30,0x34,0x2e,0x77, + 0x20,0x3f,0x20,0x5f,0x31,0x39,0x38,0x2e,0x77,0x20,0x3a,0x20,0x5f,0x31,0x38,0x39, + 0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x32, + 0x34,0x35,0x20,0x3d,0x20,0x28,0x28,0x28,0x28,0x5f,0x31,0x39,0x38,0x2e,0x78,0x79, + 0x20,0x2f,0x20,0x76,0x65,0x63,0x32,0x28,0x5f,0x31,0x39,0x38,0x2e,0x77,0x29,0x29, + 0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x76,0x65,0x63,0x32,0x28,0x30, + 0x2e,0x35,0x29,0x29,0x20,0x2a,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b, + 0x34,0x5d,0x2e,0x78,0x79,0x29,0x20,0x2d,0x20,0x28,0x28,0x28,0x28,0x5f,0x31,0x38, + 0x39,0x2e,0x78,0x79,0x20,0x2f,0x20,0x76,0x65,0x63,0x32,0x28,0x5f,0x31,0x38,0x39, + 0x2e,0x77,0x29,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x76,0x65, + 0x63,0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2a,0x20,0x75,0x62,0x5f,0x66,0x72, + 0x61,0x6d,0x65,0x5b,0x34,0x5d,0x2e,0x78,0x79,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x34,0x38,0x20,0x3d,0x20,0x6c,0x65,0x6e, + 0x67,0x74,0x68,0x28,0x5f,0x32,0x34,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x32,0x20,0x5f,0x32,0x35,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x5f,0x32,0x34,0x38,0x20,0x3e,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39, + 0x39,0x39,0x37,0x34,0x37,0x35,0x32,0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38,0x33, + 0x35,0x31,0x32,0x31,0x31,0x35,0x34,0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x32, + 0x35,0x33,0x20,0x3d,0x20,0x5f,0x32,0x34,0x35,0x20,0x2f,0x20,0x76,0x65,0x63,0x32, + 0x28,0x5f,0x32,0x34,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x5f,0x32,0x35,0x33,0x20,0x3d,0x20,0x76,0x65,0x63,0x32, + 0x28,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x37,0x37, + 0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x5f,0x36,0x35,0x2e,0x65,0x64,0x67,0x65,0x5f, + 0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x2c,0x20, + 0x30,0x2e,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x32,0x38,0x31,0x20,0x3d,0x20,0x5f,0x32,0x37,0x37,0x20,0x2b,0x20,0x31,0x2e, + 0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x33,0x30, + 0x30,0x20,0x3d,0x20,0x5f,0x32,0x30,0x35,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x65,0x63,0x32,0x20,0x5f,0x33,0x30,0x34,0x20,0x3d,0x20,0x5f,0x32,0x30,0x35, + 0x2e,0x78,0x79,0x20,0x2b,0x20,0x28,0x28,0x28,0x28,0x76,0x65,0x63,0x32,0x28,0x2d, + 0x5f,0x32,0x35,0x33,0x2e,0x79,0x2c,0x20,0x5f,0x32,0x35,0x33,0x2e,0x78,0x29,0x20, + 0x2a,0x20,0x5f,0x35,0x31,0x29,0x20,0x2a,0x20,0x5f,0x32,0x38,0x31,0x29,0x20,0x2a, + 0x20,0x28,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x34,0x5d,0x2e,0x7a,0x77, + 0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x29,0x20,0x2a,0x20,0x5f,0x33,0x30,0x30,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x33,0x34,0x38,0x20, + 0x3d,0x20,0x5f,0x32,0x30,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x34,0x38, + 0x2e,0x78,0x20,0x3d,0x20,0x5f,0x33,0x30,0x34,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x5f,0x33,0x34,0x38,0x2e,0x79,0x20,0x3d,0x20,0x5f,0x33,0x30,0x34,0x2e,0x79, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x34,0x38,0x2e,0x7a,0x20,0x3d,0x20,0x5f, + 0x32,0x30,0x35,0x2e,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x36,0x35,0x2e,0x65,0x64,0x67, + 0x65,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x33,0x30, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74, + 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x5f,0x33,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x5f,0x64,0x69,0x73,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x61,0x78,0x69,0x73, + 0x5f,0x70,0x78,0x20,0x3d,0x20,0x5f,0x35,0x31,0x20,0x2a,0x20,0x5f,0x32,0x38,0x31, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x77,0x69,0x64, + 0x74,0x68,0x5f,0x70,0x78,0x20,0x3d,0x20,0x5f,0x32,0x37,0x37,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x5f,0x66,0x6c,0x61,0x67,0x20,0x3d,0x20,0x5f,0x39,0x35,0x2e,0x65, + 0x65,0x5f,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x39,0x37,0x5d,0x2e,0x70,0x6f,0x73, + 0x5f,0x61,0x6e,0x64,0x5f,0x66,0x6c,0x61,0x67,0x2e,0x77,0x3b,0x0a,0x7d,0x0a,0x0a, + 0x00, +}; +/* + #version 430 + + uniform vec4 ub_pass[3]; + layout(location = 0) noperspective in float v_dist_from_axis_px; + layout(location = 1) flat in float v_half_width_px; + layout(location = 2) flat in float v_flag; + layout(location = 0) out vec4 out_color; + + void main() + { + float _15 = fwidth(v_dist_from_axis_px); + vec4 col; + if (v_flag > 1.5) + { + col = ub_pass[2]; + } + else + { + if (v_flag > 0.5) + { + col = ub_pass[0]; + } + else + { + col = ub_pass[1]; + } + } + out_color = col * (1.0 - smoothstep(v_half_width_px - _15, v_half_width_px + _15, abs(v_dist_from_axis_px))); + } + +*/ +static const uint8_t edge_fs_source_glsl430[652] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x75,0x6e, + 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x70,0x61, + 0x73,0x73,0x5b,0x33,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f, + 0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6e,0x6f,0x70,0x65, + 0x72,0x73,0x70,0x65,0x63,0x74,0x69,0x76,0x65,0x20,0x69,0x6e,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x76,0x5f,0x64,0x69,0x73,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x61, + 0x78,0x69,0x73,0x5f,0x70,0x78,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, + 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x66,0x6c,0x61, + 0x74,0x20,0x69,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x68,0x61,0x6c, + 0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x3b,0x0a,0x6c,0x61,0x79,0x6f, + 0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29, + 0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76, + 0x5f,0x66,0x6c,0x61,0x67,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f, + 0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20, + 0x76,0x65,0x63,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a, + 0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x20,0x3d,0x20,0x66, + 0x77,0x69,0x64,0x74,0x68,0x28,0x76,0x5f,0x64,0x69,0x73,0x74,0x5f,0x66,0x72,0x6f, + 0x6d,0x5f,0x61,0x78,0x69,0x73,0x5f,0x70,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x76,0x5f,0x66,0x6c,0x61,0x67,0x20,0x3e,0x20,0x31,0x2e,0x35,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x6f, + 0x6c,0x20,0x3d,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x32,0x5d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x76,0x5f,0x66,0x6c,0x61,0x67,0x20,0x3e,0x20,0x30,0x2e,0x35,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x20,0x3d,0x20,0x75,0x62,0x5f,0x70,0x61, + 0x73,0x73,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x20,0x3d,0x20,0x75,0x62,0x5f,0x70,0x61,0x73, + 0x73,0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30, + 0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x76,0x5f, + 0x68,0x61,0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x20,0x2d,0x20, + 0x5f,0x31,0x35,0x2c,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x77,0x69,0x64,0x74, + 0x68,0x5f,0x70,0x78,0x20,0x2b,0x20,0x5f,0x31,0x35,0x2c,0x20,0x61,0x62,0x73,0x28, + 0x76,0x5f,0x64,0x69,0x73,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x61,0x78,0x69,0x73, + 0x5f,0x70,0x78,0x29,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + struct geom_instance + { + float4 xform_row0; + float4 xform_row1; + float4 xform_row2; + float4 base_color; + float4 scale; + float4 material; + }; + + struct edge_endpoint + { + float4 pos_and_flag; + }; + + ByteAddressBuffer _60 : register(t0); + cbuffer ub_draw : register(b2) + { + int4 _65_inst_base : packoffset(c0); + float4 _65_edge_params : packoffset(c1); + }; + + ByteAddressBuffer _95 : register(t1); + cbuffer ub_frame : register(b0) + { + row_major float4x4 _180_view_proj : packoffset(c0); + float4 _180_viewport : packoffset(c4); + }; + + + static float4 gl_Position; + static int gl_VertexIndex; + static int gl_InstanceIndex; + static float v_dist_from_axis_px; + static float v_half_width_px; + static float v_flag; + + struct SPIRV_Cross_Input + { + uint gl_VertexIndex : SV_VertexID; + uint gl_InstanceIndex : SV_InstanceID; + }; + + struct SPIRV_Cross_Output + { + noperspective float v_dist_from_axis_px : TEXCOORD0; + nointerpolation float v_half_width_px : TEXCOORD1; + nointerpolation float v_flag : TEXCOORD2; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + int _16 = int(uint(gl_VertexIndex) / 6u); + int _22 = gl_VertexIndex - (_16 * 6); + bool _31 = _22 == 2; + bool _35 = _22 == 4; + float _51 = ((_31 || _35) || (_22 == 5)) ? 1.0f : (-1.0f); + geom_instance _75; + _75.xform_row0 = asfloat(_60.Load4((_65_inst_base.x + gl_InstanceIndex) * 96 + 0)); + _75.xform_row1 = asfloat(_60.Load4((_65_inst_base.x + gl_InstanceIndex) * 96 + 16)); + _75.xform_row2 = asfloat(_60.Load4((_65_inst_base.x + gl_InstanceIndex) * 96 + 32)); + _75.base_color = asfloat(_60.Load4((_65_inst_base.x + gl_InstanceIndex) * 96 + 48)); + _75.scale = asfloat(_60.Load4((_65_inst_base.x + gl_InstanceIndex) * 96 + 64)); + _75.material = asfloat(_60.Load4((_65_inst_base.x + gl_InstanceIndex) * 96 + 80)); + int _97 = 2 * _16; + float4 _131 = float4(asfloat(_95.Load4(_97 * 16 + 0)).xyz * _75.scale.xyz, 1.0f); + float4 _157 = float4(asfloat(_95.Load4((_97 + 1) * 16 + 0)).xyz * _75.scale.xyz, 1.0f); + float4 _189 = mul(float4(dot(_75.xform_row0, _131), dot(_75.xform_row1, _131), dot(_75.xform_row2, _131), 1.0f), _180_view_proj); + float4 _198 = mul(float4(dot(_75.xform_row0, _157), dot(_75.xform_row1, _157), dot(_75.xform_row2, _157), 1.0f), _180_view_proj); + bool4 _204 = (((_22 == 1) || _31) || _35).xxxx; + float4 _205 = float4(_204.x ? _198.x : _189.x, _204.y ? _198.y : _189.y, _204.z ? _198.z : _189.z, _204.w ? _198.w : _189.w); + float2 _245 = ((((_198.xy / _198.w.xx) * 0.5f) + 0.5f.xx) * _180_viewport.xy) - ((((_189.xy / _189.w.xx) * 0.5f) + 0.5f.xx) * _180_viewport.xy); + float _248 = length(_245); + float2 _253; + if (_248 > 9.9999999747524270787835121154785e-07f) + { + _253 = _245 / _248.xx; + } + else + { + _253 = float2(1.0f, 0.0f); + } + float _277 = max(_65_edge_params.x * 0.5f, 0.5f); + float _281 = _277 + 1.5f; + float _300 = _205.w; + float2 _304 = _205.xy + ((((float2(-_253.y, _253.x) * _51) * _281) * (_180_viewport.zw * 2.0f)) * _300); + float4 _348 = _205; + _348.x = _304.x; + _348.y = _304.y; + _348.z = _205.z + (_65_edge_params.y * _300); + gl_Position = _348; + v_dist_from_axis_px = _51 * _281; + v_half_width_px = _277; + v_flag = asfloat(_95.Load4(_97 * 16 + 0)).w; + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_VertexIndex = int(stage_input.gl_VertexIndex); + gl_InstanceIndex = int(stage_input.gl_InstanceIndex); + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.v_dist_from_axis_px = v_dist_from_axis_px; + stage_output.v_half_width_px = v_half_width_px; + stage_output.v_flag = v_flag; + return stage_output; + } +*/ +static const uint8_t edge_vs_source_hlsl5[3745] = { + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x67,0x65,0x6f,0x6d,0x5f,0x69,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72, + 0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x63, + 0x61,0x6c,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x65,0x64,0x67,0x65,0x5f,0x65,0x6e,0x64,0x70,0x6f,0x69, + 0x6e,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x70,0x6f,0x73,0x5f,0x61,0x6e,0x64,0x5f,0x66,0x6c,0x61,0x67,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x42,0x79,0x74,0x65,0x41,0x64,0x64,0x72,0x65,0x73,0x73,0x42,0x75,0x66, + 0x66,0x65,0x72,0x20,0x5f,0x36,0x30,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74, + 0x65,0x72,0x28,0x74,0x30,0x29,0x3b,0x0a,0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20, + 0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74, + 0x65,0x72,0x28,0x62,0x32,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74, + 0x34,0x20,0x5f,0x36,0x35,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x20, + 0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36,0x35, + 0x5f,0x65,0x64,0x67,0x65,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x20,0x3a,0x20,0x70, + 0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x29,0x3b,0x0a,0x7d, + 0x3b,0x0a,0x0a,0x42,0x79,0x74,0x65,0x41,0x64,0x64,0x72,0x65,0x73,0x73,0x42,0x75, + 0x66,0x66,0x65,0x72,0x20,0x5f,0x39,0x35,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73, + 0x74,0x65,0x72,0x28,0x74,0x31,0x29,0x3b,0x0a,0x63,0x62,0x75,0x66,0x66,0x65,0x72, + 0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x20,0x3a,0x20,0x72,0x65,0x67,0x69, + 0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78, + 0x34,0x20,0x5f,0x31,0x38,0x30,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a, + 0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31, + 0x38,0x30,0x5f,0x76,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x20,0x3a,0x20,0x70,0x61, + 0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x34,0x29,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x73,0x74, + 0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74, + 0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, + 0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49, + 0x6e,0x64,0x65,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x76,0x5f,0x64,0x69,0x73,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x61, + 0x78,0x69,0x73,0x5f,0x70,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x77,0x69,0x64,0x74, + 0x68,0x5f,0x70,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x76,0x5f,0x66,0x6c,0x61,0x67,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75, + 0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49, + 0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20, + 0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x3a, + 0x20,0x53,0x56,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x44,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x3a,0x20,0x53,0x56,0x5f,0x49,0x6e,0x73, + 0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72, + 0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, + 0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x70, + 0x65,0x72,0x73,0x70,0x65,0x63,0x74,0x69,0x76,0x65,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x76,0x5f,0x64,0x69,0x73,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x61,0x78,0x69, + 0x73,0x5f,0x70,0x78,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c, + 0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x68,0x61, + 0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x20,0x3a,0x20,0x54,0x45, + 0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69, + 0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x76,0x5f,0x66,0x6c,0x61,0x67,0x20,0x3a,0x20,0x54,0x45,0x58,0x43, + 0x4f,0x4f,0x52,0x44,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20, + 0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a, + 0x0a,0x76,0x6f,0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x31,0x36,0x20, + 0x3d,0x20,0x69,0x6e,0x74,0x28,0x75,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x56,0x65, + 0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2f,0x20,0x36,0x75,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x32,0x32,0x20,0x3d,0x20, + 0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x2d, + 0x20,0x28,0x5f,0x31,0x36,0x20,0x2a,0x20,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x33,0x31,0x20,0x3d,0x20,0x5f,0x32,0x32,0x20,0x3d, + 0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x33, + 0x35,0x20,0x3d,0x20,0x5f,0x32,0x32,0x20,0x3d,0x3d,0x20,0x34,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x31,0x20,0x3d,0x20,0x28,0x28, + 0x5f,0x33,0x31,0x20,0x7c,0x7c,0x20,0x5f,0x33,0x35,0x29,0x20,0x7c,0x7c,0x20,0x28, + 0x5f,0x32,0x32,0x20,0x3d,0x3d,0x20,0x35,0x29,0x29,0x20,0x3f,0x20,0x31,0x2e,0x30, + 0x66,0x20,0x3a,0x20,0x28,0x2d,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x67,0x65,0x6f,0x6d,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20,0x5f, + 0x37,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x37,0x35,0x2e,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x30,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74, + 0x28,0x5f,0x36,0x30,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x36,0x35,0x5f, + 0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c, + 0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20, + 0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x5f,0x37,0x35,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x20,0x3d, + 0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x36,0x30,0x2e,0x4c,0x6f,0x61, + 0x64,0x34,0x28,0x28,0x5f,0x36,0x35,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73, + 0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x31, + 0x36,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x37,0x35,0x2e,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61, + 0x74,0x28,0x5f,0x36,0x30,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x36,0x35, + 0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67, + 0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29, + 0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x33,0x32,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x5f,0x37,0x35,0x2e,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x36,0x30,0x2e,0x4c, + 0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x36,0x35,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62, + 0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61, + 0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b, + 0x20,0x34,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x37,0x35,0x2e,0x73, + 0x63,0x61,0x6c,0x65,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f, + 0x36,0x30,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x36,0x35,0x5f,0x69,0x6e, + 0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20, + 0x39,0x36,0x20,0x2b,0x20,0x36,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f, + 0x37,0x35,0x2e,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3d,0x20,0x61,0x73, + 0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x36,0x30,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28, + 0x28,0x5f,0x36,0x35,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78, + 0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e, + 0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x38,0x30,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x39,0x37,0x20,0x3d,0x20, + 0x32,0x20,0x2a,0x20,0x5f,0x31,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x5f,0x31,0x33,0x31,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x28,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x39,0x35,0x2e,0x4c,0x6f, + 0x61,0x64,0x34,0x28,0x5f,0x39,0x37,0x20,0x2a,0x20,0x31,0x36,0x20,0x2b,0x20,0x30, + 0x29,0x29,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x5f,0x37,0x35,0x2e,0x73,0x63,0x61, + 0x6c,0x65,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x35,0x37,0x20,0x3d, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28, + 0x5f,0x39,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x39,0x37,0x20,0x2b, + 0x20,0x31,0x29,0x20,0x2a,0x20,0x31,0x36,0x20,0x2b,0x20,0x30,0x29,0x29,0x2e,0x78, + 0x79,0x7a,0x20,0x2a,0x20,0x5f,0x37,0x35,0x2e,0x73,0x63,0x61,0x6c,0x65,0x2e,0x78, + 0x79,0x7a,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x38,0x39,0x20,0x3d,0x20,0x6d,0x75,0x6c, + 0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x64,0x6f,0x74,0x28,0x5f,0x37,0x35,0x2e, + 0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2c,0x20,0x5f,0x31,0x33,0x31, + 0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x37,0x35,0x2e,0x78,0x66,0x6f,0x72,0x6d, + 0x5f,0x72,0x6f,0x77,0x31,0x2c,0x20,0x5f,0x31,0x33,0x31,0x29,0x2c,0x20,0x64,0x6f, + 0x74,0x28,0x5f,0x37,0x35,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32, + 0x2c,0x20,0x5f,0x31,0x33,0x31,0x29,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20, + 0x5f,0x31,0x38,0x30,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x39,0x38, + 0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x64,0x6f, + 0x74,0x28,0x5f,0x37,0x35,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30, + 0x2c,0x20,0x5f,0x31,0x35,0x37,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x37,0x35, + 0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2c,0x20,0x5f,0x31,0x35, + 0x37,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x37,0x35,0x2e,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2c,0x20,0x5f,0x31,0x35,0x37,0x29,0x2c,0x20,0x31, + 0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f,0x31,0x38,0x30,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x70,0x72,0x6f,0x6a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x34, + 0x20,0x5f,0x32,0x30,0x34,0x20,0x3d,0x20,0x28,0x28,0x28,0x5f,0x32,0x32,0x20,0x3d, + 0x3d,0x20,0x31,0x29,0x20,0x7c,0x7c,0x20,0x5f,0x33,0x31,0x29,0x20,0x7c,0x7c,0x20, + 0x5f,0x33,0x35,0x29,0x2e,0x78,0x78,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x32,0x30,0x35,0x20,0x3d,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x28,0x5f,0x32,0x30,0x34,0x2e,0x78,0x20,0x3f,0x20,0x5f,0x31,0x39, + 0x38,0x2e,0x78,0x20,0x3a,0x20,0x5f,0x31,0x38,0x39,0x2e,0x78,0x2c,0x20,0x5f,0x32, + 0x30,0x34,0x2e,0x79,0x20,0x3f,0x20,0x5f,0x31,0x39,0x38,0x2e,0x79,0x20,0x3a,0x20, + 0x5f,0x31,0x38,0x39,0x2e,0x79,0x2c,0x20,0x5f,0x32,0x30,0x34,0x2e,0x7a,0x20,0x3f, + 0x20,0x5f,0x31,0x39,0x38,0x2e,0x7a,0x20,0x3a,0x20,0x5f,0x31,0x38,0x39,0x2e,0x7a, + 0x2c,0x20,0x5f,0x32,0x30,0x34,0x2e,0x77,0x20,0x3f,0x20,0x5f,0x31,0x39,0x38,0x2e, + 0x77,0x20,0x3a,0x20,0x5f,0x31,0x38,0x39,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x32,0x34,0x35,0x20,0x3d,0x20,0x28, + 0x28,0x28,0x28,0x5f,0x31,0x39,0x38,0x2e,0x78,0x79,0x20,0x2f,0x20,0x5f,0x31,0x39, + 0x38,0x2e,0x77,0x2e,0x78,0x78,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20, + 0x2b,0x20,0x30,0x2e,0x35,0x66,0x2e,0x78,0x78,0x29,0x20,0x2a,0x20,0x5f,0x31,0x38, + 0x30,0x5f,0x76,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x2e,0x78,0x79,0x29,0x20,0x2d, + 0x20,0x28,0x28,0x28,0x28,0x5f,0x31,0x38,0x39,0x2e,0x78,0x79,0x20,0x2f,0x20,0x5f, + 0x31,0x38,0x39,0x2e,0x77,0x2e,0x78,0x78,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66, + 0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2e,0x78,0x78,0x29,0x20,0x2a,0x20,0x5f, + 0x31,0x38,0x30,0x5f,0x76,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x2e,0x78,0x79,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x34,0x38, + 0x20,0x3d,0x20,0x6c,0x65,0x6e,0x67,0x74,0x68,0x28,0x5f,0x32,0x34,0x35,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x32,0x35,0x33, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x32,0x34,0x38,0x20,0x3e, + 0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x35,0x32,0x34, + 0x32,0x37,0x30,0x37,0x38,0x37,0x38,0x33,0x35,0x31,0x32,0x31,0x31,0x35,0x34,0x37, + 0x38,0x35,0x65,0x2d,0x30,0x37,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x32,0x35,0x33,0x20,0x3d,0x20,0x5f,0x32, + 0x34,0x35,0x20,0x2f,0x20,0x5f,0x32,0x34,0x38,0x2e,0x78,0x78,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x32,0x35,0x33,0x20, + 0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x31,0x2e,0x30,0x66,0x2c,0x20,0x30, + 0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x37,0x37,0x20,0x3d,0x20,0x6d,0x61,0x78, + 0x28,0x5f,0x36,0x35,0x5f,0x65,0x64,0x67,0x65,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73, + 0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x2c,0x20,0x30,0x2e,0x35,0x66,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x38,0x31, + 0x20,0x3d,0x20,0x5f,0x32,0x37,0x37,0x20,0x2b,0x20,0x31,0x2e,0x35,0x66,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x33,0x30,0x30,0x20,0x3d, + 0x20,0x5f,0x32,0x30,0x35,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x32,0x20,0x5f,0x33,0x30,0x34,0x20,0x3d,0x20,0x5f,0x32,0x30,0x35,0x2e, + 0x78,0x79,0x20,0x2b,0x20,0x28,0x28,0x28,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28, + 0x2d,0x5f,0x32,0x35,0x33,0x2e,0x79,0x2c,0x20,0x5f,0x32,0x35,0x33,0x2e,0x78,0x29, + 0x20,0x2a,0x20,0x5f,0x35,0x31,0x29,0x20,0x2a,0x20,0x5f,0x32,0x38,0x31,0x29,0x20, + 0x2a,0x20,0x28,0x5f,0x31,0x38,0x30,0x5f,0x76,0x69,0x65,0x77,0x70,0x6f,0x72,0x74, + 0x2e,0x7a,0x77,0x20,0x2a,0x20,0x32,0x2e,0x30,0x66,0x29,0x29,0x20,0x2a,0x20,0x5f, + 0x33,0x30,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x5f,0x33,0x34,0x38,0x20,0x3d,0x20,0x5f,0x32,0x30,0x35,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x5f,0x33,0x34,0x38,0x2e,0x78,0x20,0x3d,0x20,0x5f,0x33,0x30,0x34,0x2e, + 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x34,0x38,0x2e,0x79,0x20,0x3d,0x20, + 0x5f,0x33,0x30,0x34,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x34,0x38, + 0x2e,0x7a,0x20,0x3d,0x20,0x5f,0x32,0x30,0x35,0x2e,0x7a,0x20,0x2b,0x20,0x28,0x5f, + 0x36,0x35,0x5f,0x65,0x64,0x67,0x65,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79, + 0x20,0x2a,0x20,0x5f,0x33,0x30,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c, + 0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x5f,0x33,0x34,0x38, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x64,0x69,0x73,0x74,0x5f,0x66,0x72,0x6f, + 0x6d,0x5f,0x61,0x78,0x69,0x73,0x5f,0x70,0x78,0x20,0x3d,0x20,0x5f,0x35,0x31,0x20, + 0x2a,0x20,0x5f,0x32,0x38,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x68,0x61, + 0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x20,0x3d,0x20,0x5f,0x32, + 0x37,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x66,0x6c,0x61,0x67,0x20,0x3d, + 0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x39,0x35,0x2e,0x4c,0x6f,0x61, + 0x64,0x34,0x28,0x5f,0x39,0x37,0x20,0x2a,0x20,0x31,0x36,0x20,0x2b,0x20,0x30,0x29, + 0x29,0x2e,0x77,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, + 0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28, + 0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75, + 0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e, + 0x64,0x65,0x78,0x20,0x3d,0x20,0x69,0x6e,0x74,0x28,0x73,0x74,0x61,0x67,0x65,0x5f, + 0x69,0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49, + 0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x49,0x6e, + 0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x3d,0x20,0x69,0x6e, + 0x74,0x28,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c, + 0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73, + 0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f, + 0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65, + 0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74, + 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f, + 0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74, + 0x70,0x75,0x74,0x2e,0x76,0x5f,0x64,0x69,0x73,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f, + 0x61,0x78,0x69,0x73,0x5f,0x70,0x78,0x20,0x3d,0x20,0x76,0x5f,0x64,0x69,0x73,0x74, + 0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x61,0x78,0x69,0x73,0x5f,0x70,0x78,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e, + 0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x20, + 0x3d,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70, + 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74, + 0x70,0x75,0x74,0x2e,0x76,0x5f,0x66,0x6c,0x61,0x67,0x20,0x3d,0x20,0x76,0x5f,0x66, + 0x6c,0x61,0x67,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a, + 0x00, +}; +/* + cbuffer ub_pass : register(b1) + { + float4 _40_convex_color : packoffset(c0); + float4 _40_concave_color : packoffset(c1); + float4 _40_flat_color : packoffset(c2); + }; + + + static float v_dist_from_axis_px; + static float v_half_width_px; + static float v_flag; + static float4 out_color; + + struct SPIRV_Cross_Input + { + noperspective float v_dist_from_axis_px : TEXCOORD0; + nointerpolation float v_half_width_px : TEXCOORD1; + nointerpolation float v_flag : TEXCOORD2; + }; + + struct SPIRV_Cross_Output + { + float4 out_color : SV_Target0; + }; + + void frag_main() + { + float _15 = fwidth(v_dist_from_axis_px); + float4 col; + if (v_flag > 1.5f) + { + col = _40_flat_color; + } + else + { + if (v_flag > 0.5f) + { + col = _40_convex_color; + } + else + { + col = _40_concave_color; + } + } + out_color = col * (1.0f - smoothstep(v_half_width_px - _15, v_half_width_px + _15, abs(v_dist_from_axis_px))); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + v_dist_from_axis_px = stage_input.v_dist_from_axis_px; + v_half_width_px = stage_input.v_half_width_px; + v_flag = stage_input.v_flag; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.out_color = out_color; + return stage_output; + } +*/ +static const uint8_t edge_fs_source_hlsl5[1301] = { + 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x31,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x34,0x30,0x5f, + 0x63,0x6f,0x6e,0x76,0x65,0x78,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x70, + 0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x34,0x30,0x5f,0x63,0x6f, + 0x6e,0x63,0x61,0x76,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x70,0x61, + 0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x34,0x30,0x5f,0x66,0x6c,0x61, + 0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66, + 0x66,0x73,0x65,0x74,0x28,0x63,0x32,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x0a,0x73, + 0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x64,0x69, + 0x73,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x61,0x78,0x69,0x73,0x5f,0x70,0x78,0x3b, + 0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f, + 0x68,0x61,0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x3b,0x0a,0x73, + 0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x66,0x6c, + 0x61,0x67,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73, + 0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x70, + 0x65,0x72,0x73,0x70,0x65,0x63,0x74,0x69,0x76,0x65,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x76,0x5f,0x64,0x69,0x73,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x61,0x78,0x69, + 0x73,0x5f,0x70,0x78,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c, + 0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x68,0x61, + 0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x20,0x3a,0x20,0x54,0x45, + 0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69, + 0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x76,0x5f,0x66,0x6c,0x61,0x67,0x20,0x3a,0x20,0x54,0x45,0x58,0x43, + 0x4f,0x4f,0x52,0x44,0x32,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63, + 0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75, + 0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x53,0x56, + 0x5f,0x54,0x61,0x72,0x67,0x65,0x74,0x30,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x6f, + 0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x20,0x3d, + 0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x76,0x5f,0x64,0x69,0x73,0x74,0x5f,0x66, + 0x72,0x6f,0x6d,0x5f,0x61,0x78,0x69,0x73,0x5f,0x70,0x78,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x5f,0x66,0x6c,0x61,0x67,0x20,0x3e,0x20,0x31, + 0x2e,0x35,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x63,0x6f,0x6c,0x20,0x3d,0x20,0x5f,0x34,0x30,0x5f,0x66,0x6c,0x61, + 0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x5f,0x66,0x6c,0x61,0x67, + 0x20,0x3e,0x20,0x30,0x2e,0x35,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63, + 0x6f,0x6c,0x20,0x3d,0x20,0x5f,0x34,0x30,0x5f,0x63,0x6f,0x6e,0x76,0x65,0x78,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x20,0x3d,0x20,0x5f,0x34,0x30,0x5f,0x63,0x6f, + 0x6e,0x63,0x61,0x76,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c, + 0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74, + 0x68,0x73,0x74,0x65,0x70,0x28,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x77,0x69,0x64, + 0x74,0x68,0x5f,0x70,0x78,0x20,0x2d,0x20,0x5f,0x31,0x35,0x2c,0x20,0x76,0x5f,0x68, + 0x61,0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x20,0x2b,0x20,0x5f, + 0x31,0x35,0x2c,0x20,0x61,0x62,0x73,0x28,0x76,0x5f,0x64,0x69,0x73,0x74,0x5f,0x66, + 0x72,0x6f,0x6d,0x5f,0x61,0x78,0x69,0x73,0x5f,0x70,0x78,0x29,0x29,0x29,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f, + 0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56, + 0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x5f,0x64,0x69,0x73,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x61,0x78,0x69,0x73, + 0x5f,0x70,0x78,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75, + 0x74,0x2e,0x76,0x5f,0x64,0x69,0x73,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x61,0x78, + 0x69,0x73,0x5f,0x70,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x68,0x61,0x6c, + 0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x20,0x3d,0x20,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f, + 0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f, + 0x66,0x6c,0x61,0x67,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70, + 0x75,0x74,0x2e,0x76,0x5f,0x66,0x6c,0x61,0x67,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70, + 0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75, + 0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x6f,0x75, + 0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74, + 0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + struct geom_instance + { + float4 xform_row0; + float4 xform_row1; + float4 xform_row2; + float4 base_color; + float4 scale; + float4 material; + }; + + struct geom_instances + { + geom_instance gi_items[1]; + }; + + struct ub_draw + { + int4 inst_base; + float4 edge_params; + }; + + struct edge_endpoint + { + float4 pos_and_flag; + }; + + struct edge_endpoints + { + edge_endpoint ee_items[1]; + }; + + struct ub_frame + { + float4x4 view_proj; + float4 viewport; + }; + + struct main0_out + { + float v_dist_from_axis_px [[user(locn0)]]; + float v_half_width_px [[user(locn1)]]; + float v_flag [[user(locn2)]]; + float4 gl_Position [[position]]; + }; + + vertex main0_out main0(constant ub_frame& _180 [[buffer(0)]], constant ub_draw& _65 [[buffer(2)]], const device geom_instances& _60 [[buffer(8)]], const device edge_endpoints& _95 [[buffer(9)]], uint gl_VertexIndex [[vertex_id]], uint gl_InstanceIndex [[instance_id]]) + { + main0_out out = {}; + int _16 = int(uint(int(gl_VertexIndex)) / 6u); + int _22 = int(gl_VertexIndex) - (_16 * 6); + bool _31 = _22 == 2; + bool _35 = _22 == 4; + float _51 = ((_31 || _35) || (_22 == 5)) ? 1.0 : (-1.0); + int _72 = _65.inst_base.x + int(gl_InstanceIndex); + int _97 = 2 * _16; + float4 _131 = float4(_95.ee_items[_97].pos_and_flag.xyz * _60.gi_items[_72].scale.xyz, 1.0); + float4 _157 = float4(_95.ee_items[_97 + 1].pos_and_flag.xyz * _60.gi_items[_72].scale.xyz, 1.0); + float4 _189 = _180.view_proj * float4(dot(_60.gi_items[_72].xform_row0, _131), dot(_60.gi_items[_72].xform_row1, _131), dot(_60.gi_items[_72].xform_row2, _131), 1.0); + float4 _198 = _180.view_proj * float4(dot(_60.gi_items[_72].xform_row0, _157), dot(_60.gi_items[_72].xform_row1, _157), dot(_60.gi_items[_72].xform_row2, _157), 1.0); + float4 _205 = select(_189, _198, bool4(((_22 == 1) || _31) || _35)); + float2 _245 = ((((_198.xy / float2(_198.w)) * 0.5) + float2(0.5)) * _180.viewport.xy) - ((((_189.xy / float2(_189.w)) * 0.5) + float2(0.5)) * _180.viewport.xy); + float _248 = length(_245); + float2 _253; + if (_248 > 9.9999999747524270787835121154785e-07) + { + _253 = _245 / float2(_248); + } + else + { + _253 = float2(1.0, 0.0); + } + float _277 = fast::max(_65.edge_params.x * 0.5, 0.5); + float _281 = _277 + 1.5; + float _300 = _205.w; + float2 _304 = _205.xy + ((((float2(-_253.y, _253.x) * _51) * _281) * (_180.viewport.zw * 2.0)) * _300); + float4 _348 = _205; + _348.x = _304.x; + _348.y = _304.y; + _348.z = _205.z + (_65.edge_params.y * _300); + out.gl_Position = _348; + out.v_dist_from_axis_px = _51 * _281; + out.v_half_width_px = _277; + out.v_flag = _95.ee_items[_97].pos_and_flag.w; + return out; + } + +*/ +static const uint8_t edge_vs_source_metal_macos[2789] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x67, + 0x65,0x6f,0x6d,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f, + 0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f, + 0x77,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x62, + 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x63,0x61,0x6c,0x65,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c, + 0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x67,0x65,0x6f, + 0x6d,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x67,0x65,0x6f,0x6d,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20, + 0x67,0x69,0x5f,0x69,0x74,0x65,0x6d,0x73,0x5b,0x31,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a, + 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x34,0x20,0x69,0x6e,0x73,0x74,0x5f, + 0x62,0x61,0x73,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x65,0x64,0x67,0x65,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x65,0x64,0x67,0x65,0x5f,0x65,0x6e, + 0x64,0x70,0x6f,0x69,0x6e,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x70,0x6f,0x73,0x5f,0x61,0x6e,0x64,0x5f,0x66,0x6c,0x61,0x67, + 0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x65,0x64,0x67, + 0x65,0x5f,0x65,0x6e,0x64,0x70,0x6f,0x69,0x6e,0x74,0x73,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x65,0x64,0x67,0x65,0x5f,0x65,0x6e,0x64,0x70,0x6f,0x69,0x6e,0x74,0x20, + 0x65,0x65,0x5f,0x69,0x74,0x65,0x6d,0x73,0x5b,0x31,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a, + 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20, + 0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x3b,0x0a, + 0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30, + 0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x76,0x5f,0x64,0x69,0x73,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x61,0x78,0x69, + 0x73,0x5f,0x70,0x78,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e, + 0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x20, + 0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29,0x5d,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x66,0x6c,0x61, + 0x67,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x32,0x29,0x5d, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c, + 0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69, + 0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74, + 0x65,0x78,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69, + 0x6e,0x30,0x28,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x66, + 0x72,0x61,0x6d,0x65,0x26,0x20,0x5f,0x31,0x38,0x30,0x20,0x5b,0x5b,0x62,0x75,0x66, + 0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61, + 0x6e,0x74,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x26,0x20,0x5f,0x36,0x35,0x20, + 0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x32,0x29,0x5d,0x5d,0x2c,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x20,0x67,0x65,0x6f,0x6d, + 0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x26,0x20,0x5f,0x36,0x30,0x20, + 0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x38,0x29,0x5d,0x5d,0x2c,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x20,0x65,0x64,0x67,0x65, + 0x5f,0x65,0x6e,0x64,0x70,0x6f,0x69,0x6e,0x74,0x73,0x26,0x20,0x5f,0x39,0x35,0x20, + 0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x39,0x29,0x5d,0x5d,0x2c,0x20,0x75, + 0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64, + 0x65,0x78,0x20,0x5b,0x5b,0x76,0x65,0x72,0x74,0x65,0x78,0x5f,0x69,0x64,0x5d,0x5d, + 0x2c,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x5b,0x5b,0x69,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x5f,0x69,0x64,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d, + 0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b, + 0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x31,0x36,0x20,0x3d, + 0x20,0x69,0x6e,0x74,0x28,0x75,0x69,0x6e,0x74,0x28,0x69,0x6e,0x74,0x28,0x67,0x6c, + 0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x29,0x29,0x20,0x2f, + 0x20,0x36,0x75,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x32, + 0x32,0x20,0x3d,0x20,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65, + 0x78,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2d,0x20,0x28,0x5f,0x31,0x36,0x20,0x2a, + 0x20,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x33, + 0x31,0x20,0x3d,0x20,0x5f,0x32,0x32,0x20,0x3d,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x33,0x35,0x20,0x3d,0x20,0x5f,0x32,0x32, + 0x20,0x3d,0x3d,0x20,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x35,0x31,0x20,0x3d,0x20,0x28,0x28,0x5f,0x33,0x31,0x20,0x7c,0x7c,0x20, + 0x5f,0x33,0x35,0x29,0x20,0x7c,0x7c,0x20,0x28,0x5f,0x32,0x32,0x20,0x3d,0x3d,0x20, + 0x35,0x29,0x29,0x20,0x3f,0x20,0x31,0x2e,0x30,0x20,0x3a,0x20,0x28,0x2d,0x31,0x2e, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x37,0x32,0x20, + 0x3d,0x20,0x5f,0x36,0x35,0x2e,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e, + 0x78,0x20,0x2b,0x20,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61, + 0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x6e,0x74,0x20,0x5f,0x39,0x37,0x20,0x3d,0x20,0x32,0x20,0x2a,0x20,0x5f,0x31,0x36, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x33, + 0x31,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x39,0x35,0x2e,0x65, + 0x65,0x5f,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x39,0x37,0x5d,0x2e,0x70,0x6f,0x73, + 0x5f,0x61,0x6e,0x64,0x5f,0x66,0x6c,0x61,0x67,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, + 0x5f,0x36,0x30,0x2e,0x67,0x69,0x5f,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x37,0x32, + 0x5d,0x2e,0x73,0x63,0x61,0x6c,0x65,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31, + 0x35,0x37,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x39,0x35,0x2e, + 0x65,0x65,0x5f,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x39,0x37,0x20,0x2b,0x20,0x31, + 0x5d,0x2e,0x70,0x6f,0x73,0x5f,0x61,0x6e,0x64,0x5f,0x66,0x6c,0x61,0x67,0x2e,0x78, + 0x79,0x7a,0x20,0x2a,0x20,0x5f,0x36,0x30,0x2e,0x67,0x69,0x5f,0x69,0x74,0x65,0x6d, + 0x73,0x5b,0x5f,0x37,0x32,0x5d,0x2e,0x73,0x63,0x61,0x6c,0x65,0x2e,0x78,0x79,0x7a, + 0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x5f,0x31,0x38,0x39,0x20,0x3d,0x20,0x5f,0x31,0x38,0x30,0x2e,0x76, + 0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x28,0x64,0x6f,0x74,0x28,0x5f,0x36,0x30,0x2e,0x67,0x69,0x5f,0x69,0x74,0x65, + 0x6d,0x73,0x5b,0x5f,0x37,0x32,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f, + 0x77,0x30,0x2c,0x20,0x5f,0x31,0x33,0x31,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f, + 0x36,0x30,0x2e,0x67,0x69,0x5f,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x37,0x32,0x5d, + 0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2c,0x20,0x5f,0x31,0x33, + 0x31,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x36,0x30,0x2e,0x67,0x69,0x5f,0x69, + 0x74,0x65,0x6d,0x73,0x5b,0x5f,0x37,0x32,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f, + 0x72,0x6f,0x77,0x32,0x2c,0x20,0x5f,0x31,0x33,0x31,0x29,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31, + 0x39,0x38,0x20,0x3d,0x20,0x5f,0x31,0x38,0x30,0x2e,0x76,0x69,0x65,0x77,0x5f,0x70, + 0x72,0x6f,0x6a,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x64,0x6f,0x74, + 0x28,0x5f,0x36,0x30,0x2e,0x67,0x69,0x5f,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x37, + 0x32,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2c,0x20,0x5f, + 0x31,0x35,0x37,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x36,0x30,0x2e,0x67,0x69, + 0x5f,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x37,0x32,0x5d,0x2e,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2c,0x20,0x5f,0x31,0x35,0x37,0x29,0x2c,0x20,0x64, + 0x6f,0x74,0x28,0x5f,0x36,0x30,0x2e,0x67,0x69,0x5f,0x69,0x74,0x65,0x6d,0x73,0x5b, + 0x5f,0x37,0x32,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2c, + 0x20,0x5f,0x31,0x35,0x37,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x32,0x30,0x35,0x20,0x3d,0x20, + 0x73,0x65,0x6c,0x65,0x63,0x74,0x28,0x5f,0x31,0x38,0x39,0x2c,0x20,0x5f,0x31,0x39, + 0x38,0x2c,0x20,0x62,0x6f,0x6f,0x6c,0x34,0x28,0x28,0x28,0x5f,0x32,0x32,0x20,0x3d, + 0x3d,0x20,0x31,0x29,0x20,0x7c,0x7c,0x20,0x5f,0x33,0x31,0x29,0x20,0x7c,0x7c,0x20, + 0x5f,0x33,0x35,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x32,0x20,0x5f,0x32,0x34,0x35,0x20,0x3d,0x20,0x28,0x28,0x28,0x28,0x5f,0x31,0x39, + 0x38,0x2e,0x78,0x79,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x31, + 0x39,0x38,0x2e,0x77,0x29,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2a,0x20,0x5f, + 0x31,0x38,0x30,0x2e,0x76,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x2e,0x78,0x79,0x29, + 0x20,0x2d,0x20,0x28,0x28,0x28,0x28,0x5f,0x31,0x38,0x39,0x2e,0x78,0x79,0x20,0x2f, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x31,0x38,0x39,0x2e,0x77,0x29,0x29, + 0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, + 0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2a,0x20,0x5f,0x31,0x38,0x30,0x2e,0x76,0x69, + 0x65,0x77,0x70,0x6f,0x72,0x74,0x2e,0x78,0x79,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x34,0x38,0x20,0x3d,0x20,0x6c,0x65,0x6e, + 0x67,0x74,0x68,0x28,0x5f,0x32,0x34,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x32,0x35,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x5f,0x32,0x34,0x38,0x20,0x3e,0x20,0x39,0x2e,0x39,0x39,0x39, + 0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x35,0x32,0x34,0x32,0x37,0x30,0x37,0x38,0x37, + 0x38,0x33,0x35,0x31,0x32,0x31,0x31,0x35,0x34,0x37,0x38,0x35,0x65,0x2d,0x30,0x37, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x5f,0x32,0x35,0x33,0x20,0x3d,0x20,0x5f,0x32,0x34,0x35,0x20,0x2f,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x32,0x28,0x5f,0x32,0x34,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x32,0x35,0x33,0x20,0x3d,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x32,0x37,0x37,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d, + 0x61,0x78,0x28,0x5f,0x36,0x35,0x2e,0x65,0x64,0x67,0x65,0x5f,0x70,0x61,0x72,0x61, + 0x6d,0x73,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x2c,0x20,0x30,0x2e,0x35,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x38,0x31, + 0x20,0x3d,0x20,0x5f,0x32,0x37,0x37,0x20,0x2b,0x20,0x31,0x2e,0x35,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x33,0x30,0x30,0x20,0x3d,0x20, + 0x5f,0x32,0x30,0x35,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x32,0x20,0x5f,0x33,0x30,0x34,0x20,0x3d,0x20,0x5f,0x32,0x30,0x35,0x2e,0x78, + 0x79,0x20,0x2b,0x20,0x28,0x28,0x28,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x2d, + 0x5f,0x32,0x35,0x33,0x2e,0x79,0x2c,0x20,0x5f,0x32,0x35,0x33,0x2e,0x78,0x29,0x20, + 0x2a,0x20,0x5f,0x35,0x31,0x29,0x20,0x2a,0x20,0x5f,0x32,0x38,0x31,0x29,0x20,0x2a, + 0x20,0x28,0x5f,0x31,0x38,0x30,0x2e,0x76,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x2e, + 0x7a,0x77,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x29,0x20,0x2a,0x20,0x5f,0x33,0x30, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f, + 0x33,0x34,0x38,0x20,0x3d,0x20,0x5f,0x32,0x30,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x5f,0x33,0x34,0x38,0x2e,0x78,0x20,0x3d,0x20,0x5f,0x33,0x30,0x34,0x2e,0x78,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x34,0x38,0x2e,0x79,0x20,0x3d,0x20,0x5f,0x33, + 0x30,0x34,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x34,0x38,0x2e,0x7a, + 0x20,0x3d,0x20,0x5f,0x32,0x30,0x35,0x2e,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x36,0x35, + 0x2e,0x65,0x64,0x67,0x65,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x20,0x2a, + 0x20,0x5f,0x33,0x30,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e, + 0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x5f,0x33, + 0x34,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x64,0x69, + 0x73,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x61,0x78,0x69,0x73,0x5f,0x70,0x78,0x20, + 0x3d,0x20,0x5f,0x35,0x31,0x20,0x2a,0x20,0x5f,0x32,0x38,0x31,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x77,0x69,0x64, + 0x74,0x68,0x5f,0x70,0x78,0x20,0x3d,0x20,0x5f,0x32,0x37,0x37,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x66,0x6c,0x61,0x67,0x20,0x3d,0x20,0x5f, + 0x39,0x35,0x2e,0x65,0x65,0x5f,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x39,0x37,0x5d, + 0x2e,0x70,0x6f,0x73,0x5f,0x61,0x6e,0x64,0x5f,0x66,0x6c,0x61,0x67,0x2e,0x77,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b, + 0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + struct ub_pass + { + float4 convex_color; + float4 concave_color; + float4 flat_color; + }; + + struct main0_out + { + float4 out_color [[color(0)]]; + }; + + struct main0_in + { + float v_dist_from_axis_px [[user(locn0), center_no_perspective]]; + float v_half_width_px [[user(locn1), flat]]; + float v_flag [[user(locn2), flat]]; + }; + + fragment main0_out main0(main0_in in [[stage_in]], constant ub_pass& _40 [[buffer(1)]]) + { + main0_out out = {}; + float _15 = fwidth(in.v_dist_from_axis_px); + float4 col; + if (in.v_flag > 1.5) + { + col = _40.flat_color; + } + else + { + if (in.v_flag > 0.5) + { + col = _40.convex_color; + } + else + { + col = _40.concave_color; + } + } + out.out_color = col * (1.0 - smoothstep(in.v_half_width_px - _15, in.v_half_width_px + _15, abs(in.v_dist_from_axis_px))); + return out; + } + +*/ +static const uint8_t edge_fs_source_metal_macos[974] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75, + 0x62,0x5f,0x70,0x61,0x73,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x63,0x6f,0x6e,0x76,0x65,0x78,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6e, + 0x63,0x61,0x76,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x6c,0x61,0x74,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61, + 0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b, + 0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a, + 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x64, + 0x69,0x73,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x61,0x78,0x69,0x73,0x5f,0x70,0x78, + 0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x2c,0x20, + 0x63,0x65,0x6e,0x74,0x65,0x72,0x5f,0x6e,0x6f,0x5f,0x70,0x65,0x72,0x73,0x70,0x65, + 0x63,0x74,0x69,0x76,0x65,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f, + 0x70,0x78,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29, + 0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x76,0x5f,0x66,0x6c,0x61,0x67,0x20,0x5b,0x5b,0x75,0x73,0x65, + 0x72,0x28,0x6c,0x6f,0x63,0x6e,0x32,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d, + 0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x20,0x6d, + 0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d, + 0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e, + 0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x34,0x30,0x20,0x5b, + 0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x31,0x29,0x5d,0x5d,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75, + 0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x31,0x35,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x69, + 0x6e,0x2e,0x76,0x5f,0x64,0x69,0x73,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x61,0x78, + 0x69,0x73,0x5f,0x70,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x63,0x6f,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x69,0x6e,0x2e,0x76,0x5f,0x66,0x6c,0x61,0x67,0x20,0x3e,0x20,0x31,0x2e,0x35,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63, + 0x6f,0x6c,0x20,0x3d,0x20,0x5f,0x34,0x30,0x2e,0x66,0x6c,0x61,0x74,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65, + 0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x66,0x6c,0x61,0x67,0x20, + 0x3e,0x20,0x30,0x2e,0x35,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c, + 0x20,0x3d,0x20,0x5f,0x34,0x30,0x2e,0x63,0x6f,0x6e,0x76,0x65,0x78,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x63,0x6f,0x6c,0x20,0x3d,0x20,0x5f,0x34,0x30,0x2e,0x63,0x6f,0x6e,0x63, + 0x61,0x76,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x6f, + 0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63, + 0x6f,0x6c,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f, + 0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x68,0x61,0x6c,0x66, + 0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x20,0x2d,0x20,0x5f,0x31,0x35,0x2c, + 0x20,0x69,0x6e,0x2e,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68, + 0x5f,0x70,0x78,0x20,0x2b,0x20,0x5f,0x31,0x35,0x2c,0x20,0x61,0x62,0x73,0x28,0x69, + 0x6e,0x2e,0x76,0x5f,0x64,0x69,0x73,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x61,0x78, + 0x69,0x73,0x5f,0x70,0x78,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +static inline const sg_shader_desc* edge_edge_overlay_shader_desc(sg_backend backend) { + if (backend == SG_BACKEND_GLCORE) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)edge_vs_source_glsl430; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)edge_fs_source_glsl430; + desc.fragment_func.entry = "main"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 80; + desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[0].glsl_uniforms[0].array_count = 5; + desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_frame"; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 48; + desc.uniform_blocks[1].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[0].array_count = 3; + desc.uniform_blocks[1].glsl_uniforms[0].glsl_name = "ub_pass"; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 32; + desc.uniform_blocks[2].glsl_uniforms[0].type = SG_UNIFORMTYPE_INT4; + desc.uniform_blocks[2].glsl_uniforms[0].array_count = 0; + desc.uniform_blocks[2].glsl_uniforms[0].glsl_name = "_65.inst_base"; + desc.uniform_blocks[2].glsl_uniforms[1].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[2].glsl_uniforms[1].array_count = 0; + desc.uniform_blocks[2].glsl_uniforms[1].glsl_name = "_65.edge_params"; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.glsl_binding_n = 0; + desc.views[1].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[1].storage_buffer.readonly = true; + desc.views[1].storage_buffer.glsl_binding_n = 1; + desc.label = "edge_edge_overlay_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_D3D11) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)edge_vs_source_hlsl5; + desc.vertex_func.d3d11_target = "vs_5_0"; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)edge_fs_source_hlsl5; + desc.fragment_func.d3d11_target = "ps_5_0"; + desc.fragment_func.entry = "main"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 80; + desc.uniform_blocks[0].hlsl_register_b_n = 0; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 48; + desc.uniform_blocks[1].hlsl_register_b_n = 1; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 32; + desc.uniform_blocks[2].hlsl_register_b_n = 2; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.hlsl_register_t_n = 0; + desc.views[1].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[1].storage_buffer.readonly = true; + desc.views[1].storage_buffer.hlsl_register_t_n = 1; + desc.label = "edge_edge_overlay_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_METAL_MACOS) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)edge_vs_source_metal_macos; + desc.vertex_func.entry = "main0"; + desc.fragment_func.source = (const char*)edge_fs_source_metal_macos; + desc.fragment_func.entry = "main0"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 80; + desc.uniform_blocks[0].msl_buffer_n = 0; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 48; + desc.uniform_blocks[1].msl_buffer_n = 1; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 32; + desc.uniform_blocks[2].msl_buffer_n = 2; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.msl_buffer_n = 8; + desc.views[1].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[1].storage_buffer.readonly = true; + desc.views[1].storage_buffer.msl_buffer_n = 9; + desc.label = "edge_edge_overlay_shader"; + } + return &desc; + } + return 0; +} diff --git a/samples/shaders/generated/geom.glsl.h b/samples/shaders/generated/geom.glsl.h new file mode 100644 index 0000000..bf8e457 --- /dev/null +++ b/samples/shaders/generated/geom.glsl.h @@ -0,0 +1,4748 @@ +#pragma once +/* + #version:1# (machine generated, don't edit!) + + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) + + Cmdline: + sokol-shdc --input E:/box/box3d/samples/shaders/shapes/geom.glsl --output E:/box/box3d/samples/shaders/generated/geom.glsl.h --slang hlsl5:metal_macos:glsl430 + + Overview: + ========= + Shader program: 'triangle': + Get shader desc: geom_triangle_shader_desc(sg_query_backend()); + Vertex Shader: vs + Fragment Shader: fs + Attributes: + ATTR_geom_triangle_in_pos => 0 + ATTR_geom_triangle_in_normal => 1 + Bindings: + Uniform block 'ub_draw': + C struct: geom_ub_draw_t + Bind slot: UB_geom_ub_draw => 2 + Uniform block 'ub_frame': + C struct: geom_ub_frame_t + Bind slot: UB_geom_ub_frame => 0 + Uniform block 'ub_pass': + C struct: geom_ub_pass_t + Bind slot: UB_geom_ub_pass => 1 + Storage buffer 'instances': + C struct: geom_instance_t + Bind slot: VIEW_geom_instances => 0 + Readonly: true + Texture 'tex_shadow': + Image type: SG_IMAGETYPE_ARRAY + Sample type: SG_IMAGESAMPLETYPE_DEPTH + Multisampled: false + Bind slot: VIEW_geom_tex_shadow => 1 + Texture 'tex_ao': + Image type: SG_IMAGETYPE_2D + Sample type: SG_IMAGESAMPLETYPE_FLOAT + Multisampled: false + Bind slot: VIEW_geom_tex_ao => 4 + Texture 'tex_ibl_spec': + Image type: SG_IMAGETYPE_CUBE + Sample type: SG_IMAGESAMPLETYPE_FLOAT + Multisampled: false + Bind slot: VIEW_geom_tex_ibl_spec => 2 + Texture 'tex_brdf_lut': + Image type: SG_IMAGETYPE_2D + Sample type: SG_IMAGESAMPLETYPE_FLOAT + Multisampled: false + Bind slot: VIEW_geom_tex_brdf_lut => 3 + Sampler 'smp_shadow': + Type: SG_SAMPLERTYPE_COMPARISON + Bind slot: SMP_geom_smp_shadow => 0 + Sampler 'smp_ao': + Type: SG_SAMPLERTYPE_FILTERING + Bind slot: SMP_geom_smp_ao => 3 + Sampler 'smp_ibl_spec': + Type: SG_SAMPLERTYPE_FILTERING + Bind slot: SMP_geom_smp_ibl_spec => 1 + Sampler 'smp_brdf_lut': + Type: SG_SAMPLERTYPE_FILTERING + Bind slot: SMP_geom_smp_brdf_lut => 2 +*/ +#if !defined(SOKOL_GFX_INCLUDED) +#error "Please include sokol_gfx.h before geom.glsl.h" +#endif +#if !defined(SOKOL_SHDC_ALIGN) +#if defined(_MSC_VER) +#define SOKOL_SHDC_ALIGN(a) __declspec(align(a)) +#else +#define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) +#endif +#endif +#define ATTR_geom_triangle_in_pos (0) +#define ATTR_geom_triangle_in_normal (1) +#define UB_geom_ub_draw (2) +#define UB_geom_ub_frame (0) +#define UB_geom_ub_pass (1) +#define VIEW_geom_instances (0) +#define VIEW_geom_tex_shadow (1) +#define VIEW_geom_tex_ao (4) +#define VIEW_geom_tex_ibl_spec (2) +#define VIEW_geom_tex_brdf_lut (3) +#define SMP_geom_smp_shadow (0) +#define SMP_geom_smp_ao (3) +#define SMP_geom_smp_ibl_spec (1) +#define SMP_geom_smp_brdf_lut (2) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct geom_ub_draw_t { + int inst_base[4]; +} geom_ub_draw_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct geom_ub_frame_t { + Mat4 view_proj; +} geom_ub_frame_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct geom_ub_pass_t { + Vec4 sun_dir_world; + Vec4 sun_color; + int flags[4]; + Vec4 camera_pos; + Mat4 view; + Vec4 cascade_far_view_z; + Mat4 cascade_matrices[3]; + Vec4 sh[9]; + Vec4 ibl_params; +} geom_ub_pass_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct geom_instance_t { + Vec4 xform_row0; + Vec4 xform_row1; + Vec4 xform_row2; + Vec4 base_color; + Vec4 scale; + Vec4 material; +} geom_instance_t; +#pragma pack(pop) +/* + #version 430 + + struct instance + { + vec4 xform_row0; + vec4 xform_row1; + vec4 xform_row2; + vec4 base_color; + vec4 scale; + vec4 material; + }; + + layout(binding = 0, std430) readonly buffer instances + { + instance items[]; + } _15; + + uniform ivec4 ub_draw[1]; + uniform vec4 ub_frame[4]; + layout(location = 0) in vec3 in_pos; + layout(location = 1) in vec3 in_normal; + layout(location = 1) out vec3 v_world_normal; + layout(location = 2) flat out vec4 v_base_color; + layout(location = 3) flat out vec4 v_material; + layout(location = 0) out vec3 v_view_pos; + + void main() + { + int _30 = ub_draw[0].x + gl_InstanceID; + vec4 _68 = vec4(in_pos * _15.items[_30].scale.xyz, 1.0); + float _73 = dot(_15.items[_30].xform_row0, _68); + float _77 = dot(_15.items[_30].xform_row1, _68); + float _81 = dot(_15.items[_30].xform_row2, _68); + vec3 _89 = in_normal / _15.items[_30].scale.xyz; + v_world_normal = vec3(dot(_15.items[_30].xform_row0.xyz, _89), dot(_15.items[_30].xform_row1.xyz, _89), dot(_15.items[_30].xform_row2.xyz, _89)); + v_base_color = _15.items[_30].base_color; + v_material = _15.items[_30].material; + gl_Position = mat4(ub_frame[0], ub_frame[1], ub_frame[2], ub_frame[3]) * vec4(_73, _77, _81, 1.0); + v_view_pos = vec3(_73, _77, _81); + } + +*/ +static const uint8_t geom_vs_source_glsl430[1269] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72, + 0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x63,0x61, + 0x6c,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x6d,0x61,0x74, + 0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75, + 0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x30,0x2c,0x20,0x73, + 0x74,0x64,0x34,0x33,0x30,0x29,0x20,0x72,0x65,0x61,0x64,0x6f,0x6e,0x6c,0x79,0x20, + 0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20, + 0x69,0x74,0x65,0x6d,0x73,0x5b,0x5d,0x3b,0x0a,0x7d,0x20,0x5f,0x31,0x35,0x3b,0x0a, + 0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x69,0x76,0x65,0x63,0x34,0x20,0x75, + 0x62,0x5f,0x64,0x72,0x61,0x77,0x5b,0x31,0x5d,0x3b,0x0a,0x75,0x6e,0x69,0x66,0x6f, + 0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65, + 0x5b,0x34,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63, + 0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, + 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69, + 0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x69,0x6e,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c, + 0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f, + 0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20, + 0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a, + 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20, + 0x3d,0x20,0x32,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x76,0x65, + 0x63,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b, + 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x33,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x76, + 0x65,0x63,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a, + 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20, + 0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f, + 0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20, + 0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74, + 0x20,0x5f,0x33,0x30,0x20,0x3d,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x5b,0x30, + 0x5d,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x49,0x44,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x36, + 0x38,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20, + 0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d, + 0x2e,0x73,0x63,0x61,0x6c,0x65,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31,0x2e,0x30,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x33,0x20, + 0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b, + 0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2c, + 0x20,0x5f,0x36,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x37,0x37,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69, + 0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f, + 0x72,0x6f,0x77,0x31,0x2c,0x20,0x5f,0x36,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x31,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28, + 0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78, + 0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2c,0x20,0x5f,0x36,0x38,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x38,0x39,0x20,0x3d,0x20, + 0x69,0x6e,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x20,0x2f,0x20,0x5f,0x31,0x35,0x2e, + 0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x73,0x63,0x61,0x6c,0x65, + 0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28, + 0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33, + 0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x78,0x79, + 0x7a,0x2c,0x20,0x5f,0x38,0x39,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35, + 0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x38,0x39,0x29, + 0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b, + 0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e, + 0x78,0x79,0x7a,0x2c,0x20,0x5f,0x38,0x39,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x5f, + 0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x62,0x61, + 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f, + 0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69, + 0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x6d,0x61,0x74,0x65,0x72,0x69, + 0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74, + 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x75,0x62,0x5f,0x66,0x72, + 0x61,0x6d,0x65,0x5b,0x30,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65, + 0x5b,0x31,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x32,0x5d, + 0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x33,0x5d,0x29,0x20,0x2a, + 0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x37,0x33,0x2c,0x20,0x5f,0x37,0x37,0x2c,0x20, + 0x5f,0x38,0x31,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x20,0x3d,0x20,0x76,0x65,0x63,0x33, + 0x28,0x5f,0x37,0x33,0x2c,0x20,0x5f,0x37,0x37,0x2c,0x20,0x5f,0x38,0x31,0x29,0x3b, + 0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + #version 430 + + struct ub_pass + { + vec4 sun_dir_world; + vec4 sun_color; + ivec4 flags; + vec4 camera_pos; + mat4 view; + vec4 cascade_far_view_z; + mat4 cascade_matrices[3]; + vec4 sh[9]; + vec4 ibl_params; + }; + + uniform ub_pass _833; + + layout(binding = 0) uniform sampler2D tex_ao_smp_ao; + layout(binding = 1) uniform sampler2DArrayShadow tex_shadow_smp_shadow; + layout(binding = 2) uniform samplerCube tex_ibl_spec_smp_ibl_spec; + layout(binding = 3) uniform sampler2D tex_brdf_lut_smp_brdf_lut; + + layout(location = 1) in vec3 v_world_normal; + layout(location = 0) in vec3 v_view_pos; + layout(location = 0) out vec4 out_color; + layout(location = 2) flat in vec4 v_base_color; + layout(location = 3) flat in vec4 v_material; + + vec3 proceduralGrid(vec2 world_xz, vec3 base_color, float cell_size) + { + vec2 _535 = world_xz / vec2(cell_size); + vec2 _551 = abs(fract(_535 - vec2(0.5)) - vec2(0.5)) / max(fwidth(_535), vec2(9.9999999747524270787835121154785e-07)); + vec2 _566 = world_xz / vec2(cell_size * 10.0); + vec2 _580 = abs(fract(_566 - vec2(0.5)) - vec2(0.5)) / max(fwidth(_566), vec2(9.9999999747524270787835121154785e-07)); + vec2 _611 = max(fwidth(world_xz), vec2(9.9999999747524270787835121154785e-07)); + return mix(mix(mix(mix(base_color, base_color * 0.699999988079071044921875, vec3(1.0 - clamp(min(_551.x, _551.y), 0.0, 1.0))), base_color * 0.3499999940395355224609375, vec3(1.0 - clamp(min(_580.x, _580.y), 0.0, 1.0))), vec3(1.0, 0.0, 0.0), vec3((1.0 - clamp(abs(world_xz.y) / _611.y, 0.0, 1.0)) * step(0.0, world_xz.x))), vec3(0.0, 0.0, 1.0), vec3((1.0 - clamp(abs(world_xz.x) / _611.x, 0.0, 1.0)) * step(0.0, world_xz.y))); + } + + float sampleShadowPCF(int cascade, vec3 light_uv, float bias) + { + float _655 = float(cascade); + float _660 = light_uv.z - bias; + float _676 = light_uv.x - 0.00048828125; + float _680 = light_uv.y - 0.00048828125; + float _710 = light_uv.x + 0.00048828125; + float _778 = light_uv.y + 0.00048828125; + return ((((((((texture(tex_shadow_smp_shadow, vec4(vec4(_676, _680, _655, _660).xyz, _660)) + texture(tex_shadow_smp_shadow, vec4(vec4(light_uv.x, _680, _655, _660).xyz, _660))) + texture(tex_shadow_smp_shadow, vec4(vec4(_710, _680, _655, _660).xyz, _660))) + texture(tex_shadow_smp_shadow, vec4(vec4(_676, light_uv.y, _655, _660).xyz, _660))) + texture(tex_shadow_smp_shadow, vec4(vec4(light_uv.xy, _655, _660).xyz, _660))) + texture(tex_shadow_smp_shadow, vec4(vec4(_710, light_uv.y, _655, _660).xyz, _660))) + texture(tex_shadow_smp_shadow, vec4(vec4(_676, _778, _655, _660).xyz, _660))) + texture(tex_shadow_smp_shadow, vec4(vec4(light_uv.x, _778, _655, _660).xyz, _660))) + texture(tex_shadow_smp_shadow, vec4(vec4(_710, _778, _655, _660).xyz, _660))) * 0.111111111938953399658203125; + } + + float sampleCascade(int cascade, vec3 world_pos, vec3 world_normal) + { + vec4 _843 = _833.cascade_matrices[cascade] * vec4(world_pos, 1.0); + vec3 _850 = _843.xyz / vec3(_843.w); + vec3 _868 = vec3((_850.x * 0.5) + 0.5, ((_850.y * _833.cascade_far_view_z.w) * 0.5) + 0.5, _850.z); + bool _872 = any(lessThan(_868, vec3(0.0))); + bool _879; + if (!_872) + { + _879 = any(greaterThan(_868, vec3(1.0))); + } + else + { + _879 = _872; + } + if (_879) + { + return 1.0; + } + int param = cascade; + vec3 param_1 = _868; + float param_2 = mix(0.0040000001899898052215576171875, 0.0007999999797903001308441162109375, max(dot(world_normal, normalize(_833.sun_dir_world.xyz)), 0.0)); + float pcf = sampleShadowPCF(param, param_1, param_2); + if (cascade == 2) + { + vec2 _911 = _868.xy; + vec2 _916 = min(_911, vec2(1.0) - _911); + pcf = mix(1.0, pcf, clamp(min(_916.x, _916.y) * 10.0, 0.0, 1.0)); + } + return pcf; + } + + float sampleShadowCascaded(vec3 world_pos, vec3 world_normal, float view_z) + { + int cascade = 2; + if (view_z < _833.cascade_far_view_z.x) + { + cascade = 0; + } + else + { + if (view_z < _833.cascade_far_view_z.y) + { + cascade = 1; + } + } + int param = cascade; + vec3 param_1 = world_pos; + vec3 param_2 = world_normal; + float shadow = sampleCascade(param, param_1, param_2); + if (cascade < 2) + { + float _960; + if (cascade == 0) + { + _960 = _833.cascade_far_view_z.x; + } + else + { + _960 = _833.cascade_far_view_z.y; + } + float _972; + if (cascade == 0) + { + _972 = 0.0; + } + else + { + _972 = _833.cascade_far_view_z.x; + } + float _983 = mix(_960, _972, 0.100000001490116119384765625); + if (view_z > _983) + { + int param_3 = cascade + 1; + vec3 param_4 = world_pos; + vec3 param_5 = world_normal; + shadow = mix(shadow, sampleCascade(param_3, param_4, param_5), (view_z - _983) / (_960 - _983)); + } + } + return shadow; + } + + float pbrDistributionGGX(float n_dot_h, float alpha) + { + float _115 = alpha * alpha; + float _124 = ((n_dot_h * n_dot_h) * (_115 - 1.0)) + 1.0; + return _115 / ((3.1415927410125732421875 * _124) * _124); + } + + float pbrVisibilitySmithCorrelated(float n_dot_v, float n_dot_l, float alpha) + { + float _137 = alpha * alpha; + float _144 = 1.0 - _137; + return 0.5 / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _144) + _137)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _144) + _137))) + 9.9999997473787516355514526367188e-06); + } + + vec3 pbrFresnelSchlick(float v_dot_h, vec3 f0) + { + float _173 = 1.0 - v_dot_h; + float _177 = _173 * _173; + return f0 + ((vec3(1.0) - f0) * ((_177 * _177) * _173)); + } + + vec3 brdf_evaluate(vec3 N, vec3 V, vec3 L, vec3 sun_radiance, vec3 base_color, float metallic, float roughness) + { + float _196 = max(dot(N, L), 0.0); + vec3 _207 = normalize(V + L); + float _221 = max(roughness, 0.04500000178813934326171875); + float _225 = _221 * _221; + float param = max(dot(N, _207), 0.0); + float param_1 = _225; + float param_2 = max(dot(N, V), 9.9999997473787516355514526367188e-05); + float param_3 = _196; + float param_4 = _225; + float param_5 = max(dot(V, _207), 0.0); + vec3 param_6 = mix(vec3(0.039999999105930328369140625), base_color, vec3(metallic)); + vec3 _252 = pbrFresnelSchlick(param_5, param_6); + return ((((((vec3(1.0) - _252) * (1.0 - metallic)) * base_color) * vec3(0.3183098733425140380859375)) + (_252 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _196; + } + + vec3 pbrEvaluateShIrradiance(vec3 N, vec4 sh[9]) + { + vec3 _407 = ((((((((sh[0].xyz * 0.2820948064327239990234375) + (sh[1].xyz * ((-0.48860251903533935546875) * N.y))) + (sh[2].xyz * (0.48860251903533935546875 * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125 * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125 * (((3.0 * N.z) * N.z) - 1.0)))) + (sh[7].xyz * (((-1.09254848957061767578125) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625 * ((N.x * N.x) - (N.y * N.y)))); + return _407; + } + + vec3 pbrEvaluateIbl(vec3 N_world, vec3 V_world, vec3 base_color, float metallic, float roughness, vec4 sh[9], float max_lod, samplerCube SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, sampler2D SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut) + { + float _414 = clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05, 1.0); + vec3 _424 = mix(vec3(0.039999999105930328369140625), base_color, vec3(metallic)); + vec3 param = N_world; + vec4 param_1[9] = sh; + vec4 _488 = texture(SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut, vec2(_414, roughness)); + return (((((vec3(1.0) - (_424 + ((max(vec3(1.0 - roughness), _424) - _424) * pow(max(0.0, 1.0 - _414), 5.0)))) * (1.0 - metallic)) * base_color) * max(pbrEvaluateShIrradiance(param, param_1), vec3(0.0))) * vec3(0.3183098733425140380859375)) + (textureLod(SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, reflect(-V_world, N_world), roughness * max_lod).xyz * ((_424 * _488.x) + vec3(_488.y))); + } + + vec3 pbrEvaluateAmbient(bool iblEnabled, vec3 N_world, vec3 V_world, vec3 base_color, float metallic, float roughness, float flat_strength, vec4 sh[9], float max_lod, samplerCube SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, sampler2D SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut) + { + vec3 result = base_color * flat_strength; + if (iblEnabled) + { + vec3 param = N_world; + vec3 param_1 = V_world; + vec3 param_2 = base_color; + float param_3 = metallic; + float param_4 = roughness; + vec4 param_5[9] = sh; + float param_6 = max_lod; + result = pbrEvaluateIbl(param, param_1, param_2, param_3, param_4, param_5, param_6, SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut); + } + return result; + } + + void main() + { + vec3 _1015 = normalize(v_world_normal); + vec3 n_world = _1015; + vec3 _1022 = _833.camera_pos.xyz - v_view_pos; + if (dot(_1015, _1022) < 0.0) + { + n_world = -n_world; + } + if (_833.flags.x == 1) + { + float _1053 = clamp((_833.view * vec4(v_view_pos, 1.0)).z * (-0.0199999995529651641845703125), 0.0, 1.0); + out_color = vec4(_1053, _1053, _1053, 1.0); + return; + } + if (_833.flags.x == 2) + { + vec4 _1071 = vec4(v_view_pos, 1.0); + float _1074 = -(_833.view * _1071).z; + int cascade = 2; + if (_1074 < _833.cascade_far_view_z.x) + { + cascade = 0; + } + else + { + if (_1074 < _833.cascade_far_view_z.y) + { + cascade = 1; + } + } + vec4 _1098 = _833.cascade_matrices[cascade] * _1071; + vec3 _1105 = _1098.xyz / vec3(_1098.w); + vec3 _1122 = vec3((_1105.x * 0.5) + 0.5, ((_1105.y * _833.cascade_far_view_z.w) * 0.5) + 0.5, _1105.z); + bool _1126 = any(lessThan(_1122, vec3(0.0))); + bool _1133; + if (!_1126) + { + _1133 = any(greaterThan(_1122, vec3(1.0))); + } + else + { + _1133 = _1126; + } + vec3 tint = vec3(1.0); + if (!_1133) + { + if (cascade == 0) + { + tint = vec3(1.0, 0.4000000059604644775390625, 0.4000000059604644775390625); + } + else + { + if (cascade == 1) + { + tint = vec3(0.4000000059604644775390625, 1.0, 0.4000000059604644775390625); + } + else + { + tint = vec3(0.4000000059604644775390625, 0.4000000059604644775390625, 1.0); + } + } + } + out_color = vec4(tint, 1.0); + return; + } + if (_833.flags.x == 3) + { + out_color = vec4((normalize((_833.view * vec4(n_world, 0.0)).xyz) * 0.5) + vec3(0.5), 1.0); + return; + } + vec4 _1204 = textureLod(tex_ao_smp_ao, gl_FragCoord.xy / vec2(textureSize(tex_ao_smp_ao, 0)), 0.0); + float _1205 = _1204.x; + if (_833.flags.x == 4) + { + out_color = vec4(_1205, _1205, _1205, 1.0); + return; + } + vec3 baseColor = v_base_color.xyz; + if (v_material.z > 0.5) + { + vec2 param = v_view_pos.xz; + vec3 param_1 = v_base_color.xyz; + float param_2 = v_material.w; + baseColor = mix(v_base_color.xyz, proceduralGrid(param, param_1, param_2), vec3(pow(clamp(n_world.y, 0.0, 1.0), 8.0))); + } + vec3 param_3 = v_view_pos; + vec3 param_4 = n_world; + float param_5 = -(_833.view * vec4(v_view_pos, 1.0)).z; + vec3 _1289 = normalize(_1022); + vec3 param_6 = n_world; + vec3 param_7 = _1289; + vec3 param_8 = normalize(_833.sun_dir_world.xyz); + vec3 param_9 = _833.sun_color.xyz * sampleShadowCascaded(param_3, param_4, param_5); + vec3 param_10 = baseColor; + float param_11 = v_material.x; + float param_12 = v_material.y; + bool param_13 = _833.ibl_params.y > 0.5; + vec3 param_14 = n_world; + vec3 param_15 = _1289; + vec3 param_16 = baseColor; + float param_17 = v_material.x; + float param_18 = v_material.y; + float param_19 = _833.sun_color.w; + vec4 param_20[9]; + param_20[0] = _833.sh[0]; + param_20[1] = _833.sh[1]; + param_20[2] = _833.sh[2]; + param_20[3] = _833.sh[3]; + param_20[4] = _833.sh[4]; + param_20[5] = _833.sh[5]; + param_20[6] = _833.sh[6]; + param_20[7] = _833.sh[7]; + param_20[8] = _833.sh[8]; + float param_21 = _833.ibl_params.x; + out_color = vec4((brdf_evaluate(param_6, param_7, param_8, param_9, param_10, param_11, param_12) + (pbrEvaluateAmbient(param_13, param_14, param_15, param_16, param_17, param_18, param_19, param_20, param_21, tex_ibl_spec_smp_ibl_spec, tex_brdf_lut_smp_brdf_lut) * _1205)) * v_base_color.w, v_base_color.w); + } + +*/ +static const uint8_t geom_fs_source_glsl430[12919] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20, + 0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x76,0x65,0x63,0x34,0x20,0x66,0x6c,0x61,0x67,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x65,0x63,0x34,0x20,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x74,0x34,0x20,0x76,0x69,0x65,0x77,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x6d,0x61,0x74,0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61, + 0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x34,0x20,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a, + 0x7d,0x3b,0x0a,0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x75,0x62,0x5f,0x70, + 0x61,0x73,0x73,0x20,0x5f,0x38,0x33,0x33,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75, + 0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x30,0x29,0x20,0x75, + 0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44, + 0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x5f,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x3b,0x0a, + 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d, + 0x20,0x31,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x72,0x32,0x44,0x41,0x72,0x72,0x61,0x79,0x53,0x68,0x61,0x64,0x6f,0x77, + 0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62, + 0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x32,0x29,0x20,0x75,0x6e,0x69,0x66, + 0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x75,0x62,0x65,0x20, + 0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x5f,0x73,0x6d,0x70, + 0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75, + 0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x33,0x29,0x20,0x75, + 0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44, + 0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x73,0x6d, + 0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x3b,0x0a,0x0a,0x6c,0x61,0x79, + 0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31, + 0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, + 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69, + 0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f, + 0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69, + 0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34, + 0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f, + 0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29, + 0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x5f, + 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f, + 0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x33,0x29, + 0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x5f, + 0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20, + 0x70,0x72,0x6f,0x63,0x65,0x64,0x75,0x72,0x61,0x6c,0x47,0x72,0x69,0x64,0x28,0x76, + 0x65,0x63,0x32,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x78,0x7a,0x2c,0x20,0x76,0x65, + 0x63,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x63,0x65,0x6c,0x6c,0x5f,0x73,0x69,0x7a,0x65,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x35,0x33,0x35,0x20, + 0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x78,0x7a,0x20,0x2f,0x20,0x76,0x65,0x63, + 0x32,0x28,0x63,0x65,0x6c,0x6c,0x5f,0x73,0x69,0x7a,0x65,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x35,0x35,0x31,0x20,0x3d,0x20,0x61,0x62, + 0x73,0x28,0x66,0x72,0x61,0x63,0x74,0x28,0x5f,0x35,0x33,0x35,0x20,0x2d,0x20,0x76, + 0x65,0x63,0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2d,0x20,0x76,0x65,0x63,0x32, + 0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2f,0x20,0x6d,0x61,0x78,0x28,0x66,0x77,0x69, + 0x64,0x74,0x68,0x28,0x5f,0x35,0x33,0x35,0x29,0x2c,0x20,0x76,0x65,0x63,0x32,0x28, + 0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x35,0x32,0x34,0x32, + 0x37,0x30,0x37,0x38,0x37,0x38,0x33,0x35,0x31,0x32,0x31,0x31,0x35,0x34,0x37,0x38, + 0x35,0x65,0x2d,0x30,0x37,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x32,0x20,0x5f,0x35,0x36,0x36,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x78, + 0x7a,0x20,0x2f,0x20,0x76,0x65,0x63,0x32,0x28,0x63,0x65,0x6c,0x6c,0x5f,0x73,0x69, + 0x7a,0x65,0x20,0x2a,0x20,0x31,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x65,0x63,0x32,0x20,0x5f,0x35,0x38,0x30,0x20,0x3d,0x20,0x61,0x62,0x73,0x28, + 0x66,0x72,0x61,0x63,0x74,0x28,0x5f,0x35,0x36,0x36,0x20,0x2d,0x20,0x76,0x65,0x63, + 0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2d,0x20,0x76,0x65,0x63,0x32,0x28,0x30, + 0x2e,0x35,0x29,0x29,0x20,0x2f,0x20,0x6d,0x61,0x78,0x28,0x66,0x77,0x69,0x64,0x74, + 0x68,0x28,0x5f,0x35,0x36,0x36,0x29,0x2c,0x20,0x76,0x65,0x63,0x32,0x28,0x39,0x2e, + 0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x35,0x32,0x34,0x32,0x37,0x30, + 0x37,0x38,0x37,0x38,0x33,0x35,0x31,0x32,0x31,0x31,0x35,0x34,0x37,0x38,0x35,0x65, + 0x2d,0x30,0x37,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20, + 0x5f,0x36,0x31,0x31,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x66,0x77,0x69,0x64,0x74, + 0x68,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x78,0x7a,0x29,0x2c,0x20,0x76,0x65,0x63, + 0x32,0x28,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x35,0x32, + 0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38,0x33,0x35,0x31,0x32,0x31,0x31,0x35,0x34, + 0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x6d,0x69,0x78,0x28,0x6d,0x69,0x78,0x28,0x6d,0x69, + 0x78,0x28,0x6d,0x69,0x78,0x28,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x30, + 0x2e,0x36,0x39,0x39,0x39,0x39,0x39,0x39,0x38,0x38,0x30,0x37,0x39,0x30,0x37,0x31, + 0x30,0x34,0x34,0x39,0x32,0x31,0x38,0x37,0x35,0x2c,0x20,0x76,0x65,0x63,0x33,0x28, + 0x31,0x2e,0x30,0x20,0x2d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6d,0x69,0x6e,0x28, + 0x5f,0x35,0x35,0x31,0x2e,0x78,0x2c,0x20,0x5f,0x35,0x35,0x31,0x2e,0x79,0x29,0x2c, + 0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x29,0x2c,0x20,0x62,0x61, + 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x30,0x2e,0x33,0x34,0x39, + 0x39,0x39,0x39,0x39,0x39,0x34,0x30,0x33,0x39,0x35,0x33,0x35,0x35,0x32,0x32,0x34, + 0x36,0x30,0x39,0x33,0x37,0x35,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30, + 0x20,0x2d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6d,0x69,0x6e,0x28,0x5f,0x35,0x38, + 0x30,0x2e,0x78,0x2c,0x20,0x5f,0x35,0x38,0x30,0x2e,0x79,0x29,0x2c,0x20,0x30,0x2e, + 0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x29,0x2c,0x20,0x76,0x65,0x63,0x33,0x28, + 0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x29,0x2c,0x20, + 0x76,0x65,0x63,0x33,0x28,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x63,0x6c,0x61,0x6d, + 0x70,0x28,0x61,0x62,0x73,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x78,0x7a,0x2e,0x79, + 0x29,0x20,0x2f,0x20,0x5f,0x36,0x31,0x31,0x2e,0x79,0x2c,0x20,0x30,0x2e,0x30,0x2c, + 0x20,0x31,0x2e,0x30,0x29,0x29,0x20,0x2a,0x20,0x73,0x74,0x65,0x70,0x28,0x30,0x2e, + 0x30,0x2c,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x78,0x7a,0x2e,0x78,0x29,0x29,0x29, + 0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c, + 0x20,0x31,0x2e,0x30,0x29,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x28,0x31,0x2e,0x30, + 0x20,0x2d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x61,0x62,0x73,0x28,0x77,0x6f,0x72, + 0x6c,0x64,0x5f,0x78,0x7a,0x2e,0x78,0x29,0x20,0x2f,0x20,0x5f,0x36,0x31,0x31,0x2e, + 0x78,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x20,0x2a,0x20, + 0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30,0x2c,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x78,0x7a,0x2e,0x79,0x29,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43, + 0x46,0x28,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x76, + 0x65,0x63,0x33,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x62,0x69,0x61,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x35,0x35,0x20,0x3d,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x36,0x30,0x20,0x3d,0x20,0x6c,0x69, + 0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x7a,0x20,0x2d,0x20,0x62,0x69,0x61,0x73,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x37,0x36,0x20, + 0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20,0x2d,0x20,0x30, + 0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x38,0x30,0x20,0x3d,0x20,0x6c, + 0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x20,0x2d,0x20,0x30,0x2e,0x30,0x30, + 0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x31,0x30,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68, + 0x74,0x5f,0x75,0x76,0x2e,0x78,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38, + 0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x37,0x37,0x38,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75, + 0x76,0x2e,0x79,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38, + 0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28, + 0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34, + 0x28,0x5f,0x36,0x37,0x36,0x2c,0x20,0x5f,0x36,0x38,0x30,0x2c,0x20,0x5f,0x36,0x35, + 0x35,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x36, + 0x36,0x30,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74, + 0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68, + 0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28, + 0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20,0x5f,0x36,0x38,0x30, + 0x2c,0x20,0x5f,0x36,0x35,0x35,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x2e,0x78,0x79, + 0x7a,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78, + 0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f, + 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34, + 0x28,0x76,0x65,0x63,0x34,0x28,0x5f,0x37,0x31,0x30,0x2c,0x20,0x5f,0x36,0x38,0x30, + 0x2c,0x20,0x5f,0x36,0x35,0x35,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x2e,0x78,0x79, + 0x7a,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78, + 0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f, + 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34, + 0x28,0x76,0x65,0x63,0x34,0x28,0x5f,0x36,0x37,0x36,0x2c,0x20,0x6c,0x69,0x67,0x68, + 0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x5f,0x36,0x35,0x35,0x2c,0x20,0x5f,0x36, + 0x36,0x30,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x29,0x29, + 0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x6c,0x69,0x67,0x68, + 0x74,0x5f,0x75,0x76,0x2e,0x78,0x79,0x2c,0x20,0x5f,0x36,0x35,0x35,0x2c,0x20,0x5f, + 0x36,0x36,0x30,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x29, + 0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x5f,0x37,0x31, + 0x30,0x2c,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x5f, + 0x36,0x35,0x35,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20, + 0x5f,0x36,0x36,0x30,0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72, + 0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65, + 0x63,0x34,0x28,0x5f,0x36,0x37,0x36,0x2c,0x20,0x5f,0x37,0x37,0x38,0x2c,0x20,0x5f, + 0x36,0x35,0x35,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20, + 0x5f,0x36,0x36,0x30,0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72, + 0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65, + 0x63,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20,0x5f, + 0x37,0x37,0x38,0x2c,0x20,0x5f,0x36,0x35,0x35,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29, + 0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x29,0x29,0x20,0x2b,0x20, + 0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76, + 0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x5f,0x37,0x31,0x30,0x2c,0x20,0x5f, + 0x37,0x37,0x38,0x2c,0x20,0x5f,0x36,0x35,0x35,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29, + 0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x29,0x29,0x20,0x2a,0x20, + 0x30,0x2e,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x39,0x33,0x38,0x39,0x35, + 0x33,0x33,0x39,0x39,0x36,0x35,0x38,0x32,0x30,0x33,0x31,0x32,0x35,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61, + 0x73,0x63,0x61,0x64,0x65,0x28,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f, + 0x73,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f, + 0x72,0x6d,0x61,0x6c,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34, + 0x20,0x5f,0x38,0x34,0x33,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x2e,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x5d,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x38,0x35,0x30,0x20,0x3d,0x20,0x5f, + 0x38,0x34,0x33,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x76,0x65,0x63,0x33,0x28,0x5f, + 0x38,0x34,0x33,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, + 0x20,0x5f,0x38,0x36,0x38,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x28,0x5f,0x38, + 0x35,0x30,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e, + 0x35,0x2c,0x20,0x28,0x28,0x5f,0x38,0x35,0x30,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x38, + 0x33,0x33,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20, + 0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x38,0x35,0x30,0x2e,0x7a,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x38,0x37,0x32,0x20,0x3d,0x20, + 0x61,0x6e,0x79,0x28,0x6c,0x65,0x73,0x73,0x54,0x68,0x61,0x6e,0x28,0x5f,0x38,0x36, + 0x38,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x38,0x37,0x39,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x38,0x37,0x32,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x37,0x39, + 0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x67,0x72,0x65,0x61,0x74,0x65,0x72,0x54,0x68, + 0x61,0x6e,0x28,0x5f,0x38,0x36,0x38,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e, + 0x30,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x5f,0x38,0x37,0x39,0x20,0x3d,0x20,0x5f,0x38,0x37,0x32,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x38, + 0x37,0x39,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20, + 0x5f,0x38,0x36,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x30,0x2e, + 0x30,0x30,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x38,0x39,0x39,0x38,0x39,0x38, + 0x30,0x35,0x32,0x32,0x31,0x35,0x35,0x37,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x2c, + 0x20,0x30,0x2e,0x30,0x30,0x30,0x37,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x39,0x37, + 0x39,0x30,0x33,0x30,0x30,0x31,0x33,0x30,0x38,0x34,0x34,0x31,0x31,0x36,0x32,0x31, + 0x30,0x39,0x33,0x37,0x35,0x2c,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x77, + 0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x6e,0x6f,0x72, + 0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x38,0x33,0x33,0x2e,0x73,0x75,0x6e,0x5f, + 0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x29,0x29,0x2c, + 0x20,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68, + 0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x39,0x31,0x31,0x20, + 0x3d,0x20,0x5f,0x38,0x36,0x38,0x2e,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x39,0x31,0x36,0x20,0x3d,0x20,0x6d, + 0x69,0x6e,0x28,0x5f,0x39,0x31,0x31,0x2c,0x20,0x76,0x65,0x63,0x32,0x28,0x31,0x2e, + 0x30,0x29,0x20,0x2d,0x20,0x5f,0x39,0x31,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x31,0x2e, + 0x30,0x2c,0x20,0x70,0x63,0x66,0x2c,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6d,0x69, + 0x6e,0x28,0x5f,0x39,0x31,0x36,0x2e,0x78,0x2c,0x20,0x5f,0x39,0x31,0x36,0x2e,0x79, + 0x29,0x20,0x2a,0x20,0x31,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31, + 0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x70,0x63,0x66,0x3b,0x0a,0x7d,0x0a,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f, + 0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x76,0x65,0x63,0x33,0x20,0x77, + 0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x77, + 0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x76,0x69,0x65,0x77,0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x32, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a, + 0x20,0x3c,0x20,0x5f,0x38,0x33,0x33,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, + 0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a, + 0x20,0x3c,0x20,0x5f,0x38,0x33,0x33,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, + 0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x31,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d, + 0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x77,0x6f,0x72, + 0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64, + 0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x20,0x3c,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x36, + 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x5f,0x39,0x36,0x30,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x2e,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x5f,0x39,0x36,0x30,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x2e,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a, + 0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x37,0x32, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x5f,0x39,0x37,0x32,0x20,0x3d,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x39,0x37,0x32,0x20, + 0x3d,0x20,0x5f,0x38,0x33,0x33,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66, + 0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x38,0x33,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28, + 0x5f,0x39,0x36,0x30,0x2c,0x20,0x5f,0x39,0x37,0x32,0x2c,0x20,0x30,0x2e,0x31,0x30, + 0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x34,0x39,0x30,0x31,0x31,0x36,0x31,0x31,0x39, + 0x33,0x38,0x34,0x37,0x36,0x35,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3e, + 0x20,0x5f,0x39,0x38,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x20,0x2b,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, + 0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e, + 0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61, + 0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x29, + 0x2c,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x2d,0x20,0x5f,0x39,0x38,0x33, + 0x29,0x20,0x2f,0x20,0x28,0x5f,0x39,0x36,0x30,0x20,0x2d,0x20,0x5f,0x39,0x38,0x33, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47, + 0x47,0x58,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x35,0x20, + 0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x34,0x20, + 0x3d,0x20,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x20,0x2a,0x20,0x6e,0x5f, + 0x64,0x6f,0x74,0x5f,0x68,0x29,0x20,0x2a,0x20,0x28,0x5f,0x31,0x31,0x35,0x20,0x2d, + 0x20,0x31,0x2e,0x30,0x29,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x31,0x35,0x20,0x2f,0x20, + 0x28,0x28,0x33,0x2e,0x31,0x34,0x31,0x35,0x39,0x32,0x37,0x34,0x31,0x30,0x31,0x32, + 0x35,0x37,0x33,0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x20,0x2a,0x20,0x5f,0x31,0x32, + 0x34,0x29,0x20,0x2a,0x20,0x5f,0x31,0x32,0x34,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69, + 0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65, + 0x64,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x37,0x20,0x3d,0x20, + 0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x34,0x20,0x3d,0x20, + 0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f,0x31,0x33,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x30,0x2e,0x35,0x20,0x2f,0x20,0x28,0x28,0x28, + 0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28, + 0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74, + 0x5f,0x76,0x29,0x20,0x2a,0x20,0x5f,0x31,0x34,0x34,0x29,0x20,0x2b,0x20,0x5f,0x31, + 0x33,0x37,0x29,0x29,0x20,0x2b,0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20, + 0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c, + 0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x29,0x20,0x2a,0x20,0x5f,0x31, + 0x34,0x34,0x29,0x20,0x2b,0x20,0x5f,0x31,0x33,0x37,0x29,0x29,0x29,0x20,0x2b,0x20, + 0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35, + 0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38, + 0x38,0x65,0x2d,0x30,0x36,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20, + 0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63, + 0x6b,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c, + 0x20,0x76,0x65,0x63,0x33,0x20,0x66,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x37,0x33,0x20,0x3d,0x20,0x31,0x2e,0x30, + 0x20,0x2d,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x37,0x37,0x20,0x3d,0x20,0x5f,0x31,0x37, + 0x33,0x20,0x2a,0x20,0x5f,0x31,0x37,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x66,0x30,0x20,0x2b,0x20,0x28,0x28,0x76,0x65,0x63,0x33, + 0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x66,0x30,0x29,0x20,0x2a,0x20,0x28,0x28, + 0x5f,0x31,0x37,0x37,0x20,0x2a,0x20,0x5f,0x31,0x37,0x37,0x29,0x20,0x2a,0x20,0x5f, + 0x31,0x37,0x33,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x62, + 0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x76,0x65,0x63, + 0x33,0x20,0x4e,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x56,0x2c,0x20,0x76,0x65,0x63, + 0x33,0x20,0x4c,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61, + 0x64,0x69,0x61,0x6e,0x63,0x65,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x62,0x61,0x73, + 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d, + 0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72, + 0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x39,0x36,0x20,0x3d,0x20,0x6d,0x61,0x78, + 0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x4c,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x32,0x30,0x37,0x20, + 0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x56,0x20,0x2b,0x20, + 0x4c,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32, + 0x32,0x31,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65, + 0x73,0x73,0x2c,0x20,0x30,0x2e,0x30,0x34,0x35,0x30,0x30,0x30,0x30,0x30,0x31,0x37, + 0x38,0x38,0x31,0x33,0x39,0x33,0x34,0x33,0x32,0x36,0x31,0x37,0x31,0x38,0x37,0x35, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x32, + 0x35,0x20,0x3d,0x20,0x5f,0x32,0x32,0x31,0x20,0x2a,0x20,0x5f,0x32,0x32,0x31,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x5f,0x32, + 0x30,0x37,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f, + 0x32,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74, + 0x28,0x4e,0x2c,0x20,0x56,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39, + 0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34, + 0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x20,0x3d,0x20,0x5f,0x31,0x39,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x32, + 0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28, + 0x56,0x2c,0x20,0x5f,0x32,0x30,0x37,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36, + 0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x33, + 0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38, + 0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c,0x20,0x62,0x61,0x73,0x65, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x6d,0x65,0x74, + 0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x33,0x20,0x5f,0x32,0x35,0x32,0x20,0x3d,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73, + 0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x76, + 0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x32,0x35,0x32,0x29, + 0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c, + 0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x33,0x31,0x38,0x33, + 0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38, + 0x35,0x39,0x33,0x37,0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x5f,0x32,0x35,0x32,0x20, + 0x2a,0x20,0x28,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69, + 0x6f,0x6e,0x47,0x47,0x58,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x29,0x20,0x2a,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62, + 0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c, + 0x61,0x74,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29,0x29, + 0x29,0x29,0x20,0x2a,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63, + 0x65,0x29,0x20,0x2a,0x20,0x5f,0x31,0x39,0x36,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65, + 0x63,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68, + 0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x76,0x65,0x63,0x33,0x20, + 0x4e,0x2c,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x34,0x30,0x37,0x20,0x3d, + 0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x73,0x68,0x5b,0x30,0x5d,0x2e,0x78, + 0x79,0x7a,0x20,0x2a,0x20,0x30,0x2e,0x32,0x38,0x32,0x30,0x39,0x34,0x38,0x30,0x36, + 0x34,0x33,0x32,0x37,0x32,0x33,0x39,0x39,0x39,0x30,0x32,0x33,0x34,0x33,0x37,0x35, + 0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a, + 0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30, + 0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a, + 0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x32,0x5d, + 0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32, + 0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37, + 0x35,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68, + 0x5b,0x33,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34, + 0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35, + 0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x29,0x29, + 0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x34,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, + 0x28,0x28,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30, + 0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x20,0x2a,0x20,0x4e,0x2e, + 0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73, + 0x68,0x5b,0x35,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31, + 0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37, + 0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29, + 0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b, + 0x36,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x33,0x31,0x35,0x33, + 0x39,0x31,0x35,0x37,0x30,0x33,0x32,0x39,0x36,0x36,0x36,0x31,0x33,0x37,0x36,0x39, + 0x35,0x33,0x31,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x28,0x33,0x2e,0x30,0x20,0x2a, + 0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2d,0x20,0x31, + 0x2e,0x30,0x29,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x37,0x5d,0x2e, + 0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35, + 0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38, + 0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e, + 0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x38,0x5d,0x2e,0x78,0x79, + 0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x35,0x34,0x36,0x32,0x37,0x34,0x32,0x34,0x34, + 0x37,0x38,0x35,0x33,0x30,0x38,0x38,0x33,0x37,0x38,0x39,0x30,0x36,0x32,0x35,0x20, + 0x2a,0x20,0x28,0x28,0x4e,0x2e,0x78,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2d, + 0x20,0x28,0x4e,0x2e,0x79,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x34,0x30,0x37, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61, + 0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x76,0x65,0x63,0x33,0x20,0x4e,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x56,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61, + 0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67, + 0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39, + 0x5d,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64, + 0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x75,0x62,0x65,0x20,0x53,0x50, + 0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e, + 0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x73, + 0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x61, + 0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, + 0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f, + 0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66, + 0x5f,0x6c,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x34,0x31,0x34,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x64, + 0x6f,0x74,0x28,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x56,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34, + 0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32, + 0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x34,0x32,0x34, + 0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x33, + 0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38, + 0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c,0x20,0x62,0x61,0x73,0x65, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x6d,0x65,0x74, + 0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x5b,0x39,0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x34,0x38,0x38,0x20,0x3d,0x20,0x74,0x65,0x78, + 0x74,0x75,0x72,0x65,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73, + 0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x62,0x72,0x64, + 0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75, + 0x74,0x2c,0x20,0x76,0x65,0x63,0x32,0x28,0x5f,0x34,0x31,0x34,0x2c,0x20,0x72,0x6f, + 0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x76,0x65,0x63,0x33,0x28, + 0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x28,0x5f,0x34,0x32,0x34,0x20,0x2b,0x20,0x28, + 0x28,0x6d,0x61,0x78,0x28,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20, + 0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x2c,0x20,0x5f,0x34,0x32,0x34, + 0x29,0x20,0x2d,0x20,0x5f,0x34,0x32,0x34,0x29,0x20,0x2a,0x20,0x70,0x6f,0x77,0x28, + 0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f, + 0x34,0x31,0x34,0x29,0x2c,0x20,0x35,0x2e,0x30,0x29,0x29,0x29,0x29,0x20,0x2a,0x20, + 0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29, + 0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20, + 0x2a,0x20,0x6d,0x61,0x78,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74, + 0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x70,0x61, + 0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x2c,0x20,0x76, + 0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x29,0x20,0x2a,0x20,0x76,0x65,0x63, + 0x33,0x28,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32, + 0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x29,0x29,0x20, + 0x2b,0x20,0x28,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x4c,0x6f,0x64,0x28,0x53,0x50, + 0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e, + 0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x73, + 0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x72,0x65, + 0x66,0x6c,0x65,0x63,0x74,0x28,0x2d,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20, + 0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e, + 0x65,0x73,0x73,0x20,0x2a,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x2e,0x78, + 0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x34,0x32,0x34,0x20,0x2a,0x20,0x5f,0x34, + 0x38,0x38,0x2e,0x78,0x29,0x20,0x2b,0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x34,0x38, + 0x38,0x2e,0x79,0x29,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20, + 0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65, + 0x6e,0x74,0x28,0x62,0x6f,0x6f,0x6c,0x20,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c, + 0x65,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20, + 0x76,0x65,0x63,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72, + 0x65,0x6e,0x67,0x74,0x68,0x2c,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39, + 0x5d,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64, + 0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x75,0x62,0x65,0x20,0x53,0x50, + 0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e, + 0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x73, + 0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x61, + 0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, + 0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f, + 0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66, + 0x5f,0x6c,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, + 0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65, + 0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x62, + 0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x20,0x3d,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69, + 0x63,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x72,0x6f,0x75,0x67,0x68, + 0x6e,0x65,0x73,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x5b,0x39,0x5d,0x20,0x3d,0x20, + 0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x61,0x78,0x5f, + 0x6c,0x6f,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x73, + 0x75,0x6c,0x74,0x20,0x3d,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74, + 0x65,0x49,0x62,0x6c,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36, + 0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f, + 0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63, + 0x75,0x62,0x65,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65, + 0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f, + 0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, + 0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69, + 0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x33,0x20,0x5f,0x31,0x30,0x31,0x35,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d, + 0x61,0x6c,0x69,0x7a,0x65,0x28,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f, + 0x72,0x6d,0x61,0x6c,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, + 0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x5f,0x31,0x30,0x31,0x35,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x30,0x32,0x32,0x20, + 0x3d,0x20,0x5f,0x38,0x33,0x33,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f, + 0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70, + 0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x64,0x6f,0x74,0x28, + 0x5f,0x31,0x30,0x31,0x35,0x2c,0x20,0x5f,0x31,0x30,0x32,0x32,0x29,0x20,0x3c,0x20, + 0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x2d,0x6e,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x5f,0x38,0x33,0x33,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e, + 0x78,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35, + 0x33,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x28,0x5f,0x38,0x33,0x33,0x2e, + 0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x2e,0x7a,0x20, + 0x2a,0x20,0x28,0x2d,0x30,0x2e,0x30,0x31,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x35, + 0x35,0x32,0x39,0x36,0x35,0x31,0x36,0x34,0x31,0x38,0x34,0x35,0x37,0x30,0x33,0x31, + 0x32,0x35,0x29,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x31,0x30,0x35,0x33,0x2c,0x20, + 0x5f,0x31,0x30,0x35,0x33,0x2c,0x20,0x5f,0x31,0x30,0x35,0x33,0x2c,0x20,0x31,0x2e, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x5f,0x38,0x33,0x33,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d, + 0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x31,0x30,0x37,0x31,0x20,0x3d,0x20, + 0x76,0x65,0x63,0x34,0x28,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2c, + 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x37,0x34,0x20,0x3d,0x20,0x2d,0x28,0x5f, + 0x38,0x33,0x33,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x5f,0x31,0x30,0x37,0x31, + 0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74, + 0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x30,0x37,0x34,0x20, + 0x3c,0x20,0x5f,0x38,0x33,0x33,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66, + 0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x5f,0x31,0x30,0x37,0x34,0x20,0x3c,0x20,0x5f,0x38,0x33,0x33,0x2e,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a, + 0x2e,0x79,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x34,0x20,0x5f,0x31,0x30,0x39,0x38,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33, + 0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65, + 0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x20,0x2a,0x20,0x5f,0x31,0x30, + 0x37,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, + 0x20,0x5f,0x31,0x31,0x30,0x35,0x20,0x3d,0x20,0x5f,0x31,0x30,0x39,0x38,0x2e,0x78, + 0x79,0x7a,0x20,0x2f,0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x31,0x30,0x39,0x38,0x2e, + 0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, + 0x20,0x5f,0x31,0x31,0x32,0x32,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x28,0x5f, + 0x31,0x31,0x30,0x35,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20, + 0x30,0x2e,0x35,0x2c,0x20,0x28,0x28,0x5f,0x31,0x31,0x30,0x35,0x2e,0x79,0x20,0x2a, + 0x20,0x5f,0x38,0x33,0x33,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61, + 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e, + 0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x31,0x31,0x30,0x35,0x2e, + 0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c, + 0x20,0x5f,0x31,0x31,0x32,0x36,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x6c,0x65,0x73, + 0x73,0x54,0x68,0x61,0x6e,0x28,0x5f,0x31,0x31,0x32,0x32,0x2c,0x20,0x76,0x65,0x63, + 0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x33,0x33,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x31,0x32,0x36, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x33,0x33,0x20,0x3d,0x20, + 0x61,0x6e,0x79,0x28,0x67,0x72,0x65,0x61,0x74,0x65,0x72,0x54,0x68,0x61,0x6e,0x28, + 0x5f,0x31,0x31,0x32,0x32,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x5f,0x31,0x31,0x33,0x33,0x20,0x3d,0x20,0x5f,0x31,0x31,0x32,0x36,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x76,0x65, + 0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x31,0x33,0x33,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d, + 0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x31, + 0x2e,0x30,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39, + 0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c, + 0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34, + 0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28, + 0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36, + 0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30, + 0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30, + 0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e, + 0x74,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30, + 0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39, + 0x30,0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30, + 0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32, + 0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x74,0x69,0x6e,0x74, + 0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x38,0x33,0x33,0x2e,0x66,0x6c,0x61,0x67,0x73, + 0x2e,0x78,0x20,0x3d,0x3d,0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x28,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69, + 0x7a,0x65,0x28,0x28,0x5f,0x38,0x33,0x33,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20, + 0x76,0x65,0x63,0x34,0x28,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x30,0x2e, + 0x30,0x29,0x29,0x2e,0x78,0x79,0x7a,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20, + 0x2b,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x35,0x29,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x34,0x20,0x5f,0x31,0x32,0x30,0x34,0x20,0x3d,0x20,0x74,0x65,0x78,0x74,0x75,0x72, + 0x65,0x4c,0x6f,0x64,0x28,0x74,0x65,0x78,0x5f,0x61,0x6f,0x5f,0x73,0x6d,0x70,0x5f, + 0x61,0x6f,0x2c,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64, + 0x2e,0x78,0x79,0x20,0x2f,0x20,0x76,0x65,0x63,0x32,0x28,0x74,0x65,0x78,0x74,0x75, + 0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x74,0x65,0x78,0x5f,0x61,0x6f,0x5f,0x73,0x6d, + 0x70,0x5f,0x61,0x6f,0x2c,0x20,0x30,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x30,0x35, + 0x20,0x3d,0x20,0x5f,0x31,0x32,0x30,0x34,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x5f,0x38,0x33,0x33,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78, + 0x20,0x3d,0x3d,0x20,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, + 0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x31,0x32,0x30,0x35,0x2c,0x20,0x5f,0x31,0x32, + 0x30,0x35,0x2c,0x20,0x5f,0x31,0x32,0x30,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, + 0x62,0x61,0x73,0x65,0x43,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61, + 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c, + 0x2e,0x7a,0x20,0x3e,0x20,0x30,0x2e,0x35,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x20,0x3d,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2e, + 0x78,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73, + 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e, + 0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x61,0x73,0x65,0x43, + 0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x76,0x5f,0x62,0x61,0x73, + 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x70,0x72,0x6f, + 0x63,0x65,0x64,0x75,0x72,0x61,0x6c,0x47,0x72,0x69,0x64,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x29,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x70,0x6f,0x77,0x28,0x63, + 0x6c,0x61,0x6d,0x70,0x28,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x79,0x2c,0x20, + 0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x2c,0x20,0x38,0x2e,0x30,0x29,0x29, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x76,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x6e,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x2d,0x28,0x5f,0x38,0x33,0x33,0x2e,0x76, + 0x69,0x65,0x77,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x5f,0x76,0x69,0x65, + 0x77,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x2e,0x7a,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x32,0x38,0x39,0x20,0x3d, + 0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31,0x30,0x32,0x32, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20, + 0x3d,0x20,0x5f,0x31,0x32,0x38,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d, + 0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x38,0x33,0x33,0x2e,0x73,0x75,0x6e,0x5f,0x64, + 0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20, + 0x3d,0x20,0x5f,0x38,0x33,0x33,0x2e,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61, + 0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x62,0x61,0x73,0x65, + 0x43,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61, + 0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x76, + 0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x62,0x6f,0x6f,0x6c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d, + 0x20,0x5f,0x38,0x33,0x33,0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73, + 0x2e,0x79,0x20,0x3e,0x20,0x30,0x2e,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x6e,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x5f,0x31,0x32,0x38,0x39, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x36,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x43,0x6f,0x6c,0x6f,0x72,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x37,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c, + 0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72, + 0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33, + 0x2e,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b, + 0x39,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30, + 0x5b,0x30,0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x2e,0x73,0x68,0x5b,0x30,0x5d, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x31, + 0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x2e,0x73,0x68,0x5b,0x31,0x5d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x32,0x5d,0x20, + 0x3d,0x20,0x5f,0x38,0x33,0x33,0x2e,0x73,0x68,0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x33,0x5d,0x20,0x3d,0x20, + 0x5f,0x38,0x33,0x33,0x2e,0x73,0x68,0x5b,0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x34,0x5d,0x20,0x3d,0x20,0x5f,0x38, + 0x33,0x33,0x2e,0x73,0x68,0x5b,0x34,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x35,0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33, + 0x2e,0x73,0x68,0x5b,0x35,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x30,0x5b,0x36,0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x2e,0x73, + 0x68,0x5b,0x36,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x30,0x5b,0x37,0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x2e,0x73,0x68,0x5b, + 0x37,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30, + 0x5b,0x38,0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x2e,0x73,0x68,0x5b,0x38,0x5d, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x31,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x2e,0x69,0x62,0x6c,0x5f, + 0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75, + 0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x28, + 0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x29,0x20, + 0x2b,0x20,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d, + 0x62,0x69,0x65,0x6e,0x74,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x2c,0x20, + 0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x5f,0x73,0x6d,0x70, + 0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62, + 0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66, + 0x5f,0x6c,0x75,0x74,0x29,0x20,0x2a,0x20,0x5f,0x31,0x32,0x30,0x35,0x29,0x29,0x20, + 0x2a,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77, + 0x2c,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77, + 0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + struct instance + { + float4 xform_row0; + float4 xform_row1; + float4 xform_row2; + float4 base_color; + float4 scale; + float4 material; + }; + + ByteAddressBuffer _15 : register(t0); + cbuffer ub_draw : register(b2) + { + int4 _21_inst_base : packoffset(c0); + }; + + cbuffer ub_frame : register(b0) + { + row_major float4x4 _125_view_proj : packoffset(c0); + }; + + + static float4 gl_Position; + static int gl_InstanceIndex; + static float3 in_pos; + static float3 in_normal; + static float3 v_world_normal; + static float4 v_base_color; + static float4 v_material; + static float3 v_view_pos; + + struct SPIRV_Cross_Input + { + float3 in_pos : TEXCOORD0; + float3 in_normal : TEXCOORD1; + uint gl_InstanceIndex : SV_InstanceID; + }; + + struct SPIRV_Cross_Output + { + float3 v_view_pos : TEXCOORD0; + float3 v_world_normal : TEXCOORD1; + nointerpolation float4 v_base_color : TEXCOORD2; + nointerpolation float4 v_material : TEXCOORD3; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + instance _33; + _33.xform_row0 = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 0)); + _33.xform_row1 = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 16)); + _33.xform_row2 = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 32)); + _33.base_color = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 48)); + _33.scale = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 64)); + _33.material = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 80)); + float4 _68 = float4(in_pos * _33.scale.xyz, 1.0f); + float _73 = dot(_33.xform_row0, _68); + float _77 = dot(_33.xform_row1, _68); + float _81 = dot(_33.xform_row2, _68); + float3 _89 = in_normal / _33.scale.xyz; + v_world_normal = float3(dot(_33.xform_row0.xyz, _89), dot(_33.xform_row1.xyz, _89), dot(_33.xform_row2.xyz, _89)); + v_base_color = _33.base_color; + v_material = _33.material; + gl_Position = mul(float4(_73, _77, _81, 1.0f), _125_view_proj); + v_view_pos = float3(_73, _77, _81); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_InstanceIndex = int(stage_input.gl_InstanceIndex); + in_pos = stage_input.in_pos; + in_normal = stage_input.in_normal; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.v_world_normal = v_world_normal; + stage_output.v_base_color = v_base_color; + stage_output.v_material = v_material; + stage_output.v_view_pos = v_view_pos; + return stage_output; + } +*/ +static const uint8_t geom_vs_source_hlsl5[2542] = { + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d, + 0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x63,0x61,0x6c,0x65,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6d,0x61,0x74,0x65,0x72, + 0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x42,0x79,0x74,0x65,0x41,0x64,0x64, + 0x72,0x65,0x73,0x73,0x42,0x75,0x66,0x66,0x65,0x72,0x20,0x5f,0x31,0x35,0x20,0x3a, + 0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x30,0x29,0x3b,0x0a,0x63, + 0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x20,0x3a, + 0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x32,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x34,0x20,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73, + 0x74,0x5f,0x62,0x61,0x73,0x65,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66, + 0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x63,0x62,0x75, + 0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x20,0x3a,0x20, + 0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x31,0x32,0x35,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65, + 0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x0a,0x73,0x74,0x61,0x74, + 0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73, + 0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e, + 0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64, + 0x65,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b, + 0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76, + 0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x73,0x74,0x61, + 0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74, + 0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b, + 0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, + 0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x3a, + 0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c, + 0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x3a,0x20,0x53,0x56,0x5f,0x49,0x6e,0x73, + 0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72, + 0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, + 0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x20,0x3a, + 0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e, + 0x6f,0x72,0x6d,0x61,0x6c,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44, + 0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f, + 0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f, + 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x54,0x45,0x58, + 0x43,0x4f,0x4f,0x52,0x44,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e, + 0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3a,0x20, + 0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f, + 0x6e,0x20,0x3a,0x20,0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b, + 0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d, + 0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x20,0x5f,0x33,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33, + 0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x20,0x3d,0x20,0x61, + 0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34, + 0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e, + 0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49, + 0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x30,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f, + 0x72,0x6f,0x77,0x31,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f, + 0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e, + 0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20, + 0x39,0x36,0x20,0x2b,0x20,0x31,0x36,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f, + 0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x20,0x3d,0x20, + 0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64, + 0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65, + 0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x33,0x32, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x62,0x61,0x73,0x65, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74, + 0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f, + 0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c, + 0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20, + 0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x34,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x5f,0x33,0x33,0x2e,0x73,0x63,0x61,0x6c,0x65,0x20,0x3d,0x20,0x61,0x73,0x66, + 0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28, + 0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20, + 0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64, + 0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x36,0x34,0x29,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x6d,0x61,0x74,0x65,0x72,0x69,0x61, + 0x6c,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e, + 0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f, + 0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20, + 0x2b,0x20,0x38,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x5f,0x36,0x38,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, + 0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x2a,0x20,0x5f,0x33,0x33,0x2e,0x73,0x63,0x61, + 0x6c,0x65,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x33,0x20,0x3d,0x20,0x64, + 0x6f,0x74,0x28,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77, + 0x30,0x2c,0x20,0x5f,0x36,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x37,0x37,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x33,0x33, + 0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2c,0x20,0x5f,0x36,0x38, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x31, + 0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d, + 0x5f,0x72,0x6f,0x77,0x32,0x2c,0x20,0x5f,0x36,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x38,0x39,0x20,0x3d,0x20,0x69,0x6e, + 0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x20,0x2f,0x20,0x5f,0x33,0x33,0x2e,0x73,0x63, + 0x61,0x6c,0x65,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x28,0x64,0x6f,0x74,0x28,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x38,0x39, + 0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d, + 0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x38,0x39,0x29,0x2c, + 0x20,0x64,0x6f,0x74,0x28,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72, + 0x6f,0x77,0x32,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x38,0x39,0x29,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x3d,0x20,0x5f,0x33,0x33,0x2e,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61, + 0x6c,0x20,0x3d,0x20,0x5f,0x33,0x33,0x2e,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f, + 0x6e,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f, + 0x37,0x33,0x2c,0x20,0x5f,0x37,0x37,0x2c,0x20,0x5f,0x38,0x31,0x2c,0x20,0x31,0x2e, + 0x30,0x66,0x29,0x2c,0x20,0x5f,0x31,0x32,0x35,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70, + 0x72,0x6f,0x6a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x76,0x69,0x65,0x77, + 0x5f,0x70,0x6f,0x73,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x37, + 0x33,0x2c,0x20,0x5f,0x37,0x37,0x2c,0x20,0x5f,0x38,0x31,0x29,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74, + 0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, + 0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65, + 0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c, + 0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x3d, + 0x20,0x69,0x6e,0x74,0x28,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74, + 0x2e,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65, + 0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x3d, + 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x69,0x6e,0x5f, + 0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x5f,0x6e,0x6f,0x72,0x6d, + 0x61,0x6c,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74, + 0x2e,0x69,0x6e,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74, + 0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70, + 0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d, + 0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x20,0x3d,0x20, + 0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74, + 0x2e,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20, + 0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76, + 0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61, + 0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67, + 0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x70,0x6f,0x73,0x20,0x3d,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + cbuffer ub_pass : register(b1) + { + float4 _833_sun_dir_world : packoffset(c0); + float4 _833_sun_color : packoffset(c1); + int4 _833_flags : packoffset(c2); + float4 _833_camera_pos : packoffset(c3); + row_major float4x4 _833_view : packoffset(c4); + float4 _833_cascade_far_view_z : packoffset(c8); + row_major float4x4 _833_cascade_matrices[3] : packoffset(c9); + float4 _833_sh[9] : packoffset(c21); + float4 _833_ibl_params : packoffset(c30); + }; + + Texture2DArray tex_shadow : register(t0); + SamplerComparisonState smp_shadow : register(s0); + Texture2D tex_ao : register(t3); + SamplerState smp_ao : register(s3); + TextureCube tex_ibl_spec : register(t1); + SamplerState smp_ibl_spec : register(s1); + Texture2D tex_brdf_lut : register(t2); + SamplerState smp_brdf_lut : register(s2); + + static float4 gl_FragCoord; + static float3 v_world_normal; + static float3 v_view_pos; + static float4 out_color; + static float4 v_base_color; + static float4 v_material; + + struct SPIRV_Cross_Input + { + float3 v_view_pos : TEXCOORD0; + float3 v_world_normal : TEXCOORD1; + nointerpolation float4 v_base_color : TEXCOORD2; + nointerpolation float4 v_material : TEXCOORD3; + float4 gl_FragCoord : SV_Position; + }; + + struct SPIRV_Cross_Output + { + float4 out_color : SV_Target0; + }; + + uint2 spvTextureSize(Texture2D Tex, uint Level, out uint Param) + { + uint2 ret; + Tex.GetDimensions(Level, ret.x, ret.y, Param); + return ret; + } + + float3 proceduralGrid(float2 world_xz, float3 base_color, float cell_size) + { + float2 _535 = world_xz / cell_size.xx; + float2 _551 = abs(frac(_535 - 0.5f.xx) - 0.5f.xx) / max(fwidth(_535), 9.9999999747524270787835121154785e-07f.xx); + float2 _566 = world_xz / (cell_size * 10.0f).xx; + float2 _580 = abs(frac(_566 - 0.5f.xx) - 0.5f.xx) / max(fwidth(_566), 9.9999999747524270787835121154785e-07f.xx); + float2 _611 = max(fwidth(world_xz), 9.9999999747524270787835121154785e-07f.xx); + return lerp(lerp(lerp(lerp(base_color, base_color * 0.699999988079071044921875f, (1.0f - clamp(min(_551.x, _551.y), 0.0f, 1.0f)).xxx), base_color * 0.3499999940395355224609375f, (1.0f - clamp(min(_580.x, _580.y), 0.0f, 1.0f)).xxx), float3(1.0f, 0.0f, 0.0f), ((1.0f - clamp(abs(world_xz.y) / _611.y, 0.0f, 1.0f)) * step(0.0f, world_xz.x)).xxx), float3(0.0f, 0.0f, 1.0f), ((1.0f - clamp(abs(world_xz.x) / _611.x, 0.0f, 1.0f)) * step(0.0f, world_xz.y)).xxx); + } + + float sampleShadowPCF(int cascade, float3 light_uv, float bias) + { + float _655 = float(cascade); + float _660 = light_uv.z - bias; + float _676 = light_uv.x - 0.00048828125f; + float _680 = light_uv.y - 0.00048828125f; + float _710 = light_uv.x + 0.00048828125f; + float _778 = light_uv.y + 0.00048828125f; + return ((((((((tex_shadow.SampleCmp(smp_shadow, float4(_676, _680, _655, _660).xyz, _660) + tex_shadow.SampleCmp(smp_shadow, float4(light_uv.x, _680, _655, _660).xyz, _660)) + tex_shadow.SampleCmp(smp_shadow, float4(_710, _680, _655, _660).xyz, _660)) + tex_shadow.SampleCmp(smp_shadow, float4(_676, light_uv.y, _655, _660).xyz, _660)) + tex_shadow.SampleCmp(smp_shadow, float4(light_uv.xy, _655, _660).xyz, _660)) + tex_shadow.SampleCmp(smp_shadow, float4(_710, light_uv.y, _655, _660).xyz, _660)) + tex_shadow.SampleCmp(smp_shadow, float4(_676, _778, _655, _660).xyz, _660)) + tex_shadow.SampleCmp(smp_shadow, float4(light_uv.x, _778, _655, _660).xyz, _660)) + tex_shadow.SampleCmp(smp_shadow, float4(_710, _778, _655, _660).xyz, _660)) * 0.111111111938953399658203125f; + } + + float sampleCascade(int cascade, float3 world_pos, float3 world_normal) + { + float4 _843 = mul(float4(world_pos, 1.0f), _833_cascade_matrices[cascade]); + float3 _850 = _843.xyz / _843.w.xxx; + float3 _868 = float3((_850.x * 0.5f) + 0.5f, ((_850.y * _833_cascade_far_view_z.w) * 0.5f) + 0.5f, _850.z); + bool _872 = any(bool3(_868.x < 0.0f.xxx.x, _868.y < 0.0f.xxx.y, _868.z < 0.0f.xxx.z)); + bool _879; + if (!_872) + { + _879 = any(bool3(_868.x > 1.0f.xxx.x, _868.y > 1.0f.xxx.y, _868.z > 1.0f.xxx.z)); + } + else + { + _879 = _872; + } + if (_879) + { + return 1.0f; + } + int param = cascade; + float3 param_1 = _868; + float param_2 = lerp(0.0040000001899898052215576171875f, 0.0007999999797903001308441162109375f, max(dot(world_normal, normalize(_833_sun_dir_world.xyz)), 0.0f)); + float pcf = sampleShadowPCF(param, param_1, param_2); + if (cascade == 2) + { + float2 _911 = _868.xy; + float2 _916 = min(_911, 1.0f.xx - _911); + pcf = lerp(1.0f, pcf, clamp(min(_916.x, _916.y) * 10.0f, 0.0f, 1.0f)); + } + return pcf; + } + + float sampleShadowCascaded(float3 world_pos, float3 world_normal, float view_z) + { + int cascade = 2; + if (view_z < _833_cascade_far_view_z.x) + { + cascade = 0; + } + else + { + if (view_z < _833_cascade_far_view_z.y) + { + cascade = 1; + } + } + int param = cascade; + float3 param_1 = world_pos; + float3 param_2 = world_normal; + float shadow = sampleCascade(param, param_1, param_2); + if (cascade < 2) + { + float _960; + if (cascade == 0) + { + _960 = _833_cascade_far_view_z.x; + } + else + { + _960 = _833_cascade_far_view_z.y; + } + float _972; + if (cascade == 0) + { + _972 = 0.0f; + } + else + { + _972 = _833_cascade_far_view_z.x; + } + float _983 = lerp(_960, _972, 0.100000001490116119384765625f); + if (view_z > _983) + { + int param_3 = cascade + 1; + float3 param_4 = world_pos; + float3 param_5 = world_normal; + shadow = lerp(shadow, sampleCascade(param_3, param_4, param_5), (view_z - _983) / (_960 - _983)); + } + } + return shadow; + } + + float pbrDistributionGGX(float n_dot_h, float alpha) + { + float _115 = alpha * alpha; + float _124 = ((n_dot_h * n_dot_h) * (_115 - 1.0f)) + 1.0f; + return _115 / ((3.1415927410125732421875f * _124) * _124); + } + + float pbrVisibilitySmithCorrelated(float n_dot_v, float n_dot_l, float alpha) + { + float _137 = alpha * alpha; + float _144 = 1.0f - _137; + return 0.5f / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _144) + _137)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _144) + _137))) + 9.9999997473787516355514526367188e-06f); + } + + float3 pbrFresnelSchlick(float v_dot_h, float3 f0) + { + float _173 = 1.0f - v_dot_h; + float _177 = _173 * _173; + return f0 + ((1.0f.xxx - f0) * ((_177 * _177) * _173)); + } + + float3 brdf_evaluate(float3 N, float3 V, float3 L, float3 sun_radiance, float3 base_color, float metallic, float roughness) + { + float _196 = max(dot(N, L), 0.0f); + float3 _207 = normalize(V + L); + float _221 = max(roughness, 0.04500000178813934326171875f); + float _225 = _221 * _221; + float param = max(dot(N, _207), 0.0f); + float param_1 = _225; + float param_2 = max(dot(N, V), 9.9999997473787516355514526367188e-05f); + float param_3 = _196; + float param_4 = _225; + float param_5 = max(dot(V, _207), 0.0f); + float3 param_6 = lerp(0.039999999105930328369140625f.xxx, base_color, metallic.xxx); + float3 _252 = pbrFresnelSchlick(param_5, param_6); + return ((((((1.0f.xxx - _252) * (1.0f - metallic)) * base_color) * 0.3183098733425140380859375f.xxx) + (_252 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _196; + } + + float3 pbrEvaluateShIrradiance(float3 N, float4 sh[9]) + { + float3 _407 = ((((((((sh[0].xyz * 0.2820948064327239990234375f) + (sh[1].xyz * ((-0.48860251903533935546875f) * N.y))) + (sh[2].xyz * (0.48860251903533935546875f * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875f) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125f * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125f) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125f * (((3.0f * N.z) * N.z) - 1.0f)))) + (sh[7].xyz * (((-1.09254848957061767578125f) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625f * ((N.x * N.x) - (N.y * N.y)))); + return _407; + } + + float3 pbrEvaluateIbl(float3 N_world, float3 V_world, float3 base_color, float metallic, float roughness, float4 sh[9], TextureCube tex_spec_cube, SamplerState smp_spec_cube, Texture2D tex_brdf_lut_1, SamplerState smp_brdf_lut_1, float max_lod) + { + float _414 = clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05f, 1.0f); + float3 _424 = lerp(0.039999999105930328369140625f.xxx, base_color, metallic.xxx); + float3 param = N_world; + float4 param_1[9] = sh; + float4 _488 = tex_brdf_lut_1.Sample(smp_brdf_lut_1, float2(_414, roughness)); + return (((((1.0f.xxx - (_424 + ((max((1.0f - roughness).xxx, _424) - _424) * pow(max(0.0f, 1.0f - _414), 5.0f)))) * (1.0f - metallic)) * base_color) * max(pbrEvaluateShIrradiance(param, param_1), 0.0f.xxx)) * 0.3183098733425140380859375f.xxx) + (tex_spec_cube.SampleLevel(smp_spec_cube, reflect(-V_world, N_world), roughness * max_lod).xyz * ((_424 * _488.x) + _488.y.xxx)); + } + + float3 pbrEvaluateAmbient(bool iblEnabled, float3 N_world, float3 V_world, float3 base_color, float metallic, float roughness, float flat_strength, float4 sh[9], TextureCube tex_spec_cube, SamplerState smp_spec_cube, Texture2D tex_brdf_lut_1, SamplerState smp_brdf_lut_1, float max_lod) + { + float3 result = base_color * flat_strength; + if (iblEnabled) + { + float3 param = N_world; + float3 param_1 = V_world; + float3 param_2 = base_color; + float param_3 = metallic; + float param_4 = roughness; + float4 param_5[9] = sh; + float param_6 = max_lod; + result = pbrEvaluateIbl(param, param_1, param_2, param_3, param_4, param_5, tex_spec_cube, smp_spec_cube, tex_brdf_lut_1, smp_brdf_lut_1, param_6); + } + return result; + } + + void frag_main() + { + float3 _1015 = normalize(v_world_normal); + float3 n_world = _1015; + float3 _1022 = _833_camera_pos.xyz - v_view_pos; + if (dot(_1015, _1022) < 0.0f) + { + n_world = -n_world; + } + if (_833_flags.x == 1) + { + float _1053 = clamp(mul(float4(v_view_pos, 1.0f), _833_view).z * (-0.0199999995529651641845703125f), 0.0f, 1.0f); + out_color = float4(_1053, _1053, _1053, 1.0f); + return; + } + if (_833_flags.x == 2) + { + float4 _1071 = float4(v_view_pos, 1.0f); + float _1074 = -mul(_1071, _833_view).z; + int cascade = 2; + if (_1074 < _833_cascade_far_view_z.x) + { + cascade = 0; + } + else + { + if (_1074 < _833_cascade_far_view_z.y) + { + cascade = 1; + } + } + float4 _1098 = mul(_1071, _833_cascade_matrices[cascade]); + float3 _1105 = _1098.xyz / _1098.w.xxx; + float3 _1122 = float3((_1105.x * 0.5f) + 0.5f, ((_1105.y * _833_cascade_far_view_z.w) * 0.5f) + 0.5f, _1105.z); + bool _1126 = any(bool3(_1122.x < 0.0f.xxx.x, _1122.y < 0.0f.xxx.y, _1122.z < 0.0f.xxx.z)); + bool _1133; + if (!_1126) + { + _1133 = any(bool3(_1122.x > 1.0f.xxx.x, _1122.y > 1.0f.xxx.y, _1122.z > 1.0f.xxx.z)); + } + else + { + _1133 = _1126; + } + float3 tint = 1.0f.xxx; + if (!_1133) + { + if (cascade == 0) + { + tint = float3(1.0f, 0.4000000059604644775390625f, 0.4000000059604644775390625f); + } + else + { + if (cascade == 1) + { + tint = float3(0.4000000059604644775390625f, 1.0f, 0.4000000059604644775390625f); + } + else + { + tint = float3(0.4000000059604644775390625f, 0.4000000059604644775390625f, 1.0f); + } + } + } + out_color = float4(tint, 1.0f); + return; + } + if (_833_flags.x == 3) + { + out_color = float4((normalize(mul(float4(n_world, 0.0f), _833_view).xyz) * 0.5f) + 0.5f.xxx, 1.0f); + return; + } + uint _1196_dummy_parameter; + float4 _1204 = tex_ao.SampleLevel(smp_ao, gl_FragCoord.xy / float2(int2(spvTextureSize(tex_ao, uint(0), _1196_dummy_parameter))), 0.0f); + float _1205 = _1204.x; + if (_833_flags.x == 4) + { + out_color = float4(_1205, _1205, _1205, 1.0f); + return; + } + float3 baseColor = v_base_color.xyz; + if (v_material.z > 0.5f) + { + float2 param = v_view_pos.xz; + float3 param_1 = v_base_color.xyz; + float param_2 = v_material.w; + baseColor = lerp(v_base_color.xyz, proceduralGrid(param, param_1, param_2), pow(clamp(n_world.y, 0.0f, 1.0f), 8.0f).xxx); + } + float3 param_3 = v_view_pos; + float3 param_4 = n_world; + float param_5 = -mul(float4(v_view_pos, 1.0f), _833_view).z; + float3 _1289 = normalize(_1022); + float3 param_6 = n_world; + float3 param_7 = _1289; + float3 param_8 = normalize(_833_sun_dir_world.xyz); + float3 param_9 = _833_sun_color.xyz * sampleShadowCascaded(param_3, param_4, param_5); + float3 param_10 = baseColor; + float param_11 = v_material.x; + float param_12 = v_material.y; + bool param_13 = _833_ibl_params.y > 0.5f; + float3 param_14 = n_world; + float3 param_15 = _1289; + float3 param_16 = baseColor; + float param_17 = v_material.x; + float param_18 = v_material.y; + float param_19 = _833_sun_color.w; + float4 param_20[9]; + param_20[0] = _833_sh[0]; + param_20[1] = _833_sh[1]; + param_20[2] = _833_sh[2]; + param_20[3] = _833_sh[3]; + param_20[4] = _833_sh[4]; + param_20[5] = _833_sh[5]; + param_20[6] = _833_sh[6]; + param_20[7] = _833_sh[7]; + param_20[8] = _833_sh[8]; + float param_21 = _833_ibl_params.x; + out_color = float4((brdf_evaluate(param_6, param_7, param_8, param_9, param_10, param_11, param_12) + (pbrEvaluateAmbient(param_13, param_14, param_15, param_16, param_17, param_18, param_19, param_20, tex_ibl_spec, smp_ibl_spec, tex_brdf_lut, smp_brdf_lut, param_21) * _1205)) * v_base_color.w, v_base_color.w); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_FragCoord = stage_input.gl_FragCoord; + gl_FragCoord.w = 1.0 / gl_FragCoord.w; + v_world_normal = stage_input.v_world_normal; + v_view_pos = stage_input.v_view_pos; + v_base_color = stage_input.v_base_color; + v_material = stage_input.v_material; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.out_color = out_color; + return stage_output; + } +*/ +static const uint8_t geom_fs_source_hlsl5[14561] = { + 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x31,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x38,0x33,0x33, + 0x5f,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3a, + 0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x38,0x33,0x33, + 0x5f,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x70,0x61,0x63, + 0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x6e,0x74,0x34,0x20,0x5f,0x38,0x33,0x33,0x5f,0x66,0x6c,0x61,0x67,0x73, + 0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x32, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x38, + 0x33,0x33,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20, + 0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x33,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x38,0x33,0x33,0x5f,0x76,0x69,0x65,0x77, + 0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x34, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x38, + 0x33,0x33,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x7a,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73, + 0x65,0x74,0x28,0x63,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f, + 0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f, + 0x38,0x33,0x33,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72, + 0x69,0x63,0x65,0x73,0x5b,0x33,0x5d,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66, + 0x66,0x73,0x65,0x74,0x28,0x63,0x39,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x5f,0x38,0x33,0x33,0x5f,0x73,0x68,0x5b,0x39,0x5d,0x20, + 0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x32,0x31, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x38, + 0x33,0x33,0x5f,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x20,0x3a,0x20, + 0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x33,0x30,0x29,0x3b, + 0x0a,0x7d,0x3b,0x0a,0x0a,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x41,0x72, + 0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65, + 0x72,0x28,0x74,0x30,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x6f, + 0x6d,0x70,0x61,0x72,0x69,0x73,0x6f,0x6e,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d, + 0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73, + 0x74,0x65,0x72,0x28,0x73,0x30,0x29,0x3b,0x0a,0x54,0x65,0x78,0x74,0x75,0x72,0x65, + 0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x61, + 0x6f,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x33,0x29, + 0x3b,0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73, + 0x6d,0x70,0x5f,0x61,0x6f,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72, + 0x28,0x73,0x33,0x29,0x3b,0x0a,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x43,0x75,0x62, + 0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x69,0x62, + 0x6c,0x5f,0x73,0x70,0x65,0x63,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65, + 0x72,0x28,0x74,0x31,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74, + 0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63, + 0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x31,0x29,0x3b, + 0x0a,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x32,0x29,0x3b,0x0a, + 0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70, + 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x20,0x3a,0x20,0x72,0x65,0x67,0x69, + 0x73,0x74,0x65,0x72,0x28,0x73,0x32,0x29,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69, + 0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67, + 0x43,0x6f,0x6f,0x72,0x64,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72, + 0x6d,0x61,0x6c,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x73, + 0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x0a,0x73, + 0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73, + 0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x20, + 0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52, + 0x44,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70, + 0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76, + 0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x54,0x45, + 0x58,0x43,0x4f,0x4f,0x52,0x44,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69, + 0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3a, + 0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f, + 0x6f,0x72,0x64,0x20,0x3a,0x20,0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f, + 0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50, + 0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75, + 0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x53,0x56,0x5f,0x54,0x61,0x72, + 0x67,0x65,0x74,0x30,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x75,0x69,0x6e,0x74,0x32,0x20, + 0x73,0x70,0x76,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x54, + 0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e, + 0x20,0x54,0x65,0x78,0x2c,0x20,0x75,0x69,0x6e,0x74,0x20,0x4c,0x65,0x76,0x65,0x6c, + 0x2c,0x20,0x6f,0x75,0x74,0x20,0x75,0x69,0x6e,0x74,0x20,0x50,0x61,0x72,0x61,0x6d, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x32,0x20,0x72,0x65, + 0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x54,0x65,0x78,0x2e,0x47,0x65,0x74,0x44,0x69, + 0x6d,0x65,0x6e,0x73,0x69,0x6f,0x6e,0x73,0x28,0x4c,0x65,0x76,0x65,0x6c,0x2c,0x20, + 0x72,0x65,0x74,0x2e,0x78,0x2c,0x20,0x72,0x65,0x74,0x2e,0x79,0x2c,0x20,0x50,0x61, + 0x72,0x61,0x6d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x72,0x65,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x70,0x72,0x6f,0x63,0x65,0x64,0x75,0x72,0x61,0x6c,0x47,0x72,0x69,0x64,0x28,0x66, + 0x6c,0x6f,0x61,0x74,0x32,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x78,0x7a,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x63,0x65,0x6c,0x6c,0x5f,0x73,0x69, + 0x7a,0x65,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, + 0x20,0x5f,0x35,0x33,0x35,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x78,0x7a, + 0x20,0x2f,0x20,0x63,0x65,0x6c,0x6c,0x5f,0x73,0x69,0x7a,0x65,0x2e,0x78,0x78,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x35,0x35,0x31, + 0x20,0x3d,0x20,0x61,0x62,0x73,0x28,0x66,0x72,0x61,0x63,0x28,0x5f,0x35,0x33,0x35, + 0x20,0x2d,0x20,0x30,0x2e,0x35,0x66,0x2e,0x78,0x78,0x29,0x20,0x2d,0x20,0x30,0x2e, + 0x35,0x66,0x2e,0x78,0x78,0x29,0x20,0x2f,0x20,0x6d,0x61,0x78,0x28,0x66,0x77,0x69, + 0x64,0x74,0x68,0x28,0x5f,0x35,0x33,0x35,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39, + 0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x35,0x32,0x34,0x32,0x37,0x30,0x37,0x38,0x37, + 0x38,0x33,0x35,0x31,0x32,0x31,0x31,0x35,0x34,0x37,0x38,0x35,0x65,0x2d,0x30,0x37, + 0x66,0x2e,0x78,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x32,0x20,0x5f,0x35,0x36,0x36,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x78, + 0x7a,0x20,0x2f,0x20,0x28,0x63,0x65,0x6c,0x6c,0x5f,0x73,0x69,0x7a,0x65,0x20,0x2a, + 0x20,0x31,0x30,0x2e,0x30,0x66,0x29,0x2e,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x35,0x38,0x30,0x20,0x3d,0x20,0x61,0x62, + 0x73,0x28,0x66,0x72,0x61,0x63,0x28,0x5f,0x35,0x36,0x36,0x20,0x2d,0x20,0x30,0x2e, + 0x35,0x66,0x2e,0x78,0x78,0x29,0x20,0x2d,0x20,0x30,0x2e,0x35,0x66,0x2e,0x78,0x78, + 0x29,0x20,0x2f,0x20,0x6d,0x61,0x78,0x28,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f, + 0x35,0x36,0x36,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37, + 0x34,0x37,0x35,0x32,0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38,0x33,0x35,0x31,0x32, + 0x31,0x31,0x35,0x34,0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x66,0x2e,0x78,0x78,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x36,0x31, + 0x31,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x77, + 0x6f,0x72,0x6c,0x64,0x5f,0x78,0x7a,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39, + 0x39,0x39,0x39,0x37,0x34,0x37,0x35,0x32,0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38, + 0x33,0x35,0x31,0x32,0x31,0x31,0x35,0x34,0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x66, + 0x2e,0x78,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x6c,0x65,0x72,0x70,0x28,0x6c,0x65,0x72,0x70,0x28,0x6c,0x65,0x72,0x70,0x28, + 0x6c,0x65,0x72,0x70,0x28,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c, + 0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x30,0x2e, + 0x36,0x39,0x39,0x39,0x39,0x39,0x39,0x38,0x38,0x30,0x37,0x39,0x30,0x37,0x31,0x30, + 0x34,0x34,0x39,0x32,0x31,0x38,0x37,0x35,0x66,0x2c,0x20,0x28,0x31,0x2e,0x30,0x66, + 0x20,0x2d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6d,0x69,0x6e,0x28,0x5f,0x35,0x35, + 0x31,0x2e,0x78,0x2c,0x20,0x5f,0x35,0x35,0x31,0x2e,0x79,0x29,0x2c,0x20,0x30,0x2e, + 0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x29,0x2e,0x78,0x78,0x78,0x29,0x2c, + 0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x30,0x2e, + 0x33,0x34,0x39,0x39,0x39,0x39,0x39,0x39,0x34,0x30,0x33,0x39,0x35,0x33,0x35,0x35, + 0x32,0x32,0x34,0x36,0x30,0x39,0x33,0x37,0x35,0x66,0x2c,0x20,0x28,0x31,0x2e,0x30, + 0x66,0x20,0x2d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6d,0x69,0x6e,0x28,0x5f,0x35, + 0x38,0x30,0x2e,0x78,0x2c,0x20,0x5f,0x35,0x38,0x30,0x2e,0x79,0x29,0x2c,0x20,0x30, + 0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x29,0x2e,0x78,0x78,0x78,0x29, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x66,0x2c,0x20,0x30, + 0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x2c,0x20,0x28,0x28,0x31,0x2e, + 0x30,0x66,0x20,0x2d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x61,0x62,0x73,0x28,0x77, + 0x6f,0x72,0x6c,0x64,0x5f,0x78,0x7a,0x2e,0x79,0x29,0x20,0x2f,0x20,0x5f,0x36,0x31, + 0x31,0x2e,0x79,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29, + 0x29,0x20,0x2a,0x20,0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x77, + 0x6f,0x72,0x6c,0x64,0x5f,0x78,0x7a,0x2e,0x78,0x29,0x29,0x2e,0x78,0x78,0x78,0x29, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x30, + 0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x28,0x28,0x31,0x2e, + 0x30,0x66,0x20,0x2d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x61,0x62,0x73,0x28,0x77, + 0x6f,0x72,0x6c,0x64,0x5f,0x78,0x7a,0x2e,0x78,0x29,0x20,0x2f,0x20,0x5f,0x36,0x31, + 0x31,0x2e,0x78,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29, + 0x29,0x20,0x2a,0x20,0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x77, + 0x6f,0x72,0x6c,0x64,0x5f,0x78,0x7a,0x2e,0x79,0x29,0x29,0x2e,0x78,0x78,0x78,0x29, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x69,0x6e,0x74,0x20,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x6c, + 0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x62, + 0x69,0x61,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x36,0x35,0x35,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x36,0x36,0x30,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75, + 0x76,0x2e,0x7a,0x20,0x2d,0x20,0x62,0x69,0x61,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x37,0x36,0x20,0x3d,0x20,0x6c,0x69,0x67, + 0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20,0x2d,0x20,0x30,0x2e,0x30,0x30,0x30,0x34, + 0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x36,0x38,0x30,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74, + 0x5f,0x75,0x76,0x2e,0x79,0x20,0x2d,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38, + 0x32,0x38,0x31,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x37,0x31,0x30,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75, + 0x76,0x2e,0x78,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38, + 0x31,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x37,0x37,0x38,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e, + 0x79,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32, + 0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28, + 0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f, + 0x36,0x37,0x36,0x2c,0x20,0x5f,0x36,0x38,0x30,0x2c,0x20,0x5f,0x36,0x35,0x35,0x2c, + 0x20,0x5f,0x36,0x36,0x30,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x36,0x36,0x30, + 0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53, + 0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6c,0x69,0x67,0x68, + 0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20,0x5f,0x36,0x38,0x30,0x2c,0x20,0x5f,0x36, + 0x35,0x35,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f, + 0x36,0x36,0x30,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, + 0x5f,0x37,0x31,0x30,0x2c,0x20,0x5f,0x36,0x38,0x30,0x2c,0x20,0x5f,0x36,0x35,0x35, + 0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x36,0x36, + 0x30,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x36, + 0x37,0x36,0x2c,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20, + 0x5f,0x36,0x35,0x35,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x2e,0x78,0x79,0x7a,0x2c, + 0x20,0x5f,0x36,0x36,0x30,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68, + 0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73, + 0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x79,0x2c,0x20,0x5f, + 0x36,0x35,0x35,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20, + 0x5f,0x36,0x36,0x30,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d, + 0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x28,0x5f,0x37,0x31,0x30,0x2c,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e, + 0x79,0x2c,0x20,0x5f,0x36,0x35,0x35,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x2e,0x78, + 0x79,0x7a,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d, + 0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x5f,0x36,0x37,0x36,0x2c,0x20,0x5f,0x37,0x37,0x38,0x2c, + 0x20,0x5f,0x36,0x35,0x35,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x2e,0x78,0x79,0x7a, + 0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28, + 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20,0x5f, + 0x37,0x37,0x38,0x2c,0x20,0x5f,0x36,0x35,0x35,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29, + 0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x29,0x20,0x2b,0x20,0x74, + 0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65, + 0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x37,0x31,0x30,0x2c,0x20,0x5f,0x37,0x37, + 0x38,0x2c,0x20,0x5f,0x36,0x35,0x35,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x2e,0x78, + 0x79,0x7a,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x29,0x20,0x2a,0x20,0x30,0x2e,0x31, + 0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x39,0x33,0x38,0x39,0x35,0x33,0x33,0x39, + 0x39,0x36,0x35,0x38,0x32,0x30,0x33,0x31,0x32,0x35,0x66,0x3b,0x0a,0x7d,0x0a,0x0a, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63, + 0x61,0x64,0x65,0x28,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f, + 0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x5f,0x38,0x34,0x33,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, + 0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f,0x38,0x33,0x33,0x5f,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x5f,0x38,0x35,0x30,0x20,0x3d,0x20,0x5f,0x38,0x34,0x33, + 0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x5f,0x38,0x34,0x33,0x2e,0x77,0x2e,0x78,0x78, + 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x38, + 0x36,0x38,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x5f,0x38,0x35, + 0x30,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e, + 0x35,0x66,0x2c,0x20,0x28,0x28,0x5f,0x38,0x35,0x30,0x2e,0x79,0x20,0x2a,0x20,0x5f, + 0x38,0x33,0x33,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66, + 0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2c,0x20,0x5f,0x38,0x35,0x30,0x2e,0x7a, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x38,0x37,0x32, + 0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c,0x33,0x28,0x5f,0x38,0x36, + 0x38,0x2e,0x78,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x78, + 0x2c,0x20,0x5f,0x38,0x36,0x38,0x2e,0x79,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e, + 0x78,0x78,0x78,0x2e,0x79,0x2c,0x20,0x5f,0x38,0x36,0x38,0x2e,0x7a,0x20,0x3c,0x20, + 0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x7a,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x38,0x37,0x39,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x38,0x37,0x32,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x37,0x39,0x20,0x3d, + 0x20,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c,0x33,0x28,0x5f,0x38,0x36,0x38,0x2e, + 0x78,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x78,0x2c,0x20, + 0x5f,0x38,0x36,0x38,0x2e,0x79,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78, + 0x78,0x2e,0x79,0x2c,0x20,0x5f,0x38,0x36,0x38,0x2e,0x7a,0x20,0x3e,0x20,0x31,0x2e, + 0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x7a,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x37,0x39,0x20,0x3d,0x20, + 0x5f,0x38,0x37,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x5f,0x38,0x37,0x39,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x31, + 0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x38,0x36,0x38,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x30,0x2e,0x30,0x30,0x34,0x30,0x30,0x30, + 0x30,0x30,0x30,0x31,0x38,0x39,0x39,0x38,0x39,0x38,0x30,0x35,0x32,0x32,0x31,0x35, + 0x35,0x37,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x66,0x2c,0x20,0x30,0x2e,0x30,0x30, + 0x30,0x37,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x39,0x37,0x39,0x30,0x33,0x30,0x30, + 0x31,0x33,0x30,0x38,0x34,0x34,0x31,0x31,0x36,0x32,0x31,0x30,0x39,0x33,0x37,0x35, + 0x66,0x2c,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x77,0x6f,0x72,0x6c,0x64, + 0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69, + 0x7a,0x65,0x28,0x5f,0x38,0x33,0x33,0x5f,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30, + 0x66,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x63,0x66,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f, + 0x77,0x50,0x43,0x46,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d, + 0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x39,0x31,0x31,0x20,0x3d, + 0x20,0x5f,0x38,0x36,0x38,0x2e,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x39,0x31,0x36,0x20,0x3d,0x20, + 0x6d,0x69,0x6e,0x28,0x5f,0x39,0x31,0x31,0x2c,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78, + 0x78,0x20,0x2d,0x20,0x5f,0x39,0x31,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x31,0x2e, + 0x30,0x66,0x2c,0x20,0x70,0x63,0x66,0x2c,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6d, + 0x69,0x6e,0x28,0x5f,0x39,0x31,0x36,0x2e,0x78,0x2c,0x20,0x5f,0x39,0x31,0x36,0x2e, + 0x79,0x29,0x20,0x2a,0x20,0x31,0x30,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66, + 0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x70,0x63,0x66,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53, + 0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72, + 0x6d,0x61,0x6c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x69,0x65,0x77,0x5f, + 0x7a,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x38,0x33,0x33,0x5f, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77, + 0x5f,0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x38,0x33,0x33,0x5f, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77, + 0x5f,0x7a,0x2e,0x79,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72, + 0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61, + 0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20, + 0x3c,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x36,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f, + 0x39,0x36,0x30,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x5f,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x39, + 0x36,0x30,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x5f,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x37,0x32,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x39, + 0x37,0x32,0x20,0x3d,0x20,0x30,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, + 0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x39,0x37,0x32,0x20,0x3d,0x20,0x5f, + 0x38,0x33,0x33,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x39,0x38,0x33,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x5f,0x39, + 0x36,0x30,0x2c,0x20,0x5f,0x39,0x37,0x32,0x2c,0x20,0x30,0x2e,0x31,0x30,0x30,0x30, + 0x30,0x30,0x30,0x30,0x31,0x34,0x39,0x30,0x31,0x31,0x36,0x31,0x31,0x39,0x33,0x38, + 0x34,0x37,0x36,0x35,0x36,0x32,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3e,0x20, + 0x5f,0x39,0x38,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x20,0x2b,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x34,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x6c, + 0x65,0x72,0x70,0x28,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x35,0x29,0x2c,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x2d,0x20, + 0x5f,0x39,0x38,0x33,0x29,0x20,0x2f,0x20,0x28,0x5f,0x39,0x36,0x30,0x20,0x2d,0x20, + 0x5f,0x39,0x38,0x33,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74, + 0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64, + 0x6f,0x74,0x5f,0x68,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70,0x68, + 0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x31,0x35,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c, + 0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x32,0x34,0x20,0x3d,0x20,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x20, + 0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x29,0x20,0x2a,0x20,0x28,0x5f,0x31, + 0x31,0x35,0x20,0x2d,0x20,0x31,0x2e,0x30,0x66,0x29,0x29,0x20,0x2b,0x20,0x31,0x2e, + 0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f, + 0x31,0x31,0x35,0x20,0x2f,0x20,0x28,0x28,0x33,0x2e,0x31,0x34,0x31,0x35,0x39,0x32, + 0x37,0x34,0x31,0x30,0x31,0x32,0x35,0x37,0x33,0x32,0x34,0x32,0x31,0x38,0x37,0x35, + 0x66,0x20,0x2a,0x20,0x5f,0x31,0x32,0x34,0x29,0x20,0x2a,0x20,0x5f,0x31,0x32,0x34, + 0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x56, + 0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f, + 0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e, + 0x5f,0x64,0x6f,0x74,0x5f,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f, + 0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70, + 0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x33,0x37,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61, + 0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x34,0x34,0x20,0x3d,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x5f,0x31, + 0x33,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x30, + 0x2e,0x35,0x66,0x20,0x2f,0x20,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c, + 0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f, + 0x76,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x29,0x20,0x2a,0x20,0x5f, + 0x31,0x34,0x34,0x29,0x20,0x2b,0x20,0x5f,0x31,0x33,0x37,0x29,0x29,0x20,0x2b,0x20, + 0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28, + 0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f, + 0x74,0x5f,0x6c,0x29,0x20,0x2a,0x20,0x5f,0x31,0x34,0x34,0x29,0x20,0x2b,0x20,0x5f, + 0x31,0x33,0x37,0x29,0x29,0x29,0x20,0x2b,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39, + 0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31, + 0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x66,0x29, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x46, + 0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x66,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x31,0x37,0x33,0x20,0x3d,0x20,0x31,0x2e,0x30,0x66,0x20, + 0x2d,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x37,0x37,0x20,0x3d,0x20,0x5f,0x31,0x37,0x33, + 0x20,0x2a,0x20,0x5f,0x31,0x37,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x66,0x30,0x20,0x2b,0x20,0x28,0x28,0x31,0x2e,0x30,0x66,0x2e, + 0x78,0x78,0x78,0x20,0x2d,0x20,0x66,0x30,0x29,0x20,0x2a,0x20,0x28,0x28,0x5f,0x31, + 0x37,0x37,0x20,0x2a,0x20,0x5f,0x31,0x37,0x37,0x29,0x20,0x2a,0x20,0x5f,0x31,0x37, + 0x33,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62, + 0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x4e,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x56,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69, + 0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65, + 0x73,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x39,0x36,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e, + 0x2c,0x20,0x4c,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x32,0x30,0x37,0x20,0x3d,0x20,0x6e, + 0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x56,0x20,0x2b,0x20,0x4c,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x32,0x31,0x20, + 0x3d,0x20,0x6d,0x61,0x78,0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c, + 0x20,0x30,0x2e,0x30,0x34,0x35,0x30,0x30,0x30,0x30,0x30,0x31,0x37,0x38,0x38,0x31, + 0x33,0x39,0x33,0x34,0x33,0x32,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x66,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x32,0x35,0x20, + 0x3d,0x20,0x5f,0x32,0x32,0x31,0x20,0x2a,0x20,0x5f,0x32,0x32,0x31,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d, + 0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x5f,0x32,0x30,0x37, + 0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x32, + 0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28, + 0x4e,0x2c,0x20,0x56,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37, + 0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35, + 0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x66,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x20,0x3d,0x20,0x5f,0x31,0x39,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x32, + 0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28, + 0x56,0x2c,0x20,0x5f,0x32,0x30,0x37,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x30,0x2e,0x30,0x33,0x39, + 0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38,0x33, + 0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x66,0x2e,0x78,0x78,0x78,0x2c,0x20,0x62, + 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x6d,0x65,0x74,0x61,0x6c, + 0x6c,0x69,0x63,0x2e,0x78,0x78,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x5f,0x32,0x35,0x32,0x20,0x3d,0x20,0x70,0x62,0x72,0x46, + 0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28, + 0x28,0x28,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x20,0x2d,0x20,0x5f,0x32,0x35, + 0x32,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x6d,0x65,0x74, + 0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39, + 0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39, + 0x33,0x37,0x35,0x66,0x2e,0x78,0x78,0x78,0x29,0x20,0x2b,0x20,0x28,0x5f,0x32,0x35, + 0x32,0x20,0x2a,0x20,0x28,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75, + 0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x20,0x2a,0x20,0x70,0x62,0x72,0x56,0x69,0x73, + 0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72, + 0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, + 0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61, + 0x6e,0x63,0x65,0x29,0x20,0x2a,0x20,0x5f,0x31,0x39,0x36,0x3b,0x0a,0x7d,0x0a,0x0a, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61, + 0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x4e,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x73,0x68,0x5b,0x39,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x5f,0x34,0x30,0x37,0x20,0x3d,0x20,0x28,0x28,0x28,0x28,0x28, + 0x28,0x28,0x28,0x73,0x68,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x30, + 0x2e,0x32,0x38,0x32,0x30,0x39,0x34,0x38,0x30,0x36,0x34,0x33,0x32,0x37,0x32,0x33, + 0x39,0x39,0x39,0x30,0x32,0x33,0x34,0x33,0x37,0x35,0x66,0x29,0x20,0x2b,0x20,0x28, + 0x73,0x68,0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30, + 0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39, + 0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79, + 0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x32,0x5d,0x2e,0x78,0x79,0x7a, + 0x20,0x2a,0x20,0x28,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30, + 0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x66,0x20,0x2a, + 0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x33,0x5d, + 0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36, + 0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36, + 0x38,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x29,0x29,0x20,0x2b, + 0x20,0x28,0x73,0x68,0x5b,0x34,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28, + 0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31, + 0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x66,0x20,0x2a,0x20,0x4e,0x2e,0x78, + 0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68, + 0x5b,0x35,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e, + 0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36, + 0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29, + 0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b, + 0x36,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x33,0x31,0x35,0x33, + 0x39,0x31,0x35,0x37,0x30,0x33,0x32,0x39,0x36,0x36,0x36,0x31,0x33,0x37,0x36,0x39, + 0x35,0x33,0x31,0x32,0x35,0x66,0x20,0x2a,0x20,0x28,0x28,0x28,0x33,0x2e,0x30,0x66, + 0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2d, + 0x20,0x31,0x2e,0x30,0x66,0x29,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b, + 0x37,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30, + 0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37, + 0x35,0x37,0x38,0x31,0x32,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20, + 0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x38, + 0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x35,0x34,0x36,0x32,0x37, + 0x34,0x32,0x34,0x34,0x37,0x38,0x35,0x33,0x30,0x38,0x38,0x33,0x37,0x38,0x39,0x30, + 0x36,0x32,0x35,0x66,0x20,0x2a,0x20,0x28,0x28,0x4e,0x2e,0x78,0x20,0x2a,0x20,0x4e, + 0x2e,0x78,0x29,0x20,0x2d,0x20,0x28,0x4e,0x2e,0x79,0x20,0x2a,0x20,0x4e,0x2e,0x79, + 0x29,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x5f,0x34,0x30,0x37,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69, + 0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65, + 0x73,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d, + 0x2c,0x20,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x43,0x75,0x62,0x65,0x3c,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63, + 0x75,0x62,0x65,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74, + 0x65,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c, + 0x20,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f, + 0x31,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20, + 0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x31,0x34,0x20, + 0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x64,0x6f,0x74,0x28,0x4e,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x2c,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x39, + 0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31, + 0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38, + 0x65,0x2d,0x30,0x35,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x34,0x32,0x34,0x20,0x3d,0x20, + 0x6c,0x65,0x72,0x70,0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39, + 0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36, + 0x32,0x35,0x66,0x2e,0x78,0x78,0x78,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x2c,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2e,0x78,0x78, + 0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x5b,0x39,0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x34,0x38,0x38,0x20,0x3d,0x20,0x74,0x65, + 0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2e,0x53,0x61,0x6d, + 0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74, + 0x5f,0x31,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x34,0x31,0x34,0x2c, + 0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x31,0x2e, + 0x30,0x66,0x2e,0x78,0x78,0x78,0x20,0x2d,0x20,0x28,0x5f,0x34,0x32,0x34,0x20,0x2b, + 0x20,0x28,0x28,0x6d,0x61,0x78,0x28,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x72, + 0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x2e,0x78,0x78,0x78,0x2c,0x20,0x5f, + 0x34,0x32,0x34,0x29,0x20,0x2d,0x20,0x5f,0x34,0x32,0x34,0x29,0x20,0x2a,0x20,0x70, + 0x6f,0x77,0x28,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30, + 0x66,0x20,0x2d,0x20,0x5f,0x34,0x31,0x34,0x29,0x2c,0x20,0x35,0x2e,0x30,0x66,0x29, + 0x29,0x29,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x6d,0x65, + 0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x6d,0x61,0x78,0x28,0x70,0x62,0x72, + 0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69, + 0x61,0x6e,0x63,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x29,0x29, + 0x20,0x2a,0x20,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34, + 0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x66,0x2e, + 0x78,0x78,0x78,0x29,0x20,0x2b,0x20,0x28,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63, + 0x5f,0x63,0x75,0x62,0x65,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x4c,0x65,0x76,0x65, + 0x6c,0x28,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c, + 0x20,0x72,0x65,0x66,0x6c,0x65,0x63,0x74,0x28,0x2d,0x56,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x2c,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x72,0x6f,0x75, + 0x67,0x68,0x6e,0x65,0x73,0x73,0x20,0x2a,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64, + 0x29,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x34,0x32,0x34,0x20,0x2a, + 0x20,0x5f,0x34,0x38,0x38,0x2e,0x78,0x29,0x20,0x2b,0x20,0x5f,0x34,0x38,0x38,0x2e, + 0x79,0x2e,0x78,0x78,0x78,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d, + 0x62,0x69,0x65,0x6e,0x74,0x28,0x62,0x6f,0x6f,0x6c,0x20,0x69,0x62,0x6c,0x45,0x6e, + 0x61,0x62,0x6c,0x65,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4e,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x56,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x61, + 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x2c,0x20,0x54,0x65, + 0x78,0x74,0x75,0x72,0x65,0x43,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c, + 0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d, + 0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x54,0x65,0x78, + 0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74, + 0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x53, + 0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f, + 0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d, + 0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x66,0x6c, + 0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20, + 0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20, + 0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x33,0x20,0x3d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73, + 0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x5b,0x39,0x5d,0x20,0x3d,0x20,0x73, + 0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x61,0x78,0x5f,0x6c, + 0x6f,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x73,0x75, + 0x6c,0x74,0x20,0x3d,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65, + 0x49,0x62,0x6c,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63, + 0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f, + 0x63,0x75,0x62,0x65,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, + 0x75,0x74,0x5f,0x31,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, + 0x75,0x74,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64, + 0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x30,0x31,0x35,0x20, + 0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x76,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20, + 0x3d,0x20,0x5f,0x31,0x30,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x5f,0x31,0x30,0x32,0x32,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33, + 0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20, + 0x2d,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x30,0x31,0x35,0x2c, + 0x20,0x5f,0x31,0x30,0x32,0x32,0x29,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x2d,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x5f,0x38,0x33,0x33,0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20, + 0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x33,0x20,0x3d,0x20,0x63, + 0x6c,0x61,0x6d,0x70,0x28,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, + 0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x66, + 0x29,0x2c,0x20,0x5f,0x38,0x33,0x33,0x5f,0x76,0x69,0x65,0x77,0x29,0x2e,0x7a,0x20, + 0x2a,0x20,0x28,0x2d,0x30,0x2e,0x30,0x31,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x35, + 0x35,0x32,0x39,0x36,0x35,0x31,0x36,0x34,0x31,0x38,0x34,0x35,0x37,0x30,0x33,0x31, + 0x32,0x35,0x66,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x31, + 0x30,0x35,0x33,0x2c,0x20,0x5f,0x31,0x30,0x35,0x33,0x2c,0x20,0x5f,0x31,0x30,0x35, + 0x33,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x38,0x33,0x33,0x5f,0x66,0x6c,0x61, + 0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x5f,0x31,0x30,0x37,0x31,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x76, + 0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x30,0x37,0x34,0x20,0x3d,0x20,0x2d,0x6d,0x75,0x6c,0x28,0x5f,0x31,0x30, + 0x37,0x31,0x2c,0x20,0x5f,0x38,0x33,0x33,0x5f,0x76,0x69,0x65,0x77,0x29,0x2e,0x7a, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x30,0x37,0x34,0x20,0x3c,0x20,0x5f, + 0x38,0x33,0x33,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65, + 0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31, + 0x30,0x37,0x34,0x20,0x3c,0x20,0x5f,0x38,0x33,0x33,0x5f,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x5f,0x31,0x30,0x39,0x38,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x5f, + 0x31,0x30,0x37,0x31,0x2c,0x20,0x5f,0x38,0x33,0x33,0x5f,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x31,0x30,0x35,0x20,0x3d,0x20,0x5f,0x31, + 0x30,0x39,0x38,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x5f,0x31,0x30,0x39,0x38,0x2e, + 0x77,0x2e,0x78,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x31,0x32,0x32,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x28,0x28,0x5f,0x31,0x31,0x30,0x35,0x2e,0x78,0x20,0x2a,0x20, + 0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2c,0x20,0x28,0x28, + 0x5f,0x31,0x31,0x30,0x35,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x38,0x33,0x33,0x5f,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30, + 0x2e,0x35,0x66,0x2c,0x20,0x5f,0x31,0x31,0x30,0x35,0x2e,0x7a,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x32, + 0x36,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c,0x33,0x28,0x5f,0x31, + 0x31,0x32,0x32,0x2e,0x78,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78, + 0x2e,0x78,0x2c,0x20,0x5f,0x31,0x31,0x32,0x32,0x2e,0x79,0x20,0x3c,0x20,0x30,0x2e, + 0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x79,0x2c,0x20,0x5f,0x31,0x31,0x32,0x32,0x2e, + 0x7a,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x7a,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f, + 0x31,0x31,0x33,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x21,0x5f,0x31,0x31,0x32,0x36,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x5f,0x31,0x31,0x33,0x33,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c, + 0x33,0x28,0x5f,0x31,0x31,0x32,0x32,0x2e,0x78,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66, + 0x2e,0x78,0x78,0x78,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x31,0x32,0x32,0x2e,0x79,0x20, + 0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x79,0x2c,0x20,0x5f,0x31, + 0x31,0x32,0x32,0x2e,0x7a,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78, + 0x2e,0x7a,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x5f,0x31,0x31,0x33,0x33,0x20,0x3d,0x20,0x5f,0x31,0x31,0x32,0x36, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x74,0x69,0x6e,0x74,0x20, + 0x3d,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x31,0x33,0x33,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30, + 0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33, + 0x39,0x30,0x36,0x32,0x35,0x66,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30, + 0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30, + 0x36,0x32,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20, + 0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74, + 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30, + 0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33, + 0x39,0x30,0x36,0x32,0x35,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e, + 0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34, + 0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65, + 0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30, + 0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30, + 0x36,0x32,0x35,0x66,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30, + 0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32, + 0x35,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, + 0x74,0x69,0x6e,0x74,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x38,0x33,0x33,0x5f, + 0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x33,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28, + 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x6d,0x75,0x6c,0x28,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x30,0x2e, + 0x30,0x66,0x29,0x2c,0x20,0x5f,0x38,0x33,0x33,0x5f,0x76,0x69,0x65,0x77,0x29,0x2e, + 0x78,0x79,0x7a,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30, + 0x2e,0x35,0x66,0x2e,0x78,0x78,0x78,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x5f, + 0x31,0x31,0x39,0x36,0x5f,0x64,0x75,0x6d,0x6d,0x79,0x5f,0x70,0x61,0x72,0x61,0x6d, + 0x65,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x5f,0x31,0x32,0x30,0x34,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e, + 0x53,0x61,0x6d,0x70,0x6c,0x65,0x4c,0x65,0x76,0x65,0x6c,0x28,0x73,0x6d,0x70,0x5f, + 0x61,0x6f,0x2c,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64, + 0x2e,0x78,0x79,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x69,0x6e,0x74, + 0x32,0x28,0x73,0x70,0x76,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x53,0x69,0x7a,0x65, + 0x28,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x30,0x29, + 0x2c,0x20,0x5f,0x31,0x31,0x39,0x36,0x5f,0x64,0x75,0x6d,0x6d,0x79,0x5f,0x70,0x61, + 0x72,0x61,0x6d,0x65,0x74,0x65,0x72,0x29,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32, + 0x30,0x35,0x20,0x3d,0x20,0x5f,0x31,0x32,0x30,0x34,0x2e,0x78,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x38,0x33,0x33,0x5f,0x66,0x6c,0x61,0x67,0x73, + 0x2e,0x78,0x20,0x3d,0x3d,0x20,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x32,0x30,0x35,0x2c, + 0x20,0x5f,0x31,0x32,0x30,0x35,0x2c,0x20,0x5f,0x31,0x32,0x30,0x35,0x2c,0x20,0x31, + 0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x61,0x73,0x65,0x43,0x6f,0x6c,0x6f,0x72, + 0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e, + 0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x5f,0x6d, + 0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x7a,0x20,0x3e,0x20,0x30,0x2e,0x35,0x66, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x76, + 0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x7a,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d, + 0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x77,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x61,0x73,0x65,0x43,0x6f,0x6c,0x6f,0x72, + 0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x70,0x72,0x6f,0x63,0x65,0x64, + 0x75,0x72,0x61,0x6c,0x47,0x72,0x69,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x29,0x2c,0x20,0x70,0x6f,0x77,0x28,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6e,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x2e,0x79,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e, + 0x30,0x66,0x29,0x2c,0x20,0x38,0x2e,0x30,0x66,0x29,0x2e,0x78,0x78,0x78,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x76,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x6e,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x2d,0x6d,0x75,0x6c,0x28,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73, + 0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f,0x38,0x33,0x33,0x5f,0x76,0x69, + 0x65,0x77,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x5f,0x31,0x32,0x38,0x39,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c, + 0x69,0x7a,0x65,0x28,0x5f,0x31,0x30,0x32,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d, + 0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x5f, + 0x31,0x32,0x38,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x69,0x7a,0x65,0x28,0x5f,0x38,0x33,0x33,0x5f,0x73,0x75,0x6e,0x5f,0x64,0x69, + 0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39, + 0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x5f,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68, + 0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x62, + 0x61,0x73,0x65,0x43,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x76, + 0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20, + 0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x33,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x5f,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72, + 0x61,0x6d,0x73,0x2e,0x79,0x20,0x3e,0x20,0x30,0x2e,0x35,0x66,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x34,0x20,0x3d,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35, + 0x20,0x3d,0x20,0x5f,0x31,0x32,0x38,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20, + 0x62,0x61,0x73,0x65,0x43,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x20,0x3d,0x20, + 0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38, + 0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x39,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x5f,0x73,0x75,0x6e,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x39,0x5d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x30,0x5d,0x20, + 0x3d,0x20,0x5f,0x38,0x33,0x33,0x5f,0x73,0x68,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x31,0x5d,0x20,0x3d,0x20, + 0x5f,0x38,0x33,0x33,0x5f,0x73,0x68,0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x32,0x5d,0x20,0x3d,0x20,0x5f,0x38, + 0x33,0x33,0x5f,0x73,0x68,0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x33,0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33, + 0x5f,0x73,0x68,0x5b,0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x30,0x5b,0x34,0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x5f,0x73, + 0x68,0x5b,0x34,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x30,0x5b,0x35,0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x5f,0x73,0x68,0x5b, + 0x35,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30, + 0x5b,0x36,0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x5f,0x73,0x68,0x5b,0x36,0x5d, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x37, + 0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x5f,0x73,0x68,0x5b,0x37,0x5d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x38,0x5d,0x20, + 0x3d,0x20,0x5f,0x38,0x33,0x33,0x5f,0x73,0x68,0x5b,0x38,0x5d,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31, + 0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x5f,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61, + 0x6d,0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x62,0x72, + 0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x29,0x20,0x2b,0x20, + 0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69, + 0x65,0x6e,0x74,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x30,0x2c,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63, + 0x2c,0x20,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20, + 0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73,0x6d, + 0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x31,0x29,0x20,0x2a,0x20,0x5f,0x31,0x32,0x30,0x35,0x29,0x29,0x20, + 0x2a,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77, + 0x2c,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77, + 0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73, + 0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50, + 0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x20, + 0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c, + 0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x77,0x20,0x3d, + 0x20,0x31,0x2e,0x30,0x20,0x2f,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f, + 0x6f,0x72,0x64,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x20,0x3d,0x20,0x73,0x74,0x61,0x67, + 0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x70,0x6f,0x73,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69, + 0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e, + 0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3d,0x20,0x73, + 0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x6d,0x61,0x74, + 0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f, + 0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52, + 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73, + 0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x6f,0x75, + 0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a, + 0x00, +}; +/* + #include + #include + + using namespace metal; + + struct instance + { + float4 xform_row0; + float4 xform_row1; + float4 xform_row2; + float4 base_color; + float4 scale; + float4 material; + }; + + struct instances + { + instance items[1]; + }; + + struct ub_draw + { + int4 inst_base; + }; + + struct ub_frame + { + float4x4 view_proj; + }; + + struct main0_out + { + float3 v_view_pos [[user(locn0)]]; + float3 v_world_normal [[user(locn1)]]; + float4 v_base_color [[user(locn2)]]; + float4 v_material [[user(locn3)]]; + float4 gl_Position [[position]]; + }; + + struct main0_in + { + float3 in_pos [[attribute(0)]]; + float3 in_normal [[attribute(1)]]; + }; + + vertex main0_out main0(main0_in in [[stage_in]], constant ub_frame& _125 [[buffer(0)]], constant ub_draw& _21 [[buffer(2)]], const device instances& _15 [[buffer(8)]], uint gl_InstanceIndex [[instance_id]]) + { + main0_out out = {}; + int _30 = _21.inst_base.x + int(gl_InstanceIndex); + float4 _68 = float4(in.in_pos * _15.items[_30].scale.xyz, 1.0); + float _73 = dot(_15.items[_30].xform_row0, _68); + float _77 = dot(_15.items[_30].xform_row1, _68); + float _81 = dot(_15.items[_30].xform_row2, _68); + float3 _89 = in.in_normal / _15.items[_30].scale.xyz; + out.v_world_normal = float3(dot(_15.items[_30].xform_row0.xyz, _89), dot(_15.items[_30].xform_row1.xyz, _89), dot(_15.items[_30].xform_row2.xyz, _89)); + out.v_base_color = _15.items[_30].base_color; + out.v_material = _15.items[_30].material; + out.gl_Position = _125.view_proj * float4(_73, _77, _81, 1.0); + out.v_view_pos = float3(_73, _77, _81); + return out; + } + +*/ +static const uint8_t geom_vs_source_metal_macos[1633] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x73,0x63,0x61,0x6c,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a, + 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x20,0x69,0x74,0x65,0x6d,0x73,0x5b,0x31,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73, + 0x74,0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x34,0x20,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61, + 0x73,0x65,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75, + 0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a, + 0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69, + 0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x20,0x5b, + 0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72, + 0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x32,0x29, + 0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76, + 0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72, + 0x28,0x6c,0x6f,0x63,0x6e,0x33,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f, + 0x6e,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x3b,0x0a, + 0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30, + 0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x5b,0x5b,0x61,0x74,0x74,0x72,0x69,0x62, + 0x75,0x74,0x65,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x20,0x5b, + 0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28,0x31,0x29,0x5d,0x5d,0x3b, + 0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,0x65,0x78,0x20,0x6d,0x61,0x69,0x6e, + 0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e, + 0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f, + 0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75, + 0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x26,0x20,0x5f,0x31,0x32,0x35,0x20,0x5b,0x5b, + 0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x26,0x20,0x5f, + 0x32,0x31,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x32,0x29,0x5d,0x5d, + 0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x20,0x69, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x26,0x20,0x5f,0x31,0x35,0x20,0x5b,0x5b, + 0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x38,0x29,0x5d,0x5d,0x2c,0x20,0x75,0x69,0x6e, + 0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64, + 0x65,0x78,0x20,0x5b,0x5b,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x5f,0x69,0x64, + 0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f, + 0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x33,0x30,0x20,0x3d,0x20,0x5f,0x32,0x31,0x2e, + 0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x69,0x6e, + 0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64, + 0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x5f,0x36,0x38,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x69,0x6e,0x2e, + 0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65, + 0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x73,0x63,0x61,0x6c,0x65,0x2e,0x78,0x79, + 0x7a,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x37,0x33,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35, + 0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2c,0x20,0x5f,0x36,0x38,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x37,0x20,0x3d,0x20,0x64,0x6f, + 0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d, + 0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2c,0x20,0x5f,0x36,0x38, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x31, + 0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73, + 0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32, + 0x2c,0x20,0x5f,0x36,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x5f,0x38,0x39,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x69,0x6e,0x5f,0x6e, + 0x6f,0x72,0x6d,0x61,0x6c,0x20,0x2f,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d, + 0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x73,0x63,0x61,0x6c,0x65,0x2e,0x78,0x79,0x7a, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b, + 0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e, + 0x78,0x79,0x7a,0x2c,0x20,0x5f,0x38,0x39,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f, + 0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x38, + 0x39,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d, + 0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77, + 0x32,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x38,0x39,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f, + 0x33,0x30,0x5d,0x2e,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69, + 0x61,0x6c,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f, + 0x33,0x30,0x5d,0x2e,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f, + 0x6e,0x20,0x3d,0x20,0x5f,0x31,0x32,0x35,0x2e,0x76,0x69,0x65,0x77,0x5f,0x70,0x72, + 0x6f,0x6a,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x37,0x33,0x2c, + 0x20,0x5f,0x37,0x37,0x2c,0x20,0x5f,0x38,0x31,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x70,0x6f,0x73,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x37,0x33, + 0x2c,0x20,0x5f,0x37,0x37,0x2c,0x20,0x5f,0x38,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a, + 0x00, +}; +/* + #pragma clang diagnostic ignored "-Wmissing-prototypes" + #pragma clang diagnostic ignored "-Wmissing-braces" + + #include + #include + + using namespace metal; + + template + struct spvUnsafeArray + { + T elements[Num ? Num : 1]; + + thread T& operator [] (size_t pos) thread + { + return elements[pos]; + } + constexpr const thread T& operator [] (size_t pos) const thread + { + return elements[pos]; + } + + device T& operator [] (size_t pos) device + { + return elements[pos]; + } + constexpr const device T& operator [] (size_t pos) const device + { + return elements[pos]; + } + + constexpr const constant T& operator [] (size_t pos) const constant + { + return elements[pos]; + } + + threadgroup T& operator [] (size_t pos) threadgroup + { + return elements[pos]; + } + constexpr const threadgroup T& operator [] (size_t pos) const threadgroup + { + return elements[pos]; + } + }; + + struct ub_pass + { + float4 sun_dir_world; + float4 sun_color; + int4 flags; + float4 camera_pos; + float4x4 view; + float4 cascade_far_view_z; + float4x4 cascade_matrices[3]; + float4 sh[9]; + float4 ibl_params; + }; + + struct main0_out + { + float4 out_color [[color(0)]]; + }; + + struct main0_in + { + float3 v_view_pos [[user(locn0)]]; + float3 v_world_normal [[user(locn1)]]; + float4 v_base_color [[user(locn2), flat]]; + float4 v_material [[user(locn3), flat]]; + }; + + static inline __attribute__((always_inline)) + float3 proceduralGrid(thread const float2& world_xz, thread const float3& base_color, thread const float& cell_size) + { + float2 _535 = world_xz / float2(cell_size); + float2 _551 = abs(fract(_535 - float2(0.5)) - float2(0.5)) / fast::max(fwidth(_535), float2(9.9999999747524270787835121154785e-07)); + float2 _566 = world_xz / float2(cell_size * 10.0); + float2 _580 = abs(fract(_566 - float2(0.5)) - float2(0.5)) / fast::max(fwidth(_566), float2(9.9999999747524270787835121154785e-07)); + float2 _611 = fast::max(fwidth(world_xz), float2(9.9999999747524270787835121154785e-07)); + return mix(mix(mix(mix(base_color, base_color * 0.699999988079071044921875, float3(1.0 - fast::clamp(fast::min(_551.x, _551.y), 0.0, 1.0))), base_color * 0.3499999940395355224609375, float3(1.0 - fast::clamp(fast::min(_580.x, _580.y), 0.0, 1.0))), float3(1.0, 0.0, 0.0), float3((1.0 - fast::clamp(abs(world_xz.y) / _611.y, 0.0, 1.0)) * step(0.0, world_xz.x))), float3(0.0, 0.0, 1.0), float3((1.0 - fast::clamp(abs(world_xz.x) / _611.x, 0.0, 1.0)) * step(0.0, world_xz.y))); + } + + static inline __attribute__((always_inline)) + float sampleShadowPCF(thread const int& cascade, thread const float3& light_uv, thread const float& bias0, depth2d_array tex_shadow, sampler smp_shadow) + { + float _655 = float(cascade); + float _660 = light_uv.z - bias0; + float _676 = light_uv.x - 0.00048828125; + float _680 = light_uv.y - 0.00048828125; + float4 _683 = float4(_676, _680, _655, _660); + float4 _699 = float4(light_uv.x, _680, _655, _660); + float _710 = light_uv.x + 0.00048828125; + float4 _717 = float4(_710, _680, _655, _660); + float4 _733 = float4(_676, light_uv.y, _655, _660); + float4 _747 = float4(light_uv.xy, _655, _660); + float4 _763 = float4(_710, light_uv.y, _655, _660); + float _778 = light_uv.y + 0.00048828125; + float4 _781 = float4(_676, _778, _655, _660); + float4 _797 = float4(light_uv.x, _778, _655, _660); + float4 _815 = float4(_710, _778, _655, _660); + return ((((((((tex_shadow.sample_compare(smp_shadow, _683.xy, uint(rint(_683.z)), _660) + tex_shadow.sample_compare(smp_shadow, _699.xy, uint(rint(_699.z)), _660)) + tex_shadow.sample_compare(smp_shadow, _717.xy, uint(rint(_717.z)), _660)) + tex_shadow.sample_compare(smp_shadow, _733.xy, uint(rint(_733.z)), _660)) + tex_shadow.sample_compare(smp_shadow, _747.xy, uint(rint(_747.z)), _660)) + tex_shadow.sample_compare(smp_shadow, _763.xy, uint(rint(_763.z)), _660)) + tex_shadow.sample_compare(smp_shadow, _781.xy, uint(rint(_781.z)), _660)) + tex_shadow.sample_compare(smp_shadow, _797.xy, uint(rint(_797.z)), _660)) + tex_shadow.sample_compare(smp_shadow, _815.xy, uint(rint(_815.z)), _660)) * 0.111111111938953399658203125; + } + + static inline __attribute__((always_inline)) + float sampleCascade(thread const int& cascade, thread const float3& world_pos, thread const float3& world_normal, depth2d_array tex_shadow, sampler smp_shadow, constant ub_pass& _833) + { + float4 _843 = _833.cascade_matrices[cascade] * float4(world_pos, 1.0); + float3 _850 = _843.xyz / float3(_843.w); + float3 _868 = float3((_850.x * 0.5) + 0.5, ((_850.y * _833.cascade_far_view_z.w) * 0.5) + 0.5, _850.z); + bool _872 = any(_868 < float3(0.0)); + bool _879; + if (!_872) + { + _879 = any(_868 > float3(1.0)); + } + else + { + _879 = _872; + } + if (_879) + { + return 1.0; + } + int param = cascade; + float3 param_1 = _868; + float param_2 = mix(0.0040000001899898052215576171875, 0.0007999999797903001308441162109375, fast::max(dot(world_normal, fast::normalize(_833.sun_dir_world.xyz)), 0.0)); + float pcf = sampleShadowPCF(param, param_1, param_2, tex_shadow, smp_shadow); + if (cascade == 2) + { + float2 _911 = _868.xy; + float2 _916 = fast::min(_911, float2(1.0) - _911); + pcf = mix(1.0, pcf, fast::clamp(fast::min(_916.x, _916.y) * 10.0, 0.0, 1.0)); + } + return pcf; + } + + static inline __attribute__((always_inline)) + float sampleShadowCascaded(thread const float3& world_pos, thread const float3& world_normal, thread const float& view_z, depth2d_array tex_shadow, sampler smp_shadow, constant ub_pass& _833) + { + int cascade = 2; + if (view_z < _833.cascade_far_view_z.x) + { + cascade = 0; + } + else + { + if (view_z < _833.cascade_far_view_z.y) + { + cascade = 1; + } + } + int param = cascade; + float3 param_1 = world_pos; + float3 param_2 = world_normal; + float shadow = sampleCascade(param, param_1, param_2, tex_shadow, smp_shadow, _833); + if (cascade < 2) + { + float _960; + if (cascade == 0) + { + _960 = _833.cascade_far_view_z.x; + } + else + { + _960 = _833.cascade_far_view_z.y; + } + float _972; + if (cascade == 0) + { + _972 = 0.0; + } + else + { + _972 = _833.cascade_far_view_z.x; + } + float _983 = mix(_960, _972, 0.100000001490116119384765625); + if (view_z > _983) + { + int param_3 = cascade + 1; + float3 param_4 = world_pos; + float3 param_5 = world_normal; + shadow = mix(shadow, sampleCascade(param_3, param_4, param_5, tex_shadow, smp_shadow, _833), (view_z - _983) / (_960 - _983)); + } + } + return shadow; + } + + static inline __attribute__((always_inline)) + float pbrDistributionGGX(thread const float& n_dot_h, thread const float& alpha) + { + float _115 = alpha * alpha; + float _124 = ((n_dot_h * n_dot_h) * (_115 - 1.0)) + 1.0; + return _115 / ((3.1415927410125732421875 * _124) * _124); + } + + static inline __attribute__((always_inline)) + float pbrVisibilitySmithCorrelated(thread const float& n_dot_v, thread const float& n_dot_l, thread const float& alpha) + { + float _137 = alpha * alpha; + float _144 = 1.0 - _137; + return 0.5 / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _144) + _137)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _144) + _137))) + 9.9999997473787516355514526367188e-06); + } + + static inline __attribute__((always_inline)) + float3 pbrFresnelSchlick(thread const float& v_dot_h, thread const float3& f0) + { + float _173 = 1.0 - v_dot_h; + float _177 = _173 * _173; + return f0 + ((float3(1.0) - f0) * ((_177 * _177) * _173)); + } + + static inline __attribute__((always_inline)) + float3 brdf_evaluate(thread const float3& N, thread const float3& V, thread const float3& L, thread const float3& sun_radiance, thread const float3& base_color, thread const float& metallic, thread const float& roughness) + { + float _196 = fast::max(dot(N, L), 0.0); + float3 _207 = fast::normalize(V + L); + float _221 = fast::max(roughness, 0.04500000178813934326171875); + float _225 = _221 * _221; + float param = fast::max(dot(N, _207), 0.0); + float param_1 = _225; + float param_2 = fast::max(dot(N, V), 9.9999997473787516355514526367188e-05); + float param_3 = _196; + float param_4 = _225; + float param_5 = fast::max(dot(V, _207), 0.0); + float3 param_6 = mix(float3(0.039999999105930328369140625), base_color, float3(metallic)); + float3 _252 = pbrFresnelSchlick(param_5, param_6); + return ((((((float3(1.0) - _252) * (1.0 - metallic)) * base_color) * float3(0.3183098733425140380859375)) + (_252 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _196; + } + + static inline __attribute__((always_inline)) + float3 pbrEvaluateShIrradiance(thread const float3& N, thread const spvUnsafeArray& sh) + { + float3 _407 = ((((((((sh[0].xyz * 0.2820948064327239990234375) + (sh[1].xyz * ((-0.48860251903533935546875) * N.y))) + (sh[2].xyz * (0.48860251903533935546875 * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125 * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125 * (((3.0 * N.z) * N.z) - 1.0)))) + (sh[7].xyz * (((-1.09254848957061767578125) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625 * ((N.x * N.x) - (N.y * N.y)))); + return _407; + } + + static inline __attribute__((always_inline)) + float3 pbrEvaluateIbl(thread const float3& N_world, thread const float3& V_world, thread const float3& base_color, thread const float& metallic, thread const float& roughness, thread const spvUnsafeArray& sh, texturecube tex_spec_cube, sampler smp_spec_cube, texture2d tex_brdf_lut, sampler smp_brdf_lut, thread const float& max_lod) + { + float _414 = fast::clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05, 1.0); + float3 _424 = mix(float3(0.039999999105930328369140625), base_color, float3(metallic)); + float3 param = N_world; + spvUnsafeArray param_1 = sh; + float4 _488 = tex_brdf_lut.sample(smp_brdf_lut, float2(_414, roughness)); + return (((((float3(1.0) - (_424 + ((fast::max(float3(1.0 - roughness), _424) - _424) * powr(fast::max(0.0, 1.0 - _414), 5.0)))) * (1.0 - metallic)) * base_color) * fast::max(pbrEvaluateShIrradiance(param, param_1), float3(0.0))) * float3(0.3183098733425140380859375)) + (tex_spec_cube.sample(smp_spec_cube, reflect(-V_world, N_world), level(roughness * max_lod)).xyz * ((_424 * _488.x) + float3(_488.y))); + } + + static inline __attribute__((always_inline)) + float3 pbrEvaluateAmbient(thread const bool& iblEnabled, thread const float3& N_world, thread const float3& V_world, thread const float3& base_color, thread const float& metallic, thread const float& roughness, thread const float& flat_strength, thread const spvUnsafeArray& sh, texturecube tex_spec_cube, sampler smp_spec_cube, texture2d tex_brdf_lut, sampler smp_brdf_lut, thread const float& max_lod) + { + float3 result = base_color * flat_strength; + if (iblEnabled) + { + float3 param = N_world; + float3 param_1 = V_world; + float3 param_2 = base_color; + float param_3 = metallic; + float param_4 = roughness; + spvUnsafeArray param_5 = sh; + float param_6 = max_lod; + result = pbrEvaluateIbl(param, param_1, param_2, param_3, param_4, param_5, tex_spec_cube, smp_spec_cube, tex_brdf_lut, smp_brdf_lut, param_6); + } + return result; + } + + fragment main0_out main0(main0_in in [[stage_in]], constant ub_pass& _833 [[buffer(1)]], depth2d_array tex_shadow [[texture(0)]], texturecube tex_ibl_spec [[texture(1)]], texture2d tex_brdf_lut [[texture(2)]], texture2d tex_ao [[texture(3)]], sampler smp_shadow [[sampler(0)]], sampler smp_ibl_spec [[sampler(1)]], sampler smp_brdf_lut [[sampler(2)]], sampler smp_ao [[sampler(3)]], float4 gl_FragCoord [[position]]) + { + main0_out out = {}; + float3 _1015 = fast::normalize(in.v_world_normal); + float3 n_world = _1015; + float3 _1022 = _833.camera_pos.xyz - in.v_view_pos; + if (dot(_1015, _1022) < 0.0) + { + n_world = -n_world; + } + if (_833.flags.x == 1) + { + float _1053 = fast::clamp((_833.view * float4(in.v_view_pos, 1.0)).z * (-0.0199999995529651641845703125), 0.0, 1.0); + out.out_color = float4(_1053, _1053, _1053, 1.0); + return out; + } + if (_833.flags.x == 2) + { + float4 _1071 = float4(in.v_view_pos, 1.0); + float _1074 = -(_833.view * _1071).z; + int cascade = 2; + if (_1074 < _833.cascade_far_view_z.x) + { + cascade = 0; + } + else + { + if (_1074 < _833.cascade_far_view_z.y) + { + cascade = 1; + } + } + float4 _1098 = _833.cascade_matrices[cascade] * _1071; + float3 _1105 = _1098.xyz / float3(_1098.w); + float3 _1122 = float3((_1105.x * 0.5) + 0.5, ((_1105.y * _833.cascade_far_view_z.w) * 0.5) + 0.5, _1105.z); + bool _1126 = any(_1122 < float3(0.0)); + bool _1133; + if (!_1126) + { + _1133 = any(_1122 > float3(1.0)); + } + else + { + _1133 = _1126; + } + float3 tint = float3(1.0); + if (!_1133) + { + if (cascade == 0) + { + tint = float3(1.0, 0.4000000059604644775390625, 0.4000000059604644775390625); + } + else + { + if (cascade == 1) + { + tint = float3(0.4000000059604644775390625, 1.0, 0.4000000059604644775390625); + } + else + { + tint = float3(0.4000000059604644775390625, 0.4000000059604644775390625, 1.0); + } + } + } + out.out_color = float4(tint, 1.0); + return out; + } + if (_833.flags.x == 3) + { + out.out_color = float4((fast::normalize((_833.view * float4(n_world, 0.0)).xyz) * 0.5) + float3(0.5), 1.0); + return out; + } + float4 _1204 = tex_ao.sample(smp_ao, (gl_FragCoord.xy / float2(int2(tex_ao.get_width(), tex_ao.get_height()))), level(0.0)); + float _1205 = _1204.x; + if (_833.flags.x == 4) + { + out.out_color = float4(_1205, _1205, _1205, 1.0); + return out; + } + float3 baseColor = in.v_base_color.xyz; + if (in.v_material.z > 0.5) + { + float2 param = in.v_view_pos.xz; + float3 param_1 = in.v_base_color.xyz; + float param_2 = in.v_material.w; + baseColor = mix(in.v_base_color.xyz, proceduralGrid(param, param_1, param_2), float3(powr(fast::clamp(n_world.y, 0.0, 1.0), 8.0))); + } + float3 param_3 = in.v_view_pos; + float3 param_4 = n_world; + float param_5 = -(_833.view * float4(in.v_view_pos, 1.0)).z; + float3 _1289 = fast::normalize(_1022); + float3 param_6 = n_world; + float3 param_7 = _1289; + float3 param_8 = fast::normalize(_833.sun_dir_world.xyz); + float3 param_9 = _833.sun_color.xyz * sampleShadowCascaded(param_3, param_4, param_5, tex_shadow, smp_shadow, _833); + float3 param_10 = baseColor; + float param_11 = in.v_material.x; + float param_12 = in.v_material.y; + bool param_13 = _833.ibl_params.y > 0.5; + float3 param_14 = n_world; + float3 param_15 = _1289; + float3 param_16 = baseColor; + float param_17 = in.v_material.x; + float param_18 = in.v_material.y; + float param_19 = _833.sun_color.w; + spvUnsafeArray param_20; + param_20[0] = _833.sh[0]; + param_20[1] = _833.sh[1]; + param_20[2] = _833.sh[2]; + param_20[3] = _833.sh[3]; + param_20[4] = _833.sh[4]; + param_20[5] = _833.sh[5]; + param_20[6] = _833.sh[6]; + param_20[7] = _833.sh[7]; + param_20[8] = _833.sh[8]; + float param_21 = _833.ibl_params.x; + out.out_color = float4((brdf_evaluate(param_6, param_7, param_8, param_9, param_10, param_11, param_12) + (pbrEvaluateAmbient(param_13, param_14, param_15, param_16, param_17, param_18, param_19, param_20, tex_ibl_spec, smp_ibl_spec, tex_brdf_lut, smp_brdf_lut, param_21) * _1205)) * in.v_base_color.w, in.v_base_color.w); + return out; + } + +*/ +static const uint8_t geom_fs_source_metal_macos[16552] = { + 0x23,0x70,0x72,0x61,0x67,0x6d,0x61,0x20,0x63,0x6c,0x61,0x6e,0x67,0x20,0x64,0x69, + 0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x20,0x69,0x67,0x6e,0x6f,0x72,0x65,0x64, + 0x20,0x22,0x2d,0x57,0x6d,0x69,0x73,0x73,0x69,0x6e,0x67,0x2d,0x70,0x72,0x6f,0x74, + 0x6f,0x74,0x79,0x70,0x65,0x73,0x22,0x0a,0x23,0x70,0x72,0x61,0x67,0x6d,0x61,0x20, + 0x63,0x6c,0x61,0x6e,0x67,0x20,0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63, + 0x20,0x69,0x67,0x6e,0x6f,0x72,0x65,0x64,0x20,0x22,0x2d,0x57,0x6d,0x69,0x73,0x73, + 0x69,0x6e,0x67,0x2d,0x62,0x72,0x61,0x63,0x65,0x73,0x22,0x0a,0x0a,0x23,0x69,0x6e, + 0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f,0x73,0x74,0x64, + 0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x73, + 0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a,0x75,0x73,0x69, + 0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20,0x6d,0x65,0x74, + 0x61,0x6c,0x3b,0x0a,0x0a,0x74,0x65,0x6d,0x70,0x6c,0x61,0x74,0x65,0x3c,0x74,0x79, + 0x70,0x65,0x6e,0x61,0x6d,0x65,0x20,0x54,0x2c,0x20,0x73,0x69,0x7a,0x65,0x5f,0x74, + 0x20,0x4e,0x75,0x6d,0x3e,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x73,0x70,0x76, + 0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x54,0x20,0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x4e,0x75,0x6d, + 0x20,0x3f,0x20,0x4e,0x75,0x6d,0x20,0x3a,0x20,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x0a,0x20,0x20,0x20,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x54,0x26,0x20, + 0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72,0x20,0x5b,0x5d,0x20,0x28,0x73,0x69,0x7a, + 0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f, + 0x73,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x65,0x78,0x70,0x72,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x74,0x68, + 0x72,0x65,0x61,0x64,0x20,0x54,0x26,0x20,0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72, + 0x20,0x5b,0x5d,0x20,0x28,0x73,0x69,0x7a,0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f,0x73,0x5d, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x0a,0x20,0x20,0x20, + 0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x20,0x54,0x26,0x20,0x6f,0x70,0x65,0x72,0x61, + 0x74,0x6f,0x72,0x20,0x5b,0x5d,0x20,0x28,0x73,0x69,0x7a,0x65,0x5f,0x74,0x20,0x70, + 0x6f,0x73,0x29,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f,0x73,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6e,0x73,0x74,0x65,0x78, + 0x70,0x72,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x20, + 0x54,0x26,0x20,0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72,0x20,0x5b,0x5d,0x20,0x28, + 0x73,0x69,0x7a,0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x65,0x6c, + 0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f,0x73,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x65,0x78,0x70,0x72,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x61,0x6e,0x74,0x20,0x54,0x26,0x20,0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72, + 0x20,0x5b,0x5d,0x20,0x28,0x73,0x69,0x7a,0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f, + 0x73,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x0a,0x20, + 0x20,0x20,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x67,0x72,0x6f,0x75,0x70,0x20,0x54, + 0x26,0x20,0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72,0x20,0x5b,0x5d,0x20,0x28,0x73, + 0x69,0x7a,0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x67,0x72,0x6f,0x75,0x70,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x65,0x6c,0x65,0x6d, + 0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f,0x73,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6e,0x73,0x74,0x65,0x78,0x70,0x72,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x67,0x72,0x6f,0x75,0x70, + 0x20,0x54,0x26,0x20,0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72,0x20,0x5b,0x5d,0x20, + 0x28,0x73,0x69,0x7a,0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x67,0x72,0x6f,0x75,0x70,0x0a,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f,0x73, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72, + 0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x6e,0x74,0x34,0x20,0x66,0x6c,0x61,0x67,0x73,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f, + 0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78, + 0x34,0x20,0x76,0x69,0x65,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x78,0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72, + 0x69,0x63,0x65,0x73,0x5b,0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73, + 0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69, + 0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b, + 0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a, + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c, + 0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d, + 0x61,0x6c,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29, + 0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76, + 0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73, + 0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x32,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f, + 0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28, + 0x6c,0x6f,0x63,0x6e,0x33,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a, + 0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e, + 0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28, + 0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29, + 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x72,0x6f,0x63,0x65,0x64,0x75,0x72, + 0x61,0x6c,0x47,0x72,0x69,0x64,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x26,0x20,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x78,0x7a,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x62,0x61,0x73,0x65,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x63,0x65,0x6c,0x6c,0x5f, + 0x73,0x69,0x7a,0x65,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x32,0x20,0x5f,0x35,0x33,0x35,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x78,0x7a,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x63,0x65,0x6c,0x6c, + 0x5f,0x73,0x69,0x7a,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x32,0x20,0x5f,0x35,0x35,0x31,0x20,0x3d,0x20,0x61,0x62,0x73,0x28,0x66,0x72, + 0x61,0x63,0x74,0x28,0x5f,0x35,0x33,0x35,0x20,0x2d,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, + 0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2f,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d, + 0x61,0x78,0x28,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x35,0x33,0x35,0x29,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39, + 0x39,0x37,0x34,0x37,0x35,0x32,0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38,0x33,0x35, + 0x31,0x32,0x31,0x31,0x35,0x34,0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x29,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x35,0x36,0x36, + 0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x78,0x7a,0x20,0x2f,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x32,0x28,0x63,0x65,0x6c,0x6c,0x5f,0x73,0x69,0x7a,0x65,0x20,0x2a, + 0x20,0x31,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x32,0x20,0x5f,0x35,0x38,0x30,0x20,0x3d,0x20,0x61,0x62,0x73,0x28,0x66,0x72, + 0x61,0x63,0x74,0x28,0x5f,0x35,0x36,0x36,0x20,0x2d,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, + 0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2f,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d, + 0x61,0x78,0x28,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x35,0x36,0x36,0x29,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39, + 0x39,0x37,0x34,0x37,0x35,0x32,0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38,0x33,0x35, + 0x31,0x32,0x31,0x31,0x35,0x34,0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x29,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x36,0x31,0x31, + 0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x66,0x77,0x69, + 0x64,0x74,0x68,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x78,0x7a,0x29,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x32,0x28,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37, + 0x34,0x37,0x35,0x32,0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38,0x33,0x35,0x31,0x32, + 0x31,0x31,0x35,0x34,0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6d,0x69,0x78,0x28,0x6d,0x69, + 0x78,0x28,0x6d,0x69,0x78,0x28,0x6d,0x69,0x78,0x28,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x2a,0x20,0x30,0x2e,0x36,0x39,0x39,0x39,0x39,0x39,0x39,0x38,0x38,0x30,0x37, + 0x39,0x30,0x37,0x31,0x30,0x34,0x34,0x39,0x32,0x31,0x38,0x37,0x35,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x66,0x61,0x73,0x74, + 0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x69, + 0x6e,0x28,0x5f,0x35,0x35,0x31,0x2e,0x78,0x2c,0x20,0x5f,0x35,0x35,0x31,0x2e,0x79, + 0x29,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x29,0x2c,0x20, + 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x30,0x2e,0x33, + 0x34,0x39,0x39,0x39,0x39,0x39,0x39,0x34,0x30,0x33,0x39,0x35,0x33,0x35,0x35,0x32, + 0x32,0x34,0x36,0x30,0x39,0x33,0x37,0x35,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61, + 0x6d,0x70,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x69,0x6e,0x28,0x5f,0x35,0x38, + 0x30,0x2e,0x78,0x2c,0x20,0x5f,0x35,0x38,0x30,0x2e,0x79,0x29,0x2c,0x20,0x30,0x2e, + 0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x28,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x29, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20, + 0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x61,0x62,0x73,0x28, + 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x78,0x7a,0x2e,0x79,0x29,0x20,0x2f,0x20,0x5f,0x36, + 0x31,0x31,0x2e,0x79,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29, + 0x20,0x2a,0x20,0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30,0x2c,0x20,0x77,0x6f,0x72, + 0x6c,0x64,0x5f,0x78,0x7a,0x2e,0x78,0x29,0x29,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x31,0x2e,0x30,0x20,0x2d, + 0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x61,0x62,0x73, + 0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x78,0x7a,0x2e,0x78,0x29,0x20,0x2f,0x20,0x5f, + 0x36,0x31,0x31,0x2e,0x78,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29, + 0x29,0x20,0x2a,0x20,0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30,0x2c,0x20,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x78,0x7a,0x2e,0x79,0x29,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a, + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f, + 0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77, + 0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50, + 0x43,0x46,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, + 0x69,0x6e,0x74,0x26,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x74,0x68, + 0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x26,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2c,0x20,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26, + 0x20,0x62,0x69,0x61,0x73,0x30,0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f, + 0x61,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72, + 0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x35,0x35,0x20,0x3d,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x36,0x30,0x20,0x3d, + 0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x7a,0x20,0x2d,0x20,0x62,0x69, + 0x61,0x73,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x36,0x37,0x36,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78, + 0x20,0x2d,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x38,0x30, + 0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x20,0x2d,0x20, + 0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36,0x38,0x33,0x20,0x3d, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x36,0x37,0x36,0x2c,0x20,0x5f,0x36, + 0x38,0x30,0x2c,0x20,0x5f,0x36,0x35,0x35,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36,0x39,0x39, + 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f, + 0x75,0x76,0x2e,0x78,0x2c,0x20,0x5f,0x36,0x38,0x30,0x2c,0x20,0x5f,0x36,0x35,0x35, + 0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x37,0x31,0x30,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f, + 0x75,0x76,0x2e,0x78,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32, + 0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x5f,0x37,0x31,0x37,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f, + 0x37,0x31,0x30,0x2c,0x20,0x5f,0x36,0x38,0x30,0x2c,0x20,0x5f,0x36,0x35,0x35,0x2c, + 0x20,0x5f,0x36,0x36,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x5f,0x37,0x33,0x33,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x28,0x5f,0x36,0x37,0x36,0x2c,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e, + 0x79,0x2c,0x20,0x5f,0x36,0x35,0x35,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x34,0x37,0x20, + 0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75, + 0x76,0x2e,0x78,0x79,0x2c,0x20,0x5f,0x36,0x35,0x35,0x2c,0x20,0x5f,0x36,0x36,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37, + 0x36,0x33,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x37,0x31,0x30, + 0x2c,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x5f,0x36, + 0x35,0x35,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x37,0x38,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68, + 0x74,0x5f,0x75,0x76,0x2e,0x79,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38, + 0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x5f,0x37,0x38,0x31,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x28,0x5f,0x36,0x37,0x36,0x2c,0x20,0x5f,0x37,0x37,0x38,0x2c,0x20,0x5f,0x36,0x35, + 0x35,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x39,0x37,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20,0x5f, + 0x37,0x37,0x38,0x2c,0x20,0x5f,0x36,0x35,0x35,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x38,0x31, + 0x35,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x37,0x31,0x30,0x2c, + 0x20,0x5f,0x37,0x37,0x38,0x2c,0x20,0x5f,0x36,0x35,0x35,0x2c,0x20,0x5f,0x36,0x36, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28, + 0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65, + 0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x36,0x38, + 0x33,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28, + 0x5f,0x36,0x38,0x33,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x20, + 0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x36,0x39,0x39,0x2e,0x78,0x79,0x2c, + 0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x36,0x39,0x39,0x2e, + 0x7a,0x29,0x29,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x29,0x20,0x2b,0x20,0x74,0x65, + 0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f, + 0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x2c,0x20,0x5f,0x37,0x31,0x37,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e, + 0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x37,0x31,0x37,0x2e,0x7a,0x29,0x29,0x2c, + 0x20,0x5f,0x36,0x36,0x30,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68, + 0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70, + 0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20, + 0x5f,0x37,0x33,0x33,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69, + 0x6e,0x74,0x28,0x5f,0x37,0x33,0x33,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x36,0x36, + 0x30,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28, + 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x37,0x34,0x37, + 0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f, + 0x37,0x34,0x37,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x29,0x20, + 0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x37,0x36,0x33,0x2e,0x78,0x79,0x2c, + 0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x37,0x36,0x33,0x2e, + 0x7a,0x29,0x29,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x29,0x20,0x2b,0x20,0x74,0x65, + 0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f, + 0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x2c,0x20,0x5f,0x37,0x38,0x31,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e, + 0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x37,0x38,0x31,0x2e,0x7a,0x29,0x29,0x2c, + 0x20,0x5f,0x36,0x36,0x30,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68, + 0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70, + 0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20, + 0x5f,0x37,0x39,0x37,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69, + 0x6e,0x74,0x28,0x5f,0x37,0x39,0x37,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x36,0x36, + 0x30,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28, + 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x38,0x31,0x35, + 0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f, + 0x38,0x31,0x35,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x36,0x36,0x30,0x29,0x29,0x20, + 0x2a,0x20,0x30,0x2e,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x39,0x33,0x38, + 0x39,0x35,0x33,0x33,0x39,0x39,0x36,0x35,0x38,0x32,0x30,0x33,0x31,0x32,0x35,0x3b, + 0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e, + 0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28, + 0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29, + 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73, + 0x63,0x61,0x64,0x65,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x69,0x6e,0x74,0x26,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20, + 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x26,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20, + 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x26,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61,0x79, + 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74, + 0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x38,0x33,0x33,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x38,0x34, + 0x33,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x5d,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x38,0x35,0x30,0x20,0x3d,0x20,0x5f, + 0x38,0x34,0x33,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x28,0x5f,0x38,0x34,0x33,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x5f,0x38,0x36,0x38,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x28,0x5f,0x38,0x35,0x30,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35, + 0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x28,0x28,0x5f,0x38,0x35,0x30,0x2e, + 0x79,0x20,0x2a,0x20,0x5f,0x38,0x33,0x33,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a, + 0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x38,0x35, + 0x30,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f, + 0x38,0x37,0x32,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x5f,0x38,0x36,0x38,0x20,0x3c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x38,0x37,0x39,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x38,0x37,0x32,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x37,0x39,0x20, + 0x3d,0x20,0x61,0x6e,0x79,0x28,0x5f,0x38,0x36,0x38,0x20,0x3e,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x37,0x39,0x20,0x3d,0x20,0x5f, + 0x38,0x37,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x5f,0x38,0x37,0x39,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e, + 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x38,0x36,0x38,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d, + 0x20,0x6d,0x69,0x78,0x28,0x30,0x2e,0x30,0x30,0x34,0x30,0x30,0x30,0x30,0x30,0x30, + 0x31,0x38,0x39,0x39,0x38,0x39,0x38,0x30,0x35,0x32,0x32,0x31,0x35,0x35,0x37,0x36, + 0x31,0x37,0x31,0x38,0x37,0x35,0x2c,0x20,0x30,0x2e,0x30,0x30,0x30,0x37,0x39,0x39, + 0x39,0x39,0x39,0x39,0x37,0x39,0x37,0x39,0x30,0x33,0x30,0x30,0x31,0x33,0x30,0x38, + 0x34,0x34,0x31,0x31,0x36,0x32,0x31,0x30,0x39,0x33,0x37,0x35,0x2c,0x20,0x66,0x61, + 0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a, + 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x38,0x33,0x33,0x2e,0x73, + 0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a, + 0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x70,0x61,0x72,0x61,0x6d, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20, + 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20, + 0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x39,0x31,0x31,0x20,0x3d,0x20,0x5f, + 0x38,0x36,0x38,0x2e,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x39,0x31,0x36,0x20,0x3d,0x20,0x66,0x61, + 0x73,0x74,0x3a,0x3a,0x6d,0x69,0x6e,0x28,0x5f,0x39,0x31,0x31,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x32,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x39,0x31,0x31, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x70,0x63,0x66,0x20,0x3d, + 0x20,0x6d,0x69,0x78,0x28,0x31,0x2e,0x30,0x2c,0x20,0x70,0x63,0x66,0x2c,0x20,0x66, + 0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x66,0x61,0x73,0x74,0x3a, + 0x3a,0x6d,0x69,0x6e,0x28,0x5f,0x39,0x31,0x36,0x2e,0x78,0x2c,0x20,0x5f,0x39,0x31, + 0x36,0x2e,0x79,0x29,0x20,0x2a,0x20,0x31,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30, + 0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x70,0x63,0x66,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20, + 0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61, + 0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f, + 0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x74,0x68,0x72,0x65,0x61,0x64, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x77, + 0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x77, + 0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26, + 0x20,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64, + 0x5f,0x61,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65, + 0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, + 0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20, + 0x5f,0x38,0x33,0x33,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x38, + 0x33,0x33,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d, + 0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c, + 0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x38, + 0x33,0x33,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d, + 0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x38,0x33,0x33,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x20,0x3c,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x36,0x30,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x5f,0x39,0x36,0x30,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x2e,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f, + 0x39,0x36,0x30,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x2e,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x37,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f, + 0x39,0x37,0x32,0x20,0x3d,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, + 0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x39,0x37,0x32,0x20,0x3d,0x20,0x5f, + 0x38,0x33,0x33,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x39,0x38,0x33,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x5f,0x39,0x36, + 0x30,0x2c,0x20,0x5f,0x39,0x37,0x32,0x2c,0x20,0x30,0x2e,0x31,0x30,0x30,0x30,0x30, + 0x30,0x30,0x30,0x31,0x34,0x39,0x30,0x31,0x31,0x36,0x31,0x31,0x39,0x33,0x38,0x34, + 0x37,0x36,0x35,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3e,0x20,0x5f,0x39, + 0x38,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20, + 0x2b,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20, + 0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x6d,0x69,0x78, + 0x28,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43, + 0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35, + 0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d, + 0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x38,0x33,0x33,0x29,0x2c, + 0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x2d,0x20,0x5f,0x39,0x38,0x33,0x29, + 0x20,0x2f,0x20,0x28,0x5f,0x39,0x36,0x30,0x20,0x2d,0x20,0x5f,0x39,0x38,0x33,0x29, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x68, + 0x61,0x64,0x6f,0x77,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, + 0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75, + 0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c, + 0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x44, + 0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x74, + 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x26,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x74,0x68,0x72,0x65, + 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20, + 0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x31,0x35,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20, + 0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x32,0x34,0x20,0x3d,0x20,0x28,0x28,0x6e,0x5f,0x64,0x6f, + 0x74,0x5f,0x68,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x29,0x20,0x2a, + 0x20,0x28,0x5f,0x31,0x31,0x35,0x20,0x2d,0x20,0x31,0x2e,0x30,0x29,0x29,0x20,0x2b, + 0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x5f,0x31,0x31,0x35,0x20,0x2f,0x20,0x28,0x28,0x33,0x2e,0x31,0x34,0x31,0x35, + 0x39,0x32,0x37,0x34,0x31,0x30,0x31,0x32,0x35,0x37,0x33,0x32,0x34,0x32,0x31,0x38, + 0x37,0x35,0x20,0x2a,0x20,0x5f,0x31,0x32,0x34,0x29,0x20,0x2a,0x20,0x5f,0x31,0x32, + 0x34,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e, + 0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65, + 0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e, + 0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x56,0x69,0x73, + 0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72, + 0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6e,0x5f,0x64,0x6f,0x74, + 0x5f,0x76,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c, + 0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x26,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x37,0x20,0x3d,0x20,0x61, + 0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x34,0x20,0x3d,0x20,0x31, + 0x2e,0x30,0x20,0x2d,0x20,0x5f,0x31,0x33,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x30,0x2e,0x35,0x20,0x2f,0x20,0x28,0x28,0x28,0x6e, + 0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28, + 0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f, + 0x76,0x29,0x20,0x2a,0x20,0x5f,0x31,0x34,0x34,0x29,0x20,0x2b,0x20,0x5f,0x31,0x33, + 0x37,0x29,0x29,0x20,0x2b,0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a, + 0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20, + 0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x29,0x20,0x2a,0x20,0x5f,0x31,0x34, + 0x34,0x29,0x20,0x2b,0x20,0x5f,0x31,0x33,0x37,0x29,0x29,0x29,0x20,0x2b,0x20,0x39, + 0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31, + 0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38, + 0x65,0x2d,0x30,0x36,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63, + 0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62, + 0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e, + 0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62, + 0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28, + 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x26,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x26,0x20,0x66,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x31,0x37,0x33,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x76, + 0x5f,0x64,0x6f,0x74,0x5f,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x31,0x37,0x37,0x20,0x3d,0x20,0x5f,0x31,0x37,0x33,0x20,0x2a,0x20, + 0x5f,0x31,0x37,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x66,0x30,0x20,0x2b,0x20,0x28,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31, + 0x2e,0x30,0x29,0x20,0x2d,0x20,0x66,0x30,0x29,0x20,0x2a,0x20,0x28,0x28,0x5f,0x31, + 0x37,0x37,0x20,0x2a,0x20,0x5f,0x31,0x37,0x37,0x29,0x20,0x2a,0x20,0x5f,0x31,0x37, + 0x33,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69, + 0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74, + 0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69, + 0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x72,0x64,0x66, + 0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x74,0x68,0x72,0x65,0x61,0x64, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4e, + 0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x56,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4c, + 0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61, + 0x6e,0x63,0x65,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c, + 0x69,0x63,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73, + 0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x39,0x36,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28, + 0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x4c,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x32,0x30,0x37, + 0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69, + 0x7a,0x65,0x28,0x56,0x20,0x2b,0x20,0x4c,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x32,0x31,0x20,0x3d,0x20,0x66,0x61,0x73,0x74, + 0x3a,0x3a,0x6d,0x61,0x78,0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c, + 0x20,0x30,0x2e,0x30,0x34,0x35,0x30,0x30,0x30,0x30,0x30,0x31,0x37,0x38,0x38,0x31, + 0x33,0x39,0x33,0x34,0x33,0x32,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x32,0x35,0x20,0x3d, + 0x20,0x5f,0x32,0x32,0x31,0x20,0x2a,0x20,0x5f,0x32,0x32,0x31,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20, + 0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c, + 0x20,0x5f,0x32,0x30,0x37,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20, + 0x3d,0x20,0x5f,0x32,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x66,0x61,0x73,0x74, + 0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x56,0x29,0x2c, + 0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37, + 0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31, + 0x38,0x38,0x65,0x2d,0x30,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31,0x39, + 0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x32,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d, + 0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x56, + 0x2c,0x20,0x5f,0x32,0x30,0x37,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x36,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30, + 0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30, + 0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c,0x20,0x62, + 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x28,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x32,0x35,0x32,0x20,0x3d,0x20, + 0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63, + 0x6b,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x28,0x28,0x28,0x28,0x28,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30, + 0x29,0x20,0x2d,0x20,0x5f,0x32,0x35,0x32,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30, + 0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20, + 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33, + 0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35, + 0x29,0x29,0x20,0x2b,0x20,0x28,0x5f,0x32,0x35,0x32,0x20,0x2a,0x20,0x28,0x70,0x62, + 0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29, + 0x20,0x2a,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79, + 0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29,0x29,0x29,0x29,0x20,0x2a,0x20, + 0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x29,0x20,0x2a,0x20, + 0x5f,0x31,0x39,0x36,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, + 0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75, + 0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c, + 0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72, + 0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69, + 0x61,0x6e,0x63,0x65,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4e,0x2c,0x20,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x73,0x70,0x76,0x55,0x6e,0x73, + 0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c, + 0x20,0x39,0x3e,0x26,0x20,0x73,0x68,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x34,0x30,0x37,0x20,0x3d,0x20,0x28,0x28,0x28, + 0x28,0x28,0x28,0x28,0x28,0x73,0x68,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a, + 0x20,0x30,0x2e,0x32,0x38,0x32,0x30,0x39,0x34,0x38,0x30,0x36,0x34,0x33,0x32,0x37, + 0x32,0x33,0x39,0x39,0x39,0x30,0x32,0x33,0x34,0x33,0x37,0x35,0x29,0x20,0x2b,0x20, + 0x28,0x73,0x68,0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d, + 0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33, + 0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79, + 0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x32,0x5d,0x2e,0x78,0x79,0x7a, + 0x20,0x2a,0x20,0x28,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30, + 0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x20,0x2a,0x20, + 0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x33,0x5d,0x2e, + 0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30, + 0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38, + 0x37,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x29,0x29,0x20,0x2b,0x20,0x28, + 0x73,0x68,0x5b,0x34,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x31,0x2e, + 0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36, + 0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a, + 0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x35,0x5d, + 0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32, + 0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37, + 0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x20,0x2a,0x20,0x4e, + 0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x36,0x5d,0x2e,0x78, + 0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x33,0x31,0x35,0x33,0x39,0x31,0x35,0x37, + 0x30,0x33,0x32,0x39,0x36,0x36,0x36,0x31,0x33,0x37,0x36,0x39,0x35,0x33,0x31,0x32, + 0x35,0x20,0x2a,0x20,0x28,0x28,0x28,0x33,0x2e,0x30,0x20,0x2a,0x20,0x4e,0x2e,0x7a, + 0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x29,0x29, + 0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x37,0x5d,0x2e,0x78,0x79,0x7a,0x20, + 0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38, + 0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x29, + 0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29, + 0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x38,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, + 0x28,0x30,0x2e,0x35,0x34,0x36,0x32,0x37,0x34,0x32,0x34,0x34,0x37,0x38,0x35,0x33, + 0x30,0x38,0x38,0x33,0x37,0x38,0x39,0x30,0x36,0x32,0x35,0x20,0x2a,0x20,0x28,0x28, + 0x4e,0x2e,0x78,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2d,0x20,0x28,0x4e,0x2e, + 0x79,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x34,0x30,0x37,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f, + 0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c, + 0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65, + 0x49,0x62,0x6c,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20, + 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x26,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c, + 0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x26,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x74, + 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x26,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x74,0x68, + 0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x73,0x70,0x76,0x55,0x6e, + 0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x2c,0x20,0x39,0x3e,0x26,0x20,0x73,0x68,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72, + 0x65,0x63,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78, + 0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62, + 0x65,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f, + 0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74, + 0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72, + 0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x61,0x78,0x5f, + 0x6c,0x6f,0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x34,0x31,0x34,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c, + 0x61,0x6d,0x70,0x28,0x64,0x6f,0x74,0x28,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c, + 0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39, + 0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35, + 0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35, + 0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x5f,0x34,0x32,0x34,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39, + 0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36, + 0x32,0x35,0x29,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72, + 0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x34,0x38,0x38,0x20,0x3d,0x20,0x74,0x65, + 0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2e,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x28,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x34,0x31,0x34,0x2c,0x20,0x72,0x6f,0x75, + 0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x28,0x5f,0x34,0x32,0x34,0x20,0x2b,0x20, + 0x28,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65, + 0x73,0x73,0x29,0x2c,0x20,0x5f,0x34,0x32,0x34,0x29,0x20,0x2d,0x20,0x5f,0x34,0x32, + 0x34,0x29,0x20,0x2a,0x20,0x70,0x6f,0x77,0x72,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a, + 0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f, + 0x34,0x31,0x34,0x29,0x2c,0x20,0x35,0x2e,0x30,0x29,0x29,0x29,0x29,0x20,0x2a,0x20, + 0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29, + 0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20, + 0x2a,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x70,0x62,0x72,0x45, + 0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61, + 0x6e,0x63,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x29, + 0x29,0x29,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x33,0x31, + 0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38, + 0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x74,0x65,0x78, + 0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2e,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c, + 0x20,0x72,0x65,0x66,0x6c,0x65,0x63,0x74,0x28,0x2d,0x56,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x2c,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x6c,0x65,0x76, + 0x65,0x6c,0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x20,0x2a,0x20,0x6d, + 0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x29,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28, + 0x28,0x5f,0x34,0x32,0x34,0x20,0x2a,0x20,0x5f,0x34,0x38,0x38,0x2e,0x78,0x29,0x20, + 0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x34,0x38,0x38,0x2e,0x79,0x29, + 0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e, + 0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65, + 0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e, + 0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76, + 0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x74,0x68, + 0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x62,0x6f,0x6f,0x6c,0x26, + 0x20,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x2c,0x20,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x26,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20, + 0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20, + 0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x62,0x61, + 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x65, + 0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x72,0x6f,0x75,0x67, + 0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x66,0x6c,0x61,0x74,0x5f, + 0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65, + 0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e, + 0x26,0x20,0x73,0x68,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x63,0x75,0x62, + 0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65, + 0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20, + 0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x74, + 0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20, + 0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73,0x61, + 0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, + 0x75,0x74,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x72,0x65, + 0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x20,0x2a,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74, + 0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x62,0x6c,0x45,0x6e, + 0x61,0x62,0x6c,0x65,0x64,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x20,0x3d,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x6d,0x65,0x74,0x61, + 0x6c,0x6c,0x69,0x63,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x72,0x6f, + 0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x35,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d, + 0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x70,0x62,0x72,0x45,0x76, + 0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x74,0x65, + 0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x6d,0x70, + 0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x74,0x65,0x78,0x5f, + 0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72, + 0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x72, + 0x61,0x67,0x6d,0x65,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74, + 0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20, + 0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73, + 0x73,0x26,0x20,0x5f,0x38,0x33,0x33,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72, + 0x28,0x31,0x29,0x5d,0x5d,0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61, + 0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65, + 0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x63,0x75, + 0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x69,0x62, + 0x6c,0x5f,0x73,0x70,0x65,0x63,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65, + 0x28,0x31,0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64, + 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66, + 0x5f,0x6c,0x75,0x74,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x32, + 0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66, + 0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x20,0x5b,0x5b,0x74, + 0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x33,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x20, + 0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f, + 0x73,0x70,0x65,0x63,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x31, + 0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70, + 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x72,0x28,0x32,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, + 0x72,0x20,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x72,0x28,0x33,0x29,0x5d,0x5d,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x20,0x5b,0x5b,0x70, + 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d, + 0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x5f,0x31,0x30,0x31,0x35,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f, + 0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d, + 0x20,0x5f,0x31,0x30,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x5f,0x31,0x30,0x32,0x32,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x2e, + 0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d, + 0x20,0x69,0x6e,0x2e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x30,0x31, + 0x35,0x2c,0x20,0x5f,0x31,0x30,0x32,0x32,0x29,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x2d,0x6e,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x5f,0x38,0x33,0x33,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d, + 0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x33,0x20,0x3d,0x20, + 0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x28,0x5f,0x38,0x33, + 0x33,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, + 0x69,0x6e,0x2e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31, + 0x2e,0x30,0x29,0x29,0x2e,0x7a,0x20,0x2a,0x20,0x28,0x2d,0x30,0x2e,0x30,0x31,0x39, + 0x39,0x39,0x39,0x39,0x39,0x39,0x35,0x35,0x32,0x39,0x36,0x35,0x31,0x36,0x34,0x31, + 0x38,0x34,0x35,0x37,0x30,0x33,0x31,0x32,0x35,0x29,0x2c,0x20,0x30,0x2e,0x30,0x2c, + 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f, + 0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x30,0x35,0x33,0x2c,0x20,0x5f,0x31,0x30, + 0x35,0x33,0x2c,0x20,0x5f,0x31,0x30,0x35,0x33,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x6f,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x5f,0x38,0x33,0x33,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20, + 0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x30,0x37,0x31, + 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30, + 0x37,0x34,0x20,0x3d,0x20,0x2d,0x28,0x5f,0x38,0x33,0x33,0x2e,0x76,0x69,0x65,0x77, + 0x20,0x2a,0x20,0x5f,0x31,0x30,0x37,0x31,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x5f,0x31,0x30,0x37,0x34,0x20,0x3c,0x20,0x5f,0x38,0x33,0x33,0x2e,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x30,0x37,0x34,0x20,0x3c, + 0x20,0x5f,0x38,0x33,0x33,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61, + 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31, + 0x30,0x39,0x38,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x2e,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5d,0x20,0x2a,0x20,0x5f,0x31,0x30,0x37,0x31,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x31, + 0x30,0x35,0x20,0x3d,0x20,0x5f,0x31,0x30,0x39,0x38,0x2e,0x78,0x79,0x7a,0x20,0x2f, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x31,0x30,0x39,0x38,0x2e,0x77,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x5f,0x31,0x31,0x32,0x32,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, + 0x28,0x5f,0x31,0x31,0x30,0x35,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20, + 0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x28,0x28,0x5f,0x31,0x31,0x30,0x35,0x2e,0x79, + 0x20,0x2a,0x20,0x5f,0x38,0x33,0x33,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, + 0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20, + 0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x31,0x31,0x30, + 0x35,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f, + 0x6f,0x6c,0x20,0x5f,0x31,0x31,0x32,0x36,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x5f, + 0x31,0x31,0x32,0x32,0x20,0x3c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e, + 0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f, + 0x6c,0x20,0x5f,0x31,0x31,0x33,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x31,0x32,0x36,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x5f,0x31,0x31,0x33,0x33,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x5f, + 0x31,0x31,0x32,0x32,0x20,0x3e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e, + 0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x5f,0x31,0x31,0x33,0x33,0x20,0x3d,0x20,0x5f,0x31,0x31,0x32,0x36,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x31,0x33,0x33, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30, + 0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35, + 0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30, + 0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30, + 0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d, + 0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20, + 0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30, + 0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39, + 0x30,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30, + 0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35, + 0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39, + 0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c, + 0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34, + 0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x74,0x69,0x6e, + 0x74,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x38,0x33,0x33,0x2e, + 0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x33,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e, + 0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x28,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c, + 0x69,0x7a,0x65,0x28,0x28,0x5f,0x38,0x33,0x33,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c, + 0x20,0x30,0x2e,0x30,0x29,0x29,0x2e,0x78,0x79,0x7a,0x29,0x20,0x2a,0x20,0x30,0x2e, + 0x35,0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x35,0x29, + 0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x32, + 0x30,0x34,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20,0x28,0x67,0x6c,0x5f,0x46, + 0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x20,0x2f,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x32,0x28,0x69,0x6e,0x74,0x32,0x28,0x74,0x65,0x78,0x5f,0x61,0x6f, + 0x2e,0x67,0x65,0x74,0x5f,0x77,0x69,0x64,0x74,0x68,0x28,0x29,0x2c,0x20,0x74,0x65, + 0x78,0x5f,0x61,0x6f,0x2e,0x67,0x65,0x74,0x5f,0x68,0x65,0x69,0x67,0x68,0x74,0x28, + 0x29,0x29,0x29,0x29,0x2c,0x20,0x6c,0x65,0x76,0x65,0x6c,0x28,0x30,0x2e,0x30,0x29, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32, + 0x30,0x35,0x20,0x3d,0x20,0x5f,0x31,0x32,0x30,0x34,0x2e,0x78,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x38,0x33,0x33,0x2e,0x66,0x6c,0x61,0x67,0x73, + 0x2e,0x78,0x20,0x3d,0x3d,0x20,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x31, + 0x32,0x30,0x35,0x2c,0x20,0x5f,0x31,0x32,0x30,0x35,0x2c,0x20,0x5f,0x31,0x32,0x30, + 0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x61, + 0x73,0x65,0x43,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x62, + 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65, + 0x72,0x69,0x61,0x6c,0x2e,0x7a,0x20,0x3e,0x20,0x30,0x2e,0x35,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f, + 0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x7a,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c, + 0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x61,0x73,0x65, + 0x43,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x69,0x6e,0x2e,0x76, + 0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x2c, + 0x20,0x70,0x72,0x6f,0x63,0x65,0x64,0x75,0x72,0x61,0x6c,0x47,0x72,0x69,0x64,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x28,0x70,0x6f,0x77,0x72,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d, + 0x70,0x28,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x79,0x2c,0x20,0x30,0x2e,0x30, + 0x2c,0x20,0x31,0x2e,0x30,0x29,0x2c,0x20,0x38,0x2e,0x30,0x29,0x29,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f, + 0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x6e, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x2d,0x28,0x5f,0x38, + 0x33,0x33,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x28,0x69,0x6e,0x2e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2c,0x20, + 0x31,0x2e,0x30,0x29,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x5f,0x31,0x32,0x38,0x39,0x20,0x3d,0x20,0x66,0x61,0x73,0x74, + 0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31,0x30,0x32, + 0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x5f,0x31,0x32,0x38,0x39,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38, + 0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69, + 0x7a,0x65,0x28,0x5f,0x38,0x33,0x33,0x2e,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d, + 0x20,0x5f,0x38,0x33,0x33,0x2e,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e, + 0x78,0x79,0x7a,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64, + 0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x35,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x38, + 0x33,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x43, + 0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f, + 0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d, + 0x20,0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x33,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x2e,0x69,0x62,0x6c,0x5f,0x70, + 0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x20,0x3e,0x20,0x30,0x2e,0x35,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x34,0x20,0x3d,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x35,0x20,0x3d,0x20,0x5f,0x31,0x32,0x38,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d, + 0x20,0x62,0x61,0x73,0x65,0x43,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x20,0x3d, + 0x20,0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65, + 0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20,0x5f,0x38,0x33, + 0x33,0x2e,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61, + 0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x30,0x5b,0x30,0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x2e,0x73,0x68, + 0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x30,0x5b,0x31,0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x2e,0x73,0x68,0x5b,0x31, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b, + 0x32,0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x2e,0x73,0x68,0x5b,0x32,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x33,0x5d, + 0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x2e,0x73,0x68,0x5b,0x33,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x34,0x5d,0x20,0x3d, + 0x20,0x5f,0x38,0x33,0x33,0x2e,0x73,0x68,0x5b,0x34,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x35,0x5d,0x20,0x3d,0x20,0x5f, + 0x38,0x33,0x33,0x2e,0x73,0x68,0x5b,0x35,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x36,0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33, + 0x33,0x2e,0x73,0x68,0x5b,0x36,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x30,0x5b,0x37,0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x2e, + 0x73,0x68,0x5b,0x37,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x30,0x5b,0x38,0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x2e,0x73,0x68, + 0x5b,0x38,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x20,0x3d,0x20,0x5f,0x38,0x33,0x33,0x2e,0x69, + 0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x62,0x72,0x64,0x66,0x5f,0x65,0x76, + 0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x29,0x20,0x2b,0x20,0x28,0x70,0x62,0x72,0x45, + 0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x2c,0x20,0x74, + 0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x73,0x6d,0x70, + 0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62, + 0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64, + 0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x29, + 0x20,0x2a,0x20,0x5f,0x31,0x32,0x30,0x35,0x29,0x29,0x20,0x2a,0x20,0x69,0x6e,0x2e, + 0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x2c,0x20, + 0x69,0x6e,0x2e,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e, + 0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f, + 0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +static inline const sg_shader_desc* geom_triangle_shader_desc(sg_backend backend) { + if (backend == SG_BACKEND_GLCORE) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)geom_vs_source_glsl430; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)geom_fs_source_glsl430; + desc.fragment_func.entry = "main"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[0].glsl_name = "in_pos"; + desc.attrs[1].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[1].glsl_name = "in_normal"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[0].glsl_uniforms[0].array_count = 4; + desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_frame"; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 496; + desc.uniform_blocks[1].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[0].array_count = 0; + desc.uniform_blocks[1].glsl_uniforms[0].glsl_name = "_833.sun_dir_world"; + desc.uniform_blocks[1].glsl_uniforms[1].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[1].array_count = 0; + desc.uniform_blocks[1].glsl_uniforms[1].glsl_name = "_833.sun_color"; + desc.uniform_blocks[1].glsl_uniforms[2].type = SG_UNIFORMTYPE_INT4; + desc.uniform_blocks[1].glsl_uniforms[2].array_count = 0; + desc.uniform_blocks[1].glsl_uniforms[2].glsl_name = "_833.flags"; + desc.uniform_blocks[1].glsl_uniforms[3].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[3].array_count = 0; + desc.uniform_blocks[1].glsl_uniforms[3].glsl_name = "_833.camera_pos"; + desc.uniform_blocks[1].glsl_uniforms[4].type = SG_UNIFORMTYPE_MAT4; + desc.uniform_blocks[1].glsl_uniforms[4].array_count = 0; + desc.uniform_blocks[1].glsl_uniforms[4].glsl_name = "_833.view"; + desc.uniform_blocks[1].glsl_uniforms[5].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[5].array_count = 0; + desc.uniform_blocks[1].glsl_uniforms[5].glsl_name = "_833.cascade_far_view_z"; + desc.uniform_blocks[1].glsl_uniforms[6].type = SG_UNIFORMTYPE_MAT4; + desc.uniform_blocks[1].glsl_uniforms[6].array_count = 3; + desc.uniform_blocks[1].glsl_uniforms[6].glsl_name = "_833.cascade_matrices"; + desc.uniform_blocks[1].glsl_uniforms[7].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[7].array_count = 9; + desc.uniform_blocks[1].glsl_uniforms[7].glsl_name = "_833.sh"; + desc.uniform_blocks[1].glsl_uniforms[8].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[8].array_count = 0; + desc.uniform_blocks[1].glsl_uniforms[8].glsl_name = "_833.ibl_params"; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 16; + desc.uniform_blocks[2].glsl_uniforms[0].type = SG_UNIFORMTYPE_INT4; + desc.uniform_blocks[2].glsl_uniforms[0].array_count = 1; + desc.uniform_blocks[2].glsl_uniforms[0].glsl_name = "ub_draw"; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.glsl_binding_n = 0; + desc.views[1].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[1].texture.image_type = SG_IMAGETYPE_ARRAY; + desc.views[1].texture.sample_type = SG_IMAGESAMPLETYPE_DEPTH; + desc.views[1].texture.multisampled = false; + desc.views[2].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[2].texture.image_type = SG_IMAGETYPE_CUBE; + desc.views[2].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[2].texture.multisampled = false; + desc.views[3].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[3].texture.image_type = SG_IMAGETYPE_2D; + desc.views[3].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[3].texture.multisampled = false; + desc.views[4].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[4].texture.image_type = SG_IMAGETYPE_2D; + desc.views[4].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[4].texture.multisampled = false; + desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_COMPARISON; + desc.samplers[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[1].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[2].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[2].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[3].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[3].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[0].view_slot = 4; + desc.texture_sampler_pairs[0].sampler_slot = 3; + desc.texture_sampler_pairs[0].glsl_name = "tex_ao_smp_ao"; + desc.texture_sampler_pairs[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[1].view_slot = 1; + desc.texture_sampler_pairs[1].sampler_slot = 0; + desc.texture_sampler_pairs[1].glsl_name = "tex_shadow_smp_shadow"; + desc.texture_sampler_pairs[2].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[2].view_slot = 2; + desc.texture_sampler_pairs[2].sampler_slot = 1; + desc.texture_sampler_pairs[2].glsl_name = "tex_ibl_spec_smp_ibl_spec"; + desc.texture_sampler_pairs[3].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[3].view_slot = 3; + desc.texture_sampler_pairs[3].sampler_slot = 2; + desc.texture_sampler_pairs[3].glsl_name = "tex_brdf_lut_smp_brdf_lut"; + desc.label = "geom_triangle_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_D3D11) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)geom_vs_source_hlsl5; + desc.vertex_func.d3d11_target = "vs_5_0"; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)geom_fs_source_hlsl5; + desc.fragment_func.d3d11_target = "ps_5_0"; + desc.fragment_func.entry = "main"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[0].hlsl_sem_name = "TEXCOORD"; + desc.attrs[0].hlsl_sem_index = 0; + desc.attrs[1].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[1].hlsl_sem_name = "TEXCOORD"; + desc.attrs[1].hlsl_sem_index = 1; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].hlsl_register_b_n = 0; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 496; + desc.uniform_blocks[1].hlsl_register_b_n = 1; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 16; + desc.uniform_blocks[2].hlsl_register_b_n = 2; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.hlsl_register_t_n = 0; + desc.views[1].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[1].texture.image_type = SG_IMAGETYPE_ARRAY; + desc.views[1].texture.sample_type = SG_IMAGESAMPLETYPE_DEPTH; + desc.views[1].texture.multisampled = false; + desc.views[1].texture.hlsl_register_t_n = 0; + desc.views[2].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[2].texture.image_type = SG_IMAGETYPE_CUBE; + desc.views[2].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[2].texture.multisampled = false; + desc.views[2].texture.hlsl_register_t_n = 1; + desc.views[3].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[3].texture.image_type = SG_IMAGETYPE_2D; + desc.views[3].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[3].texture.multisampled = false; + desc.views[3].texture.hlsl_register_t_n = 2; + desc.views[4].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[4].texture.image_type = SG_IMAGETYPE_2D; + desc.views[4].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[4].texture.multisampled = false; + desc.views[4].texture.hlsl_register_t_n = 3; + desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_COMPARISON; + desc.samplers[0].hlsl_register_s_n = 0; + desc.samplers[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[1].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[1].hlsl_register_s_n = 1; + desc.samplers[2].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[2].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[2].hlsl_register_s_n = 2; + desc.samplers[3].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[3].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[3].hlsl_register_s_n = 3; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[0].view_slot = 4; + desc.texture_sampler_pairs[0].sampler_slot = 3; + desc.texture_sampler_pairs[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[1].view_slot = 1; + desc.texture_sampler_pairs[1].sampler_slot = 0; + desc.texture_sampler_pairs[2].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[2].view_slot = 2; + desc.texture_sampler_pairs[2].sampler_slot = 1; + desc.texture_sampler_pairs[3].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[3].view_slot = 3; + desc.texture_sampler_pairs[3].sampler_slot = 2; + desc.label = "geom_triangle_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_METAL_MACOS) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)geom_vs_source_metal_macos; + desc.vertex_func.entry = "main0"; + desc.fragment_func.source = (const char*)geom_fs_source_metal_macos; + desc.fragment_func.entry = "main0"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[1].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].msl_buffer_n = 0; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 496; + desc.uniform_blocks[1].msl_buffer_n = 1; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 16; + desc.uniform_blocks[2].msl_buffer_n = 2; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.msl_buffer_n = 8; + desc.views[1].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[1].texture.image_type = SG_IMAGETYPE_ARRAY; + desc.views[1].texture.sample_type = SG_IMAGESAMPLETYPE_DEPTH; + desc.views[1].texture.multisampled = false; + desc.views[1].texture.msl_texture_n = 0; + desc.views[2].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[2].texture.image_type = SG_IMAGETYPE_CUBE; + desc.views[2].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[2].texture.multisampled = false; + desc.views[2].texture.msl_texture_n = 1; + desc.views[3].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[3].texture.image_type = SG_IMAGETYPE_2D; + desc.views[3].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[3].texture.multisampled = false; + desc.views[3].texture.msl_texture_n = 2; + desc.views[4].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[4].texture.image_type = SG_IMAGETYPE_2D; + desc.views[4].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[4].texture.multisampled = false; + desc.views[4].texture.msl_texture_n = 3; + desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_COMPARISON; + desc.samplers[0].msl_sampler_n = 0; + desc.samplers[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[1].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[1].msl_sampler_n = 1; + desc.samplers[2].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[2].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[2].msl_sampler_n = 2; + desc.samplers[3].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[3].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[3].msl_sampler_n = 3; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[0].view_slot = 4; + desc.texture_sampler_pairs[0].sampler_slot = 3; + desc.texture_sampler_pairs[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[1].view_slot = 1; + desc.texture_sampler_pairs[1].sampler_slot = 0; + desc.texture_sampler_pairs[2].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[2].view_slot = 2; + desc.texture_sampler_pairs[2].sampler_slot = 1; + desc.texture_sampler_pairs[3].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[3].view_slot = 3; + desc.texture_sampler_pairs[3].sampler_slot = 2; + desc.label = "geom_triangle_shader"; + } + return &desc; + } + return 0; +} diff --git a/samples/shaders/generated/gtao_denoise.glsl.h b/samples/shaders/generated/gtao_denoise.glsl.h new file mode 100644 index 0000000..6b8946a --- /dev/null +++ b/samples/shaders/generated/gtao_denoise.glsl.h @@ -0,0 +1,1872 @@ +#pragma once +/* + #version:1# (machine generated, don't edit!) + + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) + + Cmdline: + sokol-shdc --input E:/box/box3d/samples/shaders/post/gtao_denoise.glsl --output E:/box/box3d/samples/shaders/generated/gtao_denoise.glsl.h --slang hlsl5:metal_macos:glsl430 + + Overview: + ========= + Shader program: 'prog': + Get shader desc: gtao_denoise_prog_shader_desc(sg_query_backend()); + Compute Shader: cs + Bindings: + Uniform block 'ub_gtao': + C struct: gtao_denoise_ub_gtao_t + Bind slot: UB_gtao_denoise_ub_gtao => 0 + Uniform block 'ub_denoise': + C struct: gtao_denoise_ub_denoise_t + Bind slot: UB_gtao_denoise_ub_denoise => 1 + Storage image 'out_ao': + Bind slot: VIEW_gtao_denoise_out_ao => 0 + Image type: SG_IMAGETYPE_2D + Access format: SG_PIXELFORMAT_R32F + Writeonly: true + Texture 'tex_edges': + Image type: SG_IMAGETYPE_2D + Sample type: SG_IMAGESAMPLETYPE_FLOAT + Multisampled: false + Bind slot: VIEW_gtao_denoise_tex_edges => 1 + Texture 'tex_noisy_ao': + Image type: SG_IMAGETYPE_2D + Sample type: SG_IMAGESAMPLETYPE_FLOAT + Multisampled: false + Bind slot: VIEW_gtao_denoise_tex_noisy_ao => 2 + Sampler 'smp_point_clamp': + Type: SG_SAMPLERTYPE_FILTERING + Bind slot: SMP_gtao_denoise_smp_point_clamp => 0 +*/ +#if !defined(SOKOL_GFX_INCLUDED) +#error "Please include sokol_gfx.h before gtao_denoise.glsl.h" +#endif +#if !defined(SOKOL_SHDC_ALIGN) +#if defined(_MSC_VER) +#define SOKOL_SHDC_ALIGN(a) __declspec(align(a)) +#else +#define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) +#endif +#endif +#define UB_gtao_denoise_ub_gtao (0) +#define UB_gtao_denoise_ub_denoise (1) +#define VIEW_gtao_denoise_out_ao (0) +#define VIEW_gtao_denoise_tex_edges (1) +#define VIEW_gtao_denoise_tex_noisy_ao (2) +#define SMP_gtao_denoise_smp_point_clamp (0) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct gtao_denoise_ub_gtao_t { + int ViewportSize[2]; + float DenoiseBlurBeta; + uint8_t _pad_12[4]; +} gtao_denoise_ub_gtao_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct gtao_denoise_ub_denoise_t { + int FinalApply; + int _Pad0; + int _Pad1; + int _Pad2; +} gtao_denoise_ub_denoise_t; +#pragma pack(pop) +/* + #version 430 + layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; + + struct ub_gtao + { + ivec2 ViewportSize; + float DenoiseBlurBeta; + }; + + uniform ub_gtao gtao; + + uniform ivec4 ub_denoise[1]; + layout(binding = 0, r32f) uniform writeonly image2D out_ao; + layout(binding = 0) uniform sampler2D tex_edges_smp_point_clamp; + layout(binding = 1) uniform sampler2D tex_noisy_ao_smp_point_clamp; + + float fetchEdge(ivec2 coord) + { + return texelFetch(tex_edges_smp_point_clamp, clamp(coord, ivec2(0), gtao.ViewportSize - ivec2(1)), 0).x; + } + + float fetchAO(ivec2 coord) + { + return texelFetch(tex_noisy_ao_smp_point_clamp, clamp(coord, ivec2(0), gtao.ViewportSize - ivec2(1)), 0).x; + } + + vec4 XeGTAO_UnpackEdges(float packed_val) + { + uint _44 = uint(packed_val * 255.5); + return clamp(vec4(float((_44 >> uint(6)) & 3u) * 0.3333333432674407958984375, float((_44 >> uint(4)) & 3u) * 0.3333333432674407958984375, float((_44 >> uint(2)) & 3u) * 0.3333333432674407958984375, float((_44) & 3u) * 0.3333333432674407958984375), vec4(0.0), vec4(1.0)); + } + + void XeGTAO_AddSample(float ssaoValue, float edgeValue, inout float sum, inout float sumWeight) + { + sum += (edgeValue * ssaoValue); + sumWeight += edgeValue; + } + + void XeGTAO_Output(ivec2 pixCoord, float outputValue, bool finalApply) + { + imageStore(out_ao, pixCoord, vec4(outputValue * (finalApply ? 1.5 : 1.0), 0.0, 0.0, 0.0)); + } + + void main() + { + ivec2 _168 = ivec2(gl_GlobalInvocationID.xy); + ivec2 _176 = ivec2(_168.x * 2, _168.y); + if (any(greaterThanEqual(_176, gtao.ViewportSize))) + { + return; + } + bool _193 = ub_denoise[0].x != 0; + float _196; + if (_193) + { + _196 = gtao.DenoiseBlurBeta; + } + else + { + _196 = gtao.DenoiseBlurBeta * 0.20000000298023223876953125; + } + float edgesN[4][3]; + float ao[4][3]; + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < 3; j++) + { + ivec2 _232 = _176 + ivec2(i - 1, j - 1); + ivec2 param = _232; + edgesN[i][j] = fetchEdge(param); + ivec2 param_1 = _232; + ao[i][j] = fetchAO(param_1); + } + } + for (int side = 0; side < 2; side++) + { + ivec2 _267 = _176 + ivec2(side, 0); + if (_267.x >= gtao.ViewportSize.x) + { + break; + } + int _278 = 1 + side; + int _284 = side + 2; + float param_2 = edgesN[_278][1]; + vec4 edgesC_LRTB = XeGTAO_UnpackEdges(param_2); + float param_3 = edgesN[side][1]; + vec4 _296 = XeGTAO_UnpackEdges(param_3); + float param_4 = edgesN[_284][1]; + vec4 _302 = XeGTAO_UnpackEdges(param_4); + float param_5 = edgesN[_278][0]; + vec4 _308 = XeGTAO_UnpackEdges(param_5); + float param_6 = edgesN[_278][2]; + vec4 _314 = XeGTAO_UnpackEdges(param_6); + vec4 _324 = edgesC_LRTB; + vec4 _325 = _324 * vec4(_296.y, _302.x, _308.w, _314.z); + vec4 _341 = clamp(_325 + vec4(clamp(1.5 - dot(_325, vec4(1.0)), 0.0, 1.0) * 0.3333333432674407958984375), vec4(0.0), vec4(1.0)); + edgesC_LRTB = _341; + float _345 = _341.x; + float _350 = _341.z; + float _363 = _341.y; + float _371 = _341.w; + float param_7 = ao[side][1]; + float param_8 = _345; + float param_9 = ao[_278][1] * _196; + float param_10 = _196; + XeGTAO_AddSample(param_7, param_8, param_9, param_10); + float param_11 = ao[_284][1]; + float param_12 = edgesC_LRTB.y; + float param_13 = param_9; + float param_14 = param_10; + XeGTAO_AddSample(param_11, param_12, param_13, param_14); + float param_15 = ao[_278][0]; + float param_16 = edgesC_LRTB.z; + float param_17 = param_13; + float param_18 = param_14; + XeGTAO_AddSample(param_15, param_16, param_17, param_18); + float param_19 = ao[_278][2]; + float param_20 = edgesC_LRTB.w; + float param_21 = param_17; + float param_22 = param_18; + XeGTAO_AddSample(param_19, param_20, param_21, param_22); + float param_23 = ao[side][0]; + float param_24 = 0.425000011920928955078125 * ((_345 * _296.z) + (_350 * _308.x)); + float param_25 = param_21; + float param_26 = param_22; + XeGTAO_AddSample(param_23, param_24, param_25, param_26); + float param_27 = ao[_284][0]; + float param_28 = 0.425000011920928955078125 * ((_350 * _308.y) + (_363 * _302.z)); + float param_29 = param_25; + float param_30 = param_26; + XeGTAO_AddSample(param_27, param_28, param_29, param_30); + float param_31 = ao[side][2]; + float param_32 = 0.425000011920928955078125 * ((_371 * _314.x) + (_345 * _296.w)); + float param_33 = param_29; + float param_34 = param_30; + XeGTAO_AddSample(param_31, param_32, param_33, param_34); + float param_35 = ao[_284][2]; + float param_36 = 0.425000011920928955078125 * ((_363 * _302.w) + (_371 * _314.y)); + float param_37 = param_33; + float param_38 = param_34; + XeGTAO_AddSample(param_35, param_36, param_37, param_38); + ivec2 param_39 = _267; + float param_40 = param_37 / param_38; + bool param_41 = _193; + XeGTAO_Output(param_39, param_40, param_41); + } + } + +*/ +static const uint8_t gtao_denoise_cs_source_glsl430[5273] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x6c,0x61,0x79, + 0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x6c,0x5f,0x73,0x69,0x7a,0x65,0x5f,0x78, + 0x20,0x3d,0x20,0x38,0x2c,0x20,0x6c,0x6f,0x63,0x61,0x6c,0x5f,0x73,0x69,0x7a,0x65, + 0x5f,0x79,0x20,0x3d,0x20,0x38,0x2c,0x20,0x6c,0x6f,0x63,0x61,0x6c,0x5f,0x73,0x69, + 0x7a,0x65,0x5f,0x7a,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x3b,0x0a,0x0a,0x73, + 0x74,0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x67,0x74,0x61,0x6f,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x76,0x65,0x63,0x32,0x20,0x56,0x69,0x65,0x77,0x70,0x6f, + 0x72,0x74,0x53,0x69,0x7a,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x44,0x65,0x6e,0x6f,0x69,0x73,0x65,0x42,0x6c,0x75,0x72,0x42,0x65,0x74, + 0x61,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x75, + 0x62,0x5f,0x67,0x74,0x61,0x6f,0x20,0x67,0x74,0x61,0x6f,0x3b,0x0a,0x0a,0x75,0x6e, + 0x69,0x66,0x6f,0x72,0x6d,0x20,0x69,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x64, + 0x65,0x6e,0x6f,0x69,0x73,0x65,0x5b,0x31,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75, + 0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x30,0x2c,0x20,0x72, + 0x33,0x32,0x66,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x77,0x72,0x69, + 0x74,0x65,0x6f,0x6e,0x6c,0x79,0x20,0x69,0x6d,0x61,0x67,0x65,0x32,0x44,0x20,0x6f, + 0x75,0x74,0x5f,0x61,0x6f,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69, + 0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x30,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f, + 0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78, + 0x5f,0x65,0x64,0x67,0x65,0x73,0x5f,0x73,0x6d,0x70,0x5f,0x70,0x6f,0x69,0x6e,0x74, + 0x5f,0x63,0x6c,0x61,0x6d,0x70,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62, + 0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x31,0x29,0x20,0x75,0x6e,0x69,0x66, + 0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x74,0x65, + 0x78,0x5f,0x6e,0x6f,0x69,0x73,0x79,0x5f,0x61,0x6f,0x5f,0x73,0x6d,0x70,0x5f,0x70, + 0x6f,0x69,0x6e,0x74,0x5f,0x63,0x6c,0x61,0x6d,0x70,0x3b,0x0a,0x0a,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x66,0x65,0x74,0x63,0x68,0x45,0x64,0x67,0x65,0x28,0x69,0x76,0x65, + 0x63,0x32,0x20,0x63,0x6f,0x6f,0x72,0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x74,0x65,0x78,0x65,0x6c,0x46,0x65,0x74,0x63, + 0x68,0x28,0x74,0x65,0x78,0x5f,0x65,0x64,0x67,0x65,0x73,0x5f,0x73,0x6d,0x70,0x5f, + 0x70,0x6f,0x69,0x6e,0x74,0x5f,0x63,0x6c,0x61,0x6d,0x70,0x2c,0x20,0x63,0x6c,0x61, + 0x6d,0x70,0x28,0x63,0x6f,0x6f,0x72,0x64,0x2c,0x20,0x69,0x76,0x65,0x63,0x32,0x28, + 0x30,0x29,0x2c,0x20,0x67,0x74,0x61,0x6f,0x2e,0x56,0x69,0x65,0x77,0x70,0x6f,0x72, + 0x74,0x53,0x69,0x7a,0x65,0x20,0x2d,0x20,0x69,0x76,0x65,0x63,0x32,0x28,0x31,0x29, + 0x29,0x2c,0x20,0x30,0x29,0x2e,0x78,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x66,0x65,0x74,0x63,0x68,0x41,0x4f,0x28,0x69,0x76,0x65,0x63,0x32,0x20, + 0x63,0x6f,0x6f,0x72,0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x74,0x65,0x78,0x65,0x6c,0x46,0x65,0x74,0x63,0x68,0x28,0x74, + 0x65,0x78,0x5f,0x6e,0x6f,0x69,0x73,0x79,0x5f,0x61,0x6f,0x5f,0x73,0x6d,0x70,0x5f, + 0x70,0x6f,0x69,0x6e,0x74,0x5f,0x63,0x6c,0x61,0x6d,0x70,0x2c,0x20,0x63,0x6c,0x61, + 0x6d,0x70,0x28,0x63,0x6f,0x6f,0x72,0x64,0x2c,0x20,0x69,0x76,0x65,0x63,0x32,0x28, + 0x30,0x29,0x2c,0x20,0x67,0x74,0x61,0x6f,0x2e,0x56,0x69,0x65,0x77,0x70,0x6f,0x72, + 0x74,0x53,0x69,0x7a,0x65,0x20,0x2d,0x20,0x69,0x76,0x65,0x63,0x32,0x28,0x31,0x29, + 0x29,0x2c,0x20,0x30,0x29,0x2e,0x78,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x34, + 0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x55,0x6e,0x70,0x61,0x63,0x6b,0x45,0x64, + 0x67,0x65,0x73,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x63,0x6b,0x65,0x64, + 0x5f,0x76,0x61,0x6c,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74, + 0x20,0x5f,0x34,0x34,0x20,0x3d,0x20,0x75,0x69,0x6e,0x74,0x28,0x70,0x61,0x63,0x6b, + 0x65,0x64,0x5f,0x76,0x61,0x6c,0x20,0x2a,0x20,0x32,0x35,0x35,0x2e,0x35,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x63,0x6c,0x61,0x6d, + 0x70,0x28,0x76,0x65,0x63,0x34,0x28,0x66,0x6c,0x6f,0x61,0x74,0x28,0x28,0x5f,0x34, + 0x34,0x20,0x3e,0x3e,0x20,0x75,0x69,0x6e,0x74,0x28,0x36,0x29,0x29,0x20,0x26,0x20, + 0x33,0x75,0x29,0x20,0x2a,0x20,0x30,0x2e,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x34, + 0x33,0x32,0x36,0x37,0x34,0x34,0x30,0x37,0x39,0x35,0x38,0x39,0x38,0x34,0x33,0x37, + 0x35,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x28,0x5f,0x34,0x34,0x20,0x3e,0x3e, + 0x20,0x75,0x69,0x6e,0x74,0x28,0x34,0x29,0x29,0x20,0x26,0x20,0x33,0x75,0x29,0x20, + 0x2a,0x20,0x30,0x2e,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x34,0x33,0x32,0x36,0x37, + 0x34,0x34,0x30,0x37,0x39,0x35,0x38,0x39,0x38,0x34,0x33,0x37,0x35,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x28,0x28,0x5f,0x34,0x34,0x20,0x3e,0x3e,0x20,0x75,0x69,0x6e, + 0x74,0x28,0x32,0x29,0x29,0x20,0x26,0x20,0x33,0x75,0x29,0x20,0x2a,0x20,0x30,0x2e, + 0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x34,0x33,0x32,0x36,0x37,0x34,0x34,0x30,0x37, + 0x39,0x35,0x38,0x39,0x38,0x34,0x33,0x37,0x35,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x28,0x28,0x5f,0x34,0x34,0x29,0x20,0x26,0x20,0x33,0x75,0x29,0x20,0x2a,0x20,0x30, + 0x2e,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x34,0x33,0x32,0x36,0x37,0x34,0x34,0x30, + 0x37,0x39,0x35,0x38,0x39,0x38,0x34,0x33,0x37,0x35,0x29,0x2c,0x20,0x76,0x65,0x63, + 0x34,0x28,0x30,0x2e,0x30,0x29,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x31,0x2e,0x30, + 0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x58,0x65,0x47,0x54, + 0x41,0x4f,0x5f,0x41,0x64,0x64,0x53,0x61,0x6d,0x70,0x6c,0x65,0x28,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x73,0x73,0x61,0x6f,0x56,0x61,0x6c,0x75,0x65,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x65,0x64,0x67,0x65,0x56,0x61,0x6c,0x75,0x65,0x2c,0x20,0x69, + 0x6e,0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x75,0x6d,0x2c,0x20, + 0x69,0x6e,0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x75,0x6d,0x57, + 0x65,0x69,0x67,0x68,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d, + 0x20,0x2b,0x3d,0x20,0x28,0x65,0x64,0x67,0x65,0x56,0x61,0x6c,0x75,0x65,0x20,0x2a, + 0x20,0x73,0x73,0x61,0x6f,0x56,0x61,0x6c,0x75,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x73,0x75,0x6d,0x57,0x65,0x69,0x67,0x68,0x74,0x20,0x2b,0x3d,0x20,0x65,0x64, + 0x67,0x65,0x56,0x61,0x6c,0x75,0x65,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64, + 0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x28,0x69, + 0x76,0x65,0x63,0x32,0x20,0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x6f,0x75,0x74,0x70,0x75,0x74,0x56,0x61,0x6c,0x75,0x65, + 0x2c,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x66,0x69,0x6e,0x61,0x6c,0x41,0x70,0x70,0x6c, + 0x79,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6d,0x61,0x67,0x65,0x53,0x74, + 0x6f,0x72,0x65,0x28,0x6f,0x75,0x74,0x5f,0x61,0x6f,0x2c,0x20,0x70,0x69,0x78,0x43, + 0x6f,0x6f,0x72,0x64,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x6f,0x75,0x74,0x70,0x75, + 0x74,0x56,0x61,0x6c,0x75,0x65,0x20,0x2a,0x20,0x28,0x66,0x69,0x6e,0x61,0x6c,0x41, + 0x70,0x70,0x6c,0x79,0x20,0x3f,0x20,0x31,0x2e,0x35,0x20,0x3a,0x20,0x31,0x2e,0x30, + 0x29,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30, + 0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e, + 0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x76,0x65,0x63,0x32,0x20,0x5f, + 0x31,0x36,0x38,0x20,0x3d,0x20,0x69,0x76,0x65,0x63,0x32,0x28,0x67,0x6c,0x5f,0x47, + 0x6c,0x6f,0x62,0x61,0x6c,0x49,0x6e,0x76,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x49, + 0x44,0x2e,0x78,0x79,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x76,0x65,0x63,0x32, + 0x20,0x5f,0x31,0x37,0x36,0x20,0x3d,0x20,0x69,0x76,0x65,0x63,0x32,0x28,0x5f,0x31, + 0x36,0x38,0x2e,0x78,0x20,0x2a,0x20,0x32,0x2c,0x20,0x5f,0x31,0x36,0x38,0x2e,0x79, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x61,0x6e,0x79,0x28,0x67, + 0x72,0x65,0x61,0x74,0x65,0x72,0x54,0x68,0x61,0x6e,0x45,0x71,0x75,0x61,0x6c,0x28, + 0x5f,0x31,0x37,0x36,0x2c,0x20,0x67,0x74,0x61,0x6f,0x2e,0x56,0x69,0x65,0x77,0x70, + 0x6f,0x72,0x74,0x53,0x69,0x7a,0x65,0x29,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20, + 0x5f,0x31,0x39,0x33,0x20,0x3d,0x20,0x75,0x62,0x5f,0x64,0x65,0x6e,0x6f,0x69,0x73, + 0x65,0x5b,0x30,0x5d,0x2e,0x78,0x20,0x21,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x39,0x36,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x39,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x39,0x36,0x20,0x3d,0x20, + 0x67,0x74,0x61,0x6f,0x2e,0x44,0x65,0x6e,0x6f,0x69,0x73,0x65,0x42,0x6c,0x75,0x72, + 0x42,0x65,0x74,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x5f,0x31,0x39,0x36,0x20,0x3d,0x20,0x67,0x74,0x61,0x6f,0x2e,0x44, + 0x65,0x6e,0x6f,0x69,0x73,0x65,0x42,0x6c,0x75,0x72,0x42,0x65,0x74,0x61,0x20,0x2a, + 0x20,0x30,0x2e,0x32,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x32,0x39,0x38,0x30,0x32, + 0x33,0x32,0x32,0x33,0x38,0x37,0x36,0x39,0x35,0x33,0x31,0x32,0x35,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x65, + 0x64,0x67,0x65,0x73,0x4e,0x5b,0x34,0x5d,0x5b,0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6f,0x5b,0x34,0x5d,0x5b,0x33,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x20,0x28,0x69,0x6e,0x74,0x20,0x69,0x20, + 0x3d,0x20,0x30,0x3b,0x20,0x69,0x20,0x3c,0x20,0x34,0x3b,0x20,0x69,0x2b,0x2b,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6f,0x72,0x20,0x28,0x69,0x6e,0x74,0x20,0x6a,0x20,0x3d,0x20,0x30,0x3b,0x20,0x6a, + 0x20,0x3c,0x20,0x33,0x3b,0x20,0x6a,0x2b,0x2b,0x29,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x69,0x76,0x65,0x63,0x32,0x20,0x5f,0x32,0x33,0x32,0x20,0x3d,0x20,0x5f,0x31, + 0x37,0x36,0x20,0x2b,0x20,0x69,0x76,0x65,0x63,0x32,0x28,0x69,0x20,0x2d,0x20,0x31, + 0x2c,0x20,0x6a,0x20,0x2d,0x20,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x20,0x3d,0x20,0x5f,0x32,0x33,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x64,0x67,0x65,0x73,0x4e,0x5b,0x69,0x5d,0x5b, + 0x6a,0x5d,0x20,0x3d,0x20,0x66,0x65,0x74,0x63,0x68,0x45,0x64,0x67,0x65,0x28,0x70, + 0x61,0x72,0x61,0x6d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x20,0x3d,0x20,0x5f,0x32,0x33,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x61,0x6f,0x5b,0x69,0x5d,0x5b,0x6a,0x5d,0x20,0x3d,0x20, + 0x66,0x65,0x74,0x63,0x68,0x41,0x4f,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x20,0x28,0x69,0x6e,0x74,0x20,0x73, + 0x69,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x20,0x73,0x69,0x64,0x65,0x20,0x3c,0x20, + 0x32,0x3b,0x20,0x73,0x69,0x64,0x65,0x2b,0x2b,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x76,0x65,0x63,0x32,0x20,0x5f, + 0x32,0x36,0x37,0x20,0x3d,0x20,0x5f,0x31,0x37,0x36,0x20,0x2b,0x20,0x69,0x76,0x65, + 0x63,0x32,0x28,0x73,0x69,0x64,0x65,0x2c,0x20,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x32,0x36,0x37,0x2e,0x78,0x20, + 0x3e,0x3d,0x20,0x67,0x74,0x61,0x6f,0x2e,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74, + 0x53,0x69,0x7a,0x65,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x72, + 0x65,0x61,0x6b,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x32,0x37,0x38,0x20, + 0x3d,0x20,0x31,0x20,0x2b,0x20,0x73,0x69,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x32,0x38,0x34,0x20,0x3d,0x20,0x73, + 0x69,0x64,0x65,0x20,0x2b,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d, + 0x20,0x65,0x64,0x67,0x65,0x73,0x4e,0x5b,0x5f,0x32,0x37,0x38,0x5d,0x5b,0x31,0x5d, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x65, + 0x64,0x67,0x65,0x73,0x43,0x5f,0x4c,0x52,0x54,0x42,0x20,0x3d,0x20,0x58,0x65,0x47, + 0x54,0x41,0x4f,0x5f,0x55,0x6e,0x70,0x61,0x63,0x6b,0x45,0x64,0x67,0x65,0x73,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20, + 0x3d,0x20,0x65,0x64,0x67,0x65,0x73,0x4e,0x5b,0x73,0x69,0x64,0x65,0x5d,0x5b,0x31, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20, + 0x5f,0x32,0x39,0x36,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x55,0x6e, + 0x70,0x61,0x63,0x6b,0x45,0x64,0x67,0x65,0x73,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x65,0x64,0x67,0x65, + 0x73,0x4e,0x5b,0x5f,0x32,0x38,0x34,0x5d,0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x33,0x30,0x32,0x20,0x3d, + 0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x55,0x6e,0x70,0x61,0x63,0x6b,0x45,0x64, + 0x67,0x65,0x73,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x35,0x20,0x3d,0x20,0x65,0x64,0x67,0x65,0x73,0x4e,0x5b,0x5f,0x32,0x37, + 0x38,0x5d,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x34,0x20,0x5f,0x33,0x30,0x38,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41, + 0x4f,0x5f,0x55,0x6e,0x70,0x61,0x63,0x6b,0x45,0x64,0x67,0x65,0x73,0x28,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20, + 0x65,0x64,0x67,0x65,0x73,0x4e,0x5b,0x5f,0x32,0x37,0x38,0x5d,0x5b,0x32,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x33, + 0x31,0x34,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x55,0x6e,0x70,0x61, + 0x63,0x6b,0x45,0x64,0x67,0x65,0x73,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f, + 0x33,0x32,0x34,0x20,0x3d,0x20,0x65,0x64,0x67,0x65,0x73,0x43,0x5f,0x4c,0x52,0x54, + 0x42,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20, + 0x5f,0x33,0x32,0x35,0x20,0x3d,0x20,0x5f,0x33,0x32,0x34,0x20,0x2a,0x20,0x76,0x65, + 0x63,0x34,0x28,0x5f,0x32,0x39,0x36,0x2e,0x79,0x2c,0x20,0x5f,0x33,0x30,0x32,0x2e, + 0x78,0x2c,0x20,0x5f,0x33,0x30,0x38,0x2e,0x77,0x2c,0x20,0x5f,0x33,0x31,0x34,0x2e, + 0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34, + 0x20,0x5f,0x33,0x34,0x31,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x5f,0x33, + 0x32,0x35,0x20,0x2b,0x20,0x76,0x65,0x63,0x34,0x28,0x63,0x6c,0x61,0x6d,0x70,0x28, + 0x31,0x2e,0x35,0x20,0x2d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x33,0x32,0x35,0x2c,0x20, + 0x76,0x65,0x63,0x34,0x28,0x31,0x2e,0x30,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x2c, + 0x20,0x31,0x2e,0x30,0x29,0x20,0x2a,0x20,0x30,0x2e,0x33,0x33,0x33,0x33,0x33,0x33, + 0x33,0x34,0x33,0x32,0x36,0x37,0x34,0x34,0x30,0x37,0x39,0x35,0x38,0x39,0x38,0x34, + 0x33,0x37,0x35,0x29,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x30,0x2e,0x30,0x29,0x2c, + 0x20,0x76,0x65,0x63,0x34,0x28,0x31,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x65,0x64,0x67,0x65,0x73,0x43,0x5f,0x4c,0x52,0x54,0x42, + 0x20,0x3d,0x20,0x5f,0x33,0x34,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x33,0x34,0x35,0x20,0x3d,0x20,0x5f,0x33, + 0x34,0x31,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x33,0x35,0x30,0x20,0x3d,0x20,0x5f,0x33,0x34,0x31,0x2e, + 0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x33,0x36,0x33,0x20,0x3d,0x20,0x5f,0x33,0x34,0x31,0x2e,0x79,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x33, + 0x37,0x31,0x20,0x3d,0x20,0x5f,0x33,0x34,0x31,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x37,0x20,0x3d,0x20,0x61,0x6f,0x5b,0x73,0x69,0x64,0x65,0x5d,0x5b,0x31,0x5d, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x5f,0x33,0x34,0x35,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x61,0x6f,0x5b,0x5f,0x32,0x37,0x38,0x5d, + 0x5b,0x31,0x5d,0x20,0x2a,0x20,0x5f,0x31,0x39,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x30,0x20,0x3d,0x20,0x5f,0x31,0x39,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x41,0x64,0x64,0x53,0x61,0x6d, + 0x70,0x6c,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31, + 0x20,0x3d,0x20,0x61,0x6f,0x5b,0x5f,0x32,0x38,0x34,0x5d,0x5b,0x31,0x5d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x65,0x64,0x67,0x65,0x73,0x43,0x5f, + 0x4c,0x52,0x54,0x42,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34, + 0x20,0x3d,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x41,0x64,0x64,0x53, + 0x61,0x6d,0x70,0x6c,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x61,0x6f,0x5b,0x5f,0x32,0x37,0x38,0x5d, + 0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x65,0x64, + 0x67,0x65,0x73,0x43,0x5f,0x4c,0x52,0x54,0x42,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x37,0x20,0x3d,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x58,0x65,0x47,0x54,0x41, + 0x4f,0x5f,0x41,0x64,0x64,0x53,0x61,0x6d,0x70,0x6c,0x65,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20,0x61,0x6f, + 0x5b,0x5f,0x32,0x37,0x38,0x5d,0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x30,0x20,0x3d,0x20,0x65,0x64,0x67,0x65,0x73,0x43,0x5f,0x4c,0x52,0x54,0x42,0x2e, + 0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x20,0x3d,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x20,0x3d,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x41,0x64,0x64,0x53,0x61,0x6d,0x70,0x6c, + 0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x33,0x20,0x3d,0x20,0x61,0x6f,0x5b,0x73,0x69,0x64,0x65,0x5d,0x5b,0x30,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x20,0x3d,0x20,0x30,0x2e,0x34,0x32,0x35,0x30, + 0x30,0x30,0x30,0x31,0x31,0x39,0x32,0x30,0x39,0x32,0x38,0x39,0x35,0x35,0x30,0x37, + 0x38,0x31,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x5f,0x33,0x34,0x35,0x20,0x2a,0x20, + 0x5f,0x32,0x39,0x36,0x2e,0x7a,0x29,0x20,0x2b,0x20,0x28,0x5f,0x33,0x35,0x30,0x20, + 0x2a,0x20,0x5f,0x33,0x30,0x38,0x2e,0x78,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x35,0x20,0x3d,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x36,0x20,0x3d,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x58,0x65,0x47,0x54,0x41,0x4f, + 0x5f,0x41,0x64,0x64,0x53,0x61,0x6d,0x70,0x6c,0x65,0x28,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37,0x20,0x3d,0x20,0x61,0x6f,0x5b, + 0x5f,0x32,0x38,0x34,0x5d,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x38, + 0x20,0x3d,0x20,0x30,0x2e,0x34,0x32,0x35,0x30,0x30,0x30,0x30,0x31,0x31,0x39,0x32, + 0x30,0x39,0x32,0x38,0x39,0x35,0x35,0x30,0x37,0x38,0x31,0x32,0x35,0x20,0x2a,0x20, + 0x28,0x28,0x5f,0x33,0x35,0x30,0x20,0x2a,0x20,0x5f,0x33,0x30,0x38,0x2e,0x79,0x29, + 0x20,0x2b,0x20,0x28,0x5f,0x33,0x36,0x33,0x20,0x2a,0x20,0x5f,0x33,0x30,0x32,0x2e, + 0x7a,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x39,0x20,0x3d,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x30,0x20,0x3d, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x41,0x64,0x64,0x53,0x61,0x6d, + 0x70,0x6c,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x39, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x33,0x31,0x20,0x3d,0x20,0x61,0x6f,0x5b,0x73,0x69,0x64,0x65,0x5d,0x5b,0x32, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x32,0x20,0x3d,0x20,0x30,0x2e,0x34,0x32, + 0x35,0x30,0x30,0x30,0x30,0x31,0x31,0x39,0x32,0x30,0x39,0x32,0x38,0x39,0x35,0x35, + 0x30,0x37,0x38,0x31,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x5f,0x33,0x37,0x31,0x20, + 0x2a,0x20,0x5f,0x33,0x31,0x34,0x2e,0x78,0x29,0x20,0x2b,0x20,0x28,0x5f,0x33,0x34, + 0x35,0x20,0x2a,0x20,0x5f,0x32,0x39,0x36,0x2e,0x77,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x33,0x33,0x20,0x3d,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x39,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x20,0x3d,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x58,0x65,0x47,0x54, + 0x41,0x4f,0x5f,0x41,0x64,0x64,0x53,0x61,0x6d,0x70,0x6c,0x65,0x28,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x32,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x33,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x35,0x20,0x3d,0x20,0x61, + 0x6f,0x5b,0x5f,0x32,0x38,0x34,0x5d,0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x36,0x20,0x3d,0x20,0x30,0x2e,0x34,0x32,0x35,0x30,0x30,0x30,0x30,0x31,0x31, + 0x39,0x32,0x30,0x39,0x32,0x38,0x39,0x35,0x35,0x30,0x37,0x38,0x31,0x32,0x35,0x20, + 0x2a,0x20,0x28,0x28,0x5f,0x33,0x36,0x33,0x20,0x2a,0x20,0x5f,0x33,0x30,0x32,0x2e, + 0x77,0x29,0x20,0x2b,0x20,0x28,0x5f,0x33,0x37,0x31,0x20,0x2a,0x20,0x5f,0x33,0x31, + 0x34,0x2e,0x79,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x37,0x20,0x3d,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x38, + 0x20,0x3d,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x41,0x64,0x64,0x53, + 0x61,0x6d,0x70,0x6c,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x35,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x38,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x39,0x20,0x3d,0x20,0x5f,0x32,0x36,0x37,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x34,0x30,0x20,0x3d,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x37,0x20, + 0x2f,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, + 0x31,0x20,0x3d,0x20,0x5f,0x31,0x39,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x34,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x31,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + static const uint3 gl_WorkGroupSize = uint3(8u, 8u, 1u); + + cbuffer ub_gtao : register(b0) + { + int2 gtao_ViewportSize : packoffset(c0); + float gtao_DenoiseBlurBeta : packoffset(c0.z); + }; + + cbuffer ub_denoise : register(b1) + { + int _189_FinalApply : packoffset(c0); + int _189_Pad0 : packoffset(c0.y); + int _189_Pad1 : packoffset(c0.z); + int _189_Pad2 : packoffset(c0.w); + }; + + Texture2D tex_edges : register(t0); + SamplerState smp_point_clamp : register(s0); + Texture2D tex_noisy_ao : register(t1); + RWTexture2D out_ao : register(u0); + + static uint3 gl_GlobalInvocationID; + struct SPIRV_Cross_Input + { + uint3 gl_GlobalInvocationID : SV_DispatchThreadID; + }; + + float fetchEdge(int2 coord) + { + return tex_edges.Load(int3(clamp(coord, int2(0, 0), gtao_ViewportSize - int2(1, 1)), 0)).x; + } + + float fetchAO(int2 coord) + { + return tex_noisy_ao.Load(int3(clamp(coord, int2(0, 0), gtao_ViewportSize - int2(1, 1)), 0)).x; + } + + float4 XeGTAO_UnpackEdges(float packed_val) + { + uint _44 = uint(packed_val * 255.5f); + return clamp(float4(float((_44 >> uint(6)) & 3u) * 0.3333333432674407958984375f, float((_44 >> uint(4)) & 3u) * 0.3333333432674407958984375f, float((_44 >> uint(2)) & 3u) * 0.3333333432674407958984375f, float((_44) & 3u) * 0.3333333432674407958984375f), 0.0f.xxxx, 1.0f.xxxx); + } + + void XeGTAO_AddSample(float ssaoValue, float edgeValue, inout float sum, inout float sumWeight) + { + sum += (edgeValue * ssaoValue); + sumWeight += edgeValue; + } + + void XeGTAO_Output(int2 pixCoord, float outputValue, bool finalApply) + { + out_ao[pixCoord] = float4(outputValue * (finalApply ? 1.5f : 1.0f), 0.0f, 0.0f, 0.0f).x; + } + + void comp_main() + { + int2 _168 = int2(gl_GlobalInvocationID.xy); + int2 _176 = int2(_168.x * 2, _168.y); + if (any(bool2(_176.x >= gtao_ViewportSize.x, _176.y >= gtao_ViewportSize.y))) + { + return; + } + bool _193 = _189_FinalApply != 0; + float _196; + if (_193) + { + _196 = gtao_DenoiseBlurBeta; + } + else + { + _196 = gtao_DenoiseBlurBeta * 0.20000000298023223876953125f; + } + float edgesN[4][3]; + float ao[4][3]; + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < 3; j++) + { + int2 _232 = _176 + int2(i - 1, j - 1); + int2 param = _232; + edgesN[i][j] = fetchEdge(param); + int2 param_1 = _232; + ao[i][j] = fetchAO(param_1); + } + } + for (int side = 0; side < 2; side++) + { + int2 _267 = _176 + int2(side, 0); + if (_267.x >= gtao_ViewportSize.x) + { + break; + } + int _278 = 1 + side; + int _284 = side + 2; + float param_2 = edgesN[_278][1]; + float4 edgesC_LRTB = XeGTAO_UnpackEdges(param_2); + float param_3 = edgesN[side][1]; + float4 _296 = XeGTAO_UnpackEdges(param_3); + float param_4 = edgesN[_284][1]; + float4 _302 = XeGTAO_UnpackEdges(param_4); + float param_5 = edgesN[_278][0]; + float4 _308 = XeGTAO_UnpackEdges(param_5); + float param_6 = edgesN[_278][2]; + float4 _314 = XeGTAO_UnpackEdges(param_6); + float4 _324 = edgesC_LRTB; + float4 _325 = _324 * float4(_296.y, _302.x, _308.w, _314.z); + float4 _341 = clamp(_325 + (clamp(1.5f - dot(_325, 1.0f.xxxx), 0.0f, 1.0f) * 0.3333333432674407958984375f).xxxx, 0.0f.xxxx, 1.0f.xxxx); + edgesC_LRTB = _341; + float _345 = _341.x; + float _350 = _341.z; + float _363 = _341.y; + float _371 = _341.w; + float param_7 = ao[side][1]; + float param_8 = _345; + float param_9 = ao[_278][1] * _196; + float param_10 = _196; + XeGTAO_AddSample(param_7, param_8, param_9, param_10); + float param_11 = ao[_284][1]; + float param_12 = edgesC_LRTB.y; + float param_13 = param_9; + float param_14 = param_10; + XeGTAO_AddSample(param_11, param_12, param_13, param_14); + float param_15 = ao[_278][0]; + float param_16 = edgesC_LRTB.z; + float param_17 = param_13; + float param_18 = param_14; + XeGTAO_AddSample(param_15, param_16, param_17, param_18); + float param_19 = ao[_278][2]; + float param_20 = edgesC_LRTB.w; + float param_21 = param_17; + float param_22 = param_18; + XeGTAO_AddSample(param_19, param_20, param_21, param_22); + float param_23 = ao[side][0]; + float param_24 = 0.425000011920928955078125f * ((_345 * _296.z) + (_350 * _308.x)); + float param_25 = param_21; + float param_26 = param_22; + XeGTAO_AddSample(param_23, param_24, param_25, param_26); + float param_27 = ao[_284][0]; + float param_28 = 0.425000011920928955078125f * ((_350 * _308.y) + (_363 * _302.z)); + float param_29 = param_25; + float param_30 = param_26; + XeGTAO_AddSample(param_27, param_28, param_29, param_30); + float param_31 = ao[side][2]; + float param_32 = 0.425000011920928955078125f * ((_371 * _314.x) + (_345 * _296.w)); + float param_33 = param_29; + float param_34 = param_30; + XeGTAO_AddSample(param_31, param_32, param_33, param_34); + float param_35 = ao[_284][2]; + float param_36 = 0.425000011920928955078125f * ((_363 * _302.w) + (_371 * _314.y)); + float param_37 = param_33; + float param_38 = param_34; + XeGTAO_AddSample(param_35, param_36, param_37, param_38); + int2 param_39 = _267; + float param_40 = param_37 / param_38; + bool param_41 = _193; + XeGTAO_Output(param_39, param_40, param_41); + } + } + + [numthreads(8, 8, 1)] + void main(SPIRV_Cross_Input stage_input) + { + gl_GlobalInvocationID = stage_input.gl_GlobalInvocationID; + comp_main(); + } +*/ +static const uint8_t gtao_denoise_cs_source_hlsl5[5737] = { + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x75,0x69,0x6e, + 0x74,0x33,0x20,0x67,0x6c,0x5f,0x57,0x6f,0x72,0x6b,0x47,0x72,0x6f,0x75,0x70,0x53, + 0x69,0x7a,0x65,0x20,0x3d,0x20,0x75,0x69,0x6e,0x74,0x33,0x28,0x38,0x75,0x2c,0x20, + 0x38,0x75,0x2c,0x20,0x31,0x75,0x29,0x3b,0x0a,0x0a,0x63,0x62,0x75,0x66,0x66,0x65, + 0x72,0x20,0x75,0x62,0x5f,0x67,0x74,0x61,0x6f,0x20,0x3a,0x20,0x72,0x65,0x67,0x69, + 0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x6e,0x74,0x32,0x20,0x67,0x74,0x61,0x6f,0x5f,0x56,0x69,0x65,0x77,0x70,0x6f,0x72, + 0x74,0x53,0x69,0x7a,0x65,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73, + 0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x67,0x74,0x61,0x6f,0x5f,0x44,0x65,0x6e,0x6f,0x69,0x73,0x65,0x42,0x6c, + 0x75,0x72,0x42,0x65,0x74,0x61,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66, + 0x73,0x65,0x74,0x28,0x63,0x30,0x2e,0x7a,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x63, + 0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x64,0x65,0x6e,0x6f,0x69,0x73, + 0x65,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x31,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x31,0x38,0x39,0x5f, + 0x46,0x69,0x6e,0x61,0x6c,0x41,0x70,0x70,0x6c,0x79,0x20,0x3a,0x20,0x70,0x61,0x63, + 0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x6e,0x74,0x20,0x5f,0x31,0x38,0x39,0x5f,0x50,0x61,0x64,0x30,0x20,0x3a, + 0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x2e,0x79, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x31,0x38,0x39,0x5f, + 0x50,0x61,0x64,0x31,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65, + 0x74,0x28,0x63,0x30,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74, + 0x20,0x5f,0x31,0x38,0x39,0x5f,0x50,0x61,0x64,0x32,0x20,0x3a,0x20,0x70,0x61,0x63, + 0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x2e,0x77,0x29,0x3b,0x0a,0x7d, + 0x3b,0x0a,0x0a,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x65,0x64,0x67,0x65,0x73,0x20,0x3a, + 0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x30,0x29,0x3b,0x0a,0x53, + 0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f, + 0x70,0x6f,0x69,0x6e,0x74,0x5f,0x63,0x6c,0x61,0x6d,0x70,0x20,0x3a,0x20,0x72,0x65, + 0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x30,0x29,0x3b,0x0a,0x54,0x65,0x78,0x74, + 0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65, + 0x78,0x5f,0x6e,0x6f,0x69,0x73,0x79,0x5f,0x61,0x6f,0x20,0x3a,0x20,0x72,0x65,0x67, + 0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x31,0x29,0x3b,0x0a,0x52,0x57,0x54,0x65,0x78, + 0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x6f,0x75, + 0x74,0x5f,0x61,0x6f,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28, + 0x75,0x30,0x29,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x75,0x69,0x6e, + 0x74,0x33,0x20,0x67,0x6c,0x5f,0x47,0x6c,0x6f,0x62,0x61,0x6c,0x49,0x6e,0x76,0x6f, + 0x63,0x61,0x74,0x69,0x6f,0x6e,0x49,0x44,0x3b,0x0a,0x73,0x74,0x72,0x75,0x63,0x74, + 0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70, + 0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x33,0x20,0x67, + 0x6c,0x5f,0x47,0x6c,0x6f,0x62,0x61,0x6c,0x49,0x6e,0x76,0x6f,0x63,0x61,0x74,0x69, + 0x6f,0x6e,0x49,0x44,0x20,0x3a,0x20,0x53,0x56,0x5f,0x44,0x69,0x73,0x70,0x61,0x74, + 0x63,0x68,0x54,0x68,0x72,0x65,0x61,0x64,0x49,0x44,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x66,0x65,0x74,0x63,0x68,0x45,0x64,0x67,0x65,0x28, + 0x69,0x6e,0x74,0x32,0x20,0x63,0x6f,0x6f,0x72,0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x74,0x65,0x78,0x5f,0x65,0x64,0x67, + 0x65,0x73,0x2e,0x4c,0x6f,0x61,0x64,0x28,0x69,0x6e,0x74,0x33,0x28,0x63,0x6c,0x61, + 0x6d,0x70,0x28,0x63,0x6f,0x6f,0x72,0x64,0x2c,0x20,0x69,0x6e,0x74,0x32,0x28,0x30, + 0x2c,0x20,0x30,0x29,0x2c,0x20,0x67,0x74,0x61,0x6f,0x5f,0x56,0x69,0x65,0x77,0x70, + 0x6f,0x72,0x74,0x53,0x69,0x7a,0x65,0x20,0x2d,0x20,0x69,0x6e,0x74,0x32,0x28,0x31, + 0x2c,0x20,0x31,0x29,0x29,0x2c,0x20,0x30,0x29,0x29,0x2e,0x78,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x66,0x65,0x74,0x63,0x68,0x41,0x4f,0x28,0x69, + 0x6e,0x74,0x32,0x20,0x63,0x6f,0x6f,0x72,0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x74,0x65,0x78,0x5f,0x6e,0x6f,0x69,0x73, + 0x79,0x5f,0x61,0x6f,0x2e,0x4c,0x6f,0x61,0x64,0x28,0x69,0x6e,0x74,0x33,0x28,0x63, + 0x6c,0x61,0x6d,0x70,0x28,0x63,0x6f,0x6f,0x72,0x64,0x2c,0x20,0x69,0x6e,0x74,0x32, + 0x28,0x30,0x2c,0x20,0x30,0x29,0x2c,0x20,0x67,0x74,0x61,0x6f,0x5f,0x56,0x69,0x65, + 0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65,0x20,0x2d,0x20,0x69,0x6e,0x74,0x32, + 0x28,0x31,0x2c,0x20,0x31,0x29,0x29,0x2c,0x20,0x30,0x29,0x29,0x2e,0x78,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x58,0x65,0x47,0x54,0x41,0x4f, + 0x5f,0x55,0x6e,0x70,0x61,0x63,0x6b,0x45,0x64,0x67,0x65,0x73,0x28,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x63,0x6b,0x65,0x64,0x5f,0x76,0x61,0x6c,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x5f,0x34,0x34,0x20,0x3d,0x20, + 0x75,0x69,0x6e,0x74,0x28,0x70,0x61,0x63,0x6b,0x65,0x64,0x5f,0x76,0x61,0x6c,0x20, + 0x2a,0x20,0x32,0x35,0x35,0x2e,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x28,0x66,0x6c,0x6f,0x61,0x74,0x28,0x28,0x5f,0x34,0x34,0x20,0x3e,0x3e, + 0x20,0x75,0x69,0x6e,0x74,0x28,0x36,0x29,0x29,0x20,0x26,0x20,0x33,0x75,0x29,0x20, + 0x2a,0x20,0x30,0x2e,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x34,0x33,0x32,0x36,0x37, + 0x34,0x34,0x30,0x37,0x39,0x35,0x38,0x39,0x38,0x34,0x33,0x37,0x35,0x66,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x28,0x28,0x5f,0x34,0x34,0x20,0x3e,0x3e,0x20,0x75,0x69, + 0x6e,0x74,0x28,0x34,0x29,0x29,0x20,0x26,0x20,0x33,0x75,0x29,0x20,0x2a,0x20,0x30, + 0x2e,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x34,0x33,0x32,0x36,0x37,0x34,0x34,0x30, + 0x37,0x39,0x35,0x38,0x39,0x38,0x34,0x33,0x37,0x35,0x66,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x28,0x28,0x5f,0x34,0x34,0x20,0x3e,0x3e,0x20,0x75,0x69,0x6e,0x74,0x28, + 0x32,0x29,0x29,0x20,0x26,0x20,0x33,0x75,0x29,0x20,0x2a,0x20,0x30,0x2e,0x33,0x33, + 0x33,0x33,0x33,0x33,0x33,0x34,0x33,0x32,0x36,0x37,0x34,0x34,0x30,0x37,0x39,0x35, + 0x38,0x39,0x38,0x34,0x33,0x37,0x35,0x66,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28, + 0x28,0x5f,0x34,0x34,0x29,0x20,0x26,0x20,0x33,0x75,0x29,0x20,0x2a,0x20,0x30,0x2e, + 0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x34,0x33,0x32,0x36,0x37,0x34,0x34,0x30,0x37, + 0x39,0x35,0x38,0x39,0x38,0x34,0x33,0x37,0x35,0x66,0x29,0x2c,0x20,0x30,0x2e,0x30, + 0x66,0x2e,0x78,0x78,0x78,0x78,0x2c,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78, + 0x78,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x58,0x65,0x47,0x54, + 0x41,0x4f,0x5f,0x41,0x64,0x64,0x53,0x61,0x6d,0x70,0x6c,0x65,0x28,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x73,0x73,0x61,0x6f,0x56,0x61,0x6c,0x75,0x65,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x65,0x64,0x67,0x65,0x56,0x61,0x6c,0x75,0x65,0x2c,0x20,0x69, + 0x6e,0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x75,0x6d,0x2c,0x20, + 0x69,0x6e,0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x75,0x6d,0x57, + 0x65,0x69,0x67,0x68,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d, + 0x20,0x2b,0x3d,0x20,0x28,0x65,0x64,0x67,0x65,0x56,0x61,0x6c,0x75,0x65,0x20,0x2a, + 0x20,0x73,0x73,0x61,0x6f,0x56,0x61,0x6c,0x75,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x73,0x75,0x6d,0x57,0x65,0x69,0x67,0x68,0x74,0x20,0x2b,0x3d,0x20,0x65,0x64, + 0x67,0x65,0x56,0x61,0x6c,0x75,0x65,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64, + 0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x28,0x69, + 0x6e,0x74,0x32,0x20,0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x6f,0x75,0x74,0x70,0x75,0x74,0x56,0x61,0x6c,0x75,0x65,0x2c, + 0x20,0x62,0x6f,0x6f,0x6c,0x20,0x66,0x69,0x6e,0x61,0x6c,0x41,0x70,0x70,0x6c,0x79, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x61,0x6f,0x5b,0x70, + 0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x5d,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x28,0x6f,0x75,0x74,0x70,0x75,0x74,0x56,0x61,0x6c,0x75,0x65,0x20,0x2a,0x20, + 0x28,0x66,0x69,0x6e,0x61,0x6c,0x41,0x70,0x70,0x6c,0x79,0x20,0x3f,0x20,0x31,0x2e, + 0x35,0x66,0x20,0x3a,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66, + 0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x2e,0x78,0x3b, + 0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x63,0x6f,0x6d,0x70,0x5f,0x6d,0x61, + 0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20, + 0x5f,0x31,0x36,0x38,0x20,0x3d,0x20,0x69,0x6e,0x74,0x32,0x28,0x67,0x6c,0x5f,0x47, + 0x6c,0x6f,0x62,0x61,0x6c,0x49,0x6e,0x76,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x49, + 0x44,0x2e,0x78,0x79,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20, + 0x5f,0x31,0x37,0x36,0x20,0x3d,0x20,0x69,0x6e,0x74,0x32,0x28,0x5f,0x31,0x36,0x38, + 0x2e,0x78,0x20,0x2a,0x20,0x32,0x2c,0x20,0x5f,0x31,0x36,0x38,0x2e,0x79,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f, + 0x6c,0x32,0x28,0x5f,0x31,0x37,0x36,0x2e,0x78,0x20,0x3e,0x3d,0x20,0x67,0x74,0x61, + 0x6f,0x5f,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65,0x2e,0x78, + 0x2c,0x20,0x5f,0x31,0x37,0x36,0x2e,0x79,0x20,0x3e,0x3d,0x20,0x67,0x74,0x61,0x6f, + 0x5f,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65,0x2e,0x79,0x29, + 0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x39,0x33,0x20,0x3d,0x20,0x5f, + 0x31,0x38,0x39,0x5f,0x46,0x69,0x6e,0x61,0x6c,0x41,0x70,0x70,0x6c,0x79,0x20,0x21, + 0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x39,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x39, + 0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x5f,0x31,0x39,0x36,0x20,0x3d,0x20,0x67,0x74,0x61,0x6f,0x5f,0x44,0x65,0x6e, + 0x6f,0x69,0x73,0x65,0x42,0x6c,0x75,0x72,0x42,0x65,0x74,0x61,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x39,0x36,0x20, + 0x3d,0x20,0x67,0x74,0x61,0x6f,0x5f,0x44,0x65,0x6e,0x6f,0x69,0x73,0x65,0x42,0x6c, + 0x75,0x72,0x42,0x65,0x74,0x61,0x20,0x2a,0x20,0x30,0x2e,0x32,0x30,0x30,0x30,0x30, + 0x30,0x30,0x30,0x32,0x39,0x38,0x30,0x32,0x33,0x32,0x32,0x33,0x38,0x37,0x36,0x39, + 0x35,0x33,0x31,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x65,0x64,0x67,0x65,0x73,0x4e,0x5b,0x34, + 0x5d,0x5b,0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x61,0x6f,0x5b,0x34,0x5d,0x5b,0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6f, + 0x72,0x20,0x28,0x69,0x6e,0x74,0x20,0x69,0x20,0x3d,0x20,0x30,0x3b,0x20,0x69,0x20, + 0x3c,0x20,0x34,0x3b,0x20,0x69,0x2b,0x2b,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x20,0x28,0x69,0x6e,0x74, + 0x20,0x6a,0x20,0x3d,0x20,0x30,0x3b,0x20,0x6a,0x20,0x3c,0x20,0x33,0x3b,0x20,0x6a, + 0x2b,0x2b,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x5f, + 0x32,0x33,0x32,0x20,0x3d,0x20,0x5f,0x31,0x37,0x36,0x20,0x2b,0x20,0x69,0x6e,0x74, + 0x32,0x28,0x69,0x20,0x2d,0x20,0x31,0x2c,0x20,0x6a,0x20,0x2d,0x20,0x31,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74, + 0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f,0x32,0x33,0x32,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x64,0x67,0x65, + 0x73,0x4e,0x5b,0x69,0x5d,0x5b,0x6a,0x5d,0x20,0x3d,0x20,0x66,0x65,0x74,0x63,0x68, + 0x45,0x64,0x67,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x32,0x33,0x32,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x61,0x6f,0x5b,0x69,0x5d,0x5b, + 0x6a,0x5d,0x20,0x3d,0x20,0x66,0x65,0x74,0x63,0x68,0x41,0x4f,0x28,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x20,0x28, + 0x69,0x6e,0x74,0x20,0x73,0x69,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x20,0x73,0x69, + 0x64,0x65,0x20,0x3c,0x20,0x32,0x3b,0x20,0x73,0x69,0x64,0x65,0x2b,0x2b,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e, + 0x74,0x32,0x20,0x5f,0x32,0x36,0x37,0x20,0x3d,0x20,0x5f,0x31,0x37,0x36,0x20,0x2b, + 0x20,0x69,0x6e,0x74,0x32,0x28,0x73,0x69,0x64,0x65,0x2c,0x20,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x32,0x36,0x37, + 0x2e,0x78,0x20,0x3e,0x3d,0x20,0x67,0x74,0x61,0x6f,0x5f,0x56,0x69,0x65,0x77,0x70, + 0x6f,0x72,0x74,0x53,0x69,0x7a,0x65,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x62,0x72,0x65,0x61,0x6b,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x32, + 0x37,0x38,0x20,0x3d,0x20,0x31,0x20,0x2b,0x20,0x73,0x69,0x64,0x65,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x32,0x38,0x34,0x20, + 0x3d,0x20,0x73,0x69,0x64,0x65,0x20,0x2b,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x20,0x3d,0x20,0x65,0x64,0x67,0x65,0x73,0x4e,0x5b,0x5f,0x32,0x37,0x38,0x5d, + 0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x65,0x64,0x67,0x65,0x73,0x43,0x5f,0x4c,0x52,0x54,0x42,0x20, + 0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x55,0x6e,0x70,0x61,0x63,0x6b,0x45, + 0x64,0x67,0x65,0x73,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x65,0x64,0x67,0x65,0x73,0x4e,0x5b,0x73,0x69, + 0x64,0x65,0x5d,0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x32,0x39,0x36,0x20,0x3d,0x20,0x58,0x65, + 0x47,0x54,0x41,0x4f,0x5f,0x55,0x6e,0x70,0x61,0x63,0x6b,0x45,0x64,0x67,0x65,0x73, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, + 0x20,0x3d,0x20,0x65,0x64,0x67,0x65,0x73,0x4e,0x5b,0x5f,0x32,0x38,0x34,0x5d,0x5b, + 0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x5f,0x33,0x30,0x32,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f, + 0x5f,0x55,0x6e,0x70,0x61,0x63,0x6b,0x45,0x64,0x67,0x65,0x73,0x28,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x65, + 0x64,0x67,0x65,0x73,0x4e,0x5b,0x5f,0x32,0x37,0x38,0x5d,0x5b,0x30,0x5d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f, + 0x33,0x30,0x38,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x55,0x6e,0x70, + 0x61,0x63,0x6b,0x45,0x64,0x67,0x65,0x73,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x65,0x64,0x67,0x65,0x73, + 0x4e,0x5b,0x5f,0x32,0x37,0x38,0x5d,0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x33,0x31,0x34,0x20, + 0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x55,0x6e,0x70,0x61,0x63,0x6b,0x45, + 0x64,0x67,0x65,0x73,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x33, + 0x32,0x34,0x20,0x3d,0x20,0x65,0x64,0x67,0x65,0x73,0x43,0x5f,0x4c,0x52,0x54,0x42, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x5f,0x33,0x32,0x35,0x20,0x3d,0x20,0x5f,0x33,0x32,0x34,0x20,0x2a,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x32,0x39,0x36,0x2e,0x79,0x2c,0x20,0x5f,0x33, + 0x30,0x32,0x2e,0x78,0x2c,0x20,0x5f,0x33,0x30,0x38,0x2e,0x77,0x2c,0x20,0x5f,0x33, + 0x31,0x34,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x33,0x34,0x31,0x20,0x3d,0x20,0x63,0x6c,0x61, + 0x6d,0x70,0x28,0x5f,0x33,0x32,0x35,0x20,0x2b,0x20,0x28,0x63,0x6c,0x61,0x6d,0x70, + 0x28,0x31,0x2e,0x35,0x66,0x20,0x2d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x33,0x32,0x35, + 0x2c,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x78,0x29,0x2c,0x20,0x30,0x2e, + 0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x20,0x2a,0x20,0x30,0x2e,0x33,0x33, + 0x33,0x33,0x33,0x33,0x33,0x34,0x33,0x32,0x36,0x37,0x34,0x34,0x30,0x37,0x39,0x35, + 0x38,0x39,0x38,0x34,0x33,0x37,0x35,0x66,0x29,0x2e,0x78,0x78,0x78,0x78,0x2c,0x20, + 0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x78,0x2c,0x20,0x31,0x2e,0x30,0x66,0x2e, + 0x78,0x78,0x78,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65, + 0x64,0x67,0x65,0x73,0x43,0x5f,0x4c,0x52,0x54,0x42,0x20,0x3d,0x20,0x5f,0x33,0x34, + 0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x33,0x34,0x35,0x20,0x3d,0x20,0x5f,0x33,0x34,0x31,0x2e,0x78,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x33, + 0x35,0x30,0x20,0x3d,0x20,0x5f,0x33,0x34,0x31,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x33,0x36,0x33,0x20, + 0x3d,0x20,0x5f,0x33,0x34,0x31,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x33,0x37,0x31,0x20,0x3d,0x20,0x5f, + 0x33,0x34,0x31,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x61, + 0x6f,0x5b,0x73,0x69,0x64,0x65,0x5d,0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x38,0x20,0x3d,0x20,0x5f,0x33,0x34,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20, + 0x3d,0x20,0x61,0x6f,0x5b,0x5f,0x32,0x37,0x38,0x5d,0x5b,0x31,0x5d,0x20,0x2a,0x20, + 0x5f,0x31,0x39,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x5f, + 0x31,0x39,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x58,0x65,0x47, + 0x54,0x41,0x4f,0x5f,0x41,0x64,0x64,0x53,0x61,0x6d,0x70,0x6c,0x65,0x28,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x61,0x6f,0x5b, + 0x5f,0x32,0x38,0x34,0x5d,0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32, + 0x20,0x3d,0x20,0x65,0x64,0x67,0x65,0x73,0x43,0x5f,0x4c,0x52,0x54,0x42,0x2e,0x79, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x58, + 0x65,0x47,0x54,0x41,0x4f,0x5f,0x41,0x64,0x64,0x53,0x61,0x6d,0x70,0x6c,0x65,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20, + 0x3d,0x20,0x61,0x6f,0x5b,0x5f,0x32,0x37,0x38,0x5d,0x5b,0x30,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x65,0x64,0x67,0x65,0x73,0x43,0x5f,0x4c, + 0x52,0x54,0x42,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x20,0x3d,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38, + 0x20,0x3d,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x41,0x64,0x64,0x53, + 0x61,0x6d,0x70,0x6c,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20,0x61,0x6f,0x5b,0x5f,0x32,0x37,0x38,0x5d, + 0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x20,0x3d,0x20,0x65,0x64, + 0x67,0x65,0x73,0x43,0x5f,0x4c,0x52,0x54,0x42,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x31,0x20,0x3d,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x32,0x20,0x3d,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x58,0x65,0x47,0x54,0x41, + 0x4f,0x5f,0x41,0x64,0x64,0x53,0x61,0x6d,0x70,0x6c,0x65,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33,0x20,0x3d,0x20,0x61,0x6f, + 0x5b,0x73,0x69,0x64,0x65,0x5d,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x34,0x20,0x3d,0x20,0x30,0x2e,0x34,0x32,0x35,0x30,0x30,0x30,0x30,0x31,0x31,0x39, + 0x32,0x30,0x39,0x32,0x38,0x39,0x35,0x35,0x30,0x37,0x38,0x31,0x32,0x35,0x66,0x20, + 0x2a,0x20,0x28,0x28,0x5f,0x33,0x34,0x35,0x20,0x2a,0x20,0x5f,0x32,0x39,0x36,0x2e, + 0x7a,0x29,0x20,0x2b,0x20,0x28,0x5f,0x33,0x35,0x30,0x20,0x2a,0x20,0x5f,0x33,0x30, + 0x38,0x2e,0x78,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x35,0x20,0x3d,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x36, + 0x20,0x3d,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x41,0x64,0x64,0x53, + 0x61,0x6d,0x70,0x6c,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x36,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x37,0x20,0x3d,0x20,0x61,0x6f,0x5b,0x5f,0x32,0x38,0x34,0x5d, + 0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x38,0x20,0x3d,0x20,0x30,0x2e, + 0x34,0x32,0x35,0x30,0x30,0x30,0x30,0x31,0x31,0x39,0x32,0x30,0x39,0x32,0x38,0x39, + 0x35,0x35,0x30,0x37,0x38,0x31,0x32,0x35,0x66,0x20,0x2a,0x20,0x28,0x28,0x5f,0x33, + 0x35,0x30,0x20,0x2a,0x20,0x5f,0x33,0x30,0x38,0x2e,0x79,0x29,0x20,0x2b,0x20,0x28, + 0x5f,0x33,0x36,0x33,0x20,0x2a,0x20,0x5f,0x33,0x30,0x32,0x2e,0x7a,0x29,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x39,0x20,0x3d,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x30,0x20,0x3d,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x58, + 0x65,0x47,0x54,0x41,0x4f,0x5f,0x41,0x64,0x64,0x53,0x61,0x6d,0x70,0x6c,0x65,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x39,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x31,0x20, + 0x3d,0x20,0x61,0x6f,0x5b,0x73,0x69,0x64,0x65,0x5d,0x5b,0x32,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x32,0x20,0x3d,0x20,0x30,0x2e,0x34,0x32,0x35,0x30,0x30,0x30, + 0x30,0x31,0x31,0x39,0x32,0x30,0x39,0x32,0x38,0x39,0x35,0x35,0x30,0x37,0x38,0x31, + 0x32,0x35,0x66,0x20,0x2a,0x20,0x28,0x28,0x5f,0x33,0x37,0x31,0x20,0x2a,0x20,0x5f, + 0x33,0x31,0x34,0x2e,0x78,0x29,0x20,0x2b,0x20,0x28,0x5f,0x33,0x34,0x35,0x20,0x2a, + 0x20,0x5f,0x32,0x39,0x36,0x2e,0x77,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, + 0x33,0x20,0x3d,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x39,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x33,0x34,0x20,0x3d,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x30,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f, + 0x41,0x64,0x64,0x53,0x61,0x6d,0x70,0x6c,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x32,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x35,0x20,0x3d,0x20,0x61,0x6f,0x5b,0x5f, + 0x32,0x38,0x34,0x5d,0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x36,0x20, + 0x3d,0x20,0x30,0x2e,0x34,0x32,0x35,0x30,0x30,0x30,0x30,0x31,0x31,0x39,0x32,0x30, + 0x39,0x32,0x38,0x39,0x35,0x35,0x30,0x37,0x38,0x31,0x32,0x35,0x66,0x20,0x2a,0x20, + 0x28,0x28,0x5f,0x33,0x36,0x33,0x20,0x2a,0x20,0x5f,0x33,0x30,0x32,0x2e,0x77,0x29, + 0x20,0x2b,0x20,0x28,0x5f,0x33,0x37,0x31,0x20,0x2a,0x20,0x5f,0x33,0x31,0x34,0x2e, + 0x79,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x37,0x20,0x3d,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x38,0x20,0x3d, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x41,0x64,0x64,0x53,0x61,0x6d, + 0x70,0x6c,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x35,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x37, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x39,0x20,0x3d,0x20,0x5f,0x32,0x36,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, + 0x30,0x20,0x3d,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x37,0x20,0x2f,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x33,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x62,0x6f,0x6f,0x6c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x31,0x20,0x3d, + 0x20,0x5f,0x31,0x39,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x58, + 0x65,0x47,0x54,0x41,0x4f,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x28,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x30,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x7d,0x0a,0x0a,0x5b,0x6e,0x75,0x6d,0x74,0x68,0x72,0x65,0x61,0x64,0x73, + 0x28,0x38,0x2c,0x20,0x38,0x2c,0x20,0x31,0x29,0x5d,0x0a,0x76,0x6f,0x69,0x64,0x20, + 0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73, + 0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70, + 0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x47,0x6c,0x6f, + 0x62,0x61,0x6c,0x49,0x6e,0x76,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x49,0x44,0x20, + 0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c, + 0x5f,0x47,0x6c,0x6f,0x62,0x61,0x6c,0x49,0x6e,0x76,0x6f,0x63,0x61,0x74,0x69,0x6f, + 0x6e,0x49,0x44,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6d,0x70,0x5f,0x6d,0x61, + 0x69,0x6e,0x28,0x29,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + #pragma clang diagnostic ignored "-Wmissing-prototypes" + #pragma clang diagnostic ignored "-Wmissing-braces" + + #include + #include + + using namespace metal; + + template + struct spvUnsafeArray + { + T elements[Num ? Num : 1]; + + thread T& operator [] (size_t pos) thread + { + return elements[pos]; + } + constexpr const thread T& operator [] (size_t pos) const thread + { + return elements[pos]; + } + + device T& operator [] (size_t pos) device + { + return elements[pos]; + } + constexpr const device T& operator [] (size_t pos) const device + { + return elements[pos]; + } + + constexpr const constant T& operator [] (size_t pos) const constant + { + return elements[pos]; + } + + threadgroup T& operator [] (size_t pos) threadgroup + { + return elements[pos]; + } + constexpr const threadgroup T& operator [] (size_t pos) const threadgroup + { + return elements[pos]; + } + }; + + struct ub_gtao + { + int2 ViewportSize; + float DenoiseBlurBeta; + }; + + struct ub_denoise + { + int FinalApply; + int _Pad0; + int _Pad1; + int _Pad2; + }; + + constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(8u, 8u, 1u); + + static inline __attribute__((always_inline)) + float fetchEdge(thread const int2& coord, constant ub_gtao& gtao, texture2d tex_edges, sampler smp_point_clamp) + { + return tex_edges.read(uint2(clamp(coord, int2(0), gtao.ViewportSize - int2(1))), 0).x; + } + + static inline __attribute__((always_inline)) + float fetchAO(thread const int2& coord, constant ub_gtao& gtao, sampler smp_point_clamp, texture2d tex_noisy_ao) + { + return tex_noisy_ao.read(uint2(clamp(coord, int2(0), gtao.ViewportSize - int2(1))), 0).x; + } + + static inline __attribute__((always_inline)) + float4 XeGTAO_UnpackEdges(thread const float& packed_val) + { + uint _44 = uint(packed_val * 255.5); + return fast::clamp(float4(float((_44 >> uint(6)) & 3u) * 0.3333333432674407958984375, float((_44 >> uint(4)) & 3u) * 0.3333333432674407958984375, float((_44 >> uint(2)) & 3u) * 0.3333333432674407958984375, float((_44) & 3u) * 0.3333333432674407958984375), float4(0.0), float4(1.0)); + } + + static inline __attribute__((always_inline)) + void XeGTAO_AddSample(thread const float& ssaoValue, thread const float& edgeValue, thread float& sum, thread float& sumWeight) + { + sum += (edgeValue * ssaoValue); + sumWeight += edgeValue; + } + + static inline __attribute__((always_inline)) + void XeGTAO_Output(thread const int2& pixCoord, thread const float& outputValue, thread const bool& finalApply, texture2d out_ao) + { + out_ao.write(float4(outputValue * (finalApply ? 1.5 : 1.0), 0.0, 0.0, 0.0), uint2(pixCoord)); + } + + kernel void main0(constant ub_gtao& gtao [[buffer(0)]], constant ub_denoise& _189 [[buffer(1)]], texture2d out_ao [[texture(0)]], texture2d tex_edges [[texture(1)]], texture2d tex_noisy_ao [[texture(2)]], sampler smp_point_clamp [[sampler(0)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]]) + { + int2 _168 = int2(gl_GlobalInvocationID.xy); + int2 _176 = int2(_168.x * 2, _168.y); + if (any(_176 >= gtao.ViewportSize)) + { + return; + } + bool _193 = _189.FinalApply != 0; + float _196; + if (_193) + { + _196 = gtao.DenoiseBlurBeta; + } + else + { + _196 = gtao.DenoiseBlurBeta * 0.20000000298023223876953125; + } + spvUnsafeArray, 4> edgesN; + spvUnsafeArray, 4> ao; + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < 3; j++) + { + int2 _232 = _176 + int2(i - 1, j - 1); + int2 param = _232; + edgesN[i][j] = fetchEdge(param, gtao, tex_edges, smp_point_clamp); + int2 param_1 = _232; + ao[i][j] = fetchAO(param_1, gtao, smp_point_clamp, tex_noisy_ao); + } + } + for (int side = 0; side < 2; side++) + { + int2 _267 = _176 + int2(side, 0); + if (_267.x >= gtao.ViewportSize.x) + { + break; + } + int _278 = 1 + side; + int _284 = side + 2; + float param_2 = edgesN[_278][1]; + float4 edgesC_LRTB = XeGTAO_UnpackEdges(param_2); + float param_3 = edgesN[side][1]; + float4 _296 = XeGTAO_UnpackEdges(param_3); + float param_4 = edgesN[_284][1]; + float4 _302 = XeGTAO_UnpackEdges(param_4); + float param_5 = edgesN[_278][0]; + float4 _308 = XeGTAO_UnpackEdges(param_5); + float param_6 = edgesN[_278][2]; + float4 _314 = XeGTAO_UnpackEdges(param_6); + float4 _324 = edgesC_LRTB; + float4 _325 = _324 * float4(_296.y, _302.x, _308.w, _314.z); + float4 _341 = fast::clamp(_325 + float4(fast::clamp(1.5 - dot(_325, float4(1.0)), 0.0, 1.0) * 0.3333333432674407958984375), float4(0.0), float4(1.0)); + edgesC_LRTB = _341; + float _345 = _341.x; + float _350 = _341.z; + float _363 = _341.y; + float _371 = _341.w; + float param_7 = ao[side][1]; + float param_8 = _345; + float param_9 = ao[_278][1] * _196; + float param_10 = _196; + XeGTAO_AddSample(param_7, param_8, param_9, param_10); + float param_11 = ao[_284][1]; + float param_12 = edgesC_LRTB.y; + float param_13 = param_9; + float param_14 = param_10; + XeGTAO_AddSample(param_11, param_12, param_13, param_14); + float param_15 = ao[_278][0]; + float param_16 = edgesC_LRTB.z; + float param_17 = param_13; + float param_18 = param_14; + XeGTAO_AddSample(param_15, param_16, param_17, param_18); + float param_19 = ao[_278][2]; + float param_20 = edgesC_LRTB.w; + float param_21 = param_17; + float param_22 = param_18; + XeGTAO_AddSample(param_19, param_20, param_21, param_22); + float param_23 = ao[side][0]; + float param_24 = 0.425000011920928955078125 * ((_345 * _296.z) + (_350 * _308.x)); + float param_25 = param_21; + float param_26 = param_22; + XeGTAO_AddSample(param_23, param_24, param_25, param_26); + float param_27 = ao[_284][0]; + float param_28 = 0.425000011920928955078125 * ((_350 * _308.y) + (_363 * _302.z)); + float param_29 = param_25; + float param_30 = param_26; + XeGTAO_AddSample(param_27, param_28, param_29, param_30); + float param_31 = ao[side][2]; + float param_32 = 0.425000011920928955078125 * ((_371 * _314.x) + (_345 * _296.w)); + float param_33 = param_29; + float param_34 = param_30; + XeGTAO_AddSample(param_31, param_32, param_33, param_34); + float param_35 = ao[_284][2]; + float param_36 = 0.425000011920928955078125 * ((_363 * _302.w) + (_371 * _314.y)); + float param_37 = param_33; + float param_38 = param_34; + XeGTAO_AddSample(param_35, param_36, param_37, param_38); + int2 param_39 = _267; + float param_40 = param_37 / param_38; + bool param_41 = _193; + XeGTAO_Output(param_39, param_40, param_41, out_ao); + } + } + +*/ +static const uint8_t gtao_denoise_cs_source_metal_macos[7124] = { + 0x23,0x70,0x72,0x61,0x67,0x6d,0x61,0x20,0x63,0x6c,0x61,0x6e,0x67,0x20,0x64,0x69, + 0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x20,0x69,0x67,0x6e,0x6f,0x72,0x65,0x64, + 0x20,0x22,0x2d,0x57,0x6d,0x69,0x73,0x73,0x69,0x6e,0x67,0x2d,0x70,0x72,0x6f,0x74, + 0x6f,0x74,0x79,0x70,0x65,0x73,0x22,0x0a,0x23,0x70,0x72,0x61,0x67,0x6d,0x61,0x20, + 0x63,0x6c,0x61,0x6e,0x67,0x20,0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63, + 0x20,0x69,0x67,0x6e,0x6f,0x72,0x65,0x64,0x20,0x22,0x2d,0x57,0x6d,0x69,0x73,0x73, + 0x69,0x6e,0x67,0x2d,0x62,0x72,0x61,0x63,0x65,0x73,0x22,0x0a,0x0a,0x23,0x69,0x6e, + 0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f,0x73,0x74,0x64, + 0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x73, + 0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a,0x75,0x73,0x69, + 0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20,0x6d,0x65,0x74, + 0x61,0x6c,0x3b,0x0a,0x0a,0x74,0x65,0x6d,0x70,0x6c,0x61,0x74,0x65,0x3c,0x74,0x79, + 0x70,0x65,0x6e,0x61,0x6d,0x65,0x20,0x54,0x2c,0x20,0x73,0x69,0x7a,0x65,0x5f,0x74, + 0x20,0x4e,0x75,0x6d,0x3e,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x73,0x70,0x76, + 0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x54,0x20,0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x4e,0x75,0x6d, + 0x20,0x3f,0x20,0x4e,0x75,0x6d,0x20,0x3a,0x20,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x0a,0x20,0x20,0x20,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x54,0x26,0x20, + 0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72,0x20,0x5b,0x5d,0x20,0x28,0x73,0x69,0x7a, + 0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f, + 0x73,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x65,0x78,0x70,0x72,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x74,0x68, + 0x72,0x65,0x61,0x64,0x20,0x54,0x26,0x20,0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72, + 0x20,0x5b,0x5d,0x20,0x28,0x73,0x69,0x7a,0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f,0x73,0x5d, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x0a,0x20,0x20,0x20, + 0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x20,0x54,0x26,0x20,0x6f,0x70,0x65,0x72,0x61, + 0x74,0x6f,0x72,0x20,0x5b,0x5d,0x20,0x28,0x73,0x69,0x7a,0x65,0x5f,0x74,0x20,0x70, + 0x6f,0x73,0x29,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f,0x73,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6e,0x73,0x74,0x65,0x78, + 0x70,0x72,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x20, + 0x54,0x26,0x20,0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72,0x20,0x5b,0x5d,0x20,0x28, + 0x73,0x69,0x7a,0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x65,0x6c, + 0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f,0x73,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x65,0x78,0x70,0x72,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x61,0x6e,0x74,0x20,0x54,0x26,0x20,0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72, + 0x20,0x5b,0x5d,0x20,0x28,0x73,0x69,0x7a,0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f, + 0x73,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x0a,0x20, + 0x20,0x20,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x67,0x72,0x6f,0x75,0x70,0x20,0x54, + 0x26,0x20,0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72,0x20,0x5b,0x5d,0x20,0x28,0x73, + 0x69,0x7a,0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x67,0x72,0x6f,0x75,0x70,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x65,0x6c,0x65,0x6d, + 0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f,0x73,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6e,0x73,0x74,0x65,0x78,0x70,0x72,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x67,0x72,0x6f,0x75,0x70, + 0x20,0x54,0x26,0x20,0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72,0x20,0x5b,0x5d,0x20, + 0x28,0x73,0x69,0x7a,0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x67,0x72,0x6f,0x75,0x70,0x0a,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f,0x73, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72, + 0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x67,0x74,0x61,0x6f,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53, + 0x69,0x7a,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x44, + 0x65,0x6e,0x6f,0x69,0x73,0x65,0x42,0x6c,0x75,0x72,0x42,0x65,0x74,0x61,0x3b,0x0a, + 0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x64,0x65, + 0x6e,0x6f,0x69,0x73,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20, + 0x46,0x69,0x6e,0x61,0x6c,0x41,0x70,0x70,0x6c,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x6e,0x74,0x20,0x5f,0x50,0x61,0x64,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x6e,0x74,0x20,0x5f,0x50,0x61,0x64,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e, + 0x74,0x20,0x5f,0x50,0x61,0x64,0x32,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x63,0x6f,0x6e, + 0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x69,0x6e,0x74,0x33,0x20,0x67,0x6c,0x5f,0x57, + 0x6f,0x72,0x6b,0x47,0x72,0x6f,0x75,0x70,0x53,0x69,0x7a,0x65,0x20,0x5b,0x5b,0x6d, + 0x61,0x79,0x62,0x65,0x5f,0x75,0x6e,0x75,0x73,0x65,0x64,0x5d,0x5d,0x20,0x3d,0x20, + 0x75,0x69,0x6e,0x74,0x33,0x28,0x38,0x75,0x2c,0x20,0x38,0x75,0x2c,0x20,0x31,0x75, + 0x29,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e, + 0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28, + 0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29, + 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x66,0x65,0x74,0x63,0x68,0x45,0x64,0x67,0x65, + 0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x69,0x6e, + 0x74,0x32,0x26,0x20,0x63,0x6f,0x6f,0x72,0x64,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x67,0x74,0x61,0x6f,0x26,0x20,0x67,0x74,0x61, + 0x6f,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f, + 0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x65,0x64,0x67,0x65,0x73,0x2c,0x20,0x73, + 0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x70,0x6f,0x69,0x6e,0x74, + 0x5f,0x63,0x6c,0x61,0x6d,0x70,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x74,0x65,0x78,0x5f,0x65,0x64,0x67,0x65,0x73,0x2e,0x72, + 0x65,0x61,0x64,0x28,0x75,0x69,0x6e,0x74,0x32,0x28,0x63,0x6c,0x61,0x6d,0x70,0x28, + 0x63,0x6f,0x6f,0x72,0x64,0x2c,0x20,0x69,0x6e,0x74,0x32,0x28,0x30,0x29,0x2c,0x20, + 0x67,0x74,0x61,0x6f,0x2e,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a, + 0x65,0x20,0x2d,0x20,0x69,0x6e,0x74,0x32,0x28,0x31,0x29,0x29,0x29,0x2c,0x20,0x30, + 0x29,0x2e,0x78,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69, + 0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74, + 0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69, + 0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x66,0x65,0x74,0x63,0x68, + 0x41,0x4f,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, + 0x69,0x6e,0x74,0x32,0x26,0x20,0x63,0x6f,0x6f,0x72,0x64,0x2c,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x67,0x74,0x61,0x6f,0x26,0x20,0x67, + 0x74,0x61,0x6f,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70, + 0x5f,0x70,0x6f,0x69,0x6e,0x74,0x5f,0x63,0x6c,0x61,0x6d,0x70,0x2c,0x20,0x74,0x65, + 0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74, + 0x65,0x78,0x5f,0x6e,0x6f,0x69,0x73,0x79,0x5f,0x61,0x6f,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x74,0x65,0x78,0x5f,0x6e,0x6f, + 0x69,0x73,0x79,0x5f,0x61,0x6f,0x2e,0x72,0x65,0x61,0x64,0x28,0x75,0x69,0x6e,0x74, + 0x32,0x28,0x63,0x6c,0x61,0x6d,0x70,0x28,0x63,0x6f,0x6f,0x72,0x64,0x2c,0x20,0x69, + 0x6e,0x74,0x32,0x28,0x30,0x29,0x2c,0x20,0x67,0x74,0x61,0x6f,0x2e,0x56,0x69,0x65, + 0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65,0x20,0x2d,0x20,0x69,0x6e,0x74,0x32, + 0x28,0x31,0x29,0x29,0x29,0x2c,0x20,0x30,0x29,0x2e,0x78,0x3b,0x0a,0x7d,0x0a,0x0a, + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f, + 0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77, + 0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x55,0x6e,0x70,0x61,0x63, + 0x6b,0x45,0x64,0x67,0x65,0x73,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x70,0x61,0x63,0x6b,0x65, + 0x64,0x5f,0x76,0x61,0x6c,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e, + 0x74,0x20,0x5f,0x34,0x34,0x20,0x3d,0x20,0x75,0x69,0x6e,0x74,0x28,0x70,0x61,0x63, + 0x6b,0x65,0x64,0x5f,0x76,0x61,0x6c,0x20,0x2a,0x20,0x32,0x35,0x35,0x2e,0x35,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x61,0x73, + 0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, + 0x66,0x6c,0x6f,0x61,0x74,0x28,0x28,0x5f,0x34,0x34,0x20,0x3e,0x3e,0x20,0x75,0x69, + 0x6e,0x74,0x28,0x36,0x29,0x29,0x20,0x26,0x20,0x33,0x75,0x29,0x20,0x2a,0x20,0x30, + 0x2e,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x34,0x33,0x32,0x36,0x37,0x34,0x34,0x30, + 0x37,0x39,0x35,0x38,0x39,0x38,0x34,0x33,0x37,0x35,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x28,0x28,0x5f,0x34,0x34,0x20,0x3e,0x3e,0x20,0x75,0x69,0x6e,0x74,0x28,0x34, + 0x29,0x29,0x20,0x26,0x20,0x33,0x75,0x29,0x20,0x2a,0x20,0x30,0x2e,0x33,0x33,0x33, + 0x33,0x33,0x33,0x33,0x34,0x33,0x32,0x36,0x37,0x34,0x34,0x30,0x37,0x39,0x35,0x38, + 0x39,0x38,0x34,0x33,0x37,0x35,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x28,0x5f, + 0x34,0x34,0x20,0x3e,0x3e,0x20,0x75,0x69,0x6e,0x74,0x28,0x32,0x29,0x29,0x20,0x26, + 0x20,0x33,0x75,0x29,0x20,0x2a,0x20,0x30,0x2e,0x33,0x33,0x33,0x33,0x33,0x33,0x33, + 0x34,0x33,0x32,0x36,0x37,0x34,0x34,0x30,0x37,0x39,0x35,0x38,0x39,0x38,0x34,0x33, + 0x37,0x35,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x28,0x5f,0x34,0x34,0x29,0x20, + 0x26,0x20,0x33,0x75,0x29,0x20,0x2a,0x20,0x30,0x2e,0x33,0x33,0x33,0x33,0x33,0x33, + 0x33,0x34,0x33,0x32,0x36,0x37,0x34,0x34,0x30,0x37,0x39,0x35,0x38,0x39,0x38,0x34, + 0x33,0x37,0x35,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x30,0x2e,0x30, + 0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x31,0x2e,0x30,0x29,0x29,0x3b, + 0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e, + 0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28, + 0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29, + 0x0a,0x76,0x6f,0x69,0x64,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x41,0x64,0x64, + 0x53,0x61,0x6d,0x70,0x6c,0x65,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x73,0x73,0x61,0x6f,0x56, + 0x61,0x6c,0x75,0x65,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x65,0x64,0x67,0x65,0x56,0x61, + 0x6c,0x75,0x65,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x26,0x20,0x73,0x75,0x6d,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x26,0x20,0x73,0x75,0x6d,0x57,0x65,0x69,0x67,0x68,0x74,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x65, + 0x64,0x67,0x65,0x56,0x61,0x6c,0x75,0x65,0x20,0x2a,0x20,0x73,0x73,0x61,0x6f,0x56, + 0x61,0x6c,0x75,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x57,0x65, + 0x69,0x67,0x68,0x74,0x20,0x2b,0x3d,0x20,0x65,0x64,0x67,0x65,0x56,0x61,0x6c,0x75, + 0x65,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c, + 0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f, + 0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65, + 0x29,0x29,0x0a,0x76,0x6f,0x69,0x64,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x4f, + 0x75,0x74,0x70,0x75,0x74,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x69,0x6e,0x74,0x32,0x26,0x20,0x70,0x69,0x78,0x43,0x6f,0x6f,0x72, + 0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6f,0x75,0x74,0x70,0x75,0x74,0x56,0x61,0x6c, + 0x75,0x65,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x20,0x62,0x6f,0x6f,0x6c,0x26,0x20,0x66,0x69,0x6e,0x61,0x6c,0x41,0x70,0x70,0x6c, + 0x79,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f, + 0x61,0x74,0x2c,0x20,0x61,0x63,0x63,0x65,0x73,0x73,0x3a,0x3a,0x77,0x72,0x69,0x74, + 0x65,0x3e,0x20,0x6f,0x75,0x74,0x5f,0x61,0x6f,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x6f,0x75,0x74,0x5f,0x61,0x6f,0x2e,0x77,0x72,0x69,0x74,0x65,0x28,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x6f,0x75,0x74,0x70,0x75,0x74,0x56,0x61,0x6c,0x75,0x65, + 0x20,0x2a,0x20,0x28,0x66,0x69,0x6e,0x61,0x6c,0x41,0x70,0x70,0x6c,0x79,0x20,0x3f, + 0x20,0x31,0x2e,0x35,0x20,0x3a,0x20,0x31,0x2e,0x30,0x29,0x2c,0x20,0x30,0x2e,0x30, + 0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x29,0x2c,0x20,0x75,0x69,0x6e, + 0x74,0x32,0x28,0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x29,0x29,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x6b,0x65,0x72,0x6e,0x65,0x6c,0x20,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61, + 0x69,0x6e,0x30,0x28,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f, + 0x67,0x74,0x61,0x6f,0x26,0x20,0x67,0x74,0x61,0x6f,0x20,0x5b,0x5b,0x62,0x75,0x66, + 0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61, + 0x6e,0x74,0x20,0x75,0x62,0x5f,0x64,0x65,0x6e,0x6f,0x69,0x73,0x65,0x26,0x20,0x5f, + 0x31,0x38,0x39,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x31,0x29,0x5d, + 0x5d,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f, + 0x61,0x74,0x2c,0x20,0x61,0x63,0x63,0x65,0x73,0x73,0x3a,0x3a,0x77,0x72,0x69,0x74, + 0x65,0x3e,0x20,0x6f,0x75,0x74,0x5f,0x61,0x6f,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74, + 0x75,0x72,0x65,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72, + 0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x65, + 0x64,0x67,0x65,0x73,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x31, + 0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66, + 0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x6e,0x6f,0x69,0x73,0x79,0x5f, + 0x61,0x6f,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x32,0x29,0x5d, + 0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x70, + 0x6f,0x69,0x6e,0x74,0x5f,0x63,0x6c,0x61,0x6d,0x70,0x20,0x5b,0x5b,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x75,0x69,0x6e,0x74,0x33, + 0x20,0x67,0x6c,0x5f,0x47,0x6c,0x6f,0x62,0x61,0x6c,0x49,0x6e,0x76,0x6f,0x63,0x61, + 0x74,0x69,0x6f,0x6e,0x49,0x44,0x20,0x5b,0x5b,0x74,0x68,0x72,0x65,0x61,0x64,0x5f, + 0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5f,0x69,0x6e,0x5f,0x67,0x72,0x69,0x64, + 0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x5f, + 0x31,0x36,0x38,0x20,0x3d,0x20,0x69,0x6e,0x74,0x32,0x28,0x67,0x6c,0x5f,0x47,0x6c, + 0x6f,0x62,0x61,0x6c,0x49,0x6e,0x76,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x49,0x44, + 0x2e,0x78,0x79,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x5f, + 0x31,0x37,0x36,0x20,0x3d,0x20,0x69,0x6e,0x74,0x32,0x28,0x5f,0x31,0x36,0x38,0x2e, + 0x78,0x20,0x2a,0x20,0x32,0x2c,0x20,0x5f,0x31,0x36,0x38,0x2e,0x79,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x61,0x6e,0x79,0x28,0x5f,0x31,0x37,0x36, + 0x20,0x3e,0x3d,0x20,0x67,0x74,0x61,0x6f,0x2e,0x56,0x69,0x65,0x77,0x70,0x6f,0x72, + 0x74,0x53,0x69,0x7a,0x65,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x39, + 0x33,0x20,0x3d,0x20,0x5f,0x31,0x38,0x39,0x2e,0x46,0x69,0x6e,0x61,0x6c,0x41,0x70, + 0x70,0x6c,0x79,0x20,0x21,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x31,0x39,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x5f,0x31,0x39,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x39,0x36,0x20,0x3d,0x20,0x67,0x74,0x61, + 0x6f,0x2e,0x44,0x65,0x6e,0x6f,0x69,0x73,0x65,0x42,0x6c,0x75,0x72,0x42,0x65,0x74, + 0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, + 0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x5f,0x31,0x39,0x36,0x20,0x3d,0x20,0x67,0x74,0x61,0x6f,0x2e,0x44,0x65,0x6e,0x6f, + 0x69,0x73,0x65,0x42,0x6c,0x75,0x72,0x42,0x65,0x74,0x61,0x20,0x2a,0x20,0x30,0x2e, + 0x32,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x32,0x39,0x38,0x30,0x32,0x33,0x32,0x32, + 0x33,0x38,0x37,0x36,0x39,0x35,0x33,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41, + 0x72,0x72,0x61,0x79,0x3c,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72, + 0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x2c,0x20,0x33,0x3e,0x2c,0x20,0x34, + 0x3e,0x20,0x65,0x64,0x67,0x65,0x73,0x4e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x70, + 0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x73,0x70,0x76, + 0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61, + 0x74,0x2c,0x20,0x33,0x3e,0x2c,0x20,0x34,0x3e,0x20,0x61,0x6f,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6f,0x72,0x20,0x28,0x69,0x6e,0x74,0x20,0x69,0x20,0x3d,0x20,0x30, + 0x3b,0x20,0x69,0x20,0x3c,0x20,0x34,0x3b,0x20,0x69,0x2b,0x2b,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x20, + 0x28,0x69,0x6e,0x74,0x20,0x6a,0x20,0x3d,0x20,0x30,0x3b,0x20,0x6a,0x20,0x3c,0x20, + 0x33,0x3b,0x20,0x6a,0x2b,0x2b,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e, + 0x74,0x32,0x20,0x5f,0x32,0x33,0x32,0x20,0x3d,0x20,0x5f,0x31,0x37,0x36,0x20,0x2b, + 0x20,0x69,0x6e,0x74,0x32,0x28,0x69,0x20,0x2d,0x20,0x31,0x2c,0x20,0x6a,0x20,0x2d, + 0x20,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x69,0x6e,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f,0x32, + 0x33,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x65,0x64,0x67,0x65,0x73,0x4e,0x5b,0x69,0x5d,0x5b,0x6a,0x5d,0x20,0x3d,0x20,0x66, + 0x65,0x74,0x63,0x68,0x45,0x64,0x67,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20, + 0x67,0x74,0x61,0x6f,0x2c,0x20,0x74,0x65,0x78,0x5f,0x65,0x64,0x67,0x65,0x73,0x2c, + 0x20,0x73,0x6d,0x70,0x5f,0x70,0x6f,0x69,0x6e,0x74,0x5f,0x63,0x6c,0x61,0x6d,0x70, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x6e,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x32, + 0x33,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x61,0x6f,0x5b,0x69,0x5d,0x5b,0x6a,0x5d,0x20,0x3d,0x20,0x66,0x65,0x74,0x63,0x68, + 0x41,0x4f,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x67,0x74,0x61,0x6f, + 0x2c,0x20,0x73,0x6d,0x70,0x5f,0x70,0x6f,0x69,0x6e,0x74,0x5f,0x63,0x6c,0x61,0x6d, + 0x70,0x2c,0x20,0x74,0x65,0x78,0x5f,0x6e,0x6f,0x69,0x73,0x79,0x5f,0x61,0x6f,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x20,0x28,0x69,0x6e,0x74,0x20,0x73, + 0x69,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x20,0x73,0x69,0x64,0x65,0x20,0x3c,0x20, + 0x32,0x3b,0x20,0x73,0x69,0x64,0x65,0x2b,0x2b,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x5f,0x32, + 0x36,0x37,0x20,0x3d,0x20,0x5f,0x31,0x37,0x36,0x20,0x2b,0x20,0x69,0x6e,0x74,0x32, + 0x28,0x73,0x69,0x64,0x65,0x2c,0x20,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x32,0x36,0x37,0x2e,0x78,0x20,0x3e,0x3d, + 0x20,0x67,0x74,0x61,0x6f,0x2e,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69, + 0x7a,0x65,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x72,0x65,0x61, + 0x6b,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x32,0x37,0x38,0x20,0x3d,0x20, + 0x31,0x20,0x2b,0x20,0x73,0x69,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x32,0x38,0x34,0x20,0x3d,0x20,0x73,0x69,0x64, + 0x65,0x20,0x2b,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x65, + 0x64,0x67,0x65,0x73,0x4e,0x5b,0x5f,0x32,0x37,0x38,0x5d,0x5b,0x31,0x5d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x65, + 0x64,0x67,0x65,0x73,0x43,0x5f,0x4c,0x52,0x54,0x42,0x20,0x3d,0x20,0x58,0x65,0x47, + 0x54,0x41,0x4f,0x5f,0x55,0x6e,0x70,0x61,0x63,0x6b,0x45,0x64,0x67,0x65,0x73,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20, + 0x3d,0x20,0x65,0x64,0x67,0x65,0x73,0x4e,0x5b,0x73,0x69,0x64,0x65,0x5d,0x5b,0x31, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x5f,0x32,0x39,0x36,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f, + 0x55,0x6e,0x70,0x61,0x63,0x6b,0x45,0x64,0x67,0x65,0x73,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x65,0x64, + 0x67,0x65,0x73,0x4e,0x5b,0x5f,0x32,0x38,0x34,0x5d,0x5b,0x31,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x33, + 0x30,0x32,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x55,0x6e,0x70,0x61, + 0x63,0x6b,0x45,0x64,0x67,0x65,0x73,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x65,0x64,0x67,0x65,0x73,0x4e, + 0x5b,0x5f,0x32,0x37,0x38,0x5d,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x33,0x30,0x38,0x20,0x3d, + 0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x55,0x6e,0x70,0x61,0x63,0x6b,0x45,0x64, + 0x67,0x65,0x73,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x36,0x20,0x3d,0x20,0x65,0x64,0x67,0x65,0x73,0x4e,0x5b,0x5f,0x32,0x37, + 0x38,0x5d,0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x33,0x31,0x34,0x20,0x3d,0x20,0x58,0x65,0x47, + 0x54,0x41,0x4f,0x5f,0x55,0x6e,0x70,0x61,0x63,0x6b,0x45,0x64,0x67,0x65,0x73,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x33,0x32,0x34,0x20,0x3d,0x20, + 0x65,0x64,0x67,0x65,0x73,0x43,0x5f,0x4c,0x52,0x54,0x42,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x33,0x32,0x35, + 0x20,0x3d,0x20,0x5f,0x33,0x32,0x34,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x28,0x5f,0x32,0x39,0x36,0x2e,0x79,0x2c,0x20,0x5f,0x33,0x30,0x32,0x2e,0x78,0x2c, + 0x20,0x5f,0x33,0x30,0x38,0x2e,0x77,0x2c,0x20,0x5f,0x33,0x31,0x34,0x2e,0x7a,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x5f,0x33,0x34,0x31,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c, + 0x61,0x6d,0x70,0x28,0x5f,0x33,0x32,0x35,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x31,0x2e, + 0x35,0x20,0x2d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x33,0x32,0x35,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x31,0x2e,0x30,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x2c, + 0x20,0x31,0x2e,0x30,0x29,0x20,0x2a,0x20,0x30,0x2e,0x33,0x33,0x33,0x33,0x33,0x33, + 0x33,0x34,0x33,0x32,0x36,0x37,0x34,0x34,0x30,0x37,0x39,0x35,0x38,0x39,0x38,0x34, + 0x33,0x37,0x35,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x30,0x2e,0x30, + 0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x31,0x2e,0x30,0x29,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x64,0x67,0x65,0x73,0x43,0x5f, + 0x4c,0x52,0x54,0x42,0x20,0x3d,0x20,0x5f,0x33,0x34,0x31,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x33,0x34,0x35,0x20, + 0x3d,0x20,0x5f,0x33,0x34,0x31,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x33,0x35,0x30,0x20,0x3d,0x20,0x5f, + 0x33,0x34,0x31,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x33,0x36,0x33,0x20,0x3d,0x20,0x5f,0x33,0x34,0x31, + 0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x33,0x37,0x31,0x20,0x3d,0x20,0x5f,0x33,0x34,0x31,0x2e,0x77,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x61,0x6f,0x5b,0x73,0x69,0x64,0x65, + 0x5d,0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x5f,0x33, + 0x34,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x61,0x6f,0x5b,0x5f, + 0x32,0x37,0x38,0x5d,0x5b,0x31,0x5d,0x20,0x2a,0x20,0x5f,0x31,0x39,0x36,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x5f,0x31,0x39,0x36,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x41,0x64, + 0x64,0x53,0x61,0x6d,0x70,0x6c,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x61,0x6f,0x5b,0x5f,0x32,0x38,0x34,0x5d,0x5b, + 0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x65,0x64,0x67, + 0x65,0x73,0x43,0x5f,0x4c,0x52,0x54,0x42,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x33,0x20,0x3d,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f, + 0x41,0x64,0x64,0x53,0x61,0x6d,0x70,0x6c,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x61,0x6f,0x5b,0x5f, + 0x32,0x37,0x38,0x5d,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20, + 0x3d,0x20,0x65,0x64,0x67,0x65,0x73,0x43,0x5f,0x4c,0x52,0x54,0x42,0x2e,0x7a,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x20,0x3d,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x58, + 0x65,0x47,0x54,0x41,0x4f,0x5f,0x41,0x64,0x64,0x53,0x61,0x6d,0x70,0x6c,0x65,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x20, + 0x3d,0x20,0x61,0x6f,0x5b,0x5f,0x32,0x37,0x38,0x5d,0x5b,0x32,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x30,0x20,0x3d,0x20,0x65,0x64,0x67,0x65,0x73,0x43,0x5f,0x4c, + 0x52,0x54,0x42,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x20,0x3d,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32, + 0x20,0x3d,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x41,0x64,0x64,0x53, + 0x61,0x6d,0x70,0x6c,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x33,0x20,0x3d,0x20,0x61,0x6f,0x5b,0x73,0x69,0x64,0x65,0x5d, + 0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x20,0x3d,0x20,0x30,0x2e, + 0x34,0x32,0x35,0x30,0x30,0x30,0x30,0x31,0x31,0x39,0x32,0x30,0x39,0x32,0x38,0x39, + 0x35,0x35,0x30,0x37,0x38,0x31,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x5f,0x33,0x34, + 0x35,0x20,0x2a,0x20,0x5f,0x32,0x39,0x36,0x2e,0x7a,0x29,0x20,0x2b,0x20,0x28,0x5f, + 0x33,0x35,0x30,0x20,0x2a,0x20,0x5f,0x33,0x30,0x38,0x2e,0x78,0x29,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x35,0x20,0x3d,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x36,0x20,0x3d,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x58,0x65, + 0x47,0x54,0x41,0x4f,0x5f,0x41,0x64,0x64,0x53,0x61,0x6d,0x70,0x6c,0x65,0x28,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x35,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37,0x20,0x3d, + 0x20,0x61,0x6f,0x5b,0x5f,0x32,0x38,0x34,0x5d,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x38,0x20,0x3d,0x20,0x30,0x2e,0x34,0x32,0x35,0x30,0x30,0x30,0x30, + 0x31,0x31,0x39,0x32,0x30,0x39,0x32,0x38,0x39,0x35,0x35,0x30,0x37,0x38,0x31,0x32, + 0x35,0x20,0x2a,0x20,0x28,0x28,0x5f,0x33,0x35,0x30,0x20,0x2a,0x20,0x5f,0x33,0x30, + 0x38,0x2e,0x79,0x29,0x20,0x2b,0x20,0x28,0x5f,0x33,0x36,0x33,0x20,0x2a,0x20,0x5f, + 0x33,0x30,0x32,0x2e,0x7a,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x39,0x20, + 0x3d,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x30,0x20,0x3d,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x36,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x41,0x64, + 0x64,0x53,0x61,0x6d,0x70,0x6c,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x38,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x33,0x31,0x20,0x3d,0x20,0x61,0x6f,0x5b,0x73,0x69,0x64, + 0x65,0x5d,0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x32,0x20,0x3d,0x20, + 0x30,0x2e,0x34,0x32,0x35,0x30,0x30,0x30,0x30,0x31,0x31,0x39,0x32,0x30,0x39,0x32, + 0x38,0x39,0x35,0x35,0x30,0x37,0x38,0x31,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x5f, + 0x33,0x37,0x31,0x20,0x2a,0x20,0x5f,0x33,0x31,0x34,0x2e,0x78,0x29,0x20,0x2b,0x20, + 0x28,0x5f,0x33,0x34,0x35,0x20,0x2a,0x20,0x5f,0x32,0x39,0x36,0x2e,0x77,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x33,0x20,0x3d,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x20,0x3d,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x41,0x64,0x64,0x53,0x61,0x6d,0x70,0x6c,0x65, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x33,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x33,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x35, + 0x20,0x3d,0x20,0x61,0x6f,0x5b,0x5f,0x32,0x38,0x34,0x5d,0x5b,0x32,0x5d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x36,0x20,0x3d,0x20,0x30,0x2e,0x34,0x32,0x35,0x30,0x30, + 0x30,0x30,0x31,0x31,0x39,0x32,0x30,0x39,0x32,0x38,0x39,0x35,0x35,0x30,0x37,0x38, + 0x31,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x5f,0x33,0x36,0x33,0x20,0x2a,0x20,0x5f, + 0x33,0x30,0x32,0x2e,0x77,0x29,0x20,0x2b,0x20,0x28,0x5f,0x33,0x37,0x31,0x20,0x2a, + 0x20,0x5f,0x33,0x31,0x34,0x2e,0x79,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, + 0x37,0x20,0x3d,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x33,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x33,0x38,0x20,0x3d,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f, + 0x41,0x64,0x64,0x53,0x61,0x6d,0x70,0x6c,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x36,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x38, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x39,0x20,0x3d,0x20,0x5f,0x32,0x36,0x37,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x34,0x30,0x20,0x3d,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x37,0x20,0x2f,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x38,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x34,0x31,0x20,0x3d,0x20,0x5f,0x31,0x39,0x33,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x4f,0x75,0x74,0x70, + 0x75,0x74,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x39,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x34,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x31,0x2c, + 0x20,0x6f,0x75,0x74,0x5f,0x61,0x6f,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x7d,0x0a,0x0a,0x00, +}; +static inline const sg_shader_desc* gtao_denoise_prog_shader_desc(sg_backend backend) { + if (backend == SG_BACKEND_GLCORE) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.compute_func.source = (const char*)gtao_denoise_cs_source_glsl430; + desc.compute_func.entry = "main"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_COMPUTE; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 16; + desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_INT2; + desc.uniform_blocks[0].glsl_uniforms[0].array_count = 0; + desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "gtao.ViewportSize"; + desc.uniform_blocks[0].glsl_uniforms[1].type = SG_UNIFORMTYPE_FLOAT; + desc.uniform_blocks[0].glsl_uniforms[1].array_count = 0; + desc.uniform_blocks[0].glsl_uniforms[1].glsl_name = "gtao.DenoiseBlurBeta"; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_COMPUTE; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 16; + desc.uniform_blocks[1].glsl_uniforms[0].type = SG_UNIFORMTYPE_INT4; + desc.uniform_blocks[1].glsl_uniforms[0].array_count = 1; + desc.uniform_blocks[1].glsl_uniforms[0].glsl_name = "ub_denoise"; + desc.views[0].storage_image.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[0].storage_image.image_type = SG_IMAGETYPE_2D; + desc.views[0].storage_image.access_format = SG_PIXELFORMAT_R32F; + desc.views[0].storage_image.writeonly = true; + desc.views[0].storage_image.glsl_binding_n = 0; + desc.views[1].texture.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[1].texture.image_type = SG_IMAGETYPE_2D; + desc.views[1].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[1].texture.multisampled = false; + desc.views[2].texture.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[2].texture.image_type = SG_IMAGETYPE_2D; + desc.views[2].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[2].texture.multisampled = false; + desc.samplers[0].stage = SG_SHADERSTAGE_COMPUTE; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_COMPUTE; + desc.texture_sampler_pairs[0].view_slot = 1; + desc.texture_sampler_pairs[0].sampler_slot = 0; + desc.texture_sampler_pairs[0].glsl_name = "tex_edges_smp_point_clamp"; + desc.texture_sampler_pairs[1].stage = SG_SHADERSTAGE_COMPUTE; + desc.texture_sampler_pairs[1].view_slot = 2; + desc.texture_sampler_pairs[1].sampler_slot = 0; + desc.texture_sampler_pairs[1].glsl_name = "tex_noisy_ao_smp_point_clamp"; + desc.label = "gtao_denoise_prog_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_D3D11) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.compute_func.source = (const char*)gtao_denoise_cs_source_hlsl5; + desc.compute_func.d3d11_target = "cs_5_0"; + desc.compute_func.entry = "main"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_COMPUTE; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 16; + desc.uniform_blocks[0].hlsl_register_b_n = 0; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_COMPUTE; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 16; + desc.uniform_blocks[1].hlsl_register_b_n = 1; + desc.views[0].storage_image.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[0].storage_image.image_type = SG_IMAGETYPE_2D; + desc.views[0].storage_image.access_format = SG_PIXELFORMAT_R32F; + desc.views[0].storage_image.writeonly = true; + desc.views[0].storage_image.hlsl_register_u_n = 0; + desc.views[1].texture.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[1].texture.image_type = SG_IMAGETYPE_2D; + desc.views[1].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[1].texture.multisampled = false; + desc.views[1].texture.hlsl_register_t_n = 0; + desc.views[2].texture.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[2].texture.image_type = SG_IMAGETYPE_2D; + desc.views[2].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[2].texture.multisampled = false; + desc.views[2].texture.hlsl_register_t_n = 1; + desc.samplers[0].stage = SG_SHADERSTAGE_COMPUTE; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[0].hlsl_register_s_n = 0; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_COMPUTE; + desc.texture_sampler_pairs[0].view_slot = 1; + desc.texture_sampler_pairs[0].sampler_slot = 0; + desc.texture_sampler_pairs[1].stage = SG_SHADERSTAGE_COMPUTE; + desc.texture_sampler_pairs[1].view_slot = 2; + desc.texture_sampler_pairs[1].sampler_slot = 0; + desc.label = "gtao_denoise_prog_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_METAL_MACOS) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.compute_func.source = (const char*)gtao_denoise_cs_source_metal_macos; + desc.compute_func.entry = "main0"; + desc.mtl_threads_per_threadgroup.x = 8; + desc.mtl_threads_per_threadgroup.y = 8; + desc.mtl_threads_per_threadgroup.z = 1; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_COMPUTE; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 16; + desc.uniform_blocks[0].msl_buffer_n = 0; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_COMPUTE; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 16; + desc.uniform_blocks[1].msl_buffer_n = 1; + desc.views[0].storage_image.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[0].storage_image.image_type = SG_IMAGETYPE_2D; + desc.views[0].storage_image.access_format = SG_PIXELFORMAT_R32F; + desc.views[0].storage_image.writeonly = true; + desc.views[0].storage_image.msl_texture_n = 0; + desc.views[1].texture.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[1].texture.image_type = SG_IMAGETYPE_2D; + desc.views[1].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[1].texture.multisampled = false; + desc.views[1].texture.msl_texture_n = 1; + desc.views[2].texture.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[2].texture.image_type = SG_IMAGETYPE_2D; + desc.views[2].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[2].texture.multisampled = false; + desc.views[2].texture.msl_texture_n = 2; + desc.samplers[0].stage = SG_SHADERSTAGE_COMPUTE; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[0].msl_sampler_n = 0; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_COMPUTE; + desc.texture_sampler_pairs[0].view_slot = 1; + desc.texture_sampler_pairs[0].sampler_slot = 0; + desc.texture_sampler_pairs[1].stage = SG_SHADERSTAGE_COMPUTE; + desc.texture_sampler_pairs[1].view_slot = 2; + desc.texture_sampler_pairs[1].sampler_slot = 0; + desc.label = "gtao_denoise_prog_shader"; + } + return &desc; + } + return 0; +} diff --git a/samples/shaders/generated/gtao_main_pass.glsl.h b/samples/shaders/generated/gtao_main_pass.glsl.h new file mode 100644 index 0000000..10ef62b --- /dev/null +++ b/samples/shaders/generated/gtao_main_pass.glsl.h @@ -0,0 +1,3911 @@ +#pragma once +/* + #version:1# (machine generated, don't edit!) + + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) + + Cmdline: + sokol-shdc --input E:/box/box3d/samples/shaders/post/gtao_main_pass.glsl --output E:/box/box3d/samples/shaders/generated/gtao_main_pass.glsl.h --slang hlsl5:metal_macos:glsl430 + + Overview: + ========= + Shader program: 'prog': + Get shader desc: gtao_main_pass_prog_shader_desc(sg_query_backend()); + Compute Shader: cs + Bindings: + Uniform block 'ub_gtao': + C struct: gtao_main_pass_ub_gtao_t + Bind slot: UB_gtao_main_pass_ub_gtao => 0 + Storage image 'out_noisy_ao': + Bind slot: VIEW_gtao_main_pass_out_noisy_ao => 0 + Image type: SG_IMAGETYPE_2D + Access format: SG_PIXELFORMAT_R32F + Writeonly: true + Storage image 'out_edges': + Bind slot: VIEW_gtao_main_pass_out_edges => 1 + Image type: SG_IMAGETYPE_2D + Access format: SG_PIXELFORMAT_R32F + Writeonly: true + Texture 'tex_raw_depth': + Image type: SG_IMAGETYPE_2D + Sample type: SG_IMAGESAMPLETYPE_FLOAT + Multisampled: false + Bind slot: VIEW_gtao_main_pass_tex_raw_depth => 2 + Texture 'tex_prefilter_depth': + Image type: SG_IMAGETYPE_2D + Sample type: SG_IMAGESAMPLETYPE_FLOAT + Multisampled: false + Bind slot: VIEW_gtao_main_pass_tex_prefilter_depth => 3 + Sampler 'smp_point_clamp': + Type: SG_SAMPLERTYPE_FILTERING + Bind slot: SMP_gtao_main_pass_smp_point_clamp => 0 +*/ +#if !defined(SOKOL_GFX_INCLUDED) +#error "Please include sokol_gfx.h before gtao_main_pass.glsl.h" +#endif +#if !defined(SOKOL_SHDC_ALIGN) +#if defined(_MSC_VER) +#define SOKOL_SHDC_ALIGN(a) __declspec(align(a)) +#else +#define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) +#endif +#endif +#define UB_gtao_main_pass_ub_gtao (0) +#define VIEW_gtao_main_pass_out_noisy_ao (0) +#define VIEW_gtao_main_pass_out_edges (1) +#define VIEW_gtao_main_pass_tex_raw_depth (2) +#define VIEW_gtao_main_pass_tex_prefilter_depth (3) +#define SMP_gtao_main_pass_smp_point_clamp (0) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct gtao_main_pass_ub_gtao_t { + int ViewportSize[2]; + b3Vec2 ViewportPixelSize; + b3Vec2 NDCToViewMul; + b3Vec2 NDCToViewAdd; + b3Vec2 NDCToViewMul_x_PixelSize; + float EffectRadius; + float EffectFalloffRange; + float RadiusMultiplier; + float FinalValuePower; + float SampleDistributionPower; + float ThinOccluderCompensation; + float DepthMIPSamplingOffset; + float SliceCount; + float StepsPerSlice; + uint8_t _pad_76[4]; +} gtao_main_pass_ub_gtao_t; +#pragma pack(pop) +/* + #version 430 + layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; + + struct GTAOConsts + { + vec2 ViewportPixelSize; + vec2 NDCToViewMul; + vec2 NDCToViewAdd; + vec2 NDCToViewMul_x_PixelSize; + float EffectRadius; + float EffectFalloffRange; + float RadiusMultiplier; + float FinalValuePower; + float SampleDistributionPower; + float ThinOccluderCompensation; + float DepthMIPSamplingOffset; + float SliceCount; + float StepsPerSlice; + }; + + struct ub_gtao + { + ivec2 ViewportSize; + vec2 ViewportPixelSize; + vec2 NDCToViewMul; + vec2 NDCToViewAdd; + vec2 NDCToViewMul_x_PixelSize; + float EffectRadius; + float EffectFalloffRange; + float RadiusMultiplier; + float FinalValuePower; + float SampleDistributionPower; + float ThinOccluderCompensation; + float DepthMIPSamplingOffset; + float SliceCount; + float StepsPerSlice; + }; + + uniform ub_gtao gtao; + + layout(binding = 0, r32f) uniform writeonly image2D out_noisy_ao; + layout(binding = 1, r32f) uniform writeonly image2D out_edges; + layout(binding = 0) uniform sampler2D tex_raw_depth_smp_point_clamp; + layout(binding = 1) uniform sampler2D tex_prefilter_depth_smp_point_clamp; + + float XeGTAO_ScreenSpaceToViewSpaceDepth(float screenDepth, GTAOConsts consts) + { + return screenDepth; + } + + vec4 XeGTAO_CalculateEdges(float centerZ, float leftZ, float rightZ, float topZ, float bottomZ) + { + vec4 _167 = vec4(leftZ, rightZ, topZ, bottomZ) - vec4(centerZ); + float _173 = _167.y - _167.x; + float _182 = _167.w - _167.z; + return clamp(vec4(1.25) - (min(abs(_167), abs(_167 + vec4(_173 * 0.5, _173 * (-0.5), _182 * 0.5, _182 * (-0.5)))) / vec4(centerZ * 0.010999999940395355224609375)), vec4(0.0), vec4(1.0)); + } + + vec3 XeGTAO_ComputeViewspacePosition(vec2 screenPos, float viewspaceDepth, GTAOConsts consts) + { + return vec3(((consts.NDCToViewMul * screenPos) + consts.NDCToViewAdd) * viewspaceDepth, -viewspaceDepth); + } + + vec3 XeGTAO_CalculateNormal(vec4 edgesLRTB, vec3 pixCenterPos, inout vec3 pixLPos, inout vec3 pixRPos, inout vec3 pixTPos, inout vec3 pixBPos) + { + vec4 _256 = clamp(vec4(edgesLRTB.x * edgesLRTB.z, edgesLRTB.z * edgesLRTB.y, edgesLRTB.y * edgesLRTB.w, edgesLRTB.w * edgesLRTB.x) + vec4(0.00999999977648258209228515625), vec4(0.0), vec4(1.0)); + pixLPos = normalize(pixLPos - pixCenterPos); + pixRPos = normalize(pixRPos - pixCenterPos); + pixTPos = normalize(pixTPos - pixCenterPos); + pixBPos = normalize(pixBPos - pixCenterPos); + return normalize((((cross(pixTPos, pixLPos) * _256.x) + (cross(pixRPos, pixTPos) * _256.y)) + (cross(pixBPos, pixRPos) * _256.z)) + (cross(pixLPos, pixBPos) * _256.w)); + } + + vec3 XeGTAO_ComputeViewspaceNormal(ivec2 pixCoord, GTAOConsts consts) + { + vec2 _394 = (vec2(pixCoord) + vec2(0.5)) * consts.ViewportPixelSize; + ivec2 _403 = gtao.ViewportSize - ivec2(1); + float param = texelFetch(tex_raw_depth_smp_point_clamp, clamp(pixCoord, ivec2(0), _403), 0).x; + GTAOConsts param_1 = consts; + float _452 = XeGTAO_ScreenSpaceToViewSpaceDepth(param, param_1); + float param_2 = texelFetch(tex_raw_depth_smp_point_clamp, clamp(pixCoord + ivec2(-1, 0), ivec2(0), _403), 0).x; + GTAOConsts param_3 = consts; + float _464 = XeGTAO_ScreenSpaceToViewSpaceDepth(param_2, param_3); + float param_4 = texelFetch(tex_raw_depth_smp_point_clamp, clamp(pixCoord + ivec2(1, 0), ivec2(0), _403), 0).x; + GTAOConsts param_5 = consts; + float _476 = XeGTAO_ScreenSpaceToViewSpaceDepth(param_4, param_5); + float param_6 = texelFetch(tex_raw_depth_smp_point_clamp, clamp(pixCoord + ivec2(0, -1), ivec2(0), _403), 0).x; + GTAOConsts param_7 = consts; + float _488 = XeGTAO_ScreenSpaceToViewSpaceDepth(param_6, param_7); + float param_8 = texelFetch(tex_raw_depth_smp_point_clamp, clamp(pixCoord + ivec2(0, 1), ivec2(0), _403), 0).x; + GTAOConsts param_9 = consts; + float _500 = XeGTAO_ScreenSpaceToViewSpaceDepth(param_8, param_9); + float param_10 = _452; + float param_11 = _464; + float param_12 = _476; + float param_13 = _488; + float param_14 = _500; + vec2 param_15 = _394; + float param_16 = _452; + GTAOConsts param_17 = consts; + vec2 param_18 = _394 + (vec2(-1.0, 0.0) * consts.ViewportPixelSize); + float param_19 = _464; + GTAOConsts param_20 = consts; + vec2 param_21 = _394 + (vec2(1.0, 0.0) * consts.ViewportPixelSize); + float param_22 = _476; + GTAOConsts param_23 = consts; + vec2 param_24 = _394 + (vec2(0.0, -1.0) * consts.ViewportPixelSize); + float param_25 = _488; + GTAOConsts param_26 = consts; + vec2 param_27 = _394 + (vec2(0.0, 1.0) * consts.ViewportPixelSize); + float param_28 = _500; + GTAOConsts param_29 = consts; + vec4 param_30 = XeGTAO_CalculateEdges(param_10, param_11, param_12, param_13, param_14); + vec3 param_31 = XeGTAO_ComputeViewspacePosition(param_15, param_16, param_17); + vec3 param_32 = XeGTAO_ComputeViewspacePosition(param_18, param_19, param_20); + vec3 param_33 = XeGTAO_ComputeViewspacePosition(param_21, param_22, param_23); + vec3 param_34 = XeGTAO_ComputeViewspacePosition(param_24, param_25, param_26); + vec3 param_35 = XeGTAO_ComputeViewspacePosition(param_27, param_28, param_29); + vec3 _586 = XeGTAO_CalculateNormal(param_30, param_31, param_32, param_33, param_34, param_35); + return _586; + } + + uint HilbertIndex(inout uint posX, inout uint posY) + { + uint index = 0u; + for (uint curLevel = 32u; curLevel > 0u; curLevel /= 2u) + { + uint _320 = uint((posX & curLevel) > 0u); + uint _326 = uint((posY & curLevel) > 0u); + index += ((curLevel * curLevel) * ((3u * _320) ^ _326)); + if (_326 == 0u) + { + if (_320 == 1u) + { + posX = 63u - posX; + posY = 63u - posY; + } + uint _351 = posX; + posX = posY; + posY = _351; + } + } + return index; + } + + vec2 SpatioTemporalNoise(uvec2 pixCoord, int temporalIndex) + { + uint param = pixCoord.x; + uint param_1 = pixCoord.y; + uint _366 = HilbertIndex(param, param_1); + return fract(vec2(0.5) + (vec2(0.75487768650054931640625, 0.56984031200408935546875) * float(_366 + (288u * (uint(temporalIndex) % 64u))))); + } + + float XeGTAO_PackEdges(inout vec4 edgesLRTB) + { + edgesLRTB = round(clamp(edgesLRTB, vec4(0.0), vec4(1.0)) * 2.900000095367431640625); + return dot(edgesLRTB, vec4(0.2509804069995880126953125, 0.062745101749897003173828125, 0.01568627543747425079345703125, 0.0039215688593685626983642578125)); + } + + float XeGTAO_FastSqrt(float x) + { + return intBitsToFloat(532487669 + (floatBitsToInt(x) >> 1)); + } + + float XeGTAO_FastACos(float inX) + { + float _103 = abs(inX); + float res = ((-0.15658299624919891357421875) * _103) + 1.57079637050628662109375; + float param = 1.0 - _103; + res *= XeGTAO_FastSqrt(param); + float _121; + if (inX >= 0.0) + { + _121 = res; + } + else + { + _121 = 3.1415927410125732421875 - res; + } + return _121; + } + + float XeGTAO_OutputWorkingTerm(ivec2 pixCoord, inout float visibility) + { + visibility = clamp(visibility * 0.666666686534881591796875, 0.0, 1.0); + imageStore(out_noisy_ao, pixCoord, vec4(visibility, 0.0, 0.0, 0.0)); + return visibility; + } + + float XeGTAO_MainPass(ivec2 pixCoord, vec2 localNoise, vec3 viewspaceNormal, float centerViewspaceZ, vec4 edgesLRTB, GTAOConsts consts) + { + vec2 _610 = (vec2(pixCoord) + vec2(0.5)) * consts.ViewportPixelSize; + float viewspaceZ = centerViewspaceZ; + vec4 param = edgesLRTB; + float _618 = XeGTAO_PackEdges(param); + imageStore(out_edges, pixCoord, vec4(_618, 0.0, 0.0, 0.0)); + float _621 = viewspaceZ; + float _622 = _621 * 0.999989986419677734375; + viewspaceZ = _622; + vec2 param_1 = _610; + float param_2 = _622; + GTAOConsts param_3 = consts; + vec3 _630 = XeGTAO_ComputeViewspacePosition(param_1, param_2, param_3); + vec3 _634 = normalize(-_630); + float _650 = consts.EffectRadius * consts.RadiusMultiplier; + float _656 = consts.EffectFalloffRange * _650; + float _665 = (-1.0) / _656; + float _670 = ((_650 * (1.0 - consts.EffectFalloffRange)) / _656) + 1.0; + float _697 = _650 / (vec2(viewspaceZ) * consts.NDCToViewMul_x_PixelSize).x; + float visibility = clamp((10.0 - _697) * 0.00999999977648258209228515625, 0.0, 1.0) * 0.5; + float _710 = 1.2999999523162841796875 / _697; + for (float slice = 0.0; slice < consts.SliceCount; slice += 1.0) + { + float _728 = ((slice + localNoise.x) / consts.SliceCount) * 3.1415927410125732421875; + float _731 = cos(_728); + float _734 = sin(_728); + vec2 _742 = vec2(_731, -_734) * _697; + vec3 _746 = vec3(_731, _734, 0.0); + vec3 _754 = _746 - (_634 * dot(_746, _634)); + vec3 _759 = normalize(cross(_754, _634)); + vec3 _767 = viewspaceNormal - (_759 * dot(viewspaceNormal, _759)); + float _775 = length(_767); + float projectedNormalVecLength = _775; + float _782 = clamp(dot(_767, _634) / _775, 0.0, 1.0); + float param_4 = _782; + float _788 = sign(dot(_754, _767)) * XeGTAO_FastACos(param_4); + float _792 = cos(_788 + 1.57079637050628662109375); + float _796 = cos(_788 - 1.57079637050628662109375); + float horizonCos0 = _792; + float horizonCos1 = _796; + for (float step_ = 0.0; step_ < consts.StepsPerSlice; step_ += 1.0) + { + vec2 _839 = _742 * (pow(max(0.0, (step_ + fract(localNoise.y + ((slice + (step_ * consts.StepsPerSlice)) * 0.61803400516510009765625))) / consts.StepsPerSlice), consts.SampleDistributionPower) + _710); + float _851 = clamp(log2(length(_839)) - consts.DepthMIPSamplingOffset, 0.0, 5.0); + vec2 _856 = round(_839) * consts.ViewportPixelSize; + vec2 _860 = _610 + _856; + vec2 param_5 = _860; + float param_6 = textureLod(tex_prefilter_depth_smp_point_clamp, _860, _851).x; + GTAOConsts param_7 = consts; + vec2 _881 = _610 - _856; + vec2 param_8 = _881; + float param_9 = textureLod(tex_prefilter_depth_smp_point_clamp, _881, _851).x; + GTAOConsts param_10 = consts; + vec3 _901 = XeGTAO_ComputeViewspacePosition(param_5, param_6, param_7) - _630; + vec3 _905 = XeGTAO_ComputeViewspacePosition(param_8, param_9, param_10) - _630; + float _930 = 1.0 + consts.ThinOccluderCompensation; + horizonCos0 = max(horizonCos0, mix(_792, dot(_901 / vec3(length(_901)), _634), clamp((length(vec3(_901.xy, _901.z * _930)) * _665) + _670, 0.0, 1.0))); + horizonCos1 = max(horizonCos1, mix(_796, dot(_905 / vec3(length(_905)), _634), clamp((length(vec3(_905.xy, _905.z * _930)) * _665) + _670, 0.0, 1.0))); + } + projectedNormalVecLength = mix(projectedNormalVecLength, 1.0, 0.0500000007450580596923828125); + float param_11 = horizonCos1; + float param_12 = horizonCos0; + float _1000 = XeGTAO_FastACos(param_11) * (-2.0); + float _1002 = sin(_788); + float _1016 = 2.0 * XeGTAO_FastACos(param_12); + visibility += (projectedNormalVecLength * (0.25 * (((_782 + (_1000 * _1002)) - cos(_1000 - _788)) + ((_782 + (_1016 * _1002)) - cos(_1016 - _788))))); + } + float _1040 = visibility; + float _1050 = max(0.02999999932944774627685546875, pow(max(0.0, _1040 / consts.SliceCount), consts.FinalValuePower)); + visibility = _1050; + ivec2 param_13 = pixCoord; + float param_14 = _1050; + float _1055 = XeGTAO_OutputWorkingTerm(param_13, param_14); + return _1055; + } + + void main() + { + ivec2 _1064 = ivec2(gl_GlobalInvocationID.xy); + if (any(greaterThanEqual(_1064, gtao.ViewportSize))) + { + return; + } + ivec2 param = _1064; + GTAOConsts _1261 = GTAOConsts(gtao.ViewportPixelSize, gtao.NDCToViewMul, gtao.NDCToViewAdd, gtao.NDCToViewMul_x_PixelSize, gtao.EffectRadius, gtao.EffectFalloffRange, gtao.RadiusMultiplier, gtao.FinalValuePower, gtao.SampleDistributionPower, gtao.ThinOccluderCompensation, gtao.DepthMIPSamplingOffset, gtao.SliceCount, gtao.StepsPerSlice); + GTAOConsts param_1 = _1261; + ivec2 _1127 = gtao.ViewportSize - ivec2(1); + float param_2 = texelFetch(tex_raw_depth_smp_point_clamp, clamp(_1064, ivec2(0), _1127), 0).x; + GTAOConsts param_3 = _1261; + float _1141 = XeGTAO_ScreenSpaceToViewSpaceDepth(param_2, param_3); + float param_4 = texelFetch(tex_raw_depth_smp_point_clamp, clamp(_1064 + ivec2(-1, 0), ivec2(0), _1127), 0).x; + GTAOConsts param_5 = _1261; + float param_6 = texelFetch(tex_raw_depth_smp_point_clamp, clamp(_1064 + ivec2(1, 0), ivec2(0), _1127), 0).x; + GTAOConsts param_7 = _1261; + float param_8 = texelFetch(tex_raw_depth_smp_point_clamp, clamp(_1064 + ivec2(0, -1), ivec2(0), _1127), 0).x; + GTAOConsts param_9 = _1261; + float param_10 = texelFetch(tex_raw_depth_smp_point_clamp, clamp(_1064 + ivec2(0, 1), ivec2(0), _1127), 0).x; + GTAOConsts param_11 = _1261; + float param_12 = _1141; + float param_13 = XeGTAO_ScreenSpaceToViewSpaceDepth(param_4, param_5); + float param_14 = XeGTAO_ScreenSpaceToViewSpaceDepth(param_6, param_7); + float param_15 = XeGTAO_ScreenSpaceToViewSpaceDepth(param_8, param_9); + float param_16 = XeGTAO_ScreenSpaceToViewSpaceDepth(param_10, param_11); + uvec2 param_17 = uvec2(_1064); + int param_18 = 0; + ivec2 param_19 = _1064; + vec2 param_20 = SpatioTemporalNoise(param_17, param_18); + vec3 param_21 = XeGTAO_ComputeViewspaceNormal(param, param_1); + float param_22 = _1141; + vec4 param_23 = XeGTAO_CalculateEdges(param_12, param_13, param_14, param_15, param_16); + GTAOConsts param_24 = _1261; + float _1232 = XeGTAO_MainPass(param_19, param_20, param_21, param_22, param_23, param_24); + } + +*/ +static const uint8_t gtao_main_pass_cs_source_glsl430[13720] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x6c,0x61,0x79, + 0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x6c,0x5f,0x73,0x69,0x7a,0x65,0x5f,0x78, + 0x20,0x3d,0x20,0x38,0x2c,0x20,0x6c,0x6f,0x63,0x61,0x6c,0x5f,0x73,0x69,0x7a,0x65, + 0x5f,0x79,0x20,0x3d,0x20,0x38,0x2c,0x20,0x6c,0x6f,0x63,0x61,0x6c,0x5f,0x73,0x69, + 0x7a,0x65,0x5f,0x7a,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x3b,0x0a,0x0a,0x73, + 0x74,0x72,0x75,0x63,0x74,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x56,0x69,0x65,0x77, + 0x70,0x6f,0x72,0x74,0x50,0x69,0x78,0x65,0x6c,0x53,0x69,0x7a,0x65,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x4e,0x44,0x43,0x54,0x6f,0x56,0x69,0x65, + 0x77,0x4d,0x75,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x4e, + 0x44,0x43,0x54,0x6f,0x56,0x69,0x65,0x77,0x41,0x64,0x64,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x32,0x20,0x4e,0x44,0x43,0x54,0x6f,0x56,0x69,0x65,0x77,0x4d, + 0x75,0x6c,0x5f,0x78,0x5f,0x50,0x69,0x78,0x65,0x6c,0x53,0x69,0x7a,0x65,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x45,0x66,0x66,0x65,0x63,0x74, + 0x52,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x45,0x66,0x66,0x65,0x63,0x74,0x46,0x61,0x6c,0x6c,0x6f,0x66,0x66,0x52, + 0x61,0x6e,0x67,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x52,0x61,0x64,0x69,0x75,0x73,0x4d,0x75,0x6c,0x74,0x69,0x70,0x6c,0x69,0x65,0x72, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x46,0x69,0x6e,0x61, + 0x6c,0x56,0x61,0x6c,0x75,0x65,0x50,0x6f,0x77,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x44,0x69,0x73, + 0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x50,0x6f,0x77,0x65,0x72,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x54,0x68,0x69,0x6e,0x4f,0x63, + 0x63,0x6c,0x75,0x64,0x65,0x72,0x43,0x6f,0x6d,0x70,0x65,0x6e,0x73,0x61,0x74,0x69, + 0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x44,0x65, + 0x70,0x74,0x68,0x4d,0x49,0x50,0x53,0x61,0x6d,0x70,0x6c,0x69,0x6e,0x67,0x4f,0x66, + 0x66,0x73,0x65,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x53,0x6c,0x69,0x63,0x65,0x43,0x6f,0x75,0x6e,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x53,0x74,0x65,0x70,0x73,0x50,0x65,0x72,0x53,0x6c, + 0x69,0x63,0x65,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20, + 0x75,0x62,0x5f,0x67,0x74,0x61,0x6f,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x76, + 0x65,0x63,0x32,0x20,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x56,0x69,0x65,0x77,0x70, + 0x6f,0x72,0x74,0x50,0x69,0x78,0x65,0x6c,0x53,0x69,0x7a,0x65,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x4e,0x44,0x43,0x54,0x6f,0x56,0x69,0x65,0x77, + 0x4d,0x75,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x4e,0x44, + 0x43,0x54,0x6f,0x56,0x69,0x65,0x77,0x41,0x64,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x65,0x63,0x32,0x20,0x4e,0x44,0x43,0x54,0x6f,0x56,0x69,0x65,0x77,0x4d,0x75, + 0x6c,0x5f,0x78,0x5f,0x50,0x69,0x78,0x65,0x6c,0x53,0x69,0x7a,0x65,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x45,0x66,0x66,0x65,0x63,0x74,0x52, + 0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x45,0x66,0x66,0x65,0x63,0x74,0x46,0x61,0x6c,0x6c,0x6f,0x66,0x66,0x52,0x61, + 0x6e,0x67,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x52, + 0x61,0x64,0x69,0x75,0x73,0x4d,0x75,0x6c,0x74,0x69,0x70,0x6c,0x69,0x65,0x72,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x46,0x69,0x6e,0x61,0x6c, + 0x56,0x61,0x6c,0x75,0x65,0x50,0x6f,0x77,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x44,0x69,0x73,0x74, + 0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x50,0x6f,0x77,0x65,0x72,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x54,0x68,0x69,0x6e,0x4f,0x63,0x63, + 0x6c,0x75,0x64,0x65,0x72,0x43,0x6f,0x6d,0x70,0x65,0x6e,0x73,0x61,0x74,0x69,0x6f, + 0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x44,0x65,0x70, + 0x74,0x68,0x4d,0x49,0x50,0x53,0x61,0x6d,0x70,0x6c,0x69,0x6e,0x67,0x4f,0x66,0x66, + 0x73,0x65,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x53, + 0x6c,0x69,0x63,0x65,0x43,0x6f,0x75,0x6e,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x53,0x74,0x65,0x70,0x73,0x50,0x65,0x72,0x53,0x6c,0x69, + 0x63,0x65,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20, + 0x75,0x62,0x5f,0x67,0x74,0x61,0x6f,0x20,0x67,0x74,0x61,0x6f,0x3b,0x0a,0x0a,0x6c, + 0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20, + 0x30,0x2c,0x20,0x72,0x33,0x32,0x66,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d, + 0x20,0x77,0x72,0x69,0x74,0x65,0x6f,0x6e,0x6c,0x79,0x20,0x69,0x6d,0x61,0x67,0x65, + 0x32,0x44,0x20,0x6f,0x75,0x74,0x5f,0x6e,0x6f,0x69,0x73,0x79,0x5f,0x61,0x6f,0x3b, + 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20, + 0x3d,0x20,0x31,0x2c,0x20,0x72,0x33,0x32,0x66,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f, + 0x72,0x6d,0x20,0x77,0x72,0x69,0x74,0x65,0x6f,0x6e,0x6c,0x79,0x20,0x69,0x6d,0x61, + 0x67,0x65,0x32,0x44,0x20,0x6f,0x75,0x74,0x5f,0x65,0x64,0x67,0x65,0x73,0x3b,0x0a, + 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d, + 0x20,0x30,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x72,0x61,0x77,0x5f,0x64,0x65, + 0x70,0x74,0x68,0x5f,0x73,0x6d,0x70,0x5f,0x70,0x6f,0x69,0x6e,0x74,0x5f,0x63,0x6c, + 0x61,0x6d,0x70,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64, + 0x69,0x6e,0x67,0x20,0x3d,0x20,0x31,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d, + 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x70, + 0x72,0x65,0x66,0x69,0x6c,0x74,0x65,0x72,0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x73, + 0x6d,0x70,0x5f,0x70,0x6f,0x69,0x6e,0x74,0x5f,0x63,0x6c,0x61,0x6d,0x70,0x3b,0x0a, + 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x53,0x63, + 0x72,0x65,0x65,0x6e,0x53,0x70,0x61,0x63,0x65,0x54,0x6f,0x56,0x69,0x65,0x77,0x53, + 0x70,0x61,0x63,0x65,0x44,0x65,0x70,0x74,0x68,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x73,0x63,0x72,0x65,0x65,0x6e,0x44,0x65,0x70,0x74,0x68,0x2c,0x20,0x47,0x54,0x41, + 0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x63,0x72, + 0x65,0x65,0x6e,0x44,0x65,0x70,0x74,0x68,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63, + 0x34,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x61,0x6c,0x63,0x75,0x6c,0x61, + 0x74,0x65,0x45,0x64,0x67,0x65,0x73,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x63,0x65, + 0x6e,0x74,0x65,0x72,0x5a,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6c,0x65,0x66, + 0x74,0x5a,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x69,0x67,0x68,0x74,0x5a, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x74,0x6f,0x70,0x5a,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x62,0x6f,0x74,0x74,0x6f,0x6d,0x5a,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x31,0x36,0x37,0x20,0x3d,0x20,0x76, + 0x65,0x63,0x34,0x28,0x6c,0x65,0x66,0x74,0x5a,0x2c,0x20,0x72,0x69,0x67,0x68,0x74, + 0x5a,0x2c,0x20,0x74,0x6f,0x70,0x5a,0x2c,0x20,0x62,0x6f,0x74,0x74,0x6f,0x6d,0x5a, + 0x29,0x20,0x2d,0x20,0x76,0x65,0x63,0x34,0x28,0x63,0x65,0x6e,0x74,0x65,0x72,0x5a, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x37, + 0x33,0x20,0x3d,0x20,0x5f,0x31,0x36,0x37,0x2e,0x79,0x20,0x2d,0x20,0x5f,0x31,0x36, + 0x37,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x38,0x32,0x20,0x3d,0x20,0x5f,0x31,0x36,0x37,0x2e,0x77,0x20,0x2d,0x20,0x5f, + 0x31,0x36,0x37,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x76,0x65,0x63,0x34,0x28,0x31,0x2e,0x32, + 0x35,0x29,0x20,0x2d,0x20,0x28,0x6d,0x69,0x6e,0x28,0x61,0x62,0x73,0x28,0x5f,0x31, + 0x36,0x37,0x29,0x2c,0x20,0x61,0x62,0x73,0x28,0x5f,0x31,0x36,0x37,0x20,0x2b,0x20, + 0x76,0x65,0x63,0x34,0x28,0x5f,0x31,0x37,0x33,0x20,0x2a,0x20,0x30,0x2e,0x35,0x2c, + 0x20,0x5f,0x31,0x37,0x33,0x20,0x2a,0x20,0x28,0x2d,0x30,0x2e,0x35,0x29,0x2c,0x20, + 0x5f,0x31,0x38,0x32,0x20,0x2a,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x31,0x38,0x32, + 0x20,0x2a,0x20,0x28,0x2d,0x30,0x2e,0x35,0x29,0x29,0x29,0x29,0x20,0x2f,0x20,0x76, + 0x65,0x63,0x34,0x28,0x63,0x65,0x6e,0x74,0x65,0x72,0x5a,0x20,0x2a,0x20,0x30,0x2e, + 0x30,0x31,0x30,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x34,0x30,0x33,0x39,0x35,0x33, + 0x35,0x35,0x32,0x32,0x34,0x36,0x30,0x39,0x33,0x37,0x35,0x29,0x29,0x2c,0x20,0x76, + 0x65,0x63,0x34,0x28,0x30,0x2e,0x30,0x29,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x31, + 0x2e,0x30,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x58,0x65, + 0x47,0x54,0x41,0x4f,0x5f,0x43,0x6f,0x6d,0x70,0x75,0x74,0x65,0x56,0x69,0x65,0x77, + 0x73,0x70,0x61,0x63,0x65,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x28,0x76,0x65, + 0x63,0x32,0x20,0x73,0x63,0x72,0x65,0x65,0x6e,0x50,0x6f,0x73,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x76,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x44,0x65,0x70, + 0x74,0x68,0x2c,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x76,0x65,0x63,0x33,0x28,0x28,0x28,0x63,0x6f,0x6e,0x73,0x74, + 0x73,0x2e,0x4e,0x44,0x43,0x54,0x6f,0x56,0x69,0x65,0x77,0x4d,0x75,0x6c,0x20,0x2a, + 0x20,0x73,0x63,0x72,0x65,0x65,0x6e,0x50,0x6f,0x73,0x29,0x20,0x2b,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x73,0x2e,0x4e,0x44,0x43,0x54,0x6f,0x56,0x69,0x65,0x77,0x41,0x64, + 0x64,0x29,0x20,0x2a,0x20,0x76,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x44,0x65, + 0x70,0x74,0x68,0x2c,0x20,0x2d,0x76,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x44, + 0x65,0x70,0x74,0x68,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x58, + 0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x61,0x6c,0x63,0x75,0x6c,0x61,0x74,0x65,0x4e, + 0x6f,0x72,0x6d,0x61,0x6c,0x28,0x76,0x65,0x63,0x34,0x20,0x65,0x64,0x67,0x65,0x73, + 0x4c,0x52,0x54,0x42,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x69,0x78,0x43,0x65, + 0x6e,0x74,0x65,0x72,0x50,0x6f,0x73,0x2c,0x20,0x69,0x6e,0x6f,0x75,0x74,0x20,0x76, + 0x65,0x63,0x33,0x20,0x70,0x69,0x78,0x4c,0x50,0x6f,0x73,0x2c,0x20,0x69,0x6e,0x6f, + 0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x69,0x78,0x52,0x50,0x6f,0x73,0x2c, + 0x20,0x69,0x6e,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x69,0x78,0x54, + 0x50,0x6f,0x73,0x2c,0x20,0x69,0x6e,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20, + 0x70,0x69,0x78,0x42,0x50,0x6f,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x34,0x20,0x5f,0x32,0x35,0x36,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70, + 0x28,0x76,0x65,0x63,0x34,0x28,0x65,0x64,0x67,0x65,0x73,0x4c,0x52,0x54,0x42,0x2e, + 0x78,0x20,0x2a,0x20,0x65,0x64,0x67,0x65,0x73,0x4c,0x52,0x54,0x42,0x2e,0x7a,0x2c, + 0x20,0x65,0x64,0x67,0x65,0x73,0x4c,0x52,0x54,0x42,0x2e,0x7a,0x20,0x2a,0x20,0x65, + 0x64,0x67,0x65,0x73,0x4c,0x52,0x54,0x42,0x2e,0x79,0x2c,0x20,0x65,0x64,0x67,0x65, + 0x73,0x4c,0x52,0x54,0x42,0x2e,0x79,0x20,0x2a,0x20,0x65,0x64,0x67,0x65,0x73,0x4c, + 0x52,0x54,0x42,0x2e,0x77,0x2c,0x20,0x65,0x64,0x67,0x65,0x73,0x4c,0x52,0x54,0x42, + 0x2e,0x77,0x20,0x2a,0x20,0x65,0x64,0x67,0x65,0x73,0x4c,0x52,0x54,0x42,0x2e,0x78, + 0x29,0x20,0x2b,0x20,0x76,0x65,0x63,0x34,0x28,0x30,0x2e,0x30,0x30,0x39,0x39,0x39, + 0x39,0x39,0x39,0x39,0x37,0x37,0x36,0x34,0x38,0x32,0x35,0x38,0x32,0x30,0x39,0x32, + 0x32,0x38,0x35,0x31,0x35,0x36,0x32,0x35,0x29,0x2c,0x20,0x76,0x65,0x63,0x34,0x28, + 0x30,0x2e,0x30,0x29,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x31,0x2e,0x30,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x69,0x78,0x4c,0x50,0x6f,0x73,0x20,0x3d,0x20, + 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x70,0x69,0x78,0x4c,0x50,0x6f, + 0x73,0x20,0x2d,0x20,0x70,0x69,0x78,0x43,0x65,0x6e,0x74,0x65,0x72,0x50,0x6f,0x73, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x69,0x78,0x52,0x50,0x6f,0x73,0x20,0x3d, + 0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x70,0x69,0x78,0x52,0x50, + 0x6f,0x73,0x20,0x2d,0x20,0x70,0x69,0x78,0x43,0x65,0x6e,0x74,0x65,0x72,0x50,0x6f, + 0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x69,0x78,0x54,0x50,0x6f,0x73,0x20, + 0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x70,0x69,0x78,0x54, + 0x50,0x6f,0x73,0x20,0x2d,0x20,0x70,0x69,0x78,0x43,0x65,0x6e,0x74,0x65,0x72,0x50, + 0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x69,0x78,0x42,0x50,0x6f,0x73, + 0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x70,0x69,0x78, + 0x42,0x50,0x6f,0x73,0x20,0x2d,0x20,0x70,0x69,0x78,0x43,0x65,0x6e,0x74,0x65,0x72, + 0x50,0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x28,0x28,0x28,0x63,0x72, + 0x6f,0x73,0x73,0x28,0x70,0x69,0x78,0x54,0x50,0x6f,0x73,0x2c,0x20,0x70,0x69,0x78, + 0x4c,0x50,0x6f,0x73,0x29,0x20,0x2a,0x20,0x5f,0x32,0x35,0x36,0x2e,0x78,0x29,0x20, + 0x2b,0x20,0x28,0x63,0x72,0x6f,0x73,0x73,0x28,0x70,0x69,0x78,0x52,0x50,0x6f,0x73, + 0x2c,0x20,0x70,0x69,0x78,0x54,0x50,0x6f,0x73,0x29,0x20,0x2a,0x20,0x5f,0x32,0x35, + 0x36,0x2e,0x79,0x29,0x29,0x20,0x2b,0x20,0x28,0x63,0x72,0x6f,0x73,0x73,0x28,0x70, + 0x69,0x78,0x42,0x50,0x6f,0x73,0x2c,0x20,0x70,0x69,0x78,0x52,0x50,0x6f,0x73,0x29, + 0x20,0x2a,0x20,0x5f,0x32,0x35,0x36,0x2e,0x7a,0x29,0x29,0x20,0x2b,0x20,0x28,0x63, + 0x72,0x6f,0x73,0x73,0x28,0x70,0x69,0x78,0x4c,0x50,0x6f,0x73,0x2c,0x20,0x70,0x69, + 0x78,0x42,0x50,0x6f,0x73,0x29,0x20,0x2a,0x20,0x5f,0x32,0x35,0x36,0x2e,0x77,0x29, + 0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x58,0x65,0x47,0x54,0x41, + 0x4f,0x5f,0x43,0x6f,0x6d,0x70,0x75,0x74,0x65,0x56,0x69,0x65,0x77,0x73,0x70,0x61, + 0x63,0x65,0x4e,0x6f,0x72,0x6d,0x61,0x6c,0x28,0x69,0x76,0x65,0x63,0x32,0x20,0x70, + 0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x2c,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e, + 0x73,0x74,0x73,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x33,0x39,0x34,0x20,0x3d,0x20,0x28,0x76, + 0x65,0x63,0x32,0x28,0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x29,0x20,0x2b,0x20, + 0x76,0x65,0x63,0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2a,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x73,0x2e,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x50,0x69,0x78,0x65, + 0x6c,0x53,0x69,0x7a,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x76,0x65,0x63,0x32, + 0x20,0x5f,0x34,0x30,0x33,0x20,0x3d,0x20,0x67,0x74,0x61,0x6f,0x2e,0x56,0x69,0x65, + 0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65,0x20,0x2d,0x20,0x69,0x76,0x65,0x63, + 0x32,0x28,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x74,0x65,0x78,0x65,0x6c,0x46,0x65,0x74, + 0x63,0x68,0x28,0x74,0x65,0x78,0x5f,0x72,0x61,0x77,0x5f,0x64,0x65,0x70,0x74,0x68, + 0x5f,0x73,0x6d,0x70,0x5f,0x70,0x6f,0x69,0x6e,0x74,0x5f,0x63,0x6c,0x61,0x6d,0x70, + 0x2c,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64, + 0x2c,0x20,0x69,0x76,0x65,0x63,0x32,0x28,0x30,0x29,0x2c,0x20,0x5f,0x34,0x30,0x33, + 0x29,0x2c,0x20,0x30,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41, + 0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20, + 0x3d,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x34,0x35,0x32,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41, + 0x4f,0x5f,0x53,0x63,0x72,0x65,0x65,0x6e,0x53,0x70,0x61,0x63,0x65,0x54,0x6f,0x56, + 0x69,0x65,0x77,0x53,0x70,0x61,0x63,0x65,0x44,0x65,0x70,0x74,0x68,0x28,0x70,0x61, + 0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x20,0x3d,0x20,0x74,0x65,0x78,0x65,0x6c,0x46,0x65,0x74,0x63,0x68,0x28,0x74,0x65, + 0x78,0x5f,0x72,0x61,0x77,0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x73,0x6d,0x70,0x5f, + 0x70,0x6f,0x69,0x6e,0x74,0x5f,0x63,0x6c,0x61,0x6d,0x70,0x2c,0x20,0x63,0x6c,0x61, + 0x6d,0x70,0x28,0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x20,0x2b,0x20,0x69,0x76, + 0x65,0x63,0x32,0x28,0x2d,0x31,0x2c,0x20,0x30,0x29,0x2c,0x20,0x69,0x76,0x65,0x63, + 0x32,0x28,0x30,0x29,0x2c,0x20,0x5f,0x34,0x30,0x33,0x29,0x2c,0x20,0x30,0x29,0x2e, + 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74, + 0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34, + 0x36,0x34,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x53,0x63,0x72,0x65, + 0x65,0x6e,0x53,0x70,0x61,0x63,0x65,0x54,0x6f,0x56,0x69,0x65,0x77,0x53,0x70,0x61, + 0x63,0x65,0x44,0x65,0x70,0x74,0x68,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x74, + 0x65,0x78,0x65,0x6c,0x46,0x65,0x74,0x63,0x68,0x28,0x74,0x65,0x78,0x5f,0x72,0x61, + 0x77,0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x73,0x6d,0x70,0x5f,0x70,0x6f,0x69,0x6e, + 0x74,0x5f,0x63,0x6c,0x61,0x6d,0x70,0x2c,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x70, + 0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x20,0x2b,0x20,0x69,0x76,0x65,0x63,0x32,0x28, + 0x31,0x2c,0x20,0x30,0x29,0x2c,0x20,0x69,0x76,0x65,0x63,0x32,0x28,0x30,0x29,0x2c, + 0x20,0x5f,0x34,0x30,0x33,0x29,0x2c,0x20,0x30,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x37,0x36,0x20,0x3d,0x20, + 0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x53,0x63,0x72,0x65,0x65,0x6e,0x53,0x70,0x61, + 0x63,0x65,0x54,0x6f,0x56,0x69,0x65,0x77,0x53,0x70,0x61,0x63,0x65,0x44,0x65,0x70, + 0x74,0x68,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x74,0x65,0x78,0x65,0x6c,0x46, + 0x65,0x74,0x63,0x68,0x28,0x74,0x65,0x78,0x5f,0x72,0x61,0x77,0x5f,0x64,0x65,0x70, + 0x74,0x68,0x5f,0x73,0x6d,0x70,0x5f,0x70,0x6f,0x69,0x6e,0x74,0x5f,0x63,0x6c,0x61, + 0x6d,0x70,0x2c,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x70,0x69,0x78,0x43,0x6f,0x6f, + 0x72,0x64,0x20,0x2b,0x20,0x69,0x76,0x65,0x63,0x32,0x28,0x30,0x2c,0x20,0x2d,0x31, + 0x29,0x2c,0x20,0x69,0x76,0x65,0x63,0x32,0x28,0x30,0x29,0x2c,0x20,0x5f,0x34,0x30, + 0x33,0x29,0x2c,0x20,0x30,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54, + 0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37, + 0x20,0x3d,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x38,0x38,0x20,0x3d,0x20,0x58,0x65,0x47,0x54, + 0x41,0x4f,0x5f,0x53,0x63,0x72,0x65,0x65,0x6e,0x53,0x70,0x61,0x63,0x65,0x54,0x6f, + 0x56,0x69,0x65,0x77,0x53,0x70,0x61,0x63,0x65,0x44,0x65,0x70,0x74,0x68,0x28,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x38,0x20,0x3d,0x20,0x74,0x65,0x78,0x65,0x6c,0x46,0x65,0x74,0x63,0x68, + 0x28,0x74,0x65,0x78,0x5f,0x72,0x61,0x77,0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x73, + 0x6d,0x70,0x5f,0x70,0x6f,0x69,0x6e,0x74,0x5f,0x63,0x6c,0x61,0x6d,0x70,0x2c,0x20, + 0x63,0x6c,0x61,0x6d,0x70,0x28,0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x20,0x2b, + 0x20,0x69,0x76,0x65,0x63,0x32,0x28,0x30,0x2c,0x20,0x31,0x29,0x2c,0x20,0x69,0x76, + 0x65,0x63,0x32,0x28,0x30,0x29,0x2c,0x20,0x5f,0x34,0x30,0x33,0x29,0x2c,0x20,0x30, + 0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e, + 0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x35,0x30,0x30,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x53,0x63, + 0x72,0x65,0x65,0x6e,0x53,0x70,0x61,0x63,0x65,0x54,0x6f,0x56,0x69,0x65,0x77,0x53, + 0x70,0x61,0x63,0x65,0x44,0x65,0x70,0x74,0x68,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20, + 0x3d,0x20,0x5f,0x34,0x35,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x5f,0x34,0x36, + 0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x5f,0x34,0x37,0x36,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33, + 0x20,0x3d,0x20,0x5f,0x34,0x38,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x5f,0x35, + 0x30,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x5f,0x33,0x39,0x34,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36, + 0x20,0x3d,0x20,0x5f,0x34,0x35,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41, + 0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37, + 0x20,0x3d,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x5f, + 0x33,0x39,0x34,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x2d,0x31,0x2e,0x30, + 0x2c,0x20,0x30,0x2e,0x30,0x29,0x20,0x2a,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e, + 0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x50,0x69,0x78,0x65,0x6c,0x53,0x69,0x7a, + 0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20,0x5f,0x34,0x36,0x34,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x30,0x20,0x3d,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x31,0x20,0x3d,0x20,0x5f,0x33,0x39,0x34,0x20,0x2b,0x20,0x28,0x76,0x65,0x63, + 0x32,0x28,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x29,0x20,0x2a,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x73,0x2e,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x50,0x69,0x78, + 0x65,0x6c,0x53,0x69,0x7a,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x20,0x3d,0x20,0x5f,0x34, + 0x37,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73, + 0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33,0x20,0x3d,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x20,0x3d,0x20,0x5f,0x33,0x39,0x34,0x20,0x2b, + 0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x30,0x2e,0x30,0x2c,0x20,0x2d,0x31,0x2e,0x30, + 0x29,0x20,0x2a,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x56,0x69,0x65,0x77,0x70, + 0x6f,0x72,0x74,0x50,0x69,0x78,0x65,0x6c,0x53,0x69,0x7a,0x65,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x35,0x20,0x3d,0x20,0x5f,0x34,0x38,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54, + 0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x36,0x20,0x3d,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37,0x20,0x3d,0x20, + 0x5f,0x33,0x39,0x34,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x30,0x2e,0x30, + 0x2c,0x20,0x31,0x2e,0x30,0x29,0x20,0x2a,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e, + 0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x50,0x69,0x78,0x65,0x6c,0x53,0x69,0x7a, + 0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x38,0x20,0x3d,0x20,0x5f,0x35,0x30,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x39,0x20,0x3d,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x30,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x61,0x6c,0x63, + 0x75,0x6c,0x61,0x74,0x65,0x45,0x64,0x67,0x65,0x73,0x28,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x31,0x20, + 0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x6f,0x6d,0x70,0x75,0x74,0x65, + 0x56,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f, + 0x6e,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x32,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x6f,0x6d,0x70, + 0x75,0x74,0x65,0x56,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x50,0x6f,0x73,0x69, + 0x74,0x69,0x6f,0x6e,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x33,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43, + 0x6f,0x6d,0x70,0x75,0x74,0x65,0x56,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x50, + 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41, + 0x4f,0x5f,0x43,0x6f,0x6d,0x70,0x75,0x74,0x65,0x56,0x69,0x65,0x77,0x73,0x70,0x61, + 0x63,0x65,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x28,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x35,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x35,0x20,0x3d,0x20,0x58,0x65, + 0x47,0x54,0x41,0x4f,0x5f,0x43,0x6f,0x6d,0x70,0x75,0x74,0x65,0x56,0x69,0x65,0x77, + 0x73,0x70,0x61,0x63,0x65,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x28,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x38, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x39,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x35,0x38,0x36,0x20,0x3d,0x20,0x58,0x65,0x47, + 0x54,0x41,0x4f,0x5f,0x43,0x61,0x6c,0x63,0x75,0x6c,0x61,0x74,0x65,0x4e,0x6f,0x72, + 0x6d,0x61,0x6c,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x30,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x32, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x33,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x33,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x35,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x35,0x38,0x36, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x75,0x69,0x6e,0x74,0x20,0x48,0x69,0x6c,0x62,0x65,0x72, + 0x74,0x49,0x6e,0x64,0x65,0x78,0x28,0x69,0x6e,0x6f,0x75,0x74,0x20,0x75,0x69,0x6e, + 0x74,0x20,0x70,0x6f,0x73,0x58,0x2c,0x20,0x69,0x6e,0x6f,0x75,0x74,0x20,0x75,0x69, + 0x6e,0x74,0x20,0x70,0x6f,0x73,0x59,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x75, + 0x69,0x6e,0x74,0x20,0x69,0x6e,0x64,0x65,0x78,0x20,0x3d,0x20,0x30,0x75,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x20,0x28,0x75,0x69,0x6e,0x74,0x20,0x63,0x75, + 0x72,0x4c,0x65,0x76,0x65,0x6c,0x20,0x3d,0x20,0x33,0x32,0x75,0x3b,0x20,0x63,0x75, + 0x72,0x4c,0x65,0x76,0x65,0x6c,0x20,0x3e,0x20,0x30,0x75,0x3b,0x20,0x63,0x75,0x72, + 0x4c,0x65,0x76,0x65,0x6c,0x20,0x2f,0x3d,0x20,0x32,0x75,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20, + 0x5f,0x33,0x32,0x30,0x20,0x3d,0x20,0x75,0x69,0x6e,0x74,0x28,0x28,0x70,0x6f,0x73, + 0x58,0x20,0x26,0x20,0x63,0x75,0x72,0x4c,0x65,0x76,0x65,0x6c,0x29,0x20,0x3e,0x20, + 0x30,0x75,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x75,0x69,0x6e, + 0x74,0x20,0x5f,0x33,0x32,0x36,0x20,0x3d,0x20,0x75,0x69,0x6e,0x74,0x28,0x28,0x70, + 0x6f,0x73,0x59,0x20,0x26,0x20,0x63,0x75,0x72,0x4c,0x65,0x76,0x65,0x6c,0x29,0x20, + 0x3e,0x20,0x30,0x75,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x6e,0x64,0x65,0x78,0x20,0x2b,0x3d,0x20,0x28,0x28,0x63,0x75,0x72,0x4c,0x65,0x76, + 0x65,0x6c,0x20,0x2a,0x20,0x63,0x75,0x72,0x4c,0x65,0x76,0x65,0x6c,0x29,0x20,0x2a, + 0x20,0x28,0x28,0x33,0x75,0x20,0x2a,0x20,0x5f,0x33,0x32,0x30,0x29,0x20,0x5e,0x20, + 0x5f,0x33,0x32,0x36,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x5f,0x33,0x32,0x36,0x20,0x3d,0x3d,0x20,0x30,0x75,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x33,0x32,0x30,0x20,0x3d, + 0x3d,0x20,0x31,0x75,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x70,0x6f,0x73,0x58,0x20,0x3d,0x20,0x36,0x33,0x75,0x20,0x2d, + 0x20,0x70,0x6f,0x73,0x58,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x70,0x6f,0x73,0x59,0x20,0x3d,0x20,0x36,0x33, + 0x75,0x20,0x2d,0x20,0x70,0x6f,0x73,0x59,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x5f,0x33,0x35,0x31,0x20,0x3d,0x20, + 0x70,0x6f,0x73,0x58,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x70,0x6f,0x73,0x58,0x20,0x3d,0x20,0x70,0x6f,0x73,0x59,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x70,0x6f,0x73,0x59,0x20, + 0x3d,0x20,0x5f,0x33,0x35,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x69,0x6e,0x64,0x65,0x78,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63, + 0x32,0x20,0x53,0x70,0x61,0x74,0x69,0x6f,0x54,0x65,0x6d,0x70,0x6f,0x72,0x61,0x6c, + 0x4e,0x6f,0x69,0x73,0x65,0x28,0x75,0x76,0x65,0x63,0x32,0x20,0x70,0x69,0x78,0x43, + 0x6f,0x6f,0x72,0x64,0x2c,0x20,0x69,0x6e,0x74,0x20,0x74,0x65,0x6d,0x70,0x6f,0x72, + 0x61,0x6c,0x49,0x6e,0x64,0x65,0x78,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x75, + 0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x70,0x69,0x78,0x43, + 0x6f,0x6f,0x72,0x64,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x70,0x69,0x78,0x43,0x6f, + 0x6f,0x72,0x64,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20, + 0x5f,0x33,0x36,0x36,0x20,0x3d,0x20,0x48,0x69,0x6c,0x62,0x65,0x72,0x74,0x49,0x6e, + 0x64,0x65,0x78,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x66,0x72,0x61,0x63,0x74,0x28,0x76,0x65,0x63,0x32,0x28,0x30,0x2e,0x35,0x29,0x20, + 0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x30,0x2e,0x37,0x35,0x34,0x38,0x37,0x37, + 0x36,0x38,0x36,0x35,0x30,0x30,0x35,0x34,0x39,0x33,0x31,0x36,0x34,0x30,0x36,0x32, + 0x35,0x2c,0x20,0x30,0x2e,0x35,0x36,0x39,0x38,0x34,0x30,0x33,0x31,0x32,0x30,0x30, + 0x34,0x30,0x38,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x33,0x36,0x36,0x20,0x2b,0x20,0x28,0x32,0x38, + 0x38,0x75,0x20,0x2a,0x20,0x28,0x75,0x69,0x6e,0x74,0x28,0x74,0x65,0x6d,0x70,0x6f, + 0x72,0x61,0x6c,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x25,0x20,0x36,0x34,0x75,0x29, + 0x29,0x29,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x58, + 0x65,0x47,0x54,0x41,0x4f,0x5f,0x50,0x61,0x63,0x6b,0x45,0x64,0x67,0x65,0x73,0x28, + 0x69,0x6e,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x65,0x64,0x67,0x65,0x73, + 0x4c,0x52,0x54,0x42,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x65,0x64,0x67,0x65, + 0x73,0x4c,0x52,0x54,0x42,0x20,0x3d,0x20,0x72,0x6f,0x75,0x6e,0x64,0x28,0x63,0x6c, + 0x61,0x6d,0x70,0x28,0x65,0x64,0x67,0x65,0x73,0x4c,0x52,0x54,0x42,0x2c,0x20,0x76, + 0x65,0x63,0x34,0x28,0x30,0x2e,0x30,0x29,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x31, + 0x2e,0x30,0x29,0x29,0x20,0x2a,0x20,0x32,0x2e,0x39,0x30,0x30,0x30,0x30,0x30,0x30, + 0x39,0x35,0x33,0x36,0x37,0x34,0x33,0x31,0x36,0x34,0x30,0x36,0x32,0x35,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x64,0x6f,0x74,0x28, + 0x65,0x64,0x67,0x65,0x73,0x4c,0x52,0x54,0x42,0x2c,0x20,0x76,0x65,0x63,0x34,0x28, + 0x30,0x2e,0x32,0x35,0x30,0x39,0x38,0x30,0x34,0x30,0x36,0x39,0x39,0x39,0x35,0x38, + 0x38,0x30,0x31,0x32,0x36,0x39,0x35,0x33,0x31,0x32,0x35,0x2c,0x20,0x30,0x2e,0x30, + 0x36,0x32,0x37,0x34,0x35,0x31,0x30,0x31,0x37,0x34,0x39,0x38,0x39,0x37,0x30,0x30, + 0x33,0x31,0x37,0x33,0x38,0x32,0x38,0x31,0x32,0x35,0x2c,0x20,0x30,0x2e,0x30,0x31, + 0x35,0x36,0x38,0x36,0x32,0x37,0x35,0x34,0x33,0x37,0x34,0x37,0x34,0x32,0x35,0x30, + 0x37,0x39,0x33,0x34,0x35,0x37,0x30,0x33,0x31,0x32,0x35,0x2c,0x20,0x30,0x2e,0x30, + 0x30,0x33,0x39,0x32,0x31,0x35,0x36,0x38,0x38,0x35,0x39,0x33,0x36,0x38,0x35,0x36, + 0x32,0x36,0x39,0x38,0x33,0x36,0x34,0x32,0x35,0x37,0x38,0x31,0x32,0x35,0x29,0x29, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x58,0x65,0x47,0x54,0x41, + 0x4f,0x5f,0x46,0x61,0x73,0x74,0x53,0x71,0x72,0x74,0x28,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x78,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x69,0x6e,0x74,0x42,0x69,0x74,0x73,0x54,0x6f,0x46,0x6c,0x6f,0x61,0x74,0x28, + 0x35,0x33,0x32,0x34,0x38,0x37,0x36,0x36,0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f, + 0x61,0x74,0x42,0x69,0x74,0x73,0x54,0x6f,0x49,0x6e,0x74,0x28,0x78,0x29,0x20,0x3e, + 0x3e,0x20,0x31,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x46,0x61,0x73,0x74,0x41,0x43,0x6f,0x73,0x28, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x69,0x6e,0x58,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x33,0x20,0x3d,0x20,0x61,0x62, + 0x73,0x28,0x69,0x6e,0x58,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x72,0x65,0x73,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x31,0x35,0x36, + 0x35,0x38,0x32,0x39,0x39,0x36,0x32,0x34,0x39,0x31,0x39,0x38,0x39,0x31,0x33,0x35, + 0x37,0x34,0x32,0x31,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x30,0x33,0x29, + 0x20,0x2b,0x20,0x31,0x2e,0x35,0x37,0x30,0x37,0x39,0x36,0x33,0x37,0x30,0x35,0x30, + 0x36,0x32,0x38,0x36,0x36,0x32,0x31,0x30,0x39,0x33,0x37,0x35,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20, + 0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f,0x31,0x30,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x73,0x20,0x2a,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x46,0x61, + 0x73,0x74,0x53,0x71,0x72,0x74,0x28,0x70,0x61,0x72,0x61,0x6d,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x31,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x6e,0x58,0x20,0x3e,0x3d,0x20,0x30,0x2e, + 0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x5f,0x31,0x32,0x31,0x20,0x3d,0x20,0x72,0x65,0x73,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x32,0x31,0x20,0x3d, + 0x20,0x33,0x2e,0x31,0x34,0x31,0x35,0x39,0x32,0x37,0x34,0x31,0x30,0x31,0x32,0x35, + 0x37,0x33,0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x20,0x2d,0x20,0x72,0x65,0x73,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x5f,0x31,0x32,0x31,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x57,0x6f, + 0x72,0x6b,0x69,0x6e,0x67,0x54,0x65,0x72,0x6d,0x28,0x69,0x76,0x65,0x63,0x32,0x20, + 0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x2c,0x20,0x69,0x6e,0x6f,0x75,0x74,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x69,0x73,0x69,0x62,0x69,0x6c,0x69, + 0x74,0x79,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x76,0x69,0x73,0x69,0x62, + 0x69,0x6c,0x69,0x74,0x79,0x20,0x2a,0x20,0x30,0x2e,0x36,0x36,0x36,0x36,0x36,0x36, + 0x36,0x38,0x36,0x35,0x33,0x34,0x38,0x38,0x31,0x35,0x39,0x31,0x37,0x39,0x36,0x38, + 0x37,0x35,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x6d,0x61,0x67,0x65,0x53,0x74,0x6f,0x72,0x65,0x28,0x6f,0x75, + 0x74,0x5f,0x6e,0x6f,0x69,0x73,0x79,0x5f,0x61,0x6f,0x2c,0x20,0x70,0x69,0x78,0x43, + 0x6f,0x6f,0x72,0x64,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x69,0x73,0x69,0x62, + 0x69,0x6c,0x69,0x74,0x79,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c, + 0x20,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x76,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x4d, + 0x61,0x69,0x6e,0x50,0x61,0x73,0x73,0x28,0x69,0x76,0x65,0x63,0x32,0x20,0x70,0x69, + 0x78,0x43,0x6f,0x6f,0x72,0x64,0x2c,0x20,0x76,0x65,0x63,0x32,0x20,0x6c,0x6f,0x63, + 0x61,0x6c,0x4e,0x6f,0x69,0x73,0x65,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x69, + 0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x4e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x63,0x65,0x6e,0x74,0x65,0x72,0x56,0x69,0x65,0x77,0x73, + 0x70,0x61,0x63,0x65,0x5a,0x2c,0x20,0x76,0x65,0x63,0x34,0x20,0x65,0x64,0x67,0x65, + 0x73,0x4c,0x52,0x54,0x42,0x2c,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74, + 0x73,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x65,0x63,0x32,0x20,0x5f,0x36,0x31,0x30,0x20,0x3d,0x20,0x28,0x76,0x65,0x63, + 0x32,0x28,0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x29,0x20,0x2b,0x20,0x76,0x65, + 0x63,0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2a,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x73,0x2e,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x50,0x69,0x78,0x65,0x6c,0x53, + 0x69,0x7a,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76, + 0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x5a,0x20,0x3d,0x20,0x63,0x65,0x6e,0x74, + 0x65,0x72,0x56,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x5a,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x65, + 0x64,0x67,0x65,0x73,0x4c,0x52,0x54,0x42,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x36,0x31,0x38,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41, + 0x4f,0x5f,0x50,0x61,0x63,0x6b,0x45,0x64,0x67,0x65,0x73,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6d,0x61,0x67,0x65,0x53,0x74,0x6f, + 0x72,0x65,0x28,0x6f,0x75,0x74,0x5f,0x65,0x64,0x67,0x65,0x73,0x2c,0x20,0x70,0x69, + 0x78,0x43,0x6f,0x6f,0x72,0x64,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x36,0x31, + 0x38,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36, + 0x32,0x31,0x20,0x3d,0x20,0x76,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x5a,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x32,0x32,0x20, + 0x3d,0x20,0x5f,0x36,0x32,0x31,0x20,0x2a,0x20,0x30,0x2e,0x39,0x39,0x39,0x39,0x38, + 0x39,0x39,0x38,0x36,0x34,0x31,0x39,0x36,0x37,0x37,0x37,0x33,0x34,0x33,0x37,0x35, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x5a, + 0x20,0x3d,0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x36,0x31,0x30, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x33,0x20,0x3d,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x36,0x33,0x30,0x20,0x3d,0x20,0x58,0x65,0x47, + 0x54,0x41,0x4f,0x5f,0x43,0x6f,0x6d,0x70,0x75,0x74,0x65,0x56,0x69,0x65,0x77,0x73, + 0x70,0x61,0x63,0x65,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x28,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x33,0x20,0x5f,0x36,0x33,0x34,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69, + 0x7a,0x65,0x28,0x2d,0x5f,0x36,0x33,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x35,0x30,0x20,0x3d,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x73,0x2e,0x45,0x66,0x66,0x65,0x63,0x74,0x52,0x61,0x64,0x69,0x75,0x73,0x20, + 0x2a,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x52,0x61,0x64,0x69,0x75,0x73,0x4d, + 0x75,0x6c,0x74,0x69,0x70,0x6c,0x69,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x35,0x36,0x20,0x3d,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x73,0x2e,0x45,0x66,0x66,0x65,0x63,0x74,0x46,0x61,0x6c,0x6c,0x6f,0x66,0x66, + 0x52,0x61,0x6e,0x67,0x65,0x20,0x2a,0x20,0x5f,0x36,0x35,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x36,0x35,0x20,0x3d,0x20,0x28, + 0x2d,0x31,0x2e,0x30,0x29,0x20,0x2f,0x20,0x5f,0x36,0x35,0x36,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x37,0x30,0x20,0x3d,0x20,0x28, + 0x28,0x5f,0x36,0x35,0x30,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x73,0x2e,0x45,0x66,0x66,0x65,0x63,0x74,0x46,0x61,0x6c,0x6c, + 0x6f,0x66,0x66,0x52,0x61,0x6e,0x67,0x65,0x29,0x29,0x20,0x2f,0x20,0x5f,0x36,0x35, + 0x36,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x36,0x39,0x37,0x20,0x3d,0x20,0x5f,0x36,0x35,0x30,0x20, + 0x2f,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x76,0x69,0x65,0x77,0x73,0x70,0x61,0x63, + 0x65,0x5a,0x29,0x20,0x2a,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x4e,0x44,0x43, + 0x54,0x6f,0x56,0x69,0x65,0x77,0x4d,0x75,0x6c,0x5f,0x78,0x5f,0x50,0x69,0x78,0x65, + 0x6c,0x53,0x69,0x7a,0x65,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x76,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x20,0x3d, + 0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x28,0x31,0x30,0x2e,0x30,0x20,0x2d,0x20,0x5f, + 0x36,0x39,0x37,0x29,0x20,0x2a,0x20,0x30,0x2e,0x30,0x30,0x39,0x39,0x39,0x39,0x39, + 0x39,0x39,0x37,0x37,0x36,0x34,0x38,0x32,0x35,0x38,0x32,0x30,0x39,0x32,0x32,0x38, + 0x35,0x31,0x35,0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x37,0x31,0x30,0x20,0x3d,0x20,0x31,0x2e,0x32,0x39,0x39,0x39, + 0x39,0x39,0x39,0x35,0x32,0x33,0x31,0x36,0x32,0x38,0x34,0x31,0x37,0x39,0x36,0x38, + 0x37,0x35,0x20,0x2f,0x20,0x5f,0x36,0x39,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6f,0x72,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x6c,0x69,0x63,0x65,0x20, + 0x3d,0x20,0x30,0x2e,0x30,0x3b,0x20,0x73,0x6c,0x69,0x63,0x65,0x20,0x3c,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x73,0x2e,0x53,0x6c,0x69,0x63,0x65,0x43,0x6f,0x75,0x6e,0x74, + 0x3b,0x20,0x73,0x6c,0x69,0x63,0x65,0x20,0x2b,0x3d,0x20,0x31,0x2e,0x30,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x37,0x32,0x38,0x20,0x3d,0x20,0x28,0x28,0x73,0x6c,0x69, + 0x63,0x65,0x20,0x2b,0x20,0x6c,0x6f,0x63,0x61,0x6c,0x4e,0x6f,0x69,0x73,0x65,0x2e, + 0x78,0x29,0x20,0x2f,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x53,0x6c,0x69,0x63, + 0x65,0x43,0x6f,0x75,0x6e,0x74,0x29,0x20,0x2a,0x20,0x33,0x2e,0x31,0x34,0x31,0x35, + 0x39,0x32,0x37,0x34,0x31,0x30,0x31,0x32,0x35,0x37,0x33,0x32,0x34,0x32,0x31,0x38, + 0x37,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x37,0x33,0x31,0x20,0x3d,0x20,0x63,0x6f,0x73,0x28,0x5f,0x37,0x32, + 0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x37,0x33,0x34,0x20,0x3d,0x20,0x73,0x69,0x6e,0x28,0x5f,0x37,0x32, + 0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32, + 0x20,0x5f,0x37,0x34,0x32,0x20,0x3d,0x20,0x76,0x65,0x63,0x32,0x28,0x5f,0x37,0x33, + 0x31,0x2c,0x20,0x2d,0x5f,0x37,0x33,0x34,0x29,0x20,0x2a,0x20,0x5f,0x36,0x39,0x37, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f, + 0x37,0x34,0x36,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x37,0x33,0x31,0x2c, + 0x20,0x5f,0x37,0x33,0x34,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x37,0x35,0x34,0x20,0x3d, + 0x20,0x5f,0x37,0x34,0x36,0x20,0x2d,0x20,0x28,0x5f,0x36,0x33,0x34,0x20,0x2a,0x20, + 0x64,0x6f,0x74,0x28,0x5f,0x37,0x34,0x36,0x2c,0x20,0x5f,0x36,0x33,0x34,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f, + 0x37,0x35,0x39,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28, + 0x63,0x72,0x6f,0x73,0x73,0x28,0x5f,0x37,0x35,0x34,0x2c,0x20,0x5f,0x36,0x33,0x34, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, + 0x20,0x5f,0x37,0x36,0x37,0x20,0x3d,0x20,0x76,0x69,0x65,0x77,0x73,0x70,0x61,0x63, + 0x65,0x4e,0x6f,0x72,0x6d,0x61,0x6c,0x20,0x2d,0x20,0x28,0x5f,0x37,0x35,0x39,0x20, + 0x2a,0x20,0x64,0x6f,0x74,0x28,0x76,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x4e, + 0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x5f,0x37,0x35,0x39,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x37, + 0x35,0x20,0x3d,0x20,0x6c,0x65,0x6e,0x67,0x74,0x68,0x28,0x5f,0x37,0x36,0x37,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x72,0x6f,0x6a,0x65,0x63,0x74,0x65,0x64,0x4e,0x6f,0x72,0x6d,0x61,0x6c,0x56, + 0x65,0x63,0x4c,0x65,0x6e,0x67,0x74,0x68,0x20,0x3d,0x20,0x5f,0x37,0x37,0x35,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x37,0x38,0x32,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x64,0x6f,0x74,0x28, + 0x5f,0x37,0x36,0x37,0x2c,0x20,0x5f,0x36,0x33,0x34,0x29,0x20,0x2f,0x20,0x5f,0x37, + 0x37,0x35,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x37,0x38,0x32,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x38,0x38,0x20, + 0x3d,0x20,0x73,0x69,0x67,0x6e,0x28,0x64,0x6f,0x74,0x28,0x5f,0x37,0x35,0x34,0x2c, + 0x20,0x5f,0x37,0x36,0x37,0x29,0x29,0x20,0x2a,0x20,0x58,0x65,0x47,0x54,0x41,0x4f, + 0x5f,0x46,0x61,0x73,0x74,0x41,0x43,0x6f,0x73,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x37,0x39,0x32,0x20,0x3d,0x20,0x63,0x6f,0x73,0x28,0x5f,0x37,0x38, + 0x38,0x20,0x2b,0x20,0x31,0x2e,0x35,0x37,0x30,0x37,0x39,0x36,0x33,0x37,0x30,0x35, + 0x30,0x36,0x32,0x38,0x36,0x36,0x32,0x31,0x30,0x39,0x33,0x37,0x35,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37, + 0x39,0x36,0x20,0x3d,0x20,0x63,0x6f,0x73,0x28,0x5f,0x37,0x38,0x38,0x20,0x2d,0x20, + 0x31,0x2e,0x35,0x37,0x30,0x37,0x39,0x36,0x33,0x37,0x30,0x35,0x30,0x36,0x32,0x38, + 0x36,0x36,0x32,0x31,0x30,0x39,0x33,0x37,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x68,0x6f,0x72,0x69,0x7a,0x6f, + 0x6e,0x43,0x6f,0x73,0x30,0x20,0x3d,0x20,0x5f,0x37,0x39,0x32,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x68,0x6f,0x72,0x69, + 0x7a,0x6f,0x6e,0x43,0x6f,0x73,0x31,0x20,0x3d,0x20,0x5f,0x37,0x39,0x36,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x20,0x28,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x73,0x74,0x65,0x70,0x5f,0x20,0x3d,0x20,0x30,0x2e,0x30,0x3b,0x20, + 0x73,0x74,0x65,0x70,0x5f,0x20,0x3c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x53, + 0x74,0x65,0x70,0x73,0x50,0x65,0x72,0x53,0x6c,0x69,0x63,0x65,0x3b,0x20,0x73,0x74, + 0x65,0x70,0x5f,0x20,0x2b,0x3d,0x20,0x31,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x38,0x33,0x39,0x20,0x3d,0x20,0x5f,0x37, + 0x34,0x32,0x20,0x2a,0x20,0x28,0x70,0x6f,0x77,0x28,0x6d,0x61,0x78,0x28,0x30,0x2e, + 0x30,0x2c,0x20,0x28,0x73,0x74,0x65,0x70,0x5f,0x20,0x2b,0x20,0x66,0x72,0x61,0x63, + 0x74,0x28,0x6c,0x6f,0x63,0x61,0x6c,0x4e,0x6f,0x69,0x73,0x65,0x2e,0x79,0x20,0x2b, + 0x20,0x28,0x28,0x73,0x6c,0x69,0x63,0x65,0x20,0x2b,0x20,0x28,0x73,0x74,0x65,0x70, + 0x5f,0x20,0x2a,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x53,0x74,0x65,0x70,0x73, + 0x50,0x65,0x72,0x53,0x6c,0x69,0x63,0x65,0x29,0x29,0x20,0x2a,0x20,0x30,0x2e,0x36, + 0x31,0x38,0x30,0x33,0x34,0x30,0x30,0x35,0x31,0x36,0x35,0x31,0x30,0x30,0x30,0x39, + 0x37,0x36,0x35,0x36,0x32,0x35,0x29,0x29,0x29,0x20,0x2f,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x73,0x2e,0x53,0x74,0x65,0x70,0x73,0x50,0x65,0x72,0x53,0x6c,0x69,0x63,0x65, + 0x29,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65, + 0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x50,0x6f,0x77,0x65, + 0x72,0x29,0x20,0x2b,0x20,0x5f,0x37,0x31,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38, + 0x35,0x31,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6c,0x6f,0x67,0x32,0x28, + 0x6c,0x65,0x6e,0x67,0x74,0x68,0x28,0x5f,0x38,0x33,0x39,0x29,0x29,0x20,0x2d,0x20, + 0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x44,0x65,0x70,0x74,0x68,0x4d,0x49,0x50,0x53, + 0x61,0x6d,0x70,0x6c,0x69,0x6e,0x67,0x4f,0x66,0x66,0x73,0x65,0x74,0x2c,0x20,0x30, + 0x2e,0x30,0x2c,0x20,0x35,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x38,0x35,0x36,0x20, + 0x3d,0x20,0x72,0x6f,0x75,0x6e,0x64,0x28,0x5f,0x38,0x33,0x39,0x29,0x20,0x2a,0x20, + 0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x50, + 0x69,0x78,0x65,0x6c,0x53,0x69,0x7a,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x38,0x36,0x30,0x20, + 0x3d,0x20,0x5f,0x36,0x31,0x30,0x20,0x2b,0x20,0x5f,0x38,0x35,0x36,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x5f,0x38,0x36,0x30,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x74,0x65,0x78,0x74, + 0x75,0x72,0x65,0x4c,0x6f,0x64,0x28,0x74,0x65,0x78,0x5f,0x70,0x72,0x65,0x66,0x69, + 0x6c,0x74,0x65,0x72,0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x73,0x6d,0x70,0x5f,0x70, + 0x6f,0x69,0x6e,0x74,0x5f,0x63,0x6c,0x61,0x6d,0x70,0x2c,0x20,0x5f,0x38,0x36,0x30, + 0x2c,0x20,0x5f,0x38,0x35,0x31,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74, + 0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x76,0x65,0x63,0x32,0x20,0x5f,0x38,0x38,0x31,0x20,0x3d,0x20,0x5f,0x36,0x31,0x30, + 0x20,0x2d,0x20,0x5f,0x38,0x35,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x38,0x20,0x3d,0x20,0x5f,0x38,0x38,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x39,0x20,0x3d,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x4c,0x6f,0x64, + 0x28,0x74,0x65,0x78,0x5f,0x70,0x72,0x65,0x66,0x69,0x6c,0x74,0x65,0x72,0x5f,0x64, + 0x65,0x70,0x74,0x68,0x5f,0x73,0x6d,0x70,0x5f,0x70,0x6f,0x69,0x6e,0x74,0x5f,0x63, + 0x6c,0x61,0x6d,0x70,0x2c,0x20,0x5f,0x38,0x38,0x31,0x2c,0x20,0x5f,0x38,0x35,0x31, + 0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, + 0x5f,0x39,0x30,0x31,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x6f, + 0x6d,0x70,0x75,0x74,0x65,0x56,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x50,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37, + 0x29,0x20,0x2d,0x20,0x5f,0x36,0x33,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x39,0x30,0x35,0x20, + 0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x6f,0x6d,0x70,0x75,0x74,0x65, + 0x56,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f, + 0x6e,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x29,0x20,0x2d,0x20, + 0x5f,0x36,0x33,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x33,0x30,0x20,0x3d,0x20,0x31, + 0x2e,0x30,0x20,0x2b,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x54,0x68,0x69,0x6e, + 0x4f,0x63,0x63,0x6c,0x75,0x64,0x65,0x72,0x43,0x6f,0x6d,0x70,0x65,0x6e,0x73,0x61, + 0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x68,0x6f,0x72,0x69,0x7a,0x6f,0x6e,0x43,0x6f,0x73,0x30,0x20,0x3d,0x20, + 0x6d,0x61,0x78,0x28,0x68,0x6f,0x72,0x69,0x7a,0x6f,0x6e,0x43,0x6f,0x73,0x30,0x2c, + 0x20,0x6d,0x69,0x78,0x28,0x5f,0x37,0x39,0x32,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f, + 0x39,0x30,0x31,0x20,0x2f,0x20,0x76,0x65,0x63,0x33,0x28,0x6c,0x65,0x6e,0x67,0x74, + 0x68,0x28,0x5f,0x39,0x30,0x31,0x29,0x29,0x2c,0x20,0x5f,0x36,0x33,0x34,0x29,0x2c, + 0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x28,0x6c,0x65,0x6e,0x67,0x74,0x68,0x28,0x76, + 0x65,0x63,0x33,0x28,0x5f,0x39,0x30,0x31,0x2e,0x78,0x79,0x2c,0x20,0x5f,0x39,0x30, + 0x31,0x2e,0x7a,0x20,0x2a,0x20,0x5f,0x39,0x33,0x30,0x29,0x29,0x20,0x2a,0x20,0x5f, + 0x36,0x36,0x35,0x29,0x20,0x2b,0x20,0x5f,0x36,0x37,0x30,0x2c,0x20,0x30,0x2e,0x30, + 0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x68,0x6f,0x72,0x69,0x7a,0x6f,0x6e,0x43,0x6f,0x73, + 0x31,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x68,0x6f,0x72,0x69,0x7a,0x6f,0x6e,0x43, + 0x6f,0x73,0x31,0x2c,0x20,0x6d,0x69,0x78,0x28,0x5f,0x37,0x39,0x36,0x2c,0x20,0x64, + 0x6f,0x74,0x28,0x5f,0x39,0x30,0x35,0x20,0x2f,0x20,0x76,0x65,0x63,0x33,0x28,0x6c, + 0x65,0x6e,0x67,0x74,0x68,0x28,0x5f,0x39,0x30,0x35,0x29,0x29,0x2c,0x20,0x5f,0x36, + 0x33,0x34,0x29,0x2c,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x28,0x6c,0x65,0x6e,0x67, + 0x74,0x68,0x28,0x76,0x65,0x63,0x33,0x28,0x5f,0x39,0x30,0x35,0x2e,0x78,0x79,0x2c, + 0x20,0x5f,0x39,0x30,0x35,0x2e,0x7a,0x20,0x2a,0x20,0x5f,0x39,0x33,0x30,0x29,0x29, + 0x20,0x2a,0x20,0x5f,0x36,0x36,0x35,0x29,0x20,0x2b,0x20,0x5f,0x36,0x37,0x30,0x2c, + 0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x70,0x72,0x6f,0x6a,0x65,0x63,0x74,0x65,0x64,0x4e,0x6f,0x72,0x6d,0x61,0x6c,0x56, + 0x65,0x63,0x4c,0x65,0x6e,0x67,0x74,0x68,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x70, + 0x72,0x6f,0x6a,0x65,0x63,0x74,0x65,0x64,0x4e,0x6f,0x72,0x6d,0x61,0x6c,0x56,0x65, + 0x63,0x4c,0x65,0x6e,0x67,0x74,0x68,0x2c,0x20,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e, + 0x30,0x35,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x37,0x34,0x35,0x30,0x35,0x38,0x30, + 0x35,0x39,0x36,0x39,0x32,0x33,0x38,0x32,0x38,0x31,0x32,0x35,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x68,0x6f,0x72,0x69,0x7a,0x6f,0x6e,0x43, + 0x6f,0x73,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x68,0x6f, + 0x72,0x69,0x7a,0x6f,0x6e,0x43,0x6f,0x73,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x30,0x30,0x20,0x3d, + 0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x46,0x61,0x73,0x74,0x41,0x43,0x6f,0x73, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x29,0x20,0x2a,0x20,0x28,0x2d,0x32, + 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x30,0x30,0x32,0x20,0x3d,0x20,0x73,0x69,0x6e,0x28,0x5f, + 0x37,0x38,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x31,0x36,0x20,0x3d,0x20,0x32,0x2e,0x30,0x20, + 0x2a,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x46,0x61,0x73,0x74,0x41,0x43,0x6f, + 0x73,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x76,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x20, + 0x2b,0x3d,0x20,0x28,0x70,0x72,0x6f,0x6a,0x65,0x63,0x74,0x65,0x64,0x4e,0x6f,0x72, + 0x6d,0x61,0x6c,0x56,0x65,0x63,0x4c,0x65,0x6e,0x67,0x74,0x68,0x20,0x2a,0x20,0x28, + 0x30,0x2e,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x28,0x5f,0x37,0x38,0x32,0x20,0x2b, + 0x20,0x28,0x5f,0x31,0x30,0x30,0x30,0x20,0x2a,0x20,0x5f,0x31,0x30,0x30,0x32,0x29, + 0x29,0x20,0x2d,0x20,0x63,0x6f,0x73,0x28,0x5f,0x31,0x30,0x30,0x30,0x20,0x2d,0x20, + 0x5f,0x37,0x38,0x38,0x29,0x29,0x20,0x2b,0x20,0x28,0x28,0x5f,0x37,0x38,0x32,0x20, + 0x2b,0x20,0x28,0x5f,0x31,0x30,0x31,0x36,0x20,0x2a,0x20,0x5f,0x31,0x30,0x30,0x32, + 0x29,0x29,0x20,0x2d,0x20,0x63,0x6f,0x73,0x28,0x5f,0x31,0x30,0x31,0x36,0x20,0x2d, + 0x20,0x5f,0x37,0x38,0x38,0x29,0x29,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x34, + 0x30,0x20,0x3d,0x20,0x76,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x30,0x20, + 0x3d,0x20,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x32,0x39,0x39,0x39,0x39,0x39,0x39, + 0x39,0x33,0x32,0x39,0x34,0x34,0x37,0x37,0x34,0x36,0x32,0x37,0x36,0x38,0x35,0x35, + 0x34,0x36,0x38,0x37,0x35,0x2c,0x20,0x70,0x6f,0x77,0x28,0x6d,0x61,0x78,0x28,0x30, + 0x2e,0x30,0x2c,0x20,0x5f,0x31,0x30,0x34,0x30,0x20,0x2f,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x73,0x2e,0x53,0x6c,0x69,0x63,0x65,0x43,0x6f,0x75,0x6e,0x74,0x29,0x2c,0x20, + 0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x46,0x69,0x6e,0x61,0x6c,0x56,0x61,0x6c,0x75, + 0x65,0x50,0x6f,0x77,0x65,0x72,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x69, + 0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x20,0x3d,0x20,0x5f,0x31,0x30,0x35,0x30, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20,0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x34,0x20,0x3d,0x20,0x5f,0x31,0x30,0x35,0x30,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x35,0x20,0x3d,0x20,0x58, + 0x65,0x47,0x54,0x41,0x4f,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x57,0x6f,0x72,0x6b, + 0x69,0x6e,0x67,0x54,0x65,0x72,0x6d,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x30,0x35,0x35,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x76,0x65,0x63,0x32,0x20,0x5f,0x31,0x30,0x36,0x34,0x20, + 0x3d,0x20,0x69,0x76,0x65,0x63,0x32,0x28,0x67,0x6c,0x5f,0x47,0x6c,0x6f,0x62,0x61, + 0x6c,0x49,0x6e,0x76,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x49,0x44,0x2e,0x78,0x79, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x61,0x6e,0x79,0x28,0x67, + 0x72,0x65,0x61,0x74,0x65,0x72,0x54,0x68,0x61,0x6e,0x45,0x71,0x75,0x61,0x6c,0x28, + 0x5f,0x31,0x30,0x36,0x34,0x2c,0x20,0x67,0x74,0x61,0x6f,0x2e,0x56,0x69,0x65,0x77, + 0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65,0x29,0x29,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x76,0x65,0x63, + 0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x36,0x34,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20, + 0x5f,0x31,0x32,0x36,0x31,0x20,0x3d,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73, + 0x74,0x73,0x28,0x67,0x74,0x61,0x6f,0x2e,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74, + 0x50,0x69,0x78,0x65,0x6c,0x53,0x69,0x7a,0x65,0x2c,0x20,0x67,0x74,0x61,0x6f,0x2e, + 0x4e,0x44,0x43,0x54,0x6f,0x56,0x69,0x65,0x77,0x4d,0x75,0x6c,0x2c,0x20,0x67,0x74, + 0x61,0x6f,0x2e,0x4e,0x44,0x43,0x54,0x6f,0x56,0x69,0x65,0x77,0x41,0x64,0x64,0x2c, + 0x20,0x67,0x74,0x61,0x6f,0x2e,0x4e,0x44,0x43,0x54,0x6f,0x56,0x69,0x65,0x77,0x4d, + 0x75,0x6c,0x5f,0x78,0x5f,0x50,0x69,0x78,0x65,0x6c,0x53,0x69,0x7a,0x65,0x2c,0x20, + 0x67,0x74,0x61,0x6f,0x2e,0x45,0x66,0x66,0x65,0x63,0x74,0x52,0x61,0x64,0x69,0x75, + 0x73,0x2c,0x20,0x67,0x74,0x61,0x6f,0x2e,0x45,0x66,0x66,0x65,0x63,0x74,0x46,0x61, + 0x6c,0x6c,0x6f,0x66,0x66,0x52,0x61,0x6e,0x67,0x65,0x2c,0x20,0x67,0x74,0x61,0x6f, + 0x2e,0x52,0x61,0x64,0x69,0x75,0x73,0x4d,0x75,0x6c,0x74,0x69,0x70,0x6c,0x69,0x65, + 0x72,0x2c,0x20,0x67,0x74,0x61,0x6f,0x2e,0x46,0x69,0x6e,0x61,0x6c,0x56,0x61,0x6c, + 0x75,0x65,0x50,0x6f,0x77,0x65,0x72,0x2c,0x20,0x67,0x74,0x61,0x6f,0x2e,0x53,0x61, + 0x6d,0x70,0x6c,0x65,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e, + 0x50,0x6f,0x77,0x65,0x72,0x2c,0x20,0x67,0x74,0x61,0x6f,0x2e,0x54,0x68,0x69,0x6e, + 0x4f,0x63,0x63,0x6c,0x75,0x64,0x65,0x72,0x43,0x6f,0x6d,0x70,0x65,0x6e,0x73,0x61, + 0x74,0x69,0x6f,0x6e,0x2c,0x20,0x67,0x74,0x61,0x6f,0x2e,0x44,0x65,0x70,0x74,0x68, + 0x4d,0x49,0x50,0x53,0x61,0x6d,0x70,0x6c,0x69,0x6e,0x67,0x4f,0x66,0x66,0x73,0x65, + 0x74,0x2c,0x20,0x67,0x74,0x61,0x6f,0x2e,0x53,0x6c,0x69,0x63,0x65,0x43,0x6f,0x75, + 0x6e,0x74,0x2c,0x20,0x67,0x74,0x61,0x6f,0x2e,0x53,0x74,0x65,0x70,0x73,0x50,0x65, + 0x72,0x53,0x6c,0x69,0x63,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41, + 0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20, + 0x3d,0x20,0x5f,0x31,0x32,0x36,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x76,0x65, + 0x63,0x32,0x20,0x5f,0x31,0x31,0x32,0x37,0x20,0x3d,0x20,0x67,0x74,0x61,0x6f,0x2e, + 0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65,0x20,0x2d,0x20,0x69, + 0x76,0x65,0x63,0x32,0x28,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x74,0x65,0x78, + 0x65,0x6c,0x46,0x65,0x74,0x63,0x68,0x28,0x74,0x65,0x78,0x5f,0x72,0x61,0x77,0x5f, + 0x64,0x65,0x70,0x74,0x68,0x5f,0x73,0x6d,0x70,0x5f,0x70,0x6f,0x69,0x6e,0x74,0x5f, + 0x63,0x6c,0x61,0x6d,0x70,0x2c,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x5f,0x31,0x30, + 0x36,0x34,0x2c,0x20,0x69,0x76,0x65,0x63,0x32,0x28,0x30,0x29,0x2c,0x20,0x5f,0x31, + 0x31,0x32,0x37,0x29,0x2c,0x20,0x30,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31,0x32,0x36,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x34,0x31,0x20,0x3d,0x20,0x58,0x65, + 0x47,0x54,0x41,0x4f,0x5f,0x53,0x63,0x72,0x65,0x65,0x6e,0x53,0x70,0x61,0x63,0x65, + 0x54,0x6f,0x56,0x69,0x65,0x77,0x53,0x70,0x61,0x63,0x65,0x44,0x65,0x70,0x74,0x68, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x74,0x65,0x78,0x65,0x6c,0x46,0x65,0x74, + 0x63,0x68,0x28,0x74,0x65,0x78,0x5f,0x72,0x61,0x77,0x5f,0x64,0x65,0x70,0x74,0x68, + 0x5f,0x73,0x6d,0x70,0x5f,0x70,0x6f,0x69,0x6e,0x74,0x5f,0x63,0x6c,0x61,0x6d,0x70, + 0x2c,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x5f,0x31,0x30,0x36,0x34,0x20,0x2b,0x20, + 0x69,0x76,0x65,0x63,0x32,0x28,0x2d,0x31,0x2c,0x20,0x30,0x29,0x2c,0x20,0x69,0x76, + 0x65,0x63,0x32,0x28,0x30,0x29,0x2c,0x20,0x5f,0x31,0x31,0x32,0x37,0x29,0x2c,0x20, + 0x30,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f, + 0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x5f, + 0x31,0x32,0x36,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x74,0x65,0x78,0x65,0x6c,0x46, + 0x65,0x74,0x63,0x68,0x28,0x74,0x65,0x78,0x5f,0x72,0x61,0x77,0x5f,0x64,0x65,0x70, + 0x74,0x68,0x5f,0x73,0x6d,0x70,0x5f,0x70,0x6f,0x69,0x6e,0x74,0x5f,0x63,0x6c,0x61, + 0x6d,0x70,0x2c,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x5f,0x31,0x30,0x36,0x34,0x20, + 0x2b,0x20,0x69,0x76,0x65,0x63,0x32,0x28,0x31,0x2c,0x20,0x30,0x29,0x2c,0x20,0x69, + 0x76,0x65,0x63,0x32,0x28,0x30,0x29,0x2c,0x20,0x5f,0x31,0x31,0x32,0x37,0x29,0x2c, + 0x20,0x30,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43, + 0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20, + 0x5f,0x31,0x32,0x36,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x74,0x65,0x78,0x65,0x6c, + 0x46,0x65,0x74,0x63,0x68,0x28,0x74,0x65,0x78,0x5f,0x72,0x61,0x77,0x5f,0x64,0x65, + 0x70,0x74,0x68,0x5f,0x73,0x6d,0x70,0x5f,0x70,0x6f,0x69,0x6e,0x74,0x5f,0x63,0x6c, + 0x61,0x6d,0x70,0x2c,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x5f,0x31,0x30,0x36,0x34, + 0x20,0x2b,0x20,0x69,0x76,0x65,0x63,0x32,0x28,0x30,0x2c,0x20,0x2d,0x31,0x29,0x2c, + 0x20,0x69,0x76,0x65,0x63,0x32,0x28,0x30,0x29,0x2c,0x20,0x5f,0x31,0x31,0x32,0x37, + 0x29,0x2c,0x20,0x30,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41, + 0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20, + 0x3d,0x20,0x5f,0x31,0x32,0x36,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x74,0x65, + 0x78,0x65,0x6c,0x46,0x65,0x74,0x63,0x68,0x28,0x74,0x65,0x78,0x5f,0x72,0x61,0x77, + 0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x73,0x6d,0x70,0x5f,0x70,0x6f,0x69,0x6e,0x74, + 0x5f,0x63,0x6c,0x61,0x6d,0x70,0x2c,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x5f,0x31, + 0x30,0x36,0x34,0x20,0x2b,0x20,0x69,0x76,0x65,0x63,0x32,0x28,0x30,0x2c,0x20,0x31, + 0x29,0x2c,0x20,0x69,0x76,0x65,0x63,0x32,0x28,0x30,0x29,0x2c,0x20,0x5f,0x31,0x31, + 0x32,0x37,0x29,0x2c,0x20,0x30,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47, + 0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x31,0x20,0x3d,0x20,0x5f,0x31,0x32,0x36,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d, + 0x20,0x5f,0x31,0x31,0x34,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20,0x58,0x65,0x47, + 0x54,0x41,0x4f,0x5f,0x53,0x63,0x72,0x65,0x65,0x6e,0x53,0x70,0x61,0x63,0x65,0x54, + 0x6f,0x56,0x69,0x65,0x77,0x53,0x70,0x61,0x63,0x65,0x44,0x65,0x70,0x74,0x68,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x53, + 0x63,0x72,0x65,0x65,0x6e,0x53,0x70,0x61,0x63,0x65,0x54,0x6f,0x56,0x69,0x65,0x77, + 0x53,0x70,0x61,0x63,0x65,0x44,0x65,0x70,0x74,0x68,0x28,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35, + 0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x53,0x63,0x72,0x65,0x65,0x6e, + 0x53,0x70,0x61,0x63,0x65,0x54,0x6f,0x56,0x69,0x65,0x77,0x53,0x70,0x61,0x63,0x65, + 0x44,0x65,0x70,0x74,0x68,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x39,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x58,0x65, + 0x47,0x54,0x41,0x4f,0x5f,0x53,0x63,0x72,0x65,0x65,0x6e,0x53,0x70,0x61,0x63,0x65, + 0x54,0x6f,0x56,0x69,0x65,0x77,0x53,0x70,0x61,0x63,0x65,0x44,0x65,0x70,0x74,0x68, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x76,0x65,0x63,0x32,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x20,0x3d,0x20,0x75,0x76,0x65,0x63,0x32, + 0x28,0x5f,0x31,0x30,0x36,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x39,0x20,0x3d,0x20,0x5f,0x31,0x30,0x36,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x20,0x3d,0x20,0x53, + 0x70,0x61,0x74,0x69,0x6f,0x54,0x65,0x6d,0x70,0x6f,0x72,0x61,0x6c,0x4e,0x6f,0x69, + 0x73,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x20,0x3d,0x20,0x58,0x65,0x47,0x54, + 0x41,0x4f,0x5f,0x43,0x6f,0x6d,0x70,0x75,0x74,0x65,0x56,0x69,0x65,0x77,0x73,0x70, + 0x61,0x63,0x65,0x4e,0x6f,0x72,0x6d,0x61,0x6c,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x20,0x3d,0x20, + 0x5f,0x31,0x31,0x34,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41, + 0x4f,0x5f,0x43,0x61,0x6c,0x63,0x75,0x6c,0x61,0x74,0x65,0x45,0x64,0x67,0x65,0x73, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73, + 0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x20,0x3d,0x20,0x5f,0x31, + 0x32,0x36,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x32,0x33,0x32,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x4d,0x61, + 0x69,0x6e,0x50,0x61,0x73,0x73,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x34,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + struct GTAOConsts + { + float2 ViewportPixelSize; + float2 NDCToViewMul; + float2 NDCToViewAdd; + float2 NDCToViewMul_x_PixelSize; + float EffectRadius; + float EffectFalloffRange; + float RadiusMultiplier; + float FinalValuePower; + float SampleDistributionPower; + float ThinOccluderCompensation; + float DepthMIPSamplingOffset; + float SliceCount; + float StepsPerSlice; + }; + + static const uint3 gl_WorkGroupSize = uint3(8u, 8u, 1u); + + cbuffer ub_gtao : register(b0) + { + int2 gtao_ViewportSize : packoffset(c0); + float2 gtao_ViewportPixelSize : packoffset(c0.z); + float2 gtao_NDCToViewMul : packoffset(c1); + float2 gtao_NDCToViewAdd : packoffset(c1.z); + float2 gtao_NDCToViewMul_x_PixelSize : packoffset(c2); + float gtao_EffectRadius : packoffset(c2.z); + float gtao_EffectFalloffRange : packoffset(c2.w); + float gtao_RadiusMultiplier : packoffset(c3); + float gtao_FinalValuePower : packoffset(c3.y); + float gtao_SampleDistributionPower : packoffset(c3.z); + float gtao_ThinOccluderCompensation : packoffset(c3.w); + float gtao_DepthMIPSamplingOffset : packoffset(c4); + float gtao_SliceCount : packoffset(c4.y); + float gtao_StepsPerSlice : packoffset(c4.z); + }; + + Texture2D tex_raw_depth : register(t0); + SamplerState smp_point_clamp : register(s0); + RWTexture2D out_noisy_ao : register(u0); + RWTexture2D out_edges : register(u1); + Texture2D tex_prefilter_depth : register(t1); + + static uint3 gl_GlobalInvocationID; + struct SPIRV_Cross_Input + { + uint3 gl_GlobalInvocationID : SV_DispatchThreadID; + }; + + float XeGTAO_ScreenSpaceToViewSpaceDepth(float screenDepth, GTAOConsts consts) + { + return screenDepth; + } + + float4 XeGTAO_CalculateEdges(float centerZ, float leftZ, float rightZ, float topZ, float bottomZ) + { + float4 _167 = float4(leftZ, rightZ, topZ, bottomZ) - centerZ.xxxx; + float _173 = _167.y - _167.x; + float _182 = _167.w - _167.z; + return clamp(1.25f.xxxx - (min(abs(_167), abs(_167 + float4(_173 * 0.5f, _173 * (-0.5f), _182 * 0.5f, _182 * (-0.5f)))) / (centerZ * 0.010999999940395355224609375f).xxxx), 0.0f.xxxx, 1.0f.xxxx); + } + + float3 XeGTAO_ComputeViewspacePosition(float2 screenPos, float viewspaceDepth, GTAOConsts consts) + { + return float3(((consts.NDCToViewMul * screenPos) + consts.NDCToViewAdd) * viewspaceDepth, -viewspaceDepth); + } + + float3 XeGTAO_CalculateNormal(float4 edgesLRTB, float3 pixCenterPos, inout float3 pixLPos, inout float3 pixRPos, inout float3 pixTPos, inout float3 pixBPos) + { + float4 _256 = clamp(float4(edgesLRTB.x * edgesLRTB.z, edgesLRTB.z * edgesLRTB.y, edgesLRTB.y * edgesLRTB.w, edgesLRTB.w * edgesLRTB.x) + 0.00999999977648258209228515625f.xxxx, 0.0f.xxxx, 1.0f.xxxx); + pixLPos = normalize(pixLPos - pixCenterPos); + pixRPos = normalize(pixRPos - pixCenterPos); + pixTPos = normalize(pixTPos - pixCenterPos); + pixBPos = normalize(pixBPos - pixCenterPos); + return normalize((((cross(pixTPos, pixLPos) * _256.x) + (cross(pixRPos, pixTPos) * _256.y)) + (cross(pixBPos, pixRPos) * _256.z)) + (cross(pixLPos, pixBPos) * _256.w)); + } + + float3 XeGTAO_ComputeViewspaceNormal(int2 pixCoord, GTAOConsts consts) + { + float2 _394 = (float2(pixCoord) + 0.5f.xx) * consts.ViewportPixelSize; + int2 _403 = gtao_ViewportSize - int2(1, 1); + float param = tex_raw_depth.Load(int3(clamp(pixCoord, int2(0, 0), _403), 0)).x; + GTAOConsts param_1 = consts; + float _452 = XeGTAO_ScreenSpaceToViewSpaceDepth(param, param_1); + float param_2 = tex_raw_depth.Load(int3(clamp(pixCoord + int2(-1, 0), int2(0, 0), _403), 0)).x; + GTAOConsts param_3 = consts; + float _464 = XeGTAO_ScreenSpaceToViewSpaceDepth(param_2, param_3); + float param_4 = tex_raw_depth.Load(int3(clamp(pixCoord + int2(1, 0), int2(0, 0), _403), 0)).x; + GTAOConsts param_5 = consts; + float _476 = XeGTAO_ScreenSpaceToViewSpaceDepth(param_4, param_5); + float param_6 = tex_raw_depth.Load(int3(clamp(pixCoord + int2(0, -1), int2(0, 0), _403), 0)).x; + GTAOConsts param_7 = consts; + float _488 = XeGTAO_ScreenSpaceToViewSpaceDepth(param_6, param_7); + float param_8 = tex_raw_depth.Load(int3(clamp(pixCoord + int2(0, 1), int2(0, 0), _403), 0)).x; + GTAOConsts param_9 = consts; + float _500 = XeGTAO_ScreenSpaceToViewSpaceDepth(param_8, param_9); + float param_10 = _452; + float param_11 = _464; + float param_12 = _476; + float param_13 = _488; + float param_14 = _500; + float2 param_15 = _394; + float param_16 = _452; + GTAOConsts param_17 = consts; + float2 param_18 = _394 + (float2(-1.0f, 0.0f) * consts.ViewportPixelSize); + float param_19 = _464; + GTAOConsts param_20 = consts; + float2 param_21 = _394 + (float2(1.0f, 0.0f) * consts.ViewportPixelSize); + float param_22 = _476; + GTAOConsts param_23 = consts; + float2 param_24 = _394 + (float2(0.0f, -1.0f) * consts.ViewportPixelSize); + float param_25 = _488; + GTAOConsts param_26 = consts; + float2 param_27 = _394 + (float2(0.0f, 1.0f) * consts.ViewportPixelSize); + float param_28 = _500; + GTAOConsts param_29 = consts; + float4 param_30 = XeGTAO_CalculateEdges(param_10, param_11, param_12, param_13, param_14); + float3 param_31 = XeGTAO_ComputeViewspacePosition(param_15, param_16, param_17); + float3 param_32 = XeGTAO_ComputeViewspacePosition(param_18, param_19, param_20); + float3 param_33 = XeGTAO_ComputeViewspacePosition(param_21, param_22, param_23); + float3 param_34 = XeGTAO_ComputeViewspacePosition(param_24, param_25, param_26); + float3 param_35 = XeGTAO_ComputeViewspacePosition(param_27, param_28, param_29); + float3 _586 = XeGTAO_CalculateNormal(param_30, param_31, param_32, param_33, param_34, param_35); + return _586; + } + + uint HilbertIndex(inout uint posX, inout uint posY) + { + uint index = 0u; + for (uint curLevel = 32u; curLevel > 0u; curLevel /= 2u) + { + uint _320 = uint((posX & curLevel) > 0u); + uint _326 = uint((posY & curLevel) > 0u); + index += ((curLevel * curLevel) * ((3u * _320) ^ _326)); + if (_326 == 0u) + { + if (_320 == 1u) + { + posX = 63u - posX; + posY = 63u - posY; + } + uint _351 = posX; + posX = posY; + posY = _351; + } + } + return index; + } + + float2 SpatioTemporalNoise(uint2 pixCoord, int temporalIndex) + { + uint param = pixCoord.x; + uint param_1 = pixCoord.y; + uint _366 = HilbertIndex(param, param_1); + return frac(0.5f.xx + (float2(0.75487768650054931640625f, 0.56984031200408935546875f) * float(_366 + (288u * (uint(temporalIndex) % 64u))))); + } + + float XeGTAO_PackEdges(inout float4 edgesLRTB) + { + edgesLRTB = round(clamp(edgesLRTB, 0.0f.xxxx, 1.0f.xxxx) * 2.900000095367431640625f); + return dot(edgesLRTB, float4(0.2509804069995880126953125f, 0.062745101749897003173828125f, 0.01568627543747425079345703125f, 0.0039215688593685626983642578125f)); + } + + float XeGTAO_FastSqrt(float x) + { + return asfloat(532487669 + (asint(x) >> 1)); + } + + float XeGTAO_FastACos(float inX) + { + float _103 = abs(inX); + float res = ((-0.15658299624919891357421875f) * _103) + 1.57079637050628662109375f; + float param = 1.0f - _103; + res *= XeGTAO_FastSqrt(param); + float _121; + if (inX >= 0.0f) + { + _121 = res; + } + else + { + _121 = 3.1415927410125732421875f - res; + } + return _121; + } + + float XeGTAO_OutputWorkingTerm(int2 pixCoord, inout float visibility) + { + visibility = clamp(visibility * 0.666666686534881591796875f, 0.0f, 1.0f); + out_noisy_ao[pixCoord] = float4(visibility, 0.0f, 0.0f, 0.0f).x; + return visibility; + } + + float XeGTAO_MainPass(int2 pixCoord, float2 localNoise, float3 viewspaceNormal, float centerViewspaceZ, float4 edgesLRTB, GTAOConsts consts) + { + float2 _610 = (float2(pixCoord) + 0.5f.xx) * consts.ViewportPixelSize; + float viewspaceZ = centerViewspaceZ; + float4 param = edgesLRTB; + float _618 = XeGTAO_PackEdges(param); + out_edges[pixCoord] = float4(_618, 0.0f, 0.0f, 0.0f).x; + float _621 = viewspaceZ; + float _622 = _621 * 0.999989986419677734375f; + viewspaceZ = _622; + float2 param_1 = _610; + float param_2 = _622; + GTAOConsts param_3 = consts; + float3 _630 = XeGTAO_ComputeViewspacePosition(param_1, param_2, param_3); + float3 _634 = normalize(-_630); + float _650 = consts.EffectRadius * consts.RadiusMultiplier; + float _656 = consts.EffectFalloffRange * _650; + float _665 = (-1.0f) / _656; + float _670 = ((_650 * (1.0f - consts.EffectFalloffRange)) / _656) + 1.0f; + float _697 = _650 / (viewspaceZ.xx * consts.NDCToViewMul_x_PixelSize).x; + float visibility = clamp((10.0f - _697) * 0.00999999977648258209228515625f, 0.0f, 1.0f) * 0.5f; + float _710 = 1.2999999523162841796875f / _697; + for (float slice = 0.0f; slice < consts.SliceCount; slice += 1.0f) + { + float _728 = ((slice + localNoise.x) / consts.SliceCount) * 3.1415927410125732421875f; + float _731 = cos(_728); + float _734 = sin(_728); + float2 _742 = float2(_731, -_734) * _697; + float3 _746 = float3(_731, _734, 0.0f); + float3 _754 = _746 - (_634 * dot(_746, _634)); + float3 _759 = normalize(cross(_754, _634)); + float3 _767 = viewspaceNormal - (_759 * dot(viewspaceNormal, _759)); + float _775 = length(_767); + float projectedNormalVecLength = _775; + float _782 = clamp(dot(_767, _634) / _775, 0.0f, 1.0f); + float param_4 = _782; + float _788 = sign(dot(_754, _767)) * XeGTAO_FastACos(param_4); + float _792 = cos(_788 + 1.57079637050628662109375f); + float _796 = cos(_788 - 1.57079637050628662109375f); + float horizonCos0 = _792; + float horizonCos1 = _796; + for (float step_ = 0.0f; step_ < consts.StepsPerSlice; step_ += 1.0f) + { + float2 _839 = _742 * (pow(max(0.0f, (step_ + frac(localNoise.y + ((slice + (step_ * consts.StepsPerSlice)) * 0.61803400516510009765625f))) / consts.StepsPerSlice), consts.SampleDistributionPower) + _710); + float _851 = clamp(log2(length(_839)) - consts.DepthMIPSamplingOffset, 0.0f, 5.0f); + float2 _856 = round(_839) * consts.ViewportPixelSize; + float2 _860 = _610 + _856; + float2 param_5 = _860; + float param_6 = tex_prefilter_depth.SampleLevel(smp_point_clamp, _860, _851).x; + GTAOConsts param_7 = consts; + float2 _881 = _610 - _856; + float2 param_8 = _881; + float param_9 = tex_prefilter_depth.SampleLevel(smp_point_clamp, _881, _851).x; + GTAOConsts param_10 = consts; + float3 _901 = XeGTAO_ComputeViewspacePosition(param_5, param_6, param_7) - _630; + float3 _905 = XeGTAO_ComputeViewspacePosition(param_8, param_9, param_10) - _630; + float _930 = 1.0f + consts.ThinOccluderCompensation; + horizonCos0 = max(horizonCos0, lerp(_792, dot(_901 / length(_901).xxx, _634), clamp((length(float3(_901.xy, _901.z * _930)) * _665) + _670, 0.0f, 1.0f))); + horizonCos1 = max(horizonCos1, lerp(_796, dot(_905 / length(_905).xxx, _634), clamp((length(float3(_905.xy, _905.z * _930)) * _665) + _670, 0.0f, 1.0f))); + } + projectedNormalVecLength = lerp(projectedNormalVecLength, 1.0f, 0.0500000007450580596923828125f); + float param_11 = horizonCos1; + float param_12 = horizonCos0; + float _1000 = XeGTAO_FastACos(param_11) * (-2.0f); + float _1002 = sin(_788); + float _1016 = 2.0f * XeGTAO_FastACos(param_12); + visibility += (projectedNormalVecLength * (0.25f * (((_782 + (_1000 * _1002)) - cos(_1000 - _788)) + ((_782 + (_1016 * _1002)) - cos(_1016 - _788))))); + } + float _1040 = visibility; + float _1050 = max(0.02999999932944774627685546875f, pow(max(0.0f, _1040 / consts.SliceCount), consts.FinalValuePower)); + visibility = _1050; + int2 param_13 = pixCoord; + float param_14 = _1050; + float _1055 = XeGTAO_OutputWorkingTerm(param_13, param_14); + return _1055; + } + + void comp_main() + { + int2 _1064 = int2(gl_GlobalInvocationID.xy); + if (any(bool2(_1064.x >= gtao_ViewportSize.x, _1064.y >= gtao_ViewportSize.y))) + { + return; + } + int2 param = _1064; + GTAOConsts _1261 = { gtao_ViewportPixelSize, gtao_NDCToViewMul, gtao_NDCToViewAdd, gtao_NDCToViewMul_x_PixelSize, gtao_EffectRadius, gtao_EffectFalloffRange, gtao_RadiusMultiplier, gtao_FinalValuePower, gtao_SampleDistributionPower, gtao_ThinOccluderCompensation, gtao_DepthMIPSamplingOffset, gtao_SliceCount, gtao_StepsPerSlice }; + GTAOConsts param_1 = _1261; + int2 _1127 = gtao_ViewportSize - int2(1, 1); + float param_2 = tex_raw_depth.Load(int3(clamp(_1064, int2(0, 0), _1127), 0)).x; + GTAOConsts param_3 = _1261; + float _1141 = XeGTAO_ScreenSpaceToViewSpaceDepth(param_2, param_3); + float param_4 = tex_raw_depth.Load(int3(clamp(_1064 + int2(-1, 0), int2(0, 0), _1127), 0)).x; + GTAOConsts param_5 = _1261; + float param_6 = tex_raw_depth.Load(int3(clamp(_1064 + int2(1, 0), int2(0, 0), _1127), 0)).x; + GTAOConsts param_7 = _1261; + float param_8 = tex_raw_depth.Load(int3(clamp(_1064 + int2(0, -1), int2(0, 0), _1127), 0)).x; + GTAOConsts param_9 = _1261; + float param_10 = tex_raw_depth.Load(int3(clamp(_1064 + int2(0, 1), int2(0, 0), _1127), 0)).x; + GTAOConsts param_11 = _1261; + float param_12 = _1141; + float param_13 = XeGTAO_ScreenSpaceToViewSpaceDepth(param_4, param_5); + float param_14 = XeGTAO_ScreenSpaceToViewSpaceDepth(param_6, param_7); + float param_15 = XeGTAO_ScreenSpaceToViewSpaceDepth(param_8, param_9); + float param_16 = XeGTAO_ScreenSpaceToViewSpaceDepth(param_10, param_11); + uint2 param_17 = uint2(_1064); + int param_18 = 0; + int2 param_19 = _1064; + float2 param_20 = SpatioTemporalNoise(param_17, param_18); + float3 param_21 = XeGTAO_ComputeViewspaceNormal(param, param_1); + float param_22 = _1141; + float4 param_23 = XeGTAO_CalculateEdges(param_12, param_13, param_14, param_15, param_16); + GTAOConsts param_24 = _1261; + float _1232 = XeGTAO_MainPass(param_19, param_20, param_21, param_22, param_23, param_24); + } + + [numthreads(8, 8, 1)] + void main(SPIRV_Cross_Input stage_input) + { + gl_GlobalInvocationID = stage_input.gl_GlobalInvocationID; + comp_main(); + } +*/ +static const uint8_t gtao_main_pass_cs_source_hlsl5[14295] = { + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74, + 0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x56, + 0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x50,0x69,0x78,0x65,0x6c,0x53,0x69,0x7a,0x65, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x4e,0x44,0x43, + 0x54,0x6f,0x56,0x69,0x65,0x77,0x4d,0x75,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x32,0x20,0x4e,0x44,0x43,0x54,0x6f,0x56,0x69,0x65,0x77,0x41, + 0x64,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x4e, + 0x44,0x43,0x54,0x6f,0x56,0x69,0x65,0x77,0x4d,0x75,0x6c,0x5f,0x78,0x5f,0x50,0x69, + 0x78,0x65,0x6c,0x53,0x69,0x7a,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x45,0x66,0x66,0x65,0x63,0x74,0x52,0x61,0x64,0x69,0x75,0x73,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x45,0x66,0x66,0x65,0x63, + 0x74,0x46,0x61,0x6c,0x6c,0x6f,0x66,0x66,0x52,0x61,0x6e,0x67,0x65,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x52,0x61,0x64,0x69,0x75,0x73,0x4d, + 0x75,0x6c,0x74,0x69,0x70,0x6c,0x69,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x46,0x69,0x6e,0x61,0x6c,0x56,0x61,0x6c,0x75,0x65,0x50, + 0x6f,0x77,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x53,0x61,0x6d,0x70,0x6c,0x65,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69, + 0x6f,0x6e,0x50,0x6f,0x77,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x54,0x68,0x69,0x6e,0x4f,0x63,0x63,0x6c,0x75,0x64,0x65,0x72,0x43, + 0x6f,0x6d,0x70,0x65,0x6e,0x73,0x61,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x44,0x65,0x70,0x74,0x68,0x4d,0x49,0x50,0x53, + 0x61,0x6d,0x70,0x6c,0x69,0x6e,0x67,0x4f,0x66,0x66,0x73,0x65,0x74,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x53,0x6c,0x69,0x63,0x65,0x43,0x6f, + 0x75,0x6e,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x53, + 0x74,0x65,0x70,0x73,0x50,0x65,0x72,0x53,0x6c,0x69,0x63,0x65,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x75, + 0x69,0x6e,0x74,0x33,0x20,0x67,0x6c,0x5f,0x57,0x6f,0x72,0x6b,0x47,0x72,0x6f,0x75, + 0x70,0x53,0x69,0x7a,0x65,0x20,0x3d,0x20,0x75,0x69,0x6e,0x74,0x33,0x28,0x38,0x75, + 0x2c,0x20,0x38,0x75,0x2c,0x20,0x31,0x75,0x29,0x3b,0x0a,0x0a,0x63,0x62,0x75,0x66, + 0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x67,0x74,0x61,0x6f,0x20,0x3a,0x20,0x72,0x65, + 0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x6e,0x74,0x32,0x20,0x67,0x74,0x61,0x6f,0x5f,0x56,0x69,0x65,0x77,0x70, + 0x6f,0x72,0x74,0x53,0x69,0x7a,0x65,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66, + 0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x32,0x20,0x67,0x74,0x61,0x6f,0x5f,0x56,0x69,0x65,0x77,0x70,0x6f, + 0x72,0x74,0x50,0x69,0x78,0x65,0x6c,0x53,0x69,0x7a,0x65,0x20,0x3a,0x20,0x70,0x61, + 0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x2e,0x7a,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x67,0x74,0x61,0x6f,0x5f, + 0x4e,0x44,0x43,0x54,0x6f,0x56,0x69,0x65,0x77,0x4d,0x75,0x6c,0x20,0x3a,0x20,0x70, + 0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x67,0x74,0x61,0x6f,0x5f,0x4e, + 0x44,0x43,0x54,0x6f,0x56,0x69,0x65,0x77,0x41,0x64,0x64,0x20,0x3a,0x20,0x70,0x61, + 0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x2e,0x7a,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x67,0x74,0x61,0x6f,0x5f, + 0x4e,0x44,0x43,0x54,0x6f,0x56,0x69,0x65,0x77,0x4d,0x75,0x6c,0x5f,0x78,0x5f,0x50, + 0x69,0x78,0x65,0x6c,0x53,0x69,0x7a,0x65,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f, + 0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x67,0x74,0x61,0x6f,0x5f,0x45,0x66,0x66,0x65,0x63,0x74, + 0x52,0x61,0x64,0x69,0x75,0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66, + 0x73,0x65,0x74,0x28,0x63,0x32,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x67,0x74,0x61,0x6f,0x5f,0x45,0x66,0x66,0x65,0x63,0x74, + 0x46,0x61,0x6c,0x6c,0x6f,0x66,0x66,0x52,0x61,0x6e,0x67,0x65,0x20,0x3a,0x20,0x70, + 0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x32,0x2e,0x77,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x74,0x61,0x6f,0x5f, + 0x52,0x61,0x64,0x69,0x75,0x73,0x4d,0x75,0x6c,0x74,0x69,0x70,0x6c,0x69,0x65,0x72, + 0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x33, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x74,0x61, + 0x6f,0x5f,0x46,0x69,0x6e,0x61,0x6c,0x56,0x61,0x6c,0x75,0x65,0x50,0x6f,0x77,0x65, + 0x72,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63, + 0x33,0x2e,0x79,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x67,0x74,0x61,0x6f,0x5f,0x53,0x61,0x6d,0x70,0x6c,0x65,0x44,0x69,0x73,0x74,0x72, + 0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x50,0x6f,0x77,0x65,0x72,0x20,0x3a,0x20,0x70, + 0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x33,0x2e,0x7a,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x74,0x61,0x6f,0x5f, + 0x54,0x68,0x69,0x6e,0x4f,0x63,0x63,0x6c,0x75,0x64,0x65,0x72,0x43,0x6f,0x6d,0x70, + 0x65,0x6e,0x73,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f, + 0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x33,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x74,0x61,0x6f,0x5f,0x44,0x65,0x70,0x74, + 0x68,0x4d,0x49,0x50,0x53,0x61,0x6d,0x70,0x6c,0x69,0x6e,0x67,0x4f,0x66,0x66,0x73, + 0x65,0x74,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28, + 0x63,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67, + 0x74,0x61,0x6f,0x5f,0x53,0x6c,0x69,0x63,0x65,0x43,0x6f,0x75,0x6e,0x74,0x20,0x3a, + 0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x34,0x2e,0x79, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x74,0x61, + 0x6f,0x5f,0x53,0x74,0x65,0x70,0x73,0x50,0x65,0x72,0x53,0x6c,0x69,0x63,0x65,0x20, + 0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x34,0x2e, + 0x7a,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32, + 0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x72,0x61, + 0x77,0x5f,0x64,0x65,0x70,0x74,0x68,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74, + 0x65,0x72,0x28,0x74,0x30,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53, + 0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x70,0x6f,0x69,0x6e,0x74,0x5f,0x63, + 0x6c,0x61,0x6d,0x70,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28, + 0x73,0x30,0x29,0x3b,0x0a,0x52,0x57,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44, + 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x6f,0x75,0x74,0x5f,0x6e,0x6f,0x69,0x73, + 0x79,0x5f,0x61,0x6f,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28, + 0x75,0x30,0x29,0x3b,0x0a,0x52,0x57,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44, + 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x6f,0x75,0x74,0x5f,0x65,0x64,0x67,0x65, + 0x73,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x75,0x31,0x29, + 0x3b,0x0a,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x70,0x72,0x65,0x66,0x69,0x6c,0x74,0x65, + 0x72,0x5f,0x64,0x65,0x70,0x74,0x68,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74, + 0x65,0x72,0x28,0x74,0x31,0x29,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, + 0x75,0x69,0x6e,0x74,0x33,0x20,0x67,0x6c,0x5f,0x47,0x6c,0x6f,0x62,0x61,0x6c,0x49, + 0x6e,0x76,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x49,0x44,0x3b,0x0a,0x73,0x74,0x72, + 0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, + 0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74, + 0x33,0x20,0x67,0x6c,0x5f,0x47,0x6c,0x6f,0x62,0x61,0x6c,0x49,0x6e,0x76,0x6f,0x63, + 0x61,0x74,0x69,0x6f,0x6e,0x49,0x44,0x20,0x3a,0x20,0x53,0x56,0x5f,0x44,0x69,0x73, + 0x70,0x61,0x74,0x63,0x68,0x54,0x68,0x72,0x65,0x61,0x64,0x49,0x44,0x3b,0x0a,0x7d, + 0x3b,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f, + 0x53,0x63,0x72,0x65,0x65,0x6e,0x53,0x70,0x61,0x63,0x65,0x54,0x6f,0x56,0x69,0x65, + 0x77,0x53,0x70,0x61,0x63,0x65,0x44,0x65,0x70,0x74,0x68,0x28,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x73,0x63,0x72,0x65,0x65,0x6e,0x44,0x65,0x70,0x74,0x68,0x2c,0x20,0x47, + 0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73, + 0x63,0x72,0x65,0x65,0x6e,0x44,0x65,0x70,0x74,0x68,0x3b,0x0a,0x7d,0x0a,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x61,0x6c, + 0x63,0x75,0x6c,0x61,0x74,0x65,0x45,0x64,0x67,0x65,0x73,0x28,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x63,0x65,0x6e,0x74,0x65,0x72,0x5a,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x6c,0x65,0x66,0x74,0x5a,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x69, + 0x67,0x68,0x74,0x5a,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x74,0x6f,0x70,0x5a, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x62,0x6f,0x74,0x74,0x6f,0x6d,0x5a,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31, + 0x36,0x37,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6c,0x65,0x66,0x74, + 0x5a,0x2c,0x20,0x72,0x69,0x67,0x68,0x74,0x5a,0x2c,0x20,0x74,0x6f,0x70,0x5a,0x2c, + 0x20,0x62,0x6f,0x74,0x74,0x6f,0x6d,0x5a,0x29,0x20,0x2d,0x20,0x63,0x65,0x6e,0x74, + 0x65,0x72,0x5a,0x2e,0x78,0x78,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x31,0x37,0x33,0x20,0x3d,0x20,0x5f,0x31,0x36,0x37,0x2e, + 0x79,0x20,0x2d,0x20,0x5f,0x31,0x36,0x37,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x38,0x32,0x20,0x3d,0x20,0x5f,0x31,0x36, + 0x37,0x2e,0x77,0x20,0x2d,0x20,0x5f,0x31,0x36,0x37,0x2e,0x7a,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x31, + 0x2e,0x32,0x35,0x66,0x2e,0x78,0x78,0x78,0x78,0x20,0x2d,0x20,0x28,0x6d,0x69,0x6e, + 0x28,0x61,0x62,0x73,0x28,0x5f,0x31,0x36,0x37,0x29,0x2c,0x20,0x61,0x62,0x73,0x28, + 0x5f,0x31,0x36,0x37,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x31, + 0x37,0x33,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x2c,0x20,0x5f,0x31,0x37,0x33,0x20, + 0x2a,0x20,0x28,0x2d,0x30,0x2e,0x35,0x66,0x29,0x2c,0x20,0x5f,0x31,0x38,0x32,0x20, + 0x2a,0x20,0x30,0x2e,0x35,0x66,0x2c,0x20,0x5f,0x31,0x38,0x32,0x20,0x2a,0x20,0x28, + 0x2d,0x30,0x2e,0x35,0x66,0x29,0x29,0x29,0x29,0x20,0x2f,0x20,0x28,0x63,0x65,0x6e, + 0x74,0x65,0x72,0x5a,0x20,0x2a,0x20,0x30,0x2e,0x30,0x31,0x30,0x39,0x39,0x39,0x39, + 0x39,0x39,0x39,0x34,0x30,0x33,0x39,0x35,0x33,0x35,0x35,0x32,0x32,0x34,0x36,0x30, + 0x39,0x33,0x37,0x35,0x66,0x29,0x2e,0x78,0x78,0x78,0x78,0x29,0x2c,0x20,0x30,0x2e, + 0x30,0x66,0x2e,0x78,0x78,0x78,0x78,0x2c,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78, + 0x78,0x78,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x58, + 0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x6f,0x6d,0x70,0x75,0x74,0x65,0x56,0x69,0x65, + 0x77,0x73,0x70,0x61,0x63,0x65,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x28,0x66, + 0x6c,0x6f,0x61,0x74,0x32,0x20,0x73,0x63,0x72,0x65,0x65,0x6e,0x50,0x6f,0x73,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65, + 0x44,0x65,0x70,0x74,0x68,0x2c,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74, + 0x73,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x28, + 0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x4e,0x44,0x43,0x54,0x6f,0x56,0x69,0x65,0x77, + 0x4d,0x75,0x6c,0x20,0x2a,0x20,0x73,0x63,0x72,0x65,0x65,0x6e,0x50,0x6f,0x73,0x29, + 0x20,0x2b,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x4e,0x44,0x43,0x54,0x6f,0x56, + 0x69,0x65,0x77,0x41,0x64,0x64,0x29,0x20,0x2a,0x20,0x76,0x69,0x65,0x77,0x73,0x70, + 0x61,0x63,0x65,0x44,0x65,0x70,0x74,0x68,0x2c,0x20,0x2d,0x76,0x69,0x65,0x77,0x73, + 0x70,0x61,0x63,0x65,0x44,0x65,0x70,0x74,0x68,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x61,0x6c, + 0x63,0x75,0x6c,0x61,0x74,0x65,0x4e,0x6f,0x72,0x6d,0x61,0x6c,0x28,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x65,0x64,0x67,0x65,0x73,0x4c,0x52,0x54,0x42,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x69,0x78,0x43,0x65,0x6e,0x74,0x65,0x72,0x50, + 0x6f,0x73,0x2c,0x20,0x69,0x6e,0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x70,0x69,0x78,0x4c,0x50,0x6f,0x73,0x2c,0x20,0x69,0x6e,0x6f,0x75,0x74,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x69,0x78,0x52,0x50,0x6f,0x73,0x2c,0x20, + 0x69,0x6e,0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x69,0x78, + 0x54,0x50,0x6f,0x73,0x2c,0x20,0x69,0x6e,0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x70,0x69,0x78,0x42,0x50,0x6f,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x32,0x35,0x36,0x20,0x3d,0x20, + 0x63,0x6c,0x61,0x6d,0x70,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x65,0x64,0x67, + 0x65,0x73,0x4c,0x52,0x54,0x42,0x2e,0x78,0x20,0x2a,0x20,0x65,0x64,0x67,0x65,0x73, + 0x4c,0x52,0x54,0x42,0x2e,0x7a,0x2c,0x20,0x65,0x64,0x67,0x65,0x73,0x4c,0x52,0x54, + 0x42,0x2e,0x7a,0x20,0x2a,0x20,0x65,0x64,0x67,0x65,0x73,0x4c,0x52,0x54,0x42,0x2e, + 0x79,0x2c,0x20,0x65,0x64,0x67,0x65,0x73,0x4c,0x52,0x54,0x42,0x2e,0x79,0x20,0x2a, + 0x20,0x65,0x64,0x67,0x65,0x73,0x4c,0x52,0x54,0x42,0x2e,0x77,0x2c,0x20,0x65,0x64, + 0x67,0x65,0x73,0x4c,0x52,0x54,0x42,0x2e,0x77,0x20,0x2a,0x20,0x65,0x64,0x67,0x65, + 0x73,0x4c,0x52,0x54,0x42,0x2e,0x78,0x29,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x39, + 0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x37,0x36,0x34,0x38,0x32,0x35,0x38,0x32,0x30, + 0x39,0x32,0x32,0x38,0x35,0x31,0x35,0x36,0x32,0x35,0x66,0x2e,0x78,0x78,0x78,0x78, + 0x2c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x78,0x2c,0x20,0x31,0x2e,0x30, + 0x66,0x2e,0x78,0x78,0x78,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x69,0x78, + 0x4c,0x50,0x6f,0x73,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65, + 0x28,0x70,0x69,0x78,0x4c,0x50,0x6f,0x73,0x20,0x2d,0x20,0x70,0x69,0x78,0x43,0x65, + 0x6e,0x74,0x65,0x72,0x50,0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x69, + 0x78,0x52,0x50,0x6f,0x73,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a, + 0x65,0x28,0x70,0x69,0x78,0x52,0x50,0x6f,0x73,0x20,0x2d,0x20,0x70,0x69,0x78,0x43, + 0x65,0x6e,0x74,0x65,0x72,0x50,0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70, + 0x69,0x78,0x54,0x50,0x6f,0x73,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69, + 0x7a,0x65,0x28,0x70,0x69,0x78,0x54,0x50,0x6f,0x73,0x20,0x2d,0x20,0x70,0x69,0x78, + 0x43,0x65,0x6e,0x74,0x65,0x72,0x50,0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x70,0x69,0x78,0x42,0x50,0x6f,0x73,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c, + 0x69,0x7a,0x65,0x28,0x70,0x69,0x78,0x42,0x50,0x6f,0x73,0x20,0x2d,0x20,0x70,0x69, + 0x78,0x43,0x65,0x6e,0x74,0x65,0x72,0x50,0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a, + 0x65,0x28,0x28,0x28,0x28,0x63,0x72,0x6f,0x73,0x73,0x28,0x70,0x69,0x78,0x54,0x50, + 0x6f,0x73,0x2c,0x20,0x70,0x69,0x78,0x4c,0x50,0x6f,0x73,0x29,0x20,0x2a,0x20,0x5f, + 0x32,0x35,0x36,0x2e,0x78,0x29,0x20,0x2b,0x20,0x28,0x63,0x72,0x6f,0x73,0x73,0x28, + 0x70,0x69,0x78,0x52,0x50,0x6f,0x73,0x2c,0x20,0x70,0x69,0x78,0x54,0x50,0x6f,0x73, + 0x29,0x20,0x2a,0x20,0x5f,0x32,0x35,0x36,0x2e,0x79,0x29,0x29,0x20,0x2b,0x20,0x28, + 0x63,0x72,0x6f,0x73,0x73,0x28,0x70,0x69,0x78,0x42,0x50,0x6f,0x73,0x2c,0x20,0x70, + 0x69,0x78,0x52,0x50,0x6f,0x73,0x29,0x20,0x2a,0x20,0x5f,0x32,0x35,0x36,0x2e,0x7a, + 0x29,0x29,0x20,0x2b,0x20,0x28,0x63,0x72,0x6f,0x73,0x73,0x28,0x70,0x69,0x78,0x4c, + 0x50,0x6f,0x73,0x2c,0x20,0x70,0x69,0x78,0x42,0x50,0x6f,0x73,0x29,0x20,0x2a,0x20, + 0x5f,0x32,0x35,0x36,0x2e,0x77,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x6f,0x6d,0x70,0x75, + 0x74,0x65,0x56,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x4e,0x6f,0x72,0x6d,0x61, + 0x6c,0x28,0x69,0x6e,0x74,0x32,0x20,0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x2c, + 0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, + 0x20,0x5f,0x33,0x39,0x34,0x20,0x3d,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28, + 0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66, + 0x2e,0x78,0x78,0x29,0x20,0x2a,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x56,0x69, + 0x65,0x77,0x70,0x6f,0x72,0x74,0x50,0x69,0x78,0x65,0x6c,0x53,0x69,0x7a,0x65,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x5f,0x34,0x30,0x33,0x20,0x3d, + 0x20,0x67,0x74,0x61,0x6f,0x5f,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69, + 0x7a,0x65,0x20,0x2d,0x20,0x69,0x6e,0x74,0x32,0x28,0x31,0x2c,0x20,0x31,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x72,0x61,0x77,0x5f,0x64,0x65,0x70,0x74,0x68, + 0x2e,0x4c,0x6f,0x61,0x64,0x28,0x69,0x6e,0x74,0x33,0x28,0x63,0x6c,0x61,0x6d,0x70, + 0x28,0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x2c,0x20,0x69,0x6e,0x74,0x32,0x28, + 0x30,0x2c,0x20,0x30,0x29,0x2c,0x20,0x5f,0x34,0x30,0x33,0x29,0x2c,0x20,0x30,0x29, + 0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e, + 0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x34,0x35,0x32,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x53,0x63, + 0x72,0x65,0x65,0x6e,0x53,0x70,0x61,0x63,0x65,0x54,0x6f,0x56,0x69,0x65,0x77,0x53, + 0x70,0x61,0x63,0x65,0x44,0x65,0x70,0x74,0x68,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x74, + 0x65,0x78,0x5f,0x72,0x61,0x77,0x5f,0x64,0x65,0x70,0x74,0x68,0x2e,0x4c,0x6f,0x61, + 0x64,0x28,0x69,0x6e,0x74,0x33,0x28,0x63,0x6c,0x61,0x6d,0x70,0x28,0x70,0x69,0x78, + 0x43,0x6f,0x6f,0x72,0x64,0x20,0x2b,0x20,0x69,0x6e,0x74,0x32,0x28,0x2d,0x31,0x2c, + 0x20,0x30,0x29,0x2c,0x20,0x69,0x6e,0x74,0x32,0x28,0x30,0x2c,0x20,0x30,0x29,0x2c, + 0x20,0x5f,0x34,0x30,0x33,0x29,0x2c,0x20,0x30,0x29,0x29,0x2e,0x78,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x36,0x34,0x20,0x3d, + 0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x53,0x63,0x72,0x65,0x65,0x6e,0x53,0x70, + 0x61,0x63,0x65,0x54,0x6f,0x56,0x69,0x65,0x77,0x53,0x70,0x61,0x63,0x65,0x44,0x65, + 0x70,0x74,0x68,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x72, + 0x61,0x77,0x5f,0x64,0x65,0x70,0x74,0x68,0x2e,0x4c,0x6f,0x61,0x64,0x28,0x69,0x6e, + 0x74,0x33,0x28,0x63,0x6c,0x61,0x6d,0x70,0x28,0x70,0x69,0x78,0x43,0x6f,0x6f,0x72, + 0x64,0x20,0x2b,0x20,0x69,0x6e,0x74,0x32,0x28,0x31,0x2c,0x20,0x30,0x29,0x2c,0x20, + 0x69,0x6e,0x74,0x32,0x28,0x30,0x2c,0x20,0x30,0x29,0x2c,0x20,0x5f,0x34,0x30,0x33, + 0x29,0x2c,0x20,0x30,0x29,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54, + 0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35, + 0x20,0x3d,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x37,0x36,0x20,0x3d,0x20,0x58,0x65,0x47,0x54, + 0x41,0x4f,0x5f,0x53,0x63,0x72,0x65,0x65,0x6e,0x53,0x70,0x61,0x63,0x65,0x54,0x6f, + 0x56,0x69,0x65,0x77,0x53,0x70,0x61,0x63,0x65,0x44,0x65,0x70,0x74,0x68,0x28,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x36,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x72,0x61,0x77,0x5f,0x64,0x65, + 0x70,0x74,0x68,0x2e,0x4c,0x6f,0x61,0x64,0x28,0x69,0x6e,0x74,0x33,0x28,0x63,0x6c, + 0x61,0x6d,0x70,0x28,0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x20,0x2b,0x20,0x69, + 0x6e,0x74,0x32,0x28,0x30,0x2c,0x20,0x2d,0x31,0x29,0x2c,0x20,0x69,0x6e,0x74,0x32, + 0x28,0x30,0x2c,0x20,0x30,0x29,0x2c,0x20,0x5f,0x34,0x30,0x33,0x29,0x2c,0x20,0x30, + 0x29,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f, + 0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x34,0x38,0x38,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x53, + 0x63,0x72,0x65,0x65,0x6e,0x53,0x70,0x61,0x63,0x65,0x54,0x6f,0x56,0x69,0x65,0x77, + 0x53,0x70,0x61,0x63,0x65,0x44,0x65,0x70,0x74,0x68,0x28,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20, + 0x3d,0x20,0x74,0x65,0x78,0x5f,0x72,0x61,0x77,0x5f,0x64,0x65,0x70,0x74,0x68,0x2e, + 0x4c,0x6f,0x61,0x64,0x28,0x69,0x6e,0x74,0x33,0x28,0x63,0x6c,0x61,0x6d,0x70,0x28, + 0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x20,0x2b,0x20,0x69,0x6e,0x74,0x32,0x28, + 0x30,0x2c,0x20,0x31,0x29,0x2c,0x20,0x69,0x6e,0x74,0x32,0x28,0x30,0x2c,0x20,0x30, + 0x29,0x2c,0x20,0x5f,0x34,0x30,0x33,0x29,0x2c,0x20,0x30,0x29,0x29,0x2e,0x78,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x30,0x30, + 0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x53,0x63,0x72,0x65,0x65,0x6e, + 0x53,0x70,0x61,0x63,0x65,0x54,0x6f,0x56,0x69,0x65,0x77,0x53,0x70,0x61,0x63,0x65, + 0x44,0x65,0x70,0x74,0x68,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x39,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x5f,0x34, + 0x35,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x5f,0x34,0x36,0x34,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x32,0x20,0x3d,0x20,0x5f,0x34,0x37,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20,0x5f, + 0x34,0x38,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x5f,0x35,0x30,0x30,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x35,0x20,0x3d,0x20,0x5f,0x33,0x39,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d, + 0x20,0x5f,0x34,0x35,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43, + 0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x20,0x3d, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x5f, + 0x33,0x39,0x34,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x2d,0x31, + 0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x20,0x2a,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x73,0x2e,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x50,0x69,0x78,0x65, + 0x6c,0x53,0x69,0x7a,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20,0x5f,0x34,0x36, + 0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74, + 0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x20,0x3d,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x20,0x3d,0x20,0x5f,0x33,0x39,0x34,0x20, + 0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x31,0x2e,0x30,0x66,0x2c,0x20, + 0x30,0x2e,0x30,0x66,0x29,0x20,0x2a,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x56, + 0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x50,0x69,0x78,0x65,0x6c,0x53,0x69,0x7a,0x65, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x32,0x20,0x3d,0x20,0x5f,0x34,0x37,0x36,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x33,0x20,0x3d,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x34,0x20,0x3d,0x20,0x5f,0x33,0x39,0x34,0x20,0x2b,0x20,0x28,0x66,0x6c, + 0x6f,0x61,0x74,0x32,0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x2d,0x31,0x2e,0x30,0x66, + 0x29,0x20,0x2a,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x56,0x69,0x65,0x77,0x70, + 0x6f,0x72,0x74,0x50,0x69,0x78,0x65,0x6c,0x53,0x69,0x7a,0x65,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x35,0x20,0x3d,0x20,0x5f,0x34,0x38,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54, + 0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x36,0x20,0x3d,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37,0x20, + 0x3d,0x20,0x5f,0x33,0x39,0x34,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32, + 0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x20,0x2a,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x73,0x2e,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x50,0x69, + 0x78,0x65,0x6c,0x53,0x69,0x7a,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x38,0x20,0x3d,0x20,0x5f, + 0x35,0x30,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e, + 0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x39,0x20,0x3d,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x30,0x20,0x3d,0x20,0x58,0x65,0x47, + 0x54,0x41,0x4f,0x5f,0x43,0x61,0x6c,0x63,0x75,0x6c,0x61,0x74,0x65,0x45,0x64,0x67, + 0x65,0x73,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x31,0x20,0x3d,0x20,0x58,0x65,0x47,0x54, + 0x41,0x4f,0x5f,0x43,0x6f,0x6d,0x70,0x75,0x74,0x65,0x56,0x69,0x65,0x77,0x73,0x70, + 0x61,0x63,0x65,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x32,0x20,0x3d, + 0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x6f,0x6d,0x70,0x75,0x74,0x65,0x56, + 0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x33,0x33,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x6f,0x6d, + 0x70,0x75,0x74,0x65,0x56,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x50,0x6f,0x73, + 0x69,0x74,0x69,0x6f,0x6e,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41, + 0x4f,0x5f,0x43,0x6f,0x6d,0x70,0x75,0x74,0x65,0x56,0x69,0x65,0x77,0x73,0x70,0x61, + 0x63,0x65,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x28,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x35,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x35,0x20,0x3d,0x20, + 0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x6f,0x6d,0x70,0x75,0x74,0x65,0x56,0x69, + 0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x39,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x35,0x38,0x36,0x20,0x3d, + 0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x61,0x6c,0x63,0x75,0x6c,0x61,0x74, + 0x65,0x4e,0x6f,0x72,0x6d,0x61,0x6c,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x30, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x31,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x33,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x33,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x5f,0x35,0x38,0x36,0x3b,0x0a,0x7d,0x0a,0x0a,0x75,0x69,0x6e,0x74,0x20,0x48,0x69, + 0x6c,0x62,0x65,0x72,0x74,0x49,0x6e,0x64,0x65,0x78,0x28,0x69,0x6e,0x6f,0x75,0x74, + 0x20,0x75,0x69,0x6e,0x74,0x20,0x70,0x6f,0x73,0x58,0x2c,0x20,0x69,0x6e,0x6f,0x75, + 0x74,0x20,0x75,0x69,0x6e,0x74,0x20,0x70,0x6f,0x73,0x59,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x69,0x6e,0x64,0x65,0x78,0x20,0x3d,0x20, + 0x30,0x75,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x20,0x28,0x75,0x69,0x6e, + 0x74,0x20,0x63,0x75,0x72,0x4c,0x65,0x76,0x65,0x6c,0x20,0x3d,0x20,0x33,0x32,0x75, + 0x3b,0x20,0x63,0x75,0x72,0x4c,0x65,0x76,0x65,0x6c,0x20,0x3e,0x20,0x30,0x75,0x3b, + 0x20,0x63,0x75,0x72,0x4c,0x65,0x76,0x65,0x6c,0x20,0x2f,0x3d,0x20,0x32,0x75,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x75, + 0x69,0x6e,0x74,0x20,0x5f,0x33,0x32,0x30,0x20,0x3d,0x20,0x75,0x69,0x6e,0x74,0x28, + 0x28,0x70,0x6f,0x73,0x58,0x20,0x26,0x20,0x63,0x75,0x72,0x4c,0x65,0x76,0x65,0x6c, + 0x29,0x20,0x3e,0x20,0x30,0x75,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x75,0x69,0x6e,0x74,0x20,0x5f,0x33,0x32,0x36,0x20,0x3d,0x20,0x75,0x69,0x6e, + 0x74,0x28,0x28,0x70,0x6f,0x73,0x59,0x20,0x26,0x20,0x63,0x75,0x72,0x4c,0x65,0x76, + 0x65,0x6c,0x29,0x20,0x3e,0x20,0x30,0x75,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x6e,0x64,0x65,0x78,0x20,0x2b,0x3d,0x20,0x28,0x28,0x63,0x75, + 0x72,0x4c,0x65,0x76,0x65,0x6c,0x20,0x2a,0x20,0x63,0x75,0x72,0x4c,0x65,0x76,0x65, + 0x6c,0x29,0x20,0x2a,0x20,0x28,0x28,0x33,0x75,0x20,0x2a,0x20,0x5f,0x33,0x32,0x30, + 0x29,0x20,0x5e,0x20,0x5f,0x33,0x32,0x36,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x33,0x32,0x36,0x20,0x3d,0x3d,0x20, + 0x30,0x75,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x33, + 0x32,0x30,0x20,0x3d,0x3d,0x20,0x31,0x75,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x70,0x6f,0x73,0x58,0x20,0x3d,0x20,0x36, + 0x33,0x75,0x20,0x2d,0x20,0x70,0x6f,0x73,0x58,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x70,0x6f,0x73,0x59,0x20, + 0x3d,0x20,0x36,0x33,0x75,0x20,0x2d,0x20,0x70,0x6f,0x73,0x59,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x5f,0x33,0x35, + 0x31,0x20,0x3d,0x20,0x70,0x6f,0x73,0x58,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x70,0x6f,0x73,0x58,0x20,0x3d,0x20,0x70,0x6f,0x73, + 0x59,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x70, + 0x6f,0x73,0x59,0x20,0x3d,0x20,0x5f,0x33,0x35,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x69,0x6e,0x64,0x65,0x78,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x53,0x70,0x61,0x74,0x69,0x6f,0x54,0x65, + 0x6d,0x70,0x6f,0x72,0x61,0x6c,0x4e,0x6f,0x69,0x73,0x65,0x28,0x75,0x69,0x6e,0x74, + 0x32,0x20,0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x2c,0x20,0x69,0x6e,0x74,0x20, + 0x74,0x65,0x6d,0x70,0x6f,0x72,0x61,0x6c,0x49,0x6e,0x64,0x65,0x78,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20, + 0x3d,0x20,0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d, + 0x20,0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x75,0x69,0x6e,0x74,0x20,0x5f,0x33,0x36,0x36,0x20,0x3d,0x20,0x48,0x69,0x6c, + 0x62,0x65,0x72,0x74,0x49,0x6e,0x64,0x65,0x78,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x72,0x61,0x63,0x28,0x30,0x2e,0x35,0x66,0x2e, + 0x78,0x78,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x30,0x2e,0x37, + 0x35,0x34,0x38,0x37,0x37,0x36,0x38,0x36,0x35,0x30,0x30,0x35,0x34,0x39,0x33,0x31, + 0x36,0x34,0x30,0x36,0x32,0x35,0x66,0x2c,0x20,0x30,0x2e,0x35,0x36,0x39,0x38,0x34, + 0x30,0x33,0x31,0x32,0x30,0x30,0x34,0x30,0x38,0x39,0x33,0x35,0x35,0x34,0x36,0x38, + 0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x33,0x36, + 0x36,0x20,0x2b,0x20,0x28,0x32,0x38,0x38,0x75,0x20,0x2a,0x20,0x28,0x75,0x69,0x6e, + 0x74,0x28,0x74,0x65,0x6d,0x70,0x6f,0x72,0x61,0x6c,0x49,0x6e,0x64,0x65,0x78,0x29, + 0x20,0x25,0x20,0x36,0x34,0x75,0x29,0x29,0x29,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x50,0x61,0x63, + 0x6b,0x45,0x64,0x67,0x65,0x73,0x28,0x69,0x6e,0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x65,0x64,0x67,0x65,0x73,0x4c,0x52,0x54,0x42,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x65,0x64,0x67,0x65,0x73,0x4c,0x52,0x54,0x42,0x20,0x3d, + 0x20,0x72,0x6f,0x75,0x6e,0x64,0x28,0x63,0x6c,0x61,0x6d,0x70,0x28,0x65,0x64,0x67, + 0x65,0x73,0x4c,0x52,0x54,0x42,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78, + 0x78,0x2c,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x78,0x29,0x20,0x2a,0x20, + 0x32,0x2e,0x39,0x30,0x30,0x30,0x30,0x30,0x30,0x39,0x35,0x33,0x36,0x37,0x34,0x33, + 0x31,0x36,0x34,0x30,0x36,0x32,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x64,0x6f,0x74,0x28,0x65,0x64,0x67,0x65,0x73,0x4c, + 0x52,0x54,0x42,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x30,0x2e,0x32,0x35, + 0x30,0x39,0x38,0x30,0x34,0x30,0x36,0x39,0x39,0x39,0x35,0x38,0x38,0x30,0x31,0x32, + 0x36,0x39,0x35,0x33,0x31,0x32,0x35,0x66,0x2c,0x20,0x30,0x2e,0x30,0x36,0x32,0x37, + 0x34,0x35,0x31,0x30,0x31,0x37,0x34,0x39,0x38,0x39,0x37,0x30,0x30,0x33,0x31,0x37, + 0x33,0x38,0x32,0x38,0x31,0x32,0x35,0x66,0x2c,0x20,0x30,0x2e,0x30,0x31,0x35,0x36, + 0x38,0x36,0x32,0x37,0x35,0x34,0x33,0x37,0x34,0x37,0x34,0x32,0x35,0x30,0x37,0x39, + 0x33,0x34,0x35,0x37,0x30,0x33,0x31,0x32,0x35,0x66,0x2c,0x20,0x30,0x2e,0x30,0x30, + 0x33,0x39,0x32,0x31,0x35,0x36,0x38,0x38,0x35,0x39,0x33,0x36,0x38,0x35,0x36,0x32, + 0x36,0x39,0x38,0x33,0x36,0x34,0x32,0x35,0x37,0x38,0x31,0x32,0x35,0x66,0x29,0x29, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x58,0x65,0x47,0x54,0x41, + 0x4f,0x5f,0x46,0x61,0x73,0x74,0x53,0x71,0x72,0x74,0x28,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x78,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x35,0x33,0x32,0x34,0x38,0x37,0x36, + 0x36,0x39,0x20,0x2b,0x20,0x28,0x61,0x73,0x69,0x6e,0x74,0x28,0x78,0x29,0x20,0x3e, + 0x3e,0x20,0x31,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x46,0x61,0x73,0x74,0x41,0x43,0x6f,0x73,0x28, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x69,0x6e,0x58,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x33,0x20,0x3d,0x20,0x61,0x62, + 0x73,0x28,0x69,0x6e,0x58,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x72,0x65,0x73,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x31,0x35,0x36, + 0x35,0x38,0x32,0x39,0x39,0x36,0x32,0x34,0x39,0x31,0x39,0x38,0x39,0x31,0x33,0x35, + 0x37,0x34,0x32,0x31,0x38,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x5f,0x31,0x30,0x33, + 0x29,0x20,0x2b,0x20,0x31,0x2e,0x35,0x37,0x30,0x37,0x39,0x36,0x33,0x37,0x30,0x35, + 0x30,0x36,0x32,0x38,0x36,0x36,0x32,0x31,0x30,0x39,0x33,0x37,0x35,0x66,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20, + 0x3d,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x5f,0x31,0x30,0x33,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x65,0x73,0x20,0x2a,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f, + 0x5f,0x46,0x61,0x73,0x74,0x53,0x71,0x72,0x74,0x28,0x70,0x61,0x72,0x61,0x6d,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x31, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x6e,0x58,0x20,0x3e,0x3d, + 0x20,0x30,0x2e,0x30,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x32,0x31,0x20,0x3d,0x20,0x72,0x65,0x73,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31, + 0x32,0x31,0x20,0x3d,0x20,0x33,0x2e,0x31,0x34,0x31,0x35,0x39,0x32,0x37,0x34,0x31, + 0x30,0x31,0x32,0x35,0x37,0x33,0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x66,0x20,0x2d, + 0x20,0x72,0x65,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x32,0x31,0x3b,0x0a,0x7d,0x0a,0x0a, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x4f,0x75,0x74, + 0x70,0x75,0x74,0x57,0x6f,0x72,0x6b,0x69,0x6e,0x67,0x54,0x65,0x72,0x6d,0x28,0x69, + 0x6e,0x74,0x32,0x20,0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x2c,0x20,0x69,0x6e, + 0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x69,0x73,0x69,0x62,0x69, + 0x6c,0x69,0x74,0x79,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x69,0x73,0x69, + 0x62,0x69,0x6c,0x69,0x74,0x79,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x76, + 0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x20,0x2a,0x20,0x30,0x2e,0x36,0x36, + 0x36,0x36,0x36,0x36,0x36,0x38,0x36,0x35,0x33,0x34,0x38,0x38,0x31,0x35,0x39,0x31, + 0x37,0x39,0x36,0x38,0x37,0x35,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31, + 0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x6e,0x6f, + 0x69,0x73,0x79,0x5f,0x61,0x6f,0x5b,0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x5d, + 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x76,0x69,0x73,0x69,0x62,0x69, + 0x6c,0x69,0x74,0x79,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66, + 0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x76,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x58,0x65,0x47,0x54,0x41, + 0x4f,0x5f,0x4d,0x61,0x69,0x6e,0x50,0x61,0x73,0x73,0x28,0x69,0x6e,0x74,0x32,0x20, + 0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, + 0x20,0x6c,0x6f,0x63,0x61,0x6c,0x4e,0x6f,0x69,0x73,0x65,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x76,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x4e,0x6f,0x72, + 0x6d,0x61,0x6c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x63,0x65,0x6e,0x74,0x65, + 0x72,0x56,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x5a,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x65,0x64,0x67,0x65,0x73,0x4c,0x52,0x54,0x42,0x2c,0x20,0x47, + 0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f, + 0x36,0x31,0x30,0x20,0x3d,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x70,0x69, + 0x78,0x43,0x6f,0x6f,0x72,0x64,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2e,0x78, + 0x78,0x29,0x20,0x2a,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x56,0x69,0x65,0x77, + 0x70,0x6f,0x72,0x74,0x50,0x69,0x78,0x65,0x6c,0x53,0x69,0x7a,0x65,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x69,0x65,0x77,0x73,0x70,0x61, + 0x63,0x65,0x5a,0x20,0x3d,0x20,0x63,0x65,0x6e,0x74,0x65,0x72,0x56,0x69,0x65,0x77, + 0x73,0x70,0x61,0x63,0x65,0x5a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x65,0x64,0x67,0x65,0x73, + 0x4c,0x52,0x54,0x42,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x36,0x31,0x38,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x50,0x61, + 0x63,0x6b,0x45,0x64,0x67,0x65,0x73,0x28,0x70,0x61,0x72,0x61,0x6d,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x65,0x64,0x67,0x65,0x73,0x5b,0x70,0x69, + 0x78,0x43,0x6f,0x6f,0x72,0x64,0x5d,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x28,0x5f,0x36,0x31,0x38,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30, + 0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x32,0x31,0x20,0x3d,0x20,0x76,0x69,0x65, + 0x77,0x73,0x70,0x61,0x63,0x65,0x5a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x36,0x32,0x32,0x20,0x3d,0x20,0x5f,0x36,0x32,0x31,0x20,0x2a, + 0x20,0x30,0x2e,0x39,0x39,0x39,0x39,0x38,0x39,0x39,0x38,0x36,0x34,0x31,0x39,0x36, + 0x37,0x37,0x37,0x33,0x34,0x33,0x37,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x5a,0x20,0x3d,0x20,0x5f,0x36,0x32,0x32, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x36,0x31,0x30,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d, + 0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43, + 0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20, + 0x63,0x6f,0x6e,0x73,0x74,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x5f,0x36,0x33,0x30,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f, + 0x5f,0x43,0x6f,0x6d,0x70,0x75,0x74,0x65,0x56,0x69,0x65,0x77,0x73,0x70,0x61,0x63, + 0x65,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x5f,0x36,0x33,0x34,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a, + 0x65,0x28,0x2d,0x5f,0x36,0x33,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x36,0x35,0x30,0x20,0x3d,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x73,0x2e,0x45,0x66,0x66,0x65,0x63,0x74,0x52,0x61,0x64,0x69,0x75,0x73,0x20,0x2a, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x52,0x61,0x64,0x69,0x75,0x73,0x4d,0x75, + 0x6c,0x74,0x69,0x70,0x6c,0x69,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x36,0x35,0x36,0x20,0x3d,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x73,0x2e,0x45,0x66,0x66,0x65,0x63,0x74,0x46,0x61,0x6c,0x6c,0x6f,0x66,0x66,0x52, + 0x61,0x6e,0x67,0x65,0x20,0x2a,0x20,0x5f,0x36,0x35,0x30,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x36,0x35,0x20,0x3d,0x20,0x28,0x2d, + 0x31,0x2e,0x30,0x66,0x29,0x20,0x2f,0x20,0x5f,0x36,0x35,0x36,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x37,0x30,0x20,0x3d,0x20,0x28, + 0x28,0x5f,0x36,0x35,0x30,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20, + 0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x45,0x66,0x66,0x65,0x63,0x74,0x46,0x61,0x6c, + 0x6c,0x6f,0x66,0x66,0x52,0x61,0x6e,0x67,0x65,0x29,0x29,0x20,0x2f,0x20,0x5f,0x36, + 0x35,0x36,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x39,0x37,0x20,0x3d,0x20,0x5f,0x36,0x35, + 0x30,0x20,0x2f,0x20,0x28,0x76,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x5a,0x2e, + 0x78,0x78,0x20,0x2a,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x4e,0x44,0x43,0x54, + 0x6f,0x56,0x69,0x65,0x77,0x4d,0x75,0x6c,0x5f,0x78,0x5f,0x50,0x69,0x78,0x65,0x6c, + 0x53,0x69,0x7a,0x65,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x76,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x20,0x3d,0x20, + 0x63,0x6c,0x61,0x6d,0x70,0x28,0x28,0x31,0x30,0x2e,0x30,0x66,0x20,0x2d,0x20,0x5f, + 0x36,0x39,0x37,0x29,0x20,0x2a,0x20,0x30,0x2e,0x30,0x30,0x39,0x39,0x39,0x39,0x39, + 0x39,0x39,0x37,0x37,0x36,0x34,0x38,0x32,0x35,0x38,0x32,0x30,0x39,0x32,0x32,0x38, + 0x35,0x31,0x35,0x36,0x32,0x35,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31, + 0x2e,0x30,0x66,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x31,0x30,0x20,0x3d,0x20,0x31,0x2e, + 0x32,0x39,0x39,0x39,0x39,0x39,0x39,0x35,0x32,0x33,0x31,0x36,0x32,0x38,0x34,0x31, + 0x37,0x39,0x36,0x38,0x37,0x35,0x66,0x20,0x2f,0x20,0x5f,0x36,0x39,0x37,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73, + 0x6c,0x69,0x63,0x65,0x20,0x3d,0x20,0x30,0x2e,0x30,0x66,0x3b,0x20,0x73,0x6c,0x69, + 0x63,0x65,0x20,0x3c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x53,0x6c,0x69,0x63, + 0x65,0x43,0x6f,0x75,0x6e,0x74,0x3b,0x20,0x73,0x6c,0x69,0x63,0x65,0x20,0x2b,0x3d, + 0x20,0x31,0x2e,0x30,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x32,0x38,0x20, + 0x3d,0x20,0x28,0x28,0x73,0x6c,0x69,0x63,0x65,0x20,0x2b,0x20,0x6c,0x6f,0x63,0x61, + 0x6c,0x4e,0x6f,0x69,0x73,0x65,0x2e,0x78,0x29,0x20,0x2f,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x73,0x2e,0x53,0x6c,0x69,0x63,0x65,0x43,0x6f,0x75,0x6e,0x74,0x29,0x20,0x2a, + 0x20,0x33,0x2e,0x31,0x34,0x31,0x35,0x39,0x32,0x37,0x34,0x31,0x30,0x31,0x32,0x35, + 0x37,0x33,0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x33,0x31,0x20,0x3d, + 0x20,0x63,0x6f,0x73,0x28,0x5f,0x37,0x32,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x33,0x34,0x20,0x3d, + 0x20,0x73,0x69,0x6e,0x28,0x5f,0x37,0x32,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x37,0x34,0x32,0x20, + 0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37,0x33,0x31,0x2c,0x20,0x2d, + 0x5f,0x37,0x33,0x34,0x29,0x20,0x2a,0x20,0x5f,0x36,0x39,0x37,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x37,0x34, + 0x36,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x37,0x33,0x31,0x2c, + 0x20,0x5f,0x37,0x33,0x34,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x37,0x35, + 0x34,0x20,0x3d,0x20,0x5f,0x37,0x34,0x36,0x20,0x2d,0x20,0x28,0x5f,0x36,0x33,0x34, + 0x20,0x2a,0x20,0x64,0x6f,0x74,0x28,0x5f,0x37,0x34,0x36,0x2c,0x20,0x5f,0x36,0x33, + 0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x5f,0x37,0x35,0x39,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x69,0x7a,0x65,0x28,0x63,0x72,0x6f,0x73,0x73,0x28,0x5f,0x37,0x35,0x34,0x2c, + 0x20,0x5f,0x36,0x33,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x37,0x36,0x37,0x20,0x3d,0x20,0x76, + 0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x4e,0x6f,0x72,0x6d,0x61,0x6c,0x20,0x2d, + 0x20,0x28,0x5f,0x37,0x35,0x39,0x20,0x2a,0x20,0x64,0x6f,0x74,0x28,0x76,0x69,0x65, + 0x77,0x73,0x70,0x61,0x63,0x65,0x4e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x5f,0x37, + 0x35,0x39,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x37,0x37,0x35,0x20,0x3d,0x20,0x6c,0x65,0x6e,0x67,0x74, + 0x68,0x28,0x5f,0x37,0x36,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x72,0x6f,0x6a,0x65,0x63,0x74,0x65,0x64, + 0x4e,0x6f,0x72,0x6d,0x61,0x6c,0x56,0x65,0x63,0x4c,0x65,0x6e,0x67,0x74,0x68,0x20, + 0x3d,0x20,0x5f,0x37,0x37,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x38,0x32,0x20,0x3d,0x20,0x63,0x6c,0x61, + 0x6d,0x70,0x28,0x64,0x6f,0x74,0x28,0x5f,0x37,0x36,0x37,0x2c,0x20,0x5f,0x36,0x33, + 0x34,0x29,0x20,0x2f,0x20,0x5f,0x37,0x37,0x35,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c, + 0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20, + 0x5f,0x37,0x38,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x37,0x38,0x38,0x20,0x3d,0x20,0x73,0x69,0x67,0x6e,0x28, + 0x64,0x6f,0x74,0x28,0x5f,0x37,0x35,0x34,0x2c,0x20,0x5f,0x37,0x36,0x37,0x29,0x29, + 0x20,0x2a,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x46,0x61,0x73,0x74,0x41,0x43, + 0x6f,0x73,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x39,0x32,0x20, + 0x3d,0x20,0x63,0x6f,0x73,0x28,0x5f,0x37,0x38,0x38,0x20,0x2b,0x20,0x31,0x2e,0x35, + 0x37,0x30,0x37,0x39,0x36,0x33,0x37,0x30,0x35,0x30,0x36,0x32,0x38,0x36,0x36,0x32, + 0x31,0x30,0x39,0x33,0x37,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x39,0x36,0x20,0x3d,0x20,0x63, + 0x6f,0x73,0x28,0x5f,0x37,0x38,0x38,0x20,0x2d,0x20,0x31,0x2e,0x35,0x37,0x30,0x37, + 0x39,0x36,0x33,0x37,0x30,0x35,0x30,0x36,0x32,0x38,0x36,0x36,0x32,0x31,0x30,0x39, + 0x33,0x37,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x68,0x6f,0x72,0x69,0x7a,0x6f,0x6e,0x43,0x6f,0x73,0x30, + 0x20,0x3d,0x20,0x5f,0x37,0x39,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x68,0x6f,0x72,0x69,0x7a,0x6f,0x6e,0x43,0x6f, + 0x73,0x31,0x20,0x3d,0x20,0x5f,0x37,0x39,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6f,0x72,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x74, + 0x65,0x70,0x5f,0x20,0x3d,0x20,0x30,0x2e,0x30,0x66,0x3b,0x20,0x73,0x74,0x65,0x70, + 0x5f,0x20,0x3c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x53,0x74,0x65,0x70,0x73, + 0x50,0x65,0x72,0x53,0x6c,0x69,0x63,0x65,0x3b,0x20,0x73,0x74,0x65,0x70,0x5f,0x20, + 0x2b,0x3d,0x20,0x31,0x2e,0x30,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x38,0x33,0x39,0x20,0x3d,0x20,0x5f,0x37,0x34, + 0x32,0x20,0x2a,0x20,0x28,0x70,0x6f,0x77,0x28,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30, + 0x66,0x2c,0x20,0x28,0x73,0x74,0x65,0x70,0x5f,0x20,0x2b,0x20,0x66,0x72,0x61,0x63, + 0x28,0x6c,0x6f,0x63,0x61,0x6c,0x4e,0x6f,0x69,0x73,0x65,0x2e,0x79,0x20,0x2b,0x20, + 0x28,0x28,0x73,0x6c,0x69,0x63,0x65,0x20,0x2b,0x20,0x28,0x73,0x74,0x65,0x70,0x5f, + 0x20,0x2a,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x53,0x74,0x65,0x70,0x73,0x50, + 0x65,0x72,0x53,0x6c,0x69,0x63,0x65,0x29,0x29,0x20,0x2a,0x20,0x30,0x2e,0x36,0x31, + 0x38,0x30,0x33,0x34,0x30,0x30,0x35,0x31,0x36,0x35,0x31,0x30,0x30,0x30,0x39,0x37, + 0x36,0x35,0x36,0x32,0x35,0x66,0x29,0x29,0x29,0x20,0x2f,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x73,0x2e,0x53,0x74,0x65,0x70,0x73,0x50,0x65,0x72,0x53,0x6c,0x69,0x63,0x65, + 0x29,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65, + 0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x50,0x6f,0x77,0x65, + 0x72,0x29,0x20,0x2b,0x20,0x5f,0x37,0x31,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38, + 0x35,0x31,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6c,0x6f,0x67,0x32,0x28, + 0x6c,0x65,0x6e,0x67,0x74,0x68,0x28,0x5f,0x38,0x33,0x39,0x29,0x29,0x20,0x2d,0x20, + 0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x44,0x65,0x70,0x74,0x68,0x4d,0x49,0x50,0x53, + 0x61,0x6d,0x70,0x6c,0x69,0x6e,0x67,0x4f,0x66,0x66,0x73,0x65,0x74,0x2c,0x20,0x30, + 0x2e,0x30,0x66,0x2c,0x20,0x35,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f, + 0x38,0x35,0x36,0x20,0x3d,0x20,0x72,0x6f,0x75,0x6e,0x64,0x28,0x5f,0x38,0x33,0x39, + 0x29,0x20,0x2a,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x56,0x69,0x65,0x77,0x70, + 0x6f,0x72,0x74,0x50,0x69,0x78,0x65,0x6c,0x53,0x69,0x7a,0x65,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, + 0x20,0x5f,0x38,0x36,0x30,0x20,0x3d,0x20,0x5f,0x36,0x31,0x30,0x20,0x2b,0x20,0x5f, + 0x38,0x35,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20, + 0x3d,0x20,0x5f,0x38,0x36,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x36,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x70,0x72,0x65,0x66,0x69,0x6c,0x74,0x65, + 0x72,0x5f,0x64,0x65,0x70,0x74,0x68,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x4c,0x65, + 0x76,0x65,0x6c,0x28,0x73,0x6d,0x70,0x5f,0x70,0x6f,0x69,0x6e,0x74,0x5f,0x63,0x6c, + 0x61,0x6d,0x70,0x2c,0x20,0x5f,0x38,0x36,0x30,0x2c,0x20,0x5f,0x38,0x35,0x31,0x29, + 0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x37,0x20,0x3d,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20, + 0x5f,0x38,0x38,0x31,0x20,0x3d,0x20,0x5f,0x36,0x31,0x30,0x20,0x2d,0x20,0x5f,0x38, + 0x35,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d, + 0x20,0x5f,0x38,0x38,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39, + 0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x70,0x72,0x65,0x66,0x69,0x6c,0x74,0x65,0x72, + 0x5f,0x64,0x65,0x70,0x74,0x68,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x4c,0x65,0x76, + 0x65,0x6c,0x28,0x73,0x6d,0x70,0x5f,0x70,0x6f,0x69,0x6e,0x74,0x5f,0x63,0x6c,0x61, + 0x6d,0x70,0x2c,0x20,0x5f,0x38,0x38,0x31,0x2c,0x20,0x5f,0x38,0x35,0x31,0x29,0x2e, + 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x47, + 0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x30,0x20,0x3d,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x5f,0x39,0x30,0x31,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x6f, + 0x6d,0x70,0x75,0x74,0x65,0x56,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x50,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37, + 0x29,0x20,0x2d,0x20,0x5f,0x36,0x33,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x39,0x30, + 0x35,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x6f,0x6d,0x70,0x75, + 0x74,0x65,0x56,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x50,0x6f,0x73,0x69,0x74, + 0x69,0x6f,0x6e,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x29,0x20, + 0x2d,0x20,0x5f,0x36,0x33,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x33,0x30,0x20,0x3d, + 0x20,0x31,0x2e,0x30,0x66,0x20,0x2b,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x54, + 0x68,0x69,0x6e,0x4f,0x63,0x63,0x6c,0x75,0x64,0x65,0x72,0x43,0x6f,0x6d,0x70,0x65, + 0x6e,0x73,0x61,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x68,0x6f,0x72,0x69,0x7a,0x6f,0x6e,0x43,0x6f,0x73,0x30, + 0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x68,0x6f,0x72,0x69,0x7a,0x6f,0x6e,0x43,0x6f, + 0x73,0x30,0x2c,0x20,0x6c,0x65,0x72,0x70,0x28,0x5f,0x37,0x39,0x32,0x2c,0x20,0x64, + 0x6f,0x74,0x28,0x5f,0x39,0x30,0x31,0x20,0x2f,0x20,0x6c,0x65,0x6e,0x67,0x74,0x68, + 0x28,0x5f,0x39,0x30,0x31,0x29,0x2e,0x78,0x78,0x78,0x2c,0x20,0x5f,0x36,0x33,0x34, + 0x29,0x2c,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x28,0x6c,0x65,0x6e,0x67,0x74,0x68, + 0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x39,0x30,0x31,0x2e,0x78,0x79,0x2c, + 0x20,0x5f,0x39,0x30,0x31,0x2e,0x7a,0x20,0x2a,0x20,0x5f,0x39,0x33,0x30,0x29,0x29, + 0x20,0x2a,0x20,0x5f,0x36,0x36,0x35,0x29,0x20,0x2b,0x20,0x5f,0x36,0x37,0x30,0x2c, + 0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x29,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x68,0x6f,0x72,0x69, + 0x7a,0x6f,0x6e,0x43,0x6f,0x73,0x31,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x68,0x6f, + 0x72,0x69,0x7a,0x6f,0x6e,0x43,0x6f,0x73,0x31,0x2c,0x20,0x6c,0x65,0x72,0x70,0x28, + 0x5f,0x37,0x39,0x36,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x39,0x30,0x35,0x20,0x2f, + 0x20,0x6c,0x65,0x6e,0x67,0x74,0x68,0x28,0x5f,0x39,0x30,0x35,0x29,0x2e,0x78,0x78, + 0x78,0x2c,0x20,0x5f,0x36,0x33,0x34,0x29,0x2c,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28, + 0x28,0x6c,0x65,0x6e,0x67,0x74,0x68,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f, + 0x39,0x30,0x35,0x2e,0x78,0x79,0x2c,0x20,0x5f,0x39,0x30,0x35,0x2e,0x7a,0x20,0x2a, + 0x20,0x5f,0x39,0x33,0x30,0x29,0x29,0x20,0x2a,0x20,0x5f,0x36,0x36,0x35,0x29,0x20, + 0x2b,0x20,0x5f,0x36,0x37,0x30,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e, + 0x30,0x66,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x70,0x72,0x6f,0x6a,0x65,0x63,0x74, + 0x65,0x64,0x4e,0x6f,0x72,0x6d,0x61,0x6c,0x56,0x65,0x63,0x4c,0x65,0x6e,0x67,0x74, + 0x68,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x70,0x72,0x6f,0x6a,0x65,0x63,0x74, + 0x65,0x64,0x4e,0x6f,0x72,0x6d,0x61,0x6c,0x56,0x65,0x63,0x4c,0x65,0x6e,0x67,0x74, + 0x68,0x2c,0x20,0x31,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30,0x35,0x30,0x30,0x30, + 0x30,0x30,0x30,0x30,0x37,0x34,0x35,0x30,0x35,0x38,0x30,0x35,0x39,0x36,0x39,0x32, + 0x33,0x38,0x32,0x38,0x31,0x32,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x31,0x20,0x3d,0x20,0x68,0x6f,0x72,0x69,0x7a,0x6f,0x6e,0x43,0x6f,0x73,0x31,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x68,0x6f,0x72,0x69,0x7a,0x6f, + 0x6e,0x43,0x6f,0x73,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x30,0x30,0x20,0x3d,0x20,0x58,0x65,0x47, + 0x54,0x41,0x4f,0x5f,0x46,0x61,0x73,0x74,0x41,0x43,0x6f,0x73,0x28,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x31,0x29,0x20,0x2a,0x20,0x28,0x2d,0x32,0x2e,0x30,0x66,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x30,0x30,0x32,0x20,0x3d,0x20,0x73,0x69,0x6e,0x28,0x5f,0x37,0x38,0x38, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x30,0x31,0x36,0x20,0x3d,0x20,0x32,0x2e,0x30,0x66,0x20,0x2a,0x20, + 0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x46,0x61,0x73,0x74,0x41,0x43,0x6f,0x73,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x76,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x20,0x2b,0x3d, + 0x20,0x28,0x70,0x72,0x6f,0x6a,0x65,0x63,0x74,0x65,0x64,0x4e,0x6f,0x72,0x6d,0x61, + 0x6c,0x56,0x65,0x63,0x4c,0x65,0x6e,0x67,0x74,0x68,0x20,0x2a,0x20,0x28,0x30,0x2e, + 0x32,0x35,0x66,0x20,0x2a,0x20,0x28,0x28,0x28,0x5f,0x37,0x38,0x32,0x20,0x2b,0x20, + 0x28,0x5f,0x31,0x30,0x30,0x30,0x20,0x2a,0x20,0x5f,0x31,0x30,0x30,0x32,0x29,0x29, + 0x20,0x2d,0x20,0x63,0x6f,0x73,0x28,0x5f,0x31,0x30,0x30,0x30,0x20,0x2d,0x20,0x5f, + 0x37,0x38,0x38,0x29,0x29,0x20,0x2b,0x20,0x28,0x28,0x5f,0x37,0x38,0x32,0x20,0x2b, + 0x20,0x28,0x5f,0x31,0x30,0x31,0x36,0x20,0x2a,0x20,0x5f,0x31,0x30,0x30,0x32,0x29, + 0x29,0x20,0x2d,0x20,0x63,0x6f,0x73,0x28,0x5f,0x31,0x30,0x31,0x36,0x20,0x2d,0x20, + 0x5f,0x37,0x38,0x38,0x29,0x29,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x34,0x30, + 0x20,0x3d,0x20,0x76,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x30,0x20,0x3d, + 0x20,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x32,0x39,0x39,0x39,0x39,0x39,0x39,0x39, + 0x33,0x32,0x39,0x34,0x34,0x37,0x37,0x34,0x36,0x32,0x37,0x36,0x38,0x35,0x35,0x34, + 0x36,0x38,0x37,0x35,0x66,0x2c,0x20,0x70,0x6f,0x77,0x28,0x6d,0x61,0x78,0x28,0x30, + 0x2e,0x30,0x66,0x2c,0x20,0x5f,0x31,0x30,0x34,0x30,0x20,0x2f,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x73,0x2e,0x53,0x6c,0x69,0x63,0x65,0x43,0x6f,0x75,0x6e,0x74,0x29,0x2c, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x46,0x69,0x6e,0x61,0x6c,0x56,0x61,0x6c, + 0x75,0x65,0x50,0x6f,0x77,0x65,0x72,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x20,0x3d,0x20,0x5f,0x31,0x30,0x35, + 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20,0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x34,0x20,0x3d,0x20,0x5f,0x31,0x30,0x35,0x30,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x35,0x20,0x3d,0x20,0x58, + 0x65,0x47,0x54,0x41,0x4f,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x57,0x6f,0x72,0x6b, + 0x69,0x6e,0x67,0x54,0x65,0x72,0x6d,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x30,0x35,0x35,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x63,0x6f,0x6d,0x70,0x5f,0x6d,0x61,0x69,0x6e, + 0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x5f,0x31, + 0x30,0x36,0x34,0x20,0x3d,0x20,0x69,0x6e,0x74,0x32,0x28,0x67,0x6c,0x5f,0x47,0x6c, + 0x6f,0x62,0x61,0x6c,0x49,0x6e,0x76,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x49,0x44, + 0x2e,0x78,0x79,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x61,0x6e, + 0x79,0x28,0x62,0x6f,0x6f,0x6c,0x32,0x28,0x5f,0x31,0x30,0x36,0x34,0x2e,0x78,0x20, + 0x3e,0x3d,0x20,0x67,0x74,0x61,0x6f,0x5f,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74, + 0x53,0x69,0x7a,0x65,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x30,0x36,0x34,0x2e,0x79,0x20, + 0x3e,0x3d,0x20,0x67,0x74,0x61,0x6f,0x5f,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74, + 0x53,0x69,0x7a,0x65,0x2e,0x79,0x29,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x36,0x34,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x5f,0x31,0x32, + 0x36,0x31,0x20,0x3d,0x20,0x7b,0x20,0x67,0x74,0x61,0x6f,0x5f,0x56,0x69,0x65,0x77, + 0x70,0x6f,0x72,0x74,0x50,0x69,0x78,0x65,0x6c,0x53,0x69,0x7a,0x65,0x2c,0x20,0x67, + 0x74,0x61,0x6f,0x5f,0x4e,0x44,0x43,0x54,0x6f,0x56,0x69,0x65,0x77,0x4d,0x75,0x6c, + 0x2c,0x20,0x67,0x74,0x61,0x6f,0x5f,0x4e,0x44,0x43,0x54,0x6f,0x56,0x69,0x65,0x77, + 0x41,0x64,0x64,0x2c,0x20,0x67,0x74,0x61,0x6f,0x5f,0x4e,0x44,0x43,0x54,0x6f,0x56, + 0x69,0x65,0x77,0x4d,0x75,0x6c,0x5f,0x78,0x5f,0x50,0x69,0x78,0x65,0x6c,0x53,0x69, + 0x7a,0x65,0x2c,0x20,0x67,0x74,0x61,0x6f,0x5f,0x45,0x66,0x66,0x65,0x63,0x74,0x52, + 0x61,0x64,0x69,0x75,0x73,0x2c,0x20,0x67,0x74,0x61,0x6f,0x5f,0x45,0x66,0x66,0x65, + 0x63,0x74,0x46,0x61,0x6c,0x6c,0x6f,0x66,0x66,0x52,0x61,0x6e,0x67,0x65,0x2c,0x20, + 0x67,0x74,0x61,0x6f,0x5f,0x52,0x61,0x64,0x69,0x75,0x73,0x4d,0x75,0x6c,0x74,0x69, + 0x70,0x6c,0x69,0x65,0x72,0x2c,0x20,0x67,0x74,0x61,0x6f,0x5f,0x46,0x69,0x6e,0x61, + 0x6c,0x56,0x61,0x6c,0x75,0x65,0x50,0x6f,0x77,0x65,0x72,0x2c,0x20,0x67,0x74,0x61, + 0x6f,0x5f,0x53,0x61,0x6d,0x70,0x6c,0x65,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75, + 0x74,0x69,0x6f,0x6e,0x50,0x6f,0x77,0x65,0x72,0x2c,0x20,0x67,0x74,0x61,0x6f,0x5f, + 0x54,0x68,0x69,0x6e,0x4f,0x63,0x63,0x6c,0x75,0x64,0x65,0x72,0x43,0x6f,0x6d,0x70, + 0x65,0x6e,0x73,0x61,0x74,0x69,0x6f,0x6e,0x2c,0x20,0x67,0x74,0x61,0x6f,0x5f,0x44, + 0x65,0x70,0x74,0x68,0x4d,0x49,0x50,0x53,0x61,0x6d,0x70,0x6c,0x69,0x6e,0x67,0x4f, + 0x66,0x66,0x73,0x65,0x74,0x2c,0x20,0x67,0x74,0x61,0x6f,0x5f,0x53,0x6c,0x69,0x63, + 0x65,0x43,0x6f,0x75,0x6e,0x74,0x2c,0x20,0x67,0x74,0x61,0x6f,0x5f,0x53,0x74,0x65, + 0x70,0x73,0x50,0x65,0x72,0x53,0x6c,0x69,0x63,0x65,0x20,0x7d,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x31,0x32,0x36,0x31,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x5f,0x31,0x31,0x32,0x37,0x20,0x3d,0x20,0x67, + 0x74,0x61,0x6f,0x5f,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65, + 0x20,0x2d,0x20,0x69,0x6e,0x74,0x32,0x28,0x31,0x2c,0x20,0x31,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x72,0x61,0x77,0x5f,0x64,0x65,0x70,0x74,0x68, + 0x2e,0x4c,0x6f,0x61,0x64,0x28,0x69,0x6e,0x74,0x33,0x28,0x63,0x6c,0x61,0x6d,0x70, + 0x28,0x5f,0x31,0x30,0x36,0x34,0x2c,0x20,0x69,0x6e,0x74,0x32,0x28,0x30,0x2c,0x20, + 0x30,0x29,0x2c,0x20,0x5f,0x31,0x31,0x32,0x37,0x29,0x2c,0x20,0x30,0x29,0x29,0x2e, + 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74, + 0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31,0x32,0x36, + 0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31, + 0x34,0x31,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x53,0x63,0x72,0x65, + 0x65,0x6e,0x53,0x70,0x61,0x63,0x65,0x54,0x6f,0x56,0x69,0x65,0x77,0x53,0x70,0x61, + 0x63,0x65,0x44,0x65,0x70,0x74,0x68,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x74, + 0x65,0x78,0x5f,0x72,0x61,0x77,0x5f,0x64,0x65,0x70,0x74,0x68,0x2e,0x4c,0x6f,0x61, + 0x64,0x28,0x69,0x6e,0x74,0x33,0x28,0x63,0x6c,0x61,0x6d,0x70,0x28,0x5f,0x31,0x30, + 0x36,0x34,0x20,0x2b,0x20,0x69,0x6e,0x74,0x32,0x28,0x2d,0x31,0x2c,0x20,0x30,0x29, + 0x2c,0x20,0x69,0x6e,0x74,0x32,0x28,0x30,0x2c,0x20,0x30,0x29,0x2c,0x20,0x5f,0x31, + 0x31,0x32,0x37,0x29,0x2c,0x20,0x30,0x29,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x35,0x20,0x3d,0x20,0x5f,0x31,0x32,0x36,0x31,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d, + 0x20,0x74,0x65,0x78,0x5f,0x72,0x61,0x77,0x5f,0x64,0x65,0x70,0x74,0x68,0x2e,0x4c, + 0x6f,0x61,0x64,0x28,0x69,0x6e,0x74,0x33,0x28,0x63,0x6c,0x61,0x6d,0x70,0x28,0x5f, + 0x31,0x30,0x36,0x34,0x20,0x2b,0x20,0x69,0x6e,0x74,0x32,0x28,0x31,0x2c,0x20,0x30, + 0x29,0x2c,0x20,0x69,0x6e,0x74,0x32,0x28,0x30,0x2c,0x20,0x30,0x29,0x2c,0x20,0x5f, + 0x31,0x31,0x32,0x37,0x29,0x2c,0x20,0x30,0x29,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x5f,0x31,0x32,0x36,0x31,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20, + 0x3d,0x20,0x74,0x65,0x78,0x5f,0x72,0x61,0x77,0x5f,0x64,0x65,0x70,0x74,0x68,0x2e, + 0x4c,0x6f,0x61,0x64,0x28,0x69,0x6e,0x74,0x33,0x28,0x63,0x6c,0x61,0x6d,0x70,0x28, + 0x5f,0x31,0x30,0x36,0x34,0x20,0x2b,0x20,0x69,0x6e,0x74,0x32,0x28,0x30,0x2c,0x20, + 0x2d,0x31,0x29,0x2c,0x20,0x69,0x6e,0x74,0x32,0x28,0x30,0x2c,0x20,0x30,0x29,0x2c, + 0x20,0x5f,0x31,0x31,0x32,0x37,0x29,0x2c,0x20,0x30,0x29,0x29,0x2e,0x78,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x5f,0x31,0x32,0x36,0x31,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x30,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x72,0x61,0x77,0x5f,0x64,0x65,0x70, + 0x74,0x68,0x2e,0x4c,0x6f,0x61,0x64,0x28,0x69,0x6e,0x74,0x33,0x28,0x63,0x6c,0x61, + 0x6d,0x70,0x28,0x5f,0x31,0x30,0x36,0x34,0x20,0x2b,0x20,0x69,0x6e,0x74,0x32,0x28, + 0x30,0x2c,0x20,0x31,0x29,0x2c,0x20,0x69,0x6e,0x74,0x32,0x28,0x30,0x2c,0x20,0x30, + 0x29,0x2c,0x20,0x5f,0x31,0x31,0x32,0x37,0x29,0x2c,0x20,0x30,0x29,0x29,0x2e,0x78, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x5f,0x31,0x32,0x36, + 0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x5f,0x31,0x31,0x34,0x31,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x33,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x53,0x63,0x72,0x65,0x65, + 0x6e,0x53,0x70,0x61,0x63,0x65,0x54,0x6f,0x56,0x69,0x65,0x77,0x53,0x70,0x61,0x63, + 0x65,0x44,0x65,0x70,0x74,0x68,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x58, + 0x65,0x47,0x54,0x41,0x4f,0x5f,0x53,0x63,0x72,0x65,0x65,0x6e,0x53,0x70,0x61,0x63, + 0x65,0x54,0x6f,0x56,0x69,0x65,0x77,0x53,0x70,0x61,0x63,0x65,0x44,0x65,0x70,0x74, + 0x68,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f, + 0x5f,0x53,0x63,0x72,0x65,0x65,0x6e,0x53,0x70,0x61,0x63,0x65,0x54,0x6f,0x56,0x69, + 0x65,0x77,0x53,0x70,0x61,0x63,0x65,0x44,0x65,0x70,0x74,0x68,0x28,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x36,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x53,0x63,0x72,0x65, + 0x65,0x6e,0x53,0x70,0x61,0x63,0x65,0x54,0x6f,0x56,0x69,0x65,0x77,0x53,0x70,0x61, + 0x63,0x65,0x44,0x65,0x70,0x74,0x68,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x75,0x69,0x6e,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x20, + 0x3d,0x20,0x75,0x69,0x6e,0x74,0x32,0x28,0x5f,0x31,0x30,0x36,0x34,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38, + 0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20,0x5f,0x31,0x30,0x36,0x34,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x30,0x20,0x3d,0x20,0x53,0x70,0x61,0x74,0x69,0x6f,0x54,0x65,0x6d, + 0x70,0x6f,0x72,0x61,0x6c,0x4e,0x6f,0x69,0x73,0x65,0x28,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x31,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x6f,0x6d, + 0x70,0x75,0x74,0x65,0x56,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x4e,0x6f,0x72, + 0x6d,0x61,0x6c,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x20,0x3d,0x20,0x5f,0x31,0x31,0x34,0x31,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x33,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x61, + 0x6c,0x63,0x75,0x6c,0x61,0x74,0x65,0x45,0x64,0x67,0x65,0x73,0x28,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x20,0x3d,0x20,0x5f,0x31,0x32,0x36,0x31,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x33,0x32, + 0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x4d,0x61,0x69,0x6e,0x50,0x61, + 0x73,0x73,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x29,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x5b,0x6e,0x75,0x6d,0x74,0x68,0x72,0x65,0x61,0x64,0x73,0x28,0x38, + 0x2c,0x20,0x38,0x2c,0x20,0x31,0x29,0x5d,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61, + 0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49, + 0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x47,0x6c,0x6f,0x62,0x61, + 0x6c,0x49,0x6e,0x76,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x49,0x44,0x20,0x3d,0x20, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x47, + 0x6c,0x6f,0x62,0x61,0x6c,0x49,0x6e,0x76,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x49, + 0x44,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6d,0x70,0x5f,0x6d,0x61,0x69,0x6e, + 0x28,0x29,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + #pragma clang diagnostic ignored "-Wmissing-prototypes" + + #include + #include + + using namespace metal; + + struct GTAOConsts + { + float2 ViewportPixelSize; + float2 NDCToViewMul; + float2 NDCToViewAdd; + float2 NDCToViewMul_x_PixelSize; + float EffectRadius; + float EffectFalloffRange; + float RadiusMultiplier; + float FinalValuePower; + float SampleDistributionPower; + float ThinOccluderCompensation; + float DepthMIPSamplingOffset; + float SliceCount; + float StepsPerSlice; + }; + + struct ub_gtao + { + int2 ViewportSize; + float2 ViewportPixelSize; + float2 NDCToViewMul; + float2 NDCToViewAdd; + float2 NDCToViewMul_x_PixelSize; + float EffectRadius; + float EffectFalloffRange; + float RadiusMultiplier; + float FinalValuePower; + float SampleDistributionPower; + float ThinOccluderCompensation; + float DepthMIPSamplingOffset; + float SliceCount; + float StepsPerSlice; + }; + + constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(8u, 8u, 1u); + + static inline __attribute__((always_inline)) + float XeGTAO_ScreenSpaceToViewSpaceDepth(thread const float& screenDepth, thread const GTAOConsts& consts) + { + return screenDepth; + } + + static inline __attribute__((always_inline)) + float4 XeGTAO_CalculateEdges(thread const float& centerZ, thread const float& leftZ, thread const float& rightZ, thread const float& topZ, thread const float& bottomZ) + { + float4 _167 = float4(leftZ, rightZ, topZ, bottomZ) - float4(centerZ); + float _173 = _167.y - _167.x; + float _182 = _167.w - _167.z; + return fast::clamp(float4(1.25) - (fast::min(abs(_167), abs(_167 + float4(_173 * 0.5, _173 * (-0.5), _182 * 0.5, _182 * (-0.5)))) / float4(centerZ * 0.010999999940395355224609375)), float4(0.0), float4(1.0)); + } + + static inline __attribute__((always_inline)) + float3 XeGTAO_ComputeViewspacePosition(thread const float2& screenPos, thread const float& viewspaceDepth, thread const GTAOConsts& consts) + { + return float3(((consts.NDCToViewMul * screenPos) + consts.NDCToViewAdd) * viewspaceDepth, -viewspaceDepth); + } + + static inline __attribute__((always_inline)) + float3 XeGTAO_CalculateNormal(thread const float4& edgesLRTB, thread const float3& pixCenterPos, thread float3& pixLPos, thread float3& pixRPos, thread float3& pixTPos, thread float3& pixBPos) + { + float4 _256 = fast::clamp(float4(edgesLRTB.x * edgesLRTB.z, edgesLRTB.z * edgesLRTB.y, edgesLRTB.y * edgesLRTB.w, edgesLRTB.w * edgesLRTB.x) + float4(0.00999999977648258209228515625), float4(0.0), float4(1.0)); + pixLPos = fast::normalize(pixLPos - pixCenterPos); + pixRPos = fast::normalize(pixRPos - pixCenterPos); + pixTPos = fast::normalize(pixTPos - pixCenterPos); + pixBPos = fast::normalize(pixBPos - pixCenterPos); + return fast::normalize((((cross(pixTPos, pixLPos) * _256.x) + (cross(pixRPos, pixTPos) * _256.y)) + (cross(pixBPos, pixRPos) * _256.z)) + (cross(pixLPos, pixBPos) * _256.w)); + } + + static inline __attribute__((always_inline)) + float3 XeGTAO_ComputeViewspaceNormal(thread const int2& pixCoord, thread const GTAOConsts& consts, constant ub_gtao& gtao, texture2d tex_raw_depth, sampler smp_point_clamp) + { + float2 _394 = (float2(pixCoord) + float2(0.5)) * consts.ViewportPixelSize; + int2 _403 = gtao.ViewportSize - int2(1); + float param = tex_raw_depth.read(uint2(clamp(pixCoord, int2(0), _403)), 0).x; + GTAOConsts param_1 = consts; + float _452 = XeGTAO_ScreenSpaceToViewSpaceDepth(param, param_1); + float param_2 = tex_raw_depth.read(uint2(clamp(pixCoord + int2(-1, 0), int2(0), _403)), 0).x; + GTAOConsts param_3 = consts; + float _464 = XeGTAO_ScreenSpaceToViewSpaceDepth(param_2, param_3); + float param_4 = tex_raw_depth.read(uint2(clamp(pixCoord + int2(1, 0), int2(0), _403)), 0).x; + GTAOConsts param_5 = consts; + float _476 = XeGTAO_ScreenSpaceToViewSpaceDepth(param_4, param_5); + float param_6 = tex_raw_depth.read(uint2(clamp(pixCoord + int2(0, -1), int2(0), _403)), 0).x; + GTAOConsts param_7 = consts; + float _488 = XeGTAO_ScreenSpaceToViewSpaceDepth(param_6, param_7); + float param_8 = tex_raw_depth.read(uint2(clamp(pixCoord + int2(0, 1), int2(0), _403)), 0).x; + GTAOConsts param_9 = consts; + float _500 = XeGTAO_ScreenSpaceToViewSpaceDepth(param_8, param_9); + float param_10 = _452; + float param_11 = _464; + float param_12 = _476; + float param_13 = _488; + float param_14 = _500; + float2 param_15 = _394; + float param_16 = _452; + GTAOConsts param_17 = consts; + float2 param_18 = _394 + (float2(-1.0, 0.0) * consts.ViewportPixelSize); + float param_19 = _464; + GTAOConsts param_20 = consts; + float2 param_21 = _394 + (float2(1.0, 0.0) * consts.ViewportPixelSize); + float param_22 = _476; + GTAOConsts param_23 = consts; + float2 param_24 = _394 + (float2(0.0, -1.0) * consts.ViewportPixelSize); + float param_25 = _488; + GTAOConsts param_26 = consts; + float2 param_27 = _394 + (float2(0.0, 1.0) * consts.ViewportPixelSize); + float param_28 = _500; + GTAOConsts param_29 = consts; + float4 param_30 = XeGTAO_CalculateEdges(param_10, param_11, param_12, param_13, param_14); + float3 param_31 = XeGTAO_ComputeViewspacePosition(param_15, param_16, param_17); + float3 param_32 = XeGTAO_ComputeViewspacePosition(param_18, param_19, param_20); + float3 param_33 = XeGTAO_ComputeViewspacePosition(param_21, param_22, param_23); + float3 param_34 = XeGTAO_ComputeViewspacePosition(param_24, param_25, param_26); + float3 param_35 = XeGTAO_ComputeViewspacePosition(param_27, param_28, param_29); + float3 _586 = XeGTAO_CalculateNormal(param_30, param_31, param_32, param_33, param_34, param_35); + return _586; + } + + static inline __attribute__((always_inline)) + uint HilbertIndex(thread uint& posX, thread uint& posY) + { + uint index = 0u; + for (uint curLevel = 32u; curLevel > 0u; curLevel /= 2u) + { + uint _320 = uint((posX & curLevel) > 0u); + uint _326 = uint((posY & curLevel) > 0u); + index += ((curLevel * curLevel) * ((3u * _320) ^ _326)); + if (_326 == 0u) + { + if (_320 == 1u) + { + posX = 63u - posX; + posY = 63u - posY; + } + uint _351 = posX; + posX = posY; + posY = _351; + } + } + return index; + } + + static inline __attribute__((always_inline)) + float2 SpatioTemporalNoise(thread const uint2& pixCoord, thread const int& temporalIndex) + { + uint param = pixCoord.x; + uint param_1 = pixCoord.y; + uint _366 = HilbertIndex(param, param_1); + return fract(float2(0.5) + (float2(0.75487768650054931640625, 0.56984031200408935546875) * float(_366 + (288u * (uint(temporalIndex) % 64u))))); + } + + static inline __attribute__((always_inline)) + float XeGTAO_PackEdges(thread float4& edgesLRTB) + { + edgesLRTB = round(fast::clamp(edgesLRTB, float4(0.0), float4(1.0)) * 2.900000095367431640625); + return dot(edgesLRTB, float4(0.2509804069995880126953125, 0.062745101749897003173828125, 0.01568627543747425079345703125, 0.0039215688593685626983642578125)); + } + + static inline __attribute__((always_inline)) + float XeGTAO_FastSqrt(thread const float& x) + { + return as_type(532487669 + (as_type(x) >> 1)); + } + + static inline __attribute__((always_inline)) + float XeGTAO_FastACos(thread const float& inX) + { + float _103 = abs(inX); + float res = ((-0.15658299624919891357421875) * _103) + 1.57079637050628662109375; + float param = 1.0 - _103; + res *= XeGTAO_FastSqrt(param); + float _121; + if (inX >= 0.0) + { + _121 = res; + } + else + { + _121 = 3.1415927410125732421875 - res; + } + return _121; + } + + static inline __attribute__((always_inline)) + float XeGTAO_OutputWorkingTerm(thread const int2& pixCoord, thread float& visibility, texture2d out_noisy_ao) + { + visibility = fast::clamp(visibility * 0.666666686534881591796875, 0.0, 1.0); + out_noisy_ao.write(float4(visibility, 0.0, 0.0, 0.0), uint2(pixCoord)); + return visibility; + } + + static inline __attribute__((always_inline)) + float XeGTAO_MainPass(thread const int2& pixCoord, thread const float2& localNoise, thread const float3& viewspaceNormal, thread const float& centerViewspaceZ, thread const float4& edgesLRTB, thread const GTAOConsts& consts, sampler smp_point_clamp, texture2d out_noisy_ao, texture2d out_edges, texture2d tex_prefilter_depth) + { + float2 _610 = (float2(pixCoord) + float2(0.5)) * consts.ViewportPixelSize; + float viewspaceZ = centerViewspaceZ; + float4 param = edgesLRTB; + float _618 = XeGTAO_PackEdges(param); + out_edges.write(float4(_618, 0.0, 0.0, 0.0), uint2(pixCoord)); + float _621 = viewspaceZ; + float _622 = _621 * 0.999989986419677734375; + viewspaceZ = _622; + float2 param_1 = _610; + float param_2 = _622; + GTAOConsts param_3 = consts; + float3 _630 = XeGTAO_ComputeViewspacePosition(param_1, param_2, param_3); + float3 _634 = fast::normalize(-_630); + float _650 = consts.EffectRadius * consts.RadiusMultiplier; + float _656 = consts.EffectFalloffRange * _650; + float _665 = (-1.0) / _656; + float _670 = ((_650 * (1.0 - consts.EffectFalloffRange)) / _656) + 1.0; + float _697 = _650 / (float2(viewspaceZ) * consts.NDCToViewMul_x_PixelSize).x; + float visibility = fast::clamp((10.0 - _697) * 0.00999999977648258209228515625, 0.0, 1.0) * 0.5; + float _710 = 1.2999999523162841796875 / _697; + for (float slice = 0.0; slice < consts.SliceCount; slice += 1.0) + { + float _728 = ((slice + localNoise.x) / consts.SliceCount) * 3.1415927410125732421875; + float _731 = cos(_728); + float _734 = sin(_728); + float2 _742 = float2(_731, -_734) * _697; + float3 _746 = float3(_731, _734, 0.0); + float3 _754 = _746 - (_634 * dot(_746, _634)); + float3 _759 = fast::normalize(cross(_754, _634)); + float3 _767 = viewspaceNormal - (_759 * dot(viewspaceNormal, _759)); + float _775 = length(_767); + float projectedNormalVecLength = _775; + float _782 = fast::clamp(dot(_767, _634) / _775, 0.0, 1.0); + float param_4 = _782; + float _788 = sign(dot(_754, _767)) * XeGTAO_FastACos(param_4); + float _792 = cos(_788 + 1.57079637050628662109375); + float _796 = cos(_788 - 1.57079637050628662109375); + float horizonCos0 = _792; + float horizonCos1 = _796; + for (float step_ = 0.0; step_ < consts.StepsPerSlice; step_ += 1.0) + { + float2 _839 = _742 * (powr(fast::max(0.0, (step_ + fract(localNoise.y + ((slice + (step_ * consts.StepsPerSlice)) * 0.61803400516510009765625))) / consts.StepsPerSlice), consts.SampleDistributionPower) + _710); + float _851 = fast::clamp(log2(length(_839)) - consts.DepthMIPSamplingOffset, 0.0, 5.0); + float2 _856 = round(_839) * consts.ViewportPixelSize; + float2 _860 = _610 + _856; + float2 param_5 = _860; + float param_6 = tex_prefilter_depth.sample(smp_point_clamp, _860, level(_851)).x; + GTAOConsts param_7 = consts; + float2 _881 = _610 - _856; + float2 param_8 = _881; + float param_9 = tex_prefilter_depth.sample(smp_point_clamp, _881, level(_851)).x; + GTAOConsts param_10 = consts; + float3 _901 = XeGTAO_ComputeViewspacePosition(param_5, param_6, param_7) - _630; + float3 _905 = XeGTAO_ComputeViewspacePosition(param_8, param_9, param_10) - _630; + float _930 = 1.0 + consts.ThinOccluderCompensation; + horizonCos0 = fast::max(horizonCos0, mix(_792, dot(_901 / float3(length(_901)), _634), fast::clamp((length(float3(_901.xy, _901.z * _930)) * _665) + _670, 0.0, 1.0))); + horizonCos1 = fast::max(horizonCos1, mix(_796, dot(_905 / float3(length(_905)), _634), fast::clamp((length(float3(_905.xy, _905.z * _930)) * _665) + _670, 0.0, 1.0))); + } + projectedNormalVecLength = mix(projectedNormalVecLength, 1.0, 0.0500000007450580596923828125); + float param_11 = horizonCos1; + float param_12 = horizonCos0; + float _1000 = XeGTAO_FastACos(param_11) * (-2.0); + float _1002 = sin(_788); + float _1016 = 2.0 * XeGTAO_FastACos(param_12); + visibility += (projectedNormalVecLength * (0.25 * (((_782 + (_1000 * _1002)) - cos(_1000 - _788)) + ((_782 + (_1016 * _1002)) - cos(_1016 - _788))))); + } + float _1040 = visibility; + float _1050 = fast::max(0.02999999932944774627685546875, powr(fast::max(0.0, _1040 / consts.SliceCount), consts.FinalValuePower)); + visibility = _1050; + int2 param_13 = pixCoord; + float param_14 = _1050; + float _1055 = XeGTAO_OutputWorkingTerm(param_13, param_14, out_noisy_ao); + return _1055; + } + + kernel void main0(constant ub_gtao& gtao [[buffer(0)]], texture2d out_noisy_ao [[texture(0)]], texture2d out_edges [[texture(1)]], texture2d tex_raw_depth [[texture(2)]], texture2d tex_prefilter_depth [[texture(3)]], sampler smp_point_clamp [[sampler(0)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]]) + { + int2 _1064 = int2(gl_GlobalInvocationID.xy); + if (any(_1064 >= gtao.ViewportSize)) + { + return; + } + int2 param = _1064; + GTAOConsts _1261 = GTAOConsts{ gtao.ViewportPixelSize, gtao.NDCToViewMul, gtao.NDCToViewAdd, gtao.NDCToViewMul_x_PixelSize, gtao.EffectRadius, gtao.EffectFalloffRange, gtao.RadiusMultiplier, gtao.FinalValuePower, gtao.SampleDistributionPower, gtao.ThinOccluderCompensation, gtao.DepthMIPSamplingOffset, gtao.SliceCount, gtao.StepsPerSlice }; + GTAOConsts param_1 = _1261; + int2 _1127 = gtao.ViewportSize - int2(1); + float param_2 = tex_raw_depth.read(uint2(clamp(_1064, int2(0), _1127)), 0).x; + GTAOConsts param_3 = _1261; + float _1141 = XeGTAO_ScreenSpaceToViewSpaceDepth(param_2, param_3); + float param_4 = tex_raw_depth.read(uint2(clamp(_1064 + int2(-1, 0), int2(0), _1127)), 0).x; + GTAOConsts param_5 = _1261; + float param_6 = tex_raw_depth.read(uint2(clamp(_1064 + int2(1, 0), int2(0), _1127)), 0).x; + GTAOConsts param_7 = _1261; + float param_8 = tex_raw_depth.read(uint2(clamp(_1064 + int2(0, -1), int2(0), _1127)), 0).x; + GTAOConsts param_9 = _1261; + float param_10 = tex_raw_depth.read(uint2(clamp(_1064 + int2(0, 1), int2(0), _1127)), 0).x; + GTAOConsts param_11 = _1261; + float param_12 = _1141; + float param_13 = XeGTAO_ScreenSpaceToViewSpaceDepth(param_4, param_5); + float param_14 = XeGTAO_ScreenSpaceToViewSpaceDepth(param_6, param_7); + float param_15 = XeGTAO_ScreenSpaceToViewSpaceDepth(param_8, param_9); + float param_16 = XeGTAO_ScreenSpaceToViewSpaceDepth(param_10, param_11); + uint2 param_17 = uint2(_1064); + int param_18 = 0; + int2 param_19 = _1064; + float2 param_20 = SpatioTemporalNoise(param_17, param_18); + float3 param_21 = XeGTAO_ComputeViewspaceNormal(param, param_1, gtao, tex_raw_depth, smp_point_clamp); + float param_22 = _1141; + float4 param_23 = XeGTAO_CalculateEdges(param_12, param_13, param_14, param_15, param_16); + GTAOConsts param_24 = _1261; + float _1232 = XeGTAO_MainPass(param_19, param_20, param_21, param_22, param_23, param_24, smp_point_clamp, out_noisy_ao, out_edges, tex_prefilter_depth); + } + +*/ +static const uint8_t gtao_main_pass_cs_source_metal_macos[15327] = { + 0x23,0x70,0x72,0x61,0x67,0x6d,0x61,0x20,0x63,0x6c,0x61,0x6e,0x67,0x20,0x64,0x69, + 0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x20,0x69,0x67,0x6e,0x6f,0x72,0x65,0x64, + 0x20,0x22,0x2d,0x57,0x6d,0x69,0x73,0x73,0x69,0x6e,0x67,0x2d,0x70,0x72,0x6f,0x74, + 0x6f,0x74,0x79,0x70,0x65,0x73,0x22,0x0a,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64, + 0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f,0x73,0x74,0x64,0x6c,0x69,0x62,0x3e, + 0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f, + 0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a,0x75,0x73,0x69,0x6e,0x67,0x20,0x6e, + 0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20,0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a, + 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73, + 0x74,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20, + 0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x50,0x69,0x78,0x65,0x6c,0x53,0x69,0x7a, + 0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x4e,0x44, + 0x43,0x54,0x6f,0x56,0x69,0x65,0x77,0x4d,0x75,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x4e,0x44,0x43,0x54,0x6f,0x56,0x69,0x65,0x77, + 0x41,0x64,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20, + 0x4e,0x44,0x43,0x54,0x6f,0x56,0x69,0x65,0x77,0x4d,0x75,0x6c,0x5f,0x78,0x5f,0x50, + 0x69,0x78,0x65,0x6c,0x53,0x69,0x7a,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x45,0x66,0x66,0x65,0x63,0x74,0x52,0x61,0x64,0x69,0x75,0x73, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x45,0x66,0x66,0x65, + 0x63,0x74,0x46,0x61,0x6c,0x6c,0x6f,0x66,0x66,0x52,0x61,0x6e,0x67,0x65,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x52,0x61,0x64,0x69,0x75,0x73, + 0x4d,0x75,0x6c,0x74,0x69,0x70,0x6c,0x69,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x46,0x69,0x6e,0x61,0x6c,0x56,0x61,0x6c,0x75,0x65, + 0x50,0x6f,0x77,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74, + 0x69,0x6f,0x6e,0x50,0x6f,0x77,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x54,0x68,0x69,0x6e,0x4f,0x63,0x63,0x6c,0x75,0x64,0x65,0x72, + 0x43,0x6f,0x6d,0x70,0x65,0x6e,0x73,0x61,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x44,0x65,0x70,0x74,0x68,0x4d,0x49,0x50, + 0x53,0x61,0x6d,0x70,0x6c,0x69,0x6e,0x67,0x4f,0x66,0x66,0x73,0x65,0x74,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x53,0x6c,0x69,0x63,0x65,0x43, + 0x6f,0x75,0x6e,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x53,0x74,0x65,0x70,0x73,0x50,0x65,0x72,0x53,0x6c,0x69,0x63,0x65,0x3b,0x0a,0x7d, + 0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x67,0x74,0x61, + 0x6f,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x56,0x69,0x65, + 0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x32,0x20,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x50,0x69, + 0x78,0x65,0x6c,0x53,0x69,0x7a,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x32,0x20,0x4e,0x44,0x43,0x54,0x6f,0x56,0x69,0x65,0x77,0x4d,0x75,0x6c, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x4e,0x44,0x43, + 0x54,0x6f,0x56,0x69,0x65,0x77,0x41,0x64,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x32,0x20,0x4e,0x44,0x43,0x54,0x6f,0x56,0x69,0x65,0x77,0x4d, + 0x75,0x6c,0x5f,0x78,0x5f,0x50,0x69,0x78,0x65,0x6c,0x53,0x69,0x7a,0x65,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x45,0x66,0x66,0x65,0x63,0x74, + 0x52,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x45,0x66,0x66,0x65,0x63,0x74,0x46,0x61,0x6c,0x6c,0x6f,0x66,0x66,0x52, + 0x61,0x6e,0x67,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x52,0x61,0x64,0x69,0x75,0x73,0x4d,0x75,0x6c,0x74,0x69,0x70,0x6c,0x69,0x65,0x72, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x46,0x69,0x6e,0x61, + 0x6c,0x56,0x61,0x6c,0x75,0x65,0x50,0x6f,0x77,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x44,0x69,0x73, + 0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x50,0x6f,0x77,0x65,0x72,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x54,0x68,0x69,0x6e,0x4f,0x63, + 0x63,0x6c,0x75,0x64,0x65,0x72,0x43,0x6f,0x6d,0x70,0x65,0x6e,0x73,0x61,0x74,0x69, + 0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x44,0x65, + 0x70,0x74,0x68,0x4d,0x49,0x50,0x53,0x61,0x6d,0x70,0x6c,0x69,0x6e,0x67,0x4f,0x66, + 0x66,0x73,0x65,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x53,0x6c,0x69,0x63,0x65,0x43,0x6f,0x75,0x6e,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x53,0x74,0x65,0x70,0x73,0x50,0x65,0x72,0x53,0x6c, + 0x69,0x63,0x65,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e, + 0x74,0x20,0x75,0x69,0x6e,0x74,0x33,0x20,0x67,0x6c,0x5f,0x57,0x6f,0x72,0x6b,0x47, + 0x72,0x6f,0x75,0x70,0x53,0x69,0x7a,0x65,0x20,0x5b,0x5b,0x6d,0x61,0x79,0x62,0x65, + 0x5f,0x75,0x6e,0x75,0x73,0x65,0x64,0x5d,0x5d,0x20,0x3d,0x20,0x75,0x69,0x6e,0x74, + 0x33,0x28,0x38,0x75,0x2c,0x20,0x38,0x75,0x2c,0x20,0x31,0x75,0x29,0x3b,0x0a,0x0a, + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f, + 0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77, + 0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x53,0x63,0x72,0x65,0x65,0x6e, + 0x53,0x70,0x61,0x63,0x65,0x54,0x6f,0x56,0x69,0x65,0x77,0x53,0x70,0x61,0x63,0x65, + 0x44,0x65,0x70,0x74,0x68,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x73,0x63,0x72,0x65,0x65,0x6e, + 0x44,0x65,0x70,0x74,0x68,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x26,0x20, + 0x63,0x6f,0x6e,0x73,0x74,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x73,0x63,0x72,0x65,0x65,0x6e,0x44,0x65,0x70,0x74,0x68, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69, + 0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f, + 0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29, + 0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f, + 0x43,0x61,0x6c,0x63,0x75,0x6c,0x61,0x74,0x65,0x45,0x64,0x67,0x65,0x73,0x28,0x74, + 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x26,0x20,0x63,0x65,0x6e,0x74,0x65,0x72,0x5a,0x2c,0x20,0x74,0x68,0x72,0x65, + 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20, + 0x6c,0x65,0x66,0x74,0x5a,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x72,0x69,0x67,0x68,0x74, + 0x5a,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x74,0x6f,0x70,0x5a,0x2c,0x20,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26, + 0x20,0x62,0x6f,0x74,0x74,0x6f,0x6d,0x5a,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x36,0x37,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x6c,0x65,0x66,0x74,0x5a,0x2c,0x20,0x72,0x69,0x67,0x68, + 0x74,0x5a,0x2c,0x20,0x74,0x6f,0x70,0x5a,0x2c,0x20,0x62,0x6f,0x74,0x74,0x6f,0x6d, + 0x5a,0x29,0x20,0x2d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x63,0x65,0x6e,0x74, + 0x65,0x72,0x5a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x37,0x33,0x20,0x3d,0x20,0x5f,0x31,0x36,0x37,0x2e,0x79,0x20,0x2d,0x20, + 0x5f,0x31,0x36,0x37,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x31,0x38,0x32,0x20,0x3d,0x20,0x5f,0x31,0x36,0x37,0x2e,0x77,0x20, + 0x2d,0x20,0x5f,0x31,0x36,0x37,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70, + 0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x31,0x2e,0x32,0x35,0x29,0x20,0x2d,0x20, + 0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x69,0x6e,0x28,0x61,0x62,0x73,0x28,0x5f, + 0x31,0x36,0x37,0x29,0x2c,0x20,0x61,0x62,0x73,0x28,0x5f,0x31,0x36,0x37,0x20,0x2b, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x37,0x33,0x20,0x2a,0x20,0x30, + 0x2e,0x35,0x2c,0x20,0x5f,0x31,0x37,0x33,0x20,0x2a,0x20,0x28,0x2d,0x30,0x2e,0x35, + 0x29,0x2c,0x20,0x5f,0x31,0x38,0x32,0x20,0x2a,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f, + 0x31,0x38,0x32,0x20,0x2a,0x20,0x28,0x2d,0x30,0x2e,0x35,0x29,0x29,0x29,0x29,0x20, + 0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x63,0x65,0x6e,0x74,0x65,0x72,0x5a, + 0x20,0x2a,0x20,0x30,0x2e,0x30,0x31,0x30,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x34, + 0x30,0x33,0x39,0x35,0x33,0x35,0x35,0x32,0x32,0x34,0x36,0x30,0x39,0x33,0x37,0x35, + 0x29,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x30,0x2e,0x30,0x29,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x31,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20, + 0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61, + 0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x6f,0x6d, + 0x70,0x75,0x74,0x65,0x56,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x50,0x6f,0x73, + 0x69,0x74,0x69,0x6f,0x6e,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x26,0x20,0x73,0x63,0x72,0x65,0x65, + 0x6e,0x50,0x6f,0x73,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x76,0x69,0x65,0x77,0x73,0x70, + 0x61,0x63,0x65,0x44,0x65,0x70,0x74,0x68,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74, + 0x73,0x26,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28, + 0x28,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x4e,0x44,0x43,0x54,0x6f,0x56,0x69,0x65, + 0x77,0x4d,0x75,0x6c,0x20,0x2a,0x20,0x73,0x63,0x72,0x65,0x65,0x6e,0x50,0x6f,0x73, + 0x29,0x20,0x2b,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x4e,0x44,0x43,0x54,0x6f, + 0x56,0x69,0x65,0x77,0x41,0x64,0x64,0x29,0x20,0x2a,0x20,0x76,0x69,0x65,0x77,0x73, + 0x70,0x61,0x63,0x65,0x44,0x65,0x70,0x74,0x68,0x2c,0x20,0x2d,0x76,0x69,0x65,0x77, + 0x73,0x70,0x61,0x63,0x65,0x44,0x65,0x70,0x74,0x68,0x29,0x3b,0x0a,0x7d,0x0a,0x0a, + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f, + 0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77, + 0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x61,0x6c,0x63,0x75, + 0x6c,0x61,0x74,0x65,0x4e,0x6f,0x72,0x6d,0x61,0x6c,0x28,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x26,0x20, + 0x65,0x64,0x67,0x65,0x73,0x4c,0x52,0x54,0x42,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20, + 0x70,0x69,0x78,0x43,0x65,0x6e,0x74,0x65,0x72,0x50,0x6f,0x73,0x2c,0x20,0x74,0x68, + 0x72,0x65,0x61,0x64,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x70,0x69,0x78, + 0x4c,0x50,0x6f,0x73,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x26,0x20,0x70,0x69,0x78,0x52,0x50,0x6f,0x73,0x2c,0x20,0x74,0x68, + 0x72,0x65,0x61,0x64,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x70,0x69,0x78, + 0x54,0x50,0x6f,0x73,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x26,0x20,0x70,0x69,0x78,0x42,0x50,0x6f,0x73,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x32,0x35,0x36,0x20, + 0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x65,0x64,0x67,0x65,0x73,0x4c,0x52,0x54,0x42,0x2e,0x78, + 0x20,0x2a,0x20,0x65,0x64,0x67,0x65,0x73,0x4c,0x52,0x54,0x42,0x2e,0x7a,0x2c,0x20, + 0x65,0x64,0x67,0x65,0x73,0x4c,0x52,0x54,0x42,0x2e,0x7a,0x20,0x2a,0x20,0x65,0x64, + 0x67,0x65,0x73,0x4c,0x52,0x54,0x42,0x2e,0x79,0x2c,0x20,0x65,0x64,0x67,0x65,0x73, + 0x4c,0x52,0x54,0x42,0x2e,0x79,0x20,0x2a,0x20,0x65,0x64,0x67,0x65,0x73,0x4c,0x52, + 0x54,0x42,0x2e,0x77,0x2c,0x20,0x65,0x64,0x67,0x65,0x73,0x4c,0x52,0x54,0x42,0x2e, + 0x77,0x20,0x2a,0x20,0x65,0x64,0x67,0x65,0x73,0x4c,0x52,0x54,0x42,0x2e,0x78,0x29, + 0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x30,0x2e,0x30,0x30,0x39,0x39, + 0x39,0x39,0x39,0x39,0x39,0x37,0x37,0x36,0x34,0x38,0x32,0x35,0x38,0x32,0x30,0x39, + 0x32,0x32,0x38,0x35,0x31,0x35,0x36,0x32,0x35,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x28,0x30,0x2e,0x30,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, + 0x31,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x69,0x78,0x4c,0x50, + 0x6f,0x73,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x69,0x7a,0x65,0x28,0x70,0x69,0x78,0x4c,0x50,0x6f,0x73,0x20,0x2d,0x20,0x70, + 0x69,0x78,0x43,0x65,0x6e,0x74,0x65,0x72,0x50,0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x70,0x69,0x78,0x52,0x50,0x6f,0x73,0x20,0x3d,0x20,0x66,0x61,0x73,0x74, + 0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x70,0x69,0x78,0x52, + 0x50,0x6f,0x73,0x20,0x2d,0x20,0x70,0x69,0x78,0x43,0x65,0x6e,0x74,0x65,0x72,0x50, + 0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x69,0x78,0x54,0x50,0x6f,0x73, + 0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69, + 0x7a,0x65,0x28,0x70,0x69,0x78,0x54,0x50,0x6f,0x73,0x20,0x2d,0x20,0x70,0x69,0x78, + 0x43,0x65,0x6e,0x74,0x65,0x72,0x50,0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x70,0x69,0x78,0x42,0x50,0x6f,0x73,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a, + 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x70,0x69,0x78,0x42,0x50,0x6f, + 0x73,0x20,0x2d,0x20,0x70,0x69,0x78,0x43,0x65,0x6e,0x74,0x65,0x72,0x50,0x6f,0x73, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x61, + 0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x28,0x28, + 0x28,0x63,0x72,0x6f,0x73,0x73,0x28,0x70,0x69,0x78,0x54,0x50,0x6f,0x73,0x2c,0x20, + 0x70,0x69,0x78,0x4c,0x50,0x6f,0x73,0x29,0x20,0x2a,0x20,0x5f,0x32,0x35,0x36,0x2e, + 0x78,0x29,0x20,0x2b,0x20,0x28,0x63,0x72,0x6f,0x73,0x73,0x28,0x70,0x69,0x78,0x52, + 0x50,0x6f,0x73,0x2c,0x20,0x70,0x69,0x78,0x54,0x50,0x6f,0x73,0x29,0x20,0x2a,0x20, + 0x5f,0x32,0x35,0x36,0x2e,0x79,0x29,0x29,0x20,0x2b,0x20,0x28,0x63,0x72,0x6f,0x73, + 0x73,0x28,0x70,0x69,0x78,0x42,0x50,0x6f,0x73,0x2c,0x20,0x70,0x69,0x78,0x52,0x50, + 0x6f,0x73,0x29,0x20,0x2a,0x20,0x5f,0x32,0x35,0x36,0x2e,0x7a,0x29,0x29,0x20,0x2b, + 0x20,0x28,0x63,0x72,0x6f,0x73,0x73,0x28,0x70,0x69,0x78,0x4c,0x50,0x6f,0x73,0x2c, + 0x20,0x70,0x69,0x78,0x42,0x50,0x6f,0x73,0x29,0x20,0x2a,0x20,0x5f,0x32,0x35,0x36, + 0x2e,0x77,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, + 0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75, + 0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c, + 0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x58,0x65,0x47, + 0x54,0x41,0x4f,0x5f,0x43,0x6f,0x6d,0x70,0x75,0x74,0x65,0x56,0x69,0x65,0x77,0x73, + 0x70,0x61,0x63,0x65,0x4e,0x6f,0x72,0x6d,0x61,0x6c,0x28,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x69,0x6e,0x74,0x32,0x26,0x20,0x70,0x69, + 0x78,0x43,0x6f,0x6f,0x72,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x26, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e, + 0x74,0x20,0x75,0x62,0x5f,0x67,0x74,0x61,0x6f,0x26,0x20,0x67,0x74,0x61,0x6f,0x2c, + 0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74, + 0x3e,0x20,0x74,0x65,0x78,0x5f,0x72,0x61,0x77,0x5f,0x64,0x65,0x70,0x74,0x68,0x2c, + 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x70,0x6f,0x69, + 0x6e,0x74,0x5f,0x63,0x6c,0x61,0x6d,0x70,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x33,0x39,0x34,0x20,0x3d,0x20,0x28,0x66, + 0x6c,0x6f,0x61,0x74,0x32,0x28,0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x29,0x20, + 0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2a, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74, + 0x50,0x69,0x78,0x65,0x6c,0x53,0x69,0x7a,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x6e,0x74,0x32,0x20,0x5f,0x34,0x30,0x33,0x20,0x3d,0x20,0x67,0x74,0x61,0x6f,0x2e, + 0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65,0x20,0x2d,0x20,0x69, + 0x6e,0x74,0x32,0x28,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x72,0x61, + 0x77,0x5f,0x64,0x65,0x70,0x74,0x68,0x2e,0x72,0x65,0x61,0x64,0x28,0x75,0x69,0x6e, + 0x74,0x32,0x28,0x63,0x6c,0x61,0x6d,0x70,0x28,0x70,0x69,0x78,0x43,0x6f,0x6f,0x72, + 0x64,0x2c,0x20,0x69,0x6e,0x74,0x32,0x28,0x30,0x29,0x2c,0x20,0x5f,0x34,0x30,0x33, + 0x29,0x29,0x2c,0x20,0x30,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54, + 0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x20,0x3d,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x35,0x32,0x20,0x3d,0x20,0x58,0x65,0x47,0x54, + 0x41,0x4f,0x5f,0x53,0x63,0x72,0x65,0x65,0x6e,0x53,0x70,0x61,0x63,0x65,0x54,0x6f, + 0x56,0x69,0x65,0x77,0x53,0x70,0x61,0x63,0x65,0x44,0x65,0x70,0x74,0x68,0x28,0x70, + 0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x72,0x61,0x77,0x5f,0x64,0x65,0x70,0x74, + 0x68,0x2e,0x72,0x65,0x61,0x64,0x28,0x75,0x69,0x6e,0x74,0x32,0x28,0x63,0x6c,0x61, + 0x6d,0x70,0x28,0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x20,0x2b,0x20,0x69,0x6e, + 0x74,0x32,0x28,0x2d,0x31,0x2c,0x20,0x30,0x29,0x2c,0x20,0x69,0x6e,0x74,0x32,0x28, + 0x30,0x29,0x2c,0x20,0x5f,0x34,0x30,0x33,0x29,0x29,0x2c,0x20,0x30,0x29,0x2e,0x78, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x36, + 0x34,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x53,0x63,0x72,0x65,0x65, + 0x6e,0x53,0x70,0x61,0x63,0x65,0x54,0x6f,0x56,0x69,0x65,0x77,0x53,0x70,0x61,0x63, + 0x65,0x44,0x65,0x70,0x74,0x68,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x74,0x65, + 0x78,0x5f,0x72,0x61,0x77,0x5f,0x64,0x65,0x70,0x74,0x68,0x2e,0x72,0x65,0x61,0x64, + 0x28,0x75,0x69,0x6e,0x74,0x32,0x28,0x63,0x6c,0x61,0x6d,0x70,0x28,0x70,0x69,0x78, + 0x43,0x6f,0x6f,0x72,0x64,0x20,0x2b,0x20,0x69,0x6e,0x74,0x32,0x28,0x31,0x2c,0x20, + 0x30,0x29,0x2c,0x20,0x69,0x6e,0x74,0x32,0x28,0x30,0x29,0x2c,0x20,0x5f,0x34,0x30, + 0x33,0x29,0x29,0x2c,0x20,0x30,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47, + 0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x35,0x20,0x3d,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x37,0x36,0x20,0x3d,0x20,0x58,0x65,0x47, + 0x54,0x41,0x4f,0x5f,0x53,0x63,0x72,0x65,0x65,0x6e,0x53,0x70,0x61,0x63,0x65,0x54, + 0x6f,0x56,0x69,0x65,0x77,0x53,0x70,0x61,0x63,0x65,0x44,0x65,0x70,0x74,0x68,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x72,0x61,0x77,0x5f,0x64, + 0x65,0x70,0x74,0x68,0x2e,0x72,0x65,0x61,0x64,0x28,0x75,0x69,0x6e,0x74,0x32,0x28, + 0x63,0x6c,0x61,0x6d,0x70,0x28,0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x20,0x2b, + 0x20,0x69,0x6e,0x74,0x32,0x28,0x30,0x2c,0x20,0x2d,0x31,0x29,0x2c,0x20,0x69,0x6e, + 0x74,0x32,0x28,0x30,0x29,0x2c,0x20,0x5f,0x34,0x30,0x33,0x29,0x29,0x2c,0x20,0x30, + 0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e, + 0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x34,0x38,0x38,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x53,0x63, + 0x72,0x65,0x65,0x6e,0x53,0x70,0x61,0x63,0x65,0x54,0x6f,0x56,0x69,0x65,0x77,0x53, + 0x70,0x61,0x63,0x65,0x44,0x65,0x70,0x74,0x68,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d, + 0x20,0x74,0x65,0x78,0x5f,0x72,0x61,0x77,0x5f,0x64,0x65,0x70,0x74,0x68,0x2e,0x72, + 0x65,0x61,0x64,0x28,0x75,0x69,0x6e,0x74,0x32,0x28,0x63,0x6c,0x61,0x6d,0x70,0x28, + 0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x20,0x2b,0x20,0x69,0x6e,0x74,0x32,0x28, + 0x30,0x2c,0x20,0x31,0x29,0x2c,0x20,0x69,0x6e,0x74,0x32,0x28,0x30,0x29,0x2c,0x20, + 0x5f,0x34,0x30,0x33,0x29,0x29,0x2c,0x20,0x30,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x30,0x30,0x20,0x3d,0x20, + 0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x53,0x63,0x72,0x65,0x65,0x6e,0x53,0x70,0x61, + 0x63,0x65,0x54,0x6f,0x56,0x69,0x65,0x77,0x53,0x70,0x61,0x63,0x65,0x44,0x65,0x70, + 0x74,0x68,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x39,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x5f,0x34,0x35,0x32,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x31,0x20,0x3d,0x20,0x5f,0x34,0x36,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d, + 0x20,0x5f,0x34,0x37,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20,0x5f,0x34,0x38,0x38, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x5f,0x35,0x30,0x30,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35, + 0x20,0x3d,0x20,0x5f,0x33,0x39,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x5f,0x34, + 0x35,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73, + 0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x20,0x3d,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x5f,0x33,0x39,0x34, + 0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x2d,0x31,0x2e,0x30,0x2c, + 0x20,0x30,0x2e,0x30,0x29,0x20,0x2a,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x56, + 0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x50,0x69,0x78,0x65,0x6c,0x53,0x69,0x7a,0x65, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20,0x5f,0x34,0x36,0x34,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x30,0x20,0x3d,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x31,0x20,0x3d,0x20,0x5f,0x33,0x39,0x34,0x20,0x2b,0x20,0x28,0x66,0x6c, + 0x6f,0x61,0x74,0x32,0x28,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x29,0x20,0x2a, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74, + 0x50,0x69,0x78,0x65,0x6c,0x53,0x69,0x7a,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x20,0x3d, + 0x20,0x5f,0x34,0x37,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43, + 0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33,0x20,0x3d, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x20,0x3d,0x20,0x5f, + 0x33,0x39,0x34,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x30,0x2e, + 0x30,0x2c,0x20,0x2d,0x31,0x2e,0x30,0x29,0x20,0x2a,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x73,0x2e,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x50,0x69,0x78,0x65,0x6c,0x53, + 0x69,0x7a,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x35,0x20,0x3d,0x20,0x5f,0x34,0x38,0x38,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x36,0x20,0x3d,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x37,0x20,0x3d,0x20,0x5f,0x33,0x39,0x34,0x20,0x2b,0x20, + 0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x20,0x2a,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x56,0x69,0x65,0x77,0x70, + 0x6f,0x72,0x74,0x50,0x69,0x78,0x65,0x6c,0x53,0x69,0x7a,0x65,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x38,0x20,0x3d,0x20,0x5f,0x35,0x30,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54, + 0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x39,0x20,0x3d,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x30,0x20, + 0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x61,0x6c,0x63,0x75,0x6c,0x61, + 0x74,0x65,0x45,0x64,0x67,0x65,0x73,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x31,0x20,0x3d, + 0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x6f,0x6d,0x70,0x75,0x74,0x65,0x56, + 0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x33,0x32,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x6f,0x6d, + 0x70,0x75,0x74,0x65,0x56,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x50,0x6f,0x73, + 0x69,0x74,0x69,0x6f,0x6e,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x33,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41, + 0x4f,0x5f,0x43,0x6f,0x6d,0x70,0x75,0x74,0x65,0x56,0x69,0x65,0x77,0x73,0x70,0x61, + 0x63,0x65,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x28,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x20,0x3d,0x20, + 0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x6f,0x6d,0x70,0x75,0x74,0x65,0x56,0x69, + 0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x36,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x35,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x6f,0x6d,0x70, + 0x75,0x74,0x65,0x56,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x50,0x6f,0x73,0x69, + 0x74,0x69,0x6f,0x6e,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x39,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f, + 0x35,0x38,0x36,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x61,0x6c, + 0x63,0x75,0x6c,0x61,0x74,0x65,0x4e,0x6f,0x72,0x6d,0x61,0x6c,0x28,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x31,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x33,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x33,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x5f,0x35,0x38,0x36,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74, + 0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74, + 0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79, + 0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x75,0x69,0x6e,0x74,0x20, + 0x48,0x69,0x6c,0x62,0x65,0x72,0x74,0x49,0x6e,0x64,0x65,0x78,0x28,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x75,0x69,0x6e,0x74,0x26,0x20,0x70,0x6f,0x73,0x58,0x2c,0x20, + 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x75,0x69,0x6e,0x74,0x26,0x20,0x70,0x6f,0x73, + 0x59,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x69,0x6e, + 0x64,0x65,0x78,0x20,0x3d,0x20,0x30,0x75,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6f, + 0x72,0x20,0x28,0x75,0x69,0x6e,0x74,0x20,0x63,0x75,0x72,0x4c,0x65,0x76,0x65,0x6c, + 0x20,0x3d,0x20,0x33,0x32,0x75,0x3b,0x20,0x63,0x75,0x72,0x4c,0x65,0x76,0x65,0x6c, + 0x20,0x3e,0x20,0x30,0x75,0x3b,0x20,0x63,0x75,0x72,0x4c,0x65,0x76,0x65,0x6c,0x20, + 0x2f,0x3d,0x20,0x32,0x75,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x5f,0x33,0x32,0x30,0x20,0x3d, + 0x20,0x75,0x69,0x6e,0x74,0x28,0x28,0x70,0x6f,0x73,0x58,0x20,0x26,0x20,0x63,0x75, + 0x72,0x4c,0x65,0x76,0x65,0x6c,0x29,0x20,0x3e,0x20,0x30,0x75,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x5f,0x33,0x32,0x36, + 0x20,0x3d,0x20,0x75,0x69,0x6e,0x74,0x28,0x28,0x70,0x6f,0x73,0x59,0x20,0x26,0x20, + 0x63,0x75,0x72,0x4c,0x65,0x76,0x65,0x6c,0x29,0x20,0x3e,0x20,0x30,0x75,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x64,0x65,0x78,0x20,0x2b, + 0x3d,0x20,0x28,0x28,0x63,0x75,0x72,0x4c,0x65,0x76,0x65,0x6c,0x20,0x2a,0x20,0x63, + 0x75,0x72,0x4c,0x65,0x76,0x65,0x6c,0x29,0x20,0x2a,0x20,0x28,0x28,0x33,0x75,0x20, + 0x2a,0x20,0x5f,0x33,0x32,0x30,0x29,0x20,0x5e,0x20,0x5f,0x33,0x32,0x36,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x33, + 0x32,0x36,0x20,0x3d,0x3d,0x20,0x30,0x75,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x5f,0x33,0x32,0x30,0x20,0x3d,0x3d,0x20,0x31,0x75,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x70,0x6f, + 0x73,0x58,0x20,0x3d,0x20,0x36,0x33,0x75,0x20,0x2d,0x20,0x70,0x6f,0x73,0x58,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x70,0x6f,0x73,0x59,0x20,0x3d,0x20,0x36,0x33,0x75,0x20,0x2d,0x20,0x70,0x6f, + 0x73,0x59,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x75,0x69, + 0x6e,0x74,0x20,0x5f,0x33,0x35,0x31,0x20,0x3d,0x20,0x70,0x6f,0x73,0x58,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x70,0x6f,0x73,0x58, + 0x20,0x3d,0x20,0x70,0x6f,0x73,0x59,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x70,0x6f,0x73,0x59,0x20,0x3d,0x20,0x5f,0x33,0x35,0x31, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x69,0x6e,0x64, + 0x65,0x78,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e, + 0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65, + 0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e, + 0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x53,0x70,0x61,0x74,0x69, + 0x6f,0x54,0x65,0x6d,0x70,0x6f,0x72,0x61,0x6c,0x4e,0x6f,0x69,0x73,0x65,0x28,0x74, + 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x75,0x69,0x6e,0x74, + 0x32,0x26,0x20,0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x2c,0x20,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x69,0x6e,0x74,0x26,0x20,0x74, + 0x65,0x6d,0x70,0x6f,0x72,0x61,0x6c,0x49,0x6e,0x64,0x65,0x78,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d, + 0x20,0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x75,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20, + 0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x75,0x69,0x6e,0x74,0x20,0x5f,0x33,0x36,0x36,0x20,0x3d,0x20,0x48,0x69,0x6c,0x62, + 0x65,0x72,0x74,0x49,0x6e,0x64,0x65,0x78,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x66,0x72,0x61,0x63,0x74,0x28,0x66,0x6c,0x6f,0x61,0x74, + 0x32,0x28,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32, + 0x28,0x30,0x2e,0x37,0x35,0x34,0x38,0x37,0x37,0x36,0x38,0x36,0x35,0x30,0x30,0x35, + 0x34,0x39,0x33,0x31,0x36,0x34,0x30,0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x35,0x36, + 0x39,0x38,0x34,0x30,0x33,0x31,0x32,0x30,0x30,0x34,0x30,0x38,0x39,0x33,0x35,0x35, + 0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f, + 0x33,0x36,0x36,0x20,0x2b,0x20,0x28,0x32,0x38,0x38,0x75,0x20,0x2a,0x20,0x28,0x75, + 0x69,0x6e,0x74,0x28,0x74,0x65,0x6d,0x70,0x6f,0x72,0x61,0x6c,0x49,0x6e,0x64,0x65, + 0x78,0x29,0x20,0x25,0x20,0x36,0x34,0x75,0x29,0x29,0x29,0x29,0x29,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20, + 0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61, + 0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x50,0x61,0x63,0x6b, + 0x45,0x64,0x67,0x65,0x73,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x26,0x20,0x65,0x64,0x67,0x65,0x73,0x4c,0x52,0x54,0x42,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x65,0x64,0x67,0x65,0x73,0x4c,0x52,0x54,0x42,0x20, + 0x3d,0x20,0x72,0x6f,0x75,0x6e,0x64,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c, + 0x61,0x6d,0x70,0x28,0x65,0x64,0x67,0x65,0x73,0x4c,0x52,0x54,0x42,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x30,0x2e,0x30,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x28,0x31,0x2e,0x30,0x29,0x29,0x20,0x2a,0x20,0x32,0x2e,0x39,0x30,0x30, + 0x30,0x30,0x30,0x30,0x39,0x35,0x33,0x36,0x37,0x34,0x33,0x31,0x36,0x34,0x30,0x36, + 0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x64,0x6f,0x74,0x28,0x65,0x64,0x67,0x65,0x73,0x4c,0x52,0x54,0x42,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x30,0x2e,0x32,0x35,0x30,0x39,0x38,0x30,0x34,0x30, + 0x36,0x39,0x39,0x39,0x35,0x38,0x38,0x30,0x31,0x32,0x36,0x39,0x35,0x33,0x31,0x32, + 0x35,0x2c,0x20,0x30,0x2e,0x30,0x36,0x32,0x37,0x34,0x35,0x31,0x30,0x31,0x37,0x34, + 0x39,0x38,0x39,0x37,0x30,0x30,0x33,0x31,0x37,0x33,0x38,0x32,0x38,0x31,0x32,0x35, + 0x2c,0x20,0x30,0x2e,0x30,0x31,0x35,0x36,0x38,0x36,0x32,0x37,0x35,0x34,0x33,0x37, + 0x34,0x37,0x34,0x32,0x35,0x30,0x37,0x39,0x33,0x34,0x35,0x37,0x30,0x33,0x31,0x32, + 0x35,0x2c,0x20,0x30,0x2e,0x30,0x30,0x33,0x39,0x32,0x31,0x35,0x36,0x38,0x38,0x35, + 0x39,0x33,0x36,0x38,0x35,0x36,0x32,0x36,0x39,0x38,0x33,0x36,0x34,0x32,0x35,0x37, + 0x38,0x31,0x32,0x35,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69, + 0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69, + 0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69, + 0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x58,0x65, + 0x47,0x54,0x41,0x4f,0x5f,0x46,0x61,0x73,0x74,0x53,0x71,0x72,0x74,0x28,0x74,0x68, + 0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x26,0x20,0x78,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x61,0x73,0x5f,0x74,0x79,0x70,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e, + 0x28,0x35,0x33,0x32,0x34,0x38,0x37,0x36,0x36,0x39,0x20,0x2b,0x20,0x28,0x61,0x73, + 0x5f,0x74,0x79,0x70,0x65,0x3c,0x69,0x6e,0x74,0x3e,0x28,0x78,0x29,0x20,0x3e,0x3e, + 0x20,0x31,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, + 0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75, + 0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c, + 0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x58,0x65,0x47,0x54, + 0x41,0x4f,0x5f,0x46,0x61,0x73,0x74,0x41,0x43,0x6f,0x73,0x28,0x74,0x68,0x72,0x65, + 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20, + 0x69,0x6e,0x58,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x30,0x33,0x20,0x3d,0x20,0x61,0x62,0x73,0x28,0x69,0x6e,0x58,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x65,0x73,0x20, + 0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x31,0x35,0x36,0x35,0x38,0x32,0x39,0x39,0x36, + 0x32,0x34,0x39,0x31,0x39,0x38,0x39,0x31,0x33,0x35,0x37,0x34,0x32,0x31,0x38,0x37, + 0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x30,0x33,0x29,0x20,0x2b,0x20,0x31,0x2e,0x35, + 0x37,0x30,0x37,0x39,0x36,0x33,0x37,0x30,0x35,0x30,0x36,0x32,0x38,0x36,0x36,0x32, + 0x31,0x30,0x39,0x33,0x37,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20, + 0x5f,0x31,0x30,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x73,0x20,0x2a,0x3d, + 0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x46,0x61,0x73,0x74,0x53,0x71,0x72,0x74, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x32,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x69,0x6e,0x58,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x32,0x31,0x20, + 0x3d,0x20,0x72,0x65,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x5f,0x31,0x32,0x31,0x20,0x3d,0x20,0x33,0x2e,0x31,0x34,0x31, + 0x35,0x39,0x32,0x37,0x34,0x31,0x30,0x31,0x32,0x35,0x37,0x33,0x32,0x34,0x32,0x31, + 0x38,0x37,0x35,0x20,0x2d,0x20,0x72,0x65,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x32,0x31, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69, + 0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f, + 0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29, + 0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x4f, + 0x75,0x74,0x70,0x75,0x74,0x57,0x6f,0x72,0x6b,0x69,0x6e,0x67,0x54,0x65,0x72,0x6d, + 0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x69,0x6e, + 0x74,0x32,0x26,0x20,0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x2c,0x20,0x74,0x68, + 0x72,0x65,0x61,0x64,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x76,0x69,0x73,0x69, + 0x62,0x69,0x6c,0x69,0x74,0x79,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32, + 0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x2c,0x20,0x61,0x63,0x63,0x65,0x73,0x73,0x3a, + 0x3a,0x77,0x72,0x69,0x74,0x65,0x3e,0x20,0x6f,0x75,0x74,0x5f,0x6e,0x6f,0x69,0x73, + 0x79,0x5f,0x61,0x6f,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x69,0x73,0x69, + 0x62,0x69,0x6c,0x69,0x74,0x79,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63, + 0x6c,0x61,0x6d,0x70,0x28,0x76,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x20, + 0x2a,0x20,0x30,0x2e,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x38,0x36,0x35,0x33,0x34, + 0x38,0x38,0x31,0x35,0x39,0x31,0x37,0x39,0x36,0x38,0x37,0x35,0x2c,0x20,0x30,0x2e, + 0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, + 0x5f,0x6e,0x6f,0x69,0x73,0x79,0x5f,0x61,0x6f,0x2e,0x77,0x72,0x69,0x74,0x65,0x28, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x76,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74, + 0x79,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30, + 0x29,0x2c,0x20,0x75,0x69,0x6e,0x74,0x32,0x28,0x70,0x69,0x78,0x43,0x6f,0x6f,0x72, + 0x64,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x76,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x3b,0x0a,0x7d,0x0a,0x0a,0x73, + 0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61, + 0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61, + 0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x4d,0x61,0x69,0x6e,0x50,0x61,0x73, + 0x73,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x69, + 0x6e,0x74,0x32,0x26,0x20,0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x2c,0x20,0x74, + 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x32,0x26,0x20,0x6c,0x6f,0x63,0x61,0x6c,0x4e,0x6f,0x69,0x73,0x65,0x2c,0x20, + 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x26,0x20,0x76,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x4e,0x6f, + 0x72,0x6d,0x61,0x6c,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x63,0x65,0x6e,0x74,0x65,0x72, + 0x56,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x5a,0x2c,0x20,0x74,0x68,0x72,0x65, + 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x26, + 0x20,0x65,0x64,0x67,0x65,0x73,0x4c,0x52,0x54,0x42,0x2c,0x20,0x74,0x68,0x72,0x65, + 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e, + 0x73,0x74,0x73,0x26,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2c,0x20,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x70,0x6f,0x69,0x6e,0x74,0x5f,0x63, + 0x6c,0x61,0x6d,0x70,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c, + 0x66,0x6c,0x6f,0x61,0x74,0x2c,0x20,0x61,0x63,0x63,0x65,0x73,0x73,0x3a,0x3a,0x77, + 0x72,0x69,0x74,0x65,0x3e,0x20,0x6f,0x75,0x74,0x5f,0x6e,0x6f,0x69,0x73,0x79,0x5f, + 0x61,0x6f,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c, + 0x6f,0x61,0x74,0x2c,0x20,0x61,0x63,0x63,0x65,0x73,0x73,0x3a,0x3a,0x77,0x72,0x69, + 0x74,0x65,0x3e,0x20,0x6f,0x75,0x74,0x5f,0x65,0x64,0x67,0x65,0x73,0x2c,0x20,0x74, + 0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20, + 0x74,0x65,0x78,0x5f,0x70,0x72,0x65,0x66,0x69,0x6c,0x74,0x65,0x72,0x5f,0x64,0x65, + 0x70,0x74,0x68,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x32,0x20,0x5f,0x36,0x31,0x30,0x20,0x3d,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32, + 0x28,0x70,0x69,0x78,0x43,0x6f,0x6f,0x72,0x64,0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2a,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x73,0x2e,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x50,0x69,0x78,0x65,0x6c, + 0x53,0x69,0x7a,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x76,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x5a,0x20,0x3d,0x20,0x63,0x65,0x6e, + 0x74,0x65,0x72,0x56,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x5a,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x20, + 0x3d,0x20,0x65,0x64,0x67,0x65,0x73,0x4c,0x52,0x54,0x42,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x31,0x38,0x20,0x3d,0x20,0x58,0x65, + 0x47,0x54,0x41,0x4f,0x5f,0x50,0x61,0x63,0x6b,0x45,0x64,0x67,0x65,0x73,0x28,0x70, + 0x61,0x72,0x61,0x6d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x65, + 0x64,0x67,0x65,0x73,0x2e,0x77,0x72,0x69,0x74,0x65,0x28,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x28,0x5f,0x36,0x31,0x38,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30, + 0x2c,0x20,0x30,0x2e,0x30,0x29,0x2c,0x20,0x75,0x69,0x6e,0x74,0x32,0x28,0x70,0x69, + 0x78,0x43,0x6f,0x6f,0x72,0x64,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x36,0x32,0x31,0x20,0x3d,0x20,0x76,0x69,0x65,0x77,0x73, + 0x70,0x61,0x63,0x65,0x5a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x36,0x32,0x32,0x20,0x3d,0x20,0x5f,0x36,0x32,0x31,0x20,0x2a,0x20,0x30, + 0x2e,0x39,0x39,0x39,0x39,0x38,0x39,0x39,0x38,0x36,0x34,0x31,0x39,0x36,0x37,0x37, + 0x37,0x33,0x34,0x33,0x37,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x69,0x65,0x77, + 0x73,0x70,0x61,0x63,0x65,0x5a,0x20,0x3d,0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x20,0x3d,0x20,0x5f,0x36,0x31,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x36, + 0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73, + 0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x5f,0x36,0x33,0x30,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x6f, + 0x6d,0x70,0x75,0x74,0x65,0x56,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x50,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x36, + 0x33,0x34,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x69,0x7a,0x65,0x28,0x2d,0x5f,0x36,0x33,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x35,0x30,0x20,0x3d,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x73,0x2e,0x45,0x66,0x66,0x65,0x63,0x74,0x52,0x61,0x64,0x69,0x75, + 0x73,0x20,0x2a,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x52,0x61,0x64,0x69,0x75, + 0x73,0x4d,0x75,0x6c,0x74,0x69,0x70,0x6c,0x69,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x35,0x36,0x20,0x3d,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x73,0x2e,0x45,0x66,0x66,0x65,0x63,0x74,0x46,0x61,0x6c,0x6c,0x6f, + 0x66,0x66,0x52,0x61,0x6e,0x67,0x65,0x20,0x2a,0x20,0x5f,0x36,0x35,0x30,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x36,0x35,0x20,0x3d, + 0x20,0x28,0x2d,0x31,0x2e,0x30,0x29,0x20,0x2f,0x20,0x5f,0x36,0x35,0x36,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x37,0x30,0x20,0x3d, + 0x20,0x28,0x28,0x5f,0x36,0x35,0x30,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x45,0x66,0x66,0x65,0x63,0x74,0x46,0x61, + 0x6c,0x6c,0x6f,0x66,0x66,0x52,0x61,0x6e,0x67,0x65,0x29,0x29,0x20,0x2f,0x20,0x5f, + 0x36,0x35,0x36,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x39,0x37,0x20,0x3d,0x20,0x5f,0x36,0x35, + 0x30,0x20,0x2f,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x76,0x69,0x65,0x77, + 0x73,0x70,0x61,0x63,0x65,0x5a,0x29,0x20,0x2a,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73, + 0x2e,0x4e,0x44,0x43,0x54,0x6f,0x56,0x69,0x65,0x77,0x4d,0x75,0x6c,0x5f,0x78,0x5f, + 0x50,0x69,0x78,0x65,0x6c,0x53,0x69,0x7a,0x65,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x69,0x73,0x69,0x62,0x69,0x6c,0x69, + 0x74,0x79,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70, + 0x28,0x28,0x31,0x30,0x2e,0x30,0x20,0x2d,0x20,0x5f,0x36,0x39,0x37,0x29,0x20,0x2a, + 0x20,0x30,0x2e,0x30,0x30,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x37,0x36,0x34, + 0x38,0x32,0x35,0x38,0x32,0x30,0x39,0x32,0x32,0x38,0x35,0x31,0x35,0x36,0x32,0x35, + 0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x20,0x2a,0x20,0x30,0x2e, + 0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x31, + 0x30,0x20,0x3d,0x20,0x31,0x2e,0x32,0x39,0x39,0x39,0x39,0x39,0x39,0x35,0x32,0x33, + 0x31,0x36,0x32,0x38,0x34,0x31,0x37,0x39,0x36,0x38,0x37,0x35,0x20,0x2f,0x20,0x5f, + 0x36,0x39,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x20,0x28,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x73,0x6c,0x69,0x63,0x65,0x20,0x3d,0x20,0x30,0x2e,0x30,0x3b, + 0x20,0x73,0x6c,0x69,0x63,0x65,0x20,0x3c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e, + 0x53,0x6c,0x69,0x63,0x65,0x43,0x6f,0x75,0x6e,0x74,0x3b,0x20,0x73,0x6c,0x69,0x63, + 0x65,0x20,0x2b,0x3d,0x20,0x31,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37, + 0x32,0x38,0x20,0x3d,0x20,0x28,0x28,0x73,0x6c,0x69,0x63,0x65,0x20,0x2b,0x20,0x6c, + 0x6f,0x63,0x61,0x6c,0x4e,0x6f,0x69,0x73,0x65,0x2e,0x78,0x29,0x20,0x2f,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x73,0x2e,0x53,0x6c,0x69,0x63,0x65,0x43,0x6f,0x75,0x6e,0x74, + 0x29,0x20,0x2a,0x20,0x33,0x2e,0x31,0x34,0x31,0x35,0x39,0x32,0x37,0x34,0x31,0x30, + 0x31,0x32,0x35,0x37,0x33,0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x33,0x31, + 0x20,0x3d,0x20,0x63,0x6f,0x73,0x28,0x5f,0x37,0x32,0x38,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x33,0x34, + 0x20,0x3d,0x20,0x73,0x69,0x6e,0x28,0x5f,0x37,0x32,0x38,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x37,0x34, + 0x32,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37,0x33,0x31,0x2c, + 0x20,0x2d,0x5f,0x37,0x33,0x34,0x29,0x20,0x2a,0x20,0x5f,0x36,0x39,0x37,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f, + 0x37,0x34,0x36,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x37,0x33, + 0x31,0x2c,0x20,0x5f,0x37,0x33,0x34,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x37, + 0x35,0x34,0x20,0x3d,0x20,0x5f,0x37,0x34,0x36,0x20,0x2d,0x20,0x28,0x5f,0x36,0x33, + 0x34,0x20,0x2a,0x20,0x64,0x6f,0x74,0x28,0x5f,0x37,0x34,0x36,0x2c,0x20,0x5f,0x36, + 0x33,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x5f,0x37,0x35,0x39,0x20,0x3d,0x20,0x66,0x61,0x73,0x74, + 0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x63,0x72,0x6f,0x73, + 0x73,0x28,0x5f,0x37,0x35,0x34,0x2c,0x20,0x5f,0x36,0x33,0x34,0x29,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f, + 0x37,0x36,0x37,0x20,0x3d,0x20,0x76,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x4e, + 0x6f,0x72,0x6d,0x61,0x6c,0x20,0x2d,0x20,0x28,0x5f,0x37,0x35,0x39,0x20,0x2a,0x20, + 0x64,0x6f,0x74,0x28,0x76,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65,0x4e,0x6f,0x72, + 0x6d,0x61,0x6c,0x2c,0x20,0x5f,0x37,0x35,0x39,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x37,0x35,0x20, + 0x3d,0x20,0x6c,0x65,0x6e,0x67,0x74,0x68,0x28,0x5f,0x37,0x36,0x37,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x72, + 0x6f,0x6a,0x65,0x63,0x74,0x65,0x64,0x4e,0x6f,0x72,0x6d,0x61,0x6c,0x56,0x65,0x63, + 0x4c,0x65,0x6e,0x67,0x74,0x68,0x20,0x3d,0x20,0x5f,0x37,0x37,0x35,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x38, + 0x32,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28, + 0x64,0x6f,0x74,0x28,0x5f,0x37,0x36,0x37,0x2c,0x20,0x5f,0x36,0x33,0x34,0x29,0x20, + 0x2f,0x20,0x5f,0x37,0x37,0x35,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x37,0x38,0x32,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x37,0x38,0x38,0x20,0x3d,0x20,0x73,0x69,0x67,0x6e,0x28,0x64,0x6f,0x74,0x28,0x5f, + 0x37,0x35,0x34,0x2c,0x20,0x5f,0x37,0x36,0x37,0x29,0x29,0x20,0x2a,0x20,0x58,0x65, + 0x47,0x54,0x41,0x4f,0x5f,0x46,0x61,0x73,0x74,0x41,0x43,0x6f,0x73,0x28,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x39,0x32,0x20,0x3d,0x20,0x63,0x6f,0x73, + 0x28,0x5f,0x37,0x38,0x38,0x20,0x2b,0x20,0x31,0x2e,0x35,0x37,0x30,0x37,0x39,0x36, + 0x33,0x37,0x30,0x35,0x30,0x36,0x32,0x38,0x36,0x36,0x32,0x31,0x30,0x39,0x33,0x37, + 0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x37,0x39,0x36,0x20,0x3d,0x20,0x63,0x6f,0x73,0x28,0x5f,0x37,0x38, + 0x38,0x20,0x2d,0x20,0x31,0x2e,0x35,0x37,0x30,0x37,0x39,0x36,0x33,0x37,0x30,0x35, + 0x30,0x36,0x32,0x38,0x36,0x36,0x32,0x31,0x30,0x39,0x33,0x37,0x35,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x68,0x6f, + 0x72,0x69,0x7a,0x6f,0x6e,0x43,0x6f,0x73,0x30,0x20,0x3d,0x20,0x5f,0x37,0x39,0x32, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x68,0x6f,0x72,0x69,0x7a,0x6f,0x6e,0x43,0x6f,0x73,0x31,0x20,0x3d,0x20,0x5f,0x37, + 0x39,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x20, + 0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x74,0x65,0x70,0x5f,0x20,0x3d,0x20,0x30, + 0x2e,0x30,0x3b,0x20,0x73,0x74,0x65,0x70,0x5f,0x20,0x3c,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x73,0x2e,0x53,0x74,0x65,0x70,0x73,0x50,0x65,0x72,0x53,0x6c,0x69,0x63,0x65, + 0x3b,0x20,0x73,0x74,0x65,0x70,0x5f,0x20,0x2b,0x3d,0x20,0x31,0x2e,0x30,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x38,0x33, + 0x39,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x20,0x2a,0x20,0x28,0x70,0x6f,0x77,0x72, + 0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x2c,0x20, + 0x28,0x73,0x74,0x65,0x70,0x5f,0x20,0x2b,0x20,0x66,0x72,0x61,0x63,0x74,0x28,0x6c, + 0x6f,0x63,0x61,0x6c,0x4e,0x6f,0x69,0x73,0x65,0x2e,0x79,0x20,0x2b,0x20,0x28,0x28, + 0x73,0x6c,0x69,0x63,0x65,0x20,0x2b,0x20,0x28,0x73,0x74,0x65,0x70,0x5f,0x20,0x2a, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x53,0x74,0x65,0x70,0x73,0x50,0x65,0x72, + 0x53,0x6c,0x69,0x63,0x65,0x29,0x29,0x20,0x2a,0x20,0x30,0x2e,0x36,0x31,0x38,0x30, + 0x33,0x34,0x30,0x30,0x35,0x31,0x36,0x35,0x31,0x30,0x30,0x30,0x39,0x37,0x36,0x35, + 0x36,0x32,0x35,0x29,0x29,0x29,0x20,0x2f,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e, + 0x53,0x74,0x65,0x70,0x73,0x50,0x65,0x72,0x53,0x6c,0x69,0x63,0x65,0x29,0x2c,0x20, + 0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x44,0x69,0x73, + 0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x50,0x6f,0x77,0x65,0x72,0x29,0x20, + 0x2b,0x20,0x5f,0x37,0x31,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x35,0x31,0x20, + 0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6c,0x6f, + 0x67,0x32,0x28,0x6c,0x65,0x6e,0x67,0x74,0x68,0x28,0x5f,0x38,0x33,0x39,0x29,0x29, + 0x20,0x2d,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x44,0x65,0x70,0x74,0x68,0x4d, + 0x49,0x50,0x53,0x61,0x6d,0x70,0x6c,0x69,0x6e,0x67,0x4f,0x66,0x66,0x73,0x65,0x74, + 0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x35,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20, + 0x5f,0x38,0x35,0x36,0x20,0x3d,0x20,0x72,0x6f,0x75,0x6e,0x64,0x28,0x5f,0x38,0x33, + 0x39,0x29,0x20,0x2a,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x56,0x69,0x65,0x77, + 0x70,0x6f,0x72,0x74,0x50,0x69,0x78,0x65,0x6c,0x53,0x69,0x7a,0x65,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x32,0x20,0x5f,0x38,0x36,0x30,0x20,0x3d,0x20,0x5f,0x36,0x31,0x30,0x20,0x2b,0x20, + 0x5f,0x38,0x35,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35, + 0x20,0x3d,0x20,0x5f,0x38,0x36,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x36,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x70,0x72,0x65,0x66,0x69,0x6c,0x74, + 0x65,0x72,0x5f,0x64,0x65,0x70,0x74,0x68,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x28, + 0x73,0x6d,0x70,0x5f,0x70,0x6f,0x69,0x6e,0x74,0x5f,0x63,0x6c,0x61,0x6d,0x70,0x2c, + 0x20,0x5f,0x38,0x36,0x30,0x2c,0x20,0x6c,0x65,0x76,0x65,0x6c,0x28,0x5f,0x38,0x35, + 0x31,0x29,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x32,0x20,0x5f,0x38,0x38,0x31,0x20,0x3d,0x20,0x5f,0x36,0x31,0x30,0x20,0x2d, + 0x20,0x5f,0x38,0x35,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x38,0x20,0x3d,0x20,0x5f,0x38,0x38,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x39,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x70,0x72,0x65,0x66,0x69,0x6c, + 0x74,0x65,0x72,0x5f,0x64,0x65,0x70,0x74,0x68,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65, + 0x28,0x73,0x6d,0x70,0x5f,0x70,0x6f,0x69,0x6e,0x74,0x5f,0x63,0x6c,0x61,0x6d,0x70, + 0x2c,0x20,0x5f,0x38,0x38,0x31,0x2c,0x20,0x6c,0x65,0x76,0x65,0x6c,0x28,0x5f,0x38, + 0x35,0x31,0x29,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x5f,0x39,0x30,0x31,0x20,0x3d,0x20,0x58,0x65,0x47,0x54, + 0x41,0x4f,0x5f,0x43,0x6f,0x6d,0x70,0x75,0x74,0x65,0x56,0x69,0x65,0x77,0x73,0x70, + 0x61,0x63,0x65,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x37,0x29,0x20,0x2d,0x20,0x5f,0x36,0x33,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x5f,0x39,0x30,0x35,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f, + 0x43,0x6f,0x6d,0x70,0x75,0x74,0x65,0x56,0x69,0x65,0x77,0x73,0x70,0x61,0x63,0x65, + 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x30,0x29,0x20,0x2d,0x20,0x5f,0x36,0x33,0x30,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x39,0x33,0x30,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2b,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x73,0x2e,0x54,0x68,0x69,0x6e,0x4f,0x63,0x63,0x6c,0x75,0x64,0x65,0x72,0x43, + 0x6f,0x6d,0x70,0x65,0x6e,0x73,0x61,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x68,0x6f,0x72,0x69,0x7a,0x6f,0x6e, + 0x43,0x6f,0x73,0x30,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78, + 0x28,0x68,0x6f,0x72,0x69,0x7a,0x6f,0x6e,0x43,0x6f,0x73,0x30,0x2c,0x20,0x6d,0x69, + 0x78,0x28,0x5f,0x37,0x39,0x32,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x39,0x30,0x31, + 0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x6c,0x65,0x6e,0x67,0x74,0x68, + 0x28,0x5f,0x39,0x30,0x31,0x29,0x29,0x2c,0x20,0x5f,0x36,0x33,0x34,0x29,0x2c,0x20, + 0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x28,0x6c,0x65,0x6e, + 0x67,0x74,0x68,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x39,0x30,0x31,0x2e, + 0x78,0x79,0x2c,0x20,0x5f,0x39,0x30,0x31,0x2e,0x7a,0x20,0x2a,0x20,0x5f,0x39,0x33, + 0x30,0x29,0x29,0x20,0x2a,0x20,0x5f,0x36,0x36,0x35,0x29,0x20,0x2b,0x20,0x5f,0x36, + 0x37,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x68,0x6f,0x72, + 0x69,0x7a,0x6f,0x6e,0x43,0x6f,0x73,0x31,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a, + 0x3a,0x6d,0x61,0x78,0x28,0x68,0x6f,0x72,0x69,0x7a,0x6f,0x6e,0x43,0x6f,0x73,0x31, + 0x2c,0x20,0x6d,0x69,0x78,0x28,0x5f,0x37,0x39,0x36,0x2c,0x20,0x64,0x6f,0x74,0x28, + 0x5f,0x39,0x30,0x35,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x6c,0x65, + 0x6e,0x67,0x74,0x68,0x28,0x5f,0x39,0x30,0x35,0x29,0x29,0x2c,0x20,0x5f,0x36,0x33, + 0x34,0x29,0x2c,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28, + 0x28,0x6c,0x65,0x6e,0x67,0x74,0x68,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f, + 0x39,0x30,0x35,0x2e,0x78,0x79,0x2c,0x20,0x5f,0x39,0x30,0x35,0x2e,0x7a,0x20,0x2a, + 0x20,0x5f,0x39,0x33,0x30,0x29,0x29,0x20,0x2a,0x20,0x5f,0x36,0x36,0x35,0x29,0x20, + 0x2b,0x20,0x5f,0x36,0x37,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x70,0x72,0x6f,0x6a,0x65,0x63,0x74,0x65,0x64, + 0x4e,0x6f,0x72,0x6d,0x61,0x6c,0x56,0x65,0x63,0x4c,0x65,0x6e,0x67,0x74,0x68,0x20, + 0x3d,0x20,0x6d,0x69,0x78,0x28,0x70,0x72,0x6f,0x6a,0x65,0x63,0x74,0x65,0x64,0x4e, + 0x6f,0x72,0x6d,0x61,0x6c,0x56,0x65,0x63,0x4c,0x65,0x6e,0x67,0x74,0x68,0x2c,0x20, + 0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x35,0x30,0x30,0x30,0x30,0x30,0x30,0x30, + 0x37,0x34,0x35,0x30,0x35,0x38,0x30,0x35,0x39,0x36,0x39,0x32,0x33,0x38,0x32,0x38, + 0x31,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x68, + 0x6f,0x72,0x69,0x7a,0x6f,0x6e,0x43,0x6f,0x73,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x32,0x20,0x3d,0x20,0x68,0x6f,0x72,0x69,0x7a,0x6f,0x6e,0x43,0x6f,0x73,0x30, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x30,0x30,0x30,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x46, + 0x61,0x73,0x74,0x41,0x43,0x6f,0x73,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31, + 0x29,0x20,0x2a,0x20,0x28,0x2d,0x32,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x30,0x32,0x20, + 0x3d,0x20,0x73,0x69,0x6e,0x28,0x5f,0x37,0x38,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x31,0x36, + 0x20,0x3d,0x20,0x32,0x2e,0x30,0x20,0x2a,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f, + 0x46,0x61,0x73,0x74,0x41,0x43,0x6f,0x73,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x69,0x73,0x69, + 0x62,0x69,0x6c,0x69,0x74,0x79,0x20,0x2b,0x3d,0x20,0x28,0x70,0x72,0x6f,0x6a,0x65, + 0x63,0x74,0x65,0x64,0x4e,0x6f,0x72,0x6d,0x61,0x6c,0x56,0x65,0x63,0x4c,0x65,0x6e, + 0x67,0x74,0x68,0x20,0x2a,0x20,0x28,0x30,0x2e,0x32,0x35,0x20,0x2a,0x20,0x28,0x28, + 0x28,0x5f,0x37,0x38,0x32,0x20,0x2b,0x20,0x28,0x5f,0x31,0x30,0x30,0x30,0x20,0x2a, + 0x20,0x5f,0x31,0x30,0x30,0x32,0x29,0x29,0x20,0x2d,0x20,0x63,0x6f,0x73,0x28,0x5f, + 0x31,0x30,0x30,0x30,0x20,0x2d,0x20,0x5f,0x37,0x38,0x38,0x29,0x29,0x20,0x2b,0x20, + 0x28,0x28,0x5f,0x37,0x38,0x32,0x20,0x2b,0x20,0x28,0x5f,0x31,0x30,0x31,0x36,0x20, + 0x2a,0x20,0x5f,0x31,0x30,0x30,0x32,0x29,0x29,0x20,0x2d,0x20,0x63,0x6f,0x73,0x28, + 0x5f,0x31,0x30,0x31,0x36,0x20,0x2d,0x20,0x5f,0x37,0x38,0x38,0x29,0x29,0x29,0x29, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x30,0x34,0x30,0x20,0x3d,0x20,0x76,0x69,0x73,0x69,0x62, + 0x69,0x6c,0x69,0x74,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x30,0x35,0x30,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d, + 0x61,0x78,0x28,0x30,0x2e,0x30,0x32,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x33,0x32, + 0x39,0x34,0x34,0x37,0x37,0x34,0x36,0x32,0x37,0x36,0x38,0x35,0x35,0x34,0x36,0x38, + 0x37,0x35,0x2c,0x20,0x70,0x6f,0x77,0x72,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d, + 0x61,0x78,0x28,0x30,0x2e,0x30,0x2c,0x20,0x5f,0x31,0x30,0x34,0x30,0x20,0x2f,0x20, + 0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x53,0x6c,0x69,0x63,0x65,0x43,0x6f,0x75,0x6e, + 0x74,0x29,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x73,0x2e,0x46,0x69,0x6e,0x61,0x6c, + 0x56,0x61,0x6c,0x75,0x65,0x50,0x6f,0x77,0x65,0x72,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x20,0x3d,0x20,0x5f, + 0x31,0x30,0x35,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20,0x70,0x69,0x78,0x43,0x6f,0x6f, + 0x72,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x5f,0x31,0x30,0x35,0x30,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x35,0x20, + 0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x57, + 0x6f,0x72,0x6b,0x69,0x6e,0x67,0x54,0x65,0x72,0x6d,0x28,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x6f, + 0x75,0x74,0x5f,0x6e,0x6f,0x69,0x73,0x79,0x5f,0x61,0x6f,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x30,0x35,0x35,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x6b,0x65,0x72,0x6e,0x65,0x6c,0x20,0x76,0x6f,0x69,0x64,0x20,0x6d, + 0x61,0x69,0x6e,0x30,0x28,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62, + 0x5f,0x67,0x74,0x61,0x6f,0x26,0x20,0x67,0x74,0x61,0x6f,0x20,0x5b,0x5b,0x62,0x75, + 0x66,0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78,0x74,0x75, + 0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x2c,0x20,0x61,0x63,0x63,0x65, + 0x73,0x73,0x3a,0x3a,0x77,0x72,0x69,0x74,0x65,0x3e,0x20,0x6f,0x75,0x74,0x5f,0x6e, + 0x6f,0x69,0x73,0x79,0x5f,0x61,0x6f,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72, + 0x65,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32, + 0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x2c,0x20,0x61,0x63,0x63,0x65,0x73,0x73,0x3a, + 0x3a,0x77,0x72,0x69,0x74,0x65,0x3e,0x20,0x6f,0x75,0x74,0x5f,0x65,0x64,0x67,0x65, + 0x73,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x31,0x29,0x5d,0x5d, + 0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61, + 0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x72,0x61,0x77,0x5f,0x64,0x65,0x70,0x74,0x68, + 0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x32,0x29,0x5d,0x5d,0x2c, + 0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74, + 0x3e,0x20,0x74,0x65,0x78,0x5f,0x70,0x72,0x65,0x66,0x69,0x6c,0x74,0x65,0x72,0x5f, + 0x64,0x65,0x70,0x74,0x68,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28, + 0x33,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d, + 0x70,0x5f,0x70,0x6f,0x69,0x6e,0x74,0x5f,0x63,0x6c,0x61,0x6d,0x70,0x20,0x5b,0x5b, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x75,0x69, + 0x6e,0x74,0x33,0x20,0x67,0x6c,0x5f,0x47,0x6c,0x6f,0x62,0x61,0x6c,0x49,0x6e,0x76, + 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x49,0x44,0x20,0x5b,0x5b,0x74,0x68,0x72,0x65, + 0x61,0x64,0x5f,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5f,0x69,0x6e,0x5f,0x67, + 0x72,0x69,0x64,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74, + 0x32,0x20,0x5f,0x31,0x30,0x36,0x34,0x20,0x3d,0x20,0x69,0x6e,0x74,0x32,0x28,0x67, + 0x6c,0x5f,0x47,0x6c,0x6f,0x62,0x61,0x6c,0x49,0x6e,0x76,0x6f,0x63,0x61,0x74,0x69, + 0x6f,0x6e,0x49,0x44,0x2e,0x78,0x79,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x61,0x6e,0x79,0x28,0x5f,0x31,0x30,0x36,0x34,0x20,0x3e,0x3d,0x20,0x67, + 0x74,0x61,0x6f,0x2e,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65, + 0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20, + 0x5f,0x31,0x30,0x36,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43, + 0x6f,0x6e,0x73,0x74,0x73,0x20,0x5f,0x31,0x32,0x36,0x31,0x20,0x3d,0x20,0x47,0x54, + 0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x7b,0x20,0x67,0x74,0x61,0x6f,0x2e,0x56, + 0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x50,0x69,0x78,0x65,0x6c,0x53,0x69,0x7a,0x65, + 0x2c,0x20,0x67,0x74,0x61,0x6f,0x2e,0x4e,0x44,0x43,0x54,0x6f,0x56,0x69,0x65,0x77, + 0x4d,0x75,0x6c,0x2c,0x20,0x67,0x74,0x61,0x6f,0x2e,0x4e,0x44,0x43,0x54,0x6f,0x56, + 0x69,0x65,0x77,0x41,0x64,0x64,0x2c,0x20,0x67,0x74,0x61,0x6f,0x2e,0x4e,0x44,0x43, + 0x54,0x6f,0x56,0x69,0x65,0x77,0x4d,0x75,0x6c,0x5f,0x78,0x5f,0x50,0x69,0x78,0x65, + 0x6c,0x53,0x69,0x7a,0x65,0x2c,0x20,0x67,0x74,0x61,0x6f,0x2e,0x45,0x66,0x66,0x65, + 0x63,0x74,0x52,0x61,0x64,0x69,0x75,0x73,0x2c,0x20,0x67,0x74,0x61,0x6f,0x2e,0x45, + 0x66,0x66,0x65,0x63,0x74,0x46,0x61,0x6c,0x6c,0x6f,0x66,0x66,0x52,0x61,0x6e,0x67, + 0x65,0x2c,0x20,0x67,0x74,0x61,0x6f,0x2e,0x52,0x61,0x64,0x69,0x75,0x73,0x4d,0x75, + 0x6c,0x74,0x69,0x70,0x6c,0x69,0x65,0x72,0x2c,0x20,0x67,0x74,0x61,0x6f,0x2e,0x46, + 0x69,0x6e,0x61,0x6c,0x56,0x61,0x6c,0x75,0x65,0x50,0x6f,0x77,0x65,0x72,0x2c,0x20, + 0x67,0x74,0x61,0x6f,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x44,0x69,0x73,0x74,0x72, + 0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x50,0x6f,0x77,0x65,0x72,0x2c,0x20,0x67,0x74, + 0x61,0x6f,0x2e,0x54,0x68,0x69,0x6e,0x4f,0x63,0x63,0x6c,0x75,0x64,0x65,0x72,0x43, + 0x6f,0x6d,0x70,0x65,0x6e,0x73,0x61,0x74,0x69,0x6f,0x6e,0x2c,0x20,0x67,0x74,0x61, + 0x6f,0x2e,0x44,0x65,0x70,0x74,0x68,0x4d,0x49,0x50,0x53,0x61,0x6d,0x70,0x6c,0x69, + 0x6e,0x67,0x4f,0x66,0x66,0x73,0x65,0x74,0x2c,0x20,0x67,0x74,0x61,0x6f,0x2e,0x53, + 0x6c,0x69,0x63,0x65,0x43,0x6f,0x75,0x6e,0x74,0x2c,0x20,0x67,0x74,0x61,0x6f,0x2e, + 0x53,0x74,0x65,0x70,0x73,0x50,0x65,0x72,0x53,0x6c,0x69,0x63,0x65,0x20,0x7d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x31,0x32,0x36,0x31,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x5f,0x31,0x31,0x32,0x37,0x20, + 0x3d,0x20,0x67,0x74,0x61,0x6f,0x2e,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53, + 0x69,0x7a,0x65,0x20,0x2d,0x20,0x69,0x6e,0x74,0x32,0x28,0x31,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x72,0x61,0x77,0x5f,0x64,0x65,0x70,0x74,0x68, + 0x2e,0x72,0x65,0x61,0x64,0x28,0x75,0x69,0x6e,0x74,0x32,0x28,0x63,0x6c,0x61,0x6d, + 0x70,0x28,0x5f,0x31,0x30,0x36,0x34,0x2c,0x20,0x69,0x6e,0x74,0x32,0x28,0x30,0x29, + 0x2c,0x20,0x5f,0x31,0x31,0x32,0x37,0x29,0x29,0x2c,0x20,0x30,0x29,0x2e,0x78,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31,0x32,0x36,0x31,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x34,0x31, + 0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x53,0x63,0x72,0x65,0x65,0x6e, + 0x53,0x70,0x61,0x63,0x65,0x54,0x6f,0x56,0x69,0x65,0x77,0x53,0x70,0x61,0x63,0x65, + 0x44,0x65,0x70,0x74,0x68,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x74,0x65,0x78, + 0x5f,0x72,0x61,0x77,0x5f,0x64,0x65,0x70,0x74,0x68,0x2e,0x72,0x65,0x61,0x64,0x28, + 0x75,0x69,0x6e,0x74,0x32,0x28,0x63,0x6c,0x61,0x6d,0x70,0x28,0x5f,0x31,0x30,0x36, + 0x34,0x20,0x2b,0x20,0x69,0x6e,0x74,0x32,0x28,0x2d,0x31,0x2c,0x20,0x30,0x29,0x2c, + 0x20,0x69,0x6e,0x74,0x32,0x28,0x30,0x29,0x2c,0x20,0x5f,0x31,0x31,0x32,0x37,0x29, + 0x29,0x2c,0x20,0x30,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41, + 0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20, + 0x3d,0x20,0x5f,0x31,0x32,0x36,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x74,0x65,0x78, + 0x5f,0x72,0x61,0x77,0x5f,0x64,0x65,0x70,0x74,0x68,0x2e,0x72,0x65,0x61,0x64,0x28, + 0x75,0x69,0x6e,0x74,0x32,0x28,0x63,0x6c,0x61,0x6d,0x70,0x28,0x5f,0x31,0x30,0x36, + 0x34,0x20,0x2b,0x20,0x69,0x6e,0x74,0x32,0x28,0x31,0x2c,0x20,0x30,0x29,0x2c,0x20, + 0x69,0x6e,0x74,0x32,0x28,0x30,0x29,0x2c,0x20,0x5f,0x31,0x31,0x32,0x37,0x29,0x29, + 0x2c,0x20,0x30,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f, + 0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d, + 0x20,0x5f,0x31,0x32,0x36,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f, + 0x72,0x61,0x77,0x5f,0x64,0x65,0x70,0x74,0x68,0x2e,0x72,0x65,0x61,0x64,0x28,0x75, + 0x69,0x6e,0x74,0x32,0x28,0x63,0x6c,0x61,0x6d,0x70,0x28,0x5f,0x31,0x30,0x36,0x34, + 0x20,0x2b,0x20,0x69,0x6e,0x74,0x32,0x28,0x30,0x2c,0x20,0x2d,0x31,0x29,0x2c,0x20, + 0x69,0x6e,0x74,0x32,0x28,0x30,0x29,0x2c,0x20,0x5f,0x31,0x31,0x32,0x37,0x29,0x29, + 0x2c,0x20,0x30,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f, + 0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d, + 0x20,0x5f,0x31,0x32,0x36,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x74,0x65,0x78, + 0x5f,0x72,0x61,0x77,0x5f,0x64,0x65,0x70,0x74,0x68,0x2e,0x72,0x65,0x61,0x64,0x28, + 0x75,0x69,0x6e,0x74,0x32,0x28,0x63,0x6c,0x61,0x6d,0x70,0x28,0x5f,0x31,0x30,0x36, + 0x34,0x20,0x2b,0x20,0x69,0x6e,0x74,0x32,0x28,0x30,0x2c,0x20,0x31,0x29,0x2c,0x20, + 0x69,0x6e,0x74,0x32,0x28,0x30,0x29,0x2c,0x20,0x5f,0x31,0x31,0x32,0x37,0x29,0x29, + 0x2c,0x20,0x30,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47,0x54,0x41,0x4f, + 0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20, + 0x3d,0x20,0x5f,0x31,0x32,0x36,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x5f,0x31, + 0x31,0x34,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f, + 0x5f,0x53,0x63,0x72,0x65,0x65,0x6e,0x53,0x70,0x61,0x63,0x65,0x54,0x6f,0x56,0x69, + 0x65,0x77,0x53,0x70,0x61,0x63,0x65,0x44,0x65,0x70,0x74,0x68,0x28,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x34,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x53,0x63,0x72,0x65, + 0x65,0x6e,0x53,0x70,0x61,0x63,0x65,0x54,0x6f,0x56,0x69,0x65,0x77,0x53,0x70,0x61, + 0x63,0x65,0x44,0x65,0x70,0x74,0x68,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20, + 0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x53,0x63,0x72,0x65,0x65,0x6e,0x53,0x70,0x61, + 0x63,0x65,0x54,0x6f,0x56,0x69,0x65,0x77,0x53,0x70,0x61,0x63,0x65,0x44,0x65,0x70, + 0x74,0x68,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x39,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41, + 0x4f,0x5f,0x53,0x63,0x72,0x65,0x65,0x6e,0x53,0x70,0x61,0x63,0x65,0x54,0x6f,0x56, + 0x69,0x65,0x77,0x53,0x70,0x61,0x63,0x65,0x44,0x65,0x70,0x74,0x68,0x28,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x32,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x37,0x20,0x3d,0x20,0x75,0x69,0x6e,0x74,0x32,0x28,0x5f,0x31, + 0x30,0x36,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x6e,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20, + 0x5f,0x31,0x30,0x36,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x20,0x3d,0x20,0x53,0x70,0x61, + 0x74,0x69,0x6f,0x54,0x65,0x6d,0x70,0x6f,0x72,0x61,0x6c,0x4e,0x6f,0x69,0x73,0x65, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x20,0x3d,0x20,0x58,0x65,0x47,0x54, + 0x41,0x4f,0x5f,0x43,0x6f,0x6d,0x70,0x75,0x74,0x65,0x56,0x69,0x65,0x77,0x73,0x70, + 0x61,0x63,0x65,0x4e,0x6f,0x72,0x6d,0x61,0x6c,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x67,0x74,0x61,0x6f,0x2c,0x20, + 0x74,0x65,0x78,0x5f,0x72,0x61,0x77,0x5f,0x64,0x65,0x70,0x74,0x68,0x2c,0x20,0x73, + 0x6d,0x70,0x5f,0x70,0x6f,0x69,0x6e,0x74,0x5f,0x63,0x6c,0x61,0x6d,0x70,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x32,0x20,0x3d,0x20,0x5f,0x31,0x31,0x34,0x31,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33, + 0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x61,0x6c,0x63,0x75,0x6c, + 0x61,0x74,0x65,0x45,0x64,0x67,0x65,0x73,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x47,0x54,0x41,0x4f,0x43,0x6f,0x6e,0x73,0x74,0x73,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x34,0x20,0x3d,0x20,0x5f,0x31,0x32,0x36,0x31,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x33,0x32,0x20,0x3d,0x20,0x58, + 0x65,0x47,0x54,0x41,0x4f,0x5f,0x4d,0x61,0x69,0x6e,0x50,0x61,0x73,0x73,0x28,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x70, + 0x6f,0x69,0x6e,0x74,0x5f,0x63,0x6c,0x61,0x6d,0x70,0x2c,0x20,0x6f,0x75,0x74,0x5f, + 0x6e,0x6f,0x69,0x73,0x79,0x5f,0x61,0x6f,0x2c,0x20,0x6f,0x75,0x74,0x5f,0x65,0x64, + 0x67,0x65,0x73,0x2c,0x20,0x74,0x65,0x78,0x5f,0x70,0x72,0x65,0x66,0x69,0x6c,0x74, + 0x65,0x72,0x5f,0x64,0x65,0x70,0x74,0x68,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +static inline const sg_shader_desc* gtao_main_pass_prog_shader_desc(sg_backend backend) { + if (backend == SG_BACKEND_GLCORE) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.compute_func.source = (const char*)gtao_main_pass_cs_source_glsl430; + desc.compute_func.entry = "main"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_COMPUTE; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 80; + desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_INT2; + desc.uniform_blocks[0].glsl_uniforms[0].array_count = 0; + desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "gtao.ViewportSize"; + desc.uniform_blocks[0].glsl_uniforms[1].type = SG_UNIFORMTYPE_FLOAT2; + desc.uniform_blocks[0].glsl_uniforms[1].array_count = 0; + desc.uniform_blocks[0].glsl_uniforms[1].glsl_name = "gtao.ViewportPixelSize"; + desc.uniform_blocks[0].glsl_uniforms[2].type = SG_UNIFORMTYPE_FLOAT2; + desc.uniform_blocks[0].glsl_uniforms[2].array_count = 0; + desc.uniform_blocks[0].glsl_uniforms[2].glsl_name = "gtao.NDCToViewMul"; + desc.uniform_blocks[0].glsl_uniforms[3].type = SG_UNIFORMTYPE_FLOAT2; + desc.uniform_blocks[0].glsl_uniforms[3].array_count = 0; + desc.uniform_blocks[0].glsl_uniforms[3].glsl_name = "gtao.NDCToViewAdd"; + desc.uniform_blocks[0].glsl_uniforms[4].type = SG_UNIFORMTYPE_FLOAT2; + desc.uniform_blocks[0].glsl_uniforms[4].array_count = 0; + desc.uniform_blocks[0].glsl_uniforms[4].glsl_name = "gtao.NDCToViewMul_x_PixelSize"; + desc.uniform_blocks[0].glsl_uniforms[5].type = SG_UNIFORMTYPE_FLOAT; + desc.uniform_blocks[0].glsl_uniforms[5].array_count = 0; + desc.uniform_blocks[0].glsl_uniforms[5].glsl_name = "gtao.EffectRadius"; + desc.uniform_blocks[0].glsl_uniforms[6].type = SG_UNIFORMTYPE_FLOAT; + desc.uniform_blocks[0].glsl_uniforms[6].array_count = 0; + desc.uniform_blocks[0].glsl_uniforms[6].glsl_name = "gtao.EffectFalloffRange"; + desc.uniform_blocks[0].glsl_uniforms[7].type = SG_UNIFORMTYPE_FLOAT; + desc.uniform_blocks[0].glsl_uniforms[7].array_count = 0; + desc.uniform_blocks[0].glsl_uniforms[7].glsl_name = "gtao.RadiusMultiplier"; + desc.uniform_blocks[0].glsl_uniforms[8].type = SG_UNIFORMTYPE_FLOAT; + desc.uniform_blocks[0].glsl_uniforms[8].array_count = 0; + desc.uniform_blocks[0].glsl_uniforms[8].glsl_name = "gtao.FinalValuePower"; + desc.uniform_blocks[0].glsl_uniforms[9].type = SG_UNIFORMTYPE_FLOAT; + desc.uniform_blocks[0].glsl_uniforms[9].array_count = 0; + desc.uniform_blocks[0].glsl_uniforms[9].glsl_name = "gtao.SampleDistributionPower"; + desc.uniform_blocks[0].glsl_uniforms[10].type = SG_UNIFORMTYPE_FLOAT; + desc.uniform_blocks[0].glsl_uniforms[10].array_count = 0; + desc.uniform_blocks[0].glsl_uniforms[10].glsl_name = "gtao.ThinOccluderCompensation"; + desc.uniform_blocks[0].glsl_uniforms[11].type = SG_UNIFORMTYPE_FLOAT; + desc.uniform_blocks[0].glsl_uniforms[11].array_count = 0; + desc.uniform_blocks[0].glsl_uniforms[11].glsl_name = "gtao.DepthMIPSamplingOffset"; + desc.uniform_blocks[0].glsl_uniforms[12].type = SG_UNIFORMTYPE_FLOAT; + desc.uniform_blocks[0].glsl_uniforms[12].array_count = 0; + desc.uniform_blocks[0].glsl_uniforms[12].glsl_name = "gtao.SliceCount"; + desc.uniform_blocks[0].glsl_uniforms[13].type = SG_UNIFORMTYPE_FLOAT; + desc.uniform_blocks[0].glsl_uniforms[13].array_count = 0; + desc.uniform_blocks[0].glsl_uniforms[13].glsl_name = "gtao.StepsPerSlice"; + desc.views[0].storage_image.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[0].storage_image.image_type = SG_IMAGETYPE_2D; + desc.views[0].storage_image.access_format = SG_PIXELFORMAT_R32F; + desc.views[0].storage_image.writeonly = true; + desc.views[0].storage_image.glsl_binding_n = 0; + desc.views[1].storage_image.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[1].storage_image.image_type = SG_IMAGETYPE_2D; + desc.views[1].storage_image.access_format = SG_PIXELFORMAT_R32F; + desc.views[1].storage_image.writeonly = true; + desc.views[1].storage_image.glsl_binding_n = 1; + desc.views[2].texture.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[2].texture.image_type = SG_IMAGETYPE_2D; + desc.views[2].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[2].texture.multisampled = false; + desc.views[3].texture.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[3].texture.image_type = SG_IMAGETYPE_2D; + desc.views[3].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[3].texture.multisampled = false; + desc.samplers[0].stage = SG_SHADERSTAGE_COMPUTE; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_COMPUTE; + desc.texture_sampler_pairs[0].view_slot = 2; + desc.texture_sampler_pairs[0].sampler_slot = 0; + desc.texture_sampler_pairs[0].glsl_name = "tex_raw_depth_smp_point_clamp"; + desc.texture_sampler_pairs[1].stage = SG_SHADERSTAGE_COMPUTE; + desc.texture_sampler_pairs[1].view_slot = 3; + desc.texture_sampler_pairs[1].sampler_slot = 0; + desc.texture_sampler_pairs[1].glsl_name = "tex_prefilter_depth_smp_point_clamp"; + desc.label = "gtao_main_pass_prog_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_D3D11) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.compute_func.source = (const char*)gtao_main_pass_cs_source_hlsl5; + desc.compute_func.d3d11_target = "cs_5_0"; + desc.compute_func.entry = "main"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_COMPUTE; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 80; + desc.uniform_blocks[0].hlsl_register_b_n = 0; + desc.views[0].storage_image.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[0].storage_image.image_type = SG_IMAGETYPE_2D; + desc.views[0].storage_image.access_format = SG_PIXELFORMAT_R32F; + desc.views[0].storage_image.writeonly = true; + desc.views[0].storage_image.hlsl_register_u_n = 0; + desc.views[1].storage_image.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[1].storage_image.image_type = SG_IMAGETYPE_2D; + desc.views[1].storage_image.access_format = SG_PIXELFORMAT_R32F; + desc.views[1].storage_image.writeonly = true; + desc.views[1].storage_image.hlsl_register_u_n = 1; + desc.views[2].texture.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[2].texture.image_type = SG_IMAGETYPE_2D; + desc.views[2].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[2].texture.multisampled = false; + desc.views[2].texture.hlsl_register_t_n = 0; + desc.views[3].texture.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[3].texture.image_type = SG_IMAGETYPE_2D; + desc.views[3].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[3].texture.multisampled = false; + desc.views[3].texture.hlsl_register_t_n = 1; + desc.samplers[0].stage = SG_SHADERSTAGE_COMPUTE; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[0].hlsl_register_s_n = 0; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_COMPUTE; + desc.texture_sampler_pairs[0].view_slot = 2; + desc.texture_sampler_pairs[0].sampler_slot = 0; + desc.texture_sampler_pairs[1].stage = SG_SHADERSTAGE_COMPUTE; + desc.texture_sampler_pairs[1].view_slot = 3; + desc.texture_sampler_pairs[1].sampler_slot = 0; + desc.label = "gtao_main_pass_prog_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_METAL_MACOS) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.compute_func.source = (const char*)gtao_main_pass_cs_source_metal_macos; + desc.compute_func.entry = "main0"; + desc.mtl_threads_per_threadgroup.x = 8; + desc.mtl_threads_per_threadgroup.y = 8; + desc.mtl_threads_per_threadgroup.z = 1; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_COMPUTE; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 80; + desc.uniform_blocks[0].msl_buffer_n = 0; + desc.views[0].storage_image.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[0].storage_image.image_type = SG_IMAGETYPE_2D; + desc.views[0].storage_image.access_format = SG_PIXELFORMAT_R32F; + desc.views[0].storage_image.writeonly = true; + desc.views[0].storage_image.msl_texture_n = 0; + desc.views[1].storage_image.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[1].storage_image.image_type = SG_IMAGETYPE_2D; + desc.views[1].storage_image.access_format = SG_PIXELFORMAT_R32F; + desc.views[1].storage_image.writeonly = true; + desc.views[1].storage_image.msl_texture_n = 1; + desc.views[2].texture.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[2].texture.image_type = SG_IMAGETYPE_2D; + desc.views[2].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[2].texture.multisampled = false; + desc.views[2].texture.msl_texture_n = 2; + desc.views[3].texture.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[3].texture.image_type = SG_IMAGETYPE_2D; + desc.views[3].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[3].texture.multisampled = false; + desc.views[3].texture.msl_texture_n = 3; + desc.samplers[0].stage = SG_SHADERSTAGE_COMPUTE; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[0].msl_sampler_n = 0; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_COMPUTE; + desc.texture_sampler_pairs[0].view_slot = 2; + desc.texture_sampler_pairs[0].sampler_slot = 0; + desc.texture_sampler_pairs[1].stage = SG_SHADERSTAGE_COMPUTE; + desc.texture_sampler_pairs[1].view_slot = 3; + desc.texture_sampler_pairs[1].sampler_slot = 0; + desc.label = "gtao_main_pass_prog_shader"; + } + return &desc; + } + return 0; +} diff --git a/samples/shaders/generated/gtao_prefilter_depth.glsl.h b/samples/shaders/generated/gtao_prefilter_depth.glsl.h new file mode 100644 index 0000000..b2bf72a --- /dev/null +++ b/samples/shaders/generated/gtao_prefilter_depth.glsl.h @@ -0,0 +1,1827 @@ +#pragma once +/* + #version:1# (machine generated, don't edit!) + + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) + + Cmdline: + sokol-shdc --input E:/box/box3d/samples/shaders/post/gtao_prefilter_depth.glsl --output E:/box/box3d/samples/shaders/generated/gtao_prefilter_depth.glsl.h --slang hlsl5:metal_macos:glsl430 + + Overview: + ========= + Shader program: 'prog': + Get shader desc: gtao_prefilter_depth_prog_shader_desc(sg_query_backend()); + Compute Shader: cs + Bindings: + Uniform block 'ub_gtao': + C struct: gtao_prefilter_depth_ub_gtao_t + Bind slot: UB_gtao_prefilter_depth_ub_gtao => 0 + Storage image 'out_depth0': + Bind slot: VIEW_gtao_prefilter_depth_out_depth0 => 0 + Image type: SG_IMAGETYPE_2D + Access format: SG_PIXELFORMAT_R32F + Writeonly: true + Storage image 'out_depth1': + Bind slot: VIEW_gtao_prefilter_depth_out_depth1 => 1 + Image type: SG_IMAGETYPE_2D + Access format: SG_PIXELFORMAT_R32F + Writeonly: true + Storage image 'out_depth2': + Bind slot: VIEW_gtao_prefilter_depth_out_depth2 => 2 + Image type: SG_IMAGETYPE_2D + Access format: SG_PIXELFORMAT_R32F + Writeonly: true + Storage image 'out_depth3': + Bind slot: VIEW_gtao_prefilter_depth_out_depth3 => 3 + Image type: SG_IMAGETYPE_2D + Access format: SG_PIXELFORMAT_R32F + Writeonly: true + Storage image 'out_depth4': + Bind slot: VIEW_gtao_prefilter_depth_out_depth4 => 4 + Image type: SG_IMAGETYPE_2D + Access format: SG_PIXELFORMAT_R32F + Writeonly: true + Texture 'tex_src_depth': + Image type: SG_IMAGETYPE_2D + Sample type: SG_IMAGESAMPLETYPE_FLOAT + Multisampled: false + Bind slot: VIEW_gtao_prefilter_depth_tex_src_depth => 5 + Sampler 'smp_src_depth': + Type: SG_SAMPLERTYPE_FILTERING + Bind slot: SMP_gtao_prefilter_depth_smp_src_depth => 0 +*/ +#if !defined(SOKOL_GFX_INCLUDED) +#error "Please include sokol_gfx.h before gtao_prefilter_depth.glsl.h" +#endif +#if !defined(SOKOL_SHDC_ALIGN) +#if defined(_MSC_VER) +#define SOKOL_SHDC_ALIGN(a) __declspec(align(a)) +#else +#define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) +#endif +#endif +#define UB_gtao_prefilter_depth_ub_gtao (0) +#define VIEW_gtao_prefilter_depth_out_depth0 (0) +#define VIEW_gtao_prefilter_depth_out_depth1 (1) +#define VIEW_gtao_prefilter_depth_out_depth2 (2) +#define VIEW_gtao_prefilter_depth_out_depth3 (3) +#define VIEW_gtao_prefilter_depth_out_depth4 (4) +#define VIEW_gtao_prefilter_depth_tex_src_depth (5) +#define SMP_gtao_prefilter_depth_smp_src_depth (0) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct gtao_prefilter_depth_ub_gtao_t { + int ViewportSize[2]; + float EffectRadius; + float EffectFalloffRange; + float RadiusMultiplier; + uint8_t _pad_20[12]; +} gtao_prefilter_depth_ub_gtao_t; +#pragma pack(pop) +/* + #version 430 + layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; + + struct ub_gtao + { + ivec2 ViewportSize; + float EffectRadius; + float EffectFalloffRange; + float RadiusMultiplier; + }; + + uniform ub_gtao gtao; + + layout(binding = 0, r32f) uniform writeonly image2D out_depth0; + layout(binding = 1, r32f) uniform writeonly image2D out_depth1; + layout(binding = 2, r32f) uniform writeonly image2D out_depth2; + layout(binding = 3, r32f) uniform writeonly image2D out_depth3; + layout(binding = 4, r32f) uniform writeonly image2D out_depth4; + layout(binding = 0) uniform sampler2D tex_src_depth_smp_src_depth; + + shared float g_scratchDepths[8][8]; + + float XeGTAO_ClampDepth(float depth) + { + return clamp(depth, 0.0, 3.4028234663852885981170418348452e+38); + } + + float XeGTAO_DepthMIPFilter(float depth0, float depth1, float depth2, float depth3) + { + float _32 = max(max(depth0, depth1), max(depth2, depth3)); + float _48 = (0.75 * gtao.EffectRadius) * gtao.RadiusMultiplier; + float _54 = gtao.EffectFalloffRange * _48; + float _65 = (-1.0) / _54; + float _70 = ((_48 * (1.0 - gtao.EffectFalloffRange)) / _54) + 1.0; + float _79 = clamp(((_32 - depth0) * _65) + _70, 0.0, 1.0); + float _88 = clamp(((_32 - depth1) * _65) + _70, 0.0, 1.0); + float _97 = clamp(((_32 - depth2) * _65) + _70, 0.0, 1.0); + float _106 = clamp(((_32 - depth3) * _65) + _70, 0.0, 1.0); + return ((((_79 * depth0) + (_88 * depth1)) + (_97 * depth2)) + (_106 * depth3)) / (((_79 + _88) + _97) + _106); + } + + void main() + { + ivec2 _143 = ivec2(gl_GlobalInvocationID.xy); + ivec2 _148 = ivec2(gl_LocalInvocationID.xy); + ivec2 _155 = gtao.ViewportSize - ivec2(1); + ivec2 _159 = _143 * ivec2(2); + ivec2 _169 = _159 + ivec2(1, 0); + ivec2 _175 = _159 + ivec2(0, 1); + ivec2 _181 = _159 + ivec2(1); + float param = texelFetch(tex_src_depth_smp_src_depth, clamp(_159, ivec2(0), _155), 0).x; + float _202 = XeGTAO_ClampDepth(param); + float param_1 = texelFetch(tex_src_depth_smp_src_depth, clamp(_169, ivec2(0), _155), 0).x; + float _212 = XeGTAO_ClampDepth(param_1); + float param_2 = texelFetch(tex_src_depth_smp_src_depth, clamp(_175, ivec2(0), _155), 0).x; + float _222 = XeGTAO_ClampDepth(param_2); + float param_3 = texelFetch(tex_src_depth_smp_src_depth, clamp(_181, ivec2(0), _155), 0).x; + float _232 = XeGTAO_ClampDepth(param_3); + if (all(lessThan(_159, gtao.ViewportSize))) + { + imageStore(out_depth0, _159, vec4(_202, 0.0, 0.0, 0.0)); + } + if (all(lessThan(_169, gtao.ViewportSize))) + { + imageStore(out_depth0, _169, vec4(_212, 0.0, 0.0, 0.0)); + } + if (all(lessThan(_175, gtao.ViewportSize))) + { + imageStore(out_depth0, _175, vec4(_222, 0.0, 0.0, 0.0)); + } + if (all(lessThan(_181, gtao.ViewportSize))) + { + imageStore(out_depth0, _181, vec4(_232, 0.0, 0.0, 0.0)); + } + float param_4 = _202; + float param_5 = _212; + float param_6 = _222; + float param_7 = _232; + float _299 = XeGTAO_DepthMIPFilter(param_4, param_5, param_6, param_7); + if (all(lessThan(_143, gtao.ViewportSize))) + { + imageStore(out_depth1, _143, vec4(_299, 0.0, 0.0, 0.0)); + } + int _319 = _148.x; + int _322 = _148.y; + g_scratchDepths[_319][_322] = _299; + barrier(); + float dm2 = 0.0; + if (all(equal((_148 & ivec2(1)), ivec2(0)))) + { + int _350 = _319 + 1; + int _362 = _322 + 1; + float param_8 = g_scratchDepths[_319][_322]; + float param_9 = g_scratchDepths[_350][_322]; + float param_10 = g_scratchDepths[_319][_362]; + float param_11 = g_scratchDepths[_350][_362]; + dm2 = XeGTAO_DepthMIPFilter(param_8, param_9, param_10, param_11); + ivec2 _388 = ivec2(uvec2(_143) >> uvec2(1u)); + if (all(lessThan(_388, gtao.ViewportSize))) + { + imageStore(out_depth2, _388, vec4(dm2, 0.0, 0.0, 0.0)); + } + g_scratchDepths[_319][_322] = dm2; + } + barrier(); + float dm3 = 0.0; + if (all(equal((_148 & ivec2(3)), ivec2(0)))) + { + int _429 = _319 + 2; + int _441 = _322 + 2; + float param_12 = g_scratchDepths[_319][_322]; + float param_13 = g_scratchDepths[_429][_322]; + float param_14 = g_scratchDepths[_319][_441]; + float param_15 = g_scratchDepths[_429][_441]; + dm3 = XeGTAO_DepthMIPFilter(param_12, param_13, param_14, param_15); + ivec2 _467 = ivec2(uvec2(_143) >> uvec2(2u)); + if (all(lessThan(_467, gtao.ViewportSize))) + { + imageStore(out_depth3, _467, vec4(dm3, 0.0, 0.0, 0.0)); + } + g_scratchDepths[_319][_322] = dm3; + } + barrier(); + if (all(equal(_148, ivec2(0)))) + { + float param_16 = g_scratchDepths[0][0]; + float param_17 = g_scratchDepths[4][0]; + float param_18 = g_scratchDepths[0][4]; + float param_19 = g_scratchDepths[4][4]; + ivec2 _520 = ivec2(uvec2(_143) >> uvec2(3u)); + if (all(lessThan(_520, gtao.ViewportSize))) + { + imageStore(out_depth4, _520, vec4(XeGTAO_DepthMIPFilter(param_16, param_17, param_18, param_19), 0.0, 0.0, 0.0)); + } + } + } + +*/ +static const uint8_t gtao_prefilter_depth_cs_source_glsl430[5128] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x6c,0x61,0x79, + 0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x6c,0x5f,0x73,0x69,0x7a,0x65,0x5f,0x78, + 0x20,0x3d,0x20,0x38,0x2c,0x20,0x6c,0x6f,0x63,0x61,0x6c,0x5f,0x73,0x69,0x7a,0x65, + 0x5f,0x79,0x20,0x3d,0x20,0x38,0x2c,0x20,0x6c,0x6f,0x63,0x61,0x6c,0x5f,0x73,0x69, + 0x7a,0x65,0x5f,0x7a,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x3b,0x0a,0x0a,0x73, + 0x74,0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x67,0x74,0x61,0x6f,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x76,0x65,0x63,0x32,0x20,0x56,0x69,0x65,0x77,0x70,0x6f, + 0x72,0x74,0x53,0x69,0x7a,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x45,0x66,0x66,0x65,0x63,0x74,0x52,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x45,0x66,0x66,0x65,0x63,0x74, + 0x46,0x61,0x6c,0x6c,0x6f,0x66,0x66,0x52,0x61,0x6e,0x67,0x65,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x52,0x61,0x64,0x69,0x75,0x73,0x4d,0x75, + 0x6c,0x74,0x69,0x70,0x6c,0x69,0x65,0x72,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x75,0x6e, + 0x69,0x66,0x6f,0x72,0x6d,0x20,0x75,0x62,0x5f,0x67,0x74,0x61,0x6f,0x20,0x67,0x74, + 0x61,0x6f,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64, + 0x69,0x6e,0x67,0x20,0x3d,0x20,0x30,0x2c,0x20,0x72,0x33,0x32,0x66,0x29,0x20,0x75, + 0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x77,0x72,0x69,0x74,0x65,0x6f,0x6e,0x6c,0x79, + 0x20,0x69,0x6d,0x61,0x67,0x65,0x32,0x44,0x20,0x6f,0x75,0x74,0x5f,0x64,0x65,0x70, + 0x74,0x68,0x30,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64, + 0x69,0x6e,0x67,0x20,0x3d,0x20,0x31,0x2c,0x20,0x72,0x33,0x32,0x66,0x29,0x20,0x75, + 0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x77,0x72,0x69,0x74,0x65,0x6f,0x6e,0x6c,0x79, + 0x20,0x69,0x6d,0x61,0x67,0x65,0x32,0x44,0x20,0x6f,0x75,0x74,0x5f,0x64,0x65,0x70, + 0x74,0x68,0x31,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64, + 0x69,0x6e,0x67,0x20,0x3d,0x20,0x32,0x2c,0x20,0x72,0x33,0x32,0x66,0x29,0x20,0x75, + 0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x77,0x72,0x69,0x74,0x65,0x6f,0x6e,0x6c,0x79, + 0x20,0x69,0x6d,0x61,0x67,0x65,0x32,0x44,0x20,0x6f,0x75,0x74,0x5f,0x64,0x65,0x70, + 0x74,0x68,0x32,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64, + 0x69,0x6e,0x67,0x20,0x3d,0x20,0x33,0x2c,0x20,0x72,0x33,0x32,0x66,0x29,0x20,0x75, + 0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x77,0x72,0x69,0x74,0x65,0x6f,0x6e,0x6c,0x79, + 0x20,0x69,0x6d,0x61,0x67,0x65,0x32,0x44,0x20,0x6f,0x75,0x74,0x5f,0x64,0x65,0x70, + 0x74,0x68,0x33,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64, + 0x69,0x6e,0x67,0x20,0x3d,0x20,0x34,0x2c,0x20,0x72,0x33,0x32,0x66,0x29,0x20,0x75, + 0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x77,0x72,0x69,0x74,0x65,0x6f,0x6e,0x6c,0x79, + 0x20,0x69,0x6d,0x61,0x67,0x65,0x32,0x44,0x20,0x6f,0x75,0x74,0x5f,0x64,0x65,0x70, + 0x74,0x68,0x34,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64, + 0x69,0x6e,0x67,0x20,0x3d,0x20,0x30,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d, + 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x73, + 0x72,0x63,0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x72,0x63, + 0x5f,0x64,0x65,0x70,0x74,0x68,0x3b,0x0a,0x0a,0x73,0x68,0x61,0x72,0x65,0x64,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x5f,0x73,0x63,0x72,0x61,0x74,0x63,0x68,0x44, + 0x65,0x70,0x74,0x68,0x73,0x5b,0x38,0x5d,0x5b,0x38,0x5d,0x3b,0x0a,0x0a,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x6c,0x61,0x6d,0x70, + 0x44,0x65,0x70,0x74,0x68,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x64,0x65,0x70,0x74, + 0x68,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x63,0x6c,0x61,0x6d,0x70,0x28,0x64,0x65,0x70,0x74,0x68,0x2c,0x20,0x30,0x2e,0x30, + 0x2c,0x20,0x33,0x2e,0x34,0x30,0x32,0x38,0x32,0x33,0x34,0x36,0x36,0x33,0x38,0x35, + 0x32,0x38,0x38,0x35,0x39,0x38,0x31,0x31,0x37,0x30,0x34,0x31,0x38,0x33,0x34,0x38, + 0x34,0x35,0x32,0x65,0x2b,0x33,0x38,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x44,0x65,0x70,0x74,0x68,0x4d, + 0x49,0x50,0x46,0x69,0x6c,0x74,0x65,0x72,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x64, + 0x65,0x70,0x74,0x68,0x30,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x64,0x65,0x70, + 0x74,0x68,0x31,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x64,0x65,0x70,0x74,0x68, + 0x32,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x64,0x65,0x70,0x74,0x68,0x33,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x33,0x32, + 0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x6d,0x61,0x78,0x28,0x64,0x65,0x70,0x74,0x68, + 0x30,0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x31,0x29,0x2c,0x20,0x6d,0x61,0x78,0x28, + 0x64,0x65,0x70,0x74,0x68,0x32,0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x33,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x38,0x20, + 0x3d,0x20,0x28,0x30,0x2e,0x37,0x35,0x20,0x2a,0x20,0x67,0x74,0x61,0x6f,0x2e,0x45, + 0x66,0x66,0x65,0x63,0x74,0x52,0x61,0x64,0x69,0x75,0x73,0x29,0x20,0x2a,0x20,0x67, + 0x74,0x61,0x6f,0x2e,0x52,0x61,0x64,0x69,0x75,0x73,0x4d,0x75,0x6c,0x74,0x69,0x70, + 0x6c,0x69,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x35,0x34,0x20,0x3d,0x20,0x67,0x74,0x61,0x6f,0x2e,0x45,0x66,0x66,0x65,0x63, + 0x74,0x46,0x61,0x6c,0x6c,0x6f,0x66,0x66,0x52,0x61,0x6e,0x67,0x65,0x20,0x2a,0x20, + 0x5f,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x36,0x35,0x20,0x3d,0x20,0x28,0x2d,0x31,0x2e,0x30,0x29,0x20,0x2f,0x20,0x5f,0x35, + 0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x30, + 0x20,0x3d,0x20,0x28,0x28,0x5f,0x34,0x38,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20, + 0x2d,0x20,0x67,0x74,0x61,0x6f,0x2e,0x45,0x66,0x66,0x65,0x63,0x74,0x46,0x61,0x6c, + 0x6c,0x6f,0x66,0x66,0x52,0x61,0x6e,0x67,0x65,0x29,0x29,0x20,0x2f,0x20,0x5f,0x35, + 0x34,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x37,0x39,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28, + 0x28,0x28,0x5f,0x33,0x32,0x20,0x2d,0x20,0x64,0x65,0x70,0x74,0x68,0x30,0x29,0x20, + 0x2a,0x20,0x5f,0x36,0x35,0x29,0x20,0x2b,0x20,0x5f,0x37,0x30,0x2c,0x20,0x30,0x2e, + 0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x38,0x38,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x28, + 0x28,0x5f,0x33,0x32,0x20,0x2d,0x20,0x64,0x65,0x70,0x74,0x68,0x31,0x29,0x20,0x2a, + 0x20,0x5f,0x36,0x35,0x29,0x20,0x2b,0x20,0x5f,0x37,0x30,0x2c,0x20,0x30,0x2e,0x30, + 0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x39,0x37,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x28,0x28, + 0x5f,0x33,0x32,0x20,0x2d,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x29,0x20,0x2a,0x20, + 0x5f,0x36,0x35,0x29,0x20,0x2b,0x20,0x5f,0x37,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c, + 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x30,0x36,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x28,0x28, + 0x5f,0x33,0x32,0x20,0x2d,0x20,0x64,0x65,0x70,0x74,0x68,0x33,0x29,0x20,0x2a,0x20, + 0x5f,0x36,0x35,0x29,0x20,0x2b,0x20,0x5f,0x37,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c, + 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x28,0x28,0x28,0x28,0x5f,0x37,0x39,0x20,0x2a,0x20,0x64,0x65,0x70,0x74, + 0x68,0x30,0x29,0x20,0x2b,0x20,0x28,0x5f,0x38,0x38,0x20,0x2a,0x20,0x64,0x65,0x70, + 0x74,0x68,0x31,0x29,0x29,0x20,0x2b,0x20,0x28,0x5f,0x39,0x37,0x20,0x2a,0x20,0x64, + 0x65,0x70,0x74,0x68,0x32,0x29,0x29,0x20,0x2b,0x20,0x28,0x5f,0x31,0x30,0x36,0x20, + 0x2a,0x20,0x64,0x65,0x70,0x74,0x68,0x33,0x29,0x29,0x20,0x2f,0x20,0x28,0x28,0x28, + 0x5f,0x37,0x39,0x20,0x2b,0x20,0x5f,0x38,0x38,0x29,0x20,0x2b,0x20,0x5f,0x39,0x37, + 0x29,0x20,0x2b,0x20,0x5f,0x31,0x30,0x36,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f, + 0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x76,0x65,0x63,0x32,0x20,0x5f,0x31,0x34,0x33,0x20,0x3d,0x20,0x69,0x76,0x65, + 0x63,0x32,0x28,0x67,0x6c,0x5f,0x47,0x6c,0x6f,0x62,0x61,0x6c,0x49,0x6e,0x76,0x6f, + 0x63,0x61,0x74,0x69,0x6f,0x6e,0x49,0x44,0x2e,0x78,0x79,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x76,0x65,0x63,0x32,0x20,0x5f,0x31,0x34,0x38,0x20,0x3d,0x20,0x69, + 0x76,0x65,0x63,0x32,0x28,0x67,0x6c,0x5f,0x4c,0x6f,0x63,0x61,0x6c,0x49,0x6e,0x76, + 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x49,0x44,0x2e,0x78,0x79,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x76,0x65,0x63,0x32,0x20,0x5f,0x31,0x35,0x35,0x20,0x3d,0x20, + 0x67,0x74,0x61,0x6f,0x2e,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a, + 0x65,0x20,0x2d,0x20,0x69,0x76,0x65,0x63,0x32,0x28,0x31,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x76,0x65,0x63,0x32,0x20,0x5f,0x31,0x35,0x39,0x20,0x3d,0x20,0x5f, + 0x31,0x34,0x33,0x20,0x2a,0x20,0x69,0x76,0x65,0x63,0x32,0x28,0x32,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x76,0x65,0x63,0x32,0x20,0x5f,0x31,0x36,0x39,0x20,0x3d, + 0x20,0x5f,0x31,0x35,0x39,0x20,0x2b,0x20,0x69,0x76,0x65,0x63,0x32,0x28,0x31,0x2c, + 0x20,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x76,0x65,0x63,0x32,0x20,0x5f, + 0x31,0x37,0x35,0x20,0x3d,0x20,0x5f,0x31,0x35,0x39,0x20,0x2b,0x20,0x69,0x76,0x65, + 0x63,0x32,0x28,0x30,0x2c,0x20,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x76, + 0x65,0x63,0x32,0x20,0x5f,0x31,0x38,0x31,0x20,0x3d,0x20,0x5f,0x31,0x35,0x39,0x20, + 0x2b,0x20,0x69,0x76,0x65,0x63,0x32,0x28,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x74,0x65, + 0x78,0x65,0x6c,0x46,0x65,0x74,0x63,0x68,0x28,0x74,0x65,0x78,0x5f,0x73,0x72,0x63, + 0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x72,0x63,0x5f,0x64, + 0x65,0x70,0x74,0x68,0x2c,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x5f,0x31,0x35,0x39, + 0x2c,0x20,0x69,0x76,0x65,0x63,0x32,0x28,0x30,0x29,0x2c,0x20,0x5f,0x31,0x35,0x35, + 0x29,0x2c,0x20,0x30,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x32,0x30,0x32,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f, + 0x5f,0x43,0x6c,0x61,0x6d,0x70,0x44,0x65,0x70,0x74,0x68,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x74,0x65,0x78,0x65,0x6c,0x46,0x65,0x74, + 0x63,0x68,0x28,0x74,0x65,0x78,0x5f,0x73,0x72,0x63,0x5f,0x64,0x65,0x70,0x74,0x68, + 0x5f,0x73,0x6d,0x70,0x5f,0x73,0x72,0x63,0x5f,0x64,0x65,0x70,0x74,0x68,0x2c,0x20, + 0x63,0x6c,0x61,0x6d,0x70,0x28,0x5f,0x31,0x36,0x39,0x2c,0x20,0x69,0x76,0x65,0x63, + 0x32,0x28,0x30,0x29,0x2c,0x20,0x5f,0x31,0x35,0x35,0x29,0x2c,0x20,0x30,0x29,0x2e, + 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31, + 0x32,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x6c,0x61,0x6d,0x70, + 0x44,0x65,0x70,0x74,0x68,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x20,0x3d,0x20,0x74,0x65,0x78,0x65,0x6c,0x46,0x65,0x74,0x63,0x68,0x28,0x74, + 0x65,0x78,0x5f,0x73,0x72,0x63,0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x73,0x6d,0x70, + 0x5f,0x73,0x72,0x63,0x5f,0x64,0x65,0x70,0x74,0x68,0x2c,0x20,0x63,0x6c,0x61,0x6d, + 0x70,0x28,0x5f,0x31,0x37,0x35,0x2c,0x20,0x69,0x76,0x65,0x63,0x32,0x28,0x30,0x29, + 0x2c,0x20,0x5f,0x31,0x35,0x35,0x29,0x2c,0x20,0x30,0x29,0x2e,0x78,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x32,0x32,0x20,0x3d,0x20, + 0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x6c,0x61,0x6d,0x70,0x44,0x65,0x70,0x74, + 0x68,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20, + 0x74,0x65,0x78,0x65,0x6c,0x46,0x65,0x74,0x63,0x68,0x28,0x74,0x65,0x78,0x5f,0x73, + 0x72,0x63,0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x72,0x63, + 0x5f,0x64,0x65,0x70,0x74,0x68,0x2c,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x5f,0x31, + 0x38,0x31,0x2c,0x20,0x69,0x76,0x65,0x63,0x32,0x28,0x30,0x29,0x2c,0x20,0x5f,0x31, + 0x35,0x35,0x29,0x2c,0x20,0x30,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x33,0x32,0x20,0x3d,0x20,0x58,0x65,0x47,0x54, + 0x41,0x4f,0x5f,0x43,0x6c,0x61,0x6d,0x70,0x44,0x65,0x70,0x74,0x68,0x28,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x61,0x6c,0x6c,0x28,0x6c,0x65,0x73,0x73,0x54,0x68,0x61,0x6e,0x28,0x5f,0x31,0x35, + 0x39,0x2c,0x20,0x67,0x74,0x61,0x6f,0x2e,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74, + 0x53,0x69,0x7a,0x65,0x29,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6d,0x61,0x67,0x65,0x53,0x74,0x6f,0x72,0x65, + 0x28,0x6f,0x75,0x74,0x5f,0x64,0x65,0x70,0x74,0x68,0x30,0x2c,0x20,0x5f,0x31,0x35, + 0x39,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x32,0x30,0x32,0x2c,0x20,0x30,0x2e, + 0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x61,0x6c,0x6c, + 0x28,0x6c,0x65,0x73,0x73,0x54,0x68,0x61,0x6e,0x28,0x5f,0x31,0x36,0x39,0x2c,0x20, + 0x67,0x74,0x61,0x6f,0x2e,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a, + 0x65,0x29,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x6d,0x61,0x67,0x65,0x53,0x74,0x6f,0x72,0x65,0x28,0x6f,0x75, + 0x74,0x5f,0x64,0x65,0x70,0x74,0x68,0x30,0x2c,0x20,0x5f,0x31,0x36,0x39,0x2c,0x20, + 0x76,0x65,0x63,0x34,0x28,0x5f,0x32,0x31,0x32,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20, + 0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x61,0x6c,0x6c,0x28,0x6c,0x65, + 0x73,0x73,0x54,0x68,0x61,0x6e,0x28,0x5f,0x31,0x37,0x35,0x2c,0x20,0x67,0x74,0x61, + 0x6f,0x2e,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65,0x29,0x29, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x69,0x6d,0x61,0x67,0x65,0x53,0x74,0x6f,0x72,0x65,0x28,0x6f,0x75,0x74,0x5f,0x64, + 0x65,0x70,0x74,0x68,0x30,0x2c,0x20,0x5f,0x31,0x37,0x35,0x2c,0x20,0x76,0x65,0x63, + 0x34,0x28,0x5f,0x32,0x32,0x32,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30, + 0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x61,0x6c,0x6c,0x28,0x6c,0x65,0x73,0x73,0x54, + 0x68,0x61,0x6e,0x28,0x5f,0x31,0x38,0x31,0x2c,0x20,0x67,0x74,0x61,0x6f,0x2e,0x56, + 0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65,0x29,0x29,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6d,0x61, + 0x67,0x65,0x53,0x74,0x6f,0x72,0x65,0x28,0x6f,0x75,0x74,0x5f,0x64,0x65,0x70,0x74, + 0x68,0x30,0x2c,0x20,0x5f,0x31,0x38,0x31,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x5f, + 0x32,0x33,0x32,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30, + 0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20, + 0x5f,0x32,0x30,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x5f,0x32,0x31,0x32,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x36,0x20,0x3d,0x20,0x5f,0x32,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x5f,0x32, + 0x33,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32, + 0x39,0x39,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x44,0x65,0x70,0x74, + 0x68,0x4d,0x49,0x50,0x46,0x69,0x6c,0x74,0x65,0x72,0x28,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x61,0x6c,0x6c,0x28,0x6c,0x65,0x73,0x73, + 0x54,0x68,0x61,0x6e,0x28,0x5f,0x31,0x34,0x33,0x2c,0x20,0x67,0x74,0x61,0x6f,0x2e, + 0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65,0x29,0x29,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6d, + 0x61,0x67,0x65,0x53,0x74,0x6f,0x72,0x65,0x28,0x6f,0x75,0x74,0x5f,0x64,0x65,0x70, + 0x74,0x68,0x31,0x2c,0x20,0x5f,0x31,0x34,0x33,0x2c,0x20,0x76,0x65,0x63,0x34,0x28, + 0x5f,0x32,0x39,0x39,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20, + 0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x6e,0x74,0x20,0x5f,0x33,0x31,0x39,0x20,0x3d,0x20,0x5f,0x31,0x34,0x38, + 0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x33,0x32,0x32, + 0x20,0x3d,0x20,0x5f,0x31,0x34,0x38,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67, + 0x5f,0x73,0x63,0x72,0x61,0x74,0x63,0x68,0x44,0x65,0x70,0x74,0x68,0x73,0x5b,0x5f, + 0x33,0x31,0x39,0x5d,0x5b,0x5f,0x33,0x32,0x32,0x5d,0x20,0x3d,0x20,0x5f,0x32,0x39, + 0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x61,0x72,0x72,0x69,0x65,0x72,0x28,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x64,0x6d,0x32,0x20, + 0x3d,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x61, + 0x6c,0x6c,0x28,0x65,0x71,0x75,0x61,0x6c,0x28,0x28,0x5f,0x31,0x34,0x38,0x20,0x26, + 0x20,0x69,0x76,0x65,0x63,0x32,0x28,0x31,0x29,0x29,0x2c,0x20,0x69,0x76,0x65,0x63, + 0x32,0x28,0x30,0x29,0x29,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x33,0x35,0x30,0x20,0x3d, + 0x20,0x5f,0x33,0x31,0x39,0x20,0x2b,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x33,0x36,0x32,0x20,0x3d,0x20,0x5f,0x33, + 0x32,0x32,0x20,0x2b,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20, + 0x67,0x5f,0x73,0x63,0x72,0x61,0x74,0x63,0x68,0x44,0x65,0x70,0x74,0x68,0x73,0x5b, + 0x5f,0x33,0x31,0x39,0x5d,0x5b,0x5f,0x33,0x32,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x39,0x20,0x3d,0x20,0x67,0x5f,0x73,0x63,0x72,0x61,0x74,0x63,0x68,0x44,0x65, + 0x70,0x74,0x68,0x73,0x5b,0x5f,0x33,0x35,0x30,0x5d,0x5b,0x5f,0x33,0x32,0x32,0x5d, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x67,0x5f,0x73,0x63,0x72, + 0x61,0x74,0x63,0x68,0x44,0x65,0x70,0x74,0x68,0x73,0x5b,0x5f,0x33,0x31,0x39,0x5d, + 0x5b,0x5f,0x33,0x36,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d, + 0x20,0x67,0x5f,0x73,0x63,0x72,0x61,0x74,0x63,0x68,0x44,0x65,0x70,0x74,0x68,0x73, + 0x5b,0x5f,0x33,0x35,0x30,0x5d,0x5b,0x5f,0x33,0x36,0x32,0x5d,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x64,0x6d,0x32,0x20,0x3d,0x20,0x58,0x65,0x47,0x54, + 0x41,0x4f,0x5f,0x44,0x65,0x70,0x74,0x68,0x4d,0x49,0x50,0x46,0x69,0x6c,0x74,0x65, + 0x72,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x69,0x76,0x65,0x63,0x32,0x20,0x5f,0x33,0x38,0x38,0x20,0x3d,0x20,0x69,0x76, + 0x65,0x63,0x32,0x28,0x75,0x76,0x65,0x63,0x32,0x28,0x5f,0x31,0x34,0x33,0x29,0x20, + 0x3e,0x3e,0x20,0x75,0x76,0x65,0x63,0x32,0x28,0x31,0x75,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x61,0x6c,0x6c,0x28,0x6c, + 0x65,0x73,0x73,0x54,0x68,0x61,0x6e,0x28,0x5f,0x33,0x38,0x38,0x2c,0x20,0x67,0x74, + 0x61,0x6f,0x2e,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65,0x29, + 0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6d,0x61,0x67,0x65,0x53,0x74, + 0x6f,0x72,0x65,0x28,0x6f,0x75,0x74,0x5f,0x64,0x65,0x70,0x74,0x68,0x32,0x2c,0x20, + 0x5f,0x33,0x38,0x38,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x64,0x6d,0x32,0x2c,0x20, + 0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x67,0x5f,0x73,0x63,0x72,0x61,0x74,0x63,0x68,0x44,0x65,0x70,0x74, + 0x68,0x73,0x5b,0x5f,0x33,0x31,0x39,0x5d,0x5b,0x5f,0x33,0x32,0x32,0x5d,0x20,0x3d, + 0x20,0x64,0x6d,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x62,0x61,0x72,0x72,0x69,0x65,0x72,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x64,0x6d,0x33,0x20,0x3d,0x20,0x30,0x2e,0x30,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x61,0x6c,0x6c,0x28,0x65,0x71,0x75,0x61, + 0x6c,0x28,0x28,0x5f,0x31,0x34,0x38,0x20,0x26,0x20,0x69,0x76,0x65,0x63,0x32,0x28, + 0x33,0x29,0x29,0x2c,0x20,0x69,0x76,0x65,0x63,0x32,0x28,0x30,0x29,0x29,0x29,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x6e,0x74,0x20,0x5f,0x34,0x32,0x39,0x20,0x3d,0x20,0x5f,0x33,0x31,0x39,0x20,0x2b, + 0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20, + 0x5f,0x34,0x34,0x31,0x20,0x3d,0x20,0x5f,0x33,0x32,0x32,0x20,0x2b,0x20,0x32,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x67,0x5f,0x73,0x63,0x72,0x61, + 0x74,0x63,0x68,0x44,0x65,0x70,0x74,0x68,0x73,0x5b,0x5f,0x33,0x31,0x39,0x5d,0x5b, + 0x5f,0x33,0x32,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20, + 0x67,0x5f,0x73,0x63,0x72,0x61,0x74,0x63,0x68,0x44,0x65,0x70,0x74,0x68,0x73,0x5b, + 0x5f,0x34,0x32,0x39,0x5d,0x5b,0x5f,0x33,0x32,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x34,0x20,0x3d,0x20,0x67,0x5f,0x73,0x63,0x72,0x61,0x74,0x63,0x68,0x44, + 0x65,0x70,0x74,0x68,0x73,0x5b,0x5f,0x33,0x31,0x39,0x5d,0x5b,0x5f,0x34,0x34,0x31, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x67,0x5f,0x73,0x63, + 0x72,0x61,0x74,0x63,0x68,0x44,0x65,0x70,0x74,0x68,0x73,0x5b,0x5f,0x34,0x32,0x39, + 0x5d,0x5b,0x5f,0x34,0x34,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x64,0x6d,0x33,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x44,0x65, + 0x70,0x74,0x68,0x4d,0x49,0x50,0x46,0x69,0x6c,0x74,0x65,0x72,0x28,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x76, + 0x65,0x63,0x32,0x20,0x5f,0x34,0x36,0x37,0x20,0x3d,0x20,0x69,0x76,0x65,0x63,0x32, + 0x28,0x75,0x76,0x65,0x63,0x32,0x28,0x5f,0x31,0x34,0x33,0x29,0x20,0x3e,0x3e,0x20, + 0x75,0x76,0x65,0x63,0x32,0x28,0x32,0x75,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x61,0x6c,0x6c,0x28,0x6c,0x65,0x73,0x73, + 0x54,0x68,0x61,0x6e,0x28,0x5f,0x34,0x36,0x37,0x2c,0x20,0x67,0x74,0x61,0x6f,0x2e, + 0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65,0x29,0x29,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6d,0x61,0x67,0x65,0x53,0x74,0x6f,0x72,0x65, + 0x28,0x6f,0x75,0x74,0x5f,0x64,0x65,0x70,0x74,0x68,0x33,0x2c,0x20,0x5f,0x34,0x36, + 0x37,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x64,0x6d,0x33,0x2c,0x20,0x30,0x2e,0x30, + 0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x67,0x5f,0x73,0x63,0x72,0x61,0x74,0x63,0x68,0x44,0x65,0x70,0x74,0x68,0x73,0x5b, + 0x5f,0x33,0x31,0x39,0x5d,0x5b,0x5f,0x33,0x32,0x32,0x5d,0x20,0x3d,0x20,0x64,0x6d, + 0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x62,0x61,0x72, + 0x72,0x69,0x65,0x72,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x61,0x6c,0x6c,0x28,0x65,0x71,0x75,0x61,0x6c,0x28,0x5f,0x31,0x34,0x38,0x2c,0x20, + 0x69,0x76,0x65,0x63,0x32,0x28,0x30,0x29,0x29,0x29,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x67,0x5f,0x73,0x63,0x72, + 0x61,0x74,0x63,0x68,0x44,0x65,0x70,0x74,0x68,0x73,0x5b,0x30,0x5d,0x5b,0x30,0x5d, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x20,0x3d,0x20,0x67,0x5f,0x73,0x63,0x72, + 0x61,0x74,0x63,0x68,0x44,0x65,0x70,0x74,0x68,0x73,0x5b,0x34,0x5d,0x5b,0x30,0x5d, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x67,0x5f,0x73,0x63,0x72, + 0x61,0x74,0x63,0x68,0x44,0x65,0x70,0x74,0x68,0x73,0x5b,0x30,0x5d,0x5b,0x34,0x5d, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20,0x67,0x5f,0x73,0x63,0x72, + 0x61,0x74,0x63,0x68,0x44,0x65,0x70,0x74,0x68,0x73,0x5b,0x34,0x5d,0x5b,0x34,0x5d, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x76,0x65,0x63,0x32,0x20, + 0x5f,0x35,0x32,0x30,0x20,0x3d,0x20,0x69,0x76,0x65,0x63,0x32,0x28,0x75,0x76,0x65, + 0x63,0x32,0x28,0x5f,0x31,0x34,0x33,0x29,0x20,0x3e,0x3e,0x20,0x75,0x76,0x65,0x63, + 0x32,0x28,0x33,0x75,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x61,0x6c,0x6c,0x28,0x6c,0x65,0x73,0x73,0x54,0x68,0x61,0x6e, + 0x28,0x5f,0x35,0x32,0x30,0x2c,0x20,0x67,0x74,0x61,0x6f,0x2e,0x56,0x69,0x65,0x77, + 0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65,0x29,0x29,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x69,0x6d,0x61,0x67,0x65,0x53,0x74,0x6f,0x72,0x65,0x28,0x6f,0x75,0x74, + 0x5f,0x64,0x65,0x70,0x74,0x68,0x34,0x2c,0x20,0x5f,0x35,0x32,0x30,0x2c,0x20,0x76, + 0x65,0x63,0x34,0x28,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x44,0x65,0x70,0x74,0x68, + 0x4d,0x49,0x50,0x46,0x69,0x6c,0x74,0x65,0x72,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39, + 0x29,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + static const uint3 gl_WorkGroupSize = uint3(8u, 8u, 1u); + + cbuffer ub_gtao : register(b0) + { + int2 gtao_ViewportSize : packoffset(c0); + float gtao_EffectRadius : packoffset(c0.z); + float gtao_EffectFalloffRange : packoffset(c0.w); + float gtao_RadiusMultiplier : packoffset(c1); + }; + + Texture2D tex_src_depth : register(t0); + SamplerState smp_src_depth : register(s0); + RWTexture2D out_depth0 : register(u0); + RWTexture2D out_depth1 : register(u1); + RWTexture2D out_depth2 : register(u2); + RWTexture2D out_depth3 : register(u3); + RWTexture2D out_depth4 : register(u4); + + static uint3 gl_LocalInvocationID; + static uint3 gl_GlobalInvocationID; + struct SPIRV_Cross_Input + { + uint3 gl_LocalInvocationID : SV_GroupThreadID; + uint3 gl_GlobalInvocationID : SV_DispatchThreadID; + }; + + groupshared float g_scratchDepths[8][8]; + + float XeGTAO_ClampDepth(float depth) + { + return clamp(depth, 0.0f, 3.4028234663852885981170418348452e+38f); + } + + float XeGTAO_DepthMIPFilter(float depth0, float depth1, float depth2, float depth3) + { + float _32 = max(max(depth0, depth1), max(depth2, depth3)); + float _48 = (0.75f * gtao_EffectRadius) * gtao_RadiusMultiplier; + float _54 = gtao_EffectFalloffRange * _48; + float _65 = (-1.0f) / _54; + float _70 = ((_48 * (1.0f - gtao_EffectFalloffRange)) / _54) + 1.0f; + float _79 = clamp(((_32 - depth0) * _65) + _70, 0.0f, 1.0f); + float _88 = clamp(((_32 - depth1) * _65) + _70, 0.0f, 1.0f); + float _97 = clamp(((_32 - depth2) * _65) + _70, 0.0f, 1.0f); + float _106 = clamp(((_32 - depth3) * _65) + _70, 0.0f, 1.0f); + return ((((_79 * depth0) + (_88 * depth1)) + (_97 * depth2)) + (_106 * depth3)) / (((_79 + _88) + _97) + _106); + } + + void comp_main() + { + int2 _143 = int2(gl_GlobalInvocationID.xy); + int2 _148 = int2(gl_LocalInvocationID.xy); + int2 _155 = gtao_ViewportSize - int2(1, 1); + int2 _159 = _143 * int2(2, 2); + int2 _169 = _159 + int2(1, 0); + int2 _175 = _159 + int2(0, 1); + int2 _181 = _159 + int2(1, 1); + float param = tex_src_depth.Load(int3(clamp(_159, int2(0, 0), _155), 0)).x; + float _202 = XeGTAO_ClampDepth(param); + float param_1 = tex_src_depth.Load(int3(clamp(_169, int2(0, 0), _155), 0)).x; + float _212 = XeGTAO_ClampDepth(param_1); + float param_2 = tex_src_depth.Load(int3(clamp(_175, int2(0, 0), _155), 0)).x; + float _222 = XeGTAO_ClampDepth(param_2); + float param_3 = tex_src_depth.Load(int3(clamp(_181, int2(0, 0), _155), 0)).x; + float _232 = XeGTAO_ClampDepth(param_3); + if (all(bool2(_159.x < gtao_ViewportSize.x, _159.y < gtao_ViewportSize.y))) + { + out_depth0[_159] = float4(_202, 0.0f, 0.0f, 0.0f).x; + } + if (all(bool2(_169.x < gtao_ViewportSize.x, _169.y < gtao_ViewportSize.y))) + { + out_depth0[_169] = float4(_212, 0.0f, 0.0f, 0.0f).x; + } + if (all(bool2(_175.x < gtao_ViewportSize.x, _175.y < gtao_ViewportSize.y))) + { + out_depth0[_175] = float4(_222, 0.0f, 0.0f, 0.0f).x; + } + if (all(bool2(_181.x < gtao_ViewportSize.x, _181.y < gtao_ViewportSize.y))) + { + out_depth0[_181] = float4(_232, 0.0f, 0.0f, 0.0f).x; + } + float param_4 = _202; + float param_5 = _212; + float param_6 = _222; + float param_7 = _232; + float _299 = XeGTAO_DepthMIPFilter(param_4, param_5, param_6, param_7); + if (all(bool2(_143.x < gtao_ViewportSize.x, _143.y < gtao_ViewportSize.y))) + { + out_depth1[_143] = float4(_299, 0.0f, 0.0f, 0.0f).x; + } + int _319 = _148.x; + int _322 = _148.y; + g_scratchDepths[_319][_322] = _299; + GroupMemoryBarrierWithGroupSync(); + float dm2 = 0.0f; + int2 _332 = _148 & int2(1, 1); + if (all(bool2(_332.x == int2(0, 0).x, _332.y == int2(0, 0).y))) + { + int _350 = _319 + 1; + int _362 = _322 + 1; + float param_8 = g_scratchDepths[_319][_322]; + float param_9 = g_scratchDepths[_350][_322]; + float param_10 = g_scratchDepths[_319][_362]; + float param_11 = g_scratchDepths[_350][_362]; + dm2 = XeGTAO_DepthMIPFilter(param_8, param_9, param_10, param_11); + int2 _388 = int2(uint2(_143) >> uint2(1u, 1u)); + if (all(bool2(_388.x < gtao_ViewportSize.x, _388.y < gtao_ViewportSize.y))) + { + out_depth2[_388] = float4(dm2, 0.0f, 0.0f, 0.0f).x; + } + g_scratchDepths[_319][_322] = dm2; + } + GroupMemoryBarrierWithGroupSync(); + float dm3 = 0.0f; + int2 _411 = _148 & int2(3, 3); + if (all(bool2(_411.x == int2(0, 0).x, _411.y == int2(0, 0).y))) + { + int _429 = _319 + 2; + int _441 = _322 + 2; + float param_12 = g_scratchDepths[_319][_322]; + float param_13 = g_scratchDepths[_429][_322]; + float param_14 = g_scratchDepths[_319][_441]; + float param_15 = g_scratchDepths[_429][_441]; + dm3 = XeGTAO_DepthMIPFilter(param_12, param_13, param_14, param_15); + int2 _467 = int2(uint2(_143) >> uint2(2u, 2u)); + if (all(bool2(_467.x < gtao_ViewportSize.x, _467.y < gtao_ViewportSize.y))) + { + out_depth3[_467] = float4(dm3, 0.0f, 0.0f, 0.0f).x; + } + g_scratchDepths[_319][_322] = dm3; + } + GroupMemoryBarrierWithGroupSync(); + if (all(bool2(_148.x == int2(0, 0).x, _148.y == int2(0, 0).y))) + { + float param_16 = g_scratchDepths[0][0]; + float param_17 = g_scratchDepths[4][0]; + float param_18 = g_scratchDepths[0][4]; + float param_19 = g_scratchDepths[4][4]; + int2 _520 = int2(uint2(_143) >> uint2(3u, 3u)); + if (all(bool2(_520.x < gtao_ViewportSize.x, _520.y < gtao_ViewportSize.y))) + { + out_depth4[_520] = float4(XeGTAO_DepthMIPFilter(param_16, param_17, param_18, param_19), 0.0f, 0.0f, 0.0f).x; + } + } + } + + [numthreads(8, 8, 1)] + void main(SPIRV_Cross_Input stage_input) + { + gl_LocalInvocationID = stage_input.gl_LocalInvocationID; + gl_GlobalInvocationID = stage_input.gl_GlobalInvocationID; + comp_main(); + } +*/ +static const uint8_t gtao_prefilter_depth_cs_source_hlsl5[5952] = { + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x75,0x69,0x6e, + 0x74,0x33,0x20,0x67,0x6c,0x5f,0x57,0x6f,0x72,0x6b,0x47,0x72,0x6f,0x75,0x70,0x53, + 0x69,0x7a,0x65,0x20,0x3d,0x20,0x75,0x69,0x6e,0x74,0x33,0x28,0x38,0x75,0x2c,0x20, + 0x38,0x75,0x2c,0x20,0x31,0x75,0x29,0x3b,0x0a,0x0a,0x63,0x62,0x75,0x66,0x66,0x65, + 0x72,0x20,0x75,0x62,0x5f,0x67,0x74,0x61,0x6f,0x20,0x3a,0x20,0x72,0x65,0x67,0x69, + 0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x6e,0x74,0x32,0x20,0x67,0x74,0x61,0x6f,0x5f,0x56,0x69,0x65,0x77,0x70,0x6f,0x72, + 0x74,0x53,0x69,0x7a,0x65,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73, + 0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x67,0x74,0x61,0x6f,0x5f,0x45,0x66,0x66,0x65,0x63,0x74,0x52,0x61,0x64, + 0x69,0x75,0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74, + 0x28,0x63,0x30,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x67,0x74,0x61,0x6f,0x5f,0x45,0x66,0x66,0x65,0x63,0x74,0x46,0x61,0x6c, + 0x6c,0x6f,0x66,0x66,0x52,0x61,0x6e,0x67,0x65,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b, + 0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x74,0x61,0x6f,0x5f,0x52,0x61,0x64, + 0x69,0x75,0x73,0x4d,0x75,0x6c,0x74,0x69,0x70,0x6c,0x69,0x65,0x72,0x20,0x3a,0x20, + 0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x29,0x3b,0x0a, + 0x7d,0x3b,0x0a,0x0a,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x72,0x63,0x5f,0x64,0x65, + 0x70,0x74,0x68,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74, + 0x30,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65, + 0x20,0x73,0x6d,0x70,0x5f,0x73,0x72,0x63,0x5f,0x64,0x65,0x70,0x74,0x68,0x20,0x3a, + 0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x30,0x29,0x3b,0x0a,0x52, + 0x57,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74, + 0x3e,0x20,0x6f,0x75,0x74,0x5f,0x64,0x65,0x70,0x74,0x68,0x30,0x20,0x3a,0x20,0x72, + 0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x75,0x30,0x29,0x3b,0x0a,0x52,0x57,0x54, + 0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20, + 0x6f,0x75,0x74,0x5f,0x64,0x65,0x70,0x74,0x68,0x31,0x20,0x3a,0x20,0x72,0x65,0x67, + 0x69,0x73,0x74,0x65,0x72,0x28,0x75,0x31,0x29,0x3b,0x0a,0x52,0x57,0x54,0x65,0x78, + 0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x6f,0x75, + 0x74,0x5f,0x64,0x65,0x70,0x74,0x68,0x32,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73, + 0x74,0x65,0x72,0x28,0x75,0x32,0x29,0x3b,0x0a,0x52,0x57,0x54,0x65,0x78,0x74,0x75, + 0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x6f,0x75,0x74,0x5f, + 0x64,0x65,0x70,0x74,0x68,0x33,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65, + 0x72,0x28,0x75,0x33,0x29,0x3b,0x0a,0x52,0x57,0x54,0x65,0x78,0x74,0x75,0x72,0x65, + 0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x6f,0x75,0x74,0x5f,0x64,0x65, + 0x70,0x74,0x68,0x34,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28, + 0x75,0x34,0x29,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x75,0x69,0x6e, + 0x74,0x33,0x20,0x67,0x6c,0x5f,0x4c,0x6f,0x63,0x61,0x6c,0x49,0x6e,0x76,0x6f,0x63, + 0x61,0x74,0x69,0x6f,0x6e,0x49,0x44,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, + 0x75,0x69,0x6e,0x74,0x33,0x20,0x67,0x6c,0x5f,0x47,0x6c,0x6f,0x62,0x61,0x6c,0x49, + 0x6e,0x76,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x49,0x44,0x3b,0x0a,0x73,0x74,0x72, + 0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, + 0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74, + 0x33,0x20,0x67,0x6c,0x5f,0x4c,0x6f,0x63,0x61,0x6c,0x49,0x6e,0x76,0x6f,0x63,0x61, + 0x74,0x69,0x6f,0x6e,0x49,0x44,0x20,0x3a,0x20,0x53,0x56,0x5f,0x47,0x72,0x6f,0x75, + 0x70,0x54,0x68,0x72,0x65,0x61,0x64,0x49,0x44,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75, + 0x69,0x6e,0x74,0x33,0x20,0x67,0x6c,0x5f,0x47,0x6c,0x6f,0x62,0x61,0x6c,0x49,0x6e, + 0x76,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x49,0x44,0x20,0x3a,0x20,0x53,0x56,0x5f, + 0x44,0x69,0x73,0x70,0x61,0x74,0x63,0x68,0x54,0x68,0x72,0x65,0x61,0x64,0x49,0x44, + 0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x67,0x72,0x6f,0x75,0x70,0x73,0x68,0x61,0x72,0x65, + 0x64,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x5f,0x73,0x63,0x72,0x61,0x74,0x63, + 0x68,0x44,0x65,0x70,0x74,0x68,0x73,0x5b,0x38,0x5d,0x5b,0x38,0x5d,0x3b,0x0a,0x0a, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x6c,0x61, + 0x6d,0x70,0x44,0x65,0x70,0x74,0x68,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x64,0x65, + 0x70,0x74,0x68,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x64,0x65,0x70,0x74,0x68,0x2c,0x20,0x30, + 0x2e,0x30,0x66,0x2c,0x20,0x33,0x2e,0x34,0x30,0x32,0x38,0x32,0x33,0x34,0x36,0x36, + 0x33,0x38,0x35,0x32,0x38,0x38,0x35,0x39,0x38,0x31,0x31,0x37,0x30,0x34,0x31,0x38, + 0x33,0x34,0x38,0x34,0x35,0x32,0x65,0x2b,0x33,0x38,0x66,0x29,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x44,0x65, + 0x70,0x74,0x68,0x4d,0x49,0x50,0x46,0x69,0x6c,0x74,0x65,0x72,0x28,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x64,0x65,0x70,0x74,0x68,0x30,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x64,0x65,0x70,0x74,0x68,0x31,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x64, + 0x65,0x70,0x74,0x68,0x32,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x64,0x65,0x70, + 0x74,0x68,0x33,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x33,0x32,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x6d,0x61,0x78,0x28,0x64, + 0x65,0x70,0x74,0x68,0x30,0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x31,0x29,0x2c,0x20, + 0x6d,0x61,0x78,0x28,0x64,0x65,0x70,0x74,0x68,0x32,0x2c,0x20,0x64,0x65,0x70,0x74, + 0x68,0x33,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x34,0x38,0x20,0x3d,0x20,0x28,0x30,0x2e,0x37,0x35,0x66,0x20,0x2a,0x20,0x67, + 0x74,0x61,0x6f,0x5f,0x45,0x66,0x66,0x65,0x63,0x74,0x52,0x61,0x64,0x69,0x75,0x73, + 0x29,0x20,0x2a,0x20,0x67,0x74,0x61,0x6f,0x5f,0x52,0x61,0x64,0x69,0x75,0x73,0x4d, + 0x75,0x6c,0x74,0x69,0x70,0x6c,0x69,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x34,0x20,0x3d,0x20,0x67,0x74,0x61,0x6f,0x5f, + 0x45,0x66,0x66,0x65,0x63,0x74,0x46,0x61,0x6c,0x6c,0x6f,0x66,0x66,0x52,0x61,0x6e, + 0x67,0x65,0x20,0x2a,0x20,0x5f,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x36,0x35,0x20,0x3d,0x20,0x28,0x2d,0x31,0x2e,0x30,0x66, + 0x29,0x20,0x2f,0x20,0x5f,0x35,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x37,0x30,0x20,0x3d,0x20,0x28,0x28,0x5f,0x34,0x38,0x20,0x2a, + 0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x67,0x74,0x61,0x6f,0x5f,0x45,0x66, + 0x66,0x65,0x63,0x74,0x46,0x61,0x6c,0x6c,0x6f,0x66,0x66,0x52,0x61,0x6e,0x67,0x65, + 0x29,0x29,0x20,0x2f,0x20,0x5f,0x35,0x34,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x66, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x39,0x20, + 0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x28,0x28,0x5f,0x33,0x32,0x20,0x2d,0x20, + 0x64,0x65,0x70,0x74,0x68,0x30,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x29,0x20,0x2b, + 0x20,0x5f,0x37,0x30,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x38, + 0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x28,0x28,0x5f,0x33,0x32,0x20,0x2d, + 0x20,0x64,0x65,0x70,0x74,0x68,0x31,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x29,0x20, + 0x2b,0x20,0x5f,0x37,0x30,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30, + 0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39, + 0x37,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x28,0x28,0x5f,0x33,0x32,0x20, + 0x2d,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x29, + 0x20,0x2b,0x20,0x5f,0x37,0x30,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e, + 0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x30,0x36,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x28,0x28,0x5f,0x33, + 0x32,0x20,0x2d,0x20,0x64,0x65,0x70,0x74,0x68,0x33,0x29,0x20,0x2a,0x20,0x5f,0x36, + 0x35,0x29,0x20,0x2b,0x20,0x5f,0x37,0x30,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20, + 0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x28,0x28,0x28,0x28,0x5f,0x37,0x39,0x20,0x2a,0x20,0x64,0x65,0x70,0x74, + 0x68,0x30,0x29,0x20,0x2b,0x20,0x28,0x5f,0x38,0x38,0x20,0x2a,0x20,0x64,0x65,0x70, + 0x74,0x68,0x31,0x29,0x29,0x20,0x2b,0x20,0x28,0x5f,0x39,0x37,0x20,0x2a,0x20,0x64, + 0x65,0x70,0x74,0x68,0x32,0x29,0x29,0x20,0x2b,0x20,0x28,0x5f,0x31,0x30,0x36,0x20, + 0x2a,0x20,0x64,0x65,0x70,0x74,0x68,0x33,0x29,0x29,0x20,0x2f,0x20,0x28,0x28,0x28, + 0x5f,0x37,0x39,0x20,0x2b,0x20,0x5f,0x38,0x38,0x29,0x20,0x2b,0x20,0x5f,0x39,0x37, + 0x29,0x20,0x2b,0x20,0x5f,0x31,0x30,0x36,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f, + 0x69,0x64,0x20,0x63,0x6f,0x6d,0x70,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x5f,0x31,0x34,0x33,0x20,0x3d, + 0x20,0x69,0x6e,0x74,0x32,0x28,0x67,0x6c,0x5f,0x47,0x6c,0x6f,0x62,0x61,0x6c,0x49, + 0x6e,0x76,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x49,0x44,0x2e,0x78,0x79,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x5f,0x31,0x34,0x38,0x20,0x3d, + 0x20,0x69,0x6e,0x74,0x32,0x28,0x67,0x6c,0x5f,0x4c,0x6f,0x63,0x61,0x6c,0x49,0x6e, + 0x76,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x49,0x44,0x2e,0x78,0x79,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x5f,0x31,0x35,0x35,0x20,0x3d,0x20, + 0x67,0x74,0x61,0x6f,0x5f,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a, + 0x65,0x20,0x2d,0x20,0x69,0x6e,0x74,0x32,0x28,0x31,0x2c,0x20,0x31,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x5f,0x31,0x35,0x39,0x20,0x3d,0x20, + 0x5f,0x31,0x34,0x33,0x20,0x2a,0x20,0x69,0x6e,0x74,0x32,0x28,0x32,0x2c,0x20,0x32, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x5f,0x31,0x36,0x39, + 0x20,0x3d,0x20,0x5f,0x31,0x35,0x39,0x20,0x2b,0x20,0x69,0x6e,0x74,0x32,0x28,0x31, + 0x2c,0x20,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x5f, + 0x31,0x37,0x35,0x20,0x3d,0x20,0x5f,0x31,0x35,0x39,0x20,0x2b,0x20,0x69,0x6e,0x74, + 0x32,0x28,0x30,0x2c,0x20,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74, + 0x32,0x20,0x5f,0x31,0x38,0x31,0x20,0x3d,0x20,0x5f,0x31,0x35,0x39,0x20,0x2b,0x20, + 0x69,0x6e,0x74,0x32,0x28,0x31,0x2c,0x20,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x74,0x65, + 0x78,0x5f,0x73,0x72,0x63,0x5f,0x64,0x65,0x70,0x74,0x68,0x2e,0x4c,0x6f,0x61,0x64, + 0x28,0x69,0x6e,0x74,0x33,0x28,0x63,0x6c,0x61,0x6d,0x70,0x28,0x5f,0x31,0x35,0x39, + 0x2c,0x20,0x69,0x6e,0x74,0x32,0x28,0x30,0x2c,0x20,0x30,0x29,0x2c,0x20,0x5f,0x31, + 0x35,0x35,0x29,0x2c,0x20,0x30,0x29,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x30,0x32,0x20,0x3d,0x20,0x58,0x65,0x47, + 0x54,0x41,0x4f,0x5f,0x43,0x6c,0x61,0x6d,0x70,0x44,0x65,0x70,0x74,0x68,0x28,0x70, + 0x61,0x72,0x61,0x6d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x73, + 0x72,0x63,0x5f,0x64,0x65,0x70,0x74,0x68,0x2e,0x4c,0x6f,0x61,0x64,0x28,0x69,0x6e, + 0x74,0x33,0x28,0x63,0x6c,0x61,0x6d,0x70,0x28,0x5f,0x31,0x36,0x39,0x2c,0x20,0x69, + 0x6e,0x74,0x32,0x28,0x30,0x2c,0x20,0x30,0x29,0x2c,0x20,0x5f,0x31,0x35,0x35,0x29, + 0x2c,0x20,0x30,0x29,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x32,0x31,0x32,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f, + 0x5f,0x43,0x6c,0x61,0x6d,0x70,0x44,0x65,0x70,0x74,0x68,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x73,0x72, + 0x63,0x5f,0x64,0x65,0x70,0x74,0x68,0x2e,0x4c,0x6f,0x61,0x64,0x28,0x69,0x6e,0x74, + 0x33,0x28,0x63,0x6c,0x61,0x6d,0x70,0x28,0x5f,0x31,0x37,0x35,0x2c,0x20,0x69,0x6e, + 0x74,0x32,0x28,0x30,0x2c,0x20,0x30,0x29,0x2c,0x20,0x5f,0x31,0x35,0x35,0x29,0x2c, + 0x20,0x30,0x29,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x32,0x32,0x32,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f, + 0x43,0x6c,0x61,0x6d,0x70,0x44,0x65,0x70,0x74,0x68,0x28,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x73,0x72,0x63, + 0x5f,0x64,0x65,0x70,0x74,0x68,0x2e,0x4c,0x6f,0x61,0x64,0x28,0x69,0x6e,0x74,0x33, + 0x28,0x63,0x6c,0x61,0x6d,0x70,0x28,0x5f,0x31,0x38,0x31,0x2c,0x20,0x69,0x6e,0x74, + 0x32,0x28,0x30,0x2c,0x20,0x30,0x29,0x2c,0x20,0x5f,0x31,0x35,0x35,0x29,0x2c,0x20, + 0x30,0x29,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x32,0x33,0x32,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43, + 0x6c,0x61,0x6d,0x70,0x44,0x65,0x70,0x74,0x68,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x61,0x6c,0x6c,0x28, + 0x62,0x6f,0x6f,0x6c,0x32,0x28,0x5f,0x31,0x35,0x39,0x2e,0x78,0x20,0x3c,0x20,0x67, + 0x74,0x61,0x6f,0x5f,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65, + 0x2e,0x78,0x2c,0x20,0x5f,0x31,0x35,0x39,0x2e,0x79,0x20,0x3c,0x20,0x67,0x74,0x61, + 0x6f,0x5f,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65,0x2e,0x79, + 0x29,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x6f,0x75,0x74,0x5f,0x64,0x65,0x70,0x74,0x68,0x30,0x5b,0x5f,0x31,0x35, + 0x39,0x5d,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x32,0x30,0x32, + 0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e, + 0x30,0x66,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x61,0x6c,0x6c,0x28,0x62,0x6f,0x6f,0x6c,0x32,0x28,0x5f, + 0x31,0x36,0x39,0x2e,0x78,0x20,0x3c,0x20,0x67,0x74,0x61,0x6f,0x5f,0x56,0x69,0x65, + 0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x36, + 0x39,0x2e,0x79,0x20,0x3c,0x20,0x67,0x74,0x61,0x6f,0x5f,0x56,0x69,0x65,0x77,0x70, + 0x6f,0x72,0x74,0x53,0x69,0x7a,0x65,0x2e,0x79,0x29,0x29,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x64, + 0x65,0x70,0x74,0x68,0x30,0x5b,0x5f,0x31,0x36,0x39,0x5d,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x5f,0x32,0x31,0x32,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c, + 0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x2e,0x78,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x61,0x6c, + 0x6c,0x28,0x62,0x6f,0x6f,0x6c,0x32,0x28,0x5f,0x31,0x37,0x35,0x2e,0x78,0x20,0x3c, + 0x20,0x67,0x74,0x61,0x6f,0x5f,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69, + 0x7a,0x65,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x37,0x35,0x2e,0x79,0x20,0x3c,0x20,0x67, + 0x74,0x61,0x6f,0x5f,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65, + 0x2e,0x79,0x29,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x64,0x65,0x70,0x74,0x68,0x30,0x5b,0x5f, + 0x31,0x37,0x35,0x5d,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x32, + 0x32,0x32,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20, + 0x30,0x2e,0x30,0x66,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x61,0x6c,0x6c,0x28,0x62,0x6f,0x6f,0x6c,0x32, + 0x28,0x5f,0x31,0x38,0x31,0x2e,0x78,0x20,0x3c,0x20,0x67,0x74,0x61,0x6f,0x5f,0x56, + 0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65,0x2e,0x78,0x2c,0x20,0x5f, + 0x31,0x38,0x31,0x2e,0x79,0x20,0x3c,0x20,0x67,0x74,0x61,0x6f,0x5f,0x56,0x69,0x65, + 0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65,0x2e,0x79,0x29,0x29,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, + 0x5f,0x64,0x65,0x70,0x74,0x68,0x30,0x5b,0x5f,0x31,0x38,0x31,0x5d,0x20,0x3d,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x32,0x33,0x32,0x2c,0x20,0x30,0x2e,0x30, + 0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x2e,0x78, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x32,0x30,0x32, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x35,0x20,0x3d,0x20,0x5f,0x32,0x31,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20, + 0x5f,0x32,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x5f,0x32,0x33,0x32,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x39,0x39,0x20,0x3d, + 0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x44,0x65,0x70,0x74,0x68,0x4d,0x49,0x50, + 0x46,0x69,0x6c,0x74,0x65,0x72,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x61,0x6c,0x6c,0x28,0x62,0x6f,0x6f,0x6c,0x32,0x28,0x5f,0x31, + 0x34,0x33,0x2e,0x78,0x20,0x3c,0x20,0x67,0x74,0x61,0x6f,0x5f,0x56,0x69,0x65,0x77, + 0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x34,0x33, + 0x2e,0x79,0x20,0x3c,0x20,0x67,0x74,0x61,0x6f,0x5f,0x56,0x69,0x65,0x77,0x70,0x6f, + 0x72,0x74,0x53,0x69,0x7a,0x65,0x2e,0x79,0x29,0x29,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x64,0x65, + 0x70,0x74,0x68,0x31,0x5b,0x5f,0x31,0x34,0x33,0x5d,0x20,0x3d,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x28,0x5f,0x32,0x39,0x39,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20, + 0x30,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x2e,0x78,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x33,0x31, + 0x39,0x20,0x3d,0x20,0x5f,0x31,0x34,0x38,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x6e,0x74,0x20,0x5f,0x33,0x32,0x32,0x20,0x3d,0x20,0x5f,0x31,0x34,0x38,0x2e, + 0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x5f,0x73,0x63,0x72,0x61,0x74,0x63,0x68, + 0x44,0x65,0x70,0x74,0x68,0x73,0x5b,0x5f,0x33,0x31,0x39,0x5d,0x5b,0x5f,0x33,0x32, + 0x32,0x5d,0x20,0x3d,0x20,0x5f,0x32,0x39,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x47, + 0x72,0x6f,0x75,0x70,0x4d,0x65,0x6d,0x6f,0x72,0x79,0x42,0x61,0x72,0x72,0x69,0x65, + 0x72,0x57,0x69,0x74,0x68,0x47,0x72,0x6f,0x75,0x70,0x53,0x79,0x6e,0x63,0x28,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x64,0x6d,0x32,0x20, + 0x3d,0x20,0x30,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32, + 0x20,0x5f,0x33,0x33,0x32,0x20,0x3d,0x20,0x5f,0x31,0x34,0x38,0x20,0x26,0x20,0x69, + 0x6e,0x74,0x32,0x28,0x31,0x2c,0x20,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x61,0x6c,0x6c,0x28,0x62,0x6f,0x6f,0x6c,0x32,0x28,0x5f,0x33,0x33, + 0x32,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x69,0x6e,0x74,0x32,0x28,0x30,0x2c,0x20,0x30, + 0x29,0x2e,0x78,0x2c,0x20,0x5f,0x33,0x33,0x32,0x2e,0x79,0x20,0x3d,0x3d,0x20,0x69, + 0x6e,0x74,0x32,0x28,0x30,0x2c,0x20,0x30,0x29,0x2e,0x79,0x29,0x29,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74, + 0x20,0x5f,0x33,0x35,0x30,0x20,0x3d,0x20,0x5f,0x33,0x31,0x39,0x20,0x2b,0x20,0x31, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x33, + 0x36,0x32,0x20,0x3d,0x20,0x5f,0x33,0x32,0x32,0x20,0x2b,0x20,0x31,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x67,0x5f,0x73,0x63,0x72,0x61,0x74,0x63,0x68, + 0x44,0x65,0x70,0x74,0x68,0x73,0x5b,0x5f,0x33,0x31,0x39,0x5d,0x5b,0x5f,0x33,0x32, + 0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x67,0x5f,0x73,0x63, + 0x72,0x61,0x74,0x63,0x68,0x44,0x65,0x70,0x74,0x68,0x73,0x5b,0x5f,0x33,0x35,0x30, + 0x5d,0x5b,0x5f,0x33,0x32,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20, + 0x3d,0x20,0x67,0x5f,0x73,0x63,0x72,0x61,0x74,0x63,0x68,0x44,0x65,0x70,0x74,0x68, + 0x73,0x5b,0x5f,0x33,0x31,0x39,0x5d,0x5b,0x5f,0x33,0x36,0x32,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x67,0x5f,0x73,0x63,0x72,0x61,0x74,0x63, + 0x68,0x44,0x65,0x70,0x74,0x68,0x73,0x5b,0x5f,0x33,0x35,0x30,0x5d,0x5b,0x5f,0x33, + 0x36,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x64,0x6d,0x32, + 0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x44,0x65,0x70,0x74,0x68,0x4d, + 0x49,0x50,0x46,0x69,0x6c,0x74,0x65,0x72,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x5f,0x33,0x38, + 0x38,0x20,0x3d,0x20,0x69,0x6e,0x74,0x32,0x28,0x75,0x69,0x6e,0x74,0x32,0x28,0x5f, + 0x31,0x34,0x33,0x29,0x20,0x3e,0x3e,0x20,0x75,0x69,0x6e,0x74,0x32,0x28,0x31,0x75, + 0x2c,0x20,0x31,0x75,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x61,0x6c,0x6c,0x28,0x62,0x6f,0x6f,0x6c,0x32,0x28,0x5f,0x33, + 0x38,0x38,0x2e,0x78,0x20,0x3c,0x20,0x67,0x74,0x61,0x6f,0x5f,0x56,0x69,0x65,0x77, + 0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65,0x2e,0x78,0x2c,0x20,0x5f,0x33,0x38,0x38, + 0x2e,0x79,0x20,0x3c,0x20,0x67,0x74,0x61,0x6f,0x5f,0x56,0x69,0x65,0x77,0x70,0x6f, + 0x72,0x74,0x53,0x69,0x7a,0x65,0x2e,0x79,0x29,0x29,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x6f,0x75,0x74,0x5f,0x64,0x65,0x70,0x74,0x68,0x32,0x5b,0x5f,0x33,0x38, + 0x38,0x5d,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x64,0x6d,0x32,0x2c, + 0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30, + 0x66,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x67,0x5f,0x73,0x63,0x72,0x61,0x74,0x63, + 0x68,0x44,0x65,0x70,0x74,0x68,0x73,0x5b,0x5f,0x33,0x31,0x39,0x5d,0x5b,0x5f,0x33, + 0x32,0x32,0x5d,0x20,0x3d,0x20,0x64,0x6d,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x47,0x72,0x6f,0x75,0x70,0x4d,0x65,0x6d,0x6f,0x72,0x79, + 0x42,0x61,0x72,0x72,0x69,0x65,0x72,0x57,0x69,0x74,0x68,0x47,0x72,0x6f,0x75,0x70, + 0x53,0x79,0x6e,0x63,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x64,0x6d,0x33,0x20,0x3d,0x20,0x30,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x5f,0x34,0x31,0x31,0x20,0x3d,0x20,0x5f,0x31, + 0x34,0x38,0x20,0x26,0x20,0x69,0x6e,0x74,0x32,0x28,0x33,0x2c,0x20,0x33,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x61,0x6c,0x6c,0x28,0x62,0x6f,0x6f, + 0x6c,0x32,0x28,0x5f,0x34,0x31,0x31,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x69,0x6e,0x74, + 0x32,0x28,0x30,0x2c,0x20,0x30,0x29,0x2e,0x78,0x2c,0x20,0x5f,0x34,0x31,0x31,0x2e, + 0x79,0x20,0x3d,0x3d,0x20,0x69,0x6e,0x74,0x32,0x28,0x30,0x2c,0x20,0x30,0x29,0x2e, + 0x79,0x29,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x34,0x32,0x39,0x20,0x3d,0x20,0x5f,0x33, + 0x31,0x39,0x20,0x2b,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x69,0x6e,0x74,0x20,0x5f,0x34,0x34,0x31,0x20,0x3d,0x20,0x5f,0x33,0x32,0x32,0x20, + 0x2b,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x67,0x5f, + 0x73,0x63,0x72,0x61,0x74,0x63,0x68,0x44,0x65,0x70,0x74,0x68,0x73,0x5b,0x5f,0x33, + 0x31,0x39,0x5d,0x5b,0x5f,0x33,0x32,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x33,0x20,0x3d,0x20,0x67,0x5f,0x73,0x63,0x72,0x61,0x74,0x63,0x68,0x44,0x65,0x70, + 0x74,0x68,0x73,0x5b,0x5f,0x34,0x32,0x39,0x5d,0x5b,0x5f,0x33,0x32,0x32,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x67,0x5f,0x73,0x63,0x72,0x61, + 0x74,0x63,0x68,0x44,0x65,0x70,0x74,0x68,0x73,0x5b,0x5f,0x33,0x31,0x39,0x5d,0x5b, + 0x5f,0x34,0x34,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20, + 0x67,0x5f,0x73,0x63,0x72,0x61,0x74,0x63,0x68,0x44,0x65,0x70,0x74,0x68,0x73,0x5b, + 0x5f,0x34,0x32,0x39,0x5d,0x5b,0x5f,0x34,0x34,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x64,0x6d,0x33,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41, + 0x4f,0x5f,0x44,0x65,0x70,0x74,0x68,0x4d,0x49,0x50,0x46,0x69,0x6c,0x74,0x65,0x72, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x5f,0x34,0x36,0x37,0x20,0x3d,0x20,0x69,0x6e, + 0x74,0x32,0x28,0x75,0x69,0x6e,0x74,0x32,0x28,0x5f,0x31,0x34,0x33,0x29,0x20,0x3e, + 0x3e,0x20,0x75,0x69,0x6e,0x74,0x32,0x28,0x32,0x75,0x2c,0x20,0x32,0x75,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x61,0x6c, + 0x6c,0x28,0x62,0x6f,0x6f,0x6c,0x32,0x28,0x5f,0x34,0x36,0x37,0x2e,0x78,0x20,0x3c, + 0x20,0x67,0x74,0x61,0x6f,0x5f,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69, + 0x7a,0x65,0x2e,0x78,0x2c,0x20,0x5f,0x34,0x36,0x37,0x2e,0x79,0x20,0x3c,0x20,0x67, + 0x74,0x61,0x6f,0x5f,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65, + 0x2e,0x79,0x29,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f, + 0x64,0x65,0x70,0x74,0x68,0x33,0x5b,0x5f,0x34,0x36,0x37,0x5d,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x64,0x6d,0x33,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c, + 0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x2e,0x78,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x67,0x5f,0x73,0x63,0x72,0x61,0x74,0x63,0x68,0x44,0x65,0x70,0x74,0x68, + 0x73,0x5b,0x5f,0x33,0x31,0x39,0x5d,0x5b,0x5f,0x33,0x32,0x32,0x5d,0x20,0x3d,0x20, + 0x64,0x6d,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x47, + 0x72,0x6f,0x75,0x70,0x4d,0x65,0x6d,0x6f,0x72,0x79,0x42,0x61,0x72,0x72,0x69,0x65, + 0x72,0x57,0x69,0x74,0x68,0x47,0x72,0x6f,0x75,0x70,0x53,0x79,0x6e,0x63,0x28,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x61,0x6c,0x6c,0x28,0x62,0x6f, + 0x6f,0x6c,0x32,0x28,0x5f,0x31,0x34,0x38,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x69,0x6e, + 0x74,0x32,0x28,0x30,0x2c,0x20,0x30,0x29,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x34,0x38, + 0x2e,0x79,0x20,0x3d,0x3d,0x20,0x69,0x6e,0x74,0x32,0x28,0x30,0x2c,0x20,0x30,0x29, + 0x2e,0x79,0x29,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x36,0x20,0x3d,0x20,0x67,0x5f,0x73,0x63,0x72,0x61,0x74,0x63,0x68,0x44,0x65, + 0x70,0x74,0x68,0x73,0x5b,0x30,0x5d,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x37,0x20,0x3d,0x20,0x67,0x5f,0x73,0x63,0x72,0x61,0x74,0x63,0x68,0x44,0x65, + 0x70,0x74,0x68,0x73,0x5b,0x34,0x5d,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x38,0x20,0x3d,0x20,0x67,0x5f,0x73,0x63,0x72,0x61,0x74,0x63,0x68,0x44,0x65, + 0x70,0x74,0x68,0x73,0x5b,0x30,0x5d,0x5b,0x34,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x39,0x20,0x3d,0x20,0x67,0x5f,0x73,0x63,0x72,0x61,0x74,0x63,0x68,0x44,0x65, + 0x70,0x74,0x68,0x73,0x5b,0x34,0x5d,0x5b,0x34,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x5f,0x35,0x32,0x30,0x20,0x3d,0x20, + 0x69,0x6e,0x74,0x32,0x28,0x75,0x69,0x6e,0x74,0x32,0x28,0x5f,0x31,0x34,0x33,0x29, + 0x20,0x3e,0x3e,0x20,0x75,0x69,0x6e,0x74,0x32,0x28,0x33,0x75,0x2c,0x20,0x33,0x75, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x61,0x6c,0x6c,0x28,0x62,0x6f,0x6f,0x6c,0x32,0x28,0x5f,0x35,0x32,0x30,0x2e,0x78, + 0x20,0x3c,0x20,0x67,0x74,0x61,0x6f,0x5f,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74, + 0x53,0x69,0x7a,0x65,0x2e,0x78,0x2c,0x20,0x5f,0x35,0x32,0x30,0x2e,0x79,0x20,0x3c, + 0x20,0x67,0x74,0x61,0x6f,0x5f,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69, + 0x7a,0x65,0x2e,0x79,0x29,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75, + 0x74,0x5f,0x64,0x65,0x70,0x74,0x68,0x34,0x5b,0x5f,0x35,0x32,0x30,0x5d,0x20,0x3d, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x44, + 0x65,0x70,0x74,0x68,0x4d,0x49,0x50,0x46,0x69,0x6c,0x74,0x65,0x72,0x28,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x39,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30, + 0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x7d,0x0a,0x0a,0x5b, + 0x6e,0x75,0x6d,0x74,0x68,0x72,0x65,0x61,0x64,0x73,0x28,0x38,0x2c,0x20,0x38,0x2c, + 0x20,0x31,0x29,0x5d,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53, + 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74, + 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x4c,0x6f,0x63,0x61,0x6c,0x49,0x6e,0x76,0x6f, + 0x63,0x61,0x74,0x69,0x6f,0x6e,0x49,0x44,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65, + 0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x4c,0x6f,0x63,0x61,0x6c,0x49, + 0x6e,0x76,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x49,0x44,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x67,0x6c,0x5f,0x47,0x6c,0x6f,0x62,0x61,0x6c,0x49,0x6e,0x76,0x6f,0x63,0x61, + 0x74,0x69,0x6f,0x6e,0x49,0x44,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69, + 0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x47,0x6c,0x6f,0x62,0x61,0x6c,0x49,0x6e, + 0x76,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x49,0x44,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x63,0x6f,0x6d,0x70,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x7d,0x0a,0x00, + +}; +/* + #pragma clang diagnostic ignored "-Wmissing-prototypes" + #pragma clang diagnostic ignored "-Wmissing-braces" + + #include + #include + + using namespace metal; + + template + struct spvUnsafeArray + { + T elements[Num ? Num : 1]; + + thread T& operator [] (size_t pos) thread + { + return elements[pos]; + } + constexpr const thread T& operator [] (size_t pos) const thread + { + return elements[pos]; + } + + device T& operator [] (size_t pos) device + { + return elements[pos]; + } + constexpr const device T& operator [] (size_t pos) const device + { + return elements[pos]; + } + + constexpr const constant T& operator [] (size_t pos) const constant + { + return elements[pos]; + } + + threadgroup T& operator [] (size_t pos) threadgroup + { + return elements[pos]; + } + constexpr const threadgroup T& operator [] (size_t pos) const threadgroup + { + return elements[pos]; + } + }; + + struct ub_gtao + { + int2 ViewportSize; + float EffectRadius; + float EffectFalloffRange; + float RadiusMultiplier; + }; + + constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(8u, 8u, 1u); + + static inline __attribute__((always_inline)) + float XeGTAO_ClampDepth(thread const float& depth) + { + return fast::clamp(depth, 0.0, 3.4028234663852885981170418348452e+38); + } + + static inline __attribute__((always_inline)) + float XeGTAO_DepthMIPFilter(thread const float& depth0, thread const float& depth1, thread const float& depth2, thread const float& depth3, constant ub_gtao& gtao) + { + float _32 = fast::max(fast::max(depth0, depth1), fast::max(depth2, depth3)); + float _48 = (0.75 * gtao.EffectRadius) * gtao.RadiusMultiplier; + float _54 = gtao.EffectFalloffRange * _48; + float _65 = (-1.0) / _54; + float _70 = ((_48 * (1.0 - gtao.EffectFalloffRange)) / _54) + 1.0; + float _79 = fast::clamp(((_32 - depth0) * _65) + _70, 0.0, 1.0); + float _88 = fast::clamp(((_32 - depth1) * _65) + _70, 0.0, 1.0); + float _97 = fast::clamp(((_32 - depth2) * _65) + _70, 0.0, 1.0); + float _106 = fast::clamp(((_32 - depth3) * _65) + _70, 0.0, 1.0); + return ((((_79 * depth0) + (_88 * depth1)) + (_97 * depth2)) + (_106 * depth3)) / (((_79 + _88) + _97) + _106); + } + + kernel void main0(constant ub_gtao& gtao [[buffer(0)]], texture2d out_depth0 [[texture(0)]], texture2d out_depth1 [[texture(1)]], texture2d out_depth2 [[texture(2)]], texture2d out_depth3 [[texture(3)]], texture2d out_depth4 [[texture(4)]], texture2d tex_src_depth [[texture(5)]], sampler smp_src_depth [[sampler(0)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]], uint3 gl_LocalInvocationID [[thread_position_in_threadgroup]]) + { + threadgroup spvUnsafeArray, 8> g_scratchDepths; + int2 _143 = int2(gl_GlobalInvocationID.xy); + int2 _148 = int2(gl_LocalInvocationID.xy); + int2 _155 = gtao.ViewportSize - int2(1); + int2 _159 = _143 * int2(2); + int2 _169 = _159 + int2(1, 0); + int2 _175 = _159 + int2(0, 1); + int2 _181 = _159 + int2(1); + float param = tex_src_depth.read(uint2(clamp(_159, int2(0), _155)), 0).x; + float _202 = XeGTAO_ClampDepth(param); + float param_1 = tex_src_depth.read(uint2(clamp(_169, int2(0), _155)), 0).x; + float _212 = XeGTAO_ClampDepth(param_1); + float param_2 = tex_src_depth.read(uint2(clamp(_175, int2(0), _155)), 0).x; + float _222 = XeGTAO_ClampDepth(param_2); + float param_3 = tex_src_depth.read(uint2(clamp(_181, int2(0), _155)), 0).x; + float _232 = XeGTAO_ClampDepth(param_3); + if (all(_159 < gtao.ViewportSize)) + { + out_depth0.write(float4(_202, 0.0, 0.0, 0.0), uint2(_159)); + } + if (all(_169 < gtao.ViewportSize)) + { + out_depth0.write(float4(_212, 0.0, 0.0, 0.0), uint2(_169)); + } + if (all(_175 < gtao.ViewportSize)) + { + out_depth0.write(float4(_222, 0.0, 0.0, 0.0), uint2(_175)); + } + if (all(_181 < gtao.ViewportSize)) + { + out_depth0.write(float4(_232, 0.0, 0.0, 0.0), uint2(_181)); + } + float param_4 = _202; + float param_5 = _212; + float param_6 = _222; + float param_7 = _232; + float _299 = XeGTAO_DepthMIPFilter(param_4, param_5, param_6, param_7, gtao); + if (all(_143 < gtao.ViewportSize)) + { + out_depth1.write(float4(_299, 0.0, 0.0, 0.0), uint2(_143)); + } + int _319 = _148.x; + int _322 = _148.y; + g_scratchDepths[_319][_322] = _299; + threadgroup_barrier(mem_flags::mem_threadgroup); + float dm2 = 0.0; + if (all((_148 & int2(1)) == int2(0))) + { + int _350 = _319 + 1; + int _362 = _322 + 1; + float param_8 = g_scratchDepths[_319][_322]; + float param_9 = g_scratchDepths[_350][_322]; + float param_10 = g_scratchDepths[_319][_362]; + float param_11 = g_scratchDepths[_350][_362]; + dm2 = XeGTAO_DepthMIPFilter(param_8, param_9, param_10, param_11, gtao); + int2 _388 = int2(uint2(_143) >> uint2(1u)); + if (all(_388 < gtao.ViewportSize)) + { + out_depth2.write(float4(dm2, 0.0, 0.0, 0.0), uint2(_388)); + } + g_scratchDepths[_319][_322] = dm2; + } + threadgroup_barrier(mem_flags::mem_threadgroup); + float dm3 = 0.0; + if (all((_148 & int2(3)) == int2(0))) + { + int _429 = _319 + 2; + int _441 = _322 + 2; + float param_12 = g_scratchDepths[_319][_322]; + float param_13 = g_scratchDepths[_429][_322]; + float param_14 = g_scratchDepths[_319][_441]; + float param_15 = g_scratchDepths[_429][_441]; + dm3 = XeGTAO_DepthMIPFilter(param_12, param_13, param_14, param_15, gtao); + int2 _467 = int2(uint2(_143) >> uint2(2u)); + if (all(_467 < gtao.ViewportSize)) + { + out_depth3.write(float4(dm3, 0.0, 0.0, 0.0), uint2(_467)); + } + g_scratchDepths[_319][_322] = dm3; + } + threadgroup_barrier(mem_flags::mem_threadgroup); + if (all(_148 == int2(0))) + { + float param_16 = g_scratchDepths[0][0]; + float param_17 = g_scratchDepths[4][0]; + float param_18 = g_scratchDepths[0][4]; + float param_19 = g_scratchDepths[4][4]; + int2 _520 = int2(uint2(_143) >> uint2(3u)); + if (all(_520 < gtao.ViewportSize)) + { + out_depth4.write(float4(XeGTAO_DepthMIPFilter(param_16, param_17, param_18, param_19, gtao), 0.0, 0.0, 0.0), uint2(_520)); + } + } + } + +*/ +static const uint8_t gtao_prefilter_depth_cs_source_metal_macos[6535] = { + 0x23,0x70,0x72,0x61,0x67,0x6d,0x61,0x20,0x63,0x6c,0x61,0x6e,0x67,0x20,0x64,0x69, + 0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x20,0x69,0x67,0x6e,0x6f,0x72,0x65,0x64, + 0x20,0x22,0x2d,0x57,0x6d,0x69,0x73,0x73,0x69,0x6e,0x67,0x2d,0x70,0x72,0x6f,0x74, + 0x6f,0x74,0x79,0x70,0x65,0x73,0x22,0x0a,0x23,0x70,0x72,0x61,0x67,0x6d,0x61,0x20, + 0x63,0x6c,0x61,0x6e,0x67,0x20,0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63, + 0x20,0x69,0x67,0x6e,0x6f,0x72,0x65,0x64,0x20,0x22,0x2d,0x57,0x6d,0x69,0x73,0x73, + 0x69,0x6e,0x67,0x2d,0x62,0x72,0x61,0x63,0x65,0x73,0x22,0x0a,0x0a,0x23,0x69,0x6e, + 0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f,0x73,0x74,0x64, + 0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x73, + 0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a,0x75,0x73,0x69, + 0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20,0x6d,0x65,0x74, + 0x61,0x6c,0x3b,0x0a,0x0a,0x74,0x65,0x6d,0x70,0x6c,0x61,0x74,0x65,0x3c,0x74,0x79, + 0x70,0x65,0x6e,0x61,0x6d,0x65,0x20,0x54,0x2c,0x20,0x73,0x69,0x7a,0x65,0x5f,0x74, + 0x20,0x4e,0x75,0x6d,0x3e,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x73,0x70,0x76, + 0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x54,0x20,0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x4e,0x75,0x6d, + 0x20,0x3f,0x20,0x4e,0x75,0x6d,0x20,0x3a,0x20,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x0a,0x20,0x20,0x20,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x54,0x26,0x20, + 0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72,0x20,0x5b,0x5d,0x20,0x28,0x73,0x69,0x7a, + 0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f, + 0x73,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x65,0x78,0x70,0x72,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x74,0x68, + 0x72,0x65,0x61,0x64,0x20,0x54,0x26,0x20,0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72, + 0x20,0x5b,0x5d,0x20,0x28,0x73,0x69,0x7a,0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f,0x73,0x5d, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x0a,0x20,0x20,0x20, + 0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x20,0x54,0x26,0x20,0x6f,0x70,0x65,0x72,0x61, + 0x74,0x6f,0x72,0x20,0x5b,0x5d,0x20,0x28,0x73,0x69,0x7a,0x65,0x5f,0x74,0x20,0x70, + 0x6f,0x73,0x29,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f,0x73,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6e,0x73,0x74,0x65,0x78, + 0x70,0x72,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x20, + 0x54,0x26,0x20,0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72,0x20,0x5b,0x5d,0x20,0x28, + 0x73,0x69,0x7a,0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x65,0x6c, + 0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f,0x73,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x65,0x78,0x70,0x72,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x61,0x6e,0x74,0x20,0x54,0x26,0x20,0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72, + 0x20,0x5b,0x5d,0x20,0x28,0x73,0x69,0x7a,0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f, + 0x73,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x0a,0x20, + 0x20,0x20,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x67,0x72,0x6f,0x75,0x70,0x20,0x54, + 0x26,0x20,0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72,0x20,0x5b,0x5d,0x20,0x28,0x73, + 0x69,0x7a,0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x67,0x72,0x6f,0x75,0x70,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x65,0x6c,0x65,0x6d, + 0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f,0x73,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6e,0x73,0x74,0x65,0x78,0x70,0x72,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x67,0x72,0x6f,0x75,0x70, + 0x20,0x54,0x26,0x20,0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72,0x20,0x5b,0x5d,0x20, + 0x28,0x73,0x69,0x7a,0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x67,0x72,0x6f,0x75,0x70,0x0a,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f,0x73, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72, + 0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x67,0x74,0x61,0x6f,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53, + 0x69,0x7a,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x45, + 0x66,0x66,0x65,0x63,0x74,0x52,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x45,0x66,0x66,0x65,0x63,0x74,0x46,0x61,0x6c, + 0x6c,0x6f,0x66,0x66,0x52,0x61,0x6e,0x67,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x52,0x61,0x64,0x69,0x75,0x73,0x4d,0x75,0x6c,0x74,0x69, + 0x70,0x6c,0x69,0x65,0x72,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x63,0x6f,0x6e,0x73,0x74, + 0x61,0x6e,0x74,0x20,0x75,0x69,0x6e,0x74,0x33,0x20,0x67,0x6c,0x5f,0x57,0x6f,0x72, + 0x6b,0x47,0x72,0x6f,0x75,0x70,0x53,0x69,0x7a,0x65,0x20,0x5b,0x5b,0x6d,0x61,0x79, + 0x62,0x65,0x5f,0x75,0x6e,0x75,0x73,0x65,0x64,0x5d,0x5d,0x20,0x3d,0x20,0x75,0x69, + 0x6e,0x74,0x33,0x28,0x38,0x75,0x2c,0x20,0x38,0x75,0x2c,0x20,0x31,0x75,0x29,0x3b, + 0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20, + 0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61, + 0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x6c,0x61,0x6d, + 0x70,0x44,0x65,0x70,0x74,0x68,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x64,0x65,0x70,0x74,0x68, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66, + 0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x64,0x65,0x70,0x74,0x68, + 0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x33,0x2e,0x34,0x30,0x32,0x38,0x32,0x33,0x34, + 0x36,0x36,0x33,0x38,0x35,0x32,0x38,0x38,0x35,0x39,0x38,0x31,0x31,0x37,0x30,0x34, + 0x31,0x38,0x33,0x34,0x38,0x34,0x35,0x32,0x65,0x2b,0x33,0x38,0x29,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20, + 0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61, + 0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x44,0x65,0x70,0x74, + 0x68,0x4d,0x49,0x50,0x46,0x69,0x6c,0x74,0x65,0x72,0x28,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x64, + 0x65,0x70,0x74,0x68,0x30,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x64,0x65,0x70,0x74,0x68, + 0x31,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x2c,0x20,0x74, + 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x26,0x20,0x64,0x65,0x70,0x74,0x68,0x33,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x67,0x74,0x61,0x6f,0x26,0x20,0x67,0x74,0x61, + 0x6f,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x33,0x32,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x66, + 0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x65,0x70,0x74,0x68,0x30,0x2c, + 0x20,0x64,0x65,0x70,0x74,0x68,0x31,0x29,0x2c,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a, + 0x6d,0x61,0x78,0x28,0x64,0x65,0x70,0x74,0x68,0x32,0x2c,0x20,0x64,0x65,0x70,0x74, + 0x68,0x33,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x34,0x38,0x20,0x3d,0x20,0x28,0x30,0x2e,0x37,0x35,0x20,0x2a,0x20,0x67,0x74, + 0x61,0x6f,0x2e,0x45,0x66,0x66,0x65,0x63,0x74,0x52,0x61,0x64,0x69,0x75,0x73,0x29, + 0x20,0x2a,0x20,0x67,0x74,0x61,0x6f,0x2e,0x52,0x61,0x64,0x69,0x75,0x73,0x4d,0x75, + 0x6c,0x74,0x69,0x70,0x6c,0x69,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x35,0x34,0x20,0x3d,0x20,0x67,0x74,0x61,0x6f,0x2e,0x45, + 0x66,0x66,0x65,0x63,0x74,0x46,0x61,0x6c,0x6c,0x6f,0x66,0x66,0x52,0x61,0x6e,0x67, + 0x65,0x20,0x2a,0x20,0x5f,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x36,0x35,0x20,0x3d,0x20,0x28,0x2d,0x31,0x2e,0x30,0x29,0x20, + 0x2f,0x20,0x5f,0x35,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x37,0x30,0x20,0x3d,0x20,0x28,0x28,0x5f,0x34,0x38,0x20,0x2a,0x20,0x28, + 0x31,0x2e,0x30,0x20,0x2d,0x20,0x67,0x74,0x61,0x6f,0x2e,0x45,0x66,0x66,0x65,0x63, + 0x74,0x46,0x61,0x6c,0x6c,0x6f,0x66,0x66,0x52,0x61,0x6e,0x67,0x65,0x29,0x29,0x20, + 0x2f,0x20,0x5f,0x35,0x34,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x39,0x20,0x3d,0x20,0x66,0x61, + 0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x28,0x28,0x5f,0x33,0x32,0x20, + 0x2d,0x20,0x64,0x65,0x70,0x74,0x68,0x30,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x29, + 0x20,0x2b,0x20,0x5f,0x37,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x38, + 0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x28, + 0x28,0x5f,0x33,0x32,0x20,0x2d,0x20,0x64,0x65,0x70,0x74,0x68,0x31,0x29,0x20,0x2a, + 0x20,0x5f,0x36,0x35,0x29,0x20,0x2b,0x20,0x5f,0x37,0x30,0x2c,0x20,0x30,0x2e,0x30, + 0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x39,0x37,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c, + 0x61,0x6d,0x70,0x28,0x28,0x28,0x5f,0x33,0x32,0x20,0x2d,0x20,0x64,0x65,0x70,0x74, + 0x68,0x32,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x29,0x20,0x2b,0x20,0x5f,0x37,0x30, + 0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x36,0x20,0x3d,0x20,0x66,0x61, + 0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x28,0x28,0x5f,0x33,0x32,0x20, + 0x2d,0x20,0x64,0x65,0x70,0x74,0x68,0x33,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x29, + 0x20,0x2b,0x20,0x5f,0x37,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28, + 0x28,0x28,0x5f,0x37,0x39,0x20,0x2a,0x20,0x64,0x65,0x70,0x74,0x68,0x30,0x29,0x20, + 0x2b,0x20,0x28,0x5f,0x38,0x38,0x20,0x2a,0x20,0x64,0x65,0x70,0x74,0x68,0x31,0x29, + 0x29,0x20,0x2b,0x20,0x28,0x5f,0x39,0x37,0x20,0x2a,0x20,0x64,0x65,0x70,0x74,0x68, + 0x32,0x29,0x29,0x20,0x2b,0x20,0x28,0x5f,0x31,0x30,0x36,0x20,0x2a,0x20,0x64,0x65, + 0x70,0x74,0x68,0x33,0x29,0x29,0x20,0x2f,0x20,0x28,0x28,0x28,0x5f,0x37,0x39,0x20, + 0x2b,0x20,0x5f,0x38,0x38,0x29,0x20,0x2b,0x20,0x5f,0x39,0x37,0x29,0x20,0x2b,0x20, + 0x5f,0x31,0x30,0x36,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x6b,0x65,0x72,0x6e,0x65,0x6c, + 0x20,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x63,0x6f,0x6e,0x73, + 0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x67,0x74,0x61,0x6f,0x26,0x20,0x67,0x74, + 0x61,0x6f,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d, + 0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61, + 0x74,0x2c,0x20,0x61,0x63,0x63,0x65,0x73,0x73,0x3a,0x3a,0x77,0x72,0x69,0x74,0x65, + 0x3e,0x20,0x6f,0x75,0x74,0x5f,0x64,0x65,0x70,0x74,0x68,0x30,0x20,0x5b,0x5b,0x74, + 0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78, + 0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x2c,0x20,0x61,0x63, + 0x63,0x65,0x73,0x73,0x3a,0x3a,0x77,0x72,0x69,0x74,0x65,0x3e,0x20,0x6f,0x75,0x74, + 0x5f,0x64,0x65,0x70,0x74,0x68,0x31,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72, + 0x65,0x28,0x31,0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32, + 0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x2c,0x20,0x61,0x63,0x63,0x65,0x73,0x73,0x3a, + 0x3a,0x77,0x72,0x69,0x74,0x65,0x3e,0x20,0x6f,0x75,0x74,0x5f,0x64,0x65,0x70,0x74, + 0x68,0x32,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x32,0x29,0x5d, + 0x5d,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f, + 0x61,0x74,0x2c,0x20,0x61,0x63,0x63,0x65,0x73,0x73,0x3a,0x3a,0x77,0x72,0x69,0x74, + 0x65,0x3e,0x20,0x6f,0x75,0x74,0x5f,0x64,0x65,0x70,0x74,0x68,0x33,0x20,0x5b,0x5b, + 0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x33,0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65, + 0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x2c,0x20,0x61, + 0x63,0x63,0x65,0x73,0x73,0x3a,0x3a,0x77,0x72,0x69,0x74,0x65,0x3e,0x20,0x6f,0x75, + 0x74,0x5f,0x64,0x65,0x70,0x74,0x68,0x34,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75, + 0x72,0x65,0x28,0x34,0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65, + 0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x72, + 0x63,0x5f,0x64,0x65,0x70,0x74,0x68,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72, + 0x65,0x28,0x35,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20, + 0x73,0x6d,0x70,0x5f,0x73,0x72,0x63,0x5f,0x64,0x65,0x70,0x74,0x68,0x20,0x5b,0x5b, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x75,0x69, + 0x6e,0x74,0x33,0x20,0x67,0x6c,0x5f,0x47,0x6c,0x6f,0x62,0x61,0x6c,0x49,0x6e,0x76, + 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x49,0x44,0x20,0x5b,0x5b,0x74,0x68,0x72,0x65, + 0x61,0x64,0x5f,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5f,0x69,0x6e,0x5f,0x67, + 0x72,0x69,0x64,0x5d,0x5d,0x2c,0x20,0x75,0x69,0x6e,0x74,0x33,0x20,0x67,0x6c,0x5f, + 0x4c,0x6f,0x63,0x61,0x6c,0x49,0x6e,0x76,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x49, + 0x44,0x20,0x5b,0x5b,0x74,0x68,0x72,0x65,0x61,0x64,0x5f,0x70,0x6f,0x73,0x69,0x74, + 0x69,0x6f,0x6e,0x5f,0x69,0x6e,0x5f,0x74,0x68,0x72,0x65,0x61,0x64,0x67,0x72,0x6f, + 0x75,0x70,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x74,0x68,0x72,0x65, + 0x61,0x64,0x67,0x72,0x6f,0x75,0x70,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66, + 0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65, + 0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x2c,0x20,0x38,0x3e,0x2c, + 0x20,0x38,0x3e,0x20,0x67,0x5f,0x73,0x63,0x72,0x61,0x74,0x63,0x68,0x44,0x65,0x70, + 0x74,0x68,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x5f,0x31, + 0x34,0x33,0x20,0x3d,0x20,0x69,0x6e,0x74,0x32,0x28,0x67,0x6c,0x5f,0x47,0x6c,0x6f, + 0x62,0x61,0x6c,0x49,0x6e,0x76,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x49,0x44,0x2e, + 0x78,0x79,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x5f,0x31, + 0x34,0x38,0x20,0x3d,0x20,0x69,0x6e,0x74,0x32,0x28,0x67,0x6c,0x5f,0x4c,0x6f,0x63, + 0x61,0x6c,0x49,0x6e,0x76,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x49,0x44,0x2e,0x78, + 0x79,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x5f,0x31,0x35, + 0x35,0x20,0x3d,0x20,0x67,0x74,0x61,0x6f,0x2e,0x56,0x69,0x65,0x77,0x70,0x6f,0x72, + 0x74,0x53,0x69,0x7a,0x65,0x20,0x2d,0x20,0x69,0x6e,0x74,0x32,0x28,0x31,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x5f,0x31,0x35,0x39,0x20,0x3d, + 0x20,0x5f,0x31,0x34,0x33,0x20,0x2a,0x20,0x69,0x6e,0x74,0x32,0x28,0x32,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x5f,0x31,0x36,0x39,0x20,0x3d, + 0x20,0x5f,0x31,0x35,0x39,0x20,0x2b,0x20,0x69,0x6e,0x74,0x32,0x28,0x31,0x2c,0x20, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x5f,0x31,0x37, + 0x35,0x20,0x3d,0x20,0x5f,0x31,0x35,0x39,0x20,0x2b,0x20,0x69,0x6e,0x74,0x32,0x28, + 0x30,0x2c,0x20,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20, + 0x5f,0x31,0x38,0x31,0x20,0x3d,0x20,0x5f,0x31,0x35,0x39,0x20,0x2b,0x20,0x69,0x6e, + 0x74,0x32,0x28,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x73,0x72,0x63, + 0x5f,0x64,0x65,0x70,0x74,0x68,0x2e,0x72,0x65,0x61,0x64,0x28,0x75,0x69,0x6e,0x74, + 0x32,0x28,0x63,0x6c,0x61,0x6d,0x70,0x28,0x5f,0x31,0x35,0x39,0x2c,0x20,0x69,0x6e, + 0x74,0x32,0x28,0x30,0x29,0x2c,0x20,0x5f,0x31,0x35,0x35,0x29,0x29,0x2c,0x20,0x30, + 0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x32,0x30,0x32,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x6c,0x61, + 0x6d,0x70,0x44,0x65,0x70,0x74,0x68,0x28,0x70,0x61,0x72,0x61,0x6d,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x73,0x72,0x63,0x5f,0x64,0x65,0x70,0x74, + 0x68,0x2e,0x72,0x65,0x61,0x64,0x28,0x75,0x69,0x6e,0x74,0x32,0x28,0x63,0x6c,0x61, + 0x6d,0x70,0x28,0x5f,0x31,0x36,0x39,0x2c,0x20,0x69,0x6e,0x74,0x32,0x28,0x30,0x29, + 0x2c,0x20,0x5f,0x31,0x35,0x35,0x29,0x29,0x2c,0x20,0x30,0x29,0x2e,0x78,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x32,0x20,0x3d, + 0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x43,0x6c,0x61,0x6d,0x70,0x44,0x65,0x70, + 0x74,0x68,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d, + 0x20,0x74,0x65,0x78,0x5f,0x73,0x72,0x63,0x5f,0x64,0x65,0x70,0x74,0x68,0x2e,0x72, + 0x65,0x61,0x64,0x28,0x75,0x69,0x6e,0x74,0x32,0x28,0x63,0x6c,0x61,0x6d,0x70,0x28, + 0x5f,0x31,0x37,0x35,0x2c,0x20,0x69,0x6e,0x74,0x32,0x28,0x30,0x29,0x2c,0x20,0x5f, + 0x31,0x35,0x35,0x29,0x29,0x2c,0x20,0x30,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x32,0x32,0x20,0x3d,0x20,0x58,0x65, + 0x47,0x54,0x41,0x4f,0x5f,0x43,0x6c,0x61,0x6d,0x70,0x44,0x65,0x70,0x74,0x68,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x74,0x65, + 0x78,0x5f,0x73,0x72,0x63,0x5f,0x64,0x65,0x70,0x74,0x68,0x2e,0x72,0x65,0x61,0x64, + 0x28,0x75,0x69,0x6e,0x74,0x32,0x28,0x63,0x6c,0x61,0x6d,0x70,0x28,0x5f,0x31,0x38, + 0x31,0x2c,0x20,0x69,0x6e,0x74,0x32,0x28,0x30,0x29,0x2c,0x20,0x5f,0x31,0x35,0x35, + 0x29,0x29,0x2c,0x20,0x30,0x29,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x32,0x33,0x32,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41, + 0x4f,0x5f,0x43,0x6c,0x61,0x6d,0x70,0x44,0x65,0x70,0x74,0x68,0x28,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x61, + 0x6c,0x6c,0x28,0x5f,0x31,0x35,0x39,0x20,0x3c,0x20,0x67,0x74,0x61,0x6f,0x2e,0x56, + 0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65,0x29,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f, + 0x64,0x65,0x70,0x74,0x68,0x30,0x2e,0x77,0x72,0x69,0x74,0x65,0x28,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x28,0x5f,0x32,0x30,0x32,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30, + 0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x29,0x2c,0x20,0x75,0x69,0x6e,0x74,0x32,0x28, + 0x5f,0x31,0x35,0x39,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x61,0x6c,0x6c,0x28,0x5f,0x31,0x36,0x39,0x20,0x3c, + 0x20,0x67,0x74,0x61,0x6f,0x2e,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69, + 0x7a,0x65,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x64,0x65,0x70,0x74,0x68,0x30,0x2e,0x77,0x72, + 0x69,0x74,0x65,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x32,0x31,0x32,0x2c, + 0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x29,0x2c, + 0x20,0x75,0x69,0x6e,0x74,0x32,0x28,0x5f,0x31,0x36,0x39,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x61,0x6c,0x6c, + 0x28,0x5f,0x31,0x37,0x35,0x20,0x3c,0x20,0x67,0x74,0x61,0x6f,0x2e,0x56,0x69,0x65, + 0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65,0x29,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x64,0x65, + 0x70,0x74,0x68,0x30,0x2e,0x77,0x72,0x69,0x74,0x65,0x28,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x28,0x5f,0x32,0x32,0x32,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30, + 0x2c,0x20,0x30,0x2e,0x30,0x29,0x2c,0x20,0x75,0x69,0x6e,0x74,0x32,0x28,0x5f,0x31, + 0x37,0x35,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x61,0x6c,0x6c,0x28,0x5f,0x31,0x38,0x31,0x20,0x3c,0x20,0x67, + 0x74,0x61,0x6f,0x2e,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65, + 0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x6f,0x75,0x74,0x5f,0x64,0x65,0x70,0x74,0x68,0x30,0x2e,0x77,0x72,0x69,0x74, + 0x65,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x32,0x33,0x32,0x2c,0x20,0x30, + 0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x29,0x2c,0x20,0x75, + 0x69,0x6e,0x74,0x32,0x28,0x5f,0x31,0x38,0x31,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x32,0x30,0x32,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d, + 0x20,0x5f,0x32,0x31,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f,0x32,0x32,0x32,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x37,0x20,0x3d,0x20,0x5f,0x32,0x33,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x39,0x39,0x20,0x3d,0x20,0x58,0x65,0x47,0x54, + 0x41,0x4f,0x5f,0x44,0x65,0x70,0x74,0x68,0x4d,0x49,0x50,0x46,0x69,0x6c,0x74,0x65, + 0x72,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x37,0x2c,0x20,0x67,0x74,0x61,0x6f,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x61,0x6c,0x6c,0x28,0x5f,0x31,0x34,0x33,0x20,0x3c,0x20, + 0x67,0x74,0x61,0x6f,0x2e,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a, + 0x65,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x6f,0x75,0x74,0x5f,0x64,0x65,0x70,0x74,0x68,0x31,0x2e,0x77,0x72,0x69, + 0x74,0x65,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x32,0x39,0x39,0x2c,0x20, + 0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x29,0x2c,0x20, + 0x75,0x69,0x6e,0x74,0x32,0x28,0x5f,0x31,0x34,0x33,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x33,0x31,0x39, + 0x20,0x3d,0x20,0x5f,0x31,0x34,0x38,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x6e,0x74,0x20,0x5f,0x33,0x32,0x32,0x20,0x3d,0x20,0x5f,0x31,0x34,0x38,0x2e,0x79, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x5f,0x73,0x63,0x72,0x61,0x74,0x63,0x68,0x44, + 0x65,0x70,0x74,0x68,0x73,0x5b,0x5f,0x33,0x31,0x39,0x5d,0x5b,0x5f,0x33,0x32,0x32, + 0x5d,0x20,0x3d,0x20,0x5f,0x32,0x39,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x74,0x68, + 0x72,0x65,0x61,0x64,0x67,0x72,0x6f,0x75,0x70,0x5f,0x62,0x61,0x72,0x72,0x69,0x65, + 0x72,0x28,0x6d,0x65,0x6d,0x5f,0x66,0x6c,0x61,0x67,0x73,0x3a,0x3a,0x6d,0x65,0x6d, + 0x5f,0x74,0x68,0x72,0x65,0x61,0x64,0x67,0x72,0x6f,0x75,0x70,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x64,0x6d,0x32,0x20,0x3d,0x20,0x30, + 0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x61,0x6c,0x6c,0x28, + 0x28,0x5f,0x31,0x34,0x38,0x20,0x26,0x20,0x69,0x6e,0x74,0x32,0x28,0x31,0x29,0x29, + 0x20,0x3d,0x3d,0x20,0x69,0x6e,0x74,0x32,0x28,0x30,0x29,0x29,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20, + 0x5f,0x33,0x35,0x30,0x20,0x3d,0x20,0x5f,0x33,0x31,0x39,0x20,0x2b,0x20,0x31,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x33,0x36, + 0x32,0x20,0x3d,0x20,0x5f,0x33,0x32,0x32,0x20,0x2b,0x20,0x31,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x38,0x20,0x3d,0x20,0x67,0x5f,0x73,0x63,0x72,0x61,0x74,0x63,0x68,0x44, + 0x65,0x70,0x74,0x68,0x73,0x5b,0x5f,0x33,0x31,0x39,0x5d,0x5b,0x5f,0x33,0x32,0x32, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x67,0x5f,0x73,0x63,0x72, + 0x61,0x74,0x63,0x68,0x44,0x65,0x70,0x74,0x68,0x73,0x5b,0x5f,0x33,0x35,0x30,0x5d, + 0x5b,0x5f,0x33,0x32,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d, + 0x20,0x67,0x5f,0x73,0x63,0x72,0x61,0x74,0x63,0x68,0x44,0x65,0x70,0x74,0x68,0x73, + 0x5b,0x5f,0x33,0x31,0x39,0x5d,0x5b,0x5f,0x33,0x36,0x32,0x5d,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x67,0x5f,0x73,0x63,0x72,0x61,0x74,0x63,0x68, + 0x44,0x65,0x70,0x74,0x68,0x73,0x5b,0x5f,0x33,0x35,0x30,0x5d,0x5b,0x5f,0x33,0x36, + 0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x64,0x6d,0x32,0x20, + 0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x44,0x65,0x70,0x74,0x68,0x4d,0x49, + 0x50,0x46,0x69,0x6c,0x74,0x65,0x72,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20,0x67,0x74, + 0x61,0x6f,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74, + 0x32,0x20,0x5f,0x33,0x38,0x38,0x20,0x3d,0x20,0x69,0x6e,0x74,0x32,0x28,0x75,0x69, + 0x6e,0x74,0x32,0x28,0x5f,0x31,0x34,0x33,0x29,0x20,0x3e,0x3e,0x20,0x75,0x69,0x6e, + 0x74,0x32,0x28,0x31,0x75,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x61,0x6c,0x6c,0x28,0x5f,0x33,0x38,0x38,0x20,0x3c,0x20, + 0x67,0x74,0x61,0x6f,0x2e,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a, + 0x65,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x64,0x65, + 0x70,0x74,0x68,0x32,0x2e,0x77,0x72,0x69,0x74,0x65,0x28,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x28,0x64,0x6d,0x32,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c, + 0x20,0x30,0x2e,0x30,0x29,0x2c,0x20,0x75,0x69,0x6e,0x74,0x32,0x28,0x5f,0x33,0x38, + 0x38,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x67,0x5f,0x73,0x63,0x72,0x61,0x74,0x63,0x68, + 0x44,0x65,0x70,0x74,0x68,0x73,0x5b,0x5f,0x33,0x31,0x39,0x5d,0x5b,0x5f,0x33,0x32, + 0x32,0x5d,0x20,0x3d,0x20,0x64,0x6d,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x67,0x72,0x6f,0x75,0x70,0x5f, + 0x62,0x61,0x72,0x72,0x69,0x65,0x72,0x28,0x6d,0x65,0x6d,0x5f,0x66,0x6c,0x61,0x67, + 0x73,0x3a,0x3a,0x6d,0x65,0x6d,0x5f,0x74,0x68,0x72,0x65,0x61,0x64,0x67,0x72,0x6f, + 0x75,0x70,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x64, + 0x6d,0x33,0x20,0x3d,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x61,0x6c,0x6c,0x28,0x28,0x5f,0x31,0x34,0x38,0x20,0x26,0x20,0x69,0x6e, + 0x74,0x32,0x28,0x33,0x29,0x29,0x20,0x3d,0x3d,0x20,0x69,0x6e,0x74,0x32,0x28,0x30, + 0x29,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x34,0x32,0x39,0x20,0x3d,0x20,0x5f,0x33,0x31, + 0x39,0x20,0x2b,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x6e,0x74,0x20,0x5f,0x34,0x34,0x31,0x20,0x3d,0x20,0x5f,0x33,0x32,0x32,0x20,0x2b, + 0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x67,0x5f,0x73, + 0x63,0x72,0x61,0x74,0x63,0x68,0x44,0x65,0x70,0x74,0x68,0x73,0x5b,0x5f,0x33,0x31, + 0x39,0x5d,0x5b,0x5f,0x33,0x32,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33, + 0x20,0x3d,0x20,0x67,0x5f,0x73,0x63,0x72,0x61,0x74,0x63,0x68,0x44,0x65,0x70,0x74, + 0x68,0x73,0x5b,0x5f,0x34,0x32,0x39,0x5d,0x5b,0x5f,0x33,0x32,0x32,0x5d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x67,0x5f,0x73,0x63,0x72,0x61,0x74, + 0x63,0x68,0x44,0x65,0x70,0x74,0x68,0x73,0x5b,0x5f,0x33,0x31,0x39,0x5d,0x5b,0x5f, + 0x34,0x34,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x67, + 0x5f,0x73,0x63,0x72,0x61,0x74,0x63,0x68,0x44,0x65,0x70,0x74,0x68,0x73,0x5b,0x5f, + 0x34,0x32,0x39,0x5d,0x5b,0x5f,0x34,0x34,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x64,0x6d,0x33,0x20,0x3d,0x20,0x58,0x65,0x47,0x54,0x41,0x4f, + 0x5f,0x44,0x65,0x70,0x74,0x68,0x4d,0x49,0x50,0x46,0x69,0x6c,0x74,0x65,0x72,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c,0x20,0x67,0x74,0x61,0x6f,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x5f,0x34,0x36,0x37, + 0x20,0x3d,0x20,0x69,0x6e,0x74,0x32,0x28,0x75,0x69,0x6e,0x74,0x32,0x28,0x5f,0x31, + 0x34,0x33,0x29,0x20,0x3e,0x3e,0x20,0x75,0x69,0x6e,0x74,0x32,0x28,0x32,0x75,0x29, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x61, + 0x6c,0x6c,0x28,0x5f,0x34,0x36,0x37,0x20,0x3c,0x20,0x67,0x74,0x61,0x6f,0x2e,0x56, + 0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65,0x29,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x64,0x65,0x70,0x74,0x68,0x33,0x2e,0x77, + 0x72,0x69,0x74,0x65,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x64,0x6d,0x33,0x2c, + 0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x29,0x2c, + 0x20,0x75,0x69,0x6e,0x74,0x32,0x28,0x5f,0x34,0x36,0x37,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x67,0x5f,0x73,0x63,0x72,0x61,0x74,0x63,0x68,0x44,0x65,0x70,0x74,0x68,0x73, + 0x5b,0x5f,0x33,0x31,0x39,0x5d,0x5b,0x5f,0x33,0x32,0x32,0x5d,0x20,0x3d,0x20,0x64, + 0x6d,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x74,0x68, + 0x72,0x65,0x61,0x64,0x67,0x72,0x6f,0x75,0x70,0x5f,0x62,0x61,0x72,0x72,0x69,0x65, + 0x72,0x28,0x6d,0x65,0x6d,0x5f,0x66,0x6c,0x61,0x67,0x73,0x3a,0x3a,0x6d,0x65,0x6d, + 0x5f,0x74,0x68,0x72,0x65,0x61,0x64,0x67,0x72,0x6f,0x75,0x70,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x61,0x6c,0x6c,0x28,0x5f,0x31,0x34,0x38,0x20, + 0x3d,0x3d,0x20,0x69,0x6e,0x74,0x32,0x28,0x30,0x29,0x29,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x67,0x5f,0x73,0x63, + 0x72,0x61,0x74,0x63,0x68,0x44,0x65,0x70,0x74,0x68,0x73,0x5b,0x30,0x5d,0x5b,0x30, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x20,0x3d,0x20,0x67,0x5f,0x73,0x63, + 0x72,0x61,0x74,0x63,0x68,0x44,0x65,0x70,0x74,0x68,0x73,0x5b,0x34,0x5d,0x5b,0x30, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x67,0x5f,0x73,0x63, + 0x72,0x61,0x74,0x63,0x68,0x44,0x65,0x70,0x74,0x68,0x73,0x5b,0x30,0x5d,0x5b,0x34, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20,0x67,0x5f,0x73,0x63, + 0x72,0x61,0x74,0x63,0x68,0x44,0x65,0x70,0x74,0x68,0x73,0x5b,0x34,0x5d,0x5b,0x34, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20, + 0x5f,0x35,0x32,0x30,0x20,0x3d,0x20,0x69,0x6e,0x74,0x32,0x28,0x75,0x69,0x6e,0x74, + 0x32,0x28,0x5f,0x31,0x34,0x33,0x29,0x20,0x3e,0x3e,0x20,0x75,0x69,0x6e,0x74,0x32, + 0x28,0x33,0x75,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x61,0x6c,0x6c,0x28,0x5f,0x35,0x32,0x30,0x20,0x3c,0x20,0x67,0x74, + 0x61,0x6f,0x2e,0x56,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x53,0x69,0x7a,0x65,0x29, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x64,0x65,0x70,0x74, + 0x68,0x34,0x2e,0x77,0x72,0x69,0x74,0x65,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, + 0x58,0x65,0x47,0x54,0x41,0x4f,0x5f,0x44,0x65,0x70,0x74,0x68,0x4d,0x49,0x50,0x46, + 0x69,0x6c,0x74,0x65,0x72,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20,0x67,0x74, + 0x61,0x6f,0x29,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30, + 0x2e,0x30,0x29,0x2c,0x20,0x75,0x69,0x6e,0x74,0x32,0x28,0x5f,0x35,0x32,0x30,0x29, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x7d,0x0a,0x0a,0x00, +}; +static inline const sg_shader_desc* gtao_prefilter_depth_prog_shader_desc(sg_backend backend) { + if (backend == SG_BACKEND_GLCORE) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.compute_func.source = (const char*)gtao_prefilter_depth_cs_source_glsl430; + desc.compute_func.entry = "main"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_COMPUTE; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 32; + desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_INT2; + desc.uniform_blocks[0].glsl_uniforms[0].array_count = 0; + desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "gtao.ViewportSize"; + desc.uniform_blocks[0].glsl_uniforms[1].type = SG_UNIFORMTYPE_FLOAT; + desc.uniform_blocks[0].glsl_uniforms[1].array_count = 0; + desc.uniform_blocks[0].glsl_uniforms[1].glsl_name = "gtao.EffectRadius"; + desc.uniform_blocks[0].glsl_uniforms[2].type = SG_UNIFORMTYPE_FLOAT; + desc.uniform_blocks[0].glsl_uniforms[2].array_count = 0; + desc.uniform_blocks[0].glsl_uniforms[2].glsl_name = "gtao.EffectFalloffRange"; + desc.uniform_blocks[0].glsl_uniforms[3].type = SG_UNIFORMTYPE_FLOAT; + desc.uniform_blocks[0].glsl_uniforms[3].array_count = 0; + desc.uniform_blocks[0].glsl_uniforms[3].glsl_name = "gtao.RadiusMultiplier"; + desc.views[0].storage_image.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[0].storage_image.image_type = SG_IMAGETYPE_2D; + desc.views[0].storage_image.access_format = SG_PIXELFORMAT_R32F; + desc.views[0].storage_image.writeonly = true; + desc.views[0].storage_image.glsl_binding_n = 0; + desc.views[1].storage_image.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[1].storage_image.image_type = SG_IMAGETYPE_2D; + desc.views[1].storage_image.access_format = SG_PIXELFORMAT_R32F; + desc.views[1].storage_image.writeonly = true; + desc.views[1].storage_image.glsl_binding_n = 1; + desc.views[2].storage_image.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[2].storage_image.image_type = SG_IMAGETYPE_2D; + desc.views[2].storage_image.access_format = SG_PIXELFORMAT_R32F; + desc.views[2].storage_image.writeonly = true; + desc.views[2].storage_image.glsl_binding_n = 2; + desc.views[3].storage_image.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[3].storage_image.image_type = SG_IMAGETYPE_2D; + desc.views[3].storage_image.access_format = SG_PIXELFORMAT_R32F; + desc.views[3].storage_image.writeonly = true; + desc.views[3].storage_image.glsl_binding_n = 3; + desc.views[4].storage_image.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[4].storage_image.image_type = SG_IMAGETYPE_2D; + desc.views[4].storage_image.access_format = SG_PIXELFORMAT_R32F; + desc.views[4].storage_image.writeonly = true; + desc.views[4].storage_image.glsl_binding_n = 4; + desc.views[5].texture.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[5].texture.image_type = SG_IMAGETYPE_2D; + desc.views[5].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[5].texture.multisampled = false; + desc.samplers[0].stage = SG_SHADERSTAGE_COMPUTE; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_COMPUTE; + desc.texture_sampler_pairs[0].view_slot = 5; + desc.texture_sampler_pairs[0].sampler_slot = 0; + desc.texture_sampler_pairs[0].glsl_name = "tex_src_depth_smp_src_depth"; + desc.label = "gtao_prefilter_depth_prog_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_D3D11) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.compute_func.source = (const char*)gtao_prefilter_depth_cs_source_hlsl5; + desc.compute_func.d3d11_target = "cs_5_0"; + desc.compute_func.entry = "main"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_COMPUTE; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 32; + desc.uniform_blocks[0].hlsl_register_b_n = 0; + desc.views[0].storage_image.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[0].storage_image.image_type = SG_IMAGETYPE_2D; + desc.views[0].storage_image.access_format = SG_PIXELFORMAT_R32F; + desc.views[0].storage_image.writeonly = true; + desc.views[0].storage_image.hlsl_register_u_n = 0; + desc.views[1].storage_image.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[1].storage_image.image_type = SG_IMAGETYPE_2D; + desc.views[1].storage_image.access_format = SG_PIXELFORMAT_R32F; + desc.views[1].storage_image.writeonly = true; + desc.views[1].storage_image.hlsl_register_u_n = 1; + desc.views[2].storage_image.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[2].storage_image.image_type = SG_IMAGETYPE_2D; + desc.views[2].storage_image.access_format = SG_PIXELFORMAT_R32F; + desc.views[2].storage_image.writeonly = true; + desc.views[2].storage_image.hlsl_register_u_n = 2; + desc.views[3].storage_image.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[3].storage_image.image_type = SG_IMAGETYPE_2D; + desc.views[3].storage_image.access_format = SG_PIXELFORMAT_R32F; + desc.views[3].storage_image.writeonly = true; + desc.views[3].storage_image.hlsl_register_u_n = 3; + desc.views[4].storage_image.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[4].storage_image.image_type = SG_IMAGETYPE_2D; + desc.views[4].storage_image.access_format = SG_PIXELFORMAT_R32F; + desc.views[4].storage_image.writeonly = true; + desc.views[4].storage_image.hlsl_register_u_n = 4; + desc.views[5].texture.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[5].texture.image_type = SG_IMAGETYPE_2D; + desc.views[5].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[5].texture.multisampled = false; + desc.views[5].texture.hlsl_register_t_n = 0; + desc.samplers[0].stage = SG_SHADERSTAGE_COMPUTE; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[0].hlsl_register_s_n = 0; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_COMPUTE; + desc.texture_sampler_pairs[0].view_slot = 5; + desc.texture_sampler_pairs[0].sampler_slot = 0; + desc.label = "gtao_prefilter_depth_prog_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_METAL_MACOS) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.compute_func.source = (const char*)gtao_prefilter_depth_cs_source_metal_macos; + desc.compute_func.entry = "main0"; + desc.mtl_threads_per_threadgroup.x = 8; + desc.mtl_threads_per_threadgroup.y = 8; + desc.mtl_threads_per_threadgroup.z = 1; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_COMPUTE; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 32; + desc.uniform_blocks[0].msl_buffer_n = 0; + desc.views[0].storage_image.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[0].storage_image.image_type = SG_IMAGETYPE_2D; + desc.views[0].storage_image.access_format = SG_PIXELFORMAT_R32F; + desc.views[0].storage_image.writeonly = true; + desc.views[0].storage_image.msl_texture_n = 0; + desc.views[1].storage_image.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[1].storage_image.image_type = SG_IMAGETYPE_2D; + desc.views[1].storage_image.access_format = SG_PIXELFORMAT_R32F; + desc.views[1].storage_image.writeonly = true; + desc.views[1].storage_image.msl_texture_n = 1; + desc.views[2].storage_image.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[2].storage_image.image_type = SG_IMAGETYPE_2D; + desc.views[2].storage_image.access_format = SG_PIXELFORMAT_R32F; + desc.views[2].storage_image.writeonly = true; + desc.views[2].storage_image.msl_texture_n = 2; + desc.views[3].storage_image.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[3].storage_image.image_type = SG_IMAGETYPE_2D; + desc.views[3].storage_image.access_format = SG_PIXELFORMAT_R32F; + desc.views[3].storage_image.writeonly = true; + desc.views[3].storage_image.msl_texture_n = 3; + desc.views[4].storage_image.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[4].storage_image.image_type = SG_IMAGETYPE_2D; + desc.views[4].storage_image.access_format = SG_PIXELFORMAT_R32F; + desc.views[4].storage_image.writeonly = true; + desc.views[4].storage_image.msl_texture_n = 4; + desc.views[5].texture.stage = SG_SHADERSTAGE_COMPUTE; + desc.views[5].texture.image_type = SG_IMAGETYPE_2D; + desc.views[5].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[5].texture.multisampled = false; + desc.views[5].texture.msl_texture_n = 5; + desc.samplers[0].stage = SG_SHADERSTAGE_COMPUTE; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[0].msl_sampler_n = 0; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_COMPUTE; + desc.texture_sampler_pairs[0].view_slot = 5; + desc.texture_sampler_pairs[0].sampler_slot = 0; + desc.label = "gtao_prefilter_depth_prog_shader"; + } + return &desc; + } + return 0; +} diff --git a/samples/shaders/generated/highlight_outline.glsl.h b/samples/shaders/generated/highlight_outline.glsl.h new file mode 100644 index 0000000..6da1a5a --- /dev/null +++ b/samples/shaders/generated/highlight_outline.glsl.h @@ -0,0 +1,1321 @@ +#pragma once +/* + #version:1# (machine generated, don't edit!) + + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) + + Cmdline: + sokol-shdc --input E:/box/box3d/samples/shaders/post/highlight_outline.glsl --output E:/box/box3d/samples/shaders/generated/highlight_outline.glsl.h --slang hlsl5:metal_macos:glsl430 + + Overview: + ========= + Shader program: 'prog': + Get shader desc: highlight_outline_prog_shader_desc(sg_query_backend()); + Vertex Shader: vs + Fragment Shader: fs + Attributes: + Bindings: + Uniform block 'ub_pass': + C struct: highlight_outline_ub_pass_t + Bind slot: UB_highlight_outline_ub_pass => 0 + Texture 'tex_mask': + Image type: SG_IMAGETYPE_2D + Sample type: SG_IMAGESAMPLETYPE_FLOAT + Multisampled: false + Bind slot: VIEW_highlight_outline_tex_mask => 0 + Sampler 'smp_mask': + Type: SG_SAMPLERTYPE_FILTERING + Bind slot: SMP_highlight_outline_smp_mask => 0 +*/ +#if !defined(SOKOL_GFX_INCLUDED) +#error "Please include sokol_gfx.h before highlight_outline.glsl.h" +#endif +#if !defined(SOKOL_SHDC_ALIGN) +#if defined(_MSC_VER) +#define SOKOL_SHDC_ALIGN(a) __declspec(align(a)) +#else +#define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) +#endif +#endif +#define UB_highlight_outline_ub_pass (0) +#define VIEW_highlight_outline_tex_mask (0) +#define SMP_highlight_outline_smp_mask (0) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct highlight_outline_ub_pass_t { + Vec4 hover_color; + Vec4 select_color; + Vec4 thickness_px; +} highlight_outline_ub_pass_t; +#pragma pack(pop) +/* + #version 430 + + void main() + { + gl_Position = vec4((gl_VertexID == 1) ? 3.0 : (-1.0), (gl_VertexID == 2) ? 3.0 : (-1.0), 0.0, 1.0); + } + +*/ +static const uint8_t highlight_outline_vs_source_glsl430[136] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x76,0x6f, + 0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x76,0x65, + 0x63,0x34,0x28,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x44,0x20, + 0x3d,0x3d,0x20,0x31,0x29,0x20,0x3f,0x20,0x33,0x2e,0x30,0x20,0x3a,0x20,0x28,0x2d, + 0x31,0x2e,0x30,0x29,0x2c,0x20,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78, + 0x49,0x44,0x20,0x3d,0x3d,0x20,0x32,0x29,0x20,0x3f,0x20,0x33,0x2e,0x30,0x20,0x3a, + 0x20,0x28,0x2d,0x31,0x2e,0x30,0x29,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e, + 0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + #version 430 + + uniform vec4 ub_pass[3]; + layout(binding = 0) uniform sampler2D tex_mask_smp_mask; + + layout(location = 0) out vec4 out_color; + + void main() + { + ivec2 _17 = ivec2(gl_FragCoord.xy); + ivec2 _31 = textureSize(tex_mask_smp_mask, 0); + if (texelFetch(tex_mask_smp_mask, _17, 0).x > 0.25) + { + out_color = vec4(0.0); + return; + } + int _68 = clamp(int(ub_pass[2].x + 0.5), 1, 4); + int _75 = clamp(int(ub_pass[2].y + 0.5), 1, 4); + int _79 = max(_68, _75); + bool sawSelectInSelectR = false; + bool sawHoverInHoverR = false; + bool sawHoverInSelectR = false; + ivec2 off; + for (int r = 1; r <= _79; r++) + { + for (int i = 0; i < 4; i++) + { + if (i == 0) + { + off = ivec2(r, 0); + } + else + { + if (i == 1) + { + off = ivec2(-r, 0); + } + else + { + if (i == 2) + { + off = ivec2(0, r); + } + else + { + off = ivec2(0, -r); + } + } + } + ivec2 _131 = _17 + off; + int _133 = _131.x; + bool _134 = _133 < 0; + bool _141; + if (!_134) + { + _141 = _131.y < 0; + } + else + { + _141 = _134; + } + bool _150; + if (!_141) + { + _150 = _133 >= _31.x; + } + else + { + _150 = _141; + } + bool _159; + if (!_150) + { + _159 = _131.y >= _31.y; + } + else + { + _159 = _150; + } + if (_159) + { + continue; + } + vec4 _169 = texelFetch(tex_mask_smp_mask, _131, 0); + float _170 = _169.x; + if (_170 <= 0.25) + { + continue; + } + if (_170 >= 0.75) + { + if (r <= _75) + { + sawSelectInSelectR = true; + } + } + else + { + if (r <= _68) + { + sawHoverInHoverR = true; + } + if (r <= _75) + { + sawHoverInSelectR = true; + } + } + } + } + if (sawSelectInSelectR) + { + out_color = ub_pass[1]; + return; + } + if (sawHoverInHoverR) + { + out_color = ub_pass[0]; + return; + } + if (sawHoverInSelectR) + { + out_color = ub_pass[0]; + return; + } + out_color = vec4(0.0); + } + +*/ +static const uint8_t highlight_outline_fs_source_glsl430[2889] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x75,0x6e, + 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x70,0x61, + 0x73,0x73,0x5b,0x33,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69, + 0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x30,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f, + 0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78, + 0x5f,0x6d,0x61,0x73,0x6b,0x5f,0x73,0x6d,0x70,0x5f,0x6d,0x61,0x73,0x6b,0x3b,0x0a, + 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x6f, + 0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20, + 0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x76,0x65, + 0x63,0x32,0x20,0x5f,0x31,0x37,0x20,0x3d,0x20,0x69,0x76,0x65,0x63,0x32,0x28,0x67, + 0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x76,0x65,0x63,0x32,0x20,0x5f,0x33,0x31,0x20,0x3d, + 0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x74,0x65,0x78, + 0x5f,0x6d,0x61,0x73,0x6b,0x5f,0x73,0x6d,0x70,0x5f,0x6d,0x61,0x73,0x6b,0x2c,0x20, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x74,0x65,0x78,0x65, + 0x6c,0x46,0x65,0x74,0x63,0x68,0x28,0x74,0x65,0x78,0x5f,0x6d,0x61,0x73,0x6b,0x5f, + 0x73,0x6d,0x70,0x5f,0x6d,0x61,0x73,0x6b,0x2c,0x20,0x5f,0x31,0x37,0x2c,0x20,0x30, + 0x29,0x2e,0x78,0x20,0x3e,0x20,0x30,0x2e,0x32,0x35,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x30,0x2e,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f, + 0x36,0x38,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x69,0x6e,0x74,0x28,0x75, + 0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x32,0x5d,0x2e,0x78,0x20,0x2b,0x20,0x30,0x2e, + 0x35,0x29,0x2c,0x20,0x31,0x2c,0x20,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x6e,0x74,0x20,0x5f,0x37,0x35,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x69, + 0x6e,0x74,0x28,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x32,0x5d,0x2e,0x79,0x20, + 0x2b,0x20,0x30,0x2e,0x35,0x29,0x2c,0x20,0x31,0x2c,0x20,0x34,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x37,0x39,0x20,0x3d,0x20,0x6d,0x61,0x78, + 0x28,0x5f,0x36,0x38,0x2c,0x20,0x5f,0x37,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x62,0x6f,0x6f,0x6c,0x20,0x73,0x61,0x77,0x53,0x65,0x6c,0x65,0x63,0x74,0x49,0x6e, + 0x53,0x65,0x6c,0x65,0x63,0x74,0x52,0x20,0x3d,0x20,0x66,0x61,0x6c,0x73,0x65,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x73,0x61,0x77,0x48,0x6f,0x76, + 0x65,0x72,0x49,0x6e,0x48,0x6f,0x76,0x65,0x72,0x52,0x20,0x3d,0x20,0x66,0x61,0x6c, + 0x73,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x73,0x61,0x77, + 0x48,0x6f,0x76,0x65,0x72,0x49,0x6e,0x53,0x65,0x6c,0x65,0x63,0x74,0x52,0x20,0x3d, + 0x20,0x66,0x61,0x6c,0x73,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x76,0x65,0x63, + 0x32,0x20,0x6f,0x66,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x20,0x28, + 0x69,0x6e,0x74,0x20,0x72,0x20,0x3d,0x20,0x31,0x3b,0x20,0x72,0x20,0x3c,0x3d,0x20, + 0x5f,0x37,0x39,0x3b,0x20,0x72,0x2b,0x2b,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x20,0x28,0x69,0x6e,0x74, + 0x20,0x69,0x20,0x3d,0x20,0x30,0x3b,0x20,0x69,0x20,0x3c,0x20,0x34,0x3b,0x20,0x69, + 0x2b,0x2b,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x20, + 0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x6f,0x66,0x66,0x20,0x3d,0x20,0x69,0x76,0x65,0x63,0x32,0x28, + 0x72,0x2c,0x20,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x66,0x66,0x20,0x3d,0x20,0x69,0x76,0x65,0x63, + 0x32,0x28,0x2d,0x72,0x2c,0x20,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x20,0x3d,0x3d,0x20, + 0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x6f,0x66,0x66,0x20,0x3d,0x20,0x69,0x76,0x65,0x63,0x32,0x28,0x30,0x2c,0x20, + 0x72,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c, + 0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x6f,0x66,0x66,0x20,0x3d,0x20,0x69,0x76,0x65,0x63,0x32,0x28,0x30,0x2c,0x20, + 0x2d,0x72,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x76,0x65,0x63,0x32,0x20,0x5f,0x31,0x33, + 0x31,0x20,0x3d,0x20,0x5f,0x31,0x37,0x20,0x2b,0x20,0x6f,0x66,0x66,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f, + 0x31,0x33,0x33,0x20,0x3d,0x20,0x5f,0x31,0x33,0x31,0x2e,0x78,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f, + 0x31,0x33,0x34,0x20,0x3d,0x20,0x5f,0x31,0x33,0x33,0x20,0x3c,0x20,0x30,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c, + 0x20,0x5f,0x31,0x34,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x33,0x34,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x34,0x31, + 0x20,0x3d,0x20,0x5f,0x31,0x33,0x31,0x2e,0x79,0x20,0x3c,0x20,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x34,0x31, + 0x20,0x3d,0x20,0x5f,0x31,0x33,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x35,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f, + 0x31,0x34,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x5f,0x31,0x35,0x30,0x20,0x3d,0x20,0x5f,0x31,0x33,0x33,0x20,0x3e, + 0x3d,0x20,0x5f,0x33,0x31,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x35,0x30,0x20,0x3d,0x20,0x5f,0x31,0x34, + 0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f, + 0x6c,0x20,0x5f,0x31,0x35,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x35,0x30,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x35, + 0x39,0x20,0x3d,0x20,0x5f,0x31,0x33,0x31,0x2e,0x79,0x20,0x3e,0x3d,0x20,0x5f,0x33, + 0x31,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65, + 0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x5f,0x31,0x35,0x39,0x20,0x3d,0x20,0x5f,0x31,0x35,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x35, + 0x39,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x63,0x6f,0x6e,0x74,0x69,0x6e,0x75,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x31,0x36,0x39,0x20,0x3d, + 0x20,0x74,0x65,0x78,0x65,0x6c,0x46,0x65,0x74,0x63,0x68,0x28,0x74,0x65,0x78,0x5f, + 0x6d,0x61,0x73,0x6b,0x5f,0x73,0x6d,0x70,0x5f,0x6d,0x61,0x73,0x6b,0x2c,0x20,0x5f, + 0x31,0x33,0x31,0x2c,0x20,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x37,0x30,0x20, + 0x3d,0x20,0x5f,0x31,0x36,0x39,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x37,0x30,0x20,0x3c, + 0x3d,0x20,0x30,0x2e,0x32,0x35,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x6f,0x6e,0x74,0x69,0x6e,0x75,0x65,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31, + 0x37,0x30,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x37,0x35,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x72,0x20, + 0x3c,0x3d,0x20,0x5f,0x37,0x35,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x61, + 0x77,0x53,0x65,0x6c,0x65,0x63,0x74,0x49,0x6e,0x53,0x65,0x6c,0x65,0x63,0x74,0x52, + 0x20,0x3d,0x20,0x74,0x72,0x75,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x72,0x20,0x3c,0x3d, + 0x20,0x5f,0x36,0x38,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x61,0x77,0x48, + 0x6f,0x76,0x65,0x72,0x49,0x6e,0x48,0x6f,0x76,0x65,0x72,0x52,0x20,0x3d,0x20,0x74, + 0x72,0x75,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x72,0x20,0x3c,0x3d,0x20, + 0x5f,0x37,0x35,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x61,0x77,0x48,0x6f, + 0x76,0x65,0x72,0x49,0x6e,0x53,0x65,0x6c,0x65,0x63,0x74,0x52,0x20,0x3d,0x20,0x74, + 0x72,0x75,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x73,0x61,0x77, + 0x53,0x65,0x6c,0x65,0x63,0x74,0x49,0x6e,0x53,0x65,0x6c,0x65,0x63,0x74,0x52,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f, + 0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x75,0x62,0x5f,0x70,0x61, + 0x73,0x73,0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x73,0x61,0x77,0x48,0x6f,0x76,0x65,0x72,0x49,0x6e,0x48, + 0x6f,0x76,0x65,0x72,0x52,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, + 0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x73,0x61,0x77,0x48,0x6f, + 0x76,0x65,0x72,0x49,0x6e,0x53,0x65,0x6c,0x65,0x63,0x74,0x52,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b, + 0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75, + 0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x30, + 0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + static float4 gl_Position; + static int gl_VertexIndex; + struct SPIRV_Cross_Input + { + uint gl_VertexIndex : SV_VertexID; + }; + + struct SPIRV_Cross_Output + { + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + gl_Position = float4((gl_VertexIndex == 1) ? 3.0f : (-1.0f), (gl_VertexIndex == 2) ? 3.0f : (-1.0f), 0.0f, 1.0f); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_VertexIndex = int(stage_input.gl_VertexIndex); + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + return stage_output; + } +*/ +static const uint8_t highlight_outline_vs_source_hlsl5[571] = { + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c, + 0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69, + 0x63,0x20,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49, + 0x6e,0x64,0x65,0x78,0x3b,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49, + 0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x56,0x65,0x72, + 0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x3a,0x20,0x53,0x56,0x5f,0x56,0x65, + 0x72,0x74,0x65,0x78,0x49,0x44,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75, + 0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f, + 0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a, + 0x20,0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e, + 0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x67, + 0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x3d,0x3d, + 0x20,0x31,0x29,0x20,0x3f,0x20,0x33,0x2e,0x30,0x66,0x20,0x3a,0x20,0x28,0x2d,0x31, + 0x2e,0x30,0x66,0x29,0x2c,0x20,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78, + 0x49,0x6e,0x64,0x65,0x78,0x20,0x3d,0x3d,0x20,0x32,0x29,0x20,0x3f,0x20,0x33,0x2e, + 0x30,0x66,0x20,0x3a,0x20,0x28,0x2d,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x30,0x2e, + 0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50, + 0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74, + 0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73, + 0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e, + 0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x56,0x65, + 0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x3d,0x20,0x69,0x6e,0x74,0x28, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x56, + 0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75, + 0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75, + 0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74, + 0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20, + 0x3d,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f, + 0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + cbuffer ub_pass : register(b0) + { + float4 _58_hover_color : packoffset(c0); + float4 _58_select_color : packoffset(c1); + float4 _58_thickness_px : packoffset(c2); + }; + + Texture2D tex_mask : register(t0); + SamplerState smp_mask : register(s0); + + static float4 gl_FragCoord; + static float4 out_color; + + struct SPIRV_Cross_Input + { + float4 gl_FragCoord : SV_Position; + }; + + struct SPIRV_Cross_Output + { + float4 out_color : SV_Target0; + }; + + uint2 spvTextureSize(Texture2D Tex, uint Level, out uint Param) + { + uint2 ret; + Tex.GetDimensions(Level, ret.x, ret.y, Param); + return ret; + } + + void frag_main() + { + int2 _17 = int2(gl_FragCoord.xy); + uint _31_dummy_parameter; + int2 _31 = int2(spvTextureSize(tex_mask, uint(0), _31_dummy_parameter)); + if (tex_mask.Load(int3(_17, 0)).x > 0.25f) + { + out_color = 0.0f.xxxx; + return; + } + int _68 = clamp(int(_58_thickness_px.x + 0.5f), 1, 4); + int _75 = clamp(int(_58_thickness_px.y + 0.5f), 1, 4); + int _79 = max(_68, _75); + bool sawSelectInSelectR = false; + bool sawHoverInHoverR = false; + bool sawHoverInSelectR = false; + int2 off; + for (int r = 1; r <= _79; r++) + { + for (int i = 0; i < 4; i++) + { + if (i == 0) + { + off = int2(r, 0); + } + else + { + if (i == 1) + { + off = int2(-r, 0); + } + else + { + if (i == 2) + { + off = int2(0, r); + } + else + { + off = int2(0, -r); + } + } + } + int2 _131 = _17 + off; + int _133 = _131.x; + bool _134 = _133 < 0; + bool _141; + if (!_134) + { + _141 = _131.y < 0; + } + else + { + _141 = _134; + } + bool _150; + if (!_141) + { + _150 = _133 >= _31.x; + } + else + { + _150 = _141; + } + bool _159; + if (!_150) + { + _159 = _131.y >= _31.y; + } + else + { + _159 = _150; + } + if (_159) + { + continue; + } + float4 _169 = tex_mask.Load(int3(_131, 0)); + float _170 = _169.x; + if (_170 <= 0.25f) + { + continue; + } + if (_170 >= 0.75f) + { + if (r <= _75) + { + sawSelectInSelectR = true; + } + } + else + { + if (r <= _68) + { + sawHoverInHoverR = true; + } + if (r <= _75) + { + sawHoverInSelectR = true; + } + } + } + } + if (sawSelectInSelectR) + { + out_color = _58_select_color; + return; + } + if (sawHoverInHoverR) + { + out_color = _58_hover_color; + return; + } + if (sawHoverInSelectR) + { + out_color = _58_hover_color; + return; + } + out_color = 0.0f.xxxx; + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_FragCoord = stage_input.gl_FragCoord; + gl_FragCoord.w = 1.0 / gl_FragCoord.w; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.out_color = out_color; + return stage_output; + } +*/ +static const uint8_t highlight_outline_fs_source_hlsl5[3690] = { + 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x35,0x38,0x5f, + 0x68,0x6f,0x76,0x65,0x72,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x70,0x61, + 0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x35,0x38,0x5f,0x73,0x65,0x6c, + 0x65,0x63,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b, + 0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x35,0x38,0x5f,0x74,0x68,0x69,0x63,0x6b, + 0x6e,0x65,0x73,0x73,0x5f,0x70,0x78,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66, + 0x66,0x73,0x65,0x74,0x28,0x63,0x32,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x54,0x65, + 0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20, + 0x74,0x65,0x78,0x5f,0x6d,0x61,0x73,0x6b,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73, + 0x74,0x65,0x72,0x28,0x74,0x30,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72, + 0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x6d,0x61,0x73,0x6b,0x20,0x3a, + 0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x30,0x29,0x3b,0x0a,0x0a, + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c, + 0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x3b,0x0a,0x73,0x74,0x61,0x74, + 0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49, + 0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x46, + 0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x20,0x3a,0x20,0x53,0x56,0x5f,0x50,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75, + 0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f, + 0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x53, + 0x56,0x5f,0x54,0x61,0x72,0x67,0x65,0x74,0x30,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x75, + 0x69,0x6e,0x74,0x32,0x20,0x73,0x70,0x76,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x53, + 0x69,0x7a,0x65,0x28,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x3e,0x20,0x54,0x65,0x78,0x2c,0x20,0x75,0x69,0x6e,0x74,0x20, + 0x4c,0x65,0x76,0x65,0x6c,0x2c,0x20,0x6f,0x75,0x74,0x20,0x75,0x69,0x6e,0x74,0x20, + 0x50,0x61,0x72,0x61,0x6d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e, + 0x74,0x32,0x20,0x72,0x65,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x54,0x65,0x78,0x2e, + 0x47,0x65,0x74,0x44,0x69,0x6d,0x65,0x6e,0x73,0x69,0x6f,0x6e,0x73,0x28,0x4c,0x65, + 0x76,0x65,0x6c,0x2c,0x20,0x72,0x65,0x74,0x2e,0x78,0x2c,0x20,0x72,0x65,0x74,0x2e, + 0x79,0x2c,0x20,0x50,0x61,0x72,0x61,0x6d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x72,0x65,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f, + 0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x5f,0x31,0x37,0x20,0x3d,0x20, + 0x69,0x6e,0x74,0x32,0x28,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72, + 0x64,0x2e,0x78,0x79,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20, + 0x5f,0x33,0x31,0x5f,0x64,0x75,0x6d,0x6d,0x79,0x5f,0x70,0x61,0x72,0x61,0x6d,0x65, + 0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x5f,0x33, + 0x31,0x20,0x3d,0x20,0x69,0x6e,0x74,0x32,0x28,0x73,0x70,0x76,0x54,0x65,0x78,0x74, + 0x75,0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x74,0x65,0x78,0x5f,0x6d,0x61,0x73,0x6b, + 0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x30,0x29,0x2c,0x20,0x5f,0x33,0x31,0x5f,0x64, + 0x75,0x6d,0x6d,0x79,0x5f,0x70,0x61,0x72,0x61,0x6d,0x65,0x74,0x65,0x72,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x74,0x65,0x78,0x5f,0x6d,0x61, + 0x73,0x6b,0x2e,0x4c,0x6f,0x61,0x64,0x28,0x69,0x6e,0x74,0x33,0x28,0x5f,0x31,0x37, + 0x2c,0x20,0x30,0x29,0x29,0x2e,0x78,0x20,0x3e,0x20,0x30,0x2e,0x32,0x35,0x66,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f, + 0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x30,0x2e,0x30,0x66,0x2e, + 0x78,0x78,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x6e,0x74,0x20,0x5f,0x36,0x38,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28, + 0x69,0x6e,0x74,0x28,0x5f,0x35,0x38,0x5f,0x74,0x68,0x69,0x63,0x6b,0x6e,0x65,0x73, + 0x73,0x5f,0x70,0x78,0x2e,0x78,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x29,0x2c,0x20, + 0x31,0x2c,0x20,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f, + 0x37,0x35,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x69,0x6e,0x74,0x28,0x5f, + 0x35,0x38,0x5f,0x74,0x68,0x69,0x63,0x6b,0x6e,0x65,0x73,0x73,0x5f,0x70,0x78,0x2e, + 0x79,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x29,0x2c,0x20,0x31,0x2c,0x20,0x34,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x37,0x39,0x20,0x3d,0x20, + 0x6d,0x61,0x78,0x28,0x5f,0x36,0x38,0x2c,0x20,0x5f,0x37,0x35,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x73,0x61,0x77,0x53,0x65,0x6c,0x65,0x63, + 0x74,0x49,0x6e,0x53,0x65,0x6c,0x65,0x63,0x74,0x52,0x20,0x3d,0x20,0x66,0x61,0x6c, + 0x73,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x73,0x61,0x77, + 0x48,0x6f,0x76,0x65,0x72,0x49,0x6e,0x48,0x6f,0x76,0x65,0x72,0x52,0x20,0x3d,0x20, + 0x66,0x61,0x6c,0x73,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20, + 0x73,0x61,0x77,0x48,0x6f,0x76,0x65,0x72,0x49,0x6e,0x53,0x65,0x6c,0x65,0x63,0x74, + 0x52,0x20,0x3d,0x20,0x66,0x61,0x6c,0x73,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x6e,0x74,0x32,0x20,0x6f,0x66,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6f,0x72, + 0x20,0x28,0x69,0x6e,0x74,0x20,0x72,0x20,0x3d,0x20,0x31,0x3b,0x20,0x72,0x20,0x3c, + 0x3d,0x20,0x5f,0x37,0x39,0x3b,0x20,0x72,0x2b,0x2b,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x20,0x28,0x69, + 0x6e,0x74,0x20,0x69,0x20,0x3d,0x20,0x30,0x3b,0x20,0x69,0x20,0x3c,0x20,0x34,0x3b, + 0x20,0x69,0x2b,0x2b,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x69,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x66,0x66,0x20,0x3d,0x20,0x69,0x6e,0x74,0x32, + 0x28,0x72,0x2c,0x20,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x20,0x3d,0x3d,0x20,0x31,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x66,0x66,0x20,0x3d,0x20,0x69,0x6e,0x74, + 0x32,0x28,0x2d,0x72,0x2c,0x20,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x20,0x3d,0x3d,0x20, + 0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x6f,0x66,0x66,0x20,0x3d,0x20,0x69,0x6e,0x74,0x32,0x28,0x30,0x2c,0x20,0x72, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, + 0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x6f,0x66,0x66,0x20,0x3d,0x20,0x69,0x6e,0x74,0x32,0x28,0x30,0x2c,0x20,0x2d,0x72, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x5f,0x31,0x33,0x31,0x20,0x3d, + 0x20,0x5f,0x31,0x37,0x20,0x2b,0x20,0x6f,0x66,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x31,0x33,0x33, + 0x20,0x3d,0x20,0x5f,0x31,0x33,0x31,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x33,0x34, + 0x20,0x3d,0x20,0x5f,0x31,0x33,0x33,0x20,0x3c,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31, + 0x34,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x33,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x34,0x31,0x20,0x3d,0x20, + 0x5f,0x31,0x33,0x31,0x2e,0x79,0x20,0x3c,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x34,0x31,0x20,0x3d,0x20, + 0x5f,0x31,0x33,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x35,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x34,0x31, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x5f,0x31,0x35,0x30,0x20,0x3d,0x20,0x5f,0x31,0x33,0x33,0x20,0x3e,0x3d,0x20,0x5f, + 0x33,0x31,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x5f,0x31,0x35,0x30,0x20,0x3d,0x20,0x5f,0x31,0x34,0x31,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f, + 0x31,0x35,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x35,0x30,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x35,0x39,0x20,0x3d, + 0x20,0x5f,0x31,0x33,0x31,0x2e,0x79,0x20,0x3e,0x3d,0x20,0x5f,0x33,0x31,0x2e,0x79, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f, + 0x31,0x35,0x39,0x20,0x3d,0x20,0x5f,0x31,0x35,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x35,0x39,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x6f, + 0x6e,0x74,0x69,0x6e,0x75,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x36,0x39,0x20,0x3d,0x20, + 0x74,0x65,0x78,0x5f,0x6d,0x61,0x73,0x6b,0x2e,0x4c,0x6f,0x61,0x64,0x28,0x69,0x6e, + 0x74,0x33,0x28,0x5f,0x31,0x33,0x31,0x2c,0x20,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x37,0x30,0x20,0x3d,0x20,0x5f,0x31,0x36,0x39,0x2e,0x78,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, + 0x31,0x37,0x30,0x20,0x3c,0x3d,0x20,0x30,0x2e,0x32,0x35,0x66,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x6f,0x6e,0x74, + 0x69,0x6e,0x75,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x5f,0x31,0x37,0x30,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x37,0x35, + 0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x72,0x20,0x3c,0x3d,0x20,0x5f,0x37,0x35,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x73,0x61,0x77,0x53,0x65,0x6c,0x65,0x63,0x74,0x49,0x6e, + 0x53,0x65,0x6c,0x65,0x63,0x74,0x52,0x20,0x3d,0x20,0x74,0x72,0x75,0x65,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x72,0x20,0x3c,0x3d,0x20,0x5f,0x36,0x38,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x73,0x61,0x77,0x48,0x6f,0x76,0x65,0x72,0x49,0x6e,0x48,0x6f,0x76, + 0x65,0x72,0x52,0x20,0x3d,0x20,0x74,0x72,0x75,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x72,0x20,0x3c,0x3d,0x20,0x5f,0x37,0x35,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x73,0x61,0x77,0x48,0x6f,0x76,0x65,0x72,0x49,0x6e,0x53,0x65,0x6c,0x65, + 0x63,0x74,0x52,0x20,0x3d,0x20,0x74,0x72,0x75,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x73,0x61,0x77,0x53,0x65,0x6c,0x65,0x63,0x74,0x49,0x6e,0x53, + 0x65,0x6c,0x65,0x63,0x74,0x52,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20, + 0x3d,0x20,0x5f,0x35,0x38,0x5f,0x73,0x65,0x6c,0x65,0x63,0x74,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x73,0x61,0x77,0x48,0x6f,0x76,0x65,0x72,0x49,0x6e,0x48,0x6f,0x76,0x65, + 0x72,0x52,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x5f,0x35, + 0x38,0x5f,0x68,0x6f,0x76,0x65,0x72,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x73,0x61,0x77, + 0x48,0x6f,0x76,0x65,0x72,0x49,0x6e,0x53,0x65,0x6c,0x65,0x63,0x74,0x52,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75, + 0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x5f,0x35,0x38,0x5f,0x68,0x6f, + 0x76,0x65,0x72,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, + 0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x78,0x3b,0x0a,0x7d,0x0a,0x0a,0x53, + 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75, + 0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, + 0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69, + 0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46, + 0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65, + 0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f, + 0x6f,0x72,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67, + 0x43,0x6f,0x6f,0x72,0x64,0x2e,0x77,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2f,0x20, + 0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x77,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73, + 0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75, + 0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f, + 0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x3d,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f, + 0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + struct main0_out + { + float4 gl_Position [[position]]; + }; + + vertex main0_out main0(uint gl_VertexIndex [[vertex_id]]) + { + main0_out out = {}; + out.gl_Position = float4((int(gl_VertexIndex) == 1) ? 3.0 : (-1.0), (int(gl_VertexIndex) == 2) ? 3.0 : (-1.0), 0.0, 1.0); + return out; + } + +*/ +static const uint8_t highlight_outline_vs_source_metal_macos[362] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d, + 0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f, + 0x6e,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x3b,0x0a, + 0x7d,0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,0x65,0x78,0x20,0x6d,0x61,0x69,0x6e,0x30, + 0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x75,0x69,0x6e,0x74,0x20, + 0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x5b, + 0x5b,0x76,0x65,0x72,0x74,0x65,0x78,0x5f,0x69,0x64,0x5d,0x5d,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75, + 0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e, + 0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x28,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72, + 0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x3d,0x3d,0x20,0x31,0x29,0x20, + 0x3f,0x20,0x33,0x2e,0x30,0x20,0x3a,0x20,0x28,0x2d,0x31,0x2e,0x30,0x29,0x2c,0x20, + 0x28,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e, + 0x64,0x65,0x78,0x29,0x20,0x3d,0x3d,0x20,0x32,0x29,0x20,0x3f,0x20,0x33,0x2e,0x30, + 0x20,0x3a,0x20,0x28,0x2d,0x31,0x2e,0x30,0x29,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20, + 0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + struct ub_pass + { + float4 hover_color; + float4 select_color; + float4 thickness_px; + }; + + struct main0_out + { + float4 out_color [[color(0)]]; + }; + + fragment main0_out main0(constant ub_pass& _58 [[buffer(0)]], texture2d tex_mask [[texture(0)]], sampler smp_mask [[sampler(0)]], float4 gl_FragCoord [[position]]) + { + main0_out out = {}; + int2 _17 = int2(gl_FragCoord.xy); + int2 _31 = int2(tex_mask.get_width(), tex_mask.get_height()); + if (tex_mask.read(uint2(_17), 0).x > 0.25) + { + out.out_color = float4(0.0); + return out; + } + int _68 = clamp(int(_58.thickness_px.x + 0.5), 1, 4); + int _75 = clamp(int(_58.thickness_px.y + 0.5), 1, 4); + int _79 = max(_68, _75); + bool sawSelectInSelectR = false; + bool sawHoverInHoverR = false; + bool sawHoverInSelectR = false; + int2 off; + for (int r = 1; r <= _79; r++) + { + for (int i = 0; i < 4; i++) + { + if (i == 0) + { + off = int2(r, 0); + } + else + { + if (i == 1) + { + off = int2(-r, 0); + } + else + { + if (i == 2) + { + off = int2(0, r); + } + else + { + off = int2(0, -r); + } + } + } + int2 _131 = _17 + off; + int _133 = _131.x; + bool _134 = _133 < 0; + bool _141; + if (!_134) + { + _141 = _131.y < 0; + } + else + { + _141 = _134; + } + bool _150; + if (!_141) + { + _150 = _133 >= _31.x; + } + else + { + _150 = _141; + } + bool _159; + if (!_150) + { + _159 = _131.y >= _31.y; + } + else + { + _159 = _150; + } + if (_159) + { + continue; + } + float4 _169 = tex_mask.read(uint2(_131), 0); + float _170 = _169.x; + if (_170 <= 0.25) + { + continue; + } + if (_170 >= 0.75) + { + if (r <= _75) + { + sawSelectInSelectR = true; + } + } + else + { + if (r <= _68) + { + sawHoverInHoverR = true; + } + if (r <= _75) + { + sawHoverInSelectR = true; + } + } + } + } + if (sawSelectInSelectR) + { + out.out_color = _58.select_color; + return out; + } + if (sawHoverInHoverR) + { + out.out_color = _58.hover_color; + return out; + } + if (sawHoverInSelectR) + { + out.out_color = _58.hover_color; + return out; + } + out.out_color = float4(0.0); + return out; + } + +*/ +static const uint8_t highlight_outline_fs_source_metal_macos[3233] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75, + 0x62,0x5f,0x70,0x61,0x73,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x68,0x6f,0x76,0x65,0x72,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x65,0x6c,0x65, + 0x63,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x74,0x68,0x69,0x63,0x6b,0x6e,0x65,0x73,0x73,0x5f,0x70, + 0x78,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61, + 0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b, + 0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a, + 0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f, + 0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x63,0x6f,0x6e,0x73,0x74,0x61, + 0x6e,0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x35,0x38,0x20, + 0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x74, + 0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20, + 0x74,0x65,0x78,0x5f,0x6d,0x61,0x73,0x6b,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75, + 0x72,0x65,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72, + 0x20,0x73,0x6d,0x70,0x5f,0x6d,0x61,0x73,0x6b,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x20,0x5b,0x5b, + 0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20, + 0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x5f, + 0x31,0x37,0x20,0x3d,0x20,0x69,0x6e,0x74,0x32,0x28,0x67,0x6c,0x5f,0x46,0x72,0x61, + 0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x6e,0x74,0x32,0x20,0x5f,0x33,0x31,0x20,0x3d,0x20,0x69,0x6e,0x74,0x32,0x28, + 0x74,0x65,0x78,0x5f,0x6d,0x61,0x73,0x6b,0x2e,0x67,0x65,0x74,0x5f,0x77,0x69,0x64, + 0x74,0x68,0x28,0x29,0x2c,0x20,0x74,0x65,0x78,0x5f,0x6d,0x61,0x73,0x6b,0x2e,0x67, + 0x65,0x74,0x5f,0x68,0x65,0x69,0x67,0x68,0x74,0x28,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x74,0x65,0x78,0x5f,0x6d,0x61,0x73,0x6b,0x2e,0x72, + 0x65,0x61,0x64,0x28,0x75,0x69,0x6e,0x74,0x32,0x28,0x5f,0x31,0x37,0x29,0x2c,0x20, + 0x30,0x29,0x2e,0x78,0x20,0x3e,0x20,0x30,0x2e,0x32,0x35,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f, + 0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x28,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x36,0x38,0x20,0x3d,0x20, + 0x63,0x6c,0x61,0x6d,0x70,0x28,0x69,0x6e,0x74,0x28,0x5f,0x35,0x38,0x2e,0x74,0x68, + 0x69,0x63,0x6b,0x6e,0x65,0x73,0x73,0x5f,0x70,0x78,0x2e,0x78,0x20,0x2b,0x20,0x30, + 0x2e,0x35,0x29,0x2c,0x20,0x31,0x2c,0x20,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x6e,0x74,0x20,0x5f,0x37,0x35,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28, + 0x69,0x6e,0x74,0x28,0x5f,0x35,0x38,0x2e,0x74,0x68,0x69,0x63,0x6b,0x6e,0x65,0x73, + 0x73,0x5f,0x70,0x78,0x2e,0x79,0x20,0x2b,0x20,0x30,0x2e,0x35,0x29,0x2c,0x20,0x31, + 0x2c,0x20,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x37, + 0x39,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x5f,0x36,0x38,0x2c,0x20,0x5f,0x37,0x35, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x73,0x61,0x77,0x53, + 0x65,0x6c,0x65,0x63,0x74,0x49,0x6e,0x53,0x65,0x6c,0x65,0x63,0x74,0x52,0x20,0x3d, + 0x20,0x66,0x61,0x6c,0x73,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c, + 0x20,0x73,0x61,0x77,0x48,0x6f,0x76,0x65,0x72,0x49,0x6e,0x48,0x6f,0x76,0x65,0x72, + 0x52,0x20,0x3d,0x20,0x66,0x61,0x6c,0x73,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62, + 0x6f,0x6f,0x6c,0x20,0x73,0x61,0x77,0x48,0x6f,0x76,0x65,0x72,0x49,0x6e,0x53,0x65, + 0x6c,0x65,0x63,0x74,0x52,0x20,0x3d,0x20,0x66,0x61,0x6c,0x73,0x65,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x6f,0x66,0x66,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6f,0x72,0x20,0x28,0x69,0x6e,0x74,0x20,0x72,0x20,0x3d,0x20,0x31,0x3b, + 0x20,0x72,0x20,0x3c,0x3d,0x20,0x5f,0x37,0x39,0x3b,0x20,0x72,0x2b,0x2b,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6f, + 0x72,0x20,0x28,0x69,0x6e,0x74,0x20,0x69,0x20,0x3d,0x20,0x30,0x3b,0x20,0x69,0x20, + 0x3c,0x20,0x34,0x3b,0x20,0x69,0x2b,0x2b,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x69,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x66,0x66,0x20,0x3d,0x20, + 0x69,0x6e,0x74,0x32,0x28,0x72,0x2c,0x20,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x20,0x3d, + 0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x66,0x66,0x20,0x3d, + 0x20,0x69,0x6e,0x74,0x32,0x28,0x2d,0x72,0x2c,0x20,0x30,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x69, + 0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x6f,0x66,0x66,0x20,0x3d,0x20,0x69,0x6e,0x74,0x32,0x28, + 0x30,0x2c,0x20,0x72,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x6f,0x66,0x66,0x20,0x3d,0x20,0x69,0x6e,0x74,0x32,0x28,0x30, + 0x2c,0x20,0x2d,0x72,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x32,0x20,0x5f,0x31, + 0x33,0x31,0x20,0x3d,0x20,0x5f,0x31,0x37,0x20,0x2b,0x20,0x6f,0x66,0x66,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20, + 0x5f,0x31,0x33,0x33,0x20,0x3d,0x20,0x5f,0x31,0x33,0x31,0x2e,0x78,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20, + 0x5f,0x31,0x33,0x34,0x20,0x3d,0x20,0x5f,0x31,0x33,0x33,0x20,0x3c,0x20,0x30,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f, + 0x6c,0x20,0x5f,0x31,0x34,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x33,0x34,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x34, + 0x31,0x20,0x3d,0x20,0x5f,0x31,0x33,0x31,0x2e,0x79,0x20,0x3c,0x20,0x30,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x34, + 0x31,0x20,0x3d,0x20,0x5f,0x31,0x33,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x35,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21, + 0x5f,0x31,0x34,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x5f,0x31,0x35,0x30,0x20,0x3d,0x20,0x5f,0x31,0x33,0x33,0x20, + 0x3e,0x3d,0x20,0x5f,0x33,0x31,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x35,0x30,0x20,0x3d,0x20,0x5f,0x31, + 0x34,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f, + 0x6f,0x6c,0x20,0x5f,0x31,0x35,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x35,0x30,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31, + 0x35,0x39,0x20,0x3d,0x20,0x5f,0x31,0x33,0x31,0x2e,0x79,0x20,0x3e,0x3d,0x20,0x5f, + 0x33,0x31,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x5f,0x31,0x35,0x39,0x20,0x3d,0x20,0x5f,0x31,0x35,0x30,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31, + 0x35,0x39,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x63,0x6f,0x6e,0x74,0x69,0x6e,0x75,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x36, + 0x39,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x6d,0x61,0x73,0x6b,0x2e,0x72,0x65,0x61, + 0x64,0x28,0x75,0x69,0x6e,0x74,0x32,0x28,0x5f,0x31,0x33,0x31,0x29,0x2c,0x20,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x37,0x30,0x20,0x3d,0x20,0x5f,0x31,0x36,0x39, + 0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x5f,0x31,0x37,0x30,0x20,0x3c,0x3d,0x20,0x30,0x2e,0x32,0x35, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x63,0x6f,0x6e,0x74,0x69,0x6e,0x75,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x37,0x30,0x20,0x3e,0x3d,0x20, + 0x30,0x2e,0x37,0x35,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x72,0x20,0x3c,0x3d,0x20,0x5f,0x37,0x35, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x61,0x77,0x53,0x65,0x6c,0x65,0x63, + 0x74,0x49,0x6e,0x53,0x65,0x6c,0x65,0x63,0x74,0x52,0x20,0x3d,0x20,0x74,0x72,0x75, + 0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65, + 0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x72,0x20,0x3c,0x3d,0x20,0x5f,0x36,0x38,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x61,0x77,0x48,0x6f,0x76,0x65,0x72,0x49,0x6e, + 0x48,0x6f,0x76,0x65,0x72,0x52,0x20,0x3d,0x20,0x74,0x72,0x75,0x65,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x72,0x20,0x3c,0x3d,0x20,0x5f,0x37,0x35,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x73,0x61,0x77,0x48,0x6f,0x76,0x65,0x72,0x49,0x6e,0x53, + 0x65,0x6c,0x65,0x63,0x74,0x52,0x20,0x3d,0x20,0x74,0x72,0x75,0x65,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x73,0x61,0x77,0x53,0x65,0x6c,0x65,0x63,0x74, + 0x49,0x6e,0x53,0x65,0x6c,0x65,0x63,0x74,0x52,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x5f,0x35,0x38,0x2e,0x73,0x65,0x6c, + 0x65,0x63,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x73,0x61,0x77, + 0x48,0x6f,0x76,0x65,0x72,0x49,0x6e,0x48,0x6f,0x76,0x65,0x72,0x52,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, + 0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x5f,0x35,0x38, + 0x2e,0x68,0x6f,0x76,0x65,0x72,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x73,0x61,0x77,0x48,0x6f,0x76,0x65,0x72,0x49,0x6e,0x53,0x65,0x6c,0x65,0x63,0x74, + 0x52,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, + 0x20,0x5f,0x35,0x38,0x2e,0x68,0x6f,0x76,0x65,0x72,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x6f,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a, + 0x00, +}; +static inline const sg_shader_desc* highlight_outline_prog_shader_desc(sg_backend backend) { + if (backend == SG_BACKEND_GLCORE) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)highlight_outline_vs_source_glsl430; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)highlight_outline_fs_source_glsl430; + desc.fragment_func.entry = "main"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 48; + desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[0].glsl_uniforms[0].array_count = 3; + desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_pass"; + desc.views[0].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[0].texture.image_type = SG_IMAGETYPE_2D; + desc.views[0].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[0].texture.multisampled = false; + desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[0].view_slot = 0; + desc.texture_sampler_pairs[0].sampler_slot = 0; + desc.texture_sampler_pairs[0].glsl_name = "tex_mask_smp_mask"; + desc.label = "highlight_outline_prog_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_D3D11) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)highlight_outline_vs_source_hlsl5; + desc.vertex_func.d3d11_target = "vs_5_0"; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)highlight_outline_fs_source_hlsl5; + desc.fragment_func.d3d11_target = "ps_5_0"; + desc.fragment_func.entry = "main"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 48; + desc.uniform_blocks[0].hlsl_register_b_n = 0; + desc.views[0].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[0].texture.image_type = SG_IMAGETYPE_2D; + desc.views[0].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[0].texture.multisampled = false; + desc.views[0].texture.hlsl_register_t_n = 0; + desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[0].hlsl_register_s_n = 0; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[0].view_slot = 0; + desc.texture_sampler_pairs[0].sampler_slot = 0; + desc.label = "highlight_outline_prog_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_METAL_MACOS) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)highlight_outline_vs_source_metal_macos; + desc.vertex_func.entry = "main0"; + desc.fragment_func.source = (const char*)highlight_outline_fs_source_metal_macos; + desc.fragment_func.entry = "main0"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 48; + desc.uniform_blocks[0].msl_buffer_n = 0; + desc.views[0].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[0].texture.image_type = SG_IMAGETYPE_2D; + desc.views[0].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[0].texture.multisampled = false; + desc.views[0].texture.msl_texture_n = 0; + desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[0].msl_sampler_n = 0; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[0].view_slot = 0; + desc.texture_sampler_pairs[0].sampler_slot = 0; + desc.label = "highlight_outline_prog_shader"; + } + return &desc; + } + return 0; +} diff --git a/samples/shaders/generated/mask_capsule.glsl.h b/samples/shaders/generated/mask_capsule.glsl.h new file mode 100644 index 0000000..e53a253 --- /dev/null +++ b/samples/shaders/generated/mask_capsule.glsl.h @@ -0,0 +1,1613 @@ +#pragma once +/* + #version:1# (machine generated, don't edit!) + + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) + + Cmdline: + sokol-shdc --input E:/box/box3d/samples/shaders/post/mask_capsule.glsl --output E:/box/box3d/samples/shaders/generated/mask_capsule.glsl.h --slang hlsl5:metal_macos:glsl430 + + Overview: + ========= + Shader program: 'prog': + Get shader desc: mask_capsule_prog_shader_desc(sg_query_backend()); + Vertex Shader: vs + Fragment Shader: fs + Attributes: + ATTR_mask_capsule_prog_in_pos => 0 + Bindings: + Uniform block 'ub_frame': + C struct: mask_capsule_ub_frame_t + Bind slot: UB_mask_capsule_ub_frame => 0 + Uniform block 'ub_pass': + C struct: mask_capsule_ub_pass_t + Bind slot: UB_mask_capsule_ub_pass => 1 + Storage buffer 'instances': + C struct: mask_capsule_instance_t + Bind slot: VIEW_mask_capsule_instances => 0 + Readonly: true +*/ +#if !defined(SOKOL_GFX_INCLUDED) +#error "Please include sokol_gfx.h before mask_capsule.glsl.h" +#endif +#if !defined(SOKOL_SHDC_ALIGN) +#if defined(_MSC_VER) +#define SOKOL_SHDC_ALIGN(a) __declspec(align(a)) +#else +#define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) +#endif +#endif +#define ATTR_mask_capsule_prog_in_pos (0) +#define UB_mask_capsule_ub_frame (0) +#define UB_mask_capsule_ub_pass (1) +#define VIEW_mask_capsule_instances (0) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct mask_capsule_ub_frame_t { + Mat4 view_proj; +} mask_capsule_ub_frame_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct mask_capsule_ub_pass_t { + Mat4 view_proj; + Vec4 camera_pos; +} mask_capsule_ub_pass_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct mask_capsule_instance_t { + Vec4 xform_row0; + Vec4 xform_row1; + Vec4 xform_row2; + Vec4 params; +} mask_capsule_instance_t; +#pragma pack(pop) +/* + #version 430 + + struct instance + { + vec4 xform_row0; + vec4 xform_row1; + vec4 xform_row2; + vec4 params; + }; + + layout(binding = 0, std430) readonly buffer instances + { + instance items[]; + } _15; + + uniform vec4 ub_frame[4]; + layout(location = 0) in vec3 in_pos; + layout(location = 0) sample out vec3 v_world_pos_proxy; + layout(location = 1) flat out vec3 v_center; + layout(location = 2) flat out float v_half_length; + layout(location = 3) flat out float v_radius; + layout(location = 4) flat out vec3 v_axis_x_world; + layout(location = 5) flat out float v_kind; + + void main() + { + vec3 _48 = vec3(_15.items[gl_InstanceID].xform_row0.w, _15.items[gl_InstanceID].xform_row1.w, _15.items[gl_InstanceID].xform_row2.w); + vec3 _80 = vec3((in_pos.x * 2.0) * (_15.items[gl_InstanceID].params.x + _15.items[gl_InstanceID].params.y), (in_pos.y * 2.0) * _15.items[gl_InstanceID].params.y, (in_pos.z * 2.0) * _15.items[gl_InstanceID].params.y); + vec3 _99 = _48 + vec3(dot(_15.items[gl_InstanceID].xform_row0.xyz, _80), dot(_15.items[gl_InstanceID].xform_row1.xyz, _80), dot(_15.items[gl_InstanceID].xform_row2.xyz, _80)); + v_world_pos_proxy = _99; + v_center = _48; + v_half_length = _15.items[gl_InstanceID].params.x; + v_radius = _15.items[gl_InstanceID].params.y; + v_axis_x_world = vec3(_15.items[gl_InstanceID].xform_row0.x, _15.items[gl_InstanceID].xform_row1.x, _15.items[gl_InstanceID].xform_row2.x); + v_kind = _15.items[gl_InstanceID].params.z; + gl_Position = mat4(ub_frame[0], ub_frame[1], ub_frame[2], ub_frame[3]) * vec4(_99, 1.0); + } + +*/ +static const uint8_t mask_capsule_vs_source_glsl430[1555] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72, + 0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a, + 0x7d,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69, + 0x6e,0x67,0x20,0x3d,0x20,0x30,0x2c,0x20,0x73,0x74,0x64,0x34,0x33,0x30,0x29,0x20, + 0x72,0x65,0x61,0x64,0x6f,0x6e,0x6c,0x79,0x20,0x62,0x75,0x66,0x66,0x65,0x72,0x20, + 0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5d, + 0x3b,0x0a,0x7d,0x20,0x5f,0x31,0x35,0x3b,0x0a,0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72, + 0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b, + 0x34,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74, + 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33, + 0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28, + 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x73,0x61, + 0x6d,0x70,0x6c,0x65,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b, + 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x31,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x76, + 0x65,0x63,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x32,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x3b, + 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x33,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x6c, + 0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d, + 0x20,0x34,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63, + 0x33,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f, + 0x6e,0x20,0x3d,0x20,0x35,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x6f,0x75,0x74,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x6b,0x69,0x6e,0x64,0x3b,0x0a,0x0a,0x76, + 0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x34,0x38,0x20,0x3d,0x20,0x76,0x65,0x63,0x33, + 0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e, + 0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f, + 0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d, + 0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d, + 0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f, + 0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f, + 0x77,0x32,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, + 0x5f,0x38,0x30,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x28,0x69,0x6e,0x5f,0x70, + 0x6f,0x73,0x2e,0x78,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x20,0x2a,0x20,0x28,0x5f, + 0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78, + 0x20,0x2b,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x67,0x6c,0x5f, + 0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x70,0x61,0x72,0x61, + 0x6d,0x73,0x2e,0x79,0x29,0x2c,0x20,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x2e,0x79, + 0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74, + 0x65,0x6d,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49, + 0x44,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x2c,0x20,0x28,0x69,0x6e, + 0x5f,0x70,0x6f,0x73,0x2e,0x7a,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x20,0x2a,0x20, + 0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73, + 0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e, + 0x79,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x39,0x39, + 0x20,0x3d,0x20,0x5f,0x34,0x38,0x20,0x2b,0x20,0x76,0x65,0x63,0x33,0x28,0x64,0x6f, + 0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x67,0x6c,0x5f,0x49, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d, + 0x5f,0x72,0x6f,0x77,0x30,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x38,0x30,0x29,0x2c, + 0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x67, + 0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x38, + 0x30,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d, + 0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d, + 0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x78,0x79,0x7a,0x2c, + 0x20,0x5f,0x38,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3d,0x20, + 0x5f,0x39,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65, + 0x72,0x20,0x3d,0x20,0x5f,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x68, + 0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x20,0x3d,0x20,0x5f,0x31,0x35, + 0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x49,0x44,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x5f, + 0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x31,0x35,0x2e, + 0x69,0x74,0x65,0x6d,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x49,0x44,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e, + 0x78,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x67,0x6c,0x5f, + 0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74, + 0x65,0x6d,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49, + 0x44,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x78,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x6b,0x69,0x6e,0x64,0x20,0x3d,0x20,0x5f, + 0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x7a, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f, + 0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d, + 0x65,0x5b,0x30,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x31, + 0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x32,0x5d,0x2c,0x20, + 0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x76, + 0x65,0x63,0x34,0x28,0x5f,0x39,0x39,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x00, +}; +/* + #version 430 + + uniform vec4 ub_pass[5]; + layout(location = 0) sample in vec3 v_world_pos_proxy; + layout(location = 4) flat in vec3 v_axis_x_world; + layout(location = 1) flat in vec3 v_center; + layout(location = 2) flat in float v_half_length; + layout(location = 3) flat in float v_radius; + layout(location = 0) out vec4 out_kind; + layout(location = 5) flat in float v_kind; + + void main() + { + vec3 _27 = normalize(v_world_pos_proxy - ub_pass[4].xyz); + vec3 _38 = v_axis_x_world * v_half_length; + vec3 _39 = v_center - _38; + vec3 _45 = v_center + _38; + vec3 _49 = _45 - _39; + vec3 _53 = ub_pass[4].xyz - _39; + float _58 = dot(_49, _49); + float _62 = dot(_49, _27); + float _66 = dot(_49, _53); + float _74 = dot(_53, _53); + float _80 = _58 - (_62 * _62); + float _88 = (_58 * dot(_27, _53)) - (_66 * _62); + float _100 = v_radius * v_radius; + float _111 = (_88 * _88) - (_80 * (((_58 * _74) - (_66 * _66)) - (_100 * _58))); + float t = -1.0; + if ((_111 >= 0.0) && (_80 > 9.9999999392252902907785028219223e-09)) + { + float _131 = ((-_88) - sqrt(_111)) / _80; + float _137 = _66 + (_131 * _62); + if (((_131 > 0.0) && (_137 > 0.0)) && (_137 < _58)) + { + t = _131; + } + } + float _157 = dot(_53, _27); + float _171 = (_157 * _157) - (_74 - _100); + if (_171 >= 0.0) + { + float _181 = (-_157) - sqrt(_171); + bool _183 = _181 > 0.0; + bool _192; + if (_183) + { + _192 = (t < 0.0) || (_181 < t); + } + else + { + _192 = _183; + } + if (_192) + { + if (dot((ub_pass[4].xyz + (_27 * _181)) - _39, v_axis_x_world) <= 0.0) + { + t = _181; + } + } + } + vec3 _213 = ub_pass[4].xyz - _45; + float _217 = dot(_213, _27); + float _231 = (_217 * _217) - (dot(_213, _213) - _100); + if (_231 >= 0.0) + { + float _241 = (-_217) - sqrt(_231); + bool _243 = _241 > 0.0; + bool _252; + if (_243) + { + _252 = (t < 0.0) || (_241 < t); + } + else + { + _252 = _243; + } + if (_252) + { + if (dot((ub_pass[4].xyz + (_27 * _241)) - _45, v_axis_x_world) >= 0.0) + { + t = _241; + } + } + } + if (t < 0.0) + { + discard; + } + vec4 _293 = mat4(ub_pass[0], ub_pass[1], ub_pass[2], ub_pass[3]) * vec4(ub_pass[4].xyz + (_27 * t), 1.0); + gl_FragDepth = _293.z / _293.w; + out_kind = vec4(v_kind * 0.5, 0.0, 0.0, 1.0); + } + +*/ +static const uint8_t mask_capsule_fs_source_glsl430[2586] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x75,0x6e, + 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x70,0x61, + 0x73,0x73,0x5b,0x35,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f, + 0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x34,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20, + 0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a, + 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20, + 0x3d,0x20,0x31,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63, + 0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f, + 0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29, + 0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76, + 0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x33,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75, + 0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20, + 0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x6f,0x75,0x74,0x5f,0x6b,0x69,0x6e, + 0x64,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69, + 0x6f,0x6e,0x20,0x3d,0x20,0x35,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x6b,0x69,0x6e,0x64,0x3b,0x0a,0x0a,0x76, + 0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x32,0x37,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d, + 0x61,0x6c,0x69,0x7a,0x65,0x28,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f, + 0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x75,0x62,0x5f,0x70,0x61,0x73, + 0x73,0x5b,0x34,0x5d,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x33,0x20,0x5f,0x33,0x38,0x20,0x3d,0x20,0x76,0x5f,0x61,0x78,0x69,0x73, + 0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x2a,0x20,0x76,0x5f,0x68,0x61,0x6c, + 0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x33,0x20,0x5f,0x33,0x39,0x20,0x3d,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65, + 0x72,0x20,0x2d,0x20,0x5f,0x33,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x33,0x20,0x5f,0x34,0x35,0x20,0x3d,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72, + 0x20,0x2b,0x20,0x5f,0x33,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, + 0x20,0x5f,0x34,0x39,0x20,0x3d,0x20,0x5f,0x34,0x35,0x20,0x2d,0x20,0x5f,0x33,0x39, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x35,0x33,0x20,0x3d, + 0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x34,0x5d,0x2e,0x78,0x79,0x7a,0x20, + 0x2d,0x20,0x5f,0x33,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x35,0x38,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x34,0x39,0x2c,0x20, + 0x5f,0x34,0x39,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x36,0x32,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x34,0x39,0x2c,0x20,0x5f, + 0x32,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x36,0x36,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x34,0x39,0x2c,0x20,0x5f,0x35, + 0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37, + 0x34,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x35,0x33,0x2c,0x20,0x5f,0x35,0x33, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x30, + 0x20,0x3d,0x20,0x5f,0x35,0x38,0x20,0x2d,0x20,0x28,0x5f,0x36,0x32,0x20,0x2a,0x20, + 0x5f,0x36,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x38,0x38,0x20,0x3d,0x20,0x28,0x5f,0x35,0x38,0x20,0x2a,0x20,0x64,0x6f,0x74, + 0x28,0x5f,0x32,0x37,0x2c,0x20,0x5f,0x35,0x33,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f, + 0x36,0x36,0x20,0x2a,0x20,0x5f,0x36,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x30,0x20,0x3d,0x20,0x76,0x5f,0x72,0x61, + 0x64,0x69,0x75,0x73,0x20,0x2a,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x31,0x20, + 0x3d,0x20,0x28,0x5f,0x38,0x38,0x20,0x2a,0x20,0x5f,0x38,0x38,0x29,0x20,0x2d,0x20, + 0x28,0x5f,0x38,0x30,0x20,0x2a,0x20,0x28,0x28,0x28,0x5f,0x35,0x38,0x20,0x2a,0x20, + 0x5f,0x37,0x34,0x29,0x20,0x2d,0x20,0x28,0x5f,0x36,0x36,0x20,0x2a,0x20,0x5f,0x36, + 0x36,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f,0x31,0x30,0x30,0x20,0x2a,0x20,0x5f,0x35, + 0x38,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x74,0x20,0x3d,0x20,0x2d,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x28,0x5f,0x31,0x31,0x31,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x20, + 0x26,0x26,0x20,0x28,0x5f,0x38,0x30,0x20,0x3e,0x20,0x39,0x2e,0x39,0x39,0x39,0x39, + 0x39,0x39,0x39,0x33,0x39,0x32,0x32,0x35,0x32,0x39,0x30,0x32,0x39,0x30,0x37,0x37, + 0x38,0x35,0x30,0x32,0x38,0x32,0x31,0x39,0x32,0x32,0x33,0x65,0x2d,0x30,0x39,0x29, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x31,0x20,0x3d,0x20,0x28,0x28,0x2d, + 0x5f,0x38,0x38,0x29,0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x31,0x31,0x31, + 0x29,0x29,0x20,0x2f,0x20,0x5f,0x38,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x37,0x20,0x3d,0x20,0x5f, + 0x36,0x36,0x20,0x2b,0x20,0x28,0x5f,0x31,0x33,0x31,0x20,0x2a,0x20,0x5f,0x36,0x32, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28, + 0x28,0x5f,0x31,0x33,0x31,0x20,0x3e,0x20,0x30,0x2e,0x30,0x29,0x20,0x26,0x26,0x20, + 0x28,0x5f,0x31,0x33,0x37,0x20,0x3e,0x20,0x30,0x2e,0x30,0x29,0x29,0x20,0x26,0x26, + 0x20,0x28,0x5f,0x31,0x33,0x37,0x20,0x3c,0x20,0x5f,0x35,0x38,0x29,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20,0x5f,0x31,0x33,0x31,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x37,0x20,0x3d,0x20, + 0x64,0x6f,0x74,0x28,0x5f,0x35,0x33,0x2c,0x20,0x5f,0x32,0x37,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x37,0x31,0x20,0x3d,0x20, + 0x28,0x5f,0x31,0x35,0x37,0x20,0x2a,0x20,0x5f,0x31,0x35,0x37,0x29,0x20,0x2d,0x20, + 0x28,0x5f,0x37,0x34,0x20,0x2d,0x20,0x5f,0x31,0x30,0x30,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x37,0x31,0x20,0x3e,0x3d,0x20,0x30,0x2e, + 0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x38,0x31,0x20,0x3d,0x20,0x28,0x2d, + 0x5f,0x31,0x35,0x37,0x29,0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x31,0x37, + 0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c, + 0x20,0x5f,0x31,0x38,0x33,0x20,0x3d,0x20,0x5f,0x31,0x38,0x31,0x20,0x3e,0x20,0x30, + 0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c, + 0x20,0x5f,0x31,0x39,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x5f,0x31,0x38,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f, + 0x31,0x39,0x32,0x20,0x3d,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x20, + 0x7c,0x7c,0x20,0x28,0x5f,0x31,0x38,0x31,0x20,0x3c,0x20,0x74,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x39,0x32, + 0x20,0x3d,0x20,0x5f,0x31,0x38,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, + 0x31,0x39,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x64, + 0x6f,0x74,0x28,0x28,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x34,0x5d,0x2e,0x78, + 0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x32,0x37,0x20,0x2a,0x20,0x5f,0x31,0x38,0x31, + 0x29,0x29,0x20,0x2d,0x20,0x5f,0x33,0x39,0x2c,0x20,0x76,0x5f,0x61,0x78,0x69,0x73, + 0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x20,0x3c,0x3d,0x20,0x30,0x2e,0x30, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x74,0x20,0x3d,0x20,0x5f,0x31,0x38,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, + 0x20,0x5f,0x32,0x31,0x33,0x20,0x3d,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b, + 0x34,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x34,0x35,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x37,0x20,0x3d,0x20,0x64, + 0x6f,0x74,0x28,0x5f,0x32,0x31,0x33,0x2c,0x20,0x5f,0x32,0x37,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x33,0x31,0x20,0x3d,0x20, + 0x28,0x5f,0x32,0x31,0x37,0x20,0x2a,0x20,0x5f,0x32,0x31,0x37,0x29,0x20,0x2d,0x20, + 0x28,0x64,0x6f,0x74,0x28,0x5f,0x32,0x31,0x33,0x2c,0x20,0x5f,0x32,0x31,0x33,0x29, + 0x20,0x2d,0x20,0x5f,0x31,0x30,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x5f,0x32,0x33,0x31,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x32,0x34,0x31,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x32,0x31,0x37, + 0x29,0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x32,0x33,0x31,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x32,0x34, + 0x33,0x20,0x3d,0x20,0x5f,0x32,0x34,0x31,0x20,0x3e,0x20,0x30,0x2e,0x30,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x32,0x35, + 0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, + 0x32,0x34,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x32,0x35,0x32,0x20, + 0x3d,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x20,0x7c,0x7c,0x20,0x28, + 0x5f,0x32,0x34,0x31,0x20,0x3c,0x20,0x74,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, + 0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x32,0x35,0x32,0x20,0x3d,0x20,0x5f, + 0x32,0x34,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x32,0x35,0x32,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x64,0x6f,0x74,0x28,0x28, + 0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x34,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2b, + 0x20,0x28,0x5f,0x32,0x37,0x20,0x2a,0x20,0x5f,0x32,0x34,0x31,0x29,0x29,0x20,0x2d, + 0x20,0x5f,0x34,0x35,0x2c,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x29,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20, + 0x5f,0x32,0x34,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x74,0x20,0x3c,0x20, + 0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x32,0x39,0x33,0x20, + 0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x30, + 0x5d,0x2c,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x31,0x5d,0x2c,0x20,0x75, + 0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x32,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x70,0x61, + 0x73,0x73,0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x75,0x62, + 0x5f,0x70,0x61,0x73,0x73,0x5b,0x34,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28, + 0x5f,0x32,0x37,0x20,0x2a,0x20,0x74,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68, + 0x20,0x3d,0x20,0x5f,0x32,0x39,0x33,0x2e,0x7a,0x20,0x2f,0x20,0x5f,0x32,0x39,0x33, + 0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x6b,0x69,0x6e,0x64, + 0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x5f,0x6b,0x69,0x6e,0x64,0x20,0x2a, + 0x20,0x30,0x2e,0x35,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20, + 0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + struct instance + { + float4 xform_row0; + float4 xform_row1; + float4 xform_row2; + float4 params; + }; + + ByteAddressBuffer _15 : register(t0); + cbuffer ub_frame : register(b0) + { + row_major float4x4 _128_view_proj : packoffset(c0); + }; + + + static float4 gl_Position; + static int gl_InstanceIndex; + static float3 in_pos; + static float3 v_world_pos_proxy; + static float3 v_center; + static float v_half_length; + static float v_radius; + static float3 v_axis_x_world; + static float v_kind; + + struct SPIRV_Cross_Input + { + float3 in_pos : TEXCOORD0; + uint gl_InstanceIndex : SV_InstanceID; + }; + + struct SPIRV_Cross_Output + { + sample float3 v_world_pos_proxy : TEXCOORD0; + nointerpolation float3 v_center : TEXCOORD1; + nointerpolation float v_half_length : TEXCOORD2; + nointerpolation float v_radius : TEXCOORD3; + nointerpolation float3 v_axis_x_world : TEXCOORD4; + nointerpolation float v_kind : TEXCOORD5; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + instance _23; + _23.xform_row0 = asfloat(_15.Load4(gl_InstanceIndex * 64 + 0)); + _23.xform_row1 = asfloat(_15.Load4(gl_InstanceIndex * 64 + 16)); + _23.xform_row2 = asfloat(_15.Load4(gl_InstanceIndex * 64 + 32)); + _23.params = asfloat(_15.Load4(gl_InstanceIndex * 64 + 48)); + float3 _48 = float3(_23.xform_row0.w, _23.xform_row1.w, _23.xform_row2.w); + float3 _80 = float3((in_pos.x * 2.0f) * (_23.params.x + _23.params.y), (in_pos.y * 2.0f) * _23.params.y, (in_pos.z * 2.0f) * _23.params.y); + float3 _99 = _48 + float3(dot(_23.xform_row0.xyz, _80), dot(_23.xform_row1.xyz, _80), dot(_23.xform_row2.xyz, _80)); + v_world_pos_proxy = _99; + v_center = _48; + v_half_length = _23.params.x; + v_radius = _23.params.y; + v_axis_x_world = float3(_23.xform_row0.x, _23.xform_row1.x, _23.xform_row2.x); + v_kind = _23.params.z; + gl_Position = mul(float4(_99, 1.0f), _128_view_proj); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_InstanceIndex = int(stage_input.gl_InstanceIndex); + in_pos = stage_input.in_pos; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.v_world_pos_proxy = v_world_pos_proxy; + stage_output.v_center = v_center; + stage_output.v_half_length = v_half_length; + stage_output.v_radius = v_radius; + stage_output.v_axis_x_world = v_axis_x_world; + stage_output.v_kind = v_kind; + return stage_output; + } +*/ +static const uint8_t mask_capsule_vs_source_hlsl5[2429] = { + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d, + 0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x42,0x79, + 0x74,0x65,0x41,0x64,0x64,0x72,0x65,0x73,0x73,0x42,0x75,0x66,0x66,0x65,0x72,0x20, + 0x5f,0x31,0x35,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74, + 0x30,0x29,0x3b,0x0a,0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x66, + 0x72,0x61,0x6d,0x65,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28, + 0x62,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61, + 0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x31,0x32, + 0x38,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61, + 0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x73,0x74, + 0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69, + 0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b, + 0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79, + 0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65, + 0x6e,0x67,0x74,0x68,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x73,0x74,0x61, + 0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x61,0x78,0x69, + 0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69, + 0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x6b,0x69,0x6e,0x64,0x3b,0x0a, + 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, + 0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20, + 0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75, + 0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49, + 0x6e,0x64,0x65,0x78,0x20,0x3a,0x20,0x53,0x56,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x49,0x44,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74, + 0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74, + 0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3a,0x20,0x54,0x45,0x58,0x43, + 0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74, + 0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3a,0x20,0x54,0x45,0x58, + 0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e, + 0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x20, + 0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x32,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20, + 0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x33,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52, + 0x44,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70, + 0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f, + 0x6b,0x69,0x6e,0x64,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x35, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f, + 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,0x53,0x56,0x5f,0x50,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64, + 0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20,0x5f,0x32,0x33,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x5f,0x32,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72, + 0x6f,0x77,0x30,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31, + 0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61, + 0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x2a,0x20,0x36,0x34,0x20,0x2b,0x20, + 0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x32,0x33,0x2e,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61, + 0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x67,0x6c,0x5f,0x49, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x2a,0x20,0x36, + 0x34,0x20,0x2b,0x20,0x31,0x36,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x32, + 0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x20,0x3d,0x20,0x61, + 0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34, + 0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65, + 0x78,0x20,0x2a,0x20,0x36,0x34,0x20,0x2b,0x20,0x33,0x32,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x5f,0x32,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x20,0x3d,0x20, + 0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64, + 0x34,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64, + 0x65,0x78,0x20,0x2a,0x20,0x36,0x34,0x20,0x2b,0x20,0x34,0x38,0x29,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x34,0x38,0x20,0x3d, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x32,0x33,0x2e,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f,0x32,0x33,0x2e,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f,0x32,0x33,0x2e, + 0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x77,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x38,0x30,0x20,0x3d,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x2e,0x78, + 0x20,0x2a,0x20,0x32,0x2e,0x30,0x66,0x29,0x20,0x2a,0x20,0x28,0x5f,0x32,0x33,0x2e, + 0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x20,0x2b,0x20,0x5f,0x32,0x33,0x2e,0x70, + 0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x29,0x2c,0x20,0x28,0x69,0x6e,0x5f,0x70,0x6f, + 0x73,0x2e,0x79,0x20,0x2a,0x20,0x32,0x2e,0x30,0x66,0x29,0x20,0x2a,0x20,0x5f,0x32, + 0x33,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x2c,0x20,0x28,0x69,0x6e,0x5f, + 0x70,0x6f,0x73,0x2e,0x7a,0x20,0x2a,0x20,0x32,0x2e,0x30,0x66,0x29,0x20,0x2a,0x20, + 0x5f,0x32,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x39,0x39,0x20,0x3d,0x20, + 0x5f,0x34,0x38,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x64,0x6f,0x74, + 0x28,0x5f,0x32,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e, + 0x78,0x79,0x7a,0x2c,0x20,0x5f,0x38,0x30,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f, + 0x32,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x79, + 0x7a,0x2c,0x20,0x5f,0x38,0x30,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x32,0x33, + 0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x78,0x79,0x7a,0x2c, + 0x20,0x5f,0x38,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3d,0x20, + 0x5f,0x39,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65, + 0x72,0x20,0x3d,0x20,0x5f,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x68, + 0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x20,0x3d,0x20,0x5f,0x32,0x33, + 0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x5f,0x32,0x33,0x2e,0x70,0x61, + 0x72,0x61,0x6d,0x73,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x61,0x78, + 0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x28,0x5f,0x32,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f, + 0x77,0x30,0x2e,0x78,0x2c,0x20,0x5f,0x32,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f, + 0x72,0x6f,0x77,0x31,0x2e,0x78,0x2c,0x20,0x5f,0x32,0x33,0x2e,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x5f,0x6b,0x69,0x6e,0x64,0x20,0x3d,0x20,0x5f,0x32,0x33,0x2e,0x70,0x61,0x72,0x61, + 0x6d,0x73,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73, + 0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x28,0x5f,0x39,0x39,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f, + 0x31,0x32,0x38,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x29,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f, + 0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56, + 0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78, + 0x20,0x3d,0x20,0x69,0x6e,0x74,0x28,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70, + 0x75,0x74,0x2e,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e, + 0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73, + 0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x69, + 0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x72,0x74,0x5f, + 0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52, + 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73, + 0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c, + 0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x50, + 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x76,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75, + 0x74,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3d,0x20,0x76,0x5f,0x63, + 0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65, + 0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c, + 0x65,0x6e,0x67,0x74,0x68,0x20,0x3d,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c, + 0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65, + 0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73, + 0x20,0x3d,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f, + 0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x76, + 0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e, + 0x76,0x5f,0x6b,0x69,0x6e,0x64,0x20,0x3d,0x20,0x76,0x5f,0x6b,0x69,0x6e,0x64,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67, + 0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + cbuffer ub_pass : register(b1) + { + row_major float4x4 _14_view_proj : packoffset(c0); + float4 _14_camera_pos : packoffset(c4); + }; + + + static float gl_FragDepth; + static float3 v_world_pos_proxy; + static float3 v_axis_x_world; + static float3 v_center; + static float v_half_length; + static float v_radius; + static float4 out_kind; + static float v_kind; + + struct SPIRV_Cross_Input + { + sample float3 v_world_pos_proxy : TEXCOORD0; + nointerpolation float3 v_center : TEXCOORD1; + nointerpolation float v_half_length : TEXCOORD2; + nointerpolation float v_radius : TEXCOORD3; + nointerpolation float3 v_axis_x_world : TEXCOORD4; + nointerpolation float v_kind : TEXCOORD5; + }; + + struct SPIRV_Cross_Output + { + float4 out_kind : SV_Target0; + float gl_FragDepth : SV_Depth; + }; + + void frag_main() + { + float3 _27 = normalize(v_world_pos_proxy - _14_camera_pos.xyz); + float3 _38 = v_axis_x_world * v_half_length; + float3 _39 = v_center - _38; + float3 _45 = v_center + _38; + float3 _49 = _45 - _39; + float3 _53 = _14_camera_pos.xyz - _39; + float _58 = dot(_49, _49); + float _62 = dot(_49, _27); + float _66 = dot(_49, _53); + float _74 = dot(_53, _53); + float _80 = _58 - (_62 * _62); + float _88 = (_58 * dot(_27, _53)) - (_66 * _62); + float _100 = v_radius * v_radius; + float _111 = (_88 * _88) - (_80 * (((_58 * _74) - (_66 * _66)) - (_100 * _58))); + float t = -1.0f; + if ((_111 >= 0.0f) && (_80 > 9.9999999392252902907785028219223e-09f)) + { + float _131 = ((-_88) - sqrt(_111)) / _80; + float _137 = _66 + (_131 * _62); + if (((_131 > 0.0f) && (_137 > 0.0f)) && (_137 < _58)) + { + t = _131; + } + } + float _157 = dot(_53, _27); + float _171 = (_157 * _157) - (_74 - _100); + if (_171 >= 0.0f) + { + float _181 = (-_157) - sqrt(_171); + bool _183 = _181 > 0.0f; + bool _192; + if (_183) + { + _192 = (t < 0.0f) || (_181 < t); + } + else + { + _192 = _183; + } + if (_192) + { + if (dot((_14_camera_pos.xyz + (_27 * _181)) - _39, v_axis_x_world) <= 0.0f) + { + t = _181; + } + } + } + float3 _213 = _14_camera_pos.xyz - _45; + float _217 = dot(_213, _27); + float _231 = (_217 * _217) - (dot(_213, _213) - _100); + if (_231 >= 0.0f) + { + float _241 = (-_217) - sqrt(_231); + bool _243 = _241 > 0.0f; + bool _252; + if (_243) + { + _252 = (t < 0.0f) || (_241 < t); + } + else + { + _252 = _243; + } + if (_252) + { + if (dot((_14_camera_pos.xyz + (_27 * _241)) - _45, v_axis_x_world) >= 0.0f) + { + t = _241; + } + } + } + if (t < 0.0f) + { + discard; + } + float4 _293 = mul(float4(_14_camera_pos.xyz + (_27 * t), 1.0f), _14_view_proj); + gl_FragDepth = _293.z / _293.w; + out_kind = float4(v_kind * 0.5f, 0.0f, 0.0f, 1.0f); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + v_world_pos_proxy = stage_input.v_world_pos_proxy; + v_axis_x_world = stage_input.v_axis_x_world; + v_center = stage_input.v_center; + v_half_length = stage_input.v_half_length; + v_radius = stage_input.v_radius; + v_kind = stage_input.v_kind; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_FragDepth = gl_FragDepth; + stage_output.out_kind = out_kind; + return stage_output; + } +*/ +static const uint8_t mask_capsule_fs_source_hlsl5[3512] = { + 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x31,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x31,0x34,0x5f,0x76,0x69,0x65,0x77, + 0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73, + 0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x5f,0x31,0x34,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f, + 0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63, + 0x34,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70, + 0x74,0x68,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72, + 0x6f,0x78,0x79,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69, + 0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c, + 0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x73,0x74, + 0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f, + 0x6b,0x69,0x6e,0x64,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x76,0x5f,0x6b,0x69,0x6e,0x64,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75, + 0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49, + 0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3a,0x20,0x54,0x45,0x58, + 0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e, + 0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3a,0x20,0x54,0x45, + 0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69, + 0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68, + 0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x32,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f, + 0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73, + 0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x33,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f, + 0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f, + 0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f, + 0x52,0x44,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72, + 0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76, + 0x5f,0x6b,0x69,0x6e,0x64,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44, + 0x35,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50, + 0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75, + 0x74,0x5f,0x6b,0x69,0x6e,0x64,0x20,0x3a,0x20,0x53,0x56,0x5f,0x54,0x61,0x72,0x67, + 0x65,0x74,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67, + 0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3a,0x20,0x53,0x56, + 0x5f,0x44,0x65,0x70,0x74,0x68,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64, + 0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x32,0x37,0x20,0x3d,0x20, + 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x76,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x5f,0x31, + 0x34,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x33, + 0x38,0x20,0x3d,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x20,0x2a,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67, + 0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f, + 0x33,0x39,0x20,0x3d,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x2d,0x20, + 0x5f,0x33,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x5f,0x34,0x35,0x20,0x3d,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x2b, + 0x20,0x5f,0x33,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x5f,0x34,0x39,0x20,0x3d,0x20,0x5f,0x34,0x35,0x20,0x2d,0x20,0x5f,0x33,0x39, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x35,0x33, + 0x20,0x3d,0x20,0x5f,0x31,0x34,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f, + 0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x33,0x39,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x38,0x20,0x3d,0x20,0x64,0x6f,0x74, + 0x28,0x5f,0x34,0x39,0x2c,0x20,0x5f,0x34,0x39,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x32,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28, + 0x5f,0x34,0x39,0x2c,0x20,0x5f,0x32,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x36,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f, + 0x34,0x39,0x2c,0x20,0x5f,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x37,0x34,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x35, + 0x33,0x2c,0x20,0x5f,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x38,0x30,0x20,0x3d,0x20,0x5f,0x35,0x38,0x20,0x2d,0x20,0x28, + 0x5f,0x36,0x32,0x20,0x2a,0x20,0x5f,0x36,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x38,0x20,0x3d,0x20,0x28,0x5f,0x35,0x38, + 0x20,0x2a,0x20,0x64,0x6f,0x74,0x28,0x5f,0x32,0x37,0x2c,0x20,0x5f,0x35,0x33,0x29, + 0x29,0x20,0x2d,0x20,0x28,0x5f,0x36,0x36,0x20,0x2a,0x20,0x5f,0x36,0x32,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x30,0x20, + 0x3d,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x2a,0x20,0x76,0x5f,0x72, + 0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x31,0x31,0x20,0x3d,0x20,0x28,0x5f,0x38,0x38,0x20,0x2a,0x20,0x5f, + 0x38,0x38,0x29,0x20,0x2d,0x20,0x28,0x5f,0x38,0x30,0x20,0x2a,0x20,0x28,0x28,0x28, + 0x5f,0x35,0x38,0x20,0x2a,0x20,0x5f,0x37,0x34,0x29,0x20,0x2d,0x20,0x28,0x5f,0x36, + 0x36,0x20,0x2a,0x20,0x5f,0x36,0x36,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f,0x31,0x30, + 0x30,0x20,0x2a,0x20,0x5f,0x35,0x38,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x74,0x20,0x3d,0x20,0x2d,0x31,0x2e,0x30,0x66,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x5f,0x31,0x31,0x31,0x20,0x3e, + 0x3d,0x20,0x30,0x2e,0x30,0x66,0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x38,0x30,0x20, + 0x3e,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x33,0x39,0x32,0x32,0x35, + 0x32,0x39,0x30,0x32,0x39,0x30,0x37,0x37,0x38,0x35,0x30,0x32,0x38,0x32,0x31,0x39, + 0x32,0x32,0x33,0x65,0x2d,0x30,0x39,0x66,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x33,0x31,0x20,0x3d,0x20,0x28,0x28,0x2d,0x5f,0x38,0x38,0x29,0x20,0x2d,0x20, + 0x73,0x71,0x72,0x74,0x28,0x5f,0x31,0x31,0x31,0x29,0x29,0x20,0x2f,0x20,0x5f,0x38, + 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x33,0x37,0x20,0x3d,0x20,0x5f,0x36,0x36,0x20,0x2b,0x20,0x28,0x5f, + 0x31,0x33,0x31,0x20,0x2a,0x20,0x5f,0x36,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x28,0x5f,0x31,0x33,0x31,0x20,0x3e, + 0x20,0x30,0x2e,0x30,0x66,0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x31,0x33,0x37,0x20, + 0x3e,0x20,0x30,0x2e,0x30,0x66,0x29,0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x31,0x33, + 0x37,0x20,0x3c,0x20,0x5f,0x35,0x38,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x74,0x20,0x3d,0x20,0x5f,0x31,0x33,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x37,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f, + 0x35,0x33,0x2c,0x20,0x5f,0x32,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x31,0x37,0x31,0x20,0x3d,0x20,0x28,0x5f,0x31,0x35,0x37, + 0x20,0x2a,0x20,0x5f,0x31,0x35,0x37,0x29,0x20,0x2d,0x20,0x28,0x5f,0x37,0x34,0x20, + 0x2d,0x20,0x5f,0x31,0x30,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x5f,0x31,0x37,0x31,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x66,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x38,0x31,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x31,0x35,0x37, + 0x29,0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x31,0x37,0x31,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x38, + 0x33,0x20,0x3d,0x20,0x5f,0x31,0x38,0x31,0x20,0x3e,0x20,0x30,0x2e,0x30,0x66,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31, + 0x39,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x5f,0x31,0x38,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x39,0x32, + 0x20,0x3d,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x29,0x20,0x7c,0x7c, + 0x20,0x28,0x5f,0x31,0x38,0x31,0x20,0x3c,0x20,0x74,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65, + 0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x39,0x32,0x20,0x3d, + 0x20,0x5f,0x31,0x38,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x39, + 0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x64,0x6f,0x74, + 0x28,0x28,0x5f,0x31,0x34,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73, + 0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x32,0x37,0x20,0x2a,0x20,0x5f,0x31, + 0x38,0x31,0x29,0x29,0x20,0x2d,0x20,0x5f,0x33,0x39,0x2c,0x20,0x76,0x5f,0x61,0x78, + 0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x20,0x3c,0x3d,0x20,0x30, + 0x2e,0x30,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x74,0x20,0x3d,0x20,0x5f,0x31,0x38,0x31,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x32,0x31,0x33,0x20,0x3d,0x20,0x5f,0x31,0x34, + 0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20, + 0x2d,0x20,0x5f,0x34,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x32,0x31,0x37,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x32,0x31,0x33, + 0x2c,0x20,0x5f,0x32,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x32,0x33,0x31,0x20,0x3d,0x20,0x28,0x5f,0x32,0x31,0x37,0x20,0x2a, + 0x20,0x5f,0x32,0x31,0x37,0x29,0x20,0x2d,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x32, + 0x31,0x33,0x2c,0x20,0x5f,0x32,0x31,0x33,0x29,0x20,0x2d,0x20,0x5f,0x31,0x30,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x32,0x33,0x31,0x20, + 0x3e,0x3d,0x20,0x30,0x2e,0x30,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x34, + 0x31,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x32,0x31,0x37,0x29,0x20,0x2d,0x20,0x73,0x71, + 0x72,0x74,0x28,0x5f,0x32,0x33,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x32,0x34,0x33,0x20,0x3d,0x20,0x5f,0x32, + 0x34,0x31,0x20,0x3e,0x20,0x30,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x32,0x35,0x32,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x32,0x34,0x33,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x32,0x35,0x32,0x20,0x3d,0x20,0x28,0x74,0x20, + 0x3c,0x20,0x30,0x2e,0x30,0x66,0x29,0x20,0x7c,0x7c,0x20,0x28,0x5f,0x32,0x34,0x31, + 0x20,0x3c,0x20,0x74,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x5f,0x32,0x35,0x32,0x20,0x3d,0x20,0x5f,0x32,0x34,0x33,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x32,0x35,0x32,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x64,0x6f,0x74,0x28,0x28,0x5f,0x31,0x34,0x5f, + 0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b, + 0x20,0x28,0x5f,0x32,0x37,0x20,0x2a,0x20,0x5f,0x32,0x34,0x31,0x29,0x29,0x20,0x2d, + 0x20,0x5f,0x34,0x35,0x2c,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x29,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x66,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d, + 0x20,0x5f,0x32,0x34,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x74,0x20,0x3c, + 0x20,0x30,0x2e,0x30,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f, + 0x32,0x39,0x33,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x28,0x5f,0x31,0x34,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e, + 0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x32,0x37,0x20,0x2a,0x20,0x74,0x29,0x2c, + 0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f,0x31,0x34,0x5f,0x76,0x69,0x65,0x77, + 0x5f,0x70,0x72,0x6f,0x6a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46, + 0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x5f,0x32,0x39,0x33,0x2e, + 0x7a,0x20,0x2f,0x20,0x5f,0x32,0x39,0x33,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x6f,0x75,0x74,0x5f,0x6b,0x69,0x6e,0x64,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x28,0x76,0x5f,0x6b,0x69,0x6e,0x64,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x2c, + 0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30, + 0x66,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, + 0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53, + 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74, + 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f, + 0x70,0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e, + 0x70,0x75,0x74,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f, + 0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x61,0x78,0x69, + 0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x73,0x74,0x61,0x67, + 0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x63,0x65, + 0x6e,0x74,0x65,0x72,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70, + 0x75,0x74,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x20,0x3d, + 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x68, + 0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65, + 0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x6b,0x69,0x6e,0x64,0x20,0x3d,0x20,0x73,0x74, + 0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x6b,0x69,0x6e,0x64, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, + 0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f, + 0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67, + 0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67, + 0x44,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44, + 0x65,0x70,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f, + 0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x6b,0x69,0x6e,0x64,0x20, + 0x3d,0x20,0x6f,0x75,0x74,0x5f,0x6b,0x69,0x6e,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74, + 0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + struct instance + { + float4 xform_row0; + float4 xform_row1; + float4 xform_row2; + float4 params; + }; + + struct instances + { + instance items[1]; + }; + + struct ub_frame + { + float4x4 view_proj; + }; + + struct main0_out + { + float3 v_world_pos_proxy [[user(locn0)]]; + float3 v_center [[user(locn1)]]; + float v_half_length [[user(locn2)]]; + float v_radius [[user(locn3)]]; + float3 v_axis_x_world [[user(locn4)]]; + float v_kind [[user(locn5)]]; + float4 gl_Position [[position]]; + }; + + struct main0_in + { + float3 in_pos [[attribute(0)]]; + }; + + vertex main0_out main0(main0_in in [[stage_in]], constant ub_frame& _128 [[buffer(0)]], const device instances& _15 [[buffer(8)]], uint gl_InstanceIndex [[instance_id]]) + { + main0_out out = {}; + float3 _48 = float3(_15.items[int(gl_InstanceIndex)].xform_row0.w, _15.items[int(gl_InstanceIndex)].xform_row1.w, _15.items[int(gl_InstanceIndex)].xform_row2.w); + float3 _80 = float3((in.in_pos.x * 2.0) * (_15.items[int(gl_InstanceIndex)].params.x + _15.items[int(gl_InstanceIndex)].params.y), (in.in_pos.y * 2.0) * _15.items[int(gl_InstanceIndex)].params.y, (in.in_pos.z * 2.0) * _15.items[int(gl_InstanceIndex)].params.y); + float3 _99 = _48 + float3(dot(_15.items[int(gl_InstanceIndex)].xform_row0.xyz, _80), dot(_15.items[int(gl_InstanceIndex)].xform_row1.xyz, _80), dot(_15.items[int(gl_InstanceIndex)].xform_row2.xyz, _80)); + out.v_world_pos_proxy = _99; + out.v_center = _48; + out.v_half_length = _15.items[int(gl_InstanceIndex)].params.x; + out.v_radius = _15.items[int(gl_InstanceIndex)].params.y; + out.v_axis_x_world = float3(_15.items[int(gl_InstanceIndex)].xform_row0.x, _15.items[int(gl_InstanceIndex)].xform_row1.x, _15.items[int(gl_InstanceIndex)].xform_row2.x); + out.v_kind = _15.items[int(gl_InstanceIndex)].params.z; + out.gl_Position = _128.view_proj * float4(_99, 1.0); + return out; + } + +*/ +static const uint8_t mask_capsule_vs_source_metal_macos[1962] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x73, + 0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73, + 0x74,0x61,0x6e,0x63,0x65,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73, + 0x74,0x61,0x6e,0x63,0x65,0x20,0x69,0x74,0x65,0x6d,0x73,0x5b,0x31,0x5d,0x3b,0x0a, + 0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x66,0x72, + 0x61,0x6d,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x78,0x34,0x20,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f, + 0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78, + 0x79,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f, + 0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f, + 0x63,0x6e,0x31,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x20, + 0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x32,0x29,0x5d,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64, + 0x69,0x75,0x73,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x33, + 0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x5b, + 0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x34,0x29,0x5d,0x5d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x6b,0x69,0x6e,0x64, + 0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x35,0x29,0x5d,0x5d, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f, + 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74, + 0x69,0x6f,0x6e,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63, + 0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x5b, + 0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28,0x30,0x29,0x5d,0x5d,0x3b, + 0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,0x65,0x78,0x20,0x6d,0x61,0x69,0x6e, + 0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e, + 0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f, + 0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75, + 0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x26,0x20,0x5f,0x31,0x32,0x38,0x20,0x5b,0x5b, + 0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x73,0x26,0x20,0x5f,0x31,0x35,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65, + 0x72,0x28,0x38,0x29,0x5d,0x5d,0x2c,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f, + 0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x5b,0x5b, + 0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x5f,0x69,0x64,0x5d,0x5d,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f, + 0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x5f,0x34,0x38,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x69,0x6e,0x74,0x28,0x67, + 0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29, + 0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20, + 0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c, + 0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x5d, + 0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f, + 0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f, + 0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e, + 0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x77,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x38,0x30,0x20,0x3d,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x69,0x6e,0x2e,0x69,0x6e,0x5f,0x70,0x6f, + 0x73,0x2e,0x78,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x20,0x2a,0x20,0x28,0x5f,0x31, + 0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x70, + 0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x20,0x2b,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74, + 0x65,0x6d,0x73,0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61, + 0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d, + 0x73,0x2e,0x79,0x29,0x2c,0x20,0x28,0x69,0x6e,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73, + 0x2e,0x79,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x2e, + 0x69,0x74,0x65,0x6d,0x73,0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73, + 0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x70,0x61,0x72, + 0x61,0x6d,0x73,0x2e,0x79,0x2c,0x20,0x28,0x69,0x6e,0x2e,0x69,0x6e,0x5f,0x70,0x6f, + 0x73,0x2e,0x7a,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35, + 0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e, + 0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x70,0x61, + 0x72,0x61,0x6d,0x73,0x2e,0x79,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x5f,0x39,0x39,0x20,0x3d,0x20,0x5f,0x34,0x38,0x20,0x2b,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69, + 0x74,0x65,0x6d,0x73,0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x38,0x30,0x29, + 0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b, + 0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49, + 0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77, + 0x31,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x38,0x30,0x29,0x2c,0x20,0x64,0x6f,0x74, + 0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x69,0x6e,0x74,0x28,0x67, + 0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29, + 0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x78,0x79,0x7a, + 0x2c,0x20,0x5f,0x38,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, + 0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f, + 0x78,0x79,0x20,0x3d,0x20,0x5f,0x39,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75, + 0x74,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3d,0x20,0x5f,0x34,0x38, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x68,0x61,0x6c,0x66, + 0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74, + 0x65,0x6d,0x73,0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61, + 0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d, + 0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x72, + 0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d, + 0x73,0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e, + 0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x61,0x78,0x69, + 0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x69,0x6e,0x74, + 0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65, + 0x78,0x29,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x78, + 0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x69,0x6e,0x74,0x28, + 0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78, + 0x29,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x2c, + 0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x69,0x6e,0x74,0x28,0x67, + 0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29, + 0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x78,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x6b,0x69,0x6e,0x64,0x20, + 0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x69,0x6e,0x74,0x28, + 0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78, + 0x29,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x5f,0x31,0x32,0x38,0x2e,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f, + 0x6a,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x39,0x39,0x2c,0x20, + 0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + struct ub_pass + { + float4x4 view_proj; + float4 camera_pos; + }; + + struct main0_out + { + float4 out_kind [[color(0)]]; + float gl_FragDepth [[depth(any)]]; + }; + + struct main0_in + { + float3 v_world_pos_proxy [[user(locn0), sample_perspective]]; + float3 v_center [[user(locn1), flat]]; + float v_half_length [[user(locn2), flat]]; + float v_radius [[user(locn3), flat]]; + float3 v_axis_x_world [[user(locn4), flat]]; + float v_kind [[user(locn5), flat]]; + }; + + fragment main0_out main0(main0_in in [[stage_in]], constant ub_pass& _14 [[buffer(1)]]) + { + main0_out out = {}; + float3 _27 = fast::normalize(in.v_world_pos_proxy - _14.camera_pos.xyz); + float3 _38 = in.v_axis_x_world * in.v_half_length; + float3 _39 = in.v_center - _38; + float3 _45 = in.v_center + _38; + float3 _49 = _45 - _39; + float3 _53 = _14.camera_pos.xyz - _39; + float _58 = dot(_49, _49); + float _62 = dot(_49, _27); + float _66 = dot(_49, _53); + float _74 = dot(_53, _53); + float _80 = _58 - (_62 * _62); + float _88 = (_58 * dot(_27, _53)) - (_66 * _62); + float _100 = in.v_radius * in.v_radius; + float _111 = (_88 * _88) - (_80 * (((_58 * _74) - (_66 * _66)) - (_100 * _58))); + float t = -1.0; + if ((_111 >= 0.0) && (_80 > 9.9999999392252902907785028219223e-09)) + { + float _131 = ((-_88) - sqrt(_111)) / _80; + float _137 = _66 + (_131 * _62); + if (((_131 > 0.0) && (_137 > 0.0)) && (_137 < _58)) + { + t = _131; + } + } + float _157 = dot(_53, _27); + float _171 = (_157 * _157) - (_74 - _100); + if (_171 >= 0.0) + { + float _181 = (-_157) - sqrt(_171); + bool _183 = _181 > 0.0; + bool _192; + if (_183) + { + _192 = (t < 0.0) || (_181 < t); + } + else + { + _192 = _183; + } + if (_192) + { + if (dot((_14.camera_pos.xyz + (_27 * _181)) - _39, in.v_axis_x_world) <= 0.0) + { + t = _181; + } + } + } + float3 _213 = _14.camera_pos.xyz - _45; + float _217 = dot(_213, _27); + float _231 = (_217 * _217) - (dot(_213, _213) - _100); + if (_231 >= 0.0) + { + float _241 = (-_217) - sqrt(_231); + bool _243 = _241 > 0.0; + bool _252; + if (_243) + { + _252 = (t < 0.0) || (_241 < t); + } + else + { + _252 = _243; + } + if (_252) + { + if (dot((_14.camera_pos.xyz + (_27 * _241)) - _45, in.v_axis_x_world) >= 0.0) + { + t = _241; + } + } + } + if (t < 0.0) + { + discard_fragment(); + } + float4 _293 = _14.view_proj * float4(_14.camera_pos.xyz + (_27 * t), 1.0); + out.gl_FragDepth = _293.z / _293.w; + out.out_kind = float4(in.v_kind * 0.5, 0.0, 0.0, 1.0); + return out; + } + +*/ +static const uint8_t mask_capsule_fs_source_metal_macos[2940] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75, + 0x62,0x5f,0x70,0x61,0x73,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x78,0x34,0x20,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x61,0x6d,0x65, + 0x72,0x61,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75, + 0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x6b,0x69, + 0x6e,0x64,0x20,0x5b,0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29,0x5d,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,0x46,0x72, + 0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x5b,0x5b,0x64,0x65,0x70,0x74,0x68,0x28, + 0x61,0x6e,0x79,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75, + 0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x5b,0x5b,0x75,0x73,0x65, + 0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, + 0x5f,0x70,0x65,0x72,0x73,0x70,0x65,0x63,0x74,0x69,0x76,0x65,0x5d,0x5d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e, + 0x74,0x65,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31, + 0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67, + 0x74,0x68,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x32,0x29, + 0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x5b,0x5b,0x75, + 0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x33,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74, + 0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76, + 0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x5b,0x5b, + 0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x34,0x29,0x2c,0x20,0x66,0x6c,0x61, + 0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76, + 0x5f,0x6b,0x69,0x6e,0x64,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63, + 0x6e,0x35,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a, + 0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f, + 0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f, + 0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e, + 0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f, + 0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x31,0x34,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66, + 0x65,0x72,0x28,0x31,0x29,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d, + 0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b, + 0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x32, + 0x37,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c, + 0x69,0x7a,0x65,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70, + 0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x5f,0x31,0x34,0x2e,0x63, + 0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x33,0x38,0x20,0x3d, + 0x20,0x69,0x6e,0x2e,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x20,0x2a,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c, + 0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x5f,0x33,0x39,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x63,0x65,0x6e, + 0x74,0x65,0x72,0x20,0x2d,0x20,0x5f,0x33,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x34,0x35,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76, + 0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x2b,0x20,0x5f,0x33,0x38,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x34,0x39,0x20,0x3d,0x20, + 0x5f,0x34,0x35,0x20,0x2d,0x20,0x5f,0x33,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x35,0x33,0x20,0x3d,0x20,0x5f,0x31,0x34,0x2e, + 0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d, + 0x20,0x5f,0x33,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x35,0x38,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x34,0x39,0x2c,0x20,0x5f, + 0x34,0x39,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x36,0x32,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x34,0x39,0x2c,0x20,0x5f,0x32, + 0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36, + 0x36,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x34,0x39,0x2c,0x20,0x5f,0x35,0x33, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x34, + 0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x35,0x33,0x2c,0x20,0x5f,0x35,0x33,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x30,0x20, + 0x3d,0x20,0x5f,0x35,0x38,0x20,0x2d,0x20,0x28,0x5f,0x36,0x32,0x20,0x2a,0x20,0x5f, + 0x36,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x38,0x38,0x20,0x3d,0x20,0x28,0x5f,0x35,0x38,0x20,0x2a,0x20,0x64,0x6f,0x74,0x28, + 0x5f,0x32,0x37,0x2c,0x20,0x5f,0x35,0x33,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f,0x36, + 0x36,0x20,0x2a,0x20,0x5f,0x36,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x30,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f, + 0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x2a,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x61, + 0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x31,0x31,0x20,0x3d,0x20,0x28,0x5f,0x38,0x38,0x20,0x2a,0x20,0x5f,0x38, + 0x38,0x29,0x20,0x2d,0x20,0x28,0x5f,0x38,0x30,0x20,0x2a,0x20,0x28,0x28,0x28,0x5f, + 0x35,0x38,0x20,0x2a,0x20,0x5f,0x37,0x34,0x29,0x20,0x2d,0x20,0x28,0x5f,0x36,0x36, + 0x20,0x2a,0x20,0x5f,0x36,0x36,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f,0x31,0x30,0x30, + 0x20,0x2a,0x20,0x5f,0x35,0x38,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x74,0x20,0x3d,0x20,0x2d,0x31,0x2e,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x5f,0x31,0x31,0x31,0x20,0x3e,0x3d,0x20, + 0x30,0x2e,0x30,0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x38,0x30,0x20,0x3e,0x20,0x39, + 0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x33,0x39,0x32,0x32,0x35,0x32,0x39,0x30, + 0x32,0x39,0x30,0x37,0x37,0x38,0x35,0x30,0x32,0x38,0x32,0x31,0x39,0x32,0x32,0x33, + 0x65,0x2d,0x30,0x39,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x31,0x20, + 0x3d,0x20,0x28,0x28,0x2d,0x5f,0x38,0x38,0x29,0x20,0x2d,0x20,0x73,0x71,0x72,0x74, + 0x28,0x5f,0x31,0x31,0x31,0x29,0x29,0x20,0x2f,0x20,0x5f,0x38,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33, + 0x37,0x20,0x3d,0x20,0x5f,0x36,0x36,0x20,0x2b,0x20,0x28,0x5f,0x31,0x33,0x31,0x20, + 0x2a,0x20,0x5f,0x36,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x28,0x28,0x5f,0x31,0x33,0x31,0x20,0x3e,0x20,0x30,0x2e,0x30, + 0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x31,0x33,0x37,0x20,0x3e,0x20,0x30,0x2e,0x30, + 0x29,0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x31,0x33,0x37,0x20,0x3c,0x20,0x5f,0x35, + 0x38,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20,0x5f,0x31, + 0x33,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x35,0x37,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x35,0x33,0x2c,0x20,0x5f,0x32, + 0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x37,0x31,0x20,0x3d,0x20,0x28,0x5f,0x31,0x35,0x37,0x20,0x2a,0x20,0x5f,0x31,0x35, + 0x37,0x29,0x20,0x2d,0x20,0x28,0x5f,0x37,0x34,0x20,0x2d,0x20,0x5f,0x31,0x30,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x37,0x31,0x20, + 0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x38,0x31, + 0x20,0x3d,0x20,0x28,0x2d,0x5f,0x31,0x35,0x37,0x29,0x20,0x2d,0x20,0x73,0x71,0x72, + 0x74,0x28,0x5f,0x31,0x37,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x38,0x33,0x20,0x3d,0x20,0x5f,0x31,0x38, + 0x31,0x20,0x3e,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x39,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x38,0x33,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x5f,0x31,0x39,0x32,0x20,0x3d,0x20,0x28,0x74,0x20,0x3c,0x20, + 0x30,0x2e,0x30,0x29,0x20,0x7c,0x7c,0x20,0x28,0x5f,0x31,0x38,0x31,0x20,0x3c,0x20, + 0x74,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x5f,0x31,0x39,0x32,0x20,0x3d,0x20,0x5f,0x31,0x38,0x33,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x5f,0x31,0x39,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x64,0x6f,0x74,0x28,0x28,0x5f,0x31,0x34,0x2e,0x63,0x61,0x6d, + 0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f, + 0x32,0x37,0x20,0x2a,0x20,0x5f,0x31,0x38,0x31,0x29,0x29,0x20,0x2d,0x20,0x5f,0x33, + 0x39,0x2c,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x29,0x20,0x3c,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20, + 0x5f,0x31,0x38,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f, + 0x32,0x31,0x33,0x20,0x3d,0x20,0x5f,0x31,0x34,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61, + 0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x34,0x35,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x37,0x20,0x3d, + 0x20,0x64,0x6f,0x74,0x28,0x5f,0x32,0x31,0x33,0x2c,0x20,0x5f,0x32,0x37,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x33,0x31,0x20, + 0x3d,0x20,0x28,0x5f,0x32,0x31,0x37,0x20,0x2a,0x20,0x5f,0x32,0x31,0x37,0x29,0x20, + 0x2d,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x32,0x31,0x33,0x2c,0x20,0x5f,0x32,0x31, + 0x33,0x29,0x20,0x2d,0x20,0x5f,0x31,0x30,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x5f,0x32,0x33,0x31,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x34,0x31,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x32, + 0x31,0x37,0x29,0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x32,0x33,0x31,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f, + 0x32,0x34,0x33,0x20,0x3d,0x20,0x5f,0x32,0x34,0x31,0x20,0x3e,0x20,0x30,0x2e,0x30, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f, + 0x32,0x35,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x5f,0x32,0x34,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x32,0x35, + 0x32,0x20,0x3d,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x20,0x7c,0x7c, + 0x20,0x28,0x5f,0x32,0x34,0x31,0x20,0x3c,0x20,0x74,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65, + 0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x32,0x35,0x32,0x20,0x3d, + 0x20,0x5f,0x32,0x34,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x32,0x35, + 0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x64,0x6f,0x74, + 0x28,0x28,0x5f,0x31,0x34,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73, + 0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x32,0x37,0x20,0x2a,0x20,0x5f,0x32, + 0x34,0x31,0x29,0x29,0x20,0x2d,0x20,0x5f,0x34,0x35,0x2c,0x20,0x69,0x6e,0x2e,0x76, + 0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x20,0x3e, + 0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20,0x5f,0x32,0x34,0x31,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x64,0x69,0x73,0x63, + 0x61,0x72,0x64,0x5f,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x28,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x5f,0x32,0x39,0x33,0x20,0x3d,0x20,0x5f,0x31,0x34,0x2e,0x76,0x69,0x65,0x77, + 0x5f,0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f, + 0x31,0x34,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79, + 0x7a,0x20,0x2b,0x20,0x28,0x5f,0x32,0x37,0x20,0x2a,0x20,0x74,0x29,0x2c,0x20,0x31, + 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f, + 0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x5f,0x32,0x39,0x33, + 0x2e,0x7a,0x20,0x2f,0x20,0x5f,0x32,0x39,0x33,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x6b,0x69,0x6e,0x64,0x20,0x3d,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x6b,0x69,0x6e,0x64, + 0x20,0x2a,0x20,0x30,0x2e,0x35,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30, + 0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +static inline const sg_shader_desc* mask_capsule_prog_shader_desc(sg_backend backend) { + if (backend == SG_BACKEND_GLCORE) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)mask_capsule_vs_source_glsl430; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)mask_capsule_fs_source_glsl430; + desc.fragment_func.entry = "main"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[0].glsl_name = "in_pos"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[0].glsl_uniforms[0].array_count = 4; + desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_frame"; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 80; + desc.uniform_blocks[1].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[0].array_count = 5; + desc.uniform_blocks[1].glsl_uniforms[0].glsl_name = "ub_pass"; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.glsl_binding_n = 0; + desc.label = "mask_capsule_prog_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_D3D11) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)mask_capsule_vs_source_hlsl5; + desc.vertex_func.d3d11_target = "vs_5_0"; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)mask_capsule_fs_source_hlsl5; + desc.fragment_func.d3d11_target = "ps_5_0"; + desc.fragment_func.entry = "main"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[0].hlsl_sem_name = "TEXCOORD"; + desc.attrs[0].hlsl_sem_index = 0; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].hlsl_register_b_n = 0; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 80; + desc.uniform_blocks[1].hlsl_register_b_n = 1; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.hlsl_register_t_n = 0; + desc.label = "mask_capsule_prog_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_METAL_MACOS) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)mask_capsule_vs_source_metal_macos; + desc.vertex_func.entry = "main0"; + desc.fragment_func.source = (const char*)mask_capsule_fs_source_metal_macos; + desc.fragment_func.entry = "main0"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].msl_buffer_n = 0; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 80; + desc.uniform_blocks[1].msl_buffer_n = 1; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.msl_buffer_n = 8; + desc.label = "mask_capsule_prog_shader"; + } + return &desc; + } + return 0; +} diff --git a/samples/shaders/generated/mask_hull.glsl.h b/samples/shaders/generated/mask_hull.glsl.h new file mode 100644 index 0000000..208e590 --- /dev/null +++ b/samples/shaders/generated/mask_hull.glsl.h @@ -0,0 +1,640 @@ +#pragma once +/* + #version:1# (machine generated, don't edit!) + + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) + + Cmdline: + sokol-shdc --input E:/box/box3d/samples/shaders/post/mask_hull.glsl --output E:/box/box3d/samples/shaders/generated/mask_hull.glsl.h --slang hlsl5:metal_macos:glsl430 + + Overview: + ========= + Shader program: 'prog': + Get shader desc: mask_hull_prog_shader_desc(sg_query_backend()); + Vertex Shader: vs + Fragment Shader: fs + Attributes: + ATTR_mask_hull_prog_in_pos => 0 + Bindings: + Uniform block 'ub_draw': + C struct: mask_hull_ub_draw_t + Bind slot: UB_mask_hull_ub_draw => 2 + Uniform block 'ub_frame': + C struct: mask_hull_ub_frame_t + Bind slot: UB_mask_hull_ub_frame => 0 + Storage buffer 'instances': + C struct: mask_hull_instance_t + Bind slot: VIEW_mask_hull_instances => 0 + Readonly: true +*/ +#if !defined(SOKOL_GFX_INCLUDED) +#error "Please include sokol_gfx.h before mask_hull.glsl.h" +#endif +#if !defined(SOKOL_SHDC_ALIGN) +#if defined(_MSC_VER) +#define SOKOL_SHDC_ALIGN(a) __declspec(align(a)) +#else +#define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) +#endif +#endif +#define ATTR_mask_hull_prog_in_pos (0) +#define UB_mask_hull_ub_draw (2) +#define UB_mask_hull_ub_frame (0) +#define VIEW_mask_hull_instances (0) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct mask_hull_ub_draw_t { + int inst_base[4]; +} mask_hull_ub_draw_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct mask_hull_ub_frame_t { + Mat4 view_proj; +} mask_hull_ub_frame_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct mask_hull_instance_t { + Vec4 xform_row0; + Vec4 xform_row1; + Vec4 xform_row2; + Vec4 scale_kind; +} mask_hull_instance_t; +#pragma pack(pop) +/* + #version 430 + + struct instance + { + vec4 xform_row0; + vec4 xform_row1; + vec4 xform_row2; + vec4 scale_kind; + }; + + layout(binding = 0, std430) readonly buffer instances + { + instance items[]; + } _15; + + uniform ivec4 ub_draw[1]; + uniform vec4 ub_frame[4]; + layout(location = 0) in vec3 in_pos; + layout(location = 0) flat out float v_kind; + + void main() + { + int _30 = ub_draw[0].x + gl_InstanceID; + vec4 _62 = vec4(in_pos * _15.items[_30].scale_kind.xyz, 1.0); + v_kind = _15.items[_30].scale_kind.w; + gl_Position = mat4(ub_frame[0], ub_frame[1], ub_frame[2], ub_frame[3]) * vec4(dot(_15.items[_30].xform_row0, _62), dot(_15.items[_30].xform_row1, _62), dot(_15.items[_30].xform_row2, _62), 1.0); + } + +*/ +static const uint8_t mask_hull_vs_source_glsl430[709] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72, + 0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x63,0x61,0x6c,0x65,0x5f,0x6b,0x69, + 0x6e,0x64,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62, + 0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x30,0x2c,0x20,0x73,0x74,0x64,0x34, + 0x33,0x30,0x29,0x20,0x72,0x65,0x61,0x64,0x6f,0x6e,0x6c,0x79,0x20,0x62,0x75,0x66, + 0x66,0x65,0x72,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20,0x69,0x74,0x65, + 0x6d,0x73,0x5b,0x5d,0x3b,0x0a,0x7d,0x20,0x5f,0x31,0x35,0x3b,0x0a,0x0a,0x75,0x6e, + 0x69,0x66,0x6f,0x72,0x6d,0x20,0x69,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x64, + 0x72,0x61,0x77,0x5b,0x31,0x5d,0x3b,0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20, + 0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x34,0x5d, + 0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f, + 0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x69, + 0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f, + 0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x66,0x6c,0x61,0x74, + 0x20,0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x6b,0x69,0x6e, + 0x64,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x33,0x30,0x20,0x3d,0x20, + 0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x5b,0x30,0x5d,0x2e,0x78,0x20,0x2b,0x20,0x67, + 0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x36,0x32,0x20,0x3d,0x20,0x76,0x65,0x63, + 0x34,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69, + 0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x73,0x63,0x61,0x6c,0x65,0x5f, + 0x6b,0x69,0x6e,0x64,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x5f,0x6b,0x69,0x6e,0x64,0x20,0x3d,0x20,0x5f,0x31,0x35, + 0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x73,0x63,0x61,0x6c, + 0x65,0x5f,0x6b,0x69,0x6e,0x64,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c, + 0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34, + 0x28,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x30,0x5d,0x2c,0x20,0x75,0x62, + 0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x31,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72, + 0x61,0x6d,0x65,0x5b,0x32,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65, + 0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x64,0x6f,0x74,0x28, + 0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78, + 0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2c,0x20,0x5f,0x36,0x32,0x29,0x2c, + 0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f, + 0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2c,0x20, + 0x5f,0x36,0x32,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74, + 0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72, + 0x6f,0x77,0x32,0x2c,0x20,0x5f,0x36,0x32,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b, + 0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + #version 430 + + layout(location = 0) out vec4 out_kind; + layout(location = 0) flat in float v_kind; + + void main() + { + out_kind = vec4(v_kind * 0.5, 0.0, 0.0, 1.0); + } + +*/ +static const uint8_t mask_hull_fs_source_glsl430[166] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x6f,0x75,0x74,0x5f, + 0x6b,0x69,0x6e,0x64,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63, + 0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x66,0x6c,0x61,0x74,0x20, + 0x69,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x6b,0x69,0x6e,0x64,0x3b, + 0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x6b,0x69,0x6e,0x64,0x20,0x3d,0x20,0x76, + 0x65,0x63,0x34,0x28,0x76,0x5f,0x6b,0x69,0x6e,0x64,0x20,0x2a,0x20,0x30,0x2e,0x35, + 0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + struct instance + { + float4 xform_row0; + float4 xform_row1; + float4 xform_row2; + float4 scale_kind; + }; + + ByteAddressBuffer _15 : register(t0); + cbuffer ub_draw : register(b2) + { + int4 _21_inst_base : packoffset(c0); + }; + + cbuffer ub_frame : register(b0) + { + row_major float4x4 _91_view_proj : packoffset(c0); + }; + + + static float4 gl_Position; + static int gl_InstanceIndex; + static float3 in_pos; + static float v_kind; + + struct SPIRV_Cross_Input + { + float3 in_pos : TEXCOORD0; + uint gl_InstanceIndex : SV_InstanceID; + }; + + struct SPIRV_Cross_Output + { + nointerpolation float v_kind : TEXCOORD0; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + instance _33; + _33.xform_row0 = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 64 + 0)); + _33.xform_row1 = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 64 + 16)); + _33.xform_row2 = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 64 + 32)); + _33.scale_kind = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 64 + 48)); + float4 _62 = float4(in_pos * _33.scale_kind.xyz, 1.0f); + v_kind = _33.scale_kind.w; + gl_Position = mul(float4(dot(_33.xform_row0, _62), dot(_33.xform_row1, _62), dot(_33.xform_row2, _62), 1.0f), _91_view_proj); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_InstanceIndex = int(stage_input.gl_InstanceIndex); + in_pos = stage_input.in_pos; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.v_kind = v_kind; + return stage_output; + } +*/ +static const uint8_t mask_hull_vs_source_hlsl5[1569] = { + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d, + 0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x73,0x63,0x61,0x6c,0x65,0x5f,0x6b,0x69,0x6e,0x64,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x42,0x79,0x74,0x65,0x41,0x64,0x64,0x72,0x65,0x73,0x73,0x42,0x75,0x66, + 0x66,0x65,0x72,0x20,0x5f,0x31,0x35,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74, + 0x65,0x72,0x28,0x74,0x30,0x29,0x3b,0x0a,0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20, + 0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74, + 0x65,0x72,0x28,0x62,0x32,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74, + 0x34,0x20,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x20, + 0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29, + 0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62, + 0x5f,0x66,0x72,0x61,0x6d,0x65,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65, + 0x72,0x28,0x62,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f, + 0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f, + 0x39,0x31,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70, + 0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x7d, + 0x3b,0x0a,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x73, + 0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73, + 0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74, + 0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73, + 0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76, + 0x5f,0x6b,0x69,0x6e,0x64,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53, + 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e, + 0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e, + 0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x3a,0x20,0x53,0x56, + 0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x3b,0x0a,0x7d,0x3b,0x0a, + 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, + 0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x6b,0x69,0x6e,0x64,0x20,0x3a,0x20, + 0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f, + 0x6e,0x20,0x3a,0x20,0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b, + 0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d, + 0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x20,0x5f,0x33,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33, + 0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x20,0x3d,0x20,0x61, + 0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34, + 0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e, + 0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49, + 0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x36,0x34,0x20,0x2b,0x20,0x30,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f, + 0x72,0x6f,0x77,0x31,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f, + 0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e, + 0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20, + 0x36,0x34,0x20,0x2b,0x20,0x31,0x36,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f, + 0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x20,0x3d,0x20, + 0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64, + 0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65, + 0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x36,0x34,0x20,0x2b,0x20,0x33,0x32, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x73,0x63,0x61,0x6c, + 0x65,0x5f,0x6b,0x69,0x6e,0x64,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74, + 0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f, + 0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c, + 0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20, + 0x2a,0x20,0x36,0x34,0x20,0x2b,0x20,0x34,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36,0x32,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x2a,0x20,0x5f,0x33, + 0x33,0x2e,0x73,0x63,0x61,0x6c,0x65,0x5f,0x6b,0x69,0x6e,0x64,0x2e,0x78,0x79,0x7a, + 0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x6b, + 0x69,0x6e,0x64,0x20,0x3d,0x20,0x5f,0x33,0x33,0x2e,0x73,0x63,0x61,0x6c,0x65,0x5f, + 0x6b,0x69,0x6e,0x64,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50, + 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x64,0x6f,0x74,0x28,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2c,0x20,0x5f,0x36,0x32,0x29,0x2c,0x20,0x64, + 0x6f,0x74,0x28,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77, + 0x31,0x2c,0x20,0x5f,0x36,0x32,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x33,0x33, + 0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2c,0x20,0x5f,0x36,0x32, + 0x29,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f,0x39,0x31,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49, + 0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20, + 0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73, + 0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70, + 0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73, + 0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x3d,0x20,0x69,0x6e,0x74, + 0x28,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f, + 0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x3d,0x20,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73, + 0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f, + 0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65, + 0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74, + 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f, + 0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74, + 0x70,0x75,0x74,0x2e,0x76,0x5f,0x6b,0x69,0x6e,0x64,0x20,0x3d,0x20,0x76,0x5f,0x6b, + 0x69,0x6e,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a, + 0x00, +}; +/* + static float4 out_kind; + static float v_kind; + + struct SPIRV_Cross_Input + { + nointerpolation float v_kind : TEXCOORD0; + }; + + struct SPIRV_Cross_Output + { + float4 out_kind : SV_Target0; + }; + + void frag_main() + { + out_kind = float4(v_kind * 0.5f, 0.0f, 0.0f, 1.0f); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + v_kind = stage_input.v_kind; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.out_kind = out_kind; + return stage_output; + } +*/ +static const uint8_t mask_hull_fs_source_hlsl5[477] = { + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75, + 0x74,0x5f,0x6b,0x69,0x6e,0x64,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x6b,0x69,0x6e,0x64,0x3b,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73, + 0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69, + 0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x76,0x5f,0x6b,0x69,0x6e,0x64,0x20,0x3a,0x20,0x54,0x45,0x58,0x43, + 0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63, + 0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75, + 0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x6f,0x75,0x74,0x5f,0x6b,0x69,0x6e,0x64,0x20,0x3a,0x20,0x53,0x56,0x5f, + 0x54,0x61,0x72,0x67,0x65,0x74,0x30,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x6f,0x69, + 0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x6b,0x69,0x6e,0x64,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x76,0x5f,0x6b,0x69,0x6e,0x64,0x20,0x2a,0x20,0x30, + 0x2e,0x35,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c, + 0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56, + 0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61, + 0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49, + 0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x6b,0x69,0x6e,0x64,0x20,0x3d, + 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x6b, + 0x69,0x6e,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61, + 0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f, + 0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73, + 0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f, + 0x6b,0x69,0x6e,0x64,0x20,0x3d,0x20,0x6f,0x75,0x74,0x5f,0x6b,0x69,0x6e,0x64,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67, + 0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + struct instance + { + float4 xform_row0; + float4 xform_row1; + float4 xform_row2; + float4 scale_kind; + }; + + struct instances + { + instance items[1]; + }; + + struct ub_draw + { + int4 inst_base; + }; + + struct ub_frame + { + float4x4 view_proj; + }; + + struct main0_out + { + float v_kind [[user(locn0)]]; + float4 gl_Position [[position]]; + }; + + struct main0_in + { + float3 in_pos [[attribute(0)]]; + }; + + vertex main0_out main0(main0_in in [[stage_in]], constant ub_frame& _91 [[buffer(0)]], constant ub_draw& _21 [[buffer(2)]], const device instances& _15 [[buffer(8)]], uint gl_InstanceIndex [[instance_id]]) + { + main0_out out = {}; + int _30 = _21.inst_base.x + int(gl_InstanceIndex); + float4 _62 = float4(in.in_pos * _15.items[_30].scale_kind.xyz, 1.0); + out.v_kind = _15.items[_30].scale_kind.w; + out.gl_Position = _91.view_proj * float4(dot(_15.items[_30].xform_row0, _62), dot(_15.items[_30].xform_row1, _62), dot(_15.items[_30].xform_row2, _62), 1.0); + return out; + } + +*/ +static const uint8_t mask_hull_vs_source_metal_macos[1059] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x63,0x61,0x6c,0x65,0x5f, + 0x6b,0x69,0x6e,0x64,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74, + 0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20,0x69,0x74,0x65,0x6d,0x73,0x5b, + 0x31,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75, + 0x62,0x5f,0x64,0x72,0x61,0x77,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74, + 0x34,0x20,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x3b,0x0a,0x7d,0x3b,0x0a, + 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20, + 0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73, + 0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x6b,0x69, + 0x6e,0x64,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29, + 0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67, + 0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b,0x70,0x6f,0x73, + 0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72, + 0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73, + 0x20,0x5b,0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28,0x30,0x29,0x5d, + 0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,0x65,0x78,0x20,0x6d,0x61, + 0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61, + 0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67, + 0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74, + 0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x26,0x20,0x5f,0x39,0x31,0x20,0x5b, + 0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x26,0x20, + 0x5f,0x32,0x31,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x32,0x29,0x5d, + 0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x20, + 0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x26,0x20,0x5f,0x31,0x35,0x20,0x5b, + 0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x38,0x29,0x5d,0x5d,0x2c,0x20,0x75,0x69, + 0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e, + 0x64,0x65,0x78,0x20,0x5b,0x5b,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x5f,0x69, + 0x64,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30, + 0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x33,0x30,0x20,0x3d,0x20,0x5f,0x32,0x31, + 0x2e,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x69, + 0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e, + 0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x5f,0x36,0x32,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x69,0x6e, + 0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74, + 0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x73,0x63,0x61,0x6c,0x65,0x5f,0x6b, + 0x69,0x6e,0x64,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x6b,0x69,0x6e,0x64,0x20,0x3d,0x20, + 0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x73, + 0x63,0x61,0x6c,0x65,0x5f,0x6b,0x69,0x6e,0x64,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x5f,0x39,0x31,0x2e,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a, + 0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31, + 0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2c,0x20,0x5f,0x36,0x32,0x29,0x2c,0x20,0x64, + 0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30, + 0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2c,0x20,0x5f,0x36, + 0x32,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d, + 0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77, + 0x32,0x2c,0x20,0x5f,0x36,0x32,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + struct main0_out + { + float4 out_kind [[color(0)]]; + }; + + struct main0_in + { + float v_kind [[user(locn0), flat]]; + }; + + fragment main0_out main0(main0_in in [[stage_in]]) + { + main0_out out = {}; + out.out_kind = float4(in.v_kind * 0.5, 0.0, 0.0, 1.0); + return out; + } + +*/ +static const uint8_t mask_hull_fs_source_metal_macos[347] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d, + 0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x6b,0x69,0x6e,0x64,0x20,0x5b, + 0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a, + 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x6b, + 0x69,0x6e,0x64,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30, + 0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x66, + 0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75, + 0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e, + 0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75, + 0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x6b,0x69,0x6e,0x64,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x6b,0x69,0x6e,0x64,0x20, + 0x2a,0x20,0x30,0x2e,0x35,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c, + 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +static inline const sg_shader_desc* mask_hull_prog_shader_desc(sg_backend backend) { + if (backend == SG_BACKEND_GLCORE) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)mask_hull_vs_source_glsl430; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)mask_hull_fs_source_glsl430; + desc.fragment_func.entry = "main"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[0].glsl_name = "in_pos"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[0].glsl_uniforms[0].array_count = 4; + desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_frame"; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 16; + desc.uniform_blocks[2].glsl_uniforms[0].type = SG_UNIFORMTYPE_INT4; + desc.uniform_blocks[2].glsl_uniforms[0].array_count = 1; + desc.uniform_blocks[2].glsl_uniforms[0].glsl_name = "ub_draw"; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.glsl_binding_n = 0; + desc.label = "mask_hull_prog_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_D3D11) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)mask_hull_vs_source_hlsl5; + desc.vertex_func.d3d11_target = "vs_5_0"; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)mask_hull_fs_source_hlsl5; + desc.fragment_func.d3d11_target = "ps_5_0"; + desc.fragment_func.entry = "main"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[0].hlsl_sem_name = "TEXCOORD"; + desc.attrs[0].hlsl_sem_index = 0; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].hlsl_register_b_n = 0; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 16; + desc.uniform_blocks[2].hlsl_register_b_n = 2; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.hlsl_register_t_n = 0; + desc.label = "mask_hull_prog_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_METAL_MACOS) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)mask_hull_vs_source_metal_macos; + desc.vertex_func.entry = "main0"; + desc.fragment_func.source = (const char*)mask_hull_fs_source_metal_macos; + desc.fragment_func.entry = "main0"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].msl_buffer_n = 0; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 16; + desc.uniform_blocks[2].msl_buffer_n = 2; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.msl_buffer_n = 8; + desc.label = "mask_hull_prog_shader"; + } + return &desc; + } + return 0; +} diff --git a/samples/shaders/generated/mask_sphere.glsl.h b/samples/shaders/generated/mask_sphere.glsl.h new file mode 100644 index 0000000..1b1f93c --- /dev/null +++ b/samples/shaders/generated/mask_sphere.glsl.h @@ -0,0 +1,894 @@ +#pragma once +/* + #version:1# (machine generated, don't edit!) + + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) + + Cmdline: + sokol-shdc --input E:/box/box3d/samples/shaders/post/mask_sphere.glsl --output E:/box/box3d/samples/shaders/generated/mask_sphere.glsl.h --slang hlsl5:metal_macos:glsl430 + + Overview: + ========= + Shader program: 'prog': + Get shader desc: mask_sphere_prog_shader_desc(sg_query_backend()); + Vertex Shader: vs + Fragment Shader: fs + Attributes: + ATTR_mask_sphere_prog_in_pos => 0 + Bindings: + Uniform block 'ub_frame': + C struct: mask_sphere_ub_frame_t + Bind slot: UB_mask_sphere_ub_frame => 0 + Uniform block 'ub_pass': + C struct: mask_sphere_ub_pass_t + Bind slot: UB_mask_sphere_ub_pass => 1 + Storage buffer 'instances': + C struct: mask_sphere_instance_t + Bind slot: VIEW_mask_sphere_instances => 0 + Readonly: true +*/ +#if !defined(SOKOL_GFX_INCLUDED) +#error "Please include sokol_gfx.h before mask_sphere.glsl.h" +#endif +#if !defined(SOKOL_SHDC_ALIGN) +#if defined(_MSC_VER) +#define SOKOL_SHDC_ALIGN(a) __declspec(align(a)) +#else +#define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) +#endif +#endif +#define ATTR_mask_sphere_prog_in_pos (0) +#define UB_mask_sphere_ub_frame (0) +#define UB_mask_sphere_ub_pass (1) +#define VIEW_mask_sphere_instances (0) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct mask_sphere_ub_frame_t { + Mat4 view_proj; +} mask_sphere_ub_frame_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct mask_sphere_ub_pass_t { + Mat4 view_proj; + Vec4 camera_pos; +} mask_sphere_ub_pass_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct mask_sphere_instance_t { + Vec4 center_radius; + Vec4 kind; +} mask_sphere_instance_t; +#pragma pack(pop) +/* + #version 430 + + struct instance + { + vec4 center_radius; + vec4 kind; + }; + + layout(binding = 0, std430) readonly buffer instances + { + instance items[]; + } _15; + + uniform vec4 ub_frame[4]; + layout(location = 0) in vec3 in_pos; + layout(location = 0) sample out vec3 v_world_pos_proxy; + layout(location = 1) flat out vec3 v_center; + layout(location = 2) flat out float v_radius; + layout(location = 3) flat out float v_kind; + + void main() + { + vec3 _51 = _15.items[gl_InstanceID].center_radius.xyz + (in_pos * (2.0 * _15.items[gl_InstanceID].center_radius.w)); + v_world_pos_proxy = _51; + v_center = _15.items[gl_InstanceID].center_radius.xyz; + v_radius = _15.items[gl_InstanceID].center_radius.w; + v_kind = _15.items[gl_InstanceID].kind.x; + gl_Position = mat4(ub_frame[0], ub_frame[1], ub_frame[2], ub_frame[3]) * vec4(_51, 1.0); + } + +*/ +static const uint8_t mask_sphere_vs_source_glsl430[839] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x65,0x6e,0x74,0x65,0x72,0x5f, + 0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34, + 0x20,0x6b,0x69,0x6e,0x64,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75, + 0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x30,0x2c,0x20,0x73, + 0x74,0x64,0x34,0x33,0x30,0x29,0x20,0x72,0x65,0x61,0x64,0x6f,0x6e,0x6c,0x79,0x20, + 0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20, + 0x69,0x74,0x65,0x6d,0x73,0x5b,0x5d,0x3b,0x0a,0x7d,0x20,0x5f,0x31,0x35,0x3b,0x0a, + 0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62, + 0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x34,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75, + 0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20, + 0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a, + 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20, + 0x3d,0x20,0x30,0x29,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x20,0x6f,0x75,0x74,0x20, + 0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, + 0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, + 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x66,0x6c,0x61, + 0x74,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e, + 0x74,0x65,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x6f, + 0x75,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75, + 0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69, + 0x6f,0x6e,0x20,0x3d,0x20,0x33,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x6f,0x75,0x74, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x6b,0x69,0x6e,0x64,0x3b,0x0a,0x0a, + 0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x35,0x31,0x20,0x3d,0x20,0x5f,0x31,0x35, + 0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x49,0x44,0x5d,0x2e,0x63,0x65,0x6e,0x74,0x65,0x72,0x5f,0x72,0x61,0x64, + 0x69,0x75,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x69,0x6e,0x5f,0x70,0x6f, + 0x73,0x20,0x2a,0x20,0x28,0x32,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69, + 0x74,0x65,0x6d,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x49,0x44,0x5d,0x2e,0x63,0x65,0x6e,0x74,0x65,0x72,0x5f,0x72,0x61,0x64,0x69,0x75, + 0x73,0x2e,0x77,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x5f, + 0x35,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72, + 0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x67,0x6c,0x5f, + 0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x63,0x65,0x6e,0x74, + 0x65,0x72,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x5f,0x31, + 0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61, + 0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x63,0x65,0x6e,0x74,0x65,0x72,0x5f,0x72,0x61, + 0x64,0x69,0x75,0x73,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x6b,0x69, + 0x6e,0x64,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x67, + 0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x6b,0x69, + 0x6e,0x64,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73, + 0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x75,0x62,0x5f, + 0x66,0x72,0x61,0x6d,0x65,0x5b,0x30,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61, + 0x6d,0x65,0x5b,0x31,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b, + 0x32,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x33,0x5d,0x29, + 0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x35,0x31,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + #version 430 + + uniform vec4 ub_pass[5]; + layout(location = 0) sample in vec3 v_world_pos_proxy; + layout(location = 1) flat in vec3 v_center; + layout(location = 2) flat in float v_radius; + layout(location = 0) out vec4 out_kind; + layout(location = 3) flat in float v_kind; + + void main() + { + vec3 _27 = normalize(v_world_pos_proxy - ub_pass[4].xyz); + vec3 _32 = ub_pass[4].xyz - v_center; + float _37 = dot(_32, _27); + float _53 = (_37 * _37) - (dot(_32, _32) - (v_radius * v_radius)); + if (_53 < 0.0) + { + discard; + } + float _66 = (-_37) - sqrt(_53); + if (_66 < 0.0) + { + discard; + } + vec4 _90 = mat4(ub_pass[0], ub_pass[1], ub_pass[2], ub_pass[3]) * vec4(ub_pass[4].xyz + (_27 * _66), 1.0); + gl_FragDepth = _90.z / _90.w; + out_kind = vec4(v_kind * 0.5, 0.0, 0.0, 1.0); + } + +*/ +static const uint8_t mask_sphere_fs_source_glsl430[818] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x75,0x6e, + 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x70,0x61, + 0x73,0x73,0x5b,0x35,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f, + 0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x31,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20, + 0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, + 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x66, + 0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72, + 0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f, + 0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20, + 0x76,0x65,0x63,0x34,0x20,0x6f,0x75,0x74,0x5f,0x6b,0x69,0x6e,0x64,0x3b,0x0a,0x6c, + 0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d, + 0x20,0x33,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x76,0x5f,0x6b,0x69,0x6e,0x64,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20, + 0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x33,0x20,0x5f,0x32,0x37,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a, + 0x65,0x28,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72, + 0x6f,0x78,0x79,0x20,0x2d,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x34,0x5d, + 0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, + 0x5f,0x33,0x32,0x20,0x3d,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x34,0x5d, + 0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x33,0x37,0x20,0x3d, + 0x20,0x64,0x6f,0x74,0x28,0x5f,0x33,0x32,0x2c,0x20,0x5f,0x32,0x37,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x33,0x20,0x3d,0x20, + 0x28,0x5f,0x33,0x37,0x20,0x2a,0x20,0x5f,0x33,0x37,0x29,0x20,0x2d,0x20,0x28,0x64, + 0x6f,0x74,0x28,0x5f,0x33,0x32,0x2c,0x20,0x5f,0x33,0x32,0x29,0x20,0x2d,0x20,0x28, + 0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x2a,0x20,0x76,0x5f,0x72,0x61,0x64, + 0x69,0x75,0x73,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, + 0x35,0x33,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x36,0x36,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x33,0x37,0x29,0x20,0x2d,0x20, + 0x73,0x71,0x72,0x74,0x28,0x5f,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x5f,0x36,0x36,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x64,0x69,0x73,0x63, + 0x61,0x72,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x34,0x20,0x5f,0x39,0x30,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x75, + 0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x30,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x70,0x61, + 0x73,0x73,0x5b,0x31,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x32, + 0x5d,0x2c,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x33,0x5d,0x29,0x20,0x2a, + 0x20,0x76,0x65,0x63,0x34,0x28,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x34,0x5d, + 0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x32,0x37,0x20,0x2a,0x20,0x5f,0x36, + 0x36,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c, + 0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x5f,0x39,0x30, + 0x2e,0x7a,0x20,0x2f,0x20,0x5f,0x39,0x30,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x6f,0x75,0x74,0x5f,0x6b,0x69,0x6e,0x64,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28, + 0x76,0x5f,0x6b,0x69,0x6e,0x64,0x20,0x2a,0x20,0x30,0x2e,0x35,0x2c,0x20,0x30,0x2e, + 0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x00, +}; +/* + struct instance + { + float4 center_radius; + float4 kind; + }; + + ByteAddressBuffer _15 : register(t0); + cbuffer ub_frame : register(b0) + { + row_major float4x4 _72_view_proj : packoffset(c0); + }; + + + static float4 gl_Position; + static int gl_InstanceIndex; + static float3 in_pos; + static float3 v_world_pos_proxy; + static float3 v_center; + static float v_radius; + static float v_kind; + + struct SPIRV_Cross_Input + { + float3 in_pos : TEXCOORD0; + uint gl_InstanceIndex : SV_InstanceID; + }; + + struct SPIRV_Cross_Output + { + sample float3 v_world_pos_proxy : TEXCOORD0; + nointerpolation float3 v_center : TEXCOORD1; + nointerpolation float v_radius : TEXCOORD2; + nointerpolation float v_kind : TEXCOORD3; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + instance _23; + _23.center_radius = asfloat(_15.Load4(gl_InstanceIndex * 32 + 0)); + _23.kind = asfloat(_15.Load4(gl_InstanceIndex * 32 + 16)); + float3 _51 = _23.center_radius.xyz + (in_pos * (2.0f * _23.center_radius.w)); + v_world_pos_proxy = _51; + v_center = _23.center_radius.xyz; + v_radius = _23.center_radius.w; + v_kind = _23.kind.x; + gl_Position = mul(float4(_51, 1.0f), _72_view_proj); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_InstanceIndex = int(stage_input.gl_InstanceIndex); + in_pos = stage_input.in_pos; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.v_world_pos_proxy = v_world_pos_proxy; + stage_output.v_center = v_center; + stage_output.v_radius = v_radius; + stage_output.v_kind = v_kind; + return stage_output; + } +*/ +static const uint8_t mask_sphere_vs_source_hlsl5[1625] = { + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x65,0x6e, + 0x74,0x65,0x72,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6b,0x69,0x6e,0x64,0x3b,0x0a,0x7d,0x3b,0x0a, + 0x0a,0x42,0x79,0x74,0x65,0x41,0x64,0x64,0x72,0x65,0x73,0x73,0x42,0x75,0x66,0x66, + 0x65,0x72,0x20,0x5f,0x31,0x35,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65, + 0x72,0x28,0x74,0x30,0x29,0x3b,0x0a,0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75, + 0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74, + 0x65,0x72,0x28,0x62,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77, + 0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20, + 0x5f,0x37,0x32,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20, + 0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a, + 0x7d,0x3b,0x0a,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a, + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e, + 0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x3b,0x0a,0x73,0x74,0x61, + 0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f, + 0x73,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f, + 0x78,0x79,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74, + 0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75, + 0x73,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x76,0x5f,0x6b,0x69,0x6e,0x64,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20, + 0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75, + 0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69, + 0x6e,0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44, + 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x3a,0x20,0x53, + 0x56,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, + 0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78, + 0x79,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69, + 0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74, + 0x65,0x72,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74, + 0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69, + 0x75,0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x32,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74, + 0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x6b,0x69,0x6e,0x64, + 0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x33,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69, + 0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69, + 0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x76,0x65,0x72, + 0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20,0x5f,0x32,0x33,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x5f,0x32,0x33,0x2e,0x63,0x65,0x6e,0x74,0x65,0x72,0x5f,0x72,0x61,0x64,0x69, + 0x75,0x73,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35, + 0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x2a,0x20,0x33,0x32,0x20,0x2b,0x20,0x30, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x32,0x33,0x2e,0x6b,0x69,0x6e,0x64, + 0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c, + 0x6f,0x61,0x64,0x34,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x49,0x6e,0x64,0x65,0x78,0x20,0x2a,0x20,0x33,0x32,0x20,0x2b,0x20,0x31,0x36,0x29, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x35, + 0x31,0x20,0x3d,0x20,0x5f,0x32,0x33,0x2e,0x63,0x65,0x6e,0x74,0x65,0x72,0x5f,0x72, + 0x61,0x64,0x69,0x75,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x69,0x6e,0x5f, + 0x70,0x6f,0x73,0x20,0x2a,0x20,0x28,0x32,0x2e,0x30,0x66,0x20,0x2a,0x20,0x5f,0x32, + 0x33,0x2e,0x63,0x65,0x6e,0x74,0x65,0x72,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x2e, + 0x77,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x5f,0x35,0x31, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3d, + 0x20,0x5f,0x32,0x33,0x2e,0x63,0x65,0x6e,0x74,0x65,0x72,0x5f,0x72,0x61,0x64,0x69, + 0x75,0x73,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x61, + 0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x5f,0x32,0x33,0x2e,0x63,0x65,0x6e,0x74,0x65, + 0x72,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x5f,0x6b,0x69,0x6e,0x64,0x20,0x3d,0x20,0x5f,0x32,0x33,0x2e,0x6b,0x69,0x6e, + 0x64,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x28,0x5f,0x35,0x31,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f,0x37, + 0x32,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x29,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74, + 0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, + 0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65, + 0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c, + 0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x3d, + 0x20,0x69,0x6e,0x74,0x28,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74, + 0x2e,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65, + 0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x3d, + 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x69,0x6e,0x5f, + 0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61, + 0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f, + 0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73, + 0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50, + 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73, + 0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65, + 0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x76,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e, + 0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3d,0x20,0x76,0x5f,0x63,0x65,0x6e, + 0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f, + 0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d, + 0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73, + 0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x6b,0x69, + 0x6e,0x64,0x20,0x3d,0x20,0x76,0x5f,0x6b,0x69,0x6e,0x64,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75, + 0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + cbuffer ub_pass : register(b1) + { + row_major float4x4 _14_view_proj : packoffset(c0); + float4 _14_camera_pos : packoffset(c4); + }; + + + static float gl_FragDepth; + static float3 v_world_pos_proxy; + static float3 v_center; + static float v_radius; + static float4 out_kind; + static float v_kind; + + struct SPIRV_Cross_Input + { + sample float3 v_world_pos_proxy : TEXCOORD0; + nointerpolation float3 v_center : TEXCOORD1; + nointerpolation float v_radius : TEXCOORD2; + nointerpolation float v_kind : TEXCOORD3; + }; + + struct SPIRV_Cross_Output + { + float4 out_kind : SV_Target0; + float gl_FragDepth : SV_Depth; + }; + + void frag_main() + { + float3 _27 = normalize(v_world_pos_proxy - _14_camera_pos.xyz); + float3 _32 = _14_camera_pos.xyz - v_center; + float _37 = dot(_32, _27); + float _53 = (_37 * _37) - (dot(_32, _32) - (v_radius * v_radius)); + if (_53 < 0.0f) + { + discard; + } + float _66 = (-_37) - sqrt(_53); + if (_66 < 0.0f) + { + discard; + } + float4 _90 = mul(float4(_14_camera_pos.xyz + (_27 * _66), 1.0f), _14_view_proj); + gl_FragDepth = _90.z / _90.w; + out_kind = float4(v_kind * 0.5f, 0.0f, 0.0f, 1.0f); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + v_world_pos_proxy = stage_input.v_world_pos_proxy; + v_center = stage_input.v_center; + v_radius = stage_input.v_radius; + v_kind = stage_input.v_kind; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_FragDepth = gl_FragDepth; + stage_output.out_kind = out_kind; + return stage_output; + } +*/ +static const uint8_t mask_sphere_fs_source_hlsl5[1548] = { + 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x31,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x31,0x34,0x5f,0x76,0x69,0x65,0x77, + 0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73, + 0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x5f,0x31,0x34,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f, + 0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63, + 0x34,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70, + 0x74,0x68,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72, + 0x6f,0x78,0x79,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x73,0x74,0x61, + 0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69, + 0x75,0x73,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x6f,0x75,0x74,0x5f,0x6b,0x69,0x6e,0x64,0x3b,0x0a,0x73,0x74,0x61,0x74, + 0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x6b,0x69,0x6e,0x64,0x3b, + 0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, + 0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79, + 0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f, + 0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65, + 0x72,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69, + 0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75, + 0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69, + 0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x6b,0x69,0x6e,0x64,0x20, + 0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x33,0x3b,0x0a,0x7d,0x3b,0x0a, + 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, + 0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x6b,0x69,0x6e,0x64, + 0x20,0x3a,0x20,0x53,0x56,0x5f,0x54,0x61,0x72,0x67,0x65,0x74,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67, + 0x44,0x65,0x70,0x74,0x68,0x20,0x3a,0x20,0x53,0x56,0x5f,0x44,0x65,0x70,0x74,0x68, + 0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f, + 0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x5f,0x32,0x37,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c, + 0x69,0x7a,0x65,0x28,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f, + 0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x5f,0x31,0x34,0x5f,0x63,0x61,0x6d,0x65, + 0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x33,0x32,0x20,0x3d,0x20,0x5f,0x31, + 0x34,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a, + 0x20,0x2d,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x33,0x37,0x20,0x3d,0x20,0x64,0x6f,0x74, + 0x28,0x5f,0x33,0x32,0x2c,0x20,0x5f,0x32,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x33,0x20,0x3d,0x20,0x28,0x5f,0x33,0x37, + 0x20,0x2a,0x20,0x5f,0x33,0x37,0x29,0x20,0x2d,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f, + 0x33,0x32,0x2c,0x20,0x5f,0x33,0x32,0x29,0x20,0x2d,0x20,0x28,0x76,0x5f,0x72,0x61, + 0x64,0x69,0x75,0x73,0x20,0x2a,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x29, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x35,0x33,0x20,0x3c, + 0x20,0x30,0x2e,0x30,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36, + 0x36,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x33,0x37,0x29,0x20,0x2d,0x20,0x73,0x71,0x72, + 0x74,0x28,0x5f,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x5f,0x36,0x36,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72, + 0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x5f,0x39,0x30,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x34,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f, + 0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x32,0x37,0x20,0x2a, + 0x20,0x5f,0x36,0x36,0x29,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f,0x31, + 0x34,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d, + 0x20,0x5f,0x39,0x30,0x2e,0x7a,0x20,0x2f,0x20,0x5f,0x39,0x30,0x2e,0x77,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x6b,0x69,0x6e,0x64,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x76,0x5f,0x6b,0x69,0x6e,0x64,0x20,0x2a,0x20,0x30, + 0x2e,0x35,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c, + 0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56, + 0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61, + 0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49, + 0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x73,0x74,0x61,0x67, + 0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f, + 0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x73, + 0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x72,0x61,0x64, + 0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x6b,0x69,0x6e,0x64,0x20, + 0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f, + 0x6b,0x69,0x6e,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d, + 0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56, + 0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74, + 0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f, + 0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x46, + 0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74, + 0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x6b, + 0x69,0x6e,0x64,0x20,0x3d,0x20,0x6f,0x75,0x74,0x5f,0x6b,0x69,0x6e,0x64,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65, + 0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + struct instance + { + float4 center_radius; + float4 kind; + }; + + struct instances + { + instance items[1]; + }; + + struct ub_frame + { + float4x4 view_proj; + }; + + struct main0_out + { + float3 v_world_pos_proxy [[user(locn0)]]; + float3 v_center [[user(locn1)]]; + float v_radius [[user(locn2)]]; + float v_kind [[user(locn3)]]; + float4 gl_Position [[position]]; + }; + + struct main0_in + { + float3 in_pos [[attribute(0)]]; + }; + + vertex main0_out main0(main0_in in [[stage_in]], constant ub_frame& _72 [[buffer(0)]], const device instances& _15 [[buffer(8)]], uint gl_InstanceIndex [[instance_id]]) + { + main0_out out = {}; + float3 _51 = _15.items[int(gl_InstanceIndex)].center_radius.xyz + (in.in_pos * (2.0 * _15.items[int(gl_InstanceIndex)].center_radius.w)); + out.v_world_pos_proxy = _51; + out.v_center = _15.items[int(gl_InstanceIndex)].center_radius.xyz; + out.v_radius = _15.items[int(gl_InstanceIndex)].center_radius.w; + out.v_kind = _15.items[int(gl_InstanceIndex)].kind.x; + out.gl_Position = _72.view_proj * float4(_51, 1.0); + return out; + } + +*/ +static const uint8_t mask_sphere_vs_source_metal_macos[1144] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x63,0x65,0x6e,0x74,0x65,0x72,0x5f,0x72,0x61,0x64,0x69, + 0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6b, + 0x69,0x6e,0x64,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20, + 0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20,0x69,0x74,0x65,0x6d,0x73,0x5b,0x31, + 0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75,0x62, + 0x5f,0x66,0x72,0x61,0x6d,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x78,0x34,0x20,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x3b, + 0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e, + 0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70, + 0x72,0x6f,0x78,0x79,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e, + 0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72, + 0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x5b,0x5b, + 0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x32,0x29,0x5d,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x6b,0x69,0x6e,0x64,0x20, + 0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x33,0x29,0x5d,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50, + 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69, + 0x6f,0x6e,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74, + 0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x5b,0x5b, + 0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a, + 0x7d,0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,0x65,0x78,0x20,0x6d,0x61,0x69,0x6e,0x30, + 0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30, + 0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69, + 0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62, + 0x5f,0x66,0x72,0x61,0x6d,0x65,0x26,0x20,0x5f,0x37,0x32,0x20,0x5b,0x5b,0x62,0x75, + 0x66,0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x73,0x26,0x20,0x5f,0x31,0x35,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28, + 0x38,0x29,0x5d,0x5d,0x2c,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e, + 0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x5b,0x5b,0x69,0x6e, + 0x73,0x74,0x61,0x6e,0x63,0x65,0x5f,0x69,0x64,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74, + 0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x5f,0x35,0x31,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d, + 0x73,0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x63,0x65,0x6e,0x74,0x65,0x72,0x5f, + 0x72,0x61,0x64,0x69,0x75,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x69,0x6e, + 0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x2a,0x20,0x28,0x32,0x2e,0x30,0x20,0x2a, + 0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x69,0x6e,0x74,0x28,0x67, + 0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29, + 0x5d,0x2e,0x63,0x65,0x6e,0x74,0x65,0x72,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x2e, + 0x77,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3d, + 0x20,0x5f,0x35,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f, + 0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65, + 0x6d,0x73,0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x63,0x65,0x6e,0x74,0x65,0x72, + 0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20, + 0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c, + 0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x5d, + 0x2e,0x63,0x65,0x6e,0x74,0x65,0x72,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x2e,0x77, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x6b,0x69,0x6e,0x64, + 0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x69,0x6e,0x74, + 0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65, + 0x78,0x29,0x5d,0x2e,0x6b,0x69,0x6e,0x64,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20, + 0x3d,0x20,0x5f,0x37,0x32,0x2e,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20, + 0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x31,0x2c,0x20,0x31,0x2e, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f, + 0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + struct ub_pass + { + float4x4 view_proj; + float4 camera_pos; + }; + + struct main0_out + { + float4 out_kind [[color(0)]]; + float gl_FragDepth [[depth(any)]]; + }; + + struct main0_in + { + float3 v_world_pos_proxy [[user(locn0), sample_perspective]]; + float3 v_center [[user(locn1), flat]]; + float v_radius [[user(locn2), flat]]; + float v_kind [[user(locn3), flat]]; + }; + + fragment main0_out main0(main0_in in [[stage_in]], constant ub_pass& _14 [[buffer(1)]]) + { + main0_out out = {}; + float3 _27 = fast::normalize(in.v_world_pos_proxy - _14.camera_pos.xyz); + float3 _32 = _14.camera_pos.xyz - in.v_center; + float _37 = dot(_32, _27); + float _53 = (_37 * _37) - (dot(_32, _32) - (in.v_radius * in.v_radius)); + if (_53 < 0.0) + { + discard_fragment(); + } + float _66 = (-_37) - sqrt(_53); + if (_66 < 0.0) + { + discard_fragment(); + } + float4 _90 = _14.view_proj * float4(_14.camera_pos.xyz + (_27 * _66), 1.0); + out.gl_FragDepth = _90.z / _90.w; + out.out_kind = float4(in.v_kind * 0.5, 0.0, 0.0, 1.0); + return out; + } + +*/ +static const uint8_t mask_sphere_fs_source_metal_macos[1150] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75, + 0x62,0x5f,0x70,0x61,0x73,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x78,0x34,0x20,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x61,0x6d,0x65, + 0x72,0x61,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75, + 0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x6b,0x69, + 0x6e,0x64,0x20,0x5b,0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29,0x5d,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,0x46,0x72, + 0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x5b,0x5b,0x64,0x65,0x70,0x74,0x68,0x28, + 0x61,0x6e,0x79,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75, + 0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x5b,0x5b,0x75,0x73,0x65, + 0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, + 0x5f,0x70,0x65,0x72,0x73,0x70,0x65,0x63,0x74,0x69,0x76,0x65,0x5d,0x5d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e, + 0x74,0x65,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31, + 0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x5b,0x5b, + 0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x32,0x29,0x2c,0x20,0x66,0x6c,0x61, + 0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76, + 0x5f,0x6b,0x69,0x6e,0x64,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63, + 0x6e,0x33,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a, + 0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f, + 0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f, + 0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e, + 0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f, + 0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x31,0x34,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66, + 0x65,0x72,0x28,0x31,0x29,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d, + 0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b, + 0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x32, + 0x37,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c, + 0x69,0x7a,0x65,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70, + 0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x5f,0x31,0x34,0x2e,0x63, + 0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x33,0x32,0x20,0x3d, + 0x20,0x5f,0x31,0x34,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e, + 0x78,0x79,0x7a,0x20,0x2d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65, + 0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x33,0x37, + 0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x33,0x32,0x2c,0x20,0x5f,0x32,0x37,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x33,0x20, + 0x3d,0x20,0x28,0x5f,0x33,0x37,0x20,0x2a,0x20,0x5f,0x33,0x37,0x29,0x20,0x2d,0x20, + 0x28,0x64,0x6f,0x74,0x28,0x5f,0x33,0x32,0x2c,0x20,0x5f,0x33,0x32,0x29,0x20,0x2d, + 0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x2a,0x20, + 0x69,0x6e,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x35,0x33,0x20,0x3c,0x20,0x30,0x2e,0x30, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x64,0x69,0x73,0x63,0x61,0x72,0x64,0x5f,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74, + 0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x36,0x36,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x33,0x37,0x29, + 0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x36,0x36,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x64, + 0x69,0x73,0x63,0x61,0x72,0x64,0x5f,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x28, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x5f,0x39,0x30,0x20,0x3d,0x20,0x5f,0x31,0x34,0x2e,0x76,0x69, + 0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x28,0x5f,0x31,0x34,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e, + 0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x32,0x37,0x20,0x2a,0x20,0x5f,0x36,0x36, + 0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, + 0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d,0x20, + 0x5f,0x39,0x30,0x2e,0x7a,0x20,0x2f,0x20,0x5f,0x39,0x30,0x2e,0x77,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x6b,0x69,0x6e,0x64,0x20, + 0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x6b,0x69, + 0x6e,0x64,0x20,0x2a,0x20,0x30,0x2e,0x35,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30, + 0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +static inline const sg_shader_desc* mask_sphere_prog_shader_desc(sg_backend backend) { + if (backend == SG_BACKEND_GLCORE) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)mask_sphere_vs_source_glsl430; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)mask_sphere_fs_source_glsl430; + desc.fragment_func.entry = "main"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[0].glsl_name = "in_pos"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[0].glsl_uniforms[0].array_count = 4; + desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_frame"; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 80; + desc.uniform_blocks[1].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[0].array_count = 5; + desc.uniform_blocks[1].glsl_uniforms[0].glsl_name = "ub_pass"; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.glsl_binding_n = 0; + desc.label = "mask_sphere_prog_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_D3D11) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)mask_sphere_vs_source_hlsl5; + desc.vertex_func.d3d11_target = "vs_5_0"; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)mask_sphere_fs_source_hlsl5; + desc.fragment_func.d3d11_target = "ps_5_0"; + desc.fragment_func.entry = "main"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[0].hlsl_sem_name = "TEXCOORD"; + desc.attrs[0].hlsl_sem_index = 0; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].hlsl_register_b_n = 0; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 80; + desc.uniform_blocks[1].hlsl_register_b_n = 1; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.hlsl_register_t_n = 0; + desc.label = "mask_sphere_prog_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_METAL_MACOS) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)mask_sphere_vs_source_metal_macos; + desc.vertex_func.entry = "main0"; + desc.fragment_func.source = (const char*)mask_sphere_fs_source_metal_macos; + desc.fragment_func.entry = "main0"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].msl_buffer_n = 0; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 80; + desc.uniform_blocks[1].msl_buffer_n = 1; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.msl_buffer_n = 8; + desc.label = "mask_sphere_prog_shader"; + } + return &desc; + } + return 0; +} diff --git a/samples/shaders/generated/overlay_line.glsl.h b/samples/shaders/generated/overlay_line.glsl.h new file mode 100644 index 0000000..a71af3f --- /dev/null +++ b/samples/shaders/generated/overlay_line.glsl.h @@ -0,0 +1,1691 @@ +#pragma once +/* + #version:1# (machine generated, don't edit!) + + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) + + Cmdline: + sokol-shdc --input E:/box/box3d/samples/shaders/overlays/line.glsl --output E:/box/box3d/samples/shaders/generated/overlay_line.glsl.h --slang hlsl5:metal_macos:glsl430 + + Overview: + ========= + Shader program: 'prog': + Get shader desc: overlay_line_prog_shader_desc(sg_query_backend()); + Vertex Shader: vs + Fragment Shader: fs + Attributes: + Bindings: + Uniform block 'ub_frame': + C struct: overlay_line_ub_frame_t + Bind slot: UB_overlay_line_ub_frame => 0 + Storage buffer 'line_instances': + C struct: overlay_line_line_instance_t + Bind slot: VIEW_overlay_line_line_instances => 0 + Readonly: true + Texture 'tex_depth': + Image type: SG_IMAGETYPE_2D + Sample type: SG_IMAGESAMPLETYPE_FLOAT + Multisampled: false + Bind slot: VIEW_overlay_line_tex_depth => 1 + Sampler 'smp_depth': + Type: SG_SAMPLERTYPE_FILTERING + Bind slot: SMP_overlay_line_smp_depth => 0 +*/ +#if !defined(SOKOL_GFX_INCLUDED) +#error "Please include sokol_gfx.h before overlay_line.glsl.h" +#endif +#if !defined(SOKOL_SHDC_ALIGN) +#if defined(_MSC_VER) +#define SOKOL_SHDC_ALIGN(a) __declspec(align(a)) +#else +#define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) +#endif +#endif +#define UB_overlay_line_ub_frame (0) +#define VIEW_overlay_line_line_instances (0) +#define VIEW_overlay_line_tex_depth (1) +#define SMP_overlay_line_smp_depth (0) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct overlay_line_ub_frame_t { + Mat4 view; + Mat4 proj; + Mat4 view_proj; + Mat4 inv_view_proj; + Vec4 camera_pos; + Vec4 viewport; +} overlay_line_ub_frame_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct overlay_line_line_instance_t { + Vec4 a; + Vec4 b; + Vec4 color; + uint32_t flags[4]; +} overlay_line_line_instance_t; +#pragma pack(pop) +/* + #version 430 + + struct line_instance + { + vec4 a; + vec4 b; + vec4 color; + uvec4 flags; + }; + + layout(binding = 0, std430) readonly buffer line_instances + { + line_instance instances[]; + } _17; + + uniform vec4 ub_frame[18]; + layout(location = 0) out vec2 v_screen_a; + layout(location = 1) out vec2 v_screen_b; + layout(location = 2) noperspective out float v_dist_from_axis_px; + layout(location = 3) out float v_half_width_px; + layout(location = 4) out float v_view_z; + layout(location = 5) flat out vec4 v_color; + layout(location = 6) flat out uint v_occ_mode; + + void main() + { + bool _49 = gl_VertexID == 2; + bool _53 = gl_VertexID == 4; + bool _54 = ((gl_VertexID == 1) || _49) || _53; + float _68 = ((_49 || _53) || (gl_VertexID == 5)) ? 1.0 : (-1.0); + mat4 _86 = mat4(ub_frame[8], ub_frame[9], ub_frame[10], ub_frame[11]); + vec4 _91 = vec4(_17.instances[gl_InstanceID].a.xyz, 1.0); + vec4 _92 = _86 * _91; + vec4 _100 = vec4(_17.instances[gl_InstanceID].b.xyz, 1.0); + vec4 _101 = _86 * _100; + mat4 _104 = mat4(ub_frame[0], ub_frame[1], ub_frame[2], ub_frame[3]); + bvec4 _125 = bvec4(_54); + vec4 _126 = vec4(_125.x ? _101.x : _92.x, _125.y ? _101.y : _92.y, _125.z ? _101.z : _92.z, _125.w ? _101.w : _92.w); + float _129; + if (_54) + { + _129 = (_104 * _100).z; + } + else + { + _129 = (_104 * _91).z; + } + v_screen_a = (((_92.xy / vec2(_92.w)) * 0.5) + vec2(0.5)) * ub_frame[17].xy; + v_screen_b = (((_101.xy / vec2(_101.w)) * 0.5) + vec2(0.5)) * ub_frame[17].xy; + vec2 _181 = v_screen_b - v_screen_a; + float _184 = length(_181); + vec2 _189; + if (_184 > 9.9999999747524270787835121154785e-07) + { + _189 = _181 / vec2(_184); + } + else + { + _189 = vec2(1.0, 0.0); + } + float half_width_px; + if (_17.instances[gl_InstanceID].flags.x == 0u) + { + half_width_px = _17.instances[gl_InstanceID].a.w * 0.5; + } + else + { + half_width_px = (_17.instances[gl_InstanceID].a.w * 0.5) * ((ub_frame[17].y * ub_frame[5].y) / (_129 * (-2.0))); + } + float _237 = half_width_px; + float _238 = max(_237, 0.5); + half_width_px = _238; + float _242 = _238 + 1.5; + vec2 _264 = _126.xy + ((((vec2(-_189.y, _189.x) * _68) * _242) * (ub_frame[17].zw * 2.0)) * _126.w); + vec4 _309 = _126; + _309.x = _264.x; + _309.y = _264.y; + gl_Position = _309; + v_dist_from_axis_px = _68 * _242; + v_half_width_px = _238; + v_view_z = -_129; + v_color = _17.instances[gl_InstanceID].color; + v_occ_mode = _17.instances[gl_InstanceID].flags.y; + } + +*/ +static const uint8_t overlay_line_vs_source_glsl430[2568] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x6c,0x69,0x6e,0x65,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x61,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x62,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x75,0x76,0x65,0x63,0x34,0x20,0x66,0x6c,0x61,0x67,0x73,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67, + 0x20,0x3d,0x20,0x30,0x2c,0x20,0x73,0x74,0x64,0x34,0x33,0x30,0x29,0x20,0x72,0x65, + 0x61,0x64,0x6f,0x6e,0x6c,0x79,0x20,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x6c,0x69, + 0x6e,0x65,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x6c,0x69,0x6e,0x65,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x5d,0x3b,0x0a,0x7d,0x20, + 0x5f,0x31,0x37,0x3b,0x0a,0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65, + 0x63,0x34,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x31,0x38,0x5d,0x3b, + 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x32,0x20,0x76, + 0x5f,0x73,0x63,0x72,0x65,0x65,0x6e,0x5f,0x61,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75, + 0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20, + 0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x32,0x20,0x76,0x5f,0x73,0x63,0x72,0x65,0x65, + 0x6e,0x5f,0x62,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x6e,0x6f,0x70,0x65,0x72,0x73, + 0x70,0x65,0x63,0x74,0x69,0x76,0x65,0x20,0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x76,0x5f,0x64,0x69,0x73,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x61,0x78, + 0x69,0x73,0x5f,0x70,0x78,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f, + 0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x33,0x29,0x20,0x6f,0x75,0x74,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x77,0x69,0x64, + 0x74,0x68,0x5f,0x70,0x78,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f, + 0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x34,0x29,0x20,0x6f,0x75,0x74,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a, + 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20, + 0x3d,0x20,0x35,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x76,0x65, + 0x63,0x34,0x20,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f, + 0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x36,0x29, + 0x20,0x66,0x6c,0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x75,0x69,0x6e,0x74,0x20,0x76, + 0x5f,0x6f,0x63,0x63,0x5f,0x6d,0x6f,0x64,0x65,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64, + 0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f, + 0x6f,0x6c,0x20,0x5f,0x34,0x39,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74, + 0x65,0x78,0x49,0x44,0x20,0x3d,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62, + 0x6f,0x6f,0x6c,0x20,0x5f,0x35,0x33,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x56,0x65,0x72, + 0x74,0x65,0x78,0x49,0x44,0x20,0x3d,0x3d,0x20,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x35,0x34,0x20,0x3d,0x20,0x28,0x28,0x67,0x6c,0x5f, + 0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x44,0x20,0x3d,0x3d,0x20,0x31,0x29,0x20,0x7c, + 0x7c,0x20,0x5f,0x34,0x39,0x29,0x20,0x7c,0x7c,0x20,0x5f,0x35,0x33,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x38,0x20,0x3d,0x20,0x28, + 0x28,0x5f,0x34,0x39,0x20,0x7c,0x7c,0x20,0x5f,0x35,0x33,0x29,0x20,0x7c,0x7c,0x20, + 0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x44,0x20,0x3d,0x3d,0x20, + 0x35,0x29,0x29,0x20,0x3f,0x20,0x31,0x2e,0x30,0x20,0x3a,0x20,0x28,0x2d,0x31,0x2e, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x74,0x34,0x20,0x5f,0x38,0x36, + 0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65, + 0x5b,0x38,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x39,0x5d, + 0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x31,0x30,0x5d,0x2c,0x20, + 0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x31,0x31,0x5d,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x39,0x31,0x20,0x3d,0x20,0x76,0x65, + 0x63,0x34,0x28,0x5f,0x31,0x37,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73, + 0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e, + 0x61,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x39,0x32,0x20,0x3d,0x20,0x5f,0x38,0x36,0x20, + 0x2a,0x20,0x5f,0x39,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20, + 0x5f,0x31,0x30,0x30,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x31,0x37,0x2e, + 0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73, + 0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x62,0x2e,0x78,0x79,0x7a,0x2c,0x20, + 0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f, + 0x31,0x30,0x31,0x20,0x3d,0x20,0x5f,0x38,0x36,0x20,0x2a,0x20,0x5f,0x31,0x30,0x30, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x74,0x34,0x20,0x5f,0x31,0x30,0x34,0x20, + 0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b, + 0x30,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x31,0x5d,0x2c, + 0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x32,0x5d,0x2c,0x20,0x75,0x62, + 0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x33,0x5d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x62,0x76,0x65,0x63,0x34,0x20,0x5f,0x31,0x32,0x35,0x20,0x3d,0x20,0x62,0x76,0x65, + 0x63,0x34,0x28,0x5f,0x35,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x34,0x20,0x5f,0x31,0x32,0x36,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x31, + 0x32,0x35,0x2e,0x78,0x20,0x3f,0x20,0x5f,0x31,0x30,0x31,0x2e,0x78,0x20,0x3a,0x20, + 0x5f,0x39,0x32,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x32,0x35,0x2e,0x79,0x20,0x3f,0x20, + 0x5f,0x31,0x30,0x31,0x2e,0x79,0x20,0x3a,0x20,0x5f,0x39,0x32,0x2e,0x79,0x2c,0x20, + 0x5f,0x31,0x32,0x35,0x2e,0x7a,0x20,0x3f,0x20,0x5f,0x31,0x30,0x31,0x2e,0x7a,0x20, + 0x3a,0x20,0x5f,0x39,0x32,0x2e,0x7a,0x2c,0x20,0x5f,0x31,0x32,0x35,0x2e,0x77,0x20, + 0x3f,0x20,0x5f,0x31,0x30,0x31,0x2e,0x77,0x20,0x3a,0x20,0x5f,0x39,0x32,0x2e,0x77, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32, + 0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x35,0x34,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31, + 0x32,0x39,0x20,0x3d,0x20,0x28,0x5f,0x31,0x30,0x34,0x20,0x2a,0x20,0x5f,0x31,0x30, + 0x30,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x5f,0x31,0x32,0x39,0x20,0x3d,0x20,0x28,0x5f,0x31,0x30,0x34,0x20, + 0x2a,0x20,0x5f,0x39,0x31,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x5f,0x73,0x63,0x72,0x65,0x65,0x6e,0x5f,0x61,0x20,0x3d, + 0x20,0x28,0x28,0x28,0x5f,0x39,0x32,0x2e,0x78,0x79,0x20,0x2f,0x20,0x76,0x65,0x63, + 0x32,0x28,0x5f,0x39,0x32,0x2e,0x77,0x29,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29, + 0x20,0x2b,0x20,0x76,0x65,0x63,0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2a,0x20, + 0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x31,0x37,0x5d,0x2e,0x78,0x79,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x73,0x63,0x72,0x65,0x65,0x6e,0x5f,0x62,0x20, + 0x3d,0x20,0x28,0x28,0x28,0x5f,0x31,0x30,0x31,0x2e,0x78,0x79,0x20,0x2f,0x20,0x76, + 0x65,0x63,0x32,0x28,0x5f,0x31,0x30,0x31,0x2e,0x77,0x29,0x29,0x20,0x2a,0x20,0x30, + 0x2e,0x35,0x29,0x20,0x2b,0x20,0x76,0x65,0x63,0x32,0x28,0x30,0x2e,0x35,0x29,0x29, + 0x20,0x2a,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x31,0x37,0x5d,0x2e, + 0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x31,0x38, + 0x31,0x20,0x3d,0x20,0x76,0x5f,0x73,0x63,0x72,0x65,0x65,0x6e,0x5f,0x62,0x20,0x2d, + 0x20,0x76,0x5f,0x73,0x63,0x72,0x65,0x65,0x6e,0x5f,0x61,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x38,0x34,0x20,0x3d,0x20,0x6c,0x65, + 0x6e,0x67,0x74,0x68,0x28,0x5f,0x31,0x38,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x65,0x63,0x32,0x20,0x5f,0x31,0x38,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x5f,0x31,0x38,0x34,0x20,0x3e,0x20,0x39,0x2e,0x39,0x39,0x39,0x39, + 0x39,0x39,0x39,0x37,0x34,0x37,0x35,0x32,0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38, + 0x33,0x35,0x31,0x32,0x31,0x31,0x35,0x34,0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f, + 0x31,0x38,0x39,0x20,0x3d,0x20,0x5f,0x31,0x38,0x31,0x20,0x2f,0x20,0x76,0x65,0x63, + 0x32,0x28,0x5f,0x31,0x38,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x38,0x39,0x20,0x3d,0x20,0x76,0x65,0x63, + 0x32,0x28,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x68,0x61,0x6c, + 0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x5f,0x31,0x37,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d, + 0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x30,0x75,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x68,0x61, + 0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x20,0x3d,0x20,0x5f,0x31, + 0x37,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x67,0x6c,0x5f,0x49, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x61,0x2e,0x77,0x20,0x2a, + 0x20,0x30,0x2e,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x68,0x61,0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78, + 0x20,0x3d,0x20,0x28,0x5f,0x31,0x37,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d, + 0x2e,0x61,0x2e,0x77,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2a,0x20,0x28,0x28, + 0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x31,0x37,0x5d,0x2e,0x79,0x20,0x2a, + 0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x35,0x5d,0x2e,0x79,0x29,0x20, + 0x2f,0x20,0x28,0x5f,0x31,0x32,0x39,0x20,0x2a,0x20,0x28,0x2d,0x32,0x2e,0x30,0x29, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x32,0x33,0x37,0x20,0x3d,0x20,0x68,0x61,0x6c,0x66,0x5f, + 0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x32,0x33,0x38,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x5f, + 0x32,0x33,0x37,0x2c,0x20,0x30,0x2e,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x68, + 0x61,0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x20,0x3d,0x20,0x5f, + 0x32,0x33,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x32,0x34,0x32,0x20,0x3d,0x20,0x5f,0x32,0x33,0x38,0x20,0x2b,0x20,0x31,0x2e,0x35, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x32,0x36,0x34,0x20, + 0x3d,0x20,0x5f,0x31,0x32,0x36,0x2e,0x78,0x79,0x20,0x2b,0x20,0x28,0x28,0x28,0x28, + 0x76,0x65,0x63,0x32,0x28,0x2d,0x5f,0x31,0x38,0x39,0x2e,0x79,0x2c,0x20,0x5f,0x31, + 0x38,0x39,0x2e,0x78,0x29,0x20,0x2a,0x20,0x5f,0x36,0x38,0x29,0x20,0x2a,0x20,0x5f, + 0x32,0x34,0x32,0x29,0x20,0x2a,0x20,0x28,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65, + 0x5b,0x31,0x37,0x5d,0x2e,0x7a,0x77,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x29,0x20, + 0x2a,0x20,0x5f,0x31,0x32,0x36,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x34,0x20,0x5f,0x33,0x30,0x39,0x20,0x3d,0x20,0x5f,0x31,0x32,0x36,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x30,0x39,0x2e,0x78,0x20,0x3d,0x20,0x5f,0x32, + 0x36,0x34,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x30,0x39,0x2e,0x79, + 0x20,0x3d,0x20,0x5f,0x32,0x36,0x34,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67, + 0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x5f,0x33,0x30, + 0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x64,0x69,0x73,0x74,0x5f,0x66,0x72, + 0x6f,0x6d,0x5f,0x61,0x78,0x69,0x73,0x5f,0x70,0x78,0x20,0x3d,0x20,0x5f,0x36,0x38, + 0x20,0x2a,0x20,0x5f,0x32,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x68, + 0x61,0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x20,0x3d,0x20,0x5f, + 0x32,0x33,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x7a,0x20,0x3d,0x20,0x2d,0x5f,0x31,0x32,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x5f,0x31,0x37,0x2e,0x69,0x6e,0x73, + 0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x49,0x44,0x5d,0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x5f,0x6f,0x63,0x63,0x5f,0x6d,0x6f,0x64,0x65,0x20,0x3d,0x20,0x5f,0x31, + 0x37,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x67,0x6c,0x5f,0x49, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x66,0x6c,0x61,0x67,0x73, + 0x2e,0x79,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + #version 430 + + layout(binding = 0) uniform sampler2D tex_depth_smp_depth; + + layout(location = 2) noperspective in float v_dist_from_axis_px; + layout(location = 3) in float v_half_width_px; + layout(location = 4) in float v_view_z; + layout(location = 5) flat in vec4 v_color; + layout(location = 6) flat in uint v_occ_mode; + layout(location = 1) in vec2 v_screen_b; + layout(location = 0) in vec2 v_screen_a; + layout(location = 0) out vec4 out_color; + + void main() + { + float _15 = fwidth(v_dist_from_axis_px); + float _68 = fwidth(v_view_z); + bool _78 = v_view_z > (textureLod(tex_depth_smp_depth, gl_FragCoord.xy / vec2(textureSize(tex_depth_smp_depth, 0)), 0.0).x + (0.001000000047497451305389404296875 + (2.0 * _68))); + vec4 col = v_color; + if ((v_occ_mode == 0u) && _78) + { + col = vec4(0.0); + } + else + { + if ((v_occ_mode == 1u) && _78) + { + col *= 0.25; + } + else + { + if ((v_occ_mode == 2u) && _78) + { + vec2 _117 = v_screen_b - v_screen_a; + float _136 = dot(gl_FragCoord.xy - v_screen_a, _117 / vec2(max(length(_117), 9.9999999747524270787835121154785e-07))); + float _149 = fwidth(_136); + col *= (1.0 - smoothstep(-_149, _149, abs(mod(_136, 16.0) - 4.0) - 4.0)); + } + } + } + out_color = col * (1.0 - smoothstep(v_half_width_px - _15, v_half_width_px + _15, abs(v_dist_from_axis_px))); + } + +*/ +static const uint8_t overlay_line_fs_source_glsl430[1459] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x30, + 0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, + 0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x73,0x6d, + 0x70,0x5f,0x64,0x65,0x70,0x74,0x68,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, + 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x6e, + 0x6f,0x70,0x65,0x72,0x73,0x70,0x65,0x63,0x74,0x69,0x76,0x65,0x20,0x69,0x6e,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x64,0x69,0x73,0x74,0x5f,0x66,0x72,0x6f, + 0x6d,0x5f,0x61,0x78,0x69,0x73,0x5f,0x70,0x78,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75, + 0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x33,0x29,0x20, + 0x69,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f, + 0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, + 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x34,0x29,0x20,0x69, + 0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a, + 0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f, + 0x6e,0x20,0x3d,0x20,0x35,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76, + 0x65,0x63,0x34,0x20,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79, + 0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x36, + 0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x75,0x69,0x6e,0x74,0x20,0x76, + 0x5f,0x6f,0x63,0x63,0x5f,0x6d,0x6f,0x64,0x65,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75, + 0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20, + 0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x76,0x5f,0x73,0x63,0x72,0x65,0x65,0x6e, + 0x5f,0x62,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74, + 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x32, + 0x20,0x76,0x5f,0x73,0x63,0x72,0x65,0x65,0x6e,0x5f,0x61,0x3b,0x0a,0x6c,0x61,0x79, + 0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30, + 0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e, + 0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x35,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x76,0x5f,0x64,0x69, + 0x73,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x61,0x78,0x69,0x73,0x5f,0x70,0x78,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x38,0x20, + 0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x37,0x38, + 0x20,0x3d,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3e,0x20,0x28,0x74, + 0x65,0x78,0x74,0x75,0x72,0x65,0x4c,0x6f,0x64,0x28,0x74,0x65,0x78,0x5f,0x64,0x65, + 0x70,0x74,0x68,0x5f,0x73,0x6d,0x70,0x5f,0x64,0x65,0x70,0x74,0x68,0x2c,0x20,0x67, + 0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x20,0x2f, + 0x20,0x76,0x65,0x63,0x32,0x28,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x53,0x69,0x7a, + 0x65,0x28,0x74,0x65,0x78,0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x73,0x6d,0x70,0x5f, + 0x64,0x65,0x70,0x74,0x68,0x2c,0x20,0x30,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29, + 0x2e,0x78,0x20,0x2b,0x20,0x28,0x30,0x2e,0x30,0x30,0x31,0x30,0x30,0x30,0x30,0x30, + 0x30,0x30,0x34,0x37,0x34,0x39,0x37,0x34,0x35,0x31,0x33,0x30,0x35,0x33,0x38,0x39, + 0x34,0x30,0x34,0x32,0x39,0x36,0x38,0x37,0x35,0x20,0x2b,0x20,0x28,0x32,0x2e,0x30, + 0x20,0x2a,0x20,0x5f,0x36,0x38,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x20,0x3d,0x20,0x76,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x76,0x5f,0x6f,0x63, + 0x63,0x5f,0x6d,0x6f,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x75,0x29,0x20,0x26,0x26, + 0x20,0x5f,0x37,0x38,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x30, + 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65, + 0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x76,0x5f,0x6f,0x63,0x63,0x5f,0x6d,0x6f,0x64, + 0x65,0x20,0x3d,0x3d,0x20,0x31,0x75,0x29,0x20,0x26,0x26,0x20,0x5f,0x37,0x38,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x20,0x2a,0x3d,0x20,0x30,0x2e, + 0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x28,0x76,0x5f,0x6f,0x63,0x63,0x5f,0x6d,0x6f,0x64,0x65, + 0x20,0x3d,0x3d,0x20,0x32,0x75,0x29,0x20,0x26,0x26,0x20,0x5f,0x37,0x38,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x32,0x20,0x5f,0x31,0x31,0x37,0x20,0x3d,0x20,0x76,0x5f,0x73,0x63,0x72,0x65, + 0x65,0x6e,0x5f,0x62,0x20,0x2d,0x20,0x76,0x5f,0x73,0x63,0x72,0x65,0x65,0x6e,0x5f, + 0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x36,0x20,0x3d,0x20, + 0x64,0x6f,0x74,0x28,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64, + 0x2e,0x78,0x79,0x20,0x2d,0x20,0x76,0x5f,0x73,0x63,0x72,0x65,0x65,0x6e,0x5f,0x61, + 0x2c,0x20,0x5f,0x31,0x31,0x37,0x20,0x2f,0x20,0x76,0x65,0x63,0x32,0x28,0x6d,0x61, + 0x78,0x28,0x6c,0x65,0x6e,0x67,0x74,0x68,0x28,0x5f,0x31,0x31,0x37,0x29,0x2c,0x20, + 0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x35,0x32,0x34,0x32, + 0x37,0x30,0x37,0x38,0x37,0x38,0x33,0x35,0x31,0x32,0x31,0x31,0x35,0x34,0x37,0x38, + 0x35,0x65,0x2d,0x30,0x37,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x34,0x39,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31, + 0x33,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x20,0x2a,0x3d,0x20,0x28,0x31,0x2e,0x30, + 0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x2d,0x5f, + 0x31,0x34,0x39,0x2c,0x20,0x5f,0x31,0x34,0x39,0x2c,0x20,0x61,0x62,0x73,0x28,0x6d, + 0x6f,0x64,0x28,0x5f,0x31,0x33,0x36,0x2c,0x20,0x31,0x36,0x2e,0x30,0x29,0x20,0x2d, + 0x20,0x34,0x2e,0x30,0x29,0x20,0x2d,0x20,0x34,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c, + 0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68, + 0x73,0x74,0x65,0x70,0x28,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x77,0x69,0x64,0x74, + 0x68,0x5f,0x70,0x78,0x20,0x2d,0x20,0x5f,0x31,0x35,0x2c,0x20,0x76,0x5f,0x68,0x61, + 0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x20,0x2b,0x20,0x5f,0x31, + 0x35,0x2c,0x20,0x61,0x62,0x73,0x28,0x76,0x5f,0x64,0x69,0x73,0x74,0x5f,0x66,0x72, + 0x6f,0x6d,0x5f,0x61,0x78,0x69,0x73,0x5f,0x70,0x78,0x29,0x29,0x29,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x00, +}; +/* + struct line_instance + { + float4 a; + float4 b; + float4 color; + uint4 flags; + }; + + ByteAddressBuffer _17 : register(t0); + cbuffer ub_frame : register(b0) + { + row_major float4x4 _83_view : packoffset(c0); + row_major float4x4 _83_proj : packoffset(c4); + row_major float4x4 _83_view_proj : packoffset(c8); + row_major float4x4 _83_inv_view_proj : packoffset(c12); + float4 _83_camera_pos : packoffset(c16); + float4 _83_viewport : packoffset(c17); + }; + + + static float4 gl_Position; + static int gl_VertexIndex; + static int gl_InstanceIndex; + static float2 v_screen_a; + static float2 v_screen_b; + static float v_dist_from_axis_px; + static float v_half_width_px; + static float v_view_z; + static float4 v_color; + static uint v_occ_mode; + + struct SPIRV_Cross_Input + { + uint gl_VertexIndex : SV_VertexID; + uint gl_InstanceIndex : SV_InstanceID; + }; + + struct SPIRV_Cross_Output + { + float2 v_screen_a : TEXCOORD0; + float2 v_screen_b : TEXCOORD1; + noperspective float v_dist_from_axis_px : TEXCOORD2; + float v_half_width_px : TEXCOORD3; + float v_view_z : TEXCOORD4; + nointerpolation float4 v_color : TEXCOORD5; + nointerpolation uint v_occ_mode : TEXCOORD6; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + line_instance _25; + _25.a = asfloat(_17.Load4(gl_InstanceIndex * 64 + 0)); + _25.b = asfloat(_17.Load4(gl_InstanceIndex * 64 + 16)); + _25.color = asfloat(_17.Load4(gl_InstanceIndex * 64 + 32)); + _25.flags = _17.Load4(gl_InstanceIndex * 64 + 48); + bool _49 = gl_VertexIndex == 2; + bool _53 = gl_VertexIndex == 4; + bool _54 = ((gl_VertexIndex == 1) || _49) || _53; + float _68 = ((_49 || _53) || (gl_VertexIndex == 5)) ? 1.0f : (-1.0f); + float4 _91 = float4(_25.a.xyz, 1.0f); + float4 _92 = mul(_91, _83_view_proj); + float4 _100 = float4(_25.b.xyz, 1.0f); + float4 _101 = mul(_100, _83_view_proj); + bool4 _125 = _54.xxxx; + float4 _126 = float4(_125.x ? _101.x : _92.x, _125.y ? _101.y : _92.y, _125.z ? _101.z : _92.z, _125.w ? _101.w : _92.w); + float _129; + if (_54) + { + _129 = mul(_100, _83_view).z; + } + else + { + _129 = mul(_91, _83_view).z; + } + v_screen_a = (((_92.xy / _92.w.xx) * 0.5f) + 0.5f.xx) * _83_viewport.xy; + v_screen_b = (((_101.xy / _101.w.xx) * 0.5f) + 0.5f.xx) * _83_viewport.xy; + float2 _181 = v_screen_b - v_screen_a; + float _184 = length(_181); + float2 _189; + if (_184 > 9.9999999747524270787835121154785e-07f) + { + _189 = _181 / _184.xx; + } + else + { + _189 = float2(1.0f, 0.0f); + } + float half_width_px; + if (_25.flags.x == 0u) + { + half_width_px = _25.a.w * 0.5f; + } + else + { + half_width_px = (_25.a.w * 0.5f) * ((_83_viewport.y * _83_proj[1].y) / (_129 * (-2.0f))); + } + float _237 = half_width_px; + float _238 = max(_237, 0.5f); + half_width_px = _238; + float _242 = _238 + 1.5f; + float2 _264 = _126.xy + ((((float2(-_189.y, _189.x) * _68) * _242) * (_83_viewport.zw * 2.0f)) * _126.w); + float4 _309 = _126; + _309.x = _264.x; + _309.y = _264.y; + gl_Position = _309; + v_dist_from_axis_px = _68 * _242; + v_half_width_px = _238; + v_view_z = -_129; + v_color = _25.color; + v_occ_mode = _25.flags.y; + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_VertexIndex = int(stage_input.gl_VertexIndex); + gl_InstanceIndex = int(stage_input.gl_InstanceIndex); + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.v_screen_a = v_screen_a; + stage_output.v_screen_b = v_screen_b; + stage_output.v_dist_from_axis_px = v_dist_from_axis_px; + stage_output.v_half_width_px = v_half_width_px; + stage_output.v_view_z = v_view_z; + stage_output.v_color = v_color; + stage_output.v_occ_mode = v_occ_mode; + return stage_output; + } +*/ +static const uint8_t overlay_line_vs_source_hlsl5[3858] = { + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6c,0x69,0x6e,0x65,0x5f,0x69,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x62,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f, + 0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x34,0x20,0x66, + 0x6c,0x61,0x67,0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x42,0x79,0x74,0x65,0x41,0x64, + 0x64,0x72,0x65,0x73,0x73,0x42,0x75,0x66,0x66,0x65,0x72,0x20,0x5f,0x31,0x37,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x30,0x29,0x3b,0x0a, + 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65, + 0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x38,0x33,0x5f,0x76,0x69,0x65, + 0x77,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f, + 0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x38,0x33,0x5f,0x70, + 0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74, + 0x28,0x63,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61, + 0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x38,0x33, + 0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61,0x63, + 0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x78,0x34,0x20,0x5f,0x38,0x33,0x5f,0x69,0x6e,0x76,0x5f,0x76,0x69,0x65,0x77, + 0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73, + 0x65,0x74,0x28,0x63,0x31,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x5f,0x38,0x33,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70, + 0x6f,0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28, + 0x63,0x31,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x5f,0x38,0x33,0x5f,0x76,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x20,0x3a,0x20, + 0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x37,0x29,0x3b, + 0x0a,0x7d,0x3b,0x0a,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b, + 0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x56, + 0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74, + 0x69,0x63,0x20,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x76,0x5f,0x73,0x63,0x72,0x65,0x65,0x6e,0x5f, + 0x61,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, + 0x20,0x76,0x5f,0x73,0x63,0x72,0x65,0x65,0x6e,0x5f,0x62,0x3b,0x0a,0x73,0x74,0x61, + 0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x64,0x69,0x73,0x74, + 0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x61,0x78,0x69,0x73,0x5f,0x70,0x78,0x3b,0x0a,0x73, + 0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x68,0x61, + 0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x3b,0x0a,0x73,0x74,0x61, + 0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x76,0x69,0x65,0x77, + 0x5f,0x7a,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69, + 0x63,0x20,0x75,0x69,0x6e,0x74,0x20,0x76,0x5f,0x6f,0x63,0x63,0x5f,0x6d,0x6f,0x64, + 0x65,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56, + 0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65, + 0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x3a,0x20,0x53,0x56,0x5f,0x56,0x65,0x72,0x74, + 0x65,0x78,0x49,0x44,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x67, + 0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20, + 0x3a,0x20,0x53,0x56,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x3b, + 0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52, + 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x76,0x5f,0x73,0x63, + 0x72,0x65,0x65,0x6e,0x5f,0x61,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52, + 0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x76, + 0x5f,0x73,0x63,0x72,0x65,0x65,0x6e,0x5f,0x62,0x20,0x3a,0x20,0x54,0x45,0x58,0x43, + 0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x70,0x65,0x72, + 0x73,0x70,0x65,0x63,0x74,0x69,0x76,0x65,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76, + 0x5f,0x64,0x69,0x73,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x61,0x78,0x69,0x73,0x5f, + 0x70,0x78,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x32,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66, + 0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x20,0x3a,0x20,0x54,0x45,0x58,0x43, + 0x4f,0x4f,0x52,0x44,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3a,0x20,0x54,0x45,0x58,0x43, + 0x4f,0x4f,0x52,0x44,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74, + 0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x54,0x45,0x58,0x43, + 0x4f,0x4f,0x52,0x44,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74, + 0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x75,0x69,0x6e,0x74,0x20, + 0x76,0x5f,0x6f,0x63,0x63,0x5f,0x6d,0x6f,0x64,0x65,0x20,0x3a,0x20,0x54,0x45,0x58, + 0x43,0x4f,0x4f,0x52,0x44,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a, + 0x20,0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e, + 0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6c,0x69,0x6e,0x65,0x5f,0x69,0x6e, + 0x73,0x74,0x61,0x6e,0x63,0x65,0x20,0x5f,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x5f,0x32,0x35,0x2e,0x61,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28, + 0x5f,0x31,0x37,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73, + 0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x2a,0x20,0x36,0x34,0x20, + 0x2b,0x20,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x32,0x35,0x2e,0x62, + 0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x37,0x2e,0x4c, + 0x6f,0x61,0x64,0x34,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x49,0x6e,0x64,0x65,0x78,0x20,0x2a,0x20,0x36,0x34,0x20,0x2b,0x20,0x31,0x36,0x29, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x32,0x35,0x2e,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x37,0x2e,0x4c, + 0x6f,0x61,0x64,0x34,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x49,0x6e,0x64,0x65,0x78,0x20,0x2a,0x20,0x36,0x34,0x20,0x2b,0x20,0x33,0x32,0x29, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x32,0x35,0x2e,0x66,0x6c,0x61,0x67,0x73, + 0x20,0x3d,0x20,0x5f,0x31,0x37,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x67,0x6c,0x5f, + 0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x2a,0x20, + 0x36,0x34,0x20,0x2b,0x20,0x34,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f, + 0x6f,0x6c,0x20,0x5f,0x34,0x39,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74, + 0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x3d,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x35,0x33,0x20,0x3d,0x20,0x67,0x6c,0x5f, + 0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x3d,0x3d,0x20,0x34, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x35,0x34,0x20,0x3d, + 0x20,0x28,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65, + 0x78,0x20,0x3d,0x3d,0x20,0x31,0x29,0x20,0x7c,0x7c,0x20,0x5f,0x34,0x39,0x29,0x20, + 0x7c,0x7c,0x20,0x5f,0x35,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x36,0x38,0x20,0x3d,0x20,0x28,0x28,0x5f,0x34,0x39,0x20,0x7c,0x7c, + 0x20,0x5f,0x35,0x33,0x29,0x20,0x7c,0x7c,0x20,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72, + 0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x3d,0x3d,0x20,0x35,0x29,0x29,0x20, + 0x3f,0x20,0x31,0x2e,0x30,0x66,0x20,0x3a,0x20,0x28,0x2d,0x31,0x2e,0x30,0x66,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x39,0x31, + 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x32,0x35,0x2e,0x61,0x2e, + 0x78,0x79,0x7a,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x39,0x32,0x20,0x3d,0x20,0x6d,0x75,0x6c, + 0x28,0x5f,0x39,0x31,0x2c,0x20,0x5f,0x38,0x33,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70, + 0x72,0x6f,0x6a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x5f,0x31,0x30,0x30,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f, + 0x32,0x35,0x2e,0x62,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x30,0x31, + 0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x5f,0x31,0x30,0x30,0x2c,0x20,0x5f,0x38,0x33, + 0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x62,0x6f,0x6f,0x6c,0x34,0x20,0x5f,0x31,0x32,0x35,0x20,0x3d,0x20,0x5f,0x35, + 0x34,0x2e,0x78,0x78,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x5f,0x31,0x32,0x36,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x28,0x5f,0x31,0x32,0x35,0x2e,0x78,0x20,0x3f,0x20,0x5f,0x31,0x30,0x31,0x2e,0x78, + 0x20,0x3a,0x20,0x5f,0x39,0x32,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x32,0x35,0x2e,0x79, + 0x20,0x3f,0x20,0x5f,0x31,0x30,0x31,0x2e,0x79,0x20,0x3a,0x20,0x5f,0x39,0x32,0x2e, + 0x79,0x2c,0x20,0x5f,0x31,0x32,0x35,0x2e,0x7a,0x20,0x3f,0x20,0x5f,0x31,0x30,0x31, + 0x2e,0x7a,0x20,0x3a,0x20,0x5f,0x39,0x32,0x2e,0x7a,0x2c,0x20,0x5f,0x31,0x32,0x35, + 0x2e,0x77,0x20,0x3f,0x20,0x5f,0x31,0x30,0x31,0x2e,0x77,0x20,0x3a,0x20,0x5f,0x39, + 0x32,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x32,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x35, + 0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x5f,0x31,0x32,0x39,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x5f,0x31,0x30,0x30, + 0x2c,0x20,0x5f,0x38,0x33,0x5f,0x76,0x69,0x65,0x77,0x29,0x2e,0x7a,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x32,0x39, + 0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x5f,0x39,0x31,0x2c,0x20,0x5f,0x38,0x33,0x5f, + 0x76,0x69,0x65,0x77,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x5f,0x73,0x63,0x72,0x65,0x65,0x6e,0x5f,0x61,0x20,0x3d,0x20, + 0x28,0x28,0x28,0x5f,0x39,0x32,0x2e,0x78,0x79,0x20,0x2f,0x20,0x5f,0x39,0x32,0x2e, + 0x77,0x2e,0x78,0x78,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20, + 0x30,0x2e,0x35,0x66,0x2e,0x78,0x78,0x29,0x20,0x2a,0x20,0x5f,0x38,0x33,0x5f,0x76, + 0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x2e,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x5f,0x73,0x63,0x72,0x65,0x65,0x6e,0x5f,0x62,0x20,0x3d,0x20,0x28,0x28,0x28, + 0x5f,0x31,0x30,0x31,0x2e,0x78,0x79,0x20,0x2f,0x20,0x5f,0x31,0x30,0x31,0x2e,0x77, + 0x2e,0x78,0x78,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30, + 0x2e,0x35,0x66,0x2e,0x78,0x78,0x29,0x20,0x2a,0x20,0x5f,0x38,0x33,0x5f,0x76,0x69, + 0x65,0x77,0x70,0x6f,0x72,0x74,0x2e,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x31,0x38,0x31,0x20,0x3d,0x20,0x76,0x5f,0x73, + 0x63,0x72,0x65,0x65,0x6e,0x5f,0x62,0x20,0x2d,0x20,0x76,0x5f,0x73,0x63,0x72,0x65, + 0x65,0x6e,0x5f,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x38,0x34,0x20,0x3d,0x20,0x6c,0x65,0x6e,0x67,0x74,0x68,0x28,0x5f,0x31, + 0x38,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20, + 0x5f,0x31,0x38,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31, + 0x38,0x34,0x20,0x3e,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34, + 0x37,0x35,0x32,0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38,0x33,0x35,0x31,0x32,0x31, + 0x31,0x35,0x34,0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x66,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x38,0x39,0x20, + 0x3d,0x20,0x5f,0x31,0x38,0x31,0x20,0x2f,0x20,0x5f,0x31,0x38,0x34,0x2e,0x78,0x78, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f, + 0x31,0x38,0x39,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x31,0x2e,0x30, + 0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x68,0x61,0x6c,0x66,0x5f,0x77, + 0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x5f,0x32,0x35,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20, + 0x30,0x75,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x68,0x61,0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x20, + 0x3d,0x20,0x5f,0x32,0x35,0x2e,0x61,0x2e,0x77,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x68, + 0x61,0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x20,0x3d,0x20,0x28, + 0x5f,0x32,0x35,0x2e,0x61,0x2e,0x77,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20, + 0x2a,0x20,0x28,0x28,0x5f,0x38,0x33,0x5f,0x76,0x69,0x65,0x77,0x70,0x6f,0x72,0x74, + 0x2e,0x79,0x20,0x2a,0x20,0x5f,0x38,0x33,0x5f,0x70,0x72,0x6f,0x6a,0x5b,0x31,0x5d, + 0x2e,0x79,0x29,0x20,0x2f,0x20,0x28,0x5f,0x31,0x32,0x39,0x20,0x2a,0x20,0x28,0x2d, + 0x32,0x2e,0x30,0x66,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x33,0x37,0x20,0x3d,0x20, + 0x68,0x61,0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x33,0x38,0x20,0x3d,0x20, + 0x6d,0x61,0x78,0x28,0x5f,0x32,0x33,0x37,0x2c,0x20,0x30,0x2e,0x35,0x66,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x68,0x61,0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f, + 0x70,0x78,0x20,0x3d,0x20,0x5f,0x32,0x33,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x34,0x32,0x20,0x3d,0x20,0x5f,0x32,0x33,0x38, + 0x20,0x2b,0x20,0x31,0x2e,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x32,0x20,0x5f,0x32,0x36,0x34,0x20,0x3d,0x20,0x5f,0x31,0x32,0x36,0x2e, + 0x78,0x79,0x20,0x2b,0x20,0x28,0x28,0x28,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28, + 0x2d,0x5f,0x31,0x38,0x39,0x2e,0x79,0x2c,0x20,0x5f,0x31,0x38,0x39,0x2e,0x78,0x29, + 0x20,0x2a,0x20,0x5f,0x36,0x38,0x29,0x20,0x2a,0x20,0x5f,0x32,0x34,0x32,0x29,0x20, + 0x2a,0x20,0x28,0x5f,0x38,0x33,0x5f,0x76,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x2e, + 0x7a,0x77,0x20,0x2a,0x20,0x32,0x2e,0x30,0x66,0x29,0x29,0x20,0x2a,0x20,0x5f,0x31, + 0x32,0x36,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x5f,0x33,0x30,0x39,0x20,0x3d,0x20,0x5f,0x31,0x32,0x36,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x5f,0x33,0x30,0x39,0x2e,0x78,0x20,0x3d,0x20,0x5f,0x32,0x36,0x34, + 0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x30,0x39,0x2e,0x79,0x20,0x3d, + 0x20,0x5f,0x32,0x36,0x34,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f, + 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x5f,0x33,0x30,0x39,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x64,0x69,0x73,0x74,0x5f,0x66,0x72,0x6f,0x6d, + 0x5f,0x61,0x78,0x69,0x73,0x5f,0x70,0x78,0x20,0x3d,0x20,0x5f,0x36,0x38,0x20,0x2a, + 0x20,0x5f,0x32,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x68,0x61,0x6c, + 0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x20,0x3d,0x20,0x5f,0x32,0x33, + 0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20, + 0x3d,0x20,0x2d,0x5f,0x31,0x32,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x5f,0x32,0x35,0x2e,0x63,0x6f,0x6c,0x6f,0x72, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x6f,0x63,0x63,0x5f,0x6d,0x6f,0x64,0x65, + 0x20,0x3d,0x20,0x5f,0x32,0x35,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x79,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f, + 0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56, + 0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x3d, + 0x20,0x69,0x6e,0x74,0x28,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74, + 0x2e,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x3d,0x20,0x69,0x6e,0x74,0x28,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74, + 0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70, + 0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d, + 0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76, + 0x5f,0x73,0x63,0x72,0x65,0x65,0x6e,0x5f,0x61,0x20,0x3d,0x20,0x76,0x5f,0x73,0x63, + 0x72,0x65,0x65,0x6e,0x5f,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67, + 0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x73,0x63,0x72,0x65,0x65, + 0x6e,0x5f,0x62,0x20,0x3d,0x20,0x76,0x5f,0x73,0x63,0x72,0x65,0x65,0x6e,0x5f,0x62, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70, + 0x75,0x74,0x2e,0x76,0x5f,0x64,0x69,0x73,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x61, + 0x78,0x69,0x73,0x5f,0x70,0x78,0x20,0x3d,0x20,0x76,0x5f,0x64,0x69,0x73,0x74,0x5f, + 0x66,0x72,0x6f,0x6d,0x5f,0x61,0x78,0x69,0x73,0x5f,0x70,0x78,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76, + 0x5f,0x68,0x61,0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x20,0x3d, + 0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70, + 0x75,0x74,0x2e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3d,0x20,0x76,0x5f, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67, + 0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x3d,0x20,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x6f, + 0x63,0x63,0x5f,0x6d,0x6f,0x64,0x65,0x20,0x3d,0x20,0x76,0x5f,0x6f,0x63,0x63,0x5f, + 0x6d,0x6f,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d, + 0x0a,0x00, +}; +/* + Texture2D tex_depth : register(t0); + SamplerState smp_depth : register(s0); + + static float4 gl_FragCoord; + static float v_dist_from_axis_px; + static float v_half_width_px; + static float v_view_z; + static float4 v_color; + static uint v_occ_mode; + static float2 v_screen_b; + static float2 v_screen_a; + static float4 out_color; + + struct SPIRV_Cross_Input + { + float2 v_screen_a : TEXCOORD0; + float2 v_screen_b : TEXCOORD1; + noperspective float v_dist_from_axis_px : TEXCOORD2; + float v_half_width_px : TEXCOORD3; + float v_view_z : TEXCOORD4; + nointerpolation float4 v_color : TEXCOORD5; + nointerpolation uint v_occ_mode : TEXCOORD6; + float4 gl_FragCoord : SV_Position; + }; + + struct SPIRV_Cross_Output + { + float4 out_color : SV_Target0; + }; + + float mod(float x, float y) + { + return x - y * floor(x / y); + } + + float2 mod(float2 x, float2 y) + { + return x - y * floor(x / y); + } + + float3 mod(float3 x, float3 y) + { + return x - y * floor(x / y); + } + + float4 mod(float4 x, float4 y) + { + return x - y * floor(x / y); + } + + uint2 spvTextureSize(Texture2D Tex, uint Level, out uint Param) + { + uint2 ret; + Tex.GetDimensions(Level, ret.x, ret.y, Param); + return ret; + } + + void frag_main() + { + float _15 = fwidth(v_dist_from_axis_px); + uint _50_dummy_parameter; + float _68 = fwidth(v_view_z); + bool _78 = v_view_z > (tex_depth.SampleLevel(smp_depth, gl_FragCoord.xy / float2(int2(spvTextureSize(tex_depth, uint(0), _50_dummy_parameter))), 0.0f).x + (0.001000000047497451305389404296875f + (2.0f * _68))); + float4 col = v_color; + if ((v_occ_mode == 0u) && _78) + { + col = 0.0f.xxxx; + } + else + { + if ((v_occ_mode == 1u) && _78) + { + col *= 0.25f; + } + else + { + if ((v_occ_mode == 2u) && _78) + { + float2 _117 = v_screen_b - v_screen_a; + float _136 = dot(gl_FragCoord.xy - v_screen_a, _117 / max(length(_117), 9.9999999747524270787835121154785e-07f).xx); + float _149 = fwidth(_136); + col *= (1.0f - smoothstep(-_149, _149, abs(mod(_136, 16.0f) - 4.0f) - 4.0f)); + } + } + } + out_color = col * (1.0f - smoothstep(v_half_width_px - _15, v_half_width_px + _15, abs(v_dist_from_axis_px))); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_FragCoord = stage_input.gl_FragCoord; + gl_FragCoord.w = 1.0 / gl_FragCoord.w; + v_dist_from_axis_px = stage_input.v_dist_from_axis_px; + v_half_width_px = stage_input.v_half_width_px; + v_view_z = stage_input.v_view_z; + v_color = stage_input.v_color; + v_occ_mode = stage_input.v_occ_mode; + v_screen_b = stage_input.v_screen_b; + v_screen_a = stage_input.v_screen_a; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.out_color = out_color; + return stage_output; + } +*/ +static const uint8_t overlay_line_fs_source_hlsl5[2854] = { + 0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x3e,0x20,0x74,0x65,0x78,0x5f,0x64,0x65,0x70,0x74,0x68,0x20,0x3a,0x20,0x72,0x65, + 0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x30,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70, + 0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x64,0x65,0x70, + 0x74,0x68,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x30, + 0x29,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x3b,0x0a, + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x64, + 0x69,0x73,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x61,0x78,0x69,0x73,0x5f,0x70,0x78, + 0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76, + 0x5f,0x68,0x61,0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x3b,0x0a, + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x73,0x74, + 0x61,0x74,0x69,0x63,0x20,0x75,0x69,0x6e,0x74,0x20,0x76,0x5f,0x6f,0x63,0x63,0x5f, + 0x6d,0x6f,0x64,0x65,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x32,0x20,0x76,0x5f,0x73,0x63,0x72,0x65,0x65,0x6e,0x5f,0x62,0x3b,0x0a, + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x76,0x5f, + 0x73,0x63,0x72,0x65,0x65,0x6e,0x5f,0x61,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56, + 0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x76,0x5f,0x73,0x63,0x72,0x65, + 0x65,0x6e,0x5f,0x61,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x76,0x5f,0x73, + 0x63,0x72,0x65,0x65,0x6e,0x5f,0x62,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f, + 0x52,0x44,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x70,0x65,0x72,0x73,0x70, + 0x65,0x63,0x74,0x69,0x76,0x65,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x64, + 0x69,0x73,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x61,0x78,0x69,0x73,0x5f,0x70,0x78, + 0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x32,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x77, + 0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f, + 0x52,0x44,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76, + 0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f, + 0x52,0x44,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72, + 0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f, + 0x52,0x44,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72, + 0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x75,0x69,0x6e,0x74,0x20,0x76,0x5f, + 0x6f,0x63,0x63,0x5f,0x6d,0x6f,0x64,0x65,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f, + 0x4f,0x52,0x44,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x20,0x3a,0x20, + 0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a, + 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, + 0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x20,0x3a,0x20,0x53,0x56,0x5f,0x54,0x61,0x72,0x67,0x65,0x74,0x30,0x3b,0x0a, + 0x7d,0x3b,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x6f,0x64,0x28,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x78,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x79,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x78,0x20,0x2d, + 0x20,0x79,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x6f,0x72,0x28,0x78,0x20,0x2f,0x20,0x79, + 0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x6d,0x6f,0x64, + 0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x78,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x32,0x20,0x79,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x78,0x20,0x2d,0x20,0x79,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x6f,0x72,0x28, + 0x78,0x20,0x2f,0x20,0x79,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x6d,0x6f,0x64,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x78,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x79,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x78,0x20,0x2d,0x20,0x79,0x20,0x2a,0x20,0x66, + 0x6c,0x6f,0x6f,0x72,0x28,0x78,0x20,0x2f,0x20,0x79,0x29,0x3b,0x0a,0x7d,0x0a,0x0a, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6d,0x6f,0x64,0x28,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x78,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x79,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x78,0x20,0x2d,0x20, + 0x79,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x6f,0x72,0x28,0x78,0x20,0x2f,0x20,0x79,0x29, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x75,0x69,0x6e,0x74,0x32,0x20,0x73,0x70,0x76,0x54,0x65, + 0x78,0x74,0x75,0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x54,0x65,0x78,0x74,0x75,0x72, + 0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x54,0x65,0x78,0x2c, + 0x20,0x75,0x69,0x6e,0x74,0x20,0x4c,0x65,0x76,0x65,0x6c,0x2c,0x20,0x6f,0x75,0x74, + 0x20,0x75,0x69,0x6e,0x74,0x20,0x50,0x61,0x72,0x61,0x6d,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x32,0x20,0x72,0x65,0x74,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x54,0x65,0x78,0x2e,0x47,0x65,0x74,0x44,0x69,0x6d,0x65,0x6e,0x73,0x69, + 0x6f,0x6e,0x73,0x28,0x4c,0x65,0x76,0x65,0x6c,0x2c,0x20,0x72,0x65,0x74,0x2e,0x78, + 0x2c,0x20,0x72,0x65,0x74,0x2e,0x79,0x2c,0x20,0x50,0x61,0x72,0x61,0x6d,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x72,0x65,0x74,0x3b, + 0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61, + 0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x35,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x76,0x5f, + 0x64,0x69,0x73,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x61,0x78,0x69,0x73,0x5f,0x70, + 0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x5f,0x35,0x30, + 0x5f,0x64,0x75,0x6d,0x6d,0x79,0x5f,0x70,0x61,0x72,0x61,0x6d,0x65,0x74,0x65,0x72, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x38,0x20, + 0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x37,0x38, + 0x20,0x3d,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3e,0x20,0x28,0x74, + 0x65,0x78,0x5f,0x64,0x65,0x70,0x74,0x68,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x4c, + 0x65,0x76,0x65,0x6c,0x28,0x73,0x6d,0x70,0x5f,0x64,0x65,0x70,0x74,0x68,0x2c,0x20, + 0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x20, + 0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x69,0x6e,0x74,0x32,0x28,0x73,0x70, + 0x76,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x74,0x65,0x78, + 0x5f,0x64,0x65,0x70,0x74,0x68,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x30,0x29,0x2c, + 0x20,0x5f,0x35,0x30,0x5f,0x64,0x75,0x6d,0x6d,0x79,0x5f,0x70,0x61,0x72,0x61,0x6d, + 0x65,0x74,0x65,0x72,0x29,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x2e,0x78, + 0x20,0x2b,0x20,0x28,0x30,0x2e,0x30,0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30, + 0x34,0x37,0x34,0x39,0x37,0x34,0x35,0x31,0x33,0x30,0x35,0x33,0x38,0x39,0x34,0x30, + 0x34,0x32,0x39,0x36,0x38,0x37,0x35,0x66,0x20,0x2b,0x20,0x28,0x32,0x2e,0x30,0x66, + 0x20,0x2a,0x20,0x5f,0x36,0x38,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x20,0x3d,0x20,0x76,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x76,0x5f, + 0x6f,0x63,0x63,0x5f,0x6d,0x6f,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x75,0x29,0x20, + 0x26,0x26,0x20,0x5f,0x37,0x38,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x20,0x3d,0x20,0x30,0x2e,0x30,0x66, + 0x2e,0x78,0x78,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x76,0x5f,0x6f,0x63,0x63,0x5f,0x6d, + 0x6f,0x64,0x65,0x20,0x3d,0x3d,0x20,0x31,0x75,0x29,0x20,0x26,0x26,0x20,0x5f,0x37, + 0x38,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x20,0x2a,0x3d,0x20, + 0x30,0x2e,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x76,0x5f,0x6f,0x63,0x63,0x5f,0x6d, + 0x6f,0x64,0x65,0x20,0x3d,0x3d,0x20,0x32,0x75,0x29,0x20,0x26,0x26,0x20,0x5f,0x37, + 0x38,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x31,0x31,0x37,0x20,0x3d,0x20,0x76, + 0x5f,0x73,0x63,0x72,0x65,0x65,0x6e,0x5f,0x62,0x20,0x2d,0x20,0x76,0x5f,0x73,0x63, + 0x72,0x65,0x65,0x6e,0x5f,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x33,0x36,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67, + 0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x20,0x2d,0x20,0x76,0x5f,0x73,0x63,0x72, + 0x65,0x65,0x6e,0x5f,0x61,0x2c,0x20,0x5f,0x31,0x31,0x37,0x20,0x2f,0x20,0x6d,0x61, + 0x78,0x28,0x6c,0x65,0x6e,0x67,0x74,0x68,0x28,0x5f,0x31,0x31,0x37,0x29,0x2c,0x20, + 0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x35,0x32,0x34,0x32, + 0x37,0x30,0x37,0x38,0x37,0x38,0x33,0x35,0x31,0x32,0x31,0x31,0x35,0x34,0x37,0x38, + 0x35,0x65,0x2d,0x30,0x37,0x66,0x29,0x2e,0x78,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x34,0x39,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68, + 0x28,0x5f,0x31,0x33,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x20,0x2a,0x3d,0x20,0x28, + 0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65, + 0x70,0x28,0x2d,0x5f,0x31,0x34,0x39,0x2c,0x20,0x5f,0x31,0x34,0x39,0x2c,0x20,0x61, + 0x62,0x73,0x28,0x6d,0x6f,0x64,0x28,0x5f,0x31,0x33,0x36,0x2c,0x20,0x31,0x36,0x2e, + 0x30,0x66,0x29,0x20,0x2d,0x20,0x34,0x2e,0x30,0x66,0x29,0x20,0x2d,0x20,0x34,0x2e, + 0x30,0x66,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x66,0x20, + 0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x76,0x5f,0x68, + 0x61,0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x20,0x2d,0x20,0x5f, + 0x31,0x35,0x2c,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68, + 0x5f,0x70,0x78,0x20,0x2b,0x20,0x5f,0x31,0x35,0x2c,0x20,0x61,0x62,0x73,0x28,0x76, + 0x5f,0x64,0x69,0x73,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x61,0x78,0x69,0x73,0x5f, + 0x70,0x78,0x29,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f, + 0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69, + 0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e, + 0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f, + 0x6f,0x72,0x64,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75, + 0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64, + 0x2e,0x77,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2f,0x20,0x67,0x6c,0x5f,0x46,0x72, + 0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x5f,0x64,0x69,0x73,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x61,0x78,0x69,0x73,0x5f, + 0x70,0x78,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74, + 0x2e,0x76,0x5f,0x64,0x69,0x73,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x61,0x78,0x69, + 0x73,0x5f,0x70,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66, + 0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x20,0x3d,0x20,0x73,0x74,0x61,0x67, + 0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x77, + 0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x7a,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e, + 0x70,0x75,0x74,0x2e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x73,0x74,0x61,0x67, + 0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x6f,0x63,0x63,0x5f,0x6d,0x6f,0x64,0x65,0x20, + 0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f, + 0x6f,0x63,0x63,0x5f,0x6d,0x6f,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f, + 0x73,0x63,0x72,0x65,0x65,0x6e,0x5f,0x62,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65, + 0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x73,0x63,0x72,0x65,0x65,0x6e,0x5f, + 0x62,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x73,0x63,0x72,0x65,0x65,0x6e,0x5f, + 0x61,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e, + 0x76,0x5f,0x73,0x63,0x72,0x65,0x65,0x6e,0x5f,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74, + 0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70, + 0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x6f, + 0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75, + 0x74,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + struct line_instance + { + float4 a; + float4 b; + float4 color; + uint4 flags; + }; + + struct line_instances + { + line_instance instances[1]; + }; + + struct ub_frame + { + float4x4 view; + float4x4 proj; + float4x4 view_proj; + float4x4 inv_view_proj; + float4 camera_pos; + float4 viewport; + }; + + struct main0_out + { + float2 v_screen_a [[user(locn0)]]; + float2 v_screen_b [[user(locn1)]]; + float v_dist_from_axis_px [[user(locn2)]]; + float v_half_width_px [[user(locn3)]]; + float v_view_z [[user(locn4)]]; + float4 v_color [[user(locn5)]]; + uint v_occ_mode [[user(locn6)]]; + float4 gl_Position [[position]]; + }; + + vertex main0_out main0(constant ub_frame& _83 [[buffer(0)]], const device line_instances& _17 [[buffer(8)]], uint gl_InstanceIndex [[instance_id]], uint gl_VertexIndex [[vertex_id]]) + { + main0_out out = {}; + bool _49 = int(gl_VertexIndex) == 2; + bool _53 = int(gl_VertexIndex) == 4; + bool _54 = ((int(gl_VertexIndex) == 1) || _49) || _53; + float _68 = ((_49 || _53) || (int(gl_VertexIndex) == 5)) ? 1.0 : (-1.0); + float4 _91 = float4(_17.instances[int(gl_InstanceIndex)].a.xyz, 1.0); + float4 _92 = _83.view_proj * _91; + float4 _100 = float4(_17.instances[int(gl_InstanceIndex)].b.xyz, 1.0); + float4 _101 = _83.view_proj * _100; + float4 _126 = select(_92, _101, bool4(_54)); + float _129; + if (_54) + { + _129 = (_83.view * _100).z; + } + else + { + _129 = (_83.view * _91).z; + } + out.v_screen_a = (((_92.xy / float2(_92.w)) * 0.5) + float2(0.5)) * _83.viewport.xy; + out.v_screen_b = (((_101.xy / float2(_101.w)) * 0.5) + float2(0.5)) * _83.viewport.xy; + float2 _181 = out.v_screen_b - out.v_screen_a; + float _184 = length(_181); + float2 _189; + if (_184 > 9.9999999747524270787835121154785e-07) + { + _189 = _181 / float2(_184); + } + else + { + _189 = float2(1.0, 0.0); + } + float half_width_px; + if (_17.instances[int(gl_InstanceIndex)].flags.x == 0u) + { + half_width_px = _17.instances[int(gl_InstanceIndex)].a.w * 0.5; + } + else + { + half_width_px = (_17.instances[int(gl_InstanceIndex)].a.w * 0.5) * ((_83.viewport.y * _83.proj[1].y) / (_129 * (-2.0))); + } + float _237 = half_width_px; + float _238 = fast::max(_237, 0.5); + half_width_px = _238; + float _242 = _238 + 1.5; + float2 _264 = _126.xy + ((((float2(-_189.y, _189.x) * _68) * _242) * (_83.viewport.zw * 2.0)) * _126.w); + float4 _309 = _126; + _309.x = _264.x; + _309.y = _264.y; + out.gl_Position = _309; + out.v_dist_from_axis_px = _68 * _242; + out.v_half_width_px = _238; + out.v_view_z = -_129; + out.v_color = _17.instances[int(gl_InstanceIndex)].color; + out.v_occ_mode = _17.instances[int(gl_InstanceIndex)].flags.y; + return out; + } + +*/ +static const uint8_t overlay_line_vs_source_metal_macos[2883] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6c, + 0x69,0x6e,0x65,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x61,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x62,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x75,0x69,0x6e,0x74,0x34,0x20,0x66,0x6c,0x61,0x67,0x73,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6c,0x69,0x6e,0x65,0x5f,0x69,0x6e, + 0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6c,0x69, + 0x6e,0x65,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20,0x69,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x73,0x5b,0x31,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x76,0x69,0x65, + 0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20, + 0x70,0x72,0x6f,0x6a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x78,0x34,0x20,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x69,0x6e,0x76,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x69,0x65,0x77, + 0x70,0x6f,0x72,0x74,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74, + 0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x76,0x5f,0x73,0x63,0x72,0x65,0x65,0x6e, + 0x5f,0x61,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29, + 0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x76, + 0x5f,0x73,0x63,0x72,0x65,0x65,0x6e,0x5f,0x62,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72, + 0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x64,0x69,0x73,0x74,0x5f,0x66,0x72,0x6f,0x6d, + 0x5f,0x61,0x78,0x69,0x73,0x5f,0x70,0x78,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28, + 0x6c,0x6f,0x63,0x6e,0x32,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68, + 0x5f,0x70,0x78,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x33, + 0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76, + 0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c, + 0x6f,0x63,0x6e,0x34,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73, + 0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x35,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x75,0x69,0x6e,0x74,0x20,0x76,0x5f,0x6f,0x63,0x63,0x5f,0x6d,0x6f,0x64,0x65, + 0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x36,0x29,0x5d,0x5d, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f, + 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74, + 0x69,0x6f,0x6e,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,0x65, + 0x78,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e, + 0x30,0x28,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x66,0x72, + 0x61,0x6d,0x65,0x26,0x20,0x5f,0x38,0x33,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65, + 0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x64,0x65, + 0x76,0x69,0x63,0x65,0x20,0x6c,0x69,0x6e,0x65,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x73,0x26,0x20,0x5f,0x31,0x37,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65, + 0x72,0x28,0x38,0x29,0x5d,0x5d,0x2c,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f, + 0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x5b,0x5b, + 0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x5f,0x69,0x64,0x5d,0x5d,0x2c,0x20,0x75, + 0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64, + 0x65,0x78,0x20,0x5b,0x5b,0x76,0x65,0x72,0x74,0x65,0x78,0x5f,0x69,0x64,0x5d,0x5d, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75, + 0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x34,0x39,0x20,0x3d,0x20,0x69,0x6e,0x74,0x28,0x67, + 0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x3d, + 0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x35, + 0x33,0x20,0x3d,0x20,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65, + 0x78,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x3d,0x3d,0x20,0x34,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x35,0x34,0x20,0x3d,0x20,0x28,0x28,0x69, + 0x6e,0x74,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65, + 0x78,0x29,0x20,0x3d,0x3d,0x20,0x31,0x29,0x20,0x7c,0x7c,0x20,0x5f,0x34,0x39,0x29, + 0x20,0x7c,0x7c,0x20,0x5f,0x35,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x36,0x38,0x20,0x3d,0x20,0x28,0x28,0x5f,0x34,0x39,0x20,0x7c, + 0x7c,0x20,0x5f,0x35,0x33,0x29,0x20,0x7c,0x7c,0x20,0x28,0x69,0x6e,0x74,0x28,0x67, + 0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x3d, + 0x3d,0x20,0x35,0x29,0x29,0x20,0x3f,0x20,0x31,0x2e,0x30,0x20,0x3a,0x20,0x28,0x2d, + 0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x5f,0x39,0x31,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x31, + 0x37,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x69,0x6e,0x74,0x28, + 0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78, + 0x29,0x5d,0x2e,0x61,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x39,0x32,0x20,0x3d, + 0x20,0x5f,0x38,0x33,0x2e,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x2a, + 0x20,0x5f,0x39,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x5f,0x31,0x30,0x30,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f, + 0x31,0x37,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x69,0x6e,0x74, + 0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65, + 0x78,0x29,0x5d,0x2e,0x62,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x30,0x31, + 0x20,0x3d,0x20,0x5f,0x38,0x33,0x2e,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a, + 0x20,0x2a,0x20,0x5f,0x31,0x30,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x5f,0x31,0x32,0x36,0x20,0x3d,0x20,0x73,0x65,0x6c,0x65,0x63, + 0x74,0x28,0x5f,0x39,0x32,0x2c,0x20,0x5f,0x31,0x30,0x31,0x2c,0x20,0x62,0x6f,0x6f, + 0x6c,0x34,0x28,0x5f,0x35,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x5f,0x35,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x32,0x39,0x20,0x3d,0x20,0x28,0x5f,0x38,0x33, + 0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x5f,0x31,0x30,0x30,0x29,0x2e,0x7a,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31, + 0x32,0x39,0x20,0x3d,0x20,0x28,0x5f,0x38,0x33,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a, + 0x20,0x5f,0x39,0x31,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x73,0x63,0x72,0x65,0x65,0x6e,0x5f, + 0x61,0x20,0x3d,0x20,0x28,0x28,0x28,0x5f,0x39,0x32,0x2e,0x78,0x79,0x20,0x2f,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x39,0x32,0x2e,0x77,0x29,0x29,0x20,0x2a, + 0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x30, + 0x2e,0x35,0x29,0x29,0x20,0x2a,0x20,0x5f,0x38,0x33,0x2e,0x76,0x69,0x65,0x77,0x70, + 0x6f,0x72,0x74,0x2e,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e, + 0x76,0x5f,0x73,0x63,0x72,0x65,0x65,0x6e,0x5f,0x62,0x20,0x3d,0x20,0x28,0x28,0x28, + 0x5f,0x31,0x30,0x31,0x2e,0x78,0x79,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, + 0x28,0x5f,0x31,0x30,0x31,0x2e,0x77,0x29,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29, + 0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20, + 0x2a,0x20,0x5f,0x38,0x33,0x2e,0x76,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x2e,0x78, + 0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x31, + 0x38,0x31,0x20,0x3d,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x73,0x63,0x72,0x65,0x65, + 0x6e,0x5f,0x62,0x20,0x2d,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x73,0x63,0x72,0x65, + 0x65,0x6e,0x5f,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x38,0x34,0x20,0x3d,0x20,0x6c,0x65,0x6e,0x67,0x74,0x68,0x28,0x5f,0x31, + 0x38,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20, + 0x5f,0x31,0x38,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31, + 0x38,0x34,0x20,0x3e,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34, + 0x37,0x35,0x32,0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38,0x33,0x35,0x31,0x32,0x31, + 0x31,0x35,0x34,0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x38,0x39,0x20,0x3d, + 0x20,0x5f,0x31,0x38,0x31,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f, + 0x31,0x38,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x5f,0x31,0x38,0x39,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, + 0x28,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x68,0x61,0x6c,0x66, + 0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x5f,0x31,0x37,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73, + 0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x49,0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20, + 0x3d,0x3d,0x20,0x30,0x75,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x68,0x61,0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f, + 0x70,0x78,0x20,0x3d,0x20,0x5f,0x31,0x37,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x73,0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x61,0x2e,0x77,0x20,0x2a,0x20, + 0x30,0x2e,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65, + 0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x68,0x61,0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x20, + 0x3d,0x20,0x28,0x5f,0x31,0x37,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73, + 0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x49,0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x61,0x2e,0x77,0x20,0x2a,0x20,0x30,0x2e, + 0x35,0x29,0x20,0x2a,0x20,0x28,0x28,0x5f,0x38,0x33,0x2e,0x76,0x69,0x65,0x77,0x70, + 0x6f,0x72,0x74,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x38,0x33,0x2e,0x70,0x72,0x6f,0x6a, + 0x5b,0x31,0x5d,0x2e,0x79,0x29,0x20,0x2f,0x20,0x28,0x5f,0x31,0x32,0x39,0x20,0x2a, + 0x20,0x28,0x2d,0x32,0x2e,0x30,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x33,0x37,0x20, + 0x3d,0x20,0x68,0x61,0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x33,0x38,0x20, + 0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x5f,0x32,0x33,0x37, + 0x2c,0x20,0x30,0x2e,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x68,0x61,0x6c,0x66, + 0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x20,0x3d,0x20,0x5f,0x32,0x33,0x38, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x34,0x32, + 0x20,0x3d,0x20,0x5f,0x32,0x33,0x38,0x20,0x2b,0x20,0x31,0x2e,0x35,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x32,0x36,0x34,0x20,0x3d, + 0x20,0x5f,0x31,0x32,0x36,0x2e,0x78,0x79,0x20,0x2b,0x20,0x28,0x28,0x28,0x28,0x66, + 0x6c,0x6f,0x61,0x74,0x32,0x28,0x2d,0x5f,0x31,0x38,0x39,0x2e,0x79,0x2c,0x20,0x5f, + 0x31,0x38,0x39,0x2e,0x78,0x29,0x20,0x2a,0x20,0x5f,0x36,0x38,0x29,0x20,0x2a,0x20, + 0x5f,0x32,0x34,0x32,0x29,0x20,0x2a,0x20,0x28,0x5f,0x38,0x33,0x2e,0x76,0x69,0x65, + 0x77,0x70,0x6f,0x72,0x74,0x2e,0x7a,0x77,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x29, + 0x20,0x2a,0x20,0x5f,0x31,0x32,0x36,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x33,0x30,0x39,0x20,0x3d,0x20,0x5f,0x31, + 0x32,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x30,0x39,0x2e,0x78,0x20,0x3d, + 0x20,0x5f,0x32,0x36,0x34,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x30, + 0x39,0x2e,0x79,0x20,0x3d,0x20,0x5f,0x32,0x36,0x34,0x2e,0x79,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f, + 0x6e,0x20,0x3d,0x20,0x5f,0x33,0x30,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75, + 0x74,0x2e,0x76,0x5f,0x64,0x69,0x73,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x61,0x78, + 0x69,0x73,0x5f,0x70,0x78,0x20,0x3d,0x20,0x5f,0x36,0x38,0x20,0x2a,0x20,0x5f,0x32, + 0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x68,0x61, + 0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x20,0x3d,0x20,0x5f,0x32, + 0x33,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x20,0x3d,0x20,0x2d,0x5f,0x31,0x32,0x39,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20, + 0x5f,0x31,0x37,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x69,0x6e, + 0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64, + 0x65,0x78,0x29,0x5d,0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x6f,0x75,0x74,0x2e,0x76,0x5f,0x6f,0x63,0x63,0x5f,0x6d,0x6f,0x64,0x65,0x20,0x3d, + 0x20,0x5f,0x31,0x37,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x69, + 0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e, + 0x64,0x65,0x78,0x29,0x5d,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x79,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x00, +}; +/* + #pragma clang diagnostic ignored "-Wmissing-prototypes" + + #include + #include + + using namespace metal; + + // Implementation of the GLSL mod() function, which is slightly different than Metal fmod() + template + inline Tx mod(Tx x, Ty y) + { + return x - y * floor(x / y); + } + + struct main0_out + { + float4 out_color [[color(0)]]; + }; + + struct main0_in + { + float2 v_screen_a [[user(locn0)]]; + float2 v_screen_b [[user(locn1)]]; + float v_dist_from_axis_px [[user(locn2), center_no_perspective]]; + float v_half_width_px [[user(locn3)]]; + float v_view_z [[user(locn4)]]; + float4 v_color [[user(locn5), flat]]; + uint v_occ_mode [[user(locn6)]]; + }; + + fragment main0_out main0(main0_in in [[stage_in]], texture2d tex_depth [[texture(0)]], sampler smp_depth [[sampler(0)]], float4 gl_FragCoord [[position]]) + { + main0_out out = {}; + float _15 = fwidth(in.v_dist_from_axis_px); + float _68 = fwidth(in.v_view_z); + bool _78 = in.v_view_z > (tex_depth.sample(smp_depth, (gl_FragCoord.xy / float2(int2(tex_depth.get_width(), tex_depth.get_height()))), level(0.0)).x + (0.001000000047497451305389404296875 + (2.0 * _68))); + float4 col = in.v_color; + if ((in.v_occ_mode == 0u) && _78) + { + col = float4(0.0); + } + else + { + if ((in.v_occ_mode == 1u) && _78) + { + col *= 0.25; + } + else + { + if ((in.v_occ_mode == 2u) && _78) + { + float2 _117 = in.v_screen_b - in.v_screen_a; + float _136 = dot(gl_FragCoord.xy - in.v_screen_a, _117 / float2(fast::max(length(_117), 9.9999999747524270787835121154785e-07))); + float _149 = fwidth(_136); + col *= (1.0 - smoothstep(-_149, _149, abs(mod(_136, 16.0) - 4.0) - 4.0)); + } + } + } + out.out_color = col * (1.0 - smoothstep(in.v_half_width_px - _15, in.v_half_width_px + _15, abs(in.v_dist_from_axis_px))); + return out; + } + +*/ +static const uint8_t overlay_line_fs_source_metal_macos[1996] = { + 0x23,0x70,0x72,0x61,0x67,0x6d,0x61,0x20,0x63,0x6c,0x61,0x6e,0x67,0x20,0x64,0x69, + 0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x20,0x69,0x67,0x6e,0x6f,0x72,0x65,0x64, + 0x20,0x22,0x2d,0x57,0x6d,0x69,0x73,0x73,0x69,0x6e,0x67,0x2d,0x70,0x72,0x6f,0x74, + 0x6f,0x74,0x79,0x70,0x65,0x73,0x22,0x0a,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64, + 0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f,0x73,0x74,0x64,0x6c,0x69,0x62,0x3e, + 0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f, + 0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a,0x75,0x73,0x69,0x6e,0x67,0x20,0x6e, + 0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20,0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a, + 0x0a,0x2f,0x2f,0x20,0x49,0x6d,0x70,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x61,0x74,0x69, + 0x6f,0x6e,0x20,0x6f,0x66,0x20,0x74,0x68,0x65,0x20,0x47,0x4c,0x53,0x4c,0x20,0x6d, + 0x6f,0x64,0x28,0x29,0x20,0x66,0x75,0x6e,0x63,0x74,0x69,0x6f,0x6e,0x2c,0x20,0x77, + 0x68,0x69,0x63,0x68,0x20,0x69,0x73,0x20,0x73,0x6c,0x69,0x67,0x68,0x74,0x6c,0x79, + 0x20,0x64,0x69,0x66,0x66,0x65,0x72,0x65,0x6e,0x74,0x20,0x74,0x68,0x61,0x6e,0x20, + 0x4d,0x65,0x74,0x61,0x6c,0x20,0x66,0x6d,0x6f,0x64,0x28,0x29,0x0a,0x74,0x65,0x6d, + 0x70,0x6c,0x61,0x74,0x65,0x3c,0x74,0x79,0x70,0x65,0x6e,0x61,0x6d,0x65,0x20,0x54, + 0x78,0x2c,0x20,0x74,0x79,0x70,0x65,0x6e,0x61,0x6d,0x65,0x20,0x54,0x79,0x3e,0x0a, + 0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x54,0x78,0x20,0x6d,0x6f,0x64,0x28,0x54,0x78, + 0x20,0x78,0x2c,0x20,0x54,0x79,0x20,0x79,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x78,0x20,0x2d,0x20,0x79,0x20,0x2a,0x20,0x66, + 0x6c,0x6f,0x6f,0x72,0x28,0x78,0x20,0x2f,0x20,0x79,0x29,0x3b,0x0a,0x7d,0x0a,0x0a, + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75, + 0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28, + 0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74, + 0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x76,0x5f,0x73,0x63,0x72,0x65,0x65,0x6e,0x5f, + 0x61,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x76,0x5f, + 0x73,0x63,0x72,0x65,0x65,0x6e,0x5f,0x62,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28, + 0x6c,0x6f,0x63,0x6e,0x31,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x76,0x5f,0x64,0x69,0x73,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f, + 0x61,0x78,0x69,0x73,0x5f,0x70,0x78,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c, + 0x6f,0x63,0x6e,0x32,0x29,0x2c,0x20,0x63,0x65,0x6e,0x74,0x65,0x72,0x5f,0x6e,0x6f, + 0x5f,0x70,0x65,0x72,0x73,0x70,0x65,0x63,0x74,0x69,0x76,0x65,0x5d,0x5d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66, + 0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72, + 0x28,0x6c,0x6f,0x63,0x6e,0x33,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x5b,0x5b, + 0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x34,0x29,0x5d,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x35,0x29,0x2c, + 0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e, + 0x74,0x20,0x76,0x5f,0x6f,0x63,0x63,0x5f,0x6d,0x6f,0x64,0x65,0x20,0x5b,0x5b,0x75, + 0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x36,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30, + 0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30, + 0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69, + 0x6e,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66, + 0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x64,0x65,0x70,0x74,0x68,0x20, + 0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x64,0x65,0x70,0x74, + 0x68,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67, + 0x43,0x6f,0x6f,0x72,0x64,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e, + 0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f, + 0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x20,0x3d,0x20,0x66,0x77, + 0x69,0x64,0x74,0x68,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x64,0x69,0x73,0x74,0x5f,0x66, + 0x72,0x6f,0x6d,0x5f,0x61,0x78,0x69,0x73,0x5f,0x70,0x78,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x38,0x20,0x3d,0x20,0x66,0x77, + 0x69,0x64,0x74,0x68,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x37,0x38,0x20, + 0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3e,0x20, + 0x28,0x74,0x65,0x78,0x5f,0x64,0x65,0x70,0x74,0x68,0x2e,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x28,0x73,0x6d,0x70,0x5f,0x64,0x65,0x70,0x74,0x68,0x2c,0x20,0x28,0x67,0x6c, + 0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x20,0x2f,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x69,0x6e,0x74,0x32,0x28,0x74,0x65,0x78,0x5f, + 0x64,0x65,0x70,0x74,0x68,0x2e,0x67,0x65,0x74,0x5f,0x77,0x69,0x64,0x74,0x68,0x28, + 0x29,0x2c,0x20,0x74,0x65,0x78,0x5f,0x64,0x65,0x70,0x74,0x68,0x2e,0x67,0x65,0x74, + 0x5f,0x68,0x65,0x69,0x67,0x68,0x74,0x28,0x29,0x29,0x29,0x29,0x2c,0x20,0x6c,0x65, + 0x76,0x65,0x6c,0x28,0x30,0x2e,0x30,0x29,0x29,0x2e,0x78,0x20,0x2b,0x20,0x28,0x30, + 0x2e,0x30,0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x34,0x37,0x34,0x39,0x37, + 0x34,0x35,0x31,0x33,0x30,0x35,0x33,0x38,0x39,0x34,0x30,0x34,0x32,0x39,0x36,0x38, + 0x37,0x35,0x20,0x2b,0x20,0x28,0x32,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36,0x38,0x29, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63, + 0x6f,0x6c,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x6f, + 0x63,0x63,0x5f,0x6d,0x6f,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x75,0x29,0x20,0x26, + 0x26,0x20,0x5f,0x37,0x38,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x28,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x6f, + 0x63,0x63,0x5f,0x6d,0x6f,0x64,0x65,0x20,0x3d,0x3d,0x20,0x31,0x75,0x29,0x20,0x26, + 0x26,0x20,0x5f,0x37,0x38,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c, + 0x20,0x2a,0x3d,0x20,0x30,0x2e,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x69,0x6e,0x2e,0x76, + 0x5f,0x6f,0x63,0x63,0x5f,0x6d,0x6f,0x64,0x65,0x20,0x3d,0x3d,0x20,0x32,0x75,0x29, + 0x20,0x26,0x26,0x20,0x5f,0x37,0x38,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x31, + 0x31,0x37,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x73,0x63,0x72,0x65,0x65,0x6e, + 0x5f,0x62,0x20,0x2d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x73,0x63,0x72,0x65,0x65,0x6e, + 0x5f,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x36,0x20,0x3d, + 0x20,0x64,0x6f,0x74,0x28,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72, + 0x64,0x2e,0x78,0x79,0x20,0x2d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x73,0x63,0x72,0x65, + 0x65,0x6e,0x5f,0x61,0x2c,0x20,0x5f,0x31,0x31,0x37,0x20,0x2f,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x32,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x6c,0x65, + 0x6e,0x67,0x74,0x68,0x28,0x5f,0x31,0x31,0x37,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39, + 0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x35,0x32,0x34,0x32,0x37,0x30,0x37,0x38, + 0x37,0x38,0x33,0x35,0x31,0x32,0x31,0x31,0x35,0x34,0x37,0x38,0x35,0x65,0x2d,0x30, + 0x37,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x39, + 0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31,0x33,0x36,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x63,0x6f,0x6c,0x20,0x2a,0x3d,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73, + 0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x2d,0x5f,0x31,0x34,0x39,0x2c, + 0x20,0x5f,0x31,0x34,0x39,0x2c,0x20,0x61,0x62,0x73,0x28,0x6d,0x6f,0x64,0x28,0x5f, + 0x31,0x33,0x36,0x2c,0x20,0x31,0x36,0x2e,0x30,0x29,0x20,0x2d,0x20,0x34,0x2e,0x30, + 0x29,0x20,0x2d,0x20,0x34,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, + 0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c, + 0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68, + 0x73,0x74,0x65,0x70,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x77, + 0x69,0x64,0x74,0x68,0x5f,0x70,0x78,0x20,0x2d,0x20,0x5f,0x31,0x35,0x2c,0x20,0x69, + 0x6e,0x2e,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x77,0x69,0x64,0x74,0x68,0x5f,0x70, + 0x78,0x20,0x2b,0x20,0x5f,0x31,0x35,0x2c,0x20,0x61,0x62,0x73,0x28,0x69,0x6e,0x2e, + 0x76,0x5f,0x64,0x69,0x73,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x61,0x78,0x69,0x73, + 0x5f,0x70,0x78,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +static inline const sg_shader_desc* overlay_line_prog_shader_desc(sg_backend backend) { + if (backend == SG_BACKEND_GLCORE) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)overlay_line_vs_source_glsl430; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)overlay_line_fs_source_glsl430; + desc.fragment_func.entry = "main"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 288; + desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[0].glsl_uniforms[0].array_count = 18; + desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_frame"; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.glsl_binding_n = 0; + desc.views[1].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[1].texture.image_type = SG_IMAGETYPE_2D; + desc.views[1].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[1].texture.multisampled = false; + desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[0].view_slot = 1; + desc.texture_sampler_pairs[0].sampler_slot = 0; + desc.texture_sampler_pairs[0].glsl_name = "tex_depth_smp_depth"; + desc.label = "overlay_line_prog_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_D3D11) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)overlay_line_vs_source_hlsl5; + desc.vertex_func.d3d11_target = "vs_5_0"; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)overlay_line_fs_source_hlsl5; + desc.fragment_func.d3d11_target = "ps_5_0"; + desc.fragment_func.entry = "main"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 288; + desc.uniform_blocks[0].hlsl_register_b_n = 0; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.hlsl_register_t_n = 0; + desc.views[1].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[1].texture.image_type = SG_IMAGETYPE_2D; + desc.views[1].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[1].texture.multisampled = false; + desc.views[1].texture.hlsl_register_t_n = 0; + desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[0].hlsl_register_s_n = 0; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[0].view_slot = 1; + desc.texture_sampler_pairs[0].sampler_slot = 0; + desc.label = "overlay_line_prog_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_METAL_MACOS) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)overlay_line_vs_source_metal_macos; + desc.vertex_func.entry = "main0"; + desc.fragment_func.source = (const char*)overlay_line_fs_source_metal_macos; + desc.fragment_func.entry = "main0"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 288; + desc.uniform_blocks[0].msl_buffer_n = 0; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.msl_buffer_n = 8; + desc.views[1].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[1].texture.image_type = SG_IMAGETYPE_2D; + desc.views[1].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[1].texture.multisampled = false; + desc.views[1].texture.msl_texture_n = 0; + desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[0].msl_sampler_n = 0; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[0].view_slot = 1; + desc.texture_sampler_pairs[0].sampler_slot = 0; + desc.label = "overlay_line_prog_shader"; + } + return &desc; + } + return 0; +} diff --git a/samples/shaders/generated/overlay_point.glsl.h b/samples/shaders/generated/overlay_point.glsl.h new file mode 100644 index 0000000..998af3c --- /dev/null +++ b/samples/shaders/generated/overlay_point.glsl.h @@ -0,0 +1,1203 @@ +#pragma once +/* + #version:1# (machine generated, don't edit!) + + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) + + Cmdline: + sokol-shdc --input E:/box/box3d/samples/shaders/overlays/point.glsl --output E:/box/box3d/samples/shaders/generated/overlay_point.glsl.h --slang hlsl5:metal_macos:glsl430 + + Overview: + ========= + Shader program: 'prog': + Get shader desc: overlay_point_prog_shader_desc(sg_query_backend()); + Vertex Shader: vs + Fragment Shader: fs + Attributes: + Bindings: + Uniform block 'ub_frame': + C struct: overlay_point_ub_frame_t + Bind slot: UB_overlay_point_ub_frame => 0 + Storage buffer 'point_instances': + C struct: overlay_point_point_instance_t + Bind slot: VIEW_overlay_point_point_instances => 0 + Readonly: true + Texture 'tex_depth': + Image type: SG_IMAGETYPE_2D + Sample type: SG_IMAGESAMPLETYPE_FLOAT + Multisampled: false + Bind slot: VIEW_overlay_point_tex_depth => 1 + Sampler 'smp_depth': + Type: SG_SAMPLERTYPE_FILTERING + Bind slot: SMP_overlay_point_smp_depth => 0 +*/ +#if !defined(SOKOL_GFX_INCLUDED) +#error "Please include sokol_gfx.h before overlay_point.glsl.h" +#endif +#if !defined(SOKOL_SHDC_ALIGN) +#if defined(_MSC_VER) +#define SOKOL_SHDC_ALIGN(a) __declspec(align(a)) +#else +#define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) +#endif +#endif +#define UB_overlay_point_ub_frame (0) +#define VIEW_overlay_point_point_instances (0) +#define VIEW_overlay_point_tex_depth (1) +#define SMP_overlay_point_smp_depth (0) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct overlay_point_ub_frame_t { + Mat4 view; + Mat4 proj; + Mat4 view_proj; + Mat4 inv_view_proj; + Vec4 camera_pos; + Vec4 viewport; +} overlay_point_ub_frame_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct overlay_point_point_instance_t { + Vec4 p; + Vec4 color; + uint32_t flags[4]; +} overlay_point_point_instance_t; +#pragma pack(pop) +/* + #version 430 + + struct point_instance + { + vec4 p; + vec4 color; + uvec4 flags; + }; + + layout(binding = 0, std430) readonly buffer point_instances + { + point_instance instances[]; + } _17; + + uniform vec4 ub_frame[18]; + layout(location = 0) out vec2 v_offset_from_center_px; + layout(location = 1) out float v_half_size_px; + layout(location = 2) out float v_view_z; + layout(location = 3) flat out vec4 v_color; + layout(location = 4) flat out uint v_occ_mode; + + void main() + { + bool _46 = gl_VertexID == 2; + bool _50 = gl_VertexID == 4; + vec4 _84 = vec4(_17.instances[gl_InstanceID].p.xyz, 1.0); + vec4 _85 = mat4(ub_frame[8], ub_frame[9], ub_frame[10], ub_frame[11]) * _84; + vec4 _94 = mat4(ub_frame[0], ub_frame[1], ub_frame[2], ub_frame[3]) * _84; + float _98 = _94.z; + float half_size_px; + if (_17.instances[gl_InstanceID].flags.x == 0u) + { + half_size_px = _17.instances[gl_InstanceID].p.w * 0.5; + } + else + { + half_size_px = (_17.instances[gl_InstanceID].p.w * 0.5) * ((ub_frame[17].y * ub_frame[5].y) / (_98 * (-2.0))); + } + float _132 = half_size_px; + float _133 = max(_132, 0.5); + half_size_px = _133; + vec2 _145 = vec2((((gl_VertexID == 1) || _46) || _50) ? 1.0 : (-1.0), ((_46 || _50) || (gl_VertexID == 5)) ? 1.0 : (-1.0)) * (_133 + 1.5); + vec2 _162 = _85.xy + ((_145 * (ub_frame[17].zw * 2.0)) * _85.w); + vec4 _200 = _85; + _200.x = _162.x; + _200.y = _162.y; + gl_Position = _200; + v_offset_from_center_px = _145; + v_half_size_px = _133; + v_view_z = -_98; + v_color = _17.instances[gl_InstanceID].color; + v_occ_mode = _17.instances[gl_InstanceID].flags.y; + } + +*/ +static const uint8_t overlay_point_vs_source_glsl430[1648] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x70,0x6f,0x69,0x6e,0x74,0x5f,0x69,0x6e,0x73,0x74,0x61, + 0x6e,0x63,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x70, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x76,0x65,0x63,0x34,0x20,0x66,0x6c,0x61,0x67, + 0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69, + 0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x30,0x2c,0x20,0x73,0x74,0x64,0x34,0x33, + 0x30,0x29,0x20,0x72,0x65,0x61,0x64,0x6f,0x6e,0x6c,0x79,0x20,0x62,0x75,0x66,0x66, + 0x65,0x72,0x20,0x70,0x6f,0x69,0x6e,0x74,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x70,0x6f,0x69,0x6e,0x74,0x5f,0x69, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x73,0x5b,0x5d,0x3b,0x0a,0x7d,0x20,0x5f,0x31,0x37,0x3b,0x0a,0x0a,0x75,0x6e,0x69, + 0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x66,0x72,0x61, + 0x6d,0x65,0x5b,0x31,0x38,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, + 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74, + 0x20,0x76,0x65,0x63,0x32,0x20,0x76,0x5f,0x6f,0x66,0x66,0x73,0x65,0x74,0x5f,0x66, + 0x72,0x6f,0x6d,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x5f,0x70,0x78,0x3b,0x0a,0x6c, + 0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d, + 0x20,0x31,0x29,0x20,0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f, + 0x68,0x61,0x6c,0x66,0x5f,0x73,0x69,0x7a,0x65,0x5f,0x70,0x78,0x3b,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x32,0x29,0x20,0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f, + 0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x33,0x29,0x20,0x66,0x6c,0x61,0x74, + 0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69, + 0x6f,0x6e,0x20,0x3d,0x20,0x34,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x6f,0x75,0x74, + 0x20,0x75,0x69,0x6e,0x74,0x20,0x76,0x5f,0x6f,0x63,0x63,0x5f,0x6d,0x6f,0x64,0x65, + 0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x34,0x36,0x20,0x3d,0x20, + 0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x44,0x20,0x3d,0x3d,0x20,0x32, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x35,0x30,0x20,0x3d, + 0x20,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x44,0x20,0x3d,0x3d,0x20, + 0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x38,0x34,0x20, + 0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x31,0x37,0x2e,0x69,0x6e,0x73,0x74,0x61, + 0x6e,0x63,0x65,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x49,0x44,0x5d,0x2e,0x70,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x38,0x35,0x20,0x3d,0x20, + 0x6d,0x61,0x74,0x34,0x28,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x38,0x5d, + 0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x39,0x5d,0x2c,0x20,0x75, + 0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x31,0x30,0x5d,0x2c,0x20,0x75,0x62,0x5f, + 0x66,0x72,0x61,0x6d,0x65,0x5b,0x31,0x31,0x5d,0x29,0x20,0x2a,0x20,0x5f,0x38,0x34, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x39,0x34,0x20,0x3d, + 0x20,0x6d,0x61,0x74,0x34,0x28,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x30, + 0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x31,0x5d,0x2c,0x20, + 0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x32,0x5d,0x2c,0x20,0x75,0x62,0x5f, + 0x66,0x72,0x61,0x6d,0x65,0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x5f,0x38,0x34,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x38,0x20,0x3d, + 0x20,0x5f,0x39,0x34,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x68,0x61,0x6c,0x66,0x5f,0x73,0x69,0x7a,0x65,0x5f,0x70,0x78,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x37,0x2e,0x69,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x49,0x44,0x5d,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20, + 0x30,0x75,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x68,0x61,0x6c,0x66,0x5f,0x73,0x69,0x7a,0x65,0x5f,0x70,0x78,0x20,0x3d, + 0x20,0x5f,0x31,0x37,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x67, + 0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x70,0x2e, + 0x77,0x20,0x2a,0x20,0x30,0x2e,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x68,0x61,0x6c,0x66,0x5f,0x73,0x69,0x7a,0x65,0x5f, + 0x70,0x78,0x20,0x3d,0x20,0x28,0x5f,0x31,0x37,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49, + 0x44,0x5d,0x2e,0x70,0x2e,0x77,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2a,0x20, + 0x28,0x28,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x31,0x37,0x5d,0x2e,0x79, + 0x20,0x2a,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x35,0x5d,0x2e,0x79, + 0x29,0x20,0x2f,0x20,0x28,0x5f,0x39,0x38,0x20,0x2a,0x20,0x28,0x2d,0x32,0x2e,0x30, + 0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x32,0x20,0x3d,0x20,0x68,0x61,0x6c,0x66, + 0x5f,0x73,0x69,0x7a,0x65,0x5f,0x70,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x33,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x5f, + 0x31,0x33,0x32,0x2c,0x20,0x30,0x2e,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x68, + 0x61,0x6c,0x66,0x5f,0x73,0x69,0x7a,0x65,0x5f,0x70,0x78,0x20,0x3d,0x20,0x5f,0x31, + 0x33,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x31,0x34, + 0x35,0x20,0x3d,0x20,0x76,0x65,0x63,0x32,0x28,0x28,0x28,0x28,0x67,0x6c,0x5f,0x56, + 0x65,0x72,0x74,0x65,0x78,0x49,0x44,0x20,0x3d,0x3d,0x20,0x31,0x29,0x20,0x7c,0x7c, + 0x20,0x5f,0x34,0x36,0x29,0x20,0x7c,0x7c,0x20,0x5f,0x35,0x30,0x29,0x20,0x3f,0x20, + 0x31,0x2e,0x30,0x20,0x3a,0x20,0x28,0x2d,0x31,0x2e,0x30,0x29,0x2c,0x20,0x28,0x28, + 0x5f,0x34,0x36,0x20,0x7c,0x7c,0x20,0x5f,0x35,0x30,0x29,0x20,0x7c,0x7c,0x20,0x28, + 0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x44,0x20,0x3d,0x3d,0x20,0x35, + 0x29,0x29,0x20,0x3f,0x20,0x31,0x2e,0x30,0x20,0x3a,0x20,0x28,0x2d,0x31,0x2e,0x30, + 0x29,0x29,0x20,0x2a,0x20,0x28,0x5f,0x31,0x33,0x33,0x20,0x2b,0x20,0x31,0x2e,0x35, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x31,0x36,0x32, + 0x20,0x3d,0x20,0x5f,0x38,0x35,0x2e,0x78,0x79,0x20,0x2b,0x20,0x28,0x28,0x5f,0x31, + 0x34,0x35,0x20,0x2a,0x20,0x28,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x31, + 0x37,0x5d,0x2e,0x7a,0x77,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x29,0x20,0x2a,0x20, + 0x5f,0x38,0x35,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34, + 0x20,0x5f,0x32,0x30,0x30,0x20,0x3d,0x20,0x5f,0x38,0x35,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x5f,0x32,0x30,0x30,0x2e,0x78,0x20,0x3d,0x20,0x5f,0x31,0x36,0x32,0x2e,0x78, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x32,0x30,0x30,0x2e,0x79,0x20,0x3d,0x20,0x5f, + 0x31,0x36,0x32,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x5f,0x32,0x30,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x5f,0x6f,0x66,0x66,0x73,0x65,0x74,0x5f,0x66,0x72,0x6f,0x6d, + 0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x5f,0x70,0x78,0x20,0x3d,0x20,0x5f,0x31,0x34, + 0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x73,0x69, + 0x7a,0x65,0x5f,0x70,0x78,0x20,0x3d,0x20,0x5f,0x31,0x33,0x33,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3d,0x20,0x2d,0x5f,0x39, + 0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, + 0x20,0x5f,0x31,0x37,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x67, + 0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x63,0x6f, + 0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x6f,0x63,0x63,0x5f,0x6d, + 0x6f,0x64,0x65,0x20,0x3d,0x20,0x5f,0x31,0x37,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49, + 0x44,0x5d,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x79,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + +}; +/* + #version 430 + + layout(binding = 0) uniform sampler2D tex_depth_smp_depth; + + layout(location = 0) in vec2 v_offset_from_center_px; + layout(location = 1) in float v_half_size_px; + layout(location = 2) in float v_view_z; + layout(location = 3) flat in vec4 v_color; + layout(location = 4) flat in uint v_occ_mode; + layout(location = 0) out vec4 out_color; + + void main() + { + float _13 = length(v_offset_from_center_px); + float _16 = fwidth(_13); + vec4 col = v_color; + if (v_view_z > (textureLod(tex_depth_smp_depth, gl_FragCoord.xy / vec2(textureSize(tex_depth_smp_depth, 0)), 0.0).x + (0.001000000047497451305389404296875 + (2.0 * fwidth(v_view_z))))) + { + if (v_occ_mode == 0u) + { + col = vec4(0.0); + } + else + { + col *= 0.25; + } + } + out_color = col * (1.0 - smoothstep(v_half_size_px - _16, v_half_size_px + _16, _13)); + } + +*/ +static const uint8_t overlay_point_fs_source_glsl430[894] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x30, + 0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, + 0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x73,0x6d, + 0x70,0x5f,0x64,0x65,0x70,0x74,0x68,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, + 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69, + 0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x76,0x5f,0x6f,0x66,0x66,0x73,0x65,0x74,0x5f, + 0x66,0x72,0x6f,0x6d,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x5f,0x70,0x78,0x3b,0x0a, + 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20, + 0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f, + 0x68,0x61,0x6c,0x66,0x5f,0x73,0x69,0x7a,0x65,0x5f,0x70,0x78,0x3b,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x32,0x29,0x20,0x69,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63, + 0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x33,0x29,0x20,0x66,0x6c,0x61,0x74,0x20, + 0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b, + 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x34,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x75,0x69, + 0x6e,0x74,0x20,0x76,0x5f,0x6f,0x63,0x63,0x5f,0x6d,0x6f,0x64,0x65,0x3b,0x0a,0x6c, + 0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d, + 0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x6f,0x75,0x74, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61, + 0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x33,0x20,0x3d,0x20,0x6c,0x65,0x6e,0x67,0x74,0x68,0x28,0x76,0x5f, + 0x6f,0x66,0x66,0x73,0x65,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x63,0x65,0x6e,0x74, + 0x65,0x72,0x5f,0x70,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x31,0x36,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f, + 0x31,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f, + 0x6c,0x20,0x3d,0x20,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3e,0x20, + 0x28,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x4c,0x6f,0x64,0x28,0x74,0x65,0x78,0x5f, + 0x64,0x65,0x70,0x74,0x68,0x5f,0x73,0x6d,0x70,0x5f,0x64,0x65,0x70,0x74,0x68,0x2c, + 0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79, + 0x20,0x2f,0x20,0x76,0x65,0x63,0x32,0x28,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x53, + 0x69,0x7a,0x65,0x28,0x74,0x65,0x78,0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x73,0x6d, + 0x70,0x5f,0x64,0x65,0x70,0x74,0x68,0x2c,0x20,0x30,0x29,0x29,0x2c,0x20,0x30,0x2e, + 0x30,0x29,0x2e,0x78,0x20,0x2b,0x20,0x28,0x30,0x2e,0x30,0x30,0x31,0x30,0x30,0x30, + 0x30,0x30,0x30,0x30,0x34,0x37,0x34,0x39,0x37,0x34,0x35,0x31,0x33,0x30,0x35,0x33, + 0x38,0x39,0x34,0x30,0x34,0x32,0x39,0x36,0x38,0x37,0x35,0x20,0x2b,0x20,0x28,0x32, + 0x2e,0x30,0x20,0x2a,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x76,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x29,0x29,0x29,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x5f,0x6f,0x63, + 0x63,0x5f,0x6d,0x6f,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x75,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x30, + 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x63,0x6f,0x6c,0x20,0x2a,0x3d,0x20,0x30,0x2e,0x32,0x35,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63, + 0x6f,0x6c,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f, + 0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x73,0x69, + 0x7a,0x65,0x5f,0x70,0x78,0x20,0x2d,0x20,0x5f,0x31,0x36,0x2c,0x20,0x76,0x5f,0x68, + 0x61,0x6c,0x66,0x5f,0x73,0x69,0x7a,0x65,0x5f,0x70,0x78,0x20,0x2b,0x20,0x5f,0x31, + 0x36,0x2c,0x20,0x5f,0x31,0x33,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + struct point_instance + { + float4 p; + float4 color; + uint4 flags; + }; + + ByteAddressBuffer _17 : register(t0); + cbuffer ub_frame : register(b0) + { + row_major float4x4 _76_view : packoffset(c0); + row_major float4x4 _76_proj : packoffset(c4); + row_major float4x4 _76_view_proj : packoffset(c8); + row_major float4x4 _76_inv_view_proj : packoffset(c12); + float4 _76_camera_pos : packoffset(c16); + float4 _76_viewport : packoffset(c17); + }; + + + static float4 gl_Position; + static int gl_VertexIndex; + static int gl_InstanceIndex; + static float2 v_offset_from_center_px; + static float v_half_size_px; + static float v_view_z; + static float4 v_color; + static uint v_occ_mode; + + struct SPIRV_Cross_Input + { + uint gl_VertexIndex : SV_VertexID; + uint gl_InstanceIndex : SV_InstanceID; + }; + + struct SPIRV_Cross_Output + { + float2 v_offset_from_center_px : TEXCOORD0; + float v_half_size_px : TEXCOORD1; + float v_view_z : TEXCOORD2; + nointerpolation float4 v_color : TEXCOORD3; + nointerpolation uint v_occ_mode : TEXCOORD4; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + point_instance _25; + _25.p = asfloat(_17.Load4(gl_InstanceIndex * 48 + 0)); + _25.color = asfloat(_17.Load4(gl_InstanceIndex * 48 + 16)); + _25.flags = _17.Load4(gl_InstanceIndex * 48 + 32); + bool _46 = gl_VertexIndex == 2; + bool _50 = gl_VertexIndex == 4; + float4 _84 = float4(_25.p.xyz, 1.0f); + float4 _85 = mul(_84, _76_view_proj); + float4 _94 = mul(_84, _76_view); + float _98 = _94.z; + float half_size_px; + if (_25.flags.x == 0u) + { + half_size_px = _25.p.w * 0.5f; + } + else + { + half_size_px = (_25.p.w * 0.5f) * ((_76_viewport.y * _76_proj[1].y) / (_98 * (-2.0f))); + } + float _132 = half_size_px; + float _133 = max(_132, 0.5f); + half_size_px = _133; + float2 _145 = float2((((gl_VertexIndex == 1) || _46) || _50) ? 1.0f : (-1.0f), ((_46 || _50) || (gl_VertexIndex == 5)) ? 1.0f : (-1.0f)) * (_133 + 1.5f); + float2 _162 = _85.xy + ((_145 * (_76_viewport.zw * 2.0f)) * _85.w); + float4 _200 = _85; + _200.x = _162.x; + _200.y = _162.y; + gl_Position = _200; + v_offset_from_center_px = _145; + v_half_size_px = _133; + v_view_z = -_98; + v_color = _25.color; + v_occ_mode = _25.flags.y; + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_VertexIndex = int(stage_input.gl_VertexIndex); + gl_InstanceIndex = int(stage_input.gl_InstanceIndex); + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.v_offset_from_center_px = v_offset_from_center_px; + stage_output.v_half_size_px = v_half_size_px; + stage_output.v_view_z = v_view_z; + stage_output.v_color = v_color; + stage_output.v_occ_mode = v_occ_mode; + return stage_output; + } +*/ +static const uint8_t overlay_point_vs_source_hlsl5[2813] = { + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x70,0x6f,0x69,0x6e,0x74,0x5f,0x69,0x6e,0x73, + 0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x70,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74, + 0x34,0x20,0x66,0x6c,0x61,0x67,0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x42,0x79,0x74, + 0x65,0x41,0x64,0x64,0x72,0x65,0x73,0x73,0x42,0x75,0x66,0x66,0x65,0x72,0x20,0x5f, + 0x31,0x37,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x30, + 0x29,0x3b,0x0a,0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x66,0x72, + 0x61,0x6d,0x65,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62, + 0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a, + 0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x37,0x36,0x5f, + 0x76,0x69,0x65,0x77,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65, + 0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d, + 0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x37, + 0x36,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66, + 0x73,0x65,0x74,0x28,0x63,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77, + 0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20, + 0x5f,0x37,0x36,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20, + 0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x38,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x37,0x36,0x5f,0x69,0x6e,0x76,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f, + 0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x36,0x5f,0x63,0x61,0x6d,0x65,0x72, + 0x61,0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73, + 0x65,0x74,0x28,0x63,0x31,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x5f,0x37,0x36,0x5f,0x76,0x69,0x65,0x77,0x70,0x6f,0x72,0x74, + 0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31, + 0x37,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69, + 0x6f,0x6e,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x74,0x20,0x67, + 0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x3b,0x0a,0x73, + 0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73, + 0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74, + 0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x76,0x5f,0x6f,0x66,0x66,0x73, + 0x65,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x5f,0x70, + 0x78,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x73,0x69,0x7a,0x65,0x5f,0x70,0x78,0x3b,0x0a, + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x73,0x74, + 0x61,0x74,0x69,0x63,0x20,0x75,0x69,0x6e,0x74,0x20,0x76,0x5f,0x6f,0x63,0x63,0x5f, + 0x6d,0x6f,0x64,0x65,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50, + 0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x56,0x65, + 0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x3a,0x20,0x53,0x56,0x5f,0x56, + 0x65,0x72,0x74,0x65,0x78,0x49,0x44,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e, + 0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64, + 0x65,0x78,0x20,0x3a,0x20,0x53,0x56,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x49,0x44,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53, + 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75, + 0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x76, + 0x5f,0x6f,0x66,0x66,0x73,0x65,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x63,0x65,0x6e, + 0x74,0x65,0x72,0x5f,0x70,0x78,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52, + 0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f, + 0x68,0x61,0x6c,0x66,0x5f,0x73,0x69,0x7a,0x65,0x5f,0x70,0x78,0x20,0x3a,0x20,0x54, + 0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3a,0x20,0x54, + 0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f, + 0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x54, + 0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f, + 0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x75,0x69, + 0x6e,0x74,0x20,0x76,0x5f,0x6f,0x63,0x63,0x5f,0x6d,0x6f,0x64,0x65,0x20,0x3a,0x20, + 0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f, + 0x6e,0x20,0x3a,0x20,0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b, + 0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d, + 0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x70,0x6f,0x69,0x6e, + 0x74,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20,0x5f,0x32,0x35,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x5f,0x32,0x35,0x2e,0x70,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c, + 0x6f,0x61,0x74,0x28,0x5f,0x31,0x37,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x67,0x6c, + 0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x2a, + 0x20,0x34,0x38,0x20,0x2b,0x20,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f, + 0x32,0x35,0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f, + 0x61,0x74,0x28,0x5f,0x31,0x37,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x67,0x6c,0x5f, + 0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x2a,0x20, + 0x34,0x38,0x20,0x2b,0x20,0x31,0x36,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f, + 0x32,0x35,0x2e,0x66,0x6c,0x61,0x67,0x73,0x20,0x3d,0x20,0x5f,0x31,0x37,0x2e,0x4c, + 0x6f,0x61,0x64,0x34,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x49,0x6e,0x64,0x65,0x78,0x20,0x2a,0x20,0x34,0x38,0x20,0x2b,0x20,0x33,0x32,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x34,0x36,0x20,0x3d, + 0x20,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20, + 0x3d,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f, + 0x35,0x30,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e, + 0x64,0x65,0x78,0x20,0x3d,0x3d,0x20,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x5f,0x38,0x34,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x28,0x5f,0x32,0x35,0x2e,0x70,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31,0x2e,0x30, + 0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f, + 0x38,0x35,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x5f,0x38,0x34,0x2c,0x20,0x5f,0x37, + 0x36,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x39,0x34,0x20,0x3d,0x20,0x6d, + 0x75,0x6c,0x28,0x5f,0x38,0x34,0x2c,0x20,0x5f,0x37,0x36,0x5f,0x76,0x69,0x65,0x77, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x38, + 0x20,0x3d,0x20,0x5f,0x39,0x34,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x68,0x61,0x6c,0x66,0x5f,0x73,0x69,0x7a,0x65,0x5f,0x70,0x78, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x32,0x35,0x2e,0x66,0x6c, + 0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x30,0x75,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x68,0x61,0x6c,0x66,0x5f, + 0x73,0x69,0x7a,0x65,0x5f,0x70,0x78,0x20,0x3d,0x20,0x5f,0x32,0x35,0x2e,0x70,0x2e, + 0x77,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x68,0x61,0x6c,0x66,0x5f,0x73,0x69,0x7a,0x65, + 0x5f,0x70,0x78,0x20,0x3d,0x20,0x28,0x5f,0x32,0x35,0x2e,0x70,0x2e,0x77,0x20,0x2a, + 0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2a,0x20,0x28,0x28,0x5f,0x37,0x36,0x5f,0x76, + 0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x37,0x36,0x5f, + 0x70,0x72,0x6f,0x6a,0x5b,0x31,0x5d,0x2e,0x79,0x29,0x20,0x2f,0x20,0x28,0x5f,0x39, + 0x38,0x20,0x2a,0x20,0x28,0x2d,0x32,0x2e,0x30,0x66,0x29,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x33,0x32,0x20,0x3d,0x20,0x68,0x61,0x6c,0x66,0x5f,0x73,0x69,0x7a,0x65,0x5f, + 0x70,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x33,0x33,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x5f,0x31,0x33,0x32,0x2c,0x20,0x30, + 0x2e,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x68,0x61,0x6c,0x66,0x5f,0x73, + 0x69,0x7a,0x65,0x5f,0x70,0x78,0x20,0x3d,0x20,0x5f,0x31,0x33,0x33,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x31,0x34,0x35,0x20,0x3d, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x28,0x28,0x28,0x67,0x6c,0x5f,0x56,0x65, + 0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x3d,0x3d,0x20,0x31,0x29,0x20, + 0x7c,0x7c,0x20,0x5f,0x34,0x36,0x29,0x20,0x7c,0x7c,0x20,0x5f,0x35,0x30,0x29,0x20, + 0x3f,0x20,0x31,0x2e,0x30,0x66,0x20,0x3a,0x20,0x28,0x2d,0x31,0x2e,0x30,0x66,0x29, + 0x2c,0x20,0x28,0x28,0x5f,0x34,0x36,0x20,0x7c,0x7c,0x20,0x5f,0x35,0x30,0x29,0x20, + 0x7c,0x7c,0x20,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64, + 0x65,0x78,0x20,0x3d,0x3d,0x20,0x35,0x29,0x29,0x20,0x3f,0x20,0x31,0x2e,0x30,0x66, + 0x20,0x3a,0x20,0x28,0x2d,0x31,0x2e,0x30,0x66,0x29,0x29,0x20,0x2a,0x20,0x28,0x5f, + 0x31,0x33,0x33,0x20,0x2b,0x20,0x31,0x2e,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x31,0x36,0x32,0x20,0x3d,0x20,0x5f, + 0x38,0x35,0x2e,0x78,0x79,0x20,0x2b,0x20,0x28,0x28,0x5f,0x31,0x34,0x35,0x20,0x2a, + 0x20,0x28,0x5f,0x37,0x36,0x5f,0x76,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x2e,0x7a, + 0x77,0x20,0x2a,0x20,0x32,0x2e,0x30,0x66,0x29,0x29,0x20,0x2a,0x20,0x5f,0x38,0x35, + 0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x5f,0x32,0x30,0x30,0x20,0x3d,0x20,0x5f,0x38,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x5f,0x32,0x30,0x30,0x2e,0x78,0x20,0x3d,0x20,0x5f,0x31,0x36,0x32,0x2e,0x78,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x5f,0x32,0x30,0x30,0x2e,0x79,0x20,0x3d,0x20,0x5f,0x31, + 0x36,0x32,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73, + 0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x5f,0x32,0x30,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x5f,0x6f,0x66,0x66,0x73,0x65,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f, + 0x63,0x65,0x6e,0x74,0x65,0x72,0x5f,0x70,0x78,0x20,0x3d,0x20,0x5f,0x31,0x34,0x35, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x73,0x69,0x7a, + 0x65,0x5f,0x70,0x78,0x20,0x3d,0x20,0x5f,0x31,0x33,0x33,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3d,0x20,0x2d,0x5f,0x39,0x38, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20, + 0x5f,0x32,0x35,0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x5f,0x6f,0x63,0x63,0x5f,0x6d,0x6f,0x64,0x65,0x20,0x3d,0x20,0x5f,0x32,0x35,0x2e, + 0x66,0x6c,0x61,0x67,0x73,0x2e,0x79,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52, + 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d, + 0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, + 0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75, + 0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74, + 0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x3d,0x20,0x69,0x6e,0x74,0x28,0x73,0x74, + 0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x56,0x65,0x72, + 0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67, + 0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20, + 0x3d,0x20,0x69,0x6e,0x74,0x28,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75, + 0x74,0x2e,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64, + 0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61, + 0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f, + 0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73, + 0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50, + 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73, + 0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65, + 0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x6f,0x66,0x66,0x73,0x65,0x74, + 0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x5f,0x70,0x78,0x20, + 0x3d,0x20,0x76,0x5f,0x6f,0x66,0x66,0x73,0x65,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f, + 0x63,0x65,0x6e,0x74,0x65,0x72,0x5f,0x70,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73, + 0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x68,0x61, + 0x6c,0x66,0x5f,0x73,0x69,0x7a,0x65,0x5f,0x70,0x78,0x20,0x3d,0x20,0x76,0x5f,0x68, + 0x61,0x6c,0x66,0x5f,0x73,0x69,0x7a,0x65,0x5f,0x70,0x78,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3d,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74, + 0x70,0x75,0x74,0x2e,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65, + 0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x6f,0x63,0x63,0x5f,0x6d,0x6f, + 0x64,0x65,0x20,0x3d,0x20,0x76,0x5f,0x6f,0x63,0x63,0x5f,0x6d,0x6f,0x64,0x65,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67, + 0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + Texture2D tex_depth : register(t0); + SamplerState smp_depth : register(s0); + + static float4 gl_FragCoord; + static float2 v_offset_from_center_px; + static float v_half_size_px; + static float v_view_z; + static float4 v_color; + static uint v_occ_mode; + static float4 out_color; + + struct SPIRV_Cross_Input + { + float2 v_offset_from_center_px : TEXCOORD0; + float v_half_size_px : TEXCOORD1; + float v_view_z : TEXCOORD2; + nointerpolation float4 v_color : TEXCOORD3; + nointerpolation uint v_occ_mode : TEXCOORD4; + float4 gl_FragCoord : SV_Position; + }; + + struct SPIRV_Cross_Output + { + float4 out_color : SV_Target0; + }; + + uint2 spvTextureSize(Texture2D Tex, uint Level, out uint Param) + { + uint2 ret; + Tex.GetDimensions(Level, ret.x, ret.y, Param); + return ret; + } + + void frag_main() + { + float _13 = length(v_offset_from_center_px); + float _16 = fwidth(_13); + uint _51_dummy_parameter; + float4 col = v_color; + if (v_view_z > (tex_depth.SampleLevel(smp_depth, gl_FragCoord.xy / float2(int2(spvTextureSize(tex_depth, uint(0), _51_dummy_parameter))), 0.0f).x + (0.001000000047497451305389404296875f + (2.0f * fwidth(v_view_z))))) + { + if (v_occ_mode == 0u) + { + col = 0.0f.xxxx; + } + else + { + col *= 0.25f; + } + } + out_color = col * (1.0f - smoothstep(v_half_size_px - _16, v_half_size_px + _16, _13)); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_FragCoord = stage_input.gl_FragCoord; + gl_FragCoord.w = 1.0 / gl_FragCoord.w; + v_offset_from_center_px = stage_input.v_offset_from_center_px; + v_half_size_px = stage_input.v_half_size_px; + v_view_z = stage_input.v_view_z; + v_color = stage_input.v_color; + v_occ_mode = stage_input.v_occ_mode; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.out_color = out_color; + return stage_output; + } +*/ +static const uint8_t overlay_point_fs_source_hlsl5[1902] = { + 0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x3e,0x20,0x74,0x65,0x78,0x5f,0x64,0x65,0x70,0x74,0x68,0x20,0x3a,0x20,0x72,0x65, + 0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x30,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70, + 0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x64,0x65,0x70, + 0x74,0x68,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x30, + 0x29,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x3b,0x0a, + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x76,0x5f, + 0x6f,0x66,0x66,0x73,0x65,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x63,0x65,0x6e,0x74, + 0x65,0x72,0x5f,0x70,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x73,0x69,0x7a,0x65,0x5f, + 0x70,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69, + 0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x75,0x69,0x6e,0x74,0x20,0x76,0x5f, + 0x6f,0x63,0x63,0x5f,0x6d,0x6f,0x64,0x65,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56, + 0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x76,0x5f,0x6f,0x66,0x66,0x73, + 0x65,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x5f,0x70, + 0x78,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f, + 0x73,0x69,0x7a,0x65,0x5f,0x70,0x78,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f, + 0x52,0x44,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76, + 0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f, + 0x52,0x44,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72, + 0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f, + 0x52,0x44,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72, + 0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x75,0x69,0x6e,0x74,0x20,0x76,0x5f, + 0x6f,0x63,0x63,0x5f,0x6d,0x6f,0x64,0x65,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f, + 0x4f,0x52,0x44,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x20,0x3a,0x20, + 0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a, + 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, + 0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x20,0x3a,0x20,0x53,0x56,0x5f,0x54,0x61,0x72,0x67,0x65,0x74,0x30,0x3b,0x0a, + 0x7d,0x3b,0x0a,0x0a,0x75,0x69,0x6e,0x74,0x32,0x20,0x73,0x70,0x76,0x54,0x65,0x78, + 0x74,0x75,0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x54,0x65,0x78,0x74,0x75,0x72,0x65, + 0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x54,0x65,0x78,0x2c,0x20, + 0x75,0x69,0x6e,0x74,0x20,0x4c,0x65,0x76,0x65,0x6c,0x2c,0x20,0x6f,0x75,0x74,0x20, + 0x75,0x69,0x6e,0x74,0x20,0x50,0x61,0x72,0x61,0x6d,0x29,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x75,0x69,0x6e,0x74,0x32,0x20,0x72,0x65,0x74,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x54,0x65,0x78,0x2e,0x47,0x65,0x74,0x44,0x69,0x6d,0x65,0x6e,0x73,0x69,0x6f, + 0x6e,0x73,0x28,0x4c,0x65,0x76,0x65,0x6c,0x2c,0x20,0x72,0x65,0x74,0x2e,0x78,0x2c, + 0x20,0x72,0x65,0x74,0x2e,0x79,0x2c,0x20,0x50,0x61,0x72,0x61,0x6d,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x72,0x65,0x74,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69, + 0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x33,0x20,0x3d,0x20,0x6c,0x65,0x6e,0x67,0x74,0x68,0x28,0x76,0x5f,0x6f, + 0x66,0x66,0x73,0x65,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x63,0x65,0x6e,0x74,0x65, + 0x72,0x5f,0x70,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x36,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31, + 0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x5f,0x35,0x31, + 0x5f,0x64,0x75,0x6d,0x6d,0x79,0x5f,0x70,0x61,0x72,0x61,0x6d,0x65,0x74,0x65,0x72, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c, + 0x20,0x3d,0x20,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3e,0x20,0x28, + 0x74,0x65,0x78,0x5f,0x64,0x65,0x70,0x74,0x68,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65, + 0x4c,0x65,0x76,0x65,0x6c,0x28,0x73,0x6d,0x70,0x5f,0x64,0x65,0x70,0x74,0x68,0x2c, + 0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79, + 0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x69,0x6e,0x74,0x32,0x28,0x73, + 0x70,0x76,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x74,0x65, + 0x78,0x5f,0x64,0x65,0x70,0x74,0x68,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x30,0x29, + 0x2c,0x20,0x5f,0x35,0x31,0x5f,0x64,0x75,0x6d,0x6d,0x79,0x5f,0x70,0x61,0x72,0x61, + 0x6d,0x65,0x74,0x65,0x72,0x29,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x2e, + 0x78,0x20,0x2b,0x20,0x28,0x30,0x2e,0x30,0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30, + 0x30,0x34,0x37,0x34,0x39,0x37,0x34,0x35,0x31,0x33,0x30,0x35,0x33,0x38,0x39,0x34, + 0x30,0x34,0x32,0x39,0x36,0x38,0x37,0x35,0x66,0x20,0x2b,0x20,0x28,0x32,0x2e,0x30, + 0x66,0x20,0x2a,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x76,0x5f,0x76,0x69,0x65, + 0x77,0x5f,0x7a,0x29,0x29,0x29,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x5f,0x6f,0x63,0x63, + 0x5f,0x6d,0x6f,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x75,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x63,0x6f,0x6c,0x20,0x3d,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78, + 0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x63,0x6f,0x6c,0x20,0x2a,0x3d,0x20,0x30,0x2e,0x32,0x35,0x66,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63, + 0x6f,0x6c,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x73,0x6d,0x6f, + 0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x73, + 0x69,0x7a,0x65,0x5f,0x70,0x78,0x20,0x2d,0x20,0x5f,0x31,0x36,0x2c,0x20,0x76,0x5f, + 0x68,0x61,0x6c,0x66,0x5f,0x73,0x69,0x7a,0x65,0x5f,0x70,0x78,0x20,0x2b,0x20,0x5f, + 0x31,0x36,0x2c,0x20,0x5f,0x31,0x33,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50, + 0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74, + 0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73, + 0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e, + 0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72, + 0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f, + 0x69,0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f, + 0x72,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43, + 0x6f,0x6f,0x72,0x64,0x2e,0x77,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2f,0x20,0x67, + 0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x77,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x5f,0x6f,0x66,0x66,0x73,0x65,0x74,0x5f,0x66,0x72,0x6f,0x6d, + 0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x5f,0x70,0x78,0x20,0x3d,0x20,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x6f,0x66,0x66,0x73,0x65, + 0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x5f,0x70,0x78, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x73,0x69,0x7a, + 0x65,0x5f,0x70,0x78,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70, + 0x75,0x74,0x2e,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x73,0x69,0x7a,0x65,0x5f,0x70, + 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20, + 0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75, + 0x74,0x2e,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x5f,0x6f,0x63,0x63,0x5f,0x6d,0x6f,0x64,0x65,0x20,0x3d,0x20,0x73,0x74,0x61,0x67, + 0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x6f,0x63,0x63,0x5f,0x6d,0x6f, + 0x64,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69, + 0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, + 0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67, + 0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74, + 0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + struct point_instance + { + float4 p; + float4 color; + uint4 flags; + }; + + struct point_instances + { + point_instance instances[1]; + }; + + struct ub_frame + { + float4x4 view; + float4x4 proj; + float4x4 view_proj; + float4x4 inv_view_proj; + float4 camera_pos; + float4 viewport; + }; + + struct main0_out + { + float2 v_offset_from_center_px [[user(locn0)]]; + float v_half_size_px [[user(locn1)]]; + float v_view_z [[user(locn2)]]; + float4 v_color [[user(locn3)]]; + uint v_occ_mode [[user(locn4)]]; + float4 gl_Position [[position]]; + }; + + vertex main0_out main0(constant ub_frame& _76 [[buffer(0)]], const device point_instances& _17 [[buffer(8)]], uint gl_InstanceIndex [[instance_id]], uint gl_VertexIndex [[vertex_id]]) + { + main0_out out = {}; + bool _46 = int(gl_VertexIndex) == 2; + bool _50 = int(gl_VertexIndex) == 4; + float4 _84 = float4(_17.instances[int(gl_InstanceIndex)].p.xyz, 1.0); + float4 _85 = _76.view_proj * _84; + float4 _94 = _76.view * _84; + float _98 = _94.z; + float half_size_px; + if (_17.instances[int(gl_InstanceIndex)].flags.x == 0u) + { + half_size_px = _17.instances[int(gl_InstanceIndex)].p.w * 0.5; + } + else + { + half_size_px = (_17.instances[int(gl_InstanceIndex)].p.w * 0.5) * ((_76.viewport.y * _76.proj[1].y) / (_98 * (-2.0))); + } + float _132 = half_size_px; + float _133 = fast::max(_132, 0.5); + half_size_px = _133; + float2 _145 = float2((((int(gl_VertexIndex) == 1) || _46) || _50) ? 1.0 : (-1.0), ((_46 || _50) || (int(gl_VertexIndex) == 5)) ? 1.0 : (-1.0)) * (_133 + 1.5); + float2 _162 = _85.xy + ((_145 * (_76.viewport.zw * 2.0)) * _85.w); + float4 _200 = _85; + _200.x = _162.x; + _200.y = _162.y; + out.gl_Position = _200; + out.v_offset_from_center_px = _145; + out.v_half_size_px = _133; + out.v_view_z = -_98; + out.v_color = _17.instances[int(gl_InstanceIndex)].color; + out.v_occ_mode = _17.instances[int(gl_InstanceIndex)].flags.y; + return out; + } + +*/ +static const uint8_t overlay_point_vs_source_metal_macos[2072] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x70, + 0x6f,0x69,0x6e,0x74,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x34,0x20,0x66,0x6c,0x61,0x67,0x73,0x3b, + 0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x70,0x6f,0x69,0x6e, + 0x74,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x70,0x6f,0x69,0x6e,0x74,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x31,0x5d,0x3b,0x0a,0x7d, + 0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x66,0x72,0x61, + 0x6d,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78, + 0x34,0x20,0x76,0x69,0x65,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x78,0x34,0x20,0x70,0x72,0x6f,0x6a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f, + 0x6a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20, + 0x69,0x6e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x61,0x6d,0x65,0x72,0x61, + 0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x76,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73, + 0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x76,0x5f,0x6f, + 0x66,0x66,0x73,0x65,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x63,0x65,0x6e,0x74,0x65, + 0x72,0x5f,0x70,0x78,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e, + 0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x73,0x69,0x7a,0x65,0x5f,0x70,0x78,0x20,0x5b, + 0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29,0x5d,0x5d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x76,0x69,0x65,0x77, + 0x5f,0x7a,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x32,0x29, + 0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f, + 0x63,0x6e,0x33,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74, + 0x20,0x76,0x5f,0x6f,0x63,0x63,0x5f,0x6d,0x6f,0x64,0x65,0x20,0x5b,0x5b,0x75,0x73, + 0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x34,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74, + 0x69,0x6f,0x6e,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d, + 0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,0x65,0x78,0x20,0x6d,0x61,0x69, + 0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x63,0x6f,0x6e, + 0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x26,0x20, + 0x5f,0x37,0x36,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x30,0x29,0x5d, + 0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x20, + 0x70,0x6f,0x69,0x6e,0x74,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x26, + 0x20,0x5f,0x31,0x37,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x38,0x29, + 0x5d,0x5d,0x2c,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x5b,0x5b,0x69,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x5f,0x69,0x64,0x5d,0x5d,0x2c,0x20,0x75,0x69,0x6e,0x74,0x20, + 0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x5b, + 0x5b,0x76,0x65,0x72,0x74,0x65,0x78,0x5f,0x69,0x64,0x5d,0x5d,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75, + 0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c, + 0x20,0x5f,0x34,0x36,0x20,0x3d,0x20,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x56,0x65, + 0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x3d,0x3d,0x20,0x32,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x35,0x30,0x20,0x3d,0x20, + 0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64, + 0x65,0x78,0x29,0x20,0x3d,0x3d,0x20,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x5f,0x38,0x34,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x28,0x5f,0x31,0x37,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b, + 0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49, + 0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x70,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31,0x2e, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f, + 0x38,0x35,0x20,0x3d,0x20,0x5f,0x37,0x36,0x2e,0x76,0x69,0x65,0x77,0x5f,0x70,0x72, + 0x6f,0x6a,0x20,0x2a,0x20,0x5f,0x38,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x5f,0x39,0x34,0x20,0x3d,0x20,0x5f,0x37,0x36,0x2e,0x76, + 0x69,0x65,0x77,0x20,0x2a,0x20,0x5f,0x38,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x38,0x20,0x3d,0x20,0x5f,0x39,0x34,0x2e,0x7a, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x68,0x61,0x6c,0x66, + 0x5f,0x73,0x69,0x7a,0x65,0x5f,0x70,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x5f,0x31,0x37,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b, + 0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49, + 0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d, + 0x3d,0x20,0x30,0x75,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x68,0x61,0x6c,0x66,0x5f,0x73,0x69,0x7a,0x65,0x5f,0x70,0x78, + 0x20,0x3d,0x20,0x5f,0x31,0x37,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73, + 0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x49,0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x70,0x2e,0x77,0x20,0x2a,0x20,0x30,0x2e, + 0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, + 0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x68,0x61,0x6c,0x66,0x5f,0x73,0x69,0x7a,0x65,0x5f,0x70,0x78,0x20,0x3d,0x20,0x28, + 0x5f,0x31,0x37,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x69,0x6e, + 0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64, + 0x65,0x78,0x29,0x5d,0x2e,0x70,0x2e,0x77,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20, + 0x2a,0x20,0x28,0x28,0x5f,0x37,0x36,0x2e,0x76,0x69,0x65,0x77,0x70,0x6f,0x72,0x74, + 0x2e,0x79,0x20,0x2a,0x20,0x5f,0x37,0x36,0x2e,0x70,0x72,0x6f,0x6a,0x5b,0x31,0x5d, + 0x2e,0x79,0x29,0x20,0x2f,0x20,0x28,0x5f,0x39,0x38,0x20,0x2a,0x20,0x28,0x2d,0x32, + 0x2e,0x30,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x32,0x20,0x3d,0x20,0x68,0x61, + 0x6c,0x66,0x5f,0x73,0x69,0x7a,0x65,0x5f,0x70,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x33,0x20,0x3d,0x20,0x66,0x61,0x73, + 0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x5f,0x31,0x33,0x32,0x2c,0x20,0x30,0x2e,0x35, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x68,0x61,0x6c,0x66,0x5f,0x73,0x69,0x7a,0x65, + 0x5f,0x70,0x78,0x20,0x3d,0x20,0x5f,0x31,0x33,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x31,0x34,0x35,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x32,0x28,0x28,0x28,0x28,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x56, + 0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x3d,0x3d,0x20,0x31, + 0x29,0x20,0x7c,0x7c,0x20,0x5f,0x34,0x36,0x29,0x20,0x7c,0x7c,0x20,0x5f,0x35,0x30, + 0x29,0x20,0x3f,0x20,0x31,0x2e,0x30,0x20,0x3a,0x20,0x28,0x2d,0x31,0x2e,0x30,0x29, + 0x2c,0x20,0x28,0x28,0x5f,0x34,0x36,0x20,0x7c,0x7c,0x20,0x5f,0x35,0x30,0x29,0x20, + 0x7c,0x7c,0x20,0x28,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65, + 0x78,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x3d,0x3d,0x20,0x35,0x29,0x29,0x20,0x3f, + 0x20,0x31,0x2e,0x30,0x20,0x3a,0x20,0x28,0x2d,0x31,0x2e,0x30,0x29,0x29,0x20,0x2a, + 0x20,0x28,0x5f,0x31,0x33,0x33,0x20,0x2b,0x20,0x31,0x2e,0x35,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x31,0x36,0x32,0x20,0x3d, + 0x20,0x5f,0x38,0x35,0x2e,0x78,0x79,0x20,0x2b,0x20,0x28,0x28,0x5f,0x31,0x34,0x35, + 0x20,0x2a,0x20,0x28,0x5f,0x37,0x36,0x2e,0x76,0x69,0x65,0x77,0x70,0x6f,0x72,0x74, + 0x2e,0x7a,0x77,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x29,0x20,0x2a,0x20,0x5f,0x38, + 0x35,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x5f,0x32,0x30,0x30,0x20,0x3d,0x20,0x5f,0x38,0x35,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x5f,0x32,0x30,0x30,0x2e,0x78,0x20,0x3d,0x20,0x5f,0x31,0x36,0x32,0x2e,0x78, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x32,0x30,0x30,0x2e,0x79,0x20,0x3d,0x20,0x5f, + 0x31,0x36,0x32,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67, + 0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x5f,0x32,0x30, + 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x6f,0x66,0x66, + 0x73,0x65,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x5f, + 0x70,0x78,0x20,0x3d,0x20,0x5f,0x31,0x34,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f, + 0x75,0x74,0x2e,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x73,0x69,0x7a,0x65,0x5f,0x70, + 0x78,0x20,0x3d,0x20,0x5f,0x31,0x33,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75, + 0x74,0x2e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3d,0x20,0x2d,0x5f,0x39, + 0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x20,0x3d,0x20,0x5f,0x31,0x37,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x73,0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x6f,0x63,0x63,0x5f,0x6d, + 0x6f,0x64,0x65,0x20,0x3d,0x20,0x5f,0x31,0x37,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x73,0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61, + 0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x66,0x6c,0x61,0x67,0x73, + 0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f, + 0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + struct main0_out + { + float4 out_color [[color(0)]]; + }; + + struct main0_in + { + float2 v_offset_from_center_px [[user(locn0)]]; + float v_half_size_px [[user(locn1)]]; + float v_view_z [[user(locn2)]]; + float4 v_color [[user(locn3), flat]]; + uint v_occ_mode [[user(locn4)]]; + }; + + fragment main0_out main0(main0_in in [[stage_in]], texture2d tex_depth [[texture(0)]], sampler smp_depth [[sampler(0)]], float4 gl_FragCoord [[position]]) + { + main0_out out = {}; + float _13 = length(in.v_offset_from_center_px); + float _16 = fwidth(_13); + float4 col = in.v_color; + if (in.v_view_z > (tex_depth.sample(smp_depth, (gl_FragCoord.xy / float2(int2(tex_depth.get_width(), tex_depth.get_height()))), level(0.0)).x + (0.001000000047497451305389404296875 + (2.0 * fwidth(in.v_view_z))))) + { + if (in.v_occ_mode == 0u) + { + col = float4(0.0); + } + else + { + col *= 0.25; + } + } + out.out_color = col * (1.0 - smoothstep(in.v_half_size_px - _16, in.v_half_size_px + _16, _13)); + return out; + } + +*/ +static const uint8_t overlay_point_fs_source_metal_macos[1152] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d, + 0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20, + 0x5b,0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69, + 0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x76, + 0x5f,0x6f,0x66,0x66,0x73,0x65,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x63,0x65,0x6e, + 0x74,0x65,0x72,0x5f,0x70,0x78,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f, + 0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x73,0x69,0x7a,0x65,0x5f,0x70,0x78, + 0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29,0x5d,0x5d, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e, + 0x32,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28, + 0x6c,0x6f,0x63,0x6e,0x33,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x76,0x5f,0x6f,0x63,0x63,0x5f,0x6d, + 0x6f,0x64,0x65,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x34, + 0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e, + 0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e, + 0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78,0x74, + 0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78, + 0x5f,0x64,0x65,0x70,0x74,0x68,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65, + 0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73, + 0x6d,0x70,0x5f,0x64,0x65,0x70,0x74,0x68,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x20,0x5b,0x5b,0x70, + 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d, + 0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x33,0x20,0x3d,0x20,0x6c,0x65,0x6e,0x67,0x74,0x68,0x28,0x69,0x6e,0x2e,0x76, + 0x5f,0x6f,0x66,0x66,0x73,0x65,0x74,0x5f,0x66,0x72,0x6f,0x6d,0x5f,0x63,0x65,0x6e, + 0x74,0x65,0x72,0x5f,0x70,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x36,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28, + 0x5f,0x31,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x63,0x6f,0x6c,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3e,0x20,0x28,0x74,0x65,0x78,0x5f,0x64,0x65, + 0x70,0x74,0x68,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x64, + 0x65,0x70,0x74,0x68,0x2c,0x20,0x28,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f, + 0x6f,0x72,0x64,0x2e,0x78,0x79,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28, + 0x69,0x6e,0x74,0x32,0x28,0x74,0x65,0x78,0x5f,0x64,0x65,0x70,0x74,0x68,0x2e,0x67, + 0x65,0x74,0x5f,0x77,0x69,0x64,0x74,0x68,0x28,0x29,0x2c,0x20,0x74,0x65,0x78,0x5f, + 0x64,0x65,0x70,0x74,0x68,0x2e,0x67,0x65,0x74,0x5f,0x68,0x65,0x69,0x67,0x68,0x74, + 0x28,0x29,0x29,0x29,0x29,0x2c,0x20,0x6c,0x65,0x76,0x65,0x6c,0x28,0x30,0x2e,0x30, + 0x29,0x29,0x2e,0x78,0x20,0x2b,0x20,0x28,0x30,0x2e,0x30,0x30,0x31,0x30,0x30,0x30, + 0x30,0x30,0x30,0x30,0x34,0x37,0x34,0x39,0x37,0x34,0x35,0x31,0x33,0x30,0x35,0x33, + 0x38,0x39,0x34,0x30,0x34,0x32,0x39,0x36,0x38,0x37,0x35,0x20,0x2b,0x20,0x28,0x32, + 0x2e,0x30,0x20,0x2a,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x69,0x6e,0x2e,0x76, + 0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x29,0x29,0x29,0x29,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x69, + 0x6e,0x2e,0x76,0x5f,0x6f,0x63,0x63,0x5f,0x6d,0x6f,0x64,0x65,0x20,0x3d,0x3d,0x20, + 0x30,0x75,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x20,0x3d,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65, + 0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x20,0x2a,0x3d, + 0x20,0x30,0x2e,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f, + 0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x20,0x2a, + 0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74, + 0x65,0x70,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x73,0x69,0x7a, + 0x65,0x5f,0x70,0x78,0x20,0x2d,0x20,0x5f,0x31,0x36,0x2c,0x20,0x69,0x6e,0x2e,0x76, + 0x5f,0x68,0x61,0x6c,0x66,0x5f,0x73,0x69,0x7a,0x65,0x5f,0x70,0x78,0x20,0x2b,0x20, + 0x5f,0x31,0x36,0x2c,0x20,0x5f,0x31,0x33,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + +}; +static inline const sg_shader_desc* overlay_point_prog_shader_desc(sg_backend backend) { + if (backend == SG_BACKEND_GLCORE) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)overlay_point_vs_source_glsl430; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)overlay_point_fs_source_glsl430; + desc.fragment_func.entry = "main"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 288; + desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[0].glsl_uniforms[0].array_count = 18; + desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_frame"; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.glsl_binding_n = 0; + desc.views[1].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[1].texture.image_type = SG_IMAGETYPE_2D; + desc.views[1].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[1].texture.multisampled = false; + desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[0].view_slot = 1; + desc.texture_sampler_pairs[0].sampler_slot = 0; + desc.texture_sampler_pairs[0].glsl_name = "tex_depth_smp_depth"; + desc.label = "overlay_point_prog_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_D3D11) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)overlay_point_vs_source_hlsl5; + desc.vertex_func.d3d11_target = "vs_5_0"; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)overlay_point_fs_source_hlsl5; + desc.fragment_func.d3d11_target = "ps_5_0"; + desc.fragment_func.entry = "main"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 288; + desc.uniform_blocks[0].hlsl_register_b_n = 0; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.hlsl_register_t_n = 0; + desc.views[1].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[1].texture.image_type = SG_IMAGETYPE_2D; + desc.views[1].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[1].texture.multisampled = false; + desc.views[1].texture.hlsl_register_t_n = 0; + desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[0].hlsl_register_s_n = 0; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[0].view_slot = 1; + desc.texture_sampler_pairs[0].sampler_slot = 0; + desc.label = "overlay_point_prog_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_METAL_MACOS) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)overlay_point_vs_source_metal_macos; + desc.vertex_func.entry = "main0"; + desc.fragment_func.source = (const char*)overlay_point_fs_source_metal_macos; + desc.fragment_func.entry = "main0"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 288; + desc.uniform_blocks[0].msl_buffer_n = 0; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.msl_buffer_n = 8; + desc.views[1].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[1].texture.image_type = SG_IMAGETYPE_2D; + desc.views[1].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[1].texture.multisampled = false; + desc.views[1].texture.msl_texture_n = 0; + desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[0].msl_sampler_n = 0; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[0].view_slot = 1; + desc.texture_sampler_pairs[0].sampler_slot = 0; + desc.label = "overlay_point_prog_shader"; + } + return &desc; + } + return 0; +} diff --git a/samples/shaders/generated/prefilter.glsl.h b/samples/shaders/generated/prefilter.glsl.h new file mode 100644 index 0000000..775de87 --- /dev/null +++ b/samples/shaders/generated/prefilter.glsl.h @@ -0,0 +1,1090 @@ +#pragma once +/* + #version:1# (machine generated, don't edit!) + + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) + + Cmdline: + sokol-shdc --input E:/box/box3d/samples/shaders/ibl/prefilter.glsl --output E:/box/box3d/samples/shaders/generated/prefilter.glsl.h --slang hlsl5:metal_macos:glsl430 + + Overview: + ========= + Shader program: 'build': + Get shader desc: prefilter_build_shader_desc(sg_query_backend()); + Vertex Shader: vs + Fragment Shader: fs + Attributes: + Bindings: + Uniform block 'ub_pass': + C struct: prefilter_ub_pass_t + Bind slot: UB_prefilter_ub_pass => 0 + Texture 'tex_sky': + Image type: SG_IMAGETYPE_CUBE + Sample type: SG_IMAGESAMPLETYPE_FLOAT + Multisampled: false + Bind slot: VIEW_prefilter_tex_sky => 0 + Sampler 'smp_sky': + Type: SG_SAMPLERTYPE_FILTERING + Bind slot: SMP_prefilter_smp_sky => 0 +*/ +#if !defined(SOKOL_GFX_INCLUDED) +#error "Please include sokol_gfx.h before prefilter.glsl.h" +#endif +#if !defined(SOKOL_SHDC_ALIGN) +#if defined(_MSC_VER) +#define SOKOL_SHDC_ALIGN(a) __declspec(align(a)) +#else +#define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) +#endif +#endif +#define UB_prefilter_ub_pass (0) +#define VIEW_prefilter_tex_sky (0) +#define SMP_prefilter_smp_sky (0) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct prefilter_ub_pass_t { + Vec4 face_right; + Vec4 face_up; + Vec4 face_forward; + Vec4 params; +} prefilter_ub_pass_t; +#pragma pack(pop) +/* + #version 430 + + layout(location = 0) out vec2 v_uv; + + void main() + { + vec2 _27 = (vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2)) * 2.0) - vec2(1.0); + v_uv = (_27 * 0.5) + vec2(0.5); + gl_Position = vec4(_27, 0.0, 1.0); + } + +*/ +static const uint8_t prefilter_vs_source_glsl430[240] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x32,0x20,0x76,0x5f,0x75,0x76, + 0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x32,0x37,0x20,0x3d,0x20, + 0x28,0x76,0x65,0x63,0x32,0x28,0x66,0x6c,0x6f,0x61,0x74,0x28,0x28,0x67,0x6c,0x5f, + 0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x44,0x20,0x3c,0x3c,0x20,0x31,0x29,0x20,0x26, + 0x20,0x32,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x67,0x6c,0x5f,0x56,0x65, + 0x72,0x74,0x65,0x78,0x49,0x44,0x20,0x26,0x20,0x32,0x29,0x29,0x20,0x2a,0x20,0x32, + 0x2e,0x30,0x29,0x20,0x2d,0x20,0x76,0x65,0x63,0x32,0x28,0x31,0x2e,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x75,0x76,0x20,0x3d,0x20,0x28,0x5f,0x32,0x37, + 0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x76,0x65,0x63,0x32,0x28,0x30, + 0x2e,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x32,0x37,0x2c, + 0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + +}; +/* + #version 430 + + uniform vec4 ub_pass[4]; + layout(binding = 0) uniform samplerCube tex_sky_smp_sky; + + layout(location = 0) in vec2 v_uv; + layout(location = 0) out vec4 out_color; + + float radicalInverseVdC(inout uint bits) + { + bits = (bits << 16u) | (bits >> 16u); + bits = ((bits & 1431655765u) << 1u) | ((bits & 2863311530u) >> 1u); + bits = ((bits & 858993459u) << 2u) | ((bits & 3435973836u) >> 2u); + bits = ((bits & 252645135u) << 4u) | ((bits & 4042322160u) >> 4u); + bits = ((bits & 16711935u) << 8u) | ((bits & 4278255360u) >> 8u); + return float(bits) * 2.3283064365386962890625e-10; + } + + vec2 hammersley(uint i, uint n) + { + uint param = i; + float _88 = radicalInverseVdC(param); + return vec2(float(i) / float(n), _88); + } + + vec3 importanceSampleGGX(vec2 Xi, vec3 N, float roughness) + { + float _95 = roughness * roughness; + float _101 = 6.283185482025146484375 * Xi.x; + float _116 = sqrt((1.0 - Xi.y) / (1.0 + (((_95 * _95) - 1.0) * Xi.y))); + float _124 = sqrt(max(1.0 - (_116 * _116), 0.0)); + bvec3 _146 = bvec3(abs(N.z) < 0.999000012874603271484375); + vec3 _152 = normalize(cross(vec3(_146.x ? vec3(0.0, 0.0, 1.0).x : vec3(1.0, 0.0, 0.0).x, _146.y ? vec3(0.0, 0.0, 1.0).y : vec3(1.0, 0.0, 0.0).y, _146.z ? vec3(0.0, 0.0, 1.0).z : vec3(1.0, 0.0, 0.0).z), N)); + return normalize(((_152 * (_124 * cos(_101))) + (cross(N, _152) * (_124 * sin(_101)))) + (N * _116)); + } + + void main() + { + vec2 _181 = (v_uv * 2.0) - vec2(1.0); + vec3 _209 = normalize((ub_pass[2].xyz + (ub_pass[0].xyz * _181.x)) + (ub_pass[1].xyz * _181.y)); + if (ub_pass[3].x < 0.001000000047497451305389404296875) + { + out_color = vec4(texture(tex_sky_smp_sky, _209).xyz, 1.0); + return; + } + vec3 prefiltered = vec3(0.0); + float total_w = 0.0; + for (uint i = 0u; i < 1024u; i++) + { + uint param = i; + uint param_1 = 1024u; + vec2 param_2 = hammersley(param, param_1); + vec3 param_3 = _209; + float param_4 = ub_pass[3].x; + vec3 _266 = importanceSampleGGX(param_2, param_3, param_4); + vec3 _276 = normalize((_266 * (2.0 * dot(_209, _266))) - _209); + float _281 = max(dot(_209, _276), 0.0); + if (_281 > 0.0) + { + prefiltered += (texture(tex_sky_smp_sky, _276).xyz * _281); + total_w += _281; + } + } + out_color = vec4(prefiltered / vec3(max(total_w, 9.9999997473787516355514526367188e-05)), 1.0); + } + +*/ +static const uint8_t prefilter_fs_source_glsl430[2435] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x75,0x6e, + 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x70,0x61, + 0x73,0x73,0x5b,0x34,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69, + 0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x30,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f, + 0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x75,0x62,0x65,0x20,0x74, + 0x65,0x78,0x5f,0x73,0x6b,0x79,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x6b,0x79,0x3b,0x0a, + 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x76,0x5f, + 0x75,0x76,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74, + 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63, + 0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x72,0x61,0x64,0x69,0x63,0x61,0x6c,0x49,0x6e,0x76,0x65,0x72, + 0x73,0x65,0x56,0x64,0x43,0x28,0x69,0x6e,0x6f,0x75,0x74,0x20,0x75,0x69,0x6e,0x74, + 0x20,0x62,0x69,0x74,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x62,0x69,0x74, + 0x73,0x20,0x3d,0x20,0x28,0x62,0x69,0x74,0x73,0x20,0x3c,0x3c,0x20,0x31,0x36,0x75, + 0x29,0x20,0x7c,0x20,0x28,0x62,0x69,0x74,0x73,0x20,0x3e,0x3e,0x20,0x31,0x36,0x75, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x69,0x74,0x73,0x20,0x3d,0x20,0x28,0x28, + 0x62,0x69,0x74,0x73,0x20,0x26,0x20,0x31,0x34,0x33,0x31,0x36,0x35,0x35,0x37,0x36, + 0x35,0x75,0x29,0x20,0x3c,0x3c,0x20,0x31,0x75,0x29,0x20,0x7c,0x20,0x28,0x28,0x62, + 0x69,0x74,0x73,0x20,0x26,0x20,0x32,0x38,0x36,0x33,0x33,0x31,0x31,0x35,0x33,0x30, + 0x75,0x29,0x20,0x3e,0x3e,0x20,0x31,0x75,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62, + 0x69,0x74,0x73,0x20,0x3d,0x20,0x28,0x28,0x62,0x69,0x74,0x73,0x20,0x26,0x20,0x38, + 0x35,0x38,0x39,0x39,0x33,0x34,0x35,0x39,0x75,0x29,0x20,0x3c,0x3c,0x20,0x32,0x75, + 0x29,0x20,0x7c,0x20,0x28,0x28,0x62,0x69,0x74,0x73,0x20,0x26,0x20,0x33,0x34,0x33, + 0x35,0x39,0x37,0x33,0x38,0x33,0x36,0x75,0x29,0x20,0x3e,0x3e,0x20,0x32,0x75,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x69,0x74,0x73,0x20,0x3d,0x20,0x28,0x28,0x62, + 0x69,0x74,0x73,0x20,0x26,0x20,0x32,0x35,0x32,0x36,0x34,0x35,0x31,0x33,0x35,0x75, + 0x29,0x20,0x3c,0x3c,0x20,0x34,0x75,0x29,0x20,0x7c,0x20,0x28,0x28,0x62,0x69,0x74, + 0x73,0x20,0x26,0x20,0x34,0x30,0x34,0x32,0x33,0x32,0x32,0x31,0x36,0x30,0x75,0x29, + 0x20,0x3e,0x3e,0x20,0x34,0x75,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x69,0x74, + 0x73,0x20,0x3d,0x20,0x28,0x28,0x62,0x69,0x74,0x73,0x20,0x26,0x20,0x31,0x36,0x37, + 0x31,0x31,0x39,0x33,0x35,0x75,0x29,0x20,0x3c,0x3c,0x20,0x38,0x75,0x29,0x20,0x7c, + 0x20,0x28,0x28,0x62,0x69,0x74,0x73,0x20,0x26,0x20,0x34,0x32,0x37,0x38,0x32,0x35, + 0x35,0x33,0x36,0x30,0x75,0x29,0x20,0x3e,0x3e,0x20,0x38,0x75,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28, + 0x62,0x69,0x74,0x73,0x29,0x20,0x2a,0x20,0x32,0x2e,0x33,0x32,0x38,0x33,0x30,0x36, + 0x34,0x33,0x36,0x35,0x33,0x38,0x36,0x39,0x36,0x32,0x38,0x39,0x30,0x36,0x32,0x35, + 0x65,0x2d,0x31,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x32,0x20,0x68,0x61, + 0x6d,0x6d,0x65,0x72,0x73,0x6c,0x65,0x79,0x28,0x75,0x69,0x6e,0x74,0x20,0x69,0x2c, + 0x20,0x75,0x69,0x6e,0x74,0x20,0x6e,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x75, + 0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x69,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x38,0x20,0x3d,0x20,0x72, + 0x61,0x64,0x69,0x63,0x61,0x6c,0x49,0x6e,0x76,0x65,0x72,0x73,0x65,0x56,0x64,0x43, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x76,0x65,0x63,0x32,0x28,0x66,0x6c,0x6f,0x61,0x74,0x28,0x69, + 0x29,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x6e,0x29,0x2c,0x20,0x5f,0x38, + 0x38,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x69,0x6d,0x70,0x6f, + 0x72,0x74,0x61,0x6e,0x63,0x65,0x53,0x61,0x6d,0x70,0x6c,0x65,0x47,0x47,0x58,0x28, + 0x76,0x65,0x63,0x32,0x20,0x58,0x69,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x4e,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39, + 0x35,0x20,0x3d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x20,0x2a,0x20, + 0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x31,0x20,0x3d,0x20,0x36,0x2e,0x32,0x38, + 0x33,0x31,0x38,0x35,0x34,0x38,0x32,0x30,0x32,0x35,0x31,0x34,0x36,0x34,0x38,0x34, + 0x33,0x37,0x35,0x20,0x2a,0x20,0x58,0x69,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x36,0x20,0x3d,0x20,0x73,0x71,0x72, + 0x74,0x28,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x58,0x69,0x2e,0x79,0x29,0x20,0x2f, + 0x20,0x28,0x31,0x2e,0x30,0x20,0x2b,0x20,0x28,0x28,0x28,0x5f,0x39,0x35,0x20,0x2a, + 0x20,0x5f,0x39,0x35,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x29,0x20,0x2a,0x20,0x58, + 0x69,0x2e,0x79,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x31,0x32,0x34,0x20,0x3d,0x20,0x73,0x71,0x72,0x74,0x28,0x6d,0x61, + 0x78,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x28,0x5f,0x31,0x31,0x36,0x20,0x2a,0x20, + 0x5f,0x31,0x31,0x36,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x62,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x34,0x36,0x20,0x3d,0x20,0x62, + 0x76,0x65,0x63,0x33,0x28,0x61,0x62,0x73,0x28,0x4e,0x2e,0x7a,0x29,0x20,0x3c,0x20, + 0x30,0x2e,0x39,0x39,0x39,0x30,0x30,0x30,0x30,0x31,0x32,0x38,0x37,0x34,0x36,0x30, + 0x33,0x32,0x37,0x31,0x34,0x38,0x34,0x33,0x37,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x35,0x32,0x20,0x3d,0x20,0x6e,0x6f,0x72, + 0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x63,0x72,0x6f,0x73,0x73,0x28,0x76,0x65,0x63, + 0x33,0x28,0x5f,0x31,0x34,0x36,0x2e,0x78,0x20,0x3f,0x20,0x76,0x65,0x63,0x33,0x28, + 0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x2e,0x78, + 0x20,0x3a,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30, + 0x2c,0x20,0x30,0x2e,0x30,0x29,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x34,0x36,0x2e,0x79, + 0x20,0x3f,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30, + 0x2c,0x20,0x31,0x2e,0x30,0x29,0x2e,0x79,0x20,0x3a,0x20,0x76,0x65,0x63,0x33,0x28, + 0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x29,0x2e,0x79, + 0x2c,0x20,0x5f,0x31,0x34,0x36,0x2e,0x7a,0x20,0x3f,0x20,0x76,0x65,0x63,0x33,0x28, + 0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x2e,0x7a, + 0x20,0x3a,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30, + 0x2c,0x20,0x30,0x2e,0x30,0x29,0x2e,0x7a,0x29,0x2c,0x20,0x4e,0x29,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x69,0x7a,0x65,0x28,0x28,0x28,0x5f,0x31,0x35,0x32,0x20,0x2a,0x20,0x28,0x5f, + 0x31,0x32,0x34,0x20,0x2a,0x20,0x63,0x6f,0x73,0x28,0x5f,0x31,0x30,0x31,0x29,0x29, + 0x29,0x20,0x2b,0x20,0x28,0x63,0x72,0x6f,0x73,0x73,0x28,0x4e,0x2c,0x20,0x5f,0x31, + 0x35,0x32,0x29,0x20,0x2a,0x20,0x28,0x5f,0x31,0x32,0x34,0x20,0x2a,0x20,0x73,0x69, + 0x6e,0x28,0x5f,0x31,0x30,0x31,0x29,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x4e,0x20, + 0x2a,0x20,0x5f,0x31,0x31,0x36,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69, + 0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x32,0x20,0x5f,0x31,0x38,0x31,0x20,0x3d,0x20,0x28,0x76,0x5f,0x75,0x76, + 0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x20,0x2d,0x20,0x76,0x65,0x63,0x32,0x28,0x31, + 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x32, + 0x30,0x39,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x28, + 0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x32,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2b, + 0x20,0x28,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a, + 0x20,0x2a,0x20,0x5f,0x31,0x38,0x31,0x2e,0x78,0x29,0x29,0x20,0x2b,0x20,0x28,0x75, + 0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, + 0x5f,0x31,0x38,0x31,0x2e,0x79,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x33,0x5d,0x2e,0x78,0x20,0x3c, + 0x20,0x30,0x2e,0x30,0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x34,0x37,0x34, + 0x39,0x37,0x34,0x35,0x31,0x33,0x30,0x35,0x33,0x38,0x39,0x34,0x30,0x34,0x32,0x39, + 0x36,0x38,0x37,0x35,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20, + 0x76,0x65,0x63,0x34,0x28,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78, + 0x5f,0x73,0x6b,0x79,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x6b,0x79,0x2c,0x20,0x5f,0x32, + 0x30,0x39,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x72, + 0x65,0x66,0x69,0x6c,0x74,0x65,0x72,0x65,0x64,0x20,0x3d,0x20,0x76,0x65,0x63,0x33, + 0x28,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x74,0x6f,0x74,0x61,0x6c,0x5f,0x77,0x20,0x3d,0x20,0x30,0x2e,0x30,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x20,0x28,0x75,0x69,0x6e,0x74,0x20,0x69,0x20, + 0x3d,0x20,0x30,0x75,0x3b,0x20,0x69,0x20,0x3c,0x20,0x31,0x30,0x32,0x34,0x75,0x3b, + 0x20,0x69,0x2b,0x2b,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d, + 0x20,0x69,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x31,0x30,0x32,0x34,0x75, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x68,0x61,0x6d,0x6d,0x65,0x72,0x73, + 0x6c,0x65,0x79,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x32,0x30,0x39, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x75,0x62,0x5f,0x70,0x61,0x73, + 0x73,0x5b,0x33,0x5d,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x76,0x65,0x63,0x33,0x20,0x5f,0x32,0x36,0x36,0x20,0x3d,0x20,0x69,0x6d,0x70,0x6f, + 0x72,0x74,0x61,0x6e,0x63,0x65,0x53,0x61,0x6d,0x70,0x6c,0x65,0x47,0x47,0x58,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x32,0x37,0x36,0x20,0x3d,0x20, + 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x28,0x5f,0x32,0x36,0x36,0x20, + 0x2a,0x20,0x28,0x32,0x2e,0x30,0x20,0x2a,0x20,0x64,0x6f,0x74,0x28,0x5f,0x32,0x30, + 0x39,0x2c,0x20,0x5f,0x32,0x36,0x36,0x29,0x29,0x29,0x20,0x2d,0x20,0x5f,0x32,0x30, + 0x39,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x32,0x38,0x31,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74, + 0x28,0x5f,0x32,0x30,0x39,0x2c,0x20,0x5f,0x32,0x37,0x36,0x29,0x2c,0x20,0x30,0x2e, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x5f,0x32,0x38,0x31,0x20,0x3e,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x70,0x72,0x65,0x66,0x69,0x6c,0x74,0x65,0x72,0x65,0x64,0x20,0x2b,0x3d, + 0x20,0x28,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x6b, + 0x79,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x6b,0x79,0x2c,0x20,0x5f,0x32,0x37,0x36,0x29, + 0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x5f,0x32,0x38,0x31,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x6f,0x74,0x61,0x6c,0x5f, + 0x77,0x20,0x2b,0x3d,0x20,0x5f,0x32,0x38,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x6f, + 0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28, + 0x70,0x72,0x65,0x66,0x69,0x6c,0x74,0x65,0x72,0x65,0x64,0x20,0x2f,0x20,0x76,0x65, + 0x63,0x33,0x28,0x6d,0x61,0x78,0x28,0x74,0x6f,0x74,0x61,0x6c,0x5f,0x77,0x2c,0x20, + 0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35, + 0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38, + 0x38,0x65,0x2d,0x30,0x35,0x29,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x00, +}; +/* + static float4 gl_Position; + static int gl_VertexIndex; + static float2 v_uv; + + struct SPIRV_Cross_Input + { + uint gl_VertexIndex : SV_VertexID; + }; + + struct SPIRV_Cross_Output + { + float2 v_uv : TEXCOORD0; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + float2 _27 = (float2(float((gl_VertexIndex << 1) & 2), float(gl_VertexIndex & 2)) * 2.0f) - 1.0f.xx; + v_uv = (_27 * 0.5f) + 0.5f.xx; + gl_Position = float4(_27, 0.0f, 1.0f); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_VertexIndex = int(stage_input.gl_VertexIndex); + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.v_uv = v_uv; + return stage_output; + } +*/ +static const uint8_t prefilter_vs_source_hlsl5[716] = { + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c, + 0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69, + 0x63,0x20,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49, + 0x6e,0x64,0x65,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x32,0x20,0x76,0x5f,0x75,0x76,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63, + 0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e, + 0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x67, + 0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x3a,0x20, + 0x53,0x56,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x44,0x3b,0x0a,0x7d,0x3b,0x0a, + 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, + 0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x76,0x5f,0x75,0x76,0x20,0x3a,0x20,0x54, + 0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e, + 0x20,0x3a,0x20,0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a, + 0x7d,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61, + 0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x32,0x20,0x5f,0x32,0x37,0x20,0x3d,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28, + 0x66,0x6c,0x6f,0x61,0x74,0x28,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78, + 0x49,0x6e,0x64,0x65,0x78,0x20,0x3c,0x3c,0x20,0x31,0x29,0x20,0x26,0x20,0x32,0x29, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65, + 0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x26,0x20,0x32,0x29,0x29,0x20,0x2a,0x20,0x32, + 0x2e,0x30,0x66,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x5f,0x75,0x76,0x20,0x3d,0x20,0x28,0x5f,0x32,0x37,0x20, + 0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2e,0x78, + 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69, + 0x6f,0x6e,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x32,0x37,0x2c, + 0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74, + 0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, + 0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65, + 0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c, + 0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x3d,0x20,0x69, + 0x6e,0x74,0x28,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x67, + 0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73, + 0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75, + 0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f, + 0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69, + 0x6f,0x6e,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70, + 0x75,0x74,0x2e,0x76,0x5f,0x75,0x76,0x20,0x3d,0x20,0x76,0x5f,0x75,0x76,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65, + 0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + cbuffer ub_pass : register(b0) + { + float4 _186_face_right : packoffset(c0); + float4 _186_face_up : packoffset(c1); + float4 _186_face_forward : packoffset(c2); + float4 _186_params : packoffset(c3); + }; + + TextureCube tex_sky : register(t0); + SamplerState smp_sky : register(s0); + + static float2 v_uv; + static float4 out_color; + + struct SPIRV_Cross_Input + { + float2 v_uv : TEXCOORD0; + }; + + struct SPIRV_Cross_Output + { + float4 out_color : SV_Target0; + }; + + float radicalInverseVdC(inout uint bits) + { + bits = (bits << 16u) | (bits >> 16u); + bits = ((bits & 1431655765u) << 1u) | ((bits & 2863311530u) >> 1u); + bits = ((bits & 858993459u) << 2u) | ((bits & 3435973836u) >> 2u); + bits = ((bits & 252645135u) << 4u) | ((bits & 4042322160u) >> 4u); + bits = ((bits & 16711935u) << 8u) | ((bits & 4278255360u) >> 8u); + return float(bits) * 2.3283064365386962890625e-10f; + } + + float2 hammersley(uint i, uint n) + { + uint param = i; + float _88 = radicalInverseVdC(param); + return float2(float(i) / float(n), _88); + } + + float3 importanceSampleGGX(float2 Xi, float3 N, float roughness) + { + float _95 = roughness * roughness; + float _101 = 6.283185482025146484375f * Xi.x; + float _116 = sqrt((1.0f - Xi.y) / (1.0f + (((_95 * _95) - 1.0f) * Xi.y))); + float _124 = sqrt(max(1.0f - (_116 * _116), 0.0f)); + bool3 _146 = (abs(N.z) < 0.999000012874603271484375f).xxx; + float3 _152 = normalize(cross(float3(_146.x ? float3(0.0f, 0.0f, 1.0f).x : float3(1.0f, 0.0f, 0.0f).x, _146.y ? float3(0.0f, 0.0f, 1.0f).y : float3(1.0f, 0.0f, 0.0f).y, _146.z ? float3(0.0f, 0.0f, 1.0f).z : float3(1.0f, 0.0f, 0.0f).z), N)); + return normalize(((_152 * (_124 * cos(_101))) + (cross(N, _152) * (_124 * sin(_101)))) + (N * _116)); + } + + void frag_main() + { + float2 _181 = (v_uv * 2.0f) - 1.0f.xx; + float3 _209 = normalize((_186_face_forward.xyz + (_186_face_right.xyz * _181.x)) + (_186_face_up.xyz * _181.y)); + if (_186_params.x < 0.001000000047497451305389404296875f) + { + out_color = float4(tex_sky.Sample(smp_sky, _209).xyz, 1.0f); + return; + } + float3 prefiltered = 0.0f.xxx; + float total_w = 0.0f; + for (uint i = 0u; i < 1024u; i++) + { + uint param = i; + uint param_1 = 1024u; + float2 param_2 = hammersley(param, param_1); + float3 param_3 = _209; + float param_4 = _186_params.x; + float3 _266 = importanceSampleGGX(param_2, param_3, param_4); + float3 _276 = normalize((_266 * (2.0f * dot(_209, _266))) - _209); + float _281 = max(dot(_209, _276), 0.0f); + if (_281 > 0.0f) + { + prefiltered += (tex_sky.Sample(smp_sky, _276).xyz * _281); + total_w += _281; + } + } + out_color = float4(prefiltered / max(total_w, 9.9999997473787516355514526367188e-05f).xxx, 1.0f); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + v_uv = stage_input.v_uv; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.out_color = out_color; + return stage_output; + } +*/ +static const uint8_t prefilter_fs_source_hlsl5[3027] = { + 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x38,0x36, + 0x5f,0x66,0x61,0x63,0x65,0x5f,0x72,0x69,0x67,0x68,0x74,0x20,0x3a,0x20,0x70,0x61, + 0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x38,0x36,0x5f,0x66,0x61, + 0x63,0x65,0x5f,0x75,0x70,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73, + 0x65,0x74,0x28,0x63,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x5f,0x31,0x38,0x36,0x5f,0x66,0x61,0x63,0x65,0x5f,0x66,0x6f,0x72, + 0x77,0x61,0x72,0x64,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65, + 0x74,0x28,0x63,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x5f,0x31,0x38,0x36,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x20,0x3a,0x20, + 0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x33,0x29,0x3b,0x0a, + 0x7d,0x3b,0x0a,0x0a,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x43,0x75,0x62,0x65,0x3c, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x6b,0x79,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x30,0x29,0x3b,0x0a, + 0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70, + 0x5f,0x73,0x6b,0x79,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28, + 0x73,0x30,0x29,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x32,0x20,0x76,0x5f,0x75,0x76,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56, + 0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x76,0x5f,0x75,0x76,0x20,0x3a, + 0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a, + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, + 0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x3a,0x20,0x53,0x56,0x5f,0x54,0x61,0x72,0x67,0x65,0x74,0x30,0x3b,0x0a,0x7d, + 0x3b,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x61,0x64,0x69,0x63,0x61,0x6c, + 0x49,0x6e,0x76,0x65,0x72,0x73,0x65,0x56,0x64,0x43,0x28,0x69,0x6e,0x6f,0x75,0x74, + 0x20,0x75,0x69,0x6e,0x74,0x20,0x62,0x69,0x74,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x62,0x69,0x74,0x73,0x20,0x3d,0x20,0x28,0x62,0x69,0x74,0x73,0x20,0x3c, + 0x3c,0x20,0x31,0x36,0x75,0x29,0x20,0x7c,0x20,0x28,0x62,0x69,0x74,0x73,0x20,0x3e, + 0x3e,0x20,0x31,0x36,0x75,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x69,0x74,0x73, + 0x20,0x3d,0x20,0x28,0x28,0x62,0x69,0x74,0x73,0x20,0x26,0x20,0x31,0x34,0x33,0x31, + 0x36,0x35,0x35,0x37,0x36,0x35,0x75,0x29,0x20,0x3c,0x3c,0x20,0x31,0x75,0x29,0x20, + 0x7c,0x20,0x28,0x28,0x62,0x69,0x74,0x73,0x20,0x26,0x20,0x32,0x38,0x36,0x33,0x33, + 0x31,0x31,0x35,0x33,0x30,0x75,0x29,0x20,0x3e,0x3e,0x20,0x31,0x75,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x62,0x69,0x74,0x73,0x20,0x3d,0x20,0x28,0x28,0x62,0x69,0x74, + 0x73,0x20,0x26,0x20,0x38,0x35,0x38,0x39,0x39,0x33,0x34,0x35,0x39,0x75,0x29,0x20, + 0x3c,0x3c,0x20,0x32,0x75,0x29,0x20,0x7c,0x20,0x28,0x28,0x62,0x69,0x74,0x73,0x20, + 0x26,0x20,0x33,0x34,0x33,0x35,0x39,0x37,0x33,0x38,0x33,0x36,0x75,0x29,0x20,0x3e, + 0x3e,0x20,0x32,0x75,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x69,0x74,0x73,0x20, + 0x3d,0x20,0x28,0x28,0x62,0x69,0x74,0x73,0x20,0x26,0x20,0x32,0x35,0x32,0x36,0x34, + 0x35,0x31,0x33,0x35,0x75,0x29,0x20,0x3c,0x3c,0x20,0x34,0x75,0x29,0x20,0x7c,0x20, + 0x28,0x28,0x62,0x69,0x74,0x73,0x20,0x26,0x20,0x34,0x30,0x34,0x32,0x33,0x32,0x32, + 0x31,0x36,0x30,0x75,0x29,0x20,0x3e,0x3e,0x20,0x34,0x75,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x62,0x69,0x74,0x73,0x20,0x3d,0x20,0x28,0x28,0x62,0x69,0x74,0x73,0x20, + 0x26,0x20,0x31,0x36,0x37,0x31,0x31,0x39,0x33,0x35,0x75,0x29,0x20,0x3c,0x3c,0x20, + 0x38,0x75,0x29,0x20,0x7c,0x20,0x28,0x28,0x62,0x69,0x74,0x73,0x20,0x26,0x20,0x34, + 0x32,0x37,0x38,0x32,0x35,0x35,0x33,0x36,0x30,0x75,0x29,0x20,0x3e,0x3e,0x20,0x38, + 0x75,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x28,0x62,0x69,0x74,0x73,0x29,0x20,0x2a,0x20,0x32,0x2e,0x33, + 0x32,0x38,0x33,0x30,0x36,0x34,0x33,0x36,0x35,0x33,0x38,0x36,0x39,0x36,0x32,0x38, + 0x39,0x30,0x36,0x32,0x35,0x65,0x2d,0x31,0x30,0x66,0x3b,0x0a,0x7d,0x0a,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x32,0x20,0x68,0x61,0x6d,0x6d,0x65,0x72,0x73,0x6c,0x65,0x79, + 0x28,0x75,0x69,0x6e,0x74,0x20,0x69,0x2c,0x20,0x75,0x69,0x6e,0x74,0x20,0x6e,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x20,0x3d,0x20,0x69,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x38,0x38,0x20,0x3d,0x20,0x72,0x61,0x64,0x69,0x63,0x61,0x6c,0x49,0x6e, + 0x76,0x65,0x72,0x73,0x65,0x56,0x64,0x43,0x28,0x70,0x61,0x72,0x61,0x6d,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x32,0x28,0x66,0x6c,0x6f,0x61,0x74,0x28,0x69,0x29,0x20,0x2f,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x28,0x6e,0x29,0x2c,0x20,0x5f,0x38,0x38,0x29,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6d,0x70,0x6f,0x72,0x74,0x61,0x6e, + 0x63,0x65,0x53,0x61,0x6d,0x70,0x6c,0x65,0x47,0x47,0x58,0x28,0x66,0x6c,0x6f,0x61, + 0x74,0x32,0x20,0x58,0x69,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4e,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39, + 0x35,0x20,0x3d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x20,0x2a,0x20, + 0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x31,0x20,0x3d,0x20,0x36,0x2e,0x32,0x38, + 0x33,0x31,0x38,0x35,0x34,0x38,0x32,0x30,0x32,0x35,0x31,0x34,0x36,0x34,0x38,0x34, + 0x33,0x37,0x35,0x66,0x20,0x2a,0x20,0x58,0x69,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x36,0x20,0x3d,0x20,0x73,0x71, + 0x72,0x74,0x28,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x58,0x69,0x2e,0x79,0x29, + 0x20,0x2f,0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2b,0x20,0x28,0x28,0x28,0x5f,0x39, + 0x35,0x20,0x2a,0x20,0x5f,0x39,0x35,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x66,0x29, + 0x20,0x2a,0x20,0x58,0x69,0x2e,0x79,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x34,0x20,0x3d,0x20,0x73,0x71,0x72, + 0x74,0x28,0x6d,0x61,0x78,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x28,0x5f,0x31, + 0x31,0x36,0x20,0x2a,0x20,0x5f,0x31,0x31,0x36,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x33,0x20,0x5f,0x31, + 0x34,0x36,0x20,0x3d,0x20,0x28,0x61,0x62,0x73,0x28,0x4e,0x2e,0x7a,0x29,0x20,0x3c, + 0x20,0x30,0x2e,0x39,0x39,0x39,0x30,0x30,0x30,0x30,0x31,0x32,0x38,0x37,0x34,0x36, + 0x30,0x33,0x32,0x37,0x31,0x34,0x38,0x34,0x33,0x37,0x35,0x66,0x29,0x2e,0x78,0x78, + 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31, + 0x35,0x32,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x63, + 0x72,0x6f,0x73,0x73,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x31,0x34,0x36, + 0x2e,0x78,0x20,0x3f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x66, + 0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2e,0x78,0x20, + 0x3a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x66,0x2c,0x20,0x30, + 0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x2e,0x78,0x2c,0x20,0x5f,0x31, + 0x34,0x36,0x2e,0x79,0x20,0x3f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e, + 0x30,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2e, + 0x79,0x20,0x3a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x66,0x2c, + 0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x2e,0x79,0x2c,0x20, + 0x5f,0x31,0x34,0x36,0x2e,0x7a,0x20,0x3f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, + 0x30,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66, + 0x29,0x2e,0x7a,0x20,0x3a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30, + 0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x2e,0x7a, + 0x29,0x2c,0x20,0x4e,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x28,0x28,0x5f, + 0x31,0x35,0x32,0x20,0x2a,0x20,0x28,0x5f,0x31,0x32,0x34,0x20,0x2a,0x20,0x63,0x6f, + 0x73,0x28,0x5f,0x31,0x30,0x31,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x63,0x72,0x6f, + 0x73,0x73,0x28,0x4e,0x2c,0x20,0x5f,0x31,0x35,0x32,0x29,0x20,0x2a,0x20,0x28,0x5f, + 0x31,0x32,0x34,0x20,0x2a,0x20,0x73,0x69,0x6e,0x28,0x5f,0x31,0x30,0x31,0x29,0x29, + 0x29,0x29,0x20,0x2b,0x20,0x28,0x4e,0x20,0x2a,0x20,0x5f,0x31,0x31,0x36,0x29,0x29, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d, + 0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x32,0x20,0x5f,0x31,0x38,0x31,0x20,0x3d,0x20,0x28,0x76,0x5f,0x75,0x76,0x20, + 0x2a,0x20,0x32,0x2e,0x30,0x66,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78, + 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x32, + 0x30,0x39,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x28, + 0x5f,0x31,0x38,0x36,0x5f,0x66,0x61,0x63,0x65,0x5f,0x66,0x6f,0x72,0x77,0x61,0x72, + 0x64,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x31,0x38,0x36,0x5f,0x66,0x61, + 0x63,0x65,0x5f,0x72,0x69,0x67,0x68,0x74,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x5f, + 0x31,0x38,0x31,0x2e,0x78,0x29,0x29,0x20,0x2b,0x20,0x28,0x5f,0x31,0x38,0x36,0x5f, + 0x66,0x61,0x63,0x65,0x5f,0x75,0x70,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x5f,0x31, + 0x38,0x31,0x2e,0x79,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x5f,0x31,0x38,0x36,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x20,0x3c,0x20, + 0x30,0x2e,0x30,0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x34,0x37,0x34,0x39, + 0x37,0x34,0x35,0x31,0x33,0x30,0x35,0x33,0x38,0x39,0x34,0x30,0x34,0x32,0x39,0x36, + 0x38,0x37,0x35,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x74,0x65,0x78,0x5f,0x73,0x6b,0x79,0x2e,0x53, + 0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x6b,0x79,0x2c,0x20,0x5f, + 0x32,0x30,0x39,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x70,0x72,0x65,0x66,0x69,0x6c,0x74,0x65,0x72,0x65,0x64,0x20,0x3d,0x20, + 0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x74,0x6f,0x74,0x61,0x6c,0x5f,0x77,0x20,0x3d,0x20,0x30,0x2e, + 0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x20,0x28,0x75,0x69,0x6e, + 0x74,0x20,0x69,0x20,0x3d,0x20,0x30,0x75,0x3b,0x20,0x69,0x20,0x3c,0x20,0x31,0x30, + 0x32,0x34,0x75,0x3b,0x20,0x69,0x2b,0x2b,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x20,0x3d,0x20,0x69,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x75,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x31, + 0x30,0x32,0x34,0x75,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x68, + 0x61,0x6d,0x6d,0x65,0x72,0x73,0x6c,0x65,0x79,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x20,0x3d,0x20,0x5f,0x32,0x30,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20, + 0x3d,0x20,0x5f,0x31,0x38,0x36,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x5f,0x32,0x36,0x36,0x20,0x3d,0x20,0x69,0x6d,0x70,0x6f,0x72,0x74,0x61,0x6e,0x63, + 0x65,0x53,0x61,0x6d,0x70,0x6c,0x65,0x47,0x47,0x58,0x28,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x32,0x37,0x36,0x20,0x3d,0x20,0x6e,0x6f,0x72, + 0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x28,0x5f,0x32,0x36,0x36,0x20,0x2a,0x20,0x28, + 0x32,0x2e,0x30,0x66,0x20,0x2a,0x20,0x64,0x6f,0x74,0x28,0x5f,0x32,0x30,0x39,0x2c, + 0x20,0x5f,0x32,0x36,0x36,0x29,0x29,0x29,0x20,0x2d,0x20,0x5f,0x32,0x30,0x39,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x32,0x38,0x31,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x5f, + 0x32,0x30,0x39,0x2c,0x20,0x5f,0x32,0x37,0x36,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, + 0x32,0x38,0x31,0x20,0x3e,0x20,0x30,0x2e,0x30,0x66,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x70,0x72,0x65,0x66,0x69,0x6c,0x74,0x65,0x72,0x65,0x64,0x20,0x2b,0x3d, + 0x20,0x28,0x74,0x65,0x78,0x5f,0x73,0x6b,0x79,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65, + 0x28,0x73,0x6d,0x70,0x5f,0x73,0x6b,0x79,0x2c,0x20,0x5f,0x32,0x37,0x36,0x29,0x2e, + 0x78,0x79,0x7a,0x20,0x2a,0x20,0x5f,0x32,0x38,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x6f,0x74,0x61,0x6c,0x5f,0x77, + 0x20,0x2b,0x3d,0x20,0x5f,0x32,0x38,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75, + 0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x28,0x70,0x72,0x65,0x66,0x69,0x6c,0x74,0x65,0x72,0x65,0x64,0x20,0x2f,0x20,0x6d, + 0x61,0x78,0x28,0x74,0x6f,0x74,0x61,0x6c,0x5f,0x77,0x2c,0x20,0x39,0x2e,0x39,0x39, + 0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35, + 0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30, + 0x35,0x66,0x29,0x2e,0x78,0x78,0x78,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f, + 0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56, + 0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x5f,0x75,0x76,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70, + 0x75,0x74,0x2e,0x76,0x5f,0x75,0x76,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61, + 0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50, + 0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74, + 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e, + 0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x6f,0x75,0x74,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a, + 0x7d,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + struct main0_out + { + float2 v_uv [[user(locn0)]]; + float4 gl_Position [[position]]; + }; + + vertex main0_out main0(uint gl_VertexIndex [[vertex_id]]) + { + main0_out out = {}; + float2 _27 = (float2(float((int(gl_VertexIndex) << 1) & 2), float(int(gl_VertexIndex) & 2)) * 2.0) - float2(1.0); + out.v_uv = (_27 * 0.5) + float2(0.5); + out.gl_Position = float4(_27, 0.0, 1.0); + return out; + } + +*/ +static const uint8_t prefilter_vs_source_metal_macos[474] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d, + 0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x32,0x20,0x76,0x5f,0x75,0x76,0x20,0x5b,0x5b,0x75,0x73,0x65, + 0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69, + 0x6f,0x6e,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x3b, + 0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,0x65,0x78,0x20,0x6d,0x61,0x69,0x6e, + 0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x75,0x69,0x6e,0x74, + 0x20,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20, + 0x5b,0x5b,0x76,0x65,0x72,0x74,0x65,0x78,0x5f,0x69,0x64,0x5d,0x5d,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f, + 0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x32,0x20,0x5f,0x32,0x37,0x20,0x3d,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74, + 0x32,0x28,0x66,0x6c,0x6f,0x61,0x74,0x28,0x28,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f, + 0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x3c,0x3c,0x20, + 0x31,0x29,0x20,0x26,0x20,0x32,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x69, + 0x6e,0x74,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65, + 0x78,0x29,0x20,0x26,0x20,0x32,0x29,0x29,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x20, + 0x2d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x75,0x76,0x20,0x3d,0x20,0x28,0x5f, + 0x32,0x37,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x32,0x28,0x30,0x2e,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, + 0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x32,0x37,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20, + 0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + #pragma clang diagnostic ignored "-Wmissing-prototypes" + + #include + #include + + using namespace metal; + + struct ub_pass + { + float4 face_right; + float4 face_up; + float4 face_forward; + float4 params; + }; + + struct main0_out + { + float4 out_color [[color(0)]]; + }; + + struct main0_in + { + float2 v_uv [[user(locn0)]]; + }; + + static inline __attribute__((always_inline)) + float radicalInverseVdC(thread uint& bits) + { + bits = (bits << 16u) | (bits >> 16u); + bits = ((bits & 1431655765u) << 1u) | ((bits & 2863311530u) >> 1u); + bits = ((bits & 858993459u) << 2u) | ((bits & 3435973836u) >> 2u); + bits = ((bits & 252645135u) << 4u) | ((bits & 4042322160u) >> 4u); + bits = ((bits & 16711935u) << 8u) | ((bits & 4278255360u) >> 8u); + return float(bits) * 2.3283064365386962890625e-10; + } + + static inline __attribute__((always_inline)) + float2 hammersley(thread const uint& i, thread const uint& n) + { + uint param = i; + float _88 = radicalInverseVdC(param); + return float2(float(i) / float(n), _88); + } + + static inline __attribute__((always_inline)) + float3 importanceSampleGGX(thread const float2& Xi, thread const float3& N, thread const float& roughness) + { + float _95 = roughness * roughness; + float _101 = 6.283185482025146484375 * Xi.x; + float _116 = sqrt((1.0 - Xi.y) / (1.0 + (((_95 * _95) - 1.0) * Xi.y))); + float _124 = sqrt(fast::max(1.0 - (_116 * _116), 0.0)); + float3 _152 = fast::normalize(cross(select(float3(1.0, 0.0, 0.0), float3(0.0, 0.0, 1.0), bool3(abs(N.z) < 0.999000012874603271484375)), N)); + return fast::normalize(((_152 * (_124 * cos(_101))) + (cross(N, _152) * (_124 * sin(_101)))) + (N * _116)); + } + + fragment main0_out main0(main0_in in [[stage_in]], constant ub_pass& _186 [[buffer(0)]], texturecube tex_sky [[texture(0)]], sampler smp_sky [[sampler(0)]]) + { + main0_out out = {}; + float2 _181 = (in.v_uv * 2.0) - float2(1.0); + float3 _209 = fast::normalize((_186.face_forward.xyz + (_186.face_right.xyz * _181.x)) + (_186.face_up.xyz * _181.y)); + if (_186.params.x < 0.001000000047497451305389404296875) + { + out.out_color = float4(tex_sky.sample(smp_sky, _209).xyz, 1.0); + return out; + } + float3 prefiltered = float3(0.0); + float total_w = 0.0; + for (uint i = 0u; i < 1024u; i++) + { + uint param = i; + uint param_1 = 1024u; + float2 param_2 = hammersley(param, param_1); + float3 param_3 = _209; + float param_4 = _186.params.x; + float3 _266 = importanceSampleGGX(param_2, param_3, param_4); + float3 _276 = fast::normalize((_266 * (2.0 * dot(_209, _266))) - _209); + float _281 = fast::max(dot(_209, _276), 0.0); + if (_281 > 0.0) + { + prefiltered += (tex_sky.sample(smp_sky, _276).xyz * _281); + total_w += _281; + } + } + out.out_color = float4(prefiltered / float3(fast::max(total_w, 9.9999997473787516355514526367188e-05)), 1.0); + return out; + } + +*/ +static const uint8_t prefilter_fs_source_metal_macos[2980] = { + 0x23,0x70,0x72,0x61,0x67,0x6d,0x61,0x20,0x63,0x6c,0x61,0x6e,0x67,0x20,0x64,0x69, + 0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x20,0x69,0x67,0x6e,0x6f,0x72,0x65,0x64, + 0x20,0x22,0x2d,0x57,0x6d,0x69,0x73,0x73,0x69,0x6e,0x67,0x2d,0x70,0x72,0x6f,0x74, + 0x6f,0x74,0x79,0x70,0x65,0x73,0x22,0x0a,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64, + 0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f,0x73,0x74,0x64,0x6c,0x69,0x62,0x3e, + 0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f, + 0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a,0x75,0x73,0x69,0x6e,0x67,0x20,0x6e, + 0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20,0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a, + 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x61,0x63, + 0x65,0x5f,0x72,0x69,0x67,0x68,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x66,0x61,0x63,0x65,0x5f,0x75,0x70,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x61,0x63,0x65,0x5f,0x66,0x6f,0x72, + 0x77,0x61,0x72,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72, + 0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29,0x5d, + 0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61, + 0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x32,0x20,0x76,0x5f,0x75,0x76,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28, + 0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74, + 0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74, + 0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79, + 0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x72,0x61,0x64,0x69,0x63,0x61,0x6c,0x49,0x6e,0x76,0x65,0x72,0x73,0x65,0x56, + 0x64,0x43,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x75,0x69,0x6e,0x74,0x26,0x20, + 0x62,0x69,0x74,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x62,0x69,0x74,0x73, + 0x20,0x3d,0x20,0x28,0x62,0x69,0x74,0x73,0x20,0x3c,0x3c,0x20,0x31,0x36,0x75,0x29, + 0x20,0x7c,0x20,0x28,0x62,0x69,0x74,0x73,0x20,0x3e,0x3e,0x20,0x31,0x36,0x75,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x69,0x74,0x73,0x20,0x3d,0x20,0x28,0x28,0x62, + 0x69,0x74,0x73,0x20,0x26,0x20,0x31,0x34,0x33,0x31,0x36,0x35,0x35,0x37,0x36,0x35, + 0x75,0x29,0x20,0x3c,0x3c,0x20,0x31,0x75,0x29,0x20,0x7c,0x20,0x28,0x28,0x62,0x69, + 0x74,0x73,0x20,0x26,0x20,0x32,0x38,0x36,0x33,0x33,0x31,0x31,0x35,0x33,0x30,0x75, + 0x29,0x20,0x3e,0x3e,0x20,0x31,0x75,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x69, + 0x74,0x73,0x20,0x3d,0x20,0x28,0x28,0x62,0x69,0x74,0x73,0x20,0x26,0x20,0x38,0x35, + 0x38,0x39,0x39,0x33,0x34,0x35,0x39,0x75,0x29,0x20,0x3c,0x3c,0x20,0x32,0x75,0x29, + 0x20,0x7c,0x20,0x28,0x28,0x62,0x69,0x74,0x73,0x20,0x26,0x20,0x33,0x34,0x33,0x35, + 0x39,0x37,0x33,0x38,0x33,0x36,0x75,0x29,0x20,0x3e,0x3e,0x20,0x32,0x75,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x62,0x69,0x74,0x73,0x20,0x3d,0x20,0x28,0x28,0x62,0x69, + 0x74,0x73,0x20,0x26,0x20,0x32,0x35,0x32,0x36,0x34,0x35,0x31,0x33,0x35,0x75,0x29, + 0x20,0x3c,0x3c,0x20,0x34,0x75,0x29,0x20,0x7c,0x20,0x28,0x28,0x62,0x69,0x74,0x73, + 0x20,0x26,0x20,0x34,0x30,0x34,0x32,0x33,0x32,0x32,0x31,0x36,0x30,0x75,0x29,0x20, + 0x3e,0x3e,0x20,0x34,0x75,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x69,0x74,0x73, + 0x20,0x3d,0x20,0x28,0x28,0x62,0x69,0x74,0x73,0x20,0x26,0x20,0x31,0x36,0x37,0x31, + 0x31,0x39,0x33,0x35,0x75,0x29,0x20,0x3c,0x3c,0x20,0x38,0x75,0x29,0x20,0x7c,0x20, + 0x28,0x28,0x62,0x69,0x74,0x73,0x20,0x26,0x20,0x34,0x32,0x37,0x38,0x32,0x35,0x35, + 0x33,0x36,0x30,0x75,0x29,0x20,0x3e,0x3e,0x20,0x38,0x75,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x62, + 0x69,0x74,0x73,0x29,0x20,0x2a,0x20,0x32,0x2e,0x33,0x32,0x38,0x33,0x30,0x36,0x34, + 0x33,0x36,0x35,0x33,0x38,0x36,0x39,0x36,0x32,0x38,0x39,0x30,0x36,0x32,0x35,0x65, + 0x2d,0x31,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69, + 0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74, + 0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69, + 0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x68,0x61,0x6d,0x6d, + 0x65,0x72,0x73,0x6c,0x65,0x79,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x20,0x75,0x69,0x6e,0x74,0x26,0x20,0x69,0x2c,0x20,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x75,0x69,0x6e,0x74,0x26,0x20, + 0x6e,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x20,0x3d,0x20,0x69,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x38,0x38,0x20,0x3d,0x20,0x72,0x61,0x64,0x69,0x63,0x61,0x6c, + 0x49,0x6e,0x76,0x65,0x72,0x73,0x65,0x56,0x64,0x43,0x28,0x70,0x61,0x72,0x61,0x6d, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x32,0x28,0x66,0x6c,0x6f,0x61,0x74,0x28,0x69,0x29,0x20,0x2f,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x28,0x6e,0x29,0x2c,0x20,0x5f,0x38,0x38,0x29,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65, + 0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28, + 0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6d,0x70,0x6f,0x72,0x74,0x61,0x6e,0x63, + 0x65,0x53,0x61,0x6d,0x70,0x6c,0x65,0x47,0x47,0x58,0x28,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x26,0x20, + 0x58,0x69,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4e,0x2c,0x20,0x74,0x68,0x72,0x65, + 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20, + 0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x35,0x20,0x3d,0x20,0x72,0x6f,0x75, + 0x67,0x68,0x6e,0x65,0x73,0x73,0x20,0x2a,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65, + 0x73,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x30,0x31,0x20,0x3d,0x20,0x36,0x2e,0x32,0x38,0x33,0x31,0x38,0x35,0x34,0x38,0x32, + 0x30,0x32,0x35,0x31,0x34,0x36,0x34,0x38,0x34,0x33,0x37,0x35,0x20,0x2a,0x20,0x58, + 0x69,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x31,0x36,0x20,0x3d,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x31,0x2e,0x30,0x20, + 0x2d,0x20,0x58,0x69,0x2e,0x79,0x29,0x20,0x2f,0x20,0x28,0x31,0x2e,0x30,0x20,0x2b, + 0x20,0x28,0x28,0x28,0x5f,0x39,0x35,0x20,0x2a,0x20,0x5f,0x39,0x35,0x29,0x20,0x2d, + 0x20,0x31,0x2e,0x30,0x29,0x20,0x2a,0x20,0x58,0x69,0x2e,0x79,0x29,0x29,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x34,0x20, + 0x3d,0x20,0x73,0x71,0x72,0x74,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78, + 0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x28,0x5f,0x31,0x31,0x36,0x20,0x2a,0x20,0x5f, + 0x31,0x31,0x36,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x35,0x32,0x20,0x3d,0x20,0x66, + 0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x63, + 0x72,0x6f,0x73,0x73,0x28,0x73,0x65,0x6c,0x65,0x63,0x74,0x28,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30, + 0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x2c,0x20,0x30, + 0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x2c,0x20,0x62,0x6f,0x6f,0x6c,0x33,0x28, + 0x61,0x62,0x73,0x28,0x4e,0x2e,0x7a,0x29,0x20,0x3c,0x20,0x30,0x2e,0x39,0x39,0x39, + 0x30,0x30,0x30,0x30,0x31,0x32,0x38,0x37,0x34,0x36,0x30,0x33,0x32,0x37,0x31,0x34, + 0x38,0x34,0x33,0x37,0x35,0x29,0x29,0x2c,0x20,0x4e,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e, + 0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x28,0x28,0x5f,0x31,0x35,0x32,0x20, + 0x2a,0x20,0x28,0x5f,0x31,0x32,0x34,0x20,0x2a,0x20,0x63,0x6f,0x73,0x28,0x5f,0x31, + 0x30,0x31,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x63,0x72,0x6f,0x73,0x73,0x28,0x4e, + 0x2c,0x20,0x5f,0x31,0x35,0x32,0x29,0x20,0x2a,0x20,0x28,0x5f,0x31,0x32,0x34,0x20, + 0x2a,0x20,0x73,0x69,0x6e,0x28,0x5f,0x31,0x30,0x31,0x29,0x29,0x29,0x29,0x20,0x2b, + 0x20,0x28,0x4e,0x20,0x2a,0x20,0x5f,0x31,0x31,0x36,0x29,0x29,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f, + 0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f, + 0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e, + 0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f, + 0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x31,0x38,0x36,0x20,0x5b,0x5b,0x62,0x75,0x66, + 0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72, + 0x65,0x63,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78, + 0x5f,0x73,0x6b,0x79,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x30, + 0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70, + 0x5f,0x73,0x6b,0x79,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x30, + 0x29,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30, + 0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x31,0x38,0x31,0x20,0x3d, + 0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x75,0x76,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29, + 0x20,0x2d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x31,0x2e,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x32,0x30,0x39,0x20, + 0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a, + 0x65,0x28,0x28,0x5f,0x31,0x38,0x36,0x2e,0x66,0x61,0x63,0x65,0x5f,0x66,0x6f,0x72, + 0x77,0x61,0x72,0x64,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x31,0x38,0x36, + 0x2e,0x66,0x61,0x63,0x65,0x5f,0x72,0x69,0x67,0x68,0x74,0x2e,0x78,0x79,0x7a,0x20, + 0x2a,0x20,0x5f,0x31,0x38,0x31,0x2e,0x78,0x29,0x29,0x20,0x2b,0x20,0x28,0x5f,0x31, + 0x38,0x36,0x2e,0x66,0x61,0x63,0x65,0x5f,0x75,0x70,0x2e,0x78,0x79,0x7a,0x20,0x2a, + 0x20,0x5f,0x31,0x38,0x31,0x2e,0x79,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x5f,0x31,0x38,0x36,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78, + 0x20,0x3c,0x20,0x30,0x2e,0x30,0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x34, + 0x37,0x34,0x39,0x37,0x34,0x35,0x31,0x33,0x30,0x35,0x33,0x38,0x39,0x34,0x30,0x34, + 0x32,0x39,0x36,0x38,0x37,0x35,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x74,0x65,0x78, + 0x5f,0x73,0x6b,0x79,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f, + 0x73,0x6b,0x79,0x2c,0x20,0x5f,0x32,0x30,0x39,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20, + 0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x72,0x65,0x66,0x69, + 0x6c,0x74,0x65,0x72,0x65,0x64,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, + 0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x74,0x6f,0x74,0x61,0x6c,0x5f,0x77,0x20,0x3d,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6f,0x72,0x20,0x28,0x75,0x69,0x6e,0x74,0x20,0x69,0x20,0x3d, + 0x20,0x30,0x75,0x3b,0x20,0x69,0x20,0x3c,0x20,0x31,0x30,0x32,0x34,0x75,0x3b,0x20, + 0x69,0x2b,0x2b,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20, + 0x69,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x31,0x30,0x32,0x34,0x75,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x68,0x61,0x6d,0x6d,0x65,0x72, + 0x73,0x6c,0x65,0x79,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f, + 0x32,0x30,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x31,0x38, + 0x36,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x32,0x36,0x36,0x20, + 0x3d,0x20,0x69,0x6d,0x70,0x6f,0x72,0x74,0x61,0x6e,0x63,0x65,0x53,0x61,0x6d,0x70, + 0x6c,0x65,0x47,0x47,0x58,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x5f,0x32,0x37,0x36,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f, + 0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x28,0x5f,0x32,0x36,0x36,0x20,0x2a,0x20, + 0x28,0x32,0x2e,0x30,0x20,0x2a,0x20,0x64,0x6f,0x74,0x28,0x5f,0x32,0x30,0x39,0x2c, + 0x20,0x5f,0x32,0x36,0x36,0x29,0x29,0x29,0x20,0x2d,0x20,0x5f,0x32,0x30,0x39,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x32,0x38,0x31,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78, + 0x28,0x64,0x6f,0x74,0x28,0x5f,0x32,0x30,0x39,0x2c,0x20,0x5f,0x32,0x37,0x36,0x29, + 0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x5f,0x32,0x38,0x31,0x20,0x3e,0x20,0x30,0x2e,0x30,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x70,0x72,0x65,0x66,0x69,0x6c,0x74,0x65,0x72,0x65, + 0x64,0x20,0x2b,0x3d,0x20,0x28,0x74,0x65,0x78,0x5f,0x73,0x6b,0x79,0x2e,0x73,0x61, + 0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x6b,0x79,0x2c,0x20,0x5f,0x32, + 0x37,0x36,0x29,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x5f,0x32,0x38,0x31,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x6f,0x74, + 0x61,0x6c,0x5f,0x77,0x20,0x2b,0x3d,0x20,0x5f,0x32,0x38,0x31,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20, + 0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x70,0x72,0x65,0x66,0x69,0x6c,0x74, + 0x65,0x72,0x65,0x64,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x66,0x61, + 0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x74,0x6f,0x74,0x61,0x6c,0x5f,0x77,0x2c, + 0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37, + 0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31, + 0x38,0x38,0x65,0x2d,0x30,0x35,0x29,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x00, +}; +static inline const sg_shader_desc* prefilter_build_shader_desc(sg_backend backend) { + if (backend == SG_BACKEND_GLCORE) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)prefilter_vs_source_glsl430; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)prefilter_fs_source_glsl430; + desc.fragment_func.entry = "main"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[0].glsl_uniforms[0].array_count = 4; + desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_pass"; + desc.views[0].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[0].texture.image_type = SG_IMAGETYPE_CUBE; + desc.views[0].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[0].texture.multisampled = false; + desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[0].view_slot = 0; + desc.texture_sampler_pairs[0].sampler_slot = 0; + desc.texture_sampler_pairs[0].glsl_name = "tex_sky_smp_sky"; + desc.label = "prefilter_build_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_D3D11) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)prefilter_vs_source_hlsl5; + desc.vertex_func.d3d11_target = "vs_5_0"; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)prefilter_fs_source_hlsl5; + desc.fragment_func.d3d11_target = "ps_5_0"; + desc.fragment_func.entry = "main"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].hlsl_register_b_n = 0; + desc.views[0].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[0].texture.image_type = SG_IMAGETYPE_CUBE; + desc.views[0].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[0].texture.multisampled = false; + desc.views[0].texture.hlsl_register_t_n = 0; + desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[0].hlsl_register_s_n = 0; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[0].view_slot = 0; + desc.texture_sampler_pairs[0].sampler_slot = 0; + desc.label = "prefilter_build_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_METAL_MACOS) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)prefilter_vs_source_metal_macos; + desc.vertex_func.entry = "main0"; + desc.fragment_func.source = (const char*)prefilter_fs_source_metal_macos; + desc.fragment_func.entry = "main0"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].msl_buffer_n = 0; + desc.views[0].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[0].texture.image_type = SG_IMAGETYPE_CUBE; + desc.views[0].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[0].texture.multisampled = false; + desc.views[0].texture.msl_texture_n = 0; + desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[0].msl_sampler_n = 0; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[0].view_slot = 0; + desc.texture_sampler_pairs[0].sampler_slot = 0; + desc.label = "prefilter_build_shader"; + } + return &desc; + } + return 0; +} diff --git a/samples/shaders/generated/shadow_caster_capsule.glsl.h b/samples/shaders/generated/shadow_caster_capsule.glsl.h new file mode 100644 index 0000000..17cb593 --- /dev/null +++ b/samples/shaders/generated/shadow_caster_capsule.glsl.h @@ -0,0 +1,607 @@ +#pragma once +/* + #version:1# (machine generated, don't edit!) + + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) + + Cmdline: + sokol-shdc --input E:/box/box3d/samples/shaders/shapes/shadow_caster_capsule.glsl --output E:/box/box3d/samples/shaders/generated/shadow_caster_capsule.glsl.h --slang hlsl5:metal_macos:glsl430 + + Overview: + ========= + Shader program: 'caster': + Get shader desc: shadow_capsule_caster_shader_desc(sg_query_backend()); + Vertex Shader: vs + Fragment Shader: fs + Attributes: + ATTR_shadow_capsule_caster_in_axis => 0 + ATTR_shadow_capsule_caster_in_radial => 1 + Bindings: + Uniform block 'ub_draw': + C struct: shadow_capsule_ub_draw_t + Bind slot: UB_shadow_capsule_ub_draw => 2 + Uniform block 'ub_frame': + C struct: shadow_capsule_ub_frame_t + Bind slot: UB_shadow_capsule_ub_frame => 0 + Storage buffer 'instances': + C struct: shadow_capsule_instance_t + Bind slot: VIEW_shadow_capsule_instances => 0 + Readonly: true +*/ +#if !defined(SOKOL_GFX_INCLUDED) +#error "Please include sokol_gfx.h before shadow_caster_capsule.glsl.h" +#endif +#if !defined(SOKOL_SHDC_ALIGN) +#if defined(_MSC_VER) +#define SOKOL_SHDC_ALIGN(a) __declspec(align(a)) +#else +#define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) +#endif +#endif +#define ATTR_shadow_capsule_caster_in_axis (0) +#define ATTR_shadow_capsule_caster_in_radial (1) +#define UB_shadow_capsule_ub_draw (2) +#define UB_shadow_capsule_ub_frame (0) +#define VIEW_shadow_capsule_instances (0) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct shadow_capsule_ub_draw_t { + int inst_base[4]; +} shadow_capsule_ub_draw_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct shadow_capsule_ub_frame_t { + Mat4 light_view_proj; +} shadow_capsule_ub_frame_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct shadow_capsule_instance_t { + Vec4 xform_row0; + Vec4 xform_row1; + Vec4 xform_row2; + Vec4 base_color; + Vec4 params; + Vec4 material; +} shadow_capsule_instance_t; +#pragma pack(pop) +/* + #version 430 + + struct instance + { + vec4 xform_row0; + vec4 xform_row1; + vec4 xform_row2; + vec4 base_color; + vec4 params; + vec4 material; + }; + + layout(binding = 0, std430) readonly buffer instances + { + instance items[]; + } _15; + + uniform ivec4 ub_draw[1]; + uniform vec4 ub_frame[4]; + layout(location = 0) in vec3 in_axis; + layout(location = 1) in vec3 in_radial; + + void main() + { + int _30 = ub_draw[0].x + gl_InstanceID; + vec3 _81 = (in_axis * _15.items[_30].params.x) + (in_radial * _15.items[_30].params.y); + gl_Position = mat4(ub_frame[0], ub_frame[1], ub_frame[2], ub_frame[3]) * vec4(vec3(_15.items[_30].xform_row0.w, _15.items[_30].xform_row1.w, _15.items[_30].xform_row2.w) + vec3(dot(_15.items[_30].xform_row0.xyz, _81), dot(_15.items[_30].xform_row1.xyz, _81), dot(_15.items[_30].xform_row2.xyz, _81)), 1.0); + } + +*/ +static const uint8_t shadow_capsule_vs_source_glsl430[838] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72, + 0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x6d,0x61, + 0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f, + 0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x30,0x2c,0x20, + 0x73,0x74,0x64,0x34,0x33,0x30,0x29,0x20,0x72,0x65,0x61,0x64,0x6f,0x6e,0x6c,0x79, + 0x20,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x20,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5d,0x3b,0x0a,0x7d,0x20,0x5f,0x31,0x35,0x3b, + 0x0a,0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x69,0x76,0x65,0x63,0x34,0x20, + 0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x5b,0x31,0x5d,0x3b,0x0a,0x75,0x6e,0x69,0x66, + 0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d, + 0x65,0x5b,0x34,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63, + 0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65, + 0x63,0x33,0x20,0x69,0x6e,0x5f,0x61,0x78,0x69,0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f, + 0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29, + 0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x69,0x6e,0x5f,0x72,0x61,0x64,0x69, + 0x61,0x6c,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x33,0x30,0x20,0x3d, + 0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x5b,0x30,0x5d,0x2e,0x78,0x20,0x2b,0x20, + 0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x38,0x31,0x20,0x3d,0x20,0x28,0x69, + 0x6e,0x5f,0x61,0x78,0x69,0x73,0x20,0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65, + 0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78, + 0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6c,0x20,0x2a, + 0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e, + 0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67, + 0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74, + 0x34,0x28,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x30,0x5d,0x2c,0x20,0x75, + 0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x31,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66, + 0x72,0x61,0x6d,0x65,0x5b,0x32,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d, + 0x65,0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63, + 0x33,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d, + 0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f, + 0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e, + 0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d, + 0x5f,0x72,0x6f,0x77,0x32,0x2e,0x77,0x29,0x20,0x2b,0x20,0x76,0x65,0x63,0x33,0x28, + 0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33, + 0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x78,0x79, + 0x7a,0x2c,0x20,0x5f,0x38,0x31,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35, + 0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x38,0x31,0x29, + 0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b, + 0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e, + 0x78,0x79,0x7a,0x2c,0x20,0x5f,0x38,0x31,0x29,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + #version 430 + + void main() + { + } + +*/ +static const uint8_t shadow_capsule_fs_source_glsl430[32] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x76,0x6f, + 0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x7d,0x0a,0x0a,0x00, + +}; +/* + struct instance + { + float4 xform_row0; + float4 xform_row1; + float4 xform_row2; + float4 base_color; + float4 params; + float4 material; + }; + + ByteAddressBuffer _15 : register(t0); + cbuffer ub_draw : register(b2) + { + int4 _21_inst_base : packoffset(c0); + }; + + cbuffer ub_frame : register(b0) + { + row_major float4x4 _108_light_view_proj : packoffset(c0); + }; + + + static float4 gl_Position; + static int gl_InstanceIndex; + static float3 in_axis; + static float3 in_radial; + + struct SPIRV_Cross_Input + { + float3 in_axis : TEXCOORD0; + float3 in_radial : TEXCOORD1; + uint gl_InstanceIndex : SV_InstanceID; + }; + + struct SPIRV_Cross_Output + { + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + instance _33; + _33.xform_row0 = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 0)); + _33.xform_row1 = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 16)); + _33.xform_row2 = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 32)); + _33.base_color = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 48)); + _33.params = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 64)); + _33.material = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 80)); + float3 _81 = (in_axis * _33.params.x) + (in_radial * _33.params.y); + gl_Position = mul(float4(float3(_33.xform_row0.w, _33.xform_row1.w, _33.xform_row2.w) + float3(dot(_33.xform_row0.xyz, _81), dot(_33.xform_row1.xyz, _81), dot(_33.xform_row2.xyz, _81)), 1.0f), _108_light_view_proj); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_InstanceIndex = int(stage_input.gl_InstanceIndex); + in_axis = stage_input.in_axis; + in_radial = stage_input.in_radial; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + return stage_output; + } +*/ +static const uint8_t shadow_capsule_vs_source_hlsl5[1860] = { + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d, + 0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x73,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6d,0x61,0x74,0x65, + 0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x42,0x79,0x74,0x65,0x41,0x64, + 0x64,0x72,0x65,0x73,0x73,0x42,0x75,0x66,0x66,0x65,0x72,0x20,0x5f,0x31,0x35,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x30,0x29,0x3b,0x0a, + 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x32,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x34,0x20,0x5f,0x32,0x31,0x5f,0x69,0x6e, + 0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66, + 0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x63,0x62, + 0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x20,0x3a, + 0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x31,0x30,0x38,0x5f,0x6c,0x69,0x67,0x68, + 0x74,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61, + 0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x73,0x74, + 0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69, + 0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x61,0x78,0x69,0x73, + 0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x69,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75, + 0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49, + 0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x69,0x6e,0x5f,0x61,0x78,0x69,0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43, + 0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x69,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6c,0x20,0x3a,0x20,0x54,0x45, + 0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e, + 0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64, + 0x65,0x78,0x20,0x3a,0x20,0x53,0x56,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x49,0x44,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53, + 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75, + 0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67, + 0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,0x53,0x56,0x5f, + 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x6f, + 0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20,0x5f,0x33, + 0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d, + 0x5f,0x72,0x6f,0x77,0x30,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28, + 0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69, + 0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f, + 0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a, + 0x20,0x39,0x36,0x20,0x2b,0x20,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f, + 0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x20,0x3d,0x20, + 0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64, + 0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65, + 0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x31,0x36, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x32,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74, + 0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f, + 0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c, + 0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20, + 0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x33,0x32,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x5f,0x33,0x33,0x2e,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20, + 0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f, + 0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61, + 0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20, + 0x34,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x70,0x61, + 0x72,0x61,0x6d,0x73,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f, + 0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e, + 0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20, + 0x39,0x36,0x20,0x2b,0x20,0x36,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f, + 0x33,0x33,0x2e,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3d,0x20,0x61,0x73, + 0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28, + 0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78, + 0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e, + 0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x38,0x30,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x38,0x31, + 0x20,0x3d,0x20,0x28,0x69,0x6e,0x5f,0x61,0x78,0x69,0x73,0x20,0x2a,0x20,0x5f,0x33, + 0x33,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x20,0x2b,0x20,0x28,0x69, + 0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6c,0x20,0x2a,0x20,0x5f,0x33,0x33,0x2e,0x70, + 0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c, + 0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x33, + 0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20, + 0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x77, + 0x2c,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32, + 0x2e,0x77,0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x64,0x6f,0x74, + 0x28,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e, + 0x78,0x79,0x7a,0x2c,0x20,0x5f,0x38,0x31,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f, + 0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x79, + 0x7a,0x2c,0x20,0x5f,0x38,0x31,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x33,0x33, + 0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x78,0x79,0x7a,0x2c, + 0x20,0x5f,0x38,0x31,0x29,0x29,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f, + 0x31,0x30,0x38,0x5f,0x6c,0x69,0x67,0x68,0x74,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70, + 0x72,0x6f,0x6a,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, + 0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e, + 0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70, + 0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x3d,0x20,0x69,0x6e,0x74,0x28,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x6e,0x5f,0x61,0x78,0x69,0x73,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f, + 0x69,0x6e,0x70,0x75,0x74,0x2e,0x69,0x6e,0x5f,0x61,0x78,0x69,0x73,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6c,0x20,0x3d,0x20,0x73, + 0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x69,0x6e,0x5f,0x72,0x61, + 0x64,0x69,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d, + 0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56, + 0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74, + 0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f, + 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x50,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b, + 0x0a,0x7d,0x0a,0x00, +}; +/* + void frag_main() + { + } + + void main() + { + frag_main(); + } +*/ +static const uint8_t shadow_capsule_fs_source_hlsl5[56] = { + 0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29, + 0x0a,0x7b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69, + 0x6e,0x28,0x29,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + struct instance + { + float4 xform_row0; + float4 xform_row1; + float4 xform_row2; + float4 base_color; + float4 params; + float4 material; + }; + + struct instances + { + instance items[1]; + }; + + struct ub_draw + { + int4 inst_base; + }; + + struct ub_frame + { + float4x4 light_view_proj; + }; + + struct main0_out + { + float4 gl_Position [[position]]; + }; + + struct main0_in + { + float3 in_axis [[attribute(0)]]; + float3 in_radial [[attribute(1)]]; + }; + + vertex main0_out main0(main0_in in [[stage_in]], constant ub_frame& _108 [[buffer(0)]], constant ub_draw& _21 [[buffer(2)]], const device instances& _15 [[buffer(8)]], uint gl_InstanceIndex [[instance_id]]) + { + main0_out out = {}; + int _30 = _21.inst_base.x + int(gl_InstanceIndex); + float3 _81 = (in.in_axis * _15.items[_30].params.x) + (in.in_radial * _15.items[_30].params.y); + out.gl_Position = _108.light_view_proj * float4(float3(_15.items[_30].xform_row0.w, _15.items[_30].xform_row1.w, _15.items[_30].xform_row2.w) + float3(dot(_15.items[_30].xform_row0.xyz, _81), dot(_15.items[_30].xform_row1.xyz, _81), dot(_15.items[_30].xform_row2.xyz, _81)), 1.0); + return out; + } + +*/ +static const uint8_t shadow_capsule_vs_source_metal_macos[1216] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x20,0x69,0x74,0x65,0x6d,0x73,0x5b,0x31,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a, + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x34,0x20,0x69,0x6e,0x73,0x74,0x5f,0x62, + 0x61,0x73,0x65,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20, + 0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72, + 0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f, + 0x6e,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20, + 0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x61,0x78,0x69,0x73,0x20,0x5b,0x5b, + 0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x72,0x61, + 0x64,0x69,0x61,0x6c,0x20,0x5b,0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65, + 0x28,0x31,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,0x65, + 0x78,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e, + 0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x26,0x20,0x5f, + 0x31,0x30,0x38,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x30,0x29,0x5d, + 0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x64, + 0x72,0x61,0x77,0x26,0x20,0x5f,0x32,0x31,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65, + 0x72,0x28,0x32,0x29,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x64,0x65, + 0x76,0x69,0x63,0x65,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x26,0x20, + 0x5f,0x31,0x35,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x38,0x29,0x5d, + 0x5d,0x2c,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61, + 0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x5b,0x5b,0x69,0x6e,0x73,0x74,0x61, + 0x6e,0x63,0x65,0x5f,0x69,0x64,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20, + 0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x33,0x30,0x20, + 0x3d,0x20,0x5f,0x32,0x31,0x2e,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e, + 0x78,0x20,0x2b,0x20,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61, + 0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x38,0x31,0x20,0x3d,0x20,0x28,0x69,0x6e,0x2e, + 0x69,0x6e,0x5f,0x61,0x78,0x69,0x73,0x20,0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74, + 0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e, + 0x78,0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x69,0x6e,0x5f,0x72,0x61,0x64,0x69, + 0x61,0x6c,0x20,0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f, + 0x33,0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69, + 0x6f,0x6e,0x20,0x3d,0x20,0x5f,0x31,0x30,0x38,0x2e,0x6c,0x69,0x67,0x68,0x74,0x5f, + 0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74, + 0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72, + 0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73, + 0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31, + 0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33, + 0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x77,0x29, + 0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31, + 0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x38,0x31, + 0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73, + 0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31, + 0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x38,0x31,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28, + 0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78, + 0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f, + 0x38,0x31,0x29,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + +}; +/* + #include + #include + + using namespace metal; + + fragment void main0() + { + } + +*/ +static const uint8_t shadow_capsule_fs_source_metal_macos[100] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74, + 0x20,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x29,0x0a,0x7b,0x0a, + 0x7d,0x0a,0x0a,0x00, +}; +static inline const sg_shader_desc* shadow_capsule_caster_shader_desc(sg_backend backend) { + if (backend == SG_BACKEND_GLCORE) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)shadow_capsule_vs_source_glsl430; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)shadow_capsule_fs_source_glsl430; + desc.fragment_func.entry = "main"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[0].glsl_name = "in_axis"; + desc.attrs[1].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[1].glsl_name = "in_radial"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[0].glsl_uniforms[0].array_count = 4; + desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_frame"; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 16; + desc.uniform_blocks[2].glsl_uniforms[0].type = SG_UNIFORMTYPE_INT4; + desc.uniform_blocks[2].glsl_uniforms[0].array_count = 1; + desc.uniform_blocks[2].glsl_uniforms[0].glsl_name = "ub_draw"; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.glsl_binding_n = 0; + desc.label = "shadow_capsule_caster_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_D3D11) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)shadow_capsule_vs_source_hlsl5; + desc.vertex_func.d3d11_target = "vs_5_0"; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)shadow_capsule_fs_source_hlsl5; + desc.fragment_func.d3d11_target = "ps_5_0"; + desc.fragment_func.entry = "main"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[0].hlsl_sem_name = "TEXCOORD"; + desc.attrs[0].hlsl_sem_index = 0; + desc.attrs[1].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[1].hlsl_sem_name = "TEXCOORD"; + desc.attrs[1].hlsl_sem_index = 1; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].hlsl_register_b_n = 0; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 16; + desc.uniform_blocks[2].hlsl_register_b_n = 2; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.hlsl_register_t_n = 0; + desc.label = "shadow_capsule_caster_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_METAL_MACOS) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)shadow_capsule_vs_source_metal_macos; + desc.vertex_func.entry = "main0"; + desc.fragment_func.source = (const char*)shadow_capsule_fs_source_metal_macos; + desc.fragment_func.entry = "main0"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[1].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].msl_buffer_n = 0; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 16; + desc.uniform_blocks[2].msl_buffer_n = 2; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.msl_buffer_n = 8; + desc.label = "shadow_capsule_caster_shader"; + } + return &desc; + } + return 0; +} diff --git a/samples/shaders/generated/shadow_caster_cube.glsl.h b/samples/shaders/generated/shadow_caster_cube.glsl.h new file mode 100644 index 0000000..c3abc28 --- /dev/null +++ b/samples/shaders/generated/shadow_caster_cube.glsl.h @@ -0,0 +1,544 @@ +#pragma once +/* + #version:1# (machine generated, don't edit!) + + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) + + Cmdline: + sokol-shdc --input E:/box/box3d/samples/shaders/shapes/shadow_caster_cube.glsl --output E:/box/box3d/samples/shaders/generated/shadow_caster_cube.glsl.h --slang hlsl5:metal_macos:glsl430 + + Overview: + ========= + Shader program: 'caster': + Get shader desc: shadow_cube_caster_shader_desc(sg_query_backend()); + Vertex Shader: vs + Fragment Shader: fs + Attributes: + ATTR_shadow_cube_caster_in_pos => 0 + Bindings: + Uniform block 'ub_draw': + C struct: shadow_cube_ub_draw_t + Bind slot: UB_shadow_cube_ub_draw => 2 + Uniform block 'ub_frame': + C struct: shadow_cube_ub_frame_t + Bind slot: UB_shadow_cube_ub_frame => 0 + Storage buffer 'cube_instances': + C struct: shadow_cube_cube_instance_t + Bind slot: VIEW_shadow_cube_cube_instances => 0 + Readonly: true +*/ +#if !defined(SOKOL_GFX_INCLUDED) +#error "Please include sokol_gfx.h before shadow_caster_cube.glsl.h" +#endif +#if !defined(SOKOL_SHDC_ALIGN) +#if defined(_MSC_VER) +#define SOKOL_SHDC_ALIGN(a) __declspec(align(a)) +#else +#define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) +#endif +#endif +#define ATTR_shadow_cube_caster_in_pos (0) +#define UB_shadow_cube_ub_draw (2) +#define UB_shadow_cube_ub_frame (0) +#define VIEW_shadow_cube_cube_instances (0) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct shadow_cube_ub_draw_t { + int inst_base[4]; +} shadow_cube_ub_draw_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct shadow_cube_ub_frame_t { + Mat4 light_view_proj; +} shadow_cube_ub_frame_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct shadow_cube_cube_instance_t { + Vec4 xform_row0; + Vec4 xform_row1; + Vec4 xform_row2; + Vec4 base_color; + Vec4 material; +} shadow_cube_cube_instance_t; +#pragma pack(pop) +/* + #version 430 + + struct cube_instance + { + vec4 xform_row0; + vec4 xform_row1; + vec4 xform_row2; + vec4 base_color; + vec4 material; + }; + + layout(binding = 0, std430) readonly buffer cube_instances + { + cube_instance instances[]; + } _15; + + uniform ivec4 ub_draw[1]; + uniform vec4 ub_frame[4]; + layout(location = 0) in vec3 in_pos; + + void main() + { + int _30 = ub_draw[0].x + gl_InstanceID; + vec4 _58 = vec4(in_pos, 1.0); + gl_Position = mat4(ub_frame[0], ub_frame[1], ub_frame[2], ub_frame[3]) * vec4(dot(_15.instances[_30].xform_row0, _58), dot(_15.instances[_30].xform_row1, _58), dot(_15.instances[_30].xform_row2, _58), 1.0); + } + +*/ +static const uint8_t shadow_cube_vs_source_glsl430[641] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x63,0x75,0x62,0x65,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f, + 0x77,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x62,0x61,0x73, + 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x34,0x20,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a, + 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d, + 0x20,0x30,0x2c,0x20,0x73,0x74,0x64,0x34,0x33,0x30,0x29,0x20,0x72,0x65,0x61,0x64, + 0x6f,0x6e,0x6c,0x79,0x20,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x63,0x75,0x62,0x65, + 0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x63,0x75,0x62,0x65,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20,0x69, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x5d,0x3b,0x0a,0x7d,0x20,0x5f,0x31, + 0x35,0x3b,0x0a,0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x69,0x76,0x65,0x63, + 0x34,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x5b,0x31,0x5d,0x3b,0x0a,0x75,0x6e, + 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x66,0x72, + 0x61,0x6d,0x65,0x5b,0x34,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, + 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20, + 0x76,0x65,0x63,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x0a,0x76,0x6f, + 0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x6e,0x74,0x20,0x5f,0x33,0x30,0x20,0x3d,0x20,0x75,0x62,0x5f,0x64,0x72,0x61, + 0x77,0x5b,0x30,0x5d,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x49,0x44,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34, + 0x20,0x5f,0x35,0x38,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x69,0x6e,0x5f,0x70, + 0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c, + 0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34, + 0x28,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x30,0x5d,0x2c,0x20,0x75,0x62, + 0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x31,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72, + 0x61,0x6d,0x65,0x5b,0x32,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65, + 0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x64,0x6f,0x74,0x28, + 0x5f,0x31,0x35,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x5f,0x33, + 0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2c,0x20,0x5f, + 0x35,0x38,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x6e,0x73, + 0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2c,0x20,0x5f,0x35,0x38,0x29,0x2c,0x20,0x64,0x6f, + 0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b, + 0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2c, + 0x20,0x5f,0x35,0x38,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a, + 0x00, +}; +/* + #version 430 + + void main() + { + } + +*/ +static const uint8_t shadow_cube_fs_source_glsl430[32] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x76,0x6f, + 0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x7d,0x0a,0x0a,0x00, + +}; +/* + struct cube_instance + { + float4 xform_row0; + float4 xform_row1; + float4 xform_row2; + float4 base_color; + float4 material; + }; + + ByteAddressBuffer _15 : register(t0); + cbuffer ub_draw : register(b2) + { + int4 _21_inst_base : packoffset(c0); + }; + + cbuffer ub_frame : register(b0) + { + row_major float4x4 _82_light_view_proj : packoffset(c0); + }; + + + static float4 gl_Position; + static int gl_InstanceIndex; + static float3 in_pos; + + struct SPIRV_Cross_Input + { + float3 in_pos : TEXCOORD0; + uint gl_InstanceIndex : SV_InstanceID; + }; + + struct SPIRV_Cross_Output + { + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + cube_instance _33; + _33.xform_row0 = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 80 + 0)); + _33.xform_row1 = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 80 + 16)); + _33.xform_row2 = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 80 + 32)); + _33.base_color = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 80 + 48)); + _33.material = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 80 + 64)); + float4 _58 = float4(in_pos, 1.0f); + gl_Position = mul(float4(dot(_33.xform_row0, _58), dot(_33.xform_row1, _58), dot(_33.xform_row2, _58), 1.0f), _82_light_view_proj); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_InstanceIndex = int(stage_input.gl_InstanceIndex); + in_pos = stage_input.in_pos; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + return stage_output; + } +*/ +static const uint8_t shadow_cube_vs_source_hlsl5[1546] = { + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x63,0x75,0x62,0x65,0x5f,0x69,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72, + 0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6d,0x61, + 0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x42,0x79,0x74,0x65, + 0x41,0x64,0x64,0x72,0x65,0x73,0x73,0x42,0x75,0x66,0x66,0x65,0x72,0x20,0x5f,0x31, + 0x35,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x30,0x29, + 0x3b,0x0a,0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x64,0x72,0x61, + 0x77,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x32,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x34,0x20,0x5f,0x32,0x31,0x5f, + 0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b, + 0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a, + 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65, + 0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x38,0x32,0x5f,0x6c,0x69,0x67, + 0x68,0x74,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70, + 0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x7d, + 0x3b,0x0a,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x73, + 0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73, + 0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74, + 0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73, + 0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f, + 0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20, + 0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x3a,0x20,0x53,0x56,0x5f,0x49,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x49,0x44,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75, + 0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f, + 0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a, + 0x20,0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e, + 0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x63,0x75,0x62,0x65,0x5f,0x69,0x6e, + 0x73,0x74,0x61,0x6e,0x63,0x65,0x20,0x5f,0x33,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x20,0x3d, + 0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61, + 0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73, + 0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x38,0x30,0x20,0x2b,0x20,0x30, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x31,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74, + 0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f, + 0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c, + 0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20, + 0x2a,0x20,0x38,0x30,0x20,0x2b,0x20,0x31,0x36,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x20, + 0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f, + 0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61, + 0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x38,0x30,0x20,0x2b,0x20, + 0x33,0x32,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x62,0x61, + 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f, + 0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32, + 0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20, + 0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78, + 0x29,0x20,0x2a,0x20,0x38,0x30,0x20,0x2b,0x20,0x34,0x38,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20, + 0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f, + 0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61, + 0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x38,0x30,0x20,0x2b,0x20, + 0x36,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x5f,0x35,0x38,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x69,0x6e, + 0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d, + 0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x64,0x6f,0x74,0x28,0x5f,0x33, + 0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2c,0x20,0x5f,0x35, + 0x38,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2c,0x20,0x5f,0x35,0x38,0x29,0x2c,0x20,0x64,0x6f, + 0x74,0x28,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32, + 0x2c,0x20,0x5f,0x35,0x38,0x29,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f, + 0x38,0x32,0x5f,0x6c,0x69,0x67,0x68,0x74,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72, + 0x6f,0x6a,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, + 0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28, + 0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75, + 0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x49,0x6e,0x64,0x65,0x78,0x20,0x3d,0x20,0x69,0x6e,0x74,0x28,0x73,0x74,0x61,0x67, + 0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61, + 0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x6e,0x5f,0x70,0x6f,0x73,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e, + 0x70,0x75,0x74,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74, + 0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70, + 0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d, + 0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f, + 0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + void frag_main() + { + } + + void main() + { + frag_main(); + } +*/ +static const uint8_t shadow_cube_fs_source_hlsl5[56] = { + 0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29, + 0x0a,0x7b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69, + 0x6e,0x28,0x29,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + struct cube_instance + { + float4 xform_row0; + float4 xform_row1; + float4 xform_row2; + float4 base_color; + float4 material; + }; + + struct cube_instances + { + cube_instance instances[1]; + }; + + struct ub_draw + { + int4 inst_base; + }; + + struct ub_frame + { + float4x4 light_view_proj; + }; + + struct main0_out + { + float4 gl_Position [[position]]; + }; + + struct main0_in + { + float3 in_pos [[attribute(0)]]; + }; + + vertex main0_out main0(main0_in in [[stage_in]], constant ub_frame& _82 [[buffer(0)]], constant ub_draw& _21 [[buffer(2)]], const device cube_instances& _15 [[buffer(8)]], uint gl_InstanceIndex [[instance_id]]) + { + main0_out out = {}; + int _30 = _21.inst_base.x + int(gl_InstanceIndex); + float4 _58 = float4(in.in_pos, 1.0); + out.gl_Position = _82.light_view_proj * float4(dot(_15.instances[_30].xform_row0, _58), dot(_15.instances[_30].xform_row1, _58), dot(_15.instances[_30].xform_row2, _58), 1.0); + return out; + } + +*/ +static const uint8_t shadow_cube_vs_source_metal_macos[1016] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x63, + 0x75,0x62,0x65,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f, + 0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f, + 0x77,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x62, + 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a, + 0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x63,0x75,0x62,0x65,0x5f, + 0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x63,0x75,0x62,0x65,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20,0x69,0x6e, + 0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x31,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a, + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x34,0x20,0x69,0x6e,0x73,0x74,0x5f,0x62, + 0x61,0x73,0x65,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20, + 0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72, + 0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f, + 0x6e,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20, + 0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x5b,0x5b,0x61, + 0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d, + 0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,0x65,0x78,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f, + 0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f, + 0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e, + 0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f, + 0x66,0x72,0x61,0x6d,0x65,0x26,0x20,0x5f,0x38,0x32,0x20,0x5b,0x5b,0x62,0x75,0x66, + 0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61, + 0x6e,0x74,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x26,0x20,0x5f,0x32,0x31,0x20, + 0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x32,0x29,0x5d,0x5d,0x2c,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x20,0x63,0x75,0x62,0x65, + 0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x26,0x20,0x5f,0x31,0x35,0x20, + 0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x38,0x29,0x5d,0x5d,0x2c,0x20,0x75, + 0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49, + 0x6e,0x64,0x65,0x78,0x20,0x5b,0x5b,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x5f, + 0x69,0x64,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e, + 0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x33,0x30,0x20,0x3d,0x20,0x5f,0x32, + 0x31,0x2e,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20, + 0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49, + 0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x5f,0x35,0x38,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x69, + 0x6e,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74, + 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x5f,0x38,0x32,0x2e,0x6c,0x69,0x67,0x68,0x74,0x5f, + 0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x6e,0x73,0x74,0x61, + 0x6e,0x63,0x65,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f, + 0x72,0x6f,0x77,0x30,0x2c,0x20,0x5f,0x35,0x38,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28, + 0x5f,0x31,0x35,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x5f,0x33, + 0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2c,0x20,0x5f, + 0x35,0x38,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x6e,0x73, + 0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2c,0x20,0x5f,0x35,0x38,0x29,0x2c,0x20,0x31,0x2e, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f, + 0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + fragment void main0() + { + } + +*/ +static const uint8_t shadow_cube_fs_source_metal_macos[100] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74, + 0x20,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x29,0x0a,0x7b,0x0a, + 0x7d,0x0a,0x0a,0x00, +}; +static inline const sg_shader_desc* shadow_cube_caster_shader_desc(sg_backend backend) { + if (backend == SG_BACKEND_GLCORE) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)shadow_cube_vs_source_glsl430; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)shadow_cube_fs_source_glsl430; + desc.fragment_func.entry = "main"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[0].glsl_name = "in_pos"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[0].glsl_uniforms[0].array_count = 4; + desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_frame"; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 16; + desc.uniform_blocks[2].glsl_uniforms[0].type = SG_UNIFORMTYPE_INT4; + desc.uniform_blocks[2].glsl_uniforms[0].array_count = 1; + desc.uniform_blocks[2].glsl_uniforms[0].glsl_name = "ub_draw"; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.glsl_binding_n = 0; + desc.label = "shadow_cube_caster_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_D3D11) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)shadow_cube_vs_source_hlsl5; + desc.vertex_func.d3d11_target = "vs_5_0"; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)shadow_cube_fs_source_hlsl5; + desc.fragment_func.d3d11_target = "ps_5_0"; + desc.fragment_func.entry = "main"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[0].hlsl_sem_name = "TEXCOORD"; + desc.attrs[0].hlsl_sem_index = 0; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].hlsl_register_b_n = 0; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 16; + desc.uniform_blocks[2].hlsl_register_b_n = 2; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.hlsl_register_t_n = 0; + desc.label = "shadow_cube_caster_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_METAL_MACOS) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)shadow_cube_vs_source_metal_macos; + desc.vertex_func.entry = "main0"; + desc.fragment_func.source = (const char*)shadow_cube_fs_source_metal_macos; + desc.fragment_func.entry = "main0"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].msl_buffer_n = 0; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 16; + desc.uniform_blocks[2].msl_buffer_n = 2; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.msl_buffer_n = 8; + desc.label = "shadow_cube_caster_shader"; + } + return &desc; + } + return 0; +} diff --git a/samples/shaders/generated/shadow_caster_geom.glsl.h b/samples/shaders/generated/shadow_caster_geom.glsl.h new file mode 100644 index 0000000..4bc313d --- /dev/null +++ b/samples/shaders/generated/shadow_caster_geom.glsl.h @@ -0,0 +1,557 @@ +#pragma once +/* + #version:1# (machine generated, don't edit!) + + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) + + Cmdline: + sokol-shdc --input E:/box/box3d/samples/shaders/shapes/shadow_caster_geom.glsl --output E:/box/box3d/samples/shaders/generated/shadow_caster_geom.glsl.h --slang hlsl5:metal_macos:glsl430 + + Overview: + ========= + Shader program: 'caster': + Get shader desc: shadow_geom_caster_shader_desc(sg_query_backend()); + Vertex Shader: vs + Fragment Shader: fs + Attributes: + ATTR_shadow_geom_caster_in_pos => 0 + Bindings: + Uniform block 'ub_draw': + C struct: shadow_geom_ub_draw_t + Bind slot: UB_shadow_geom_ub_draw => 2 + Uniform block 'ub_frame': + C struct: shadow_geom_ub_frame_t + Bind slot: UB_shadow_geom_ub_frame => 0 + Storage buffer 'instances': + C struct: shadow_geom_instance_t + Bind slot: VIEW_shadow_geom_instances => 0 + Readonly: true +*/ +#if !defined(SOKOL_GFX_INCLUDED) +#error "Please include sokol_gfx.h before shadow_caster_geom.glsl.h" +#endif +#if !defined(SOKOL_SHDC_ALIGN) +#if defined(_MSC_VER) +#define SOKOL_SHDC_ALIGN(a) __declspec(align(a)) +#else +#define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) +#endif +#endif +#define ATTR_shadow_geom_caster_in_pos (0) +#define UB_shadow_geom_ub_draw (2) +#define UB_shadow_geom_ub_frame (0) +#define VIEW_shadow_geom_instances (0) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct shadow_geom_ub_draw_t { + int inst_base[4]; +} shadow_geom_ub_draw_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct shadow_geom_ub_frame_t { + Mat4 light_view_proj; +} shadow_geom_ub_frame_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct shadow_geom_instance_t { + Vec4 xform_row0; + Vec4 xform_row1; + Vec4 xform_row2; + Vec4 base_color; + Vec4 scale; + Vec4 material; +} shadow_geom_instance_t; +#pragma pack(pop) +/* + #version 430 + + struct instance + { + vec4 xform_row0; + vec4 xform_row1; + vec4 xform_row2; + vec4 base_color; + vec4 scale; + vec4 material; + }; + + layout(binding = 0, std430) readonly buffer instances + { + instance items[]; + } _15; + + uniform ivec4 ub_draw[1]; + uniform vec4 ub_frame[4]; + layout(location = 0) in vec3 in_pos; + + void main() + { + int _30 = ub_draw[0].x + gl_InstanceID; + vec4 _68 = vec4(in_pos * _15.items[_30].scale.xyz, 1.0); + gl_Position = mat4(ub_frame[0], ub_frame[1], ub_frame[2], ub_frame[3]) * vec4(dot(_15.items[_30].xform_row0, _68), dot(_15.items[_30].xform_row1, _68), dot(_15.items[_30].xform_row2, _68), 1.0); + } + +*/ +static const uint8_t shadow_geom_vs_source_glsl430[653] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72, + 0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x63,0x61, + 0x6c,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x6d,0x61,0x74, + 0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75, + 0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x30,0x2c,0x20,0x73, + 0x74,0x64,0x34,0x33,0x30,0x29,0x20,0x72,0x65,0x61,0x64,0x6f,0x6e,0x6c,0x79,0x20, + 0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20, + 0x69,0x74,0x65,0x6d,0x73,0x5b,0x5d,0x3b,0x0a,0x7d,0x20,0x5f,0x31,0x35,0x3b,0x0a, + 0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x69,0x76,0x65,0x63,0x34,0x20,0x75, + 0x62,0x5f,0x64,0x72,0x61,0x77,0x5b,0x31,0x5d,0x3b,0x0a,0x75,0x6e,0x69,0x66,0x6f, + 0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65, + 0x5b,0x34,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63, + 0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20, + 0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74, + 0x20,0x5f,0x33,0x30,0x20,0x3d,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x5b,0x30, + 0x5d,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x49,0x44,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x36, + 0x38,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20, + 0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d, + 0x2e,0x73,0x63,0x61,0x6c,0x65,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31,0x2e,0x30,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f, + 0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d, + 0x65,0x5b,0x30,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x31, + 0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x32,0x5d,0x2c,0x20, + 0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x76, + 0x65,0x63,0x34,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d, + 0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77, + 0x30,0x2c,0x20,0x5f,0x36,0x38,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35, + 0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2c,0x20,0x5f,0x36,0x38,0x29,0x2c,0x20,0x64,0x6f, + 0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d, + 0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2c,0x20,0x5f,0x36,0x38, + 0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + #version 430 + + void main() + { + } + +*/ +static const uint8_t shadow_geom_fs_source_glsl430[32] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x76,0x6f, + 0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x7d,0x0a,0x0a,0x00, + +}; +/* + struct instance + { + float4 xform_row0; + float4 xform_row1; + float4 xform_row2; + float4 base_color; + float4 scale; + float4 material; + }; + + ByteAddressBuffer _15 : register(t0); + cbuffer ub_draw : register(b2) + { + int4 _21_inst_base : packoffset(c0); + }; + + cbuffer ub_frame : register(b0) + { + row_major float4x4 _91_light_view_proj : packoffset(c0); + }; + + + static float4 gl_Position; + static int gl_InstanceIndex; + static float3 in_pos; + + struct SPIRV_Cross_Input + { + float3 in_pos : TEXCOORD0; + uint gl_InstanceIndex : SV_InstanceID; + }; + + struct SPIRV_Cross_Output + { + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + instance _33; + _33.xform_row0 = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 0)); + _33.xform_row1 = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 16)); + _33.xform_row2 = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 32)); + _33.base_color = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 48)); + _33.scale = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 64)); + _33.material = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 80)); + float4 _68 = float4(in_pos * _33.scale.xyz, 1.0f); + gl_Position = mul(float4(dot(_33.xform_row0, _68), dot(_33.xform_row1, _68), dot(_33.xform_row2, _68), 1.0f), _91_light_view_proj); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_InstanceIndex = int(stage_input.gl_InstanceIndex); + in_pos = stage_input.in_pos; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + return stage_output; + } +*/ +static const uint8_t shadow_geom_vs_source_hlsl5[1654] = { + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d, + 0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x63,0x61,0x6c,0x65,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6d,0x61,0x74,0x65,0x72, + 0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x42,0x79,0x74,0x65,0x41,0x64,0x64, + 0x72,0x65,0x73,0x73,0x42,0x75,0x66,0x66,0x65,0x72,0x20,0x5f,0x31,0x35,0x20,0x3a, + 0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x30,0x29,0x3b,0x0a,0x63, + 0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x20,0x3a, + 0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x32,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x34,0x20,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73, + 0x74,0x5f,0x62,0x61,0x73,0x65,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66, + 0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x63,0x62,0x75, + 0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x20,0x3a,0x20, + 0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x39,0x31,0x5f,0x6c,0x69,0x67,0x68,0x74,0x5f, + 0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b, + 0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a, + 0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67, + 0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x73,0x74,0x61,0x74, + 0x69,0x63,0x20,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x0a, + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, + 0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20,0x54, + 0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69, + 0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e, + 0x64,0x65,0x78,0x20,0x3a,0x20,0x53,0x56,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x49,0x44,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20, + 0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70, + 0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,0x53,0x56, + 0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76, + 0x6f,0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20,0x5f, + 0x33,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x30,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74, + 0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f, + 0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c, + 0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20, + 0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x20,0x3d, + 0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61, + 0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73, + 0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x31, + 0x36,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61, + 0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31, + 0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67, + 0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29, + 0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x33,0x32,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x5f,0x33,0x33,0x2e,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c, + 0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62, + 0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61, + 0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b, + 0x20,0x34,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x73, + 0x63,0x61,0x6c,0x65,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f, + 0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e, + 0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20, + 0x39,0x36,0x20,0x2b,0x20,0x36,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f, + 0x33,0x33,0x2e,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3d,0x20,0x61,0x73, + 0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28, + 0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78, + 0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e, + 0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x38,0x30,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36,0x38, + 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73, + 0x20,0x2a,0x20,0x5f,0x33,0x33,0x2e,0x73,0x63,0x61,0x6c,0x65,0x2e,0x78,0x79,0x7a, + 0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f, + 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x64,0x6f,0x74,0x28,0x5f,0x33,0x33,0x2e,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2c,0x20,0x5f,0x36,0x38,0x29,0x2c,0x20, + 0x64,0x6f,0x74,0x28,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f, + 0x77,0x31,0x2c,0x20,0x5f,0x36,0x38,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x33, + 0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2c,0x20,0x5f,0x36, + 0x38,0x29,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f,0x39,0x31,0x5f,0x6c, + 0x69,0x67,0x68,0x74,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x29,0x3b, + 0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, + 0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52, + 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74, + 0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65, + 0x78,0x20,0x3d,0x20,0x69,0x6e,0x74,0x28,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e, + 0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49, + 0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x5f,0x70,0x6f, + 0x73,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e, + 0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x72,0x74, + 0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49, + 0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67, + 0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x67,0x6c,0x5f, + 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75, + 0x74,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + void frag_main() + { + } + + void main() + { + frag_main(); + } +*/ +static const uint8_t shadow_geom_fs_source_hlsl5[56] = { + 0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29, + 0x0a,0x7b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69, + 0x6e,0x28,0x29,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + struct instance + { + float4 xform_row0; + float4 xform_row1; + float4 xform_row2; + float4 base_color; + float4 scale; + float4 material; + }; + + struct instances + { + instance items[1]; + }; + + struct ub_draw + { + int4 inst_base; + }; + + struct ub_frame + { + float4x4 light_view_proj; + }; + + struct main0_out + { + float4 gl_Position [[position]]; + }; + + struct main0_in + { + float3 in_pos [[attribute(0)]]; + }; + + vertex main0_out main0(main0_in in [[stage_in]], constant ub_frame& _91 [[buffer(0)]], constant ub_draw& _21 [[buffer(2)]], const device instances& _15 [[buffer(8)]], uint gl_InstanceIndex [[instance_id]]) + { + main0_out out = {}; + int _30 = _21.inst_base.x + int(gl_InstanceIndex); + float4 _68 = float4(in.in_pos * _15.items[_30].scale.xyz, 1.0); + out.gl_Position = _91.light_view_proj * float4(dot(_15.items[_30].xform_row0, _68), dot(_15.items[_30].xform_row1, _68), dot(_15.items[_30].xform_row2, _68), 1.0); + return out; + } + +*/ +static const uint8_t shadow_geom_vs_source_metal_macos[1025] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x73,0x63,0x61,0x6c,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a, + 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x20,0x69,0x74,0x65,0x6d,0x73,0x5b,0x31,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73, + 0x74,0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x34,0x20,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61, + 0x73,0x65,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75, + 0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x76,0x69,0x65, + 0x77,0x5f,0x70,0x72,0x6f,0x6a,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75, + 0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73, + 0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e, + 0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d, + 0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x5b,0x5b,0x61,0x74, + 0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x76,0x65,0x72,0x74,0x65,0x78,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f, + 0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69, + 0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d, + 0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x66, + 0x72,0x61,0x6d,0x65,0x26,0x20,0x5f,0x39,0x31,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66, + 0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e, + 0x74,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x26,0x20,0x5f,0x32,0x31,0x20,0x5b, + 0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x32,0x29,0x5d,0x5d,0x2c,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x20,0x69,0x6e,0x73,0x74,0x61, + 0x6e,0x63,0x65,0x73,0x26,0x20,0x5f,0x31,0x35,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66, + 0x65,0x72,0x28,0x38,0x29,0x5d,0x5d,0x2c,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c, + 0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x5b, + 0x5b,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x5f,0x69,0x64,0x5d,0x5d,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20, + 0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e, + 0x74,0x20,0x5f,0x33,0x30,0x20,0x3d,0x20,0x5f,0x32,0x31,0x2e,0x69,0x6e,0x73,0x74, + 0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x69,0x6e,0x74,0x28,0x67,0x6c, + 0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36,0x38,0x20, + 0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x69,0x6e,0x2e,0x69,0x6e,0x5f,0x70, + 0x6f,0x73,0x20,0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f, + 0x33,0x30,0x5d,0x2e,0x73,0x63,0x61,0x6c,0x65,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31, + 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f, + 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x5f,0x39,0x31,0x2e,0x6c, + 0x69,0x67,0x68,0x74,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x2a, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e, + 0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d, + 0x5f,0x72,0x6f,0x77,0x30,0x2c,0x20,0x5f,0x36,0x38,0x29,0x2c,0x20,0x64,0x6f,0x74, + 0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e, + 0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2c,0x20,0x5f,0x36,0x38,0x29, + 0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b, + 0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2c, + 0x20,0x5f,0x36,0x38,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a, + 0x00, +}; +/* + #include + #include + + using namespace metal; + + fragment void main0() + { + } + +*/ +static const uint8_t shadow_geom_fs_source_metal_macos[100] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74, + 0x20,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x29,0x0a,0x7b,0x0a, + 0x7d,0x0a,0x0a,0x00, +}; +static inline const sg_shader_desc* shadow_geom_caster_shader_desc(sg_backend backend) { + if (backend == SG_BACKEND_GLCORE) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)shadow_geom_vs_source_glsl430; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)shadow_geom_fs_source_glsl430; + desc.fragment_func.entry = "main"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[0].glsl_name = "in_pos"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[0].glsl_uniforms[0].array_count = 4; + desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_frame"; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 16; + desc.uniform_blocks[2].glsl_uniforms[0].type = SG_UNIFORMTYPE_INT4; + desc.uniform_blocks[2].glsl_uniforms[0].array_count = 1; + desc.uniform_blocks[2].glsl_uniforms[0].glsl_name = "ub_draw"; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.glsl_binding_n = 0; + desc.label = "shadow_geom_caster_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_D3D11) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)shadow_geom_vs_source_hlsl5; + desc.vertex_func.d3d11_target = "vs_5_0"; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)shadow_geom_fs_source_hlsl5; + desc.fragment_func.d3d11_target = "ps_5_0"; + desc.fragment_func.entry = "main"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[0].hlsl_sem_name = "TEXCOORD"; + desc.attrs[0].hlsl_sem_index = 0; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].hlsl_register_b_n = 0; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 16; + desc.uniform_blocks[2].hlsl_register_b_n = 2; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.hlsl_register_t_n = 0; + desc.label = "shadow_geom_caster_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_METAL_MACOS) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)shadow_geom_vs_source_metal_macos; + desc.vertex_func.entry = "main0"; + desc.fragment_func.source = (const char*)shadow_geom_fs_source_metal_macos; + desc.fragment_func.entry = "main0"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].msl_buffer_n = 0; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 16; + desc.uniform_blocks[2].msl_buffer_n = 2; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.msl_buffer_n = 8; + desc.label = "shadow_geom_caster_shader"; + } + return &desc; + } + return 0; +} diff --git a/samples/shaders/generated/shadow_caster_sphere.glsl.h b/samples/shaders/generated/shadow_caster_sphere.glsl.h new file mode 100644 index 0000000..9718f31 --- /dev/null +++ b/samples/shaders/generated/shadow_caster_sphere.glsl.h @@ -0,0 +1,546 @@ +#pragma once +/* + #version:1# (machine generated, don't edit!) + + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) + + Cmdline: + sokol-shdc --input E:/box/box3d/samples/shaders/shapes/shadow_caster_sphere.glsl --output E:/box/box3d/samples/shaders/generated/shadow_caster_sphere.glsl.h --slang hlsl5:metal_macos:glsl430 + + Overview: + ========= + Shader program: 'caster': + Get shader desc: shadow_sphere_caster_shader_desc(sg_query_backend()); + Vertex Shader: vs + Fragment Shader: fs + Attributes: + ATTR_shadow_sphere_caster_in_pos => 0 + Bindings: + Uniform block 'ub_draw': + C struct: shadow_sphere_ub_draw_t + Bind slot: UB_shadow_sphere_ub_draw => 2 + Uniform block 'ub_frame': + C struct: shadow_sphere_ub_frame_t + Bind slot: UB_shadow_sphere_ub_frame => 0 + Storage buffer 'instances': + C struct: shadow_sphere_instance_t + Bind slot: VIEW_shadow_sphere_instances => 0 + Readonly: true +*/ +#if !defined(SOKOL_GFX_INCLUDED) +#error "Please include sokol_gfx.h before shadow_caster_sphere.glsl.h" +#endif +#if !defined(SOKOL_SHDC_ALIGN) +#if defined(_MSC_VER) +#define SOKOL_SHDC_ALIGN(a) __declspec(align(a)) +#else +#define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) +#endif +#endif +#define ATTR_shadow_sphere_caster_in_pos (0) +#define UB_shadow_sphere_ub_draw (2) +#define UB_shadow_sphere_ub_frame (0) +#define VIEW_shadow_sphere_instances (0) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct shadow_sphere_ub_draw_t { + int inst_base[4]; +} shadow_sphere_ub_draw_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct shadow_sphere_ub_frame_t { + Mat4 light_view_proj; +} shadow_sphere_ub_frame_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct shadow_sphere_instance_t { + Vec4 xform_row0; + Vec4 xform_row1; + Vec4 xform_row2; + Vec4 base_color; + Vec4 params; + Vec4 material; +} shadow_sphere_instance_t; +#pragma pack(pop) +/* + #version 430 + + struct instance + { + vec4 xform_row0; + vec4 xform_row1; + vec4 xform_row2; + vec4 base_color; + vec4 params; + vec4 material; + }; + + layout(binding = 0, std430) readonly buffer instances + { + instance items[]; + } _15; + + uniform ivec4 ub_draw[1]; + uniform vec4 ub_frame[4]; + layout(location = 0) in vec3 in_pos; + + void main() + { + int _30 = ub_draw[0].x + gl_InstanceID; + gl_Position = mat4(ub_frame[0], ub_frame[1], ub_frame[2], ub_frame[3]) * vec4(vec3(_15.items[_30].xform_row0.w, _15.items[_30].xform_row1.w, _15.items[_30].xform_row2.w) + (in_pos * _15.items[_30].params.x), 1.0); + } + +*/ +static const uint8_t shadow_sphere_vs_source_glsl430[612] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72, + 0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x6d,0x61, + 0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f, + 0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x30,0x2c,0x20, + 0x73,0x74,0x64,0x34,0x33,0x30,0x29,0x20,0x72,0x65,0x61,0x64,0x6f,0x6e,0x6c,0x79, + 0x20,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x20,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5d,0x3b,0x0a,0x7d,0x20,0x5f,0x31,0x35,0x3b, + 0x0a,0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x69,0x76,0x65,0x63,0x34,0x20, + 0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x5b,0x31,0x5d,0x3b,0x0a,0x75,0x6e,0x69,0x66, + 0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d, + 0x65,0x5b,0x34,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63, + 0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65, + 0x63,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64, + 0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e, + 0x74,0x20,0x5f,0x33,0x30,0x20,0x3d,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x5b, + 0x30,0x5d,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x49,0x44,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73, + 0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x75,0x62,0x5f, + 0x66,0x72,0x61,0x6d,0x65,0x5b,0x30,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61, + 0x6d,0x65,0x5b,0x31,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b, + 0x32,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x33,0x5d,0x29, + 0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x33,0x28,0x5f,0x31,0x35, + 0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74, + 0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72, + 0x6f,0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73, + 0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32, + 0x2e,0x77,0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x2a,0x20, + 0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x70, + 0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x00, +}; +/* + #version 430 + + void main() + { + } + +*/ +static const uint8_t shadow_sphere_fs_source_glsl430[32] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x76,0x6f, + 0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x7d,0x0a,0x0a,0x00, + +}; +/* + struct instance + { + float4 xform_row0; + float4 xform_row1; + float4 xform_row2; + float4 base_color; + float4 params; + float4 material; + }; + + ByteAddressBuffer _15 : register(t0); + cbuffer ub_draw : register(b2) + { + int4 _21_inst_base : packoffset(c0); + }; + + cbuffer ub_frame : register(b0) + { + row_major float4x4 _83_light_view_proj : packoffset(c0); + }; + + + static float4 gl_Position; + static int gl_InstanceIndex; + static float3 in_pos; + + struct SPIRV_Cross_Input + { + float3 in_pos : TEXCOORD0; + uint gl_InstanceIndex : SV_InstanceID; + }; + + struct SPIRV_Cross_Output + { + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + instance _33; + _33.xform_row0 = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 0)); + _33.xform_row1 = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 16)); + _33.xform_row2 = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 32)); + _33.base_color = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 48)); + _33.params = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 64)); + _33.material = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 80)); + gl_Position = mul(float4(float3(_33.xform_row0.w, _33.xform_row1.w, _33.xform_row2.w) + (in_pos * _33.params.x), 1.0f), _83_light_view_proj); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_InstanceIndex = int(stage_input.gl_InstanceIndex); + in_pos = stage_input.in_pos; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + return stage_output; + } +*/ +static const uint8_t shadow_sphere_vs_source_hlsl5[1611] = { + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d, + 0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x73,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6d,0x61,0x74,0x65, + 0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x42,0x79,0x74,0x65,0x41,0x64, + 0x64,0x72,0x65,0x73,0x73,0x42,0x75,0x66,0x66,0x65,0x72,0x20,0x5f,0x31,0x35,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x30,0x29,0x3b,0x0a, + 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x32,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x34,0x20,0x5f,0x32,0x31,0x5f,0x69,0x6e, + 0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66, + 0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x63,0x62, + 0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x20,0x3a, + 0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x38,0x33,0x5f,0x6c,0x69,0x67,0x68,0x74, + 0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61,0x63, + 0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x7d,0x3b,0x0a, + 0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x73,0x74,0x61, + 0x74,0x69,0x63,0x20,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61, + 0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a, + 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, + 0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20, + 0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75, + 0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49, + 0x6e,0x64,0x65,0x78,0x20,0x3a,0x20,0x53,0x56,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x49,0x44,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74, + 0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74, + 0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,0x53, + 0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a, + 0x76,0x6f,0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20, + 0x5f,0x33,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61, + 0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31, + 0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67, + 0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29, + 0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x20, + 0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f, + 0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61, + 0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20, + 0x31,0x36,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f, + 0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32, + 0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20, + 0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78, + 0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x33,0x32,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e, + 0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f, + 0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20, + 0x2b,0x20,0x34,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e, + 0x70,0x61,0x72,0x61,0x6d,0x73,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74, + 0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f, + 0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c, + 0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20, + 0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x36,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x5f,0x33,0x33,0x2e,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3d,0x20, + 0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64, + 0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65, + 0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x38,0x30, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74, + 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f,0x33,0x33,0x2e, + 0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x77,0x29,0x20,0x2b,0x20, + 0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x2a,0x20,0x5f,0x33,0x33,0x2e,0x70,0x61, + 0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20, + 0x5f,0x38,0x33,0x5f,0x6c,0x69,0x67,0x68,0x74,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70, + 0x72,0x6f,0x6a,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, + 0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e, + 0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70, + 0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x3d,0x20,0x69,0x6e,0x74,0x28,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69, + 0x6e,0x70,0x75,0x74,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75, + 0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75, + 0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74, + 0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20, + 0x3d,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f, + 0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + void frag_main() + { + } + + void main() + { + frag_main(); + } +*/ +static const uint8_t shadow_sphere_fs_source_hlsl5[56] = { + 0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29, + 0x0a,0x7b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69, + 0x6e,0x28,0x29,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + struct instance + { + float4 xform_row0; + float4 xform_row1; + float4 xform_row2; + float4 base_color; + float4 params; + float4 material; + }; + + struct instances + { + instance items[1]; + }; + + struct ub_draw + { + int4 inst_base; + }; + + struct ub_frame + { + float4x4 light_view_proj; + }; + + struct main0_out + { + float4 gl_Position [[position]]; + }; + + struct main0_in + { + float3 in_pos [[attribute(0)]]; + }; + + vertex main0_out main0(main0_in in [[stage_in]], constant ub_frame& _83 [[buffer(0)]], constant ub_draw& _21 [[buffer(2)]], const device instances& _15 [[buffer(8)]], uint gl_InstanceIndex [[instance_id]]) + { + main0_out out = {}; + int _30 = _21.inst_base.x + int(gl_InstanceIndex); + out.gl_Position = _83.light_view_proj * float4(float3(_15.items[_30].xform_row0.w, _15.items[_30].xform_row1.w, _15.items[_30].xform_row2.w) + (in.in_pos * _15.items[_30].params.x), 1.0); + return out; + } + +*/ +static const uint8_t shadow_sphere_vs_source_metal_macos[982] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x20,0x69,0x74,0x65,0x6d,0x73,0x5b,0x31,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a, + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x34,0x20,0x69,0x6e,0x73,0x74,0x5f,0x62, + 0x61,0x73,0x65,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20, + 0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72, + 0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f, + 0x6e,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20, + 0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x5b,0x5b,0x61, + 0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d, + 0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,0x65,0x78,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f, + 0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f, + 0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e, + 0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f, + 0x66,0x72,0x61,0x6d,0x65,0x26,0x20,0x5f,0x38,0x33,0x20,0x5b,0x5b,0x62,0x75,0x66, + 0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61, + 0x6e,0x74,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x26,0x20,0x5f,0x32,0x31,0x20, + 0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x32,0x29,0x5d,0x5d,0x2c,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x20,0x69,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x73,0x26,0x20,0x5f,0x31,0x35,0x20,0x5b,0x5b,0x62,0x75,0x66, + 0x66,0x65,0x72,0x28,0x38,0x29,0x5d,0x5d,0x2c,0x20,0x75,0x69,0x6e,0x74,0x20,0x67, + 0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20, + 0x5b,0x5b,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x5f,0x69,0x64,0x5d,0x5d,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74, + 0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x6e,0x74,0x20,0x5f,0x33,0x30,0x20,0x3d,0x20,0x5f,0x32,0x31,0x2e,0x69,0x6e,0x73, + 0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x69,0x6e,0x74,0x28,0x67, + 0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73, + 0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x5f,0x38,0x33,0x2e,0x6c,0x69,0x67,0x68, + 0x74,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x31,0x35,0x2e, + 0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d, + 0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65, + 0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f, + 0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b, + 0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e, + 0x77,0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20, + 0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d, + 0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + fragment void main0() + { + } + +*/ +static const uint8_t shadow_sphere_fs_source_metal_macos[100] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74, + 0x20,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x29,0x0a,0x7b,0x0a, + 0x7d,0x0a,0x0a,0x00, +}; +static inline const sg_shader_desc* shadow_sphere_caster_shader_desc(sg_backend backend) { + if (backend == SG_BACKEND_GLCORE) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)shadow_sphere_vs_source_glsl430; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)shadow_sphere_fs_source_glsl430; + desc.fragment_func.entry = "main"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[0].glsl_name = "in_pos"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[0].glsl_uniforms[0].array_count = 4; + desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_frame"; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 16; + desc.uniform_blocks[2].glsl_uniforms[0].type = SG_UNIFORMTYPE_INT4; + desc.uniform_blocks[2].glsl_uniforms[0].array_count = 1; + desc.uniform_blocks[2].glsl_uniforms[0].glsl_name = "ub_draw"; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.glsl_binding_n = 0; + desc.label = "shadow_sphere_caster_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_D3D11) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)shadow_sphere_vs_source_hlsl5; + desc.vertex_func.d3d11_target = "vs_5_0"; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)shadow_sphere_fs_source_hlsl5; + desc.fragment_func.d3d11_target = "ps_5_0"; + desc.fragment_func.entry = "main"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[0].hlsl_sem_name = "TEXCOORD"; + desc.attrs[0].hlsl_sem_index = 0; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].hlsl_register_b_n = 0; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 16; + desc.uniform_blocks[2].hlsl_register_b_n = 2; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.hlsl_register_t_n = 0; + desc.label = "shadow_sphere_caster_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_METAL_MACOS) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)shadow_sphere_vs_source_metal_macos; + desc.vertex_func.entry = "main0"; + desc.fragment_func.source = (const char*)shadow_sphere_fs_source_metal_macos; + desc.fragment_func.entry = "main0"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].msl_buffer_n = 0; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 16; + desc.uniform_blocks[2].msl_buffer_n = 2; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.msl_buffer_n = 8; + desc.label = "shadow_sphere_caster_shader"; + } + return &desc; + } + return 0; +} diff --git a/samples/shaders/generated/sky.glsl.h b/samples/shaders/generated/sky.glsl.h new file mode 100644 index 0000000..0996a4a --- /dev/null +++ b/samples/shaders/generated/sky.glsl.h @@ -0,0 +1,2111 @@ +#pragma once +/* + #version:1# (machine generated, don't edit!) + + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) + + Cmdline: + sokol-shdc --input E:/box/box3d/samples/shaders/ibl/sky.glsl --output E:/box/box3d/samples/shaders/generated/sky.glsl.h --slang hlsl5:metal_macos:glsl430 + + Overview: + ========= + Shader program: 'sky': + Get shader desc: sky_shader_desc(sg_query_backend()); + Vertex Shader: vs + Fragment Shader: fs + Attributes: + Bindings: + Uniform block 'sky_ub_frame': + C struct: sky_ub_frame_t + Bind slot: UB_sky_ub_frame => 0 + Uniform block 'sky_ub_pass': + C struct: sky_ub_pass_t + Bind slot: UB_sky_ub_pass => 1 +*/ +#if !defined(SOKOL_GFX_INCLUDED) +#error "Please include sokol_gfx.h before sky.glsl.h" +#endif +#if !defined(SOKOL_SHDC_ALIGN) +#if defined(_MSC_VER) +#define SOKOL_SHDC_ALIGN(a) __declspec(align(a)) +#else +#define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) +#endif +#endif +#define UB_sky_ub_frame (0) +#define UB_sky_ub_pass (1) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct sky_ub_frame_t { + Mat4 inv_view_proj; +} sky_ub_frame_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct sky_ub_pass_t { + Vec4 sun_dir_world; + Vec4 sky_params; + Vec4 camera_pos; +} sky_ub_pass_t; +#pragma pack(pop) +/* + #version 430 + + uniform vec4 sky_ub_frame[4]; + layout(location = 0) out vec4 v_world_homog; + + void main() + { + vec4 _35 = vec4((vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2)) * 2.0) - vec2(1.0), 0.0, 1.0); + gl_Position = _35; + v_world_homog = mat4(sky_ub_frame[0], sky_ub_frame[1], sky_ub_frame[2], sky_ub_frame[3]) * _35; + } + +*/ +static const uint8_t vs_source_glsl430[343] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x75,0x6e, + 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x6b,0x79,0x5f,0x75, + 0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x34,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f, + 0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29, + 0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x68,0x6f,0x6d,0x6f,0x67,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d, + 0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34, + 0x20,0x5f,0x33,0x35,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x28,0x76,0x65,0x63, + 0x32,0x28,0x66,0x6c,0x6f,0x61,0x74,0x28,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74, + 0x65,0x78,0x49,0x44,0x20,0x3c,0x3c,0x20,0x31,0x29,0x20,0x26,0x20,0x32,0x29,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78, + 0x49,0x44,0x20,0x26,0x20,0x32,0x29,0x29,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x20, + 0x2d,0x20,0x76,0x65,0x63,0x32,0x28,0x31,0x2e,0x30,0x29,0x2c,0x20,0x30,0x2e,0x30, + 0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50, + 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x5f,0x33,0x35,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x68,0x6f,0x6d,0x6f,0x67, + 0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x73,0x6b,0x79,0x5f,0x75,0x62,0x5f,0x66, + 0x72,0x61,0x6d,0x65,0x5b,0x30,0x5d,0x2c,0x20,0x73,0x6b,0x79,0x5f,0x75,0x62,0x5f, + 0x66,0x72,0x61,0x6d,0x65,0x5b,0x31,0x5d,0x2c,0x20,0x73,0x6b,0x79,0x5f,0x75,0x62, + 0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x32,0x5d,0x2c,0x20,0x73,0x6b,0x79,0x5f,0x75, + 0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x5f,0x33, + 0x35,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + #version 430 + + uniform vec4 sky_ub_pass[3]; + layout(location = 0) in vec4 v_world_homog; + layout(location = 0) out vec4 out_color; + + float preethamPerez(float cos_theta, float cos_gamma, float gamma, float A, float B, float C, float D, float E) + { + return (1.0 + (A * exp(B / max(cos_theta, 0.00999999977648258209228515625)))) * ((1.0 + (C * exp(D * gamma))) + ((E * cos_gamma) * cos_gamma)); + } + + vec3 preethamXyY_to_XYZ(float x, float y, float Y) + { + float _77 = max(y, 9.9999997473787516355514526367188e-06); + return vec3((Y * x) / _77, Y, (Y * ((1.0 - x) - y)) / _77); + } + + vec3 preethamXYZ_to_linear_srgb(vec3 c) + { + return vec3(dot(c, vec3(3.240454196929931640625, -1.537138462066650390625, -0.498531401157379150390625)), dot(c, vec3(-0.969265997409820556640625, 1.87601077556610107421875, 0.04155600070953369140625)), dot(c, vec3(0.0556433983147144317626953125, -0.2040258944034576416015625, 1.05722522735595703125))); + } + + vec3 preethamSky(vec3 view_dir, vec3 sun_dir, float turbidity) + { + float _122 = clamp(sun_dir.y, 0.0, 1.0); + vec3 _135 = normalize(vec3(view_dir.x, max(view_dir.y, 0.0) + 0.00999999977648258209228515625, view_dir.z)); + float _139 = max(_135.y, 0.0); + float _145 = clamp(dot(sun_dir, _135), -1.0, 1.0); + float _148 = acos(_145); + float _151 = acos(_122); + float _154 = max(turbidity, 1.0); + float _158 = _154 * _154; + float _164 = (0.1787000000476837158203125 * _154) - 1.4630000591278076171875; + float _170 = ((-0.3553999960422515869140625) * _154) + 0.4275000095367431640625; + float _176 = ((-0.0227000005543231964111328125) * _154) + 5.325099945068359375; + float _182 = (0.12060000002384185791015625 * _154) - 2.5771000385284423828125; + float _188 = ((-0.0670000016689300537109375) * _154) + 0.370299994945526123046875; + float _194 = ((-0.01930000074207782745361328125) * _154) - 0.2592000067234039306640625; + float _200 = ((-0.066500000655651092529296875) * _154) + 0.0007999999797903001308441162109375; + float _206 = ((-0.00039999998989515006542205810546875) * _154) + 0.2125000059604644775390625; + float _212 = ((-0.0640999972820281982421875) * _154) - 0.898899972438812255859375; + float _218 = ((-0.0032999999821186065673828125) * _154) + 0.0452000014483928680419921875; + float _224 = ((-0.0166999995708465576171875) * _154) - 0.26080000400543212890625; + float _230 = ((-0.0949999988079071044921875) * _154) + 0.009200000204145908355712890625; + float _236 = ((-0.0078999996185302734375) * _154) + 0.21019999682903289794921875; + float _242 = ((-0.04410000145435333251953125) * _154) - 1.65369999408721923828125; + float _248 = ((-0.01090000011026859283447265625) * _154) + 0.05290000140666961669921875; + float _254 = _151 * _151; + float _258 = _254 * _151; + float param = _139; + float param_1 = _145; + float param_2 = _148; + float param_3 = _164; + float param_4 = _170; + float param_5 = _176; + float param_6 = _182; + float param_7 = _188; + float param_8 = _139; + float param_9 = _145; + float param_10 = _148; + float param_11 = _194; + float param_12 = _200; + float param_13 = _206; + float param_14 = _212; + float param_15 = _218; + float param_16 = _139; + float param_17 = _145; + float param_18 = _148; + float param_19 = _224; + float param_20 = _230; + float param_21 = _236; + float param_22 = _242; + float param_23 = _248; + float param_24 = 1.0; + float param_25 = _122; + float param_26 = _151; + float param_27 = _164; + float param_28 = _170; + float param_29 = _176; + float param_30 = _182; + float param_31 = _188; + float param_32 = 1.0; + float param_33 = _122; + float param_34 = _151; + float param_35 = _194; + float param_36 = _200; + float param_37 = _206; + float param_38 = _212; + float param_39 = _218; + float param_40 = 1.0; + float param_41 = _122; + float param_42 = _151; + float param_43 = _224; + float param_44 = _230; + float param_45 = _236; + float param_46 = _242; + float param_47 = _248; + float param_48 = (((((((0.001659999950788915157318115234375 * _258) - (0.00374999991618096828460693359375 * _254)) + (0.0020900000818073749542236328125 * _151)) * _158) + ((((((-0.02903000079095363616943359375) * _258) + (0.063770003616809844970703125 * _254)) - (0.0320199988782405853271484375 * _151)) + 0.003940000198781490325927734375) * _154)) + ((((0.116930000483989715576171875 * _258) - (0.21196000277996063232421875 * _254)) + (0.060520000755786895751953125 * _151)) + 0.25885999202728271484375)) * preethamPerez(param_8, param_9, param_10, param_11, param_12, param_13, param_14, param_15)) / max(preethamPerez(param_32, param_33, param_34, param_35, param_36, param_37, param_38, param_39), 9.9999997473787516355514526367188e-06); + float param_49 = (((((((0.00274999998509883880615234375 * _258) - (0.006099999882280826568603515625 * _254)) + (0.0031699999235570430755615234375 * _151)) * _158) + ((((((-0.042139999568462371826171875) * _258) + (0.08969999849796295166015625 * _254)) - (0.04152999818325042724609375 * _151)) + 0.0051600001752376556396484375) * _154)) + ((((0.1534599959850311279296875 * _258) - (0.26756000518798828125 * _254)) + (0.06669999659061431884765625 * _151)) + 0.2668800055980682373046875)) * preethamPerez(param_16, param_17, param_18, param_19, param_20, param_21, param_22, param_23)) / max(preethamPerez(param_40, param_41, param_42, param_43, param_44, param_45, param_46, param_47), 9.9999997473787516355514526367188e-06); + float param_50 = max(((((((4.045300006866455078125 * _154) - 4.971000194549560546875) * tan((0.4444444477558135986328125 - (_154 * 0.008333333767950534820556640625)) * (3.1415927410125732421875 - (2.0 * _151)))) - (0.21549999713897705078125 * _154)) + 2.41919994354248046875) * preethamPerez(param, param_1, param_2, param_3, param_4, param_5, param_6, param_7)) / max(preethamPerez(param_24, param_25, param_26, param_27, param_28, param_29, param_30, param_31), 9.9999997473787516355514526367188e-06), 0.0); + vec3 param_51 = preethamXyY_to_XYZ(param_48, param_49, param_50); + return max(preethamXYZ_to_linear_srgb(param_51), vec3(0.0)); + } + + vec3 preethamSkyScaled(vec3 view_dir, vec3 sun_dir, float turbidity, float fade) + { + vec3 param = view_dir; + vec3 param_1 = sun_dir; + float param_2 = turbidity; + return (preethamSky(param, param_1, param_2) * 0.0599999986588954925537109375) * fade; + } + + void main() + { + vec3 param = normalize((v_world_homog.xyz / vec3(v_world_homog.w)) - sky_ub_pass[2].xyz); + vec3 param_1 = normalize(sky_ub_pass[0].xyz); + float param_2 = sky_ub_pass[1].x; + float param_3 = sky_ub_pass[0].w; + out_color = vec4(preethamSkyScaled(param, param_1, param_2, param_3), 1.0); + } + +*/ +static const uint8_t fs_source_glsl430[6753] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x75,0x6e, + 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x6b,0x79,0x5f,0x75, + 0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x33,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75, + 0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20, + 0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x68,0x6f,0x6d,0x6f,0x67,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f, + 0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20, + 0x76,0x65,0x63,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a, + 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x50, + 0x65,0x72,0x65,0x7a,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x63,0x6f,0x73,0x5f,0x74, + 0x68,0x65,0x74,0x61,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x63,0x6f,0x73,0x5f, + 0x67,0x61,0x6d,0x6d,0x61,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x61,0x6d, + 0x6d,0x61,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x41,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x42,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x43,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x44,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x45,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x31, + 0x2e,0x30,0x20,0x2b,0x20,0x28,0x41,0x20,0x2a,0x20,0x65,0x78,0x70,0x28,0x42,0x20, + 0x2f,0x20,0x6d,0x61,0x78,0x28,0x63,0x6f,0x73,0x5f,0x74,0x68,0x65,0x74,0x61,0x2c, + 0x20,0x30,0x2e,0x30,0x30,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x37,0x36,0x34, + 0x38,0x32,0x35,0x38,0x32,0x30,0x39,0x32,0x32,0x38,0x35,0x31,0x35,0x36,0x32,0x35, + 0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x28,0x28,0x31,0x2e,0x30,0x20,0x2b,0x20,0x28, + 0x43,0x20,0x2a,0x20,0x65,0x78,0x70,0x28,0x44,0x20,0x2a,0x20,0x67,0x61,0x6d,0x6d, + 0x61,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x28,0x45,0x20,0x2a,0x20,0x63,0x6f,0x73, + 0x5f,0x67,0x61,0x6d,0x6d,0x61,0x29,0x20,0x2a,0x20,0x63,0x6f,0x73,0x5f,0x67,0x61, + 0x6d,0x6d,0x61,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x70, + 0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x58,0x79,0x59,0x5f,0x74,0x6f,0x5f,0x58,0x59, + 0x5a,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x78,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x79,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x59,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x37,0x20,0x3d,0x20,0x6d, + 0x61,0x78,0x28,0x79,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34, + 0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32, + 0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x76,0x65,0x63,0x33,0x28,0x28,0x59, + 0x20,0x2a,0x20,0x78,0x29,0x20,0x2f,0x20,0x5f,0x37,0x37,0x2c,0x20,0x59,0x2c,0x20, + 0x28,0x59,0x20,0x2a,0x20,0x28,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x78,0x29,0x20, + 0x2d,0x20,0x79,0x29,0x29,0x20,0x2f,0x20,0x5f,0x37,0x37,0x29,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x76,0x65,0x63,0x33,0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x58,0x59, + 0x5a,0x5f,0x74,0x6f,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x73,0x72,0x67,0x62, + 0x28,0x76,0x65,0x63,0x33,0x20,0x63,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x76,0x65,0x63,0x33,0x28,0x64,0x6f,0x74,0x28,0x63, + 0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x33,0x2e,0x32,0x34,0x30,0x34,0x35,0x34,0x31, + 0x39,0x36,0x39,0x32,0x39,0x39,0x33,0x31,0x36,0x34,0x30,0x36,0x32,0x35,0x2c,0x20, + 0x2d,0x31,0x2e,0x35,0x33,0x37,0x31,0x33,0x38,0x34,0x36,0x32,0x30,0x36,0x36,0x36, + 0x35,0x30,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x2d,0x30,0x2e,0x34,0x39,0x38, + 0x35,0x33,0x31,0x34,0x30,0x31,0x31,0x35,0x37,0x33,0x37,0x39,0x31,0x35,0x30,0x33, + 0x39,0x30,0x36,0x32,0x35,0x29,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x63,0x2c,0x20, + 0x76,0x65,0x63,0x33,0x28,0x2d,0x30,0x2e,0x39,0x36,0x39,0x32,0x36,0x35,0x39,0x39, + 0x37,0x34,0x30,0x39,0x38,0x32,0x30,0x35,0x35,0x36,0x36,0x34,0x30,0x36,0x32,0x35, + 0x2c,0x20,0x31,0x2e,0x38,0x37,0x36,0x30,0x31,0x30,0x37,0x37,0x35,0x35,0x36,0x36, + 0x31,0x30,0x31,0x30,0x37,0x34,0x32,0x31,0x38,0x37,0x35,0x2c,0x20,0x30,0x2e,0x30, + 0x34,0x31,0x35,0x35,0x36,0x30,0x30,0x30,0x37,0x30,0x39,0x35,0x33,0x33,0x36,0x39, + 0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x63,0x2c, + 0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x35,0x35,0x36,0x34,0x33,0x33,0x39, + 0x38,0x33,0x31,0x34,0x37,0x31,0x34,0x34,0x33,0x31,0x37,0x36,0x32,0x36,0x39,0x35, + 0x33,0x31,0x32,0x35,0x2c,0x20,0x2d,0x30,0x2e,0x32,0x30,0x34,0x30,0x32,0x35,0x38, + 0x39,0x34,0x34,0x30,0x33,0x34,0x35,0x37,0x36,0x34,0x31,0x36,0x30,0x31,0x35,0x36, + 0x32,0x35,0x2c,0x20,0x31,0x2e,0x30,0x35,0x37,0x32,0x32,0x35,0x32,0x32,0x37,0x33, + 0x35,0x35,0x39,0x35,0x37,0x30,0x33,0x31,0x32,0x35,0x29,0x29,0x29,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x53, + 0x6b,0x79,0x28,0x76,0x65,0x63,0x33,0x20,0x76,0x69,0x65,0x77,0x5f,0x64,0x69,0x72, + 0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x74,0x75,0x72,0x62,0x69,0x64,0x69,0x74,0x79,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32, + 0x32,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x73,0x75,0x6e,0x5f,0x64,0x69, + 0x72,0x2e,0x79,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x33,0x35,0x20,0x3d,0x20, + 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x76,0x65,0x63,0x33,0x28,0x76, + 0x69,0x65,0x77,0x5f,0x64,0x69,0x72,0x2e,0x78,0x2c,0x20,0x6d,0x61,0x78,0x28,0x76, + 0x69,0x65,0x77,0x5f,0x64,0x69,0x72,0x2e,0x79,0x2c,0x20,0x30,0x2e,0x30,0x29,0x20, + 0x2b,0x20,0x30,0x2e,0x30,0x30,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x37,0x36, + 0x34,0x38,0x32,0x35,0x38,0x32,0x30,0x39,0x32,0x32,0x38,0x35,0x31,0x35,0x36,0x32, + 0x35,0x2c,0x20,0x76,0x69,0x65,0x77,0x5f,0x64,0x69,0x72,0x2e,0x7a,0x29,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x39,0x20, + 0x3d,0x20,0x6d,0x61,0x78,0x28,0x5f,0x31,0x33,0x35,0x2e,0x79,0x2c,0x20,0x30,0x2e, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x34,0x35,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x64,0x6f,0x74,0x28,0x73, + 0x75,0x6e,0x5f,0x64,0x69,0x72,0x2c,0x20,0x5f,0x31,0x33,0x35,0x29,0x2c,0x20,0x2d, + 0x31,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x38,0x20,0x3d,0x20,0x61,0x63,0x6f,0x73, + 0x28,0x5f,0x31,0x34,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x31,0x35,0x31,0x20,0x3d,0x20,0x61,0x63,0x6f,0x73,0x28,0x5f,0x31, + 0x32,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x35,0x34,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x74,0x75,0x72,0x62,0x69,0x64, + 0x69,0x74,0x79,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x38,0x20,0x3d,0x20,0x5f,0x31,0x35,0x34, + 0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x36,0x34,0x20,0x3d,0x20,0x28,0x30,0x2e,0x31,0x37,0x38, + 0x37,0x30,0x30,0x30,0x30,0x30,0x30,0x34,0x37,0x36,0x38,0x33,0x37,0x31,0x35,0x38, + 0x32,0x30,0x33,0x31,0x32,0x35,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2d, + 0x20,0x31,0x2e,0x34,0x36,0x33,0x30,0x30,0x30,0x30,0x35,0x39,0x31,0x32,0x37,0x38, + 0x30,0x37,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x37,0x30,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30, + 0x2e,0x33,0x35,0x35,0x33,0x39,0x39,0x39,0x39,0x36,0x30,0x34,0x32,0x32,0x35,0x31, + 0x35,0x38,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31, + 0x35,0x34,0x29,0x20,0x2b,0x20,0x30,0x2e,0x34,0x32,0x37,0x35,0x30,0x30,0x30,0x30, + 0x39,0x35,0x33,0x36,0x37,0x34,0x33,0x31,0x36,0x34,0x30,0x36,0x32,0x35,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x37,0x36,0x20,0x3d, + 0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x32,0x32,0x37,0x30,0x30,0x30,0x30,0x30,0x35, + 0x35,0x34,0x33,0x32,0x33,0x31,0x39,0x36,0x34,0x31,0x31,0x31,0x33,0x32,0x38,0x31, + 0x32,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2b,0x20,0x35,0x2e, + 0x33,0x32,0x35,0x30,0x39,0x39,0x39,0x34,0x35,0x30,0x36,0x38,0x33,0x35,0x39,0x33, + 0x37,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x38,0x32,0x20,0x3d,0x20,0x28,0x30,0x2e,0x31,0x32,0x30,0x36,0x30,0x30,0x30,0x30, + 0x30,0x30,0x32,0x33,0x38,0x34,0x31,0x38,0x35,0x37,0x39,0x31,0x30,0x31,0x35,0x36, + 0x32,0x35,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2d,0x20,0x32,0x2e,0x35, + 0x37,0x37,0x31,0x30,0x30,0x30,0x33,0x38,0x35,0x32,0x38,0x34,0x34,0x32,0x33,0x38, + 0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x38,0x38,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x36,0x37, + 0x30,0x30,0x30,0x30,0x30,0x31,0x36,0x36,0x38,0x39,0x33,0x30,0x30,0x35,0x33,0x37, + 0x31,0x30,0x39,0x33,0x37,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20, + 0x2b,0x20,0x30,0x2e,0x33,0x37,0x30,0x32,0x39,0x39,0x39,0x39,0x34,0x39,0x34,0x35, + 0x35,0x32,0x36,0x31,0x32,0x33,0x30,0x34,0x36,0x38,0x37,0x35,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x39,0x34,0x20,0x3d,0x20,0x28, + 0x28,0x2d,0x30,0x2e,0x30,0x31,0x39,0x33,0x30,0x30,0x30,0x30,0x30,0x37,0x34,0x32, + 0x30,0x37,0x37,0x38,0x32,0x37,0x34,0x35,0x33,0x36,0x31,0x33,0x32,0x38,0x31,0x32, + 0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2d,0x20,0x30,0x2e,0x32, + 0x35,0x39,0x32,0x30,0x30,0x30,0x30,0x36,0x37,0x32,0x33,0x34,0x30,0x33,0x39,0x33, + 0x30,0x36,0x36,0x34,0x30,0x36,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x32,0x30,0x30,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e, + 0x30,0x36,0x36,0x35,0x30,0x30,0x30,0x30,0x30,0x36,0x35,0x35,0x36,0x35,0x31,0x30, + 0x39,0x32,0x35,0x32,0x39,0x32,0x39,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x5f, + 0x31,0x35,0x34,0x29,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x37,0x39,0x39,0x39, + 0x39,0x39,0x39,0x37,0x39,0x37,0x39,0x30,0x33,0x30,0x30,0x31,0x33,0x30,0x38,0x34, + 0x34,0x31,0x31,0x36,0x32,0x31,0x30,0x39,0x33,0x37,0x35,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x30,0x36,0x20,0x3d,0x20,0x28,0x28, + 0x2d,0x30,0x2e,0x30,0x30,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x38,0x39,0x38, + 0x39,0x35,0x31,0x35,0x30,0x30,0x36,0x35,0x34,0x32,0x32,0x30,0x35,0x38,0x31,0x30, + 0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20, + 0x2b,0x20,0x30,0x2e,0x32,0x31,0x32,0x35,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30, + 0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x32,0x20,0x3d,0x20, + 0x28,0x28,0x2d,0x30,0x2e,0x30,0x36,0x34,0x30,0x39,0x39,0x39,0x39,0x37,0x32,0x38, + 0x32,0x30,0x32,0x38,0x31,0x39,0x38,0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x29,0x20, + 0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2d,0x20,0x30,0x2e,0x38,0x39,0x38,0x38, + 0x39,0x39,0x39,0x37,0x32,0x34,0x33,0x38,0x38,0x31,0x32,0x32,0x35,0x35,0x38,0x35, + 0x39,0x33,0x37,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x32,0x31,0x38,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x30,0x33,0x32, + 0x39,0x39,0x39,0x39,0x39,0x39,0x38,0x32,0x31,0x31,0x38,0x36,0x30,0x36,0x35,0x36, + 0x37,0x33,0x38,0x32,0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34, + 0x29,0x20,0x2b,0x20,0x30,0x2e,0x30,0x34,0x35,0x32,0x30,0x30,0x30,0x30,0x31,0x34, + 0x34,0x38,0x33,0x39,0x32,0x38,0x36,0x38,0x30,0x34,0x31,0x39,0x39,0x32,0x31,0x38, + 0x37,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32, + 0x32,0x34,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x31,0x36,0x36,0x39,0x39, + 0x39,0x39,0x39,0x35,0x37,0x30,0x38,0x34,0x36,0x35,0x35,0x37,0x36,0x31,0x37,0x31, + 0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2d,0x20,0x30, + 0x2e,0x32,0x36,0x30,0x38,0x30,0x30,0x30,0x30,0x34,0x30,0x30,0x35,0x34,0x33,0x32, + 0x31,0x32,0x38,0x39,0x30,0x36,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x32,0x33,0x30,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e, + 0x30,0x39,0x34,0x39,0x39,0x39,0x39,0x39,0x38,0x38,0x30,0x37,0x39,0x30,0x37,0x31, + 0x30,0x34,0x34,0x39,0x32,0x31,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35, + 0x34,0x29,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x39,0x32,0x30,0x30,0x30,0x30,0x30, + 0x32,0x30,0x34,0x31,0x34,0x35,0x39,0x30,0x38,0x33,0x35,0x35,0x37,0x31,0x32,0x38, + 0x39,0x30,0x36,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x32,0x33,0x36,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x30,0x37, + 0x38,0x39,0x39,0x39,0x39,0x39,0x36,0x31,0x38,0x35,0x33,0x30,0x32,0x37,0x33,0x34, + 0x33,0x37,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2b,0x20,0x30, + 0x2e,0x32,0x31,0x30,0x31,0x39,0x39,0x39,0x39,0x36,0x38,0x32,0x39,0x30,0x33,0x32, + 0x38,0x39,0x37,0x39,0x34,0x39,0x32,0x31,0x38,0x37,0x35,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x34,0x32,0x20,0x3d,0x20,0x28,0x28, + 0x2d,0x30,0x2e,0x30,0x34,0x34,0x31,0x30,0x30,0x30,0x30,0x31,0x34,0x35,0x34,0x33, + 0x35,0x33,0x33,0x33,0x32,0x35,0x31,0x39,0x35,0x33,0x31,0x32,0x35,0x29,0x20,0x2a, + 0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2d,0x20,0x31,0x2e,0x36,0x35,0x33,0x36,0x39, + 0x39,0x39,0x39,0x34,0x30,0x38,0x37,0x32,0x31,0x39,0x32,0x33,0x38,0x32,0x38,0x31, + 0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32, + 0x34,0x38,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x31,0x30,0x39,0x30,0x30, + 0x30,0x30,0x30,0x31,0x31,0x30,0x32,0x36,0x38,0x35,0x39,0x32,0x38,0x33,0x34,0x34, + 0x37,0x32,0x36,0x35,0x36,0x32,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29, + 0x20,0x2b,0x20,0x30,0x2e,0x30,0x35,0x32,0x39,0x30,0x30,0x30,0x30,0x31,0x34,0x30, + 0x36,0x36,0x36,0x39,0x36,0x31,0x36,0x36,0x39,0x39,0x32,0x31,0x38,0x37,0x35,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x35,0x34,0x20, + 0x3d,0x20,0x5f,0x31,0x35,0x31,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x35,0x38,0x20,0x3d,0x20, + 0x5f,0x32,0x35,0x34,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f, + 0x31,0x33,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x31,0x34,0x35,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x20,0x3d,0x20,0x5f,0x31,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31,0x36, + 0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x31,0x37,0x30,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d, + 0x20,0x5f,0x31,0x37,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f,0x31,0x38,0x32,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x37,0x20,0x3d,0x20,0x5f,0x31,0x38,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x5f, + 0x31,0x33,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x5f,0x31,0x34,0x35,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x30,0x20,0x3d,0x20,0x5f,0x31,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x5f, + 0x31,0x39,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x5f,0x32,0x30,0x30,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x33,0x20,0x3d,0x20,0x5f,0x32,0x30,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20, + 0x5f,0x32,0x31,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x5f,0x32,0x31,0x38,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x36,0x20,0x3d,0x20,0x5f,0x31,0x33,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x20,0x3d, + 0x20,0x5f,0x31,0x34,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x5f,0x31,0x34,0x38, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20,0x5f,0x32,0x32,0x34,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x20, + 0x3d,0x20,0x5f,0x32,0x33,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x20,0x3d,0x20,0x5f,0x32,0x33, + 0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x32,0x20,0x3d,0x20,0x5f,0x32,0x34,0x32,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33, + 0x20,0x3d,0x20,0x5f,0x32,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x20,0x3d,0x20,0x31,0x2e, + 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x35,0x20,0x3d,0x20,0x5f,0x31,0x32,0x32,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x36, + 0x20,0x3d,0x20,0x5f,0x31,0x35,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37,0x20,0x3d,0x20,0x5f,0x31, + 0x36,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x38,0x20,0x3d,0x20,0x5f,0x31,0x37,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x39,0x20,0x3d,0x20,0x5f,0x31,0x37,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x30,0x20,0x3d,0x20,0x5f, + 0x31,0x38,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x33,0x31,0x20,0x3d,0x20,0x5f,0x31,0x38,0x38,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x32,0x20,0x3d,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x33,0x20,0x3d,0x20,0x5f, + 0x31,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x20,0x3d,0x20,0x5f,0x31,0x35,0x31,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x35,0x20,0x3d,0x20,0x5f,0x31,0x39,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x36,0x20,0x3d,0x20, + 0x5f,0x32,0x30,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x37,0x20,0x3d,0x20,0x5f,0x32,0x30,0x36,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x33,0x38,0x20,0x3d,0x20,0x5f,0x32,0x31,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x39,0x20,0x3d, + 0x20,0x5f,0x32,0x31,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x30,0x20,0x3d,0x20,0x31,0x2e,0x30,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x34,0x31,0x20,0x3d,0x20,0x5f,0x31,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x32,0x20,0x3d, + 0x20,0x5f,0x31,0x35,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x33,0x20,0x3d,0x20,0x5f,0x32,0x32,0x34, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x34,0x34,0x20,0x3d,0x20,0x5f,0x32,0x33,0x30,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x35,0x20, + 0x3d,0x20,0x5f,0x32,0x33,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x36,0x20,0x3d,0x20,0x5f,0x32,0x34, + 0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x34,0x37,0x20,0x3d,0x20,0x5f,0x32,0x34,0x38,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x38, + 0x20,0x3d,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x30,0x2e,0x30,0x30,0x31,0x36, + 0x35,0x39,0x39,0x39,0x39,0x39,0x35,0x30,0x37,0x38,0x38,0x39,0x31,0x35,0x31,0x35, + 0x37,0x33,0x31,0x38,0x31,0x31,0x35,0x32,0x33,0x34,0x33,0x37,0x35,0x20,0x2a,0x20, + 0x5f,0x32,0x35,0x38,0x29,0x20,0x2d,0x20,0x28,0x30,0x2e,0x30,0x30,0x33,0x37,0x34, + 0x39,0x39,0x39,0x39,0x39,0x31,0x36,0x31,0x38,0x30,0x39,0x36,0x38,0x32,0x38,0x34, + 0x36,0x30,0x36,0x39,0x33,0x33,0x35,0x39,0x33,0x37,0x35,0x20,0x2a,0x20,0x5f,0x32, + 0x35,0x34,0x29,0x29,0x20,0x2b,0x20,0x28,0x30,0x2e,0x30,0x30,0x32,0x30,0x39,0x30, + 0x30,0x30,0x30,0x30,0x38,0x31,0x38,0x30,0x37,0x33,0x37,0x34,0x39,0x35,0x34,0x32, + 0x32,0x33,0x36,0x33,0x32,0x38,0x31,0x32,0x35,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31, + 0x29,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x38,0x29,0x20,0x2b,0x20,0x28,0x28,0x28, + 0x28,0x28,0x28,0x2d,0x30,0x2e,0x30,0x32,0x39,0x30,0x33,0x30,0x30,0x30,0x30,0x37, + 0x39,0x30,0x39,0x35,0x33,0x36,0x33,0x36,0x31,0x36,0x39,0x34,0x33,0x33,0x35,0x39, + 0x33,0x37,0x35,0x29,0x20,0x2a,0x20,0x5f,0x32,0x35,0x38,0x29,0x20,0x2b,0x20,0x28, + 0x30,0x2e,0x30,0x36,0x33,0x37,0x37,0x30,0x30,0x30,0x33,0x36,0x31,0x36,0x38,0x30, + 0x39,0x38,0x34,0x34,0x39,0x37,0x30,0x37,0x30,0x33,0x31,0x32,0x35,0x20,0x2a,0x20, + 0x5f,0x32,0x35,0x34,0x29,0x29,0x20,0x2d,0x20,0x28,0x30,0x2e,0x30,0x33,0x32,0x30, + 0x31,0x39,0x39,0x39,0x38,0x38,0x37,0x38,0x32,0x34,0x30,0x35,0x38,0x35,0x33,0x32, + 0x37,0x31,0x34,0x38,0x34,0x33,0x37,0x35,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31,0x29, + 0x29,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x33,0x39,0x34,0x30,0x30,0x30,0x30,0x31, + 0x39,0x38,0x37,0x38,0x31,0x34,0x39,0x30,0x33,0x32,0x35,0x39,0x32,0x37,0x37,0x33, + 0x34,0x33,0x37,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x29,0x20,0x2b, + 0x20,0x28,0x28,0x28,0x28,0x30,0x2e,0x31,0x31,0x36,0x39,0x33,0x30,0x30,0x30,0x30, + 0x34,0x38,0x33,0x39,0x38,0x39,0x37,0x31,0x35,0x35,0x37,0x36,0x31,0x37,0x31,0x38, + 0x37,0x35,0x20,0x2a,0x20,0x5f,0x32,0x35,0x38,0x29,0x20,0x2d,0x20,0x28,0x30,0x2e, + 0x32,0x31,0x31,0x39,0x36,0x30,0x30,0x30,0x32,0x37,0x37,0x39,0x39,0x36,0x30,0x36, + 0x33,0x32,0x33,0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x20,0x2a,0x20,0x5f,0x32,0x35, + 0x34,0x29,0x29,0x20,0x2b,0x20,0x28,0x30,0x2e,0x30,0x36,0x30,0x35,0x32,0x30,0x30, + 0x30,0x30,0x37,0x35,0x35,0x37,0x38,0x36,0x38,0x39,0x35,0x37,0x35,0x31,0x39,0x35, + 0x33,0x31,0x32,0x35,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31,0x29,0x29,0x20,0x2b,0x20, + 0x30,0x2e,0x32,0x35,0x38,0x38,0x35,0x39,0x39,0x39,0x32,0x30,0x32,0x37,0x32,0x38, + 0x32,0x37,0x31,0x34,0x38,0x34,0x33,0x37,0x35,0x29,0x29,0x20,0x2a,0x20,0x70,0x72, + 0x65,0x65,0x74,0x68,0x61,0x6d,0x50,0x65,0x72,0x65,0x7a,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x29,0x29,0x20,0x2f,0x20,0x6d,0x61,0x78, + 0x28,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x50,0x65,0x72,0x65,0x7a,0x28,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x33,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, + 0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x36,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x33,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x39,0x29,0x2c,0x20, + 0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35, + 0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38, + 0x38,0x65,0x2d,0x30,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x39,0x20,0x3d,0x20,0x28,0x28,0x28, + 0x28,0x28,0x28,0x28,0x30,0x2e,0x30,0x30,0x32,0x37,0x34,0x39,0x39,0x39,0x39,0x39, + 0x38,0x35,0x30,0x39,0x38,0x38,0x33,0x38,0x38,0x30,0x36,0x31,0x35,0x32,0x33,0x34, + 0x33,0x37,0x35,0x20,0x2a,0x20,0x5f,0x32,0x35,0x38,0x29,0x20,0x2d,0x20,0x28,0x30, + 0x2e,0x30,0x30,0x36,0x30,0x39,0x39,0x39,0x39,0x39,0x38,0x38,0x32,0x32,0x38,0x30, + 0x38,0x32,0x36,0x35,0x36,0x38,0x36,0x30,0x33,0x35,0x31,0x35,0x36,0x32,0x35,0x20, + 0x2a,0x20,0x5f,0x32,0x35,0x34,0x29,0x29,0x20,0x2b,0x20,0x28,0x30,0x2e,0x30,0x30, + 0x33,0x31,0x36,0x39,0x39,0x39,0x39,0x39,0x32,0x33,0x35,0x35,0x37,0x30,0x34,0x33, + 0x30,0x37,0x35,0x35,0x36,0x31,0x35,0x32,0x33,0x34,0x33,0x37,0x35,0x20,0x2a,0x20, + 0x5f,0x31,0x35,0x31,0x29,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x38,0x29,0x20,0x2b, + 0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x2d,0x30,0x2e,0x30,0x34,0x32,0x31,0x33,0x39, + 0x39,0x39,0x39,0x35,0x36,0x38,0x34,0x36,0x32,0x33,0x37,0x31,0x38,0x32,0x36,0x31, + 0x37,0x31,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x5f,0x32,0x35,0x38,0x29,0x20,0x2b, + 0x20,0x28,0x30,0x2e,0x30,0x38,0x39,0x36,0x39,0x39,0x39,0x39,0x38,0x34,0x39,0x37, + 0x39,0x36,0x32,0x39,0x35,0x31,0x36,0x36,0x30,0x31,0x35,0x36,0x32,0x35,0x20,0x2a, + 0x20,0x5f,0x32,0x35,0x34,0x29,0x29,0x20,0x2d,0x20,0x28,0x30,0x2e,0x30,0x34,0x31, + 0x35,0x32,0x39,0x39,0x39,0x38,0x31,0x38,0x33,0x32,0x35,0x30,0x34,0x32,0x37,0x32, + 0x34,0x36,0x30,0x39,0x33,0x37,0x35,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31,0x29,0x29, + 0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x35,0x31,0x36,0x30,0x30,0x30,0x30,0x31,0x37, + 0x35,0x32,0x33,0x37,0x36,0x35,0x35,0x36,0x33,0x39,0x36,0x34,0x38,0x34,0x33,0x37, + 0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x29,0x20,0x2b,0x20,0x28,0x28, + 0x28,0x28,0x30,0x2e,0x31,0x35,0x33,0x34,0x35,0x39,0x39,0x39,0x35,0x39,0x38,0x35, + 0x30,0x33,0x31,0x31,0x32,0x37,0x39,0x32,0x39,0x36,0x38,0x37,0x35,0x20,0x2a,0x20, + 0x5f,0x32,0x35,0x38,0x29,0x20,0x2d,0x20,0x28,0x30,0x2e,0x32,0x36,0x37,0x35,0x36, + 0x30,0x30,0x30,0x35,0x31,0x38,0x37,0x39,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x20, + 0x2a,0x20,0x5f,0x32,0x35,0x34,0x29,0x29,0x20,0x2b,0x20,0x28,0x30,0x2e,0x30,0x36, + 0x36,0x36,0x39,0x39,0x39,0x39,0x36,0x35,0x39,0x30,0x36,0x31,0x34,0x33,0x31,0x38, + 0x38,0x34,0x37,0x36,0x35,0x36,0x32,0x35,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31,0x29, + 0x29,0x20,0x2b,0x20,0x30,0x2e,0x32,0x36,0x36,0x38,0x38,0x30,0x30,0x30,0x35,0x35, + 0x39,0x38,0x30,0x36,0x38,0x32,0x33,0x37,0x33,0x30,0x34,0x36,0x38,0x37,0x35,0x29, + 0x29,0x20,0x2a,0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x50,0x65,0x72,0x65, + 0x7a,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33, + 0x29,0x29,0x20,0x2f,0x20,0x6d,0x61,0x78,0x28,0x70,0x72,0x65,0x65,0x74,0x68,0x61, + 0x6d,0x50,0x65,0x72,0x65,0x7a,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x30,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x34,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x33,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x34,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, + 0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x36,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x34,0x37,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39, + 0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34, + 0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x35,0x30,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x34, + 0x2e,0x30,0x34,0x35,0x33,0x30,0x30,0x30,0x30,0x36,0x38,0x36,0x36,0x34,0x35,0x35, + 0x30,0x37,0x38,0x31,0x32,0x35,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2d, + 0x20,0x34,0x2e,0x39,0x37,0x31,0x30,0x30,0x30,0x31,0x39,0x34,0x35,0x34,0x39,0x35, + 0x36,0x30,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x74,0x61,0x6e,0x28, + 0x28,0x30,0x2e,0x34,0x34,0x34,0x34,0x34,0x34,0x34,0x34,0x37,0x37,0x35,0x35,0x38, + 0x31,0x33,0x35,0x39,0x38,0x36,0x33,0x32,0x38,0x31,0x32,0x35,0x20,0x2d,0x20,0x28, + 0x5f,0x31,0x35,0x34,0x20,0x2a,0x20,0x30,0x2e,0x30,0x30,0x38,0x33,0x33,0x33,0x33, + 0x33,0x33,0x37,0x36,0x37,0x39,0x35,0x30,0x35,0x33,0x34,0x38,0x32,0x30,0x35,0x35, + 0x36,0x36,0x34,0x30,0x36,0x32,0x35,0x29,0x29,0x20,0x2a,0x20,0x28,0x33,0x2e,0x31, + 0x34,0x31,0x35,0x39,0x32,0x37,0x34,0x31,0x30,0x31,0x32,0x35,0x37,0x33,0x32,0x34, + 0x32,0x31,0x38,0x37,0x35,0x20,0x2d,0x20,0x28,0x32,0x2e,0x30,0x20,0x2a,0x20,0x5f, + 0x31,0x35,0x31,0x29,0x29,0x29,0x29,0x20,0x2d,0x20,0x28,0x30,0x2e,0x32,0x31,0x35, + 0x34,0x39,0x39,0x39,0x39,0x37,0x31,0x33,0x38,0x39,0x37,0x37,0x30,0x35,0x30,0x37, + 0x38,0x31,0x32,0x35,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x29,0x20,0x2b,0x20, + 0x32,0x2e,0x34,0x31,0x39,0x31,0x39,0x39,0x39,0x34,0x33,0x35,0x34,0x32,0x34,0x38, + 0x30,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x70,0x72,0x65,0x65,0x74,0x68, + 0x61,0x6d,0x50,0x65,0x72,0x65,0x7a,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x29,0x29,0x20,0x2f, + 0x20,0x6d,0x61,0x78,0x28,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x50,0x65,0x72, + 0x65,0x7a,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x36,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x39,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x33,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, + 0x31,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33, + 0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33, + 0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x35,0x31,0x20,0x3d,0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x58,0x79, + 0x59,0x5f,0x74,0x6f,0x5f,0x58,0x59,0x5a,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, + 0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x39,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x35,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x6d,0x61,0x78,0x28,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x58, + 0x59,0x5a,0x5f,0x74,0x6f,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x73,0x72,0x67, + 0x62,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x31,0x29,0x2c,0x20,0x76,0x65,0x63, + 0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33, + 0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x53,0x6b,0x79,0x53,0x63,0x61,0x6c, + 0x65,0x64,0x28,0x76,0x65,0x63,0x33,0x20,0x76,0x69,0x65,0x77,0x5f,0x64,0x69,0x72, + 0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x74,0x75,0x72,0x62,0x69,0x64,0x69,0x74,0x79,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x66,0x61,0x64,0x65,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20, + 0x76,0x69,0x65,0x77,0x5f,0x64,0x69,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x73,0x75,0x6e, + 0x5f,0x64,0x69,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x74,0x75,0x72,0x62,0x69,0x64, + 0x69,0x74,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x28,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x53,0x6b,0x79,0x28,0x70,0x61,0x72, + 0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x29,0x20,0x2a,0x20,0x30,0x2e,0x30,0x35,0x39,0x39,0x39,0x39, + 0x39,0x39,0x38,0x36,0x35,0x38,0x38,0x39,0x35,0x34,0x39,0x32,0x35,0x35,0x33,0x37, + 0x31,0x30,0x39,0x33,0x37,0x35,0x29,0x20,0x2a,0x20,0x66,0x61,0x64,0x65,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20, + 0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x28,0x76,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x5f,0x68,0x6f,0x6d,0x6f,0x67,0x2e,0x78,0x79,0x7a,0x20,0x2f, + 0x20,0x76,0x65,0x63,0x33,0x28,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x68,0x6f, + 0x6d,0x6f,0x67,0x2e,0x77,0x29,0x29,0x20,0x2d,0x20,0x73,0x6b,0x79,0x5f,0x75,0x62, + 0x5f,0x70,0x61,0x73,0x73,0x5b,0x32,0x5d,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20, + 0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x73,0x6b,0x79,0x5f, + 0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x20,0x3d,0x20,0x73,0x6b,0x79,0x5f,0x75,0x62,0x5f,0x70,0x61,0x73,0x73, + 0x5b,0x31,0x5d,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x73,0x6b,0x79,0x5f,0x75, + 0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x30,0x5d,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63, + 0x34,0x28,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x53,0x6b,0x79,0x53,0x63,0x61, + 0x6c,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a, + 0x00, +}; +/* + cbuffer sky_ub_frame : register(b0) + { + row_major float4x4 _50_inv_view_proj : packoffset(c0); + }; + + + static float4 gl_Position; + static int gl_VertexIndex; + static float4 v_world_homog; + + struct SPIRV_Cross_Input + { + uint gl_VertexIndex : SV_VertexID; + }; + + struct SPIRV_Cross_Output + { + float4 v_world_homog : TEXCOORD0; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + float4 _35 = float4((float2(float((gl_VertexIndex << 1) & 2), float(gl_VertexIndex & 2)) * 2.0f) - 1.0f.xx, 0.0f, 1.0f); + gl_Position = _35; + v_world_homog = mul(_35, _50_inv_view_proj); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_VertexIndex = int(stage_input.gl_VertexIndex); + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.v_world_homog = v_world_homog; + return stage_output; + } +*/ +static const uint8_t vs_source_hlsl5[868] = { + 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x73,0x6b,0x79,0x5f,0x75,0x62,0x5f,0x66, + 0x72,0x61,0x6d,0x65,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28, + 0x62,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61, + 0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x35,0x30, + 0x5f,0x69,0x6e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a, + 0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b, + 0x0a,0x7d,0x3b,0x0a,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b, + 0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x56, + 0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74, + 0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x68,0x6f,0x6d,0x6f,0x67,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74, + 0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70, + 0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c, + 0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x3a,0x20,0x53, + 0x56,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x44,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a, + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, + 0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x68, + 0x6f,0x6d,0x6f,0x67,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f, + 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,0x53,0x56,0x5f,0x50,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64, + 0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x33,0x35,0x20,0x3d,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x66, + 0x6c,0x6f,0x61,0x74,0x28,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49, + 0x6e,0x64,0x65,0x78,0x20,0x3c,0x3c,0x20,0x31,0x29,0x20,0x26,0x20,0x32,0x29,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78, + 0x49,0x6e,0x64,0x65,0x78,0x20,0x26,0x20,0x32,0x29,0x29,0x20,0x2a,0x20,0x32,0x2e, + 0x30,0x66,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x2c,0x20,0x30, + 0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x5f,0x33, + 0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x68, + 0x6f,0x6d,0x6f,0x67,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x5f,0x33,0x35,0x2c,0x20, + 0x5f,0x35,0x30,0x5f,0x69,0x6e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f, + 0x6a,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, + 0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53, + 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74, + 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64, + 0x65,0x78,0x20,0x3d,0x20,0x69,0x6e,0x74,0x28,0x73,0x74,0x61,0x67,0x65,0x5f,0x69, + 0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e, + 0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d, + 0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56, + 0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74, + 0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f, + 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x50,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67, + 0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x5f,0x68,0x6f,0x6d,0x6f,0x67,0x20,0x3d,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x5f,0x68,0x6f,0x6d,0x6f,0x67,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b, + 0x0a,0x7d,0x0a,0x00, +}; +/* + cbuffer sky_ub_pass : register(b1) + { + float4 _549_sun_dir_world : packoffset(c0); + float4 _549_sky_params : packoffset(c1); + float4 _549_camera_pos : packoffset(c2); + }; + + + static float4 v_world_homog; + static float4 out_color; + + struct SPIRV_Cross_Input + { + float4 v_world_homog : TEXCOORD0; + }; + + struct SPIRV_Cross_Output + { + float4 out_color : SV_Target0; + }; + + float preethamPerez(float cos_theta, float cos_gamma, float gamma, float A, float B, float C, float D, float E) + { + return (1.0f + (A * exp(B / max(cos_theta, 0.00999999977648258209228515625f)))) * ((1.0f + (C * exp(D * gamma))) + ((E * cos_gamma) * cos_gamma)); + } + + float3 preethamXyY_to_XYZ(float x, float y, float Y) + { + float _77 = max(y, 9.9999997473787516355514526367188e-06f); + return float3((Y * x) / _77, Y, (Y * ((1.0f - x) - y)) / _77); + } + + float3 preethamXYZ_to_linear_srgb(float3 c) + { + return float3(dot(c, float3(3.240454196929931640625f, -1.537138462066650390625f, -0.498531401157379150390625f)), dot(c, float3(-0.969265997409820556640625f, 1.87601077556610107421875f, 0.04155600070953369140625f)), dot(c, float3(0.0556433983147144317626953125f, -0.2040258944034576416015625f, 1.05722522735595703125f))); + } + + float3 preethamSky(float3 view_dir, float3 sun_dir, float turbidity) + { + float _122 = clamp(sun_dir.y, 0.0f, 1.0f); + float3 _135 = normalize(float3(view_dir.x, max(view_dir.y, 0.0f) + 0.00999999977648258209228515625f, view_dir.z)); + float _139 = max(_135.y, 0.0f); + float _145 = clamp(dot(sun_dir, _135), -1.0f, 1.0f); + float _148 = acos(_145); + float _151 = acos(_122); + float _154 = max(turbidity, 1.0f); + float _158 = _154 * _154; + float _164 = (0.1787000000476837158203125f * _154) - 1.4630000591278076171875f; + float _170 = ((-0.3553999960422515869140625f) * _154) + 0.4275000095367431640625f; + float _176 = ((-0.0227000005543231964111328125f) * _154) + 5.325099945068359375f; + float _182 = (0.12060000002384185791015625f * _154) - 2.5771000385284423828125f; + float _188 = ((-0.0670000016689300537109375f) * _154) + 0.370299994945526123046875f; + float _194 = ((-0.01930000074207782745361328125f) * _154) - 0.2592000067234039306640625f; + float _200 = ((-0.066500000655651092529296875f) * _154) + 0.0007999999797903001308441162109375f; + float _206 = ((-0.00039999998989515006542205810546875f) * _154) + 0.2125000059604644775390625f; + float _212 = ((-0.0640999972820281982421875f) * _154) - 0.898899972438812255859375f; + float _218 = ((-0.0032999999821186065673828125f) * _154) + 0.0452000014483928680419921875f; + float _224 = ((-0.0166999995708465576171875f) * _154) - 0.26080000400543212890625f; + float _230 = ((-0.0949999988079071044921875f) * _154) + 0.009200000204145908355712890625f; + float _236 = ((-0.0078999996185302734375f) * _154) + 0.21019999682903289794921875f; + float _242 = ((-0.04410000145435333251953125f) * _154) - 1.65369999408721923828125f; + float _248 = ((-0.01090000011026859283447265625f) * _154) + 0.05290000140666961669921875f; + float _254 = _151 * _151; + float _258 = _254 * _151; + float param = _139; + float param_1 = _145; + float param_2 = _148; + float param_3 = _164; + float param_4 = _170; + float param_5 = _176; + float param_6 = _182; + float param_7 = _188; + float param_8 = _139; + float param_9 = _145; + float param_10 = _148; + float param_11 = _194; + float param_12 = _200; + float param_13 = _206; + float param_14 = _212; + float param_15 = _218; + float param_16 = _139; + float param_17 = _145; + float param_18 = _148; + float param_19 = _224; + float param_20 = _230; + float param_21 = _236; + float param_22 = _242; + float param_23 = _248; + float param_24 = 1.0f; + float param_25 = _122; + float param_26 = _151; + float param_27 = _164; + float param_28 = _170; + float param_29 = _176; + float param_30 = _182; + float param_31 = _188; + float param_32 = 1.0f; + float param_33 = _122; + float param_34 = _151; + float param_35 = _194; + float param_36 = _200; + float param_37 = _206; + float param_38 = _212; + float param_39 = _218; + float param_40 = 1.0f; + float param_41 = _122; + float param_42 = _151; + float param_43 = _224; + float param_44 = _230; + float param_45 = _236; + float param_46 = _242; + float param_47 = _248; + float param_48 = (((((((0.001659999950788915157318115234375f * _258) - (0.00374999991618096828460693359375f * _254)) + (0.0020900000818073749542236328125f * _151)) * _158) + ((((((-0.02903000079095363616943359375f) * _258) + (0.063770003616809844970703125f * _254)) - (0.0320199988782405853271484375f * _151)) + 0.003940000198781490325927734375f) * _154)) + ((((0.116930000483989715576171875f * _258) - (0.21196000277996063232421875f * _254)) + (0.060520000755786895751953125f * _151)) + 0.25885999202728271484375f)) * preethamPerez(param_8, param_9, param_10, param_11, param_12, param_13, param_14, param_15)) / max(preethamPerez(param_32, param_33, param_34, param_35, param_36, param_37, param_38, param_39), 9.9999997473787516355514526367188e-06f); + float param_49 = (((((((0.00274999998509883880615234375f * _258) - (0.006099999882280826568603515625f * _254)) + (0.0031699999235570430755615234375f * _151)) * _158) + ((((((-0.042139999568462371826171875f) * _258) + (0.08969999849796295166015625f * _254)) - (0.04152999818325042724609375f * _151)) + 0.0051600001752376556396484375f) * _154)) + ((((0.1534599959850311279296875f * _258) - (0.26756000518798828125f * _254)) + (0.06669999659061431884765625f * _151)) + 0.2668800055980682373046875f)) * preethamPerez(param_16, param_17, param_18, param_19, param_20, param_21, param_22, param_23)) / max(preethamPerez(param_40, param_41, param_42, param_43, param_44, param_45, param_46, param_47), 9.9999997473787516355514526367188e-06f); + float param_50 = max(((((((4.045300006866455078125f * _154) - 4.971000194549560546875f) * tan((0.4444444477558135986328125f - (_154 * 0.008333333767950534820556640625f)) * (3.1415927410125732421875f - (2.0f * _151)))) - (0.21549999713897705078125f * _154)) + 2.41919994354248046875f) * preethamPerez(param, param_1, param_2, param_3, param_4, param_5, param_6, param_7)) / max(preethamPerez(param_24, param_25, param_26, param_27, param_28, param_29, param_30, param_31), 9.9999997473787516355514526367188e-06f), 0.0f); + float3 param_51 = preethamXyY_to_XYZ(param_48, param_49, param_50); + return max(preethamXYZ_to_linear_srgb(param_51), 0.0f.xxx); + } + + float3 preethamSkyScaled(float3 view_dir, float3 sun_dir, float turbidity, float fade) + { + float3 param = view_dir; + float3 param_1 = sun_dir; + float param_2 = turbidity; + return (preethamSky(param, param_1, param_2) * 0.0599999986588954925537109375f) * fade; + } + + void frag_main() + { + float3 param = normalize((v_world_homog.xyz / v_world_homog.w.xxx) - _549_camera_pos.xyz); + float3 param_1 = normalize(_549_sun_dir_world.xyz); + float param_2 = _549_sky_params.x; + float param_3 = _549_sun_dir_world.w; + out_color = float4(preethamSkyScaled(param, param_1, param_2, param_3), 1.0f); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + v_world_homog = stage_input.v_world_homog; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.out_color = out_color; + return stage_output; + } +*/ +static const uint8_t fs_source_hlsl5[7367] = { + 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x73,0x6b,0x79,0x5f,0x75,0x62,0x5f,0x70, + 0x61,0x73,0x73,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62, + 0x31,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x5f,0x35,0x34,0x39,0x5f,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28, + 0x63,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x5f,0x35,0x34,0x39,0x5f,0x73,0x6b,0x79,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x20, + 0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x35,0x34, + 0x39,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20,0x70, + 0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x32,0x29,0x3b,0x0a,0x7d, + 0x3b,0x0a,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x68,0x6f,0x6d,0x6f,0x67,0x3b, + 0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f, + 0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63, + 0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e, + 0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x68,0x6f,0x6d,0x6f,0x67,0x20,0x3a, + 0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a, + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, + 0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x3a,0x20,0x53,0x56,0x5f,0x54,0x61,0x72,0x67,0x65,0x74,0x30,0x3b,0x0a,0x7d, + 0x3b,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61, + 0x6d,0x50,0x65,0x72,0x65,0x7a,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x63,0x6f,0x73, + 0x5f,0x74,0x68,0x65,0x74,0x61,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x63,0x6f, + 0x73,0x5f,0x67,0x61,0x6d,0x6d,0x61,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67, + 0x61,0x6d,0x6d,0x61,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x41,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x42,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x43,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x44,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x45,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x28,0x31,0x2e,0x30,0x66,0x20,0x2b,0x20,0x28,0x41,0x20,0x2a,0x20,0x65,0x78,0x70, + 0x28,0x42,0x20,0x2f,0x20,0x6d,0x61,0x78,0x28,0x63,0x6f,0x73,0x5f,0x74,0x68,0x65, + 0x74,0x61,0x2c,0x20,0x30,0x2e,0x30,0x30,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37, + 0x37,0x36,0x34,0x38,0x32,0x35,0x38,0x32,0x30,0x39,0x32,0x32,0x38,0x35,0x31,0x35, + 0x36,0x32,0x35,0x66,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x28,0x28,0x31,0x2e,0x30, + 0x66,0x20,0x2b,0x20,0x28,0x43,0x20,0x2a,0x20,0x65,0x78,0x70,0x28,0x44,0x20,0x2a, + 0x20,0x67,0x61,0x6d,0x6d,0x61,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x28,0x45,0x20, + 0x2a,0x20,0x63,0x6f,0x73,0x5f,0x67,0x61,0x6d,0x6d,0x61,0x29,0x20,0x2a,0x20,0x63, + 0x6f,0x73,0x5f,0x67,0x61,0x6d,0x6d,0x61,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x58,0x79, + 0x59,0x5f,0x74,0x6f,0x5f,0x58,0x59,0x5a,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x78, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x79,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x59,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x37,0x37,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x79,0x2c,0x20,0x39,0x2e,0x39, + 0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33, + 0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d, + 0x30,0x36,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x59,0x20,0x2a,0x20,0x78,0x29,0x20, + 0x2f,0x20,0x5f,0x37,0x37,0x2c,0x20,0x59,0x2c,0x20,0x28,0x59,0x20,0x2a,0x20,0x28, + 0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x78,0x29,0x20,0x2d,0x20,0x79,0x29,0x29, + 0x20,0x2f,0x20,0x5f,0x37,0x37,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x58,0x59,0x5a,0x5f,0x74, + 0x6f,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x73,0x72,0x67,0x62,0x28,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x63,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x64,0x6f,0x74,0x28, + 0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x33,0x2e,0x32,0x34,0x30,0x34, + 0x35,0x34,0x31,0x39,0x36,0x39,0x32,0x39,0x39,0x33,0x31,0x36,0x34,0x30,0x36,0x32, + 0x35,0x66,0x2c,0x20,0x2d,0x31,0x2e,0x35,0x33,0x37,0x31,0x33,0x38,0x34,0x36,0x32, + 0x30,0x36,0x36,0x36,0x35,0x30,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x2c,0x20,0x2d, + 0x30,0x2e,0x34,0x39,0x38,0x35,0x33,0x31,0x34,0x30,0x31,0x31,0x35,0x37,0x33,0x37, + 0x39,0x31,0x35,0x30,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x29,0x29,0x2c,0x20,0x64, + 0x6f,0x74,0x28,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x2d,0x30,0x2e, + 0x39,0x36,0x39,0x32,0x36,0x35,0x39,0x39,0x37,0x34,0x30,0x39,0x38,0x32,0x30,0x35, + 0x35,0x36,0x36,0x34,0x30,0x36,0x32,0x35,0x66,0x2c,0x20,0x31,0x2e,0x38,0x37,0x36, + 0x30,0x31,0x30,0x37,0x37,0x35,0x35,0x36,0x36,0x31,0x30,0x31,0x30,0x37,0x34,0x32, + 0x31,0x38,0x37,0x35,0x66,0x2c,0x20,0x30,0x2e,0x30,0x34,0x31,0x35,0x35,0x36,0x30, + 0x30,0x30,0x37,0x30,0x39,0x35,0x33,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35, + 0x66,0x29,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x30,0x2e,0x30,0x35,0x35,0x36,0x34,0x33,0x33,0x39,0x38,0x33,0x31, + 0x34,0x37,0x31,0x34,0x34,0x33,0x31,0x37,0x36,0x32,0x36,0x39,0x35,0x33,0x31,0x32, + 0x35,0x66,0x2c,0x20,0x2d,0x30,0x2e,0x32,0x30,0x34,0x30,0x32,0x35,0x38,0x39,0x34, + 0x34,0x30,0x33,0x34,0x35,0x37,0x36,0x34,0x31,0x36,0x30,0x31,0x35,0x36,0x32,0x35, + 0x66,0x2c,0x20,0x31,0x2e,0x30,0x35,0x37,0x32,0x32,0x35,0x32,0x32,0x37,0x33,0x35, + 0x35,0x39,0x35,0x37,0x30,0x33,0x31,0x32,0x35,0x66,0x29,0x29,0x29,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61, + 0x6d,0x53,0x6b,0x79,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x69,0x65,0x77, + 0x5f,0x64,0x69,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x73,0x75,0x6e, + 0x5f,0x64,0x69,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x74,0x75,0x72,0x62, + 0x69,0x64,0x69,0x74,0x79,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x32,0x32,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28, + 0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x2e,0x79,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c, + 0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x5f,0x31,0x33,0x35,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c, + 0x69,0x7a,0x65,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x76,0x69,0x65,0x77,0x5f, + 0x64,0x69,0x72,0x2e,0x78,0x2c,0x20,0x6d,0x61,0x78,0x28,0x76,0x69,0x65,0x77,0x5f, + 0x64,0x69,0x72,0x2e,0x79,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x20,0x2b,0x20,0x30, + 0x2e,0x30,0x30,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x37,0x36,0x34,0x38,0x32, + 0x35,0x38,0x32,0x30,0x39,0x32,0x32,0x38,0x35,0x31,0x35,0x36,0x32,0x35,0x66,0x2c, + 0x20,0x76,0x69,0x65,0x77,0x5f,0x64,0x69,0x72,0x2e,0x7a,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x39,0x20,0x3d,0x20, + 0x6d,0x61,0x78,0x28,0x5f,0x31,0x33,0x35,0x2e,0x79,0x2c,0x20,0x30,0x2e,0x30,0x66, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34, + 0x35,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x64,0x6f,0x74,0x28,0x73,0x75, + 0x6e,0x5f,0x64,0x69,0x72,0x2c,0x20,0x5f,0x31,0x33,0x35,0x29,0x2c,0x20,0x2d,0x31, + 0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x38,0x20,0x3d,0x20,0x61,0x63,0x6f, + 0x73,0x28,0x5f,0x31,0x34,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x35,0x31,0x20,0x3d,0x20,0x61,0x63,0x6f,0x73,0x28,0x5f, + 0x31,0x32,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x35,0x34,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x74,0x75,0x72,0x62,0x69, + 0x64,0x69,0x74,0x79,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x38,0x20,0x3d,0x20,0x5f,0x31, + 0x35,0x34,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x34,0x20,0x3d,0x20,0x28,0x30,0x2e,0x31, + 0x37,0x38,0x37,0x30,0x30,0x30,0x30,0x30,0x30,0x34,0x37,0x36,0x38,0x33,0x37,0x31, + 0x35,0x38,0x32,0x30,0x33,0x31,0x32,0x35,0x66,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34, + 0x29,0x20,0x2d,0x20,0x31,0x2e,0x34,0x36,0x33,0x30,0x30,0x30,0x30,0x35,0x39,0x31, + 0x32,0x37,0x38,0x30,0x37,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x66,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x37,0x30,0x20,0x3d,0x20, + 0x28,0x28,0x2d,0x30,0x2e,0x33,0x35,0x35,0x33,0x39,0x39,0x39,0x39,0x36,0x30,0x34, + 0x32,0x32,0x35,0x31,0x35,0x38,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x66,0x29, + 0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2b,0x20,0x30,0x2e,0x34,0x32,0x37, + 0x35,0x30,0x30,0x30,0x30,0x39,0x35,0x33,0x36,0x37,0x34,0x33,0x31,0x36,0x34,0x30, + 0x36,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x37,0x36,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x32,0x32,0x37, + 0x30,0x30,0x30,0x30,0x30,0x35,0x35,0x34,0x33,0x32,0x33,0x31,0x39,0x36,0x34,0x31, + 0x31,0x31,0x33,0x32,0x38,0x31,0x32,0x35,0x66,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35, + 0x34,0x29,0x20,0x2b,0x20,0x35,0x2e,0x33,0x32,0x35,0x30,0x39,0x39,0x39,0x34,0x35, + 0x30,0x36,0x38,0x33,0x35,0x39,0x33,0x37,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x38,0x32,0x20,0x3d,0x20,0x28,0x30,0x2e, + 0x31,0x32,0x30,0x36,0x30,0x30,0x30,0x30,0x30,0x30,0x32,0x33,0x38,0x34,0x31,0x38, + 0x35,0x37,0x39,0x31,0x30,0x31,0x35,0x36,0x32,0x35,0x66,0x20,0x2a,0x20,0x5f,0x31, + 0x35,0x34,0x29,0x20,0x2d,0x20,0x32,0x2e,0x35,0x37,0x37,0x31,0x30,0x30,0x30,0x33, + 0x38,0x35,0x32,0x38,0x34,0x34,0x32,0x33,0x38,0x32,0x38,0x31,0x32,0x35,0x66,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x38,0x38,0x20, + 0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x36,0x37,0x30,0x30,0x30,0x30,0x30,0x31, + 0x36,0x36,0x38,0x39,0x33,0x30,0x30,0x35,0x33,0x37,0x31,0x30,0x39,0x33,0x37,0x35, + 0x66,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2b,0x20,0x30,0x2e,0x33, + 0x37,0x30,0x32,0x39,0x39,0x39,0x39,0x34,0x39,0x34,0x35,0x35,0x32,0x36,0x31,0x32, + 0x33,0x30,0x34,0x36,0x38,0x37,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x31,0x39,0x34,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e, + 0x30,0x31,0x39,0x33,0x30,0x30,0x30,0x30,0x30,0x37,0x34,0x32,0x30,0x37,0x37,0x38, + 0x32,0x37,0x34,0x35,0x33,0x36,0x31,0x33,0x32,0x38,0x31,0x32,0x35,0x66,0x29,0x20, + 0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2d,0x20,0x30,0x2e,0x32,0x35,0x39,0x32, + 0x30,0x30,0x30,0x30,0x36,0x37,0x32,0x33,0x34,0x30,0x33,0x39,0x33,0x30,0x36,0x36, + 0x34,0x30,0x36,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x32,0x30,0x30,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x36, + 0x36,0x35,0x30,0x30,0x30,0x30,0x30,0x36,0x35,0x35,0x36,0x35,0x31,0x30,0x39,0x32, + 0x35,0x32,0x39,0x32,0x39,0x36,0x38,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x5f,0x31, + 0x35,0x34,0x29,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x37,0x39,0x39,0x39,0x39, + 0x39,0x39,0x37,0x39,0x37,0x39,0x30,0x33,0x30,0x30,0x31,0x33,0x30,0x38,0x34,0x34, + 0x31,0x31,0x36,0x32,0x31,0x30,0x39,0x33,0x37,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x30,0x36,0x20,0x3d,0x20,0x28,0x28, + 0x2d,0x30,0x2e,0x30,0x30,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x38,0x39,0x38, + 0x39,0x35,0x31,0x35,0x30,0x30,0x36,0x35,0x34,0x32,0x32,0x30,0x35,0x38,0x31,0x30, + 0x35,0x34,0x36,0x38,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29, + 0x20,0x2b,0x20,0x30,0x2e,0x32,0x31,0x32,0x35,0x30,0x30,0x30,0x30,0x35,0x39,0x36, + 0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x32,0x20, + 0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x36,0x34,0x30,0x39,0x39,0x39,0x39,0x37, + 0x32,0x38,0x32,0x30,0x32,0x38,0x31,0x39,0x38,0x32,0x34,0x32,0x31,0x38,0x37,0x35, + 0x66,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2d,0x20,0x30,0x2e,0x38, + 0x39,0x38,0x38,0x39,0x39,0x39,0x37,0x32,0x34,0x33,0x38,0x38,0x31,0x32,0x32,0x35, + 0x35,0x38,0x35,0x39,0x33,0x37,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x38,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e, + 0x30,0x30,0x33,0x32,0x39,0x39,0x39,0x39,0x39,0x39,0x38,0x32,0x31,0x31,0x38,0x36, + 0x30,0x36,0x35,0x36,0x37,0x33,0x38,0x32,0x38,0x31,0x32,0x35,0x66,0x29,0x20,0x2a, + 0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2b,0x20,0x30,0x2e,0x30,0x34,0x35,0x32,0x30, + 0x30,0x30,0x30,0x31,0x34,0x34,0x38,0x33,0x39,0x32,0x38,0x36,0x38,0x30,0x34,0x31, + 0x39,0x39,0x32,0x31,0x38,0x37,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x32,0x32,0x34,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e, + 0x30,0x31,0x36,0x36,0x39,0x39,0x39,0x39,0x39,0x35,0x37,0x30,0x38,0x34,0x36,0x35, + 0x35,0x37,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x5f,0x31, + 0x35,0x34,0x29,0x20,0x2d,0x20,0x30,0x2e,0x32,0x36,0x30,0x38,0x30,0x30,0x30,0x30, + 0x34,0x30,0x30,0x35,0x34,0x33,0x32,0x31,0x32,0x38,0x39,0x30,0x36,0x32,0x35,0x66, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x33,0x30, + 0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x39,0x34,0x39,0x39,0x39,0x39,0x39, + 0x38,0x38,0x30,0x37,0x39,0x30,0x37,0x31,0x30,0x34,0x34,0x39,0x32,0x31,0x38,0x37, + 0x35,0x66,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2b,0x20,0x30,0x2e, + 0x30,0x30,0x39,0x32,0x30,0x30,0x30,0x30,0x30,0x32,0x30,0x34,0x31,0x34,0x35,0x39, + 0x30,0x38,0x33,0x35,0x35,0x37,0x31,0x32,0x38,0x39,0x30,0x36,0x32,0x35,0x66,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x33,0x36,0x20, + 0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x30,0x37,0x38,0x39,0x39,0x39,0x39,0x39, + 0x36,0x31,0x38,0x35,0x33,0x30,0x32,0x37,0x33,0x34,0x33,0x37,0x35,0x66,0x29,0x20, + 0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2b,0x20,0x30,0x2e,0x32,0x31,0x30,0x31, + 0x39,0x39,0x39,0x39,0x36,0x38,0x32,0x39,0x30,0x33,0x32,0x38,0x39,0x37,0x39,0x34, + 0x39,0x32,0x31,0x38,0x37,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x32,0x34,0x32,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30, + 0x34,0x34,0x31,0x30,0x30,0x30,0x30,0x31,0x34,0x35,0x34,0x33,0x35,0x33,0x33,0x33, + 0x32,0x35,0x31,0x39,0x35,0x33,0x31,0x32,0x35,0x66,0x29,0x20,0x2a,0x20,0x5f,0x31, + 0x35,0x34,0x29,0x20,0x2d,0x20,0x31,0x2e,0x36,0x35,0x33,0x36,0x39,0x39,0x39,0x39, + 0x34,0x30,0x38,0x37,0x32,0x31,0x39,0x32,0x33,0x38,0x32,0x38,0x31,0x32,0x35,0x66, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x34,0x38, + 0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x31,0x30,0x39,0x30,0x30,0x30,0x30, + 0x30,0x31,0x31,0x30,0x32,0x36,0x38,0x35,0x39,0x32,0x38,0x33,0x34,0x34,0x37,0x32, + 0x36,0x35,0x36,0x32,0x35,0x66,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20, + 0x2b,0x20,0x30,0x2e,0x30,0x35,0x32,0x39,0x30,0x30,0x30,0x30,0x31,0x34,0x30,0x36, + 0x36,0x36,0x39,0x36,0x31,0x36,0x36,0x39,0x39,0x32,0x31,0x38,0x37,0x35,0x66,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x35,0x34,0x20, + 0x3d,0x20,0x5f,0x31,0x35,0x31,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x35,0x38,0x20,0x3d,0x20, + 0x5f,0x32,0x35,0x34,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f, + 0x31,0x33,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x31,0x34,0x35,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x20,0x3d,0x20,0x5f,0x31,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31,0x36, + 0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x31,0x37,0x30,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d, + 0x20,0x5f,0x31,0x37,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f,0x31,0x38,0x32,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x37,0x20,0x3d,0x20,0x5f,0x31,0x38,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x5f, + 0x31,0x33,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x5f,0x31,0x34,0x35,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x30,0x20,0x3d,0x20,0x5f,0x31,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x5f, + 0x31,0x39,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x5f,0x32,0x30,0x30,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x33,0x20,0x3d,0x20,0x5f,0x32,0x30,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20, + 0x5f,0x32,0x31,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x5f,0x32,0x31,0x38,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x36,0x20,0x3d,0x20,0x5f,0x31,0x33,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x20,0x3d, + 0x20,0x5f,0x31,0x34,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x5f,0x31,0x34,0x38, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20,0x5f,0x32,0x32,0x34,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x20, + 0x3d,0x20,0x5f,0x32,0x33,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x20,0x3d,0x20,0x5f,0x32,0x33, + 0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x32,0x20,0x3d,0x20,0x5f,0x32,0x34,0x32,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33, + 0x20,0x3d,0x20,0x5f,0x32,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x20,0x3d,0x20,0x31,0x2e, + 0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x35,0x20,0x3d,0x20,0x5f,0x31,0x32,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x36,0x20,0x3d,0x20,0x5f,0x31,0x35,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37,0x20,0x3d,0x20,0x5f, + 0x31,0x36,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x38,0x20,0x3d,0x20,0x5f,0x31,0x37,0x30,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x39,0x20,0x3d,0x20,0x5f,0x31,0x37,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x30,0x20,0x3d,0x20, + 0x5f,0x31,0x38,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x31,0x20,0x3d,0x20,0x5f,0x31,0x38,0x38,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x33,0x32,0x20,0x3d,0x20,0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x33,0x20,0x3d, + 0x20,0x5f,0x31,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x20,0x3d,0x20,0x5f,0x31,0x35,0x31, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x33,0x35,0x20,0x3d,0x20,0x5f,0x31,0x39,0x34,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x36,0x20, + 0x3d,0x20,0x5f,0x32,0x30,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x37,0x20,0x3d,0x20,0x5f,0x32,0x30, + 0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x38,0x20,0x3d,0x20,0x5f,0x32,0x31,0x32,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x39, + 0x20,0x3d,0x20,0x5f,0x32,0x31,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x30,0x20,0x3d,0x20,0x31,0x2e, + 0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x34,0x31,0x20,0x3d,0x20,0x5f,0x31,0x32,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, + 0x32,0x20,0x3d,0x20,0x5f,0x31,0x35,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x33,0x20,0x3d,0x20,0x5f, + 0x32,0x32,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x34,0x34,0x20,0x3d,0x20,0x5f,0x32,0x33,0x30,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x34,0x35,0x20,0x3d,0x20,0x5f,0x32,0x33,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x36,0x20,0x3d,0x20, + 0x5f,0x32,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x37,0x20,0x3d,0x20,0x5f,0x32,0x34,0x38,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x34,0x38,0x20,0x3d,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x30,0x2e,0x30, + 0x30,0x31,0x36,0x35,0x39,0x39,0x39,0x39,0x39,0x35,0x30,0x37,0x38,0x38,0x39,0x31, + 0x35,0x31,0x35,0x37,0x33,0x31,0x38,0x31,0x31,0x35,0x32,0x33,0x34,0x33,0x37,0x35, + 0x66,0x20,0x2a,0x20,0x5f,0x32,0x35,0x38,0x29,0x20,0x2d,0x20,0x28,0x30,0x2e,0x30, + 0x30,0x33,0x37,0x34,0x39,0x39,0x39,0x39,0x39,0x31,0x36,0x31,0x38,0x30,0x39,0x36, + 0x38,0x32,0x38,0x34,0x36,0x30,0x36,0x39,0x33,0x33,0x35,0x39,0x33,0x37,0x35,0x66, + 0x20,0x2a,0x20,0x5f,0x32,0x35,0x34,0x29,0x29,0x20,0x2b,0x20,0x28,0x30,0x2e,0x30, + 0x30,0x32,0x30,0x39,0x30,0x30,0x30,0x30,0x30,0x38,0x31,0x38,0x30,0x37,0x33,0x37, + 0x34,0x39,0x35,0x34,0x32,0x32,0x33,0x36,0x33,0x32,0x38,0x31,0x32,0x35,0x66,0x20, + 0x2a,0x20,0x5f,0x31,0x35,0x31,0x29,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x38,0x29, + 0x20,0x2b,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x2d,0x30,0x2e,0x30,0x32,0x39,0x30, + 0x33,0x30,0x30,0x30,0x30,0x37,0x39,0x30,0x39,0x35,0x33,0x36,0x33,0x36,0x31,0x36, + 0x39,0x34,0x33,0x33,0x35,0x39,0x33,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x5f,0x32, + 0x35,0x38,0x29,0x20,0x2b,0x20,0x28,0x30,0x2e,0x30,0x36,0x33,0x37,0x37,0x30,0x30, + 0x30,0x33,0x36,0x31,0x36,0x38,0x30,0x39,0x38,0x34,0x34,0x39,0x37,0x30,0x37,0x30, + 0x33,0x31,0x32,0x35,0x66,0x20,0x2a,0x20,0x5f,0x32,0x35,0x34,0x29,0x29,0x20,0x2d, + 0x20,0x28,0x30,0x2e,0x30,0x33,0x32,0x30,0x31,0x39,0x39,0x39,0x38,0x38,0x37,0x38, + 0x32,0x34,0x30,0x35,0x38,0x35,0x33,0x32,0x37,0x31,0x34,0x38,0x34,0x33,0x37,0x35, + 0x66,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31,0x29,0x29,0x20,0x2b,0x20,0x30,0x2e,0x30, + 0x30,0x33,0x39,0x34,0x30,0x30,0x30,0x30,0x31,0x39,0x38,0x37,0x38,0x31,0x34,0x39, + 0x30,0x33,0x32,0x35,0x39,0x32,0x37,0x37,0x33,0x34,0x33,0x37,0x35,0x66,0x29,0x20, + 0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x29,0x20,0x2b,0x20,0x28,0x28,0x28,0x28,0x30, + 0x2e,0x31,0x31,0x36,0x39,0x33,0x30,0x30,0x30,0x30,0x34,0x38,0x33,0x39,0x38,0x39, + 0x37,0x31,0x35,0x35,0x37,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x66,0x20,0x2a,0x20, + 0x5f,0x32,0x35,0x38,0x29,0x20,0x2d,0x20,0x28,0x30,0x2e,0x32,0x31,0x31,0x39,0x36, + 0x30,0x30,0x30,0x32,0x37,0x37,0x39,0x39,0x36,0x30,0x36,0x33,0x32,0x33,0x32,0x34, + 0x32,0x31,0x38,0x37,0x35,0x66,0x20,0x2a,0x20,0x5f,0x32,0x35,0x34,0x29,0x29,0x20, + 0x2b,0x20,0x28,0x30,0x2e,0x30,0x36,0x30,0x35,0x32,0x30,0x30,0x30,0x30,0x37,0x35, + 0x35,0x37,0x38,0x36,0x38,0x39,0x35,0x37,0x35,0x31,0x39,0x35,0x33,0x31,0x32,0x35, + 0x66,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31,0x29,0x29,0x20,0x2b,0x20,0x30,0x2e,0x32, + 0x35,0x38,0x38,0x35,0x39,0x39,0x39,0x32,0x30,0x32,0x37,0x32,0x38,0x32,0x37,0x31, + 0x34,0x38,0x34,0x33,0x37,0x35,0x66,0x29,0x29,0x20,0x2a,0x20,0x70,0x72,0x65,0x65, + 0x74,0x68,0x61,0x6d,0x50,0x65,0x72,0x65,0x7a,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x35,0x29,0x29,0x20,0x2f,0x20,0x6d,0x61,0x78,0x28,0x70, + 0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x50,0x65,0x72,0x65,0x7a,0x28,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x33,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x33,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x36,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x33,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, + 0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x39,0x29,0x2c,0x20,0x39,0x2e, + 0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36, + 0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65, + 0x2d,0x30,0x36,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x39,0x20,0x3d,0x20,0x28,0x28,0x28,0x28, + 0x28,0x28,0x28,0x30,0x2e,0x30,0x30,0x32,0x37,0x34,0x39,0x39,0x39,0x39,0x39,0x38, + 0x35,0x30,0x39,0x38,0x38,0x33,0x38,0x38,0x30,0x36,0x31,0x35,0x32,0x33,0x34,0x33, + 0x37,0x35,0x66,0x20,0x2a,0x20,0x5f,0x32,0x35,0x38,0x29,0x20,0x2d,0x20,0x28,0x30, + 0x2e,0x30,0x30,0x36,0x30,0x39,0x39,0x39,0x39,0x39,0x38,0x38,0x32,0x32,0x38,0x30, + 0x38,0x32,0x36,0x35,0x36,0x38,0x36,0x30,0x33,0x35,0x31,0x35,0x36,0x32,0x35,0x66, + 0x20,0x2a,0x20,0x5f,0x32,0x35,0x34,0x29,0x29,0x20,0x2b,0x20,0x28,0x30,0x2e,0x30, + 0x30,0x33,0x31,0x36,0x39,0x39,0x39,0x39,0x39,0x32,0x33,0x35,0x35,0x37,0x30,0x34, + 0x33,0x30,0x37,0x35,0x35,0x36,0x31,0x35,0x32,0x33,0x34,0x33,0x37,0x35,0x66,0x20, + 0x2a,0x20,0x5f,0x31,0x35,0x31,0x29,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x38,0x29, + 0x20,0x2b,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x2d,0x30,0x2e,0x30,0x34,0x32,0x31, + 0x33,0x39,0x39,0x39,0x39,0x35,0x36,0x38,0x34,0x36,0x32,0x33,0x37,0x31,0x38,0x32, + 0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x5f,0x32,0x35,0x38, + 0x29,0x20,0x2b,0x20,0x28,0x30,0x2e,0x30,0x38,0x39,0x36,0x39,0x39,0x39,0x39,0x38, + 0x34,0x39,0x37,0x39,0x36,0x32,0x39,0x35,0x31,0x36,0x36,0x30,0x31,0x35,0x36,0x32, + 0x35,0x66,0x20,0x2a,0x20,0x5f,0x32,0x35,0x34,0x29,0x29,0x20,0x2d,0x20,0x28,0x30, + 0x2e,0x30,0x34,0x31,0x35,0x32,0x39,0x39,0x39,0x38,0x31,0x38,0x33,0x32,0x35,0x30, + 0x34,0x32,0x37,0x32,0x34,0x36,0x30,0x39,0x33,0x37,0x35,0x66,0x20,0x2a,0x20,0x5f, + 0x31,0x35,0x31,0x29,0x29,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x35,0x31,0x36,0x30, + 0x30,0x30,0x30,0x31,0x37,0x35,0x32,0x33,0x37,0x36,0x35,0x35,0x36,0x33,0x39,0x36, + 0x34,0x38,0x34,0x33,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29, + 0x29,0x20,0x2b,0x20,0x28,0x28,0x28,0x28,0x30,0x2e,0x31,0x35,0x33,0x34,0x35,0x39, + 0x39,0x39,0x35,0x39,0x38,0x35,0x30,0x33,0x31,0x31,0x32,0x37,0x39,0x32,0x39,0x36, + 0x38,0x37,0x35,0x66,0x20,0x2a,0x20,0x5f,0x32,0x35,0x38,0x29,0x20,0x2d,0x20,0x28, + 0x30,0x2e,0x32,0x36,0x37,0x35,0x36,0x30,0x30,0x30,0x35,0x31,0x38,0x37,0x39,0x38, + 0x38,0x32,0x38,0x31,0x32,0x35,0x66,0x20,0x2a,0x20,0x5f,0x32,0x35,0x34,0x29,0x29, + 0x20,0x2b,0x20,0x28,0x30,0x2e,0x30,0x36,0x36,0x36,0x39,0x39,0x39,0x39,0x36,0x35, + 0x39,0x30,0x36,0x31,0x34,0x33,0x31,0x38,0x38,0x34,0x37,0x36,0x35,0x36,0x32,0x35, + 0x66,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31,0x29,0x29,0x20,0x2b,0x20,0x30,0x2e,0x32, + 0x36,0x36,0x38,0x38,0x30,0x30,0x30,0x35,0x35,0x39,0x38,0x30,0x36,0x38,0x32,0x33, + 0x37,0x33,0x30,0x34,0x36,0x38,0x37,0x35,0x66,0x29,0x29,0x20,0x2a,0x20,0x70,0x72, + 0x65,0x65,0x74,0x68,0x61,0x6d,0x50,0x65,0x72,0x65,0x7a,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33,0x29,0x29,0x20,0x2f,0x20,0x6d, + 0x61,0x78,0x28,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x50,0x65,0x72,0x65,0x7a, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x34,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x32,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x34,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, + 0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x35,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x34,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x37,0x29, + 0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38, + 0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37, + 0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x30,0x20,0x3d,0x20, + 0x6d,0x61,0x78,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x34,0x2e,0x30,0x34,0x35,0x33, + 0x30,0x30,0x30,0x30,0x36,0x38,0x36,0x36,0x34,0x35,0x35,0x30,0x37,0x38,0x31,0x32, + 0x35,0x66,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2d,0x20,0x34,0x2e,0x39, + 0x37,0x31,0x30,0x30,0x30,0x31,0x39,0x34,0x35,0x34,0x39,0x35,0x36,0x30,0x35,0x34, + 0x36,0x38,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x74,0x61,0x6e,0x28,0x28,0x30,0x2e, + 0x34,0x34,0x34,0x34,0x34,0x34,0x34,0x34,0x37,0x37,0x35,0x35,0x38,0x31,0x33,0x35, + 0x39,0x38,0x36,0x33,0x32,0x38,0x31,0x32,0x35,0x66,0x20,0x2d,0x20,0x28,0x5f,0x31, + 0x35,0x34,0x20,0x2a,0x20,0x30,0x2e,0x30,0x30,0x38,0x33,0x33,0x33,0x33,0x33,0x33, + 0x37,0x36,0x37,0x39,0x35,0x30,0x35,0x33,0x34,0x38,0x32,0x30,0x35,0x35,0x36,0x36, + 0x34,0x30,0x36,0x32,0x35,0x66,0x29,0x29,0x20,0x2a,0x20,0x28,0x33,0x2e,0x31,0x34, + 0x31,0x35,0x39,0x32,0x37,0x34,0x31,0x30,0x31,0x32,0x35,0x37,0x33,0x32,0x34,0x32, + 0x31,0x38,0x37,0x35,0x66,0x20,0x2d,0x20,0x28,0x32,0x2e,0x30,0x66,0x20,0x2a,0x20, + 0x5f,0x31,0x35,0x31,0x29,0x29,0x29,0x29,0x20,0x2d,0x20,0x28,0x30,0x2e,0x32,0x31, + 0x35,0x34,0x39,0x39,0x39,0x39,0x37,0x31,0x33,0x38,0x39,0x37,0x37,0x30,0x35,0x30, + 0x37,0x38,0x31,0x32,0x35,0x66,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x29,0x20, + 0x2b,0x20,0x32,0x2e,0x34,0x31,0x39,0x31,0x39,0x39,0x39,0x34,0x33,0x35,0x34,0x32, + 0x34,0x38,0x30,0x34,0x36,0x38,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x70,0x72,0x65, + 0x65,0x74,0x68,0x61,0x6d,0x50,0x65,0x72,0x65,0x7a,0x28,0x70,0x61,0x72,0x61,0x6d, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x29, + 0x29,0x20,0x2f,0x20,0x6d,0x61,0x78,0x28,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d, + 0x50,0x65,0x72,0x65,0x7a,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x39, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x30,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x33,0x31,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37, + 0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35, + 0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x66,0x29,0x2c,0x20, + 0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x31,0x20,0x3d,0x20,0x70,0x72,0x65, + 0x65,0x74,0x68,0x61,0x6d,0x58,0x79,0x59,0x5f,0x74,0x6f,0x5f,0x58,0x59,0x5a,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x34,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6d,0x61,0x78,0x28,0x70,0x72, + 0x65,0x65,0x74,0x68,0x61,0x6d,0x58,0x59,0x5a,0x5f,0x74,0x6f,0x5f,0x6c,0x69,0x6e, + 0x65,0x61,0x72,0x5f,0x73,0x72,0x67,0x62,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35, + 0x31,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x29,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61, + 0x6d,0x53,0x6b,0x79,0x53,0x63,0x61,0x6c,0x65,0x64,0x28,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x76,0x69,0x65,0x77,0x5f,0x64,0x69,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x74,0x75,0x72,0x62,0x69,0x64,0x69,0x74,0x79,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x66,0x61,0x64,0x65,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x76,0x69, + 0x65,0x77,0x5f,0x64,0x69,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x73,0x75,0x6e, + 0x5f,0x64,0x69,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x74,0x75,0x72,0x62,0x69,0x64, + 0x69,0x74,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x28,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x53,0x6b,0x79,0x28,0x70,0x61,0x72, + 0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x29,0x20,0x2a,0x20,0x30,0x2e,0x30,0x35,0x39,0x39,0x39,0x39, + 0x39,0x39,0x38,0x36,0x35,0x38,0x38,0x39,0x35,0x34,0x39,0x32,0x35,0x35,0x33,0x37, + 0x31,0x30,0x39,0x33,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x66,0x61,0x64,0x65,0x3b, + 0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61, + 0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c, + 0x69,0x7a,0x65,0x28,0x28,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x68,0x6f,0x6d, + 0x6f,0x67,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x5f,0x68,0x6f,0x6d,0x6f,0x67,0x2e,0x77,0x2e,0x78,0x78,0x78,0x29,0x20,0x2d,0x20, + 0x5f,0x35,0x34,0x39,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e, + 0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x69,0x7a,0x65,0x28,0x5f,0x35,0x34,0x39,0x5f,0x73,0x75,0x6e,0x5f,0x64,0x69, + 0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20, + 0x3d,0x20,0x5f,0x35,0x34,0x39,0x5f,0x73,0x6b,0x79,0x5f,0x70,0x61,0x72,0x61,0x6d, + 0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x35,0x34,0x39,0x5f,0x73,0x75, + 0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x77,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x53,0x6b, + 0x79,0x53,0x63,0x61,0x6c,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x29,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73, + 0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49, + 0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73, + 0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x68,0x6f,0x6d,0x6f,0x67,0x20, + 0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x68,0x6f,0x6d,0x6f,0x67,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75, + 0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75, + 0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74, + 0x70,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20, + 0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70, + 0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + struct sky_ub_frame + { + float4x4 inv_view_proj; + }; + + struct main0_out + { + float4 v_world_homog [[user(locn0)]]; + float4 gl_Position [[position]]; + }; + + vertex main0_out main0(constant sky_ub_frame& _50 [[buffer(0)]], uint gl_VertexIndex [[vertex_id]]) + { + main0_out out = {}; + float4 _35 = float4((float2(float((int(gl_VertexIndex) << 1) & 2), float(int(gl_VertexIndex) & 2)) * 2.0) - float2(1.0), 0.0, 1.0); + out.gl_Position = _35; + out.v_world_homog = _50.inv_view_proj * _35; + return out; + } + +*/ +static const uint8_t vs_source_metal_macos[586] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x73, + 0x6b,0x79,0x5f,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x69,0x6e,0x76,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x68,0x6f,0x6d,0x6f,0x67,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72, + 0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f, + 0x6e,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x3b,0x0a, + 0x7d,0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,0x65,0x78,0x20,0x6d,0x61,0x69,0x6e,0x30, + 0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x63,0x6f,0x6e,0x73,0x74, + 0x61,0x6e,0x74,0x20,0x73,0x6b,0x79,0x5f,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65, + 0x26,0x20,0x5f,0x35,0x30,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x30, + 0x29,0x5d,0x5d,0x2c,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x56,0x65,0x72, + 0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x5b,0x5b,0x76,0x65,0x72,0x74,0x65, + 0x78,0x5f,0x69,0x64,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61, + 0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x33,0x35, + 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x66,0x6c,0x6f,0x61,0x74, + 0x32,0x28,0x66,0x6c,0x6f,0x61,0x74,0x28,0x28,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f, + 0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x3c,0x3c,0x20, + 0x31,0x29,0x20,0x26,0x20,0x32,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x69, + 0x6e,0x74,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65, + 0x78,0x29,0x20,0x26,0x20,0x32,0x29,0x29,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x20, + 0x2d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x31,0x2e,0x30,0x29,0x2c,0x20,0x30, + 0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75, + 0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x5f,0x33,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x5f,0x68,0x6f,0x6d,0x6f,0x67,0x20,0x3d,0x20,0x5f,0x35,0x30, + 0x2e,0x69,0x6e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x2a, + 0x20,0x5f,0x33,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + #pragma clang diagnostic ignored "-Wmissing-prototypes" + + #include + #include + + using namespace metal; + + struct sky_ub_pass + { + float4 sun_dir_world; + float4 sky_params; + float4 camera_pos; + }; + + struct main0_out + { + float4 out_color [[color(0)]]; + }; + + struct main0_in + { + float4 v_world_homog [[user(locn0)]]; + }; + + static inline __attribute__((always_inline)) + float preethamPerez(thread const float& cos_theta, thread const float& cos_gamma, thread const float& gamma, thread const float& A, thread const float& B, thread const float& C, thread const float& D, thread const float& E) + { + return (1.0 + (A * exp(B / fast::max(cos_theta, 0.00999999977648258209228515625)))) * ((1.0 + (C * exp(D * gamma))) + ((E * cos_gamma) * cos_gamma)); + } + + static inline __attribute__((always_inline)) + float3 preethamXyY_to_XYZ(thread const float& x, thread const float& y, thread const float& Y) + { + float _77 = fast::max(y, 9.9999997473787516355514526367188e-06); + return float3((Y * x) / _77, Y, (Y * ((1.0 - x) - y)) / _77); + } + + static inline __attribute__((always_inline)) + float3 preethamXYZ_to_linear_srgb(thread const float3& c) + { + return float3(dot(c, float3(3.240454196929931640625, -1.537138462066650390625, -0.498531401157379150390625)), dot(c, float3(-0.969265997409820556640625, 1.87601077556610107421875, 0.04155600070953369140625)), dot(c, float3(0.0556433983147144317626953125, -0.2040258944034576416015625, 1.05722522735595703125))); + } + + static inline __attribute__((always_inline)) + float3 preethamSky(thread const float3& view_dir, thread const float3& sun_dir, thread const float& turbidity) + { + float _122 = fast::clamp(sun_dir.y, 0.0, 1.0); + float3 _135 = fast::normalize(float3(view_dir.x, fast::max(view_dir.y, 0.0) + 0.00999999977648258209228515625, view_dir.z)); + float _139 = fast::max(_135.y, 0.0); + float _145 = fast::clamp(dot(sun_dir, _135), -1.0, 1.0); + float _148 = acos(_145); + float _151 = acos(_122); + float _154 = fast::max(turbidity, 1.0); + float _158 = _154 * _154; + float _164 = (0.1787000000476837158203125 * _154) - 1.4630000591278076171875; + float _170 = ((-0.3553999960422515869140625) * _154) + 0.4275000095367431640625; + float _176 = ((-0.0227000005543231964111328125) * _154) + 5.325099945068359375; + float _182 = (0.12060000002384185791015625 * _154) - 2.5771000385284423828125; + float _188 = ((-0.0670000016689300537109375) * _154) + 0.370299994945526123046875; + float _194 = ((-0.01930000074207782745361328125) * _154) - 0.2592000067234039306640625; + float _200 = ((-0.066500000655651092529296875) * _154) + 0.0007999999797903001308441162109375; + float _206 = ((-0.00039999998989515006542205810546875) * _154) + 0.2125000059604644775390625; + float _212 = ((-0.0640999972820281982421875) * _154) - 0.898899972438812255859375; + float _218 = ((-0.0032999999821186065673828125) * _154) + 0.0452000014483928680419921875; + float _224 = ((-0.0166999995708465576171875) * _154) - 0.26080000400543212890625; + float _230 = ((-0.0949999988079071044921875) * _154) + 0.009200000204145908355712890625; + float _236 = ((-0.0078999996185302734375) * _154) + 0.21019999682903289794921875; + float _242 = ((-0.04410000145435333251953125) * _154) - 1.65369999408721923828125; + float _248 = ((-0.01090000011026859283447265625) * _154) + 0.05290000140666961669921875; + float _254 = _151 * _151; + float _258 = _254 * _151; + float param = _139; + float param_1 = _145; + float param_2 = _148; + float param_3 = _164; + float param_4 = _170; + float param_5 = _176; + float param_6 = _182; + float param_7 = _188; + float param_8 = _139; + float param_9 = _145; + float param_10 = _148; + float param_11 = _194; + float param_12 = _200; + float param_13 = _206; + float param_14 = _212; + float param_15 = _218; + float param_16 = _139; + float param_17 = _145; + float param_18 = _148; + float param_19 = _224; + float param_20 = _230; + float param_21 = _236; + float param_22 = _242; + float param_23 = _248; + float param_24 = 1.0; + float param_25 = _122; + float param_26 = _151; + float param_27 = _164; + float param_28 = _170; + float param_29 = _176; + float param_30 = _182; + float param_31 = _188; + float param_32 = 1.0; + float param_33 = _122; + float param_34 = _151; + float param_35 = _194; + float param_36 = _200; + float param_37 = _206; + float param_38 = _212; + float param_39 = _218; + float param_40 = 1.0; + float param_41 = _122; + float param_42 = _151; + float param_43 = _224; + float param_44 = _230; + float param_45 = _236; + float param_46 = _242; + float param_47 = _248; + float param_48 = (((((((0.001659999950788915157318115234375 * _258) - (0.00374999991618096828460693359375 * _254)) + (0.0020900000818073749542236328125 * _151)) * _158) + ((((((-0.02903000079095363616943359375) * _258) + (0.063770003616809844970703125 * _254)) - (0.0320199988782405853271484375 * _151)) + 0.003940000198781490325927734375) * _154)) + ((((0.116930000483989715576171875 * _258) - (0.21196000277996063232421875 * _254)) + (0.060520000755786895751953125 * _151)) + 0.25885999202728271484375)) * preethamPerez(param_8, param_9, param_10, param_11, param_12, param_13, param_14, param_15)) / fast::max(preethamPerez(param_32, param_33, param_34, param_35, param_36, param_37, param_38, param_39), 9.9999997473787516355514526367188e-06); + float param_49 = (((((((0.00274999998509883880615234375 * _258) - (0.006099999882280826568603515625 * _254)) + (0.0031699999235570430755615234375 * _151)) * _158) + ((((((-0.042139999568462371826171875) * _258) + (0.08969999849796295166015625 * _254)) - (0.04152999818325042724609375 * _151)) + 0.0051600001752376556396484375) * _154)) + ((((0.1534599959850311279296875 * _258) - (0.26756000518798828125 * _254)) + (0.06669999659061431884765625 * _151)) + 0.2668800055980682373046875)) * preethamPerez(param_16, param_17, param_18, param_19, param_20, param_21, param_22, param_23)) / fast::max(preethamPerez(param_40, param_41, param_42, param_43, param_44, param_45, param_46, param_47), 9.9999997473787516355514526367188e-06); + float param_50 = fast::max(((((((4.045300006866455078125 * _154) - 4.971000194549560546875) * tan((0.4444444477558135986328125 - (_154 * 0.008333333767950534820556640625)) * (3.1415927410125732421875 - (2.0 * _151)))) - (0.21549999713897705078125 * _154)) + 2.41919994354248046875) * preethamPerez(param, param_1, param_2, param_3, param_4, param_5, param_6, param_7)) / fast::max(preethamPerez(param_24, param_25, param_26, param_27, param_28, param_29, param_30, param_31), 9.9999997473787516355514526367188e-06), 0.0); + float3 param_51 = preethamXyY_to_XYZ(param_48, param_49, param_50); + return fast::max(preethamXYZ_to_linear_srgb(param_51), float3(0.0)); + } + + static inline __attribute__((always_inline)) + float3 preethamSkyScaled(thread const float3& view_dir, thread const float3& sun_dir, thread const float& turbidity, thread const float& fade) + { + float3 param = view_dir; + float3 param_1 = sun_dir; + float param_2 = turbidity; + return (preethamSky(param, param_1, param_2) * 0.0599999986588954925537109375) * fade; + } + + fragment main0_out main0(main0_in in [[stage_in]], constant sky_ub_pass& _549 [[buffer(1)]]) + { + main0_out out = {}; + float3 param = fast::normalize((in.v_world_homog.xyz / float3(in.v_world_homog.w)) - _549.camera_pos.xyz); + float3 param_1 = fast::normalize(_549.sun_dir_world.xyz); + float param_2 = _549.sky_params.x; + float param_3 = _549.sun_dir_world.w; + out.out_color = float4(preethamSkyScaled(param, param_1, param_2, param_3), 1.0); + return out; + } + +*/ +static const uint8_t fs_source_metal_macos[7742] = { + 0x23,0x70,0x72,0x61,0x67,0x6d,0x61,0x20,0x63,0x6c,0x61,0x6e,0x67,0x20,0x64,0x69, + 0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x20,0x69,0x67,0x6e,0x6f,0x72,0x65,0x64, + 0x20,0x22,0x2d,0x57,0x6d,0x69,0x73,0x73,0x69,0x6e,0x67,0x2d,0x70,0x72,0x6f,0x74, + 0x6f,0x74,0x79,0x70,0x65,0x73,0x22,0x0a,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64, + 0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f,0x73,0x74,0x64,0x6c,0x69,0x62,0x3e, + 0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f, + 0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a,0x75,0x73,0x69,0x6e,0x67,0x20,0x6e, + 0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20,0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a, + 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x73,0x6b,0x79,0x5f,0x75,0x62,0x5f,0x70, + 0x61,0x73,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x6b,0x79,0x5f,0x70, + 0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f, + 0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x63,0x6f,0x6c,0x6f, + 0x72,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75, + 0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x5f,0x68,0x6f,0x6d,0x6f,0x67,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f, + 0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74, + 0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72, + 0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f, + 0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x50,0x65,0x72,0x65,0x7a,0x28,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26, + 0x20,0x63,0x6f,0x73,0x5f,0x74,0x68,0x65,0x74,0x61,0x2c,0x20,0x74,0x68,0x72,0x65, + 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20, + 0x63,0x6f,0x73,0x5f,0x67,0x61,0x6d,0x6d,0x61,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x67, + 0x61,0x6d,0x6d,0x61,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x41,0x2c,0x20,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26, + 0x20,0x42,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x43,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x44, + 0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x26,0x20,0x45,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x31,0x2e,0x30,0x20,0x2b,0x20,0x28,0x41,0x20, + 0x2a,0x20,0x65,0x78,0x70,0x28,0x42,0x20,0x2f,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a, + 0x6d,0x61,0x78,0x28,0x63,0x6f,0x73,0x5f,0x74,0x68,0x65,0x74,0x61,0x2c,0x20,0x30, + 0x2e,0x30,0x30,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x37,0x36,0x34,0x38,0x32, + 0x35,0x38,0x32,0x30,0x39,0x32,0x32,0x38,0x35,0x31,0x35,0x36,0x32,0x35,0x29,0x29, + 0x29,0x29,0x20,0x2a,0x20,0x28,0x28,0x31,0x2e,0x30,0x20,0x2b,0x20,0x28,0x43,0x20, + 0x2a,0x20,0x65,0x78,0x70,0x28,0x44,0x20,0x2a,0x20,0x67,0x61,0x6d,0x6d,0x61,0x29, + 0x29,0x29,0x20,0x2b,0x20,0x28,0x28,0x45,0x20,0x2a,0x20,0x63,0x6f,0x73,0x5f,0x67, + 0x61,0x6d,0x6d,0x61,0x29,0x20,0x2a,0x20,0x63,0x6f,0x73,0x5f,0x67,0x61,0x6d,0x6d, + 0x61,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69, + 0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74, + 0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69, + 0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x72,0x65,0x65, + 0x74,0x68,0x61,0x6d,0x58,0x79,0x59,0x5f,0x74,0x6f,0x5f,0x58,0x59,0x5a,0x28,0x74, + 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x26,0x20,0x78,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x79,0x2c,0x20,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26, + 0x20,0x59,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x37,0x37,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28, + 0x79,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37, + 0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36, + 0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x59,0x20, + 0x2a,0x20,0x78,0x29,0x20,0x2f,0x20,0x5f,0x37,0x37,0x2c,0x20,0x59,0x2c,0x20,0x28, + 0x59,0x20,0x2a,0x20,0x28,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x78,0x29,0x20,0x2d, + 0x20,0x79,0x29,0x29,0x20,0x2f,0x20,0x5f,0x37,0x37,0x29,0x3b,0x0a,0x7d,0x0a,0x0a, + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f, + 0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77, + 0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x58,0x59,0x5a,0x5f, + 0x74,0x6f,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x73,0x72,0x67,0x62,0x28,0x74, + 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x26,0x20,0x63,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x64,0x6f,0x74,0x28,0x63, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x33,0x2e,0x32,0x34,0x30,0x34,0x35, + 0x34,0x31,0x39,0x36,0x39,0x32,0x39,0x39,0x33,0x31,0x36,0x34,0x30,0x36,0x32,0x35, + 0x2c,0x20,0x2d,0x31,0x2e,0x35,0x33,0x37,0x31,0x33,0x38,0x34,0x36,0x32,0x30,0x36, + 0x36,0x36,0x35,0x30,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x2d,0x30,0x2e,0x34, + 0x39,0x38,0x35,0x33,0x31,0x34,0x30,0x31,0x31,0x35,0x37,0x33,0x37,0x39,0x31,0x35, + 0x30,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x63, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x2d,0x30,0x2e,0x39,0x36,0x39,0x32, + 0x36,0x35,0x39,0x39,0x37,0x34,0x30,0x39,0x38,0x32,0x30,0x35,0x35,0x36,0x36,0x34, + 0x30,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e,0x38,0x37,0x36,0x30,0x31,0x30,0x37,0x37, + 0x35,0x35,0x36,0x36,0x31,0x30,0x31,0x30,0x37,0x34,0x32,0x31,0x38,0x37,0x35,0x2c, + 0x20,0x30,0x2e,0x30,0x34,0x31,0x35,0x35,0x36,0x30,0x30,0x30,0x37,0x30,0x39,0x35, + 0x33,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x29,0x2c,0x20,0x64,0x6f, + 0x74,0x28,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x35, + 0x35,0x36,0x34,0x33,0x33,0x39,0x38,0x33,0x31,0x34,0x37,0x31,0x34,0x34,0x33,0x31, + 0x37,0x36,0x32,0x36,0x39,0x35,0x33,0x31,0x32,0x35,0x2c,0x20,0x2d,0x30,0x2e,0x32, + 0x30,0x34,0x30,0x32,0x35,0x38,0x39,0x34,0x34,0x30,0x33,0x34,0x35,0x37,0x36,0x34, + 0x31,0x36,0x30,0x31,0x35,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30,0x35,0x37,0x32, + 0x32,0x35,0x32,0x32,0x37,0x33,0x35,0x35,0x39,0x35,0x37,0x30,0x33,0x31,0x32,0x35, + 0x29,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69, + 0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74, + 0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69, + 0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x72,0x65,0x65, + 0x74,0x68,0x61,0x6d,0x53,0x6b,0x79,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x76,0x69,0x65, + 0x77,0x5f,0x64,0x69,0x72,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x73,0x75,0x6e,0x5f, + 0x64,0x69,0x72,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x74,0x75,0x72,0x62,0x69,0x64,0x69, + 0x74,0x79,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x32,0x32,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61, + 0x6d,0x70,0x28,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x2e,0x79,0x2c,0x20,0x30,0x2e, + 0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x5f,0x31,0x33,0x35,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a, + 0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x28,0x76,0x69,0x65,0x77,0x5f,0x64,0x69,0x72,0x2e,0x78,0x2c,0x20,0x66,0x61, + 0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x76,0x69,0x65,0x77,0x5f,0x64,0x69,0x72, + 0x2e,0x79,0x2c,0x20,0x30,0x2e,0x30,0x29,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x39, + 0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x37,0x36,0x34,0x38,0x32,0x35,0x38,0x32,0x30, + 0x39,0x32,0x32,0x38,0x35,0x31,0x35,0x36,0x32,0x35,0x2c,0x20,0x76,0x69,0x65,0x77, + 0x5f,0x64,0x69,0x72,0x2e,0x7a,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x39,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a, + 0x3a,0x6d,0x61,0x78,0x28,0x5f,0x31,0x33,0x35,0x2e,0x79,0x2c,0x20,0x30,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34, + 0x35,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28, + 0x64,0x6f,0x74,0x28,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x2c,0x20,0x5f,0x31,0x33, + 0x35,0x29,0x2c,0x20,0x2d,0x31,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x38,0x20,0x3d, + 0x20,0x61,0x63,0x6f,0x73,0x28,0x5f,0x31,0x34,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x31,0x20,0x3d,0x20,0x61,0x63, + 0x6f,0x73,0x28,0x5f,0x31,0x32,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x34,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a, + 0x3a,0x6d,0x61,0x78,0x28,0x74,0x75,0x72,0x62,0x69,0x64,0x69,0x74,0x79,0x2c,0x20, + 0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x35,0x38,0x20,0x3d,0x20,0x5f,0x31,0x35,0x34,0x20,0x2a,0x20,0x5f,0x31, + 0x35,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x36,0x34,0x20,0x3d,0x20,0x28,0x30,0x2e,0x31,0x37,0x38,0x37,0x30,0x30,0x30,0x30, + 0x30,0x30,0x34,0x37,0x36,0x38,0x33,0x37,0x31,0x35,0x38,0x32,0x30,0x33,0x31,0x32, + 0x35,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2d,0x20,0x31,0x2e,0x34,0x36, + 0x33,0x30,0x30,0x30,0x30,0x35,0x39,0x31,0x32,0x37,0x38,0x30,0x37,0x36,0x31,0x37, + 0x31,0x38,0x37,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x37,0x30,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x33,0x35,0x35,0x33, + 0x39,0x39,0x39,0x39,0x36,0x30,0x34,0x32,0x32,0x35,0x31,0x35,0x38,0x36,0x39,0x31, + 0x34,0x30,0x36,0x32,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2b, + 0x20,0x30,0x2e,0x34,0x32,0x37,0x35,0x30,0x30,0x30,0x30,0x39,0x35,0x33,0x36,0x37, + 0x34,0x33,0x31,0x36,0x34,0x30,0x36,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x37,0x36,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30, + 0x2e,0x30,0x32,0x32,0x37,0x30,0x30,0x30,0x30,0x30,0x35,0x35,0x34,0x33,0x32,0x33, + 0x31,0x39,0x36,0x34,0x31,0x31,0x31,0x33,0x32,0x38,0x31,0x32,0x35,0x29,0x20,0x2a, + 0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2b,0x20,0x35,0x2e,0x33,0x32,0x35,0x30,0x39, + 0x39,0x39,0x34,0x35,0x30,0x36,0x38,0x33,0x35,0x39,0x33,0x37,0x35,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x38,0x32,0x20,0x3d,0x20, + 0x28,0x30,0x2e,0x31,0x32,0x30,0x36,0x30,0x30,0x30,0x30,0x30,0x30,0x32,0x33,0x38, + 0x34,0x31,0x38,0x35,0x37,0x39,0x31,0x30,0x31,0x35,0x36,0x32,0x35,0x20,0x2a,0x20, + 0x5f,0x31,0x35,0x34,0x29,0x20,0x2d,0x20,0x32,0x2e,0x35,0x37,0x37,0x31,0x30,0x30, + 0x30,0x33,0x38,0x35,0x32,0x38,0x34,0x34,0x32,0x33,0x38,0x32,0x38,0x31,0x32,0x35, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x38,0x38, + 0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x36,0x37,0x30,0x30,0x30,0x30,0x30, + 0x31,0x36,0x36,0x38,0x39,0x33,0x30,0x30,0x35,0x33,0x37,0x31,0x30,0x39,0x33,0x37, + 0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2b,0x20,0x30,0x2e,0x33, + 0x37,0x30,0x32,0x39,0x39,0x39,0x39,0x34,0x39,0x34,0x35,0x35,0x32,0x36,0x31,0x32, + 0x33,0x30,0x34,0x36,0x38,0x37,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x39,0x34,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30, + 0x31,0x39,0x33,0x30,0x30,0x30,0x30,0x30,0x37,0x34,0x32,0x30,0x37,0x37,0x38,0x32, + 0x37,0x34,0x35,0x33,0x36,0x31,0x33,0x32,0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20, + 0x5f,0x31,0x35,0x34,0x29,0x20,0x2d,0x20,0x30,0x2e,0x32,0x35,0x39,0x32,0x30,0x30, + 0x30,0x30,0x36,0x37,0x32,0x33,0x34,0x30,0x33,0x39,0x33,0x30,0x36,0x36,0x34,0x30, + 0x36,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x32,0x30,0x30,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x36,0x36,0x35,0x30, + 0x30,0x30,0x30,0x30,0x36,0x35,0x35,0x36,0x35,0x31,0x30,0x39,0x32,0x35,0x32,0x39, + 0x32,0x39,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20, + 0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x37,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x39, + 0x37,0x39,0x30,0x33,0x30,0x30,0x31,0x33,0x30,0x38,0x34,0x34,0x31,0x31,0x36,0x32, + 0x31,0x30,0x39,0x33,0x37,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x32,0x30,0x36,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x30, + 0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x38,0x39,0x38,0x39,0x35,0x31,0x35,0x30, + 0x30,0x36,0x35,0x34,0x32,0x32,0x30,0x35,0x38,0x31,0x30,0x35,0x34,0x36,0x38,0x37, + 0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2b,0x20,0x30,0x2e,0x32, + 0x31,0x32,0x35,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37, + 0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x32,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e, + 0x30,0x36,0x34,0x30,0x39,0x39,0x39,0x39,0x37,0x32,0x38,0x32,0x30,0x32,0x38,0x31, + 0x39,0x38,0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35, + 0x34,0x29,0x20,0x2d,0x20,0x30,0x2e,0x38,0x39,0x38,0x38,0x39,0x39,0x39,0x37,0x32, + 0x34,0x33,0x38,0x38,0x31,0x32,0x32,0x35,0x35,0x38,0x35,0x39,0x33,0x37,0x35,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x38,0x20, + 0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x30,0x33,0x32,0x39,0x39,0x39,0x39,0x39, + 0x39,0x38,0x32,0x31,0x31,0x38,0x36,0x30,0x36,0x35,0x36,0x37,0x33,0x38,0x32,0x38, + 0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2b,0x20,0x30, + 0x2e,0x30,0x34,0x35,0x32,0x30,0x30,0x30,0x30,0x31,0x34,0x34,0x38,0x33,0x39,0x32, + 0x38,0x36,0x38,0x30,0x34,0x31,0x39,0x39,0x32,0x31,0x38,0x37,0x35,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x32,0x34,0x20,0x3d,0x20, + 0x28,0x28,0x2d,0x30,0x2e,0x30,0x31,0x36,0x36,0x39,0x39,0x39,0x39,0x39,0x35,0x37, + 0x30,0x38,0x34,0x36,0x35,0x35,0x37,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x29,0x20, + 0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2d,0x20,0x30,0x2e,0x32,0x36,0x30,0x38, + 0x30,0x30,0x30,0x30,0x34,0x30,0x30,0x35,0x34,0x33,0x32,0x31,0x32,0x38,0x39,0x30, + 0x36,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x32,0x33,0x30,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x39,0x34,0x39,0x39, + 0x39,0x39,0x39,0x38,0x38,0x30,0x37,0x39,0x30,0x37,0x31,0x30,0x34,0x34,0x39,0x32, + 0x31,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2b,0x20, + 0x30,0x2e,0x30,0x30,0x39,0x32,0x30,0x30,0x30,0x30,0x30,0x32,0x30,0x34,0x31,0x34, + 0x35,0x39,0x30,0x38,0x33,0x35,0x35,0x37,0x31,0x32,0x38,0x39,0x30,0x36,0x32,0x35, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x33,0x36, + 0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x30,0x37,0x38,0x39,0x39,0x39,0x39, + 0x39,0x36,0x31,0x38,0x35,0x33,0x30,0x32,0x37,0x33,0x34,0x33,0x37,0x35,0x29,0x20, + 0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2b,0x20,0x30,0x2e,0x32,0x31,0x30,0x31, + 0x39,0x39,0x39,0x39,0x36,0x38,0x32,0x39,0x30,0x33,0x32,0x38,0x39,0x37,0x39,0x34, + 0x39,0x32,0x31,0x38,0x37,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x32,0x34,0x32,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x34, + 0x34,0x31,0x30,0x30,0x30,0x30,0x31,0x34,0x35,0x34,0x33,0x35,0x33,0x33,0x33,0x32, + 0x35,0x31,0x39,0x35,0x33,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34, + 0x29,0x20,0x2d,0x20,0x31,0x2e,0x36,0x35,0x33,0x36,0x39,0x39,0x39,0x39,0x34,0x30, + 0x38,0x37,0x32,0x31,0x39,0x32,0x33,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x34,0x38,0x20,0x3d,0x20, + 0x28,0x28,0x2d,0x30,0x2e,0x30,0x31,0x30,0x39,0x30,0x30,0x30,0x30,0x30,0x31,0x31, + 0x30,0x32,0x36,0x38,0x35,0x39,0x32,0x38,0x33,0x34,0x34,0x37,0x32,0x36,0x35,0x36, + 0x32,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2b,0x20,0x30,0x2e, + 0x30,0x35,0x32,0x39,0x30,0x30,0x30,0x30,0x31,0x34,0x30,0x36,0x36,0x36,0x39,0x36, + 0x31,0x36,0x36,0x39,0x39,0x32,0x31,0x38,0x37,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x35,0x34,0x20,0x3d,0x20,0x5f,0x31,0x35, + 0x31,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x32,0x35,0x38,0x20,0x3d,0x20,0x5f,0x32,0x35,0x34,0x20, + 0x2a,0x20,0x5f,0x31,0x35,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f,0x31,0x33,0x39,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x20,0x3d,0x20,0x5f,0x31,0x34,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x31, + 0x34,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31,0x36,0x34,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20, + 0x3d,0x20,0x5f,0x31,0x37,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x5f,0x31,0x37,0x36, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f,0x31,0x38,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20, + 0x5f,0x31,0x38,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x5f,0x31,0x33,0x39,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x39,0x20,0x3d,0x20,0x5f,0x31,0x34,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x5f, + 0x31,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x5f,0x31,0x39,0x34,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x32,0x20,0x3d,0x20,0x5f,0x32,0x30,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20, + 0x5f,0x32,0x30,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x5f,0x32,0x31,0x32,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x35,0x20,0x3d,0x20,0x5f,0x32,0x31,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d, + 0x20,0x5f,0x31,0x33,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x20,0x3d,0x20,0x5f,0x31,0x34,0x35, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x5f,0x31,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x20, + 0x3d,0x20,0x5f,0x32,0x32,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x20,0x3d,0x20,0x5f,0x32,0x33, + 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x31,0x20,0x3d,0x20,0x5f,0x32,0x33,0x36,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32, + 0x20,0x3d,0x20,0x5f,0x32,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33,0x20,0x3d,0x20,0x5f,0x32, + 0x34,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x34,0x20,0x3d,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x35, + 0x20,0x3d,0x20,0x5f,0x31,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x36,0x20,0x3d,0x20,0x5f,0x31, + 0x35,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x37,0x20,0x3d,0x20,0x5f,0x31,0x36,0x34,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x38,0x20,0x3d,0x20,0x5f,0x31,0x37,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x39,0x20,0x3d,0x20,0x5f, + 0x31,0x37,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x33,0x30,0x20,0x3d,0x20,0x5f,0x31,0x38,0x32,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x31,0x20,0x3d,0x20,0x5f,0x31,0x38,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x32,0x20,0x3d,0x20, + 0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x33,0x33,0x20,0x3d,0x20,0x5f,0x31,0x32,0x32,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x34,0x20,0x3d,0x20,0x5f,0x31,0x35,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x35,0x20,0x3d,0x20, + 0x5f,0x31,0x39,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x36,0x20,0x3d,0x20,0x5f,0x32,0x30,0x30,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x33,0x37,0x20,0x3d,0x20,0x5f,0x32,0x30,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x38,0x20,0x3d, + 0x20,0x5f,0x32,0x31,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x39,0x20,0x3d,0x20,0x5f,0x32,0x31,0x38, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x34,0x30,0x20,0x3d,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x31,0x20,0x3d, + 0x20,0x5f,0x31,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x32,0x20,0x3d,0x20,0x5f,0x31,0x35,0x31, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x34,0x33,0x20,0x3d,0x20,0x5f,0x32,0x32,0x34,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x34,0x20, + 0x3d,0x20,0x5f,0x32,0x33,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x35,0x20,0x3d,0x20,0x5f,0x32,0x33, + 0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x34,0x36,0x20,0x3d,0x20,0x5f,0x32,0x34,0x32,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x37, + 0x20,0x3d,0x20,0x5f,0x32,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x38,0x20,0x3d,0x20,0x28,0x28, + 0x28,0x28,0x28,0x28,0x28,0x30,0x2e,0x30,0x30,0x31,0x36,0x35,0x39,0x39,0x39,0x39, + 0x39,0x35,0x30,0x37,0x38,0x38,0x39,0x31,0x35,0x31,0x35,0x37,0x33,0x31,0x38,0x31, + 0x31,0x35,0x32,0x33,0x34,0x33,0x37,0x35,0x20,0x2a,0x20,0x5f,0x32,0x35,0x38,0x29, + 0x20,0x2d,0x20,0x28,0x30,0x2e,0x30,0x30,0x33,0x37,0x34,0x39,0x39,0x39,0x39,0x39, + 0x31,0x36,0x31,0x38,0x30,0x39,0x36,0x38,0x32,0x38,0x34,0x36,0x30,0x36,0x39,0x33, + 0x33,0x35,0x39,0x33,0x37,0x35,0x20,0x2a,0x20,0x5f,0x32,0x35,0x34,0x29,0x29,0x20, + 0x2b,0x20,0x28,0x30,0x2e,0x30,0x30,0x32,0x30,0x39,0x30,0x30,0x30,0x30,0x30,0x38, + 0x31,0x38,0x30,0x37,0x33,0x37,0x34,0x39,0x35,0x34,0x32,0x32,0x33,0x36,0x33,0x32, + 0x38,0x31,0x32,0x35,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31,0x29,0x29,0x20,0x2a,0x20, + 0x5f,0x31,0x35,0x38,0x29,0x20,0x2b,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x2d,0x30, + 0x2e,0x30,0x32,0x39,0x30,0x33,0x30,0x30,0x30,0x30,0x37,0x39,0x30,0x39,0x35,0x33, + 0x36,0x33,0x36,0x31,0x36,0x39,0x34,0x33,0x33,0x35,0x39,0x33,0x37,0x35,0x29,0x20, + 0x2a,0x20,0x5f,0x32,0x35,0x38,0x29,0x20,0x2b,0x20,0x28,0x30,0x2e,0x30,0x36,0x33, + 0x37,0x37,0x30,0x30,0x30,0x33,0x36,0x31,0x36,0x38,0x30,0x39,0x38,0x34,0x34,0x39, + 0x37,0x30,0x37,0x30,0x33,0x31,0x32,0x35,0x20,0x2a,0x20,0x5f,0x32,0x35,0x34,0x29, + 0x29,0x20,0x2d,0x20,0x28,0x30,0x2e,0x30,0x33,0x32,0x30,0x31,0x39,0x39,0x39,0x38, + 0x38,0x37,0x38,0x32,0x34,0x30,0x35,0x38,0x35,0x33,0x32,0x37,0x31,0x34,0x38,0x34, + 0x33,0x37,0x35,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31,0x29,0x29,0x20,0x2b,0x20,0x30, + 0x2e,0x30,0x30,0x33,0x39,0x34,0x30,0x30,0x30,0x30,0x31,0x39,0x38,0x37,0x38,0x31, + 0x34,0x39,0x30,0x33,0x32,0x35,0x39,0x32,0x37,0x37,0x33,0x34,0x33,0x37,0x35,0x29, + 0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x29,0x20,0x2b,0x20,0x28,0x28,0x28,0x28, + 0x30,0x2e,0x31,0x31,0x36,0x39,0x33,0x30,0x30,0x30,0x30,0x34,0x38,0x33,0x39,0x38, + 0x39,0x37,0x31,0x35,0x35,0x37,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x20,0x2a,0x20, + 0x5f,0x32,0x35,0x38,0x29,0x20,0x2d,0x20,0x28,0x30,0x2e,0x32,0x31,0x31,0x39,0x36, + 0x30,0x30,0x30,0x32,0x37,0x37,0x39,0x39,0x36,0x30,0x36,0x33,0x32,0x33,0x32,0x34, + 0x32,0x31,0x38,0x37,0x35,0x20,0x2a,0x20,0x5f,0x32,0x35,0x34,0x29,0x29,0x20,0x2b, + 0x20,0x28,0x30,0x2e,0x30,0x36,0x30,0x35,0x32,0x30,0x30,0x30,0x30,0x37,0x35,0x35, + 0x37,0x38,0x36,0x38,0x39,0x35,0x37,0x35,0x31,0x39,0x35,0x33,0x31,0x32,0x35,0x20, + 0x2a,0x20,0x5f,0x31,0x35,0x31,0x29,0x29,0x20,0x2b,0x20,0x30,0x2e,0x32,0x35,0x38, + 0x38,0x35,0x39,0x39,0x39,0x32,0x30,0x32,0x37,0x32,0x38,0x32,0x37,0x31,0x34,0x38, + 0x34,0x33,0x37,0x35,0x29,0x29,0x20,0x2a,0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61, + 0x6d,0x50,0x65,0x72,0x65,0x7a,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x35,0x29,0x29,0x20,0x2f,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61, + 0x78,0x28,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x50,0x65,0x72,0x65,0x7a,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x36, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x37,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x33,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x39,0x29,0x2c, + 0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37, + 0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31, + 0x38,0x38,0x65,0x2d,0x30,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x39,0x20,0x3d,0x20,0x28,0x28, + 0x28,0x28,0x28,0x28,0x28,0x30,0x2e,0x30,0x30,0x32,0x37,0x34,0x39,0x39,0x39,0x39, + 0x39,0x38,0x35,0x30,0x39,0x38,0x38,0x33,0x38,0x38,0x30,0x36,0x31,0x35,0x32,0x33, + 0x34,0x33,0x37,0x35,0x20,0x2a,0x20,0x5f,0x32,0x35,0x38,0x29,0x20,0x2d,0x20,0x28, + 0x30,0x2e,0x30,0x30,0x36,0x30,0x39,0x39,0x39,0x39,0x39,0x38,0x38,0x32,0x32,0x38, + 0x30,0x38,0x32,0x36,0x35,0x36,0x38,0x36,0x30,0x33,0x35,0x31,0x35,0x36,0x32,0x35, + 0x20,0x2a,0x20,0x5f,0x32,0x35,0x34,0x29,0x29,0x20,0x2b,0x20,0x28,0x30,0x2e,0x30, + 0x30,0x33,0x31,0x36,0x39,0x39,0x39,0x39,0x39,0x32,0x33,0x35,0x35,0x37,0x30,0x34, + 0x33,0x30,0x37,0x35,0x35,0x36,0x31,0x35,0x32,0x33,0x34,0x33,0x37,0x35,0x20,0x2a, + 0x20,0x5f,0x31,0x35,0x31,0x29,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x38,0x29,0x20, + 0x2b,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x2d,0x30,0x2e,0x30,0x34,0x32,0x31,0x33, + 0x39,0x39,0x39,0x39,0x35,0x36,0x38,0x34,0x36,0x32,0x33,0x37,0x31,0x38,0x32,0x36, + 0x31,0x37,0x31,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x5f,0x32,0x35,0x38,0x29,0x20, + 0x2b,0x20,0x28,0x30,0x2e,0x30,0x38,0x39,0x36,0x39,0x39,0x39,0x39,0x38,0x34,0x39, + 0x37,0x39,0x36,0x32,0x39,0x35,0x31,0x36,0x36,0x30,0x31,0x35,0x36,0x32,0x35,0x20, + 0x2a,0x20,0x5f,0x32,0x35,0x34,0x29,0x29,0x20,0x2d,0x20,0x28,0x30,0x2e,0x30,0x34, + 0x31,0x35,0x32,0x39,0x39,0x39,0x38,0x31,0x38,0x33,0x32,0x35,0x30,0x34,0x32,0x37, + 0x32,0x34,0x36,0x30,0x39,0x33,0x37,0x35,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31,0x29, + 0x29,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x35,0x31,0x36,0x30,0x30,0x30,0x30,0x31, + 0x37,0x35,0x32,0x33,0x37,0x36,0x35,0x35,0x36,0x33,0x39,0x36,0x34,0x38,0x34,0x33, + 0x37,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x29,0x20,0x2b,0x20,0x28, + 0x28,0x28,0x28,0x30,0x2e,0x31,0x35,0x33,0x34,0x35,0x39,0x39,0x39,0x35,0x39,0x38, + 0x35,0x30,0x33,0x31,0x31,0x32,0x37,0x39,0x32,0x39,0x36,0x38,0x37,0x35,0x20,0x2a, + 0x20,0x5f,0x32,0x35,0x38,0x29,0x20,0x2d,0x20,0x28,0x30,0x2e,0x32,0x36,0x37,0x35, + 0x36,0x30,0x30,0x30,0x35,0x31,0x38,0x37,0x39,0x38,0x38,0x32,0x38,0x31,0x32,0x35, + 0x20,0x2a,0x20,0x5f,0x32,0x35,0x34,0x29,0x29,0x20,0x2b,0x20,0x28,0x30,0x2e,0x30, + 0x36,0x36,0x36,0x39,0x39,0x39,0x39,0x36,0x35,0x39,0x30,0x36,0x31,0x34,0x33,0x31, + 0x38,0x38,0x34,0x37,0x36,0x35,0x36,0x32,0x35,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31, + 0x29,0x29,0x20,0x2b,0x20,0x30,0x2e,0x32,0x36,0x36,0x38,0x38,0x30,0x30,0x30,0x35, + 0x35,0x39,0x38,0x30,0x36,0x38,0x32,0x33,0x37,0x33,0x30,0x34,0x36,0x38,0x37,0x35, + 0x29,0x29,0x20,0x2a,0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x50,0x65,0x72, + 0x65,0x7a,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x33,0x29,0x29,0x20,0x2f,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28, + 0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x50,0x65,0x72,0x65,0x7a,0x28,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x34,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x31, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x32,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x34,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x34,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x34,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x37,0x29,0x2c,0x20,0x39, + 0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31, + 0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38, + 0x65,0x2d,0x30,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x30,0x20,0x3d,0x20,0x66,0x61,0x73,0x74, + 0x3a,0x3a,0x6d,0x61,0x78,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x34,0x2e,0x30,0x34, + 0x35,0x33,0x30,0x30,0x30,0x30,0x36,0x38,0x36,0x36,0x34,0x35,0x35,0x30,0x37,0x38, + 0x31,0x32,0x35,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2d,0x20,0x34,0x2e, + 0x39,0x37,0x31,0x30,0x30,0x30,0x31,0x39,0x34,0x35,0x34,0x39,0x35,0x36,0x30,0x35, + 0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x74,0x61,0x6e,0x28,0x28,0x30,0x2e, + 0x34,0x34,0x34,0x34,0x34,0x34,0x34,0x34,0x37,0x37,0x35,0x35,0x38,0x31,0x33,0x35, + 0x39,0x38,0x36,0x33,0x32,0x38,0x31,0x32,0x35,0x20,0x2d,0x20,0x28,0x5f,0x31,0x35, + 0x34,0x20,0x2a,0x20,0x30,0x2e,0x30,0x30,0x38,0x33,0x33,0x33,0x33,0x33,0x33,0x37, + 0x36,0x37,0x39,0x35,0x30,0x35,0x33,0x34,0x38,0x32,0x30,0x35,0x35,0x36,0x36,0x34, + 0x30,0x36,0x32,0x35,0x29,0x29,0x20,0x2a,0x20,0x28,0x33,0x2e,0x31,0x34,0x31,0x35, + 0x39,0x32,0x37,0x34,0x31,0x30,0x31,0x32,0x35,0x37,0x33,0x32,0x34,0x32,0x31,0x38, + 0x37,0x35,0x20,0x2d,0x20,0x28,0x32,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31, + 0x29,0x29,0x29,0x29,0x20,0x2d,0x20,0x28,0x30,0x2e,0x32,0x31,0x35,0x34,0x39,0x39, + 0x39,0x39,0x37,0x31,0x33,0x38,0x39,0x37,0x37,0x30,0x35,0x30,0x37,0x38,0x31,0x32, + 0x35,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x29,0x20,0x2b,0x20,0x32,0x2e,0x34, + 0x31,0x39,0x31,0x39,0x39,0x39,0x34,0x33,0x35,0x34,0x32,0x34,0x38,0x30,0x34,0x36, + 0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x50, + 0x65,0x72,0x65,0x7a,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x29,0x29,0x20,0x2f,0x20,0x66,0x61, + 0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d, + 0x50,0x65,0x72,0x65,0x7a,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x39, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x30,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x33,0x31,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37, + 0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35, + 0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x29,0x2c,0x20,0x30, + 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x31,0x20,0x3d,0x20,0x70,0x72,0x65,0x65,0x74, + 0x68,0x61,0x6d,0x58,0x79,0x59,0x5f,0x74,0x6f,0x5f,0x58,0x59,0x5a,0x28,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x34,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x39, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61, + 0x78,0x28,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x58,0x59,0x5a,0x5f,0x74,0x6f, + 0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x73,0x72,0x67,0x62,0x28,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x35,0x31,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30, + 0x2e,0x30,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, + 0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75, + 0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c, + 0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x72,0x65, + 0x65,0x74,0x68,0x61,0x6d,0x53,0x6b,0x79,0x53,0x63,0x61,0x6c,0x65,0x64,0x28,0x74, + 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x26,0x20,0x76,0x69,0x65,0x77,0x5f,0x64,0x69,0x72,0x2c,0x20,0x74,0x68, + 0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x26,0x20,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x2c,0x20,0x74,0x68,0x72,0x65, + 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20, + 0x74,0x75,0x72,0x62,0x69,0x64,0x69,0x74,0x79,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x66, + 0x61,0x64,0x65,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x76,0x69,0x65,0x77,0x5f,0x64, + 0x69,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x20,0x3d,0x20,0x74,0x75,0x72,0x62,0x69,0x64,0x69,0x74,0x79,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x70,0x72,0x65, + 0x65,0x74,0x68,0x61,0x6d,0x53,0x6b,0x79,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x29,0x20,0x2a,0x20,0x30,0x2e,0x30,0x35,0x39,0x39,0x39,0x39,0x39,0x39,0x38,0x36, + 0x35,0x38,0x38,0x39,0x35,0x34,0x39,0x32,0x35,0x35,0x33,0x37,0x31,0x30,0x39,0x33, + 0x37,0x35,0x29,0x20,0x2a,0x20,0x66,0x61,0x64,0x65,0x3b,0x0a,0x7d,0x0a,0x0a,0x66, + 0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75, + 0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e, + 0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d, + 0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x73,0x6b,0x79,0x5f,0x75, + 0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x35,0x34,0x39,0x20,0x5b,0x5b,0x62, + 0x75,0x66,0x66,0x65,0x72,0x28,0x31,0x29,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20, + 0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e, + 0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x5f,0x68,0x6f,0x6d,0x6f,0x67,0x2e,0x78,0x79,0x7a,0x20,0x2f, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x5f,0x68,0x6f,0x6d,0x6f,0x67,0x2e,0x77,0x29,0x29,0x20,0x2d,0x20,0x5f, + 0x35,0x34,0x39,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78, + 0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a, + 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x35,0x34,0x39,0x2e,0x73, + 0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x35,0x34,0x39,0x2e,0x73,0x6b,0x79,0x5f, + 0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x35, + 0x34,0x39,0x2e,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x70, + 0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x53,0x6b,0x79,0x53,0x63,0x61,0x6c,0x65,0x64, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +static inline const sg_shader_desc* sky_shader_desc(sg_backend backend) { + if (backend == SG_BACKEND_GLCORE) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)vs_source_glsl430; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)fs_source_glsl430; + desc.fragment_func.entry = "main"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[0].glsl_uniforms[0].array_count = 4; + desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "sky_ub_frame"; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 48; + desc.uniform_blocks[1].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[0].array_count = 3; + desc.uniform_blocks[1].glsl_uniforms[0].glsl_name = "sky_ub_pass"; + desc.label = "sky_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_D3D11) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)vs_source_hlsl5; + desc.vertex_func.d3d11_target = "vs_5_0"; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)fs_source_hlsl5; + desc.fragment_func.d3d11_target = "ps_5_0"; + desc.fragment_func.entry = "main"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].hlsl_register_b_n = 0; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 48; + desc.uniform_blocks[1].hlsl_register_b_n = 1; + desc.label = "sky_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_METAL_MACOS) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)vs_source_metal_macos; + desc.vertex_func.entry = "main0"; + desc.fragment_func.source = (const char*)fs_source_metal_macos; + desc.fragment_func.entry = "main0"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].msl_buffer_n = 0; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 48; + desc.uniform_blocks[1].msl_buffer_n = 1; + desc.label = "sky_shader"; + } + return &desc; + } + return 0; +} diff --git a/samples/shaders/generated/sky_to_cube.glsl.h b/samples/shaders/generated/sky_to_cube.glsl.h new file mode 100644 index 0000000..76a65b0 --- /dev/null +++ b/samples/shaders/generated/sky_to_cube.glsl.h @@ -0,0 +1,2067 @@ +#pragma once +/* + #version:1# (machine generated, don't edit!) + + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) + + Cmdline: + sokol-shdc --input E:/box/box3d/samples/shaders/ibl/sky_to_cube.glsl --output E:/box/box3d/samples/shaders/generated/sky_to_cube.glsl.h --slang hlsl5:metal_macos:glsl430 + + Overview: + ========= + Shader program: 'build': + Get shader desc: sky_to_cube_build_shader_desc(sg_query_backend()); + Vertex Shader: vs + Fragment Shader: fs + Attributes: + Bindings: + Uniform block 'ub_face': + C struct: sky_to_cube_ub_face_t + Bind slot: UB_sky_to_cube_ub_face => 0 +*/ +#if !defined(SOKOL_GFX_INCLUDED) +#error "Please include sokol_gfx.h before sky_to_cube.glsl.h" +#endif +#if !defined(SOKOL_SHDC_ALIGN) +#if defined(_MSC_VER) +#define SOKOL_SHDC_ALIGN(a) __declspec(align(a)) +#else +#define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) +#endif +#endif +#define UB_sky_to_cube_ub_face (0) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct sky_to_cube_ub_face_t { + Vec4 face_right; + Vec4 face_up; + Vec4 face_forward; + Vec4 sun_dir_world; +} sky_to_cube_ub_face_t; +#pragma pack(pop) +/* + #version 430 + + layout(location = 0) out vec2 v_uv; + + void main() + { + vec2 _27 = (vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2)) * 2.0) - vec2(1.0); + v_uv = (_27 * 0.5) + vec2(0.5); + gl_Position = vec4(_27, 0.0, 1.0); + } + +*/ +static const uint8_t sky_to_cube_vs_source_glsl430[240] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x32,0x20,0x76,0x5f,0x75,0x76, + 0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x32,0x37,0x20,0x3d,0x20, + 0x28,0x76,0x65,0x63,0x32,0x28,0x66,0x6c,0x6f,0x61,0x74,0x28,0x28,0x67,0x6c,0x5f, + 0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x44,0x20,0x3c,0x3c,0x20,0x31,0x29,0x20,0x26, + 0x20,0x32,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x67,0x6c,0x5f,0x56,0x65, + 0x72,0x74,0x65,0x78,0x49,0x44,0x20,0x26,0x20,0x32,0x29,0x29,0x20,0x2a,0x20,0x32, + 0x2e,0x30,0x29,0x20,0x2d,0x20,0x76,0x65,0x63,0x32,0x28,0x31,0x2e,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x75,0x76,0x20,0x3d,0x20,0x28,0x5f,0x32,0x37, + 0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x76,0x65,0x63,0x32,0x28,0x30, + 0x2e,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x32,0x37,0x2c, + 0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + +}; +/* + #version 430 + + uniform vec4 ub_face[4]; + layout(location = 0) in vec2 v_uv; + layout(location = 0) out vec4 out_color; + + float preethamPerez(float cos_theta, float cos_gamma, float gamma, float A, float B, float C, float D, float E) + { + return (1.0 + (A * exp(B / max(cos_theta, 0.00999999977648258209228515625)))) * ((1.0 + (C * exp(D * gamma))) + ((E * cos_gamma) * cos_gamma)); + } + + vec3 preethamXyY_to_XYZ(float x, float y, float Y) + { + float _77 = max(y, 9.9999997473787516355514526367188e-06); + return vec3((Y * x) / _77, Y, (Y * ((1.0 - x) - y)) / _77); + } + + vec3 preethamXYZ_to_linear_srgb(vec3 c) + { + return vec3(dot(c, vec3(3.240454196929931640625, -1.537138462066650390625, -0.498531401157379150390625)), dot(c, vec3(-0.969265997409820556640625, 1.87601077556610107421875, 0.04155600070953369140625)), dot(c, vec3(0.0556433983147144317626953125, -0.2040258944034576416015625, 1.05722522735595703125))); + } + + vec3 preethamSky(vec3 view_dir, vec3 sun_dir, float turbidity) + { + float _122 = clamp(sun_dir.y, 0.0, 1.0); + vec3 _135 = normalize(vec3(view_dir.x, max(view_dir.y, 0.0) + 0.00999999977648258209228515625, view_dir.z)); + float _139 = max(_135.y, 0.0); + float _145 = clamp(dot(sun_dir, _135), -1.0, 1.0); + float _148 = acos(_145); + float _151 = acos(_122); + float _154 = max(turbidity, 1.0); + float _158 = _154 * _154; + float _164 = (0.1787000000476837158203125 * _154) - 1.4630000591278076171875; + float _170 = ((-0.3553999960422515869140625) * _154) + 0.4275000095367431640625; + float _176 = ((-0.0227000005543231964111328125) * _154) + 5.325099945068359375; + float _182 = (0.12060000002384185791015625 * _154) - 2.5771000385284423828125; + float _188 = ((-0.0670000016689300537109375) * _154) + 0.370299994945526123046875; + float _194 = ((-0.01930000074207782745361328125) * _154) - 0.2592000067234039306640625; + float _200 = ((-0.066500000655651092529296875) * _154) + 0.0007999999797903001308441162109375; + float _206 = ((-0.00039999998989515006542205810546875) * _154) + 0.2125000059604644775390625; + float _212 = ((-0.0640999972820281982421875) * _154) - 0.898899972438812255859375; + float _218 = ((-0.0032999999821186065673828125) * _154) + 0.0452000014483928680419921875; + float _224 = ((-0.0166999995708465576171875) * _154) - 0.26080000400543212890625; + float _230 = ((-0.0949999988079071044921875) * _154) + 0.009200000204145908355712890625; + float _236 = ((-0.0078999996185302734375) * _154) + 0.21019999682903289794921875; + float _242 = ((-0.04410000145435333251953125) * _154) - 1.65369999408721923828125; + float _248 = ((-0.01090000011026859283447265625) * _154) + 0.05290000140666961669921875; + float _254 = _151 * _151; + float _258 = _254 * _151; + float param = _139; + float param_1 = _145; + float param_2 = _148; + float param_3 = _164; + float param_4 = _170; + float param_5 = _176; + float param_6 = _182; + float param_7 = _188; + float param_8 = _139; + float param_9 = _145; + float param_10 = _148; + float param_11 = _194; + float param_12 = _200; + float param_13 = _206; + float param_14 = _212; + float param_15 = _218; + float param_16 = _139; + float param_17 = _145; + float param_18 = _148; + float param_19 = _224; + float param_20 = _230; + float param_21 = _236; + float param_22 = _242; + float param_23 = _248; + float param_24 = 1.0; + float param_25 = _122; + float param_26 = _151; + float param_27 = _164; + float param_28 = _170; + float param_29 = _176; + float param_30 = _182; + float param_31 = _188; + float param_32 = 1.0; + float param_33 = _122; + float param_34 = _151; + float param_35 = _194; + float param_36 = _200; + float param_37 = _206; + float param_38 = _212; + float param_39 = _218; + float param_40 = 1.0; + float param_41 = _122; + float param_42 = _151; + float param_43 = _224; + float param_44 = _230; + float param_45 = _236; + float param_46 = _242; + float param_47 = _248; + float param_48 = (((((((0.001659999950788915157318115234375 * _258) - (0.00374999991618096828460693359375 * _254)) + (0.0020900000818073749542236328125 * _151)) * _158) + ((((((-0.02903000079095363616943359375) * _258) + (0.063770003616809844970703125 * _254)) - (0.0320199988782405853271484375 * _151)) + 0.003940000198781490325927734375) * _154)) + ((((0.116930000483989715576171875 * _258) - (0.21196000277996063232421875 * _254)) + (0.060520000755786895751953125 * _151)) + 0.25885999202728271484375)) * preethamPerez(param_8, param_9, param_10, param_11, param_12, param_13, param_14, param_15)) / max(preethamPerez(param_32, param_33, param_34, param_35, param_36, param_37, param_38, param_39), 9.9999997473787516355514526367188e-06); + float param_49 = (((((((0.00274999998509883880615234375 * _258) - (0.006099999882280826568603515625 * _254)) + (0.0031699999235570430755615234375 * _151)) * _158) + ((((((-0.042139999568462371826171875) * _258) + (0.08969999849796295166015625 * _254)) - (0.04152999818325042724609375 * _151)) + 0.0051600001752376556396484375) * _154)) + ((((0.1534599959850311279296875 * _258) - (0.26756000518798828125 * _254)) + (0.06669999659061431884765625 * _151)) + 0.2668800055980682373046875)) * preethamPerez(param_16, param_17, param_18, param_19, param_20, param_21, param_22, param_23)) / max(preethamPerez(param_40, param_41, param_42, param_43, param_44, param_45, param_46, param_47), 9.9999997473787516355514526367188e-06); + float param_50 = max(((((((4.045300006866455078125 * _154) - 4.971000194549560546875) * tan((0.4444444477558135986328125 - (_154 * 0.008333333767950534820556640625)) * (3.1415927410125732421875 - (2.0 * _151)))) - (0.21549999713897705078125 * _154)) + 2.41919994354248046875) * preethamPerez(param, param_1, param_2, param_3, param_4, param_5, param_6, param_7)) / max(preethamPerez(param_24, param_25, param_26, param_27, param_28, param_29, param_30, param_31), 9.9999997473787516355514526367188e-06), 0.0); + vec3 param_51 = preethamXyY_to_XYZ(param_48, param_49, param_50); + return max(preethamXYZ_to_linear_srgb(param_51), vec3(0.0)); + } + + vec3 preethamSkyScaled(vec3 view_dir, vec3 sun_dir, float turbidity, float fade) + { + vec3 param = view_dir; + vec3 param_1 = sun_dir; + float param_2 = turbidity; + return (preethamSky(param, param_1, param_2) * 0.0599999986588954925537109375) * fade; + } + + void main() + { + vec2 _541 = (v_uv * 2.0) - vec2(1.0); + vec3 param = normalize((ub_face[2].xyz + (ub_face[0].xyz * _541.x)) + (ub_face[1].xyz * _541.y)); + vec3 param_1 = ub_face[3].xyz; + float param_2 = ub_face[3].w; + float param_3 = ub_face[2].w; + out_color = vec4(preethamSkyScaled(param, param_1, param_2, param_3), 1.0); + } + +*/ +static const uint8_t sky_to_cube_fs_source_glsl430[6767] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x75,0x6e, + 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x66,0x61, + 0x63,0x65,0x5b,0x34,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f, + 0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76, + 0x65,0x63,0x32,0x20,0x76,0x5f,0x75,0x76,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, + 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f, + 0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x3b,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x72,0x65,0x65,0x74,0x68, + 0x61,0x6d,0x50,0x65,0x72,0x65,0x7a,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x63,0x6f, + 0x73,0x5f,0x74,0x68,0x65,0x74,0x61,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x63, + 0x6f,0x73,0x5f,0x67,0x61,0x6d,0x6d,0x61,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x67,0x61,0x6d,0x6d,0x61,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x41,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x42,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x43, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x44,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x45,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x28,0x31,0x2e,0x30,0x20,0x2b,0x20,0x28,0x41,0x20,0x2a,0x20,0x65,0x78,0x70, + 0x28,0x42,0x20,0x2f,0x20,0x6d,0x61,0x78,0x28,0x63,0x6f,0x73,0x5f,0x74,0x68,0x65, + 0x74,0x61,0x2c,0x20,0x30,0x2e,0x30,0x30,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37, + 0x37,0x36,0x34,0x38,0x32,0x35,0x38,0x32,0x30,0x39,0x32,0x32,0x38,0x35,0x31,0x35, + 0x36,0x32,0x35,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x28,0x28,0x31,0x2e,0x30,0x20, + 0x2b,0x20,0x28,0x43,0x20,0x2a,0x20,0x65,0x78,0x70,0x28,0x44,0x20,0x2a,0x20,0x67, + 0x61,0x6d,0x6d,0x61,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x28,0x45,0x20,0x2a,0x20, + 0x63,0x6f,0x73,0x5f,0x67,0x61,0x6d,0x6d,0x61,0x29,0x20,0x2a,0x20,0x63,0x6f,0x73, + 0x5f,0x67,0x61,0x6d,0x6d,0x61,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63, + 0x33,0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x58,0x79,0x59,0x5f,0x74,0x6f, + 0x5f,0x58,0x59,0x5a,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x78,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x79,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x59,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x37,0x20, + 0x3d,0x20,0x6d,0x61,0x78,0x28,0x79,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39, + 0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31, + 0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x76,0x65,0x63,0x33, + 0x28,0x28,0x59,0x20,0x2a,0x20,0x78,0x29,0x20,0x2f,0x20,0x5f,0x37,0x37,0x2c,0x20, + 0x59,0x2c,0x20,0x28,0x59,0x20,0x2a,0x20,0x28,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20, + 0x78,0x29,0x20,0x2d,0x20,0x79,0x29,0x29,0x20,0x2f,0x20,0x5f,0x37,0x37,0x29,0x3b, + 0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61, + 0x6d,0x58,0x59,0x5a,0x5f,0x74,0x6f,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x73, + 0x72,0x67,0x62,0x28,0x76,0x65,0x63,0x33,0x20,0x63,0x29,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x76,0x65,0x63,0x33,0x28,0x64,0x6f, + 0x74,0x28,0x63,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x33,0x2e,0x32,0x34,0x30,0x34, + 0x35,0x34,0x31,0x39,0x36,0x39,0x32,0x39,0x39,0x33,0x31,0x36,0x34,0x30,0x36,0x32, + 0x35,0x2c,0x20,0x2d,0x31,0x2e,0x35,0x33,0x37,0x31,0x33,0x38,0x34,0x36,0x32,0x30, + 0x36,0x36,0x36,0x35,0x30,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x2d,0x30,0x2e, + 0x34,0x39,0x38,0x35,0x33,0x31,0x34,0x30,0x31,0x31,0x35,0x37,0x33,0x37,0x39,0x31, + 0x35,0x30,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28, + 0x63,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x2d,0x30,0x2e,0x39,0x36,0x39,0x32,0x36, + 0x35,0x39,0x39,0x37,0x34,0x30,0x39,0x38,0x32,0x30,0x35,0x35,0x36,0x36,0x34,0x30, + 0x36,0x32,0x35,0x2c,0x20,0x31,0x2e,0x38,0x37,0x36,0x30,0x31,0x30,0x37,0x37,0x35, + 0x35,0x36,0x36,0x31,0x30,0x31,0x30,0x37,0x34,0x32,0x31,0x38,0x37,0x35,0x2c,0x20, + 0x30,0x2e,0x30,0x34,0x31,0x35,0x35,0x36,0x30,0x30,0x30,0x37,0x30,0x39,0x35,0x33, + 0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x29,0x2c,0x20,0x64,0x6f,0x74, + 0x28,0x63,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x35,0x35,0x36,0x34, + 0x33,0x33,0x39,0x38,0x33,0x31,0x34,0x37,0x31,0x34,0x34,0x33,0x31,0x37,0x36,0x32, + 0x36,0x39,0x35,0x33,0x31,0x32,0x35,0x2c,0x20,0x2d,0x30,0x2e,0x32,0x30,0x34,0x30, + 0x32,0x35,0x38,0x39,0x34,0x34,0x30,0x33,0x34,0x35,0x37,0x36,0x34,0x31,0x36,0x30, + 0x31,0x35,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30,0x35,0x37,0x32,0x32,0x35,0x32, + 0x32,0x37,0x33,0x35,0x35,0x39,0x35,0x37,0x30,0x33,0x31,0x32,0x35,0x29,0x29,0x29, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x70,0x72,0x65,0x65,0x74,0x68, + 0x61,0x6d,0x53,0x6b,0x79,0x28,0x76,0x65,0x63,0x33,0x20,0x76,0x69,0x65,0x77,0x5f, + 0x64,0x69,0x72,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x73,0x75,0x6e,0x5f,0x64,0x69, + 0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x74,0x75,0x72,0x62,0x69,0x64,0x69, + 0x74,0x79,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x32,0x32,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x73,0x75,0x6e, + 0x5f,0x64,0x69,0x72,0x2e,0x79,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x33,0x35, + 0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x76,0x65,0x63, + 0x33,0x28,0x76,0x69,0x65,0x77,0x5f,0x64,0x69,0x72,0x2e,0x78,0x2c,0x20,0x6d,0x61, + 0x78,0x28,0x76,0x69,0x65,0x77,0x5f,0x64,0x69,0x72,0x2e,0x79,0x2c,0x20,0x30,0x2e, + 0x30,0x29,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x39,0x39,0x39,0x39,0x39,0x39,0x39, + 0x37,0x37,0x36,0x34,0x38,0x32,0x35,0x38,0x32,0x30,0x39,0x32,0x32,0x38,0x35,0x31, + 0x35,0x36,0x32,0x35,0x2c,0x20,0x76,0x69,0x65,0x77,0x5f,0x64,0x69,0x72,0x2e,0x7a, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x33,0x39,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x5f,0x31,0x33,0x35,0x2e,0x79,0x2c, + 0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x34,0x35,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x64,0x6f, + 0x74,0x28,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x2c,0x20,0x5f,0x31,0x33,0x35,0x29, + 0x2c,0x20,0x2d,0x31,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x38,0x20,0x3d,0x20,0x61, + 0x63,0x6f,0x73,0x28,0x5f,0x31,0x34,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x31,0x20,0x3d,0x20,0x61,0x63,0x6f,0x73, + 0x28,0x5f,0x31,0x32,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x31,0x35,0x34,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x74,0x75,0x72, + 0x62,0x69,0x64,0x69,0x74,0x79,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x38,0x20,0x3d,0x20,0x5f, + 0x31,0x35,0x34,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x34,0x20,0x3d,0x20,0x28,0x30,0x2e, + 0x31,0x37,0x38,0x37,0x30,0x30,0x30,0x30,0x30,0x30,0x34,0x37,0x36,0x38,0x33,0x37, + 0x31,0x35,0x38,0x32,0x30,0x33,0x31,0x32,0x35,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34, + 0x29,0x20,0x2d,0x20,0x31,0x2e,0x34,0x36,0x33,0x30,0x30,0x30,0x30,0x35,0x39,0x31, + 0x32,0x37,0x38,0x30,0x37,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x37,0x30,0x20,0x3d,0x20,0x28, + 0x28,0x2d,0x30,0x2e,0x33,0x35,0x35,0x33,0x39,0x39,0x39,0x39,0x36,0x30,0x34,0x32, + 0x32,0x35,0x31,0x35,0x38,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x20,0x2a, + 0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2b,0x20,0x30,0x2e,0x34,0x32,0x37,0x35,0x30, + 0x30,0x30,0x30,0x39,0x35,0x33,0x36,0x37,0x34,0x33,0x31,0x36,0x34,0x30,0x36,0x32, + 0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x37, + 0x36,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x32,0x32,0x37,0x30,0x30,0x30, + 0x30,0x30,0x35,0x35,0x34,0x33,0x32,0x33,0x31,0x39,0x36,0x34,0x31,0x31,0x31,0x33, + 0x32,0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2b, + 0x20,0x35,0x2e,0x33,0x32,0x35,0x30,0x39,0x39,0x39,0x34,0x35,0x30,0x36,0x38,0x33, + 0x35,0x39,0x33,0x37,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x38,0x32,0x20,0x3d,0x20,0x28,0x30,0x2e,0x31,0x32,0x30,0x36,0x30, + 0x30,0x30,0x30,0x30,0x30,0x32,0x33,0x38,0x34,0x31,0x38,0x35,0x37,0x39,0x31,0x30, + 0x31,0x35,0x36,0x32,0x35,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2d,0x20, + 0x32,0x2e,0x35,0x37,0x37,0x31,0x30,0x30,0x30,0x33,0x38,0x35,0x32,0x38,0x34,0x34, + 0x32,0x33,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x31,0x38,0x38,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e, + 0x30,0x36,0x37,0x30,0x30,0x30,0x30,0x30,0x31,0x36,0x36,0x38,0x39,0x33,0x30,0x30, + 0x35,0x33,0x37,0x31,0x30,0x39,0x33,0x37,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35, + 0x34,0x29,0x20,0x2b,0x20,0x30,0x2e,0x33,0x37,0x30,0x32,0x39,0x39,0x39,0x39,0x34, + 0x39,0x34,0x35,0x35,0x32,0x36,0x31,0x32,0x33,0x30,0x34,0x36,0x38,0x37,0x35,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x39,0x34,0x20, + 0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x31,0x39,0x33,0x30,0x30,0x30,0x30,0x30, + 0x37,0x34,0x32,0x30,0x37,0x37,0x38,0x32,0x37,0x34,0x35,0x33,0x36,0x31,0x33,0x32, + 0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2d,0x20, + 0x30,0x2e,0x32,0x35,0x39,0x32,0x30,0x30,0x30,0x30,0x36,0x37,0x32,0x33,0x34,0x30, + 0x33,0x39,0x33,0x30,0x36,0x36,0x34,0x30,0x36,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x30,0x30,0x20,0x3d,0x20,0x28,0x28, + 0x2d,0x30,0x2e,0x30,0x36,0x36,0x35,0x30,0x30,0x30,0x30,0x30,0x36,0x35,0x35,0x36, + 0x35,0x31,0x30,0x39,0x32,0x35,0x32,0x39,0x32,0x39,0x36,0x38,0x37,0x35,0x29,0x20, + 0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x37, + 0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x39,0x37,0x39,0x30,0x33,0x30,0x30,0x31,0x33, + 0x30,0x38,0x34,0x34,0x31,0x31,0x36,0x32,0x31,0x30,0x39,0x33,0x37,0x35,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x30,0x36,0x20,0x3d, + 0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x30,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39, + 0x38,0x39,0x38,0x39,0x35,0x31,0x35,0x30,0x30,0x36,0x35,0x34,0x32,0x32,0x30,0x35, + 0x38,0x31,0x30,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35, + 0x34,0x29,0x20,0x2b,0x20,0x30,0x2e,0x32,0x31,0x32,0x35,0x30,0x30,0x30,0x30,0x35, + 0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x32, + 0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x36,0x34,0x30,0x39,0x39,0x39,0x39, + 0x37,0x32,0x38,0x32,0x30,0x32,0x38,0x31,0x39,0x38,0x32,0x34,0x32,0x31,0x38,0x37, + 0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2d,0x20,0x30,0x2e,0x38, + 0x39,0x38,0x38,0x39,0x39,0x39,0x37,0x32,0x34,0x33,0x38,0x38,0x31,0x32,0x32,0x35, + 0x35,0x38,0x35,0x39,0x33,0x37,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x32,0x31,0x38,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30, + 0x30,0x33,0x32,0x39,0x39,0x39,0x39,0x39,0x39,0x38,0x32,0x31,0x31,0x38,0x36,0x30, + 0x36,0x35,0x36,0x37,0x33,0x38,0x32,0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x5f, + 0x31,0x35,0x34,0x29,0x20,0x2b,0x20,0x30,0x2e,0x30,0x34,0x35,0x32,0x30,0x30,0x30, + 0x30,0x31,0x34,0x34,0x38,0x33,0x39,0x32,0x38,0x36,0x38,0x30,0x34,0x31,0x39,0x39, + 0x32,0x31,0x38,0x37,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x32,0x32,0x34,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x31,0x36, + 0x36,0x39,0x39,0x39,0x39,0x39,0x35,0x37,0x30,0x38,0x34,0x36,0x35,0x35,0x37,0x36, + 0x31,0x37,0x31,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20, + 0x2d,0x20,0x30,0x2e,0x32,0x36,0x30,0x38,0x30,0x30,0x30,0x30,0x34,0x30,0x30,0x35, + 0x34,0x33,0x32,0x31,0x32,0x38,0x39,0x30,0x36,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x33,0x30,0x20,0x3d,0x20,0x28,0x28, + 0x2d,0x30,0x2e,0x30,0x39,0x34,0x39,0x39,0x39,0x39,0x39,0x38,0x38,0x30,0x37,0x39, + 0x30,0x37,0x31,0x30,0x34,0x34,0x39,0x32,0x31,0x38,0x37,0x35,0x29,0x20,0x2a,0x20, + 0x5f,0x31,0x35,0x34,0x29,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x39,0x32,0x30,0x30, + 0x30,0x30,0x30,0x32,0x30,0x34,0x31,0x34,0x35,0x39,0x30,0x38,0x33,0x35,0x35,0x37, + 0x31,0x32,0x38,0x39,0x30,0x36,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x32,0x33,0x36,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e, + 0x30,0x30,0x37,0x38,0x39,0x39,0x39,0x39,0x39,0x36,0x31,0x38,0x35,0x33,0x30,0x32, + 0x37,0x33,0x34,0x33,0x37,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20, + 0x2b,0x20,0x30,0x2e,0x32,0x31,0x30,0x31,0x39,0x39,0x39,0x39,0x36,0x38,0x32,0x39, + 0x30,0x33,0x32,0x38,0x39,0x37,0x39,0x34,0x39,0x32,0x31,0x38,0x37,0x35,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x34,0x32,0x20,0x3d, + 0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x34,0x34,0x31,0x30,0x30,0x30,0x30,0x31,0x34, + 0x35,0x34,0x33,0x35,0x33,0x33,0x33,0x32,0x35,0x31,0x39,0x35,0x33,0x31,0x32,0x35, + 0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2d,0x20,0x31,0x2e,0x36,0x35, + 0x33,0x36,0x39,0x39,0x39,0x39,0x34,0x30,0x38,0x37,0x32,0x31,0x39,0x32,0x33,0x38, + 0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x32,0x34,0x38,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x31,0x30, + 0x39,0x30,0x30,0x30,0x30,0x30,0x31,0x31,0x30,0x32,0x36,0x38,0x35,0x39,0x32,0x38, + 0x33,0x34,0x34,0x37,0x32,0x36,0x35,0x36,0x32,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31, + 0x35,0x34,0x29,0x20,0x2b,0x20,0x30,0x2e,0x30,0x35,0x32,0x39,0x30,0x30,0x30,0x30, + 0x31,0x34,0x30,0x36,0x36,0x36,0x39,0x36,0x31,0x36,0x36,0x39,0x39,0x32,0x31,0x38, + 0x37,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32, + 0x35,0x34,0x20,0x3d,0x20,0x5f,0x31,0x35,0x31,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x35,0x38, + 0x20,0x3d,0x20,0x5f,0x32,0x35,0x34,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20, + 0x3d,0x20,0x5f,0x31,0x33,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x31,0x34,0x35, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x31,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20, + 0x5f,0x31,0x36,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x31,0x37,0x30,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x35,0x20,0x3d,0x20,0x5f,0x31,0x37,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f,0x31, + 0x38,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x5f,0x31,0x38,0x38,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20, + 0x3d,0x20,0x5f,0x31,0x33,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x5f,0x31,0x34,0x35, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x5f,0x31,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20, + 0x3d,0x20,0x5f,0x31,0x39,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x5f,0x32,0x30, + 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20,0x5f,0x32,0x30,0x36,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34, + 0x20,0x3d,0x20,0x5f,0x32,0x31,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x5f,0x32, + 0x31,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x5f,0x31,0x33,0x39,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x37,0x20,0x3d,0x20,0x5f,0x31,0x34,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x5f, + 0x31,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20,0x5f,0x32,0x32,0x34,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x30,0x20,0x3d,0x20,0x5f,0x32,0x33,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x20,0x3d,0x20, + 0x5f,0x32,0x33,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x20,0x3d,0x20,0x5f,0x32,0x34,0x32,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x33,0x20,0x3d,0x20,0x5f,0x32,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x20,0x3d, + 0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x35,0x20,0x3d,0x20,0x5f,0x31,0x32,0x32,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x36,0x20,0x3d,0x20,0x5f,0x31,0x35,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37,0x20,0x3d, + 0x20,0x5f,0x31,0x36,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x38,0x20,0x3d,0x20,0x5f,0x31,0x37,0x30, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x39,0x20,0x3d,0x20,0x5f,0x31,0x37,0x36,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x30,0x20, + 0x3d,0x20,0x5f,0x31,0x38,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x31,0x20,0x3d,0x20,0x5f,0x31,0x38, + 0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x32,0x20,0x3d,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x33,0x20, + 0x3d,0x20,0x5f,0x31,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x20,0x3d,0x20,0x5f,0x31,0x35, + 0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x35,0x20,0x3d,0x20,0x5f,0x31,0x39,0x34,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x36, + 0x20,0x3d,0x20,0x5f,0x32,0x30,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x37,0x20,0x3d,0x20,0x5f,0x32, + 0x30,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x38,0x20,0x3d,0x20,0x5f,0x32,0x31,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, + 0x39,0x20,0x3d,0x20,0x5f,0x32,0x31,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x30,0x20,0x3d,0x20,0x31, + 0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x34,0x31,0x20,0x3d,0x20,0x5f,0x31,0x32,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, + 0x32,0x20,0x3d,0x20,0x5f,0x31,0x35,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x33,0x20,0x3d,0x20,0x5f, + 0x32,0x32,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x34,0x34,0x20,0x3d,0x20,0x5f,0x32,0x33,0x30,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x34,0x35,0x20,0x3d,0x20,0x5f,0x32,0x33,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x36,0x20,0x3d,0x20, + 0x5f,0x32,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x37,0x20,0x3d,0x20,0x5f,0x32,0x34,0x38,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x34,0x38,0x20,0x3d,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x30,0x2e,0x30, + 0x30,0x31,0x36,0x35,0x39,0x39,0x39,0x39,0x39,0x35,0x30,0x37,0x38,0x38,0x39,0x31, + 0x35,0x31,0x35,0x37,0x33,0x31,0x38,0x31,0x31,0x35,0x32,0x33,0x34,0x33,0x37,0x35, + 0x20,0x2a,0x20,0x5f,0x32,0x35,0x38,0x29,0x20,0x2d,0x20,0x28,0x30,0x2e,0x30,0x30, + 0x33,0x37,0x34,0x39,0x39,0x39,0x39,0x39,0x31,0x36,0x31,0x38,0x30,0x39,0x36,0x38, + 0x32,0x38,0x34,0x36,0x30,0x36,0x39,0x33,0x33,0x35,0x39,0x33,0x37,0x35,0x20,0x2a, + 0x20,0x5f,0x32,0x35,0x34,0x29,0x29,0x20,0x2b,0x20,0x28,0x30,0x2e,0x30,0x30,0x32, + 0x30,0x39,0x30,0x30,0x30,0x30,0x30,0x38,0x31,0x38,0x30,0x37,0x33,0x37,0x34,0x39, + 0x35,0x34,0x32,0x32,0x33,0x36,0x33,0x32,0x38,0x31,0x32,0x35,0x20,0x2a,0x20,0x5f, + 0x31,0x35,0x31,0x29,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x38,0x29,0x20,0x2b,0x20, + 0x28,0x28,0x28,0x28,0x28,0x28,0x2d,0x30,0x2e,0x30,0x32,0x39,0x30,0x33,0x30,0x30, + 0x30,0x30,0x37,0x39,0x30,0x39,0x35,0x33,0x36,0x33,0x36,0x31,0x36,0x39,0x34,0x33, + 0x33,0x35,0x39,0x33,0x37,0x35,0x29,0x20,0x2a,0x20,0x5f,0x32,0x35,0x38,0x29,0x20, + 0x2b,0x20,0x28,0x30,0x2e,0x30,0x36,0x33,0x37,0x37,0x30,0x30,0x30,0x33,0x36,0x31, + 0x36,0x38,0x30,0x39,0x38,0x34,0x34,0x39,0x37,0x30,0x37,0x30,0x33,0x31,0x32,0x35, + 0x20,0x2a,0x20,0x5f,0x32,0x35,0x34,0x29,0x29,0x20,0x2d,0x20,0x28,0x30,0x2e,0x30, + 0x33,0x32,0x30,0x31,0x39,0x39,0x39,0x38,0x38,0x37,0x38,0x32,0x34,0x30,0x35,0x38, + 0x35,0x33,0x32,0x37,0x31,0x34,0x38,0x34,0x33,0x37,0x35,0x20,0x2a,0x20,0x5f,0x31, + 0x35,0x31,0x29,0x29,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x33,0x39,0x34,0x30,0x30, + 0x30,0x30,0x31,0x39,0x38,0x37,0x38,0x31,0x34,0x39,0x30,0x33,0x32,0x35,0x39,0x32, + 0x37,0x37,0x33,0x34,0x33,0x37,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29, + 0x29,0x20,0x2b,0x20,0x28,0x28,0x28,0x28,0x30,0x2e,0x31,0x31,0x36,0x39,0x33,0x30, + 0x30,0x30,0x30,0x34,0x38,0x33,0x39,0x38,0x39,0x37,0x31,0x35,0x35,0x37,0x36,0x31, + 0x37,0x31,0x38,0x37,0x35,0x20,0x2a,0x20,0x5f,0x32,0x35,0x38,0x29,0x20,0x2d,0x20, + 0x28,0x30,0x2e,0x32,0x31,0x31,0x39,0x36,0x30,0x30,0x30,0x32,0x37,0x37,0x39,0x39, + 0x36,0x30,0x36,0x33,0x32,0x33,0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x20,0x2a,0x20, + 0x5f,0x32,0x35,0x34,0x29,0x29,0x20,0x2b,0x20,0x28,0x30,0x2e,0x30,0x36,0x30,0x35, + 0x32,0x30,0x30,0x30,0x30,0x37,0x35,0x35,0x37,0x38,0x36,0x38,0x39,0x35,0x37,0x35, + 0x31,0x39,0x35,0x33,0x31,0x32,0x35,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31,0x29,0x29, + 0x20,0x2b,0x20,0x30,0x2e,0x32,0x35,0x38,0x38,0x35,0x39,0x39,0x39,0x32,0x30,0x32, + 0x37,0x32,0x38,0x32,0x37,0x31,0x34,0x38,0x34,0x33,0x37,0x35,0x29,0x29,0x20,0x2a, + 0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x50,0x65,0x72,0x65,0x7a,0x28,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x29,0x29,0x20,0x2f,0x20, + 0x6d,0x61,0x78,0x28,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x50,0x65,0x72,0x65, + 0x7a,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x32,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x33,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x37,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x39, + 0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37, + 0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36, + 0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x39,0x20,0x3d,0x20, + 0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x30,0x2e,0x30,0x30,0x32,0x37,0x34,0x39,0x39, + 0x39,0x39,0x39,0x38,0x35,0x30,0x39,0x38,0x38,0x33,0x38,0x38,0x30,0x36,0x31,0x35, + 0x32,0x33,0x34,0x33,0x37,0x35,0x20,0x2a,0x20,0x5f,0x32,0x35,0x38,0x29,0x20,0x2d, + 0x20,0x28,0x30,0x2e,0x30,0x30,0x36,0x30,0x39,0x39,0x39,0x39,0x39,0x38,0x38,0x32, + 0x32,0x38,0x30,0x38,0x32,0x36,0x35,0x36,0x38,0x36,0x30,0x33,0x35,0x31,0x35,0x36, + 0x32,0x35,0x20,0x2a,0x20,0x5f,0x32,0x35,0x34,0x29,0x29,0x20,0x2b,0x20,0x28,0x30, + 0x2e,0x30,0x30,0x33,0x31,0x36,0x39,0x39,0x39,0x39,0x39,0x32,0x33,0x35,0x35,0x37, + 0x30,0x34,0x33,0x30,0x37,0x35,0x35,0x36,0x31,0x35,0x32,0x33,0x34,0x33,0x37,0x35, + 0x20,0x2a,0x20,0x5f,0x31,0x35,0x31,0x29,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x38, + 0x29,0x20,0x2b,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x2d,0x30,0x2e,0x30,0x34,0x32, + 0x31,0x33,0x39,0x39,0x39,0x39,0x35,0x36,0x38,0x34,0x36,0x32,0x33,0x37,0x31,0x38, + 0x32,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x5f,0x32,0x35,0x38, + 0x29,0x20,0x2b,0x20,0x28,0x30,0x2e,0x30,0x38,0x39,0x36,0x39,0x39,0x39,0x39,0x38, + 0x34,0x39,0x37,0x39,0x36,0x32,0x39,0x35,0x31,0x36,0x36,0x30,0x31,0x35,0x36,0x32, + 0x35,0x20,0x2a,0x20,0x5f,0x32,0x35,0x34,0x29,0x29,0x20,0x2d,0x20,0x28,0x30,0x2e, + 0x30,0x34,0x31,0x35,0x32,0x39,0x39,0x39,0x38,0x31,0x38,0x33,0x32,0x35,0x30,0x34, + 0x32,0x37,0x32,0x34,0x36,0x30,0x39,0x33,0x37,0x35,0x20,0x2a,0x20,0x5f,0x31,0x35, + 0x31,0x29,0x29,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x35,0x31,0x36,0x30,0x30,0x30, + 0x30,0x31,0x37,0x35,0x32,0x33,0x37,0x36,0x35,0x35,0x36,0x33,0x39,0x36,0x34,0x38, + 0x34,0x33,0x37,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x29,0x20,0x2b, + 0x20,0x28,0x28,0x28,0x28,0x30,0x2e,0x31,0x35,0x33,0x34,0x35,0x39,0x39,0x39,0x35, + 0x39,0x38,0x35,0x30,0x33,0x31,0x31,0x32,0x37,0x39,0x32,0x39,0x36,0x38,0x37,0x35, + 0x20,0x2a,0x20,0x5f,0x32,0x35,0x38,0x29,0x20,0x2d,0x20,0x28,0x30,0x2e,0x32,0x36, + 0x37,0x35,0x36,0x30,0x30,0x30,0x35,0x31,0x38,0x37,0x39,0x38,0x38,0x32,0x38,0x31, + 0x32,0x35,0x20,0x2a,0x20,0x5f,0x32,0x35,0x34,0x29,0x29,0x20,0x2b,0x20,0x28,0x30, + 0x2e,0x30,0x36,0x36,0x36,0x39,0x39,0x39,0x39,0x36,0x35,0x39,0x30,0x36,0x31,0x34, + 0x33,0x31,0x38,0x38,0x34,0x37,0x36,0x35,0x36,0x32,0x35,0x20,0x2a,0x20,0x5f,0x31, + 0x35,0x31,0x29,0x29,0x20,0x2b,0x20,0x30,0x2e,0x32,0x36,0x36,0x38,0x38,0x30,0x30, + 0x30,0x35,0x35,0x39,0x38,0x30,0x36,0x38,0x32,0x33,0x37,0x33,0x30,0x34,0x36,0x38, + 0x37,0x35,0x29,0x29,0x20,0x2a,0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x50, + 0x65,0x72,0x65,0x7a,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x33,0x29,0x29,0x20,0x2f,0x20,0x6d,0x61,0x78,0x28,0x70,0x72,0x65,0x65, + 0x74,0x68,0x61,0x6d,0x50,0x65,0x72,0x65,0x7a,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x34,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x31,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x34,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x33, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x34,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x34,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x36,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x37,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39, + 0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35, + 0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x35,0x30,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x28,0x28,0x28,0x28, + 0x28,0x28,0x34,0x2e,0x30,0x34,0x35,0x33,0x30,0x30,0x30,0x30,0x36,0x38,0x36,0x36, + 0x34,0x35,0x35,0x30,0x37,0x38,0x31,0x32,0x35,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34, + 0x29,0x20,0x2d,0x20,0x34,0x2e,0x39,0x37,0x31,0x30,0x30,0x30,0x31,0x39,0x34,0x35, + 0x34,0x39,0x35,0x36,0x30,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x74, + 0x61,0x6e,0x28,0x28,0x30,0x2e,0x34,0x34,0x34,0x34,0x34,0x34,0x34,0x34,0x37,0x37, + 0x35,0x35,0x38,0x31,0x33,0x35,0x39,0x38,0x36,0x33,0x32,0x38,0x31,0x32,0x35,0x20, + 0x2d,0x20,0x28,0x5f,0x31,0x35,0x34,0x20,0x2a,0x20,0x30,0x2e,0x30,0x30,0x38,0x33, + 0x33,0x33,0x33,0x33,0x33,0x37,0x36,0x37,0x39,0x35,0x30,0x35,0x33,0x34,0x38,0x32, + 0x30,0x35,0x35,0x36,0x36,0x34,0x30,0x36,0x32,0x35,0x29,0x29,0x20,0x2a,0x20,0x28, + 0x33,0x2e,0x31,0x34,0x31,0x35,0x39,0x32,0x37,0x34,0x31,0x30,0x31,0x32,0x35,0x37, + 0x33,0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x20,0x2d,0x20,0x28,0x32,0x2e,0x30,0x20, + 0x2a,0x20,0x5f,0x31,0x35,0x31,0x29,0x29,0x29,0x29,0x20,0x2d,0x20,0x28,0x30,0x2e, + 0x32,0x31,0x35,0x34,0x39,0x39,0x39,0x39,0x37,0x31,0x33,0x38,0x39,0x37,0x37,0x30, + 0x35,0x30,0x37,0x38,0x31,0x32,0x35,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x29, + 0x20,0x2b,0x20,0x32,0x2e,0x34,0x31,0x39,0x31,0x39,0x39,0x39,0x34,0x33,0x35,0x34, + 0x32,0x34,0x38,0x30,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x70,0x72,0x65, + 0x65,0x74,0x68,0x61,0x6d,0x50,0x65,0x72,0x65,0x7a,0x28,0x70,0x61,0x72,0x61,0x6d, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x29, + 0x29,0x20,0x2f,0x20,0x6d,0x61,0x78,0x28,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d, + 0x50,0x65,0x72,0x65,0x7a,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x39, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x30,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x33,0x31,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37, + 0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35, + 0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x29,0x2c,0x20,0x30, + 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x35,0x31,0x20,0x3d,0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61, + 0x6d,0x58,0x79,0x59,0x5f,0x74,0x6f,0x5f,0x58,0x59,0x5a,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x34,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x39,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x6d,0x61,0x78,0x28,0x70,0x72,0x65,0x65,0x74,0x68, + 0x61,0x6d,0x58,0x59,0x5a,0x5f,0x74,0x6f,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f, + 0x73,0x72,0x67,0x62,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x31,0x29,0x2c,0x20, + 0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76, + 0x65,0x63,0x33,0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x53,0x6b,0x79,0x53, + 0x63,0x61,0x6c,0x65,0x64,0x28,0x76,0x65,0x63,0x33,0x20,0x76,0x69,0x65,0x77,0x5f, + 0x64,0x69,0x72,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x73,0x75,0x6e,0x5f,0x64,0x69, + 0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x74,0x75,0x72,0x62,0x69,0x64,0x69, + 0x74,0x79,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x66,0x61,0x64,0x65,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x20,0x3d,0x20,0x76,0x69,0x65,0x77,0x5f,0x64,0x69,0x72,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20, + 0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x74,0x75,0x72, + 0x62,0x69,0x64,0x69,0x74,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x28,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x53,0x6b,0x79,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x20,0x2a,0x20,0x30,0x2e,0x30,0x35,0x39, + 0x39,0x39,0x39,0x39,0x39,0x38,0x36,0x35,0x38,0x38,0x39,0x35,0x34,0x39,0x32,0x35, + 0x35,0x33,0x37,0x31,0x30,0x39,0x33,0x37,0x35,0x29,0x20,0x2a,0x20,0x66,0x61,0x64, + 0x65,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x35,0x34, + 0x31,0x20,0x3d,0x20,0x28,0x76,0x5f,0x75,0x76,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29, + 0x20,0x2d,0x20,0x76,0x65,0x63,0x32,0x28,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x6e, + 0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x28,0x75,0x62,0x5f,0x66,0x61,0x63, + 0x65,0x5b,0x32,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x75,0x62,0x5f,0x66, + 0x61,0x63,0x65,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x5f,0x35,0x34, + 0x31,0x2e,0x78,0x29,0x29,0x20,0x2b,0x20,0x28,0x75,0x62,0x5f,0x66,0x61,0x63,0x65, + 0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x5f,0x35,0x34,0x31,0x2e,0x79, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x75,0x62,0x5f,0x66,0x61,0x63,0x65,0x5b,0x33, + 0x5d,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x75,0x62,0x5f,0x66,0x61, + 0x63,0x65,0x5b,0x33,0x5d,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x75,0x62,0x5f, + 0x66,0x61,0x63,0x65,0x5b,0x32,0x5d,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f, + 0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28, + 0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x53,0x6b,0x79,0x53,0x63,0x61,0x6c,0x65, + 0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x33,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + static float4 gl_Position; + static int gl_VertexIndex; + static float2 v_uv; + + struct SPIRV_Cross_Input + { + uint gl_VertexIndex : SV_VertexID; + }; + + struct SPIRV_Cross_Output + { + float2 v_uv : TEXCOORD0; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + float2 _27 = (float2(float((gl_VertexIndex << 1) & 2), float(gl_VertexIndex & 2)) * 2.0f) - 1.0f.xx; + v_uv = (_27 * 0.5f) + 0.5f.xx; + gl_Position = float4(_27, 0.0f, 1.0f); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_VertexIndex = int(stage_input.gl_VertexIndex); + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.v_uv = v_uv; + return stage_output; + } +*/ +static const uint8_t sky_to_cube_vs_source_hlsl5[716] = { + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c, + 0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69, + 0x63,0x20,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49, + 0x6e,0x64,0x65,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x32,0x20,0x76,0x5f,0x75,0x76,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63, + 0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e, + 0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x67, + 0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x3a,0x20, + 0x53,0x56,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x44,0x3b,0x0a,0x7d,0x3b,0x0a, + 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, + 0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x76,0x5f,0x75,0x76,0x20,0x3a,0x20,0x54, + 0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e, + 0x20,0x3a,0x20,0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a, + 0x7d,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61, + 0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x32,0x20,0x5f,0x32,0x37,0x20,0x3d,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28, + 0x66,0x6c,0x6f,0x61,0x74,0x28,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78, + 0x49,0x6e,0x64,0x65,0x78,0x20,0x3c,0x3c,0x20,0x31,0x29,0x20,0x26,0x20,0x32,0x29, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65, + 0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x26,0x20,0x32,0x29,0x29,0x20,0x2a,0x20,0x32, + 0x2e,0x30,0x66,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x5f,0x75,0x76,0x20,0x3d,0x20,0x28,0x5f,0x32,0x37,0x20, + 0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2e,0x78, + 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69, + 0x6f,0x6e,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x32,0x37,0x2c, + 0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74, + 0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, + 0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65, + 0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c, + 0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x3d,0x20,0x69, + 0x6e,0x74,0x28,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x67, + 0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73, + 0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75, + 0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f, + 0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69, + 0x6f,0x6e,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70, + 0x75,0x74,0x2e,0x76,0x5f,0x75,0x76,0x20,0x3d,0x20,0x76,0x5f,0x75,0x76,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65, + 0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + cbuffer ub_face : register(b0) + { + float4 _546_face_right : packoffset(c0); + float4 _546_face_up : packoffset(c1); + float4 _546_face_forward : packoffset(c2); + float4 _546_sun_dir_world : packoffset(c3); + }; + + + static float2 v_uv; + static float4 out_color; + + struct SPIRV_Cross_Input + { + float2 v_uv : TEXCOORD0; + }; + + struct SPIRV_Cross_Output + { + float4 out_color : SV_Target0; + }; + + float preethamPerez(float cos_theta, float cos_gamma, float gamma, float A, float B, float C, float D, float E) + { + return (1.0f + (A * exp(B / max(cos_theta, 0.00999999977648258209228515625f)))) * ((1.0f + (C * exp(D * gamma))) + ((E * cos_gamma) * cos_gamma)); + } + + float3 preethamXyY_to_XYZ(float x, float y, float Y) + { + float _77 = max(y, 9.9999997473787516355514526367188e-06f); + return float3((Y * x) / _77, Y, (Y * ((1.0f - x) - y)) / _77); + } + + float3 preethamXYZ_to_linear_srgb(float3 c) + { + return float3(dot(c, float3(3.240454196929931640625f, -1.537138462066650390625f, -0.498531401157379150390625f)), dot(c, float3(-0.969265997409820556640625f, 1.87601077556610107421875f, 0.04155600070953369140625f)), dot(c, float3(0.0556433983147144317626953125f, -0.2040258944034576416015625f, 1.05722522735595703125f))); + } + + float3 preethamSky(float3 view_dir, float3 sun_dir, float turbidity) + { + float _122 = clamp(sun_dir.y, 0.0f, 1.0f); + float3 _135 = normalize(float3(view_dir.x, max(view_dir.y, 0.0f) + 0.00999999977648258209228515625f, view_dir.z)); + float _139 = max(_135.y, 0.0f); + float _145 = clamp(dot(sun_dir, _135), -1.0f, 1.0f); + float _148 = acos(_145); + float _151 = acos(_122); + float _154 = max(turbidity, 1.0f); + float _158 = _154 * _154; + float _164 = (0.1787000000476837158203125f * _154) - 1.4630000591278076171875f; + float _170 = ((-0.3553999960422515869140625f) * _154) + 0.4275000095367431640625f; + float _176 = ((-0.0227000005543231964111328125f) * _154) + 5.325099945068359375f; + float _182 = (0.12060000002384185791015625f * _154) - 2.5771000385284423828125f; + float _188 = ((-0.0670000016689300537109375f) * _154) + 0.370299994945526123046875f; + float _194 = ((-0.01930000074207782745361328125f) * _154) - 0.2592000067234039306640625f; + float _200 = ((-0.066500000655651092529296875f) * _154) + 0.0007999999797903001308441162109375f; + float _206 = ((-0.00039999998989515006542205810546875f) * _154) + 0.2125000059604644775390625f; + float _212 = ((-0.0640999972820281982421875f) * _154) - 0.898899972438812255859375f; + float _218 = ((-0.0032999999821186065673828125f) * _154) + 0.0452000014483928680419921875f; + float _224 = ((-0.0166999995708465576171875f) * _154) - 0.26080000400543212890625f; + float _230 = ((-0.0949999988079071044921875f) * _154) + 0.009200000204145908355712890625f; + float _236 = ((-0.0078999996185302734375f) * _154) + 0.21019999682903289794921875f; + float _242 = ((-0.04410000145435333251953125f) * _154) - 1.65369999408721923828125f; + float _248 = ((-0.01090000011026859283447265625f) * _154) + 0.05290000140666961669921875f; + float _254 = _151 * _151; + float _258 = _254 * _151; + float param = _139; + float param_1 = _145; + float param_2 = _148; + float param_3 = _164; + float param_4 = _170; + float param_5 = _176; + float param_6 = _182; + float param_7 = _188; + float param_8 = _139; + float param_9 = _145; + float param_10 = _148; + float param_11 = _194; + float param_12 = _200; + float param_13 = _206; + float param_14 = _212; + float param_15 = _218; + float param_16 = _139; + float param_17 = _145; + float param_18 = _148; + float param_19 = _224; + float param_20 = _230; + float param_21 = _236; + float param_22 = _242; + float param_23 = _248; + float param_24 = 1.0f; + float param_25 = _122; + float param_26 = _151; + float param_27 = _164; + float param_28 = _170; + float param_29 = _176; + float param_30 = _182; + float param_31 = _188; + float param_32 = 1.0f; + float param_33 = _122; + float param_34 = _151; + float param_35 = _194; + float param_36 = _200; + float param_37 = _206; + float param_38 = _212; + float param_39 = _218; + float param_40 = 1.0f; + float param_41 = _122; + float param_42 = _151; + float param_43 = _224; + float param_44 = _230; + float param_45 = _236; + float param_46 = _242; + float param_47 = _248; + float param_48 = (((((((0.001659999950788915157318115234375f * _258) - (0.00374999991618096828460693359375f * _254)) + (0.0020900000818073749542236328125f * _151)) * _158) + ((((((-0.02903000079095363616943359375f) * _258) + (0.063770003616809844970703125f * _254)) - (0.0320199988782405853271484375f * _151)) + 0.003940000198781490325927734375f) * _154)) + ((((0.116930000483989715576171875f * _258) - (0.21196000277996063232421875f * _254)) + (0.060520000755786895751953125f * _151)) + 0.25885999202728271484375f)) * preethamPerez(param_8, param_9, param_10, param_11, param_12, param_13, param_14, param_15)) / max(preethamPerez(param_32, param_33, param_34, param_35, param_36, param_37, param_38, param_39), 9.9999997473787516355514526367188e-06f); + float param_49 = (((((((0.00274999998509883880615234375f * _258) - (0.006099999882280826568603515625f * _254)) + (0.0031699999235570430755615234375f * _151)) * _158) + ((((((-0.042139999568462371826171875f) * _258) + (0.08969999849796295166015625f * _254)) - (0.04152999818325042724609375f * _151)) + 0.0051600001752376556396484375f) * _154)) + ((((0.1534599959850311279296875f * _258) - (0.26756000518798828125f * _254)) + (0.06669999659061431884765625f * _151)) + 0.2668800055980682373046875f)) * preethamPerez(param_16, param_17, param_18, param_19, param_20, param_21, param_22, param_23)) / max(preethamPerez(param_40, param_41, param_42, param_43, param_44, param_45, param_46, param_47), 9.9999997473787516355514526367188e-06f); + float param_50 = max(((((((4.045300006866455078125f * _154) - 4.971000194549560546875f) * tan((0.4444444477558135986328125f - (_154 * 0.008333333767950534820556640625f)) * (3.1415927410125732421875f - (2.0f * _151)))) - (0.21549999713897705078125f * _154)) + 2.41919994354248046875f) * preethamPerez(param, param_1, param_2, param_3, param_4, param_5, param_6, param_7)) / max(preethamPerez(param_24, param_25, param_26, param_27, param_28, param_29, param_30, param_31), 9.9999997473787516355514526367188e-06f), 0.0f); + float3 param_51 = preethamXyY_to_XYZ(param_48, param_49, param_50); + return max(preethamXYZ_to_linear_srgb(param_51), 0.0f.xxx); + } + + float3 preethamSkyScaled(float3 view_dir, float3 sun_dir, float turbidity, float fade) + { + float3 param = view_dir; + float3 param_1 = sun_dir; + float param_2 = turbidity; + return (preethamSky(param, param_1, param_2) * 0.0599999986588954925537109375f) * fade; + } + + void frag_main() + { + float2 _541 = (v_uv * 2.0f) - 1.0f.xx; + float3 param = normalize((_546_face_forward.xyz + (_546_face_right.xyz * _541.x)) + (_546_face_up.xyz * _541.y)); + float3 param_1 = _546_sun_dir_world.xyz; + float param_2 = _546_sun_dir_world.w; + float param_3 = _546_face_forward.w; + out_color = float4(preethamSkyScaled(param, param_1, param_2, param_3), 1.0f); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + v_uv = stage_input.v_uv; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.out_color = out_color; + return stage_output; + } +*/ +static const uint8_t sky_to_cube_fs_source_hlsl5[7428] = { + 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x66,0x61,0x63,0x65,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x35,0x34,0x36, + 0x5f,0x66,0x61,0x63,0x65,0x5f,0x72,0x69,0x67,0x68,0x74,0x20,0x3a,0x20,0x70,0x61, + 0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x35,0x34,0x36,0x5f,0x66,0x61, + 0x63,0x65,0x5f,0x75,0x70,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73, + 0x65,0x74,0x28,0x63,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x5f,0x35,0x34,0x36,0x5f,0x66,0x61,0x63,0x65,0x5f,0x66,0x6f,0x72, + 0x77,0x61,0x72,0x64,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65, + 0x74,0x28,0x63,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x5f,0x35,0x34,0x36,0x5f,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65, + 0x74,0x28,0x63,0x33,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x0a,0x73,0x74,0x61,0x74, + 0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x76,0x5f,0x75,0x76,0x3b,0x0a, + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75, + 0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74, + 0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70, + 0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20, + 0x76,0x5f,0x75,0x76,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30, + 0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49, + 0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x53,0x56,0x5f,0x54,0x61,0x72,0x67, + 0x65,0x74,0x30,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x50,0x65,0x72,0x65,0x7a,0x28,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x63,0x6f,0x73,0x5f,0x74,0x68,0x65,0x74,0x61,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x63,0x6f,0x73,0x5f,0x67,0x61,0x6d,0x6d,0x61,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x67,0x61,0x6d,0x6d,0x61,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x41,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x42,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x43,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x44,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x45,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2b,0x20,0x28,0x41, + 0x20,0x2a,0x20,0x65,0x78,0x70,0x28,0x42,0x20,0x2f,0x20,0x6d,0x61,0x78,0x28,0x63, + 0x6f,0x73,0x5f,0x74,0x68,0x65,0x74,0x61,0x2c,0x20,0x30,0x2e,0x30,0x30,0x39,0x39, + 0x39,0x39,0x39,0x39,0x39,0x37,0x37,0x36,0x34,0x38,0x32,0x35,0x38,0x32,0x30,0x39, + 0x32,0x32,0x38,0x35,0x31,0x35,0x36,0x32,0x35,0x66,0x29,0x29,0x29,0x29,0x20,0x2a, + 0x20,0x28,0x28,0x31,0x2e,0x30,0x66,0x20,0x2b,0x20,0x28,0x43,0x20,0x2a,0x20,0x65, + 0x78,0x70,0x28,0x44,0x20,0x2a,0x20,0x67,0x61,0x6d,0x6d,0x61,0x29,0x29,0x29,0x20, + 0x2b,0x20,0x28,0x28,0x45,0x20,0x2a,0x20,0x63,0x6f,0x73,0x5f,0x67,0x61,0x6d,0x6d, + 0x61,0x29,0x20,0x2a,0x20,0x63,0x6f,0x73,0x5f,0x67,0x61,0x6d,0x6d,0x61,0x29,0x29, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x72,0x65,0x65, + 0x74,0x68,0x61,0x6d,0x58,0x79,0x59,0x5f,0x74,0x6f,0x5f,0x58,0x59,0x5a,0x28,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x78,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x79,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x59,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x37,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28, + 0x79,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37, + 0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36, + 0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x59, + 0x20,0x2a,0x20,0x78,0x29,0x20,0x2f,0x20,0x5f,0x37,0x37,0x2c,0x20,0x59,0x2c,0x20, + 0x28,0x59,0x20,0x2a,0x20,0x28,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x78,0x29, + 0x20,0x2d,0x20,0x79,0x29,0x29,0x20,0x2f,0x20,0x5f,0x37,0x37,0x29,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61, + 0x6d,0x58,0x59,0x5a,0x5f,0x74,0x6f,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x73, + 0x72,0x67,0x62,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x63,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x28,0x64,0x6f,0x74,0x28,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, + 0x33,0x2e,0x32,0x34,0x30,0x34,0x35,0x34,0x31,0x39,0x36,0x39,0x32,0x39,0x39,0x33, + 0x31,0x36,0x34,0x30,0x36,0x32,0x35,0x66,0x2c,0x20,0x2d,0x31,0x2e,0x35,0x33,0x37, + 0x31,0x33,0x38,0x34,0x36,0x32,0x30,0x36,0x36,0x36,0x35,0x30,0x33,0x39,0x30,0x36, + 0x32,0x35,0x66,0x2c,0x20,0x2d,0x30,0x2e,0x34,0x39,0x38,0x35,0x33,0x31,0x34,0x30, + 0x31,0x31,0x35,0x37,0x33,0x37,0x39,0x31,0x35,0x30,0x33,0x39,0x30,0x36,0x32,0x35, + 0x66,0x29,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x2d,0x30,0x2e,0x39,0x36,0x39,0x32,0x36,0x35,0x39,0x39,0x37,0x34, + 0x30,0x39,0x38,0x32,0x30,0x35,0x35,0x36,0x36,0x34,0x30,0x36,0x32,0x35,0x66,0x2c, + 0x20,0x31,0x2e,0x38,0x37,0x36,0x30,0x31,0x30,0x37,0x37,0x35,0x35,0x36,0x36,0x31, + 0x30,0x31,0x30,0x37,0x34,0x32,0x31,0x38,0x37,0x35,0x66,0x2c,0x20,0x30,0x2e,0x30, + 0x34,0x31,0x35,0x35,0x36,0x30,0x30,0x30,0x37,0x30,0x39,0x35,0x33,0x33,0x36,0x39, + 0x31,0x34,0x30,0x36,0x32,0x35,0x66,0x29,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x63, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x35,0x35,0x36,0x34, + 0x33,0x33,0x39,0x38,0x33,0x31,0x34,0x37,0x31,0x34,0x34,0x33,0x31,0x37,0x36,0x32, + 0x36,0x39,0x35,0x33,0x31,0x32,0x35,0x66,0x2c,0x20,0x2d,0x30,0x2e,0x32,0x30,0x34, + 0x30,0x32,0x35,0x38,0x39,0x34,0x34,0x30,0x33,0x34,0x35,0x37,0x36,0x34,0x31,0x36, + 0x30,0x31,0x35,0x36,0x32,0x35,0x66,0x2c,0x20,0x31,0x2e,0x30,0x35,0x37,0x32,0x32, + 0x35,0x32,0x32,0x37,0x33,0x35,0x35,0x39,0x35,0x37,0x30,0x33,0x31,0x32,0x35,0x66, + 0x29,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, + 0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x53,0x6b,0x79,0x28,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x76,0x69,0x65,0x77,0x5f,0x64,0x69,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x74,0x75,0x72,0x62,0x69,0x64,0x69,0x74,0x79,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x32,0x20,0x3d,0x20, + 0x63,0x6c,0x61,0x6d,0x70,0x28,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x2e,0x79,0x2c, + 0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x33,0x35,0x20,0x3d,0x20, + 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x28,0x76,0x69,0x65,0x77,0x5f,0x64,0x69,0x72,0x2e,0x78,0x2c,0x20,0x6d,0x61,0x78, + 0x28,0x76,0x69,0x65,0x77,0x5f,0x64,0x69,0x72,0x2e,0x79,0x2c,0x20,0x30,0x2e,0x30, + 0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x39,0x39,0x39,0x39,0x39,0x39,0x39, + 0x37,0x37,0x36,0x34,0x38,0x32,0x35,0x38,0x32,0x30,0x39,0x32,0x32,0x38,0x35,0x31, + 0x35,0x36,0x32,0x35,0x66,0x2c,0x20,0x76,0x69,0x65,0x77,0x5f,0x64,0x69,0x72,0x2e, + 0x7a,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x33,0x39,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x5f,0x31,0x33,0x35,0x2e,0x79, + 0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x34,0x35,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28, + 0x64,0x6f,0x74,0x28,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x2c,0x20,0x5f,0x31,0x33, + 0x35,0x29,0x2c,0x20,0x2d,0x31,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x38, + 0x20,0x3d,0x20,0x61,0x63,0x6f,0x73,0x28,0x5f,0x31,0x34,0x35,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x31,0x20,0x3d,0x20, + 0x61,0x63,0x6f,0x73,0x28,0x5f,0x31,0x32,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x34,0x20,0x3d,0x20,0x6d,0x61,0x78, + 0x28,0x74,0x75,0x72,0x62,0x69,0x64,0x69,0x74,0x79,0x2c,0x20,0x31,0x2e,0x30,0x66, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35, + 0x38,0x20,0x3d,0x20,0x5f,0x31,0x35,0x34,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x34,0x20, + 0x3d,0x20,0x28,0x30,0x2e,0x31,0x37,0x38,0x37,0x30,0x30,0x30,0x30,0x30,0x30,0x34, + 0x37,0x36,0x38,0x33,0x37,0x31,0x35,0x38,0x32,0x30,0x33,0x31,0x32,0x35,0x66,0x20, + 0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2d,0x20,0x31,0x2e,0x34,0x36,0x33,0x30, + 0x30,0x30,0x30,0x35,0x39,0x31,0x32,0x37,0x38,0x30,0x37,0x36,0x31,0x37,0x31,0x38, + 0x37,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x37,0x30,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x33,0x35,0x35,0x33,0x39, + 0x39,0x39,0x39,0x36,0x30,0x34,0x32,0x32,0x35,0x31,0x35,0x38,0x36,0x39,0x31,0x34, + 0x30,0x36,0x32,0x35,0x66,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2b, + 0x20,0x30,0x2e,0x34,0x32,0x37,0x35,0x30,0x30,0x30,0x30,0x39,0x35,0x33,0x36,0x37, + 0x34,0x33,0x31,0x36,0x34,0x30,0x36,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x37,0x36,0x20,0x3d,0x20,0x28,0x28,0x2d, + 0x30,0x2e,0x30,0x32,0x32,0x37,0x30,0x30,0x30,0x30,0x30,0x35,0x35,0x34,0x33,0x32, + 0x33,0x31,0x39,0x36,0x34,0x31,0x31,0x31,0x33,0x32,0x38,0x31,0x32,0x35,0x66,0x29, + 0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2b,0x20,0x35,0x2e,0x33,0x32,0x35, + 0x30,0x39,0x39,0x39,0x34,0x35,0x30,0x36,0x38,0x33,0x35,0x39,0x33,0x37,0x35,0x66, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x38,0x32, + 0x20,0x3d,0x20,0x28,0x30,0x2e,0x31,0x32,0x30,0x36,0x30,0x30,0x30,0x30,0x30,0x30, + 0x32,0x33,0x38,0x34,0x31,0x38,0x35,0x37,0x39,0x31,0x30,0x31,0x35,0x36,0x32,0x35, + 0x66,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2d,0x20,0x32,0x2e,0x35,0x37, + 0x37,0x31,0x30,0x30,0x30,0x33,0x38,0x35,0x32,0x38,0x34,0x34,0x32,0x33,0x38,0x32, + 0x38,0x31,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x38,0x38,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x36,0x37, + 0x30,0x30,0x30,0x30,0x30,0x31,0x36,0x36,0x38,0x39,0x33,0x30,0x30,0x35,0x33,0x37, + 0x31,0x30,0x39,0x33,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29, + 0x20,0x2b,0x20,0x30,0x2e,0x33,0x37,0x30,0x32,0x39,0x39,0x39,0x39,0x34,0x39,0x34, + 0x35,0x35,0x32,0x36,0x31,0x32,0x33,0x30,0x34,0x36,0x38,0x37,0x35,0x66,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x39,0x34,0x20,0x3d, + 0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x31,0x39,0x33,0x30,0x30,0x30,0x30,0x30,0x37, + 0x34,0x32,0x30,0x37,0x37,0x38,0x32,0x37,0x34,0x35,0x33,0x36,0x31,0x33,0x32,0x38, + 0x31,0x32,0x35,0x66,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2d,0x20, + 0x30,0x2e,0x32,0x35,0x39,0x32,0x30,0x30,0x30,0x30,0x36,0x37,0x32,0x33,0x34,0x30, + 0x33,0x39,0x33,0x30,0x36,0x36,0x34,0x30,0x36,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x30,0x30,0x20,0x3d,0x20,0x28, + 0x28,0x2d,0x30,0x2e,0x30,0x36,0x36,0x35,0x30,0x30,0x30,0x30,0x30,0x36,0x35,0x35, + 0x36,0x35,0x31,0x30,0x39,0x32,0x35,0x32,0x39,0x32,0x39,0x36,0x38,0x37,0x35,0x66, + 0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30, + 0x30,0x37,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x39,0x37,0x39,0x30,0x33,0x30,0x30, + 0x31,0x33,0x30,0x38,0x34,0x34,0x31,0x31,0x36,0x32,0x31,0x30,0x39,0x33,0x37,0x35, + 0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x30, + 0x36,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x30,0x30,0x33,0x39,0x39,0x39, + 0x39,0x39,0x39,0x38,0x39,0x38,0x39,0x35,0x31,0x35,0x30,0x30,0x36,0x35,0x34,0x32, + 0x32,0x30,0x35,0x38,0x31,0x30,0x35,0x34,0x36,0x38,0x37,0x35,0x66,0x29,0x20,0x2a, + 0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2b,0x20,0x30,0x2e,0x32,0x31,0x32,0x35,0x30, + 0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39, + 0x30,0x36,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x32,0x31,0x32,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x36,0x34, + 0x30,0x39,0x39,0x39,0x39,0x37,0x32,0x38,0x32,0x30,0x32,0x38,0x31,0x39,0x38,0x32, + 0x34,0x32,0x31,0x38,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29, + 0x20,0x2d,0x20,0x30,0x2e,0x38,0x39,0x38,0x38,0x39,0x39,0x39,0x37,0x32,0x34,0x33, + 0x38,0x38,0x31,0x32,0x32,0x35,0x35,0x38,0x35,0x39,0x33,0x37,0x35,0x66,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x38,0x20,0x3d, + 0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x30,0x33,0x32,0x39,0x39,0x39,0x39,0x39,0x39, + 0x38,0x32,0x31,0x31,0x38,0x36,0x30,0x36,0x35,0x36,0x37,0x33,0x38,0x32,0x38,0x31, + 0x32,0x35,0x66,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2b,0x20,0x30, + 0x2e,0x30,0x34,0x35,0x32,0x30,0x30,0x30,0x30,0x31,0x34,0x34,0x38,0x33,0x39,0x32, + 0x38,0x36,0x38,0x30,0x34,0x31,0x39,0x39,0x32,0x31,0x38,0x37,0x35,0x66,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x32,0x34,0x20,0x3d, + 0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x31,0x36,0x36,0x39,0x39,0x39,0x39,0x39,0x35, + 0x37,0x30,0x38,0x34,0x36,0x35,0x35,0x37,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x66, + 0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2d,0x20,0x30,0x2e,0x32,0x36, + 0x30,0x38,0x30,0x30,0x30,0x30,0x34,0x30,0x30,0x35,0x34,0x33,0x32,0x31,0x32,0x38, + 0x39,0x30,0x36,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x32,0x33,0x30,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x39, + 0x34,0x39,0x39,0x39,0x39,0x39,0x38,0x38,0x30,0x37,0x39,0x30,0x37,0x31,0x30,0x34, + 0x34,0x39,0x32,0x31,0x38,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34, + 0x29,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x39,0x32,0x30,0x30,0x30,0x30,0x30,0x32, + 0x30,0x34,0x31,0x34,0x35,0x39,0x30,0x38,0x33,0x35,0x35,0x37,0x31,0x32,0x38,0x39, + 0x30,0x36,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x32,0x33,0x36,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x30,0x37, + 0x38,0x39,0x39,0x39,0x39,0x39,0x36,0x31,0x38,0x35,0x33,0x30,0x32,0x37,0x33,0x34, + 0x33,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2b,0x20, + 0x30,0x2e,0x32,0x31,0x30,0x31,0x39,0x39,0x39,0x39,0x36,0x38,0x32,0x39,0x30,0x33, + 0x32,0x38,0x39,0x37,0x39,0x34,0x39,0x32,0x31,0x38,0x37,0x35,0x66,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x34,0x32,0x20,0x3d,0x20, + 0x28,0x28,0x2d,0x30,0x2e,0x30,0x34,0x34,0x31,0x30,0x30,0x30,0x30,0x31,0x34,0x35, + 0x34,0x33,0x35,0x33,0x33,0x33,0x32,0x35,0x31,0x39,0x35,0x33,0x31,0x32,0x35,0x66, + 0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2d,0x20,0x31,0x2e,0x36,0x35, + 0x33,0x36,0x39,0x39,0x39,0x39,0x34,0x30,0x38,0x37,0x32,0x31,0x39,0x32,0x33,0x38, + 0x32,0x38,0x31,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x32,0x34,0x38,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x31, + 0x30,0x39,0x30,0x30,0x30,0x30,0x30,0x31,0x31,0x30,0x32,0x36,0x38,0x35,0x39,0x32, + 0x38,0x33,0x34,0x34,0x37,0x32,0x36,0x35,0x36,0x32,0x35,0x66,0x29,0x20,0x2a,0x20, + 0x5f,0x31,0x35,0x34,0x29,0x20,0x2b,0x20,0x30,0x2e,0x30,0x35,0x32,0x39,0x30,0x30, + 0x30,0x30,0x31,0x34,0x30,0x36,0x36,0x36,0x39,0x36,0x31,0x36,0x36,0x39,0x39,0x32, + 0x31,0x38,0x37,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x32,0x35,0x34,0x20,0x3d,0x20,0x5f,0x31,0x35,0x31,0x20,0x2a,0x20,0x5f, + 0x31,0x35,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x32,0x35,0x38,0x20,0x3d,0x20,0x5f,0x32,0x35,0x34,0x20,0x2a,0x20,0x5f,0x31,0x35, + 0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x20,0x3d,0x20,0x5f,0x31,0x33,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f, + 0x31,0x34,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x31,0x34,0x38,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, + 0x20,0x3d,0x20,0x5f,0x31,0x36,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x31,0x37, + 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x5f,0x31,0x37,0x36,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d, + 0x20,0x5f,0x31,0x38,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x5f,0x31,0x38,0x38,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x38,0x20,0x3d,0x20,0x5f,0x31,0x33,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x5f, + 0x31,0x34,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x5f,0x31,0x34,0x38,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x31,0x20,0x3d,0x20,0x5f,0x31,0x39,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20, + 0x5f,0x32,0x30,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20,0x5f,0x32,0x30,0x36,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x34,0x20,0x3d,0x20,0x5f,0x32,0x31,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d, + 0x20,0x5f,0x32,0x31,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x5f,0x31,0x33,0x39, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x37,0x20,0x3d,0x20,0x5f,0x31,0x34,0x35,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20, + 0x3d,0x20,0x5f,0x31,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20,0x5f,0x32,0x32, + 0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x30,0x20,0x3d,0x20,0x5f,0x32,0x33,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31, + 0x20,0x3d,0x20,0x5f,0x32,0x33,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x20,0x3d,0x20,0x5f,0x32, + 0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x33,0x20,0x3d,0x20,0x5f,0x32,0x34,0x38,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x34,0x20,0x3d,0x20,0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x35,0x20,0x3d,0x20,0x5f, + 0x31,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x36,0x20,0x3d,0x20,0x5f,0x31,0x35,0x31,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x37,0x20,0x3d,0x20,0x5f,0x31,0x36,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x38,0x20,0x3d,0x20, + 0x5f,0x31,0x37,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x39,0x20,0x3d,0x20,0x5f,0x31,0x37,0x36,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x33,0x30,0x20,0x3d,0x20,0x5f,0x31,0x38,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x31,0x20,0x3d, + 0x20,0x5f,0x31,0x38,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x32,0x20,0x3d,0x20,0x31,0x2e,0x30,0x66, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x33,0x33,0x20,0x3d,0x20,0x5f,0x31,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x20, + 0x3d,0x20,0x5f,0x31,0x35,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x35,0x20,0x3d,0x20,0x5f,0x31,0x39, + 0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x36,0x20,0x3d,0x20,0x5f,0x32,0x30,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x37, + 0x20,0x3d,0x20,0x5f,0x32,0x30,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x38,0x20,0x3d,0x20,0x5f,0x32, + 0x31,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x39,0x20,0x3d,0x20,0x5f,0x32,0x31,0x38,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, + 0x30,0x20,0x3d,0x20,0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x31,0x20,0x3d,0x20,0x5f, + 0x31,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x34,0x32,0x20,0x3d,0x20,0x5f,0x31,0x35,0x31,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x34,0x33,0x20,0x3d,0x20,0x5f,0x32,0x32,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x34,0x20,0x3d,0x20, + 0x5f,0x32,0x33,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x35,0x20,0x3d,0x20,0x5f,0x32,0x33,0x36,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x34,0x36,0x20,0x3d,0x20,0x5f,0x32,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x37,0x20,0x3d, + 0x20,0x5f,0x32,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x38,0x20,0x3d,0x20,0x28,0x28,0x28,0x28, + 0x28,0x28,0x28,0x30,0x2e,0x30,0x30,0x31,0x36,0x35,0x39,0x39,0x39,0x39,0x39,0x35, + 0x30,0x37,0x38,0x38,0x39,0x31,0x35,0x31,0x35,0x37,0x33,0x31,0x38,0x31,0x31,0x35, + 0x32,0x33,0x34,0x33,0x37,0x35,0x66,0x20,0x2a,0x20,0x5f,0x32,0x35,0x38,0x29,0x20, + 0x2d,0x20,0x28,0x30,0x2e,0x30,0x30,0x33,0x37,0x34,0x39,0x39,0x39,0x39,0x39,0x31, + 0x36,0x31,0x38,0x30,0x39,0x36,0x38,0x32,0x38,0x34,0x36,0x30,0x36,0x39,0x33,0x33, + 0x35,0x39,0x33,0x37,0x35,0x66,0x20,0x2a,0x20,0x5f,0x32,0x35,0x34,0x29,0x29,0x20, + 0x2b,0x20,0x28,0x30,0x2e,0x30,0x30,0x32,0x30,0x39,0x30,0x30,0x30,0x30,0x30,0x38, + 0x31,0x38,0x30,0x37,0x33,0x37,0x34,0x39,0x35,0x34,0x32,0x32,0x33,0x36,0x33,0x32, + 0x38,0x31,0x32,0x35,0x66,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31,0x29,0x29,0x20,0x2a, + 0x20,0x5f,0x31,0x35,0x38,0x29,0x20,0x2b,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x2d, + 0x30,0x2e,0x30,0x32,0x39,0x30,0x33,0x30,0x30,0x30,0x30,0x37,0x39,0x30,0x39,0x35, + 0x33,0x36,0x33,0x36,0x31,0x36,0x39,0x34,0x33,0x33,0x35,0x39,0x33,0x37,0x35,0x66, + 0x29,0x20,0x2a,0x20,0x5f,0x32,0x35,0x38,0x29,0x20,0x2b,0x20,0x28,0x30,0x2e,0x30, + 0x36,0x33,0x37,0x37,0x30,0x30,0x30,0x33,0x36,0x31,0x36,0x38,0x30,0x39,0x38,0x34, + 0x34,0x39,0x37,0x30,0x37,0x30,0x33,0x31,0x32,0x35,0x66,0x20,0x2a,0x20,0x5f,0x32, + 0x35,0x34,0x29,0x29,0x20,0x2d,0x20,0x28,0x30,0x2e,0x30,0x33,0x32,0x30,0x31,0x39, + 0x39,0x39,0x38,0x38,0x37,0x38,0x32,0x34,0x30,0x35,0x38,0x35,0x33,0x32,0x37,0x31, + 0x34,0x38,0x34,0x33,0x37,0x35,0x66,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31,0x29,0x29, + 0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x33,0x39,0x34,0x30,0x30,0x30,0x30,0x31,0x39, + 0x38,0x37,0x38,0x31,0x34,0x39,0x30,0x33,0x32,0x35,0x39,0x32,0x37,0x37,0x33,0x34, + 0x33,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x29,0x20,0x2b, + 0x20,0x28,0x28,0x28,0x28,0x30,0x2e,0x31,0x31,0x36,0x39,0x33,0x30,0x30,0x30,0x30, + 0x34,0x38,0x33,0x39,0x38,0x39,0x37,0x31,0x35,0x35,0x37,0x36,0x31,0x37,0x31,0x38, + 0x37,0x35,0x66,0x20,0x2a,0x20,0x5f,0x32,0x35,0x38,0x29,0x20,0x2d,0x20,0x28,0x30, + 0x2e,0x32,0x31,0x31,0x39,0x36,0x30,0x30,0x30,0x32,0x37,0x37,0x39,0x39,0x36,0x30, + 0x36,0x33,0x32,0x33,0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x66,0x20,0x2a,0x20,0x5f, + 0x32,0x35,0x34,0x29,0x29,0x20,0x2b,0x20,0x28,0x30,0x2e,0x30,0x36,0x30,0x35,0x32, + 0x30,0x30,0x30,0x30,0x37,0x35,0x35,0x37,0x38,0x36,0x38,0x39,0x35,0x37,0x35,0x31, + 0x39,0x35,0x33,0x31,0x32,0x35,0x66,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31,0x29,0x29, + 0x20,0x2b,0x20,0x30,0x2e,0x32,0x35,0x38,0x38,0x35,0x39,0x39,0x39,0x32,0x30,0x32, + 0x37,0x32,0x38,0x32,0x37,0x31,0x34,0x38,0x34,0x33,0x37,0x35,0x66,0x29,0x29,0x20, + 0x2a,0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x50,0x65,0x72,0x65,0x7a,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x29,0x29,0x20,0x2f, + 0x20,0x6d,0x61,0x78,0x28,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x50,0x65,0x72, + 0x65,0x7a,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x32,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x33,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x37,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x33,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, + 0x39,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33, + 0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33, + 0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x39,0x20, + 0x3d,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x30,0x2e,0x30,0x30,0x32,0x37,0x34, + 0x39,0x39,0x39,0x39,0x39,0x38,0x35,0x30,0x39,0x38,0x38,0x33,0x38,0x38,0x30,0x36, + 0x31,0x35,0x32,0x33,0x34,0x33,0x37,0x35,0x66,0x20,0x2a,0x20,0x5f,0x32,0x35,0x38, + 0x29,0x20,0x2d,0x20,0x28,0x30,0x2e,0x30,0x30,0x36,0x30,0x39,0x39,0x39,0x39,0x39, + 0x38,0x38,0x32,0x32,0x38,0x30,0x38,0x32,0x36,0x35,0x36,0x38,0x36,0x30,0x33,0x35, + 0x31,0x35,0x36,0x32,0x35,0x66,0x20,0x2a,0x20,0x5f,0x32,0x35,0x34,0x29,0x29,0x20, + 0x2b,0x20,0x28,0x30,0x2e,0x30,0x30,0x33,0x31,0x36,0x39,0x39,0x39,0x39,0x39,0x32, + 0x33,0x35,0x35,0x37,0x30,0x34,0x33,0x30,0x37,0x35,0x35,0x36,0x31,0x35,0x32,0x33, + 0x34,0x33,0x37,0x35,0x66,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31,0x29,0x29,0x20,0x2a, + 0x20,0x5f,0x31,0x35,0x38,0x29,0x20,0x2b,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x2d, + 0x30,0x2e,0x30,0x34,0x32,0x31,0x33,0x39,0x39,0x39,0x39,0x35,0x36,0x38,0x34,0x36, + 0x32,0x33,0x37,0x31,0x38,0x32,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x66,0x29,0x20, + 0x2a,0x20,0x5f,0x32,0x35,0x38,0x29,0x20,0x2b,0x20,0x28,0x30,0x2e,0x30,0x38,0x39, + 0x36,0x39,0x39,0x39,0x39,0x38,0x34,0x39,0x37,0x39,0x36,0x32,0x39,0x35,0x31,0x36, + 0x36,0x30,0x31,0x35,0x36,0x32,0x35,0x66,0x20,0x2a,0x20,0x5f,0x32,0x35,0x34,0x29, + 0x29,0x20,0x2d,0x20,0x28,0x30,0x2e,0x30,0x34,0x31,0x35,0x32,0x39,0x39,0x39,0x38, + 0x31,0x38,0x33,0x32,0x35,0x30,0x34,0x32,0x37,0x32,0x34,0x36,0x30,0x39,0x33,0x37, + 0x35,0x66,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31,0x29,0x29,0x20,0x2b,0x20,0x30,0x2e, + 0x30,0x30,0x35,0x31,0x36,0x30,0x30,0x30,0x30,0x31,0x37,0x35,0x32,0x33,0x37,0x36, + 0x35,0x35,0x36,0x33,0x39,0x36,0x34,0x38,0x34,0x33,0x37,0x35,0x66,0x29,0x20,0x2a, + 0x20,0x5f,0x31,0x35,0x34,0x29,0x29,0x20,0x2b,0x20,0x28,0x28,0x28,0x28,0x30,0x2e, + 0x31,0x35,0x33,0x34,0x35,0x39,0x39,0x39,0x35,0x39,0x38,0x35,0x30,0x33,0x31,0x31, + 0x32,0x37,0x39,0x32,0x39,0x36,0x38,0x37,0x35,0x66,0x20,0x2a,0x20,0x5f,0x32,0x35, + 0x38,0x29,0x20,0x2d,0x20,0x28,0x30,0x2e,0x32,0x36,0x37,0x35,0x36,0x30,0x30,0x30, + 0x35,0x31,0x38,0x37,0x39,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x66,0x20,0x2a,0x20, + 0x5f,0x32,0x35,0x34,0x29,0x29,0x20,0x2b,0x20,0x28,0x30,0x2e,0x30,0x36,0x36,0x36, + 0x39,0x39,0x39,0x39,0x36,0x35,0x39,0x30,0x36,0x31,0x34,0x33,0x31,0x38,0x38,0x34, + 0x37,0x36,0x35,0x36,0x32,0x35,0x66,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31,0x29,0x29, + 0x20,0x2b,0x20,0x30,0x2e,0x32,0x36,0x36,0x38,0x38,0x30,0x30,0x30,0x35,0x35,0x39, + 0x38,0x30,0x36,0x38,0x32,0x33,0x37,0x33,0x30,0x34,0x36,0x38,0x37,0x35,0x66,0x29, + 0x29,0x20,0x2a,0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x50,0x65,0x72,0x65, + 0x7a,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33, + 0x29,0x29,0x20,0x2f,0x20,0x6d,0x61,0x78,0x28,0x70,0x72,0x65,0x65,0x74,0x68,0x61, + 0x6d,0x50,0x65,0x72,0x65,0x7a,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x30,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x34,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x33,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x34,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, + 0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x36,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x34,0x37,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39, + 0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34, + 0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x66,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x35,0x30,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x28,0x28,0x28,0x28,0x28,0x28, + 0x34,0x2e,0x30,0x34,0x35,0x33,0x30,0x30,0x30,0x30,0x36,0x38,0x36,0x36,0x34,0x35, + 0x35,0x30,0x37,0x38,0x31,0x32,0x35,0x66,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29, + 0x20,0x2d,0x20,0x34,0x2e,0x39,0x37,0x31,0x30,0x30,0x30,0x31,0x39,0x34,0x35,0x34, + 0x39,0x35,0x36,0x30,0x35,0x34,0x36,0x38,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x74, + 0x61,0x6e,0x28,0x28,0x30,0x2e,0x34,0x34,0x34,0x34,0x34,0x34,0x34,0x34,0x37,0x37, + 0x35,0x35,0x38,0x31,0x33,0x35,0x39,0x38,0x36,0x33,0x32,0x38,0x31,0x32,0x35,0x66, + 0x20,0x2d,0x20,0x28,0x5f,0x31,0x35,0x34,0x20,0x2a,0x20,0x30,0x2e,0x30,0x30,0x38, + 0x33,0x33,0x33,0x33,0x33,0x33,0x37,0x36,0x37,0x39,0x35,0x30,0x35,0x33,0x34,0x38, + 0x32,0x30,0x35,0x35,0x36,0x36,0x34,0x30,0x36,0x32,0x35,0x66,0x29,0x29,0x20,0x2a, + 0x20,0x28,0x33,0x2e,0x31,0x34,0x31,0x35,0x39,0x32,0x37,0x34,0x31,0x30,0x31,0x32, + 0x35,0x37,0x33,0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x66,0x20,0x2d,0x20,0x28,0x32, + 0x2e,0x30,0x66,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31,0x29,0x29,0x29,0x29,0x20,0x2d, + 0x20,0x28,0x30,0x2e,0x32,0x31,0x35,0x34,0x39,0x39,0x39,0x39,0x37,0x31,0x33,0x38, + 0x39,0x37,0x37,0x30,0x35,0x30,0x37,0x38,0x31,0x32,0x35,0x66,0x20,0x2a,0x20,0x5f, + 0x31,0x35,0x34,0x29,0x29,0x20,0x2b,0x20,0x32,0x2e,0x34,0x31,0x39,0x31,0x39,0x39, + 0x39,0x34,0x33,0x35,0x34,0x32,0x34,0x38,0x30,0x34,0x36,0x38,0x37,0x35,0x66,0x29, + 0x20,0x2a,0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x50,0x65,0x72,0x65,0x7a, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x37,0x29,0x29,0x20,0x2f,0x20,0x6d,0x61,0x78,0x28,0x70,0x72, + 0x65,0x65,0x74,0x68,0x61,0x6d,0x50,0x65,0x72,0x65,0x7a,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x35,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x38,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x30, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x31,0x29,0x2c,0x20,0x39,0x2e,0x39, + 0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33, + 0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d, + 0x30,0x36,0x66,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x31, + 0x20,0x3d,0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x58,0x79,0x59,0x5f,0x74, + 0x6f,0x5f,0x58,0x59,0x5a,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x38,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x35,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x6d,0x61,0x78,0x28,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x58,0x59,0x5a,0x5f, + 0x74,0x6f,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72,0x5f,0x73,0x72,0x67,0x62,0x28,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x35,0x31,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78, + 0x78,0x78,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, + 0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x53,0x6b,0x79,0x53,0x63,0x61,0x6c,0x65,0x64, + 0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x69,0x65,0x77,0x5f,0x64,0x69,0x72, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x74,0x75,0x72,0x62,0x69,0x64,0x69,0x74, + 0x79,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x66,0x61,0x64,0x65,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x20,0x3d,0x20,0x76,0x69,0x65,0x77,0x5f,0x64,0x69,0x72,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x20,0x3d,0x20,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20, + 0x74,0x75,0x72,0x62,0x69,0x64,0x69,0x74,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x53, + 0x6b,0x79,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x20,0x2a,0x20,0x30,0x2e, + 0x30,0x35,0x39,0x39,0x39,0x39,0x39,0x39,0x38,0x36,0x35,0x38,0x38,0x39,0x35,0x34, + 0x39,0x32,0x35,0x35,0x33,0x37,0x31,0x30,0x39,0x33,0x37,0x35,0x66,0x29,0x20,0x2a, + 0x20,0x66,0x61,0x64,0x65,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x66, + 0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x35,0x34,0x31,0x20,0x3d,0x20,0x28, + 0x76,0x5f,0x75,0x76,0x20,0x2a,0x20,0x32,0x2e,0x30,0x66,0x29,0x20,0x2d,0x20,0x31, + 0x2e,0x30,0x66,0x2e,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x69,0x7a,0x65,0x28,0x28,0x5f,0x35,0x34,0x36,0x5f,0x66,0x61,0x63,0x65,0x5f, + 0x66,0x6f,0x72,0x77,0x61,0x72,0x64,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f, + 0x35,0x34,0x36,0x5f,0x66,0x61,0x63,0x65,0x5f,0x72,0x69,0x67,0x68,0x74,0x2e,0x78, + 0x79,0x7a,0x20,0x2a,0x20,0x5f,0x35,0x34,0x31,0x2e,0x78,0x29,0x29,0x20,0x2b,0x20, + 0x28,0x5f,0x35,0x34,0x36,0x5f,0x66,0x61,0x63,0x65,0x5f,0x75,0x70,0x2e,0x78,0x79, + 0x7a,0x20,0x2a,0x20,0x5f,0x35,0x34,0x31,0x2e,0x79,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x20,0x3d,0x20,0x5f,0x35,0x34,0x36,0x5f,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f, + 0x35,0x34,0x36,0x5f,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x35,0x34,0x36,0x5f,0x66,0x61, + 0x63,0x65,0x5f,0x66,0x6f,0x72,0x77,0x61,0x72,0x64,0x2e,0x77,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x53,0x6b,0x79, + 0x53,0x63,0x61,0x6c,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x29,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b, + 0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, + 0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52, + 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74, + 0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x5f,0x75,0x76,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e, + 0x70,0x75,0x74,0x2e,0x76,0x5f,0x75,0x76,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72, + 0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53, + 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75, + 0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74, + 0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x6f,0x75,0x74, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b, + 0x0a,0x7d,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + struct main0_out + { + float2 v_uv [[user(locn0)]]; + float4 gl_Position [[position]]; + }; + + vertex main0_out main0(uint gl_VertexIndex [[vertex_id]]) + { + main0_out out = {}; + float2 _27 = (float2(float((int(gl_VertexIndex) << 1) & 2), float(int(gl_VertexIndex) & 2)) * 2.0) - float2(1.0); + out.v_uv = (_27 * 0.5) + float2(0.5); + out.gl_Position = float4(_27, 0.0, 1.0); + return out; + } + +*/ +static const uint8_t sky_to_cube_vs_source_metal_macos[474] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d, + 0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x32,0x20,0x76,0x5f,0x75,0x76,0x20,0x5b,0x5b,0x75,0x73,0x65, + 0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69, + 0x6f,0x6e,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x3b, + 0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,0x65,0x78,0x20,0x6d,0x61,0x69,0x6e, + 0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x75,0x69,0x6e,0x74, + 0x20,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20, + 0x5b,0x5b,0x76,0x65,0x72,0x74,0x65,0x78,0x5f,0x69,0x64,0x5d,0x5d,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f, + 0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x32,0x20,0x5f,0x32,0x37,0x20,0x3d,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74, + 0x32,0x28,0x66,0x6c,0x6f,0x61,0x74,0x28,0x28,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f, + 0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x3c,0x3c,0x20, + 0x31,0x29,0x20,0x26,0x20,0x32,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x69, + 0x6e,0x74,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65, + 0x78,0x29,0x20,0x26,0x20,0x32,0x29,0x29,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x20, + 0x2d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x75,0x76,0x20,0x3d,0x20,0x28,0x5f, + 0x32,0x37,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x32,0x28,0x30,0x2e,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, + 0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x32,0x37,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20, + 0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + #pragma clang diagnostic ignored "-Wmissing-prototypes" + + #include + #include + + using namespace metal; + + struct ub_face + { + float4 face_right; + float4 face_up; + float4 face_forward; + float4 sun_dir_world; + }; + + struct main0_out + { + float4 out_color [[color(0)]]; + }; + + struct main0_in + { + float2 v_uv [[user(locn0)]]; + }; + + static inline __attribute__((always_inline)) + float preethamPerez(thread const float& cos_theta, thread const float& cos_gamma, thread const float& gamma, thread const float& A, thread const float& B, thread const float& C, thread const float& D, thread const float& E) + { + return (1.0 + (A * exp(B / fast::max(cos_theta, 0.00999999977648258209228515625)))) * ((1.0 + (C * exp(D * gamma))) + ((E * cos_gamma) * cos_gamma)); + } + + static inline __attribute__((always_inline)) + float3 preethamXyY_to_XYZ(thread const float& x, thread const float& y, thread const float& Y) + { + float _77 = fast::max(y, 9.9999997473787516355514526367188e-06); + return float3((Y * x) / _77, Y, (Y * ((1.0 - x) - y)) / _77); + } + + static inline __attribute__((always_inline)) + float3 preethamXYZ_to_linear_srgb(thread const float3& c) + { + return float3(dot(c, float3(3.240454196929931640625, -1.537138462066650390625, -0.498531401157379150390625)), dot(c, float3(-0.969265997409820556640625, 1.87601077556610107421875, 0.04155600070953369140625)), dot(c, float3(0.0556433983147144317626953125, -0.2040258944034576416015625, 1.05722522735595703125))); + } + + static inline __attribute__((always_inline)) + float3 preethamSky(thread const float3& view_dir, thread const float3& sun_dir, thread const float& turbidity) + { + float _122 = fast::clamp(sun_dir.y, 0.0, 1.0); + float3 _135 = fast::normalize(float3(view_dir.x, fast::max(view_dir.y, 0.0) + 0.00999999977648258209228515625, view_dir.z)); + float _139 = fast::max(_135.y, 0.0); + float _145 = fast::clamp(dot(sun_dir, _135), -1.0, 1.0); + float _148 = acos(_145); + float _151 = acos(_122); + float _154 = fast::max(turbidity, 1.0); + float _158 = _154 * _154; + float _164 = (0.1787000000476837158203125 * _154) - 1.4630000591278076171875; + float _170 = ((-0.3553999960422515869140625) * _154) + 0.4275000095367431640625; + float _176 = ((-0.0227000005543231964111328125) * _154) + 5.325099945068359375; + float _182 = (0.12060000002384185791015625 * _154) - 2.5771000385284423828125; + float _188 = ((-0.0670000016689300537109375) * _154) + 0.370299994945526123046875; + float _194 = ((-0.01930000074207782745361328125) * _154) - 0.2592000067234039306640625; + float _200 = ((-0.066500000655651092529296875) * _154) + 0.0007999999797903001308441162109375; + float _206 = ((-0.00039999998989515006542205810546875) * _154) + 0.2125000059604644775390625; + float _212 = ((-0.0640999972820281982421875) * _154) - 0.898899972438812255859375; + float _218 = ((-0.0032999999821186065673828125) * _154) + 0.0452000014483928680419921875; + float _224 = ((-0.0166999995708465576171875) * _154) - 0.26080000400543212890625; + float _230 = ((-0.0949999988079071044921875) * _154) + 0.009200000204145908355712890625; + float _236 = ((-0.0078999996185302734375) * _154) + 0.21019999682903289794921875; + float _242 = ((-0.04410000145435333251953125) * _154) - 1.65369999408721923828125; + float _248 = ((-0.01090000011026859283447265625) * _154) + 0.05290000140666961669921875; + float _254 = _151 * _151; + float _258 = _254 * _151; + float param = _139; + float param_1 = _145; + float param_2 = _148; + float param_3 = _164; + float param_4 = _170; + float param_5 = _176; + float param_6 = _182; + float param_7 = _188; + float param_8 = _139; + float param_9 = _145; + float param_10 = _148; + float param_11 = _194; + float param_12 = _200; + float param_13 = _206; + float param_14 = _212; + float param_15 = _218; + float param_16 = _139; + float param_17 = _145; + float param_18 = _148; + float param_19 = _224; + float param_20 = _230; + float param_21 = _236; + float param_22 = _242; + float param_23 = _248; + float param_24 = 1.0; + float param_25 = _122; + float param_26 = _151; + float param_27 = _164; + float param_28 = _170; + float param_29 = _176; + float param_30 = _182; + float param_31 = _188; + float param_32 = 1.0; + float param_33 = _122; + float param_34 = _151; + float param_35 = _194; + float param_36 = _200; + float param_37 = _206; + float param_38 = _212; + float param_39 = _218; + float param_40 = 1.0; + float param_41 = _122; + float param_42 = _151; + float param_43 = _224; + float param_44 = _230; + float param_45 = _236; + float param_46 = _242; + float param_47 = _248; + float param_48 = (((((((0.001659999950788915157318115234375 * _258) - (0.00374999991618096828460693359375 * _254)) + (0.0020900000818073749542236328125 * _151)) * _158) + ((((((-0.02903000079095363616943359375) * _258) + (0.063770003616809844970703125 * _254)) - (0.0320199988782405853271484375 * _151)) + 0.003940000198781490325927734375) * _154)) + ((((0.116930000483989715576171875 * _258) - (0.21196000277996063232421875 * _254)) + (0.060520000755786895751953125 * _151)) + 0.25885999202728271484375)) * preethamPerez(param_8, param_9, param_10, param_11, param_12, param_13, param_14, param_15)) / fast::max(preethamPerez(param_32, param_33, param_34, param_35, param_36, param_37, param_38, param_39), 9.9999997473787516355514526367188e-06); + float param_49 = (((((((0.00274999998509883880615234375 * _258) - (0.006099999882280826568603515625 * _254)) + (0.0031699999235570430755615234375 * _151)) * _158) + ((((((-0.042139999568462371826171875) * _258) + (0.08969999849796295166015625 * _254)) - (0.04152999818325042724609375 * _151)) + 0.0051600001752376556396484375) * _154)) + ((((0.1534599959850311279296875 * _258) - (0.26756000518798828125 * _254)) + (0.06669999659061431884765625 * _151)) + 0.2668800055980682373046875)) * preethamPerez(param_16, param_17, param_18, param_19, param_20, param_21, param_22, param_23)) / fast::max(preethamPerez(param_40, param_41, param_42, param_43, param_44, param_45, param_46, param_47), 9.9999997473787516355514526367188e-06); + float param_50 = fast::max(((((((4.045300006866455078125 * _154) - 4.971000194549560546875) * tan((0.4444444477558135986328125 - (_154 * 0.008333333767950534820556640625)) * (3.1415927410125732421875 - (2.0 * _151)))) - (0.21549999713897705078125 * _154)) + 2.41919994354248046875) * preethamPerez(param, param_1, param_2, param_3, param_4, param_5, param_6, param_7)) / fast::max(preethamPerez(param_24, param_25, param_26, param_27, param_28, param_29, param_30, param_31), 9.9999997473787516355514526367188e-06), 0.0); + float3 param_51 = preethamXyY_to_XYZ(param_48, param_49, param_50); + return fast::max(preethamXYZ_to_linear_srgb(param_51), float3(0.0)); + } + + static inline __attribute__((always_inline)) + float3 preethamSkyScaled(thread const float3& view_dir, thread const float3& sun_dir, thread const float& turbidity, thread const float& fade) + { + float3 param = view_dir; + float3 param_1 = sun_dir; + float param_2 = turbidity; + return (preethamSky(param, param_1, param_2) * 0.0599999986588954925537109375) * fade; + } + + fragment main0_out main0(main0_in in [[stage_in]], constant ub_face& _546 [[buffer(0)]]) + { + main0_out out = {}; + float2 _541 = (in.v_uv * 2.0) - float2(1.0); + float3 param = fast::normalize((_546.face_forward.xyz + (_546.face_right.xyz * _541.x)) + (_546.face_up.xyz * _541.y)); + float3 param_1 = _546.sun_dir_world.xyz; + float param_2 = _546.sun_dir_world.w; + float param_3 = _546.face_forward.w; + out.out_color = float4(preethamSkyScaled(param, param_1, param_2, param_3), 1.0); + return out; + } + +*/ +static const uint8_t sky_to_cube_fs_source_metal_macos[7794] = { + 0x23,0x70,0x72,0x61,0x67,0x6d,0x61,0x20,0x63,0x6c,0x61,0x6e,0x67,0x20,0x64,0x69, + 0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x20,0x69,0x67,0x6e,0x6f,0x72,0x65,0x64, + 0x20,0x22,0x2d,0x57,0x6d,0x69,0x73,0x73,0x69,0x6e,0x67,0x2d,0x70,0x72,0x6f,0x74, + 0x6f,0x74,0x79,0x70,0x65,0x73,0x22,0x0a,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64, + 0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f,0x73,0x74,0x64,0x6c,0x69,0x62,0x3e, + 0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f, + 0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a,0x75,0x73,0x69,0x6e,0x67,0x20,0x6e, + 0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20,0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a, + 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x66,0x61,0x63,0x65,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x61,0x63, + 0x65,0x5f,0x72,0x69,0x67,0x68,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x66,0x61,0x63,0x65,0x5f,0x75,0x70,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x61,0x63,0x65,0x5f,0x66,0x6f,0x72, + 0x77,0x61,0x72,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a, + 0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30, + 0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x63,0x6f, + 0x6c,0x6f,0x72,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x76,0x5f,0x75,0x76,0x20, + 0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b, + 0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69, + 0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f, + 0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29, + 0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d, + 0x50,0x65,0x72,0x65,0x7a,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x63,0x6f,0x73,0x5f,0x74,0x68, + 0x65,0x74,0x61,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x63,0x6f,0x73,0x5f,0x67,0x61,0x6d, + 0x6d,0x61,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x67,0x61,0x6d,0x6d,0x61,0x2c,0x20,0x74, + 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x26,0x20,0x41,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x42,0x2c,0x20,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26, + 0x20,0x43,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x44,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x45, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28, + 0x31,0x2e,0x30,0x20,0x2b,0x20,0x28,0x41,0x20,0x2a,0x20,0x65,0x78,0x70,0x28,0x42, + 0x20,0x2f,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x63,0x6f,0x73, + 0x5f,0x74,0x68,0x65,0x74,0x61,0x2c,0x20,0x30,0x2e,0x30,0x30,0x39,0x39,0x39,0x39, + 0x39,0x39,0x39,0x37,0x37,0x36,0x34,0x38,0x32,0x35,0x38,0x32,0x30,0x39,0x32,0x32, + 0x38,0x35,0x31,0x35,0x36,0x32,0x35,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x28,0x28, + 0x31,0x2e,0x30,0x20,0x2b,0x20,0x28,0x43,0x20,0x2a,0x20,0x65,0x78,0x70,0x28,0x44, + 0x20,0x2a,0x20,0x67,0x61,0x6d,0x6d,0x61,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x28, + 0x45,0x20,0x2a,0x20,0x63,0x6f,0x73,0x5f,0x67,0x61,0x6d,0x6d,0x61,0x29,0x20,0x2a, + 0x20,0x63,0x6f,0x73,0x5f,0x67,0x61,0x6d,0x6d,0x61,0x29,0x29,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f, + 0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c, + 0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x58,0x79,0x59, + 0x5f,0x74,0x6f,0x5f,0x58,0x59,0x5a,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x78,0x2c,0x20,0x74, + 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x26,0x20,0x79,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x59,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x37,0x20,0x3d,0x20,0x66, + 0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x79,0x2c,0x20,0x39,0x2e,0x39,0x39, + 0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35, + 0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30, + 0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x59,0x20,0x2a,0x20,0x78,0x29,0x20,0x2f,0x20, + 0x5f,0x37,0x37,0x2c,0x20,0x59,0x2c,0x20,0x28,0x59,0x20,0x2a,0x20,0x28,0x28,0x31, + 0x2e,0x30,0x20,0x2d,0x20,0x78,0x29,0x20,0x2d,0x20,0x79,0x29,0x29,0x20,0x2f,0x20, + 0x5f,0x37,0x37,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, + 0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75, + 0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c, + 0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x72,0x65, + 0x65,0x74,0x68,0x61,0x6d,0x58,0x59,0x5a,0x5f,0x74,0x6f,0x5f,0x6c,0x69,0x6e,0x65, + 0x61,0x72,0x5f,0x73,0x72,0x67,0x62,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x63,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x28,0x64,0x6f,0x74,0x28,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x28,0x33,0x2e,0x32,0x34,0x30,0x34,0x35,0x34,0x31,0x39,0x36,0x39,0x32,0x39, + 0x39,0x33,0x31,0x36,0x34,0x30,0x36,0x32,0x35,0x2c,0x20,0x2d,0x31,0x2e,0x35,0x33, + 0x37,0x31,0x33,0x38,0x34,0x36,0x32,0x30,0x36,0x36,0x36,0x35,0x30,0x33,0x39,0x30, + 0x36,0x32,0x35,0x2c,0x20,0x2d,0x30,0x2e,0x34,0x39,0x38,0x35,0x33,0x31,0x34,0x30, + 0x31,0x31,0x35,0x37,0x33,0x37,0x39,0x31,0x35,0x30,0x33,0x39,0x30,0x36,0x32,0x35, + 0x29,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x28,0x2d,0x30,0x2e,0x39,0x36,0x39,0x32,0x36,0x35,0x39,0x39,0x37,0x34,0x30, + 0x39,0x38,0x32,0x30,0x35,0x35,0x36,0x36,0x34,0x30,0x36,0x32,0x35,0x2c,0x20,0x31, + 0x2e,0x38,0x37,0x36,0x30,0x31,0x30,0x37,0x37,0x35,0x35,0x36,0x36,0x31,0x30,0x31, + 0x30,0x37,0x34,0x32,0x31,0x38,0x37,0x35,0x2c,0x20,0x30,0x2e,0x30,0x34,0x31,0x35, + 0x35,0x36,0x30,0x30,0x30,0x37,0x30,0x39,0x35,0x33,0x33,0x36,0x39,0x31,0x34,0x30, + 0x36,0x32,0x35,0x29,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x63,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x35,0x35,0x36,0x34,0x33,0x33,0x39,0x38, + 0x33,0x31,0x34,0x37,0x31,0x34,0x34,0x33,0x31,0x37,0x36,0x32,0x36,0x39,0x35,0x33, + 0x31,0x32,0x35,0x2c,0x20,0x2d,0x30,0x2e,0x32,0x30,0x34,0x30,0x32,0x35,0x38,0x39, + 0x34,0x34,0x30,0x33,0x34,0x35,0x37,0x36,0x34,0x31,0x36,0x30,0x31,0x35,0x36,0x32, + 0x35,0x2c,0x20,0x31,0x2e,0x30,0x35,0x37,0x32,0x32,0x35,0x32,0x32,0x37,0x33,0x35, + 0x35,0x39,0x35,0x37,0x30,0x33,0x31,0x32,0x35,0x29,0x29,0x29,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f, + 0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c, + 0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x53,0x6b,0x79, + 0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x26,0x20,0x76,0x69,0x65,0x77,0x5f,0x64,0x69,0x72,0x2c,0x20, + 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x26,0x20,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x2c,0x20,0x74,0x68, + 0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x26,0x20,0x74,0x75,0x72,0x62,0x69,0x64,0x69,0x74,0x79,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x32,0x20,0x3d,0x20, + 0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x73,0x75,0x6e,0x5f, + 0x64,0x69,0x72,0x2e,0x79,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x33, + 0x35,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c, + 0x69,0x7a,0x65,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x76,0x69,0x65,0x77,0x5f, + 0x64,0x69,0x72,0x2e,0x78,0x2c,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78, + 0x28,0x76,0x69,0x65,0x77,0x5f,0x64,0x69,0x72,0x2e,0x79,0x2c,0x20,0x30,0x2e,0x30, + 0x29,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37, + 0x37,0x36,0x34,0x38,0x32,0x35,0x38,0x32,0x30,0x39,0x32,0x32,0x38,0x35,0x31,0x35, + 0x36,0x32,0x35,0x2c,0x20,0x76,0x69,0x65,0x77,0x5f,0x64,0x69,0x72,0x2e,0x7a,0x29, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33, + 0x39,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x5f,0x31, + 0x33,0x35,0x2e,0x79,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x35,0x20,0x3d,0x20,0x66,0x61,0x73, + 0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x64,0x6f,0x74,0x28,0x73,0x75,0x6e, + 0x5f,0x64,0x69,0x72,0x2c,0x20,0x5f,0x31,0x33,0x35,0x29,0x2c,0x20,0x2d,0x31,0x2e, + 0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x34,0x38,0x20,0x3d,0x20,0x61,0x63,0x6f,0x73,0x28,0x5f, + 0x31,0x34,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x35,0x31,0x20,0x3d,0x20,0x61,0x63,0x6f,0x73,0x28,0x5f,0x31,0x32,0x32, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35, + 0x34,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x74,0x75, + 0x72,0x62,0x69,0x64,0x69,0x74,0x79,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x38,0x20,0x3d,0x20, + 0x5f,0x31,0x35,0x34,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x34,0x20,0x3d,0x20,0x28,0x30, + 0x2e,0x31,0x37,0x38,0x37,0x30,0x30,0x30,0x30,0x30,0x30,0x34,0x37,0x36,0x38,0x33, + 0x37,0x31,0x35,0x38,0x32,0x30,0x33,0x31,0x32,0x35,0x20,0x2a,0x20,0x5f,0x31,0x35, + 0x34,0x29,0x20,0x2d,0x20,0x31,0x2e,0x34,0x36,0x33,0x30,0x30,0x30,0x30,0x35,0x39, + 0x31,0x32,0x37,0x38,0x30,0x37,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x37,0x30,0x20,0x3d,0x20, + 0x28,0x28,0x2d,0x30,0x2e,0x33,0x35,0x35,0x33,0x39,0x39,0x39,0x39,0x36,0x30,0x34, + 0x32,0x32,0x35,0x31,0x35,0x38,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x20, + 0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2b,0x20,0x30,0x2e,0x34,0x32,0x37,0x35, + 0x30,0x30,0x30,0x30,0x39,0x35,0x33,0x36,0x37,0x34,0x33,0x31,0x36,0x34,0x30,0x36, + 0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x37,0x36,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x32,0x32,0x37,0x30,0x30, + 0x30,0x30,0x30,0x35,0x35,0x34,0x33,0x32,0x33,0x31,0x39,0x36,0x34,0x31,0x31,0x31, + 0x33,0x32,0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20, + 0x2b,0x20,0x35,0x2e,0x33,0x32,0x35,0x30,0x39,0x39,0x39,0x34,0x35,0x30,0x36,0x38, + 0x33,0x35,0x39,0x33,0x37,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x31,0x38,0x32,0x20,0x3d,0x20,0x28,0x30,0x2e,0x31,0x32,0x30,0x36, + 0x30,0x30,0x30,0x30,0x30,0x30,0x32,0x33,0x38,0x34,0x31,0x38,0x35,0x37,0x39,0x31, + 0x30,0x31,0x35,0x36,0x32,0x35,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2d, + 0x20,0x32,0x2e,0x35,0x37,0x37,0x31,0x30,0x30,0x30,0x33,0x38,0x35,0x32,0x38,0x34, + 0x34,0x32,0x33,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x38,0x38,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30, + 0x2e,0x30,0x36,0x37,0x30,0x30,0x30,0x30,0x30,0x31,0x36,0x36,0x38,0x39,0x33,0x30, + 0x30,0x35,0x33,0x37,0x31,0x30,0x39,0x33,0x37,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31, + 0x35,0x34,0x29,0x20,0x2b,0x20,0x30,0x2e,0x33,0x37,0x30,0x32,0x39,0x39,0x39,0x39, + 0x34,0x39,0x34,0x35,0x35,0x32,0x36,0x31,0x32,0x33,0x30,0x34,0x36,0x38,0x37,0x35, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x39,0x34, + 0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x31,0x39,0x33,0x30,0x30,0x30,0x30, + 0x30,0x37,0x34,0x32,0x30,0x37,0x37,0x38,0x32,0x37,0x34,0x35,0x33,0x36,0x31,0x33, + 0x32,0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2d, + 0x20,0x30,0x2e,0x32,0x35,0x39,0x32,0x30,0x30,0x30,0x30,0x36,0x37,0x32,0x33,0x34, + 0x30,0x33,0x39,0x33,0x30,0x36,0x36,0x34,0x30,0x36,0x32,0x35,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x30,0x30,0x20,0x3d,0x20,0x28, + 0x28,0x2d,0x30,0x2e,0x30,0x36,0x36,0x35,0x30,0x30,0x30,0x30,0x30,0x36,0x35,0x35, + 0x36,0x35,0x31,0x30,0x39,0x32,0x35,0x32,0x39,0x32,0x39,0x36,0x38,0x37,0x35,0x29, + 0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30, + 0x37,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x39,0x37,0x39,0x30,0x33,0x30,0x30,0x31, + 0x33,0x30,0x38,0x34,0x34,0x31,0x31,0x36,0x32,0x31,0x30,0x39,0x33,0x37,0x35,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x30,0x36,0x20, + 0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x30,0x30,0x33,0x39,0x39,0x39,0x39,0x39, + 0x39,0x38,0x39,0x38,0x39,0x35,0x31,0x35,0x30,0x30,0x36,0x35,0x34,0x32,0x32,0x30, + 0x35,0x38,0x31,0x30,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31, + 0x35,0x34,0x29,0x20,0x2b,0x20,0x30,0x2e,0x32,0x31,0x32,0x35,0x30,0x30,0x30,0x30, + 0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32, + 0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31, + 0x32,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x36,0x34,0x30,0x39,0x39,0x39, + 0x39,0x37,0x32,0x38,0x32,0x30,0x32,0x38,0x31,0x39,0x38,0x32,0x34,0x32,0x31,0x38, + 0x37,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2d,0x20,0x30,0x2e, + 0x38,0x39,0x38,0x38,0x39,0x39,0x39,0x37,0x32,0x34,0x33,0x38,0x38,0x31,0x32,0x32, + 0x35,0x35,0x38,0x35,0x39,0x33,0x37,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x38,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e, + 0x30,0x30,0x33,0x32,0x39,0x39,0x39,0x39,0x39,0x39,0x38,0x32,0x31,0x31,0x38,0x36, + 0x30,0x36,0x35,0x36,0x37,0x33,0x38,0x32,0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20, + 0x5f,0x31,0x35,0x34,0x29,0x20,0x2b,0x20,0x30,0x2e,0x30,0x34,0x35,0x32,0x30,0x30, + 0x30,0x30,0x31,0x34,0x34,0x38,0x33,0x39,0x32,0x38,0x36,0x38,0x30,0x34,0x31,0x39, + 0x39,0x32,0x31,0x38,0x37,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x32,0x32,0x34,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x31, + 0x36,0x36,0x39,0x39,0x39,0x39,0x39,0x35,0x37,0x30,0x38,0x34,0x36,0x35,0x35,0x37, + 0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29, + 0x20,0x2d,0x20,0x30,0x2e,0x32,0x36,0x30,0x38,0x30,0x30,0x30,0x30,0x34,0x30,0x30, + 0x35,0x34,0x33,0x32,0x31,0x32,0x38,0x39,0x30,0x36,0x32,0x35,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x33,0x30,0x20,0x3d,0x20,0x28, + 0x28,0x2d,0x30,0x2e,0x30,0x39,0x34,0x39,0x39,0x39,0x39,0x39,0x38,0x38,0x30,0x37, + 0x39,0x30,0x37,0x31,0x30,0x34,0x34,0x39,0x32,0x31,0x38,0x37,0x35,0x29,0x20,0x2a, + 0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x39,0x32,0x30, + 0x30,0x30,0x30,0x30,0x32,0x30,0x34,0x31,0x34,0x35,0x39,0x30,0x38,0x33,0x35,0x35, + 0x37,0x31,0x32,0x38,0x39,0x30,0x36,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x33,0x36,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30, + 0x2e,0x30,0x30,0x37,0x38,0x39,0x39,0x39,0x39,0x39,0x36,0x31,0x38,0x35,0x33,0x30, + 0x32,0x37,0x33,0x34,0x33,0x37,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29, + 0x20,0x2b,0x20,0x30,0x2e,0x32,0x31,0x30,0x31,0x39,0x39,0x39,0x39,0x36,0x38,0x32, + 0x39,0x30,0x33,0x32,0x38,0x39,0x37,0x39,0x34,0x39,0x32,0x31,0x38,0x37,0x35,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x34,0x32,0x20, + 0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x34,0x34,0x31,0x30,0x30,0x30,0x30,0x31, + 0x34,0x35,0x34,0x33,0x35,0x33,0x33,0x33,0x32,0x35,0x31,0x39,0x35,0x33,0x31,0x32, + 0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x29,0x20,0x2d,0x20,0x31,0x2e,0x36, + 0x35,0x33,0x36,0x39,0x39,0x39,0x39,0x34,0x30,0x38,0x37,0x32,0x31,0x39,0x32,0x33, + 0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x32,0x34,0x38,0x20,0x3d,0x20,0x28,0x28,0x2d,0x30,0x2e,0x30,0x31, + 0x30,0x39,0x30,0x30,0x30,0x30,0x30,0x31,0x31,0x30,0x32,0x36,0x38,0x35,0x39,0x32, + 0x38,0x33,0x34,0x34,0x37,0x32,0x36,0x35,0x36,0x32,0x35,0x29,0x20,0x2a,0x20,0x5f, + 0x31,0x35,0x34,0x29,0x20,0x2b,0x20,0x30,0x2e,0x30,0x35,0x32,0x39,0x30,0x30,0x30, + 0x30,0x31,0x34,0x30,0x36,0x36,0x36,0x39,0x36,0x31,0x36,0x36,0x39,0x39,0x32,0x31, + 0x38,0x37,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x32,0x35,0x34,0x20,0x3d,0x20,0x5f,0x31,0x35,0x31,0x20,0x2a,0x20,0x5f,0x31,0x35, + 0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x35, + 0x38,0x20,0x3d,0x20,0x5f,0x32,0x35,0x34,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x20,0x3d,0x20,0x5f,0x31,0x33,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x31,0x34, + 0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x31,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d, + 0x20,0x5f,0x31,0x36,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x31,0x37,0x30,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x35,0x20,0x3d,0x20,0x5f,0x31,0x37,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f, + 0x31,0x38,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x5f,0x31,0x38,0x38,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38, + 0x20,0x3d,0x20,0x5f,0x31,0x33,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x5f,0x31,0x34, + 0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x5f,0x31,0x34,0x38,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31, + 0x20,0x3d,0x20,0x5f,0x31,0x39,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x5f,0x32, + 0x30,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20,0x5f,0x32,0x30,0x36,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x34,0x20,0x3d,0x20,0x5f,0x32,0x31,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x5f, + 0x32,0x31,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x5f,0x31,0x33,0x39,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x37,0x20,0x3d,0x20,0x5f,0x31,0x34,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20, + 0x5f,0x31,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20,0x5f,0x32,0x32,0x34,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x30,0x20,0x3d,0x20,0x5f,0x32,0x33,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x20,0x3d, + 0x20,0x5f,0x32,0x33,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x20,0x3d,0x20,0x5f,0x32,0x34,0x32, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x33,0x20,0x3d,0x20,0x5f,0x32,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x20, + 0x3d,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x35,0x20,0x3d,0x20,0x5f,0x31,0x32,0x32, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x36,0x20,0x3d,0x20,0x5f,0x31,0x35,0x31,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37,0x20, + 0x3d,0x20,0x5f,0x31,0x36,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x38,0x20,0x3d,0x20,0x5f,0x31,0x37, + 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x39,0x20,0x3d,0x20,0x5f,0x31,0x37,0x36,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x30, + 0x20,0x3d,0x20,0x5f,0x31,0x38,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x31,0x20,0x3d,0x20,0x5f,0x31, + 0x38,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x32,0x20,0x3d,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x33, + 0x20,0x3d,0x20,0x5f,0x31,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x20,0x3d,0x20,0x5f,0x31, + 0x35,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x35,0x20,0x3d,0x20,0x5f,0x31,0x39,0x34,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, + 0x36,0x20,0x3d,0x20,0x5f,0x32,0x30,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x37,0x20,0x3d,0x20,0x5f, + 0x32,0x30,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x33,0x38,0x20,0x3d,0x20,0x5f,0x32,0x31,0x32,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x39,0x20,0x3d,0x20,0x5f,0x32,0x31,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x30,0x20,0x3d,0x20, + 0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x34,0x31,0x20,0x3d,0x20,0x5f,0x31,0x32,0x32,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x34,0x32,0x20,0x3d,0x20,0x5f,0x31,0x35,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x33,0x20,0x3d,0x20, + 0x5f,0x32,0x32,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x34,0x20,0x3d,0x20,0x5f,0x32,0x33,0x30,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x34,0x35,0x20,0x3d,0x20,0x5f,0x32,0x33,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x36,0x20,0x3d, + 0x20,0x5f,0x32,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x37,0x20,0x3d,0x20,0x5f,0x32,0x34,0x38, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x34,0x38,0x20,0x3d,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x30,0x2e, + 0x30,0x30,0x31,0x36,0x35,0x39,0x39,0x39,0x39,0x39,0x35,0x30,0x37,0x38,0x38,0x39, + 0x31,0x35,0x31,0x35,0x37,0x33,0x31,0x38,0x31,0x31,0x35,0x32,0x33,0x34,0x33,0x37, + 0x35,0x20,0x2a,0x20,0x5f,0x32,0x35,0x38,0x29,0x20,0x2d,0x20,0x28,0x30,0x2e,0x30, + 0x30,0x33,0x37,0x34,0x39,0x39,0x39,0x39,0x39,0x31,0x36,0x31,0x38,0x30,0x39,0x36, + 0x38,0x32,0x38,0x34,0x36,0x30,0x36,0x39,0x33,0x33,0x35,0x39,0x33,0x37,0x35,0x20, + 0x2a,0x20,0x5f,0x32,0x35,0x34,0x29,0x29,0x20,0x2b,0x20,0x28,0x30,0x2e,0x30,0x30, + 0x32,0x30,0x39,0x30,0x30,0x30,0x30,0x30,0x38,0x31,0x38,0x30,0x37,0x33,0x37,0x34, + 0x39,0x35,0x34,0x32,0x32,0x33,0x36,0x33,0x32,0x38,0x31,0x32,0x35,0x20,0x2a,0x20, + 0x5f,0x31,0x35,0x31,0x29,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x38,0x29,0x20,0x2b, + 0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x2d,0x30,0x2e,0x30,0x32,0x39,0x30,0x33,0x30, + 0x30,0x30,0x30,0x37,0x39,0x30,0x39,0x35,0x33,0x36,0x33,0x36,0x31,0x36,0x39,0x34, + 0x33,0x33,0x35,0x39,0x33,0x37,0x35,0x29,0x20,0x2a,0x20,0x5f,0x32,0x35,0x38,0x29, + 0x20,0x2b,0x20,0x28,0x30,0x2e,0x30,0x36,0x33,0x37,0x37,0x30,0x30,0x30,0x33,0x36, + 0x31,0x36,0x38,0x30,0x39,0x38,0x34,0x34,0x39,0x37,0x30,0x37,0x30,0x33,0x31,0x32, + 0x35,0x20,0x2a,0x20,0x5f,0x32,0x35,0x34,0x29,0x29,0x20,0x2d,0x20,0x28,0x30,0x2e, + 0x30,0x33,0x32,0x30,0x31,0x39,0x39,0x39,0x38,0x38,0x37,0x38,0x32,0x34,0x30,0x35, + 0x38,0x35,0x33,0x32,0x37,0x31,0x34,0x38,0x34,0x33,0x37,0x35,0x20,0x2a,0x20,0x5f, + 0x31,0x35,0x31,0x29,0x29,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x33,0x39,0x34,0x30, + 0x30,0x30,0x30,0x31,0x39,0x38,0x37,0x38,0x31,0x34,0x39,0x30,0x33,0x32,0x35,0x39, + 0x32,0x37,0x37,0x33,0x34,0x33,0x37,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34, + 0x29,0x29,0x20,0x2b,0x20,0x28,0x28,0x28,0x28,0x30,0x2e,0x31,0x31,0x36,0x39,0x33, + 0x30,0x30,0x30,0x30,0x34,0x38,0x33,0x39,0x38,0x39,0x37,0x31,0x35,0x35,0x37,0x36, + 0x31,0x37,0x31,0x38,0x37,0x35,0x20,0x2a,0x20,0x5f,0x32,0x35,0x38,0x29,0x20,0x2d, + 0x20,0x28,0x30,0x2e,0x32,0x31,0x31,0x39,0x36,0x30,0x30,0x30,0x32,0x37,0x37,0x39, + 0x39,0x36,0x30,0x36,0x33,0x32,0x33,0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x20,0x2a, + 0x20,0x5f,0x32,0x35,0x34,0x29,0x29,0x20,0x2b,0x20,0x28,0x30,0x2e,0x30,0x36,0x30, + 0x35,0x32,0x30,0x30,0x30,0x30,0x37,0x35,0x35,0x37,0x38,0x36,0x38,0x39,0x35,0x37, + 0x35,0x31,0x39,0x35,0x33,0x31,0x32,0x35,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31,0x29, + 0x29,0x20,0x2b,0x20,0x30,0x2e,0x32,0x35,0x38,0x38,0x35,0x39,0x39,0x39,0x32,0x30, + 0x32,0x37,0x32,0x38,0x32,0x37,0x31,0x34,0x38,0x34,0x33,0x37,0x35,0x29,0x29,0x20, + 0x2a,0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x50,0x65,0x72,0x65,0x7a,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x29,0x29,0x20,0x2f, + 0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x70,0x72,0x65,0x65,0x74, + 0x68,0x61,0x6d,0x50,0x65,0x72,0x65,0x7a,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, + 0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x33,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x35,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x33,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x38,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x33,0x39,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39, + 0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35, + 0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x34,0x39,0x20,0x3d,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x30,0x2e, + 0x30,0x30,0x32,0x37,0x34,0x39,0x39,0x39,0x39,0x39,0x38,0x35,0x30,0x39,0x38,0x38, + 0x33,0x38,0x38,0x30,0x36,0x31,0x35,0x32,0x33,0x34,0x33,0x37,0x35,0x20,0x2a,0x20, + 0x5f,0x32,0x35,0x38,0x29,0x20,0x2d,0x20,0x28,0x30,0x2e,0x30,0x30,0x36,0x30,0x39, + 0x39,0x39,0x39,0x39,0x38,0x38,0x32,0x32,0x38,0x30,0x38,0x32,0x36,0x35,0x36,0x38, + 0x36,0x30,0x33,0x35,0x31,0x35,0x36,0x32,0x35,0x20,0x2a,0x20,0x5f,0x32,0x35,0x34, + 0x29,0x29,0x20,0x2b,0x20,0x28,0x30,0x2e,0x30,0x30,0x33,0x31,0x36,0x39,0x39,0x39, + 0x39,0x39,0x32,0x33,0x35,0x35,0x37,0x30,0x34,0x33,0x30,0x37,0x35,0x35,0x36,0x31, + 0x35,0x32,0x33,0x34,0x33,0x37,0x35,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31,0x29,0x29, + 0x20,0x2a,0x20,0x5f,0x31,0x35,0x38,0x29,0x20,0x2b,0x20,0x28,0x28,0x28,0x28,0x28, + 0x28,0x2d,0x30,0x2e,0x30,0x34,0x32,0x31,0x33,0x39,0x39,0x39,0x39,0x35,0x36,0x38, + 0x34,0x36,0x32,0x33,0x37,0x31,0x38,0x32,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x29, + 0x20,0x2a,0x20,0x5f,0x32,0x35,0x38,0x29,0x20,0x2b,0x20,0x28,0x30,0x2e,0x30,0x38, + 0x39,0x36,0x39,0x39,0x39,0x39,0x38,0x34,0x39,0x37,0x39,0x36,0x32,0x39,0x35,0x31, + 0x36,0x36,0x30,0x31,0x35,0x36,0x32,0x35,0x20,0x2a,0x20,0x5f,0x32,0x35,0x34,0x29, + 0x29,0x20,0x2d,0x20,0x28,0x30,0x2e,0x30,0x34,0x31,0x35,0x32,0x39,0x39,0x39,0x38, + 0x31,0x38,0x33,0x32,0x35,0x30,0x34,0x32,0x37,0x32,0x34,0x36,0x30,0x39,0x33,0x37, + 0x35,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31,0x29,0x29,0x20,0x2b,0x20,0x30,0x2e,0x30, + 0x30,0x35,0x31,0x36,0x30,0x30,0x30,0x30,0x31,0x37,0x35,0x32,0x33,0x37,0x36,0x35, + 0x35,0x36,0x33,0x39,0x36,0x34,0x38,0x34,0x33,0x37,0x35,0x29,0x20,0x2a,0x20,0x5f, + 0x31,0x35,0x34,0x29,0x29,0x20,0x2b,0x20,0x28,0x28,0x28,0x28,0x30,0x2e,0x31,0x35, + 0x33,0x34,0x35,0x39,0x39,0x39,0x35,0x39,0x38,0x35,0x30,0x33,0x31,0x31,0x32,0x37, + 0x39,0x32,0x39,0x36,0x38,0x37,0x35,0x20,0x2a,0x20,0x5f,0x32,0x35,0x38,0x29,0x20, + 0x2d,0x20,0x28,0x30,0x2e,0x32,0x36,0x37,0x35,0x36,0x30,0x30,0x30,0x35,0x31,0x38, + 0x37,0x39,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x20,0x2a,0x20,0x5f,0x32,0x35,0x34, + 0x29,0x29,0x20,0x2b,0x20,0x28,0x30,0x2e,0x30,0x36,0x36,0x36,0x39,0x39,0x39,0x39, + 0x36,0x35,0x39,0x30,0x36,0x31,0x34,0x33,0x31,0x38,0x38,0x34,0x37,0x36,0x35,0x36, + 0x32,0x35,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31,0x29,0x29,0x20,0x2b,0x20,0x30,0x2e, + 0x32,0x36,0x36,0x38,0x38,0x30,0x30,0x30,0x35,0x35,0x39,0x38,0x30,0x36,0x38,0x32, + 0x33,0x37,0x33,0x30,0x34,0x36,0x38,0x37,0x35,0x29,0x29,0x20,0x2a,0x20,0x70,0x72, + 0x65,0x65,0x74,0x68,0x61,0x6d,0x50,0x65,0x72,0x65,0x7a,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33,0x29,0x29,0x20,0x2f,0x20,0x66, + 0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x70,0x72,0x65,0x65,0x74,0x68,0x61, + 0x6d,0x50,0x65,0x72,0x65,0x7a,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x30,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x34,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x33,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x34,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, + 0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x36,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x34,0x37,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39, + 0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34, + 0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x35,0x30,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x28, + 0x28,0x28,0x28,0x28,0x28,0x34,0x2e,0x30,0x34,0x35,0x33,0x30,0x30,0x30,0x30,0x36, + 0x38,0x36,0x36,0x34,0x35,0x35,0x30,0x37,0x38,0x31,0x32,0x35,0x20,0x2a,0x20,0x5f, + 0x31,0x35,0x34,0x29,0x20,0x2d,0x20,0x34,0x2e,0x39,0x37,0x31,0x30,0x30,0x30,0x31, + 0x39,0x34,0x35,0x34,0x39,0x35,0x36,0x30,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20, + 0x2a,0x20,0x74,0x61,0x6e,0x28,0x28,0x30,0x2e,0x34,0x34,0x34,0x34,0x34,0x34,0x34, + 0x34,0x37,0x37,0x35,0x35,0x38,0x31,0x33,0x35,0x39,0x38,0x36,0x33,0x32,0x38,0x31, + 0x32,0x35,0x20,0x2d,0x20,0x28,0x5f,0x31,0x35,0x34,0x20,0x2a,0x20,0x30,0x2e,0x30, + 0x30,0x38,0x33,0x33,0x33,0x33,0x33,0x33,0x37,0x36,0x37,0x39,0x35,0x30,0x35,0x33, + 0x34,0x38,0x32,0x30,0x35,0x35,0x36,0x36,0x34,0x30,0x36,0x32,0x35,0x29,0x29,0x20, + 0x2a,0x20,0x28,0x33,0x2e,0x31,0x34,0x31,0x35,0x39,0x32,0x37,0x34,0x31,0x30,0x31, + 0x32,0x35,0x37,0x33,0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x20,0x2d,0x20,0x28,0x32, + 0x2e,0x30,0x20,0x2a,0x20,0x5f,0x31,0x35,0x31,0x29,0x29,0x29,0x29,0x20,0x2d,0x20, + 0x28,0x30,0x2e,0x32,0x31,0x35,0x34,0x39,0x39,0x39,0x39,0x37,0x31,0x33,0x38,0x39, + 0x37,0x37,0x30,0x35,0x30,0x37,0x38,0x31,0x32,0x35,0x20,0x2a,0x20,0x5f,0x31,0x35, + 0x34,0x29,0x29,0x20,0x2b,0x20,0x32,0x2e,0x34,0x31,0x39,0x31,0x39,0x39,0x39,0x34, + 0x33,0x35,0x34,0x32,0x34,0x38,0x30,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20, + 0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x50,0x65,0x72,0x65,0x7a,0x28,0x70,0x61, + 0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x37,0x29,0x29,0x20,0x2f,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78, + 0x28,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x50,0x65,0x72,0x65,0x7a,0x28,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x36,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x38,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x33,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x31,0x29,0x2c,0x20, + 0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35, + 0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38, + 0x38,0x65,0x2d,0x30,0x36,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35, + 0x31,0x20,0x3d,0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x58,0x79,0x59,0x5f, + 0x74,0x6f,0x5f,0x58,0x59,0x5a,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x38,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x35,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x70,0x72,0x65,0x65,0x74, + 0x68,0x61,0x6d,0x58,0x59,0x5a,0x5f,0x74,0x6f,0x5f,0x6c,0x69,0x6e,0x65,0x61,0x72, + 0x5f,0x73,0x72,0x67,0x62,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x31,0x29,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20, + 0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61, + 0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x53,0x6b, + 0x79,0x53,0x63,0x61,0x6c,0x65,0x64,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x76,0x69,0x65, + 0x77,0x5f,0x64,0x69,0x72,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x73,0x75,0x6e,0x5f, + 0x64,0x69,0x72,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x74,0x75,0x72,0x62,0x69,0x64,0x69, + 0x74,0x79,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x66,0x61,0x64,0x65,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x20,0x3d,0x20,0x76,0x69,0x65,0x77,0x5f,0x64,0x69,0x72,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20, + 0x3d,0x20,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x74, + 0x75,0x72,0x62,0x69,0x64,0x69,0x74,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x28,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x53,0x6b, + 0x79,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x20,0x2a,0x20,0x30,0x2e,0x30, + 0x35,0x39,0x39,0x39,0x39,0x39,0x39,0x38,0x36,0x35,0x38,0x38,0x39,0x35,0x34,0x39, + 0x32,0x35,0x35,0x33,0x37,0x31,0x30,0x39,0x33,0x37,0x35,0x29,0x20,0x2a,0x20,0x66, + 0x61,0x64,0x65,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74, + 0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30, + 0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73, + 0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x66,0x61,0x63,0x65,0x26,0x20,0x5f,0x35,0x34, + 0x36,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74, + 0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x35,0x34,0x31,0x20,0x3d,0x20,0x28,0x69,0x6e, + 0x2e,0x76,0x5f,0x75,0x76,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x20,0x2d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x32,0x28,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x66, + 0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x28, + 0x5f,0x35,0x34,0x36,0x2e,0x66,0x61,0x63,0x65,0x5f,0x66,0x6f,0x72,0x77,0x61,0x72, + 0x64,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x35,0x34,0x36,0x2e,0x66,0x61, + 0x63,0x65,0x5f,0x72,0x69,0x67,0x68,0x74,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x5f, + 0x35,0x34,0x31,0x2e,0x78,0x29,0x29,0x20,0x2b,0x20,0x28,0x5f,0x35,0x34,0x36,0x2e, + 0x66,0x61,0x63,0x65,0x5f,0x75,0x70,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x5f,0x35, + 0x34,0x31,0x2e,0x79,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x35,0x34, + 0x36,0x2e,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e, + 0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x35,0x34,0x36,0x2e,0x73,0x75, + 0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x77,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, + 0x20,0x3d,0x20,0x5f,0x35,0x34,0x36,0x2e,0x66,0x61,0x63,0x65,0x5f,0x66,0x6f,0x72, + 0x77,0x61,0x72,0x64,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e, + 0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x28,0x70,0x72,0x65,0x65,0x74,0x68,0x61,0x6d,0x53,0x6b,0x79,0x53,0x63, + 0x61,0x6c,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x00, +}; +static inline const sg_shader_desc* sky_to_cube_build_shader_desc(sg_backend backend) { + if (backend == SG_BACKEND_GLCORE) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)sky_to_cube_vs_source_glsl430; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)sky_to_cube_fs_source_glsl430; + desc.fragment_func.entry = "main"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[0].glsl_uniforms[0].array_count = 4; + desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_face"; + desc.label = "sky_to_cube_build_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_D3D11) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)sky_to_cube_vs_source_hlsl5; + desc.vertex_func.d3d11_target = "vs_5_0"; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)sky_to_cube_fs_source_hlsl5; + desc.fragment_func.d3d11_target = "ps_5_0"; + desc.fragment_func.entry = "main"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].hlsl_register_b_n = 0; + desc.label = "sky_to_cube_build_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_METAL_MACOS) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)sky_to_cube_vs_source_metal_macos; + desc.vertex_func.entry = "main0"; + desc.fragment_func.source = (const char*)sky_to_cube_fs_source_metal_macos; + desc.fragment_func.entry = "main0"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].msl_buffer_n = 0; + desc.label = "sky_to_cube_build_shader"; + } + return &desc; + } + return 0; +} diff --git a/samples/shaders/generated/sphere.glsl.h b/samples/shaders/generated/sphere.glsl.h new file mode 100644 index 0000000..5c49fd1 --- /dev/null +++ b/samples/shaders/generated/sphere.glsl.h @@ -0,0 +1,4913 @@ +#pragma once +/* + #version:1# (machine generated, don't edit!) + + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) + + Cmdline: + sokol-shdc --input E:/box/box3d/samples/shaders/shapes/sphere.glsl --output E:/box/box3d/samples/shaders/generated/sphere.glsl.h --slang hlsl5:metal_macos:glsl430 + + Overview: + ========= + Shader program: 'impostor': + Get shader desc: sphere_impostor_shader_desc(sg_query_backend()); + Vertex Shader: vs + Fragment Shader: fs + Attributes: + ATTR_sphere_impostor_in_pos => 0 + Bindings: + Uniform block 'ub_draw': + C struct: sphere_ub_draw_t + Bind slot: UB_sphere_ub_draw => 2 + Uniform block 'ub_frame': + C struct: sphere_ub_frame_t + Bind slot: UB_sphere_ub_frame => 0 + Uniform block 'ub_pass': + C struct: sphere_ub_pass_t + Bind slot: UB_sphere_ub_pass => 1 + Storage buffer 'instances': + C struct: sphere_instance_t + Bind slot: VIEW_sphere_instances => 0 + Readonly: true + Texture 'tex_shadow': + Image type: SG_IMAGETYPE_ARRAY + Sample type: SG_IMAGESAMPLETYPE_DEPTH + Multisampled: false + Bind slot: VIEW_sphere_tex_shadow => 1 + Texture 'tex_ao': + Image type: SG_IMAGETYPE_2D + Sample type: SG_IMAGESAMPLETYPE_FLOAT + Multisampled: false + Bind slot: VIEW_sphere_tex_ao => 4 + Texture 'tex_ibl_spec': + Image type: SG_IMAGETYPE_CUBE + Sample type: SG_IMAGESAMPLETYPE_FLOAT + Multisampled: false + Bind slot: VIEW_sphere_tex_ibl_spec => 2 + Texture 'tex_brdf_lut': + Image type: SG_IMAGETYPE_2D + Sample type: SG_IMAGESAMPLETYPE_FLOAT + Multisampled: false + Bind slot: VIEW_sphere_tex_brdf_lut => 3 + Sampler 'smp_shadow': + Type: SG_SAMPLERTYPE_COMPARISON + Bind slot: SMP_sphere_smp_shadow => 0 + Sampler 'smp_ao': + Type: SG_SAMPLERTYPE_FILTERING + Bind slot: SMP_sphere_smp_ao => 3 + Sampler 'smp_ibl_spec': + Type: SG_SAMPLERTYPE_FILTERING + Bind slot: SMP_sphere_smp_ibl_spec => 1 + Sampler 'smp_brdf_lut': + Type: SG_SAMPLERTYPE_FILTERING + Bind slot: SMP_sphere_smp_brdf_lut => 2 +*/ +#if !defined(SOKOL_GFX_INCLUDED) +#error "Please include sokol_gfx.h before sphere.glsl.h" +#endif +#if !defined(SOKOL_SHDC_ALIGN) +#if defined(_MSC_VER) +#define SOKOL_SHDC_ALIGN(a) __declspec(align(a)) +#else +#define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) +#endif +#endif +#define ATTR_sphere_impostor_in_pos (0) +#define UB_sphere_ub_draw (2) +#define UB_sphere_ub_frame (0) +#define UB_sphere_ub_pass (1) +#define VIEW_sphere_instances (0) +#define VIEW_sphere_tex_shadow (1) +#define VIEW_sphere_tex_ao (4) +#define VIEW_sphere_tex_ibl_spec (2) +#define VIEW_sphere_tex_brdf_lut (3) +#define SMP_sphere_smp_shadow (0) +#define SMP_sphere_smp_ao (3) +#define SMP_sphere_smp_ibl_spec (1) +#define SMP_sphere_smp_brdf_lut (2) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct sphere_ub_draw_t { + int inst_base[4]; +} sphere_ub_draw_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct sphere_ub_frame_t { + Mat4 view_proj; +} sphere_ub_frame_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct sphere_ub_pass_t { + Vec4 sun_dir_world; + Vec4 sun_color; + int flags[4]; + Vec4 camera_pos; + Mat4 view_proj; + Mat4 view; + Vec4 cascade_far_view_z; + Mat4 cascade_matrices[3]; + Vec4 sh[9]; + Vec4 ibl_params; +} sphere_ub_pass_t; +#pragma pack(pop) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct sphere_instance_t { + Vec4 xform_row0; + Vec4 xform_row1; + Vec4 xform_row2; + Vec4 base_color; + Vec4 params; + Vec4 material; +} sphere_instance_t; +#pragma pack(pop) +/* + #version 430 + + struct instance + { + vec4 xform_row0; + vec4 xform_row1; + vec4 xform_row2; + vec4 base_color; + vec4 params; + vec4 material; + }; + + layout(binding = 0, std430) readonly buffer instances + { + instance items[]; + } _15; + + uniform ivec4 ub_draw[1]; + uniform vec4 ub_frame[4]; + layout(location = 0) in vec3 in_pos; + layout(location = 0) out vec3 v_world_pos_proxy; + layout(location = 1) flat out vec3 v_center; + layout(location = 2) flat out float v_radius; + layout(location = 3) flat out vec3 v_rot_row0; + layout(location = 4) flat out vec3 v_rot_row1; + layout(location = 5) flat out vec3 v_rot_row2; + layout(location = 6) flat out vec4 v_base_color; + layout(location = 7) flat out vec4 v_material; + + void main() + { + int _30 = ub_draw[0].x + gl_InstanceID; + vec3 _63 = vec3(_15.items[_30].xform_row0.w, _15.items[_30].xform_row1.w, _15.items[_30].xform_row2.w); + vec3 _76 = _63 + (in_pos * (2.0 * _15.items[_30].params.x)); + v_world_pos_proxy = _76; + v_center = _63; + v_radius = _15.items[_30].params.x; + v_rot_row0 = _15.items[_30].xform_row0.xyz; + v_rot_row1 = _15.items[_30].xform_row1.xyz; + v_rot_row2 = _15.items[_30].xform_row2.xyz; + v_base_color = _15.items[_30].base_color; + v_material = _15.items[_30].material; + gl_Position = mat4(ub_frame[0], ub_frame[1], ub_frame[2], ub_frame[3]) * vec4(_76, 1.0); + } + +*/ +static const uint8_t sphere_vs_source_glsl430[1358] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72, + 0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x6d,0x61, + 0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f, + 0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x30,0x2c,0x20, + 0x73,0x74,0x64,0x34,0x33,0x30,0x29,0x20,0x72,0x65,0x61,0x64,0x6f,0x6e,0x6c,0x79, + 0x20,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x20,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5d,0x3b,0x0a,0x7d,0x20,0x5f,0x31,0x35,0x3b, + 0x0a,0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x69,0x76,0x65,0x63,0x34,0x20, + 0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x5b,0x31,0x5d,0x3b,0x0a,0x75,0x6e,0x69,0x66, + 0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d, + 0x65,0x5b,0x34,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63, + 0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65, + 0x63,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75, + 0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20, + 0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x6c,0x61,0x79,0x6f, + 0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29, + 0x20,0x66,0x6c,0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20,0x76, + 0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28, + 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x66,0x6c, + 0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72, + 0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f, + 0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x33,0x29,0x20,0x66,0x6c,0x61,0x74, + 0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f, + 0x72,0x6f,0x77,0x30,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63, + 0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x34,0x29,0x20,0x66,0x6c,0x61,0x74,0x20, + 0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72, + 0x6f,0x77,0x31,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x35,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x6f, + 0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f, + 0x77,0x32,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74, + 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x36,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x6f,0x75, + 0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x37,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x6f, + 0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69, + 0x61,0x6c,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x33,0x30,0x20,0x3d, + 0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x5b,0x30,0x5d,0x2e,0x78,0x20,0x2b,0x20, + 0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x36,0x33,0x20,0x3d,0x20,0x76,0x65, + 0x63,0x33,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30, + 0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20, + 0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78, + 0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35, + 0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x33,0x20,0x5f,0x37,0x36,0x20,0x3d,0x20,0x5f,0x36,0x33,0x20,0x2b,0x20, + 0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x2a,0x20,0x28,0x32,0x2e,0x30,0x20,0x2a, + 0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e, + 0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78, + 0x79,0x20,0x3d,0x20,0x5f,0x37,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x63, + 0x65,0x6e,0x74,0x65,0x72,0x20,0x3d,0x20,0x5f,0x36,0x33,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e, + 0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d, + 0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72, + 0x6f,0x77,0x30,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b, + 0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e, + 0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72, + 0x6f,0x77,0x31,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b, + 0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e, + 0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72, + 0x6f,0x77,0x32,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b, + 0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e, + 0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d, + 0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61, + 0x6c,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33, + 0x30,0x5d,0x2e,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d, + 0x61,0x74,0x34,0x28,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x30,0x5d,0x2c, + 0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x31,0x5d,0x2c,0x20,0x75,0x62, + 0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x32,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72, + 0x61,0x6d,0x65,0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x5f, + 0x37,0x36,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + #version 430 + + struct ub_pass + { + vec4 sun_dir_world; + vec4 sun_color; + ivec4 flags; + vec4 camera_pos; + mat4 view_proj; + mat4 view; + vec4 cascade_far_view_z; + mat4 cascade_matrices[3]; + vec4 sh[9]; + vec4 ibl_params; + }; + + uniform ub_pass _707; + + layout(binding = 0) uniform sampler2D tex_ao_smp_ao; + layout(binding = 1) uniform sampler2DArrayShadow tex_shadow_smp_shadow; + layout(binding = 2) uniform samplerCube tex_ibl_spec_smp_ibl_spec; + layout(binding = 3) uniform sampler2D tex_brdf_lut_smp_brdf_lut; + + layout(location = 0) in vec3 v_world_pos_proxy; + layout(location = 1) flat in vec3 v_center; + layout(location = 2) flat in float v_radius; + layout(location = 3) flat in vec3 v_rot_row0; + layout(location = 4) flat in vec3 v_rot_row1; + layout(location = 5) flat in vec3 v_rot_row2; + layout(location = 6) flat in vec4 v_base_color; + layout(location = 0) out vec4 out_color; + layout(location = 7) flat in vec4 v_material; + + float sampleShadowPCF(int cascade, vec3 light_uv, float bias) + { + float _529 = float(cascade); + float _534 = light_uv.z - bias; + float _550 = light_uv.x - 0.00048828125; + float _554 = light_uv.y - 0.00048828125; + float _584 = light_uv.x + 0.00048828125; + float _652 = light_uv.y + 0.00048828125; + return ((((((((texture(tex_shadow_smp_shadow, vec4(vec4(_550, _554, _529, _534).xyz, _534)) + texture(tex_shadow_smp_shadow, vec4(vec4(light_uv.x, _554, _529, _534).xyz, _534))) + texture(tex_shadow_smp_shadow, vec4(vec4(_584, _554, _529, _534).xyz, _534))) + texture(tex_shadow_smp_shadow, vec4(vec4(_550, light_uv.y, _529, _534).xyz, _534))) + texture(tex_shadow_smp_shadow, vec4(vec4(light_uv.xy, _529, _534).xyz, _534))) + texture(tex_shadow_smp_shadow, vec4(vec4(_584, light_uv.y, _529, _534).xyz, _534))) + texture(tex_shadow_smp_shadow, vec4(vec4(_550, _652, _529, _534).xyz, _534))) + texture(tex_shadow_smp_shadow, vec4(vec4(light_uv.x, _652, _529, _534).xyz, _534))) + texture(tex_shadow_smp_shadow, vec4(vec4(_584, _652, _529, _534).xyz, _534))) * 0.111111111938953399658203125; + } + + float sampleCascade(int cascade, vec3 world_pos, vec3 world_normal) + { + vec4 _717 = _707.cascade_matrices[cascade] * vec4(world_pos, 1.0); + vec3 _724 = _717.xyz / vec3(_717.w); + vec3 _742 = vec3((_724.x * 0.5) + 0.5, ((_724.y * _707.cascade_far_view_z.w) * 0.5) + 0.5, _724.z); + bool _746 = any(lessThan(_742, vec3(0.0))); + bool _753; + if (!_746) + { + _753 = any(greaterThan(_742, vec3(1.0))); + } + else + { + _753 = _746; + } + if (_753) + { + return 1.0; + } + int param = cascade; + vec3 param_1 = _742; + float param_2 = mix(0.0040000001899898052215576171875, 0.0007999999797903001308441162109375, max(dot(world_normal, normalize(_707.sun_dir_world.xyz)), 0.0)); + float pcf = sampleShadowPCF(param, param_1, param_2); + if (cascade == 2) + { + vec2 _785 = _742.xy; + vec2 _790 = min(_785, vec2(1.0) - _785); + pcf = mix(1.0, pcf, clamp(min(_790.x, _790.y) * 10.0, 0.0, 1.0)); + } + return pcf; + } + + float sampleShadowCascaded(vec3 world_pos, vec3 world_normal, float view_z) + { + int cascade = 2; + if (view_z < _707.cascade_far_view_z.x) + { + cascade = 0; + } + else + { + if (view_z < _707.cascade_far_view_z.y) + { + cascade = 1; + } + } + int param = cascade; + vec3 param_1 = world_pos; + vec3 param_2 = world_normal; + float shadow = sampleCascade(param, param_1, param_2); + if (cascade < 2) + { + float _835; + if (cascade == 0) + { + _835 = _707.cascade_far_view_z.x; + } + else + { + _835 = _707.cascade_far_view_z.y; + } + float _847; + if (cascade == 0) + { + _847 = 0.0; + } + else + { + _847 = _707.cascade_far_view_z.x; + } + float _858 = mix(_835, _847, 0.100000001490116119384765625); + if (view_z > _858) + { + int param_3 = cascade + 1; + vec3 param_4 = world_pos; + vec3 param_5 = world_normal; + shadow = mix(shadow, sampleCascade(param_3, param_4, param_5), (view_z - _858) / (_835 - _858)); + } + } + return shadow; + } + + float pbrDistributionGGX(float n_dot_h, float alpha) + { + float _107 = alpha * alpha; + float _116 = ((n_dot_h * n_dot_h) * (_107 - 1.0)) + 1.0; + return _107 / ((3.1415927410125732421875 * _116) * _116); + } + + float pbrVisibilitySmithCorrelated(float n_dot_v, float n_dot_l, float alpha) + { + float _129 = alpha * alpha; + float _136 = 1.0 - _129; + return 0.5 / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _136) + _129)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _136) + _129))) + 9.9999997473787516355514526367188e-06); + } + + vec3 pbrFresnelSchlick(float v_dot_h, vec3 f0) + { + float _165 = 1.0 - v_dot_h; + float _169 = _165 * _165; + return f0 + ((vec3(1.0) - f0) * ((_169 * _169) * _165)); + } + + vec3 brdf_evaluate(vec3 N, vec3 V, vec3 L, vec3 sun_radiance, vec3 base_color, float metallic, float roughness) + { + float _188 = max(dot(N, L), 0.0); + vec3 _199 = normalize(V + L); + float _213 = max(roughness, 0.04500000178813934326171875); + float _217 = _213 * _213; + float param = max(dot(N, _199), 0.0); + float param_1 = _217; + float param_2 = max(dot(N, V), 9.9999997473787516355514526367188e-05); + float param_3 = _188; + float param_4 = _217; + float param_5 = max(dot(V, _199), 0.0); + vec3 param_6 = mix(vec3(0.039999999105930328369140625), base_color, vec3(metallic)); + vec3 _244 = pbrFresnelSchlick(param_5, param_6); + return ((((((vec3(1.0) - _244) * (1.0 - metallic)) * base_color) * vec3(0.3183098733425140380859375)) + (_244 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _188; + } + + vec3 pbrEvaluateShIrradiance(vec3 N, vec4 sh[9]) + { + vec3 _399 = ((((((((sh[0].xyz * 0.2820948064327239990234375) + (sh[1].xyz * ((-0.48860251903533935546875) * N.y))) + (sh[2].xyz * (0.48860251903533935546875 * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125 * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125 * (((3.0 * N.z) * N.z) - 1.0)))) + (sh[7].xyz * (((-1.09254848957061767578125) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625 * ((N.x * N.x) - (N.y * N.y)))); + return _399; + } + + vec3 pbrEvaluateIbl(vec3 N_world, vec3 V_world, vec3 base_color, float metallic, float roughness, vec4 sh[9], float max_lod, samplerCube SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, sampler2D SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut) + { + float _406 = clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05, 1.0); + vec3 _416 = mix(vec3(0.039999999105930328369140625), base_color, vec3(metallic)); + vec3 param = N_world; + vec4 param_1[9] = sh; + vec4 _482 = texture(SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut, vec2(_406, roughness)); + return (((((vec3(1.0) - (_416 + ((max(vec3(1.0 - roughness), _416) - _416) * pow(max(0.0, 1.0 - _406), 5.0)))) * (1.0 - metallic)) * base_color) * max(pbrEvaluateShIrradiance(param, param_1), vec3(0.0))) * vec3(0.3183098733425140380859375)) + (textureLod(SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, reflect(-V_world, N_world), roughness * max_lod).xyz * ((_416 * _482.x) + vec3(_482.y))); + } + + vec3 pbrEvaluateAmbient(bool iblEnabled, vec3 N_world, vec3 V_world, vec3 base_color, float metallic, float roughness, float flat_strength, vec4 sh[9], float max_lod, samplerCube SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, sampler2D SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut) + { + vec3 result = base_color * flat_strength; + if (iblEnabled) + { + vec3 param = N_world; + vec3 param_1 = V_world; + vec3 param_2 = base_color; + float param_3 = metallic; + float param_4 = roughness; + vec4 param_5[9] = sh; + float param_6 = max_lod; + result = pbrEvaluateIbl(param, param_1, param_2, param_3, param_4, param_5, param_6, SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut); + } + return result; + } + + void main() + { + vec3 _896 = normalize(v_world_pos_proxy - _707.camera_pos.xyz); + vec3 _901 = _707.camera_pos.xyz - v_center; + float _905 = dot(_901, _896); + float _914 = v_radius * v_radius; + float _921 = (_905 * _905) - (dot(_901, _901) - _914); + float _931 = sqrt(max(0.0, _914 - _921)) - v_radius; + float _934 = fwidth(_931); + float _936 = max(_934, 9.9999999747524270787835121154785e-07); + float _943 = 1.0 - smoothstep(-_936, _936, _931); + float _947; + if (_921 >= 0.0) + { + _947 = (-_905) - sqrt(_921); + } + else + { + _947 = -_905; + } + if ((_943 <= 0.0) || (_947 < 0.0)) + { + discard; + } + vec3 _972 = _707.camera_pos.xyz + (_896 * _947); + vec3 _977 = normalize(_972 - v_center); + float _983 = _977.x; + float _989 = _977.y; + float _996 = _977.z; + float _998 = ((v_rot_row0.x * _983) + (v_rot_row1.x * _989)) + (v_rot_row2.x * _996); + float _1015 = ((v_rot_row0.y * _983) + (v_rot_row1.y * _989)) + (v_rot_row2.y * _996); + float _1032 = ((v_rot_row0.z * _983) + (v_rot_row1.z * _989)) + (v_rot_row2.z * _996); + vec3 _1083 = v_base_color.xyz * ((_1015 > 0.0) ? 1.0 : 0.64999997615814208984375); + vec3 _1093 = mix(_1083, _1083 * 0.3499999940395355224609375, vec3(max(1.0 - smoothstep(0.0, fwidth(_998) * 1.5, abs(_998)), max(1.0 - smoothstep(0.0, fwidth(_1015) * 1.5, abs(_1015)), 1.0 - smoothstep(0.0, fwidth(_1032) * 1.5, abs(_1032)))))); + vec4 _1101 = vec4(_972, 1.0); + vec4 _1102 = _707.view_proj * _1101; + gl_FragDepth = _1102.z / _1102.w; + if (_707.flags.x == 1) + { + float _1134 = clamp((_707.view * _1101).z * (-0.0199999995529651641845703125), 0.0, 1.0); + out_color = vec4(_1134, _1134, _1134, 1.0); + return; + } + if (_707.flags.x == 2) + { + float _1155 = -(_707.view * _1101).z; + int cascade = 2; + if (_1155 < _707.cascade_far_view_z.x) + { + cascade = 0; + } + else + { + if (_1155 < _707.cascade_far_view_z.y) + { + cascade = 1; + } + } + vec4 _1179 = _707.cascade_matrices[cascade] * _1101; + vec3 _1186 = _1179.xyz / vec3(_1179.w); + vec3 _1203 = vec3((_1186.x * 0.5) + 0.5, ((_1186.y * _707.cascade_far_view_z.w) * 0.5) + 0.5, _1186.z); + bool _1207 = any(lessThan(_1203, vec3(0.0))); + bool _1214; + if (!_1207) + { + _1214 = any(greaterThan(_1203, vec3(1.0))); + } + else + { + _1214 = _1207; + } + vec3 tint = vec3(1.0); + if (!_1214) + { + if (cascade == 0) + { + tint = vec3(1.0, 0.4000000059604644775390625, 0.4000000059604644775390625); + } + else + { + if (cascade == 1) + { + tint = vec3(0.4000000059604644775390625, 1.0, 0.4000000059604644775390625); + } + else + { + tint = vec3(0.4000000059604644775390625, 0.4000000059604644775390625, 1.0); + } + } + } + out_color = vec4(tint, 1.0); + return; + } + if (_707.flags.x == 3) + { + out_color = vec4((normalize((_707.view * vec4(_983, _989, _996, 0.0)).xyz) * 0.5) + vec3(0.5), 1.0); + return; + } + vec4 _1284 = textureLod(tex_ao_smp_ao, gl_FragCoord.xy / vec2(textureSize(tex_ao_smp_ao, 0)), 0.0); + float _1285 = _1284.x; + if (_707.flags.x == 4) + { + out_color = vec4(_1285, _1285, _1285, 1.0); + return; + } + vec3 param = _972; + vec3 param_1 = _977; + float param_2 = -(_707.view * _1101).z; + vec3 _1333 = normalize(_707.camera_pos.xyz - _972); + vec3 param_3 = _977; + vec3 param_4 = _1333; + vec3 param_5 = normalize(_707.sun_dir_world.xyz); + vec3 param_6 = _707.sun_color.xyz * sampleShadowCascaded(param, param_1, param_2); + vec3 param_7 = _1093; + float param_8 = v_material.x; + float param_9 = v_material.y; + bool param_10 = _707.ibl_params.y > 0.5; + vec3 param_11 = _977; + vec3 param_12 = _1333; + vec3 param_13 = _1093; + float param_14 = v_material.x; + float param_15 = v_material.y; + float param_16 = _707.sun_color.w; + vec4 param_17[9]; + param_17[0] = _707.sh[0]; + param_17[1] = _707.sh[1]; + param_17[2] = _707.sh[2]; + param_17[3] = _707.sh[3]; + param_17[4] = _707.sh[4]; + param_17[5] = _707.sh[5]; + param_17[6] = _707.sh[6]; + param_17[7] = _707.sh[7]; + param_17[8] = _707.sh[8]; + float param_18 = _707.ibl_params.x; + float _1412 = v_base_color.w * _943; + out_color = vec4((brdf_evaluate(param_3, param_4, param_5, param_6, param_7, param_8, param_9) + (pbrEvaluateAmbient(param_10, param_11, param_12, param_13, param_14, param_15, param_16, param_17, param_18, tex_ibl_spec_smp_ibl_spec, tex_brdf_lut_smp_brdf_lut) * _1285)) * _1412, _1412); + } + +*/ +static const uint8_t sphere_fs_source_glsl430[13172] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20, + 0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x76,0x65,0x63,0x34,0x20,0x66,0x6c,0x61,0x67,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x65,0x63,0x34,0x20,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x74,0x34,0x20,0x76,0x69,0x65,0x77,0x5f,0x70, + 0x72,0x6f,0x6a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x74,0x34,0x20,0x76,0x69, + 0x65,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x74,0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x33,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61, + 0x6d,0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20, + 0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x20,0x5f,0x37,0x30,0x37,0x3b,0x0a,0x0a,0x6c, + 0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20, + 0x30,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x5f,0x73,0x6d,0x70,0x5f, + 0x61,0x6f,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69, + 0x6e,0x67,0x20,0x3d,0x20,0x31,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x41,0x72,0x72,0x61,0x79,0x53,0x68, + 0x61,0x64,0x6f,0x77,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f, + 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x6c,0x61,0x79,0x6f, + 0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x32,0x29,0x20, + 0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43, + 0x75,0x62,0x65,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63, + 0x5f,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x3b,0x0a,0x6c, + 0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20, + 0x33,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75, + 0x74,0x5f,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x3b,0x0a, + 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b, + 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x31,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65, + 0x63,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x6c,0x61,0x79, + 0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32, + 0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, + 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x33,0x29,0x20,0x66, + 0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x72,0x6f, + 0x74,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, + 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x34,0x29,0x20,0x66,0x6c,0x61, + 0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f, + 0x72,0x6f,0x77,0x31,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63, + 0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x35,0x29,0x20,0x66,0x6c,0x61,0x74,0x20, + 0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f, + 0x77,0x32,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74, + 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x36,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e, + 0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74, + 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63, + 0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79, + 0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x37, + 0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x76, + 0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x0a,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43, + 0x46,0x28,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x76, + 0x65,0x63,0x33,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x62,0x69,0x61,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x32,0x39,0x20,0x3d,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x33,0x34,0x20,0x3d,0x20,0x6c,0x69, + 0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x7a,0x20,0x2d,0x20,0x62,0x69,0x61,0x73,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x35,0x30,0x20, + 0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20,0x2d,0x20,0x30, + 0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x35,0x34,0x20,0x3d,0x20,0x6c, + 0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x20,0x2d,0x20,0x30,0x2e,0x30,0x30, + 0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x38,0x34,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68, + 0x74,0x5f,0x75,0x76,0x2e,0x78,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38, + 0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x36,0x35,0x32,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75, + 0x76,0x2e,0x79,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38, + 0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28, + 0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34, + 0x28,0x5f,0x35,0x35,0x30,0x2c,0x20,0x5f,0x35,0x35,0x34,0x2c,0x20,0x5f,0x35,0x32, + 0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35, + 0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74, + 0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68, + 0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28, + 0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20,0x5f,0x35,0x35,0x34, + 0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79, + 0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78, + 0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f, + 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34, + 0x28,0x76,0x65,0x63,0x34,0x28,0x5f,0x35,0x38,0x34,0x2c,0x20,0x5f,0x35,0x35,0x34, + 0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79, + 0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78, + 0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f, + 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34, + 0x28,0x76,0x65,0x63,0x34,0x28,0x5f,0x35,0x35,0x30,0x2c,0x20,0x6c,0x69,0x67,0x68, + 0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35, + 0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x29, + 0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x6c,0x69,0x67,0x68, + 0x74,0x5f,0x75,0x76,0x2e,0x78,0x79,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f, + 0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29, + 0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x5f,0x35,0x38, + 0x34,0x2c,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x5f, + 0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20, + 0x5f,0x35,0x33,0x34,0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72, + 0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65, + 0x63,0x34,0x28,0x5f,0x35,0x35,0x30,0x2c,0x20,0x5f,0x36,0x35,0x32,0x2c,0x20,0x5f, + 0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20, + 0x5f,0x35,0x33,0x34,0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72, + 0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65, + 0x63,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20,0x5f, + 0x36,0x35,0x32,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29, + 0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x29,0x20,0x2b,0x20, + 0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76, + 0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x5f,0x35,0x38,0x34,0x2c,0x20,0x5f, + 0x36,0x35,0x32,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29, + 0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x29,0x20,0x2a,0x20, + 0x30,0x2e,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x39,0x33,0x38,0x39,0x35, + 0x33,0x33,0x39,0x39,0x36,0x35,0x38,0x32,0x30,0x33,0x31,0x32,0x35,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61, + 0x73,0x63,0x61,0x64,0x65,0x28,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f, + 0x73,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f, + 0x72,0x6d,0x61,0x6c,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34, + 0x20,0x5f,0x37,0x31,0x37,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x5d,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x37,0x32,0x34,0x20,0x3d,0x20,0x5f, + 0x37,0x31,0x37,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x76,0x65,0x63,0x33,0x28,0x5f, + 0x37,0x31,0x37,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, + 0x20,0x5f,0x37,0x34,0x32,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x28,0x5f,0x37, + 0x32,0x34,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e, + 0x35,0x2c,0x20,0x28,0x28,0x5f,0x37,0x32,0x34,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x37, + 0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20, + 0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x37,0x32,0x34,0x2e,0x7a,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x37,0x34,0x36,0x20,0x3d,0x20, + 0x61,0x6e,0x79,0x28,0x6c,0x65,0x73,0x73,0x54,0x68,0x61,0x6e,0x28,0x5f,0x37,0x34, + 0x32,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x37,0x35,0x33,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x37,0x34,0x36,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x37,0x35,0x33, + 0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x67,0x72,0x65,0x61,0x74,0x65,0x72,0x54,0x68, + 0x61,0x6e,0x28,0x5f,0x37,0x34,0x32,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e, + 0x30,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x5f,0x37,0x35,0x33,0x20,0x3d,0x20,0x5f,0x37,0x34,0x36,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37, + 0x35,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20, + 0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x30,0x2e, + 0x30,0x30,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x38,0x39,0x39,0x38,0x39,0x38, + 0x30,0x35,0x32,0x32,0x31,0x35,0x35,0x37,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x2c, + 0x20,0x30,0x2e,0x30,0x30,0x30,0x37,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x39,0x37, + 0x39,0x30,0x33,0x30,0x30,0x31,0x33,0x30,0x38,0x34,0x34,0x31,0x31,0x36,0x32,0x31, + 0x30,0x39,0x33,0x37,0x35,0x2c,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x77, + 0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x6e,0x6f,0x72, + 0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37,0x30,0x37,0x2e,0x73,0x75,0x6e,0x5f, + 0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x29,0x29,0x2c, + 0x20,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68, + 0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x37,0x38,0x35,0x20, + 0x3d,0x20,0x5f,0x37,0x34,0x32,0x2e,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x37,0x39,0x30,0x20,0x3d,0x20,0x6d, + 0x69,0x6e,0x28,0x5f,0x37,0x38,0x35,0x2c,0x20,0x76,0x65,0x63,0x32,0x28,0x31,0x2e, + 0x30,0x29,0x20,0x2d,0x20,0x5f,0x37,0x38,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x31,0x2e, + 0x30,0x2c,0x20,0x70,0x63,0x66,0x2c,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6d,0x69, + 0x6e,0x28,0x5f,0x37,0x39,0x30,0x2e,0x78,0x2c,0x20,0x5f,0x37,0x39,0x30,0x2e,0x79, + 0x29,0x20,0x2a,0x20,0x31,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31, + 0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x70,0x63,0x66,0x3b,0x0a,0x7d,0x0a,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f, + 0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x76,0x65,0x63,0x33,0x20,0x77, + 0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x77, + 0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x76,0x69,0x65,0x77,0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x32, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a, + 0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, + 0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a, + 0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, + 0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x31,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d, + 0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x77,0x6f,0x72, + 0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64, + 0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x20,0x3c,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x33, + 0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x5f,0x38,0x33,0x35,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x5f,0x38,0x33,0x35,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a, + 0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x34,0x37, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x5f,0x38,0x34,0x37,0x20,0x3d,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x34,0x37,0x20, + 0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66, + 0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x35,0x38,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28, + 0x5f,0x38,0x33,0x35,0x2c,0x20,0x5f,0x38,0x34,0x37,0x2c,0x20,0x30,0x2e,0x31,0x30, + 0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x34,0x39,0x30,0x31,0x31,0x36,0x31,0x31,0x39, + 0x33,0x38,0x34,0x37,0x36,0x35,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3e, + 0x20,0x5f,0x38,0x35,0x38,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x20,0x2b,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, + 0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e, + 0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61, + 0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x29, + 0x2c,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x2d,0x20,0x5f,0x38,0x35,0x38, + 0x29,0x20,0x2f,0x20,0x28,0x5f,0x38,0x33,0x35,0x20,0x2d,0x20,0x5f,0x38,0x35,0x38, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47, + 0x47,0x58,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x37,0x20, + 0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x36,0x20, + 0x3d,0x20,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x20,0x2a,0x20,0x6e,0x5f, + 0x64,0x6f,0x74,0x5f,0x68,0x29,0x20,0x2a,0x20,0x28,0x5f,0x31,0x30,0x37,0x20,0x2d, + 0x20,0x31,0x2e,0x30,0x29,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x30,0x37,0x20,0x2f,0x20, + 0x28,0x28,0x33,0x2e,0x31,0x34,0x31,0x35,0x39,0x32,0x37,0x34,0x31,0x30,0x31,0x32, + 0x35,0x37,0x33,0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x20,0x2a,0x20,0x5f,0x31,0x31, + 0x36,0x29,0x20,0x2a,0x20,0x5f,0x31,0x31,0x36,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69, + 0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65, + 0x64,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x39,0x20,0x3d,0x20, + 0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x36,0x20,0x3d,0x20, + 0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f,0x31,0x32,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x30,0x2e,0x35,0x20,0x2f,0x20,0x28,0x28,0x28, + 0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28, + 0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74, + 0x5f,0x76,0x29,0x20,0x2a,0x20,0x5f,0x31,0x33,0x36,0x29,0x20,0x2b,0x20,0x5f,0x31, + 0x32,0x39,0x29,0x29,0x20,0x2b,0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20, + 0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c, + 0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x29,0x20,0x2a,0x20,0x5f,0x31, + 0x33,0x36,0x29,0x20,0x2b,0x20,0x5f,0x31,0x32,0x39,0x29,0x29,0x29,0x20,0x2b,0x20, + 0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35, + 0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38, + 0x38,0x65,0x2d,0x30,0x36,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20, + 0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63, + 0x6b,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c, + 0x20,0x76,0x65,0x63,0x33,0x20,0x66,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x35,0x20,0x3d,0x20,0x31,0x2e,0x30, + 0x20,0x2d,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x39,0x20,0x3d,0x20,0x5f,0x31,0x36, + 0x35,0x20,0x2a,0x20,0x5f,0x31,0x36,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x66,0x30,0x20,0x2b,0x20,0x28,0x28,0x76,0x65,0x63,0x33, + 0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x66,0x30,0x29,0x20,0x2a,0x20,0x28,0x28, + 0x5f,0x31,0x36,0x39,0x20,0x2a,0x20,0x5f,0x31,0x36,0x39,0x29,0x20,0x2a,0x20,0x5f, + 0x31,0x36,0x35,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x62, + 0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x76,0x65,0x63, + 0x33,0x20,0x4e,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x56,0x2c,0x20,0x76,0x65,0x63, + 0x33,0x20,0x4c,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61, + 0x64,0x69,0x61,0x6e,0x63,0x65,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x62,0x61,0x73, + 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d, + 0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72, + 0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x38,0x38,0x20,0x3d,0x20,0x6d,0x61,0x78, + 0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x4c,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x39,0x39,0x20, + 0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x56,0x20,0x2b,0x20, + 0x4c,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32, + 0x31,0x33,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65, + 0x73,0x73,0x2c,0x20,0x30,0x2e,0x30,0x34,0x35,0x30,0x30,0x30,0x30,0x30,0x31,0x37, + 0x38,0x38,0x31,0x33,0x39,0x33,0x34,0x33,0x32,0x36,0x31,0x37,0x31,0x38,0x37,0x35, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31, + 0x37,0x20,0x3d,0x20,0x5f,0x32,0x31,0x33,0x20,0x2a,0x20,0x5f,0x32,0x31,0x33,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x5f,0x31, + 0x39,0x39,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f, + 0x32,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74, + 0x28,0x4e,0x2c,0x20,0x56,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39, + 0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34, + 0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x20,0x3d,0x20,0x5f,0x31,0x38,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x32, + 0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28, + 0x56,0x2c,0x20,0x5f,0x31,0x39,0x39,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36, + 0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x33, + 0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38, + 0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c,0x20,0x62,0x61,0x73,0x65, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x6d,0x65,0x74, + 0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x33,0x20,0x5f,0x32,0x34,0x34,0x20,0x3d,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73, + 0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x76, + 0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x32,0x34,0x34,0x29, + 0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c, + 0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x33,0x31,0x38,0x33, + 0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38, + 0x35,0x39,0x33,0x37,0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x5f,0x32,0x34,0x34,0x20, + 0x2a,0x20,0x28,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69, + 0x6f,0x6e,0x47,0x47,0x58,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x29,0x20,0x2a,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62, + 0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c, + 0x61,0x74,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29,0x29, + 0x29,0x29,0x20,0x2a,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63, + 0x65,0x29,0x20,0x2a,0x20,0x5f,0x31,0x38,0x38,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65, + 0x63,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68, + 0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x76,0x65,0x63,0x33,0x20, + 0x4e,0x2c,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x33,0x39,0x39,0x20,0x3d, + 0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x73,0x68,0x5b,0x30,0x5d,0x2e,0x78, + 0x79,0x7a,0x20,0x2a,0x20,0x30,0x2e,0x32,0x38,0x32,0x30,0x39,0x34,0x38,0x30,0x36, + 0x34,0x33,0x32,0x37,0x32,0x33,0x39,0x39,0x39,0x30,0x32,0x33,0x34,0x33,0x37,0x35, + 0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a, + 0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30, + 0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a, + 0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x32,0x5d, + 0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32, + 0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37, + 0x35,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68, + 0x5b,0x33,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34, + 0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35, + 0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x29,0x29, + 0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x34,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, + 0x28,0x28,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30, + 0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x20,0x2a,0x20,0x4e,0x2e, + 0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73, + 0x68,0x5b,0x35,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31, + 0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37, + 0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29, + 0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b, + 0x36,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x33,0x31,0x35,0x33, + 0x39,0x31,0x35,0x37,0x30,0x33,0x32,0x39,0x36,0x36,0x36,0x31,0x33,0x37,0x36,0x39, + 0x35,0x33,0x31,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x28,0x33,0x2e,0x30,0x20,0x2a, + 0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2d,0x20,0x31, + 0x2e,0x30,0x29,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x37,0x5d,0x2e, + 0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35, + 0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38, + 0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e, + 0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x38,0x5d,0x2e,0x78,0x79, + 0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x35,0x34,0x36,0x32,0x37,0x34,0x32,0x34,0x34, + 0x37,0x38,0x35,0x33,0x30,0x38,0x38,0x33,0x37,0x38,0x39,0x30,0x36,0x32,0x35,0x20, + 0x2a,0x20,0x28,0x28,0x4e,0x2e,0x78,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2d, + 0x20,0x28,0x4e,0x2e,0x79,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x33,0x39,0x39, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61, + 0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x76,0x65,0x63,0x33,0x20,0x4e,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x56,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61, + 0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67, + 0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39, + 0x5d,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64, + 0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x75,0x62,0x65,0x20,0x53,0x50, + 0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e, + 0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x73, + 0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x61, + 0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, + 0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f, + 0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66, + 0x5f,0x6c,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x34,0x30,0x36,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x64, + 0x6f,0x74,0x28,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x56,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34, + 0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32, + 0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x34,0x31,0x36, + 0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x33, + 0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38, + 0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c,0x20,0x62,0x61,0x73,0x65, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x6d,0x65,0x74, + 0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x5b,0x39,0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x34,0x38,0x32,0x20,0x3d,0x20,0x74,0x65,0x78, + 0x74,0x75,0x72,0x65,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73, + 0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x62,0x72,0x64, + 0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75, + 0x74,0x2c,0x20,0x76,0x65,0x63,0x32,0x28,0x5f,0x34,0x30,0x36,0x2c,0x20,0x72,0x6f, + 0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x76,0x65,0x63,0x33,0x28, + 0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x28,0x5f,0x34,0x31,0x36,0x20,0x2b,0x20,0x28, + 0x28,0x6d,0x61,0x78,0x28,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20, + 0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x2c,0x20,0x5f,0x34,0x31,0x36, + 0x29,0x20,0x2d,0x20,0x5f,0x34,0x31,0x36,0x29,0x20,0x2a,0x20,0x70,0x6f,0x77,0x28, + 0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f, + 0x34,0x30,0x36,0x29,0x2c,0x20,0x35,0x2e,0x30,0x29,0x29,0x29,0x29,0x20,0x2a,0x20, + 0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29, + 0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20, + 0x2a,0x20,0x6d,0x61,0x78,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74, + 0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x70,0x61, + 0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x2c,0x20,0x76, + 0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x29,0x20,0x2a,0x20,0x76,0x65,0x63, + 0x33,0x28,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32, + 0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x29,0x29,0x20, + 0x2b,0x20,0x28,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x4c,0x6f,0x64,0x28,0x53,0x50, + 0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e, + 0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x73, + 0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x72,0x65, + 0x66,0x6c,0x65,0x63,0x74,0x28,0x2d,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20, + 0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e, + 0x65,0x73,0x73,0x20,0x2a,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x2e,0x78, + 0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x34,0x31,0x36,0x20,0x2a,0x20,0x5f,0x34, + 0x38,0x32,0x2e,0x78,0x29,0x20,0x2b,0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x34,0x38, + 0x32,0x2e,0x79,0x29,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20, + 0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65, + 0x6e,0x74,0x28,0x62,0x6f,0x6f,0x6c,0x20,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c, + 0x65,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20, + 0x76,0x65,0x63,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72, + 0x65,0x6e,0x67,0x74,0x68,0x2c,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39, + 0x5d,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64, + 0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x75,0x62,0x65,0x20,0x53,0x50, + 0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e, + 0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x73, + 0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x61, + 0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, + 0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f, + 0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66, + 0x5f,0x6c,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, + 0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65, + 0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x62, + 0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x20,0x3d,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69, + 0x63,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x72,0x6f,0x75,0x67,0x68, + 0x6e,0x65,0x73,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x5b,0x39,0x5d,0x20,0x3d,0x20, + 0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x61,0x78,0x5f, + 0x6c,0x6f,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x73, + 0x75,0x6c,0x74,0x20,0x3d,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74, + 0x65,0x49,0x62,0x6c,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36, + 0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f, + 0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63, + 0x75,0x62,0x65,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65, + 0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f, + 0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, + 0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69, + 0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x33,0x20,0x5f,0x38,0x39,0x36,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x69,0x7a,0x65,0x28,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, + 0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61, + 0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x39,0x30,0x31,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78, + 0x79,0x7a,0x20,0x2d,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x30,0x35,0x20,0x3d,0x20, + 0x64,0x6f,0x74,0x28,0x5f,0x39,0x30,0x31,0x2c,0x20,0x5f,0x38,0x39,0x36,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x31,0x34,0x20, + 0x3d,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x2a,0x20,0x76,0x5f,0x72, + 0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x39,0x32,0x31,0x20,0x3d,0x20,0x28,0x5f,0x39,0x30,0x35,0x20,0x2a,0x20, + 0x5f,0x39,0x30,0x35,0x29,0x20,0x2d,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x39,0x30, + 0x31,0x2c,0x20,0x5f,0x39,0x30,0x31,0x29,0x20,0x2d,0x20,0x5f,0x39,0x31,0x34,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x33,0x31, + 0x20,0x3d,0x20,0x73,0x71,0x72,0x74,0x28,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x2c, + 0x20,0x5f,0x39,0x31,0x34,0x20,0x2d,0x20,0x5f,0x39,0x32,0x31,0x29,0x29,0x20,0x2d, + 0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x33,0x34,0x20,0x3d,0x20,0x66,0x77,0x69,0x64, + 0x74,0x68,0x28,0x5f,0x39,0x33,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x39,0x33,0x36,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x5f, + 0x39,0x33,0x34,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34, + 0x37,0x35,0x32,0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38,0x33,0x35,0x31,0x32,0x31, + 0x31,0x35,0x34,0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x34,0x33,0x20,0x3d,0x20,0x31,0x2e, + 0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x2d, + 0x5f,0x39,0x33,0x36,0x2c,0x20,0x5f,0x39,0x33,0x36,0x2c,0x20,0x5f,0x39,0x33,0x31, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x34, + 0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x39,0x32,0x31,0x20, + 0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x39,0x34,0x37,0x20,0x3d,0x20,0x28,0x2d,0x5f, + 0x39,0x30,0x35,0x29,0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x39,0x32,0x31, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, + 0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x5f,0x39,0x34,0x37,0x20,0x3d,0x20,0x2d,0x5f,0x39,0x30,0x35,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x5f,0x39,0x34, + 0x33,0x20,0x3c,0x3d,0x20,0x30,0x2e,0x30,0x29,0x20,0x7c,0x7c,0x20,0x28,0x5f,0x39, + 0x34,0x37,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, + 0x20,0x5f,0x39,0x37,0x32,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x6d, + 0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f, + 0x38,0x39,0x36,0x20,0x2a,0x20,0x5f,0x39,0x34,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x39,0x37,0x37,0x20,0x3d,0x20,0x6e,0x6f,0x72, + 0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x39,0x37,0x32,0x20,0x2d,0x20,0x76,0x5f, + 0x63,0x65,0x6e,0x74,0x65,0x72,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x39,0x38,0x33,0x20,0x3d,0x20,0x5f,0x39,0x37,0x37,0x2e,0x78, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x38,0x39, + 0x20,0x3d,0x20,0x5f,0x39,0x37,0x37,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x39,0x36,0x20,0x3d,0x20,0x5f,0x39,0x37,0x37, + 0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39, + 0x39,0x38,0x20,0x3d,0x20,0x28,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77, + 0x30,0x2e,0x78,0x20,0x2a,0x20,0x5f,0x39,0x38,0x33,0x29,0x20,0x2b,0x20,0x28,0x76, + 0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x20,0x2a,0x20,0x5f,0x39, + 0x38,0x39,0x29,0x29,0x20,0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f, + 0x77,0x32,0x2e,0x78,0x20,0x2a,0x20,0x5f,0x39,0x39,0x36,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x31,0x35,0x20,0x3d,0x20, + 0x28,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x79,0x20,0x2a, + 0x20,0x5f,0x39,0x38,0x33,0x29,0x20,0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f, + 0x72,0x6f,0x77,0x31,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x39,0x38,0x39,0x29,0x29,0x20, + 0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x79,0x20, + 0x2a,0x20,0x5f,0x39,0x39,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x30,0x33,0x32,0x20,0x3d,0x20,0x28,0x28,0x76,0x5f,0x72, + 0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x7a,0x20,0x2a,0x20,0x5f,0x39,0x38,0x33, + 0x29,0x20,0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x2e, + 0x7a,0x20,0x2a,0x20,0x5f,0x39,0x38,0x39,0x29,0x29,0x20,0x2b,0x20,0x28,0x76,0x5f, + 0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x7a,0x20,0x2a,0x20,0x5f,0x39,0x39, + 0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x30, + 0x38,0x33,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x31,0x30,0x31,0x35,0x20, + 0x3e,0x20,0x30,0x2e,0x30,0x29,0x20,0x3f,0x20,0x31,0x2e,0x30,0x20,0x3a,0x20,0x30, + 0x2e,0x36,0x34,0x39,0x39,0x39,0x39,0x39,0x37,0x36,0x31,0x35,0x38,0x31,0x34,0x32, + 0x30,0x38,0x39,0x38,0x34,0x33,0x37,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x33,0x20,0x5f,0x31,0x30,0x39,0x33,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28, + 0x5f,0x31,0x30,0x38,0x33,0x2c,0x20,0x5f,0x31,0x30,0x38,0x33,0x20,0x2a,0x20,0x30, + 0x2e,0x33,0x34,0x39,0x39,0x39,0x39,0x39,0x39,0x34,0x30,0x33,0x39,0x35,0x33,0x35, + 0x35,0x32,0x32,0x34,0x36,0x30,0x39,0x33,0x37,0x35,0x2c,0x20,0x76,0x65,0x63,0x33, + 0x28,0x6d,0x61,0x78,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74, + 0x68,0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30,0x2c,0x20,0x66,0x77,0x69,0x64,0x74, + 0x68,0x28,0x5f,0x39,0x39,0x38,0x29,0x20,0x2a,0x20,0x31,0x2e,0x35,0x2c,0x20,0x61, + 0x62,0x73,0x28,0x5f,0x39,0x39,0x38,0x29,0x29,0x2c,0x20,0x6d,0x61,0x78,0x28,0x31, + 0x2e,0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28, + 0x30,0x2e,0x30,0x2c,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31,0x30,0x31, + 0x35,0x29,0x20,0x2a,0x20,0x31,0x2e,0x35,0x2c,0x20,0x61,0x62,0x73,0x28,0x5f,0x31, + 0x30,0x31,0x35,0x29,0x29,0x2c,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f, + 0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30,0x2c,0x20,0x66,0x77,0x69, + 0x64,0x74,0x68,0x28,0x5f,0x31,0x30,0x33,0x32,0x29,0x20,0x2a,0x20,0x31,0x2e,0x35, + 0x2c,0x20,0x61,0x62,0x73,0x28,0x5f,0x31,0x30,0x33,0x32,0x29,0x29,0x29,0x29,0x29, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x31,0x31,0x30, + 0x31,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x39,0x37,0x32,0x2c,0x20,0x31, + 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x31, + 0x31,0x30,0x32,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x76,0x69,0x65,0x77,0x5f, + 0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20,0x5f,0x31,0x31,0x30,0x31,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d, + 0x20,0x5f,0x31,0x31,0x30,0x32,0x2e,0x7a,0x20,0x2f,0x20,0x5f,0x31,0x31,0x30,0x32, + 0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x37, + 0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x31,0x33,0x34,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70, + 0x28,0x28,0x5f,0x37,0x30,0x37,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x5f,0x31, + 0x31,0x30,0x31,0x29,0x2e,0x7a,0x20,0x2a,0x20,0x28,0x2d,0x30,0x2e,0x30,0x31,0x39, + 0x39,0x39,0x39,0x39,0x39,0x39,0x35,0x35,0x32,0x39,0x36,0x35,0x31,0x36,0x34,0x31, + 0x38,0x34,0x35,0x37,0x30,0x33,0x31,0x32,0x35,0x29,0x2c,0x20,0x30,0x2e,0x30,0x2c, + 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f, + 0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28, + 0x5f,0x31,0x31,0x33,0x34,0x2c,0x20,0x5f,0x31,0x31,0x33,0x34,0x2c,0x20,0x5f,0x31, + 0x31,0x33,0x34,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x37,0x2e,0x66,0x6c, + 0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x31,0x35,0x35,0x20,0x3d,0x20,0x2d,0x28,0x5f,0x37,0x30,0x37,0x2e,0x76, + 0x69,0x65,0x77,0x20,0x2a,0x20,0x5f,0x31,0x31,0x30,0x31,0x29,0x2e,0x7a,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x35,0x35,0x20,0x3c,0x20,0x5f,0x37,0x30, + 0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, + 0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x35, + 0x35,0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f, + 0x31,0x31,0x37,0x39,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x5d,0x20,0x2a,0x20,0x5f,0x31,0x31,0x30,0x31,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x31,0x38, + 0x36,0x20,0x3d,0x20,0x5f,0x31,0x31,0x37,0x39,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20, + 0x76,0x65,0x63,0x33,0x28,0x5f,0x31,0x31,0x37,0x39,0x2e,0x77,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x32,0x30, + 0x33,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x28,0x5f,0x31,0x31,0x38,0x36,0x2e, + 0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20, + 0x28,0x28,0x5f,0x31,0x31,0x38,0x36,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x37,0x30,0x37, + 0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65, + 0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20, + 0x30,0x2e,0x35,0x2c,0x20,0x5f,0x31,0x31,0x38,0x36,0x2e,0x7a,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x32,0x30, + 0x37,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x6c,0x65,0x73,0x73,0x54,0x68,0x61,0x6e, + 0x28,0x5f,0x31,0x32,0x30,0x33,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30, + 0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f, + 0x6c,0x20,0x5f,0x31,0x32,0x31,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x32,0x30,0x37,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x5f,0x31,0x32,0x31,0x34,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x67, + 0x72,0x65,0x61,0x74,0x65,0x72,0x54,0x68,0x61,0x6e,0x28,0x5f,0x31,0x32,0x30,0x33, + 0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x32,0x31, + 0x34,0x20,0x3d,0x20,0x5f,0x31,0x32,0x30,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x33,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x21,0x5f,0x31,0x32,0x31,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69, + 0x6e,0x74,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x2c,0x20,0x30, + 0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34, + 0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x34,0x30, + 0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37, + 0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74, + 0x69,0x6e,0x74,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x34,0x30,0x30, + 0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35, + 0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x34, + 0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37, + 0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, + 0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x76, + 0x65,0x63,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39, + 0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c, + 0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34, + 0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20, + 0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x74,0x69,0x6e,0x74,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x5f,0x37,0x30,0x37,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d, + 0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65, + 0x63,0x34,0x28,0x28,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x28,0x5f, + 0x37,0x30,0x37,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28, + 0x5f,0x39,0x38,0x33,0x2c,0x20,0x5f,0x39,0x38,0x39,0x2c,0x20,0x5f,0x39,0x39,0x36, + 0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,0x2e,0x78,0x79,0x7a,0x29,0x20,0x2a,0x20,0x30, + 0x2e,0x35,0x29,0x20,0x2b,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x35,0x29,0x2c, + 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x31,0x32,0x38,0x34,0x20,0x3d,0x20,0x74,0x65, + 0x78,0x74,0x75,0x72,0x65,0x4c,0x6f,0x64,0x28,0x74,0x65,0x78,0x5f,0x61,0x6f,0x5f, + 0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43, + 0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x20,0x2f,0x20,0x76,0x65,0x63,0x32,0x28,0x74, + 0x65,0x78,0x74,0x75,0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x74,0x65,0x78,0x5f,0x61, + 0x6f,0x5f,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20,0x30,0x29,0x29,0x2c,0x20,0x30, + 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x32,0x38,0x35,0x20,0x3d,0x20,0x5f,0x31,0x32,0x38,0x34,0x2e,0x78,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x37,0x2e,0x66,0x6c,0x61, + 0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x31,0x32,0x38,0x35,0x2c, + 0x20,0x5f,0x31,0x32,0x38,0x35,0x2c,0x20,0x5f,0x31,0x32,0x38,0x35,0x2c,0x20,0x31, + 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f,0x39,0x37,0x32, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x20,0x3d,0x20,0x5f,0x39,0x37,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x2d, + 0x28,0x5f,0x37,0x30,0x37,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x5f,0x31,0x31, + 0x30,0x31,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, + 0x5f,0x31,0x33,0x33,0x33,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a, + 0x65,0x28,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f, + 0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x39,0x37,0x32,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20, + 0x3d,0x20,0x5f,0x39,0x37,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x31,0x33,0x33,0x33, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x35,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f, + 0x37,0x30,0x37,0x2e,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e, + 0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63, + 0x61,0x64,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20, + 0x3d,0x20,0x5f,0x31,0x30,0x39,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x76,0x5f,0x6d, + 0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x76, + 0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x62,0x6f,0x6f,0x6c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73, + 0x2e,0x79,0x20,0x3e,0x20,0x30,0x2e,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x5f,0x39, + 0x37,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x5f,0x31,0x33,0x33,0x33,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33, + 0x20,0x3d,0x20,0x5f,0x31,0x30,0x39,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x76, + 0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20, + 0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x36,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x75,0x6e,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x39,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x30,0x5d,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x31,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30, + 0x37,0x2e,0x73,0x68,0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x37,0x5b,0x32,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e, + 0x73,0x68,0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x37,0x5b,0x33,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68, + 0x5b,0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x37,0x5b,0x34,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x34, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b, + 0x35,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x35,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x36,0x5d, + 0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x36,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x37,0x5d,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x37,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x38,0x5d,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x38,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20, + 0x5f,0x37,0x30,0x37,0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e, + 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34, + 0x31,0x32,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x2e,0x77,0x20,0x2a,0x20,0x5f,0x39,0x34,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34, + 0x28,0x28,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x29,0x20,0x2b, + 0x20,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62, + 0x69,0x65,0x6e,0x74,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x2c,0x20,0x74, + 0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x5f,0x73,0x6d,0x70,0x5f, + 0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72, + 0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f, + 0x6c,0x75,0x74,0x29,0x20,0x2a,0x20,0x5f,0x31,0x32,0x38,0x35,0x29,0x29,0x20,0x2a, + 0x20,0x5f,0x31,0x34,0x31,0x32,0x2c,0x20,0x5f,0x31,0x34,0x31,0x32,0x29,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x00, +}; +/* + struct instance + { + float4 xform_row0; + float4 xform_row1; + float4 xform_row2; + float4 base_color; + float4 params; + float4 material; + }; + + ByteAddressBuffer _15 : register(t0); + cbuffer ub_draw : register(b2) + { + int4 _21_inst_base : packoffset(c0); + }; + + cbuffer ub_frame : register(b0) + { + row_major float4x4 _112_view_proj : packoffset(c0); + }; + + + static float4 gl_Position; + static int gl_InstanceIndex; + static float3 in_pos; + static float3 v_world_pos_proxy; + static float3 v_center; + static float v_radius; + static float3 v_rot_row0; + static float3 v_rot_row1; + static float3 v_rot_row2; + static float4 v_base_color; + static float4 v_material; + + struct SPIRV_Cross_Input + { + float3 in_pos : TEXCOORD0; + uint gl_InstanceIndex : SV_InstanceID; + }; + + struct SPIRV_Cross_Output + { + float3 v_world_pos_proxy : TEXCOORD0; + nointerpolation float3 v_center : TEXCOORD1; + nointerpolation float v_radius : TEXCOORD2; + nointerpolation float3 v_rot_row0 : TEXCOORD3; + nointerpolation float3 v_rot_row1 : TEXCOORD4; + nointerpolation float3 v_rot_row2 : TEXCOORD5; + nointerpolation float4 v_base_color : TEXCOORD6; + nointerpolation float4 v_material : TEXCOORD7; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + instance _33; + _33.xform_row0 = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 0)); + _33.xform_row1 = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 16)); + _33.xform_row2 = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 32)); + _33.base_color = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 48)); + _33.params = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 64)); + _33.material = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 80)); + float3 _63 = float3(_33.xform_row0.w, _33.xform_row1.w, _33.xform_row2.w); + float3 _76 = _63 + (in_pos * (2.0f * _33.params.x)); + v_world_pos_proxy = _76; + v_center = _63; + v_radius = _33.params.x; + v_rot_row0 = _33.xform_row0.xyz; + v_rot_row1 = _33.xform_row1.xyz; + v_rot_row2 = _33.xform_row2.xyz; + v_base_color = _33.base_color; + v_material = _33.material; + gl_Position = mul(float4(_76, 1.0f), _112_view_proj); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_InstanceIndex = int(stage_input.gl_InstanceIndex); + in_pos = stage_input.in_pos; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.v_world_pos_proxy = v_world_pos_proxy; + stage_output.v_center = v_center; + stage_output.v_radius = v_radius; + stage_output.v_rot_row0 = v_rot_row0; + stage_output.v_rot_row1 = v_rot_row1; + stage_output.v_rot_row2 = v_rot_row2; + stage_output.v_base_color = v_base_color; + stage_output.v_material = v_material; + return stage_output; + } +*/ +static const uint8_t sphere_vs_source_hlsl5[2863] = { + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d, + 0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x73,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6d,0x61,0x74,0x65, + 0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x42,0x79,0x74,0x65,0x41,0x64, + 0x64,0x72,0x65,0x73,0x73,0x42,0x75,0x66,0x66,0x65,0x72,0x20,0x5f,0x31,0x35,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x30,0x29,0x3b,0x0a, + 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x32,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x34,0x20,0x5f,0x32,0x31,0x5f,0x69,0x6e, + 0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66, + 0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x63,0x62, + 0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x20,0x3a, + 0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x31,0x31,0x32,0x5f,0x76,0x69,0x65,0x77, + 0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73, + 0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x0a,0x73,0x74,0x61, + 0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69, + 0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e, + 0x64,0x65,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69, + 0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x73,0x74,0x61,0x74, + 0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74, + 0x65,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69, + 0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72, + 0x6f,0x77,0x30,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x73, + 0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72, + 0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x0a, + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, + 0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20,0x54, + 0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69, + 0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e, + 0x64,0x65,0x78,0x20,0x3a,0x20,0x53,0x56,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x49,0x44,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20, + 0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70, + 0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78, + 0x79,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69, + 0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74, + 0x65,0x72,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74, + 0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69, + 0x75,0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x32,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74, + 0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74, + 0x5f,0x72,0x6f,0x77,0x30,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44, + 0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f, + 0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f, + 0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f, + 0x4f,0x52,0x44,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65, + 0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x20,0x3a,0x20,0x54,0x45, + 0x58,0x43,0x4f,0x4f,0x52,0x44,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69, + 0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x36,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f, + 0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72, + 0x69,0x61,0x6c,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x37,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50, + 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,0x53,0x56,0x5f,0x50,0x6f,0x73, + 0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20, + 0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20,0x5f,0x33,0x33,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f, + 0x77,0x30,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35, + 0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74, + 0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73, + 0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36, + 0x20,0x2b,0x20,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e, + 0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x20,0x3d,0x20,0x61,0x73,0x66, + 0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28, + 0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20, + 0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64, + 0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x31,0x36,0x29,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72, + 0x6f,0x77,0x32,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31, + 0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73, + 0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e, + 0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39, + 0x36,0x20,0x2b,0x20,0x33,0x32,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33, + 0x33,0x2e,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x61, + 0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34, + 0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e, + 0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49, + 0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x34,0x38,0x29, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d, + 0x73,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e, + 0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f, + 0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20, + 0x2b,0x20,0x36,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e, + 0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f, + 0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32, + 0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20, + 0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78, + 0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x38,0x30,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x36,0x33,0x20,0x3d,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d, + 0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f,0x33,0x33,0x2e,0x78, + 0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x37,0x36,0x20,0x3d,0x20,0x5f, + 0x36,0x33,0x20,0x2b,0x20,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x2a,0x20,0x28, + 0x32,0x2e,0x30,0x66,0x20,0x2a,0x20,0x5f,0x33,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d, + 0x73,0x2e,0x78,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x5f, + 0x37,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72, + 0x20,0x3d,0x20,0x5f,0x36,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x61, + 0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x5f,0x33,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d, + 0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72, + 0x6f,0x77,0x30,0x20,0x3d,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f, + 0x72,0x6f,0x77,0x30,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f, + 0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x20,0x3d,0x20,0x5f,0x33,0x33,0x2e,0x78, + 0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x20,0x3d,0x20, + 0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x78, + 0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x5f,0x33,0x33,0x2e,0x62,0x61,0x73,0x65,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x6d,0x61,0x74, + 0x65,0x72,0x69,0x61,0x6c,0x20,0x3d,0x20,0x5f,0x33,0x33,0x2e,0x6d,0x61,0x74,0x65, + 0x72,0x69,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73, + 0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x28,0x5f,0x37,0x36,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f, + 0x31,0x31,0x32,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x29,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f, + 0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56, + 0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78, + 0x20,0x3d,0x20,0x69,0x6e,0x74,0x28,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70, + 0x75,0x74,0x2e,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e, + 0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73, + 0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x69, + 0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x72,0x74,0x5f, + 0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52, + 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73, + 0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c, + 0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x50, + 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x76,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75, + 0x74,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3d,0x20,0x76,0x5f,0x63, + 0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65, + 0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73, + 0x20,0x3d,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f, + 0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x20,0x3d,0x20,0x76,0x5f,0x72,0x6f,0x74, + 0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65, + 0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f, + 0x77,0x31,0x20,0x3d,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75, + 0x74,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x20,0x3d,0x20,0x76, + 0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73, + 0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x62,0x61, + 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73, + 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65, + 0x72,0x69,0x61,0x6c,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61, + 0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74, + 0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + cbuffer ub_pass : register(b1) + { + float4 _707_sun_dir_world : packoffset(c0); + float4 _707_sun_color : packoffset(c1); + int4 _707_flags : packoffset(c2); + float4 _707_camera_pos : packoffset(c3); + row_major float4x4 _707_view_proj : packoffset(c4); + row_major float4x4 _707_view : packoffset(c8); + float4 _707_cascade_far_view_z : packoffset(c12); + row_major float4x4 _707_cascade_matrices[3] : packoffset(c13); + float4 _707_sh[9] : packoffset(c25); + float4 _707_ibl_params : packoffset(c34); + }; + + Texture2DArray tex_shadow : register(t0); + SamplerComparisonState smp_shadow : register(s0); + Texture2D tex_ao : register(t3); + SamplerState smp_ao : register(s3); + TextureCube tex_ibl_spec : register(t1); + SamplerState smp_ibl_spec : register(s1); + Texture2D tex_brdf_lut : register(t2); + SamplerState smp_brdf_lut : register(s2); + + static float4 gl_FragCoord; + static float gl_FragDepth; + static float3 v_world_pos_proxy; + static float3 v_center; + static float v_radius; + static float3 v_rot_row0; + static float3 v_rot_row1; + static float3 v_rot_row2; + static float4 v_base_color; + static float4 out_color; + static float4 v_material; + + struct SPIRV_Cross_Input + { + float3 v_world_pos_proxy : TEXCOORD0; + nointerpolation float3 v_center : TEXCOORD1; + nointerpolation float v_radius : TEXCOORD2; + nointerpolation float3 v_rot_row0 : TEXCOORD3; + nointerpolation float3 v_rot_row1 : TEXCOORD4; + nointerpolation float3 v_rot_row2 : TEXCOORD5; + nointerpolation float4 v_base_color : TEXCOORD6; + nointerpolation float4 v_material : TEXCOORD7; + float4 gl_FragCoord : SV_Position; + }; + + struct SPIRV_Cross_Output + { + float4 out_color : SV_Target0; + float gl_FragDepth : SV_Depth; + }; + + uint2 spvTextureSize(Texture2D Tex, uint Level, out uint Param) + { + uint2 ret; + Tex.GetDimensions(Level, ret.x, ret.y, Param); + return ret; + } + + float sampleShadowPCF(int cascade, float3 light_uv, float bias) + { + float _529 = float(cascade); + float _534 = light_uv.z - bias; + float _550 = light_uv.x - 0.00048828125f; + float _554 = light_uv.y - 0.00048828125f; + float _584 = light_uv.x + 0.00048828125f; + float _652 = light_uv.y + 0.00048828125f; + return ((((((((tex_shadow.SampleCmp(smp_shadow, float4(_550, _554, _529, _534).xyz, _534) + tex_shadow.SampleCmp(smp_shadow, float4(light_uv.x, _554, _529, _534).xyz, _534)) + tex_shadow.SampleCmp(smp_shadow, float4(_584, _554, _529, _534).xyz, _534)) + tex_shadow.SampleCmp(smp_shadow, float4(_550, light_uv.y, _529, _534).xyz, _534)) + tex_shadow.SampleCmp(smp_shadow, float4(light_uv.xy, _529, _534).xyz, _534)) + tex_shadow.SampleCmp(smp_shadow, float4(_584, light_uv.y, _529, _534).xyz, _534)) + tex_shadow.SampleCmp(smp_shadow, float4(_550, _652, _529, _534).xyz, _534)) + tex_shadow.SampleCmp(smp_shadow, float4(light_uv.x, _652, _529, _534).xyz, _534)) + tex_shadow.SampleCmp(smp_shadow, float4(_584, _652, _529, _534).xyz, _534)) * 0.111111111938953399658203125f; + } + + float sampleCascade(int cascade, float3 world_pos, float3 world_normal) + { + float4 _717 = mul(float4(world_pos, 1.0f), _707_cascade_matrices[cascade]); + float3 _724 = _717.xyz / _717.w.xxx; + float3 _742 = float3((_724.x * 0.5f) + 0.5f, ((_724.y * _707_cascade_far_view_z.w) * 0.5f) + 0.5f, _724.z); + bool _746 = any(bool3(_742.x < 0.0f.xxx.x, _742.y < 0.0f.xxx.y, _742.z < 0.0f.xxx.z)); + bool _753; + if (!_746) + { + _753 = any(bool3(_742.x > 1.0f.xxx.x, _742.y > 1.0f.xxx.y, _742.z > 1.0f.xxx.z)); + } + else + { + _753 = _746; + } + if (_753) + { + return 1.0f; + } + int param = cascade; + float3 param_1 = _742; + float param_2 = lerp(0.0040000001899898052215576171875f, 0.0007999999797903001308441162109375f, max(dot(world_normal, normalize(_707_sun_dir_world.xyz)), 0.0f)); + float pcf = sampleShadowPCF(param, param_1, param_2); + if (cascade == 2) + { + float2 _785 = _742.xy; + float2 _790 = min(_785, 1.0f.xx - _785); + pcf = lerp(1.0f, pcf, clamp(min(_790.x, _790.y) * 10.0f, 0.0f, 1.0f)); + } + return pcf; + } + + float sampleShadowCascaded(float3 world_pos, float3 world_normal, float view_z) + { + int cascade = 2; + if (view_z < _707_cascade_far_view_z.x) + { + cascade = 0; + } + else + { + if (view_z < _707_cascade_far_view_z.y) + { + cascade = 1; + } + } + int param = cascade; + float3 param_1 = world_pos; + float3 param_2 = world_normal; + float shadow = sampleCascade(param, param_1, param_2); + if (cascade < 2) + { + float _835; + if (cascade == 0) + { + _835 = _707_cascade_far_view_z.x; + } + else + { + _835 = _707_cascade_far_view_z.y; + } + float _847; + if (cascade == 0) + { + _847 = 0.0f; + } + else + { + _847 = _707_cascade_far_view_z.x; + } + float _858 = lerp(_835, _847, 0.100000001490116119384765625f); + if (view_z > _858) + { + int param_3 = cascade + 1; + float3 param_4 = world_pos; + float3 param_5 = world_normal; + shadow = lerp(shadow, sampleCascade(param_3, param_4, param_5), (view_z - _858) / (_835 - _858)); + } + } + return shadow; + } + + float pbrDistributionGGX(float n_dot_h, float alpha) + { + float _107 = alpha * alpha; + float _116 = ((n_dot_h * n_dot_h) * (_107 - 1.0f)) + 1.0f; + return _107 / ((3.1415927410125732421875f * _116) * _116); + } + + float pbrVisibilitySmithCorrelated(float n_dot_v, float n_dot_l, float alpha) + { + float _129 = alpha * alpha; + float _136 = 1.0f - _129; + return 0.5f / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _136) + _129)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _136) + _129))) + 9.9999997473787516355514526367188e-06f); + } + + float3 pbrFresnelSchlick(float v_dot_h, float3 f0) + { + float _165 = 1.0f - v_dot_h; + float _169 = _165 * _165; + return f0 + ((1.0f.xxx - f0) * ((_169 * _169) * _165)); + } + + float3 brdf_evaluate(float3 N, float3 V, float3 L, float3 sun_radiance, float3 base_color, float metallic, float roughness) + { + float _188 = max(dot(N, L), 0.0f); + float3 _199 = normalize(V + L); + float _213 = max(roughness, 0.04500000178813934326171875f); + float _217 = _213 * _213; + float param = max(dot(N, _199), 0.0f); + float param_1 = _217; + float param_2 = max(dot(N, V), 9.9999997473787516355514526367188e-05f); + float param_3 = _188; + float param_4 = _217; + float param_5 = max(dot(V, _199), 0.0f); + float3 param_6 = lerp(0.039999999105930328369140625f.xxx, base_color, metallic.xxx); + float3 _244 = pbrFresnelSchlick(param_5, param_6); + return ((((((1.0f.xxx - _244) * (1.0f - metallic)) * base_color) * 0.3183098733425140380859375f.xxx) + (_244 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _188; + } + + float3 pbrEvaluateShIrradiance(float3 N, float4 sh[9]) + { + float3 _399 = ((((((((sh[0].xyz * 0.2820948064327239990234375f) + (sh[1].xyz * ((-0.48860251903533935546875f) * N.y))) + (sh[2].xyz * (0.48860251903533935546875f * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875f) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125f * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125f) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125f * (((3.0f * N.z) * N.z) - 1.0f)))) + (sh[7].xyz * (((-1.09254848957061767578125f) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625f * ((N.x * N.x) - (N.y * N.y)))); + return _399; + } + + float3 pbrEvaluateIbl(float3 N_world, float3 V_world, float3 base_color, float metallic, float roughness, float4 sh[9], TextureCube tex_spec_cube, SamplerState smp_spec_cube, Texture2D tex_brdf_lut_1, SamplerState smp_brdf_lut_1, float max_lod) + { + float _406 = clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05f, 1.0f); + float3 _416 = lerp(0.039999999105930328369140625f.xxx, base_color, metallic.xxx); + float3 param = N_world; + float4 param_1[9] = sh; + float4 _482 = tex_brdf_lut_1.Sample(smp_brdf_lut_1, float2(_406, roughness)); + return (((((1.0f.xxx - (_416 + ((max((1.0f - roughness).xxx, _416) - _416) * pow(max(0.0f, 1.0f - _406), 5.0f)))) * (1.0f - metallic)) * base_color) * max(pbrEvaluateShIrradiance(param, param_1), 0.0f.xxx)) * 0.3183098733425140380859375f.xxx) + (tex_spec_cube.SampleLevel(smp_spec_cube, reflect(-V_world, N_world), roughness * max_lod).xyz * ((_416 * _482.x) + _482.y.xxx)); + } + + float3 pbrEvaluateAmbient(bool iblEnabled, float3 N_world, float3 V_world, float3 base_color, float metallic, float roughness, float flat_strength, float4 sh[9], TextureCube tex_spec_cube, SamplerState smp_spec_cube, Texture2D tex_brdf_lut_1, SamplerState smp_brdf_lut_1, float max_lod) + { + float3 result = base_color * flat_strength; + if (iblEnabled) + { + float3 param = N_world; + float3 param_1 = V_world; + float3 param_2 = base_color; + float param_3 = metallic; + float param_4 = roughness; + float4 param_5[9] = sh; + float param_6 = max_lod; + result = pbrEvaluateIbl(param, param_1, param_2, param_3, param_4, param_5, tex_spec_cube, smp_spec_cube, tex_brdf_lut_1, smp_brdf_lut_1, param_6); + } + return result; + } + + void frag_main() + { + float3 _896 = normalize(v_world_pos_proxy - _707_camera_pos.xyz); + float3 _901 = _707_camera_pos.xyz - v_center; + float _905 = dot(_901, _896); + float _914 = v_radius * v_radius; + float _921 = (_905 * _905) - (dot(_901, _901) - _914); + float _931 = sqrt(max(0.0f, _914 - _921)) - v_radius; + float _934 = fwidth(_931); + float _936 = max(_934, 9.9999999747524270787835121154785e-07f); + float _943 = 1.0f - smoothstep(-_936, _936, _931); + float _947; + if (_921 >= 0.0f) + { + _947 = (-_905) - sqrt(_921); + } + else + { + _947 = -_905; + } + if ((_943 <= 0.0f) || (_947 < 0.0f)) + { + discard; + } + float3 _972 = _707_camera_pos.xyz + (_896 * _947); + float3 _977 = normalize(_972 - v_center); + float _983 = _977.x; + float _989 = _977.y; + float _996 = _977.z; + float _998 = ((v_rot_row0.x * _983) + (v_rot_row1.x * _989)) + (v_rot_row2.x * _996); + float _1015 = ((v_rot_row0.y * _983) + (v_rot_row1.y * _989)) + (v_rot_row2.y * _996); + float _1032 = ((v_rot_row0.z * _983) + (v_rot_row1.z * _989)) + (v_rot_row2.z * _996); + float3 _1083 = v_base_color.xyz * ((_1015 > 0.0f) ? 1.0f : 0.64999997615814208984375f); + float3 _1093 = lerp(_1083, _1083 * 0.3499999940395355224609375f, max(1.0f - smoothstep(0.0f, fwidth(_998) * 1.5f, abs(_998)), max(1.0f - smoothstep(0.0f, fwidth(_1015) * 1.5f, abs(_1015)), 1.0f - smoothstep(0.0f, fwidth(_1032) * 1.5f, abs(_1032)))).xxx); + float4 _1101 = float4(_972, 1.0f); + float4 _1102 = mul(_1101, _707_view_proj); + gl_FragDepth = _1102.z / _1102.w; + if (_707_flags.x == 1) + { + float _1134 = clamp(mul(_1101, _707_view).z * (-0.0199999995529651641845703125f), 0.0f, 1.0f); + out_color = float4(_1134, _1134, _1134, 1.0f); + return; + } + if (_707_flags.x == 2) + { + float _1155 = -mul(_1101, _707_view).z; + int cascade = 2; + if (_1155 < _707_cascade_far_view_z.x) + { + cascade = 0; + } + else + { + if (_1155 < _707_cascade_far_view_z.y) + { + cascade = 1; + } + } + float4 _1179 = mul(_1101, _707_cascade_matrices[cascade]); + float3 _1186 = _1179.xyz / _1179.w.xxx; + float3 _1203 = float3((_1186.x * 0.5f) + 0.5f, ((_1186.y * _707_cascade_far_view_z.w) * 0.5f) + 0.5f, _1186.z); + bool _1207 = any(bool3(_1203.x < 0.0f.xxx.x, _1203.y < 0.0f.xxx.y, _1203.z < 0.0f.xxx.z)); + bool _1214; + if (!_1207) + { + _1214 = any(bool3(_1203.x > 1.0f.xxx.x, _1203.y > 1.0f.xxx.y, _1203.z > 1.0f.xxx.z)); + } + else + { + _1214 = _1207; + } + float3 tint = 1.0f.xxx; + if (!_1214) + { + if (cascade == 0) + { + tint = float3(1.0f, 0.4000000059604644775390625f, 0.4000000059604644775390625f); + } + else + { + if (cascade == 1) + { + tint = float3(0.4000000059604644775390625f, 1.0f, 0.4000000059604644775390625f); + } + else + { + tint = float3(0.4000000059604644775390625f, 0.4000000059604644775390625f, 1.0f); + } + } + } + out_color = float4(tint, 1.0f); + return; + } + if (_707_flags.x == 3) + { + out_color = float4((normalize(mul(float4(_983, _989, _996, 0.0f), _707_view).xyz) * 0.5f) + 0.5f.xxx, 1.0f); + return; + } + uint _1276_dummy_parameter; + float4 _1284 = tex_ao.SampleLevel(smp_ao, gl_FragCoord.xy / float2(int2(spvTextureSize(tex_ao, uint(0), _1276_dummy_parameter))), 0.0f); + float _1285 = _1284.x; + if (_707_flags.x == 4) + { + out_color = float4(_1285, _1285, _1285, 1.0f); + return; + } + float3 param = _972; + float3 param_1 = _977; + float param_2 = -mul(_1101, _707_view).z; + float3 _1333 = normalize(_707_camera_pos.xyz - _972); + float3 param_3 = _977; + float3 param_4 = _1333; + float3 param_5 = normalize(_707_sun_dir_world.xyz); + float3 param_6 = _707_sun_color.xyz * sampleShadowCascaded(param, param_1, param_2); + float3 param_7 = _1093; + float param_8 = v_material.x; + float param_9 = v_material.y; + bool param_10 = _707_ibl_params.y > 0.5f; + float3 param_11 = _977; + float3 param_12 = _1333; + float3 param_13 = _1093; + float param_14 = v_material.x; + float param_15 = v_material.y; + float param_16 = _707_sun_color.w; + float4 param_17[9]; + param_17[0] = _707_sh[0]; + param_17[1] = _707_sh[1]; + param_17[2] = _707_sh[2]; + param_17[3] = _707_sh[3]; + param_17[4] = _707_sh[4]; + param_17[5] = _707_sh[5]; + param_17[6] = _707_sh[6]; + param_17[7] = _707_sh[7]; + param_17[8] = _707_sh[8]; + float param_18 = _707_ibl_params.x; + float _1412 = v_base_color.w * _943; + out_color = float4((brdf_evaluate(param_3, param_4, param_5, param_6, param_7, param_8, param_9) + (pbrEvaluateAmbient(param_10, param_11, param_12, param_13, param_14, param_15, param_16, param_17, tex_ibl_spec, smp_ibl_spec, tex_brdf_lut, smp_brdf_lut, param_18) * _1285)) * _1412, _1412); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_FragCoord = stage_input.gl_FragCoord; + gl_FragCoord.w = 1.0 / gl_FragCoord.w; + v_world_pos_proxy = stage_input.v_world_pos_proxy; + v_center = stage_input.v_center; + v_radius = stage_input.v_radius; + v_rot_row0 = stage_input.v_rot_row0; + v_rot_row1 = stage_input.v_rot_row1; + v_rot_row2 = stage_input.v_rot_row2; + v_base_color = stage_input.v_base_color; + v_material = stage_input.v_material; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_FragDepth = gl_FragDepth; + stage_output.out_color = out_color; + return stage_output; + } +*/ +static const uint8_t sphere_fs_source_hlsl5[15240] = { + 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x31,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x30,0x37, + 0x5f,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3a, + 0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x30,0x37, + 0x5f,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x70,0x61,0x63, + 0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x6e,0x74,0x34,0x20,0x5f,0x37,0x30,0x37,0x5f,0x66,0x6c,0x61,0x67,0x73, + 0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x32, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37, + 0x30,0x37,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20, + 0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x33,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x37,0x30,0x37,0x5f,0x76,0x69,0x65,0x77, + 0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73, + 0x65,0x74,0x28,0x63,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f, + 0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f, + 0x37,0x30,0x37,0x5f,0x76,0x69,0x65,0x77,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f, + 0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3a,0x20, + 0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x32,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x33,0x5d, + 0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31, + 0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f, + 0x37,0x30,0x37,0x5f,0x73,0x68,0x5b,0x39,0x5d,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b, + 0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x30,0x37,0x5f,0x69,0x62,0x6c, + 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66, + 0x66,0x73,0x65,0x74,0x28,0x63,0x33,0x34,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x54, + 0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x30,0x29,0x3b, + 0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x6f,0x6d,0x70,0x61,0x72,0x69,0x73, + 0x6f,0x6e,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x30, + 0x29,0x3b,0x0a,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x20,0x3a,0x20,0x72,0x65, + 0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x33,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70, + 0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x33,0x29,0x3b,0x0a, + 0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x43,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63, + 0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x31,0x29,0x3b, + 0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d, + 0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x20,0x3a,0x20,0x72,0x65,0x67, + 0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x31,0x29,0x3b,0x0a,0x54,0x65,0x78,0x74,0x75, + 0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78, + 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x20,0x3a,0x20,0x72,0x65,0x67,0x69, + 0x73,0x74,0x65,0x72,0x28,0x74,0x32,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65, + 0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f, + 0x6c,0x75,0x74,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73, + 0x32,0x29,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x3b, + 0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c, + 0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x3b,0x0a,0x73,0x74,0x61,0x74, + 0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x73,0x74,0x61, + 0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e, + 0x74,0x65,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x73,0x74,0x61,0x74, + 0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f, + 0x72,0x6f,0x77,0x30,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a, + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f, + 0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x73, + 0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x6d, + 0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74, + 0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70, + 0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78, + 0x79,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69, + 0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74, + 0x65,0x72,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74, + 0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69, + 0x75,0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x32,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74, + 0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74, + 0x5f,0x72,0x6f,0x77,0x30,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44, + 0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f, + 0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f, + 0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f, + 0x4f,0x52,0x44,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65, + 0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x20,0x3a,0x20,0x54,0x45, + 0x58,0x43,0x4f,0x4f,0x52,0x44,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69, + 0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x36,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f, + 0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72, + 0x69,0x61,0x6c,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x37,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x46, + 0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x20,0x3a,0x20,0x53,0x56,0x5f,0x50,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75, + 0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f, + 0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x53, + 0x56,0x5f,0x54,0x61,0x72,0x67,0x65,0x74,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74, + 0x68,0x20,0x3a,0x20,0x53,0x56,0x5f,0x44,0x65,0x70,0x74,0x68,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x75,0x69,0x6e,0x74,0x32,0x20,0x73,0x70,0x76,0x54,0x65,0x78,0x74,0x75, + 0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44, + 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x54,0x65,0x78,0x2c,0x20,0x75,0x69, + 0x6e,0x74,0x20,0x4c,0x65,0x76,0x65,0x6c,0x2c,0x20,0x6f,0x75,0x74,0x20,0x75,0x69, + 0x6e,0x74,0x20,0x50,0x61,0x72,0x61,0x6d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x75,0x69,0x6e,0x74,0x32,0x20,0x72,0x65,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x54, + 0x65,0x78,0x2e,0x47,0x65,0x74,0x44,0x69,0x6d,0x65,0x6e,0x73,0x69,0x6f,0x6e,0x73, + 0x28,0x4c,0x65,0x76,0x65,0x6c,0x2c,0x20,0x72,0x65,0x74,0x2e,0x78,0x2c,0x20,0x72, + 0x65,0x74,0x2e,0x79,0x2c,0x20,0x50,0x61,0x72,0x61,0x6d,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x72,0x65,0x74,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61, + 0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x6c,0x69,0x67,0x68,0x74, + 0x5f,0x75,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x62,0x69,0x61,0x73,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x32, + 0x39,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35, + 0x33,0x34,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x7a,0x20, + 0x2d,0x20,0x62,0x69,0x61,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x35,0x35,0x30,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75, + 0x76,0x2e,0x78,0x20,0x2d,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38, + 0x31,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x35,0x35,0x34,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e, + 0x79,0x20,0x2d,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32, + 0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35, + 0x38,0x34,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20, + 0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x66, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x35,0x32, + 0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x20,0x2b,0x20, + 0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x66,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28, + 0x28,0x28,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61, + 0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x35,0x30,0x2c, + 0x20,0x5f,0x35,0x35,0x34,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33, + 0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x20,0x2b,0x20, + 0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c, + 0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76, + 0x2e,0x78,0x2c,0x20,0x5f,0x35,0x35,0x34,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20, + 0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29, + 0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53, + 0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x38,0x34, + 0x2c,0x20,0x5f,0x35,0x35,0x34,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35, + 0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20, + 0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d, + 0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x35,0x30,0x2c,0x20, + 0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x5f,0x35,0x32,0x39, + 0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33, + 0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6c,0x69, + 0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x79,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c, + 0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34, + 0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e, + 0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68, + 0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x38, + 0x34,0x2c,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x5f, + 0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20, + 0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d, + 0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x28,0x5f,0x35,0x35,0x30,0x2c,0x20,0x5f,0x36,0x35,0x32,0x2c,0x20,0x5f,0x35,0x32, + 0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35, + 0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6c, + 0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20,0x5f,0x36,0x35,0x32,0x2c, + 0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a, + 0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28, + 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x28,0x5f,0x35,0x38,0x34,0x2c,0x20,0x5f,0x36,0x35,0x32,0x2c,0x20,0x5f, + 0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20, + 0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2a,0x20,0x30,0x2e,0x31,0x31,0x31,0x31,0x31, + 0x31,0x31,0x31,0x31,0x39,0x33,0x38,0x39,0x35,0x33,0x33,0x39,0x39,0x36,0x35,0x38, + 0x32,0x30,0x33,0x31,0x32,0x35,0x66,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28, + 0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d, + 0x61,0x6c,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x5f,0x37,0x31,0x37,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e, + 0x30,0x66,0x29,0x2c,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x5d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x5f,0x37,0x32,0x34,0x20,0x3d,0x20,0x5f,0x37,0x31,0x37,0x2e,0x78,0x79,0x7a, + 0x20,0x2f,0x20,0x5f,0x37,0x31,0x37,0x2e,0x77,0x2e,0x78,0x78,0x78,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x37,0x34,0x32,0x20,0x3d, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x5f,0x37,0x32,0x34,0x2e,0x78,0x20, + 0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2c,0x20, + 0x28,0x28,0x5f,0x37,0x32,0x34,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x37,0x30,0x37,0x5f, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77, + 0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20, + 0x30,0x2e,0x35,0x66,0x2c,0x20,0x5f,0x37,0x32,0x34,0x2e,0x7a,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x37,0x34,0x36,0x20,0x3d,0x20,0x61, + 0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c,0x33,0x28,0x5f,0x37,0x34,0x32,0x2e,0x78,0x20, + 0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x78,0x2c,0x20,0x5f,0x37, + 0x34,0x32,0x2e,0x79,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e, + 0x79,0x2c,0x20,0x5f,0x37,0x34,0x32,0x2e,0x7a,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66, + 0x2e,0x78,0x78,0x78,0x2e,0x7a,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f, + 0x6f,0x6c,0x20,0x5f,0x37,0x35,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x21,0x5f,0x37,0x34,0x36,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x37,0x35,0x33,0x20,0x3d,0x20,0x61,0x6e,0x79, + 0x28,0x62,0x6f,0x6f,0x6c,0x33,0x28,0x5f,0x37,0x34,0x32,0x2e,0x78,0x20,0x3e,0x20, + 0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x78,0x2c,0x20,0x5f,0x37,0x34,0x32, + 0x2e,0x79,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x79,0x2c, + 0x20,0x5f,0x37,0x34,0x32,0x2e,0x7a,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78, + 0x78,0x78,0x2e,0x7a,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x5f,0x37,0x35,0x33,0x20,0x3d,0x20,0x5f,0x37,0x34,0x36, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x5f,0x37,0x35,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e,0x30,0x66,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6c, + 0x65,0x72,0x70,0x28,0x30,0x2e,0x30,0x30,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x31, + 0x38,0x39,0x39,0x38,0x39,0x38,0x30,0x35,0x32,0x32,0x31,0x35,0x35,0x37,0x36,0x31, + 0x37,0x31,0x38,0x37,0x35,0x66,0x2c,0x20,0x30,0x2e,0x30,0x30,0x30,0x37,0x39,0x39, + 0x39,0x39,0x39,0x39,0x37,0x39,0x37,0x39,0x30,0x33,0x30,0x30,0x31,0x33,0x30,0x38, + 0x34,0x34,0x31,0x31,0x36,0x32,0x31,0x30,0x39,0x33,0x37,0x35,0x66,0x2c,0x20,0x6d, + 0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72, + 0x6d,0x61,0x6c,0x2c,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f, + 0x37,0x30,0x37,0x5f,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x2e,0x78,0x79,0x7a,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x63,0x66,0x20,0x3d, + 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x32,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x37,0x38,0x35,0x20,0x3d,0x20,0x5f,0x37,0x34, + 0x32,0x2e,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x32,0x20,0x5f,0x37,0x39,0x30,0x20,0x3d,0x20,0x6d,0x69,0x6e,0x28, + 0x5f,0x37,0x38,0x35,0x2c,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x20,0x2d,0x20, + 0x5f,0x37,0x38,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x70, + 0x63,0x66,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x31,0x2e,0x30,0x66,0x2c,0x20, + 0x70,0x63,0x66,0x2c,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6d,0x69,0x6e,0x28,0x5f, + 0x37,0x39,0x30,0x2e,0x78,0x2c,0x20,0x5f,0x37,0x39,0x30,0x2e,0x79,0x29,0x20,0x2a, + 0x20,0x31,0x30,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e, + 0x30,0x66,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x70,0x63,0x66,0x3b,0x0a,0x7d,0x0a,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f, + 0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x69,0x65,0x77,0x5f,0x7a,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20, + 0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64, + 0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3c,0x20,0x32,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x33,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d, + 0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x33,0x35,0x20, + 0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66, + 0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65, + 0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x33,0x35,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61, + 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x38,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d, + 0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x34,0x37,0x20,0x3d, + 0x20,0x30,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x5f,0x38,0x34,0x37,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77, + 0x5f,0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38, + 0x35,0x38,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x5f,0x38,0x33,0x35,0x2c,0x20, + 0x5f,0x38,0x34,0x37,0x2c,0x20,0x30,0x2e,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30, + 0x31,0x34,0x39,0x30,0x31,0x31,0x36,0x31,0x31,0x39,0x33,0x38,0x34,0x37,0x36,0x35, + 0x36,0x32,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3e,0x20,0x5f,0x38,0x35,0x38, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x33,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x2b,0x20, + 0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20, + 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f, + 0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61, + 0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x29, + 0x2c,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x2d,0x20,0x5f,0x38,0x35,0x38, + 0x29,0x20,0x2f,0x20,0x28,0x5f,0x38,0x33,0x35,0x20,0x2d,0x20,0x5f,0x38,0x35,0x38, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47, + 0x47,0x58,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x37,0x20, + 0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x36,0x20, + 0x3d,0x20,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x20,0x2a,0x20,0x6e,0x5f, + 0x64,0x6f,0x74,0x5f,0x68,0x29,0x20,0x2a,0x20,0x28,0x5f,0x31,0x30,0x37,0x20,0x2d, + 0x20,0x31,0x2e,0x30,0x66,0x29,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x66,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x30,0x37,0x20, + 0x2f,0x20,0x28,0x28,0x33,0x2e,0x31,0x34,0x31,0x35,0x39,0x32,0x37,0x34,0x31,0x30, + 0x31,0x32,0x35,0x37,0x33,0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x66,0x20,0x2a,0x20, + 0x5f,0x31,0x31,0x36,0x29,0x20,0x2a,0x20,0x5f,0x31,0x31,0x36,0x29,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62, + 0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c, + 0x61,0x74,0x65,0x64,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74, + 0x5f,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f, + 0x6c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x39, + 0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x36, + 0x20,0x3d,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x5f,0x31,0x32,0x39,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x30,0x2e,0x35,0x66,0x20, + 0x2f,0x20,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x73, + 0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20, + 0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x29,0x20,0x2a,0x20,0x5f,0x31,0x33,0x36,0x29, + 0x20,0x2b,0x20,0x5f,0x31,0x32,0x39,0x29,0x29,0x20,0x2b,0x20,0x28,0x6e,0x5f,0x64, + 0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f, + 0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x29, + 0x20,0x2a,0x20,0x5f,0x31,0x33,0x36,0x29,0x20,0x2b,0x20,0x5f,0x31,0x32,0x39,0x29, + 0x29,0x29,0x20,0x2b,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37, + 0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36, + 0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x66,0x29,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e, + 0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x66,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x36,0x35,0x20,0x3d,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x76,0x5f, + 0x64,0x6f,0x74,0x5f,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x36,0x39,0x20,0x3d,0x20,0x5f,0x31,0x36,0x35,0x20,0x2a,0x20,0x5f, + 0x31,0x36,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x66,0x30,0x20,0x2b,0x20,0x28,0x28,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x20, + 0x2d,0x20,0x66,0x30,0x29,0x20,0x2a,0x20,0x28,0x28,0x5f,0x31,0x36,0x39,0x20,0x2a, + 0x20,0x5f,0x31,0x36,0x39,0x29,0x20,0x2a,0x20,0x5f,0x31,0x36,0x35,0x29,0x29,0x3b, + 0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x72,0x64,0x66,0x5f, + 0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x4e,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x56,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x4c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x73,0x75, + 0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x38,0x38, + 0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x4c,0x29, + 0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x5f,0x31,0x39,0x39,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x69,0x7a,0x65,0x28,0x56,0x20,0x2b,0x20,0x4c,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x33,0x20,0x3d,0x20,0x6d,0x61, + 0x78,0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x30,0x2e,0x30, + 0x34,0x35,0x30,0x30,0x30,0x30,0x30,0x31,0x37,0x38,0x38,0x31,0x33,0x39,0x33,0x34, + 0x33,0x32,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x37,0x20,0x3d,0x20,0x5f,0x32, + 0x31,0x33,0x20,0x2a,0x20,0x5f,0x32,0x31,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x6d,0x61,0x78, + 0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x5f,0x31,0x39,0x39,0x29,0x2c,0x20,0x30, + 0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x32,0x31,0x37,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x56, + 0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37, + 0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36, + 0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20, + 0x5f,0x31,0x38,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x32,0x31,0x37,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x35,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x56,0x2c,0x20,0x5f, + 0x31,0x39,0x39,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20, + 0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39, + 0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34, + 0x30,0x36,0x32,0x35,0x66,0x2e,0x78,0x78,0x78,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2e, + 0x78,0x78,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x5f,0x32,0x34,0x34,0x20,0x3d,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e, + 0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x31,0x2e, + 0x30,0x66,0x2e,0x78,0x78,0x78,0x20,0x2d,0x20,0x5f,0x32,0x34,0x34,0x29,0x20,0x2a, + 0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69, + 0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x29,0x20,0x2a,0x20,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33, + 0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x66, + 0x2e,0x78,0x78,0x78,0x29,0x20,0x2b,0x20,0x28,0x5f,0x32,0x34,0x34,0x20,0x2a,0x20, + 0x28,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e, + 0x47,0x47,0x58,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x29,0x20,0x2a,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c, + 0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74, + 0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29,0x29,0x29,0x29, + 0x20,0x2a,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x29, + 0x20,0x2a,0x20,0x5f,0x31,0x38,0x38,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68, + 0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x4e,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x5b,0x39, + 0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x5f,0x33,0x39,0x39,0x20,0x3d,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x73, + 0x68,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x30,0x2e,0x32,0x38,0x32, + 0x30,0x39,0x34,0x38,0x30,0x36,0x34,0x33,0x32,0x37,0x32,0x33,0x39,0x39,0x39,0x30, + 0x32,0x33,0x34,0x33,0x37,0x35,0x66,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x31, + 0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38, + 0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34, + 0x36,0x38,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20, + 0x2b,0x20,0x28,0x73,0x68,0x5b,0x32,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28, + 0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33, + 0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x66,0x20,0x2a,0x20,0x4e,0x2e,0x7a, + 0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x33,0x5d,0x2e,0x78,0x79,0x7a, + 0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31, + 0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x66, + 0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68, + 0x5b,0x34,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x31,0x2e,0x30,0x39, + 0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35, + 0x37,0x38,0x31,0x32,0x35,0x66,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20, + 0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x35,0x5d,0x2e, + 0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35, + 0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38, + 0x31,0x32,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x20,0x2a,0x20,0x4e, + 0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x36,0x5d,0x2e,0x78, + 0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x33,0x31,0x35,0x33,0x39,0x31,0x35,0x37, + 0x30,0x33,0x32,0x39,0x36,0x36,0x36,0x31,0x33,0x37,0x36,0x39,0x35,0x33,0x31,0x32, + 0x35,0x66,0x20,0x2a,0x20,0x28,0x28,0x28,0x33,0x2e,0x30,0x66,0x20,0x2a,0x20,0x4e, + 0x2e,0x7a,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30, + 0x66,0x29,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x37,0x5d,0x2e,0x78, + 0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34, + 0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31, + 0x32,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e, + 0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x38,0x5d,0x2e,0x78,0x79, + 0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x35,0x34,0x36,0x32,0x37,0x34,0x32,0x34,0x34, + 0x37,0x38,0x35,0x33,0x30,0x38,0x38,0x33,0x37,0x38,0x39,0x30,0x36,0x32,0x35,0x66, + 0x20,0x2a,0x20,0x28,0x28,0x4e,0x2e,0x78,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20, + 0x2d,0x20,0x28,0x4e,0x2e,0x79,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x33,0x39, + 0x39,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72, + 0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x2c,0x20,0x54,0x65, + 0x78,0x74,0x75,0x72,0x65,0x43,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c, + 0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d, + 0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x54,0x65,0x78, + 0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74, + 0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x53, + 0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f, + 0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x30,0x36,0x20,0x3d,0x20,0x63,0x6c, + 0x61,0x6d,0x70,0x28,0x64,0x6f,0x74,0x28,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c, + 0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39, + 0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35, + 0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35, + 0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x5f,0x34,0x31,0x36,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70, + 0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39, + 0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x66,0x2e, + 0x78,0x78,0x78,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c, + 0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2e,0x78,0x78,0x78,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x5b,0x39, + 0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x5f,0x34,0x38,0x32,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x62,0x72, + 0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x28, + 0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x34,0x30,0x36,0x2c,0x20,0x72,0x6f,0x75, + 0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x31,0x2e,0x30,0x66,0x2e,0x78, + 0x78,0x78,0x20,0x2d,0x20,0x28,0x5f,0x34,0x31,0x36,0x20,0x2b,0x20,0x28,0x28,0x6d, + 0x61,0x78,0x28,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x72,0x6f,0x75,0x67,0x68, + 0x6e,0x65,0x73,0x73,0x29,0x2e,0x78,0x78,0x78,0x2c,0x20,0x5f,0x34,0x31,0x36,0x29, + 0x20,0x2d,0x20,0x5f,0x34,0x31,0x36,0x29,0x20,0x2a,0x20,0x70,0x6f,0x77,0x28,0x6d, + 0x61,0x78,0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20, + 0x5f,0x34,0x30,0x36,0x29,0x2c,0x20,0x35,0x2e,0x30,0x66,0x29,0x29,0x29,0x29,0x20, + 0x2a,0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c, + 0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x29,0x20,0x2a,0x20,0x6d,0x61,0x78,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c, + 0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29, + 0x2c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x29,0x29,0x20,0x2a,0x20,0x30, + 0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34, + 0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x66,0x2e,0x78,0x78,0x78,0x29, + 0x20,0x2b,0x20,0x28,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62, + 0x65,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x4c,0x65,0x76,0x65,0x6c,0x28,0x73,0x6d, + 0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x72,0x65,0x66, + 0x6c,0x65,0x63,0x74,0x28,0x2d,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x4e, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65, + 0x73,0x73,0x20,0x2a,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x2e,0x78,0x79, + 0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x34,0x31,0x36,0x20,0x2a,0x20,0x5f,0x34,0x38, + 0x32,0x2e,0x78,0x29,0x20,0x2b,0x20,0x5f,0x34,0x38,0x32,0x2e,0x79,0x2e,0x78,0x78, + 0x78,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, + 0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e, + 0x74,0x28,0x62,0x6f,0x6f,0x6c,0x20,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65, + 0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61, + 0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67, + 0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x66,0x6c,0x61, + 0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x2c,0x20,0x54,0x65,0x78,0x74,0x75,0x72, + 0x65,0x43,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65, + 0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x53,0x61,0x6d, + 0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70, + 0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x54,0x65,0x78,0x74,0x75,0x72,0x65, + 0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62, + 0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c, + 0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66, + 0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61, + 0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x62,0x61,0x73, + 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73, + 0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x56,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x62,0x61, + 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20, + 0x3d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x34,0x20,0x3d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x35,0x5b,0x39,0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d, + 0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x35,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62, + 0x65,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65, + 0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31, + 0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x72,0x65,0x73, + 0x75,0x6c,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61, + 0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x38,0x39,0x36,0x20,0x3d,0x20,0x6e,0x6f,0x72, + 0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70, + 0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x5f,0x37,0x30,0x37,0x5f, + 0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x39,0x30,0x31, + 0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70, + 0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65, + 0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x30, + 0x35,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x39,0x30,0x31,0x2c,0x20,0x5f,0x38, + 0x39,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x39,0x31,0x34,0x20,0x3d,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x2a, + 0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x32,0x31,0x20,0x3d,0x20,0x28,0x5f,0x39,0x30, + 0x35,0x20,0x2a,0x20,0x5f,0x39,0x30,0x35,0x29,0x20,0x2d,0x20,0x28,0x64,0x6f,0x74, + 0x28,0x5f,0x39,0x30,0x31,0x2c,0x20,0x5f,0x39,0x30,0x31,0x29,0x20,0x2d,0x20,0x5f, + 0x39,0x31,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x39,0x33,0x31,0x20,0x3d,0x20,0x73,0x71,0x72,0x74,0x28,0x6d,0x61,0x78,0x28, + 0x30,0x2e,0x30,0x66,0x2c,0x20,0x5f,0x39,0x31,0x34,0x20,0x2d,0x20,0x5f,0x39,0x32, + 0x31,0x29,0x29,0x20,0x2d,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x33,0x34,0x20,0x3d, + 0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x39,0x33,0x31,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x33,0x36,0x20,0x3d,0x20, + 0x6d,0x61,0x78,0x28,0x5f,0x39,0x33,0x34,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39, + 0x39,0x39,0x39,0x37,0x34,0x37,0x35,0x32,0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38, + 0x33,0x35,0x31,0x32,0x31,0x31,0x35,0x34,0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x66, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x34, + 0x33,0x20,0x3d,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74, + 0x68,0x73,0x74,0x65,0x70,0x28,0x2d,0x5f,0x39,0x33,0x36,0x2c,0x20,0x5f,0x39,0x33, + 0x36,0x2c,0x20,0x5f,0x39,0x33,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x39,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x5f,0x39,0x32,0x31,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x66,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x39, + 0x34,0x37,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x39,0x30,0x35,0x29,0x20,0x2d,0x20,0x73, + 0x71,0x72,0x74,0x28,0x5f,0x39,0x32,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x39,0x34,0x37,0x20,0x3d,0x20,0x2d, + 0x5f,0x39,0x30,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x28,0x5f,0x39,0x34,0x33,0x20,0x3c,0x3d,0x20,0x30,0x2e,0x30, + 0x66,0x29,0x20,0x7c,0x7c,0x20,0x28,0x5f,0x39,0x34,0x37,0x20,0x3c,0x20,0x30,0x2e, + 0x30,0x66,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x39,0x37, + 0x32,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f, + 0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x38,0x39,0x36,0x20, + 0x2a,0x20,0x5f,0x39,0x34,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x5f,0x39,0x37,0x37,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x69,0x7a,0x65,0x28,0x5f,0x39,0x37,0x32,0x20,0x2d,0x20,0x76,0x5f,0x63,0x65, + 0x6e,0x74,0x65,0x72,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x39,0x38,0x33,0x20,0x3d,0x20,0x5f,0x39,0x37,0x37,0x2e,0x78,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x38,0x39,0x20,0x3d, + 0x20,0x5f,0x39,0x37,0x37,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x39,0x39,0x36,0x20,0x3d,0x20,0x5f,0x39,0x37,0x37,0x2e,0x7a, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x39,0x38, + 0x20,0x3d,0x20,0x28,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x2e, + 0x78,0x20,0x2a,0x20,0x5f,0x39,0x38,0x33,0x29,0x20,0x2b,0x20,0x28,0x76,0x5f,0x72, + 0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x20,0x2a,0x20,0x5f,0x39,0x38,0x39, + 0x29,0x29,0x20,0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32, + 0x2e,0x78,0x20,0x2a,0x20,0x5f,0x39,0x39,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x31,0x35,0x20,0x3d,0x20,0x28,0x28, + 0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x79,0x20,0x2a,0x20,0x5f, + 0x39,0x38,0x33,0x29,0x20,0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f, + 0x77,0x31,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x39,0x38,0x39,0x29,0x29,0x20,0x2b,0x20, + 0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x79,0x20,0x2a,0x20, + 0x5f,0x39,0x39,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x30,0x33,0x32,0x20,0x3d,0x20,0x28,0x28,0x76,0x5f,0x72,0x6f,0x74, + 0x5f,0x72,0x6f,0x77,0x30,0x2e,0x7a,0x20,0x2a,0x20,0x5f,0x39,0x38,0x33,0x29,0x20, + 0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x7a,0x20, + 0x2a,0x20,0x5f,0x39,0x38,0x39,0x29,0x29,0x20,0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f, + 0x74,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x7a,0x20,0x2a,0x20,0x5f,0x39,0x39,0x36,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x30, + 0x38,0x33,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x31,0x30,0x31,0x35,0x20, + 0x3e,0x20,0x30,0x2e,0x30,0x66,0x29,0x20,0x3f,0x20,0x31,0x2e,0x30,0x66,0x20,0x3a, + 0x20,0x30,0x2e,0x36,0x34,0x39,0x39,0x39,0x39,0x39,0x37,0x36,0x31,0x35,0x38,0x31, + 0x34,0x32,0x30,0x38,0x39,0x38,0x34,0x33,0x37,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x30,0x39,0x33,0x20,0x3d, + 0x20,0x6c,0x65,0x72,0x70,0x28,0x5f,0x31,0x30,0x38,0x33,0x2c,0x20,0x5f,0x31,0x30, + 0x38,0x33,0x20,0x2a,0x20,0x30,0x2e,0x33,0x34,0x39,0x39,0x39,0x39,0x39,0x39,0x34, + 0x30,0x33,0x39,0x35,0x33,0x35,0x35,0x32,0x32,0x34,0x36,0x30,0x39,0x33,0x37,0x35, + 0x66,0x2c,0x20,0x6d,0x61,0x78,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x73,0x6d, + 0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x66, + 0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x39,0x39,0x38,0x29,0x20,0x2a,0x20,0x31,0x2e, + 0x35,0x66,0x2c,0x20,0x61,0x62,0x73,0x28,0x5f,0x39,0x39,0x38,0x29,0x29,0x2c,0x20, + 0x6d,0x61,0x78,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74, + 0x68,0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x66,0x77,0x69,0x64, + 0x74,0x68,0x28,0x5f,0x31,0x30,0x31,0x35,0x29,0x20,0x2a,0x20,0x31,0x2e,0x35,0x66, + 0x2c,0x20,0x61,0x62,0x73,0x28,0x5f,0x31,0x30,0x31,0x35,0x29,0x29,0x2c,0x20,0x31, + 0x2e,0x30,0x66,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70, + 0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31, + 0x30,0x33,0x32,0x29,0x20,0x2a,0x20,0x31,0x2e,0x35,0x66,0x2c,0x20,0x61,0x62,0x73, + 0x28,0x5f,0x31,0x30,0x33,0x32,0x29,0x29,0x29,0x29,0x2e,0x78,0x78,0x78,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x31,0x30, + 0x31,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x39,0x37,0x32,0x2c, + 0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x5f,0x31,0x31,0x30,0x32,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x5f, + 0x31,0x31,0x30,0x31,0x2c,0x20,0x5f,0x37,0x30,0x37,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x70,0x72,0x6f,0x6a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72, + 0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x5f,0x31,0x31,0x30,0x32,0x2e, + 0x7a,0x20,0x2f,0x20,0x5f,0x31,0x31,0x30,0x32,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x37,0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e, + 0x78,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x33, + 0x34,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6d,0x75,0x6c,0x28,0x5f,0x31, + 0x31,0x30,0x31,0x2c,0x20,0x5f,0x37,0x30,0x37,0x5f,0x76,0x69,0x65,0x77,0x29,0x2e, + 0x7a,0x20,0x2a,0x20,0x28,0x2d,0x30,0x2e,0x30,0x31,0x39,0x39,0x39,0x39,0x39,0x39, + 0x39,0x35,0x35,0x32,0x39,0x36,0x35,0x31,0x36,0x34,0x31,0x38,0x34,0x35,0x37,0x30, + 0x33,0x31,0x32,0x35,0x66,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e, + 0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, + 0x5f,0x31,0x31,0x33,0x34,0x2c,0x20,0x5f,0x31,0x31,0x33,0x34,0x2c,0x20,0x5f,0x31, + 0x31,0x33,0x34,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x37,0x5f,0x66, + 0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x31,0x35,0x35,0x20,0x3d,0x20,0x2d,0x6d,0x75,0x6c,0x28,0x5f,0x31, + 0x31,0x30,0x31,0x2c,0x20,0x5f,0x37,0x30,0x37,0x5f,0x76,0x69,0x65,0x77,0x29,0x2e, + 0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x35,0x35,0x20,0x3c,0x20, + 0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72, + 0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, + 0x31,0x31,0x35,0x35,0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x5f,0x31,0x31,0x37,0x39,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28, + 0x5f,0x31,0x31,0x30,0x31,0x2c,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x5d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x31,0x38,0x36,0x20,0x3d,0x20,0x5f, + 0x31,0x31,0x37,0x39,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x5f,0x31,0x31,0x37,0x39, + 0x2e,0x77,0x2e,0x78,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x32,0x30,0x33,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x5f,0x31,0x31,0x38,0x36,0x2e,0x78,0x20,0x2a, + 0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2c,0x20,0x28, + 0x28,0x5f,0x31,0x31,0x38,0x36,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x37,0x30,0x37,0x5f, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77, + 0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20, + 0x30,0x2e,0x35,0x66,0x2c,0x20,0x5f,0x31,0x31,0x38,0x36,0x2e,0x7a,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x32, + 0x30,0x37,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c,0x33,0x28,0x5f, + 0x31,0x32,0x30,0x33,0x2e,0x78,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78, + 0x78,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x32,0x30,0x33,0x2e,0x79,0x20,0x3c,0x20,0x30, + 0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x79,0x2c,0x20,0x5f,0x31,0x32,0x30,0x33, + 0x2e,0x7a,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x7a,0x29, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20, + 0x5f,0x31,0x32,0x31,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x21,0x5f,0x31,0x32,0x30,0x37,0x29,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x5f,0x31,0x32,0x31,0x34,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f, + 0x6c,0x33,0x28,0x5f,0x31,0x32,0x30,0x33,0x2e,0x78,0x20,0x3e,0x20,0x31,0x2e,0x30, + 0x66,0x2e,0x78,0x78,0x78,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x32,0x30,0x33,0x2e,0x79, + 0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x79,0x2c,0x20,0x5f, + 0x31,0x32,0x30,0x33,0x2e,0x7a,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78, + 0x78,0x2e,0x7a,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x5f,0x31,0x32,0x31,0x34,0x20,0x3d,0x20,0x5f,0x31,0x32,0x30, + 0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x74,0x69,0x6e,0x74, + 0x20,0x3d,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x32,0x31,0x34,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30, + 0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35, + 0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30, + 0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39, + 0x30,0x36,0x32,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e, + 0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30, + 0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35, + 0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x2c,0x20,0x30, + 0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34, + 0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20, + 0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30, + 0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39, + 0x30,0x36,0x32,0x35,0x66,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30, + 0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36, + 0x32,0x35,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75, + 0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x28,0x74,0x69,0x6e,0x74,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x37, + 0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x33,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, + 0x28,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x6d,0x75,0x6c,0x28,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x39,0x38,0x33,0x2c,0x20,0x5f,0x39,0x38,0x39, + 0x2c,0x20,0x5f,0x39,0x39,0x36,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f, + 0x37,0x30,0x37,0x5f,0x76,0x69,0x65,0x77,0x29,0x2e,0x78,0x79,0x7a,0x29,0x20,0x2a, + 0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2e,0x78,0x78, + 0x78,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x5f,0x31,0x32,0x37,0x36,0x5f,0x64, + 0x75,0x6d,0x6d,0x79,0x5f,0x70,0x61,0x72,0x61,0x6d,0x65,0x74,0x65,0x72,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x32,0x38,0x34, + 0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65, + 0x4c,0x65,0x76,0x65,0x6c,0x28,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20,0x67,0x6c, + 0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x20,0x2f,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x69,0x6e,0x74,0x32,0x28,0x73,0x70,0x76,0x54, + 0x65,0x78,0x74,0x75,0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x74,0x65,0x78,0x5f,0x61, + 0x6f,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x30,0x29,0x2c,0x20,0x5f,0x31,0x32,0x37, + 0x36,0x5f,0x64,0x75,0x6d,0x6d,0x79,0x5f,0x70,0x61,0x72,0x61,0x6d,0x65,0x74,0x65, + 0x72,0x29,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x38,0x35,0x20,0x3d,0x20,0x5f, + 0x31,0x32,0x38,0x34,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x5f,0x37,0x30,0x37,0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20, + 0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x28,0x5f,0x31,0x32,0x38,0x35,0x2c,0x20,0x5f,0x31,0x32,0x38,0x35, + 0x2c,0x20,0x5f,0x31,0x32,0x38,0x35,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f,0x39,0x37,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x20,0x3d,0x20,0x5f,0x39,0x37,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x2d,0x6d, + 0x75,0x6c,0x28,0x5f,0x31,0x31,0x30,0x31,0x2c,0x20,0x5f,0x37,0x30,0x37,0x5f,0x76, + 0x69,0x65,0x77,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x5f,0x31,0x33,0x33,0x33,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61, + 0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x39,0x37,0x32,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x39,0x37,0x37,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20, + 0x3d,0x20,0x5f,0x31,0x33,0x33,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x6e,0x6f, + 0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37,0x30,0x37,0x5f,0x73,0x75,0x6e, + 0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x73,0x75,0x6e,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x5f, + 0x31,0x30,0x39,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65, + 0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61, + 0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f, + 0x6f,0x6c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x5f,0x37, + 0x30,0x37,0x5f,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x20, + 0x3e,0x20,0x30,0x2e,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x5f,0x39, + 0x37,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x5f,0x31,0x33,0x33,0x33,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20,0x5f,0x31,0x30,0x39,0x33,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34, + 0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x35,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c, + 0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x73,0x75, + 0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x39, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b, + 0x30,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x73,0x68,0x5b,0x30,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x31,0x5d, + 0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x73,0x68,0x5b,0x31,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x32,0x5d,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x5f,0x73,0x68,0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x33,0x5d,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x37,0x5f,0x73,0x68,0x5b,0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x34,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30, + 0x37,0x5f,0x73,0x68,0x5b,0x34,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x37,0x5b,0x35,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f, + 0x73,0x68,0x5b,0x35,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x37,0x5b,0x36,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x73,0x68, + 0x5b,0x36,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x37,0x5b,0x37,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x73,0x68,0x5b,0x37, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b, + 0x38,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x73,0x68,0x5b,0x38,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x38,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x69,0x62,0x6c,0x5f,0x70, + 0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x34,0x31,0x32,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73, + 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x20,0x2a,0x20,0x5f,0x39,0x34,0x33, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20, + 0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x62,0x72,0x64,0x66,0x5f,0x65, + 0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x39,0x29,0x20,0x2b,0x20,0x28,0x70,0x62,0x72,0x45,0x76,0x61, + 0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20,0x74,0x65,0x78, + 0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x69, + 0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64, + 0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f, + 0x6c,0x75,0x74,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x29,0x20,0x2a, + 0x20,0x5f,0x31,0x32,0x38,0x35,0x29,0x29,0x20,0x2a,0x20,0x5f,0x31,0x34,0x31,0x32, + 0x2c,0x20,0x5f,0x31,0x34,0x31,0x32,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49, + 0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20, + 0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73, + 0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70, + 0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61, + 0x67,0x43,0x6f,0x6f,0x72,0x64,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69, + 0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72, + 0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f, + 0x6f,0x72,0x64,0x2e,0x77,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2f,0x20,0x67,0x6c, + 0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x77,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72, + 0x6f,0x78,0x79,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75, + 0x74,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72, + 0x6f,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65, + 0x72,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e, + 0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f, + 0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69, + 0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x20,0x3d,0x20, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x72,0x6f, + 0x74,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x6f, + 0x74,0x5f,0x72,0x6f,0x77,0x31,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69, + 0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x20, + 0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f, + 0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f, + 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x6d,0x61,0x74, + 0x65,0x72,0x69,0x61,0x6c,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e, + 0x70,0x75,0x74,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73, + 0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75, + 0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f, + 0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65, + 0x70,0x74,0x68,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70, + 0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75, + 0x74,0x70,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, + 0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74, + 0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + struct instance + { + float4 xform_row0; + float4 xform_row1; + float4 xform_row2; + float4 base_color; + float4 params; + float4 material; + }; + + struct instances + { + instance items[1]; + }; + + struct ub_draw + { + int4 inst_base; + }; + + struct ub_frame + { + float4x4 view_proj; + }; + + struct main0_out + { + float3 v_world_pos_proxy [[user(locn0)]]; + float3 v_center [[user(locn1)]]; + float v_radius [[user(locn2)]]; + float3 v_rot_row0 [[user(locn3)]]; + float3 v_rot_row1 [[user(locn4)]]; + float3 v_rot_row2 [[user(locn5)]]; + float4 v_base_color [[user(locn6)]]; + float4 v_material [[user(locn7)]]; + float4 gl_Position [[position]]; + }; + + struct main0_in + { + float3 in_pos [[attribute(0)]]; + }; + + vertex main0_out main0(main0_in in [[stage_in]], constant ub_frame& _112 [[buffer(0)]], constant ub_draw& _21 [[buffer(2)]], const device instances& _15 [[buffer(8)]], uint gl_InstanceIndex [[instance_id]]) + { + main0_out out = {}; + int _30 = _21.inst_base.x + int(gl_InstanceIndex); + float3 _63 = float3(_15.items[_30].xform_row0.w, _15.items[_30].xform_row1.w, _15.items[_30].xform_row2.w); + float3 _76 = _63 + (in.in_pos * (2.0 * _15.items[_30].params.x)); + out.v_world_pos_proxy = _76; + out.v_center = _63; + out.v_radius = _15.items[_30].params.x; + out.v_rot_row0 = _15.items[_30].xform_row0.xyz; + out.v_rot_row1 = _15.items[_30].xform_row1.xyz; + out.v_rot_row2 = _15.items[_30].xform_row2.xyz; + out.v_base_color = _15.items[_30].base_color; + out.v_material = _15.items[_30].material; + out.gl_Position = _112.view_proj * float4(_76, 1.0); + return out; + } + +*/ +static const uint8_t sphere_vs_source_metal_macos[1693] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x20,0x69,0x74,0x65,0x6d,0x73,0x5b,0x31,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a, + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x34,0x20,0x69,0x6e,0x73,0x74,0x5f,0x62, + 0x61,0x73,0x65,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20, + 0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f, + 0x6a,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61, + 0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, + 0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f, + 0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x5b,0x5b,0x75,0x73, + 0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20, + 0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x32,0x29,0x5d,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f, + 0x74,0x5f,0x72,0x6f,0x77,0x30,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f, + 0x63,0x6e,0x33,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x20,0x5b,0x5b, + 0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x34,0x29,0x5d,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f, + 0x72,0x6f,0x77,0x32,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e, + 0x35,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b, + 0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x36,0x29,0x5d,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65, + 0x72,0x69,0x61,0x6c,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e, + 0x37,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b,0x70, + 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73, + 0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70, + 0x6f,0x73,0x20,0x5b,0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28,0x30, + 0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,0x65,0x78,0x20, + 0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28, + 0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74, + 0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61, + 0x6e,0x74,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x26,0x20,0x5f,0x31,0x31, + 0x32,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x64,0x72,0x61, + 0x77,0x26,0x20,0x5f,0x32,0x31,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28, + 0x32,0x29,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x64,0x65,0x76,0x69, + 0x63,0x65,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x26,0x20,0x5f,0x31, + 0x35,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x38,0x29,0x5d,0x5d,0x2c, + 0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x5b,0x5b,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x5f,0x69,0x64,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61, + 0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x33,0x30,0x20,0x3d,0x20, + 0x5f,0x32,0x31,0x2e,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20, + 0x2b,0x20,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x5f,0x36,0x33,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e, + 0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f,0x31, + 0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69, + 0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f, + 0x72,0x6f,0x77,0x32,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x5f,0x37,0x36,0x20,0x3d,0x20,0x5f,0x36,0x33,0x20,0x2b,0x20, + 0x28,0x69,0x6e,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x2a,0x20,0x28,0x32,0x2e, + 0x30,0x20,0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33, + 0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70, + 0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x5f,0x37,0x36,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72, + 0x20,0x3d,0x20,0x5f,0x36,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e, + 0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69, + 0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73, + 0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x72,0x6f, + 0x74,0x5f,0x72,0x6f,0x77,0x30,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65, + 0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f, + 0x77,0x30,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e, + 0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x20,0x3d,0x20,0x5f,0x31,0x35, + 0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x6f,0x75,0x74,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x20,0x3d, + 0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e, + 0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x78,0x79,0x7a,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73, + 0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65, + 0x72,0x69,0x61,0x6c,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73, + 0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74, + 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x5f,0x31,0x31,0x32,0x2e,0x76,0x69,0x65,0x77,0x5f, + 0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x37, + 0x36,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + #pragma clang diagnostic ignored "-Wmissing-prototypes" + #pragma clang diagnostic ignored "-Wmissing-braces" + + #include + #include + + using namespace metal; + + template + struct spvUnsafeArray + { + T elements[Num ? Num : 1]; + + thread T& operator [] (size_t pos) thread + { + return elements[pos]; + } + constexpr const thread T& operator [] (size_t pos) const thread + { + return elements[pos]; + } + + device T& operator [] (size_t pos) device + { + return elements[pos]; + } + constexpr const device T& operator [] (size_t pos) const device + { + return elements[pos]; + } + + constexpr const constant T& operator [] (size_t pos) const constant + { + return elements[pos]; + } + + threadgroup T& operator [] (size_t pos) threadgroup + { + return elements[pos]; + } + constexpr const threadgroup T& operator [] (size_t pos) const threadgroup + { + return elements[pos]; + } + }; + + struct ub_pass + { + float4 sun_dir_world; + float4 sun_color; + int4 flags; + float4 camera_pos; + float4x4 view_proj; + float4x4 view; + float4 cascade_far_view_z; + float4x4 cascade_matrices[3]; + float4 sh[9]; + float4 ibl_params; + }; + + struct main0_out + { + float4 out_color [[color(0)]]; + float gl_FragDepth [[depth(any)]]; + }; + + struct main0_in + { + float3 v_world_pos_proxy [[user(locn0)]]; + float3 v_center [[user(locn1), flat]]; + float v_radius [[user(locn2), flat]]; + float3 v_rot_row0 [[user(locn3), flat]]; + float3 v_rot_row1 [[user(locn4), flat]]; + float3 v_rot_row2 [[user(locn5), flat]]; + float4 v_base_color [[user(locn6), flat]]; + float4 v_material [[user(locn7), flat]]; + }; + + static inline __attribute__((always_inline)) + float sampleShadowPCF(thread const int& cascade, thread const float3& light_uv, thread const float& bias0, depth2d_array tex_shadow, sampler smp_shadow) + { + float _529 = float(cascade); + float _534 = light_uv.z - bias0; + float _550 = light_uv.x - 0.00048828125; + float _554 = light_uv.y - 0.00048828125; + float4 _557 = float4(_550, _554, _529, _534); + float4 _573 = float4(light_uv.x, _554, _529, _534); + float _584 = light_uv.x + 0.00048828125; + float4 _591 = float4(_584, _554, _529, _534); + float4 _607 = float4(_550, light_uv.y, _529, _534); + float4 _621 = float4(light_uv.xy, _529, _534); + float4 _637 = float4(_584, light_uv.y, _529, _534); + float _652 = light_uv.y + 0.00048828125; + float4 _655 = float4(_550, _652, _529, _534); + float4 _671 = float4(light_uv.x, _652, _529, _534); + float4 _689 = float4(_584, _652, _529, _534); + return ((((((((tex_shadow.sample_compare(smp_shadow, _557.xy, uint(rint(_557.z)), _534) + tex_shadow.sample_compare(smp_shadow, _573.xy, uint(rint(_573.z)), _534)) + tex_shadow.sample_compare(smp_shadow, _591.xy, uint(rint(_591.z)), _534)) + tex_shadow.sample_compare(smp_shadow, _607.xy, uint(rint(_607.z)), _534)) + tex_shadow.sample_compare(smp_shadow, _621.xy, uint(rint(_621.z)), _534)) + tex_shadow.sample_compare(smp_shadow, _637.xy, uint(rint(_637.z)), _534)) + tex_shadow.sample_compare(smp_shadow, _655.xy, uint(rint(_655.z)), _534)) + tex_shadow.sample_compare(smp_shadow, _671.xy, uint(rint(_671.z)), _534)) + tex_shadow.sample_compare(smp_shadow, _689.xy, uint(rint(_689.z)), _534)) * 0.111111111938953399658203125; + } + + static inline __attribute__((always_inline)) + float sampleCascade(thread const int& cascade, thread const float3& world_pos, thread const float3& world_normal, depth2d_array tex_shadow, sampler smp_shadow, constant ub_pass& _707) + { + float4 _717 = _707.cascade_matrices[cascade] * float4(world_pos, 1.0); + float3 _724 = _717.xyz / float3(_717.w); + float3 _742 = float3((_724.x * 0.5) + 0.5, ((_724.y * _707.cascade_far_view_z.w) * 0.5) + 0.5, _724.z); + bool _746 = any(_742 < float3(0.0)); + bool _753; + if (!_746) + { + _753 = any(_742 > float3(1.0)); + } + else + { + _753 = _746; + } + if (_753) + { + return 1.0; + } + int param = cascade; + float3 param_1 = _742; + float param_2 = mix(0.0040000001899898052215576171875, 0.0007999999797903001308441162109375, fast::max(dot(world_normal, fast::normalize(_707.sun_dir_world.xyz)), 0.0)); + float pcf = sampleShadowPCF(param, param_1, param_2, tex_shadow, smp_shadow); + if (cascade == 2) + { + float2 _785 = _742.xy; + float2 _790 = fast::min(_785, float2(1.0) - _785); + pcf = mix(1.0, pcf, fast::clamp(fast::min(_790.x, _790.y) * 10.0, 0.0, 1.0)); + } + return pcf; + } + + static inline __attribute__((always_inline)) + float sampleShadowCascaded(thread const float3& world_pos, thread const float3& world_normal, thread const float& view_z, depth2d_array tex_shadow, sampler smp_shadow, constant ub_pass& _707) + { + int cascade = 2; + if (view_z < _707.cascade_far_view_z.x) + { + cascade = 0; + } + else + { + if (view_z < _707.cascade_far_view_z.y) + { + cascade = 1; + } + } + int param = cascade; + float3 param_1 = world_pos; + float3 param_2 = world_normal; + float shadow = sampleCascade(param, param_1, param_2, tex_shadow, smp_shadow, _707); + if (cascade < 2) + { + float _835; + if (cascade == 0) + { + _835 = _707.cascade_far_view_z.x; + } + else + { + _835 = _707.cascade_far_view_z.y; + } + float _847; + if (cascade == 0) + { + _847 = 0.0; + } + else + { + _847 = _707.cascade_far_view_z.x; + } + float _858 = mix(_835, _847, 0.100000001490116119384765625); + if (view_z > _858) + { + int param_3 = cascade + 1; + float3 param_4 = world_pos; + float3 param_5 = world_normal; + shadow = mix(shadow, sampleCascade(param_3, param_4, param_5, tex_shadow, smp_shadow, _707), (view_z - _858) / (_835 - _858)); + } + } + return shadow; + } + + static inline __attribute__((always_inline)) + float pbrDistributionGGX(thread const float& n_dot_h, thread const float& alpha) + { + float _107 = alpha * alpha; + float _116 = ((n_dot_h * n_dot_h) * (_107 - 1.0)) + 1.0; + return _107 / ((3.1415927410125732421875 * _116) * _116); + } + + static inline __attribute__((always_inline)) + float pbrVisibilitySmithCorrelated(thread const float& n_dot_v, thread const float& n_dot_l, thread const float& alpha) + { + float _129 = alpha * alpha; + float _136 = 1.0 - _129; + return 0.5 / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _136) + _129)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _136) + _129))) + 9.9999997473787516355514526367188e-06); + } + + static inline __attribute__((always_inline)) + float3 pbrFresnelSchlick(thread const float& v_dot_h, thread const float3& f0) + { + float _165 = 1.0 - v_dot_h; + float _169 = _165 * _165; + return f0 + ((float3(1.0) - f0) * ((_169 * _169) * _165)); + } + + static inline __attribute__((always_inline)) + float3 brdf_evaluate(thread const float3& N, thread const float3& V, thread const float3& L, thread const float3& sun_radiance, thread const float3& base_color, thread const float& metallic, thread const float& roughness) + { + float _188 = fast::max(dot(N, L), 0.0); + float3 _199 = fast::normalize(V + L); + float _213 = fast::max(roughness, 0.04500000178813934326171875); + float _217 = _213 * _213; + float param = fast::max(dot(N, _199), 0.0); + float param_1 = _217; + float param_2 = fast::max(dot(N, V), 9.9999997473787516355514526367188e-05); + float param_3 = _188; + float param_4 = _217; + float param_5 = fast::max(dot(V, _199), 0.0); + float3 param_6 = mix(float3(0.039999999105930328369140625), base_color, float3(metallic)); + float3 _244 = pbrFresnelSchlick(param_5, param_6); + return ((((((float3(1.0) - _244) * (1.0 - metallic)) * base_color) * float3(0.3183098733425140380859375)) + (_244 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _188; + } + + static inline __attribute__((always_inline)) + float3 pbrEvaluateShIrradiance(thread const float3& N, thread const spvUnsafeArray& sh) + { + float3 _399 = ((((((((sh[0].xyz * 0.2820948064327239990234375) + (sh[1].xyz * ((-0.48860251903533935546875) * N.y))) + (sh[2].xyz * (0.48860251903533935546875 * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125 * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125 * (((3.0 * N.z) * N.z) - 1.0)))) + (sh[7].xyz * (((-1.09254848957061767578125) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625 * ((N.x * N.x) - (N.y * N.y)))); + return _399; + } + + static inline __attribute__((always_inline)) + float3 pbrEvaluateIbl(thread const float3& N_world, thread const float3& V_world, thread const float3& base_color, thread const float& metallic, thread const float& roughness, thread const spvUnsafeArray& sh, texturecube tex_spec_cube, sampler smp_spec_cube, texture2d tex_brdf_lut, sampler smp_brdf_lut, thread const float& max_lod) + { + float _406 = fast::clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05, 1.0); + float3 _416 = mix(float3(0.039999999105930328369140625), base_color, float3(metallic)); + float3 param = N_world; + spvUnsafeArray param_1 = sh; + float4 _482 = tex_brdf_lut.sample(smp_brdf_lut, float2(_406, roughness)); + return (((((float3(1.0) - (_416 + ((fast::max(float3(1.0 - roughness), _416) - _416) * powr(fast::max(0.0, 1.0 - _406), 5.0)))) * (1.0 - metallic)) * base_color) * fast::max(pbrEvaluateShIrradiance(param, param_1), float3(0.0))) * float3(0.3183098733425140380859375)) + (tex_spec_cube.sample(smp_spec_cube, reflect(-V_world, N_world), level(roughness * max_lod)).xyz * ((_416 * _482.x) + float3(_482.y))); + } + + static inline __attribute__((always_inline)) + float3 pbrEvaluateAmbient(thread const bool& iblEnabled, thread const float3& N_world, thread const float3& V_world, thread const float3& base_color, thread const float& metallic, thread const float& roughness, thread const float& flat_strength, thread const spvUnsafeArray& sh, texturecube tex_spec_cube, sampler smp_spec_cube, texture2d tex_brdf_lut, sampler smp_brdf_lut, thread const float& max_lod) + { + float3 result = base_color * flat_strength; + if (iblEnabled) + { + float3 param = N_world; + float3 param_1 = V_world; + float3 param_2 = base_color; + float param_3 = metallic; + float param_4 = roughness; + spvUnsafeArray param_5 = sh; + float param_6 = max_lod; + result = pbrEvaluateIbl(param, param_1, param_2, param_3, param_4, param_5, tex_spec_cube, smp_spec_cube, tex_brdf_lut, smp_brdf_lut, param_6); + } + return result; + } + + fragment main0_out main0(main0_in in [[stage_in]], constant ub_pass& _707 [[buffer(1)]], depth2d_array tex_shadow [[texture(0)]], texturecube tex_ibl_spec [[texture(1)]], texture2d tex_brdf_lut [[texture(2)]], texture2d tex_ao [[texture(3)]], sampler smp_shadow [[sampler(0)]], sampler smp_ibl_spec [[sampler(1)]], sampler smp_brdf_lut [[sampler(2)]], sampler smp_ao [[sampler(3)]], float4 gl_FragCoord [[position]]) + { + main0_out out = {}; + float3 _896 = fast::normalize(in.v_world_pos_proxy - _707.camera_pos.xyz); + float3 _901 = _707.camera_pos.xyz - in.v_center; + float _905 = dot(_901, _896); + float _914 = in.v_radius * in.v_radius; + float _921 = (_905 * _905) - (dot(_901, _901) - _914); + float _931 = sqrt(fast::max(0.0, _914 - _921)) - in.v_radius; + float _934 = fwidth(_931); + float _936 = fast::max(_934, 9.9999999747524270787835121154785e-07); + float _943 = 1.0 - smoothstep(-_936, _936, _931); + float _947; + if (_921 >= 0.0) + { + _947 = (-_905) - sqrt(_921); + } + else + { + _947 = -_905; + } + if ((_943 <= 0.0) || (_947 < 0.0)) + { + discard_fragment(); + } + float3 _972 = _707.camera_pos.xyz + (_896 * _947); + float3 _977 = fast::normalize(_972 - in.v_center); + float _983 = _977.x; + float _989 = _977.y; + float _996 = _977.z; + float _998 = ((in.v_rot_row0.x * _983) + (in.v_rot_row1.x * _989)) + (in.v_rot_row2.x * _996); + float _1015 = ((in.v_rot_row0.y * _983) + (in.v_rot_row1.y * _989)) + (in.v_rot_row2.y * _996); + float _1032 = ((in.v_rot_row0.z * _983) + (in.v_rot_row1.z * _989)) + (in.v_rot_row2.z * _996); + float3 _1083 = in.v_base_color.xyz * ((_1015 > 0.0) ? 1.0 : 0.64999997615814208984375); + float3 _1093 = mix(_1083, _1083 * 0.3499999940395355224609375, float3(fast::max(1.0 - smoothstep(0.0, fwidth(_998) * 1.5, abs(_998)), fast::max(1.0 - smoothstep(0.0, fwidth(_1015) * 1.5, abs(_1015)), 1.0 - smoothstep(0.0, fwidth(_1032) * 1.5, abs(_1032)))))); + float4 _1101 = float4(_972, 1.0); + float4 _1102 = _707.view_proj * _1101; + out.gl_FragDepth = _1102.z / _1102.w; + if (_707.flags.x == 1) + { + float _1134 = fast::clamp((_707.view * _1101).z * (-0.0199999995529651641845703125), 0.0, 1.0); + out.out_color = float4(_1134, _1134, _1134, 1.0); + return out; + } + if (_707.flags.x == 2) + { + float _1155 = -(_707.view * _1101).z; + int cascade = 2; + if (_1155 < _707.cascade_far_view_z.x) + { + cascade = 0; + } + else + { + if (_1155 < _707.cascade_far_view_z.y) + { + cascade = 1; + } + } + float4 _1179 = _707.cascade_matrices[cascade] * _1101; + float3 _1186 = _1179.xyz / float3(_1179.w); + float3 _1203 = float3((_1186.x * 0.5) + 0.5, ((_1186.y * _707.cascade_far_view_z.w) * 0.5) + 0.5, _1186.z); + bool _1207 = any(_1203 < float3(0.0)); + bool _1214; + if (!_1207) + { + _1214 = any(_1203 > float3(1.0)); + } + else + { + _1214 = _1207; + } + float3 tint = float3(1.0); + if (!_1214) + { + if (cascade == 0) + { + tint = float3(1.0, 0.4000000059604644775390625, 0.4000000059604644775390625); + } + else + { + if (cascade == 1) + { + tint = float3(0.4000000059604644775390625, 1.0, 0.4000000059604644775390625); + } + else + { + tint = float3(0.4000000059604644775390625, 0.4000000059604644775390625, 1.0); + } + } + } + out.out_color = float4(tint, 1.0); + return out; + } + if (_707.flags.x == 3) + { + out.out_color = float4((fast::normalize((_707.view * float4(_983, _989, _996, 0.0)).xyz) * 0.5) + float3(0.5), 1.0); + return out; + } + float4 _1284 = tex_ao.sample(smp_ao, (gl_FragCoord.xy / float2(int2(tex_ao.get_width(), tex_ao.get_height()))), level(0.0)); + float _1285 = _1284.x; + if (_707.flags.x == 4) + { + out.out_color = float4(_1285, _1285, _1285, 1.0); + return out; + } + float3 param = _972; + float3 param_1 = _977; + float param_2 = -(_707.view * _1101).z; + float3 _1333 = fast::normalize(_707.camera_pos.xyz - _972); + float3 param_3 = _977; + float3 param_4 = _1333; + float3 param_5 = fast::normalize(_707.sun_dir_world.xyz); + float3 param_6 = _707.sun_color.xyz * sampleShadowCascaded(param, param_1, param_2, tex_shadow, smp_shadow, _707); + float3 param_7 = _1093; + float param_8 = in.v_material.x; + float param_9 = in.v_material.y; + bool param_10 = _707.ibl_params.y > 0.5; + float3 param_11 = _977; + float3 param_12 = _1333; + float3 param_13 = _1093; + float param_14 = in.v_material.x; + float param_15 = in.v_material.y; + float param_16 = _707.sun_color.w; + spvUnsafeArray param_17; + param_17[0] = _707.sh[0]; + param_17[1] = _707.sh[1]; + param_17[2] = _707.sh[2]; + param_17[3] = _707.sh[3]; + param_17[4] = _707.sh[4]; + param_17[5] = _707.sh[5]; + param_17[6] = _707.sh[6]; + param_17[7] = _707.sh[7]; + param_17[8] = _707.sh[8]; + float param_18 = _707.ibl_params.x; + float _1412 = in.v_base_color.w * _943; + out.out_color = float4((brdf_evaluate(param_3, param_4, param_5, param_6, param_7, param_8, param_9) + (pbrEvaluateAmbient(param_10, param_11, param_12, param_13, param_14, param_15, param_16, param_17, tex_ibl_spec, smp_ibl_spec, tex_brdf_lut, smp_brdf_lut, param_18) * _1285)) * _1412, _1412); + return out; + } + +*/ +static const uint8_t sphere_fs_source_metal_macos[16701] = { + 0x23,0x70,0x72,0x61,0x67,0x6d,0x61,0x20,0x63,0x6c,0x61,0x6e,0x67,0x20,0x64,0x69, + 0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x20,0x69,0x67,0x6e,0x6f,0x72,0x65,0x64, + 0x20,0x22,0x2d,0x57,0x6d,0x69,0x73,0x73,0x69,0x6e,0x67,0x2d,0x70,0x72,0x6f,0x74, + 0x6f,0x74,0x79,0x70,0x65,0x73,0x22,0x0a,0x23,0x70,0x72,0x61,0x67,0x6d,0x61,0x20, + 0x63,0x6c,0x61,0x6e,0x67,0x20,0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63, + 0x20,0x69,0x67,0x6e,0x6f,0x72,0x65,0x64,0x20,0x22,0x2d,0x57,0x6d,0x69,0x73,0x73, + 0x69,0x6e,0x67,0x2d,0x62,0x72,0x61,0x63,0x65,0x73,0x22,0x0a,0x0a,0x23,0x69,0x6e, + 0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f,0x73,0x74,0x64, + 0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x73, + 0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a,0x75,0x73,0x69, + 0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20,0x6d,0x65,0x74, + 0x61,0x6c,0x3b,0x0a,0x0a,0x74,0x65,0x6d,0x70,0x6c,0x61,0x74,0x65,0x3c,0x74,0x79, + 0x70,0x65,0x6e,0x61,0x6d,0x65,0x20,0x54,0x2c,0x20,0x73,0x69,0x7a,0x65,0x5f,0x74, + 0x20,0x4e,0x75,0x6d,0x3e,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x73,0x70,0x76, + 0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x54,0x20,0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x4e,0x75,0x6d, + 0x20,0x3f,0x20,0x4e,0x75,0x6d,0x20,0x3a,0x20,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x0a,0x20,0x20,0x20,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x54,0x26,0x20, + 0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72,0x20,0x5b,0x5d,0x20,0x28,0x73,0x69,0x7a, + 0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f, + 0x73,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x65,0x78,0x70,0x72,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x74,0x68, + 0x72,0x65,0x61,0x64,0x20,0x54,0x26,0x20,0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72, + 0x20,0x5b,0x5d,0x20,0x28,0x73,0x69,0x7a,0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f,0x73,0x5d, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x0a,0x20,0x20,0x20, + 0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x20,0x54,0x26,0x20,0x6f,0x70,0x65,0x72,0x61, + 0x74,0x6f,0x72,0x20,0x5b,0x5d,0x20,0x28,0x73,0x69,0x7a,0x65,0x5f,0x74,0x20,0x70, + 0x6f,0x73,0x29,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f,0x73,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6e,0x73,0x74,0x65,0x78, + 0x70,0x72,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x20, + 0x54,0x26,0x20,0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72,0x20,0x5b,0x5d,0x20,0x28, + 0x73,0x69,0x7a,0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x65,0x6c, + 0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f,0x73,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x65,0x78,0x70,0x72,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x61,0x6e,0x74,0x20,0x54,0x26,0x20,0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72, + 0x20,0x5b,0x5d,0x20,0x28,0x73,0x69,0x7a,0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f, + 0x73,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x0a,0x20, + 0x20,0x20,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x67,0x72,0x6f,0x75,0x70,0x20,0x54, + 0x26,0x20,0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72,0x20,0x5b,0x5d,0x20,0x28,0x73, + 0x69,0x7a,0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x67,0x72,0x6f,0x75,0x70,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x65,0x6c,0x65,0x6d, + 0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f,0x73,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6e,0x73,0x74,0x65,0x78,0x70,0x72,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x67,0x72,0x6f,0x75,0x70, + 0x20,0x54,0x26,0x20,0x6f,0x70,0x65,0x72,0x61,0x74,0x6f,0x72,0x20,0x5b,0x5d,0x20, + 0x28,0x73,0x69,0x7a,0x65,0x5f,0x74,0x20,0x70,0x6f,0x73,0x29,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x67,0x72,0x6f,0x75,0x70,0x0a,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x70,0x6f,0x73, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72, + 0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x6e,0x74,0x34,0x20,0x66,0x6c,0x61,0x67,0x73,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f, + 0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78, + 0x34,0x20,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x76,0x69,0x65,0x77,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x33,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x5b,0x39, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x69,0x62, + 0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29, + 0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c, + 0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x5b,0x5b,0x64,0x65,0x70, + 0x74,0x68,0x28,0x61,0x6e,0x79,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73, + 0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x5b,0x5b, + 0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74, + 0x65,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29, + 0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x5b,0x5b,0x75, + 0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x32,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74, + 0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76, + 0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72, + 0x28,0x6c,0x6f,0x63,0x6e,0x33,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f, + 0x74,0x5f,0x72,0x6f,0x77,0x31,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f, + 0x63,0x6e,0x34,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72, + 0x6f,0x77,0x32,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x35, + 0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x36,0x29, + 0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20, + 0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x37,0x29,0x2c,0x20,0x66, + 0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69, + 0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69, + 0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69, + 0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61, + 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x74,0x68, + 0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x69,0x6e,0x74,0x26,0x20, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20, + 0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x6c,0x69, + 0x67,0x68,0x74,0x5f,0x75,0x76,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x62,0x69,0x61,0x73, + 0x30,0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61,0x79, + 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x35,0x32,0x39,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x33,0x34,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68, + 0x74,0x5f,0x75,0x76,0x2e,0x7a,0x20,0x2d,0x20,0x62,0x69,0x61,0x73,0x30,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x35,0x30,0x20,0x3d, + 0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20,0x2d,0x20,0x30,0x2e, + 0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x35,0x34,0x20,0x3d,0x20,0x6c,0x69, + 0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x20,0x2d,0x20,0x30,0x2e,0x30,0x30,0x30, + 0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x5f,0x35,0x35,0x37,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x28,0x5f,0x35,0x35,0x30,0x2c,0x20,0x5f,0x35,0x35,0x34,0x2c,0x20,0x5f, + 0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x35,0x37,0x33,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c, + 0x20,0x5f,0x35,0x35,0x34,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33, + 0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35, + 0x38,0x34,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20, + 0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x35,0x39,0x31, + 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x38,0x34,0x2c,0x20, + 0x5f,0x35,0x35,0x34,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36, + 0x30,0x37,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x35,0x30, + 0x2c,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x5f,0x35, + 0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36,0x32,0x31,0x20,0x3d,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x79,0x2c, + 0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36,0x33,0x37,0x20,0x3d,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x38,0x34,0x2c,0x20,0x6c,0x69,0x67, + 0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f, + 0x35,0x33,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x36,0x35,0x32,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e, + 0x79,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32, + 0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36, + 0x35,0x35,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x35,0x30, + 0x2c,0x20,0x5f,0x36,0x35,0x32,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35, + 0x33,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x5f,0x36,0x37,0x31,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6c,0x69, + 0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20,0x5f,0x36,0x35,0x32,0x2c,0x20, + 0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36,0x38,0x39,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x38,0x34,0x2c,0x20,0x5f,0x36,0x35,0x32, + 0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28, + 0x28,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x35,0x35,0x37,0x2e,0x78,0x79,0x2c, + 0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x35,0x35,0x37,0x2e, + 0x7a,0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x20,0x2b,0x20,0x74,0x65,0x78, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63, + 0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2c,0x20,0x5f,0x35,0x37,0x33,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74, + 0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x35,0x37,0x33,0x2e,0x7a,0x29,0x29,0x2c,0x20, + 0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61, + 0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f, + 0x35,0x39,0x31,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e, + 0x74,0x28,0x5f,0x35,0x39,0x31,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x34, + 0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73, + 0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x36,0x30,0x37,0x2e, + 0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x36, + 0x30,0x37,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b, + 0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x36,0x32,0x31,0x2e,0x78,0x79,0x2c,0x20, + 0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x36,0x32,0x31,0x2e,0x7a, + 0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63, + 0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2c,0x20,0x5f,0x36,0x33,0x37,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74, + 0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x36,0x33,0x37,0x2e,0x7a,0x29,0x29,0x2c,0x20, + 0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61, + 0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f, + 0x36,0x35,0x35,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e, + 0x74,0x28,0x5f,0x36,0x35,0x35,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x34, + 0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73, + 0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x36,0x37,0x31,0x2e, + 0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x36, + 0x37,0x31,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b, + 0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x36,0x38,0x39,0x2e,0x78,0x79,0x2c,0x20, + 0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x36,0x38,0x39,0x2e,0x7a, + 0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2a,0x20,0x30,0x2e,0x31, + 0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x39,0x33,0x38,0x39,0x35,0x33,0x33,0x39, + 0x39,0x36,0x35,0x38,0x32,0x30,0x33,0x31,0x32,0x35,0x3b,0x0a,0x7d,0x0a,0x0a,0x73, + 0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61, + 0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61, + 0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28, + 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x69,0x6e,0x74, + 0x26,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20, + 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20, + 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x64,0x65, + 0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61, + 0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73, + 0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x70, + 0x61,0x73,0x73,0x26,0x20,0x5f,0x37,0x30,0x37,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x31,0x37,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72, + 0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x20,0x2a,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, + 0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x5f,0x37,0x32,0x34,0x20,0x3d,0x20,0x5f,0x37,0x31,0x37,0x2e,0x78, + 0x79,0x7a,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x37,0x31,0x37, + 0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x5f,0x37,0x34,0x32,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x5f, + 0x37,0x32,0x34,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30, + 0x2e,0x35,0x2c,0x20,0x28,0x28,0x5f,0x37,0x32,0x34,0x2e,0x79,0x20,0x2a,0x20,0x5f, + 0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29, + 0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x37,0x32,0x34,0x2e,0x7a,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x37,0x34,0x36,0x20,0x3d, + 0x20,0x61,0x6e,0x79,0x28,0x5f,0x37,0x34,0x32,0x20,0x3c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f, + 0x6f,0x6c,0x20,0x5f,0x37,0x35,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x21,0x5f,0x37,0x34,0x36,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x37,0x35,0x33,0x20,0x3d,0x20,0x61,0x6e,0x79, + 0x28,0x5f,0x37,0x34,0x32,0x20,0x3e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31, + 0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x5f,0x37,0x35,0x33,0x20,0x3d,0x20,0x5f,0x37,0x34,0x36,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37, + 0x35,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20, + 0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28, + 0x30,0x2e,0x30,0x30,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x38,0x39,0x39,0x38, + 0x39,0x38,0x30,0x35,0x32,0x32,0x31,0x35,0x35,0x37,0x36,0x31,0x37,0x31,0x38,0x37, + 0x35,0x2c,0x20,0x30,0x2e,0x30,0x30,0x30,0x37,0x39,0x39,0x39,0x39,0x39,0x39,0x37, + 0x39,0x37,0x39,0x30,0x33,0x30,0x30,0x31,0x33,0x30,0x38,0x34,0x34,0x31,0x31,0x36, + 0x32,0x31,0x30,0x39,0x33,0x37,0x35,0x2c,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d, + 0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72, + 0x6d,0x61,0x6c,0x2c,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37,0x30,0x37,0x2e,0x73,0x75,0x6e,0x5f,0x64,0x69, + 0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x29,0x29,0x2c,0x20,0x30, + 0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x63,0x66,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64, + 0x6f,0x77,0x50,0x43,0x46,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x74, + 0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x32,0x20,0x5f,0x37,0x38,0x35,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x2e,0x78, + 0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x32,0x20,0x5f,0x37,0x39,0x30,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d, + 0x69,0x6e,0x28,0x5f,0x37,0x38,0x35,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28, + 0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x37,0x38,0x35,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28, + 0x31,0x2e,0x30,0x2c,0x20,0x70,0x63,0x66,0x2c,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a, + 0x63,0x6c,0x61,0x6d,0x70,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x69,0x6e,0x28, + 0x5f,0x37,0x39,0x30,0x2e,0x78,0x2c,0x20,0x5f,0x37,0x39,0x30,0x2e,0x79,0x29,0x20, + 0x2a,0x20,0x31,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x70,0x63,0x66,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61, + 0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74, + 0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73, + 0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63, + 0x61,0x64,0x65,0x64,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x70,0x6f,0x73,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x76,0x69,0x65,0x77, + 0x5f,0x7a,0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61, + 0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e, + 0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x37,0x30,0x37,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a, + 0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a, + 0x2e,0x79,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63, + 0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x74,0x65,0x78, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2c,0x20,0x5f,0x37,0x30,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3c,0x20,0x32,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x33,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d, + 0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x33,0x35,0x20, + 0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66, + 0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65, + 0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x33,0x35,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61, + 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x38,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d, + 0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x34,0x37,0x20,0x3d, + 0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x5f,0x38,0x34,0x37,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x35, + 0x38,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x5f,0x38,0x33,0x35,0x2c,0x20,0x5f,0x38, + 0x34,0x37,0x2c,0x20,0x30,0x2e,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x34, + 0x39,0x30,0x31,0x31,0x36,0x31,0x31,0x39,0x33,0x38,0x34,0x37,0x36,0x35,0x36,0x32, + 0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3e,0x20,0x5f,0x38,0x35,0x38,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, + 0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x2b,0x20,0x31,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x77,0x6f,0x72, + 0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x35,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64, + 0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x74,0x65,0x78, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2c,0x20,0x5f,0x37,0x30,0x37,0x29,0x2c,0x20,0x28,0x76,0x69,0x65, + 0x77,0x5f,0x7a,0x20,0x2d,0x20,0x5f,0x38,0x35,0x38,0x29,0x20,0x2f,0x20,0x28,0x5f, + 0x38,0x33,0x35,0x20,0x2d,0x20,0x5f,0x38,0x35,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x3b, + 0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e, + 0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28, + 0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29, + 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69, + 0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x74,0x68,0x72,0x65,0x61,0x64, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6e,0x5f, + 0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x61,0x6c,0x70,0x68,0x61, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x30,0x37,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70, + 0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x31,0x36,0x20,0x3d,0x20,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x20,0x2a, + 0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x29,0x20,0x2a,0x20,0x28,0x5f,0x31,0x30, + 0x37,0x20,0x2d,0x20,0x31,0x2e,0x30,0x29,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x30,0x37, + 0x20,0x2f,0x20,0x28,0x28,0x33,0x2e,0x31,0x34,0x31,0x35,0x39,0x32,0x37,0x34,0x31, + 0x30,0x31,0x32,0x35,0x37,0x33,0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x20,0x2a,0x20, + 0x5f,0x31,0x31,0x36,0x29,0x20,0x2a,0x20,0x5f,0x31,0x31,0x36,0x29,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20, + 0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61, + 0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69, + 0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65, + 0x64,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x26,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x2c,0x20,0x74, + 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x26,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x74,0x68,0x72,0x65, + 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20, + 0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x32,0x39,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20, + 0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x33,0x36,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20, + 0x5f,0x31,0x32,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x30,0x2e,0x35,0x20,0x2f,0x20,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f, + 0x6c,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74, + 0x5f,0x76,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x29,0x20,0x2a,0x20, + 0x5f,0x31,0x33,0x36,0x29,0x20,0x2b,0x20,0x5f,0x31,0x32,0x39,0x29,0x29,0x20,0x2b, + 0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x73,0x71,0x72,0x74, + 0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x6e,0x5f,0x64, + 0x6f,0x74,0x5f,0x6c,0x29,0x20,0x2a,0x20,0x5f,0x31,0x33,0x36,0x29,0x20,0x2b,0x20, + 0x5f,0x31,0x32,0x39,0x29,0x29,0x29,0x20,0x2b,0x20,0x39,0x2e,0x39,0x39,0x39,0x39, + 0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35, + 0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x29, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69, + 0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f, + 0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29, + 0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73, + 0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x76, + 0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x66,0x30,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36, + 0x35,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f, + 0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36, + 0x39,0x20,0x3d,0x20,0x5f,0x31,0x36,0x35,0x20,0x2a,0x20,0x5f,0x31,0x36,0x35,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x30,0x20,0x2b, + 0x20,0x28,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d, + 0x20,0x66,0x30,0x29,0x20,0x2a,0x20,0x28,0x28,0x5f,0x31,0x36,0x39,0x20,0x2a,0x20, + 0x5f,0x31,0x36,0x39,0x29,0x20,0x2a,0x20,0x5f,0x31,0x36,0x35,0x29,0x29,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65, + 0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28, + 0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c, + 0x75,0x61,0x74,0x65,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4e,0x2c,0x20,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x26,0x20,0x56,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4c,0x2c,0x20,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x26,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x2c,0x20, + 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x26,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c, + 0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x26,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x74, + 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x26,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x38,0x38,0x20,0x3d, + 0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e, + 0x2c,0x20,0x4c,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x39,0x39,0x20,0x3d,0x20,0x66,0x61, + 0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x56,0x20, + 0x2b,0x20,0x4c,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x32,0x31,0x33,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78, + 0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x30,0x2e,0x30,0x34, + 0x35,0x30,0x30,0x30,0x30,0x30,0x31,0x37,0x38,0x38,0x31,0x33,0x39,0x33,0x34,0x33, + 0x32,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x37,0x20,0x3d,0x20,0x5f,0x32,0x31,0x33, + 0x20,0x2a,0x20,0x5f,0x32,0x31,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a, + 0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x5f,0x31,0x39,0x39, + 0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x32,0x31, + 0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78, + 0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x56,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39, + 0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35, + 0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30, + 0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31,0x38,0x38,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20, + 0x3d,0x20,0x5f,0x32,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x66,0x61,0x73,0x74, + 0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x56,0x2c,0x20,0x5f,0x31,0x39, + 0x39,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d, + 0x69,0x78,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x33,0x39,0x39, + 0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38,0x33,0x36, + 0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x6d,0x65,0x74, + 0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x5f,0x32,0x34,0x34,0x20,0x3d,0x20,0x70,0x62,0x72,0x46,0x72, + 0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28, + 0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f, + 0x32,0x34,0x34,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65, + 0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, + 0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31, + 0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x29,0x29,0x20,0x2b,0x20, + 0x28,0x5f,0x32,0x34,0x34,0x20,0x2a,0x20,0x28,0x70,0x62,0x72,0x44,0x69,0x73,0x74, + 0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x20,0x2a,0x20,0x70,0x62, + 0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68, + 0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x34,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x73,0x75,0x6e,0x5f,0x72, + 0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x29,0x20,0x2a,0x20,0x5f,0x31,0x38,0x38,0x3b, + 0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e, + 0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28, + 0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29, + 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75, + 0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28, + 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x26,0x20,0x4e,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72, + 0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x26,0x20, + 0x73,0x68,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x5f,0x33,0x39,0x39,0x20,0x3d,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28, + 0x73,0x68,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x30,0x2e,0x32,0x38, + 0x32,0x30,0x39,0x34,0x38,0x30,0x36,0x34,0x33,0x32,0x37,0x32,0x33,0x39,0x39,0x39, + 0x30,0x32,0x33,0x34,0x33,0x37,0x35,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x31, + 0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38, + 0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34, + 0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b, + 0x20,0x28,0x73,0x68,0x5b,0x32,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30, + 0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39, + 0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29, + 0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x33,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a, + 0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30, + 0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a, + 0x20,0x4e,0x2e,0x78,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x34,0x5d, + 0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x31,0x2e,0x30,0x39,0x32,0x35,0x34, + 0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31, + 0x32,0x35,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29, + 0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x35,0x5d,0x2e,0x78,0x79,0x7a,0x20, + 0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38, + 0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x29, + 0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29, + 0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x36,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, + 0x28,0x30,0x2e,0x33,0x31,0x35,0x33,0x39,0x31,0x35,0x37,0x30,0x33,0x32,0x39,0x36, + 0x36,0x36,0x31,0x33,0x37,0x36,0x39,0x35,0x33,0x31,0x32,0x35,0x20,0x2a,0x20,0x28, + 0x28,0x28,0x33,0x2e,0x30,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2a,0x20,0x4e, + 0x2e,0x7a,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x29,0x29,0x29,0x29,0x20,0x2b,0x20, + 0x28,0x73,0x68,0x5b,0x37,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28, + 0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36, + 0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e, + 0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73, + 0x68,0x5b,0x38,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x35,0x34, + 0x36,0x32,0x37,0x34,0x32,0x34,0x34,0x37,0x38,0x35,0x33,0x30,0x38,0x38,0x33,0x37, + 0x38,0x39,0x30,0x36,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x4e,0x2e,0x78,0x20,0x2a, + 0x20,0x4e,0x2e,0x78,0x29,0x20,0x2d,0x20,0x28,0x4e,0x2e,0x79,0x20,0x2a,0x20,0x4e, + 0x2e,0x79,0x29,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x5f,0x33,0x39,0x39,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74, + 0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72, + 0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f, + 0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x74, + 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x26,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x26,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20, + 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x74,0x68,0x72,0x65, + 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x72,0x6f, + 0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20, + 0x63,0x6f,0x6e,0x73,0x74,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41, + 0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x26, + 0x20,0x73,0x68,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x63,0x75,0x62,0x65, + 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63, + 0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73, + 0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x74,0x65, + 0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74, + 0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75, + 0x74,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x30,0x36, + 0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x64, + 0x6f,0x74,0x28,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x56,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34, + 0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32, + 0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x34, + 0x31,0x36,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, + 0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33, + 0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c,0x20, + 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20, + 0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73, + 0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x5f,0x34,0x38,0x32,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64, + 0x66,0x5f,0x6c,0x75,0x74,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70, + 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x32,0x28,0x5f,0x34,0x30,0x36,0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73, + 0x73,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x28,0x28,0x28,0x28,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29, + 0x20,0x2d,0x20,0x28,0x5f,0x34,0x31,0x36,0x20,0x2b,0x20,0x28,0x28,0x66,0x61,0x73, + 0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e, + 0x30,0x20,0x2d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x2c,0x20, + 0x5f,0x34,0x31,0x36,0x29,0x20,0x2d,0x20,0x5f,0x34,0x31,0x36,0x29,0x20,0x2a,0x20, + 0x70,0x6f,0x77,0x72,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x30, + 0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f,0x34,0x30,0x36,0x29,0x2c, + 0x20,0x35,0x2e,0x30,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20, + 0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62, + 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x66,0x61,0x73, + 0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61, + 0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x70, + 0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x29,0x20,0x2a,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38, + 0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33, + 0x37,0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63, + 0x5f,0x63,0x75,0x62,0x65,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70, + 0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x72,0x65,0x66,0x6c, + 0x65,0x63,0x74,0x28,0x2d,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x4e,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x6c,0x65,0x76,0x65,0x6c,0x28,0x72,0x6f, + 0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x20,0x2a,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f, + 0x64,0x29,0x29,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x34,0x31,0x36, + 0x20,0x2a,0x20,0x5f,0x34,0x38,0x32,0x2e,0x78,0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x28,0x5f,0x34,0x38,0x32,0x2e,0x79,0x29,0x29,0x29,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20, + 0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61, + 0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74, + 0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20, + 0x63,0x6f,0x6e,0x73,0x74,0x20,0x62,0x6f,0x6f,0x6c,0x26,0x20,0x69,0x62,0x6c,0x45, + 0x6e,0x61,0x62,0x6c,0x65,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4e,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x56,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69, + 0x63,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73, + 0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x26,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e, + 0x67,0x74,0x68,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79, + 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x26,0x20,0x73,0x68,0x2c, + 0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x63,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f, + 0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62, + 0x65,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73, + 0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72, + 0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62, + 0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72, + 0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x74, + 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x26,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20, + 0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x66, + 0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d, + 0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65, + 0x73,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x70,0x76,0x55, + 0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x2c,0x20,0x39,0x3e,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20, + 0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x61,0x78,0x5f, + 0x6c,0x6f,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x73, + 0x75,0x6c,0x74,0x20,0x3d,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74, + 0x65,0x49,0x62,0x6c,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65, + 0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63, + 0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f, + 0x6c,0x75,0x74,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75, + 0x74,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x72,0x65, + 0x73,0x75,0x6c,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e, + 0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e, + 0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x37, + 0x30,0x37,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x31,0x29,0x5d,0x5d, + 0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61,0x79,0x3c, + 0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x30,0x29,0x5d,0x5d, + 0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x63,0x75,0x62,0x65,0x3c,0x66,0x6c, + 0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65, + 0x63,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x31,0x29,0x5d,0x5d, + 0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61, + 0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x20, + 0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x32,0x29,0x5d,0x5d,0x2c,0x20, + 0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e, + 0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72, + 0x65,0x28,0x33,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20, + 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x5b,0x5b,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x20, + 0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x31,0x29,0x5d,0x5d,0x2c,0x20, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66, + 0x5f,0x6c,0x75,0x74,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x32, + 0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70, + 0x5f,0x61,0x6f,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x33,0x29, + 0x5d,0x5d,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x46,0x72, + 0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69, + 0x6f,0x6e,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e, + 0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x38,0x39,0x36,0x20, + 0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a, + 0x65,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, + 0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61, + 0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x39,0x30,0x31,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73, + 0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74, + 0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39, + 0x30,0x35,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x39,0x30,0x31,0x2c,0x20,0x5f, + 0x38,0x39,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x39,0x31,0x34,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69, + 0x75,0x73,0x20,0x2a,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x32,0x31, + 0x20,0x3d,0x20,0x28,0x5f,0x39,0x30,0x35,0x20,0x2a,0x20,0x5f,0x39,0x30,0x35,0x29, + 0x20,0x2d,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x39,0x30,0x31,0x2c,0x20,0x5f,0x39, + 0x30,0x31,0x29,0x20,0x2d,0x20,0x5f,0x39,0x31,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x33,0x31,0x20,0x3d,0x20,0x73,0x71, + 0x72,0x74,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30, + 0x2c,0x20,0x5f,0x39,0x31,0x34,0x20,0x2d,0x20,0x5f,0x39,0x32,0x31,0x29,0x29,0x20, + 0x2d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x33,0x34,0x20,0x3d,0x20, + 0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x39,0x33,0x31,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x33,0x36,0x20,0x3d,0x20,0x66, + 0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x5f,0x39,0x33,0x34,0x2c,0x20,0x39, + 0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x35,0x32,0x34,0x32,0x37, + 0x30,0x37,0x38,0x37,0x38,0x33,0x35,0x31,0x32,0x31,0x31,0x35,0x34,0x37,0x38,0x35, + 0x65,0x2d,0x30,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x39,0x34,0x33,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73,0x6d, + 0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x2d,0x5f,0x39,0x33,0x36,0x2c,0x20, + 0x5f,0x39,0x33,0x36,0x2c,0x20,0x5f,0x39,0x33,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x5f,0x39,0x32,0x31,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x5f,0x39,0x34,0x37,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x39,0x30,0x35,0x29,0x20,0x2d, + 0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x39,0x32,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x39,0x34,0x37,0x20,0x3d, + 0x20,0x2d,0x5f,0x39,0x30,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x5f,0x39,0x34,0x33,0x20,0x3c,0x3d,0x20,0x30, + 0x2e,0x30,0x29,0x20,0x7c,0x7c,0x20,0x28,0x5f,0x39,0x34,0x37,0x20,0x3c,0x20,0x30, + 0x2e,0x30,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64,0x5f,0x66,0x72,0x61,0x67,0x6d, + 0x65,0x6e,0x74,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x39,0x37,0x32,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78, + 0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x38,0x39,0x36,0x20,0x2a,0x20,0x5f,0x39,0x34, + 0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f, + 0x39,0x37,0x37,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d, + 0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x39,0x37,0x32,0x20,0x2d,0x20,0x69,0x6e,0x2e, + 0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x38,0x33,0x20,0x3d,0x20,0x5f,0x39,0x37,0x37, + 0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39, + 0x38,0x39,0x20,0x3d,0x20,0x5f,0x39,0x37,0x37,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x39,0x36,0x20,0x3d,0x20,0x5f,0x39, + 0x37,0x37,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x39,0x39,0x38,0x20,0x3d,0x20,0x28,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f, + 0x74,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x78,0x20,0x2a,0x20,0x5f,0x39,0x38,0x33,0x29, + 0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77, + 0x31,0x2e,0x78,0x20,0x2a,0x20,0x5f,0x39,0x38,0x39,0x29,0x29,0x20,0x2b,0x20,0x28, + 0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x78,0x20, + 0x2a,0x20,0x5f,0x39,0x39,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x30,0x31,0x35,0x20,0x3d,0x20,0x28,0x28,0x69,0x6e,0x2e, + 0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x79,0x20,0x2a,0x20,0x5f, + 0x39,0x38,0x33,0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f,0x74, + 0x5f,0x72,0x6f,0x77,0x31,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x39,0x38,0x39,0x29,0x29, + 0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77, + 0x32,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x39,0x39,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x33,0x32,0x20,0x3d,0x20,0x28, + 0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x7a, + 0x20,0x2a,0x20,0x5f,0x39,0x38,0x33,0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x76, + 0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x7a,0x20,0x2a,0x20,0x5f,0x39, + 0x38,0x39,0x29,0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f,0x74, + 0x5f,0x72,0x6f,0x77,0x32,0x2e,0x7a,0x20,0x2a,0x20,0x5f,0x39,0x39,0x36,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x30,0x38, + 0x33,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x31,0x30,0x31, + 0x35,0x20,0x3e,0x20,0x30,0x2e,0x30,0x29,0x20,0x3f,0x20,0x31,0x2e,0x30,0x20,0x3a, + 0x20,0x30,0x2e,0x36,0x34,0x39,0x39,0x39,0x39,0x39,0x37,0x36,0x31,0x35,0x38,0x31, + 0x34,0x32,0x30,0x38,0x39,0x38,0x34,0x33,0x37,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x30,0x39,0x33,0x20,0x3d,0x20, + 0x6d,0x69,0x78,0x28,0x5f,0x31,0x30,0x38,0x33,0x2c,0x20,0x5f,0x31,0x30,0x38,0x33, + 0x20,0x2a,0x20,0x30,0x2e,0x33,0x34,0x39,0x39,0x39,0x39,0x39,0x39,0x34,0x30,0x33, + 0x39,0x35,0x33,0x35,0x35,0x32,0x32,0x34,0x36,0x30,0x39,0x33,0x37,0x35,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78, + 0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65, + 0x70,0x28,0x30,0x2e,0x30,0x2c,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x39, + 0x39,0x38,0x29,0x20,0x2a,0x20,0x31,0x2e,0x35,0x2c,0x20,0x61,0x62,0x73,0x28,0x5f, + 0x39,0x39,0x38,0x29,0x29,0x2c,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78, + 0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65, + 0x70,0x28,0x30,0x2e,0x30,0x2c,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31, + 0x30,0x31,0x35,0x29,0x20,0x2a,0x20,0x31,0x2e,0x35,0x2c,0x20,0x61,0x62,0x73,0x28, + 0x5f,0x31,0x30,0x31,0x35,0x29,0x29,0x2c,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73, + 0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30,0x2c,0x20,0x66, + 0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31,0x30,0x33,0x32,0x29,0x20,0x2a,0x20,0x31, + 0x2e,0x35,0x2c,0x20,0x61,0x62,0x73,0x28,0x5f,0x31,0x30,0x33,0x32,0x29,0x29,0x29, + 0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x5f,0x31,0x31,0x30,0x31,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f, + 0x39,0x37,0x32,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x31,0x30,0x32,0x20,0x3d,0x20,0x5f,0x37, + 0x30,0x37,0x2e,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20,0x5f, + 0x31,0x31,0x30,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c, + 0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x5f,0x31,0x31, + 0x30,0x32,0x2e,0x7a,0x20,0x2f,0x20,0x5f,0x31,0x31,0x30,0x32,0x2e,0x77,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x37,0x2e,0x66,0x6c,0x61, + 0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x31,0x33,0x34,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61, + 0x6d,0x70,0x28,0x28,0x5f,0x37,0x30,0x37,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20, + 0x5f,0x31,0x31,0x30,0x31,0x29,0x2e,0x7a,0x20,0x2a,0x20,0x28,0x2d,0x30,0x2e,0x30, + 0x31,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x35,0x35,0x32,0x39,0x36,0x35,0x31,0x36, + 0x34,0x31,0x38,0x34,0x35,0x37,0x30,0x33,0x31,0x32,0x35,0x29,0x2c,0x20,0x30,0x2e, + 0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x31,0x33,0x34,0x2c,0x20,0x5f, + 0x31,0x31,0x33,0x34,0x2c,0x20,0x5f,0x31,0x31,0x33,0x34,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x37,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e, + 0x78,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x35, + 0x35,0x20,0x3d,0x20,0x2d,0x28,0x5f,0x37,0x30,0x37,0x2e,0x76,0x69,0x65,0x77,0x20, + 0x2a,0x20,0x5f,0x31,0x31,0x30,0x31,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20, + 0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x5f,0x31,0x31,0x35,0x35,0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a, + 0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x35,0x35,0x20,0x3c,0x20, + 0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72, + 0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x29,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x31, + 0x37,0x39,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x5d,0x20,0x2a,0x20,0x5f,0x31,0x31,0x30,0x31,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x31,0x38, + 0x36,0x20,0x3d,0x20,0x5f,0x31,0x31,0x37,0x39,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x31,0x31,0x37,0x39,0x2e,0x77,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x5f,0x31,0x32,0x30,0x33,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28, + 0x5f,0x31,0x31,0x38,0x36,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b, + 0x20,0x30,0x2e,0x35,0x2c,0x20,0x28,0x28,0x5f,0x31,0x31,0x38,0x36,0x2e,0x79,0x20, + 0x2a,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66, + 0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30, + 0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x31,0x31,0x38,0x36, + 0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f, + 0x6c,0x20,0x5f,0x31,0x32,0x30,0x37,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x5f,0x31, + 0x32,0x30,0x33,0x20,0x3c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c, + 0x20,0x5f,0x31,0x32,0x31,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x32,0x30,0x37,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x5f,0x31,0x32,0x31,0x34,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x5f,0x31, + 0x32,0x30,0x33,0x20,0x3e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x5f,0x31,0x32,0x31,0x34,0x20,0x3d,0x20,0x5f,0x31,0x32,0x30,0x37,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x32,0x31,0x34,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30, + 0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33, + 0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30, + 0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36, + 0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65, + 0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d, + 0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30, + 0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30, + 0x36,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30, + 0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33, + 0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36, + 0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20, + 0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36, + 0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x74,0x69,0x6e,0x74, + 0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x37,0x2e,0x66, + 0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x33,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f, + 0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x28,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69, + 0x7a,0x65,0x28,0x28,0x5f,0x37,0x30,0x37,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x39,0x38,0x33,0x2c,0x20,0x5f,0x39,0x38, + 0x39,0x2c,0x20,0x5f,0x39,0x39,0x36,0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,0x2e,0x78, + 0x79,0x7a,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x28,0x30,0x2e,0x35,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f, + 0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x32,0x38,0x34,0x20,0x3d,0x20,0x74,0x65,0x78, + 0x5f,0x61,0x6f,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x61, + 0x6f,0x2c,0x20,0x28,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64, + 0x2e,0x78,0x79,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x69,0x6e,0x74, + 0x32,0x28,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e,0x67,0x65,0x74,0x5f,0x77,0x69,0x64, + 0x74,0x68,0x28,0x29,0x2c,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e,0x67,0x65,0x74, + 0x5f,0x68,0x65,0x69,0x67,0x68,0x74,0x28,0x29,0x29,0x29,0x29,0x2c,0x20,0x6c,0x65, + 0x76,0x65,0x6c,0x28,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x38,0x35,0x20,0x3d,0x20,0x5f,0x31,0x32, + 0x38,0x34,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37, + 0x30,0x37,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x34,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f, + 0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x32,0x38,0x35,0x2c,0x20,0x5f,0x31,0x32, + 0x38,0x35,0x2c,0x20,0x5f,0x31,0x32,0x38,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x6f,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f,0x39, + 0x37,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x39,0x37,0x37,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x20,0x3d,0x20,0x2d,0x28,0x5f,0x37,0x30,0x37,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a, + 0x20,0x5f,0x31,0x31,0x30,0x31,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x33,0x33,0x33,0x20,0x3d,0x20,0x66,0x61, + 0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37, + 0x30,0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79, + 0x7a,0x20,0x2d,0x20,0x5f,0x39,0x37,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20, + 0x5f,0x39,0x37,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x31,0x33,0x33,0x33, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72, + 0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37,0x30,0x37,0x2e,0x73,0x75,0x6e,0x5f, + 0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x36,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x75,0x6e,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, + 0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x70, + 0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20, + 0x5f,0x37,0x30,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x5f,0x31,0x30,0x39, + 0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65, + 0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76, + 0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x62,0x6f,0x6f,0x6c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73, + 0x2e,0x79,0x20,0x3e,0x20,0x30,0x2e,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20, + 0x5f,0x39,0x37,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x5f,0x31,0x33,0x33, + 0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20,0x5f,0x31,0x30,0x39,0x33,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x34,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69, + 0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f, + 0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e, + 0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65, + 0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x30,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30, + 0x37,0x2e,0x73,0x68,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x37,0x5b,0x31,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e, + 0x73,0x68,0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x37,0x5b,0x32,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68, + 0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x37,0x5b,0x33,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x33, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b, + 0x34,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x34,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x35,0x5d, + 0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x35,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x36,0x5d,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x36,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x37,0x5d,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x37,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x38,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30, + 0x37,0x2e,0x73,0x68,0x5b,0x38,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x5f,0x37, + 0x30,0x37,0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x31,0x32, + 0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x2e,0x77,0x20,0x2a,0x20,0x5f,0x39,0x34,0x33,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x62,0x72,0x64,0x66,0x5f,0x65,0x76, + 0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x39,0x29,0x20,0x2b,0x20,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c, + 0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20,0x74,0x65,0x78,0x5f, + 0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x69,0x62, + 0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66, + 0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, + 0x75,0x74,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x29,0x20,0x2a,0x20, + 0x5f,0x31,0x32,0x38,0x35,0x29,0x29,0x20,0x2a,0x20,0x5f,0x31,0x34,0x31,0x32,0x2c, + 0x20,0x5f,0x31,0x34,0x31,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +static inline const sg_shader_desc* sphere_impostor_shader_desc(sg_backend backend) { + if (backend == SG_BACKEND_GLCORE) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)sphere_vs_source_glsl430; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)sphere_fs_source_glsl430; + desc.fragment_func.entry = "main"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[0].glsl_name = "in_pos"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[0].glsl_uniforms[0].array_count = 4; + desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_frame"; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 560; + desc.uniform_blocks[1].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[0].array_count = 0; + desc.uniform_blocks[1].glsl_uniforms[0].glsl_name = "_707.sun_dir_world"; + desc.uniform_blocks[1].glsl_uniforms[1].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[1].array_count = 0; + desc.uniform_blocks[1].glsl_uniforms[1].glsl_name = "_707.sun_color"; + desc.uniform_blocks[1].glsl_uniforms[2].type = SG_UNIFORMTYPE_INT4; + desc.uniform_blocks[1].glsl_uniforms[2].array_count = 0; + desc.uniform_blocks[1].glsl_uniforms[2].glsl_name = "_707.flags"; + desc.uniform_blocks[1].glsl_uniforms[3].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[3].array_count = 0; + desc.uniform_blocks[1].glsl_uniforms[3].glsl_name = "_707.camera_pos"; + desc.uniform_blocks[1].glsl_uniforms[4].type = SG_UNIFORMTYPE_MAT4; + desc.uniform_blocks[1].glsl_uniforms[4].array_count = 0; + desc.uniform_blocks[1].glsl_uniforms[4].glsl_name = "_707.view_proj"; + desc.uniform_blocks[1].glsl_uniforms[5].type = SG_UNIFORMTYPE_MAT4; + desc.uniform_blocks[1].glsl_uniforms[5].array_count = 0; + desc.uniform_blocks[1].glsl_uniforms[5].glsl_name = "_707.view"; + desc.uniform_blocks[1].glsl_uniforms[6].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[6].array_count = 0; + desc.uniform_blocks[1].glsl_uniforms[6].glsl_name = "_707.cascade_far_view_z"; + desc.uniform_blocks[1].glsl_uniforms[7].type = SG_UNIFORMTYPE_MAT4; + desc.uniform_blocks[1].glsl_uniforms[7].array_count = 3; + desc.uniform_blocks[1].glsl_uniforms[7].glsl_name = "_707.cascade_matrices"; + desc.uniform_blocks[1].glsl_uniforms[8].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[8].array_count = 9; + desc.uniform_blocks[1].glsl_uniforms[8].glsl_name = "_707.sh"; + desc.uniform_blocks[1].glsl_uniforms[9].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[9].array_count = 0; + desc.uniform_blocks[1].glsl_uniforms[9].glsl_name = "_707.ibl_params"; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 16; + desc.uniform_blocks[2].glsl_uniforms[0].type = SG_UNIFORMTYPE_INT4; + desc.uniform_blocks[2].glsl_uniforms[0].array_count = 1; + desc.uniform_blocks[2].glsl_uniforms[0].glsl_name = "ub_draw"; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.glsl_binding_n = 0; + desc.views[1].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[1].texture.image_type = SG_IMAGETYPE_ARRAY; + desc.views[1].texture.sample_type = SG_IMAGESAMPLETYPE_DEPTH; + desc.views[1].texture.multisampled = false; + desc.views[2].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[2].texture.image_type = SG_IMAGETYPE_CUBE; + desc.views[2].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[2].texture.multisampled = false; + desc.views[3].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[3].texture.image_type = SG_IMAGETYPE_2D; + desc.views[3].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[3].texture.multisampled = false; + desc.views[4].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[4].texture.image_type = SG_IMAGETYPE_2D; + desc.views[4].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[4].texture.multisampled = false; + desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_COMPARISON; + desc.samplers[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[1].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[2].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[2].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[3].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[3].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[0].view_slot = 4; + desc.texture_sampler_pairs[0].sampler_slot = 3; + desc.texture_sampler_pairs[0].glsl_name = "tex_ao_smp_ao"; + desc.texture_sampler_pairs[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[1].view_slot = 1; + desc.texture_sampler_pairs[1].sampler_slot = 0; + desc.texture_sampler_pairs[1].glsl_name = "tex_shadow_smp_shadow"; + desc.texture_sampler_pairs[2].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[2].view_slot = 2; + desc.texture_sampler_pairs[2].sampler_slot = 1; + desc.texture_sampler_pairs[2].glsl_name = "tex_ibl_spec_smp_ibl_spec"; + desc.texture_sampler_pairs[3].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[3].view_slot = 3; + desc.texture_sampler_pairs[3].sampler_slot = 2; + desc.texture_sampler_pairs[3].glsl_name = "tex_brdf_lut_smp_brdf_lut"; + desc.label = "sphere_impostor_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_D3D11) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)sphere_vs_source_hlsl5; + desc.vertex_func.d3d11_target = "vs_5_0"; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)sphere_fs_source_hlsl5; + desc.fragment_func.d3d11_target = "ps_5_0"; + desc.fragment_func.entry = "main"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[0].hlsl_sem_name = "TEXCOORD"; + desc.attrs[0].hlsl_sem_index = 0; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].hlsl_register_b_n = 0; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 560; + desc.uniform_blocks[1].hlsl_register_b_n = 1; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 16; + desc.uniform_blocks[2].hlsl_register_b_n = 2; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.hlsl_register_t_n = 0; + desc.views[1].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[1].texture.image_type = SG_IMAGETYPE_ARRAY; + desc.views[1].texture.sample_type = SG_IMAGESAMPLETYPE_DEPTH; + desc.views[1].texture.multisampled = false; + desc.views[1].texture.hlsl_register_t_n = 0; + desc.views[2].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[2].texture.image_type = SG_IMAGETYPE_CUBE; + desc.views[2].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[2].texture.multisampled = false; + desc.views[2].texture.hlsl_register_t_n = 1; + desc.views[3].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[3].texture.image_type = SG_IMAGETYPE_2D; + desc.views[3].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[3].texture.multisampled = false; + desc.views[3].texture.hlsl_register_t_n = 2; + desc.views[4].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[4].texture.image_type = SG_IMAGETYPE_2D; + desc.views[4].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[4].texture.multisampled = false; + desc.views[4].texture.hlsl_register_t_n = 3; + desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_COMPARISON; + desc.samplers[0].hlsl_register_s_n = 0; + desc.samplers[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[1].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[1].hlsl_register_s_n = 1; + desc.samplers[2].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[2].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[2].hlsl_register_s_n = 2; + desc.samplers[3].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[3].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[3].hlsl_register_s_n = 3; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[0].view_slot = 4; + desc.texture_sampler_pairs[0].sampler_slot = 3; + desc.texture_sampler_pairs[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[1].view_slot = 1; + desc.texture_sampler_pairs[1].sampler_slot = 0; + desc.texture_sampler_pairs[2].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[2].view_slot = 2; + desc.texture_sampler_pairs[2].sampler_slot = 1; + desc.texture_sampler_pairs[3].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[3].view_slot = 3; + desc.texture_sampler_pairs[3].sampler_slot = 2; + desc.label = "sphere_impostor_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_METAL_MACOS) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)sphere_vs_source_metal_macos; + desc.vertex_func.entry = "main0"; + desc.fragment_func.source = (const char*)sphere_fs_source_metal_macos; + desc.fragment_func.entry = "main0"; + desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 64; + desc.uniform_blocks[0].msl_buffer_n = 0; + desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[1].size = 560; + desc.uniform_blocks[1].msl_buffer_n = 1; + desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; + desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[2].size = 16; + desc.uniform_blocks[2].msl_buffer_n = 2; + desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; + desc.views[0].storage_buffer.readonly = true; + desc.views[0].storage_buffer.msl_buffer_n = 8; + desc.views[1].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[1].texture.image_type = SG_IMAGETYPE_ARRAY; + desc.views[1].texture.sample_type = SG_IMAGESAMPLETYPE_DEPTH; + desc.views[1].texture.multisampled = false; + desc.views[1].texture.msl_texture_n = 0; + desc.views[2].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[2].texture.image_type = SG_IMAGETYPE_CUBE; + desc.views[2].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[2].texture.multisampled = false; + desc.views[2].texture.msl_texture_n = 1; + desc.views[3].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[3].texture.image_type = SG_IMAGETYPE_2D; + desc.views[3].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[3].texture.multisampled = false; + desc.views[3].texture.msl_texture_n = 2; + desc.views[4].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[4].texture.image_type = SG_IMAGETYPE_2D; + desc.views[4].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[4].texture.multisampled = false; + desc.views[4].texture.msl_texture_n = 3; + desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_COMPARISON; + desc.samplers[0].msl_sampler_n = 0; + desc.samplers[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[1].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[1].msl_sampler_n = 1; + desc.samplers[2].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[2].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[2].msl_sampler_n = 2; + desc.samplers[3].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[3].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[3].msl_sampler_n = 3; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[0].view_slot = 4; + desc.texture_sampler_pairs[0].sampler_slot = 3; + desc.texture_sampler_pairs[1].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[1].view_slot = 1; + desc.texture_sampler_pairs[1].sampler_slot = 0; + desc.texture_sampler_pairs[2].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[2].view_slot = 2; + desc.texture_sampler_pairs[2].sampler_slot = 1; + desc.texture_sampler_pairs[3].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[3].view_slot = 3; + desc.texture_sampler_pairs[3].sampler_slot = 2; + desc.label = "sphere_impostor_shader"; + } + return &desc; + } + return 0; +} diff --git a/samples/shaders/generated/tonemap.glsl.h b/samples/shaders/generated/tonemap.glsl.h new file mode 100644 index 0000000..7e44ca5 --- /dev/null +++ b/samples/shaders/generated/tonemap.glsl.h @@ -0,0 +1,1000 @@ +#pragma once +/* + #version:1# (machine generated, don't edit!) + + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) + + Cmdline: + sokol-shdc --input E:/box/box3d/samples/shaders/post/tonemap.glsl --output E:/box/box3d/samples/shaders/generated/tonemap.glsl.h --slang hlsl5:metal_macos:glsl430 + + Overview: + ========= + Shader program: 'prog': + Get shader desc: tonemap_prog_shader_desc(sg_query_backend()); + Vertex Shader: vs + Fragment Shader: fs + Attributes: + Bindings: + Uniform block 'ub_tonemap': + C struct: tonemap_ub_tonemap_t + Bind slot: UB_tonemap_ub_tonemap => 0 + Texture 'tex_scene': + Image type: SG_IMAGETYPE_2D + Sample type: SG_IMAGESAMPLETYPE_FLOAT + Multisampled: false + Bind slot: VIEW_tonemap_tex_scene => 0 + Sampler 'smp_scene': + Type: SG_SAMPLERTYPE_FILTERING + Bind slot: SMP_tonemap_smp_scene => 0 +*/ +#if !defined(SOKOL_GFX_INCLUDED) +#error "Please include sokol_gfx.h before tonemap.glsl.h" +#endif +#if !defined(SOKOL_SHDC_ALIGN) +#if defined(_MSC_VER) +#define SOKOL_SHDC_ALIGN(a) __declspec(align(a)) +#else +#define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) +#endif +#endif +#define UB_tonemap_ub_tonemap (0) +#define VIEW_tonemap_tex_scene (0) +#define SMP_tonemap_smp_scene (0) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct tonemap_ub_tonemap_t { + Vec4 params; +} tonemap_ub_tonemap_t; +#pragma pack(pop) +/* + #version 430 + + layout(location = 0) out vec2 v_uv; + + void main() + { + vec2 _27 = (vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2)) * 2.0) - vec2(1.0); + v_uv = (_27 * 0.5) + vec2(0.5); + gl_Position = vec4(_27, 0.0, 1.0); + } + +*/ +static const uint8_t tonemap_vs_source_glsl430[240] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x32,0x20,0x76,0x5f,0x75,0x76, + 0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x32,0x37,0x20,0x3d,0x20, + 0x28,0x76,0x65,0x63,0x32,0x28,0x66,0x6c,0x6f,0x61,0x74,0x28,0x28,0x67,0x6c,0x5f, + 0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x44,0x20,0x3c,0x3c,0x20,0x31,0x29,0x20,0x26, + 0x20,0x32,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x67,0x6c,0x5f,0x56,0x65, + 0x72,0x74,0x65,0x78,0x49,0x44,0x20,0x26,0x20,0x32,0x29,0x29,0x20,0x2a,0x20,0x32, + 0x2e,0x30,0x29,0x20,0x2d,0x20,0x76,0x65,0x63,0x32,0x28,0x31,0x2e,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x75,0x76,0x20,0x3d,0x20,0x28,0x5f,0x32,0x37, + 0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x76,0x65,0x63,0x32,0x28,0x30, + 0x2e,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x32,0x37,0x2c, + 0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + +}; +/* + #version 430 + + uniform vec4 ub_tonemap[1]; + layout(binding = 0) uniform sampler2D tex_scene_smp_scene; + + layout(location = 0) in vec2 v_uv; + layout(location = 0) out vec4 out_color; + + vec3 agxDefaultContrastApprox(vec3 x) + { + vec3 _28 = x * x; + vec3 _32 = _28 * _28; + return (((((((_32 * 15.5) * _28) - ((_32 * 40.1399993896484375) * x)) + (_32 * 31.95999908447265625)) - ((_28 * 6.868000030517578125) * x)) + (_28 * 0.4298000037670135498046875)) + (x * 0.119099996984004974365234375)) - vec3(0.002319999970495700836181640625); + } + + vec3 agx(inout vec3 v) + { + v = mat3(vec3(0.842479050159454345703125, 0.0423282422125339508056640625, 0.0423756539821624755859375), vec3(0.0784336030483245849609375, 0.87846863269805908203125, 0.0784336030483245849609375), vec3(0.079223744571208953857421875, 0.07916612923145294189453125, 0.8791429996490478515625)) * v; + v = max(v, vec3(1.0000000133514319600180897396058e-10)); + v = clamp(log2(v), vec3(-12.47393035888671875), vec3(4.026069164276123046875)); + v = (v - vec3(-12.47393035888671875)) * vec3(0.0606060661375522613525390625); + vec3 param = v; + v = agxDefaultContrastApprox(param); + return v; + } + + vec3 agxLook(vec3 v, float saturation) + { + vec3 _133 = vec3(dot(v, vec3(0.2125999927520751953125, 0.715200006961822509765625, 0.072200000286102294921875))); + return _133 + ((v - _133) * saturation); + } + + vec3 agxOutset(vec3 v) + { + return mat3(vec3(1.19687902927398681640625, -0.0528968535363674163818359375, -0.0529716350138187408447265625), vec3(-0.0980208814144134521484375, 1.1519031524658203125, -0.098043449223041534423828125), vec3(-0.099029742181301116943359375, -0.098961174488067626953125, 1.1510736942291259765625)) * v; + } + + void main() + { + float _155; + if (ub_tonemap[0].y > 0.0) + { + _155 = v_uv.y; + } + else + { + _155 = 1.0 - v_uv.y; + } + vec3 param = textureLod(tex_scene_smp_scene, vec2(v_uv.x, _155), 0.0).xyz * pow(2.0, ub_tonemap[0].x); + vec3 _197 = agx(param); + vec3 param_1 = _197; + float param_2 = ub_tonemap[0].z; + vec3 param_3 = agxLook(param_1, param_2); + out_color = vec4(clamp(agxOutset(param_3), vec3(0.0), vec3(1.0)), 1.0); + } + +*/ +static const uint8_t tonemap_fs_source_glsl430[2169] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x75,0x6e, + 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x74,0x6f, + 0x6e,0x65,0x6d,0x61,0x70,0x5b,0x31,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, + 0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x30,0x29,0x20,0x75,0x6e, + 0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20, + 0x74,0x65,0x78,0x5f,0x73,0x63,0x65,0x6e,0x65,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x63, + 0x65,0x6e,0x65,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63, + 0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65, + 0x63,0x32,0x20,0x76,0x5f,0x75,0x76,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28, + 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75, + 0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x3b,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x61,0x67,0x78,0x44,0x65,0x66,0x61,0x75, + 0x6c,0x74,0x43,0x6f,0x6e,0x74,0x72,0x61,0x73,0x74,0x41,0x70,0x70,0x72,0x6f,0x78, + 0x28,0x76,0x65,0x63,0x33,0x20,0x78,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x33,0x20,0x5f,0x32,0x38,0x20,0x3d,0x20,0x78,0x20,0x2a,0x20,0x78,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x33,0x32,0x20,0x3d,0x20, + 0x5f,0x32,0x38,0x20,0x2a,0x20,0x5f,0x32,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x5f,0x33,0x32, + 0x20,0x2a,0x20,0x31,0x35,0x2e,0x35,0x29,0x20,0x2a,0x20,0x5f,0x32,0x38,0x29,0x20, + 0x2d,0x20,0x28,0x28,0x5f,0x33,0x32,0x20,0x2a,0x20,0x34,0x30,0x2e,0x31,0x33,0x39, + 0x39,0x39,0x39,0x33,0x38,0x39,0x36,0x34,0x38,0x34,0x33,0x37,0x35,0x29,0x20,0x2a, + 0x20,0x78,0x29,0x29,0x20,0x2b,0x20,0x28,0x5f,0x33,0x32,0x20,0x2a,0x20,0x33,0x31, + 0x2e,0x39,0x35,0x39,0x39,0x39,0x39,0x30,0x38,0x34,0x34,0x37,0x32,0x36,0x35,0x36, + 0x32,0x35,0x29,0x29,0x20,0x2d,0x20,0x28,0x28,0x5f,0x32,0x38,0x20,0x2a,0x20,0x36, + 0x2e,0x38,0x36,0x38,0x30,0x30,0x30,0x30,0x33,0x30,0x35,0x31,0x37,0x35,0x37,0x38, + 0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x78,0x29,0x29,0x20,0x2b,0x20,0x28,0x5f,0x32, + 0x38,0x20,0x2a,0x20,0x30,0x2e,0x34,0x32,0x39,0x38,0x30,0x30,0x30,0x30,0x33,0x37, + 0x36,0x37,0x30,0x31,0x33,0x35,0x34,0x39,0x38,0x30,0x34,0x36,0x38,0x37,0x35,0x29, + 0x29,0x20,0x2b,0x20,0x28,0x78,0x20,0x2a,0x20,0x30,0x2e,0x31,0x31,0x39,0x30,0x39, + 0x39,0x39,0x39,0x36,0x39,0x38,0x34,0x30,0x30,0x34,0x39,0x37,0x34,0x33,0x36,0x35, + 0x32,0x33,0x34,0x33,0x37,0x35,0x29,0x29,0x20,0x2d,0x20,0x76,0x65,0x63,0x33,0x28, + 0x30,0x2e,0x30,0x30,0x32,0x33,0x31,0x39,0x39,0x39,0x39,0x39,0x37,0x30,0x34,0x39, + 0x35,0x37,0x30,0x30,0x38,0x33,0x36,0x31,0x38,0x31,0x36,0x34,0x30,0x36,0x32,0x35, + 0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x61,0x67,0x78,0x28,0x69, + 0x6e,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x20,0x3d,0x20,0x6d,0x61,0x74,0x33,0x28,0x76,0x65,0x63,0x33, + 0x28,0x30,0x2e,0x38,0x34,0x32,0x34,0x37,0x39,0x30,0x35,0x30,0x31,0x35,0x39,0x34, + 0x35,0x34,0x33,0x34,0x35,0x37,0x30,0x33,0x31,0x32,0x35,0x2c,0x20,0x30,0x2e,0x30, + 0x34,0x32,0x33,0x32,0x38,0x32,0x34,0x32,0x32,0x31,0x32,0x35,0x33,0x33,0x39,0x35, + 0x30,0x38,0x30,0x35,0x36,0x36,0x34,0x30,0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x30, + 0x34,0x32,0x33,0x37,0x35,0x36,0x35,0x33,0x39,0x38,0x32,0x31,0x36,0x32,0x34,0x37, + 0x35,0x35,0x38,0x35,0x39,0x33,0x37,0x35,0x29,0x2c,0x20,0x76,0x65,0x63,0x33,0x28, + 0x30,0x2e,0x30,0x37,0x38,0x34,0x33,0x33,0x36,0x30,0x33,0x30,0x34,0x38,0x33,0x32, + 0x34,0x35,0x38,0x34,0x39,0x36,0x30,0x39,0x33,0x37,0x35,0x2c,0x20,0x30,0x2e,0x38, + 0x37,0x38,0x34,0x36,0x38,0x36,0x33,0x32,0x36,0x39,0x38,0x30,0x35,0x39,0x30,0x38, + 0x32,0x30,0x33,0x31,0x32,0x35,0x2c,0x20,0x30,0x2e,0x30,0x37,0x38,0x34,0x33,0x33, + 0x36,0x30,0x33,0x30,0x34,0x38,0x33,0x32,0x34,0x35,0x38,0x34,0x39,0x36,0x30,0x39, + 0x33,0x37,0x35,0x29,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x37,0x39, + 0x32,0x32,0x33,0x37,0x34,0x34,0x35,0x37,0x31,0x32,0x30,0x38,0x39,0x35,0x33,0x38, + 0x35,0x37,0x34,0x32,0x31,0x38,0x37,0x35,0x2c,0x20,0x30,0x2e,0x30,0x37,0x39,0x31, + 0x36,0x36,0x31,0x32,0x39,0x32,0x33,0x31,0x34,0x35,0x32,0x39,0x34,0x31,0x38,0x39, + 0x34,0x35,0x33,0x31,0x32,0x35,0x2c,0x20,0x30,0x2e,0x38,0x37,0x39,0x31,0x34,0x32, + 0x39,0x39,0x39,0x36,0x34,0x39,0x30,0x34,0x37,0x38,0x35,0x31,0x35,0x36,0x32,0x35, + 0x29,0x29,0x20,0x2a,0x20,0x76,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x20,0x3d,0x20, + 0x6d,0x61,0x78,0x28,0x76,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x30, + 0x30,0x30,0x30,0x30,0x30,0x31,0x33,0x33,0x35,0x31,0x34,0x33,0x31,0x39,0x36,0x30, + 0x30,0x31,0x38,0x30,0x38,0x39,0x37,0x33,0x39,0x36,0x30,0x35,0x38,0x65,0x2d,0x31, + 0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x20,0x3d,0x20,0x63,0x6c,0x61, + 0x6d,0x70,0x28,0x6c,0x6f,0x67,0x32,0x28,0x76,0x29,0x2c,0x20,0x76,0x65,0x63,0x33, + 0x28,0x2d,0x31,0x32,0x2e,0x34,0x37,0x33,0x39,0x33,0x30,0x33,0x35,0x38,0x38,0x38, + 0x36,0x37,0x31,0x38,0x37,0x35,0x29,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x34,0x2e, + 0x30,0x32,0x36,0x30,0x36,0x39,0x31,0x36,0x34,0x32,0x37,0x36,0x31,0x32,0x33,0x30, + 0x34,0x36,0x38,0x37,0x35,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x20,0x3d, + 0x20,0x28,0x76,0x20,0x2d,0x20,0x76,0x65,0x63,0x33,0x28,0x2d,0x31,0x32,0x2e,0x34, + 0x37,0x33,0x39,0x33,0x30,0x33,0x35,0x38,0x38,0x38,0x36,0x37,0x31,0x38,0x37,0x35, + 0x29,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x36,0x30,0x36, + 0x30,0x36,0x30,0x36,0x36,0x31,0x33,0x37,0x35,0x35,0x32,0x32,0x36,0x31,0x33,0x35, + 0x32,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x76,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x20,0x3d,0x20,0x61,0x67,0x78,0x44,0x65,0x66,0x61,0x75,0x6c, + 0x74,0x43,0x6f,0x6e,0x74,0x72,0x61,0x73,0x74,0x41,0x70,0x70,0x72,0x6f,0x78,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x76,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x61,0x67, + 0x78,0x4c,0x6f,0x6f,0x6b,0x28,0x76,0x65,0x63,0x33,0x20,0x76,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x73,0x61,0x74,0x75,0x72,0x61,0x74,0x69,0x6f,0x6e,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x33,0x33,0x20, + 0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x64,0x6f,0x74,0x28,0x76,0x2c,0x20,0x76,0x65, + 0x63,0x33,0x28,0x30,0x2e,0x32,0x31,0x32,0x35,0x39,0x39,0x39,0x39,0x32,0x37,0x35, + 0x32,0x30,0x37,0x35,0x31,0x39,0x35,0x33,0x31,0x32,0x35,0x2c,0x20,0x30,0x2e,0x37, + 0x31,0x35,0x32,0x30,0x30,0x30,0x30,0x36,0x39,0x36,0x31,0x38,0x32,0x32,0x35,0x30, + 0x39,0x37,0x36,0x35,0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x30,0x37,0x32,0x32,0x30, + 0x30,0x30,0x30,0x30,0x32,0x38,0x36,0x31,0x30,0x32,0x32,0x39,0x34,0x39,0x32,0x31, + 0x38,0x37,0x35,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x5f,0x31,0x33,0x33,0x20,0x2b,0x20,0x28,0x28,0x76,0x20,0x2d,0x20, + 0x5f,0x31,0x33,0x33,0x29,0x20,0x2a,0x20,0x73,0x61,0x74,0x75,0x72,0x61,0x74,0x69, + 0x6f,0x6e,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x61,0x67,0x78, + 0x4f,0x75,0x74,0x73,0x65,0x74,0x28,0x76,0x65,0x63,0x33,0x20,0x76,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6d,0x61,0x74,0x33, + 0x28,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x31,0x39,0x36,0x38,0x37,0x39,0x30,0x32, + 0x39,0x32,0x37,0x33,0x39,0x38,0x36,0x38,0x31,0x36,0x34,0x30,0x36,0x32,0x35,0x2c, + 0x20,0x2d,0x30,0x2e,0x30,0x35,0x32,0x38,0x39,0x36,0x38,0x35,0x33,0x35,0x33,0x36, + 0x33,0x36,0x37,0x34,0x31,0x36,0x33,0x38,0x31,0x38,0x33,0x35,0x39,0x33,0x37,0x35, + 0x2c,0x20,0x2d,0x30,0x2e,0x30,0x35,0x32,0x39,0x37,0x31,0x36,0x33,0x35,0x30,0x31, + 0x33,0x38,0x31,0x38,0x37,0x34,0x30,0x38,0x34,0x34,0x37,0x32,0x36,0x35,0x36,0x32, + 0x35,0x29,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x2d,0x30,0x2e,0x30,0x39,0x38,0x30, + 0x32,0x30,0x38,0x38,0x31,0x34,0x31,0x34,0x34,0x31,0x33,0x34,0x35,0x32,0x31,0x34, + 0x38,0x34,0x33,0x37,0x35,0x2c,0x20,0x31,0x2e,0x31,0x35,0x31,0x39,0x30,0x33,0x31, + 0x35,0x32,0x34,0x36,0x35,0x38,0x32,0x30,0x33,0x31,0x32,0x35,0x2c,0x20,0x2d,0x30, + 0x2e,0x30,0x39,0x38,0x30,0x34,0x33,0x34,0x34,0x39,0x32,0x32,0x33,0x30,0x34,0x31, + 0x35,0x33,0x34,0x34,0x32,0x33,0x38,0x32,0x38,0x31,0x32,0x35,0x29,0x2c,0x20,0x76, + 0x65,0x63,0x33,0x28,0x2d,0x30,0x2e,0x30,0x39,0x39,0x30,0x32,0x39,0x37,0x34,0x32, + 0x31,0x38,0x31,0x33,0x30,0x31,0x31,0x31,0x36,0x39,0x34,0x33,0x33,0x35,0x39,0x33, + 0x37,0x35,0x2c,0x20,0x2d,0x30,0x2e,0x30,0x39,0x38,0x39,0x36,0x31,0x31,0x37,0x34, + 0x34,0x38,0x38,0x30,0x36,0x37,0x36,0x32,0x36,0x39,0x35,0x33,0x31,0x32,0x35,0x2c, + 0x20,0x31,0x2e,0x31,0x35,0x31,0x30,0x37,0x33,0x36,0x39,0x34,0x32,0x32,0x39,0x31, + 0x32,0x35,0x39,0x37,0x36,0x35,0x36,0x32,0x35,0x29,0x29,0x20,0x2a,0x20,0x76,0x3b, + 0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x35, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x75,0x62,0x5f,0x74,0x6f,0x6e, + 0x65,0x6d,0x61,0x70,0x5b,0x30,0x5d,0x2e,0x79,0x20,0x3e,0x20,0x30,0x2e,0x30,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f, + 0x31,0x35,0x35,0x20,0x3d,0x20,0x76,0x5f,0x75,0x76,0x2e,0x79,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x35,0x35,0x20, + 0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x76,0x5f,0x75,0x76,0x2e,0x79,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x4c,0x6f, + 0x64,0x28,0x74,0x65,0x78,0x5f,0x73,0x63,0x65,0x6e,0x65,0x5f,0x73,0x6d,0x70,0x5f, + 0x73,0x63,0x65,0x6e,0x65,0x2c,0x20,0x76,0x65,0x63,0x32,0x28,0x76,0x5f,0x75,0x76, + 0x2e,0x78,0x2c,0x20,0x5f,0x31,0x35,0x35,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x2e, + 0x78,0x79,0x7a,0x20,0x2a,0x20,0x70,0x6f,0x77,0x28,0x32,0x2e,0x30,0x2c,0x20,0x75, + 0x62,0x5f,0x74,0x6f,0x6e,0x65,0x6d,0x61,0x70,0x5b,0x30,0x5d,0x2e,0x78,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x39,0x37,0x20,0x3d, + 0x20,0x61,0x67,0x78,0x28,0x70,0x61,0x72,0x61,0x6d,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20, + 0x5f,0x31,0x39,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x75,0x62,0x5f,0x74,0x6f,0x6e, + 0x65,0x6d,0x61,0x70,0x5b,0x30,0x5d,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x61,0x67, + 0x78,0x4c,0x6f,0x6f,0x6b,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x63,0x6c, + 0x61,0x6d,0x70,0x28,0x61,0x67,0x78,0x4f,0x75,0x74,0x73,0x65,0x74,0x28,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x29,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30, + 0x29,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x29,0x2c,0x20,0x31, + 0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + static float4 gl_Position; + static int gl_VertexIndex; + static float2 v_uv; + + struct SPIRV_Cross_Input + { + uint gl_VertexIndex : SV_VertexID; + }; + + struct SPIRV_Cross_Output + { + float2 v_uv : TEXCOORD0; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + float2 _27 = (float2(float((gl_VertexIndex << 1) & 2), float(gl_VertexIndex & 2)) * 2.0f) - 1.0f.xx; + v_uv = (_27 * 0.5f) + 0.5f.xx; + gl_Position = float4(_27, 0.0f, 1.0f); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_VertexIndex = int(stage_input.gl_VertexIndex); + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.v_uv = v_uv; + return stage_output; + } +*/ +static const uint8_t tonemap_vs_source_hlsl5[716] = { + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c, + 0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69, + 0x63,0x20,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49, + 0x6e,0x64,0x65,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x32,0x20,0x76,0x5f,0x75,0x76,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63, + 0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e, + 0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x67, + 0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x3a,0x20, + 0x53,0x56,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x44,0x3b,0x0a,0x7d,0x3b,0x0a, + 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, + 0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x76,0x5f,0x75,0x76,0x20,0x3a,0x20,0x54, + 0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e, + 0x20,0x3a,0x20,0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a, + 0x7d,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61, + 0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x32,0x20,0x5f,0x32,0x37,0x20,0x3d,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28, + 0x66,0x6c,0x6f,0x61,0x74,0x28,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78, + 0x49,0x6e,0x64,0x65,0x78,0x20,0x3c,0x3c,0x20,0x31,0x29,0x20,0x26,0x20,0x32,0x29, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65, + 0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x26,0x20,0x32,0x29,0x29,0x20,0x2a,0x20,0x32, + 0x2e,0x30,0x66,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x5f,0x75,0x76,0x20,0x3d,0x20,0x28,0x5f,0x32,0x37,0x20, + 0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2e,0x78, + 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69, + 0x6f,0x6e,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x32,0x37,0x2c, + 0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74, + 0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, + 0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65, + 0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c, + 0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x3d,0x20,0x69, + 0x6e,0x74,0x28,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x67, + 0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73, + 0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75, + 0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f, + 0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69, + 0x6f,0x6e,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70, + 0x75,0x74,0x2e,0x76,0x5f,0x75,0x76,0x20,0x3d,0x20,0x76,0x5f,0x75,0x76,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65, + 0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + cbuffer ub_tonemap : register(b0) + { + float4 _144_params : packoffset(c0); + }; + + Texture2D tex_scene : register(t0); + SamplerState smp_scene : register(s0); + + static float2 v_uv; + static float4 out_color; + + struct SPIRV_Cross_Input + { + float2 v_uv : TEXCOORD0; + }; + + struct SPIRV_Cross_Output + { + float4 out_color : SV_Target0; + }; + + float3 agxDefaultContrastApprox(float3 x) + { + float3 _28 = x * x; + float3 _32 = _28 * _28; + return (((((((_32 * 15.5f) * _28) - ((_32 * 40.1399993896484375f) * x)) + (_32 * 31.95999908447265625f)) - ((_28 * 6.868000030517578125f) * x)) + (_28 * 0.4298000037670135498046875f)) + (x * 0.119099996984004974365234375f)) - 0.002319999970495700836181640625f.xxx; + } + + float3 agx(inout float3 v) + { + v = mul(v, float3x3(float3(0.842479050159454345703125f, 0.0423282422125339508056640625f, 0.0423756539821624755859375f), float3(0.0784336030483245849609375f, 0.87846863269805908203125f, 0.0784336030483245849609375f), float3(0.079223744571208953857421875f, 0.07916612923145294189453125f, 0.8791429996490478515625f))); + v = max(v, 1.0000000133514319600180897396058e-10f.xxx); + v = clamp(log2(v), (-12.47393035888671875f).xxx, 4.026069164276123046875f.xxx); + v = (v - (-12.47393035888671875f).xxx) * 0.0606060661375522613525390625f.xxx; + float3 param = v; + v = agxDefaultContrastApprox(param); + return v; + } + + float3 agxLook(float3 v, float saturation) + { + float3 _133 = dot(v, float3(0.2125999927520751953125f, 0.715200006961822509765625f, 0.072200000286102294921875f)).xxx; + return _133 + ((v - _133) * saturation); + } + + float3 agxOutset(float3 v) + { + return mul(v, float3x3(float3(1.19687902927398681640625f, -0.0528968535363674163818359375f, -0.0529716350138187408447265625f), float3(-0.0980208814144134521484375f, 1.1519031524658203125f, -0.098043449223041534423828125f), float3(-0.099029742181301116943359375f, -0.098961174488067626953125f, 1.1510736942291259765625f))); + } + + void frag_main() + { + float _155; + if (_144_params.y > 0.0f) + { + _155 = v_uv.y; + } + else + { + _155 = 1.0f - v_uv.y; + } + float3 param = tex_scene.SampleLevel(smp_scene, float2(v_uv.x, _155), 0.0f).xyz * pow(2.0f, _144_params.x); + float3 _197 = agx(param); + float3 param_1 = _197; + float param_2 = _144_params.z; + float3 param_3 = agxLook(param_1, param_2); + out_color = float4(clamp(agxOutset(param_3), 0.0f.xxx, 1.0f.xxx), 1.0f); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + v_uv = stage_input.v_uv; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.out_color = out_color; + return stage_output; + } +*/ +static const uint8_t tonemap_fs_source_hlsl5[2627] = { + 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x74,0x6f,0x6e,0x65,0x6d, + 0x61,0x70,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x30, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f, + 0x31,0x34,0x34,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x20,0x3a,0x20,0x70,0x61,0x63, + 0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x7d,0x3b,0x0a, + 0x0a,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x63,0x65,0x6e,0x65,0x20,0x3a,0x20,0x72, + 0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x30,0x29,0x3b,0x0a,0x53,0x61,0x6d, + 0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x73,0x63, + 0x65,0x6e,0x65,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73, + 0x30,0x29,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x32,0x20,0x76,0x5f,0x75,0x76,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f, + 0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x76,0x5f,0x75,0x76,0x20,0x3a,0x20, + 0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73, + 0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73, + 0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20, + 0x3a,0x20,0x53,0x56,0x5f,0x54,0x61,0x72,0x67,0x65,0x74,0x30,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x61,0x67,0x78,0x44,0x65,0x66,0x61, + 0x75,0x6c,0x74,0x43,0x6f,0x6e,0x74,0x72,0x61,0x73,0x74,0x41,0x70,0x70,0x72,0x6f, + 0x78,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x78,0x29,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x32,0x38,0x20,0x3d,0x20,0x78, + 0x20,0x2a,0x20,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x5f,0x33,0x32,0x20,0x3d,0x20,0x5f,0x32,0x38,0x20,0x2a,0x20,0x5f,0x32,0x38, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28, + 0x28,0x28,0x28,0x28,0x5f,0x33,0x32,0x20,0x2a,0x20,0x31,0x35,0x2e,0x35,0x66,0x29, + 0x20,0x2a,0x20,0x5f,0x32,0x38,0x29,0x20,0x2d,0x20,0x28,0x28,0x5f,0x33,0x32,0x20, + 0x2a,0x20,0x34,0x30,0x2e,0x31,0x33,0x39,0x39,0x39,0x39,0x33,0x38,0x39,0x36,0x34, + 0x38,0x34,0x33,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x78,0x29,0x29,0x20,0x2b,0x20, + 0x28,0x5f,0x33,0x32,0x20,0x2a,0x20,0x33,0x31,0x2e,0x39,0x35,0x39,0x39,0x39,0x39, + 0x30,0x38,0x34,0x34,0x37,0x32,0x36,0x35,0x36,0x32,0x35,0x66,0x29,0x29,0x20,0x2d, + 0x20,0x28,0x28,0x5f,0x32,0x38,0x20,0x2a,0x20,0x36,0x2e,0x38,0x36,0x38,0x30,0x30, + 0x30,0x30,0x33,0x30,0x35,0x31,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x66,0x29,0x20, + 0x2a,0x20,0x78,0x29,0x29,0x20,0x2b,0x20,0x28,0x5f,0x32,0x38,0x20,0x2a,0x20,0x30, + 0x2e,0x34,0x32,0x39,0x38,0x30,0x30,0x30,0x30,0x33,0x37,0x36,0x37,0x30,0x31,0x33, + 0x35,0x34,0x39,0x38,0x30,0x34,0x36,0x38,0x37,0x35,0x66,0x29,0x29,0x20,0x2b,0x20, + 0x28,0x78,0x20,0x2a,0x20,0x30,0x2e,0x31,0x31,0x39,0x30,0x39,0x39,0x39,0x39,0x36, + 0x39,0x38,0x34,0x30,0x30,0x34,0x39,0x37,0x34,0x33,0x36,0x35,0x32,0x33,0x34,0x33, + 0x37,0x35,0x66,0x29,0x29,0x20,0x2d,0x20,0x30,0x2e,0x30,0x30,0x32,0x33,0x31,0x39, + 0x39,0x39,0x39,0x39,0x37,0x30,0x34,0x39,0x35,0x37,0x30,0x30,0x38,0x33,0x36,0x31, + 0x38,0x31,0x36,0x34,0x30,0x36,0x32,0x35,0x66,0x2e,0x78,0x78,0x78,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x61,0x67,0x78,0x28,0x69,0x6e,0x6f, + 0x75,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x76,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x78,0x33,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e, + 0x38,0x34,0x32,0x34,0x37,0x39,0x30,0x35,0x30,0x31,0x35,0x39,0x34,0x35,0x34,0x33, + 0x34,0x35,0x37,0x30,0x33,0x31,0x32,0x35,0x66,0x2c,0x20,0x30,0x2e,0x30,0x34,0x32, + 0x33,0x32,0x38,0x32,0x34,0x32,0x32,0x31,0x32,0x35,0x33,0x33,0x39,0x35,0x30,0x38, + 0x30,0x35,0x36,0x36,0x34,0x30,0x36,0x32,0x35,0x66,0x2c,0x20,0x30,0x2e,0x30,0x34, + 0x32,0x33,0x37,0x35,0x36,0x35,0x33,0x39,0x38,0x32,0x31,0x36,0x32,0x34,0x37,0x35, + 0x35,0x38,0x35,0x39,0x33,0x37,0x35,0x66,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x28,0x30,0x2e,0x30,0x37,0x38,0x34,0x33,0x33,0x36,0x30,0x33,0x30,0x34,0x38, + 0x33,0x32,0x34,0x35,0x38,0x34,0x39,0x36,0x30,0x39,0x33,0x37,0x35,0x66,0x2c,0x20, + 0x30,0x2e,0x38,0x37,0x38,0x34,0x36,0x38,0x36,0x33,0x32,0x36,0x39,0x38,0x30,0x35, + 0x39,0x30,0x38,0x32,0x30,0x33,0x31,0x32,0x35,0x66,0x2c,0x20,0x30,0x2e,0x30,0x37, + 0x38,0x34,0x33,0x33,0x36,0x30,0x33,0x30,0x34,0x38,0x33,0x32,0x34,0x35,0x38,0x34, + 0x39,0x36,0x30,0x39,0x33,0x37,0x35,0x66,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x28,0x30,0x2e,0x30,0x37,0x39,0x32,0x32,0x33,0x37,0x34,0x34,0x35,0x37,0x31, + 0x32,0x30,0x38,0x39,0x35,0x33,0x38,0x35,0x37,0x34,0x32,0x31,0x38,0x37,0x35,0x66, + 0x2c,0x20,0x30,0x2e,0x30,0x37,0x39,0x31,0x36,0x36,0x31,0x32,0x39,0x32,0x33,0x31, + 0x34,0x35,0x32,0x39,0x34,0x31,0x38,0x39,0x34,0x35,0x33,0x31,0x32,0x35,0x66,0x2c, + 0x20,0x30,0x2e,0x38,0x37,0x39,0x31,0x34,0x32,0x39,0x39,0x39,0x36,0x34,0x39,0x30, + 0x34,0x37,0x38,0x35,0x31,0x35,0x36,0x32,0x35,0x66,0x29,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x76,0x2c,0x20,0x31,0x2e, + 0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x33,0x33,0x35,0x31,0x34,0x33,0x31,0x39, + 0x36,0x30,0x30,0x31,0x38,0x30,0x38,0x39,0x37,0x33,0x39,0x36,0x30,0x35,0x38,0x65, + 0x2d,0x31,0x30,0x66,0x2e,0x78,0x78,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6c,0x6f,0x67,0x32,0x28,0x76,0x29, + 0x2c,0x20,0x28,0x2d,0x31,0x32,0x2e,0x34,0x37,0x33,0x39,0x33,0x30,0x33,0x35,0x38, + 0x38,0x38,0x36,0x37,0x31,0x38,0x37,0x35,0x66,0x29,0x2e,0x78,0x78,0x78,0x2c,0x20, + 0x34,0x2e,0x30,0x32,0x36,0x30,0x36,0x39,0x31,0x36,0x34,0x32,0x37,0x36,0x31,0x32, + 0x33,0x30,0x34,0x36,0x38,0x37,0x35,0x66,0x2e,0x78,0x78,0x78,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x20,0x3d,0x20,0x28,0x76,0x20,0x2d,0x20,0x28,0x2d,0x31,0x32, + 0x2e,0x34,0x37,0x33,0x39,0x33,0x30,0x33,0x35,0x38,0x38,0x38,0x36,0x37,0x31,0x38, + 0x37,0x35,0x66,0x29,0x2e,0x78,0x78,0x78,0x29,0x20,0x2a,0x20,0x30,0x2e,0x30,0x36, + 0x30,0x36,0x30,0x36,0x30,0x36,0x36,0x31,0x33,0x37,0x35,0x35,0x32,0x32,0x36,0x31, + 0x33,0x35,0x32,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x2e,0x78,0x78,0x78,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x20,0x3d,0x20,0x76,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x20,0x3d,0x20,0x61, + 0x67,0x78,0x44,0x65,0x66,0x61,0x75,0x6c,0x74,0x43,0x6f,0x6e,0x74,0x72,0x61,0x73, + 0x74,0x41,0x70,0x70,0x72,0x6f,0x78,0x28,0x70,0x61,0x72,0x61,0x6d,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x76,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x61,0x67,0x78,0x4c,0x6f,0x6f,0x6b,0x28, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x73,0x61,0x74,0x75,0x72,0x61,0x74,0x69,0x6f,0x6e,0x29,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x33,0x33,0x20,0x3d,0x20, + 0x64,0x6f,0x74,0x28,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e, + 0x32,0x31,0x32,0x35,0x39,0x39,0x39,0x39,0x32,0x37,0x35,0x32,0x30,0x37,0x35,0x31, + 0x39,0x35,0x33,0x31,0x32,0x35,0x66,0x2c,0x20,0x30,0x2e,0x37,0x31,0x35,0x32,0x30, + 0x30,0x30,0x30,0x36,0x39,0x36,0x31,0x38,0x32,0x32,0x35,0x30,0x39,0x37,0x36,0x35, + 0x36,0x32,0x35,0x66,0x2c,0x20,0x30,0x2e,0x30,0x37,0x32,0x32,0x30,0x30,0x30,0x30, + 0x30,0x32,0x38,0x36,0x31,0x30,0x32,0x32,0x39,0x34,0x39,0x32,0x31,0x38,0x37,0x35, + 0x66,0x29,0x29,0x2e,0x78,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x5f,0x31,0x33,0x33,0x20,0x2b,0x20,0x28,0x28,0x76,0x20,0x2d, + 0x20,0x5f,0x31,0x33,0x33,0x29,0x20,0x2a,0x20,0x73,0x61,0x74,0x75,0x72,0x61,0x74, + 0x69,0x6f,0x6e,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x61,0x67,0x78,0x4f,0x75,0x74,0x73,0x65,0x74,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x76,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x6d,0x75,0x6c,0x28,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x78,0x33, + 0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x31,0x39,0x36,0x38,0x37,0x39, + 0x30,0x32,0x39,0x32,0x37,0x33,0x39,0x38,0x36,0x38,0x31,0x36,0x34,0x30,0x36,0x32, + 0x35,0x66,0x2c,0x20,0x2d,0x30,0x2e,0x30,0x35,0x32,0x38,0x39,0x36,0x38,0x35,0x33, + 0x35,0x33,0x36,0x33,0x36,0x37,0x34,0x31,0x36,0x33,0x38,0x31,0x38,0x33,0x35,0x39, + 0x33,0x37,0x35,0x66,0x2c,0x20,0x2d,0x30,0x2e,0x30,0x35,0x32,0x39,0x37,0x31,0x36, + 0x33,0x35,0x30,0x31,0x33,0x38,0x31,0x38,0x37,0x34,0x30,0x38,0x34,0x34,0x37,0x32, + 0x36,0x35,0x36,0x32,0x35,0x66,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, + 0x2d,0x30,0x2e,0x30,0x39,0x38,0x30,0x32,0x30,0x38,0x38,0x31,0x34,0x31,0x34,0x34, + 0x31,0x33,0x34,0x35,0x32,0x31,0x34,0x38,0x34,0x33,0x37,0x35,0x66,0x2c,0x20,0x31, + 0x2e,0x31,0x35,0x31,0x39,0x30,0x33,0x31,0x35,0x32,0x34,0x36,0x35,0x38,0x32,0x30, + 0x33,0x31,0x32,0x35,0x66,0x2c,0x20,0x2d,0x30,0x2e,0x30,0x39,0x38,0x30,0x34,0x33, + 0x34,0x34,0x39,0x32,0x32,0x33,0x30,0x34,0x31,0x35,0x33,0x34,0x34,0x32,0x33,0x38, + 0x32,0x38,0x31,0x32,0x35,0x66,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, + 0x2d,0x30,0x2e,0x30,0x39,0x39,0x30,0x32,0x39,0x37,0x34,0x32,0x31,0x38,0x31,0x33, + 0x30,0x31,0x31,0x31,0x36,0x39,0x34,0x33,0x33,0x35,0x39,0x33,0x37,0x35,0x66,0x2c, + 0x20,0x2d,0x30,0x2e,0x30,0x39,0x38,0x39,0x36,0x31,0x31,0x37,0x34,0x34,0x38,0x38, + 0x30,0x36,0x37,0x36,0x32,0x36,0x39,0x35,0x33,0x31,0x32,0x35,0x66,0x2c,0x20,0x31, + 0x2e,0x31,0x35,0x31,0x30,0x37,0x33,0x36,0x39,0x34,0x32,0x32,0x39,0x31,0x32,0x35, + 0x39,0x37,0x36,0x35,0x36,0x32,0x35,0x66,0x29,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a, + 0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35, + 0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x34,0x34,0x5f, + 0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x20,0x3e,0x20,0x30,0x2e,0x30,0x66,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f, + 0x31,0x35,0x35,0x20,0x3d,0x20,0x76,0x5f,0x75,0x76,0x2e,0x79,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x35,0x35,0x20, + 0x3d,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x76,0x5f,0x75,0x76,0x2e,0x79,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x73,0x63, + 0x65,0x6e,0x65,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x4c,0x65,0x76,0x65,0x6c,0x28, + 0x73,0x6d,0x70,0x5f,0x73,0x63,0x65,0x6e,0x65,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x32,0x28,0x76,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x35,0x35,0x29,0x2c, + 0x20,0x30,0x2e,0x30,0x66,0x29,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x70,0x6f,0x77, + 0x28,0x32,0x2e,0x30,0x66,0x2c,0x20,0x5f,0x31,0x34,0x34,0x5f,0x70,0x61,0x72,0x61, + 0x6d,0x73,0x2e,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x5f,0x31,0x39,0x37,0x20,0x3d,0x20,0x61,0x67,0x78,0x28,0x70,0x61,0x72, + 0x61,0x6d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x31,0x39,0x37,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x20,0x3d,0x20,0x5f,0x31,0x34,0x34,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e, + 0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x61,0x67,0x78,0x4c,0x6f,0x6f,0x6b,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x63,0x6c,0x61,0x6d,0x70,0x28, + 0x61,0x67,0x78,0x4f,0x75,0x74,0x73,0x65,0x74,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2c,0x20,0x31,0x2e, + 0x30,0x66,0x2e,0x78,0x78,0x78,0x29,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f, + 0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56, + 0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x5f,0x75,0x76,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70, + 0x75,0x74,0x2e,0x76,0x5f,0x75,0x76,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61, + 0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50, + 0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74, + 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e, + 0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x6f,0x75,0x74,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a, + 0x7d,0x0a,0x00, +}; +/* + #include + #include + + using namespace metal; + + struct main0_out + { + float2 v_uv [[user(locn0)]]; + float4 gl_Position [[position]]; + }; + + vertex main0_out main0(uint gl_VertexIndex [[vertex_id]]) + { + main0_out out = {}; + float2 _27 = (float2(float((int(gl_VertexIndex) << 1) & 2), float(int(gl_VertexIndex) & 2)) * 2.0) - float2(1.0); + out.v_uv = (_27 * 0.5) + float2(0.5); + out.gl_Position = float4(_27, 0.0, 1.0); + return out; + } + +*/ +static const uint8_t tonemap_vs_source_metal_macos[474] = { + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d, + 0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x32,0x20,0x76,0x5f,0x75,0x76,0x20,0x5b,0x5b,0x75,0x73,0x65, + 0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69, + 0x6f,0x6e,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x3b, + 0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,0x65,0x78,0x20,0x6d,0x61,0x69,0x6e, + 0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x75,0x69,0x6e,0x74, + 0x20,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20, + 0x5b,0x5b,0x76,0x65,0x72,0x74,0x65,0x78,0x5f,0x69,0x64,0x5d,0x5d,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f, + 0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x32,0x20,0x5f,0x32,0x37,0x20,0x3d,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74, + 0x32,0x28,0x66,0x6c,0x6f,0x61,0x74,0x28,0x28,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f, + 0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x3c,0x3c,0x20, + 0x31,0x29,0x20,0x26,0x20,0x32,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x69, + 0x6e,0x74,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65, + 0x78,0x29,0x20,0x26,0x20,0x32,0x29,0x29,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x20, + 0x2d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x75,0x76,0x20,0x3d,0x20,0x28,0x5f, + 0x32,0x37,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x32,0x28,0x30,0x2e,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, + 0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x32,0x37,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20, + 0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +/* + #pragma clang diagnostic ignored "-Wmissing-prototypes" + + #include + #include + + using namespace metal; + + struct ub_tonemap + { + float4 params; + }; + + struct main0_out + { + float4 out_color [[color(0)]]; + }; + + struct main0_in + { + float2 v_uv [[user(locn0)]]; + }; + + static inline __attribute__((always_inline)) + float3 agxDefaultContrastApprox(thread const float3& x) + { + float3 _28 = x * x; + float3 _32 = _28 * _28; + return (((((((_32 * 15.5) * _28) - ((_32 * 40.1399993896484375) * x)) + (_32 * 31.95999908447265625)) - ((_28 * 6.868000030517578125) * x)) + (_28 * 0.4298000037670135498046875)) + (x * 0.119099996984004974365234375)) - float3(0.002319999970495700836181640625); + } + + static inline __attribute__((always_inline)) + float3 agx(thread float3& v) + { + v = float3x3(float3(0.842479050159454345703125, 0.0423282422125339508056640625, 0.0423756539821624755859375), float3(0.0784336030483245849609375, 0.87846863269805908203125, 0.0784336030483245849609375), float3(0.079223744571208953857421875, 0.07916612923145294189453125, 0.8791429996490478515625)) * v; + v = fast::max(v, float3(1.0000000133514319600180897396058e-10)); + v = fast::clamp(log2(v), float3(-12.47393035888671875), float3(4.026069164276123046875)); + v = (v - float3(-12.47393035888671875)) * float3(0.0606060661375522613525390625); + float3 param = v; + v = agxDefaultContrastApprox(param); + return v; + } + + static inline __attribute__((always_inline)) + float3 agxLook(thread const float3& v, thread const float& saturation) + { + float3 _133 = float3(dot(v, float3(0.2125999927520751953125, 0.715200006961822509765625, 0.072200000286102294921875))); + return _133 + ((v - _133) * saturation); + } + + static inline __attribute__((always_inline)) + float3 agxOutset(thread const float3& v) + { + return float3x3(float3(1.19687902927398681640625, -0.0528968535363674163818359375, -0.0529716350138187408447265625), float3(-0.0980208814144134521484375, 1.1519031524658203125, -0.098043449223041534423828125), float3(-0.099029742181301116943359375, -0.098961174488067626953125, 1.1510736942291259765625)) * v; + } + + fragment main0_out main0(main0_in in [[stage_in]], constant ub_tonemap& _144 [[buffer(0)]], texture2d tex_scene [[texture(0)]], sampler smp_scene [[sampler(0)]]) + { + main0_out out = {}; + float _155; + if (_144.params.y > 0.0) + { + _155 = in.v_uv.y; + } + else + { + _155 = 1.0 - in.v_uv.y; + } + float3 param = tex_scene.sample(smp_scene, float2(in.v_uv.x, _155), level(0.0)).xyz * powr(2.0, _144.params.x); + float3 _197 = agx(param); + float3 param_1 = _197; + float param_2 = _144.params.z; + float3 param_3 = agxLook(param_1, param_2); + out.out_color = float4(fast::clamp(agxOutset(param_3), float3(0.0), float3(1.0)), 1.0); + return out; + } + +*/ +static const uint8_t tonemap_fs_source_metal_macos[2815] = { + 0x23,0x70,0x72,0x61,0x67,0x6d,0x61,0x20,0x63,0x6c,0x61,0x6e,0x67,0x20,0x64,0x69, + 0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x20,0x69,0x67,0x6e,0x6f,0x72,0x65,0x64, + 0x20,0x22,0x2d,0x57,0x6d,0x69,0x73,0x73,0x69,0x6e,0x67,0x2d,0x70,0x72,0x6f,0x74, + 0x6f,0x74,0x79,0x70,0x65,0x73,0x22,0x0a,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64, + 0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f,0x73,0x74,0x64,0x6c,0x69,0x62,0x3e, + 0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f, + 0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a,0x75,0x73,0x69,0x6e,0x67,0x20,0x6e, + 0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20,0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a, + 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x74,0x6f,0x6e,0x65,0x6d, + 0x61,0x70,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75, + 0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29,0x5d,0x5d, + 0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69, + 0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x32,0x20,0x76,0x5f,0x75,0x76,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c, + 0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x61, + 0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74, + 0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73, + 0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x61,0x67,0x78,0x44,0x65,0x66,0x61,0x75,0x6c,0x74,0x43,0x6f,0x6e,0x74,0x72, + 0x61,0x73,0x74,0x41,0x70,0x70,0x72,0x6f,0x78,0x28,0x74,0x68,0x72,0x65,0x61,0x64, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x78, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f, + 0x32,0x38,0x20,0x3d,0x20,0x78,0x20,0x2a,0x20,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x33,0x32,0x20,0x3d,0x20,0x5f,0x32,0x38, + 0x20,0x2a,0x20,0x5f,0x32,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x5f,0x33,0x32,0x20,0x2a,0x20, + 0x31,0x35,0x2e,0x35,0x29,0x20,0x2a,0x20,0x5f,0x32,0x38,0x29,0x20,0x2d,0x20,0x28, + 0x28,0x5f,0x33,0x32,0x20,0x2a,0x20,0x34,0x30,0x2e,0x31,0x33,0x39,0x39,0x39,0x39, + 0x33,0x38,0x39,0x36,0x34,0x38,0x34,0x33,0x37,0x35,0x29,0x20,0x2a,0x20,0x78,0x29, + 0x29,0x20,0x2b,0x20,0x28,0x5f,0x33,0x32,0x20,0x2a,0x20,0x33,0x31,0x2e,0x39,0x35, + 0x39,0x39,0x39,0x39,0x30,0x38,0x34,0x34,0x37,0x32,0x36,0x35,0x36,0x32,0x35,0x29, + 0x29,0x20,0x2d,0x20,0x28,0x28,0x5f,0x32,0x38,0x20,0x2a,0x20,0x36,0x2e,0x38,0x36, + 0x38,0x30,0x30,0x30,0x30,0x33,0x30,0x35,0x31,0x37,0x35,0x37,0x38,0x31,0x32,0x35, + 0x29,0x20,0x2a,0x20,0x78,0x29,0x29,0x20,0x2b,0x20,0x28,0x5f,0x32,0x38,0x20,0x2a, + 0x20,0x30,0x2e,0x34,0x32,0x39,0x38,0x30,0x30,0x30,0x30,0x33,0x37,0x36,0x37,0x30, + 0x31,0x33,0x35,0x34,0x39,0x38,0x30,0x34,0x36,0x38,0x37,0x35,0x29,0x29,0x20,0x2b, + 0x20,0x28,0x78,0x20,0x2a,0x20,0x30,0x2e,0x31,0x31,0x39,0x30,0x39,0x39,0x39,0x39, + 0x36,0x39,0x38,0x34,0x30,0x30,0x34,0x39,0x37,0x34,0x33,0x36,0x35,0x32,0x33,0x34, + 0x33,0x37,0x35,0x29,0x29,0x20,0x2d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30, + 0x2e,0x30,0x30,0x32,0x33,0x31,0x39,0x39,0x39,0x39,0x39,0x37,0x30,0x34,0x39,0x35, + 0x37,0x30,0x30,0x38,0x33,0x36,0x31,0x38,0x31,0x36,0x34,0x30,0x36,0x32,0x35,0x29, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69, + 0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f, + 0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29, + 0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x61,0x67,0x78,0x28,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x76,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x78, + 0x33,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x38,0x34,0x32,0x34,0x37, + 0x39,0x30,0x35,0x30,0x31,0x35,0x39,0x34,0x35,0x34,0x33,0x34,0x35,0x37,0x30,0x33, + 0x31,0x32,0x35,0x2c,0x20,0x30,0x2e,0x30,0x34,0x32,0x33,0x32,0x38,0x32,0x34,0x32, + 0x32,0x31,0x32,0x35,0x33,0x33,0x39,0x35,0x30,0x38,0x30,0x35,0x36,0x36,0x34,0x30, + 0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x30,0x34,0x32,0x33,0x37,0x35,0x36,0x35,0x33, + 0x39,0x38,0x32,0x31,0x36,0x32,0x34,0x37,0x35,0x35,0x38,0x35,0x39,0x33,0x37,0x35, + 0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x37,0x38,0x34, + 0x33,0x33,0x36,0x30,0x33,0x30,0x34,0x38,0x33,0x32,0x34,0x35,0x38,0x34,0x39,0x36, + 0x30,0x39,0x33,0x37,0x35,0x2c,0x20,0x30,0x2e,0x38,0x37,0x38,0x34,0x36,0x38,0x36, + 0x33,0x32,0x36,0x39,0x38,0x30,0x35,0x39,0x30,0x38,0x32,0x30,0x33,0x31,0x32,0x35, + 0x2c,0x20,0x30,0x2e,0x30,0x37,0x38,0x34,0x33,0x33,0x36,0x30,0x33,0x30,0x34,0x38, + 0x33,0x32,0x34,0x35,0x38,0x34,0x39,0x36,0x30,0x39,0x33,0x37,0x35,0x29,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x37,0x39,0x32,0x32,0x33,0x37, + 0x34,0x34,0x35,0x37,0x31,0x32,0x30,0x38,0x39,0x35,0x33,0x38,0x35,0x37,0x34,0x32, + 0x31,0x38,0x37,0x35,0x2c,0x20,0x30,0x2e,0x30,0x37,0x39,0x31,0x36,0x36,0x31,0x32, + 0x39,0x32,0x33,0x31,0x34,0x35,0x32,0x39,0x34,0x31,0x38,0x39,0x34,0x35,0x33,0x31, + 0x32,0x35,0x2c,0x20,0x30,0x2e,0x38,0x37,0x39,0x31,0x34,0x32,0x39,0x39,0x39,0x36, + 0x34,0x39,0x30,0x34,0x37,0x38,0x35,0x31,0x35,0x36,0x32,0x35,0x29,0x29,0x20,0x2a, + 0x20,0x76,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x20,0x3d,0x20,0x66,0x61,0x73,0x74, + 0x3a,0x3a,0x6d,0x61,0x78,0x28,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, + 0x31,0x2e,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x33,0x33,0x35,0x31,0x34,0x33, + 0x31,0x39,0x36,0x30,0x30,0x31,0x38,0x30,0x38,0x39,0x37,0x33,0x39,0x36,0x30,0x35, + 0x38,0x65,0x2d,0x31,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x20,0x3d, + 0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6c,0x6f,0x67, + 0x32,0x28,0x76,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x2d,0x31,0x32, + 0x2e,0x34,0x37,0x33,0x39,0x33,0x30,0x33,0x35,0x38,0x38,0x38,0x36,0x37,0x31,0x38, + 0x37,0x35,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x34,0x2e,0x30,0x32, + 0x36,0x30,0x36,0x39,0x31,0x36,0x34,0x32,0x37,0x36,0x31,0x32,0x33,0x30,0x34,0x36, + 0x38,0x37,0x35,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x20,0x3d,0x20,0x28, + 0x76,0x20,0x2d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x2d,0x31,0x32,0x2e,0x34, + 0x37,0x33,0x39,0x33,0x30,0x33,0x35,0x38,0x38,0x38,0x36,0x37,0x31,0x38,0x37,0x35, + 0x29,0x29,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x36, + 0x30,0x36,0x30,0x36,0x30,0x36,0x36,0x31,0x33,0x37,0x35,0x35,0x32,0x32,0x36,0x31, + 0x33,0x35,0x32,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20, + 0x76,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x20,0x3d,0x20,0x61,0x67,0x78,0x44,0x65, + 0x66,0x61,0x75,0x6c,0x74,0x43,0x6f,0x6e,0x74,0x72,0x61,0x73,0x74,0x41,0x70,0x70, + 0x72,0x6f,0x78,0x28,0x70,0x61,0x72,0x61,0x6d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x76,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61, + 0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74, + 0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73, + 0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x61,0x67,0x78,0x4c,0x6f,0x6f,0x6b,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20, + 0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x76,0x2c, + 0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x26,0x20,0x73,0x61,0x74,0x75,0x72,0x61,0x74,0x69,0x6f,0x6e,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31, + 0x33,0x33,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x64,0x6f,0x74,0x28, + 0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x32,0x31,0x32,0x35, + 0x39,0x39,0x39,0x39,0x32,0x37,0x35,0x32,0x30,0x37,0x35,0x31,0x39,0x35,0x33,0x31, + 0x32,0x35,0x2c,0x20,0x30,0x2e,0x37,0x31,0x35,0x32,0x30,0x30,0x30,0x30,0x36,0x39, + 0x36,0x31,0x38,0x32,0x32,0x35,0x30,0x39,0x37,0x36,0x35,0x36,0x32,0x35,0x2c,0x20, + 0x30,0x2e,0x30,0x37,0x32,0x32,0x30,0x30,0x30,0x30,0x30,0x32,0x38,0x36,0x31,0x30, + 0x32,0x32,0x39,0x34,0x39,0x32,0x31,0x38,0x37,0x35,0x29,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x33,0x33,0x20,0x2b, + 0x20,0x28,0x28,0x76,0x20,0x2d,0x20,0x5f,0x31,0x33,0x33,0x29,0x20,0x2a,0x20,0x73, + 0x61,0x74,0x75,0x72,0x61,0x74,0x69,0x6f,0x6e,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73, + 0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61, + 0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61, + 0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x61,0x67,0x78,0x4f,0x75,0x74,0x73,0x65,0x74,0x28,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x26,0x20,0x76,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x78,0x33,0x28,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x28,0x31,0x2e,0x31,0x39,0x36,0x38,0x37,0x39,0x30,0x32,0x39,0x32,0x37,0x33, + 0x39,0x38,0x36,0x38,0x31,0x36,0x34,0x30,0x36,0x32,0x35,0x2c,0x20,0x2d,0x30,0x2e, + 0x30,0x35,0x32,0x38,0x39,0x36,0x38,0x35,0x33,0x35,0x33,0x36,0x33,0x36,0x37,0x34, + 0x31,0x36,0x33,0x38,0x31,0x38,0x33,0x35,0x39,0x33,0x37,0x35,0x2c,0x20,0x2d,0x30, + 0x2e,0x30,0x35,0x32,0x39,0x37,0x31,0x36,0x33,0x35,0x30,0x31,0x33,0x38,0x31,0x38, + 0x37,0x34,0x30,0x38,0x34,0x34,0x37,0x32,0x36,0x35,0x36,0x32,0x35,0x29,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x2d,0x30,0x2e,0x30,0x39,0x38,0x30,0x32,0x30, + 0x38,0x38,0x31,0x34,0x31,0x34,0x34,0x31,0x33,0x34,0x35,0x32,0x31,0x34,0x38,0x34, + 0x33,0x37,0x35,0x2c,0x20,0x31,0x2e,0x31,0x35,0x31,0x39,0x30,0x33,0x31,0x35,0x32, + 0x34,0x36,0x35,0x38,0x32,0x30,0x33,0x31,0x32,0x35,0x2c,0x20,0x2d,0x30,0x2e,0x30, + 0x39,0x38,0x30,0x34,0x33,0x34,0x34,0x39,0x32,0x32,0x33,0x30,0x34,0x31,0x35,0x33, + 0x34,0x34,0x32,0x33,0x38,0x32,0x38,0x31,0x32,0x35,0x29,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x28,0x2d,0x30,0x2e,0x30,0x39,0x39,0x30,0x32,0x39,0x37,0x34,0x32, + 0x31,0x38,0x31,0x33,0x30,0x31,0x31,0x31,0x36,0x39,0x34,0x33,0x33,0x35,0x39,0x33, + 0x37,0x35,0x2c,0x20,0x2d,0x30,0x2e,0x30,0x39,0x38,0x39,0x36,0x31,0x31,0x37,0x34, + 0x34,0x38,0x38,0x30,0x36,0x37,0x36,0x32,0x36,0x39,0x35,0x33,0x31,0x32,0x35,0x2c, + 0x20,0x31,0x2e,0x31,0x35,0x31,0x30,0x37,0x33,0x36,0x39,0x34,0x32,0x32,0x39,0x31, + 0x32,0x35,0x39,0x37,0x36,0x35,0x36,0x32,0x35,0x29,0x29,0x20,0x2a,0x20,0x76,0x3b, + 0x0a,0x7d,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x20,0x6d,0x61,0x69, + 0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69, + 0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65, + 0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20, + 0x75,0x62,0x5f,0x74,0x6f,0x6e,0x65,0x6d,0x61,0x70,0x26,0x20,0x5f,0x31,0x34,0x34, + 0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20, + 0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e, + 0x20,0x74,0x65,0x78,0x5f,0x73,0x63,0x65,0x6e,0x65,0x20,0x5b,0x5b,0x74,0x65,0x78, + 0x74,0x75,0x72,0x65,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x63,0x65,0x6e,0x65,0x20,0x5b,0x5b,0x73, + 0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74, + 0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x35,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, + 0x31,0x34,0x34,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x20,0x3e,0x20,0x30, + 0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x5f,0x31,0x35,0x35,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x75,0x76, + 0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c, + 0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x5f,0x31,0x35,0x35,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x69,0x6e, + 0x2e,0x76,0x5f,0x75,0x76,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20, + 0x3d,0x20,0x74,0x65,0x78,0x5f,0x73,0x63,0x65,0x6e,0x65,0x2e,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x63,0x65,0x6e,0x65,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x32,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20, + 0x5f,0x31,0x35,0x35,0x29,0x2c,0x20,0x6c,0x65,0x76,0x65,0x6c,0x28,0x30,0x2e,0x30, + 0x29,0x29,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x70,0x6f,0x77,0x72,0x28,0x32,0x2e, + 0x30,0x2c,0x20,0x5f,0x31,0x34,0x34,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31, + 0x39,0x37,0x20,0x3d,0x20,0x61,0x67,0x78,0x28,0x70,0x61,0x72,0x61,0x6d,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x31,0x39,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20, + 0x5f,0x31,0x34,0x34,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x7a,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x20,0x3d,0x20,0x61,0x67,0x78,0x4c,0x6f,0x6f,0x6b,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a, + 0x63,0x6c,0x61,0x6d,0x70,0x28,0x61,0x67,0x78,0x4f,0x75,0x74,0x73,0x65,0x74,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x28,0x30,0x2e,0x30,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e, + 0x30,0x29,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +static inline const sg_shader_desc* tonemap_prog_shader_desc(sg_backend backend) { + if (backend == SG_BACKEND_GLCORE) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)tonemap_vs_source_glsl430; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)tonemap_fs_source_glsl430; + desc.fragment_func.entry = "main"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 16; + desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[0].glsl_uniforms[0].array_count = 1; + desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_tonemap"; + desc.views[0].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[0].texture.image_type = SG_IMAGETYPE_2D; + desc.views[0].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[0].texture.multisampled = false; + desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[0].view_slot = 0; + desc.texture_sampler_pairs[0].sampler_slot = 0; + desc.texture_sampler_pairs[0].glsl_name = "tex_scene_smp_scene"; + desc.label = "tonemap_prog_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_D3D11) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)tonemap_vs_source_hlsl5; + desc.vertex_func.d3d11_target = "vs_5_0"; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)tonemap_fs_source_hlsl5; + desc.fragment_func.d3d11_target = "ps_5_0"; + desc.fragment_func.entry = "main"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 16; + desc.uniform_blocks[0].hlsl_register_b_n = 0; + desc.views[0].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[0].texture.image_type = SG_IMAGETYPE_2D; + desc.views[0].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[0].texture.multisampled = false; + desc.views[0].texture.hlsl_register_t_n = 0; + desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[0].hlsl_register_s_n = 0; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[0].view_slot = 0; + desc.texture_sampler_pairs[0].sampler_slot = 0; + desc.label = "tonemap_prog_shader"; + } + return &desc; + } + if (backend == SG_BACKEND_METAL_MACOS) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.vertex_func.source = (const char*)tonemap_vs_source_metal_macos; + desc.vertex_func.entry = "main0"; + desc.fragment_func.source = (const char*)tonemap_fs_source_metal_macos; + desc.fragment_func.entry = "main0"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 16; + desc.uniform_blocks[0].msl_buffer_n = 0; + desc.views[0].texture.stage = SG_SHADERSTAGE_FRAGMENT; + desc.views[0].texture.image_type = SG_IMAGETYPE_2D; + desc.views[0].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.views[0].texture.multisampled = false; + desc.views[0].texture.msl_texture_n = 0; + desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.samplers[0].msl_sampler_n = 0; + desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.texture_sampler_pairs[0].view_slot = 0; + desc.texture_sampler_pairs[0].sampler_slot = 0; + desc.label = "tonemap_prog_shader"; + } + return &desc; + } + return 0; +} diff --git a/samples/shaders/ibl/brdf_lut.glsl b/samples/shaders/ibl/brdf_lut.glsl new file mode 100644 index 0000000..3f2c6e8 --- /dev/null +++ b/samples/shaders/ibl/brdf_lut.glsl @@ -0,0 +1,144 @@ +// BRDF integration LUT (Karis 2013 split-sum, environment term). +// +// Output is RG16F at 256^2. R = scale, G = bias for the split-sum approx: +// integrated_specular = prefiltered_env(R(N,V), roughness) * (F0 * lut.r + lut.g) +// where lut is sampled at (n_dot_v, roughness). Generated once at boot, +// independent of sun, environment, and view. +// +// The integral is importance-sampled GGX over 1024 Hammersley samples per +// pixel. Heavy for a single fragment, but it runs once and into +// a 256^2 target so the total cost is bounded (~67M iterations). The result +// is environment-independent, it stays valid for the lifetime of the +// renderer. +// +// VS sets v_uv to the SAMPLE-time UV that addresses this pixel's content, +// not the raw NDC-derived UV. sokol-shdc does NOT normalize render-target +// V orientation across backends: on GL a fragment at NDC.y=+1 stores at +// the texture row that sampling at V=1 returns, on D3D11/Metal/WGPU the +// same fragment stores at the row that sampling at V=0 returns. The FS +// uses v_uv.y as the integration roughness, so for sampling at +// (n_dot_v, roughness) to round-trip we flip via a backend-conditional +// uvYSign (+1 GL, -1 D3D11/Metal/WGPU). Same pattern as gtao.glsl / +// cube.glsl's cascade_far_view_z.w. + +#pragma sokol @module brdf_lut + +#pragma sokol @ctype vec4 Vec4 + +#pragma sokol @vs vs + +layout(binding = 0)uniform ub_brdf +{ + // .x = uvYSign (+1 GL, -1 D3D11/Metal/WGPU) + vec4 params; +}; + +out vec2 v_uv; + +void main() +{ + vec2 ndc = vec2(float((gl_VertexIndex << 1)& 2), + float(gl_VertexIndex & 2)) * 2.0 - 1.0; + v_uv = vec2(ndc.x * 0.5 + 0.5, 0.5 + ndc.y * 0.5 * params.x); + gl_Position = vec4(ndc, 0.0, 1.0); +} +#pragma sokol @end + +#pragma sokol @fs fs + +in vec2 v_uv; +out vec2 out_color; + +const float BRDF_LUT_PI = 3.14159265358979323846; +const uint NUM_SAMPLES = 1024u; + +// Van der Corput radical inverse, bit-reverse trick for low-discrepancy +// sequences. Together with the index, gives a Hammersley sample on [0,1)^2. +float radicalInverseVdC(uint bits) +{ + bits = (bits << 16u)|(bits >> 16u); + bits = ((bits & 0x55555555u) << 1u)|((bits & 0xAAAAAAAAu) >> 1u); + bits = ((bits & 0x33333333u) << 2u)|((bits & 0xCCCCCCCCu) >> 2u); + bits = ((bits & 0x0F0F0F0Fu) << 4u)|((bits & 0xF0F0F0F0u) >> 4u); + bits = ((bits & 0x00FF00FFu) << 8u)|((bits & 0xFF00FF00u) >> 8u); + return float(bits) * 2.3283064365386963e-10; +} + +vec2 hammersley(uint i, uint n) +{ + return vec2(float(i) / float(n), radicalInverseVdC(i)); +} + +// GGX importance sampling, returns a microfacet half-vector H in tangent +// space (z-up). For BRDF integration N = (0,0,1) so tangent = world space. +vec3 importanceSampleGGX(vec2 Xi, float alpha) +{ + float a2 = alpha * alpha; + float phi = 2.0 * BRDF_LUT_PI * Xi.x; + float cos_theta = sqrt((1.0 - Xi.y) / (1.0 + (a2 - 1.0) * Xi.y)); + float sin_theta = sqrt(max(1.0 - cos_theta * cos_theta, 0.0)); + return vec3(sin_theta * cos(phi), sin_theta * sin(phi), cos_theta); +} + +// Smith G with Karis' IBL remap: k = a^2/2 (rather than (a+1)^2/8 used for +// direct lighting). This is the form that pairs correctly with importance- +// sampled GGX integration. +float smithGggxIbl(float n_dot_v, float n_dot_l, float alpha) +{ + float k = (alpha * alpha) * 0.5; + float gv = n_dot_v / (n_dot_v * (1.0 - k) + k); + float gl = n_dot_l / (n_dot_l * (1.0 - k) + k); + return gv * gl; +} + +vec2 integrateBRDF(float n_dot_v, float roughness) +{ + // V is in the (x,z) plane with N = +Z. n_dot_v fully determines it. + vec3 V = vec3(sqrt(max(1.0 - n_dot_v * n_dot_v, 0.0)), 0.0, n_dot_v); + + float A = 0.0; + float B = 0.0; + float alpha = roughness * roughness; + + for (uint i = 0u; i < NUM_SAMPLES; ++i) + { + vec2 Xi = hammersley(i, NUM_SAMPLES); + vec3 H = importanceSampleGGX(Xi, alpha); + vec3 L = 2.0 * dot(V, H) * H - V; + + float n_dot_l = max(L.z, 0.0); + float n_dot_h = max(H.z, 0.0); + float v_dot_h = max(dot(V, H), 0.0); + + if (n_dot_l > 0.0) + { + float G = smithGggxIbl(n_dot_v, n_dot_l, alpha); + + // pdf-cancelled visibility: G * v_dot_h / (n_dot_h * n_dot_v). + float G_Vis = (G * v_dot_h) / max(n_dot_h * n_dot_v, 1.0e-5); + + // max(0, ...): v_dot_h is max -clamped to [0, inf) above but + // unit-vector drift could in principle push it just over 1. + // Wrap to dodge HLSL's pow(negative, n) warning (X3571). + float Fc = pow(max(0.0, 1.0 - v_dot_h), 5.0); + + A += (1.0 - Fc) * G_Vis; + B += Fc * G_Vis; + } + } + + return vec2(A, B) / float(NUM_SAMPLES); +} + +void main() +{ + // v_uv ranges over [0.5/N, (N-0.5)/N] across the LUT, never touches 0 + // or 1 exactly, which keeps the integration well-defined at the + // (n_dot_v=0, roughness=0) corner. + float n_dot_v = max(v_uv.x, 1.0e-3); + float roughness = max(v_uv.y, 1.0e-3); + out_color = integrateBRDF(n_dot_v, roughness); +} +#pragma sokol @end + +#pragma sokol @program build vs fs diff --git a/samples/shaders/ibl/prefilter.glsl b/samples/shaders/ibl/prefilter.glsl new file mode 100644 index 0000000..35c573a --- /dev/null +++ b/samples/shaders/ibl/prefilter.glsl @@ -0,0 +1,128 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// GGX prefilter fills the radiance mip chain of the IBL specular +// cubemap from the raw Preetham sky cube produced by sky_to_cube.glsl. +// +// One draw per face per mip. The C side passes the destination face's +// (right, up, forward) basis and the target mip's roughness. The FS +// importance-samples the GGX lobe centered on N (the per-pixel face +// direction), reads the input cube, and accumulates n.l-weighted +// radiance. Karis split-sum convention: assume V = N (acceptable for +// IBL, the lost direction-dependence becomes part of the BRDF LUT). +// +// At roughness 0 (mirror, mip 0) the GGX lobe collapses to a delta and +// we read the input cube directly. This both speeds up mip 0 and avoids +// the artefact of GGX importance sampling returning a numerically +// imprecise direction near the singularity. +// +// @module prefilter prefixes the generated typedefs so this header +// coexists in ibl.c alongside brdf_lut.glsl.h and sky_to_cube.glsl.h. + +#pragma sokol @module prefilter + +#pragma sokol @ctype vec4 Vec4 + +#pragma sokol @vs vs + +out vec2 v_uv; + +void main() +{ + vec2 ndc = vec2(float((gl_VertexIndex << 1) & 2), + float(gl_VertexIndex & 2)) * 2.0 - 1.0; + v_uv = ndc * 0.5 + 0.5; + gl_Position = vec4(ndc, 0.0, 1.0); +} +#pragma sokol @end + +#pragma sokol @fs fs + +layout(binding = 0) uniform ub_pass +{ + vec4 face_right; // .xyz = world-space face right axis + vec4 face_up; // .xyz = world-space face up axis + vec4 face_forward; // .xyz = world-space face forward axis + vec4 params; // .x = roughness in [0,1], .yzw = unused +}; + +// Input is the unprefiltered sky cube. Filtering sampler with linear +// mips. Although we sample LOD 0 here, the trilinear filter still +// kicks in on the texel-level lookup. +#pragma sokol @image_sample_type tex_sky float +layout(binding = 0)uniform textureCube tex_sky; +#pragma sokol @sampler_type smp_sky filtering +layout(binding = 0)uniform sampler smp_sky; + +in vec2 v_uv; +out vec4 out_color; + +const float PREFILTER_PI = 3.14159265358979323846; +const uint NUM_SAMPLES = 1024u; + +float radicalInverseVdC(uint bits) +{ + bits = (bits << 16u)|(bits >> 16u); + bits = ((bits & 0x55555555u) << 1u)|((bits & 0xAAAAAAAAu) >> 1u); + bits = ((bits & 0x33333333u) << 2u)|((bits & 0xCCCCCCCCu) >> 2u); + bits = ((bits & 0x0F0F0F0Fu) << 4u)|((bits & 0xF0F0F0F0u) >> 4u); + bits = ((bits & 0x00FF00FFu) << 8u)|((bits & 0xFF00FF00u) >> 8u); + return float(bits) * 2.3283064365386963e-10; +} + +vec2 hammersley(uint i, uint n) +{ + return vec2(float(i) / float(n), radicalInverseVdC(i)); +} + +vec3 importanceSampleGGX(vec2 Xi, vec3 N, float roughness) +{ + float a = roughness * roughness; + float phi = 2.0 * PREFILTER_PI * Xi.x; + float cos_theta = sqrt((1.0 - Xi.y) / (1.0 + (a * a - 1.0) * Xi.y)); + float sin_theta = sqrt(max(1.0 - cos_theta * cos_theta, 0.0)); + + vec3 H_tan = vec3(sin_theta * cos(phi), sin_theta * sin(phi), cos_theta); + + // Build an orthonormal basis around N. + vec3 up = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0); + vec3 tangent = normalize(cross(up, N)); + vec3 bitan = cross(N, tangent); + + return normalize(tangent * H_tan.x + bitan * H_tan.y + N * H_tan.z); +} + +void main() +{ + vec2 uv = v_uv * 2.0 - 1.0; + vec3 N = normalize(face_forward.xyz + uv.x * face_right.xyz + uv.y * face_up.xyz); + vec3 V = N; // Karis split-sum, assume V = N + + float roughness = params.x; + if (roughness < 0.001) + { + // Mirror: GGX lobe is a delta, just sample the input direction. + out_color = vec4(texture(samplerCube(tex_sky, smp_sky), N).rgb, 1.0); + return; + } + + vec3 prefiltered = vec3(0.0); + float total_w = 0.0; + + for(uint i = 0u; i < NUM_SAMPLES; ++i) + { + vec2 Xi = hammersley(i, NUM_SAMPLES); + vec3 H = importanceSampleGGX(Xi, N, roughness); + vec3 L = normalize(2.0 * dot(V, H) * H - V); + float n_dot_l = max(dot(N, L), 0.0); + if (n_dot_l > 0.0) + { + prefiltered += texture(samplerCube(tex_sky, smp_sky), L).rgb * n_dot_l; + total_w += n_dot_l; + } + } + out_color = vec4(prefiltered / max(total_w, 1.0e-4), 1.0); +} +#pragma sokol @end + +#pragma sokol @program build vs fs diff --git a/samples/shaders/ibl/sky.glsl b/samples/shaders/ibl/sky.glsl new file mode 100644 index 0000000..d9f88f5 --- /dev/null +++ b/samples/shaders/ibl/sky.glsl @@ -0,0 +1,103 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Procedural sky: Preetham/Shirley/Smits 1999 analytic daylight. +// +// Drawn as a fullscreen triangle inside the main lit pass, AFTER all opaque +// shapes, with depth test GREATER_EQUAL against the reverse-Z far plane +// (clear value = 0). NDC z = 0 puts the triangle at the far plane, opaque +// fragments wrote z > 0 (closer in reverse-Z), so GREATER_EQUAL discards +// the sky there and keeps it on untouched pixels. Depth write is disabled, +// the sky is "infinitely far" and shouldn't write to z. +// +// View-ray reconstruction. VS unprojects each fullscreen-triangle vertex +// to homogeneous world coordinates via inv_view_proj and forwards them +// undivided. All three vertices have gl_Position.w = 1, so perspective- +// correct interpolation degenerates to linear interp, and matrix linearity +// means the interpolated v_world_homog at a fragment equals inv_view_proj +// times that fragment's NDC point exactly. FS divides by w and subtracts +// the camera position to get the world-space view direction. +// +// Below-horizon handling. Preetham is invalid for sun elevations near and +// below the horizon. The renderer C side computes a smoothstep fade weight +// between sin(2 deg) and sin(5 deg) and passes it as sun_dir_world.w, the FS +// just multiplies the output by it. preethamSky in common/preetham.glsl +// clamps its inputs to the upper hemisphere internally to keep the math +// finite while the fade weight drives the output to zero. +// +// Output is linear sRGB radiance, scaled by an empirical luminance factor +// chosen to land near the target sun:sky ratio (~8-15:1) under the +// renderer's sun_color premultiplied-by-pi convention. + +#pragma sokol @ctype mat4 Mat4 +#pragma sokol @ctype vec4 Vec4 +#pragma sokol @ctype vec3 b3Vec3 + +#pragma sokol @vs vs + +// Per-shader UBO name prefix (sky_*) to keep sokol-shdc's generated typedefs +// disjoint from cube.glsl.h's unprefixed ub_frame_t / ub_pass_t, both +// headers are included from src/gfx/renderer.c. +layout(binding = 0) uniform sky_ub_frame +{ + mat4 inv_view_proj; +}; + +out vec4 v_world_homog; // inv_view_proj * (ndc, 0, 1), undivided + +void main() +{ + // Standard fullscreen-triangle trick: 3 vertices cover the NDC square + // and 25% extra outside, which the rasterizer clips. Avoids the + // two-triangle seam-discontinuity that a quad has at its diagonal. + // vert 0 -> (-1, -1) + // vert 1 -> ( 3, -1) + // vert 2 -> (-1, 3). + vec2 ndc = vec2(float((gl_VertexIndex << 1) & 2), float(gl_VertexIndex & 2)) * 2.0 - 1.0; + + // NDC z = 0 -> reverse-Z far plane. Depth test GREATER_EQUAL passes + // against the cleared depth of 0 on untouched pixels and fails on any + // opaque pixel (whose depth is > 0 in reverse-Z). + vec4 clip = vec4(ndc, 0.0, 1.0); + gl_Position = clip; + + v_world_homog = inv_view_proj * clip; +} +#pragma sokol @end + +#pragma sokol @fs fs + +#pragma sokol @include ../common/preetham.glsl + +layout(binding = 1)uniform sky_ub_pass +{ + vec4 sun_dir_world; // .xyz = world dir TO sun (normalized), .w = below-horizon fade weight [0,1] + vec4 sky_params; // .x = turbidity (Preetham T), .yzw = reserved + vec4 camera_pos; // .xyz = world camera position, .w = unused +}; + +in vec4 v_world_homog; +out vec4 out_color; + +void main() +{ + // World-space view direction at this fragment. + vec3 world_pos = v_world_homog.xyz / v_world_homog.w; + vec3 view_dir = normalize(world_pos - camera_pos.xyz); + + // Renormalize the sun defensively. Caller is the renderer with + // sun.dirToSun already normalized, but an undetected zero vector + // here would emit NaNs. + vec3 sun_dir = normalize(sun_dir_world.xyz); + + // Empirical luminance scale + below-horizon fade live in + // preethamSkyScaled so the IBL sky cubemap (sky_to_cube.glsl) sees + // the same backdrop. Fade weight comes from the C side via + // sun_dir_world.w (1 above horizon, 0 below). + vec3 rgb = preethamSkyScaled(view_dir, sun_dir, sky_params.x, sun_dir_world.w); + + out_color = vec4(rgb, 1.0); +} +#pragma sokol @end + +#pragma sokol @program sky vs fs diff --git a/samples/shaders/ibl/sky_to_cube.glsl b/samples/shaders/ibl/sky_to_cube.glsl new file mode 100644 index 0000000..b4cc20a --- /dev/null +++ b/samples/shaders/ibl/sky_to_cube.glsl @@ -0,0 +1,70 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Sky cubemap renderer. +// +// Fills one face of a 6xN^2 RGBA16F cubemap per draw with the Preetham +// analytic daylight model. The C side runs six passes (one per face) +// when the sun direction or turbidity changes, the resulting cubemap +// becomes both the diffuse-irradiance source (via SH projection on the +// CPU) and the input to the GGX prefilter pass. +// +// Direction reconstruction. Each draw receives a per-face mat3 basis +// (right, up, forward). The FS computes a world-space direction from +// the fragment's v_uv in [0,1]^2 as +// dir = normalize(forward + (2*v_uv.x - 1) * right + (2*v_uv.y - 1) * up) +// The basis vectors are filled C-side to match the GL cubemap sampling +// convention (which sokol abstracts uniformly across backends), so a +// direction d written here is recovered by sampling the cubemap with +// the same d. + +// @module sky_to_cube prefixes the generated typedefs (struct, slot +// enum, static byte arrays) so this header coexists in ibl.c with +// brdf_lut.glsl.h and prefilter.glsl.h without collisions. + +#pragma sokol @module sky_to_cube + +#pragma sokol @ctype vec4 Vec4 + +#pragma sokol @vs vs + +out vec2 v_uv; + +void main() +{ + vec2 ndc = vec2(float((gl_VertexIndex << 1) & 2), + float(gl_VertexIndex & 2)) * 2.0 - 1.0; + v_uv = ndc * 0.5 + 0.5; + gl_Position = vec4(ndc, 0.0, 1.0); +} +#pragma sokol @end + +#pragma sokol @fs fs + +#pragma sokol @include ../common/preetham.glsl + +layout(binding = 0)uniform ub_face +{ + // Three rows of a mat3 basis. Stored as vec4 for std140 alignment, + // .xyz are the axis vectors, .w is unused (.w on face_forward + // doubles as the below-horizon fade weight to save a UBO slot). + vec4 face_right; // .xyz = world-space face right axis + vec4 face_up; // .xyz = world-space face up axis + vec4 face_forward; // .xyz = world-space face forward axis, .w = fade weight + vec4 sun_dir_world; // .xyz = world-space direction TO sun, .w = turbidity +}; + +in vec2 v_uv; +out vec4 out_color; + +void main() +{ + vec2 uv = v_uv * 2.0 - 1.0; // [-1, +1] across the face + vec3 dir = normalize(face_forward.xyz + uv.x * face_right.xyz + uv.y * face_up.xyz); + + vec3 rgb = preethamSkyScaled(dir, sun_dir_world.xyz, sun_dir_world.w, face_forward.w); + out_color = vec4(rgb, 1.0); +} +#pragma sokol @end + +#pragma sokol @program build vs fs diff --git a/samples/shaders/overlays/line.glsl b/samples/shaders/overlays/line.glsl new file mode 100644 index 0000000..29badeb --- /dev/null +++ b/samples/shaders/overlays/line.glsl @@ -0,0 +1,275 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Overlay line shader. +// +// Renders fat lines as shader-expanded screen-space quads. Per-instance +// data (two endpoints, color, thickness, mode flags) lives in a storage +// buffer indexed by gl_InstanceIndex, the VS expands six vertices per +// instance from gl_VertexIndex with no VBO/IBO bound. +// +// Vertex index -> corner layout (two triangles forming a quad): +// +// 0 -> endpoint=A, side=-1 3 -> endpoint=A, side=-1 +// 1 -> endpoint=B, side=-1 4 -> endpoint=B, side=+1 +// 2 -> endpoint=B, side=+1 5 -> endpoint=A, side=+1 +// +// Thickness modes (instance flag bit 0): +// PIXELS, screen-space pixels, constant on-screen weight. +// WORLD, world meters, converted to pixels per endpoint using +// `viewport.y * proj[1][1] / (2 * clip.w)`. Per-endpoint, so +// a long line tapers correctly with depth. +// +// Occlusion modes (instance flag bit 1, branched in the FS): +// HIDE, output alpha=0 when occluded (single-pipeline approximation +// of a depth-tested draw, see note below on pipeline state). +// DIM, modulate color (premultiplied -> multiply both rgb and a) when +// occluded so the line stays readable through walls. +// DASHED, screen-space dash pattern (8 px on / 8 px off) when occluded. +// Pattern is zero-alpha in the gap, NOT discard, avoids +// disabling early-Z and keeps the FS flow control flat. +// +// Pipeline state notes: +// * depth_compare = ALWAYS, depth_write = off. The shader samples the +// linear-depth pre-pass (R32F view-space Z, written by GTAO's depth +// pre-pass) and compares per-fragment for the DIM/DASHED branches. +// HIDE relies on the same sample + alpha=0. MSAA silhouettes for +// HIDE may read slightly harder than a depth-tested draw would +// produce. If that bites visually, split into a second pipeline +// with depth_compare = GREATER for HIDE-mode instances. +// * Premultiplied-alpha blend (SRC_ONE, ONE_MINUS_SRC_ALPHA). CPU side +// packs `color.rgb *= color.a` into the instance before upload. +// +// UV handling: the linear-depth target is sampled at +// `gl_FragCoord.xy / textureSize(...)`. This is the same trick cube.glsl +// uses for the GTAO sample. Pixel-space gl_FragCoord matches the +// rasterizer's storage orientation on every backend, so no uvYSign flip +// is needed. The flip is required only when sampling with NDC-derived +// UVs, which we don't do here. + +#pragma sokol @module overlay_line + +#pragma sokol @ctype mat4 Mat4 +#pragma sokol @ctype vec4 Vec4 + +#pragma sokol @vs vs + +layout(binding = 0) uniform ub_frame +{ + mat4 view; + mat4 proj; + mat4 view_proj; + mat4 inv_view_proj; + vec4 camera_pos; // .xyz = pos, .w = time + vec4 viewport; // .xy = size px, .zw = 1/size +}; + +struct line_instance +{ + vec4 a; // .xyz = world endpoint A, .w = thickness (px or world) + vec4 b; // .xyz = world endpoint B, .w = reserved + vec4 color; // premultiplied linear RGBA + uvec4 flags; // .x = thickness unit (0 px / 1 world) + // .y = occlusion mode (0 hide / 1 dim / 2 dashed) + // .zw = reserved +}; + +layout(binding = 0) readonly buffer line_instances +{ + line_instance instances[]; +}; + +out vec2 v_screen_a; // flat per-instance screen-space pixel coords of A +out vec2 v_screen_b; // flat per-instance screen-space pixel coords of B + +noperspective out float v_dist_from_axis_px; // signed perpendicular pixel distance (smooth) +out float v_half_width_px; // half-width in pixels at this fragment (smooth, varies in WORLD mode) + +out float v_view_z; // positive view-space depth (smooth, perspective-correct) +flat out vec4 v_color; +flat out uint v_occ_mode; + +void main() +{ + line_instance inst = instances[gl_InstanceIndex]; + + // Decode vertex index -> endpoint + side. + int index = gl_VertexIndex; + bool is_b = (index == 1)||(index == 2)||(index == 4); + float side = ((index == 2)||(index == 4)||(index == 5)) ? 1.0 : -1.0; + + vec3 world_a = inst.a.xyz; + vec3 world_b = inst.b.xyz; + vec4 clip_a = view_proj * vec4(world_a, 1.0); + vec4 clip_b = view_proj * vec4(world_b, 1.0); + vec4 view_a = view * vec4(world_a, 1.0); + vec4 view_b = view * vec4(world_b, 1.0); + + vec4 clip_end = is_b ? clip_b : clip_a; + float view_z_end = -(is_b ? view_b.z : view_a.z); + + // Screen-space pixel coords of both endpoints (after perspective divide, + // remapped from NDC [-1,1] to pixel [0, viewport]). Used by the FS for + // dash phase computation, both endpoints needed at every vertex because + // we don't qualify "flat from provoking vertex" which is impl-defined. + vec2 ndc_a = clip_a.xy / clip_a.w; + vec2 ndc_b = clip_b.xy / clip_b.w; + v_screen_a = (ndc_a * 0.5 + 0.5) * viewport.xy; + v_screen_b = (ndc_b * 0.5 + 0.5) * viewport.xy; + + // Screen-space line direction in pixels (aspect-corrected). Fallback + // direction if both endpoints project to the same pixel, line is + // effectively a point, the perpendicular doesn't matter. + vec2 dir_px = v_screen_b - v_screen_a; + float len_px = length(dir_px); + vec2 dir_n = (len_px > 1e-6) ? (dir_px / len_px) : vec2(1.0, 0.0); + vec2 perp_n = vec2(-dir_n.y, dir_n.x); + + // Half-width in pixels, mode-aware. WORLD converts at the endpoint's + // view-space depth so the line tapers correctly. proj[1][1] is + // 1/tan(fovY/2) for a standard perspective projection, viewport.y * + // proj[1][1] / (2 * z) yields pixels per world unit at view-space + // distance z. + float thickness = inst.a.w; + float half_width_px; + if (inst.flags.x == 0u) + { + half_width_px = thickness * 0.5; + } + else + { + float pixels_per_world = viewport.y * proj[1][1] / (2.0 * view_z_end); + half_width_px = thickness * 0.5 * pixels_per_world; + } + + // Floor at 0.5 px so very thin lines don't vanish into sub-pixel land, + // attenuation for requested widths below this happens FS-side via the + // box-filter coverage falloff. + half_width_px = max(half_width_px, 0.5); + + // Expand the rasterized quad past the true half-width by an AA pad so + // the FS coverage falloff has geometry to ramp down inside. Without it + // the quad edge cuts the falloff off mid-ramp, a hard step along the + // line that reads as a jaggy no matter how good the FS filter is. The + // FS uses the TRUE half-width (v_half_width_px), so the pad adds only + // transparent margin, it does not fatten the visible line. The FS + // smoothstep falloff completes at d = half_width + fwidth, and fwidth + // (an L1 norm) peaks at sqrt(2) on a 45 deg line, so the pad must be + // >= ~1.42 px, 1.5 covers it with margin. + const float AA_PAD_PX = 1.5; + float quad_half_px = half_width_px + AA_PAD_PX; + + // Offset from the axis in pixels -> in NDC at this endpoint's depth. + // Multiply by clip_end.w so that after perspective divide it lands at + // the right NDC position. + vec2 offset_px = perp_n * side * quad_half_px; + vec2 offset_ndc = offset_px * (2.0 * viewport.zw); + vec4 clip_pos = clip_end; + clip_pos.xy += offset_ndc * clip_end.w; + + gl_Position = clip_pos; + v_dist_from_axis_px = side * quad_half_px; + v_half_width_px = half_width_px; + v_view_z = view_z_end; + v_color = inst.color; + v_occ_mode = inst.flags.y; +} +#pragma sokol @end + +#pragma sokol @fs fs + +// binding=1 (not 0): sokol-shdc enforces disjoint binding numbers between +// storage buffers and textures across all stages of a program. The line +// instance buffer holds binding=0 in the VS, so the depth texture takes 1. +#pragma sokol @image_sample_type tex_depth float +layout(binding = 1)uniform texture2D tex_depth; + +#pragma sokol @sampler_type smp_depth filtering +layout(binding = 0)uniform sampler smp_depth; + +in vec2 v_screen_a; +in vec2 v_screen_b; +noperspective in float v_dist_from_axis_px; +in float v_half_width_px; +in float v_view_z; +flat in vec4 v_color; +flat in uint v_occ_mode; +out vec4 out_color; + +const uint OCC_HIDE = 0u; +const uint OCC_DIM = 1u; +const uint OCC_DASHED = 2u; + +void main() +{ + // Coverage from the capsule SDF. d is the fragment's folded + // perpendicular distance from the axis (px), coverage ramps 1->0 over a + // 2*aa band straddling the true edge at d = half_width. + // + // This is a smoothstep, not an energy-exact box filter. A box filter's + // ~1px falloff faithfully renders the intrinsic stair-stepping of a + // thin near-axis-aligned line, this wider cubic falloff spreads each + // row-to-row step into a gradient that reads smoother, the better + // tradeoff for thin debug lines. fwidth is taken of the raw signed + // v_dist_from_axis_px (not abs/sd): fwidth(abs(x)) kinks where x + // crosses 0 at the line center, the signed value is stable everywhere. + // The VS quad pad (AA_PAD_PX) must cover this 2*aa band. + float d = abs(v_dist_from_axis_px); + float aa = fwidth(v_dist_from_axis_px); + float coverage = 1.0 - smoothstep(v_half_width_px - aa, v_half_width_px + aa, d); + + // Sample scene linear depth. Pixel-space gl_FragCoord divided by the + // target's textureSize is backend-canonical, no UV.y flip needed. + vec2 depth_uv = gl_FragCoord.xy / vec2(textureSize(sampler2D(tex_depth, smp_depth), 0)); + float scene_z = textureLod(sampler2D(tex_depth, smp_depth), depth_uv, 0.0).r; + + // Slope-scaled occlusion bias. A fixed bias can't protect a line lying + // coplanar with a surface: at grazing angles the scene depth changes + // many mm per pixel, so the sampled scene_z and the line's own v_view_z + // disagree by more than any small constant, the test flips per pixel + // and HIDE-mode chunks drop out, breaking the line. fwidth(v_view_z) is + // the line's per-pixel view-depth change: large at grazing angles, ~0 + // head-on, so the bias grows exactly where it's needed without letting + // head-on lines bleed through occluders. Same idea as slope-scaled + // shadow depth bias. + const float occlusion_bias_m = 0.001; // ~1 mm floor, head-on contact + const float occlusion_slope_k = 2.0; // grazing-angle multiplier + float occlusion_bias = occlusion_bias_m + occlusion_slope_k * fwidth(v_view_z); + bool occluded = v_view_z > scene_z + occlusion_bias; + + // Occlusion mode modulation. v_color is premultiplied: multiplying the + // whole vec4 stays valid (rgb*= and a*= by the same factor preserves + // the premultiplied invariant). + vec4 col = v_color; + + if (v_occ_mode == OCC_HIDE && occluded) + { + col = vec4(0.0); + } + else if (v_occ_mode == OCC_DIM && occluded) + { + col *= 0.25; + } + else if (v_occ_mode == OCC_DASHED && occluded) + { + // Screen-space dash phase, in pixels along the line from A. + vec2 line_vec = v_screen_b - v_screen_a; + float line_len = max(length(line_vec), 1e-6); + vec2 line_dir = line_vec / line_len; + vec2 rel_px = gl_FragCoord.xy - v_screen_a; + float along_px = dot(rel_px, line_dir); + + const float DASH_PERIOD_PX = 16.0; + const float DASH_HALF = 4.0; // half the solid run inside the period + float phase = mod(along_px, DASH_PERIOD_PX); + float dash_sd = abs(phase - DASH_HALF) - DASH_HALF; + float dash_aa = fwidth(along_px); + float dash_msk = 1.0 - smoothstep(-dash_aa, dash_aa, dash_sd); + col *= dash_msk; + } + + out_color = col * coverage; +} +#pragma sokol @end + +#pragma sokol @program prog vs fs diff --git a/samples/shaders/overlays/point.glsl b/samples/shaders/overlays/point.glsl new file mode 100644 index 0000000..44536d2 --- /dev/null +++ b/samples/shaders/overlays/point.glsl @@ -0,0 +1,176 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Overlay point shader. +// +// Renders fat points as shader-expanded screen-space quads centered on the +// projected world position. Per-instance data (world point, color, size, +// mode flags) lives in a storage buffer indexed by gl_InstanceIndex, the +// VS expands six vertices per instance from gl_VertexIndex with no +// VBO/IBO bound. Two triangles form the quad: +// +// 0 -> (-1, -1) 3 -> (-1, -1) +// 1 -> (+1, -1) 4 -> (+1, +1) +// 2 -> (+1, +1) 5 -> (-1, +1) +// +// Size modes (instance flag bit 0) and occlusion modes (bit 1) match +// line.glsl's conventions exactly, see that file for the rationale. +// +// The FS is a circle SDF: signed distance from the projected point center +// in pixels, AA'd via fwidth. Square or diamond markers would be cheaper +// but circles read unambiguously as "point markers" against the line +// primitive which is a capsule SDF. +// +// Dashed-mode for a point is a bit nonsensical (the dashing axis is +// "along the line", a point has no axis), so DASHED behaves identically +// to DIM here. HIDE and DIM behave as documented. + +#pragma sokol @module overlay_point + +#pragma sokol @ctype mat4 Mat4 +#pragma sokol @ctype vec4 Vec4 + +#pragma sokol @vs vs + +layout(binding = 0)uniform ub_frame +{ + mat4 view; + mat4 proj; + mat4 view_proj; + mat4 inv_view_proj; + vec4 camera_pos; // .xyz = pos, .w = time + vec4 viewport; // .xy = size px, .zw = 1/size +}; + +struct point_instance +{ + vec4 p; // .xyz = world position, .w = size (px or world) + vec4 color; // premultiplied linear RGBA + uvec4 flags; // .x = size unit (0 px / 1 world) + // .y = occlusion mode (0 hide / 1 dim / 2 dashed->dim) + // .zw = reserved +}; + +layout(binding = 0) readonly buffer point_instances +{ + point_instance instances[]; +}; + +out vec2 v_offset_from_center_px; // signed pixel offset from quad center (smooth) +out float v_half_size_px; // true point radius in pixels (flat-equivalent, all 6 verts share) +out float v_view_z; // positive view-space depth (smooth, perspective-correct) +flat out vec4 v_color; +flat out uint v_occ_mode; + +void main() +{ + point_instance inst = instances[gl_InstanceIndex]; + + int index = gl_VertexIndex; + float corner_x = ((index == 1)||(index == 2)||(index == 4)) ? 1.0 : -1.0; + float corner_y = ((index == 2)||(index == 4)||(index == 5)) ? 1.0 : -1.0; + + vec3 world_p = inst.p.xyz; + vec4 clip_c = view_proj * vec4(world_p, 1.0); + vec4 view_c = view * vec4(world_p, 1.0); + float view_z = -view_c.z; + + // Half-size in pixels, mode-aware. WORLD conversion follows the same + // formula as line.glsl: pixels per world unit = viewport.y * + // proj[1][1] / (2 * view_z). + float requested = inst.p.w; + float half_size_px; + if (inst.flags.x == 0u) + { + half_size_px = requested * 0.5; + } + else + { + float pixels_per_world = viewport.y * proj[1][1] / (2.0 * view_z); + half_size_px = requested * 0.5 * pixels_per_world; + } + half_size_px = max(half_size_px, 0.5); + + // Expand the rasterized quad past the true radius by an AA pad so the + // FS circle-SDF falloff has geometry to ramp down inside (see + // overlays/line.glsl for the full rationale). The FS smoothstep + // completes at d = radius + fwidth, and fwidth (an L1 norm) peaks at + // sqrt(2), so the pad must be >= ~1.42 px, 1.5 covers it. + const float AA_PAD_PX = 1.5; + float quad_half_px = half_size_px + AA_PAD_PX; + + vec2 offset_px = vec2(corner_x, corner_y) * quad_half_px; + vec2 offset_ndc = offset_px * (2.0 * viewport.zw); + + vec4 clip_pos = clip_c; + clip_pos.xy += offset_ndc * clip_c.w; + + gl_Position = clip_pos; + v_offset_from_center_px = offset_px; + v_half_size_px = half_size_px; + v_view_z = view_z; + v_color = inst.color; + v_occ_mode = inst.flags.y; +} +#pragma sokol @end + +#pragma sokol @fs fs + +// binding=1 (not 0): sokol-shdc enforces disjoint binding numbers between +// storage buffers and textures across all stages of a program. The point +// instance buffer holds binding=0 in the VS, so the depth texture takes 1. +#pragma sokol @image_sample_type tex_depth float +layout(binding = 1)uniform texture2D tex_depth; + +#pragma sokol @sampler_type smp_depth filtering +layout(binding = 0)uniform sampler smp_depth; + +in vec2 v_offset_from_center_px; +in float v_half_size_px; +in float v_view_z; +flat in vec4 v_color; +flat in uint v_occ_mode; +out vec4 out_color; + +const uint OCC_HIDE = 0u; + +void main() +{ + // Coverage from the circle SDF. d is the fragment's radial distance + // from the point center (px), coverage ramps 1->0 over a 2*aa band + // straddling the true edge at d = radius. Smoothstep (cubic, wider + // than an energy-exact box filter), see overlays/line.glsl for why + // the softer falloff is preferred for thin overlay primitives. + float d = length(v_offset_from_center_px); + float aa = fwidth(d); + float coverage = 1.0 - smoothstep(v_half_size_px - aa, v_half_size_px + aa, d); + + vec2 depth_uv = gl_FragCoord.xy / vec2(textureSize(sampler2D(tex_depth, smp_depth), 0)); + float scene_z = textureLod(sampler2D(tex_depth, smp_depth), depth_uv, 0.0).r; + + // Slope-scaled occlusion bias, see overlays/line.glsl for the full + // rationale. Keeps a point resting on a surface from flickering out in + // HIDE mode without letting head-on points bleed through occluders. + const float occlusion_bias_m = 0.001; // ~1 mm floor + const float occlusion_slope_k = 2.0; + float occlusion_bias = occlusion_bias_m + occlusion_slope_k * fwidth(v_view_z); + bool occluded = v_view_z > scene_z + occlusion_bias; + + vec4 col = v_color; + + if (occluded) + { + if (v_occ_mode == OCC_HIDE) + { + col = vec4(0.0); + } else { + // DIM (1) and DASHED (2, degenerates to DIM for points) + col *= 0.25; + } + } + + out_color = col * coverage; +} +#pragma sokol @end + +#pragma sokol @program prog vs fs diff --git a/samples/shaders/post/depth_only_capsule.glsl b/samples/shaders/post/depth_only_capsule.glsl new file mode 100644 index 0000000..8f7b362 --- /dev/null +++ b/samples/shaders/post/depth_only_capsule.glsl @@ -0,0 +1,180 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Depth-only pre-pass for capsules. Mirrors +// depth_only_sphere: analytic ray-capsule hit, writes linear view-space +// depth into R32F + reverse-Z clip depth into gl_FragDepth. + +#pragma sokol @module depth_only_capsule + +#pragma sokol @ctype mat4 Mat4 +#pragma sokol @ctype vec4 Vec4 +#pragma sokol @ctype vec3 b3Vec3 +#pragma sokol @ctype vec2 b3Vec2 + +#pragma sokol @vs vs + +layout(binding = 0) uniform ub_frame +{ + mat4 view_proj; +}; + +struct instance +{ + vec4 xform_row0; // .xyz = R row 0, .w = center.x + vec4 xform_row1; // .xyz = R row 1, .w = center.y + vec4 xform_row2; // .xyz = R row 2, .w = center.z + vec4 base_color; // unused, layout match + vec4 params; // .x = halfLength, .y = radius + vec4 material; // unused, layout match +}; + +layout(binding = 0) readonly buffer instances +{ + instance items[]; +}; + +in vec3 in_pos; // unit-cube corner, half-extent 0.5 + +sample out vec3 v_world_pos_proxy; +flat out vec3 v_center; +flat out float v_half_length; +flat out float v_radius; +flat out vec3 v_axis_x_world; + +void main() +{ + instance inst = items[gl_InstanceIndex]; + vec3 center = vec3(inst.xform_row0.w, inst.xform_row1.w, inst.xform_row2.w); + float halfLength = inst.params.x; + float radius = inst.params.y; + + vec3 obj_pos = vec3( + in_pos.x * 2.0 * (halfLength + radius), + in_pos.y * 2.0 * radius, + in_pos.z * 2.0 * radius + ); + + vec3 world_pos = center + vec3( + dot(inst.xform_row0.xyz, obj_pos), + dot(inst.xform_row1.xyz, obj_pos), + dot(inst.xform_row2.xyz, obj_pos) + ); + + v_world_pos_proxy = world_pos; + v_center = center; + v_half_length = halfLength; + v_radius = radius; + v_axis_x_world = vec3(inst.xform_row0.x, inst.xform_row1.x, inst.xform_row2.x); + + gl_Position = view_proj * vec4(world_pos, 1.0); +} + +#pragma sokol @end + +#pragma sokol @fs fs + +layout(binding = 1) uniform ub_pass +{ + mat4 view_proj; + mat4 view; + vec4 camera_pos; // .xyz = world camera position +}; + +sample in vec3 v_world_pos_proxy; +flat in vec3 v_center; +flat in float v_half_length; +flat in float v_radius; +flat in vec3 v_axis_x_world; + +out vec4 out_linear_depth; + +void main() +{ + vec3 ro = camera_pos.xyz; + vec3 rd = normalize(v_world_pos_proxy - ro); + + vec3 axis = v_axis_x_world; + vec3 pa = v_center - v_half_length * axis; + vec3 pb = v_center + v_half_length * axis; + + vec3 ba = pb - pa; + vec3 oa = ro - pa; + float baba = dot(ba, ba); + float bard = dot(ba, rd); + float baoa = dot(ba, oa); + float rdoa = dot(rd, oa); + float oaoa = dot(oa, oa); + + float a_c = baba - bard * bard; + float b_c = baba * rdoa - baoa * bard; + float c_c = baba * oaoa - baoa * baoa - v_radius * v_radius * baba; + float h_c = b_c * b_c - a_c * c_c; + + float t = -1.0; + + if (h_c >= 0.0 && a_c > 1e-8) + { + float t_body = (-b_c - sqrt(h_c)) / a_c; + float y = baoa + t_body * bard; + if (t_body > 0.0 && y > 0.0 && y < baba) + { + t = t_body; + } + } + + // Cap A (-X). + { + vec3 oc = ro - pa; + float b = dot(oc, rd); + float c = dot(oc, oc) - v_radius * v_radius; + float h = b * b - c; + if (h >= 0.0) + { + float tc = -b - sqrt(h); + if (tc > 0.0 &&(t < 0.0 || tc < t)) + { + vec3 hit = ro + tc * rd; + if (dot(hit - pa, axis) <= 0.0) + { + t = tc; + } + } + } + } + // Cap B (+X). + { + vec3 oc = ro - pb; + float b = dot(oc, rd); + float c = dot(oc, oc) - v_radius * v_radius; + float h = b * b - c; + if (h >= 0.0) + { + float tc = -b - sqrt(h); + if (tc > 0.0 &&(t < 0.0 || tc < t)) + { + vec3 hit = ro + tc * rd; + if (dot(hit - pb, axis) >= 0.0) + { + t = tc; + } + } + } + } + + if (t < 0.0) + { + discard; + } + + vec3 hit_world = ro + t * rd; + float view_z = -(view * vec4(hit_world, 1.0)).z; + + vec4 hit_clip = view_proj * vec4(hit_world, 1.0); + gl_FragDepth = hit_clip.z / hit_clip.w; + + out_linear_depth = vec4(view_z, 0.0, 0.0, 0.0); +} +#pragma sokol @end + +#pragma sokol @program prog vs fs diff --git a/samples/shaders/post/depth_only_cube.glsl b/samples/shaders/post/depth_only_cube.glsl new file mode 100644 index 0000000..def36ff --- /dev/null +++ b/samples/shaders/post/depth_only_cube.glsl @@ -0,0 +1,70 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Depth-only pre-pass for cubes. Writes positive +// linear view-space depth to an R32F color attachment, the D32F depth +// attachment is transient (rasterizer / early-Z only, never sampled). The +// full XeGTAO port reconstructs normals from depth derivatives inside +// MainPass, so the prepass produces no normal channel. + +#pragma sokol @module depth_only_cube + +#pragma sokol @ctype mat4 Mat4 +#pragma sokol @ctype vec4 Vec4 +#pragma sokol @ctype vec3 b3Vec3 +#pragma sokol @ctype vec2 b3Vec2 + +#pragma sokol @vs vs + +layout(binding = 0) uniform ub_frame +{ + mat4 view_proj; + mat4 view; +}; + +struct cube_instance +{ + vec4 xform_row0; + vec4 xform_row1; + vec4 xform_row2; + vec4 base_color; // unused, layout match with lit pipeline + vec4 material; // unused, layout match with lit pipeline +}; + +layout(binding = 0) readonly buffer cube_instances +{ + cube_instance instances[]; +}; + +in vec3 in_pos; +out float v_linear_view_z; + +void main() +{ + cube_instance inst = instances[gl_InstanceIndex]; + vec4 local_pos = vec4(in_pos, 1.0); + vec3 world_pos = vec3( + dot(inst.xform_row0, local_pos), + dot(inst.xform_row1, local_pos), + dot(inst.xform_row2, local_pos) + ); + vec4 view_h = view * vec4(world_pos, 1.0); + v_linear_view_z = -view_h.z; + gl_Position = view_proj * vec4(world_pos, 1.0); +} + +#pragma sokol @end + +#pragma sokol @fs fs + +in float v_linear_view_z; +out vec4 out_linear_depth; + +void main() +{ + out_linear_depth = vec4(v_linear_view_z, 0.0, 0.0, 0.0); +} + +#pragma sokol @end + +#pragma sokol @program prog vs fs diff --git a/samples/shaders/post/depth_only_geom.glsl b/samples/shaders/post/depth_only_geom.glsl new file mode 100644 index 0000000..a916c37 --- /dev/null +++ b/samples/shaders/post/depth_only_geom.glsl @@ -0,0 +1,84 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Depth-only pre-pass for triangle geometries (hulls, meshes, +// height fields). Same vertex math as the lit +// geom pipeline, FS writes positive linear view-space depth only. + +#pragma sokol @module depth_only_geom + +#pragma sokol @ctype mat4 Mat4 +#pragma sokol @ctype vec4 Vec4 +#pragma sokol @ctype vec3 b3Vec3 +#pragma sokol @ctype vec2 b3Vec2 + +#pragma sokol @vs vs + +layout(binding = 0) uniform ub_frame +{ + mat4 view_proj; + mat4 view; +}; + +layout(binding = 2) uniform ub_draw +{ + ivec4 inst_base; // .x = base index into the global instance array +}; + +struct instance +{ + vec4 xform_row0; + vec4 xform_row1; + vec4 xform_row2; + vec4 base_color; // unused, layout match + vec4 scale; // .xyz = per-instance scale + vec4 material; // unused, layout match +}; + +layout(binding = 0) readonly buffer instances +{ + instance items[]; +}; + +// Position-only input. The shared vertex buffer carries position+normal +// (stride 24 bytes), but this pre-pass doesn't read the normal. We just +// don't declare an `in_normal` attribute so glslang doesn't keep it +// around (and the GL driver doesn't warn about an unused attribute slot +// after stripping). The C-side pipeline desc skips the in_normal binding +// to match. +in vec3 in_pos; + +out float v_linear_view_z; + +void main() +{ + instance inst = items[inst_base.x + gl_InstanceIndex]; + + vec3 scaled_pos = in_pos * inst.scale.xyz; + vec4 local_pos = vec4(scaled_pos, 1.0); + vec3 world_pos = vec3( + dot(inst.xform_row0, local_pos), + dot(inst.xform_row1, local_pos), + dot(inst.xform_row2, local_pos) + ); + + vec4 view_h = view * vec4(world_pos, 1.0); + v_linear_view_z = -view_h.z; + gl_Position = view_proj * vec4(world_pos, 1.0); +} + +#pragma sokol @end + +#pragma sokol @fs fs + +in float v_linear_view_z; +out vec4 out_linear_depth; + +void main() +{ + out_linear_depth = vec4(v_linear_view_z, 0.0, 0.0, 0.0); +} + +#pragma sokol @end + +#pragma sokol @program prog vs fs diff --git a/samples/shaders/post/depth_only_sphere.glsl b/samples/shaders/post/depth_only_sphere.glsl new file mode 100644 index 0000000..290b454 --- /dev/null +++ b/samples/shaders/post/depth_only_sphere.glsl @@ -0,0 +1,100 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Depth-only pre-pass for spheres. Same shape as +// the lit sphere impostor: bounding-cube proxy in the VS, analytic +// ray-sphere intersection in the FS. Writes the analytic surface's linear +// view-space depth to an R32F color attachment and the reverse-Z clip +// depth to gl_FragDepth (transient D32F attachment, rasterizer only). + +#pragma sokol @module depth_only_sphere + +#pragma sokol @ctype mat4 Mat4 +#pragma sokol @ctype vec4 Vec4 +#pragma sokol @ctype vec3 b3Vec3 +#pragma sokol @ctype vec2 b3Vec2 + +#pragma sokol @vs vs + +layout(binding = 0) uniform ub_frame +{ + mat4 view_proj; +}; + +struct instance +{ + vec4 xform_row0; // .w = center.x + vec4 xform_row1; // .w = center.y + vec4 xform_row2; // .w = center.z + vec4 base_color; // unused, layout match + vec4 params; // .x = radius + vec4 material; // unused, layout match +}; + +layout(binding = 0) readonly buffer instances +{ + instance items[]; +}; + +in vec3 in_pos; // unit-cube corner, half-extent 0.5 + +sample out vec3 v_world_pos_proxy; +flat out vec3 v_center; +flat out float v_radius; + +void main() +{ + instance inst = items[gl_InstanceIndex]; + vec3 center = vec3(inst.xform_row0.w, inst.xform_row1.w, inst.xform_row2.w); + float radius = inst.params.x; + vec3 world_pos = center + (2.0 * radius) * in_pos; + + v_world_pos_proxy = world_pos; + v_center = center; + v_radius = radius; + + gl_Position = view_proj * vec4(world_pos, 1.0); +} + +#pragma sokol @end + +#pragma sokol @fs fs + +layout(binding = 1) uniform ub_pass +{ + mat4 view_proj; // for gl_FragDepth (reverse-Z) + mat4 view; // for linear view-space depth + vec4 camera_pos; // .xyz = world camera position +}; + +sample in vec3 v_world_pos_proxy; +flat in vec3 v_center; +flat in float v_radius; + +out vec4 out_linear_depth; + +void main() +{ + vec3 ro = camera_pos.xyz; + vec3 rd = normalize(v_world_pos_proxy - ro); + + vec3 oc = ro - v_center; + float b = dot(oc, rd); + float c2 = dot(oc, oc) - v_radius * v_radius; + float h = b * b - c2; + if (h < 0.0) discard; + float t = -b - sqrt(h); + if (t < 0.0) discard; + + vec3 hit_world = ro + t * rd; + float view_z = -(view * vec4(hit_world, 1.0)).z; + + vec4 hit_clip = view_proj * vec4(hit_world, 1.0); + gl_FragDepth = hit_clip.z / hit_clip.w; + + out_linear_depth = vec4(view_z, 0.0, 0.0, 0.0); +} + +#pragma sokol @end + +#pragma sokol @program prog vs fs diff --git a/samples/shaders/post/gtao_denoise.glsl b/samples/shaders/post/gtao_denoise.glsl new file mode 100644 index 0000000..66ab7fb --- /dev/null +++ b/samples/shaders/post/gtao_denoise.glsl @@ -0,0 +1,260 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// GTAO Denoise compute shader. +// +// Port of Esoterica's Denoise.esf (which is XeGTAO's XeGTAO_Denoise), a +// cross-bilateral 3x3 blur of the noisy AO term, weighted by the packed +// per-pixel edges that MainPass wrote alongside the noise. The renderer +// runs N dispatches per frame: (N - 1) intermediate dispatches with +// finalApply = 0 ping-pong noisy0 <-> noisy1, then one final dispatch with +// finalApply = 1 that rescales by XE_GTAO_OCCLUSION_TERM_SCALE (1.5) on +// write and lands in `result` for the lit shaders to sample. N is chosen +// renderer-side and may be 1 (final dispatch only, no intermediates). +// +// 8x8 numthreads, each thread processes 2 horizontal pixels at coords +// (2*tid.x, tid.y) and (2*tid.x + 1, tid.y). Mirrors MainPass.esf's +// "2 pixels per thread" optimization, Esoterica calls this out explicitly +// at line 52. +// +// Departures from Esoterica's Denoise.esf / XeGTAO_Denoise: +// +// * The 3 edges + 4 AO GatherRed calls in XeGTAO.esh:815-822 are +// replaced by direct texelFetch reads of the same 12-texel +// neighbourhood (4-wide x 3-tall around pixCoordBase). Same +// rationale as gtao_prefilter_depth.glsl and gtao_main_pass.glsl: +// sidesteps the textureGather channel-ordering / backend-Y-flip +// ambiguity. Cost is 24 single-channel R32F fetches vs 7 gather ops +// per thread, predictably slower but a non-issue for a debug +// renderer. +// +// * Dispatch sized as ceil(W / 16) x ceil(H / 8) workgroups (each +// workgroup writes 16 horizontal x 8 vertical pixels). Esoterica +// dispatches ceil(W / 8) x ceil(H / 8), twice as many threads in X, +// which over-covers by 2x with the surplus writes landing OOB +// (silent no-op in D3D11/Vulkan/Metal compute). The visible output +// is identical, we just skip the wasted threads. Recorded as a +// deviation. +// +// * `lpfloat` collapses to `float` (matches Esoterica's config. +// XE_GTAO_USE_HALF_FLOAT_PRECISION=0). +// +// * `AOTermType` is a plain `float`, XE_GTAO_COMPUTE_BENT_NORMALS is +// undefined on our side (matches Esoterica's default). The +// XeGTAO_DecodeGatherPartial path collapses to identity, we inline it. +// +// * `XE_GTAO_SHOW_EDGES` / `XE_GTAO_SHOW_BENT_NORMALS` debug-viz +// branches dropped, render3d uses its own debug_view_mode plumbing. +// +// * `finalApply` is delivered as a per-dispatch UBO field instead +// HLSL root constants. Lives in a small dedicated ub_denoise UBO at +// binding=1, the shared ub_gtao at binding=0 carries the same byte +// layout as the prefilter + main_pass shaders so the renderer can +// reuse one C-side build of the constants. +// +// * Bounds clamping for the 12 neighbours uses +// `clamp(coord, 0, ViewportSize - 1)` per fetch. The edge-clamped +// duplicates feed back through the same XeGTAO weighting math, same +// replicated-edge approximation Esoterica gets implicitly through +// the gather + clamp_to_edge sampler. + +#pragma sokol @module gtao_denoise + +#pragma sokol @ctype vec2 b3Vec2 +#pragma sokol @ctype vec4 Vec4 +#pragma sokol @ctype mat4 Mat4 + +#pragma sokol @cs cs + +// Per-shader subset of Esoterica's XeGTAO::GTAOConstants. Denoise only +// reads `ViewportSize` (bounds checks) and `DenoiseBlurBeta` (blur +// strength). Explicit `gtao.X` instance name prevents SPIRV-Cross +// synthesizing one (`_NNN.X`), trimming to just-the-read fields +// prevents the GL linker's per-field dead-strip from producing +// `glGetUniformLocation` warnings. See the matching comment in +// gtao_prefilter_depth.glsl. +layout( binding = 0 ) uniform ub_gtao +{ + ivec2 ViewportSize; + float DenoiseBlurBeta; +} +gtao; +// NoiseIndex intentionally omitted, see gtao_prefilter_depth.glsl. + +// Per-dispatch knob. `FinalApply` non-zero on the final (3rd) denoise +// dispatch, rescales the AO term by XE_GTAO_OCCLUSION_TERM_SCALE before +// writing so lit shaders see the over-bright [0, 1.5] visibility range. +layout( binding = 1 ) uniform ub_denoise +{ + int FinalApply; + int _Pad0; + int _Pad1; + int _Pad2; +}; + +// Storage-image output (R32F, same access-format rationale as MainPass +// / PrefilterDepth: sokol-shdc / SPIRV-Cross restrict storage_image +// access formats to r32f / r32i / r32ui plus rgba/rg{32,16} variants). +layout( binding = 0, r32f ) uniform writeonly image2D out_ao; + +// Sampled inputs. Bind base 1: storage images take 0..0, textures start +// at 1. Same point-clamp sampler used by every GTAO compute shader. +layout( binding = 1 ) uniform texture2D tex_edges; +layout( binding = 2 ) uniform texture2D tex_noisy_ao; +layout( binding = 0 ) uniform sampler smp_point_clamp; + +#pragma sokol @include ../common/xe_gtao_common.glsl + +// XeGTAO.esh:745-751, additive sample with edge weight. Inlined here +// because GLSL's lack of `inout` arrays makes the HLSL helper awkward, +// the math is unchanged. +void XeGTAO_AddSample( float ssaoValue, float edgeValue, inout float sum, inout float sumWeight ) +{ + float weight = edgeValue; + sum += weight * ssaoValue; + sumWeight += weight; +} + +// Edge-clamped texelFetch helpers. We fetch a 4x3 neighbourhood around +// each pixel pair (pixCoordBase, pixCoordBase + (1, 0)). The diagonals +// reach one step out on each side and one step up/down, so the inclusive +// fetch range is (pixCoordBase + (-1, -1)).. (pixCoordBase + (2, 1)). +float fetchEdge( ivec2 coord ) +{ + ivec2 vmax = gtao.ViewportSize - 1; + ivec2 c = clamp( coord, ivec2( 0 ), vmax ); + return texelFetch( sampler2D( tex_edges, smp_point_clamp ), c, 0 ).r; +} + +float fetchAO( ivec2 coord ) +{ + ivec2 vmax = gtao.ViewportSize - 1; + ivec2 c = clamp( coord, ivec2( 0 ), vmax ); + return texelFetch( sampler2D( tex_noisy_ao, smp_point_clamp ), c, 0 ).r; +} + +// Output helper, XeGTAO.esh:757-774 collapsed to the "kirill: float AO +// term" patch (lines 771-772) since we always carry the float term, not +// the packed-UINT variant. +void XeGTAO_Output( ivec2 pixCoord, float outputValue, bool finalApply ) +{ + float scale = finalApply ? XE_GTAO_OCCLUSION_TERM_SCALE : 1.0; + imageStore( out_ao, pixCoord, vec4( outputValue * scale, 0.0, 0.0, 0.0 ) ); +} + +layout( local_size_x = 8, local_size_y = 8, local_size_z = 1 ) in; + +void main() +{ + ivec2 dispatchThreadID = ivec2( gl_GlobalInvocationID.xy ); + + // pixCoordBase = (2 * tid.x, tid.y). With the proper "2 horizontal + // pixels per thread" dispatch sizing (groups = ceil(W/16) x + // ceil(H/8)), tid.x ranges 0..ceil(W/16)*8 - 1, so pixCoordBase.x + // ranges 0..2*ceil(W/16)*8 - 2, at most one pixel past W when W is + // odd. The early-out + per-side bounds guard handles that tail. + ivec2 pixCoordBase = ivec2( dispatchThreadID.x * 2, dispatchThreadID.y ); + if ( any( greaterThanEqual( pixCoordBase, gtao.ViewportSize ) ) ) + { + return; + } + + bool finalApply = ( FinalApply != 0 ); + float blurAmount = finalApply ? gtao.DenoiseBlurBeta : ( gtao.DenoiseBlurBeta / 5.0 ); + const float diagWeight = 0.85 * 0.5; + + // 4 x 3 neighbourhood of edges + AO, indexed [x = -1..2][y = -1..1]. + // Reading them up-front lets the per-side code below be a direct + // index lookup, mirroring Esoterica's per-side `visQk[index]` extracts + // from the gather results. + float edgesN[4][3]; + float ao[4][3]; + for ( int i = 0; i < 4; ++i ) + { + for ( int j = 0; j < 3; ++j ) + { + ivec2 c = pixCoordBase + ivec2( i - 1, j - 1 ); + edgesN[i][j] = fetchEdge( c ); + ao[i][j] = fetchAO( c ); + } + } + + // Process side 0 (pixel at pixCoordBase) then side 1 (pixCoordBase + + // (1, 0)). The unrolled per-side block matches XeGTAO.esh:824-892. + for ( int side = 0; side < 2; ++side ) + { + ivec2 pixCoord = pixCoordBase + ivec2( side, 0 ); + if ( pixCoord.x >= gtao.ViewportSize.x ) + { + break; + } + + // Index helpers: column `c` in the 4-wide patch corresponds to + // x = pixCoordBase.x + (c - 1). For side==0 the C column is 1 + // (the L/R neighbours sit at columns 0 / 2), for side==1 the C + // column is 2 (neighbours at 1 / 3). + int cC = 1 + side; + int cL = cC - 1; + int cR = cC + 1; + + vec4 edgesC_LRTB = XeGTAO_UnpackEdges( edgesN[cC][1] ); + vec4 edgesL_LRTB = XeGTAO_UnpackEdges( edgesN[cL][1] ); + vec4 edgesR_LRTB = XeGTAO_UnpackEdges( edgesN[cR][1] ); + vec4 edgesT_LRTB = XeGTAO_UnpackEdges( edgesN[cC][0] ); + vec4 edgesB_LRTB = XeGTAO_UnpackEdges( edgesN[cC][2] ); + + // Edge symmetricity nudge, XeGTAO.esh:836-837. Clamps the center + // pixel's per-direction edge weight against the matching edge on + // the neighbour pixel, sharpens the blur, especially under TAA + // (which we don't have, kept for A/B parity). + edgesC_LRTB *= vec4( edgesL_LRTB.y, edgesR_LRTB.x, edgesT_LRTB.w, edgesB_LRTB.z ); + + // Leak, XeGTAO.esh:839-843 (`#if 1` branch is the default and + // only path Esoterica ships). Allows a small amount of bleed + // when a pixel is surrounded by 3-4 edges, reducing aliasing. + const float leak_threshold = 2.5; + const float leak_strength = 0.5; + float edginess = + ( clamp( 4.0 - leak_threshold - dot( edgesC_LRTB, vec4( 1.0 ) ), 0.0, 1.0 ) / ( 4.0 - leak_threshold ) ) * + leak_strength; + edgesC_LRTB = clamp( edgesC_LRTB + edginess, 0.0, 1.0 ); + + // Diagonal weights, XeGTAO.esh:852-855. + float weightTL = diagWeight * ( edgesC_LRTB.x * edgesL_LRTB.z + edgesC_LRTB.z * edgesT_LRTB.x ); + float weightTR = diagWeight * ( edgesC_LRTB.z * edgesT_LRTB.y + edgesC_LRTB.y * edgesR_LRTB.z ); + float weightBL = diagWeight * ( edgesC_LRTB.w * edgesB_LRTB.x + edgesC_LRTB.x * edgesL_LRTB.w ); + float weightBR = diagWeight * ( edgesC_LRTB.y * edgesR_LRTB.w + edgesC_LRTB.w * edgesB_LRTB.y ); + + // AO neighbourhood for this side. Center at (cC, 1), L/R at + // (cL, 1) / (cR, 1), T/B at (cC, 0) / (cC, 2), diagonals at the + // 4 corners of the 3x3 around (cC, 1). + float ssaoValue = ao[cC][1]; + float ssaoValueL = ao[cL][1]; + float ssaoValueR = ao[cR][1]; + float ssaoValueT = ao[cC][0]; + float ssaoValueB = ao[cC][2]; + float ssaoValueTL = ao[cL][0]; + float ssaoValueTR = ao[cR][0]; + float ssaoValueBL = ao[cL][2]; + float ssaoValueBR = ao[cR][2]; + + float sumWeight = blurAmount; + float sum = ssaoValue * sumWeight; + + XeGTAO_AddSample( ssaoValueL, edgesC_LRTB.x, sum, sumWeight ); + XeGTAO_AddSample( ssaoValueR, edgesC_LRTB.y, sum, sumWeight ); + XeGTAO_AddSample( ssaoValueT, edgesC_LRTB.z, sum, sumWeight ); + XeGTAO_AddSample( ssaoValueB, edgesC_LRTB.w, sum, sumWeight ); + + XeGTAO_AddSample( ssaoValueTL, weightTL, sum, sumWeight ); + XeGTAO_AddSample( ssaoValueTR, weightTR, sum, sumWeight ); + XeGTAO_AddSample( ssaoValueBL, weightBL, sum, sumWeight ); + XeGTAO_AddSample( ssaoValueBR, weightBR, sum, sumWeight ); + + float aoTerm = sum / sumWeight; + XeGTAO_Output( pixCoord, aoTerm, finalApply ); + } +} +#pragma sokol @end + +#pragma sokol @program prog cs diff --git a/samples/shaders/post/gtao_main_pass.glsl b/samples/shaders/post/gtao_main_pass.glsl new file mode 100644 index 0000000..5aaae05 --- /dev/null +++ b/samples/shaders/post/gtao_main_pass.glsl @@ -0,0 +1,412 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// GTAO MainPass compute shader. +// +// Port of Esoterica's MainPass.esf (which is XeGTAO's MainPass with +// XE_GTAO_GENERATE_NORMALS_INPLACE enabled). For each viewport pixel, +// reconstructs the view-space normal from depth derivatives, generates a +// Hilbert+R2 spatial noise pair, and runs the XeGTAO slice trace against +// the prefiltered depth chain. Slice count and steps-per-slice come from +// the ub_gtao UBO (the AmbientOcclusionQuality preset on the C side) rather than the +// hardcoded Ultra tier. +// +// Outputs: +// * out_noisy_ao (R32F, storage_image): the visibility term divided +// by XE_GTAO_OCCLUSION_TERM_SCALE (1.5) and saturated to [0,1]. +// XeGTAO_OutputWorkingTerm's pre-denoise format. Denoise +// will multiply by 1.5 on finalApply to restore the over-bright +// occlusion term. (Deviation: Esoterica uses R16F. sokol-shdc / +// SPIRV-Cross only permit r32f/r32i/r32ui plus rgba/rg{32,16} +// variants for storage_image access formats, mirrors D3D11's +// typed-UAV restriction. R32F is the cheapest single-channel +// fp format that survives cross-compilation.) +// * out_edges (R32F, storage_image): packed edge gradients +// consumed by Denoise. Same R8->R32F deviation rationale as +// out_noisy_ao, the value range still fits in [0,1] so +// XeGTAO_UnpackEdges on the read side is unchanged. +// +// Departures from Esoterica's MainPass.esf: +// +// * Cardinal depth taps (center, L, R, T, B) use texelFetch on the raw +// depth target instead of two GatherRed calls. Two reasons: avoids +// the GatherRed channel-ordering / backend Y-flip ambiguity, and +// matches the same pattern already adopted by +// gtao_prefilter_depth.glsl. +// +// * The trace samples DO use textureLod since they sample at fractional +// mip levels, texelFetch can't pick a mip. The prefilter chain was +// written by the PrefilterDepth compute via imageStore, so the +// UV->texel mapping is internally consistent within the chain even +// across backends (no fragment-shader Y-flip in the producer). +// +// * `lpfloat` collapses to `float` (XE_GTAO_USE_HALF_FLOAT_PRECISION=0, +// XE_GTAO_FP32_DEPTHS=1, matches Esoterica's config). +// +// * SpatioTemporalNoise is called with temporalIndex=0 hardcoded +// (no TAA), producing the same noise pattern every frame. The +// original NoiseIndex UBO field is gone, see the comment under +// ub_gtao. +// +// * The "early-out for OOB threads" at the top of MainPass.esf is kept. +// Unlike PrefilterDepth there is no inter-thread groupshared +// reduction, so divergent control flow at the top is safe (no +// barriers). + +#pragma sokol @module gtao_main_pass + +#pragma sokol @ctype vec2 b3Vec2 +#pragma sokol @ctype vec4 Vec4 +#pragma sokol @ctype mat4 Mat4 + +#pragma sokol @cs cs + +// Per-shader subset of Esoterica's XeGTAO::GTAOConstants, only the +// fields MainPass actually reads (14 of 16). Explicit `gtao.X` instance +// name prevents SPIRV-Cross synthesizing one (`_NNN.X`), trimming to +// just-the-read fields prevents the GL linker's per-field dead-strip +// from producing `glGetUniformLocation` warnings. See the matching +// comment in gtao_prefilter_depth.glsl. +layout( binding = 0 ) uniform ub_gtao +{ + ivec2 ViewportSize; + vec2 ViewportPixelSize; + + vec2 NDCToViewMul; + vec2 NDCToViewAdd; + + vec2 NDCToViewMul_x_PixelSize; + float EffectRadius; + float EffectFalloffRange; + + float RadiusMultiplier; + float FinalValuePower; + float SampleDistributionPower; + float ThinOccluderCompensation; + + float DepthMIPSamplingOffset; + + // Runtime trace quality: slice count and steps-per-slice. Driven by + // the AmbientOcclusionQuality preset on the C side (Low/Medium/High/Ultra), the + // trace loops read these instead of hardcoded Ultra-tier constants. + float SliceCount; + float StepsPerSlice; +} +gtao; +// NoiseIndex intentionally omitted, see gtao_prefilter_depth.glsl. + +// Storage-image outputs. Bindings 0..1. r32f instead of r16f/r8 (see +// header, sokol-shdc storage_image access-format restriction). +layout( binding = 0, r32f ) uniform writeonly image2D out_noisy_ao; +layout( binding = 1, r32f ) uniform writeonly image2D out_edges; + +// Sampled textures. Binding base 2 (sokol-shdc shares the +// storage_image/texture bind-space across the compute stage, storage +// images take 0..1, so textures start at 2). The sampler is point-clamp, +// linear sampling on a prefiltered depth chain would inter-mip-level +// blend depth values which corrupts the trace (see XeGTAO.esh:476). +layout( binding = 2 ) uniform texture2D tex_raw_depth; +layout( binding = 3 ) uniform texture2D tex_prefilter_depth; +layout( binding = 0 ) uniform sampler smp_point_clamp; + +#pragma sokol @include ../common/xe_gtao_common.glsl + +// SpatioTemporalNoise, MainPass.esf:43-60 with the +// XE_GTAO_HILBERT_LUT_AVAILABLE branch removed (we generate the index +// in-shader, mirrors Esoterica's default). With NoiseIndex=0 the +// `288 * (temporalIndex % 64)` term is zero, the (288*0) is kept as a +// no-op so this function reads verbatim against the reference. +vec2 SpatioTemporalNoise( uvec2 pixCoord, int temporalIndex ) +{ + uint index = HilbertIndex( pixCoord.x, pixCoord.y ); + index += 288u * ( uint( temporalIndex ) % 64u ); + // R2 sequence, Roberts 2018. + return fract( 0.5 + float( index ) * vec2( 0.75487766624669276005, 0.5698402909980532659114 ) ); +} + +// XeGTAO.esh:897-921 with cardinal taps coming from texelFetch instead +// of GatherRed (see header). Identical math. +vec3 XeGTAO_ComputeViewspaceNormal( ivec2 pixCoord, GTAOConsts consts ) +{ + vec2 normalizedScreenPos = ( vec2( pixCoord ) + 0.5 ) * consts.ViewportPixelSize; + + // Clamp the 4 cardinal taps into the viewport. At the viewport edge + // we replicate the center pixel, same approximation as gather-with- + // sampler-clamp. + ivec2 vmax = gtao.ViewportSize - 1; + ivec2 cC = clamp( pixCoord, ivec2( 0 ), vmax ); + ivec2 cL = clamp( pixCoord + ivec2( -1, 0 ), ivec2( 0 ), vmax ); + ivec2 cR = clamp( pixCoord + ivec2( 1, 0 ), ivec2( 0 ), vmax ); + ivec2 cT = clamp( pixCoord + ivec2( 0, -1 ), ivec2( 0 ), vmax ); + ivec2 cB = clamp( pixCoord + ivec2( 0, 1 ), ivec2( 0 ), vmax ); + + float viewspaceZ = + XeGTAO_ScreenSpaceToViewSpaceDepth( texelFetch( sampler2D( tex_raw_depth, smp_point_clamp ), cC, 0 ).r, consts ); + float pixLZ = + XeGTAO_ScreenSpaceToViewSpaceDepth( texelFetch( sampler2D( tex_raw_depth, smp_point_clamp ), cL, 0 ).r, consts ); + float pixRZ = + XeGTAO_ScreenSpaceToViewSpaceDepth( texelFetch( sampler2D( tex_raw_depth, smp_point_clamp ), cR, 0 ).r, consts ); + float pixTZ = + XeGTAO_ScreenSpaceToViewSpaceDepth( texelFetch( sampler2D( tex_raw_depth, smp_point_clamp ), cT, 0 ).r, consts ); + float pixBZ = + XeGTAO_ScreenSpaceToViewSpaceDepth( texelFetch( sampler2D( tex_raw_depth, smp_point_clamp ), cB, 0 ).r, consts ); + + vec4 edgesLRTB = XeGTAO_CalculateEdges( viewspaceZ, pixLZ, pixRZ, pixTZ, pixBZ ); + + vec3 CENTER = XeGTAO_ComputeViewspacePosition( normalizedScreenPos, viewspaceZ, consts ); + vec3 LEFT = + XeGTAO_ComputeViewspacePosition( normalizedScreenPos + vec2( -1.0, 0.0 ) * consts.ViewportPixelSize, pixLZ, consts ); + vec3 RIGHT = + XeGTAO_ComputeViewspacePosition( normalizedScreenPos + vec2( 1.0, 0.0 ) * consts.ViewportPixelSize, pixRZ, consts ); + vec3 TOP = + XeGTAO_ComputeViewspacePosition( normalizedScreenPos + vec2( 0.0, -1.0 ) * consts.ViewportPixelSize, pixTZ, consts ); + vec3 BOTTOM = + XeGTAO_ComputeViewspacePosition( normalizedScreenPos + vec2( 0.0, 1.0 ) * consts.ViewportPixelSize, pixBZ, consts ); + return XeGTAO_CalculateNormal( edgesLRTB, CENTER, LEFT, RIGHT, TOP, BOTTOM ); +} + +// XeGTAO.esh:213-231. Stores the visibility/scale-divided term and +// returns it. `bentNormal` arg dropped, XE_GTAO_COMPUTE_BENT_NORMALS is +// undefined on our side (matches Esoterica). +float XeGTAO_OutputWorkingTerm( ivec2 pixCoord, float visibility ) +{ + visibility = clamp( visibility / XE_GTAO_OCCLUSION_TERM_SCALE, 0.0, 1.0 ); + imageStore( out_noisy_ao, pixCoord, vec4( visibility, 0.0, 0.0, 0.0 ) ); + return visibility; +} + +// XeGTAO.esh:270-617 with: +// * Cardinal taps via texelFetch (see header). +// * Bent-normals branch (`XE_GTAO_COMPUTE_BENT_NORMALS`) removed, +// undefined in our config. +// * In-place normals branch (`XE_GTAO_GENERATE_NORMALS_INPLACE`) always +// taken. The cardinal-tap reads above already happened, so this +// is just the same XeGTAO_CalculateNormal call as in +// XeGTAO_ComputeViewspaceNormal. We share the call by computing the +// normal in main before invoking MainPass, and pass it in. +// * Debug-viz (`XE_GTAO_SHOW_DEBUG_VIZ`, `XE_GTAO_SHOW_NORMALS`, etc.) +// branches dropped, we use the renderer's debug_view_mode plumbing +// instead. +// * `sliceCount`/`stepsPerSlice` come from the ub_gtao UBO (the +// AmbientOcclusionQuality preset on the C side), not the hardcoded 9/3 Ultra tier of +// MainPass.esf:135. The two `for` loops iterate `float` counters with a +// `<` comparison so the runtime bound cross-compiles cleanly, the +// trade-off is the inner loop can no longer be statically unrolled. +// * Edges are packed and written before the trace, exactly as in +// MainPass.esf. The Denoise pass reads them as bilateral weights. +// +// pixCoord = dispatchThreadID.xy. Returns the saturated visibility scalar +// for visualisation in the renderer's debug_view_mode == 4. +float XeGTAO_MainPass( ivec2 pixCoord, vec2 localNoise, vec3 viewspaceNormal, + float centerViewspaceZ, // value already fetched for normal recon + vec4 edgesLRTB, // ditto, written below + GTAOConsts consts ) +{ + vec2 normalizedScreenPos = ( vec2( pixCoord ) + 0.5 ) * consts.ViewportPixelSize; + float viewspaceZ = centerViewspaceZ; + + imageStore( out_edges, pixCoord, vec4( XeGTAO_PackEdges( edgesLRTB ), 0.0, 0.0, 0.0 ) ); + + // FP32 depth: push the center pixel slightly towards camera to avoid + // self-occlusion from depth imprecision. XeGTAO.esh:318-322. With + // positive linear view-Z + reverse-Z, "towards camera" is multiply by + // (1 - epsilon). + viewspaceZ *= 0.99999; + + vec3 pixCenterPos = XeGTAO_ComputeViewspacePosition( normalizedScreenPos, viewspaceZ, consts ); + vec3 viewVec = normalize( -pixCenterPos ); + + float sliceCount = consts.SliceCount; + float stepsPerSlice = consts.StepsPerSlice; + const float effectRadius = consts.EffectRadius * consts.RadiusMultiplier; + const float falloffRange = consts.EffectFalloffRange * effectRadius; + const float falloffFrom = effectRadius * ( 1.0 - consts.EffectFalloffRange ); + const float falloffMul = -1.0 / falloffRange; + const float falloffAdd = falloffFrom / falloffRange + 1.0; + const float sampleDistributionPower = consts.SampleDistributionPower; + const float thinOccluderCompensation = consts.ThinOccluderCompensation; + + float visibility = 0.0; + + { + const float noiseSlice = localNoise.x; + const float noiseSample = localNoise.y; + const float pixelTooCloseThreshold = 1.3; + + // Approx viewspace pixel size at pixCoord. XeGTAO.esh:377. + vec2 pixelDirRBViewspaceSizeAtCenterZ = vec2( viewspaceZ, viewspaceZ ) * consts.NDCToViewMul_x_PixelSize; + float screenspaceRadius = effectRadius / pixelDirRBViewspaceSizeAtCenterZ.x; + + // Fade out for small screen radii, XeGTAO.esh:382. + visibility += clamp( ( 10.0 - screenspaceRadius ) / 100.0, 0.0, 1.0 ) * 0.5; + + float minS = pixelTooCloseThreshold / screenspaceRadius; + + for ( float slice = 0.0; slice < sliceCount; slice += 1.0 ) + { + float sliceK = ( slice + noiseSlice ) / sliceCount; + float phi = sliceK * XE_GTAO_PI; + float cosPhi = cos( phi ); + float sinPhi = sin( phi ); + vec2 omega = vec2( cosPhi, -sinPhi ); + omega *= screenspaceRadius; + + vec3 directionVec = vec3( cosPhi, sinPhi, 0.0 ); + vec3 orthoDirectionVec = directionVec - ( dot( directionVec, viewVec ) * viewVec ); + vec3 axisVec = normalize( cross( orthoDirectionVec, viewVec ) ); + + vec3 projectedNormalVec = viewspaceNormal - axisVec * dot( viewspaceNormal, axisVec ); + + float signNorm = sign( dot( orthoDirectionVec, projectedNormalVec ) ); + float projectedNormalVecLength = length( projectedNormalVec ); + float cosNorm = clamp( dot( projectedNormalVec, viewVec ) / projectedNormalVecLength, 0.0, 1.0 ); + + float n = signNorm * XeGTAO_FastACos( cosNorm ); + + const float lowHorizonCos0 = cos( n + XE_GTAO_PI_HALF ); + const float lowHorizonCos1 = cos( n - XE_GTAO_PI_HALF ); + + float horizonCos0 = lowHorizonCos0; + float horizonCos1 = lowHorizonCos1; + + for ( float step_ = 0.0; step_ < stepsPerSlice; step_ += 1.0 ) + { + // R1 sequence, XeGTAO.esh:459. + float stepBaseNoise = ( slice + step_ * stepsPerSlice ) * 0.6180339887498948482; + float stepNoise = fract( noiseSample + stepBaseNoise ); + + float s = ( step_ + stepNoise ) / stepsPerSlice; + // step_, stepNoise (=fract(.)), stepsPerSlice are all >= 0 + // by construction, max(0, .) is redundant at runtime but + // silences HLSL's pow(negative, n) warning (X3571). + s = pow( max( 0.0, s ), sampleDistributionPower ); + s += minS; + + vec2 sampleOffset = s * omega; + float sampleOffsetLength = length( sampleOffset ); + + float mipLevel = + clamp( log2( sampleOffsetLength ) - consts.DepthMIPSamplingOffset, 0.0, XE_GTAO_DEPTH_MIP_LEVELS ); + + // Snap to pixel centers, XeGTAO.esh:481. + sampleOffset = round( sampleOffset ) * consts.ViewportPixelSize; + + vec2 sampleScreenPos0 = normalizedScreenPos + sampleOffset; + float SZ0 = textureLod( sampler2D( tex_prefilter_depth, smp_point_clamp ), sampleScreenPos0, mipLevel ).x; + vec3 samplePos0 = XeGTAO_ComputeViewspacePosition( sampleScreenPos0, SZ0, consts ); + + vec2 sampleScreenPos1 = normalizedScreenPos - sampleOffset; + float SZ1 = textureLod( sampler2D( tex_prefilter_depth, smp_point_clamp ), sampleScreenPos1, mipLevel ).x; + vec3 samplePos1 = XeGTAO_ComputeViewspacePosition( sampleScreenPos1, SZ1, consts ); + + vec3 sampleDelta0 = samplePos0 - pixCenterPos; + vec3 sampleDelta1 = samplePos1 - pixCenterPos; + float sampleDist0 = length( sampleDelta0 ); + float sampleDist1 = length( sampleDelta1 ); + + vec3 sampleHorizonVec0 = sampleDelta0 / sampleDist0; + vec3 sampleHorizonVec1 = sampleDelta1 / sampleDist1; + + // Esoterica branch: thin-object heuristic (XeGTAO.esh:518-524). + // XE_GTAO_USE_DEFAULT_CONSTANTS=0 path so falloffBase uses + // thinOccluderCompensation. With thinOccluderCompensation = 0 + // this is equivalent to the simpler XeGTAO.esh:516-517 form + // since the z-axis factor becomes 1. + float falloffBase0 = + length( vec3( sampleDelta0.x, sampleDelta0.y, sampleDelta0.z * ( 1.0 + thinOccluderCompensation ) ) ); + float falloffBase1 = + length( vec3( sampleDelta1.x, sampleDelta1.y, sampleDelta1.z * ( 1.0 + thinOccluderCompensation ) ) ); + float weight0 = clamp( falloffBase0 * falloffMul + falloffAdd, 0.0, 1.0 ); + float weight1 = clamp( falloffBase1 * falloffMul + falloffAdd, 0.0, 1.0 ); + + float shc0 = dot( sampleHorizonVec0, viewVec ); + float shc1 = dot( sampleHorizonVec1, viewVec ); + + shc0 = mix( lowHorizonCos0, shc0, weight0 ); + shc1 = mix( lowHorizonCos1, shc1, weight1 ); + + horizonCos0 = max( horizonCos0, shc0 ); + horizonCos1 = max( horizonCos1, shc1 ); + } + + // Slight over-darkening fudge, XeGTAO.esh:571. + projectedNormalVecLength = mix( projectedNormalVecLength, 1.0, 0.05 ); + + float h0 = -XeGTAO_FastACos( horizonCos1 ); + float h1 = XeGTAO_FastACos( horizonCos0 ); + float iarc0 = ( cosNorm + 2.0 * h0 * sin( n ) - cos( 2.0 * h0 - n ) ) * 0.25; + float iarc1 = ( cosNorm + 2.0 * h1 * sin( n ) - cos( 2.0 * h1 - n ) ) * 0.25; + float localVisibility = projectedNormalVecLength * ( iarc0 + iarc1 ); + visibility += localVisibility; + } + + visibility /= sliceCount; + // visibility is summed from non-negative localVisibility terms and + // divided by positive sliceCount, so always >= 0. max(0, .) is a + // no-op at runtime, silences HLSL's pow(negative, n) warning. + visibility = pow( max( 0.0, visibility ), consts.FinalValuePower ); + // Disallow total occlusion, XeGTAO.esh:597. + visibility = max( 0.03, visibility ); + } + + return XeGTAO_OutputWorkingTerm( pixCoord, visibility ); +} + +layout( local_size_x = 8, local_size_y = 8, local_size_z = 1 ) in; + +void main() +{ + ivec2 pixCoord = ivec2( gl_GlobalInvocationID.xy ); + if ( any( greaterThanEqual( pixCoord, gtao.ViewportSize ) ) ) + { + return; + } + + // Populate GTAOConsts from the UBO, gives the helpers in + // xe_gtao_common.glsl + the inlined XeGTAO_MainPass a single by- + // value argument matching the HLSL reference. + GTAOConsts consts; + consts.ViewportPixelSize = gtao.ViewportPixelSize; + consts.NDCToViewMul = gtao.NDCToViewMul; + consts.NDCToViewAdd = gtao.NDCToViewAdd; + consts.NDCToViewMul_x_PixelSize = gtao.NDCToViewMul_x_PixelSize; + consts.EffectRadius = gtao.EffectRadius; + consts.EffectFalloffRange = gtao.EffectFalloffRange; + consts.RadiusMultiplier = gtao.RadiusMultiplier; + consts.FinalValuePower = gtao.FinalValuePower; + consts.SampleDistributionPower = gtao.SampleDistributionPower; + consts.ThinOccluderCompensation = gtao.ThinOccluderCompensation; + consts.DepthMIPSamplingOffset = gtao.DepthMIPSamplingOffset; + consts.SliceCount = gtao.SliceCount; + consts.StepsPerSlice = gtao.StepsPerSlice; + + // Cardinal-tap reads happen inside ComputeViewspaceNormal, redo the + // center read so MainPass has its viewspaceZ + edges without + // re-fetching the 4 neighbours. Cheaper to repeat the 1-tap fetch + // than to plumb the 5-tap state through a return struct. + vec3 viewspaceNormal = XeGTAO_ComputeViewspaceNormal( pixCoord, consts ); + + ivec2 vmax = gtao.ViewportSize - 1; + float centerZ = XeGTAO_ScreenSpaceToViewSpaceDepth( + texelFetch( sampler2D( tex_raw_depth, smp_point_clamp ), clamp( pixCoord, ivec2( 0 ), vmax ), 0 ).r, consts ); + float leftZ = XeGTAO_ScreenSpaceToViewSpaceDepth( + texelFetch( sampler2D( tex_raw_depth, smp_point_clamp ), clamp( pixCoord + ivec2( -1, 0 ), ivec2( 0 ), vmax ), 0 ).r, + consts ); + float rightZ = XeGTAO_ScreenSpaceToViewSpaceDepth( + texelFetch( sampler2D( tex_raw_depth, smp_point_clamp ), clamp( pixCoord + ivec2( 1, 0 ), ivec2( 0 ), vmax ), 0 ).r, + consts ); + float topZ = XeGTAO_ScreenSpaceToViewSpaceDepth( + texelFetch( sampler2D( tex_raw_depth, smp_point_clamp ), clamp( pixCoord + ivec2( 0, -1 ), ivec2( 0 ), vmax ), 0 ).r, + consts ); + float botZ = XeGTAO_ScreenSpaceToViewSpaceDepth( + texelFetch( sampler2D( tex_raw_depth, smp_point_clamp ), clamp( pixCoord + ivec2( 0, 1 ), ivec2( 0 ), vmax ), 0 ).r, + consts ); + vec4 edgesLRTB = XeGTAO_CalculateEdges( centerZ, leftZ, rightZ, topZ, botZ ); + + vec2 noise = SpatioTemporalNoise( uvec2( pixCoord ), 0 ); + + XeGTAO_MainPass( pixCoord, noise, viewspaceNormal, centerZ, edgesLRTB, consts ); +} +#pragma sokol @end + +#pragma sokol @program prog cs diff --git a/samples/shaders/post/gtao_prefilter_depth.glsl b/samples/shaders/post/gtao_prefilter_depth.glsl new file mode 100644 index 0000000..e8c2a55 --- /dev/null +++ b/samples/shaders/post/gtao_prefilter_depth.glsl @@ -0,0 +1,248 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// GTAO PrefilterDepth compute shader. +// +// Port of Esoterica's PrefilterDepth.esf, which is XeGTAO's +// XeGTAO_PrefilterDepths16x16, a single 16x16-pixel tile per group, +// 8x8 threads, each thread handling 2x2 destination pixels. Builds the +// 5-mip prefiltered linear-depth chain consumed by the GTAO main pass. +// Mip0 is the raw input, mips 1..4 use the XeGTAO weighted- +// average depth-MIP filter which biases toward the closer of the four +// taps in each 2x2 footprint (suppresses thin-feature pulled mips). +// +// Departures from XeGTAO_PrefilterDepths16x16: +// +// * Input depth is **already positive linear view-Z** (render3d's +// R32F prepass target), not NDC reverse-Z. Esoterica's +// XeGTAO_ScreenSpaceToViewSpaceDepth call collapses to a pass- +// through, we just clamp. GTAOConstants.DepthUnpackConsts is +// therefore unused (kept in the UBO for layout parity). +// +// * Mip-0 fetches use texelFetch on the source texture instead +// GatherRed + offset(1,1). The mathematical result is identical +// (point-sampled raw texels at a 2x2 footprint), but texelFetch +// sidesteps the documented textureGather channel-ordering / +// Y-flip pitfalls. Cost is 4 texel reads vs 1 gather op, +// a single dispatch per frame, doesn't matter. +// +// * lpfloat is `float`. Matches Esoterica's +// XE_GTAO_USE_HALF_FLOAT_PRECISION=0 / XE_GTAO_FP32_DEPTHS=1 +// configuration, min16float / float16_t paths don't survive +// sokol-shdc cleanly. +// +// Dispatch: ceil(width / 16) x ceil(height / 16) x 1. Each group writes +// a 16x16 mip-0 region, 8x8 mip-1, 4x4 mip-2, 2x2 mip-3, 1x1 mip-4. +// +// Esoterica early-returns OOB threads at the top of the shader. FXC +// (D3D11) rejects that as "thread sync operation in varying flow" +// (HLSL X3663) when the subsequent barrier participations diverge. +// We instead let every thread run the full reduction so all barriers +// see uniform participation, and guard each imageStore individually +// against the viewport bound. Source-texel reads are clamped to the +// in-bounds edge so OOB threads contribute consistent (replicated- +// edge) depth values to the mip-1..4 reductions. These values are +// only used to keep the groupshared scratch populated, the actual +// mip writes for those threads are skipped by the bounds guard. + +#pragma sokol @module gtao_prefilter_depth + +#pragma sokol @ctype vec2 b3Vec2 +#pragma sokol @ctype vec4 Vec4 +#pragma sokol @ctype mat4 Mat4 + +#pragma sokol @cs cs + +// Per-shader subset of Esoterica's XeGTAO::GTAOConstants, only the +// fields PrefilterDepth's `XeGTAO_DepthMIPFilter` and `main ` actually +// read. The block has an explicit instance name (`gtao.X`) so SPIRV- +// Cross doesn't synthesize one (`_NNN.X`) when emitting GLSL for the GL +// backend. Without that, each unread field that the driver's GLSL +// linker dead-strips triggers a sokol_gfx `glGetUniformLocation` warning +// with an unreadable synthetic name. Keeping the block trimmed to only +// the read fields means there's nothing for the linker to strip. +layout(binding = 0) uniform ub_gtao +{ + ivec2 ViewportSize; + float EffectRadius; + float EffectFalloffRange; + float RadiusMultiplier; +} gtao; + +// Outputs: one storage_image per mip level. R32F write-only. Each mip +// has its own bind slot (0..4), sokol-gfx wires each to a sg_view that +// targets a specific mip of the 5-mip prefilterDepth image. +layout(binding = 0, r32f) uniform writeonly image2D out_depth0; +layout(binding = 1, r32f) uniform writeonly image2D out_depth1; +layout(binding = 2, r32f) uniform writeonly image2D out_depth2; +layout(binding = 3, r32f) uniform writeonly image2D out_depth3; +layout(binding = 4, r32f) uniform writeonly image2D out_depth4; + +// Source: full-res positive linear view-Z. Bound as a sampled texture so +// texelFetch is available. The sampler is point-clamp (texelFetch ignores +// it but sokol-gfx requires a sampler binding for any texture binding). +// Binding 5 because sokol-shdc shares the storage_image/texture bind- +// space across the compute stage even though the underlying backends +// use disjoint SRV/UAV register banks, storage images take 0..4 so the +// texture starts at 5. +layout(binding = 5) uniform texture2D tex_src_depth; +layout(binding = 0) uniform sampler smp_src_depth; + +// XeGTAO_ClampDepth, clamps to fp32 finite. Matches XeGTAO.esh:648-655 +// for the XE_GTAO_USE_HALF_FLOAT_PRECISION=0 branch (FLT_MAX upper +// bound). Our sky sentinel of 1e9 sits comfortably below this. +float XeGTAO_ClampDepth(float depth) { + return clamp(depth, 0.0, 3.402823466e+38); +} + +// XeGTAO_DepthMIPFilter, weighted average that biases toward the +// closest tap (smallest depth) and suppresses contributions from taps +// outside an effect-radius-scaled falloff window. Verbatim port +// XeGTAO.esh:619-644, with XE_GTAO_USE_DEFAULT_CONSTANTS=0 branches +// since we drive everything from the UBO. +float XeGTAO_DepthMIPFilter(float depth0, float depth1, float depth2, float depth3) { + float maxDepth = max(max(depth0, depth1), max(depth2, depth3)); + +const float depthRangeScaleFactor = 0.75; // "found empirically :)" XeGTAO.esh:624 +float effectRadius = depthRangeScaleFactor * gtao.EffectRadius * gtao.RadiusMultiplier; +float falloffRange = gtao.EffectFalloffRange * effectRadius; +float falloffFrom = effectRadius * (1.0 - gtao.EffectFalloffRange); +float falloffMul = -1.0 / falloffRange; +float falloffAdd = falloffFrom / falloffRange + 1.0; + +float weight0 = clamp((maxDepth - depth0) * falloffMul + falloffAdd, 0.0, 1.0); +float weight1 = clamp((maxDepth - depth1) * falloffMul + falloffAdd, 0.0, 1.0); +float weight2 = clamp((maxDepth - depth2) * falloffMul + falloffAdd, 0.0, 1.0); +float weight3 = clamp((maxDepth - depth3) * falloffMul + falloffAdd, 0.0, 1.0); + +float weightSum = weight0 + weight1 + weight2 + weight3; +return (weight0 * depth0 + weight1 * depth1 + +weight2 * depth2 + weight3 * depth3) / weightSum; +} + +// Mip-2..4 inter-thread reduction scratch. groupshared, written by the +// mip-N producer threads and read by the mip-(N+1) producers after a +// barrier. Mirrors XeGTAO.esh:657. +shared float g_scratchDepths[8][8]; + +layout(local_size_x = 8, local_size_y = 8, local_size_z = 1)in; + +void main() { +ivec2 dispatchThreadID = ivec2(gl_GlobalInvocationID.xy); +ivec2 groupThreadID = ivec2(gl_LocalInvocationID.xy); +ivec2 viewportMax = ivec2(gtao.ViewportSize) - 1; + +// MIP 0 +// Esoterica reads via GatherRed at the texel-corner UV with offset +// (1,1), we read the same four texels via texelFetch to avoid the +// textureGather channel-ordering / backend-Y-flip ambiguity (see +// header). Indexing matches Esoterica's (depth0, depth1, depth2, +// depth3) = (top-left, top-right, bottom-left, bottom-right) within +// the 2x2 destination block. Source coords are clamped to the +// in-bounds edge so OOB threads still feed valid (replicated-edge) +// depths into the mip-1..4 reductions, the actual mip writes for +// those threads are gated below. +ivec2 pixCoord = dispatchThreadID * 2; +ivec2 p0 = clamp(pixCoord + ivec2(0, 0), ivec2(0), viewportMax); +ivec2 p1 = clamp(pixCoord + ivec2(1, 0), ivec2(0), viewportMax); +ivec2 p2 = clamp(pixCoord + ivec2(0, 1), ivec2(0), viewportMax); +ivec2 p3 = clamp(pixCoord + ivec2(1, 1), ivec2(0), viewportMax); +float depth0 = XeGTAO_ClampDepth(texelFetch(sampler2D(tex_src_depth, smp_src_depth), p0, 0).r); +float depth1 = XeGTAO_ClampDepth(texelFetch(sampler2D(tex_src_depth, smp_src_depth), p1, 0).r); +float depth2 = XeGTAO_ClampDepth(texelFetch(sampler2D(tex_src_depth, smp_src_depth), p2, 0).r); +float depth3 = XeGTAO_ClampDepth(texelFetch(sampler2D(tex_src_depth, smp_src_depth), p3, 0).r); + +if (all(lessThan(pixCoord + ivec2(0, 0), ivec2(gtao.ViewportSize)))) { + imageStore(out_depth0, pixCoord + ivec2(0, 0), vec4(depth0, 0.0, 0.0, 0.0)); +} +if (all(lessThan(pixCoord + ivec2(1, 0), ivec2(gtao.ViewportSize)))) { + imageStore(out_depth0, pixCoord + ivec2(1, 0), vec4(depth1, 0.0, 0.0, 0.0)); +} +if (all(lessThan(pixCoord + ivec2(0, 1), ivec2(gtao.ViewportSize)))) { + imageStore(out_depth0, pixCoord + ivec2(0, 1), vec4(depth2, 0.0, 0.0, 0.0)); +} +if (all(lessThan(pixCoord + ivec2(1, 1), ivec2(gtao.ViewportSize)))) { + imageStore(out_depth0, pixCoord + ivec2(1, 1), vec4(depth3, 0.0, 0.0, 0.0)); +} + +// MIP 1 +// Every thread produces one mip-1 candidate (always stored in +// scratch so the mip-2 reduction has a uniform view), conditionally +// written to the mip-1 image only if dispatchThreadID is in bounds. +float dm1 = XeGTAO_DepthMIPFilter(depth0, depth1, depth2, depth3); +if (all(lessThan(dispatchThreadID, ivec2(gtao.ViewportSize)))) { + imageStore(out_depth1, dispatchThreadID, vec4(dm1, 0.0, 0.0, 0.0)); +} +g_scratchDepths[groupThreadID.x][groupThreadID.y] = dm1; + +barrier(); + +// MIP 2 +// 2x2 reduction over the group's 8x8 mip-1 footprint, one thread per +// mip-2 texel, picked at the (x%2,y%2)==(0,0) corner. Reads stride 1. +// The reduction itself happens uniformly (predicated only on local +// group coords), the bounds check gates the imageStore, never the +// barrier path. +float dm2 = 0.0; +bool isMip2Producer = all(equal(groupThreadID & ivec2(1), ivec2(0))); +if (isMip2Producer) { + float inTL = g_scratchDepths[groupThreadID.x + 0][groupThreadID.y + 0]; + float inTR = g_scratchDepths[groupThreadID.x + 1][groupThreadID.y + 0]; + float inBL = g_scratchDepths[groupThreadID.x + 0][groupThreadID.y + 1]; + float inBR = g_scratchDepths[groupThreadID.x + 1][groupThreadID.y + 1]; + + dm2 = XeGTAO_DepthMIPFilter(inTL, inTR, inBL, inBR); + // gl_GlobalInvocationID is unsigned by spec -> dispatchThreadID is + // always >= 0, so an unsigned right-shift produces the same value as + // `dispatchThreadID / 2` without the HLSL signed-divide warning + // (X3556). Compute once + reuse for the bounds-check + imageStore. + ivec2 dispatchID2 = ivec2(uvec2(dispatchThreadID) >> 1u); + if (all(lessThan(dispatchID2, ivec2(gtao.ViewportSize)))) { + imageStore(out_depth2, dispatchID2, vec4(dm2, 0.0, 0.0, 0.0)); + } + g_scratchDepths[groupThreadID.x][groupThreadID.y] = dm2; +} + +barrier(); + +// MIP 3 +// Reads stride 2 from the same scratch slab, one mip-3 texel per +// 4x4 thread block, picked at the (x%4,y%4)==(0,0) corner. +float dm3 = 0.0; +bool isMip3Producer = all(equal(groupThreadID & ivec2(3), ivec2(0))); +if (isMip3Producer) { + float inTL = g_scratchDepths[groupThreadID.x + 0][groupThreadID.y + 0]; + float inTR = g_scratchDepths[groupThreadID.x + 2][groupThreadID.y + 0]; + float inBL = g_scratchDepths[groupThreadID.x + 0][groupThreadID.y + 2]; + float inBR = g_scratchDepths[groupThreadID.x + 2][groupThreadID.y + 2]; + + dm3 = XeGTAO_DepthMIPFilter(inTL, inTR, inBL, inBR); + ivec2 dispatchID4 = ivec2(uvec2(dispatchThreadID) >> 2u); + if (all(lessThan(dispatchID4, ivec2(gtao.ViewportSize)))) { + imageStore(out_depth3, dispatchID4, vec4(dm3, 0.0, 0.0, 0.0)); + } + g_scratchDepths[groupThreadID.x][groupThreadID.y] = dm3; +} + +barrier(); + +// MIP 4 +// Final reduction, single thread per group writes a single texel. +// Esoterica's commented-out scratch write at the end is dead code +// (no consumer), we drop the comment. +if (all(equal(groupThreadID, ivec2(0)))) { + float inTL = g_scratchDepths[0][0]; + float inTR = g_scratchDepths[4][0]; + float inBL = g_scratchDepths[0][4]; + float inBR = g_scratchDepths[4][4]; + + float dm4 = XeGTAO_DepthMIPFilter(inTL, inTR, inBL, inBR); + ivec2 dispatchID8 = ivec2(uvec2(dispatchThreadID) >> 3u); + if (all(lessThan(dispatchID8, ivec2(gtao.ViewportSize)))) { + imageStore(out_depth4, dispatchID8, vec4(dm4, 0.0, 0.0, 0.0)); + } +} +} +#pragma sokol @end + +#pragma sokol @program prog cs diff --git a/samples/shaders/post/highlight_outline.glsl b/samples/shaders/post/highlight_outline.glsl new file mode 100644 index 0000000..d695fb0 --- /dev/null +++ b/samples/shaders/post/highlight_outline.glsl @@ -0,0 +1,132 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Highlight outline post-pass. +// +// Fullscreen triangle (no vbuf). Reads the R8 UNORM highlight mask written by +// the mask_sphere/mask_capsule/mask_hull pipelines. Each non-zero pixel is +// inside a highlighted shape (encoded 0.5 = hover, 1.0 = select). The shader +// detects silhouette pixels (center is empty but a neighbor is filled) +// and emits the appropriate outline color premultiplied for blend-over the +// resolved scene color. +// +// Two ring radii tunable from C: hoverThicknessPx, selectThicknessPx. +// Select takes priority over hover when both rings catch a neighbor. + +#pragma sokol @module highlight_outline + +#pragma sokol @ctype vec4 Vec4 + +#pragma sokol @vs vs +// Fullscreen triangle by gl_VertexIndex, 3 verts covering NDC +// [-1, 3] x [-1, 3], clipped to the [-1,1] viewport. No vertex buffer. +void main() +{ + vec2 p = vec2( ( gl_VertexIndex == 1 ) ? 3.0 : -1.0, ( gl_VertexIndex == 2 ) ? 3.0 : -1.0 ); + gl_Position = vec4( p, 0.0, 1.0 ); +} +#pragma sokol @end + +#pragma sokol @fs fs + +layout( binding = 0 ) uniform ub_pass +{ + vec4 hover_color; // premultiplied linear RGBA + vec4 select_color; // premultiplied linear RGBA + vec4 thickness_px; // .x = hover thickness, .y = select thickness, .zw unused +}; + +layout( binding = 0 ) uniform texture2D tex_mask; +layout( binding = 0 ) uniform sampler smp_mask; + +layout( location = 0 ) out vec4 out_color; + +// Discrete-kind threshold. 0.5 encodes hover, 1.0 encodes select. Threshold +// at 0.75 splits them. Values < 0.25 are "empty". +const float KIND_EMPTY_THRESHOLD = 0.25; +const float KIND_SELECT_THRESHOLD = 0.75; + +void main() +{ + ivec2 px = ivec2( gl_FragCoord.xy ); + ivec2 sz = textureSize( sampler2D( tex_mask, smp_mask ), 0 ); + + // Inside a highlighted shape, keep the scene color (output 0 alpha). + float center = texelFetch( sampler2D( tex_mask, smp_mask ), px, 0 ).x; + if ( center > KIND_EMPTY_THRESHOLD ) + { + out_color = vec4( 0.0 ); + return; + } + + int hoverR = clamp( int( thickness_px.x + 0.5 ), 1, 4 ); + int selectR = clamp( int( thickness_px.y + 0.5 ), 1, 4 ); + int maxR = max( hoverR, selectR ); + + // Track the strongest neighbor kind found, and the smallest radius at + // which we found a select-kind / hover-kind neighbor. The outline rules: + // * a select-kind pixel anywhere within selectR -> draw select + // * else a hover-kind pixel within hoverR -> draw hover + // * else a hover-kind pixel within selectR -> still draw hover + // (so the wider ring of a hover-only shape stays visible if the + // user widened thickness). + bool sawSelectInSelectR = false; + bool sawHoverInHoverR = false; + bool sawHoverInSelectR = false; + + for ( int r = 1; r <= maxR; ++r ) + { + for ( int i = 0; i < 4; ++i ) + { + ivec2 off; + if ( i == 0 ) + off = ivec2( r, 0 ); + else if ( i == 1 ) + off = ivec2( -r, 0 ); + else if ( i == 2 ) + off = ivec2( 0, r ); + else + off = ivec2( 0, -r ); + + ivec2 q = px + off; + if ( q.x < 0 || q.y < 0 || q.x >= sz.x || q.y >= sz.y ) + continue; + float k = texelFetch( sampler2D( tex_mask, smp_mask ), q, 0 ).x; + if ( k <= KIND_EMPTY_THRESHOLD ) + continue; + + if ( k >= KIND_SELECT_THRESHOLD ) + { + if ( r <= selectR ) + sawSelectInSelectR = true; + } + else + { + if ( r <= hoverR ) + sawHoverInHoverR = true; + if ( r <= selectR ) + sawHoverInSelectR = true; + } + } + } + + if ( sawSelectInSelectR ) + { + out_color = select_color; + return; + } + if ( sawHoverInHoverR ) + { + out_color = hover_color; + return; + } + if ( sawHoverInSelectR ) + { + out_color = hover_color; + return; + } + out_color = vec4( 0.0 ); +} +#pragma sokol @end + +#pragma sokol @program prog vs fs diff --git a/samples/shaders/post/mask_capsule.glsl b/samples/shaders/post/mask_capsule.glsl new file mode 100644 index 0000000..61c6754 --- /dev/null +++ b/samples/shaders/post/mask_capsule.glsl @@ -0,0 +1,164 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Highlight mask, capsule impostor. +// +// Stripped sibling of depth_only_capsule. Same OBB proxy + analytic +// ray-capsule intersection in the FS, outputs a uint highlight kind to the +// R8_UINT mask attachment. Writes gl_FragDepth so the GREATER_EQUAL depth +// test compares against the prepass depth at the analytic surface. + +#pragma sokol @module mask_capsule + +#pragma sokol @ctype mat4 Mat4 +#pragma sokol @ctype vec4 Vec4 +#pragma sokol @ctype vec3 b3Vec3 + +#pragma sokol @vs vs + +layout( binding = 0 ) uniform ub_frame +{ + mat4 view_proj; +}; + +struct instance +{ + vec4 xform_row0; // .xyz = R row 0, .w = center.x + vec4 xform_row1; // .xyz = R row 1, .w = center.y + vec4 xform_row2; // .xyz = R row 2, .w = center.z + vec4 params; // .x = halfLength, .y = radius, .z = highlight kind (float) +}; + +layout( binding = 0 ) readonly buffer instances +{ + instance items[]; +}; + +in vec3 in_pos; // unit-cube corner, half-extent 0.5 + +sample out vec3 v_world_pos_proxy; +flat out vec3 v_center; +flat out float v_half_length; +flat out float v_radius; +flat out vec3 v_axis_x_world; +flat out float v_kind; + +void main() +{ + instance inst = items[gl_InstanceIndex]; + vec3 center = vec3( inst.xform_row0.w, inst.xform_row1.w, inst.xform_row2.w ); + float halfLength = inst.params.x; + float radius = inst.params.y; + + vec3 obj_pos = vec3( in_pos.x * 2.0 * ( halfLength + radius ), in_pos.y * 2.0 * radius, in_pos.z * 2.0 * radius ); + vec3 world_pos = center + vec3( dot( inst.xform_row0.xyz, obj_pos ), dot( inst.xform_row1.xyz, obj_pos ), + dot( inst.xform_row2.xyz, obj_pos ) ); + + v_world_pos_proxy = world_pos; + v_center = center; + v_half_length = halfLength; + v_radius = radius; + v_axis_x_world = vec3( inst.xform_row0.x, inst.xform_row1.x, inst.xform_row2.x ); + v_kind = inst.params.z; + + gl_Position = view_proj * vec4( world_pos, 1.0 ); +} +#pragma sokol @end + +#pragma sokol @fs fs + +layout( binding = 1 ) uniform ub_pass +{ + mat4 view_proj; // for reverse-Z gl_FragDepth + vec4 camera_pos; // .xyz = world camera position +}; + +sample in vec3 v_world_pos_proxy; +flat in vec3 v_center; +flat in float v_half_length; +flat in float v_radius; +flat in vec3 v_axis_x_world; +flat in float v_kind; + +layout( location = 0 ) out vec4 out_kind; + +void main() +{ + vec3 ro = camera_pos.xyz; + vec3 rd = normalize( v_world_pos_proxy - ro ); + + vec3 axis = v_axis_x_world; + vec3 pa = v_center - v_half_length * axis; + vec3 pb = v_center + v_half_length * axis; + + vec3 ba = pb - pa; + vec3 oa = ro - pa; + float baba = dot( ba, ba ); + float bard = dot( ba, rd ); + float baoa = dot( ba, oa ); + float rdoa = dot( rd, oa ); + float oaoa = dot( oa, oa ); + + float a_c = baba - bard * bard; + float b_c = baba * rdoa - baoa * bard; + float c_c = baba * oaoa - baoa * baoa - v_radius * v_radius * baba; + float h_c = b_c * b_c - a_c * c_c; + + float t = -1.0; + if ( h_c >= 0.0 && a_c > 1e-8 ) + { + float t_body = ( -b_c - sqrt( h_c ) ) / a_c; + float y = baoa + t_body * bard; + if ( t_body > 0.0 && y > 0.0 && y < baba ) + { + t = t_body; + } + } + // Cap A. + { + vec3 oc = ro - pa; + float b = dot( oc, rd ); + float c = dot( oc, oc ) - v_radius * v_radius; + float h = b * b - c; + if ( h >= 0.0 ) + { + float tc = -b - sqrt( h ); + if ( tc > 0.0 && ( t < 0.0 || tc < t ) ) + { + vec3 hit = ro + tc * rd; + if ( dot( hit - pa, axis ) <= 0.0 ) + t = tc; + } + } + } + // Cap B. + { + vec3 oc = ro - pb; + float b = dot( oc, rd ); + float c = dot( oc, oc ) - v_radius * v_radius; + float h = b * b - c; + if ( h >= 0.0 ) + { + float tc = -b - sqrt( h ); + if ( tc > 0.0 && ( t < 0.0 || tc < t ) ) + { + vec3 hit = ro + tc * rd; + if ( dot( hit - pb, axis ) >= 0.0 ) + t = tc; + } + } + } + + if ( t < 0.0 ) + discard; + + vec3 hit_world = ro + t * rd; + vec4 hit_clip = view_proj * vec4( hit_world, 1.0 ); + gl_FragDepth = hit_clip.z / hit_clip.w; + + // R8 UNORM mask: 1.0=hover, 2.0=select -> 0.5, 1.0. + out_kind = vec4( v_kind * 0.5, 0.0, 0.0, 1.0 ); +} +#pragma sokol @end + +#pragma sokol @program prog vs fs diff --git a/samples/shaders/post/mask_hull.glsl b/samples/shaders/post/mask_hull.glsl new file mode 100644 index 0000000..33b9b8d --- /dev/null +++ b/samples/shaders/post/mask_hull.glsl @@ -0,0 +1,78 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Highlight mask, convex hull (triangle-rasterized). +// +// Same vertex math as depth_only_geom (transform + per-instance scale), but the +// FS just emits the highlight kind into the R8_UINT mask. Rasterized depth +// is correct as-is, no gl_FragDepth write. Pipeline depth-tests GREATER_EQUAL +// against the prepass depth. + +#pragma sokol @module mask_hull + +#pragma sokol @ctype mat4 Mat4 +#pragma sokol @ctype vec4 Vec4 +#pragma sokol @ctype vec3 b3Vec3 + +#pragma sokol @vs vs + +layout( binding = 0 ) uniform ub_frame +{ + mat4 view_proj; +}; + +layout( binding = 2 ) uniform ub_draw +{ + ivec4 inst_base; // .x = base index into the hull-mask instance array +}; + +struct instance +{ + vec4 xform_row0; + vec4 xform_row1; + vec4 xform_row2; + vec4 scale_kind; // .xyz = per-instance scale, .w = highlight kind +}; + +layout( binding = 0 ) readonly buffer instances +{ + instance items[]; +}; + +// Position-only input. The shared geom vbo carries position+normal +// (stride 24 bytes), but the mask FS only needs world position. We +// don't declare an `in_normal` attribute so the GL linker doesn't strip +// it and warn. The C-side pipeline desc skips the in_normal binding to +// match. +in vec3 in_pos; + +flat out float v_kind; + +void main() +{ + instance inst = items[inst_base.x + gl_InstanceIndex]; + + vec3 scaled_pos = in_pos * inst.scale_kind.xyz; + vec4 local_pos = vec4( scaled_pos, 1.0 ); + vec3 world_pos = + vec3( dot( inst.xform_row0, local_pos ), dot( inst.xform_row1, local_pos ), dot( inst.xform_row2, local_pos ) ); + + v_kind = inst.scale_kind.w; + gl_Position = view_proj * vec4( world_pos, 1.0 ); +} +#pragma sokol @end + +#pragma sokol @fs fs + +flat in float v_kind; + +layout( location = 0 ) out vec4 out_kind; + +void main() +{ + // R8 UNORM mask: 1.0=hover, 2.0=select -> 0.5, 1.0. + out_kind = vec4( v_kind * 0.5, 0.0, 0.0, 1.0 ); +} +#pragma sokol @end + +#pragma sokol @program prog vs fs diff --git a/samples/shaders/post/mask_sphere.glsl b/samples/shaders/post/mask_sphere.glsl new file mode 100644 index 0000000..4919096 --- /dev/null +++ b/samples/shaders/post/mask_sphere.glsl @@ -0,0 +1,103 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Highlight mask, sphere impostor. +// +// Stripped sibling of depth_only_sphere. Same bounding-cube proxy + analytic +// ray-sphere intersection in the FS, outputs a uint highlight kind to the +// R8_UINT mask attachment instead of writing depth. Depth-TEST against the +// existing GTAO prepass depth (reverse-Z GREATER, no depth write) so +// highlighted shapes behind opaque geometry don't bleed outlines. + +#pragma sokol @module mask_sphere + +#pragma sokol @ctype mat4 Mat4 +#pragma sokol @ctype vec4 Vec4 +#pragma sokol @ctype vec3 b3Vec3 + +#pragma sokol @vs vs + +layout( binding = 0 ) uniform ub_frame +{ + mat4 view_proj; +}; + +struct instance +{ + vec4 center_radius; // .xyz = center, .w = radius + vec4 kind; // .x = highlight kind (1.0 = hover, 2.0 = select), .yzw unused +}; + +layout( binding = 0 ) readonly buffer instances +{ + instance items[]; +}; + +in vec3 in_pos; // unit-cube corner, half-extent 0.5 + +sample out vec3 v_world_pos_proxy; +flat out vec3 v_center; +flat out float v_radius; +flat out float v_kind; + +void main() +{ + instance inst = items[gl_InstanceIndex]; + vec3 center = inst.center_radius.xyz; + float radius = inst.center_radius.w; + + vec3 world_pos = center + ( 2.0 * radius ) * in_pos; + + v_world_pos_proxy = world_pos; + v_center = center; + v_radius = radius; + v_kind = inst.kind.x; + + gl_Position = view_proj * vec4( world_pos, 1.0 ); +} +#pragma sokol @end + +#pragma sokol @fs fs + +layout( binding = 1 ) uniform ub_pass +{ + mat4 view_proj; // for reverse-Z gl_FragDepth + vec4 camera_pos; // .xyz = world camera position +}; + +sample in vec3 v_world_pos_proxy; +flat in vec3 v_center; +flat in float v_radius; +flat in float v_kind; + +layout( location = 0 ) out vec4 out_kind; + +void main() +{ + vec3 ro = camera_pos.xyz; + vec3 rd = normalize( v_world_pos_proxy - ro ); + + vec3 oc = ro - v_center; + float b = dot( oc, rd ); + float c2 = dot( oc, oc ) - v_radius * v_radius; + float h = b * b - c2; + if ( h < 0.0 ) + discard; + float t = -b - sqrt( h ); + if ( t < 0.0 ) + discard; + + // Write analytic surface depth so the depth test compares at the + // sphere's true surface, not at the bounding-cube proxy. Matches the + // prepass depth's contents bit-for-bit, so GREATER_EQUAL passes when + // unoccluded and fails when an opaque shape is in front. + vec3 hit_world = ro + t * rd; + vec4 hit_clip = view_proj * vec4( hit_world, 1.0 ); + gl_FragDepth = hit_clip.z / hit_clip.w; + + // R8 UNORM mask: 1.0=hover, 2.0=select -> 0.5, 1.0. + out_kind = vec4( v_kind * 0.5, 0.0, 0.0, 1.0 ); +} +#pragma sokol @end + +#pragma sokol @program prog vs fs diff --git a/samples/shaders/post/tonemap.glsl b/samples/shaders/post/tonemap.glsl new file mode 100644 index 0000000..908c1e8 --- /dev/null +++ b/samples/shaders/post/tonemap.glsl @@ -0,0 +1,138 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// AgX tonemap fullscreen pass. +// +// Reads the resolved HDR scene color (RGBA16F), applies an exposure stop, +// runs AgX (Standard look, identity ASC-CDL), and writes display-encoded +// sRGB to a linear-format (non-sRGB) framebuffer. +// +// Implementation is the "Minimal AgX" port of Troy Sobotka's reference +// (https://iolite-engine.com/blog_posts/minimal_agx_implementation), +// the same shader form used by Three.js and Filament. The 6th-order +// polynomial in agxDefaultContrastApprox is a fit of the AgX sigmoid, +// mean error^2 vs. the reference curve is ~3.7e-6. +// +// Color path: +// 1. linear sRGB HDR (scene) +// 2. x exposure (pow(2, ev)) +// 3. AgX inset matrix -> "AgX color space" +// 4. clamp(log2(.), MIN_EV, MAX_EV) -> [0,1] log-space +// 5. polynomial sigmoid -> [0,1] log-space, S-shaped +// 6. AgX look -> luma-preserving saturation (params.z, 1.0 = identity) +// 7. AgX outset matrix -> display-encoded sRGB (no further EOTF) +// +// Output target format is linear unorm (BGRA8/RGBA8, NOT SRGB), so the +// outset-matrix result writes verbatim, no pow(., 2.2) at the end. If +// the target ever becomes sRGB-formatted (driver does linear->sRGB encode +// on store), add `v = pow(max(v, 0.0), vec3(2.2))` after the outset +// matrix to give the driver linear values. +// +// UV handling: the scene RT was written by the rasterizer at SV_Position +// (top-origin on D3D11/Metal/WGPU, bottom-origin on GL). Sampling it here +// with `v_uv = ndc * 0.5 + 0.5` reads the wrong row on D3D11/Metal/WGPU +// because v_uv.y=1 always means "max-V texel", which is top on GL but +// bottom on the others. The C side passes a backend-conditional uvYSign +// (+1 GL, -1 D3D/Metal/WGPU), we flip v_uv.y at sample time on the +// negative-sign backends. Same pattern as brdf_lut.glsl, just applied at +// the consumer (sample-time) instead of the producer (write-time). + +#pragma sokol @module tonemap + +#pragma sokol @ctype vec4 Vec4 + +#pragma sokol @vs vs + +out vec2 v_uv; + +void main() +{ + vec2 ndc = vec2( float( ( gl_VertexIndex << 1 ) & 2 ), float( gl_VertexIndex & 2 ) ) * 2.0 - 1.0; + v_uv = ndc * 0.5 + 0.5; + gl_Position = vec4( ndc, 0.0, 1.0 ); +} +#pragma sokol @end + +#pragma sokol @fs fs + +layout( binding = 0 ) uniform ub_tonemap +{ + // .x = ev (exposure stops, final multiplier = pow(2, ev)) + // .y = uvYSign (+1 GL, -1 D3D11/Metal/WGPU), flips sample-time v_uv.y + // so the scene RT reads back upright on every backend. + // .z = AgX look saturation (1.0 = identity / stock AgX Standard look) + // .w reserved + vec4 params; +}; + +layout( binding = 0 ) uniform texture2D tex_scene; +layout( binding = 0 ) uniform sampler smp_scene; + +in vec2 v_uv; +out vec4 out_color; + +// 6th-order polynomial fit of the AgX sigmoid (Sobotka). Operates on the +// [0,1] log-space encoded value, output stays in [0,1] log-space but +// S-shaped to match the AgX contrast curve. +vec3 agxDefaultContrastApprox( vec3 x ) +{ + vec3 x2 = x * x; + vec3 x4 = x2 * x2; + return +15.5 * x4 * x2 - 40.14 * x4 * x + 31.96 * x4 - 6.868 * x2 * x + 0.4298 * x2 + 0.1191 * x - 0.00232; +} + +vec3 agx( vec3 v ) +{ + // Inset matrix: linear sRGB primaries -> AgX inset primaries. + const mat3 inset = mat3( 0.842479062253094, 0.0423282422610123, 0.0423756549057051, 0.0784335999999992, 0.878468636469772, + 0.0784336, 0.0792237451477643, 0.0791661274605434, 0.879142973793104 ); + const float MIN_EV = -12.47393; + const float MAX_EV = 4.026069; + + v = inset * v; + // Floor to a tiny positive so log2 stays finite at black. + v = max( v, vec3( 1.0e-10 ) ); + v = clamp( log2( v ), MIN_EV, MAX_EV ); + v = ( v - MIN_EV ) / ( MAX_EV - MIN_EV ); + v = agxDefaultContrastApprox( v ); + return v; +} + +vec3 agxOutset( vec3 v ) +{ + // Inverse of the inset matrix, brings the sigmoid output back to display + // sRGB primaries. Result is display-encoded sRGB (ready for an unorm RT). + const mat3 outset = mat3( 1.19687900512017, -0.0528968517574562, -0.0529716355144438, -0.0980208811401368, 1.15190312990417, + -0.0980434501171241, -0.0990297440797205, -0.0989611768448433, 1.15107367264116 ); + return outset * v; +} + +// AgX "look": luma-preserving saturation, applied to the sigmoid output +// while it's still in AgX-encoded [0,1] space (before the outset matrix). +// saturation 1.0 is identity: AgX's stock Standard look. AgX walks bright +// colors toward white ("path to white"), which reads as desaturation. +// saturation > 1.0 pushes them back out, < 1.0 mutes them. Rec.709 luma +// weights hold perceived brightness fixed. The reference Minimal AgX look +// also exposes per-channel slope/power ("Punchy"/"Golden" presets), we +// wire only saturation, the one knob this debug renderer needs. +vec3 agxLook( vec3 v, float saturation ) +{ + const vec3 LUMA = vec3( 0.2126, 0.7152, 0.0722 ); + float luma = dot( v, LUMA ); + return luma + saturation * ( v - luma ); +} + +void main() +{ + // Backend-conditional v_uv.y flip: when params.y < 0 (D3D11/Metal/WGPU), + // replace v_uv.y with (1 - v_uv.y) so the sample reads the correct row. + // Equivalent to `mix(1.0-y, y, step(0.0, params.y))` but cheaper. + float sampleY = ( params.y > 0.0 ) ? v_uv.y : ( 1.0 - v_uv.y ); + vec3 hdr = textureLod( sampler2D( tex_scene, smp_scene ), vec2( v_uv.x, sampleY ), 0.0 ).rgb; + hdr *= pow( 2.0, params.x ); + vec3 ldr = agxOutset( agxLook( agx( hdr ), params.z ) ); + out_color = vec4( clamp( ldr, 0.0, 1.0 ), 1.0 ); +} +#pragma sokol @end + +#pragma sokol @program prog vs fs diff --git a/samples/shaders/shapes/capsule.glsl b/samples/shaders/shapes/capsule.glsl new file mode 100644 index 0000000..bad9bf5 --- /dev/null +++ b/samples/shaders/shapes/capsule.glsl @@ -0,0 +1,487 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Capsule impostor. +// +// Per-instance: a 3x4 rigid affine (orthonormal rotation rows in .xyz of each +// xform_row*, capsule center in .w of each row), an RGBA color, and a `params` +// row whose .x is halfLength (segment half-length along local +X) and .y is +// the cap radius. The capsule's long axis is the local +X axis: end caps sit +// at object-space (+/- halfLength, 0, 0) with radius `radius`. +// +// Pipeline overview: +// VS: emit a unit-cube vertex (half-extent 0.5) scaled to an OBB with +// half-extents (halfLength + radius, radius, radius), then rotated by +// the instance rotation and translated by center. Pass world position +// of the proxy vertex (interpolated) plus flat per-instance data. +// FS: reconstruct view ray as (camera, normalize(v_world_pos_proxy - camera)). +// Quilez ray-capsule intersection in world space (cylinder body + two +// end-cap spheres). discard on miss / behind-camera. Compute world-space +// normal at the hit, transform to object space via transpose(rotation), +// shade two great-circle rings at the object-space y=0 and z=0 +// equators: on caps these appear as half-circles through the apex, +// on the cylinder body they continue as longitudinal lines. The X +// equator is omitted: n_obj.x is identically zero on the cylinder +// (would paint the entire body), and at the cap-cylinder seam the +// curvature discontinuity makes its line thinner than the others. +// Constant screen-space pixel thickness via fwidth, on a north/south +// hemisphere base contrast. Apply Lambert + ambient against +// world-space sun, write reverse-Z gl_FragDepth. +// +// `@module capsule` prefixes the generated C symbols (capsule_ub_frame_t, +// capsule_instance_t, capsule_shader_desc, ...) so this header coexists with +// cube.glsl.h and sphere.glsl.h in renderer.c without typedef collisions on +// ub_frame_t. +// +// UBO layout matches sphere.glsl exactly (frame data lives in ub_pass on +// the FS side because the renderer always re-applies ub_pass per draw, and +// one FS UBO is simpler than two). +// +// gl_FragDepth disables hi-Z. That's accepted for impostors. + +#pragma sokol @module capsule + +#pragma sokol @ctype mat4 Mat4 +#pragma sokol @ctype vec4 Vec4 +#pragma sokol @ctype vec3 b3Vec3 +#pragma sokol @ctype vec2 b3Vec2 + +#pragma sokol @vs vs + +layout( binding = 0 ) uniform ub_frame +{ + mat4 view_proj; +}; + +// per-draw offset into the instance buffer. See cube.glsl for the +// rationale. +layout( binding = 2 ) uniform ub_draw +{ + ivec4 inst_base; +}; + +struct instance +{ + vec4 xform_row0; // .xyz = rotation row 0, .w = center.x + vec4 xform_row1; // .xyz = rotation row 1, .w = center.y + vec4 xform_row2; // .xyz = rotation row 2, .w = center.z + vec4 base_color; // .rgb = linear baseColor, .a = alpha + vec4 params; // .x = halfLength, .y = radius, .zw = unused + vec4 material; // .x = metallic, .y = roughness, + // .z = shadow-cast bit (, CPU-only, ignored here), + // .w = reserved +}; + +layout( binding = 0 ) readonly buffer instances +{ + instance items[]; +}; + +in vec3 in_pos; // unit-cube corner, half-extent 0.5 + +// Interpolated, per-pixel. The FS computes an analytical sub-pixel coverage +// from the signed silhouette distance and feeds it through alpha-to-coverage +// (opaque pipeline) or the alpha blend (transparent pipeline). Mirrors +// sphere.glsl. +out vec3 v_world_pos_proxy; + +// Flat: same value for every fragment in this instance. +flat out vec3 v_center; +flat out float v_half_length; +flat out float v_radius; +flat out vec3 v_axis_x_world; // world-space direction of local +X (capsule long axis) +flat out vec3 v_rot_row0; // R rows for n_world -> n_obj transform in FS +flat out vec3 v_rot_row1; +flat out vec3 v_rot_row2; +flat out vec4 v_base_color; +flat out vec4 v_material; + +void main() +{ + instance inst = items[inst_base.x + gl_InstanceIndex]; + vec3 center = vec3( inst.xform_row0.w, inst.xform_row1.w, inst.xform_row2.w ); + float halfLength = inst.params.x; + float radius = inst.params.y; + + // OBB half-extents: (halfLength + radius) along local X, radius along Y/Z. + // Multiply unit-cube vertex (half-extent 0.5) by 2*these to get exact OBB. + vec3 obj_pos = vec3( in_pos.x * 2.0 * ( halfLength + radius ), in_pos.y * 2.0 * radius, in_pos.z * 2.0 * radius ); + + // world = R * obj + center, each component is the dot of an R row with obj_pos. + vec3 world_pos = center + vec3( dot( inst.xform_row0.xyz, obj_pos ), dot( inst.xform_row1.xyz, obj_pos ), + dot( inst.xform_row2.xyz, obj_pos ) ); + + v_world_pos_proxy = world_pos; + v_center = center; + v_half_length = halfLength; + v_radius = radius; + // Local +X in world = first column of R = (R[0][0], R[1][0], R[2][0]) + // = (xform_row0.x, xform_row1.x, xform_row2.x). + v_axis_x_world = vec3( inst.xform_row0.x, inst.xform_row1.x, inst.xform_row2.x ); + v_rot_row0 = inst.xform_row0.xyz; + v_rot_row1 = inst.xform_row1.xyz; + v_rot_row2 = inst.xform_row2.xyz; + v_base_color = inst.base_color; + v_material = inst.material; + + gl_Position = view_proj * vec4( world_pos, 1.0 ); +} +#pragma sokol @end + +#pragma sokol @fs fs + +#pragma sokol @include ../common/pbr.glsl + +layout( binding = 1 ) uniform ub_pass +{ + vec4 sun_dir_world; // .xyz = world-space dir TO sun (normalized) + vec4 sun_color; // .rgb = color, .a = ambient strength (flat-ambient fallback) + ivec4 flags; // .x = debug_view_mode (0 lit, 1 view-depth, 2 cascade-index) + vec4 camera_pos; // .xyz = camera world pos, .w unused + mat4 view_proj; // for reverse-Z gl_FragDepth + mat4 view; // for view-space depth debug mode + cascade selection + vec4 cascade_far_view_z; // .xyz = far view-space Z per cascade + mat4 cascade_matrices[3]; // light-space view-proj per cascade + vec4 sh[9]; // IBL diffuse SH coefficients (band 0..2, RGB in .xyz) + vec4 ibl_params; // .x = prefilter cube max_lod, .y = IBL enable (1=IBL, 0=flat ambient), .zw reserved +}; + +#pragma sokol @image_sample_type tex_shadow depth +layout( binding = 1 ) uniform texture2DArray tex_shadow; +#pragma sokol @sampler_type smp_shadow comparison +layout( binding = 0 ) uniform samplerShadow smp_shadow; + +// IBL bindings, same convention as cube.glsl: texture bindings 2/3, +// sampler bindings 1/2, disjoint from the shadow path's 1/0. +#pragma sokol @image_sample_type tex_ibl_spec float +layout( binding = 2 ) uniform textureCube tex_ibl_spec; +#pragma sokol @sampler_type smp_ibl_spec filtering +layout( binding = 1 ) uniform sampler smp_ibl_spec; +#pragma sokol @image_sample_type tex_brdf_lut float +layout( binding = 3 ) uniform texture2D tex_brdf_lut; +#pragma sokol @sampler_type smp_brdf_lut filtering +layout( binding = 2 ) uniform sampler smp_brdf_lut; + +// GTAO, same convention as cube.glsl. Multiplies only the IBL ambient. +#pragma sokol @image_sample_type tex_ao float +layout( binding = 4 ) uniform texture2D tex_ao; +#pragma sokol @sampler_type smp_ao filtering +layout( binding = 3 ) uniform sampler smp_ao; + +// 3x3 PCF over a 1-texel radius. Manually unrolled, see cube.glsl for +// the X3570 rationale. +float sampleShadowPCF( int cascade, vec3 light_uv, float bias ) +{ + float t = 1.0 / 2048.0; + float ly = float( cascade ); + float rz = light_uv.z - bias; + vec2 c = light_uv.xy; + float s = 0.0; + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x - t, c.y - t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x, c.y - t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x + t, c.y - t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x - t, c.y, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x, c.y, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x + t, c.y, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x - t, c.y + t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x, c.y + t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x + t, c.y + t, ly, rz ) ); + return s / 9.0; +} + +float sampleCascade( int cascade, vec3 world_pos, vec3 world_normal ) +{ + vec4 light_clip = cascade_matrices[cascade] * vec4( world_pos, 1.0 ); + vec3 light_ndc = light_clip.xyz / light_clip.w; + // Backend-dependent Y orientation, see cube.glsl for the longer note. + float ny = light_ndc.y * cascade_far_view_z.w; + vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z ); + + if ( any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) ) ) + { + return 1.0; + } + + float n_dot_l = max( dot( world_normal, normalize( sun_dir_world.xyz ) ), 0.0 ); + float bias = mix( 0.0040, 0.0008, n_dot_l ); + + float pcf = sampleShadowPCF( cascade, light_uv, bias ); + + // See cube.glsl for the longer note. Cascade 2 has no fallback at its + // UV boundary, so fade PCF toward 1.0 over the outer 10% to hide the + // polygonal seam where cascade 2's spatial extent ends on the ground. + if ( cascade == 2 ) + { + vec2 edge = min( light_uv.xy, 1.0 - light_uv.xy ); + float fade = clamp( min( edge.x, edge.y ) * 10.0, 0.0, 1.0 ); + pcf = mix( 1.0, pcf, fade ); + } + + return pcf; +} + +float sampleShadowCascaded( vec3 world_pos, vec3 world_normal, float view_z ) +{ + int cascade = 2; + if ( view_z < cascade_far_view_z.x ) + cascade = 0; + else if ( view_z < cascade_far_view_z.y ) + cascade = 1; + + float shadow = sampleCascade( cascade, world_pos, world_normal ); + + // Blend the last 10% of each cascade's range with the next cascade + // to hide the polygonal step where they meet. See cube.glsl for the + // longer note. + if ( cascade < 2 ) + { + float far_z = ( cascade == 0 ) ? cascade_far_view_z.x : cascade_far_view_z.y; + float near_z = ( cascade == 0 ) ? 0.0 : cascade_far_view_z.x; + float blend_start = mix( far_z, near_z, 0.1 ); + if ( view_z > blend_start ) + { + float alpha = ( view_z - blend_start ) / ( far_z - blend_start ); + shadow = mix( shadow, sampleCascade( cascade + 1, world_pos, world_normal ), alpha ); + } + } + + return shadow; +} + +in vec3 v_world_pos_proxy; +flat in vec3 v_center; +flat in float v_half_length; +flat in float v_radius; +flat in vec3 v_axis_x_world; +flat in vec3 v_rot_row0; +flat in vec3 v_rot_row1; +flat in vec3 v_rot_row2; +flat in vec4 v_base_color; +flat in vec4 v_material; + +out vec4 out_color; + +void main() +{ + // Ray construction (world space) + vec3 ro = camera_pos.xyz; + vec3 rd = normalize( v_world_pos_proxy - ro ); + + // Capsule endpoints in world space. + vec3 axis = v_axis_x_world; // already unit (rigid R) + vec3 pa = v_center - v_half_length * axis; // -X cap center + vec3 pb = v_center + v_half_length * axis; // +X cap center + + // Ray-capsule (cylinder body), Quilez closed form + // Reference: https://iquilezles.org/articles/intersectors/ + vec3 ba = pb - pa; + vec3 oa = ro - pa; + float baba = dot( ba, ba ); + float bard = dot( ba, rd ); + float baoa = dot( ba, oa ); + float rdoa = dot( rd, oa ); + float oaoa = dot( oa, oa ); + + float a_c = baba - bard * bard; + float b_c = baba * rdoa - baoa * bard; + float c_c = baba * oaoa - baoa * baoa - v_radius * v_radius * baba; + float h_c = b_c * b_c - a_c * c_c; + + // Analytical silhouette AA. A capsule is the Minkowski sum of a segment + // and a sphere, so distance(ray-line, capsule) = distance(ray-line, + // segment) - radius. The closest point on the segment to the ray-line is + // at s_inf (unconstrained) clamped to [0,1]: when s_inf lies inside the + // segment p_cap is the cylinder's closest-axis point (perp distance = + // cylinder silhouette), when clamped p_cap is a cap center (perp + // distance = cap-sphere silhouette). One formula covers body + caps with + // a single clamp. Computed in uniform control flow before any discard. + float s_inf = ( baoa - ( b_c / max( a_c, 1e-8 ) ) * bard ) / baba; + float s_clamp = clamp( s_inf, 0.0, 1.0 ); + vec3 p_cap = pa + s_clamp * ba; + vec3 oc_cap = ro - p_cap; + float bb_cap = dot( oc_cap, rd ); + float perp2 = max( 0.0, dot( oc_cap, oc_cap ) - bb_cap * bb_cap ); + float d_sil = sqrt( perp2 ) - v_radius; + float aa = max( fwidth( d_sil ), 1e-6 ); + float coverage = 1.0 - smoothstep( -aa, aa, d_sil ); + + float t = -1.0; // hit parameter, -1 means "no hit yet" + vec3 n_world = vec3( 0.0 ); + + if ( h_c >= 0.0 && a_c > 1e-8 ) + { + float t_body = ( -b_c - sqrt( h_c ) ) / a_c; + // Axial coord of the cylinder hit, normalized so 0..baba spans the body. + float y = baoa + t_body * bard; + if ( t_body > 0.0 && y > 0.0 && y < baba ) + { + vec3 hit = ro + t_body * rd; + // Project hit onto the cylinder centerline, normal is (hit - axis_pt)/r. + vec3 axis_pt = pa + ba * ( y / baba ); + n_world = ( hit - axis_pt ) / v_radius; + t = t_body; + } + } + + // End-cap spheres + // Test both caps, keep the closer hit (smallest positive t). + // + // Cap A (-X end) at pa. + { + vec3 oc = ro - pa; + float b = dot( oc, rd ); + float c = dot( oc, oc ) - v_radius * v_radius; + float h = b * b - c; + if ( h >= 0.0 ) + { + float tc = -b - sqrt( h ); + if ( tc > 0.0 && ( t < 0.0 || tc < t ) ) + { + vec3 hit = ro + tc * rd; + // Reject the half of the cap sphere that's inside the + // cylinder. The visible part of cap A has (hit - pa). axis <= 0. + if ( dot( hit - pa, axis ) <= 0.0 ) + { + n_world = ( hit - pa ) / v_radius; + t = tc; + } + } + } + } + // Cap B (+X end) at pb. + { + vec3 oc = ro - pb; + float b = dot( oc, rd ); + float c = dot( oc, oc ) - v_radius * v_radius; + float h = b * b - c; + if ( h >= 0.0 ) + { + float tc = -b - sqrt( h ); + if ( tc > 0.0 && ( t < 0.0 || tc < t ) ) + { + vec3 hit = ro + tc * rd; + if ( dot( hit - pb, axis ) >= 0.0 ) + { + n_world = ( hit - pb ) / v_radius; + t = tc; + } + } + } + } + + // Near-miss fallback: ray didn't hit the capsule, but coverage > 0 means + // we're inside the silhouette AA band. Shade off the closest-approach + // point on the ray to the capsule's segment, the resulting normal is + // the silhouette normal at p_cap, which is what these sub-pixel + // fragments should display. + if ( t < 0.0 ) + { + t = -bb_cap; + vec3 closest = ro + t * rd; + n_world = normalize( closest - p_cap ); + } + + if ( coverage <= 0.0 || t < 0.0 ) + { + // True miss outside the AA band, or capsule behind camera. + discard; + } + + vec3 hit_world = ro + t * rd; + + // Object-space normal via R^T + vec3 n_obj = vec3( v_rot_row0.x * n_world.x + v_rot_row1.x * n_world.y + v_rot_row2.x * n_world.z, + v_rot_row0.y * n_world.x + v_rot_row1.y * n_world.y + v_rot_row2.y * n_world.z, + v_rot_row0.z * n_world.x + v_rot_row1.z * n_world.y + v_rot_row2.z * n_world.z ); + + // Surface pattern + // Two great-circle rings at object-space y=0 and z=0 equators, drawn + // uniformly on caps and body. fwidth is taken on the signed normal + // component (abs has a derivative kink at zero that produces + // speckled lines). Constant ~LINE_PIXELS screen-space thickness. + float hemi = ( n_obj.y > 0.0 ) ? 1.0 : 0.65; + vec3 base = v_base_color.rgb * hemi; + + const float LINE_PIXELS = 1.5; + float ring_y = 1.0 - smoothstep( 0.0, fwidth( n_obj.y ) * LINE_PIXELS, abs( n_obj.y ) ); + float ring_z = 1.0 - smoothstep( 0.0, fwidth( n_obj.z ) * LINE_PIXELS, abs( n_obj.z ) ); + float line = max( ring_y, ring_z ); + + vec3 line_color = base * 0.35; + vec3 surface = mix( base, line_color, line ); + + // Reverse-Z depth + vec4 hit_clip = view_proj * vec4( hit_world, 1.0 ); + gl_FragDepth = hit_clip.z / hit_clip.w; + + // Output + if ( flags.x == 1 ) + { + vec3 hit_view = ( view * vec4( hit_world, 1.0 ) ).xyz; + float view_depth = -hit_view.z; + float v = clamp( view_depth / 50.0, 0.0, 1.0 ); + out_color = vec4( v, v, v, 1.0 ); + return; + } + if ( flags.x == 2 ) + { + float view_z_dbg = -( view * vec4( hit_world, 1.0 ) ).z; + int cascade = 2; + if ( view_z_dbg < cascade_far_view_z.x ) + cascade = 0; + else if ( view_z_dbg < cascade_far_view_z.y ) + cascade = 1; + vec4 light_clip = cascade_matrices[cascade] * vec4( hit_world, 1.0 ); + vec3 light_ndc = light_clip.xyz / light_clip.w; + float ny = light_ndc.y * cascade_far_view_z.w; + vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z ); + bool oob = any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) ); + vec3 tint = vec3( 1.0 ); + if ( !oob ) + { + if ( cascade == 0 ) + tint = vec3( 1.0, 0.4, 0.4 ); + else if ( cascade == 1 ) + tint = vec3( 0.4, 1.0, 0.4 ); + else + tint = vec3( 0.4, 0.4, 1.0 ); + } + out_color = vec4( tint, 1.0 ); + return; + } + if ( flags.x == 3 ) + { + // View-space normal as RGB, [-1,1] mapped to [0,1]. + vec3 n_view = ( view * vec4( n_world, 0.0 ) ).xyz; + out_color = vec4( normalize( n_view ) * 0.5 + 0.5, 1.0 ); + return; + } + + // GTAO sample. + vec2 ao_uv = gl_FragCoord.xy / vec2( textureSize( sampler2D( tex_ao, smp_ao ), 0 ) ); + float ao = textureLod( sampler2D( tex_ao, smp_ao ), ao_uv, 0.0 ).x; + + if ( flags.x == 4 ) + { + out_color = vec4( vec3( ao ), 1.0 ); + return; + } + + vec3 L = normalize( sun_dir_world.xyz ); + float n_dot_l = max( dot( n_world, L ), 0.0 ); + float view_z = -( view * vec4( hit_world, 1.0 ) ).z; + float shadow = sampleShadowCascaded( hit_world, n_world, view_z ); + vec3 V = normalize( camera_pos.xyz - hit_world ); + vec3 direct = brdf_evaluate( n_world, V, L, sun_color.rgb * shadow, surface, v_material.x, v_material.y ); + vec3 ambient = pbrEvaluateAmbient( ibl_params.y > 0.5, n_world, V, surface, v_material.x, v_material.y, sun_color.a, sh, + tex_ibl_spec, smp_ibl_spec, tex_brdf_lut, smp_brdf_lut, ibl_params.x ); + // premultiplied output, see cube.glsl. Alpha is scaled by analytical + // silhouette coverage so alpha-to-coverage (opaque pipeline) or the + // premultiplied alpha blend (transparent pipeline) produces a smooth + // sub-pixel silhouette instead of a binary hit/miss edge. + float a = v_base_color.a * coverage; + out_color = vec4( ( direct + ambient * ao ) * a, a ); +} +#pragma sokol @end + +#pragma sokol @program impostor vs fs diff --git a/samples/shaders/shapes/cube.glsl b/samples/shaders/shapes/cube.glsl new file mode 100644 index 0000000..759d544 --- /dev/null +++ b/samples/shaders/shapes/cube.glsl @@ -0,0 +1,391 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Cube shader, cascaded-shadow-map sampling and +// with PBR shading (GGX+Smith+Schlick+Lambert via +// common/pbr.glsl). +// +// Per-vertex input is a unit-cube corner (8 unique positions, 36 indices). +// Per-instance data lives in a readonly storage buffer indexed by +// gl_InstanceIndex: a 3x4 row-major affine transform plus a PBR material +// (baseColor + metallic + roughness). Flat shading is recovered from +// dFdx/dFdy of view-space position, no per-vertex normals are stored or +// interpolated. +// +// Lighting math runs in VIEW space (n_view, V = normalize(-v_view_pos), +// L = sun_dir_view). Converting the cube's normal computation to world +// space produced inverted normals on D3D11 (likely a screen-Y +// handedness interaction with the cross-product derivation). dot(n, L) is +// rotation-invariant, so the shadow bias formula reuses the view-space +// dot(n, L) unchanged. Shadow projection itself needs world-space coordinates, +// so we forward v_world_pos as a separate varying for the cascade matrix +// lookup. +// +// debug_view_mode (ub_pass.flags.x) selects the output: +// 0 = Lambert + ambient * shadow factor. +// 1 = view-space distance from camera as grayscale. +// 2 = cascade-index tint (red/green/blue = cascade 0/1/2, white = UV +// out of bounds on the chosen cascade, i.e. unsampled). +// +// UBO bindings are stage-specific in sokol-shdc. +// VS uses ub_frame at binding=0, FS uses ub_pass at binding=1. The shadow +// depth array texture binds at texture-binding=0, the comparison sampler +// binds at sampler-binding=0. + +#pragma sokol @ctype mat4 Mat4 +#pragma sokol @ctype vec4 Vec4 +#pragma sokol @ctype vec3 b3Vec3 +#pragma sokol @ctype vec2 b3Vec2 + +#pragma sokol @vs vs + +layout( binding = 0 ) uniform ub_frame +{ + mat4 view; + mat4 proj; + mat4 view_proj; + mat4 inv_view_proj; + vec4 camera_pos; // .xyz = world pos, .w = time + vec4 viewport; // .xy = size px, .zw = 1/size +}; + +// per-draw offset into the cube_instances buffer. Opaque draws bind +// the contiguous opaque arena and set inst_base.x = 0 (bulk-instanced). +// Transparent draws bind the transparent arena and set inst_base.x = K to +// pick the K-th transparent instance, then sg_draw with instanceCount = 1. +// The back-to-front sort across shape types is realized through these +// per-instance picks. +layout( binding = 2 ) uniform ub_draw +{ + ivec4 inst_base; +}; + +struct cube_instance +{ + vec4 xform_row0; // 3x4 affine, rows + vec4 xform_row1; + vec4 xform_row2; + vec4 base_color; // .rgb = linear baseColor, .a = alpha + vec4 material; // .x = metallic, .y = roughness, + // .z = shadow-cast bit (, CPU-only, ignored here), + // .w = reserved +}; + +layout( binding = 0 ) readonly buffer cube_instances +{ + cube_instance instances[]; +}; + +in vec3 in_pos; // per-vertex (cube corner, local space) + +out vec3 v_view_pos; // for view-space normal via dFdx/dFdy +out vec3 v_world_pos; // for shadow projection (cascade matrix lookup) +flat out vec4 v_base_color; +flat out vec4 v_material; + +void main() +{ + cube_instance inst = instances[inst_base.x + gl_InstanceIndex]; + vec4 local_pos = vec4( in_pos, 1.0 ); + vec3 world_pos = + vec3( dot( inst.xform_row0, local_pos ), dot( inst.xform_row1, local_pos ), dot( inst.xform_row2, local_pos ) ); + vec4 view_pos = view * vec4( world_pos, 1.0 ); + v_view_pos = view_pos.xyz; + v_world_pos = world_pos; + v_base_color = inst.base_color; + v_material = inst.material; + gl_Position = proj * view_pos; +} +#pragma sokol @end + +#pragma sokol @fs fs + +#pragma sokol @include ../common/pbr.glsl + +layout( binding = 1 ) uniform ub_pass +{ + vec4 sun_dir_view; // .xyz = view-space dir TO sun (normalized), for direct lighting + vec4 sun_color; // .rgb = color, .a = ambient strength (flat-ambient fallback) + ivec4 flags; // .x = debug_view_mode + vec4 cascade_far_view_z; // .xyz = far view-space Z per cascade + mat4 cascade_matrices[3]; // light-space view-proj per cascade + mat4 view; // IBL: world->view rotation for view->world n_view transform + vec4 camera_pos_world; // IBL: world camera pos for V_world derivation + vec4 sh[9]; // IBL diffuse SH coefficients (band 0..2, RGB in .xyz) + vec4 ibl_params; // .x = prefilter cube max_lod, .y = IBL enable (1=IBL, 0=flat ambient), .zw reserved +}; + +// binding=1 (not 0): sokol-shdc enforces disjoint binding numbers between +// storage buffers and textures across all stages of a program. The cube +// instance buffer holds binding=0 in the VS, so the shadow texture takes 1. +#pragma sokol @image_sample_type tex_shadow depth +layout( binding = 1 ) uniform texture2DArray tex_shadow; +#pragma sokol @sampler_type smp_shadow comparison +layout( binding = 0 ) uniform samplerShadow smp_shadow; + +// IBL: prefiltered sky cubemap (specular) and Karis BRDF integration +// LUT. Texture bindings 2/3 and sampler bindings 1/2, disjoint from the +// shadow path's 1/0. +#pragma sokol @image_sample_type tex_ibl_spec float +layout( binding = 2 ) uniform textureCube tex_ibl_spec; +#pragma sokol @sampler_type smp_ibl_spec filtering +layout( binding = 1 ) uniform sampler smp_ibl_spec; +#pragma sokol @image_sample_type tex_brdf_lut float +layout( binding = 3 ) uniform texture2D tex_brdf_lut; +#pragma sokol @sampler_type smp_brdf_lut filtering +layout( binding = 2 ) uniform sampler smp_brdf_lut; + +// GTAO: full-res R32F ambient occlusion target written by +// post/gtao_denoise. Sampled per pixel via gl_FragCoord and used to +// modulate only the IBL ambient term (direct sun light is untouched, +// per XeGTAO). +#pragma sokol @image_sample_type tex_ao float +layout( binding = 4 ) uniform texture2D tex_ao; +#pragma sokol @sampler_type smp_ao filtering +layout( binding = 3 ) uniform sampler smp_ao; + +in vec3 v_view_pos; +in vec3 v_world_pos; +flat in vec4 v_base_color; +flat in vec4 v_material; +out vec4 out_color; + +// 3x3 PCF over a 1-texel radius. The comparison sampler returns 0..1 +// per tap (0 = occluded, 1 = lit). Uniform 1/9 weighting. +// +// Manually unrolled: the HLSL compiler emits warning X3570 ("gradient +// instruction used in a loop with varying iteration") on the looped +// version because texture uses implicit derivatives. Unrolling here +// keeps cross-compilation clean on the D3D11 backend. +float sampleShadowPCF( int cascade, vec3 light_uv, float bias ) +{ + float t = 1.0 / 2048.0; + float ly = float( cascade ); + float rz = light_uv.z - bias; + vec2 c = light_uv.xy; + float s = 0.0; + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x - t, c.y - t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x, c.y - t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x + t, c.y - t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x - t, c.y, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x, c.y, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x + t, c.y, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x - t, c.y + t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x, c.y + t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x + t, c.y + t, ly, rz ) ); + return s / 9.0; +} + +float sampleCascade( int cascade, vec3 world_pos, float n_dot_l ) +{ + vec4 light_clip = cascade_matrices[cascade] * vec4( world_pos, 1.0 ); + vec3 light_ndc = light_clip.xyz / light_clip.w; + + // UV.y orientation is BACKEND-DEPENDENT. D3D11/Metal/WebGPU sample + // render targets with V = 0 at the top (NDC.y = +1 -> texture row 0), + // they need UV.y = 0.5 - NDC.y * 0.5. OpenGL samples with V = 0 at + // the bottom (NDC.y = +1 -> top row N-1), it needs the textbook + // UV.y = NDC.y * 0.5 + 0.5. Renderer side sets cascade_far_view_z.w + // to -1 on D3D11/Metal/WGPU and +1 on glcore so a single multiply + // here picks the right convention. + float ny = light_ndc.y * cascade_far_view_z.w; + vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z ); + + if ( any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) ) ) + { + return 1.0; + } + + // Slope-scaled bias: tan(angle to light) = sqrt(1 - n.l^2) / n.l. + // Constant texel-step factor keeps the bias roughly the same world + // size across cascades (each cascade's depth range scales with its + // bounding sphere, bias scales with it via the texel step). + float ndl = clamp( n_dot_l, 0.001, 1.0 ); + float tanAngle = sqrt( 1.0 - ndl * ndl ) / ndl; + float texelDepthStep = 0.001; + float bias = clamp( texelDepthStep * tanAngle, 0.0005, 0.05 ); + + float pcf = sampleShadowPCF( cascade, light_uv, bias ); + + // Cascade 2 is the last cascade, sampleShadowCascaded's view-z blend + // has nothing to blend into beyond it. On flat ground at glancing sun + // angles PCF inside the cascade reads slightly below 1.0 (bias slop + // across a 3x3 kernel that covers ~5 cm of world per texel here), while + // fragments outside the cascade's spatial sphere fall through to the + // OOB return of 1.0. Without smoothing, cascade 2's UV boundary reads + // as a hexagonal polygon on the ground. Fade PCF toward 1.0 over the + // outer 10% of UV space to hide the seam. + if ( cascade == 2 ) + { + vec2 edge = min( light_uv.xy, 1.0 - light_uv.xy ); + float fade = clamp( min( edge.x, edge.y ) * 10.0, 0.0, 1.0 ); + pcf = mix( 1.0, pcf, fade ); + } + + return pcf; +} + +// n_dot_l is the (clamped) dot of the surface normal with the sun +// direction, passed in by the caller in whichever space is convenient +// (rotation-invariant, same value in view and world space). +float sampleShadowCascaded( vec3 world_pos, float n_dot_l, float view_z ) +{ + int cascade = 2; + if ( view_z < cascade_far_view_z.x ) + { + cascade = 0; + } + else if ( view_z < cascade_far_view_z.y ) + { + cascade = 1; + } + + float shadow = sampleCascade( cascade, world_pos, n_dot_l ); + + // Blend the last 10% of each cascade's range with the next cascade. + // Each cascade uses the same slope-scaled bias in shadow-UV units, + // but cascades cover very different world extents (cascade 0 ~= 1 m, + // cascade 2 ~= 25 m+), so PCF response on flat receivers differs + // slightly per cascade, without this blend the boundary reads as a + // polygonal step on the ground at glancing sun angles. + if ( cascade < 2 ) + { + float far_z = ( cascade == 0 ) ? cascade_far_view_z.x : cascade_far_view_z.y; + float near_z = ( cascade == 0 ) ? 0.0 : cascade_far_view_z.x; + float blend_start = mix( far_z, near_z, 0.1 ); + if ( view_z > blend_start ) + { + float alpha = ( view_z - blend_start ) / ( far_z - blend_start ); + shadow = mix( shadow, sampleCascade( cascade + 1, world_pos, n_dot_l ), alpha ); + } + } + + return shadow; +} + +void main() +{ + // Derivatives at top level: undefined inside non-uniform branches. + // In view space the cross-product convention works out + // consistently across GL/D3D11/Metal because dFdx/dFdy are derived + // from the same screen-space basis the camera uses to define view + // space. Computing in world space instead inverts the normal on + // D3D11 (raw screen-Y handedness leaks through the conversion). + vec3 dx = dFdx( v_view_pos ); + + // GL's dFdy points in +view_y (screen origin is lower-left), while HLSL + // ddy and Metal dfdy point in -view_y (screen origin is upper-left). + // sokol-shdc cross-compiles dFdy->ddy/dfdy without a sign flip, so the raw + // value's screen direction depends on the backend. cascade_far_view_z.w + // is +1 on glcore/gles3 and -1 on D3D11/Metal/WGPU (same flag used by + // the shadow UV.y remap below), negating it gives a multiplier that + // canonicalizes dFdy to the -view_y direction on every backend. With + // canonical dy, cross(dy, dx) = (-view_y) x (+view_x) = +view_z, which + // points toward the camera (out of the screen), the correct outward + // normal for a back-culled front face. + vec3 dy = dFdy( v_view_pos ) * ( -cascade_far_view_z.w ); + vec3 n_view = normalize( cross( dy, dx ) ); + + float view_z = -v_view_pos.z; + + // Debug view : depth + if ( flags.x == 1 ) + { + float v = clamp( view_z / 50.0, 0.0, 1.0 ); + out_color = vec4( v, v, v, 1.0 ); + return; + } + + // Debug view : shadow cascades + if ( flags.x == 2 ) + { + int cascade = 2; + if ( view_z < cascade_far_view_z.x ) + { + cascade = 0; + } + else if ( view_z < cascade_far_view_z.y ) + { + cascade = 1; + } + + vec4 light_clip = cascade_matrices[cascade] * vec4( v_world_pos, 1.0 ); + vec3 light_ndc = light_clip.xyz / light_clip.w; + float ny = light_ndc.y * cascade_far_view_z.w; + vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z ); + bool oob = any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) ); + vec3 tint = vec3( 1.0 ); + if ( !oob ) + { + if ( cascade == 0 ) + { + tint = vec3( 1.0, 0.4, 0.4 ); + } + else if ( cascade == 1 ) + { + tint = vec3( 0.4, 1.0, 0.4 ); + } + else + { + tint = vec3( 0.4, 0.4, 1.0 ); + } + } + out_color = vec4( tint, 1.0 ); + return; + } + + // Debug view : normals + if ( flags.x == 3 ) + { + // View-space normal as RGB, [-1,1] mapped to [0,1]. + out_color = vec4( n_view * 0.5 + 0.5, 1.0 ); + return; + } + + // GTAO sample. textureSize avoids needing a viewport uniform in + // ub_pass, the AO texture matches the swapchain/offscreen target + // exactly so dividing the pixel-space gl_FragCoord by the AO size + // yields the right UV regardless of backend Y-orientation. + vec2 ao_uv = gl_FragCoord.xy / vec2( textureSize( sampler2D( tex_ao, smp_ao ), 0 ) ); + float ao = textureLod( sampler2D( tex_ao, smp_ao ), ao_uv, 0.0 ).x; + + // Debug view : ambient occlusion + if ( flags.x == 4 ) + { + out_color = vec4( vec3( ao ), 1.0 ); + return; + } + + // dot(n, L) is rotation-invariant. Same value with view-space or world-space + // normals + sun directions. Use the view-space pair for direct light. + vec3 L = normalize( sun_dir_view.xyz ); + float n_dot_l = max( dot( n_view, L ), 0.0 ); + float shadow = sampleShadowCascaded( v_world_pos, n_dot_l, view_z ); + + // Camera sits at origin in view space, so V_view = normalize(-v_view_pos). + vec3 V_view = normalize( -v_view_pos ); + vec3 direct = brdf_evaluate( n_view, V_view, L, sun_color.rgb * shadow, v_base_color.rgb, v_material.x, v_material.y ); + + // IBL needs world-space N and V. view is the world->view matrix, its + // 3x3 is orthonormal (camera rotation), so transpose(mat3(view)) + // takes view-space -> world-space without inverse cost. Stays clear + // of the D3D11 cross-product handedness trap that forced n_view to + // be computed in view space. Only rotate here, no derivatives. + mat3 view_to_world = transpose( mat3( view ) ); + vec3 N_world = normalize( view_to_world * n_view ); + vec3 V_world = normalize( camera_pos_world.xyz - v_world_pos ); + vec3 ambient = pbrEvaluateAmbient( ibl_params.y > 0.5, N_world, V_world, v_base_color.rgb, v_material.x, v_material.y, + sun_color.a, sh, tex_ibl_spec, smp_ibl_spec, tex_brdf_lut, smp_brdf_lut, ibl_params.x ); + + // GTAO modulates only the ambient (IBL) term, per XeGTAO. Direct sun + // is left alone so contact darkening doesn't fight the primary light's + // shadowing. + // Premultiplied output. For opaque draws (a == 1) this is bit- + // identical to the `vec4(rgb, a)` form. For transparent draws + // the renderer's premultiplied-alpha blend (ONE, ONE_MINUS_SRC_ALPHA) + // consumes (rgb * a, a) directly. + out_color = vec4( ( direct + ambient * ao ) * v_base_color.a, v_base_color.a ); +} +#pragma sokol @end + +#pragma sokol @program cube vs fs diff --git a/samples/shaders/shapes/edge.glsl b/samples/shaders/shapes/edge.glsl new file mode 100644 index 0000000..fccc290 --- /dev/null +++ b/samples/shaders/shapes/edge.glsl @@ -0,0 +1,202 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Edge overlay shader. +// +// Renders per-shape edges (face boundaries for hulls, dedup'd triangle edges +// for meshes, grid + diagonals for heightfields) as shader-expanded screen- +// space quads. Edge endpoint positions live in a per-geometry storage buffer +// (GetEdgeStorageView), per-instance transforms come from the existing +// geom instance buffer (GetMeshInstanceView / GetTransparentMeshInstanceView). Six +// vertices per edge, batched as `2 * 6 * edgeCount` vertices x instanceCount +// in one sg_draw, no VBO/IBO bound, gl_VertexIndex selects edge + corner. +// +// Vertex index -> corner layout (matches overlays/line.glsl): +// +// 0 -> endpoint=A, side=-1 3 -> endpoint=A, side=-1 +// 1 -> endpoint=B, side=-1 4 -> endpoint=B, side=+1 +// 2 -> endpoint=B, side=+1 5 -> endpoint=A, side=+1 +// +// Z-fight prevention: reverse-Z clip-space nudge in the VS, +// `clip.z += zBias * clip.w`. Positive bias = toward camera (z=1 is near in +// reverse-Z). 5e-5 is enough at typical scene scales without visible offset +// at glancing angles. +// +// Per-fragment color picks between convex/concave/flat uniforms from the +// per-endpoint flag (0 concave, 1 convex, 2 flat, stored as float to keep +// the std430 endpoint struct a flat vec4, no vec3+uint padding ambiguity). +// +// Pipeline state: +// * depth_compare = GREATER_EQUAL (reverse-Z). With the zBias nudge this +// keeps the edge on top of the shape's own surface, transparent shapes +// drawn after still over-blend the edge correctly. +// * depth_write = off. The edge isn't real surface depth. +// * Premultiplied-alpha blend (SRC_ONE, ONE_MINUS_SRC_ALPHA). FS outputs +// `color * coverage` so coverage drops below 1 at the AA band only. + +#pragma sokol @module edge + +#pragma sokol @ctype mat4 Mat4 +#pragma sokol @ctype vec4 Vec4 + +#pragma sokol @vs vs + +layout( binding = 0 ) uniform ub_frame +{ + mat4 view_proj; + vec4 viewport; // .xy = size px, .zw = 1/size +}; + +layout( binding = 2 ) uniform ub_draw +{ + ivec4 inst_base; // .x = base index into the geom instance buffer + vec4 edge_params; // .x = thicknessPx, .y = zBias, .zw reserved +}; + +struct geom_instance +{ + vec4 xform_row0; + vec4 xform_row1; + vec4 xform_row2; + vec4 base_color; + vec4 scale; + vec4 material; +}; + +layout( binding = 0 ) readonly buffer geom_instances +{ + geom_instance gi_items[]; +}; + +// Endpoint = vec4 (.xyz = position, .w = flag as float). Two consecutive +// entries per edge. sokol-shdc requires storage buffers to hold a struct +// array, not a primitive array, so the vec4 is wrapped. +struct edge_endpoint +{ + vec4 pos_and_flag; +}; + +layout( binding = 1 ) readonly buffer edge_endpoints +{ + edge_endpoint ee_items[]; +}; + +// Long edges get thinned in the middle with perspective math +noperspective out float v_dist_from_axis_px; + +// Flat thickness +flat out float v_half_width_px; + +flat out float v_flag; + +void main() +{ + // gl_VertexIndex is non-negative, an unsigned divide produces the same + // result and sidesteps HLSL's signed-divide warning (X3556). + int edge_idx = int( uint( gl_VertexIndex ) / 6u ); + int corner = gl_VertexIndex - edge_idx * 6; + + bool is_b = ( corner == 1 ) || ( corner == 2 ) || ( corner == 4 ); + float side = ( ( corner == 2 ) || ( corner == 4 ) || ( corner == 5 ) ) ? 1.0 : -1.0; + + geom_instance inst = gi_items[inst_base.x + gl_InstanceIndex]; + vec4 ea = ee_items[2 * edge_idx + 0].pos_and_flag; + vec4 eb = ee_items[2 * edge_idx + 1].pos_and_flag; + + // Per-instance affine: rotation row dotted with (local_pos, 1). Apply + // per-instance scale first, same convention as geom.glsl. + vec3 a_local = ea.xyz * inst.scale.xyz; + vec3 b_local = eb.xyz * inst.scale.xyz; + vec3 a_world = vec3( dot( inst.xform_row0, vec4( a_local, 1.0 ) ), dot( inst.xform_row1, vec4( a_local, 1.0 ) ), + dot( inst.xform_row2, vec4( a_local, 1.0 ) ) ); + vec3 b_world = vec3( dot( inst.xform_row0, vec4( b_local, 1.0 ) ), dot( inst.xform_row1, vec4( b_local, 1.0 ) ), + dot( inst.xform_row2, vec4( b_local, 1.0 ) ) ); + + vec4 clip_a = view_proj * vec4( a_world, 1.0 ); + vec4 clip_b = view_proj * vec4( b_world, 1.0 ); + vec4 clip_end = is_b ? clip_b : clip_a; + + // Screen-space pixel coords of both endpoints (post-perspective divide, + // NDC [-1,1] -> pixel [0, viewport]). + vec2 ndc_a = clip_a.xy / clip_a.w; + vec2 ndc_b = clip_b.xy / clip_b.w; + vec2 sa = ( ndc_a * 0.5 + 0.5 ) * viewport.xy; + vec2 sb = ( ndc_b * 0.5 + 0.5 ) * viewport.xy; + + vec2 dir_px = sb - sa; + float len_px = length( dir_px ); + vec2 dir_n = ( len_px > 1e-6 ) ? ( dir_px / len_px ) : vec2( 1.0, 0.0 ); + vec2 perp_n = vec2( -dir_n.y, dir_n.x ); + + // Half-width in pixels, floor at 0.5 so very thin requests don't vanish + // into sub-pixel land (the SDF's AA falloff handles attenuation below). + float half_width_px = max( edge_params.x * 0.5, 0.5 ); + + // Expand the rasterized quad past the true half-width by an AA pad so + // the FS coverage falloff has geometry to ramp down inside (see + // overlays/line.glsl for the full rationale). The FS smoothstep + // completes at d = half_width + fwidth, and fwidth (an L1 norm) peaks + // at sqrt(2) on a 45 deg line, so the pad must be >= ~1.42 px, 1.5 covers it. + const float AA_PAD_PX = 1.5; + float quad_half_px = half_width_px + AA_PAD_PX; + + vec2 offset_px = perp_n * side * quad_half_px; + vec2 offset_ndc = offset_px * ( 2.0 * viewport.zw ); + vec4 clip_pos = clip_end; + clip_pos.xy += offset_ndc * clip_end.w; + // Reverse-Z z-bias nudge (toward camera, z=1 = near). + clip_pos.z += edge_params.y * clip_pos.w; + + gl_Position = clip_pos; + v_dist_from_axis_px = side * quad_half_px; + v_half_width_px = half_width_px; + v_flag = ea.w; // both endpoints carry the same flag +} +#pragma sokol @end + +#pragma sokol @fs fs + +layout( binding = 1 ) uniform ub_pass +{ + vec4 convex_color; // premultiplied linear RGBA + vec4 concave_color; // premultiplied linear RGBA + vec4 flat_color; // premultiplied linear RGBA +}; + +noperspective in float v_dist_from_axis_px; +flat in float v_half_width_px; +flat in float v_flag; + +out vec4 out_color; + +void main() +{ + // Coverage from the capsule SDF. d is the fragment's folded + // perpendicular distance from the axis (px), coverage ramps 1->0 over a + // 2*aa band straddling the true edge at d = half_width. Smoothstep + // (cubic, wider than an energy-exact box filter), with fwidth of the + // raw signed v_dist_from_axis_px to avoid the abs-kink, see + // overlays/line.glsl for the full rationale. + float d = abs( v_dist_from_axis_px ); + float aa = fwidth( v_dist_from_axis_px ); + float coverage = 1.0 - smoothstep( v_half_width_px - aa, v_half_width_px + aa, d ); + + // Flag is 0 concave, 1 convex, 2 flat (coplanar). + vec4 col; + if ( v_flag > 1.5 ) + { + col = flat_color; + } + else if ( v_flag > 0.5 ) + { + col = convex_color; + } + else + { + col = concave_color; + } + out_color = col * coverage; +} +#pragma sokol @end + +#pragma sokol @program edge_overlay vs fs diff --git a/samples/shaders/shapes/geom.glsl b/samples/shaders/shapes/geom.glsl new file mode 100644 index 0000000..35d50e5 --- /dev/null +++ b/samples/shaders/shapes/geom.glsl @@ -0,0 +1,327 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Triangle-geometry shader. Drives every shape with intrinsic topology: +// convex hulls, triangle meshes, and heightfields. One pipeline. The CPU +// builders in src/box3d/box3d_geometry.c emit duplicated-vertex meshes so +// per-face normals are baked into per-vertex data (flat shading). +// +// Per-vertex data: position (vec3), normal (vec3). Per-instance data lives +// in a readonly storage buffer indexed by `inst_base.x + gl_InstanceIndex`. +// `inst_base` is a ub_draw uniform set per draw so a single shared +// instance buffer can hold contiguous slices owned by many geometries. +// (sokol_gfx's sg_draw has no first_instance argument, hence the manual +// base offset.) +// +// Per-instance affine is a 3x4: rotation rows in .xyz of each xform_row*, +// center in .w of each row. Per-instance scale is non-uniform vec3. Mesh +// instances carry b3Mesh's per-instance scale here, hulls and heightfields +// pass (1,1,1) (their hash already includes scale, so the registry entry's +// geometry is pre-scaled). Normals are transformed by R * (n / scale) so +// non-uniform scale doesn't shear the shading. +// +// @module geom prefixes the generated C symbols (geom_instance_t, +// geom_ub_frame_t, geom_triangle_shader_desc, ...) so this header coexists +// with the existing shape-shader headers in renderer.c without typedef +// collisions on the common ub_frame_t / instance_t names. + +#pragma sokol @module geom + +#pragma sokol @ctype mat4 Mat4 +#pragma sokol @ctype vec4 Vec4 +#pragma sokol @ctype vec3 b3Vec3 +#pragma sokol @ctype vec2 b3Vec2 + +#pragma sokol @vs vs + +layout( binding = 0 ) uniform ub_frame +{ + mat4 view_proj; +}; + +layout( binding = 2 ) uniform ub_draw +{ + ivec4 inst_base; // .x = base index into the global instance array +}; + +struct instance +{ + vec4 xform_row0; // .xyz = rotation row 0, .w = center.x + vec4 xform_row1; // .xyz = rotation row 1, .w = center.y + vec4 xform_row2; // .xyz = rotation row 2, .w = center.z + vec4 base_color; // .rgb = linear baseColor, .a = alpha + vec4 scale; // .xyz = per-instance scale, .w = unused + vec4 material; // .x = metallic, .y = roughness, + // .z = materialMode (0=solid, 1=ground grid), + // .w = gridCellSize (world units) +}; + +layout( binding = 0 ) readonly buffer instances +{ + instance items[]; +}; + +in vec3 in_pos; +in vec3 in_normal; + +out vec3 v_view_pos; // view-space position, for debug_view_mode=1 + // (forwarded as world_pos, see comment in main) +out vec3 v_world_normal; // world-space normal, normalized in FS +flat out vec4 v_base_color; +flat out vec4 v_material; + +void main() +{ + instance inst = items[inst_base.x + gl_InstanceIndex]; + + vec3 scaled_pos = in_pos * inst.scale.xyz; + vec4 local_pos = vec4( scaled_pos, 1.0 ); + vec3 world_pos = + vec3( dot( inst.xform_row0, local_pos ), dot( inst.xform_row1, local_pos ), dot( inst.xform_row2, local_pos ) ); + + // World normal: R * (normal / scale). Inverse-transpose for a diagonal + // scale + rotation matrix simplifies to R applied to (normal / scale). + // Renormalized in the FS, non-uniform scale denormalizes here. + vec3 inv_scaled_n = in_normal / inst.scale.xyz; + vec3 world_normal = vec3( dot( inst.xform_row0.xyz, inv_scaled_n ), dot( inst.xform_row1.xyz, inv_scaled_n ), + dot( inst.xform_row2.xyz, inv_scaled_n ) ); + + v_world_normal = world_normal; + v_base_color = inst.base_color; + v_material = inst.material; + + gl_Position = view_proj * vec4( world_pos, 1.0 ); + // View matrix lives only in ub_pass on the FS side. To keep ub_frame + // minimal (matches sphere/capsule), forward world_pos and recompute + // view_pos in the FS from the pass-side view. + v_view_pos = world_pos; // sentinel: FS treats as world if needed +} +#pragma sokol @end + +#pragma sokol @fs fs + +#pragma sokol @include ../common/pbr.glsl + +layout( binding = 1 ) uniform ub_pass +{ + vec4 sun_dir_world; // .xyz = world-space dir TO sun (normalized) + vec4 sun_color; // .rgb = color, .a = ambient strength (flat-ambient fallback) + ivec4 flags; // .x = debug_view_mode (0 lit, 1 view-depth, 2 cascade-index) + vec4 camera_pos; // .xyz = camera world pos, .w unused + mat4 view; // for view-space depth debug mode + cascade selection + vec4 cascade_far_view_z; // .xyz = far view-space Z per cascade + mat4 cascade_matrices[3]; // light-space view-proj per cascade + vec4 sh[9]; // IBL diffuse SH coefficients (band 0..2, RGB in .xyz) + vec4 ibl_params; // .x = prefilter cube max_lod, .y = IBL enable (1=IBL, 0=flat ambient), .zw reserved +}; + +#pragma sokol @image_sample_type tex_shadow depth +layout( binding = 1 ) uniform texture2DArray tex_shadow; +#pragma sokol @sampler_type smp_shadow comparison +layout( binding = 0 ) uniform samplerShadow smp_shadow; + +// IBL bindings, same convention as cube.glsl: texture bindings 2/3, +// sampler bindings 1/2, disjoint from the shadow path's 1/0. +#pragma sokol @image_sample_type tex_ibl_spec float +layout( binding = 2 ) uniform textureCube tex_ibl_spec; +#pragma sokol @sampler_type smp_ibl_spec filtering +layout( binding = 1 ) uniform sampler smp_ibl_spec; +#pragma sokol @image_sample_type tex_brdf_lut float +layout( binding = 3 ) uniform texture2D tex_brdf_lut; +#pragma sokol @sampler_type smp_brdf_lut filtering +layout( binding = 2 ) uniform sampler smp_brdf_lut; + +// GTAO, same convention as cube.glsl. Multiplies only the IBL ambient. +#pragma sokol @image_sample_type tex_ao float +layout( binding = 4 ) uniform texture2D tex_ao; +#pragma sokol @sampler_type smp_ao filtering +layout( binding = 3 ) uniform sampler smp_ao; + +// 3x3 PCF over a 1-texel radius. Manually unrolled, see cube.glsl for +// the X3570 rationale. +float sampleShadowPCF( int cascade, vec3 light_uv, float bias ) +{ + float t = 1.0 / 2048.0; + float ly = float( cascade ); + float rz = light_uv.z - bias; + vec2 c = light_uv.xy; + float s = 0.0; + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x - t, c.y - t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x, c.y - t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x + t, c.y - t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x - t, c.y, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x, c.y, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x + t, c.y, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x - t, c.y + t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x, c.y + t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x + t, c.y + t, ly, rz ) ); + return s / 9.0; +} + +float sampleCascade( int cascade, vec3 world_pos, vec3 world_normal ) +{ + vec4 light_clip = cascade_matrices[cascade] * vec4( world_pos, 1.0 ); + vec3 light_ndc = light_clip.xyz / light_clip.w; + // Backend-dependent Y orientation, see cube.glsl for the longer note. + float ny = light_ndc.y * cascade_far_view_z.w; + vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z ); + + if ( any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) ) ) + { + return 1.0; + } + + float n_dot_l = max( dot( world_normal, normalize( sun_dir_world.xyz ) ), 0.0 ); + float bias = mix( 0.0040, 0.0008, n_dot_l ); + + float pcf = sampleShadowPCF( cascade, light_uv, bias ); + + // See cube.glsl for the longer note. Cascade 2 has no fallback at its + // UV boundary, so fade PCF toward 1.0 over the outer 10% to hide the + // polygonal seam where cascade 2's spatial extent ends on the ground. + if ( cascade == 2 ) + { + vec2 edge = min( light_uv.xy, 1.0 - light_uv.xy ); + float fade = clamp( min( edge.x, edge.y ) * 10.0, 0.0, 1.0 ); + pcf = mix( 1.0, pcf, fade ); + } + + return pcf; +} + +float sampleShadowCascaded( vec3 world_pos, vec3 world_normal, float view_z ) +{ + int cascade = 2; + if ( view_z < cascade_far_view_z.x ) + cascade = 0; + else if ( view_z < cascade_far_view_z.y ) + cascade = 1; + + float shadow = sampleCascade( cascade, world_pos, world_normal ); + + // Blend the last 10% of each cascade's range with the next cascade + // to hide the polygonal step where they meet. See cube.glsl for the + // longer note. + if ( cascade < 2 ) + { + float far_z = ( cascade == 0 ) ? cascade_far_view_z.x : cascade_far_view_z.y; + float near_z = ( cascade == 0 ) ? 0.0 : cascade_far_view_z.x; + float blend_start = mix( far_z, near_z, 0.1 ); + if ( view_z > blend_start ) + { + float alpha = ( view_z - blend_start ) / ( far_z - blend_start ); + shadow = mix( shadow, sampleCascade( cascade + 1, world_pos, world_normal ), alpha ); + } + } + + return shadow; +} + +in vec3 v_view_pos; // actually world_pos forwarded from VS +in vec3 v_world_normal; +flat in vec4 v_base_color; +flat in vec4 v_material; + +out vec4 out_color; + +void main() +{ + vec3 n_world = normalize( v_world_normal ); + + // Geom meshes render double sided, a per-instance mirror scale can flip + // winding, so face the shading normal toward the camera. + if ( dot( n_world, camera_pos.xyz - v_view_pos ) < 0.0 ) + { + n_world = -n_world; + } + + if ( flags.x == 1 ) + { + vec3 hit_view = ( view * vec4( v_view_pos, 1.0 ) ).xyz; + float view_depth = -hit_view.z; + float v = clamp( view_depth / 50.0, 0.0, 1.0 ); + out_color = vec4( v, v, v, 1.0 ); + return; + } + if ( flags.x == 2 ) + { + // v_view_pos is actually world_pos forwarded from the VS. + float view_z_dbg = -( view * vec4( v_view_pos, 1.0 ) ).z; + int cascade = 2; + if ( view_z_dbg < cascade_far_view_z.x ) + cascade = 0; + else if ( view_z_dbg < cascade_far_view_z.y ) + cascade = 1; + vec4 light_clip = cascade_matrices[cascade] * vec4( v_view_pos, 1.0 ); + vec3 light_ndc = light_clip.xyz / light_clip.w; + float ny = light_ndc.y * cascade_far_view_z.w; + vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z ); + bool oob = any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) ); + vec3 tint = vec3( 1.0 ); + if ( !oob ) + { + if ( cascade == 0 ) + tint = vec3( 1.0, 0.4, 0.4 ); + else if ( cascade == 1 ) + tint = vec3( 0.4, 1.0, 0.4 ); + else + tint = vec3( 0.4, 0.4, 1.0 ); + } + out_color = vec4( tint, 1.0 ); + return; + } + if ( flags.x == 3 ) + { + // View-space normal as RGB, [-1,1] mapped to [0,1]. + vec3 n_view = ( view * vec4( n_world, 0.0 ) ).xyz; + out_color = vec4( normalize( n_view ) * 0.5 + 0.5, 1.0 ); + return; + } + + // GTAO sample. + vec2 ao_uv = gl_FragCoord.xy / vec2( textureSize( sampler2D( tex_ao, smp_ao ), 0 ) ); + float ao = textureLod( sampler2D( tex_ao, smp_ao ), ao_uv, 0.0 ).x; + + if ( flags.x == 4 ) + { + out_color = vec4( vec3( ao ), 1.0 ); + return; + } + + // v_view_pos here is actually world_pos (see VS comment). + vec3 world_pos = v_view_pos; + + // Procedural ground grid: when materialMode selects it, replace the + // solid baseColor with the antialiased grid over world XZ. The branch + // is on a flat per-instance varying. Within any quad of a single draw + // every invocation takes the same path, so the fwidth inside is in + // dynamically uniform control flow (legal for derivatives). + // + // The grid is sampled in world XZ, which only makes sense on horizontal + // surfaces. On side faces of a ground box (or any tilted surface) the + // pattern degenerates to stripes/aliasing, so we fade the grid + // contribution toward zero as the surface tilts away from horizontal. + // pow(n.y, 8) gives a soft falloff while leaving the top face fully + // patterned and the strictly vertical sides flat. + vec3 baseColor = v_base_color.rgb; + if ( v_material.z > 0.5 ) + { + vec3 grid_color = proceduralGrid( world_pos.xz, v_base_color.rgb, v_material.w ); + float grid_blend = pow( clamp( n_world.y, 0.0, 1.0 ), 8.0 ); + baseColor = mix( v_base_color.rgb, grid_color, grid_blend ); + } + + vec3 L = normalize( sun_dir_world.xyz ); + float n_dot_l = max( dot( n_world, L ), 0.0 ); + float view_z = -( view * vec4( world_pos, 1.0 ) ).z; + float shadow = sampleShadowCascaded( world_pos, n_world, view_z ); + vec3 V = normalize( camera_pos.xyz - world_pos ); + vec3 direct = brdf_evaluate( n_world, V, L, sun_color.rgb * shadow, baseColor, v_material.x, v_material.y ); + vec3 ambient = pbrEvaluateAmbient( ibl_params.y > 0.5, n_world, V, baseColor, v_material.x, v_material.y, sun_color.a, sh, + tex_ibl_spec, smp_ibl_spec, tex_brdf_lut, smp_brdf_lut, ibl_params.x ); + // premultiplied output, see cube.glsl. + out_color = vec4( ( direct + ambient * ao ) * v_base_color.a, v_base_color.a ); +} +#pragma sokol @end + +#pragma sokol @program triangle vs fs diff --git a/samples/shaders/shapes/shadow_caster_capsule.glsl b/samples/shaders/shapes/shadow_caster_capsule.glsl new file mode 100644 index 0000000..be6cb62 --- /dev/null +++ b/samples/shaders/shapes/shadow_caster_capsule.glsl @@ -0,0 +1,86 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Shadow caster for capsules. As with the sphere caster, we substitute +// a low-poly proxy mesh for the analytic impostor. The proxy is a +// 12-slice cylinder with two hemispherical caps. Vertices are authored in +// a "unit-capsule" coordinate frame where each component carries enough +// information to scale independently by halfLength and radius. +// +// Each vertex is encoded as two attributes: +// in_axis, direction along the long axis (vec3). Scaled by halfLength. +// For body verts: (+/-1, 0, 0). For cap verts: same as the +// attached cap (i.e., (+1,0,0) for +X cap, (-1,0,0) for -X). +// in_radial, radial offset (vec3). Scaled by radius. For body verts: +// (0, cos theta, sin theta). For cap verts: an extension of the +// hemisphere parameterization that includes the cap's +// axial bulge, e.g. for +X cap at latitude alpha: in_radial = +// (sin alpha, cos alpha cos beta, cos alpha sin beta). +// +// The world position is then +// world = center + R * (in_axis * halfLength + in_radial * radius) +// where R is the capsule's rotation. Since rotation is orthonormal and +// halfLength/radius are scalars, the encoding scales linearly and +// produces a true capsule for any (halfLength, radius) pair. +// +// `@module shadow_capsule` namespaces the generated symbols. + +#pragma sokol @module shadow_capsule + +#pragma sokol @ctype mat4 Mat4 +#pragma sokol @ctype vec4 Vec4 +#pragma sokol @ctype vec3 b3Vec3 +#pragma sokol @ctype vec2 b3Vec2 + +#pragma sokol @vs vs + +layout( binding = 0 ) uniform ub_frame +{ + mat4 light_view_proj; +}; + +// per-draw offset, see shadow_caster_cube.glsl. +layout( binding = 2 ) uniform ub_draw +{ + ivec4 inst_base; +}; + +struct instance +{ + vec4 xform_row0; // .xyz = rotation row 0, .w = center.x + vec4 xform_row1; // .xyz = rotation row 1, .w = center.y + vec4 xform_row2; // .xyz = rotation row 2, .w = center.z + vec4 base_color; // unused in caster, present so layout matches lit pipeline + vec4 params; // .x = halfLength, .y = radius + vec4 material; // unused in caster, present so layout matches lit pipeline +}; + +layout( binding = 0 ) readonly buffer instances +{ + instance items[]; +}; + +in vec3 in_axis; // axis-direction component, scaled by halfLength +in vec3 in_radial; // radial component, scaled by radius + +void main() +{ + instance inst = items[inst_base.x + gl_InstanceIndex]; + vec3 center = vec3( inst.xform_row0.w, inst.xform_row1.w, inst.xform_row2.w ); + float halfLength = inst.params.x; + float radius = inst.params.y; + + vec3 local_pos = in_axis * halfLength + in_radial * radius; + vec3 world_pos = center + vec3( dot( inst.xform_row0.xyz, local_pos ), dot( inst.xform_row1.xyz, local_pos ), + dot( inst.xform_row2.xyz, local_pos ) ); + gl_Position = light_view_proj * vec4( world_pos, 1.0 ); +} +#pragma sokol @end + +#pragma sokol @fs fs +void main() +{ +} +#pragma sokol @end + +#pragma sokol @program caster vs fs diff --git a/samples/shaders/shapes/shadow_caster_cube.glsl b/samples/shaders/shapes/shadow_caster_cube.glsl new file mode 100644 index 0000000..9bf9801 --- /dev/null +++ b/samples/shaders/shapes/shadow_caster_cube.glsl @@ -0,0 +1,78 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Shadow caster for cubes. Depth-only, no fragment output, the +// pipeline runs with color_count=0 and writes only into the cascade's +// depth attachment. +// +// Shares the cube instance buffer layout with cube.glsl: each instance is +// a 3x4 row-major affine plus PBR material data (base_color + material are +// unused here but kept in the layout so one storage buffer feeds both +// pipelines without any repacking, struct stride MUST match the lit +// pipeline's, otherwise indexing breaks). +// +// Shadow space is standard Z (0 near = closer to light, 1 far). The light +// matrix uploaded as ub_frame.light_view_proj is constructed with +// an orthographic projection and mat4LookAt on the C side, which already +// produces the correct convention. No reverse-Z swap. +// +// `@module shadow_cube` keeps the generated symbols (shadow_cube_*) out +// collision with the lit cube pipeline's symbols. + +#pragma sokol @module shadow_cube + +#pragma sokol @ctype mat4 Mat4 +#pragma sokol @ctype vec4 Vec4 +#pragma sokol @ctype vec3 b3Vec3 +#pragma sokol @ctype vec2 b3Vec2 + +#pragma sokol @vs vs + +layout( binding = 0 ) uniform ub_frame +{ + mat4 light_view_proj; +}; + +// per-draw offset. Opaque draws set inst_base.x = 0, transparent +// draws (per the SHADOW_FULL flag) pick one instance at a time from the +// transparent arena. +layout( binding = 2 ) uniform ub_draw +{ + ivec4 inst_base; +}; + +struct cube_instance +{ + vec4 xform_row0; + vec4 xform_row1; + vec4 xform_row2; + vec4 base_color; // unused in caster, present so layout matches lit pipeline + vec4 material; // unused in caster, present so layout matches lit pipeline +}; + +layout( binding = 0 ) readonly buffer cube_instances +{ + cube_instance instances[]; +}; + +in vec3 in_pos; + +void main() +{ + cube_instance inst = instances[inst_base.x + gl_InstanceIndex]; + vec4 local_pos = vec4( in_pos, 1.0 ); + vec3 world_pos = + vec3( dot( inst.xform_row0, local_pos ), dot( inst.xform_row1, local_pos ), dot( inst.xform_row2, local_pos ) ); + gl_Position = light_view_proj * vec4( world_pos, 1.0 ); +} +#pragma sokol @end + +#pragma sokol @fs fs +// Empty FS: pipeline is created with color_count = 0. The rasterizer +// generates depth values from gl_Position, nothing else gets written. +void main() +{ +} +#pragma sokol @end + +#pragma sokol @program caster vs fs diff --git a/samples/shaders/shapes/shadow_caster_geom.glsl b/samples/shaders/shapes/shadow_caster_geom.glsl new file mode 100644 index 0000000..34e6e90 --- /dev/null +++ b/samples/shaders/shapes/shadow_caster_geom.glsl @@ -0,0 +1,79 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Shadow caster for triangle geometries (hulls, meshes, heightfields). +// Depth-only: color_count=0, empty fragment shader, writes only the +// cascade's depth attachment. +// +// Mirrors geom.glsl exactly in instance/vertex layout so the same +// per-frame instance buffer + per-entry vbo/ibo bindings drive both +// pipelines. The lit pipeline samples the surface normal for shading, +// here it's accepted as a vertex attribute and ignored. Keeping the +// vertex layout identical means the renderer doesn't have to maintain +// two parallel buffer schemes. +// +// `@module shadow_geom` keeps the generated symbols out of collision +// with the lit geom pipeline's symbols. + +#pragma sokol @module shadow_geom + +#pragma sokol @ctype mat4 Mat4 +#pragma sokol @ctype vec4 Vec4 +#pragma sokol @ctype vec3 b3Vec3 +#pragma sokol @ctype vec2 b3Vec2 + +#pragma sokol @vs vs + +layout( binding = 0 ) uniform ub_frame +{ + mat4 light_view_proj; +}; + +layout( binding = 2 ) uniform ub_draw +{ + ivec4 inst_base; // .x = first-instance offset into the global geom instance buffer +}; + +struct instance +{ + vec4 xform_row0; // .xyz = rotation row 0, .w = center.x + vec4 xform_row1; + vec4 xform_row2; + vec4 base_color; // unused here, layout matches lit pipeline + vec4 scale; // .xyz = per-instance scale (mesh only), hulls/heightfields = 1 + vec4 material; // unused here, layout matches lit pipeline +}; + +layout( binding = 0 ) readonly buffer instances +{ + instance items[]; +}; + +// Position-only input. The shared vertex buffer carries position+normal +// (stride 24 bytes), but this caster doesn't read the normal. We just +// don't declare an `in_normal` attribute so glslang doesn't keep it +// around (and the GL driver doesn't warn about an unused attribute slot +// after stripping). The C-side pipeline desc skips the in_normal binding +// to match. +in vec3 in_pos; + +void main() +{ + instance inst = items[inst_base.x + gl_InstanceIndex]; + + vec3 scaled_pos = in_pos * inst.scale.xyz; + vec4 local_pos = vec4( scaled_pos, 1.0 ); + vec3 world_pos = + vec3( dot( inst.xform_row0, local_pos ), dot( inst.xform_row1, local_pos ), dot( inst.xform_row2, local_pos ) ); + + gl_Position = light_view_proj * vec4( world_pos, 1.0 ); +} +#pragma sokol @end + +#pragma sokol @fs fs +void main() +{ +} +#pragma sokol @end + +#pragma sokol @program caster vs fs diff --git a/samples/shaders/shapes/shadow_caster_sphere.glsl b/samples/shaders/shapes/shadow_caster_sphere.glsl new file mode 100644 index 0000000..f3738e7 --- /dev/null +++ b/samples/shaders/shapes/shadow_caster_sphere.glsl @@ -0,0 +1,71 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Shadow caster for spheres. The lit sphere pipeline ray-casts an +// analytic sphere from a bounding-cube proxy, but we can't afford to +// write gl_FragDepth in a depth-only shadow pass (early-Z killed, high +// shadow-map resolution makes the cost prohibitive). Instead the shadow +// pipeline rasterizes a low-poly icosphere proxy (subdiv-1, 42 verts, 80 +// tris) generated at InitRenderer and stored in dedicated icosphere vbuf/ibuf. +// +// Per-vertex: in_pos is a unit-sphere position (length == 1). Per-instance +// reads from the same sphere instance buffer the lit pipeline uses, the +// rotation rows are ignored (a sphere is rotation-invariant) and only +// the center (xform_row*.w) and radius (params.x) participate. +// +// `@module shadow_sphere` namespaces the generated symbols. + +#pragma sokol @module shadow_sphere + +#pragma sokol @ctype mat4 Mat4 +#pragma sokol @ctype vec4 Vec4 +#pragma sokol @ctype vec3 b3Vec3 +#pragma sokol @ctype vec2 b3Vec2 + +#pragma sokol @vs vs + +layout( binding = 0 ) uniform ub_frame +{ + mat4 light_view_proj; +}; + +// per-draw offset, see shadow_caster_cube.glsl. +layout( binding = 2 ) uniform ub_draw +{ + ivec4 inst_base; +}; + +struct instance +{ + vec4 xform_row0; // .xyz = rotation row 0 (unused), .w = center.x + vec4 xform_row1; // .xyz = rotation row 1 (unused), .w = center.y + vec4 xform_row2; // .xyz = rotation row 2 (unused), .w = center.z + vec4 base_color; // unused in caster, present so layout matches lit pipeline + vec4 params; // .x = radius + vec4 material; // unused in caster, present so layout matches lit pipeline +}; + +layout( binding = 0 ) readonly buffer instances +{ + instance items[]; +}; + +in vec3 in_pos; // unit-icosphere vertex (length == 1) + +void main() +{ + instance inst = items[inst_base.x + gl_InstanceIndex]; + vec3 center = vec3( inst.xform_row0.w, inst.xform_row1.w, inst.xform_row2.w ); + float radius = inst.params.x; + vec3 world_pos = center + radius * in_pos; + gl_Position = light_view_proj * vec4( world_pos, 1.0 ); +} +#pragma sokol @end + +#pragma sokol @fs fs +void main() +{ +} +#pragma sokol @end + +#pragma sokol @program caster vs fs diff --git a/samples/shaders/shapes/sphere.glsl b/samples/shaders/shapes/sphere.glsl new file mode 100644 index 0000000..64cc2e8 --- /dev/null +++ b/samples/shaders/shapes/sphere.glsl @@ -0,0 +1,416 @@ +// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-License-Identifier: MIT + +// Sphere impostor. +// +// Per-instance: a 3x4 rigid affine (orthonormal rotation rows in .xyz of each +// xform_row*, sphere center in .w of each row), an RGBA color, and a `params` +// row whose .x is the world-space radius. Rotation does not change the +// silhouette (a sphere is rotation-invariant) so the bounding-cube proxy is +// emitted axis-aligned. Rotation feeds the surface pattern in the FS so spin +// is visible. +// +// Pipeline overview: +// VS: emit a unit-cube vertex scaled by 2*radius and translated by center. +// Pass world position of the proxy vertex (interpolated) plus flat +// per-instance data (center, radius, rotation rows, color) to FS. +// FS: reconstruct view ray as (camera, normalize(v_world_pos_proxy - camera)). +// Analytic ray-sphere intersection. discard on miss / behind-camera. +// Compute world-space normal at the hit, transform to object space via +// transpose(rotation), shade three great-circle rings at the +// object-space x=0, y=0, z=0 equators (constant screen-space pixel +// thickness via fwidth) over a north/south hemisphere base contrast, +// apply Lambert + ambient against world-space sun, write reverse-Z +// gl_FragDepth. +// +// `@module sphere` prefixes the generated C symbols (sphere_ub_frame_t, +// sphere_instance_t, sphere_shader_desc, ...) so this header coexists with +// cube.glsl.h in renderer.c without typedef collisions on ub_frame_t. +// +// UBO layout. UBOs are per-stage in sokol-shdc: +// VS binding=0 ub_frame: just view_proj. That's all the VS needs to emit +// the proxy in clip space. +// FS binding=1 ub_pass: sun + debug flags + camera_pos + view_proj + view. +// The frame-level matrices live here (rather than in +// a second FS UBO at a different binding) because +// the renderer always re-applies ub_pass per draw, +// and one FS UBO is simpler than two. Naming is a +// slight stretch (some fields are per-frame, not +// per-pass) but correctness-wise irrelevant in a +// single-pass renderer. +// +// gl_FragDepth disables hi-Z. That's accepted for impostors. + +#pragma sokol @module sphere + +#pragma sokol @ctype mat4 Mat4 +#pragma sokol @ctype vec4 Vec4 +#pragma sokol @ctype vec3 b3Vec3 +#pragma sokol @ctype vec2 b3Vec2 + +#pragma sokol @vs vs + +layout( binding = 0 ) uniform ub_frame +{ + mat4 view_proj; +}; + +// per-draw offset into the instance buffer. See cube.glsl for the +// rationale. Opaque draws set inst_base.x = 0 + bulk-instance, transparent +// draws pick one instance at a time. +layout( binding = 2 ) uniform ub_draw +{ + ivec4 inst_base; +}; + +struct instance +{ + vec4 xform_row0; // .xyz = rotation row 0, .w = center.x + vec4 xform_row1; // .xyz = rotation row 1, .w = center.y + vec4 xform_row2; // .xyz = rotation row 2, .w = center.z + vec4 base_color; // .rgb = linear baseColor, .a = alpha + vec4 params; // .x = radius, .yzw = unused + vec4 material; // .x = metallic, .y = roughness, + // .z = shadow-cast bit (, CPU-only, ignored here), + // .w = reserved +}; + +layout( binding = 0 ) readonly buffer instances +{ + instance items[]; +}; + +in vec3 in_pos; // unit-cube corner, half-extent 0.5 + +// Interpolated: any point along the camera-to-pixel ray works as a far +// reference, we re-normalize in FS. Per-pixel (not per-sample): the FS +// computes analytical sub-pixel coverage from the signed silhouette +// distance and feeds it through alpha-to-coverage, which replaces the +// per-sample ray test the `sample` qualifier used to do. +out vec3 v_world_pos_proxy; + +// Flat: same value for every fragment in this instance. +flat out vec3 v_center; +flat out float v_radius; +flat out vec3 v_rot_row0; +flat out vec3 v_rot_row1; +flat out vec3 v_rot_row2; +flat out vec4 v_base_color; +flat out vec4 v_material; + +void main() +{ + instance inst = items[inst_base.x + gl_InstanceIndex]; + + // sphere center in world space + vec3 center = vec3( inst.xform_row0.w, inst.xform_row1.w, inst.xform_row2.w ); + float radius = inst.params.x; + + // Local in_pos has half-extent 0.5, multiply by 2*radius to get a cube + // half-extent radius exactly enclosing the sphere. + // This creates an AABB in world space + vec3 world_pos = center + ( 2.0 * radius ) * in_pos; + + v_world_pos_proxy = world_pos; + v_center = center; + v_radius = radius; + v_rot_row0 = inst.xform_row0.xyz; + v_rot_row1 = inst.xform_row1.xyz; + v_rot_row2 = inst.xform_row2.xyz; + v_base_color = inst.base_color; + v_material = inst.material; + + gl_Position = view_proj * vec4( world_pos, 1.0 ); +} + +#pragma sokol @end + +#pragma sokol @fs fs + +#pragma sokol @include ../common/pbr.glsl + +layout( binding = 1 ) uniform ub_pass +{ + vec4 sun_dir_world; // .xyz = world-space dir TO sun (normalized) + vec4 sun_color; // .rgb = color, .a = ambient strength (flat-ambient fallback) + ivec4 flags; // .x = debug_view_mode (0 lit, 1 view-depth, 2 cascade-index) + vec4 camera_pos; // .xyz = camera world pos, .w unused + mat4 view_proj; // for reverse-Z gl_FragDepth + mat4 view; // for view-space depth debug mode + cascade selection + vec4 cascade_far_view_z; // .xyz = far view-space Z per cascade + mat4 cascade_matrices[3]; // light-space view-proj per cascade + vec4 sh[9]; // IBL diffuse SH coefficients (band 0..2, RGB in .xyz) + vec4 ibl_params; // .x = prefilter cube max_lod, .y = IBL enable (1=IBL, 0=flat ambient), .zw reserved +}; + +#pragma sokol @image_sample_type tex_shadow depth +layout( binding = 1 ) uniform texture2DArray tex_shadow; +#pragma sokol @sampler_type smp_shadow comparison +layout( binding = 0 ) uniform samplerShadow smp_shadow; + +// IBL bindings, same convention as cube.glsl: texture bindings 2/3, +// sampler bindings 1/2, disjoint from the shadow path's 1/0. +#pragma sokol @image_sample_type tex_ibl_spec float +layout( binding = 2 ) uniform textureCube tex_ibl_spec; +#pragma sokol @sampler_type smp_ibl_spec filtering +layout( binding = 1 ) uniform sampler smp_ibl_spec; +#pragma sokol @image_sample_type tex_brdf_lut float +layout( binding = 3 ) uniform texture2D tex_brdf_lut; +#pragma sokol @sampler_type smp_brdf_lut filtering +layout( binding = 2 ) uniform sampler smp_brdf_lut; + +// GTAO, same convention as cube.glsl. Multiplies only the IBL ambient. +#pragma sokol @image_sample_type tex_ao float +layout( binding = 4 ) uniform texture2D tex_ao; +#pragma sokol @sampler_type smp_ao filtering +layout( binding = 3 ) uniform sampler smp_ao; + +// 3x3 PCF over a 1-texel radius. Manually unrolled, see cube.glsl for +// the X3570 rationale. +float sampleShadowPCF( int cascade, vec3 light_uv, float bias ) +{ + float t = 1.0 / 2048.0; + float ly = float( cascade ); + float rz = light_uv.z - bias; + vec2 c = light_uv.xy; + float s = 0.0; + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x - t, c.y - t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x, c.y - t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x + t, c.y - t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x - t, c.y, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x, c.y, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x + t, c.y, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x - t, c.y + t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x, c.y + t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x + t, c.y + t, ly, rz ) ); + return s / 9.0; +} + +float sampleCascade( int cascade, vec3 world_pos, vec3 world_normal ) +{ + vec4 light_clip = cascade_matrices[cascade] * vec4( world_pos, 1.0 ); + vec3 light_ndc = light_clip.xyz / light_clip.w; + // Backend-dependent Y orientation, see cube.glsl for the longer note. + float ny = light_ndc.y * cascade_far_view_z.w; + vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z ); + + if ( any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) ) ) + { + return 1.0; + } + + float n_dot_l = max( dot( world_normal, normalize( sun_dir_world.xyz ) ), 0.0 ); + float bias = mix( 0.0040, 0.0008, n_dot_l ); + + float pcf = sampleShadowPCF( cascade, light_uv, bias ); + + // See cube.glsl for the longer note. Cascade 2 has no fallback at its + // UV boundary, so fade PCF toward 1.0 over the outer 10% to hide the + // polygonal seam where cascade 2's spatial extent ends on the ground. + if ( cascade == 2 ) + { + vec2 edge = min( light_uv.xy, 1.0 - light_uv.xy ); + float fade = clamp( min( edge.x, edge.y ) * 10.0, 0.0, 1.0 ); + pcf = mix( 1.0, pcf, fade ); + } + + return pcf; +} + +float sampleShadowCascaded( vec3 world_pos, vec3 world_normal, float view_z ) +{ + int cascade = 2; + if ( view_z < cascade_far_view_z.x ) + cascade = 0; + else if ( view_z < cascade_far_view_z.y ) + cascade = 1; + + float shadow = sampleCascade( cascade, world_pos, world_normal ); + + // Blend the last 10% of each cascade's range with the next cascade + // to hide the polygonal step where they meet. See cube.glsl for the + // longer note. + if ( cascade < 2 ) + { + float far_z = ( cascade == 0 ) ? cascade_far_view_z.x : cascade_far_view_z.y; + float near_z = ( cascade == 0 ) ? 0.0 : cascade_far_view_z.x; + float blend_start = mix( far_z, near_z, 0.1 ); + if ( view_z > blend_start ) + { + float alpha = ( view_z - blend_start ) / ( far_z - blend_start ); + shadow = mix( shadow, sampleCascade( cascade + 1, world_pos, world_normal ), alpha ); + } + } + + return shadow; +} + +in vec3 v_world_pos_proxy; + +// sphere center in world space +flat in vec3 v_center; +flat in float v_radius; +flat in vec3 v_rot_row0; +flat in vec3 v_rot_row1; +flat in vec3 v_rot_row2; +flat in vec4 v_base_color; +flat in vec4 v_material; + +out vec4 out_color; + +void main() +{ + // Ray construction (world space) + // ray origin + vec3 ro = camera_pos.xyz; + + // ray direction + vec3 rd = normalize( v_world_pos_proxy - ro ); + + // Ray-sphere intersection + // |ro + t*rd - c|^2 = r^2 => t^2 + 2*b*t + c2 = 0 + vec3 oc = ro - v_center; + float b = dot( oc, rd ); + float c2 = dot( oc, oc ) - v_radius * v_radius; + float h = b * b - c2; + + // Analytical silhouette AA. `d` is the signed perpendicular distance from + // the ray-line to the sphere surface (in world units): negative when the + // ray hits, positive when it misses by `d`. fwidth(d) gives world-units + // per pixel near the silhouette, which becomes the AA half-width. See + // https://iquilezles.org/articles/spherefunctions . Computed in uniform + // control flow before any discard so derivatives are defined. + float d = sqrt( max( 0.0, v_radius * v_radius - h ) ) - v_radius; + float aa = max( fwidth( d ), 1e-6 ); + float coverage = 1.0 - smoothstep( -aa, aa, d ); + + // For hits use the near intersection. For near-misses (h<0) the ray + // doesn't actually touch the sphere, use the closest-approach distance + // -b instead, and shade from the closest-approach point. The resulting + // normal (direction from center to closest-approach) is the silhouette + // normal, which is what these sub-pixel fragments should display anyway. + float t = ( h >= 0.0 ) ? ( -b - sqrt( h ) ) : -b; + if ( coverage <= 0.0 || t < 0.0 ) + { + // True miss outside the AA band, or sphere behind camera, or camera + // inside the sphere. + discard; + } + + vec3 hit_world = ro + t * rd; + vec3 n_world = normalize( hit_world - v_center ); + + // Object-space normal via R^T + // n_obj = R^T * n_world. R^T's rows are the columns of R. The .x + // components of v_rot_row0/1/2 form row 0 of R^T, .y components form row + // 1, .z components form row 2. + vec3 n_obj = vec3( v_rot_row0.x * n_world.x + v_rot_row1.x * n_world.y + v_rot_row2.x * n_world.z, + v_rot_row0.y * n_world.x + v_rot_row1.y * n_world.y + v_rot_row2.y * n_world.z, + v_rot_row0.z * n_world.x + v_rot_row1.z * n_world.y + v_rot_row2.z * n_world.z ); + + // Surface pattern + // Hemisphere split: north 1.0, south 0.65, base shading contrast. + float hemi = ( n_obj.y > 0.0 ) ? 1.0 : 0.65; + + // Three great-circle rings at the equators of object-space X, Y, Z. + // Each equator is the locus where the corresponding object-space normal + // component is zero, so the distance-to-equator is just the absolute + // value of that component (a chord-distance metric in [0, 1] that's + // monotonic in the geodesic distance from the great circle). + // + // Constant screen-space thickness via per-component fwidth: each ring's + // band scales with the per-pixel rate of change of *its own* normal + // component, so it stays ~LINE_PIXELS wide independent of camera zoom + // and viewing angle. fwidth is taken on the *signed* component (not on + // abs(.)): abs has a derivative kink at zero (the equator itself), + // so fwidth(abs(x)) gives garbage on 2x2 quads that straddle the + // equator. Don't use max of all three fwidths as the shared band: + // near the silhouette of one ring, the *other* two components change + // huge amounts per pixel (the surface is edge-on), and a shared band + // would over-fatten this ring. + const float LINE_PIXELS = 1.5; + float ring_x = 1.0 - smoothstep( 0.0, fwidth( n_obj.x ) * LINE_PIXELS, abs( n_obj.x ) ); + float ring_y = 1.0 - smoothstep( 0.0, fwidth( n_obj.y ) * LINE_PIXELS, abs( n_obj.y ) ); + float ring_z = 1.0 - smoothstep( 0.0, fwidth( n_obj.z ) * LINE_PIXELS, abs( n_obj.z ) ); + float line = max( ring_x, max( ring_y, ring_z ) ); + + vec3 base = v_base_color.rgb * hemi; + vec3 line_color = base * 0.35; + vec3 surface = mix( base, line_color, line ); + + // Reverse-Z depth + vec4 hit_clip = view_proj * vec4( hit_world, 1.0 ); + gl_FragDepth = hit_clip.z / hit_clip.w; + + // Output + if ( flags.x == 1 ) + { + // view-space depth grayscale, matches cube debug mode. + vec3 hit_view = ( view * vec4( hit_world, 1.0 ) ).xyz; + float view_depth = -hit_view.z; + float v = clamp( view_depth / 50.0, 0.0, 1.0 ); + out_color = vec4( v, v, v, 1.0 ); + return; + } + if ( flags.x == 2 ) + { + float view_z_dbg = -( view * vec4( hit_world, 1.0 ) ).z; + int cascade = 2; + if ( view_z_dbg < cascade_far_view_z.x ) + cascade = 0; + else if ( view_z_dbg < cascade_far_view_z.y ) + cascade = 1; + vec4 light_clip = cascade_matrices[cascade] * vec4( hit_world, 1.0 ); + vec3 light_ndc = light_clip.xyz / light_clip.w; + float ny = light_ndc.y * cascade_far_view_z.w; + vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z ); + bool oob = any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) ); + vec3 tint = vec3( 1.0 ); + if ( !oob ) + { + if ( cascade == 0 ) + tint = vec3( 1.0, 0.4, 0.4 ); + else if ( cascade == 1 ) + tint = vec3( 0.4, 1.0, 0.4 ); + else + tint = vec3( 0.4, 0.4, 1.0 ); + } + out_color = vec4( tint, 1.0 ); + return; + } + if ( flags.x == 3 ) + { + // View-space normal as RGB, [-1,1] mapped to [0,1]. + vec3 n_view = ( view * vec4( n_world, 0.0 ) ).xyz; + out_color = vec4( normalize( n_view ) * 0.5 + 0.5, 1.0 ); + return; + } + + // GTAO sample. + vec2 ao_uv = gl_FragCoord.xy / vec2( textureSize( sampler2D( tex_ao, smp_ao ), 0 ) ); + float ao = textureLod( sampler2D( tex_ao, smp_ao ), ao_uv, 0.0 ).x; + + if ( flags.x == 4 ) + { + out_color = vec4( vec3( ao ), 1.0 ); + return; + } + + vec3 L = normalize( sun_dir_world.xyz ); + float n_dot_l = max( dot( n_world, L ), 0.0 ); + float view_z = -( view * vec4( hit_world, 1.0 ) ).z; + float shadow = sampleShadowCascaded( hit_world, n_world, view_z ); + vec3 V = normalize( camera_pos.xyz - hit_world ); + vec3 direct = brdf_evaluate( n_world, V, L, sun_color.rgb * shadow, surface, v_material.x, v_material.y ); + vec3 ambient = pbrEvaluateAmbient( ibl_params.y > 0.5, n_world, V, surface, v_material.x, v_material.y, sun_color.a, sh, + tex_ibl_spec, smp_ibl_spec, tex_brdf_lut, smp_brdf_lut, ibl_params.x ); + // premultiplied output, see cube.glsl. Alpha is scaled by analytical + // silhouette coverage so alpha-to-coverage (opaque pipeline) or the + // premultiplied alpha blend (transparent pipeline) produces a smooth + // sub-pixel silhouette instead of a binary hit/miss edge. + float a = v_base_color.a * coverage; + out_color = vec4( ( direct + ambient * ao ) * a, a ); +} +#pragma sokol @end + +#pragma sokol @program impostor vs fs diff --git a/samples/ssao_buffer.cpp b/samples/ssao_buffer.cpp deleted file mode 100644 index 1ff1516..0000000 --- a/samples/ssao_buffer.cpp +++ /dev/null @@ -1,163 +0,0 @@ -// SPDX-FileCopyrightText: 2025 Erin Catto -// SPDX-License-Identifier: MIT - -#include "ssao_buffer.h" - -#include "box3d/math_functions.h" -#include "shader.h" - -#include -#include -#include -#include -#include - -#include "geo_buffer.h" - -struct SsaoBuffer -{ - int32_t width, height; - uint32_t frameBufferId; - uint32_t blurFrameBufferId; - uint32_t colorBufferId; - uint32_t blurColorBufferId; - - b3Vec3 ssaoKernel[32]; - uint32_t noiseTexture; -}; - -SsaoBuffer* CreateSsaoBuffer(int32_t width, int32_t height) -{ - SsaoBuffer* buffer = (SsaoBuffer*)malloc(sizeof(SsaoBuffer)); - buffer->width = width; - buffer->height = height; - - // frame buffer - glGenFramebuffers(1, &buffer->frameBufferId); - glBindFramebuffer(GL_FRAMEBUFFER, buffer->frameBufferId); - - // color buffer - glGenTextures(1, &buffer->colorBufferId); - glBindTexture(GL_TEXTURE_2D, buffer->colorBufferId); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, width, height, 0, GL_RED, GL_FLOAT, NULL); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, buffer->colorBufferId, 0); - - if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) - { - fprintf(stderr, "SSAO Framebuffer not complete!\n"); - free(buffer); - return nullptr; - } - - // blur frame buffer - glGenFramebuffers(1, &buffer->blurFrameBufferId); - glBindFramebuffer(GL_FRAMEBUFFER, buffer->blurFrameBufferId); - - // blur color buffer - glGenTextures(1, &buffer->blurColorBufferId); - glBindTexture(GL_TEXTURE_2D, buffer->blurColorBufferId); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, width, height, 0, GL_RED, GL_FLOAT, NULL); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, buffer->blurColorBufferId, 0); - if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) - { - fprintf(stderr, "SSAO Blur Framebuffer not complete!\n"); - free(buffer); - return nullptr; - } - - // unbind frame buffer - glBindFramebuffer(GL_FRAMEBUFFER, 0); - - // generate sample kernel - std::uniform_real_distribution randomFloats(0.0f, 1.0f); // generates random floats between 0.0 and 1.0 - std::default_random_engine generator; - - for (uint32_t i = 0; i < 32; ++i) - { - b3Vec3 sample{randomFloats(generator) * 2.0f - 1.0f, randomFloats(generator) * 2.0f - 1.0f, randomFloats(generator)}; - sample = b3Normalize(sample); - sample = randomFloats(generator) * sample; - float scale = float(i) / 32.0f; - - // scale samples s.t. they're more aligned to center of kernel - scale = b3LerpFloat(0.1f, 1.0f, scale * scale); - sample = scale * sample; - buffer->ssaoKernel[i] = sample; - } - - // random sample kernel tangent vectors stuffed into a texture - b3Vec3 ssaoNoise[16]; - for (b3Vec3& noise : ssaoNoise) - { - // rotate around z-axis (in tangent space) - noise = {randomFloats(generator) * 2.0f - 1.0f, randomFloats(generator) * 2.0f - 1.0f, 0.0f}; - } - - glGenTextures(1, &buffer->noiseTexture); - glBindTexture(GL_TEXTURE_2D, buffer->noiseTexture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 4, 4, 0, GL_RGB, GL_FLOAT, &ssaoNoise[0]); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - - return buffer; -} - -void BindSsaoBuffer(SsaoBuffer* buffer) -{ - glBindFramebuffer(GL_FRAMEBUFFER, buffer->frameBufferId); - glClear(GL_COLOR_BUFFER_BIT); -} - -void SetSsaoSamples(SsaoBuffer* buffer, uint32_t ssaoShader) -{ - // Send kernel + rotation - for (uint32_t i = 0; i < 32; ++i) - { - char sampleName[32]; - snprintf(sampleName, 32, "samples[%d]", i); - SetUniformVec3(ssaoShader, sampleName, buffer->ssaoKernel[i]); - } -} - -void BindSsaoTextures(SsaoBuffer* buffer) -{ - glActiveTexture(GL_TEXTURE2); - glBindTexture(GL_TEXTURE_2D, buffer->noiseTexture); -} - -void BindSsaoBlurBuffer(SsaoBuffer* buffer) -{ - glBindFramebuffer(GL_FRAMEBUFFER, buffer->blurFrameBufferId); - glClear(GL_COLOR_BUFFER_BIT); -} - -void BindSsaoColorTexture(SsaoBuffer* buffer) -{ - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, buffer->colorBufferId); -} - -void BindSsaoBlurTexture(SsaoBuffer* buffer) -{ - glActiveTexture(GL_TEXTURE3); - glBindTexture(GL_TEXTURE_2D, buffer->blurColorBufferId); -} - -void DestroySsaoBuffer(SsaoBuffer* buffer) -{ - glDeleteFramebuffers(1, &buffer->frameBufferId); - glDeleteFramebuffers(1, &buffer->blurFrameBufferId); - - glDeleteTextures(1, &buffer->colorBufferId); - glDeleteTextures(1, &buffer->blurColorBufferId); - - glDeleteTextures(1, &buffer->noiseTexture); - - free(buffer); -} diff --git a/samples/ssao_buffer.h b/samples/ssao_buffer.h deleted file mode 100644 index e9c1d11..0000000 --- a/samples/ssao_buffer.h +++ /dev/null @@ -1,21 +0,0 @@ -// SPDX-FileCopyrightText: 2025 Erin Catto -// SPDX-License-Identifier: MIT - -#pragma once - -#include - -struct SsaoBuffer; -struct GeoBuffer; - -SsaoBuffer* CreateSsaoBuffer(int32_t width, int32_t height); - -void BindSsaoBuffer(SsaoBuffer* buffer); -void SetSsaoSamples(SsaoBuffer* buffer, uint32_t ssaoShader); -void BindSsaoTextures(SsaoBuffer* buffer); - -void BindSsaoBlurBuffer(SsaoBuffer* buffer); -void BindSsaoColorTexture(SsaoBuffer* buffer); -void BindSsaoBlurTexture(SsaoBuffer* buffer); - -void DestroySsaoBuffer(SsaoBuffer* buffer); diff --git a/samples/stb_image_write.h b/samples/stb_image_write.h deleted file mode 100644 index 151eaca..0000000 --- a/samples/stb_image_write.h +++ /dev/null @@ -1,1724 +0,0 @@ -/* stb_image_write - v1.16 - public domain - http://nothings.org/stb - writes out PNG/BMP/TGA/JPEG/HDR images to C stdio - Sean Barrett 2010-2015 - no warranty implied; use at your own risk - - Before #including, - - #define STB_IMAGE_WRITE_IMPLEMENTATION - - in the file that you want to have the implementation. - - Will probably not work correctly with strict-aliasing optimizations. - -ABOUT: - - This header file is a library for writing images to C stdio or a callback. - - The PNG output is not optimal; it is 20-50% larger than the file - written by a decent optimizing implementation; though providing a custom - zlib compress function (see STBIW_ZLIB_COMPRESS) can mitigate that. - This library is designed for source code compactness and simplicity, - not optimal image file size or run-time performance. - -BUILDING: - - You can #define STBIW_ASSERT(x) before the #include to avoid using assert.h. - You can #define STBIW_MALLOC(), STBIW_REALLOC(), and STBIW_FREE() to replace - malloc,realloc,free. - You can #define STBIW_MEMMOVE() to replace memmove() - You can #define STBIW_ZLIB_COMPRESS to use a custom zlib-style compress function - for PNG compression (instead of the builtin one), it must have the following signature: - unsigned char * my_compress(unsigned char *data, int data_len, int *out_len, int quality); - The returned data will be freed with STBIW_FREE() (free() by default), - so it must be heap allocated with STBIW_MALLOC() (malloc() by default), - -UNICODE: - - If compiling for Windows and you wish to use Unicode filenames, compile - with - #define STBIW_WINDOWS_UTF8 - and pass utf8-encoded filenames. Call stbiw_convert_wchar_to_utf8 to convert - Windows wchar_t filenames to utf8. - -USAGE: - - There are five functions, one for each image file format: - - int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes); - int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data); - int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data); - int stbi_write_jpg(char const *filename, int w, int h, int comp, const void *data, int quality); - int stbi_write_hdr(char const *filename, int w, int h, int comp, const float *data); - - void stbi_flip_vertically_on_write(int flag); // flag is non-zero to flip data vertically - - There are also five equivalent functions that use an arbitrary write function. You are - expected to open/close your file-equivalent before and after calling these: - - int stbi_write_png_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data, int stride_in_bytes); - int stbi_write_bmp_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data); - int stbi_write_tga_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data); - int stbi_write_hdr_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const float *data); - int stbi_write_jpg_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int quality); - - where the callback is: - void stbi_write_func(void *context, void *data, int size); - - You can configure it with these global variables: - int stbi_write_tga_with_rle; // defaults to true; set to 0 to disable RLE - int stbi_write_png_compression_level; // defaults to 8; set to higher for more compression - int stbi_write_force_png_filter; // defaults to -1; set to 0..5 to force a filter mode - - - You can define STBI_WRITE_NO_STDIO to disable the file variant of these - functions, so the library will not use stdio.h at all. However, this will - also disable HDR writing, because it requires stdio for formatted output. - - Each function returns 0 on failure and non-0 on success. - - The functions create an image file defined by the parameters. The image - is a rectangle of pixels stored from left-to-right, top-to-bottom. - Each pixel contains 'comp' channels of data stored interleaved with 8-bits - per channel, in the following order: 1=Y, 2=YA, 3=RGB, 4=RGBA. (Y is - monochrome color.) The rectangle is 'w' pixels wide and 'h' pixels tall. - The *data pointer points to the first byte of the top-left-most pixel. - For PNG, "stride_in_bytes" is the distance in bytes from the first byte of - a row of pixels to the first byte of the next row of pixels. - - PNG creates output files with the same number of components as the input. - The BMP format expands Y to RGB in the file format and does not - output alpha. - - PNG supports writing rectangles of data even when the bytes storing rows of - data are not consecutive in memory (e.g. sub-rectangles of a larger image), - by supplying the stride between the beginning of adjacent rows. The other - formats do not. (Thus you cannot write a native-format BMP through the BMP - writer, both because it is in BGR order and because it may have padding - at the end of the line.) - - PNG allows you to set the deflate compression level by setting the global - variable 'stbi_write_png_compression_level' (it defaults to 8). - - HDR expects linear float data. Since the format is always 32-bit rgb(e) - data, alpha (if provided) is discarded, and for monochrome data it is - replicated across all three channels. - - TGA supports RLE or non-RLE compressed data. To use non-RLE-compressed - data, set the global variable 'stbi_write_tga_with_rle' to 0. - - JPEG does ignore alpha channels in input data; quality is between 1 and 100. - Higher quality looks better but results in a bigger image. - JPEG baseline (no JPEG progressive). - -CREDITS: - - - Sean Barrett - PNG/BMP/TGA - Baldur Karlsson - HDR - Jean-Sebastien Guay - TGA monochrome - Tim Kelsey - misc enhancements - Alan Hickman - TGA RLE - Emmanuel Julien - initial file IO callback implementation - Jon Olick - original jo_jpeg.cpp code - Daniel Gibson - integrate JPEG, allow external zlib - Aarni Koskela - allow choosing PNG filter - - bugfixes: - github:Chribba - Guillaume Chereau - github:jry2 - github:romigrou - Sergio Gonzalez - Jonas Karlsson - Filip Wasil - Thatcher Ulrich - github:poppolopoppo - Patrick Boettcher - github:xeekworx - Cap Petschulat - Simon Rodriguez - Ivan Tikhonov - github:ignotion - Adam Schackart - Andrew Kensler - -LICENSE - - See end of file for license information. - -*/ - -#ifndef INCLUDE_STB_IMAGE_WRITE_H -#define INCLUDE_STB_IMAGE_WRITE_H - -#include - -// if STB_IMAGE_WRITE_STATIC causes problems, try defining STBIWDEF to 'inline' or 'static inline' -#ifndef STBIWDEF -#ifdef STB_IMAGE_WRITE_STATIC -#define STBIWDEF static -#else -#ifdef __cplusplus -#define STBIWDEF extern "C" -#else -#define STBIWDEF extern -#endif -#endif -#endif - -#ifndef STB_IMAGE_WRITE_STATIC // C++ forbids static forward declarations -STBIWDEF int stbi_write_tga_with_rle; -STBIWDEF int stbi_write_png_compression_level; -STBIWDEF int stbi_write_force_png_filter; -#endif - -#ifndef STBI_WRITE_NO_STDIO -STBIWDEF int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes); -STBIWDEF int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data); -STBIWDEF int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data); -STBIWDEF int stbi_write_hdr(char const *filename, int w, int h, int comp, const float *data); -STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const void *data, int quality); - -#ifdef STBIW_WINDOWS_UTF8 -STBIWDEF int stbiw_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input); -#endif -#endif - -typedef void stbi_write_func(void *context, void *data, int size); - -STBIWDEF int stbi_write_png_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data, int stride_in_bytes); -STBIWDEF int stbi_write_bmp_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data); -STBIWDEF int stbi_write_tga_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data); -STBIWDEF int stbi_write_hdr_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const float *data); -STBIWDEF int stbi_write_jpg_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int quality); - -STBIWDEF void stbi_flip_vertically_on_write(int flip_boolean); - -#endif//INCLUDE_STB_IMAGE_WRITE_H - -#ifdef STB_IMAGE_WRITE_IMPLEMENTATION - -#ifdef _WIN32 - #ifndef _CRT_SECURE_NO_WARNINGS - #define _CRT_SECURE_NO_WARNINGS - #endif - #ifndef _CRT_NONSTDC_NO_DEPRECATE - #define _CRT_NONSTDC_NO_DEPRECATE - #endif -#endif - -#ifndef STBI_WRITE_NO_STDIO -#include -#endif // STBI_WRITE_NO_STDIO - -#include -#include -#include -#include - -#if defined(STBIW_MALLOC) && defined(STBIW_FREE) && (defined(STBIW_REALLOC) || defined(STBIW_REALLOC_SIZED)) -// ok -#elif !defined(STBIW_MALLOC) && !defined(STBIW_FREE) && !defined(STBIW_REALLOC) && !defined(STBIW_REALLOC_SIZED) -// ok -#else -#error "Must define all or none of STBIW_MALLOC, STBIW_FREE, and STBIW_REALLOC (or STBIW_REALLOC_SIZED)." -#endif - -#ifndef STBIW_MALLOC -#define STBIW_MALLOC(sz) malloc(sz) -#define STBIW_REALLOC(p,newsz) realloc(p,newsz) -#define STBIW_FREE(p) free(p) -#endif - -#ifndef STBIW_REALLOC_SIZED -#define STBIW_REALLOC_SIZED(p,oldsz,newsz) STBIW_REALLOC(p,newsz) -#endif - - -#ifndef STBIW_MEMMOVE -#define STBIW_MEMMOVE(a,b,sz) memmove(a,b,sz) -#endif - - -#ifndef STBIW_ASSERT -#include -#define STBIW_ASSERT(x) assert(x) -#endif - -#define STBIW_UCHAR(x) (unsigned char) ((x) & 0xff) - -#ifdef STB_IMAGE_WRITE_STATIC -static int stbi_write_png_compression_level = 8; -static int stbi_write_tga_with_rle = 1; -static int stbi_write_force_png_filter = -1; -#else -int stbi_write_png_compression_level = 8; -int stbi_write_tga_with_rle = 1; -int stbi_write_force_png_filter = -1; -#endif - -static int stbi__flip_vertically_on_write = 0; - -STBIWDEF void stbi_flip_vertically_on_write(int flag) -{ - stbi__flip_vertically_on_write = flag; -} - -typedef struct -{ - stbi_write_func *func; - void *context; - unsigned char buffer[64]; - int buf_used; -} stbi__write_context; - -// initialize a callback-based context -static void stbi__start_write_callbacks(stbi__write_context *s, stbi_write_func *c, void *context) -{ - s->func = c; - s->context = context; -} - -#ifndef STBI_WRITE_NO_STDIO - -static void stbi__stdio_write(void *context, void *data, int size) -{ - fwrite(data,1,size,(FILE*) context); -} - -#if defined(_WIN32) && defined(STBIW_WINDOWS_UTF8) -#ifdef __cplusplus -#define STBIW_EXTERN extern "C" -#else -#define STBIW_EXTERN extern -#endif -STBIW_EXTERN __declspec(dllimport) int __stdcall MultiByteToWideChar(unsigned int cp, unsigned long flags, const char *str, int cbmb, wchar_t *widestr, int cchwide); -STBIW_EXTERN __declspec(dllimport) int __stdcall WideCharToMultiByte(unsigned int cp, unsigned long flags, const wchar_t *widestr, int cchwide, char *str, int cbmb, const char *defchar, int *used_default); - -STBIWDEF int stbiw_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input) -{ - return WideCharToMultiByte(65001 /* UTF8 */, 0, input, -1, buffer, (int) bufferlen, NULL, NULL); -} -#endif - -static FILE *stbiw__fopen(char const *filename, char const *mode) -{ - FILE *f; -#if defined(_WIN32) && defined(STBIW_WINDOWS_UTF8) - wchar_t wMode[64]; - wchar_t wFilename[1024]; - if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, filename, -1, wFilename, sizeof(wFilename)/sizeof(*wFilename))) - return 0; - - if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, mode, -1, wMode, sizeof(wMode)/sizeof(*wMode))) - return 0; - -#if defined(_MSC_VER) && _MSC_VER >= 1400 - if (0 != _wfopen_s(&f, wFilename, wMode)) - f = 0; -#else - f = _wfopen(wFilename, wMode); -#endif - -#elif defined(_MSC_VER) && _MSC_VER >= 1400 - if (0 != fopen_s(&f, filename, mode)) - f=0; -#else - f = fopen(filename, mode); -#endif - return f; -} - -static int stbi__start_write_file(stbi__write_context *s, const char *filename) -{ - FILE *f = stbiw__fopen(filename, "wb"); - stbi__start_write_callbacks(s, stbi__stdio_write, (void *) f); - return f != NULL; -} - -static void stbi__end_write_file(stbi__write_context *s) -{ - fclose((FILE *)s->context); -} - -#endif // !STBI_WRITE_NO_STDIO - -typedef unsigned int stbiw_uint32; -typedef int stb_image_write_test[sizeof(stbiw_uint32)==4 ? 1 : -1]; - -static void stbiw__writefv(stbi__write_context *s, const char *fmt, va_list v) -{ - while (*fmt) { - switch (*fmt++) { - case ' ': break; - case '1': { unsigned char x = STBIW_UCHAR(va_arg(v, int)); - s->func(s->context,&x,1); - break; } - case '2': { int x = va_arg(v,int); - unsigned char b[2]; - b[0] = STBIW_UCHAR(x); - b[1] = STBIW_UCHAR(x>>8); - s->func(s->context,b,2); - break; } - case '4': { stbiw_uint32 x = va_arg(v,int); - unsigned char b[4]; - b[0]=STBIW_UCHAR(x); - b[1]=STBIW_UCHAR(x>>8); - b[2]=STBIW_UCHAR(x>>16); - b[3]=STBIW_UCHAR(x>>24); - s->func(s->context,b,4); - break; } - default: - STBIW_ASSERT(0); - return; - } - } -} - -static void stbiw__writef(stbi__write_context *s, const char *fmt, ...) -{ - va_list v; - va_start(v, fmt); - stbiw__writefv(s, fmt, v); - va_end(v); -} - -static void stbiw__write_flush(stbi__write_context *s) -{ - if (s->buf_used) { - s->func(s->context, &s->buffer, s->buf_used); - s->buf_used = 0; - } -} - -static void stbiw__putc(stbi__write_context *s, unsigned char c) -{ - s->func(s->context, &c, 1); -} - -static void stbiw__write1(stbi__write_context *s, unsigned char a) -{ - if ((size_t)s->buf_used + 1 > sizeof(s->buffer)) - stbiw__write_flush(s); - s->buffer[s->buf_used++] = a; -} - -static void stbiw__write3(stbi__write_context *s, unsigned char a, unsigned char b, unsigned char c) -{ - int n; - if ((size_t)s->buf_used + 3 > sizeof(s->buffer)) - stbiw__write_flush(s); - n = s->buf_used; - s->buf_used = n+3; - s->buffer[n+0] = a; - s->buffer[n+1] = b; - s->buffer[n+2] = c; -} - -static void stbiw__write_pixel(stbi__write_context *s, int rgb_dir, int comp, int write_alpha, int expand_mono, unsigned char *d) -{ - unsigned char bg[3] = { 255, 0, 255}, px[3]; - int k; - - if (write_alpha < 0) - stbiw__write1(s, d[comp - 1]); - - switch (comp) { - case 2: // 2 pixels = mono + alpha, alpha is written separately, so same as 1-channel case - case 1: - if (expand_mono) - stbiw__write3(s, d[0], d[0], d[0]); // monochrome bmp - else - stbiw__write1(s, d[0]); // monochrome TGA - break; - case 4: - if (!write_alpha) { - // composite against pink background - for (k = 0; k < 3; ++k) - px[k] = bg[k] + ((d[k] - bg[k]) * d[3]) / 255; - stbiw__write3(s, px[1 - rgb_dir], px[1], px[1 + rgb_dir]); - break; - } - /* FALLTHROUGH */ - case 3: - stbiw__write3(s, d[1 - rgb_dir], d[1], d[1 + rgb_dir]); - break; - } - if (write_alpha > 0) - stbiw__write1(s, d[comp - 1]); -} - -static void stbiw__write_pixels(stbi__write_context *s, int rgb_dir, int vdir, int x, int y, int comp, void *data, int write_alpha, int scanline_pad, int expand_mono) -{ - stbiw_uint32 zero = 0; - int i,j, j_end; - - if (y <= 0) - return; - - if (stbi__flip_vertically_on_write) - vdir *= -1; - - if (vdir < 0) { - j_end = -1; j = y-1; - } else { - j_end = y; j = 0; - } - - for (; j != j_end; j += vdir) { - for (i=0; i < x; ++i) { - unsigned char *d = (unsigned char *) data + (j*x+i)*comp; - stbiw__write_pixel(s, rgb_dir, comp, write_alpha, expand_mono, d); - } - stbiw__write_flush(s); - s->func(s->context, &zero, scanline_pad); - } -} - -static int stbiw__outfile(stbi__write_context *s, int rgb_dir, int vdir, int x, int y, int comp, int expand_mono, void *data, int alpha, int pad, const char *fmt, ...) -{ - if (y < 0 || x < 0) { - return 0; - } else { - va_list v; - va_start(v, fmt); - stbiw__writefv(s, fmt, v); - va_end(v); - stbiw__write_pixels(s,rgb_dir,vdir,x,y,comp,data,alpha,pad, expand_mono); - return 1; - } -} - -static int stbi_write_bmp_core(stbi__write_context *s, int x, int y, int comp, const void *data) -{ - if (comp != 4) { - // write RGB bitmap - int pad = (-x*3) & 3; - return stbiw__outfile(s,-1,-1,x,y,comp,1,(void *) data,0,pad, - "11 4 22 4" "4 44 22 444444", - 'B', 'M', 14+40+(x*3+pad)*y, 0,0, 14+40, // file header - 40, x,y, 1,24, 0,0,0,0,0,0); // bitmap header - } else { - // RGBA bitmaps need a v4 header - // use BI_BITFIELDS mode with 32bpp and alpha mask - // (straight BI_RGB with alpha mask doesn't work in most readers) - return stbiw__outfile(s,-1,-1,x,y,comp,1,(void *)data,1,0, - "11 4 22 4" "4 44 22 444444 4444 4 444 444 444 444", - 'B', 'M', 14+108+x*y*4, 0, 0, 14+108, // file header - 108, x,y, 1,32, 3,0,0,0,0,0, 0xff0000,0xff00,0xff,0xff000000u, 0, 0,0,0, 0,0,0, 0,0,0, 0,0,0); // bitmap V4 header - } -} - -STBIWDEF int stbi_write_bmp_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data) -{ - stbi__write_context s = { 0 }; - stbi__start_write_callbacks(&s, func, context); - return stbi_write_bmp_core(&s, x, y, comp, data); -} - -#ifndef STBI_WRITE_NO_STDIO -STBIWDEF int stbi_write_bmp(char const *filename, int x, int y, int comp, const void *data) -{ - stbi__write_context s = { 0 }; - if (stbi__start_write_file(&s,filename)) { - int r = stbi_write_bmp_core(&s, x, y, comp, data); - stbi__end_write_file(&s); - return r; - } else - return 0; -} -#endif //!STBI_WRITE_NO_STDIO - -static int stbi_write_tga_core(stbi__write_context *s, int x, int y, int comp, void *data) -{ - int has_alpha = (comp == 2 || comp == 4); - int colorbytes = has_alpha ? comp-1 : comp; - int format = colorbytes < 2 ? 3 : 2; // 3 color channels (RGB/RGBA) = 2, 1 color channel (Y/YA) = 3 - - if (y < 0 || x < 0) - return 0; - - if (!stbi_write_tga_with_rle) { - return stbiw__outfile(s, -1, -1, x, y, comp, 0, (void *) data, has_alpha, 0, - "111 221 2222 11", 0, 0, format, 0, 0, 0, 0, 0, x, y, (colorbytes + has_alpha) * 8, has_alpha * 8); - } else { - int i,j,k; - int jend, jdir; - - stbiw__writef(s, "111 221 2222 11", 0,0,format+8, 0,0,0, 0,0,x,y, (colorbytes + has_alpha) * 8, has_alpha * 8); - - if (stbi__flip_vertically_on_write) { - j = 0; - jend = y; - jdir = 1; - } else { - j = y-1; - jend = -1; - jdir = -1; - } - for (; j != jend; j += jdir) { - unsigned char *row = (unsigned char *) data + j * x * comp; - int len; - - for (i = 0; i < x; i += len) { - unsigned char *begin = row + i * comp; - int diff = 1; - len = 1; - - if (i < x - 1) { - ++len; - diff = memcmp(begin, row + (i + 1) * comp, comp); - if (diff) { - const unsigned char *prev = begin; - for (k = i + 2; k < x && len < 128; ++k) { - if (memcmp(prev, row + k * comp, comp)) { - prev += comp; - ++len; - } else { - --len; - break; - } - } - } else { - for (k = i + 2; k < x && len < 128; ++k) { - if (!memcmp(begin, row + k * comp, comp)) { - ++len; - } else { - break; - } - } - } - } - - if (diff) { - unsigned char header = STBIW_UCHAR(len - 1); - stbiw__write1(s, header); - for (k = 0; k < len; ++k) { - stbiw__write_pixel(s, -1, comp, has_alpha, 0, begin + k * comp); - } - } else { - unsigned char header = STBIW_UCHAR(len - 129); - stbiw__write1(s, header); - stbiw__write_pixel(s, -1, comp, has_alpha, 0, begin); - } - } - } - stbiw__write_flush(s); - } - return 1; -} - -STBIWDEF int stbi_write_tga_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data) -{ - stbi__write_context s = { 0 }; - stbi__start_write_callbacks(&s, func, context); - return stbi_write_tga_core(&s, x, y, comp, (void *) data); -} - -#ifndef STBI_WRITE_NO_STDIO -STBIWDEF int stbi_write_tga(char const *filename, int x, int y, int comp, const void *data) -{ - stbi__write_context s = { 0 }; - if (stbi__start_write_file(&s,filename)) { - int r = stbi_write_tga_core(&s, x, y, comp, (void *) data); - stbi__end_write_file(&s); - return r; - } else - return 0; -} -#endif - -// ************************************************************************************************* -// Radiance RGBE HDR writer -// by Baldur Karlsson - -#define stbiw__max(a, b) ((a) > (b) ? (a) : (b)) - -#ifndef STBI_WRITE_NO_STDIO - -static void stbiw__linear_to_rgbe(unsigned char *rgbe, float *linear) -{ - int exponent; - float maxcomp = stbiw__max(linear[0], stbiw__max(linear[1], linear[2])); - - if (maxcomp < 1e-32f) { - rgbe[0] = rgbe[1] = rgbe[2] = rgbe[3] = 0; - } else { - float normalize = (float) frexp(maxcomp, &exponent) * 256.0f/maxcomp; - - rgbe[0] = (unsigned char)(linear[0] * normalize); - rgbe[1] = (unsigned char)(linear[1] * normalize); - rgbe[2] = (unsigned char)(linear[2] * normalize); - rgbe[3] = (unsigned char)(exponent + 128); - } -} - -static void stbiw__write_run_data(stbi__write_context *s, int length, unsigned char databyte) -{ - unsigned char lengthbyte = STBIW_UCHAR(length+128); - STBIW_ASSERT(length+128 <= 255); - s->func(s->context, &lengthbyte, 1); - s->func(s->context, &databyte, 1); -} - -static void stbiw__write_dump_data(stbi__write_context *s, int length, unsigned char *data) -{ - unsigned char lengthbyte = STBIW_UCHAR(length); - STBIW_ASSERT(length <= 128); // inconsistent with spec but consistent with official code - s->func(s->context, &lengthbyte, 1); - s->func(s->context, data, length); -} - -static void stbiw__write_hdr_scanline(stbi__write_context *s, int width, int ncomp, unsigned char *scratch, float *scanline) -{ - unsigned char scanlineheader[4] = { 2, 2, 0, 0 }; - unsigned char rgbe[4]; - float linear[3]; - int x; - - scanlineheader[2] = (width&0xff00)>>8; - scanlineheader[3] = (width&0x00ff); - - /* skip RLE for images too small or large */ - if (width < 8 || width >= 32768) { - for (x=0; x < width; x++) { - switch (ncomp) { - case 4: /* fallthrough */ - case 3: linear[2] = scanline[x*ncomp + 2]; - linear[1] = scanline[x*ncomp + 1]; - linear[0] = scanline[x*ncomp + 0]; - break; - default: - linear[0] = linear[1] = linear[2] = scanline[x*ncomp + 0]; - break; - } - stbiw__linear_to_rgbe(rgbe, linear); - s->func(s->context, rgbe, 4); - } - } else { - int c,r; - /* encode into scratch buffer */ - for (x=0; x < width; x++) { - switch(ncomp) { - case 4: /* fallthrough */ - case 3: linear[2] = scanline[x*ncomp + 2]; - linear[1] = scanline[x*ncomp + 1]; - linear[0] = scanline[x*ncomp + 0]; - break; - default: - linear[0] = linear[1] = linear[2] = scanline[x*ncomp + 0]; - break; - } - stbiw__linear_to_rgbe(rgbe, linear); - scratch[x + width*0] = rgbe[0]; - scratch[x + width*1] = rgbe[1]; - scratch[x + width*2] = rgbe[2]; - scratch[x + width*3] = rgbe[3]; - } - - s->func(s->context, scanlineheader, 4); - - /* RLE each component separately */ - for (c=0; c < 4; c++) { - unsigned char *comp = &scratch[width*c]; - - x = 0; - while (x < width) { - // find first run - r = x; - while (r+2 < width) { - if (comp[r] == comp[r+1] && comp[r] == comp[r+2]) - break; - ++r; - } - if (r+2 >= width) - r = width; - // dump up to first run - while (x < r) { - int len = r-x; - if (len > 128) len = 128; - stbiw__write_dump_data(s, len, &comp[x]); - x += len; - } - // if there's a run, output it - if (r+2 < width) { // same test as what we break out of in search loop, so only true if we break'd - // find next byte after run - while (r < width && comp[r] == comp[x]) - ++r; - // output run up to r - while (x < r) { - int len = r-x; - if (len > 127) len = 127; - stbiw__write_run_data(s, len, comp[x]); - x += len; - } - } - } - } - } -} - -static int stbi_write_hdr_core(stbi__write_context *s, int x, int y, int comp, float *data) -{ - if (y <= 0 || x <= 0 || data == NULL) - return 0; - else { - // Each component is stored separately. Allocate scratch space for full output scanline. - unsigned char *scratch = (unsigned char *) STBIW_MALLOC(x*4); - int i, len; - char buffer[128]; - char header[] = "#?RADIANCE\n# Written by stb_image_write.h\nFORMAT=32-bit_rle_rgbe\n"; - s->func(s->context, header, sizeof(header)-1); - -#ifdef __STDC_LIB_EXT1__ - len = sprintf_s(buffer, sizeof(buffer), "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x); -#else - len = snprintf(buffer, sizeof(buffer), "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x); -#endif - s->func(s->context, buffer, len); - - for(i=0; i < y; i++) - stbiw__write_hdr_scanline(s, x, comp, scratch, data + comp*x*(stbi__flip_vertically_on_write ? y-1-i : i)); - STBIW_FREE(scratch); - return 1; - } -} - -STBIWDEF int stbi_write_hdr_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const float *data) -{ - stbi__write_context s = { 0 }; - stbi__start_write_callbacks(&s, func, context); - return stbi_write_hdr_core(&s, x, y, comp, (float *) data); -} - -STBIWDEF int stbi_write_hdr(char const *filename, int x, int y, int comp, const float *data) -{ - stbi__write_context s = { 0 }; - if (stbi__start_write_file(&s,filename)) { - int r = stbi_write_hdr_core(&s, x, y, comp, (float *) data); - stbi__end_write_file(&s); - return r; - } else - return 0; -} -#endif // STBI_WRITE_NO_STDIO - - -////////////////////////////////////////////////////////////////////////////// -// -// PNG writer -// - -#ifndef STBIW_ZLIB_COMPRESS -// stretchy buffer; stbiw__sbpush() == vector<>::push_back() -- stbiw__sbcount() == vector<>::size() -#define stbiw__sbraw(a) ((int *) (void *) (a) - 2) -#define stbiw__sbm(a) stbiw__sbraw(a)[0] -#define stbiw__sbn(a) stbiw__sbraw(a)[1] - -#define stbiw__sbneedgrow(a,n) ((a)==0 || stbiw__sbn(a)+n >= stbiw__sbm(a)) -#define stbiw__sbmaybegrow(a,n) (stbiw__sbneedgrow(a,(n)) ? stbiw__sbgrow(a,n) : 0) -#define stbiw__sbgrow(a,n) stbiw__sbgrowf((void **) &(a), (n), sizeof(*(a))) - -#define stbiw__sbpush(a, v) (stbiw__sbmaybegrow(a,1), (a)[stbiw__sbn(a)++] = (v)) -#define stbiw__sbcount(a) ((a) ? stbiw__sbn(a) : 0) -#define stbiw__sbfree(a) ((a) ? STBIW_FREE(stbiw__sbraw(a)),0 : 0) - -static void *stbiw__sbgrowf(void **arr, int increment, int itemsize) -{ - int m = *arr ? 2*stbiw__sbm(*arr)+increment : increment+1; - void *p = STBIW_REALLOC_SIZED(*arr ? stbiw__sbraw(*arr) : 0, *arr ? (stbiw__sbm(*arr)*itemsize + sizeof(int)*2) : 0, itemsize * m + sizeof(int)*2); - STBIW_ASSERT(p); - if (p) { - if (!*arr) ((int *) p)[1] = 0; - *arr = (void *) ((int *) p + 2); - stbiw__sbm(*arr) = m; - } - return *arr; -} - -static unsigned char *stbiw__zlib_flushf(unsigned char *data, unsigned int *bitbuffer, int *bitcount) -{ - while (*bitcount >= 8) { - stbiw__sbpush(data, STBIW_UCHAR(*bitbuffer)); - *bitbuffer >>= 8; - *bitcount -= 8; - } - return data; -} - -static int stbiw__zlib_bitrev(int code, int codebits) -{ - int res=0; - while (codebits--) { - res = (res << 1) | (code & 1); - code >>= 1; - } - return res; -} - -static unsigned int stbiw__zlib_countm(unsigned char *a, unsigned char *b, int limit) -{ - int i; - for (i=0; i < limit && i < 258; ++i) - if (a[i] != b[i]) break; - return i; -} - -static unsigned int stbiw__zhash(unsigned char *data) -{ - stbiw_uint32 hash = data[0] + (data[1] << 8) + (data[2] << 16); - hash ^= hash << 3; - hash += hash >> 5; - hash ^= hash << 4; - hash += hash >> 17; - hash ^= hash << 25; - hash += hash >> 6; - return hash; -} - -#define stbiw__zlib_flush() (out = stbiw__zlib_flushf(out, &bitbuf, &bitcount)) -#define stbiw__zlib_add(code,codebits) \ - (bitbuf |= (code) << bitcount, bitcount += (codebits), stbiw__zlib_flush()) -#define stbiw__zlib_huffa(b,c) stbiw__zlib_add(stbiw__zlib_bitrev(b,c),c) -// default huffman tables -#define stbiw__zlib_huff1(n) stbiw__zlib_huffa(0x30 + (n), 8) -#define stbiw__zlib_huff2(n) stbiw__zlib_huffa(0x190 + (n)-144, 9) -#define stbiw__zlib_huff3(n) stbiw__zlib_huffa(0 + (n)-256,7) -#define stbiw__zlib_huff4(n) stbiw__zlib_huffa(0xc0 + (n)-280,8) -#define stbiw__zlib_huff(n) ((n) <= 143 ? stbiw__zlib_huff1(n) : (n) <= 255 ? stbiw__zlib_huff2(n) : (n) <= 279 ? stbiw__zlib_huff3(n) : stbiw__zlib_huff4(n)) -#define stbiw__zlib_huffb(n) ((n) <= 143 ? stbiw__zlib_huff1(n) : stbiw__zlib_huff2(n)) - -#define stbiw__ZHASH 16384 - -#endif // STBIW_ZLIB_COMPRESS - -STBIWDEF unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, int *out_len, int quality) -{ -#ifdef STBIW_ZLIB_COMPRESS - // user provided a zlib compress implementation, use that - return STBIW_ZLIB_COMPRESS(data, data_len, out_len, quality); -#else // use builtin - static unsigned short lengthc[] = { 3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258, 259 }; - static unsigned char lengtheb[]= { 0,0,0,0,0,0,0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0 }; - static unsigned short distc[] = { 1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577, 32768 }; - static unsigned char disteb[] = { 0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13 }; - unsigned int bitbuf=0; - int i,j, bitcount=0; - unsigned char *out = NULL; - unsigned char ***hash_table = (unsigned char***) STBIW_MALLOC(stbiw__ZHASH * sizeof(unsigned char**)); - if (hash_table == NULL) - return NULL; - if (quality < 5) quality = 5; - - stbiw__sbpush(out, 0x78); // DEFLATE 32K window - stbiw__sbpush(out, 0x5e); // FLEVEL = 1 - stbiw__zlib_add(1,1); // BFINAL = 1 - stbiw__zlib_add(1,2); // BTYPE = 1 -- fixed huffman - - for (i=0; i < stbiw__ZHASH; ++i) - hash_table[i] = NULL; - - i=0; - while (i < data_len-3) { - // hash next 3 bytes of data to be compressed - int h = stbiw__zhash(data+i)&(stbiw__ZHASH-1), best=3; - unsigned char *bestloc = 0; - unsigned char **hlist = hash_table[h]; - int n = stbiw__sbcount(hlist); - for (j=0; j < n; ++j) { - if (hlist[j]-data > i-32768) { // if entry lies within window - int d = stbiw__zlib_countm(hlist[j], data+i, data_len-i); - if (d >= best) { best=d; bestloc=hlist[j]; } - } - } - // when hash table entry is too long, delete half the entries - if (hash_table[h] && stbiw__sbn(hash_table[h]) == 2*quality) { - STBIW_MEMMOVE(hash_table[h], hash_table[h]+quality, sizeof(hash_table[h][0])*quality); - stbiw__sbn(hash_table[h]) = quality; - } - stbiw__sbpush(hash_table[h],data+i); - - if (bestloc) { - // "lazy matching" - check match at *next* byte, and if it's better, do cur byte as literal - h = stbiw__zhash(data+i+1)&(stbiw__ZHASH-1); - hlist = hash_table[h]; - n = stbiw__sbcount(hlist); - for (j=0; j < n; ++j) { - if (hlist[j]-data > i-32767) { - int e = stbiw__zlib_countm(hlist[j], data+i+1, data_len-i-1); - if (e > best) { // if next match is better, bail on current match - bestloc = NULL; - break; - } - } - } - } - - if (bestloc) { - int d = (int) (data+i - bestloc); // distance back - STBIW_ASSERT(d <= 32767 && best <= 258); - for (j=0; best > lengthc[j+1]-1; ++j); - stbiw__zlib_huff(j+257); - if (lengtheb[j]) stbiw__zlib_add(best - lengthc[j], lengtheb[j]); - for (j=0; d > distc[j+1]-1; ++j); - stbiw__zlib_add(stbiw__zlib_bitrev(j,5),5); - if (disteb[j]) stbiw__zlib_add(d - distc[j], disteb[j]); - i += best; - } else { - stbiw__zlib_huffb(data[i]); - ++i; - } - } - // write out final bytes - for (;i < data_len; ++i) - stbiw__zlib_huffb(data[i]); - stbiw__zlib_huff(256); // end of block - // pad with 0 bits to byte boundary - while (bitcount) - stbiw__zlib_add(0,1); - - for (i=0; i < stbiw__ZHASH; ++i) - (void) stbiw__sbfree(hash_table[i]); - STBIW_FREE(hash_table); - - // store uncompressed instead if compression was worse - if (stbiw__sbn(out) > data_len + 2 + ((data_len+32766)/32767)*5) { - stbiw__sbn(out) = 2; // truncate to DEFLATE 32K window and FLEVEL = 1 - for (j = 0; j < data_len;) { - int blocklen = data_len - j; - if (blocklen > 32767) blocklen = 32767; - stbiw__sbpush(out, data_len - j == blocklen); // BFINAL = ?, BTYPE = 0 -- no compression - stbiw__sbpush(out, STBIW_UCHAR(blocklen)); // LEN - stbiw__sbpush(out, STBIW_UCHAR(blocklen >> 8)); - stbiw__sbpush(out, STBIW_UCHAR(~blocklen)); // NLEN - stbiw__sbpush(out, STBIW_UCHAR(~blocklen >> 8)); - memcpy(out+stbiw__sbn(out), data+j, blocklen); - stbiw__sbn(out) += blocklen; - j += blocklen; - } - } - - { - // compute adler32 on input - unsigned int s1=1, s2=0; - int blocklen = (int) (data_len % 5552); - j=0; - while (j < data_len) { - for (i=0; i < blocklen; ++i) { s1 += data[j+i]; s2 += s1; } - s1 %= 65521; s2 %= 65521; - j += blocklen; - blocklen = 5552; - } - stbiw__sbpush(out, STBIW_UCHAR(s2 >> 8)); - stbiw__sbpush(out, STBIW_UCHAR(s2)); - stbiw__sbpush(out, STBIW_UCHAR(s1 >> 8)); - stbiw__sbpush(out, STBIW_UCHAR(s1)); - } - *out_len = stbiw__sbn(out); - // make returned pointer freeable - STBIW_MEMMOVE(stbiw__sbraw(out), out, *out_len); - return (unsigned char *) stbiw__sbraw(out); -#endif // STBIW_ZLIB_COMPRESS -} - -static unsigned int stbiw__crc32(unsigned char *buffer, int len) -{ -#ifdef STBIW_CRC32 - return STBIW_CRC32(buffer, len); -#else - static unsigned int crc_table[256] = - { - 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, - 0x0eDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, - 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, - 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, - 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, - 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, - 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, - 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, - 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, - 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, - 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, - 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, - 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, - 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, - 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, - 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, - 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, - 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, - 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, - 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, - 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, - 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, - 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, - 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, - 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, - 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, - 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, - 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, - 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, - 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, - 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, - 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D - }; - - unsigned int crc = ~0u; - int i; - for (i=0; i < len; ++i) - crc = (crc >> 8) ^ crc_table[buffer[i] ^ (crc & 0xff)]; - return ~crc; -#endif -} - -#define stbiw__wpng4(o,a,b,c,d) ((o)[0]=STBIW_UCHAR(a),(o)[1]=STBIW_UCHAR(b),(o)[2]=STBIW_UCHAR(c),(o)[3]=STBIW_UCHAR(d),(o)+=4) -#define stbiw__wp32(data,v) stbiw__wpng4(data, (v)>>24,(v)>>16,(v)>>8,(v)); -#define stbiw__wptag(data,s) stbiw__wpng4(data, s[0],s[1],s[2],s[3]) - -static void stbiw__wpcrc(unsigned char **data, int len) -{ - unsigned int crc = stbiw__crc32(*data - len - 4, len+4); - stbiw__wp32(*data, crc); -} - -static unsigned char stbiw__paeth(int a, int b, int c) -{ - int p = a + b - c, pa = abs(p-a), pb = abs(p-b), pc = abs(p-c); - if (pa <= pb && pa <= pc) return STBIW_UCHAR(a); - if (pb <= pc) return STBIW_UCHAR(b); - return STBIW_UCHAR(c); -} - -// @OPTIMIZE: provide an option that always forces left-predict or paeth predict -static void stbiw__encode_png_line(unsigned char *pixels, int stride_bytes, int width, int height, int y, int n, int filter_type, signed char *line_buffer) -{ - static int mapping[] = { 0,1,2,3,4 }; - static int firstmap[] = { 0,1,0,5,6 }; - int *mymap = (y != 0) ? mapping : firstmap; - int i; - int type = mymap[filter_type]; - unsigned char *z = pixels + stride_bytes * (stbi__flip_vertically_on_write ? height-1-y : y); - int signed_stride = stbi__flip_vertically_on_write ? -stride_bytes : stride_bytes; - - if (type==0) { - memcpy(line_buffer, z, width*n); - return; - } - - // first loop isn't optimized since it's just one pixel - for (i = 0; i < n; ++i) { - switch (type) { - case 1: line_buffer[i] = z[i]; break; - case 2: line_buffer[i] = z[i] - z[i-signed_stride]; break; - case 3: line_buffer[i] = z[i] - (z[i-signed_stride]>>1); break; - case 4: line_buffer[i] = (signed char) (z[i] - stbiw__paeth(0,z[i-signed_stride],0)); break; - case 5: line_buffer[i] = z[i]; break; - case 6: line_buffer[i] = z[i]; break; - } - } - switch (type) { - case 1: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - z[i-n]; break; - case 2: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - z[i-signed_stride]; break; - case 3: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - ((z[i-n] + z[i-signed_stride])>>1); break; - case 4: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - stbiw__paeth(z[i-n], z[i-signed_stride], z[i-signed_stride-n]); break; - case 5: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - (z[i-n]>>1); break; - case 6: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - stbiw__paeth(z[i-n], 0,0); break; - } -} - -STBIWDEF unsigned char *stbi_write_png_to_mem(const unsigned char *pixels, int stride_bytes, int x, int y, int n, int *out_len) -{ - int force_filter = stbi_write_force_png_filter; - int ctype[5] = { -1, 0, 4, 2, 6 }; - unsigned char sig[8] = { 137,80,78,71,13,10,26,10 }; - unsigned char *out,*o, *filt, *zlib; - signed char *line_buffer; - int j,zlen; - - if (stride_bytes == 0) - stride_bytes = x * n; - - if (force_filter >= 5) { - force_filter = -1; - } - - filt = (unsigned char *) STBIW_MALLOC((x*n+1) * y); if (!filt) return 0; - line_buffer = (signed char *) STBIW_MALLOC(x * n); if (!line_buffer) { STBIW_FREE(filt); return 0; } - for (j=0; j < y; ++j) { - int filter_type; - if (force_filter > -1) { - filter_type = force_filter; - stbiw__encode_png_line((unsigned char*)(pixels), stride_bytes, x, y, j, n, force_filter, line_buffer); - } else { // Estimate the best filter by running through all of them: - int best_filter = 0, best_filter_val = 0x7fffffff, est, i; - for (filter_type = 0; filter_type < 5; filter_type++) { - stbiw__encode_png_line((unsigned char*)(pixels), stride_bytes, x, y, j, n, filter_type, line_buffer); - - // Estimate the entropy of the line using this filter; the less, the better. - est = 0; - for (i = 0; i < x*n; ++i) { - est += abs((signed char) line_buffer[i]); - } - if (est < best_filter_val) { - best_filter_val = est; - best_filter = filter_type; - } - } - if (filter_type != best_filter) { // If the last iteration already got us the best filter, don't redo it - stbiw__encode_png_line((unsigned char*)(pixels), stride_bytes, x, y, j, n, best_filter, line_buffer); - filter_type = best_filter; - } - } - // when we get here, filter_type contains the filter type, and line_buffer contains the data - filt[j*(x*n+1)] = (unsigned char) filter_type; - STBIW_MEMMOVE(filt+j*(x*n+1)+1, line_buffer, x*n); - } - STBIW_FREE(line_buffer); - zlib = stbi_zlib_compress(filt, y*( x*n+1), &zlen, stbi_write_png_compression_level); - STBIW_FREE(filt); - if (!zlib) return 0; - - // each tag requires 12 bytes of overhead - out = (unsigned char *) STBIW_MALLOC(8 + 12+13 + 12+zlen + 12); - if (!out) return 0; - *out_len = 8 + 12+13 + 12+zlen + 12; - - o=out; - STBIW_MEMMOVE(o,sig,8); o+= 8; - stbiw__wp32(o, 13); // header length - stbiw__wptag(o, "IHDR"); - stbiw__wp32(o, x); - stbiw__wp32(o, y); - *o++ = 8; - *o++ = STBIW_UCHAR(ctype[n]); - *o++ = 0; - *o++ = 0; - *o++ = 0; - stbiw__wpcrc(&o,13); - - stbiw__wp32(o, zlen); - stbiw__wptag(o, "IDAT"); - STBIW_MEMMOVE(o, zlib, zlen); - o += zlen; - STBIW_FREE(zlib); - stbiw__wpcrc(&o, zlen); - - stbiw__wp32(o,0); - stbiw__wptag(o, "IEND"); - stbiw__wpcrc(&o,0); - - STBIW_ASSERT(o == out + *out_len); - - return out; -} - -#ifndef STBI_WRITE_NO_STDIO -STBIWDEF int stbi_write_png(char const *filename, int x, int y, int comp, const void *data, int stride_bytes) -{ - FILE *f; - int len; - unsigned char *png = stbi_write_png_to_mem((const unsigned char *) data, stride_bytes, x, y, comp, &len); - if (png == NULL) return 0; - - f = stbiw__fopen(filename, "wb"); - if (!f) { STBIW_FREE(png); return 0; } - fwrite(png, 1, len, f); - fclose(f); - STBIW_FREE(png); - return 1; -} -#endif - -STBIWDEF int stbi_write_png_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int stride_bytes) -{ - int len; - unsigned char *png = stbi_write_png_to_mem((const unsigned char *) data, stride_bytes, x, y, comp, &len); - if (png == NULL) return 0; - func(context, png, len); - STBIW_FREE(png); - return 1; -} - - -/* *************************************************************************** - * - * JPEG writer - * - * This is based on Jon Olick's jo_jpeg.cpp: - * public domain Simple, Minimalistic JPEG writer - http://www.jonolick.com/code.html - */ - -static const unsigned char stbiw__jpg_ZigZag[] = { 0,1,5,6,14,15,27,28,2,4,7,13,16,26,29,42,3,8,12,17,25,30,41,43,9,11,18, - 24,31,40,44,53,10,19,23,32,39,45,52,54,20,22,33,38,46,51,55,60,21,34,37,47,50,56,59,61,35,36,48,49,57,58,62,63 }; - -static void stbiw__jpg_writeBits(stbi__write_context *s, int *bitBufP, int *bitCntP, const unsigned short *bs) { - int bitBuf = *bitBufP, bitCnt = *bitCntP; - bitCnt += bs[1]; - bitBuf |= bs[0] << (24 - bitCnt); - while(bitCnt >= 8) { - unsigned char c = (bitBuf >> 16) & 255; - stbiw__putc(s, c); - if(c == 255) { - stbiw__putc(s, 0); - } - bitBuf <<= 8; - bitCnt -= 8; - } - *bitBufP = bitBuf; - *bitCntP = bitCnt; -} - -static void stbiw__jpg_DCT(float *d0p, float *d1p, float *d2p, float *d3p, float *d4p, float *d5p, float *d6p, float *d7p) { - float d0 = *d0p, d1 = *d1p, d2 = *d2p, d3 = *d3p, d4 = *d4p, d5 = *d5p, d6 = *d6p, d7 = *d7p; - float z1, z2, z3, z4, z5, z11, z13; - - float tmp0 = d0 + d7; - float tmp7 = d0 - d7; - float tmp1 = d1 + d6; - float tmp6 = d1 - d6; - float tmp2 = d2 + d5; - float tmp5 = d2 - d5; - float tmp3 = d3 + d4; - float tmp4 = d3 - d4; - - // Even part - float tmp10 = tmp0 + tmp3; // phase 2 - float tmp13 = tmp0 - tmp3; - float tmp11 = tmp1 + tmp2; - float tmp12 = tmp1 - tmp2; - - d0 = tmp10 + tmp11; // phase 3 - d4 = tmp10 - tmp11; - - z1 = (tmp12 + tmp13) * 0.707106781f; // c4 - d2 = tmp13 + z1; // phase 5 - d6 = tmp13 - z1; - - // Odd part - tmp10 = tmp4 + tmp5; // phase 2 - tmp11 = tmp5 + tmp6; - tmp12 = tmp6 + tmp7; - - // The rotator is modified from fig 4-8 to avoid extra negations. - z5 = (tmp10 - tmp12) * 0.382683433f; // c6 - z2 = tmp10 * 0.541196100f + z5; // c2-c6 - z4 = tmp12 * 1.306562965f + z5; // c2+c6 - z3 = tmp11 * 0.707106781f; // c4 - - z11 = tmp7 + z3; // phase 5 - z13 = tmp7 - z3; - - *d5p = z13 + z2; // phase 6 - *d3p = z13 - z2; - *d1p = z11 + z4; - *d7p = z11 - z4; - - *d0p = d0; *d2p = d2; *d4p = d4; *d6p = d6; -} - -static void stbiw__jpg_calcBits(int val, unsigned short bits[2]) { - int tmp1 = val < 0 ? -val : val; - val = val < 0 ? val-1 : val; - bits[1] = 1; - while(tmp1 >>= 1) { - ++bits[1]; - } - bits[0] = val & ((1<0)&&(DU[end0pos]==0); --end0pos) { - } - // end0pos = first element in reverse order !=0 - if(end0pos == 0) { - stbiw__jpg_writeBits(s, bitBuf, bitCnt, EOB); - return DU[0]; - } - for(i = 1; i <= end0pos; ++i) { - int startpos = i; - int nrzeroes; - unsigned short bits[2]; - for (; DU[i]==0 && i<=end0pos; ++i) { - } - nrzeroes = i-startpos; - if ( nrzeroes >= 16 ) { - int lng = nrzeroes>>4; - int nrmarker; - for (nrmarker=1; nrmarker <= lng; ++nrmarker) - stbiw__jpg_writeBits(s, bitBuf, bitCnt, M16zeroes); - nrzeroes &= 15; - } - stbiw__jpg_calcBits(DU[i], bits); - stbiw__jpg_writeBits(s, bitBuf, bitCnt, HTAC[(nrzeroes<<4)+bits[1]]); - stbiw__jpg_writeBits(s, bitBuf, bitCnt, bits); - } - if(end0pos != 63) { - stbiw__jpg_writeBits(s, bitBuf, bitCnt, EOB); - } - return DU[0]; -} - -static int stbi_write_jpg_core(stbi__write_context *s, int width, int height, int comp, const void* data, int quality) { - // Constants that don't pollute global namespace - static const unsigned char std_dc_luminance_nrcodes[] = {0,0,1,5,1,1,1,1,1,1,0,0,0,0,0,0,0}; - static const unsigned char std_dc_luminance_values[] = {0,1,2,3,4,5,6,7,8,9,10,11}; - static const unsigned char std_ac_luminance_nrcodes[] = {0,0,2,1,3,3,2,4,3,5,5,4,4,0,0,1,0x7d}; - static const unsigned char std_ac_luminance_values[] = { - 0x01,0x02,0x03,0x00,0x04,0x11,0x05,0x12,0x21,0x31,0x41,0x06,0x13,0x51,0x61,0x07,0x22,0x71,0x14,0x32,0x81,0x91,0xa1,0x08, - 0x23,0x42,0xb1,0xc1,0x15,0x52,0xd1,0xf0,0x24,0x33,0x62,0x72,0x82,0x09,0x0a,0x16,0x17,0x18,0x19,0x1a,0x25,0x26,0x27,0x28, - 0x29,0x2a,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x53,0x54,0x55,0x56,0x57,0x58,0x59, - 0x5a,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x83,0x84,0x85,0x86,0x87,0x88,0x89, - 0x8a,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xb2,0xb3,0xb4,0xb5,0xb6, - 0xb7,0xb8,0xb9,0xba,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xe1,0xe2, - 0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa - }; - static const unsigned char std_dc_chrominance_nrcodes[] = {0,0,3,1,1,1,1,1,1,1,1,1,0,0,0,0,0}; - static const unsigned char std_dc_chrominance_values[] = {0,1,2,3,4,5,6,7,8,9,10,11}; - static const unsigned char std_ac_chrominance_nrcodes[] = {0,0,2,1,2,4,4,3,4,7,5,4,4,0,1,2,0x77}; - static const unsigned char std_ac_chrominance_values[] = { - 0x00,0x01,0x02,0x03,0x11,0x04,0x05,0x21,0x31,0x06,0x12,0x41,0x51,0x07,0x61,0x71,0x13,0x22,0x32,0x81,0x08,0x14,0x42,0x91, - 0xa1,0xb1,0xc1,0x09,0x23,0x33,0x52,0xf0,0x15,0x62,0x72,0xd1,0x0a,0x16,0x24,0x34,0xe1,0x25,0xf1,0x17,0x18,0x19,0x1a,0x26, - 0x27,0x28,0x29,0x2a,0x35,0x36,0x37,0x38,0x39,0x3a,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x53,0x54,0x55,0x56,0x57,0x58, - 0x59,0x5a,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x82,0x83,0x84,0x85,0x86,0x87, - 0x88,0x89,0x8a,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xb2,0xb3,0xb4, - 0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda, - 0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa - }; - // Huffman tables - static const unsigned short YDC_HT[256][2] = { {0,2},{2,3},{3,3},{4,3},{5,3},{6,3},{14,4},{30,5},{62,6},{126,7},{254,8},{510,9}}; - static const unsigned short UVDC_HT[256][2] = { {0,2},{1,2},{2,2},{6,3},{14,4},{30,5},{62,6},{126,7},{254,8},{510,9},{1022,10},{2046,11}}; - static const unsigned short YAC_HT[256][2] = { - {10,4},{0,2},{1,2},{4,3},{11,4},{26,5},{120,7},{248,8},{1014,10},{65410,16},{65411,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, - {12,4},{27,5},{121,7},{502,9},{2038,11},{65412,16},{65413,16},{65414,16},{65415,16},{65416,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, - {28,5},{249,8},{1015,10},{4084,12},{65417,16},{65418,16},{65419,16},{65420,16},{65421,16},{65422,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, - {58,6},{503,9},{4085,12},{65423,16},{65424,16},{65425,16},{65426,16},{65427,16},{65428,16},{65429,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, - {59,6},{1016,10},{65430,16},{65431,16},{65432,16},{65433,16},{65434,16},{65435,16},{65436,16},{65437,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, - {122,7},{2039,11},{65438,16},{65439,16},{65440,16},{65441,16},{65442,16},{65443,16},{65444,16},{65445,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, - {123,7},{4086,12},{65446,16},{65447,16},{65448,16},{65449,16},{65450,16},{65451,16},{65452,16},{65453,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, - {250,8},{4087,12},{65454,16},{65455,16},{65456,16},{65457,16},{65458,16},{65459,16},{65460,16},{65461,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, - {504,9},{32704,15},{65462,16},{65463,16},{65464,16},{65465,16},{65466,16},{65467,16},{65468,16},{65469,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, - {505,9},{65470,16},{65471,16},{65472,16},{65473,16},{65474,16},{65475,16},{65476,16},{65477,16},{65478,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, - {506,9},{65479,16},{65480,16},{65481,16},{65482,16},{65483,16},{65484,16},{65485,16},{65486,16},{65487,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, - {1017,10},{65488,16},{65489,16},{65490,16},{65491,16},{65492,16},{65493,16},{65494,16},{65495,16},{65496,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, - {1018,10},{65497,16},{65498,16},{65499,16},{65500,16},{65501,16},{65502,16},{65503,16},{65504,16},{65505,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, - {2040,11},{65506,16},{65507,16},{65508,16},{65509,16},{65510,16},{65511,16},{65512,16},{65513,16},{65514,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, - {65515,16},{65516,16},{65517,16},{65518,16},{65519,16},{65520,16},{65521,16},{65522,16},{65523,16},{65524,16},{0,0},{0,0},{0,0},{0,0},{0,0}, - {2041,11},{65525,16},{65526,16},{65527,16},{65528,16},{65529,16},{65530,16},{65531,16},{65532,16},{65533,16},{65534,16},{0,0},{0,0},{0,0},{0,0},{0,0} - }; - static const unsigned short UVAC_HT[256][2] = { - {0,2},{1,2},{4,3},{10,4},{24,5},{25,5},{56,6},{120,7},{500,9},{1014,10},{4084,12},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, - {11,4},{57,6},{246,8},{501,9},{2038,11},{4085,12},{65416,16},{65417,16},{65418,16},{65419,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, - {26,5},{247,8},{1015,10},{4086,12},{32706,15},{65420,16},{65421,16},{65422,16},{65423,16},{65424,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, - {27,5},{248,8},{1016,10},{4087,12},{65425,16},{65426,16},{65427,16},{65428,16},{65429,16},{65430,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, - {58,6},{502,9},{65431,16},{65432,16},{65433,16},{65434,16},{65435,16},{65436,16},{65437,16},{65438,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, - {59,6},{1017,10},{65439,16},{65440,16},{65441,16},{65442,16},{65443,16},{65444,16},{65445,16},{65446,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, - {121,7},{2039,11},{65447,16},{65448,16},{65449,16},{65450,16},{65451,16},{65452,16},{65453,16},{65454,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, - {122,7},{2040,11},{65455,16},{65456,16},{65457,16},{65458,16},{65459,16},{65460,16},{65461,16},{65462,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, - {249,8},{65463,16},{65464,16},{65465,16},{65466,16},{65467,16},{65468,16},{65469,16},{65470,16},{65471,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, - {503,9},{65472,16},{65473,16},{65474,16},{65475,16},{65476,16},{65477,16},{65478,16},{65479,16},{65480,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, - {504,9},{65481,16},{65482,16},{65483,16},{65484,16},{65485,16},{65486,16},{65487,16},{65488,16},{65489,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, - {505,9},{65490,16},{65491,16},{65492,16},{65493,16},{65494,16},{65495,16},{65496,16},{65497,16},{65498,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, - {506,9},{65499,16},{65500,16},{65501,16},{65502,16},{65503,16},{65504,16},{65505,16},{65506,16},{65507,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, - {2041,11},{65508,16},{65509,16},{65510,16},{65511,16},{65512,16},{65513,16},{65514,16},{65515,16},{65516,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, - {16352,14},{65517,16},{65518,16},{65519,16},{65520,16},{65521,16},{65522,16},{65523,16},{65524,16},{65525,16},{0,0},{0,0},{0,0},{0,0},{0,0}, - {1018,10},{32707,15},{65526,16},{65527,16},{65528,16},{65529,16},{65530,16},{65531,16},{65532,16},{65533,16},{65534,16},{0,0},{0,0},{0,0},{0,0},{0,0} - }; - static const int YQT[] = {16,11,10,16,24,40,51,61,12,12,14,19,26,58,60,55,14,13,16,24,40,57,69,56,14,17,22,29,51,87,80,62,18,22, - 37,56,68,109,103,77,24,35,55,64,81,104,113,92,49,64,78,87,103,121,120,101,72,92,95,98,112,100,103,99}; - static const int UVQT[] = {17,18,24,47,99,99,99,99,18,21,26,66,99,99,99,99,24,26,56,99,99,99,99,99,47,66,99,99,99,99,99,99, - 99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99}; - static const float aasf[] = { 1.0f * 2.828427125f, 1.387039845f * 2.828427125f, 1.306562965f * 2.828427125f, 1.175875602f * 2.828427125f, - 1.0f * 2.828427125f, 0.785694958f * 2.828427125f, 0.541196100f * 2.828427125f, 0.275899379f * 2.828427125f }; - - int row, col, i, k, subsample; - float fdtbl_Y[64], fdtbl_UV[64]; - unsigned char YTable[64], UVTable[64]; - - if(!data || !width || !height || comp > 4 || comp < 1) { - return 0; - } - - quality = quality ? quality : 90; - subsample = quality <= 90 ? 1 : 0; - quality = quality < 1 ? 1 : quality > 100 ? 100 : quality; - quality = quality < 50 ? 5000 / quality : 200 - quality * 2; - - for(i = 0; i < 64; ++i) { - int uvti, yti = (YQT[i]*quality+50)/100; - YTable[stbiw__jpg_ZigZag[i]] = (unsigned char) (yti < 1 ? 1 : yti > 255 ? 255 : yti); - uvti = (UVQT[i]*quality+50)/100; - UVTable[stbiw__jpg_ZigZag[i]] = (unsigned char) (uvti < 1 ? 1 : uvti > 255 ? 255 : uvti); - } - - for(row = 0, k = 0; row < 8; ++row) { - for(col = 0; col < 8; ++col, ++k) { - fdtbl_Y[k] = 1 / (YTable [stbiw__jpg_ZigZag[k]] * aasf[row] * aasf[col]); - fdtbl_UV[k] = 1 / (UVTable[stbiw__jpg_ZigZag[k]] * aasf[row] * aasf[col]); - } - } - - // Write Headers - { - static const unsigned char head0[] = { 0xFF,0xD8,0xFF,0xE0,0,0x10,'J','F','I','F',0,1,1,0,0,1,0,1,0,0,0xFF,0xDB,0,0x84,0 }; - static const unsigned char head2[] = { 0xFF,0xDA,0,0xC,3,1,0,2,0x11,3,0x11,0,0x3F,0 }; - const unsigned char head1[] = { 0xFF,0xC0,0,0x11,8,(unsigned char)(height>>8),STBIW_UCHAR(height),(unsigned char)(width>>8),STBIW_UCHAR(width), - 3,1,(unsigned char)(subsample?0x22:0x11),0,2,0x11,1,3,0x11,1,0xFF,0xC4,0x01,0xA2,0 }; - s->func(s->context, (void*)head0, sizeof(head0)); - s->func(s->context, (void*)YTable, sizeof(YTable)); - stbiw__putc(s, 1); - s->func(s->context, UVTable, sizeof(UVTable)); - s->func(s->context, (void*)head1, sizeof(head1)); - s->func(s->context, (void*)(std_dc_luminance_nrcodes+1), sizeof(std_dc_luminance_nrcodes)-1); - s->func(s->context, (void*)std_dc_luminance_values, sizeof(std_dc_luminance_values)); - stbiw__putc(s, 0x10); // HTYACinfo - s->func(s->context, (void*)(std_ac_luminance_nrcodes+1), sizeof(std_ac_luminance_nrcodes)-1); - s->func(s->context, (void*)std_ac_luminance_values, sizeof(std_ac_luminance_values)); - stbiw__putc(s, 1); // HTUDCinfo - s->func(s->context, (void*)(std_dc_chrominance_nrcodes+1), sizeof(std_dc_chrominance_nrcodes)-1); - s->func(s->context, (void*)std_dc_chrominance_values, sizeof(std_dc_chrominance_values)); - stbiw__putc(s, 0x11); // HTUACinfo - s->func(s->context, (void*)(std_ac_chrominance_nrcodes+1), sizeof(std_ac_chrominance_nrcodes)-1); - s->func(s->context, (void*)std_ac_chrominance_values, sizeof(std_ac_chrominance_values)); - s->func(s->context, (void*)head2, sizeof(head2)); - } - - // Encode 8x8 macroblocks - { - static const unsigned short fillBits[] = {0x7F, 7}; - int DCY=0, DCU=0, DCV=0; - int bitBuf=0, bitCnt=0; - // comp == 2 is grey+alpha (alpha is ignored) - int ofsG = comp > 2 ? 1 : 0, ofsB = comp > 2 ? 2 : 0; - const unsigned char *dataR = (const unsigned char *)data; - const unsigned char *dataG = dataR + ofsG; - const unsigned char *dataB = dataR + ofsB; - int x, y, pos; - if(subsample) { - for(y = 0; y < height; y += 16) { - for(x = 0; x < width; x += 16) { - float Y[256], U[256], V[256]; - for(row = y, pos = 0; row < y+16; ++row) { - // row >= height => use last input row - int clamped_row = (row < height) ? row : height - 1; - int base_p = (stbi__flip_vertically_on_write ? (height-1-clamped_row) : clamped_row)*width*comp; - for(col = x; col < x+16; ++col, ++pos) { - // if col >= width => use pixel from last input column - int p = base_p + ((col < width) ? col : (width-1))*comp; - float r = dataR[p], g = dataG[p], b = dataB[p]; - Y[pos]= +0.29900f*r + 0.58700f*g + 0.11400f*b - 128; - U[pos]= -0.16874f*r - 0.33126f*g + 0.50000f*b; - V[pos]= +0.50000f*r - 0.41869f*g - 0.08131f*b; - } - } - DCY = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, Y+0, 16, fdtbl_Y, DCY, YDC_HT, YAC_HT); - DCY = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, Y+8, 16, fdtbl_Y, DCY, YDC_HT, YAC_HT); - DCY = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, Y+128, 16, fdtbl_Y, DCY, YDC_HT, YAC_HT); - DCY = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, Y+136, 16, fdtbl_Y, DCY, YDC_HT, YAC_HT); - - // subsample U,V - { - float subU[64], subV[64]; - int yy, xx; - for(yy = 0, pos = 0; yy < 8; ++yy) { - for(xx = 0; xx < 8; ++xx, ++pos) { - int j = yy*32+xx*2; - subU[pos] = (U[j+0] + U[j+1] + U[j+16] + U[j+17]) * 0.25f; - subV[pos] = (V[j+0] + V[j+1] + V[j+16] + V[j+17]) * 0.25f; - } - } - DCU = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, subU, 8, fdtbl_UV, DCU, UVDC_HT, UVAC_HT); - DCV = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, subV, 8, fdtbl_UV, DCV, UVDC_HT, UVAC_HT); - } - } - } - } else { - for(y = 0; y < height; y += 8) { - for(x = 0; x < width; x += 8) { - float Y[64], U[64], V[64]; - for(row = y, pos = 0; row < y+8; ++row) { - // row >= height => use last input row - int clamped_row = (row < height) ? row : height - 1; - int base_p = (stbi__flip_vertically_on_write ? (height-1-clamped_row) : clamped_row)*width*comp; - for(col = x; col < x+8; ++col, ++pos) { - // if col >= width => use pixel from last input column - int p = base_p + ((col < width) ? col : (width-1))*comp; - float r = dataR[p], g = dataG[p], b = dataB[p]; - Y[pos]= +0.29900f*r + 0.58700f*g + 0.11400f*b - 128; - U[pos]= -0.16874f*r - 0.33126f*g + 0.50000f*b; - V[pos]= +0.50000f*r - 0.41869f*g - 0.08131f*b; - } - } - - DCY = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, Y, 8, fdtbl_Y, DCY, YDC_HT, YAC_HT); - DCU = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, U, 8, fdtbl_UV, DCU, UVDC_HT, UVAC_HT); - DCV = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, V, 8, fdtbl_UV, DCV, UVDC_HT, UVAC_HT); - } - } - } - - // Do the bit alignment of the EOI marker - stbiw__jpg_writeBits(s, &bitBuf, &bitCnt, fillBits); - } - - // EOI - stbiw__putc(s, 0xFF); - stbiw__putc(s, 0xD9); - - return 1; -} - -STBIWDEF int stbi_write_jpg_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int quality) -{ - stbi__write_context s = { 0 }; - stbi__start_write_callbacks(&s, func, context); - return stbi_write_jpg_core(&s, x, y, comp, (void *) data, quality); -} - - -#ifndef STBI_WRITE_NO_STDIO -STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const void *data, int quality) -{ - stbi__write_context s = { 0 }; - if (stbi__start_write_file(&s,filename)) { - int r = stbi_write_jpg_core(&s, x, y, comp, data, quality); - stbi__end_write_file(&s); - return r; - } else - return 0; -} -#endif - -#endif // STB_IMAGE_WRITE_IMPLEMENTATION - -/* Revision history - 1.16 (2021-07-11) - make Deflate code emit uncompressed blocks when it would otherwise expand - support writing BMPs with alpha channel - 1.15 (2020-07-13) unknown - 1.14 (2020-02-02) updated JPEG writer to downsample chroma channels - 1.13 - 1.12 - 1.11 (2019-08-11) - - 1.10 (2019-02-07) - support utf8 filenames in Windows; fix warnings and platform ifdefs - 1.09 (2018-02-11) - fix typo in zlib quality API, improve STB_I_W_STATIC in C++ - 1.08 (2018-01-29) - add stbi__flip_vertically_on_write, external zlib, zlib quality, choose PNG filter - 1.07 (2017-07-24) - doc fix - 1.06 (2017-07-23) - writing JPEG (using Jon Olick's code) - 1.05 ??? - 1.04 (2017-03-03) - monochrome BMP expansion - 1.03 ??? - 1.02 (2016-04-02) - avoid allocating large structures on the stack - 1.01 (2016-01-16) - STBIW_REALLOC_SIZED: support allocators with no realloc support - avoid race-condition in crc initialization - minor compile issues - 1.00 (2015-09-14) - installable file IO function - 0.99 (2015-09-13) - warning fixes; TGA rle support - 0.98 (2015-04-08) - added STBIW_MALLOC, STBIW_ASSERT etc - 0.97 (2015-01-18) - fixed HDR asserts, rewrote HDR rle logic - 0.96 (2015-01-17) - add HDR output - fix monochrome BMP - 0.95 (2014-08-17) - add monochrome TGA output - 0.94 (2014-05-31) - rename private functions to avoid conflicts with stb_image.h - 0.93 (2014-05-27) - warning fixes - 0.92 (2010-08-01) - casts to unsigned char to fix warnings - 0.91 (2010-07-17) - first public release - 0.90 first internal release -*/ - -/* ------------------------------------------------------------------------------- -This software is available under 2 licenses -- choose whichever you prefer. ------------------------------------------------------------------------------- -ALTERNATIVE A - MIT License -Copyright (c) 2017 Sean Barrett -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. ------------------------------------------------------------------------------- -ALTERNATIVE B - Public Domain (www.unlicense.org) -This is free and unencumbered software released into the public domain. -Anyone is free to copy, modify, publish, use, compile, sell, or distribute this -software, either in source code form or as a compiled binary, for any purpose, -commercial or non-commercial, and by any means. -In jurisdictions that recognize copyright laws, the author or authors of this -software dedicate any and all copyright interest in the software to the public -domain. We make this dedication for the benefit of the public at large and to -the detriment of our heirs and successors. We intend this dedication to be an -overt act of relinquishment in perpetuity of all present and future rights to -this software under copyright law. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------- -*/ diff --git a/samples/stb_truetype.h b/samples/stb_truetype.h deleted file mode 100644 index 90a5c2e..0000000 --- a/samples/stb_truetype.h +++ /dev/null @@ -1,5079 +0,0 @@ -// stb_truetype.h - v1.26 - public domain -// authored from 2009-2021 by Sean Barrett / RAD Game Tools -// -// ======================================================================= -// -// NO SECURITY GUARANTEE -- DO NOT USE THIS ON UNTRUSTED FONT FILES -// -// This library does no range checking of the offsets found in the file, -// meaning an attacker can use it to read arbitrary memory. -// -// ======================================================================= -// -// This library processes TrueType files: -// parse files -// extract glyph metrics -// extract glyph shapes -// render glyphs to one-channel bitmaps with antialiasing (box filter) -// render glyphs to one-channel SDF bitmaps (signed-distance field/function) -// -// Todo: -// non-MS cmaps -// crashproof on bad data -// hinting? (no longer patented) -// cleartype-style AA? -// optimize: use simple memory allocator for intermediates -// optimize: build edge-list directly from curves -// optimize: rasterize directly from curves? -// -// ADDITIONAL CONTRIBUTORS -// -// Mikko Mononen: compound shape support, more cmap formats -// Tor Andersson: kerning, subpixel rendering -// Dougall Johnson: OpenType / Type 2 font handling -// Daniel Ribeiro Maciel: basic GPOS-based kerning -// -// Misc other: -// Ryan Gordon -// Simon Glass -// github:IntellectualKitty -// Imanol Celaya -// Daniel Ribeiro Maciel -// -// Bug/warning reports/fixes: -// "Zer" on mollyrocket Fabian "ryg" Giesen github:NiLuJe -// Cass Everitt Martins Mozeiko github:aloucks -// stoiko (Haemimont Games) Cap Petschulat github:oyvindjam -// Brian Hook Omar Cornut github:vassvik -// Walter van Niftrik Ryan Griege -// David Gow Peter LaValle -// David Given Sergey Popov -// Ivan-Assen Ivanov Giumo X. Clanjor -// Anthony Pesch Higor Euripedes -// Johan Duparc Thomas Fields -// Hou Qiming Derek Vinyard -// Rob Loach Cort Stratton -// Kenney Phillis Jr. Brian Costabile -// Ken Voskuil (kaesve) Yakov Galka -// -// VERSION HISTORY -// -// 1.26 (2021-08-28) fix broken rasterizer -// 1.25 (2021-07-11) many fixes -// 1.24 (2020-02-05) fix warning -// 1.23 (2020-02-02) query SVG data for glyphs; query whole kerning table (but only kern not GPOS) -// 1.22 (2019-08-11) minimize missing-glyph duplication; fix kerning if both 'GPOS' and 'kern' are defined -// 1.21 (2019-02-25) fix warning -// 1.20 (2019-02-07) PackFontRange skips missing codepoints; GetScaleFontVMetrics() -// 1.19 (2018-02-11) GPOS kerning, STBTT_fmod -// 1.18 (2018-01-29) add missing function -// 1.17 (2017-07-23) make more arguments const; doc fix -// 1.16 (2017-07-12) SDF support -// 1.15 (2017-03-03) make more arguments const -// 1.14 (2017-01-16) num-fonts-in-TTC function -// 1.13 (2017-01-02) support OpenType fonts, certain Apple fonts -// 1.12 (2016-10-25) suppress warnings about casting away const with -Wcast-qual -// 1.11 (2016-04-02) fix unused-variable warning -// 1.10 (2016-04-02) user-defined fabs(); rare memory leak; remove duplicate typedef -// 1.09 (2016-01-16) warning fix; avoid crash on outofmem; use allocation userdata properly -// 1.08 (2015-09-13) document stbtt_Rasterize(); fixes for vertical & horizontal edges -// 1.07 (2015-08-01) allow PackFontRanges to accept arrays of sparse codepoints; -// variant PackFontRanges to pack and render in separate phases; -// fix stbtt_GetFontOFfsetForIndex (never worked for non-0 input?); -// fixed an assert() bug in the new rasterizer -// replace assert() with STBTT_assert() in new rasterizer -// -// Full history can be found at the end of this file. -// -// LICENSE -// -// See end of file for license information. -// -// USAGE -// -// Include this file in whatever places need to refer to it. In ONE C/C++ -// file, write: -// #define STB_TRUETYPE_IMPLEMENTATION -// before the #include of this file. This expands out the actual -// implementation into that C/C++ file. -// -// To make the implementation private to the file that generates the implementation, -// #define STBTT_STATIC -// -// Simple 3D API (don't ship this, but it's fine for tools and quick start) -// stbtt_BakeFontBitmap() -- bake a font to a bitmap for use as texture -// stbtt_GetBakedQuad() -- compute quad to draw for a given char -// -// Improved 3D API (more shippable): -// #include "stb_rect_pack.h" -- optional, but you really want it -// stbtt_PackBegin() -// stbtt_PackSetOversampling() -- for improved quality on small fonts -// stbtt_PackFontRanges() -- pack and renders -// stbtt_PackEnd() -// stbtt_GetPackedQuad() -// -// "Load" a font file from a memory buffer (you have to keep the buffer loaded) -// stbtt_InitFont() -// stbtt_GetFontOffsetForIndex() -- indexing for TTC font collections -// stbtt_GetNumberOfFonts() -- number of fonts for TTC font collections -// -// Render a unicode codepoint to a bitmap -// stbtt_GetCodepointBitmap() -- allocates and returns a bitmap -// stbtt_MakeCodepointBitmap() -- renders into bitmap you provide -// stbtt_GetCodepointBitmapBox() -- how big the bitmap must be -// -// Character advance/positioning -// stbtt_GetCodepointHMetrics() -// stbtt_GetFontVMetrics() -// stbtt_GetFontVMetricsOS2() -// stbtt_GetCodepointKernAdvance() -// -// Starting with version 1.06, the rasterizer was replaced with a new, -// faster and generally-more-precise rasterizer. The new rasterizer more -// accurately measures pixel coverage for anti-aliasing, except in the case -// where multiple shapes overlap, in which case it overestimates the AA pixel -// coverage. Thus, anti-aliasing of intersecting shapes may look wrong. If -// this turns out to be a problem, you can re-enable the old rasterizer with -// #define STBTT_RASTERIZER_VERSION 1 -// which will incur about a 15% speed hit. -// -// ADDITIONAL DOCUMENTATION -// -// Immediately after this block comment are a series of sample programs. -// -// After the sample programs is the "header file" section. This section -// includes documentation for each API function. -// -// Some important concepts to understand to use this library: -// -// Codepoint -// Characters are defined by unicode codepoints, e.g. 65 is -// uppercase A, 231 is lowercase c with a cedilla, 0x7e30 is -// the hiragana for "ma". -// -// Glyph -// A visual character shape (every codepoint is rendered as -// some glyph) -// -// Glyph index -// A font-specific integer ID representing a glyph -// -// Baseline -// Glyph shapes are defined relative to a baseline, which is the -// bottom of uppercase characters. Characters extend both above -// and below the baseline. -// -// Current Point -// As you draw text to the screen, you keep track of a "current point" -// which is the origin of each character. The current point's vertical -// position is the baseline. Even "baked fonts" use this model. -// -// Vertical Font Metrics -// The vertical qualities of the font, used to vertically position -// and space the characters. See docs for stbtt_GetFontVMetrics. -// -// Font Size in Pixels or Points -// The preferred interface for specifying font sizes in stb_truetype -// is to specify how tall the font's vertical extent should be in pixels. -// If that sounds good enough, skip the next paragraph. -// -// Most font APIs instead use "points", which are a common typographic -// measurement for describing font size, defined as 72 points per inch. -// stb_truetype provides a point API for compatibility. However, true -// "per inch" conventions don't make much sense on computer displays -// since different monitors have different number of pixels per -// inch. For example, Windows traditionally uses a convention that -// there are 96 pixels per inch, thus making 'inch' measurements have -// nothing to do with inches, and thus effectively defining a point to -// be 1.333 pixels. Additionally, the TrueType font data provides -// an explicit scale factor to scale a given font's glyphs to points, -// but the author has observed that this scale factor is often wrong -// for non-commercial fonts, thus making fonts scaled in points -// according to the TrueType spec incoherently sized in practice. -// -// DETAILED USAGE: -// -// Scale: -// Select how high you want the font to be, in points or pixels. -// Call ScaleForPixelHeight or ScaleForMappingEmToPixels to compute -// a scale factor SF that will be used by all other functions. -// -// Baseline: -// You need to select a y-coordinate that is the baseline of where -// your text will appear. Call GetFontBoundingBox to get the baseline-relative -// bounding box for all characters. SF*-y0 will be the distance in pixels -// that the worst-case character could extend above the baseline, so if -// you want the top edge of characters to appear at the top of the -// screen where y=0, then you would set the baseline to SF*-y0. -// -// Current point: -// Set the current point where the first character will appear. The -// first character could extend left of the current point; this is font -// dependent. You can either choose a current point that is the leftmost -// point and hope, or add some padding, or check the bounding box or -// left-side-bearing of the first character to be displayed and set -// the current point based on that. -// -// Displaying a character: -// Compute the bounding box of the character. It will contain signed values -// relative to . I.e. if it returns x0,y0,x1,y1, -// then the character should be displayed in the rectangle from -// to = 32 && *text < 128) { - stbtt_aligned_quad q; - stbtt_GetBakedQuad(cdata, 512,512, *text-32, &x,&y,&q,1);//1=opengl & d3d10+,0=d3d9 - glTexCoord2f(q.s0,q.t0); glVertex2f(q.x0,q.y0); - glTexCoord2f(q.s1,q.t0); glVertex2f(q.x1,q.y0); - glTexCoord2f(q.s1,q.t1); glVertex2f(q.x1,q.y1); - glTexCoord2f(q.s0,q.t1); glVertex2f(q.x0,q.y1); - } - ++text; - } - glEnd(); -} -#endif -// -// -////////////////////////////////////////////////////////////////////////////// -// -// Complete program (this compiles): get a single bitmap, print as ASCII art -// -#if 0 -#include -#define STB_TRUETYPE_IMPLEMENTATION // force following include to generate implementation -#include "stb_truetype.h" - -char ttf_buffer[1<<25]; - -int main(int argc, char **argv) -{ - stbtt_fontinfo font; - unsigned char *bitmap; - int w,h,i,j,c = (argc > 1 ? atoi(argv[1]) : 'a'), s = (argc > 2 ? atoi(argv[2]) : 20); - - fread(ttf_buffer, 1, 1<<25, fopen(argc > 3 ? argv[3] : "c:/windows/fonts/arialbd.ttf", "rb")); - - stbtt_InitFont(&font, ttf_buffer, stbtt_GetFontOffsetForIndex(ttf_buffer,0)); - bitmap = stbtt_GetCodepointBitmap(&font, 0,stbtt_ScaleForPixelHeight(&font, s), c, &w, &h, 0,0); - - for (j=0; j < h; ++j) { - for (i=0; i < w; ++i) - putchar(" .:ioVM@"[bitmap[j*w+i]>>5]); - putchar('\n'); - } - return 0; -} -#endif -// -// Output: -// -// .ii. -// @@@@@@. -// V@Mio@@o -// :i. V@V -// :oM@@M -// :@@@MM@M -// @@o o@M -// :@@. M@M -// @@@o@@@@ -// :M@@V:@@. -// -////////////////////////////////////////////////////////////////////////////// -// -// Complete program: print "Hello World!" banner, with bugs -// -#if 0 -char buffer[24<<20]; -unsigned char screen[20][79]; - -int main(int arg, char **argv) -{ - stbtt_fontinfo font; - int i,j,ascent,baseline,ch=0; - float scale, xpos=2; // leave a little padding in case the character extends left - char *text = "Heljo World!"; // intentionally misspelled to show 'lj' brokenness - - fread(buffer, 1, 1000000, fopen("c:/windows/fonts/arialbd.ttf", "rb")); - stbtt_InitFont(&font, buffer, 0); - - scale = stbtt_ScaleForPixelHeight(&font, 15); - stbtt_GetFontVMetrics(&font, &ascent,0,0); - baseline = (int) (ascent*scale); - - while (text[ch]) { - int advance,lsb,x0,y0,x1,y1; - float x_shift = xpos - (float) floor(xpos); - stbtt_GetCodepointHMetrics(&font, text[ch], &advance, &lsb); - stbtt_GetCodepointBitmapBoxSubpixel(&font, text[ch], scale,scale,x_shift,0, &x0,&y0,&x1,&y1); - stbtt_MakeCodepointBitmapSubpixel(&font, &screen[baseline + y0][(int) xpos + x0], x1-x0,y1-y0, 79, scale,scale,x_shift,0, text[ch]); - // note that this stomps the old data, so where character boxes overlap (e.g. 'lj') it's wrong - // because this API is really for baking character bitmaps into textures. if you want to render - // a sequence of characters, you really need to render each bitmap to a temp buffer, then - // "alpha blend" that into the working buffer - xpos += (advance * scale); - if (text[ch+1]) - xpos += scale*stbtt_GetCodepointKernAdvance(&font, text[ch],text[ch+1]); - ++ch; - } - - for (j=0; j < 20; ++j) { - for (i=0; i < 78; ++i) - putchar(" .:ioVM@"[screen[j][i]>>5]); - putchar('\n'); - } - - return 0; -} -#endif - - -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// -//// -//// INTEGRATION WITH YOUR CODEBASE -//// -//// The following sections allow you to supply alternate definitions -//// of C library functions used by stb_truetype, e.g. if you don't -//// link with the C runtime library. - -#ifdef STB_TRUETYPE_IMPLEMENTATION - // #define your own (u)stbtt_int8/16/32 before including to override this - #ifndef stbtt_uint8 - typedef unsigned char stbtt_uint8; - typedef signed char stbtt_int8; - typedef unsigned short stbtt_uint16; - typedef signed short stbtt_int16; - typedef unsigned int stbtt_uint32; - typedef signed int stbtt_int32; - #endif - - typedef char stbtt__check_size32[sizeof(stbtt_int32)==4 ? 1 : -1]; - typedef char stbtt__check_size16[sizeof(stbtt_int16)==2 ? 1 : -1]; - - // e.g. #define your own STBTT_ifloor/STBTT_iceil() to avoid math.h - #ifndef STBTT_ifloor - #include - #define STBTT_ifloor(x) ((int) floor(x)) - #define STBTT_iceil(x) ((int) ceil(x)) - #endif - - #ifndef STBTT_sqrt - #include - #define STBTT_sqrt(x) sqrt(x) - #define STBTT_pow(x,y) pow(x,y) - #endif - - #ifndef STBTT_fmod - #include - #define STBTT_fmod(x,y) fmod(x,y) - #endif - - #ifndef STBTT_cos - #include - #define STBTT_cos(x) cos(x) - #define STBTT_acos(x) acos(x) - #endif - - #ifndef STBTT_fabs - #include - #define STBTT_fabs(x) fabs(x) - #endif - - // #define your own functions "STBTT_malloc" / "STBTT_free" to avoid malloc.h - #ifndef STBTT_malloc - #include - #define STBTT_malloc(x,u) ((void)(u),malloc(x)) - #define STBTT_free(x,u) ((void)(u),free(x)) - #endif - - #ifndef STBTT_assert - #include - #define STBTT_assert(x) assert(x) - #endif - - #ifndef STBTT_strlen - #include - #define STBTT_strlen(x) strlen(x) - #endif - - #ifndef STBTT_memcpy - #include - #define STBTT_memcpy memcpy - #define STBTT_memset memset - #endif -#endif - -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -//// -//// INTERFACE -//// -//// - -#ifndef __STB_INCLUDE_STB_TRUETYPE_H__ -#define __STB_INCLUDE_STB_TRUETYPE_H__ - -#ifdef STBTT_STATIC -#define STBTT_DEF static -#else -#define STBTT_DEF extern -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -// private structure -typedef struct -{ - unsigned char *data; - int cursor; - int size; -} stbtt__buf; - -////////////////////////////////////////////////////////////////////////////// -// -// TEXTURE BAKING API -// -// If you use this API, you only have to call two functions ever. -// - -typedef struct -{ - unsigned short x0,y0,x1,y1; // coordinates of bbox in bitmap - float xoff,yoff,xadvance; -} stbtt_bakedchar; - -STBTT_DEF int stbtt_BakeFontBitmap(const unsigned char *data, int offset, // font location (use offset=0 for plain .ttf) - float pixel_height, // height of font in pixels - unsigned char *pixels, int pw, int ph, // bitmap to be filled in - int first_char, int num_chars, // characters to bake - stbtt_bakedchar *chardata); // you allocate this, it's num_chars long -// if return is positive, the first unused row of the bitmap -// if return is negative, returns the negative of the number of characters that fit -// if return is 0, no characters fit and no rows were used -// This uses a very crappy packing. - -typedef struct -{ - float x0,y0,s0,t0; // top-left - float x1,y1,s1,t1; // bottom-right -} stbtt_aligned_quad; - -STBTT_DEF void stbtt_GetBakedQuad(const stbtt_bakedchar *chardata, int pw, int ph, // same data as above - int char_index, // character to display - float *xpos, float *ypos, // pointers to current position in screen pixel space - stbtt_aligned_quad *q, // output: quad to draw - int opengl_fillrule); // true if opengl fill rule; false if DX9 or earlier -// Call GetBakedQuad with char_index = 'character - first_char', and it -// creates the quad you need to draw and advances the current position. -// -// The coordinate system used assumes y increases downwards. -// -// Characters will extend both above and below the current position; -// see discussion of "BASELINE" above. -// -// It's inefficient; you might want to c&p it and optimize it. - -STBTT_DEF void stbtt_GetScaledFontVMetrics(const unsigned char *fontdata, int index, float size, float *ascent, float *descent, float *lineGap); -// Query the font vertical metrics without having to create a font first. - - -////////////////////////////////////////////////////////////////////////////// -// -// NEW TEXTURE BAKING API -// -// This provides options for packing multiple fonts into one atlas, not -// perfectly but better than nothing. - -typedef struct -{ - unsigned short x0,y0,x1,y1; // coordinates of bbox in bitmap - float xoff,yoff,xadvance; - float xoff2,yoff2; -} stbtt_packedchar; - -typedef struct stbtt_pack_context stbtt_pack_context; -typedef struct stbtt_fontinfo stbtt_fontinfo; -#ifndef STB_RECT_PACK_VERSION -typedef struct stbrp_rect stbrp_rect; -#endif - -STBTT_DEF int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, int width, int height, int stride_in_bytes, int padding, void *alloc_context); -// Initializes a packing context stored in the passed-in stbtt_pack_context. -// Future calls using this context will pack characters into the bitmap passed -// in here: a 1-channel bitmap that is width * height. stride_in_bytes is -// the distance from one row to the next (or 0 to mean they are packed tightly -// together). "padding" is the amount of padding to leave between each -// character (normally you want '1' for bitmaps you'll use as textures with -// bilinear filtering). -// -// Returns 0 on failure, 1 on success. - -STBTT_DEF void stbtt_PackEnd (stbtt_pack_context *spc); -// Cleans up the packing context and frees all memory. - -#define STBTT_POINT_SIZE(x) (-(x)) - -STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, const unsigned char *fontdata, int font_index, float font_size, - int first_unicode_char_in_range, int num_chars_in_range, stbtt_packedchar *chardata_for_range); -// Creates character bitmaps from the font_index'th font found in fontdata (use -// font_index=0 if you don't know what that is). It creates num_chars_in_range -// bitmaps for characters with unicode values starting at first_unicode_char_in_range -// and increasing. Data for how to render them is stored in chardata_for_range; -// pass these to stbtt_GetPackedQuad to get back renderable quads. -// -// font_size is the full height of the character from ascender to descender, -// as computed by stbtt_ScaleForPixelHeight. To use a point size as computed -// by stbtt_ScaleForMappingEmToPixels, wrap the point size in STBTT_POINT_SIZE() -// and pass that result as 'font_size': -// ..., 20 , ... // font max minus min y is 20 pixels tall -// ..., STBTT_POINT_SIZE(20), ... // 'M' is 20 pixels tall - -typedef struct -{ - float font_size; - int first_unicode_codepoint_in_range; // if non-zero, then the chars are continuous, and this is the first codepoint - int *array_of_unicode_codepoints; // if non-zero, then this is an array of unicode codepoints - int num_chars; - stbtt_packedchar *chardata_for_range; // output - unsigned char h_oversample, v_oversample; // don't set these, they're used internally -} stbtt_pack_range; - -STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, const unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges); -// Creates character bitmaps from multiple ranges of characters stored in -// ranges. This will usually create a better-packed bitmap than multiple -// calls to stbtt_PackFontRange. Note that you can call this multiple -// times within a single PackBegin/PackEnd. - -STBTT_DEF void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_oversample); -// Oversampling a font increases the quality by allowing higher-quality subpixel -// positioning, and is especially valuable at smaller text sizes. -// -// This function sets the amount of oversampling for all following calls to -// stbtt_PackFontRange(s) or stbtt_PackFontRangesGatherRects for a given -// pack context. The default (no oversampling) is achieved by h_oversample=1 -// and v_oversample=1. The total number of pixels required is -// h_oversample*v_oversample larger than the default; for example, 2x2 -// oversampling requires 4x the storage of 1x1. For best results, render -// oversampled textures with bilinear filtering. Look at the readme in -// stb/tests/oversample for information about oversampled fonts -// -// To use with PackFontRangesGather etc., you must set it before calls -// call to PackFontRangesGatherRects. - -STBTT_DEF void stbtt_PackSetSkipMissingCodepoints(stbtt_pack_context *spc, int skip); -// If skip != 0, this tells stb_truetype to skip any codepoints for which -// there is no corresponding glyph. If skip=0, which is the default, then -// codepoints without a glyph recived the font's "missing character" glyph, -// typically an empty box by convention. - -STBTT_DEF void stbtt_GetPackedQuad(const stbtt_packedchar *chardata, int pw, int ph, // same data as above - int char_index, // character to display - float *xpos, float *ypos, // pointers to current position in screen pixel space - stbtt_aligned_quad *q, // output: quad to draw - int align_to_integer); - -STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, const stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects); -STBTT_DEF void stbtt_PackFontRangesPackRects(stbtt_pack_context *spc, stbrp_rect *rects, int num_rects); -STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, const stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects); -// Calling these functions in sequence is roughly equivalent to calling -// stbtt_PackFontRanges(). If you more control over the packing of multiple -// fonts, or if you want to pack custom data into a font texture, take a look -// at the source to of stbtt_PackFontRanges() and create a custom version -// using these functions, e.g. call GatherRects multiple times, -// building up a single array of rects, then call PackRects once, -// then call RenderIntoRects repeatedly. This may result in a -// better packing than calling PackFontRanges multiple times -// (or it may not). - -// this is an opaque structure that you shouldn't mess with which holds -// all the context needed from PackBegin to PackEnd. -struct stbtt_pack_context { - void *user_allocator_context; - void *pack_info; - int width; - int height; - int stride_in_bytes; - int padding; - int skip_missing; - unsigned int h_oversample, v_oversample; - unsigned char *pixels; - void *nodes; -}; - -////////////////////////////////////////////////////////////////////////////// -// -// FONT LOADING -// -// - -STBTT_DEF int stbtt_GetNumberOfFonts(const unsigned char *data); -// This function will determine the number of fonts in a font file. TrueType -// collection (.ttc) files may contain multiple fonts, while TrueType font -// (.ttf) files only contain one font. The number of fonts can be used for -// indexing with the previous function where the index is between zero and one -// less than the total fonts. If an error occurs, -1 is returned. - -STBTT_DEF int stbtt_GetFontOffsetForIndex(const unsigned char *data, int index); -// Each .ttf/.ttc file may have more than one font. Each font has a sequential -// index number starting from 0. Call this function to get the font offset for -// a given index; it returns -1 if the index is out of range. A regular .ttf -// file will only define one font and it always be at offset 0, so it will -// return '0' for index 0, and -1 for all other indices. - -// The following structure is defined publicly so you can declare one on -// the stack or as a global or etc, but you should treat it as opaque. -struct stbtt_fontinfo -{ - void * userdata; - unsigned char * data; // pointer to .ttf file - int fontstart; // offset of start of font - - int numGlyphs; // number of glyphs, needed for range checking - - int loca,head,glyf,hhea,hmtx,kern,gpos,svg; // table locations as offset from start of .ttf - int index_map; // a cmap mapping for our chosen character encoding - int indexToLocFormat; // format needed to map from glyph index to glyph - - stbtt__buf cff; // cff font data - stbtt__buf charstrings; // the charstring index - stbtt__buf gsubrs; // global charstring subroutines index - stbtt__buf subrs; // private charstring subroutines index - stbtt__buf fontdicts; // array of font dicts - stbtt__buf fdselect; // map from glyph to fontdict -}; - -STBTT_DEF int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data, int offset); -// Given an offset into the file that defines a font, this function builds -// the necessary cached info for the rest of the system. You must allocate -// the stbtt_fontinfo yourself, and stbtt_InitFont will fill it out. You don't -// need to do anything special to free it, because the contents are pure -// value data with no additional data structures. Returns 0 on failure. - - -////////////////////////////////////////////////////////////////////////////// -// -// CHARACTER TO GLYPH-INDEX CONVERSIOn - -STBTT_DEF int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint); -// If you're going to perform multiple operations on the same character -// and you want a speed-up, call this function with the character you're -// going to process, then use glyph-based functions instead of the -// codepoint-based functions. -// Returns 0 if the character codepoint is not defined in the font. - - -////////////////////////////////////////////////////////////////////////////// -// -// CHARACTER PROPERTIES -// - -STBTT_DEF float stbtt_ScaleForPixelHeight(const stbtt_fontinfo *info, float pixels); -// computes a scale factor to produce a font whose "height" is 'pixels' tall. -// Height is measured as the distance from the highest ascender to the lowest -// descender; in other words, it's equivalent to calling stbtt_GetFontVMetrics -// and computing: -// scale = pixels / (ascent - descent) -// so if you prefer to measure height by the ascent only, use a similar calculation. - -STBTT_DEF float stbtt_ScaleForMappingEmToPixels(const stbtt_fontinfo *info, float pixels); -// computes a scale factor to produce a font whose EM size is mapped to -// 'pixels' tall. This is probably what traditional APIs compute, but -// I'm not positive. - -STBTT_DEF void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, int *descent, int *lineGap); -// ascent is the coordinate above the baseline the font extends; descent -// is the coordinate below the baseline the font extends (i.e. it is typically negative) -// lineGap is the spacing between one row's descent and the next row's ascent... -// so you should advance the vertical position by "*ascent - *descent + *lineGap" -// these are expressed in unscaled coordinates, so you must multiply by -// the scale factor for a given size - -STBTT_DEF int stbtt_GetFontVMetricsOS2(const stbtt_fontinfo *info, int *typoAscent, int *typoDescent, int *typoLineGap); -// analogous to GetFontVMetrics, but returns the "typographic" values from the OS/2 -// table (specific to MS/Windows TTF files). -// -// Returns 1 on success (table present), 0 on failure. - -STBTT_DEF void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int *x1, int *y1); -// the bounding box around all possible characters - -STBTT_DEF void stbtt_GetCodepointHMetrics(const stbtt_fontinfo *info, int codepoint, int *advanceWidth, int *leftSideBearing); -// leftSideBearing is the offset from the current horizontal position to the left edge of the character -// advanceWidth is the offset from the current horizontal position to the next horizontal position -// these are expressed in unscaled coordinates - -STBTT_DEF int stbtt_GetCodepointKernAdvance(const stbtt_fontinfo *info, int ch1, int ch2); -// an additional amount to add to the 'advance' value between ch1 and ch2 - -STBTT_DEF int stbtt_GetCodepointBox(const stbtt_fontinfo *info, int codepoint, int *x0, int *y0, int *x1, int *y1); -// Gets the bounding box of the visible part of the glyph, in unscaled coordinates - -STBTT_DEF void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_index, int *advanceWidth, int *leftSideBearing); -STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2); -STBTT_DEF int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1); -// as above, but takes one or more glyph indices for greater efficiency - -typedef struct stbtt_kerningentry -{ - int glyph1; // use stbtt_FindGlyphIndex - int glyph2; - int advance; -} stbtt_kerningentry; - -STBTT_DEF int stbtt_GetKerningTableLength(const stbtt_fontinfo *info); -STBTT_DEF int stbtt_GetKerningTable(const stbtt_fontinfo *info, stbtt_kerningentry* table, int table_length); -// Retrieves a complete list of all of the kerning pairs provided by the font -// stbtt_GetKerningTable never writes more than table_length entries and returns how many entries it did write. -// The table will be sorted by (a.glyph1 == b.glyph1)?(a.glyph2 < b.glyph2):(a.glyph1 < b.glyph1) - -////////////////////////////////////////////////////////////////////////////// -// -// GLYPH SHAPES (you probably don't need these, but they have to go before -// the bitmaps for C declaration-order reasons) -// - -#ifndef STBTT_vmove // you can predefine these to use different values (but why?) - enum { - STBTT_vmove=1, - STBTT_vline, - STBTT_vcurve, - STBTT_vcubic - }; -#endif - -#ifndef stbtt_vertex // you can predefine this to use different values - // (we share this with other code at RAD) - #define stbtt_vertex_type short // can't use stbtt_int16 because that's not visible in the header file - typedef struct - { - stbtt_vertex_type x,y,cx,cy,cx1,cy1; - unsigned char type,padding; - } stbtt_vertex; -#endif - -STBTT_DEF int stbtt_IsGlyphEmpty(const stbtt_fontinfo *info, int glyph_index); -// returns non-zero if nothing is drawn for this glyph - -STBTT_DEF int stbtt_GetCodepointShape(const stbtt_fontinfo *info, int unicode_codepoint, stbtt_vertex **vertices); -STBTT_DEF int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **vertices); -// returns # of vertices and fills *vertices with the pointer to them -// these are expressed in "unscaled" coordinates -// -// The shape is a series of contours. Each one starts with -// a STBTT_moveto, then consists of a series of mixed -// STBTT_lineto and STBTT_curveto segments. A lineto -// draws a line from previous endpoint to its x,y; a curveto -// draws a quadratic bezier from previous endpoint to -// its x,y, using cx,cy as the bezier control point. - -STBTT_DEF void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *vertices); -// frees the data allocated above - -STBTT_DEF unsigned char *stbtt_FindSVGDoc(const stbtt_fontinfo *info, int gl); -STBTT_DEF int stbtt_GetCodepointSVG(const stbtt_fontinfo *info, int unicode_codepoint, const char **svg); -STBTT_DEF int stbtt_GetGlyphSVG(const stbtt_fontinfo *info, int gl, const char **svg); -// fills svg with the character's SVG data. -// returns data size or 0 if SVG not found. - -////////////////////////////////////////////////////////////////////////////// -// -// BITMAP RENDERING -// - -STBTT_DEF void stbtt_FreeBitmap(unsigned char *bitmap, void *userdata); -// frees the bitmap allocated below - -STBTT_DEF unsigned char *stbtt_GetCodepointBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int codepoint, int *width, int *height, int *xoff, int *yoff); -// allocates a large-enough single-channel 8bpp bitmap and renders the -// specified character/glyph at the specified scale into it, with -// antialiasing. 0 is no coverage (transparent), 255 is fully covered (opaque). -// *width & *height are filled out with the width & height of the bitmap, -// which is stored left-to-right, top-to-bottom. -// -// xoff/yoff are the offset it pixel space from the glyph origin to the top-left of the bitmap - -STBTT_DEF unsigned char *stbtt_GetCodepointBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint, int *width, int *height, int *xoff, int *yoff); -// the same as stbtt_GetCodepoitnBitmap, but you can specify a subpixel -// shift for the character - -STBTT_DEF void stbtt_MakeCodepointBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int codepoint); -// the same as stbtt_GetCodepointBitmap, but you pass in storage for the bitmap -// in the form of 'output', with row spacing of 'out_stride' bytes. the bitmap -// is clipped to out_w/out_h bytes. Call stbtt_GetCodepointBitmapBox to get the -// width and height and positioning info for it first. - -STBTT_DEF void stbtt_MakeCodepointBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint); -// same as stbtt_MakeCodepointBitmap, but you can specify a subpixel -// shift for the character - -STBTT_DEF void stbtt_MakeCodepointBitmapSubpixelPrefilter(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int oversample_x, int oversample_y, float *sub_x, float *sub_y, int codepoint); -// same as stbtt_MakeCodepointBitmapSubpixel, but prefiltering -// is performed (see stbtt_PackSetOversampling) - -STBTT_DEF void stbtt_GetCodepointBitmapBox(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1); -// get the bbox of the bitmap centered around the glyph origin; so the -// bitmap width is ix1-ix0, height is iy1-iy0, and location to place -// the bitmap top left is (leftSideBearing*scale,iy0). -// (Note that the bitmap uses y-increases-down, but the shape uses -// y-increases-up, so CodepointBitmapBox and CodepointBox are inverted.) - -STBTT_DEF void stbtt_GetCodepointBitmapBoxSubpixel(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1); -// same as stbtt_GetCodepointBitmapBox, but you can specify a subpixel -// shift for the character - -// the following functions are equivalent to the above functions, but operate -// on glyph indices instead of Unicode codepoints (for efficiency) -STBTT_DEF unsigned char *stbtt_GetGlyphBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int glyph, int *width, int *height, int *xoff, int *yoff); -STBTT_DEF unsigned char *stbtt_GetGlyphBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int glyph, int *width, int *height, int *xoff, int *yoff); -STBTT_DEF void stbtt_MakeGlyphBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int glyph); -STBTT_DEF void stbtt_MakeGlyphBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int glyph); -STBTT_DEF void stbtt_MakeGlyphBitmapSubpixelPrefilter(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int oversample_x, int oversample_y, float *sub_x, float *sub_y, int glyph); -STBTT_DEF void stbtt_GetGlyphBitmapBox(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1); -STBTT_DEF void stbtt_GetGlyphBitmapBoxSubpixel(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y,float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1); - - -// @TODO: don't expose this structure -typedef struct -{ - int w,h,stride; - unsigned char *pixels; -} stbtt__bitmap; - -// rasterize a shape with quadratic beziers into a bitmap -STBTT_DEF void stbtt_Rasterize(stbtt__bitmap *result, // 1-channel bitmap to draw into - float flatness_in_pixels, // allowable error of curve in pixels - stbtt_vertex *vertices, // array of vertices defining shape - int num_verts, // number of vertices in above array - float scale_x, float scale_y, // scale applied to input vertices - float shift_x, float shift_y, // translation applied to input vertices - int x_off, int y_off, // another translation applied to input - int invert, // if non-zero, vertically flip shape - void *userdata); // context for to STBTT_MALLOC - -////////////////////////////////////////////////////////////////////////////// -// -// Signed Distance Function (or Field) rendering - -STBTT_DEF void stbtt_FreeSDF(unsigned char *bitmap, void *userdata); -// frees the SDF bitmap allocated below - -STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float scale, int glyph, int padding, unsigned char onedge_value, float pixel_dist_scale, int *width, int *height, int *xoff, int *yoff); -STBTT_DEF unsigned char * stbtt_GetCodepointSDF(const stbtt_fontinfo *info, float scale, int codepoint, int padding, unsigned char onedge_value, float pixel_dist_scale, int *width, int *height, int *xoff, int *yoff); -// These functions compute a discretized SDF field for a single character, suitable for storing -// in a single-channel texture, sampling with bilinear filtering, and testing against -// larger than some threshold to produce scalable fonts. -// info -- the font -// scale -- controls the size of the resulting SDF bitmap, same as it would be creating a regular bitmap -// glyph/codepoint -- the character to generate the SDF for -// padding -- extra "pixels" around the character which are filled with the distance to the character (not 0), -// which allows effects like bit outlines -// onedge_value -- value 0-255 to test the SDF against to reconstruct the character (i.e. the isocontour of the character) -// pixel_dist_scale -- what value the SDF should increase by when moving one SDF "pixel" away from the edge (on the 0..255 scale) -// if positive, > onedge_value is inside; if negative, < onedge_value is inside -// width,height -- output height & width of the SDF bitmap (including padding) -// xoff,yoff -- output origin of the character -// return value -- a 2D array of bytes 0..255, width*height in size -// -// pixel_dist_scale & onedge_value are a scale & bias that allows you to make -// optimal use of the limited 0..255 for your application, trading off precision -// and special effects. SDF values outside the range 0..255 are clamped to 0..255. -// -// Example: -// scale = stbtt_ScaleForPixelHeight(22) -// padding = 5 -// onedge_value = 180 -// pixel_dist_scale = 180/5.0 = 36.0 -// -// This will create an SDF bitmap in which the character is about 22 pixels -// high but the whole bitmap is about 22+5+5=32 pixels high. To produce a filled -// shape, sample the SDF at each pixel and fill the pixel if the SDF value -// is greater than or equal to 180/255. (You'll actually want to antialias, -// which is beyond the scope of this example.) Additionally, you can compute -// offset outlines (e.g. to stroke the character border inside & outside, -// or only outside). For example, to fill outside the character up to 3 SDF -// pixels, you would compare against (180-36.0*3)/255 = 72/255. The above -// choice of variables maps a range from 5 pixels outside the shape to -// 2 pixels inside the shape to 0..255; this is intended primarily for apply -// outside effects only (the interior range is needed to allow proper -// antialiasing of the font at *smaller* sizes) -// -// The function computes the SDF analytically at each SDF pixel, not by e.g. -// building a higher-res bitmap and approximating it. In theory the quality -// should be as high as possible for an SDF of this size & representation, but -// unclear if this is true in practice (perhaps building a higher-res bitmap -// and computing from that can allow drop-out prevention). -// -// The algorithm has not been optimized at all, so expect it to be slow -// if computing lots of characters or very large sizes. - - - -////////////////////////////////////////////////////////////////////////////// -// -// Finding the right font... -// -// You should really just solve this offline, keep your own tables -// of what font is what, and don't try to get it out of the .ttf file. -// That's because getting it out of the .ttf file is really hard, because -// the names in the file can appear in many possible encodings, in many -// possible languages, and e.g. if you need a case-insensitive comparison, -// the details of that depend on the encoding & language in a complex way -// (actually underspecified in truetype, but also gigantic). -// -// But you can use the provided functions in two possible ways: -// stbtt_FindMatchingFont() will use *case-sensitive* comparisons on -// unicode-encoded names to try to find the font you want; -// you can run this before calling stbtt_InitFont() -// -// stbtt_GetFontNameString() lets you get any of the various strings -// from the file yourself and do your own comparisons on them. -// You have to have called stbtt_InitFont() first. - - -STBTT_DEF int stbtt_FindMatchingFont(const unsigned char *fontdata, const char *name, int flags); -// returns the offset (not index) of the font that matches, or -1 if none -// if you use STBTT_MACSTYLE_DONTCARE, use a font name like "Arial Bold". -// if you use any other flag, use a font name like "Arial"; this checks -// the 'macStyle' header field; i don't know if fonts set this consistently -#define STBTT_MACSTYLE_DONTCARE 0 -#define STBTT_MACSTYLE_BOLD 1 -#define STBTT_MACSTYLE_ITALIC 2 -#define STBTT_MACSTYLE_UNDERSCORE 4 -#define STBTT_MACSTYLE_NONE 8 // <= not same as 0, this makes us check the bitfield is 0 - -STBTT_DEF int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const char *s2, int len2); -// returns 1/0 whether the first string interpreted as utf8 is identical to -// the second string interpreted as big-endian utf16... useful for strings from next func - -STBTT_DEF const char *stbtt_GetFontNameString(const stbtt_fontinfo *font, int *length, int platformID, int encodingID, int languageID, int nameID); -// returns the string (which may be big-endian double byte, e.g. for unicode) -// and puts the length in bytes in *length. -// -// some of the values for the IDs are below; for more see the truetype spec: -// http://developer.apple.com/textfonts/TTRefMan/RM06/Chap6name.html -// http://www.microsoft.com/typography/otspec/name.htm - -enum { // platformID - STBTT_PLATFORM_ID_UNICODE =0, - STBTT_PLATFORM_ID_MAC =1, - STBTT_PLATFORM_ID_ISO =2, - STBTT_PLATFORM_ID_MICROSOFT =3 -}; - -enum { // encodingID for STBTT_PLATFORM_ID_UNICODE - STBTT_UNICODE_EID_UNICODE_1_0 =0, - STBTT_UNICODE_EID_UNICODE_1_1 =1, - STBTT_UNICODE_EID_ISO_10646 =2, - STBTT_UNICODE_EID_UNICODE_2_0_BMP=3, - STBTT_UNICODE_EID_UNICODE_2_0_FULL=4 -}; - -enum { // encodingID for STBTT_PLATFORM_ID_MICROSOFT - STBTT_MS_EID_SYMBOL =0, - STBTT_MS_EID_UNICODE_BMP =1, - STBTT_MS_EID_SHIFTJIS =2, - STBTT_MS_EID_UNICODE_FULL =10 -}; - -enum { // encodingID for STBTT_PLATFORM_ID_MAC; same as Script Manager codes - STBTT_MAC_EID_ROMAN =0, STBTT_MAC_EID_ARABIC =4, - STBTT_MAC_EID_JAPANESE =1, STBTT_MAC_EID_HEBREW =5, - STBTT_MAC_EID_CHINESE_TRAD =2, STBTT_MAC_EID_GREEK =6, - STBTT_MAC_EID_KOREAN =3, STBTT_MAC_EID_RUSSIAN =7 -}; - -enum { // languageID for STBTT_PLATFORM_ID_MICROSOFT; same as LCID... - // problematic because there are e.g. 16 english LCIDs and 16 arabic LCIDs - STBTT_MS_LANG_ENGLISH =0x0409, STBTT_MS_LANG_ITALIAN =0x0410, - STBTT_MS_LANG_CHINESE =0x0804, STBTT_MS_LANG_JAPANESE =0x0411, - STBTT_MS_LANG_DUTCH =0x0413, STBTT_MS_LANG_KOREAN =0x0412, - STBTT_MS_LANG_FRENCH =0x040c, STBTT_MS_LANG_RUSSIAN =0x0419, - STBTT_MS_LANG_GERMAN =0x0407, STBTT_MS_LANG_SPANISH =0x0409, - STBTT_MS_LANG_HEBREW =0x040d, STBTT_MS_LANG_SWEDISH =0x041D -}; - -enum { // languageID for STBTT_PLATFORM_ID_MAC - STBTT_MAC_LANG_ENGLISH =0 , STBTT_MAC_LANG_JAPANESE =11, - STBTT_MAC_LANG_ARABIC =12, STBTT_MAC_LANG_KOREAN =23, - STBTT_MAC_LANG_DUTCH =4 , STBTT_MAC_LANG_RUSSIAN =32, - STBTT_MAC_LANG_FRENCH =1 , STBTT_MAC_LANG_SPANISH =6 , - STBTT_MAC_LANG_GERMAN =2 , STBTT_MAC_LANG_SWEDISH =5 , - STBTT_MAC_LANG_HEBREW =10, STBTT_MAC_LANG_CHINESE_SIMPLIFIED =33, - STBTT_MAC_LANG_ITALIAN =3 , STBTT_MAC_LANG_CHINESE_TRAD =19 -}; - -#ifdef __cplusplus -} -#endif - -#endif // __STB_INCLUDE_STB_TRUETYPE_H__ - -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -//// -//// IMPLEMENTATION -//// -//// - -#ifdef STB_TRUETYPE_IMPLEMENTATION - -#ifndef STBTT_MAX_OVERSAMPLE -#define STBTT_MAX_OVERSAMPLE 8 -#endif - -#if STBTT_MAX_OVERSAMPLE > 255 -#error "STBTT_MAX_OVERSAMPLE cannot be > 255" -#endif - -typedef int stbtt__test_oversample_pow2[(STBTT_MAX_OVERSAMPLE & (STBTT_MAX_OVERSAMPLE-1)) == 0 ? 1 : -1]; - -#ifndef STBTT_RASTERIZER_VERSION -#define STBTT_RASTERIZER_VERSION 2 -#endif - -#ifdef _MSC_VER -#define STBTT__NOTUSED(v) (void)(v) -#else -#define STBTT__NOTUSED(v) (void)sizeof(v) -#endif - -////////////////////////////////////////////////////////////////////////// -// -// stbtt__buf helpers to parse data from file -// - -static stbtt_uint8 stbtt__buf_get8(stbtt__buf *b) -{ - if (b->cursor >= b->size) - return 0; - return b->data[b->cursor++]; -} - -static stbtt_uint8 stbtt__buf_peek8(stbtt__buf *b) -{ - if (b->cursor >= b->size) - return 0; - return b->data[b->cursor]; -} - -static void stbtt__buf_seek(stbtt__buf *b, int o) -{ - STBTT_assert(!(o > b->size || o < 0)); - b->cursor = (o > b->size || o < 0) ? b->size : o; -} - -static void stbtt__buf_skip(stbtt__buf *b, int o) -{ - stbtt__buf_seek(b, b->cursor + o); -} - -static stbtt_uint32 stbtt__buf_get(stbtt__buf *b, int n) -{ - stbtt_uint32 v = 0; - int i; - STBTT_assert(n >= 1 && n <= 4); - for (i = 0; i < n; i++) - v = (v << 8) | stbtt__buf_get8(b); - return v; -} - -static stbtt__buf stbtt__new_buf(const void *p, size_t size) -{ - stbtt__buf r; - STBTT_assert(size < 0x40000000); - r.data = (stbtt_uint8*) p; - r.size = (int) size; - r.cursor = 0; - return r; -} - -#define stbtt__buf_get16(b) stbtt__buf_get((b), 2) -#define stbtt__buf_get32(b) stbtt__buf_get((b), 4) - -static stbtt__buf stbtt__buf_range(const stbtt__buf *b, int o, int s) -{ - stbtt__buf r = stbtt__new_buf(NULL, 0); - if (o < 0 || s < 0 || o > b->size || s > b->size - o) return r; - r.data = b->data + o; - r.size = s; - return r; -} - -static stbtt__buf stbtt__cff_get_index(stbtt__buf *b) -{ - int count, start, offsize; - start = b->cursor; - count = stbtt__buf_get16(b); - if (count) { - offsize = stbtt__buf_get8(b); - STBTT_assert(offsize >= 1 && offsize <= 4); - stbtt__buf_skip(b, offsize * count); - stbtt__buf_skip(b, stbtt__buf_get(b, offsize) - 1); - } - return stbtt__buf_range(b, start, b->cursor - start); -} - -static stbtt_uint32 stbtt__cff_int(stbtt__buf *b) -{ - int b0 = stbtt__buf_get8(b); - if (b0 >= 32 && b0 <= 246) return b0 - 139; - else if (b0 >= 247 && b0 <= 250) return (b0 - 247)*256 + stbtt__buf_get8(b) + 108; - else if (b0 >= 251 && b0 <= 254) return -(b0 - 251)*256 - stbtt__buf_get8(b) - 108; - else if (b0 == 28) return stbtt__buf_get16(b); - else if (b0 == 29) return stbtt__buf_get32(b); - STBTT_assert(0); - return 0; -} - -static void stbtt__cff_skip_operand(stbtt__buf *b) { - int v, b0 = stbtt__buf_peek8(b); - STBTT_assert(b0 >= 28); - if (b0 == 30) { - stbtt__buf_skip(b, 1); - while (b->cursor < b->size) { - v = stbtt__buf_get8(b); - if ((v & 0xF) == 0xF || (v >> 4) == 0xF) - break; - } - } else { - stbtt__cff_int(b); - } -} - -static stbtt__buf stbtt__dict_get(stbtt__buf *b, int key) -{ - stbtt__buf_seek(b, 0); - while (b->cursor < b->size) { - int start = b->cursor, end, op; - while (stbtt__buf_peek8(b) >= 28) - stbtt__cff_skip_operand(b); - end = b->cursor; - op = stbtt__buf_get8(b); - if (op == 12) op = stbtt__buf_get8(b) | 0x100; - if (op == key) return stbtt__buf_range(b, start, end-start); - } - return stbtt__buf_range(b, 0, 0); -} - -static void stbtt__dict_get_ints(stbtt__buf *b, int key, int outcount, stbtt_uint32 *out) -{ - int i; - stbtt__buf operands = stbtt__dict_get(b, key); - for (i = 0; i < outcount && operands.cursor < operands.size; i++) - out[i] = stbtt__cff_int(&operands); -} - -static int stbtt__cff_index_count(stbtt__buf *b) -{ - stbtt__buf_seek(b, 0); - return stbtt__buf_get16(b); -} - -static stbtt__buf stbtt__cff_index_get(stbtt__buf b, int i) -{ - int count, offsize, start, end; - stbtt__buf_seek(&b, 0); - count = stbtt__buf_get16(&b); - offsize = stbtt__buf_get8(&b); - STBTT_assert(i >= 0 && i < count); - STBTT_assert(offsize >= 1 && offsize <= 4); - stbtt__buf_skip(&b, i*offsize); - start = stbtt__buf_get(&b, offsize); - end = stbtt__buf_get(&b, offsize); - return stbtt__buf_range(&b, 2+(count+1)*offsize+start, end - start); -} - -////////////////////////////////////////////////////////////////////////// -// -// accessors to parse data from file -// - -// on platforms that don't allow misaligned reads, if we want to allow -// truetype fonts that aren't padded to alignment, define ALLOW_UNALIGNED_TRUETYPE - -#define ttBYTE(p) (* (stbtt_uint8 *) (p)) -#define ttCHAR(p) (* (stbtt_int8 *) (p)) -#define ttFixed(p) ttLONG(p) - -static stbtt_uint16 ttUSHORT(stbtt_uint8 *p) { return p[0]*256 + p[1]; } -static stbtt_int16 ttSHORT(stbtt_uint8 *p) { return p[0]*256 + p[1]; } -static stbtt_uint32 ttULONG(stbtt_uint8 *p) { return (p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3]; } -static stbtt_int32 ttLONG(stbtt_uint8 *p) { return (p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3]; } - -#define stbtt_tag4(p,c0,c1,c2,c3) ((p)[0] == (c0) && (p)[1] == (c1) && (p)[2] == (c2) && (p)[3] == (c3)) -#define stbtt_tag(p,str) stbtt_tag4(p,str[0],str[1],str[2],str[3]) - -static int stbtt__isfont(stbtt_uint8 *font) -{ - // check the version number - if (stbtt_tag4(font, '1',0,0,0)) return 1; // TrueType 1 - if (stbtt_tag(font, "typ1")) return 1; // TrueType with type 1 font -- we don't support this! - if (stbtt_tag(font, "OTTO")) return 1; // OpenType with CFF - if (stbtt_tag4(font, 0,1,0,0)) return 1; // OpenType 1.0 - if (stbtt_tag(font, "true")) return 1; // Apple specification for TrueType fonts - return 0; -} - -// @OPTIMIZE: binary search -static stbtt_uint32 stbtt__find_table(stbtt_uint8 *data, stbtt_uint32 fontstart, const char *tag) -{ - stbtt_int32 num_tables = ttUSHORT(data+fontstart+4); - stbtt_uint32 tabledir = fontstart + 12; - stbtt_int32 i; - for (i=0; i < num_tables; ++i) { - stbtt_uint32 loc = tabledir + 16*i; - if (stbtt_tag(data+loc+0, tag)) - return ttULONG(data+loc+8); - } - return 0; -} - -static int stbtt_GetFontOffsetForIndex_internal(unsigned char *font_collection, int index) -{ - // if it's just a font, there's only one valid index - if (stbtt__isfont(font_collection)) - return index == 0 ? 0 : -1; - - // check if it's a TTC - if (stbtt_tag(font_collection, "ttcf")) { - // version 1? - if (ttULONG(font_collection+4) == 0x00010000 || ttULONG(font_collection+4) == 0x00020000) { - stbtt_int32 n = ttLONG(font_collection+8); - if (index >= n) - return -1; - return ttULONG(font_collection+12+index*4); - } - } - return -1; -} - -static int stbtt_GetNumberOfFonts_internal(unsigned char *font_collection) -{ - // if it's just a font, there's only one valid font - if (stbtt__isfont(font_collection)) - return 1; - - // check if it's a TTC - if (stbtt_tag(font_collection, "ttcf")) { - // version 1? - if (ttULONG(font_collection+4) == 0x00010000 || ttULONG(font_collection+4) == 0x00020000) { - return ttLONG(font_collection+8); - } - } - return 0; -} - -static stbtt__buf stbtt__get_subrs(stbtt__buf cff, stbtt__buf fontdict) -{ - stbtt_uint32 subrsoff = 0, private_loc[2] = { 0, 0 }; - stbtt__buf pdict; - stbtt__dict_get_ints(&fontdict, 18, 2, private_loc); - if (!private_loc[1] || !private_loc[0]) return stbtt__new_buf(NULL, 0); - pdict = stbtt__buf_range(&cff, private_loc[1], private_loc[0]); - stbtt__dict_get_ints(&pdict, 19, 1, &subrsoff); - if (!subrsoff) return stbtt__new_buf(NULL, 0); - stbtt__buf_seek(&cff, private_loc[1]+subrsoff); - return stbtt__cff_get_index(&cff); -} - -// since most people won't use this, find this table the first time it's needed -static int stbtt__get_svg(stbtt_fontinfo *info) -{ - stbtt_uint32 t; - if (info->svg < 0) { - t = stbtt__find_table(info->data, info->fontstart, "SVG "); - if (t) { - stbtt_uint32 offset = ttULONG(info->data + t + 2); - info->svg = t + offset; - } else { - info->svg = 0; - } - } - return info->svg; -} - -static int stbtt_InitFont_internal(stbtt_fontinfo *info, unsigned char *data, int fontstart) -{ - stbtt_uint32 cmap, t; - stbtt_int32 i,numTables; - - info->data = data; - info->fontstart = fontstart; - info->cff = stbtt__new_buf(NULL, 0); - - cmap = stbtt__find_table(data, fontstart, "cmap"); // required - info->loca = stbtt__find_table(data, fontstart, "loca"); // required - info->head = stbtt__find_table(data, fontstart, "head"); // required - info->glyf = stbtt__find_table(data, fontstart, "glyf"); // required - info->hhea = stbtt__find_table(data, fontstart, "hhea"); // required - info->hmtx = stbtt__find_table(data, fontstart, "hmtx"); // required - info->kern = stbtt__find_table(data, fontstart, "kern"); // not required - info->gpos = stbtt__find_table(data, fontstart, "GPOS"); // not required - - if (!cmap || !info->head || !info->hhea || !info->hmtx) - return 0; - if (info->glyf) { - // required for truetype - if (!info->loca) return 0; - } else { - // initialization for CFF / Type2 fonts (OTF) - stbtt__buf b, topdict, topdictidx; - stbtt_uint32 cstype = 2, charstrings = 0, fdarrayoff = 0, fdselectoff = 0; - stbtt_uint32 cff; - - cff = stbtt__find_table(data, fontstart, "CFF "); - if (!cff) return 0; - - info->fontdicts = stbtt__new_buf(NULL, 0); - info->fdselect = stbtt__new_buf(NULL, 0); - - // @TODO this should use size from table (not 512MB) - info->cff = stbtt__new_buf(data+cff, 512*1024*1024); - b = info->cff; - - // read the header - stbtt__buf_skip(&b, 2); - stbtt__buf_seek(&b, stbtt__buf_get8(&b)); // hdrsize - - // @TODO the name INDEX could list multiple fonts, - // but we just use the first one. - stbtt__cff_get_index(&b); // name INDEX - topdictidx = stbtt__cff_get_index(&b); - topdict = stbtt__cff_index_get(topdictidx, 0); - stbtt__cff_get_index(&b); // string INDEX - info->gsubrs = stbtt__cff_get_index(&b); - - stbtt__dict_get_ints(&topdict, 17, 1, &charstrings); - stbtt__dict_get_ints(&topdict, 0x100 | 6, 1, &cstype); - stbtt__dict_get_ints(&topdict, 0x100 | 36, 1, &fdarrayoff); - stbtt__dict_get_ints(&topdict, 0x100 | 37, 1, &fdselectoff); - info->subrs = stbtt__get_subrs(b, topdict); - - // we only support Type 2 charstrings - if (cstype != 2) return 0; - if (charstrings == 0) return 0; - - if (fdarrayoff) { - // looks like a CID font - if (!fdselectoff) return 0; - stbtt__buf_seek(&b, fdarrayoff); - info->fontdicts = stbtt__cff_get_index(&b); - info->fdselect = stbtt__buf_range(&b, fdselectoff, b.size-fdselectoff); - } - - stbtt__buf_seek(&b, charstrings); - info->charstrings = stbtt__cff_get_index(&b); - } - - t = stbtt__find_table(data, fontstart, "maxp"); - if (t) - info->numGlyphs = ttUSHORT(data+t+4); - else - info->numGlyphs = 0xffff; - - info->svg = -1; - - // find a cmap encoding table we understand *now* to avoid searching - // later. (todo: could make this installable) - // the same regardless of glyph. - numTables = ttUSHORT(data + cmap + 2); - info->index_map = 0; - for (i=0; i < numTables; ++i) { - stbtt_uint32 encoding_record = cmap + 4 + 8 * i; - // find an encoding we understand: - switch(ttUSHORT(data+encoding_record)) { - case STBTT_PLATFORM_ID_MICROSOFT: - switch (ttUSHORT(data+encoding_record+2)) { - case STBTT_MS_EID_UNICODE_BMP: - case STBTT_MS_EID_UNICODE_FULL: - // MS/Unicode - info->index_map = cmap + ttULONG(data+encoding_record+4); - break; - } - break; - case STBTT_PLATFORM_ID_UNICODE: - // Mac/iOS has these - // all the encodingIDs are unicode, so we don't bother to check it - info->index_map = cmap + ttULONG(data+encoding_record+4); - break; - } - } - if (info->index_map == 0) - return 0; - - info->indexToLocFormat = ttUSHORT(data+info->head + 50); - return 1; -} - -STBTT_DEF int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint) -{ - stbtt_uint8 *data = info->data; - stbtt_uint32 index_map = info->index_map; - - stbtt_uint16 format = ttUSHORT(data + index_map + 0); - if (format == 0) { // apple byte encoding - stbtt_int32 bytes = ttUSHORT(data + index_map + 2); - if (unicode_codepoint < bytes-6) - return ttBYTE(data + index_map + 6 + unicode_codepoint); - return 0; - } else if (format == 6) { - stbtt_uint32 first = ttUSHORT(data + index_map + 6); - stbtt_uint32 count = ttUSHORT(data + index_map + 8); - if ((stbtt_uint32) unicode_codepoint >= first && (stbtt_uint32) unicode_codepoint < first+count) - return ttUSHORT(data + index_map + 10 + (unicode_codepoint - first)*2); - return 0; - } else if (format == 2) { - STBTT_assert(0); // @TODO: high-byte mapping for japanese/chinese/korean - return 0; - } else if (format == 4) { // standard mapping for windows fonts: binary search collection of ranges - stbtt_uint16 segcount = ttUSHORT(data+index_map+6) >> 1; - stbtt_uint16 searchRange = ttUSHORT(data+index_map+8) >> 1; - stbtt_uint16 entrySelector = ttUSHORT(data+index_map+10); - stbtt_uint16 rangeShift = ttUSHORT(data+index_map+12) >> 1; - - // do a binary search of the segments - stbtt_uint32 endCount = index_map + 14; - stbtt_uint32 search = endCount; - - if (unicode_codepoint > 0xffff) - return 0; - - // they lie from endCount .. endCount + segCount - // but searchRange is the nearest power of two, so... - if (unicode_codepoint >= ttUSHORT(data + search + rangeShift*2)) - search += rangeShift*2; - - // now decrement to bias correctly to find smallest - search -= 2; - while (entrySelector) { - stbtt_uint16 end; - searchRange >>= 1; - end = ttUSHORT(data + search + searchRange*2); - if (unicode_codepoint > end) - search += searchRange*2; - --entrySelector; - } - search += 2; - - { - stbtt_uint16 offset, start, last; - stbtt_uint16 item = (stbtt_uint16) ((search - endCount) >> 1); - - start = ttUSHORT(data + index_map + 14 + segcount*2 + 2 + 2*item); - last = ttUSHORT(data + endCount + 2*item); - if (unicode_codepoint < start || unicode_codepoint > last) - return 0; - - offset = ttUSHORT(data + index_map + 14 + segcount*6 + 2 + 2*item); - if (offset == 0) - return (stbtt_uint16) (unicode_codepoint + ttSHORT(data + index_map + 14 + segcount*4 + 2 + 2*item)); - - return ttUSHORT(data + offset + (unicode_codepoint-start)*2 + index_map + 14 + segcount*6 + 2 + 2*item); - } - } else if (format == 12 || format == 13) { - stbtt_uint32 ngroups = ttULONG(data+index_map+12); - stbtt_int32 low,high; - low = 0; high = (stbtt_int32)ngroups; - // Binary search the right group. - while (low < high) { - stbtt_int32 mid = low + ((high-low) >> 1); // rounds down, so low <= mid < high - stbtt_uint32 start_char = ttULONG(data+index_map+16+mid*12); - stbtt_uint32 end_char = ttULONG(data+index_map+16+mid*12+4); - if ((stbtt_uint32) unicode_codepoint < start_char) - high = mid; - else if ((stbtt_uint32) unicode_codepoint > end_char) - low = mid+1; - else { - stbtt_uint32 start_glyph = ttULONG(data+index_map+16+mid*12+8); - if (format == 12) - return start_glyph + unicode_codepoint-start_char; - else // format == 13 - return start_glyph; - } - } - return 0; // not found - } - // @TODO - STBTT_assert(0); - return 0; -} - -STBTT_DEF int stbtt_GetCodepointShape(const stbtt_fontinfo *info, int unicode_codepoint, stbtt_vertex **vertices) -{ - return stbtt_GetGlyphShape(info, stbtt_FindGlyphIndex(info, unicode_codepoint), vertices); -} - -static void stbtt_setvertex(stbtt_vertex *v, stbtt_uint8 type, stbtt_int32 x, stbtt_int32 y, stbtt_int32 cx, stbtt_int32 cy) -{ - v->type = type; - v->x = (stbtt_int16) x; - v->y = (stbtt_int16) y; - v->cx = (stbtt_int16) cx; - v->cy = (stbtt_int16) cy; -} - -static int stbtt__GetGlyfOffset(const stbtt_fontinfo *info, int glyph_index) -{ - int g1,g2; - - STBTT_assert(!info->cff.size); - - if (glyph_index >= info->numGlyphs) return -1; // glyph index out of range - if (info->indexToLocFormat >= 2) return -1; // unknown index->glyph map format - - if (info->indexToLocFormat == 0) { - g1 = info->glyf + ttUSHORT(info->data + info->loca + glyph_index * 2) * 2; - g2 = info->glyf + ttUSHORT(info->data + info->loca + glyph_index * 2 + 2) * 2; - } else { - g1 = info->glyf + ttULONG (info->data + info->loca + glyph_index * 4); - g2 = info->glyf + ttULONG (info->data + info->loca + glyph_index * 4 + 4); - } - - return g1==g2 ? -1 : g1; // if length is 0, return -1 -} - -static int stbtt__GetGlyphInfoT2(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1); - -STBTT_DEF int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1) -{ - if (info->cff.size) { - stbtt__GetGlyphInfoT2(info, glyph_index, x0, y0, x1, y1); - } else { - int g = stbtt__GetGlyfOffset(info, glyph_index); - if (g < 0) return 0; - - if (x0) *x0 = ttSHORT(info->data + g + 2); - if (y0) *y0 = ttSHORT(info->data + g + 4); - if (x1) *x1 = ttSHORT(info->data + g + 6); - if (y1) *y1 = ttSHORT(info->data + g + 8); - } - return 1; -} - -STBTT_DEF int stbtt_GetCodepointBox(const stbtt_fontinfo *info, int codepoint, int *x0, int *y0, int *x1, int *y1) -{ - return stbtt_GetGlyphBox(info, stbtt_FindGlyphIndex(info,codepoint), x0,y0,x1,y1); -} - -STBTT_DEF int stbtt_IsGlyphEmpty(const stbtt_fontinfo *info, int glyph_index) -{ - stbtt_int16 numberOfContours; - int g; - if (info->cff.size) - return stbtt__GetGlyphInfoT2(info, glyph_index, NULL, NULL, NULL, NULL) == 0; - g = stbtt__GetGlyfOffset(info, glyph_index); - if (g < 0) return 1; - numberOfContours = ttSHORT(info->data + g); - return numberOfContours == 0; -} - -static int stbtt__close_shape(stbtt_vertex *vertices, int num_vertices, int was_off, int start_off, - stbtt_int32 sx, stbtt_int32 sy, stbtt_int32 scx, stbtt_int32 scy, stbtt_int32 cx, stbtt_int32 cy) -{ - if (start_off) { - if (was_off) - stbtt_setvertex(&vertices[num_vertices++], STBTT_vcurve, (cx+scx)>>1, (cy+scy)>>1, cx,cy); - stbtt_setvertex(&vertices[num_vertices++], STBTT_vcurve, sx,sy,scx,scy); - } else { - if (was_off) - stbtt_setvertex(&vertices[num_vertices++], STBTT_vcurve,sx,sy,cx,cy); - else - stbtt_setvertex(&vertices[num_vertices++], STBTT_vline,sx,sy,0,0); - } - return num_vertices; -} - -static int stbtt__GetGlyphShapeTT(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **pvertices) -{ - stbtt_int16 numberOfContours; - stbtt_uint8 *endPtsOfContours; - stbtt_uint8 *data = info->data; - stbtt_vertex *vertices=0; - int num_vertices=0; - int g = stbtt__GetGlyfOffset(info, glyph_index); - - *pvertices = NULL; - - if (g < 0) return 0; - - numberOfContours = ttSHORT(data + g); - - if (numberOfContours > 0) { - stbtt_uint8 flags=0,flagcount; - stbtt_int32 ins, i,j=0,m,n, next_move, was_off=0, off, start_off=0; - stbtt_int32 x,y,cx,cy,sx,sy, scx,scy; - stbtt_uint8 *points; - endPtsOfContours = (data + g + 10); - ins = ttUSHORT(data + g + 10 + numberOfContours * 2); - points = data + g + 10 + numberOfContours * 2 + 2 + ins; - - n = 1+ttUSHORT(endPtsOfContours + numberOfContours*2-2); - - m = n + 2*numberOfContours; // a loose bound on how many vertices we might need - vertices = (stbtt_vertex *) STBTT_malloc(m * sizeof(vertices[0]), info->userdata); - if (vertices == 0) - return 0; - - next_move = 0; - flagcount=0; - - // in first pass, we load uninterpreted data into the allocated array - // above, shifted to the end of the array so we won't overwrite it when - // we create our final data starting from the front - - off = m - n; // starting offset for uninterpreted data, regardless of how m ends up being calculated - - // first load flags - - for (i=0; i < n; ++i) { - if (flagcount == 0) { - flags = *points++; - if (flags & 8) - flagcount = *points++; - } else - --flagcount; - vertices[off+i].type = flags; - } - - // now load x coordinates - x=0; - for (i=0; i < n; ++i) { - flags = vertices[off+i].type; - if (flags & 2) { - stbtt_int16 dx = *points++; - x += (flags & 16) ? dx : -dx; // ??? - } else { - if (!(flags & 16)) { - x = x + (stbtt_int16) (points[0]*256 + points[1]); - points += 2; - } - } - vertices[off+i].x = (stbtt_int16) x; - } - - // now load y coordinates - y=0; - for (i=0; i < n; ++i) { - flags = vertices[off+i].type; - if (flags & 4) { - stbtt_int16 dy = *points++; - y += (flags & 32) ? dy : -dy; // ??? - } else { - if (!(flags & 32)) { - y = y + (stbtt_int16) (points[0]*256 + points[1]); - points += 2; - } - } - vertices[off+i].y = (stbtt_int16) y; - } - - // now convert them to our format - num_vertices=0; - sx = sy = cx = cy = scx = scy = 0; - for (i=0; i < n; ++i) { - flags = vertices[off+i].type; - x = (stbtt_int16) vertices[off+i].x; - y = (stbtt_int16) vertices[off+i].y; - - if (next_move == i) { - if (i != 0) - num_vertices = stbtt__close_shape(vertices, num_vertices, was_off, start_off, sx,sy,scx,scy,cx,cy); - - // now start the new one - start_off = !(flags & 1); - if (start_off) { - // if we start off with an off-curve point, then when we need to find a point on the curve - // where we can start, and we need to save some state for when we wraparound. - scx = x; - scy = y; - if (!(vertices[off+i+1].type & 1)) { - // next point is also a curve point, so interpolate an on-point curve - sx = (x + (stbtt_int32) vertices[off+i+1].x) >> 1; - sy = (y + (stbtt_int32) vertices[off+i+1].y) >> 1; - } else { - // otherwise just use the next point as our start point - sx = (stbtt_int32) vertices[off+i+1].x; - sy = (stbtt_int32) vertices[off+i+1].y; - ++i; // we're using point i+1 as the starting point, so skip it - } - } else { - sx = x; - sy = y; - } - stbtt_setvertex(&vertices[num_vertices++], STBTT_vmove,sx,sy,0,0); - was_off = 0; - next_move = 1 + ttUSHORT(endPtsOfContours+j*2); - ++j; - } else { - if (!(flags & 1)) { // if it's a curve - if (was_off) // two off-curve control points in a row means interpolate an on-curve midpoint - stbtt_setvertex(&vertices[num_vertices++], STBTT_vcurve, (cx+x)>>1, (cy+y)>>1, cx, cy); - cx = x; - cy = y; - was_off = 1; - } else { - if (was_off) - stbtt_setvertex(&vertices[num_vertices++], STBTT_vcurve, x,y, cx, cy); - else - stbtt_setvertex(&vertices[num_vertices++], STBTT_vline, x,y,0,0); - was_off = 0; - } - } - } - num_vertices = stbtt__close_shape(vertices, num_vertices, was_off, start_off, sx,sy,scx,scy,cx,cy); - } else if (numberOfContours < 0) { - // Compound shapes. - int more = 1; - stbtt_uint8 *comp = data + g + 10; - num_vertices = 0; - vertices = 0; - while (more) { - stbtt_uint16 flags, gidx; - int comp_num_verts = 0, i; - stbtt_vertex *comp_verts = 0, *tmp = 0; - float mtx[6] = {1,0,0,1,0,0}, m, n; - - flags = ttSHORT(comp); comp+=2; - gidx = ttSHORT(comp); comp+=2; - - if (flags & 2) { // XY values - if (flags & 1) { // shorts - mtx[4] = ttSHORT(comp); comp+=2; - mtx[5] = ttSHORT(comp); comp+=2; - } else { - mtx[4] = ttCHAR(comp); comp+=1; - mtx[5] = ttCHAR(comp); comp+=1; - } - } - else { - // @TODO handle matching point - STBTT_assert(0); - } - if (flags & (1<<3)) { // WE_HAVE_A_SCALE - mtx[0] = mtx[3] = ttSHORT(comp)/16384.0f; comp+=2; - mtx[1] = mtx[2] = 0; - } else if (flags & (1<<6)) { // WE_HAVE_AN_X_AND_YSCALE - mtx[0] = ttSHORT(comp)/16384.0f; comp+=2; - mtx[1] = mtx[2] = 0; - mtx[3] = ttSHORT(comp)/16384.0f; comp+=2; - } else if (flags & (1<<7)) { // WE_HAVE_A_TWO_BY_TWO - mtx[0] = ttSHORT(comp)/16384.0f; comp+=2; - mtx[1] = ttSHORT(comp)/16384.0f; comp+=2; - mtx[2] = ttSHORT(comp)/16384.0f; comp+=2; - mtx[3] = ttSHORT(comp)/16384.0f; comp+=2; - } - - // Find transformation scales. - m = (float) STBTT_sqrt(mtx[0]*mtx[0] + mtx[1]*mtx[1]); - n = (float) STBTT_sqrt(mtx[2]*mtx[2] + mtx[3]*mtx[3]); - - // Get indexed glyph. - comp_num_verts = stbtt_GetGlyphShape(info, gidx, &comp_verts); - if (comp_num_verts > 0) { - // Transform vertices. - for (i = 0; i < comp_num_verts; ++i) { - stbtt_vertex* v = &comp_verts[i]; - stbtt_vertex_type x,y; - x=v->x; y=v->y; - v->x = (stbtt_vertex_type)(m * (mtx[0]*x + mtx[2]*y + mtx[4])); - v->y = (stbtt_vertex_type)(n * (mtx[1]*x + mtx[3]*y + mtx[5])); - x=v->cx; y=v->cy; - v->cx = (stbtt_vertex_type)(m * (mtx[0]*x + mtx[2]*y + mtx[4])); - v->cy = (stbtt_vertex_type)(n * (mtx[1]*x + mtx[3]*y + mtx[5])); - } - // Append vertices. - tmp = (stbtt_vertex*)STBTT_malloc((num_vertices+comp_num_verts)*sizeof(stbtt_vertex), info->userdata); - if (!tmp) { - if (vertices) STBTT_free(vertices, info->userdata); - if (comp_verts) STBTT_free(comp_verts, info->userdata); - return 0; - } - if (num_vertices > 0 && vertices) STBTT_memcpy(tmp, vertices, num_vertices*sizeof(stbtt_vertex)); - STBTT_memcpy(tmp+num_vertices, comp_verts, comp_num_verts*sizeof(stbtt_vertex)); - if (vertices) STBTT_free(vertices, info->userdata); - vertices = tmp; - STBTT_free(comp_verts, info->userdata); - num_vertices += comp_num_verts; - } - // More components ? - more = flags & (1<<5); - } - } else { - // numberOfCounters == 0, do nothing - } - - *pvertices = vertices; - return num_vertices; -} - -typedef struct -{ - int bounds; - int started; - float first_x, first_y; - float x, y; - stbtt_int32 min_x, max_x, min_y, max_y; - - stbtt_vertex *pvertices; - int num_vertices; -} stbtt__csctx; - -#define STBTT__CSCTX_INIT(bounds) {bounds,0, 0,0, 0,0, 0,0,0,0, NULL, 0} - -static void stbtt__track_vertex(stbtt__csctx *c, stbtt_int32 x, stbtt_int32 y) -{ - if (x > c->max_x || !c->started) c->max_x = x; - if (y > c->max_y || !c->started) c->max_y = y; - if (x < c->min_x || !c->started) c->min_x = x; - if (y < c->min_y || !c->started) c->min_y = y; - c->started = 1; -} - -static void stbtt__csctx_v(stbtt__csctx *c, stbtt_uint8 type, stbtt_int32 x, stbtt_int32 y, stbtt_int32 cx, stbtt_int32 cy, stbtt_int32 cx1, stbtt_int32 cy1) -{ - if (c->bounds) { - stbtt__track_vertex(c, x, y); - if (type == STBTT_vcubic) { - stbtt__track_vertex(c, cx, cy); - stbtt__track_vertex(c, cx1, cy1); - } - } else { - stbtt_setvertex(&c->pvertices[c->num_vertices], type, x, y, cx, cy); - c->pvertices[c->num_vertices].cx1 = (stbtt_int16) cx1; - c->pvertices[c->num_vertices].cy1 = (stbtt_int16) cy1; - } - c->num_vertices++; -} - -static void stbtt__csctx_close_shape(stbtt__csctx *ctx) -{ - if (ctx->first_x != ctx->x || ctx->first_y != ctx->y) - stbtt__csctx_v(ctx, STBTT_vline, (int)ctx->first_x, (int)ctx->first_y, 0, 0, 0, 0); -} - -static void stbtt__csctx_rmove_to(stbtt__csctx *ctx, float dx, float dy) -{ - stbtt__csctx_close_shape(ctx); - ctx->first_x = ctx->x = ctx->x + dx; - ctx->first_y = ctx->y = ctx->y + dy; - stbtt__csctx_v(ctx, STBTT_vmove, (int)ctx->x, (int)ctx->y, 0, 0, 0, 0); -} - -static void stbtt__csctx_rline_to(stbtt__csctx *ctx, float dx, float dy) -{ - ctx->x += dx; - ctx->y += dy; - stbtt__csctx_v(ctx, STBTT_vline, (int)ctx->x, (int)ctx->y, 0, 0, 0, 0); -} - -static void stbtt__csctx_rccurve_to(stbtt__csctx *ctx, float dx1, float dy1, float dx2, float dy2, float dx3, float dy3) -{ - float cx1 = ctx->x + dx1; - float cy1 = ctx->y + dy1; - float cx2 = cx1 + dx2; - float cy2 = cy1 + dy2; - ctx->x = cx2 + dx3; - ctx->y = cy2 + dy3; - stbtt__csctx_v(ctx, STBTT_vcubic, (int)ctx->x, (int)ctx->y, (int)cx1, (int)cy1, (int)cx2, (int)cy2); -} - -static stbtt__buf stbtt__get_subr(stbtt__buf idx, int n) -{ - int count = stbtt__cff_index_count(&idx); - int bias = 107; - if (count >= 33900) - bias = 32768; - else if (count >= 1240) - bias = 1131; - n += bias; - if (n < 0 || n >= count) - return stbtt__new_buf(NULL, 0); - return stbtt__cff_index_get(idx, n); -} - -static stbtt__buf stbtt__cid_get_glyph_subrs(const stbtt_fontinfo *info, int glyph_index) -{ - stbtt__buf fdselect = info->fdselect; - int nranges, start, end, v, fmt, fdselector = -1, i; - - stbtt__buf_seek(&fdselect, 0); - fmt = stbtt__buf_get8(&fdselect); - if (fmt == 0) { - // untested - stbtt__buf_skip(&fdselect, glyph_index); - fdselector = stbtt__buf_get8(&fdselect); - } else if (fmt == 3) { - nranges = stbtt__buf_get16(&fdselect); - start = stbtt__buf_get16(&fdselect); - for (i = 0; i < nranges; i++) { - v = stbtt__buf_get8(&fdselect); - end = stbtt__buf_get16(&fdselect); - if (glyph_index >= start && glyph_index < end) { - fdselector = v; - break; - } - start = end; - } - } - if (fdselector == -1) stbtt__new_buf(NULL, 0); - return stbtt__get_subrs(info->cff, stbtt__cff_index_get(info->fontdicts, fdselector)); -} - -static int stbtt__run_charstring(const stbtt_fontinfo *info, int glyph_index, stbtt__csctx *c) -{ - int in_header = 1, maskbits = 0, subr_stack_height = 0, sp = 0, v, i, b0; - int has_subrs = 0, clear_stack; - float s[48]; - stbtt__buf subr_stack[10], subrs = info->subrs, b; - float f; - -#define STBTT__CSERR(s) (0) - - // this currently ignores the initial width value, which isn't needed if we have hmtx - b = stbtt__cff_index_get(info->charstrings, glyph_index); - while (b.cursor < b.size) { - i = 0; - clear_stack = 1; - b0 = stbtt__buf_get8(&b); - switch (b0) { - // @TODO implement hinting - case 0x13: // hintmask - case 0x14: // cntrmask - if (in_header) - maskbits += (sp / 2); // implicit "vstem" - in_header = 0; - stbtt__buf_skip(&b, (maskbits + 7) / 8); - break; - - case 0x01: // hstem - case 0x03: // vstem - case 0x12: // hstemhm - case 0x17: // vstemhm - maskbits += (sp / 2); - break; - - case 0x15: // rmoveto - in_header = 0; - if (sp < 2) return STBTT__CSERR("rmoveto stack"); - stbtt__csctx_rmove_to(c, s[sp-2], s[sp-1]); - break; - case 0x04: // vmoveto - in_header = 0; - if (sp < 1) return STBTT__CSERR("vmoveto stack"); - stbtt__csctx_rmove_to(c, 0, s[sp-1]); - break; - case 0x16: // hmoveto - in_header = 0; - if (sp < 1) return STBTT__CSERR("hmoveto stack"); - stbtt__csctx_rmove_to(c, s[sp-1], 0); - break; - - case 0x05: // rlineto - if (sp < 2) return STBTT__CSERR("rlineto stack"); - for (; i + 1 < sp; i += 2) - stbtt__csctx_rline_to(c, s[i], s[i+1]); - break; - - // hlineto/vlineto and vhcurveto/hvcurveto alternate horizontal and vertical - // starting from a different place. - - case 0x07: // vlineto - if (sp < 1) return STBTT__CSERR("vlineto stack"); - goto vlineto; - case 0x06: // hlineto - if (sp < 1) return STBTT__CSERR("hlineto stack"); - for (;;) { - if (i >= sp) break; - stbtt__csctx_rline_to(c, s[i], 0); - i++; - vlineto: - if (i >= sp) break; - stbtt__csctx_rline_to(c, 0, s[i]); - i++; - } - break; - - case 0x1F: // hvcurveto - if (sp < 4) return STBTT__CSERR("hvcurveto stack"); - goto hvcurveto; - case 0x1E: // vhcurveto - if (sp < 4) return STBTT__CSERR("vhcurveto stack"); - for (;;) { - if (i + 3 >= sp) break; - stbtt__csctx_rccurve_to(c, 0, s[i], s[i+1], s[i+2], s[i+3], (sp - i == 5) ? s[i + 4] : 0.0f); - i += 4; - hvcurveto: - if (i + 3 >= sp) break; - stbtt__csctx_rccurve_to(c, s[i], 0, s[i+1], s[i+2], (sp - i == 5) ? s[i+4] : 0.0f, s[i+3]); - i += 4; - } - break; - - case 0x08: // rrcurveto - if (sp < 6) return STBTT__CSERR("rcurveline stack"); - for (; i + 5 < sp; i += 6) - stbtt__csctx_rccurve_to(c, s[i], s[i+1], s[i+2], s[i+3], s[i+4], s[i+5]); - break; - - case 0x18: // rcurveline - if (sp < 8) return STBTT__CSERR("rcurveline stack"); - for (; i + 5 < sp - 2; i += 6) - stbtt__csctx_rccurve_to(c, s[i], s[i+1], s[i+2], s[i+3], s[i+4], s[i+5]); - if (i + 1 >= sp) return STBTT__CSERR("rcurveline stack"); - stbtt__csctx_rline_to(c, s[i], s[i+1]); - break; - - case 0x19: // rlinecurve - if (sp < 8) return STBTT__CSERR("rlinecurve stack"); - for (; i + 1 < sp - 6; i += 2) - stbtt__csctx_rline_to(c, s[i], s[i+1]); - if (i + 5 >= sp) return STBTT__CSERR("rlinecurve stack"); - stbtt__csctx_rccurve_to(c, s[i], s[i+1], s[i+2], s[i+3], s[i+4], s[i+5]); - break; - - case 0x1A: // vvcurveto - case 0x1B: // hhcurveto - if (sp < 4) return STBTT__CSERR("(vv|hh)curveto stack"); - f = 0.0; - if (sp & 1) { f = s[i]; i++; } - for (; i + 3 < sp; i += 4) { - if (b0 == 0x1B) - stbtt__csctx_rccurve_to(c, s[i], f, s[i+1], s[i+2], s[i+3], 0.0); - else - stbtt__csctx_rccurve_to(c, f, s[i], s[i+1], s[i+2], 0.0, s[i+3]); - f = 0.0; - } - break; - - case 0x0A: // callsubr - if (!has_subrs) { - if (info->fdselect.size) - subrs = stbtt__cid_get_glyph_subrs(info, glyph_index); - has_subrs = 1; - } - // FALLTHROUGH - case 0x1D: // callgsubr - if (sp < 1) return STBTT__CSERR("call(g|)subr stack"); - v = (int) s[--sp]; - if (subr_stack_height >= 10) return STBTT__CSERR("recursion limit"); - subr_stack[subr_stack_height++] = b; - b = stbtt__get_subr(b0 == 0x0A ? subrs : info->gsubrs, v); - if (b.size == 0) return STBTT__CSERR("subr not found"); - b.cursor = 0; - clear_stack = 0; - break; - - case 0x0B: // return - if (subr_stack_height <= 0) return STBTT__CSERR("return outside subr"); - b = subr_stack[--subr_stack_height]; - clear_stack = 0; - break; - - case 0x0E: // endchar - stbtt__csctx_close_shape(c); - return 1; - - case 0x0C: { // two-byte escape - float dx1, dx2, dx3, dx4, dx5, dx6, dy1, dy2, dy3, dy4, dy5, dy6; - float dx, dy; - int b1 = stbtt__buf_get8(&b); - switch (b1) { - // @TODO These "flex" implementations ignore the flex-depth and resolution, - // and always draw beziers. - case 0x22: // hflex - if (sp < 7) return STBTT__CSERR("hflex stack"); - dx1 = s[0]; - dx2 = s[1]; - dy2 = s[2]; - dx3 = s[3]; - dx4 = s[4]; - dx5 = s[5]; - dx6 = s[6]; - stbtt__csctx_rccurve_to(c, dx1, 0, dx2, dy2, dx3, 0); - stbtt__csctx_rccurve_to(c, dx4, 0, dx5, -dy2, dx6, 0); - break; - - case 0x23: // flex - if (sp < 13) return STBTT__CSERR("flex stack"); - dx1 = s[0]; - dy1 = s[1]; - dx2 = s[2]; - dy2 = s[3]; - dx3 = s[4]; - dy3 = s[5]; - dx4 = s[6]; - dy4 = s[7]; - dx5 = s[8]; - dy5 = s[9]; - dx6 = s[10]; - dy6 = s[11]; - //fd is s[12] - stbtt__csctx_rccurve_to(c, dx1, dy1, dx2, dy2, dx3, dy3); - stbtt__csctx_rccurve_to(c, dx4, dy4, dx5, dy5, dx6, dy6); - break; - - case 0x24: // hflex1 - if (sp < 9) return STBTT__CSERR("hflex1 stack"); - dx1 = s[0]; - dy1 = s[1]; - dx2 = s[2]; - dy2 = s[3]; - dx3 = s[4]; - dx4 = s[5]; - dx5 = s[6]; - dy5 = s[7]; - dx6 = s[8]; - stbtt__csctx_rccurve_to(c, dx1, dy1, dx2, dy2, dx3, 0); - stbtt__csctx_rccurve_to(c, dx4, 0, dx5, dy5, dx6, -(dy1+dy2+dy5)); - break; - - case 0x25: // flex1 - if (sp < 11) return STBTT__CSERR("flex1 stack"); - dx1 = s[0]; - dy1 = s[1]; - dx2 = s[2]; - dy2 = s[3]; - dx3 = s[4]; - dy3 = s[5]; - dx4 = s[6]; - dy4 = s[7]; - dx5 = s[8]; - dy5 = s[9]; - dx6 = dy6 = s[10]; - dx = dx1+dx2+dx3+dx4+dx5; - dy = dy1+dy2+dy3+dy4+dy5; - if (STBTT_fabs(dx) > STBTT_fabs(dy)) - dy6 = -dy; - else - dx6 = -dx; - stbtt__csctx_rccurve_to(c, dx1, dy1, dx2, dy2, dx3, dy3); - stbtt__csctx_rccurve_to(c, dx4, dy4, dx5, dy5, dx6, dy6); - break; - - default: - return STBTT__CSERR("unimplemented"); - } - } break; - - default: - if (b0 != 255 && b0 != 28 && b0 < 32) - return STBTT__CSERR("reserved operator"); - - // push immediate - if (b0 == 255) { - f = (float)(stbtt_int32)stbtt__buf_get32(&b) / 0x10000; - } else { - stbtt__buf_skip(&b, -1); - f = (float)(stbtt_int16)stbtt__cff_int(&b); - } - if (sp >= 48) return STBTT__CSERR("push stack overflow"); - s[sp++] = f; - clear_stack = 0; - break; - } - if (clear_stack) sp = 0; - } - return STBTT__CSERR("no endchar"); - -#undef STBTT__CSERR -} - -static int stbtt__GetGlyphShapeT2(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **pvertices) -{ - // runs the charstring twice, once to count and once to output (to avoid realloc) - stbtt__csctx count_ctx = STBTT__CSCTX_INIT(1); - stbtt__csctx output_ctx = STBTT__CSCTX_INIT(0); - if (stbtt__run_charstring(info, glyph_index, &count_ctx)) { - *pvertices = (stbtt_vertex*)STBTT_malloc(count_ctx.num_vertices*sizeof(stbtt_vertex), info->userdata); - output_ctx.pvertices = *pvertices; - if (stbtt__run_charstring(info, glyph_index, &output_ctx)) { - STBTT_assert(output_ctx.num_vertices == count_ctx.num_vertices); - return output_ctx.num_vertices; - } - } - *pvertices = NULL; - return 0; -} - -static int stbtt__GetGlyphInfoT2(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1) -{ - stbtt__csctx c = STBTT__CSCTX_INIT(1); - int r = stbtt__run_charstring(info, glyph_index, &c); - if (x0) *x0 = r ? c.min_x : 0; - if (y0) *y0 = r ? c.min_y : 0; - if (x1) *x1 = r ? c.max_x : 0; - if (y1) *y1 = r ? c.max_y : 0; - return r ? c.num_vertices : 0; -} - -STBTT_DEF int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **pvertices) -{ - if (!info->cff.size) - return stbtt__GetGlyphShapeTT(info, glyph_index, pvertices); - else - return stbtt__GetGlyphShapeT2(info, glyph_index, pvertices); -} - -STBTT_DEF void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_index, int *advanceWidth, int *leftSideBearing) -{ - stbtt_uint16 numOfLongHorMetrics = ttUSHORT(info->data+info->hhea + 34); - if (glyph_index < numOfLongHorMetrics) { - if (advanceWidth) *advanceWidth = ttSHORT(info->data + info->hmtx + 4*glyph_index); - if (leftSideBearing) *leftSideBearing = ttSHORT(info->data + info->hmtx + 4*glyph_index + 2); - } else { - if (advanceWidth) *advanceWidth = ttSHORT(info->data + info->hmtx + 4*(numOfLongHorMetrics-1)); - if (leftSideBearing) *leftSideBearing = ttSHORT(info->data + info->hmtx + 4*numOfLongHorMetrics + 2*(glyph_index - numOfLongHorMetrics)); - } -} - -STBTT_DEF int stbtt_GetKerningTableLength(const stbtt_fontinfo *info) -{ - stbtt_uint8 *data = info->data + info->kern; - - // we only look at the first table. it must be 'horizontal' and format 0. - if (!info->kern) - return 0; - if (ttUSHORT(data+2) < 1) // number of tables, need at least 1 - return 0; - if (ttUSHORT(data+8) != 1) // horizontal flag must be set in format - return 0; - - return ttUSHORT(data+10); -} - -STBTT_DEF int stbtt_GetKerningTable(const stbtt_fontinfo *info, stbtt_kerningentry* table, int table_length) -{ - stbtt_uint8 *data = info->data + info->kern; - int k, length; - - // we only look at the first table. it must be 'horizontal' and format 0. - if (!info->kern) - return 0; - if (ttUSHORT(data+2) < 1) // number of tables, need at least 1 - return 0; - if (ttUSHORT(data+8) != 1) // horizontal flag must be set in format - return 0; - - length = ttUSHORT(data+10); - if (table_length < length) - length = table_length; - - for (k = 0; k < length; k++) - { - table[k].glyph1 = ttUSHORT(data+18+(k*6)); - table[k].glyph2 = ttUSHORT(data+20+(k*6)); - table[k].advance = ttSHORT(data+22+(k*6)); - } - - return length; -} - -static int stbtt__GetGlyphKernInfoAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2) -{ - stbtt_uint8 *data = info->data + info->kern; - stbtt_uint32 needle, straw; - int l, r, m; - - // we only look at the first table. it must be 'horizontal' and format 0. - if (!info->kern) - return 0; - if (ttUSHORT(data+2) < 1) // number of tables, need at least 1 - return 0; - if (ttUSHORT(data+8) != 1) // horizontal flag must be set in format - return 0; - - l = 0; - r = ttUSHORT(data+10) - 1; - needle = glyph1 << 16 | glyph2; - while (l <= r) { - m = (l + r) >> 1; - straw = ttULONG(data+18+(m*6)); // note: unaligned read - if (needle < straw) - r = m - 1; - else if (needle > straw) - l = m + 1; - else - return ttSHORT(data+22+(m*6)); - } - return 0; -} - -static stbtt_int32 stbtt__GetCoverageIndex(stbtt_uint8 *coverageTable, int glyph) -{ - stbtt_uint16 coverageFormat = ttUSHORT(coverageTable); - switch (coverageFormat) { - case 1: { - stbtt_uint16 glyphCount = ttUSHORT(coverageTable + 2); - - // Binary search. - stbtt_int32 l=0, r=glyphCount-1, m; - int straw, needle=glyph; - while (l <= r) { - stbtt_uint8 *glyphArray = coverageTable + 4; - stbtt_uint16 glyphID; - m = (l + r) >> 1; - glyphID = ttUSHORT(glyphArray + 2 * m); - straw = glyphID; - if (needle < straw) - r = m - 1; - else if (needle > straw) - l = m + 1; - else { - return m; - } - } - break; - } - - case 2: { - stbtt_uint16 rangeCount = ttUSHORT(coverageTable + 2); - stbtt_uint8 *rangeArray = coverageTable + 4; - - // Binary search. - stbtt_int32 l=0, r=rangeCount-1, m; - int strawStart, strawEnd, needle=glyph; - while (l <= r) { - stbtt_uint8 *rangeRecord; - m = (l + r) >> 1; - rangeRecord = rangeArray + 6 * m; - strawStart = ttUSHORT(rangeRecord); - strawEnd = ttUSHORT(rangeRecord + 2); - if (needle < strawStart) - r = m - 1; - else if (needle > strawEnd) - l = m + 1; - else { - stbtt_uint16 startCoverageIndex = ttUSHORT(rangeRecord + 4); - return startCoverageIndex + glyph - strawStart; - } - } - break; - } - - default: return -1; // unsupported - } - - return -1; -} - -static stbtt_int32 stbtt__GetGlyphClass(stbtt_uint8 *classDefTable, int glyph) -{ - stbtt_uint16 classDefFormat = ttUSHORT(classDefTable); - switch (classDefFormat) - { - case 1: { - stbtt_uint16 startGlyphID = ttUSHORT(classDefTable + 2); - stbtt_uint16 glyphCount = ttUSHORT(classDefTable + 4); - stbtt_uint8 *classDef1ValueArray = classDefTable + 6; - - if (glyph >= startGlyphID && glyph < startGlyphID + glyphCount) - return (stbtt_int32)ttUSHORT(classDef1ValueArray + 2 * (glyph - startGlyphID)); - break; - } - - case 2: { - stbtt_uint16 classRangeCount = ttUSHORT(classDefTable + 2); - stbtt_uint8 *classRangeRecords = classDefTable + 4; - - // Binary search. - stbtt_int32 l=0, r=classRangeCount-1, m; - int strawStart, strawEnd, needle=glyph; - while (l <= r) { - stbtt_uint8 *classRangeRecord; - m = (l + r) >> 1; - classRangeRecord = classRangeRecords + 6 * m; - strawStart = ttUSHORT(classRangeRecord); - strawEnd = ttUSHORT(classRangeRecord + 2); - if (needle < strawStart) - r = m - 1; - else if (needle > strawEnd) - l = m + 1; - else - return (stbtt_int32)ttUSHORT(classRangeRecord + 4); - } - break; - } - - default: - return -1; // Unsupported definition type, return an error. - } - - // "All glyphs not assigned to a class fall into class 0". (OpenType spec) - return 0; -} - -// Define to STBTT_assert(x) if you want to break on unimplemented formats. -#define STBTT_GPOS_TODO_assert(x) - -static stbtt_int32 stbtt__GetGlyphGPOSInfoAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2) -{ - stbtt_uint16 lookupListOffset; - stbtt_uint8 *lookupList; - stbtt_uint16 lookupCount; - stbtt_uint8 *data; - stbtt_int32 i, sti; - - if (!info->gpos) return 0; - - data = info->data + info->gpos; - - if (ttUSHORT(data+0) != 1) return 0; // Major version 1 - if (ttUSHORT(data+2) != 0) return 0; // Minor version 0 - - lookupListOffset = ttUSHORT(data+8); - lookupList = data + lookupListOffset; - lookupCount = ttUSHORT(lookupList); - - for (i=0; i= pairSetCount) return 0; - - needle=glyph2; - r=pairValueCount-1; - l=0; - - // Binary search. - while (l <= r) { - stbtt_uint16 secondGlyph; - stbtt_uint8 *pairValue; - m = (l + r) >> 1; - pairValue = pairValueArray + (2 + valueRecordPairSizeInBytes) * m; - secondGlyph = ttUSHORT(pairValue); - straw = secondGlyph; - if (needle < straw) - r = m - 1; - else if (needle > straw) - l = m + 1; - else { - stbtt_int16 xAdvance = ttSHORT(pairValue + 2); - return xAdvance; - } - } - } else - return 0; - break; - } - - case 2: { - stbtt_uint16 valueFormat1 = ttUSHORT(table + 4); - stbtt_uint16 valueFormat2 = ttUSHORT(table + 6); - if (valueFormat1 == 4 && valueFormat2 == 0) { // Support more formats? - stbtt_uint16 classDef1Offset = ttUSHORT(table + 8); - stbtt_uint16 classDef2Offset = ttUSHORT(table + 10); - int glyph1class = stbtt__GetGlyphClass(table + classDef1Offset, glyph1); - int glyph2class = stbtt__GetGlyphClass(table + classDef2Offset, glyph2); - - stbtt_uint16 class1Count = ttUSHORT(table + 12); - stbtt_uint16 class2Count = ttUSHORT(table + 14); - stbtt_uint8 *class1Records, *class2Records; - stbtt_int16 xAdvance; - - if (glyph1class < 0 || glyph1class >= class1Count) return 0; // malformed - if (glyph2class < 0 || glyph2class >= class2Count) return 0; // malformed - - class1Records = table + 16; - class2Records = class1Records + 2 * (glyph1class * class2Count); - xAdvance = ttSHORT(class2Records + 2 * glyph2class); - return xAdvance; - } else - return 0; - break; - } - - default: - return 0; // Unsupported position format - } - } - } - - return 0; -} - -STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int g1, int g2) -{ - int xAdvance = 0; - - if (info->gpos) - xAdvance += stbtt__GetGlyphGPOSInfoAdvance(info, g1, g2); - else if (info->kern) - xAdvance += stbtt__GetGlyphKernInfoAdvance(info, g1, g2); - - return xAdvance; -} - -STBTT_DEF int stbtt_GetCodepointKernAdvance(const stbtt_fontinfo *info, int ch1, int ch2) -{ - if (!info->kern && !info->gpos) // if no kerning table, don't waste time looking up both codepoint->glyphs - return 0; - return stbtt_GetGlyphKernAdvance(info, stbtt_FindGlyphIndex(info,ch1), stbtt_FindGlyphIndex(info,ch2)); -} - -STBTT_DEF void stbtt_GetCodepointHMetrics(const stbtt_fontinfo *info, int codepoint, int *advanceWidth, int *leftSideBearing) -{ - stbtt_GetGlyphHMetrics(info, stbtt_FindGlyphIndex(info,codepoint), advanceWidth, leftSideBearing); -} - -STBTT_DEF void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, int *descent, int *lineGap) -{ - if (ascent ) *ascent = ttSHORT(info->data+info->hhea + 4); - if (descent) *descent = ttSHORT(info->data+info->hhea + 6); - if (lineGap) *lineGap = ttSHORT(info->data+info->hhea + 8); -} - -STBTT_DEF int stbtt_GetFontVMetricsOS2(const stbtt_fontinfo *info, int *typoAscent, int *typoDescent, int *typoLineGap) -{ - int tab = stbtt__find_table(info->data, info->fontstart, "OS/2"); - if (!tab) - return 0; - if (typoAscent ) *typoAscent = ttSHORT(info->data+tab + 68); - if (typoDescent) *typoDescent = ttSHORT(info->data+tab + 70); - if (typoLineGap) *typoLineGap = ttSHORT(info->data+tab + 72); - return 1; -} - -STBTT_DEF void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int *x1, int *y1) -{ - *x0 = ttSHORT(info->data + info->head + 36); - *y0 = ttSHORT(info->data + info->head + 38); - *x1 = ttSHORT(info->data + info->head + 40); - *y1 = ttSHORT(info->data + info->head + 42); -} - -STBTT_DEF float stbtt_ScaleForPixelHeight(const stbtt_fontinfo *info, float height) -{ - int fheight = ttSHORT(info->data + info->hhea + 4) - ttSHORT(info->data + info->hhea + 6); - return (float) height / fheight; -} - -STBTT_DEF float stbtt_ScaleForMappingEmToPixels(const stbtt_fontinfo *info, float pixels) -{ - int unitsPerEm = ttUSHORT(info->data + info->head + 18); - return pixels / unitsPerEm; -} - -STBTT_DEF void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *v) -{ - STBTT_free(v, info->userdata); -} - -STBTT_DEF stbtt_uint8 *stbtt_FindSVGDoc(const stbtt_fontinfo *info, int gl) -{ - int i; - stbtt_uint8 *data = info->data; - stbtt_uint8 *svg_doc_list = data + stbtt__get_svg((stbtt_fontinfo *) info); - - int numEntries = ttUSHORT(svg_doc_list); - stbtt_uint8 *svg_docs = svg_doc_list + 2; - - for(i=0; i= ttUSHORT(svg_doc)) && (gl <= ttUSHORT(svg_doc + 2))) - return svg_doc; - } - return 0; -} - -STBTT_DEF int stbtt_GetGlyphSVG(const stbtt_fontinfo *info, int gl, const char **svg) -{ - stbtt_uint8 *data = info->data; - stbtt_uint8 *svg_doc; - - if (info->svg == 0) - return 0; - - svg_doc = stbtt_FindSVGDoc(info, gl); - if (svg_doc != NULL) { - *svg = (char *) data + info->svg + ttULONG(svg_doc + 4); - return ttULONG(svg_doc + 8); - } else { - return 0; - } -} - -STBTT_DEF int stbtt_GetCodepointSVG(const stbtt_fontinfo *info, int unicode_codepoint, const char **svg) -{ - return stbtt_GetGlyphSVG(info, stbtt_FindGlyphIndex(info, unicode_codepoint), svg); -} - -////////////////////////////////////////////////////////////////////////////// -// -// antialiasing software rasterizer -// - -STBTT_DEF void stbtt_GetGlyphBitmapBoxSubpixel(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y,float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1) -{ - int x0=0,y0=0,x1,y1; // =0 suppresses compiler warning - if (!stbtt_GetGlyphBox(font, glyph, &x0,&y0,&x1,&y1)) { - // e.g. space character - if (ix0) *ix0 = 0; - if (iy0) *iy0 = 0; - if (ix1) *ix1 = 0; - if (iy1) *iy1 = 0; - } else { - // move to integral bboxes (treating pixels as little squares, what pixels get touched)? - if (ix0) *ix0 = STBTT_ifloor( x0 * scale_x + shift_x); - if (iy0) *iy0 = STBTT_ifloor(-y1 * scale_y + shift_y); - if (ix1) *ix1 = STBTT_iceil ( x1 * scale_x + shift_x); - if (iy1) *iy1 = STBTT_iceil (-y0 * scale_y + shift_y); - } -} - -STBTT_DEF void stbtt_GetGlyphBitmapBox(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1) -{ - stbtt_GetGlyphBitmapBoxSubpixel(font, glyph, scale_x, scale_y,0.0f,0.0f, ix0, iy0, ix1, iy1); -} - -STBTT_DEF void stbtt_GetCodepointBitmapBoxSubpixel(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1) -{ - stbtt_GetGlyphBitmapBoxSubpixel(font, stbtt_FindGlyphIndex(font,codepoint), scale_x, scale_y,shift_x,shift_y, ix0,iy0,ix1,iy1); -} - -STBTT_DEF void stbtt_GetCodepointBitmapBox(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1) -{ - stbtt_GetCodepointBitmapBoxSubpixel(font, codepoint, scale_x, scale_y,0.0f,0.0f, ix0,iy0,ix1,iy1); -} - -////////////////////////////////////////////////////////////////////////////// -// -// Rasterizer - -typedef struct stbtt__hheap_chunk -{ - struct stbtt__hheap_chunk *next; -} stbtt__hheap_chunk; - -typedef struct stbtt__hheap -{ - struct stbtt__hheap_chunk *head; - void *first_free; - int num_remaining_in_head_chunk; -} stbtt__hheap; - -static void *stbtt__hheap_alloc(stbtt__hheap *hh, size_t size, void *userdata) -{ - if (hh->first_free) { - void *p = hh->first_free; - hh->first_free = * (void **) p; - return p; - } else { - if (hh->num_remaining_in_head_chunk == 0) { - int count = (size < 32 ? 2000 : size < 128 ? 800 : 100); - stbtt__hheap_chunk *c = (stbtt__hheap_chunk *) STBTT_malloc(sizeof(stbtt__hheap_chunk) + size * count, userdata); - if (c == NULL) - return NULL; - c->next = hh->head; - hh->head = c; - hh->num_remaining_in_head_chunk = count; - } - --hh->num_remaining_in_head_chunk; - return (char *) (hh->head) + sizeof(stbtt__hheap_chunk) + size * hh->num_remaining_in_head_chunk; - } -} - -static void stbtt__hheap_free(stbtt__hheap *hh, void *p) -{ - *(void **) p = hh->first_free; - hh->first_free = p; -} - -static void stbtt__hheap_cleanup(stbtt__hheap *hh, void *userdata) -{ - stbtt__hheap_chunk *c = hh->head; - while (c) { - stbtt__hheap_chunk *n = c->next; - STBTT_free(c, userdata); - c = n; - } -} - -typedef struct stbtt__edge { - float x0,y0, x1,y1; - int invert; -} stbtt__edge; - - -typedef struct stbtt__active_edge -{ - struct stbtt__active_edge *next; - #if STBTT_RASTERIZER_VERSION==1 - int x,dx; - float ey; - int direction; - #elif STBTT_RASTERIZER_VERSION==2 - float fx,fdx,fdy; - float direction; - float sy; - float ey; - #else - #error "Unrecognized value of STBTT_RASTERIZER_VERSION" - #endif -} stbtt__active_edge; - -#if STBTT_RASTERIZER_VERSION == 1 -#define STBTT_FIXSHIFT 10 -#define STBTT_FIX (1 << STBTT_FIXSHIFT) -#define STBTT_FIXMASK (STBTT_FIX-1) - -static stbtt__active_edge *stbtt__new_active(stbtt__hheap *hh, stbtt__edge *e, int off_x, float start_point, void *userdata) -{ - stbtt__active_edge *z = (stbtt__active_edge *) stbtt__hheap_alloc(hh, sizeof(*z), userdata); - float dxdy = (e->x1 - e->x0) / (e->y1 - e->y0); - STBTT_assert(z != NULL); - if (!z) return z; - - // round dx down to avoid overshooting - if (dxdy < 0) - z->dx = -STBTT_ifloor(STBTT_FIX * -dxdy); - else - z->dx = STBTT_ifloor(STBTT_FIX * dxdy); - - z->x = STBTT_ifloor(STBTT_FIX * e->x0 + z->dx * (start_point - e->y0)); // use z->dx so when we offset later it's by the same amount - z->x -= off_x * STBTT_FIX; - - z->ey = e->y1; - z->next = 0; - z->direction = e->invert ? 1 : -1; - return z; -} -#elif STBTT_RASTERIZER_VERSION == 2 -static stbtt__active_edge *stbtt__new_active(stbtt__hheap *hh, stbtt__edge *e, int off_x, float start_point, void *userdata) -{ - stbtt__active_edge *z = (stbtt__active_edge *) stbtt__hheap_alloc(hh, sizeof(*z), userdata); - float dxdy = (e->x1 - e->x0) / (e->y1 - e->y0); - STBTT_assert(z != NULL); - //STBTT_assert(e->y0 <= start_point); - if (!z) return z; - z->fdx = dxdy; - z->fdy = dxdy != 0.0f ? (1.0f/dxdy) : 0.0f; - z->fx = e->x0 + dxdy * (start_point - e->y0); - z->fx -= off_x; - z->direction = e->invert ? 1.0f : -1.0f; - z->sy = e->y0; - z->ey = e->y1; - z->next = 0; - return z; -} -#else -#error "Unrecognized value of STBTT_RASTERIZER_VERSION" -#endif - -#if STBTT_RASTERIZER_VERSION == 1 -// note: this routine clips fills that extend off the edges... ideally this -// wouldn't happen, but it could happen if the truetype glyph bounding boxes -// are wrong, or if the user supplies a too-small bitmap -static void stbtt__fill_active_edges(unsigned char *scanline, int len, stbtt__active_edge *e, int max_weight) -{ - // non-zero winding fill - int x0=0, w=0; - - while (e) { - if (w == 0) { - // if we're currently at zero, we need to record the edge start point - x0 = e->x; w += e->direction; - } else { - int x1 = e->x; w += e->direction; - // if we went to zero, we need to draw - if (w == 0) { - int i = x0 >> STBTT_FIXSHIFT; - int j = x1 >> STBTT_FIXSHIFT; - - if (i < len && j >= 0) { - if (i == j) { - // x0,x1 are the same pixel, so compute combined coverage - scanline[i] = scanline[i] + (stbtt_uint8) ((x1 - x0) * max_weight >> STBTT_FIXSHIFT); - } else { - if (i >= 0) // add antialiasing for x0 - scanline[i] = scanline[i] + (stbtt_uint8) (((STBTT_FIX - (x0 & STBTT_FIXMASK)) * max_weight) >> STBTT_FIXSHIFT); - else - i = -1; // clip - - if (j < len) // add antialiasing for x1 - scanline[j] = scanline[j] + (stbtt_uint8) (((x1 & STBTT_FIXMASK) * max_weight) >> STBTT_FIXSHIFT); - else - j = len; // clip - - for (++i; i < j; ++i) // fill pixels between x0 and x1 - scanline[i] = scanline[i] + (stbtt_uint8) max_weight; - } - } - } - } - - e = e->next; - } -} - -static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e, int n, int vsubsample, int off_x, int off_y, void *userdata) -{ - stbtt__hheap hh = { 0, 0, 0 }; - stbtt__active_edge *active = NULL; - int y,j=0; - int max_weight = (255 / vsubsample); // weight per vertical scanline - int s; // vertical subsample index - unsigned char scanline_data[512], *scanline; - - if (result->w > 512) - scanline = (unsigned char *) STBTT_malloc(result->w, userdata); - else - scanline = scanline_data; - - y = off_y * vsubsample; - e[n].y0 = (off_y + result->h) * (float) vsubsample + 1; - - while (j < result->h) { - STBTT_memset(scanline, 0, result->w); - for (s=0; s < vsubsample; ++s) { - // find center of pixel for this scanline - float scan_y = y + 0.5f; - stbtt__active_edge **step = &active; - - // update all active edges; - // remove all active edges that terminate before the center of this scanline - while (*step) { - stbtt__active_edge * z = *step; - if (z->ey <= scan_y) { - *step = z->next; // delete from list - STBTT_assert(z->direction); - z->direction = 0; - stbtt__hheap_free(&hh, z); - } else { - z->x += z->dx; // advance to position for current scanline - step = &((*step)->next); // advance through list - } - } - - // resort the list if needed - for(;;) { - int changed=0; - step = &active; - while (*step && (*step)->next) { - if ((*step)->x > (*step)->next->x) { - stbtt__active_edge *t = *step; - stbtt__active_edge *q = t->next; - - t->next = q->next; - q->next = t; - *step = q; - changed = 1; - } - step = &(*step)->next; - } - if (!changed) break; - } - - // insert all edges that start before the center of this scanline -- omit ones that also end on this scanline - while (e->y0 <= scan_y) { - if (e->y1 > scan_y) { - stbtt__active_edge *z = stbtt__new_active(&hh, e, off_x, scan_y, userdata); - if (z != NULL) { - // find insertion point - if (active == NULL) - active = z; - else if (z->x < active->x) { - // insert at front - z->next = active; - active = z; - } else { - // find thing to insert AFTER - stbtt__active_edge *p = active; - while (p->next && p->next->x < z->x) - p = p->next; - // at this point, p->next->x is NOT < z->x - z->next = p->next; - p->next = z; - } - } - } - ++e; - } - - // now process all active edges in XOR fashion - if (active) - stbtt__fill_active_edges(scanline, result->w, active, max_weight); - - ++y; - } - STBTT_memcpy(result->pixels + j * result->stride, scanline, result->w); - ++j; - } - - stbtt__hheap_cleanup(&hh, userdata); - - if (scanline != scanline_data) - STBTT_free(scanline, userdata); -} - -#elif STBTT_RASTERIZER_VERSION == 2 - -// the edge passed in here does not cross the vertical line at x or the vertical line at x+1 -// (i.e. it has already been clipped to those) -static void stbtt__handle_clipped_edge(float *scanline, int x, stbtt__active_edge *e, float x0, float y0, float x1, float y1) -{ - if (y0 == y1) return; - STBTT_assert(y0 < y1); - STBTT_assert(e->sy <= e->ey); - if (y0 > e->ey) return; - if (y1 < e->sy) return; - if (y0 < e->sy) { - x0 += (x1-x0) * (e->sy - y0) / (y1-y0); - y0 = e->sy; - } - if (y1 > e->ey) { - x1 += (x1-x0) * (e->ey - y1) / (y1-y0); - y1 = e->ey; - } - - if (x0 == x) - STBTT_assert(x1 <= x+1); - else if (x0 == x+1) - STBTT_assert(x1 >= x); - else if (x0 <= x) - STBTT_assert(x1 <= x); - else if (x0 >= x+1) - STBTT_assert(x1 >= x+1); - else - STBTT_assert(x1 >= x && x1 <= x+1); - - if (x0 <= x && x1 <= x) - scanline[x] += e->direction * (y1-y0); - else if (x0 >= x+1 && x1 >= x+1) - ; - else { - STBTT_assert(x0 >= x && x0 <= x+1 && x1 >= x && x1 <= x+1); - scanline[x] += e->direction * (y1-y0) * (1-((x0-x)+(x1-x))/2); // coverage = 1 - average x position - } -} - -static float stbtt__sized_trapezoid_area(float height, float top_width, float bottom_width) -{ - STBTT_assert(top_width >= 0); - STBTT_assert(bottom_width >= 0); - return (top_width + bottom_width) / 2.0f * height; -} - -static float stbtt__position_trapezoid_area(float height, float tx0, float tx1, float bx0, float bx1) -{ - return stbtt__sized_trapezoid_area(height, tx1 - tx0, bx1 - bx0); -} - -static float stbtt__sized_triangle_area(float height, float width) -{ - return height * width / 2; -} - -static void stbtt__fill_active_edges_new(float *scanline, float *scanline_fill, int len, stbtt__active_edge *e, float y_top) -{ - float y_bottom = y_top+1; - - while (e) { - // brute force every pixel - - // compute intersection points with top & bottom - STBTT_assert(e->ey >= y_top); - - if (e->fdx == 0) { - float x0 = e->fx; - if (x0 < len) { - if (x0 >= 0) { - stbtt__handle_clipped_edge(scanline,(int) x0,e, x0,y_top, x0,y_bottom); - stbtt__handle_clipped_edge(scanline_fill-1,(int) x0+1,e, x0,y_top, x0,y_bottom); - } else { - stbtt__handle_clipped_edge(scanline_fill-1,0,e, x0,y_top, x0,y_bottom); - } - } - } else { - float x0 = e->fx; - float dx = e->fdx; - float xb = x0 + dx; - float x_top, x_bottom; - float sy0,sy1; - float dy = e->fdy; - STBTT_assert(e->sy <= y_bottom && e->ey >= y_top); - - // compute endpoints of line segment clipped to this scanline (if the - // line segment starts on this scanline. x0 is the intersection of the - // line with y_top, but that may be off the line segment. - if (e->sy > y_top) { - x_top = x0 + dx * (e->sy - y_top); - sy0 = e->sy; - } else { - x_top = x0; - sy0 = y_top; - } - if (e->ey < y_bottom) { - x_bottom = x0 + dx * (e->ey - y_top); - sy1 = e->ey; - } else { - x_bottom = xb; - sy1 = y_bottom; - } - - if (x_top >= 0 && x_bottom >= 0 && x_top < len && x_bottom < len) { - // from here on, we don't have to range check x values - - if ((int) x_top == (int) x_bottom) { - float height; - // simple case, only spans one pixel - int x = (int) x_top; - height = (sy1 - sy0) * e->direction; - STBTT_assert(x >= 0 && x < len); - scanline[x] += stbtt__position_trapezoid_area(height, x_top, x+1.0f, x_bottom, x+1.0f); - scanline_fill[x] += height; // everything right of this pixel is filled - } else { - int x,x1,x2; - float y_crossing, y_final, step, sign, area; - // covers 2+ pixels - if (x_top > x_bottom) { - // flip scanline vertically; signed area is the same - float t; - sy0 = y_bottom - (sy0 - y_top); - sy1 = y_bottom - (sy1 - y_top); - t = sy0, sy0 = sy1, sy1 = t; - t = x_bottom, x_bottom = x_top, x_top = t; - dx = -dx; - dy = -dy; - t = x0, x0 = xb, xb = t; - } - STBTT_assert(dy >= 0); - STBTT_assert(dx >= 0); - - x1 = (int) x_top; - x2 = (int) x_bottom; - // compute intersection with y axis at x1+1 - y_crossing = y_top + dy * (x1+1 - x0); - - // compute intersection with y axis at x2 - y_final = y_top + dy * (x2 - x0); - - // x1 x_top x2 x_bottom - // y_top +------|-----+------------+------------+--------|---+------------+ - // | | | | | | - // | | | | | | - // sy0 | Txxxxx|............|............|............|............| - // y_crossing | *xxxxx.......|............|............|............| - // | | xxxxx..|............|............|............| - // | | /- xx*xxxx........|............|............| - // | | dy < | xxxxxx..|............|............| - // y_final | | \- | xx*xxx.........|............| - // sy1 | | | | xxxxxB...|............| - // | | | | | | - // | | | | | | - // y_bottom +------------+------------+------------+------------+------------+ - // - // goal is to measure the area covered by '.' in each pixel - - // if x2 is right at the right edge of x1, y_crossing can blow up, github #1057 - // @TODO: maybe test against sy1 rather than y_bottom? - if (y_crossing > y_bottom) - y_crossing = y_bottom; - - sign = e->direction; - - // area of the rectangle covered from sy0..y_crossing - area = sign * (y_crossing-sy0); - - // area of the triangle (x_top,sy0), (x1+1,sy0), (x1+1,y_crossing) - scanline[x1] += stbtt__sized_triangle_area(area, x1+1 - x_top); - - // check if final y_crossing is blown up; no test case for this - if (y_final > y_bottom) { - y_final = y_bottom; - dy = (y_final - y_crossing ) / (x2 - (x1+1)); // if denom=0, y_final = y_crossing, so y_final <= y_bottom - } - - // in second pixel, area covered by line segment found in first pixel - // is always a rectangle 1 wide * the height of that line segment; this - // is exactly what the variable 'area' stores. it also gets a contribution - // from the line segment within it. the THIRD pixel will get the first - // pixel's rectangle contribution, the second pixel's rectangle contribution, - // and its own contribution. the 'own contribution' is the same in every pixel except - // the leftmost and rightmost, a trapezoid that slides down in each pixel. - // the second pixel's contribution to the third pixel will be the - // rectangle 1 wide times the height change in the second pixel, which is dy. - - step = sign * dy * 1; // dy is dy/dx, change in y for every 1 change in x, - // which multiplied by 1-pixel-width is how much pixel area changes for each step in x - // so the area advances by 'step' every time - - for (x = x1+1; x < x2; ++x) { - scanline[x] += area + step/2; // area of trapezoid is 1*step/2 - area += step; - } - STBTT_assert(STBTT_fabs(area) <= 1.01f); // accumulated error from area += step unless we round step down - STBTT_assert(sy1 > y_final-0.01f); - - // area covered in the last pixel is the rectangle from all the pixels to the left, - // plus the trapezoid filled by the line segment in this pixel all the way to the right edge - scanline[x2] += area + sign * stbtt__position_trapezoid_area(sy1-y_final, (float) x2, x2+1.0f, x_bottom, x2+1.0f); - - // the rest of the line is filled based on the total height of the line segment in this pixel - scanline_fill[x2] += sign * (sy1-sy0); - } - } else { - // if edge goes outside of box we're drawing, we require - // clipping logic. since this does not match the intended use - // of this library, we use a different, very slow brute - // force implementation - // note though that this does happen some of the time because - // x_top and x_bottom can be extrapolated at the top & bottom of - // the shape and actually lie outside the bounding box - int x; - for (x=0; x < len; ++x) { - // cases: - // - // there can be up to two intersections with the pixel. any intersection - // with left or right edges can be handled by splitting into two (or three) - // regions. intersections with top & bottom do not necessitate case-wise logic. - // - // the old way of doing this found the intersections with the left & right edges, - // then used some simple logic to produce up to three segments in sorted order - // from top-to-bottom. however, this had a problem: if an x edge was epsilon - // across the x border, then the corresponding y position might not be distinct - // from the other y segment, and it might ignored as an empty segment. to avoid - // that, we need to explicitly produce segments based on x positions. - - // rename variables to clearly-defined pairs - float y0 = y_top; - float x1 = (float) (x); - float x2 = (float) (x+1); - float x3 = xb; - float y3 = y_bottom; - - // x = e->x + e->dx * (y-y_top) - // (y-y_top) = (x - e->x) / e->dx - // y = (x - e->x) / e->dx + y_top - float y1 = (x - x0) / dx + y_top; - float y2 = (x+1 - x0) / dx + y_top; - - if (x0 < x1 && x3 > x2) { // three segments descending down-right - stbtt__handle_clipped_edge(scanline,x,e, x0,y0, x1,y1); - stbtt__handle_clipped_edge(scanline,x,e, x1,y1, x2,y2); - stbtt__handle_clipped_edge(scanline,x,e, x2,y2, x3,y3); - } else if (x3 < x1 && x0 > x2) { // three segments descending down-left - stbtt__handle_clipped_edge(scanline,x,e, x0,y0, x2,y2); - stbtt__handle_clipped_edge(scanline,x,e, x2,y2, x1,y1); - stbtt__handle_clipped_edge(scanline,x,e, x1,y1, x3,y3); - } else if (x0 < x1 && x3 > x1) { // two segments across x, down-right - stbtt__handle_clipped_edge(scanline,x,e, x0,y0, x1,y1); - stbtt__handle_clipped_edge(scanline,x,e, x1,y1, x3,y3); - } else if (x3 < x1 && x0 > x1) { // two segments across x, down-left - stbtt__handle_clipped_edge(scanline,x,e, x0,y0, x1,y1); - stbtt__handle_clipped_edge(scanline,x,e, x1,y1, x3,y3); - } else if (x0 < x2 && x3 > x2) { // two segments across x+1, down-right - stbtt__handle_clipped_edge(scanline,x,e, x0,y0, x2,y2); - stbtt__handle_clipped_edge(scanline,x,e, x2,y2, x3,y3); - } else if (x3 < x2 && x0 > x2) { // two segments across x+1, down-left - stbtt__handle_clipped_edge(scanline,x,e, x0,y0, x2,y2); - stbtt__handle_clipped_edge(scanline,x,e, x2,y2, x3,y3); - } else { // one segment - stbtt__handle_clipped_edge(scanline,x,e, x0,y0, x3,y3); - } - } - } - } - e = e->next; - } -} - -// directly AA rasterize edges w/o supersampling -static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e, int n, int vsubsample, int off_x, int off_y, void *userdata) -{ - stbtt__hheap hh = { 0, 0, 0 }; - stbtt__active_edge *active = NULL; - int y,j=0, i; - float scanline_data[129], *scanline, *scanline2; - - STBTT__NOTUSED(vsubsample); - - if (result->w > 64) - scanline = (float *) STBTT_malloc((result->w*2+1) * sizeof(float), userdata); - else - scanline = scanline_data; - - scanline2 = scanline + result->w; - - y = off_y; - e[n].y0 = (float) (off_y + result->h) + 1; - - while (j < result->h) { - // find center of pixel for this scanline - float scan_y_top = y + 0.0f; - float scan_y_bottom = y + 1.0f; - stbtt__active_edge **step = &active; - - STBTT_memset(scanline , 0, result->w*sizeof(scanline[0])); - STBTT_memset(scanline2, 0, (result->w+1)*sizeof(scanline[0])); - - // update all active edges; - // remove all active edges that terminate before the top of this scanline - while (*step) { - stbtt__active_edge * z = *step; - if (z->ey <= scan_y_top) { - *step = z->next; // delete from list - STBTT_assert(z->direction); - z->direction = 0; - stbtt__hheap_free(&hh, z); - } else { - step = &((*step)->next); // advance through list - } - } - - // insert all edges that start before the bottom of this scanline - while (e->y0 <= scan_y_bottom) { - if (e->y0 != e->y1) { - stbtt__active_edge *z = stbtt__new_active(&hh, e, off_x, scan_y_top, userdata); - if (z != NULL) { - if (j == 0 && off_y != 0) { - if (z->ey < scan_y_top) { - // this can happen due to subpixel positioning and some kind of fp rounding error i think - z->ey = scan_y_top; - } - } - STBTT_assert(z->ey >= scan_y_top); // if we get really unlucky a tiny bit of an edge can be out of bounds - // insert at front - z->next = active; - active = z; - } - } - ++e; - } - - // now process all active edges - if (active) - stbtt__fill_active_edges_new(scanline, scanline2+1, result->w, active, scan_y_top); - - { - float sum = 0; - for (i=0; i < result->w; ++i) { - float k; - int m; - sum += scanline2[i]; - k = scanline[i] + sum; - k = (float) STBTT_fabs(k)*255 + 0.5f; - m = (int) k; - if (m > 255) m = 255; - result->pixels[j*result->stride + i] = (unsigned char) m; - } - } - // advance all the edges - step = &active; - while (*step) { - stbtt__active_edge *z = *step; - z->fx += z->fdx; // advance to position for current scanline - step = &((*step)->next); // advance through list - } - - ++y; - ++j; - } - - stbtt__hheap_cleanup(&hh, userdata); - - if (scanline != scanline_data) - STBTT_free(scanline, userdata); -} -#else -#error "Unrecognized value of STBTT_RASTERIZER_VERSION" -#endif - -#define STBTT__COMPARE(a,b) ((a)->y0 < (b)->y0) - -static void stbtt__sort_edges_ins_sort(stbtt__edge *p, int n) -{ - int i,j; - for (i=1; i < n; ++i) { - stbtt__edge t = p[i], *a = &t; - j = i; - while (j > 0) { - stbtt__edge *b = &p[j-1]; - int c = STBTT__COMPARE(a,b); - if (!c) break; - p[j] = p[j-1]; - --j; - } - if (i != j) - p[j] = t; - } -} - -static void stbtt__sort_edges_quicksort(stbtt__edge *p, int n) -{ - /* threshold for transitioning to insertion sort */ - while (n > 12) { - stbtt__edge t; - int c01,c12,c,m,i,j; - - /* compute median of three */ - m = n >> 1; - c01 = STBTT__COMPARE(&p[0],&p[m]); - c12 = STBTT__COMPARE(&p[m],&p[n-1]); - /* if 0 >= mid >= end, or 0 < mid < end, then use mid */ - if (c01 != c12) { - /* otherwise, we'll need to swap something else to middle */ - int z; - c = STBTT__COMPARE(&p[0],&p[n-1]); - /* 0>mid && midn => n; 0 0 */ - /* 0n: 0>n => 0; 0 n */ - z = (c == c12) ? 0 : n-1; - t = p[z]; - p[z] = p[m]; - p[m] = t; - } - /* now p[m] is the median-of-three */ - /* swap it to the beginning so it won't move around */ - t = p[0]; - p[0] = p[m]; - p[m] = t; - - /* partition loop */ - i=1; - j=n-1; - for(;;) { - /* handling of equality is crucial here */ - /* for sentinels & efficiency with duplicates */ - for (;;++i) { - if (!STBTT__COMPARE(&p[i], &p[0])) break; - } - for (;;--j) { - if (!STBTT__COMPARE(&p[0], &p[j])) break; - } - /* make sure we haven't crossed */ - if (i >= j) break; - t = p[i]; - p[i] = p[j]; - p[j] = t; - - ++i; - --j; - } - /* recurse on smaller side, iterate on larger */ - if (j < (n-i)) { - stbtt__sort_edges_quicksort(p,j); - p = p+i; - n = n-i; - } else { - stbtt__sort_edges_quicksort(p+i, n-i); - n = j; - } - } -} - -static void stbtt__sort_edges(stbtt__edge *p, int n) -{ - stbtt__sort_edges_quicksort(p, n); - stbtt__sort_edges_ins_sort(p, n); -} - -typedef struct -{ - float x,y; -} stbtt__point; - -static void stbtt__rasterize(stbtt__bitmap *result, stbtt__point *pts, int *wcount, int windings, float scale_x, float scale_y, float shift_x, float shift_y, int off_x, int off_y, int invert, void *userdata) -{ - float y_scale_inv = invert ? -scale_y : scale_y; - stbtt__edge *e; - int n,i,j,k,m; -#if STBTT_RASTERIZER_VERSION == 1 - int vsubsample = result->h < 8 ? 15 : 5; -#elif STBTT_RASTERIZER_VERSION == 2 - int vsubsample = 1; -#else - #error "Unrecognized value of STBTT_RASTERIZER_VERSION" -#endif - // vsubsample should divide 255 evenly; otherwise we won't reach full opacity - - // now we have to blow out the windings into explicit edge lists - n = 0; - for (i=0; i < windings; ++i) - n += wcount[i]; - - e = (stbtt__edge *) STBTT_malloc(sizeof(*e) * (n+1), userdata); // add an extra one as a sentinel - if (e == 0) return; - n = 0; - - m=0; - for (i=0; i < windings; ++i) { - stbtt__point *p = pts + m; - m += wcount[i]; - j = wcount[i]-1; - for (k=0; k < wcount[i]; j=k++) { - int a=k,b=j; - // skip the edge if horizontal - if (p[j].y == p[k].y) - continue; - // add edge from j to k to the list - e[n].invert = 0; - if (invert ? p[j].y > p[k].y : p[j].y < p[k].y) { - e[n].invert = 1; - a=j,b=k; - } - e[n].x0 = p[a].x * scale_x + shift_x; - e[n].y0 = (p[a].y * y_scale_inv + shift_y) * vsubsample; - e[n].x1 = p[b].x * scale_x + shift_x; - e[n].y1 = (p[b].y * y_scale_inv + shift_y) * vsubsample; - ++n; - } - } - - // now sort the edges by their highest point (should snap to integer, and then by x) - //STBTT_sort(e, n, sizeof(e[0]), stbtt__edge_compare); - stbtt__sort_edges(e, n); - - // now, traverse the scanlines and find the intersections on each scanline, use xor winding rule - stbtt__rasterize_sorted_edges(result, e, n, vsubsample, off_x, off_y, userdata); - - STBTT_free(e, userdata); -} - -static void stbtt__add_point(stbtt__point *points, int n, float x, float y) -{ - if (!points) return; // during first pass, it's unallocated - points[n].x = x; - points[n].y = y; -} - -// tessellate until threshold p is happy... @TODO warped to compensate for non-linear stretching -static int stbtt__tesselate_curve(stbtt__point *points, int *num_points, float x0, float y0, float x1, float y1, float x2, float y2, float objspace_flatness_squared, int n) -{ - // midpoint - float mx = (x0 + 2*x1 + x2)/4; - float my = (y0 + 2*y1 + y2)/4; - // versus directly drawn line - float dx = (x0+x2)/2 - mx; - float dy = (y0+y2)/2 - my; - if (n > 16) // 65536 segments on one curve better be enough! - return 1; - if (dx*dx+dy*dy > objspace_flatness_squared) { // half-pixel error allowed... need to be smaller if AA - stbtt__tesselate_curve(points, num_points, x0,y0, (x0+x1)/2.0f,(y0+y1)/2.0f, mx,my, objspace_flatness_squared,n+1); - stbtt__tesselate_curve(points, num_points, mx,my, (x1+x2)/2.0f,(y1+y2)/2.0f, x2,y2, objspace_flatness_squared,n+1); - } else { - stbtt__add_point(points, *num_points,x2,y2); - *num_points = *num_points+1; - } - return 1; -} - -static void stbtt__tesselate_cubic(stbtt__point *points, int *num_points, float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3, float objspace_flatness_squared, int n) -{ - // @TODO this "flatness" calculation is just made-up nonsense that seems to work well enough - float dx0 = x1-x0; - float dy0 = y1-y0; - float dx1 = x2-x1; - float dy1 = y2-y1; - float dx2 = x3-x2; - float dy2 = y3-y2; - float dx = x3-x0; - float dy = y3-y0; - float longlen = (float) (STBTT_sqrt(dx0*dx0+dy0*dy0)+STBTT_sqrt(dx1*dx1+dy1*dy1)+STBTT_sqrt(dx2*dx2+dy2*dy2)); - float shortlen = (float) STBTT_sqrt(dx*dx+dy*dy); - float flatness_squared = longlen*longlen-shortlen*shortlen; - - if (n > 16) // 65536 segments on one curve better be enough! - return; - - if (flatness_squared > objspace_flatness_squared) { - float x01 = (x0+x1)/2; - float y01 = (y0+y1)/2; - float x12 = (x1+x2)/2; - float y12 = (y1+y2)/2; - float x23 = (x2+x3)/2; - float y23 = (y2+y3)/2; - - float xa = (x01+x12)/2; - float ya = (y01+y12)/2; - float xb = (x12+x23)/2; - float yb = (y12+y23)/2; - - float mx = (xa+xb)/2; - float my = (ya+yb)/2; - - stbtt__tesselate_cubic(points, num_points, x0,y0, x01,y01, xa,ya, mx,my, objspace_flatness_squared,n+1); - stbtt__tesselate_cubic(points, num_points, mx,my, xb,yb, x23,y23, x3,y3, objspace_flatness_squared,n+1); - } else { - stbtt__add_point(points, *num_points,x3,y3); - *num_points = *num_points+1; - } -} - -// returns number of contours -static stbtt__point *stbtt_FlattenCurves(stbtt_vertex *vertices, int num_verts, float objspace_flatness, int **contour_lengths, int *num_contours, void *userdata) -{ - stbtt__point *points=0; - int num_points=0; - - float objspace_flatness_squared = objspace_flatness * objspace_flatness; - int i,n=0,start=0, pass; - - // count how many "moves" there are to get the contour count - for (i=0; i < num_verts; ++i) - if (vertices[i].type == STBTT_vmove) - ++n; - - *num_contours = n; - if (n == 0) return 0; - - *contour_lengths = (int *) STBTT_malloc(sizeof(**contour_lengths) * n, userdata); - - if (*contour_lengths == 0) { - *num_contours = 0; - return 0; - } - - // make two passes through the points so we don't need to realloc - for (pass=0; pass < 2; ++pass) { - float x=0,y=0; - if (pass == 1) { - points = (stbtt__point *) STBTT_malloc(num_points * sizeof(points[0]), userdata); - if (points == NULL) goto error; - } - num_points = 0; - n= -1; - for (i=0; i < num_verts; ++i) { - switch (vertices[i].type) { - case STBTT_vmove: - // start the next contour - if (n >= 0) - (*contour_lengths)[n] = num_points - start; - ++n; - start = num_points; - - x = vertices[i].x, y = vertices[i].y; - stbtt__add_point(points, num_points++, x,y); - break; - case STBTT_vline: - x = vertices[i].x, y = vertices[i].y; - stbtt__add_point(points, num_points++, x, y); - break; - case STBTT_vcurve: - stbtt__tesselate_curve(points, &num_points, x,y, - vertices[i].cx, vertices[i].cy, - vertices[i].x, vertices[i].y, - objspace_flatness_squared, 0); - x = vertices[i].x, y = vertices[i].y; - break; - case STBTT_vcubic: - stbtt__tesselate_cubic(points, &num_points, x,y, - vertices[i].cx, vertices[i].cy, - vertices[i].cx1, vertices[i].cy1, - vertices[i].x, vertices[i].y, - objspace_flatness_squared, 0); - x = vertices[i].x, y = vertices[i].y; - break; - } - } - (*contour_lengths)[n] = num_points - start; - } - - return points; -error: - STBTT_free(points, userdata); - STBTT_free(*contour_lengths, userdata); - *contour_lengths = 0; - *num_contours = 0; - return NULL; -} - -STBTT_DEF void stbtt_Rasterize(stbtt__bitmap *result, float flatness_in_pixels, stbtt_vertex *vertices, int num_verts, float scale_x, float scale_y, float shift_x, float shift_y, int x_off, int y_off, int invert, void *userdata) -{ - float scale = scale_x > scale_y ? scale_y : scale_x; - int winding_count = 0; - int *winding_lengths = NULL; - stbtt__point *windings = stbtt_FlattenCurves(vertices, num_verts, flatness_in_pixels / scale, &winding_lengths, &winding_count, userdata); - if (windings) { - stbtt__rasterize(result, windings, winding_lengths, winding_count, scale_x, scale_y, shift_x, shift_y, x_off, y_off, invert, userdata); - STBTT_free(winding_lengths, userdata); - STBTT_free(windings, userdata); - } -} - -STBTT_DEF void stbtt_FreeBitmap(unsigned char *bitmap, void *userdata) -{ - STBTT_free(bitmap, userdata); -} - -STBTT_DEF unsigned char *stbtt_GetGlyphBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int glyph, int *width, int *height, int *xoff, int *yoff) -{ - int ix0,iy0,ix1,iy1; - stbtt__bitmap gbm; - stbtt_vertex *vertices; - int num_verts = stbtt_GetGlyphShape(info, glyph, &vertices); - - if (scale_x == 0) scale_x = scale_y; - if (scale_y == 0) { - if (scale_x == 0) { - STBTT_free(vertices, info->userdata); - return NULL; - } - scale_y = scale_x; - } - - stbtt_GetGlyphBitmapBoxSubpixel(info, glyph, scale_x, scale_y, shift_x, shift_y, &ix0,&iy0,&ix1,&iy1); - - // now we get the size - gbm.w = (ix1 - ix0); - gbm.h = (iy1 - iy0); - gbm.pixels = NULL; // in case we error - - if (width ) *width = gbm.w; - if (height) *height = gbm.h; - if (xoff ) *xoff = ix0; - if (yoff ) *yoff = iy0; - - if (gbm.w && gbm.h) { - gbm.pixels = (unsigned char *) STBTT_malloc(gbm.w * gbm.h, info->userdata); - if (gbm.pixels) { - gbm.stride = gbm.w; - - stbtt_Rasterize(&gbm, 0.35f, vertices, num_verts, scale_x, scale_y, shift_x, shift_y, ix0, iy0, 1, info->userdata); - } - } - STBTT_free(vertices, info->userdata); - return gbm.pixels; -} - -STBTT_DEF unsigned char *stbtt_GetGlyphBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int glyph, int *width, int *height, int *xoff, int *yoff) -{ - return stbtt_GetGlyphBitmapSubpixel(info, scale_x, scale_y, 0.0f, 0.0f, glyph, width, height, xoff, yoff); -} - -STBTT_DEF void stbtt_MakeGlyphBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int glyph) -{ - int ix0,iy0; - stbtt_vertex *vertices; - int num_verts = stbtt_GetGlyphShape(info, glyph, &vertices); - stbtt__bitmap gbm; - - stbtt_GetGlyphBitmapBoxSubpixel(info, glyph, scale_x, scale_y, shift_x, shift_y, &ix0,&iy0,0,0); - gbm.pixels = output; - gbm.w = out_w; - gbm.h = out_h; - gbm.stride = out_stride; - - if (gbm.w && gbm.h) - stbtt_Rasterize(&gbm, 0.35f, vertices, num_verts, scale_x, scale_y, shift_x, shift_y, ix0,iy0, 1, info->userdata); - - STBTT_free(vertices, info->userdata); -} - -STBTT_DEF void stbtt_MakeGlyphBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int glyph) -{ - stbtt_MakeGlyphBitmapSubpixel(info, output, out_w, out_h, out_stride, scale_x, scale_y, 0.0f,0.0f, glyph); -} - -STBTT_DEF unsigned char *stbtt_GetCodepointBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint, int *width, int *height, int *xoff, int *yoff) -{ - return stbtt_GetGlyphBitmapSubpixel(info, scale_x, scale_y,shift_x,shift_y, stbtt_FindGlyphIndex(info,codepoint), width,height,xoff,yoff); -} - -STBTT_DEF void stbtt_MakeCodepointBitmapSubpixelPrefilter(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int oversample_x, int oversample_y, float *sub_x, float *sub_y, int codepoint) -{ - stbtt_MakeGlyphBitmapSubpixelPrefilter(info, output, out_w, out_h, out_stride, scale_x, scale_y, shift_x, shift_y, oversample_x, oversample_y, sub_x, sub_y, stbtt_FindGlyphIndex(info,codepoint)); -} - -STBTT_DEF void stbtt_MakeCodepointBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint) -{ - stbtt_MakeGlyphBitmapSubpixel(info, output, out_w, out_h, out_stride, scale_x, scale_y, shift_x, shift_y, stbtt_FindGlyphIndex(info,codepoint)); -} - -STBTT_DEF unsigned char *stbtt_GetCodepointBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int codepoint, int *width, int *height, int *xoff, int *yoff) -{ - return stbtt_GetCodepointBitmapSubpixel(info, scale_x, scale_y, 0.0f,0.0f, codepoint, width,height,xoff,yoff); -} - -STBTT_DEF void stbtt_MakeCodepointBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int codepoint) -{ - stbtt_MakeCodepointBitmapSubpixel(info, output, out_w, out_h, out_stride, scale_x, scale_y, 0.0f,0.0f, codepoint); -} - -////////////////////////////////////////////////////////////////////////////// -// -// bitmap baking -// -// This is SUPER-CRAPPY packing to keep source code small - -static int stbtt_BakeFontBitmap_internal(unsigned char *data, int offset, // font location (use offset=0 for plain .ttf) - float pixel_height, // height of font in pixels - unsigned char *pixels, int pw, int ph, // bitmap to be filled in - int first_char, int num_chars, // characters to bake - stbtt_bakedchar *chardata) -{ - float scale; - int x,y,bottom_y, i; - stbtt_fontinfo f; - f.userdata = NULL; - if (!stbtt_InitFont(&f, data, offset)) - return -1; - STBTT_memset(pixels, 0, pw*ph); // background of 0 around pixels - x=y=1; - bottom_y = 1; - - scale = stbtt_ScaleForPixelHeight(&f, pixel_height); - - for (i=0; i < num_chars; ++i) { - int advance, lsb, x0,y0,x1,y1,gw,gh; - int g = stbtt_FindGlyphIndex(&f, first_char + i); - stbtt_GetGlyphHMetrics(&f, g, &advance, &lsb); - stbtt_GetGlyphBitmapBox(&f, g, scale,scale, &x0,&y0,&x1,&y1); - gw = x1-x0; - gh = y1-y0; - if (x + gw + 1 >= pw) - y = bottom_y, x = 1; // advance to next row - if (y + gh + 1 >= ph) // check if it fits vertically AFTER potentially moving to next row - return -i; - STBTT_assert(x+gw < pw); - STBTT_assert(y+gh < ph); - stbtt_MakeGlyphBitmap(&f, pixels+x+y*pw, gw,gh,pw, scale,scale, g); - chardata[i].x0 = (stbtt_int16) x; - chardata[i].y0 = (stbtt_int16) y; - chardata[i].x1 = (stbtt_int16) (x + gw); - chardata[i].y1 = (stbtt_int16) (y + gh); - chardata[i].xadvance = scale * advance; - chardata[i].xoff = (float) x0; - chardata[i].yoff = (float) y0; - x = x + gw + 1; - if (y+gh+1 > bottom_y) - bottom_y = y+gh+1; - } - return bottom_y; -} - -STBTT_DEF void stbtt_GetBakedQuad(const stbtt_bakedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int opengl_fillrule) -{ - float d3d_bias = opengl_fillrule ? 0 : -0.5f; - float ipw = 1.0f / pw, iph = 1.0f / ph; - const stbtt_bakedchar *b = chardata + char_index; - int round_x = STBTT_ifloor((*xpos + b->xoff) + 0.5f); - int round_y = STBTT_ifloor((*ypos + b->yoff) + 0.5f); - - q->x0 = round_x + d3d_bias; - q->y0 = round_y + d3d_bias; - q->x1 = round_x + b->x1 - b->x0 + d3d_bias; - q->y1 = round_y + b->y1 - b->y0 + d3d_bias; - - q->s0 = b->x0 * ipw; - q->t0 = b->y0 * iph; - q->s1 = b->x1 * ipw; - q->t1 = b->y1 * iph; - - *xpos += b->xadvance; -} - -////////////////////////////////////////////////////////////////////////////// -// -// rectangle packing replacement routines if you don't have stb_rect_pack.h -// - -#ifndef STB_RECT_PACK_VERSION - -typedef int stbrp_coord; - -//////////////////////////////////////////////////////////////////////////////////// -// // -// // -// COMPILER WARNING ?!?!? // -// // -// // -// if you get a compile warning due to these symbols being defined more than // -// once, move #include "stb_rect_pack.h" before #include "stb_truetype.h" // -// // -//////////////////////////////////////////////////////////////////////////////////// - -typedef struct -{ - int width,height; - int x,y,bottom_y; -} stbrp_context; - -typedef struct -{ - unsigned char x; -} stbrp_node; - -struct stbrp_rect -{ - stbrp_coord x,y; - int id,w,h,was_packed; -}; - -static void stbrp_init_target(stbrp_context *con, int pw, int ph, stbrp_node *nodes, int num_nodes) -{ - con->width = pw; - con->height = ph; - con->x = 0; - con->y = 0; - con->bottom_y = 0; - STBTT__NOTUSED(nodes); - STBTT__NOTUSED(num_nodes); -} - -static void stbrp_pack_rects(stbrp_context *con, stbrp_rect *rects, int num_rects) -{ - int i; - for (i=0; i < num_rects; ++i) { - if (con->x + rects[i].w > con->width) { - con->x = 0; - con->y = con->bottom_y; - } - if (con->y + rects[i].h > con->height) - break; - rects[i].x = con->x; - rects[i].y = con->y; - rects[i].was_packed = 1; - con->x += rects[i].w; - if (con->y + rects[i].h > con->bottom_y) - con->bottom_y = con->y + rects[i].h; - } - for ( ; i < num_rects; ++i) - rects[i].was_packed = 0; -} -#endif - -////////////////////////////////////////////////////////////////////////////// -// -// bitmap baking -// -// This is SUPER-AWESOME (tm Ryan Gordon) packing using stb_rect_pack.h. If -// stb_rect_pack.h isn't available, it uses the BakeFontBitmap strategy. - -STBTT_DEF int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, int pw, int ph, int stride_in_bytes, int padding, void *alloc_context) -{ - stbrp_context *context = (stbrp_context *) STBTT_malloc(sizeof(*context) ,alloc_context); - int num_nodes = pw - padding; - stbrp_node *nodes = (stbrp_node *) STBTT_malloc(sizeof(*nodes ) * num_nodes,alloc_context); - - if (context == NULL || nodes == NULL) { - if (context != NULL) STBTT_free(context, alloc_context); - if (nodes != NULL) STBTT_free(nodes , alloc_context); - return 0; - } - - spc->user_allocator_context = alloc_context; - spc->width = pw; - spc->height = ph; - spc->pixels = pixels; - spc->pack_info = context; - spc->nodes = nodes; - spc->padding = padding; - spc->stride_in_bytes = stride_in_bytes != 0 ? stride_in_bytes : pw; - spc->h_oversample = 1; - spc->v_oversample = 1; - spc->skip_missing = 0; - - stbrp_init_target(context, pw-padding, ph-padding, nodes, num_nodes); - - if (pixels) - STBTT_memset(pixels, 0, pw*ph); // background of 0 around pixels - - return 1; -} - -STBTT_DEF void stbtt_PackEnd (stbtt_pack_context *spc) -{ - STBTT_free(spc->nodes , spc->user_allocator_context); - STBTT_free(spc->pack_info, spc->user_allocator_context); -} - -STBTT_DEF void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_oversample) -{ - STBTT_assert(h_oversample <= STBTT_MAX_OVERSAMPLE); - STBTT_assert(v_oversample <= STBTT_MAX_OVERSAMPLE); - if (h_oversample <= STBTT_MAX_OVERSAMPLE) - spc->h_oversample = h_oversample; - if (v_oversample <= STBTT_MAX_OVERSAMPLE) - spc->v_oversample = v_oversample; -} - -STBTT_DEF void stbtt_PackSetSkipMissingCodepoints(stbtt_pack_context *spc, int skip) -{ - spc->skip_missing = skip; -} - -#define STBTT__OVER_MASK (STBTT_MAX_OVERSAMPLE-1) - -static void stbtt__h_prefilter(unsigned char *pixels, int w, int h, int stride_in_bytes, unsigned int kernel_width) -{ - unsigned char buffer[STBTT_MAX_OVERSAMPLE]; - int safe_w = w - kernel_width; - int j; - STBTT_memset(buffer, 0, STBTT_MAX_OVERSAMPLE); // suppress bogus warning from VS2013 -analyze - for (j=0; j < h; ++j) { - int i; - unsigned int total; - STBTT_memset(buffer, 0, kernel_width); - - total = 0; - - // make kernel_width a constant in common cases so compiler can optimize out the divide - switch (kernel_width) { - case 2: - for (i=0; i <= safe_w; ++i) { - total += pixels[i] - buffer[i & STBTT__OVER_MASK]; - buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i]; - pixels[i] = (unsigned char) (total / 2); - } - break; - case 3: - for (i=0; i <= safe_w; ++i) { - total += pixels[i] - buffer[i & STBTT__OVER_MASK]; - buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i]; - pixels[i] = (unsigned char) (total / 3); - } - break; - case 4: - for (i=0; i <= safe_w; ++i) { - total += pixels[i] - buffer[i & STBTT__OVER_MASK]; - buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i]; - pixels[i] = (unsigned char) (total / 4); - } - break; - case 5: - for (i=0; i <= safe_w; ++i) { - total += pixels[i] - buffer[i & STBTT__OVER_MASK]; - buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i]; - pixels[i] = (unsigned char) (total / 5); - } - break; - default: - for (i=0; i <= safe_w; ++i) { - total += pixels[i] - buffer[i & STBTT__OVER_MASK]; - buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i]; - pixels[i] = (unsigned char) (total / kernel_width); - } - break; - } - - for (; i < w; ++i) { - STBTT_assert(pixels[i] == 0); - total -= buffer[i & STBTT__OVER_MASK]; - pixels[i] = (unsigned char) (total / kernel_width); - } - - pixels += stride_in_bytes; - } -} - -static void stbtt__v_prefilter(unsigned char *pixels, int w, int h, int stride_in_bytes, unsigned int kernel_width) -{ - unsigned char buffer[STBTT_MAX_OVERSAMPLE]; - int safe_h = h - kernel_width; - int j; - STBTT_memset(buffer, 0, STBTT_MAX_OVERSAMPLE); // suppress bogus warning from VS2013 -analyze - for (j=0; j < w; ++j) { - int i; - unsigned int total; - STBTT_memset(buffer, 0, kernel_width); - - total = 0; - - // make kernel_width a constant in common cases so compiler can optimize out the divide - switch (kernel_width) { - case 2: - for (i=0; i <= safe_h; ++i) { - total += pixels[i*stride_in_bytes] - buffer[i & STBTT__OVER_MASK]; - buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i*stride_in_bytes]; - pixels[i*stride_in_bytes] = (unsigned char) (total / 2); - } - break; - case 3: - for (i=0; i <= safe_h; ++i) { - total += pixels[i*stride_in_bytes] - buffer[i & STBTT__OVER_MASK]; - buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i*stride_in_bytes]; - pixels[i*stride_in_bytes] = (unsigned char) (total / 3); - } - break; - case 4: - for (i=0; i <= safe_h; ++i) { - total += pixels[i*stride_in_bytes] - buffer[i & STBTT__OVER_MASK]; - buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i*stride_in_bytes]; - pixels[i*stride_in_bytes] = (unsigned char) (total / 4); - } - break; - case 5: - for (i=0; i <= safe_h; ++i) { - total += pixels[i*stride_in_bytes] - buffer[i & STBTT__OVER_MASK]; - buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i*stride_in_bytes]; - pixels[i*stride_in_bytes] = (unsigned char) (total / 5); - } - break; - default: - for (i=0; i <= safe_h; ++i) { - total += pixels[i*stride_in_bytes] - buffer[i & STBTT__OVER_MASK]; - buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i*stride_in_bytes]; - pixels[i*stride_in_bytes] = (unsigned char) (total / kernel_width); - } - break; - } - - for (; i < h; ++i) { - STBTT_assert(pixels[i*stride_in_bytes] == 0); - total -= buffer[i & STBTT__OVER_MASK]; - pixels[i*stride_in_bytes] = (unsigned char) (total / kernel_width); - } - - pixels += 1; - } -} - -static float stbtt__oversample_shift(int oversample) -{ - if (!oversample) - return 0.0f; - - // The prefilter is a box filter of width "oversample", - // which shifts phase by (oversample - 1)/2 pixels in - // oversampled space. We want to shift in the opposite - // direction to counter this. - return (float)-(oversample - 1) / (2.0f * (float)oversample); -} - -// rects array must be big enough to accommodate all characters in the given ranges -STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, const stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects) -{ - int i,j,k; - int missing_glyph_added = 0; - - k=0; - for (i=0; i < num_ranges; ++i) { - float fh = ranges[i].font_size; - float scale = fh > 0 ? stbtt_ScaleForPixelHeight(info, fh) : stbtt_ScaleForMappingEmToPixels(info, -fh); - ranges[i].h_oversample = (unsigned char) spc->h_oversample; - ranges[i].v_oversample = (unsigned char) spc->v_oversample; - for (j=0; j < ranges[i].num_chars; ++j) { - int x0,y0,x1,y1; - int codepoint = ranges[i].array_of_unicode_codepoints == NULL ? ranges[i].first_unicode_codepoint_in_range + j : ranges[i].array_of_unicode_codepoints[j]; - int glyph = stbtt_FindGlyphIndex(info, codepoint); - if (glyph == 0 && (spc->skip_missing || missing_glyph_added)) { - rects[k].w = rects[k].h = 0; - } else { - stbtt_GetGlyphBitmapBoxSubpixel(info,glyph, - scale * spc->h_oversample, - scale * spc->v_oversample, - 0,0, - &x0,&y0,&x1,&y1); - rects[k].w = (stbrp_coord) (x1-x0 + spc->padding + spc->h_oversample-1); - rects[k].h = (stbrp_coord) (y1-y0 + spc->padding + spc->v_oversample-1); - if (glyph == 0) - missing_glyph_added = 1; - } - ++k; - } - } - - return k; -} - -STBTT_DEF void stbtt_MakeGlyphBitmapSubpixelPrefilter(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int prefilter_x, int prefilter_y, float *sub_x, float *sub_y, int glyph) -{ - stbtt_MakeGlyphBitmapSubpixel(info, - output, - out_w - (prefilter_x - 1), - out_h - (prefilter_y - 1), - out_stride, - scale_x, - scale_y, - shift_x, - shift_y, - glyph); - - if (prefilter_x > 1) - stbtt__h_prefilter(output, out_w, out_h, out_stride, prefilter_x); - - if (prefilter_y > 1) - stbtt__v_prefilter(output, out_w, out_h, out_stride, prefilter_y); - - *sub_x = stbtt__oversample_shift(prefilter_x); - *sub_y = stbtt__oversample_shift(prefilter_y); -} - -// rects array must be big enough to accommodate all characters in the given ranges -STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, const stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects) -{ - int i,j,k, missing_glyph = -1, return_value = 1; - - // save current values - int old_h_over = spc->h_oversample; - int old_v_over = spc->v_oversample; - - k = 0; - for (i=0; i < num_ranges; ++i) { - float fh = ranges[i].font_size; - float scale = fh > 0 ? stbtt_ScaleForPixelHeight(info, fh) : stbtt_ScaleForMappingEmToPixels(info, -fh); - float recip_h,recip_v,sub_x,sub_y; - spc->h_oversample = ranges[i].h_oversample; - spc->v_oversample = ranges[i].v_oversample; - recip_h = 1.0f / spc->h_oversample; - recip_v = 1.0f / spc->v_oversample; - sub_x = stbtt__oversample_shift(spc->h_oversample); - sub_y = stbtt__oversample_shift(spc->v_oversample); - for (j=0; j < ranges[i].num_chars; ++j) { - stbrp_rect *r = &rects[k]; - if (r->was_packed && r->w != 0 && r->h != 0) { - stbtt_packedchar *bc = &ranges[i].chardata_for_range[j]; - int advance, lsb, x0,y0,x1,y1; - int codepoint = ranges[i].array_of_unicode_codepoints == NULL ? ranges[i].first_unicode_codepoint_in_range + j : ranges[i].array_of_unicode_codepoints[j]; - int glyph = stbtt_FindGlyphIndex(info, codepoint); - stbrp_coord pad = (stbrp_coord) spc->padding; - - // pad on left and top - r->x += pad; - r->y += pad; - r->w -= pad; - r->h -= pad; - stbtt_GetGlyphHMetrics(info, glyph, &advance, &lsb); - stbtt_GetGlyphBitmapBox(info, glyph, - scale * spc->h_oversample, - scale * spc->v_oversample, - &x0,&y0,&x1,&y1); - stbtt_MakeGlyphBitmapSubpixel(info, - spc->pixels + r->x + r->y*spc->stride_in_bytes, - r->w - spc->h_oversample+1, - r->h - spc->v_oversample+1, - spc->stride_in_bytes, - scale * spc->h_oversample, - scale * spc->v_oversample, - 0,0, - glyph); - - if (spc->h_oversample > 1) - stbtt__h_prefilter(spc->pixels + r->x + r->y*spc->stride_in_bytes, - r->w, r->h, spc->stride_in_bytes, - spc->h_oversample); - - if (spc->v_oversample > 1) - stbtt__v_prefilter(spc->pixels + r->x + r->y*spc->stride_in_bytes, - r->w, r->h, spc->stride_in_bytes, - spc->v_oversample); - - bc->x0 = (stbtt_int16) r->x; - bc->y0 = (stbtt_int16) r->y; - bc->x1 = (stbtt_int16) (r->x + r->w); - bc->y1 = (stbtt_int16) (r->y + r->h); - bc->xadvance = scale * advance; - bc->xoff = (float) x0 * recip_h + sub_x; - bc->yoff = (float) y0 * recip_v + sub_y; - bc->xoff2 = (x0 + r->w) * recip_h + sub_x; - bc->yoff2 = (y0 + r->h) * recip_v + sub_y; - - if (glyph == 0) - missing_glyph = j; - } else if (spc->skip_missing) { - return_value = 0; - } else if (r->was_packed && r->w == 0 && r->h == 0 && missing_glyph >= 0) { - ranges[i].chardata_for_range[j] = ranges[i].chardata_for_range[missing_glyph]; - } else { - return_value = 0; // if any fail, report failure - } - - ++k; - } - } - - // restore original values - spc->h_oversample = old_h_over; - spc->v_oversample = old_v_over; - - return return_value; -} - -STBTT_DEF void stbtt_PackFontRangesPackRects(stbtt_pack_context *spc, stbrp_rect *rects, int num_rects) -{ - stbrp_pack_rects((stbrp_context *) spc->pack_info, rects, num_rects); -} - -STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, const unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges) -{ - stbtt_fontinfo info; - int i,j,n, return_value = 1; - //stbrp_context *context = (stbrp_context *) spc->pack_info; - stbrp_rect *rects; - - // flag all characters as NOT packed - for (i=0; i < num_ranges; ++i) - for (j=0; j < ranges[i].num_chars; ++j) - ranges[i].chardata_for_range[j].x0 = - ranges[i].chardata_for_range[j].y0 = - ranges[i].chardata_for_range[j].x1 = - ranges[i].chardata_for_range[j].y1 = 0; - - n = 0; - for (i=0; i < num_ranges; ++i) - n += ranges[i].num_chars; - - rects = (stbrp_rect *) STBTT_malloc(sizeof(*rects) * n, spc->user_allocator_context); - if (rects == NULL) - return 0; - - info.userdata = spc->user_allocator_context; - stbtt_InitFont(&info, fontdata, stbtt_GetFontOffsetForIndex(fontdata,font_index)); - - n = stbtt_PackFontRangesGatherRects(spc, &info, ranges, num_ranges, rects); - - stbtt_PackFontRangesPackRects(spc, rects, n); - - return_value = stbtt_PackFontRangesRenderIntoRects(spc, &info, ranges, num_ranges, rects); - - STBTT_free(rects, spc->user_allocator_context); - return return_value; -} - -STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, const unsigned char *fontdata, int font_index, float font_size, - int first_unicode_codepoint_in_range, int num_chars_in_range, stbtt_packedchar *chardata_for_range) -{ - stbtt_pack_range range; - range.first_unicode_codepoint_in_range = first_unicode_codepoint_in_range; - range.array_of_unicode_codepoints = NULL; - range.num_chars = num_chars_in_range; - range.chardata_for_range = chardata_for_range; - range.font_size = font_size; - return stbtt_PackFontRanges(spc, fontdata, font_index, &range, 1); -} - -STBTT_DEF void stbtt_GetScaledFontVMetrics(const unsigned char *fontdata, int index, float size, float *ascent, float *descent, float *lineGap) -{ - int i_ascent, i_descent, i_lineGap; - float scale; - stbtt_fontinfo info; - stbtt_InitFont(&info, fontdata, stbtt_GetFontOffsetForIndex(fontdata, index)); - scale = size > 0 ? stbtt_ScaleForPixelHeight(&info, size) : stbtt_ScaleForMappingEmToPixels(&info, -size); - stbtt_GetFontVMetrics(&info, &i_ascent, &i_descent, &i_lineGap); - *ascent = (float) i_ascent * scale; - *descent = (float) i_descent * scale; - *lineGap = (float) i_lineGap * scale; -} - -STBTT_DEF void stbtt_GetPackedQuad(const stbtt_packedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int align_to_integer) -{ - float ipw = 1.0f / pw, iph = 1.0f / ph; - const stbtt_packedchar *b = chardata + char_index; - - if (align_to_integer) { - float x = (float) STBTT_ifloor((*xpos + b->xoff) + 0.5f); - float y = (float) STBTT_ifloor((*ypos + b->yoff) + 0.5f); - q->x0 = x; - q->y0 = y; - q->x1 = x + b->xoff2 - b->xoff; - q->y1 = y + b->yoff2 - b->yoff; - } else { - q->x0 = *xpos + b->xoff; - q->y0 = *ypos + b->yoff; - q->x1 = *xpos + b->xoff2; - q->y1 = *ypos + b->yoff2; - } - - q->s0 = b->x0 * ipw; - q->t0 = b->y0 * iph; - q->s1 = b->x1 * ipw; - q->t1 = b->y1 * iph; - - *xpos += b->xadvance; -} - -////////////////////////////////////////////////////////////////////////////// -// -// sdf computation -// - -#define STBTT_min(a,b) ((a) < (b) ? (a) : (b)) -#define STBTT_max(a,b) ((a) < (b) ? (b) : (a)) - -static int stbtt__ray_intersect_bezier(float orig[2], float ray[2], float q0[2], float q1[2], float q2[2], float hits[2][2]) -{ - float q0perp = q0[1]*ray[0] - q0[0]*ray[1]; - float q1perp = q1[1]*ray[0] - q1[0]*ray[1]; - float q2perp = q2[1]*ray[0] - q2[0]*ray[1]; - float roperp = orig[1]*ray[0] - orig[0]*ray[1]; - - float a = q0perp - 2*q1perp + q2perp; - float b = q1perp - q0perp; - float c = q0perp - roperp; - - float s0 = 0., s1 = 0.; - int num_s = 0; - - if (a != 0.0) { - float discr = b*b - a*c; - if (discr > 0.0) { - float rcpna = -1 / a; - float d = (float) STBTT_sqrt(discr); - s0 = (b+d) * rcpna; - s1 = (b-d) * rcpna; - if (s0 >= 0.0 && s0 <= 1.0) - num_s = 1; - if (d > 0.0 && s1 >= 0.0 && s1 <= 1.0) { - if (num_s == 0) s0 = s1; - ++num_s; - } - } - } else { - // 2*b*s + c = 0 - // s = -c / (2*b) - s0 = c / (-2 * b); - if (s0 >= 0.0 && s0 <= 1.0) - num_s = 1; - } - - if (num_s == 0) - return 0; - else { - float rcp_len2 = 1 / (ray[0]*ray[0] + ray[1]*ray[1]); - float rayn_x = ray[0] * rcp_len2, rayn_y = ray[1] * rcp_len2; - - float q0d = q0[0]*rayn_x + q0[1]*rayn_y; - float q1d = q1[0]*rayn_x + q1[1]*rayn_y; - float q2d = q2[0]*rayn_x + q2[1]*rayn_y; - float rod = orig[0]*rayn_x + orig[1]*rayn_y; - - float q10d = q1d - q0d; - float q20d = q2d - q0d; - float q0rd = q0d - rod; - - hits[0][0] = q0rd + s0*(2.0f - 2.0f*s0)*q10d + s0*s0*q20d; - hits[0][1] = a*s0+b; - - if (num_s > 1) { - hits[1][0] = q0rd + s1*(2.0f - 2.0f*s1)*q10d + s1*s1*q20d; - hits[1][1] = a*s1+b; - return 2; - } else { - return 1; - } - } -} - -static int equal(float *a, float *b) -{ - return (a[0] == b[0] && a[1] == b[1]); -} - -static int stbtt__compute_crossings_x(float x, float y, int nverts, stbtt_vertex *verts) -{ - int i; - float orig[2], ray[2] = { 1, 0 }; - float y_frac; - int winding = 0; - - // make sure y never passes through a vertex of the shape - y_frac = (float) STBTT_fmod(y, 1.0f); - if (y_frac < 0.01f) - y += 0.01f; - else if (y_frac > 0.99f) - y -= 0.01f; - - orig[0] = x; - orig[1] = y; - - // test a ray from (-infinity,y) to (x,y) - for (i=0; i < nverts; ++i) { - if (verts[i].type == STBTT_vline) { - int x0 = (int) verts[i-1].x, y0 = (int) verts[i-1].y; - int x1 = (int) verts[i ].x, y1 = (int) verts[i ].y; - if (y > STBTT_min(y0,y1) && y < STBTT_max(y0,y1) && x > STBTT_min(x0,x1)) { - float x_inter = (y - y0) / (y1 - y0) * (x1-x0) + x0; - if (x_inter < x) - winding += (y0 < y1) ? 1 : -1; - } - } - if (verts[i].type == STBTT_vcurve) { - int x0 = (int) verts[i-1].x , y0 = (int) verts[i-1].y ; - int x1 = (int) verts[i ].cx, y1 = (int) verts[i ].cy; - int x2 = (int) verts[i ].x , y2 = (int) verts[i ].y ; - int ax = STBTT_min(x0,STBTT_min(x1,x2)), ay = STBTT_min(y0,STBTT_min(y1,y2)); - int by = STBTT_max(y0,STBTT_max(y1,y2)); - if (y > ay && y < by && x > ax) { - float q0[2],q1[2],q2[2]; - float hits[2][2]; - q0[0] = (float)x0; - q0[1] = (float)y0; - q1[0] = (float)x1; - q1[1] = (float)y1; - q2[0] = (float)x2; - q2[1] = (float)y2; - if (equal(q0,q1) || equal(q1,q2)) { - x0 = (int)verts[i-1].x; - y0 = (int)verts[i-1].y; - x1 = (int)verts[i ].x; - y1 = (int)verts[i ].y; - if (y > STBTT_min(y0,y1) && y < STBTT_max(y0,y1) && x > STBTT_min(x0,x1)) { - float x_inter = (y - y0) / (y1 - y0) * (x1-x0) + x0; - if (x_inter < x) - winding += (y0 < y1) ? 1 : -1; - } - } else { - int num_hits = stbtt__ray_intersect_bezier(orig, ray, q0, q1, q2, hits); - if (num_hits >= 1) - if (hits[0][0] < 0) - winding += (hits[0][1] < 0 ? -1 : 1); - if (num_hits >= 2) - if (hits[1][0] < 0) - winding += (hits[1][1] < 0 ? -1 : 1); - } - } - } - } - return winding; -} - -static float stbtt__cuberoot( float x ) -{ - if (x<0) - return -(float) STBTT_pow(-x,1.0f/3.0f); - else - return (float) STBTT_pow( x,1.0f/3.0f); -} - -// x^3 + a*x^2 + b*x + c = 0 -static int stbtt__solve_cubic(float a, float b, float c, float* r) -{ - float s = -a / 3; - float p = b - a*a / 3; - float q = a * (2*a*a - 9*b) / 27 + c; - float p3 = p*p*p; - float d = q*q + 4*p3 / 27; - if (d >= 0) { - float z = (float) STBTT_sqrt(d); - float u = (-q + z) / 2; - float v = (-q - z) / 2; - u = stbtt__cuberoot(u); - v = stbtt__cuberoot(v); - r[0] = s + u + v; - return 1; - } else { - float u = (float) STBTT_sqrt(-p/3); - float v = (float) STBTT_acos(-STBTT_sqrt(-27/p3) * q / 2) / 3; // p3 must be negative, since d is negative - float m = (float) STBTT_cos(v); - float n = (float) STBTT_cos(v-3.141592/2)*1.732050808f; - r[0] = s + u * 2 * m; - r[1] = s - u * (m + n); - r[2] = s - u * (m - n); - - //STBTT_assert( STBTT_fabs(((r[0]+a)*r[0]+b)*r[0]+c) < 0.05f); // these asserts may not be safe at all scales, though they're in bezier t parameter units so maybe? - //STBTT_assert( STBTT_fabs(((r[1]+a)*r[1]+b)*r[1]+c) < 0.05f); - //STBTT_assert( STBTT_fabs(((r[2]+a)*r[2]+b)*r[2]+c) < 0.05f); - return 3; - } -} - -STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float scale, int glyph, int padding, unsigned char onedge_value, float pixel_dist_scale, int *width, int *height, int *xoff, int *yoff) -{ - float scale_x = scale, scale_y = scale; - int ix0,iy0,ix1,iy1; - int w,h; - unsigned char *data; - - if (scale == 0) return NULL; - - stbtt_GetGlyphBitmapBoxSubpixel(info, glyph, scale, scale, 0.0f,0.0f, &ix0,&iy0,&ix1,&iy1); - - // if empty, return NULL - if (ix0 == ix1 || iy0 == iy1) - return NULL; - - ix0 -= padding; - iy0 -= padding; - ix1 += padding; - iy1 += padding; - - w = (ix1 - ix0); - h = (iy1 - iy0); - - if (width ) *width = w; - if (height) *height = h; - if (xoff ) *xoff = ix0; - if (yoff ) *yoff = iy0; - - // invert for y-downwards bitmaps - scale_y = -scale_y; - - { - // distance from singular values (in the same units as the pixel grid) - const float eps = 1./1024, eps2 = eps*eps; - int x,y,i,j; - float *precompute; - stbtt_vertex *verts; - int num_verts = stbtt_GetGlyphShape(info, glyph, &verts); - data = (unsigned char *) STBTT_malloc(w * h, info->userdata); - precompute = (float *) STBTT_malloc(num_verts * sizeof(float), info->userdata); - - for (i=0,j=num_verts-1; i < num_verts; j=i++) { - if (verts[i].type == STBTT_vline) { - float x0 = verts[i].x*scale_x, y0 = verts[i].y*scale_y; - float x1 = verts[j].x*scale_x, y1 = verts[j].y*scale_y; - float dist = (float) STBTT_sqrt((x1-x0)*(x1-x0) + (y1-y0)*(y1-y0)); - precompute[i] = (dist < eps) ? 0.0f : 1.0f / dist; - } else if (verts[i].type == STBTT_vcurve) { - float x2 = verts[j].x *scale_x, y2 = verts[j].y *scale_y; - float x1 = verts[i].cx*scale_x, y1 = verts[i].cy*scale_y; - float x0 = verts[i].x *scale_x, y0 = verts[i].y *scale_y; - float bx = x0 - 2*x1 + x2, by = y0 - 2*y1 + y2; - float len2 = bx*bx + by*by; - if (len2 >= eps2) - precompute[i] = 1.0f / len2; - else - precompute[i] = 0.0f; - } else - precompute[i] = 0.0f; - } - - for (y=iy0; y < iy1; ++y) { - for (x=ix0; x < ix1; ++x) { - float val; - float min_dist = 999999.0f; - float sx = (float) x + 0.5f; - float sy = (float) y + 0.5f; - float x_gspace = (sx / scale_x); - float y_gspace = (sy / scale_y); - - int winding = stbtt__compute_crossings_x(x_gspace, y_gspace, num_verts, verts); // @OPTIMIZE: this could just be a rasterization, but needs to be line vs. non-tesselated curves so a new path - - for (i=0; i < num_verts; ++i) { - float x0 = verts[i].x*scale_x, y0 = verts[i].y*scale_y; - - if (verts[i].type == STBTT_vline && precompute[i] != 0.0f) { - float x1 = verts[i-1].x*scale_x, y1 = verts[i-1].y*scale_y; - - float dist,dist2 = (x0-sx)*(x0-sx) + (y0-sy)*(y0-sy); - if (dist2 < min_dist*min_dist) - min_dist = (float) STBTT_sqrt(dist2); - - // coarse culling against bbox - //if (sx > STBTT_min(x0,x1)-min_dist && sx < STBTT_max(x0,x1)+min_dist && - // sy > STBTT_min(y0,y1)-min_dist && sy < STBTT_max(y0,y1)+min_dist) - dist = (float) STBTT_fabs((x1-x0)*(y0-sy) - (y1-y0)*(x0-sx)) * precompute[i]; - STBTT_assert(i != 0); - if (dist < min_dist) { - // check position along line - // x' = x0 + t*(x1-x0), y' = y0 + t*(y1-y0) - // minimize (x'-sx)*(x'-sx)+(y'-sy)*(y'-sy) - float dx = x1-x0, dy = y1-y0; - float px = x0-sx, py = y0-sy; - // minimize (px+t*dx)^2 + (py+t*dy)^2 = px*px + 2*px*dx*t + t^2*dx*dx + py*py + 2*py*dy*t + t^2*dy*dy - // derivative: 2*px*dx + 2*py*dy + (2*dx*dx+2*dy*dy)*t, set to 0 and solve - float t = -(px*dx + py*dy) / (dx*dx + dy*dy); - if (t >= 0.0f && t <= 1.0f) - min_dist = dist; - } - } else if (verts[i].type == STBTT_vcurve) { - float x2 = verts[i-1].x *scale_x, y2 = verts[i-1].y *scale_y; - float x1 = verts[i ].cx*scale_x, y1 = verts[i ].cy*scale_y; - float box_x0 = STBTT_min(STBTT_min(x0,x1),x2); - float box_y0 = STBTT_min(STBTT_min(y0,y1),y2); - float box_x1 = STBTT_max(STBTT_max(x0,x1),x2); - float box_y1 = STBTT_max(STBTT_max(y0,y1),y2); - // coarse culling against bbox to avoid computing cubic unnecessarily - if (sx > box_x0-min_dist && sx < box_x1+min_dist && sy > box_y0-min_dist && sy < box_y1+min_dist) { - int num=0; - float ax = x1-x0, ay = y1-y0; - float bx = x0 - 2*x1 + x2, by = y0 - 2*y1 + y2; - float mx = x0 - sx, my = y0 - sy; - float res[3] = {0.f,0.f,0.f}; - float px,py,t,it,dist2; - float a_inv = precompute[i]; - if (a_inv == 0.0) { // if a_inv is 0, it's 2nd degree so use quadratic formula - float a = 3*(ax*bx + ay*by); - float b = 2*(ax*ax + ay*ay) + (mx*bx+my*by); - float c = mx*ax+my*ay; - if (STBTT_fabs(a) < eps2) { // if a is 0, it's linear - if (STBTT_fabs(b) >= eps2) { - res[num++] = -c/b; - } - } else { - float discriminant = b*b - 4*a*c; - if (discriminant < 0) - num = 0; - else { - float root = (float) STBTT_sqrt(discriminant); - res[0] = (-b - root)/(2*a); - res[1] = (-b + root)/(2*a); - num = 2; // don't bother distinguishing 1-solution case, as code below will still work - } - } - } else { - float b = 3*(ax*bx + ay*by) * a_inv; // could precompute this as it doesn't depend on sample point - float c = (2*(ax*ax + ay*ay) + (mx*bx+my*by)) * a_inv; - float d = (mx*ax+my*ay) * a_inv; - num = stbtt__solve_cubic(b, c, d, res); - } - dist2 = (x0-sx)*(x0-sx) + (y0-sy)*(y0-sy); - if (dist2 < min_dist*min_dist) - min_dist = (float) STBTT_sqrt(dist2); - - if (num >= 1 && res[0] >= 0.0f && res[0] <= 1.0f) { - t = res[0], it = 1.0f - t; - px = it*it*x0 + 2*t*it*x1 + t*t*x2; - py = it*it*y0 + 2*t*it*y1 + t*t*y2; - dist2 = (px-sx)*(px-sx) + (py-sy)*(py-sy); - if (dist2 < min_dist * min_dist) - min_dist = (float) STBTT_sqrt(dist2); - } - if (num >= 2 && res[1] >= 0.0f && res[1] <= 1.0f) { - t = res[1], it = 1.0f - t; - px = it*it*x0 + 2*t*it*x1 + t*t*x2; - py = it*it*y0 + 2*t*it*y1 + t*t*y2; - dist2 = (px-sx)*(px-sx) + (py-sy)*(py-sy); - if (dist2 < min_dist * min_dist) - min_dist = (float) STBTT_sqrt(dist2); - } - if (num >= 3 && res[2] >= 0.0f && res[2] <= 1.0f) { - t = res[2], it = 1.0f - t; - px = it*it*x0 + 2*t*it*x1 + t*t*x2; - py = it*it*y0 + 2*t*it*y1 + t*t*y2; - dist2 = (px-sx)*(px-sx) + (py-sy)*(py-sy); - if (dist2 < min_dist * min_dist) - min_dist = (float) STBTT_sqrt(dist2); - } - } - } - } - if (winding == 0) - min_dist = -min_dist; // if outside the shape, value is negative - val = onedge_value + pixel_dist_scale * min_dist; - if (val < 0) - val = 0; - else if (val > 255) - val = 255; - data[(y-iy0)*w+(x-ix0)] = (unsigned char) val; - } - } - STBTT_free(precompute, info->userdata); - STBTT_free(verts, info->userdata); - } - return data; -} - -STBTT_DEF unsigned char * stbtt_GetCodepointSDF(const stbtt_fontinfo *info, float scale, int codepoint, int padding, unsigned char onedge_value, float pixel_dist_scale, int *width, int *height, int *xoff, int *yoff) -{ - return stbtt_GetGlyphSDF(info, scale, stbtt_FindGlyphIndex(info, codepoint), padding, onedge_value, pixel_dist_scale, width, height, xoff, yoff); -} - -STBTT_DEF void stbtt_FreeSDF(unsigned char *bitmap, void *userdata) -{ - STBTT_free(bitmap, userdata); -} - -////////////////////////////////////////////////////////////////////////////// -// -// font name matching -- recommended not to use this -// - -// check if a utf8 string contains a prefix which is the utf16 string; if so return length of matching utf8 string -static stbtt_int32 stbtt__CompareUTF8toUTF16_bigendian_prefix(stbtt_uint8 *s1, stbtt_int32 len1, stbtt_uint8 *s2, stbtt_int32 len2) -{ - stbtt_int32 i=0; - - // convert utf16 to utf8 and compare the results while converting - while (len2) { - stbtt_uint16 ch = s2[0]*256 + s2[1]; - if (ch < 0x80) { - if (i >= len1) return -1; - if (s1[i++] != ch) return -1; - } else if (ch < 0x800) { - if (i+1 >= len1) return -1; - if (s1[i++] != 0xc0 + (ch >> 6)) return -1; - if (s1[i++] != 0x80 + (ch & 0x3f)) return -1; - } else if (ch >= 0xd800 && ch < 0xdc00) { - stbtt_uint32 c; - stbtt_uint16 ch2 = s2[2]*256 + s2[3]; - if (i+3 >= len1) return -1; - c = ((ch - 0xd800) << 10) + (ch2 - 0xdc00) + 0x10000; - if (s1[i++] != 0xf0 + (c >> 18)) return -1; - if (s1[i++] != 0x80 + ((c >> 12) & 0x3f)) return -1; - if (s1[i++] != 0x80 + ((c >> 6) & 0x3f)) return -1; - if (s1[i++] != 0x80 + ((c ) & 0x3f)) return -1; - s2 += 2; // plus another 2 below - len2 -= 2; - } else if (ch >= 0xdc00 && ch < 0xe000) { - return -1; - } else { - if (i+2 >= len1) return -1; - if (s1[i++] != 0xe0 + (ch >> 12)) return -1; - if (s1[i++] != 0x80 + ((ch >> 6) & 0x3f)) return -1; - if (s1[i++] != 0x80 + ((ch ) & 0x3f)) return -1; - } - s2 += 2; - len2 -= 2; - } - return i; -} - -static int stbtt_CompareUTF8toUTF16_bigendian_internal(char *s1, int len1, char *s2, int len2) -{ - return len1 == stbtt__CompareUTF8toUTF16_bigendian_prefix((stbtt_uint8*) s1, len1, (stbtt_uint8*) s2, len2); -} - -// returns results in whatever encoding you request... but note that 2-byte encodings -// will be BIG-ENDIAN... use stbtt_CompareUTF8toUTF16_bigendian() to compare -STBTT_DEF const char *stbtt_GetFontNameString(const stbtt_fontinfo *font, int *length, int platformID, int encodingID, int languageID, int nameID) -{ - stbtt_int32 i,count,stringOffset; - stbtt_uint8 *fc = font->data; - stbtt_uint32 offset = font->fontstart; - stbtt_uint32 nm = stbtt__find_table(fc, offset, "name"); - if (!nm) return NULL; - - count = ttUSHORT(fc+nm+2); - stringOffset = nm + ttUSHORT(fc+nm+4); - for (i=0; i < count; ++i) { - stbtt_uint32 loc = nm + 6 + 12 * i; - if (platformID == ttUSHORT(fc+loc+0) && encodingID == ttUSHORT(fc+loc+2) - && languageID == ttUSHORT(fc+loc+4) && nameID == ttUSHORT(fc+loc+6)) { - *length = ttUSHORT(fc+loc+8); - return (const char *) (fc+stringOffset+ttUSHORT(fc+loc+10)); - } - } - return NULL; -} - -static int stbtt__matchpair(stbtt_uint8 *fc, stbtt_uint32 nm, stbtt_uint8 *name, stbtt_int32 nlen, stbtt_int32 target_id, stbtt_int32 next_id) -{ - stbtt_int32 i; - stbtt_int32 count = ttUSHORT(fc+nm+2); - stbtt_int32 stringOffset = nm + ttUSHORT(fc+nm+4); - - for (i=0; i < count; ++i) { - stbtt_uint32 loc = nm + 6 + 12 * i; - stbtt_int32 id = ttUSHORT(fc+loc+6); - if (id == target_id) { - // find the encoding - stbtt_int32 platform = ttUSHORT(fc+loc+0), encoding = ttUSHORT(fc+loc+2), language = ttUSHORT(fc+loc+4); - - // is this a Unicode encoding? - if (platform == 0 || (platform == 3 && encoding == 1) || (platform == 3 && encoding == 10)) { - stbtt_int32 slen = ttUSHORT(fc+loc+8); - stbtt_int32 off = ttUSHORT(fc+loc+10); - - // check if there's a prefix match - stbtt_int32 matchlen = stbtt__CompareUTF8toUTF16_bigendian_prefix(name, nlen, fc+stringOffset+off,slen); - if (matchlen >= 0) { - // check for target_id+1 immediately following, with same encoding & language - if (i+1 < count && ttUSHORT(fc+loc+12+6) == next_id && ttUSHORT(fc+loc+12) == platform && ttUSHORT(fc+loc+12+2) == encoding && ttUSHORT(fc+loc+12+4) == language) { - slen = ttUSHORT(fc+loc+12+8); - off = ttUSHORT(fc+loc+12+10); - if (slen == 0) { - if (matchlen == nlen) - return 1; - } else if (matchlen < nlen && name[matchlen] == ' ') { - ++matchlen; - if (stbtt_CompareUTF8toUTF16_bigendian_internal((char*) (name+matchlen), nlen-matchlen, (char*)(fc+stringOffset+off),slen)) - return 1; - } - } else { - // if nothing immediately following - if (matchlen == nlen) - return 1; - } - } - } - - // @TODO handle other encodings - } - } - return 0; -} - -static int stbtt__matches(stbtt_uint8 *fc, stbtt_uint32 offset, stbtt_uint8 *name, stbtt_int32 flags) -{ - stbtt_int32 nlen = (stbtt_int32) STBTT_strlen((char *) name); - stbtt_uint32 nm,hd; - if (!stbtt__isfont(fc+offset)) return 0; - - // check italics/bold/underline flags in macStyle... - if (flags) { - hd = stbtt__find_table(fc, offset, "head"); - if ((ttUSHORT(fc+hd+44) & 7) != (flags & 7)) return 0; - } - - nm = stbtt__find_table(fc, offset, "name"); - if (!nm) return 0; - - if (flags) { - // if we checked the macStyle flags, then just check the family and ignore the subfamily - if (stbtt__matchpair(fc, nm, name, nlen, 16, -1)) return 1; - if (stbtt__matchpair(fc, nm, name, nlen, 1, -1)) return 1; - if (stbtt__matchpair(fc, nm, name, nlen, 3, -1)) return 1; - } else { - if (stbtt__matchpair(fc, nm, name, nlen, 16, 17)) return 1; - if (stbtt__matchpair(fc, nm, name, nlen, 1, 2)) return 1; - if (stbtt__matchpair(fc, nm, name, nlen, 3, -1)) return 1; - } - - return 0; -} - -static int stbtt_FindMatchingFont_internal(unsigned char *font_collection, char *name_utf8, stbtt_int32 flags) -{ - stbtt_int32 i; - for (i=0;;++i) { - stbtt_int32 off = stbtt_GetFontOffsetForIndex(font_collection, i); - if (off < 0) return off; - if (stbtt__matches((stbtt_uint8 *) font_collection, off, (stbtt_uint8*) name_utf8, flags)) - return off; - } -} - -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wcast-qual" -#endif - -STBTT_DEF int stbtt_BakeFontBitmap(const unsigned char *data, int offset, - float pixel_height, unsigned char *pixels, int pw, int ph, - int first_char, int num_chars, stbtt_bakedchar *chardata) -{ - return stbtt_BakeFontBitmap_internal((unsigned char *) data, offset, pixel_height, pixels, pw, ph, first_char, num_chars, chardata); -} - -STBTT_DEF int stbtt_GetFontOffsetForIndex(const unsigned char *data, int index) -{ - return stbtt_GetFontOffsetForIndex_internal((unsigned char *) data, index); -} - -STBTT_DEF int stbtt_GetNumberOfFonts(const unsigned char *data) -{ - return stbtt_GetNumberOfFonts_internal((unsigned char *) data); -} - -STBTT_DEF int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data, int offset) -{ - return stbtt_InitFont_internal(info, (unsigned char *) data, offset); -} - -STBTT_DEF int stbtt_FindMatchingFont(const unsigned char *fontdata, const char *name, int flags) -{ - return stbtt_FindMatchingFont_internal((unsigned char *) fontdata, (char *) name, flags); -} - -STBTT_DEF int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const char *s2, int len2) -{ - return stbtt_CompareUTF8toUTF16_bigendian_internal((char *) s1, len1, (char *) s2, len2); -} - -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif - -#endif // STB_TRUETYPE_IMPLEMENTATION - - -// FULL VERSION HISTORY -// -// 1.25 (2021-07-11) many fixes -// 1.24 (2020-02-05) fix warning -// 1.23 (2020-02-02) query SVG data for glyphs; query whole kerning table (but only kern not GPOS) -// 1.22 (2019-08-11) minimize missing-glyph duplication; fix kerning if both 'GPOS' and 'kern' are defined -// 1.21 (2019-02-25) fix warning -// 1.20 (2019-02-07) PackFontRange skips missing codepoints; GetScaleFontVMetrics() -// 1.19 (2018-02-11) OpenType GPOS kerning (horizontal only), STBTT_fmod -// 1.18 (2018-01-29) add missing function -// 1.17 (2017-07-23) make more arguments const; doc fix -// 1.16 (2017-07-12) SDF support -// 1.15 (2017-03-03) make more arguments const -// 1.14 (2017-01-16) num-fonts-in-TTC function -// 1.13 (2017-01-02) support OpenType fonts, certain Apple fonts -// 1.12 (2016-10-25) suppress warnings about casting away const with -Wcast-qual -// 1.11 (2016-04-02) fix unused-variable warning -// 1.10 (2016-04-02) allow user-defined fabs() replacement -// fix memory leak if fontsize=0.0 -// fix warning from duplicate typedef -// 1.09 (2016-01-16) warning fix; avoid crash on outofmem; use alloc userdata for PackFontRanges -// 1.08 (2015-09-13) document stbtt_Rasterize(); fixes for vertical & horizontal edges -// 1.07 (2015-08-01) allow PackFontRanges to accept arrays of sparse codepoints; -// allow PackFontRanges to pack and render in separate phases; -// fix stbtt_GetFontOFfsetForIndex (never worked for non-0 input?); -// fixed an assert() bug in the new rasterizer -// replace assert() with STBTT_assert() in new rasterizer -// 1.06 (2015-07-14) performance improvements (~35% faster on x86 and x64 on test machine) -// also more precise AA rasterizer, except if shapes overlap -// remove need for STBTT_sort -// 1.05 (2015-04-15) fix misplaced definitions for STBTT_STATIC -// 1.04 (2015-04-15) typo in example -// 1.03 (2015-04-12) STBTT_STATIC, fix memory leak in new packing, various fixes -// 1.02 (2014-12-10) fix various warnings & compile issues w/ stb_rect_pack, C++ -// 1.01 (2014-12-08) fix subpixel position when oversampling to exactly match -// non-oversampled; STBTT_POINT_SIZE for packed case only -// 1.00 (2014-12-06) add new PackBegin etc. API, w/ support for oversampling -// 0.99 (2014-09-18) fix multiple bugs with subpixel rendering (ryg) -// 0.9 (2014-08-07) support certain mac/iOS fonts without an MS platformID -// 0.8b (2014-07-07) fix a warning -// 0.8 (2014-05-25) fix a few more warnings -// 0.7 (2013-09-25) bugfix: subpixel glyph bug fixed in 0.5 had come back -// 0.6c (2012-07-24) improve documentation -// 0.6b (2012-07-20) fix a few more warnings -// 0.6 (2012-07-17) fix warnings; added stbtt_ScaleForMappingEmToPixels, -// stbtt_GetFontBoundingBox, stbtt_IsGlyphEmpty -// 0.5 (2011-12-09) bugfixes: -// subpixel glyph renderer computed wrong bounding box -// first vertex of shape can be off-curve (FreeSans) -// 0.4b (2011-12-03) fixed an error in the font baking example -// 0.4 (2011-12-01) kerning, subpixel rendering (tor) -// bugfixes for: -// codepoint-to-glyph conversion using table fmt=12 -// codepoint-to-glyph conversion using table fmt=4 -// stbtt_GetBakedQuad with non-square texture (Zer) -// updated Hello World! sample to use kerning and subpixel -// fixed some warnings -// 0.3 (2009-06-24) cmap fmt=12, compound shapes (MM) -// userdata, malloc-from-userdata, non-zero fill (stb) -// 0.2 (2009-03-11) Fix unsigned/signed char warnings -// 0.1 (2009-03-09) First public release -// - -/* ------------------------------------------------------------------------------- -This software is available under 2 licenses -- choose whichever you prefer. ------------------------------------------------------------------------------- -ALTERNATIVE A - MIT License -Copyright (c) 2017 Sean Barrett -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. ------------------------------------------------------------------------------- -ALTERNATIVE B - Public Domain (www.unlicense.org) -This is free and unencumbered software released into the public domain. -Anyone is free to copy, modify, publish, use, compile, sell, or distribute this -software, either in source code form or as a compiled binary, for any purpose, -commercial or non-commercial, and by any means. -In jurisdictions that recognize copyright laws, the author or authors of this -software dedicate any and all copyright interest in the software to the public -domain. We make this dedication for the benefit of the public at large and to -the detriment of our heirs and successors. We intend this dedication to be an -overt act of relinquishment in perpetuity of all present and future rights to -this software under copyright law. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------- -*/ diff --git a/samples/utility.h b/samples/utility.h deleted file mode 100644 index 4b92bb4..0000000 --- a/samples/utility.h +++ /dev/null @@ -1,118 +0,0 @@ -// SPDX-FileCopyrightText: 2025 Erin Catto -// SPDX-License-Identifier: MIT - -#pragma once - -#include "box3d/types.h" - -struct Vector4 -{ - float x, y, z, w; -}; - -struct Matrix4 -{ - Vector4 cx, cy, cz, cw; -}; - -inline Matrix4 MakeMatrix4( const b3Transform& transform, b3Vec3 scale ) -{ - b3Matrix3 m3 = b3MakeMatrixFromQuat( transform.q ); - Matrix4 m = {}; - m.cx = { scale.x * m3.cx.x, scale.x * m3.cx.y, scale.x * m3.cx.z, 0.0f }; - m.cy = { scale.y * m3.cy.x, scale.y * m3.cy.y, scale.y * m3.cy.z, 0.0f }; - m.cz = { scale.z * m3.cz.x, scale.z * m3.cz.y, scale.z * m3.cz.z, 0.0f }; - m.cw = { transform.p.x, transform.p.y, transform.p.z, 1.0f }; - return m; -} - -inline Matrix4 MakeMatrix4( const b3Transform& transform, float scale ) -{ - b3Matrix3 m3 = b3MakeMatrixFromQuat( transform.q ); - Matrix4 m = {}; - m.cx = { scale * m3.cx.x, scale * m3.cx.y, scale * m3.cx.z, 0.0f }; - m.cy = { scale * m3.cy.x, scale * m3.cy.y, scale * m3.cy.z, 0.0f }; - m.cz = { scale * m3.cz.x, scale * m3.cz.y, scale * m3.cz.z, 0.0f }; - m.cw = { transform.p.x, transform.p.y, transform.p.z, 1.0f }; - return m; -} - -inline Vector4 MulMV( const Matrix4& m, Vector4 a ) -{ - Vector4 b; - b.x = m.cx.x * a.x + m.cy.x * a.y + m.cz.x * a.z + m.cw.x * a.w; - b.y = m.cx.y * a.x + m.cy.y * a.y + m.cz.y * a.z + m.cw.y * a.w; - b.z = m.cx.z * a.x + m.cy.z * a.y + m.cz.z * a.z + m.cw.z * a.w; - b.w = m.cx.w * a.x + m.cy.w * a.y + m.cz.w * a.z + m.cw.w * a.w; - return b; -} - -inline Matrix4 MulMM( const Matrix4& a, const Matrix4& b ) -{ - Matrix4 c; - c.cx = MulMV( a, b.cx ); - c.cy = MulMV( a, b.cy ); - c.cz = MulMV( a, b.cz ); - c.cw = MulMV( a, b.cw ); - return c; -} - -struct RGBA8 -{ - uint8_t r, g, b, a; -}; - -inline RGBA8 MakeRGBA8( b3HexColor h, float alpha ) -{ - RGBA8 color; - color.r = ( h >> 16 ) & 0xFF; - color.g = ( h >> 8 ) & 0xFF; - color.b = h & 0xFF; - color.a = uint8_t( 255.0f * alpha + 0.5f ); - return color; -} - -inline RGBA8 MakeRGBA8( b3HexColor h ) -{ - RGBA8 color; - color.r = ( h >> 16 ) & 0xFF; - color.g = ( h >> 8 ) & 0xFF; - color.b = h & 0xFF; - color.a = 0xFF; - return color; -} - -struct RGBAf -{ - float r, g, b, a; -}; - -inline RGBAf MakeRGBAf( b3HexColor h, float alpha ) -{ - RGBAf color; - color.r = ( ( h >> 16 ) & 0xFF ) / 255.0f; - color.g = ( ( h >> 8 ) & 0xFF ) / 255.0f; - color.b = ( h & 0xFF ) / 255.0f; - color.a = alpha; - return color; -} - -inline RGBAf MakeRGBAf( b3HexColor h ) -{ - return MakeRGBAf( h, 1.0f ); -} - -Matrix4 MakeOrthographicMatrix( float left, float right, float bottom, float top, float near, float far ); - -struct Arena -{ - void Create( int byteCount ); - void Destroy(); - - void* Allocate( int byteCount ); - void Clear(); - - char* data; - int capacity; - int index; -}; diff --git a/shaders/common.glsl b/shaders/common.glsl deleted file mode 100644 index 4479268..0000000 --- a/shaders/common.glsl +++ /dev/null @@ -1,80 +0,0 @@ -// Shared constants and helpers used across deferred and forward fragment shaders. -// Included via the loader's `#include "common.glsl"` directive (no `#version` -// here; the including shader provides it). -// -// All color constants are authored in sRGB (display) space and converted to -// linear at use. Intensities are linear-space scalars. - -vec3 SrgbToLinear(vec3 c) { return pow(c, vec3(2.2)); } -vec3 LinearToSrgb(vec3 c) { return pow(c, vec3(1.0 / 2.2)); } - -vec3 ACESFilm(vec3 x) -{ - float a = 2.51, b = 0.03, c = 2.43, d = 0.59, e = 0.14; - return clamp((x * (a * x + b)) / (x * (c * x + d) + e), 0.0, 1.0); -} - -const vec3 SUN_COLOR_SRGB = vec3(1.00, 0.97, 0.92); -const float SUN_INTENSITY = 0.5; -const vec3 SKY_AMBIENT_SRGB = vec3(0.55, 0.60, 0.68); -const vec3 GROUND_AMBIENT_SRGB = vec3(0.22, 0.20, 0.17); -const float AMBIENT_INTENSITY = 0.4; -const float SPEC_POWER = 32.0; -const float SPEC_SCALE = 0.20; - -const vec3 SKY_ZENITH_SRGB = vec3(0.28, 0.48, 0.78); -const vec3 SKY_HORIZON_SRGB = vec3(0.55, 0.65, 0.78); -const vec3 SKY_GROUND_SRGB = vec3(0.28, 0.25, 0.22); -const vec3 SUN_DISK_SRGB = vec3(1.00, 0.97, 0.85); -const float SUN_DISK_BRIGHT = 8.0; -const vec3 SUN_HALO_SRGB = vec3(1.00, 0.92, 0.78); -const float SUN_HALO_BRIGHT = 0.35; - -const float FOG_DENSITY = 0.002; - -vec3 SkyColor(vec3 rayDir, vec3 sunDir) -{ - float t = clamp(rayDir.y, -1.0, 1.0); - vec3 skySrgb = (t >= 0.0) - ? mix(SKY_HORIZON_SRGB, SKY_ZENITH_SRGB, pow(t, 1.2)) - : mix(SKY_HORIZON_SRGB, SKY_GROUND_SRGB, pow(-t, 0.50)); - vec3 sky = SrgbToLinear(skySrgb); - - float sunCos = max(dot(rayDir, sunDir), 0.0); - sky += SrgbToLinear(SUN_DISK_SRGB) * SUN_DISK_BRIGHT * pow(sunCos, 800.0); - sky += SrgbToLinear(SUN_HALO_SRGB) * SUN_HALO_BRIGHT * pow(sunCos, 8.0); - return sky; -} - -// Hemispheric ambient term for a +Y-up world. N is world-space normal. -vec3 HemisphericAmbient(vec3 N) -{ - float hemi = 0.5 + 0.5 * N.y; - return AMBIENT_INTENSITY * mix(SrgbToLinear(GROUND_AMBIENT_SRGB), - SrgbToLinear(SKY_AMBIENT_SRGB), hemi); -} - -// TPDF (triangular) dither for 8-bit sRGB output. Two independent IGN samples -// give noise in [-1, +1] LSB; converting smooth gradients (sky, fog) from -// hard contour bands into high-frequency texture the eye averages out. Apply -// AFTER LinearToSrgb so quantization happens in display space. -vec3 DitherSrgb(vec3 c, vec2 fragCoord) -{ - const vec2 magic = vec2(0.06711056, 0.00583715); - const float k = 52.9829189; - float r1 = fract(k * fract(dot(fragCoord, magic))); - float r2 = fract(k * fract(dot(fragCoord + 7.0, magic))); - float t = r1 + r2 - 1.0; - return c + vec3(t) * (1.0 / 255.0); -} - -// Anti-aliased 1-pixel-wide world-space grid. uv is the tiled coordinate -// (e.g. worldXZ divided by the desired cell size). Returns ~1.0 on a line, -// ~0.0 in the cell interior; fwidth filtering keeps the line crisp at any -// distance and prevents the grid from aliasing on far receivers. -float WorldGrid(vec2 uv) -{ - vec2 grid = abs(fract(uv - 0.5) - 0.5); - vec2 line = grid / fwidth(uv); - return 1.0 - smoothstep(0.0, 1.5, min(line.x, line.y)); -} diff --git a/shaders/deferred_lighting_fs.glsl b/shaders/deferred_lighting_fs.glsl deleted file mode 100644 index f01ebf1..0000000 --- a/shaders/deferred_lighting_fs.glsl +++ /dev/null @@ -1,253 +0,0 @@ -#version 330 core - -#include "common.glsl" - -out vec4 outColor; - -in vec2 TexCoords; - -uniform sampler2D gPosition; // view-space position (xyz=0 for sky) -uniform sampler2D gNormal; // view-space normal -uniform sampler2D gAlbedoSpec; // sRGB albedo, a specular strength -uniform sampler2D ssao; -uniform sampler2DShadow shadowMap; - -uniform mat4 lightSpaceMatrix; -uniform mat4 cameraMatrix; // camera-to-world -uniform float worldTexelSize; // world-space span of one shadow-map texel -uniform float lightZRange; // lightFarPlane - lightNearPlane, in world units - -// Sun + sky -uniform vec3 sunDirWorld; // normalized, points from scene toward sun -uniform float tanHalfFovY; -uniform float aspectRatio; - -uniform bool useSSAO; -uniform bool useShadow; -uniform bool useGrid; -uniform float aoPower; -uniform float aoDirect; -uniform bool aoOnly; - -// Vogel disk (phyllotaxis spiral) sampling. Produces naturally well-distributed -// taps for any sample count, and the rotation phase is just an additive angle -// per tap — no rotation matrix needed. -const float GOLDEN_ANGLE = 2.39996323; -const int PCF_TAP_COUNT = 32; -const float PCF_RADIUS_TEXELS = 3.0; - -float ShadowCalculation(vec4 lightSpacePos, vec3 worldNormal, vec3 worldPos) -{ - vec3 projCoords = lightSpacePos.xyz / lightSpacePos.w; - projCoords = projCoords * 0.5 + 0.5; - - // dFdx/dFdy must run before any early return so neighboring fragments in the - // 2x2 quad always reach this point with valid projCoords values. - vec3 ddxCoords = dFdx(projCoords); - vec3 ddyCoords = dFdy(projCoords); - - if (projCoords.z > 1.0 || projCoords.z < 0.0) return 0.0; - - // Soft-fade near the shadow map boundary so geometry just outside the fitted - // frustum doesn't produce a hard cutoff line. Falls off over the outer 6% - // of the xy range and outer 10% of the depth range. - vec2 edge = min(projCoords.xy, 1.0 - projCoords.xy); - float xyFade = smoothstep(0.0, 0.06, min(edge.x, edge.y)); - float zFade = 1.0 - smoothstep(0.90, 1.0, projCoords.z); - float fade = xyFade * zFade; - if (fade <= 0.0) return 0.0; - - // Receiver-plane depth bias: convert the screen-space gradient of projCoords.z - // into a gradient with respect to shadow-map UV via the inverse Jacobian. - // Each PCF tap then gets the depth the receiver surface would *actually* have - // at that tap's offset, so per-texel acne disappears without lifting shadows - // off contact via a large constant bias. - // - // Silhouette guard: at object edges, dFdx/dFdy mix samples from two unrelated - // surfaces, producing a meaningless gradient that would over-bias the test - // and paint a bright fringe along the silhouette. fwidth flags that case and - // we fall back to a constant bias for those fragments. - vec2 dzduv = vec2(0.0); - // True silhouettes (adjacent pixels on different surfaces) have huge zWidth, - // close to 1.0. Continuous surfaces even at grazing angles stay well below. - float zWidth = abs(ddxCoords.z) + abs(ddyCoords.z); - bool onSilhouette = zWidth > 0.3; - if (!onSilhouette) - { - float det = ddxCoords.x * ddyCoords.y - ddxCoords.y * ddyCoords.x; - if (abs(det) > 1e-8) - { - float invDet = 1.0 / det; - dzduv.x = (ddyCoords.y * ddxCoords.z - ddxCoords.y * ddyCoords.z) * invDet; - dzduv.y = (ddxCoords.x * ddyCoords.z - ddyCoords.x * ddxCoords.z) * invDet; - } - // Clamp loose enough to cover legitimate steep slopes (e.g. surfaces - // nearly aligned with the light direction) but still finite. - dzduv = clamp(dzduv, vec2(-2.0), vec2(2.0)); - } - - vec2 texelSize = 1.0 / textureSize(shadowMap, 0); - - // Adapt PCF kernel radius to the screen pixel's footprint in shadow texels. - // At far view distances each screen pixel covers many shadow texels; a - // fixed 3-texel disk fits *inside* a single pixel, so adjacent pixels see - // nearly the same texel set just rotated differently — that resonates with - // the texel grid into the swirly moire visible on distant flat receivers. - // Growing the kernel with the footprint makes the taps actually average - // over the pixel's shadow-texel coverage, and as a bonus distant shadows - // get the gentle softening they should naturally have. Clamped so very - // distant geometry doesn't blow the kernel up to a useless smear. - float footprintTexels = max(length(ddxCoords.xy), length(ddyCoords.xy)) / texelSize.x; - float radiusTexels = clamp(footprintTexels, PCF_RADIUS_TEXELS, 8.0); - vec2 sampleScale = radiusTexels * texelSize; - - // Hardware bilinear PCF samples a 2x2 texel neighborhood against a single - // refZ, but the four stored depths differ by up to dzduv * 0.5 * texelSize. - // Without absorbing that, half the bilinear neighbors pass and half fail, - // producing the residual banding RPDB alone can't kill. Scaling the bias - // with the receiver slope keeps adjacent texels on the same side of the - // comparison. - float slopeBias = (abs(dzduv.x) + abs(dzduv.y)) * texelSize.x; - // World-unit bias floor: the existing constants are in normalized [0,1] - // light-space depth, but the geometric scale that actually causes acne - // (stacked-brick seams, hull-on-hull contacts) is in world units. A - // 1-world-unit caster spans `1.0 / lightZRange` of normalized depth, so - // any bias smaller than that lets self-shadow bands appear at every - // brick interface. Floor it at ~half a world unit so the bias adapts - // automatically to camera distance (which controls lightZRange). - float minBias = 0.5 / max(lightZRange, 1.0); - float bias = max(minBias, onSilhouette ? 0.003 : (slopeBias + 0.0005)); - - // Per-pixel rotation phase. At extreme grazing angles each screen pixel - // covers many shadow texels and rotation makes adjacent pixels sample - // wildly different texel subsets — that resonates with the texel grid into - // visible moire. Fade rotation out as the receiver becomes foreshortened. - // - // Use Interleaved Gradient Noise (Jimenez 2014) for the angle. The basic - // fract(sin(dot(...))*43758.5453) hash has low-frequency structure that - // shows through as concentric/swirl moire when each screen pixel covers - // many shadow texels (distant view of a flat receiver). IGN was designed - // for shader dithering and decorrelates much better at neighboring pixels. - float rotStrength = 1.0 - smoothstep(0.05, 0.20, zWidth); - float ign = fract(52.9829189 * fract(dot(gl_FragCoord.xy, vec2(0.06711056, 0.00583715)))); - float phi = ign * 6.2831853 * rotStrength; - - // Vogel-disk PCF: each tap is one rotation step further around the golden- - // angle spiral, with radius growing as sqrt(i/N) so density is uniform - // across the disk. sampler2DShadow + GL_LEQUAL returns 1.0 when refZ <= - // storedDepth (lit), with hardware bilinear PCF inside each tap thanks to - // GL_LINEAR filtering on the depth texture. - float lit = 0.0; - float invN = 1.0 / float(PCF_TAP_COUNT); - for (int i = 0; i < PCF_TAP_COUNT; ++i) - { - float r = sqrt((float(i) + 0.5) * invN); - float theta = float(i) * GOLDEN_ANGLE + phi; - vec2 offset = vec2(cos(theta), sin(theta)) * r * sampleScale; - float refZ = projCoords.z + dot(dzduv, offset) - bias; - lit += texture(shadowMap, vec3(projCoords.xy + offset, refZ)); - } - return (1.0 - lit * invN) * fade; -} - -void main() -{ - vec2 ndc = TexCoords * 2.0 - 1.0; - vec3 camRight = cameraMatrix[0].xyz; - vec3 camUp = cameraMatrix[1].xyz; - vec3 camForward = -cameraMatrix[2].xyz; - vec3 viewDirWorld = normalize( - camForward - + ndc.x * tanHalfFovY * aspectRatio * camRight - + ndc.y * tanHalfFovY * camUp - ); - - vec3 viewPos = texture(gPosition, TexCoords).rgb; - vec3 viewNormal = texture(gNormal, TexCoords).rgb; - vec3 albedoSrgb = texture(gAlbedoSpec, TexCoords).rgb; - float specStrength = texture(gAlbedoSpec, TexCoords).a; - float ao = useSSAO ? texture(ssao, TexCoords).r : 1.0; - - if (viewPos.z == 0.0) - { - // AO-only debug still shows sky as sky so the geometry framing reads. - vec3 sky = LinearToSrgb(ACESFilm(SkyColor(viewDirWorld, sunDirWorld))); - outColor = vec4(DitherSrgb(sky, gl_FragCoord.xy), 1.0); - return; - } - - if (aoOnly) - { - // Bypass tonemap so AO of 1.0 reads as pure white. - outColor = vec4(vec3(ao), 1.0); - return; - } - - vec3 baseColor = SrgbToLinear(albedoSrgb); - vec3 worldPos = (cameraMatrix * vec4(viewPos, 1.0)).xyz; - vec3 worldNormal = normalize(mat3(cameraMatrix) * viewNormal); - - // World-space grid on near-horizontal upward faces. Two tiers so distance - // reads at any zoom: minor lines every 1 unit, major every 5. fwidth keeps - // each line ~1 pixel wide regardless of camera distance, which both - // avoids aliasing and produces a natural "fade with distance" since lines - // sub-pixel-merge into the surface tint as they recede. The orientation - // gate lets the same grid apply to stacked-cube tops without leaking onto - // walls or sloped faces. Disabled per-sample on mesh-collision grounds - // where the wireframe overlay already provides the same signal. - if (useGrid && abs(worldPos.y) < 0.5) - { - float groundFactor = smoothstep(0.95, 0.99, worldNormal.y); - if (groundFactor > 0.0) - { - float minor = WorldGrid(worldPos.xz); - float major = WorldGrid(worldPos.xz * 0.2); - float gridDarken = (1.0 - 0.15 * minor) * (1.0 - 0.40 * major); - baseColor *= mix(1.0, gridDarken, groundFactor); - } - } - - float aoFactor = pow(ao, aoPower); - - vec3 ambient = HemisphericAmbient(worldNormal) * aoFactor; - - vec3 sunColor = SrgbToLinear(SUN_COLOR_SRGB) * SUN_INTENSITY; - - float NdotL = max(dot(worldNormal, sunDirWorld), 0.0); - vec3 diffuse = NdotL * sunColor; - - vec3 viewDirToCam = -viewDirWorld; - vec3 halfDir = normalize(sunDirWorld + viewDirToCam); - float spec = pow(max(dot(worldNormal, halfDir), 0.0), SPEC_POWER); - vec3 specular = spec * specStrength * SPEC_SCALE * sunColor; - - float shadow = 0.0; - if (useShadow) - { - // Normal-offset bias: push the receiver point along the world normal - // before projecting to light space. RPDB inside ShadowCalculation - // handles per-tap bias well on flat receivers, but its Jacobian breaks - // down at grazing angles where dzduv saturates the ±2 clamp. Offsetting - // along N concentrates extra bias exactly on faces near-perpendicular - // to the light (NdotL near 0), killing the residual acne RPDB misses. - vec3 biasedWorldPos = worldPos + worldNormal * worldTexelSize * 1.5 * (1.0 - NdotL); - vec4 lightSpacePos = lightSpaceMatrix * vec4(biasedWorldPos, 1.0); - shadow = ShadowCalculation(lightSpacePos, worldNormal, worldPos); - } - - // todo for disabling shadows - // shadow = 0.0f; - - // Physically AO should only modulate indirect light, but direct sun overwhelms ambient on - // sunlit surfaces and the contact darkening disappears. aoDirect dials in a controllable - // amount of AO on the direct term — a fudge, but the only way to get visible contact AO - // on a brightly lit floor without a separate contact-shadow pass. - float directAO = mix(1.0, aoFactor, aoDirect); - vec3 color = baseColor * (ambient + (1.0 - shadow) * (diffuse + specular) * directAO); - - float dist = length(viewPos); - float fog = 1.0 - exp(-FOG_DENSITY * dist); - color = mix(color, SkyColor(viewDirWorld, sunDirWorld), fog); - - outColor = vec4(DitherSrgb(LinearToSrgb(ACESFilm(color)), gl_FragCoord.xy), 1.0); -} diff --git a/shaders/depth_copy_fs.glsl b/shaders/depth_copy_fs.glsl deleted file mode 100644 index 3661142..0000000 --- a/shaders/depth_copy_fs.glsl +++ /dev/null @@ -1,10 +0,0 @@ -#version 330 core - -in vec2 TexCoords; - -uniform sampler2D depthTexture; - -void main() -{ - gl_FragDepth = texture(depthTexture, TexCoords).r; -} diff --git a/shaders/empty.fs b/shaders/empty.fs deleted file mode 100644 index cd61250..0000000 --- a/shaders/empty.fs +++ /dev/null @@ -1,5 +0,0 @@ -#version 330 core - -void main() -{ -} diff --git a/shaders/forward.fs b/shaders/forward.fs deleted file mode 100644 index cea36dc..0000000 --- a/shaders/forward.fs +++ /dev/null @@ -1,10 +0,0 @@ -#version 330 core - -layout (location = 0) out vec4 fragmentColor; - -in vec3 overrideColor; - -void main() -{ - fragmentColor = vec4(overrideColor, 1.0); -} diff --git a/shaders/forward.vs b/shaders/forward.vs deleted file mode 100644 index d45a38a..0000000 --- a/shaders/forward.vs +++ /dev/null @@ -1,17 +0,0 @@ -#version 330 core - -layout (location = 0) in vec3 v_position; -layout (location = 1) in int v_flags; - -uniform mat4 projection; -uniform mat4 view; -uniform mat4 model; -uniform vec3 color; - -out vec3 overrideColor; - -void main() -{ - overrideColor = v_flags != 0 ? vec3(0.9, 0.9, 0.9) : color; - gl_Position = projection * view * model * vec4(v_position, 1.0); -} diff --git a/shaders/geometry_fs.glsl b/shaders/geometry_fs.glsl deleted file mode 100644 index 0ffb3d9..0000000 --- a/shaders/geometry_fs.glsl +++ /dev/null @@ -1,20 +0,0 @@ -#version 330 core - -layout (location = 0) out vec3 gPosition; -layout (location = 1) out vec3 gNormal; -layout (location = 2) out vec4 gAlbedoSpec; - -in vec3 fragmentPosition; -in vec3 normal; -in vec4 color; - -void main() -{ - // store the fragment position vector in the first gbuffer texture - gPosition = fragmentPosition; - - // also store the per-fragment normals into the gbuffer - gNormal = normalize(normal); - - gAlbedoSpec = color; -} \ No newline at end of file diff --git a/shaders/geometry_vs.glsl b/shaders/geometry_vs.glsl deleted file mode 100644 index bc74a2a..0000000 --- a/shaders/geometry_vs.glsl +++ /dev/null @@ -1,46 +0,0 @@ -#version 330 core - -layout (location = 0) in vec3 aPos; -layout (location = 1) in vec3 aNormal; -layout (location = 2) in int aMaterial; - -out vec3 fragmentPosition; -out vec3 normal; -out vec4 color; - -// for drawing a hollow cube -uniform bool invertedNormals; - -uniform mat4 model; -uniform mat4 view; -uniform mat4 projection; -uniform vec4 objectColor; - -void main() -{ - // Define an array of 10 colors - vec3 colors[10]; - colors[0] = vec3(0.4706, 0.6118, 0.2); - colors[1] = vec3(0.5255, 0.2941, 0.3529); - colors[2] = vec3(0.2, 0.2, 0.4588); - colors[3] = vec3(0.7451, 0.5725, 0.2471); - colors[4] = vec3(0.6784, 0.2627, 0.6784); - colors[5] = vec3(0.2784, 0.6, 0.6); - colors[6] = vec3(0.502, 0.251, 0.0039); - colors[7] = vec3(0.698, 0.5608, 0.8314); - colors[8] = vec3(0.0, 0.2941, 0.0); - colors[9] = vec3(0.5, 0.5, 0.5); - - vec4 viewPos = view * model * vec4(aPos, 1.0); - fragmentPosition = viewPos.xyz; - - mat3 normalMatrix = transpose(inverse(mat3(view * model))); - normal = normalMatrix * (invertedNormals ? -aNormal : aNormal); - - int colorIndex = max(0, aMaterial) % 10; - color = aMaterial >= 0 ? vec4(colors[colorIndex], 1.0) : objectColor; - - // color = vec4(colors[2], 1.0f); - - gl_Position = projection * viewPos; -} \ No newline at end of file diff --git a/shaders/mesh.fs b/shaders/mesh.fs deleted file mode 100644 index 0ffb3d9..0000000 --- a/shaders/mesh.fs +++ /dev/null @@ -1,20 +0,0 @@ -#version 330 core - -layout (location = 0) out vec3 gPosition; -layout (location = 1) out vec3 gNormal; -layout (location = 2) out vec4 gAlbedoSpec; - -in vec3 fragmentPosition; -in vec3 normal; -in vec4 color; - -void main() -{ - // store the fragment position vector in the first gbuffer texture - gPosition = fragmentPosition; - - // also store the per-fragment normals into the gbuffer - gNormal = normalize(normal); - - gAlbedoSpec = color; -} \ No newline at end of file diff --git a/shaders/mesh.vs b/shaders/mesh.vs deleted file mode 100644 index 8c50074..0000000 --- a/shaders/mesh.vs +++ /dev/null @@ -1,48 +0,0 @@ -#version 330 core - -// Static -layout (location = 0) in vec3 v_localPosition; -layout (location = 1) in vec3 v_localNormal; -layout (location = 2) in int v_material; - -// Instance -layout (location = 3) in vec4 v_instanceColor; -layout (location = 4) in mat4 v_instanceMatrix; - -out vec3 fragmentPosition; -out vec3 normal; -out vec4 color; - -uniform mat4 view; -uniform mat4 projection; - -void main() -{ - // Define an array of 10 colors - vec3 colors[10]; - colors[0] = vec3(0.4706, 0.6118, 0.2); - colors[1] = vec3(0.5255, 0.2941, 0.3529); - colors[2] = vec3(0.2, 0.2, 0.4588); - colors[3] = vec3(0.7451, 0.5725, 0.2471); - colors[4] = vec3(0.6784, 0.2627, 0.6784); - colors[5] = vec3(0.2784, 0.6, 0.6); - colors[6] = vec3(0.502, 0.251, 0.0039); - colors[7] = vec3(0.698, 0.5608, 0.8314); - colors[8] = vec3(0.0, 0.2941, 0.0); - colors[9] = vec3(0.5, 0.5, 0.5); - - vec4 viewPos = view * v_instanceMatrix * vec4(v_localPosition, 1.0); - fragmentPosition = viewPos.xyz; - - mat3 normalMatrix = transpose(inverse(mat3(view * v_instanceMatrix))); - normal = normalMatrix * v_localNormal; - - int colorIndex = max(0, v_material) % 10; - - // alpha is specular - color = v_material >= 0 ? vec4(colors[colorIndex], 1.0) : v_instanceColor; - - //color = vec4(colors[4], 1.0f); - - gl_Position = projection * viewPos; -} \ No newline at end of file diff --git a/shaders/mesh_edge.vs b/shaders/mesh_edge.vs deleted file mode 100644 index 7667f77..0000000 --- a/shaders/mesh_edge.vs +++ /dev/null @@ -1,20 +0,0 @@ -#version 330 core - -// Static -layout (location = 0) in vec3 v_localPosition; -layout (location = 1) in int v_flags; - -// Instance -layout (location = 2) in vec4 v_instanceColor; -layout (location = 3) in mat4 v_instanceMatrix; - -out vec3 overrideColor; - -uniform mat4 projection; -uniform mat4 view; - -void main() -{ - overrideColor = v_flags != 0 ? vec3(0.6, 0.6, 0.6) : 0.5 * v_instanceColor.rgb; - gl_Position = projection * view * v_instanceMatrix * vec4(v_localPosition, 1.0); -} diff --git a/shaders/mesh_forward.fs b/shaders/mesh_forward.fs deleted file mode 100644 index 96c17f6..0000000 --- a/shaders/mesh_forward.fs +++ /dev/null @@ -1,34 +0,0 @@ -#version 330 core - -#include "common.glsl" - -layout (location = 0) out vec4 fragmentColor; - -in vec3 position; // world space -in vec3 normal; // world space -in vec4 color; // sRGB albedo, alpha is opacity - -uniform vec3 sunDirWorld; -uniform vec3 cameraPos; - -void main() -{ - vec3 N = normalize(normal); - vec3 viewRay = normalize(position - cameraPos); - - vec3 baseColor = SrgbToLinear(color.rgb); - - vec3 ambient = HemisphericAmbient(N); - - vec3 sunColor = SrgbToLinear(SUN_COLOR_SRGB) * SUN_INTENSITY; - float NdotL = max(dot(N, sunDirWorld), 0.0); - vec3 diffuse = NdotL * sunColor; - - vec3 lit = baseColor * (ambient + diffuse); - - float dist = length(position - cameraPos); - float fog = 1.0 - exp(-FOG_DENSITY * dist); - lit = mix(lit, SkyColor(viewRay, sunDirWorld), fog); - - fragmentColor = vec4(DitherSrgb(LinearToSrgb(ACESFilm(lit)), gl_FragCoord.xy), color.a); -} diff --git a/shaders/mesh_forward.vs b/shaders/mesh_forward.vs deleted file mode 100644 index 19b203d..0000000 --- a/shaders/mesh_forward.vs +++ /dev/null @@ -1,47 +0,0 @@ -#version 330 core - -layout (location = 0) in vec3 v_localPosition; -layout (location = 1) in vec3 v_localNormal; -layout (location = 2) in int v_material; -layout (location = 3) in vec4 v_instanceColor; -layout (location = 4) in mat4 v_instanceMatrix; - -out vec3 position; -out vec3 normal; -out vec4 color; - -uniform mat4 view; -uniform mat4 projection; - -void main() -{ - // Define an array of 10 colors - vec3 colors[10]; - colors[0] = vec3(0.4706, 0.6118, 0.2); - colors[1] = vec3(0.5255, 0.2941, 0.3529); - colors[2] = vec3(0.2, 0.2, 0.4588); - colors[3] = vec3(0.7451, 0.5725, 0.2471); - colors[4] = vec3(0.6784, 0.2627, 0.6784); - colors[5] = vec3(0.2784, 0.6, 0.6); - colors[6] = vec3(0.502, 0.251, 0.0039); - colors[7] = vec3(0.698, 0.5608, 0.8314); - colors[8] = vec3(0.0, 0.2941, 0.0); - colors[9] = vec3(0.5, 0.5, 0.5); - - // world space position - position = vec3(v_instanceMatrix * vec4(v_localPosition, 1.0)); - - vec4 viewPos = view * vec4(position, 1.0); - - // world space normal, accounting for non-uniform scale - mat3 normalMatrix = transpose(inverse(mat3(v_instanceMatrix))); - normal = normalMatrix * v_localNormal; - - int colorIndex = max(0, v_material) % 10; - color = v_material >= 0 ? vec4(colors[colorIndex], v_instanceColor.a) : v_instanceColor; - - // color = vec4(colors[2], 0.5f); - - gl_Position = projection * viewPos; - -} \ No newline at end of file diff --git a/shaders/mesh_shadow.vs b/shaders/mesh_shadow.vs deleted file mode 100644 index 551471f..0000000 --- a/shaders/mesh_shadow.vs +++ /dev/null @@ -1,14 +0,0 @@ -#version 330 core - -layout (location = 0) in vec3 v_localPosition; -layout (location = 1) in vec3 v_localNormal; -layout (location = 2) in int v_material; -layout (location = 3) in vec4 v_instanceColor; -layout (location = 4) in mat4 v_instanceMatrix; - -uniform mat4 lightSpaceMatrix; - -void main() -{ - gl_Position = lightSpaceMatrix * v_instanceMatrix * vec4(v_localPosition, 1.0); -} diff --git a/shaders/quad_vs.glsl b/shaders/quad_vs.glsl deleted file mode 100644 index 9f93e29..0000000 --- a/shaders/quad_vs.glsl +++ /dev/null @@ -1,11 +0,0 @@ -#version 330 core -layout (location = 0) in vec3 aPos; -layout (location = 1) in vec2 aTexCoords; - -out vec2 TexCoords; - -void main() -{ - TexCoords = aTexCoords; - gl_Position = vec4(aPos, 1.0); -} \ No newline at end of file diff --git a/shaders/shadow_map.vs b/shaders/shadow_map.vs deleted file mode 100644 index 947562f..0000000 --- a/shaders/shadow_map.vs +++ /dev/null @@ -1,10 +0,0 @@ -#version 330 core -layout (location = 0) in vec3 aPos; - -uniform mat4 lightSpaceMatrix; -uniform mat4 model; - -void main() -{ - gl_Position = lightSpaceMatrix * model * vec4(aPos, 1.0); -} \ No newline at end of file diff --git a/shaders/ssao_blur_fs.glsl b/shaders/ssao_blur_fs.glsl deleted file mode 100644 index 24ec446..0000000 --- a/shaders/ssao_blur_fs.glsl +++ /dev/null @@ -1,47 +0,0 @@ -#version 330 core -out float FragColor; - -in vec2 TexCoords; - -uniform sampler2D ssaoInput; -uniform sampler2D gPosition; - -// Depth difference (in view-space units) over which a tap's weight halves. -// Tight enough to keep silhouette edges sharp, loose enough not to leave -// per-tap noise behind on smooth surfaces. -const float DEPTH_SIGMA = 0.25; - -void main() -{ - vec2 texelSize = 1.0 / vec2(textureSize(ssaoInput, 0)); - float centerZ = texture(gPosition, TexCoords).z; - - // Sky / no-geometry: pass through. Avoids contaminating real geometry's - // bilateral weights with the zero-init sentinel from the G-buffer. - if (centerZ == 0.0) - { - FragColor = texture(ssaoInput, TexCoords).r; - return; - } - - float invTwoSigmaSq = 1.0 / (2.0 * DEPTH_SIGMA * DEPTH_SIGMA); - - float result = 0.0; - float weightSum = 0.0; - for (int x = -2; x < 2; ++x) - { - for (int y = -2; y < 2; ++y) - { - vec2 sampleUV = TexCoords + vec2(float(x), float(y)) * texelSize; - float tapZ = texture(gPosition, sampleUV).z; - // Drop sky taps so they don't pull the weighted average toward 1.0 - // along silhouettes against the background. - if (tapZ == 0.0) continue; - float dz = centerZ - tapZ; - float w = exp(-dz * dz * invTwoSigmaSq); - result += texture(ssaoInput, sampleUV).r * w; - weightSum += w; - } - } - FragColor = (weightSum > 0.0) ? (result / weightSum) : texture(ssaoInput, TexCoords).r; -} diff --git a/shaders/ssao_fs.glsl b/shaders/ssao_fs.glsl deleted file mode 100644 index 3ae4423..0000000 --- a/shaders/ssao_fs.glsl +++ /dev/null @@ -1,67 +0,0 @@ -#version 330 core -out float FragColor; - -in vec2 TexCoords; - -uniform sampler2D gPosition; -uniform sampler2D gNormal; -uniform sampler2D texNoise; - -uniform vec3 samples[32]; -uniform float radius = 0.5; -uniform float bias = 0.025; -uniform float minScale = 0.1; - -// parameters (you'd probably want to use them as uniforms to more easily tweak the effect) -int kernelSize = 32; - -// tile noise texture over screen based on screen dimensions divided by noise size -uniform vec2 noiseScale; - -uniform mat4 projection; - -void main() -{ - // get input for SSAO algorithm - vec3 fragPos = texture(gPosition, TexCoords).xyz; - - // early-out for sky/background fragments (no geometry in G-buffer) - if (fragPos.z == 0.0) - { - FragColor = 1.0; - return; - } - - vec3 normal = normalize(texture(gNormal, TexCoords).rgb); - vec3 randomVec = normalize(texture(texNoise, TexCoords * noiseScale).xyz); - - // create TBN change-of-basis matrix: from tangent-space to view-space - vec3 tangent = normalize(randomVec - normal * dot(randomVec, normal)); - vec3 bitangent = cross(normal, tangent); - mat3 TBN = mat3(tangent, bitangent, normal); - - // iterate over the sample kernel and calculate occlusion factor - float occlusion = 0.0; - for(int i = 0; i < kernelSize; ++i) - { - // get sample position - vec3 samplePos = TBN * samples[i]; // from tangent to view-space - samplePos = fragPos + samplePos * radius; - - // project sample position (to sample texture) (to get position on screen/texture) - vec4 offset = vec4(samplePos, 1.0); - offset = projection * offset; // from view to clip-space - offset.xyz /= offset.w; // perspective divide - offset.xyz = offset.xyz * 0.5 + 0.5; // transform to range 0.0 - 1.0 - - // get sample depth - float sampleDepth = texture(gPosition, offset.xy).z; // get depth value of kernel sample - - // range check & accumulate - float rangeCheck = smoothstep(0.0, 1.0, radius / abs(fragPos.z - sampleDepth)); - occlusion += (sampleDepth >= samplePos.z + bias ? 1.0 : 0.0) * rangeCheck; - } - occlusion = max(1.0 - (occlusion / kernelSize), minScale); - - FragColor = occlusion; -} diff --git a/shared/benchmarks.c b/shared/benchmarks.c index 4c942af..4825cc7 100644 --- a/shared/benchmarks.c +++ b/shared/benchmarks.c @@ -18,6 +18,18 @@ #define BENCHMARK_DEBUG 1 #endif +static b3ShapeId g_groundShapeId = { 0 }; + +b3ShapeId GetGroundShapeId( void ) +{ + return g_groundShapeId; +} + +void ResetGroundShapeId( void ) +{ + g_groundShapeId = b3_nullShapeId; +} + void CreateJointGrid( b3WorldId worldId ) { b3World_EnableSleeping( worldId, false ); @@ -94,12 +106,12 @@ void CreateLargePyramid( b3WorldId worldId ) { b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = (b3Vec3){ 0.0f, -1.0f }; + bodyDef.position = (b3Vec3){ 0.0f, -1.0f, 0.0f }; b3BodyId groundId = b3CreateBody( worldId, &bodyDef ); b3BoxHull box = b3MakeBoxHull( 100.0f, 1.0f, 100.0f ); b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHullShape( groundId, &shapeDef, &box.base ); + g_groundShapeId = b3CreateHullShape( groundId, &shapeDef, &box.base ); } b3BodyDef bodyDef = b3DefaultBodyDef(); @@ -133,12 +145,12 @@ void CreateWidePyramid( b3WorldId worldId ) { { b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = (b3Vec3){ 0.0f, -1.0f }; + bodyDef.position = (b3Vec3){ 0.0f, -1.0f, 0.0f }; b3BodyId groundId = b3CreateBody( worldId, &bodyDef ); b3BoxHull box = b3MakeBoxHull( 100.0f, 1.0f, 100.0f ); b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHullShape( groundId, &shapeDef, &box.base ); + g_groundShapeId = b3CreateHullShape( groundId, &shapeDef, &box.base ); } const float boxSize = 2.0f; @@ -178,6 +190,7 @@ static void CreateSmallPyramid( b3WorldId worldId, int baseCount, float extent, bodyDef.enableSleep = false; b3ShapeDef shapeDef = b3DefaultShapeDef(); + shapeDef.density = 100.0f; b3BoxHull box = b3MakeBoxHull( extent, extent, extent ); @@ -210,9 +223,8 @@ void CreateManyPyramids( b3WorldId worldId ) b3BodyId groundId = b3CreateBody( worldId, &bodyDef ); b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull box = b3MakeBoxHull( groundExtent, 1.0f, groundExtent ); - b3CreateHullShape( groundId, &shapeDef, &box.base ); + g_groundShapeId = b3CreateHullShape( groundId, &shapeDef, &box.base ); } float baseWidth = 2.0f * extent * baseCount; @@ -532,7 +544,7 @@ void CreateWasher( b3WorldId worldId ) b3BoxHull box = b3MakeBoxHull( 60.0f, 1.0f, 60.0f ); b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHullShape( groundId, &shapeDef, &box.base ); + g_groundShapeId = b3CreateHullShape( groundId, &shapeDef, &box.base ); } { @@ -794,7 +806,7 @@ void CreateJunkyard( b3WorldId worldId ) b3ShapeDef shapeDef = b3DefaultShapeDef(); { b3BoxHull box = b3MakeBoxHull( 120.0f, 1.0f, 120.0f ); - b3CreateHullShape( groundId, &shapeDef, &box.base ); + g_groundShapeId = b3CreateHullShape( groundId, &shapeDef, &box.base ); } { b3Vec3 offset = { -50.0f, 8.0f, 0.0f }; diff --git a/shared/benchmarks.h b/shared/benchmarks.h index e8b15f5..9975e1d 100644 --- a/shared/benchmarks.h +++ b/shared/benchmarks.h @@ -15,6 +15,11 @@ extern "C" { #endif +// This is used by the sample app to draw a ground grid. Should only +// be used for box hulls. +b3ShapeId GetGroundShapeId( void ); +void ResetGroundShapeId( void ); + void CreateTrees25( b3WorldId worldId ); void CreateTrees50( b3WorldId worldId ); void CreateTrees100( b3WorldId worldId ); diff --git a/shared/human.c b/shared/human.c index ea87668..805d770 100644 --- a/shared/human.c +++ b/shared/human.c @@ -623,6 +623,15 @@ void Human_CreateParallelAnchors( Human* human, b3WorldId worldId ) } } +void Human_SetBullet(Human* human, bool flag) +{ + for ( int i = 0; i < bone_count; ++i ) + { + Bone* bone = human->bones + i; + b3Body_SetBullet( bone->bodyId, flag ); + } +} + #if 0 void Human::EnablePoseControl( b3World* world, float springHertz, bool poseControl ) { diff --git a/shared/human.h b/shared/human.h index 9e8e6be..d9c2ca1 100644 --- a/shared/human.h +++ b/shared/human.h @@ -73,6 +73,8 @@ void Human_AlignSpring( Human* human, b3WorldId worldId, b3BodyId groundId, floa void Human_CreateMotorAnchors( Human* human, b3WorldId worldId ); void Human_CreateParallelAnchors( Human* human, b3WorldId worldId ); +void Human_SetBullet( Human* human, bool flag ); + // void Human_EnablePoseControl( Human* human, float springHertz, bool enablePoseControl ); // void Human_AdjustPoseControl( Human* human, float springHertz ); // void Human_DriveBase( Human* human, b3Transform transform, float timeStep ); diff --git a/shared/overflow_color.c b/shared/overflow_color.c index 8e118d0..39524af 100644 --- a/shared/overflow_color.c +++ b/shared/overflow_color.c @@ -25,7 +25,7 @@ OverflowColorPileData CreateOverflowColorPile( b3WorldId worldId ) b3BoxHull box = b3MakeBoxHull( 20.0f, 1.0f, 20.0f ); b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHullShape( groundId, &shapeDef, &box.base ); + data.groundShapeId = b3CreateHullShape( groundId, &shapeDef, &box.base ); } // Tall, heavy hub. Tall so neighbors can ring around it in multiple diff --git a/shared/overflow_color.h b/shared/overflow_color.h index fc7dd57..05ea4f8 100644 --- a/shared/overflow_color.h +++ b/shared/overflow_color.h @@ -15,6 +15,7 @@ extern "C" // exercising the b3*_Overflow solver path that no other scene reaches. typedef struct OverflowColorPileData { + b3ShapeId groundShapeId; b3BodyId hubId; int neighborCount; } OverflowColorPileData; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5ba4eb3..8ff24f0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,4 @@ include(GNUInstallDirs) -include(FetchContent) set(BOX3D_SOURCE_FILES aabb.c diff --git a/src/dynamic_tree.c b/src/dynamic_tree.c index eb963ae..367d9dc 100644 --- a/src/dynamic_tree.c +++ b/src/dynamic_tree.c @@ -1016,7 +1016,7 @@ static void b3ValidateMetrics( const b3DynamicTree* tree, int index ) const b3TreeNode* node = tree->nodes + index; - B3_VALIDATE( b3IsSaneAABB( node->aabb ) ); + B3_VALIDATE( b3IsValidAABB( node->aabb ) ); if ( b3IsLeaf( node ) ) { diff --git a/src/hull.c b/src/hull.c index 03e2765..bbb22a8 100644 --- a/src/hull.c +++ b/src/hull.c @@ -156,10 +156,7 @@ static inline void b3QHList_Init( b3QHListNode* head ) head->next = head; } -static inline bool b3QHList_Empty( const b3QHListNode* head ) -{ - return head->next == head; -} +#define B3_LIST_EMPTY( A ) ( ( A )->next == (A) ) static inline bool b3QHList_Contains( const b3QHListNode* node ) { @@ -806,7 +803,7 @@ static void b3HullBuilder_DrainConflictList( b3HullBuilder* b, b3QHFace* face ) b3QHList_Remove( &orphan->link ); b3QHList_PushBack( &b->orphanedList.link, &orphan->link ); } - B3_ASSERT( b3QHList_Empty( &face->conflictListHead.link ) ); + B3_ASSERT( B3_LIST_EMPTY( &face->conflictListHead.link ) ); } // Mark a face for deletion, drain its conflict list, and populate a fresh DFS frame for it. @@ -1023,7 +1020,7 @@ static void b3HullBuilder_AbsorbFaces( b3HullBuilder* b, b3QHFace* face ) } } - B3_ASSERT( b3QHList_Empty( head ) ); + B3_ASSERT( B3_LIST_EMPTY( head ) ); // Conflict list is now drained. Retire this face to the free list. b3HullBuilder_RetireFace( b, b->mergedFaces[i] ); @@ -1228,7 +1225,7 @@ static void b3HullBuilder_ResolveVertices( b3HullBuilder* b ) // Otherwise: vertex is interior to the hull. Its slot in the bump pool is abandoned. } - B3_ASSERT( b3QHList_Empty( &b->orphanedList.link ) ); + B3_ASSERT( B3_LIST_EMPTY( &b->orphanedList.link ) ); } static void b3HullBuilder_ResolveFaces( b3HullBuilder* b ) @@ -1243,7 +1240,7 @@ static void b3HullBuilder_ResolveFaces( b3HullBuilder* b ) if ( face->mark == B3_MARK_DELETE && b3QHList_Contains( &face->link ) ) { - B3_ASSERT( b3QHList_Empty( &face->conflictListHead.link ) ); + B3_ASSERT( B3_LIST_EMPTY( &face->conflictListHead.link ) ); b3QHList_Remove( &face->link ); } } diff --git a/src/physics_world.c b/src/physics_world.c index b43142e..17b5f15 100644 --- a/src/physics_world.c +++ b/src/physics_world.c @@ -1131,59 +1131,77 @@ static bool DrawQueryCallback( int proxyId, uint64_t userData, void* context ) if ( shape->materials[0].customColor != 0 ) { + // May already carry a packed material preset, pass through unchanged color = (b3HexColor)shape->materials[0].customColor; } - else if ( body->type == b3_dynamicBody && body->mass == 0.0f ) - { - // Bad body - color = b3_colorRed; - } - else if ( body->setIndex == b3_disabledSet ) - { - color = b3_colorSlateGray; - } - else if ( shape->sensorIndex != B3_NULL_INDEX ) - { - color = b3_colorWheat; - } - else if ( body->flags & b3_hadTimeOfImpact ) - { - color = b3_colorLime; - } - else if ( ( bodySim->flags & b3_isBullet ) && body->setIndex == b3_awakeSet ) - { - color = b3_colorTurquoise; - } - else if ( body->flags & b3_isSpeedCapped ) - { - color = b3_colorYellow; - } - else if ( bodySim->flags & b3_isFast ) - { - color = b3_colorSalmon; - } - else if ( body->type == b3_staticBody ) - { - color = b3_colorPaleGreen; - } - else if ( body->type == b3_kinematicBody ) - { - if ( body->setIndex == b3_awakeSet ) - { - color = b3_colorRoyalBlue; - } - else - { - color = b3_colorDarkBlue; - } - } - else if ( body->setIndex == b3_awakeSet ) - { - color = b3_colorPink; - } else { - color = b3_colorGray; + // Hue carries the state, material carries its energy. Calm matte for the + // resting masses, glossy for fast bodies, metallic for the driven kinematic. + // Diagnostic states keep a saturated hue and the default material so they pop. + b3HexColor rgb; + b3DebugMaterial material = b3_debugMaterialDefault; + + if ( body->type == b3_dynamicBody && body->mass == 0.0f ) + { + // Bad body + rgb = b3_colorRed; + } + else if ( body->setIndex == b3_disabledSet ) + { + rgb = b3_colorSlateGray; + } + else if ( shape->sensorIndex != B3_NULL_INDEX ) + { + rgb = b3_colorWheat; + } + else if ( body->flags & b3_hadTimeOfImpact ) + { + rgb = b3_colorLime; + } + else if ( ( bodySim->flags & b3_isBullet ) && body->setIndex == b3_awakeSet ) + { + rgb = b3_colorTurquoise; + } + else if ( body->flags & b3_isSpeedCapped ) + { + rgb = b3_colorYellow; + } + else if ( bodySim->flags & b3_isFast ) + { + rgb = b3_colorOrange; + material = b3_debugMaterialGlossy; + } + else if ( body->type == b3_staticBody ) + { + rgb = b3_colorDarkGray; + material = b3_debugMaterialMatte; + } + else if ( body->type == b3_kinematicBody ) + { + if ( body->setIndex == b3_awakeSet ) + { + rgb = b3_colorSteelBlue; + material = b3_debugMaterialMetallic; + } + else + { + rgb = b3_colorLightSteelBlue; + material = b3_debugMaterialMatte; + } + } + else if ( body->setIndex == b3_awakeSet ) + { + rgb = b3_colorTan; + material = b3_debugMaterialSoft; + } + else + { + rgb = b3_colorLightSlateGray; + material = b3_debugMaterialDead; + } + + color = (b3HexColor)b3MakeDebugColor( rgb, material ); } if ( shape->userShape == NULL && world->createDebugShape != NULL ) diff --git a/src/timer.c b/src/timer.c index 07ad30e..826b149 100644 --- a/src/timer.c +++ b/src/timer.c @@ -78,6 +78,11 @@ void b3Yield( void ) SwitchToThread(); } +void b3Sleep( int milliseconds ) +{ + Sleep( (DWORD)milliseconds ); +} + typedef struct b3Mutex { CRITICAL_SECTION cs; @@ -250,6 +255,14 @@ void b3Yield( void ) sched_yield(); } +void b3Sleep( int milliseconds ) +{ + struct timespec ts; + ts.tv_sec = milliseconds / 1000; + ts.tv_nsec = ( milliseconds % 1000 ) * 1000000L; + nanosleep( &ts, NULL ); +} + #include typedef struct b3Mutex { @@ -373,6 +386,7 @@ void b3JoinThread( b3Thread* t ) #include #include #include +#include static double s_invFrequency = 0.0; @@ -418,6 +432,14 @@ void b3Yield( void ) sched_yield(); } +void b3Sleep( int milliseconds ) +{ + struct timespec ts; + ts.tv_sec = milliseconds / 1000; + ts.tv_nsec = ( milliseconds % 1000 ) * 1000000L; + nanosleep( &ts, NULL ); +} + #include typedef struct b3Mutex { @@ -560,6 +582,11 @@ void b3Yield( void ) { } +void b3Sleep( int milliseconds ) +{ + ( (void)( milliseconds ) ); +} + typedef struct b3Mutex { int dummy;